Parse [REDIS] section and connect at startup (sync only)

This commit is contained in:
Audric committed 2026-04-15 02:47:23 +02:00
1 parent 6ecbf69bc0
commit 98b7d0a89e
2 files changed
+40

No files matched your search

+36
View File
@@ -69,6 +69,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#include "ReflectorClient.h"
#include "TGHandler.h"
#include "TrunkLink.h"
#include "RedisStore.h"
#include <version/SVXREFLECTOR.h>
@@ -298,6 +299,8 @@ Reflector::~Reflector(void)
m_srv = 0;
delete m_cmd_pty;
m_cmd_pty = 0;
delete m_redis;
m_redis = nullptr;
for (auto* link : m_trunk_links)
{
delete link;
@@ -417,6 +420,39 @@ bool Reflector::initialize(Async::Config &cfg)
mem_fun(*this, &Reflector::ctrlPtyDataReceived));
}
// Optional [REDIS] section — when present, Redis becomes the source
// of truth for users/passwords/cluster/trunk dynamic settings.
{
std::string redis_host;
std::string redis_unix;
m_cfg->getValue("REDIS", "HOST", redis_host);
m_cfg->getValue("REDIS", "UNIX_SOCKET", redis_unix);
if (!redis_host.empty() || !redis_unix.empty())
{
RedisStore::Config rcfg;
rcfg.host = redis_host;
rcfg.unix_socket = redis_unix;
std::string port_s; m_cfg->getValue("REDIS", "PORT", port_s);
if (!port_s.empty()) rcfg.port = static_cast<uint16_t>(std::stoul(port_s));
m_cfg->getValue("REDIS", "PASSWORD", rcfg.password);
std::string db_s; m_cfg->getValue("REDIS", "DB", db_s);
if (!db_s.empty()) rcfg.db = std::stoi(db_s);
m_cfg->getValue("REDIS", "KEY_PREFIX", rcfg.key_prefix);
std::string tls_s; m_cfg->getValue("REDIS", "TLS_ENABLED", tls_s);
rcfg.tls_enabled = (tls_s == "1");
m_cfg->getValue("REDIS", "TLS_CA_CERT", rcfg.tls_ca_cert);
m_cfg->getValue("REDIS", "TLS_CLIENT_CERT", rcfg.tls_client_cert);
m_cfg->getValue("REDIS", "TLS_CLIENT_KEY", rcfg.tls_client_key);
m_redis = new RedisStore(rcfg);
if (!m_redis->connect()) {
std::cerr << "*** ERROR: [REDIS] is configured but Redis is unreachable. "
<< "Aborting startup." << std::endl;
return false;
}
}
}
m_cfg->getValue("GLOBAL", "ACCEPT_CERT_EMAIL", m_accept_cert_email);
m_cfg->valueUpdated.connect(sigc::mem_fun(*this, &Reflector::cfgUpdated));
+4
View File
@@ -86,6 +86,7 @@ namespace Async
class ReflectorMsg;
class ReflectorUdpMsg;
class RedisStore;
/****************************************************************************
@@ -244,6 +245,8 @@ class Reflector : public sigc::trackable
bool isClusterTG(uint32_t tg) const { return m_cluster_tgs.count(tg) > 0; }
bool isSatelliteMode(void) const { return m_is_satellite; }
RedisStore* redisStore(void) const { return m_redis; }
// Callbacks for SatelliteLink to forward satellite events to trunk peers
void forwardSatelliteAudioToTrunks(uint32_t tg,
const std::string& callsign);
@@ -338,6 +341,7 @@ class Reflector : public sigc::trackable
// MQTT publishing
MqttPublisher* m_mqtt = nullptr;
RedisStore* m_redis = nullptr;
Async::Timer m_mqtt_status_timer;
Reflector(const Reflector&);