refactor(panel): drop two duplicated helpers

SettingService.GetDefaultJSONConfig was a byte-identical copy of
GetDefaultXrayConfig with no callers anywhere in the tree.

amneziawgnet.normalizeDNSServer re-implemented the exported
amneziawg.NormalizeDNSServer line for line, in a file that already imports
that package for EffectiveMTU three lines above it. Its two callers now use
the exported one, so the bare-IP-to-host:port rule has a single definition.
This commit is contained in:
Sanaei committed 2026-09-10 21:08:13 +02:00 Unverified
1 parent 0fbdf0f9bf
commit 3f1e52f09e
4 files changed
+4 -27

No files matched your search

+2 -1
View File
@@ -14,6 +14,7 @@ import (
"gvisor.dev/gvisor/pkg/tcpip"
"gvisor.dev/gvisor/pkg/tcpip/adapters/gonet"
"github.com/mhsanaei/3x-ui/v3/internal/amneziawg"
"github.com/mhsanaei/3x-ui/v3/internal/logger"
)
@@ -78,7 +79,7 @@ func dnsCacheKey(tag, dnsServer, host string) string {
}
func resolveTunnelVia(ctx context.Context, dev *Device, tag string, dnsServer string, host string) (netip.Addr, error) {
normDNS := normalizeDNSServer(dnsServer)
normDNS := amneziawg.NormalizeDNSServer(dnsServer)
if normDNS == "" {
normDNS = defaultDNSFor(dev.LocalAddresses())
}
+2 -1
View File
@@ -14,6 +14,7 @@ import (
"gvisor.dev/gvisor/pkg/tcpip"
"gvisor.dev/gvisor/pkg/tcpip/adapters/gonet"
"github.com/mhsanaei/3x-ui/v3/internal/amneziawg"
"github.com/mhsanaei/3x-ui/v3/internal/logger"
)
@@ -77,7 +78,7 @@ func (s *socks5EgressServer) SetDNSServer(addr string) {
func (s *socks5EgressServer) SetStack(tag string, dev *Device, dnsServer ...string) {
norm := ""
if len(dnsServer) > 0 && dnsServer[0] != "" {
norm = normalizeDNSServer(dnsServer[0])
norm = amneziawg.NormalizeDNSServer(dnsServer[0])
}
s.mu.Lock()
prevDev := s.stacks[tag]
-16
View File
@@ -2,7 +2,6 @@ package amneziawgnet
import (
"fmt"
"net/netip"
"strings"
"sync"
@@ -53,21 +52,6 @@ func outboundFingerprint(inst amneziawg.OutboundInstance) string {
strings.Join(inst.Address, ","))
}
// normalizeDNSServer normalizes a configured DNS server to host:port.
func normalizeDNSServer(s string) string {
s = strings.TrimSpace(s)
if s == "" {
return ""
}
if addr, err := netip.ParseAddr(s); err == nil {
return netip.AddrPortFrom(addr, 53).String()
}
if ap, err := netip.ParseAddrPort(s); err == nil {
return ap.String()
}
return s
}
// Reconcile converges devices to desired and stops removed tags; per-tick
// contract of Manager.Reconcile -- errors log, never abort the batch.
func (m *OutboundManager) Reconcile(desired []OutboundDesired) {
Loaded 3 of 4 files, more files were not shown because too many files have changed in this diff. Show more