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
@@ -2968,6 +2968,29 @@ bool Reflector::isLocalTG(uint32_t tg) const
|
||||
} /* Reflector::isLocalTG */
|
||||
|
||||
|
||||
bool Reflector::hasPrefixRoute(uint32_t tg) const
|
||||
{
|
||||
const std::string s = std::to_string(tg);
|
||||
for (const auto& prefix : m_all_prefixes)
|
||||
{
|
||||
if (s.size() >= prefix.size() &&
|
||||
s.compare(0, prefix.size(), prefix) == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
} /* Reflector::hasPrefixRoute */
|
||||
|
||||
|
||||
bool Reflector::shouldRelayInbound(uint32_t tg) const
|
||||
{
|
||||
if (isLocalTG(tg)) return true;
|
||||
if (isClusterTG(tg)) return false;
|
||||
return hasPrefixRoute(tg);
|
||||
} /* Reflector::shouldRelayInbound */
|
||||
|
||||
|
||||
void Reflector::forwardTrunkAudioToOtherTrunks(const TrunkLink* src,
|
||||
uint32_t tg,
|
||||
const std::vector<uint8_t>& audio)
|
||||
|
||||
@@ -253,6 +253,24 @@ class Reflector : public sigc::trackable
|
||||
// Used to gate owner-relay fanout of trunk-received audio.
|
||||
bool isLocalTG(uint32_t tg) const;
|
||||
|
||||
// True iff any prefix in m_all_prefixes (local + every configured
|
||||
// [TRUNK_x] REMOTE_PREFIX) prefix-matches this TG. Used to gate
|
||||
// trunk-to-trunk fanout: a non-owner gateway forwards onward only if
|
||||
// it knows a route via prefix table. A bare cluster TG with no prefix
|
||||
// anywhere in the mesh has no route and stays single-hop.
|
||||
bool hasPrefixRoute(uint32_t tg) const;
|
||||
|
||||
// True iff inbound trunk traffic for this TG should be re-forwarded
|
||||
// to other trunk peers. Composes ownership, prefix routing, and the
|
||||
// anti-loop rule for cluster TGs:
|
||||
// - we own it -> yes (existing owner-fanout)
|
||||
// - it is a cluster TG -> no (deliberately single-hop; cluster TGs
|
||||
// are broadcast outbound from local clients, never relayed
|
||||
// between trunk peers, since they would loop in cyclic meshes)
|
||||
// - we have a prefix route (gateway between meshes) -> yes
|
||||
// - otherwise -> no
|
||||
bool shouldRelayInbound(uint32_t tg) const;
|
||||
|
||||
// Owner-relay fanout: when we receive trunk traffic for a TG we own,
|
||||
// forward to every other trunk peer except `src`. Each peer's TrunkLink
|
||||
// applies its own shared/cluster/interest filter, so links with no
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user