publishing: MQTT works in satellite mode + Redis publishes per-client status blob

- Move MQTT init above the satellite early-return in Reflector::initialize so
  satellite-mode reflectors publish to MQTT (client connect/disconnect, talker
  events, full status, etc.) just like full reflectors.
- Add reflector-sat (SATELLITE_OF=reflector-a) to the default test compose so
  satellite mode is exercised end-to-end. New test_31 verifies MQTT
  client-connect/disconnect events under the satellite's own topic prefix.
- Add RedisStore::pushClientStatus and Reflector::publishClientStatus to write
  the per-client status JSON (qth, rx siglev/sql_open/enabled/active,
  monitoredTGs, selected TG, ...) to live:client:<callsign>.status. Hooked
  from publishRxUpdate, handleNodeInfo, setMonitoredTGs, and setTg.
- New Redis test_live_client_status_blob sends a synthetic MsgNodeInfoV2 with
  qth+rx and asserts the parsed blob contains the expected fields.

31/31 trunk + 10/10 twin + 14/14 redis pass.
This commit is contained in:
Audric committed 2026-04-17 01:05:37 +02:00
1 parent 6b7a1f0306
commit 688a62ec5b
10 files changed
+299 -33

No files matched your search

+15
View File
@@ -314,6 +314,21 @@ void RedisStore::clearLiveClient(const std::string& callsign) {
m_live_queue->push(std::move(op));
}
void RedisStore::pushClientStatus(const std::string& callsign,
const std::string& status_json) {
if (!m_live_queue) return;
RedisLiveQueue::Op op;
op.op = RedisLiveQueue::OpType::HSET;
op.key = keyFor("live:client:" + callsign);
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,
+5
View File
@@ -78,6 +78,11 @@ class RedisStore : public sigc::trackable
const std::string& codecs,
uint32_t current_tg);
void clearLiveClient(const std::string& callsign);
// Publish the rich per-client status blob (rx levels, monitoredTGs,
// qth/location etc.) as a serialized JSON string in the `status`
// field of the existing live:client:<callsign> hash.
void pushClientStatus(const std::string& callsign,
const std::string& status_json);
void pushLiveTrunk(const std::string& section,
const std::string& state,
const std::string& peer_id);
+43 -28
View File
@@ -483,6 +483,35 @@ bool Reflector::initialize(Async::Config &cfg)
// Parse CLUSTER_TGS — comma-separated list of TG numbers broadcast to all peers
reloadClusterTgs();
// Initialize MQTT publisher if [MQTT] section is configured.
// Done before the satellite early-return so satellites publish too.
std::string mqtt_host;
if (cfg.getValue("MQTT", "HOST", mqtt_host))
{
m_mqtt = new MqttPublisher(cfg);
if (!m_mqtt->initialize())
{
cerr << "*** WARNING: MQTT publisher failed to initialize, continuing without MQTT" << endl;
delete m_mqtt;
m_mqtt = nullptr;
}
else
{
// Set up periodic status publishing
unsigned status_interval = 1000;
cfg.getValue("MQTT", "STATUS_INTERVAL", status_interval);
m_mqtt_status_timer.setTimeout(status_interval);
m_mqtt_status_timer.setEnable(true);
m_mqtt_status_timer.expired.connect(
[this](Async::Timer*)
{
refreshStatus();
m_mqtt->publishFullStatus(m_status);
m_mqtt_status_timer.setEnable(true);
});
}
}
// Satellite mode: connect to parent instead of joining the trunk mesh
std::string satellite_of;
if (cfg.getValue("GLOBAL", "SATELLITE_OF", satellite_of) &&
@@ -518,34 +547,6 @@ bool Reflector::initialize(Async::Config &cfg)
initTwinServer();
initSatelliteServer();
// Initialize MQTT publisher if [MQTT] section is configured
std::string mqtt_host;
if (cfg.getValue("MQTT", "HOST", mqtt_host))
{
m_mqtt = new MqttPublisher(cfg);
if (!m_mqtt->initialize())
{
cerr << "*** WARNING: MQTT publisher failed to initialize, continuing without MQTT" << endl;
delete m_mqtt;
m_mqtt = nullptr;
}
else
{
// Set up periodic status publishing
unsigned status_interval = 1000;
cfg.getValue("MQTT", "STATUS_INTERVAL", status_interval);
m_mqtt_status_timer.setTimeout(status_interval);
m_mqtt_status_timer.setEnable(true);
m_mqtt_status_timer.expired.connect(
[this](Async::Timer*)
{
refreshStatus();
m_mqtt->publishFullStatus(m_status);
m_mqtt_status_timer.setEnable(true);
});
}
}
return true;
} /* Reflector::initialize */
@@ -2961,9 +2962,23 @@ void Reflector::publishRxUpdate(ReflectorClient* client)
{
m_mqtt->onRxUpdate(client->callsign(), client->rxStatusJson());
}
publishClientStatus(client);
} /* Reflector::publishRxUpdate */
void Reflector::publishClientStatus(ReflectorClient* client)
{
if (m_redis == nullptr || client == nullptr) return;
const std::string& cs = client->callsign();
if (cs.empty()) return;
if (!m_status["nodes"].isMember(cs)) return;
Json::StreamWriterBuilder wb;
wb["indentation"] = "";
m_redis->pushClientStatus(cs,
Json::writeString(wb, m_status["nodes"][cs]));
} /* Reflector::publishClientStatus */
void Reflector::onClientAuthenticated(const std::string& callsign,
uint32_t tg, const std::string& ip)
{
+3
View File
@@ -260,6 +260,9 @@ class Reflector : public sigc::trackable
void forwardFlushToSatellitesExcept(SatelliteLink* except, uint32_t tg);
void publishRxUpdate(ReflectorClient* client);
// Push the rich per-client status blob (rx, monitoredTGs, qth, ...)
// to Redis. Cheap no-op if Redis is not configured.
void publishClientStatus(ReflectorClient* client);
void onClientAuthenticated(const std::string& callsign, uint32_t tg,
const std::string& ip);
void notifyExternalTrunkTalkerStart(uint32_t tg,
@@ -1016,6 +1016,7 @@ void ReflectorClient::handleNodeInfo(std::istream& is)
<< "]: Failed to parse MsgNodeInfo JSON object: "
<< e.what() << std::endl;
}
if (m_reflector != nullptr) m_reflector->publishClientStatus(this);
} /* ReflectorClient::handleNodeInfo */
@@ -1433,6 +1434,7 @@ void ReflectorClient::setMonitoredTGs(const std::set<uint32_t>& tgs)
monitored_tgs.append(tg);
}
}
if (m_reflector != nullptr) m_reflector->publishClientStatus(this);
} /* ReflectorClient::setMonitoredTGs */
@@ -1467,6 +1469,7 @@ void ReflectorClient::setTg(uint32_t tg)
}
updateIsTalker();
if (m_reflector != nullptr) m_reflector->publishClientStatus(this);
} /* ReflectorClient::setTg */