mirror of
https://gitee.com/wujiawei1207537021/wu-lazy-cloud-network.git
synced 2025-06-16 18:35:05 +08:00
【fix】
This commit is contained in:
@ -4,6 +4,7 @@ import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelPipeline;
|
||||
import io.netty.channel.socket.SocketChannel;
|
||||
import io.netty.handler.timeout.IdleStateHandler;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.handler.NettyClientPermeateClientTransferHandler;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelTypeAdapter;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.decoder.NettyProxyMsgDecoder;
|
||||
@ -35,6 +36,9 @@ public class NettyClientPermeateClientTransferFilter extends DebugChannelInitial
|
||||
// // 解码、编码
|
||||
// pipeline.addLast(new NettyProxyMsgDecoder(Integer.MAX_VALUE, 0, 4, -4, 0));
|
||||
// pipeline.addLast(new NettMsgEncoder());
|
||||
|
||||
pipeline.addLast(new IdleStateHandler(0, 4, 0));
|
||||
|
||||
pipeline.addLast(new NettyProxyMsgDecoder(Integer.MAX_VALUE, 0, 4, -4, 0));
|
||||
pipeline.addLast(new NettyProxyMsgEncoder());
|
||||
pipeline.addLast(new NettyClientPermeateClientTransferHandler(channelTypeAdapter));
|
||||
|
@ -4,6 +4,7 @@ import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelPipeline;
|
||||
import io.netty.channel.socket.SocketChannel;
|
||||
import io.netty.handler.timeout.IdleStateHandler;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.handler.NettyClientPermeateClientTransferRealHandler;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelTypeAdapter;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.decoder.NettyProxyMsgDecoder;
|
||||
@ -35,6 +36,9 @@ public class NettyClientPermeateClientTransferRealFilter extends DebugChannelIni
|
||||
// // 解码、编码
|
||||
// pipeline.addLast(new NettyProxyMsgDecoder(Integer.MAX_VALUE, 0, 4, -4, 0));
|
||||
// pipeline.addLast(new NettMsgEncoder());
|
||||
|
||||
pipeline.addLast(new IdleStateHandler(0, 4, 0));
|
||||
|
||||
pipeline.addLast(new NettyProxyMsgDecoder(Integer.MAX_VALUE, 0, 4, -4, 0));
|
||||
pipeline.addLast(new NettyProxyMsgEncoder());
|
||||
pipeline.addLast(new NettyClientPermeateClientTransferRealHandler(channelTypeAdapter));
|
||||
|
@ -36,6 +36,7 @@ public class NettyClientPermeateServerTransferFilter extends DebugChannelInitial
|
||||
// // 解码、编码
|
||||
// pipeline.addLast(new NettyProxyMsgDecoder(Integer.MAX_VALUE, 0, 4, -4, 0));
|
||||
// pipeline.addLast(new NettMsgEncoder());
|
||||
pipeline.addLast(new IdleStateHandler(0, 4, 0));
|
||||
pipeline.addLast(new NettyProxyMsgDecoder(Integer.MAX_VALUE, 0, 4, -4, 0));
|
||||
pipeline.addLast(new IdleStateHandler(0, 4, 0));
|
||||
pipeline.addLast(new NettyProxyMsgEncoder());
|
||||
|
@ -42,6 +42,7 @@ public class NettyClientPermeateClientTransferRealHandler extends SimpleChannelI
|
||||
String clientId = ChannelAttributeKeyUtils.getClientId(ctx.channel());
|
||||
String visitorId = ChannelAttributeKeyUtils.getVisitorId(ctx.channel());
|
||||
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(ctx.channel());
|
||||
log.warn("close client permeate client transfer real clientId:{} visitorId:{}", clientId, visitorId);
|
||||
// 关闭访客
|
||||
if (nextChannel != null) {
|
||||
|
||||
|
@ -18,6 +18,7 @@ import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyRealIdContext;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
@Slf4j
|
||||
@ -54,7 +55,7 @@ public class NettyClientPermeateClientVisitorHandler extends SimpleChannelInbou
|
||||
// Channel transferChannel = nettyChannelPool.availableChannel(visitorId);
|
||||
// 创建访客连接客户端通道
|
||||
NettyClientPermeateClientVisitorTransferSocket.buildTransferServer(internalNetworkClientPermeateClientVisitor,visitorChannel);
|
||||
log.info("客户端渗透客户端访客端口连接成功了");
|
||||
log.info("客户端渗透客户端访客:【{}】端口连接成功了",visitorId);
|
||||
super.channelActive(ctx);
|
||||
}
|
||||
|
||||
@ -108,7 +109,7 @@ public class NettyClientPermeateClientVisitorHandler extends SimpleChannelInbou
|
||||
// 关闭 访客通信通道、访客真实通道
|
||||
NettyRealIdContext.clear(visitorId);
|
||||
NettyCommunicationIdContext.clear(visitorId);
|
||||
log.warn("【客户端渗透客户端】访客端口断开连接");
|
||||
log.warn("【客户端渗透客户端】访客:【{}】端口断开连接",visitorId);
|
||||
super.channelInactive(ctx);
|
||||
}
|
||||
|
||||
|
@ -57,7 +57,7 @@ public class NettyClientPermeateClientRealSocket {
|
||||
Channel realChannel = future.channel();
|
||||
realChannel.config().setOption(ChannelOption.AUTO_READ, false);
|
||||
|
||||
log.info("访客通过 客户端:【{}】,绑定本地服务,IP:{},端口:{} 新建通道成功", clientId, clientTargetIp, clientTargetPort);
|
||||
log.info("访客通过 客户端:【{}】,visitorId:{},绑定本地服务,IP:{},端口:{} 新建通道成功", clientId,visitorId, clientTargetIp, clientTargetPort);
|
||||
// 客户端真实通道
|
||||
NettyRealIdContext.pushReal(realChannel, visitorId);
|
||||
// 绑定访客ID到当前真实通道属性
|
||||
@ -126,11 +126,9 @@ public class NettyClientPermeateClientRealSocket {
|
||||
|
||||
|
||||
// 客户端新建访客通道 连接服务端IP:{},连接服务端端口:{}
|
||||
log.info("Client creates a new visitor channel to connect to server IP: {}, connecting to server port: {}", inetHost, inetPort);
|
||||
log.info("client creates a new visitor channel to connect to server IP: {}, connecting to server port: {} with visitorId:{} & clientId:{}", inetHost, inetPort,visitorId,clientId);
|
||||
ChannelFuture future = bootstrap.connect(inetHost, inetPort);
|
||||
|
||||
// 使用的客户端ID:{}
|
||||
log.info("Client ID used: {}", clientId);
|
||||
future.addListener((ChannelFutureListener) futureListener -> {
|
||||
Channel transferChannel = futureListener.channel();
|
||||
if (futureListener.isSuccess()) {
|
||||
|
@ -10,9 +10,7 @@ import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientPrope
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.InternalNetworkClientPermeateClientVisitor;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.filter.NettyClientPermeateClientTransferFilter;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.MessageType;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyCommunicationIdContext;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyRealIdContext;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelTypeAdapter;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
|
||||
|
||||
@ -28,7 +26,7 @@ public class NettyClientPermeateClientVisitorTransferSocket {
|
||||
/**
|
||||
* 连接服务端通信通道
|
||||
*/
|
||||
public static void buildTransferServer(InternalNetworkClientPermeateClientVisitor internalNetworkClientPermeateClientVisitor,Channel visitorChannel) {
|
||||
public static void buildTransferServer(InternalNetworkClientPermeateClientVisitor internalNetworkClientPermeateClientVisitor, Channel visitorChannel) {
|
||||
|
||||
|
||||
Bootstrap bootstrap = new Bootstrap();
|
||||
@ -62,25 +60,24 @@ public class NettyClientPermeateClientVisitorTransferSocket {
|
||||
String toClientId = internalNetworkClientPermeateClientVisitor.getToClientId();
|
||||
|
||||
// 客户端新建访客通道 连接服务端IP:{},连接服务端端口:{}
|
||||
log.info("Client creates a new visitor channel to connect to server IP: {}, connecting to server port: {}", inetHost, inetPort);
|
||||
log.info("Client creates a new visitor channel to connect to server IP: {}, connecting to server port: {} with clientId:【{}】 toClientId:【{}】 & visitorId:【{}】", inetHost, inetPort, clientId, toClientId, visitorId);
|
||||
ChannelFuture future = bootstrap.connect(inetHost, inetPort);
|
||||
|
||||
// 使用的客户端ID:{}
|
||||
log.info("Client ID used: {}", clientId);
|
||||
future.addListener((ChannelFutureListener) futureListener -> {
|
||||
Channel transferChannel = futureListener.channel();
|
||||
if (futureListener.isSuccess()) {
|
||||
|
||||
NettyProxyMsg myMsg = new NettyProxyMsg();
|
||||
myMsg.setType(MessageType.REPORT_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL);
|
||||
NettyProxyMsg nettyProxyMsg = new NettyProxyMsg();
|
||||
nettyProxyMsg.setType(MessageType.REPORT_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL);
|
||||
// other clientId
|
||||
myMsg.setClientId(toClientId);
|
||||
myMsg.setVisitorPort(visitorPort);
|
||||
myMsg.setClientTargetIp(targetIp);
|
||||
myMsg.setClientTargetPort(targetPort);
|
||||
nettyProxyMsg.setClientId(toClientId);
|
||||
nettyProxyMsg.setVisitorPort(visitorPort);
|
||||
nettyProxyMsg.setClientTargetIp(targetIp);
|
||||
nettyProxyMsg.setClientTargetPort(targetPort);
|
||||
|
||||
myMsg.setVisitorId(visitorId);
|
||||
transferChannel.writeAndFlush(myMsg);
|
||||
nettyProxyMsg.setVisitorId(visitorId);
|
||||
transferChannel.writeAndFlush(nettyProxyMsg);
|
||||
// 绑定客户端真实通信通道
|
||||
ChannelAttributeKeyUtils.buildVisitorId(transferChannel, visitorId);
|
||||
ChannelAttributeKeyUtils.buildClientId(transferChannel, clientId);
|
||||
@ -93,7 +90,7 @@ public class NettyClientPermeateClientVisitorTransferSocket {
|
||||
log.info("无法连接到服务端....");
|
||||
eventLoopGroup.schedule(() -> {
|
||||
try {
|
||||
buildTransferServer(internalNetworkClientPermeateClientVisitor,visitorChannel);
|
||||
buildTransferServer(internalNetworkClientPermeateClientVisitor, visitorChannel);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
Reference in New Issue
Block a user