Refactoring in prep for mirroring

This commit is contained in:
Adam Ierymenko 2019-08-06 07:51:50 -05:00
parent f4f8fef82e
commit 37d508ab96
No known key found for this signature in database
GPG key ID: 1657198823E52A61
10 changed files with 161 additions and 152 deletions

View file

@ -313,7 +313,7 @@ void DB::_memberChanged(nlohmann::json &old,nlohmann::json &memberConfig,bool in
if (initialized) { if (initialized) {
std::lock_guard<std::mutex> ll(_changeListeners_l); std::lock_guard<std::mutex> ll(_changeListeners_l);
for(auto i=_changeListeners.begin();i!=_changeListeners.end();++i) { for(auto i=_changeListeners.begin();i!=_changeListeners.end();++i) {
(*i)->onNetworkMemberUpdate(networkId,memberId,memberConfig); (*i)->onNetworkMemberUpdate(this,networkId,memberId,memberConfig);
} }
} }
} else if (memberId) { } else if (memberId) {
@ -336,7 +336,7 @@ void DB::_memberChanged(nlohmann::json &old,nlohmann::json &memberConfig,bool in
if ((initialized)&&((wasAuth)&&(!isAuth)&&(networkId)&&(memberId))) { if ((initialized)&&((wasAuth)&&(!isAuth)&&(networkId)&&(memberId))) {
std::lock_guard<std::mutex> ll(_changeListeners_l); std::lock_guard<std::mutex> ll(_changeListeners_l);
for(auto i=_changeListeners.begin();i!=_changeListeners.end();++i) { for(auto i=_changeListeners.begin();i!=_changeListeners.end();++i) {
(*i)->onNetworkMemberDeauthorize(networkId,memberId); (*i)->onNetworkMemberDeauthorize(this,networkId,memberId);
} }
} }
} }
@ -362,7 +362,7 @@ void DB::_networkChanged(nlohmann::json &old,nlohmann::json &networkConfig,bool
if (initialized) { if (initialized) {
std::lock_guard<std::mutex> ll(_changeListeners_l); std::lock_guard<std::mutex> ll(_changeListeners_l);
for(auto i=_changeListeners.begin();i!=_changeListeners.end();++i) { for(auto i=_changeListeners.begin();i!=_changeListeners.end();++i) {
(*i)->onNetworkUpdate(networkId,networkConfig); (*i)->onNetworkUpdate(this,networkId,networkConfig);
} }
} }
} }

View file

@ -58,10 +58,10 @@ public:
public: public:
ChangeListener() {} ChangeListener() {}
virtual ~ChangeListener() {} virtual ~ChangeListener() {}
virtual void onNetworkUpdate(uint64_t networkId,const nlohmann::json &network) {} virtual void onNetworkUpdate(const DB *db,uint64_t networkId,const nlohmann::json &network) {}
virtual void onNetworkMemberUpdate(uint64_t networkId,uint64_t memberId,const nlohmann::json &member) {} virtual void onNetworkMemberUpdate(const DB *db,uint64_t networkId,uint64_t memberId,const nlohmann::json &member) {}
virtual void onNetworkMemberDeauthorize(uint64_t networkId,uint64_t memberId) {} virtual void onNetworkMemberDeauthorize(const DB *db,uint64_t networkId,uint64_t memberId) {}
virtual void onNetworkMemberOnline(uint64_t networkId,uint64_t memberId,const InetAddress &physicalAddress) {} virtual void onNetworkMemberOnline(const DB *db,uint64_t networkId,uint64_t memberId,const InetAddress &physicalAddress) {}
}; };
struct NetworkSummaryInfo struct NetworkSummaryInfo
@ -95,12 +95,15 @@ public:
bool get(const uint64_t networkId,nlohmann::json &network,const uint64_t memberId,nlohmann::json &member); bool get(const uint64_t networkId,nlohmann::json &network,const uint64_t memberId,nlohmann::json &member);
bool get(const uint64_t networkId,nlohmann::json &network,const uint64_t memberId,nlohmann::json &member,NetworkSummaryInfo &info); bool get(const uint64_t networkId,nlohmann::json &network,const uint64_t memberId,nlohmann::json &member,NetworkSummaryInfo &info);
bool get(const uint64_t networkId,nlohmann::json &network,std::vector<nlohmann::json> &members); bool get(const uint64_t networkId,nlohmann::json &network,std::vector<nlohmann::json> &members);
bool summary(const uint64_t networkId,NetworkSummaryInfo &info); bool summary(const uint64_t networkId,NetworkSummaryInfo &info);
void networks(std::vector<uint64_t> &networks); void networks(std::vector<uint64_t> &networks);
virtual void save(nlohmann::json *orig,nlohmann::json &record) = 0; virtual void save(nlohmann::json *orig,nlohmann::json &record) = 0;
virtual void eraseNetwork(const uint64_t networkId) = 0; virtual void eraseNetwork(const uint64_t networkId) = 0;
virtual void eraseMember(const uint64_t networkId,const uint64_t memberId) = 0; virtual void eraseMember(const uint64_t networkId,const uint64_t memberId) = 0;
virtual void nodeIsOnline(const uint64_t networkId,const uint64_t memberId,const InetAddress &physicalAddress) = 0; virtual void nodeIsOnline(const uint64_t networkId,const uint64_t memberId,const InetAddress &physicalAddress) = 0;
inline void addListener(DB::ChangeListener *const listener) inline void addListener(DB::ChangeListener *const listener)

