【fix】新增本地socks代理服务端

This commit is contained in:
wujiawei
2025-05-03 23:34:28 +08:00
parent 2adf5e4749
commit 24fe9e4bc9
6 changed files with 32 additions and 25 deletions

View File

@ -12,13 +12,16 @@ import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyC
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettySocketChannelContext;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.proxy.socks.client.AbstractHandleSocketClientProxyServerTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.factory.EventLoopGroupFactory;
import org.framework.lazy.cloud.network.heartbeat.common.constant.ProxyMessageType;
import org.springframework.stereotype.Component;
import org.wu.framework.spring.utils.SpringContextHolder;
import java.util.ArrayList;
import java.util.List;
/**
* @see ProxyMessageType#SOCKET_CLIENT_PROXY_SERVER_
*/
@Slf4j
@Component
public class NettySocketProtocolHandleSocketClientProxyServerTypeAdvanced
@ -34,12 +37,9 @@ public class NettySocketProtocolHandleSocketClientProxyServerTypeAdvanced
NettySocketChannelContext nettySocketChannelContext = (NettySocketChannelContext) nettyChannelContext;
Channel channel = nettySocketChannelContext.channel();
ChannelHandlerContext channelHandlerContext = nettySocketChannelContext.channelHandlerContext();
EventLoopGroup group = EventLoopGroupFactory.createClientWorkGroup();
Channel proxyChannel = nettySocketChannelContext.channel();
String host = nettyProxyMsg.getTargetIpString();
Integer port = Integer.parseInt(nettyProxyMsg.getTargetPortString());
Bootstrap b = new Bootstrap();
Socks5AddressType socks5AddressType = nettySocketChannelContext.getSocks5AddressType();
@ -58,7 +58,7 @@ public class NettySocketProtocolHandleSocketClientProxyServerTypeAdvanced
nettySocksClientProxyServer.setNettyClientProperties(nettyClientProperties);
// 创建连接
NettySocksClientProxyServerSocket.buildTransferServer(nettySocksClientProxyServer, channel);
NettySocksClientProxyServerSocket.buildTransferServer(nettySocksClientProxyServer, proxyChannel);

View File

@ -28,12 +28,12 @@ public class NettyClientProxyServerVisitorInboundHandler extends SimpleChannelIn
@Override
public void channelRead0(ChannelHandlerContext ctx, NettyByteBuf nettyByteBuf) throws Exception {
log.info("转发客户端的请求到代理服务器");
log.info("【socks】转发客户端的请求到代理服务器");
// 结果下发
Channel channel = ctx.channel();
byte[] bytes = nettyByteBuf.getData();
log.debug("bytes.length:{}",bytes.length);
log.debug("客户端代理服务端,本地接收请求数据:{}", new String(bytes));
log.debug("客户端代理服务端,socks本地接收请求数据:{}", new String(bytes));
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
if (nextChannel.isActive()) {
@ -51,7 +51,7 @@ public class NettyClientProxyServerVisitorInboundHandler extends SimpleChannelIn
@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
log.info("客户端与代理服务器的连接已经断开,即将断开代理服务器和目标服务器的连接");
log.info("【socks】客户端与代理服务器的连接已经断开,即将断开代理服务器和目标服务器的连接");
Channel channel = ctx.channel();
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
if (nextChannel.isActive()) {
@ -67,7 +67,7 @@ public class NettyClientProxyServerVisitorInboundHandler extends SimpleChannelIn
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
log.error("NettyClientProxyServerVisitorInboundHandler exception", cause);
log.error("【socks】NettyClientProxyServerVisitorInboundHandler exception", cause);
ctx.close();
}
}