public void handleEvent(final StreamConnection connection) { try { connection.setOption(Options.TCP_NODELAY, Boolean.TRUE); } catch (IOException e) { // ignore } final SslChannel sslChannel = connection instanceof SslChannel ? (SslChannel) connection : null; final RemoteConnection remoteConnection = new RemoteConnection(connection, sslChannel, connectOptions, RemoteConnectionProvider.this); cancellableResult.addCancelHandler(new Cancellable() { @Override public Cancellable cancel() { RemoteConnectionHandler.sendCloseRequestBody(remoteConnection); remoteConnection.handlePreAuthCloseRequest(); return this; } }); if (connection.isOpen()) { remoteConnection.setResult(cancellableResult); connection.getSinkChannel().setWriteListener(remoteConnection.getWriteListener()); final ClientConnectionOpenListener openListener = new ClientConnectionOpenListener(destination, remoteConnection, connectionProviderContext, authenticationConfiguration, saslClientFactoryOperator, serverMechs, connectOptions); openListener.handleEvent(connection.getSourceChannel()); } } };
public void handleEvent(final ConduitStreamSourceChannel channel) { final Pooled<ByteBuffer> message; try { message = connection.getMessageReader().getMessage(); } catch (IOException e) { connection.handleException(e); return; connection.handleException(allMechanismsFailed()); return; connection.handleException(client.abruptClose(connection)); return; case Protocol.CONNECTION_ALIVE: { client.trace("Client received connection alive"); connection.sendAliveResponse(); return; connection.handlePreAuthCloseRequest(); return; if (optionMap.get(Options.SSL_STARTTLS, true) && connection.getConnection() instanceof SslConnection) { final Pooled<ByteBuffer> pooledSendBuffer = connection.allocate(); boolean ok = false; try { sendBuffer.put(Protocol.STARTTLS); sendBuffer.flip();
private void notifyEnd() { synchronized (connection.getLock()) { if (nextReceiver != null) { final Receiver receiver = nextReceiver; nextReceiver = null; try { getExecutor().execute(() -> receiver.handleEnd(RemoteConnectionChannel.this)); } catch (Throwable t) { connection.handleException(new IOException("Fatal connection error", t)); return; } } } }
void handlePreAuthCloseRequest() { try { terminateHeartbeat(); synchronized (getLock()) { connection.close(); } } catch (IOException e) { Messages.conn.debug("Error closing remoting channel", e); } }
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(); } }
public void handleEvent(final ConduitStreamSourceChannel channel) { final Pooled<ByteBuffer> message; final MessageReader messageReader = connection.getMessageReader(); try { message = messageReader.getMessage(); } catch (IOException e) { connection.handleException(e); return; connection.handleException(client.abruptClose(connection)); saslDispose(saslClient); return; case Protocol.CONNECTION_ALIVE: { client.trace("Client received connection alive"); connection.sendAliveResponse(); return; connection.handlePreAuthCloseRequest(); saslDispose(saslClient); return; client.trace("Client received authentication challenge"); messageReader.suspendReads(); connection.getExecutor().execute(() -> { try { final boolean clientComplete = saslClient.isComplete(); if (clientComplete) { connection.handleException(new SaslException(saslClient.getMechanismName() + ": Received extra auth message after completion")); return;
public void handleEvent(final ConduitStreamSourceChannel channel) { SaslWrapper saslWrapper = connection.getSaslWrapper(); final Object lock = connection.getLock(); final MessageReader messageReader = connection.getMessageReader(); try { Pooled<ByteBuffer> message = null; case Protocol.CONNECTION_ALIVE: { log.trace("Received connection alive"); connection.sendAliveResponse(); break; Pooled<ByteBuffer> pooledReply = connection.allocate(); boolean ok2 = false; try { ok2 = true; connection.send(pooledReply); } finally { if (! ok2) pooledReply.free(); connection.getExecutor().execute(SpiUtils.getServiceOpenTask(connectionChannel, openListener)); break; } finally { connection.handleException(e); synchronized (lock) { IoUtils.safeClose(channel);
public void handleEvent(final ConnectedMessageChannel channel) { Pooled<ByteBuffer> pooledBuffer = connection.allocate(); boolean free = true; ByteBuffer receiveBuffer; try { if (channel instanceof RemotingMessageChannel) { synchronized (connection.getLock()) { int res; RemotingMessageChannel.AdjustedBuffer ab = new RemotingMessageChannel.AdjustedBuffer(pooledBuffer); res = rc.receive(ab); } catch (IOException e) { connection.handleException(e); return; connection.handlePreAuthCloseRequest(); return; synchronized (connection.getLock()) { final int res; try { res = channel.receive(receiveBuffer); } catch (IOException e) { connection.handleException(e); return; connection.handlePreAuthCloseRequest(); return; case Protocol.CONNECTION_CLOSE: {
final Pooled<ByteBuffer> pooled = connection.allocate(); try { final ByteBuffer sendBuffer = pooled.getResource(); final Object qop = saslServer.getNegotiatedProperty(Sasl.QOP); if (!isInitial && ("auth-int".equals(qop) || "auth-conf".equals(qop))) { connection.setSaslWrapper(SaslWrapper.create(saslServer)); final String peerName = connection.getPeerAddress().getHostName(); final RemoteConnectionHandler connectionHandler = new RemoteConnectionHandler( connectionContext, connection, maxInboundChannels, maxOutboundChannels, AnonymousPrincipal.getInstance(), remoteEndpointName, behavior, authCap, offeredMechanisms, peerName, serverName); connection.getRemoteConnectionProvider().addConnectionHandler(connectionHandler); final SecurityIdentity identity = (SecurityIdentity) saslServer.getNegotiatedProperty(WildFlySasl.SECURITY_IDENTITY); connection.setIdentity(identity == null ? saslAuthenticationFactory.getSecurityDomain().getAnonymousSecurityIdentity() : identity); connection.setReadListener(new RemoteReadListener(connectionHandler, connection), false); return connectionHandler; }, saslAuthenticationFactory); sendBuffer.put(p, Protocol.AUTH_CHALLENGE); if (isInitial) { connection.setReadListener(new Authentication(saslServer, remoteEndpointName, behavior, maxInboundChannels, maxOutboundChannels, authCap, offeredMechanisms), false); close = true; } else if (!isInitial) { connection.setReadListener(new Initial(), false); connection.send(pooled, close); ok = true; resumeReads();
public void handleEvent(final ConduitStreamSourceChannel channel) { final Pooled<ByteBuffer> message; try { message = connection.getMessageReader().getMessage(); } catch (IOException e) { connection.handleException(e); saslDispose(saslServer); return; connection.handlePreAuthCloseRequest(); saslDispose(saslServer); return; case Protocol.CONNECTION_CLOSE: { server.trace("Server received connection close request"); connection.handlePreAuthCloseRequest(); saslDispose(saslServer); return; server.tracef("Server received authentication response"); suspendReads(); connection.getExecutor().execute(new AuthStepRunnable(false, saslServer, message, remoteEndpointName, behavior, maxInboundChannels, maxOutboundChannels, authCap, offeredMechanisms)); free = false; return; saslDispose(saslServer); final Initial initial = new Initial(); connection.setReadListener(initial, true); initial.handleClientCapabilities(buffer); initial.sendCapabilities();
public void handleEvent(final ConnectedMessageChannel channel) { final Pooled<ByteBuffer> pooledBuffer = connection.allocate(); boolean free = true; try { final ByteBuffer buffer = pooledBuffer.getResource(); synchronized (connection.getLock()) { final int res; try { res = channel.receive(buffer); } catch (IOException e) { connection.handleException(e); saslDispose(saslServer); return; connection.handlePreAuthCloseRequest(); saslDispose(saslServer); return; case Protocol.CONNECTION_CLOSE: { server.trace("Server received connection close request"); connection.handlePreAuthCloseRequest(); saslDispose(saslServer); return; connection.getChannel().suspendReads(); connection.getExecutor().execute(new AuthStepRunnable(false, saslServer, authorizingCallbackHandler, pooledBuffer, remoteEndpointName, behavior, maxInboundChannels, maxOutboundChannels)); free = false; return; saslDispose(saslServer);
public void handleEvent(final ConnectedMessageChannel channel) { final Pooled<ByteBuffer> pooledBuffer = connection.allocate(); boolean free = true; try { final ByteBuffer buffer = pooledBuffer.getResource(); synchronized (connection.getLock()) { final int res; try { res = channel.receive(buffer); } catch (IOException e) { connection.handleException(e); saslDispose(saslClient); return; connection.handleException(client.abruptClose(connection)); saslDispose(saslClient); return; case Protocol.CONNECTION_ALIVE: { client.trace("Client received connection alive"); connection.sendAliveResponse(); return; connection.handlePreAuthCloseRequest(); saslDispose(saslClient); return; client.trace("Client received authentication challenge"); channel.suspendReads(); connection.getExecutor().execute(new Runnable() {
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(); } }
final OptionMap connectionOptionMap = remoteConnection.getOptionMap(); Pooled<ByteBuffer> pooled = remoteConnection.allocate(); try { ByteBuffer buffer = pooled.getResource(); remoteConnection.send(pooled); ok = true; log.tracef("Completed initiation of service open of type %s on %s", serviceType, this);
private void handleAccepted(final StreamConnection accepted, final SslChannel sslChannel, final OptionMap serverOptionMap, final SaslAuthenticationFactory saslAuthenticationFactory) { final RemoteConnection connection = new RemoteConnection(accepted, sslChannel, serverOptionMap, RemoteConnectionProvider.this); final ServerConnectionOpenListener openListener = new ServerConnectionOpenListener(connection, connectionProviderContext, saslAuthenticationFactory, serverOptionMap); accepted.getSinkChannel().setWriteListener(connection.getWriteListener()); log.tracef("Accepted connection from %s to %s", connection.getPeerAddress(), connection.getLocalAddress()); openListener.handleEvent(accepted.getSourceChannel()); } }
if (channel.flush()) { Messages.conn.trace("Flushed channel"); final SslChannel sslChannel = getSslChannel(); assert sslChannel != null; // because STARTTLS would be false in this case sslChannel.startHandshake(); Messages.conn.trace("Flushed channel"); if (closed) { terminateHeartbeat(); handleException(e, false); while ((pooled = queue.poll()) != null) { pooled.free();
RemoteReadListener(final RemoteConnectionHandler handler, final RemoteConnection connection) { synchronized (connection.getLock()) { connection.getConnection().getCloseSetter().set((ChannelListener<Channel>) channel -> connection.getExecutor().execute(() -> { handler.handleConnectionClose(); handler.closeComplete(); })); } this.handler = handler; this.connection = connection; }
protected void closeAction() throws IOException { sendCloseRequest(); remoteConnection.shutdownWrites(); remoteConnection.getMessageReader().shutdownReads(); // now these guys can't send useless messages closePendingChannels(); closeAllChannels(); remoteConnection.getRemoteConnectionProvider().removeConnectionHandler(this); }
public void accept(final StreamConnection channel) { if (channel.getWorker() != getXnioWorker()) { throw conn.invalidWorker(); } try { channel.setOption(Options.TCP_NODELAY, Boolean.TRUE); } catch (IOException e) { // ignore } final SslChannel sslChannel = channel instanceof SslConnection ? (SslConnection) channel : null; final RemoteConnection connection = new RemoteConnection(channel, sslChannel, optionMap, HttpUpgradeConnectionProvider.this); final ServerConnectionOpenListener openListener = new ServerConnectionOpenListener(connection, getConnectionProviderContext(), saslAuthenticationFactory, optionMap); channel.getSinkChannel().setWriteListener(connection.getWriteListener()); conn.tracef("Accepted connection from %s to %s", channel.getPeerAddress(), channel.getLocalAddress()); openListener.handleEvent(channel.getSourceChannel()); } }
void sendCapRequest(final String remoteServerName) { client.trace("Client sending capabilities request"); final Pooled<ByteBuffer> pooledSendBuffer = connection.allocate(); boolean ok = false; try { connection.setReadListener(new Capabilities(remoteServerName, uri), true); connection.send(pooledSendBuffer); ok = true;