fix(reflector): restrict monitor-TG UDP audio to passive observers

A client with a non-zero selected TG must never receive UDP audio
for a monitored TG. svxlink's priority/auto-switch for monitor TGs
is driven by the TCP TalkerStart message; once svxlink decides to
switch, it sends MsgSelectTG and from then on the audio arrives via
the selected-TG arm of the fanout (TgFilter). The monitor arm is
only meaningful for passive observers (currentTG=0).

a661879 (v1.3.10) introduced the monitor arm to support passive
multi-hop monitoring, but gated it loosely. dc3a8c0 narrowed the
gate to "selected TG idle right now" — too eager, since a real
QSO has 0.5-3s inter-PTT gaps where the selected TG is talkerless.
5c585be added first-talker-wins on top, masking but not fixing
the leak. The net effect: while a user was mid-QSO on TG 9 with
TG 110 in MONITOR_TGS, TG 110 audio bled into the inter-PTT gaps
and was played by svxlink. Tragedy.

Replace SelectedTgIdleFilter with PassiveObserverFilter
(`m_current_tg == 0`) at all 9 UDP fanout sites in Reflector.cpp,
SatelliteClient.cpp, SatelliteLink.cpp, and TrunkLink.cpp.
EarliestMonitorTalkerFilter is retained — passive observers with
multiple monitor TGs still need first-talker-wins to avoid Opus
decoder mixing (test_44).

Tests:
- New test_45 pins down the contract: A select_tg=9,
  monitor_tgs=[110]; C continuously talks on 110; A receives zero
  TG 110 UDP frames. Fails on master, passes after fix.
- test_43 repurposed from "first-talker-wins for selected" (a
  property that should never have been asserted) to the
  multi-monitor variant of test_45.
- test_39/40/41/42/44 stay green by construction.

All suites: 48 trunk + 7 mqtt + 6 logging + 15 twin = 76/76.
This commit is contained in:
Audric committed 2026-05-12 16:48:52 +02:00
1 parent 5c585bebbc
commit d5860ad1dc
7 files changed
+120 -55

No files matched your search

