mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-05 20:13:44 +02:00
Refactoring in prep for mirroring
This commit is contained in:
parent
f4f8fef82e
commit
37d508ab96
10 changed files with 161 additions and 152 deletions
|
@ -313,7 +313,7 @@ void DB::_memberChanged(nlohmann::json &old,nlohmann::json &memberConfig,bool in
|
|||
if (initialized) {
|
||||
std::lock_guard<std::mutex> ll(_changeListeners_l);
|
||||
for(auto i=_changeListeners.begin();i!=_changeListeners.end();++i) {
|
||||
(*i)->onNetworkMemberUpdate(networkId,memberId,memberConfig);
|
||||
(*i)->onNetworkMemberUpdate(this,networkId,memberId,memberConfig);
|
||||
}
|
||||
}
|
||||
} else if (memberId) {
|
||||
|
@ -336,7 +336,7 @@ void DB::_memberChanged(nlohmann::json &old,nlohmann::json &memberConfig,bool in
|
|||
if ((initialized)&&((wasAuth)&&(!isAuth)&&(networkId)&&(memberId))) {
|
||||
std::lock_guard<std::mutex> ll(_changeListeners_l);
|
||||
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) {
|
||||
std::lock_guard<std::mutex> ll(_changeListeners_l);
|
||||
for(auto i=_changeListeners.begin();i!=_changeListeners.end();++i) {
|
||||
(*i)->onNetworkUpdate(networkId,networkConfig);
|
||||
(*i)->onNetworkUpdate(this,networkId,networkConfig);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,10 +58,10 @@ public:
|
|||
public:
|
||||
ChangeListener() {}
|
||||
virtual ~ChangeListener() {}
|
||||
virtual void onNetworkUpdate(uint64_t networkId,const nlohmann::json &network) {}
|
||||
virtual void onNetworkMemberUpdate(uint64_t networkId,uint64_t memberId,const nlohmann::json &member) {}
|
||||
virtual void onNetworkMemberDeauthorize(uint64_t networkId,uint64_t memberId) {}
|
||||
virtual void onNetworkMemberOnline(uint64_t networkId,uint64_t memberId,const InetAddress &physicalAddress) {}
|
||||
virtual void onNetworkUpdate(const DB *db,uint64_t networkId,const nlohmann::json &network) {}
|
||||
virtual void onNetworkMemberUpdate(const DB *db,uint64_t networkId,uint64_t memberId,const nlohmann::json &member) {}
|
||||
virtual void onNetworkMemberDeauthorize(const DB *db,uint64_t networkId,uint64_t memberId) {}
|
||||
virtual void onNetworkMemberOnline(const DB *db,uint64_t networkId,uint64_t memberId,const InetAddress &physicalAddress) {}
|
||||
};
|
||||
|
||||
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,NetworkSummaryInfo &info);
|
||||
bool get(const uint64_t networkId,nlohmann::json &network,std::vector<nlohmann::json> &members);
|
||||
|
||||
bool summary(const uint64_t networkId,NetworkSummaryInfo &info);
|
||||
void networks(std::vector<uint64_t> &networks);
|
||||
|
||||
virtual void save(nlohmann::json *orig,nlohmann::json &record) = 0;
|
||||
|
||||
virtual void eraseNetwork(const uint64_t networkId) = 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;
|
||||
|
||||
inline void addListener(DB::ChangeListener *const listener)
|
||||
|
|
|
@ -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
|
||||
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
|
||||
try {
|
||||
|
@ -1212,7 +1212,7 @@ void EmbeddedNetworkController::onNetworkMemberUpdate(const uint64_t networkId,c
|
|||
} 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();
|
||||
Revocation rev((uint32_t)_node->prng(),networkId,0,now,ZT_REVOCATION_FLAG_FAST_PROPAGATE,Address(memberId),Revocation::CREDENTIAL_TYPE_COM);
|
||||
|
|
|
@ -101,9 +101,9 @@ public:
|
|||
|
||||
void handleRemoteTrace(const ZT_RemoteTrace &rt);
|
||||
|
||||
virtual void onNetworkUpdate(const uint64_t networkId,const nlohmann::json &network);
|
||||
virtual void onNetworkMemberUpdate(const uint64_t networkId,const uint64_t memberId,const nlohmann::json &member);
|
||||
virtual void onNetworkMemberDeauthorize(const uint64_t networkId,const uint64_t memberId);
|
||||
virtual void onNetworkUpdate(const DB *db,uint64_t networkId,const nlohmann::json &network);
|
||||
virtual void onNetworkMemberUpdate(const DB *db,uint64_t networkId,uint64_t memberId,const nlohmann::json &member);
|
||||
virtual void onNetworkMemberDeauthorize(const DB *db,uint64_t networkId,uint64_t memberId);
|
||||
|
||||
private:
|
||||
void _request(uint64_t nwid,const InetAddress &fromAddr,uint64_t requestPacketId,const Identity &identity,const Dictionary<ZT_NETWORKCONFIG_METADATA_DICT_CAPACITY> &metaData);
|
||||
|
|
|
@ -178,7 +178,7 @@ void FileDB::nodeIsOnline(const uint64_t networkId,const uint64_t memberId,const
|
|||
{
|
||||
std::lock_guard<std::mutex> l2(_changeListeners_l);
|
||||
for(auto i=_changeListeners.begin();i!=_changeListeners.end();++i)
|
||||
(*i)->onNetworkMemberOnline(networkId,memberId,physicalAddress);
|
||||
(*i)->onNetworkMemberOnline(this,networkId,memberId,physicalAddress);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
for(auto i=_changeListeners.begin();i!=_changeListeners.end();++i)
|
||||
(*i)->onNetworkMemberOnline(networkId,memberId,physicalAddress);
|
||||
(*i)->onNetworkMemberOnline(this,networkId,memberId,physicalAddress);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -24,9 +24,11 @@
|
|||
* of your own application.
|
||||
*/
|
||||
|
||||
#include "PostgreSQL.hpp"
|
||||
|
||||
#ifdef ZT_CONTROLLER_USE_LIBPQ
|
||||
|
||||
#include "PostgreSQL.hpp"
|
||||
#include "../node/Constants.hpp"
|
||||
#include "EmbeddedNetworkController.hpp"
|
||||
#include "RabbitMQ.hpp"
|
||||
#include "../version.h"
|
||||
|
@ -37,6 +39,7 @@
|
|||
#include <amqp_tcp_socket.h>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace {
|
||||
|
||||
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;
|
||||
|
||||
|
@ -221,7 +224,7 @@ void PostgreSQL::nodeIsOnline(const uint64_t networkId, const uint64_t memberId,
|
|||
{
|
||||
std::lock_guard<std::mutex> l2(_changeListeners_l);
|
||||
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) {
|
||||
char *connStr = getenv("PGBOUNCER_CONNSTR");
|
||||
if (connStr != NULL) {
|
||||
|
@ -1452,4 +1456,5 @@ PGconn *PostgreSQL::getPgConn(OverrideMode m) {
|
|||
|
||||
return PQconnectdb(_connString.c_str());
|
||||
}
|
||||
|
||||
#endif //ZT_CONTROLLER_USE_LIBPQ
|
||||
|
|
|
@ -24,6 +24,8 @@
|
|||
* of your own application.
|
||||
*/
|
||||
|
||||
#define ZT_CONTROLLER_USE_LIBPQ
|
||||
|
||||
#ifdef ZT_CONTROLLER_USE_LIBPQ
|
||||
|
||||
#ifndef ZT_CONTROLLER_LIBPQ_HPP
|
||||
|
@ -37,8 +39,7 @@ extern "C" {
|
|||
typedef struct pg_conn PGconn;
|
||||
}
|
||||
|
||||
namespace ZeroTier
|
||||
{
|
||||
namespace ZeroTier {
|
||||
|
||||
struct MQConfig;
|
||||
|
||||
|
@ -110,7 +111,7 @@ private:
|
|||
MQConfig *_mqc;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace ZeroTier
|
||||
|
||||
#endif // ZT_CONTROLLER_LIBPQ_HPP
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
* directly against ZeroTier software without disclosing the source code
|
||||
* of your own application.
|
||||
*/
|
||||
|
||||
#ifndef ZT_CONTROLLER_RABBITMQ_HPP
|
||||
#define ZT_CONTROLLER_RABBITMQ_HPP
|
||||
|
||||
|
@ -68,7 +69,6 @@ private:
|
|||
int _channel;
|
||||
|
||||
Mutex _chan_m;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue