Skip to content

Commit

Permalink
Obtain the local address from the fd when the client connects only wi…
Browse files Browse the repository at this point in the history
…th remote address (UDS) (#13419)

Motivation:
Client can use only a remote address for connecting to the server.

Modifications:
- Obtain the local address from the fd when the client uses only a
remote address for connecting to the server.
- Add junit test

Result:

Fixes #13417
  • Loading branch information
violetagg authored and normanmaurer committed Jun 5, 2023
1 parent 1b72f37 commit 36fc89b
Showing 1 changed file with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,25 @@ public void testAddresses(TestInfo testInfo) throws Throwable {
run(testInfo, new Runner<ServerBootstrap, Bootstrap>() {
@Override
public void run(ServerBootstrap serverBootstrap, Bootstrap bootstrap) throws Throwable {
testAddresses(serverBootstrap, bootstrap);
testAddresses(serverBootstrap, bootstrap, true);
}
});
}

@Test
@Timeout(value = 30000, unit = TimeUnit.MILLISECONDS)
public void testAddressesConnectWithoutLocalAddress(TestInfo testInfo) throws Throwable {
run(testInfo, new Runner<ServerBootstrap, Bootstrap>() {
@Override
public void run(ServerBootstrap serverBootstrap, Bootstrap bootstrap) throws Throwable {
testAddresses(serverBootstrap, bootstrap, false);
}
});
}

protected abstract void assertAddress(SocketAddress address);

private void testAddresses(ServerBootstrap sb, Bootstrap cb) throws Throwable {
private void testAddresses(ServerBootstrap sb, Bootstrap cb, boolean withLocalAddress) throws Throwable {
Channel serverChannel = null;
Channel clientChannel = null;
try {
Expand All @@ -65,7 +76,11 @@ public void channelActive(ChannelHandlerContext ctx) {
assertNull(clientChannel.localAddress());
assertNull(clientChannel.remoteAddress());

clientChannel.connect(serverChannel.localAddress(), newSocketAddress()).asStage().get();
if (withLocalAddress) {
clientChannel.connect(serverChannel.localAddress(), newSocketAddress()).asStage().get();
} else {
clientChannel.connect(serverChannel.localAddress()).asStage().get();
}

assertAddress(clientChannel.localAddress());
assertAddress(clientChannel.remoteAddress());
Expand Down

0 comments on commit 36fc89b

Please sign in to comment.