예제 #1
0
        private BProtocol createNegotiatedProtocol(BNegotiate nego)
        {
            BProtocol protocol = null;

            if (nego.protocols.IndexOf(BNegotiate.BINARY_STREAM) == 0)
            {
                int  negotiatedBypsVersion = Math.Min(BMessageHeader.BYPS_VERSION_CURRENT, nego.bversion);
                long negotiatedVersion     = Math.Min(apiDesc.version, nego.version);
                nego.protocols = BNegotiate.BINARY_STREAM;
                if (nego.byteOrder == ByteOrder.UNDEFINED)
                {
                    nego.byteOrder = ByteOrder.LITTLE_ENDIAN;
                }
                if (nego.byteOrder != ByteOrder.LITTLE_ENDIAN)
                {
                    throw new BException(BExceptionC.CORRUPT, "Protocol requires unsupported byte order BIG_ENDIAN");
                }
                nego.version = negotiatedVersion;
                protocol     = new BProtocolS(apiDesc, negotiatedBypsVersion, negotiatedVersion, nego.byteOrder);
            }
            else
            {
                throw new BException(BExceptionC.CORRUPT, "Protocol negotiation failed.");
            }

            return(protocol);
        }
예제 #2
0
 public void setProtocol(BProtocol protocol)
 {
     lock (this)
     {
         this.protocol = protocol;
     }
 }
예제 #3
0
 public void applyNegotiate(BNegotiate nego)
 {
     lock (this)
     {
         BNegotiate negoCopy = new BNegotiate(nego);
         protocol = createNegotiatedProtocol(negoCopy);
         setTargetId(nego.targetId);
         setSessionId(nego.sessionId);
     }
 }
예제 #4
0
        public BTransport(BTransport rhs, BTargetId targetId)
        {
            this.apiDesc   = rhs.apiDesc;
            this.wire      = rhs.wire;
            this.targetId  = targetId;
            this.sessionId = rhs.sessionId;
            this.protocol  = rhs.getProtocol();

            // Still connected to the server given by rhs.
            this.connectedServerId = rhs.targetId.getServerId();
        }
예제 #5
0
        public BProtocol negotiateProtocolServer(BTargetId targetId, ByteBuffer buf, BAsyncResultIF <ByteBuffer> asyncResult)
        {
            if (log.isDebugEnabled())
            {
                log.debug("negotiateProtocolServer(targetId=" + targetId);
            }
            BProtocol ret = null;

            try
            {
                if (log.isDebugEnabled())
                {
                    log.debug("read nego msg");
                }
                BNegotiate nego = new BNegotiate();
                nego.read(buf);

                lock (this)
                {
                    this.protocol = ret = createNegotiatedProtocol(nego);
                    this.setTargetId(targetId);
                    this.setSessionId(targetId.toSessionId());
                }
                if (log.isDebugEnabled())
                {
                    log.debug("protocol=" + this.protocol + ", targetId=" + this.targetId);
                }

                ByteBuffer bout = ByteBuffer.allocate(BNegotiate.NEGOTIATE_MAX_SIZE);
                try
                {
                    nego.targetId  = targetId;
                    nego.sessionId = targetId.toSessionId();
                    nego.write(bout);
                    bout.flip();
                    asyncResult.setAsyncResult(bout, null);
                }
                finally
                {
                }
            }
            catch (Exception e)
            {
                asyncResult.setAsyncResult(null, e);
            }
            if (log.isDebugEnabled())
            {
                log.debug(")negotiateProtocolServer=" + ret);
            }
            return(ret);
        }
예제 #6
0
        private BProtocol detectProtocolFromInputBuffer(ByteBuffer buf)
        {
            BProtocol ret = null;

            // Read the first 4 bytes to detect the protocol.
            int magic = BMessageHeader.detectProtocol(buf);

            if (magic == BMessageHeader.MAGIC_BINARY_STREAM)
            {
                // Version, ByteOrder wird in BInput gelesen
                ret = new BProtocolS(apiDesc);
            }

            if (ret == null)
            {
                throw new BException(BExceptionC.CORRUPT, "Invalid protocol.");
            }

            return(ret);
        }
예제 #7
0
        public virtual BProtocol negotiate(BTargetId targetId, ByteBuffer bin, BAsyncResultIF <ByteBuffer> asyncResult)
        {
            BProtocol protocol = transport.negotiateProtocolServer(targetId, bin, asyncResult);

            return(protocol);
        }