예제 #1
0
        public bool Setup(string host, int port)
        {
            Setup();

            if (tcpClient == null)
            {
                try
                {
                    tcpClient = new TcpClient();
                    tcpClient.Connect(host, port);
                    var cryptStream = new CryptedStream(tcpClient.GetStream(), keyPair);
                    if (cryptStream.Setup())
                    {
                        upstreamNode = SetupNode(cryptStream);
                        return(true);
                    }
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e);
                }

                tcpClient.Close();
                tcpClient = null;
                return(false);
            }
            else
            {
                return(true);
            }
        }
예제 #2
0
 private void AcceptLoop()
 {
     while (true)
     {
         var client      = tcpListener.AcceptTcpClient();
         var cryptStream = new CryptedStream(client.GetStream(), keyPair);
         if (cryptStream.Setup(key => TrustedKeys.Contains(key)))
         {
             SetupNode(cryptStream);
         }
     }
 }