Commit Graph
94 Commits
Author SHA1 Message Date
Audric 6fb5aa4b91 TwinLink: mirror external trunk-talker state to partner
When TrunkLink receives MsgTrunkTalkerStart/Stop from an external peer,
Reflector now forwards those events to TwinLink via
notifyExternalTrunkTalkerStart/Stop.  TwinLink sends MsgTwinExtTalkerStart
(type 123) / MsgTwinExtTalkerStop (type 124) over the twin link, and the
receiving side calls TGHandler::setTrunkTalkerForTGViaPeer so the partner
twin blocks local clients from keying up the TG.  On disconnect,
clearPeerTalkerState iterates held TGs before clearing them so the partner
is also notified.  No echo loop: Reflector::onTrunkTalkerUpdated does not
feed back into TwinLink.
2026-04-15 21:30:14 +02:00
Audric 2554efb392 TwinLink: mirror local-client talker and audio to partner
Outbound: onLocalTalkerUpdated/onLocalAudio/onLocalFlush now send
MsgTrunkTalkerStart/Stop, MsgTrunkAudio, MsgTrunkFlush over the twin
TCP connection when isActive().

Receive-side: handleMsgTrunkTalkerStart/Stop call
TGHandler::setTrunkTalkerForTG / clearTrunkTalkerForTG, which fires
trunkTalkerUpdated → Reflector::onTrunkTalkerUpdated, broadcasting
MsgTalkerStart/Stop to local clients. handleMsgTrunkAudio and
handleMsgTrunkFlush call Reflector::broadcastUdpMsg directly.

Reflector::onTalkerUpdated (talkerUpdated signal handler) now notifies
m_twin_link after the trunk/satellite loops. MsgUdpAudio and
MsgUdpFlushSamples handlers similarly call m_twin_link->onLocalAudio/
onLocalFlush in the non-satellite branch.

No echo loop: trunkTalkerUpdated (twin receive path) is distinct from
talkerUpdated (local-client signal that drives outbound sends).
2026-04-15 21:18:24 +02:00
Audric 9b748d1bdc TWIN inbound: validate HMAC and local_prefix before handoff
Add HMAC verification (msg.verify) and local_prefix equality check in
Reflector::twinPendingFrameReceived, after the role check and before
handing the connection off to TwinLink::acceptInboundConnection.  HMAC
is checked first (fail-fast, avoids leaking prefix info on bad secret).
Expose secret() and localPrefix() as const accessors on TwinLink.
2026-04-15 21:13:58 +02:00
Audric 4b6346d4ab TWIN server: accept inbound twin connections on TWIN_LISTEN_PORT
Replace the initTwinServer() stub with a real Async::TcpServer that
listens on TWIN_LISTEN_PORT (default 5304). Inbound connections are
held in m_twin_pending_cons with a 10-second hello timeout; on receipt
of a valid MsgTrunkHello with ROLE_TWIN the connection is handed off to
TwinLink::acceptInboundConnection(). Pending entries are cleaned up on
timeout, disconnect, and successful handoff. No server is created when
no [TWIN] section is configured.
2026-04-15 20:54:51 +02:00
Audric 9f349fff5c TwinLink: outbound connect, handshake, heartbeat skeleton
Implements TwinLink.cpp with constructor (random priority nonce via
std::random_device, signal wiring), initialize() (parse [TWIN] HOST/PORT/
SECRET and [GLOBAL] LOCAL_PREFIX, addStaticSRVRecord + reconnect policy,
m_con.connect()), onConnected() sending MsgTrunkHello with ROLE_TWIN,
handleMsgTrunkHello() validating role/HMAC/prefix-match, heartbeatTick()
(2s TX / 5s RX thresholds), sendMsg/sendMsgOnOutbound/sendMsgOnInbound,
and acceptInboundConnection().  Phase C handlers (talker mirror, audio,
ext-trunk) are present as empty stubs.

