mirror of
https://gitee.com/wujiawei1207537021/wu-lazy-cloud-network.git
synced 2025-06-17 19:05:07 +08:00
[fix] 通道数据添加appKey、appSecret、originalIp验证
This commit is contained in:
@ -186,10 +186,12 @@ public class LazyNettyServerPropertiesApplicationImpl implements LazyNettyServer
|
||||
String inetHost = lazyNettyServerProperties.getInetHost();
|
||||
Integer inetPort = lazyNettyServerProperties.getInetPort();
|
||||
String clientId = lazyNettyServerProperties.getClientId();
|
||||
String appKey = lazyNettyServerProperties.getAppKey();
|
||||
String appSecret = lazyNettyServerProperties.getAppSecret();
|
||||
|
||||
NettyClientSocket nettyClientSocket = new
|
||||
NettyClientSocket(inetHost, inetPort, clientId,
|
||||
NormalUsedString.DEFAULT,
|
||||
NormalUsedString.DEFAULT,appKey,appSecret,
|
||||
clientChangeEvent, handleChannelTypeAdvancedList);
|
||||
cacheNettyClientSocketMap.put(lazyNettyServerProperties, nettyClientSocket);
|
||||
|
||||
|
@ -48,7 +48,9 @@ public class ClientAutoConfiguration implements CommandLineRunner {
|
||||
String inetHost = nettyClientProperties.getInetHost();
|
||||
int inetPort = nettyClientProperties.getInetPort();
|
||||
String clientId = nettyClientProperties.getClientId();
|
||||
return new NettyClientSocket(inetHost, inetPort, clientId, NormalUsedString.DEFAULT, clientChangeEvent, handleChannelTypeAdvancedList);
|
||||
String appKey = nettyClientProperties.getAppKey();
|
||||
String appSecret = nettyClientProperties.getAppSecret();
|
||||
return new NettyClientSocket(inetHost, inetPort, clientId, NormalUsedString.DEFAULT, appKey,appSecret,clientChangeEvent, handleChannelTypeAdvancedList);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -62,9 +64,11 @@ public class ClientAutoConfiguration implements CommandLineRunner {
|
||||
String inetHost = nettyClientProperties.getInetHost();
|
||||
int inetPort = nettyClientProperties.getInetPort();
|
||||
String clientId = nettyClientProperties.getClientId();
|
||||
String appKey = nettyClientProperties.getAppKey();
|
||||
String appSecret = nettyClientProperties.getAppSecret();
|
||||
NettyClientSocket nettyClientSocket = new NettyClientSocket(
|
||||
inetHost, inetPort,
|
||||
clientId, NormalUsedString.DEFAULT,
|
||||
clientId, NormalUsedString.DEFAULT,appKey,appSecret,
|
||||
clientChangeEvent, handleChannelTypeAdvancedList);
|
||||
Thread thread = new Thread(() -> {
|
||||
try {
|
||||
|
@ -127,6 +127,7 @@ public class NettyClientPermeateClientVisitorHandler extends SimpleChannelInbou
|
||||
|
||||
@Override
|
||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
|
||||
cause.printStackTrace();
|
||||
log.error("exceptionCaught");
|
||||
}
|
||||
}
|
@ -7,8 +7,8 @@ import io.netty.channel.nio.NioEventLoopGroup;
|
||||
import io.netty.channel.socket.nio.NioSocketChannel;
|
||||
import lombok.Getter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.filter.NettyClientFilter;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.event.ClientChangeEvent;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.filter.NettyClientFilter;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.MessageType;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyServerContext;
|
||||
@ -16,6 +16,7 @@ import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelTypeAdap
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@ -43,6 +44,8 @@ public class NettyClientSocket {
|
||||
* 当前连接的服务端ID
|
||||
*/
|
||||
private final String serverId;
|
||||
private final String appKey;
|
||||
private final String appSecret;
|
||||
/**
|
||||
* 客户端状态变更事件
|
||||
*/
|
||||
@ -50,11 +53,20 @@ public class NettyClientSocket {
|
||||
private final ClientChangeEvent clientChangeEvent;
|
||||
private final List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList; // 处理服务端发送过来的数据类型
|
||||
|
||||
public NettyClientSocket(String inetHost, int inetPort, String clientId, String serverId, ClientChangeEvent clientChangeEvent, List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList) {
|
||||
public NettyClientSocket(String inetHost,
|
||||
int inetPort,
|
||||
String clientId,
|
||||
String serverId,
|
||||
String appKey,
|
||||
String appSecret,
|
||||
ClientChangeEvent clientChangeEvent,
|
||||
List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList) {
|
||||
this.inetHost = inetHost;
|
||||
this.inetPort = inetPort;
|
||||
this.clientId = clientId;
|
||||
this.serverId = serverId;
|
||||
this.appKey = appKey;
|
||||
this.appSecret = appSecret;
|
||||
this.clientChangeEvent = clientChangeEvent;
|
||||
this.handleChannelTypeAdvancedList = handleChannelTypeAdvancedList;
|
||||
}
|
||||
@ -78,7 +90,6 @@ public class NettyClientSocket {
|
||||
.option(ChannelOption.WRITE_BUFFER_WATER_MARK, new WriteBufferWaterMark(1024 * 1024, 1024 * 1024 * 2))
|
||||
.handler(new NettyClientFilter(new ChannelTypeAdapter(handleChannelTypeAdvancedList), this))
|
||||
;
|
||||
|
||||
log.info("use clientId:{} connect to server IP:{},server port :{}", clientId, inetHost, inetPort);
|
||||
ChannelFuture future = bootstrap.connect(inetHost, inetPort);
|
||||
// 客户端连接服务端的channel
|
||||
@ -92,7 +103,11 @@ public class NettyClientSocket {
|
||||
NettyProxyMsg nettyMsg = new NettyProxyMsg();
|
||||
nettyMsg.setType(MessageType.REPORT_CLIENT_CONNECT_SUCCESS);
|
||||
nettyMsg.setClientId(clientId);
|
||||
String hostAddress = InetAddress.getLocalHost().getHostAddress();
|
||||
nettyMsg.setOriginalIpString(hostAddress);
|
||||
nettyMsg.setData((clientId).getBytes());
|
||||
nettyMsg.setAppKeyString(appKey);
|
||||
nettyMsg.setAppSecretString(appSecret);
|
||||
ChannelAttributeKeyUtils.buildClientId(serviceChannel, clientId);
|
||||
serviceChannel.writeAndFlush(nettyMsg);
|
||||
|
||||
|
Reference in New Issue
Block a user