mirror of
https://github.com/netbirdio/netbird.git
synced 2026-07-18 12:39:54 +00:00
* [client] Index peer tunnel IPs for O(1) PeerStateByIP lookup Replace the linear scan over all peers with an ipToKey map maintained by AddPeer/RemovePeer, covering both IPv4 and IPv6 tunnel addresses. Offline peers are intentionally no longer resolvable by IP: only active peers can carry traffic, so IdentityForIP and the DNS disconnected-peer filter now treat them as unknown, same as foreign IPs. Skip the DNS answer filter for single-record responses; dropping the only answer was always restored by the empty-answer escape hatch, so the fast path is behavior-neutral. * Ensure `ipToKey` entries are only removed if they match the peer being deleted, preventing accidental removal of unrelated mappings.
45 lines
1.4 KiB
Go
45 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"
|
|
}
|
|
}
|