Wires Reflector::initTwinLink() to construct and initialize a real TwinLink
(replaces stub), adds destructor cleanup, and adds TwinLink.cpp to
CMakeLists sources.  Build passes clean.
2026-04-15 20:33:54 +02:00
Audric 074b1aea4c TwinLink.h: align with TrunkLink.h style (GPL header, section comments, heartbeatTick name) 2026-04-15 20:27:33 +02:00
Audric 73aca6decc TwinLink: header skeleton 2026-04-15 20:23:53 +02:00
Audric 3c92de178c Reflector: parse [TWIN] section (stub; no link behavior yet) 2026-04-15 20:08:11 +02:00
Audric c76f07af31 TGHandler: per-peer attribution for trunk-talker state
Add setTrunkTalkerForTGViaPeer, clearTrunkTalkersForPeer, and
peerIdForTG to support selective cleanup of trunk-talker state when
a specific peer disconnects (needed by the TWIN link protocol).
Also ensure clearTrunkTalkerForTG and clearAllTrunkTalkers keep the
new m_trunk_talker_peer_ids map in sync.
2026-04-15 19:57:38 +02:00
Audric e6946d0da8 msg: add ROLE_TWIN and MsgTwinExtTalkerStart/Stop (types 123/124) 2026-04-15 19:43:52 +02:00
Audric 8aecd951da chore: ignore .worktrees/ (and include pre-existing .gitignore self-entry) 2026-04-15 19:33:19 +02:00
Audric 205153ad9c docs(TWIN): resolve open design questions; switch to active/active
Rewrite the TWIN protocol spec around the decisions agreed with the
sysop: active/active external-trunk ownership with sticky per-frame
socket selection (refA holds both TCP sockets, picks one, fails over
instantly), single [TRUNK_x] section with multiple hosts + PAIRED=1
on the external peer side, full TGHandler state mirror across the
twin link (including external-trunk-talker state via new
MsgTwinExtTalkerStart/Stop messages — types 123/124, replacing the
earlier MsgTwinRoleClaim/MsgTwinRoleState), 2s/5s heartbeat cadence,
TCP relay for twin audio, and split-brain tolerated during twin-link
outages with handshake-time state resync on reconnect.

No code yet; this is still a design doc pending implementation.
2026-04-15 19:00:39 +02:00
Audric bb4d058aaa docs(TWIN): note MsgTrunkFilter (122) is unused on twin links
The message-type table jumped from 121 to 123 without explaining why
122 is skipped. Add a row making explicit that MsgTrunkFilter is
satellite-only and not meaningful on a twin link (twins mirror all TGs).
2026-04-15 18:25:25 +02:00
Audric a84cde03a1 docs: add TWIN_PROTOCOL design draft for HA-pair reflector linking
Design-only draft (not yet implemented) introducing a dedicated [TWIN]
link type so two reflectors can act as a redundant pair with a shared
LOCAL_PREFIX — cleaner than abusing overlapping trunk prefixes for HA.
Covers handshake (ROLE_TWIN via MsgTrunkHello), cross-twin talker
arbitration, active/standby external-trunk ownership with priority-nonce
election, and flags 7 open design questions for sysop review before
coding begins.
2026-04-15 18:19:18 +02:00
Audric 21ed18c893 docs(REDIS): add PHP dashboard examples and MySQL→conf migration
REDIS.md previously showed only redis-cli commands. Add two sections
after the minimal working example:

- PHP dashboard example using phpredis (noting Predis as a drop-in):
  connect, user CRUD, cluster TGs, per-trunk filters, dynamic trunk
  peer add/remove, live state reads, live.changed subscribe, and
  invoking --import-conf-to-redis from PHP.

- Migration guide for operators coming from a custom MySQL-backed
  dashboard: an assumed MySQL schema plus a PHP PDO script that
  generates a .conf snippet, piped through --import-conf-to-redis for
  a one-shot migration with an audit step.
