mirror of
https://gitee.com/wujiawei1207537021/wu-lazy-cloud-network.git
synced 2025-06-06 21:37:56 +08:00
[fix]
This commit is contained in:
parent
93549cad90
commit
c144688a9d
@ -100,6 +100,15 @@ public class HeartbeatClientConfiguration {
|
||||
public ClientHandleDistributeClientPermeateServerInitTypeAdvanced clientHandleDistributeClientPermeateServerInitTypeAdvanced(NettyClientProperties nettyClientProperties) {
|
||||
return new ClientHandleDistributeClientPermeateServerInitTypeAdvanced(nettyClientProperties);
|
||||
}
|
||||
/**
|
||||
* 处理 客户端渗透服务端init close 信息
|
||||
*
|
||||
* @return ClientHandleDistributeClientPermeateServerCloseTypeAdvanced
|
||||
*/
|
||||
@Bean
|
||||
public ClientHandleDistributeClientPermeateServerCloseTypeAdvanced clientHandleDistributeClientPermeateServerCloseTypeAdvanced( ) {
|
||||
return new ClientHandleDistributeClientPermeateServerCloseTypeAdvanced();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ClientHandleDistributeSingleClientRealConnectTypeAdvanced clientHandleDistributeSingleClientRealConnectTypeAdvanced(NettyClientProperties nettyClientProperties,
|
||||
|
@ -0,0 +1,44 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.advanced;
|
||||
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.socket.NettyClientPermeateServerVisitorSocket;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyVisitorPortContext;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.client.AbstractHandleDistributeClientPermeateServerCloseTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.socket.PermeateVisitorSocket;
|
||||
|
||||
|
||||
/**
|
||||
* 客户端渗透服务端init close 信息
|
||||
*
|
||||
* @see MessageTypeEnums#DISTRIBUTE_CLIENT_PERMEATE_SERVER_CLOSE
|
||||
*/
|
||||
@Slf4j
|
||||
public class ClientHandleDistributeClientPermeateServerCloseTypeAdvanced extends AbstractHandleDistributeClientPermeateServerCloseTypeAdvanced<NettyProxyMsg> {
|
||||
|
||||
|
||||
/**
|
||||
* 处理当前数据
|
||||
*
|
||||
* @param channel 当前通道
|
||||
* @param nettyProxyMsg 通道数据
|
||||
*/
|
||||
@Override
|
||||
public void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
|
||||
// 初始化 客户端渗透服务端socket
|
||||
byte[] msgVisitorPort = nettyProxyMsg.getVisitorPort();
|
||||
Integer visitorPort = Integer.parseInt(new String(msgVisitorPort));
|
||||
PermeateVisitorSocket visitorSocket = NettyVisitorPortContext.getVisitorSocket(visitorPort);
|
||||
// 关闭当前客户端渗透服务端访客通道
|
||||
try {
|
||||
visitorSocket.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -13,8 +13,8 @@ import org.framework.lazy.cloud.network.heartbeat.common.NettyClientVisitorConte
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyVisitorPortContext;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelFlowAdapter;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.socket.PermeateVisitorSocket;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -24,7 +24,7 @@ import java.util.List;
|
||||
* @see NettyClientVisitorContext
|
||||
*/
|
||||
@Slf4j
|
||||
public class NettyClientPermeateServerVisitorSocket {
|
||||
public class NettyClientPermeateServerVisitorSocket implements PermeateVisitorSocket {
|
||||
private final EventLoopGroup bossGroup = new NioEventLoopGroup();
|
||||
private final EventLoopGroup workerGroup = new NioEventLoopGroup();
|
||||
private final NettyClientPermeateServerVisitorFilter nettyClientPermeateServerVisitorFilter;
|
||||
@ -42,11 +42,11 @@ public class NettyClientPermeateServerVisitorSocket {
|
||||
/**
|
||||
* 启动客户端本地端口渗透到服务端端口
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public void start() throws Exception {
|
||||
@Override
|
||||
public void start() {
|
||||
|
||||
Channel visitor = NettyVisitorPortContext.getVisitor(visitorPort);
|
||||
Channel visitor = NettyVisitorPortContext.getVisitorChannel(visitorPort);
|
||||
if (visitor == null) {
|
||||
ServerBootstrap bootstrap = new ServerBootstrap();
|
||||
bootstrap
|
||||
@ -68,40 +68,44 @@ public class NettyClientPermeateServerVisitorSocket {
|
||||
|
||||
|
||||
.childHandler(nettyClientPermeateServerVisitorFilter);
|
||||
ChannelFuture sync = bootstrap.bind(visitorPort).sync();
|
||||
sync.addListener((ChannelFutureListener) future -> {
|
||||
|
||||
try {
|
||||
bootstrap.bind(visitorPort).sync().addListener((ChannelFutureListener) future -> {
|
||||
if (future.isSuccess()) {
|
||||
// 这里时异步处理
|
||||
log.info("客户端:[{}]访客端口:[{}] 开启", clientId, visitorPort);
|
||||
NettyVisitorPortContext.pushVisitor(visitorPort, future.channel());
|
||||
NettyVisitorPortContext.pushVisitorChannel(visitorPort, future.channel());
|
||||
|
||||
} else {
|
||||
log.error("客户端:[{}]访客端口:[{}]绑定失败", clientId, visitorPort);
|
||||
}
|
||||
});
|
||||
NettyClientVisitorContext.pushVisitorSocket(clientId, this);
|
||||
NettyVisitorPortContext.pushVisitorSocket(visitorPort, this);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
} else {
|
||||
log.warn("客户端:[{}]访客端口:[{}] 重复启动", clientId, visitorPort);
|
||||
log.warn("客户端渗透服务端:[{}]访客端口:[{}] 重复启动", clientId, visitorPort);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void close() throws IOException, InterruptedException {
|
||||
@Override
|
||||
public void close() {
|
||||
if (!bossGroup.isShutdown()) {
|
||||
bossGroup.shutdownGracefully();
|
||||
}
|
||||
if (!workerGroup.isShutdown()) {
|
||||
workerGroup.shutdownGracefully();
|
||||
}
|
||||
Channel visitor = NettyVisitorPortContext.getVisitor(visitorPort);
|
||||
Channel visitor = NettyVisitorPortContext.getVisitorChannel(visitorPort);
|
||||
if (visitor != null) {
|
||||
|
||||
// close channel
|
||||
visitor.close();
|
||||
// remove visitor
|
||||
NettyVisitorPortContext.removeVisitor(visitorPort);
|
||||
NettyVisitorPortContext.removeVisitorChannel(visitorPort);
|
||||
// remove client this
|
||||
NettyClientVisitorContext.removeVisitorSocket(clientId,this);
|
||||
NettyVisitorPortContext.removeVisitorSocket(visitorPort);
|
||||
log.warn("关闭客户端 :【{}】 访客户端口:【{}】", clientId, visitorPort);
|
||||
} else {
|
||||
log.warn("关闭访客端口失败 未找到客户端通道 客户端 :【{}】 访客户端口:【{}】", clientId, visitorPort);
|
||||
|
@ -112,7 +112,13 @@ public class MessageType {
|
||||
* @see AbstractHandleReportClientPermeateServerInitTypeAdvanced
|
||||
*/
|
||||
public static final byte REPORT_CLIENT_PERMEATE_SERVER_INIT = 0X13;
|
||||
|
||||
/**
|
||||
* 上报 客户端渗透服务端init close 信息
|
||||
*
|
||||
* @see MessageTypeEnums#REPORT_CLIENT_PERMEATE_SERVER_CLOSE
|
||||
* @see AbstractHandleReportClientPermeateServerCloseTypeAdvanced
|
||||
*/
|
||||
public static final byte REPORT_CLIENT_PERMEATE_SERVER_CLOSE = 0X14;
|
||||
/**
|
||||
* 下发 客户端接收连接成功通知
|
||||
*
|
||||
@ -213,4 +219,12 @@ public class MessageType {
|
||||
* @see AbstractHandleDistributeClientPermeateServerInitTypeAdvanced
|
||||
*/
|
||||
public static final byte DISTRIBUTE_CLIENT_PERMEATE_SERVER_INIT = -0X13;
|
||||
|
||||
/**
|
||||
* 下发 客户端渗透服务端init close信息
|
||||
*
|
||||
* @see MessageTypeEnums#DISTRIBUTE_CLIENT_PERMEATE_SERVER_CLOSE
|
||||
* @see AbstractHandleDistributeClientPermeateServerCloseTypeAdvanced
|
||||
*/
|
||||
public static final byte DISTRIBUTE_CLIENT_PERMEATE_SERVER_CLOSE = -0X14;
|
||||
}
|
||||
|
@ -1,5 +1,8 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.common;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.socket.PermeateVisitorSocket;
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
@ -7,7 +10,8 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
*/
|
||||
public class NettyVisitorPortContext {
|
||||
|
||||
protected static final ConcurrentHashMap<Integer, Object> VISITOR_PORT = new ConcurrentHashMap<>();
|
||||
protected static final ConcurrentHashMap<Integer, Channel> VISITOR_PORT_CHANNEL = new ConcurrentHashMap<>();
|
||||
protected static final ConcurrentHashMap<Integer, PermeateVisitorSocket> VISITOR_PORT_SOCKET = new ConcurrentHashMap<>();
|
||||
|
||||
|
||||
/**
|
||||
@ -16,11 +20,20 @@ public class NettyVisitorPortContext {
|
||||
* @param visitorPort 访客端口
|
||||
* @param visitor 访客
|
||||
*/
|
||||
public static <T> void pushVisitor(Integer visitorPort, T visitor) {
|
||||
VISITOR_PORT.put(visitorPort, visitor);
|
||||
|
||||
public static void pushVisitorChannel(Integer visitorPort, Channel visitor) {
|
||||
VISITOR_PORT_CHANNEL.put(visitorPort, visitor);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 添加访客
|
||||
*
|
||||
* @param visitorPort 访客端口
|
||||
* @param visitorSocket 访客socket
|
||||
*/
|
||||
public static <T> void pushVisitorSocket(Integer visitorPort, PermeateVisitorSocket visitorSocket) {
|
||||
VISITOR_PORT_SOCKET.put(visitorPort, visitorSocket);
|
||||
}
|
||||
/**
|
||||
* 通过访客端口获取访客
|
||||
*
|
||||
@ -28,8 +41,19 @@ public class NettyVisitorPortContext {
|
||||
* @param <T> 访客范型
|
||||
* @return 访客
|
||||
*/
|
||||
public static <T> T getVisitor(Integer visitorPort) {
|
||||
return (T) VISITOR_PORT.get(visitorPort);
|
||||
public static Channel getVisitorChannel(Integer visitorPort) {
|
||||
return VISITOR_PORT_CHANNEL.get(visitorPort);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过访客端口获取访客socket
|
||||
*
|
||||
* @param visitorPort 访客端口
|
||||
* @param <T> 访客范型
|
||||
* @return 访客
|
||||
*/
|
||||
public static PermeateVisitorSocket getVisitorSocket(Integer visitorPort) {
|
||||
return VISITOR_PORT_SOCKET.get(visitorPort);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -38,10 +62,25 @@ public class NettyVisitorPortContext {
|
||||
* @return 删除的访客通道
|
||||
* @param <T> 访客通道范型
|
||||
*/
|
||||
public static <T> T removeVisitor(Integer visitorPort){
|
||||
T visitor = getVisitor(visitorPort);
|
||||
public static Channel removeVisitorChannel(Integer visitorPort) {
|
||||
Channel visitor = getVisitorChannel(visitorPort);
|
||||
if(visitor!=null){
|
||||
VISITOR_PORT.remove(visitorPort);
|
||||
VISITOR_PORT_CHANNEL.remove(visitorPort);
|
||||
}
|
||||
return visitor;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除访客 socket
|
||||
*
|
||||
* @param visitorPort 访客通道
|
||||
* @param <T> 访客通道范型
|
||||
* @return 删除的访客通道
|
||||
*/
|
||||
public static PermeateVisitorSocket removeVisitorSocket(Integer visitorPort) {
|
||||
PermeateVisitorSocket visitor = getVisitorSocket(visitorPort);
|
||||
if (visitor != null) {
|
||||
VISITOR_PORT_SOCKET.remove(visitorPort);
|
||||
}
|
||||
return visitor;
|
||||
}
|
||||
|
@ -0,0 +1,28 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.common.advanced.client;
|
||||
|
||||
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.AbstractHandleChannelTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
|
||||
|
||||
|
||||
/**
|
||||
* 下发 客户端渗透服务端init close 信息
|
||||
*
|
||||
* @see MessageTypeEnums#DISTRIBUTE_CLIENT_PERMEATE_SERVER_CLOSE
|
||||
*/
|
||||
public abstract class AbstractHandleDistributeClientPermeateServerCloseTypeAdvanced<MSG> extends AbstractHandleChannelTypeAdvanced<NettyProxyMsg> implements HandleChannelTypeAdvanced {
|
||||
|
||||
|
||||
/**
|
||||
* 是否支持当前类型
|
||||
*
|
||||
* @param msg 通道数据
|
||||
* @return 布尔类型 是、否
|
||||
*/
|
||||
@Override
|
||||
public boolean doSupport(NettyProxyMsg msg) {
|
||||
return MessageTypeEnums.DISTRIBUTE_CLIENT_PERMEATE_SERVER_CLOSE.getTypeByte() == msg.getType();
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.common.advanced.server;
|
||||
|
||||
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.AbstractHandleChannelTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
|
||||
|
||||
|
||||
/**
|
||||
* 上报 客户端渗透服务端init close 信息
|
||||
* REPORT_CLIENT_PERMEATE_SERVER_CLOSE
|
||||
*/
|
||||
public abstract class AbstractHandleReportClientPermeateServerCloseTypeAdvanced<MSG> extends AbstractHandleChannelTypeAdvanced<NettyProxyMsg> implements HandleChannelTypeAdvanced {
|
||||
|
||||
|
||||
/**
|
||||
* 是否支持当前类型
|
||||
*
|
||||
* @param msg 通道数据
|
||||
* @return 布尔类型 是、否
|
||||
*/
|
||||
@Override
|
||||
public boolean doSupport(NettyProxyMsg msg) {
|
||||
return MessageTypeEnums.REPORT_CLIENT_PERMEATE_SERVER_CLOSE.getTypeByte() == msg.getType();
|
||||
}
|
||||
}
|
@ -66,6 +66,11 @@ public enum MessageTypeEnums {
|
||||
* @see AbstractHandleReportClientPermeateServerInitTypeAdvanced
|
||||
*/
|
||||
REPORT_CLIENT_PERMEATE_SERVER_INIT(MessageType.REPORT_CLIENT_PERMEATE_SERVER_INIT, "上报 客户端渗透服务端init信息"),
|
||||
/**
|
||||
* 上报 客户端渗透服务端init close 信息
|
||||
* @see AbstractHandleReportClientPermeateServerCloseTypeAdvanced
|
||||
*/
|
||||
REPORT_CLIENT_PERMEATE_SERVER_CLOSE(MessageType.REPORT_CLIENT_PERMEATE_SERVER_CLOSE, "上报 客户端渗透服务端init close 信息"),
|
||||
/**
|
||||
* @see AbstractHandleDistributeConnectSuccessNotificationTypeAdvancedHandle
|
||||
*/
|
||||
@ -121,6 +126,11 @@ public enum MessageTypeEnums {
|
||||
* @see AbstractHandleDistributeClientPermeateServerInitTypeAdvanced
|
||||
*/
|
||||
DISTRIBUTE_CLIENT_PERMEATE_SERVER_INIT(MessageType.DISTRIBUTE_CLIENT_PERMEATE_SERVER_INIT, "下发 客户端渗透服务端init信息"),
|
||||
|
||||
/**
|
||||
* @see AbstractHandleDistributeClientPermeateServerCloseTypeAdvanced
|
||||
*/
|
||||
DISTRIBUTE_CLIENT_PERMEATE_SERVER_CLOSE(MessageType.DISTRIBUTE_CLIENT_PERMEATE_SERVER_CLOSE, "下发 客户端渗透服务端init close信息"),
|
||||
;
|
||||
|
||||
private final byte typeByte;
|
||||
|
@ -0,0 +1,14 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.common.socket;
|
||||
|
||||
public interface PermeateVisitorSocket {
|
||||
|
||||
/**
|
||||
* 启动socket
|
||||
*/
|
||||
public void start() ;
|
||||
|
||||
/**
|
||||
* 关闭socket
|
||||
*/
|
||||
public void close() ;
|
||||
}
|
@ -4,17 +4,16 @@ package org.framework.lazy.cloud.network.heartbeat.server.netty.advanced;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelId;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.server.standalone.application.LazyClientStatsChangeApplication;
|
||||
import org.framework.lazy.cloud.network.heartbeat.server.netty.socket.NettyServerPermeateClientVisitorSocket;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.wu.framework.core.utils.ObjectUtils;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.ChannelContext;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.MessageType;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyClientVisitorContext;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.server.AbstractHandleReportDisconnectTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.server.netty.socket.NettyServerPermeateClientVisitorSocket;
|
||||
import org.framework.lazy.cloud.network.heartbeat.server.standalone.application.LazyClientStatsChangeApplication;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.wu.framework.core.utils.ObjectUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@ -75,12 +74,8 @@ public class ServerHandleReportDisconnectTypeAdvanced extends AbstractHandleRepo
|
||||
if (!ObjectUtils.isEmpty(visitorSockets)) {
|
||||
for (NettyServerPermeateClientVisitorSocket visitorSocket : visitorSockets) {
|
||||
int visitorPort = visitorSocket.getVisitorPort();
|
||||
try {
|
||||
visitorSocket.close();
|
||||
log.warn("client :[{}] visitorPort:[{}] close", new String(clientId), visitorPort);
|
||||
} catch (IOException | InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -130,7 +130,7 @@ public class NettyServerPermeateClientVisitorHandler extends SimpleChannelInboun
|
||||
return;
|
||||
}
|
||||
// 通信通道自动读写打开 ,然后关闭通信通道
|
||||
// Channel visitorChannel = NettyCommunicationIdContext.getVisitor(visitorId);
|
||||
// Channel visitorChannel = NettyCommunicationIdContext.getVisitorChannel(visitorId);
|
||||
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(ctx.channel());
|
||||
if (nextChannel != null && nextChannel.isActive()) {
|
||||
|
||||
|
@ -10,10 +10,9 @@ import org.framework.lazy.cloud.network.heartbeat.common.InternalNetworkPenetrat
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyClientVisitorContext;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyVisitorPortContext;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelFlowAdapter;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.socket.PermeateVisitorSocket;
|
||||
import org.framework.lazy.cloud.network.heartbeat.server.netty.filter.NettyServerPermeateClientVisitorFilter;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* 内网穿透服务端访客通道
|
||||
*
|
||||
@ -21,7 +20,7 @@ import java.io.IOException;
|
||||
* @see NettyClientVisitorContext
|
||||
*/
|
||||
@Slf4j
|
||||
public class NettyServerPermeateClientVisitorSocket {
|
||||
public class NettyServerPermeateClientVisitorSocket implements PermeateVisitorSocket {
|
||||
private final EventLoopGroup bossGroup = new NioEventLoopGroup();
|
||||
private final EventLoopGroup workerGroup = new NioEventLoopGroup();
|
||||
private final NettyServerPermeateClientVisitorFilter nettyServerPermeateClientVisitorFilter;
|
||||
@ -41,9 +40,10 @@ public class NettyServerPermeateClientVisitorSocket {
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public void startVisitorServer() throws Exception {
|
||||
@Override
|
||||
public void start() {
|
||||
|
||||
Channel visitor = NettyVisitorPortContext.getVisitor(visitorPort);
|
||||
Channel visitor = NettyVisitorPortContext.getVisitorChannel(visitorPort);
|
||||
if (visitor == null) {
|
||||
ServerBootstrap bootstrap = new ServerBootstrap();
|
||||
bootstrap
|
||||
@ -65,38 +65,43 @@ public class NettyServerPermeateClientVisitorSocket {
|
||||
|
||||
|
||||
.childHandler(nettyServerPermeateClientVisitorFilter);
|
||||
ChannelFuture sync = bootstrap.bind(visitorPort).sync();
|
||||
sync.addListener((ChannelFutureListener) future -> {
|
||||
try {
|
||||
bootstrap.bind(visitorPort).sync().addListener((ChannelFutureListener) future -> {
|
||||
if (future.isSuccess()) {
|
||||
// 这里时异步处理
|
||||
log.info("客户端:[{}]访客端口:[{}] 开启", clientId, visitorPort);
|
||||
NettyVisitorPortContext.pushVisitor(visitorPort, future.channel());
|
||||
NettyVisitorPortContext.pushVisitorChannel(visitorPort, future.channel());
|
||||
|
||||
} else {
|
||||
log.error("客户端:[{}]访客端口:[{}]绑定失败", clientId, visitorPort);
|
||||
}
|
||||
});
|
||||
NettyClientVisitorContext.pushVisitorSocket(clientId, this);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
} else {
|
||||
log.warn("客户端:[{}]访客端口:[{}] 重复启动", clientId, visitorPort);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void close() throws IOException, InterruptedException {
|
||||
@Override
|
||||
public void close() {
|
||||
if (!bossGroup.isShutdown()) {
|
||||
bossGroup.shutdownGracefully();
|
||||
}
|
||||
if (!workerGroup.isShutdown()) {
|
||||
workerGroup.shutdownGracefully();
|
||||
}
|
||||
Channel visitor = NettyVisitorPortContext.getVisitor(visitorPort);
|
||||
Channel visitor = NettyVisitorPortContext.getVisitorChannel(visitorPort);
|
||||
if (visitor != null) {
|
||||
|
||||
// close channel
|
||||
visitor.close();
|
||||
// remove visitor
|
||||
NettyVisitorPortContext.removeVisitor(visitorPort);
|
||||
NettyVisitorPortContext.removeVisitorChannel(visitorPort);
|
||||
// remove client this
|
||||
NettyClientVisitorContext.removeVisitorSocket(clientId,this);
|
||||
log.warn("关闭客户端 :【{}】 访客户端口:【{}】", clientId, visitorPort);
|
||||
|
@ -92,7 +92,7 @@ public class NettyServerPermeateServerConnectVisitorSocket {
|
||||
if (!workerGroup.isShutdown()) {
|
||||
workerGroup.shutdownGracefully();
|
||||
}
|
||||
Channel visitor = NettyVisitorPortContext.getVisitor(visitorPort);
|
||||
Channel visitor = NettyVisitorPortContext.getVisitorChannel(visitorPort);
|
||||
if (visitor != null) {
|
||||
// close channel
|
||||
visitor.close();
|
||||
|
@ -57,20 +57,7 @@ public class LazyInternalNetworkClientPermeateServerMappingApplicationImpl imple
|
||||
String serverId = serverNodeProperties.getNodeId();
|
||||
lazyInternalNetworkClientPermeateServerMapping.setServerId(serverId);
|
||||
// 发送客户端初始化渗透
|
||||
String clientId = lazyInternalNetworkClientPermeateServerMapping.getClientId();
|
||||
ChannelContext.ClientChannel clientChannel = ChannelContext.get(clientId);
|
||||
if(clientChannel!=null && clientChannel.getChannel()!=null&&clientChannel.getChannel().isActive()){
|
||||
Channel channel = clientChannel.getChannel();
|
||||
String permeateTargetIp = lazyInternalNetworkClientPermeateServerMapping.getPermeateTargetIp();
|
||||
Integer permeateTargetPort = lazyInternalNetworkClientPermeateServerMapping.getPermeateTargetPort();
|
||||
Integer visitorPort = lazyInternalNetworkClientPermeateServerMapping.getVisitorPort();
|
||||
NettyProxyMsg nettyMsg = new NettyProxyMsg();
|
||||
nettyMsg.setType(MessageType.DISTRIBUTE_CLIENT_PERMEATE_SERVER_INIT);
|
||||
nettyMsg.setClientTargetIp(permeateTargetIp);
|
||||
nettyMsg.setClientTargetPort(permeateTargetPort);
|
||||
nettyMsg.setVisitorPort(visitorPort);
|
||||
channel.writeAndFlush(nettyMsg);
|
||||
}
|
||||
createClientPermeateServerSocketMessage(lazyInternalNetworkClientPermeateServerMapping);
|
||||
return lazyInternalNetworkClientPermeateServerMappingRepository.story(lazyInternalNetworkClientPermeateServerMapping);
|
||||
}
|
||||
/**
|
||||
@ -89,6 +76,7 @@ public class LazyInternalNetworkClientPermeateServerMappingApplicationImpl imple
|
||||
for (LazyInternalNetworkClientPermeateServerMapping lazyInternalNetworkClientPermeateServerMapping : lazyInternalNetworkClientPermeateServerMappingList) {
|
||||
String serverId = serverNodeProperties.getNodeId();
|
||||
lazyInternalNetworkClientPermeateServerMapping.setServerId(serverId);
|
||||
createClientPermeateServerSocketMessage(lazyInternalNetworkClientPermeateServerMapping);
|
||||
}
|
||||
return lazyInternalNetworkClientPermeateServerMappingRepository.batchStory(lazyInternalNetworkClientPermeateServerMappingList);
|
||||
}
|
||||
@ -107,6 +95,13 @@ public class LazyInternalNetworkClientPermeateServerMappingApplicationImpl imple
|
||||
LazyInternalNetworkClientPermeateServerMapping lazyInternalNetworkClientPermeateServerMapping = LazyInternalNetworkClientPermeateServerMappingDTOAssembler.INSTANCE.toLazyInternalNetworkClientPermeateServerMapping(lazyInternalNetworkClientPermeateServerMappingUpdateCommand);
|
||||
String serverId = serverNodeProperties.getNodeId();
|
||||
lazyInternalNetworkClientPermeateServerMapping.setServerId(serverId);
|
||||
// 关闭
|
||||
LazyInternalNetworkClientPermeateServerMapping mapping = new LazyInternalNetworkClientPermeateServerMapping();
|
||||
mapping.setId(lazyInternalNetworkClientPermeateServerMapping.getId());
|
||||
lazyInternalNetworkClientPermeateServerMappingRepository.findOne(mapping).accept(this::closeClientPermeateServerSocketMessage);
|
||||
|
||||
|
||||
createClientPermeateServerSocketMessage(lazyInternalNetworkClientPermeateServerMapping);
|
||||
return lazyInternalNetworkClientPermeateServerMappingRepository.story(lazyInternalNetworkClientPermeateServerMapping);
|
||||
}
|
||||
|
||||
@ -174,4 +169,47 @@ public class LazyInternalNetworkClientPermeateServerMappingApplicationImpl imple
|
||||
return lazyInternalNetworkClientPermeateServerMappingRepository.remove(lazyInternalNetworkClientPermeateServerMapping);
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭 客户端渗透服务端socket 消息
|
||||
* @param lazyInternalNetworkClientPermeateServerMapping 客户端渗透服务端映射
|
||||
*/
|
||||
public void closeClientPermeateServerSocketMessage(LazyInternalNetworkClientPermeateServerMapping lazyInternalNetworkClientPermeateServerMapping){
|
||||
// 发送客户端初始化渗透
|
||||
String clientId = lazyInternalNetworkClientPermeateServerMapping.getClientId();
|
||||
ChannelContext.ClientChannel clientChannel = ChannelContext.get(clientId);
|
||||
if(clientChannel!=null && clientChannel.getChannel()!=null&&clientChannel.getChannel().isActive()){
|
||||
Channel channel = clientChannel.getChannel();
|
||||
String permeateTargetIp = lazyInternalNetworkClientPermeateServerMapping.getPermeateTargetIp();
|
||||
Integer permeateTargetPort = lazyInternalNetworkClientPermeateServerMapping.getPermeateTargetPort();
|
||||
Integer visitorPort = lazyInternalNetworkClientPermeateServerMapping.getVisitorPort();
|
||||
NettyProxyMsg nettyMsg = new NettyProxyMsg();
|
||||
nettyMsg.setType(MessageType.DISTRIBUTE_CLIENT_PERMEATE_SERVER_CLOSE);
|
||||
nettyMsg.setClientTargetIp(permeateTargetIp);
|
||||
nettyMsg.setClientTargetPort(permeateTargetPort);
|
||||
nettyMsg.setVisitorPort(visitorPort);
|
||||
channel.writeAndFlush(nettyMsg);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建 客户端渗透服务端socket 消息
|
||||
* @param lazyInternalNetworkClientPermeateServerMapping 客户端渗透服务端映射
|
||||
*/
|
||||
public void createClientPermeateServerSocketMessage(LazyInternalNetworkClientPermeateServerMapping lazyInternalNetworkClientPermeateServerMapping){
|
||||
// 发送客户端初始化渗透
|
||||
String clientId = lazyInternalNetworkClientPermeateServerMapping.getClientId();
|
||||
ChannelContext.ClientChannel clientChannel = ChannelContext.get(clientId);
|
||||
if(clientChannel!=null && clientChannel.getChannel()!=null&&clientChannel.getChannel().isActive()){
|
||||
Channel channel = clientChannel.getChannel();
|
||||
String permeateTargetIp = lazyInternalNetworkClientPermeateServerMapping.getPermeateTargetIp();
|
||||
Integer permeateTargetPort = lazyInternalNetworkClientPermeateServerMapping.getPermeateTargetPort();
|
||||
Integer visitorPort = lazyInternalNetworkClientPermeateServerMapping.getVisitorPort();
|
||||
NettyProxyMsg nettyMsg = new NettyProxyMsg();
|
||||
nettyMsg.setType(MessageType.DISTRIBUTE_CLIENT_PERMEATE_SERVER_INIT);
|
||||
nettyMsg.setClientTargetIp(permeateTargetIp);
|
||||
nettyMsg.setClientTargetPort(permeateTargetPort);
|
||||
nettyMsg.setVisitorPort(visitorPort);
|
||||
channel.writeAndFlush(nettyMsg);
|
||||
}
|
||||
}
|
||||
}
|
@ -164,11 +164,8 @@ public class LazyInternalNetworkPenetrationMappingApplicationImpl implements Laz
|
||||
if (!ObjectUtils.isEmpty(nettyServerPermeateClientVisitorSocketList)) {
|
||||
// 关闭端口
|
||||
for (NettyServerPermeateClientVisitorSocket nettyServerPermeateClientVisitorSocket : nettyServerPermeateClientVisitorSocketList) {
|
||||
try {
|
||||
nettyServerPermeateClientVisitorSocket.close();
|
||||
} catch (IOException | InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -291,7 +288,7 @@ public class LazyInternalNetworkPenetrationMappingApplicationImpl implements Laz
|
||||
.builderChannelFlowAdapter(channelFlowAdapter)
|
||||
.build();
|
||||
try {
|
||||
nettyServerPermeateClientVisitorSocket.startVisitorServer();
|
||||
nettyServerPermeateClientVisitorSocket.start();
|
||||
} catch (Exception e) {
|
||||
log.error("客户端:{},网络端口:{},开放失败", clientId, visitorPort);
|
||||
throw new RuntimeException(e);
|
||||
|
@ -1,28 +1,27 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.server.standalone.application.impl;
|
||||
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.ChannelContext;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.MessageType;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyClientVisitorContext;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.server.netty.socket.NettyServerPermeateClientVisitorSocket;
|
||||
import org.framework.lazy.cloud.network.heartbeat.server.properties.ServerNodeProperties;
|
||||
import org.framework.lazy.cloud.network.heartbeat.server.standalone.application.LazyNettyClientStateApplication;
|
||||
import org.framework.lazy.cloud.network.heartbeat.server.standalone.application.assembler.NettyClientStateDTOAssembler;
|
||||
import org.framework.lazy.cloud.network.heartbeat.server.standalone.application.command.netty.client.state.*;
|
||||
import org.framework.lazy.cloud.network.heartbeat.server.standalone.application.dto.LazyNettyClientStateDTO;
|
||||
import org.framework.lazy.cloud.network.heartbeat.server.standalone.domain.model.lazy.netty.client.state.LazyNettyClientState;
|
||||
import org.framework.lazy.cloud.network.heartbeat.server.standalone.domain.model.lazy.netty.client.state.LazyNettyClientStateRepository;
|
||||
import org.framework.lazy.cloud.network.heartbeat.server.standalone.application.dto.LazyNettyClientStateDTO;
|
||||
import org.wu.framework.core.utils.ObjectUtils;
|
||||
import org.wu.framework.database.lazy.web.plus.stereotype.LazyApplication;
|
||||
import org.wu.framework.lazy.orm.core.persistence.reverse.lazy.ddd.DefaultDDDLazyApplicationImpl;
|
||||
import org.wu.framework.lazy.orm.database.lambda.domain.LazyPage;
|
||||
import org.wu.framework.web.response.Result;
|
||||
import org.wu.framework.web.response.ResultFactory;
|
||||
import io.netty.channel.Channel;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.wu.framework.core.utils.ObjectUtils;
|
||||
import org.wu.framework.lazy.orm.core.persistence.reverse.lazy.ddd.DefaultDDDLazyApplicationImpl;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.ChannelContext;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.MessageType;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyClientVisitorContext;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
@ -173,11 +172,7 @@ public class LazyNettyClientStateApplicationImpl implements LazyNettyClientState
|
||||
List<NettyServerPermeateClientVisitorSocket> nettyServerPermeateClientVisitorSocketList = NettyClientVisitorContext.getVisitorSockets(clientId);
|
||||
if (!ObjectUtils.isEmpty(nettyServerPermeateClientVisitorSocketList)) {
|
||||
for (NettyServerPermeateClientVisitorSocket nettyServerPermeateClientVisitorSocket : nettyServerPermeateClientVisitorSocketList) {
|
||||
try {
|
||||
nettyServerPermeateClientVisitorSocket.close();
|
||||
} catch (IOException | InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
return lazyNettyClientStateRepository.remove(lazyNettyClientState);
|
||||
|
Loading…
x
Reference in New Issue
Block a user