readN() public method

public readN ( byte buf ) : int
buf byte
return int
Esempio n. 1
0
        protected internal virtual void  recvStatus()
        {

            try
            {
                byte[] buf = read2BytePackage();
                OtpInputStream ibuf = new OtpInputStream(buf);
                int tag = ibuf.read1();
                if (tag != ChallengeStatus)
                {
                    throw new System.IO.IOException("Handshake protocol error");
                }
                byte[] tmpbuf = new byte[buf.Length - 1];
                ibuf.readN(tmpbuf);
                char[] tmpChar;
                tmpChar = new char[tmpbuf.Length];
                tmpbuf.CopyTo(tmpChar, 0);
                System.String status = new System.String(tmpChar);

                if (status.CompareTo("ok") != 0)
                {
                    throw new System.IO.IOException("Peer replied with status '" + status + "' instead of 'ok'");
                }
            }
            catch (Erlang.Exception)
            {
                throw new System.IO.IOException("Handshake failed - not enough data");
            }
            catch (System.Net.Sockets.SocketException e)
            {
                throw new System.IO.IOException("Peer dropped connection: " + e.ToString());
            }

            if (traceLevel >= OtpTrace.Type.handshakeThreshold)
            {
                OtpTrace.TraceEvent("<- " + "HANDSHAKE recvStatus (ok)" + " local=" + self);
            }
        }
Esempio n. 2
0
 protected internal virtual void  recvChallengeAck(int our_challenge)
 {
     
     byte[] her_digest = new byte[16];
     try
     {
         byte[] buf = read2BytePackage();
         OtpInputStream ibuf = new OtpInputStream(buf);
         int tag = ibuf.read1();
         if (tag != ChallengeAck)
         {
             throw new System.IO.IOException("Handshake protocol error");
         }
         ibuf.readN(her_digest);
         byte[] our_digest = genDigest(our_challenge, auth_cookie);
         if (!digests_equals(her_digest, our_digest))
         {
             throw new OtpAuthException("Peer authentication error.");
         }
     }
     catch (Erlang.Exception)
     {
         throw new System.IO.IOException("Handshake failed - not enough data");
     }
     catch (System.Exception)
     {
         throw new OtpAuthException("Peer authentication error.");
     }
     
     if (traceLevel >= OtpTrace.Type.handshakeThreshold)
     {
         OtpTrace.TraceEvent("<- " + "HANDSHAKE recvChallengeAck" + " from=" + peer._node + " digest=" + hex(her_digest) + " local=" + self);
     }
 }
Esempio n. 3
0
 protected internal virtual int recvChallenge()
 {
     
     int challenge;
     
     try
     {
         byte[] buf = read2BytePackage();
         OtpInputStream ibuf = new OtpInputStream(buf);
         peer.ntype = ibuf.read1();
         if (peer.ntype != AbstractNode.NTYPE_R6)
         {
             throw new System.IO.IOException("Unexpected peer type");
         }
         peer._distLow = (peer._distHigh = ibuf.read2BE());
         peer.flags = ibuf.read4BE();
         challenge = ibuf.read4BE();
         byte[] tmpname = new byte[buf.Length - 11];
         ibuf.readN(tmpname);
         char[] tmpChar;
         tmpChar = new char[tmpname.Length];
         tmpname.CopyTo(tmpChar, 0);
         System.String hisname = new System.String(tmpChar);
         int i = hisname.IndexOf((System.Char) '@', 0);
         peer._node = hisname;
         peer._alive = hisname.Substring(0, (i) - (0));
         peer._host = hisname.Substring(i + 1, (hisname.Length) - (i + 1));
     }
     catch (Erlang.Exception)
     {
         throw new System.IO.IOException("Handshake failed - not enough data");
     }
     
     if (traceLevel >= OtpTrace.Type.handshakeThreshold)
     {
         OtpTrace.TraceEvent("<- " + "HANDSHAKE recvChallenge" + " from=" + peer._node + " challenge=" + challenge + " local=" + self);
     }
     
     return challenge;
 }
