Commit Graph
32 Commits
Author SHA1 Message Date
Audric 6b7a1f0306 docs(tests): sync counts + document Redis peer-node tests
Trunk count 27→30 (MQTT tests 28-30 from 0700e01) and Redis count
10→13 with three new rows for RedisPeerNodeTest (populate+diff,
hostile-string sanitization, trunk-down cleanup) from 7b95d0d.
2026-04-16 21:36:52 +02:00
Audric 7b95d0d2ce redis: mirror peer node lists + sanitize trunk-received strings
Peer node lists (MsgTrunkNodeList, type 121) now propagate into Redis
alongside the existing MQTT publish, so dashboards reading Redis see a
complete view of local + peer rosters. Each remote entry is stored as
live:peer_node:<peer_id>:<callsign> with 60s TTL; a per-peer cache
diffs incoming snapshots so dropped callsigns are DEL'd, and a full
trunk-down deletes all of that peer's entries.

All untrusted strings arriving via the trunk (peer_id from the hello,
plus callsign/qth/lat/lon in node lists) are now sanitized at receive:
control chars + ':' stripped, length bounded (32 callsign, 64 peer_id
and qth), non-finite and out-of-range coordinates cleared. Entries
whose callsign becomes empty after sanitization are dropped.

Also reorders TrunkLink in/outbound onDisconnected so the state-change
notification fires after the per-direction state is cleared, letting
consumers that inspect isActive() (like the Redis peer-node cleanup)
see the correct post-disconnect state.

Adds RedisPeerNodeTest (3 cases: populate+diff, sanitization, trunk-
down cleanup) and a build_node_list wire helper in test_trunk.py.
Exposes the trunk port in docker-compose.redis.yml so the host can
inject trunk frames against the r1 test reflector.
2026-04-16 21:25:37 +02:00
Audric 0700e01453 test(mqtt): add tests for client connect/disconnect, full status, and local nodes
Tests 28-30 cover MQTT publish paths that were untested:
- client connected/disconnected events with tg and ip fields
- periodic retained status message (mirrors /status endpoint)
- retained nodes/local list on client connect
2026-04-16 18:48:03 +02:00
Audric 5777bbb56e docs(tests): document twin satellite tests and Redis harness
Reflect tests added since the last doc sync: twin tests 9-10
(satellite + twin audio mirror), the satellite-on-ref1 in the twin
topology, and the separate Redis integration harness and its 10
test_redis.py cases.
2026-04-16 01:03:28 +02:00
Audric 337cfa7208 TWIN: forward mirrored audio/flush to satellites + integration tests
TwinLink::handleMsgTrunkAudio and handleMsgTrunkFlush now call
forwardAudioToSatellitesExcept / forwardFlushToSatellitesExcept,
mirroring TrunkLink. Without this, satellites attached to a twin
member only saw talker-state updates for traffic originated on the
partner — the audio frames themselves were dropped.

Adds test_09 (satellite handshakes with the twin parent) and test_10
(client on ref2 transmits; satellite on ref1 receives TalkerStart +
audio frames via the TWIN-mirror path). Wires a [SATELLITE] section
and host port mapping into the twin topology generator and lets
SatellitePeer.connect_satellite take an explicit port override.
2026-04-16 00:18:27 +02:00
Audric 7507c116e6 docs: polish TWIN_PROTOCOL and TESTS for shipped-feature framing
TWIN_PROTOCOL.md:
- Drop "DESIGN DRAFT" from the title.
- Rename "Implementation Sketch (non-binding)" to "Implementation" and
  rewrite as descriptive prose naming the actual files that shipped.
- Rename "Resolved Decisions" to "Design Rationale"; drop "from the
  original draft" framing.
- Correct the split-brain reconnect note: state heals via normal event
  flow; there is no bulk state-dump on reconnect.

TESTS.md:
- Document the two-phase run (default 3-reflector mesh + twin 4-reflector
  topology) and the --topology twin flag.
- Add a "Twin Test Topology" section with diagram and port-mapping table.
- Add a new test-case table for the 8 twin-protocol tests.
- List test_twin.py and the twin-related topology fields in File Structure.
2026-04-15 23:07:55 +02:00
Audric 81bd3eabf3 TWIN audio-mirror: stale-inbound cleanup + end-to-end integration test
Two changes:

