当前位置: 首页>>代码示例>>C#>>正文


C# BEncodedList类代码示例

本文整理汇总了C#中BEncodedList的典型用法代码示例。如果您正苦于以下问题:C# BEncodedList类的具体用法?C# BEncodedList怎么用?C# BEncodedList使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


BEncodedList类属于命名空间,在下文中一共展示了BEncodedList类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ReadTorrentFileList

        /// <summary>
        /// Reads the file list from a .torrent file.
        /// </summary>
        /// <param name="downloadPath"></param>
        /// <returns></returns>
        public static List<SimpleFileInfo> ReadTorrentFileList(string torrentFile)
        {
            if (!File.Exists(torrentFile))
                throw new FileNotFoundException("Can't find file " + torrentFile);

            var ret = new List<SimpleFileInfo>();

            //read and decode the .torrent file
            byte[] torrentBytes = File.ReadAllBytes(torrentFile);
            var torrentData = BEncodedValue.Decode<BEncodedDictionary>(torrentBytes);

            BEncodedList fileList = new BEncodedList();

            try
            {
                fileList = torrentData.Item<BEncodedDictionary>("info").Item<BEncodedList>("files");
            }
            catch { };

            foreach (var fileItem in fileList)
            {
                var fileData = fileItem as BEncodedDictionary;

                string filePath = BuildPathFromDirectoryList(fileData.Item<BEncodedList>("path"));
                long length = fileData.Item<BEncodedNumber>("length").Number;

                ret.Add(new SimpleFileInfo(filePath, length));
            }
            ret.Sort( new Comparison<SimpleFileInfo>( FileNameComparison));

            return ret;
        }
开发者ID:chitza,项目名称:uDir,代码行数:37,代码来源:Utils.cs

示例2: CorruptDictionary

 public void CorruptDictionary()
 {
     BEncodedList l = new BEncodedList();
     BEncodedDictionary d = new BEncodedDictionary();
     l.Add(d);
     IList<Peer> decoded = Peer.Decode(l);
     Assert.AreEqual(0, decoded.Count, "#1");
 }
开发者ID:JacklEventreur,项目名称:monotorrent,代码行数:8,代码来源:PeerTests.cs

示例3: CorruptDictionary

 public void CorruptDictionary()
 {
     var l = new BEncodedList();
     var d = new BEncodedDictionary();
     l.Add(d);
     IList<Peer> decoded = Peer.Decode(l);
     Assert.Equal(0, decoded.Count);
 }
开发者ID:claudiuslollarius,项目名称:monotorrent,代码行数:8,代码来源:PeerTests.cs

示例4: ErrorMessage

 public ErrorMessage(ErrorCode error, string message)
     : base(ErrorType)
 {
     var l = new BEncodedList();
     l.Add(new BEncodedNumber((int) error));
     l.Add(new BEncodedString(message));
     properties.Add(ErrorListKey, l);
 }
开发者ID:claudiuslollarius,项目名称:monotorrent,代码行数:8,代码来源:ErrorMessage.cs

示例5: CorruptDictionary

        public void CorruptDictionary()
        {
            var list = new BEncodedList();
            var dictionary = new BEncodedDictionary();

            list.Add(dictionary);
            IList<Peer> decoded = Peer.Decode(list);
            Assert.AreEqual(0, decoded.Count, "#1");
        }
开发者ID:Eskat0n,项目名称:OctoTorrent,代码行数:9,代码来源:PeerTests.cs

示例6: benDictionaryEncodingBuffered

 public void benDictionaryEncodingBuffered()
 {
     var data = Encoding.UTF8.GetBytes("d4:spaml1:a1:bee");
     var dict = new BEncodedDictionary();
     var list = new BEncodedList();
     list.Add(new BEncodedString("a"));
     list.Add(new BEncodedString("b"));
     dict.Add("spam", list);
     var result = new byte[dict.LengthInBytes()];
     dict.Encode(result, 0);
     Assert.True(Toolbox.ByteMatch(data, result));
 }