View file

@ -1190,7 +1190,7 @@ void EmbeddedNetworkController::handleRemoteTrace(const ZT_RemoteTrace &rt)
} }
} }
void EmbeddedNetworkController::onNetworkUpdate(const uint64_t networkId,const nlohmann::json &network) void EmbeddedNetworkController::onNetworkUpdate(const DB *db,uint64_t networkId,const nlohmann::json &network)
{ {
// Send an update to all members of the network that are online // Send an update to all members of the network that are online
const int64_t now = OSUtils::now(); const int64_t now = OSUtils::now();
@ -1201,7 +1201,7 @@ void EmbeddedNetworkController::onNetworkUpdate(const uint64_t networkId,const n
} }
} }
void EmbeddedNetworkController::onNetworkMemberUpdate(const uint64_t networkId,const uint64_t memberId,const nlohmann::json &member) void EmbeddedNetworkController::onNetworkMemberUpdate(const DB *db,uint64_t networkId,uint64_t memberId,const nlohmann::json &member)
{ {
// Push update to member if online // Push update to member if online
try { try {
@ -1212,7 +1212,7 @@ void EmbeddedNetworkController::onNetworkMemberUpdate(const uint64_t networkId,c
} catch ( ... ) {} } catch ( ... ) {}
} }
void EmbeddedNetworkController::onNetworkMemberDeauthorize(const uint64_t networkId,const uint64_t memberId) void EmbeddedNetworkController::onNetworkMemberDeauthorize(const DB *db,uint64_t networkId,uint64_t memberId)
{ {
const int64_t now = OSUtils::now(); const int64_t now = OSUtils::now();
Revocation rev((uint32_t)_node->prng(),networkId,0,now,ZT_REVOCATION_FLAG_FAST_PROPAGATE,Address(memberId),Revocation::CREDENTIAL_TYPE_COM); Revocation rev((uint32_t)_node->prng(),networkId,0,now,ZT_REVOCATION_FLAG_FAST_PROPAGATE,Address(memberId),Revocation::CREDENTIAL_TYPE_COM);

View file

@ -101,9 +101,9 @@ public:
void handleRemoteTrace(const ZT_RemoteTrace &rt); void handleRemoteTrace(const ZT_RemoteTrace &rt);
virtual void onNetworkUpdate(const uint64_t networkId,const nlohmann::json &network); virtual void onNetworkUpdate(const DB *db,uint64_t networkId,const nlohmann::json &network);
virtual void onNetworkMemberUpdate(const uint64_t networkId,const uint64_t memberId,const nlohmann::json &member); virtual void onNetworkMemberUpdate(const DB *db,uint64_t networkId,uint64_t memberId,const nlohmann::json &member);
virtual void onNetworkMemberDeauthorize(const uint64_t networkId,const uint64_t memberId); virtual void onNetworkMemberDeauthorize(const DB *db,uint64_t networkId,uint64_t memberId);
private: private:
void _request(uint64_t nwid,const InetAddress &fromAddr,uint64_t requestPacketId,const Identity &identity,const Dictionary<ZT_NETWORKCONFIG_METADATA_DICT_CAPACITY> &metaData); void _request(uint64_t nwid,const InetAddress &fromAddr,uint64_t requestPacketId,const Identity &identity,const Dictionary<ZT_NETWORKCONFIG_METADATA_DICT_CAPACITY> &metaData);

View file

@ -178,7 +178,7 @@ void FileDB::nodeIsOnline(const uint64_t networkId,const uint64_t memberId,const
{ {
std::lock_guard<std::mutex> l2(_changeListeners_l); std::lock_guard<std::mutex> l2(_changeListeners_l);
for(auto i=_changeListeners.begin();i!=_changeListeners.end();++i) for(auto i=_changeListeners.begin();i!=_changeListeners.end();++i)
(*i)->onNetworkMemberOnline(networkId,memberId,physicalAddress); (*i)->onNetworkMemberOnline(this,networkId,memberId,physicalAddress);
} }
} }

View file

@ -404,7 +404,7 @@ void LFDB::nodeIsOnline(const uint64_t networkId,const uint64_t memberId,const I
{ {
std::lock_guard<std::mutex> l2(_changeListeners_l); std::lock_guard<std::mutex> l2(_changeListeners_l);
for(auto i=_changeListeners.begin();i!=_changeListeners.end();++i) for(auto i=_changeListeners.begin();i!=_changeListeners.end();++i)
(*i)->onNetworkMemberOnline(networkId,memberId,physicalAddress); (*i)->onNetworkMemberOnline(this,networkId,memberId,physicalAddress);
} }
} }

View file

@ -24,9 +24,11 @@
* of your own application. * of your own application.
*/ */
#include "PostgreSQL.hpp"
#ifdef ZT_CONTROLLER_USE_LIBPQ #ifdef ZT_CONTROLLER_USE_LIBPQ
#include "PostgreSQL.hpp" #include "../node/Constants.hpp"
#include "EmbeddedNetworkController.hpp" #include "EmbeddedNetworkController.hpp"
#include "RabbitMQ.hpp" #include "RabbitMQ.hpp"
#include "../version.h" #include "../version.h"
@ -37,6 +39,7 @@
#include <amqp_tcp_socket.h> #include <amqp_tcp_socket.h>
using json = nlohmann::json; using json = nlohmann::json;
namespace { namespace {
static const int DB_MINIMUM_VERSION = 5; static const int DB_MINIMUM_VERSION = 5;
@ -73,7 +76,7 @@ std::string join(const std::vector<std::string> &elements, const char * const se
} }
} }
} } // anonymous namespace
using namespace ZeroTier; using namespace ZeroTier;
@ -221,7 +224,7 @@ void PostgreSQL::nodeIsOnline(const uint64_t networkId, const uint64_t memberId,
{ {
std::lock_guard<std::mutex> l2(_changeListeners_l); std::lock_guard<std::mutex> l2(_changeListeners_l);
for(auto i=_changeListeners.begin();i!=_changeListeners.end();++i) for(auto i=_changeListeners.begin();i!=_changeListeners.end();++i)
(*i)->onNetworkMemberOnline(networkId,memberId,physicalAddress); (*i)->onNetworkMemberOnline(this,networkId,memberId,physicalAddress);
} }
} }
@ -1438,7 +1441,8 @@ void PostgreSQL::onlineNotificationThread()
} }
} }
PGconn *PostgreSQL::getPgConn(OverrideMode m) { PGconn *PostgreSQL::getPgConn(OverrideMode m)
{
if (m == ALLOW_PGBOUNCER_OVERRIDE) { if (m == ALLOW_PGBOUNCER_OVERRIDE) {
char *connStr = getenv("PGBOUNCER_CONNSTR"); char *connStr = getenv("PGBOUNCER_CONNSTR");
if (connStr != NULL) { if (connStr != NULL) {
@ -1452,4 +1456,5 @@ PGconn *PostgreSQL::getPgConn(OverrideMode m) {
return PQconnectdb(_connString.c_str()); return PQconnectdb(_connString.c_str());
} }
#endif //ZT_CONTROLLER_USE_LIBPQ #endif //ZT_CONTROLLER_USE_LIBPQ

View file

@ -24,6 +24,8 @@
* of your own application. * of your own application.
*/ */
#define ZT_CONTROLLER_USE_LIBPQ
#ifdef ZT_CONTROLLER_USE_LIBPQ #ifdef ZT_CONTROLLER_USE_LIBPQ
#ifndef ZT_CONTROLLER_LIBPQ_HPP #ifndef ZT_CONTROLLER_LIBPQ_HPP
@ -37,8 +39,7 @@ extern "C" {
typedef struct pg_conn PGconn; typedef struct pg_conn PGconn;
} }
namespace ZeroTier namespace ZeroTier {
{
struct MQConfig; struct MQConfig;
@ -110,7 +111,7 @@ private:
MQConfig *_mqc; MQConfig *_mqc;
}; };
} } // namespace ZeroTier
#endif // ZT_CONTROLLER_LIBPQ_HPP #endif // ZT_CONTROLLER_LIBPQ_HPP

View file

@ -23,6 +23,7 @@
* directly against ZeroTier software without disclosing the source code * directly against ZeroTier software without disclosing the source code
* of your own application. * of your own application.
*/ */
#ifndef ZT_CONTROLLER_RABBITMQ_HPP #ifndef ZT_CONTROLLER_RABBITMQ_HPP
#define ZT_CONTROLLER_RABBITMQ_HPP #define ZT_CONTROLLER_RABBITMQ_HPP
@ -68,7 +69,6 @@ private:
int _channel; int _channel;
Mutex _chan_m; Mutex _chan_m;
}; };
} }