Beispiel #1
0
        public async Task ConnectToPeerAsync(IPEndPoint remoteEndpoint)
        {
            if (remoteEndpoint.Port == Port && LocalAddresses.Contains(remoteEndpoint.Address))
            {
                return;
            }

            lock (unconnectedPeers)
            {
                unconnectedPeers.Remove(remoteEndpoint);
            }
            lock (connectedPeers)
            {
                if (connectedPeers.Any(p => remoteEndpoint.Equals(p.ListenerEndpoint)))
                {
                    return;
                }
            }

            TcpRemotePeer remoteNode = new TcpRemotePeer(this, remoteEndpoint);

            if (await remoteNode.ConnectAsync())
            {
                OnConnected(remoteNode);
            }
        }
Beispiel #2
0
 private async void AcceptPeers()
 {
     while (!cancellationTokenSource.IsCancellationRequested)
     {
         Socket socket;
         try
         {
             socket = await listener.AcceptSocketAsync();
         }
         catch (ObjectDisposedException)
         {
             break;
         }
         catch (SocketException)
         {
             continue;
         }
         TcpRemotePeer remoteNode = new TcpRemotePeer(this, socket);
         OnConnected(remoteNode);
     }
 }