You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by ky...@apache.org on 2021/09/24 06:32:15 UTC

[dubbo] branch 3.0 updated: [3.0] socks proxy filtering local address (#8876)

This is an automated email from the ASF dual-hosted git repository.

kylixs pushed a commit to branch 3.0
in repository https://gitbox.apache.org/repos/asf/dubbo.git


The following commit(s) were added to refs/heads/3.0 by this push:
     new e68d89e  [3.0] socks proxy filtering local address (#8876)
e68d89e is described below

commit e68d89e00d64c2e1448ed4684e2b2f94078ee376
Author: Gong Dewei <ky...@qq.com>
AuthorDate: Fri Sep 24 14:32:04 2021 +0800

    [3.0] socks proxy filtering local address (#8876)
---
 .../apache/dubbo/remoting/transport/netty4/NettyClient.java   | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

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 086ead5..5d7fb3e 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
@@ -32,6 +32,7 @@ import org.apache.dubbo.common.config.ConfigurationUtils;
 import org.apache.dubbo.common.logger.Logger;
 import org.apache.dubbo.common.logger.LoggerFactory;
 import org.apache.dubbo.common.utils.NetUtils;
+import org.apache.dubbo.common.utils.StringUtils;
 import org.apache.dubbo.remoting.ChannelHandler;
 import org.apache.dubbo.remoting.Constants;
 import org.apache.dubbo.remoting.RemotingException;
@@ -118,7 +119,7 @@ public class NettyClient extends AbstractClient {
                         .addLast("handler", nettyClientHandler);
 
                 String socksProxyHost = ConfigurationUtils.getProperty(getUrl().getOrDefaultApplicationModel(), SOCKS_PROXY_HOST);
-                if(socksProxyHost != null) {
+                if(socksProxyHost != null && !isFilteredAddress(getUrl().getHost())) {
                     int socksProxyPort = Integer.parseInt(ConfigurationUtils.getProperty(getUrl().getOrDefaultApplicationModel(), SOCKS_PROXY_PORT, DEFAULT_SOCKS_PROXY_PORT));
                     Socks5ProxyHandler socks5ProxyHandler = new Socks5ProxyHandler(new InetSocketAddress(socksProxyHost, socksProxyPort));
                     ch.pipeline().addFirst(socks5ProxyHandler);
@@ -127,6 +128,14 @@ public class NettyClient extends AbstractClient {
         });
     }
 
+    private boolean isFilteredAddress(String host) {
+        // filter local address
+        if (StringUtils.isEquals(NetUtils.getLocalHost(), host) || NetUtils.isLocalHost(host)) {
+            return true;
+        }
+        return false;
+    }
+
     @Override
     protected void doConnect() throws Throwable {
         long start = System.currentTimeMillis();