开发者ID:claudiuslollarius,项目名称:monotorrent,代码行数:12,代码来源:BEncodeTest.cs

示例7: benDictionaryEncoding

        public void benDictionaryEncoding()
        {
            var data = Encoding.UTF8.GetBytes("d4:spaml1:a1:bee");

            var dict = new BEncodedDictionary();
            var list = new BEncodedList();
            list.Add(new BEncodedString("a"));
            list.Add(new BEncodedString("b"));
            dict.Add("spam", list);
            Assert.Equal(Encoding.UTF8.GetString(data), Encoding.UTF8.GetString(dict.Encode()));
            Assert.True(Toolbox.ByteMatch(data, dict.Encode()));
        }
开发者ID:claudiuslollarius,项目名称:monotorrent,代码行数:12,代码来源:BEncodeTest.cs

示例8: benDictionaryEncoding

        public void benDictionaryEncoding()
        {
            byte[] data = System.Text.Encoding.UTF8.GetBytes("d4:spaml1:a1:bee");

            BEncodedDictionary dict = new BEncodedDictionary();
            BEncodedList list = new BEncodedList();
            list.Add(new BEncodedString("a"));
            list.Add(new BEncodedString("b"));
            dict.Add("spam", list);
            Assert.AreEqual(System.Text.Encoding.UTF8.GetString(data), System.Text.Encoding.UTF8.GetString(dict.Encode()));
            Assert.IsTrue(Toolbox.ByteMatch(data, dict.Encode()));
        }
开发者ID:burris,项目名称:monotorrent,代码行数:12,代码来源:BEncodingTest.cs

示例9: CorruptList

        public void CorruptList()
        {
            var list = new BEncodedList();
            for (var i = 0; i < peers.Count; i++)
                list.Add((BEncodedString) peers[i].CompactPeer());

            list.Insert(2, new BEncodedNumber(5));
            VerifyDecodedPeers(Peer.Decode(list));

            list.Clear();
            list.Add(new BEncodedString(new byte[3]));
            IList<Peer> decoded = Peer.Decode(list);
            Assert.Equal(0, decoded.Count);
        }
开发者ID:claudiuslollarius,项目名称:monotorrent,代码行数:14,代码来源:PeerTests.cs

示例10: AddCommonStuff

        private void AddCommonStuff(BEncodedDictionary torrent)
        {
            if (Announces.Count > 0 && Announces[0].Count > 0)
                Announce = Announces[0][0];

            if (GetrightHttpSeeds.Count > 0)
            {
                var seedlist = new BEncodedList();
                seedlist.AddRange(
                    GetrightHttpSeeds.ConvertAll<BEncodedValue>(delegate(string s) { return (BEncodedString) s; }));
                torrent["url-list"] = seedlist;
            }

            var span = DateTime.Now - new DateTime(1970, 1, 1);
            torrent["creation date"] = new BEncodedNumber((long) span.TotalSeconds);
        }
开发者ID:claudiuslollarius,项目名称:monotorrent,代码行数:16,代码来源:TorrentCreator.cs

示例11: CreateTorrent

        private static BEncodedDictionary CreateTorrent(int pieceLength)
        {
            var infoDict = new BEncodedDictionary();
            infoDict[new BEncodedString("piece length")] = new BEncodedNumber(pieceLength);
            infoDict[new BEncodedString("pieces")] = new BEncodedString(new byte[20*15]);
            infoDict[new BEncodedString("length")] = new BEncodedNumber(15*256*1024 - 1);
            infoDict[new BEncodedString("name")] = new BEncodedString("test.files");

            var dict = new BEncodedDictionary();
            dict[new BEncodedString("info")] = infoDict;

            var announceTier = new BEncodedList();
            announceTier.Add(new BEncodedString("custom://transfers1/announce"));
            announceTier.Add(new BEncodedString("custom://transfers2/announce"));
            announceTier.Add(new BEncodedString("http://transfers3/announce"));
            var announceList = new BEncodedList();
            announceList.Add(announceTier);
            dict[new BEncodedString("announce-list")] = announceList;
            return dict;
        }
