Пример #1
0
 public void NullHex()
 {
     Assert.Throws <ArgumentNullException>(delegate
     {
         InfoHash.FromHex(null);
     });
 }
Пример #2
0
 public void InvalidHex()
 {
     Assert.Throws <ArgumentException>(delegate
     {
         InfoHash.FromHex("123123123123123123123");
     });
 }
Пример #3
0
 public void HexTest()
 {
     InfoHash hash = Create();
     string hex = hash.ToHex();
     Assert.AreEqual(40, hex.Length, "#1");
     InfoHash other = InfoHash.FromHex(hex);
     Assert.AreEqual(hash, other, "#2");
 }
        public void LoadV2OnlyTorrent()
        {
            // A v2 only torrent does not have a regular infohash
            Assert.IsNull(V2OnlyTorrent.InfoHashes.V1);
            Assert.IsNotNull(V2OnlyTorrent.InfoHashes.V2);

            Assert.IsTrue(V2OnlyTorrent.CreatePieceHashes().GetHash(V2OnlyTorrent.PieceCount - 1).V1Hash.IsEmpty);
            Assert.IsFalse(V2OnlyTorrent.CreatePieceHashes().GetHash(V2OnlyTorrent.PieceCount - 1).V2Hash.IsEmpty);
            Assert.IsFalse(V2OnlyTorrent.CreatePieceHashes().GetHash(0).V2Hash.IsEmpty);

            Assert.AreEqual(InfoHash.FromHex("caf1e1c30e81cb361b9ee167c4aa64228a7fa4fa9f6105232b28ad099f3a302e"), V2OnlyTorrent.InfoHashes.V2);
        }
Пример #5
0
        void ParseMagnetLink(string url)
        {
            string[] splitStr = url.Split('?');
            if (splitStr.Length == 0 || splitStr[0] != "magnet:")
            {
                throw new FormatException("The magnet link must start with 'magnet:?'.");
            }

            if (splitStr.Length == 1)
            {
                return;//no parametter
            }
            string[] parameters = splitStr[1].Split('&', ';');

            for (int i = 0; i < parameters.Length; i++)
            {
                string[] keyval = parameters[i].Split('=');
                if (keyval.Length != 2)
                {
                    throw new FormatException("A field-value pair of the magnet link contain more than one equal'.");
                }
                switch (keyval[0].Substring(0, 2))
                {
                case "xt":    //exact topic
                    if (InfoHash != null)
                    {
                        throw new FormatException("More than one infohash in magnet link is not allowed.");
                    }

                    string val = keyval[1].Substring(9);
                    switch (keyval[1].Substring(0, 9))
                    {
                    case "urn:sha1:":        //base32 hash
                    case "urn:btih:":
                        if (val.Length == 32)
                        {
                            InfoHash = InfoHash.FromBase32(val);
                        }
                        else if (val.Length == 40)
                        {
                            InfoHash = InfoHash.FromHex(val);
                        }
                        else
                        {
                            throw new FormatException("Infohash must be base32 or hex encoded.");
                        }
                        break;
                    }
                    break;

                case "tr":     //address tracker
                    var bytes = UriHelper.UrlDecode(keyval[1]);
                    AnnounceUrls.Add(Encoding.UTF8.GetString(bytes));
                    break;

                case "ws":    //webseed
                case "as":    //acceptable source
                    Webseeds.Add(keyval[1]);
                    break;

                case "dn":    //display name
                    var name = UriHelper.UrlDecode(keyval[1]);
                    Name = Encoding.UTF8.GetString(name);
                    break;

                case "xl":    //exact length
                case "xs":    // eXact Source - P2P link.
                case "kt":    //keyword topic
                case "mt":    //manifest topic
                    //not supported for moment
                    break;

                default:
                    //not supported
                    break;
                }
            }
        }
Пример #6
0
 public void NullHex()
 {
     InfoHash.FromHex(null);
 }
Пример #7
0
 public void InvalidHex()
 {
     InfoHash.FromHex("123123123123123123123");
 }
Пример #8
0
 //[ExpectedException(typeof(ArgumentNullException))]
 public void NullHex()
 {
     Assert.Catch <ArgumentException>(() =>
                                      InfoHash.FromHex(null));
 }
Пример #9
0
 //[ExpectedException (typeof(ArgumentException))]
 public void InvalidHex()
 {
     Assert.Catch <ArgumentException>(() =>
                                      InfoHash.FromHex("123123123123123123123"));
 }