2026-04-15 16:27:09 +02:00
Audric 65063fd92a docs: catalogue v1.1 jay additions and v1.2 Redis store in README + protocol doc
README 'What it adds over SvxReflector' was still on the pre-v1.1
surface. Add entries for:
  - per-trunk TG filters (BLACKLIST_TGS/ALLOW_TGS/TG_MAP/PEER_ID) with
    the shared filter syntax
  - node-list broadcasting (MsgTrunkNodeList) and its MQTT republishing
  - PTY admin channel (TRUNK MUTE/UNMUTE/RELOAD/STATUS, CFG)
  - optional Redis-backed config store (points at docs/REDIS.md)

Also refresh the /status and MQTT bullets to mention muted-callsigns,
Redis metrics, node lists, and MQTT_NAME.

TRUNK_PROTOCOL.md protocol-messages table was missing the jayReflector
message types — add 121 MsgTrunkNodeList and 122 MsgTrunkFilter with
their fields, plus a short paragraph explaining each. Also flesh out
MsgTrunkHello's listed fields to include the nonce/hmac/role actually
on the wire.
2026-04-15 16:20:11 +02:00
Audric db9dcf6917 Merge feature/redis-config-store: Redis-backed config store
Adds an optional Redis-backed config store the reflector consults when
[REDIS] is present in svxreflector.conf. When absent, behavior is
byte-identical to master.

When enabled, Redis becomes the source of truth for:
  - [USERS] / [PASSWORDS] (callsign -> password-group -> password)
  - CLUSTER_TGS
  - per-trunk BLACKLIST_TGS / ALLOW_TGS / TG_MAP
  - trunk peer definitions themselves (host/port/secret/remote_prefix/
    peer_id), addable/removable at runtime via pub/sub — no restart

The reflector subscribes to <KEY_PREFIX>:config.changed and reacts per
scope (users, cluster, trunk:<section>, all). Live state (live:client:*,
live:talker:*, live:trunk:*) is pushed through a bounded queue drained
every 75 ms with 60 s TTLs refreshed every 30 s — no Redis call ever
happens on the audio path. Two hiredis async contexts: one pub/sub
subscriber, one for writes. Reconnect with exponential backoff and a
full reload on resume.

Migration tool: svxreflector --import-conf-to-redis [--dry-run]
copies .conf sections into Redis. Idempotent.

Tests: 10 new integration tests (parallel Redis harness with up/test/
down subcommands, separate docker-compose.redis.yml). Legacy trunk
suite fixed: 27/27 pass (was 23/27) — three distinct pre-existing bugs
resolved (missing COMMAND_PTY in generator, statusJson filter dropping
TG_MAP remapped TGs, u32 vs u16 mismatch in Python NodeList parser).

Redis PTY mute plumbing scoped out; mute is local-only and exposed in
/status JSON as a per-trunk 'muted' array. Dashboards drive mutes via
PTY directly.
2026-04-15 16:02:03 +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 1d639dd0b0 Dynamic trunk add/remove via Redis pub/sub
Reflector::onRedisConfigChanged now handles 'trunk:<section>' events by
reading the trunk:<section>:peer hash from Redis:
  - peer present + no local link  -> create new TrunkLink
  - peer absent + local link       -> destroy local TrunkLink (Redis-managed only)
  - both present                   -> reload filters (existing behavior)
  - neither                        -> log and ignore

Tracks which sections were loaded from Redis (m_redis_trunk_sections) so
conf-based test trunks (e.g. TRUNK_TEST) correctly fall back to
reloadConfig() rather than being destroyed on a filter-change event.

