mirror of
https://github.com/netbirdio/netbird.git
synced 2025-07-21 16:28:16 +02:00
With the lazy connection feature, the peer will connect to target peers on-demand. The trigger can be any IP traffic. This feature can be enabled with the NB_ENABLE_EXPERIMENTAL_LAZY_CONN environment variable. When the engine receives a network map, it binds a free UDP port for every remote peer, and the system configures WireGuard endpoints for these ports. When traffic appears on a UDP socket, the system removes this listener and starts the peer connection procedure immediately. Key changes Fix slow netbird status -d command Move from engine.go file to conn_mgr.go the peer connection related code Refactor the iface interface usage and moved interface file next to the engine code Add new command line flag and UI option to enable feature The peer.Conn struct is reusable after it has been closed. Change connection states Connection states Idle: The peer is not attempting to establish a connection. This typically means it's in a lazy state or the remote peer is expired. Connecting: The peer is actively trying to establish a connection. This occurs when the peer has entered an active state and is continuously attempting to reach the remote peer. Connected: A successful peer-to-peer connection has been established and communication is active.
33 lines
1.4 KiB
Go
33 lines
1.4 KiB
Go
/*
|
|
Package lazyconn provides mechanisms for managing lazy connections, which activate on demand to optimize resource usage and establish connections efficiently.
|
|
|
|
## Overview
|
|
|
|
The package includes a `Manager` component responsible for:
|
|
- Managing lazy connections activated on-demand
|
|
- Managing inactivity monitors for lazy connections (based on peer disconnection events)
|
|
- Maintaining a list of excluded peers that should always have permanent connections
|
|
- Handling remote peer connection initiatives based on peer signaling
|
|
|
|
## Thread-Safe Operations
|
|
|
|
The `Manager` ensures thread safety across multiple operations, categorized by caller:
|
|
|
|
- **Engine (single goroutine)**:
|
|
- `AddPeer`: Adds a peer to the connection manager.
|
|
- `RemovePeer`: Removes a peer from the connection manager.
|
|
- `ActivatePeer`: Activates a lazy connection for a peer. This come from Signal client
|
|
- `ExcludePeer`: Marks peers for a permanent connection. Like router peers and other peers that should always have a connection.
|
|
|
|
- **Connection Dispatcher (any peer routine)**:
|
|
- `onPeerConnected`: Suspend the inactivity monitor for an active peer connection.
|
|
- `onPeerDisconnected`: Starts the inactivity monitor for a disconnected peer.
|
|
|
|
- **Activity Manager**:
|
|
- `onPeerActivity`: Run peer.Open(context).
|
|
|
|
- **Inactivity Monitor**:
|
|
- `onPeerInactivityTimedOut`: Close peer connection and restart activity monitor.
|
|
*/
|
|
package lazyconn
|