+3 -3
View File
@@ -1414,7 +1414,7 @@ void Reflector::udpDatagramReceived(const IpAddress& addr, uint16_t port,
ReflectorClient::mkAndFilter(
ReflectorClient::TgMonitorFilter(tg),
ReflectorClient::mkAndFilter(
ReflectorClient::SelectedTgIdleFilter(),
ReflectorClient::PassiveObserverFilter(),
ReflectorClient::EarliestMonitorTalkerFilter(tg))))));
if (m_is_satellite && m_satellite_client != nullptr)
{
@@ -1584,7 +1584,7 @@ void Reflector::onTalkerUpdated(uint32_t tg, ReflectorClient* old_talker,
ReflectorClient::mkAndFilter(
ReflectorClient::TgMonitorFilter(tg),
ReflectorClient::mkAndFilter(
ReflectorClient::SelectedTgIdleFilter(),
ReflectorClient::PassiveObserverFilter(),
ReflectorClient::EarliestMonitorTalkerFilter(tg)))),
ReflectorClient::ExceptFilter(old_talker)));
if (m_mqtt != nullptr)
@@ -2903,7 +2903,7 @@ void Reflector::onTrunkTalkerUpdated(uint32_t tg,
ReflectorClient::mkAndFilter(
ReflectorClient::TgMonitorFilter(tg),
ReflectorClient::mkAndFilter(
ReflectorClient::SelectedTgIdleFilter(),
ReflectorClient::PassiveObserverFilter(),
ReflectorClient::EarliestMonitorTalkerFilter(tg)))));
if (m_mqtt != nullptr)
{
+3 -9
View File
@@ -184,17 +184,11 @@ bool ReflectorClient::TgFilter::operator()(ReflectorClient* client) const
}
bool ReflectorClient::SelectedTgIdleFilter::operator()(
bool ReflectorClient::PassiveObserverFilter::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() */
return client->m_current_tg == 0;
} /* ReflectorClient::PassiveObserverFilter::operator() */
namespace {
+18 -7
View File
@@ -203,10 +203,23 @@ class ReflectorClient : public sigc::trackable
uint32_t m_tg;
};
class SelectedTgIdleFilter : public Filter
/**
* @brief Gate monitor-TG UDP delivery on passive-observer state.
*
* Returns true iff the client has no selected TG (`currentTG == 0`).
* svxlink's priority/auto-switch logic for monitor TGs is driven by
* the TCP TalkerStart message, not by UDP audio — a client with a
* selected TG never needs monitor-TG audio over UDP. Once svxlink
* decides to switch, it sends `MsgSelectTG` and from then on the
* audio arrives via the selected-TG arm of the fanout
* (`TgFilter(tg)`). The monitor arm exists exclusively to serve
* passive observers who set `currentTG=0` and rely on `monitor_tgs`
* for awareness.
*/
class PassiveObserverFilter : public Filter
{
public:
SelectedTgIdleFilter() {}
PassiveObserverFilter() {}
virtual bool operator ()(ReflectorClient *client) const;
};
@@ -223,11 +236,9 @@ class ReflectorClient : public sigc::trackable
* still considered as a candidate — this delivers the flush to the
* listener that was actually decoding it.
*
* Designed to be ANDed with `TgMonitorFilter(tg)` and
* `SelectedTgIdleFilter` at the seven UDP fanout sites added by
* `92d9a63`. With those two siblings the predicate evaluates only on
* the monitor arm of the OR; the selected-TG arm (`TgFilter(tg)`)
* is unaffected.
* Designed to be ANDed with `PassiveObserverFilter` and
* `TgMonitorFilter(tg)` so it only evaluates on the monitor arm of
* the fanout OR for `currentTG=0` clients.
*/
class EarliestMonitorTalkerFilter : public Filter
{
+2 -2
View File
@@ -368,7 +368,7 @@ void SatelliteClient::handleMsgPeerAudio(std::istream& is)
ReflectorClient::mkAndFilter(
ReflectorClient::TgMonitorFilter(msg.tg()),
ReflectorClient::mkAndFilter(
ReflectorClient::SelectedTgIdleFilter(),
ReflectorClient::PassiveObserverFilter(),
ReflectorClient::EarliestMonitorTalkerFilter(msg.tg())))));
} /* SatelliteClient::handleMsgPeerAudio */
@@ -384,7 +384,7 @@ void SatelliteClient::handleMsgPeerFlush(std::istream& is)
ReflectorClient::mkAndFilter(
ReflectorClient::TgMonitorFilter(msg.tg()),
ReflectorClient::mkAndFilter(
ReflectorClient::SelectedTgIdleFilter(),
ReflectorClient::PassiveObserverFilter(),
ReflectorClient::EarliestMonitorTalkerFilter(msg.tg())))));
} /* SatelliteClient::handleMsgPeerFlush */
+2 -2
View File
@@ -388,7 +388,7 @@ void SatelliteLink::handleMsgPeerAudio(std::istream& is)
ReflectorClient::mkAndFilter(
ReflectorClient::TgMonitorFilter(tg),
ReflectorClient::mkAndFilter(
ReflectorClient::SelectedTgIdleFilter(),
ReflectorClient::PassiveObserverFilter(),
ReflectorClient::EarliestMonitorTalkerFilter(tg)))));
// Forward to trunk peers
@@ -415,7 +415,7 @@ void SatelliteLink::handleMsgPeerFlush(std::istream& is)
ReflectorClient::mkAndFilter(
ReflectorClient::TgMonitorFilter(tg),
ReflectorClient::mkAndFilter(
ReflectorClient::SelectedTgIdleFilter(),
ReflectorClient::PassiveObserverFilter(),
ReflectorClient::EarliestMonitorTalkerFilter(tg)))));
m_reflector->forwardSatelliteFlushToTrunks(tg);
+2 -2
View File
@@ -1164,7 +1164,7 @@ void TrunkLink::handleMsgPeerAudio(std::istream& is)
ReflectorClient::mkAndFilter(
ReflectorClient::TgMonitorFilter(local_tg),
ReflectorClient::mkAndFilter(
ReflectorClient::SelectedTgIdleFilter(),
ReflectorClient::PassiveObserverFilter(),
ReflectorClient::EarliestMonitorTalkerFilter(local_tg)))));
// Forward trunk audio to connected satellites
@@ -1206,7 +1206,7 @@ void TrunkLink::handleMsgPeerFlush(std::istream& is)
ReflectorClient::mkAndFilter(
ReflectorClient::TgMonitorFilter(local_tg),
ReflectorClient::mkAndFilter(
ReflectorClient::SelectedTgIdleFilter(),
ReflectorClient::PassiveObserverFilter(),
ReflectorClient::EarliestMonitorTalkerFilter(local_tg)))));
// Forward trunk flush to connected satellites