feat(reflector): apply TG filter at fanout for events without inline TG

Disconnect, rx, and status messages don't carry a TG, so the sender
looks up the originating client's current TG via currentClientTg()
and tests it against each SatelliteLink's filter before emitting.
Connect events already have inline TG filtering inside
SatelliteLink::sendClientConnected.

If the lookup returns 0 (e.g. the client has just disconnected when
the fanout fires), default-allow rather than block — preserves the
event flow when the local client state is racing.

SatelliteClient and TwinLink have no filter today — they receive
unfiltered.
This commit is contained in:
Audric committed 2026-04-28 20:57:54 +02:00
1 parent 24a4bc98f9
commit b5b54cb8d6
3 files changed
+33 -4

No files matched your search

+23 -3
View File
@@ -3144,6 +3144,20 @@ void Reflector::publishClientStatus(ReflectorClient* client)
} /* Reflector::publishClientStatus */ } /* Reflector::publishClientStatus */
uint32_t Reflector::currentClientTg(const std::string& callsign) const
{
for (const auto& it : m_client_con_map)
{
ReflectorClient* c = it.second;
if (c != nullptr && c->callsign() == callsign)
{
return c->currentTG();
}
}
return 0;
} /* Reflector::currentClientTg */
void Reflector::fanoutClientConnected(const std::string& callsign, void Reflector::fanoutClientConnected(const std::string& callsign,
uint32_t tg, uint32_t tg,
const std::string& ip) const std::string& ip)
@@ -3168,9 +3182,11 @@ void Reflector::fanoutClientConnected(const std::string& callsign,
void Reflector::fanoutClientDisconnected(const std::string& callsign) void Reflector::fanoutClientDisconnected(const std::string& callsign)
{ {
uint32_t tg = currentClientTg(callsign);
for (auto& kv : m_satellite_con_map) for (auto& kv : m_satellite_con_map)
{ {
if (kv.second != nullptr) if (kv.second != nullptr &&
(tg == 0 || kv.second->filterPassesTg(tg)))
{ {
kv.second->sendClientDisconnected(callsign); kv.second->sendClientDisconnected(callsign);
} }
@@ -3192,9 +3208,11 @@ void Reflector::fanoutClientRx(const std::string& callsign,
Json::StreamWriterBuilder wb; Json::StreamWriterBuilder wb;
wb["indentation"] = ""; wb["indentation"] = "";
std::string s = Json::writeString(wb, rx_json); std::string s = Json::writeString(wb, rx_json);
uint32_t tg = currentClientTg(callsign);
for (auto& kv : m_satellite_con_map) for (auto& kv : m_satellite_con_map)
{ {
if (kv.second != nullptr) if (kv.second != nullptr &&
(tg == 0 || kv.second->filterPassesTg(tg)))
{ {
kv.second->sendClientRx(callsign, s); kv.second->sendClientRx(callsign, s);
} }
@@ -3216,9 +3234,11 @@ void Reflector::fanoutClientStatus(const std::string& callsign,
Json::StreamWriterBuilder wb; Json::StreamWriterBuilder wb;
wb["indentation"] = ""; wb["indentation"] = "";
std::string s = Json::writeString(wb, status_json); std::string s = Json::writeString(wb, status_json);
uint32_t tg = currentClientTg(callsign);
for (auto& kv : m_satellite_con_map) for (auto& kv : m_satellite_con_map)
{ {
if (kv.second != nullptr) if (kv.second != nullptr &&
(tg == 0 || kv.second->filterPassesTg(tg)))
{ {
kv.second->sendClientStatus(callsign, s); kv.second->sendClientStatus(callsign, s);
} }
+5
View File
@@ -283,6 +283,11 @@ class Reflector : public sigc::trackable
// to Redis. Cheap no-op if Redis is not configured. // to Redis. Cheap no-op if Redis is not configured.
void publishClientStatus(ReflectorClient* client); void publishClientStatus(ReflectorClient* client);
// Look up a local client's current talk group by callsign. Returns 0
// if the client is unknown. Used by fanoutClient{Disconnected,Rx,Status}
// to apply per-peer TG filter for events that don't carry an inline TG.
uint32_t currentClientTg(const std::string& callsign) const;
// Per-client liveness fanout to satellite and twin peers. Iterates // Per-client liveness fanout to satellite and twin peers. Iterates
// m_satellite_con_map, m_satellite_client, and m_twin_link. Trunk // m_satellite_con_map, m_satellite_client, and m_twin_link. Trunk
// peers are intentionally NOT fanned out (deferred per design spec). // peers are intentionally NOT fanned out (deferred per design spec).
+5 -1
View File
@@ -80,6 +80,11 @@ class SatelliteLink : public sigc::trackable
return m_partner_nodes; return m_partner_nodes;
} }
// Returns true if the given TG passes this satellite's filter (or if no
// filter is set). Used by Reflector::fanoutClient{Disconnected,Rx,Status}
// which lack an inline TG and must look it up externally.
bool filterPassesTg(uint32_t tg) const;
private: private:
static const unsigned HEARTBEAT_TX_CNT_RESET = 10; static const unsigned HEARTBEAT_TX_CNT_RESET = 10;
static const unsigned HEARTBEAT_RX_CNT_RESET = 15; static const unsigned HEARTBEAT_RX_CNT_RESET = 15;
@@ -115,7 +120,6 @@ class SatelliteLink : public sigc::trackable
void handleMsgPeerClientDisconnected(std::istream& is); void handleMsgPeerClientDisconnected(std::istream& is);
void handleMsgPeerClientRx(std::istream& is); void handleMsgPeerClientRx(std::istream& is);
void handleMsgPeerClientStatus(std::istream& is); void handleMsgPeerClientStatus(std::istream& is);
bool filterPassesTg(uint32_t tg) const;
void sendMsg(const ReflectorMsg& msg); void sendMsg(const ReflectorMsg& msg);
void heartbeatTick(Async::Timer* t); void heartbeatTick(Async::Timer* t);
}; };