Ejemplo n.º 1
0
        async void HandleLocalPeerFound(object sender, LocalPeerFoundEventArgs args)
        {
            try {
                await MainLoop;

                TorrentManager manager = allTorrents.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)
            }
        }