diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/proxy/handler/ProxyMessageAuthHandler.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/proxy/handler/ProxyMessageAuthHandler.java index 6055ee10..5316e227 100644 --- a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/proxy/handler/ProxyMessageAuthHandler.java +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/proxy/handler/ProxyMessageAuthHandler.java @@ -33,7 +33,9 @@ import fun.asgc.neutrino.proxy.core.*; import fun.asgc.neutrino.proxy.server.base.proxy.ProxyConfig; import fun.asgc.neutrino.proxy.server.constant.ClientConnectTypeEnum; import fun.asgc.neutrino.proxy.server.constant.EnableStatusEnum; +import fun.asgc.neutrino.proxy.server.constant.OnlineStatusEnum; import fun.asgc.neutrino.proxy.server.constant.SuccessCodeEnum; +import fun.asgc.neutrino.proxy.server.dal.LicenseMapper; import fun.asgc.neutrino.proxy.server.dal.entity.ClientConnectRecordDO; import fun.asgc.neutrino.proxy.server.dal.entity.LicenseDO; import fun.asgc.neutrino.proxy.server.dal.entity.PortMappingDO; @@ -86,6 +88,8 @@ public class ProxyMessageAuthHandler implements ProxyMessageHandler { private FlowReportService flowReportService; @Autowired private ClientConnectRecordService clientConnectRecordService; + @Autowired + private LicenseMapper licenseMapper; @Override public void handle(ChannelHandlerContext ctx, ProxyMessage proxyMessage) { @@ -167,15 +171,16 @@ public class ProxyMessageAuthHandler implements ProxyMessageHandler { .setCode(SuccessCodeEnum.SUCCESS.getCode()) .setCreateTime(now)); + // 更新license在线状态 + licenseMapper.updateOnlineStatus(licenseDO.getId(), OnlineStatusEnum.ONLINE.getStatus(), now); + List portMappingList = portMappingService.findEnableListByLicenseId(licenseDO.getId()); // 没有端口映射仍然保持连接 - if (!CollectionUtil.isEmpty(portMappingList)) { - ProxyUtil.initProxyInfo(licenseDO.getId(), ProxyMapping.buildList(portMappingList)); + ProxyUtil.initProxyInfo(licenseDO.getId(), ProxyMapping.buildList(portMappingList)); - ProxyUtil.addCmdChannel(licenseDO.getId(), ctx.channel(), portMappingList.stream().map(PortMappingDO::getServerPort).collect(Collectors.toSet())); + ProxyUtil.addCmdChannel(licenseDO.getId(), ctx.channel(), portMappingList.stream().map(PortMappingDO::getServerPort).collect(Collectors.toSet())); - startUserPortServer(ProxyUtil.getAttachInfo(ctx.channel()), portMappingList); - } + startUserPortServer(ProxyUtil.getAttachInfo(ctx.channel()), portMappingList); } @Override @@ -184,6 +189,9 @@ public class ProxyMessageAuthHandler implements ProxyMessageHandler { } private void startUserPortServer(CmdChannelAttachInfo cmdChannelAttachInfo, List portMappingList) { + if (CollectionUtil.isEmpty(portMappingList)) { + return; + } ServerBootstrap bootstrap = new ServerBootstrap(); bootstrap.group(serverBossGroup, serverWorkerGroup) .channel(NioServerSocketChannel.class).childHandler(new ChannelInitializer() { 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 531f2dad..b29c8468 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 @@ -72,9 +72,11 @@ public class ProxyUtil { */ public static void initProxyInfo(Integer licenseId, List proxyMappingList) { licenseToServerPortMap.put(licenseId, new HashSet<>()); - for (ProxyMapping proxyMapping : proxyMappingList) { - licenseToServerPortMap.get(licenseId).add(proxyMapping.getServerPort()); - proxyInfoMap.put(proxyMapping.getServerPort(), proxyMapping.getLanInfo()); + if (!CollectionUtil.isEmpty(proxyMappingList)) { + for (ProxyMapping proxyMapping : proxyMappingList) { + licenseToServerPortMap.get(licenseId).add(proxyMapping.getServerPort()); + proxyInfoMap.put(proxyMapping.getServerPort(), proxyMapping.getLanInfo()); + } } } @@ -103,12 +105,10 @@ public class ProxyUtil { * @param serverPorts 服务端端口集合 */ public static void addCmdChannel(Integer licenseId, Channel cmdChannel, Set serverPorts) { - if (CollectionUtil.isEmpty(serverPorts)) { - return; - } - - for (int port : serverPorts) { - serverPortToCmdChannelMap.put(port, cmdChannel); + if (!CollectionUtil.isEmpty(serverPorts)) { + for (int port : serverPorts) { + serverPortToCmdChannelMap.put(port, cmdChannel); + } } setAttachInfo(cmdChannel, new CmdChannelAttachInfo()