Dashboards can now add/remove trunk peers without restarting the reflector.
2026-04-15 15:09:17 +02:00
Audric 9c6f27e12b Load trunk peer definitions from Redis at startup
When [REDIS] is configured, Reflector::initialize synthesizes [TRUNK_*]
sections from 'trunk:<section>:peer' hashes before the trunk discovery
loop. .conf [TRUNK_*] sections are ignored (with a warning) when Redis
is configured. The importer --import-conf-to-redis now also writes peer
definitions into 'trunk:<section>:peer' so existing configs can migrate.
2026-04-15 14:41:18 +02:00
Audric 5cab611ccd docs: remove Redis mute plumbing references; direct to PTY + /status 2026-04-15 13:48:28 +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 525bebdd5a Gitignore an internal workflow docs subdirectory 2026-04-15 13:32:45 +02:00
Audric 276aedc3e1 Document Redis-backed config store 2026-04-15 13:14:50 +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 2981361c6d Redis: reconnect with exponential backoff and full reload on resume 2026-04-15 09:47:04 +02:00
Audric d0b8a44dc7 Refresh live-state TTLs every 30s; expose Redis metrics in /status 2026-04-15 09:34:42 +02:00
Audric 97467a4f70 Push live-state events through queued drain to Redis 2026-04-15 09:25:07 +02:00
Audric 8363e36f6a Add bounded in-memory queue for live-state Redis writes 2026-04-15 09:21:01 +02:00
Audric 92c2a94940 Persist PTY MUTE/UNMUTE to Redis when [REDIS] is configured 2026-04-15 09:10:40 +02:00
Audric 2fc63fc6f3 Extend --import-conf-to-redis to cluster TGs and trunk filters
Imports CLUSTER_TGS from [GLOBAL] into Redis set cluster:tgs,
and per-[TRUNK_*] BLACKLIST_TGS/ALLOW_TGS into sets and TG_MAP
into a hash. Summary line updated with cluster_n and trunks_n counters.
2026-04-15 09:09:15 +02:00
Audric 97ebdeb172 Cluster TGs sourced from Redis when enabled; reload on pub/sub 2026-04-15 09:06:35 +02:00
Audric 11751a08ed TrunkLink reads filters/mutes from Redis when [REDIS] is configured 2026-04-15 09:04:49 +02:00
Audric 2826376070 Add --import-conf-to-redis migration tool (USERS+PASSWORDS) 2026-04-15 09:02:25 +02:00
Audric 977624febf Dispatch Redis config.changed events to per-scope reload paths 2026-04-15 08:57:08 +02:00
Audric 2a3515247c Route auth lookup through RedisStore when [REDIS] is configured 2026-04-15 08:46:39 +02:00
Audric 0de78c459b Add hiredis async adapter and pub/sub subscription 2026-04-15 02:52:03 +02:00
Audric 98b7d0a89e Parse [REDIS] section and connect at startup (sync only) 2026-04-15 02:47:23 +02:00
Audric 6ecbf69bc0 Implement RedisStore sync connect and schema reads/writes 2026-04-15 02:44:01 +02:00
Audric b64b79f2a7 Add RedisStore skeleton (no functionality yet) 2026-04-15 02:41:23 +02:00
Audric 2877d6be79 Add hiredis build/runtime dependency for upcoming Redis backend 2026-04-15 02:38:27 +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 6f5138cd11 Reference WW_DEPLOYMENT.md in README docs list 2026-04-12 23:24:48 +02:00
Audric d7260e524f Add worldwide deployment example doc 2026-04-12 23:17:56 +02:00
Audric 6ddf4ee3e8 Use git tag in version string instead of hardcoded trunk revision
Changes version from 1.3.99.12+trunk1@master to
1.3.99.12+trunk@<git describe> so the version automatically
reflects the current tag/commit.
2026-04-10 11:21:13 +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 76c2afc084 Add messaging integration ideas doc
Covers Telegram, SMS, Discord, email digests, WebSocket dashboards,
webhook relays, push notifications, and observability pipelines —
all driven by MQTT events.
2026-04-09 13:23:41 +02:00
Audric a2eefac1f2 Add MQTT RX status events and fix periodic status publishing
Periodic MQTT status was missing dynamic fields (trunks, cluster_tgs,
local_prefix, etc.) because they were only rebuilt during HTTP requests.
Extract status-building into refreshStatus() called from both paths.