1. TwinLink::acceptInboundConnection now treats an existing but-disconnected
   m_inbound_con as stale and replaces it with the new arriving connection,
   and wires a disconnected signal on the inbound so m_inbound_con is
   cleared when the remote end goes away. Without these, a partner container
   restart left the surviving twin holding a dead inbound reference that
   kept rejecting the partner's reconnection attempts until the heartbeat
   RX timeout cleared it (5s window, mid-test).

2. New test_08_audio_mirror_between_twins integration test. Reuses ClientPeer
   from test_trunk.py to connect a V2 sender to ref1 and a V2 receiver to
   ref2, both on TG 26201 (prefix 262). Sends audio from ref1's client,
   asserts the receiver on ref2 gets UDP audio + flush datagrams. Proves
   the Phase C1 path end-to-end:
     ref1 client UDP audio
       -> TGHandler.talkerUpdated -> TwinLink.onLocalAudio
       -> MsgTrunkAudio over [TWIN]
       -> ref2.handleMsgTrunkAudio -> broadcastUdpMsg
       -> ref2 client UDP socket.

All 8 tests now pass (36s wall clock).
2026-04-15 22:59:21 +02:00
Audric 06a2275ee6 Fix: guard send paths against writing to closed sockets; lower test port bases
Three fixes surfaced while running the E3 integration suite end-to-end:

1. sendMsgOnPairedInbound / sendMsgOnPairedOutbound / TwinLink sendMsgOn*
   now check isConnected() before calling write(). Without the guard, a
   heartbeat TX firing between the remote peer dying and our RX-timeout
   cleanup tripped an "assert sock >= 0" inside Async::TcpConnection::write
   and crashed the reflector (seen in test_07 as ref2 exiting with SIGSEGV
   after ref1 was killed).

2. Twin topology trunk_port_base values reduced (45000-48000) so the
   http-port offset (+3080) stays <= 65535. The earlier 60000-63000 bases
   produced 66080, which docker compose rejected as an invalid hostPort.

3. Twin reflector names lowercased (refa, refc) to satisfy Docker's image
   tag constraint (lowercase-only).

All 7 integration tests now pass end-to-end:
  - twin handshake (mutual authenticated hello)
  - no HMAC/prefix errors on startup
  - refa's PAIRED=1 trunk reports connected=True
  - both pair members see TRUNK_IT_DE back to refa
  - no twin-related ERRORs in startup logs
  - kill ref2 -> ref1 detects timeout, restart -> re-handshakes
  - kill ref1 -> refa stays connected to the pair via ref2 (failover)
2026-04-15 22:47:05 +02:00
Audric 9acb765110 tests: integration tests for TWIN handshake, mirror, failover
Adds tests/test_twin.py with 7 tests covering the TWIN topology:
  1–2. Twin handshake presence and absence of auth errors on ref1/ref2
  3–4. PAIRED=1 trunk (refA↔DE pair) reported connected on all three sides
  5.   Twin wiring smoke test (no ERROR[TWIN], server-listen log present)
  6.   Twin disconnect/recovery: kill ref2, verify ref1 detects timeout,
       verify re-handshake after restart
  7.   PAIRED trunk failover: kill ref1, verify refA still routes via ref2

run_tests.sh extended to tear down the default mesh, regenerate configs
with --topology twin, run test_twin.py, then restore the default topology.
2026-04-15 22:28:42 +02:00
Audric 9cfea32da6 tests: topology schema supports twin_of and paired trunks
Add TWIN_TOPOLOGY data (TWIN_REFLECTORS, TWIN_TRUNKS) to topology.py and
extend generate_configs.py to render [TWIN] sections, TWIN_LISTEN_PORT, and
PAIRED=1 multi-host trunk sections when invoked with --topology twin (or
TOPOLOGY=twin env var).  Default topology and its generated output are
unchanged.
2026-04-15 22:23:48 +02:00
Audric ba3b100361 Fix 4 pre-existing legacy-test failures
Three distinct root causes, all pre-existing on master and confirmed
there with the same symptoms:

1. tests/generate_configs.py was missing COMMAND_PTY=, so the reflector
   never opened its admin PTY. Every PTY-driven test (MUTE, UNMUTE, CFG,
   TRUNK RELOAD) wrote to a regular file that nobody read. Adding the
   config entry makes those commands actually reach the reflector, fixing
   test_24_pty_trunk_mute and test_25_pty_trunk_reload.

