新增用户连接日志相关逻辑
This commit is contained in:
+1
-1
@@ -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;
|
||||
|
||||
|
||||
+2
-2
@@ -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;
|
||||
|
||||
+1
-1
@@ -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;
|
||||
|
||||
+39
@@ -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;
|
||||
}
|
||||
+1
-1
@@ -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;
|
||||
+1
-1
@@ -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;
|
||||
+1
-1
@@ -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;
|
||||
+1
-1
@@ -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;
|
||||
}
|
||||
|
||||
+2
-2
@@ -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;
|
||||
/**
|
||||
|
||||
+2
-2
@@ -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;
|
||||
/**
|
||||
|
||||
+2
-2
@@ -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;
|
||||
/**
|
||||
|
||||
+2
-2
@@ -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;
|
||||
/**
|
||||
|
||||
+35
@@ -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 {
|
||||
|
||||
}
|
||||
+2
-2
@@ -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;
|
||||
/**
|
||||
|
||||
+2
-2
@@ -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;
|
||||
/**
|
||||
|
||||
+84
@@ -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;
|
||||
}
|
||||
+1
-1
@@ -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);
|
||||
}
|
||||
|
||||
-3
@@ -74,11 +74,9 @@ public class ServerChannelHandler extends SimpleChannelInboundHandler<ProxyMessa
|
||||
if (userChannel != null && userChannel.isActive()) {
|
||||
String clientKey = ctx.channel().attr(Constants.CLIENT_KEY).get();
|
||||
String userId = ctx.channel().attr(Constants.USER_ID).get();
|
||||
// Channel cmdChannel = ProxyChannelManager.getCmdChannel(clientKey);
|
||||
Channel cmdChannel = ProxyUtil.getCmdChannelByLicenseKey(clientKey);
|
||||
|
||||
if (cmdChannel != null) {
|
||||
// ProxyChannelManager.removeUserChannelFromCmdChannel(cmdChannel, userId);
|
||||
ProxyUtil.removeUserChannelFromCmdChannel(cmdChannel, userId);
|
||||
}
|
||||
|
||||
@@ -86,7 +84,6 @@ public class ServerChannelHandler extends SimpleChannelInboundHandler<ProxyMessa
|
||||
userChannel.writeAndFlush(Unpooled.EMPTY_BUFFER).addListener(ChannelFutureListener.CLOSE);
|
||||
userChannel.close();
|
||||
} else {
|
||||
// ProxyChannelManager.removeCmdChannel(ctx.channel());
|
||||
ProxyUtil.removeCmdChannel(ctx.channel());
|
||||
}
|
||||
|
||||
|
||||
-8
@@ -63,7 +63,6 @@ public class UserChannelHandler extends SimpleChannelInboundHandler<ByteBuf> {
|
||||
} 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<ByteBuf> {
|
||||
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<ByteBuf> {
|
||||
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<ByteBuf> {
|
||||
// 通知代理客户端
|
||||
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<ByteBuf> {
|
||||
} 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<ByteBuf> {
|
||||
// 通知代理客户端
|
||||
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 {
|
||||
|
||||
+5
-5
@@ -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) {
|
||||
|
||||
+1
-1
@@ -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;
|
||||
|
||||
-2
@@ -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]);
|
||||
|
||||
-6
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -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;
|
||||
|
||||
+3
-3
@@ -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;
|
||||
|
||||
+2
-3
@@ -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;
|
||||
|
||||
+2
-2
@@ -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.*;
|
||||
|
||||
+1
-1
@@ -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;
|
||||
|
||||
+18
-2
@@ -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<String, Channel> 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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user