Esempio n. 1
0
        public void ReadDictionaryOfDictionaries()
        {
            BenDecoder  decoder    = DecoderForString("d4:dictd4:spam4:eggsee");
            IDictionary dictionary = decoder.ReadDictionary();

            Assert.AreEqual(1, dictionary.Count);
            Assert.IsInstanceOfType(typeof(IDictionary), dictionary["dict"]);
        }
Esempio n. 2
0
 public static IDictionary Decode(string fileName)
 {
     FileStream stream = new FileStream(fileName, FileMode.Open);
     BenDecoder decoder = new BenDecoder(stream);
     IDictionary result = decoder.ReadDictionary();
     stream.Close();
     return result;
 }
Esempio n. 3
0
        public void ReadDictionary()
        {
            BenDecoder  decoder    = DecoderForString("d3:cow3:moo4:spam4:eggse");
            IDictionary dictionary = decoder.ReadDictionary();

            Assert.AreEqual(2, dictionary.Count);
            Assert.AreEqual("moo", dictionary["cow"].ToString());
            Assert.AreEqual("eggs", dictionary["spam"].ToString());
        }
Esempio n. 4
0
        public static IDictionary Decode(string fileName)
        {
            FileStream  stream  = new FileStream(fileName, FileMode.Open);
            BenDecoder  decoder = new BenDecoder(stream);
            IDictionary result  = decoder.ReadDictionary();

            stream.Close();
            return(result);
        }
Esempio n. 5
0
 static void Main(string[] args)
 {
     string filename = args[0];
     BenDecoder decoder = new BenDecoder(File.OpenRead(filename));
     Torrent torrent = new Torrent(decoder.ReadDictionary());
     Console.WriteLine("Tracker: {0}", torrent.AnnounceUri);
     Console.WriteLine("Number of pieces: {0}", torrent.Pieces.Count);
     Console.WriteLine("Piece length: {0}", torrent.PieceLength);
     Console.WriteLine("Hash: {0}", torrent.InfoHash.ToHexString());
     Console.WriteLine("Files:");
     foreach (ITorrentFile file in torrent.Files)
     {
         Console.WriteLine("  Name: {0}, Size: {1}", file.Name, file.Length);
     }
 }
Esempio n. 6
0
 public TrackerResponse(ByteString responseText)
 {
     HttpResponse response = new HttpResponse(responseText);
     BenDecoder decoder = new BenDecoder(new MemoryStream(response.Content.ToBytes()));
     responseContent = decoder.ReadDictionary();
     
     if(IsSuccessful)
     {
         ByteString peers = responseContent["peers"] as ByteString;
         BinaryReader reader = new BinaryReader(new MemoryStream(peers.ToBytes()));
         for(int i = 0; i<peers.ToBytes().Length; i+=6)
         {
             peerList.Add(new PeerInfo(reader.ReadBytes(4), reader.ReadInt16()));
         }
     }
 }
Esempio n. 7
0
        public TrackerResponse(ByteString responseText)
        {
            HttpResponse response = new HttpResponse(responseText);
            BenDecoder   decoder  = new BenDecoder(new MemoryStream(response.Content.ToBytes()));

            responseContent = decoder.ReadDictionary();

            if (IsSuccessful)
            {
                ByteString   peers  = responseContent["peers"] as ByteString;
                BinaryReader reader = new BinaryReader(new MemoryStream(peers.ToBytes()));
                for (int i = 0; i < peers.ToBytes().Length; i += 6)
                {
                    peerList.Add(new PeerInfo(reader.ReadBytes(4), reader.ReadInt16()));
                }
            }
        }
Esempio n. 8
0
        public void NonsenceInputThrowsException()
        {
            BenDecoder decoder = DecoderForString("Nonsence!");

            decoder.ReadDictionary();
        }