async void ConnectionReceived(object?sender, PeerConnectionEventArgs e)
        {
            await ClientEngine.MainLoop;
            var peer = new Peer("", e.Connection.Uri, EncryptionTypes.All);

            try {
                if (Engine.ConnectionManager.ShouldBanPeer(peer))
                {
                    e.Connection.Dispose();
                    return;
                }
                if (!e.Connection.IsIncoming)
                {
                    var manager = Engine.Torrents.FirstOrDefault(t => t.InfoHashes.Contains(e.InfoHash !)) !;
                    var id      = new PeerId(peer, e.Connection, new BitField(manager.Bitfield.Length).SetAll(false));
                    id.LastMessageSent.Restart();
                    id.LastMessageReceived.Restart();

                    Engine.ConnectionManager.ProcessNewOutgoingConnection(manager, id);
                    return;
                }

                logger.Info(e.Connection, "ConnectionReceived");

                var supportedEncryptions = EncryptionTypes.GetSupportedEncryption(peer.AllowedEncryption, Engine.Settings.AllowedEncryption);
                EncryptorFactory.EncryptorResult result = await EncryptorFactory.CheckIncomingConnectionAsync(e.Connection, supportedEncryptions, SKeys, Engine.Factories);

                if (!await HandleHandshake(peer, e.Connection, result.Handshake !, result.Decryptor, result.Encryptor))
                {
                    e.Connection.Dispose();
                }
            } catch {
                e.Connection.Dispose();
            }
        }
 internal void RaisePeerDisconnected(PeerConnectionEventArgs args)
 {
     Mode.HandlePeerDisconnected(args.PeerID);
     Toolbox.RaiseAsyncEvent <PeerConnectionEventArgs>(PeerDisconnected, this, args);
 }
Beispiel #3
0
        private void PeerDisconnected(object sender, PeerConnectionEventArgs e)
        {
            lock (_peersLock)
            {
                var p = (HdknPeer)_peers.FirstOrDefault(i => i.PeerId == e.PeerID.PeerID);

                if (p != null)
                    _peers.Remove(p);
            }
        }
 internal void RaisePeerConnected(PeerConnectionEventArgs args)
 {
     Toolbox.RaiseAsyncEvent <PeerConnectionEventArgs>(PeerConnected, this, args);
 }
Beispiel #5
0
 private void PeerConnected(object o, PeerConnectionEventArgs e)
 {
     if (e.ConnectionDirection == MonoTorrent.Common.Direction.Incoming)
         natStatus.HasIncoming = true;
 }
Beispiel #6
0
        private void PeerConnected(object sender, PeerConnectionEventArgs e)
        {
            HdknPeer p = new HdknPeer(e.PeerID);

            lock (_peersLock)
            {
                _peers.Add(p);
            }
        }
Beispiel #7
0
        static void cm_PeerDisconnected(object sender, PeerConnectionEventArgs e)
        {
		if (e.PeerID == null)
			return;
		lock (queue){
			queue.Add (String.Format("{0} peer at {1}. Reason: {2}",
                    		e.ConnectionDirection == Direction.Incoming ? "Got disconnected from" : "Disconnected from",
                    		e.PeerID.Uri, e.Message));
		}
        }
Beispiel #8
0
        static void cm_PeerConnected(object sender, PeerConnectionEventArgs e)
        {
		if (e.PeerID == null)
			return;

		lock (queue){
			queue.Add (String.Format("{0} peer at {1}",
				e.ConnectionDirection == Direction.Incoming ? "Accepted connection from" : "Connected to",
				e.PeerID.Uri));

		}
        }
Beispiel #9
0
		private void OnPeerDisconnected (object sender, PeerConnectionEventArgs a)
		{
			TreeIter iter;
			
			if(a.PeerID == null)
				return;
			
			Gtk.Application.Invoke (delegate {
				lock(peers){
					if(!peers.ContainsKey(a.PeerID))
						return;
					iter = peers [a.PeerID];
					peerListStore.Remove (ref iter);
					peers.Remove (a.PeerID);
				}
			});
		}
Beispiel #10
0
		private void OnPeerConnected (object sender, PeerConnectionEventArgs a)
		{
			if(!a.PeerID.IsValid)
				return;
			
			Gtk.Application.Invoke (delegate {
				peers.Add (a.PeerID, peerListStore.AppendValues (a.PeerID.Location, a.PeerID.ClientSoftware.Client.ToString(), a.PeerID.Monitor.DownloadSpeed.ToString(), a.PeerID.Monitor.UploadSpeed.ToString(), a.PeerID.IsSeeder.ToString(), a.PeerID.IsInterested.ToString()));
			});
		}
        private void manager_PeerDisconnected(object sender, PeerConnectionEventArgs args)
        {
            try {
                LoggingService.LogDebug("Peer Disconnected: {0}", args.PeerID.Uri);

                // Find the matching peer
                bool found = false;

                string nodeID = args.PeerID.Uri.AbsolutePath;
                lock (this.peers) {
                    foreach (BitTorrentFileTransferPeer peer in this.peers) {
                        if (nodeID == peer.Node.NodeID) {
                            this.peers.Remove(peer);
                            found = true;
                            break;
                        }
                    }
                }
                if (!found) {
                    // This should never hapen.
                    LoggingService.LogWarning("PeerDisconnected: Unknown peer!");
                }

                if (base.peers.Count == 0) {
                    if (manager.Progress != 100) {
                        // Transfer didn't finish, cancel!
                        LoggingService.LogWarning("No more peers - canceling torrent!");
                        this.Cancel();
                    } else {
                        // Transfer was complete (or an upload), just stop normally.
                        manager.Stop();
                    }
                }
            } catch (Exception ex) {
                LoggingService.LogError("Error in manager_PeerDisconnected:", ex);
                this.Cancel();
            }
        }
        private void manager_PeerConnected(object sender, PeerConnectionEventArgs args)
        {
            try {
                LoggingService.LogDebug("PEER CONNECTED: {0} {1}", args.PeerID.Uri, args.PeerID.GetHashCode());

                // XXX: This check can probably be removed.
                if (args.TorrentManager != this.manager) {
                    throw new Exception("PeerConnected for wrong manager. This should NEVER happen.");
                }

                // Now, match the peer to the internal BittorrentFileTransferPeer.
                lock (this.peers) {
                    foreach (BitTorrentFileTransferPeer peer in this.peers) {
                        string nodeID = args.PeerID.Uri.AbsolutePath;
                        if (nodeID == peer.Node.NodeID) {
                            ITransport transport = ((TorrentConnection)args.PeerID.Connection).Transport;
                            transport.Operation = new FileTransferOperation(transport, this, peer);

                            peer.AddPeerId(args.PeerID);
                            return;
                        }
                    }
                }

                // If we got here, then we were not expecting this peer.
                throw new Exception("Unexpected peer!!!! - " + args.PeerID.Uri.ToString());
            } catch (Exception ex) {
                LoggingService.LogError("Error in manager_PeerConnected.", ex);
                args.PeerID.CloseConnection();
            }
        }
		public void OnPeerDisconnected(object sender, PeerConnectionEventArgs args)
		{
            if (!mainForm.IsDisposing)
				mainForm.Invoke(new PeerHandler(DeletePeer), args.PeerID);
		}