private void asyncCloseMessage(final int id) { Pooled<ByteBuffer> pooled = connection.allocate(); boolean ok = false; try { ByteBuffer byteBuffer = pooled.getResource(); byteBuffer.put(Protocol.MESSAGE_CLOSE); byteBuffer.putInt(channelId); byteBuffer.putShort((short) id); byteBuffer.flip(); ok = true; connection.send(pooled); } finally { if (! ok) pooled.free(); } }
static void sendCloseRequestBody(RemoteConnection remoteConnection) { final Pooled<ByteBuffer> pooled = remoteConnection.allocate(); boolean ok = false; try { final ByteBuffer buffer = pooled.getResource(); buffer.put(Protocol.CONNECTION_CLOSE); buffer.flip(); remoteConnection.send(pooled, true); ok = true; } finally { if (! ok) { pooled.free(); } } }
public void sendAuthDelete(final int id) throws IOException { log.tracef("Sending authentication delete for ID %08x", id); // todo: allocate small buffer final Pooled<ByteBuffer> pooled = remoteConnection.allocate(); boolean ok = false; try { final ByteBuffer buffer = pooled.getResource(); buffer.put(Protocol.APP_AUTH_DELETE); buffer.putInt(id); buffer.flip(); remoteConnection.send(pooled); ok = true; } finally { if (! ok) pooled.free(); } }
private void refuseService(final int channelId, final String reason) { if (log.isTraceEnabled()) { log.tracef("Refusing service on channel %08x: %s", Integer.valueOf(channelId), reason); } Pooled<ByteBuffer> pooledReply = connection.allocate(); boolean ok = false; try { ByteBuffer replyBuffer = pooledReply.getResource(); replyBuffer.clear(); replyBuffer.put(Protocol.SERVICE_ERROR); replyBuffer.putInt(channelId); replyBuffer.put(reason.getBytes(StandardCharsets.UTF_8)); replyBuffer.flip(); ok = true; // send takes ownership of the buffer connection.send(pooledReply); } finally { if (! ok) pooledReply.free(); } } }
public void sendAuthReject(final int id) throws IOException { log.tracef("Sending authentication reject for ID %08x", id); // todo: allocate small buffer final Pooled<ByteBuffer> pooled = remoteConnection.allocate(); boolean ok = false; try { final ByteBuffer buffer = pooled.getResource(); buffer.put(Protocol.APP_AUTH_REJECT); buffer.putInt(id); buffer.flip(); remoteConnection.send(pooled); ok = true; } finally { if (! ok) pooled.free(); } }
public void writeShutdown() throws IOException { if (closeWrites()) { Pooled<ByteBuffer> pooled = connection.allocate(); boolean ok = false; try { ByteBuffer byteBuffer = pooled.getResource(); byteBuffer.put(Protocol.CHANNEL_SHUTDOWN_WRITE); byteBuffer.putInt(channelId); byteBuffer.flip(); connection.send(pooled); ok = true; } finally { if (! ok) pooled.free(); } } }
public void sendAuthDeleteAck(final int id) throws IOException { log.tracef("Sending authentication delete ack for ID %08x", id); // todo: allocate small buffer final Pooled<ByteBuffer> pooled = remoteConnection.allocate(); boolean ok = false; try { final ByteBuffer buffer = pooled.getResource(); buffer.put(Protocol.APP_AUTH_DELETE_ACK); buffer.putInt(id); buffer.flip(); remoteConnection.send(pooled); ok = true; } finally { if (! ok) pooled.free(); } }
void rejectAuthentication(String mechName) { // reject log.rejectedInvalidMechanism(mechName); final Pooled<ByteBuffer> pooled = connection.allocate(); boolean ok = false; try { final ByteBuffer sendBuffer = pooled.getResource(); sendBuffer.put(Protocol.AUTH_REJECTED); sendBuffer.flip(); connection.send(pooled); ok = true; } finally { if (! ok) pooled.free(); } }
public void sendAuthChallenge(final int id, final byte[] challenge) throws IOException { log.tracef("Sending authentication challenge for ID %08x", id); int requiredSize = 5 + challenge.length; final Pooled<ByteBuffer> pooled = remoteConnection.allocate(); boolean ok = false; try { final ByteBuffer buffer = pooled.getResource(); if (buffer.remaining() < requiredSize) { throw log.authenticationMessageTooLarge(); } buffer.put(Protocol.APP_AUTH_CHALLENGE); buffer.putInt(id); buffer.put(challenge); buffer.flip(); remoteConnection.send(pooled); ok = true; } finally { if (! ok) pooled.free(); } }
public void sendAuthResponse(final int id, final byte[] response) throws IOException { log.tracef("Sending authentication response for ID %08x", id); int requiredSize = 5 + response.length; final Pooled<ByteBuffer> pooled = remoteConnection.allocate(); boolean ok = false; try { final ByteBuffer buffer = pooled.getResource(); if (buffer.remaining() < requiredSize) { throw log.authenticationMessageTooLarge(); } buffer.put(Protocol.APP_AUTH_RESPONSE); buffer.putInt(id); buffer.put(response); buffer.flip(); remoteConnection.send(pooled); ok = true; } finally { if (! ok) pooled.free(); } }
void sendAliveResponse() { Messages.conn.trace("Sending connection alive ack"); final Pooled<ByteBuffer> pooled = allocate(); boolean ok = false; try { final ByteBuffer buffer = pooled.getResource(); buffer.put(Protocol.CONNECTION_ALIVE_ACK); buffer.limit(80); Buffers.addRandom(buffer); buffer.flip(); send(pooled); ok = true; } finally { if (! ok) pooled.free(); } }
public void sendAuthSuccess(final int id, final byte[] challenge) throws IOException { log.tracef("Sending authentication success for ID %08x", id); int requiredSize = 5 + ((challenge != null) ? challenge.length : 0); final Pooled<ByteBuffer> pooled = remoteConnection.allocate(); boolean ok = false; try { final ByteBuffer buffer = pooled.getResource(); if (buffer.remaining() < requiredSize) { throw log.authenticationMessageTooLarge(); } buffer.put(Protocol.APP_AUTH_SUCCESS); buffer.putInt(id); if (challenge != null) { buffer.put(challenge); } buffer.flip(); remoteConnection.send(pooled); ok = true; } finally { if (! ok) pooled.free(); } }
public void sendAuthRequest(final int id, final String mechName, final byte[] initialResponse) throws IOException { log.tracef("Sending authentication request for ID %08x, mech %s", id, mechName); final byte[] mechNameBytes = mechName.getBytes(StandardCharsets.UTF_8); final int length = mechNameBytes.length; if (length == 0 || length > 256) { throw log.mechanismNameTooLong(mechName); } int requiredSize = 6 + length + ((initialResponse != null) ? initialResponse.length : 0); final Pooled<ByteBuffer> pooled = remoteConnection.allocate(); boolean ok = false; try { final ByteBuffer buffer = pooled.getResource(); if (buffer.remaining() < requiredSize) { throw log.authenticationMessageTooLarge(); } buffer.put(Protocol.APP_AUTH_REQUEST); buffer.putInt(id); buffer.put((byte) length); buffer.put(mechNameBytes); if (initialResponse != null) { buffer.put(initialResponse); } buffer.flip(); remoteConnection.send(pooled); ok = true; } finally { if (! ok) pooled.free(); } }
void sendAlive() { Messages.conn.trace("Sending connection alive"); final Pooled<ByteBuffer> pooled = allocate(); boolean ok = false; try { final ByteBuffer buffer = pooled.getResource(); buffer.put(Protocol.CONNECTION_ALIVE); buffer.limit(80); Buffers.addRandom(buffer); buffer.flip(); send(pooled); ok = true; messageReader.wakeupReads(); } finally { if (! ok) pooled.free(); } }
private void doAcknowledge(final Pooled<ByteBuffer> acked) { assert holdsLock(inputStream); if (eofReceived) { // no ack needed; also a best-effort to work around broken peers return; } final boolean badMsgSize = channel.getConnectionHandler().isFaultyMessageSize(); int consumed = acked.getResource().position(); if (! badMsgSize) consumed -= 8; // position minus header length (not including framing size) inboundWindow += consumed; Pooled<ByteBuffer> pooled = allocate(Protocol.MESSAGE_WINDOW_OPEN); boolean ok = false; try { ByteBuffer buffer = pooled.getResource(); buffer.putInt(consumed); // Open window by buffer size buffer.flip(); channel.getRemoteConnection().send(pooled); ok = true; } finally { if (! ok) pooled.free(); } }
private void doSendCloseMessage() { assert holdsLock(inputStream); if (closeSent || ! channel.getConnectionHandler().isMessageClose()) { // we don't send a MESSAGE_CLOSE because broken versions will simply stop sending packets, and we won't know when the message is really gone. // the risk is that the remote side could have started a new message in the meantime, and our MESSAGE_CLOSE would kill the wrong message. // so this behavior is better than the alternative. return; } Pooled<ByteBuffer> pooled = allocate(Protocol.MESSAGE_CLOSE); boolean ok = false; try { ByteBuffer buffer = pooled.getResource(); buffer.flip(); channel.getRemoteConnection().send(pooled); ok = true; closeSent = true; } finally { if (! ok) pooled.free(); } }
public void handleEvent(final ConduitStreamSourceChannel channel) { final Pooled<ByteBuffer> pooled = connection.allocate(); boolean ok = false; try { ByteBuffer sendBuffer = pooled.getResource(); sendBuffer.put(Protocol.GREETING); ProtocolUtils.writeString(sendBuffer, Protocol.GRT_SERVER_NAME, serverName); sendBuffer.flip(); connection.setReadListener(new Initial(), true); connection.send(pooled); ok = true; return; } catch (BufferUnderflowException | BufferOverflowException e) { connection.handleException(log.invalidMessage(connection)); return; } finally { if (! ok) pooled.free(); } }
byteBuffer.flip(); ok = true; connection.send(pooled); } finally { if (! ok) pooled.free();
channel.getRemoteConnection().send(pooled); ok = true; } finally {
ProtocolUtils.writeEmpty(sendBuffer, Protocol.CAP_AUTHENTICATION); sendBuffer.flip(); connection.send(pooled); ok = true; return;