2011shenlin commented on code in PR #5123:
URL: https://github.com/apache/rocketmq/pull/5123#discussion_r979906183
##########
remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettyRemotingClient.java:
##########
@@ -271,6 +290,83 @@ public void run() {
}
+ private Map.Entry<String, SocksProxyConfig> getProxy(String addr) {
+ String[] addrArr = addr.split(":");
+ for (Map.Entry<String, SocksProxyConfig> entry : proxyMap.entrySet()) {
+ String cidr = entry.getKey();
+ if (RemotingHelper.ipInCIDR(addrArr[0], cidr)) {
+ return entry;
+ }
+ }
+ return null;
+ }
+
+ private Bootstrap fetchBootstrap(String addr) {
+ Map.Entry<String, SocksProxyConfig> proxyEntry = getProxy(addr);
+ if (proxyEntry == null) {
+ return bootstrap;
+ }
+
+ String cidr = proxyEntry.getKey();
+ SocksProxyConfig socksProxyConfig = proxyEntry.getValue();
+
+ LOGGER.info("Netty fetch bootstrap, addr: {}, cidr: {}, proxy: {}",
+ addr, cidr, socksProxyConfig != null ? socksProxyConfig.getAddr()
: "");
+
+ Bootstrap bootstrapWithProxy = bootstrapMap.get(cidr);
+ if (bootstrapWithProxy == null) {
+ bootstrapWithProxy = createBootstrap(socksProxyConfig);
+ Bootstrap old = bootstrapMap.putIfAbsent(cidr, bootstrapWithProxy);
+ if (old != null) {
+ bootstrapWithProxy = old;
+ }
+ }
+ return bootstrapWithProxy;
+ }
+
+ private Bootstrap createBootstrap(final SocksProxyConfig proxy) {
+ Bootstrap bootstrap = new Bootstrap();
+
bootstrap.group(this.eventLoopGroupWorker).channel(NioSocketChannel.class)
+ .option(ChannelOption.TCP_NODELAY, true)
+ .option(ChannelOption.SO_KEEPALIVE, false)
+ .option(ChannelOption.CONNECT_TIMEOUT_MILLIS,
nettyClientConfig.getConnectTimeoutMillis())
+ .option(ChannelOption.SO_SNDBUF,
nettyClientConfig.getClientSocketSndBufSize())
+ .option(ChannelOption.SO_RCVBUF,
nettyClientConfig.getClientSocketRcvBufSize())
+ .handler(new ChannelInitializer<SocketChannel>() {
+ @Override
+ public void initChannel(SocketChannel ch) {
+ ChannelPipeline pipeline = ch.pipeline();
+ if (nettyClientConfig.isUseTLS()) {
+ if (null != sslContext) {
+ pipeline.addFirst(defaultEventExecutorGroup,
+ "sslHandler",
sslContext.newHandler(ch.alloc()));
+ LOGGER.info("Prepend SSL handler");
+ } else {
+ LOGGER.warn("Connections are insecure as
SSLContext is null!");
+ }
+ }
+
+ // Netty Socks5 Proxy
+ if (proxy != null) {
+ String[] arr = proxy.getAddr().split(":");
+ pipeline.addFirst(new Socks5ProxyHandler(
+ new InetSocketAddress(arr[0],
Integer.parseInt(arr[1])),
+ proxy.getUsername(), proxy.getPassword()));
+ }
+
+ pipeline.addLast(
+ nettyClientConfig.isDisableNettyWorkerGroup() ? null :
defaultEventExecutorGroup,
+ new NettyEncoder(),
+ new NettyDecoder(),
+ new IdleStateHandler(0, 0,
nettyClientConfig.getClientChannelMaxIdleTimeSeconds()),
+ new NettyConnectManageHandler(),
+ new NettyClientHandler());
+ }
+ });
+
+ return bootstrap;
Review Comment:
when use socks, DNS should be privided by the target network.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]