public void ExtractInfoHash()
        {
            Bencoder   bc  = new Bencoder();
            MnlMessage msg = new MnlMessage
                             .Builder(ParseTest.ConvertHexStringToByteArray("64313a6164323a696432303a7200ee612a3d17f22d721a8019317eb27c7039c9393a696e666f5f6861736832303af6ef92f7cfa792c050fef70c405ded104771553d363a6e6f7365656469316565313a71393a6765745f7065657273313a74343a9b9427a4313a76343a5554ab14313a79313a7165"))
                             .Build();

            MnlMessage myMsg = new MnlMessage
                               .Builder(ParseTest.ConvertHexStringToByteArray("64313a74323a3032313a79313a71313a71393a6765745f7065657273313a6164323a696432303a09dc0cea8478d7f285ef674c6a2f931ae3b603f4393a696e666f5f6861736832303a3f4f40163040223f3f063f3a562f603e3f543f3f6565"))
                               .Build();



            Dictionary <string, object> decoded   = (Dictionary <string, object>)bc.DecodeElement(ParseTest.ConvertHexStringToByteArray("64313a6164323a696432303ab2dfb21aa9b31c00cdca99bcd9232a7facbc76e2393a696e666f5f6861736832303aa44f7b0766a4e53ebfc0cf79fa9c82778b88d94765313a71393a6765745f7065657273313a74343a67707588313a79313a7165"));
            Dictionary <string, object> decodedMy = (Dictionary <string, object>)bc.DecodeElement(ParseTest.ConvertHexStringToByteArray("64313a74323a3034313a79313a71313a71393a6765745f7065657273313a6164323a696432303ae36f5d8ef6928691d9696e02d025e3b8f1a08ca2393a696e666f5f6861736832303a139f69de76a07790ec3ad31cbc3bd5d9058716006565"));
            var infoHash = Encoding.UTF8.GetBytes((string)((Dictionary <string, object>)decoded["a"])["info_hash"]);

            var bytes = ParseTest.ConvertHexStringToByteArray("3F4F40163040223F3F063F3A562F603E3F543F3F");

            //CollectionAssert.AreEqual(infoHash, bytes);

            SoapHexBinary hex = new SoapHexBinary(infoHash);

            Debug.WriteLine($"Info hash: {hex.ToString()} ");
        }
Exemple #2
0
        public void ParseInput(ParseTest parseTest)
        {
            var parser = new Parser();
            var result = parser.Parse(parseTest.Input);

            Console.WriteLine(result.Evaluated);
            Console.WriteLine(result.Parsed);
            Console.WriteLine(result.Type);

            Assert.That(result.Evaluated, Is.EqualTo(parseTest.Evaluated));
            Assert.That(result.Parsed, Is.EqualTo(parseTest.Parsed));
            Assert.That(result.Type, Is.EqualTo(parseTest.Type));
        }
Exemple #3
0
        public void TestLocation()
        {
            string   @in      = new ParseTest().GetFilePath("/htmltests/yahoo-jp.html");
            Document doc      = Dcsoup.ParseFile(@in, "UTF-8", "http://www.yahoo.co.jp/index.html");
            string   location = doc.Location;
            string   baseUri  = doc.BaseUri;

            Assert.AreEqual("http://www.yahoo.co.jp/index.html", location);
            Assert.AreEqual("http://www.yahoo.co.jp/_ylh=X3oDMTB0NWxnaGxsBF9TAzIwNzcyOTYyNjUEdGlkAzEyBHRtcGwDZ2Ex/", baseUri);
            @in      = new ParseTest().GetFilePath("/htmltests/nyt-article-1.html");
            doc      = Dcsoup.ParseFile(@in, null, "http://www.nytimes.com/2010/07/26/business/global/26bp.html?hp");
            location = doc.Location;
            baseUri  = doc.BaseUri;
            Assert.AreEqual("http://www.nytimes.com/2010/07/26/business/global/26bp.html?hp", location);
            Assert.AreEqual("http://www.nytimes.com/2010/07/26/business/global/26bp.html?hp", baseUri);
        }
Exemple #4
0
        public void GetPeers()   // - new info hash 3F4F7B07663F3F3E3F3F3F793F3F3F773F3F3F47
        {
            Node node  = new Node(new System.Net.IPEndPoint(IPAddress.Loopback, 8881));
            var  bytes = ParseTest.ConvertHexStringToByteArray("f6ef92f7cfa792c050fef70c405ded104771553d");
            //Array.Reverse(bytes);
            Id infoHash = new Id(bytes);

            CollectionAssert.AreEqual(infoHash.Value, ParseTest.ConvertHexStringToByteArray("f6ef92f7cfa792c050fef70c405ded104771553d"));

            IEnumerable <ContactNode> nodes = null;
            object token = null;

            Assert.IsTrue(node.GetPeers(new ContactNode(Id.GenerateRandom(), new IPEndPoint(IPAddress.Loopback, 8999)), infoHash, out nodes, out token));

            node.Shutdown();
        }
Exemple #5
0
        public void FindPeers()
        {
            Node node = new Node(new System.Net.IPEndPoint(IPAddress.Any, 8881));

            ContactNode qbitContact = new ContactNode(Id.GenerateRandom(), new IPEndPoint(IPAddress.Loopback, 8999));

            MnlMessage pingResp = node.Ping(qbitContact);

            qbitContact = new ContactNode(new Id((byte[])pingResp.Payload["id"]), qbitContact.EndPoint);

            node.BucketList.Put(qbitContact);

            HashTable hashTable = new HashTable(node, new IPEndPoint[] { new IPEndPoint(IPAddress.Loopback, 8999) }, 8881);

            Id infoHash = new Id(ParseTest.ConvertHexStringToByteArray("139f69de76a07790ec3ad31cbc3bd5d905871600"));

            var foundPeers = hashTable.FindPeers(infoHash);

            Assert.IsTrue(foundPeers.Count() > 0);

            node.Shutdown();
        }
        public void CalcInfoHash()
        {
            Metainfo mf = new Metainfo(File.ReadAllBytes("infHash.torrent"), Encoding.ASCII);

            CollectionAssert.AreEqual(mf.InfoHash, ParseTest.ConvertHexStringToByteArray("139f69de76a07790ec3ad31cbc3bd5d905871600"));
        }