From 78f3165e8587d7f1d21a50db00f5280d6bd2eebe Mon Sep 17 00:00:00 2001 From: Zoltan Papp Date: Sat, 11 Jul 2026 15:17:16 +0200 Subject: [PATCH] [client] Extract WGWatcher into its own wg_watcher package Move the WireGuard handshake watcher out of the peer package into client/internal/peer/wg_watcher. The test stays an internal test since it drives the unexported checkPeriod. Update conn.go to reference the watcher through the package. --- client/internal/peer/conn.go | 5 +++-- client/internal/peer/{ => wg_watcher}/wg_watcher.go | 2 +- client/internal/peer/{ => wg_watcher}/wg_watcher_test.go | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) rename client/internal/peer/{ => wg_watcher}/wg_watcher.go (99%) rename client/internal/peer/{ => wg_watcher}/wg_watcher_test.go (99%) diff --git a/client/internal/peer/conn.go b/client/internal/peer/conn.go index 5833ca6a3..76cb87fac 100644 --- a/client/internal/peer/conn.go +++ b/client/internal/peer/conn.go @@ -24,6 +24,7 @@ import ( "github.com/netbirdio/netbird/client/internal/peer/id" "github.com/netbirdio/netbird/client/internal/peer/state_dump" "github.com/netbirdio/netbird/client/internal/peer/status" + "github.com/netbirdio/netbird/client/internal/peer/wg_watcher" "github.com/netbirdio/netbird/client/internal/peer/worker" "github.com/netbirdio/netbird/client/internal/portforward" "github.com/netbirdio/netbird/client/internal/rosenpass" @@ -138,7 +139,7 @@ type Conn struct { relayDialInFlight bool pendingRelayOffer *OfferAnswer - wgWatcher *WGWatcher + wgWatcher *wg_watcher.WGWatcher wgWatcherWg sync.WaitGroup wgWatcherCancel context.CancelFunc // wgTimeouts counts consecutive WireGuard handshake timeouts without a @@ -192,7 +193,7 @@ func NewConn(config ConnConfig, services ServiceDependencies) (*Conn, error) { statusICE: worker.NewAtomicStatus(), dumpState: dumpState, endpointUpdater: NewEndpointUpdater(connLog, config.WgConfig, isController(config)), - wgWatcher: NewWGWatcher(connLog, config.WgConfig.WgInterface, config.Key, dumpState), + wgWatcher: wg_watcher.NewWGWatcher(connLog, config.WgConfig.WgInterface, config.Key, dumpState), metricsRecorder: services.MetricsRecorder, } diff --git a/client/internal/peer/wg_watcher.go b/client/internal/peer/wg_watcher/wg_watcher.go similarity index 99% rename from client/internal/peer/wg_watcher.go rename to client/internal/peer/wg_watcher/wg_watcher.go index f09cf1098..448f148be 100644 --- a/client/internal/peer/wg_watcher.go +++ b/client/internal/peer/wg_watcher/wg_watcher.go @@ -1,4 +1,4 @@ -package peer +package wg_watcher import ( "context" diff --git a/client/internal/peer/wg_watcher_test.go b/client/internal/peer/wg_watcher/wg_watcher_test.go similarity index 99% rename from client/internal/peer/wg_watcher_test.go rename to client/internal/peer/wg_watcher/wg_watcher_test.go index c76337fd8..af89e3f0b 100644 --- a/client/internal/peer/wg_watcher_test.go +++ b/client/internal/peer/wg_watcher/wg_watcher_test.go @@ -1,4 +1,4 @@ -package peer +package wg_watcher import ( "context"