public async Task AddPeers_Tracker_Private()
        {
            var torrent = TestRig.CreatePrivate();

            using var engine = new ClientEngine(EngineSettingsBuilder.CreateForTests());
            var manager = await engine.AddAsync(torrent, "");

            manager.SetTrackerManager(TrackerManager);

            var peersTask = new TaskCompletionSource <TrackerPeersAdded> ();

            manager.PeersFound += (o, e) => {
                if (e is TrackerPeersAdded args)
                {
                    peersTask.TrySetResult(args);
                }
            };

            await TrackerManager.AddTrackerAsync(new Uri ("http://test.tracker"));

            TrackerManager.RaiseAnnounceComplete(TrackerManager.Tiers.Single().ActiveTracker, true, new[] { new Peer("One", new Uri("ipv4://1.1.1.1:1111")), new Peer("Two", new Uri("ipv4://2.2.2.2:2222")) });

            var addedArgs = await peersTask.Task.WithTimeout();

            Assert.AreEqual(2, addedArgs.NewPeers, "#1");
            Assert.AreEqual(2, manager.Peers.AvailablePeers.Count, "#2");
        }
        public async Task AddPeers_PeerExchangeMessage_Private()
        {
            var peer = new byte[] { 192, 168, 0, 1, 100, 0 };
            var dotF = new byte[] { 1 << 0 | 1 << 2 }; // 0x1 means supports encryption, 0x2 means is a seeder
            var id   = PeerId.CreateNull(40);

            id.SupportsFastPeer   = true;
            id.SupportsLTMessages = true;

            var torrent = TestRig.CreatePrivate();

            using var engine = new ClientEngine(EngineSettingsBuilder.CreateForTests());
            var manager = await engine.AddAsync(torrent, "");

            manager.Mode = new DownloadMode(manager, DiskManager, ConnectionManager, Settings);
            var peersTask = new TaskCompletionSource <PeerExchangePeersAdded> ();

            manager.PeersFound += (o, e) => {
                if (e is PeerExchangePeersAdded args)
                {
                    peersTask.TrySetResult(args);
                }
            };

            var exchangeMessage = new PeerExchangeMessage(13, peer, dotF, null);

            manager.Mode.HandleMessage(id, exchangeMessage);

            var addedArgs = await peersTask.Task.WithTimeout();

            Assert.AreEqual(0, addedArgs.NewPeers, "#1");
        }
Beispiel #3
0
        public void Setup()
        {
            Engine = new ClientEngine(EngineSettingsBuilder.CreateForTests());

            PieceWriter = new TestWriter();
            Engine.DiskManager.ChangePieceWriter(PieceWriter);
            Torrent    = TestRig.CreateMultiFileTorrent(new[] { new TorrentFile("path", Piece.BlockSize * 1024, 0, 1024 / 8 - 1, 0, null, null, null) }, Piece.BlockSize * 8, out torrentInfo);
            MagnetLink = new MagnetLink(Torrent.InfoHash, "MagnetDownload");
        }
Beispiel #4
0
        public async Task Setup()
        {
            Engine = new ClientEngine(EngineSettingsBuilder.CreateForTests());

            PieceWriter = new TestWriter();
            await Engine.DiskManager.SetWriterAsync(PieceWriter);

            Torrent    = TestRig.CreateMultiFileTorrent(new[] { new TorrentFile("path", Constants.BlockSize * 1024, 0, 1024 / 8 - 1, 0) }, Constants.BlockSize * 8, out torrentInfo);
            MagnetLink = new MagnetLink(Torrent.InfoHashes, "MagnetDownload");
        }
        public async Task MismatchedPeerId_PrivateTorrent()
        {
            var torrent = TestRig.CreatePrivate();

            using var engine = new ClientEngine(EngineSettingsBuilder.CreateForTests());
            var manager = await engine.AddAsync(torrent, "");

            manager.Mode = new DownloadMode(manager, DiskManager, ConnectionManager, Settings);
            var peer      = PeerId.CreateNull(manager.Bitfield.Length);
            var handshake = new HandshakeMessage(manager.InfoHash, new BEncodedString(Enumerable.Repeat('c', 20).ToArray()), VersionInfo.ProtocolStringV100, false);

            Assert.Throws <TorrentException> (() => manager.Mode.HandleMessage(peer, handshake));
        }
Beispiel #6
0
        public async Task ScrapeWithTruncatedInfoHash()
        {
            var link = new MagnetLink(new InfoHashes(null, new InfoHash(new byte[32])));

            using var engine = new ClientEngine(EngineSettingsBuilder.CreateForTests());
            var manager = await engine.AddAsync(link, "");

            var args = new TrackerRequestFactory(manager).CreateScrape();

            Assert.AreEqual(20, args.InfoHash.Span.Length);
            Assert.IsTrue(manager.InfoHashes.Contains(args.InfoHash));
            Assert.IsNull(manager.InfoHashes.V1);
        }
Beispiel #7
0
        public async Task EmptyPeerId_PrivateTorrent()
        {
            var torrent = TestRig.CreatePrivate();

            using var engine = new ClientEngine(EngineSettingsBuilder.CreateForTests());
            var manager = await engine.AddAsync(torrent, "");

            manager.Mode = new DownloadMode(manager, DiskManager, ConnectionManager, Settings);
            var peer = PeerId.CreateNull(manager.Bitfield.Length);

            peer.Peer.PeerId = null;
            var handshake = new HandshakeMessage(manager.InfoHashes.V1OrV2, new BEncodedString(Enumerable.Repeat('c', 20).ToArray()), Constants.ProtocolStringV100, false);

            manager.Mode.HandleMessage(peer, handshake, default);
            Assert.AreEqual(handshake.PeerId, peer.PeerID);
        }