fix: ensure tunnel protocol and KCP config are correctly processed and cleaned up

This commit is contained in:
sagitchu
2026-04-22 09:41:41 +08:00
parent 6e60f5cfbd
commit 9aff669c0e
3 changed files with 15 additions and 3 deletions
+13 -3
View File
@@ -825,7 +825,9 @@ func (h *Handler) tunnelUpdate(w http.ResponseWriter, r *http.Request) {
defer func() { tx.Rollback() }()
updateProtocol := "tls"
if len(runtimeState.InNodes) > 0 && strings.TrimSpace(runtimeState.InNodes[0].Protocol) != "" {
if len(runtimeState.OutNodes) > 0 && strings.TrimSpace(runtimeState.OutNodes[0].Protocol) != "" {
updateProtocol = strings.TrimSpace(runtimeState.OutNodes[0].Protocol)
} else if len(runtimeState.InNodes) > 0 && strings.TrimSpace(runtimeState.InNodes[0].Protocol) != "" {
updateProtocol = strings.TrimSpace(runtimeState.InNodes[0].Protocol)
}
if err := h.repo.UpdateTunnelTx(
@@ -3405,14 +3407,22 @@ func (h *Handler) rollbackTunnelRuntime(chainNodeIDs, serviceNodeIDs []int64, tu
protocol = "tls"
}
seenServices := make(map[int64]struct{})
serviceName := fmt.Sprintf("%d_%s", tunnelID, protocol)
serviceNames := []string{
fmt.Sprintf("%d_tls", tunnelID),
fmt.Sprintf("%d_kcp", tunnelID),
fmt.Sprintf("%d_wss", tunnelID),
fmt.Sprintf("%d_mtls", tunnelID),
fmt.Sprintf("%d_mwss", tunnelID),
fmt.Sprintf("%d_tcp", tunnelID),
fmt.Sprintf("%d_mtcp", tunnelID),
}
for i := len(serviceNodeIDs) - 1; i >= 0; i-- {
nodeID := serviceNodeIDs[i]
if _, ok := seenServices[nodeID]; ok {
continue
}
seenServices[nodeID] = struct{}{}
_, _ = h.sendNodeCommand(nodeID, "DeleteService", map[string]interface{}{"services": []string{serviceName}}, false, true)
_, _ = h.sendNodeCommand(nodeID, "DeleteService", map[string]interface{}{"services": serviceNames}, false, true)
}
seenChains := make(map[int64]struct{})
BIN
View File
Binary file not shown.
+2
View File
@@ -105,6 +105,8 @@ func GetDuration(md metadata.Metadata, keys ...string) (v time.Duration) {
switch vv := md.Get(key).(type) {
case int:
v = time.Duration(vv) * time.Second
case float64:
v = time.Duration(vv) * time.Second
case string:
v, _ = time.ParseDuration(vv)
if v == 0 {