From 3d51aa455006903345f554a2dd90034993796114 Mon Sep 17 00:00:00 2001 From: sergei Date: Tue, 14 Apr 2026 06:23:55 +0400 Subject: vpnem: VPN infrastructure with load-balanced multi-protocol nodes - Multi-protocol VPS nodes (VLESS-REALITY + Hysteria2 + SOCKS5) - Smart load balancing via recommendation API - Windows/Linux client (Go + Wails + sing-box) - Server API with RealIP detection and connection tracking - Auto-deployment via vpnui control plane - Silent Windows installer with UAC elevation - Load-based server recommendation (no sticky sessions) - Best Server one-click connection workflow --- internal/engine/proxy_port.go | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 internal/engine/proxy_port.go (limited to 'internal/engine/proxy_port.go') diff --git a/internal/engine/proxy_port.go b/internal/engine/proxy_port.go new file mode 100644 index 0000000..5e657c0 --- /dev/null +++ b/internal/engine/proxy_port.go @@ -0,0 +1,37 @@ +package engine + +import ( + "fmt" + "net" + + "vpnem/internal/config" +) + +var localProxyPortCandidates = []int{config.LocalProxyPort, 10808, 10880, 18080, 20800} + +func ResolveLocalProxyPort() (int, error) { + for _, port := range localProxyPortCandidates { + if localProxyPortAvailable(port) { + return port, nil + } + } + listener, err := net.Listen("tcp", net.JoinHostPort(config.LocalProxyHost, "0")) + if err != nil { + return 0, err + } + defer listener.Close() + addr, ok := listener.Addr().(*net.TCPAddr) + if !ok { + return 0, fmt.Errorf("unexpected listener addr type %T", listener.Addr()) + } + return addr.Port, nil +} + +func localProxyPortAvailable(port int) bool { + listener, err := net.Listen("tcp", net.JoinHostPort(config.LocalProxyHost, fmt.Sprintf("%d", port))) + if err != nil { + return false + } + _ = listener.Close() + return true +} -- cgit v1.2.3