mirror of
https://github.com/Sagit-chu/flvx.git
synced 2026-09-29 16:06:36 +08:00
test
This commit is contained in:
@@ -91,13 +91,8 @@ public class FlowController extends BaseController {
|
||||
if (!Objects.equals(userTunnelId, DEFAULT_USER_TUNNEL_ID)) {
|
||||
userTunnel = userTunnelService.getById(userTunnelId);
|
||||
}
|
||||
System.out.println(flowDataList);
|
||||
// 4. 处理流量倍率
|
||||
List<FlowDto> validFlowData = flowDataList;
|
||||
if (forward != null) {
|
||||
validFlowData = filterFlowData(flowDataList, forward.getTunnelId());
|
||||
}
|
||||
System.out.println(validFlowData);
|
||||
List<FlowDto> validFlowData = filterFlowData(flowDataList, forward);
|
||||
|
||||
|
||||
|
||||
@@ -146,20 +141,23 @@ public class FlowController extends BaseController {
|
||||
|
||||
|
||||
|
||||
private List<FlowDto> filterFlowData(List<FlowDto> flowDataList, Integer tunnel_id) {
|
||||
Tunnel tunnel = tunnelService.getById(tunnel_id);
|
||||
if (tunnel != null && tunnel.getTrafficRatio() != null){
|
||||
BigDecimal trafficRatio = tunnel.getTrafficRatio();
|
||||
for (FlowDto flowDto : flowDataList) {
|
||||
// 将Long转为BigDecimal进行计算,然后转回Long
|
||||
BigDecimal originalD = BigDecimal.valueOf(flowDto.getD());
|
||||
BigDecimal originalU = BigDecimal.valueOf(flowDto.getU());
|
||||
|
||||
BigDecimal newD = originalD.multiply(trafficRatio);
|
||||
BigDecimal newU = originalU.multiply(trafficRatio);
|
||||
|
||||
flowDto.setD(newD.longValue());
|
||||
flowDto.setU(newU.longValue());
|
||||
private List<FlowDto> filterFlowData(List<FlowDto> flowDataList, Forward forward) {
|
||||
if (forward != null) {
|
||||
Tunnel tunnel = tunnelService.getById(forward.getTunnelId());
|
||||
if (tunnel != null){
|
||||
BigDecimal trafficRatio = tunnel.getTrafficRatio();
|
||||
for (FlowDto flowDto : flowDataList) {
|
||||
System.out.println(flowDto);
|
||||
BigDecimal originalD = BigDecimal.valueOf(flowDto.getD());
|
||||
BigDecimal originalU = BigDecimal.valueOf(flowDto.getU());
|
||||
|
||||
BigDecimal newD = originalD.multiply(trafficRatio);
|
||||
BigDecimal newU = originalU.multiply(trafficRatio);
|
||||
|
||||
flowDto.setD(newD.longValue());
|
||||
flowDto.setU(newU.longValue());
|
||||
System.out.println(flowDto);
|
||||
}
|
||||
}
|
||||
}
|
||||
return flowDataList;
|
||||
|
||||
@@ -846,22 +846,7 @@ public class TunnelServiceImpl extends ServiceImpl<TunnelMapper, Tunnel> impleme
|
||||
result.setTimestamp(System.currentTimeMillis());
|
||||
|
||||
try {
|
||||
// 首先检查节点的WebSocket连接状态
|
||||
if (!isNodeWebSocketConnected(node.getId())) {
|
||||
// 如果WebSocket连接有问题,更新节点状态并返回错误
|
||||
node.setStatus(0); // 标记为离线
|
||||
nodeService.updateById(node);
|
||||
|
||||
result.setSuccess(false);
|
||||
result.setMessage("节点WebSocket连接已断开,请检查节点是否正常运行");
|
||||
result.setAverageTime(-1.0);
|
||||
result.setPacketLoss(100.0);
|
||||
return result;
|
||||
}
|
||||
|
||||
// 如果连接正常,执行标准的ping诊断
|
||||
return performPingDiagnosis(node, targetIp, description);
|
||||
|
||||
} catch (Exception e) {
|
||||
result.setSuccess(false);
|
||||
result.setMessage("连接检查异常: " + e.getMessage());
|
||||
@@ -871,31 +856,6 @@ public class TunnelServiceImpl extends ServiceImpl<TunnelMapper, Tunnel> impleme
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查节点的WebSocket连接是否有效
|
||||
*
|
||||
* @param nodeId 节点ID
|
||||
* @return 连接是否有效
|
||||
*/
|
||||
private boolean isNodeWebSocketConnected(Long nodeId) {
|
||||
try {
|
||||
// 发送一个简单的测试ping,超时时间设为3秒
|
||||
JSONObject testData = new JSONObject();
|
||||
testData.put("ip", "127.0.0.1");
|
||||
testData.put("count", 1);
|
||||
|
||||
GostDto testResult = WebSocketServer.send_msg(nodeId, testData, "Ping");
|
||||
|
||||
// 如果能收到任何响应(不管是成功还是失败),说明WebSocket连接正常
|
||||
return testResult != null &&
|
||||
!testResult.getMsg().equals("节点不在线") &&
|
||||
!testResult.getMsg().equals("节点连接已断开") &&
|
||||
!testResult.getMsg().equals("等待响应超时");
|
||||
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// ========== 内部数据类 ==========
|
||||
|
||||
|
||||
Reference in New Issue
Block a user