[fix] 优化tcp架构

This commit is contained in:
wujiawei
2024-12-13 14:29:11 +08:00
parent 41a81133f1
commit 42bc37c712
113 changed files with 3617 additions and 300 deletions

View File

@ -9,7 +9,7 @@ import org.framework.lazy.cloud.network.heartbeat.common.advanced.tcp.AbstractTc
/**
* 服务端 处理客户端心跳
* TYPE_HEARTBEAT
* TCP_TYPE_HEARTBEAT
*/
public class ClientTcpHandleChannelHeartbeatTypeAdvanced extends AbstractTcpHandleChannelHeartbeatTypeAdvanced<NettyProxyMsg> {
@ -22,7 +22,7 @@ public class ClientTcpHandleChannelHeartbeatTypeAdvanced extends AbstractTcpHand
@Override
public void doHandler(Channel channel, NettyProxyMsg msg) {
NettyProxyMsg hb = new NettyProxyMsg();
hb.setType(MessageType.TYPE_HEARTBEAT);
hb.setType(MessageType.TCP_TYPE_HEARTBEAT);
// channel.writeAndFlush(hb);
}

View File

@ -97,7 +97,7 @@ public class NettyClientHandler extends SimpleChannelInboundHandler<NettyProxyMs
if (IdleState.WRITER_IDLE.equals(event.state())) { //如果写通道处于空闲状态,就发送心跳命令
String clientId = nettyClientSocket.getClientId();
NettyProxyMsg nettyMsg = new NettyProxyMsg();
nettyMsg.setType(MessageType.TYPE_HEARTBEAT);
nettyMsg.setType(MessageType.TCP_TYPE_HEARTBEAT);
nettyMsg.setData(clientId.getBytes(StandardCharsets.UTF_8));
nettyMsg.setClientId(clientId.getBytes(StandardCharsets.UTF_8));
ctx.writeAndFlush(nettyMsg);// 发送心跳数据

View File

@ -32,7 +32,7 @@ public class NettyClientPermeateClientRealHandler extends SimpleChannelInboundHa
// 访客通信通道 上报服务端代理完成
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(ctx.channel());
NettyProxyMsg returnMessage = new NettyProxyMsg();
returnMessage.setType(MessageType.REPORT_CLIENT_TRANSFER_CLIENT_RESPONSE);
returnMessage.setType(MessageType.TCP_REPORT_CLIENT_TRANSFER_CLIENT_RESPONSE);
returnMessage.setVisitorId(visitorId);
returnMessage.setClientId(clientId);
returnMessage.setVisitorPort(visitorPort);
@ -55,7 +55,7 @@ public class NettyClientPermeateClientRealHandler extends SimpleChannelInboundHa
if (nextChannel != null) {
// 上报关闭这个客户端的访客通道
NettyProxyMsg closeVisitorMsg = new NettyProxyMsg();
closeVisitorMsg.setType(MessageType.REPORT_CLIENT_PERMEATE_CLIENT_TRANSFER_CLOSE);
closeVisitorMsg.setType(MessageType.TCP_REPORT_CLIENT_PERMEATE_CLIENT_TRANSFER_CLOSE);
closeVisitorMsg.setVisitorId(visitorId);
nextChannel.writeAndFlush(closeVisitorMsg);
}

View File

@ -47,7 +47,7 @@ public class NettyClientPermeateClientTransferHandler extends SimpleChannelInbou
if (nextChannel != null) {
// 上报关闭这个客户端的访客通道
NettyProxyMsg closeVisitorMsg = new NettyProxyMsg();
closeVisitorMsg.setType(MessageType.REPORT_CLIENT_PERMEATE_CLIENT_TRANSFER_CLOSE);
closeVisitorMsg.setType(MessageType.TCP_REPORT_CLIENT_PERMEATE_CLIENT_TRANSFER_CLOSE);
closeVisitorMsg.setVisitorId(visitorId);
nextChannel.writeAndFlush(closeVisitorMsg);
}

View File

@ -48,7 +48,7 @@ public class NettyClientPermeateClientTransferRealHandler extends SimpleChannelI
// 上报关闭这个客户端的访客通道
NettyProxyMsg closeVisitorMsg = new NettyProxyMsg();
closeVisitorMsg.setType(MessageType.REPORT_CLIENT_PERMEATE_CLIENT_TRANSFER_CLOSE);
closeVisitorMsg.setType(MessageType.TCP_REPORT_CLIENT_PERMEATE_CLIENT_TRANSFER_CLOSE);
closeVisitorMsg.setVisitorId(visitorId);
nextChannel.writeAndFlush(closeVisitorMsg);
}

View File

@ -75,7 +75,7 @@ public class NettyClientPermeateClientVisitorHandler extends SimpleChannelInbou
Integer visitorPort = internalNetworkClientPermeateClientVisitor.getVisitorPort();
String clientId = internalNetworkClientPermeateClientVisitor.getNettyClientProperties().getClientId();
NettyProxyMsg nettyProxyMsg = new NettyProxyMsg();
nettyProxyMsg.setType(MessageType.REPORT_CLIENT_PERMEATE_CLIENT_TRANSFER_REQUEST);
nettyProxyMsg.setType(MessageType.TCP_REPORT_CLIENT_PERMEATE_CLIENT_TRANSFER_REQUEST);
nettyProxyMsg.setVisitorId(visitorId);
nettyProxyMsg.setClientId(clientId);
nettyProxyMsg.setVisitorPort(visitorPort);
@ -102,7 +102,7 @@ public class NettyClientPermeateClientVisitorHandler extends SimpleChannelInbou
// 通知客户端 关闭访问通道、真实通道
NettyProxyMsg myMsg = new NettyProxyMsg();
myMsg.setType(MessageType.REPORT_CLIENT_PERMEATE_CLIENT_TRANSFER_CLOSE);
myMsg.setType(MessageType.TCP_REPORT_CLIENT_PERMEATE_CLIENT_TRANSFER_CLOSE);
nextChannel.writeAndFlush(myMsg);
}
// 关闭 访客通信通道、访客真实通道

