【fix】修复流量计费bug

This commit is contained in:
wujiawei 2024-09-22 18:13:51 +08:00
parent 4f58a675d0
commit c04ba09763
21 changed files with 603 additions and 65 deletions

View File

@ -131,6 +131,10 @@ public class HeartbeatClientConfiguration {
public ClientHandleDistributeClientPermeateServerCloseTypeAdvanced clientHandleDistributeClientPermeateServerCloseTypeAdvanced( ) { public ClientHandleDistributeClientPermeateServerCloseTypeAdvanced clientHandleDistributeClientPermeateServerCloseTypeAdvanced( ) {
return new ClientHandleDistributeClientPermeateServerCloseTypeAdvanced(); return new ClientHandleDistributeClientPermeateServerCloseTypeAdvanced();
} }
@Bean
public ClientHandleDistributeClientPermeateServerTransferTypeAdvanced clientHandleDistributeClientPermeateServerTransferTypeAdvanced( ) {
return new ClientHandleDistributeClientPermeateServerTransferTypeAdvanced();
}
@Bean @Bean
public ClientHandleDistributeClientPermeateClientCloseTypeAdvanced clientHandleDistributeClientPermeateClientCloseTypeAdvanced() { public ClientHandleDistributeClientPermeateClientCloseTypeAdvanced clientHandleDistributeClientPermeateClientCloseTypeAdvanced() {

View File

@ -0,0 +1,53 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.advanced;
import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.client.AbstractHandleDistributeClientPermeateServerTransferTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
/**
* 服务端处理客户端数据传输
*
* @see MessageTypeEnums#DISTRIBUTE_CLIENT_TRANSFER
*/
@Slf4j
public class ClientHandleDistributeClientPermeateServerTransferTypeAdvanced extends AbstractHandleDistributeClientPermeateServerTransferTypeAdvanced<NettyProxyMsg> {
/**
* 处理当前数据
*
* @param channel 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
public void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
log.debug("接收到服务端需要内网穿透的数据:{}" , nettyProxyMsg);
byte[] visitorPort = nettyProxyMsg.getVisitorPort();
byte[] clientTargetIp = nettyProxyMsg.getClientTargetIp();
byte[] clientTargetPort = nettyProxyMsg.getClientTargetPort();
byte[] visitorId = nettyProxyMsg.getVisitorId();
// 真实服务通道
// Channel realChannel = NettyRealIdContext.getReal(new String(visitorId));
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
if (nextChannel == null) {
log.error("无法获取访客:{} 真实服务", new String(visitorId));
return;
}
// 把数据转到真实服务
ByteBuf buf = channel.config().getAllocator().buffer(nettyProxyMsg.getData().length);
buf.writeBytes(nettyProxyMsg.getData());
nextChannel.writeAndFlush(buf);
}
}

View File

@ -0,0 +1,42 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.filter;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import org.framework.lazy.cloud.network.heartbeat.client.netty.handler.NettyClientPermeateClientTransferHandler;
import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelTypeAdapter;
import org.framework.lazy.cloud.network.heartbeat.common.decoder.NettyProxyMsgDecoder;
import org.framework.lazy.cloud.network.heartbeat.common.encoder.NettyProxyMsgEncoder;
import org.framework.lazy.cloud.network.heartbeat.common.filter.DebugChannelInitializer;
/**
* netty 客户端渗透通信通道
*/
public class NettyClientPermeateClientTransferFilter extends DebugChannelInitializer<SocketChannel> {
private final ChannelTypeAdapter channelTypeAdapter;
public NettyClientPermeateClientTransferFilter(ChannelTypeAdapter channelTypeAdapter) {
this.channelTypeAdapter = channelTypeAdapter;
}
/**
* This method will be called once the {@link Channel} was registered. After the method returns this instance
* will be removed from the {@link ChannelPipeline} of the {@link Channel}.
*
* @param ch the {@link Channel} which was registered.
* @throws Exception is thrown if an error occurs. In that case it will be handled by
* {@link #exceptionCaught(ChannelHandlerContext, Throwable)} which will by default connectionClose
* the {@link Channel}.
*/
@Override
protected void initChannel0(SocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
// // 解码编码
// pipeline.addLast(new NettyProxyMsgDecoder(Integer.MAX_VALUE, 0, 4, -4, 0));
// pipeline.addLast(new NettMsgEncoder());
pipeline.addLast(new NettyProxyMsgDecoder(Integer.MAX_VALUE, 0, 4, -4, 0));
pipeline.addLast(new NettyProxyMsgEncoder());
pipeline.addLast(new NettyClientPermeateClientTransferHandler(channelTypeAdapter));
}
}

View File

@ -0,0 +1,42 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.filter;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import org.framework.lazy.cloud.network.heartbeat.client.netty.handler.NettyClientPermeateServerTransferHandler;
import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelTypeAdapter;
import org.framework.lazy.cloud.network.heartbeat.common.decoder.NettyProxyMsgDecoder;
import org.framework.lazy.cloud.network.heartbeat.common.encoder.NettyProxyMsgEncoder;
import org.framework.lazy.cloud.network.heartbeat.common.filter.DebugChannelInitializer;
/**
* netty 客户端渗透通信通道
*/
public class NettyClientPermeateServerTransferFilter extends DebugChannelInitializer<SocketChannel> {
private final ChannelTypeAdapter channelTypeAdapter;
public NettyClientPermeateServerTransferFilter(ChannelTypeAdapter channelTypeAdapter) {
this.channelTypeAdapter = channelTypeAdapter;
}
/**
* This method will be called once the {@link Channel} was registered. After the method returns this instance
* will be removed from the {@link ChannelPipeline} of the {@link Channel}.
*
* @param ch the {@link Channel} which was registered.
* @throws Exception is thrown if an error occurs. In that case it will be handled by
* {@link #exceptionCaught(ChannelHandlerContext, Throwable)} which will by default connectionClose
* the {@link Channel}.
*/
@Override
protected void initChannel0(SocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
// // 解码编码
// pipeline.addLast(new NettyProxyMsgDecoder(Integer.MAX_VALUE, 0, 4, -4, 0));
// pipeline.addLast(new NettMsgEncoder());
pipeline.addLast(new NettyProxyMsgDecoder(Integer.MAX_VALUE, 0, 4, -4, 0));
pipeline.addLast(new NettyProxyMsgEncoder());
pipeline.addLast(new NettyClientPermeateServerTransferHandler(channelTypeAdapter));
}
}

View File

@ -0,0 +1,79 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.handler;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelOption;
import io.netty.channel.SimpleChannelInboundHandler;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.ChannelContext;
import org.framework.lazy.cloud.network.heartbeat.common.MessageType;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.NettyRealIdContext;
import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelTypeAdapter;
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
import org.wu.framework.core.utils.ObjectUtils;
/**
* 客户端访客通信通道 处理器
*/
@Slf4j
public class NettyClientPermeateClientTransferHandler extends SimpleChannelInboundHandler<NettyProxyMsg> {
private final ChannelTypeAdapter channelTypeAdapter;
public NettyClientPermeateClientTransferHandler(ChannelTypeAdapter channelTypeAdapter) {
this.channelTypeAdapter = channelTypeAdapter;
}
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
super.channelActive(ctx);
}
@Override
public void channelRead0(ChannelHandlerContext ctx, NettyProxyMsg nettyProxyMsg) throws Exception {
Channel channel = ctx.channel();
channelTypeAdapter.handler(channel, nettyProxyMsg);
}
@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
String clientId = ChannelAttributeKeyUtils.getClientId(ctx.channel());
String visitorId = ChannelAttributeKeyUtils.getVisitorId(ctx.channel());
// 关闭访客
ChannelContext.ClientChannel clientChannel = ChannelContext.get(clientId);
if (clientChannel != null) {
Channel channel = clientChannel.getChannel();
// 上报关闭这个客户端的访客通道
NettyProxyMsg closeVisitorMsg = new NettyProxyMsg();
closeVisitorMsg.setType(MessageType.REPORT_SINGLE_CLIENT_CLOSE_VISITOR);
closeVisitorMsg.setVisitorId(visitorId);
channel.writeAndFlush(closeVisitorMsg);
}
super.channelInactive(ctx);
}
@Override
public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception {
// 处理客户端本地真实通道问题
String visitorId = ChannelAttributeKeyUtils.getVisitorId(ctx.channel());
if(ObjectUtils.isEmpty(visitorId)) {
super.channelWritabilityChanged(ctx);
return;
}
Channel realChannel = NettyRealIdContext.getReal(visitorId);
if (realChannel != null) {
log.debug("visitorId:{} transfer AUTO_READ:{} ",visitorId,ctx.channel().isWritable());
realChannel.config().setOption(ChannelOption.AUTO_READ, ctx.channel().isWritable());
}
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
super.exceptionCaught(ctx, cause);
}
}

View File

@ -0,0 +1,79 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.handler;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelOption;
import io.netty.channel.SimpleChannelInboundHandler;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.ChannelContext;
import org.framework.lazy.cloud.network.heartbeat.common.MessageType;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.NettyRealIdContext;
import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelTypeAdapter;
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
import org.wu.framework.core.utils.ObjectUtils;
/**
* 客户端访客通信通道 处理器
*/
@Slf4j
public class NettyClientPermeateServerTransferHandler extends SimpleChannelInboundHandler<NettyProxyMsg> {
private final ChannelTypeAdapter channelTypeAdapter;
public NettyClientPermeateServerTransferHandler(ChannelTypeAdapter channelTypeAdapter) {
this.channelTypeAdapter = channelTypeAdapter;
}
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
super.channelActive(ctx);
}
@Override
public void channelRead0(ChannelHandlerContext ctx, NettyProxyMsg nettyProxyMsg) throws Exception {
Channel channel = ctx.channel();
channelTypeAdapter.handler(channel, nettyProxyMsg);
}
@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
String clientId = ChannelAttributeKeyUtils.getClientId(ctx.channel());
String visitorId = ChannelAttributeKeyUtils.getVisitorId(ctx.channel());
// 关闭访客
ChannelContext.ClientChannel clientChannel = ChannelContext.get(clientId);
if (clientChannel != null) {
Channel channel = clientChannel.getChannel();
// 上报关闭服务端客户端真实通道
NettyProxyMsg closeVisitorMsg = new NettyProxyMsg();
closeVisitorMsg.setType(MessageType.REPORT_CLIENT_PERMEATE_SERVER_TRANSFER_CLOSE);
closeVisitorMsg.setVisitorId(visitorId);
channel.writeAndFlush(closeVisitorMsg);
}
super.channelInactive(ctx);
}
@Override
public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception {
// 处理客户端本地真实通道问题
String visitorId = ChannelAttributeKeyUtils.getVisitorId(ctx.channel());
if(ObjectUtils.isEmpty(visitorId)) {
super.channelWritabilityChanged(ctx);
return;
}
Channel realChannel = NettyRealIdContext.getReal(visitorId);
if (realChannel != null) {
log.debug("visitorId:{} transfer AUTO_READ:{} ",visitorId,ctx.channel().isWritable());
realChannel.config().setOption(ChannelOption.AUTO_READ, ctx.channel().isWritable());
}
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
super.exceptionCaught(ctx, cause);
}
}

