【fix】修复无法启动问题

This commit is contained in:
wujiawei
2025-04-30 16:02:07 +08:00
parent f2a22c177e
commit 9dc36fe8e9
40 changed files with 156 additions and 116 deletions

View File

@ -65,21 +65,21 @@ public class ServerHandleUdpClientConnectSuccessTypeAdvanced extends AbstractHan
*/
@Override
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg msg) {
Channel newChannel = channelHandlerContext.channel();
String clientId = msg.getClientIdString();
String appKey = msg.getAppKeyString();
String appSecret = msg.getAppSecretString();
String originalIp = msg.getOriginalIpString();
ChannelContext.push(channelHandlerContext, clientId);
ChannelContext.push(newChannel, clientId);
ChannelAttributeKeyUtils.buildClientId(channelHandlerContext, clientId);
ChannelAttributeKeyUtils.buildAppKey(channelHandlerContext, appKey);
ChannelAttributeKeyUtils.buildAppSecret(channelHandlerContext, appSecret);
ChannelAttributeKeyUtils.buildOriginalIp(channelHandlerContext, originalIp);
ChannelAttributeKeyUtils.buildClientId(newChannel, clientId);
ChannelAttributeKeyUtils.buildAppKey(newChannel, appKey);
ChannelAttributeKeyUtils.buildAppSecret(newChannel, appSecret);
ChannelAttributeKeyUtils.buildOriginalIp(newChannel, originalIp);
// 客户端:{}IP:{}连接成功
log.info("Client: {}, IP: {} Connection successful", new String(msg.getClientId()), channelHandlerContext.remoteAddress().toString());
log.info("Client: {}, IP: {} Connection successful", new String(msg.getClientId()), newChannel.remoteAddress().toString());
// 验证客户端是否时黑名单
LazyNettyClientBlacklist lazyNettyClientBlacklist = new LazyNettyClientBlacklist();
lazyNettyClientBlacklist.setClientId(clientId);
@ -125,7 +125,7 @@ public class ServerHandleUdpClientConnectSuccessTypeAdvanced extends AbstractHan
}else {
// 关闭通道
log.warn("无法认证客户端:【{}】",clientId);
channelHandlerContext.close();
newChannel.close();
}
@ -150,7 +150,7 @@ public class ServerHandleUdpClientConnectSuccessTypeAdvanced extends AbstractHan
nettyMsg.setClientTargetIp(permeateTargetIp);
nettyMsg.setClientTargetPort(permeateTargetPort);
nettyMsg.setVisitorPort(visitorPort);
channelHandlerContext.writeAndFlush(nettyMsg);
newChannel.writeAndFlush(nettyMsg);
}
});
@ -174,7 +174,7 @@ public class ServerHandleUdpClientConnectSuccessTypeAdvanced extends AbstractHan
nettyMsg.setVisitorPort(visitorPort);
nettyMsg.setClientId(clientId);
nettyMsg.setData(toClientId.getBytes(StandardCharsets.UTF_8));
channelHandlerContext.writeAndFlush(nettyMsg);
newChannel.writeAndFlush(nettyMsg);
}
});

View File

@ -28,10 +28,10 @@ public class ServerHandleUdpReportClientPermeateClientCloseTypeAdvanced extends
@Override
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
// 关闭 next、next transfer 通道
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channelHandlerContext);
Channel transferNextChannel = ChannelAttributeKeyUtils.getTransferNextChannel(channelHandlerContext);
channelHandlerContext.close();
Channel channel = channelHandlerContext.channel();
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
Channel transferNextChannel = ChannelAttributeKeyUtils.getTransferNextChannel(channel);
channel.close();
nextChannel.close();
transferNextChannel.close();
}

View File