View File

@ -47,7 +47,7 @@ public class NettyClientPermeateServerTransferHandler extends SimpleChannelInbou
if (nextChannel != null) {
// 上报关闭服务端客户端真实通道
NettyProxyMsg closeVisitorMsg = new NettyProxyMsg();
closeVisitorMsg.setType(MessageType.REPORT_CLIENT_PERMEATE_SERVER_TRANSFER_CLOSE);
closeVisitorMsg.setType(MessageType.TCP_TCP_REPORT_CLIENT_PERMEATE_SERVER_TRANSFER_CLOSE);
closeVisitorMsg.setVisitorId(visitorId);
nextChannel.writeAndFlush(closeVisitorMsg);
}
@ -79,7 +79,7 @@ public class NettyClientPermeateServerTransferHandler extends SimpleChannelInbou
if (obj instanceof IdleStateEvent event) {
if (IdleState.WRITER_IDLE.equals(event.state())) { //如果写通道处于空闲状态,就发送心跳命令
NettyProxyMsg nettyMsg = new NettyProxyMsg();
nettyMsg.setType(MessageType.TYPE_HEARTBEAT);
nettyMsg.setType(MessageType.TCP_TYPE_HEARTBEAT);
ctx.writeAndFlush(nettyMsg);// 发送心跳数据
} else if (event.state() == IdleState.WRITER_IDLE) { // 如果检测到写空闲状态,关闭连接
// 离线、暂存通知

View File

@ -70,7 +70,7 @@ public class NettyClientPermeateServerVisitorHandler extends SimpleChannelInboun
Integer visitorPort = internalNetworkClientPermeateServerVisitor.getVisitorPort();
String clientId = internalNetworkClientPermeateServerVisitor.getNettyClientProperties().getClientId();
NettyProxyMsg nettyProxyMsg = new NettyProxyMsg();
nettyProxyMsg.setType(MessageType.REPORT_CLIENT_PERMEATE_SERVER_TRANSFER);
nettyProxyMsg.setType(MessageType.TCP_REPORT_CLIENT_PERMEATE_SERVER_TRANSFER);
nettyProxyMsg.setVisitorId(visitorId);
nettyProxyMsg.setClientId(clientId);
nettyProxyMsg.setVisitorPort(visitorPort);
@ -95,7 +95,7 @@ public class NettyClientPermeateServerVisitorHandler extends SimpleChannelInboun
if (nextChannel != null && nextChannel.isActive()) {
// 通知服务端 关闭访问通道、真实通道
NettyProxyMsg myMsg = new NettyProxyMsg();
myMsg.setType(MessageType.REPORT_CLIENT_PERMEATE_SERVER_TRANSFER_CLOSE);
myMsg.setType(MessageType.TCP_TCP_REPORT_CLIENT_PERMEATE_SERVER_TRANSFER_CLOSE);
myMsg.setVisitorId(visitorId);
nextChannel.writeAndFlush(myMsg);
//通信通道
@ -136,7 +136,7 @@ public class NettyClientPermeateServerVisitorHandler extends SimpleChannelInboun
if (nextChannel != null) {
// 下发关闭访客
NettyProxyMsg closeRealClient = new NettyProxyMsg();
closeRealClient.setType(MessageType.REPORT_CLIENT_PERMEATE_SERVER_TRANSFER_CLOSE);
closeRealClient.setType(MessageType.TCP_TCP_REPORT_CLIENT_PERMEATE_SERVER_TRANSFER_CLOSE);
closeRealClient.setClientId(clientId);
closeRealClient.setVisitorId(visitorId);
nextChannel.writeAndFlush(closeRealClient);

View File

@ -31,7 +31,7 @@ public class NettyServerPermeateClientRealHandler extends SimpleChannelInboundHa
// 访客通信通道 上报服务端代理完成
Channel visitor = ChannelAttributeKeyUtils.getNextChannel(ctx.channel());
NettyProxyMsg returnMessage = new NettyProxyMsg();
returnMessage.setType(MessageType.REPORT_CLIENT_TRANSFER);
returnMessage.setType(MessageType.TCP_REPORT_CLIENT_TRANSFER);
returnMessage.setVisitorId(visitorId);
returnMessage.setClientId(clientId);
returnMessage.setVisitorPort(visitorPort);
@ -55,7 +55,7 @@ public class NettyServerPermeateClientRealHandler extends SimpleChannelInboundHa
if (visitor != null) {
// 上报关闭这个客户端的访客通道
NettyProxyMsg closeVisitorMsg = new NettyProxyMsg();
closeVisitorMsg.setType(MessageType.REPORT_SERVICE_PERMEATE_CLIENT_CLIENT_CLOSE_VISITOR);
closeVisitorMsg.setType(MessageType.TCP_REPORT_SERVICE_PERMEATE_CLIENT_CLIENT_CLOSE_VISITOR);
closeVisitorMsg.setVisitorId(visitorId);
visitor.writeAndFlush(closeVisitorMsg);
}

View File

@ -44,7 +44,7 @@ public class NettyServerPermeateClientTransferHandler extends SimpleChannelInbou
if (nextChannel != null) {
// 上报关闭这个客户端的访客通道
NettyProxyMsg closeVisitorMsg = new NettyProxyMsg();
closeVisitorMsg.setType(MessageType.REPORT_SERVICE_PERMEATE_CLIENT_CLIENT_CLOSE_VISITOR);
closeVisitorMsg.setType(MessageType.TCP_REPORT_SERVICE_PERMEATE_CLIENT_CLIENT_CLOSE_VISITOR);
closeVisitorMsg.setVisitorId(visitorId);
nextChannel.writeAndFlush(closeVisitorMsg);
}

View File

@ -140,7 +140,7 @@ public class NettyClientPermeateClientRealSocket {
nettyProxyMsg.setClientTargetIp(clientTargetIp);
nettyProxyMsg.setClientTargetPort(clientTargetPort);
nettyProxyMsg.setVisitorPort(visitorPort);
nettyProxyMsg.setType(MessageType.REPORT_CLIENT_PERMEATE_CLIENT_TRANSFER_CHANNEL_INIT_SUCCESSFUL);
nettyProxyMsg.setType(MessageType.TCP_REPORT_CLIENT_PERMEATE_CLIENT_TRANSFER_CHANNEL_INIT_SUCCESSFUL);
transferChannel.writeAndFlush(nettyProxyMsg);
ChannelAttributeKeyUtils.buildNextChannel(transferChannel, realChannel);

View File

@ -69,7 +69,7 @@ public class NettyClientPermeateClientVisitorTransferSocket {
if (futureListener.isSuccess()) {
NettyProxyMsg nettyProxyMsg = new NettyProxyMsg();
nettyProxyMsg.setType(MessageType.REPORT_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL);
nettyProxyMsg.setType(MessageType.TCP_REPORT_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL);
// other clientId
nettyProxyMsg.setClientId(toClientId);
nettyProxyMsg.setVisitorPort(visitorPort);

View File

@ -71,7 +71,7 @@ public class NettyClientPermeateServerVisitorTransferSocket {
if (futureListener.isSuccess()) {
NettyProxyMsg myMsg = new NettyProxyMsg();
myMsg.setType(MessageType.REPORT_CLIENT_TRANSFER_SERVER_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL);
myMsg.setType(MessageType.TCP_REPORT_CLIENT_TRANSFER_SERVER_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL);
myMsg.setClientId(clientId);
myMsg.setVisitorPort(visitorPort);
myMsg.setClientTargetIp(targetIp);

View File

@ -101,7 +101,7 @@ public class NettyClientSocket {
log.info("clientId:{},connect to server IP:{},server port :{} isSuccess ", clientId, inetHost, inetPort);
// 告诉服务端这条连接是client的连接
NettyProxyMsg nettyMsg = new NettyProxyMsg();
nettyMsg.setType(MessageType.REPORT_CLIENT_CONNECT_SUCCESS);
nettyMsg.setType(MessageType.TCP_REPORT_CLIENT_CONNECT_SUCCESS);
nettyMsg.setClientId(clientId);
String hostAddress = InetAddress.getLocalHost().getHostAddress();
nettyMsg.setOriginalIpString(hostAddress);

View File

@ -176,7 +176,7 @@ public class NettyServerPermeateClientRealSocket {
if (futureListener.isSuccess()) {
NettyProxyMsg myMsg = new NettyProxyMsg();
myMsg.setType(MessageType.REPORT_SINGLE_CLIENT_REAL_CONNECT);
myMsg.setType(MessageType.TCP_REPORT_SINGLE_CLIENT_REAL_CONNECT);
myMsg.setClientId(visitorClientId);
myMsg.setVisitorPort(visitorPort);
myMsg.setClientTargetIp(clientTargetIp);

View File

@ -29,7 +29,7 @@
// Channel channel = clientChannel.getChannel();
//
// NettyProxyMsg nettyMsg = new NettyProxyMsg();
// nettyMsg.setType(MessageType.REPORT_CLIENT_STAGING_OPENED);
// nettyMsg.setType(MessageType.TCP_REPORT_CLIENT_STAGING_OPENED);
// nettyMsg.setData((clientId
// .getBytes(StandardCharsets.UTF_8)));
// nettyMsg.setClientId((clientId
@ -52,7 +52,7 @@
// // 上报 当前通道暂存关闭了
// Channel channel = clientChannel.getChannel();
// NettyProxyMsg nettyMsg = new NettyProxyMsg();
// nettyMsg.setType(MessageType.REPORT_CLIENT_STAGING_CLOSED);
// nettyMsg.setType(MessageType.TCP_REPORT_CLIENT_STAGING_CLOSED);
// nettyMsg.setData((clientId
// .getBytes(StandardCharsets.UTF_8)));
// nettyMsg.setClientId((clientId