Exemple #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();
 }
Exemple #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();
     }
 }
Exemple #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();
     }
 }
Exemple #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();
 }
Exemple #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();
         }
     }
 }
Exemple #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();
 }
Exemple #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();
     }
 }