use of io.vertx.proton.ProtonTransportOptions in project vertx-proton by vert-x3.
the class ProtonServerImpl method connectHandler.
@Override
public ProtonServerImpl connectHandler(Handler<ProtonConnection> handler) {
this.handler = handler;
server.connectHandler(netSocket -> {
String hostname = null;
try {
hostname = InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException e) {
// ignore
}
final ProtonConnectionImpl connection = new ProtonConnectionImpl(vertx, hostname);
if (advertiseAnonymousRelayCapability) {
connection.setOfferedCapabilities(new Symbol[] { ProtonConnectionImpl.ANONYMOUS_RELAY });
}
final ProtonSaslAuthenticator authenticator = authenticatorFactory.create();
ProtonTransportOptions transportOptions = new ProtonTransportOptions();
transportOptions.setHeartbeat(this.options.getHeartbeat());
transportOptions.setMaxFrameSize(this.options.getMaxFrameSize());
connection.bindServer(netSocket, new ProtonSaslAuthenticator() {
@Override
public void init(NetSocket socket, ProtonConnection protonConnection, Transport transport) {
authenticator.init(socket, protonConnection, transport);
}
@Override
public void process(Handler<Boolean> completionHandler) {
final Context context = Vertx.currentContext();
authenticator.process(complete -> {
final Context callbackContext = vertx.getOrCreateContext();
if (context != callbackContext) {
throw new IllegalStateException("Callback was not made on the original context");
}
if (complete) {
// The authenticator completed, now check success, do required post processing
if (succeeded()) {
handler.handle(connection);
connection.flush();
} else {
// auth failed, flush any pending data and disconnect client
connection.flush();
connection.disconnect();
}
}
completionHandler.handle(complete);
});
}
@Override
public boolean succeeded() {
return authenticator.succeeded();
}
}, transportOptions);
});
return this;
}
use of io.vertx.proton.ProtonTransportOptions in project vertx-proton by vert-x3.
the class ProtonClientImpl method connectNetClient.
private void connectNetClient(NetClient netClient, String host, int port, String username, String password, ConnectCompletionHandler connectHandler, ProtonClientOptions options) {
String serverName = options.getSniServerName() != null ? options.getSniServerName() : (options.getVirtualHost() != null ? options.getVirtualHost() : null);
netClient.connect(port, host, serverName, res -> {
if (res.succeeded()) {
String virtualHost = options.getVirtualHost() != null ? options.getVirtualHost() : host;
ProtonConnectionImpl conn = new ProtonConnectionImpl(vertx, virtualHost);
conn.disconnectHandler(h -> {
LOG.trace("Connection disconnected");
if (!connectHandler.isComplete()) {
connectHandler.handle(Future.failedFuture(new VertxException("Disconnected")));
}
});
ProtonSaslClientAuthenticatorImpl authenticator = new ProtonSaslClientAuthenticatorImpl(username, password, options.getEnabledSaslMechanisms(), connectHandler);
ProtonTransportOptions transportOptions = new ProtonTransportOptions();
transportOptions.setHeartbeat(options.getHeartbeat());
transportOptions.setMaxFrameSize(options.getMaxFrameSize());
conn.bindClient(netClient, res.result(), authenticator, transportOptions);
// Need to flush here to get the SASL process going, or it will wait until calls on the connection are processed
// later (e.g open()).
conn.flush();
} else {
connectHandler.handle(Future.failedFuture(res.cause()));
}
});
}
Aggregations