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.
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.
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).
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.
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.
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.
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.
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.
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.
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.
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
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.
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).
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.
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.