@ -29,16 +29,16 @@ public class ServerHandleUdpReportClientPermeateClientTransferCloseTypeAdvanced
@Override
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
// 关闭 next、next transfer 通道
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channelHandlerContext);
Channel transferNextChannel = ChannelAttributeKeyUtils.getTransferNextChannel(channelHandlerContext);
Channel channel = channelHandlerContext.channel();
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
Channel transferNextChannel = ChannelAttributeKeyUtils.getTransferNextChannel(channel);
// 下发关闭客户端真实通道
NettyProxyMsg closeTransferNettyProxyMsg = new NettyProxyMsg();
closeTransferNettyProxyMsg.setType(TcpMessageType.TCP_DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_CLOSE);
transferNextChannel.writeAndFlush(closeTransferNettyProxyMsg);
channelHandlerContext.close();
channel.close();
nextChannel.close();
transferNextChannel.close();
}

View File

@ -25,9 +25,10 @@ public class ServerHandleUdpReportClientPermeateServerTransferCloseTypeAdvanced
*/
@Override
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
Channel channel = channelHandlerContext.channel();
// 关闭传输通信通道
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channelHandlerContext);
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
nextChannel.close();
channelHandlerContext.close();
channel.close();
}
}

View File

@ -37,6 +37,7 @@ public class ServerHandleUdpReportClientPermeateServerTransferTypeAdvanced exten
*/
@Override
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();
@ -44,7 +45,7 @@ public class ServerHandleUdpReportClientPermeateServerTransferTypeAdvanced exten
log.debug("【客户端渗透服务端】访客ID:【{}】接收到客户端:[{}] 接收服务端数据大小:[{}] 接收服务端数据:[{}]", new String(visitorId), clientId, msg.getData().length, new String(msg.getData()));
// 将数据转发访客通道
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channelHandlerContext);
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
if (nextChannel != null) {
ByteBuf buf = nextChannel.config().getAllocator().buffer(msg.getData().length);
buf.writeBytes(msg.getData());
@ -59,7 +60,7 @@ public class ServerHandleUdpReportClientPermeateServerTransferTypeAdvanced exten
.clientId(clientId)
.flow(msg.getData().length)
.build();
channelFlowAdapter.asyncHandler(channelHandlerContext, serverChannelFlow);
channelFlowAdapter.asyncHandler(channel, serverChannelFlow);
}
log.debug("客户端渗透服务端】访客ID:【{}】接收到客户端:[{}] 传输真实数据成功", new String(visitorId), clientId);
}

View File

@ -28,6 +28,7 @@ public class ServerHandleUdpReportClientTransferClientPermeateChannelConnectionS
*/
@Override
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
Channel channel = channelHandlerContext.channel();
// 创建目标地址连接
byte[] msgVisitorId = nettyProxyMsg.getVisitorId();
byte[] msgVisitorPort = nettyProxyMsg.getVisitorPort();
@ -35,11 +36,11 @@ public class ServerHandleUdpReportClientTransferClientPermeateChannelConnectionS
byte[] msgClientTargetPort = nettyProxyMsg.getClientTargetPort();
byte[] clientId = nettyProxyMsg.getClientId();// 目标客户端ID
ChannelAttributeKeyUtils.buildClientId(channelHandlerContext, clientId);
ChannelAttributeKeyUtils.buildVisitorPort(channelHandlerContext, Integer.parseInt(new String(msgVisitorPort)));
ChannelAttributeKeyUtils.buildVisitorId(channelHandlerContext, msgVisitorId);
ChannelAttributeKeyUtils.buildClientId(channel, clientId);
ChannelAttributeKeyUtils.buildVisitorPort(channel, Integer.parseInt(new String(msgVisitorPort)));
ChannelAttributeKeyUtils.buildVisitorId(channel, msgVisitorId);
// 绑定访客通道
NettyTransferChannelContext.pushVisitor(channelHandlerContext,msgVisitorId);
NettyTransferChannelContext.pushVisitor(channel,msgVisitorId);
Channel clientChannel = ChannelContext.getLoadBalance(clientId);
NettyProxyMsg clientConnectTagetNettyProxyMsg = new NettyProxyMsg();

View File