Add per-client RX status MQTT events (client/{callsign}/rx) published on
every signal strength update, supporting multiple receivers per node.
2026-04-09 12:59:52 +02:00
Audric 4a9cba6edb Fix SvxReflectorDashboard link in README 2026-04-09 00:50:40 +02:00
Audric 483b1ffaa4 Add MQTT documentation to README and docs/MQTT.md 2026-04-08 20:48:37 +02:00
Audric c311217a96 Add MQTT config section template to svxreflector.conf 2026-04-08 20:44:33 +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 5b7a3dd8cd Wire MqttPublisher into Reflector event handlers 2026-04-08 20:32:02 +02:00
Audric 89f8c07ccc Add MqttPublisher class with config, lifecycle, and event publishing methods 2026-04-08 20:21:25 +02:00
Audric 7161408af5 Add libmosquitto dependency for MQTT publishing 2026-04-08 20:12:09 +02:00
Audric 175cb15254 Ignore duplicate hello on inbound trunk connection
handleMsgTrunkHello was called for hellos arriving on both outbound
and inbound connections. Inbound hellos are already handled by
acceptInboundConnection, so a second one arriving via onFrameReceived
(e.g. from TcpPrioClient background reconnect) is a duplicate.
Silently ignore it instead of printing a misleading double hello log.
2026-04-08 17:33:04 +02:00
Audric be4d3b99c5 Fix pending trunk connection leak causing permanent peer lockout
TcpConnection::disconnect() does not emit the disconnected signal,
so trunkClientDisconnected was never called to clean up
m_trunk_pending_cons entries. After any connection hiccup, pending
entries leaked permanently — once 2 accumulated from one IP, that
peer was locked out from inbound connections forever.

Clean up the pending map entry before calling disconnect() in both
trunkPendingTimeout and all error paths in trunkPendingFrameReceived.
2026-04-08 16:52:14 +02:00
Audric aa4b41f702 Update all documentation for mandatory matching trunk section names
Both sides of a trunk link must now use the same [TRUNK_x] section
name, agreed upon by both sysops. Updated all examples across README,
TRUNK_PROTOCOL, INSTALL, DEPLOYMENT_ITALY (EN+IT), and
DESIGN_SATELLITE_AND_CLUSTER to use sorted-pair naming convention
(e.g. TRUNK_01_02 for the link between prefix 01 and 02).
2026-04-05 18:33:29 +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 7d1aeff623 Fix trunk reconnect storm with per-IP pending connection limit
When two trunk peers simultaneously reconnect, rapid retries from one
peer could fill the global pending connection pool (5 slots), starving
other peers and creating a reject→reconnect→reject loop.

Add a per-IP limit of 2 pending (pre-hello) connections in the trunk
server, so one misbehaving or rapidly-reconnecting peer cannot exhaust
the pool.  Also increase outbound reconnect backoff (2s min, 30s max)
to reduce retry pressure after connection failures.
2026-03-29 19:47:17 +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 c82827080c Move version field from /status to /config HTTP endpoint 2026-03-28 23:04:35 +01:00
Audric e24c3a55e8 Add version field to /status HTTP JSON endpoint 2026-03-28 22:50:46 +01: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 8cf96f9ba5 Update docs to reflect decoupled trunk connections and implemented features
Connection handling docs still described the old priority-based tie-breaking
model removed in 3b7831c. Updated TRUNK_PROTOCOL.md, README.md to describe
the current dual-connection model (outbound preferred, inbound fallback).
Marked satellite and cluster TG features as implemented in design doc.
Added satellite files to TRUNK_PROTOCOL.md files-changed table.
2026-03-28 16:01:34 +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
Audric 3b7831c307 Decouple outbound and inbound trunk connections
The previous design treated outbound and inbound as mutually exclusive
via a ConDir state machine, causing a rapid reconnect loop when both
peers tried to connect simultaneously. Now both connections coexist
independently: outbound (TcpPrioClient, auto-reconnects) and inbound
(accepted from peer) each have their own hello state and heartbeat
counters. Data messages route through outbound with inbound as fallback.
2026-03-26 15:44:45 +01:00
Audric 67e3712d02 Add port comments and CI workflow to trigger svxlink-docker rebuild
- Annotate docker-compose port mappings with their purpose
- Add GitHub Actions workflow that dispatches a rebuild event to
  audric/svxlink-docker on every push to master
