mirror of
https://github.com/netbirdio/netbird.git
synced 2026-08-29 11:01:29 +02:00
The rebase carried #6664's WGWatcher changes into our wg_watcher package (single-shot, no enabled flag). Adapt conn.go to match: create a fresh watcher per connection attempt in enableWgWatcherIfNeeded, drop it in disableWgWatcherIfNeeded, nil-guard resetEndpoint. Guard stale WG timeouts on the event loop instead of #6664's conn.mu recheck: onWGDisconnected only checked watcherCtx on the watcher goroutine, racing the loop that cancels it and processes the timeout. A loop-owned wgWatcherGen tags evWGTimeout; handleWGTimeout drops events from a superseded generation, so the check and the teardown happen atomically on the single loop.
72 lines
1.6 KiB
Go
72 lines
1.6 KiB
Go
package peer
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/pion/ice/v4"
|
|
|
|
"github.com/netbirdio/netbird/client/internal/peer/signaling"
|
|
"github.com/netbirdio/netbird/client/internal/peer/worker"
|
|
"github.com/netbirdio/netbird/route"
|
|
)
|
|
|
|
// event is a message processed by the Conn event loop. All mutable Conn state
|
|
// is owned by that loop; producers deliver events through the mailbox and
|
|
// never mutate Conn state directly.
|
|
type event any
|
|
|
|
// evClose asks the event loop to tear down the connection. done is closed
|
|
// once the teardown finished.
|
|
type evClose struct {
|
|
signalToRemote bool
|
|
done chan struct{}
|
|
}
|
|
|
|
type evRemoteOffer struct {
|
|
offer signaling.OfferAnswer
|
|
}
|
|
|
|
type evRemoteAnswer struct {
|
|
answer signaling.OfferAnswer
|
|
}
|
|
|
|
type evRemoteCandidate struct {
|
|
candidate ice.Candidate
|
|
haRoutes route.HAMap
|
|
}
|
|
|
|
type evICEReady struct {
|
|
priority worker.ConnPriority
|
|
info worker.ICEConnInfo
|
|
}
|
|
|
|
type evICEDown struct {
|
|
sessionChanged bool
|
|
}
|
|
|
|
type evRelayReady struct {
|
|
info worker.RelayConnInfo
|
|
}
|
|
|
|
type evRelayDown struct{}
|
|
|
|
// evRelayDialDone reports that the relay dial helper goroutine finished,
|
|
// successfully or not, so the loop may dispatch a pending offer.
|
|
type evRelayDialDone struct{}
|
|
|
|
type evWGTimeout struct {
|
|
gen uint64
|
|
}
|
|
|
|
// evWGHandshake reports the first WireGuard handshake of the current watcher run.
|
|
type evWGHandshake struct {
|
|
when time.Time
|
|
}
|
|
|
|
// evWGCheckOK reports a watcher check that observed a fresh handshake,
|
|
// including handshakes of connections that were already up.
|
|
type evWGCheckOK struct{}
|
|
|
|
// evGuardTick asks the loop to send a new offer to restore connectivity.
|
|
type evGuardTick struct{}
|