private void DisconnectPeer(IPEndPoint remoteEndpoint, Exception e) { this.badPeers.Add(remoteEndpoint); //TODO this.unconnectedPeers.TryRemove(remoteEndpoint.ToCandidatePeerKey()); RemoteNode pendingPeer; this.pendingPeers.TryRemove(remoteEndpoint, out pendingPeer); RemoteNode connectedPeer; this.connectedPeers.TryRemove(remoteEndpoint, out connectedPeer); this.logger.DebugException("Remote peer failed: {0}".Format2(remoteEndpoint), e); if (pendingPeer != null) { UnwireNode(pendingPeer); pendingPeer.Disconnect(); } if (connectedPeer != null) { UnwireNode(connectedPeer); connectedPeer.Disconnect(); } }
private async Task <RemoteNode> ConnectToPeer(IPEndPoint remoteEndPoint) { try { var remoteNode = new RemoteNode(remoteEndPoint, this.logger); this.unconnectedPeers.TryRemove(remoteEndPoint.ToCandidatePeerKey()); this.pendingPeers.TryAdd(remoteNode.RemoteEndPoint, remoteNode); var success = await ConnectAndHandshake(remoteNode, isIncoming : false); if (success) { await PeerStartup(remoteNode); return(remoteNode); } else { //this.knownAddressCache[remoteEndPoint.ToNetworkAddressKey()] = // new NetworkAddressWithTime(0, remoteEndPoint.ToNetworkAddress(0)); DisconnectPeer(remoteEndPoint, null); return(null); } } catch (Exception e) { this.logger.DebugException("Could not connect to {0}".Format2(remoteEndPoint), e); //this.knownAddressCache[remoteEndPoint.ToNetworkAddressKey()] = // new NetworkAddressWithTime(0, remoteEndPoint.ToNetworkAddress(0)); DisconnectPeer(remoteEndPoint, e); return(null); } }