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 manager = TestRig.CreatePrivate(); 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"); }
public async Task AddPeers_Tracker_Private() { var manager = TestRig.CreatePrivate(); using var engine = new ClientEngine(); await engine.Register(manager); 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 void MismatchedPeerId_PrivateTorrent() { var manager = TestRig.CreatePrivate(); 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)); }
public void EmptyPeerId_PrivateTorrent() { var manager = TestRig.CreatePrivate(); manager.Mode = new DownloadMode(manager, DiskManager, ConnectionManager, Settings); var peer = PeerId.CreateNull(manager.Bitfield.Length); peer.Peer.PeerId = null; var handshake = new HandshakeMessage(manager.InfoHash, new BEncodedString(Enumerable.Repeat('c', 20).ToArray()), VersionInfo.ProtocolStringV100, false); manager.Mode.HandleMessage(peer, handshake); Assert.AreEqual(handshake.PeerId, peer.PeerID); }
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)); }
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); }