@ -27,6 +27,7 @@ public class ServerHandleUdpReportClientTransferClientPermeateChannelInitSuccess
*/
@Override
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
Channel channel = channelHandlerContext.channel();
// 创建目标地址连接
byte[] msgVisitorId = nettyProxyMsg.getVisitorId();
byte[] msgVisitorPort = nettyProxyMsg.getVisitorPort();
@ -34,15 +35,15 @@ public class ServerHandleUdpReportClientTransferClientPermeateChannelInitSuccess
byte[] msgClientTargetPort = nettyProxyMsg.getClientTargetPort();
byte[] clientId = nettyProxyMsg.getClientId();
ChannelAttributeKeyUtils.buildVisitorPort(channelHandlerContext, Integer.parseInt(new String(msgVisitorPort)));
ChannelAttributeKeyUtils.buildVisitorPort(channel, Integer.parseInt(new String(msgVisitorPort)));
// next translation
Channel nextTransferChannel = NettyTransferChannelContext.getVisitor(msgVisitorId);
ChannelAttributeKeyUtils.buildTransferNextChannel(nextTransferChannel, channelHandlerContext);
ChannelAttributeKeyUtils.buildTransferNextChannel(channelHandlerContext,nextTransferChannel);
ChannelAttributeKeyUtils.buildClientId(channelHandlerContext,clientId);
ChannelAttributeKeyUtils.buildVisitorId(channelHandlerContext,msgVisitorId);
ChannelAttributeKeyUtils.buildTransferNextChannel(nextTransferChannel, channel);
ChannelAttributeKeyUtils.buildTransferNextChannel(channel,nextTransferChannel);
ChannelAttributeKeyUtils.buildClientId(channel,clientId);
ChannelAttributeKeyUtils.buildVisitorId(channel,msgVisitorId);
Channel nextChannel = ChannelAttributeKeyUtils.getTransferNextChannel(channelHandlerContext);
Channel nextChannel = ChannelAttributeKeyUtils.getTransferNextChannel(channel);
NettyProxyMsg clientConnectTagetNettyProxyMsg = new NettyProxyMsg();
clientConnectTagetNettyProxyMsg.setVisitorId(msgVisitorId);

View File

@ -30,6 +30,9 @@ public class ServerHandleUdpReportClientTransferClientResponseTypeAdvanced exten
*/
@Override
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
Channel channel = channelHandlerContext.channel();
// 创建目标地址连接
byte[] msgVisitorId = nettyProxyMsg.getVisitorId();
byte[] msgVisitorPort = nettyProxyMsg.getVisitorPort();
@ -37,7 +40,7 @@ public class ServerHandleUdpReportClientTransferClientResponseTypeAdvanced exten
byte[] msgClientTargetPort = nettyProxyMsg.getClientTargetPort();
String clientId = nettyProxyMsg.getClientIdString();
// 下发客户端初始化成功
Channel nextChannel = ChannelAttributeKeyUtils.getTransferNextChannel(channelHandlerContext);
Channel nextChannel = ChannelAttributeKeyUtils.getTransferNextChannel(channel);
NettyProxyMsg clientConnectTagetNettyProxyMsg = new NettyProxyMsg();
@ -61,7 +64,7 @@ public class ServerHandleUdpReportClientTransferClientResponseTypeAdvanced exten
.flow(clientConnectTagetNettyProxyMsg.getData().length)
.build();
channelFlowAdapter.asyncHandler(channelHandlerContext, serverChannelFlow);
channelFlowAdapter.asyncHandler(channel, serverChannelFlow);
}else {
log.error("can not find the client:【{}】 channelHandlerContext",clientId);
}

View File