2. TrunkLink::statusJson built active_talkers by iterating the global
   trunk-talker map and filtering by isSharedTG(tg), which checks the
   peer's remote_prefix. When TG_MAP remaps a peer-owned wire TG to a
   local-owned TG, the local TG no longer matches the peer's prefix, so
   the view silently dropped it. Iterate m_peer_active_tgs directly
   instead — that set already contains post-remap local TGs for this
   specific peer. Fixes test_22_tg_map_remap_in.

3. Python test harness parsed MsgTrunkNodeList vector-length prefixes as
   u32 ('!I'), but AsyncMsg.h MsgPacker<std::vector> emits u16 lengths.
   The parser mis-read into garbage at huge offsets and crashed with a
   struct.error. Switch read_vec_str/u32/f32 to u16 ('!H') to match the
   wire format. Fixes test_27_node_list_emitted.

Legacy suite: 27/27 passing (was 23/27).
Redis suite: 10/10 still passing.
2026-04-15 15:59:36 +02:00
Audric 16a98f3562 Test + document dynamic trunk add/remove via Redis pub/sub
Add RedisTrunkAddRemoveTest (2 cases: happy-path add/remove and
missing-fields guard) to the Redis integration suite (10 tests total).
Update docs/REDIS.md with trunk:peer key schema, override-semantics
bullet, cookbook add/remove subsections, and static-vs-Redis note.
2026-04-15 15:16:54 +02:00
Audric bc412e1847 Remove Redis mute plumbing; expose mute list in /status JSON
Dashboard will write mutes directly to the PTY rather than Redis; the
Redis addTrunkMute/removeTrunkMute/loadTrunkMutes methods and the PTY
write-through were unused. Mute state is now reflected in the /status
JSON as a per-trunk 'muted' array so operators and dashboards can see
current state without polling Redis.
2026-04-15 13:45:00 +02:00
Audric aed5566956 Split run_redis_tests.sh into up/test/down subcommands
Default 'all' runs the full cycle (CI-friendly). Developers can use
'up' once, 'test' repeatedly as they iterate, 'down' when finished.
Dramatically cuts per-iteration overhead — no rebuild or healthcheck
wait between test runs.
2026-04-15 13:40:44 +02:00
Audric a7cd1909f9 Test: --import-conf-to-redis is idempotent 2026-04-15 13:06:30 +02:00
Audric 6036f4903a Test: reflector survives Redis outage and resyncs on restore
Adds RedisOutageTest: stops Redis mid-session, verifies the existing V2
client connection stays alive, then confirms the reflector logs
config.changed: all after reconnect and that post-recovery user writes
take effect.

Fixed callsign N0OTHR to satisfy the reflector's default ACCEPT_CALLSIGN
regex (N0OTHER is 7 chars and fails the pattern).
2026-04-15 13:04:01 +02:00
Audric 9ce6211b03 Test: live:client hash appears/disappears on V2 auth/disconnect
Add RedisLiveStateTest (2 tests) to test_redis.py verifying that
live:client:<callsign> hashes appear in Redis on V2 client auth and
are deleted on disconnect.

Fix a pre-existing bug in RedisStore where drainLiveQueue() sent HSET/
DEL/EXPIRE commands on m_async — the same hiredis context used for
SUBSCRIBE. Redis rejects non-pub/sub commands on a subscribed connection,
causing the repeated "async disconnect" loop seen in logs. Add a second
async context m_async_write exclusively for live-state writes; the sub
context m_async is now used only for SUBSCRIBE/config.changed delivery.

All 7 Redis integration tests pass.
2026-04-15 11:54:48 +02:00
Audric 685696b6b2 Test: PTY MUTE/UNMUTE persists to Redis 2026-04-15 11:09:47 +02:00
Audric ce305e957e Test: verify trunk filter reload via Redis pub/sub
Add [TRUNK_TEST] placeholder trunk section to the Redis test topology so
TrunkLink::reloadConfig() is instantiated. Add RedisTrunkFilterTest with
two tests that SADD/SREM blacklist and allow entries, publish
config.changed, and assert the expected 'Reloaded filters' log line
appears in container stdout within 3 s.
2026-04-15 11:06:51 +02:00
Audric 363648ae43 Add Redis test harness and user add/disable integration tests
Parallel harness (topology_redis.py, generate_redis_configs.py,
docker-compose.redis.yml, run_redis_tests.sh) runs on port range 45xxx
without conflicting with the legacy test stack. test_redis.py adds two
integration tests: user add+auth and user disable rejection, both using
the existing ClientPeer V2 auth from test_trunk.py.
2026-04-15 11:03:09 +02:00
Audric b16653e4df Test harness: add redis service + per-reflector redis flag (infra only)
- topology.py: add REDIS constants and redis_db_index() helper; support a
  'redis' key in REFLECTORS entries (default off — not flipped for any
  reflector here).
