mirror of
https://gitee.com/wujiawei1207537021/wu-lazy-cloud-network.git
synced 2025-06-16 03:05:02 +08:00
[fix] 添加namespace
This commit is contained in:
@ -22,8 +22,8 @@ public class LazyNettyServerPropertiesQueryListCommand {
|
||||
/**
|
||||
* 命名空间
|
||||
*/
|
||||
@Schema(description ="命名空间",name ="serverId",example = "")
|
||||
private String serverId;
|
||||
@Schema(description ="命名空间",name ="namespace",example = "")
|
||||
private String namespace;
|
||||
/**
|
||||
*
|
||||
* 客户身份ID
|
||||
|
@ -26,8 +26,8 @@ public class LazyNettyServerPropertiesQueryOneCommand {
|
||||
/**
|
||||
* 命名空间
|
||||
*/
|
||||
@Schema(description ="命名空间",name ="serverId",example = "")
|
||||
private String serverId;
|
||||
@Schema(description ="命名空间",name ="namespace",example = "")
|
||||
private String namespace;
|
||||
/**
|
||||
*
|
||||
* 客户身份ID
|
||||
|
@ -26,8 +26,8 @@ public class LazyNettyServerPropertiesRemoveCommand {
|
||||
/**
|
||||
* 命名空间
|
||||
*/
|
||||
@Schema(description ="命名空间",name ="serverId",example = "")
|
||||
private String serverId;
|
||||
@Schema(description ="命名空间",name ="namespace",example = "")
|
||||
private String namespace;
|
||||
/**
|
||||
*
|
||||
* 客户身份ID
|
||||
|
@ -26,8 +26,8 @@ public class LazyNettyServerPropertiesStoryCommand {
|
||||
/**
|
||||
* 命名空间
|
||||
*/
|
||||
@Schema(description ="命名空间",name ="serverId",example = "")
|
||||
private String serverId;
|
||||
@Schema(description ="命名空间",name ="namespace",example = "")
|
||||
private String namespace;
|
||||
/**
|
||||
*
|
||||
* 客户身份ID
|
||||
|
@ -25,8 +25,8 @@ public class LazyNettyServerPropertiesUpdateCommand {
|
||||
/**
|
||||
* 命名空间
|
||||
*/
|
||||
@Schema(description ="命名空间",name ="serverId",example = "")
|
||||
private String serverId;
|
||||
@Schema(description ="命名空间",name ="namespace",example = "")
|
||||
private String namespace;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -23,8 +23,8 @@ public class LazyNettyServerPropertiesDTO {
|
||||
/**
|
||||
* 命名空间
|
||||
*/
|
||||
@Schema(description = "命名空间", name = "serverId", example = "")
|
||||
private String serverId;
|
||||
@Schema(description = "命名空间", name = "namespace", example = "")
|
||||
private String namespace;
|
||||
/**
|
||||
*
|
||||
* 客户身份ID
|
||||
|
@ -185,7 +185,7 @@ public class LazyNettyServerPropertiesApplicationImpl implements LazyNettyServer
|
||||
public void starterOneClientSocket(LazyNettyServerProperties lazyNettyServerProperties) {
|
||||
boolean enabled = nettyClientProperties.isEnabled();
|
||||
if (enabled) {
|
||||
String serverId = lazyNettyServerProperties.getServerId();
|
||||
String namespace = lazyNettyServerProperties.getNamespace();
|
||||
String inetHost = lazyNettyServerProperties.getInetHost();
|
||||
Integer inetPort = lazyNettyServerProperties.getInetPort();
|
||||
String clientId = lazyNettyServerProperties.getClientId();
|
||||
@ -196,12 +196,12 @@ public class LazyNettyServerPropertiesApplicationImpl implements LazyNettyServer
|
||||
if (ProtocolType.TCP.equals(protocolType)) {
|
||||
nettyClientSocket = new
|
||||
NettyTcpClientSocket(inetHost, inetPort, clientId,
|
||||
serverId, appKey, appSecret,
|
||||
namespace, appKey, appSecret,
|
||||
clientChangeEvent, handleChannelTypeAdvancedList);
|
||||
} else if (ProtocolType.UDP.equals(protocolType)) {
|
||||
nettyClientSocket = new
|
||||
NettyUdpClientSocket(inetHost, inetPort, clientId,
|
||||
serverId, appKey, appSecret,
|
||||
namespace, appKey, appSecret,
|
||||
clientChangeEvent, handleChannelTypeAdvancedList);
|
||||
} else {
|
||||
nettyClientSocket = null;
|
||||
|
@ -18,7 +18,7 @@ public class NettyClientProperties {
|
||||
/**
|
||||
* 命名空间
|
||||
*/
|
||||
private String serverId= NormalUsedString.DEFAULT;
|
||||
private String namespace= NormalUsedString.DEFAULT;
|
||||
/**
|
||||
* 服务端地址 如:127.0.0.1
|
||||
*/
|
||||
|
@ -46,14 +46,14 @@ public class NettyClientSocketApplicationListener implements ApplicationListener
|
||||
String appKey = nettyClientProperties.getAppKey();
|
||||
String appSecret = nettyClientProperties.getAppSecret();
|
||||
ProtocolType protocolType = nettyClientProperties.getProtocolType();
|
||||
String serverId = nettyClientProperties.getServerId();
|
||||
String namespace = nettyClientProperties.getNamespace();
|
||||
if (Objects.isNull(clientId) ||
|
||||
Objects.isNull(inetHost)) {
|
||||
log.warn("配置信息为空,请通过页面添加配置信息:{}", nettyClientProperties);
|
||||
return;
|
||||
}
|
||||
LazyNettyServerPropertiesDO lazyNettyServerPropertiesDO = new LazyNettyServerPropertiesDO();
|
||||
lazyNettyServerPropertiesDO.setServerId(serverId);
|
||||
lazyNettyServerPropertiesDO.setNamespace(namespace);
|
||||
lazyNettyServerPropertiesDO.setClientId(clientId);
|
||||
lazyNettyServerPropertiesDO.setInetHost(inetHost);
|
||||
lazyNettyServerPropertiesDO.setInetPort(inetPort);
|
||||
@ -66,7 +66,7 @@ public class NettyClientSocketApplicationListener implements ApplicationListener
|
||||
|
||||
// 根据服务端端口、port 唯一性验证
|
||||
boolean exists = lazyLambdaStream.exists(LazyWrappers.<LazyNettyServerPropertiesDO>lambdaWrapper()
|
||||
.eq(LazyNettyServerPropertiesDO::getServerId, serverId)
|
||||
.eq(LazyNettyServerPropertiesDO::getNamespace, namespace)
|
||||
.eq(LazyNettyServerPropertiesDO::getInetHost, inetHost)
|
||||
.eq(LazyNettyServerPropertiesDO::getInetPort, inetPort)
|
||||
.eq(LazyNettyServerPropertiesDO::getClientId, clientId)
|
||||
|
@ -26,7 +26,7 @@ public class LazyNettyServerProperties {
|
||||
* 命名空间
|
||||
*/
|
||||
@Schema(description ="命名空间",name ="namespace",example = "")
|
||||
private String serverId;
|
||||
private String namespace;
|
||||
/**
|
||||
*
|
||||
* 客户身份ID
|
||||
|
@ -29,9 +29,9 @@ public class LazyNettyServerPropertiesDO {
|
||||
/**
|
||||
* 命名空间
|
||||
*/
|
||||
@Schema(description ="命名空间",name ="serverId",example = "")
|
||||
@LazyTableFieldUnique(name="server_id",comment="命名空间",columnType="varchar(25)",defaultValue = "DEFAULT")
|
||||
private String serverId;
|
||||
@Schema(description ="命名空间",name ="namespace",example = "")
|
||||
@LazyTableFieldUnique(name="namespace",comment="命名空间",columnType="varchar(25)",defaultValue = "DEFAULT")
|
||||
private String namespace;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -40,7 +40,7 @@ public class LazyNettyServerPropertiesRepositoryImpl implements LazyNettyServerP
|
||||
@Override
|
||||
public Result<LazyNettyServerProperties> story(LazyNettyServerProperties lazyNettyServerProperties) {
|
||||
LazyNettyServerPropertiesDO lazyNettyServerPropertiesDO = LazyNettyServerPropertiesConverter.INSTANCE.fromLazyNettyServerProperties(lazyNettyServerProperties);
|
||||
String serverId = lazyNettyServerPropertiesDO.getServerId();
|
||||
String namespace = lazyNettyServerPropertiesDO.getNamespace();
|
||||
String inetHost = lazyNettyServerPropertiesDO.getInetHost();
|
||||
Integer inetPort = lazyNettyServerPropertiesDO.getInetPort();
|
||||
String clientId = lazyNettyServerPropertiesDO.getClientId();
|
||||
@ -48,7 +48,7 @@ public class LazyNettyServerPropertiesRepositoryImpl implements LazyNettyServerP
|
||||
|
||||
// 查询 ip、端口、客户端
|
||||
boolean exists = lazyLambdaStream.exists(LazyWrappers.<LazyNettyServerPropertiesDO>lambdaWrapper()
|
||||
.eq(LazyNettyServerPropertiesDO::getServerId, serverId)
|
||||
.eq(LazyNettyServerPropertiesDO::getNamespace, namespace)
|
||||
.eq(LazyNettyServerPropertiesDO::getInetHost, inetHost)
|
||||
.eq(LazyNettyServerPropertiesDO::getInetPort, inetPort)
|
||||
.eq(LazyNettyServerPropertiesDO::getClientId, clientId)
|
||||
@ -56,7 +56,7 @@ public class LazyNettyServerPropertiesRepositoryImpl implements LazyNettyServerP
|
||||
if (exists) {
|
||||
// 更新
|
||||
lazyLambdaStream.update(lazyNettyServerPropertiesDO, LazyWrappers.<LazyNettyServerPropertiesDO>lambdaWrapper()
|
||||
.eq(LazyNettyServerPropertiesDO::getServerId, serverId)
|
||||
.eq(LazyNettyServerPropertiesDO::getNamespace, namespace)
|
||||
.eq(LazyNettyServerPropertiesDO::getInetHost, inetHost)
|
||||
.eq(LazyNettyServerPropertiesDO::getInetPort, inetPort)
|
||||
.eq(LazyNettyServerPropertiesDO::getClientId, clientId)
|
||||
|
@ -13,6 +13,10 @@ import java.util.List;
|
||||
@Data
|
||||
public class NettyClientPermeateClientVisitor implements InternalNetworkPermeate {
|
||||
|
||||
/**
|
||||
* namespace
|
||||
*/
|
||||
private String namespace;
|
||||
/**
|
||||
* 当前客户端ID
|
||||
*/
|
||||
|
@ -31,9 +31,11 @@ public class ClientHandleTcpClientChannelActiveAdvanced extends AbstractHandleTc
|
||||
protected void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg nettyProxyMsg) {
|
||||
Channel channel = nettyChannelContext.channel();
|
||||
// 缓存当前通道
|
||||
byte[] clientIdByte = nettyProxyMsg.getClientId();
|
||||
String clientId = new String(clientIdByte);
|
||||
ChannelContext.push(channel, clientId);
|
||||
String clientId = nettyProxyMsg.clientId();
|
||||
String serverId = nettyProxyMsg.namespace();
|
||||
|
||||
|
||||
ChannelContext.push(channel, serverId, clientId);
|
||||
ChannelAttributeKeyUtils.buildClientId(channel, clientId);
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,8 @@ import java.util.List;
|
||||
*/
|
||||
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
|
||||
@Slf4j
|
||||
public class ClientHandleTcpDistributeClientPermeateClientInitTypeAdvanced extends AbstractHandleTcpDistributeClientPermeateClientInitTypeAdvanced<NettyProxyMsg> {
|
||||
public class ClientHandleTcpDistributeClientPermeateClientInitTypeAdvanced
|
||||
extends AbstractHandleTcpDistributeClientPermeateClientInitTypeAdvanced<NettyProxyMsg> {
|
||||
|
||||
/**
|
||||
* 处理当前数据
|
||||
@ -35,6 +36,7 @@ public class ClientHandleTcpDistributeClientPermeateClientInitTypeAdvanced exten
|
||||
@Override
|
||||
public void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg nettyProxyMsg) {
|
||||
// 初始化 客户端渗透服务端socket
|
||||
String namespace = nettyProxyMsg.namespace();
|
||||
byte[] fromClientIdBytes = nettyProxyMsg.getClientId();
|
||||
byte[] visitorPortBytes = nettyProxyMsg.getVisitorPort();
|
||||
byte[] clientTargetIpBytes = nettyProxyMsg.getClientTargetIp();
|
||||
@ -54,6 +56,7 @@ public class ClientHandleTcpDistributeClientPermeateClientInitTypeAdvanced exten
|
||||
fromClientId, toClientId, visitorPort, clientTargetIp, clientTargetPort);
|
||||
NettyTcpClientPermeateClientVisitorSocket nettyTcpClientPermeateClientVisitorSocket =
|
||||
NettyTcpClientPermeateClientVisitorSocket.NettyClientPermeateClientVisitorSocketBuilder.builder()
|
||||
.builderNamespace(namespace)
|
||||
.builderClientId(fromClientId)
|
||||
.builderClientTargetIp(clientTargetIp)
|
||||
.builderClientTargetPort(clientTargetPort)
|
||||
|
@ -8,9 +8,9 @@ import io.netty.handler.timeout.IdleState;
|
||||
import io.netty.handler.timeout.IdleStateEvent;
|
||||
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.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.advanced.payload.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.constant.TcpMessageType;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Date;
|
||||
@ -59,11 +59,13 @@ public class NettyTcpClientHandler extends SimpleChannelInboundHandler<NettyProx
|
||||
log.info("When establishing a connection:{}" , new Date());
|
||||
ctx.fireChannelActive();
|
||||
String clientId = nettyTcpClientSocket.getClientId();
|
||||
String namespace = nettyTcpClientSocket.getNamespace();
|
||||
// 处理客户端连接成功
|
||||
Channel channel = ctx.channel();
|
||||
NettyProxyMsg nettyMsg = new NettyProxyMsg();
|
||||
nettyMsg.setType(TcpMessageType.TCP_CLIENT_CHANNEL_ACTIVE);
|
||||
nettyMsg.setClientId(clientId);
|
||||
nettyMsg.setNamespace(namespace);
|
||||
channelTypeAdapter.handler(ctx, nettyMsg);
|
||||
|
||||
|
||||
@ -76,7 +78,7 @@ public class NettyTcpClientHandler extends SimpleChannelInboundHandler<NettyProx
|
||||
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
|
||||
//服务端主动关闭当前客户端连接时
|
||||
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(() -> {
|
||||
try {
|
||||
nettyTcpClientSocket.newConnect2Server();
|
||||
|
@ -114,6 +114,10 @@ public class NettyTcpClientPermeateClientVisitorSocket implements PermeateVisito
|
||||
|
||||
public static final class NettyClientPermeateClientVisitorSocketBuilder {
|
||||
|
||||
/**
|
||||
* namespace
|
||||
*/
|
||||
private String namespace;
|
||||
/**
|
||||
* 客户端ID
|
||||
*/
|
||||
@ -161,6 +165,16 @@ public class NettyTcpClientPermeateClientVisitorSocket implements PermeateVisito
|
||||
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;
|
||||
}
|
||||
public NettyTcpClientPermeateClientVisitorSocket build() {
|
||||
if (namespace == null) {
|
||||
throw new IllegalArgumentException("namespace must not null");
|
||||
}
|
||||
if (clientTargetIp == null) {
|
||||
throw new IllegalArgumentException("clientTargetIp must not null");
|
||||
}
|
||||
@ -268,6 +285,7 @@ public class NettyTcpClientPermeateClientVisitorSocket implements PermeateVisito
|
||||
}
|
||||
NettyClientPermeateClientVisitor nettyClientPermeateClientVisitor = new NettyClientPermeateClientVisitor();
|
||||
|
||||
nettyClientPermeateClientVisitor.setNamespace(namespace);
|
||||
nettyClientPermeateClientVisitor.setFromClientId(nettyClientProperties.getClientId());
|
||||
nettyClientPermeateClientVisitor.setToClientId(toClientId);
|
||||
nettyClientPermeateClientVisitor.setTargetIp(clientTargetIp);
|
||||
|
@ -46,6 +46,7 @@ public class NettyTcpClientPermeateClientVisitorTransferSocket {
|
||||
.handler(new NettyTcpClientPermeateClientTransferFilter(new ChannelTypeAdapter(nettyClientPermeateClientVisitor.getHandleChannelTypeAdvancedList())))
|
||||
;
|
||||
NettyClientProperties nettyClientProperties = nettyClientPermeateClientVisitor.getNettyClientProperties();
|
||||
String namespace = nettyClientProperties.getNamespace();
|
||||
String inetHost = nettyClientProperties.getInetHost();
|
||||
int inetPort = nettyClientProperties.getInetPort();
|
||||
// local client id
|
||||
@ -70,6 +71,7 @@ public class NettyTcpClientPermeateClientVisitorTransferSocket {
|
||||
|
||||
NettyProxyMsg nettyProxyMsg = new NettyProxyMsg();
|
||||
nettyProxyMsg.setType(TcpMessageType.TCP_REPORT_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL);
|
||||
nettyProxyMsg.setNamespace(namespace);
|
||||
// other clientId
|
||||
nettyProxyMsg.setClientId(toClientId);
|
||||
nettyProxyMsg.setVisitorPort(visitorPort);
|
||||
|
@ -44,7 +44,8 @@ public class NettyTcpClientSocket implements NettyClientSocket {
|
||||
/**
|
||||
* 当前连接的服务端ID
|
||||
*/
|
||||
private final String serverId;
|
||||
@Getter
|
||||
private final String namespace;
|
||||
private final String appKey;
|
||||
private final String appSecret;
|
||||
/**
|
||||
@ -57,7 +58,7 @@ public class NettyTcpClientSocket implements NettyClientSocket {
|
||||
public NettyTcpClientSocket(String inetHost,
|
||||
int inetPort,
|
||||
String clientId,
|
||||
String serverId,
|
||||
String namespace,
|
||||
String appKey,
|
||||
String appSecret,
|
||||
ClientChangeEvent clientChangeEvent,
|
||||
@ -65,7 +66,7 @@ public class NettyTcpClientSocket implements NettyClientSocket {
|
||||
this.inetHost = inetHost;
|
||||
this.inetPort = inetPort;
|
||||
this.clientId = clientId;
|
||||
this.serverId = serverId;
|
||||
this.namespace = namespace;
|
||||
this.appKey = appKey;
|
||||
this.appSecret = appSecret;
|
||||
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))
|
||||
.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);
|
||||
// 客户端连接服务端的channel
|
||||
Channel serviceChannel = future.channel();
|
||||
@ -96,11 +97,12 @@ public class NettyTcpClientSocket implements NettyClientSocket {
|
||||
future.addListener((ChannelFutureListener) futureListener -> {
|
||||
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的连接
|
||||
NettyProxyMsg nettyMsg = new NettyProxyMsg();
|
||||
nettyMsg.setType(TcpMessageType.TCP_REPORT_CLIENT_CONNECT_SUCCESS);
|
||||
nettyMsg.setClientId(clientId);
|
||||
nettyMsg.setNamespace(serverId);
|
||||
String hostAddress = InetAddress.getLocalHost().getHostAddress();
|
||||
nettyMsg.setOriginalIpString(hostAddress);
|
||||
nettyMsg.setData((clientId).getBytes());
|
||||
@ -145,6 +147,6 @@ public class NettyTcpClientSocket implements NettyClientSocket {
|
||||
*/
|
||||
@Override
|
||||
public void newConnect2Server() throws InterruptedException {
|
||||
newTcpConnect2Server(inetHost, inetPort, clientId, serverId, clientChangeEvent);
|
||||
newTcpConnect2Server(inetHost, inetPort, clientId, namespace, clientChangeEvent);
|
||||
}
|
||||
}
|
@ -32,8 +32,10 @@ public class ClientHandleUdpClientChannelActiveAdvanced extends AbstractHandleUd
|
||||
Channel channel = nettyChannelContext.channel();
|
||||
// 缓存当前通道
|
||||
byte[] clientIdByte = nettyProxyMsg.getClientId();
|
||||
byte[] serverIdByte = nettyProxyMsg.getNamespace();
|
||||
String clientId = new String(clientIdByte);
|
||||
ChannelContext.push(channel, clientId);
|
||||
String serverId = new String(clientIdByte);
|
||||
ChannelContext.push(channel,serverId, clientId);
|
||||
ChannelAttributeKeyUtils.buildClientId(channel, clientId);
|
||||
}
|
||||
}
|
||||
|
@ -59,11 +59,13 @@ public class NettyUdpClientHandler extends SimpleChannelInboundHandler<NettyProx
|
||||
log.info("When establishing a connection:{}" , new Date());
|
||||
ctx.fireChannelActive();
|
||||
String clientId = nettyUdpClientSocket.getClientId();
|
||||
String serverId = nettyUdpClientSocket.getNamespace();
|
||||
// 处理客户端连接成功
|
||||
Channel channel = ctx.channel();
|
||||
NettyProxyMsg nettyMsg = new NettyProxyMsg();
|
||||
nettyMsg.setType(UdpMessageType.UDP_CLIENT_CHANNEL_ACTIVE);
|
||||
nettyMsg.setClientId(clientId);
|
||||
nettyMsg.setNamespace(serverId);
|
||||
channelTypeAdapter.handler(ctx, nettyMsg);
|
||||
|
||||
|
||||
|
@ -46,6 +46,7 @@ public class NettyUdpClientPermeateClientVisitorTransferSocket {
|
||||
.handler(new NettyUdpClientPermeateClientTransferFilter(new ChannelTypeAdapter(nettyClientPermeateClientVisitor.getHandleChannelTypeAdvancedList())))
|
||||
;
|
||||
NettyClientProperties nettyClientProperties = nettyClientPermeateClientVisitor.getNettyClientProperties();
|
||||
String namespace = nettyClientProperties.getNamespace();
|
||||
String inetHost = nettyClientProperties.getInetHost();
|
||||
int inetPort = nettyClientProperties.getInetPort();
|
||||
// local client id
|
||||
@ -71,6 +72,7 @@ public class NettyUdpClientPermeateClientVisitorTransferSocket {
|
||||
NettyProxyMsg nettyProxyMsg = new NettyProxyMsg();
|
||||
nettyProxyMsg.setType(UdpMessageType.UDP_REPORT_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL);
|
||||
// other clientId
|
||||
nettyProxyMsg.setNamespace(namespace);
|
||||
nettyProxyMsg.setClientId(toClientId);
|
||||
nettyProxyMsg.setVisitorPort(visitorPort);
|
||||
nettyProxyMsg.setClientTargetIp(targetIp);
|
||||
|
@ -44,7 +44,8 @@ public class NettyUdpClientSocket implements NettyClientSocket {
|
||||
/**
|
||||
* 当前连接的服务端ID
|
||||
*/
|
||||
private final String serverId;
|
||||
@Getter
|
||||
private final String namespace;
|
||||
private final String appKey;
|
||||
private final String appSecret;
|
||||
/**
|
||||
@ -57,7 +58,7 @@ public class NettyUdpClientSocket implements NettyClientSocket {
|
||||
public NettyUdpClientSocket(String inetHost,
|
||||
int inetPort,
|
||||
String clientId,
|
||||
String serverId,
|
||||
String namespace,
|
||||
String appKey,
|
||||
String appSecret,
|
||||
ClientChangeEvent clientChangeEvent,
|
||||
@ -65,7 +66,7 @@ public class NettyUdpClientSocket implements NettyClientSocket {
|
||||
this.inetHost = inetHost;
|
||||
this.inetPort = inetPort;
|
||||
this.clientId = clientId;
|
||||
this.serverId = serverId;
|
||||
this.namespace = namespace;
|
||||
this.appKey = appKey;
|
||||
this.appSecret = appSecret;
|
||||
this.clientChangeEvent = clientChangeEvent;
|
||||
@ -73,10 +74,10 @@ public class NettyUdpClientSocket implements NettyClientSocket {
|
||||
}
|
||||
|
||||
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.group(eventLoopGroup)
|
||||
.channel(NioDatagramChannel.class)
|
||||
@ -104,6 +105,7 @@ public class NettyUdpClientSocket implements NettyClientSocket {
|
||||
// 告诉服务端这条连接是client的连接
|
||||
NettyProxyMsg nettyMsg = new NettyProxyMsg();
|
||||
nettyMsg.setType(UdpMessageType.UDP_REPORT_CLIENT_CONNECT_SUCCESS);
|
||||
nettyMsg.setNamespace(namespace);
|
||||
nettyMsg.setClientId(clientId);
|
||||
String hostAddress = InetAddress.getLocalHost().getHostAddress();
|
||||
nettyMsg.setOriginalIpString(hostAddress);
|
||||
@ -113,17 +115,17 @@ public class NettyUdpClientSocket implements NettyClientSocket {
|
||||
ChannelAttributeKeyUtils.buildClientId(serviceChannel, clientId);
|
||||
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 {
|
||||
log.warn("Reconnect every 2 seconds....");
|
||||
// 离线
|
||||
NettyServerContext.removeServerEndpointChannels(serverId, clientId);
|
||||
clientChangeEvent.clientOffLine(inetHost, inetPort,serverId, clientId);
|
||||
NettyServerContext.removeServerEndpointChannels(namespace, clientId);
|
||||
clientChangeEvent.clientOffLine(inetHost, inetPort, namespace, clientId);
|
||||
eventLoopGroup.schedule(() -> {
|
||||
try {
|
||||
newConnect2Server(inetHost, inetPort, clientId, serverId, clientChangeEvent);
|
||||
newConnect2Server(inetHost, inetPort, clientId, namespace, clientChangeEvent);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -34,8 +34,8 @@ public class ClientHandleHttpClientProxyClientTypeAdvanced extends
|
||||
@Override
|
||||
protected void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg nettyProxyMsg) {
|
||||
Channel channel = nettyChannelContext.channel();
|
||||
String targetPortString = nettyProxyMsg.getTargetPortString();
|
||||
String targetIpString = nettyProxyMsg.getTargetIpString();
|
||||
String targetPortString = nettyProxyMsg.targetPort();
|
||||
String targetIpString = nettyProxyMsg.targetIp();
|
||||
byte[] data = nettyProxyMsg.getData();
|
||||
byte[] clientId = nettyProxyMsg.getClientId();
|
||||
List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList = new ArrayList<>(SpringContextHolder.getApplicationContext().getBeansOfType(HandleChannelTypeAdvanced.class).values());
|
||||
|
@ -34,8 +34,8 @@ public class ClientHandleHttpClientProxyServerTypeAdvanced extends
|
||||
protected void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg nettyProxyMsg) {
|
||||
|
||||
Channel channel = nettyChannelContext.channel();
|
||||
String targetPortString = nettyProxyMsg.getTargetPortString();
|
||||
String targetIpString = nettyProxyMsg.getTargetIpString();
|
||||
String targetPortString = nettyProxyMsg.targetPort();
|
||||
String targetIpString = nettyProxyMsg.targetIp();
|
||||
byte[] data = nettyProxyMsg.getData();
|
||||
List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList = new ArrayList<>(SpringContextHolder.getApplicationContext().getBeansOfType(HandleChannelTypeAdvanced.class).values());
|
||||
NettyClientProperties nettyClientProperties = SpringContextHolder.getBean(NettyClientProperties.class);
|
||||
|
@ -3,7 +3,6 @@ package org.framework.lazy.cloud.network.heartbeat.client.netty.proxy.http.socke
|
||||
|
||||
import io.netty.bootstrap.Bootstrap;
|
||||
import io.netty.channel.*;
|
||||
import io.netty.channel.nio.NioEventLoopGroup;
|
||||
import io.netty.channel.socket.nio.NioSocketChannel;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
|
||||
@ -50,6 +49,7 @@ public class NettyHttpClientProxyClientProxySocket {
|
||||
int inetPort = nettyClientProperties.getInetPort();
|
||||
// local client id
|
||||
|
||||
String namespace = nettyClientProperties.getNamespace();
|
||||
String clientId = nettyClientProperties.getClientId();
|
||||
|
||||
String targetIp = nettyHttpClientProxyClient.getTargetIp();
|
||||
@ -71,6 +71,7 @@ public class NettyHttpClientProxyClientProxySocket {
|
||||
|
||||
NettyProxyMsg nettyProxyMsg = new NettyProxyMsg();
|
||||
nettyProxyMsg.setType(ProxyMessageType.HTTP_REPORT_CLIENT_PROXY_CLIENT_TRANSFER_CONNECTION_);
|
||||
nettyProxyMsg.setNamespace(namespace);
|
||||
// other clientId
|
||||
nettyProxyMsg.setClientId(targetClientId);
|
||||
nettyProxyMsg.setClientTargetIp(targetIp);
|
||||
|
@ -32,10 +32,10 @@ public class ClientHandleDistributeSocksClientProxyClientOtherConnectionTransfer
|
||||
@Override
|
||||
protected void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg nettyProxyMsg) {
|
||||
Channel channel = nettyChannelContext.channel();
|
||||
String clientId = nettyProxyMsg.getClientIdString();
|
||||
String clientId = nettyProxyMsg.clientId();
|
||||
byte[] visitorId = nettyProxyMsg.getVisitorId();
|
||||
String targetIp = nettyProxyMsg.getTargetIpString();
|
||||
Integer targetPort = Integer.parseInt(nettyProxyMsg.getTargetPortString());
|
||||
String targetIp = nettyProxyMsg.targetIp();
|
||||
Integer targetPort = Integer.parseInt(nettyProxyMsg.targetPort());
|
||||
|
||||
List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList = new ArrayList<>(SpringContextHolder.getApplicationContext().getBeansOfType(HandleChannelTypeAdvanced.class).values());
|
||||
NettyClientProperties nettyClientProperties = SpringContextHolder.getBean(NettyClientProperties.class);
|
||||
|
@ -37,8 +37,8 @@ public class ClientHandleNettySocketProtocolHandleSocketClientProxyClientStartTy
|
||||
|
||||
NettySocketChannelContext nettySocketChannelContext = (NettySocketChannelContext) nettyChannelContext;
|
||||
Channel proxyChannel = nettySocketChannelContext.channel();
|
||||
String host = nettyProxyMsg.getTargetIpString();
|
||||
Integer port = Integer.parseInt(nettyProxyMsg.getTargetPortString());
|
||||
String host = nettyProxyMsg.targetIp();
|
||||
Integer port = Integer.parseInt(nettyProxyMsg.targetPort());
|
||||
byte[] clientId = nettyProxyMsg.getClientId();
|
||||
byte[] visitorId = nettyProxyMsg.getVisitorId();
|
||||
|
||||
|
@ -40,8 +40,8 @@ public class ClientHandleNettySocketProtocolHandleSocketClientProxyServerStartTy
|
||||
|
||||
NettySocketChannelContext nettySocketChannelContext = (NettySocketChannelContext) nettyChannelContext;
|
||||
Channel proxyChannel = nettySocketChannelContext.channel();
|
||||
String host = nettyProxyMsg.getTargetIpString();
|
||||
Integer port = Integer.parseInt(nettyProxyMsg.getTargetPortString());
|
||||
String host = nettyProxyMsg.targetIp();
|
||||
Integer port = Integer.parseInt(nettyProxyMsg.targetPort());
|
||||
Socks5AddressType socks5AddressType = nettySocketChannelContext.getSocks5AddressType();
|
||||
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.proxy.socks.advanced;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.handler.codec.socksx.v5.Socks5AddressType;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.proxy.socks.NettySocksClientProxyClient;
|
||||
@ -37,10 +36,10 @@ public class ClientHandleSocksDistributeServerProxyClientConnectionInitTypeAdvan
|
||||
// 绑定真实通道
|
||||
|
||||
Channel channel = nettyChannelContext.channel();
|
||||
String clientId = nettyProxyMsg.getClientIdString();
|
||||
String clientId = nettyProxyMsg.clientId();
|
||||
byte[] visitorId = nettyProxyMsg.getVisitorId();
|
||||
String targetIp = nettyProxyMsg.getTargetIpString();
|
||||
Integer targetPort = Integer.parseInt(nettyProxyMsg.getTargetPortString());
|
||||
String targetIp = nettyProxyMsg.targetIp();
|
||||
Integer targetPort = Integer.parseInt(nettyProxyMsg.targetPort());
|
||||
|
||||
|
||||
List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList = new ArrayList<>(SpringContextHolder.getApplicationContext().getBeansOfType(HandleChannelTypeAdvanced.class).values());
|
||||
|
@ -41,6 +41,7 @@ public class NettySocksClientProxyClientVisitorTransferSocket {
|
||||
.handler(new NettySocksClientProxyClientVisitorTransferFilter(new ChannelTypeAdapter(nettySocksClientProxyClient.getHandleChannelTypeAdvancedList())))
|
||||
;
|
||||
NettyClientProperties nettyClientProperties = nettySocksClientProxyClient.getNettyClientProperties();
|
||||
String namespace = nettyClientProperties.getNamespace();
|
||||
String inetHost = nettyClientProperties.getInetHost();
|
||||
int inetPort = nettyClientProperties.getInetPort();
|
||||
// local client id
|
||||
@ -69,6 +70,7 @@ public class NettySocksClientProxyClientVisitorTransferSocket {
|
||||
|
||||
NettyProxyMsg nettyProxyMsg = new NettyProxyMsg();
|
||||
nettyProxyMsg.setType(ProxyMessageType.SOCKS_REPORT_CLIENT_PROXY_CLIENT_TRANSFER_CONNECTION_);
|
||||
nettyProxyMsg.setNamespace(namespace);
|
||||
// other clientId
|
||||
nettyProxyMsg.setClientTargetIp(targetIp);
|
||||
nettyProxyMsg.setClientTargetPort(targetPort);
|
||||
|
@ -52,6 +52,7 @@
|
||||
// // 上报 当前通道暂存关闭了
|
||||
// Channel channel = clientChannel.getChannel();
|
||||
// NettyProxyMsg nettyMsg = new NettyProxyMsg();
|
||||
// nettyMsg.setNamespace();
|
||||
// nettyMsg.setType(MessageType.TCP_REPORT_CLIENT_STAGING_CLOSED);
|
||||
// nettyMsg.setData((clientId
|
||||
// .getBytes(StandardCharsets.UTF_8)));
|
||||
|
File diff suppressed because one or more lines are too long
@ -5,7 +5,7 @@
|
||||
<link rel="icon" href="./favicon.ico">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<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">
|
||||
</head>
|
||||
<body>
|
||||
|
@ -1,6 +1,7 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.common;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
|
||||
import org.wu.framework.core.utils.ObjectUtils;
|
||||
@ -19,8 +20,9 @@ import java.util.stream.Collectors;
|
||||
@Slf4j
|
||||
public class ChannelContext {
|
||||
|
||||
private final static ConcurrentHashMap<String/*clientId*/, List<Channel>/*通道*/>
|
||||
channelIdClientChannelDTOConcurrentHashMap = new ConcurrentHashMap<>();
|
||||
private final static ConcurrentHashMap<String/*namespace*/,
|
||||
ConcurrentHashMap<String/*clientId*/, List<Channel>/*通道*/>>
|
||||
cacheClientChannelConcurrentHashMap = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* 新增通道
|
||||
@ -28,26 +30,37 @@ public class ChannelContext {
|
||||
* @param channel 通道
|
||||
* @param clientId 客户端ID
|
||||
*/
|
||||
public static void push(Channel channel, String clientId) {
|
||||
// 如果客户端已经存在 移除
|
||||
if (channelIdClientChannelDTOConcurrentHashMap.containsKey(clientId)) {
|
||||
// clear(clientId);
|
||||
List<Channel> existChannelList = new ArrayList<>();
|
||||
List<Channel> oldChannels = channelIdClientChannelDTOConcurrentHashMap.get(clientId);
|
||||
for (Channel existChannel : oldChannels) {
|
||||
if (existChannel != null) {
|
||||
if(existChannel.isActive()){
|
||||
existChannelList.add(existChannel);
|
||||
}else {
|
||||
log.warn("close channel with client:{}", ChannelAttributeKeyUtils.getClientId(existChannel));
|
||||
existChannel.close();
|
||||
public static void push(Channel channel, String namespace, String clientId) {
|
||||
// 如果服务端已经存在 移除
|
||||
if (cacheClientChannelConcurrentHashMap.containsKey(namespace)) {
|
||||
|
||||
ConcurrentHashMap<String/*clientId*/, List<Channel>/*通道*/> clientChannelListConcurrentHashMap =
|
||||
cacheClientChannelConcurrentHashMap.get(namespace);
|
||||
|
||||
|
||||
// 判断是否存在客户端
|
||||
if (clientChannelListConcurrentHashMap.containsKey(clientId)) {
|
||||
List<Channel> existChannelList = new ArrayList<>();
|
||||
List<Channel> oldChannels = clientChannelListConcurrentHashMap.get(clientId);
|
||||
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 {
|
||||
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 clientId 客户端ID
|
||||
*/
|
||||
public static void push(Channel channel, byte[] clientId) {
|
||||
push(channel,new String(clientId, StandardCharsets.UTF_8));
|
||||
public static void push(Channel channel, byte[] namespace, byte[] clientId) {
|
||||
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 返回所有通道信息
|
||||
*/
|
||||
public static ConcurrentMap<String/*clientId*/, List<Channel>/*通道*/> getChannels() {
|
||||
return channelIdClientChannelDTOConcurrentHashMap;
|
||||
public static ConcurrentMap<ServerClient/*clientId*/, List<Channel>/*通道*/> getChannels() {
|
||||
|
||||
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 返回所有通道信息
|
||||
*/
|
||||
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
|
||||
* @return 通道信息
|
||||
*/
|
||||
public static List<Channel> get(byte[] clientId) {
|
||||
if (channelIdClientChannelDTOConcurrentHashMap
|
||||
.containsKey(new String(clientId))) {
|
||||
return channelIdClientChannelDTOConcurrentHashMap
|
||||
.get(new String(clientId));
|
||||
} else {
|
||||
public static List<Channel> get(byte[] namespace, byte[] clientId) {
|
||||
try {
|
||||
return cacheClientChannelConcurrentHashMap.get(new String(namespace, StandardCharsets.UTF_8)).get(new String(clientId, StandardCharsets.UTF_8));
|
||||
} catch (Exception e) {
|
||||
// 无法通过客户端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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -104,8 +137,8 @@ public class ChannelContext {
|
||||
* @param clientId 客户端ID
|
||||
* @return 通道信息
|
||||
*/
|
||||
public static List<Channel> get(String clientId) {
|
||||
return get(clientId.getBytes(StandardCharsets.UTF_8));
|
||||
public static List<Channel> get(String namespace, String clientId) {
|
||||
return get(namespace.getBytes(StandardCharsets.UTF_8), clientId.getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
/**
|
||||
* 根据通道ID获取通道信息
|
||||
@ -113,8 +146,8 @@ public class ChannelContext {
|
||||
* @param clientId 客户端ID
|
||||
* @return 通道信息
|
||||
*/
|
||||
public static Channel getLoadBalance(byte[] clientId) {
|
||||
List<Channel> channels = get(clientId);
|
||||
public static Channel getLoadBalance(byte[] namespace, byte[] clientId) {
|
||||
List<Channel> channels = get(namespace, clientId);
|
||||
if(ObjectUtils.isEmpty(channels)){
|
||||
return null;
|
||||
}
|
||||
@ -132,8 +165,8 @@ public class ChannelContext {
|
||||
* @param clientId 客户端ID
|
||||
* @return 通道信息
|
||||
*/
|
||||
public static Channel getLoadBalance(String clientId) {
|
||||
return getLoadBalance(clientId.getBytes(StandardCharsets.UTF_8));
|
||||
public static Channel getLoadBalance(String namespace, String clientId) {
|
||||
return getLoadBalance(namespace.getBytes(StandardCharsets.UTF_8), clientId.getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -141,10 +174,10 @@ public class ChannelContext {
|
||||
*
|
||||
* @param clientId 客户端ID
|
||||
*/
|
||||
public static void clear(String clientId) {
|
||||
List<Channel> channels = get(clientId);
|
||||
public static void clear(String namespace, String clientId) {
|
||||
List<Channel> channels = get(namespace, clientId);
|
||||
if (channels != null) {
|
||||
remove(clientId);
|
||||
remove(namespace, clientId);
|
||||
for (Channel channel : channels) {
|
||||
if (channel != null && channel.isActive()) {
|
||||
channel.close();
|
||||
@ -153,7 +186,7 @@ public class ChannelContext {
|
||||
} else {
|
||||
// log warm
|
||||
// 无法通过客户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
|
||||
*/
|
||||
public static void remove(byte[] clientId) {
|
||||
List<Channel> clientChannel = get(clientId);
|
||||
public static void remove(byte[] namespace, byte[] clientId) {
|
||||
List<Channel> clientChannel = get(namespace, clientId);
|
||||
if (clientChannel != null) {
|
||||
channelIdClientChannelDTOConcurrentHashMap.remove(new String(clientId));
|
||||
cacheClientChannelConcurrentHashMap.get(new String(namespace, StandardCharsets.UTF_8)).remove(new String(clientId, StandardCharsets.UTF_8));
|
||||
} else {
|
||||
// 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
|
||||
*/
|
||||
public static void remove(String clientId) {
|
||||
List<Channel> clientChannel = get(clientId);
|
||||
public static void remove(String namespace, String clientId) {
|
||||
List<Channel> clientChannel = get(namespace, clientId);
|
||||
if (clientChannel != null) {
|
||||
channelIdClientChannelDTOConcurrentHashMap.remove(clientId);
|
||||
cacheClientChannelConcurrentHashMap.get(namespace).remove(clientId);
|
||||
} else {
|
||||
// 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,10 @@ import lombok.experimental.Accessors;
|
||||
public class InternalNetworkPenetrationRealClient {
|
||||
|
||||
|
||||
/**
|
||||
* 命名空间
|
||||
*/
|
||||
private String namespace;
|
||||
/**
|
||||
* 客户端ID
|
||||
*/
|
||||
|
@ -20,8 +20,8 @@ public class NettyClientChannel {
|
||||
*/
|
||||
private Channel channel;
|
||||
/**
|
||||
* 服务端ID
|
||||
* namespace
|
||||
*/
|
||||
private String serverId;
|
||||
private String namespace;
|
||||
|
||||
}
|
@ -15,21 +15,24 @@ import java.util.stream.Collectors;
|
||||
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<>();
|
||||
|
||||
|
||||
/**
|
||||
* 添加访客
|
||||
*
|
||||
* @param serverId 服务端ID
|
||||
* @param namespace namespace
|
||||
* @param clientId 客户端ID
|
||||
* @param channel channel
|
||||
*/
|
||||
public static <T> void pushServerEndpointChannel(String serverId, String clientId, Channel channel) {
|
||||
List<NettyClientChannel> nettyClientChannelList = getServerEndpointChannels(serverId);
|
||||
public static <T> void pushServerEndpointChannel(String namespace, String clientId, Channel channel) {
|
||||
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();
|
||||
if (oldChannel != null && oldChannel.isActive()) {
|
||||
oldChannel.close();
|
||||
@ -39,11 +42,11 @@ public class NettyServerContext {
|
||||
List<NettyClientChannel> activeNettyClientChannelList = nettyClientChannelList
|
||||
.stream()
|
||||
.filter(nettyClientChannel ->
|
||||
!nettyClientChannel.getClientId().equals(clientId) && !nettyClientChannel.getServerId().equals(serverId))
|
||||
!nettyClientChannel.getClientId().equals(clientId) && !nettyClientChannel.getNamespace().equals(namespace))
|
||||
.collect(Collectors.toList());
|
||||
NettyClientChannel nettyClientChannel = new NettyClientChannel(clientId, channel, serverId);
|
||||
NettyClientChannel nettyClientChannel = new NettyClientChannel(clientId, channel, namespace);
|
||||
activeNettyClientChannelList.add(nettyClientChannel);
|
||||
NETTY_CLIENT_CHANNEL_SOCKET.put(serverId, activeNettyClientChannelList);
|
||||
NETTY_CLIENT_CHANNEL_SOCKET.put(namespace, activeNettyClientChannelList);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -15,8 +15,8 @@ import java.nio.charset.StandardCharsets;
|
||||
@Setter
|
||||
@Getter
|
||||
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
|
||||
public static final int bodyLength = 1 + 1 + 4 + 4 + 4 + 4 + 4 + 4 + 4 + 4 + 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 + 4;
|
||||
|
||||
|
||||
/**
|
||||
@ -55,6 +55,12 @@ public class NettyProxyMsg {
|
||||
* @since 1.2.9
|
||||
*/
|
||||
private byte[] originalIp;
|
||||
|
||||
/**
|
||||
* namespace
|
||||
* byte[] 长度 4
|
||||
*/
|
||||
private byte[] namespace;
|
||||
/**
|
||||
* 客户端ID
|
||||
* byte[] 长度 4
|
||||
@ -106,6 +112,14 @@ public class NettyProxyMsg {
|
||||
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) {
|
||||
if (ObjectUtils.isEmpty(appKey)) {
|
||||
@ -172,18 +186,28 @@ public class NettyProxyMsg {
|
||||
return new String(originalIp, StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
public String getClientIdString() {
|
||||
public String clientId() {
|
||||
if (ObjectUtils.isEmpty(clientId)) {
|
||||
return null;
|
||||
}
|
||||
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 客户端目标地址
|
||||
*/
|
||||
public String getTargetIpString() {
|
||||
public String targetIp() {
|
||||
if (ObjectUtils.isEmpty(clientTargetIp)) {
|
||||
return null;
|
||||
}
|
||||
@ -194,7 +218,7 @@ public class NettyProxyMsg {
|
||||
*
|
||||
* @return 客户端目标端口
|
||||
*/
|
||||
public String getTargetPortString() {
|
||||
public String targetPort() {
|
||||
if (ObjectUtils.isEmpty(clientTargetPort)) {
|
||||
return null;
|
||||
}
|
||||
@ -205,7 +229,7 @@ public class NettyProxyMsg {
|
||||
* 获取访客ID
|
||||
* @return
|
||||
*/
|
||||
public String getVisitorIdString() {
|
||||
public String visitorId() {
|
||||
if (ObjectUtils.isEmpty(visitorId)) {
|
||||
return null;
|
||||
}
|
||||
|
@ -173,7 +173,7 @@ public class UdpMessageType {
|
||||
*
|
||||
* @see UdpMessageTypeEnums#UDP_REPORT_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL
|
||||
* @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;
|
||||
|
||||
@ -183,7 +183,7 @@ public class UdpMessageType {
|
||||
*
|
||||
* @see UdpMessageTypeEnums#UDP_REPORT_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_INIT_SUCCESSFUL
|
||||
* @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;
|
||||
/**
|
||||
@ -191,7 +191,7 @@ public class UdpMessageType {
|
||||
*
|
||||
* @see UdpMessageTypeEnums#UDP_REPORT_CLIENT_TRANSFER_CLIENT_REQUEST
|
||||
* @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;
|
||||
|
||||
@ -200,7 +200,7 @@ public class UdpMessageType {
|
||||
*
|
||||
* @see UdpMessageTypeEnums#UDP_REPORT_CLIENT_TRANSFER_CLIENT_RESPONSE
|
||||
* @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;
|
||||
|
||||
@ -209,7 +209,7 @@ public class UdpMessageType {
|
||||
*
|
||||
* @see UdpMessageTypeEnums#UDP_REPORT_CLIENT_PERMEATE_CLIENT_TRANSFER_CLOSE
|
||||
* @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;
|
||||
|
||||
@ -370,7 +370,7 @@ public class UdpMessageType {
|
||||
*
|
||||
* @see UdpMessageTypeEnums#UDP_DISTRIBUTE_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL
|
||||
* @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;
|
||||
|
||||
@ -380,7 +380,7 @@ public class UdpMessageType {
|
||||
*
|
||||
* @see UdpMessageTypeEnums#UDP_DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_CHANNEL_INIT_SUCCESSFUL
|
||||
* @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;
|
||||
|
||||
@ -389,7 +389,7 @@ public class UdpMessageType {
|
||||
*
|
||||
* @see UdpMessageTypeEnums#UDP_DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_REQUEST
|
||||
* @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;
|
||||
/**
|
||||
@ -397,7 +397,7 @@ public class UdpMessageType {
|
||||
*
|
||||
* @see UdpMessageTypeEnums#UDP_DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_RESPONSE
|
||||
* @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;
|
||||
|
||||
@ -407,7 +407,7 @@ public class UdpMessageType {
|
||||
*
|
||||
* @see UdpMessageTypeEnums#UDP_DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_CLOSE
|
||||
* @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;
|
||||
|
||||
|
@ -128,6 +128,13 @@ public class NettyProxyMsgDecoder extends LengthFieldBasedFrameDecoder {
|
||||
in.readBytes(originalIpBytes);
|
||||
nettyProxyMsg.setOriginalIp(originalIpBytes);
|
||||
|
||||
|
||||
int namespaceLength = in.readInt();
|
||||
byte[] namespaceBytes = new byte[namespaceLength];
|
||||
in.readBytes(namespaceBytes);
|
||||
nettyProxyMsg.setNamespace(namespaceBytes);
|
||||
|
||||
|
||||
int clientIdLength = in.readInt();
|
||||
byte[] clientIdBytes = new byte[clientIdLength];
|
||||
in.readBytes(clientIdBytes);
|
||||
@ -159,6 +166,7 @@ public class NettyProxyMsgDecoder extends LengthFieldBasedFrameDecoder {
|
||||
appKeyLength -
|
||||
appSecretLength -
|
||||
originalIpLength -
|
||||
namespaceLength -
|
||||
clientIdLength -
|
||||
clientTargetIpLength -
|
||||
clientTargetPortLength -
|
||||
|
@ -28,6 +28,7 @@ public class NettyProxyMsgEncoder extends MessageToByteEncoder<NettyProxyMsg> {
|
||||
byte[] appKey = msg.getAppKey();
|
||||
byte[] appSecret = msg.getAppSecret();
|
||||
byte[] originalIp = msg.getOriginalIp();
|
||||
byte[] namespace = msg.getNamespace();
|
||||
byte[] clientIdBytes = msg.getClientId();
|
||||
byte[] clientTargetIpBytes = msg.getClientTargetIp();
|
||||
byte[] clientTargetPortBytes = msg.getClientTargetPort();
|
||||
@ -44,6 +45,9 @@ public class NettyProxyMsgEncoder extends MessageToByteEncoder<NettyProxyMsg> {
|
||||
if (originalIp != null) {
|
||||
bodyLength += originalIp.length;
|
||||
}
|
||||
if (namespace != null) {
|
||||
bodyLength += namespace.length;
|
||||
}
|
||||
if (clientIdBytes != null) {
|
||||
bodyLength += clientIdBytes.length;
|
||||
}
|
||||
@ -95,6 +99,18 @@ public class NettyProxyMsgEncoder extends MessageToByteEncoder<NettyProxyMsg> {
|
||||
// 防止原始IP 未填写
|
||||
out.writeInt(0x00);
|
||||
}
|
||||
|
||||
|
||||
// 防止数据读错位置 服务端IP
|
||||
if (namespace != null) {
|
||||
out.writeInt(namespace.length);
|
||||
out.writeBytes(namespace);
|
||||
} else {
|
||||
// 防止 服务端IP 未填写
|
||||
out.writeInt(0x00);
|
||||
}
|
||||
|
||||
|
||||
// 防止数据读错位置 clientId
|
||||
if (clientIdBytes != null) {
|
||||
out.writeInt(clientIdBytes.length);
|
||||
@ -132,6 +148,7 @@ public class NettyProxyMsgEncoder extends MessageToByteEncoder<NettyProxyMsg> {
|
||||
out.writeInt(0x00);
|
||||
}
|
||||
|
||||
// 访客ID
|
||||
if (visitorIdBytes != null) {
|
||||
out.writeInt(visitorIdBytes.length);
|
||||
out.writeBytes(visitorIdBytes);
|
||||
@ -139,6 +156,8 @@ public class NettyProxyMsgEncoder extends MessageToByteEncoder<NettyProxyMsg> {
|
||||
// 防止客户端 访客ID未填写
|
||||
out.writeInt(0x00);
|
||||
}
|
||||
|
||||
// 数据消息体
|
||||
if (msgDataBytes != null) {
|
||||
out.writeBytes(msgDataBytes);
|
||||
}
|
||||
|
@ -30,8 +30,8 @@ public class HttpClientProxyClientProxyTypeAdvanced extends AbstractHttpClientPr
|
||||
@Override
|
||||
protected void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg nettyProxyMsg) {
|
||||
Channel channel = nettyChannelContext.channel();
|
||||
String targetPortString = nettyProxyMsg.getTargetPortString();
|
||||
String targetIpString = nettyProxyMsg.getTargetIpString();
|
||||
String targetPortString = nettyProxyMsg.targetPort();
|
||||
String targetIpString = nettyProxyMsg.targetIp();
|
||||
Bootstrap b = new Bootstrap();
|
||||
b.group(channel.eventLoop())
|
||||
.channel(NioSocketChannel.class)
|
||||
|
@ -29,8 +29,8 @@ public class HttpProtocolHandleChannelLocalProxyTypeAdvanced extends AbstractHtt
|
||||
*/
|
||||
@Override
|
||||
protected void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg nettyProxyMsg) {
|
||||
String targetPortString = nettyProxyMsg.getTargetPortString();
|
||||
String targetIpString = nettyProxyMsg.getTargetIpString();
|
||||
String targetPortString = nettyProxyMsg.targetPort();
|
||||
String targetIpString = nettyProxyMsg.targetIp();
|
||||
Bootstrap b = new Bootstrap();
|
||||
Channel channel = nettyChannelContext.channel();
|
||||
b.group(channel.eventLoop())
|
||||
|
@ -37,8 +37,8 @@ public class NettySocketProtocolHandleSocketLocalProxyTypeAdvanced
|
||||
Channel channel = nettySocketChannelContext.channel();
|
||||
ChannelHandlerContext channelHandlerContext = nettySocketChannelContext.channelHandlerContext();
|
||||
EventLoopGroup group = EventLoopGroupFactory.createClientWorkGroup();
|
||||
String host = nettyProxyMsg.getTargetIpString();
|
||||
Integer port = Integer.parseInt(nettyProxyMsg.getTargetPortString());
|
||||
String host = nettyProxyMsg.targetIp();
|
||||
Integer port = Integer.parseInt(nettyProxyMsg.targetPort());
|
||||
Bootstrap b = new Bootstrap();
|
||||
Socks5AddressType socks5AddressType = nettySocketChannelContext.getSocks5AddressType();
|
||||
|
||||
|
@ -83,11 +83,11 @@ public class NettyHttpProxyHandler extends ChannelInboundHandlerAdapter {
|
||||
|
||||
|
||||
ProxyRoute route = RouteContext.getRoute(originHost, String.valueOf(originPort));
|
||||
|
||||
String namespace = route.getNamespace();
|
||||
proxyMsg.setVisitorId(visitorId);
|
||||
proxyMsg.setData(bytes);
|
||||
|
||||
|
||||
proxyMsg.setNamespace(namespace);
|
||||
|
||||
if(ObjectUtils.isEmpty(route)){
|
||||
// 本地代理
|
||||
|
@ -60,7 +60,8 @@ public class NettySocks5CommandRequestHandler extends SimpleChannelInboundHandle
|
||||
|
||||
proxyMsg.setVisitorId(visitorId);
|
||||
ProxyRoute route = RouteContext.getRoute(originHost, String.valueOf(originPort));
|
||||
|
||||
String namespace = route.getNamespace();
|
||||
proxyMsg.setNamespace(namespace);
|
||||
|
||||
|
||||
if(ObjectUtils.isEmpty(route)){
|
||||
|
@ -24,6 +24,10 @@ public class ClientProxyRoute implements ProxyRoute{
|
||||
* 虚拟端口
|
||||
*/
|
||||
private String virtualPort;
|
||||
/**
|
||||
* 命名空间
|
||||
*/
|
||||
private String namespace;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -6,6 +6,9 @@ package org.framework.lazy.cloud.network.heartbeat.protocol.route;
|
||||
public interface ProxyRoute {
|
||||
|
||||
|
||||
String getNamespace();
|
||||
|
||||
|
||||
String getVirtualIp();
|
||||
|
||||
|
||||
|
@ -9,6 +9,11 @@ import lombok.Data;
|
||||
@Data
|
||||
public class ServerProxyRoute implements ProxyRoute {
|
||||
|
||||
|
||||
/**
|
||||
* 命名空间
|
||||
*/
|
||||
private String namespace;
|
||||
/**
|
||||
*
|
||||
* 服务端ip
|
||||
|
@ -161,7 +161,7 @@ public class LazyNettyClusterNodeRepositoryImpl implements LazyNettyClusterNodeR
|
||||
// 查询这个节点下客户端注册是否正常
|
||||
List<LazyNettyClientStateDO> lazyNettyClientStateDOList = lazyLambdaStream.selectList(
|
||||
LazyWrappers.<LazyNettyClientStateDO>lambdaWrapper()
|
||||
.eq(LazyNettyClientStateDO::getServerId, clusterNodeId)
|
||||
.eq(LazyNettyClientStateDO::getNamespace, clusterNodeId)
|
||||
);
|
||||
boolean anyMatch = lazyNettyClientStateDOList.stream()
|
||||
.anyMatch(lazyNettyClientStateDO ->
|
||||
|
@ -76,11 +76,12 @@ public class ServerHandleTcpClientConnectSuccessTypeAdvanced extends AbstractHan
|
||||
public void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg msg) {
|
||||
|
||||
Channel newChannel = nettyChannelContext.channel();
|
||||
String clientId = msg.getClientIdString();
|
||||
String serverId = msg.namespace();
|
||||
String clientId = msg.clientId();
|
||||
String appKey = msg.getAppKeyString();
|
||||
String appSecret = msg.getAppSecretString();
|
||||
String originalIp = msg.getOriginalIpString();
|
||||
ChannelContext.push(newChannel, clientId);
|
||||
ChannelContext.push(newChannel,serverId, clientId);
|
||||
|
||||
ChannelAttributeKeyUtils.buildClientId(newChannel, clientId);
|
||||
ChannelAttributeKeyUtils.buildAppKey(newChannel, appKey);
|
||||
@ -172,11 +173,13 @@ public class ServerHandleTcpClientConnectSuccessTypeAdvanced extends AbstractHan
|
||||
.accept(lazyInternalNetworkClientPermeateServerMappingDTOS -> {
|
||||
for (LazyClientPermeateClientMappingDTO lazyClientPermeateClientMappingDTO : lazyInternalNetworkClientPermeateServerMappingDTOS) {
|
||||
|
||||
String selfNamespace = lazyClientPermeateClientMappingDTO.getNamespace();
|
||||
String permeateTargetIp = lazyClientPermeateClientMappingDTO.getPermeateTargetIp();
|
||||
Integer permeateTargetPort = lazyClientPermeateClientMappingDTO.getPermeateTargetPort();
|
||||
Integer visitorPort = lazyClientPermeateClientMappingDTO.getVisitorPort();
|
||||
String toClientId = lazyClientPermeateClientMappingDTO.getToClientId();
|
||||
NettyProxyMsg nettyMsg = new NettyProxyMsg();
|
||||
nettyMsg.setNamespace(selfNamespace);
|
||||
nettyMsg.setType(TcpMessageType.TCP_DISTRIBUTE_CLIENT_PERMEATE_CLIENT_INIT);
|
||||
nettyMsg.setClientTargetIp(permeateTargetIp);
|
||||
nettyMsg.setClientTargetPort(permeateTargetPort);
|
||||
|
@ -2,9 +2,10 @@ package org.framework.lazy.cloud.network.heartbeat.server.netty.permeate.tcp.adv
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.*;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyProxyMsg;
|
||||
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.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.constant.TcpMessageType;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
|
||||
@ -18,7 +19,8 @@ import org.springframework.stereotype.Component;
|
||||
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
|
||||
@Slf4j
|
||||
@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[] msgClientTargetIp = nettyProxyMsg.getClientTargetIp();
|
||||
byte[] msgClientTargetPort = nettyProxyMsg.getClientTargetPort();
|
||||
byte[] clientId = nettyProxyMsg.getClientId();// 目标客户端ID
|
||||
String clientId = nettyProxyMsg.clientId();// 目标客户端ID
|
||||
String namespace = nettyProxyMsg.namespace();
|
||||
|
||||
ChannelAttributeKeyUtils.buildClientId(transferChannel, clientId);
|
||||
ChannelAttributeKeyUtils.buildVisitorPort(transferChannel, Integer.parseInt(new String(msgVisitorPort)));
|
||||
ChannelAttributeKeyUtils.buildVisitorId(transferChannel, msgVisitorId);
|
||||
// 绑定访客通道
|
||||
NettyTransferChannelContext.pushVisitor(transferChannel,msgVisitorId);
|
||||
Channel clientChannel = ChannelContext.getLoadBalance(clientId);
|
||||
Channel clientChannel = ChannelContext.getLoadBalance(namespace, clientId);
|
||||
|
||||
NettyProxyMsg clientConnectTagetNettyProxyMsg = new NettyProxyMsg();
|
||||
clientConnectTagetNettyProxyMsg.setVisitorId(msgVisitorId);
|
||||
|
@ -36,7 +36,7 @@ public class ServerHandleTcpReportClientTransferClientResponseTypeAdvanced exten
|
||||
byte[] msgVisitorPort = nettyProxyMsg.getVisitorPort();
|
||||
byte[] msgClientTargetIp = nettyProxyMsg.getClientTargetIp();
|
||||
byte[] msgClientTargetPort = nettyProxyMsg.getClientTargetPort();
|
||||
String clientId = nettyProxyMsg.getClientIdString();
|
||||
String clientId = nettyProxyMsg.clientId();
|
||||
// 下发客户端初始化成功
|
||||
Channel nextChannel = ChannelAttributeKeyUtils.getTransferNextChannel(channel);
|
||||
|
||||
|
@ -36,7 +36,7 @@ public class ServerHandleTcpReportClientTransferClientTypeAdvanced extends Abstr
|
||||
byte[] msgVisitorPort = nettyProxyMsg.getVisitorPort();
|
||||
byte[] msgClientTargetIp = nettyProxyMsg.getClientTargetIp();
|
||||
byte[] msgClientTargetPort = nettyProxyMsg.getClientTargetPort();
|
||||
String clientId = nettyProxyMsg.getClientIdString();
|
||||
String clientId = nettyProxyMsg.clientId();
|
||||
// 下发客户端初始化成功
|
||||
Channel nextChannel = ChannelAttributeKeyUtils.getTransferNextChannel(channel);
|
||||
Integer visitorPort = ChannelAttributeKeyUtils.getVisitorPort(channel);
|
||||
|
@ -47,9 +47,10 @@ public class ServerHandleTcpReportDisconnectTypeAdvanced extends AbstractHandleT
|
||||
Channel deathChannel = nettyChannelContext.channel();
|
||||
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);
|
||||
Channel deathClientChannelDTO = ChannelContext.getLoadBalance(clientId);
|
||||
Channel deathClientChannelDTO = ChannelContext.getLoadBalance(serverId,clientId);
|
||||
String appKey = ChannelAttributeKeyUtils.getAppKey(deathChannel);
|
||||
String appSecret = ChannelAttributeKeyUtils.getAppSecret(deathChannel);
|
||||
String originalIp = ChannelAttributeKeyUtils.getOriginalIp(deathChannel);
|
||||
@ -58,11 +59,12 @@ public class ServerHandleTcpReportDisconnectTypeAdvanced extends AbstractHandleT
|
||||
|
||||
LazyNettyClientLoginCommand lazyNettyClientLoginCommand = new LazyNettyClientLoginCommand();
|
||||
lazyNettyClientLoginCommand.setClientId(clientId);
|
||||
lazyNettyClientLoginCommand.setNamespace(serverId);
|
||||
lazyNettyClientLoginCommand.setAppKey(appKey);
|
||||
lazyNettyClientLoginCommand.setAppSecret(appSecret);
|
||||
lazyNettyClientLoginCommand.setOriginalIp(originalIp);
|
||||
lazyClientStatsChangeApplication.clientOffLine(lazyNettyClientLoginCommand);
|
||||
ChannelContext.remove(clientId);
|
||||
ChannelContext.remove(serverId,clientId);
|
||||
|
||||
// 通知其他客户端 channelId 关闭了
|
||||
ChannelContext.getChannels().forEach((existClientId, channels) -> {
|
||||
|
@ -43,11 +43,12 @@ public class ServerHandleTcpReportStagingClosedTypeAdvanced extends AbstractHand
|
||||
String appSecret = ChannelAttributeKeyUtils.getAppSecret(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) {
|
||||
String clientId = new String(clientIdBytes);
|
||||
|
||||
// 存储当前客户端暂存关闭
|
||||
LazyNettyClientLoginCommand lazyNettyClientLoginCommand = new LazyNettyClientLoginCommand();
|
||||
lazyNettyClientLoginCommand.setClientId(clientId);
|
||||
|
@ -42,15 +42,15 @@ public class ServerHandleTcpReportStagingOpenedTypeAdvanced extends AbstractHand
|
||||
protected void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg msg) {
|
||||
Channel stagingOpenedChannel = nettyChannelContext.channel();
|
||||
// 获取所有通道
|
||||
byte[] clientIdBytes = msg.getClientId();
|
||||
String serverId = msg.namespace();
|
||||
String clientId = msg.clientId();
|
||||
String appKey = ChannelAttributeKeyUtils.getAppKey(stagingOpenedChannel);
|
||||
String appSecret = ChannelAttributeKeyUtils.getAppSecret(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.setClientId(clientId);
|
||||
lazyNettyClientLoginCommand.setAppKey(appKey);
|
||||
|
@ -40,6 +40,7 @@ public class NettyTcpServerPermeateClientVisitorHandler extends SimpleChannelInb
|
||||
|
||||
// 生成访客ID
|
||||
String visitorId = UUID.randomUUID().toString();
|
||||
String namespace = internalNetworkPenetrationRealClient.getNamespace();
|
||||
String clientId = internalNetworkPenetrationRealClient.getClientId();
|
||||
Integer visitorPort = internalNetworkPenetrationRealClient.getVisitorPort();
|
||||
String clientTargetIp = internalNetworkPenetrationRealClient.getClientTargetIp();
|
||||
@ -50,6 +51,7 @@ public class NettyTcpServerPermeateClientVisitorHandler extends SimpleChannelInb
|
||||
ChannelAttributeKeyUtils.buildVisitorId(visitorChannel, visitorId);
|
||||
ChannelAttributeKeyUtils.buildClientId(visitorChannel, clientId);
|
||||
NettyProxyMsg nettyProxyMsg = new NettyProxyMsg();
|
||||
nettyProxyMsg.setNamespace(namespace);
|
||||
nettyProxyMsg.setType(TcpMessageType.TCP_DISTRIBUTE_SINGLE_CLIENT_REAL_CONNECT);
|
||||
nettyProxyMsg.setClientId(clientId);
|
||||
nettyProxyMsg.setVisitorPort(visitorPort);
|
||||
@ -62,7 +64,7 @@ public class NettyTcpServerPermeateClientVisitorHandler extends SimpleChannelInb
|
||||
// Channel transferChannel = nettyChannelPool.availableChannel(visitorId);
|
||||
// if (transferChannel == null) {
|
||||
// 客户端心跳通道
|
||||
Channel clientChannel = ChannelContext.getLoadBalance(clientId);
|
||||
Channel clientChannel = ChannelContext.getLoadBalance(namespace,clientId);
|
||||
if (clientChannel != null) {
|
||||
log.info("通过客户端:{},获取通道而后创建连接", clientId);
|
||||
clientChannel.writeAndFlush(nettyProxyMsg);
|
||||
|
@ -106,6 +106,10 @@ public class NettyTcpServerPermeateClientVisitorSocket implements PermeateVisito
|
||||
|
||||
public static final class NettyVisitorSocketBuilder {
|
||||
|
||||
/**
|
||||
* 命名空间
|
||||
*/
|
||||
private String namespace;
|
||||
/**
|
||||
* 客户端ID
|
||||
*/
|
||||
@ -140,6 +144,16 @@ public class NettyTcpServerPermeateClientVisitorSocket implements PermeateVisito
|
||||
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() {
|
||||
if (namespace == null) {
|
||||
throw new IllegalArgumentException("namespace must not null");
|
||||
}
|
||||
if (clientId == null) {
|
||||
throw new IllegalArgumentException("clientId must not null");
|
||||
}
|
||||
@ -221,6 +238,7 @@ public class NettyTcpServerPermeateClientVisitorSocket implements PermeateVisito
|
||||
}
|
||||
InternalNetworkPenetrationRealClient internalNetworkPenetrationRealClient = InternalNetworkPenetrationRealClient
|
||||
.builder()
|
||||
.namespace(namespace)
|
||||
.clientId(clientId)
|
||||
.clientTargetIp(clientTargetIp)
|
||||
.clientTargetPort(clientTargetPort)
|
||||
|
@ -66,12 +66,12 @@ public class ServerHandleUdpClientConnectSuccessTypeAdvanced extends AbstractHan
|
||||
@Override
|
||||
public void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg msg) {
|
||||
Channel newChannel = nettyChannelContext.channel();
|
||||
|
||||
String clientId = msg.getClientIdString();
|
||||
String serverId = msg.namespace();
|
||||
String clientId = msg.clientId();
|
||||
String appKey = msg.getAppKeyString();
|
||||
String appSecret = msg.getAppSecretString();
|
||||
String originalIp = msg.getOriginalIpString();
|
||||
ChannelContext.push(newChannel, clientId);
|
||||
ChannelContext.push(newChannel, serverId,clientId);
|
||||
|
||||
ChannelAttributeKeyUtils.buildClientId(newChannel, clientId);
|
||||
ChannelAttributeKeyUtils.buildAppKey(newChannel, appKey);
|
||||
|
@ -3,11 +3,11 @@ package org.framework.lazy.cloud.network.heartbeat.server.netty.permeate.udp.adv
|
||||
import io.netty.channel.Channel;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
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.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.constant.TcpMessageType;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.context.annotation.Role;
|
||||
@ -30,18 +30,19 @@ public class ServerHandleUdpReportClientTransferClientPermeateChannelConnectionS
|
||||
protected void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg nettyProxyMsg) {
|
||||
Channel channel = nettyChannelContext.channel();
|
||||
// 创建目标地址连接
|
||||
String namespace = nettyProxyMsg.namespace();
|
||||
byte[] msgVisitorId = nettyProxyMsg.getVisitorId();
|
||||
byte[] msgVisitorPort = nettyProxyMsg.getVisitorPort();
|
||||
byte[] msgClientTargetIp = nettyProxyMsg.getClientTargetIp();
|
||||
String msgClientTargetIp = nettyProxyMsg.targetIp();
|
||||
byte[] msgClientTargetPort = nettyProxyMsg.getClientTargetPort();
|
||||
byte[] clientId = nettyProxyMsg.getClientId();// 目标客户端ID
|
||||
String clientId = nettyProxyMsg.clientId();// 目标客户端ID
|
||||
|
||||
ChannelAttributeKeyUtils.buildClientId(channel, clientId);
|
||||
ChannelAttributeKeyUtils.buildVisitorPort(channel, Integer.parseInt(new String(msgVisitorPort)));
|
||||
ChannelAttributeKeyUtils.buildVisitorId(channel, msgVisitorId);
|
||||
// 绑定访客通道
|
||||
NettyTransferChannelContext.pushVisitor(channel,msgVisitorId);
|
||||
Channel clientChannel = ChannelContext.getLoadBalance(clientId);
|
||||
Channel clientChannel = ChannelContext.getLoadBalance(namespace,clientId);
|
||||
|
||||
NettyProxyMsg clientConnectTagetNettyProxyMsg = new NettyProxyMsg();
|
||||
clientConnectTagetNettyProxyMsg.setVisitorId(msgVisitorId);
|
||||
|
@ -38,7 +38,7 @@ public class ServerHandleUdpReportClientTransferClientResponseTypeAdvanced exten
|
||||
byte[] msgVisitorPort = nettyProxyMsg.getVisitorPort();
|
||||
byte[] msgClientTargetIp = nettyProxyMsg.getClientTargetIp();
|
||||
byte[] msgClientTargetPort = nettyProxyMsg.getClientTargetPort();
|
||||
String clientId = nettyProxyMsg.getClientIdString();
|
||||
String clientId = nettyProxyMsg.clientId();
|
||||
// 下发客户端初始化成功
|
||||
Channel nextChannel = ChannelAttributeKeyUtils.getTransferNextChannel(channel);
|
||||
|
||||
|
@ -36,7 +36,7 @@ public class ServerHandleUdpReportClientTransferClientTypeAdvanced extends Abstr
|
||||
byte[] msgVisitorPort = nettyProxyMsg.getVisitorPort();
|
||||
byte[] msgClientTargetIp = nettyProxyMsg.getClientTargetIp();
|
||||
byte[] msgClientTargetPort = nettyProxyMsg.getClientTargetPort();
|
||||
String clientId = nettyProxyMsg.getClientIdString();
|
||||
String clientId = nettyProxyMsg.clientId();
|
||||
// 下发客户端初始化成功
|
||||
Channel nextChannel = ChannelAttributeKeyUtils.getTransferNextChannel(channel);
|
||||
Integer visitorPort = ChannelAttributeKeyUtils.getVisitorPort(channel);
|
||||
|
@ -46,9 +46,10 @@ public class ServerHandleUdpReportDisconnectTypeAdvanced extends AbstractHandleU
|
||||
public void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg msg) {
|
||||
Channel deathChannel = nettyChannelContext.channel();
|
||||
// 关闭连接通知
|
||||
String clientId = msg.getClientIdString();
|
||||
String clientId = msg.clientId();
|
||||
String serverId = msg.namespace();
|
||||
log.warn("close client :{} channel", clientId);
|
||||
Channel deathClientChannelDTO = ChannelContext.getLoadBalance(clientId);
|
||||
Channel deathClientChannelDTO = ChannelContext.getLoadBalance(serverId,clientId);
|
||||
String appKey = ChannelAttributeKeyUtils.getAppKey(deathChannel);
|
||||
String appSecret = ChannelAttributeKeyUtils.getAppSecret(deathChannel);
|
||||
String originalIp = ChannelAttributeKeyUtils.getOriginalIp(deathChannel);
|
||||
@ -61,7 +62,7 @@ public class ServerHandleUdpReportDisconnectTypeAdvanced extends AbstractHandleU
|
||||
lazyNettyClientLoginCommand.setAppSecret(appSecret);
|
||||
lazyNettyClientLoginCommand.setOriginalIp(originalIp);
|
||||
lazyClientStatsChangeApplication.clientOffLine(lazyNettyClientLoginCommand);
|
||||
ChannelContext.remove(clientId);
|
||||
ChannelContext.remove(serverId,clientId);
|
||||
|
||||
// 通知其他客户端 channelId 关闭了
|
||||
ChannelContext.getChannels().forEach((existClientId, channels) -> {
|
||||
@ -87,7 +88,7 @@ public class ServerHandleUdpReportDisconnectTypeAdvanced extends AbstractHandleU
|
||||
for (NettyUdpServerPermeateClientVisitorSocket visitorSocket : visitorSockets) {
|
||||
int visitorPort = visitorSocket.getVisitorPort();
|
||||
visitorSocket.close();
|
||||
log.warn("client :[{}] visitorPort:[{}] close", new String(clientId), visitorPort);
|
||||
log.warn("client :[{}] visitorPort:[{}] close", clientId, visitorPort);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,9 +4,9 @@ import io.netty.channel.Channel;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
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.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.server.standalone.application.LazyClientStatsChangeApplication;
|
||||
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 appSecret = ChannelAttributeKeyUtils.getAppSecret(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) {
|
||||
String clientId = new String(clientIdBytes);
|
||||
|
||||
// 存储当前客户端暂存关闭
|
||||
LazyNettyClientLoginCommand lazyNettyClientLoginCommand = new LazyNettyClientLoginCommand();
|
||||
lazyNettyClientLoginCommand.setClientId(clientId);
|
||||
|
@ -42,15 +42,16 @@ public class ServerHandleUdpReportStagingOpenedTypeAdvanced extends AbstractHand
|
||||
protected void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg msg) {
|
||||
Channel stagingOpenedChannel = nettyChannelContext.channel();
|
||||
// 获取所有通道
|
||||
byte[] clientIdBytes = msg.getClientId();
|
||||
String serverId = msg.namespace();
|
||||
String clientId = msg.clientId();
|
||||
String appKey = ChannelAttributeKeyUtils.getAppKey(stagingOpenedChannel);
|
||||
String appSecret = ChannelAttributeKeyUtils.getAppSecret(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.setClientId(clientId);
|
||||
lazyNettyClientLoginCommand.setAppKey(appKey);
|
||||
|
@ -40,6 +40,7 @@ public class NettyUdpServerPermeateClientVisitorHandler extends SimpleChannelInb
|
||||
|
||||
// 生成访客ID
|
||||
String visitorId = UUID.randomUUID().toString();
|
||||
String namespace = internalNetworkPenetrationRealClient.getNamespace();
|
||||
String clientId = internalNetworkPenetrationRealClient.getClientId();
|
||||
Integer visitorPort = internalNetworkPenetrationRealClient.getVisitorPort();
|
||||
String clientTargetIp = internalNetworkPenetrationRealClient.getClientTargetIp();
|
||||
@ -54,6 +55,7 @@ public class NettyUdpServerPermeateClientVisitorHandler extends SimpleChannelInb
|
||||
nettyProxyMsg.setClientId(clientId);
|
||||
nettyProxyMsg.setVisitorPort(visitorPort);
|
||||
nettyProxyMsg.setClientTargetIp(clientTargetIp);
|
||||
nettyProxyMsg.setNamespace(namespace);
|
||||
nettyProxyMsg.setClientTargetPort(clientTargetPort);
|
||||
|
||||
nettyProxyMsg.setVisitorId(visitorId);
|
||||
@ -62,7 +64,7 @@ public class NettyUdpServerPermeateClientVisitorHandler extends SimpleChannelInb
|
||||
// Channel transferChannel = nettyChannelPool.availableChannel(visitorId);
|
||||
// if (transferChannel == null) {
|
||||
// 客户端心跳通道
|
||||
Channel clientChannel = ChannelContext.getLoadBalance(clientId);
|
||||
Channel clientChannel = ChannelContext.getLoadBalance(namespace,clientId);
|
||||
if (clientChannel != null) {
|
||||
log.info("通过客户端:{},获取通道而后创建连接", clientId);
|
||||
clientChannel.writeAndFlush(nettyProxyMsg);
|
||||
|
@ -106,6 +106,10 @@ public class NettyUdpServerPermeateClientVisitorSocket implements PermeateVisito
|
||||
|
||||
public static final class NettyVisitorSocketBuilder {
|
||||
|
||||
/**
|
||||
* 命名空间
|
||||
*/
|
||||
private String namespace;
|
||||
/**
|
||||
* 客户端ID
|
||||
*/
|
||||
@ -207,6 +211,9 @@ public class NettyUdpServerPermeateClientVisitorSocket implements PermeateVisito
|
||||
}
|
||||
|
||||
public NettyUdpServerPermeateClientVisitorSocket build() {
|
||||
if (namespace == null) {
|
||||
throw new IllegalArgumentException("namespace must not null");
|
||||
}
|
||||
if (clientId == null) {
|
||||
throw new IllegalArgumentException("clientId must not null");
|
||||
}
|
||||
@ -221,6 +228,7 @@ public class NettyUdpServerPermeateClientVisitorSocket implements PermeateVisito
|
||||
}
|
||||
InternalNetworkPenetrationRealClient internalNetworkPenetrationRealClient = InternalNetworkPenetrationRealClient
|
||||
.builder()
|
||||
.namespace(namespace)
|
||||
.clientId(clientId)
|
||||
.clientTargetIp(clientTargetIp)
|
||||
.clientTargetPort(clientTargetPort)
|
||||
|
@ -48,12 +48,13 @@ public class ServerHandleHttpReportClientProxyClientTransferRequestTypeAdvanced
|
||||
public void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg nettyProxyMsg) {
|
||||
Channel channel = nettyChannelContext.channel();
|
||||
// 创建链接、发送数据
|
||||
String targetPortString = nettyProxyMsg.getTargetPortString();
|
||||
String targetPortString = nettyProxyMsg.targetPort();
|
||||
Integer targetPort = Integer.parseInt(targetPortString);
|
||||
String targetIpString = nettyProxyMsg.getTargetIpString();
|
||||
String targetIpString = nettyProxyMsg.targetIp();
|
||||
byte[] data = nettyProxyMsg.getData();
|
||||
byte[] visitorId = nettyProxyMsg.getVisitorId();
|
||||
byte[] clientId = nettyProxyMsg.getClientId();
|
||||
String serverId = nettyProxyMsg.namespace();
|
||||
String clientId = nettyProxyMsg.clientId();
|
||||
String msgVisitorId = new String(visitorId);
|
||||
ChannelAttributeKeyUtils.buildClientId(channel, clientId);
|
||||
ChannelAttributeKeyUtils.buildVisitorId(channel, msgVisitorId);
|
||||
@ -66,7 +67,7 @@ public class ServerHandleHttpReportClientProxyClientTransferRequestTypeAdvanced
|
||||
nettyByteBuf.setData(data);
|
||||
ChannelAttributeKeyUtils.buildNettyByteBufData(channel, nettyByteBuf);
|
||||
// 获取客户端心跳通道
|
||||
Channel loadBalance = ChannelContext.getLoadBalance(clientId);
|
||||
Channel loadBalance = ChannelContext.getLoadBalance(serverId,clientId);
|
||||
|
||||
NettyProxyMsg clientConnectTagetNettyProxyMsg = new NettyProxyMsg();
|
||||
clientConnectTagetNettyProxyMsg.setVisitorId(msgVisitorId);
|
||||
|
@ -50,9 +50,9 @@ public class ServerHandleHttpReportClientProxyClientTransferResponseTypeAdvanced
|
||||
String targetIp = ChannelAttributeKeyUtils.getTargetIp(transferNextChannel);
|
||||
Integer targetPort = ChannelAttributeKeyUtils.getTargetPort(transferNextChannel);
|
||||
|
||||
String clientId = nettyProxyMsg.getClientIdString();
|
||||
String clientId = nettyProxyMsg.clientId();
|
||||
Integer visitorPort = nettyProxyMsg.getVisitorPortInt();
|
||||
String visitorId = nettyProxyMsg.getVisitorIdString();
|
||||
String visitorId = nettyProxyMsg.visitorId();
|
||||
if(ObjectUtils.isNotEmpty(transferNextChannel)) {
|
||||
log.info("目标客户端返回数据通过服务端下发到原始通道");
|
||||
NettyProxyMsg responseProxyMsg = new NettyProxyMsg();
|
||||
|
@ -51,10 +51,10 @@ public class ServerHandleHttpReportClientProxyServerTransferRequestTypeAdvanced
|
||||
public void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg nettyProxyMsg) {
|
||||
Channel channel = nettyChannelContext.channel();
|
||||
// 创建链接、发送数据
|
||||
String targetPortString = nettyProxyMsg.getTargetPortString();
|
||||
String targetPortString = nettyProxyMsg.targetPort();
|
||||
int targetPort = Integer.parseInt(targetPortString);
|
||||
String targetIpString = nettyProxyMsg.getTargetIpString();
|
||||
String clientIdString = nettyProxyMsg.getClientIdString();
|
||||
String targetIpString = nettyProxyMsg.targetIp();
|
||||
String clientIdString = nettyProxyMsg.clientId();
|
||||
byte[] data = nettyProxyMsg.getData();
|
||||
byte[] visitorId = nettyProxyMsg.getVisitorId();
|
||||
String originalIpString = nettyProxyMsg.getOriginalIpString();
|
||||
|
@ -45,8 +45,8 @@ public class ServerHandleHttpReportServerProxyClientTransferRequestTypeAdvanced
|
||||
// 数据下发
|
||||
byte[] msgVisitorId = nettyProxyMsg.getVisitorId();
|
||||
|
||||
String targetIpString = nettyProxyMsg.getTargetIpString();
|
||||
String targetPortString = nettyProxyMsg.getTargetPortString();
|
||||
String targetIpString = nettyProxyMsg.targetIp();
|
||||
String targetPortString = nettyProxyMsg.targetPort();
|
||||
Integer targetPort = Integer.parseInt(targetPortString);
|
||||
|
||||
|
||||
|
@ -34,33 +34,34 @@ public class ServerHandleHttpReportServerProxyClientTransferTypeAdvanced
|
||||
|
||||
Channel channel = nettyChannelContext.channel();
|
||||
// 创建链接、发送数据
|
||||
String targetPortString = nettyProxyMsg.getTargetPortString();
|
||||
String targetIpString = nettyProxyMsg.getTargetIpString();
|
||||
String targetPort = nettyProxyMsg.targetPort();
|
||||
String targetIp = nettyProxyMsg.targetIp();
|
||||
byte[] data = nettyProxyMsg.getData();
|
||||
byte[] visitorId = nettyProxyMsg.getVisitorId();
|
||||
byte[] clientId = nettyProxyMsg.getClientId();
|
||||
String msgVisitorId = new String(visitorId);
|
||||
ChannelAttributeKeyUtils.buildClientId(channel, clientId);
|
||||
ChannelAttributeKeyUtils.buildVisitorId(channel, msgVisitorId);
|
||||
String visitorId = nettyProxyMsg.visitorId();
|
||||
String namespace = nettyProxyMsg.namespace();
|
||||
String clientId = nettyProxyMsg.clientId();
|
||||
|
||||
NettyTransferChannelContext.pushVisitor(channel, msgVisitorId);
|
||||
ChannelAttributeKeyUtils.buildClientId(channel, clientId);
|
||||
ChannelAttributeKeyUtils.buildVisitorId(channel, visitorId);
|
||||
|
||||
NettyTransferChannelContext.pushVisitor(channel, visitorId);
|
||||
NettyByteBuf nettyByteBuf = new NettyByteBuf();
|
||||
nettyByteBuf.setData(data);
|
||||
ChannelAttributeKeyUtils.buildNettyByteBufData(channel, nettyByteBuf);
|
||||
// 获取客户端心跳通道
|
||||
Channel loadBalance = ChannelContext.getLoadBalance(clientId);
|
||||
Channel loadBalance = ChannelContext.getLoadBalance(namespace,clientId);
|
||||
|
||||
NettyProxyMsg clientConnectTagetNettyProxyMsg = new NettyProxyMsg();
|
||||
clientConnectTagetNettyProxyMsg.setVisitorId(msgVisitorId);
|
||||
clientConnectTagetNettyProxyMsg.setClientTargetIp(targetIpString);
|
||||
clientConnectTagetNettyProxyMsg.setClientTargetPort(Integer.parseInt(targetPortString));
|
||||
clientConnectTagetNettyProxyMsg.setVisitorId(visitorId);
|
||||
clientConnectTagetNettyProxyMsg.setClientTargetIp(targetIp);
|
||||
clientConnectTagetNettyProxyMsg.setClientTargetPort(Integer.parseInt(targetPort));
|
||||
clientConnectTagetNettyProxyMsg.setClientId(clientId);
|
||||
clientConnectTagetNettyProxyMsg.setType(ProxyMessageType.HTTP_DISTRIBUTE_SERVER_PROXY_CLIENT_CONNECTION_SUCCESSFUL_);
|
||||
if (loadBalance != null) {
|
||||
// 让客户端主动创建一个数据传输通道
|
||||
loadBalance.writeAndFlush(clientConnectTagetNettyProxyMsg);
|
||||
}else {
|
||||
log.error("can not find target client:【】 nettyChannelContext",clientId);
|
||||
log.error("can not find target client:【{}】 nettyChannelContext",clientId);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,13 +1,7 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.server.netty.proxy.socks.advanced;
|
||||
|
||||
|
||||
import io.netty.bootstrap.Bootstrap;
|
||||
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 io.netty.channel.Channel;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.ChannelContext;
|
||||
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.proxy.socks.server.AbstractHandleSocksReportClientProxyClientConnectionTransferTypeAdvanced;
|
||||
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.server.netty.proxy.socks.handler.NettySocksClientProxyServerRealHandler;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.context.annotation.Role;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.wu.framework.core.utils.ObjectUtils;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
|
||||
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
|
||||
@Slf4j
|
||||
@ -44,11 +33,12 @@ public class ServerHandleSocksReportClientProxyClientConnectTransferTypeAdvanced
|
||||
public void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg nettyProxyMsg) {
|
||||
Channel transferChannel = nettyChannelContext.channel();
|
||||
|
||||
String host = nettyProxyMsg.getTargetIpString();
|
||||
Integer port = Integer.parseInt(nettyProxyMsg.getTargetPortString());
|
||||
String namespace = nettyProxyMsg.namespace();
|
||||
String host = nettyProxyMsg.targetIp();
|
||||
Integer port = Integer.parseInt(nettyProxyMsg.targetPort());
|
||||
byte[] data = nettyProxyMsg.getData();
|
||||
byte[] visitorId = nettyProxyMsg.getVisitorId();
|
||||
byte[] targetClientId = nettyProxyMsg.getClientId();
|
||||
String targetClientId = nettyProxyMsg.clientId();
|
||||
String msgVisitorId = new String(visitorId);
|
||||
ChannelAttributeKeyUtils.buildClientId(transferChannel, targetClientId);
|
||||
ChannelAttributeKeyUtils.buildVisitorId(transferChannel, msgVisitorId);
|
||||
@ -58,7 +48,7 @@ public class ServerHandleSocksReportClientProxyClientConnectTransferTypeAdvanced
|
||||
NettyTransferChannelContext.pushVisitor(transferChannel, msgVisitorId);
|
||||
|
||||
// 客户端连接客户端传输通道
|
||||
Channel loadBalance = ChannelContext.getLoadBalance(targetClientId);
|
||||
Channel loadBalance = ChannelContext.getLoadBalance(namespace, targetClientId);
|
||||
if(ObjectUtils.isNotEmpty(loadBalance)) {
|
||||
// 下发创建新链接指令
|
||||
NettyProxyMsg otherClientConnectServer = new NettyProxyMsg();
|
||||
|
@ -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.Socks5CommandStatus;
|
||||
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.adapter.ChannelTypeAdapter;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
|
||||
@ -49,8 +48,8 @@ public class ServerHandleSocksReportClientProxyServerConnectTransferTypeAdvanced
|
||||
Channel transferChannel = nettyChannelContext.channel();
|
||||
|
||||
|
||||
String host = nettyProxyMsg.getTargetIpString();
|
||||
Integer port = Integer.parseInt(nettyProxyMsg.getTargetPortString());
|
||||
String host = nettyProxyMsg.targetIp();
|
||||
Integer port = Integer.parseInt(nettyProxyMsg.targetPort());
|
||||
byte[] data = nettyProxyMsg.getData();
|
||||
byte[] visitorId = nettyProxyMsg.getVisitorId();
|
||||
byte[] clientId = nettyProxyMsg.getClientId();
|
||||
|
@ -1,7 +1,7 @@
|
||||
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 lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.ChannelContext;
|
||||
@ -35,13 +35,14 @@ public class ServerHandleSocksReportServerProxyClientTypeAdvanced
|
||||
public void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg nettyProxyMsg) {
|
||||
NettySocketChannelContext nettySocketChannelContext = (NettySocketChannelContext) nettyChannelContext;
|
||||
Channel visitorrChannel = nettySocketChannelContext.channel();
|
||||
String host = nettyProxyMsg.getTargetIpString();
|
||||
Integer port = Integer.parseInt(nettyProxyMsg.getTargetPortString());
|
||||
String namespace = nettyProxyMsg.namespace();
|
||||
String host = nettyProxyMsg.targetIp();
|
||||
Integer port = Integer.parseInt(nettyProxyMsg.targetPort());
|
||||
|
||||
|
||||
|
||||
byte[] visitorId = nettyProxyMsg.getVisitorId();
|
||||
byte[] targetClientId = nettyProxyMsg.getClientId();
|
||||
String targetClientId = nettyProxyMsg.clientId();
|
||||
Socks5AddressType socks5AddressType = nettySocketChannelContext.getSocks5AddressType();
|
||||
byte socks5AddressTypeByte = socks5AddressType.byteValue();
|
||||
|
||||
@ -55,7 +56,7 @@ public class ServerHandleSocksReportServerProxyClientTypeAdvanced
|
||||
NettyTransferChannelContext.pushVisitor(visitorrChannel, msgVisitorId);
|
||||
|
||||
// 客户端连接客户端传输通道
|
||||
Channel loadBalance = ChannelContext.getLoadBalance(targetClientId);
|
||||
Channel loadBalance = ChannelContext.getLoadBalance(namespace,targetClientId);
|
||||
if(ObjectUtils.isNotEmpty(loadBalance)) {
|
||||
// 下发创建新链接指令
|
||||
NettyProxyMsg otherClientConnectServer = new NettyProxyMsg();
|
||||
|
@ -50,8 +50,8 @@ public class LazyNettyClientBlacklistQueryListCommand {
|
||||
@Schema(description = "更新时间", name = "updateTime", example = "")
|
||||
private LocalDateTime updateTime;
|
||||
/**
|
||||
* 服务端ID
|
||||
* 命名空间
|
||||
*/
|
||||
@Schema(description = "服务端ID", name = "serverId", example = "")
|
||||
private String serverId;
|
||||
@Schema(description = "命名空间", name = "namespace", example = "")
|
||||
private String namespace;
|
||||
}
|
@ -50,8 +50,8 @@ public class LazyNettyClientBlacklistQueryOneCommand {
|
||||
@Schema(description = "更新时间", name = "updateTime", example = "")
|
||||
private LocalDateTime updateTime;
|
||||
/**
|
||||
* 服务端ID
|
||||
* 命名空间
|
||||
*/
|
||||
@Schema(description = "服务端ID", name = "serverId", example = "")
|
||||
private String serverId;
|
||||
@Schema(description = "命名空间", name = "namespace", example = "")
|
||||
private String namespace;
|
||||
}
|
@ -50,8 +50,8 @@ public class LazyNettyClientBlacklistRemoveCommand {
|
||||
@Schema(description = "更新时间", name = "updateTime", example = "")
|
||||
private LocalDateTime updateTime;
|
||||
/**
|
||||
* 服务端ID
|
||||
* 命名空间
|
||||
*/
|
||||
@Schema(description = "服务端ID", name = "serverId", example = "")
|
||||
private String serverId;
|
||||
@Schema(description = "命名空间", name = "namespace", example = "")
|
||||
private String namespace;
|
||||
}
|
@ -52,10 +52,11 @@ public class LazyNettyClientBlacklistStoryCommand {
|
||||
* 更新时间
|
||||
*/
|
||||
@Schema(description = "更新时间", name = "updateTime", example = "")
|
||||
private LocalDateTime updateTime; /**
|
||||
* 服务端ID
|
||||
private LocalDateTime updateTime;
|
||||
/**
|
||||
* 命名空间
|
||||
*/
|
||||
@Schema(description = "服务端ID", name = "serverId", example = "")
|
||||
private String serverId;
|
||||
@Schema(description = "命名空间", name = "namespace", example = "")
|
||||
private String namespace;
|
||||
|
||||
}
|
@ -48,10 +48,10 @@ public class LazyNettyClientBlacklistUpdateCommand {
|
||||
* 更新时间
|
||||
*/
|
||||
@Schema(description = "更新时间", name = "updateTime", example = "")
|
||||
private LocalDateTime updateTime; /**
|
||||
* 服务端ID
|
||||
private LocalDateTime updateTime;
|
||||
/**
|
||||
* 命名空间
|
||||
*/
|
||||
@Schema(description = "服务端ID", name = "serverId", example = "")
|
||||
private String serverId;
|
||||
|
||||
@Schema(description = "命名空间", name = "namespace", example = "")
|
||||
private String namespace;
|
||||
}
|
@ -73,11 +73,10 @@ public class LazyClientPermeateClientMappingQueryListCommand {
|
||||
private Integer permeateTargetPort;
|
||||
|
||||
/**
|
||||
*
|
||||
* 服务端ID
|
||||
* 命名空间
|
||||
*/
|
||||
@Schema(description ="服务端ID",name ="serverId",example = "")
|
||||
private String serverId;
|
||||
@Schema(description = "命名空间", name = "namespace", example = "")
|
||||
private String namespace;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -73,11 +73,10 @@ public class LazyClientPermeateClientMappingQueryOneCommand {
|
||||
private Integer permeateTargetPort;
|
||||
|
||||
/**
|
||||
*
|
||||
* 服务端ID
|
||||
* 命名空间
|
||||
*/
|
||||
@Schema(description ="服务端ID",name ="serverId",example = "")
|
||||
private String serverId;
|
||||
@Schema(description = "命名空间", name = "namespace", example = "")
|
||||
private String namespace;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -73,11 +73,10 @@ public class LazyClientPermeateClientMappingRemoveCommand {
|
||||
private Integer permeateTargetPort;
|
||||
|
||||
/**
|
||||
*
|
||||
* 服务端ID
|
||||
* 命名空间
|
||||
*/
|
||||
@Schema(description ="服务端ID",name ="serverId",example = "")
|
||||
private String serverId;
|
||||
@Schema(description = "命名空间", name = "namespace", example = "")
|
||||
private String namespace;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -73,11 +73,10 @@ public class LazyClientPermeateClientMappingStoryCommand {
|
||||
private Integer permeateTargetPort;
|
||||
|
||||
/**
|
||||
*
|
||||
* 服务端ID
|
||||
* 命名空间
|
||||
*/
|
||||
@Schema(description ="服务端ID",name ="serverId",example = "")
|
||||
private String serverId;
|
||||
@Schema(description = "命名空间", name = "namespace", example = "")
|
||||
private String namespace;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -73,11 +73,10 @@ public class LazyClientPermeateClientMappingUpdateCommand {
|
||||
private Integer permeateTargetPort;
|
||||
|
||||
/**
|
||||
*
|
||||
* 服务端ID
|
||||
* 命名空间
|
||||
*/
|
||||
@Schema(description ="服务端ID",name ="serverId",example = "")
|
||||
private String serverId;
|
||||
@Schema(description = "命名空间", name = "namespace", example = "")
|
||||
private String namespace;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -73,11 +73,10 @@ public class LazyClientPermeateServerMappingQueryListCommand {
|
||||
private Integer permeateTargetPort;
|
||||
|
||||
/**
|
||||
*
|
||||
* 服务端ID
|
||||
* 命名空间
|
||||
*/
|
||||
@Schema(description ="服务端ID",name ="serverId",example = "")
|
||||
private String serverId;
|
||||
@Schema(description = "命名空间", name = "namespace", example = "")
|
||||
private String namespace;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -73,11 +73,10 @@ public class LazyClientPermeateServerMappingQueryOneCommand {
|
||||
private Integer permeateTargetPort;
|
||||
|
||||
/**
|
||||
*
|
||||
* 服务端ID
|
||||
* 命名空间
|
||||
*/
|
||||
@Schema(description ="服务端ID",name ="serverId",example = "")
|
||||
private String serverId;
|
||||
@Schema(description = "命名空间", name = "namespace", example = "")
|
||||
private String namespace;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -73,11 +73,10 @@ public class LazyClientPermeateServerMappingRemoveCommand {
|
||||
private Integer permeateTargetPort;
|
||||
|
||||
/**
|
||||
*
|
||||
* 服务端ID
|
||||
* 命名空间
|
||||
*/
|
||||
@Schema(description ="服务端ID",name ="serverId",example = "")
|
||||
private String serverId;
|
||||
@Schema(description = "命名空间", name = "namespace", example = "")
|
||||
private String namespace;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -73,11 +73,10 @@ public class LazyClientPermeateServerMappingStoryCommand {
|
||||
private Integer permeateTargetPort;
|
||||
|
||||
/**
|
||||
*
|
||||
* 服务端ID
|
||||
* 命名空间
|
||||
*/
|
||||
@Schema(description ="服务端ID",name ="serverId",example = "")
|
||||
private String serverId;
|
||||
@Schema(description = "命名空间", name = "namespace", example = "")
|
||||
private String namespace;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -73,11 +73,10 @@ public class LazyClientPermeateServerMappingUpdateCommand {
|
||||
private Integer permeateTargetPort;
|
||||
|
||||
/**
|
||||
*
|
||||
* 服务端ID
|
||||
* 命名空间
|
||||
*/
|
||||
@Schema(description ="服务端ID",name ="serverId",example = "")
|
||||
private String serverId;
|
||||
@Schema(description = "命名空间", name = "namespace", example = "")
|
||||
private String namespace;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -46,10 +46,10 @@ public class LazyNettyClientLoginCommand {
|
||||
private String stagingState;
|
||||
|
||||
/**
|
||||
* 服务端ID
|
||||
* 命名空间
|
||||
*/
|
||||
@Schema(description = "服务端ID", name = "serverId", example = "")
|
||||
private String serverId;
|
||||
@Schema(description = "命名空间", name = "namespace", example = "")
|
||||
private String namespace;
|
||||
|
||||
/**
|
||||
* 令牌key
|
||||
|
@ -31,9 +31,9 @@ public class LazyNettyClientMessageCommand {
|
||||
@Schema(description = "发送的消息", name = "message", example = "")
|
||||
private String message;
|
||||
/**
|
||||
* 服务端ID
|
||||
* 命名空间
|
||||
*/
|
||||
@Schema(description = "服务端ID", name = "serverId", example = "")
|
||||
private String serverId;
|
||||
@Schema(description = "命名空间", name = "namespace", example = "")
|
||||
private String namespace;
|
||||
|
||||
}
|
@ -66,10 +66,11 @@ public class LazyNettyClientStateQueryListCommand {
|
||||
* 描述
|
||||
*/
|
||||
@Schema(description = "描述", name = "describe", example = "")
|
||||
private String describe; /**
|
||||
* 服务端ID
|
||||
private String describe;
|
||||
/**
|
||||
* 命名空间
|
||||
*/
|
||||
@Schema(description = "服务端ID", name = "serverId", example = "")
|
||||
private String serverId;
|
||||
@Schema(description = "命名空间", name = "namespace", example = "")
|
||||
private String namespace;
|
||||
|
||||
}
|
@ -67,9 +67,10 @@ public class LazyNettyClientStateQueryOneCommand {
|
||||
* 描述
|
||||
*/
|
||||
@Schema(description = "描述", name = "describe", example = "")
|
||||
private String describe; /**
|
||||
* 服务端ID
|
||||
private String describe;
|
||||
/**
|
||||
* 命名空间
|
||||
*/
|
||||
@Schema(description = "服务端ID", name = "serverId", example = "")
|
||||
private String serverId;
|
||||
@Schema(description = "命名空间", name = "namespace", example = "")
|
||||
private String namespace;
|
||||
}
|
@ -61,10 +61,11 @@ public class LazyNettyClientStateRemoveCommand {
|
||||
* 修改时间
|
||||
*/
|
||||
@Schema(description = "修改时间", name = "updateTime", example = "")
|
||||
private LocalDateTime updateTime; /**
|
||||
* 服务端ID
|
||||
private LocalDateTime updateTime;
|
||||
/**
|
||||
* 命名空间
|
||||
*/
|
||||
@Schema(description = "服务端ID", name = "serverId", example = "")
|
||||
private String serverId;
|
||||
@Schema(description = "命名空间", name = "namespace", example = "")
|
||||
private String namespace;
|
||||
|
||||
}
|
@ -66,10 +66,10 @@ public class LazyNettyClientStateStoryCommand {
|
||||
* 描述
|
||||
*/
|
||||
@Schema(description = "描述", name = "describe", example = "")
|
||||
private String describe; /**
|
||||
* 服务端ID
|
||||
private String describe;
|
||||
/**
|
||||
* 命名空间
|
||||
*/
|
||||
@Schema(description = "服务端ID", name = "serverId", example = "")
|
||||
private String serverId;
|
||||
|
||||
@Schema(description = "命名空间", name = "namespace", example = "")
|
||||
private String namespace;
|
||||
}
|
@ -66,9 +66,10 @@ public class LazyNettyClientStateUpdateCommand {
|
||||
* 描述
|
||||
*/
|
||||
@Schema(description = "描述", name = "describe", example = "")
|
||||
private String describe; /**
|
||||
* 服务端ID
|
||||
private String describe;
|
||||
/**
|
||||
* 命名空间
|
||||
*/
|
||||
@Schema(description = "服务端ID", name = "serverId", example = "")
|
||||
private String serverId;
|
||||
@Schema(description = "命名空间", name = "namespace", example = "")
|
||||
private String namespace;
|
||||
}
|
@ -50,11 +50,10 @@ public class LazyNettyClientStateRecordQueryListCommand {
|
||||
private NettyClientStatus onLineState;
|
||||
|
||||
/**
|
||||
*
|
||||
* 服务端ID
|
||||
* 命名空间
|
||||
*/
|
||||
@Schema(description ="服务端ID",name ="serverId",example = "")
|
||||
private String serverId;
|
||||
@Schema(description = "命名空间", name = "namespace", example = "")
|
||||
private String namespace;
|
||||
|
||||
/**
|
||||
*
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user