mirror of
https://github.com/netbirdio/netbird.git
synced 2026-10-09 23:19:11 +02:00
[client] Resume peer reconnection when the network comes back
Ticks taken while the OS reported no network were skipped, but they still advanced the exponential backoff, so a peer could be tens of seconds from its next attempt by the time connectivity returned. Recovery then depended on a signal or relay event, which never arrives when both stayed up across the outage, e.g. a short airplane mode toggle over Wi-Fi. A peer parked in ICE hourly mode stayed there for the same reason. React to the offline-to-online transition directly: re-arm the reconnect ticker and reset the ICE retry state, so the peer retries at once. Add netstate.Changed for callers that own a select loop and cannot block in Wait.
This commit is contained in:
@@ -61,6 +61,20 @@ func (s *State) IsOnline() bool {
|
||||
return s.online
|
||||
}
|
||||
|
||||
// Changed returns a channel closed on the next availability transition, for
|
||||
// callers that already own a select loop and cannot block in Wait. Re-read it
|
||||
// after every fire: each transition installs a fresh channel. On a nil
|
||||
// receiver — no State injected — it returns nil, which blocks forever in a
|
||||
// select, so the caller simply never observes a transition.
|
||||
func (s *State) Changed() <-chan struct{} {
|
||||
if s == nil {
|
||||
return nil
|
||||
}
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
return s.changed
|
||||
}
|
||||
|
||||
// Wait blocks while the network is offline. It reports whether it had to
|
||||
// wait, so callers can reset their backoff after an outage. It returns early
|
||||
// with the context error when ctx is done. On a nil receiver — no State
|
||||
|
||||
Reference in New Issue
Block a user