Move failover command to monitor

Former-commit-id: 23e7b173c9
This commit is contained in:
Owen
2025-12-01 20:21:05 -05:00
parent a497f0873f
commit 3b2ffe006a
4 changed files with 51 additions and 64 deletions

View File

@@ -392,6 +392,12 @@ func StartTunnel(config TunnelConfig) {
interfaceIP = strings.Split(interfaceIP, "/")[0]
}
// Determine if we should send relay messages (only when holepunching is enabled and relay is not disabled)
var wsClientForMonitor *websocket.Client
if config.Holepunch && !config.DisableRelay {
wsClientForMonitor = olm
}
peerMonitor = peermonitor.NewPeerMonitor(
func(siteID int, connected bool, rtt time.Duration) {
// Find the site config to get endpoint information
@@ -413,10 +419,7 @@ func StartTunnel(config TunnelConfig) {
logger.Warn("Peer %d is disconnected", siteID)
}
},
util.FixKey(privateKey.String()),
olm,
dev,
config.Holepunch && !config.DisableRelay, // Enable relay only if holepunching is enabled and DisableRelay is false
wsClientForMonitor,
middleDev,
interfaceIP,
sharedBind, // Pass sharedBind for holepunch testing
@@ -710,7 +713,7 @@ func StartTunnel(config TunnelConfig) {
// Update HTTP server to mark this peer as using relay
apiServer.UpdatePeerRelayStatus(relayData.SiteId, relayData.Endpoint, true)
peerMonitor.HandleFailover(relayData.SiteId, primaryRelay)
peerManager.HandleFailover(relayData.SiteId, primaryRelay)
})
// Handler for peer handshake - adds exit node to holepunch rotation and notifies server

View File

@@ -27,9 +27,6 @@ type GlobalConfig struct {
OnConnected func()
OnTerminated func()
OnAuthError func(statusCode int, message string) // Called when auth fails (401/403)
// Source tracking (not in JSON)
sources map[string]string
}
type TunnelConfig struct {