macula_connection_upgrade (macula v0.20.5)
View SourceConnection Upgrade Manager.
Handles upgrading connections from relay (indirect) to direct when hole punching succeeds. This is a key optimization for reducing latency and bootstrap load.
Upgrade Flow: 1. Connection established via relay (fallback) 2. Hole punch attempt happens in background 3. On success, upgrade_to_direct/2 is called 4. Messages are seamlessly transitioned to direct connection 5. Relay connection is gracefully closed
Key Features: - Message ordering preserved during upgrade - No message loss during transition - Automatic fallback if direct connection fails - Metrics tracking for upgrade success/failure
Summary
Functions
Get upgrade statistics.
Register a relay connection for potential future upgrade. Called when connection is established via relay fallback.
Start the connection upgrade manager.
Unregister a relay connection (closed or upgraded).
Upgrade a relay connection to direct. PeerId - The remote peer's ID RelayConn - Current relay connection handle DirectConn - New direct connection handle from hole punch
Functions
-spec get_upgrade_stats() -> map().
Get upgrade statistics.
-spec register_relay(binary(), term(), {inet:ip_address(), inet:port_number()}) -> ok.
Register a relay connection for potential future upgrade. Called when connection is established via relay fallback.
Start the connection upgrade manager.
-spec unregister_relay(binary()) -> ok.
Unregister a relay connection (closed or upgraded).
Upgrade a relay connection to direct. PeerId - The remote peer's ID RelayConn - Current relay connection handle DirectConn - New direct connection handle from hole punch