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:
@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user