Esempio n. 4
0
        protected internal virtual void  recvName(OtpPeer peer)
        {
            
            System.String hisname = "";
            
            try
            {
                byte[] tmpbuf = read2BytePackage();
                OtpInputStream ibuf = new OtpInputStream(tmpbuf);
                byte[] tmpname;
                int len = (int) (tmpbuf.Length);
                peer.ntype = ibuf.read1();
                if (peer.ntype != AbstractNode.NTYPE_R6)
                {
                    throw new System.IO.IOException("Unknown remote node type");
                }
                peer._distLow = (peer._distHigh = ibuf.read2BE());
                if (peer._distLow < 5)
                {
                    throw new System.IO.IOException("Unknown remote node type");
                }
                peer.flags = ibuf.read4BE();
                tmpname = new byte[len - 7];
                ibuf.readN(tmpname);
                char[] tmpChar;
                tmpChar = new char[tmpname.Length];
                tmpname.CopyTo(tmpChar, 0);
                hisname = new System.String(tmpChar);
                // Set the old nodetype parameter to indicate hidden/normal status
                // When the old handshake is removed, the ntype should also be.
                if ((peer.flags & AbstractNode.dFlagPublished) != 0)
                    peer.ntype = AbstractNode.NTYPE_R4_ERLANG;
                else
                    peer.ntype = AbstractNode.NTYPE_R4_HIDDEN;


                if ((peer.flags & AbstractNode.dFlagExtendedReferences) == 0) 
                {
                    throw new System.IO.IOException("Handshake failed - peer cannot handle extended references");
                }
                  
                if (OtpSystem.useExtendedPidsPorts() && (peer.flags & AbstractNode.dFlagExtendedPidsPorts) == 0) 
                if (true && (peer.flags & AbstractNode.dFlagExtendedPidsPorts) == 0) 
                {
                    throw new System.IO.IOException("Handshake failed - peer cannot handle extended pids and ports");
                }
            }
            catch (Erlang.Exception)
            {
                throw new System.IO.IOException("Handshake failed - not enough data");
            }
            
            
            int i = hisname.IndexOf((System.Char) '@', 0);
            peer._node = hisname;
            peer._alive = hisname.Substring(0, (i) - (0));
            peer._host = hisname.Substring(i + 1, (hisname.Length) - (i + 1));
            
            if (traceLevel >= OtpTrace.Type.handshakeThreshold)
            {
                OtpTrace.TraceEvent("<- " + "HANDSHAKE" + " ntype=" + peer.ntype + " dist=" + peer._distHigh + " remote=" + peer);
            }
        }
Esempio n. 5
0
        protected internal virtual int recvChallengeReply(int our_challenge)
        {
            int challenge;
            byte[] her_digest = new byte[16];

            try
            {
                byte[] buf = read2BytePackage();
                OtpInputStream ibuf = new OtpInputStream(buf);
                int tag = ibuf.read1();
                if (tag != ChallengeReply)
                {
                    throw new System.IO.IOException("Handshake protocol error");
                }
                challenge = ibuf.read4BE();
                ibuf.readN(her_digest);
                byte[] our_digest = genDigest(our_challenge, self.cookie());
                if (!digests_equals(her_digest, our_digest))
                {
                    throw new OtpAuthException("Peer authentication error.");
                }
            }
            catch (Erlang.DecodeException)
            {
                throw new System.IO.IOException("Handshake failed - not enough data");
            }

            if (traceLevel >= handshakeThreshold)
            {
                System.Console.Out.WriteLine("<- " + "HANDSHAKE recvChallengeReply" + " from=" + peer._node + " challenge=" + challenge + " digest=" + hex(her_digest) + " local=" + self);
            }

            return challenge;
        }
Esempio n. 6
0
        protected internal virtual void recvStatus()
        {
            try
            {
                byte[] buf = read2BytePackage();
                OtpInputStream ibuf = new OtpInputStream(buf);
                int tag = ibuf.read1();
                if (tag != ChallengeStatus)
                {
                    throw new System.IO.IOException("Handshake protocol error");
                }
                byte[] tmpbuf = new byte[buf.Length - 1];
                ibuf.readN(tmpbuf);
                char[] tmpChar;
                tmpChar = new char[tmpbuf.Length];
                tmpbuf.CopyTo(tmpChar, 0);
                System.String status = new System.String(tmpChar);

                if (status.CompareTo("ok") != 0)
                {
                    throw new System.IO.IOException("Peer replied with status '" + status + "' instead of 'ok'");
                }
            }
            catch (Erlang.DecodeException)
            {
                throw new System.IO.IOException("Handshake failed - not enough data");
            }
            if (traceLevel >= handshakeThreshold)
            {
                System.Console.Out.WriteLine("<- " + "HANDSHAKE recvStatus (ok)" + " local=" + self);
            }
        }