You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.7 KiB
57 lines
1.7 KiB
|
8 years ago
|
#ifdef ZT_CONTROLLER_USE_LIBPQ
|
||
|
|
|
||
|
12 months ago
|
#include "PostgreSQL.hpp"
|
||
|
4 years ago
|
|
||
|
12 months ago
|
#include <nlohmann/json.hpp>
|
||
|
5 years ago
|
|
||
|
12 months ago
|
using namespace nlohmann;
|
||
|
8 years ago
|
|
||
|
|
using namespace ZeroTier;
|
||
|
|
|
||
|
9 months ago
|
MemberNotificationReceiver::MemberNotificationReceiver(DB* p, pqxx::connection& c, const std::string& channel) : pqxx::notification_receiver(c, channel), _psql(p)
|
||
|
5 years ago
|
{
|
||
|
3 years ago
|
fprintf(stderr, "initialize MemberNotificationReceiver\n");
|
||
|
5 years ago
|
}
|
||
|
5 years ago
|
|
||
|
9 months ago
|
void MemberNotificationReceiver::operator()(const std::string& payload, int packend_pid)
|
||
|
|
{
|
||
|
5 years ago
|
fprintf(stderr, "Member Notification received: %s\n", payload.c_str());
|
||
|
3 years ago
|
Metrics::pgsql_mem_notification++;
|
||
|
5 years ago
|
json tmp(json::parse(payload));
|
||
|
9 months ago
|
json& ov = tmp["old_val"];
|
||
|
|
json& nv = tmp["new_val"];
|
||
|
5 years ago
|
json oldConfig, newConfig;
|
||
|
9 months ago
|
if (ov.is_object())
|
||
|
|
oldConfig = ov;
|
||
|
|
if (nv.is_object())
|
||
|
|
newConfig = nv;
|
||
|
5 years ago
|
if (oldConfig.is_object() || newConfig.is_object()) {
|
||
|
9 months ago
|
_psql->_memberChanged(oldConfig, newConfig, _psql->isReady());
|
||
|
5 years ago
|
fprintf(stderr, "payload sent\n");
|
||
|
5 years ago
|
}
|
||
|
|
}
|
||
|
|
|
||
|
9 months ago
|
NetworkNotificationReceiver::NetworkNotificationReceiver(DB* p, pqxx::connection& c, const std::string& channel) : pqxx::notification_receiver(c, channel), _psql(p)
|
||
|
5 years ago
|
{
|
||
|
|
fprintf(stderr, "initialize NetworkNotificationReceiver\n");
|
||
|
|
}
|
||
|
5 years ago
|
|
||
|
9 months ago
|
void NetworkNotificationReceiver::operator()(const std::string& payload, int packend_pid)
|
||
|
|
{
|
||
|
3 years ago
|
fprintf(stderr, "Network Notification received: %s\n", payload.c_str());
|
||
|
3 years ago
|
Metrics::pgsql_net_notification++;
|
||
|
5 years ago
|
json tmp(json::parse(payload));
|
||
|
9 months ago
|
json& ov = tmp["old_val"];
|
||
|
|
json& nv = tmp["new_val"];
|
||
|
5 years ago
|
json oldConfig, newConfig;
|
||
|
9 months ago
|
if (ov.is_object())
|
||
|
|
oldConfig = ov;
|
||
|
|
if (nv.is_object())
|
||
|
|
newConfig = nv;
|
||
|
5 years ago
|
if (oldConfig.is_object() || newConfig.is_object()) {
|
||
|
9 months ago
|
_psql->_networkChanged(oldConfig, newConfig, _psql->isReady());
|
||
|
5 years ago
|
fprintf(stderr, "payload sent\n");
|
||
|
5 years ago
|
}
|
||
|
|
}
|
||
|
|
|
||
|
12 months ago
|
#endif
|