@ -30,6 +30,7 @@ public class ServerHandleUdpReportClientTransferClientTypeAdvanced extends Abstr
*/
@Override
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
Channel channel = channelHandlerContext.channel();
// 创建目标地址连接
byte[] msgVisitorId = nettyProxyMsg.getVisitorId();
byte[] msgVisitorPort = nettyProxyMsg.getVisitorPort();
@ -37,8 +38,8 @@ public class ServerHandleUdpReportClientTransferClientTypeAdvanced extends Abstr
byte[] msgClientTargetPort = nettyProxyMsg.getClientTargetPort();
String clientId = nettyProxyMsg.getClientIdString();
// 下发客户端初始化成功
Channel nextChannel = ChannelAttributeKeyUtils.getTransferNextChannel(channelHandlerContext);
Integer visitorPort = ChannelAttributeKeyUtils.getVisitorPort(channelHandlerContext);
Channel nextChannel = ChannelAttributeKeyUtils.getTransferNextChannel(channel);
Integer visitorPort = ChannelAttributeKeyUtils.getVisitorPort(channel);
NettyProxyMsg clientConnectTagetNettyProxyMsg = new NettyProxyMsg();
@ -60,7 +61,7 @@ public class ServerHandleUdpReportClientTransferClientTypeAdvanced extends Abstr
.clientId(clientId)
.flow(clientConnectTagetNettyProxyMsg.getData().length)
.build();
channelFlowAdapter.asyncHandler(channelHandlerContext, serverChannelFlow);
channelFlowAdapter.asyncHandler(channel, serverChannelFlow);
}else {
log.error("can not find the client:【{}】 channelHandlerContext",clientId);
}

View File

@ -1,5 +1,6 @@
package org.framework.lazy.cloud.network.heartbeat.server.netty.permeate.udp.advanced;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.udp.server.AbstractHandleUdpReportClientTransferServerPermeateChannelConnectionSuccessfulTypeAdvanced;
@ -23,6 +24,7 @@ public class ServerHandleUdpReportClientTransferServerPermeateChannelConnectionS
*/
@Override
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
Channel channel = channelHandlerContext.channel();
// 创建目标地址连接
byte[] msgVisitorId = nettyProxyMsg.getVisitorId();
byte[] msgVisitorPort = nettyProxyMsg.getVisitorPort();
@ -31,13 +33,13 @@ public class ServerHandleUdpReportClientTransferServerPermeateChannelConnectionS
byte[] msgClientId = nettyProxyMsg.getClientId();
String clientId = new String(msgClientId);
// 绑定客户端ID
ChannelAttributeKeyUtils.buildClientId(channelHandlerContext,clientId);
ChannelAttributeKeyUtils.buildVisitorId(channelHandlerContext,msgVisitorId);
ChannelAttributeKeyUtils.buildClientId(channel,clientId);
ChannelAttributeKeyUtils.buildVisitorId(channel,msgVisitorId);
NettyUdpClientPermeateServerConnectRealSocket.buildNewRealServer(new String(msgVisitorId),
Integer.parseInt(new String(msgVisitorPort)),
new String(msgClientTargetIp),
Integer.parseInt(new String(msgClientTargetPort)),
channelHandlerContext
channel
);

View File

