2121import org .apache .dubbo .common .Version ;
2222import org .apache .dubbo .common .logger .Logger ;
2323import org .apache .dubbo .common .logger .LoggerFactory ;
24+ import org .apache .dubbo .common .utils .ConfigUtils ;
2425import org .apache .dubbo .common .utils .NetUtils ;
2526import org .apache .dubbo .common .utils .UrlUtils ;
2627import org .apache .dubbo .remoting .ChannelHandler ;
3536import io .netty .channel .ChannelOption ;
3637import io .netty .channel .nio .NioEventLoopGroup ;
3738import io .netty .channel .socket .nio .NioSocketChannel ;
39+ import io .netty .handler .proxy .Socks5ProxyHandler ;
3840import io .netty .handler .timeout .IdleStateHandler ;
3941import io .netty .util .concurrent .DefaultThreadFactory ;
4042
4143import 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