WebSocket Protocol

How the hub and node communicate

The hub and node communicate over a persistent WebSocket connection. This enables real-time command dispatch and progress streaming.

Connection Flow

  1. Node requests a short-lived WS token from POST /api/v1/nodes/:id/ws-token
  2. Token is valid for 60 seconds
  3. Node connects to ws://hub:4865/api/v1/ws?token=<ws-token>
  4. Connection established — node is marked as “online”

Keepalive

  • The node sends a ping every 30 seconds
  • The hub must respond with a pong within 90 seconds
  • If the hub does not respond, the node disconnects and reconnects

Auto-Reconnect

If the connection drops, the node reconnects with exponential backoff:

  • Start at 1 second delay
  • Double after each failed attempt
  • Maximum delay: 60 seconds
  • Reset to 1 second after successful reconnection

Commands

The hub sends JSON-encoded commands over the WebSocket:

CommandDescription
BackupRun a backup with specified plan configuration
RestoreRestore files from a snapshot
PruneRun repository maintenance (prune)
CheckVerify repository integrity
RepoStatsCollect repository storage statistics
ListSnapshotsList snapshots in a repository
BrowseSnapshotList files in a snapshot path
UpdateSelf-update the node agent
UninstallRemove the node agent

Token Rotation

WebSocket tokens are short-lived (60 seconds) and single-use. The node must request a new token before each connection attempt. This limits the window of exposure if a token is intercepted.