feat(peer): passive-monitor support via MsgPeerTgInterest
A node that has selected a TG without keying, or marked it in monitoredTGs, never received any audio: peer interest was only populated by talker activity, and the local UDP fanout filtered by TgFilter alone (current TG match), ignoring monitor entries. Adds: - MsgPeerTgInterest (wire ID 129, peer_id + vector<uint32_t>) — each trunk peer advertises the union of its local clients' selected TG and monitoredTGs to peers whose prefix is the longest-prefix-match for the TG. Edge-triggered (500 ms debounce) on client connect / disconnect, MsgSelectTG, MsgTgMonitor, and trunk hello completion; 60 s periodic refresh as a safety net, skipping when the outgoing set is unchanged. The receiver writes mapTgIn(tg) into m_peer_interested_tgs so the existing send-side gates (isPeerInterestedTG, shouldRelayInbound + forwardTrunkAudioToOther Trunks) deliver audio without requiring a PTT to bootstrap. - Multi-hop propagation. Receivers re-advertise interest from other peers, prefix-filtered for the destination link and source-link excluded, so country-gateway-into-national-mesh layouts (§2) converge in one debounce per hop. Closes the gap where SE monitoring an Italian regional TG would never reach Z1 without IT 222 explicitly forwarding interest. - TgMonitorFilter applied at every local UDP fanout (audio + MsgUdpFlushSamples) — Reflector::onUdpFrameReceived and the local talker stop, the trunk receive path, and both directions of the satellite mirror. Without this, the protocol-level interest arrives at the right reflector but stops at its UDP fanout — the passive monitor still hears nothing. Strict superset: no existing delivery path is removed. Loop safety relies on filtering local-side MsgPeerTgInterest by isSharedTG (same gate as audio fanout). Advertising to non-owner peers would register ghost interest there, which gateway prefix routing would then relay back across the mesh. Verified by test_32_three_way_conversation (full mesh, no echo loops). Tests: new test_39_passive_monitor_multihop covers the §2 chain (SE-style monitor on a, talker on d, gateway b). All existing tests pass: 42 trunk + 7 mqtt-deltas + 6 logging + 14 twin = 69/69. Builds on the idea originally proposed in #4 by @sa2blv; the single-hop and wire-ID-collision issues described in the close comment are addressed in this rewrite.
This commit is contained in:
1 parent
ccf34adbe6
commit
a6618790bb
11 files changed
+496
-23
No files matched your search
@@ -2656,6 +2656,78 @@ class TestTrunkIntegration(unittest.TestCase):
|
||||
sender.close()
|
||||
receiver.close()
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Test 39: passive monitor actually hears audio across a multi-hop gateway
|
||||
# ------------------------------------------------------------------
|
||||
def test_39_passive_monitor_multihop(self):
|
||||
"""A passive monitor on reflector-a hears audio from a TG owned by
|
||||
reflector-d, with reflector-b acting as a gateway, *without* the
|
||||
monitor ever PTT'ing to bootstrap interest.
|
||||
|
||||
Topology (test_37 setup):
|
||||
a prefix 122 trunks: b, c (no direct trunk to d)
|
||||
b prefix 121 trunks: a, c, d (gateway)
|
||||
d prefix 1219 trunks: b only
|
||||
|
||||
TG `121951` is owned by d. a's monitored set is advertised via
|
||||
MsgPeerTgInterest to b; b longest-prefix-matches `1219` → d and
|
||||
re-advertises the interest to d. d's PTT then fans out to b
|
||||
(peer-interest), b forwards to a (peer-interest), and a delivers
|
||||
UDP audio to the local monitoring client via TgMonitorFilter. The
|
||||
whole chain works without a transmitting once.
|
||||
"""
|
||||
if "d" not in REFLECTOR_NAMES:
|
||||
self.skipTest("test_39 requires reflector 'd' in topology")
|
||||
|
||||
tg = 121951 # owned by d (longest 1219); next-longest at b is 121
|
||||
|
||||
a_client = ClientPeer()
|
||||
d_client = ClientPeer()
|
||||
try:
|
||||
# a-client: connects to a, selects tg=0 (no PTT possible),
|
||||
# monitors `tg` passively. This is the "Swedish ham listening
|
||||
# to an Italian regional TG" case — interest must propagate to
|
||||
# the owner without the monitor transmitting.
|
||||
a_port = T.mapped_client_port("a")
|
||||
a_client.connect(HOST, a_port)
|
||||
a_client.authenticate(callsign=CLIENT_CALLSIGN, password=CLIENT_PASSWORD)
|
||||
a_client.setup_udp(udp_port=a_port)
|
||||
a_client.select_tg(0)
|
||||
a_client.monitor_tgs([tg])
|
||||
|
||||
# d-client: connects to d, selects `tg`, will PTT.
|
||||
d_port = T.mapped_client_port("d")
|
||||
d_client.connect(HOST, d_port)
|
||||
d_client.authenticate(callsign=CLIENT2_CALLSIGN, password=CLIENT2_PASSWORD)
|
||||
d_client.setup_udp(udp_port=d_port)
|
||||
d_client.select_tg(tg)
|
||||
|
||||
# Advertisement is debounced 500 ms in TrunkLink, then re-advertised
|
||||
# at b on receipt → debounced again toward d. 2 s gives both legs
|
||||
# plus a safety margin.
|
||||
time.sleep(2.0)
|
||||
|
||||
# Drain any backlog before the measurement burst.
|
||||
a_client.recv_udp_all(timeout=0.05)
|
||||
|
||||
for _ in range(6):
|
||||
d_client.send_udp_audio(b"\xBE\xEF" * 80)
|
||||
time.sleep(0.02)
|
||||
d_client.send_udp_flush()
|
||||
time.sleep(1.5)
|
||||
|
||||
msgs = a_client.recv_udp_all(timeout=1.0)
|
||||
audio = sum(1 for t, _ in msgs if t == UDP_AUDIO)
|
||||
flush = sum(1 for t, _ in msgs if t == UDP_FLUSH)
|
||||
self.assertGreater(audio + flush, 0,
|
||||
f"passive monitor on reflector-a did not hear TG {tg} "
|
||||
f"audio from reflector-d via gateway b — "
|
||||
f"MsgPeerTgInterest multi-hop propagation or "
|
||||
f"TgMonitorFilter UDP delivery broken")
|
||||
finally:
|
||||
a_client.close()
|
||||
d_client.close()
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Custom test runner with clean, readable output
|
||||
|
||||
Reference in new issue
Block a user