Skip to content

Commit a0e8e5a

Browse files
author
c0rex86
committed
fix(proxy): improve proxy management by handling enabled and disabled states
- Added logic to track enabled proxies and ensure only active ones are started. - Enhanced stopping mechanism for proxies to log when they are removed or disabled. - Cleaned up the updateProxies method for better clarity and functionality.
1 parent 8429690 commit a0e8e5a

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

proxy/tcp.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,21 @@ func (pm *ProxyManager) updateProxies() {
7878
proxies := pm.configMgr.GetProxies()
7979

8080
currentPorts := make(map[int]bool)
81+
enabledPorts := make(map[int]bool)
82+
83+
// собираем список активных и включенных прокси
8184
for _, proxy := range proxies {
8285
currentPorts[proxy.ListenPort] = true
86+
if proxy.Enabled {
87+
enabledPorts[proxy.ListenPort] = true
88+
}
89+
}
90+
91+
// запускаем новые включенные прокси
92+
for _, proxy := range proxies {
93+
if !proxy.Enabled {
94+
continue
95+
}
8396

8497
pm.mu.RLock()
8598
_, exists := pm.activeProxies[proxy.ListenPort]
@@ -90,10 +103,11 @@ func (pm *ProxyManager) updateProxies() {
90103
}
91104
}
92105

106+
// останавливаем прокси, которые были отключены или удалены
93107
pm.mu.Lock()
94108
for port, proxy := range pm.activeProxies {
95-
if !currentPorts[port] {
96-
log.Printf("[Proxy] Stopping proxy on port %d", port)
109+
if !currentPorts[port] || !enabledPorts[port] {
110+
log.Printf("[Proxy] Stopping proxy on port %d (removed or disabled)", port)
97111
proxy.Stop()
98112
delete(pm.activeProxies, port)
99113
}

0 commit comments

Comments
 (0)