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); }
public void setProtocol(BProtocol protocol) { lock (this) { this.protocol = protocol; } }
public void applyNegotiate(BNegotiate nego) { lock (this) { BNegotiate negoCopy = new BNegotiate(nego); protocol = createNegotiatedProtocol(negoCopy); setTargetId(nego.targetId); setSessionId(nego.sessionId); } }
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(); }
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); }
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); }
public virtual BProtocol negotiate(BTargetId targetId, ByteBuffer bin, BAsyncResultIF <ByteBuffer> asyncResult) { BProtocol protocol = transport.negotiateProtocolServer(targetId, bin, asyncResult); return(protocol); }