Beispiel #1
0
 private void OnConnected(RemoteNode remoteNode)
 {
     lock (connectedPeers)
     {
         connectedPeers.Add(remoteNode);
     }
     remoteNode.Disconnected      += RemoteNode_Disconnected;
     remoteNode.InventoryReceived += RemoteNode_InventoryReceived;
     remoteNode.PeersReceived     += RemoteNode_PeersReceived;
     remoteNode.StartProtocol();
 }
Beispiel #2
0
 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();
     }
 }
Beispiel #3
0
 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();
     }
 }
Beispiel #4
0
 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();
 }
Beispiel #5
0
 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();
         }
     }
 }
Beispiel #6
0
 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();
 }
Beispiel #7
0
 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();
     }
 }