feat(reflector): gateway prefix routing via shouldRelayInbound
A non-owner reflector with two trunk legs (a country gateway sitting
between an international mesh and a national mesh) now forwards inbound
trunk traffic toward the actual prefix owner — automatically, via
longest-prefix-match in its own [TRUNK_x] table. Cluster TGs keep their
deliberate single-hop semantic to prevent loops in cyclic meshes.
Implementation
- Reflector::shouldRelayInbound(tg) composes the inbound relay decision:
* isLocalTG -> fan out (existing owner-relay)
* isClusterTG -> stop (anti-loop; cluster TGs broadcast outbound
from local clients only)
* hasPrefixRoute -> gateway forwarding via per-trunk isSharedTG
- The four isLocalTG gates in TrunkLink::handleMsgPeer{TalkerStart,
TalkerStop,Audio,Flush} are replaced by shouldRelayInbound. Source
exclusion in forwardTrunk*ToOtherTrunks plus per-link interest
tracking keep the topology naturally loop-free.
Tests
- topology.py: per-reflector `peers` filter for sparse layouts; new
reflector `d` (prefix 1219, trunked only to `b`) demonstrating
gateway-only reachability from `a` to `d`.
- generate_configs.py: honours the peers filter.
- test_trunk.py:
* setUpClass and test_01 skip non-existent pairs in sparse layouts.
* test_37_gateway_prefix_routing: a-client (122) <-> d-client (1219)
over TG 121950 in both directions, no CLUSTER_TGS.
* test_38_cluster_tg_local_client_broadcast: explicit coverage for
the outbound local-client cluster broadcast path.
- All previously passing tests still pass: 41/41 trunk + 7/7
mqtt-deltas + 14/14 twin.
Docs
- docs/TOPOLOGY_EXAMPLES.md (new) + .pdf + topology_pdf/ build sources +
build_topology_pdf.sh: visual cookbook of the five topology shapes
(international full-mesh, national mesh joined at gateway, satellite
tree, hybrid satellite-under-regional, HA twin pair). Includes an
MCC-range appendix with the recommendation to draw cluster TGs from
100-199 / 800-999 to avoid country-prefix collisions.
- docs/PEER_PROTOCOL.md: rewrote the "Owner-Relay Fanout" section as
"Inbound Relay (shouldRelayInbound)" with the three-regime
composition and clarified the single-mesh fanout caveat.
- README.md: feature bullet now describes gateway prefix routing and
links to TOPOLOGY_EXAMPLES.md (also added to the documentation list).
This commit is contained in:
1 parent
658a1b153f
commit
52b5e4f3cf
22 files changed
+2191
-38
No files matched your search
@@ -14,6 +14,11 @@ REFLECTORS = {
|
||||
"a": {"prefix": ["122"], "trunk_port_base": 15000},
|
||||
"b": {"prefix": ["121"], "trunk_port_base": 25000},
|
||||
"c": {"prefix": ["1"], "trunk_port_base": 35000},
|
||||
# `d` is sparse-trunked: only connects to `b`. With prefix `1219`
|
||||
# (sub-prefix of b's `121`), it lets test_37 verify gateway forwarding
|
||||
# — a's audio for TG `121950` must reach d via the b gateway, even
|
||||
# though a has no direct trunk to d.
|
||||
"d": {"prefix": ["1219"], "trunk_port_base": 45000, "peers": ["b"]},
|
||||
}
|
||||
|
||||
# Fake trunk peers used by the test harness.
|
||||
@@ -102,6 +107,22 @@ def trunk_secret(name_a: str, name_b: str) -> str:
|
||||
pair = tuple(sorted([name_a, name_b]))
|
||||
return f"secret_{pair[0]}{pair[1]}"
|
||||
|
||||
def _allowed_peers(name: str) -> set:
|
||||
"""Other reflector names that `name` is willing to trunk to.
|
||||
|
||||
Default is full mesh (all other reflectors). A reflector can opt into
|
||||
a sparse layout by setting `peers: ["x", "y"]` in REFLECTORS — useful
|
||||
for testing gateway-style prefix routing.
|
||||
"""
|
||||
me = REFLECTORS[name]
|
||||
if "peers" in me:
|
||||
return set(me["peers"])
|
||||
return {n for n in REFLECTORS if n != name}
|
||||
|
||||
def should_trunk(a: str, b: str) -> bool:
|
||||
"""A trunk between a and b exists iff both sides allow it."""
|
||||
return b in _allowed_peers(a) and a in _allowed_peers(b)
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Helpers for prefix handling
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
Reference in new issue
Block a user