@ -44,13 +44,14 @@ public class ServerHandleUdpReportDisconnectTypeAdvanced extends AbstractHandleU
*/
@Override
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg msg) {
Channel deathChannel = channelHandlerContext.channel();
// 关闭连接通知
String clientId = msg.getClientIdString();
log.warn("close client :{} channel", clientId);
Channel deathClientChannelDTO = ChannelContext.getLoadBalance(clientId);
String appKey = ChannelAttributeKeyUtils.getAppKey(channelHandlerContext);
String appSecret = ChannelAttributeKeyUtils.getAppSecret(channelHandlerContext);
String originalIp = ChannelAttributeKeyUtils.getOriginalIp(channelHandlerContext);
String appKey = ChannelAttributeKeyUtils.getAppKey(deathChannel);
String appSecret = ChannelAttributeKeyUtils.getAppSecret(deathChannel);
String originalIp = ChannelAttributeKeyUtils.getOriginalIp(deathChannel);
if (deathClientChannelDTO != null) {
// 服务状态离线

View File

@ -29,6 +29,7 @@ public class ServerHandleUdpReportServicePermeateClientRealConnectTypeAdvanced e
*/
@Override
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
Channel channel = channelHandlerContext.channel();
// 客户端绑定端口成功
byte[] clientId = nettyProxyMsg.getClientId();
byte[] clientTargetIp = nettyProxyMsg.getClientTargetIp();
@ -37,16 +38,16 @@ public class ServerHandleUdpReportServicePermeateClientRealConnectTypeAdvanced e
byte[] visitorId = nettyProxyMsg.getVisitorId();
log.info("客户端:{},绑定真实服务ip:{},port:{},成功", new String(clientId), new String(clientTargetIp), new String(clientTargetPort));
// 绑定服务端访客通信通道
NettyCommunicationIdContext.pushVisitor(channelHandlerContext, new String(visitorId));
ChannelAttributeKeyUtils.buildVisitorId(channelHandlerContext, visitorId);
ChannelAttributeKeyUtils.buildClientId(channelHandlerContext, clientId);
ChannelAttributeKeyUtils.buildVisitorPort(channelHandlerContext, Integer.valueOf(new String(visitorPort)));
NettyCommunicationIdContext.pushVisitor(channel, new String(visitorId));
ChannelAttributeKeyUtils.buildVisitorId(channel, visitorId);
ChannelAttributeKeyUtils.buildClientId(channel, clientId);
ChannelAttributeKeyUtils.buildVisitorPort(channel, Integer.valueOf(new String(visitorPort)));
// 访客通道开启自动读取
Channel visitorRealChannel = NettyRealIdContext.getReal(visitorId);
visitorRealChannel.config().setOption(ChannelOption.AUTO_READ, true);
ChannelAttributeKeyUtils.buildNextChannel(channelHandlerContext, visitorRealChannel);
ChannelAttributeKeyUtils.buildNextChannel(visitorRealChannel, channelHandlerContext);
ChannelAttributeKeyUtils.buildNextChannel(channel, visitorRealChannel);
ChannelAttributeKeyUtils.buildNextChannel(visitorRealChannel, channel);
// 或许此处还应该通知服务端 这个访客绑定的客户端真实通道打开

View File

@ -41,6 +41,7 @@ public class ServerHandleUdpReportServicePermeateClientTransferTypeAdvanced exte
*/
@Override
public 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();
@ -48,7 +49,7 @@ public class ServerHandleUdpReportServicePermeateClientTransferTypeAdvanced exte
// log.debug("访客ID:【{}】接收到客户端:[{}] 返回数据大小:[{}] 内网穿透返回的数据:[{}]", new String(visitorId), clientId, msg.getData().length, new String(msg.getData()));
// 将数据转发访客通道
Channel visitor = NettyRealIdContext.getReal(visitorId);
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channelHandlerContext);
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
if (nextChannel != null) {
ByteBuf buf = nextChannel.config().getAllocator().buffer(msg.getData().length);
buf.writeBytes(msg.getData());
@ -63,7 +64,7 @@ public class ServerHandleUdpReportServicePermeateClientTransferTypeAdvanced exte
.clientId(clientId)
.flow(msg.getData().length)
.build();
channelFlowAdapter.asyncHandler(channelHandlerContext, serverChannelFlow);
channelFlowAdapter.asyncHandler(channel, serverChannelFlow);
}
log.debug("访客ID:【{}】接收到客户端:[{}] 发送真实数据成功", new String(visitorId), clientId);
}

View File

