Ejemplo n.º 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();
 }
Ejemplo n.º 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();
     }
 }
Ejemplo n.º 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();
     }
 }
Ejemplo n.º 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();
 }
Ejemplo n.º 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();
         }
     }
 }
Ejemplo n.º 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();
 }
Ejemplo n.º 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();
     }
 }