View File

@ -76,7 +76,7 @@ public class NettyClientPermeateServerVisitorHandler extends SimpleChannelInboun
Integer visitorPort = internalNetworkPermeateServerVisitor.getVisitorPort(); Integer visitorPort = internalNetworkPermeateServerVisitor.getVisitorPort();
String clientId = internalNetworkPermeateServerVisitor.getNettyClientProperties().getClientId(); String clientId = internalNetworkPermeateServerVisitor.getNettyClientProperties().getClientId();
NettyProxyMsg nettyProxyMsg = new NettyProxyMsg(); NettyProxyMsg nettyProxyMsg = new NettyProxyMsg();
nettyProxyMsg.setType(MessageType.REPORT_CLIENT_TRANSFER); nettyProxyMsg.setType(MessageType.REPORT_CLIENT_PERMEATE_SERVER_TRANSFER);
nettyProxyMsg.setVisitorId(visitorId); nettyProxyMsg.setVisitorId(visitorId);
nettyProxyMsg.setClientId(clientId); nettyProxyMsg.setClientId(clientId);
nettyProxyMsg.setVisitorPort(visitorPort); nettyProxyMsg.setVisitorPort(visitorPort);
@ -112,7 +112,7 @@ public class NettyClientPermeateServerVisitorHandler extends SimpleChannelInboun
// 通知服务端 关闭访问通道真实通道 // 通知服务端 关闭访问通道真实通道
NettyProxyMsg myMsg = new NettyProxyMsg(); NettyProxyMsg myMsg = new NettyProxyMsg();
myMsg.setType(MessageType.DISTRIBUTE_SINGLE_CLIENT_REAL_CLOSE_VISITOR); myMsg.setType(MessageType.REPORT_CLIENT_PERMEATE_SERVER_TRANSFER_CLOSE);
myMsg.setVisitorId(visitorId); myMsg.setVisitorId(visitorId);
nextChannel.writeAndFlush(myMsg); nextChannel.writeAndFlush(myMsg);
} }
@ -126,28 +126,6 @@ public class NettyClientPermeateServerVisitorHandler extends SimpleChannelInboun
@Override @Override
public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception { public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception {
// 获取访客的传输通道
String visitorId = ChannelAttributeKeyUtils.getVisitorId(ctx.channel());
if(ObjectUtils.isEmpty(visitorId)) {
super.channelWritabilityChanged(ctx);
return;
}
Channel visitorCommunicationChannel = NettyCommunicationIdContext.getVisitor(visitorId);
if (visitorCommunicationChannel != null) {
log.debug("visitorId:{} transfer AUTO_READ:{} ",visitorId,ctx.channel().isWritable());
visitorCommunicationChannel.config().setOption(ChannelOption.AUTO_READ, ctx.channel().isWritable());
}
// Channel visitorChannel = ctx.channel();
// String vid = visitorChannel.attr(Constant.VID).get();
// if (StringUtil.isNullOrEmpty(vid)) {
// super.channelWritabilityChanged(ctx);
// return;
// }
// Channel clientChannel = Constant.vcc.get(vid);
// if (clientChannel != null) {
// clientChannel.config().setOption(ChannelOption.AUTO_READ, visitorChannel.isWritable());
// }
if (ctx.channel().isWritable()) { if (ctx.channel().isWritable()) {
log.debug("Channel is writable again"); log.debug("Channel is writable again");
// 恢复之前暂停的操作如写入数据 // 恢复之前暂停的操作如写入数据
@ -155,7 +133,7 @@ public class NettyClientPermeateServerVisitorHandler extends SimpleChannelInboun
log.debug("Channel is not writable"); log.debug("Channel is not writable");
// 暂停写入操作等待可写状态 // 暂停写入操作等待可写状态
} }
log.info("visitorId:{} channelWritabilityChanged!",visitorId); log.info("channelWritabilityChanged!");
} }
@Override @Override
@ -171,7 +149,7 @@ public class NettyClientPermeateServerVisitorHandler extends SimpleChannelInboun
if (nextChannel != null) { if (nextChannel != null) {
// 下发关闭访客 // 下发关闭访客
NettyProxyMsg closeRealClient = new NettyProxyMsg(); NettyProxyMsg closeRealClient = new NettyProxyMsg();
closeRealClient.setType(MessageType.DISTRIBUTE_SINGLE_CLIENT_REAL_CONNECT_AUTO_READ); closeRealClient.setType(MessageType.REPORT_CLIENT_PERMEATE_SERVER_TRANSFER_CLOSE);
closeRealClient.setClientId(clientId); closeRealClient.setClientId(clientId);
closeRealClient.setVisitorId(visitorId); closeRealClient.setVisitorId(visitorId);
nextChannel.writeAndFlush(closeRealClient); nextChannel.writeAndFlush(closeRealClient);

View File

@ -8,7 +8,7 @@ import io.netty.channel.socket.nio.NioSocketChannel;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties; import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
import org.framework.lazy.cloud.network.heartbeat.client.netty.InternalNetworkClientPermeateClientVisitor; import org.framework.lazy.cloud.network.heartbeat.client.netty.InternalNetworkClientPermeateClientVisitor;
import org.framework.lazy.cloud.network.heartbeat.client.netty.filter.NettyClientPermeateTransferFilter; import org.framework.lazy.cloud.network.heartbeat.client.netty.filter.NettyClientPermeateClientTransferFilter;
import org.framework.lazy.cloud.network.heartbeat.common.MessageType; import org.framework.lazy.cloud.network.heartbeat.common.MessageType;
import org.framework.lazy.cloud.network.heartbeat.common.NettyCommunicationIdContext; import org.framework.lazy.cloud.network.heartbeat.common.NettyCommunicationIdContext;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg; import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
@ -16,8 +16,6 @@ import org.framework.lazy.cloud.network.heartbeat.common.NettyRealIdContext;
import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelTypeAdapter; import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelTypeAdapter;
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils; import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
import java.util.concurrent.TimeUnit;
/** /**
* 客户端渗透服务端传输通道 * 客户端渗透服务端传输通道
*/ */
@ -54,8 +52,7 @@ public class NettyClientPermeateClientVisitorTransferSocket {
// .option(ChannelOption.RCVBUF_ALLOCATOR, new NettyRecvByteBufAllocator(1024 * 1024))//用于Channel分配接受Buffer的分配器 默认AdaptiveRecvByteBufAllocator.DEFAULT // .option(ChannelOption.RCVBUF_ALLOCATOR, new NettyRecvByteBufAllocator(1024 * 1024))//用于Channel分配接受Buffer的分配器 默认AdaptiveRecvByteBufAllocator.DEFAULT
.option(ChannelOption.WRITE_BUFFER_WATER_MARK, new WriteBufferWaterMark(1024 * 1024, 1024 * 1024 * 2)) .option(ChannelOption.WRITE_BUFFER_WATER_MARK, new WriteBufferWaterMark(1024 * 1024, 1024 * 1024 * 2))
.handler(new NettyClientPermeateClientTransferFilter(new ChannelTypeAdapter(internalNetworkClientPermeateClientVisitor.getHandleChannelTypeAdvancedList())))
.handler(new NettyClientPermeateTransferFilter(new ChannelTypeAdapter(internalNetworkClientPermeateClientVisitor.getHandleChannelTypeAdvancedList())))
; ;
NettyClientProperties nettyClientProperties = internalNetworkClientPermeateClientVisitor.getNettyClientProperties(); NettyClientProperties nettyClientProperties = internalNetworkClientPermeateClientVisitor.getNettyClientProperties();
String inetHost = nettyClientProperties.getInetHost(); String inetHost = nettyClientProperties.getInetHost();

View File

@ -8,7 +8,7 @@ import io.netty.channel.socket.nio.NioSocketChannel;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties; import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
import org.framework.lazy.cloud.network.heartbeat.client.netty.InternalNetworkPermeateServerVisitor; import org.framework.lazy.cloud.network.heartbeat.client.netty.InternalNetworkPermeateServerVisitor;
import org.framework.lazy.cloud.network.heartbeat.client.netty.filter.NettyClientPermeateTransferFilter; import org.framework.lazy.cloud.network.heartbeat.client.netty.filter.NettyClientPermeateServerTransferFilter;
import org.framework.lazy.cloud.network.heartbeat.common.MessageType; import org.framework.lazy.cloud.network.heartbeat.common.MessageType;
import org.framework.lazy.cloud.network.heartbeat.common.NettyCommunicationIdContext; import org.framework.lazy.cloud.network.heartbeat.common.NettyCommunicationIdContext;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg; import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
@ -16,8 +16,6 @@ import org.framework.lazy.cloud.network.heartbeat.common.NettyRealIdContext;
import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelTypeAdapter; import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelTypeAdapter;
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils; import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
import java.util.concurrent.TimeUnit;
/** /**
* 客户端渗透服务端传输通道 * 客户端渗透服务端传输通道
*/ */
@ -55,7 +53,7 @@ public class NettyClientPermeateServerVisitorTransferSocket {
.option(ChannelOption.WRITE_BUFFER_WATER_MARK, new WriteBufferWaterMark(1024 * 1024, 1024 * 1024 * 2)) .option(ChannelOption.WRITE_BUFFER_WATER_MARK, new WriteBufferWaterMark(1024 * 1024, 1024 * 1024 * 2))
.handler(new NettyClientPermeateTransferFilter(new ChannelTypeAdapter(internalNetworkPermeateServerVisitor.getHandleChannelTypeAdvancedList()))) .handler(new NettyClientPermeateServerTransferFilter(new ChannelTypeAdapter(internalNetworkPermeateServerVisitor.getHandleChannelTypeAdvancedList())))
; ;
NettyClientProperties nettyClientProperties = internalNetworkPermeateServerVisitor.getNettyClientProperties(); NettyClientProperties nettyClientProperties = internalNetworkPermeateServerVisitor.getNettyClientProperties();
String inetHost = nettyClientProperties.getInetHost(); String inetHost = nettyClientProperties.getInetHost();

View File

@ -95,6 +95,12 @@ public class MessageType {
*/ */
public static final byte REPORT_CLUSTER_NODE_REGISTER_MESSAGE = 0X11; public static final byte REPORT_CLUSTER_NODE_REGISTER_MESSAGE = 0X11;
/**
* 客户端渗透服务端类型------------------------------------------------------------------------------------
*
*/
/** /**
* 上报 客户端渗透服务端数据传输通道连接成功 * 上报 客户端渗透服务端数据传输通道连接成功
* *
@ -117,6 +123,30 @@ public class MessageType {
* @see AbstractHandleReportClientPermeateServerCloseTypeAdvanced * @see AbstractHandleReportClientPermeateServerCloseTypeAdvanced
*/ */
public static final byte REPORT_CLIENT_PERMEATE_SERVER_CLOSE = 0X14; public static final byte REPORT_CLIENT_PERMEATE_SERVER_CLOSE = 0X14;
/**
* 上报 客户端渗透服务端通信通道关闭
*
* @see MessageTypeEnums#REPORT_CLIENT_PERMEATE_SERVER_TRANSFER_CLOSE
* @see AbstractHandleReportClientPermeateServerTransferCloseTypeAdvanced
*/
public static final byte REPORT_CLIENT_PERMEATE_SERVER_TRANSFER_CLOSE = 0X15;
/**
* 上报 客户端渗透服务端通信传输
*
* @see MessageTypeEnums#REPORT_CLIENT_PERMEATE_SERVER_TRANSFER
* @see AbstractHandleReportClientPermeateServerTransferTypeAdvanced
*/
public static final byte REPORT_CLIENT_PERMEATE_SERVER_TRANSFER = 0X16;
/**
* 客户端渗透客户端类型------------------------------------------------------------------------------------
* 60~90
*/
/** /**
* 上报 客户端渗透客户端init信息 * 上报 客户端渗透客户端init信息
@ -124,14 +154,14 @@ public class MessageType {
* @see MessageTypeEnums#REPORT_CLIENT_PERMEATE_CLIENT_INIT * @see MessageTypeEnums#REPORT_CLIENT_PERMEATE_CLIENT_INIT
* @see AbstractHandleReportClientPermeateClientInitTypeAdvanced * @see AbstractHandleReportClientPermeateClientInitTypeAdvanced
*/ */
public static final byte REPORT_CLIENT_PERMEATE_CLIENT_INIT = 0X15; public static final byte REPORT_CLIENT_PERMEATE_CLIENT_INIT = 0X19;
/** /**
* 上报 客户端渗透客户端init close 信息 * 上报 客户端渗透客户端init close 信息
* *
* @see MessageTypeEnums#REPORT_CLIENT_PERMEATE_CLIENT_CLOSE * @see MessageTypeEnums#REPORT_CLIENT_PERMEATE_CLIENT_CLOSE
* @see AbstractHandleReportClientPermeateClientCloseTypeAdvanced * @see AbstractHandleReportClientPermeateClientCloseTypeAdvanced
*/ */
public static final byte REPORT_CLIENT_PERMEATE_CLIENT_CLOSE = 0X16; public static final byte REPORT_CLIENT_PERMEATE_CLIENT_CLOSE = 0X20;
/** /**
* 上报 客户端渗透客户端数据传输通道连接成功 * 上报 客户端渗透客户端数据传输通道连接成功
* *
@ -139,7 +169,7 @@ public class MessageType {
* @see AbstractHandleReportClientTransferClientPermeateChannelConnectionSuccessfulTypeAdvanced * @see AbstractHandleReportClientTransferClientPermeateChannelConnectionSuccessfulTypeAdvanced
* @see MessageType#DISTRIBUTE_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL * @see MessageType#DISTRIBUTE_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL
*/ */
public static final byte REPORT_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL = 0X17; public static final byte REPORT_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL = 0X21;
/** /**
@ -149,7 +179,7 @@ public class MessageType {
* @see AbstractHandleReportClientTransferClientPermeateChannelInitSuccessfulTypeAdvanced * @see AbstractHandleReportClientTransferClientPermeateChannelInitSuccessfulTypeAdvanced
* @see MessageType#DISTRIBUTE_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_INIT_SUCCESSFUL * @see MessageType#DISTRIBUTE_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_INIT_SUCCESSFUL
*/ */
public static final byte REPORT_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_INIT_SUCCESSFUL = 0X18; public static final byte REPORT_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_INIT_SUCCESSFUL = 0X22;
/** /**
* 上报客户端渗透客户端数据传输请求 * 上报客户端渗透客户端数据传输请求
* *
@ -157,7 +187,7 @@ public class MessageType {
* @see AbstractHandleReportClientTransferClientTypeAdvanced * @see AbstractHandleReportClientTransferClientTypeAdvanced
* @see MessageType#DISTRIBUTE_CLIENT_TRANSFER_CLIENT_REQUEST * @see MessageType#DISTRIBUTE_CLIENT_TRANSFER_CLIENT_REQUEST
*/ */
public static final byte REPORT_CLIENT_TRANSFER_CLIENT_REQUEST = 0X19; public static final byte REPORT_CLIENT_TRANSFER_CLIENT_REQUEST = 0X23;
/** /**
* 上报客户端渗透客户端数据传输结果 * 上报客户端渗透客户端数据传输结果
@ -166,7 +196,7 @@ public class MessageType {
* @see AbstractHandleReportClientTransferClientResponseTypeAdvanced * @see AbstractHandleReportClientTransferClientResponseTypeAdvanced
* @see MessageType#DISTRIBUTE_CLIENT_TRANSFER_CLIENT_RESPONSE * @see MessageType#DISTRIBUTE_CLIENT_TRANSFER_CLIENT_RESPONSE
*/ */
public static final byte REPORT_CLIENT_TRANSFER_CLIENT_RESPONSE = 0X20; public static final byte REPORT_CLIENT_TRANSFER_CLIENT_RESPONSE = 0X24;
/** /**
* 下发 客户端接收连接成功通知 * 下发 客户端接收连接成功通知
@ -277,13 +307,29 @@ public class MessageType {
*/ */
public static final byte DISTRIBUTE_CLIENT_PERMEATE_SERVER_CLOSE = -0X14; public static final byte DISTRIBUTE_CLIENT_PERMEATE_SERVER_CLOSE = -0X14;
/**
* 下发 客户端渗透服务端通信通道关闭
*
* @see MessageTypeEnums#DISTRIBUTE_CLIENT_PERMEATE_SERVER_TRANSFER_CLOSE
* @see AbstractHandleDistributeClientPermeateServerTransferCloseTypeAdvanced
*/
public static final byte DISTRIBUTE_CLIENT_PERMEATE_SERVER_TRANSFER_CLOSE = -0X15;
/**
* 下发 客户端渗透服务端通信传输
*
* @see MessageTypeEnums#DISTRIBUTE_CLIENT_PERMEATE_SERVER_TRANSFER
* @see AbstractHandleDistributeClientPermeateServerTransferTypeAdvanced
*/
public static final byte DISTRIBUTE_CLIENT_PERMEATE_SERVER_TRANSFER = -0X16;
/** /**
* 下发 客户端渗透客户端init信息 * 下发 客户端渗透客户端init信息
* *
* @see MessageTypeEnums#DISTRIBUTE_CLIENT_PERMEATE_CLIENT_INIT * @see MessageTypeEnums#DISTRIBUTE_CLIENT_PERMEATE_CLIENT_INIT
* @see AbstractHandleDistributeClientPermeateClientInitTypeAdvanced * @see AbstractHandleDistributeClientPermeateClientInitTypeAdvanced
*/ */
public static final byte DISTRIBUTE_CLIENT_PERMEATE_CLIENT_INIT = -0X15; public static final byte DISTRIBUTE_CLIENT_PERMEATE_CLIENT_INIT = -0X19;
/** /**
* 下发 客户端渗透客户端init close信息 * 下发 客户端渗透客户端init close信息
@ -291,7 +337,7 @@ public class MessageType {
* @see MessageTypeEnums#DISTRIBUTE_CLIENT_PERMEATE_CLIENT_CLOSE * @see MessageTypeEnums#DISTRIBUTE_CLIENT_PERMEATE_CLIENT_CLOSE
* @see AbstractHandleDistributeClientPermeateClientCloseTypeAdvanced * @see AbstractHandleDistributeClientPermeateClientCloseTypeAdvanced
*/ */
public static final byte DISTRIBUTE_CLIENT_PERMEATE_CLIENT_CLOSE = -0X16; public static final byte DISTRIBUTE_CLIENT_PERMEATE_CLIENT_CLOSE = -0X20;
@ -302,7 +348,7 @@ public class MessageType {
* @see AbstractHandleDistributeClientTransferClientPermeateChannelConnectionSuccessfulTypeAdvanced * @see AbstractHandleDistributeClientTransferClientPermeateChannelConnectionSuccessfulTypeAdvanced
* @see MessageType#REPORT_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL * @see MessageType#REPORT_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL
*/ */
public static final byte DISTRIBUTE_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL = -0X17; public static final byte DISTRIBUTE_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL = -0X21;
/** /**
@ -312,7 +358,7 @@ public class MessageType {
* @see AbstractHandleDistributeClientTransferClientPermeateChannelInitSuccessfulTypeAdvanced * @see AbstractHandleDistributeClientTransferClientPermeateChannelInitSuccessfulTypeAdvanced
* @see MessageType#DISTRIBUTE_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_INIT_SUCCESSFUL * @see MessageType#DISTRIBUTE_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_INIT_SUCCESSFUL
*/ */
public static final byte DISTRIBUTE_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_INIT_SUCCESSFUL = -0X18; public static final byte DISTRIBUTE_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_INIT_SUCCESSFUL = -0X22;
/** /**
* 下发 客户端渗透客户端数据传输请求 * 下发 客户端渗透客户端数据传输请求
@ -321,7 +367,7 @@ public class MessageType {
* @see AbstractHandleDistributeClientTransferClientRequestTypeAdvanced * @see AbstractHandleDistributeClientTransferClientRequestTypeAdvanced
* @see MessageType#REPORT_CLIENT_TRANSFER_CLIENT_REQUEST * @see MessageType#REPORT_CLIENT_TRANSFER_CLIENT_REQUEST
*/ */
public static final byte DISTRIBUTE_CLIENT_TRANSFER_CLIENT_REQUEST = -0X19; public static final byte DISTRIBUTE_CLIENT_TRANSFER_CLIENT_REQUEST = -0X23;
/** /**
* 下发客户端渗透客户端数据传输响应 * 下发客户端渗透客户端数据传输响应
* *
@ -329,5 +375,5 @@ public class MessageType {
* @see AbstractHandleDistributeClientTransferClientResponseTypeAdvanced * @see AbstractHandleDistributeClientTransferClientResponseTypeAdvanced
* @see MessageType#REPORT_CLIENT_TRANSFER_CLIENT_RESPONSE * @see MessageType#REPORT_CLIENT_TRANSFER_CLIENT_RESPONSE
*/ */
public static final byte DISTRIBUTE_CLIENT_TRANSFER_CLIENT_RESPONSE = -0X20; public static final byte DISTRIBUTE_CLIENT_TRANSFER_CLIENT_RESPONSE = -0X24;
} }

View File

@ -0,0 +1,28 @@
package org.framework.lazy.cloud.network.heartbeat.common.advanced.client;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.AbstractHandleChannelTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
/**
* 下发 客户端渗透服务端通信通道关闭
*
* @see MessageTypeEnums#DISTRIBUTE_CLIENT_PERMEATE_SERVER_TRANSFER_CLOSE
*/
public abstract class AbstractHandleDistributeClientPermeateServerTransferCloseTypeAdvanced<MSG> extends AbstractHandleChannelTypeAdvanced<NettyProxyMsg> implements HandleChannelTypeAdvanced {
/**
* 是否支持当前类型
*
* @param msg 通道数据
* @return 布尔类型
*/
@Override
public boolean doSupport(NettyProxyMsg msg) {
return MessageTypeEnums.DISTRIBUTE_CLIENT_PERMEATE_SERVER_TRANSFER_CLOSE.getTypeByte() == msg.getType();
}
}

View File

@ -0,0 +1,28 @@
package org.framework.lazy.cloud.network.heartbeat.common.advanced.client;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.AbstractHandleChannelTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
/**
* 下发 客户端渗透服务端通信传输
*
* @see MessageTypeEnums#DISTRIBUTE_CLIENT_PERMEATE_SERVER_TRANSFER
*/
public abstract class AbstractHandleDistributeClientPermeateServerTransferTypeAdvanced<MSG> extends AbstractHandleChannelTypeAdvanced<NettyProxyMsg> implements HandleChannelTypeAdvanced {
/**
* 是否支持当前类型
*
* @param msg 通道数据
* @return 布尔类型
*/
@Override
public boolean doSupport(NettyProxyMsg msg) {
return MessageTypeEnums.DISTRIBUTE_CLIENT_PERMEATE_SERVER_TRANSFER.getTypeByte() == msg.getType();
}
}

View File

@ -0,0 +1,27 @@
package org.framework.lazy.cloud.network.heartbeat.common.advanced.server;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.AbstractHandleChannelTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
/**
* 上报 客户端渗透服务端通信通道关闭
* REPORT_CLIENT_PERMEATE_SERVER_TRANSFER_CLOSE
*/
public abstract class AbstractHandleReportClientPermeateServerTransferCloseTypeAdvanced<MSG> extends AbstractHandleChannelTypeAdvanced<NettyProxyMsg> implements HandleChannelTypeAdvanced {
/**
* 是否支持当前类型
*
* @param msg 通道数据
* @return 布尔类型
*/
@Override
public boolean doSupport(NettyProxyMsg msg) {
return MessageTypeEnums.REPORT_CLIENT_PERMEATE_SERVER_TRANSFER_CLOSE.getTypeByte() == msg.getType();
}
}

View File

@ -0,0 +1,27 @@
package org.framework.lazy.cloud.network.heartbeat.common.advanced.server;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.AbstractHandleChannelTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
/**
* 上报 客户端渗透服务端通信
* REPORT_CLIENT_PERMEATE_SERVER_TRANSFER
*/
public abstract class AbstractHandleReportClientPermeateServerTransferTypeAdvanced<MSG> extends AbstractHandleChannelTypeAdvanced<NettyProxyMsg> implements HandleChannelTypeAdvanced {
/**
* 是否支持当前类型
*
* @param msg 通道数据
* @return 布尔类型
*/
@Override
public boolean doSupport(NettyProxyMsg msg) {
return MessageTypeEnums.REPORT_CLIENT_PERMEATE_SERVER_TRANSFER.getTypeByte() == msg.getType();
}
}

View File

@ -71,7 +71,21 @@ public enum MessageTypeEnums {
* @see AbstractHandleReportClientPermeateServerCloseTypeAdvanced * @see AbstractHandleReportClientPermeateServerCloseTypeAdvanced
*/ */
REPORT_CLIENT_PERMEATE_SERVER_CLOSE(MessageType.REPORT_CLIENT_PERMEATE_SERVER_CLOSE, "上报 客户端渗透服务端init close 信息"), REPORT_CLIENT_PERMEATE_SERVER_CLOSE(MessageType.REPORT_CLIENT_PERMEATE_SERVER_CLOSE, "上报 客户端渗透服务端init close 信息"),
/**
/**
* 上报 客户端渗透服务端通信通道关闭
* @see AbstractHandleReportClientPermeateServerTransferCloseTypeAdvanced
*/
REPORT_CLIENT_PERMEATE_SERVER_TRANSFER_CLOSE(MessageType.REPORT_CLIENT_PERMEATE_SERVER_TRANSFER_CLOSE, "上报 客户端渗透服务端通信通道关闭"),
/**
* 上报 客户端渗透服务端通信传输
* @see AbstractHandleReportClientPermeateServerTransferTypeAdvanced
*/
REPORT_CLIENT_PERMEATE_SERVER_TRANSFER(MessageType.REPORT_CLIENT_PERMEATE_SERVER_TRANSFER, "上报 客户端渗透服务端通信传输"),
/**
* @see AbstractHandleReportClientPermeateClientInitTypeAdvanced * @see AbstractHandleReportClientPermeateClientInitTypeAdvanced
*/ */
REPORT_CLIENT_PERMEATE_CLIENT_INIT(MessageType.REPORT_CLIENT_PERMEATE_CLIENT_INIT, "上报 客户端渗透客户端init信息"), REPORT_CLIENT_PERMEATE_CLIENT_INIT(MessageType.REPORT_CLIENT_PERMEATE_CLIENT_INIT, "上报 客户端渗透客户端init信息"),
@ -161,11 +175,21 @@ public enum MessageTypeEnums {
* @see AbstractHandleDistributeClientPermeateServerCloseTypeAdvanced * @see AbstractHandleDistributeClientPermeateServerCloseTypeAdvanced
*/ */
DISTRIBUTE_CLIENT_PERMEATE_SERVER_CLOSE(MessageType.DISTRIBUTE_CLIENT_PERMEATE_SERVER_CLOSE, "下发 客户端渗透服务端init close信息"), DISTRIBUTE_CLIENT_PERMEATE_SERVER_CLOSE(MessageType.DISTRIBUTE_CLIENT_PERMEATE_SERVER_CLOSE, "下发 客户端渗透服务端init close信息"),
/** /**
* @see AbstractHandleDistributeClientPermeateServerTransferCloseTypeAdvanced
*/
DISTRIBUTE_CLIENT_PERMEATE_SERVER_TRANSFER_CLOSE(MessageType.DISTRIBUTE_CLIENT_PERMEATE_SERVER_TRANSFER_CLOSE, "下发 客户端渗透服务端通信通道关闭"),
/**
* @see AbstractHandleDistributeClientPermeateServerTransferTypeAdvanced
*/
DISTRIBUTE_CLIENT_PERMEATE_SERVER_TRANSFER(MessageType.DISTRIBUTE_CLIENT_PERMEATE_SERVER_TRANSFER, "下发 客户端渗透服务端通信传输"),
/**
* @see AbstractHandleDistributeClientPermeateClientInitTypeAdvanced * @see AbstractHandleDistributeClientPermeateClientInitTypeAdvanced
*/ */
DISTRIBUTE_CLIENT_PERMEATE_CLIENT_INIT(MessageType.DISTRIBUTE_CLIENT_PERMEATE_CLIENT_INIT, "下发 客户端渗透客户端init信息"), DISTRIBUTE_CLIENT_PERMEATE_CLIENT_INIT(MessageType.DISTRIBUTE_CLIENT_PERMEATE_CLIENT_INIT, "下发 客户端渗透客户端init信息"),
/** /**
* @see AbstractHandleDistributeClientPermeateClientCloseTypeAdvanced * @see AbstractHandleDistributeClientPermeateClientCloseTypeAdvanced
*/ */

View File

@ -0,0 +1,33 @@
package org.framework.lazy.cloud.network.heartbeat.server.netty.advanced;
import io.netty.channel.Channel;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.ChannelContext;
import org.framework.lazy.cloud.network.heartbeat.common.MessageType;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.NettyTransferChannelContext;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.server.AbstractHandleReportClientPermeateServerTransferCloseTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.server.AbstractHandleReportClientTransferClientPermeateChannelConnectionSuccessfulTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
import org.springframework.stereotype.Component;
/**
* 上报 客户端渗透服务端通信通道关闭
*/
@Slf4j
@Component
public class ServerHandleReportClientPermeateServerTransferCloseTypeAdvanced extends AbstractHandleReportClientPermeateServerTransferCloseTypeAdvanced<NettyProxyMsg> {
/**
* 处理当前数据
*
* @param channel 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
protected void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
// 关闭传输通信通道
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
nextChannel.close();
channel.close();
}
}

View File

@ -0,0 +1,63 @@
package org.framework.lazy.cloud.network.heartbeat.server.netty.advanced;
import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.NettyRealIdContext;
import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelFlowAdapter;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.server.AbstractHandleReportClientPermeateServerTransferTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.enums.ChannelFlowEnum;
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
import org.framework.lazy.cloud.network.heartbeat.server.netty.flow.ServerChannelFlow;
import org.springframework.stereotype.Component;
/**
* 上报 客户端渗透服务端通信
* REPORT_CLIENT_PERMEATE_SERVER_TRANSFER
*/
@Slf4j
@Component
public class ServerHandleReportClientPermeateServerTransferTypeAdvanced extends AbstractHandleReportClientPermeateServerTransferTypeAdvanced<NettyProxyMsg> {
private final ChannelFlowAdapter channelFlowAdapter;
public ServerHandleReportClientPermeateServerTransferTypeAdvanced(ChannelFlowAdapter channelFlowAdapter) {
this.channelFlowAdapter = channelFlowAdapter;
}
/**
* 处理当前数据
*
* @param channel 当前通道
* @param msg 通道数据
*/
@Override
protected void doHandler(Channel channel, NettyProxyMsg msg) {
String clientId = new String(msg.getClientId());
Integer visitorPort = Integer.valueOf(new String(msg.getVisitorPort()));
byte[] visitorId = msg.getVisitorId();
// log.info("访客ID:【{}】 访客端口:[{}] 接收到客户端:[{}]", new String(visitorId), visitorPort, clientId);
// log.debug("访客ID:【{}】接收到客户端:[{}] 返回数据大小:[{}] 内网穿透返回的数据:[{}]", new String(visitorId), clientId, msg.getData().length, new String(msg.getData()));
// 将数据转发访客通道
Channel visitor = NettyRealIdContext.getReal(visitorId);
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
if (nextChannel != null) {
ByteBuf buf = nextChannel.config().getAllocator().buffer(msg.getData().length);
buf.writeBytes(msg.getData());
ChannelFuture channelFuture = nextChannel.writeAndFlush(buf);
boolean success = channelFuture.isSuccess();
log.debug("visitor writerAndFlush status: {}", success);
// 记录出口数据
ServerChannelFlow serverChannelFlow = ServerChannelFlow
.builder()
.channelFlowEnum(ChannelFlowEnum.OUT_FLOW)
.port(visitorPort)
.clientId(clientId)
.flow(msg.getData().length)
.build();
channelFlowAdapter.asyncHandler(channel, serverChannelFlow);
}
log.debug("访客ID:【{}】接收到客户端:[{}] 发送真实数据成功", new String(visitorId), clientId);
}
}

View File

@ -19,7 +19,7 @@ import java.nio.charset.StandardCharsets;
/** /**
* 服务端处理客户端数据传输 * 服务端处理客户端数据传输
* REPORT_CLIENT_STAGING_CLOSED * REPORT_CLIENT_TRANSFER
*/ */
@Slf4j @Slf4j
@Component @Component

View File

@ -5,8 +5,7 @@ import io.netty.channel.socket.SocketChannel;
import org.framework.lazy.cloud.network.heartbeat.common.decoder.TransferDecoder; 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.encoder.TransferEncoder;
import org.framework.lazy.cloud.network.heartbeat.common.filter.DebugChannelInitializer; import org.framework.lazy.cloud.network.heartbeat.common.filter.DebugChannelInitializer;
import org.framework.lazy.cloud.network.heartbeat.server.netty.handler.ClientPermeateServerRealHandler; import org.framework.lazy.cloud.network.heartbeat.server.netty.handler.NettyClientPermeateServerRealHandler;
import org.framework.lazy.cloud.network.heartbeat.server.netty.handler.PermeateClientRealHandler;
/** /**
* 客户端渗透服务端 * 客户端渗透服务端
@ -24,7 +23,7 @@ public class ClientPermeateServerRealFilter extends DebugChannelInitializer<Sock
// 解码编码 // 解码编码
pipeline.addLast(new TransferDecoder(Integer.MAX_VALUE, 1024 * 1024*10)); pipeline.addLast(new TransferDecoder(Integer.MAX_VALUE, 1024 * 1024*10));
pipeline.addLast(new TransferEncoder()); pipeline.addLast(new TransferEncoder());
pipeline.addLast(new ClientPermeateServerRealHandler()); pipeline.addLast(new NettyClientPermeateServerRealHandler());
} }
} }

View File

@ -1,8 +1,6 @@
package org.framework.lazy.cloud.network.heartbeat.server.netty.handler; package org.framework.lazy.cloud.network.heartbeat.server.netty.handler;
import com.alibaba.fastjson.JSON;
import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelOption; import io.netty.channel.ChannelOption;
@ -17,7 +15,7 @@ import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeK
* 客户端渗透服务端 * 客户端渗透服务端
*/ */
@Slf4j @Slf4j
public class ClientPermeateServerRealHandler extends SimpleChannelInboundHandler<NettyByteBuf> { public class NettyClientPermeateServerRealHandler extends SimpleChannelInboundHandler<NettyByteBuf> {
@Override @Override
public void channelActive(ChannelHandlerContext ctx) throws Exception { public void channelActive(ChannelHandlerContext ctx) throws Exception {
@ -42,7 +40,7 @@ public class ClientPermeateServerRealHandler extends SimpleChannelInboundHandler
// 消息下发到客户端 // 消息下发到客户端
NettyProxyMsg nettyMsg = new NettyProxyMsg(); NettyProxyMsg nettyMsg = new NettyProxyMsg();
nettyMsg.setType(MessageType.DISTRIBUTE_CLIENT_TRANSFER); nettyMsg.setType(MessageType.DISTRIBUTE_CLIENT_PERMEATE_SERVER_TRANSFER);
nettyMsg.setData(bytes); nettyMsg.setData(bytes);
nextChannel.writeAndFlush(nettyMsg); nextChannel.writeAndFlush(nettyMsg);
@ -66,13 +64,6 @@ public class ClientPermeateServerRealHandler extends SimpleChannelInboundHandler
public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception { public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception {
// 获取访客的传输通道
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(ctx.channel());
if (nextChannel != null) {
log.debug("transfer AUTO_READ:{} ",ctx.channel().isWritable());
nextChannel.config().setOption(ChannelOption.AUTO_READ, ctx.channel().isWritable());
}
} }
@Override @Override

View File

@ -27,7 +27,7 @@ public class LazyVisitorPortFlowDO {
* 客户端ID * 客户端ID
*/ */
@Schema(description = "客户端ID", name = "clientId", example = "") @Schema(description = "客户端ID", name = "clientId", example = "")
@LazyTableFieldUnique(name = "client_id", comment = "客户端ID", columnType = "varchar(50)") @LazyTableFieldUnique(name = "client_id", comment = "客户端ID", columnType = "varchar(50)",notNull = true)
private String clientId; private String clientId;
/** /**