Skip to main content

relay_router

Function relay_router 

Source
pub fn relay_router(state: Arc<NodeState>) -> Router
Expand description

Returns an axum Router handling WebSocket upgrade at /scp/v1.

Incoming WebSocket connections are bridged to the node’s internal relay server. The axum handler upgrades the HTTP connection to WebSocket, then connects to the relay on localhost and forwards frames bidirectionally.

An Arc<Semaphore> caps concurrent bridge connections to max_total_connections from the relay config. The permit is acquired before the HTTP 101 upgrade and held inside the on_upgrade closure for the entire WebSocket connection lifetime — ensuring the semaphore accurately tracks active connections, not just in-flight upgrade requests (#229).