Пример #1
0
        async void HandleLocalPeerFound(object sender, LocalPeerFoundEventArgs args)
        {
            try {
                await MainLoop;

                TorrentManager manager = Torrents.FirstOrDefault(t => t.InfoHash == args.InfoHash);
                // There's no TorrentManager in the engine
                if (manager == null)
                {
                    return;
                }

                // The torrent is marked as private, so we can't add random people
                if (manager.HasMetadata && manager.Torrent.IsPrivate)
                {
                    manager.RaisePeersFound(new LocalPeersAdded(manager, 0, 0));
                }
                else
                {
                    // Add new peer to matched Torrent
                    var peer       = new Peer("", args.Uri);
                    int peersAdded = manager.AddPeer(peer, fromTrackers: false, prioritise: true) ? 1 : 0;
                    manager.RaisePeersFound(new LocalPeersAdded(manager, peersAdded, 1));
                }
            } catch {
                // We don't care if the peer couldn't be added (for whatever reason)
            }
        }
Пример #2
0
        async void DhtEnginePeersFound(object o, PeersFoundEventArgs e)
        {
            await MainLoop;

            TorrentManager manager = Torrents.FirstOrDefault(t => t.InfoHash == e.InfoHash);

            if (manager == null)
            {
                return;
            }

            if (manager.CanUseDht)
            {
                int successfullyAdded = await manager.AddPeersAsync(e.Peers);

                manager.RaisePeersFound(new DhtPeersAdded(manager, successfullyAdded, e.Peers.Count));
            }
            else
            {
                // This is only used for unit testing to validate that even if the DHT engine
                // finds peers for a private torrent, we will not add them to the manager.
                manager.RaisePeersFound(new DhtPeersAdded(manager, 0, 0));
            }
        }
Пример #3
0
 public PeriodicTorrent GetTorrent(Torrent torrent)
 {
     return(Torrents.FirstOrDefault(t => t.Torrent.Torrent == torrent));
 }