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:
Audric committed 2026-05-07 16:12:14 +02:00
1 parent 658a1b153f
commit 52b5e4f3cf
22 files changed
+2191 -38

No files matched your search

+16 -12
View File
@@ -1027,10 +1027,13 @@ void TrunkLink::handleMsgPeerTalkerStart(std::istream& is)
peerId());
m_reflector->notifyExternalTrunkTalkerStart(local_tg, m_section, msg.callsign());
// Owner-relay: if we own this TG, propagate the talker-start to every
// other interested trunk peer so their local clients and our mesh-wide
// audience learn about the remote talker.
if (m_reflector->isLocalTG(local_tg))
// Prefix-routed fanout: forward to every other trunk peer if we have a
// route for this TG in our prefix table. isSharedTG inside the per-trunk
// filter (TrunkLink::onLocalTalkerStart) selects the longest-match owner;
// isPeerInterestedTG covers the return leg. Cluster TGs with no prefix
// match anywhere stay single-hop — gating on hasPrefixRoute prevents
// them from looping in cyclic trunk topologies.
if (m_reflector->shouldRelayInbound(local_tg))
{
m_reflector->forwardTrunkTalkerStartToOtherTrunks(this, local_tg,
msg.callsign());
@@ -1064,8 +1067,9 @@ void TrunkLink::handleMsgPeerTalkerStop(std::istream& is)
TGHandler::instance()->clearTrunkTalkerForTG(local_tg);
m_reflector->notifyExternalTrunkTalkerStop(local_tg, m_section);
// Owner-relay: propagate the talker-stop to every other interested peer.
if (m_reflector->isLocalTG(local_tg))
// Prefix-routed fanout (mirrors talker-start): only fan out if we have
// a route. Cluster TGs without a prefix match stay single-hop.
if (m_reflector->shouldRelayInbound(local_tg))
{
m_reflector->forwardTrunkTalkerStopToOtherTrunks(this, local_tg);
}
@@ -1117,9 +1121,9 @@ void TrunkLink::handleMsgPeerAudio(std::istream& is)
// Forward trunk audio to connected satellites
m_reflector->forwardAudioToSatellitesExcept(nullptr, local_tg, msg.audio());
// Owner-relay: when the TG is ours, fan the audio out to every other
// trunk peer that has interest (so mesh-wide audience hears the talker).
if (m_reflector->isLocalTG(local_tg))
// Prefix-routed fanout (mirrors talker-start): only fan out if we have
// a route. Cluster TGs without a prefix match stay single-hop.
if (m_reflector->shouldRelayInbound(local_tg))
{
m_reflector->forwardTrunkAudioToOtherTrunks(this, local_tg, msg.audio());
}
@@ -1153,9 +1157,9 @@ void TrunkLink::handleMsgPeerFlush(std::istream& is)
// Forward trunk flush to connected satellites
m_reflector->forwardFlushToSatellitesExcept(nullptr, local_tg);
// Owner-relay: when the TG is ours, fan the flush out to every other
// trunk peer so their clients see end-of-stream as well.
if (m_reflector->isLocalTG(local_tg))
// Prefix-routed fanout (mirrors talker-start): only fan out if we have
// a route. Cluster TGs without a prefix match stay single-hop.
if (m_reflector->shouldRelayInbound(local_tg))
{
m_reflector->forwardTrunkFlushToOtherTrunks(this, local_tg);
}