[update] 显式指定注解处理器,4.x

This commit is contained in:
wujiawei
2026-01-06 23:30:55 +08:00
parent 9d9f3fc4c6
commit 4d6c5fcbd7
47 changed files with 198 additions and 87 deletions

View File

@@ -4,6 +4,7 @@ package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.soc
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.*;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.nio.NioIoHandler;
import io.netty.channel.socket.nio.NioSocketChannel;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
@@ -24,7 +25,7 @@ import java.util.concurrent.TimeUnit;
*/
@Slf4j
public class NettyTcpClientPermeateClientRealSocket {
static EventLoopGroup eventLoopGroup = new NioEventLoopGroup();
static EventLoopGroup eventLoopGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory());
public static void buildRealServer(String clientId,

View File

@@ -4,6 +4,7 @@ package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.soc
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.*;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.nio.NioIoHandler;
import io.netty.channel.socket.nio.NioSocketChannel;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
@@ -21,7 +22,7 @@ import java.util.concurrent.TimeUnit;
*/
@Slf4j
public class NettyTcpClientPermeateClientVisitorTransferSocket {
static EventLoopGroup eventLoopGroup = new NioEventLoopGroup();
static EventLoopGroup eventLoopGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory());
/**
* 连接服务端通信通道

View File

@@ -4,6 +4,7 @@ package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.soc
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.*;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.nio.NioIoHandler;
import io.netty.channel.socket.nio.NioSocketChannel;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
@@ -21,7 +22,7 @@ import java.util.concurrent.TimeUnit;
*/
@Slf4j
public class NettyTcpClientPermeateServerVisitorTransferSocket {
static EventLoopGroup eventLoopGroup = new NioEventLoopGroup();
static EventLoopGroup eventLoopGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory());
/**
* 连接服务端通信通道

View File

@@ -4,6 +4,7 @@ package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.soc
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.*;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.nio.NioIoHandler;
import io.netty.channel.socket.nio.NioSocketChannel;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
@@ -26,7 +27,7 @@ import java.util.concurrent.TimeUnit;
*/
@Slf4j
public class NettyTcpClientSocket implements NettyClientSocket {
private final EventLoopGroup eventLoopGroup = new NioEventLoopGroup();
private final EventLoopGroup eventLoopGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory());
/**
* 服务端host
*/

View File

@@ -4,6 +4,7 @@ package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.soc
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.*;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.nio.NioIoHandler;
import io.netty.channel.socket.nio.NioSocketChannel;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
@@ -24,7 +25,7 @@ import java.util.concurrent.TimeUnit;
*/
@Slf4j
public class NettyTcpServerPermeateClientRealSocket {
static EventLoopGroup eventLoopGroup = new NioEventLoopGroup();
static EventLoopGroup eventLoopGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory());
/**
* 连接真实服务

View File

@@ -4,6 +4,7 @@ package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.udp.soc
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.*;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.nio.NioIoHandler;
import io.netty.channel.socket.nio.NioSocketChannel;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
@@ -24,7 +25,7 @@ import java.util.concurrent.TimeUnit;
*/
@Slf4j
public class NettyUdpClientPermeateClientRealSocket {
static EventLoopGroup eventLoopGroup = new NioEventLoopGroup();
static EventLoopGroup eventLoopGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory());
public static void buildRealServer(String clientId,

View File

@@ -3,15 +3,15 @@ package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.udp.soc
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.*;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.nio.NioIoHandler;
import io.netty.channel.socket.nio.NioSocketChannel;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.NettyClientPermeateClientVisitor;
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.udp.filter.NettyUdpClientPermeateClientTransferFilter;
import org.framework.lazy.cloud.network.heartbeat.common.constant.UdpMessageType;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelTypeAdapter;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.constant.UdpMessageType;
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
import java.util.concurrent.TimeUnit;
@@ -21,7 +21,7 @@ import java.util.concurrent.TimeUnit;
*/
@Slf4j
public class NettyUdpClientPermeateClientVisitorTransferSocket {
static EventLoopGroup eventLoopGroup = new NioEventLoopGroup();
static EventLoopGroup eventLoopGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory());
/**
* 连接服务端通信通道

View File

@@ -4,6 +4,7 @@ package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.udp.soc
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.*;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.nio.NioIoHandler;
import io.netty.channel.socket.nio.NioSocketChannel;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
@@ -21,7 +22,7 @@ import java.util.concurrent.TimeUnit;
*/
@Slf4j
public class NettyUdpClientPermeateServerVisitorTransferSocket {
static EventLoopGroup eventLoopGroup = new NioEventLoopGroup();
static EventLoopGroup eventLoopGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory());
/**
* 连接服务端通信通道

View File

@@ -4,6 +4,7 @@ package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.udp.soc
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.*;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.nio.NioIoHandler;
import io.netty.channel.socket.nio.NioDatagramChannel;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
@@ -26,7 +27,7 @@ import java.util.concurrent.TimeUnit;
*/
@Slf4j
public class NettyUdpClientSocket implements NettyClientSocket {
private final EventLoopGroup eventLoopGroup = new NioEventLoopGroup();
private final EventLoopGroup eventLoopGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory());
/**
* 服务端host
*/

View File

@@ -3,7 +3,7 @@ package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.udp.soc
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.*;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.nio.NioIoHandler;
import io.netty.channel.socket.nio.NioSocketChannel;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
@@ -11,10 +11,10 @@ import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.udp.filt
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.udp.filter.NettyUdpServerPermeateClientTransferFilter;
import org.framework.lazy.cloud.network.heartbeat.common.InternalNetworkPenetrationRealClient;
import org.framework.lazy.cloud.network.heartbeat.common.NettyCommunicationIdContext;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.constant.UdpMessageType;
import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelTypeAdapter;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.constant.UdpMessageType;
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
import java.util.List;
@@ -25,7 +25,7 @@ import java.util.concurrent.TimeUnit;
*/
@Slf4j
public class NettyUdpServerPermeateClientRealSocket {
static EventLoopGroup eventLoopGroup = new NioEventLoopGroup();
static EventLoopGroup eventLoopGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory());
/**
* 连接真实服务

View File

@@ -4,6 +4,7 @@ package org.framework.lazy.cloud.network.heartbeat.client.netty.proxy.http.socke
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.*;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.nio.NioIoHandler;
import io.netty.channel.socket.nio.NioSocketChannel;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
@@ -24,7 +25,7 @@ import java.util.concurrent.TimeUnit;
*/
@Slf4j
public class NettyHttpClientProxyClientRealSocket {
static EventLoopGroup eventLoopGroup = new NioEventLoopGroup();
static EventLoopGroup eventLoopGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory());
public static void buildRealServer(String clientId,

View File

@@ -3,14 +3,14 @@ package org.framework.lazy.cloud.network.heartbeat.client.netty.proxy.http.socke
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.*;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.nio.NioIoHandler;
import io.netty.channel.socket.nio.NioSocketChannel;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
import org.framework.lazy.cloud.network.heartbeat.client.netty.proxy.http.NettyHttpClientProxyServer;
import org.framework.lazy.cloud.network.heartbeat.client.netty.proxy.http.filter.NettyHttpClientProxyServerProxyFilter;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelTypeAdapter;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.constant.ProxyMessageType;
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
@@ -22,7 +22,7 @@ import java.util.concurrent.TimeUnit;
*/
@Slf4j
public class NettyHttpClientProxyServerProxySocket {
static EventLoopGroup eventLoopGroup = new NioEventLoopGroup();
static EventLoopGroup eventLoopGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory());
/**
* 连接服务端通信通道

View File

@@ -5,6 +5,7 @@ package org.framework.lazy.cloud.network.heartbeat.client.netty.proxy.http.socke
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.*;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.nio.NioIoHandler;
import io.netty.channel.socket.nio.NioSocketChannel;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
@@ -25,7 +26,7 @@ import java.util.concurrent.TimeUnit;
*/
@Slf4j
public class NettyHttpServerProxyClientRealSocket {
static EventLoopGroup eventLoopGroup = new NioEventLoopGroup();
static EventLoopGroup eventLoopGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory());
public static void buildRealServer(String clientId,

View File

@@ -12,6 +12,7 @@ import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyP
import org.framework.lazy.cloud.network.heartbeat.common.advanced.proxy.socks.client.AbstractHandleSocksDistributeClientProxyClientConnectionTransferSuccessTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.decoder.TransferDecoder;
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelUtils;
import org.framework.lazy.cloud.network.heartbeat.protocol.handler.NettySocks5CommandRequestHandler;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Role;
@@ -47,7 +48,9 @@ public class ClientHandleDistributeSocksClientProxyClientConnectionTransferSucce
DefaultSocks5CommandResponse commandResponse =
new DefaultSocks5CommandResponse(Socks5CommandStatus.SUCCESS, socks5AddressType);
nextChannel.writeAndFlush(commandResponse);
nextChannel.pipeline().remove(NettySocks5CommandRequestHandler.class);
nextChannel.pipeline().remove(Socks5CommandRequestDecoder.class);
ChannelUtils.safeRemoveHandler(nextChannel,NettySocks5CommandRequestHandler.class);
ChannelUtils.safeRemoveHandler(nextChannel,Socks5CommandRequestDecoder.class);
}
}

View File

@@ -12,6 +12,7 @@ import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyP
import org.framework.lazy.cloud.network.heartbeat.common.advanced.proxy.socks.client.AbstractHandleSocksDistributeClientProxyServerConnectionTransferSuccessTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.decoder.TransferDecoder;
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelUtils;
import org.framework.lazy.cloud.network.heartbeat.protocol.handler.NettySocks5CommandRequestHandler;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Role;
@@ -47,7 +48,8 @@ public class ClientHandleDistributeSocksClientProxyServerConnectionTransferSucce
DefaultSocks5CommandResponse commandResponse =
new DefaultSocks5CommandResponse(Socks5CommandStatus.SUCCESS, socks5AddressType);
nextChannel.writeAndFlush(commandResponse);
nextChannel.pipeline().remove(NettySocks5CommandRequestHandler.class);
nextChannel.pipeline().remove(Socks5CommandRequestDecoder.class);
ChannelUtils.safeRemoveHandler(nextChannel,NettySocks5CommandRequestHandler.class);
ChannelUtils.safeRemoveHandler(nextChannel,Socks5CommandRequestDecoder.class);
}
}

