From bc412e1847af8c5aa8cd8a0465128e176df6d7c1 Mon Sep 17 00:00:00 2001 From: Audric Date: Wed, 15 Apr 2026 13:45:00 +0200 Subject: [PATCH] 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. --- src/svxlink/reflector/RedisStore.cpp | 32 ------------------- src/svxlink/reflector/RedisStore.h | 6 ---- src/svxlink/reflector/Reflector.cpp | 6 ---- src/svxlink/reflector/TrunkLink.cpp | 13 ++++---- src/svxlink/reflector/TrunkLink.h | 4 +++ tests/test_redis.py | 47 ---------------------------- 6 files changed, 10 insertions(+), 98 deletions(-) diff --git a/src/svxlink/reflector/RedisStore.cpp b/src/svxlink/reflector/RedisStore.cpp index 3c854cb..eed8d23 100644 --- a/src/svxlink/reflector/RedisStore.cpp +++ b/src/svxlink/reflector/RedisStore.cpp @@ -194,38 +194,6 @@ std::map RedisStore::loadTrunkTgMap(const std::string& secti return out; } -std::set RedisStore::loadTrunkMutes(const std::string& section) { - std::set 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) { if (!m_sync) return; std::string ch = channelName(); diff --git a/src/svxlink/reflector/RedisStore.h b/src/svxlink/reflector/RedisStore.h index 655668a..67067ae 100644 --- a/src/svxlink/reflector/RedisStore.h +++ b/src/svxlink/reflector/RedisStore.h @@ -56,12 +56,6 @@ class RedisStore : public sigc::trackable std::string loadTrunkFilter(const std::string& section, const std::string& field); // "blacklist"|"allow" std::map loadTrunkTgMap(const std::string& section); - std::set 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). void publishConfigChanged(const std::string& scope); diff --git a/src/svxlink/reflector/Reflector.cpp b/src/svxlink/reflector/Reflector.cpp index 28ef084..3643c5b 100644 --- a/src/svxlink/reflector/Reflector.cpp +++ b/src/svxlink/reflector/Reflector.cpp @@ -2036,12 +2036,6 @@ void Reflector::ctrlPtyDataReceived(const void *buf, size_t count) if (subcmd == "MUTE") link->muteCallsign(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"); } else if (subcmd == "RELOAD") diff --git a/src/svxlink/reflector/TrunkLink.cpp b/src/svxlink/reflector/TrunkLink.cpp index 206ca6f..402d50f 100644 --- a/src/svxlink/reflector/TrunkLink.cpp +++ b/src/svxlink/reflector/TrunkLink.cpp @@ -384,6 +384,10 @@ Json::Value TrunkLink::statusJson(void) const } 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; } /* TrunkLink::statusJson */ @@ -1149,18 +1153,13 @@ void TrunkLink::reloadConfig(void) } } - if (rs) { - m_muted_callsigns = rs->loadTrunkMutes(m_section); - } - cout << m_section << ": Reloaded filters" << (m_blacklist_filter.empty() ? "" : " blacklist=" + m_blacklist_filter.toString()) << (m_allow_filter.empty() ? "" : " allow=" + m_allow_filter.toString()) - << " tg_map_entries=" << m_tg_map_in.size(); - if (rs) cout << " mutes=" << m_muted_callsigns.size(); - cout << endl; + << " tg_map_entries=" << m_tg_map_in.size() + << endl; } /* TrunkLink::reloadConfig */ diff --git a/src/svxlink/reflector/TrunkLink.h b/src/svxlink/reflector/TrunkLink.h index 876639f..87f7bb3 100644 --- a/src/svxlink/reflector/TrunkLink.h +++ b/src/svxlink/reflector/TrunkLink.h @@ -154,6 +154,10 @@ class TrunkLink : public sigc::trackable { return m_muted_callsigns.count(callsign) > 0; } + const std::set& mutedCallsigns(void) const + { + return m_muted_callsigns; + } // Re-parse BLACKLIST_TGS, ALLOW_TGS and TG_MAP from current config void reloadConfig(void); // One-line summary for TRUNK STATUS diff --git a/tests/test_redis.py b/tests/test_redis.py index c68cf6f..1ba0fdc 100755 --- a/tests/test_redis.py +++ b/tests/test_redis.py @@ -174,53 +174,6 @@ class RedisTrunkFilterTest(unittest.TestCase): 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): """Verify live:client: hashes appear/disappear as V2 clients connect and disconnect. Talker and trunk live-state are not covered here