private bool validate(int operation) { if(!_endpoint.datagram()) // Datagram connections are always implicitly validated. { if(_adapter != null) // The server side has the active role for connection validation. { if(_writeStream.size() == 0) { _writeStream.writeBlob(IceInternal.Protocol.magic); Ice.Util.currentProtocol.write__(_writeStream); Ice.Util.currentProtocolEncoding.write__(_writeStream); _writeStream.writeByte(IceInternal.Protocol.validateConnectionMsg); _writeStream.writeByte((byte)0); // Compression status (always zero for validate connection). _writeStream.writeInt(IceInternal.Protocol.headerSize); // Message size. IceInternal.TraceUtil.traceSend(_writeStream, _logger, _traceLevels); _writeStream.prepareWrite(); } if(_observer != null) { observerStartWrite(_writeStream.pos()); } if(_writeStream.pos() != _writeStream.size() && !_transceiver.write(_writeStream.getBuffer())) { scheduleTimeout(IceInternal.SocketOperation.Write, connectTimeout()); _threadPool.update(this, operation, IceInternal.SocketOperation.Write); return false; } if(_observer != null) { observerFinishWrite(_writeStream.pos()); } } else // The client side has the passive role for connection validation. { if(_readStream.size() == 0) { _readStream.resize(IceInternal.Protocol.headerSize, true); _readStream.pos(0); } if(_observer != null) { observerStartRead(_readStream.pos()); } if(_readStream.pos() != _readStream.size() && !_transceiver.read(_readStream.getBuffer())) { scheduleTimeout(IceInternal.SocketOperation.Read, connectTimeout()); _threadPool.update(this, operation, IceInternal.SocketOperation.Read); return false; } if(_observer != null) { observerFinishRead(_readStream.pos()); } Debug.Assert(_readStream.pos() == IceInternal.Protocol.headerSize); _readStream.pos(0); byte[] m = _readStream.readBlob(4); if(m[0] != IceInternal.Protocol.magic[0] || m[1] != IceInternal.Protocol.magic[1] || m[2] != IceInternal.Protocol.magic[2] || m[3] != IceInternal.Protocol.magic[3]) { BadMagicException ex = new BadMagicException(); ex.badMagic = m; throw ex; } ProtocolVersion pv = new ProtocolVersion(); pv.read__(_readStream); IceInternal.Protocol.checkSupportedProtocol(pv); EncodingVersion ev = new EncodingVersion(); ev.read__(_readStream); IceInternal.Protocol.checkSupportedProtocolEncoding(ev); byte messageType = _readStream.readByte(); if(messageType != IceInternal.Protocol.validateConnectionMsg) { throw new ConnectionNotValidatedException(); } _readStream.readByte(); // Ignore compression status for validate connection. int size = _readStream.readInt(); if(size != IceInternal.Protocol.headerSize) { throw new IllegalMessageSizeException(); } IceInternal.TraceUtil.traceRecv(_readStream, _logger, _traceLevels); _validated = true; } } _writeStream.resize(0, false); _writeStream.pos(0); _readStream.resize(IceInternal.Protocol.headerSize, true); _readStream.pos(0); _readHeader = true; return true; }
private bool validate(int operation) { if(!_endpoint.datagram()) // Datagram connections are always implicitly validated. { if(_adapter != null) // The server side has the active role for connection validation. { if(_writeStream.size() == 0) { _writeStream.writeBlob(IceInternal.Protocol.magic); Ice.Util.currentProtocol.write__(_writeStream); Ice.Util.currentProtocolEncoding.write__(_writeStream); _writeStream.writeByte(IceInternal.Protocol.validateConnectionMsg); _writeStream.writeByte((byte)0); // Compression status (always zero for validate connection). _writeStream.writeInt(IceInternal.Protocol.headerSize); // Message size. IceInternal.TraceUtil.traceSend(_writeStream, _logger, _traceLevels); _writeStream.prepareWrite(); } if(_observer != null) { observerStartWrite(_writeStream.getBuffer()); } if(_writeStream.pos() != _writeStream.size()) { int op = write(_writeStream.getBuffer()); if(op != 0) { scheduleTimeout(op); _threadPool.update(this, operation, op); return false; } } if(_observer != null) { observerFinishWrite(_writeStream.getBuffer()); } } else // The client side has the passive role for connection validation. { if(_readStream.size() == 0) { _readStream.resize(IceInternal.Protocol.headerSize, true); _readStream.pos(0); } if(_observer != null) { observerStartRead(_readStream.getBuffer()); } if(_readStream.pos() != _readStream.size()) { int op = read(_readStream.getBuffer()); if(op != 0) { scheduleTimeout(op); _threadPool.update(this, operation, op); return false; } } if(_observer != null) { observerFinishRead(_readStream.getBuffer()); } Debug.Assert(_readStream.pos() == IceInternal.Protocol.headerSize); _readStream.pos(0); byte[] m = _readStream.readBlob(4); if(m[0] != IceInternal.Protocol.magic[0] || m[1] != IceInternal.Protocol.magic[1] || m[2] != IceInternal.Protocol.magic[2] || m[3] != IceInternal.Protocol.magic[3]) { BadMagicException ex = new BadMagicException(); ex.badMagic = m; throw ex; } ProtocolVersion pv = new ProtocolVersion(); pv.read__(_readStream); IceInternal.Protocol.checkSupportedProtocol(pv); EncodingVersion ev = new EncodingVersion(); ev.read__(_readStream); IceInternal.Protocol.checkSupportedProtocolEncoding(ev); byte messageType = _readStream.readByte(); if(messageType != IceInternal.Protocol.validateConnectionMsg) { throw new ConnectionNotValidatedException(); } _readStream.readByte(); // Ignore compression status for validate connection. int size = _readStream.readInt(); if(size != IceInternal.Protocol.headerSize) { throw new IllegalMessageSizeException(); } IceInternal.TraceUtil.traceRecv(_readStream, _logger, _traceLevels); _validated = true; } } _writeStream.resize(0, false); _writeStream.pos(0); _readStream.resize(IceInternal.Protocol.headerSize, true); _readStream.pos(0); _readHeader = true; if(_instance.traceLevels().network >= 1) { StringBuilder s = new StringBuilder(); if(_endpoint.datagram()) { s.Append("starting to "); s.Append(_connector != null ? "send" : "receive"); s.Append(" "); s.Append(_endpoint.protocol()); s.Append(" messages\n"); s.Append(_transceiver.toDetailedString()); } else { s.Append(_connector != null ? "established" : "accepted"); s.Append(" "); s.Append(_endpoint.protocol()); s.Append(" connection\n"); s.Append(ToString()); } _instance.initializationData().logger.trace(_instance.traceLevels().networkCat, s.ToString()); } return true; }
private bool validate(int operation) { if(!_endpoint.datagram()) // Datagram connections are always implicitly validated. { if(_adapter != null) // The server side has the active role for connection validation. { if(_writeStream.size() == 0) { _writeStream.writeBlob(IceInternal.Protocol.magic); _writeStream.writeByte(IceInternal.Protocol.protocolMajor); _writeStream.writeByte(IceInternal.Protocol.protocolMinor); _writeStream.writeByte(IceInternal.Protocol.encodingMajor); _writeStream.writeByte(IceInternal.Protocol.encodingMinor); _writeStream.writeByte(IceInternal.Protocol.validateConnectionMsg); _writeStream.writeByte((byte)0); // Compression status (always zero for validate connection). _writeStream.writeInt(IceInternal.Protocol.headerSize); // Message size. IceInternal.TraceUtil.traceSend(_writeStream, _logger, _traceLevels); _writeStream.prepareWrite(); } if(_writeStream.pos() != _writeStream.size() && !_transceiver.write(_writeStream.getBuffer())) { scheduleTimeout(IceInternal.SocketOperation.Write, connectTimeout()); _threadPool.update(this, operation, IceInternal.SocketOperation.Write); return false; } } else // The client side has the passive role for connection validation. { if(_readStream.size() == 0) { _readStream.resize(IceInternal.Protocol.headerSize, true); _readStream.pos(0); } if(_readStream.pos() != _readStream.size() && !_transceiver.read(_readStream.getBuffer())) { scheduleTimeout(IceInternal.SocketOperation.Read, connectTimeout()); _threadPool.update(this, operation, IceInternal.SocketOperation.Read); return false; } Debug.Assert(_readStream.pos() == IceInternal.Protocol.headerSize); _readStream.pos(0); byte[] m = _readStream.readBlob(4); if(m[0] != IceInternal.Protocol.magic[0] || m[1] != IceInternal.Protocol.magic[1] || m[2] != IceInternal.Protocol.magic[2] || m[3] != IceInternal.Protocol.magic[3]) { BadMagicException ex = new BadMagicException(); ex.badMagic = m; throw ex; } byte pMajor = _readStream.readByte(); byte pMinor = _readStream.readByte(); if(pMajor != IceInternal.Protocol.protocolMajor) { UnsupportedProtocolException e = new UnsupportedProtocolException(); e.badMajor = pMajor < 0 ? pMajor + 255 : pMajor; e.badMinor = pMinor < 0 ? pMinor + 255 : pMinor; e.major = IceInternal.Protocol.protocolMajor; e.minor = IceInternal.Protocol.protocolMinor; throw e; } byte eMajor = _readStream.readByte(); byte eMinor = _readStream.readByte(); if(eMajor != IceInternal.Protocol.encodingMajor) { UnsupportedEncodingException e = new UnsupportedEncodingException(); e.badMajor = eMajor < 0 ? eMajor + 255 : eMajor; e.badMinor = eMinor < 0 ? eMinor + 255 : eMinor; e.major = IceInternal.Protocol.encodingMajor; e.minor = IceInternal.Protocol.encodingMinor; throw e; } byte messageType = _readStream.readByte(); if(messageType != IceInternal.Protocol.validateConnectionMsg) { throw new ConnectionNotValidatedException(); } _readStream.readByte(); // Ignore compression status for validate connection. int size = _readStream.readInt(); if(size != IceInternal.Protocol.headerSize) { throw new IllegalMessageSizeException(); } IceInternal.TraceUtil.traceRecv(_readStream, _logger, _traceLevels); } } _writeStream.resize(0, false); _writeStream.pos(0); _readStream.resize(IceInternal.Protocol.headerSize, true); _readStream.pos(0); _readHeader = true; return true; }