@ -38,10 +38,10 @@ public class ServerHandleUdpReportStagingClosedTypeAdvanced extends AbstractHand
*/
@Override
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg msg) {
String appKey = ChannelAttributeKeyUtils.getAppKey(channelHandlerContext);
String appSecret = ChannelAttributeKeyUtils.getAppSecret(channelHandlerContext);
String originalIp = ChannelAttributeKeyUtils.getOriginalIp(channelHandlerContext);
Channel stagingClosedChannel = channelHandlerContext.channel();
String appKey = ChannelAttributeKeyUtils.getAppKey(stagingClosedChannel);
String appSecret = ChannelAttributeKeyUtils.getAppSecret(stagingClosedChannel);
String originalIp = ChannelAttributeKeyUtils.getOriginalIp(stagingClosedChannel);
byte[] clientIdBytes = msg.getClientId();
// 获取所有通道

View File

@ -40,11 +40,12 @@ public class ServerHandleUdpReportStagingOpenedTypeAdvanced extends AbstractHand
*/
@Override
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg msg) {
Channel stagingOpenedChannel = channelHandlerContext.channel();
// 获取所有通道
byte[] clientIdBytes = msg.getClientId();
String appKey = ChannelAttributeKeyUtils.getAppKey(channelHandlerContext);
String appSecret = ChannelAttributeKeyUtils.getAppSecret(channelHandlerContext);
String originalIp = ChannelAttributeKeyUtils.getOriginalIp(channelHandlerContext);
String appKey = ChannelAttributeKeyUtils.getAppKey(stagingOpenedChannel);
String appSecret = ChannelAttributeKeyUtils.getAppSecret(stagingOpenedChannel);
String originalIp = ChannelAttributeKeyUtils.getOriginalIp(stagingOpenedChannel);
List<Channel> stagingOpenedClientChannel = ChannelContext.get(clientIdBytes);

View File

@ -35,6 +35,7 @@ public class ServerHandleHttpReportClientProxyClientConnectTransferTypeAdvanced
*/
@Override
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
Channel channel = channelHandlerContext.channel();
// 创建链接、发送数据
String targetPortString = nettyProxyMsg.getTargetPortString();
String targetIpString = nettyProxyMsg.getTargetIpString();
@ -42,13 +43,13 @@ public class ServerHandleHttpReportClientProxyClientConnectTransferTypeAdvanced
byte[] visitorId = nettyProxyMsg.getVisitorId();
byte[] clientId = nettyProxyMsg.getClientId();
String msgVisitorId = new String(visitorId);
ChannelAttributeKeyUtils.buildClientId(channelHandlerContext, clientId);
ChannelAttributeKeyUtils.buildVisitorId(channelHandlerContext, msgVisitorId);
ChannelAttributeKeyUtils.buildClientId(channel, clientId);
ChannelAttributeKeyUtils.buildVisitorId(channel, msgVisitorId);
NettyTransferChannelContext.pushVisitor(channelHandlerContext, msgVisitorId);
NettyTransferChannelContext.pushVisitor(channel, msgVisitorId);
NettyByteBuf nettyByteBuf = new NettyByteBuf();
nettyByteBuf.setData(data);
ChannelAttributeKeyUtils.buildNettyByteBufData(channelHandlerContext, nettyByteBuf);
ChannelAttributeKeyUtils.buildNettyByteBufData(channel, nettyByteBuf);
// 获取客户端心跳通道
Channel loadBalance = ChannelContext.getLoadBalance(clientId);

View File

@ -35,6 +35,7 @@ public class ServerHandleHttpReportClientProxyClientTransferChannelInitSuccessfu
@Override
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
Channel channel = channelHandlerContext.channel();
byte[] msgVisitorId = nettyProxyMsg.getVisitorId();
byte[] msgClientTargetIp = nettyProxyMsg.getClientTargetIp();
@ -44,10 +45,10 @@ public class ServerHandleHttpReportClientProxyClientTransferChannelInitSuccessfu
// next translation
Channel nextTransferChannel = NettyTransferChannelContext.getVisitor(msgVisitorId);
ChannelAttributeKeyUtils.buildTransferNextChannel(nextTransferChannel, channelHandlerContext);
ChannelAttributeKeyUtils.buildTransferNextChannel(channelHandlerContext, nextTransferChannel);
ChannelAttributeKeyUtils.buildClientId(channelHandlerContext, clientId);
ChannelAttributeKeyUtils.buildVisitorId(channelHandlerContext, msgVisitorId);
ChannelAttributeKeyUtils.buildTransferNextChannel(nextTransferChannel, channel);
ChannelAttributeKeyUtils.buildTransferNextChannel(channel, nextTransferChannel);
ChannelAttributeKeyUtils.buildClientId(channel, clientId);
ChannelAttributeKeyUtils.buildVisitorId(channel, msgVisitorId);
NettyByteBuf nettyByteBufData = ChannelAttributeKeyUtils.getNettyByteBufData(nextTransferChannel);

View File

@ -33,19 +33,20 @@ public class ServerHandleHttpReportClientProxyClientTransferCloseTypeAdvanced
@Override
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
Channel channel = channelHandlerContext.channel();
// 关闭通道
// 关闭 next、next transfer 通道
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channelHandlerContext);
Channel transferNextChannel = ChannelAttributeKeyUtils.getTransferNextChannel(channelHandlerContext);
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
Channel transferNextChannel = ChannelAttributeKeyUtils.getTransferNextChannel(channel);
// 下发关闭客户端真实通道
NettyProxyMsg closeTransferNettyProxyMsg = new NettyProxyMsg();
closeTransferNettyProxyMsg.setType(ProxyMessageType.HTTP_DISTRIBUTE_CLIENT_PROXY_CLIENT_TRANSFER_CLOSE_);
transferNextChannel.writeAndFlush(closeTransferNettyProxyMsg);
channelHandlerContext.close();
channel.close();
nextChannel.close();
transferNextChannel.close();
}

