summaryrefslogtreecommitdiff
path: root/internal/engine/proxy_port.go
diff options
context:
space:
mode:
authorsergei <sergei@em-sysadmin.xyz>2026-04-14 06:23:55 +0400
committersergei <sergei@em-sysadmin.xyz>2026-04-14 06:23:55 +0400
commit3d51aa455006903345f554a2dd90034993796114 (patch)
tree62a7be2faf047f5eb7886feebc3b815556f03d7f /internal/engine/proxy_port.go
downloadvpnem-main.tar.gz
vpnem-main.tar.bz2
vpnem-main.zip
vpnem: VPN infrastructure with load-balanced multi-protocol nodesHEADmain
- 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
Diffstat (limited to 'internal/engine/proxy_port.go')
-rw-r--r--internal/engine/proxy_port.go37
1 files changed, 37 insertions, 0 deletions
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
+}