public void TorrentInfo_ViyFile() { TorrentInfo torrentFile = new TorrentInfo(); torrentFile.Announce = "http://bt4.rutracker.org/ann?uk=wa36F12BA3"; torrentFile.Comment = "http://rutracker.org/forum/viewtopic.php?t=4390356"; torrentFile.PieceLength = 262144; torrentFile.AnnounceList = new System.Collections.Generic.List <string> { "http://bt4.rutracker.org/ann?uk=wa36F12BA3", "http://retracker.local/announce" }; torrentFile.Files = new System.Collections.Generic.List <(string, long)> { ("Soft7/DirectX14/dxwebsetup.exe", 299864), ("Soft6/Redist16/vcredist_x86.exe", 4995416), ("Soft6/Redist16/vcredist_x64.exe", 4877648), ("Data.bin", 180935132), ("Setup.exe", 7389257), ("Survivors Viy.ico", 118921), ("autorun.inf", 70), }; BencodeParser parser = new BencodeParser(_viyFilePath); TorrentInfo expectedTorrentFile = parser.GetTorrentInfo(); torrentFile.InfoHash = new Sha1Encryptor().GetHash(parser.ReadInfoValue()); Assert.AreEqual(expectedTorrentFile.Announce, torrentFile.Announce); Assert.AreEqual(expectedTorrentFile.Comment, torrentFile.Comment); Assert.AreEqual(expectedTorrentFile.PieceLength, torrentFile.PieceLength); CollectionAssert.AreEqual(expectedTorrentFile.AnnounceList, torrentFile.AnnounceList); CollectionAssert.AreEqual(expectedTorrentFile.Files, expectedTorrentFile.Files); }
public void TorrentInfo_UbuntuFile() { TorrentInfo torrentFile = new TorrentInfo(); torrentFile.Announce = "http://torrent.ubuntu.com:6969/announce"; torrentFile.Comment = "Ubuntu CD releases.ubuntu.com"; torrentFile.PieceLength = 524288; torrentFile.AnnounceList = new System.Collections.Generic.List <string> { "http://torrent.ubuntu.com:6969/announce", "http://ipv6.torrent.ubuntu.com:6969/announce" }; torrentFile.Files = new System.Collections.Generic.List <(string, long)> { ("ubuntu-19.04-desktop-amd64.iso", 2097152000) }; BencodeParser parser = new BencodeParser(_ubuntuFIlePath); TorrentInfo expectedTorrentFile = parser.GetTorrentInfo(); torrentFile.InfoHash = new Sha1Encryptor().GetHash(parser.ReadInfoValue()); Assert.AreEqual(expectedTorrentFile.Announce, torrentFile.Announce); Assert.AreEqual(expectedTorrentFile.Comment, torrentFile.Comment); Assert.AreEqual(expectedTorrentFile.PieceLength, torrentFile.PieceLength); CollectionAssert.AreEqual(expectedTorrentFile.AnnounceList, torrentFile.AnnounceList); CollectionAssert.AreEqual(expectedTorrentFile.Files, expectedTorrentFile.Files); }
/// <summary> /// Creates an instance. /// </summary> /// <param name="torrentFile">Local path to torrent file.</param> /// <param name="encryptor">Enctypror for computing info_hash. It's desirable to use Sha1Enctyptor</param> public TorrentClient(string torrentFile, IEncryptor encryptor, IConnection connection) { _connection = connection; _peerId = GeneratePeedId().ToUpper(); _uploadedBytes = _downloadedBytes = _leftBytes = 0; _bencodeParser = new BencodeParser(torrentFile); _restClient = new RestClient(); _encryptor = encryptor; _torrentFile = _bencodeParser.GetTorrentInfo(); _torrentFile.InfoHash = _encryptor.GetUrlEncodedHash(_bencodeParser.ReadInfoValue()); _infoHash = _encryptor.GetHashBytes(_bencodeParser.ReadInfoValue()); }