【fix】

This commit is contained in:
wujiawei
2025-04-30 15:19:56 +08:00
parent 98587b442c
commit f2a22c177e
144 changed files with 958 additions and 669 deletions

View File

@ -1,7 +1,7 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.advanced;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import org.framework.lazy.cloud.network.heartbeat.common.constant.TcpMessageType;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.tcp.AbstractTcpHandleChannelHeartbeatTypeAdvanced;
@ -16,14 +16,14 @@ public class ClientHandleTcpChannelHeartbeatTypeAdvanced extends AbstractTcpHand
/**
* 处理当前数据
*
* @param channel 当前通道
* @param channelHandlerContext 当前通道
* @param msg 通道数据
*/
@Override
public void doHandler(Channel channel, NettyProxyMsg msg) {
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg msg) {
NettyProxyMsg hb = new NettyProxyMsg();
hb.setType(TcpMessageType.TCP_TYPE_HEARTBEAT);
// channel.writeAndFlush(hb);
// channelHandlerContext.writeAndFlush(hb);
}
}

View File

@ -3,6 +3,7 @@ package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.adv
import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
@ -28,11 +29,12 @@ public class ClientHandleTcpChannelTransferTypeAdvancedHandleDistributeTcpDistri
/**
* 处理当前数据
*
* @param channel 当前通道
* @param channelHandlerContext 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
public void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
Channel channel = channelHandlerContext.channel();
log.debug("接收到服务端需要内网穿透的数据:{}" , nettyProxyMsg);
String clientId = nettyClientProperties.getClientId();
byte[] visitorPort = nettyProxyMsg.getVisitorPort();

View File

@ -1,6 +1,7 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.advanced;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
import org.framework.lazy.cloud.network.heartbeat.common.ChannelContext;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
@ -20,11 +21,12 @@ public class ClientHandleTcpClientChannelActiveAdvanced extends AbstractHandleTc
/**
* 处理当前数据
*
* @param channel 当前通道
* @param channelHandlerContext 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
protected void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
Channel channel = channelHandlerContext.channel();
// 缓存当前通道
byte[] clientIdByte = nettyProxyMsg.getClientId();
String clientId = new String(clientIdByte);

View File

@ -1,7 +1,7 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.advanced;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.NettyVisitorPortContext;
@ -22,11 +22,11 @@ public class ClientHandleTcpDistributeClientPermeateClientCloseTypeAdvanced exte
/**
* 处理当前数据
*
* @param channel 当前通道
* @param channelHandlerContext 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
public void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
// 初始化 客户端渗透服务端socket
byte[] msgVisitorPort = nettyProxyMsg.getVisitorPort();
Integer visitorPort = Integer.parseInt(new String(msgVisitorPort));

View File

@ -1,7 +1,7 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.advanced;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
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.tcp.socket.NettyTcpClientPermeateClientVisitorSocket;
@ -26,11 +26,11 @@ public class ClientHandleTcpDistributeClientPermeateClientInitTypeAdvanced exten
/**
* 处理当前数据
*
* @param channel 当前通道
* @param channelHandlerContext 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
public void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
// 初始化 客户端渗透服务端socket
byte[] fromClientIdBytes = nettyProxyMsg.getClientId();
byte[] visitorPortBytes = nettyProxyMsg.getVisitorPort();

View File

@ -2,6 +2,7 @@ package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.adv
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.tcp.client.AbstractHandleTcpDistributeClientPermeateClientTransferCloseTypeAdvanced;
@ -20,11 +21,12 @@ public class ClientHandleTcpDistributeClientPermeateClientTransferCloseTypeAdvan
/**
* 处理当前数据
*
* @param channel 当前通道
* @param channelHandlerContext 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
public void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
Channel channel = channelHandlerContext.channel();
// 关闭客户端真实通道、访客通道
Channel realChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
realChannel.close();// 真实通道关闭

View File

@ -1,7 +1,7 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.advanced;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.NettyVisitorPortContext;
@ -22,11 +22,11 @@ public class ClientHandleTcpDistributeClientPermeateServerCloseTypeAdvanced exte
/**
* 处理当前数据
*
* @param channel 当前通道
* @param channelHandlerContext 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
public void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
// 初始化 客户端渗透服务端socket
byte[] msgVisitorPort = nettyProxyMsg.getVisitorPort();
Integer visitorPort = Integer.parseInt(new String(msgVisitorPort));

View File

@ -1,7 +1,7 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.advanced;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
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.tcp.socket.NettyTcpClientPermeateServerVisitorSocket;
@ -32,11 +32,11 @@ public class ClientHandleTcpDistributeClientPermeateServerInitTypeAdvanced exten
/**
* 处理当前数据
*
* @param channel 当前通道
* @param channelHandlerContext 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
public void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
// 初始化 客户端渗透服务端socket
byte[] clientIdBytes = nettyProxyMsg.getClientId();
byte[] visitorPort = nettyProxyMsg.getVisitorPort();

View File

@ -2,6 +2,7 @@ package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.adv
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.tcp.client.AbstractHandleTcpDistributeClientPermeateServerTransferCloseTypeAdvanced;
@ -20,11 +21,12 @@ public class ClientHandleTcpDistributeClientPermeateServerTransferCloseTypeAdvan
/**
* 处理当前数据
*
* @param channel 当前通道
* @param channelHandlerContext 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
public void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
Channel channel = channelHandlerContext.channel();
// 关闭本地通信通道
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
channel.close();

View File

@ -3,6 +3,7 @@ package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.adv
import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.tcp.client.AbstractHandleTcpDistributeClientPermeateServerTransferTypeAdvanced;
@ -22,11 +23,12 @@ public class ClientHandleTcpDistributeClientPermeateServerTransferTypeAdvanced e
/**
* 处理当前数据
*
* @param channel 当前通道
* @param channelHandlerContext 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
public void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
Channel channel = channelHandlerContext.channel();
log.debug("客户端渗透服务端返回数据:{}" , new String(nettyProxyMsg.getData()));
byte[] visitorPort = nettyProxyMsg.getVisitorPort();
byte[] clientTargetIp = nettyProxyMsg.getClientTargetIp();

View File

@ -1,7 +1,7 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.advanced;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
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.tcp.socket.NettyTcpClientPermeateClientRealSocket;
@ -27,11 +27,11 @@ public class ClientHandleTcpDistributeClientTransferClientPermeateChannelConnect
/**
* 处理当前数据
*
* @param channel 当前通道
* @param channelHandlerContext 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
public void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
// 创建connect 然后发送创建成功
byte[] msgClientId = nettyProxyMsg.getClientId();
byte[] msgClientTargetIp = nettyProxyMsg.getClientTargetIp();

View File

@ -2,6 +2,7 @@ package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.adv
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelOption;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
@ -24,11 +25,12 @@ public class ClientHandleTcpDistributeClientTransferClientPermeateChannelInitSuc
/**
* 处理当前数据
*
* @param channel 当前通道
* @param channelHandlerContext 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
public void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
Channel channel = channelHandlerContext.channel();
// 连接成功 开启自动读取写
byte[] msgClientId = nettyProxyMsg.getClientId();
byte[] msgClientTargetIp = nettyProxyMsg.getClientTargetIp();

View File

@ -3,6 +3,7 @@ package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.adv
import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.tcp.client.AbstractHandleTcpDistributeClientTransferClientRequestTypeAdvanced;
@ -24,11 +25,12 @@ public class ClientHandleTcpDistributeClientTransferClientRequestTypeAdvanced ex
/**
* 处理当前数据
*
* @param channel 当前通道
* @param channelHandlerContext 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
public void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
Channel channel = channelHandlerContext.channel();
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
// 把数据转到真实服务
ByteBuf buf = channel.config().getAllocator().buffer(nettyProxyMsg.getData().length);

View File

@ -2,6 +2,7 @@ package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.adv
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelOption;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.handler.NettyTcpClientPermeateServerVisitorHandler;
@ -27,15 +28,16 @@ public class ClientHandleTcpDistributeClientTransferServerPermeateChannelConnect
/**
* 处理当前数据
*
* @param transferChannel 当前通道
* @param channelHandlerContext 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
public void doHandler(Channel transferChannel, NettyProxyMsg nettyProxyMsg) {
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
Channel channel = channelHandlerContext.channel();
// 连接成功 开启自动读取写
byte[] msgVisitorId = nettyProxyMsg.getVisitorId();
String visitorId = new String(msgVisitorId);
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(transferChannel);
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
nextChannel.config().setOption(ChannelOption.AUTO_READ, true);
}

View File

@ -1,7 +1,7 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.advanced;
import com.alibaba.fastjson.JSONObject;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.event.ClientChangeEvent;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
@ -25,11 +25,11 @@ public class ClientHandleTcpDistributeConnectSuccessNotificationTypeAdvancedHand
/**
* 处理当前数据
*
* @param channel 当前通道
* @param channelHandlerContext 当前通道
* @param msg 通道数据
*/
@Override
protected void doHandler(Channel channel, NettyProxyMsg msg) {
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg msg) {
// 客户端ID{},客户端:{}连接成功
log.warn("Client ID: {}, Client Data : {} Connection successful", new String(msg.getClientId()), new String(msg.getData()));

View File

@ -1,7 +1,7 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.advanced;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.event.ClientChangeEvent;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
@ -25,11 +25,11 @@ public class ClientHandleTcpDistributeDisconnectTypeAdvancedHandle extends Abstr
/**
* 处理当前数据
*
* @param channel 当前通道
* @param channelHandlerContext 当前通道
* @param msg 通道数据
*/
@Override
public void doHandler(Channel channel, NettyProxyMsg msg) {
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg msg) {
// 服务下线
byte[] data = msg.getData();
byte[] clientId = msg.getClientId();

View File

@ -1,6 +1,6 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.advanced;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
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.tcp.socket.NettyTcpServerPermeateClientRealSocket;
@ -30,11 +30,11 @@ public class ClientHandleTcpDistributeServicePermeateClientRealConnectTypeAdvanc
/**
* 处理当前数据
*
* @param channel 当前通道
* @param channelHandlerContext 当前通道
* @param msg 通道数据
*/
@Override
protected void doHandler(Channel channel, NettyProxyMsg msg) {
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg msg) {
// 创建真实端口监听
byte[] clientIdBytes = msg.getClientId();
byte[] visitorPort = msg.getVisitorPort();

View File

@ -3,6 +3,7 @@ package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.adv
import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.tcp.client.AbstractHandleTcpDistributeServicePermeateClientTransferClientResponseTypeAdvanced;
@ -24,11 +25,12 @@ public class ClientHandleTcpDistributeServicePermeateClientTransferClientRespons
/**
* 处理当前数据
*
* @param channel 当前通道
* @param channelHandlerContext 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
public void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
Channel channel = channelHandlerContext.channel();
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
// 把数据转到真实服务
ByteBuf buf = channel.config().getAllocator().buffer(nettyProxyMsg.getData().length);

View File

@ -1,6 +1,6 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.advanced;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.tcp.client.AbstractHandleTcpDistributeSingleClientMessageTypeAdvanced;
@ -13,11 +13,11 @@ public class ClientHandleTcpDistributeSingleClientMessageTypeAdvanced extends Ab
/**
* 处理当前数据
*
* @param channel 当前通道
* @param channelHandlerContext 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
protected void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
byte[] clientId = nettyProxyMsg.getClientId();
byte[] data = nettyProxyMsg.getData();
log.info("接收客户端:{},发送过来的聊天信息:{}", new String(clientId), new String(data));

View File

@ -1,6 +1,7 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.advanced;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelOption;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
@ -13,11 +14,12 @@ public class ClientHandleTcpDistributeSingleClientRealAutoReadConnectTypeAdvance
/**
* 处理当前数据
*
* @param channel 当前通道
* @param channelHandlerContext 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
protected void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
Channel channel = channelHandlerContext.channel();
// 获取访客ID
byte[] visitorId = nettyProxyMsg.getVisitorId();
// 获取访客对应的真实代理通道

View File

@ -1,6 +1,6 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.advanced;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.NettyCommunicationIdContext;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
@ -12,11 +12,11 @@ public class ClientHandleTcpDistributeSingleClientRealCloseVisitorTypeAdvanced e
/**
* 处理当前数据
*
* @param channel 当前通道
* @param channelHandlerContext 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
protected void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
// 关闭代理的真实通道
byte[] visitorId = nettyProxyMsg.getVisitorId();
NettyRealIdContext.clear(visitorId);

View File

@ -1,6 +1,6 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.advanced;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.tcp.client.AbstractHandleTcpDistributeStagingClosedTypeAdvanced;
@ -15,11 +15,11 @@ public class ClientHandleTcpDistributeStagingClosedTypeAdvanced extends Abstract
/**
* 处理当前数据
*
* @param channel 当前通道
* @param channelHandlerContext 当前通道
* @param msg 通道数据
*/
@Override
protected void doHandler(Channel channel, NettyProxyMsg msg) {
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg msg) {
String clientId = new String(msg.getClientId());
log.info("客户端:{}离线暂存关闭", clientId);
// 修改redis 客户端暂存状态

View File

@ -1,6 +1,6 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.advanced;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.tcp.client.AbstractHandleTcpDistributeStagingOpenedTypeAdvanced;
@ -19,11 +19,11 @@ public class ClientHandleTcpDistributeStagingOpenedTypeAdvanced extends Abstract
/**
* 处理当前数据
*
* @param channel 当前通道
* @param channelHandlerContext 当前通道
* @param msg 通道数据
*/
@Override
protected void doHandler(Channel channel, NettyProxyMsg msg) {
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg msg) {
String clientId = new String(msg.getClientId());
//客户端:{}离线暂存开启
log.warn("Client: {} Offline temporary storage enabled", new String(msg.getClientId()));

View File

@ -47,7 +47,7 @@ public class NettyTcpClientHandler extends SimpleChannelInboundHandler<NettyProx
// 接收服务端、或者是代理端的信息
Channel channel = ctx.channel();
// log.info("type:{},clientId:{},data:{}",msg.getMysqlType(),new String(msg.getClientId()),new String(msg.getData()));
channelTypeAdapter.handler(channel, msg);
channelTypeAdapter.handler(ctx, msg);
}
/**
@ -64,7 +64,7 @@ public class NettyTcpClientHandler extends SimpleChannelInboundHandler<NettyProx
NettyProxyMsg nettyMsg = new NettyProxyMsg();
nettyMsg.setType(TcpMessageType.TCP_CLIENT_CHANNEL_ACTIVE);
nettyMsg.setClientId(clientId);
channelTypeAdapter.handler(channel, nettyMsg);
channelTypeAdapter.handler(ctx, nettyMsg);
}
@ -108,7 +108,7 @@ public class NettyTcpClientHandler extends SimpleChannelInboundHandler<NettyProx
NettyProxyMsg nettyMsg = new NettyProxyMsg();
nettyMsg.setType(TcpMessageType.TCP_DISTRIBUTE_CLIENT_DISCONNECTION_NOTIFICATION);
nettyMsg.setClientId(clientId.getBytes(StandardCharsets.UTF_8));
channelTypeAdapter.handler(channel, nettyMsg);
channelTypeAdapter.handler(ctx, nettyMsg);
ctx.close();
}

View File

@ -29,7 +29,7 @@ public class NettyTcpClientPermeateClientTransferHandler extends SimpleChannelIn
@Override
public void channelRead0(ChannelHandlerContext ctx, NettyProxyMsg nettyProxyMsg) throws Exception {
Channel channel = ctx.channel();
channelTypeAdapter.handler(channel, nettyProxyMsg);
channelTypeAdapter.handler(ctx, nettyProxyMsg);
}

View File

@ -29,7 +29,7 @@ public class NettyTcpClientPermeateClientTransferRealHandler extends SimpleChann
@Override
public void channelRead0(ChannelHandlerContext ctx, NettyProxyMsg nettyProxyMsg) throws Exception {
Channel channel = ctx.channel();
channelTypeAdapter.handler(channel, nettyProxyMsg);
channelTypeAdapter.handler(ctx, nettyProxyMsg);
}

View File

@ -31,7 +31,7 @@ public class NettyTcpClientPermeateServerTransferHandler extends SimpleChannelIn
@Override
public void channelRead0(ChannelHandlerContext ctx, NettyProxyMsg nettyProxyMsg) throws Exception {
Channel channel = ctx.channel();
channelTypeAdapter.handler(channel, nettyProxyMsg);
channelTypeAdapter.handler(ctx, nettyProxyMsg);
}

View File

@ -31,7 +31,7 @@ public class NettyTcpServerPermeateClientTransferHandler extends SimpleChannelIn
@Override
public void channelRead0(ChannelHandlerContext ctx, NettyProxyMsg nettyProxyMsg) throws Exception {
Channel channel = ctx.channel();
channelTypeAdapter.handler(channel, nettyProxyMsg);
channelTypeAdapter.handler(ctx, nettyProxyMsg);
}

View File

@ -1,7 +1,7 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.udp.advanced;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import org.framework.lazy.cloud.network.heartbeat.common.constant.UdpMessageType;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.udp.AbstractUdpHandleChannelHeartbeatTypeAdvanced;
@ -16,14 +16,14 @@ public class ClientHandleUdpChannelHeartbeatTypeAdvanced extends AbstractUdpHand
/**
* 处理当前数据
*
* @param channel 当前通道
* @param channelHandlerContext 当前通道
* @param msg 通道数据
*/
@Override
public void doHandler(Channel channel, NettyProxyMsg msg) {
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg msg) {
NettyProxyMsg hb = new NettyProxyMsg();
hb.setType(UdpMessageType.UDP_TYPE_HEARTBEAT);
// channel.writeAndFlush(hb);
// channelHandlerContext.writeAndFlush(hb);
}
}

View File

@ -3,6 +3,7 @@ package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.udp.adv
import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
@ -28,11 +29,11 @@ public class ClientHandleUdpChannelTransferTypeAdvancedHandleDistribute extends
/**
* 处理当前数据
*
* @param channel 当前通道
* @param channelHandlerContext 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
public void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
log.debug("接收到服务端需要内网穿透的数据:{}" , nettyProxyMsg);
String clientId = nettyClientProperties.getClientId();
byte[] visitorPort = nettyProxyMsg.getVisitorPort();
@ -41,7 +42,7 @@ public class ClientHandleUdpChannelTransferTypeAdvancedHandleDistribute extends
byte[] visitorId = nettyProxyMsg.getVisitorId();
// 真实服务通道
// Channel realChannel = NettyRealIdContext.getReal(new String(visitorId));
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channelHandlerContext);
if (nextChannel == null) {
log.error("无法获取访客:{} 真实服务", new String(visitorId));
return;
@ -49,7 +50,7 @@ public class ClientHandleUdpChannelTransferTypeAdvancedHandleDistribute extends
// 把数据转到真实服务
ByteBuf buf = channel.config().getAllocator().buffer(nettyProxyMsg.getData().length);
ByteBuf buf = channelHandlerContext.config().getAllocator().buffer(nettyProxyMsg.getData().length);
buf.writeBytes(nettyProxyMsg.getData());
nextChannel.writeAndFlush(buf);

View File

@ -1,6 +1,6 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.udp.advanced;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
import org.framework.lazy.cloud.network.heartbeat.common.ChannelContext;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
@ -20,15 +20,15 @@ public class ClientHandleUdpClientChannelActiveAdvanced extends AbstractHandleUd
/**
* 处理当前数据
*
* @param channel 当前通道
* @param channelHandlerContext 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
protected void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
// 缓存当前通道
byte[] clientIdByte = nettyProxyMsg.getClientId();
String clientId = new String(clientIdByte);
ChannelContext.push(channel, clientId);
ChannelAttributeKeyUtils.buildClientId(channel, clientId);
ChannelContext.push(channelHandlerContext, clientId);
ChannelAttributeKeyUtils.buildClientId(channelHandlerContext, clientId);
}
}

View File

@ -1,7 +1,7 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.udp.advanced;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.NettyVisitorPortContext;
@ -22,11 +22,11 @@ public class ClientHandleUdpDistributeClientPermeateClientCloseTypeAdvanced exte
/**
* 处理当前数据
*
* @param channel 当前通道
* @param channelHandlerContext 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
public void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
// 初始化 客户端渗透服务端socket
byte[] msgVisitorPort = nettyProxyMsg.getVisitorPort();
Integer visitorPort = Integer.parseInt(new String(msgVisitorPort));

View File

@ -1,7 +1,7 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.udp.advanced;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
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.udp.socket.NettyUdpClientPermeateClientVisitorSocket;
@ -26,11 +26,11 @@ public class ClientHandleUdpDistributeClientPermeateClientInitTypeAdvanced exten
/**
* 处理当前数据
*
* @param channel 当前通道
* @param channelHandlerContext 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
public void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
// 初始化 客户端渗透服务端socket
byte[] fromClientIdBytes = nettyProxyMsg.getClientId();
byte[] visitorPortBytes = nettyProxyMsg.getVisitorPort();

View File

@ -2,6 +2,7 @@ package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.udp.adv
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.udp.client.AbstractHandleUdpDistributeClientPermeateClientTransferCloseTypeAdvanced;
@ -20,15 +21,15 @@ public class ClientHandleUdpDistributeClientPermeateClientTransferCloseTypeAdvan
/**
* 处理当前数据
*
* @param channel 当前通道
* @param channelHandlerContext 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
public void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
// 关闭客户端真实通道、访客通道
Channel realChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
Channel realChannel = ChannelAttributeKeyUtils.getNextChannel(channelHandlerContext);
realChannel.close();// 真实通道关闭
channel.close(); // 数据传输通道关闭
channelHandlerContext.close(); // 数据传输通道关闭
}

View File

@ -1,7 +1,7 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.udp.advanced;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.NettyVisitorPortContext;
@ -22,11 +22,11 @@ public class ClientHandleUdpDistributeClientPermeateServerCloseTypeAdvanced exte
/**
* 处理当前数据
*
* @param channel 当前通道
* @param channelHandlerContext 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
public void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
// 初始化 客户端渗透服务端socket
byte[] msgVisitorPort = nettyProxyMsg.getVisitorPort();
Integer visitorPort = Integer.parseInt(new String(msgVisitorPort));

View File

@ -1,7 +1,7 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.udp.advanced;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
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.udp.socket.NettyUdpClientPermeateServerVisitorSocket;
@ -32,11 +32,11 @@ public class ClientHandleUdpDistributeClientPermeateServerInitTypeAdvanced exten
/**
* 处理当前数据
*
* @param channel 当前通道
* @param channelHandlerContext 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
public void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
// 初始化 客户端渗透服务端socket
byte[] clientIdBytes = nettyProxyMsg.getClientId();
byte[] visitorPort = nettyProxyMsg.getVisitorPort();

View File

@ -2,6 +2,7 @@ package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.udp.adv
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.udp.client.AbstractHandleUdpDistributeClientPermeateServerTransferCloseTypeAdvanced;
@ -20,14 +21,14 @@ public class ClientHandleUdpDistributeClientPermeateServerTransferCloseTypeAdvan
/**
* 处理当前数据
*
* @param channel 当前通道
* @param channelHandlerContext 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
public void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
// 关闭本地通信通道
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
channel.close();
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channelHandlerContext);
channelHandlerContext.close();
nextChannel.close();
}

View File

@ -3,6 +3,7 @@ package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.udp.adv
import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.udp.client.AbstractHandleUdpDistributeClientPermeateServerTransferTypeAdvanced;
@ -22,11 +23,12 @@ public class ClientHandleUdpDistributeClientPermeateServerTransferTypeAdvanced e
/**
* 处理当前数据
*
* @param channel 当前通道
* @param channelHandlerContext 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
public void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
Channel channel = channelHandlerContext.channel();
log.debug("客户端渗透服务端返回数据:{}" , new String(nettyProxyMsg.getData()));
byte[] visitorPort = nettyProxyMsg.getVisitorPort();
byte[] clientTargetIp = nettyProxyMsg.getClientTargetIp();

View File

@ -1,7 +1,7 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.udp.advanced;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
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.udp.socket.NettyUdpClientPermeateClientRealSocket;
@ -26,11 +26,11 @@ public class ClientHandleUdpDistributeClientTransferClientPermeateChannelConnect
/**
* 处理当前数据
*
* @param channel 当前通道
* @param channelHandlerContext 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
public void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
// 创建connect 然后发送创建成功
byte[] msgClientId = nettyProxyMsg.getClientId();
byte[] msgClientTargetIp = nettyProxyMsg.getClientTargetIp();

View File

@ -2,6 +2,7 @@ package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.udp.adv
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelOption;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
@ -24,11 +25,11 @@ public class ClientHandleUdpDistributeClientTransferClientPermeateChannelInitSuc
/**
* 处理当前数据
*
* @param channel 当前通道
* @param channelHandlerContext 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
public void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
// 连接成功 开启自动读取写
byte[] msgClientId = nettyProxyMsg.getClientId();
byte[] msgClientTargetIp = nettyProxyMsg.getClientTargetIp();
@ -36,7 +37,7 @@ public class ClientHandleUdpDistributeClientTransferClientPermeateChannelInitSuc
byte[] msgVisitorId = nettyProxyMsg.getVisitorId();
byte[] msgVisitorPort = nettyProxyMsg.getVisitorPort();
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channelHandlerContext);
nextChannel.config().setOption(ChannelOption.AUTO_READ, true);
}

View File

@ -3,6 +3,7 @@ package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.udp.adv
import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.udp.client.AbstractHandleUdpDistributeClientTransferClientRequestTypeAdvanced;
@ -24,11 +25,12 @@ public class ClientHandleUdpDistributeClientTransferClientRequestTypeAdvanced ex
/**
* 处理当前数据
*
* @param channel 当前通道
* @param channelHandlerContext 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
public void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
Channel channel = channelHandlerContext.channel();
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
// 把数据转到真实服务
ByteBuf buf = channel.config().getAllocator().buffer(nettyProxyMsg.getData().length);

View File

@ -2,6 +2,7 @@ package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.udp.adv
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelOption;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.udp.handler.NettyUdpClientPermeateServerVisitorHandler;
@ -27,15 +28,15 @@ public class ClientHandleUdpDistributeClientTransferServerPermeateChannelConnect
/**
* 处理当前数据
*
* @param transferChannel 当前通道
* @param channelHandlerContext 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
public void doHandler(Channel transferChannel, NettyProxyMsg nettyProxyMsg) {
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
// 连接成功 开启自动读取写
byte[] msgVisitorId = nettyProxyMsg.getVisitorId();
String visitorId = new String(msgVisitorId);
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(transferChannel);
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channelHandlerContext);
nextChannel.config().setOption(ChannelOption.AUTO_READ, true);
}

View File

@ -1,7 +1,7 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.udp.advanced;
import com.alibaba.fastjson.JSONObject;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.event.ClientChangeEvent;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
@ -25,11 +25,11 @@ public class ClientHandleUdpDistributeConnectSuccessNotificationTypeAdvancedHand
/**
* 处理当前数据
*
* @param channel 当前通道
* @param channelHandlerContext 当前通道
* @param msg 通道数据
*/
@Override
protected void doHandler(Channel channel, NettyProxyMsg msg) {
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg msg) {
// 客户端ID{},客户端:{}连接成功
log.warn("Client ID: {}, Client Data : {} Connection successful", new String(msg.getClientId()), new String(msg.getData()));

View File

@ -1,7 +1,7 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.udp.advanced;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.event.ClientChangeEvent;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
@ -25,11 +25,11 @@ public class ClientHandleUdpDistributeDisconnectTypeAdvancedHandle extends Abstr
/**
* 处理当前数据
*
* @param channel 当前通道
* @param channelHandlerContext 当前通道
* @param msg 通道数据
*/
@Override
public void doHandler(Channel channel, NettyProxyMsg msg) {
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg msg) {
// 服务下线
byte[] data = msg.getData();
byte[] clientId = msg.getClientId();

View File

@ -1,6 +1,6 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.udp.advanced;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
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.udp.socket.NettyUdpServerPermeateClientRealSocket;
@ -29,11 +29,11 @@ public class ClientHandleUdpDistributeServicePermeateClientRealConnectTypeAdvanc
/**
* 处理当前数据
*
* @param channel 当前通道
* @param channelHandlerContext 当前通道
* @param msg 通道数据
*/
@Override
protected void doHandler(Channel channel, NettyProxyMsg msg) {
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg msg) {
// 创建真实端口监听
byte[] clientIdBytes = msg.getClientId();
byte[] visitorPort = msg.getVisitorPort();

View File

@ -3,6 +3,7 @@ package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.udp.adv
import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.udp.client.AbstractHandleUdpDistributeServicePermeateClientTransferClientResponseTypeAdvanced;
@ -24,14 +25,14 @@ public class ClientHandleUdpDistributeServicePermeateClientTransferClientRespons
/**
* 处理当前数据
*
* @param channel 当前通道
* @param channelHandlerContext 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
public void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channelHandlerContext);
// 把数据转到真实服务
ByteBuf buf = channel.config().getAllocator().buffer(nettyProxyMsg.getData().length);
ByteBuf buf = channelHandlerContext.config().getAllocator().buffer(nettyProxyMsg.getData().length);
buf.writeBytes(nettyProxyMsg.getData());
nextChannel.writeAndFlush(buf);

View File

@ -1,6 +1,6 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.udp.advanced;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.udp.client.AbstractHandleUdpDistributeSingleClientMessageTypeAdvanced;
@ -13,11 +13,11 @@ public class ClientHandleUdpDistributeSingleClientMessageTypeAdvanced extends Ab
/**
* 处理当前数据
*
* @param channel 当前通道
* @param channelHandlerContext 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
protected void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
byte[] clientId = nettyProxyMsg.getClientId();
byte[] data = nettyProxyMsg.getData();
log.info("接收客户端:{},发送过来的聊天信息:{}", new String(clientId), new String(data));

View File

@ -1,6 +1,7 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.udp.advanced;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelOption;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
@ -13,16 +14,16 @@ public class ClientHandleUdpDistributeSingleClientRealAutoReadConnectTypeAdvance
/**
* 处理当前数据
*
* @param channel 当前通道
* @param channelHandlerContext 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
protected void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
// 获取访客ID
byte[] visitorId = nettyProxyMsg.getVisitorId();
// 获取访客对应的真实代理通道
Channel realChannel = NettyRealIdContext.getReal(visitorId);
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channelHandlerContext);
if (nextChannel != null) {
nextChannel.config().setOption(ChannelOption.AUTO_READ, true);
}

View File

@ -1,6 +1,6 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.udp.advanced;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.NettyCommunicationIdContext;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
@ -12,11 +12,11 @@ public class ClientHandleUdpDistributeSingleClientRealCloseVisitorTypeAdvanced e
/**
* 处理当前数据
*
* @param channel 当前通道
* @param channelHandlerContext 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
protected void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
// 关闭代理的真实通道
byte[] visitorId = nettyProxyMsg.getVisitorId();
NettyRealIdContext.clear(visitorId);

View File

@ -1,6 +1,6 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.udp.advanced;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.udp.client.AbstractHandleUdpDistributeStagingClosedTypeAdvanced;
@ -15,11 +15,11 @@ public class ClientHandleUdpDistributeStagingClosedTypeAdvanced extends Abstract
/**
* 处理当前数据
*
* @param channel 当前通道
* @param channelHandlerContext 当前通道
* @param msg 通道数据
*/
@Override
protected void doHandler(Channel channel, NettyProxyMsg msg) {
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg msg) {
String clientId = new String(msg.getClientId());
log.info("客户端:{}离线暂存关闭", clientId);
// 修改redis 客户端暂存状态

View File

@ -1,6 +1,6 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.udp.advanced;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.udp.client.AbstractHandleUdpDistributeStagingOpenedTypeAdvanced;
@ -19,11 +19,11 @@ public class ClientHandleUdpDistributeStagingOpenedTypeAdvanced extends Abstract
/**
* 处理当前数据
*
* @param channel 当前通道
* @param channelHandlerContext 当前通道
* @param msg 通道数据
*/
@Override
protected void doHandler(Channel channel, NettyProxyMsg msg) {
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg msg) {
String clientId = new String(msg.getClientId());
//客户端:{}离线暂存开启
log.warn("Client: {} Offline temporary storage enabled", new String(msg.getClientId()));

View File

@ -47,7 +47,7 @@ public class NettyUdpClientHandler extends SimpleChannelInboundHandler<NettyProx
// 接收服务端、或者是代理端的信息
Channel channel = ctx.channel();
// log.info("type:{},clientId:{},data:{}",msg.getMysqlType(),new String(msg.getClientId()),new String(msg.getData()));
channelTypeAdapter.handler(channel, msg);
channelTypeAdapter.handler(ctx, msg);
}
/**
@ -64,7 +64,7 @@ public class NettyUdpClientHandler extends SimpleChannelInboundHandler<NettyProx
NettyProxyMsg nettyMsg = new NettyProxyMsg();
nettyMsg.setType(UdpMessageType.UDP_CLIENT_CHANNEL_ACTIVE);
nettyMsg.setClientId(clientId);
channelTypeAdapter.handler(channel, nettyMsg);
channelTypeAdapter.handler(ctx, nettyMsg);
}
@ -108,7 +108,7 @@ public class NettyUdpClientHandler extends SimpleChannelInboundHandler<NettyProx
NettyProxyMsg nettyMsg = new NettyProxyMsg();
nettyMsg.setType(UdpMessageType.UDP_DISTRIBUTE_CLIENT_DISCONNECTION_NOTIFICATION);
nettyMsg.setClientId(clientId.getBytes(StandardCharsets.UTF_8));
channelTypeAdapter.handler(channel, nettyMsg);
channelTypeAdapter.handler(ctx, nettyMsg);
ctx.close();
}

View File

@ -29,7 +29,7 @@ public class NettyUdpClientPermeateClientTransferHandler extends SimpleChannelIn
@Override
public void channelRead0(ChannelHandlerContext ctx, NettyProxyMsg nettyProxyMsg) throws Exception {
Channel channel = ctx.channel();
channelTypeAdapter.handler(channel, nettyProxyMsg);
channelTypeAdapter.handler(ctx, nettyProxyMsg);
}

View File

@ -29,7 +29,7 @@ public class NettyUdpClientPermeateClientTransferRealHandler extends SimpleChann
@Override
public void channelRead0(ChannelHandlerContext ctx, NettyProxyMsg nettyProxyMsg) throws Exception {
Channel channel = ctx.channel();
channelTypeAdapter.handler(channel, nettyProxyMsg);
channelTypeAdapter.handler(ctx, nettyProxyMsg);
}

View File

@ -31,7 +31,7 @@ public class NettyUdpClientPermeateServerTransferHandler extends SimpleChannelIn
@Override
public void channelRead0(ChannelHandlerContext ctx, NettyProxyMsg nettyProxyMsg) throws Exception {
Channel channel = ctx.channel();
channelTypeAdapter.handler(channel, nettyProxyMsg);
channelTypeAdapter.handler(ctx, nettyProxyMsg);
}

View File

@ -31,7 +31,7 @@ public class NettyUdpServerPermeateClientTransferHandler extends SimpleChannelIn
@Override
public void channelRead0(ChannelHandlerContext ctx, NettyProxyMsg nettyProxyMsg) throws Exception {
Channel channel = ctx.channel();
channelTypeAdapter.handler(channel, nettyProxyMsg);
channelTypeAdapter.handler(ctx, nettyProxyMsg);
}

View File

@ -1,6 +1,6 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.proxy.http.advanced;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
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.socket.NettyHttpClientProxyClientRealSocket;
@ -24,11 +24,11 @@ public class ClientHandleDistributeHttpClientProxyClientConnectionTransferSucces
/**
* 处理当前数据
*
* @param channel 当前通道
* @param channelHandlerContext 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
protected void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
// 客户端主动连接服务端创建一个传输通道

View File

@ -2,19 +2,12 @@ package org.framework.lazy.cloud.network.heartbeat.client.netty.proxy.http.advan
import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
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.socket.NettyHttpClientProxyClientRealSocket;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.proxy.http.client.AbstractHandleHttpDistributeClientProxyClientConnectionTransferSuccessfulTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.proxy.http.client.AbstractHandleHttpDistributeClientProxyClientTransferRequestTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
import org.wu.framework.core.utils.ObjectUtils;
import org.wu.framework.spring.utils.SpringContextHolder;
import java.util.ArrayList;
import java.util.List;
/**
* http 远程代理
@ -28,16 +21,16 @@ public class ClientHandleDistributeHttpClientProxyClientTransferRequestAdvanced
/**
* 处理当前数据
*
* @param channel 当前通道
* @param channelHandlerContext 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
protected void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
// 数据发送
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channelHandlerContext);
if(ObjectUtils.isNotEmpty(nextChannel)){
ByteBuf buf = channel.config().getAllocator().buffer(nettyProxyMsg.getData().length);
ByteBuf buf = channelHandlerContext.config().getAllocator().buffer(nettyProxyMsg.getData().length);
buf.writeBytes(nettyProxyMsg.getData());
nextChannel.writeAndFlush(buf);
}else {

View File

@ -1,7 +1,7 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.proxy.http.advanced;
import com.alibaba.fastjson.JSON;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.proxy.http.client.AbstractHandleHttpDistributeClientProxyServerClientRouteTypeAdvanced;
@ -20,11 +20,11 @@ public class ClientHandleDistributeHttpClientProxyServerClientRouteTypeAdvanced
/**
* 处理当前数据
*
* @param channel 当前通道
* @param channelHandlerContext 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
protected void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
byte[] data = nettyProxyMsg.getData();
ClientProxyRoute clientProxyRoute = JSON.parseObject(data, ClientProxyRoute.class);

View File

@ -1,15 +1,11 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.proxy.http.advanced;
import com.alibaba.fastjson.JSON;
import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.proxy.http.client.AbstractHandleHttpDistributeClientProxyServerServerRouteTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.proxy.http.client.AbstractHandleHttpDistributeClientProxyServerTransferTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
import org.framework.lazy.cloud.network.heartbeat.protocol.route.RouteContext;
import org.framework.lazy.cloud.network.heartbeat.protocol.route.RouteType;
import org.framework.lazy.cloud.network.heartbeat.protocol.route.ServerProxyRoute;
/**
@ -24,11 +20,11 @@ public class ClientHandleDistributeHttpClientProxyServerServerRouteTypeAdvanced
/**
* 处理当前数据
*
* @param channel 当前通道
* @param channelHandlerContext 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
protected void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
byte[] data = nettyProxyMsg.getData();
ServerProxyRoute serverProxyRoute = JSON.parseObject(data, ServerProxyRoute.class);

View File

@ -2,6 +2,7 @@ package org.framework.lazy.cloud.network.heartbeat.client.netty.proxy.http.advan
import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.proxy.http.client.AbstractHandleHttpDistributeClientProxyServerTransferTypeAdvanced;
@ -19,21 +20,21 @@ public class ClientHandleDistributeHttpClientProxyServerTransferTypeAdvanced ext
/**
* 处理当前数据
*
* @param channel 当前通道
* @param channelHandlerContext 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
protected void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
String visitorId = ChannelAttributeKeyUtils.getVisitorId(channel);
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
String visitorId = ChannelAttributeKeyUtils.getVisitorId(channelHandlerContext);
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channelHandlerContext);
if (nextChannel == null) {
log.error("无法获取访客:{} 真实服务", visitorId);
return;
}
// 把数据转到真实服务
ByteBuf buf = channel.config().getAllocator().buffer(nettyProxyMsg.getData().length);
ByteBuf buf = channelHandlerContext.config().getAllocator().buffer(nettyProxyMsg.getData().length);
buf.writeBytes(nettyProxyMsg.getData());
nextChannel.writeAndFlush(buf);

View File

@ -1,6 +1,6 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.proxy.http.advanced;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
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.socket.NettyHttpServerProxyClientRealSocket;
@ -19,11 +19,11 @@ public class ClientHandleDistributeHttpServerProxyClientConnectionSuccessfulType
/**
* 处理当前数据
*
* @param channel 当前通道
* @param channelHandlerContext 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
protected void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
// 创建一个传输通道

View File

@ -2,6 +2,7 @@ package org.framework.lazy.cloud.network.heartbeat.client.netty.proxy.http.advan
import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.client.netty.proxy.http.handler.NettyHttpServerProxyClientRealHandler;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
@ -20,16 +21,16 @@ public class ClientHandleDistributeHttpServerProxyClientTransferRequestAdvanced
/**
* 处理当前数据
*
* @param channel 当前通道
* @param channelHandlerContext 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
protected void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
// 数据发送
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channelHandlerContext);
if (ObjectUtils.isNotEmpty(nextChannel)) {
ByteBuf buf = channel.config().getAllocator().buffer(nettyProxyMsg.getData().length);
ByteBuf buf = channelHandlerContext.config().getAllocator().buffer(nettyProxyMsg.getData().length);
buf.writeBytes(nettyProxyMsg.getData());
nextChannel.writeAndFlush(buf);
} else {

View File

@ -1,6 +1,6 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.proxy.http.advanced;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
import org.framework.lazy.cloud.network.heartbeat.client.netty.proxy.http.NettyHttpClientProxyClient;
import org.framework.lazy.cloud.network.heartbeat.client.netty.proxy.http.socket.NettyHttpClientProxyClientProxySocket;
@ -24,11 +24,11 @@ public class ClientHandleHttpClientProxyClientTypeAdvanced extends
/**
* 处理当前数据
*
* @param channel 当前通道
* @param channelHandlerContext 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
protected void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
String targetPortString = nettyProxyMsg.getTargetPortString();
String targetIpString = nettyProxyMsg.getTargetIpString();
byte[] data = nettyProxyMsg.getData();
@ -46,6 +46,6 @@ public class ClientHandleHttpClientProxyClientTypeAdvanced extends
nettyHttpClientProxyClient.setNettyClientProperties(nettyClientProperties);
nettyHttpClientProxyClient.setData(data);
NettyHttpClientProxyClientProxySocket.buildTransferServer(nettyHttpClientProxyClient, channel);
NettyHttpClientProxyClientProxySocket.buildTransferServer(nettyHttpClientProxyClient, channelHandlerContext);
}
}

View File

@ -1,6 +1,6 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.proxy.http.advanced;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
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.socket.NettyHttpClientProxyServerProxySocket;
@ -23,11 +23,11 @@ public class ClientHandleHttpClientProxyServerTypeAdvanced extends
/**
* 处理当前数据
*
* @param channel 当前通道
* @param channelHandlerContext 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
protected void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
String targetPortString = nettyProxyMsg.getTargetPortString();
String targetIpString = nettyProxyMsg.getTargetIpString();
@ -45,7 +45,7 @@ public class ClientHandleHttpClientProxyServerTypeAdvanced extends
nettyHttpClientProxyServer.setNettyClientProperties(nettyClientProperties);
nettyHttpClientProxyServer.setData(data);
NettyHttpClientProxyServerProxySocket.buildTransferServer(nettyHttpClientProxyServer, channel);
NettyHttpClientProxyServerProxySocket.buildTransferServer(nettyHttpClientProxyServer, channelHandlerContext);
}
}

View File

@ -1,17 +1,11 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.proxy.http.advanced;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
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.socket.NettyHttpClientProxyClientRealSocket;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.proxy.http.client.AbstractHandleHttpDistributeClientProxyClientTransferCLoseTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
import org.wu.framework.spring.utils.SpringContextHolder;
import java.util.ArrayList;
import java.util.List;
/**
* http 远程代理
@ -25,15 +19,15 @@ public class ClientHandleHttpDistributeClientProxyClientTransferCLoseTypeAdvance
/**
* 处理当前数据
*
* @param channel 当前通道
* @param channelHandlerContext 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
protected void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
// 关闭传输通道
Channel realChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
Channel realChannel = ChannelAttributeKeyUtils.getNextChannel(channelHandlerContext);
realChannel.close();// 真实通道关闭
channel.close(); // 数据传输通道关闭
channelHandlerContext.close(); // 数据传输通道关闭
}
}

View File

@ -2,6 +2,7 @@ package org.framework.lazy.cloud.network.heartbeat.client.netty.proxy.http.advan
import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.proxy.http.client.AbstractHandleHttpDistributeClientProxyClientTransferResponseTypeAdvanced;
@ -20,16 +21,16 @@ public class ClientHandleHttpDistributeClientProxyClientTransferResponseTypeAdva
/**
* 处理当前数据
*
* @param channel 当前通道
* @param channelHandlerContext 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
protected void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
// 数据发送
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channelHandlerContext);
if(ObjectUtils.isNotEmpty(nextChannel)){
ByteBuf buf = channel.config().getAllocator().buffer(nettyProxyMsg.getData().length);
ByteBuf buf = channelHandlerContext.config().getAllocator().buffer(nettyProxyMsg.getData().length);
buf.writeBytes(nettyProxyMsg.getData());
nextChannel.writeAndFlush(buf);
}else {

View File

@ -30,7 +30,7 @@ public class NettyHttpClientProxyClientProxyHandler extends SimpleChannelInbound
@Override
public void channelRead0(ChannelHandlerContext ctx, NettyProxyMsg nettyProxyMsg) throws Exception {
Channel channel = ctx.channel();
channelTypeAdapter.handler(channel, nettyProxyMsg);
channelTypeAdapter.handler(ctx, nettyProxyMsg);
}

View File

@ -30,7 +30,7 @@ public class NettyHttpClientProxyClientTransferRealHandler extends SimpleChannel
@Override
public void channelRead0(ChannelHandlerContext ctx, NettyProxyMsg nettyProxyMsg) throws Exception {
Channel channel = ctx.channel();
channelTypeAdapter.handler(channel, nettyProxyMsg);
channelTypeAdapter.handler(ctx, nettyProxyMsg);
}

View File

@ -29,7 +29,7 @@ public class NettyHttpClientProxyServerProxyHandler extends SimpleChannelInbound
@Override
public void channelRead0(ChannelHandlerContext ctx, NettyProxyMsg nettyProxyMsg) throws Exception {
Channel channel = ctx.channel();
channelTypeAdapter.handler(channel, nettyProxyMsg);
channelTypeAdapter.handler(ctx, nettyProxyMsg);
}

View File

@ -30,7 +30,7 @@ public class NettyHttpServerProxyClientTransferRealHandler extends SimpleChannel
@Override
public void channelRead0(ChannelHandlerContext ctx, NettyProxyMsg nettyProxyMsg) throws Exception {
Channel channel = ctx.channel();
channelTypeAdapter.handler(channel, nettyProxyMsg);
channelTypeAdapter.handler(ctx, nettyProxyMsg);
}

View File

@ -1,6 +1,6 @@
package org.framework.lazy.cloud.network.heartbeat.common.adapter;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
import org.springframework.core.Ordered;
@ -22,9 +22,10 @@ public class ChannelTypeAdapter {
/**
* 处理当前数据
*
* @param channelHandlerContext 当前通道上下文
* @param msg 通道数据
*/
public void handler(Channel channel, Object msg) {
public void handler(ChannelHandlerContext channelHandlerContext, Object msg) {
// 升序 处理器
List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedSortedList =
handleChannelTypeAdvancedList.
@ -36,7 +37,7 @@ public class ChannelTypeAdapter {
for (HandleChannelTypeAdvanced handleChannelTypeAdvanced : handleChannelTypeAdvancedSortedList) {
if (handleChannelTypeAdvanced.support(msg)) {
// log.info("处理器:{},客户端:{}, 处理类型:{}",handleChannelTypeAdvanced.getClass(),new String(msg.getClientId()),msg.getMysqlType());
handleChannelTypeAdvanced.handler(channel, msg);
handleChannelTypeAdvanced.handler(channelHandlerContext, msg);
return;
}
}

View File

@ -1,7 +1,7 @@
package org.framework.lazy.cloud.network.heartbeat.common.advanced;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
@ -12,20 +12,20 @@ public abstract class AbstractHandleChannelTypeAdvanced<MSG> implements HandleCh
/**
* 处理当前数据
*
* @param channel 当前通道
* @param channelHandlerContext 当前通道上下文
* @param msg 通道数据
*/
protected abstract void doHandler(Channel channel, MSG msg);
protected abstract void doHandler(ChannelHandlerContext channelHandlerContext, MSG msg);
/**
* 处理当前数据
*
* @param channel 当前通道
* @param channelHandlerContext 当前通道上下文
* @param msg 通道数据
*/
@Override
public void handler(Channel channel, Object msg) {
doHandler(channel, (MSG) msg);
public void handler(ChannelHandlerContext channelHandlerContext, Object msg) {
doHandler(channelHandlerContext, (MSG) msg);
}
/**

View File

@ -1,7 +1,7 @@
package org.framework.lazy.cloud.network.heartbeat.common.advanced;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import org.springframework.core.Ordered;
import org.framework.lazy.cloud.network.heartbeat.common.constant.TcpMessageType;
import org.framework.lazy.cloud.network.heartbeat.common.enums.TcpMessageTypeEnums;
@ -9,19 +9,21 @@ import org.framework.lazy.cloud.network.heartbeat.common.enums.TcpMessageTypeEnu
/**
* 通道不同数据类型处理器
*
*
* @see TcpMessageType
* @see TcpMessageTypeEnums
*/
public interface HandleChannelTypeAdvanced extends Ordered {
/**
* 处理当前数据
*
* @param channel 当前通道
* @param channelHandlerContext 当前通道上下文
* @param msg 通道数据
*/
void handler(Channel channel, Object msg);
void handler(ChannelHandlerContext channelHandlerContext, Object msg);
/**
* 是否支持当前类型

View File

@ -0,0 +1,21 @@
package org.framework.lazy.cloud.network.heartbeat.common.advanced.proxy.socket;
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.ProxyMessageTypeEnums;
public abstract class AbstractHandleSocketLocalProxyTypeAdvanced<MSG> extends AbstractHandleChannelTypeAdvanced<NettyProxyMsg> implements HandleChannelTypeAdvanced {
/**
* 是否支持当前类型
*
* @param nettyProxyMsg 通道数据
* @return 布尔类型 是、否
*/
@Override
protected boolean doSupport(NettyProxyMsg nettyProxyMsg) {
return ProxyMessageTypeEnums.SOCKET_LOCAL_PROXY.getTypeByte() == nettyProxyMsg.getType();
}
}

View File

@ -5,7 +5,8 @@ import org.framework.lazy.cloud.network.heartbeat.common.advanced.proxy.http.Abs
import org.framework.lazy.cloud.network.heartbeat.common.advanced.proxy.http.AbstractHttpLocalProxyTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.proxy.http.client.*;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.proxy.http.server.*;
import org.framework.lazy.cloud.network.heartbeat.common.enums.TcpMessageTypeEnums;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.proxy.socket.AbstractHandleSocketLocalProxyTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.enums.ProxyMessageTypeEnums;
/**
* http代理消息类型
@ -18,14 +19,14 @@ public class ProxyMessageType {
/**
* http 本地代理
*
* @see TcpMessageTypeEnums#HTTP_LOCAL_PROXY
* @see ProxyMessageTypeEnums#HTTP_LOCAL_PROXY
* @see AbstractHttpLocalProxyTypeAdvanced
*/
public static final byte HTTP_LOCAL_PROXY = 96;
/**
* http 远程客户端代理
*
* @see TcpMessageTypeEnums#HTTP_CLIENT_PROXY_CLIENT_
* @see ProxyMessageTypeEnums#HTTP_CLIENT_PROXY_CLIENT_
* @see AbstractHttpClientProxyClientTypeAdvanced
*/
public static final byte HTTP_CLIENT_PROXY_CLIENT_ = HTTP_LOCAL_PROXY + 1;
@ -34,21 +35,21 @@ public class ProxyMessageType {
/**
* http 远程服务端代理
*
* @see TcpMessageTypeEnums#HTTP_CLIENT_PROXY_SERVER_
* @see ProxyMessageTypeEnums#HTTP_CLIENT_PROXY_SERVER_
* @see AbstractHttpClientProxyServerTypeAdvanced
*/
public static final byte HTTP_CLIENT_PROXY_SERVER_ = HTTP_CLIENT_PROXY_CLIENT_ + 1;
/**
* http 远程服务端代理传输数据上报
*
* @see TcpMessageTypeEnums#HTTP_REPORT_CLIENT_PROXY_SERVER_TRANSFER_
* @see ProxyMessageTypeEnums#HTTP_REPORT_CLIENT_PROXY_SERVER_TRANSFER_
* @see AbstractHandleHttpReportClientProxyServerTransferTypeAdvanced
*/
public static final byte HTTP_REPORT_CLIENT_PROXY_SERVER_TRANSFER_ = HTTP_CLIENT_PROXY_SERVER_ + 1;
/**
* http 远程代理服务通道关闭
*
* @see TcpMessageTypeEnums#HTTP_REPORT_CLIENT_PROXY_SERVER_TRANSFER_CLOSE_
* @see ProxyMessageTypeEnums#HTTP_REPORT_CLIENT_PROXY_SERVER_TRANSFER_CLOSE_
* @see AbstractHandleHttpReportClientProxyServerTransferCloseTypeAdvanced
*/
public static final byte HTTP_REPORT_CLIENT_PROXY_SERVER_TRANSFER_CLOSE_ = HTTP_REPORT_CLIENT_PROXY_SERVER_TRANSFER_ + 1;
@ -57,7 +58,7 @@ public class ProxyMessageType {
/**
* http 客户端远程客户端代理传输连接
*
* @see TcpMessageTypeEnums#HTTP_REPORT_CLIENT_PROXY_CLIENT_TRANSFER_CONNECTION_
* @see ProxyMessageTypeEnums#HTTP_REPORT_CLIENT_PROXY_CLIENT_TRANSFER_CONNECTION_
* @see AbstractHandleHttpReportClientProxyClientConnectionTransferTypeAdvanced
*/
public static final byte HTTP_REPORT_CLIENT_PROXY_CLIENT_TRANSFER_CONNECTION_ = HTTP_REPORT_CLIENT_PROXY_SERVER_TRANSFER_CLOSE_ + 1;
@ -66,7 +67,7 @@ public class ProxyMessageType {
/**
* http 目标客户端传输通道连接初始化成功
*
* @see TcpMessageTypeEnums#HTTP_REPORT_CLIENT_PROXY_CLIENT_TRANSFER_CHANNEL_INIT_SUCCESSFUL_
* @see ProxyMessageTypeEnums#HTTP_REPORT_CLIENT_PROXY_CLIENT_TRANSFER_CHANNEL_INIT_SUCCESSFUL_
* @see AbstractHandleHttpReportClientProxyClientTransferChannelInitSuccessfulTypeAdvanced
*/
public static final byte HTTP_REPORT_CLIENT_PROXY_CLIENT_TRANSFER_CHANNEL_INIT_SUCCESSFUL_ = HTTP_REPORT_CLIENT_PROXY_CLIENT_TRANSFER_CONNECTION_ + 1;
@ -75,7 +76,7 @@ public class ProxyMessageType {
/**
* http 另一个客户端将返回数据通过传输通道返回
*
* @see TcpMessageTypeEnums#HTTP_REPORT_CLIENT_PROXY_CLIENT_TRANSFER_RESPONSE_
* @see ProxyMessageTypeEnums#HTTP_REPORT_CLIENT_PROXY_CLIENT_TRANSFER_RESPONSE_
* @see AbstractHandleHttpReportClientProxyClientTransferResponseTypeAdvanced
*/
public static final byte HTTP_REPORT_CLIENT_PROXY_CLIENT_TRANSFER_RESPONSE_ = HTTP_REPORT_CLIENT_PROXY_CLIENT_TRANSFER_CHANNEL_INIT_SUCCESSFUL_ + 1;
@ -83,7 +84,7 @@ public class ProxyMessageType {
/**
* 上报传输通道关闭
*
* @see TcpMessageTypeEnums#HTTP_REPORT_CLIENT_PROXY_CLIENT_TRANSFER_CLOSE_
* @see ProxyMessageTypeEnums#HTTP_REPORT_CLIENT_PROXY_CLIENT_TRANSFER_CLOSE_
* @see AbstractHandleHttpReportClientProxyClientTransferCloseTypeAdvanced
*/
public static final byte HTTP_REPORT_CLIENT_PROXY_CLIENT_TRANSFER_CLOSE_ = HTTP_REPORT_CLIENT_PROXY_CLIENT_TRANSFER_RESPONSE_ + 1;
@ -91,7 +92,7 @@ public class ProxyMessageType {
/**
* http 服务端代理客户端
*
* @see TcpMessageTypeEnums#HTTP_SERVER_PROXY_CLIENT_
* @see ProxyMessageTypeEnums#HTTP_SERVER_PROXY_CLIENT_
* @see AbstractHttpServerProxyClientTypeAdvanced
*/
public static final byte HTTP_SERVER_PROXY_CLIENT_ = HTTP_REPORT_CLIENT_PROXY_CLIENT_TRANSFER_CLOSE_ + 1;
@ -100,7 +101,7 @@ public class ProxyMessageType {
/**
* http 上报客户端连接成功
*
* @see TcpMessageTypeEnums#HTTP_REPORT_SERVER_PROXY_CLIENT_TRANSFER_CHANNEL_INIT_SUCCESSFUL_
* @see ProxyMessageTypeEnums#HTTP_REPORT_SERVER_PROXY_CLIENT_TRANSFER_CHANNEL_INIT_SUCCESSFUL_
* @see AbstractHandleHttpReportServerProxyClientTransferChannelInitSuccessfulTypeAdvanced
*/
public static final byte HTTP_REPORT_SERVER_PROXY_CLIENT_TRANSFER_CHANNEL_INIT_SUCCESSFUL_ = HTTP_SERVER_PROXY_CLIENT_ + 1;
@ -108,14 +109,14 @@ public class ProxyMessageType {
/**
* 下发返回结果
*
* @see TcpMessageTypeEnums#HTTP_REPORT_SERVER_PROXY_CLIENT_TRANSFER_RESPONSE_
* @see ProxyMessageTypeEnums#HTTP_REPORT_SERVER_PROXY_CLIENT_TRANSFER_RESPONSE_
* @see AbstractHandleHttpReportServerProxyClientTransferResponseTypeAdvanced
*/
public static final byte HTTP_REPORT_SERVER_PROXY_CLIENT_TRANSFER_RESPONSE_ = HTTP_REPORT_SERVER_PROXY_CLIENT_TRANSFER_CHANNEL_INIT_SUCCESSFUL_ + 1;
/**
* 上报传输通道关闭
*
* @see TcpMessageTypeEnums#HTTP_REPORT_SERVER_PROXY_CLIENT_TRANSFER_CLOSE_
* @see ProxyMessageTypeEnums#HTTP_REPORT_SERVER_PROXY_CLIENT_TRANSFER_CLOSE_
* @see AbstractHandleHttpReportServerProxyClientTransferCloseTypeAdvanced
*/
public static final byte HTTP_REPORT_SERVER_PROXY_CLIENT_TRANSFER_CLOSE_ = HTTP_REPORT_SERVER_PROXY_CLIENT_TRANSFER_RESPONSE_ + 1;
@ -123,6 +124,39 @@ public class ProxyMessageType {
// #################################################################################################
// socket 代理
/**
* socket 本地代理
*
* @see ProxyMessageTypeEnums#SOCKET_LOCAL_PROXY
* @see AbstractHandleSocketLocalProxyTypeAdvanced
*/
public static final byte SOCKET_LOCAL_PROXY = HTTP_REPORT_SERVER_PROXY_CLIENT_TRANSFER_CLOSE_ + 1;
/**
* socket 客户端代理客户端
*
* @see ProxyMessageTypeEnums#SOCKET_CLIENT_PROXY_CLIENT_
* @see AbstractHandleSocketClientProxyClietnTypeAdvanced
*/
public static final byte SOCKET_CLIENT_PROXY_CLIENT_ = SOCKET_LOCAL_PROXY + 1;
/**
* socket 客户端代理服务端
*
* @see ProxyMessageTypeEnums#SOCKET_CLIENT_PROXY_SERVER_
* @see AbstractHandleSocketClientProxyServerTypeAdvanced
*/
public static final byte SOCKET_CLIENT_PROXY_SERVER_ = SOCKET_CLIENT_PROXY_CLIENT_ + 1;
/**
* socket 服务端代理客户端
*
* @see ProxyMessageTypeEnums#SOCKET_SERVER_PROXY_CLIENT_
* @see AbstractHandleSocketServerProxyClientTypeAdvanced
*/
public static final byte SOCKET_SERVER_PROXY_CLIENT_ = SOCKET_CLIENT_PROXY_SERVER_ + 1;
public static final byte HTTP_DISTRIBUTE_PROXY = -96;
@ -130,7 +164,7 @@ public class ProxyMessageType {
/**
* 下发服务端路由
*
* @see TcpMessageTypeEnums#HTTP_DISTRIBUTE_CLIENT_PROXY_SERVER_SERVER_ROUTE_
* @see ProxyMessageTypeEnums#HTTP_DISTRIBUTE_CLIENT_PROXY_SERVER_SERVER_ROUTE_
* @see AbstractHandleHttpDistributeClientProxyServerServerRouteTypeAdvanced
*/
public static final byte HTTP_DISTRIBUTE_CLIENT_PROXY_SERVER_SERVER_ROUTE_ = HTTP_DISTRIBUTE_PROXY - 1;
@ -139,7 +173,7 @@ public class ProxyMessageType {
/**
* 下发客户端路由
*
* @see TcpMessageTypeEnums#HTTP_DISTRIBUTE_CLIENT_PROXY_SERVER_CLIENT_ROUTE_
* @see ProxyMessageTypeEnums#HTTP_DISTRIBUTE_CLIENT_PROXY_SERVER_CLIENT_ROUTE_
* @see AbstractHandleHttpDistributeClientProxyServerClientRouteTypeAdvanced
*/
public static final byte HTTP_DISTRIBUTE_CLIENT_PROXY_SERVER_CLIENT_ROUTE_ = HTTP_DISTRIBUTE_CLIENT_PROXY_SERVER_SERVER_ROUTE_ - 1;
@ -148,7 +182,7 @@ public class ProxyMessageType {
/**
* http 下发服务端连接客户端
*
* @see TcpMessageTypeEnums#HTTP_DISTRIBUTE_SERVER_PROXY_CLIENT_CONNECTION_SUCCESSFUL_
* @see ProxyMessageTypeEnums#HTTP_DISTRIBUTE_SERVER_PROXY_CLIENT_CONNECTION_SUCCESSFUL_
* @see AbstractHandleHttpDistributeServerProxyClientConnectionSuccessfulTypeAdvanced
*/
public static final byte HTTP_DISTRIBUTE_SERVER_PROXY_CLIENT_CONNECTION_SUCCESSFUL_ = HTTP_DISTRIBUTE_CLIENT_PROXY_SERVER_CLIENT_ROUTE_ - 1;
@ -156,7 +190,7 @@ public class ProxyMessageType {
/**
* http 下发数据到另一个客户端
*
* @see TcpMessageTypeEnums#HTTP_DISTRIBUTE_SERVER_PROXY_CLIENT_TRANSFER_REQUEST_
* @see ProxyMessageTypeEnums#HTTP_DISTRIBUTE_SERVER_PROXY_CLIENT_TRANSFER_REQUEST_
* @see AbstractHandleHttpDistributeServerProxyClientTransferRequestTypeAdvanced
*/
public static final byte HTTP_DISTRIBUTE_SERVER_PROXY_CLIENT_TRANSFER_REQUEST_ = HTTP_DISTRIBUTE_SERVER_PROXY_CLIENT_CONNECTION_SUCCESSFUL_ - 1;
@ -165,7 +199,7 @@ public class ProxyMessageType {
/**
* http 远程服务端代理传输数据下发
*
* @see TcpMessageTypeEnums#HTTP_DISTRIBUTE_CLIENT_PROXY_SERVER_TRANSFER_
* @see ProxyMessageTypeEnums#HTTP_DISTRIBUTE_CLIENT_PROXY_SERVER_TRANSFER_
* @see AbstractHandleHttpDistributeClientProxyServerTransferTypeAdvanced
*/
public static final byte HTTP_DISTRIBUTE_CLIENT_PROXY_SERVER_TRANSFER_ = HTTP_DISTRIBUTE_SERVER_PROXY_CLIENT_TRANSFER_REQUEST_ - 1;
@ -175,7 +209,7 @@ public class ProxyMessageType {
/**
* http 客户端代理客户端,客户端连接服务端成功
*
* @see TcpMessageTypeEnums#HTTP_DISTRIBUTE_CLIENT_PROXY_CLIENT_TRANSFER_CONNECTION_SUCCESSFUL_
* @see ProxyMessageTypeEnums#HTTP_DISTRIBUTE_CLIENT_PROXY_CLIENT_TRANSFER_CONNECTION_SUCCESSFUL_
* @see AbstractHandleHttpDistributeClientProxyClientConnectionTransferSuccessfulTypeAdvanced
*/
public static final byte HTTP_DISTRIBUTE_CLIENT_PROXY_CLIENT_TRANSFER_CONNECTION_SUCCESSFUL_ = HTTP_DISTRIBUTE_CLIENT_PROXY_SERVER_TRANSFER_ - 1;
@ -184,14 +218,14 @@ public class ProxyMessageType {
/**
* 下发返回结果
*
* @see TcpMessageTypeEnums#HTTP_DISTRIBUTE_CLIENT_PROXY_CLIENT_TRANSFER_RESPONSE_
* @see ProxyMessageTypeEnums#HTTP_DISTRIBUTE_CLIENT_PROXY_CLIENT_TRANSFER_RESPONSE_
* @see AbstractHandleHttpDistributeClientProxyClientTransferResponseTypeAdvanced
*/
public static final byte HTTP_DISTRIBUTE_CLIENT_PROXY_CLIENT_TRANSFER_RESPONSE_ = HTTP_DISTRIBUTE_CLIENT_PROXY_CLIENT_TRANSFER_CONNECTION_SUCCESSFUL_ - 1;
/**
* 下发传输通道关闭
*
* @see TcpMessageTypeEnums#HTTP_DISTRIBUTE_CLIENT_PROXY_CLIENT_TRANSFER_CLOSE_
* @see ProxyMessageTypeEnums#HTTP_DISTRIBUTE_CLIENT_PROXY_CLIENT_TRANSFER_CLOSE_
* @see AbstractHandleHttpDistributeClientProxyClientTransferCLoseTypeAdvanced
*/
public static final byte HTTP_DISTRIBUTE_CLIENT_PROXY_CLIENT_TRANSFER_CLOSE_ = HTTP_DISTRIBUTE_CLIENT_PROXY_CLIENT_TRANSFER_RESPONSE_ - 1;
@ -200,7 +234,7 @@ public class ProxyMessageType {
/**
* http 下发数据到另一个客户端
*
* @see TcpMessageTypeEnums#HTTP_DISTRIBUTE_CLIENT_PROXY_CLIENT_TRANSFER_REQUEST_
* @see ProxyMessageTypeEnums#HTTP_DISTRIBUTE_CLIENT_PROXY_CLIENT_TRANSFER_REQUEST_
* @see AbstractHandleHttpDistributeClientProxyClientTransferRequestTypeAdvanced
*/
public static final byte HTTP_DISTRIBUTE_CLIENT_PROXY_CLIENT_TRANSFER_REQUEST_ = HTTP_DISTRIBUTE_CLIENT_PROXY_CLIENT_TRANSFER_CLOSE_ - 1;

View File

@ -10,6 +10,7 @@ import org.framework.lazy.cloud.network.heartbeat.common.advanced.proxy.http.Abs
import org.framework.lazy.cloud.network.heartbeat.common.advanced.proxy.http.AbstractHttpLocalProxyTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.proxy.http.client.*;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.proxy.http.server.*;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.proxy.socket.AbstractHandleSocketLocalProxyTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.constant.ProxyMessageType;
import org.framework.lazy.cloud.network.heartbeat.common.constant.TcpMessageType;
@ -127,7 +128,7 @@ public enum ProxyMessageTypeEnums {
/**
* http 上报客户端连接成功
*
* @see TcpMessageTypeEnums#HTTP_REPORT_SERVER_PROXY_CLIENT_TRANSFER_CHANNEL_INIT_SUCCESSFUL_
* @see ProxyMessageType#HTTP_REPORT_SERVER_PROXY_CLIENT_TRANSFER_CHANNEL_INIT_SUCCESSFUL_
* @see AbstractHandleHttpReportServerProxyClientTransferChannelInitSuccessfulTypeAdvanced
*/
HTTP_REPORT_SERVER_PROXY_CLIENT_TRANSFER_CHANNEL_INIT_SUCCESSFUL_(ProxyMessageType.HTTP_REPORT_SERVER_PROXY_CLIENT_TRANSFER_CHANNEL_INIT_SUCCESSFUL_, "http 上报客户端连接成功"),
@ -150,6 +151,13 @@ public enum ProxyMessageTypeEnums {
HTTP_REPORT_SERVER_PROXY_CLIENT_TRANSFER_CLOSE_(ProxyMessageType.HTTP_REPORT_SERVER_PROXY_CLIENT_TRANSFER_CLOSE_, "http 上报传输通道关闭"),
/**
* socket本地代理
* @see AbstractHandleSocketLocalProxyTypeAdvanced
*/
SOCKET_LOCAL_PROXY(ProxyMessageType.SOCKET_LOCAL_PROXY, "socket本地代理"),
;
private final byte typeByte;

View File

@ -8,6 +8,8 @@ public class EventLoopGroupFactory {
private static final EventLoopGroup bossGroup = new NioEventLoopGroup();
private static final EventLoopGroup workerGroup = new NioEventLoopGroup();
// 客户端工作分组
private static final EventLoopGroup clientWorkGroup = new NioEventLoopGroup();
public static EventLoopGroup createBossGroup(){
return bossGroup;
@ -18,4 +20,7 @@ public class EventLoopGroupFactory {
}
public static EventLoopGroup createClientWorkGroup() {
return clientWorkGroup;
}
}

View File

@ -2,10 +2,7 @@ package org.framework.lazy.cloud.network.heartbeat.protocol.advanced;
import io.netty.bootstrap.Bootstrap;
import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.*;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioSocketChannel;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
@ -26,11 +23,12 @@ public class HttpClientProxyClientProxyTypeAdvanced extends AbstractHttpClientPr
/**
* 处理当前数据
*
* @param channel 当前通道
* @param channelHandlerContext 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
protected void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
Channel channel = channelHandlerContext.channel();
String targetPortString = nettyProxyMsg.getTargetPortString();
String targetIpString = nettyProxyMsg.getTargetIpString();
Bootstrap b = new Bootstrap();
@ -56,7 +54,7 @@ public class HttpClientProxyClientProxyTypeAdvanced extends AbstractHttpClientPr
buf.writeBytes(nettyProxyMsg.getData());
proxyChannel.writeAndFlush(buf);
} else {
channel.close();
channelHandlerContext.close();
}
});
}

View File

@ -2,10 +2,7 @@ package org.framework.lazy.cloud.network.heartbeat.protocol.advanced;
import io.netty.bootstrap.Bootstrap;
import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.*;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioSocketChannel;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
@ -26,14 +23,15 @@ public class HttpProtocolHandleChannelLocalProxyTypeAdvanced extends AbstractHtt
/**
* 处理当前数据
*
* @param channel 当前通道
* @param channelHandlerContext 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
protected void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
String targetPortString = nettyProxyMsg.getTargetPortString();
String targetIpString = nettyProxyMsg.getTargetIpString();
Bootstrap b = new Bootstrap();
Channel channel = channelHandlerContext.channel();
b.group(channel.eventLoop())
.channel(NioSocketChannel.class)
.handler(new ChannelInitializer<SocketChannel>() {

View File

@ -0,0 +1,70 @@
package org.framework.lazy.cloud.network.heartbeat.protocol.advanced;
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.*;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.handler.codec.socksx.v5.DefaultSocks5CommandResponse;
import io.netty.handler.codec.socksx.v5.Socks5AddressType;
import io.netty.handler.codec.socksx.v5.Socks5CommandRequestDecoder;
import io.netty.handler.codec.socksx.v5.Socks5CommandStatus;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.proxy.socket.AbstractHandleSocketLocalProxyTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.factory.EventLoopGroupFactory;
import org.framework.lazy.cloud.network.heartbeat.protocol.handler.NettyClient2DestInboundHandler;
import org.framework.lazy.cloud.network.heartbeat.protocol.handler.NettyDest2ClientInboundHandler;
import org.framework.lazy.cloud.network.heartbeat.protocol.handler.NettySocks5CommandRequestHandler;
import org.springframework.stereotype.Component;
import java.net.InetSocketAddress;
@Slf4j
@Component
public class NettySocketProtocolHandleSocketLocalProxyTypeAdvanced
extends AbstractHandleSocketLocalProxyTypeAdvanced<NettyProxyMsg> {
/**
* 处理当前数据
*
* @param ctx 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
protected void doHandler(ChannelHandlerContext ctx, NettyProxyMsg nettyProxyMsg) {
EventLoopGroup group = EventLoopGroupFactory.createClientWorkGroup();
String host = nettyProxyMsg.getTargetIpString();
Integer port = Integer.parseInt(nettyProxyMsg.getTargetPortString());
Bootstrap b = new Bootstrap();
Socks5AddressType socks5AddressType=Socks5AddressType.IPv4;
b.group(group)
.channel(NioSocketChannel.class)
.option(ChannelOption.TCP_NODELAY, true)
.handler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ch.pipeline().addLast(new NettyDest2ClientInboundHandler(ctx));
}
});
log.info("准备连接目标服务器ip={},port={}", host, port);
ChannelFuture f = b.connect(new InetSocketAddress(host, port));
f.addListener((ChannelFutureListener) future -> {
if (future.isSuccess()) {
log.info("目标服务器连接成功");
//添加客户端转发请求到服务端的Handler
ctx.pipeline().addLast(new NettyClient2DestInboundHandler(future));
DefaultSocks5CommandResponse commandResponse = new DefaultSocks5CommandResponse(Socks5CommandStatus.SUCCESS, socks5AddressType);
ctx.writeAndFlush(commandResponse);
ctx.pipeline().remove(NettySocks5CommandRequestHandler.class);
ctx.pipeline().remove(Socks5CommandRequestDecoder.class);
} else {
log.error("连接目标服务器失败,address={},port={}", host, port);
DefaultSocks5CommandResponse commandResponse = new DefaultSocks5CommandResponse(Socks5CommandStatus.FAILURE, socks5AddressType);
ctx.writeAndFlush(commandResponse);
future.channel().close();
}
});
}
}

View File

@ -1,89 +0,0 @@
package org.framework.lazy.cloud.network.heartbeat.protocol.context;
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.*;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioDatagramChannel;
import jakarta.annotation.PreDestroy;
import lombok.extern.slf4j.Slf4j;
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.context.SocketApplicationListener;
import org.framework.lazy.cloud.network.heartbeat.protocol.handler.NettyUdpProxyHandler;
import org.framework.lazy.cloud.network.heartbeat.protocol.properties.ProtocolProxyProperties;
import org.springframework.stereotype.Component;
import java.util.List;
@Slf4j
@Component
public class NettyUdpProxySocketApplicationListener implements SocketApplicationListener {
private final EventLoopGroup bossGroup = new NioEventLoopGroup();
private ChannelFuture channelFuture;
private final ProtocolProxyProperties protocolProxyProperties;
private final List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList;
public NettyUdpProxySocketApplicationListener(ProtocolProxyProperties protocolProxyProperties,
List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList) {
this.protocolProxyProperties = protocolProxyProperties;
this.handleChannelTypeAdvancedList = handleChannelTypeAdvancedList;
}
/**
* 运行
*
* @throws InterruptedException
*/
@Override
public void doRunning() throws Exception {
try {
ChannelTypeAdapter channelTypeAdapter = new ChannelTypeAdapter(handleChannelTypeAdvancedList);
NettyUdpProxyHandler nettyUdpProxyHandler = new NettyUdpProxyHandler(channelTypeAdapter);// 通道业务处理
ProtocolProxyProperties.UdpProtocolProxy udpProtocolProxy = protocolProxyProperties.getUdpProtocolProxy();
Integer udpProtocolProxyPort = udpProtocolProxy.getPort();
Bootstrap b = new Bootstrap();
b.group(bossGroup)
.channel(NioDatagramChannel.class)
// 给服务端channel设置属性
// 设置读缓冲区为2M
.option(ChannelOption.SO_RCVBUF, 2048 * 1024)
// 设置写缓冲区为1M
.option(ChannelOption.SO_SNDBUF, 1024 * 1024)
.option(ChannelOption.SO_KEEPALIVE, true)
// .childOption(ChannelOption.TCP_NODELAY, false)
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 1000 * 60)//连接超时时间设置为 60 秒
// .childOption(ChannelOption.RCVBUF_ALLOCATOR, new NettyRecvByteBufAllocator(1024 * 1024))//用于Channel分配接受Buffer的分配器 默认AdaptiveRecvByteBufAllocator.DEFAULT
.option(ChannelOption.WRITE_BUFFER_WATER_MARK, new WriteBufferWaterMark(1024 * 1024, 1024 * 1024 * 2))
.handler(nettyUdpProxyHandler);
channelFuture = b.bind(udpProtocolProxyPort).sync();
channelFuture.addListener((ChannelFutureListener) channelFuture -> {
// 服务器已启动
log.info("UDP 协议代理 服务器启动成功【{}】",udpProtocolProxyPort);
});
channelFuture.channel().closeFuture().sync();
} catch (Exception e) {
log.error("启动UDP 协议代理 失败", e);
} finally {
destroy();
// 服务器已关闭
log.warn("UDP 协议代理 服务关闭");
}
}
@PreDestroy
@Override
public void destroy() throws Exception {
if (channelFuture != null) {
channelFuture.channel().close().syncUninterruptibly();
}
if (!bossGroup.isShutdown()) {
bossGroup.shutdownGracefully();
}
}
}

View File

@ -32,7 +32,6 @@ public class NettyHttpProxyFilter extends DebugChannelInitializer<SocketChannel>
// 类型处理器适配器
ChannelTypeAdapter channelTypeAdapter = new ChannelTypeAdapter(handleChannelTypeAdvancedList);
// pipeline.addLast(new HttpClientCodec());
pipeline.addLast(new HttpRequestDecoder());
pipeline.addLast(new HttpObjectAggregator(1048576));
pipeline.addLast("doHandler", new NettyHttpProxyHandler(channelTypeAdapter));// 服务端业务逻辑

View File

@ -1,13 +1,17 @@
package org.framework.lazy.cloud.network.heartbeat.protocol.filter;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpClientCodec;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.socksx.v5.Socks5CommandRequestDecoder;
import io.netty.handler.codec.socksx.v5.Socks5InitialRequestDecoder;
import io.netty.handler.codec.socksx.v5.Socks5ServerEncoder;
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.factory.EventLoopGroupFactory;
import org.framework.lazy.cloud.network.heartbeat.common.filter.DebugChannelInitializer;
import org.framework.lazy.cloud.network.heartbeat.protocol.handler.NettyTcpProxyHandler;
import org.framework.lazy.cloud.network.heartbeat.protocol.handler.NettySocks5CommandRequestHandler;
import org.framework.lazy.cloud.network.heartbeat.protocol.handler.NettySocks5InitialRequestHandler;
import org.springframework.stereotype.Component;
import java.util.List;
@ -31,7 +35,24 @@ public class NettyTcpProxyFilter extends DebugChannelInitializer<SocketChannel>
ChannelPipeline pipeline = ch.pipeline();
// 类型处理器适配器
ChannelTypeAdapter channelTypeAdapter = new ChannelTypeAdapter(handleChannelTypeAdvancedList);
pipeline.addLast("doHandler", new NettyTcpProxyHandler(channelTypeAdapter));// 服务端业务逻辑
//socks5响应最后一个encode
pipeline.addLast(Socks5ServerEncoder.DEFAULT);
// 初始化连接
pipeline.addLast(new Socks5InitialRequestDecoder());
pipeline.addLast(new NettySocks5InitialRequestHandler());
// 认证
// ch.pipeline().addLast(new Socks5PasswordAuthRequestDecoder());
// ch.pipeline().addLast(new Socks5PasswordAuthRequestInboundHandler());
EventLoopGroup clientWorkGroup = EventLoopGroupFactory.createClientWorkGroup();
// 连接请求
pipeline.addLast(new Socks5CommandRequestDecoder());
pipeline.addLast(new NettySocks5CommandRequestHandler(channelTypeAdapter));

View File

@ -0,0 +1,53 @@
package org.framework.lazy.cloud.network.heartbeat.protocol.handler;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.util.ReferenceCountUtil;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class NettyClient2DestInboundHandler extends ChannelInboundHandlerAdapter {
private final ChannelFuture dstChannelFuture;
public NettyClient2DestInboundHandler(ChannelFuture dstChannelFuture) {
this.dstChannelFuture = dstChannelFuture;
}
@Override
public void channelActive(ChannelHandlerContext ctx) {
ctx.writeAndFlush(Unpooled.EMPTY_BUFFER);
}
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
log.info("转发客户端的请求到代理服务器");
if (dstChannelFuture.channel().isActive()) {
dstChannelFuture.channel().writeAndFlush(msg);
} else {
log.info("释放内存");
ReferenceCountUtil.release(msg);
}
}
@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
log.info("客户端与代理服务器的连接已经断开,即将断开代理服务器和目标服务器的连接");
if (dstChannelFuture.channel().isActive()) {
if (ctx.channel().isActive()) {
ctx.channel().writeAndFlush(Unpooled.EMPTY_BUFFER).addListener(ChannelFutureListener.CLOSE);
}
}
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
log.error("NettyClient2DestInboundHandler exception", cause);
ctx.close();
}
}

View File

@ -0,0 +1,49 @@
package org.framework.lazy.cloud.network.heartbeat.protocol.handler;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.util.ReferenceCountUtil;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class NettyDest2ClientInboundHandler extends ChannelInboundHandlerAdapter {
private final ChannelHandlerContext clientChannelHandlerContext;
public NettyDest2ClientInboundHandler(ChannelHandlerContext clientChannelHandlerContext) {
this.clientChannelHandlerContext = clientChannelHandlerContext;
}
@Override
public void channelActive(ChannelHandlerContext ctx) {
ctx.writeAndFlush(Unpooled.EMPTY_BUFFER);
}
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
log.trace("开始写回客户端数据");
if (clientChannelHandlerContext.channel().isActive()) {
clientChannelHandlerContext.writeAndFlush(msg);
} else {
log.info("释放内存");
ReferenceCountUtil.release(msg);
}
}
@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
log.trace("代理服务器和目标服务器的连接已经断开,即将断开客户端和代理服务器的连接");
if (clientChannelHandlerContext.channel().isActive()) {
clientChannelHandlerContext.channel().writeAndFlush(Unpooled.EMPTY_BUFFER).addListener(ChannelFutureListener.CLOSE);
}
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
log.error("NettyDest2ClientInboundHandler exception", cause);
ctx.close();
}
}

View File

@ -106,7 +106,7 @@ public class NettyHttpProxyHandler extends ChannelInboundHandlerAdapter {
proxyMsg.setType(ProxyMessageType.HTTP_SERVER_PROXY_CLIENT_);
}
}
channelTypeAdapter.handler(ctx.channel(), proxyMsg);
channelTypeAdapter.handler(ctx, proxyMsg);
// 判断是否被路由
} else {

View File

@ -0,0 +1,93 @@
package org.framework.lazy.cloud.network.heartbeat.protocol.handler;
import io.netty.channel.*;
import io.netty.channel.socket.nio.NioDatagramChannel;
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.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelTypeAdapter;
import org.framework.lazy.cloud.network.heartbeat.common.constant.ProxyMessageType;
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
import org.framework.lazy.cloud.network.heartbeat.protocol.route.ClientProxyRoute;
import org.framework.lazy.cloud.network.heartbeat.protocol.route.ProxyRoute;
import org.framework.lazy.cloud.network.heartbeat.protocol.route.RouteContext;
import org.framework.lazy.cloud.network.heartbeat.protocol.route.RouteType;
import org.wu.framework.core.utils.ObjectUtils;
import java.util.UUID;
@Slf4j
public class NettySocks5CommandRequestHandler extends SimpleChannelInboundHandler<Socks5CommandRequest> {
private final ChannelTypeAdapter channelTypeAdapter;
public NettySocks5CommandRequestHandler(ChannelTypeAdapter channelTypeAdapter) {
this.channelTypeAdapter = channelTypeAdapter;
}
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
Channel channel = ctx.channel();
if (channel instanceof NioSocketChannel) {
System.out.println("这是一个TCP通道");
} else if (channel instanceof NioDatagramChannel) {
System.out.println("这是一个UDP通道");
} else {
System.out.println("未知类型的通道");
}
String visitorId = UUID.randomUUID().toString();
ChannelAttributeKeyUtils.buildVisitorId(channel, visitorId);
super.channelActive(ctx);
}
@Override
protected void channelRead0(ChannelHandlerContext ctx, Socks5CommandRequest request) throws Exception {
if (request.type() == Socks5CommandType.CONNECT) {
String host = request.dstAddr();
int port = request.dstPort();
Socks5AddressType socks5AddressType = request.dstAddrType();
String visitorId = ChannelAttributeKeyUtils.getVisitorId(ctx.channel());
NettyProxyMsg proxyMsg = new NettyProxyMsg();
proxyMsg.setVisitorId(visitorId);
proxyMsg.setClientTargetIp(host);
proxyMsg.setClientTargetPort(port);
ProxyRoute route = RouteContext.getRoute(host, String.valueOf(port));
if(ObjectUtils.isEmpty(route)){
proxyMsg.setType(ProxyMessageType.SOCKET_LOCAL_PROXY);
}else {
if(RouteType.LOCAL.equals(route.getRouteType())){
proxyMsg.setType(ProxyMessageType.SOCKET_LOCAL_PROXY);
}else if (RouteType.CLIENT_PROXY_CLIENT.equals(route.getRouteType())){
ClientProxyRoute clientProxyRoute= (ClientProxyRoute) route;
String clientId = clientProxyRoute.getClientId();
proxyMsg.setClientId(clientId);
proxyMsg.setType(ProxyMessageType.SOCKET_CLIENT_PROXY_CLIENT_);
}else if (RouteType.CLIENT_PROXY_SEVER.equals(route.getRouteType())){
proxyMsg.setType(ProxyMessageType.SOCKET_CLIENT_PROXY_SERVER_);
}else if (RouteType.SERVER_PROXY_CLIENT.equals(route.getRouteType())){
ClientProxyRoute clientProxyRoute= (ClientProxyRoute) route;
String clientId = clientProxyRoute.getClientId();
proxyMsg.setClientId(clientId);
proxyMsg.setType(ProxyMessageType.SOCKET_SERVER_PROXY_CLIENT_);
}
}
channelTypeAdapter.handler(ctx, proxyMsg);
} else {
log.info("receive commandRequest type={}", request.type());
ReferenceCountUtil.retain(request);
ctx.fireChannelRead(request);
}
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
cause.printStackTrace();
ctx.close();
}
}

View File

@ -0,0 +1,34 @@
package org.framework.lazy.cloud.network.heartbeat.protocol.handler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.codec.socksx.v5.*;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class NettySocks5InitialRequestHandler extends SimpleChannelInboundHandler<Socks5InitialRequest> {
@Override
protected void channelRead0(ChannelHandlerContext ctx, Socks5InitialRequest msg) throws Exception {
boolean failure = msg.decoderResult().isFailure();
if (failure) {
log.error("初始化socks5失败请检查是否是socks5协议");
// ReferenceCountUtil.retain(msg);
ctx.fireChannelRead(msg);
return;
}
log.info("初始化socket连接");
// 不验证账号密码
Socks5InitialResponse socks5InitialResponse = new DefaultSocks5InitialResponse(Socks5AuthMethod.NO_AUTH);
ctx.writeAndFlush(socks5InitialResponse);
ctx.pipeline().remove(this);
ctx.pipeline().remove(Socks5InitialRequestDecoder.class);
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
cause.printStackTrace();
ctx.close();
}
}

View File

@ -1,31 +0,0 @@
package org.framework.lazy.cloud.network.heartbeat.protocol.handler;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.channel.socket.DatagramPacket;
import java.net.InetSocketAddress;
public class NettyUdpProxyBackendHandler extends SimpleChannelInboundHandler<DatagramPacket> {
private final Channel inboundChannel;
private final InetSocketAddress clientAddress;
public NettyUdpProxyBackendHandler(Channel inboundChannel, InetSocketAddress clientAddress) {
this.inboundChannel = inboundChannel;
this.clientAddress = clientAddress;
}
@Override
protected void channelRead0(ChannelHandlerContext ctx, DatagramPacket packet) throws Exception {
inboundChannel.writeAndFlush(new DatagramPacket(packet.content().retain(), clientAddress));
ctx.channel().close();
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
cause.printStackTrace();
ctx.close();
}
}

View File

@ -1,46 +0,0 @@
package org.framework.lazy.cloud.network.heartbeat.protocol.handler;
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.channel.socket.DatagramPacket;
import io.netty.channel.socket.nio.NioDatagramChannel;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelTypeAdapter;
import java.net.InetSocketAddress;
/**
* description 服务端数据处理器
*
* @author 吴佳伟
* @date 2023/09/13 10:27
*/
@Slf4j
public class NettyUdpProxyHandler extends SimpleChannelInboundHandler<DatagramPacket> {
private final ChannelTypeAdapter channelTypeAdapter;
private InetSocketAddress targetAddress = new InetSocketAddress("example.com", 80);
public NettyUdpProxyHandler(ChannelTypeAdapter channelTypeAdapter) {
this.channelTypeAdapter = channelTypeAdapter;
}
@Override
protected void channelRead0(ChannelHandlerContext ctx, DatagramPacket packet) throws Exception {
Bootstrap b = new Bootstrap();
b.group(ctx.channel().eventLoop())
.channel(NioDatagramChannel.class)
.handler(new NettyUdpProxyBackendHandler(ctx.channel(), packet.sender()));
Channel channel = b.bind(0).sync().channel();
channel.writeAndFlush(new DatagramPacket(packet.content().retain(), targetAddress));
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
cause.printStackTrace();
ctx.close();
}
}

View File

@ -4,7 +4,6 @@ package org.framework.lazy.cloud.network.heartbeat.protocol.init;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.protocol.context.NettyHttpProxySocketApplicationListener;
import org.framework.lazy.cloud.network.heartbeat.protocol.context.NettyTcpProxySocketApplicationListener;
import org.framework.lazy.cloud.network.heartbeat.protocol.context.NettyUdpProxySocketApplicationListener;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
@ -18,8 +17,7 @@ import org.springframework.context.annotation.Import;
@Slf4j
@Configuration
@Import({NettyHttpProxySocketApplicationListener.class,
NettyTcpProxySocketApplicationListener.class,
NettyUdpProxySocketApplicationListener.class})
NettyTcpProxySocketApplicationListener.class})
public class InitProtocolProxySocket {

View File

@ -1,6 +1,5 @@
package org.framework.lazy.cloud.network.heartbeat.protocol.socket5;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext;

View File

@ -1,7 +1,7 @@
package org.framework.lazy.cloud.network.heartbeat.server.netty.permeate.tcp.advanced;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.tcp.AbstractTcpHandleChannelHeartbeatTypeAdvanced;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Role;
@ -21,14 +21,14 @@ public class ServerHandleTcpChannelHeartbeatTypeAdvanced extends AbstractTcpHand
/**
* 处理当前数据
*
* @param channel 当前通道
* @param channelHandlerContext 当前通道
* @param msg 通道数据
*/
@Override
public void doHandler(Channel channel, NettyProxyMsg msg) {
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg msg) {
NettyProxyMsg hb = new NettyProxyMsg();
hb.setType(TcpMessageType.TCP_TYPE_HEARTBEAT);
channel.writeAndFlush(hb);
channelHandlerContext.writeAndFlush(hb);
}

View File

@ -3,6 +3,7 @@ package org.framework.lazy.cloud.network.heartbeat.server.netty.permeate.tcp.adv
import com.alibaba.fastjson.JSON;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.ChannelContext;
import org.framework.lazy.cloud.network.heartbeat.common.constant.ProxyMessageType;
@ -71,13 +72,13 @@ public class ServerHandleTcpClientConnectSuccessTypeAdvanced extends AbstractHan
/**
* 处理当前数据
*
* @param newChannel 当前通道
* @param channelHandlerContext 当前通道
* @param msg 通道数据
*/
@Override
public void doHandler(Channel newChannel, NettyProxyMsg msg) {
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg msg) {
Channel newChannel = channelHandlerContext.channel();
String clientId = msg.getClientIdString();
String appKey = msg.getAppKeyString();
String appSecret = msg.getAppSecretString();
@ -136,7 +137,7 @@ public class ServerHandleTcpClientConnectSuccessTypeAdvanced extends AbstractHan
}else {
// 关闭通道
log.warn("无法认证客户端:【{}】",clientId);
newChannel.close();
channelHandlerContext.close();
}
@ -161,7 +162,7 @@ public class ServerHandleTcpClientConnectSuccessTypeAdvanced extends AbstractHan
nettyMsg.setClientTargetIp(permeateTargetIp);
nettyMsg.setClientTargetPort(permeateTargetPort);
nettyMsg.setVisitorPort(visitorPort);
newChannel.writeAndFlush(nettyMsg);
channelHandlerContext.writeAndFlush(nettyMsg);
}
});
@ -185,7 +186,7 @@ public class ServerHandleTcpClientConnectSuccessTypeAdvanced extends AbstractHan
nettyMsg.setVisitorPort(visitorPort);
nettyMsg.setClientId(clientId);
nettyMsg.setData(toClientId.getBytes(StandardCharsets.UTF_8));
newChannel.writeAndFlush(nettyMsg);
channelHandlerContext.writeAndFlush(nettyMsg);
}
});
// 下发服务端路由
@ -205,7 +206,7 @@ public class ServerHandleTcpClientConnectSuccessTypeAdvanced extends AbstractHan
nettyMsg.setType(ProxyMessageType.HTTP_DISTRIBUTE_CLIENT_PROXY_SERVER_SERVER_ROUTE_);
nettyMsg.setData((JSON.toJSONString(serverProxyRoute)
.getBytes(StandardCharsets.UTF_8)));
newChannel.writeAndFlush(nettyMsg);
channelHandlerContext.writeAndFlush(nettyMsg);
}
});
@ -228,7 +229,7 @@ public class ServerHandleTcpClientConnectSuccessTypeAdvanced extends AbstractHan
nettyMsg.setType(ProxyMessageType.HTTP_DISTRIBUTE_CLIENT_PROXY_SERVER_CLIENT_ROUTE_);
nettyMsg.setData((JSON.toJSONString(clientProxyRoute)
.getBytes(StandardCharsets.UTF_8)));
newChannel.writeAndFlush(nettyMsg);
channelHandlerContext.writeAndFlush(nettyMsg);
}
});

View File

@ -1,6 +1,7 @@
package org.framework.lazy.cloud.network.heartbeat.server.netty.permeate.tcp.advanced;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.tcp.server.AbstractHandleTcpReportClientPermeateClientCloseTypeAdvanced;
@ -21,12 +22,13 @@ public class ServerHandleTcpReportClientPermeateClientCloseTypeAdvanced extends
/**
* 处理当前数据
*
* @param channel 当前通道
* @param channelHandlerContext 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
protected void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
// 关闭 next、next transfer 通道
Channel channel = channelHandlerContext.channel();
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
Channel transferNextChannel = ChannelAttributeKeyUtils.getTransferNextChannel(channel);

View File

@ -1,6 +1,7 @@
package org.framework.lazy.cloud.network.heartbeat.server.netty.permeate.tcp.advanced;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.constant.TcpMessageType;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
@ -22,13 +23,13 @@ public class ServerHandleTcpReportClientPermeateClientTransferCloseTypeAdvanced
/**
* 处理当前数据
*
* @param channel 当前通道
* @param channelHandlerContext 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
protected void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
// 关闭 next、next transfer 通道
Channel channel = channelHandlerContext.channel();
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
Channel transferNextChannel = ChannelAttributeKeyUtils.getTransferNextChannel(channel);

View File

@ -1,6 +1,7 @@
package org.framework.lazy.cloud.network.heartbeat.server.netty.permeate.tcp.advanced;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.tcp.server.AbstractHandleTcpReportClientPermeateServerTransferCloseTypeAdvanced;
@ -19,11 +20,12 @@ public class ServerHandleTcpReportClientPermeateServerTransferCloseTypeAdvanced
/**
* 处理当前数据
*
* @param channel 当前通道
* @param channelHandlerContext 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
protected void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
Channel channel = channelHandlerContext.channel();
// 关闭传输通信通道
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
nextChannel.close();

View File

@ -3,6 +3,7 @@ package org.framework.lazy.cloud.network.heartbeat.server.netty.permeate.tcp.adv
import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelFlowAdapter;
@ -31,11 +32,12 @@ public class ServerHandleTcpReportClientPermeateServerTransferTypeAdvanced exten
/**
* 处理当前数据
*
* @param channel 当前通道
* @param channelHandlerContext 当前通道
* @param msg 通道数据
*/
@Override
protected void doHandler(Channel channel, NettyProxyMsg msg) {
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg msg) {
Channel channel = channelHandlerContext.channel();
String clientId = new String(msg.getClientId());
Integer visitorPort = Integer.valueOf(new String(msg.getVisitorPort()));
byte[] visitorId = msg.getVisitorId();

View File

@ -1,6 +1,7 @@
package org.framework.lazy.cloud.network.heartbeat.server.netty.permeate.tcp.advanced;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.*;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.tcp.server.AbstractHandleTcpReportClientTransferClientPermeateChannelConnectionSuccessfulTypeAdvanced;
@ -20,11 +21,12 @@ public class ServerHandleTcpReportClientTransferClientPermeateChannelConnectionS
/**
* 处理当前数据
*
* @param transferChannel 当前通道
* @param channelHandlerContext 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
protected void doHandler(Channel transferChannel, NettyProxyMsg nettyProxyMsg) {
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
Channel transferChannel = channelHandlerContext.channel();
// 创建目标地址连接
byte[] msgVisitorId = nettyProxyMsg.getVisitorId();
byte[] msgVisitorPort = nettyProxyMsg.getVisitorPort();

Some files were not shown because too many files have changed in this diff Show More