21
21
import org .apache .dubbo .common .Version ;
22
22
import org .apache .dubbo .common .logger .Logger ;
23
23
import org .apache .dubbo .common .logger .LoggerFactory ;
24
+ import org .apache .dubbo .common .utils .ConfigUtils ;
24
25
import org .apache .dubbo .common .utils .NetUtils ;
25
26
import org .apache .dubbo .common .utils .UrlUtils ;
26
27
import org .apache .dubbo .remoting .ChannelHandler ;
35
36
import io .netty .channel .ChannelOption ;
36
37
import io .netty .channel .nio .NioEventLoopGroup ;
37
38
import io .netty .channel .socket .nio .NioSocketChannel ;
39
+ import io .netty .handler .proxy .Socks5ProxyHandler ;
38
40
import io .netty .handler .timeout .IdleStateHandler ;
39
41
import io .netty .util .concurrent .DefaultThreadFactory ;
40
42
41
43
import static java .util .concurrent .TimeUnit .MILLISECONDS ;
42
44
45
+ import java .net .InetSocketAddress ;
46
+
43
47
/**
44
48
* NettyClient.
45
49
*/
@@ -48,6 +52,12 @@ public class NettyClient extends AbstractClient {
48
52
private static final Logger logger = LoggerFactory .getLogger (NettyClient .class );
49
53
50
54
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" ;
51
61
52
62
private Bootstrap bootstrap ;
53
63
@@ -85,6 +95,12 @@ protected void initChannel(Channel ch) throws Exception {
85
95
.addLast ("encoder" , adapter .getEncoder ())
86
96
.addLast ("client-idle-handler" , new IdleStateHandler (heartbeatInterval , 0 , 0 , MILLISECONDS ))
87
97
.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
+ }
88
104
}
89
105
});
90
106
}
0 commit comments