- generate_configs.py: emit [REDIS] section per reflector when flagged,
  add redis:7-alpine service to docker-compose when any reflector is
  flagged, add depends_on for redis-enabled reflectors.

No reflector has 'redis: True' set; regenerated configs match master
byte-for-byte. Later tests (F2+) will flip the flag selectively and
handle Redis population via --import-conf-to-redis.
2026-04-15 10:54:02 +02:00
Audric 5708e2d0e8 Merge jayReflector additions: per-trunk filters, node-list, PTY mute
Ports DJ1JAY / FM-Funknetz' jayReflector features (https://github.com/dj1jay/jayReflector)
into GeuReflector while keeping the in-process MqttPublisher.

Per-trunk config (TrunkLink): BLACKLIST_TGS, ALLOW_TGS, TG_MAP (with
explicit-route bypass of the prefix routing check), PEER_ID. New helpers
TgFilter.h provide exact / "24*" / "10-20" syntax shared across keys.

Wire protocol (additive, backward compatible — older peers ignore unknown
types): MsgTrunkNodeList (type 121) carries callsign + current_tg + optional
lat/lon/QTH; MsgTrunkFilter (type 122) reserved for satellite TG filters.

Reflector emits debounced (500 ms) MsgTrunkNodeList to all trunk peers on
local client login/logout/TG change. Inbound lists are republished via MQTT
under nodes/<peer_id>; the local list under nodes/local. New MQTT_NAME global
key inserts a path component so several reflectors can share a TOPIC_PREFIX.

PTY commands (Reflector): TRUNK MUTE|UNMUTE <section> <callsign>,
TRUNK RELOAD [<section>] re-reads BLACKLIST_TGS/ALLOW_TGS/TG_MAP without
restart, TRUNK STATUS [<section>] dumps a one-line summary per link.
Mute is applied on the inbound audio path.

Tests: 8 new integration tests (19-27) plus a TEST_PEER_FILTER fixture in
topology.py. Tests cover PEER_ID hello, BLACKLIST/ALLOW/TG_MAP semantics,
PTY MUTE/RELOAD/STATUS via docker exec, MQTT_NAME topic namespacing, and
node-list emission. Total now 27 tests.

Docs: docs/JAY-additions.md credits DJ1JAY / FM-Funknetz and lists every
merged feature with file pointers and the filter-evaluation order.
README.md links it. svxreflector.conf.in documents every new key.

Bumps SVXREFLECTOR to 1.3.99.13+trunk.
2026-04-14 23:48:03 +02:00
Audric 8b6148a678 Fix satellite disconnect loop: parent now sends hello reply
The parent SatelliteLink never sent a hello reply after authenticating
the satellite client. This caused two problems:

1. The satellite client's m_hello_received stayed false, preventing it
   from forwarding any local events to the parent.
2. No parent→satellite traffic until the first heartbeat at ~10s,
   allowing intermediate firewalls/NAT to kill the idle connection
   (observed as ~7s disconnect-after-auth loops).

Send a MsgTrunkHello reply from the parent, matching what TrunkLink
already does for trunk peers. Update tests for two-way handshake.
2026-04-10 10:59:39 +02:00
Audric bca223afbe Add MQTT integration test for talker events
Add mosquitto broker to test Docker Compose, configure [MQTT] sections
in all generated reflector configs, and add test_18_mqtt_talker_event
that verifies talker start/stop events are published to MQTT topics.
2026-04-08 20:36:23 +02:00
Audric 05c4c88ff3 Require matching trunk section names and cap audio debug at 500 frames
Trunk link matching now requires the peer's hello ID (section name) to
match the local [TRUNK_x] section name. Both sides of a trunk link must
use the same section name, agreed upon by both sysops. This replaces
the previous matching by secret+prefix only.

BREAKING CHANGE: existing deployments must rename their [TRUNK_x]
sections so both sides use the same name for each link.

