Skip to content

Node protocol ​

How bs-control and bs-node talk. The Go structs are in core/internal/shared/nodeproto. This page is for people debugging a node or writing tools around it.

Transport ​

  • HTTPS with mutual TLS on the control's port 8443.
  • The node always opens the connection, so it works behind NAT.
  • Every message carries proto, an integer version (now 1). The control accepts the current and the previous version, so nodes can be upgraded one by one.
PathAuthPurpose
POST /node/v1/enrolljoin token (no client certificate)First contact. Rate limited per IP.
GET /node/v1/configmTLSFull snapshot of the streams on this node, versioned by rev.
GET /node/v1/streammTLSLong-lived WebSocket, one JSON message per frame.
GET /node/v1/vod?kind=movie|episode&id=NmTLSWhere a VOD file lives (path or url). The node caches the answer for 10 minutes.

Enrollment ​

The join token looks like bsj1.<secret>.<hex sha256 of the CA certificate>. It works once and expires after ttl_minutes: 60 by default, from 5 to 1440 (24 hours). POST /node-join-tokens in the admin API creates one and returns a ready to paste install_command.

  1. The node makes its own private key and a certificate request (CSR). The key never leaves the node.
  2. The node connects to the control and checks that the CA matches the hash in the token before sending anything.
  3. Request:
json
{"join_token": "bsj1....", "csr_pem": "...", "hostname": "edge-sp-1", "version": "1.0.0",
 "proto": 1, "ffmpeg_versions": ["8.1", "latest"], "cpu_cores": 8, "mem_bytes": 17179869184,
 "http_port": 8090, "https_port": 8091}
  1. Answer:
json
{"node_id": "...", "cert_pem": "...", "ca_pem": "...", "node_secret": "..."}

http_port and https_port are the ports viewers use to reach the node: public_port (or public_tls_port) when set, else the listen port. 0 or missing means an older node or no HTTPS. The control redirects viewers to these ports.

node_secret signs the play tokens for this node. The node saves its identity in state_dir with mode 0600.

A node that enrolls over a direct loopback connection runs on the control machine (installer role both, wizard option "Use this server"). It gets delivery_mode proxy, so the control serves its streams, and its public_host is the panel host. Other nodes get redirect.

Local enrollment ​

On a role both install, the control has node_api.local_join_file and the node has join_token_file, both /opt/bitstream/data/join/local.token. When setup completes, the control writes a single use join token there (60 minutes, written then renamed, mode 0640). The node waits for the file, enrolls over https://127.0.0.1:8443 with the CA pin and deletes it.

There is no revocation list. The control checks on every connection that the node_id is still active.

Messages ​

Every frame:

json
{"proto": 1, "type": "stream_start", "id": "optional", "time": "2026-11-28T14:30:00Z", "data": {}}

Commands from the control:

typedataWhat the node does
stream_start{"stream_id": N}Start a stream. Also used to pre-warm an on-demand stream.
stream_stop{"stream_id": N}Stop it.
stream_restart{"stream_id": N}Restart it.
config_update{"rev": N, "config": {...}}New config. Without config, the node fetches /node/v1/config.
session_kill{"sid": "...", "reason": "..."}Drop one viewer.
probe{"url": "...", "user_agent": "", "headers": {}, "timeout_sec": 15}Run ffprobe. Answered by command_result with the same id.
processesnoneList the ffmpeg children. Answered by command_result with [{"pid", "stream_id", "cpu_pct", "rss"}]. CPU is measured over about 0.5 s, 100 means one core, rss is bytes. Older nodes ignore it, and the control then shows an empty list.

Events from the node:

typeWhen
stream_statusA stream changes state: state, source_index, ffmpeg_version, redacted error, reason, restarts.
session_startViewers arrived. Sent in batches every second.
session_heartbeatEvery 10 seconds, with the full list of live session ids. Safe to repeat.
session_endViewers left, with bytes sent and a reason.
statsEvery 5 seconds. Only the streams that changed, plus the full list once a minute.
logA log line for a stream. Source URLs are redacted.
command_result{"ok": true, "error": "", "data": {}} for a command with an id.

The stats event has node values (cpu_percent, load1, mem_total, mem_used, disk_total, disk_used, proc_cpu_percent, proc_rss, buffer_used, net per interface, clients, advice, http_port, https_port) and per stream values (state, health as ok, degraded or down, source_index, bitrate_in, bitrate_out, fps, speed, uptime_sec, clients, restarts).

The ports in stats repeat the enrollment report on every heartbeat, so a node restarted on another port fixes the panel by itself.

Optional in stats: disk_read_bps and disk_write_bps (block device bytes per second). The message time of stats lets the control measure the node clock skew for the dashboard service status. Nodes that send neither keep working; the panel shows those numbers as unknown.

Stream states and reasons ​

state is starting, running, stalled, backoff or stopped. source_index is the index in sources, or a negative value for a parent in the server tree.

reason is the error as a stable code the panel translates: no_data, frozen, slow, ended, refused, timeout, not_found, forbidden, http_error, dns, not_ts or unavailable. On a backup source it says why the primary failed. Older nodes leave it empty.

Config snapshot ​

yaml
rev: 42
node_id: "..."
settings:
  ip_check: prefix
streams:
  - id: 101
    name: Sports HD
    mode: ffmpeg          # ffmpeg | llod | direct
    on_demand: true
    idle_timeout_sec: 60
    sources:
      - url: http://provider.example.net/live/u/p/1234.ts
        account: provider-a
        max_connections: 2
    parents:              # server tree, nearest first
      - {node_id: "...", url: "http://10.0.0.2:8090", token: "..."}
    may_pull_source: true

Other stream fields: radio, ffmpeg_version, probesize, analyze_duration_ms, input_args, output_args, created. Source fields: url, user_agent, headers, account, max_connections.

The same YAML is what a node reads from streams_file in standalone mode.

Node settings ​

KeyDefaultMeaning
ip_checkprefixoff, prefix (/24 IPv4, /64 IPv6) or exact. Skipped when the IP family changes.
resume_window_sec300How long a session can reconnect with the same token after the last byte.
segment_sec4HLS target segment length.
playlist_size4HLS segments in the playlist.
idle_timeout_sec30On-demand stop delay.
buffer_sec6TS ring buffer, in seconds of bitrate.
stream_buffer_mb16Cap per stream.
node_buffer_mb2048Cap for the whole node.
primary_hold_sec30Healthy time before going back to the main source.
max_starts2 x coresSources opened at the same time.

Play tokens ​

The control signs a token for each viewer with the node's secret. The node checks it alone, with no database.

token = base64url(payload) + "." + base64url(HMAC-SHA256(node_secret, payload))
FieldMeaning
sidSession id, the key of the connection slot.
lidLine id, 0 for relays.
stStream, movie or episode id.
klive, movie, episode, radio or relay.
fts or hls.
ipClient IP seen by the control.
expDeadline to open the session (30 seconds by default).

The token is always in the path:

PathContent
/s/<token>/stream.tsMPEG-TS
/s/<token>/index.m3u8HLS playlist with relative segment URIs
/s/<token>/<seq>.tsHLS segment
/relay/<token>/stream.tsRelay to a child node (k=relay)

After opening, the node accepts the token while the sid is active, plus the resume window. One sid has at most one TS connection: a new one drops the old one.

Local endpoints on the node ​

  • GET /healthz answers ok.
  • GET /metrics (Prometheus) answers only on loopback.

Bitstream documentation