diff --git a/client/internal/lazyconn/manager/manager.go b/client/internal/lazyconn/manager/manager.go index e9623e394..cb9662bc9 100644 --- a/client/internal/lazyconn/manager/manager.go +++ b/client/internal/lazyconn/manager/manager.go @@ -8,24 +8,19 @@ import ( "github.com/netbirdio/netbird/client/internal/lazyconn" "github.com/netbirdio/netbird/client/internal/lazyconn/listener" - "github.com/netbirdio/netbird/client/internal/lazyconn/watcher" ) type Manager struct { PeerActivityChan chan string - watcher *watcher.Watcher listenerMgr *listener.Manager managedPeers map[string]lazyconn.PeerConfig - - watcherWG sync.WaitGroup - mu sync.Mutex + mu sync.Mutex } func NewManager(wgIface lazyconn.WGIface) *Manager { m := &Manager{ PeerActivityChan: make(chan string, 1), - watcher: watcher.NewWatcher(wgIface), listenerMgr: listener.NewManager(wgIface), managedPeers: make(map[string]lazyconn.PeerConfig), } @@ -33,35 +28,13 @@ func NewManager(wgIface lazyconn.WGIface) *Manager { } func (m *Manager) Start() { - m.mu.Lock() - ctx, cancel := context.WithCancel(context.Background()) defer cancel() - m.watcherWG.Add(1) - m.mu.Unlock() - - go func() { - m.watcher.Watch(ctx) - m.watcherWG.Done() - }() - for { select { case <-ctx.Done(): return - case peerID := <-m.watcher.PeerTimedOutChan: - m.mu.Lock() - cfg, ok := m.managedPeers[peerID] - if !ok { - m.mu.Unlock() - continue - } - - if err := m.listenerMgr.CreateFakePeer(cfg); err != nil { - log.Errorf("failed to start watch lazy connection tries: %s", err) - } - m.mu.Unlock() case peerID := <-m.listenerMgr.TrafficStartChan: m.mu.Lock() _, ok := m.managedPeers[peerID] @@ -107,7 +80,6 @@ func (m *Manager) RemovePeer(peerID string) bool { log.Debugf("removing lazy peer: %s", peerID) - m.watcher.RemovePeer(peerID) m.listenerMgr.RemovePeer(peerID) delete(m.managedPeers, peerID) return false @@ -118,7 +90,6 @@ func (m *Manager) Close() { defer m.mu.Unlock() m.listenerMgr.Close() - m.watcherWG.Wait() m.managedPeers = make(map[string]lazyconn.PeerConfig) } diff --git a/client/internal/lazyconn/watcher/watcher.go b/client/internal/lazyconn/watcher/watcher.go index de56e9c96..d5a1e8799 100644 --- a/client/internal/lazyconn/watcher/watcher.go +++ b/client/internal/lazyconn/watcher/watcher.go @@ -20,6 +20,8 @@ type rxHistory struct { received int64 } +// Watcher checks for peer timeouts +// Todo: this is a naive implementation, we must to finish it type Watcher struct { PeerTimedOutChan chan string @@ -70,7 +72,6 @@ func (m *Watcher) RemovePeer(id string) { delete(m.peers, id) } -// Todo: this is a naive implementation, we must to finish it func (m *Watcher) checkTimeouts(ctx context.Context, allPeersStats map[string]configurer.WGStats) { m.peersMu.Lock() defer m.peersMu.Unlock()