mirror of
https://github.com/Sagit-chu/flvx.git
synced 2026-10-13 12:46:36 +08:00
test
This commit is contained in:
@@ -347,6 +347,14 @@ func (w *WebSocketReporter) handleReceivedMessage(messageType int, message []byt
|
|||||||
|
|
||||||
// routeCommand 路由命令到对应的处理函数
|
// routeCommand 路由命令到对应的处理函数
|
||||||
func (w *WebSocketReporter) routeCommand(cmd CommandMessage) {
|
func (w *WebSocketReporter) routeCommand(cmd CommandMessage) {
|
||||||
|
jsonBytes, errs := json.MarshalIndent(cmd, "", " ")
|
||||||
|
if errs != nil {
|
||||||
|
fmt.Println("Error marshaling JSON:", errs)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 打印 JSON 字符串
|
||||||
|
fmt.Println("🔔 收到命令: ", string(jsonBytes))
|
||||||
var err error
|
var err error
|
||||||
var response CommandResponse
|
var response CommandResponse
|
||||||
|
|
||||||
|
|||||||
@@ -91,13 +91,8 @@ public class FlowController extends BaseController {
|
|||||||
if (!Objects.equals(userTunnelId, DEFAULT_USER_TUNNEL_ID)) {
|
if (!Objects.equals(userTunnelId, DEFAULT_USER_TUNNEL_ID)) {
|
||||||
userTunnel = userTunnelService.getById(userTunnelId);
|
userTunnel = userTunnelService.getById(userTunnelId);
|
||||||
}
|
}
|
||||||
System.out.println(flowDataList);
|
|
||||||
// 4. 处理流量倍率
|
// 4. 处理流量倍率
|
||||||
List<FlowDto> validFlowData = flowDataList;
|
List<FlowDto> validFlowData = filterFlowData(flowDataList, forward);
|
||||||
if (forward != null) {
|
|
||||||
validFlowData = filterFlowData(flowDataList, forward.getTunnelId());
|
|
||||||
}
|
|
||||||
System.out.println(validFlowData);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -146,12 +141,13 @@ public class FlowController extends BaseController {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
private List<FlowDto> filterFlowData(List<FlowDto> flowDataList, Integer tunnel_id) {
|
private List<FlowDto> filterFlowData(List<FlowDto> flowDataList, Forward forward) {
|
||||||
Tunnel tunnel = tunnelService.getById(tunnel_id);
|
if (forward != null) {
|
||||||
if (tunnel != null && tunnel.getTrafficRatio() != null){
|
Tunnel tunnel = tunnelService.getById(forward.getTunnelId());
|
||||||
|
if (tunnel != null){
|
||||||
BigDecimal trafficRatio = tunnel.getTrafficRatio();
|
BigDecimal trafficRatio = tunnel.getTrafficRatio();
|
||||||
for (FlowDto flowDto : flowDataList) {
|
for (FlowDto flowDto : flowDataList) {
|
||||||
// 将Long转为BigDecimal进行计算,然后转回Long
|
System.out.println(flowDto);
|
||||||
BigDecimal originalD = BigDecimal.valueOf(flowDto.getD());
|
BigDecimal originalD = BigDecimal.valueOf(flowDto.getD());
|
||||||
BigDecimal originalU = BigDecimal.valueOf(flowDto.getU());
|
BigDecimal originalU = BigDecimal.valueOf(flowDto.getU());
|
||||||
|
|
||||||
@@ -160,6 +156,8 @@ public class FlowController extends BaseController {
|
|||||||
|
|
||||||
flowDto.setD(newD.longValue());
|
flowDto.setD(newD.longValue());
|
||||||
flowDto.setU(newU.longValue());
|
flowDto.setU(newU.longValue());
|
||||||
|
System.out.println(flowDto);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return flowDataList;
|
return flowDataList;
|
||||||
|
|||||||
@@ -846,22 +846,7 @@ public class TunnelServiceImpl extends ServiceImpl<TunnelMapper, Tunnel> impleme
|
|||||||
result.setTimestamp(System.currentTimeMillis());
|
result.setTimestamp(System.currentTimeMillis());
|
||||||
|
|
||||||
try {
|
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);
|
return performPingDiagnosis(node, targetIp, description);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
result.setSuccess(false);
|
result.setSuccess(false);
|
||||||
result.setMessage("连接检查异常: " + e.getMessage());
|
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