Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add socks5 proxy support #3624

Merged
merged 3 commits into from
Apr 26, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,14 @@
import io.netty.channel.ChannelOption;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.handler.proxy.Socks5ProxyHandler;
import io.netty.handler.timeout.IdleStateHandler;
import io.netty.util.concurrent.DefaultThreadFactory;

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

import java.net.InetSocketAddress;

/**
* NettyClient.
*/
Expand All @@ -48,6 +51,12 @@ public class NettyClient extends AbstractClient {
private static final Logger logger = LoggerFactory.getLogger(NettyClient.class);

private static final NioEventLoopGroup nioEventLoopGroup = new NioEventLoopGroup(Constants.DEFAULT_IO_THREADS, new DefaultThreadFactory("NettyClientWorker", true));

private static final String SOCKS_PROXY_HOST = "socksProxyHost";

private static final String SOCKS_PROXY_PORT = "socksProxyPort";

private static final int DEFAULT_SOCKS_PROXY_PORT = 1080;

private Bootstrap bootstrap;

Expand Down Expand Up @@ -85,6 +94,12 @@ protected void initChannel(Channel ch) throws Exception {
.addLast("encoder", adapter.getEncoder())
.addLast("client-idle-handler", new IdleStateHandler(heartbeatInterval, 0, 0, MILLISECONDS))
.addLast("handler", nettyClientHandler);
String socksProxyHost = System.getProperty(SOCKS_PROXY_HOST);
if(socksProxyHost != null) {
Integer socksProxyPort = Integer.getInteger(SOCKS_PROXY_PORT, DEFAULT_SOCKS_PROXY_PORT);
nihongye marked this conversation as resolved.
Show resolved Hide resolved
Socks5ProxyHandler socks5ProxyHandler = new Socks5ProxyHandler(new InetSocketAddress(socksProxyHost, socksProxyPort));
ch.pipeline().addFirst(socks5ProxyHandler);
}
}
});
}
Expand Down