mirror of
https://github.com/netbirdio/netbird.git
synced 2026-04-22 10:16:38 +00:00
* [client] Suppress ICE signaling and periodic offers in force-relay mode When NB_FORCE_RELAY is enabled, skip WorkerICE creation entirely, suppress ICE credentials in offer/answer messages, disable the periodic ICE candidate monitor, and fix isConnectedOnAllWay to only check relay status so the guard stops sending unnecessary offers. * [client] Dynamically suppress ICE based on remote peer's offer credentials Track whether the remote peer includes ICE credentials in its offers/answers. When remote stops sending ICE credentials, skip ICE listener dispatch, suppress ICE credentials in responses, and exclude ICE from the guard connectivity check. When remote resumes sending ICE credentials, re-enable all ICE behavior. * [client] Fix nil SessionID panic and force ICE teardown on relay-only transition Fix nil pointer dereference in signalOfferAnswer when SessionID is nil (relay-only offers). Close stale ICE agent immediately when remote peer stops sending ICE credentials to avoid traffic black-hole during the ICE disconnect timeout. * [client] Add relay-only fallback check when ICE is unavailable Ensure the relay connection is supported with the peer when ICE is disabled to prevent connectivity issues. * [client] Add tri-state connection status to guard for smarter ICE retry (#5828) * [client] Add tri-state connection status to guard for smarter ICE retry Refactor isConnectedOnAllWay to return a ConnStatus enum (Connected, Disconnected, PartiallyConnected) instead of a boolean. When relay is up but ICE is not (PartiallyConnected), limit ICE offers to 3 retries with exponential backoff then fall back to hourly attempts, reducing unnecessary signaling traffic. Fully disconnected peers continue to retry aggressively. External events (relay/ICE disconnect, signal/relay reconnect) reset retry state to give ICE a fresh chance. * [client] Clarify guard ICE retry state and trace log trigger Split iceRetryState.attempt into shouldRetry (pure predicate) and enterHourlyMode (explicit state transition) so the caller in reconnectLoopWithRetry reads top-to-bottom. Restore the original trace-log behavior in isConnectedOnAllWay so it only logs on full disconnection, not on the new PartiallyConnected state. * [client] Extract pure evalConnStatus and add unit tests Split isConnectedOnAllWay into a thin method that snapshots state and a pure evalConnStatus helper that takes a connStatusInputs struct, so the tri-state decision logic can be exercised without constructing full Worker or Handshaker objects. Add table-driven tests covering force-relay, ICE-unavailable and fully-available code paths, plus unit tests for iceRetryState budget/hourly transitions and reset. * [client] Improve grammar in logs and refactor ICE credential checks
46 lines
1.4 KiB
Go
46 lines
1.4 KiB
Go
package peer
|
|
|
|
import (
|
|
log "github.com/sirupsen/logrus"
|
|
)
|
|
|
|
const (
|
|
// StatusIdle indicate the peer is in disconnected state
|
|
StatusIdle ConnStatus = iota
|
|
// StatusConnecting indicate the peer is in connecting state
|
|
StatusConnecting
|
|
// StatusConnected indicate the peer is in connected state
|
|
StatusConnected
|
|
)
|
|
|
|
// connStatusInputs is the primitive-valued snapshot of the state that drives the
|
|
// tri-state connection classification. Extracted so the decision logic can be unit-tested
|
|
// without constructing full Worker/Handshaker objects.
|
|
type connStatusInputs struct {
|
|
forceRelay bool // NB_FORCE_RELAY or JS/WASM
|
|
peerUsesRelay bool // remote peer advertises relay support AND local has relay
|
|
relayConnected bool // statusRelay reports Connected (independent of whether peer uses relay)
|
|
remoteSupportsICE bool // remote peer sent ICE credentials
|
|
iceWorkerCreated bool // local WorkerICE exists (false in force-relay mode)
|
|
iceStatusConnecting bool // statusICE is anything other than Disconnected
|
|
iceInProgress bool // a negotiation is currently in flight
|
|
}
|
|
|
|
|
|
// ConnStatus describe the status of a peer's connection
|
|
type ConnStatus int32
|
|
|
|
func (s ConnStatus) String() string {
|
|
switch s {
|
|
case StatusConnecting:
|
|
return "Connecting"
|
|
case StatusConnected:
|
|
return "Connected"
|
|
case StatusIdle:
|
|
return "Idle"
|
|
default:
|
|
log.Errorf("unknown status: %d", s)
|
|
return "INVALID_PEER_CONNECTION_STATUS"
|
|
}
|
|
}
|