Esempio n. 1
0
 public async void Start()
 {
     if (Interlocked.Exchange(ref started, 1) == 0)
     {
         connectThread.Start();
         try
         {
             listener.Start();
         }
         catch (SocketException)
         {
             return;
         }
         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.Disconnected        += RemoteNode_Disconnected;
             remoteNode.PeersReceived       += RemoteNode_PeersReceived;
             remoteNode.BlockReceived       += RemoteNode_BlockReceived;
             remoteNode.TransactionReceived += RemoteNode_TransactionReceived;
             remoteNode.StartProtocol();
         }
     }
 }
Esempio n. 2
0
 public async Task ConnectToPeerAsync(IPEndPoint remoteEndpoint)
 {
     if (remoteEndpoint.Equals(LocalEndpoint)) return;
     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();
 }
Esempio n. 3
0
 public async void Start()
 {
     if (Interlocked.Exchange(ref started, 1) == 0)
     {
         connectThread.Start();
         try
         {
         listener.Start();
         }
         catch (SocketException)
         {
             return;
         }
         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.Disconnected += RemoteNode_Disconnected;
             remoteNode.PeersReceived += RemoteNode_PeersReceived;
             remoteNode.BlockReceived += RemoteNode_BlockReceived;
             remoteNode.TransactionReceived += RemoteNode_TransactionReceived;
             remoteNode.StartProtocol();
         }
     }
 }