2026-03-26 14:11:57 +01:00
Audric b8d0dd19af Add trunk TCP server for bidirectional peer connections
Previously TrunkLink only connected outbound — there was no server
listening on port 5302, so both reflectors got "Connection refused."

Changes:
- Reflector: add trunk TcpServer (default port 5302, configurable
  via TRUNK_LISTEN_PORT) that accepts inbound peer connections,
  authenticates via HMAC, and matches by secret + prefix
- TrunkLink: support both outbound and inbound directions with
  automatic conflict resolution (lower priority keeps outbound)
- Security: pre-auth frame size cap (4KB), max 5 pending connections,
  10s hello timeout, log-injection sanitization
- Docs: updated TRUNK_PROTOCOL.md, README.md, CLAUDE.md
2026-03-26 12:59:04 +01:00
Audric 53a9a6fc75 Support overlapping TG prefixes with longest-prefix-match routing
isSharedTG now finds the longest matching remote prefix and verifies
no other prefix in the mesh is more specific. Each TrunkLink receives
the full set of all prefixes at startup via setAllPrefixes().
initTrunkLinks is split into two passes: collect all prefixes first,
then create links with full knowledge.
2026-03-26 10:55:47 +01:00
Audric dda6ac5531 docs: clarify cluster TG subscription model and satellite TG filtering
Cluster TGs are a per-reflector subscription choice, not a mesh-wide
requirement. Document that satellites forward all TGs unconditionally
with no prefix or cluster TG filtering.
2026-03-24 16:59:42 +01:00
Audric b958a53ab3 Remove connection throttling from all TCP servers 2026-03-22 15:33:08 +01:00
Audric 3a9b147b92 Relax client and satellite server connection throttling to match HTTP server 2026-03-22 10:19:07 +01:00
Audric ddbf8fd228 Relax HTTP server connection throttling for monitoring
Increase bucket_max from 10 to 100 and bucket_inc from 0.1 to 10.0
to allow more frequent polling of the /status endpoint.
2026-03-21 22:28:02 +01:00
Audric 64697e61d7 Fix event loop blocking on DNS abort in CppDnsLookupWorker
abortLookup() called m_result.get() synchronously, blocking the entire
event loop while waiting for a potentially long getaddrinfo() call to
finish (~18s when the DNS server is unreachable). This caused the HTTP
/status endpoint and all other event loop processing to stall whenever
a TrunkLink reconnect cycle aborted a pending DNS lookup.

Move the future and thread context to a detached cleanup thread so the
event loop returns immediately.
2026-03-20 20:28:26 +01:00
Audric 9f5ed86196 docs: add network requirements section to README
Clarify that trunk links require mutual reachability (static IP +
open port on both sides) while satellite links only need the parent
to be reachable (satellites can run behind NAT).
2026-03-20 19:15:16 +01:00
Audric fa57db6e62 Fix satellite heartbeat timeout cleanup and /status blocking
Heartbeat timeout called m_con->disconnect() on a server-managed
connection, which didn't trigger TcpServer::clientDisconnected —
leaving dead satellites in the map forever. After timeout, the
unsigned rx counter wrapped to UINT_MAX preventing re-detection.
The timer also kept firing sendMsg() to the dead socket, blocking
the event loop and causing /status to stall for ~10s.

