diff --git a/client/internal/peer/wg_watcher.go b/client/internal/peer/wg_watcher.go index b6c5817f8..18bf7cee6 100644 --- a/client/internal/peer/wg_watcher.go +++ b/client/internal/peer/wg_watcher.go @@ -33,6 +33,7 @@ type WGWatcher struct { ctx context.Context ctxCancel context.CancelFunc ctxLock sync.Mutex + enabled time.Time } func NewWGWatcher(log *log.Entry, wgIfaceStater WGInterfaceStater, peerKey string, stateDump *stateDump) *WGWatcher { @@ -48,6 +49,7 @@ func NewWGWatcher(log *log.Entry, wgIfaceStater WGInterfaceStater, peerKey strin func (w *WGWatcher) EnableWgWatcher(parentCtx context.Context, onDisconnectedFn func()) { w.log.Debugf("enable WireGuard watcher") w.ctxLock.Lock() + w.enabled = time.Now() if w.ctx != nil && w.ctx.Err() == nil { w.log.Errorf("WireGuard watcher already enabled") @@ -87,6 +89,8 @@ func (w *WGWatcher) DisableWgWatcher() { func (w *WGWatcher) periodicHandshakeCheck(ctx context.Context, ctxCancel context.CancelFunc, onDisconnectedFn func(), initialHandshake time.Time) { w.log.Infof("WireGuard watcher started") + debugTicker := time.NewTicker(time.Second) + timer := time.NewTimer(wgHandshakeOvertime) defer timer.Stop() defer ctxCancel() @@ -95,15 +99,28 @@ func (w *WGWatcher) periodicHandshakeCheck(ctx context.Context, ctxCancel contex for { select { + case <-debugTicker.C: + handshake, err := w.wgState() + if err != nil { + w.log.Errorf("failed to read wg stats: %v", err) + continue + } + if !handshake.IsZero() { + w.log.Infof("first wg handshake detected at: %s, %s", handshake, time.Since(w.enabled)) + debugTicker.Stop() + } case <-timer.C: handshake, ok := w.handshakeCheck(lastHandshake) if !ok { onDisconnectedFn() return } - if lastHandshake.IsZero() { - w.log.Infof("first wg handshake detected at: %s", handshake) - } + /* + // todo: put it back if remove debug ticker + if lastHandshake.IsZero() { + w.log.Infof("first wg handshake detected at: %s", handshake) + } + */ lastHandshake = *handshake