use of org.rx.net.support.SocksSupport in project rxlib by RockyLOMO.
the class Socks5Upstream method initChannel.
@SneakyThrows
@Override
public void initChannel(Channel channel) {
UpstreamSupport next = router.invoke();
if (next == null) {
throw new InvalidException("ProxyHandlers is empty");
}
AuthenticEndpoint svrEp = next.getEndpoint();
SocksSupport support = next.getSupport();
TransportUtil.addBackendHandler(channel, config, svrEp.getEndpoint());
if (support != null && (SocksSupport.FAKE_IPS.contains(destination.getHost()) || SocksSupport.FAKE_PORTS.contains(destination.getPort()) || !Sockets.isValidIp(destination.getHost()))) {
String dstEpStr = destination.toString();
SUID hash = SUID.compute(dstEpStr);
// 先变更
destination = new UnresolvedEndpoint(String.format("%s%s", hash, SocksSupport.FAKE_HOST_SUFFIX), Arrays.randomNext(SocksSupport.FAKE_PORT_OBFS));
Cache.getOrSet(hash, k -> awaitQuietly(() -> {
App.logMetric(String.format("socks5[%s]", config.getListenPort()), dstEpStr);
support.fakeEndpoint(hash, dstEpStr);
return true;
}, SocksSupport.ASYNC_TIMEOUT));
}
Socks5ProxyHandler proxyHandler = new Socks5ProxyHandler(svrEp.getEndpoint(), svrEp.getUsername(), svrEp.getPassword());
proxyHandler.setConnectTimeoutMillis(config.getConnectTimeoutMillis());
channel.pipeline().addLast(proxyHandler);
}
Aggregations