Fix: SatelliteLink emits linkFailed signal instead of calling
disconnect directly. Reflector handles cleanup via a deferred
zero-timer to avoid re-entrancy. The /status handler skips
satellites pending cleanup. Also disable ALSA in Docker build
(unused by the reflector).
2026-03-20 19:08:31 +01:00
Audric 195be03036 docs: remove redundant example in live reload section 2026-03-20 13:55:23 +01:00
Audric 551cfa70cd Implement satellite reflectors
Satellite reflectors are lightweight relay instances that connect to a
parent reflector instead of joining the full trunk mesh. Clients connect
to the satellite normally; it relays all TGs bidirectionally to the
parent. The parent forwards satellite events to local clients, trunk
peers, and other satellites.

New classes:
- SatelliteLink: parent-side handler for each inbound satellite
  connection (HMAC auth, heartbeat, all-TG relay)
- SatelliteClient: satellite-side outbound connection to parent

Wire protocol: MsgTrunkHello gains m_role field (ROLE_PEER=0,
ROLE_SATELLITE=1) to distinguish satellite handshakes.

Config:
- Parent: [SATELLITE] section with LISTEN_PORT and SECRET
- Satellite: SATELLITE_OF, SATELLITE_PORT, SATELLITE_SECRET in [GLOBAL]

HTTP /config endpoint now shows mode (reflector/satellite),
satellite_server config on parents, and satellite connection info.

Docs updated: README, DEPLOYMENT_ITALY, Italian translation.
2026-03-20 13:53:17 +01:00
Audric 166e57f445 Implement cluster TGs and /config HTTP endpoint
Cluster TGs (BrandMeister-style): talk groups broadcast to all trunk
peers regardless of prefix ownership. Configured via CLUSTER_TGS in
[GLOBAL]. Routing checks in TrunkLink now accept isSharedTG || isClusterTG
for all 8 inbound/outbound handlers. Validated at startup to not overlap
with any LOCAL_PREFIX or REMOTE_PREFIX.

New GET /config endpoint returns static configuration (local_prefix,
cluster_tgs, listen_port, http_port, trunk peers) for dashboard use.

Docs: cluster TG sections added to README, DEPLOYMENT_ITALY, and
Italian translation. Design doc for satellite reflectors and cluster
TGs added.
2026-03-20 12:41:26 +01:00
Audric e26b932223 docs: clarify that PTY config changes are in-memory only
Add a "Persisting across reboots" subsection to the live reload
documentation explaining that PTY CFG commands must be paired with
a config file edit to survive restarts.
2026-03-20 11:56:31 +01:00
Audric fca7c33794 Security hardening: fix 19 of 22 vulnerabilities found in audit
Critical:
- Trunk HMAC-SHA1 auth: MsgTrunkHello now carries nonce+digest,
  peer disconnected on secret mismatch (was loaded but never verified)

High:
- Pre-hello guard: reject all trunk messages before handshake completes
- CSPRNG for password generator: random.choice -> secrets.choice

Medium:
- Path traversal protection on callsign-based file operations
- Replace assert() on network-derived UDP data with error handling
- HTTP server connection throttling (matching main TCP server)
- try/catch on regex compilation in callsignOk()/emailOk()
- Per-link trunk talker tracking (clearAllTrunkTalkers scoped to peer)
- Regenerate priority nonce on each new trunk connection
- Cap active TGs and trunk talkers at 10000 each
- Don't reset heartbeat for unauthenticated client app messages
- Fix RENEW_AFTER integer division (2/3 -> 2.0/3.0)

Low:
- JSON-escape HTTP method in error response
- snprintf for pidfile error message
- MsgAuthResponse::digest() null check on empty vector
- Check unpack() return values in AsyncMsg.h vector/map/string
- Replace stack VLA with std::string; reserve+push_back vs resize
- Require TalkerStart before accepting trunk audio
2026-03-20 11:54:18 +01:00