Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@

import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.Version;
import org.apache.dubbo.common.config.ConfigurationUtils;
import org.apache.dubbo.common.utils.NetUtils;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.remoting.ChannelHandler;
import org.apache.dubbo.remoting.Constants;
import org.apache.dubbo.remoting.RemotingException;
Expand All @@ -28,6 +30,7 @@
import org.apache.dubbo.remoting.transport.netty4.ssl.SslContexts;
import org.apache.dubbo.remoting.utils.UrlUtils;

import java.net.InetSocketAddress;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;

Expand All @@ -40,6 +43,7 @@
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http2.Http2FrameCodec;
import io.netty.handler.proxy.Socks5ProxyHandler;
import io.netty.handler.ssl.SslContext;
import io.netty.handler.timeout.IdleStateHandler;
import io.netty.util.concurrent.DefaultPromise;
Expand All @@ -52,6 +56,12 @@

public final class NettyConnectionClient extends AbstractNettyConnectionClient {

private static final String SOCKS_PROXY_HOST = "socksProxyHost";

private static final String SOCKS_PROXY_PORT = "socksProxyPort";

private static final String DEFAULT_SOCKS_PROXY_PORT = "1080";
Comment on lines +59 to +63

private Bootstrap bootstrap;

private AtomicReference<Promise<Void>> channelInitializedPromiseRef;
Expand All @@ -70,6 +80,7 @@ protected void initConnectionClient() {
super.initConnectionClient();
}

@Override
protected void initBootstrap() {
channelInitializedPromiseRef = new AtomicReference<>();
Bootstrap bootstrap = new Bootstrap();
Expand Down Expand Up @@ -124,7 +135,16 @@ protected void initChannel(SocketChannel ch) {

// set null but do not close this client, it will be reconnecting in the future
ch.closeFuture().addListener(channelFuture -> clearNettyChannel());
// TODO support Socks5
// support Socks5
String socksProxyHost =
ConfigurationUtils.getProperty(getUrl().getOrDefaultApplicationModel(), SOCKS_PROXY_HOST);
if (socksProxyHost != null && !isFilteredAddress(getUrl().getHost())) {
int socksProxyPort = Integer.parseInt(ConfigurationUtils.getProperty(
getUrl().getOrDefaultApplicationModel(), SOCKS_PROXY_PORT, DEFAULT_SOCKS_PROXY_PORT));
Comment on lines +141 to +143
Socks5ProxyHandler socks5ProxyHandler =
new Socks5ProxyHandler(new InetSocketAddress(socksProxyHost, socksProxyPort));
Comment on lines +144 to +145
pipeline.addFirst(socks5ProxyHandler);
}
Comment on lines +138 to +147

// set channel initialized promise to success if necessary.
Promise<Void> channelInitializedPromise = channelInitializedPromiseRef.get();
Expand Down Expand Up @@ -227,4 +247,9 @@ private void waitConnectionPreface(long start) throws RemotingException {
throw remotingException;
}
}

private boolean isFilteredAddress(String host) {
// filter local address
return StringUtils.isEquals(NetUtils.getLocalHost(), host) || NetUtils.isLocalHost(host);
}
}
Loading