From 0ef0c958c455744bcb907dab1a98080f4e5e6729 Mon Sep 17 00:00:00 2001 From: "hongye.nhy" Date: Fri, 8 Mar 2019 17:45:00 +0800 Subject: [PATCH 1/2] add socks5 proxy support --- .../remoting/transport/netty4/NettyClient.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/NettyClient.java b/dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/NettyClient.java index 464087e7c23..93d60063427 100644 --- a/dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/NettyClient.java +++ b/dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/NettyClient.java @@ -35,11 +35,14 @@ import io.netty.channel.ChannelOption; import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.socket.nio.NioSocketChannel; +import io.netty.handler.proxy.Socks5ProxyHandler; import io.netty.handler.timeout.IdleStateHandler; import io.netty.util.concurrent.DefaultThreadFactory; import static java.util.concurrent.TimeUnit.MILLISECONDS; +import java.net.InetSocketAddress; + /** * NettyClient. */ @@ -48,6 +51,12 @@ public class NettyClient extends AbstractClient { private static final Logger logger = LoggerFactory.getLogger(NettyClient.class); private static final NioEventLoopGroup nioEventLoopGroup = new NioEventLoopGroup(Constants.DEFAULT_IO_THREADS, new DefaultThreadFactory("NettyClientWorker", true)); + + private static final String SOCKS_PROXY_HOST = "socksProxyHost"; + + private static final String SOCKS_PROXY_PORT = "socksProxyPort"; + + private static final int DEFAULT_SOCKS_PROXY_PORT = 1080; private Bootstrap bootstrap; @@ -85,6 +94,12 @@ protected void initChannel(Channel ch) throws Exception { .addLast("encoder", adapter.getEncoder()) .addLast("client-idle-handler", new IdleStateHandler(heartbeatInterval, 0, 0, MILLISECONDS)) .addLast("handler", nettyClientHandler); + String socksProxyHost = System.getProperty(SOCKS_PROXY_HOST); + if(socksProxyHost != null) { + Integer socksProxyPort = Integer.getInteger(SOCKS_PROXY_PORT, DEFAULT_SOCKS_PROXY_PORT); + Socks5ProxyHandler socks5ProxyHandler = new Socks5ProxyHandler(new InetSocketAddress(socksProxyHost, socksProxyPort)); + ch.pipeline().addFirst(socks5ProxyHandler); + } } }); } From 0fca65d0ae75b31f950626d8e0ce95310a30506e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AA=84=E9=BE=99?= Date: Fri, 19 Apr 2019 19:38:22 +0800 Subject: [PATCH 2/2] replace System.getProperty to ConfigUtils.getProperty --- .../dubbo/remoting/transport/netty4/NettyClient.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/NettyClient.java b/dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/NettyClient.java index 2e5679e48a2..322d658b856 100644 --- a/dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/NettyClient.java +++ b/dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/NettyClient.java @@ -21,6 +21,7 @@ import org.apache.dubbo.common.Version; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; +import org.apache.dubbo.common.utils.ConfigUtils; import org.apache.dubbo.common.utils.NetUtils; import org.apache.dubbo.common.utils.UrlUtils; import org.apache.dubbo.remoting.ChannelHandler; @@ -56,7 +57,7 @@ public class NettyClient extends AbstractClient { private static final String SOCKS_PROXY_PORT = "socksProxyPort"; - private static final int DEFAULT_SOCKS_PROXY_PORT = 1080; + private static final String DEFAULT_SOCKS_PROXY_PORT = "1080"; private Bootstrap bootstrap; @@ -94,9 +95,9 @@ protected void initChannel(Channel ch) throws Exception { .addLast("encoder", adapter.getEncoder()) .addLast("client-idle-handler", new IdleStateHandler(heartbeatInterval, 0, 0, MILLISECONDS)) .addLast("handler", nettyClientHandler); - String socksProxyHost = System.getProperty(SOCKS_PROXY_HOST); + String socksProxyHost = ConfigUtils.getProperty(SOCKS_PROXY_HOST); if(socksProxyHost != null) { - Integer socksProxyPort = Integer.getInteger(SOCKS_PROXY_PORT, DEFAULT_SOCKS_PROXY_PORT); + int socksProxyPort = Integer.parseInt(ConfigUtils.getProperty(SOCKS_PROXY_PORT, DEFAULT_SOCKS_PROXY_PORT)); Socks5ProxyHandler socks5ProxyHandler = new Socks5ProxyHandler(new InetSocketAddress(socksProxyHost, socksProxyPort)); ch.pipeline().addFirst(socks5ProxyHandler); }