Skip to content

Commit 083605a

Browse files
nihongyechickenlj
authored andcommitted
add socks5 proxy support (apache#3624)
1 parent d2be44d commit 083605a

File tree

1 file changed

+16
-0
lines changed
  • dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4

1 file changed

+16
-0
lines changed

dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/NettyClient.java

+16
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.apache.dubbo.common.Version;
2222
import org.apache.dubbo.common.logger.Logger;
2323
import org.apache.dubbo.common.logger.LoggerFactory;
24+
import org.apache.dubbo.common.utils.ConfigUtils;
2425
import org.apache.dubbo.common.utils.NetUtils;
2526
import org.apache.dubbo.common.utils.UrlUtils;
2627
import org.apache.dubbo.remoting.ChannelHandler;
@@ -35,11 +36,14 @@
3536
import io.netty.channel.ChannelOption;
3637
import io.netty.channel.nio.NioEventLoopGroup;
3738
import io.netty.channel.socket.nio.NioSocketChannel;
39+
import io.netty.handler.proxy.Socks5ProxyHandler;
3840
import io.netty.handler.timeout.IdleStateHandler;
3941
import io.netty.util.concurrent.DefaultThreadFactory;
4042

4143
import static java.util.concurrent.TimeUnit.MILLISECONDS;
4244

45+
import java.net.InetSocketAddress;
46+
4347
/**
4448
* NettyClient.
4549
*/
@@ -48,6 +52,12 @@ public class NettyClient extends AbstractClient {
4852
private static final Logger logger = LoggerFactory.getLogger(NettyClient.class);
4953

5054
private static final NioEventLoopGroup nioEventLoopGroup = new NioEventLoopGroup(Constants.DEFAULT_IO_THREADS, new DefaultThreadFactory("NettyClientWorker", true));
55+
56+
private static final String SOCKS_PROXY_HOST = "socksProxyHost";
57+
58+
private static final String SOCKS_PROXY_PORT = "socksProxyPort";
59+
60+
private static final String DEFAULT_SOCKS_PROXY_PORT = "1080";
5161

5262
private Bootstrap bootstrap;
5363

@@ -85,6 +95,12 @@ protected void initChannel(Channel ch) throws Exception {
8595
.addLast("encoder", adapter.getEncoder())
8696
.addLast("client-idle-handler", new IdleStateHandler(heartbeatInterval, 0, 0, MILLISECONDS))
8797
.addLast("handler", nettyClientHandler);
98+
String socksProxyHost = ConfigUtils.getProperty(SOCKS_PROXY_HOST);
99+
if(socksProxyHost != null) {
100+
int socksProxyPort = Integer.parseInt(ConfigUtils.getProperty(SOCKS_PROXY_PORT, DEFAULT_SOCKS_PROXY_PORT));
101+
Socks5ProxyHandler socks5ProxyHandler = new Socks5ProxyHandler(new InetSocketAddress(socksProxyHost, socksProxyPort));
102+
ch.pipeline().addFirst(socks5ProxyHandler);
103+
}
88104
}
89105
});
90106
}

0 commit comments

Comments
 (0)