@Override public Transport getTransport() { if (context instanceof Transport) { return (Transport) context; } else if (context instanceof Connection) { return ((Connection)context).getTransport(); } else { Session session = getSession(); if (session == null) { return null; } Connection connection = session.getConnection(); if (connection == null) { return null; } return connection.getTransport(); } }
@Override public Transport getTransport() { if (context instanceof Transport) { return (Transport) context; } else if (context instanceof Connection) { return ((Connection)context).getTransport(); } else { Session session = getSession(); if (session == null) { return null; } Connection connection = session.getConnection(); if (connection == null) { return null; } return connection.getTransport(); } }
@Override public void onTransportClosed(Event event) { final Transport transport = event.getTransport(); final Connection connection = event.getConnection(); if (TRACE_LOGGER.isInfoEnabled()) { TRACE_LOGGER.info(String.format(Locale.US, "onTransportClosed hostname[%s]", (connection != null ? connection.getHostname() : "n/a"))); } if (transport != null && connection != null && connection.getTransport() != null) { transport.unbind(); } } }
private void writeToNetwork(Connection connection, OutputStream out) throws IOException { Transport transport = connection.getTransport(); while(transport.pending() > 0) { ByteBuffer outputBuf = transport.head(); final int size = outputBuf.remaining(); byte[] tmpBuf = new byte[size]; outputBuf.get(tmpBuf); LOG.tracev("writing {0} bytes", size); out.write(tmpBuf); transport.pop(size); } }
@Override public void onConnectionLocalClose(Event event) { Connection connection = event.getConnection(); TRACE_LOGGER.debug("onConnectionLocalClose: hostname:{}", connection.getHostname()); if(connection.getRemoteState() == EndpointState.CLOSED) { // Service closed it first. In some such cases transport is not unbound and causing a leak. if(connection.getTransport() != null) { connection.getTransport().unbind(); } connection.free(); } } }
private boolean isSaslAuthenticated(Connection connection, SaslMechanism mechanism) { Transport transport = connection.getTransport(); Sasl sasl = transport.sasl(); return sasl.getState() == PN_SASL_PASS && mechanism.completedSuccessfully(); }
private void readFromNetwork(Connection connection, InputStream in, BooleanSupplier test) throws IOException, LoginException { Transport transport = connection.getTransport(); while(test.getAsBoolean()) { ByteBuffer buf = transport.getInputBuffer(); byte[] tmpBuf = new byte[buf.remaining()]; int bytesRead = in.read(tmpBuf); LOG.tracev("read {0} bytes", bytesRead); if (bytesRead == -1) { throw new LoginException("Unexpected EOS experienced when authenticating using SASL delegation"); } else { buf.put(tmpBuf, 0, bytesRead); TransportResult result = transport.processInput(); if(!result.isOk()) { LoginException e = new LoginException("Unexpected error when authenticating using SASL delegation"); e.initCause(result.getException()); throw e; } } } }
ProtonReceiverImpl(Receiver receiver) { super(receiver); session = receiver.getSession(); sessionIncomingCapacity = session.getIncomingCapacity(); maxFrameSize = session.getConnection().getTransport().getMaxFrameSize(); windowFullThreshhold = sessionIncomingCapacity - maxFrameSize; }
@Override public void onConnectionLocalClose(Event event) { final Connection connection = event.getConnection(); final ErrorCondition error = connection.getCondition(); if (TRACE_LOGGER.isInfoEnabled()) { TRACE_LOGGER.info(String.format(Locale.US, "onConnectionLocalClose: hostname[%s], errorCondition[%s], errorDescription[%s]", connection.getHostname(), error != null ? error.getCondition() : "n/a", error != null ? error.getDescription() : "n/a")); } if (connection.getRemoteState() == EndpointState.CLOSED) { // This means that the CLOSE origin is Service final Transport transport = connection.getTransport(); if (transport != null) { transport.unbind(); // we proactively dispose IO even if service fails to close } } }
@Override public void inspectOpenedResource(Connection connection) { int brokerMaxFrameSize = connection.getTransport().getRemoteMaxFrameSize(); if (brokerMaxFrameSize != AmqpSupport.MAX_FRAME_SIZE_DEFAULT) { markAsInvalid("Broker did not send the expected max Frame Size"); } } });
@Override public void inspectOpenedResource(Connection connection) { int brokerMaxFrameSize = connection.getTransport().getRemoteMaxFrameSize(); if (brokerMaxFrameSize != AmqpSupport.MAX_FRAME_SIZE_DEFAULT) { markAsInvalid("Broker did not send the expected max Frame Size"); } } });
@Override public void inspectOpenedResource(Connection connection) { int brokerMaxFrameSize = connection.getTransport().getRemoteMaxFrameSize(); if (brokerMaxFrameSize != AmqpSupport.MAX_FRAME_SIZE_DEFAULT) { markAsInvalid("Broker did not send the expected max Frame Size"); } } });
@Override public void inspectOpenedResource(Connection connection) { assertEquals("Broker did not send half the idle timeout", TEST_IDLE_TIMEOUT / 2, connection.getTransport().getRemoteIdleTimeout()); } });
@Override public void inspectOpenedResource(Connection connection) { int brokerMaxFrameSize = connection.getTransport().getRemoteMaxFrameSize(); if (brokerMaxFrameSize != CONFIGURED_FRAME_SIZE) { markAsInvalid("Broker did not send the expected max Frame Size"); } } });
@Override public void inspectOpenedResource(Connection connection) { assertEquals("Broker did not send half the idle timeout", TEST_IDLE_TIMEOUT / 2, connection.getTransport().getRemoteIdleTimeout()); } });
@Override public void inspectOpenedResource(Connection connection) { assertEquals("idle timeout was not disabled", 0, connection.getTransport().getRemoteIdleTimeout()); } });
@Override public void inspectOpenedResource(Connection connection) { assertEquals("idle timeout was not disabled", 0, connection.getTransport().getRemoteIdleTimeout()); } });
@Override public void inspectOpenedResource(Connection connection) { int brokerMaxFrameSize = connection.getTransport().getRemoteMaxFrameSize(); if (brokerMaxFrameSize != AmqpSupport.MAX_FRAME_SIZE_DEFAULT) { markAsInvalid("Broker did not send the expected max Frame Size"); } } });
private void checkSaslAuthenticationState() { try { if (authenticator.isComplete()) { if (!authenticator.wasSuccessful()) { // Close the transport to avoid emitting any additional frames if the // authentication process was unsuccessful, then signal the completion // to avoid any race with the caller triggering any other traffic. // Don't release the authenticator as we need it on close to know what // the state of authentication was. org.apache.qpid.proton.engine.Transport t = protonConnection.getTransport(); t.close_head(); connectionRequest.onFailure(authenticator.getFailureCause()); } else { // Signal completion and release the authenticator we won't use it again. connectionRequest.onSuccess(); authenticator = null; } } } catch (Throwable ex) { try { org.apache.qpid.proton.engine.Transport t = protonConnection.getTransport(); t.close_head(); } finally { fireProviderException(ex); } } }
private void performSaslSteps(Connection connection, InputStream in, OutputStream out, SaslMechanism mechanism) throws IOException, LoginException { Transport transport = connection.getTransport(); Sasl sasl = transport.sasl(); do { readFromNetwork(connection, in, () -> !(EnumSet.of(PN_SASL_PASS, PN_SASL_FAIL).contains(sasl.getState()) || (sasl.getState() == PN_SASL_STEP && sasl.pending() > 0))); if (sasl.pending() > 0) { byte[] challenge = new byte[sasl.pending()]; byte[] response = mechanism.getResponse(challenge); if (sasl.getState() == PN_SASL_STEP) { sasl.send(response, 0, response.length); writeToNetwork(connection, out); } } } while (sasl.getState() == PN_SASL_STEP); }