mirror of
https://gitee.com/wujiawei1207537021/wu-lazy-cloud-network.git
synced 2026-02-04 15:05:54 +08:00
[update] 显式指定注解处理器,4.x
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
// 认证失败
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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 代理服务器
|
||||
|
||||
@@ -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>() {
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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 端口(模拟全端口拦截)
|
||||
|
||||
Reference in New Issue
Block a user