From 007524ac6b2ee286300d796a93b996207034e20e Mon Sep 17 00:00:00 2001 From: aoshiguchen <1052045476@qq.com> Date: Sat, 3 Sep 2022 22:41:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=90=86=E9=80=BB=E8=BE=91=E4=BC=98?= =?UTF-8?q?=E5=8C=96.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../proxy/domain/CmdChannelAttachInfo.java | 4 +++ .../server/service/ProxyMutualService.java | 2 +- .../neutrino/proxy/server/util/ProxyUtil.java | 34 +++++++++---------- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/proxy/domain/CmdChannelAttachInfo.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/proxy/domain/CmdChannelAttachInfo.java index 18b9caa5..8a475582 100644 --- a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/proxy/domain/CmdChannelAttachInfo.java +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/proxy/domain/CmdChannelAttachInfo.java @@ -52,4 +52,8 @@ public class CmdChannelAttachInfo { * licenseKey */ private String licenseKey; + /** + * ip + */ + private String ip; } diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/service/ProxyMutualService.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/service/ProxyMutualService.java index 6bb644c9..69631f05 100644 --- a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/service/ProxyMutualService.java +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/service/ProxyMutualService.java @@ -43,7 +43,7 @@ public class ProxyMutualService { */ public void bindServerPort(CmdChannelAttachInfo attachInfo, Integer serverPort) { // TODO - log.info("绑定服务端端口 licenseId:{},ip:{},lanInfo:{},serverPort:{}", attachInfo.getLicenseId(), attachInfo.getIp(), attachInfo.getClientLanInfo(), serverPort); + log.info("绑定服务端端口 licenseKey:{},ip:{},lanInfo:{},serverPort:{}", attachInfo.getLicenseKey(), attachInfo.getIp(), attachInfo.getClientLanInfo(), serverPort); } } diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/util/ProxyUtil.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/util/ProxyUtil.java index 869b3131..30d22b55 100644 --- a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/util/ProxyUtil.java +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/util/ProxyUtil.java @@ -46,7 +46,7 @@ public class ProxyUtil { /** * license -> 服务端口映射 */ - private static final Map> licenseToServerPortMap = new HashMap<>(); + private static final Map> licenseToServerPortMap = new HashMap<>(); /** * 代理信息映射 */ @@ -58,7 +58,7 @@ public class ProxyUtil { /** * license -> 指令通道映射 */ - private static Map licenseToCmdChannelMap = new ConcurrentHashMap<>(); + private static Map licenseToCmdChannelMap = new ConcurrentHashMap<>(); /** * cmdChannelAttachInfo.getUserChannelMap() 读写锁 @@ -67,24 +67,24 @@ public class ProxyUtil { /** * 初始化代理信息 - * @param licenseId 客户端licenseId + * @param licenseKey licenseKey * @param proxyMappingList 代理映射集合 */ - public static void initProxyInfo(Integer licenseId, List proxyMappingList) { - licenseToServerPortMap.put(licenseId, new HashSet<>()); + public static void initProxyInfo(String licenseKey, List proxyMappingList) { + licenseToServerPortMap.put(licenseKey, new HashSet<>()); for (ProxyMapping proxyMapping : proxyMappingList) { - licenseToServerPortMap.get(licenseId).add(proxyMapping.getServerPort()); + licenseToServerPortMap.get(licenseKey).add(proxyMapping.getServerPort()); proxyInfoMap.put(proxyMapping.getServerPort(), proxyMapping.getLanInfo()); } } /** * 根据licenseKey获取服务端端口集合 - * @param licenseId licenseId + * @param licenseKey licenseKey * @return 服务端端口集合 */ - public static Set getServerPortsByLicenseKey(Integer licenseId) { - return licenseToServerPortMap.get(licenseId); + public static Set getServerPortsByLicenseKey(String licenseKey) { + return licenseToServerPortMap.get(licenseKey); } /** @@ -98,11 +98,11 @@ public class ProxyUtil { /** * 添加指令通道相关缓存信息 - * @param licenseId licenseId + * @param licenseKey licenseKey * @param cmdChannel 指令通道 * @param serverPorts 服务端端口集合 */ - public static void addCmdChannel(Integer licenseId, Channel cmdChannel, Set serverPorts) { + public static void addCmdChannel(String licenseKey, Channel cmdChannel, Set serverPorts) { if (CollectionUtil.isEmpty(serverPorts)) { return; } @@ -114,9 +114,9 @@ public class ProxyUtil { setAttachInfo(cmdChannel, new CmdChannelAttachInfo() .setIp(ChannelUtil.getIP(cmdChannel)) .setServerPorts(serverPorts) - .setLicenseId(licenseId) + .setLicenseKey(licenseKey) .setUserChannelMap(new HashMap<>(16))); - licenseToCmdChannelMap.put(licenseId, cmdChannel); + licenseToCmdChannelMap.put(licenseKey, cmdChannel); } /** @@ -129,9 +129,9 @@ public class ProxyUtil { } CmdChannelAttachInfo cmdChannelAttachInfo = getAttachInfo(cmdChannel); - Channel channel0 = licenseToCmdChannelMap.remove(cmdChannelAttachInfo.getLicenseId()); + Channel channel0 = licenseToCmdChannelMap.remove(cmdChannelAttachInfo.getLicenseKey()); if (cmdChannel != channel0) { - licenseToCmdChannelMap.put(cmdChannelAttachInfo.getLicenseId(), cmdChannel); + licenseToCmdChannelMap.put(cmdChannelAttachInfo.getLicenseKey(), cmdChannel); } for (int port : cmdChannelAttachInfo.getServerPorts()) { @@ -164,8 +164,8 @@ public class ProxyUtil { return serverPortToCmdChannelMap.get(serverPort); } - public static Channel getCmdChannelByLicenseId(Integer licenseId) { - return licenseToCmdChannelMap.get(licenseId); + public static Channel getCmdChannelByLicenseKey(String licenseKey) { + return licenseToCmdChannelMap.get(licenseKey); } /**