diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/constant/ClientConnectTypeEnum.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/constant/ClientConnectTypeEnum.java new file mode 100644 index 00000000..8f2851cb --- /dev/null +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/constant/ClientConnectTypeEnum.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/11/23 + */ +@Getter +@AllArgsConstructor +public enum ClientConnectTypeEnum { + CONNECT(1, "连接"), + DISCONNECT(2, "断开连接"); + + private Integer type; + private String desc; +} diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/constant/SuccessCodeEnum.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/constant/SuccessCodeEnum.java new file mode 100644 index 00000000..2c0a6e12 --- /dev/null +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/constant/SuccessCodeEnum.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/11/23 + */ +@Getter +@AllArgsConstructor +public enum SuccessCodeEnum { + SUCCESS(1, "成功"), + FAIL(2, "失败"); + + private Integer code; + private String desc; +} diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/ClientConnectRecordMapper.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/ClientConnectRecordMapper.java index 1ba5bf0d..42ecd441 100644 --- a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/ClientConnectRecordMapper.java +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/ClientConnectRecordMapper.java @@ -2,6 +2,8 @@ package fun.asgc.neutrino.proxy.server.dal; import fun.asgc.neutrino.core.annotation.Component; import fun.asgc.neutrino.core.aop.Intercept; +import fun.asgc.neutrino.core.db.mapper.SqlMapper; +import fun.asgc.neutrino.proxy.server.dal.entity.ClientConnectRecordDO; /** * @author: aoshiguchen @@ -9,6 +11,7 @@ import fun.asgc.neutrino.core.aop.Intercept; */ @Intercept(ignoreGlobal = true) @Component -public class ClientConnectRecordMapper { +public interface ClientConnectRecordMapper extends SqlMapper { + void add(ClientConnectRecordDO clientConnectRecordDO); } diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/entity/ClientConnectRecordDO.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/entity/ClientConnectRecordDO.java index ed5279ab..4a6fb795 100644 --- a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/entity/ClientConnectRecordDO.java +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/entity/ClientConnectRecordDO.java @@ -19,10 +19,8 @@ import java.util.Date; public class ClientConnectRecordDO { @Id private Integer id; - private Integer userId; private String ip; private Integer licenseId; - private String licenseKey; private Integer type; private String msg; /** 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 b6eaa465..1b46caca 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 @@ -24,9 +24,14 @@ package fun.asgc.neutrino.proxy.server.proxy.core; import fun.asgc.neutrino.core.base.Dispatcher; import fun.asgc.neutrino.core.util.BeanManager; +import fun.asgc.neutrino.core.util.ChannelUtil; import fun.asgc.neutrino.proxy.core.Constants; import fun.asgc.neutrino.proxy.core.ProxyMessage; +import fun.asgc.neutrino.proxy.server.constant.ClientConnectTypeEnum; +import fun.asgc.neutrino.proxy.server.constant.SuccessCodeEnum; +import fun.asgc.neutrino.proxy.server.dal.entity.ClientConnectRecordDO; import fun.asgc.neutrino.proxy.server.proxy.domain.CmdChannelAttachInfo; +import fun.asgc.neutrino.proxy.server.service.ClientConnectRecordService; import fun.asgc.neutrino.proxy.server.service.ProxyMutualService; import fun.asgc.neutrino.proxy.server.util.ProxyUtil; import io.netty.buffer.Unpooled; @@ -34,6 +39,8 @@ import io.netty.channel.*; import io.netty.handler.timeout.IdleStateEvent; import lombok.extern.slf4j.Slf4j; +import java.util.Date; + /** * * @author: aoshiguchen @@ -81,6 +88,14 @@ public class ServerChannelHandler extends SimpleChannelInboundHandler portMappingList = portMappingService.findEnableListByLicenseId(licenseDO.getId()); // 没有端口映射仍然保持连接 if (!CollectionUtil.isEmpty(portMappingList)) { diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/service/ClientConnectRecordService.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/service/ClientConnectRecordService.java new file mode 100644 index 00000000..83b75878 --- /dev/null +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/service/ClientConnectRecordService.java @@ -0,0 +1,45 @@ +/** + * 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.service; + +import fun.asgc.neutrino.core.annotation.Autowired; +import fun.asgc.neutrino.core.annotation.Component; +import fun.asgc.neutrino.core.annotation.NonIntercept; +import fun.asgc.neutrino.proxy.server.dal.ClientConnectRecordMapper; +import fun.asgc.neutrino.proxy.server.dal.entity.ClientConnectRecordDO; +import lombok.extern.slf4j.Slf4j; + +/** + * @author: aoshiguchen + * @date: 2022/11/23 + */ +@Slf4j +@NonIntercept +@Component +public class ClientConnectRecordService { + @Autowired + private ClientConnectRecordMapper clientConnectRecordMapper; + + public void add(ClientConnectRecordDO clientConnectRecordDO) { + clientConnectRecordMapper.add(clientConnectRecordDO); + } +} diff --git a/neutrino-proxy-server/src/main/resources/mapper/ClientConnectRecordMapper.xml b/neutrino-proxy-server/src/main/resources/mapper/ClientConnectRecordMapper.xml new file mode 100644 index 00000000..c6b22539 --- /dev/null +++ b/neutrino-proxy-server/src/main/resources/mapper/ClientConnectRecordMapper.xml @@ -0,0 +1,7 @@ + + + + insert into client_connect_record(`ip`,`license_id`,`type`, `msg`, `code`, `err`, `create_time`) + values(:ip,:licenseId,:type,:msg,:code,:err,:createTime) + + 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 406f7884..759ea1cb 100644 --- a/neutrino-proxy-server/src/main/resources/sql/init-structure.sql +++ b/neutrino-proxy-server/src/main/resources/sql/init-structure.sql @@ -75,10 +75,8 @@ CREATE TABLE IF NOT EXISTS `user_login_record` ( #客户端连接记录表 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, - `license_id` INTEGER(20) NOT NULL, - `license_key` VARCHAR(100) NOT NULL, + `license_id` INTEGER(20) DEFAULT NULL, `type` INTEGER(2) NOT NULL, `msg` VARCHAR(512) DEFAULT NULL, `code` INTEGER(2) NOT NULL,