Add RedisStore skeleton (no functionality yet)
This commit is contained in:
1 parent
2877d6be79
commit
b64b79f2a7
3 files changed
+163
-1
No files matched your search
@@ -35,7 +35,7 @@ set(LIBS asynccpp asyncaudio asynccore svxmisc ${LIBS})
|
||||
# Build the executable
|
||||
add_executable(svxreflector
|
||||
svxreflector.cpp Reflector.cpp ReflectorClient.cpp TGHandler.cpp TrunkLink.cpp
|
||||
SatelliteLink.cpp SatelliteClient.cpp MqttPublisher.cpp
|
||||
SatelliteLink.cpp SatelliteClient.cpp MqttPublisher.cpp RedisStore.cpp
|
||||
)
|
||||
target_link_libraries(svxreflector ${LIBS})
|
||||
set_target_properties(svxreflector PROPERTIES
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
#include "RedisStore.h"
|
||||
#include <hiredis/hiredis.h>
|
||||
#include <iostream>
|
||||
|
||||
RedisStore::RedisStore(const Config& cfg) : m_cfg(cfg) {}
|
||||
RedisStore::~RedisStore() {
|
||||
if (m_sync) { redisFree(m_sync); m_sync = nullptr; }
|
||||
}
|
||||
|
||||
bool RedisStore::connect(void) {
|
||||
std::cerr << "RedisStore::connect not implemented yet" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool RedisStore::isReady(void) const { return m_sync != nullptr; }
|
||||
|
||||
std::string RedisStore::lookupUserKey(const std::string&) { return ""; }
|
||||
std::map<std::string, std::string> RedisStore::loadAllUsers(void) { return {}; }
|
||||
bool RedisStore::isUserEnabled(const std::string&) { return true; }
|
||||
std::set<uint32_t> RedisStore::loadClusterTgs(void) { return {}; }
|
||||
std::string RedisStore::loadTrunkFilter(const std::string&, const std::string&) { return ""; }
|
||||
std::map<uint32_t, uint32_t> RedisStore::loadTrunkTgMap(const std::string&) { return {}; }
|
||||
std::set<std::string> RedisStore::loadTrunkMutes(const std::string&) { return {}; }
|
||||
void RedisStore::addTrunkMute(const std::string&, const std::string&) {}
|
||||
void RedisStore::removeTrunkMute(const std::string&, const std::string&) {}
|
||||
void RedisStore::publishConfigChanged(const std::string&) {}
|
||||
void RedisStore::pushLiveTalker(uint32_t, const std::string&, const std::string&) {}
|
||||
void RedisStore::clearLiveTalker(uint32_t) {}
|
||||
void RedisStore::pushLiveClient(const std::string&, const std::string&,
|
||||
const std::string&, uint32_t) {}
|
||||
void RedisStore::clearLiveClient(const std::string&) {}
|
||||
void RedisStore::pushLiveTrunk(const std::string&, const std::string&,
|
||||
const std::string&) {}
|
||||
|
||||
size_t RedisStore::liveQueueSize(void) const { return 0; }
|
||||
|
||||
bool RedisStore::connectSync(void) { return false; }
|
||||
bool RedisStore::connectAsync(void) { return false; }
|
||||
void RedisStore::subscribe(void) {}
|
||||
void RedisStore::scheduleReconnect(void) {}
|
||||
void RedisStore::onAsyncDisconnect(int) {}
|
||||
void RedisStore::onPubSubMessage(const std::string&, const std::string&) {}
|
||||
void RedisStore::drainLiveQueue(Async::Timer*) {}
|
||||
void RedisStore::refreshLiveExpire(Async::Timer*) {}
|
||||
|
||||
std::string RedisStore::keyFor(const std::string& suffix) const {
|
||||
if (m_cfg.key_prefix.empty()) return suffix;
|
||||
return m_cfg.key_prefix + ":" + suffix;
|
||||
}
|
||||
|
||||
std::string RedisStore::channelName(void) const {
|
||||
return keyFor("config.changed");
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
#ifndef REDIS_STORE_INCLUDED
|
||||
#define REDIS_STORE_INCLUDED
|
||||
|
||||
#include <sigc++/sigc++.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <cstdint>
|
||||
|
||||
struct redisContext;
|
||||
struct redisAsyncContext;
|
||||
namespace Async { class Config; class Timer; }
|
||||
|
||||
class RedisAsyncAdapter;
|
||||
class RedisLiveQueue;
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
explicit RedisStore(const Config& cfg);
|
||||
~RedisStore();
|
||||
|
||||
// Synchronous startup connect. Returns false on failure (caller exits).
|
||||
bool connect(void);
|
||||
|
||||
bool isReady(void) const;
|
||||
|
||||
// Emitted when a config.changed message arrives from Redis. The
|
||||
// string payload identifies the scope: "users", "cluster",
|
||||
// "trunk:<section>", or "all".
|
||||
sigc::signal<void, std::string> configChanged;
|
||||
|
||||
// Schema accessors (sync). Empty results on Redis errors are logged
|
||||
// and treated as "no entries".
|
||||
std::string lookupUserKey(const std::string& callsign);
|
||||
std::map<std::string, std::string> loadAllUsers(void);
|
||||
bool isUserEnabled(const std::string& callsign);
|
||||
|
||||
std::set<uint32_t> loadClusterTgs(void);
|
||||
|
||||
std::string loadTrunkFilter(const std::string& section,
|
||||
const std::string& field); // "blacklist"|"allow"
|
||||
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).
|
||||
void publishConfigChanged(const std::string& scope);
|
||||
|
||||
// Live-state push (non-blocking; enqueues onto live queue).
|
||||
void pushLiveTalker(uint32_t tg, const std::string& callsign,
|
||||
const std::string& source);
|
||||
void clearLiveTalker(uint32_t tg);
|
||||
void pushLiveClient(const std::string& callsign,
|
||||
const std::string& ip,
|
||||
const std::string& codecs,
|
||||
uint32_t current_tg);
|
||||
void clearLiveClient(const std::string& callsign);
|
||||
void pushLiveTrunk(const std::string& section,
|
||||
const std::string& state,
|
||||
const std::string& peer_id);
|
||||
|
||||
uint64_t droppedLiveWrites(void) const { return m_dropped_live_writes; }
|
||||
size_t liveQueueSize(void) const;
|
||||
|
||||
private:
|
||||
Config m_cfg;
|
||||
redisContext* m_sync = nullptr;
|
||||
redisAsyncContext* m_async = nullptr;
|
||||
RedisAsyncAdapter* m_adapter = nullptr;
|
||||
RedisLiveQueue* m_live_queue = nullptr;
|
||||
Async::Timer* m_drain_timer = nullptr;
|
||||
Async::Timer* m_reconnect_timer = nullptr;
|
||||
Async::Timer* m_heartbeat_timer = nullptr;
|
||||
int m_reconnect_backoff_s = 1;
|
||||
uint64_t m_dropped_live_writes = 0;
|
||||
|
||||
bool connectSync(void);
|
||||
bool connectAsync(void);
|
||||
void subscribe(void);
|
||||
void scheduleReconnect(void);
|
||||
void onAsyncDisconnect(int status);
|
||||
void onPubSubMessage(const std::string& channel, const std::string& payload);
|
||||
void drainLiveQueue(Async::Timer*);
|
||||
void refreshLiveExpire(Async::Timer*);
|
||||
|
||||
std::string keyFor(const std::string& suffix) const;
|
||||
std::string channelName(void) const;
|
||||
};
|
||||
|
||||
#endif /* REDIS_STORE_INCLUDED */
|
||||
Reference in new issue
Block a user