private void OnConnected(RemoteNode remoteNode) { lock (connectedPeers) { connectedPeers.Add(remoteNode); } remoteNode.Disconnected += RemoteNode_Disconnected; remoteNode.InventoryReceived += RemoteNode_InventoryReceived; remoteNode.PeersReceived += RemoteNode_PeersReceived; remoteNode.StartProtocol(); }
private async Task AcceptPeersAsync() { while (disposed == 0) { Socket socket; try { socket = await listener.AcceptSocketAsync(); } catch (ObjectDisposedException) { break; } catch (SocketException) { break; } RemoteNode remoteNode = new RemoteNode(this, socket); remoteNode.Disconnected += RemoteNode_Disconnected; remoteNode.InventoryReceived += RemoteNode_InventoryReceived; remoteNode.PeersReceived += RemoteNode_PeersReceived; remoteNode.StartProtocol(); } }
private void AcceptPeersLoop() { while (disposed == 0) { TcpClient tcp; try { tcp = listener.AcceptTcpClient(); } catch (ObjectDisposedException) { break; } catch (SocketException) { break; } RemoteNode remoteNode = new RemoteNode(this, tcp); remoteNode.Disconnected += RemoteNode_Disconnected; remoteNode.InventoryReceived += RemoteNode_InventoryReceived; remoteNode.PeersReceived += RemoteNode_PeersReceived; remoteNode.StartProtocol(); } }
public async Task ConnectToPeerAsync(IPEndPoint remoteEndpoint) { RemoteNode remoteNode; lock (unconnectedPeers) { unconnectedPeers.Remove(remoteEndpoint); } lock (pendingPeers) { lock (connectedPeers) { if (pendingPeers.Any(p => p.RemoteEndpoint == remoteEndpoint) || connectedPeers.ContainsKey(remoteEndpoint)) return; } remoteNode = new RemoteNode(this, remoteEndpoint); pendingPeers.Add(remoteNode); remoteNode.Disconnected += RemoteNode_Disconnected; remoteNode.NewInventory += RemoteNode_NewInventory; remoteNode.NewPeers += RemoteNode_NewPeers; } await remoteNode.ConnectAsync(); }
public async void Start() { if (Interlocked.Exchange(ref started, 1) == 0) { connectWorker.Start(); listener.Start(); while (disposed == 0) { TcpClient tcp; try { tcp = await listener.AcceptTcpClientAsync(); } catch (ObjectDisposedException) { continue; } RemoteNode remoteNode = new RemoteNode(this, tcp); lock (pendingPeers) { pendingPeers.Add(remoteNode); } remoteNode.StartProtocol(); } } }
public async Task ConnectToPeerAsync(IPEndPoint remoteEndpoint) { RemoteNode remoteNode; lock (unconnectedPeers) { unconnectedPeers.Remove(remoteEndpoint); } lock (pendingPeers) { lock (connectedPeers) { if (pendingPeers.Any(p => p.RemoteEndpoint == remoteEndpoint) || connectedPeers.ContainsKey(remoteEndpoint)) return; } remoteNode = new RemoteNode(this, remoteEndpoint); pendingPeers.Add(remoteNode); remoteNode.Disconnected += RemoteNode_Disconnected; remoteNode.PeersReceived += RemoteNode_PeersReceived; remoteNode.BlockReceived += RemoteNode_BlockReceived; remoteNode.TransactionReceived += RemoteNode_TransactionReceived; } await remoteNode.ConnectAsync(); }
private void AcceptPeersLoop() { while (disposed == 0) { TcpClient tcp; try { tcp = listener.AcceptTcpClient(); } catch (ObjectDisposedException) { break; } catch (SocketException) { break; } RemoteNode remoteNode = new RemoteNode(this, tcp); lock (pendingPeers) { pendingPeers.Add(remoteNode); } remoteNode.Disconnected += RemoteNode_Disconnected; remoteNode.PeersReceived += RemoteNode_PeersReceived; remoteNode.BlockReceived += RemoteNode_BlockReceived; remoteNode.TransactionReceived += RemoteNode_TransactionReceived; remoteNode.StartProtocol(); } }