From 278c8fd9f1a36bc7b81cbfd50b93626d5341b8de Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Fri, 13 Mar 2015 13:53:15 -0700 Subject: [PATCH] Wire up externally specified NetworkConfigMaster --- main.cpp | 7 ++++++- netconf/SqliteNetworkConfigMaster.hpp | 1 + netconf/netconf-schema.sql | 9 ++++----- node/Node.cpp | 3 ++- node/Node.hpp | 3 +++ node/RuntimeEnvironment.hpp | 4 ++-- 6 files changed, 18 insertions(+), 9 deletions(-) diff --git a/main.cpp b/main.cpp index f5e0b8c53..7467ba41f 100644 --- a/main.cpp +++ b/main.cpp @@ -78,6 +78,10 @@ #include "osnet/NativeSocketManager.hpp" +#ifdef ZT_ENABLE_NETCONF_MASTER +#include "netconf/SqliteNetworkConfigMaster.hpp" +#endif // ZT_ENABLE_NETCONF_MASTER + #ifdef __WINDOWS__ #include "osnet/WindowsEthernetTapFactory.hpp" #include "osnet/WindowsRoutingTable.hpp" @@ -810,6 +814,7 @@ int main(int argc,char **argv) RoutingTable *routingTable = (RoutingTable *)0; SocketManager *socketManager = (SocketManager *)0; NodeControlService *controlService = (NodeControlService *)0; + NetworkConfigMaster *netconfMaster = (NetworkConfigMaster *)0; try { // Get or create authtoken.secret -- note that if this fails, authentication @@ -827,7 +832,7 @@ int main(int argc,char **argv) throw; } - node = new Node(homeDir,tapFactory,routingTable,socketManager,needsReset,(overrideRootTopology.length() > 0) ? overrideRootTopology.c_str() : (const char *)0); + node = new Node(homeDir,tapFactory,routingTable,socketManager,netconfMaster,needsReset,(overrideRootTopology.length() > 0) ? overrideRootTopology.c_str() : (const char *)0); controlService = new NodeControlService(node,authToken.c_str()); switch(node->run()) { diff --git a/netconf/SqliteNetworkConfigMaster.hpp b/netconf/SqliteNetworkConfigMaster.hpp index 514e33dd0..829eb4f82 100644 --- a/netconf/SqliteNetworkConfigMaster.hpp +++ b/netconf/SqliteNetworkConfigMaster.hpp @@ -47,6 +47,7 @@ class SqliteNetworkConfigMaster : public NetworkConfigMaster public: SqliteNetworkConfigMaster(const Identity &signingId,const char *dbPath); virtual ~SqliteNetworkConfigMaster(); + virtual NetworkConfigMaster::ResultCode doNetworkConfigRequest( const InetAddress &fromAddr, uint64_t packetId, diff --git a/netconf/netconf-schema.sql b/netconf/netconf-schema.sql index 4d985562f..ccd6de65f 100644 --- a/netconf/netconf-schema.sql +++ b/netconf/netconf-schema.sql @@ -1,7 +1,7 @@ CREATE TABLE Config ( k varchar(16) PRIMARY KEY NOT NULL, v varchar(1024) NOT NULL -) WITHOUT ROWID; +); CREATE TABLE IpAssignment ( networkId char(16) NOT NULL, @@ -30,8 +30,7 @@ CREATE TABLE Member ( nodeId char(10) NOT NULL, cachedNetconf blob(4096), cachedNetconfRevision integer(32), - cachedNetconfTimestamp integer(32), - clientReportedTimestamp integer(32), + clientReportedRevision integer(32), authorized integer(1) NOT NULL DEFAULT(0), activeBridge integer(1) NOT NULL DEFAULT(0) ); @@ -62,7 +61,7 @@ CREATE TABLE Network ( multicastLimit integer(8) NOT NULL DEFAULT(32), creationTime integer(32) NOT NULL DEFAULT(0), revision integer(32) NOT NULL DEFAULT(0) -) WITHOUT ROWID; +); CREATE TABLE Node ( id char(10) PRIMARY KEY NOT NULL, @@ -70,7 +69,7 @@ CREATE TABLE Node ( lastAt varchar(64), lastSeen integer(32) NOT NULL DEFAULT(0), firstSeen integer(32) NOT NULL DEFAULT(0) -) WITHOUT ROWID; +); CREATE TABLE Rule ( networkId char(16) NOT NULL, diff --git a/node/Node.cpp b/node/Node.cpp index 28c9ddaa9..d013444a1 100644 --- a/node/Node.cpp +++ b/node/Node.cpp @@ -108,7 +108,6 @@ struct _NodeImpl delete renv.mc; renv.mc = (Multicaster *)0; delete renv.antiRec; renv.antiRec = (AntiRecursion *)0; delete renv.sw; renv.sw = (Switch *)0; // order matters less from here down - delete renv.netconfMaster; renv.netconfMaster = (NetworkConfigMaster *)0; delete renv.http; renv.http = (HttpClient *)0; delete renv.prng; renv.prng = (CMWC4096 *)0; delete renv.log; renv.log = (Logger *)0; // but stop logging last of all @@ -129,6 +128,7 @@ Node::Node( EthernetTapFactory *tf, RoutingTable *rt, SocketManager *sm, + NetworkConfigMaster *nm, bool resetIdentity, const char *overrideRootTopology) throw() : _impl(new _NodeImpl) @@ -142,6 +142,7 @@ Node::Node( impl->renv.tapFactory = tf; impl->renv.routingTable = rt; impl->renv.sm = sm; + impl->renv.netconfMaster = nm; if (resetIdentity) { // Forget identity and peer database, peer keys, etc. diff --git a/node/Node.hpp b/node/Node.hpp index 2e428a98a..23d59e368 100644 --- a/node/Node.hpp +++ b/node/Node.hpp @@ -37,6 +37,7 @@ namespace ZeroTier { class EthernetTapFactory; class RoutingTable; class SocketManager; +class NetworkConfigMaster; /** * A ZeroTier One node @@ -87,6 +88,7 @@ public: * @param tf Ethernet tap factory for platform network stack * @param rt Routing table interface for platform network stack * @param sm Socket manager for physical network I/O + * @param nm Network configuration master or NULL for none * @param resetIdentity If true, delete identity before starting and regenerate * @param overrideRootTopology Override root topology with this dictionary (in string serialized format) and do not update (default: NULL for none) */ @@ -95,6 +97,7 @@ public: EthernetTapFactory *tf, RoutingTable *rt, SocketManager *sm, + NetworkConfigMaster *nm, bool resetIdentity, const char *overrideRootTopology = (const char *)0) throw(); diff --git a/node/RuntimeEnvironment.hpp b/node/RuntimeEnvironment.hpp index 035903d9c..57a1c2624 100644 --- a/node/RuntimeEnvironment.hpp +++ b/node/RuntimeEnvironment.hpp @@ -75,10 +75,10 @@ public: tapFactory((EthernetTapFactory *)0), routingTable((RoutingTable *)0), sm((SocketManager *)0), + netconfMaster((NetworkConfigMaster *)0), log((Logger *)0), prng((CMWC4096 *)0), http((HttpClient *)0), - netconfMaster((NetworkConfigMaster *)0), sw((Switch *)0), mc((Multicaster *)0), antiRec((AntiRecursion *)0), @@ -112,6 +112,7 @@ public: EthernetTapFactory *tapFactory; RoutingTable *routingTable; SocketManager *sm; + NetworkConfigMaster *netconfMaster; /* * Order matters a bit here. These are constructed in this order @@ -124,7 +125,6 @@ public: Logger *log; // null if logging is disabled CMWC4096 *prng; HttpClient *http; - NetworkConfigMaster *netconfMaster; Switch *sw; Multicaster *mc; AntiRecursion *antiRec;