修复v6 添加隧道类型选择

This commit is contained in:
qaq
2025-06-18 11:13:41 +08:00
parent d56c94fd43
commit 8ddd65a58c
19 changed files with 568 additions and 88 deletions
@@ -536,13 +536,13 @@ public class ForwardServiceImpl extends ServiceImpl<ForwardMapper, Forward> impl
// 隧道转发需要创建链和远程服务
if (tunnel.getType() == TUNNEL_TYPE_TUNNEL_FORWARD) {
R chainResult = createChainService(inNode, serviceName, tunnel.getOutIp(), forward.getOutPort());
R chainResult = createChainService(inNode, serviceName, tunnel.getOutIp(), forward.getOutPort(), tunnel.getProtocol());
if (chainResult.getCode() != 0) {
updateForwardStatusToError(forward);
return chainResult;
}
R remoteResult = createRemoteService(tunnel.getOutNodeId().intValue(), serviceName, forward);
R remoteResult = createRemoteService(tunnel.getOutNodeId().intValue(), serviceName, forward, tunnel.getProtocol());
if (remoteResult.getCode() != 0) {
updateForwardStatusToError(forward);
return remoteResult;
@@ -568,13 +568,13 @@ public class ForwardServiceImpl extends ServiceImpl<ForwardMapper, Forward> impl
// 隧道转发需要更新链和远程服务
if (tunnel.getType() == TUNNEL_TYPE_TUNNEL_FORWARD) {
R chainResult = updateChainService(inNode, serviceName, tunnel.getOutIp(), forward.getOutPort());
R chainResult = updateChainService(inNode, serviceName, tunnel.getOutIp(), forward.getOutPort(), tunnel.getProtocol());
if (chainResult.getCode() != 0) {
updateForwardStatusToError(forward);
return chainResult;
}
R remoteResult = updateRemoteService(tunnel.getOutNodeId().intValue(), serviceName, forward);
R remoteResult = updateRemoteService(tunnel.getOutNodeId().intValue(), serviceName, forward, tunnel.getProtocol());
if (remoteResult.getCode() != 0) {
updateForwardStatusToError(forward);
return remoteResult;
@@ -624,20 +624,20 @@ public class ForwardServiceImpl extends ServiceImpl<ForwardMapper, Forward> impl
/**
* 创建链服务
*/
private R createChainService(Node inNode, String serviceName, String outIp, Integer outPort) {
private R createChainService(Node inNode, String serviceName, String outIp, Integer outPort, String protocol) {
String remoteAddr = outIp + ":" + outPort;
GostDto result = GostUtil.AddChains(inNode.getIp() + ":" + inNode.getPort(), serviceName, remoteAddr, inNode.getSecret());
GostDto result = GostUtil.AddChains(inNode.getIp() + ":" + inNode.getPort(), serviceName, remoteAddr, inNode.getSecret(), protocol);
return isGostOperationSuccess(result) ? R.ok() : R.err(result.getMsg());
}
/**
* 创建远程服务
*/
private R createRemoteService(Integer outNodeId, String serviceName, Forward forward) {
private R createRemoteService(Integer outNodeId, String serviceName, Forward forward, String protocol) {
Node outNode = nodeService.getNodeById(outNodeId.longValue());
GostDto result = GostUtil.AddRemoteService(outNode.getIp() + ":" + outNode.getPort(),
serviceName, forward.getOutPort(),
forward.getRemoteAddr(), outNode.getSecret());
forward.getRemoteAddr(), outNode.getSecret(), protocol);
return isGostOperationSuccess(result) ? R.ok() : R.err(result.getMsg());
}
@@ -654,13 +654,13 @@ public class ForwardServiceImpl extends ServiceImpl<ForwardMapper, Forward> impl
/**
* 更新链服务
*/
private R updateChainService(Node inNode, String serviceName, String outIp, Integer outPort) {
private R updateChainService(Node inNode, String serviceName, String outIp, Integer outPort, String protocol) {
// 创建新链
String remoteAddr = outIp + ":" + outPort;
GostDto createResult = GostUtil.UpdateChains(inNode.getIp() + ":" + inNode.getPort(), serviceName, remoteAddr, inNode.getSecret());
GostDto createResult = GostUtil.UpdateChains(inNode.getIp() + ":" + inNode.getPort(), serviceName, remoteAddr, inNode.getSecret(), protocol);
if (createResult.getMsg().contains(GOST_NOT_FOUND_MSG)) {
createResult = GostUtil.AddChains(inNode.getIp() + ":" + inNode.getPort(), serviceName, remoteAddr, inNode.getSecret());
createResult = GostUtil.AddChains(inNode.getIp() + ":" + inNode.getPort(), serviceName, remoteAddr, inNode.getSecret(), protocol);
}
return isGostOperationSuccess(createResult) ? R.ok() : R.err(createResult.getMsg());
}
@@ -668,7 +668,7 @@ public class ForwardServiceImpl extends ServiceImpl<ForwardMapper, Forward> impl
/**
* 更新远程服务
*/
private R updateRemoteService(Integer outNodeId, String serviceName, Forward forward) {
private R updateRemoteService(Integer outNodeId, String serviceName, Forward forward, String protocol) {
Node outNode = nodeService.getNodeById(outNodeId.longValue());
// 创建新远程服务
GostDto createResult = GostUtil.UpdateRemoteService(outNode.getIp() + ":" + outNode.getPort(),
@@ -677,7 +677,7 @@ public class ForwardServiceImpl extends ServiceImpl<ForwardMapper, Forward> impl
if (createResult.getMsg().contains(GOST_NOT_FOUND_MSG)) {
createResult = GostUtil.AddRemoteService(outNode.getIp() + ":" + outNode.getPort(),
serviceName, forward.getOutPort(),
forward.getRemoteAddr(), outNode.getSecret());
forward.getRemoteAddr(), outNode.getSecret(),protocol);
}
return isGostOperationSuccess(createResult) ? R.ok() : R.err(createResult.getMsg());
}
@@ -257,6 +257,16 @@ public class TunnelServiceImpl extends ServiceImpl<TunnelMapper, Tunnel> impleme
// 设置流量计算类型
tunnel.setFlow(tunnelDto.getFlow());
// 设置协议类型(仅隧道转发需要)
if (tunnelDto.getType() == TUNNEL_TYPE_TUNNEL_FORWARD) {
// 隧道转发时,设置协议类型,默认为tls
String protocol = StrUtil.isNotBlank(tunnelDto.getProtocol()) ? tunnelDto.getProtocol() : "tls";
tunnel.setProtocol(protocol);
} else {
// 端口转发时,协议类型为null
tunnel.setProtocol(null);
}
return tunnel;
}
@@ -310,6 +320,13 @@ public class TunnelServiceImpl extends ServiceImpl<TunnelMapper, Tunnel> impleme
return R.err(ERROR_SAME_NODE_NOT_ALLOWED);
}
// 验证协议类型
String protocol = tunnelDto.getProtocol();
if (StrUtil.isNotBlank(protocol) &&
!protocol.equals("tls") && !protocol.equals("tcp") && !protocol.equals("mtls")) {
return R.err("协议类型只能为tls、tcp或mtls");
}
// 验证出口节点是否存在
Node outNode = nodeService.getById(tunnelDto.getOutNodeId());
if (outNode == null) {