mirror of
https://github.com/netbirdio/netbird.git
synced 2026-09-11 17:29:07 +02:00
Tag each WG timeout event with the watcher's context and discard it at dispatch time when that context is cancelled. This replaces the earlier generation counter and the mailbox-level epoch filter: cancelling the watcher is now the single act that both stops it and retires its pending timeouts, so the two can no longer diverge, and the staleness check moves to dispatch time so a cancel performed by an earlier event in the same drained batch already suppresses a superseded watcher's timeout.
84 lines
2.1 KiB
Go
84 lines
2.1 KiB
Go
package peer
|
|
|
|
import (
|
|
"context"
|
|
"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
|
|
|
|
// staleableEvent is implemented by events tied to the lifetime of a transport
|
|
// component (WG watcher, ICE agent, relay connection). Each such component runs
|
|
// under its own context, cancelled when the component is superseded; an event
|
|
// carrying a cancelled context is dropped at dispatch time. A cancel performed
|
|
// by an earlier event in the same drained batch already suppresses it.
|
|
type staleableEvent interface {
|
|
isStale() bool
|
|
}
|
|
|
|
// 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 {
|
|
ctx context.Context
|
|
}
|
|
|
|
func (e evWGTimeout) isStale() bool { return e.ctx.Err() != nil }
|
|
|
|
// 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{}
|