[fix] 添加namespace

This commit is contained in:
wujiawei
2025-06-11 16:19:11 +08:00
parent 51b603a6c5
commit 3163987ef7
208 changed files with 1011 additions and 828 deletions

View File

@ -22,8 +22,8 @@ public class LazyNettyServerPropertiesQueryListCommand {
/** /**
* 命名空间 * 命名空间
*/ */
@Schema(description ="命名空间",name ="serverId",example = "") @Schema(description ="命名空间",name ="namespace",example = "")
private String serverId; private String namespace;
/** /**
* *
* 客户身份ID * 客户身份ID

View File

@ -26,8 +26,8 @@ public class LazyNettyServerPropertiesQueryOneCommand {
/** /**
* 命名空间 * 命名空间
*/ */
@Schema(description ="命名空间",name ="serverId",example = "") @Schema(description ="命名空间",name ="namespace",example = "")
private String serverId; private String namespace;
/** /**
* *
* 客户身份ID * 客户身份ID

View File

@ -26,8 +26,8 @@ public class LazyNettyServerPropertiesRemoveCommand {
/** /**
* 命名空间 * 命名空间
*/ */
@Schema(description ="命名空间",name ="serverId",example = "") @Schema(description ="命名空间",name ="namespace",example = "")
private String serverId; private String namespace;
/** /**
* *
* 客户身份ID * 客户身份ID

View File

@ -26,8 +26,8 @@ public class LazyNettyServerPropertiesStoryCommand {
/** /**
* 命名空间 * 命名空间
*/ */
@Schema(description ="命名空间",name ="serverId",example = "") @Schema(description ="命名空间",name ="namespace",example = "")
private String serverId; private String namespace;
/** /**
* *
* 客户身份ID * 客户身份ID

View File

@ -25,8 +25,8 @@ public class LazyNettyServerPropertiesUpdateCommand {
/** /**
* 命名空间 * 命名空间
*/ */
@Schema(description ="命名空间",name ="serverId",example = "") @Schema(description ="命名空间",name ="namespace",example = "")
private String serverId; private String namespace;
/** /**
* *

View File

@ -23,8 +23,8 @@ public class LazyNettyServerPropertiesDTO {
/** /**
* 命名空间 * 命名空间
*/ */
@Schema(description = "命名空间", name = "serverId", example = "") @Schema(description = "命名空间", name = "namespace", example = "")
private String serverId; private String namespace;
/** /**
* *
* 客户身份ID * 客户身份ID

View File

@ -185,7 +185,7 @@ public class LazyNettyServerPropertiesApplicationImpl implements LazyNettyServer
public void starterOneClientSocket(LazyNettyServerProperties lazyNettyServerProperties) { public void starterOneClientSocket(LazyNettyServerProperties lazyNettyServerProperties) {
boolean enabled = nettyClientProperties.isEnabled(); boolean enabled = nettyClientProperties.isEnabled();
if (enabled) { if (enabled) {
String serverId = lazyNettyServerProperties.getServerId(); String namespace = lazyNettyServerProperties.getNamespace();
String inetHost = lazyNettyServerProperties.getInetHost(); String inetHost = lazyNettyServerProperties.getInetHost();
Integer inetPort = lazyNettyServerProperties.getInetPort(); Integer inetPort = lazyNettyServerProperties.getInetPort();
String clientId = lazyNettyServerProperties.getClientId(); String clientId = lazyNettyServerProperties.getClientId();
@ -196,12 +196,12 @@ public class LazyNettyServerPropertiesApplicationImpl implements LazyNettyServer
if (ProtocolType.TCP.equals(protocolType)) { if (ProtocolType.TCP.equals(protocolType)) {
nettyClientSocket = new nettyClientSocket = new
NettyTcpClientSocket(inetHost, inetPort, clientId, NettyTcpClientSocket(inetHost, inetPort, clientId,
serverId, appKey, appSecret, namespace, appKey, appSecret,
clientChangeEvent, handleChannelTypeAdvancedList); clientChangeEvent, handleChannelTypeAdvancedList);
} else if (ProtocolType.UDP.equals(protocolType)) { } else if (ProtocolType.UDP.equals(protocolType)) {
nettyClientSocket = new nettyClientSocket = new
NettyUdpClientSocket(inetHost, inetPort, clientId, NettyUdpClientSocket(inetHost, inetPort, clientId,
serverId, appKey, appSecret, namespace, appKey, appSecret,
clientChangeEvent, handleChannelTypeAdvancedList); clientChangeEvent, handleChannelTypeAdvancedList);
} else { } else {
nettyClientSocket = null; nettyClientSocket = null;

View File

@ -18,7 +18,7 @@ public class NettyClientProperties {
/** /**
* 命名空间 * 命名空间
*/ */
private String serverId= NormalUsedString.DEFAULT; private String namespace= NormalUsedString.DEFAULT;
/** /**
* 服务端地址 如127.0.0.1 * 服务端地址 如127.0.0.1
*/ */

View File

@ -46,14 +46,14 @@ public class NettyClientSocketApplicationListener implements ApplicationListener
String appKey = nettyClientProperties.getAppKey(); String appKey = nettyClientProperties.getAppKey();
String appSecret = nettyClientProperties.getAppSecret(); String appSecret = nettyClientProperties.getAppSecret();
ProtocolType protocolType = nettyClientProperties.getProtocolType(); ProtocolType protocolType = nettyClientProperties.getProtocolType();
String serverId = nettyClientProperties.getServerId(); String namespace = nettyClientProperties.getNamespace();
if (Objects.isNull(clientId) || if (Objects.isNull(clientId) ||
Objects.isNull(inetHost)) { Objects.isNull(inetHost)) {
log.warn("配置信息为空,请通过页面添加配置信息:{}", nettyClientProperties); log.warn("配置信息为空,请通过页面添加配置信息:{}", nettyClientProperties);
return; return;
} }
LazyNettyServerPropertiesDO lazyNettyServerPropertiesDO = new LazyNettyServerPropertiesDO(); LazyNettyServerPropertiesDO lazyNettyServerPropertiesDO = new LazyNettyServerPropertiesDO();
lazyNettyServerPropertiesDO.setServerId(serverId); lazyNettyServerPropertiesDO.setNamespace(namespace);
lazyNettyServerPropertiesDO.setClientId(clientId); lazyNettyServerPropertiesDO.setClientId(clientId);
lazyNettyServerPropertiesDO.setInetHost(inetHost); lazyNettyServerPropertiesDO.setInetHost(inetHost);
lazyNettyServerPropertiesDO.setInetPort(inetPort); lazyNettyServerPropertiesDO.setInetPort(inetPort);
@ -66,7 +66,7 @@ public class NettyClientSocketApplicationListener implements ApplicationListener
// 根据服务端端口、port 唯一性验证 // 根据服务端端口、port 唯一性验证
boolean exists = lazyLambdaStream.exists(LazyWrappers.<LazyNettyServerPropertiesDO>lambdaWrapper() boolean exists = lazyLambdaStream.exists(LazyWrappers.<LazyNettyServerPropertiesDO>lambdaWrapper()
.eq(LazyNettyServerPropertiesDO::getServerId, serverId) .eq(LazyNettyServerPropertiesDO::getNamespace, namespace)
.eq(LazyNettyServerPropertiesDO::getInetHost, inetHost) .eq(LazyNettyServerPropertiesDO::getInetHost, inetHost)
.eq(LazyNettyServerPropertiesDO::getInetPort, inetPort) .eq(LazyNettyServerPropertiesDO::getInetPort, inetPort)
.eq(LazyNettyServerPropertiesDO::getClientId, clientId) .eq(LazyNettyServerPropertiesDO::getClientId, clientId)

View File

@ -26,7 +26,7 @@ public class LazyNettyServerProperties {
* 命名空间 * 命名空间
*/ */
@Schema(description ="命名空间",name ="namespace",example = "") @Schema(description ="命名空间",name ="namespace",example = "")
private String serverId; private String namespace;
/** /**
* *
* 客户身份ID * 客户身份ID

View File

@ -29,9 +29,9 @@ public class LazyNettyServerPropertiesDO {
/** /**
* 命名空间 * 命名空间
*/ */
@Schema(description ="命名空间",name ="serverId",example = "") @Schema(description ="命名空间",name ="namespace",example = "")
@LazyTableFieldUnique(name="server_id",comment="命名空间",columnType="varchar(25)",defaultValue = "DEFAULT") @LazyTableFieldUnique(name="namespace",comment="命名空间",columnType="varchar(25)",defaultValue = "DEFAULT")
private String serverId; private String namespace;
/** /**
* *

View File

@ -40,7 +40,7 @@ public class LazyNettyServerPropertiesRepositoryImpl implements LazyNettyServerP
@Override @Override
public Result<LazyNettyServerProperties> story(LazyNettyServerProperties lazyNettyServerProperties) { public Result<LazyNettyServerProperties> story(LazyNettyServerProperties lazyNettyServerProperties) {
LazyNettyServerPropertiesDO lazyNettyServerPropertiesDO = LazyNettyServerPropertiesConverter.INSTANCE.fromLazyNettyServerProperties(lazyNettyServerProperties); LazyNettyServerPropertiesDO lazyNettyServerPropertiesDO = LazyNettyServerPropertiesConverter.INSTANCE.fromLazyNettyServerProperties(lazyNettyServerProperties);
String serverId = lazyNettyServerPropertiesDO.getServerId(); String namespace = lazyNettyServerPropertiesDO.getNamespace();
String inetHost = lazyNettyServerPropertiesDO.getInetHost(); String inetHost = lazyNettyServerPropertiesDO.getInetHost();
Integer inetPort = lazyNettyServerPropertiesDO.getInetPort(); Integer inetPort = lazyNettyServerPropertiesDO.getInetPort();
String clientId = lazyNettyServerPropertiesDO.getClientId(); String clientId = lazyNettyServerPropertiesDO.getClientId();
@ -48,7 +48,7 @@ public class LazyNettyServerPropertiesRepositoryImpl implements LazyNettyServerP
// 查询 ip、端口、客户端 // 查询 ip、端口、客户端
boolean exists = lazyLambdaStream.exists(LazyWrappers.<LazyNettyServerPropertiesDO>lambdaWrapper() boolean exists = lazyLambdaStream.exists(LazyWrappers.<LazyNettyServerPropertiesDO>lambdaWrapper()
.eq(LazyNettyServerPropertiesDO::getServerId, serverId) .eq(LazyNettyServerPropertiesDO::getNamespace, namespace)
.eq(LazyNettyServerPropertiesDO::getInetHost, inetHost) .eq(LazyNettyServerPropertiesDO::getInetHost, inetHost)
.eq(LazyNettyServerPropertiesDO::getInetPort, inetPort) .eq(LazyNettyServerPropertiesDO::getInetPort, inetPort)
.eq(LazyNettyServerPropertiesDO::getClientId, clientId) .eq(LazyNettyServerPropertiesDO::getClientId, clientId)
@ -56,7 +56,7 @@ public class LazyNettyServerPropertiesRepositoryImpl implements LazyNettyServerP
if (exists) { if (exists) {
// 更新 // 更新
lazyLambdaStream.update(lazyNettyServerPropertiesDO, LazyWrappers.<LazyNettyServerPropertiesDO>lambdaWrapper() lazyLambdaStream.update(lazyNettyServerPropertiesDO, LazyWrappers.<LazyNettyServerPropertiesDO>lambdaWrapper()
.eq(LazyNettyServerPropertiesDO::getServerId, serverId) .eq(LazyNettyServerPropertiesDO::getNamespace, namespace)
.eq(LazyNettyServerPropertiesDO::getInetHost, inetHost) .eq(LazyNettyServerPropertiesDO::getInetHost, inetHost)
.eq(LazyNettyServerPropertiesDO::getInetPort, inetPort) .eq(LazyNettyServerPropertiesDO::getInetPort, inetPort)
.eq(LazyNettyServerPropertiesDO::getClientId, clientId) .eq(LazyNettyServerPropertiesDO::getClientId, clientId)

View File

@ -13,6 +13,10 @@ import java.util.List;
@Data @Data
public class NettyClientPermeateClientVisitor implements InternalNetworkPermeate { public class NettyClientPermeateClientVisitor implements InternalNetworkPermeate {
/**
* namespace
*/
private String namespace;
/** /**
* 当前客户端ID * 当前客户端ID
*/ */

View File

@ -31,9 +31,11 @@ public class ClientHandleTcpClientChannelActiveAdvanced extends AbstractHandleTc
protected void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg nettyProxyMsg) { protected void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg nettyProxyMsg) {
Channel channel = nettyChannelContext.channel(); Channel channel = nettyChannelContext.channel();
// 缓存当前通道 // 缓存当前通道
byte[] clientIdByte = nettyProxyMsg.getClientId(); String clientId = nettyProxyMsg.clientId();
String clientId = new String(clientIdByte); String serverId = nettyProxyMsg.namespace();
ChannelContext.push(channel, clientId);
ChannelContext.push(channel, serverId, clientId);
ChannelAttributeKeyUtils.buildClientId(channel, clientId); ChannelAttributeKeyUtils.buildClientId(channel, clientId);
} }
} }

View File