View File

@ -33,8 +33,9 @@ public class ServerHandleHttpReportClientProxyClientTransferResponseTypeAdvanced
*/
@Override
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
Channel channel = channelHandlerContext.channel();
// 将返回数据下发客户端
Channel transferNextChannel = ChannelAttributeKeyUtils.getTransferNextChannel(channelHandlerContext);
Channel transferNextChannel = ChannelAttributeKeyUtils.getTransferNextChannel(channel);
if(ObjectUtils.isNotEmpty(transferNextChannel)) {
log.info("目标客户端返回数据通过服务端下发到原始通道");

View File

@ -1,6 +1,7 @@
package org.framework.lazy.cloud.network.heartbeat.server.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;
@ -37,6 +38,7 @@ public class ServerHandleHttpReportClientProxyServerProxyTransferTypeAdvanced
*/
@Override
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
Channel channel = channelHandlerContext.channel();
// 创建链接、发送数据
String targetPortString = nettyProxyMsg.getTargetPortString();
String targetIpString = nettyProxyMsg.getTargetIpString();
@ -56,7 +58,7 @@ public class ServerHandleHttpReportClientProxyServerProxyTransferTypeAdvanced
nettyHttpClientProxyServerTransfer.setData(data);
NettyHttpClientProxyServerRealSocket
.buildRealServer(nettyHttpClientProxyServerTransfer, channelHandlerContext,new String(visitorId));
.buildRealServer(nettyHttpClientProxyServerTransfer, channel,new String(visitorId));
}

View File

@ -31,10 +31,11 @@ public class ServerHandleHttpReportClientProxyServerTransferCloseTypeAdvanced ex
*/
@Override
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
Channel channel = channelHandlerContext.channel();
// 关闭传输通信通道
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channelHandlerContext);
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
nextChannel.close();
channelHandlerContext.close();
channel.close();
}

View File

