Fix slow netbird status -d issue

This commit is contained in:
Zoltán Papp
2025-02-26 16:50:53 +01:00
parent 9188fcabaf
commit 6ad66fe3cd
16 changed files with 67 additions and 228 deletions
+1 -1
View File
@@ -14,6 +14,6 @@ import (
type WGIface interface {
UpdatePeer(peerKey string, allowedIps []netip.Prefix, keepAlive time.Duration, endpoint *net.UDPAddr, preSharedKey *wgtypes.Key) error
RemovePeer(peerKey string) error
GetStats(peerKey string) (configurer.WGStats, error)
GetStats() (map[string]configurer.WGStats, error)
GetProxy() wgproxy.Proxy
}
+7 -2
View File
@@ -2,6 +2,7 @@ package peer
import (
"context"
"fmt"
"sync"
"time"
@@ -20,7 +21,7 @@ var (
)
type WGInterfaceStater interface {
GetStats(key string) (configurer.WGStats, error)
GetStats() (map[string]configurer.WGStats, error)
}
type WGWatcher struct {
@@ -146,9 +147,13 @@ func (w *WGWatcher) handshakeCheck(lastHandshake time.Time) (*time.Time, bool) {
}
func (w *WGWatcher) wgState() (time.Time, error) {
wgState, err := w.wgIfaceStater.GetStats(w.peerKey)
wgStates, err := w.wgIfaceStater.GetStats()
if err != nil {
return time.Time{}, err
}
wgState, ok := wgStates[w.peerKey]
if !ok {
return time.Time{}, fmt.Errorf("peer %s not found in WireGuard endpoints", w.peerKey)
}
return wgState.LastHandshake, nil
}
+3 -18
View File
@@ -11,26 +11,11 @@ import (
)
type MocWgIface struct {
initial bool
lastHandshake time.Time
stop bool
stop bool
}
func (m *MocWgIface) GetStats(key string) (configurer.WGStats, error) {
if !m.initial {
m.initial = true
return configurer.WGStats{}, nil
}
if !m.stop {
m.lastHandshake = time.Now()
}
stats := configurer.WGStats{
LastHandshake: m.lastHandshake,
}
return stats, nil
func (m *MocWgIface) GetStats() (map[string]configurer.WGStats, error) {
return map[string]configurer.WGStats{}, nil
}
func (m *MocWgIface) disconnect() {