Ejemplo n.º 1
0
        protected void Connect()
        {
            try
            {
                socket = Peer.CreateTransport(Peer.Host, Peer.Port);

                if (TraceLevel >= TraceHandshake)
                {
                    Logger.Debug($"-> MD5 CONNECT TO {Peer.Host}:{Peer.Port}");
                }

                int nameTag = SendName(Peer.DistChoose, Local.CapFlags, Local.Creation);
                RecvStatus();
                int    peer_challenge = RecvChallenge();
                byte[] our_digest     = GenDigest(peer_challenge, Local.Cookie);
                int    our_challenge  = GenChallenge();
                SendComplement(nameTag);
                SendChallengeReply(our_challenge, our_digest);
                RecvChallengeAck(our_challenge);
                Connected  = true;
                cookieOk   = true;
                sendCookie = false;
                if (TraceLevel >= TraceHandshake)
                {
                    Logger.Debug($"-> CONNECTED TO {Peer.Host}:{Peer.Port}");
                }
            }
            catch (IOException)
            {
                Close();
                throw;
            }
            catch (OtpAuthException)
            {
                Close();
                throw;
            }
            catch (Exception e)
            {
                Close();
                throw new IOException("Cannot connect to peer node", e);
            }
        }