@ -31,6 +31,7 @@ public class ServerHandleHttpReportServerProxyClientTransferChannelInitSuccessfu
@Override
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
Channel channel = channelHandlerContext.channel();
// 数据下发
byte[] msgVisitorId = nettyProxyMsg.getVisitorId();
@ -41,11 +42,11 @@ public class ServerHandleHttpReportServerProxyClientTransferChannelInitSuccessfu
// next
Channel nextChannel = NettyTransferChannelContext.getVisitor(msgVisitorId);
ChannelAttributeKeyUtils.buildNextChannel(nextChannel, channelHandlerContext);
ChannelAttributeKeyUtils.buildNextChannel(channelHandlerContext, nextChannel);
ChannelAttributeKeyUtils.buildNextChannel(nextChannel, channel);
ChannelAttributeKeyUtils.buildNextChannel(channel, nextChannel);
ChannelAttributeKeyUtils.buildClientId(channelHandlerContext, clientId);
ChannelAttributeKeyUtils.buildVisitorId(channelHandlerContext, msgVisitorId);
ChannelAttributeKeyUtils.buildClientId(channel, clientId);
ChannelAttributeKeyUtils.buildVisitorId(channel, msgVisitorId);
NettyByteBuf nettyByteBufData = ChannelAttributeKeyUtils.getNettyByteBufData(nextChannel);
@ -60,7 +61,7 @@ public class ServerHandleHttpReportServerProxyClientTransferChannelInitSuccessfu
clientConnectTagetNettyProxyMsg.setType(ProxyMessageType.HTTP_DISTRIBUTE_SERVER_PROXY_CLIENT_TRANSFER_REQUEST_);
channelHandlerContext.writeAndFlush(clientConnectTagetNettyProxyMsg);
channel.writeAndFlush(clientConnectTagetNettyProxyMsg);
}

View File

@ -27,10 +27,11 @@ public class ServerHandleHttpReportServerProxyClientTransferCloseTypeAdvanced ex
*/
@Override
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
Channel channel = channelHandlerContext.channel();
// 关闭传输通信通道
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channelHandlerContext);
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
nextChannel.close();
channelHandlerContext.close();
channel.close();
}

View File

@ -30,12 +30,13 @@ public class ServerHandleHttpReportServerProxyClientTransferResponseTypeAdvanced
*/
@Override
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
Channel channel = channelHandlerContext.channel();
// 将返回数据
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channelHandlerContext);
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
if(ObjectUtils.isNotEmpty(nextChannel)) {
log.info("目标客户端返回数据通过服务端下发到原始通道");
ByteBuf buf = channelHandlerContext.config().getAllocator().buffer(nettyProxyMsg.getData().length);
ByteBuf buf = channel.config().getAllocator().buffer(nettyProxyMsg.getData().length);
buf.writeBytes(nettyProxyMsg.getData());
nextChannel.writeAndFlush(buf);
}else {

View File

@ -32,6 +32,7 @@ public class ServerHandleHttpReportServerProxyClientTransferTypeAdvanced
@Override
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
Channel channel = channelHandlerContext.channel();
// 创建链接、发送数据
String targetPortString = nettyProxyMsg.getTargetPortString();
String targetIpString = nettyProxyMsg.getTargetIpString();
@ -39,13 +40,13 @@ public class ServerHandleHttpReportServerProxyClientTransferTypeAdvanced
byte[] visitorId = nettyProxyMsg.getVisitorId();
byte[] clientId = nettyProxyMsg.getClientId();
String msgVisitorId = new String(visitorId);
ChannelAttributeKeyUtils.buildClientId(channelHandlerContext, clientId);
ChannelAttributeKeyUtils.buildVisitorId(channelHandlerContext, msgVisitorId);
ChannelAttributeKeyUtils.buildClientId(channel, clientId);
ChannelAttributeKeyUtils.buildVisitorId(channel, msgVisitorId);
NettyTransferChannelContext.pushVisitor(channelHandlerContext, msgVisitorId);
NettyTransferChannelContext.pushVisitor(channel, msgVisitorId);
NettyByteBuf nettyByteBuf = new NettyByteBuf();
nettyByteBuf.setData(data);
ChannelAttributeKeyUtils.buildNettyByteBufData(channelHandlerContext, nettyByteBuf);
ChannelAttributeKeyUtils.buildNettyByteBufData(channel, nettyByteBuf);
// 获取客户端心跳通道
Channel loadBalance = ChannelContext.getLoadBalance(clientId);