diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/base/rest/ServiceException.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/base/rest/ServiceException.java index fd00c6b7..e416ab4b 100644 --- a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/base/rest/ServiceException.java +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/base/rest/ServiceException.java @@ -21,7 +21,7 @@ */ package fun.asgc.neutrino.proxy.server.base.rest; -import fun.asgc.neutrino.proxy.server.base.rest.constant.ExceptionConstant; +import fun.asgc.neutrino.proxy.server.constant.ExceptionConstant; import lombok.Getter; import org.apache.commons.lang3.StringUtils; diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/base/rest/interceptor/BaseAuthInterceptor.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/base/rest/interceptor/BaseAuthInterceptor.java index 59bba426..acb9688e 100644 --- a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/base/rest/interceptor/BaseAuthInterceptor.java +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/base/rest/interceptor/BaseAuthInterceptor.java @@ -29,8 +29,8 @@ import fun.asgc.neutrino.core.web.context.HttpResponseWrapper; import fun.asgc.neutrino.core.web.interceptor.HandlerInterceptor; import fun.asgc.neutrino.proxy.server.base.rest.*; import fun.asgc.neutrino.proxy.server.base.rest.annotation.OnlyAdmin; -import fun.asgc.neutrino.proxy.server.base.rest.constant.EnableStatusEnum; -import fun.asgc.neutrino.proxy.server.base.rest.constant.ExceptionConstant; +import fun.asgc.neutrino.proxy.server.constant.EnableStatusEnum; +import fun.asgc.neutrino.proxy.server.constant.ExceptionConstant; import fun.asgc.neutrino.proxy.server.dal.entity.UserDO; import fun.asgc.neutrino.proxy.server.service.UserService; import fun.asgc.neutrino.proxy.server.util.HttpUtil; diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/base/rest/interceptor/GlobalExceptionHandler.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/base/rest/interceptor/GlobalExceptionHandler.java index 349db089..11e1545d 100644 --- a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/base/rest/interceptor/GlobalExceptionHandler.java +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/base/rest/interceptor/GlobalExceptionHandler.java @@ -24,7 +24,7 @@ package fun.asgc.neutrino.proxy.server.base.rest.interceptor; import fun.asgc.neutrino.core.web.context.HttpRequestWrapper; import fun.asgc.neutrino.core.web.context.HttpResponseWrapper; import fun.asgc.neutrino.core.web.interceptor.RestControllerExceptionHandler; -import fun.asgc.neutrino.proxy.server.base.rest.constant.ExceptionConstant; +import fun.asgc.neutrino.proxy.server.constant.ExceptionConstant; import fun.asgc.neutrino.proxy.server.base.rest.ResponseBody; import fun.asgc.neutrino.proxy.server.base.rest.ServiceException; import org.apache.commons.lang3.exception.ExceptionUtils; diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/constant/ConnectTypeEnum.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/constant/ConnectTypeEnum.java new file mode 100644 index 00000000..85ff12f7 --- /dev/null +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/constant/ConnectTypeEnum.java @@ -0,0 +1,39 @@ +/** + * Copyright (c) 2022 aoshiguchen + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package fun.asgc.neutrino.proxy.server.constant; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * + * @author: aoshiguchen + * @date: 2022/8/31 + */ +@Getter +@AllArgsConstructor +public enum ConnectTypeEnum { + CONNECT(1, "连接"), + DISCONNECT(2, "端开连接"); + private Integer type; + private String desc; +} diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/base/rest/constant/EnableStatusEnum.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/constant/EnableStatusEnum.java similarity index 95% rename from neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/base/rest/constant/EnableStatusEnum.java rename to neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/constant/EnableStatusEnum.java index e20fef02..e31229ce 100644 --- a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/base/rest/constant/EnableStatusEnum.java +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/constant/EnableStatusEnum.java @@ -19,7 +19,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package fun.asgc.neutrino.proxy.server.base.rest.constant; +package fun.asgc.neutrino.proxy.server.constant; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/base/rest/constant/ExceptionConstant.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/constant/ExceptionConstant.java similarity index 97% rename from neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/base/rest/constant/ExceptionConstant.java rename to neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/constant/ExceptionConstant.java index d53a275c..aff60d9a 100644 --- a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/base/rest/constant/ExceptionConstant.java +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/constant/ExceptionConstant.java @@ -19,7 +19,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package fun.asgc.neutrino.proxy.server.base.rest.constant; +package fun.asgc.neutrino.proxy.server.constant; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/base/rest/constant/OnlineStatusEnum.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/constant/OnlineStatusEnum.java similarity index 95% rename from neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/base/rest/constant/OnlineStatusEnum.java rename to neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/constant/OnlineStatusEnum.java index a8f1e6ef..ed7383ba 100644 --- a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/base/rest/constant/OnlineStatusEnum.java +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/constant/OnlineStatusEnum.java @@ -19,7 +19,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package fun.asgc.neutrino.proxy.server.base.rest.constant; +package fun.asgc.neutrino.proxy.server.constant; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/req/LicenseUpdateEnableStatusReq.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/req/LicenseUpdateEnableStatusReq.java index 70ae03e4..e1a3ba5a 100644 --- a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/req/LicenseUpdateEnableStatusReq.java +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/req/LicenseUpdateEnableStatusReq.java @@ -36,7 +36,7 @@ public class LicenseUpdateEnableStatusReq { private Integer id; /** * 启用状态 - * {@link fun.asgc.neutrino.proxy.server.base.rest.constant.EnableStatusEnum} + * {@link fun.asgc.neutrino.proxy.server.constant.EnableStatusEnum} */ private Integer enable; } diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/res/LicenseDetailRes.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/res/LicenseDetailRes.java index b565ee56..5b2ee9bc 100644 --- a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/res/LicenseDetailRes.java +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/res/LicenseDetailRes.java @@ -21,7 +21,7 @@ */ package fun.asgc.neutrino.proxy.server.controller.res; -import fun.asgc.neutrino.proxy.server.base.rest.constant.OnlineStatusEnum; +import fun.asgc.neutrino.proxy.server.constant.OnlineStatusEnum; import lombok.Data; import lombok.experimental.Accessors; @@ -59,7 +59,7 @@ public class LicenseDetailRes { private Integer isOnline; /** * 启用状态 - * {@link fun.asgc.neutrino.proxy.server.base.rest.constant.EnableStatusEnum} + * {@link fun.asgc.neutrino.proxy.server.constant.EnableStatusEnum} */ private Integer enable; /** diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/res/LicenseListRes.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/res/LicenseListRes.java index 3af4bd14..2bbd506f 100644 --- a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/res/LicenseListRes.java +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/res/LicenseListRes.java @@ -22,7 +22,7 @@ package fun.asgc.neutrino.proxy.server.controller.res; import fun.asgc.neutrino.core.db.annotation.Id; -import fun.asgc.neutrino.proxy.server.base.rest.constant.OnlineStatusEnum; +import fun.asgc.neutrino.proxy.server.constant.OnlineStatusEnum; import lombok.Data; import lombok.experimental.Accessors; @@ -61,7 +61,7 @@ public class LicenseListRes { private Integer isOnline; /** * 启用状态 - * {@link fun.asgc.neutrino.proxy.server.base.rest.constant.EnableStatusEnum} + * {@link fun.asgc.neutrino.proxy.server.constant.EnableStatusEnum} */ private Integer enable; /** diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/res/PortMappingDetailRes.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/res/PortMappingDetailRes.java index 9dcb8826..9826b26a 100644 --- a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/res/PortMappingDetailRes.java +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/res/PortMappingDetailRes.java @@ -22,7 +22,7 @@ package fun.asgc.neutrino.proxy.server.controller.res; import fun.asgc.neutrino.core.db.annotation.Id; -import fun.asgc.neutrino.proxy.server.base.rest.constant.OnlineStatusEnum; +import fun.asgc.neutrino.proxy.server.constant.OnlineStatusEnum; import lombok.Data; import lombok.experimental.Accessors; @@ -73,7 +73,7 @@ public class PortMappingDetailRes { private Integer isOnline; /** * 启用状态 - * {@link fun.asgc.neutrino.proxy.server.base.rest.constant.EnableStatusEnum} + * {@link fun.asgc.neutrino.proxy.server.constant.EnableStatusEnum} */ private Integer enable; /** diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/res/PortMappingListRes.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/res/PortMappingListRes.java index e948a17e..9775668b 100644 --- a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/res/PortMappingListRes.java +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/res/PortMappingListRes.java @@ -21,7 +21,7 @@ */ package fun.asgc.neutrino.proxy.server.controller.res; -import fun.asgc.neutrino.proxy.server.base.rest.constant.OnlineStatusEnum; +import fun.asgc.neutrino.proxy.server.constant.OnlineStatusEnum; import lombok.Data; import java.util.Date; @@ -69,7 +69,7 @@ public class PortMappingListRes { private Integer isOnline; /** * 启用状态 - * {@link fun.asgc.neutrino.proxy.server.base.rest.constant.EnableStatusEnum} + * {@link fun.asgc.neutrino.proxy.server.constant.EnableStatusEnum} */ private Integer enable; /** diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/UserConnectRecordMapper.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/UserConnectRecordMapper.java new file mode 100644 index 00000000..649c26c5 --- /dev/null +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/UserConnectRecordMapper.java @@ -0,0 +1,35 @@ +/** + * Copyright (c) 2022 aoshiguchen + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package fun.asgc.neutrino.proxy.server.dal; + +import fun.asgc.neutrino.core.annotation.Component; +import fun.asgc.neutrino.core.db.mapper.SqlMapper; + +/** + * + * @author: aoshiguchen + * @date: 2022/8/31 + */ +@Component +public interface UserConnectRecordMapper extends SqlMapper { + +} diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/entity/LicenseDO.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/entity/LicenseDO.java index ed870d79..46aa9f1f 100644 --- a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/entity/LicenseDO.java +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/entity/LicenseDO.java @@ -23,7 +23,7 @@ package fun.asgc.neutrino.proxy.server.dal.entity; import fun.asgc.neutrino.core.db.annotation.Id; import fun.asgc.neutrino.core.db.annotation.Table; -import fun.asgc.neutrino.proxy.server.base.rest.constant.OnlineStatusEnum; +import fun.asgc.neutrino.proxy.server.constant.OnlineStatusEnum; import lombok.Data; import lombok.ToString; import lombok.experimental.Accessors; @@ -61,7 +61,7 @@ public class LicenseDO { private Integer isOnline; /** * 启用状态 - * {@link fun.asgc.neutrino.proxy.server.base.rest.constant.EnableStatusEnum} + * {@link fun.asgc.neutrino.proxy.server.constant.EnableStatusEnum} */ private Integer enable; /** diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/entity/PortMappingDO.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/entity/PortMappingDO.java index 441af6d6..805fcc2d 100644 --- a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/entity/PortMappingDO.java +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/entity/PortMappingDO.java @@ -23,7 +23,7 @@ package fun.asgc.neutrino.proxy.server.dal.entity; import fun.asgc.neutrino.core.db.annotation.Id; import fun.asgc.neutrino.core.db.annotation.Table; -import fun.asgc.neutrino.proxy.server.base.rest.constant.OnlineStatusEnum; +import fun.asgc.neutrino.proxy.server.constant.OnlineStatusEnum; import lombok.Data; import lombok.ToString; import lombok.experimental.Accessors; @@ -65,7 +65,7 @@ public class PortMappingDO { private Integer isOnline; /** * 启用状态 - * {@link fun.asgc.neutrino.proxy.server.base.rest.constant.EnableStatusEnum} + * {@link fun.asgc.neutrino.proxy.server.constant.EnableStatusEnum} */ private Integer enable; /** diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/entity/UserConnectRecordDO.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/entity/UserConnectRecordDO.java new file mode 100644 index 00000000..70435504 --- /dev/null +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/entity/UserConnectRecordDO.java @@ -0,0 +1,84 @@ +/** + * Copyright (c) 2022 aoshiguchen + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package fun.asgc.neutrino.proxy.server.dal.entity; + +import fun.asgc.neutrino.core.db.annotation.Table; +import lombok.Data; +import lombok.ToString; + +import java.util.Date; + +/** + * + * @author: aoshiguchen + * @date: 2022/8/31 + */ +@ToString +@Data +@Table("user_connect_record") +public class UserConnectRecordDO { + private Integer id; + /** + * 服务端端口号 + */ + private Integer serverPort; + /** + * userIp + */ + private String userIp; + /** + * 客户端IP + */ + private String clientIp; + /** + * 客户端信息 + */ + private String clientLanInfo; + /** + * 用户ID + */ + private String userId; + /** + * licenseId + */ + private Integer licenseId; + /** + * licenseKey + */ + private String licenseKey; + /** + * writeBytes + */ + private Integer writeBytes; + /** + * readBytes + */ + private Integer readBytes; + /** + * type + */ + private Integer type; + /** + * 创建时间 + */ + private Date createTime; +} diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/proxy/core/BytesMetricsHandler.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/proxy/core/BytesMetricsHandler.java index d3a3e58a..4182d9ca 100644 --- a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/proxy/core/BytesMetricsHandler.java +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/proxy/core/BytesMetricsHandler.java @@ -51,7 +51,7 @@ public class BytesMetricsHandler extends ChannelDuplexHandler { public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { InetSocketAddress sa = (InetSocketAddress) ctx.channel().localAddress(); MetricsCollector metricsCollector = MetricsCollector.getCollector(sa.getPort()); - metricsCollector.incrementWroteBytes(((ByteBuf) msg).readableBytes()); + metricsCollector.incrementWriteBytes(((ByteBuf) msg).readableBytes()); metricsCollector.incrementWroteMsgs(1); super.write(ctx, msg, promise); } diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/proxy/core/ServerChannelHandler.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/proxy/core/ServerChannelHandler.java index 0ca45176..9a88c385 100644 --- a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/proxy/core/ServerChannelHandler.java +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/proxy/core/ServerChannelHandler.java @@ -74,11 +74,9 @@ public class ServerChannelHandler extends SimpleChannelInboundHandler { } else { byte[] bytes = new byte[buf.readableBytes()]; buf.readBytes(bytes); -// String userId = ProxyChannelManager.getUserChannelUserId(userChannel); String userId = ProxyUtil.getUserChannelUserId(userChannel); proxyChannel.writeAndFlush(ProxyMessage.buildTransferMessage(userId, bytes)); } @@ -73,7 +72,6 @@ public class UserChannelHandler extends SimpleChannelInboundHandler { public void channelActive(ChannelHandlerContext ctx) throws Exception { Channel userChannel = ctx.channel(); InetSocketAddress sa = (InetSocketAddress) userChannel.localAddress(); -// Channel cmdChannel = ProxyChannelManager.getCmdChannel(sa.getPort()); Channel cmdChannel = ProxyUtil.getCmdChannelByServerPort(sa.getPort()); if (cmdChannel == null) { @@ -84,7 +82,6 @@ public class UserChannelHandler extends SimpleChannelInboundHandler { String lanInfo = ProxyUtil.getClientLanInfoByServerPort(sa.getPort()); // 用户连接到代理服务器时,设置用户连接不可读,等待代理后端服务器连接成功后再改变为可读状态 userChannel.config().setOption(ChannelOption.AUTO_READ, false); -// ProxyChannelManager.addUserChannelToCmdChannel(cmdChannel, userId, userChannel); ProxyUtil.addUserChannelToCmdChannel(cmdChannel, userId, userChannel); cmdChannel.writeAndFlush(ProxyMessage.buildConnectMessage(userId).setData(lanInfo.getBytes())); } @@ -98,7 +95,6 @@ public class UserChannelHandler extends SimpleChannelInboundHandler { // 通知代理客户端 Channel userChannel = ctx.channel(); InetSocketAddress sa = (InetSocketAddress) userChannel.localAddress(); -// Channel cmdChannel = ProxyChannelManager.getCmdChannel(sa.getPort()); Channel cmdChannel = ProxyUtil.getCmdChannelByServerPort(sa.getPort()); if (cmdChannel == null) { @@ -108,9 +104,7 @@ public class UserChannelHandler extends SimpleChannelInboundHandler { } else { // 用户连接断开,从控制连接中移除 -// String userId = ProxyChannelManager.getUserChannelUserId(userChannel); String userId = ProxyUtil.getUserChannelUserId(userChannel); -// ProxyChannelManager.removeUserChannelFromCmdChannel(cmdChannel, userId); ProxyUtil.removeUserChannelFromCmdChannel(cmdChannel, userId); Channel proxyChannel = userChannel.attr(Constants.NEXT_CHANNEL).get(); @@ -134,11 +128,9 @@ public class UserChannelHandler extends SimpleChannelInboundHandler { // 通知代理客户端 Channel userChannel = ctx.channel(); InetSocketAddress sa = (InetSocketAddress) userChannel.localAddress(); -// Channel cmdChannel = ProxyChannelManager.getCmdChannel(sa.getPort()); Channel cmdChannel = ProxyUtil.getCmdChannelByServerPort(sa.getPort()); if (cmdChannel == null) { - // 该端口还没有代理客户端 ctx.channel().close(); } else { diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/proxy/domain/MetricsCollector.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/proxy/domain/MetricsCollector.java index 6862e06d..6b5c8c76 100644 --- a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/proxy/domain/MetricsCollector.java +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/proxy/domain/MetricsCollector.java @@ -44,7 +44,7 @@ public class MetricsCollector { private AtomicLong readBytes = new AtomicLong(); - private AtomicLong wroteBytes = new AtomicLong(); + private AtomicLong writeBytes = new AtomicLong(); private AtomicLong readMsgs = new AtomicLong(); @@ -96,7 +96,7 @@ public class MetricsCollector { metrics.setChannels(channels.get()); metrics.setPort(port); metrics.setReadBytes(readBytes.getAndSet(0)); - metrics.setWroteBytes(wroteBytes.getAndSet(0)); + metrics.setWroteBytes(writeBytes.getAndSet(0)); metrics.setTimestamp(System.currentTimeMillis()); metrics.setReadMsgs(readMsgs.getAndSet(0)); metrics.setWroteMsgs(wroteMsgs.getAndSet(0)); @@ -109,7 +109,7 @@ public class MetricsCollector { metrics.setChannels(channels.get()); metrics.setPort(port); metrics.setReadBytes(readBytes.get()); - metrics.setWroteBytes(wroteBytes.get()); + metrics.setWroteBytes(writeBytes.get()); metrics.setTimestamp(System.currentTimeMillis()); metrics.setReadMsgs(readMsgs.get()); metrics.setWroteMsgs(wroteMsgs.get()); @@ -121,8 +121,8 @@ public class MetricsCollector { readBytes.addAndGet(bytes); } - public void incrementWroteBytes(long bytes) { - wroteBytes.addAndGet(bytes); + public void incrementWriteBytes(long bytes) { + writeBytes.addAndGet(bytes); } public void incrementReadMsgs(long msgs) { 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 50e609ca..5a36b0d6 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 @@ -29,8 +29,8 @@ import fun.asgc.neutrino.core.annotation.NonIntercept; import fun.asgc.neutrino.core.util.CollectionUtil; import fun.asgc.neutrino.core.util.StringUtil; import fun.asgc.neutrino.proxy.core.*; +import fun.asgc.neutrino.proxy.server.constant.*; import fun.asgc.neutrino.proxy.server.base.proxy.ProxyConfig; -import fun.asgc.neutrino.proxy.server.base.rest.constant.EnableStatusEnum; import fun.asgc.neutrino.proxy.server.proxy.core.BytesMetricsHandler; import fun.asgc.neutrino.proxy.server.proxy.core.UserChannelHandler; import fun.asgc.neutrino.proxy.server.dal.entity.LicenseDO; diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/proxy/handler/ProxyMessageConnectHandler.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/proxy/handler/ProxyMessageConnectHandler.java index 6dd043a5..3f621814 100644 --- a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/proxy/handler/ProxyMessageConnectHandler.java +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/proxy/handler/ProxyMessageConnectHandler.java @@ -58,7 +58,6 @@ public class ProxyMessageConnectHandler implements ProxyMessageHandler { return; } -// Channel cmdChannel = ProxyChannelManager.getCmdChannel(tokens[1]); Channel cmdChannel = ProxyUtil.getCmdChannelByLicenseKey(tokens[1]); if (cmdChannel == null) { @@ -66,7 +65,6 @@ public class ProxyMessageConnectHandler implements ProxyMessageHandler { return; } -// Channel userChannel = ProxyChannelManager.getUserChannel(cmdChannel, tokens[0]); Channel userChannel = ProxyUtil.getUserChannel(cmdChannel, tokens[0]); if (userChannel != null) { ctx.channel().attr(Constants.USER_ID).set(tokens[0]); diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/proxy/handler/ProxyMessageDisconnectHandler.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/proxy/handler/ProxyMessageDisconnectHandler.java index edf93939..83703b8d 100644 --- a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/proxy/handler/ProxyMessageDisconnectHandler.java +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/proxy/handler/ProxyMessageDisconnectHandler.java @@ -53,7 +53,6 @@ public class ProxyMessageDisconnectHandler implements ProxyMessageHandler { // 代理连接没有连上服务器由控制连接发送用户端断开连接消息 if (clientKey == null) { String userId = proxyMessage.getInfo(); -// Channel userChannel = ProxyChannelManager.removeUserChannelFromCmdChannel(ctx.channel(), userId); Channel userChannel = ProxyUtil.removeUserChannelFromCmdChannel(ctx.channel(), userId); if (userChannel != null) { // 数据发送完成后再关闭连接,解决http1.0数据传输问题 @@ -62,20 +61,15 @@ public class ProxyMessageDisconnectHandler implements ProxyMessageHandler { return; } -// Channel cmdChannel = ProxyChannelManager.getCmdChannel(clientKey); Channel cmdChannel = ProxyUtil.getCmdChannelByLicenseKey(clientKey); if (cmdChannel == null) { return; } -// Channel userChannel = ProxyChannelManager.removeUserChannelFromCmdChannel(cmdChannel, ctx.channel().attr(Constants.USER_ID).get()); Channel userChannel = ProxyUtil.removeUserChannelFromCmdChannel(cmdChannel, ((UserChannelAttachInfo)ProxyUtil.getAttachInfo(ctx.channel())).getUserId()); if (userChannel != null) { // 数据发送完成后再关闭连接,解决http1.0数据传输问题 userChannel.writeAndFlush(Unpooled.EMPTY_BUFFER).addListener(ChannelFutureListener.CLOSE); -// ctx.channel().attr(Constants.NEXT_CHANNEL).remove(); -// ctx.channel().attr(Constants.CLIENT_KEY).remove(); -// ctx.channel().attr(Constants.USER_ID).remove(); } } diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/service/LicenseService.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/service/LicenseService.java index 7ef01b6c..cfa06d7d 100644 --- a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/service/LicenseService.java +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/service/LicenseService.java @@ -28,9 +28,9 @@ import fun.asgc.neutrino.core.db.page.Page; import fun.asgc.neutrino.core.db.page.PageQuery; import fun.asgc.neutrino.core.util.CollectionUtil; import fun.asgc.neutrino.proxy.server.base.rest.SystemContextHolder; -import fun.asgc.neutrino.proxy.server.base.rest.constant.EnableStatusEnum; -import fun.asgc.neutrino.proxy.server.base.rest.constant.ExceptionConstant; -import fun.asgc.neutrino.proxy.server.base.rest.constant.OnlineStatusEnum; +import fun.asgc.neutrino.proxy.server.constant.EnableStatusEnum; +import fun.asgc.neutrino.proxy.server.constant.ExceptionConstant; +import fun.asgc.neutrino.proxy.server.constant.OnlineStatusEnum; import fun.asgc.neutrino.proxy.server.controller.req.LicenseCreateReq; import fun.asgc.neutrino.proxy.server.controller.req.LicenseListReq; import fun.asgc.neutrino.proxy.server.controller.req.LicenseUpdateEnableStatusReq; diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/service/PortMappingService.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/service/PortMappingService.java index 611a5101..3c507d5d 100644 --- a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/service/PortMappingService.java +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/service/PortMappingService.java @@ -28,9 +28,9 @@ import fun.asgc.neutrino.core.db.page.Page; import fun.asgc.neutrino.core.db.page.PageQuery; import fun.asgc.neutrino.core.util.CollectionUtil; import fun.asgc.neutrino.proxy.server.base.rest.SystemContextHolder; -import fun.asgc.neutrino.proxy.server.base.rest.constant.EnableStatusEnum; -import fun.asgc.neutrino.proxy.server.base.rest.constant.ExceptionConstant; -import fun.asgc.neutrino.proxy.server.base.rest.constant.OnlineStatusEnum; +import fun.asgc.neutrino.proxy.server.constant.EnableStatusEnum; +import fun.asgc.neutrino.proxy.server.constant.ExceptionConstant; +import fun.asgc.neutrino.proxy.server.constant.OnlineStatusEnum; import fun.asgc.neutrino.proxy.server.controller.req.PortMappingCreateReq; import fun.asgc.neutrino.proxy.server.controller.req.PortMappingListReq; import fun.asgc.neutrino.proxy.server.controller.req.PortMappingUpdateEnableStatusReq; diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/service/PortPoolService.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/service/PortPoolService.java index 36a68dae..5872d56c 100644 --- a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/service/PortPoolService.java +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/service/PortPoolService.java @@ -25,12 +25,11 @@ import fun.asgc.neutrino.core.annotation.Autowired; import fun.asgc.neutrino.core.annotation.Component; import fun.asgc.neutrino.core.db.page.Page; import fun.asgc.neutrino.core.db.page.PageQuery; -import fun.asgc.neutrino.proxy.server.base.rest.constant.EnableStatusEnum; -import fun.asgc.neutrino.proxy.server.base.rest.constant.ExceptionConstant; +import fun.asgc.neutrino.proxy.server.constant.EnableStatusEnum; +import fun.asgc.neutrino.proxy.server.constant.ExceptionConstant; import fun.asgc.neutrino.proxy.server.controller.req.PortPoolCreateReq; import fun.asgc.neutrino.proxy.server.controller.req.PortPoolListReq; import fun.asgc.neutrino.proxy.server.controller.req.PortPoolUpdateEnableStatusReq; -import fun.asgc.neutrino.proxy.server.controller.res.LicenseListRes; import fun.asgc.neutrino.proxy.server.controller.res.PortPoolCreateRes; import fun.asgc.neutrino.proxy.server.controller.res.PortPoolListRes; import fun.asgc.neutrino.proxy.server.controller.res.PortPoolUpdateEnableStatusRes; diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/service/UserService.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/service/UserService.java index 4b8f5cdd..1988622d 100644 --- a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/service/UserService.java +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/service/UserService.java @@ -26,8 +26,8 @@ import fun.asgc.neutrino.core.annotation.Component; import fun.asgc.neutrino.core.db.page.Page; import fun.asgc.neutrino.core.db.page.PageQuery; import fun.asgc.neutrino.core.util.DateUtil; -import fun.asgc.neutrino.proxy.server.base.rest.constant.EnableStatusEnum; -import fun.asgc.neutrino.proxy.server.base.rest.constant.ExceptionConstant; +import fun.asgc.neutrino.proxy.server.constant.EnableStatusEnum; +import fun.asgc.neutrino.proxy.server.constant.ExceptionConstant; import fun.asgc.neutrino.proxy.server.base.rest.ServiceException; import fun.asgc.neutrino.proxy.server.base.rest.SystemContextHolder; import fun.asgc.neutrino.proxy.server.controller.req.*; diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/util/ParamCheckUtil.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/util/ParamCheckUtil.java index d228339e..a3e89174 100644 --- a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/util/ParamCheckUtil.java +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/util/ParamCheckUtil.java @@ -22,7 +22,7 @@ package fun.asgc.neutrino.proxy.server.util; import fun.asgc.neutrino.core.util.StringUtil; -import fun.asgc.neutrino.proxy.server.base.rest.constant.ExceptionConstant; +import fun.asgc.neutrino.proxy.server.constant.ExceptionConstant; import fun.asgc.neutrino.proxy.server.base.rest.ServiceException; import java.util.Collection; 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 68c5490c..d8e32dcd 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 @@ -34,6 +34,8 @@ import io.netty.util.AttributeKey; import java.net.InetSocketAddress; import java.util.*; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.locks.ReadWriteLock; +import java.util.concurrent.locks.ReentrantReadWriteLock; /** * @@ -59,6 +61,11 @@ public class ProxyUtil { */ private static Map licenseToCmdChannelMap = new ConcurrentHashMap<>(); + /** + * cmdChannelAttachInfo.getUserChannelMap() 读写锁 + */ + private static final ReadWriteLock userChannelMapLock = new ReentrantReadWriteLock(); + /** * 初始化代理信息 * @param licenseKey 客户端licenseKey @@ -130,6 +137,7 @@ public class ProxyUtil { if (null == cmdChannel || null == getAttachInfo(cmdChannel)) { return; } + CmdChannelAttachInfo cmdChannelAttachInfo = getAttachInfo(cmdChannel); Channel channel0 = licenseToCmdChannelMap.remove(cmdChannelAttachInfo.getLicenseKey()); if (cmdChannel != channel0) { @@ -183,7 +191,12 @@ public class ProxyUtil { .setUserId(userId) .setLanInfo(lanInfo) ); - ((CmdChannelAttachInfo)getAttachInfo(cmdChannel)).getUserChannelMap().put(userId, userChannel); + userChannelMapLock.writeLock().lock(); + try { + ((CmdChannelAttachInfo)getAttachInfo(cmdChannel)).getUserChannelMap().put(userId, userChannel); + } finally { + userChannelMapLock.writeLock().unlock(); + } } public static Channel removeUserChannelFromCmdChannel(Channel cmdChannel, String userId) { @@ -191,8 +204,11 @@ public class ProxyUtil { return null; } - synchronized (cmdChannel) { + userChannelMapLock.writeLock().lock(); + try { return ((CmdChannelAttachInfo)getAttachInfo(cmdChannel)).getUserChannelMap().remove(userId); + } finally { + userChannelMapLock.writeLock().unlock(); } } diff --git a/neutrino-proxy-server/src/main/resources/sql/init-structure.sql b/neutrino-proxy-server/src/main/resources/sql/init-structure.sql index 335b4921..86672994 100644 --- a/neutrino-proxy-server/src/main/resources/sql/init-structure.sql +++ b/neutrino-proxy-server/src/main/resources/sql/init-structure.sql @@ -12,8 +12,8 @@ CREATE TABLE IF NOT EXISTS `user` ( #license表 CREATE TABLE IF NOT EXISTS `license` ( `id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, - `name` varchar(50) NOT NULL, - `key` varchar(100) NOT NULL, + `name` VARCHAR(50) NOT NULL, + `key` VARCHAR(100) NOT NULL, `user_id` INTEGER NOT NULL, `is_online` INTEGER(2) NOT NULL, `enable` INTEGER(2) NOT NULL, @@ -55,7 +55,7 @@ CREATE TABLE IF NOT EXISTS `port_mapping` ( `id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, `license_id` INTEGER(20) NOT NULL, `server_port` INTEGER NOT NULL, - `client_ip` varchar(20) NOT NULL, + `client_ip` VARCHAR(20) NOT NULL, `client_port` INTEGER NOT NULL, `is_online` INTEGER(2) NOT NULL, `enable` INTEGER(2) NOT NULL, @@ -67,11 +67,27 @@ CREATE TABLE IF NOT EXISTS `port_mapping` ( CREATE TABLE IF NOT EXISTS `client_connect_record` ( `id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, `user_id` INTEGER NOT NULL, - `ip` varchar(50) NOT NULL, + `ip` VARCHAR(50) NOT NULL, `license_id` INTEGER(20) NOT NULL, `license_key` VARCHAR(100) NOT NULL, - `write_bytes` INTEGER(20) NOT NULL, - `read_bytes` INTEGER(20) NOT NULL, + `write_bytes` INTEGER(20), + `read_bytes` INTEGER(20), + `type` INTEGER(2) NOT NULL, + `create_time` INTEGER(20) NOT NULL +); + +#用户连接记录表 +CREATE TABLE IF NOT EXISTS `user_connect_record` ( + `id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + `server_port` INTEGER NOT NULL, + `user_ip` VARCHAR(50) NOT NULL, + `client_ip` VARCHAR(50) NOT NULL, + `client_lan_info` VARCHAR(50) NOT NULL, + `user_id` INTEGER NOT NULL, + `license_id` INTEGER(20) NOT NULL, + `license_key` VARCHAR(100) NOT NULL, + `write_bytes` INTEGER(20), + `read_bytes` INTEGER(20), `type` INTEGER(2) NOT NULL, `create_time` INTEGER(20) NOT NULL );