mirror of
https://gitee.com/wujiawei1207537021/wu-lazy-cloud-network.git
synced 2025-06-16 18:35:05 +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>
|
||||
|
Reference in New Issue
Block a user