build: opt-out WITH_MQTT/WITH_REDIS flags + extend Redis to /status parity

- Add CMake options WITH_MQTT (default ON) and WITH_REDIS (default ON).
  When OFF, the matching .cpp is dropped from the target, the pkg_check
  is skipped, and MqttPublisher.h / RedisStore.h expose no-op stub
  classes so every call site in Reflector.cpp / ReflectorClient.cpp /
  TrunkLink.cpp keeps compiling. svxreflector.cpp's --import-conf-to-redis
  is gated on WITH_REDIS. Lets sysops who don't run MQTT or Redis drop
  libmosquitto-dev / libhiredis-dev from their build environment.
  README.md and docs/INSTALL.md document the flags.

- Fill the gap between /status and Redis with three new event-driven
  keys (all small, all using the existing 60s TTL refresh):
    * live:meta  — mode, version, local_prefix, listen_port, http_port,
      cluster_tgs, satellite-server stats. Written at startup, on
      reloadClusterTgs(), and on satellite connect/disconnect.
    * live📡<sat_id> — per-satellite status blob. Written via
      a new SatelliteLink::statusChanged signal on hello + on every
      talker start/stop. Cleared on disconnect / cleanup.
    * live:trunk:<section>.status — extended trunk hash with the full
      TrunkLink::statusJson() snapshot. Written at startup, on trunk
      state changes, and on config.changed-all reloads.

  A dashboard can now reconstruct the equivalent of GET /status from a
  handful of small Redis keys instead of one ~500 KB blob — idiomatic
  Redis usage, no per-second hot-write churn.

- New Redis tests: live_meta_populated_at_startup,
  live_trunk_carries_status_blob.

All four flag combinations build cleanly. 31 trunk + 10 twin + 16 redis
pass.
This commit is contained in:
Audric committed 2026-04-17 02:52:36 +02:00
1 parent 688a62ec5b
commit bd196d6365
13 files changed
+447 -19

No files matched your search