View File

@@ -1,15 +1,17 @@
package org.framework.lazy.cloud.network.heartbeat.common.factory;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.MultiThreadIoEventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.nio.NioIoHandler;
public class EventLoopGroupFactory {
private static final EventLoopGroup bossGroup = new NioEventLoopGroup();
private static final EventLoopGroup workerGroup = new NioEventLoopGroup();
private static final EventLoopGroup bossGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory());
private static final EventLoopGroup workerGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory());
// 客户端工作分组
private static final EventLoopGroup clientWorkGroup = new NioEventLoopGroup();
private static final EventLoopGroup clientWorkGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory());
public static EventLoopGroup createBossGroup(){
return bossGroup;

View File

@@ -0,0 +1,78 @@
package org.framework.lazy.cloud.network.heartbeat.common.utils;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPipeline;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class ChannelUtils {
/**
* 安全移除Pipeline中的Handler核心先检查存在性避免重复移除
*
* @param channel 目标通道
* @param handlerClass 要移除的Handler类
*/
public static <T extends ChannelHandler> void safeRemoveHandler(Channel channel, Class<T> handlerClass) {
if (channel == null || !channel.isOpen() || !channel.isActive()) {
// 通道已关闭,直接返回,不操作
return;
}
ChannelPipeline pipeline = channel.pipeline();
// 核心先检查Handler是否存在再移除
if (pipeline.get(handlerClass) != null) {
try {
pipeline.remove(handlerClass);
log.info("Handler {} 移除成功", handlerClass.getSimpleName());
} catch (Exception e) {
// 捕获异常,避免程序崩溃(仅打印日志,不中断流程)
log.error("移除Handler失败{}", e.getMessage());
}
}
}
/**
* 安全移除Pipeline中的Handler核心先检查存在性避免重复移除
*
* @param channelHandlerContext 目标通道
* @param handlerClass 要移除的Handler类
*/
public static <T extends ChannelHandler> void safeRemoveHandler(ChannelHandlerContext channelHandlerContext, Class<T> handlerClass) {
ChannelPipeline pipeline = channelHandlerContext.pipeline();
// 核心先检查Handler是否存在再移除
if (pipeline.get(handlerClass) != null) {
try {
pipeline.remove(handlerClass);
log.info("Handler {} 移除成功", handlerClass.getSimpleName());
} catch (Exception e) {
// 捕获异常,避免程序崩溃(仅打印日志,不中断流程)
log.error("移除Handler失败{}", e.getMessage());
}
}
} /**
* 安全移除Pipeline中的Handler核心先检查存在性避免重复移除
*
* @param channelHandlerContext 目标通道
* @param channelHandler 要移除的Handler
*/
public static <T extends ChannelHandler> void safeRemoveHandler(ChannelHandlerContext channelHandlerContext, ChannelHandler channelHandler) {
if (channelHandler==null){
return;
}
Class<? extends ChannelHandler> handlerClass = channelHandler.getClass();
ChannelPipeline pipeline = channelHandlerContext.pipeline();
// 核心先检查Handler是否存在再移除
if (pipeline.get(handlerClass) != null) {
try {
pipeline.remove(handlerClass);
log.info("Handler {} 移除成功", handlerClass.getSimpleName());
} catch (Exception e) {
// 捕获异常,避免程序崩溃(仅打印日志,不中断流程)
log.error("移除Handler失败{}", e.getMessage());
}
}
}
}

View File

@@ -20,7 +20,7 @@ public class DnsServer {
}
public void run() throws Exception {
EventLoopGroup group = new NioEventLoopGroup();
EventLoopGroup group = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory());
try {
Bootstrap b = new Bootstrap();
b.group(group)

View File

@@ -19,8 +19,8 @@ public class HttpProxyServer {
private static final int PORT = 8001;
public static void main(String[] args) throws Exception {
EventLoopGroup bossGroup = new NioEventLoopGroup();
EventLoopGroup workerGroup = new NioEventLoopGroup();
EventLoopGroup bossGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory());
EventLoopGroup workerGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory());
try {
ServerBootstrap b = new ServerBootstrap();
b.group(bossGroup, workerGroup)

View File

@@ -23,8 +23,8 @@ public class MultiProtocolProxyServer {
private static final int UDP_PORT = 10000;
public static void main(String[] args) throws Exception {
EventLoopGroup bossGroup = new NioEventLoopGroup();
EventLoopGroup workerGroup = new NioEventLoopGroup();
EventLoopGroup bossGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory());
EventLoopGroup workerGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory());
try {
// 启动 HTTP 代理服务器

View File

@@ -42,7 +42,7 @@ public final class DnsServer {
ProxyUdp proxyUdp = new ProxyUdp();
proxyUdp.init();
final int[] num = {0};
final NioEventLoopGroup group = new NioEventLoopGroup();
final NioEventLoopGroup group = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory());
Bootstrap bootstrap = new Bootstrap();
bootstrap.group(group).channel(NioDatagramChannel.class)
.handler(new ChannelInitializer<NioDatagramChannel>() {

View File

@@ -19,7 +19,7 @@ class ProxyUdp {
private Channel proxyChannel;
public void init() throws InterruptedException {
EventLoopGroup proxyGroup = new NioEventLoopGroup();
EventLoopGroup proxyGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory());
Bootstrap b = new Bootstrap();
b.group(proxyGroup)
.channel(NioDatagramChannel.class)

View File

@@ -17,6 +17,7 @@ import org.framework.lazy.cloud.network.heartbeat.common.decoder.TransferDecoder
import org.framework.lazy.cloud.network.heartbeat.common.encoder.TransferEncoder;
import org.framework.lazy.cloud.network.heartbeat.common.factory.EventLoopGroupFactory;
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelUtils;
import org.framework.lazy.cloud.network.heartbeat.protocol.handler.NettyProxy2RealInboundHandler;
import org.framework.lazy.cloud.network.heartbeat.protocol.handler.NettySocketBackendHandler;
import org.framework.lazy.cloud.network.heartbeat.protocol.handler.NettySocks5CommandRequestHandler;
@@ -71,13 +72,16 @@ public class NettySocketProtocolHandleSocketLocalProxyTypeAdvanced
ChannelAttributeKeyUtils.buildVisitorId(realChannel, visitorId);
//添加客户端转发请求到服务端的Handler
// 解码、编码
proxyChannel.pipeline().addLast(new TransferDecoder(Integer.MAX_VALUE, 1024 * 1024 * 10));
proxyChannel.pipeline().addLast(new TransferEncoder());
proxyChannel.pipeline().addLast(new NettyProxy2RealInboundHandler());
ChannelPipeline channelPipeline = proxyChannel.pipeline();
channelPipeline.addLast(new TransferDecoder(Integer.MAX_VALUE, 1024 * 1024 * 10));
channelPipeline.addLast(new TransferEncoder());
channelPipeline.addLast(new NettyProxy2RealInboundHandler());
DefaultSocks5CommandResponse commandResponse = new DefaultSocks5CommandResponse(Socks5CommandStatus.SUCCESS, socks5AddressType);
proxyChannel.writeAndFlush(commandResponse);
proxyChannel.pipeline().remove(NettySocks5CommandRequestHandler.class);
proxyChannel.pipeline().remove(Socks5CommandRequestDecoder.class);
ChannelUtils.safeRemoveHandler(proxyChannel,NettySocks5CommandRequestHandler.class);
ChannelUtils.safeRemoveHandler(proxyChannel,Socks5CommandRequestDecoder.class);
} else {
log.error("连接目标服务器失败,address={},port={}", host, port);
DefaultSocks5CommandResponse commandResponse = new DefaultSocks5CommandResponse(Socks5CommandStatus.FAILURE, socks5AddressType);

View File

@@ -3,6 +3,7 @@ package org.framework.lazy.cloud.network.heartbeat.protocol.context;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.*;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.nio.NioIoHandler;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.handler.logging.LogLevel;
import io.netty.handler.logging.LoggingHandler;
@@ -17,8 +18,8 @@ import org.springframework.stereotype.Component;
@Component
public class NettyHttpProxySocketApplicationListener implements SocketApplicationListener {
private final EventLoopGroup bossGroup = new NioEventLoopGroup();
private final EventLoopGroup workerGroup = new NioEventLoopGroup();
private final EventLoopGroup bossGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory());
private final EventLoopGroup workerGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory());
private final NettyHttpProxyFilter nettyHttpProxyFilter;// 通道业务处理
private final ProtocolProxyProperties protocolProxyProperties;
private ChannelFuture channelFuture;

View File

@@ -3,6 +3,7 @@ package org.framework.lazy.cloud.network.heartbeat.protocol.context;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.*;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.nio.NioIoHandler;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import jakarta.annotation.PreDestroy;
import lombok.extern.slf4j.Slf4j;
@@ -15,8 +16,8 @@ import org.springframework.stereotype.Component;
@Component
public class NettySocketProxySocketApplicationListener implements SocketApplicationListener {
private final EventLoopGroup bossGroup = new NioEventLoopGroup();
private final EventLoopGroup workerGroup = new NioEventLoopGroup();
private final EventLoopGroup bossGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory());
private final EventLoopGroup workerGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory());
private final NettyTcpProxyFilter nettyTcpProxyFilter;// 通道业务处理
private final ProtocolProxyProperties protocolProxyProperties;
private ChannelFuture channelFuture;
@@ -55,7 +56,7 @@ public class NettySocketProxySocketApplicationListener implements SocketApplicat
.childHandler(nettyTcpProxyFilter);
channelFuture = b.bind(socketProtocolProxyPort).sync();
channelFuture.addListener((ChannelFutureListener) channelFuture -> {
channelFuture.addListener((ChannelFutureListener) _ -> {
// 服务器已启动
log.info("Socket 协议代理 服务器启动成功 【{}】", socketProtocolProxyPort);
});

View File

@@ -4,6 +4,7 @@ import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.codec.socksx.v5.*;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelUtils;
import org.framework.lazy.cloud.network.heartbeat.protocol.auth.NettyPasswordAuth;
import org.framework.lazy.cloud.network.heartbeat.protocol.properties.ProtocolProxyProperties;
@@ -41,9 +42,9 @@ public class NettySocks5InitialRequestHandler extends SimpleChannelInboundHandle
ctx.writeAndFlush(socks5InitialResponse);
}
ChannelUtils.safeRemoveHandler(ctx,Socks5InitialRequestDecoder.class);
ChannelUtils.safeRemoveHandler(ctx,this);
ctx.pipeline().remove(this);
ctx.pipeline().remove(Socks5InitialRequestDecoder.class);
}
@Override

View File

@@ -5,6 +5,7 @@ import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.codec.socksx.v5.*;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelUtils;
import org.framework.lazy.cloud.network.heartbeat.protocol.auth.NettyPasswordAuth;
@Slf4j
@@ -28,8 +29,9 @@ public class NettySocks5PasswordAuthRequestInboundHandler extends SimpleChannelI
log.debug("认证直接成功");
Socks5PasswordAuthResponse passwordAuthResponse = new DefaultSocks5PasswordAuthResponse(Socks5PasswordAuthStatus.SUCCESS);
ctx.writeAndFlush(passwordAuthResponse);
ctx.pipeline().remove(this);
ctx.pipeline().remove(Socks5PasswordAuthRequestDecoder.class);
ChannelUtils.safeRemoveHandler(ctx,this);
ChannelUtils.safeRemoveHandler(ctx,Socks5PasswordAuthRequestDecoder.class);
} else {
log.error("授权失败: with username:{} password:{}", username, password);
// 认证失败

View File

@@ -1,11 +1,9 @@
package org.framework.lazy.cloud.network.heartbeat.protocol;
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.*;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.nio.NioIoHandler;
import io.netty.channel.socket.DatagramChannel;
import io.netty.channel.socket.nio.NioDatagramChannel;
import io.netty.handler.codec.dns.DatagramDnsQueryDecoder;
@@ -24,7 +22,7 @@ public class DnsServer {
}
public void run() throws Exception {
EventLoopGroup group = new NioEventLoopGroup();
EventLoopGroup group = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory());
try {
Bootstrap b = new Bootstrap();
b.group(group)

View File

@@ -5,6 +5,7 @@ import io.netty.bootstrap.ServerBootstrap;
import io.netty.buffer.Unpooled;
import io.netty.channel.*;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.nio.NioIoHandler;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.channel.socket.nio.NioSocketChannel;
@@ -21,8 +22,8 @@ public class HttpProxyServer {
private static final int PORT = 8080;
public static void main(String[] args) throws Exception {
EventLoopGroup bossGroup = new NioEventLoopGroup();
EventLoopGroup workerGroup = new NioEventLoopGroup();
EventLoopGroup bossGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory());
EventLoopGroup workerGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory());
try {
ServerBootstrap b = new ServerBootstrap();
b.group(bossGroup, workerGroup)

View File

@@ -5,6 +5,7 @@ import io.netty.bootstrap.ServerBootstrap;
import io.netty.buffer.Unpooled;
import io.netty.channel.*;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.nio.NioIoHandler;
import io.netty.channel.socket.DatagramPacket;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioDatagramChannel;
@@ -25,8 +26,8 @@ public class MultiProtocolProxyServer {
private static final int UDP_PORT = 10000;
public static void main(String[] args) throws Exception {
EventLoopGroup bossGroup = new NioEventLoopGroup();
EventLoopGroup workerGroup = new NioEventLoopGroup();
EventLoopGroup bossGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory());
EventLoopGroup workerGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory());
try {
// 启动 HTTP 代理服务器

View File

@@ -6,6 +6,7 @@ import io.netty.bootstrap.Bootstrap;
import io.netty.buffer.Unpooled;
import io.netty.channel.*;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.nio.NioIoHandler;
import io.netty.channel.socket.nio.NioDatagramChannel;
import io.netty.handler.codec.dns.*;
import io.netty.util.AttributeKey;
@@ -42,7 +43,7 @@ public final class DnsServer {
ProxyUdp proxyUdp = new ProxyUdp();
proxyUdp.init();
final int[] num = {0};
final NioEventLoopGroup group = new NioEventLoopGroup();
final EventLoopGroup group = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory());
Bootstrap bootstrap = new Bootstrap();
bootstrap.group(group).channel(NioDatagramChannel.class)
.handler(new ChannelInitializer<NioDatagramChannel>() {

View File

@@ -5,6 +5,7 @@ import io.netty.buffer.ByteBufUtil;
import io.netty.buffer.Unpooled;
import io.netty.channel.*;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.nio.NioIoHandler;
import io.netty.channel.socket.DatagramChannel;
import io.netty.channel.socket.nio.NioDatagramChannel;
import io.netty.handler.codec.dns.*;
@@ -19,7 +20,7 @@ class ProxyUdp {
private Channel proxyChannel;
public void init() throws InterruptedException {
EventLoopGroup proxyGroup = new NioEventLoopGroup();
EventLoopGroup proxyGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory());
Bootstrap b = new Bootstrap();
b.group(proxyGroup)
.channel(NioDatagramChannel.class)

View File

@@ -7,6 +7,7 @@ import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.handler.codec.socksx.v5.*;
import io.netty.util.ReferenceCountUtil;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelUtils;
import java.net.InetSocketAddress;
@@ -41,8 +42,9 @@ public class Socks5CommandRequestHandler extends SimpleChannelInboundHandler<Soc
ctx.pipeline().addLast(new Client2DestInboundHandler(future));
DefaultSocks5CommandResponse commandResponse = new DefaultSocks5CommandResponse(Socks5CommandStatus.SUCCESS, request.dstAddrType());
ctx.writeAndFlush(commandResponse);
ctx.pipeline().remove(Socks5CommandRequestHandler.class);
ctx.pipeline().remove(Socks5CommandRequestDecoder.class);
ChannelUtils.safeRemoveHandler(ctx,Socks5CommandRequestHandler.class);
ChannelUtils.safeRemoveHandler(ctx,Socks5CommandRequestDecoder.class);
} else {
log.error("连接目标服务器失败,address={},port={}", request.dstAddr(), request.dstPort());
DefaultSocks5CommandResponse commandResponse = new DefaultSocks5CommandResponse(Socks5CommandStatus.FAILURE, request.dstAddrType());

View File

@@ -4,6 +4,7 @@ import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.codec.socksx.v5.*;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelUtils;
@Slf4j
public class Socks5InitialRequestHandler extends SimpleChannelInboundHandler<Socks5InitialRequest> {
@@ -22,8 +23,8 @@ public class Socks5InitialRequestHandler extends SimpleChannelInboundHandler<Soc
Socks5InitialResponse socks5InitialResponse = new DefaultSocks5InitialResponse(Socks5AuthMethod.NO_AUTH);
ctx.writeAndFlush(socks5InitialResponse);
ctx.pipeline().remove(this);
ctx.pipeline().remove(Socks5InitialRequestDecoder.class);
ChannelUtils.safeRemoveHandler(ctx,this);
ChannelUtils.safeRemoveHandler(ctx,Socks5InitialRequestDecoder.class);
}
@Override

View File

@@ -4,6 +4,7 @@ import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.codec.socksx.v5.*;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelUtils;
@Slf4j
public class Socks5PasswordAuthRequestInboundHandler extends SimpleChannelInboundHandler<DefaultSocks5PasswordAuthRequest> {
@@ -16,8 +17,9 @@ public class Socks5PasswordAuthRequestInboundHandler extends SimpleChannelInboun
log.info("认证直接成功");
Socks5PasswordAuthResponse passwordAuthResponse = new DefaultSocks5PasswordAuthResponse(Socks5PasswordAuthStatus.SUCCESS);
ctx.writeAndFlush(passwordAuthResponse);
ctx.pipeline().remove(this);
ctx.pipeline().remove(Socks5PasswordAuthRequestDecoder.class);
ChannelUtils.safeRemoveHandler(ctx,this);
ChannelUtils.safeRemoveHandler(ctx,Socks5PasswordAuthRequestDecoder.class);
// 认证失败
// Socks5PasswordAuthResponse passwordAuthResponse = new DefaultSocks5PasswordAuthResponse(Socks5PasswordAuthStatus.FAILURE);

View File

@@ -1,11 +1,9 @@
package org.framework.lazy.cloud.network.heartbeat.protocol.socket5;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.*;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.nio.NioIoHandler;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.handler.codec.socksx.v5.Socks5CommandRequestDecoder;
@@ -26,10 +24,10 @@ public class Socks5ProxyServer {
}
public void run() throws Exception {
EventLoopGroup bossGroup = new NioEventLoopGroup();
EventLoopGroup workerGroup = new NioEventLoopGroup();
EventLoopGroup bossGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory());
EventLoopGroup workerGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory());
EventLoopGroup group = new NioEventLoopGroup();
EventLoopGroup group = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory());
try {
ServerBootstrap b = new ServerBootstrap();
b.group(bossGroup, workerGroup)

View File

@@ -3,6 +3,7 @@ package org.framework.lazy.cloud.network.heartbeat.protocol.test1;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.*;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.nio.NioIoHandler;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.handler.logging.LogLevel;
@@ -43,7 +44,7 @@ public class TrafficInterceptor {
*/
public void start() throws InterruptedException {
bossGroup = new NioEventLoopGroup(1);
workerGroup = new NioEventLoopGroup();
workerGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory());
try {
// 核心:启动服务端,绑定网卡 IP监听所有 TCP 端口(模拟全端口拦截)

View File

@@ -15,8 +15,8 @@ import org.springframework.stereotype.Component;
@Component
public class NettyTcpServerSocketApplicationListener implements SocketApplicationListener {
private final EventLoopGroup bossGroup = new NioEventLoopGroup();
private final EventLoopGroup workerGroup = new NioEventLoopGroup();
private final EventLoopGroup bossGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory());
private final EventLoopGroup workerGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory());
private final NettyTcpServerFilter nettyTcpServerFilter;// 通道业务处理
private final ServerNodeProperties serverNodeProperties;
private ChannelFuture channelFuture;

View File

@@ -18,7 +18,7 @@ import org.springframework.stereotype.Component;
//@Component
public class NettyUdpServerSocketApplicationListener implements SocketApplicationListener {
private final EventLoopGroup bossGroup = "linux".equalsIgnoreCase(SystemPropertyUtil.get("os.name")) ? new EpollEventLoopGroup() : new NioEventLoopGroup();
private final EventLoopGroup bossGroup = "linux".equalsIgnoreCase(SystemPropertyUtil.get("os.name")) ? new EpollEventLoopGroup() : new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory());
private final NettyUdpServerFilter nettyUdpServerFilter;// 通道业务处理
private final ServerNodeProperties serverNodeProperties;
private ChannelFuture channelFuture;

View File

@@ -14,8 +14,8 @@ import org.framework.lazy.cloud.network.heartbeat.server.netty.permeate.tcp.filt
*/
@Deprecated
public class NettyOnCloudNettyServerSocket {
private final EventLoopGroup bossGroup = new NioEventLoopGroup();
private final EventLoopGroup workerGroup = new NioEventLoopGroup();
private final EventLoopGroup bossGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory());
private final EventLoopGroup workerGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory());
private final NettyTcpServerFilter nettyTcpServerFilter;// 通道业务处理
private ChannelFuture channelFuture;

View File

@@ -18,7 +18,7 @@ import java.util.concurrent.TimeUnit;
*/
@Slf4j
public class NettyTcpClientPermeateServerConnectRealSocket {
private static final EventLoopGroup eventLoopGroup = new NioEventLoopGroup();
private static final EventLoopGroup eventLoopGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory());
/**

View File

@@ -17,7 +17,7 @@ import java.util.concurrent.TimeUnit;
*/
@Slf4j
public class NettyTcpServerPermeateServerConnectRealSocket {
private static final EventLoopGroup eventLoopGroup = new NioEventLoopGroup();
private static final EventLoopGroup eventLoopGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory());
/**
* 连接真实服务

View File

@@ -18,7 +18,7 @@ import java.util.concurrent.TimeUnit;
*/
@Slf4j
public class NettyUdpClientPermeateServerConnectRealSocket {
private static final EventLoopGroup eventLoopGroup = new NioEventLoopGroup();
private static final EventLoopGroup eventLoopGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory());
/**

View File

@@ -17,7 +17,7 @@ import java.util.concurrent.TimeUnit;
*/
@Slf4j
public class NettyUdpServerPermeateServerConnectRealSocket {
private static final EventLoopGroup eventLoopGroup = new NioEventLoopGroup();
private static final EventLoopGroup eventLoopGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory());
/**
* 连接真实服务

View File

@@ -18,7 +18,7 @@ import java.util.concurrent.TimeUnit;
*/
@Slf4j
public class NettyHttpClientProxyServerRealSocket {
private static final EventLoopGroup eventLoopGroup = new NioEventLoopGroup();
private static final EventLoopGroup eventLoopGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory());
/**

View File

@@ -15,6 +15,7 @@ import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyP
import org.framework.lazy.cloud.network.heartbeat.common.advanced.proxy.socks.server.AbstractHandleSocksReportServerProxyClientConnectionSuccessTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.decoder.TransferDecoder;
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelUtils;
import org.framework.lazy.cloud.network.heartbeat.protocol.handler.NettySocks5CommandRequestHandler;
import org.framework.lazy.cloud.network.heartbeat.server.netty.proxy.socks.filter.NettySocksServerProxyClientVisitorFilter;
import org.framework.lazy.cloud.network.heartbeat.server.netty.proxy.socks.handler.NettySocksClientProxyServerRealHandler;
@@ -74,8 +75,8 @@ public class ServerHandleSocksReportServerProxyClientConnectionSuccessTypeAdvanc
nextChannel.pipeline().addLast(new NettySocksServerProxyClientVisitorFilter());
nextChannel.pipeline().remove(NettySocks5CommandRequestHandler.class);
nextChannel.pipeline().remove(Socks5CommandRequestDecoder.class);
ChannelUtils.safeRemoveHandler(nextChannel,NettySocks5CommandRequestHandler.class);
ChannelUtils.safeRemoveHandler(nextChannel,Socks5CommandRequestDecoder.class);
}
}

View File

@@ -12,7 +12,7 @@
//public class NettyMulticastExample {
//
// public static void main(String[] args) throws Exception {
// EventLoopGroup group = new NioEventLoopGroup();
// EventLoopGroup group = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory());
// try {
// Bootstrap b = new Bootstrap();
// b.group(group)