use of org.rx.net.AESCodec in project rxlib by RockyLOMO.
the class Socks5CommandRequestHandler method relay.
private void relay(Channel inbound, Channel outbound, Socks5AddressType dstAddrType, UnresolvedEndpoint dstEp, StringBuilder extMsg) {
UnresolvedEndpoint realEp = SocksContext.realDestination(inbound);
ConcurrentLinkedQueue<Object> pendingPackages = new ConcurrentLinkedQueue<>();
inbound.pipeline().addLast(FrontendRelayHandler.PIPELINE_NAME, new FrontendRelayHandler(outbound, pendingPackages));
outbound.pipeline().addLast(BackendRelayHandler.PIPELINE_NAME, new BackendRelayHandler(inbound, pendingPackages));
inbound.writeAndFlush(new DefaultSocks5CommandResponse(Socks5CommandStatus.SUCCESS, dstAddrType)).addListener((ChannelFutureListener) f -> {
if (!f.isSuccess()) {
Sockets.closeOnFlushed(f.channel());
return;
}
SocksProxyServer server = SocksContext.server(inbound);
SocksConfig config = server.getConfig();
if (server.aesRouter(realEp) && config.getTransportFlags().has(TransportFlags.FRONTEND_COMPRESS)) {
ChannelHandler[] handlers = new AESCodec(config.getAesKey()).channelHandlers();
for (int i = handlers.length - 1; i > -1; i--) {
ChannelHandler handler = handlers[i];
inbound.pipeline().addAfter(TransportUtil.ZIP_DECODER, handler.getClass().getSimpleName(), handler);
}
extMsg.append("[FRONTEND_AES]");
}
log.info("socks5[{}] {} => {} connected, dstEp={}[{}] {}", config.getListenPort(), inbound.localAddress(), outbound.remoteAddress(), dstEp, realEp, extMsg.toString());
SocksSupport.ENDPOINT_TRACER.link(inbound, outbound);
});
}
use of org.rx.net.AESCodec in project rxlib by RockyLOMO.
the class Socks5CommandRequestHandler method connect.
private void connect(Channel inbound, Socks5AddressType dstAddrType, RouteEventArgs e) {
SocksProxyServer server = SocksContext.server(inbound);
UnresolvedEndpoint realEp = SocksContext.realDestination(inbound);
Sockets.bootstrap(inbound.eventLoop(), server.getConfig(), outbound -> {
SocksContext.server(outbound, server);
e.getValue().initChannel(outbound);
}).connect(e.getValue().getDestination().socketAddress()).addListener((ChannelFutureListener) f -> {
UnresolvedEndpoint dstEp = e.getValue().getDestination();
if (!f.isSuccess()) {
if (server.onReconnecting != null) {
server.raiseEvent(server.onReconnecting, e);
if (!e.isCancel() && e.isUpstreamChanged()) {
e.reset();
connect(inbound, dstAddrType, e);
return;
}
}
ExceptionHandler.INSTANCE.log("socks5[{}] connect {}[{}] fail", server.getConfig().getListenPort(), dstEp, realEp, f.cause());
inbound.writeAndFlush(new DefaultSocks5CommandResponse(Socks5CommandStatus.FAILURE, dstAddrType)).addListener(ChannelFutureListener.CLOSE);
return;
}
Channel outbound = f.channel();
StringBuilder aesMsg = new StringBuilder();
Socks5ProxyHandler proxyHandler;
SocksConfig config = server.getConfig();
if (server.aesRouter(realEp) && (proxyHandler = outbound.pipeline().get(Socks5ProxyHandler.class)) != null) {
proxyHandler.setHandshakeCallback(() -> {
if (config.getTransportFlags().has(TransportFlags.BACKEND_COMPRESS)) {
ChannelHandler[] handlers = new AESCodec(config.getAesKey()).channelHandlers();
for (int i = handlers.length - 1; i > -1; i--) {
ChannelHandler handler = handlers[i];
outbound.pipeline().addAfter(TransportUtil.ZIP_DECODER, handler.getClass().getSimpleName(), handler);
}
aesMsg.append("[BACKEND_AES]");
}
relay(inbound, outbound, dstAddrType, dstEp, aesMsg);
});
return;
}
relay(inbound, outbound, dstAddrType, dstEp, aesMsg);
});
}
Aggregations