eclipse-vertx / eclipse-vertx/vert.x

Support setting local address when using tcp based clients

Open
#2,335 7 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
14.7k
Forks
2.1k
Avg merge
2d 7h
Merged PRs (30d)
28

Description

Hi,
My friend was using vertx webclient as a crawling client, while the SA of his company require him to specify the local port for some security reasons.
I read the source code of vertx and found out that the current version vertx doesn't support specifying local address when making tcp connections or creating udp sockets.
However I think it's not difficult to achieve such thing:

I walked through the code and found that when using http client, the connection is setup in [ChannelProvider](https://github.com/eclipse/vert.x/blob/master/src/main/java/io/vertx/core/net/impl/ChannelProvider.java), where `bootstrap.connect` is invoked with one argument (the remote address). I think it's not hard to add an arguemnt to `ChannelProvider#connect` like this:

```java
public void connect(VertxInternal vertx, Bootstrap bootstrap, ProxyOptions options, SocketAddress remoteAddress,
SocketAddress localAddress,
Handler channelInitializer, Handler> channelHandler) {
```

then call `bootstrap.connect` with two arguments (the remote addres and the local address).

And some fields could be added to `NetworkOptions` or `TCPSSLOptions` to store the local address info.

And ofcause, the related code would all be modified.

I would like to make a pr but before that I would like to check whether this fixing method is ok and why it's not supported for now ...

Also, I saw that the argument `ProxyOptions options` is not used in `connect` method, is it safe to be removed?

Looking forward to your reply~

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.