代理服务端solon化改造

This commit is contained in:
aoshiguchen
2023-03-09 22:04:44 +08:00
parent c3f7bb571f
commit e940edeee9
51 changed files with 510 additions and 405 deletions
+2
View File
@@ -49,3 +49,5 @@ hs_err_pid*
**/*.log
**/gifs/
**/deploy/
**/app-**.yml
+9
View File
@@ -15,6 +15,15 @@
<dependencies>
<dependency>
<groupId>org.noear</groupId>
<artifactId>solon-api</artifactId>
</dependency>
<dependency>
<groupId>org.noear</groupId>
<artifactId>mybatis-plus-solon-plugin</artifactId>
<version>2.2.1</version>
</dependency>
<dependency>
<groupId>fun.asgc.neutrino</groupId>
<artifactId>neutrino-proxy-core</artifactId>
@@ -1,42 +1,17 @@
/**
* 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;
import fun.asgc.neutrino.core.annotation.EnableJob;
import fun.asgc.neutrino.core.annotation.NeutrinoApplication;
import fun.asgc.neutrino.core.context.NeutrinoLauncher;
import org.noear.solon.Solon;
import org.noear.solon.annotation.Controller;
/**
*
* @author: aoshiguchen
* @date: 2022/6/16
*/
@EnableJob
@NeutrinoApplication(environmentVariableKey = "NeutrinoProxyServer")
@Controller
public class ProxyServer {
public static void main(String[] args) {
NeutrinoLauncher.run(ProxyServer.class, args);
Solon.start(ProxyServer.class, args);
}
}
@@ -21,9 +21,9 @@
*/
package fun.asgc.neutrino.proxy.server.base.proxy;
import fun.asgc.neutrino.core.annotation.Configuration;
import fun.asgc.neutrino.core.annotation.Value;
import lombok.Data;
import org.noear.solon.annotation.Component;
import org.noear.solon.annotation.Inject;
/**
* 服务端代理配置
@@ -31,48 +31,37 @@ import lombok.Data;
* @date: 2022/6/16
*/
@Data
@Configuration(prefix = "neutrino.proxy")
@Component
public class ProxyConfig {
/**
* 传输协议相关配置
*/
@Inject("${neutrino.proxy.protocol}")
private Protocol protocol;
/**
* 服务端配置
*/
@Inject("${neutrino.proxy.server}")
private Server server;
@Data
public static class Protocol {
@Value("max-frame-length")
private Integer maxFrameLength;
@Value("length-field-offset")
private Integer lengthFieldOffset;
@Value("length-field-length")
private Integer lengthFieldLength;
@Value("initial-bytes-to-strip")
private Integer initialBytesToStrip;
@Value("length-adjustment")
private Integer lengthAdjustment;
@Value("read-idle-time")
private Integer readIdleTime;
@Value("write-idle-time")
private Integer writeIdleTime;
@Value("all-idle-time-seconds")
private Integer allIdleTimeSeconds;
}
@Data
public static class Server {
@Value("port")
private Integer port;
@Value("ssl-port")
private Integer sslPort;
@Value("key-store-password")
private String keyStorePassword;
@Value("key-manager-password")
private String keyManagerPassword;
@Value("jks-path")
private String jksPath;
}
@@ -21,31 +21,48 @@
*/
package fun.asgc.neutrino.proxy.server.base.proxy;
import fun.asgc.neutrino.core.annotation.Bean;
import fun.asgc.neutrino.core.annotation.Component;
import fun.asgc.neutrino.core.annotation.Order;
import fun.asgc.neutrino.core.base.DefaultDispatcher;
import fun.asgc.neutrino.core.base.Dispatcher;
import fun.asgc.neutrino.core.base.Ordered;
import fun.asgc.neutrino.core.util.BeanManager;
import fun.asgc.neutrino.proxy.core.ProxyDataTypeEnum;
import fun.asgc.neutrino.proxy.core.ProxyMessage;
import fun.asgc.neutrino.proxy.core.ProxyMessageHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.nio.NioEventLoopGroup;
import org.noear.solon.annotation.Bean;
import org.noear.solon.annotation.Configuration;
import org.noear.solon.annotation.Inject;
import org.noear.solon.core.AopContext;
import java.util.List;
/**
* 代理配置
* @author: aoshiguchen
* @date: 2022/10/8
*/
@Order(Ordered.HIGHEST_PRECEDENCE)
@Component
@Configuration
public class ProxyConfiguration {
@Inject
private AopContext aopContext;
@Bean
public Dispatcher<ChannelHandlerContext, ProxyMessage> dispatcher() {
return new DefaultDispatcher<>("消息调度器",
BeanManager.getBeanListBySuperClass(ProxyMessageHandler.class),
proxyMessage -> ProxyDataTypeEnum.of((int)proxyMessage.getType()) == null ? null : ProxyDataTypeEnum.of((int)proxyMessage.getType()).getName());
public void dispatcher() {
aopContext.lifecycle(() -> {
List<ProxyMessageHandler> list = aopContext.getBeansOfType(ProxyMessageHandler.class);
Dispatcher<ChannelHandlerContext, ProxyMessage> dispatcher = new DefaultDispatcher<>("消息调度器", list,
proxyMessage -> ProxyDataTypeEnum.of((int)proxyMessage.getType()) == null ?
null : ProxyDataTypeEnum.of((int)proxyMessage.getType()).getName());
aopContext.wrapAndPut(Dispatcher.class, dispatcher);
});
}
@Bean("serverBossGroup")
public NioEventLoopGroup serverBossGroup() {
return new NioEventLoopGroup();
}
@Bean("serverWorkerGroup")
public NioEventLoopGroup serverWorkerGroup() {
return new NioEventLoopGroup();
}
}
@@ -21,18 +21,16 @@
*/
package fun.asgc.neutrino.proxy.server.base.rest;
import com.alibaba.druid.pool.DruidDataSource;
import com.google.common.collect.Lists;
import fun.asgc.neutrino.core.annotation.PreLoad;
import fun.asgc.neutrino.core.db.template.JdbcTemplate;
import fun.asgc.neutrino.core.util.*;
import fun.asgc.neutrino.proxy.server.base.rest.config.DbConfig;
import fun.asgc.neutrino.proxy.server.constant.DbTypeEnum;
import lombok.extern.slf4j.Slf4j;
import org.sqlite.SQLiteConfig;
import org.sqlite.SQLiteDataSource;
import java.sql.DriverManager;
import org.noear.solon.annotation.Component;
import org.noear.solon.annotation.Inject;
import org.noear.solon.core.event.AppLoadEndEvent;
import org.noear.solon.core.event.EventListener;
import java.util.List;
/**
@@ -41,22 +39,23 @@ import java.util.List;
* @date: 2022/7/31
*/
@Slf4j
@PreLoad("init")
public class DBInitialize {
@Component
public class DBInitialize implements EventListener<AppLoadEndEvent> {
private static List<String> initDataTableNameList = Lists.newArrayList("user", "license", "port_pool", "port_mapping", "job_info");
private static DbConfig dbConfig;
private static JdbcTemplate jdbcTemplate;
@Inject
private DbConfig dbConfig;
@Inject
private JdbcTemplate jdbcTemplate;
private static DbTypeEnum dbTypeEnum;
private DbTypeEnum dbTypeEnum;
public static void init() throws Exception {
dbConfig = ConfigUtil.getYmlConfig(DbConfig.class);
@Override
public void onEvent(AppLoadEndEvent appLoadEndEvent) throws Throwable {
Assert.notNull(dbConfig.getType(), "neutrino.data.db.type不能为空!");
dbTypeEnum = DbTypeEnum.of(dbConfig.getType());
Assert.notNull(dbTypeEnum, "neutrino.data.db.type取值异常!");
log.info("{}数据库初始化...", dbConfig.getType());
jdbcTemplate = getJdbcTemplate();
initDBStructure();
initDBData();
}
@@ -64,7 +63,7 @@ public class DBInitialize {
/**
* 初始化数据库结构
*/
private static void initDBStructure() throws Exception {
private void initDBStructure() throws Exception {
List<String> lines = FileUtil.readContentAsStringList(String.format("classpath:/sql/%s/init-structure.sql", dbConfig.getType()));
if (CollectionUtil.isEmpty(lines)) {
return;
@@ -87,7 +86,7 @@ public class DBInitialize {
* 初始化数据
* @throws Exception
*/
private static void initDBData() throws Exception {
private void initDBData() throws Exception {
if (CollectionUtil.isEmpty(initDataTableNameList)) {
return;
}
@@ -116,42 +115,42 @@ public class DBInitialize {
}
}
/**
* 获取jdbcTemplate实例
* @return
* @throws Exception
*/
private static JdbcTemplate getJdbcTemplate() throws Exception {
return LockUtil.doubleCheckProcess(
() -> null == jdbcTemplate,
DBInitialize.class,
() -> {
if (DbTypeEnum.SQLITE == dbTypeEnum) {
//建立一个数据库名data.db的连接,如果不存在就在当前目录下创建之
DriverManager.getConnection(dbConfig.getUrl());
// 创建数据源
SQLiteDataSource dataSource = new SQLiteDataSource();
dataSource.setUrl(dbConfig.getUrl());
dataSource.setJournalMode(SQLiteConfig.JournalMode.WAL.getValue());
// 创建jdbcTemplate
jdbcTemplate = new JdbcTemplate(dataSource);
} else if (DbTypeEnum.MYSQL == dbTypeEnum) {
DruidDataSource dataSource = new DruidDataSource();
dataSource.setDriverClassName(dbConfig.getDriverClass());
dataSource.setUrl(dbConfig.getUrl());
dataSource.setInitialSize(5);
dataSource.setMinIdle(5);
dataSource.setMaxActive(20);
dataSource.setMaxWait(60000);
dataSource.setPoolPreparedStatements(true);
dataSource.setUsername(dbConfig.getUsername());
dataSource.setPassword(dbConfig.getPassword());
// 创建jdbcTemplate
jdbcTemplate = new JdbcTemplate(dataSource);
}
},
() -> jdbcTemplate
);
}
// /**
// * 获取jdbcTemplate实例
// * @return
// * @throws Exception
// */
// private JdbcTemplate getJdbcTemplate() throws Exception {
// return LockUtil.doubleCheckProcess(
// () -> null == jdbcTemplate,
// DBInitialize2.class,
// () -> {
// if (DbTypeEnum.SQLITE == dbTypeEnum) {
// //建立一个数据库名data.db的连接,如果不存在就在当前目录下创建之
// DriverManager.getConnection(dbConfig.getUrl());
// // 创建数据源
// SQLiteDataSource dataSource = new SQLiteDataSource();
// dataSource.setUrl(dbConfig.getUrl());
// dataSource.setJournalMode(SQLiteConfig.JournalMode.WAL.getValue());
// // 创建jdbcTemplate
// jdbcTemplate = new JdbcTemplate(dataSource);
// } else if (DbTypeEnum.MYSQL == dbTypeEnum) {
// DruidDataSource dataSource = new DruidDataSource();
// dataSource.setDriverClassName(dbConfig.getDriverClass());
// dataSource.setUrl(dbConfig.getUrl());
// dataSource.setInitialSize(5);
// dataSource.setMinIdle(5);
// dataSource.setMaxActive(20);
// dataSource.setMaxWait(60000);
// dataSource.setPoolPreparedStatements(true);
// dataSource.setUsername(dbConfig.getUsername());
// dataSource.setPassword(dbConfig.getPassword());
//
// // 创建jdbcTemplate
// jdbcTemplate = new JdbcTemplate(dataSource);
// }
// },
// () -> jdbcTemplate
// );
// }
}
@@ -21,11 +21,10 @@
*/
package fun.asgc.neutrino.proxy.server.base.rest.config;
import fun.asgc.neutrino.core.annotation.Configuration;
import fun.asgc.neutrino.core.annotation.NonIntercept;
import fun.asgc.neutrino.core.annotation.Value;
import fun.asgc.neutrino.proxy.server.constant.DbTypeEnum;
import lombok.Data;
import org.noear.solon.annotation.Component;
import org.noear.solon.annotation.Inject;
/**
* sqlite数据库配置
@@ -33,35 +32,33 @@ import lombok.Data;
* @date: 2022/7/31
*/
@Data
@NonIntercept
@Configuration(prefix = "neutrino.data.db")
@Component
public class DbConfig {
/**
* 数据库类型
* {@link DbTypeEnum}
*/
@Value("type")
@Inject("${neutrino.data.db.type}")
private String type;
/**
* 连接url
*/
@Value("url")
@Inject("${neutrino.data.db.url}")
private String url;
/**
* 驱动类
*/
@Value("driver-class")
@Inject("${neutrino.data.db.driver-class}")
private String driverClass;
/**
* 用户名
*/
@Value("username")
@Inject("${neutrino.data.db.username}")
private String username;
/**
* 密码
*/
@Value("password")
@Inject("${neutrino.data.db.password}")
private String password;
}
@@ -22,10 +22,11 @@
package fun.asgc.neutrino.proxy.server.base.rest.config;
import com.alibaba.druid.pool.DruidDataSource;
import fun.asgc.neutrino.core.annotation.*;
import fun.asgc.neutrino.core.base.Ordered;
import fun.asgc.neutrino.core.db.template.JdbcTemplate;
import fun.asgc.neutrino.proxy.server.constant.DbTypeEnum;
import org.noear.solon.annotation.Bean;
import org.noear.solon.annotation.Configuration;
import org.noear.solon.annotation.Inject;
import org.sqlite.SQLiteConfig;
import org.sqlite.SQLiteDataSource;
@@ -36,13 +37,12 @@ import javax.sql.DataSource;
*author: aoshiguchen
* @date: 2022/8/1
*/
@Order(Ordered.HIGHEST_PRECEDENCE)
@Component
@Configuration
public class RestConfiguration {
@Autowired
@Inject
private DbConfig dbConfig;
@Bean
@Bean("dataSource")
public DataSource dataSource() {
DbTypeEnum dbTypeEnum = DbTypeEnum.of(dbConfig.getType());
if (DbTypeEnum.SQLITE == dbTypeEnum) {
@@ -68,8 +68,8 @@ public class RestConfiguration {
}
@Bean
public JdbcTemplate jdbcTemplate() {
return new JdbcTemplate(dataSource());
public JdbcTemplate jdbcTemplate(@Inject("dataSource") DataSource dataSource) {
return new JdbcTemplate(dataSource);
}
}
@@ -21,19 +21,22 @@
*/
package fun.asgc.neutrino.proxy.server.base.rest.interceptor;
import fun.asgc.neutrino.core.util.BeanManager;
import fun.asgc.neutrino.core.util.HttpUtil;
import fun.asgc.neutrino.core.util.StringUtil;
import fun.asgc.neutrino.core.web.context.HttpContextHolder;
import fun.asgc.neutrino.core.web.context.HttpRequestWrapper;
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.Authorization;
import fun.asgc.neutrino.proxy.server.base.rest.ServiceException;
import fun.asgc.neutrino.proxy.server.base.rest.SystemContext;
import fun.asgc.neutrino.proxy.server.base.rest.SystemContextHolder;
import fun.asgc.neutrino.proxy.server.base.rest.annotation.OnlyAdmin;
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 org.noear.solon.Solon;
import java.lang.reflect.Method;
@@ -56,7 +59,7 @@ public class BaseAuthInterceptor implements HandlerInterceptor {
if (StringUtil.isEmpty(authorize)) {
throw ServiceException.create(ExceptionConstant.USER_NOT_LOGIN);
}
UserDO userDO = BeanManager.getBean(UserService.class).findByToken(authorize);
UserDO userDO = Solon.context().getBean(UserService.class).findByToken(authorize);
if (null == userDO) {
throw ServiceException.create(ExceptionConstant.USER_NOT_LOGIN);
}
@@ -71,7 +74,7 @@ public class BaseAuthInterceptor implements HandlerInterceptor {
systemContext.setUser(userDO);
// token续期
BeanManager.getBean(UserService.class).updateTokenExpirationTime(authorize);
Solon.context().getBean(UserService.class).updateTokenExpirationTime(authorize);
}
return true;
@@ -21,14 +21,17 @@
*/
package fun.asgc.neutrino.proxy.server.controller;
import fun.asgc.neutrino.core.annotation.Autowired;
import fun.asgc.neutrino.core.annotation.NonIntercept;
import fun.asgc.neutrino.core.web.annotation.*;
import fun.asgc.neutrino.core.web.annotation.RequestBody;
import fun.asgc.neutrino.proxy.server.base.rest.Authorization;
import fun.asgc.neutrino.proxy.server.controller.req.LoginReq;
import fun.asgc.neutrino.proxy.server.controller.res.LoginRes;
import fun.asgc.neutrino.proxy.server.service.UserService;
import fun.asgc.neutrino.proxy.server.util.ParamCheckUtil;
import org.noear.solon.annotation.Controller;
import org.noear.solon.annotation.Inject;
import org.noear.solon.annotation.Mapping;
import org.noear.solon.annotation.Post;
/**
*
@@ -36,14 +39,14 @@ import fun.asgc.neutrino.proxy.server.util.ParamCheckUtil;
* @date: 2022/7/31
*/
@NonIntercept
@RequestMapping
@RestController
@Controller
public class IndexController {
@Autowired
@Inject
private UserService userService;
@Authorization(login = false)
@PostMapping("login")
@Post
@Mapping("login")
public LoginRes login(@RequestBody LoginReq req) {
ParamCheckUtil.checkNotEmpty(req.getLoginName(), "loginName");
ParamCheckUtil.checkNotEmpty(req.getLoginPassword(), "loginPassword");
@@ -51,7 +54,8 @@ public class IndexController {
return userService.login(req);
}
@PostMapping("logout")
@Post
@Mapping("logout")
public void logout() {
userService.logout();
}
@@ -1,10 +1,7 @@
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.annotation.ResultType;
import fun.asgc.neutrino.core.db.annotation.Select;
import fun.asgc.neutrino.core.db.mapper.SqlMapper;
import fun.asgc.neutrino.core.db.page.Page;
import fun.asgc.neutrino.proxy.server.controller.req.ClientConnectRecordListReq;
import fun.asgc.neutrino.proxy.server.controller.res.ClientConnectRecordListRes;
@@ -14,9 +11,7 @@ import fun.asgc.neutrino.proxy.server.dal.entity.ClientConnectRecordDO;
* @author: aoshiguchen
* @date: 2022/11/23
*/
@Intercept(ignoreGlobal = true)
@Component
public interface ClientConnectRecordMapper extends SqlMapper {
public interface ClientConnectRecordMapper {
void add(ClientConnectRecordDO clientConnectRecordDO);
@@ -21,20 +21,12 @@
*/
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.annotation.Delete;
import fun.asgc.neutrino.core.db.mapper.SqlMapper;
import java.util.Date;
/**
* @author: aoshiguchen
* @date: 2022/9/17
*/
@Intercept(ignoreGlobal = true)
@Component
public interface DataCleanMapper extends SqlMapper {
public interface DataCleanMapper {
@Delete("delete from `job_log` where create_time < ?")
void cleanJobLog(Date date);
@@ -21,9 +21,7 @@
*/
package fun.asgc.neutrino.proxy.server.dal;
import fun.asgc.neutrino.core.annotation.Component;
import fun.asgc.neutrino.core.annotation.Param;
import fun.asgc.neutrino.core.aop.Intercept;
import fun.asgc.neutrino.core.db.annotation.Delete;
import fun.asgc.neutrino.core.db.annotation.Insert;
import fun.asgc.neutrino.core.db.annotation.ResultType;
@@ -34,13 +32,8 @@ import fun.asgc.neutrino.proxy.server.dal.entity.FlowReportDayDO;
import java.util.Date;
import java.util.List;
/**
* @author: aoshiguchen
* @date: 2022/10/28
*/
@Intercept(ignoreGlobal = true)
@Component
public interface FlowReportDayMapper extends SqlMapper {
public interface FlowReportDayMapper {
@Select("select * from flow_report_day where license_id = :licenseId and date_str = :dateStr")
FlowReportDayDO findOne(@Param("licenseId") Integer licenseId, @Param("dateStr") String dateStr);
@@ -21,26 +21,18 @@
*/
package fun.asgc.neutrino.proxy.server.dal;
import fun.asgc.neutrino.core.annotation.Component;
import fun.asgc.neutrino.core.annotation.Param;
import fun.asgc.neutrino.core.aop.Intercept;
import fun.asgc.neutrino.core.db.annotation.Delete;
import fun.asgc.neutrino.core.db.annotation.Insert;
import fun.asgc.neutrino.core.db.annotation.ResultType;
import fun.asgc.neutrino.core.db.annotation.Select;
import fun.asgc.neutrino.core.db.mapper.SqlMapper;
import fun.asgc.neutrino.proxy.server.dal.entity.FlowReportHourDO;
import java.util.Date;
import java.util.List;
/**
* @author: aoshiguchen
* @date: 2022/10/28
*/
@Intercept(ignoreGlobal = true)
@Component
public interface FlowReportHourMapper extends SqlMapper {
public interface FlowReportHourMapper {
@Select("select * from flow_report_hour where license_id = :licenseId and date_str = :dateStr")
FlowReportHourDO findOne(@Param("licenseId") Integer licenseId, @Param("dateStr") String dateStr);
@@ -21,26 +21,18 @@
*/
package fun.asgc.neutrino.proxy.server.dal;
import fun.asgc.neutrino.core.annotation.Component;
import fun.asgc.neutrino.core.annotation.Param;
import fun.asgc.neutrino.core.aop.Intercept;
import fun.asgc.neutrino.core.db.annotation.Insert;
import fun.asgc.neutrino.core.db.annotation.ResultType;
import fun.asgc.neutrino.core.db.annotation.Select;
import fun.asgc.neutrino.core.db.mapper.SqlMapper;
import fun.asgc.neutrino.proxy.server.dal.entity.FlowReportMinuteDO;
import java.util.Date;
import java.util.List;
import java.util.Set;
/**
* @author: aoshiguchen
* @date: 2022/10/24
*/
@Intercept(ignoreGlobal = true)
@Component
public interface FlowReportMinuteMapper extends SqlMapper {
public interface FlowReportMinuteMapper {
@Select("select * from flow_report_minute where license_id = :licenseId and date = :date")
FlowReportMinuteDO findOne(@Param("licenseId") Integer licenseId, @Param("date") String date);
@@ -21,22 +21,14 @@
*/
package fun.asgc.neutrino.proxy.server.dal;
import fun.asgc.neutrino.core.annotation.Component;
import fun.asgc.neutrino.core.annotation.Param;
import fun.asgc.neutrino.core.aop.Intercept;
import fun.asgc.neutrino.core.db.annotation.Delete;
import fun.asgc.neutrino.core.db.annotation.Insert;
import fun.asgc.neutrino.core.db.annotation.Select;
import fun.asgc.neutrino.core.db.mapper.SqlMapper;
import fun.asgc.neutrino.proxy.server.dal.entity.FlowReportMonthDO;
/**
* @author: aoshiguchen
* @date: 2022/10/28
*/
@Intercept(ignoreGlobal = true)
@Component
public interface FlowReportMonthMapper extends SqlMapper {
public interface FlowReportMonthMapper {
@Select("select * from flow_report_month where license_id = :licenseId and date_str = :dateStr")
FlowReportMonthDO findOne(@Param("licenseId") Integer licenseId, @Param("dateStr") String dateStr);
@@ -21,13 +21,10 @@
*/
package fun.asgc.neutrino.proxy.server.dal;
import fun.asgc.neutrino.core.annotation.Component;
import fun.asgc.neutrino.core.annotation.Param;
import fun.asgc.neutrino.core.aop.Intercept;
import fun.asgc.neutrino.core.db.annotation.ResultType;
import fun.asgc.neutrino.core.db.annotation.Select;
import fun.asgc.neutrino.core.db.annotation.Update;
import fun.asgc.neutrino.core.db.mapper.SqlMapper;
import fun.asgc.neutrino.core.db.page.Page;
import fun.asgc.neutrino.proxy.server.controller.req.JobInfoListReq;
import fun.asgc.neutrino.proxy.server.controller.res.JobInfoListRes;
@@ -36,14 +33,8 @@ import fun.asgc.neutrino.proxy.server.dal.entity.JobInfoDO;
import java.util.Date;
import java.util.List;
/**
*
* @author: aoshiguchen
* @date: 2022/9/5
*/
@Intercept(ignoreGlobal = true)
@Component
public interface JobInfoMapper extends SqlMapper {
public interface JobInfoMapper {
@ResultType(JobInfoListRes.class)
@Select("select * from job_info")
@@ -22,18 +22,13 @@
package fun.asgc.neutrino.proxy.server.dal;
import fun.asgc.neutrino.core.annotation.Component;
import fun.asgc.neutrino.core.annotation.Param;
import fun.asgc.neutrino.core.aop.Intercept;
import fun.asgc.neutrino.core.db.annotation.Insert;
import fun.asgc.neutrino.core.db.annotation.ResultType;
import fun.asgc.neutrino.core.db.annotation.Select;
import fun.asgc.neutrino.core.db.mapper.SqlMapper;
import fun.asgc.neutrino.core.db.page.Page;
import fun.asgc.neutrino.proxy.server.controller.req.JobInfoListReq;
import fun.asgc.neutrino.proxy.server.controller.req.JobLogListReq;
import fun.asgc.neutrino.proxy.server.controller.res.JobInfoListRes;
import fun.asgc.neutrino.proxy.server.controller.res.JobLogListRes;
import fun.asgc.neutrino.proxy.server.dal.entity.JobInfoDO;
import fun.asgc.neutrino.proxy.server.dal.entity.JobLogDO;
/**
@@ -43,7 +38,7 @@ import fun.asgc.neutrino.proxy.server.dal.entity.JobLogDO;
*/
@Intercept(ignoreGlobal = true)
@Component
public interface JobLogMapper extends SqlMapper {
public interface JobLogMapper {
@Insert("insert into job_log(`job_id`,`handler`,`param`,`code`,`msg`,`alarm_status`,`create_time`) values(:jobId,:handler,:param,:code,:msg,:alarmStatus,:createTime)")
void add(JobLogDO jobLog);
@@ -28,7 +28,6 @@ import fun.asgc.neutrino.core.db.annotation.Delete;
import fun.asgc.neutrino.core.db.annotation.ResultType;
import fun.asgc.neutrino.core.db.annotation.Select;
import fun.asgc.neutrino.core.db.annotation.Update;
import fun.asgc.neutrino.core.db.mapper.SqlMapper;
import fun.asgc.neutrino.core.db.page.Page;
import fun.asgc.neutrino.proxy.server.controller.req.LicenseListReq;
import fun.asgc.neutrino.proxy.server.controller.res.LicenseListRes;
@@ -45,7 +44,7 @@ import java.util.Set;
*/
@Intercept(ignoreGlobal = true)
@Component
public interface LicenseMapper extends SqlMapper {
public interface LicenseMapper {
/**
* 查询license分页
@@ -28,7 +28,6 @@ import fun.asgc.neutrino.core.db.annotation.Delete;
import fun.asgc.neutrino.core.db.annotation.ResultType;
import fun.asgc.neutrino.core.db.annotation.Select;
import fun.asgc.neutrino.core.db.annotation.Update;
import fun.asgc.neutrino.core.db.mapper.SqlMapper;
import fun.asgc.neutrino.core.db.page.Page;
import fun.asgc.neutrino.proxy.server.controller.req.PortMappingListReq;
import fun.asgc.neutrino.proxy.server.controller.res.PortMappingListRes;
@@ -45,7 +44,7 @@ import java.util.Set;
*/
@Intercept(ignoreGlobal = true)
@Component
public interface PortMappingMapper extends SqlMapper {
public interface PortMappingMapper {
@ResultType(PortMappingListRes.class)
@Select("select * from port_mapping")
@@ -25,7 +25,6 @@ import fun.asgc.neutrino.core.annotation.Component;
import fun.asgc.neutrino.core.annotation.Param;
import fun.asgc.neutrino.core.aop.Intercept;
import fun.asgc.neutrino.core.db.annotation.*;
import fun.asgc.neutrino.core.db.mapper.SqlMapper;
import fun.asgc.neutrino.core.db.page.Page;
import fun.asgc.neutrino.proxy.server.controller.req.PortPoolListReq;
import fun.asgc.neutrino.proxy.server.controller.res.PortPoolListRes;
@@ -41,7 +40,7 @@ import java.util.List;
*/
@Intercept(ignoreGlobal = true)
@Component
public interface PortPoolMapper extends SqlMapper {
public interface PortPoolMapper {
@ResultType(PortPoolListRes.class)
@Select("select * from port_pool")
@@ -23,7 +23,6 @@ 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;
/**
*
@@ -32,6 +31,6 @@ import fun.asgc.neutrino.core.db.mapper.SqlMapper;
*/
@Intercept(ignoreGlobal = true)
@Component
public interface UserConnectRecordMapper extends SqlMapper {
public interface UserConnectRecordMapper {
}
@@ -26,7 +26,6 @@ import fun.asgc.neutrino.core.aop.Intercept;
import fun.asgc.neutrino.core.db.annotation.Insert;
import fun.asgc.neutrino.core.db.annotation.ResultType;
import fun.asgc.neutrino.core.db.annotation.Select;
import fun.asgc.neutrino.core.db.mapper.SqlMapper;
import fun.asgc.neutrino.core.db.page.Page;
import fun.asgc.neutrino.proxy.server.controller.req.UserLoginRecordListReq;
import fun.asgc.neutrino.proxy.server.controller.res.UserLoginRecordListRes;
@@ -39,7 +38,7 @@ import fun.asgc.neutrino.proxy.server.dal.entity.UserLoginRecordDO;
*/
@Intercept(ignoreGlobal = true)
@Component
public interface UserLoginRecordMapper extends SqlMapper {
public interface UserLoginRecordMapper {
/**
* 新增用户登录日志
* @param userLoginRecord
@@ -25,7 +25,6 @@ import fun.asgc.neutrino.core.annotation.Component;
import fun.asgc.neutrino.core.annotation.Param;
import fun.asgc.neutrino.core.aop.Intercept;
import fun.asgc.neutrino.core.db.annotation.*;
import fun.asgc.neutrino.core.db.mapper.SqlMapper;
import fun.asgc.neutrino.core.db.page.Page;
import fun.asgc.neutrino.proxy.server.controller.req.UserListReq;
import fun.asgc.neutrino.proxy.server.controller.res.UserListRes;
@@ -42,7 +41,7 @@ import java.util.Set;
*/
@Intercept(ignoreGlobal = true)
@Component
public interface UserMapper extends SqlMapper {
public interface UserMapper {
/**
* 根据登录名查询用户记录
@@ -3,7 +3,6 @@ package fun.asgc.neutrino.proxy.server.dal;
import fun.asgc.neutrino.core.annotation.Component;
import fun.asgc.neutrino.core.annotation.Param;
import fun.asgc.neutrino.core.aop.Intercept;
import fun.asgc.neutrino.core.db.mapper.SqlMapper;
import fun.asgc.neutrino.core.db.page.Page;
import fun.asgc.neutrino.proxy.server.controller.res.UserFlowReportRes;
@@ -15,7 +14,7 @@ import java.util.Date;
*/
@Intercept(ignoreGlobal = true)
@Component
public interface UserReportMapper extends SqlMapper {
public interface UserReportMapper {
void userFlowReportPage(Page<UserFlowReportRes> page, @Param("todayBegin") Date todayBegin, @Param("todayEnd") Date todayEnd);
@@ -26,7 +26,6 @@ import fun.asgc.neutrino.core.annotation.Param;
import fun.asgc.neutrino.core.aop.Intercept;
import fun.asgc.neutrino.core.db.annotation.Delete;
import fun.asgc.neutrino.core.db.annotation.Update;
import fun.asgc.neutrino.core.db.mapper.SqlMapper;
import fun.asgc.neutrino.proxy.server.dal.entity.UserTokenDO;
import java.util.Date;
@@ -38,7 +37,7 @@ import java.util.Date;
*/
@Intercept(ignoreGlobal = true)
@Component
public interface UserTokenMapper extends SqlMapper {
public interface UserTokenMapper {
/**
* 新增用户token
* 支持注解 + xml配置2种方式
@@ -0,0 +1,51 @@
package fun.asgc.neutrino.proxy.server.db;
import fun.asgc.neutrino.core.aop.Aop;
import fun.asgc.neutrino.proxy.server.dal.*;
import org.noear.solon.core.AopContext;
import org.noear.solon.core.Plugin;
/**
* @author: aoshiguchen
* @date: 2023/3/9
*/
public class MapperPlugin implements Plugin {
@Override
public void start(AopContext context) throws Throwable {
Aop.intercept(ClientConnectRecordMapper.class, SqlMapperInterceptor.class);
Aop.intercept(DataCleanMapper.class, SqlMapperInterceptor.class);
Aop.intercept(FlowReportDayMapper.class, SqlMapperInterceptor.class);
Aop.intercept(FlowReportHourMapper.class, SqlMapperInterceptor.class);
Aop.intercept(FlowReportMinuteMapper.class, SqlMapperInterceptor.class);
Aop.intercept(FlowReportMonthMapper.class, SqlMapperInterceptor.class);
Aop.intercept(JobInfoMapper.class, SqlMapperInterceptor.class);
Aop.intercept(JobLogMapper.class, SqlMapperInterceptor.class);
Aop.intercept(LicenseMapper.class, SqlMapperInterceptor.class);
Aop.intercept(PortMappingMapper.class, SqlMapperInterceptor.class);
Aop.intercept(PortPoolMapper.class, SqlMapperInterceptor.class);
Aop.intercept(UserConnectRecordMapper.class, SqlMapperInterceptor.class);
Aop.intercept(UserLoginRecordMapper.class, SqlMapperInterceptor.class);
Aop.intercept(UserMapper.class, SqlMapperInterceptor.class);
Aop.intercept(UserReportMapper.class, SqlMapperInterceptor.class);
Aop.intercept(UserTokenMapper.class, SqlMapperInterceptor.class);
context.wrapAndPut(ClientConnectRecordMapper.class, Aop.get(ClientConnectRecordMapper.class));
context.wrapAndPut(DataCleanMapper.class, Aop.get(DataCleanMapper.class));
context.wrapAndPut(FlowReportDayMapper.class, Aop.get(FlowReportDayMapper.class));
context.wrapAndPut(FlowReportHourMapper.class, Aop.get(FlowReportHourMapper.class));
context.wrapAndPut(FlowReportMinuteMapper.class, Aop.get(FlowReportMinuteMapper.class));
context.wrapAndPut(FlowReportMonthMapper.class, Aop.get(FlowReportMonthMapper.class));
context.wrapAndPut(JobInfoMapper.class, Aop.get(JobInfoMapper.class));
context.wrapAndPut(JobLogMapper.class, Aop.get(JobLogMapper.class));
context.wrapAndPut(LicenseMapper.class, Aop.get(LicenseMapper.class));
context.wrapAndPut(PortMappingMapper.class, Aop.get(PortMappingMapper.class));
context.wrapAndPut(PortPoolMapper.class, Aop.get(PortPoolMapper.class));
context.wrapAndPut(UserConnectRecordMapper.class, Aop.get(UserConnectRecordMapper.class));
context.wrapAndPut(UserLoginRecordMapper.class, Aop.get(UserLoginRecordMapper.class));
context.wrapAndPut(UserMapper.class, Aop.get(UserMapper.class));
context.wrapAndPut(UserReportMapper.class, Aop.get(UserReportMapper.class));
context.wrapAndPut(UserTokenMapper.class, Aop.get(UserTokenMapper.class));
}
}
@@ -0,0 +1,140 @@
/**
* 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.db;
import fun.asgc.neutrino.core.annotation.Component;
import fun.asgc.neutrino.core.annotation.NonIntercept;
import fun.asgc.neutrino.core.annotation.Param;
import fun.asgc.neutrino.core.aop.Invocation;
import fun.asgc.neutrino.core.aop.interceptor.Interceptor;
import fun.asgc.neutrino.core.db.mapper.SqlParser;
import fun.asgc.neutrino.core.db.page.Page;
import fun.asgc.neutrino.core.db.template.JdbcTemplate;
import fun.asgc.neutrino.core.util.ArrayUtil;
import fun.asgc.neutrino.core.util.Assert;
import fun.asgc.neutrino.core.util.StringUtil;
import fun.asgc.neutrino.core.util.TypeUtil;
import org.noear.solon.Solon;
import java.lang.reflect.Parameter;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* sqlmapper拦截器
* @author: aoshiguchen
* @date: 2022/6/28
*/
@NonIntercept
@Component
public class SqlMapperInterceptor implements Interceptor {
@Override
public void intercept(Invocation inv) throws Exception {
JdbcTemplate jdbcTemplate = Solon.context().getBean(JdbcTemplate.class);
Assert.notNull(jdbcTemplate, "JdbcTemplate未注入,调用失败!");
SqlParser sqlParser = SqlParser.getInstance(inv.getTargetMethod());
if (null == sqlParser) {
return;
}
String sql = sqlParser.getSql();
Class<?> resultType = sqlParser.getResultType();
Class<?> resultComponentType = sqlParser.getResultComponentType();
Object res = null;
if (sqlParser.isSelect()) {
if (sqlParser.isReturnCollection()) {
Object params = getParams(inv);
if (null == params || params.getClass().isArray()) {
res = jdbcTemplate.queryForList(resultComponentType, sql, inv.getArgs());
} else {
res = jdbcTemplate.queryForListByMap(resultComponentType, sql, (Map)params);
}
} else {
if (Page.class.isAssignableFrom(inv.getTargetMethod().getParameters()[0].getType())) {
// 分页查询 TODO 此处暂时临时处理,假设后面的参数是一个DO对象
Page page = (Page) inv.getArgs()[0];
int offset = (page.getCurrentPage() - 1) * page.getPageSize();
long total = jdbcTemplate.queryForLongByModel(String.format("select count(1) from (%s) T", sql), inv.getArgs()[1]);
List resultList = jdbcTemplate.queryForListByModel(resultComponentType, String.format("%s limit %s,%s", sql, offset, page.getPageSize()), inv.getArgs()[1]);
page.setTotal(total);
page.setRecords(resultList);
} else {
Object params = getParams(inv);
if (null == params || params.getClass().isArray()) {
res = jdbcTemplate.query(resultType, sql, inv.getArgs());
} else {
res = jdbcTemplate.queryByMap(resultType, sql, (Map)params);
}
}
}
} else if (sqlParser.isInsert() || sqlParser.isDelete() || sqlParser.isUpdate()) {
int argsCount = ArrayUtil.isEmpty(inv.getArgs()) ? 0 : inv.getArgs().length;
if (argsCount == 1 && inv.getArgs()[0] instanceof Map) {
res = jdbcTemplate.updateByMap(sql, (Map)inv.getArgs()[0]);
// 临时解决只有一个参数,且参数类型不是实体类型时,参数未起作用的情况
} else if (argsCount == 1 && !TypeUtil.isNormalBasicType(inv.getArgs()[0].getClass()) && !(inv.getArgs()[0] instanceof Date)) {
res = jdbcTemplate.updateByModel(sql, inv.getArgs()[0]);
} else {
Object params = getParams(inv);
if (null == params) {
res = jdbcTemplate.update(sql);
} else if (params.getClass().isArray()){
res = jdbcTemplate.update(sql, (Object[])params);
} else if (params instanceof Map) {
res = jdbcTemplate.updateByMap(sql, (Map)params);
}
}
}
inv.setReturnValue(TypeUtil.conversion(res, resultType));
}
/**
* 获取请求参数
* @param inv
* @return
*/
private Object getParams(Invocation inv) {
if (inv.getTargetMethod().getParameterCount() == 0) {
return null;
}
if (!inv.getTargetMethod().getParameters()[0].isAnnotationPresent(Param.class)) {
return inv.getArgs();
}
Map<String, Object> params = new HashMap<>();
for (int i = 0; i < inv.getTargetMethod().getParameterCount(); i++) {
Parameter parameter = inv.getTargetMethod().getParameters()[i];
Param param = parameter.getAnnotation(Param.class);
if (null == param) {
continue;
}
String key = param.value();
Object val = inv.getArgs()[i];
if (!StringUtil.isEmpty(key)) {
params.put(key, val);
}
}
return params;
}
}
@@ -22,12 +22,6 @@
package fun.asgc.neutrino.proxy.server.proxy.core;
import fun.asgc.neutrino.core.annotation.Autowired;
import fun.asgc.neutrino.core.annotation.Bean;
import fun.asgc.neutrino.core.annotation.Component;
import fun.asgc.neutrino.core.annotation.NonIntercept;
import fun.asgc.neutrino.core.context.ApplicationRunner;
import fun.asgc.neutrino.core.context.Environment;
import fun.asgc.neutrino.core.util.FileUtil;
import fun.asgc.neutrino.proxy.core.ProxyMessageDecoder;
import fun.asgc.neutrino.proxy.core.ProxyMessageEncoder;
@@ -41,8 +35,15 @@ import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.handler.ssl.SslHandler;
import io.netty.handler.timeout.IdleStateHandler;
import lombok.extern.slf4j.Slf4j;
import org.noear.solon.annotation.Component;
import org.noear.solon.annotation.Inject;
import org.noear.solon.core.event.AppLoadEndEvent;
import org.noear.solon.core.event.EventListener;
import javax.net.ssl.*;
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLEngine;
import javax.net.ssl.TrustManager;
import java.io.InputStream;
import java.security.KeyStore;
@@ -52,24 +53,29 @@ import java.security.KeyStore;
* @date: 2022/6/16
*/
@Slf4j
@NonIntercept
@Component
public class ProxyServerRunner implements ApplicationRunner {
@Autowired
public class ProxyServerRunner implements EventListener<AppLoadEndEvent> {
@Inject
private ProxyConfig proxyConfig;
@Autowired("serverBossGroup")
@Inject("serverBossGroup")
private NioEventLoopGroup serverBossGroup;
@Autowired("serverWorkerGroup")
@Inject("serverWorkerGroup")
private NioEventLoopGroup serverWorkerGroup;
@Autowired
private Environment environment;
@Inject("${neutrino.proxy.server.port}")
private Integer port;
@Inject("${neutrino.proxy.server.ssl-port}")
private Integer sslPort;
@Inject("${neutrino.proxy.server.jks-path}")
private String jksPath;
@Inject("${neutrino.proxy.server.key-store-password}")
private String keyStorePassword;
@Inject("${neutrino.proxy.server.key-manager-password}")
private String keyManagerPassword;
@Override
public void run(String[] args) {
public void onEvent(AppLoadEndEvent appLoadEndEvent) throws Throwable {
startProxyServer();
startProxyServerForSSL();
}
/**
* 启动代理服务
*/
@@ -83,7 +89,6 @@ public class ProxyServerRunner implements ApplicationRunner {
}
});
try {
Integer port = environment.getMainArgsForInteger("neutrino.proxy.server.port", proxyConfig.getServer().getPort());
bootstrap.bind(port).sync();
log.info("代理服务启动,端口:{}", port);
} catch (Exception e) {
@@ -92,7 +97,6 @@ public class ProxyServerRunner implements ApplicationRunner {
}
private void startProxyServerForSSL() {
Integer sslPort = environment.getMainArgsForInteger("neutrino.proxy.server.ssl-port", proxyConfig.getServer().getSslPort());
if (null == sslPort) {
return;
}
@@ -115,15 +119,12 @@ public class ProxyServerRunner implements ApplicationRunner {
private ChannelHandler createSslHandler() {
try {
String jksPath = environment.getMainArgsForString("neutrino.proxy.server.jks-path", proxyConfig.getServer().getJksPath());
InputStream jksInputStream = FileUtil.getInputStream(jksPath);
SSLContext serverContext = SSLContext.getInstance("TLS");
final KeyStore ks = KeyStore.getInstance("JKS");
String keyStorePassword = environment.getMainArgsForString("neutrino.proxy.server.key-store-password", proxyConfig.getServer().getKeyStorePassword());
ks.load(jksInputStream, keyStorePassword.toCharArray());
final KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
String keyManagerPassword = environment.getMainArgsForString("neutrino.proxy.server.key-manager-password", proxyConfig.getServer().getKeyManagerPassword());
kmf.init(ks, keyManagerPassword.toCharArray());
TrustManager[] trustManagers = null;
@@ -149,14 +150,4 @@ public class ProxyServerRunner implements ApplicationRunner {
ch.pipeline().addLast(new IdleStateHandler(proxyConfig.getProtocol().getReadIdleTime(), proxyConfig.getProtocol().getWriteIdleTime(), proxyConfig.getProtocol().getAllIdleTimeSeconds()));
ch.pipeline().addLast(new ServerChannelHandler());
}
@Bean
public NioEventLoopGroup serverBossGroup() {
return new NioEventLoopGroup();
}
@Bean
public NioEventLoopGroup serverWorkerGroup() {
return new NioEventLoopGroup();
}
}
@@ -23,7 +23,6 @@
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;
@@ -38,6 +37,7 @@ import io.netty.buffer.Unpooled;
import io.netty.channel.*;
import io.netty.handler.timeout.IdleStateEvent;
import lombok.extern.slf4j.Slf4j;
import org.noear.solon.Solon;
import java.util.Date;
@@ -51,7 +51,7 @@ public class ServerChannelHandler extends SimpleChannelInboundHandler<ProxyMessa
private static volatile Dispatcher<ChannelHandlerContext, ProxyMessage> dispatcher;
public ServerChannelHandler() {
dispatcher = BeanManager.getBean(Dispatcher.class);
dispatcher = Solon.context().getBean(Dispatcher.class);
}
@Override
@@ -87,8 +87,8 @@ public class ServerChannelHandler extends SimpleChannelInboundHandler<ProxyMessa
} else {
CmdChannelAttachInfo cmdChannelAttachInfo = ProxyUtil.getAttachInfo(ctx.channel());
if (null != cmdChannelAttachInfo) {
BeanManager.getBean(ProxyMutualService.class).offline(cmdChannelAttachInfo);
BeanManager.getBean(ClientConnectRecordService.class).add(new ClientConnectRecordDO()
Solon.context().getBean(ProxyMutualService.class).offline(cmdChannelAttachInfo);
Solon.context().getBean(ClientConnectRecordService.class).add(new ClientConnectRecordDO()
.setIp(ChannelUtil.getIP(ctx.channel()))
.setLicenseId(cmdChannelAttachInfo.getLicenseId())
.setType(ClientConnectTypeEnum.DISCONNECT.getType())
@@ -22,7 +22,6 @@
package fun.asgc.neutrino.proxy.server.proxy.core;
import fun.asgc.neutrino.core.util.BeanManager;
import fun.asgc.neutrino.core.util.StringUtil;
import fun.asgc.neutrino.proxy.core.Constants;
import fun.asgc.neutrino.proxy.core.ProxyMessage;
@@ -34,6 +33,7 @@ import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelOption;
import io.netty.channel.SimpleChannelInboundHandler;
import org.noear.solon.Solon;
import java.net.InetSocketAddress;
import java.util.concurrent.atomic.AtomicLong;
@@ -72,7 +72,7 @@ public class VisitorChannelHandler extends SimpleChannelInboundHandler<ByteBuf>
// 增加流量计数
VisitorChannelAttachInfo visitorChannelAttachInfo = ProxyUtil.getAttachInfo(visitorChannel);
BeanManager.getBean(FlowReportService.class).addWriteByte(visitorChannelAttachInfo.getLicenseId(), bytes.length);
Solon.context().getBean(FlowReportService.class).addWriteByte(visitorChannelAttachInfo.getLicenseId(), bytes.length);
}
}
@@ -22,10 +22,7 @@
package fun.asgc.neutrino.proxy.server.proxy.handler;
import fun.asgc.neutrino.core.annotation.Autowired;
import fun.asgc.neutrino.core.annotation.Component;
import fun.asgc.neutrino.core.annotation.Match;
import fun.asgc.neutrino.core.annotation.NonIntercept;
import fun.asgc.neutrino.core.util.ChannelUtil;
import fun.asgc.neutrino.core.util.StringUtil;
import fun.asgc.neutrino.proxy.core.*;
@@ -43,6 +40,8 @@ import fun.asgc.neutrino.proxy.server.util.ProxyUtil;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;
import org.noear.solon.annotation.Component;
import org.noear.solon.annotation.Inject;
import java.util.Date;
@@ -52,27 +51,26 @@ import java.util.Date;
* @date: 2022/6/16
*/
@Slf4j
@NonIntercept
@Match(type = Constants.ProxyDataTypeName.AUTH)
@Component
public class ProxyMessageAuthHandler implements ProxyMessageHandler {
@Autowired
@Inject
private ProxyConfig proxyConfig;
@Autowired
@Inject
private LicenseService licenseService;
@Autowired
@Inject
private UserService userService;
@Autowired
@Inject
private PortMappingService portMappingService;
@Autowired
@Inject
private ProxyMutualService proxyMutualService;
@Autowired
@Inject
private FlowReportService flowReportService;
@Autowired
@Inject
private ClientConnectRecordService clientConnectRecordService;
@Autowired
@Inject
private LicenseMapper licenseMapper;
@Autowired
@Inject
private VisitorChannelService visitorChannelService;
@Override
@@ -22,10 +22,7 @@
package fun.asgc.neutrino.proxy.server.proxy.handler;
import fun.asgc.neutrino.core.annotation.Autowired;
import fun.asgc.neutrino.core.annotation.Component;
import fun.asgc.neutrino.core.annotation.Match;
import fun.asgc.neutrino.core.annotation.NonIntercept;
import fun.asgc.neutrino.core.util.StringUtil;
import fun.asgc.neutrino.proxy.core.*;
import fun.asgc.neutrino.proxy.server.constant.EnableStatusEnum;
@@ -37,20 +34,20 @@ import fun.asgc.neutrino.proxy.server.util.ProxyUtil;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelOption;
import org.noear.solon.annotation.Component;
import org.noear.solon.annotation.Inject;
/**
*
* @author: aoshiguchen
* @date: 2022/6/16
*/
@NonIntercept
@Match(type = Constants.ProxyDataTypeName.CONNECT)
@Component
public class ProxyMessageConnectHandler implements ProxyMessageHandler {
@Autowired
@Inject
private LicenseService licenseService;
@Autowired
@Inject
private UserService userService;
@Override
@@ -22,9 +22,7 @@
package fun.asgc.neutrino.proxy.server.proxy.handler;
import fun.asgc.neutrino.core.annotation.Component;
import fun.asgc.neutrino.core.annotation.Match;
import fun.asgc.neutrino.core.annotation.NonIntercept;
import fun.asgc.neutrino.proxy.core.Constants;
import fun.asgc.neutrino.proxy.core.ProxyDataTypeEnum;
import fun.asgc.neutrino.proxy.core.ProxyMessage;
@@ -34,13 +32,13 @@ import io.netty.buffer.Unpooled;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext;
import org.noear.solon.annotation.Component;
/**
*
* @author: aoshiguchen
* @date: 2022/6/16
*/
@NonIntercept
@Match(type = Constants.ProxyDataTypeName.DISCONNECT)
@Component
public class ProxyMessageDisconnectHandler implements ProxyMessageHandler {
@@ -22,21 +22,19 @@
package fun.asgc.neutrino.proxy.server.proxy.handler;
import fun.asgc.neutrino.core.annotation.Component;
import fun.asgc.neutrino.core.annotation.Match;
import fun.asgc.neutrino.core.annotation.NonIntercept;
import fun.asgc.neutrino.proxy.core.Constants;
import fun.asgc.neutrino.proxy.core.ProxyDataTypeEnum;
import fun.asgc.neutrino.proxy.core.ProxyMessage;
import fun.asgc.neutrino.proxy.core.ProxyMessageHandler;
import io.netty.channel.ChannelHandlerContext;
import org.noear.solon.annotation.Component;
/**
*
* @author: aoshiguchen
* @date: 2022/6/16
*/
@NonIntercept
@Match(type = Constants.ProxyDataTypeName.HEARTBEAT)
@Component
public class ProxyMessageHeartbeatHandler implements ProxyMessageHandler {
@@ -22,10 +22,7 @@
package fun.asgc.neutrino.proxy.server.proxy.handler;
import fun.asgc.neutrino.core.annotation.Component;
import fun.asgc.neutrino.core.annotation.Match;
import fun.asgc.neutrino.core.annotation.NonIntercept;
import fun.asgc.neutrino.core.util.BeanManager;
import fun.asgc.neutrino.proxy.core.Constants;
import fun.asgc.neutrino.proxy.core.ProxyDataTypeEnum;
import fun.asgc.neutrino.proxy.core.ProxyMessage;
@@ -36,13 +33,14 @@ import fun.asgc.neutrino.proxy.server.util.ProxyUtil;
import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import org.noear.solon.Solon;
import org.noear.solon.annotation.Component;
/**
*
* @author: aoshiguchen
* @date: 2022/6/16
*/
@NonIntercept
@Match(type = Constants.ProxyDataTypeName.TRANSFER)
@Component
public class ProxyMessageTransferHandler implements ProxyMessageHandler {
@@ -57,7 +55,7 @@ public class ProxyMessageTransferHandler implements ProxyMessageHandler {
// 增加流量计数
VisitorChannelAttachInfo visitorChannelAttachInfo = ProxyUtil.getAttachInfo(visitorChannel);
BeanManager.getBean(FlowReportService.class).addReadByte(visitorChannelAttachInfo.getLicenseId(), proxyMessage.getData().length);
Solon.context().getBean(FlowReportService.class).addReadByte(visitorChannelAttachInfo.getLicenseId(), proxyMessage.getData().length);
}
}
@@ -21,9 +21,6 @@
*/
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.core.db.page.Page;
import fun.asgc.neutrino.core.db.page.PageQuery;
import fun.asgc.neutrino.core.util.CollectionUtil;
@@ -37,6 +34,8 @@ 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.UserDO;
import lombok.extern.slf4j.Slf4j;
import org.noear.solon.annotation.Component;
import org.noear.solon.annotation.Inject;
import java.util.List;
import java.util.Map;
@@ -49,14 +48,13 @@ import java.util.stream.Collectors;
* @date: 2022/11/23
*/
@Slf4j
@NonIntercept
@Component
public class ClientConnectRecordService {
@Autowired
@Inject
private ClientConnectRecordMapper clientConnectRecordMapper;
@Autowired
@Inject
private LicenseMapper licenseMapper;
@Autowired
@Inject
private UserMapper userMapper;
public void add(ClientConnectRecordDO clientConnectRecordDO) {
@@ -21,10 +21,9 @@
*/
package fun.asgc.neutrino.proxy.server.service;
import fun.asgc.neutrino.core.annotation.Component;
import fun.asgc.neutrino.core.annotation.NonIntercept;
import fun.asgc.neutrino.core.util.LockUtil;
import lombok.extern.slf4j.Slf4j;
import org.noear.solon.annotation.Component;
import java.util.HashMap;
import java.util.Map;
@@ -36,7 +35,6 @@ import java.util.concurrent.atomic.AtomicInteger;
* @date: 2022/10/26
*/
@Slf4j
@NonIntercept
@Component
public class FlowReportService {
private Map<Integer/*licenseId*/, AtomicInteger/*writeByte*/> writeByteMap = new HashMap<>();
@@ -22,24 +22,29 @@
package fun.asgc.neutrino.proxy.server.service;
import com.google.common.collect.Lists;
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.core.db.page.Page;
import fun.asgc.neutrino.core.db.page.PageQuery;
import fun.asgc.neutrino.core.quartz.IJobSource;
import fun.asgc.neutrino.core.quartz.JobExecutor;
import fun.asgc.neutrino.core.quartz.JobInfo;
import fun.asgc.neutrino.core.util.BeanManager;
import fun.asgc.neutrino.core.util.CollectionUtil;
import fun.asgc.neutrino.proxy.server.constant.EnableStatusEnum;
import fun.asgc.neutrino.proxy.server.constant.ExceptionConstant;
import fun.asgc.neutrino.proxy.server.controller.req.*;
import fun.asgc.neutrino.proxy.server.controller.res.*;
import fun.asgc.neutrino.proxy.server.controller.req.JobInfoExecuteReq;
import fun.asgc.neutrino.proxy.server.controller.req.JobInfoListReq;
import fun.asgc.neutrino.proxy.server.controller.req.JobInfoUpdateEnableStatusReq;
import fun.asgc.neutrino.proxy.server.controller.req.JobInfoUpdateReq;
import fun.asgc.neutrino.proxy.server.controller.res.JobInfoExecuteRes;
import fun.asgc.neutrino.proxy.server.controller.res.JobInfoListRes;
import fun.asgc.neutrino.proxy.server.controller.res.JobInfoUpdateEnableStatusRes;
import fun.asgc.neutrino.proxy.server.controller.res.JobInfoUpdateRes;
import fun.asgc.neutrino.proxy.server.dal.JobInfoMapper;
import fun.asgc.neutrino.proxy.server.dal.entity.JobInfoDO;
import fun.asgc.neutrino.proxy.server.util.ParamCheckUtil;
import lombok.extern.slf4j.Slf4j;
import org.noear.solon.Solon;
import org.noear.solon.annotation.Component;
import org.noear.solon.annotation.Inject;
import java.util.Date;
import java.util.List;
@@ -50,11 +55,9 @@ import java.util.List;
* @date: 2022/9/5
*/
@Slf4j
@NonIntercept
@Component
public class JobInfoService implements IJobSource {
@Autowired
@Inject
private JobInfoMapper jobInfoMapper;
public Page<JobInfoListRes> page(PageQuery pageQuery, JobInfoListReq req) {
@@ -73,7 +76,7 @@ public class JobInfoService implements IJobSource {
ParamCheckUtil.checkNotNull(jobInfoDO, ExceptionConstant.JOB_INFO_NOT_EXIST);
jobInfoMapper.updateEnableStatus(req.getId(), req.getEnable(), new Date());
if (EnableStatusEnum.ENABLE.getStatus().equals(req.getEnable())) {
BeanManager.getBean(JobExecutor.class).add(new JobInfo()
Solon.context().getBean(JobExecutor.class).add(new JobInfo()
.setId(String.valueOf(jobInfoDO.getId()))
.setName(jobInfoDO.getHandler())
.setDesc(jobInfoDO.getDesc())
@@ -82,13 +85,13 @@ public class JobInfoService implements IJobSource {
.setEnable(true)
);
} else {
BeanManager.getBean(JobExecutor.class).remove(String.valueOf(req.getId()));
Solon.context().getBean(JobExecutor.class).remove(String.valueOf(req.getId()));
}
return new JobInfoUpdateEnableStatusRes();
}
public JobInfoExecuteRes execute(JobInfoExecuteReq req) {
BeanManager.getBean(JobExecutor.class).trigger(String.valueOf(req.getId()), req.getParam());
Solon.context().getBean(JobExecutor.class).trigger(String.valueOf(req.getId()), req.getParam());
return new JobInfoExecuteRes();
}
@@ -21,21 +21,18 @@
*/
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.core.db.page.Page;
import fun.asgc.neutrino.core.db.page.PageQuery;
import fun.asgc.neutrino.core.quartz.IJobCallback;
import fun.asgc.neutrino.core.quartz.JobInfo;
import fun.asgc.neutrino.proxy.server.controller.req.JobInfoListReq;
import fun.asgc.neutrino.proxy.server.controller.req.JobLogListReq;
import fun.asgc.neutrino.proxy.server.controller.res.JobInfoListRes;
import fun.asgc.neutrino.proxy.server.controller.res.JobLogListRes;
import fun.asgc.neutrino.proxy.server.dal.JobLogMapper;
import fun.asgc.neutrino.proxy.server.dal.entity.JobLogDO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.noear.solon.annotation.Component;
import org.noear.solon.annotation.Inject;
import java.util.Date;
@@ -45,10 +42,9 @@ import java.util.Date;
* @date: 2022/9/4
*/
@Slf4j
@NonIntercept
@Component
public class JobLogService implements IJobCallback {
@Autowired
@Inject
private JobLogMapper jobLogMapper;
@Override
@@ -22,7 +22,6 @@
package fun.asgc.neutrino.proxy.server.service;
import com.google.common.collect.Sets;
import fun.asgc.neutrino.core.annotation.*;
import fun.asgc.neutrino.core.db.page.Page;
import fun.asgc.neutrino.core.db.page.PageQuery;
import fun.asgc.neutrino.core.util.CollectionUtil;
@@ -40,6 +39,9 @@ import fun.asgc.neutrino.proxy.server.dal.UserMapper;
import fun.asgc.neutrino.proxy.server.dal.entity.LicenseDO;
import fun.asgc.neutrino.proxy.server.dal.entity.UserDO;
import fun.asgc.neutrino.proxy.server.util.ParamCheckUtil;
import org.noear.solon.annotation.Component;
import org.noear.solon.annotation.Inject;
import org.noear.solon.core.Lifecycle;
import java.util.*;
import java.util.function.Function;
@@ -50,15 +52,14 @@ import java.util.stream.Collectors;
* @author: aoshiguchen
* @date: 2022/8/6
*/
@NonIntercept
@Component
public class LicenseService {
public class LicenseService implements Lifecycle {
@Autowired
@Inject
private LicenseMapper licenseMapper;
@Autowired
@Inject
private UserMapper userMapper;
@Autowired
@Inject
private VisitorChannelService visitorChannelService;
public Page<LicenseListRes> page(PageQuery pageQuery, LicenseListReq req) {
@@ -209,9 +210,16 @@ public class LicenseService {
/**
* 服务端项目停止、启动时,更新在线状态为离线
*/
@Init
@Destroy
public void destroy() {
@Override
public void start() throws Throwable {
licenseMapper.updateOnlineStatus(OnlineStatusEnum.OFFLINE.getStatus(), new Date());
}
/**
* 服务端项目停止、启动时,更新在线状态为离线
*/
@Override
public void stop() throws Throwable {
licenseMapper.updateOnlineStatus(OnlineStatusEnum.OFFLINE.getStatus(), new Date());
}
}
@@ -22,7 +22,6 @@
package fun.asgc.neutrino.proxy.server.service;
import com.google.common.collect.Sets;
import fun.asgc.neutrino.core.annotation.*;
import fun.asgc.neutrino.core.db.page.Page;
import fun.asgc.neutrino.core.db.page.PageQuery;
import fun.asgc.neutrino.core.util.CollectionUtil;
@@ -44,6 +43,9 @@ import fun.asgc.neutrino.proxy.server.dal.entity.PortMappingDO;
import fun.asgc.neutrino.proxy.server.dal.entity.PortPoolDO;
import fun.asgc.neutrino.proxy.server.dal.entity.UserDO;
import fun.asgc.neutrino.proxy.server.util.ParamCheckUtil;
import org.noear.solon.annotation.Component;
import org.noear.solon.annotation.Inject;
import org.noear.solon.core.Lifecycle;
import java.util.Date;
import java.util.List;
@@ -57,18 +59,17 @@ import java.util.stream.Collectors;
* @author: aoshiguchen
* @date: 2022/8/8
*/
@NonIntercept
@Component
public class PortMappingService {
@Autowired
public class PortMappingService implements Lifecycle {
@Inject
private PortMappingMapper portMappingMapper;
@Autowired
@Inject
private LicenseMapper licenseMapper;
@Autowired
@Inject
private UserMapper userMapper;
@Autowired
@Inject
private PortPoolMapper portPoolMapper;
@Autowired
@Inject
private VisitorChannelService visitorChannelService;
public Page<PortMappingListRes> page(PageQuery pageQuery, PortMappingListReq req) {
@@ -243,10 +244,16 @@ public class PortMappingService {
/**
* 服务端项目停止、启动时,更新在线状态为离线
*/
@Init
@Destroy
public void destroy() {
@Override
public void start() throws Throwable {
portMappingMapper.updateOnlineStatus(OnlineStatusEnum.OFFLINE.getStatus(), new Date());
}
/**
* 服务端项目停止、启动时,更新在线状态为离线
*/
@Override
public void stop() throws Throwable {
portMappingMapper.updateOnlineStatus(OnlineStatusEnum.OFFLINE.getStatus(), new Date());
}
}
@@ -21,9 +21,6 @@
*/
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.core.db.page.Page;
import fun.asgc.neutrino.core.db.page.PageQuery;
import fun.asgc.neutrino.proxy.server.constant.EnableStatusEnum;
@@ -37,6 +34,8 @@ import fun.asgc.neutrino.proxy.server.controller.res.PortPoolUpdateEnableStatusR
import fun.asgc.neutrino.proxy.server.dal.PortPoolMapper;
import fun.asgc.neutrino.proxy.server.dal.entity.PortPoolDO;
import fun.asgc.neutrino.proxy.server.util.ParamCheckUtil;
import org.noear.solon.annotation.Component;
import org.noear.solon.annotation.Inject;
import java.util.Date;
import java.util.List;
@@ -46,13 +45,12 @@ import java.util.List;
* @author: aoshiguchen
* @date: 2022/8/7
*/
@NonIntercept
@Component
public class PortPoolService {
@Autowired
@Inject
private PortPoolMapper portPoolMapper;
@Autowired
@Inject
private VisitorChannelService visitorChannelService;
public Page<PortPoolListRes> page(PageQuery pageQuery, PortPoolListReq req) {
@@ -21,14 +21,13 @@
*/
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.constant.OnlineStatusEnum;
import fun.asgc.neutrino.proxy.server.dal.LicenseMapper;
import fun.asgc.neutrino.proxy.server.dal.PortMappingMapper;
import fun.asgc.neutrino.proxy.server.proxy.domain.CmdChannelAttachInfo;
import lombok.extern.slf4j.Slf4j;
import org.noear.solon.annotation.Component;
import org.noear.solon.annotation.Inject;
import java.util.Date;
@@ -38,12 +37,11 @@ import java.util.Date;
* @date: 2022/9/3
*/
@Slf4j
@NonIntercept
@Component
public class ProxyMutualService {
@Autowired
@Inject
private PortMappingMapper portMappingMapper;
@Autowired
@Inject
private LicenseMapper licenseMapper;
/**
@@ -21,9 +21,6 @@
*/
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.core.db.page.Page;
import fun.asgc.neutrino.core.db.page.PageQuery;
import fun.asgc.neutrino.proxy.server.controller.req.LicenseFlowReportReq;
@@ -32,17 +29,17 @@ import fun.asgc.neutrino.proxy.server.controller.res.LicenseFlowReportRes;
import fun.asgc.neutrino.proxy.server.controller.res.UserFlowReportRes;
import fun.asgc.neutrino.proxy.server.dal.UserReportMapper;
import lombok.extern.slf4j.Slf4j;
import org.noear.solon.annotation.Component;
import org.noear.solon.annotation.Inject;
/**
* @author: aoshiguchen
* @date: 2022/12/23
*/
@Slf4j
@NonIntercept
@Component
public class ReportService {
@Autowired
@Inject
private UserReportMapper userReportMapper;
/**
@@ -21,9 +21,6 @@
*/
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.core.db.page.Page;
import fun.asgc.neutrino.core.db.page.PageQuery;
import fun.asgc.neutrino.core.util.CollectionUtil;
@@ -32,6 +29,8 @@ import fun.asgc.neutrino.proxy.server.controller.res.UserLoginRecordListRes;
import fun.asgc.neutrino.proxy.server.dal.UserLoginRecordMapper;
import fun.asgc.neutrino.proxy.server.dal.UserMapper;
import fun.asgc.neutrino.proxy.server.dal.entity.UserDO;
import org.noear.solon.annotation.Component;
import org.noear.solon.annotation.Inject;
import java.util.List;
import java.util.Map;
@@ -44,12 +43,11 @@ import java.util.stream.Collectors;
* @author: aoshiguchen
* @date: 2022/10/20
*/
@NonIntercept
@Component
public class UserLoginRecordService {
@Autowired
@Inject
private UserLoginRecordMapper userLoginRecordMapper;
@Autowired
@Inject
private UserMapper userMapper;
public Page<UserLoginRecordListRes> page(PageQuery pageQuery, UserLoginRecordListReq req) {
@@ -21,9 +21,6 @@
*/
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.core.db.page.Page;
import fun.asgc.neutrino.core.db.page.PageQuery;
import fun.asgc.neutrino.core.util.DateUtil;
@@ -41,6 +38,8 @@ import fun.asgc.neutrino.proxy.server.dal.entity.UserLoginRecordDO;
import fun.asgc.neutrino.proxy.server.dal.entity.UserTokenDO;
import fun.asgc.neutrino.proxy.server.util.Md5Util;
import fun.asgc.neutrino.proxy.server.util.ParamCheckUtil;
import org.noear.solon.annotation.Component;
import org.noear.solon.annotation.Inject;
import java.util.Calendar;
import java.util.Date;
@@ -52,17 +51,16 @@ import java.util.UUID;
* @author: aoshiguchen
* @date: 2022/7/31
*/
@NonIntercept
@Component
public class UserService {
private static final String DEFAULT_PASSWORD = "123456";
@Autowired
@Inject
private UserMapper userMapper;
@Autowired
@Inject
private UserTokenMapper userTokenMapper;
@Autowired
@Inject
private UserLoginRecordMapper userLoginRecordMapper;
@Autowired
@Inject
private VisitorChannelService visitorChannelService;
public LoginRes login(LoginReq req) {
@@ -23,9 +23,6 @@ package fun.asgc.neutrino.proxy.server.service;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
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.core.util.CollectionUtil;
import fun.asgc.neutrino.proxy.core.Constants;
import fun.asgc.neutrino.proxy.server.constant.EnableStatusEnum;
@@ -49,6 +46,8 @@ import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import lombok.extern.slf4j.Slf4j;
import org.noear.solon.annotation.Component;
import org.noear.solon.annotation.Inject;
import java.net.BindException;
import java.util.List;
@@ -60,22 +59,21 @@ import java.util.stream.Collectors;
* @date: 2023/2/5
*/
@Slf4j
@NonIntercept
@Component
public class VisitorChannelService {
@Autowired("serverBossGroup")
@Inject("serverBossGroup")
private NioEventLoopGroup serverBossGroup;
@Autowired("serverWorkerGroup")
@Inject("serverWorkerGroup")
private NioEventLoopGroup serverWorkerGroup;
@Autowired
@Inject
private ProxyMutualService proxyMutualService;
@Autowired
@Inject
private UserMapper userMapper;
@Autowired
@Inject
private LicenseMapper licenseMapper;
@Autowired
@Inject
private PortMappingMapper portMappingMapper;
@Autowired
@Inject
private PortPoolMapper portPoolMapper;
/**
@@ -0,0 +1,2 @@
solon.plugin=fun.asgc.neutrino.proxy.server.db.MapperPlugin
solon.plugin.priority=3
@@ -1,15 +1,7 @@
neutrino:
application:
name: neutrino-proxy-server
http:
enable: true
port: 8888
context-path: /
max-content-length-desc: 128K
static-resource:
locations:
- "neutrino-proxy-admin/dist/"
server:
port: 8081
neutrino:
proxy:
protocol:
max-frame-length: 2097152
@@ -31,8 +23,15 @@ neutrino:
type: sqlite
url: jdbc:sqlite:data.db
driver-class: org.sqlite.JDBC
# type: mysql
# url: jdbc:mysql://103.163.47.16:3306/neutrino-proxy?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&useAffectedRows=true&useSSL=false
# driver-class: com.mysql.jdbc.Driver
# username: "******"
# password: "******"
username:
password:
#添加MIME印射(如果有需要?)
#是否启用静态文件服务。(可不配,默认为启用)
solon.staticfiles.enable: true
#静态文件的304缓存时长。(可不配,默认为10分钟)
solon.staticfiles.maxAge: 600
#添加静态目录映射。(按需选择)#v1.11.0 后支持
solon.staticfiles.mappings:
- path: "/"
repository: "./neutrino-proxy-admin/dist/" #2.添加资源路径(仓库只能是目录)
+7
View File
@@ -9,6 +9,13 @@
<packaging>pom</packaging>
<version>${revision}</version>
<parent>
<groupId>org.noear</groupId>
<artifactId>solon-parent</artifactId>
<version>2.2.1</version>
<relativePath />
</parent>
<modules>
<module>neutrino-core</module>
<module>neutrino-proxy-core</module>