docs: peer-client liveness MQTT topics + protocol additions

- docs/MQTT.md: new peer/<id>/client/<call>/* topics, retained-rx
  migration, MQTT_NAME twin-mode requirement, retained-store
  growth note (housekeeping deferred per Task 11).
- docs/PEER_PROTOCOL.md: MsgPeerClient* types 125-128 with routing
  (satellite+twin only, not trunk).
- CLAUDE.md: refresh trunk/peer message overview to reflect rename
  and new types.
This commit is contained in:
Audric committed 2026-04-29 17:50:31 +02:00
1 parent db16676c16
commit c19f7d7752
2 files changed
+212 -13

No files matched your search

+165 -12
View File
@@ -53,7 +53,9 @@ use `TOPIC_PREFIX/#` to receive everything, or subscribe to specific subtrees.
### Talker events ### Talker events
Published when a client or trunk peer starts or stops talking on a talk group. Published when a **locally connected** client starts or stops talking on a talk
group. Peer-side talker events are published under the `peer/` subtree (see
below).
``` ```
{TOPIC_PREFIX}/talker/{tg}/start {TOPIC_PREFIX}/talker/{tg}/start
@@ -65,12 +67,15 @@ Payload:
{"callsign": "ON4ABC", "source": "local"} {"callsign": "ON4ABC", "source": "local"}
``` ```
`source` is `"local"` when the talker is a directly connected client, or These topics are **local-only** — they fire only for clients directly connected
`"trunk"` when the talker is on a remote reflector reached via trunk. to this reflector. Non-retained. Dashboards that want every talker on the mesh
(local + peer) must also subscribe to `peer/+/talker/+/start` and
`peer/+/talker/+/stop` (see [Per-peer client topics](#per-peer-client-topics)).
### Client events ### Client events
Published when a SvxLink node authenticates or disconnects. Published when a SvxLink node authenticates or disconnects from **this**
reflector.
``` ```
{TOPIC_PREFIX}/client/{callsign}/connected {TOPIC_PREFIX}/client/{callsign}/connected
@@ -87,10 +92,14 @@ Disconnected payload:
{} {}
``` ```
Both are non-retained. On disconnect, the reflector also clears the retained
`client/{callsign}/rx` and `client/{callsign}/status` topics (zero-length
retained publish).
### Receiver (RX) status events ### Receiver (RX) status events
Published on every signal strength update from a connected node. Each node can Published on signal-strength updates from a connected node. Each node can have
have multiple receivers — the payload contains all of them keyed by receiver ID. multiple receivers — the payload contains all of them keyed by receiver ID.
``` ```
{TOPIC_PREFIX}/client/{callsign}/rx {TOPIC_PREFIX}/client/{callsign}/rx
@@ -109,6 +118,99 @@ Payload:
| `sql_open` | boolean | Whether the squelch is open | | `sql_open` | boolean | Whether the squelch is open |
| `active` | boolean | Whether the receiver is actively selected | | `active` | boolean | Whether the receiver is actively selected |
This topic is **retained** (changed from non-retained in the peer-client
liveness update — see migration note below). It is debounced at 500 ms per
callsign to avoid excessive broker write churn from 50 Hz rx-update rates.
### Per-client status events
Published when the reflector's internal per-client status blob changes (receiver
configuration, QTH data, monitored TGs, etc.).
```
{TOPIC_PREFIX}/client/{callsign}/status
```
Payload: the same rich per-client JSON blob that appears inside `nodes/local`
under the node's callsign key. **Retained.** Cleared on client disconnect.
This is new in the peer-client liveness update. Previously the status blob was
only accessible via the full `nodes/local` snapshot; this topic surfaces it
per-client so dashboards can subscribe per-callsign.
### Per-peer client topics
When this reflector is connected to a satellite or twin partner, it republishes
per-client liveness events received from that peer under its own MQTT broker.
```
{TOPIC_PREFIX}/peer/{peer_id}/client/{callsign}/connected
{TOPIC_PREFIX}/peer/{peer_id}/client/{callsign}/disconnected
{TOPIC_PREFIX}/peer/{peer_id}/client/{callsign}/rx
{TOPIC_PREFIX}/peer/{peer_id}/client/{callsign}/status
{TOPIC_PREFIX}/peer/{peer_id}/talker/{tg}/start
{TOPIC_PREFIX}/peer/{peer_id}/talker/{tg}/stop
```
`{peer_id}` is the satellite's configured ID (or twin's `MQTT_NAME`).
**Routing:** these topics fire only for satellite and twin links. Trunk peers
continue to exchange only `MsgPeerNodeList` snapshots and talker events — they
do not emit `MsgPeerClient*` messages. Future trunk-axis enablement is a
purely additive change.
| Topic | Retained | Notes |
|-------|----------|-------|
| `peer/.../client/.../connected` | No | Fired when peer's client authenticates |
| `peer/.../client/.../disconnected` | No | Fired on peer client disconnect |
| `peer/.../client/.../rx` | **Yes** | 500 ms sender-debounced rx blob |
| `peer/.../client/.../status` | **Yes** | Rich status blob (same format as local `client/.../status`) |
| `peer/.../talker/.../start` | No | Peer-namespaced talker start |
| `peer/.../talker/.../stop` | No | Peer-namespaced talker stop |
`connected` payload:
```json
{"tg": 2626, "ip": "10.0.0.5"}
```
`disconnected` payload:
```json
{}
```
`rx` and `status` payloads are JSON strings with the same schema as their
local equivalents (`client/.../rx` and `client/.../status`).
**Retained-store growth note.** When a peer client disconnects, the retained
`peer/{peer_id}/client/{callsign}/rx` and `.../status` topics survive in the
broker until cleared. The reflector **does not automatically clear** them on
peer disconnect — this cleanup is deferred (a libmosquitto thread-safety issue
blocks automatic in-process clearing; tracked as a future improvement).
Dashboards should correlate rx/status topics with the current `nodes/{peer_id}`
snapshot to suppress display of callsigns no longer in that roster. Out-of-band
broker housekeeping (e.g. a periodic retained-message audit script) is the
recommended hygiene strategy at scale.
**Dashboard subscription patterns.** To receive every talker on the mesh:
```
talker/+/start
talker/+/stop
peer/+/talker/+/start
peer/+/talker/+/stop
```
To receive per-client liveness for all peers:
```
client/+/connected
client/+/disconnected
client/+/rx
client/+/status
peer/+/client/+/connected
peer/+/client/+/disconnected
peer/+/client/+/rx
peer/+/client/+/status
```
### Trunk events ### Trunk events
Published when a trunk link's outbound or inbound connection goes up or down. Published when a trunk link's outbound or inbound connection goes up or down.
@@ -169,8 +271,8 @@ The payload is identical to the HTTP `/status` JSON response.
{TOPIC_PREFIX}/status {TOPIC_PREFIX}/status
``` ```
This is the only topic published with MQTT **retain** enabled, so new Published with MQTT **retain** enabled so new subscribers immediately receive
subscribers immediately receive the last known state. the last known state.
--- ---
@@ -181,15 +283,66 @@ subscribers immediately receive the last known state.
| `talker/...` | 0 | No | | `talker/...` | 0 | No |
| `client/.../connected` | 0 | No | | `client/.../connected` | 0 | No |
| `client/.../disconnected` | 0 | No | | `client/.../disconnected` | 0 | No |
| `client/.../rx` | 0 | No | | `client/.../rx` | 0 | **Yes** ¹ |
| `client/.../status` | 0 | **Yes** |
| `trunk/...` | 0 | No | | `trunk/...` | 0 | No |
| `nodes/local` | 0 | **Yes** | | `nodes/local` | 0 | **Yes** |
| `nodes/<peer_id>` | 0 | **Yes** | | `nodes/<peer_id>` | 0 | **Yes** |
| `peer/.../client/.../connected` | 0 | No |
| `peer/.../client/.../disconnected` | 0 | No |
| `peer/.../client/.../rx` | 0 | **Yes** ¹ |
| `peer/.../client/.../status` | 0 | **Yes** |
| `peer/.../talker/...` | 0 | No |
| `status` | 0 | **Yes** | | `status` | 0 | **Yes** |
QoS 0 (fire-and-forget) is used throughout. Event messages are ephemeral — a ¹ `rx` topics are debounced at 500 ms per callsign. Native rx-update rate is
missed talker start is covered by the next periodic status dump. Retain on ~50 Hz; debounce keeps roughly 1 in 25 updates. Adequate for human-readable
`status` ensures late-joining subscribers get a baseline immediately. dashboards; a non-debounced data path would be needed for automated signal
strength logging (not currently implemented).
**Migration note for `client/.../rx`:** this topic changed from non-retained to
retained in the peer-client liveness update. Existing subscribers see no
behavior change (they will receive a retained bootstrap value on subscribe,
which they may not have before). Zero-length retained publish on client
disconnect clears the entry immediately.
QoS 0 (fire-and-forget) is used throughout. Missed event messages are covered
by the next periodic `status` dump or the retained `nodes/*` snapshots.
---
## Twin-mode and `MQTT_NAME`
When two twin reflectors share a single MQTT broker, each must publish under a
disjoint topic subtree. Set `MQTT_NAME` in the `[MQTT]` section on both sides:
```ini
# Reflector A
[MQTT]
HOST=mqtt.example.com
PORT=1883
USERNAME=reflector
PASSWORD=secret
TOPIC_PREFIX=svxreflector
MQTT_NAME=refA
# Reflector B
[MQTT]
HOST=mqtt.example.com
PORT=1883
USERNAME=reflector
PASSWORD=secret
TOPIC_PREFIX=svxreflector
MQTT_NAME=refB
```
With `MQTT_NAME` set, every topic is published under
`{TOPIC_PREFIX}/{MQTT_NAME}/...` (e.g. `svxreflector/refA/nodes/local`).
Without `MQTT_NAME`, topics are published directly under `{TOPIC_PREFIX}/...`.
**Startup validation:** if a `[TWIN_x]` section is present **and** `[MQTT]` is
configured, the reflector aborts startup if `MQTT_NAME` is empty. This prevents
silent retained-topic collisions between the two twins on a shared broker.
--- ---
+47 -1
View File
@@ -399,6 +399,52 @@ were added by the jayReflector integration (v1.1.0) and are optional —
older peers silently ignore unknown message types, preserving backward older peers silently ignore unknown message types, preserving backward
compatibility. compatibility.
### `MsgPeerClient*` — per-client liveness deltas (types 125–128)
Types 123–124 are reserved for `MsgTwinExt*` (twin-only talker extensions).
Types 125–128 carry per-client liveness deltas for satellite and twin links.
| Type | Name | Fields |
|------|------|--------|
| 125 | `MsgPeerClientConnected` | `string callsign`, `uint32 tg`, `string ip` |
| 126 | `MsgPeerClientDisconnected` | `string callsign` |
| 127 | `MsgPeerClientRx` | `string callsign`, `string rx_json` |
| 128 | `MsgPeerClientStatus` | `string callsign`, `string status_json` |
**Routing:** these types are emitted only over `SatelliteLink`, `SatelliteClient`,
and `TwinLink`. `TrunkLink` does not emit them. The wire format is general, so
future trunk-axis enablement is purely additive.
**`MsgPeerClientConnected` (125):** sent when a local client successfully
authenticates. `tg` is the client's initial talk group; `ip` is the client's
remote address. Receiver republishes to MQTT `peer/{peer_id}/client/{callsign}/connected`.
**`MsgPeerClientDisconnected` (126):** sent on client disconnect. Receiver
republishes to MQTT `peer/{peer_id}/client/{callsign}/disconnected`.
**`MsgPeerClientRx` (127):** sent on rx-status changes. `rx_json` is a
JSON-serialized receiver map (same schema as `client/{callsign}/rx`), capped
at 64 KiB on receive (matching `MsgPeerNodeList` status-blob cap). The sender
debounces per callsign at 500 ms to limit rate. Receiver publishes as a
**retained** MQTT topic.
**`MsgPeerClientStatus` (128):** sent on per-client status changes.
`status_json` is the same rich per-client blob that appears in
`MsgPeerNodeList::status_blobs`, capped at 64 KiB. Receiver publishes as a
**retained** MQTT topic.
**TG filter interaction.** If the receiver has advertised a `MsgPeerFilter`
(e.g. a satellite with `SATELLITE_FILTER`), the sender checks the originating
client's current TG against that filter before emitting any `MsgPeerClient*`
message. Clients on filtered-out TGs produce no delta traffic toward that peer.
**Backward compatibility.** All three peer-protocol dispatch sites
(`SatelliteLink`, `SatelliteClient`, `TwinLink`) have graceful unknown-type
fall-through — unrecognised frames are silently ignored (heartbeat reset
happens before dispatch, so unknown frames count as keepalive). An old peer
receiving these types ignores them and falls back to the existing
`MsgPeerNodeList` snapshot mechanism.
`MsgPeerNodeList` is emitted by the reflector on local client login, logout, `MsgPeerNodeList` is emitted by the reflector on local client login, logout,
or TG change, debounced to 500 ms, and broadcast to every trunk peer. Peers or TG change, debounced to 500 ms, and broadcast to every trunk peer. Peers
republish it via MQTT under `nodes/<peer_id>` so a central dashboard can see republish it via MQTT under `nodes/<peer_id>` so a central dashboard can see
@@ -598,7 +644,7 @@ REMOTE_PREFIX=2
| File | Change | | File | Change |
|------|--------| |------|--------|
| `src/svxlink/reflector/ReflectorMsg.h` | Added `MsgPeerHello`–`MsgPeerHeartbeat` (types 115–120); `MsgPeerHello` carries `local_prefix` string instead of TG list | | `src/svxlink/reflector/ReflectorMsg.h` | Added `MsgPeerHello`–`MsgPeerHeartbeat` (types 115–120); `MsgPeerHello` carries `local_prefix` string instead of TG list. Added `MsgPeerClientConnected`–`MsgPeerClientStatus` (types 125–128). Renamed from `MsgTrunk*` (wire IDs unchanged). |
| `src/svxlink/reflector/TGHandler.h` | Added trunk talker map, 5 methods + snapshot accessor, `trunkTalkerUpdated` signal | | `src/svxlink/reflector/TGHandler.h` | Added trunk talker map, 5 methods + snapshot accessor, `trunkTalkerUpdated` signal |
| `src/svxlink/reflector/TGHandler.cpp` | Implemented trunk talker methods including `clearAllTrunkTalkers` | | `src/svxlink/reflector/TGHandler.cpp` | Implemented trunk talker methods including `clearAllTrunkTalkers` |
| `src/svxlink/reflector/Reflector.h` | Added `m_trunk_links`, `m_trunk_srv`, `initTrunkLinks()`, `initTrunkServer()`, `onTrunkTalkerUpdated()`, trunk inbound connection handling | | `src/svxlink/reflector/Reflector.h` | Added `m_trunk_links`, `m_trunk_srv`, `initTrunkLinks()`, `initTrunkServer()`, `onTrunkTalkerUpdated()`, trunk inbound connection handling |