@ -24,7 +24,8 @@ import java.util.List;
*/ */
@Role(BeanDefinition.ROLE_INFRASTRUCTURE) @Role(BeanDefinition.ROLE_INFRASTRUCTURE)
@Slf4j @Slf4j
public class ClientHandleTcpDistributeClientPermeateClientInitTypeAdvanced extends AbstractHandleTcpDistributeClientPermeateClientInitTypeAdvanced<NettyProxyMsg> { public class ClientHandleTcpDistributeClientPermeateClientInitTypeAdvanced
extends AbstractHandleTcpDistributeClientPermeateClientInitTypeAdvanced<NettyProxyMsg> {
/** /**
* 处理当前数据 * 处理当前数据
@ -35,6 +36,7 @@ public class ClientHandleTcpDistributeClientPermeateClientInitTypeAdvanced exten
@Override @Override
public void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg nettyProxyMsg) { public void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg nettyProxyMsg) {
// 初始化 客户端渗透服务端socket // 初始化 客户端渗透服务端socket
String namespace = nettyProxyMsg.namespace();
byte[] fromClientIdBytes = nettyProxyMsg.getClientId(); byte[] fromClientIdBytes = nettyProxyMsg.getClientId();
byte[] visitorPortBytes = nettyProxyMsg.getVisitorPort(); byte[] visitorPortBytes = nettyProxyMsg.getVisitorPort();
byte[] clientTargetIpBytes = nettyProxyMsg.getClientTargetIp(); byte[] clientTargetIpBytes = nettyProxyMsg.getClientTargetIp();
@ -54,6 +56,7 @@ public class ClientHandleTcpDistributeClientPermeateClientInitTypeAdvanced exten
fromClientId, toClientId, visitorPort, clientTargetIp, clientTargetPort); fromClientId, toClientId, visitorPort, clientTargetIp, clientTargetPort);
NettyTcpClientPermeateClientVisitorSocket nettyTcpClientPermeateClientVisitorSocket = NettyTcpClientPermeateClientVisitorSocket nettyTcpClientPermeateClientVisitorSocket =
NettyTcpClientPermeateClientVisitorSocket.NettyClientPermeateClientVisitorSocketBuilder.builder() NettyTcpClientPermeateClientVisitorSocket.NettyClientPermeateClientVisitorSocketBuilder.builder()
.builderNamespace(namespace)
.builderClientId(fromClientId) .builderClientId(fromClientId)
.builderClientTargetIp(clientTargetIp) .builderClientTargetIp(clientTargetIp)
.builderClientTargetPort(clientTargetPort) .builderClientTargetPort(clientTargetPort)

View File

@ -8,9 +8,9 @@ import io.netty.handler.timeout.IdleState;
import io.netty.handler.timeout.IdleStateEvent; import io.netty.handler.timeout.IdleStateEvent;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.socket.NettyTcpClientSocket; import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.socket.NettyTcpClientSocket;
import org.framework.lazy.cloud.network.heartbeat.common.constant.TcpMessageType;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelTypeAdapter; import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelTypeAdapter;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.constant.TcpMessageType;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Date; import java.util.Date;
@ -59,11 +59,13 @@ public class NettyTcpClientHandler extends SimpleChannelInboundHandler<NettyProx
log.info("When establishing a connection{}" , new Date()); log.info("When establishing a connection{}" , new Date());
ctx.fireChannelActive(); ctx.fireChannelActive();
String clientId = nettyTcpClientSocket.getClientId(); String clientId = nettyTcpClientSocket.getClientId();
String namespace = nettyTcpClientSocket.getNamespace();
// 处理客户端连接成功 // 处理客户端连接成功
Channel channel = ctx.channel(); Channel channel = ctx.channel();
NettyProxyMsg nettyMsg = new NettyProxyMsg(); NettyProxyMsg nettyMsg = new NettyProxyMsg();
nettyMsg.setType(TcpMessageType.TCP_CLIENT_CHANNEL_ACTIVE); nettyMsg.setType(TcpMessageType.TCP_CLIENT_CHANNEL_ACTIVE);
nettyMsg.setClientId(clientId); nettyMsg.setClientId(clientId);
nettyMsg.setNamespace(namespace);
channelTypeAdapter.handler(ctx, nettyMsg); channelTypeAdapter.handler(ctx, nettyMsg);
@ -76,7 +78,7 @@ public class NettyTcpClientHandler extends SimpleChannelInboundHandler<NettyProx
public void channelInactive(ChannelHandlerContext ctx) throws Exception { public void channelInactive(ChannelHandlerContext ctx) throws Exception {
//服务端主动关闭当前客户端连接时 //服务端主动关闭当前客户端连接时
log.info("When the server actively closes the current client connection{}" , new Date()); log.info("When the server actively closes the current client connection{}" , new Date());
final EventLoop eventLoop = ctx.channel().eventLoop(); EventLoop eventLoop = ctx.channel().eventLoop();
eventLoop.schedule(() -> { eventLoop.schedule(() -> {
try { try {
nettyTcpClientSocket.newConnect2Server(); nettyTcpClientSocket.newConnect2Server();

View File

@ -114,6 +114,10 @@ public class NettyTcpClientPermeateClientVisitorSocket implements PermeateVisito
public static final class NettyClientPermeateClientVisitorSocketBuilder { public static final class NettyClientPermeateClientVisitorSocketBuilder {
/**
* namespace
*/
private String namespace;
/** /**
* 客户端ID * 客户端ID
*/ */
@ -161,6 +165,16 @@ public class NettyTcpClientPermeateClientVisitorSocket implements PermeateVisito
return new NettyClientPermeateClientVisitorSocketBuilder(); return new NettyClientPermeateClientVisitorSocketBuilder();
} }
/**
* 填充客户端
*
* @param clientId 客户端
* @return 返回当前对象
*/
public NettyClientPermeateClientVisitorSocketBuilder builderNamespace(String namespace) {
this.namespace = namespace;
return this;
}
/** /**
* 填充客户端 * 填充客户端
* *
@ -257,6 +271,9 @@ public class NettyTcpClientPermeateClientVisitorSocket implements PermeateVisito
return this; return this;
} }
public NettyTcpClientPermeateClientVisitorSocket build() { public NettyTcpClientPermeateClientVisitorSocket build() {
if (namespace == null) {
throw new IllegalArgumentException("namespace must not null");
}
if (clientTargetIp == null) { if (clientTargetIp == null) {
throw new IllegalArgumentException("clientTargetIp must not null"); throw new IllegalArgumentException("clientTargetIp must not null");
} }
@ -268,6 +285,7 @@ public class NettyTcpClientPermeateClientVisitorSocket implements PermeateVisito
} }
NettyClientPermeateClientVisitor nettyClientPermeateClientVisitor = new NettyClientPermeateClientVisitor(); NettyClientPermeateClientVisitor nettyClientPermeateClientVisitor = new NettyClientPermeateClientVisitor();
nettyClientPermeateClientVisitor.setNamespace(namespace);
nettyClientPermeateClientVisitor.setFromClientId(nettyClientProperties.getClientId()); nettyClientPermeateClientVisitor.setFromClientId(nettyClientProperties.getClientId());
nettyClientPermeateClientVisitor.setToClientId(toClientId); nettyClientPermeateClientVisitor.setToClientId(toClientId);
nettyClientPermeateClientVisitor.setTargetIp(clientTargetIp); nettyClientPermeateClientVisitor.setTargetIp(clientTargetIp);

View File

@ -46,6 +46,7 @@ public class NettyTcpClientPermeateClientVisitorTransferSocket {
.handler(new NettyTcpClientPermeateClientTransferFilter(new ChannelTypeAdapter(nettyClientPermeateClientVisitor.getHandleChannelTypeAdvancedList()))) .handler(new NettyTcpClientPermeateClientTransferFilter(new ChannelTypeAdapter(nettyClientPermeateClientVisitor.getHandleChannelTypeAdvancedList())))
; ;
NettyClientProperties nettyClientProperties = nettyClientPermeateClientVisitor.getNettyClientProperties(); NettyClientProperties nettyClientProperties = nettyClientPermeateClientVisitor.getNettyClientProperties();
String namespace = nettyClientProperties.getNamespace();
String inetHost = nettyClientProperties.getInetHost(); String inetHost = nettyClientProperties.getInetHost();
int inetPort = nettyClientProperties.getInetPort(); int inetPort = nettyClientProperties.getInetPort();
// local client id // local client id
@ -70,6 +71,7 @@ public class NettyTcpClientPermeateClientVisitorTransferSocket {
NettyProxyMsg nettyProxyMsg = new NettyProxyMsg(); NettyProxyMsg nettyProxyMsg = new NettyProxyMsg();
nettyProxyMsg.setType(TcpMessageType.TCP_REPORT_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL); nettyProxyMsg.setType(TcpMessageType.TCP_REPORT_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL);
nettyProxyMsg.setNamespace(namespace);
// other clientId // other clientId
nettyProxyMsg.setClientId(toClientId); nettyProxyMsg.setClientId(toClientId);
nettyProxyMsg.setVisitorPort(visitorPort); nettyProxyMsg.setVisitorPort(visitorPort);

View File

@ -44,7 +44,8 @@ public class NettyTcpClientSocket implements NettyClientSocket {
/** /**
* 当前连接的服务端ID * 当前连接的服务端ID
*/ */
private final String serverId; @Getter
private final String namespace;
private final String appKey; private final String appKey;
private final String appSecret; private final String appSecret;
/** /**
@ -57,7 +58,7 @@ public class NettyTcpClientSocket implements NettyClientSocket {
public NettyTcpClientSocket(String inetHost, public NettyTcpClientSocket(String inetHost,
int inetPort, int inetPort,
String clientId, String clientId,
String serverId, String namespace,
String appKey, String appKey,
String appSecret, String appSecret,
ClientChangeEvent clientChangeEvent, ClientChangeEvent clientChangeEvent,
@ -65,7 +66,7 @@ public class NettyTcpClientSocket implements NettyClientSocket {
this.inetHost = inetHost; this.inetHost = inetHost;
this.inetPort = inetPort; this.inetPort = inetPort;
this.clientId = clientId; this.clientId = clientId;
this.serverId = serverId; this.namespace = namespace;
this.appKey = appKey; this.appKey = appKey;
this.appSecret = appSecret; this.appSecret = appSecret;
this.clientChangeEvent = clientChangeEvent; this.clientChangeEvent = clientChangeEvent;
@ -88,7 +89,7 @@ public class NettyTcpClientSocket implements NettyClientSocket {
.option(ChannelOption.WRITE_BUFFER_WATER_MARK, new WriteBufferWaterMark(1024 * 1024, 1024 * 1024 * 2)) .option(ChannelOption.WRITE_BUFFER_WATER_MARK, new WriteBufferWaterMark(1024 * 1024, 1024 * 1024 * 2))
.handler(new NettyTcpClientFilter(new ChannelTypeAdapter(handleChannelTypeAdvancedList), this)) .handler(new NettyTcpClientFilter(new ChannelTypeAdapter(handleChannelTypeAdvancedList), this))
; ;
log.info("use clientId:{} connect to server serverId:{}, IP:{},server port :{}", clientId, serverId, inetHost, inetPort); log.info("use clientId:{} connect to server namespace:{}, IP:{},server port :{}", clientId, serverId, inetHost, inetPort);
ChannelFuture future = bootstrap.connect(inetHost, inetPort); ChannelFuture future = bootstrap.connect(inetHost, inetPort);
// 客户端连接服务端的channel // 客户端连接服务端的channel
Channel serviceChannel = future.channel(); Channel serviceChannel = future.channel();
@ -96,11 +97,12 @@ public class NettyTcpClientSocket implements NettyClientSocket {
future.addListener((ChannelFutureListener) futureListener -> { future.addListener((ChannelFutureListener) futureListener -> {
if (futureListener.isSuccess()) { if (futureListener.isSuccess()) {
log.info("clientId:{},connect to serverId:{}, server IP:{},server port :{} isSuccess ", clientId, serverId, inetHost, inetPort); log.info("clientId:{},connect to namespace:{}, server IP:{},server port :{} isSuccess ", clientId, serverId, inetHost, inetPort);
// 告诉服务端这条连接是client的连接 // 告诉服务端这条连接是client的连接
NettyProxyMsg nettyMsg = new NettyProxyMsg(); NettyProxyMsg nettyMsg = new NettyProxyMsg();
nettyMsg.setType(TcpMessageType.TCP_REPORT_CLIENT_CONNECT_SUCCESS); nettyMsg.setType(TcpMessageType.TCP_REPORT_CLIENT_CONNECT_SUCCESS);
nettyMsg.setClientId(clientId); nettyMsg.setClientId(clientId);
nettyMsg.setNamespace(serverId);
String hostAddress = InetAddress.getLocalHost().getHostAddress(); String hostAddress = InetAddress.getLocalHost().getHostAddress();
nettyMsg.setOriginalIpString(hostAddress); nettyMsg.setOriginalIpString(hostAddress);
nettyMsg.setData((clientId).getBytes()); nettyMsg.setData((clientId).getBytes());
@ -145,6 +147,6 @@ public class NettyTcpClientSocket implements NettyClientSocket {
*/ */
@Override @Override
public void newConnect2Server() throws InterruptedException { public void newConnect2Server() throws InterruptedException {
newTcpConnect2Server(inetHost, inetPort, clientId, serverId, clientChangeEvent); newTcpConnect2Server(inetHost, inetPort, clientId, namespace, clientChangeEvent);
} }
} }

View File

@ -32,8 +32,10 @@ public class ClientHandleUdpClientChannelActiveAdvanced extends AbstractHandleUd
Channel channel = nettyChannelContext.channel(); Channel channel = nettyChannelContext.channel();
// 缓存当前通道 // 缓存当前通道
byte[] clientIdByte = nettyProxyMsg.getClientId(); byte[] clientIdByte = nettyProxyMsg.getClientId();
byte[] serverIdByte = nettyProxyMsg.getNamespace();
String clientId = new String(clientIdByte); String clientId = new String(clientIdByte);
ChannelContext.push(channel, clientId); String serverId = new String(clientIdByte);
ChannelContext.push(channel,serverId, clientId);
ChannelAttributeKeyUtils.buildClientId(channel, clientId); ChannelAttributeKeyUtils.buildClientId(channel, clientId);
} }
} }

View File

@ -59,11 +59,13 @@ public class NettyUdpClientHandler extends SimpleChannelInboundHandler<NettyProx
log.info("When establishing a connection{}" , new Date()); log.info("When establishing a connection{}" , new Date());
ctx.fireChannelActive(); ctx.fireChannelActive();
String clientId = nettyUdpClientSocket.getClientId(); String clientId = nettyUdpClientSocket.getClientId();
String serverId = nettyUdpClientSocket.getNamespace();
// 处理客户端连接成功 // 处理客户端连接成功
Channel channel = ctx.channel(); Channel channel = ctx.channel();
NettyProxyMsg nettyMsg = new NettyProxyMsg(); NettyProxyMsg nettyMsg = new NettyProxyMsg();
nettyMsg.setType(UdpMessageType.UDP_CLIENT_CHANNEL_ACTIVE); nettyMsg.setType(UdpMessageType.UDP_CLIENT_CHANNEL_ACTIVE);
nettyMsg.setClientId(clientId); nettyMsg.setClientId(clientId);
nettyMsg.setNamespace(serverId);
channelTypeAdapter.handler(ctx, nettyMsg); channelTypeAdapter.handler(ctx, nettyMsg);

View File

