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.
This commit is contained in:
1 parent
b25cbff36a
commit
7507c116e6
2 files changed
+119
-59
No files matched your search
+46
-46
@@ -1,6 +1,6 @@
|
|||||||
# GeuReflector — Twin (HA-Pair) Protocol — DESIGN DRAFT
|
# GeuReflector — Twin (HA-Pair) Protocol
|
||||||
|
|
||||||
> **Status:** Implemented in v1.3.x+twin1. See §Implementation Sketch for
|
> **Status:** Implemented in v1.3.x+twin1. See §Implementation for
|
||||||
> what shipped and `tests/test_twin.py` for integration test coverage
|
> what shipped and `tests/test_twin.py` for integration test coverage
|
||||||
> (8 tests including an end-to-end V2-client audio-mirror path).
|
> (8 tests including an end-to-end V2-client audio-mirror path).
|
||||||
|
|
||||||
@@ -186,7 +186,7 @@ PAIRED=1
|
|||||||
The external peer opens TCP connections to **both** hosts and maintains
|
The external peer opens TCP connections to **both** hosts and maintains
|
||||||
them in parallel. This requires extending `TrunkLink` to manage a list
|
them in parallel. This requires extending `TrunkLink` to manage a list
|
||||||
of TCP endpoints instead of a single outbound + inbound pair (see
|
of TCP endpoints instead of a single outbound + inbound pair (see
|
||||||
§Implementation Sketch).
|
§Implementation).
|
||||||
|
|
||||||
### Sticky per-frame routing
|
### Sticky per-frame routing
|
||||||
|
|
||||||
@@ -313,43 +313,41 @@ port so inbound validation logic stays cleanly separated.
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Implementation Sketch (non-binding)
|
## Implementation
|
||||||
|
|
||||||
- New `TwinLink.cpp` / `TwinLink.h`, structurally similar to
|
Where the pieces live in the source tree:
|
||||||
`TrunkLink` but:
|
|
||||||
- no prefix filtering (`isSharedTG`/`isOwnedTG` replaced by
|
- **`src/svxlink/reflector/TwinLink.cpp` / `.h`** — the twin link itself.
|
||||||
unconditional accept for the paired node),
|
Structurally similar to `TrunkLink` but with no prefix filtering
|
||||||
- 2s TX / 5s RX heartbeat cadence (vs trunk's 10s/15s),
|
(accept everything from the paired node), 2s TX / 5s RX heartbeat,
|
||||||
- `priority` field is used only for the simultaneous-PTT tiebreak
|
and the `priority` nonce used only for the simultaneous-PTT
|
||||||
(no role election),
|
tiebreak. Mirrors all `TGHandler` mutations to the partner,
|
||||||
- mirrors all `TGHandler` mutations to the partner, including
|
including external trunk-talker state via
|
||||||
external trunk-talker state via `MsgTwinExtTalkerStart/Stop`.
|
`MsgTwinExtTalkerStart/Stop`.
|
||||||
- New twin TCP server in `Reflector`, analogous to the trunk server
|
- **`Reflector`** runs a twin TCP server on `TWIN_LISTEN_PORT`
|
||||||
but listening on `TWIN_LISTEN_PORT` (default 5304).
|
(default 5304), analogous to the existing trunk server. Inbound
|
||||||
- `TrunkLink` extension for `PAIRED=1`:
|
hellos are validated (role, HMAC, `local_prefix`) before handoff
|
||||||
- Parse `HOST=h1,h2,...` into a list of endpoints.
|
to `TwinLink::acceptInboundConnection`.
|
||||||
- Open outbound to every endpoint in parallel (reuse
|
- **`TrunkLink`** is extended for `PAIRED=1` on a normal `[TRUNK_x]`
|
||||||
`TcpPrioClient` per endpoint or similar).
|
section: `HOST=h1,h2,...` parses into a list of endpoints; one
|
||||||
- Relax the "one inbound per section" rule to `len(HOSTS)` inbounds.
|
`TcpPrioClient` is opened per endpoint; the "one inbound per
|
||||||
- Sticky selection state: track the "current sticky send socket"
|
section" rule is relaxed to `len(HOSTS)` inbounds; sending uses
|
||||||
and an ordered list of alternates; switch on TCP-level failure of
|
sticky selection (one socket per transmission, instant failover
|
||||||
the current socket.
|
to the next live one on TCP-level failure).
|
||||||
- `TGHandler` gets a new `setTrunkTalkerForTGViaPeer(tg, callsign,
|
- **`TGHandler`** gains `setTrunkTalkerForTGViaPeer(tg, callsign,
|
||||||
peer_id)` entry point so the twin link can attribute external state
|
peer_id)`, `clearTrunkTalkersForPeer(peer_id)` and
|
||||||
to a specific external peer on mirror (required so disconnect
|
`peerIdForTG(tg)` so external trunk-talker state mirrored across
|
||||||
cleanup of one external peer doesn't clear state owned by another).
|
the twin link can be cleaned up per-peer on disconnect without
|
||||||
- `MsgTwinExtTalkerStart` / `MsgTwinExtTalkerStop` added to
|
clobbering other peers' claims.
|
||||||
`ReflectorMsg.h` (types 123, 124).
|
- **`ReflectorMsg.h`** adds types 123 / 124 (`MsgTwinExtTalkerStart`
|
||||||
- Config template (`svxreflector.conf.in`) gets commented-out `[TWIN]`
|
/ `Stop`) and a new `ROLE_TWIN = 2` value on `MsgTrunkHello`.
|
||||||
and `PAIRED=1` examples.
|
- **`svxreflector.conf.in`** includes commented-out `[TWIN]` and
|
||||||
- Integration test: 4-node topology in `tests/topology.py` —
|
`PAIRED=1` examples.
|
||||||
refA (IT, prefix 222), ref1+ref2 (DE twin pair, prefix 262), and
|
- **`tests/test_twin.py`** covers handshake, PAIRED trunk wiring,
|
||||||
one more external reflector — exercising:
|
no-auth-error startup, kill/restart recovery, PAIRED failover, and
|
||||||
- normal 2-way audio through one sticky socket,
|
an end-to-end audio-mirror test that uses two V2 clients (one
|
||||||
- socket failover mid-transmission,
|
talking on ref1, one listening on ref2) to exercise the full
|
||||||
- twin-link outage with independent continued operation,
|
UDP→TGHandler→TwinLink→UDP path.
|
||||||
- external-talker state propagation blocking local-client PTT on
|
|
||||||
the partner twin.
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -379,10 +377,13 @@ Artifacts that can occur while the twin link is down:
|
|||||||
refA's sticky choice and the `handleMsgTrunkAudio` talker check.
|
refA's sticky choice and the `handleMsgTrunkAudio` talker check.
|
||||||
|
|
||||||
These artifacts are bounded to the duration of the twin-link outage
|
These artifacts are bounded to the duration of the twin-link outage
|
||||||
and heal automatically on reconnection: the re-established twin link
|
and heal automatically on reconnection: once the twin link is back,
|
||||||
resynchronizes `TGHandler` state via a full state dump on handshake
|
subsequent talker-starts, audio frames and external-trunk events
|
||||||
(handshake-time state reconciliation is a small protocol addition
|
propagate over it as normal, so state converges as soon as there is
|
||||||
for the implementation — see §Implementation Sketch).
|
new activity on each affected TG. There is no bulk state-dump on
|
||||||
|
reconnect — in-progress transmissions at the moment of disconnect
|
||||||
|
may be truncated on the receiving twin, but nothing is left in a
|
||||||
|
permanently inconsistent state.
|
||||||
|
|
||||||
We explicitly accept this behavior rather than adding a quorum witness
|
We explicitly accept this behavior rather than adding a quorum witness
|
||||||
or a degraded-mode lockdown: the twin link is expected to be LAN-close
|
or a degraded-mode lockdown: the twin link is expected to be LAN-close
|
||||||
@@ -391,10 +392,9 @@ losing service during the outage.
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Resolved Decisions
|
## Design Rationale
|
||||||
|
|
||||||
All open design questions from the original draft were resolved on
|
Summary of the key design choices and why they were made:
|
||||||
2026-04-15. Summary for reference:
|
|
||||||
|
|
||||||
| Topic | Decision | Rationale |
|
| Topic | Decision | Rationale |
|
||||||
|-------|----------|-----------|
|
|-------|----------|-----------|
|
||||||
|
|||||||
+73
-13
@@ -2,7 +2,11 @@
|
|||||||
|
|
||||||
## Overview
|
## Overview
|
||||||
|
|
||||||
The integration tests verify the trunk protocol, satellite links, and end-to-end audio routing by spinning up a 3-reflector Docker Compose mesh and connecting fake peers and clients from a Python test harness.
|
The integration tests verify the trunk protocol, satellite links, twin (HA-pair) protocol, and end-to-end audio routing by spinning up reflector meshes in Docker Compose and connecting fake peers and clients from a Python test harness.
|
||||||
|
|
||||||
|
The suite runs in **two phases**:
|
||||||
|
1. A 3-reflector trunk mesh exercising `test_trunk.py` (27 tests).
|
||||||
|
2. A 4-reflector twin topology exercising `test_twin.py` (8 tests).
|
||||||
|
|
||||||
**Requirements:** Docker, Docker Compose, Python 3.7+ (stdlib only, no pip packages).
|
**Requirements:** Docker, Docker Compose, Python 3.7+ (stdlib only, no pip packages).
|
||||||
|
|
||||||
@@ -14,16 +18,20 @@ bash run_tests.sh
|
|||||||
```
|
```
|
||||||
|
|
||||||
This will:
|
This will:
|
||||||
1. Generate configs and `docker-compose.test.yml` from `topology.py`
|
1. Generate the default configs and `docker-compose.test.yml` from `topology.py`
|
||||||
2. Build and start the 3-reflector mesh
|
2. Build and start the 3-reflector mesh
|
||||||
3. Run 27 automated tests
|
3. Run 27 automated trunk/satellite/MQTT tests (`test_trunk.py`)
|
||||||
4. Enter an interactive prompt to manually test any TG number
|
4. Enter an interactive prompt to manually test any TG number
|
||||||
5. Tear down the mesh on exit (or Ctrl-C)
|
5. Tear down the default mesh
|
||||||
|
6. Regenerate with `--topology twin` (4-reflector twin topology)
|
||||||
|
7. Rebuild the mesh and run 8 automated twin-protocol tests (`test_twin.py`)
|
||||||
|
8. Restore the default topology files and tear everything down
|
||||||
|
|
||||||
To regenerate configs without running tests:
|
To regenerate configs without running tests:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
python3 generate_configs.py
|
python3 generate_configs.py # default 3-reflector mesh
|
||||||
|
python3 generate_configs.py --topology twin # 4-reflector twin topology
|
||||||
```
|
```
|
||||||
|
|
||||||
## Test Mesh Topology
|
## Test Mesh Topology
|
||||||
@@ -62,14 +70,46 @@ All test configs have `TRUNK_DEBUG=1` enabled for verbose trunk logging during t
|
|||||||
|
|
||||||
Internal ports inside Docker are always 5300, 5302, 8080, 5303.
|
Internal ports inside Docker are always 5300, 5302, 8080, 5303.
|
||||||
|
|
||||||
|
## Twin Test Topology
|
||||||
|
|
||||||
|
The twin topology (`--topology twin`) exercises the TWIN HA-pair protocol and `PAIRED=1` external trunks. See `docs/TWIN_PROTOCOL.md` for the protocol specification.
|
||||||
|
|
||||||
|
```
|
||||||
|
refa (prefix 222)
|
||||||
|
│
|
||||||
|
│ [TRUNK_IT_DE] PAIRED=1 (one section, both hosts)
|
||||||
|
│ ┌───────────────┐
|
||||||
|
▼ ▼
|
||||||
|
ref1 ◄── [TWIN] ──► ref2 (both LOCAL_PREFIX=262)
|
||||||
|
│ │
|
||||||
|
└─── refc ───────────┘
|
||||||
|
(prefix 333)
|
||||||
|
```
|
||||||
|
|
||||||
|
- **refa** (IT, `LOCAL_PREFIX=222`) — the non-pair side; its single `[TRUNK_IT_DE]` lists both German hosts and uses sticky per-transmission selection with instant failover.
|
||||||
|
- **ref1, ref2** (DE, `LOCAL_PREFIX=262` on **both**) — the twin pair, linked by a `[TWIN]` section on port 5304 and sharing `TGHandler` state.
|
||||||
|
- **refc** (`LOCAL_PREFIX=333`) — extra peer so the twin pair also has a normal (non-paired) trunk.
|
||||||
|
|
||||||
|
### Twin Port Mapping
|
||||||
|
|
||||||
|
| Reflector | Client (TCP+UDP) | Trunk (TCP) | Twin (TCP) | HTTP |
|
||||||
|
|-----------|-------------------|-------------|------------|-------|
|
||||||
|
| refa | 45300 | 45302 | — | 48080 |
|
||||||
|
| ref1 | 46300 | 46302 | 46304 | 49080 |
|
||||||
|
| ref2 | 47300 | 47302 | 47304 | 50080 |
|
||||||
|
| refc | 48300 | 48302 | — | 51080 |
|
||||||
|
|
||||||
|
Internal port for `[TWIN]` is always 5304.
|
||||||
|
|
||||||
## File Structure
|
## File Structure
|
||||||
|
|
||||||
| File | Purpose |
|
| File | Purpose |
|
||||||
|------|---------|
|
|------|---------|
|
||||||
| `topology.py` | Single source of truth — prefixes, ports, secrets, cluster TGs, test clients |
|
| `topology.py` | Single source of truth — prefixes, ports, secrets, cluster TGs, test clients. Contains both the default mesh (`REFLECTORS`) and the `TWIN_REFLECTORS` / `TWIN_TRUNKS` definitions. |
|
||||||
| `generate_configs.py` | Generates `configs/*.conf` and `docker-compose.test.yml` from topology |
|
| `generate_configs.py` | Generates `configs/*.conf` and `docker-compose.test.yml` from topology. Supports `--topology default` (implicit) and `--topology twin`. |
|
||||||
| `test_trunk.py` | Test harness: fake peers, fake clients, 17 test cases, interactive loop |
|
| `test_trunk.py` | Test harness: fake trunk peers, satellite peer, V2 client, 27 test cases, interactive loop. |
|
||||||
| `run_tests.sh` | Orchestrator: generate → build → test → teardown |
|
| `test_twin.py` | TWIN-protocol tests (8 cases) using the twin topology. Reuses `ClientPeer` from `test_trunk.py` for the audio-mirror test. |
|
||||||
|
| `run_tests.sh` | Orchestrator: generate → build → trunk tests → teardown → regenerate twin → build → twin tests → teardown. |
|
||||||
| `configs/` | Generated reflector config files (do not edit manually) |
|
| `configs/` | Generated reflector config files (do not edit manually) |
|
||||||
| `docker-compose.test.yml` | Generated compose file (do not edit manually) |
|
| `docker-compose.test.yml` | Generated compose file (do not edit manually) |
|
||||||
|
|
||||||
@@ -156,6 +196,21 @@ each filter independently of the other trunk fixtures.
|
|||||||
|---|------|-----------------|
|
|---|------|-----------------|
|
||||||
| 27 | `MsgTrunkNodeList` emission | Connecting a V2 client triggers a debounced node-list send to trunk peers; the harness receives a `MsgTrunkNodeList` (type 121) containing the new client |
|
| 27 | `MsgTrunkNodeList` emission | Connecting a V2 client triggers a debounced node-list send to trunk peers; the harness receives a `MsgTrunkNodeList` (type 121) containing the new client |
|
||||||
|
|
||||||
|
### Twin Protocol (HA-pair)
|
||||||
|
|
||||||
|
Run separately on the twin topology (`test_twin.py`). See `docs/TWIN_PROTOCOL.md` for the protocol.
|
||||||
|
|
||||||
|
| # | Test | What it verifies |
|
||||||
|
|---|------|-----------------|
|
||||||
|
| 1 | TWIN handshake | Both ref1 and ref2 log a successful `TWIN: hello from partner` with authentication |
|
||||||
|
| 2 | No auth errors | Neither twin emits HMAC or `local_prefix` mismatch errors on startup |
|
||||||
|
| 3 | PAIRED trunk on refa | refa's single `[TRUNK_IT_DE]` (PAIRED=1) reports `connected=True` with both hosts reachable |
|
||||||
|
| 4 | PAIRED return leg | ref1 and ref2 each see their own `[TRUNK_IT_DE]` back to refa as connected |
|
||||||
|
| 5 | No twin-setup errors | Startup logs on both twins contain no `ERROR[TWIN]` lines |
|
||||||
|
| 6 | Twin disconnect recovery | Killing ref2 triggers an RX timeout on ref1; restarting ref2 re-handshakes cleanly |
|
||||||
|
| 7 | PAIRED trunk failover | Killing ref1 does **not** disconnect refa's `[TRUNK_IT_DE]` — sticky selection fails over to ref2 without holdoff |
|
||||||
|
| 8 | Audio mirror end-to-end | A V2 client on ref1 transmits on TG 26201; a V2 client on ref2 receives UDP audio and a flush marker, exercising the full `TGHandler.talkerUpdated` → `TwinLink.onLocalAudio` → `MsgTrunkAudio` → `broadcastUdpMsg` path |
|
||||||
|
|
||||||
## Interactive Mode
|
## Interactive Mode
|
||||||
|
|
||||||
After the automated tests pass, an interactive prompt lets you test any TG number:
|
After the automated tests pass, an interactive prompt lets you test any TG number:
|
||||||
@@ -173,10 +228,15 @@ The interactive mode connects a V2 client to reflector-a, sends audio on the giv
|
|||||||
|
|
||||||
## Modifying the Topology
|
## Modifying the Topology
|
||||||
|
|
||||||
All topology is defined in `topology.py`. To add a reflector or change prefixes:
|
All topology is defined in `topology.py`. The file contains two topologies:
|
||||||
|
|
||||||
1. Edit `REFLECTORS`, `CLUSTER_TGS`, or other constants in `topology.py`
|
- **Default** (`REFLECTORS`, `CLUSTER_TGS`, `TEST_PEER`, etc.) — the 3-reflector mesh used by `test_trunk.py`.
|
||||||
2. Run `python3 generate_configs.py` to regenerate configs and compose file
|
- **Twin** (`TWIN_REFLECTORS`, `TWIN_TRUNKS`, `TWIN_CLUSTER_TGS`) — the 4-reflector twin topology used by `test_twin.py`, including `twin_of` and `paired` fields.
|
||||||
3. Run `bash run_tests.sh` to rebuild and test
|
|
||||||
|
To add a reflector or change prefixes:
|
||||||
|
|
||||||
|
1. Edit the relevant constants in `topology.py`
|
||||||
|
2. Run `python3 generate_configs.py` (default) or `python3 generate_configs.py --topology twin`
|
||||||
|
3. Run `bash run_tests.sh` to rebuild and test both suites
|
||||||
|
|
||||||
Do not edit files in `configs/` or `docker-compose.test.yml` directly — they are overwritten by the generator.
|
Do not edit files in `configs/` or `docker-compose.test.yml` directly — they are overwritten by the generator.
|
||||||
Reference in new issue
Block a user