Remove Redis mute plumbing; expose mute list in /status JSON

Dashboard will write mutes directly to the PTY rather than Redis; the
Redis addTrunkMute/removeTrunkMute/loadTrunkMutes methods and the PTY
write-through were unused. Mute state is now reflected in the /status
JSON as a per-trunk 'muted' array so operators and dashboards can see
current state without polling Redis.
This commit is contained in:
Audric committed 2026-04-15 13:45:00 +02:00
1 parent aed5566956
commit bc412e1847
6 files changed
+10 -98

No files matched your search

-32
View File
@@ -194,38 +194,6 @@ std::map<uint32_t, uint32_t> RedisStore::loadTrunkTgMap(const std::string& secti
return out; return out;
} }
std::set<std::string> RedisStore::loadTrunkMutes(const std::string& section) {
std::set<std::string> out;
if (!m_sync) return out;
std::string k = keyFor("trunk:" + section + ":mutes");
redisReply* r = (redisReply*)redisCommand(m_sync, "SMEMBERS %s", k.c_str());
if (r && r->type == REDIS_REPLY_ARRAY) {
for (size_t i = 0; i < r->elements; ++i) {
if (r->element[i]->type == REDIS_REPLY_STRING) {
out.emplace(r->element[i]->str, r->element[i]->len);
}
}
}
if (r) freeReplyObject(r);
return out;
}
void RedisStore::addTrunkMute(const std::string& section, const std::string& callsign) {
if (!m_sync) return;
std::string k = keyFor("trunk:" + section + ":mutes");
redisReply* r = (redisReply*)redisCommand(m_sync, "SADD %s %s",
k.c_str(), callsign.c_str());
if (r) freeReplyObject(r);
}
void RedisStore::removeTrunkMute(const std::string& section, const std::string& callsign) {
if (!m_sync) return;
std::string k = keyFor("trunk:" + section + ":mutes");
redisReply* r = (redisReply*)redisCommand(m_sync, "SREM %s %s",
k.c_str(), callsign.c_str());
if (r) freeReplyObject(r);
}
void RedisStore::publishConfigChanged(const std::string& scope) { void RedisStore::publishConfigChanged(const std::string& scope) {
if (!m_sync) return; if (!m_sync) return;
std::string ch = channelName(); std::string ch = channelName();
-6
View File
@@ -56,12 +56,6 @@ class RedisStore : public sigc::trackable
std::string loadTrunkFilter(const std::string& section, std::string loadTrunkFilter(const std::string& section,
const std::string& field); // "blacklist"|"allow" const std::string& field); // "blacklist"|"allow"
std::map<uint32_t, uint32_t> loadTrunkTgMap(const std::string& section); std::map<uint32_t, uint32_t> loadTrunkTgMap(const std::string& section);
std::set<std::string> loadTrunkMutes(const std::string& section);
// Mute set ops (sync, used by PTY persistence).
void addTrunkMute(const std::string& section, const std::string& callsign);
void removeTrunkMute(const std::string& section, const std::string& callsign);
// Publish a config.changed scope token (sync). // Publish a config.changed scope token (sync).
void publishConfigChanged(const std::string& scope); void publishConfigChanged(const std::string& scope);
-6
View File
@@ -2036,12 +2036,6 @@ void Reflector::ctrlPtyDataReceived(const void *buf, size_t count)
if (subcmd == "MUTE") link->muteCallsign(callsign); if (subcmd == "MUTE") link->muteCallsign(callsign);
else link->unmuteCallsign(callsign); else link->unmuteCallsign(callsign);
if (m_redis) {
if (subcmd == "MUTE") m_redis->addTrunkMute(section, callsign);
else m_redis->removeTrunkMute(section, callsign);
m_redis->publishConfigChanged("trunk:" + section);
}
m_cmd_pty->write(section + ": " + subcmd + " " + callsign + "\n"); m_cmd_pty->write(section + ": " + subcmd + " " + callsign + "\n");
} }
else if (subcmd == "RELOAD") else if (subcmd == "RELOAD")
+6 -7
View File
@@ -384,6 +384,10 @@ Json::Value TrunkLink::statusJson(void) const
} }
obj["active_talkers"] = talkers; obj["active_talkers"] = talkers;
Json::Value muted_arr(Json::arrayValue);
for (const auto& cs : m_muted_callsigns) muted_arr.append(cs);
obj["muted"] = muted_arr;
return obj; return obj;
} /* TrunkLink::statusJson */ } /* TrunkLink::statusJson */
@@ -1149,18 +1153,13 @@ void TrunkLink::reloadConfig(void)
} }
} }
if (rs) {
m_muted_callsigns = rs->loadTrunkMutes(m_section);
}
cout << m_section << ": Reloaded filters" cout << m_section << ": Reloaded filters"
<< (m_blacklist_filter.empty() ? "" : << (m_blacklist_filter.empty() ? "" :
" blacklist=" + m_blacklist_filter.toString()) " blacklist=" + m_blacklist_filter.toString())
<< (m_allow_filter.empty() ? "" : << (m_allow_filter.empty() ? "" :
" allow=" + m_allow_filter.toString()) " allow=" + m_allow_filter.toString())
<< " tg_map_entries=" << m_tg_map_in.size(); << " tg_map_entries=" << m_tg_map_in.size()
if (rs) cout << " mutes=" << m_muted_callsigns.size(); << endl;
cout << endl;
} /* TrunkLink::reloadConfig */ } /* TrunkLink::reloadConfig */
+4
View File
@@ -154,6 +154,10 @@ class TrunkLink : public sigc::trackable
{ {
return m_muted_callsigns.count(callsign) > 0; return m_muted_callsigns.count(callsign) > 0;
} }
const std::set<std::string>& mutedCallsigns(void) const
{
return m_muted_callsigns;
}
// Re-parse BLACKLIST_TGS, ALLOW_TGS and TG_MAP from current config // Re-parse BLACKLIST_TGS, ALLOW_TGS and TG_MAP from current config
void reloadConfig(void); void reloadConfig(void);
// One-line summary for TRUNK STATUS // One-line summary for TRUNK STATUS
-47
View File
@@ -174,53 +174,6 @@ class RedisTrunkFilterTest(unittest.TestCase):
self.assertIn("TRUNK_TEST", line) self.assertIn("TRUNK_TEST", line)
class RedisPtyMuteTest(unittest.TestCase):
SECTION = "TRUNK_TEST"
def setUp(self):
flushdb()
def _pty_send(self, command: str) -> None:
"""Write a command line to the reflector's PTY inside the
container. The existing COMMAND_PTY config lives at
/dev/shm/reflector_ctrl."""
subprocess.run([
"docker", "compose", "-f", "docker-compose.redis.yml",
"exec", "-T", R1_SVC,
"bash", "-c",
f"printf '{command}\\n' > /dev/shm/reflector_ctrl"
], check=True,
cwd=os.path.dirname(os.path.abspath(__file__)))
def _wait_for_members(self, key: str, expected_cs: str, present: bool,
timeout: float = 3.0) -> None:
deadline = time.time() + timeout
last = ""
while time.time() < deadline:
last = redis_cli("SMEMBERS", key)
members = set(filter(None, last.splitlines()))
if present and expected_cs in members:
return
if (not present) and expected_cs not in members:
return
time.sleep(0.1)
self.fail(
f"Timed out waiting for {expected_cs} "
f"{'in' if present else 'absent from'} {key}. "
f"Last SMEMBERS: {last!r}")
def test_pty_mute_then_unmute_persists_to_redis(self):
key = k(f"trunk:{self.SECTION}:mutes")
# Baseline: empty
self.assertEqual(redis_cli("SMEMBERS", key), "")
self._pty_send(f"TRUNK MUTE {self.SECTION} SM0XYZ")
self._wait_for_members(key, "SM0XYZ", present=True)
self._pty_send(f"TRUNK UNMUTE {self.SECTION} SM0XYZ")
self._wait_for_members(key, "SM0XYZ", present=False)
class RedisLiveStateTest(unittest.TestCase): class RedisLiveStateTest(unittest.TestCase):
"""Verify live:client:<callsign> hashes appear/disappear as V2 clients """Verify live:client:<callsign> hashes appear/disappear as V2 clients
connect and disconnect. Talker and trunk live-state are not covered here connect and disconnect. Talker and trunk live-state are not covered here