build: opt-out WITH_MQTT/WITH_REDIS flags + extend Redis to /status parity

- Add CMake options WITH_MQTT (default ON) and WITH_REDIS (default ON).
  When OFF, the matching .cpp is dropped from the target, the pkg_check
  is skipped, and MqttPublisher.h / RedisStore.h expose no-op stub
  classes so every call site in Reflector.cpp / ReflectorClient.cpp /
  TrunkLink.cpp keeps compiling. svxreflector.cpp's --import-conf-to-redis
  is gated on WITH_REDIS. Lets sysops who don't run MQTT or Redis drop
  libmosquitto-dev / libhiredis-dev from their build environment.
  README.md and docs/INSTALL.md document the flags.

- Fill the gap between /status and Redis with three new event-driven
  keys (all small, all using the existing 60s TTL refresh):
    * live:meta  — mode, version, local_prefix, listen_port, http_port,
      cluster_tgs, satellite-server stats. Written at startup, on
      reloadClusterTgs(), and on satellite connect/disconnect.
    * live📡<sat_id> — per-satellite status blob. Written via
      a new SatelliteLink::statusChanged signal on hello + on every
      talker start/stop. Cleared on disconnect / cleanup.
    * live:trunk:<section>.status — extended trunk hash with the full
      TrunkLink::statusJson() snapshot. Written at startup, on trunk
      state changes, and on config.changed-all reloads.

  A dashboard can now reconstruct the equivalent of GET /status from a
  handful of small Redis keys instead of one ~500 KB blob — idiomatic
  Redis usage, no per-second hot-write churn.

- New Redis tests: live_meta_populated_at_startup,
  live_trunk_carries_status_blob.

All four flag combinations build cleanly. 31 trunk + 10 twin + 16 redis
pass.
This commit is contained in:
Audric committed 2026-04-17 02:52:36 +02:00
1 parent 688a62ec5b
commit bd196d6365
13 files changed
+447 -19

No files matched your search

+2
View File
@@ -253,6 +253,8 @@ Each test writes directly to Redis via `redis-cli` inside the container, publish
| 5 | `live:client` appears on auth | On V2 authentication, `live:client:<callsign>` hash is populated with `connected_at`, `ip`, `tg`, `codecs` |
| 6 | `live:client` disappears on disconnect | After forceful TCP close the hash is removed within ~5 s |
| 6b | `live:client` rich status blob | After the client sends `MsgNodeInfo`, `live:client:<callsign>.status` holds the full per-client JSON (qth, rx params, monitoredTGs) and `updated_at` |
| 6c | `live:meta` populated | `live:meta` hash carries `mode`, `version`, `local_prefix`, `listen_port`, `cluster_tgs`, `updated_at` after a `config.changed all` republish |
| 6d | `live:trunk` carries status blob | `live:trunk:<section>.status` is a serialized `TrunkLink::statusJson()` (host, port, connected, local/remote prefix, active_talkers, muted) |
| 7 | Outage + resync | Stopping Redis keeps existing clients connected; on restart the reflector logs `config.changed: all` and accepts newly-written users |
| 8 | `--import-conf-to-redis` idempotent | Running the importer twice against the same `.conf` produces identical keyspace dumps |
| 9 | Peer node list populates + diffs | Inbound `MsgTrunkNodeList` creates `live:peer_node:<section>:<callsign>` hashes; a shrunk follow-up list DELs dropped callsigns and updates mutated fields (e.g. `tg`) |
+40
View File
@@ -297,6 +297,46 @@ class RedisLiveStateTest(unittest.TestCase):
# Drain queue + Redis publish should take <100ms. Give more for slack.
self._wait_for_hash(k("live:client:N0TEST"), present=False, timeout=5.0)
def test_live_meta_populated_at_startup(self):
"""live:meta hash carries reflector-wide info (mode, version, ports,
cluster_tgs) so dashboards can reconstruct the /status header
without an HTTP query."""
# setUp() flushdb wiped the startup-written keys; trigger a
# republish via the existing config.changed pubsub.
publish("all")
time.sleep(0.5)
raw = self._wait_for_hash(k("live:meta"), present=True, timeout=5.0)
fields = raw.splitlines()
m = dict(zip(fields[0::2], fields[1::2]))
self.assertEqual(m.get("mode"), "reflector")
self.assertIn("version", m)
self.assertIn("listen_port", m)
self.assertIn("local_prefix", m)
# cluster_tgs is always written (may be empty CSV)
self.assertIn("cluster_tgs", m)
self.assertIn("updated_at", m)
def test_live_trunk_carries_status_blob(self):
"""live:trunk:<section> includes a `status` field with the full
TrunkLink::statusJson() snapshot (host, port, connected flags,
local/remote prefixes, active_talkers, muted)."""
import json as _json
publish("all")
time.sleep(0.5)
raw = self._wait_for_hash(k("live:trunk:TRUNK_TEST"),
present=True, timeout=5.0)
fields = raw.splitlines()
m = dict(zip(fields[0::2], fields[1::2]))
self.assertIn("status", m)
status = _json.loads(m["status"])
# Sanity: statusJson contract from TrunkLink.cpp
self.assertIn("host", status)
self.assertIn("port", status)
self.assertIn("connected", status)
self.assertIn("local_prefix", status)
self.assertIn("remote_prefix", status)
self.assertIn("active_talkers", status)
class RedisOutageTest(unittest.TestCase):
"""Verify reflector tolerates Redis going down and resyncs on resume."""