Search in sources :

Example 1 with SocksSupport

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);
}
Also used : UnresolvedEndpoint(org.rx.net.support.UnresolvedEndpoint) UpstreamSupport(org.rx.net.support.UpstreamSupport) AuthenticEndpoint(org.rx.net.AuthenticEndpoint) SocksSupport(org.rx.net.support.SocksSupport) InvalidException(org.rx.exception.InvalidException) SUID(org.rx.bean.SUID) SneakyThrows(lombok.SneakyThrows)

Aggregations

SneakyThrows (lombok.SneakyThrows)1 SUID (org.rx.bean.SUID)1 InvalidException (org.rx.exception.InvalidException)1 AuthenticEndpoint (org.rx.net.AuthenticEndpoint)1 SocksSupport (org.rx.net.support.SocksSupport)1 UnresolvedEndpoint (org.rx.net.support.UnresolvedEndpoint)1 UpstreamSupport (org.rx.net.support.UpstreamSupport)1