Also cap TRUNK_DEBUG audio frame logging at 500 frames per trunk link
to prevent excessive log output during sustained transmissions.
2026-04-05 18:22:04 +02:00
Audric 638d3c527e Add TRUNK_DEBUG option for verbose trunk connection diagnostics
Add TRUNK_DEBUG=1 config option in [GLOBAL] that enables detailed
logging of trunk connection lifecycle: state on connect/disconnect,
heartbeat countdown warnings near timeout, every non-heartbeat frame
with direction and type, send path decisions, and prefix matching
details on the trunk server. Helps diagnose connection issues
reported in #1 where the remote side kills connections.
2026-04-05 11:55:43 +02:00
Audric 9c359ba507 Add integration test documentation and svxdashboard reference
Add tests/TESTS.md documenting the test suite topology, all 17 test
cases, harness components, and usage instructions. Link it from the
main README and add a tip pointing to audric/svxdashboard.
2026-04-05 10:57:52 +02:00
Audric 4e6bff7962 Merge /config into /status and remove /config endpoint
All static configuration fields (version, local_prefix, listen_port,
http_port, mode, satellite/satellite_server) are now included directly
in the /status JSON response. The /config endpoint is removed.
2026-03-29 15:29:45 +02:00
Audric accb4b3686 Fix bidirectional trunk routing and monitoring client notifications
Two bugs prevented real-world trunk conversations from working:

1. onTrunkTalkerUpdated only notified clients selected on a TG, not
   clients monitoring it. SvxLink repeaters monitoring a foreign TG
   never received MsgTalkerStart and could not auto-switch. Fixed by
   adding TgMonitorFilter to trunk talker broadcasts, matching the
   existing behavior of onTalkerUpdated for local talkers.

2. Trunk TG routing was one-way: when a client visited a foreign TG,
   isSharedTG forwarded to the owner, but the owner had no return
   path. Added per-link peer interest tracking — when a peer sends
   MsgTrunkTalkerStart for a TG, the receiving side records interest
   and forwards local activity on that TG back. Interest refreshes
   on audio, expires after 10 minutes idle, clears on disconnect.

New integration test verifies the full round-trip: client-A talks on
a foreign TG, monitoring client-B receives the notification, client-B
replies, and client-A receives audio back through the trunk.
2026-03-28 19:09:38 +01:00
Audric eca3c71122 Fix TG number substring match in log grep and remove debug logging
The interactive tester's log parser matched "TG #1" as a substring of
"TG #12001", "TG #10", etc., causing false positives for short TG numbers.
Use a regex negative lookahead (?!\d) so "TG #1" only matches when not
followed by another digit. Same fix applied to test_15 satellite routing.

Also remove debug logging accidentally left in TrunkLink::onLocalTalkerStart.
2026-03-27 15:19:13 +01:00
Audric d2f4acffcd Add satellite integration tests
5 new tests covering satellite protocol: handshake and /status visibility,
audio delivery from satellite to parent's local clients, trunk-to-satellite
audio forwarding, satellite audio routed to trunk peers via parent, and
disconnect cleanup. Reflector-a acts as the satellite parent with a
[SATELLITE] section; a SatellitePeer class connects as a fake satellite
using MsgTrunkHello with ROLE_SATELLITE.
2026-03-27 14:58:51 +01:00
Audric 685d7253ff Fix trunk receive-side TG filtering and add integration test suite
The receive-side handlers (handleMsgTrunkTalkerStart, handleMsgTrunkAudio,
etc.) used isSharedTG() which only checks the remote peer's prefix. This
caused non-cluster TGs to be silently dropped on the receiving reflector —
e.g. a client on reflector-a talking on TG 40001 (owned by reflector-b)
would never reach reflector-b because reflector-b checked the TG against
reflector-a's prefix instead of its own.

Add isOwnedTG() that accepts TGs matching either the local or remote
prefix, and use it in all four receive handlers. The send-side still uses
isSharedTG() (remote prefix only) which is correct.

Also add a Docker-based integration test suite (tests/) with 11 automated
tests covering handshake, routing, cross-reflector audio delivery, cluster
TGs, heartbeat, disconnect cleanup, and trunk-to-trunk isolation. An
interactive mode lets users test arbitrary TG numbers with routing verified
via reflector logs. Topology is defined once in tests/topology.py.

Fix Dockerfile to copy built shared libraries to the runtime image.
2026-03-27 14:43:57 +01:00