解决license下没有可用端口映射时,license对应在线状态不准确的问题
This commit is contained in:
+13
-5
@@ -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.base.proxy.ProxyConfig;
|
||||||
import fun.asgc.neutrino.proxy.server.constant.ClientConnectTypeEnum;
|
import fun.asgc.neutrino.proxy.server.constant.ClientConnectTypeEnum;
|
||||||
import fun.asgc.neutrino.proxy.server.constant.EnableStatusEnum;
|
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.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.ClientConnectRecordDO;
|
||||||
import fun.asgc.neutrino.proxy.server.dal.entity.LicenseDO;
|
import fun.asgc.neutrino.proxy.server.dal.entity.LicenseDO;
|
||||||
import fun.asgc.neutrino.proxy.server.dal.entity.PortMappingDO;
|
import fun.asgc.neutrino.proxy.server.dal.entity.PortMappingDO;
|
||||||
@@ -86,6 +88,8 @@ public class ProxyMessageAuthHandler implements ProxyMessageHandler {
|
|||||||
private FlowReportService flowReportService;
|
private FlowReportService flowReportService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private ClientConnectRecordService clientConnectRecordService;
|
private ClientConnectRecordService clientConnectRecordService;
|
||||||
|
@Autowired
|
||||||
|
private LicenseMapper licenseMapper;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(ChannelHandlerContext ctx, ProxyMessage proxyMessage) {
|
public void handle(ChannelHandlerContext ctx, ProxyMessage proxyMessage) {
|
||||||
@@ -167,15 +171,16 @@ public class ProxyMessageAuthHandler implements ProxyMessageHandler {
|
|||||||
.setCode(SuccessCodeEnum.SUCCESS.getCode())
|
.setCode(SuccessCodeEnum.SUCCESS.getCode())
|
||||||
.setCreateTime(now));
|
.setCreateTime(now));
|
||||||
|
|
||||||
|
// 更新license在线状态
|
||||||
|
licenseMapper.updateOnlineStatus(licenseDO.getId(), OnlineStatusEnum.ONLINE.getStatus(), now);
|
||||||
|
|
||||||
List<PortMappingDO> portMappingList = portMappingService.findEnableListByLicenseId(licenseDO.getId());
|
List<PortMappingDO> 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
|
@Override
|
||||||
@@ -184,6 +189,9 @@ public class ProxyMessageAuthHandler implements ProxyMessageHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void startUserPortServer(CmdChannelAttachInfo cmdChannelAttachInfo, List<PortMappingDO> portMappingList) {
|
private void startUserPortServer(CmdChannelAttachInfo cmdChannelAttachInfo, List<PortMappingDO> portMappingList) {
|
||||||
|
if (CollectionUtil.isEmpty(portMappingList)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
ServerBootstrap bootstrap = new ServerBootstrap();
|
ServerBootstrap bootstrap = new ServerBootstrap();
|
||||||
bootstrap.group(serverBossGroup, serverWorkerGroup)
|
bootstrap.group(serverBossGroup, serverWorkerGroup)
|
||||||
.channel(NioServerSocketChannel.class).childHandler(new ChannelInitializer<SocketChannel>() {
|
.channel(NioServerSocketChannel.class).childHandler(new ChannelInitializer<SocketChannel>() {
|
||||||
|
|||||||
+9
-9
@@ -72,9 +72,11 @@ public class ProxyUtil {
|
|||||||
*/
|
*/
|
||||||
public static void initProxyInfo(Integer licenseId, List<ProxyMapping> proxyMappingList) {
|
public static void initProxyInfo(Integer licenseId, List<ProxyMapping> proxyMappingList) {
|
||||||
licenseToServerPortMap.put(licenseId, new HashSet<>());
|
licenseToServerPortMap.put(licenseId, new HashSet<>());
|
||||||
for (ProxyMapping proxyMapping : proxyMappingList) {
|
if (!CollectionUtil.isEmpty(proxyMappingList)) {
|
||||||
licenseToServerPortMap.get(licenseId).add(proxyMapping.getServerPort());
|
for (ProxyMapping proxyMapping : proxyMappingList) {
|
||||||
proxyInfoMap.put(proxyMapping.getServerPort(), proxyMapping.getLanInfo());
|
licenseToServerPortMap.get(licenseId).add(proxyMapping.getServerPort());
|
||||||
|
proxyInfoMap.put(proxyMapping.getServerPort(), proxyMapping.getLanInfo());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,12 +105,10 @@ public class ProxyUtil {
|
|||||||
* @param serverPorts 服务端端口集合
|
* @param serverPorts 服务端端口集合
|
||||||
*/
|
*/
|
||||||
public static void addCmdChannel(Integer licenseId, Channel cmdChannel, Set<Integer> serverPorts) {
|
public static void addCmdChannel(Integer licenseId, Channel cmdChannel, Set<Integer> serverPorts) {
|
||||||
if (CollectionUtil.isEmpty(serverPorts)) {
|
if (!CollectionUtil.isEmpty(serverPorts)) {
|
||||||
return;
|
for (int port : serverPorts) {
|
||||||
}
|
serverPortToCmdChannelMap.put(port, cmdChannel);
|
||||||
|
}
|
||||||
for (int port : serverPorts) {
|
|
||||||
serverPortToCmdChannelMap.put(port, cmdChannel);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setAttachInfo(cmdChannel, new CmdChannelAttachInfo()
|
setAttachInfo(cmdChannel, new CmdChannelAttachInfo()
|
||||||
|
|||||||
Reference in New Issue
Block a user