开发者ID:claudiuslollarius,项目名称:monotorrent,代码行数:20,代码来源:EngineTestRig.cs

示例12: Handle

		public override void Handle(DhtEngine engine, Node node)
		{
			base.Handle(engine, node);

			BEncodedString token = engine.TokenManager.GenerateToken(node);
			var response = new GetPeersResponse(engine.RoutingTable.LocalNode.Id, TransactionId, token);
			if (engine.Torrents.ContainsKey(InfoHash))
			{
				var list = new BEncodedList();
				foreach (Node n in engine.Torrents[InfoHash])
					list.Add(n.CompactPort());
				response.Values = list;
			}
			else
			{
				// Is this right?
				response.Nodes = Node.CompactNode(engine.RoutingTable.GetClosest(InfoHash));
			}

			engine.MessageLoop.EnqueueSend(response, node.EndPoint);
		}
开发者ID:rajkosto,项目名称:DayZeroLauncher,代码行数:21,代码来源:GetPeers.cs

示例13: Decode

 public static MonoTorrentCollection<Peer> Decode(BEncodedList peers)
 {
     var list = new MonoTorrentCollection<Peer>(peers.Count);
     foreach (var value in peers)
     {
         try
         {
             if (value is BEncodedDictionary)
                 list.Add(DecodeFromDict((BEncodedDictionary) value));
             else if (value is BEncodedString)
                 foreach (var p in Decode((BEncodedString) value))
                     list.Add(p);
         }
         catch
         {
             // If something is invalid and throws an exception, ignore it
             // and continue decoding the rest of the peers
         }
     }
     return list;
 }
开发者ID:claudiuslollarius,项目名称:monotorrent,代码行数:21,代码来源:Peer.cs

示例14: AddCommonStuff

		///<summary>
		///this adds stuff common to single and multi file torrents
		///</summary>
		void AddCommonStuff(BEncodedDictionary torrent)
		{
			if (announces.Count > 0 && announces[0].Count > 0) torrent.Add("announce", new BEncodedString(announces[0][0]));

			// If there is more than one tier or the first tier has more than 1 tracker
			if (announces.Count > 1 || (announces.Count > 0 && announces[0].Count > 1))
			{
				var announceList = new BEncodedList();
				for (var i = 0; i < announces.Count; i++)
				{
					var tier = new BEncodedList();
					for (var j = 0; j < announces[i].Count; j++) tier.Add(new BEncodedString(announces[i][j]));

					announceList.Add(tier);
				}

				torrent.Add("announce-list", announceList);
			}

			var epocheStart = new DateTime(1970, 1, 1);
			var span = DateTime.Now - epocheStart;
			Logger.Log(null, "creation date: {0} - {1} = {2}:{3}", DateTime.Now, epocheStart, span, span.TotalSeconds);
			torrent.Add("creation date", new BEncodedNumber((long)span.TotalSeconds));
		}
开发者ID:GoogleFrog,项目名称:Zero-K-Infrastructure,代码行数:27,代码来源:TorrentCreator.cs

示例15: SaveNodes

        public byte[] SaveNodes()
        {
            BEncodedList details = new BEncodedList();

            MainLoop.QueueWait((MainLoopTask)delegate {
                foreach (Bucket b in RoutingTable.Buckets)
                {
                    foreach (Node n in b.Nodes)
                        if (n.State != NodeState.Bad)
                            details.Add(n.CompactNode());

                    if (b.Replacement != null)
                        if (b.Replacement.State != NodeState.Bad)
                            details.Add(b.Replacement.CompactNode());
                }
            });

            return details.Encode();
        }
开发者ID:mrscylla,项目名称:octotorrent,代码行数:19,代码来源:DhtEngine.cs


注:本文中的BEncodedList类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。