@ -46,6 +46,7 @@ public class NettyUdpClientPermeateClientVisitorTransferSocket {
.handler(new NettyUdpClientPermeateClientTransferFilter(new ChannelTypeAdapter(nettyClientPermeateClientVisitor.getHandleChannelTypeAdvancedList()))) .handler(new NettyUdpClientPermeateClientTransferFilter(new ChannelTypeAdapter(nettyClientPermeateClientVisitor.getHandleChannelTypeAdvancedList())))
; ;
NettyClientProperties nettyClientProperties = nettyClientPermeateClientVisitor.getNettyClientProperties(); NettyClientProperties nettyClientProperties = nettyClientPermeateClientVisitor.getNettyClientProperties();
String namespace = nettyClientProperties.getNamespace();
String inetHost = nettyClientProperties.getInetHost(); String inetHost = nettyClientProperties.getInetHost();
int inetPort = nettyClientProperties.getInetPort(); int inetPort = nettyClientProperties.getInetPort();
// local client id // local client id
@ -71,6 +72,7 @@ public class NettyUdpClientPermeateClientVisitorTransferSocket {
NettyProxyMsg nettyProxyMsg = new NettyProxyMsg(); NettyProxyMsg nettyProxyMsg = new NettyProxyMsg();
nettyProxyMsg.setType(UdpMessageType.UDP_REPORT_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL); nettyProxyMsg.setType(UdpMessageType.UDP_REPORT_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL);
// other clientId // other clientId
nettyProxyMsg.setNamespace(namespace);
nettyProxyMsg.setClientId(toClientId); nettyProxyMsg.setClientId(toClientId);
nettyProxyMsg.setVisitorPort(visitorPort); nettyProxyMsg.setVisitorPort(visitorPort);
nettyProxyMsg.setClientTargetIp(targetIp); nettyProxyMsg.setClientTargetIp(targetIp);

View File

@ -44,7 +44,8 @@ public class NettyUdpClientSocket implements NettyClientSocket {
/** /**
* 当前连接的服务端ID * 当前连接的服务端ID
*/ */
private final String serverId; @Getter
private final String namespace;
private final String appKey; private final String appKey;
private final String appSecret; private final String appSecret;
/** /**
@ -57,7 +58,7 @@ public class NettyUdpClientSocket implements NettyClientSocket {
public NettyUdpClientSocket(String inetHost, public NettyUdpClientSocket(String inetHost,
int inetPort, int inetPort,
String clientId, String clientId,
String serverId, String namespace,
String appKey, String appKey,
String appSecret, String appSecret,
ClientChangeEvent clientChangeEvent, ClientChangeEvent clientChangeEvent,
@ -65,7 +66,7 @@ public class NettyUdpClientSocket implements NettyClientSocket {
this.inetHost = inetHost; this.inetHost = inetHost;
this.inetPort = inetPort; this.inetPort = inetPort;
this.clientId = clientId; this.clientId = clientId;
this.serverId = serverId; this.namespace = namespace;
this.appKey = appKey; this.appKey = appKey;
this.appSecret = appSecret; this.appSecret = appSecret;
this.clientChangeEvent = clientChangeEvent; this.clientChangeEvent = clientChangeEvent;
@ -73,10 +74,10 @@ public class NettyUdpClientSocket implements NettyClientSocket {
} }
public void newConnect2Server() throws InterruptedException { public void newConnect2Server() throws InterruptedException {
newConnect2Server(inetHost, inetPort, clientId, serverId, clientChangeEvent); newConnect2Server(inetHost, inetPort, clientId, namespace, clientChangeEvent);
} }
protected void newConnect2Server(String inetHost, int inetPort, String clientId, String serverId, ClientChangeEvent clientChangeEvent) throws InterruptedException { protected void newConnect2Server(String inetHost, int inetPort, String clientId, String namespace, ClientChangeEvent clientChangeEvent) throws InterruptedException {
Bootstrap bootstrap = new Bootstrap(); Bootstrap bootstrap = new Bootstrap();
bootstrap.group(eventLoopGroup) bootstrap.group(eventLoopGroup)
.channel(NioDatagramChannel.class) .channel(NioDatagramChannel.class)
@ -104,6 +105,7 @@ public class NettyUdpClientSocket implements NettyClientSocket {
// 告诉服务端这条连接是client的连接 // 告诉服务端这条连接是client的连接
NettyProxyMsg nettyMsg = new NettyProxyMsg(); NettyProxyMsg nettyMsg = new NettyProxyMsg();
nettyMsg.setType(UdpMessageType.UDP_REPORT_CLIENT_CONNECT_SUCCESS); nettyMsg.setType(UdpMessageType.UDP_REPORT_CLIENT_CONNECT_SUCCESS);
nettyMsg.setNamespace(namespace);
nettyMsg.setClientId(clientId); nettyMsg.setClientId(clientId);
String hostAddress = InetAddress.getLocalHost().getHostAddress(); String hostAddress = InetAddress.getLocalHost().getHostAddress();
nettyMsg.setOriginalIpString(hostAddress); nettyMsg.setOriginalIpString(hostAddress);
@ -113,17 +115,17 @@ public class NettyUdpClientSocket implements NettyClientSocket {
ChannelAttributeKeyUtils.buildClientId(serviceChannel, clientId); ChannelAttributeKeyUtils.buildClientId(serviceChannel, clientId);
serviceChannel.writeAndFlush(nettyMsg); serviceChannel.writeAndFlush(nettyMsg);
NettyServerContext.pushServerEndpointChannel(serverId, clientId, serviceChannel); NettyServerContext.pushServerEndpointChannel(namespace, clientId, serviceChannel);
// 在线 客户端注册服务端成功 // 在线 客户端注册服务端成功
clientChangeEvent.clientOnLine(inetHost, inetPort,serverId, clientId); clientChangeEvent.clientOnLine(inetHost, inetPort, namespace, clientId);
} else { } else {
log.warn("Reconnect every 2 seconds...."); log.warn("Reconnect every 2 seconds....");
// 离线 // 离线
NettyServerContext.removeServerEndpointChannels(serverId, clientId); NettyServerContext.removeServerEndpointChannels(namespace, clientId);
clientChangeEvent.clientOffLine(inetHost, inetPort,serverId, clientId); clientChangeEvent.clientOffLine(inetHost, inetPort, namespace, clientId);
eventLoopGroup.schedule(() -> { eventLoopGroup.schedule(() -> {
try { try {
newConnect2Server(inetHost, inetPort, clientId, serverId, clientChangeEvent); newConnect2Server(inetHost, inetPort, clientId, namespace, clientChangeEvent);
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
} }

View File

@ -34,8 +34,8 @@ public class ClientHandleHttpClientProxyClientTypeAdvanced extends
@Override @Override
protected void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg nettyProxyMsg) { protected void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg nettyProxyMsg) {
Channel channel = nettyChannelContext.channel(); Channel channel = nettyChannelContext.channel();
String targetPortString = nettyProxyMsg.getTargetPortString(); String targetPortString = nettyProxyMsg.targetPort();
String targetIpString = nettyProxyMsg.getTargetIpString(); String targetIpString = nettyProxyMsg.targetIp();
byte[] data = nettyProxyMsg.getData(); byte[] data = nettyProxyMsg.getData();
byte[] clientId = nettyProxyMsg.getClientId(); byte[] clientId = nettyProxyMsg.getClientId();
List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList = new ArrayList<>(SpringContextHolder.getApplicationContext().getBeansOfType(HandleChannelTypeAdvanced.class).values()); List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList = new ArrayList<>(SpringContextHolder.getApplicationContext().getBeansOfType(HandleChannelTypeAdvanced.class).values());

View File

@ -34,8 +34,8 @@ public class ClientHandleHttpClientProxyServerTypeAdvanced extends
protected void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg nettyProxyMsg) { protected void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg nettyProxyMsg) {
Channel channel = nettyChannelContext.channel(); Channel channel = nettyChannelContext.channel();
String targetPortString = nettyProxyMsg.getTargetPortString(); String targetPortString = nettyProxyMsg.targetPort();
String targetIpString = nettyProxyMsg.getTargetIpString(); String targetIpString = nettyProxyMsg.targetIp();
byte[] data = nettyProxyMsg.getData(); byte[] data = nettyProxyMsg.getData();
List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList = new ArrayList<>(SpringContextHolder.getApplicationContext().getBeansOfType(HandleChannelTypeAdvanced.class).values()); List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList = new ArrayList<>(SpringContextHolder.getApplicationContext().getBeansOfType(HandleChannelTypeAdvanced.class).values());
NettyClientProperties nettyClientProperties = SpringContextHolder.getBean(NettyClientProperties.class); NettyClientProperties nettyClientProperties = SpringContextHolder.getBean(NettyClientProperties.class);

View File

@ -3,7 +3,6 @@ package org.framework.lazy.cloud.network.heartbeat.client.netty.proxy.http.socke
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.Bootstrap;
import io.netty.channel.*; import io.netty.channel.*;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel; import io.netty.channel.socket.nio.NioSocketChannel;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties; import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
@ -50,6 +49,7 @@ public class NettyHttpClientProxyClientProxySocket {
int inetPort = nettyClientProperties.getInetPort(); int inetPort = nettyClientProperties.getInetPort();
// local client id // local client id
String namespace = nettyClientProperties.getNamespace();
String clientId = nettyClientProperties.getClientId(); String clientId = nettyClientProperties.getClientId();
String targetIp = nettyHttpClientProxyClient.getTargetIp(); String targetIp = nettyHttpClientProxyClient.getTargetIp();
@ -71,6 +71,7 @@ public class NettyHttpClientProxyClientProxySocket {
NettyProxyMsg nettyProxyMsg = new NettyProxyMsg(); NettyProxyMsg nettyProxyMsg = new NettyProxyMsg();
nettyProxyMsg.setType(ProxyMessageType.HTTP_REPORT_CLIENT_PROXY_CLIENT_TRANSFER_CONNECTION_); nettyProxyMsg.setType(ProxyMessageType.HTTP_REPORT_CLIENT_PROXY_CLIENT_TRANSFER_CONNECTION_);
nettyProxyMsg.setNamespace(namespace);
// other clientId // other clientId
nettyProxyMsg.setClientId(targetClientId); nettyProxyMsg.setClientId(targetClientId);
nettyProxyMsg.setClientTargetIp(targetIp); nettyProxyMsg.setClientTargetIp(targetIp);

View File

@ -32,10 +32,10 @@ public class ClientHandleDistributeSocksClientProxyClientOtherConnectionTransfer
@Override @Override
protected void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg nettyProxyMsg) { protected void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg nettyProxyMsg) {
Channel channel = nettyChannelContext.channel(); Channel channel = nettyChannelContext.channel();
String clientId = nettyProxyMsg.getClientIdString(); String clientId = nettyProxyMsg.clientId();
byte[] visitorId = nettyProxyMsg.getVisitorId(); byte[] visitorId = nettyProxyMsg.getVisitorId();
String targetIp = nettyProxyMsg.getTargetIpString(); String targetIp = nettyProxyMsg.targetIp();
Integer targetPort = Integer.parseInt(nettyProxyMsg.getTargetPortString()); Integer targetPort = Integer.parseInt(nettyProxyMsg.targetPort());
List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList = new ArrayList<>(SpringContextHolder.getApplicationContext().getBeansOfType(HandleChannelTypeAdvanced.class).values()); List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList = new ArrayList<>(SpringContextHolder.getApplicationContext().getBeansOfType(HandleChannelTypeAdvanced.class).values());
NettyClientProperties nettyClientProperties = SpringContextHolder.getBean(NettyClientProperties.class); NettyClientProperties nettyClientProperties = SpringContextHolder.getBean(NettyClientProperties.class);

View File

@ -37,8 +37,8 @@ public class ClientHandleNettySocketProtocolHandleSocketClientProxyClientStartTy
NettySocketChannelContext nettySocketChannelContext = (NettySocketChannelContext) nettyChannelContext; NettySocketChannelContext nettySocketChannelContext = (NettySocketChannelContext) nettyChannelContext;
Channel proxyChannel = nettySocketChannelContext.channel(); Channel proxyChannel = nettySocketChannelContext.channel();
String host = nettyProxyMsg.getTargetIpString(); String host = nettyProxyMsg.targetIp();
Integer port = Integer.parseInt(nettyProxyMsg.getTargetPortString()); Integer port = Integer.parseInt(nettyProxyMsg.targetPort());
byte[] clientId = nettyProxyMsg.getClientId(); byte[] clientId = nettyProxyMsg.getClientId();
byte[] visitorId = nettyProxyMsg.getVisitorId(); byte[] visitorId = nettyProxyMsg.getVisitorId();

View File

@ -40,8 +40,8 @@ public class ClientHandleNettySocketProtocolHandleSocketClientProxyServerStartTy
NettySocketChannelContext nettySocketChannelContext = (NettySocketChannelContext) nettyChannelContext; NettySocketChannelContext nettySocketChannelContext = (NettySocketChannelContext) nettyChannelContext;
Channel proxyChannel = nettySocketChannelContext.channel(); Channel proxyChannel = nettySocketChannelContext.channel();
String host = nettyProxyMsg.getTargetIpString(); String host = nettyProxyMsg.targetIp();
Integer port = Integer.parseInt(nettyProxyMsg.getTargetPortString()); Integer port = Integer.parseInt(nettyProxyMsg.targetPort());
Socks5AddressType socks5AddressType = nettySocketChannelContext.getSocks5AddressType(); Socks5AddressType socks5AddressType = nettySocketChannelContext.getSocks5AddressType();

View File

@ -1,7 +1,6 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.proxy.socks.advanced; package org.framework.lazy.cloud.network.heartbeat.client.netty.proxy.socks.advanced;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.handler.codec.socksx.v5.Socks5AddressType;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties; import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
import org.framework.lazy.cloud.network.heartbeat.client.netty.proxy.socks.NettySocksClientProxyClient; import org.framework.lazy.cloud.network.heartbeat.client.netty.proxy.socks.NettySocksClientProxyClient;
@ -37,10 +36,10 @@ public class ClientHandleSocksDistributeServerProxyClientConnectionInitTypeAdvan
// 绑定真实通道 // 绑定真实通道
Channel channel = nettyChannelContext.channel(); Channel channel = nettyChannelContext.channel();
String clientId = nettyProxyMsg.getClientIdString(); String clientId = nettyProxyMsg.clientId();
byte[] visitorId = nettyProxyMsg.getVisitorId(); byte[] visitorId = nettyProxyMsg.getVisitorId();
String targetIp = nettyProxyMsg.getTargetIpString(); String targetIp = nettyProxyMsg.targetIp();
Integer targetPort = Integer.parseInt(nettyProxyMsg.getTargetPortString()); Integer targetPort = Integer.parseInt(nettyProxyMsg.targetPort());
List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList = new ArrayList<>(SpringContextHolder.getApplicationContext().getBeansOfType(HandleChannelTypeAdvanced.class).values()); List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList = new ArrayList<>(SpringContextHolder.getApplicationContext().getBeansOfType(HandleChannelTypeAdvanced.class).values());

View File

@ -41,6 +41,7 @@ public class NettySocksClientProxyClientVisitorTransferSocket {
.handler(new NettySocksClientProxyClientVisitorTransferFilter(new ChannelTypeAdapter(nettySocksClientProxyClient.getHandleChannelTypeAdvancedList()))) .handler(new NettySocksClientProxyClientVisitorTransferFilter(new ChannelTypeAdapter(nettySocksClientProxyClient.getHandleChannelTypeAdvancedList())))
; ;
NettyClientProperties nettyClientProperties = nettySocksClientProxyClient.getNettyClientProperties(); NettyClientProperties nettyClientProperties = nettySocksClientProxyClient.getNettyClientProperties();
String namespace = nettyClientProperties.getNamespace();
String inetHost = nettyClientProperties.getInetHost(); String inetHost = nettyClientProperties.getInetHost();
int inetPort = nettyClientProperties.getInetPort(); int inetPort = nettyClientProperties.getInetPort();
// local client id // local client id
@ -69,6 +70,7 @@ public class NettySocksClientProxyClientVisitorTransferSocket {
NettyProxyMsg nettyProxyMsg = new NettyProxyMsg(); NettyProxyMsg nettyProxyMsg = new NettyProxyMsg();
nettyProxyMsg.setType(ProxyMessageType.SOCKS_REPORT_CLIENT_PROXY_CLIENT_TRANSFER_CONNECTION_); nettyProxyMsg.setType(ProxyMessageType.SOCKS_REPORT_CLIENT_PROXY_CLIENT_TRANSFER_CONNECTION_);
nettyProxyMsg.setNamespace(namespace);
// other clientId // other clientId
nettyProxyMsg.setClientTargetIp(targetIp); nettyProxyMsg.setClientTargetIp(targetIp);
nettyProxyMsg.setClientTargetPort(targetPort); nettyProxyMsg.setClientTargetPort(targetPort);

View File

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

View File

@ -5,7 +5,7 @@
<link rel="icon" href="./favicon.ico"> <link rel="icon" href="./favicon.ico">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Java 使用 Lazy ORM 网络穿透客户端!</title> <title>Java 使用 Lazy ORM 网络穿透客户端!</title>
<script type="module" crossorigin src="./assets/index-Dx8CuNMY.js"></script> <script type="module" crossorigin src="./assets/index-CtIDExbE.js"></script>
<link rel="stylesheet" crossorigin href="./assets/index-BEQZ9T9z.css"> <link rel="stylesheet" crossorigin href="./assets/index-BEQZ9T9z.css">
</head> </head>
<body> <body>

View File

@ -1,6 +1,7 @@
package org.framework.lazy.cloud.network.heartbeat.common; package org.framework.lazy.cloud.network.heartbeat.common;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import lombok.Data;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils; import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
import org.wu.framework.core.utils.ObjectUtils; import org.wu.framework.core.utils.ObjectUtils;
@ -19,8 +20,9 @@ import java.util.stream.Collectors;
@Slf4j @Slf4j
public class ChannelContext { public class ChannelContext {
private final static ConcurrentHashMap<String/*clientId*/, List<Channel>/*通道*/> private final static ConcurrentHashMap<String/*namespace*/,
channelIdClientChannelDTOConcurrentHashMap = new ConcurrentHashMap<>(); ConcurrentHashMap<String/*clientId*/, List<Channel>/*通道*/>>
cacheClientChannelConcurrentHashMap = new ConcurrentHashMap<>();
/** /**
* 新增通道 * 新增通道
@ -28,26 +30,37 @@ public class ChannelContext {
* @param channel 通道 * @param channel 通道
* @param clientId 客户端ID * @param clientId 客户端ID
*/ */
public static void push(Channel channel, String clientId) { public static void push(Channel channel, String namespace, String clientId) {
// 如果客户端已经存在 移除 // 如果服务端已经存在 移除
if (channelIdClientChannelDTOConcurrentHashMap.containsKey(clientId)) { if (cacheClientChannelConcurrentHashMap.containsKey(namespace)) {
// clear(clientId);
List<Channel> existChannelList = new ArrayList<>(); ConcurrentHashMap<String/*clientId*/, List<Channel>/*通道*/> clientChannelListConcurrentHashMap =
List<Channel> oldChannels = channelIdClientChannelDTOConcurrentHashMap.get(clientId); cacheClientChannelConcurrentHashMap.get(namespace);
for (Channel existChannel : oldChannels) {
if (existChannel != null) {
if(existChannel.isActive()){ // 判断是否存在客户端
existChannelList.add(existChannel); if (clientChannelListConcurrentHashMap.containsKey(clientId)) {
}else { List<Channel> existChannelList = new ArrayList<>();
log.warn("close channel with client:{}", ChannelAttributeKeyUtils.getClientId(existChannel)); List<Channel> oldChannels = clientChannelListConcurrentHashMap.get(clientId);
existChannel.close(); for (Channel existChannel : oldChannels) {
if (existChannel != null) {
if (existChannel.isActive()) {
existChannelList.add(existChannel);
} else {
log.warn("close channel with namespace:{} client:{}", namespace, ChannelAttributeKeyUtils.getClientId(existChannel));
existChannel.close();
}
} }
} }
existChannelList.add(channel);
clientChannelListConcurrentHashMap.put(clientId, existChannelList);
cacheClientChannelConcurrentHashMap.put(namespace, clientChannelListConcurrentHashMap);
} }
existChannelList.add(channel);
channelIdClientChannelDTOConcurrentHashMap.put(clientId, existChannelList);
}else { }else {
channelIdClientChannelDTOConcurrentHashMap.putIfAbsent(clientId, Collections.synchronizedList(new ArrayList<>(List.of(channel)))); ConcurrentHashMap<String/*clientId*/, List<Channel>/*通道*/> clientChannelListConcurrentHashMap =
new ConcurrentHashMap<>();
clientChannelListConcurrentHashMap.put(clientId, Collections.synchronizedList(new ArrayList<>(List.of(channel))));
cacheClientChannelConcurrentHashMap.putIfAbsent(namespace, clientChannelListConcurrentHashMap);
} }
} }
@ -58,8 +71,17 @@ public class ChannelContext {
* @param channel 通道 * @param channel 通道
* @param clientId 客户端ID * @param clientId 客户端ID
*/ */
public static void push(Channel channel, byte[] clientId) { public static void push(Channel channel, byte[] namespace, byte[] clientId) {
push(channel,new String(clientId, StandardCharsets.UTF_8)); push(channel, new String(namespace, StandardCharsets.UTF_8), new String(clientId, StandardCharsets.UTF_8));
}
/**
* 获取指定服务端所有通道
*
* @return 返回所有通道信息
*/
public static ConcurrentMap<String/*clientId*/, List<Channel>/*通道*/> getChannels(String namespace) {
return cacheClientChannelConcurrentHashMap.get(namespace);
} }
/** /**
@ -67,8 +89,20 @@ public class ChannelContext {
* *
* @return 返回所有通道信息 * @return 返回所有通道信息
*/ */
public static ConcurrentMap<String/*clientId*/, List<Channel>/*通道*/> getChannels() { public static ConcurrentMap<ServerClient/*clientId*/, List<Channel>/*通道*/> getChannels() {
return channelIdClientChannelDTOConcurrentHashMap;
ConcurrentHashMap<ServerClient/*ServerClient*/, List<Channel>/*通道*/> channelListConcurrentHashMap =
new ConcurrentHashMap<>();
cacheClientChannelConcurrentHashMap.forEach((namespace, item) -> {
item.forEach((clientId, channels) -> {
ServerClient serverClient = new ServerClient();
serverClient.setClientId(namespace);
serverClient.setClientId(clientId);
channelListConcurrentHashMap.put(serverClient, channels);
});
});
return channelListConcurrentHashMap;
} }
/** /**
* 获取所有通道 * 获取所有通道
@ -76,7 +110,7 @@ public class ChannelContext {
* @return 返回所有通道信息 * @return 返回所有通道信息
*/ */
public static List<String> getClientIds() { public static List<String> getClientIds() {
return new ArrayList<>(channelIdClientChannelDTOConcurrentHashMap.keySet().stream().toList()); return new ArrayList<>(cacheClientChannelConcurrentHashMap.keySet().stream().toList());
} }
@ -86,16 +120,15 @@ public class ChannelContext {
* @param clientId 客户端ID * @param clientId 客户端ID
* @return 通道信息 * @return 通道信息
*/ */
public static List<Channel> get(byte[] clientId) { public static List<Channel> get(byte[] namespace, byte[] clientId) {
if (channelIdClientChannelDTOConcurrentHashMap try {
.containsKey(new String(clientId))) { return cacheClientChannelConcurrentHashMap.get(new String(namespace, StandardCharsets.UTF_8)).get(new String(clientId, StandardCharsets.UTF_8));
return channelIdClientChannelDTOConcurrentHashMap } catch (Exception e) {
.get(new String(clientId));
} else {
// 无法通过客户端ID[{}]获取通道信息 // 无法通过客户端ID[{}]获取通道信息
log.error("Unable to obtain channel information through client ID [{}]",new String(clientId)); log.error("Unable to obtain channel information through namespace:{} client ID [{}]", new String(namespace), new String(clientId));
return null; return null;
} }
} }
/** /**
@ -104,8 +137,8 @@ public class ChannelContext {
* @param clientId 客户端ID * @param clientId 客户端ID
* @return 通道信息 * @return 通道信息
*/ */
public static List<Channel> get(String clientId) { public static List<Channel> get(String namespace, String clientId) {
return get(clientId.getBytes(StandardCharsets.UTF_8)); return get(namespace.getBytes(StandardCharsets.UTF_8), clientId.getBytes(StandardCharsets.UTF_8));
} }
/** /**
* 根据通道ID获取通道信息 * 根据通道ID获取通道信息
@ -113,8 +146,8 @@ public class ChannelContext {
* @param clientId 客户端ID * @param clientId 客户端ID
* @return 通道信息 * @return 通道信息
*/ */
public static Channel getLoadBalance(byte[] clientId) { public static Channel getLoadBalance(byte[] namespace, byte[] clientId) {
List<Channel> channels = get(clientId); List<Channel> channels = get(namespace, clientId);
if(ObjectUtils.isEmpty(channels)){ if(ObjectUtils.isEmpty(channels)){
return null; return null;
} }
@ -132,8 +165,8 @@ public class ChannelContext {
* @param clientId 客户端ID * @param clientId 客户端ID
* @return 通道信息 * @return 通道信息
*/ */
public static Channel getLoadBalance(String clientId) { public static Channel getLoadBalance(String namespace, String clientId) {
return getLoadBalance(clientId.getBytes(StandardCharsets.UTF_8)); return getLoadBalance(namespace.getBytes(StandardCharsets.UTF_8), clientId.getBytes(StandardCharsets.UTF_8));
} }
/** /**
@ -141,10 +174,10 @@ public class ChannelContext {
* *
* @param clientId 客户端ID * @param clientId 客户端ID
*/ */
public static void clear(String clientId) { public static void clear(String namespace, String clientId) {
List<Channel> channels = get(clientId); List<Channel> channels = get(namespace, clientId);
if (channels != null) { if (channels != null) {
remove(clientId); remove(namespace, clientId);
for (Channel channel : channels) { for (Channel channel : channels) {
if (channel != null && channel.isActive()) { if (channel != null && channel.isActive()) {
channel.close(); channel.close();
@ -153,7 +186,7 @@ public class ChannelContext {
} else { } else {
// log warm // log warm
// 无法通过客户ID:[{}]移除客户端 // 无法通过客户ID:[{}]移除客户端
log.warn("Unable to remove client through customer ID: [{}]", clientId); log.warn("Unable to remove client through namespace:{} clientId: [{}]", namespace, clientId);
} }
} }
@ -162,13 +195,13 @@ public class ChannelContext {
* *
* @param clientId 客户端ID * @param clientId 客户端ID
*/ */
public static void remove(byte[] clientId) { public static void remove(byte[] namespace, byte[] clientId) {
List<Channel> clientChannel = get(clientId); List<Channel> clientChannel = get(namespace, clientId);
if (clientChannel != null) { if (clientChannel != null) {
channelIdClientChannelDTOConcurrentHashMap.remove(new String(clientId)); cacheClientChannelConcurrentHashMap.get(new String(namespace, StandardCharsets.UTF_8)).remove(new String(clientId, StandardCharsets.UTF_8));
} else { } else {
// log warm 无法通过客户ID:[{}]移除客户端 // log warm 无法通过客户ID:[{}]移除客户端
log.warn("Unable to remove client through customer ID: [{}]", new String(clientId)); log.warn("Unable to remove client through namespace:{} clientId: [{}]", new String(namespace), new String(clientId));
} }
} }
@ -177,13 +210,13 @@ public class ChannelContext {
* *
* @param clientId 客户端ID * @param clientId 客户端ID
*/ */
public static void remove(String clientId) { public static void remove(String namespace, String clientId) {
List<Channel> clientChannel = get(clientId); List<Channel> clientChannel = get(namespace, clientId);
if (clientChannel != null) { if (clientChannel != null) {
channelIdClientChannelDTOConcurrentHashMap.remove(clientId); cacheClientChannelConcurrentHashMap.get(namespace).remove(clientId);
} else { } else {
// log warm 无法通过客户ID:[{}]移除客户端 // log warm 无法通过客户ID:[{}]移除客户端
log.warn("Unable to remove client through customer ID: [{}]", clientId); log.warn("Unable to remove client through namespace :【{}】 clientId: {}", namespace, clientId);
} }
} }
@ -206,5 +239,12 @@ public class ChannelContext {
} }
@Data
public static class ServerClient {
private String namespace;
private String clientId;
}
} }

View File

@ -16,6 +16,10 @@ import lombok.experimental.Accessors;
public class InternalNetworkPenetrationRealClient { public class InternalNetworkPenetrationRealClient {
/**
* 命名空间
*/
private String namespace;
/** /**
* 客户端ID * 客户端ID
*/ */

View File

@ -20,8 +20,8 @@ public class NettyClientChannel {
*/ */
private Channel channel; private Channel channel;
/** /**
* 服务端ID * namespace
*/ */
private String serverId; private String namespace;
} }

View File

@ -15,21 +15,24 @@ import java.util.stream.Collectors;
public class NettyServerContext { public class NettyServerContext {
protected static final ConcurrentHashMap<String/*serverId*/, List<NettyClientChannel>/*NettyClientChannel*/> protected static final ConcurrentHashMap<String/*namespace*/, List<NettyClientChannel>/*NettyClientChannel*/>
NETTY_CLIENT_CHANNEL_SOCKET = new ConcurrentHashMap<>(); NETTY_CLIENT_CHANNEL_SOCKET = new ConcurrentHashMap<>();
/** /**
* 添加访客 * 添加访客
* *
* @param serverId 服务端ID * @param namespace namespace
* @param clientId 客户端ID * @param clientId 客户端ID
* @param channel channel * @param channel channel
*/ */
public static <T> void pushServerEndpointChannel(String serverId, String clientId, Channel channel) { public static <T> void pushServerEndpointChannel(String namespace, String clientId, Channel channel) {
List<NettyClientChannel> nettyClientChannelList = getServerEndpointChannels(serverId); List<NettyClientChannel> nettyClientChannelList = getServerEndpointChannels(namespace);
// 关闭旧的通道 // 关闭旧的通道
nettyClientChannelList.stream().filter(nettyClientChannel -> nettyClientChannel.getClientId().equals(clientId) && nettyClientChannel.getServerId().equals(serverId)).forEach(nettyClientChannel -> { nettyClientChannelList
.stream()
.filter(nettyClientChannel ->
nettyClientChannel.getClientId().equals(clientId) && nettyClientChannel.getNamespace().equals(namespace)).forEach(nettyClientChannel -> {
Channel oldChannel = nettyClientChannel.getChannel(); Channel oldChannel = nettyClientChannel.getChannel();
if (oldChannel != null && oldChannel.isActive()) { if (oldChannel != null && oldChannel.isActive()) {
oldChannel.close(); oldChannel.close();
@ -39,11 +42,11 @@ public class NettyServerContext {
List<NettyClientChannel> activeNettyClientChannelList = nettyClientChannelList List<NettyClientChannel> activeNettyClientChannelList = nettyClientChannelList
.stream() .stream()
.filter(nettyClientChannel -> .filter(nettyClientChannel ->
!nettyClientChannel.getClientId().equals(clientId) && !nettyClientChannel.getServerId().equals(serverId)) !nettyClientChannel.getClientId().equals(clientId) && !nettyClientChannel.getNamespace().equals(namespace))
.collect(Collectors.toList()); .collect(Collectors.toList());
NettyClientChannel nettyClientChannel = new NettyClientChannel(clientId, channel, serverId); NettyClientChannel nettyClientChannel = new NettyClientChannel(clientId, channel, namespace);
activeNettyClientChannelList.add(nettyClientChannel); activeNettyClientChannelList.add(nettyClientChannel);
NETTY_CLIENT_CHANNEL_SOCKET.put(serverId, activeNettyClientChannelList); NETTY_CLIENT_CHANNEL_SOCKET.put(namespace, activeNettyClientChannelList);
} }
/** /**

View File

@ -15,8 +15,8 @@ import java.nio.charset.StandardCharsets;
@Setter @Setter
@Getter @Getter
public class NettyProxyMsg { public class NettyProxyMsg {
// body 长度 type 1 isSsl 1 appKey 4 appSecret 4 clientId 4 originalIp 4 clientTargetIp 4 clientTargetPort 4 visitorPort 4 visitorId 4 data 4 // body 长度 type 1 isSsl 1 appKey 4 appSecret 4 clientId 4 namespace 4 originalIp 4 clientTargetIp 4 clientTargetPort 4 visitorPort 4 visitorId 4 data 4
public static final int bodyLength = 1 + 1 + 4 + 4 + 4 + 4 + 4 + 4 + 4 + 4 + 4; public static final int bodyLength = 1 + 1 + 4 + 4 + 4 + 4 + 4 + 4 + 4 + 4 + 4 + 4;
/** /**
@ -55,6 +55,12 @@ public class NettyProxyMsg {
* @since 1.2.9 * @since 1.2.9
*/ */
private byte[] originalIp; private byte[] originalIp;
/**
* namespace
* byte[] 长度 4
*/
private byte[] namespace;
/** /**
* 客户端ID * 客户端ID
* byte[] 长度 4 * byte[] 长度 4
@ -106,6 +112,14 @@ public class NettyProxyMsg {
this.clientId = clientId.getBytes(StandardCharsets.UTF_8); this.clientId = clientId.getBytes(StandardCharsets.UTF_8);
} }
public void setNamespace(byte[] namespace) {
this.namespace = namespace;
}
public void setNamespace(String serverId) {
this.namespace = serverId.getBytes(StandardCharsets.UTF_8);
}
public void setAppKeyString(String appKey) { public void setAppKeyString(String appKey) {
if (ObjectUtils.isEmpty(appKey)) { if (ObjectUtils.isEmpty(appKey)) {
@ -172,18 +186,28 @@ public class NettyProxyMsg {
return new String(originalIp, StandardCharsets.UTF_8); return new String(originalIp, StandardCharsets.UTF_8);
} }
public String getClientIdString() { public String clientId() {
if (ObjectUtils.isEmpty(clientId)) { if (ObjectUtils.isEmpty(clientId)) {
return null; return null;
} }
return new String(clientId, StandardCharsets.UTF_8); return new String(clientId, StandardCharsets.UTF_8);
} }
/**
* namespace
*/
public String namespace() {
if (ObjectUtils.isEmpty(namespace)) {
return null;
}
return new String(namespace, StandardCharsets.UTF_8);
}
/** /**
* 客户端目标地址 * 客户端目标地址
* *
* @return 客户端目标地址 * @return 客户端目标地址
*/ */
public String getTargetIpString() { public String targetIp() {
if (ObjectUtils.isEmpty(clientTargetIp)) { if (ObjectUtils.isEmpty(clientTargetIp)) {
return null; return null;
} }
@ -194,7 +218,7 @@ public class NettyProxyMsg {
* *
* @return 客户端目标端口 * @return 客户端目标端口
*/ */
public String getTargetPortString() { public String targetPort() {
if (ObjectUtils.isEmpty(clientTargetPort)) { if (ObjectUtils.isEmpty(clientTargetPort)) {
return null; return null;
} }
@ -205,7 +229,7 @@ public class NettyProxyMsg {
* 获取访客ID * 获取访客ID
* @return * @return
*/ */
public String getVisitorIdString() { public String visitorId() {
if (ObjectUtils.isEmpty(visitorId)) { if (ObjectUtils.isEmpty(visitorId)) {
return null; return null;
} }

View File

@ -173,7 +173,7 @@ public class UdpMessageType {
* *
* @see UdpMessageTypeEnums#UDP_REPORT_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL * @see UdpMessageTypeEnums#UDP_REPORT_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL
* @see AbstractHandleUdpReportClientTransferClientPermeateChannelConnectionSuccessfulTypeAdvanced * @see AbstractHandleUdpReportClientTransferClientPermeateChannelConnectionSuccessfulTypeAdvanced
* @see TcpMessageType#UDP_DISTRIBUTE_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL * @see UdpMessageType#UDP_DISTRIBUTE_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL
*/ */
public static final byte UDP_REPORT_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL = UDP_REPORT_CLIENT_PERMEATE_CLIENT_CLOSE+1; public static final byte UDP_REPORT_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL = UDP_REPORT_CLIENT_PERMEATE_CLIENT_CLOSE+1;
@ -183,7 +183,7 @@ public class UdpMessageType {
* *
* @see UdpMessageTypeEnums#UDP_REPORT_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_INIT_SUCCESSFUL * @see UdpMessageTypeEnums#UDP_REPORT_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_INIT_SUCCESSFUL
* @see AbstractHandleUdpReportClientTransferClientPermeateChannelInitSuccessfulTypeAdvanced * @see AbstractHandleUdpReportClientTransferClientPermeateChannelInitSuccessfulTypeAdvanced
* @see TcpMessageType#UDP_DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_CHANNEL_INIT_SUCCESSFUL * @see UdpMessageType#UDP_DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_CHANNEL_INIT_SUCCESSFUL
*/ */
public static final byte UDP_REPORT_CLIENT_PERMEATE_CLIENT_TRANSFER_CHANNEL_INIT_SUCCESSFUL = UDP_REPORT_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL+1; public static final byte UDP_REPORT_CLIENT_PERMEATE_CLIENT_TRANSFER_CHANNEL_INIT_SUCCESSFUL = UDP_REPORT_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL+1;
/** /**
@ -191,7 +191,7 @@ public class UdpMessageType {
* *
* @see UdpMessageTypeEnums#UDP_REPORT_CLIENT_TRANSFER_CLIENT_REQUEST * @see UdpMessageTypeEnums#UDP_REPORT_CLIENT_TRANSFER_CLIENT_REQUEST
* @see AbstractHandleUdpReportClientTransferClientTypeAdvanced * @see AbstractHandleUdpReportClientTransferClientTypeAdvanced
* @see TcpMessageType#UDP_DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_REQUEST * @see UdpMessageType#UDP_DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_REQUEST
*/ */
public static final byte UDP_REPORT_CLIENT_PERMEATE_CLIENT_TRANSFER_REQUEST = UDP_REPORT_CLIENT_PERMEATE_CLIENT_TRANSFER_CHANNEL_INIT_SUCCESSFUL+1; public static final byte UDP_REPORT_CLIENT_PERMEATE_CLIENT_TRANSFER_REQUEST = UDP_REPORT_CLIENT_PERMEATE_CLIENT_TRANSFER_CHANNEL_INIT_SUCCESSFUL+1;
@ -200,7 +200,7 @@ public class UdpMessageType {
* *
* @see UdpMessageTypeEnums#UDP_REPORT_CLIENT_TRANSFER_CLIENT_RESPONSE * @see UdpMessageTypeEnums#UDP_REPORT_CLIENT_TRANSFER_CLIENT_RESPONSE
* @see AbstractHandleUdpReportClientTransferClientResponseTypeAdvanced * @see AbstractHandleUdpReportClientTransferClientResponseTypeAdvanced
* @see TcpMessageType#UDP_DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_RESPONSE * @see UdpMessageType#UDP_DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_RESPONSE
*/ */
public static final byte UDP_REPORT_CLIENT_TRANSFER_CLIENT_RESPONSE = UDP_REPORT_CLIENT_PERMEATE_CLIENT_TRANSFER_REQUEST+1; public static final byte UDP_REPORT_CLIENT_TRANSFER_CLIENT_RESPONSE = UDP_REPORT_CLIENT_PERMEATE_CLIENT_TRANSFER_REQUEST+1;
@ -209,7 +209,7 @@ public class UdpMessageType {
* *
* @see UdpMessageTypeEnums#UDP_REPORT_CLIENT_PERMEATE_CLIENT_TRANSFER_CLOSE * @see UdpMessageTypeEnums#UDP_REPORT_CLIENT_PERMEATE_CLIENT_TRANSFER_CLOSE
* @see AbstractHandleUdpReportClientPermeateClientTransferCloseTypeAdvanced * @see AbstractHandleUdpReportClientPermeateClientTransferCloseTypeAdvanced
* @see TcpMessageType#UDP_DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_CLOSE * @see UdpMessageType#UDP_DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_CLOSE
*/ */
public static final byte UDP_REPORT_CLIENT_PERMEATE_CLIENT_TRANSFER_CLOSE = UDP_REPORT_CLIENT_TRANSFER_CLIENT_RESPONSE+1; public static final byte UDP_REPORT_CLIENT_PERMEATE_CLIENT_TRANSFER_CLOSE = UDP_REPORT_CLIENT_TRANSFER_CLIENT_RESPONSE+1;
@ -370,7 +370,7 @@ public class UdpMessageType {
* *
* @see UdpMessageTypeEnums#UDP_DISTRIBUTE_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL * @see UdpMessageTypeEnums#UDP_DISTRIBUTE_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL
* @see AbstractHandleUdpDistributeClientTransferClientPermeateChannelConnectionSuccessfulTypeAdvanced * @see AbstractHandleUdpDistributeClientTransferClientPermeateChannelConnectionSuccessfulTypeAdvanced
* @see TcpMessageType#UDP_REPORT_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL * @see UdpMessageType#UDP_REPORT_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL
*/ */
public static final byte UDP_DISTRIBUTE_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL = UDP_DISTRIBUTE_CLIENT_PERMEATE_CLIENT_CLOSE-1; public static final byte UDP_DISTRIBUTE_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL = UDP_DISTRIBUTE_CLIENT_PERMEATE_CLIENT_CLOSE-1;
@ -380,7 +380,7 @@ public class UdpMessageType {
* *
* @see UdpMessageTypeEnums#UDP_DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_CHANNEL_INIT_SUCCESSFUL * @see UdpMessageTypeEnums#UDP_DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_CHANNEL_INIT_SUCCESSFUL
* @see AbstractHandleUdpDistributeClientTransferClientPermeateChannelInitSuccessfulTypeAdvanced * @see AbstractHandleUdpDistributeClientTransferClientPermeateChannelInitSuccessfulTypeAdvanced
* @see TcpMessageType#UDP_DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_CHANNEL_INIT_SUCCESSFUL * @see UdpMessageType#UDP_DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_CHANNEL_INIT_SUCCESSFUL
*/ */
public static final byte UDP_DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_CHANNEL_INIT_SUCCESSFUL = UDP_DISTRIBUTE_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL-1; public static final byte UDP_DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_CHANNEL_INIT_SUCCESSFUL = UDP_DISTRIBUTE_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL-1;
@ -389,7 +389,7 @@ public class UdpMessageType {
* *
* @see UdpMessageTypeEnums#UDP_DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_REQUEST * @see UdpMessageTypeEnums#UDP_DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_REQUEST
* @see AbstractHandleUdpDistributeClientTransferClientRequestTypeAdvanced * @see AbstractHandleUdpDistributeClientTransferClientRequestTypeAdvanced
* @see TcpMessageType#UDP_REPORT_CLIENT_PERMEATE_CLIENT_TRANSFER_REQUEST * @see UdpMessageType#UDP_REPORT_CLIENT_PERMEATE_CLIENT_TRANSFER_REQUEST
*/ */
public static final byte UDP_DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_REQUEST = UDP_DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_CHANNEL_INIT_SUCCESSFUL-1; public static final byte UDP_DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_REQUEST = UDP_DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_CHANNEL_INIT_SUCCESSFUL-1;
/** /**
@ -397,7 +397,7 @@ public class UdpMessageType {
* *
* @see UdpMessageTypeEnums#UDP_DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_RESPONSE * @see UdpMessageTypeEnums#UDP_DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_RESPONSE
* @see AbstractHandleUdpDistributeServicePermeateClientTransferClientResponseTypeAdvanced * @see AbstractHandleUdpDistributeServicePermeateClientTransferClientResponseTypeAdvanced
* @see TcpMessageType#UDP_REPORT_CLIENT_TRANSFER_CLIENT_RESPONSE * @see UdpMessageType#UDP_REPORT_CLIENT_TRANSFER_CLIENT_RESPONSE
*/ */
public static final byte UDP_DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_RESPONSE = UDP_DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_REQUEST-1; public static final byte UDP_DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_RESPONSE = UDP_DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_REQUEST-1;
@ -407,7 +407,7 @@ public class UdpMessageType {
* *
* @see UdpMessageTypeEnums#UDP_DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_CLOSE * @see UdpMessageTypeEnums#UDP_DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_CLOSE
* @see AbstractHandleUdpDistributeClientPermeateClientTransferCloseTypeAdvanced * @see AbstractHandleUdpDistributeClientPermeateClientTransferCloseTypeAdvanced
* @see TcpMessageType#UDP_REPORT_CLIENT_PERMEATE_CLIENT_TRANSFER_CLOSE * @see UdpMessageType#UDP_REPORT_CLIENT_PERMEATE_CLIENT_TRANSFER_CLOSE
*/ */
public static final byte UDP_DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_CLOSE = UDP_DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_RESPONSE-1; public static final byte UDP_DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_CLOSE = UDP_DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_RESPONSE-1;

View File

@ -128,6 +128,13 @@ public class NettyProxyMsgDecoder extends LengthFieldBasedFrameDecoder {
in.readBytes(originalIpBytes); in.readBytes(originalIpBytes);
nettyProxyMsg.setOriginalIp(originalIpBytes); nettyProxyMsg.setOriginalIp(originalIpBytes);
int namespaceLength = in.readInt();
byte[] namespaceBytes = new byte[namespaceLength];
in.readBytes(namespaceBytes);
nettyProxyMsg.setNamespace(namespaceBytes);
int clientIdLength = in.readInt(); int clientIdLength = in.readInt();
byte[] clientIdBytes = new byte[clientIdLength]; byte[] clientIdBytes = new byte[clientIdLength];
in.readBytes(clientIdBytes); in.readBytes(clientIdBytes);
@ -159,6 +166,7 @@ public class NettyProxyMsgDecoder extends LengthFieldBasedFrameDecoder {
appKeyLength - appKeyLength -
appSecretLength - appSecretLength -
originalIpLength - originalIpLength -
namespaceLength -
clientIdLength - clientIdLength -
clientTargetIpLength - clientTargetIpLength -
clientTargetPortLength - clientTargetPortLength -

View File

@ -28,6 +28,7 @@ public class NettyProxyMsgEncoder extends MessageToByteEncoder<NettyProxyMsg> {
byte[] appKey = msg.getAppKey(); byte[] appKey = msg.getAppKey();
byte[] appSecret = msg.getAppSecret(); byte[] appSecret = msg.getAppSecret();
byte[] originalIp = msg.getOriginalIp(); byte[] originalIp = msg.getOriginalIp();
byte[] namespace = msg.getNamespace();
byte[] clientIdBytes = msg.getClientId(); byte[] clientIdBytes = msg.getClientId();
byte[] clientTargetIpBytes = msg.getClientTargetIp(); byte[] clientTargetIpBytes = msg.getClientTargetIp();
byte[] clientTargetPortBytes = msg.getClientTargetPort(); byte[] clientTargetPortBytes = msg.getClientTargetPort();
@ -44,6 +45,9 @@ public class NettyProxyMsgEncoder extends MessageToByteEncoder<NettyProxyMsg> {
if (originalIp != null) { if (originalIp != null) {
bodyLength += originalIp.length; bodyLength += originalIp.length;
} }
if (namespace != null) {
bodyLength += namespace.length;
}
if (clientIdBytes != null) { if (clientIdBytes != null) {
bodyLength += clientIdBytes.length; bodyLength += clientIdBytes.length;
} }
@ -95,6 +99,18 @@ public class NettyProxyMsgEncoder extends MessageToByteEncoder<NettyProxyMsg> {
// 防止原始IP 未填写 // 防止原始IP 未填写
out.writeInt(0x00); out.writeInt(0x00);
} }
// 防止数据读错位置 服务端IP
if (namespace != null) {
out.writeInt(namespace.length);
out.writeBytes(namespace);
} else {
// 防止 服务端IP 未填写
out.writeInt(0x00);
}
// 防止数据读错位置 clientId // 防止数据读错位置 clientId
if (clientIdBytes != null) { if (clientIdBytes != null) {
out.writeInt(clientIdBytes.length); out.writeInt(clientIdBytes.length);
@ -132,6 +148,7 @@ public class NettyProxyMsgEncoder extends MessageToByteEncoder<NettyProxyMsg> {
out.writeInt(0x00); out.writeInt(0x00);
} }
// 访客ID
if (visitorIdBytes != null) { if (visitorIdBytes != null) {
out.writeInt(visitorIdBytes.length); out.writeInt(visitorIdBytes.length);
out.writeBytes(visitorIdBytes); out.writeBytes(visitorIdBytes);
@ -139,6 +156,8 @@ public class NettyProxyMsgEncoder extends MessageToByteEncoder<NettyProxyMsg> {
// 防止客户端 访客ID未填写 // 防止客户端 访客ID未填写
out.writeInt(0x00); out.writeInt(0x00);
} }
// 数据消息体
if (msgDataBytes != null) { if (msgDataBytes != null) {
out.writeBytes(msgDataBytes); out.writeBytes(msgDataBytes);
} }

View File

@ -30,8 +30,8 @@ public class HttpClientProxyClientProxyTypeAdvanced extends AbstractHttpClientPr
@Override @Override
protected void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg nettyProxyMsg) { protected void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg nettyProxyMsg) {
Channel channel = nettyChannelContext.channel(); Channel channel = nettyChannelContext.channel();
String targetPortString = nettyProxyMsg.getTargetPortString(); String targetPortString = nettyProxyMsg.targetPort();
String targetIpString = nettyProxyMsg.getTargetIpString(); String targetIpString = nettyProxyMsg.targetIp();
Bootstrap b = new Bootstrap(); Bootstrap b = new Bootstrap();
b.group(channel.eventLoop()) b.group(channel.eventLoop())
.channel(NioSocketChannel.class) .channel(NioSocketChannel.class)

View File

@ -29,8 +29,8 @@ public class HttpProtocolHandleChannelLocalProxyTypeAdvanced extends AbstractHtt
*/ */
@Override @Override
protected void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg nettyProxyMsg) { protected void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg nettyProxyMsg) {
String targetPortString = nettyProxyMsg.getTargetPortString(); String targetPortString = nettyProxyMsg.targetPort();
String targetIpString = nettyProxyMsg.getTargetIpString(); String targetIpString = nettyProxyMsg.targetIp();
Bootstrap b = new Bootstrap(); Bootstrap b = new Bootstrap();
Channel channel = nettyChannelContext.channel(); Channel channel = nettyChannelContext.channel();
b.group(channel.eventLoop()) b.group(channel.eventLoop())

View File

@ -37,8 +37,8 @@ public class NettySocketProtocolHandleSocketLocalProxyTypeAdvanced
Channel channel = nettySocketChannelContext.channel(); Channel channel = nettySocketChannelContext.channel();
ChannelHandlerContext channelHandlerContext = nettySocketChannelContext.channelHandlerContext(); ChannelHandlerContext channelHandlerContext = nettySocketChannelContext.channelHandlerContext();
EventLoopGroup group = EventLoopGroupFactory.createClientWorkGroup(); EventLoopGroup group = EventLoopGroupFactory.createClientWorkGroup();
String host = nettyProxyMsg.getTargetIpString(); String host = nettyProxyMsg.targetIp();
Integer port = Integer.parseInt(nettyProxyMsg.getTargetPortString()); Integer port = Integer.parseInt(nettyProxyMsg.targetPort());
Bootstrap b = new Bootstrap(); Bootstrap b = new Bootstrap();
Socks5AddressType socks5AddressType = nettySocketChannelContext.getSocks5AddressType(); Socks5AddressType socks5AddressType = nettySocketChannelContext.getSocks5AddressType();

View File

@ -83,11 +83,11 @@ public class NettyHttpProxyHandler extends ChannelInboundHandlerAdapter {
ProxyRoute route = RouteContext.getRoute(originHost, String.valueOf(originPort)); ProxyRoute route = RouteContext.getRoute(originHost, String.valueOf(originPort));
String namespace = route.getNamespace();
proxyMsg.setVisitorId(visitorId); proxyMsg.setVisitorId(visitorId);
proxyMsg.setData(bytes); proxyMsg.setData(bytes);
proxyMsg.setNamespace(namespace);
if(ObjectUtils.isEmpty(route)){ if(ObjectUtils.isEmpty(route)){
// 本地代理 // 本地代理

View File

@ -60,7 +60,8 @@ public class NettySocks5CommandRequestHandler extends SimpleChannelInboundHandle
proxyMsg.setVisitorId(visitorId); proxyMsg.setVisitorId(visitorId);
ProxyRoute route = RouteContext.getRoute(originHost, String.valueOf(originPort)); ProxyRoute route = RouteContext.getRoute(originHost, String.valueOf(originPort));
String namespace = route.getNamespace();
proxyMsg.setNamespace(namespace);
if(ObjectUtils.isEmpty(route)){ if(ObjectUtils.isEmpty(route)){

View File

@ -24,6 +24,10 @@ public class ClientProxyRoute implements ProxyRoute{
* 虚拟端口 * 虚拟端口
*/ */
private String virtualPort; private String virtualPort;
/**
* 命名空间
*/
private String namespace;
/** /**
* *

View File

@ -6,6 +6,9 @@ package org.framework.lazy.cloud.network.heartbeat.protocol.route;
public interface ProxyRoute { public interface ProxyRoute {
String getNamespace();
String getVirtualIp(); String getVirtualIp();

View File

@ -9,6 +9,11 @@ import lombok.Data;
@Data @Data
public class ServerProxyRoute implements ProxyRoute { public class ServerProxyRoute implements ProxyRoute {
/**
* 命名空间
*/
private String namespace;
/** /**
* *
* 服务端ip * 服务端ip

View File

@ -161,7 +161,7 @@ public class LazyNettyClusterNodeRepositoryImpl implements LazyNettyClusterNodeR
// 查询这个节点下客户端注册是否正常 // 查询这个节点下客户端注册是否正常
List<LazyNettyClientStateDO> lazyNettyClientStateDOList = lazyLambdaStream.selectList( List<LazyNettyClientStateDO> lazyNettyClientStateDOList = lazyLambdaStream.selectList(
LazyWrappers.<LazyNettyClientStateDO>lambdaWrapper() LazyWrappers.<LazyNettyClientStateDO>lambdaWrapper()
.eq(LazyNettyClientStateDO::getServerId, clusterNodeId) .eq(LazyNettyClientStateDO::getNamespace, clusterNodeId)
); );
boolean anyMatch = lazyNettyClientStateDOList.stream() boolean anyMatch = lazyNettyClientStateDOList.stream()
.anyMatch(lazyNettyClientStateDO -> .anyMatch(lazyNettyClientStateDO ->

View File

@ -76,11 +76,12 @@ public class ServerHandleTcpClientConnectSuccessTypeAdvanced extends AbstractHan
public void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg msg) { public void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg msg) {
Channel newChannel = nettyChannelContext.channel(); Channel newChannel = nettyChannelContext.channel();
String clientId = msg.getClientIdString(); String serverId = msg.namespace();
String clientId = msg.clientId();
String appKey = msg.getAppKeyString(); String appKey = msg.getAppKeyString();
String appSecret = msg.getAppSecretString(); String appSecret = msg.getAppSecretString();
String originalIp = msg.getOriginalIpString(); String originalIp = msg.getOriginalIpString();
ChannelContext.push(newChannel, clientId); ChannelContext.push(newChannel,serverId, clientId);
ChannelAttributeKeyUtils.buildClientId(newChannel, clientId); ChannelAttributeKeyUtils.buildClientId(newChannel, clientId);
ChannelAttributeKeyUtils.buildAppKey(newChannel, appKey); ChannelAttributeKeyUtils.buildAppKey(newChannel, appKey);
@ -172,11 +173,13 @@ public class ServerHandleTcpClientConnectSuccessTypeAdvanced extends AbstractHan
.accept(lazyInternalNetworkClientPermeateServerMappingDTOS -> { .accept(lazyInternalNetworkClientPermeateServerMappingDTOS -> {
for (LazyClientPermeateClientMappingDTO lazyClientPermeateClientMappingDTO : lazyInternalNetworkClientPermeateServerMappingDTOS) { for (LazyClientPermeateClientMappingDTO lazyClientPermeateClientMappingDTO : lazyInternalNetworkClientPermeateServerMappingDTOS) {
String selfNamespace = lazyClientPermeateClientMappingDTO.getNamespace();
String permeateTargetIp = lazyClientPermeateClientMappingDTO.getPermeateTargetIp(); String permeateTargetIp = lazyClientPermeateClientMappingDTO.getPermeateTargetIp();
Integer permeateTargetPort = lazyClientPermeateClientMappingDTO.getPermeateTargetPort(); Integer permeateTargetPort = lazyClientPermeateClientMappingDTO.getPermeateTargetPort();
Integer visitorPort = lazyClientPermeateClientMappingDTO.getVisitorPort(); Integer visitorPort = lazyClientPermeateClientMappingDTO.getVisitorPort();
String toClientId = lazyClientPermeateClientMappingDTO.getToClientId(); String toClientId = lazyClientPermeateClientMappingDTO.getToClientId();
NettyProxyMsg nettyMsg = new NettyProxyMsg(); NettyProxyMsg nettyMsg = new NettyProxyMsg();
nettyMsg.setNamespace(selfNamespace);
nettyMsg.setType(TcpMessageType.TCP_DISTRIBUTE_CLIENT_PERMEATE_CLIENT_INIT); nettyMsg.setType(TcpMessageType.TCP_DISTRIBUTE_CLIENT_PERMEATE_CLIENT_INIT);
nettyMsg.setClientTargetIp(permeateTargetIp); nettyMsg.setClientTargetIp(permeateTargetIp);
nettyMsg.setClientTargetPort(permeateTargetPort); nettyMsg.setClientTargetPort(permeateTargetPort);

View File

@ -2,9 +2,10 @@ package org.framework.lazy.cloud.network.heartbeat.server.netty.permeate.tcp.adv
import io.netty.channel.Channel; import io.netty.channel.Channel;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.*; import org.framework.lazy.cloud.network.heartbeat.common.ChannelContext;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyProxyMsg; import org.framework.lazy.cloud.network.heartbeat.common.NettyTransferChannelContext;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyChannelContext; import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyChannelContext;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.tcp.server.AbstractHandleTcpReportClientTransferClientPermeateChannelConnectionSuccessfulTypeAdvanced; import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.tcp.server.AbstractHandleTcpReportClientTransferClientPermeateChannelConnectionSuccessfulTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.constant.TcpMessageType; import org.framework.lazy.cloud.network.heartbeat.common.constant.TcpMessageType;
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils; import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
@ -18,7 +19,8 @@ import org.springframework.stereotype.Component;
@Role(BeanDefinition.ROLE_INFRASTRUCTURE) @Role(BeanDefinition.ROLE_INFRASTRUCTURE)
@Slf4j @Slf4j
@Component @Component
public class ServerHandleTcpReportClientTransferClientPermeateChannelConnectionSuccessfulTypeAdvanced extends AbstractHandleTcpReportClientTransferClientPermeateChannelConnectionSuccessfulTypeAdvanced<NettyProxyMsg> { public class ServerHandleTcpReportClientTransferClientPermeateChannelConnectionSuccessfulTypeAdvanced
extends AbstractHandleTcpReportClientTransferClientPermeateChannelConnectionSuccessfulTypeAdvanced<NettyProxyMsg> {
/** /**
* 处理当前数据 * 处理当前数据
* *
@ -33,14 +35,15 @@ public class ServerHandleTcpReportClientTransferClientPermeateChannelConnectionS
byte[] msgVisitorPort = nettyProxyMsg.getVisitorPort(); byte[] msgVisitorPort = nettyProxyMsg.getVisitorPort();
byte[] msgClientTargetIp = nettyProxyMsg.getClientTargetIp(); byte[] msgClientTargetIp = nettyProxyMsg.getClientTargetIp();
byte[] msgClientTargetPort = nettyProxyMsg.getClientTargetPort(); byte[] msgClientTargetPort = nettyProxyMsg.getClientTargetPort();
byte[] clientId = nettyProxyMsg.getClientId();// 目标客户端ID String clientId = nettyProxyMsg.clientId();// 目标客户端ID
String namespace = nettyProxyMsg.namespace();
ChannelAttributeKeyUtils.buildClientId(transferChannel, clientId); ChannelAttributeKeyUtils.buildClientId(transferChannel, clientId);
ChannelAttributeKeyUtils.buildVisitorPort(transferChannel, Integer.parseInt(new String(msgVisitorPort))); ChannelAttributeKeyUtils.buildVisitorPort(transferChannel, Integer.parseInt(new String(msgVisitorPort)));
ChannelAttributeKeyUtils.buildVisitorId(transferChannel, msgVisitorId); ChannelAttributeKeyUtils.buildVisitorId(transferChannel, msgVisitorId);
// 绑定访客通道 // 绑定访客通道
NettyTransferChannelContext.pushVisitor(transferChannel,msgVisitorId); NettyTransferChannelContext.pushVisitor(transferChannel,msgVisitorId);
Channel clientChannel = ChannelContext.getLoadBalance(clientId); Channel clientChannel = ChannelContext.getLoadBalance(namespace, clientId);
NettyProxyMsg clientConnectTagetNettyProxyMsg = new NettyProxyMsg(); NettyProxyMsg clientConnectTagetNettyProxyMsg = new NettyProxyMsg();
clientConnectTagetNettyProxyMsg.setVisitorId(msgVisitorId); clientConnectTagetNettyProxyMsg.setVisitorId(msgVisitorId);

View File

@ -36,7 +36,7 @@ public class ServerHandleTcpReportClientTransferClientResponseTypeAdvanced exten
byte[] msgVisitorPort = nettyProxyMsg.getVisitorPort(); byte[] msgVisitorPort = nettyProxyMsg.getVisitorPort();
byte[] msgClientTargetIp = nettyProxyMsg.getClientTargetIp(); byte[] msgClientTargetIp = nettyProxyMsg.getClientTargetIp();
byte[] msgClientTargetPort = nettyProxyMsg.getClientTargetPort(); byte[] msgClientTargetPort = nettyProxyMsg.getClientTargetPort();
String clientId = nettyProxyMsg.getClientIdString(); String clientId = nettyProxyMsg.clientId();
// 下发客户端初始化成功 // 下发客户端初始化成功
Channel nextChannel = ChannelAttributeKeyUtils.getTransferNextChannel(channel); Channel nextChannel = ChannelAttributeKeyUtils.getTransferNextChannel(channel);

View File

@ -36,7 +36,7 @@ public class ServerHandleTcpReportClientTransferClientTypeAdvanced extends Abstr
byte[] msgVisitorPort = nettyProxyMsg.getVisitorPort(); byte[] msgVisitorPort = nettyProxyMsg.getVisitorPort();
byte[] msgClientTargetIp = nettyProxyMsg.getClientTargetIp(); byte[] msgClientTargetIp = nettyProxyMsg.getClientTargetIp();
byte[] msgClientTargetPort = nettyProxyMsg.getClientTargetPort(); byte[] msgClientTargetPort = nettyProxyMsg.getClientTargetPort();
String clientId = nettyProxyMsg.getClientIdString(); String clientId = nettyProxyMsg.clientId();
// 下发客户端初始化成功 // 下发客户端初始化成功
Channel nextChannel = ChannelAttributeKeyUtils.getTransferNextChannel(channel); Channel nextChannel = ChannelAttributeKeyUtils.getTransferNextChannel(channel);
Integer visitorPort = ChannelAttributeKeyUtils.getVisitorPort(channel); Integer visitorPort = ChannelAttributeKeyUtils.getVisitorPort(channel);

View File

@ -47,9 +47,10 @@ public class ServerHandleTcpReportDisconnectTypeAdvanced extends AbstractHandleT
Channel deathChannel = nettyChannelContext.channel(); Channel deathChannel = nettyChannelContext.channel();
log.debug("close the channel with id :{}",deathChannel.id().asLongText()); log.debug("close the channel with id :{}",deathChannel.id().asLongText());
// 关闭连接通知 // 关闭连接通知
String clientId = msg.getClientIdString(); String clientId = msg.clientId();
String serverId = msg.namespace();
log.warn("close client :{} channel", clientId); log.warn("close client :{} channel", clientId);
Channel deathClientChannelDTO = ChannelContext.getLoadBalance(clientId); Channel deathClientChannelDTO = ChannelContext.getLoadBalance(serverId,clientId);
String appKey = ChannelAttributeKeyUtils.getAppKey(deathChannel); String appKey = ChannelAttributeKeyUtils.getAppKey(deathChannel);
String appSecret = ChannelAttributeKeyUtils.getAppSecret(deathChannel); String appSecret = ChannelAttributeKeyUtils.getAppSecret(deathChannel);
String originalIp = ChannelAttributeKeyUtils.getOriginalIp(deathChannel); String originalIp = ChannelAttributeKeyUtils.getOriginalIp(deathChannel);
@ -58,11 +59,12 @@ public class ServerHandleTcpReportDisconnectTypeAdvanced extends AbstractHandleT
LazyNettyClientLoginCommand lazyNettyClientLoginCommand = new LazyNettyClientLoginCommand(); LazyNettyClientLoginCommand lazyNettyClientLoginCommand = new LazyNettyClientLoginCommand();
lazyNettyClientLoginCommand.setClientId(clientId); lazyNettyClientLoginCommand.setClientId(clientId);
lazyNettyClientLoginCommand.setNamespace(serverId);
lazyNettyClientLoginCommand.setAppKey(appKey); lazyNettyClientLoginCommand.setAppKey(appKey);
lazyNettyClientLoginCommand.setAppSecret(appSecret); lazyNettyClientLoginCommand.setAppSecret(appSecret);
lazyNettyClientLoginCommand.setOriginalIp(originalIp); lazyNettyClientLoginCommand.setOriginalIp(originalIp);
lazyClientStatsChangeApplication.clientOffLine(lazyNettyClientLoginCommand); lazyClientStatsChangeApplication.clientOffLine(lazyNettyClientLoginCommand);
ChannelContext.remove(clientId); ChannelContext.remove(serverId,clientId);
// 通知其他客户端 channelId 关闭了 // 通知其他客户端 channelId 关闭了
ChannelContext.getChannels().forEach((existClientId, channels) -> { ChannelContext.getChannels().forEach((existClientId, channels) -> {

View File

@ -43,11 +43,12 @@ public class ServerHandleTcpReportStagingClosedTypeAdvanced extends AbstractHand
String appSecret = ChannelAttributeKeyUtils.getAppSecret(stagingClosedChannel); String appSecret = ChannelAttributeKeyUtils.getAppSecret(stagingClosedChannel);
String originalIp = ChannelAttributeKeyUtils.getOriginalIp(stagingClosedChannel); String originalIp = ChannelAttributeKeyUtils.getOriginalIp(stagingClosedChannel);
byte[] clientIdBytes = msg.getClientId(); String serverId= msg.namespace();
String clientId = msg.clientId();
// 获取所有通道 // 获取所有通道
List<Channel> stagingOpenedClientChannel = ChannelContext.get(clientIdBytes); List<Channel> stagingOpenedClientChannel = ChannelContext.get(serverId,clientId);
if (stagingOpenedClientChannel != null) { if (stagingOpenedClientChannel != null) {
String clientId = new String(clientIdBytes);
// 存储当前客户端暂存关闭 // 存储当前客户端暂存关闭
LazyNettyClientLoginCommand lazyNettyClientLoginCommand = new LazyNettyClientLoginCommand(); LazyNettyClientLoginCommand lazyNettyClientLoginCommand = new LazyNettyClientLoginCommand();
lazyNettyClientLoginCommand.setClientId(clientId); lazyNettyClientLoginCommand.setClientId(clientId);

View File

@ -42,15 +42,15 @@ public class ServerHandleTcpReportStagingOpenedTypeAdvanced extends AbstractHand
protected void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg msg) { protected void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg msg) {
Channel stagingOpenedChannel = nettyChannelContext.channel(); Channel stagingOpenedChannel = nettyChannelContext.channel();
// 获取所有通道 // 获取所有通道
byte[] clientIdBytes = msg.getClientId(); String serverId = msg.namespace();
String clientId = msg.clientId();
String appKey = ChannelAttributeKeyUtils.getAppKey(stagingOpenedChannel); String appKey = ChannelAttributeKeyUtils.getAppKey(stagingOpenedChannel);
String appSecret = ChannelAttributeKeyUtils.getAppSecret(stagingOpenedChannel); String appSecret = ChannelAttributeKeyUtils.getAppSecret(stagingOpenedChannel);
String originalIp = ChannelAttributeKeyUtils.getOriginalIp(stagingOpenedChannel); String originalIp = ChannelAttributeKeyUtils.getOriginalIp(stagingOpenedChannel);
List<Channel> stagingOpenedClientChannel = ChannelContext.get(clientIdBytes); List<Channel> stagingOpenedClientChannel = ChannelContext.get(serverId,clientId);
// 存储当前客户端暂存关闭 // 存储当前客户端暂存关闭
String clientId = new String(clientIdBytes);
LazyNettyClientLoginCommand lazyNettyClientLoginCommand = new LazyNettyClientLoginCommand(); LazyNettyClientLoginCommand lazyNettyClientLoginCommand = new LazyNettyClientLoginCommand();
lazyNettyClientLoginCommand.setClientId(clientId); lazyNettyClientLoginCommand.setClientId(clientId);
lazyNettyClientLoginCommand.setAppKey(appKey); lazyNettyClientLoginCommand.setAppKey(appKey);

View File

@ -40,6 +40,7 @@ public class NettyTcpServerPermeateClientVisitorHandler extends SimpleChannelInb
// 生成访客ID // 生成访客ID
String visitorId = UUID.randomUUID().toString(); String visitorId = UUID.randomUUID().toString();
String namespace = internalNetworkPenetrationRealClient.getNamespace();
String clientId = internalNetworkPenetrationRealClient.getClientId(); String clientId = internalNetworkPenetrationRealClient.getClientId();
Integer visitorPort = internalNetworkPenetrationRealClient.getVisitorPort(); Integer visitorPort = internalNetworkPenetrationRealClient.getVisitorPort();
String clientTargetIp = internalNetworkPenetrationRealClient.getClientTargetIp(); String clientTargetIp = internalNetworkPenetrationRealClient.getClientTargetIp();
@ -50,6 +51,7 @@ public class NettyTcpServerPermeateClientVisitorHandler extends SimpleChannelInb
ChannelAttributeKeyUtils.buildVisitorId(visitorChannel, visitorId); ChannelAttributeKeyUtils.buildVisitorId(visitorChannel, visitorId);
ChannelAttributeKeyUtils.buildClientId(visitorChannel, clientId); ChannelAttributeKeyUtils.buildClientId(visitorChannel, clientId);
NettyProxyMsg nettyProxyMsg = new NettyProxyMsg(); NettyProxyMsg nettyProxyMsg = new NettyProxyMsg();
nettyProxyMsg.setNamespace(namespace);
nettyProxyMsg.setType(TcpMessageType.TCP_DISTRIBUTE_SINGLE_CLIENT_REAL_CONNECT); nettyProxyMsg.setType(TcpMessageType.TCP_DISTRIBUTE_SINGLE_CLIENT_REAL_CONNECT);
nettyProxyMsg.setClientId(clientId); nettyProxyMsg.setClientId(clientId);
nettyProxyMsg.setVisitorPort(visitorPort); nettyProxyMsg.setVisitorPort(visitorPort);
@ -62,7 +64,7 @@ public class NettyTcpServerPermeateClientVisitorHandler extends SimpleChannelInb
// Channel transferChannel = nettyChannelPool.availableChannel(visitorId); // Channel transferChannel = nettyChannelPool.availableChannel(visitorId);
// if (transferChannel == null) { // if (transferChannel == null) {
// 客户端心跳通道 // 客户端心跳通道
Channel clientChannel = ChannelContext.getLoadBalance(clientId); Channel clientChannel = ChannelContext.getLoadBalance(namespace,clientId);
if (clientChannel != null) { if (clientChannel != null) {
log.info("通过客户端:{},获取通道而后创建连接", clientId); log.info("通过客户端:{},获取通道而后创建连接", clientId);
clientChannel.writeAndFlush(nettyProxyMsg); clientChannel.writeAndFlush(nettyProxyMsg);

View File

@ -106,6 +106,10 @@ public class NettyTcpServerPermeateClientVisitorSocket implements PermeateVisito
public static final class NettyVisitorSocketBuilder { public static final class NettyVisitorSocketBuilder {
/**
* 命名空间
*/
private String namespace;
/** /**
* 客户端ID * 客户端ID
*/ */
@ -140,6 +144,16 @@ public class NettyTcpServerPermeateClientVisitorSocket implements PermeateVisito
return new NettyVisitorSocketBuilder(); return new NettyVisitorSocketBuilder();
} }
/**
* 填充客户端
*
* @param clientId 客户端
* @return 返回当前对象
*/
public NettyVisitorSocketBuilder builderNamespace(String namespace) {
this.namespace = namespace;
return this;
}
/** /**
* 填充客户端 * 填充客户端
* *
@ -207,6 +221,9 @@ public class NettyTcpServerPermeateClientVisitorSocket implements PermeateVisito
} }
public NettyTcpServerPermeateClientVisitorSocket build() { public NettyTcpServerPermeateClientVisitorSocket build() {
if (namespace == null) {
throw new IllegalArgumentException("namespace must not null");
}
if (clientId == null) { if (clientId == null) {
throw new IllegalArgumentException("clientId must not null"); throw new IllegalArgumentException("clientId must not null");
} }
@ -221,6 +238,7 @@ public class NettyTcpServerPermeateClientVisitorSocket implements PermeateVisito
} }
InternalNetworkPenetrationRealClient internalNetworkPenetrationRealClient = InternalNetworkPenetrationRealClient InternalNetworkPenetrationRealClient internalNetworkPenetrationRealClient = InternalNetworkPenetrationRealClient
.builder() .builder()
.namespace(namespace)
.clientId(clientId) .clientId(clientId)
.clientTargetIp(clientTargetIp) .clientTargetIp(clientTargetIp)
.clientTargetPort(clientTargetPort) .clientTargetPort(clientTargetPort)

View File

@ -66,12 +66,12 @@ public class ServerHandleUdpClientConnectSuccessTypeAdvanced extends AbstractHan
@Override @Override
public void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg msg) { public void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg msg) {
Channel newChannel = nettyChannelContext.channel(); Channel newChannel = nettyChannelContext.channel();
String serverId = msg.namespace();
String clientId = msg.getClientIdString(); String clientId = msg.clientId();
String appKey = msg.getAppKeyString(); String appKey = msg.getAppKeyString();
String appSecret = msg.getAppSecretString(); String appSecret = msg.getAppSecretString();
String originalIp = msg.getOriginalIpString(); String originalIp = msg.getOriginalIpString();
ChannelContext.push(newChannel, clientId); ChannelContext.push(newChannel, serverId,clientId);
ChannelAttributeKeyUtils.buildClientId(newChannel, clientId); ChannelAttributeKeyUtils.buildClientId(newChannel, clientId);
ChannelAttributeKeyUtils.buildAppKey(newChannel, appKey); ChannelAttributeKeyUtils.buildAppKey(newChannel, appKey);

View File

@ -3,11 +3,11 @@ package org.framework.lazy.cloud.network.heartbeat.server.netty.permeate.udp.adv
import io.netty.channel.Channel; import io.netty.channel.Channel;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.ChannelContext; import org.framework.lazy.cloud.network.heartbeat.common.ChannelContext;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyChannelContext;
import org.framework.lazy.cloud.network.heartbeat.common.constant.TcpMessageType;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.NettyTransferChannelContext; import org.framework.lazy.cloud.network.heartbeat.common.NettyTransferChannelContext;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyChannelContext;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.udp.server.AbstractHandleUdpReportClientTransferClientPermeateChannelConnectionSuccessfulTypeAdvanced; import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.udp.server.AbstractHandleUdpReportClientTransferClientPermeateChannelConnectionSuccessfulTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.constant.TcpMessageType;
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils; import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Role; import org.springframework.context.annotation.Role;
@ -30,18 +30,19 @@ public class ServerHandleUdpReportClientTransferClientPermeateChannelConnectionS
protected void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg nettyProxyMsg) { protected void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg nettyProxyMsg) {
Channel channel = nettyChannelContext.channel(); Channel channel = nettyChannelContext.channel();
// 创建目标地址连接 // 创建目标地址连接
String namespace = nettyProxyMsg.namespace();
byte[] msgVisitorId = nettyProxyMsg.getVisitorId(); byte[] msgVisitorId = nettyProxyMsg.getVisitorId();
byte[] msgVisitorPort = nettyProxyMsg.getVisitorPort(); byte[] msgVisitorPort = nettyProxyMsg.getVisitorPort();
byte[] msgClientTargetIp = nettyProxyMsg.getClientTargetIp(); String msgClientTargetIp = nettyProxyMsg.targetIp();
byte[] msgClientTargetPort = nettyProxyMsg.getClientTargetPort(); byte[] msgClientTargetPort = nettyProxyMsg.getClientTargetPort();
byte[] clientId = nettyProxyMsg.getClientId();// 目标客户端ID String clientId = nettyProxyMsg.clientId();// 目标客户端ID
ChannelAttributeKeyUtils.buildClientId(channel, clientId); ChannelAttributeKeyUtils.buildClientId(channel, clientId);
ChannelAttributeKeyUtils.buildVisitorPort(channel, Integer.parseInt(new String(msgVisitorPort))); ChannelAttributeKeyUtils.buildVisitorPort(channel, Integer.parseInt(new String(msgVisitorPort)));
ChannelAttributeKeyUtils.buildVisitorId(channel, msgVisitorId); ChannelAttributeKeyUtils.buildVisitorId(channel, msgVisitorId);
// 绑定访客通道 // 绑定访客通道
NettyTransferChannelContext.pushVisitor(channel,msgVisitorId); NettyTransferChannelContext.pushVisitor(channel,msgVisitorId);
Channel clientChannel = ChannelContext.getLoadBalance(clientId); Channel clientChannel = ChannelContext.getLoadBalance(namespace,clientId);
NettyProxyMsg clientConnectTagetNettyProxyMsg = new NettyProxyMsg(); NettyProxyMsg clientConnectTagetNettyProxyMsg = new NettyProxyMsg();
clientConnectTagetNettyProxyMsg.setVisitorId(msgVisitorId); clientConnectTagetNettyProxyMsg.setVisitorId(msgVisitorId);

View File

@ -38,7 +38,7 @@ public class ServerHandleUdpReportClientTransferClientResponseTypeAdvanced exten
byte[] msgVisitorPort = nettyProxyMsg.getVisitorPort(); byte[] msgVisitorPort = nettyProxyMsg.getVisitorPort();
byte[] msgClientTargetIp = nettyProxyMsg.getClientTargetIp(); byte[] msgClientTargetIp = nettyProxyMsg.getClientTargetIp();
byte[] msgClientTargetPort = nettyProxyMsg.getClientTargetPort(); byte[] msgClientTargetPort = nettyProxyMsg.getClientTargetPort();
String clientId = nettyProxyMsg.getClientIdString(); String clientId = nettyProxyMsg.clientId();
// 下发客户端初始化成功 // 下发客户端初始化成功
Channel nextChannel = ChannelAttributeKeyUtils.getTransferNextChannel(channel); Channel nextChannel = ChannelAttributeKeyUtils.getTransferNextChannel(channel);

View File

@ -36,7 +36,7 @@ public class ServerHandleUdpReportClientTransferClientTypeAdvanced extends Abstr
byte[] msgVisitorPort = nettyProxyMsg.getVisitorPort(); byte[] msgVisitorPort = nettyProxyMsg.getVisitorPort();
byte[] msgClientTargetIp = nettyProxyMsg.getClientTargetIp(); byte[] msgClientTargetIp = nettyProxyMsg.getClientTargetIp();
byte[] msgClientTargetPort = nettyProxyMsg.getClientTargetPort(); byte[] msgClientTargetPort = nettyProxyMsg.getClientTargetPort();
String clientId = nettyProxyMsg.getClientIdString(); String clientId = nettyProxyMsg.clientId();
// 下发客户端初始化成功 // 下发客户端初始化成功
Channel nextChannel = ChannelAttributeKeyUtils.getTransferNextChannel(channel); Channel nextChannel = ChannelAttributeKeyUtils.getTransferNextChannel(channel);
Integer visitorPort = ChannelAttributeKeyUtils.getVisitorPort(channel); Integer visitorPort = ChannelAttributeKeyUtils.getVisitorPort(channel);

View File

@ -46,9 +46,10 @@ public class ServerHandleUdpReportDisconnectTypeAdvanced extends AbstractHandleU
public void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg msg) { public void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg msg) {
Channel deathChannel = nettyChannelContext.channel(); Channel deathChannel = nettyChannelContext.channel();
// 关闭连接通知 // 关闭连接通知
String clientId = msg.getClientIdString(); String clientId = msg.clientId();
String serverId = msg.namespace();
log.warn("close client :{} channel", clientId); log.warn("close client :{} channel", clientId);
Channel deathClientChannelDTO = ChannelContext.getLoadBalance(clientId); Channel deathClientChannelDTO = ChannelContext.getLoadBalance(serverId,clientId);
String appKey = ChannelAttributeKeyUtils.getAppKey(deathChannel); String appKey = ChannelAttributeKeyUtils.getAppKey(deathChannel);
String appSecret = ChannelAttributeKeyUtils.getAppSecret(deathChannel); String appSecret = ChannelAttributeKeyUtils.getAppSecret(deathChannel);
String originalIp = ChannelAttributeKeyUtils.getOriginalIp(deathChannel); String originalIp = ChannelAttributeKeyUtils.getOriginalIp(deathChannel);
@ -61,7 +62,7 @@ public class ServerHandleUdpReportDisconnectTypeAdvanced extends AbstractHandleU
lazyNettyClientLoginCommand.setAppSecret(appSecret); lazyNettyClientLoginCommand.setAppSecret(appSecret);
lazyNettyClientLoginCommand.setOriginalIp(originalIp); lazyNettyClientLoginCommand.setOriginalIp(originalIp);
lazyClientStatsChangeApplication.clientOffLine(lazyNettyClientLoginCommand); lazyClientStatsChangeApplication.clientOffLine(lazyNettyClientLoginCommand);
ChannelContext.remove(clientId); ChannelContext.remove(serverId,clientId);
// 通知其他客户端 channelId 关闭了 // 通知其他客户端 channelId 关闭了
ChannelContext.getChannels().forEach((existClientId, channels) -> { ChannelContext.getChannels().forEach((existClientId, channels) -> {
@ -87,7 +88,7 @@ public class ServerHandleUdpReportDisconnectTypeAdvanced extends AbstractHandleU
for (NettyUdpServerPermeateClientVisitorSocket visitorSocket : visitorSockets) { for (NettyUdpServerPermeateClientVisitorSocket visitorSocket : visitorSockets) {
int visitorPort = visitorSocket.getVisitorPort(); int visitorPort = visitorSocket.getVisitorPort();
visitorSocket.close(); visitorSocket.close();
log.warn("client :[{}] visitorPort:[{}] close", new String(clientId), visitorPort); log.warn("client :[{}] visitorPort:[{}] close", clientId, visitorPort);
} }
} }

View File

@ -4,9 +4,9 @@ import io.netty.channel.Channel;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.ChannelContext; import org.framework.lazy.cloud.network.heartbeat.common.ChannelContext;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyChannelContext; import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyChannelContext;
import org.framework.lazy.cloud.network.heartbeat.common.constant.TcpMessageType;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyProxyMsg; import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.udp.server.AbstractHandleUdpReportStagingClosedTypeAdvanced; import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.udp.server.AbstractHandleUdpReportStagingClosedTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.constant.TcpMessageType;
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils; import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
import org.framework.lazy.cloud.network.heartbeat.server.standalone.application.LazyClientStatsChangeApplication; import org.framework.lazy.cloud.network.heartbeat.server.standalone.application.LazyClientStatsChangeApplication;
import org.framework.lazy.cloud.network.heartbeat.server.standalone.application.command.lazy.netty.client.state.LazyNettyClientLoginCommand; import org.framework.lazy.cloud.network.heartbeat.server.standalone.application.command.lazy.netty.client.state.LazyNettyClientLoginCommand;
@ -42,12 +42,12 @@ public class ServerHandleUdpReportStagingClosedTypeAdvanced extends AbstractHand
String appKey = ChannelAttributeKeyUtils.getAppKey(stagingClosedChannel); String appKey = ChannelAttributeKeyUtils.getAppKey(stagingClosedChannel);
String appSecret = ChannelAttributeKeyUtils.getAppSecret(stagingClosedChannel); String appSecret = ChannelAttributeKeyUtils.getAppSecret(stagingClosedChannel);
String originalIp = ChannelAttributeKeyUtils.getOriginalIp(stagingClosedChannel); String originalIp = ChannelAttributeKeyUtils.getOriginalIp(stagingClosedChannel);
String serverId = msg.namespace();
byte[] clientIdBytes = msg.getClientId(); String clientId = msg.clientId();
// 获取所有通道 // 获取所有通道
List<Channel> stagingOpenedClientChannel = ChannelContext.get(clientIdBytes); List<Channel> stagingOpenedClientChannel = ChannelContext.get(serverId, clientId);
if (stagingOpenedClientChannel != null) { if (stagingOpenedClientChannel != null) {
String clientId = new String(clientIdBytes);
// 存储当前客户端暂存关闭 // 存储当前客户端暂存关闭
LazyNettyClientLoginCommand lazyNettyClientLoginCommand = new LazyNettyClientLoginCommand(); LazyNettyClientLoginCommand lazyNettyClientLoginCommand = new LazyNettyClientLoginCommand();
lazyNettyClientLoginCommand.setClientId(clientId); lazyNettyClientLoginCommand.setClientId(clientId);

View File

@ -42,15 +42,16 @@ public class ServerHandleUdpReportStagingOpenedTypeAdvanced extends AbstractHand
protected void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg msg) { protected void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg msg) {
Channel stagingOpenedChannel = nettyChannelContext.channel(); Channel stagingOpenedChannel = nettyChannelContext.channel();
// 获取所有通道 // 获取所有通道
byte[] clientIdBytes = msg.getClientId(); String serverId = msg.namespace();
String clientId = msg.clientId();
String appKey = ChannelAttributeKeyUtils.getAppKey(stagingOpenedChannel); String appKey = ChannelAttributeKeyUtils.getAppKey(stagingOpenedChannel);
String appSecret = ChannelAttributeKeyUtils.getAppSecret(stagingOpenedChannel); String appSecret = ChannelAttributeKeyUtils.getAppSecret(stagingOpenedChannel);
String originalIp = ChannelAttributeKeyUtils.getOriginalIp(stagingOpenedChannel); String originalIp = ChannelAttributeKeyUtils.getOriginalIp(stagingOpenedChannel);
List<Channel> stagingOpenedClientChannel = ChannelContext.get(clientIdBytes); List<Channel> stagingOpenedClientChannel = ChannelContext.get(serverId,clientId);
// 存储当前客户端暂存关闭 // 存储当前客户端暂存关闭
String clientId = new String(clientIdBytes);
LazyNettyClientLoginCommand lazyNettyClientLoginCommand = new LazyNettyClientLoginCommand(); LazyNettyClientLoginCommand lazyNettyClientLoginCommand = new LazyNettyClientLoginCommand();
lazyNettyClientLoginCommand.setClientId(clientId); lazyNettyClientLoginCommand.setClientId(clientId);
lazyNettyClientLoginCommand.setAppKey(appKey); lazyNettyClientLoginCommand.setAppKey(appKey);

View File

@ -40,6 +40,7 @@ public class NettyUdpServerPermeateClientVisitorHandler extends SimpleChannelInb
// 生成访客ID // 生成访客ID
String visitorId = UUID.randomUUID().toString(); String visitorId = UUID.randomUUID().toString();
String namespace = internalNetworkPenetrationRealClient.getNamespace();
String clientId = internalNetworkPenetrationRealClient.getClientId(); String clientId = internalNetworkPenetrationRealClient.getClientId();
Integer visitorPort = internalNetworkPenetrationRealClient.getVisitorPort(); Integer visitorPort = internalNetworkPenetrationRealClient.getVisitorPort();
String clientTargetIp = internalNetworkPenetrationRealClient.getClientTargetIp(); String clientTargetIp = internalNetworkPenetrationRealClient.getClientTargetIp();
@ -54,6 +55,7 @@ public class NettyUdpServerPermeateClientVisitorHandler extends SimpleChannelInb
nettyProxyMsg.setClientId(clientId); nettyProxyMsg.setClientId(clientId);
nettyProxyMsg.setVisitorPort(visitorPort); nettyProxyMsg.setVisitorPort(visitorPort);
nettyProxyMsg.setClientTargetIp(clientTargetIp); nettyProxyMsg.setClientTargetIp(clientTargetIp);
nettyProxyMsg.setNamespace(namespace);
nettyProxyMsg.setClientTargetPort(clientTargetPort); nettyProxyMsg.setClientTargetPort(clientTargetPort);
nettyProxyMsg.setVisitorId(visitorId); nettyProxyMsg.setVisitorId(visitorId);
@ -62,7 +64,7 @@ public class NettyUdpServerPermeateClientVisitorHandler extends SimpleChannelInb
// Channel transferChannel = nettyChannelPool.availableChannel(visitorId); // Channel transferChannel = nettyChannelPool.availableChannel(visitorId);
// if (transferChannel == null) { // if (transferChannel == null) {
// 客户端心跳通道 // 客户端心跳通道
Channel clientChannel = ChannelContext.getLoadBalance(clientId); Channel clientChannel = ChannelContext.getLoadBalance(namespace,clientId);
if (clientChannel != null) { if (clientChannel != null) {
log.info("通过客户端:{},获取通道而后创建连接", clientId); log.info("通过客户端:{},获取通道而后创建连接", clientId);
clientChannel.writeAndFlush(nettyProxyMsg); clientChannel.writeAndFlush(nettyProxyMsg);

View File

@ -106,6 +106,10 @@ public class NettyUdpServerPermeateClientVisitorSocket implements PermeateVisito
public static final class NettyVisitorSocketBuilder { public static final class NettyVisitorSocketBuilder {
/**
* 命名空间
*/
private String namespace;
/** /**
* 客户端ID * 客户端ID
*/ */
@ -207,6 +211,9 @@ public class NettyUdpServerPermeateClientVisitorSocket implements PermeateVisito
} }
public NettyUdpServerPermeateClientVisitorSocket build() { public NettyUdpServerPermeateClientVisitorSocket build() {
if (namespace == null) {
throw new IllegalArgumentException("namespace must not null");
}
if (clientId == null) { if (clientId == null) {
throw new IllegalArgumentException("clientId must not null"); throw new IllegalArgumentException("clientId must not null");
} }
@ -221,6 +228,7 @@ public class NettyUdpServerPermeateClientVisitorSocket implements PermeateVisito
} }
InternalNetworkPenetrationRealClient internalNetworkPenetrationRealClient = InternalNetworkPenetrationRealClient InternalNetworkPenetrationRealClient internalNetworkPenetrationRealClient = InternalNetworkPenetrationRealClient
.builder() .builder()
.namespace(namespace)
.clientId(clientId) .clientId(clientId)
.clientTargetIp(clientTargetIp) .clientTargetIp(clientTargetIp)
.clientTargetPort(clientTargetPort) .clientTargetPort(clientTargetPort)

View File

@ -48,12 +48,13 @@ public class ServerHandleHttpReportClientProxyClientTransferRequestTypeAdvanced
public void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg nettyProxyMsg) { public void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg nettyProxyMsg) {
Channel channel = nettyChannelContext.channel(); Channel channel = nettyChannelContext.channel();
// 创建链接、发送数据 // 创建链接、发送数据
String targetPortString = nettyProxyMsg.getTargetPortString(); String targetPortString = nettyProxyMsg.targetPort();
Integer targetPort = Integer.parseInt(targetPortString); Integer targetPort = Integer.parseInt(targetPortString);
String targetIpString = nettyProxyMsg.getTargetIpString(); String targetIpString = nettyProxyMsg.targetIp();
byte[] data = nettyProxyMsg.getData(); byte[] data = nettyProxyMsg.getData();
byte[] visitorId = nettyProxyMsg.getVisitorId(); byte[] visitorId = nettyProxyMsg.getVisitorId();
byte[] clientId = nettyProxyMsg.getClientId(); String serverId = nettyProxyMsg.namespace();
String clientId = nettyProxyMsg.clientId();
String msgVisitorId = new String(visitorId); String msgVisitorId = new String(visitorId);
ChannelAttributeKeyUtils.buildClientId(channel, clientId); ChannelAttributeKeyUtils.buildClientId(channel, clientId);
ChannelAttributeKeyUtils.buildVisitorId(channel, msgVisitorId); ChannelAttributeKeyUtils.buildVisitorId(channel, msgVisitorId);
@ -66,7 +67,7 @@ public class ServerHandleHttpReportClientProxyClientTransferRequestTypeAdvanced
nettyByteBuf.setData(data); nettyByteBuf.setData(data);
ChannelAttributeKeyUtils.buildNettyByteBufData(channel, nettyByteBuf); ChannelAttributeKeyUtils.buildNettyByteBufData(channel, nettyByteBuf);
// 获取客户端心跳通道 // 获取客户端心跳通道
Channel loadBalance = ChannelContext.getLoadBalance(clientId); Channel loadBalance = ChannelContext.getLoadBalance(serverId,clientId);
NettyProxyMsg clientConnectTagetNettyProxyMsg = new NettyProxyMsg(); NettyProxyMsg clientConnectTagetNettyProxyMsg = new NettyProxyMsg();
clientConnectTagetNettyProxyMsg.setVisitorId(msgVisitorId); clientConnectTagetNettyProxyMsg.setVisitorId(msgVisitorId);

View File

@ -50,9 +50,9 @@ public class ServerHandleHttpReportClientProxyClientTransferResponseTypeAdvanced
String targetIp = ChannelAttributeKeyUtils.getTargetIp(transferNextChannel); String targetIp = ChannelAttributeKeyUtils.getTargetIp(transferNextChannel);
Integer targetPort = ChannelAttributeKeyUtils.getTargetPort(transferNextChannel); Integer targetPort = ChannelAttributeKeyUtils.getTargetPort(transferNextChannel);
String clientId = nettyProxyMsg.getClientIdString(); String clientId = nettyProxyMsg.clientId();
Integer visitorPort = nettyProxyMsg.getVisitorPortInt(); Integer visitorPort = nettyProxyMsg.getVisitorPortInt();
String visitorId = nettyProxyMsg.getVisitorIdString(); String visitorId = nettyProxyMsg.visitorId();
if(ObjectUtils.isNotEmpty(transferNextChannel)) { if(ObjectUtils.isNotEmpty(transferNextChannel)) {
log.info("目标客户端返回数据通过服务端下发到原始通道"); log.info("目标客户端返回数据通过服务端下发到原始通道");
NettyProxyMsg responseProxyMsg = new NettyProxyMsg(); NettyProxyMsg responseProxyMsg = new NettyProxyMsg();

View File

@ -51,10 +51,10 @@ public class ServerHandleHttpReportClientProxyServerTransferRequestTypeAdvanced
public void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg nettyProxyMsg) { public void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg nettyProxyMsg) {
Channel channel = nettyChannelContext.channel(); Channel channel = nettyChannelContext.channel();
// 创建链接、发送数据 // 创建链接、发送数据
String targetPortString = nettyProxyMsg.getTargetPortString(); String targetPortString = nettyProxyMsg.targetPort();
int targetPort = Integer.parseInt(targetPortString); int targetPort = Integer.parseInt(targetPortString);
String targetIpString = nettyProxyMsg.getTargetIpString(); String targetIpString = nettyProxyMsg.targetIp();
String clientIdString = nettyProxyMsg.getClientIdString(); String clientIdString = nettyProxyMsg.clientId();
byte[] data = nettyProxyMsg.getData(); byte[] data = nettyProxyMsg.getData();
byte[] visitorId = nettyProxyMsg.getVisitorId(); byte[] visitorId = nettyProxyMsg.getVisitorId();
String originalIpString = nettyProxyMsg.getOriginalIpString(); String originalIpString = nettyProxyMsg.getOriginalIpString();

View File

@ -45,8 +45,8 @@ public class ServerHandleHttpReportServerProxyClientTransferRequestTypeAdvanced
// 数据下发 // 数据下发
byte[] msgVisitorId = nettyProxyMsg.getVisitorId(); byte[] msgVisitorId = nettyProxyMsg.getVisitorId();
String targetIpString = nettyProxyMsg.getTargetIpString(); String targetIpString = nettyProxyMsg.targetIp();
String targetPortString = nettyProxyMsg.getTargetPortString(); String targetPortString = nettyProxyMsg.targetPort();
Integer targetPort = Integer.parseInt(targetPortString); Integer targetPort = Integer.parseInt(targetPortString);

View File

@ -34,33 +34,34 @@ public class ServerHandleHttpReportServerProxyClientTransferTypeAdvanced
Channel channel = nettyChannelContext.channel(); Channel channel = nettyChannelContext.channel();
// 创建链接、发送数据 // 创建链接、发送数据
String targetPortString = nettyProxyMsg.getTargetPortString(); String targetPort = nettyProxyMsg.targetPort();
String targetIpString = nettyProxyMsg.getTargetIpString(); String targetIp = nettyProxyMsg.targetIp();
byte[] data = nettyProxyMsg.getData(); byte[] data = nettyProxyMsg.getData();
byte[] visitorId = nettyProxyMsg.getVisitorId(); String visitorId = nettyProxyMsg.visitorId();
byte[] clientId = nettyProxyMsg.getClientId(); String namespace = nettyProxyMsg.namespace();
String msgVisitorId = new String(visitorId); String clientId = nettyProxyMsg.clientId();
ChannelAttributeKeyUtils.buildClientId(channel, clientId);
ChannelAttributeKeyUtils.buildVisitorId(channel, msgVisitorId);
NettyTransferChannelContext.pushVisitor(channel, msgVisitorId); ChannelAttributeKeyUtils.buildClientId(channel, clientId);
ChannelAttributeKeyUtils.buildVisitorId(channel, visitorId);
NettyTransferChannelContext.pushVisitor(channel, visitorId);
NettyByteBuf nettyByteBuf = new NettyByteBuf(); NettyByteBuf nettyByteBuf = new NettyByteBuf();
nettyByteBuf.setData(data); nettyByteBuf.setData(data);
ChannelAttributeKeyUtils.buildNettyByteBufData(channel, nettyByteBuf); ChannelAttributeKeyUtils.buildNettyByteBufData(channel, nettyByteBuf);
// 获取客户端心跳通道 // 获取客户端心跳通道
Channel loadBalance = ChannelContext.getLoadBalance(clientId); Channel loadBalance = ChannelContext.getLoadBalance(namespace,clientId);
NettyProxyMsg clientConnectTagetNettyProxyMsg = new NettyProxyMsg(); NettyProxyMsg clientConnectTagetNettyProxyMsg = new NettyProxyMsg();
clientConnectTagetNettyProxyMsg.setVisitorId(msgVisitorId); clientConnectTagetNettyProxyMsg.setVisitorId(visitorId);
clientConnectTagetNettyProxyMsg.setClientTargetIp(targetIpString); clientConnectTagetNettyProxyMsg.setClientTargetIp(targetIp);
clientConnectTagetNettyProxyMsg.setClientTargetPort(Integer.parseInt(targetPortString)); clientConnectTagetNettyProxyMsg.setClientTargetPort(Integer.parseInt(targetPort));
clientConnectTagetNettyProxyMsg.setClientId(clientId); clientConnectTagetNettyProxyMsg.setClientId(clientId);
clientConnectTagetNettyProxyMsg.setType(ProxyMessageType.HTTP_DISTRIBUTE_SERVER_PROXY_CLIENT_CONNECTION_SUCCESSFUL_); clientConnectTagetNettyProxyMsg.setType(ProxyMessageType.HTTP_DISTRIBUTE_SERVER_PROXY_CLIENT_CONNECTION_SUCCESSFUL_);
if (loadBalance != null) { if (loadBalance != null) {
// 让客户端主动创建一个数据传输通道 // 让客户端主动创建一个数据传输通道
loadBalance.writeAndFlush(clientConnectTagetNettyProxyMsg); loadBalance.writeAndFlush(clientConnectTagetNettyProxyMsg);
}else { }else {
log.error("can not find target client:【】 nettyChannelContext",clientId); log.error("can not find target client:【{}】 nettyChannelContext",clientId);
} }
} }

View File

@ -1,13 +1,7 @@
package org.framework.lazy.cloud.network.heartbeat.server.netty.proxy.socks.advanced; package org.framework.lazy.cloud.network.heartbeat.server.netty.proxy.socks.advanced;
import io.netty.bootstrap.Bootstrap; import io.netty.channel.Channel;
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.Socks5CommandStatus;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.ChannelContext; import org.framework.lazy.cloud.network.heartbeat.common.ChannelContext;
import org.framework.lazy.cloud.network.heartbeat.common.NettyTransferChannelContext; import org.framework.lazy.cloud.network.heartbeat.common.NettyTransferChannelContext;
@ -15,17 +9,12 @@ import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyC
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyProxyMsg; import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.proxy.socks.server.AbstractHandleSocksReportClientProxyClientConnectionTransferTypeAdvanced; import org.framework.lazy.cloud.network.heartbeat.common.advanced.proxy.socks.server.AbstractHandleSocksReportClientProxyClientConnectionTransferTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.constant.ProxyMessageType; import org.framework.lazy.cloud.network.heartbeat.common.constant.ProxyMessageType;
import org.framework.lazy.cloud.network.heartbeat.common.decoder.TransferDecoder;
import org.framework.lazy.cloud.network.heartbeat.common.factory.EventLoopGroupFactory;
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils; import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
import org.framework.lazy.cloud.network.heartbeat.server.netty.proxy.socks.handler.NettySocksClientProxyServerRealHandler;
import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Role; import org.springframework.context.annotation.Role;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.wu.framework.core.utils.ObjectUtils; import org.wu.framework.core.utils.ObjectUtils;
import java.net.InetSocketAddress;
@Role(BeanDefinition.ROLE_INFRASTRUCTURE) @Role(BeanDefinition.ROLE_INFRASTRUCTURE)
@Slf4j @Slf4j
@ -44,11 +33,12 @@ public class ServerHandleSocksReportClientProxyClientConnectTransferTypeAdvanced
public void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg nettyProxyMsg) { public void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg nettyProxyMsg) {
Channel transferChannel = nettyChannelContext.channel(); Channel transferChannel = nettyChannelContext.channel();
String host = nettyProxyMsg.getTargetIpString(); String namespace = nettyProxyMsg.namespace();
Integer port = Integer.parseInt(nettyProxyMsg.getTargetPortString()); String host = nettyProxyMsg.targetIp();
Integer port = Integer.parseInt(nettyProxyMsg.targetPort());
byte[] data = nettyProxyMsg.getData(); byte[] data = nettyProxyMsg.getData();
byte[] visitorId = nettyProxyMsg.getVisitorId(); byte[] visitorId = nettyProxyMsg.getVisitorId();
byte[] targetClientId = nettyProxyMsg.getClientId(); String targetClientId = nettyProxyMsg.clientId();
String msgVisitorId = new String(visitorId); String msgVisitorId = new String(visitorId);
ChannelAttributeKeyUtils.buildClientId(transferChannel, targetClientId); ChannelAttributeKeyUtils.buildClientId(transferChannel, targetClientId);
ChannelAttributeKeyUtils.buildVisitorId(transferChannel, msgVisitorId); ChannelAttributeKeyUtils.buildVisitorId(transferChannel, msgVisitorId);
@ -58,7 +48,7 @@ public class ServerHandleSocksReportClientProxyClientConnectTransferTypeAdvanced
NettyTransferChannelContext.pushVisitor(transferChannel, msgVisitorId); NettyTransferChannelContext.pushVisitor(transferChannel, msgVisitorId);
// 客户端连接客户端传输通道 // 客户端连接客户端传输通道
Channel loadBalance = ChannelContext.getLoadBalance(targetClientId); Channel loadBalance = ChannelContext.getLoadBalance(namespace, targetClientId);
if(ObjectUtils.isNotEmpty(loadBalance)) { if(ObjectUtils.isNotEmpty(loadBalance)) {
// 下发创建新链接指令 // 下发创建新链接指令
NettyProxyMsg otherClientConnectServer = new NettyProxyMsg(); NettyProxyMsg otherClientConnectServer = new NettyProxyMsg();

View File

@ -9,7 +9,6 @@ import io.netty.handler.codec.socksx.v5.DefaultSocks5CommandResponse;
import io.netty.handler.codec.socksx.v5.Socks5AddressType; import io.netty.handler.codec.socksx.v5.Socks5AddressType;
import io.netty.handler.codec.socksx.v5.Socks5CommandStatus; import io.netty.handler.codec.socksx.v5.Socks5CommandStatus;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
import org.framework.lazy.cloud.network.heartbeat.common.NettyTransferChannelContext; import org.framework.lazy.cloud.network.heartbeat.common.NettyTransferChannelContext;
import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelTypeAdapter; 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.advanced.HandleChannelTypeAdvanced;
@ -49,8 +48,8 @@ public class ServerHandleSocksReportClientProxyServerConnectTransferTypeAdvanced
Channel transferChannel = nettyChannelContext.channel(); Channel transferChannel = nettyChannelContext.channel();
String host = nettyProxyMsg.getTargetIpString(); String host = nettyProxyMsg.targetIp();
Integer port = Integer.parseInt(nettyProxyMsg.getTargetPortString()); Integer port = Integer.parseInt(nettyProxyMsg.targetPort());
byte[] data = nettyProxyMsg.getData(); byte[] data = nettyProxyMsg.getData();
byte[] visitorId = nettyProxyMsg.getVisitorId(); byte[] visitorId = nettyProxyMsg.getVisitorId();
byte[] clientId = nettyProxyMsg.getClientId(); byte[] clientId = nettyProxyMsg.getClientId();

View File

@ -1,7 +1,7 @@
package org.framework.lazy.cloud.network.heartbeat.server.netty.proxy.socks.advanced; package org.framework.lazy.cloud.network.heartbeat.server.netty.proxy.socks.advanced;
import io.netty.channel.*; import io.netty.channel.Channel;
import io.netty.handler.codec.socksx.v5.Socks5AddressType; import io.netty.handler.codec.socksx.v5.Socks5AddressType;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.ChannelContext; import org.framework.lazy.cloud.network.heartbeat.common.ChannelContext;
@ -35,13 +35,14 @@ public class ServerHandleSocksReportServerProxyClientTypeAdvanced
public void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg nettyProxyMsg) { public void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg nettyProxyMsg) {
NettySocketChannelContext nettySocketChannelContext = (NettySocketChannelContext) nettyChannelContext; NettySocketChannelContext nettySocketChannelContext = (NettySocketChannelContext) nettyChannelContext;
Channel visitorrChannel = nettySocketChannelContext.channel(); Channel visitorrChannel = nettySocketChannelContext.channel();
String host = nettyProxyMsg.getTargetIpString(); String namespace = nettyProxyMsg.namespace();
Integer port = Integer.parseInt(nettyProxyMsg.getTargetPortString()); String host = nettyProxyMsg.targetIp();
Integer port = Integer.parseInt(nettyProxyMsg.targetPort());
byte[] visitorId = nettyProxyMsg.getVisitorId(); byte[] visitorId = nettyProxyMsg.getVisitorId();
byte[] targetClientId = nettyProxyMsg.getClientId(); String targetClientId = nettyProxyMsg.clientId();
Socks5AddressType socks5AddressType = nettySocketChannelContext.getSocks5AddressType(); Socks5AddressType socks5AddressType = nettySocketChannelContext.getSocks5AddressType();
byte socks5AddressTypeByte = socks5AddressType.byteValue(); byte socks5AddressTypeByte = socks5AddressType.byteValue();
@ -55,7 +56,7 @@ public class ServerHandleSocksReportServerProxyClientTypeAdvanced
NettyTransferChannelContext.pushVisitor(visitorrChannel, msgVisitorId); NettyTransferChannelContext.pushVisitor(visitorrChannel, msgVisitorId);
// 客户端连接客户端传输通道 // 客户端连接客户端传输通道
Channel loadBalance = ChannelContext.getLoadBalance(targetClientId); Channel loadBalance = ChannelContext.getLoadBalance(namespace,targetClientId);
if(ObjectUtils.isNotEmpty(loadBalance)) { if(ObjectUtils.isNotEmpty(loadBalance)) {
// 下发创建新链接指令 // 下发创建新链接指令
NettyProxyMsg otherClientConnectServer = new NettyProxyMsg(); NettyProxyMsg otherClientConnectServer = new NettyProxyMsg();

View File

@ -50,8 +50,8 @@ public class LazyNettyClientBlacklistQueryListCommand {
@Schema(description = "更新时间", name = "updateTime", example = "") @Schema(description = "更新时间", name = "updateTime", example = "")
private LocalDateTime updateTime; private LocalDateTime updateTime;
/** /**
* 服务端ID * 命名空间
*/ */
@Schema(description = "服务端ID", name = "serverId", example = "") @Schema(description = "命名空间", name = "namespace", example = "")
private String serverId; private String namespace;
} }

View File

@ -50,8 +50,8 @@ public class LazyNettyClientBlacklistQueryOneCommand {
@Schema(description = "更新时间", name = "updateTime", example = "") @Schema(description = "更新时间", name = "updateTime", example = "")
private LocalDateTime updateTime; private LocalDateTime updateTime;
/** /**
* 服务端ID * 命名空间
*/ */
@Schema(description = "服务端ID", name = "serverId", example = "") @Schema(description = "命名空间", name = "namespace", example = "")
private String serverId; private String namespace;
} }

View File

@ -50,8 +50,8 @@ public class LazyNettyClientBlacklistRemoveCommand {
@Schema(description = "更新时间", name = "updateTime", example = "") @Schema(description = "更新时间", name = "updateTime", example = "")
private LocalDateTime updateTime; private LocalDateTime updateTime;
/** /**
* 服务端ID * 命名空间
*/ */
@Schema(description = "服务端ID", name = "serverId", example = "") @Schema(description = "命名空间", name = "namespace", example = "")
private String serverId; private String namespace;
} }

View File

@ -52,10 +52,11 @@ public class LazyNettyClientBlacklistStoryCommand {
* 更新时间 * 更新时间
*/ */
@Schema(description = "更新时间", name = "updateTime", example = "") @Schema(description = "更新时间", name = "updateTime", example = "")
private LocalDateTime updateTime; /** private LocalDateTime updateTime;
* 服务端ID /**
* 命名空间
*/ */
@Schema(description = "服务端ID", name = "serverId", example = "") @Schema(description = "命名空间", name = "namespace", example = "")
private String serverId; private String namespace;
} }

View File

@ -48,10 +48,10 @@ public class LazyNettyClientBlacklistUpdateCommand {
* 更新时间 * 更新时间
*/ */
@Schema(description = "更新时间", name = "updateTime", example = "") @Schema(description = "更新时间", name = "updateTime", example = "")
private LocalDateTime updateTime; /** private LocalDateTime updateTime;
* 服务端ID /**
* 命名空间
*/ */
@Schema(description = "服务端ID", name = "serverId", example = "") @Schema(description = "命名空间", name = "namespace", example = "")
private String serverId; private String namespace;
} }

View File

@ -73,11 +73,10 @@ public class LazyClientPermeateClientMappingQueryListCommand {
private Integer permeateTargetPort; private Integer permeateTargetPort;
/** /**
* * 命名空间
* 服务端ID
*/ */
@Schema(description ="服务端ID",name ="serverId",example = "") @Schema(description = "命名空间", name = "namespace", example = "")
private String serverId; private String namespace;
/** /**
* *

View File

@ -73,11 +73,10 @@ public class LazyClientPermeateClientMappingQueryOneCommand {
private Integer permeateTargetPort; private Integer permeateTargetPort;
/** /**
* * 命名空间
* 服务端ID
*/ */
@Schema(description ="服务端ID",name ="serverId",example = "") @Schema(description = "命名空间", name = "namespace", example = "")
private String serverId; private String namespace;
/** /**
* *

View File

@ -73,11 +73,10 @@ public class LazyClientPermeateClientMappingRemoveCommand {
private Integer permeateTargetPort; private Integer permeateTargetPort;
/** /**
* * 命名空间
* 服务端ID
*/ */
@Schema(description ="服务端ID",name ="serverId",example = "") @Schema(description = "命名空间", name = "namespace", example = "")
private String serverId; private String namespace;
/** /**
* *

View File

@ -73,11 +73,10 @@ public class LazyClientPermeateClientMappingStoryCommand {
private Integer permeateTargetPort; private Integer permeateTargetPort;
/** /**
* * 命名空间
* 服务端ID
*/ */
@Schema(description ="服务端ID",name ="serverId",example = "") @Schema(description = "命名空间", name = "namespace", example = "")
private String serverId; private String namespace;
/** /**
* *

View File

@ -73,11 +73,10 @@ public class LazyClientPermeateClientMappingUpdateCommand {
private Integer permeateTargetPort; private Integer permeateTargetPort;
/** /**
* * 命名空间
* 服务端ID
*/ */
@Schema(description ="服务端ID",name ="serverId",example = "") @Schema(description = "命名空间", name = "namespace", example = "")
private String serverId; private String namespace;
/** /**
* *

View File

@ -73,11 +73,10 @@ public class LazyClientPermeateServerMappingQueryListCommand {
private Integer permeateTargetPort; private Integer permeateTargetPort;
/** /**
* * 命名空间
* 服务端ID
*/ */
@Schema(description ="服务端ID",name ="serverId",example = "") @Schema(description = "命名空间", name = "namespace", example = "")
private String serverId; private String namespace;
/** /**
* *

View File

@ -73,11 +73,10 @@ public class LazyClientPermeateServerMappingQueryOneCommand {
private Integer permeateTargetPort; private Integer permeateTargetPort;
/** /**
* * 命名空间
* 服务端ID
*/ */
@Schema(description ="服务端ID",name ="serverId",example = "") @Schema(description = "命名空间", name = "namespace", example = "")
private String serverId; private String namespace;
/** /**
* *

View File

@ -73,11 +73,10 @@ public class LazyClientPermeateServerMappingRemoveCommand {
private Integer permeateTargetPort; private Integer permeateTargetPort;
/** /**
* * 命名空间
* 服务端ID
*/ */
@Schema(description ="服务端ID",name ="serverId",example = "") @Schema(description = "命名空间", name = "namespace", example = "")
private String serverId; private String namespace;
/** /**
* *

View File

@ -73,11 +73,10 @@ public class LazyClientPermeateServerMappingStoryCommand {
private Integer permeateTargetPort; private Integer permeateTargetPort;
/** /**
* * 命名空间
* 服务端ID
*/ */
@Schema(description ="服务端ID",name ="serverId",example = "") @Schema(description = "命名空间", name = "namespace", example = "")
private String serverId; private String namespace;
/** /**
* *

View File

@ -73,11 +73,10 @@ public class LazyClientPermeateServerMappingUpdateCommand {
private Integer permeateTargetPort; private Integer permeateTargetPort;
/** /**
* * 命名空间
* 服务端ID
*/ */
@Schema(description ="服务端ID",name ="serverId",example = "") @Schema(description = "命名空间", name = "namespace", example = "")
private String serverId; private String namespace;
/** /**
* *

View File

@ -46,10 +46,10 @@ public class LazyNettyClientLoginCommand {
private String stagingState; private String stagingState;
/** /**
* 服务端ID * 命名空间
*/ */
@Schema(description = "服务端ID", name = "serverId", example = "") @Schema(description = "命名空间", name = "namespace", example = "")
private String serverId; private String namespace;
/** /**
* 令牌key * 令牌key

View File

@ -31,9 +31,9 @@ public class LazyNettyClientMessageCommand {
@Schema(description = "发送的消息", name = "message", example = "") @Schema(description = "发送的消息", name = "message", example = "")
private String message; private String message;
/** /**
* 服务端ID * 命名空间
*/ */
@Schema(description = "服务端ID", name = "serverId", example = "") @Schema(description = "命名空间", name = "namespace", example = "")
private String serverId; private String namespace;
} }

View File

@ -66,10 +66,11 @@ public class LazyNettyClientStateQueryListCommand {
* 描述 * 描述
*/ */
@Schema(description = "描述", name = "describe", example = "") @Schema(description = "描述", name = "describe", example = "")
private String describe; /** private String describe;
* 服务端ID /**
* 命名空间
*/ */
@Schema(description = "服务端ID", name = "serverId", example = "") @Schema(description = "命名空间", name = "namespace", example = "")
private String serverId; private String namespace;
} }

View File

@ -67,9 +67,10 @@ public class LazyNettyClientStateQueryOneCommand {
* 描述 * 描述
*/ */
@Schema(description = "描述", name = "describe", example = "") @Schema(description = "描述", name = "describe", example = "")
private String describe; /** private String describe;
* 服务端ID /**
* 命名空间
*/ */
@Schema(description = "服务端ID", name = "serverId", example = "") @Schema(description = "命名空间", name = "namespace", example = "")
private String serverId; private String namespace;
} }

View File

@ -61,10 +61,11 @@ public class LazyNettyClientStateRemoveCommand {
* 修改时间 * 修改时间
*/ */
@Schema(description = "修改时间", name = "updateTime", example = "") @Schema(description = "修改时间", name = "updateTime", example = "")
private LocalDateTime updateTime; /** private LocalDateTime updateTime;
* 服务端ID /**
* 命名空间
*/ */
@Schema(description = "服务端ID", name = "serverId", example = "") @Schema(description = "命名空间", name = "namespace", example = "")
private String serverId; private String namespace;
} }

View File

@ -66,10 +66,10 @@ public class LazyNettyClientStateStoryCommand {
* 描述 * 描述
*/ */
@Schema(description = "描述", name = "describe", example = "") @Schema(description = "描述", name = "describe", example = "")
private String describe; /** private String describe;
* 服务端ID /**
* 命名空间
*/ */
@Schema(description = "服务端ID", name = "serverId", example = "") @Schema(description = "命名空间", name = "namespace", example = "")
private String serverId; private String namespace;
} }

View File

@ -66,9 +66,10 @@ public class LazyNettyClientStateUpdateCommand {
* 描述 * 描述
*/ */
@Schema(description = "描述", name = "describe", example = "") @Schema(description = "描述", name = "describe", example = "")
private String describe; /** private String describe;
* 服务端ID /**
* 命名空间
*/ */
@Schema(description = "服务端ID", name = "serverId", example = "") @Schema(description = "命名空间", name = "namespace", example = "")
private String serverId; private String namespace;
} }

View File

@ -50,11 +50,10 @@ public class LazyNettyClientStateRecordQueryListCommand {
private NettyClientStatus onLineState; private NettyClientStatus onLineState;
/** /**
* * 命名空间
* 服务端ID
*/ */
@Schema(description ="服务端ID",name ="serverId",example = "") @Schema(description = "命名空间", name = "namespace", example = "")
private String serverId; private String namespace;
/** /**
* *

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