+13 -2
View File
@@ -107,8 +107,9 @@ reflectors hear the same audio on TG 25 with no extra configuration.
## Build
Requires the same dependencies as SvxReflector: libsigc++, OpenSSL, libjsoncpp,
libpopt, libmosquitto. Optional: libopus, libgsm, libspeex.
Required: libsigc++, OpenSSL, libjsoncpp, libpopt.
Required by default (opt out with the CMake flags below): libmosquitto, libhiredis.
Optional codecs: libopus, libgsm, libspeex.
```bash
cd geureflector
@@ -117,6 +118,16 @@ cmake --build build
# binary at build/bin/svxreflector
```
To skip the MQTT publisher or the Redis backend at compile time (e.g. on a
host without `libmosquitto-dev` or `libhiredis-dev`):
```bash
cmake -S src -B build -DLOCAL_STATE_DIR=/var -DWITH_MQTT=OFF
cmake -S src -B build -DLOCAL_STATE_DIR=/var -DWITH_REDIS=OFF
```
See [`docs/INSTALL.md`](docs/INSTALL.md) for the full step-by-step.
---
## Testing
+40 -2
View File
@@ -11,16 +11,26 @@ plus a few config additions.
- A working SvxReflector installation (any recent version)
- Build tools: `git`, `cmake` (≥ 3.7), `g++` with C++11 support
- Development libraries (same as SvxReflector itself):
- Development libraries:
```bash
# Debian/Ubuntu
# Debian/Ubuntu — required
sudo apt install build-essential cmake libsigc++-2.0-dev libssl-dev \
libjsoncpp-dev libpopt-dev
# Required for MQTT publishing (skip if building with -DWITH_MQTT=OFF)
sudo apt install libmosquitto-dev
# Required for Redis-backed config store (skip if building with -DWITH_REDIS=OFF)
sudo apt install libhiredis-dev
# Optional codec support
sudo apt install libopus-dev libgsm1-dev libspeex-dev
```
The MQTT and Redis backends are enabled by default. If your deployment doesn't
need them, see step 2 below for the opt-out CMake flags — that lets you skip
the matching `*-dev` packages entirely.
---
## 1. Get the source
@@ -41,6 +51,34 @@ cmake --build build
The compiled binary is at `build/bin/svxreflector`.
### Optional: build without MQTT or Redis
The MQTT publisher and Redis-backed config store are enabled by default. To
build without them — for example, on a host where you don't want to install
`libmosquitto-dev` or `libhiredis-dev` — pass the matching CMake flags:
```bash
# build without MQTT support
cmake -S src -B build -DLOCAL_STATE_DIR=/var -DWITH_MQTT=OFF
# build without Redis support
cmake -S src -B build -DLOCAL_STATE_DIR=/var -DWITH_REDIS=OFF
# build without either
cmake -S src -B build -DLOCAL_STATE_DIR=/var -DWITH_MQTT=OFF -DWITH_REDIS=OFF
```
CMake prints which mode it picked (`-- WITH_MQTT=ON: building with libmosquitto
support`) at configure time.
Behavior with the feature disabled:
- **`WITH_MQTT=OFF`** + `[MQTT]` section in your conf → reflector logs a
warning and continues without publishing. Safe to leave `[MQTT]` in place.
- **`WITH_REDIS=OFF`** + `[REDIS]` section in your conf → reflector aborts
startup (since Redis-mode auth would not work). Remove the `[REDIS]` section
before starting.
---
## 3. Stop the running service
+42 -11
View File
@@ -19,27 +19,58 @@ pkg_check_modules (JSONCPP REQUIRED jsoncpp)
include_directories(${JSONCPP_INCLUDE_DIRS})
set(LIBS ${LIBS} ${JSONCPP_LIBRARIES})
# Find mosquitto library (MQTT publishing)
pkg_check_modules(MOSQUITTO REQUIRED libmosquitto)
include_directories(${MOSQUITTO_INCLUDE_DIRS})
set(LIBS ${LIBS} ${MOSQUITTO_LIBRARIES})
# Optional MQTT publishing — pass -DWITH_MQTT=OFF to build without
# libmosquitto. Call sites keep working through a no-op stub class
# defined in MqttPublisher.h.
option(WITH_MQTT "Enable MQTT publishing (requires libmosquitto)" ON)
if(WITH_MQTT)
pkg_check_modules(MOSQUITTO REQUIRED libmosquitto)
include_directories(${MOSQUITTO_INCLUDE_DIRS})
set(LIBS ${LIBS} ${MOSQUITTO_LIBRARIES})
message(STATUS "WITH_MQTT=ON: building with libmosquitto support")
else()
message(STATUS "WITH_MQTT=OFF: building WITHOUT MQTT support; "
"[MQTT] config sections will fail to initialize at startup")
endif()
# Find hiredis library (Redis C client)
pkg_check_modules(HIREDIS REQUIRED hiredis)
include_directories(${HIREDIS_INCLUDE_DIRS})
set(LIBS ${LIBS} ${HIREDIS_LIBRARIES})
# Optional Redis-backed config store — pass -DWITH_REDIS=OFF to build
# without libhiredis. Call sites keep working through a no-op stub class
# defined in RedisStore.h.
option(WITH_REDIS "Enable Redis-backed config store (requires libhiredis)" ON)
if(WITH_REDIS)
pkg_check_modules(HIREDIS REQUIRED hiredis)
include_directories(${HIREDIS_INCLUDE_DIRS})
set(LIBS ${LIBS} ${HIREDIS_LIBRARIES})
message(STATUS "WITH_REDIS=ON: building with libhiredis support")
else()
message(STATUS "WITH_REDIS=OFF: building WITHOUT Redis support; "
"[REDIS] config sections will cause startup to abort")
endif()
# Add project libraries
set(LIBS asynccpp asyncaudio asynccore svxmisc ${LIBS})
# Build the executable
add_executable(svxreflector
set(REFLECTOR_SOURCES
svxreflector.cpp Reflector.cpp ReflectorClient.cpp TGHandler.cpp TrunkLink.cpp
TwinLink.cpp
SatelliteLink.cpp SatelliteClient.cpp MqttPublisher.cpp RedisStore.cpp
RedisAsyncAdapter.cpp RedisLiveQueue.cpp
SatelliteLink.cpp SatelliteClient.cpp
)
if(WITH_MQTT)
list(APPEND REFLECTOR_SOURCES MqttPublisher.cpp)
endif()
if(WITH_REDIS)
list(APPEND REFLECTOR_SOURCES RedisStore.cpp RedisAsyncAdapter.cpp RedisLiveQueue.cpp)
endif()
add_executable(svxreflector ${REFLECTOR_SOURCES})
target_link_libraries(svxreflector ${LIBS})
if(WITH_MQTT)
target_compile_definitions(svxreflector PRIVATE WITH_MQTT)
endif()
if(WITH_REDIS)
target_compile_definitions(svxreflector PRIVATE WITH_REDIS)
endif()
set_target_properties(svxreflector PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${RUNTIME_OUTPUT_DIRECTORY}
)
+35 -2
View File
@@ -7,10 +7,12 @@
#include <json/json.h>
#include "ReflectorMsg.h"
struct mosquitto;
namespace Async { class Config; }
#ifdef WITH_MQTT
struct mosquitto;
class MqttPublisher
{
public:
@@ -67,4 +69,35 @@ class MqttPublisher
}; /* class MqttPublisher */
#else /* !WITH_MQTT */
// Build-time no-op stub: lets the rest of the codebase compile and link
// when libmosquitto is unavailable. initialize() returns false so
// Reflector::initialize logs the existing "MQTT publisher failed to
// initialize, continuing without MQTT" warning and proceeds with
// m_mqtt = nullptr; every other call site is already null-guarded.
class MqttPublisher
{
public:
MqttPublisher(Async::Config&) {}
bool initialize(void) { return false; }
void shutdown(void) {}
void onTalkerStart(uint32_t, const std::string&, bool) {}
void onTalkerStop(uint32_t, const std::string&, bool) {}
void onClientConnected(const std::string&, uint32_t,
const std::string&) {}
void onClientDisconnected(const std::string&) {}
void onTrunkUp(const std::string&, const std::string&,
const std::string&, uint16_t) {}
void onTrunkDown(const std::string&, const std::string&) {}
void onRxUpdate(const std::string&, const Json::Value&) {}
void publishFullStatus(const Json::Value&) {}
void publishLocalNodes(
const std::vector<MsgTrunkNodeList::NodeEntry>&) {}
void publishPeerNodes(const std::string&,
const std::vector<MsgTrunkNodeList::NodeEntry>&) {}
};
#endif /* WITH_MQTT */
#endif /* MQTT_PUBLISHER_INCLUDED */
+52
View File
@@ -329,6 +329,58 @@ void RedisStore::pushClientStatus(const std::string& callsign,
m_live_queue->push(std::move(op));
}
void RedisStore::pushMeta(
const std::vector<std::pair<std::string,std::string>>& fields) {
if (!m_live_queue || fields.empty()) return;
RedisLiveQueue::Op op;
op.op = RedisLiveQueue::OpType::HSET;
op.key = keyFor("live:meta");
m_live_keys.insert(op.key);
op.fields = fields;
op.fields.emplace_back("updated_at", std::to_string(std::time(nullptr)));
op.ttl_s = 60;
m_live_queue->push(std::move(op));
}
void RedisStore::pushSatelliteStatus(const std::string& sat_id,
const std::string& status_json) {
if (!m_live_queue || sat_id.empty()) return;
RedisLiveQueue::Op op;
op.op = RedisLiveQueue::OpType::HSET;
op.key = keyFor("live:satellite:" + sat_id);
m_live_keys.insert(op.key);
op.fields = {
{"status", status_json},
{"updated_at", std::to_string(std::time(nullptr))}
};
op.ttl_s = 60;
m_live_queue->push(std::move(op));
}
void RedisStore::clearSatelliteStatus(const std::string& sat_id) {
if (!m_live_queue || sat_id.empty()) return;
RedisLiveQueue::Op op;
op.op = RedisLiveQueue::OpType::DEL;
op.key = keyFor("live:satellite:" + sat_id);
m_live_keys.erase(op.key);
m_live_queue->push(std::move(op));
}
void RedisStore::pushTrunkStatus(const std::string& section,
const std::string& status_json) {
if (!m_live_queue || section.empty()) return;
RedisLiveQueue::Op op;
op.op = RedisLiveQueue::OpType::HSET;
op.key = keyFor("live:trunk:" + section);
m_live_keys.insert(op.key);
op.fields = {
{"status", status_json},
{"updated_at", std::to_string(std::time(nullptr))}
};
op.ttl_s = 60;
m_live_queue->push(std::move(op));
}
void RedisStore::pushPeerNode(const std::string& peer_id,
const std::string& callsign,
uint32_t tg,
+98 -1
View File
@@ -8,9 +8,12 @@
#include <set>
#include <cstdint>
namespace Async { class Config; class Timer; }
#ifdef WITH_REDIS
struct redisContext;
struct redisAsyncContext;
namespace Async { class Config; class Timer; }
class RedisAsyncAdapter;
class RedisLiveQueue;
@@ -83,6 +86,21 @@ class RedisStore : public sigc::trackable
// field of the existing live:client:<callsign> hash.
void pushClientStatus(const std::string& callsign,
const std::string& status_json);
// Reflector-wide meta: mode, version, prefixes, listen ports, cluster
// TGs, satellite-server stats. Stored under live:meta as a hash;
// written event-driven (startup + on cfg/satellite-count changes).
void pushMeta(const std::vector<std::pair<std::string,std::string>>& fields);
// Per-satellite status snapshot. Stored under live:satellite:<sat_id>
// as a hash with a `status` JSON field. Written when the satellite
// hello is received and on per-satellite events; cleared on disconnect.
void pushSatelliteStatus(const std::string& sat_id,
const std::string& status_json);
void clearSatelliteStatus(const std::string& sat_id);
// Extended per-trunk status (full TrunkLink::statusJson snapshot).
// Stored as the `status` field on the existing live:trunk:<section>
// hash. Written on trunk state-change events.
void pushTrunkStatus(const std::string& section,
const std::string& status_json);
void pushLiveTrunk(const std::string& section,
const std::string& state,
const std::string& peer_id);
@@ -128,4 +146,83 @@ class RedisStore : public sigc::trackable
std::string channelName(void) const;
};
#else /* !WITH_REDIS */
// Build-time no-op stub: lets the rest of the codebase compile and link
// when libhiredis is unavailable. connect() returns false so
// Reflector::initialize aborts startup if [REDIS] is configured —
// matching the existing "Redis is unreachable" path. The load*
// accessors return empty containers; the live-state pushes are no-ops.
class RedisStore : public sigc::trackable
{
public:
struct Config
{
std::string host;
uint16_t port = 6379;
std::string password;
int db = 0;
std::string key_prefix;
std::string unix_socket;
bool tls_enabled = false;
std::string tls_ca_cert;
std::string tls_client_cert;
std::string tls_client_key;
};
struct TrunkPeerConfig
{
std::string host;
std::string port;
std::string secret;
std::string remote_prefix;
std::string peer_id;
};
explicit RedisStore(const Config&) {}
bool connect(void) { return false; }
bool isReady(void) const { return false; }
sigc::signal<void, std::string> configChanged;
std::string lookupUserKey(const std::string&) { return {}; }
std::map<std::string, std::string> loadAllUsers(void) { return {}; }
bool isUserEnabled(const std::string&) { return false; }
std::set<uint32_t> loadClusterTgs(void) { return {}; }
std::string loadTrunkFilter(const std::string&,
const std::string&) { return {}; }
std::map<uint32_t, uint32_t> loadTrunkTgMap(const std::string&) {
return {};
}
std::map<std::string, TrunkPeerConfig> loadTrunkPeers(void) {
return {};
}
void publishConfigChanged(const std::string&) {}
void pushLiveTalker(uint32_t, const std::string&,
const std::string&) {}
void clearLiveTalker(uint32_t) {}
void pushLiveClient(const std::string&, const std::string&,
const std::string&, uint32_t) {}
void clearLiveClient(const std::string&) {}
void pushClientStatus(const std::string&, const std::string&) {}
void pushMeta(const std::vector<std::pair<std::string,std::string>>&) {}
void pushSatelliteStatus(const std::string&, const std::string&) {}
void clearSatelliteStatus(const std::string&) {}
void pushTrunkStatus(const std::string&, const std::string&) {}
void pushLiveTrunk(const std::string&, const std::string&,
const std::string&) {}
void pushPeerNode(const std::string&, const std::string&, uint32_t,
float, float, const std::string&) {}
void clearPeerNode(const std::string&, const std::string&) {}
uint64_t droppedLiveWrites(void) const { return 0; }
size_t liveQueueSize(void) const { return 0; }
};
#endif /* WITH_REDIS */
#endif /* REDIS_STORE_INCLUDED */
+94 -1
View File
@@ -526,6 +526,7 @@ bool Reflector::initialize(Async::Config &cfg)
return false;
}
// Satellites don't participate in the trunk mesh
publishMetaToRedis();
return true;
}
@@ -547,6 +548,9 @@ bool Reflector::initialize(Async::Config &cfg)
initTwinServer();
initSatelliteServer();
publishMetaToRedis();
for (auto* link : m_trunk_links) publishTrunkStatusToRedis(link);
return true;
} /* Reflector::initialize */
@@ -2618,7 +2622,10 @@ void Reflector::satelliteConnected(Async::FramedTcpConnection* con)
auto* link = new SatelliteLink(this, con, m_satellite_secret);
link->linkFailed.connect(
sigc::mem_fun(*this, &Reflector::onSatelliteLinkFailed));
link->statusChanged.connect(
sigc::mem_fun(*this, &Reflector::publishSatelliteStatusToRedis));
m_satellite_con_map[con] = link;
publishMetaToRedis();
} /* Reflector::satelliteConnected */
@@ -2630,8 +2637,12 @@ void Reflector::satelliteDisconnected(Async::FramedTcpConnection* con,
{
std::cout << "SAT: Satellite '" << it->second->satelliteId()
<< "' disconnected" << std::endl;
if (m_redis != nullptr) {
m_redis->clearSatelliteStatus(it->second->satelliteId());
}
delete it->second;
m_satellite_con_map.erase(it);
publishMetaToRedis();
}
} /* Reflector::satelliteDisconnected */
@@ -2665,9 +2676,13 @@ void Reflector::processSatelliteCleanup(Async::Timer* t)
std::cout << "SAT: Cleaning up timed-out satellite '"
<< link->satelliteId() << "'" << std::endl;
if (m_redis != nullptr) {
m_redis->clearSatelliteStatus(link->satelliteId());
}
delete link;
m_satellite_con_map.erase(con);
con->disconnect();
publishMetaToRedis();
}
} /* Reflector::processSatelliteCleanup */
@@ -2829,6 +2844,7 @@ void Reflector::reloadClusterTgs(void)
}
std::cout << std::endl;
}
publishMetaToRedis();
}
@@ -2926,7 +2942,10 @@ void Reflector::onRedisConfigChanged(std::string scope)
if (section.empty()) {
// Full sweep — reload filters on every existing link; don't try
// to add/remove here (startup already did that).
for (auto* link : m_trunk_links) link->reloadConfig();
for (auto* link : m_trunk_links) {
link->reloadConfig();
publishTrunkStatusToRedis(link);
}
} else {
// Per-section: check Redis for peer presence vs local state.
auto peers = m_redis ? m_redis->loadTrunkPeers()
@@ -2979,6 +2998,76 @@ void Reflector::publishClientStatus(ReflectorClient* client)
} /* Reflector::publishClientStatus */
void Reflector::publishMetaToRedis(void)
{
if (m_redis == nullptr) return;
std::vector<std::pair<std::string,std::string>> fields;
fields.emplace_back("mode", m_is_satellite ? "satellite" : "reflector");
fields.emplace_back("version", SVXREFLECTOR_VERSION);
std::string s;
if (m_cfg->getValue("GLOBAL", "LOCAL_PREFIX", s)) {
fields.emplace_back("local_prefix", s);
}
std::string listen_port("5300");
m_cfg->getValue("GLOBAL", "LISTEN_PORT", listen_port);
fields.emplace_back("listen_port", listen_port);
std::string http_port;
if (m_cfg->getValue("GLOBAL", "HTTP_SRV_PORT", http_port)) {
fields.emplace_back("http_port", http_port);
}
std::string cluster_csv;
for (uint32_t tg : m_cluster_tgs) {
if (!cluster_csv.empty()) cluster_csv += ",";
cluster_csv += std::to_string(tg);
}
fields.emplace_back("cluster_tgs", cluster_csv);
if (m_is_satellite) {
std::string sat_of, sat_port_str, sat_id;
m_cfg->getValue("GLOBAL", "SATELLITE_OF", sat_of);
m_cfg->getValue("GLOBAL", "SATELLITE_PORT", sat_port_str);
m_cfg->getValue("GLOBAL", "SATELLITE_ID", sat_id);
if (!sat_of.empty()) fields.emplace_back("satellite_parent_host", sat_of);
if (!sat_port_str.empty()) fields.emplace_back("satellite_parent_port", sat_port_str);
if (!sat_id.empty()) fields.emplace_back("satellite_id", sat_id);
} else {
std::string sat_listen_port;
if (m_cfg->getValue("SATELLITE", "LISTEN_PORT", sat_listen_port)) {
fields.emplace_back("satellite_server_listen_port", sat_listen_port);
fields.emplace_back("satellite_server_connected_count",
std::to_string(m_satellite_con_map.size()));
}
}
m_redis->pushMeta(fields);
} /* Reflector::publishMetaToRedis */
void Reflector::publishSatelliteStatusToRedis(SatelliteLink* link)
{
if (m_redis == nullptr || link == nullptr) return;
const std::string& sat_id = link->satelliteId();
if (sat_id.empty()) return; // hello not yet received
Json::StreamWriterBuilder wb;
wb["indentation"] = "";
m_redis->pushSatelliteStatus(sat_id,
Json::writeString(wb, link->statusJson()));
} /* Reflector::publishSatelliteStatusToRedis */
void Reflector::publishTrunkStatusToRedis(TrunkLink* link)
{
if (m_redis == nullptr || link == nullptr) return;
Json::StreamWriterBuilder wb;
wb["indentation"] = "";
m_redis->pushTrunkStatus(link->section(),
Json::writeString(wb, link->statusJson()));
} /* Reflector::publishTrunkStatusToRedis */
void Reflector::onClientAuthenticated(const std::string& callsign,
uint32_t tg, const std::string& ip)
{
@@ -3094,6 +3183,10 @@ void Reflector::onTrunkStateChanged(const std::string& section,
if (m_redis != nullptr)
{
m_redis->pushLiveTrunk(section, up ? "up" : "down", peer_id);
for (auto* l : m_trunk_links)
{
if (l->section() == section) { publishTrunkStatusToRedis(l); break; }
}
}
// When a trunk link is fully down (both directions), clear any node
+9
View File
@@ -263,6 +263,15 @@ class Reflector : public sigc::trackable
// Push the rich per-client status blob (rx, monitoredTGs, qth, ...)
// to Redis. Cheap no-op if Redis is not configured.
void publishClientStatus(ReflectorClient* client);
// Reflector-wide live:meta hash (mode, version, prefixes, ports,
// cluster TGs, satellite-server stats). Event-driven write.
void publishMetaToRedis(void);
// Per-satellite live:satellite:<id> snapshot. Triggered on satellite
// hello + active-TG changes.
void publishSatelliteStatusToRedis(SatelliteLink* link);
// Per-trunk live:trunk:<section> `status` field with full
// TrunkLink::statusJson(). Triggered on trunk state-change events.
void publishTrunkStatusToRedis(TrunkLink* link);
void onClientAuthenticated(const std::string& callsign, uint32_t tg,
const std::string& ip);
void notifyExternalTrunkTalkerStart(uint32_t tg,
+6
View File
@@ -189,6 +189,8 @@ void SatelliteLink::handleMsgTrunkHello(std::istream& is)
// firewalls / NAT devices that drop idle TCP sessions.
sendMsg(MsgTrunkHello("PARENT", "", 0, m_secret,
MsgTrunkHello::ROLE_PEER));
statusChanged(this);
} /* SatelliteLink::handleMsgTrunkHello */
@@ -207,6 +209,8 @@ void SatelliteLink::handleMsgTrunkTalkerStart(std::istream& is)
// Forward to trunk peers
m_reflector->forwardSatelliteAudioToTrunks(tg, msg.callsign());
statusChanged(this);
} /* SatelliteLink::handleMsgTrunkTalkerStart */
@@ -221,6 +225,8 @@ void SatelliteLink::handleMsgTrunkTalkerStop(std::istream& is)
// Forward stop to trunk peers
m_reflector->forwardSatelliteStopToTrunks(tg);
statusChanged(this);
} /* SatelliteLink::handleMsgTrunkTalkerStop */
+8
View File
@@ -37,6 +37,14 @@ class SatelliteLink : public sigc::trackable
*/
sigc::signal<void, SatelliteLink*> linkFailed;
/**
* Emitted whenever the per-satellite status (id, authentication,
* active TGs) changes. Reflector uses this to refresh the satellite's
* Redis snapshot. Carries `this`; ignore if satelliteId() is empty
* (hello not yet received).
*/
sigc::signal<void, SatelliteLink*> statusChanged;
// Events from local clients or trunk peers → send down to satellite
void onParentTalkerStart(uint32_t tg, const std::string& callsign);
void onParentTalkerStop(uint32_t tg);
+8
View File
@@ -77,8 +77,10 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#include "version/SVXREFLECTOR.h"
#include "Reflector.h"
#ifdef WITH_REDIS
#include <hiredis/hiredis.h>
#include "RedisStore.h"
#endif
/****************************************************************************
@@ -146,6 +148,7 @@ namespace {
LogWriter logwriter;
};
#ifdef WITH_REDIS
static int import_to_redis = 0;
static int dry_run = 0;
@@ -350,6 +353,7 @@ static bool runImportConfToRedis(Async::Config& cfg, bool dry_run)
if (ctx) redisFree(ctx);
return true;
}
#endif /* WITH_REDIS */
/****************************************************************************
@@ -595,9 +599,11 @@ int main(int argc, const char *argv[])
stdin_watch->activity.connect(sigc::ptr_fun(&stdinHandler));
}
#ifdef WITH_REDIS
if (import_to_redis) {
return runImportConfToRedis(cfg, dry_run != 0) ? 0 : 1;
}
#endif
Reflector ref;
if (ref.initialize(cfg))
@@ -664,10 +670,12 @@ static void parse_arguments(int argc, const char **argv)
"Start " PROGRAM_NAME " as a daemon", NULL},
{"version", 0, POPT_ARG_NONE, &print_version, 0,
"Print the application version string", NULL},
#ifdef WITH_REDIS
{"import-conf-to-redis", 0, POPT_ARG_NONE, &import_to_redis, 0,
"Import [USERS]/[PASSWORDS] from .conf into Redis, then exit", NULL},
{"dry-run", 0, POPT_ARG_NONE, &dry_run, 0,
"With --import-conf-to-redis: print commands without executing", NULL},
#endif
{NULL, 0, 0, NULL, 0}
};
int err;
+2
View File
@@ -253,6 +253,8 @@ Each test writes directly to Redis via `redis-cli` inside the container, publish
| 5 | `live:client` appears on auth | On V2 authentication, `live:client:<callsign>` hash is populated with `connected_at`, `ip`, `tg`, `codecs` |
| 6 | `live:client` disappears on disconnect | After forceful TCP close the hash is removed within ~5 s |
| 6b | `live:client` rich status blob | After the client sends `MsgNodeInfo`, `live:client:<callsign>.status` holds the full per-client JSON (qth, rx params, monitoredTGs) and `updated_at` |
| 6c | `live:meta` populated | `live:meta` hash carries `mode`, `version`, `local_prefix`, `listen_port`, `cluster_tgs`, `updated_at` after a `config.changed all` republish |
| 6d | `live:trunk` carries status blob | `live:trunk:<section>.status` is a serialized `TrunkLink::statusJson()` (host, port, connected, local/remote prefix, active_talkers, muted) |
| 7 | Outage + resync | Stopping Redis keeps existing clients connected; on restart the reflector logs `config.changed: all` and accepts newly-written users |
| 8 | `--import-conf-to-redis` idempotent | Running the importer twice against the same `.conf` produces identical keyspace dumps |
| 9 | Peer node list populates + diffs | Inbound `MsgTrunkNodeList` creates `live:peer_node:<section>:<callsign>` hashes; a shrunk follow-up list DELs dropped callsigns and updates mutated fields (e.g. `tg`) |
+40
View File
@@ -297,6 +297,46 @@ class RedisLiveStateTest(unittest.TestCase):
# Drain queue + Redis publish should take <100ms. Give more for slack.
self._wait_for_hash(k("live:client:N0TEST"), present=False, timeout=5.0)
def test_live_meta_populated_at_startup(self):
"""live:meta hash carries reflector-wide info (mode, version, ports,
cluster_tgs) so dashboards can reconstruct the /status header
without an HTTP query."""
# setUp() flushdb wiped the startup-written keys; trigger a
# republish via the existing config.changed pubsub.
publish("all")
time.sleep(0.5)
raw = self._wait_for_hash(k("live:meta"), present=True, timeout=5.0)
fields = raw.splitlines()
m = dict(zip(fields[0::2], fields[1::2]))
self.assertEqual(m.get("mode"), "reflector")
self.assertIn("version", m)
self.assertIn("listen_port", m)
self.assertIn("local_prefix", m)
# cluster_tgs is always written (may be empty CSV)
self.assertIn("cluster_tgs", m)
self.assertIn("updated_at", m)
def test_live_trunk_carries_status_blob(self):
"""live:trunk:<section> includes a `status` field with the full
TrunkLink::statusJson() snapshot (host, port, connected flags,
local/remote prefixes, active_talkers, muted)."""
import json as _json
publish("all")
time.sleep(0.5)
raw = self._wait_for_hash(k("live:trunk:TRUNK_TEST"),
present=True, timeout=5.0)
fields = raw.splitlines()
m = dict(zip(fields[0::2], fields[1::2]))
self.assertIn("status", m)
status = _json.loads(m["status"])
# Sanity: statusJson contract from TrunkLink.cpp
self.assertIn("host", status)
self.assertIn("port", status)
self.assertIn("connected", status)
self.assertIn("local_prefix", status)
self.assertIn("remote_prefix", status)
self.assertIn("active_talkers", status)
class RedisOutageTest(unittest.TestCase):
"""Verify reflector tolerates Redis going down and resyncs on resume."""