diff --git a/README.md b/README.md index 47d5342..367d239 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,20 @@ Trunk extension by IW1GEU. --- +## Contents + +- [New to SvxLink reflectors? Start here](#new-to-svxlink-reflectors-start-here) +- [Quick start — one standalone reflector](#quick-start--one-standalone-reflector) +- [Which setup fits my deployment?](#which-setup-fits-my-deployment) +- [Why trunking?](#why-trunking) +- [What it adds over SvxReflector](#what-it-adds-over-svxreflector) +- [How TG ownership works](#how-tg-ownership-works) +- [Build](#build) · [Testing](#testing) · [Configuration](#configuration) +- [HTTP Status](#http-status) · [Live user/password reload](#live-userpassword-reload) +- [Documentation](#documentation) · [License](#license) + +--- + ## New to SvxLink reflectors? Start here If you already run SvxReflector, skip to [What it adds](#what-it-adds-over-svxreflector). @@ -86,6 +100,22 @@ connect it to others. --- +## Which setup fits my deployment? + +| Your situation | Setup | Where to look | +|----------------|-------|---------------| +| One reflector for a club or single site | Standalone (no trunks) | [Quick start](#quick-start--one-standalone-reflector) above | +| Several regions in one country | Full trunk mesh | [Full-mesh example](#full-mesh-example--three-reflectors), [`docs/DEPLOYMENT_ITALY.md`](docs/DEPLOYMENT_ITALY.md) | +| Many countries / a backbone | Full mesh + gateways + routable prefixes | [`docs/WW_DEPLOYMENT.md`](docs/WW_DEPLOYMENT.md), [Routable prefixes](#5-routable-prefixes--hierarchical-and-non-full-mesh-topologies-optional) | +| Members behind NAT / no static IP | Satellites under a parent | [Satellite reflectors](#satellite-reflectors) | +| Failover for a single reflector | Twin (HA) pair | [`docs/TWIN_PROTOCOL.md`](docs/TWIN_PROTOCOL.md) | + +For diagrams of each shape and a fuller decision guide, see +[`docs/TOPOLOGY_EXAMPLES.md`](docs/TOPOLOGY_EXAMPLES.md). For *why* these pieces +work the way they do, read [`docs/CONCEPTS.md`](docs/CONCEPTS.md). + +--- + ## Why trunking? A standard SvxReflector is a single centralized server. Without trunking, a @@ -716,6 +746,9 @@ The PTY path is set by `COMMAND_PTY` in `[GLOBAL]` (default ## Documentation +- [`docs/CONCEPTS.md`](docs/CONCEPTS.md) — **start here after the glossary**: how + TG ownership, owner-relay, peer interest, cluster TGs, and talker arbitration + fit together, with a worked three-way-QSO example - [`docs/INSTALL.md`](docs/INSTALL.md) — how to build and install GeuReflector as a drop-in replacement for an existing SvxReflector installation - [`docs/DOCKER.md`](docs/DOCKER.md) — running GeuReflector in a Docker container @@ -747,6 +780,9 @@ The PTY path is set by `COMMAND_PTY` in `[GLOBAL]` (default - [`docs/LOGGING.md`](docs/LOGGING.md) — leveled, per-subsystem, live-reloadable logger: `LOG=` config, PTY commands, Docker vs. `--logfile` deployments, migration from `TRUNK_DEBUG` +- [`docs/TROUBLESHOOTING.md`](docs/TROUBLESHOOTING.md) — symptom-first checklists + for trunks that won't connect, audio that won't cross, satellite/twin issues, + and flapping links - [`docs/MESSAGING_IDEAS.md`](docs/MESSAGING_IDEAS.md) — ideas for consuming MQTT events via Telegram, SMS, Discord, webhooks, dashboards, and more - [`docs/DESIGN_SATELLITE_AND_CLUSTER.md`](docs/DESIGN_SATELLITE_AND_CLUSTER.md) — design diff --git a/docs/CONCEPTS.md b/docs/CONCEPTS.md new file mode 100644 index 0000000..5017510 --- /dev/null +++ b/docs/CONCEPTS.md @@ -0,0 +1,171 @@ +# Concepts + +This page explains *how GeuReflector thinks* — the handful of ideas that make +the rest of the documentation click. It sits between the +[README glossary](../README.md#glossary) (one-line definitions) and +[`PEER_PROTOCOL.md`](PEER_PROTOCOL.md) (the byte-level wire spec). Read it once +and the deployment guides will make sense. + +No prior trunk knowledge is assumed, but you should know what a reflector and a +talk group are — see the [README intro](../README.md#new-to-svxlink-reflectors-start-here) +if not. + +--- + +## 1. The mental model: talk groups are phone numbers + +A talk group is identified by a number, and GeuReflector routes it the way a +phone network routes a call: **by its leading digits**. + +Each reflector is configured with one or more `LOCAL_PREFIX` values. A reflector +*owns* every talk group whose number starts with one of its prefixes: + +``` +LOCAL_PREFIX=222 → owns 222, 2220, 2225, 22299, 222100, … +LOCAL_PREFIX=262 → owns 262, 2620, 26200, … +``` + +The owner is the single authoritative home for those TGs across the whole mesh. +Everyone else reaches them *through* the owner. + +### Longest prefix wins + +Prefixes may overlap on purpose. If both `222` and `222100` exist in the mesh, +TG `222100` belongs to whoever owns `222100` — the **longest matching prefix +wins**. This is what lets a national reflector own `222` while delegating a +specific sub-range like `222100` to a regional or club reflector. (See +[routable prefixes](../README.md#5-routable-prefixes--hierarchical-and-non-full-mesh-topologies-optional) +for declaring such delegated routes.) + +--- + +## 2. What happens when a client keys up + +A client (an SvxLink node) selects a TG and presses PTT. Two cases: + +- **The TG is owned locally.** The reflector behaves exactly like stock + SvxReflector: it relays the audio to every other local client on that TG. If + any *remote* reflector has shown interest in the TG, it is also sent over the + trunk(s) to them. +- **The TG is owned by a peer.** The reflector forwards the audio over the trunk + to the owning peer (selected by longest-prefix-match). The owner then relays + it — see below. + +The client never knows or cares which reflector owns the TG. That is the whole +point: nodes stay unmodified. + +--- + +## 3. Owner-relay: why the owner is the hub + +In a full mesh every reflector has a direct trunk to every other. You might +expect the speaker's reflector to blast audio to all peers directly — but that +would duplicate audio and risk loops. Instead: + +> **Only the TG's owner fans audio out to the rest of the mesh.** + +A non-owner sends to the owner; the owner relays to every *other* peer that has +expressed interest (never back to the source). This "owner-relay" rule keeps a +single, predictable distribution point per TG and is what makes three-way and +larger conversations work without echo. It is a deliberate single-hop fanout — +the owner does not expect peers to re-relay among themselves. + +--- + +## 4. Peer interest: how the owner knows who to send to + +The owner only forwards a TG to peers that actually care about it. A peer +becomes "interested" in a TG in two ways: + +- **It advertises interest** when one of its local clients selects or monitors + that TG (via a `MsgPeerTgInterest` message). This works even before anyone + speaks, so a listener hears the *first* transmission. +- **It speaks on the TG**, which implicitly marks interest. + +Interest is **per-link** and **expires after 10 minutes of inactivity** on that +TG from that peer (or immediately when the trunk disconnects). This timeout is +why a TG that has been silent for a long time may take one transmission to +"warm up" again on a listener that never advertised explicit interest. + +--- + +## 5. Cluster TGs: the nationwide broadcast exception + +Some TGs should reach everyone regardless of prefix ownership — think +BrandMeister's nationwide talk groups. Those are **cluster TGs**, listed in +`CLUSTER_TGS`: + +- A reflector both **sends** and **accepts** a cluster TG only if that TG is in + its own `CLUSTER_TGS`. Two reflectors exchange a cluster TG only if *both* + list it. +- Cluster TGs are broadcast from a local client out to every trunk peer. +- On the receive side they are deliberately **single-hop**: a cluster TG arriving + over a trunk is played locally but *not* re-forwarded to other trunks. In a + mesh with cycles, re-forwarding would loop — so the only way a cluster TG + crosses the mesh is the originator's own fanout to each peer. + +Cluster TG numbers must not overlap any `LOCAL_PREFIX` or `REMOTE_PREFIX`. + +--- + +## 6. Talker arbitration: who wins a collision + +What if two reflectors' clients key the same TG at the same instant? Each +reflector arbitrates its own local clients normally (first talker wins locally). +Across the trunk, ties are broken by a **random 32-bit priority nonce** that the +two reflectors exchange during their handshake (`MsgPeerHello`): + +> **The lower nonce wins.** The loser defers, treats itself as receiving from +> the remote talker, and blocks its own local clients from interrupting until the +> winner stops. + +This guarantees both sides converge on the same winner without a central +coordinator. + +--- + +## 7. Beyond the full mesh (pointers) + +The four ideas above cover a standard full mesh. Three extensions handle shapes a +flat mesh can't: + +- **Gateway prefix routing / routable prefixes** — a reflector with two trunk + legs (e.g. a country gateway between an international and a national mesh) can + transit traffic toward an owner it doesn't itself own, by declaring + `ROUTABLE_PREFIXES`. See the + [README routable-prefixes section](../README.md#5-routable-prefixes--hierarchical-and-non-full-mesh-topologies-optional). +- **Satellites** — a lightweight reflector that connects *out* to a parent + instead of joining the mesh (NAT-friendly); by default it mirrors all TGs in + both directions. See [`DESIGN_SATELLITE_AND_CLUSTER.md`](DESIGN_SATELLITE_AND_CLUSTER.md). +- **Twins** — two reflectors sharing one prefix as a high-availability pair, + appearing as a single peer to the rest of the mesh. See + [`TWIN_PROTOCOL.md`](TWIN_PROTOCOL.md). + +--- + +## 8. A worked example: a three-way QSO + +Three reflectors, full mesh. **A** owns prefix `1`, **B** owns `2`, **C** owns `3`. +A listener on each is monitoring TG `25` (owned by **B**). + +1. A client on **A** keys TG `25`. `25` is not A's; longest-prefix-match says + **B** owns it. A sends the audio over the A–B trunk. +2. **B** is the owner. It plays `25` to its own local clients, and fans the audio + out to every *other* interested peer — here, **C** (which advertised interest + because its listener is monitoring `25`). B does **not** send back to A. +3. **C** receives `25` over the B–C trunk and plays it to its local listener. +4. Everyone on `25` — across all three reflectors — hears the transmission, with + B as the single relay point. When the talker stops, the next person to key + `25` (on any reflector) goes through the same path; trunk-level arbitration + settles any simultaneous starts. + +--- + +## Where to go next + +- [`PEER_PROTOCOL.md`](PEER_PROTOCOL.md) — the exact messages, handshake, and + field layouts behind everything above. +- [`TOPOLOGY_EXAMPLES.md`](TOPOLOGY_EXAMPLES.md) — visual cookbook of the + supported mesh shapes, with a "which topology do I want?" guide. +- [`TROUBLESHOOTING.md`](TROUBLESHOOTING.md) — when a trunk won't connect or + audio won't cross. diff --git a/docs/TROUBLESHOOTING.md b/docs/TROUBLESHOOTING.md new file mode 100644 index 0000000..1e3740e --- /dev/null +++ b/docs/TROUBLESHOOTING.md @@ -0,0 +1,137 @@ +# Troubleshooting + +Common failure modes when bringing up trunks, satellites, and twins, with what +to check first. If a concept here is unfamiliar, read [`CONCEPTS.md`](CONCEPTS.md). + +**Two tools answer most questions:** + +- **`GET /status`** (enable with `HTTP_SRV_PORT=8080`) — shows each trunk's + `connected` state, active talkers, satellites, and the rosters received from + peers. This is the fastest way to see what the reflector *thinks* is happening. +- **Logs** — for connection and routing detail. Use the leveled logger + (see [`LOGGING.md`](LOGGING.md)); `TRUNK_DEBUG=1` exposes per-section HMAC and + prefix-match decisions but is extremely verbose — **enable it only while + diagnosing, then turn it off** (it logs every audio frame). + +--- + +## A trunk won't connect + +`/status` shows the trunk with `"connected": false`, or the log never reports a +hello exchange. Check, in order: + +1. **Section names must be identical on both ends.** The `[TRUNK_x]` section + name is part of the handshake. If reflector A uses `[TRUNK_AB]` and B uses + `[TRUNK_BA]`, B rejects the connection. Both sysops must agree on one name. +2. **The `SECRET` must match** on both sides exactly. A mismatch fails the HMAC + check; with `TRUNK_DEBUG=1` you will see the section matched on name but + failed on secret. +3. **Port 5302/TCP must be reachable inbound** on *both* reflectors. Trunks are + mutually dialed: each side connects outbound *and* listens inbound. A firewall + or NAT blocking 5302 on either end prevents at least one direction. (If only + one direction is blocked the link may still show connected via the other leg — + but fix both.) +4. **Each reflector needs a stable address.** Use a static IP or stable DNS name + in `HOST=`. A peer behind a changing dynamic IP cannot be reliably dialed — + that is what [satellites](#a-satellite-cant-connect) are for. +5. **`REMOTE_PREFIX` should match the peer's `LOCAL_PREFIX`.** A wrong prefix + does not stop the *connection*, but it breaks *routing* (next section). + +> Note: trunks connect *peer to peer*, independent of any client login. You do +> not need `[USERS]`/`[PASSWORDS]` entries for a trunk — those are for nodes. + +--- + +## The trunk is connected but audio doesn't cross + +The link shows `connected: true`, but a client on one reflector can't hear a +client on another. + +1. **Is the TG owned by the right reflector?** Audio for TG `25` only flows if + some reflector's `LOCAL_PREFIX` matches `25` (here, prefix `2`). If nobody + owns the prefix, there is no home to route to. Confirm with the owner's + `local_prefix` in `/status`. +2. **For a nationwide TG, is it a cluster TG on *both* sides?** A cluster TG is + exchanged only between reflectors that *both* list it in `CLUSTER_TGS`. If A + lists `222` and B does not, B silently ignores it — by design. +3. **Give it one transmission to warm up.** A listener that never *selected* the + TG relies on the owner having current "interest" for its link. Interest + expires after 10 minutes of silence on that TG, so the first key-up after a + long idle may be what re-establishes the path. A client that actually selects + or monitors the TG advertises interest immediately and should not need this. +4. **Check per-trunk filters.** `BLACKLIST_TGS` is evaluated first and drops the + TG outright; `ALLOW_TGS`, if set, drops everything not listed. `TG_MAP` may be + rewriting the number. These are per-`[TRUNK_x]` and reloadable via the PTY + (`TRUNK RELOAD
`); inspect them with `TRUNK STATUS
`. +5. **Is a callsign muted?** `TRUNK MUTE
` suppresses that + callsign's audio on the inbound path. Check `muted` in `/status` and + `TRUNK UNMUTE` if needed. + +--- + +## Audio crosses in only one direction + +Usually an asymmetry between the two ends: + +- **Filters differ.** A `BLACKLIST_TGS`/`ALLOW_TGS`/`TG_MAP` set on one side but + not the other makes audio pass one way and not the other. Compare both + sections. +- **Interest is one-sided.** If only one side has a client selecting the TG, only + that side has advertised interest. The other direction starts flowing once a + client there selects/keys the TG. +- **Multi-hop transit:** each intermediate hop must declare the same + `ROUTABLE_PREFIXES` for the forward path; the return path relies on interest + (and, for a single-uplink leaf, the `*` wildcard). Re-check every hop in the + chain — there is no automatic propagation. + +--- + +## A satellite can't connect + +1. **Parent `[SATELLITE]` section present** with `LISTEN_PORT=5303` and a + `SECRET=` (or a per-id `SECRET_=` matching the satellite's + `SATELLITE_ID`). A per-id mismatch rejects with **no fallback**. +2. **Satellite side** sets `SATELLITE_OF`, `SATELLITE_PORT`, `SATELLITE_SECRET`, + and `SATELLITE_ID` in `[GLOBAL]` — and does **not** set `LOCAL_PREFIX`, + `REMOTE_PREFIX`, `CLUSTER_TGS`, or any `[TRUNK_x]` section. +3. **Only the parent needs an open inbound port** (5303). The satellite dials + out, so it can sit behind NAT. +4. **Seeing fewer TGs than expected?** A `SATELLITE_FILTER` on the satellite + narrows scope in *both* directions. Empty/absent = all TGs. The active filter + appears under `/status.satellites[].filter`. + +--- + +## Twin pair: duplicates or self-echo + +If an external reflector trunking to a twin pair hears doubled audio or its own +transmissions back: + +- The external peer **must use a single `[TRUNK_x]` section with `PAIRED=1`**, + not two separate sections (one per twin). Two sections defeat the sticky + per-transmission socket selection and cause duplication and self-echo. See + [`TWIN_PROTOCOL.md`](TWIN_PROTOCOL.md) ("External peer view"). + +--- + +## A trunk keeps dropping / reconnecting + +The link flaps; logs show repeated RX timeouts. + +- Heartbeats run every ~10 s with a ~15 s receive timeout. A link that drops + about every 15 s of quiet usually means heartbeats aren't arriving — check for + packet loss, a stateful firewall/NAT idle-timeout killing the TCP session, or + one side pausing (an overloaded or swapping host). +- Confirm both directions: `/status` exposes the outbound and inbound legs + separately for twins; for trunks, a flapping link that still shows `connected` + is usually surviving on one leg while the other fails — fix the failing + direction's reachability. + +--- + +## Still stuck? + +Capture `/status` from both ends and a short log slice with the relevant +subsystem at debug level (see [`LOGGING.md`](LOGGING.md)). The combination of +"what each side thinks the link state is" plus "which sections matched on +name/secret/prefix" pinpoints the vast majority of trunk problems.