Skip to content

Commit

Permalink
#8695: move client address binding to QuicClientConnectorConfigurator
Browse files Browse the repository at this point in the history
Signed-off-by: Ludovic Orban <[email protected]>
  • Loading branch information
lorban committed Oct 17, 2022
1 parent cd282f5 commit 1c96c41
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import java.net.SocketOption;
import java.net.StandardProtocolFamily;
import java.net.StandardSocketOptions;
import java.nio.channels.DatagramChannel;
import java.nio.channels.NetworkChannel;
import java.nio.channels.SelectableChannel;
import java.nio.channels.SelectionKey;
Expand Down Expand Up @@ -502,13 +501,6 @@ protected void configure(SelectableChannel selectable) throws IOException
if (sendBufferSize >= 0)
setSocketOption(channel, StandardSocketOptions.SO_SNDBUF, sendBufferSize);
}
if (selectable instanceof DatagramChannel)
{
// QUIC must know the local address, but it is non-null on datagram sockets only if it has been bound,
// so implicitly bind to 0.0.0.0:0 when no bind address has been set.
if (getBindAddress() == null)
setBindAddress(new InetSocketAddress("0.0.0.0", 0));
}
}

private <T> void setSocketOption(NetworkChannel channel, SocketOption<T> option, T value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ public ChannelWithAddress newChannelWithAddress(ClientConnector clientConnector,
{
context.put(QuicConfiguration.CONTEXT_KEY, configuration);
DatagramChannel channel = DatagramChannel.open();
if (clientConnector.getBindAddress() == null)
{
// QUIC must know the local address for connection migration, so we must always bind early.
channel.bind(null);
}
return new ChannelWithAddress(channel, address);
}

Expand Down

0 comments on commit 1c96c41

Please sign in to comment.