Skip to content

Commit

Permalink
Save creating (and validating) a peer INET address if not required
Browse files Browse the repository at this point in the history
  • Loading branch information
franz1981 committed Nov 2, 2023
1 parent 3e9d5d1 commit 64297be
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions src/main/java/io/vertx/core/net/impl/NetClientImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import java.util.function.Predicate;
import java.util.function.Supplier;

/**
*
Expand Down Expand Up @@ -294,16 +293,8 @@ private void connectInternal2(ConnectOptions connectOptions,
}
remoteAddress = SocketAddress.inetSocketAddress(port, host);
}
String peerHost = connectOptions.getHost();
Integer peerPort = connectOptions.getPort();
if (remoteAddress.isInetSocket()) {
if (peerHost == null) {
peerHost = remoteAddress.host();;
}
if (peerPort == null) {
peerPort = remoteAddress.port();
}
}

SocketAddress peerAddress = peerAddress(remoteAddress, connectOptions);

vertx.transport().configure(options, remoteAddress.isDomainSocket(), bootstrap);

Expand All @@ -321,7 +312,7 @@ private void connectInternal2(ConnectOptions connectOptions,
.proxyOptions(proxyOptions);

SocketAddress captured = remoteAddress;
SocketAddress peerAddress = peerHost != null && peerPort != null ? SocketAddress.inetSocketAddress(peerPort, peerHost) : null;

channelProvider.handler(ch -> connected(
context,
sslOptions,
Expand Down Expand Up @@ -365,6 +356,26 @@ private void connectInternal2(ConnectOptions connectOptions,
}
}

private static SocketAddress peerAddress(SocketAddress remoteAddress, ConnectOptions connectOptions) {
if (!connectOptions.isSsl()) {
return null;
}
String peerHost = connectOptions.getHost();
Integer peerPort = connectOptions.getPort();
if (remoteAddress.isInetSocket()) {
if (peerHost == null && peerPort == null) {
return remoteAddress;
}
if (peerHost == null) {
peerHost = remoteAddress.host();;
}
if (peerPort == null) {
peerPort = remoteAddress.port();
}
}
return peerHost != null && peerPort != null ? SocketAddress.inetSocketAddress(peerPort, peerHost) : null;
}

private void connected(ContextInternal context,
ClientSSLOptions sslOptions,
Channel ch,
Expand Down

0 comments on commit 64297be

Please sign in to comment.