fix(reflector): gate monitor TG UDP delivery on selected TG idle
Adds ReflectorClient::SelectedTgIdleFilter and wraps the TgMonitorFilter
arm at the seven UDP fanout sites that a661879 (v1.3.10) added it to.
Monitor-TG UDP audio is now delivered to a client only when its selected
TG has no active local or trunk talker; passive observers (currentTG=0)
keep receiving monitor UDP via a tg==0 short-circuit. svxlink's TCP
TalkerStart path and ++/+/plain priority logic are untouched.
Restores the pre-v1.3.10 single-TG-at-a-time invariant for selected-TG
clients while keeping test_39 (passive multi-hop) green. Adds test_40
(monitor-TG mixing regression), test_41 (priority switch via MsgSelectTG),
test_42 (passive observer sanity).
This commit is contained in:
1 parent
36d49fbbd6
commit
dc3a8c018c
7 files changed
+153
-9
No files matched your search
@@ -1411,7 +1411,9 @@ void Reflector::udpDatagramReceived(const IpAddress& addr, uint16_t port,
|
|||||||
ReflectorClient::ExceptFilter(client),
|
ReflectorClient::ExceptFilter(client),
|
||||||
ReflectorClient::mkOrFilter(
|
ReflectorClient::mkOrFilter(
|
||||||
ReflectorClient::TgFilter(tg),
|
ReflectorClient::TgFilter(tg),
|
||||||
ReflectorClient::TgMonitorFilter(tg))));
|
ReflectorClient::mkAndFilter(
|
||||||
|
ReflectorClient::TgMonitorFilter(tg),
|
||||||
|
ReflectorClient::SelectedTgIdleFilter()))));
|
||||||
if (m_is_satellite && m_satellite_client != nullptr)
|
if (m_is_satellite && m_satellite_client != nullptr)
|
||||||
{
|
{
|
||||||
m_satellite_client->onLocalAudio(tg, msg.audioData());
|
m_satellite_client->onLocalAudio(tg, msg.audioData());
|
||||||
@@ -1577,7 +1579,9 @@ void Reflector::onTalkerUpdated(uint32_t tg, ReflectorClient* old_talker,
|
|||||||
ReflectorClient::mkAndFilter(
|
ReflectorClient::mkAndFilter(
|
||||||
ReflectorClient::mkOrFilter(
|
ReflectorClient::mkOrFilter(
|
||||||
ReflectorClient::TgFilter(tg),
|
ReflectorClient::TgFilter(tg),
|
||||||
ReflectorClient::TgMonitorFilter(tg)),
|
ReflectorClient::mkAndFilter(
|
||||||
|
ReflectorClient::TgMonitorFilter(tg),
|
||||||
|
ReflectorClient::SelectedTgIdleFilter())),
|
||||||
ReflectorClient::ExceptFilter(old_talker)));
|
ReflectorClient::ExceptFilter(old_talker)));
|
||||||
if (m_mqtt != nullptr)
|
if (m_mqtt != nullptr)
|
||||||
{
|
{
|
||||||
@@ -2854,7 +2858,9 @@ void Reflector::onTrunkTalkerUpdated(uint32_t tg,
|
|||||||
broadcastUdpMsg(MsgUdpFlushSamples(),
|
broadcastUdpMsg(MsgUdpFlushSamples(),
|
||||||
ReflectorClient::mkOrFilter(
|
ReflectorClient::mkOrFilter(
|
||||||
ReflectorClient::TgFilter(tg),
|
ReflectorClient::TgFilter(tg),
|
||||||
ReflectorClient::TgMonitorFilter(tg)));
|
ReflectorClient::mkAndFilter(
|
||||||
|
ReflectorClient::TgMonitorFilter(tg),
|
||||||
|
ReflectorClient::SelectedTgIdleFilter())));
|
||||||
if (m_mqtt != nullptr)
|
if (m_mqtt != nullptr)
|
||||||
{
|
{
|
||||||
m_mqtt->onPeerTalkerStop(peer_id, tg, old_cs);
|
m_mqtt->onPeerTalkerStop(peer_id, tg, old_cs);
|
||||||
|
|||||||
@@ -184,6 +184,19 @@ bool ReflectorClient::TgFilter::operator()(ReflectorClient* client) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool ReflectorClient::SelectedTgIdleFilter::operator()(
|
||||||
|
ReflectorClient* client) const
|
||||||
|
{
|
||||||
|
uint32_t tg = client->m_current_tg;
|
||||||
|
if (tg == 0)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return TGHandler::instance()->talkerForTG(tg) == nullptr
|
||||||
|
&& !TGHandler::instance()->hasTrunkTalker(tg);
|
||||||
|
} /* ReflectorClient::SelectedTgIdleFilter::operator() */
|
||||||
|
|
||||||
|
|
||||||
ReflectorClient::ReflectorClient(Reflector *ref, Async::FramedTcpConnection *con,
|
ReflectorClient::ReflectorClient(Reflector *ref, Async::FramedTcpConnection *con,
|
||||||
Async::Config *cfg)
|
Async::Config *cfg)
|
||||||
: m_con(con), m_con_state(STATE_EXPECT_PROTO_VER),
|
: m_con(con), m_con_state(STATE_EXPECT_PROTO_VER),
|
||||||
|
|||||||
@@ -203,6 +203,13 @@ class ReflectorClient : public sigc::trackable
|
|||||||
uint32_t m_tg;
|
uint32_t m_tg;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class SelectedTgIdleFilter : public Filter
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
SelectedTgIdleFilter() {}
|
||||||
|
virtual bool operator ()(ReflectorClient *client) const;
|
||||||
|
};
|
||||||
|
|
||||||
template <class F1, class F2>
|
template <class F1, class F2>
|
||||||
class AndFilter : public Filter
|
class AndFilter : public Filter
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -365,7 +365,9 @@ void SatelliteClient::handleMsgPeerAudio(std::istream& is)
|
|||||||
m_reflector->broadcastUdpMsg(udp_msg,
|
m_reflector->broadcastUdpMsg(udp_msg,
|
||||||
ReflectorClient::mkOrFilter(
|
ReflectorClient::mkOrFilter(
|
||||||
ReflectorClient::TgFilter(msg.tg()),
|
ReflectorClient::TgFilter(msg.tg()),
|
||||||
ReflectorClient::TgMonitorFilter(msg.tg())));
|
ReflectorClient::mkAndFilter(
|
||||||
|
ReflectorClient::TgMonitorFilter(msg.tg()),
|
||||||
|
ReflectorClient::SelectedTgIdleFilter())));
|
||||||
} /* SatelliteClient::handleMsgPeerAudio */
|
} /* SatelliteClient::handleMsgPeerAudio */
|
||||||
|
|
||||||
|
|
||||||
@@ -377,7 +379,9 @@ void SatelliteClient::handleMsgPeerFlush(std::istream& is)
|
|||||||
m_reflector->broadcastUdpMsg(MsgUdpFlushSamples(),
|
m_reflector->broadcastUdpMsg(MsgUdpFlushSamples(),
|
||||||
ReflectorClient::mkOrFilter(
|
ReflectorClient::mkOrFilter(
|
||||||
ReflectorClient::TgFilter(msg.tg()),
|
ReflectorClient::TgFilter(msg.tg()),
|
||||||
ReflectorClient::TgMonitorFilter(msg.tg())));
|
ReflectorClient::mkAndFilter(
|
||||||
|
ReflectorClient::TgMonitorFilter(msg.tg()),
|
||||||
|
ReflectorClient::SelectedTgIdleFilter())));
|
||||||
} /* SatelliteClient::handleMsgPeerFlush */
|
} /* SatelliteClient::handleMsgPeerFlush */
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -379,7 +379,9 @@ void SatelliteLink::handleMsgPeerAudio(std::istream& is)
|
|||||||
m_reflector->broadcastUdpMsg(udp_msg,
|
m_reflector->broadcastUdpMsg(udp_msg,
|
||||||
ReflectorClient::mkOrFilter(
|
ReflectorClient::mkOrFilter(
|
||||||
ReflectorClient::TgFilter(tg),
|
ReflectorClient::TgFilter(tg),
|
||||||
ReflectorClient::TgMonitorFilter(tg)));
|
ReflectorClient::mkAndFilter(
|
||||||
|
ReflectorClient::TgMonitorFilter(tg),
|
||||||
|
ReflectorClient::SelectedTgIdleFilter())));
|
||||||
|
|
||||||
// Forward to trunk peers
|
// Forward to trunk peers
|
||||||
m_reflector->forwardSatelliteRawAudioToTrunks(tg, msg.audio());
|
m_reflector->forwardSatelliteRawAudioToTrunks(tg, msg.audio());
|
||||||
@@ -399,7 +401,9 @@ void SatelliteLink::handleMsgPeerFlush(std::istream& is)
|
|||||||
m_reflector->broadcastUdpMsg(MsgUdpFlushSamples(),
|
m_reflector->broadcastUdpMsg(MsgUdpFlushSamples(),
|
||||||
ReflectorClient::mkOrFilter(
|
ReflectorClient::mkOrFilter(
|
||||||
ReflectorClient::TgFilter(tg),
|
ReflectorClient::TgFilter(tg),
|
||||||
ReflectorClient::TgMonitorFilter(tg)));
|
ReflectorClient::mkAndFilter(
|
||||||
|
ReflectorClient::TgMonitorFilter(tg),
|
||||||
|
ReflectorClient::SelectedTgIdleFilter())));
|
||||||
|
|
||||||
m_reflector->forwardSatelliteFlushToTrunks(tg);
|
m_reflector->forwardSatelliteFlushToTrunks(tg);
|
||||||
m_reflector->forwardFlushToSatellitesExcept(this, tg);
|
m_reflector->forwardFlushToSatellitesExcept(this, tg);
|
||||||
|
|||||||
@@ -1161,7 +1161,9 @@ void TrunkLink::handleMsgPeerAudio(std::istream& is)
|
|||||||
m_reflector->broadcastUdpMsg(udp_msg,
|
m_reflector->broadcastUdpMsg(udp_msg,
|
||||||
ReflectorClient::mkOrFilter(
|
ReflectorClient::mkOrFilter(
|
||||||
ReflectorClient::TgFilter(local_tg),
|
ReflectorClient::TgFilter(local_tg),
|
||||||
ReflectorClient::TgMonitorFilter(local_tg)));
|
ReflectorClient::mkAndFilter(
|
||||||
|
ReflectorClient::TgMonitorFilter(local_tg),
|
||||||
|
ReflectorClient::SelectedTgIdleFilter())));
|
||||||
|
|
||||||
// Forward trunk audio to connected satellites
|
// Forward trunk audio to connected satellites
|
||||||
m_reflector->forwardAudioToSatellitesExcept(nullptr, local_tg, msg.audio());
|
m_reflector->forwardAudioToSatellitesExcept(nullptr, local_tg, msg.audio());
|
||||||
@@ -1199,7 +1201,9 @@ void TrunkLink::handleMsgPeerFlush(std::istream& is)
|
|||||||
m_reflector->broadcastUdpMsg(MsgUdpFlushSamples(),
|
m_reflector->broadcastUdpMsg(MsgUdpFlushSamples(),
|
||||||
ReflectorClient::mkOrFilter(
|
ReflectorClient::mkOrFilter(
|
||||||
ReflectorClient::TgFilter(local_tg),
|
ReflectorClient::TgFilter(local_tg),
|
||||||
ReflectorClient::TgMonitorFilter(local_tg)));
|
ReflectorClient::mkAndFilter(
|
||||||
|
ReflectorClient::TgMonitorFilter(local_tg),
|
||||||
|
ReflectorClient::SelectedTgIdleFilter())));
|
||||||
|
|
||||||
// Forward trunk flush to connected satellites
|
// Forward trunk flush to connected satellites
|
||||||
m_reflector->forwardFlushToSatellitesExcept(nullptr, local_tg);
|
m_reflector->forwardFlushToSatellitesExcept(nullptr, local_tg);
|
||||||
|
|||||||
@@ -2804,6 +2804,112 @@ class TestTrunkIntegration(unittest.TestCase):
|
|||||||
b_client.close()
|
b_client.close()
|
||||||
c_client.close()
|
c_client.close()
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
# Test 41: priority-driven TG switch via MsgSelectTG resumes audio
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
def test_41_priority_switch_still_works(self):
|
||||||
|
"""When real svxlink sees a higher-priority monitor TG fire while
|
||||||
|
its selected TG is idle, it sends MsgSelectTG to switch. The
|
||||||
|
reflector then routes audio for the new selected TG via TgFilter
|
||||||
|
(the gate is irrelevant on that arm). This test simulates the
|
||||||
|
switch (the Python client can't run svxlink's priority logic) and
|
||||||
|
confirms audio flows after MsgSelectTG.
|
||||||
|
|
||||||
|
Before the simulated switch: A's currentTG=9 idle, monitor=[110],
|
||||||
|
a talker on TG 110. With the new gate AND `currentTG=9 idle`, the
|
||||||
|
monitor arm passes (talkerForTG(9) is null). To make the test
|
||||||
|
independent of that detail and prove the post-switch path, we
|
||||||
|
call select_tg(110), drain any traffic from before the measurement
|
||||||
|
burst, then verify the post-switch audio arrives via TgFilter.
|
||||||
|
"""
|
||||||
|
port = T.mapped_client_port(self.PRIMARY)
|
||||||
|
|
||||||
|
a_client = ClientPeer()
|
||||||
|
c_client = ClientPeer()
|
||||||
|
try:
|
||||||
|
a_client.connect(HOST, port)
|
||||||
|
a_client.authenticate(callsign=CLIENT_CALLSIGN, password=CLIENT_PASSWORD)
|
||||||
|
a_client.setup_udp(udp_port=port)
|
||||||
|
a_client.select_tg(9)
|
||||||
|
a_client.monitor_tgs([110])
|
||||||
|
|
||||||
|
c_client.connect(HOST, port)
|
||||||
|
c_client.authenticate(callsign=CLIENT2_CALLSIGN, password=CLIENT2_PASSWORD)
|
||||||
|
c_client.setup_udp(udp_port=port)
|
||||||
|
c_client.select_tg(110)
|
||||||
|
|
||||||
|
time.sleep(0.4)
|
||||||
|
|
||||||
|
# Simulate svxlink's priority-driven switch: A re-selects TG 110.
|
||||||
|
a_client.select_tg(110)
|
||||||
|
time.sleep(0.2)
|
||||||
|
a_client.recv_udp_all(timeout=0.05)
|
||||||
|
|
||||||
|
P_C = b"\xCC\xDD\xCC\xDD"
|
||||||
|
for _ in range(6):
|
||||||
|
c_client.send_udp_audio(P_C * 40)
|
||||||
|
time.sleep(0.02)
|
||||||
|
c_client.send_udp_flush()
|
||||||
|
time.sleep(0.5)
|
||||||
|
|
||||||
|
msgs = a_client.recv_udp_all(timeout=1.0)
|
||||||
|
audio_payloads = [p for t, p in msgs if t == UDP_AUDIO]
|
||||||
|
self.assertGreater(len(audio_payloads), 0,
|
||||||
|
"After simulated priority switch (select_tg(110)), A "
|
||||||
|
"received no TG 110 UDP audio — TgFilter delivery broken")
|
||||||
|
self.assertTrue(any(P_C in p for p in audio_payloads),
|
||||||
|
"Audio arrived but did not carry the TG 110 pattern P_C")
|
||||||
|
finally:
|
||||||
|
a_client.close()
|
||||||
|
c_client.close()
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
# Test 42: passive observer (currentTG=0) still gets monitor UDP
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
def test_42_passive_observer_unaffected(self):
|
||||||
|
"""A client with select_tg(0) and a single monitor TG must still
|
||||||
|
receive UDP audio for that monitor TG. Guards the
|
||||||
|
`tg == 0 → return true` short-circuit in SelectedTgIdleFilter.
|
||||||
|
"""
|
||||||
|
port = T.mapped_client_port(self.PRIMARY)
|
||||||
|
|
||||||
|
a_client = ClientPeer()
|
||||||
|
c_client = ClientPeer()
|
||||||
|
try:
|
||||||
|
a_client.connect(HOST, port)
|
||||||
|
a_client.authenticate(callsign=CLIENT_CALLSIGN, password=CLIENT_PASSWORD)
|
||||||
|
a_client.setup_udp(udp_port=port)
|
||||||
|
a_client.select_tg(0)
|
||||||
|
a_client.monitor_tgs([110])
|
||||||
|
|
||||||
|
c_client.connect(HOST, port)
|
||||||
|
c_client.authenticate(callsign=CLIENT2_CALLSIGN, password=CLIENT2_PASSWORD)
|
||||||
|
c_client.setup_udp(udp_port=port)
|
||||||
|
c_client.select_tg(110)
|
||||||
|
|
||||||
|
time.sleep(0.4)
|
||||||
|
a_client.recv_udp_all(timeout=0.05)
|
||||||
|
|
||||||
|
P_C = b"\xCC\xDD\xCC\xDD"
|
||||||
|
for _ in range(6):
|
||||||
|
c_client.send_udp_audio(P_C * 40)
|
||||||
|
time.sleep(0.02)
|
||||||
|
c_client.send_udp_flush()
|
||||||
|
time.sleep(0.5)
|
||||||
|
|
||||||
|
msgs = a_client.recv_udp_all(timeout=1.0)
|
||||||
|
audio_payloads = [p for t, p in msgs if t == UDP_AUDIO]
|
||||||
|
self.assertGreater(len(audio_payloads), 0,
|
||||||
|
"Passive observer (currentTG=0, monitor=[110]) received no "
|
||||||
|
"UDP audio — SelectedTgIdleFilter incorrectly blocking the "
|
||||||
|
"currentTG==0 case")
|
||||||
|
self.assertTrue(any(P_C in p for p in audio_payloads),
|
||||||
|
"Passive observer received audio but no frames carried "
|
||||||
|
"the TG 110 pattern P_C")
|
||||||
|
finally:
|
||||||
|
a_client.close()
|
||||||
|
c_client.close()
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# Custom test runner with clean, readable output
|
# Custom test runner with clean, readable output
|
||||||
|
|||||||
Reference in new issue
Block a user