We now always build the controller in ZeroTier One, at least for desktop and server targets. Also means that ZeroTier One now requires C++11. (Still keeping C++11 out of the core in node/ though.)

This commit is contained in:
Adam Ierymenko 2016-08-17 10:42:32 -07:00
parent cc808cc2dd
commit a13f4d8353
10 changed files with 24 additions and 86 deletions

View file

@ -33,7 +33,7 @@
#include "../include/ZeroTierOne.h" #include "../include/ZeroTierOne.h"
#include "../node/Constants.hpp" #include "../node/Constants.hpp"
#include "SqliteNetworkController.hpp" #include "EmbeddedNetworkController.hpp"
#include "../node/Node.hpp" #include "../node/Node.hpp"
#include "../node/Utils.hpp" #include "../node/Utils.hpp"
@ -337,7 +337,7 @@ static bool _parseRule(const json &r,ZT_VirtualNetworkRule &rule)
return false; return false;
} }
SqliteNetworkController::SqliteNetworkController(Node *node,const char *dbPath) : EmbeddedNetworkController::EmbeddedNetworkController(Node *node,const char *dbPath) :
_node(node), _node(node),
_path(dbPath) _path(dbPath)
{ {
@ -585,11 +585,11 @@ SqliteNetworkController::SqliteNetworkController(Node *node,const char *dbPath)
*/ */
} }
SqliteNetworkController::~SqliteNetworkController() EmbeddedNetworkController::~EmbeddedNetworkController()
{ {
} }
NetworkController::ResultCode SqliteNetworkController::doNetworkConfigRequest(const InetAddress &fromAddr,const Identity &signingId,const Identity &identity,uint64_t nwid,const Dictionary<ZT_NETWORKCONFIG_METADATA_DICT_CAPACITY> &metaData,NetworkConfig &nc) NetworkController::ResultCode EmbeddedNetworkController::doNetworkConfigRequest(const InetAddress &fromAddr,const Identity &signingId,const Identity &identity,uint64_t nwid,const Dictionary<ZT_NETWORKCONFIG_METADATA_DICT_CAPACITY> &metaData,NetworkConfig &nc)
{ {
if (((!signingId)||(!signingId.hasPrivate()))||(signingId.address().toInt() != (nwid >> 24))) { if (((!signingId)||(!signingId.hasPrivate()))||(signingId.address().toInt() != (nwid >> 24))) {
return NetworkController::NETCONF_QUERY_INTERNAL_SERVER_ERROR; return NetworkController::NETCONF_QUERY_INTERNAL_SERVER_ERROR;
@ -898,7 +898,7 @@ NetworkController::ResultCode SqliteNetworkController::doNetworkConfigRequest(co
return NetworkController::NETCONF_QUERY_OK; return NetworkController::NETCONF_QUERY_OK;
} }
unsigned int SqliteNetworkController::handleControlPlaneHttpGET( unsigned int EmbeddedNetworkController::handleControlPlaneHttpGET(
const std::vector<std::string> &path, const std::vector<std::string> &path,
const std::map<std::string,std::string> &urlArgs, const std::map<std::string,std::string> &urlArgs,
const std::map<std::string,std::string> &headers, const std::map<std::string,std::string> &headers,
@ -1040,7 +1040,7 @@ unsigned int SqliteNetworkController::handleControlPlaneHttpGET(
return 404; return 404;
} }
unsigned int SqliteNetworkController::handleControlPlaneHttpPOST( unsigned int EmbeddedNetworkController::handleControlPlaneHttpPOST(
const std::vector<std::string> &path, const std::vector<std::string> &path,
const std::map<std::string,std::string> &urlArgs, const std::map<std::string,std::string> &urlArgs,
const std::map<std::string,std::string> &headers, const std::map<std::string,std::string> &headers,
@ -1155,7 +1155,7 @@ unsigned int SqliteNetworkController::handleControlPlaneHttpPOST(
te.test = test; te.test = test;
te.jsonResults = ""; te.jsonResults = "";
_node->circuitTestBegin(test,&(SqliteNetworkController::_circuitTestCallback)); _node->circuitTestBegin(test,&(EmbeddedNetworkController::_circuitTestCallback));
char json[1024]; char json[1024];
Utils::snprintf(json,sizeof(json),"{\"testId\":\"%.16llx\"}",test->testId); Utils::snprintf(json,sizeof(json),"{\"testId\":\"%.16llx\"}",test->testId);
@ -1348,7 +1348,7 @@ unsigned int SqliteNetworkController::handleControlPlaneHttpPOST(
return 404; return 404;
} }
unsigned int SqliteNetworkController::handleControlPlaneHttpDELETE( unsigned int EmbeddedNetworkController::handleControlPlaneHttpDELETE(
const std::vector<std::string> &path, const std::vector<std::string> &path,
const std::map<std::string,std::string> &urlArgs, const std::map<std::string,std::string> &urlArgs,
const std::map<std::string,std::string> &headers, const std::map<std::string,std::string> &headers,
@ -1394,10 +1394,10 @@ unsigned int SqliteNetworkController::handleControlPlaneHttpDELETE(
return 404; return 404;
} }
void SqliteNetworkController::_circuitTestCallback(ZT_Node *node,ZT_CircuitTest *test,const ZT_CircuitTestReport *report) void EmbeddedNetworkController::_circuitTestCallback(ZT_Node *node,ZT_CircuitTest *test,const ZT_CircuitTestReport *report)
{ {
char tmp[65535]; char tmp[65535];
SqliteNetworkController *const self = reinterpret_cast<SqliteNetworkController *>(test->ptr); EmbeddedNetworkController *const self = reinterpret_cast<EmbeddedNetworkController *>(test->ptr);
if (!test) if (!test)
return; return;

View file

@ -41,11 +41,11 @@ namespace ZeroTier {
class Node; class Node;
class SqliteNetworkController : public NetworkController class EmbeddedNetworkController : public NetworkController
{ {
public: public:
SqliteNetworkController(Node *node,const char *dbPath); EmbeddedNetworkController(Node *node,const char *dbPath);
virtual ~SqliteNetworkController(); virtual ~EmbeddedNetworkController();
virtual NetworkController::ResultCode doNetworkConfigRequest( virtual NetworkController::ResultCode doNetworkConfigRequest(
const InetAddress &fromAddr, const InetAddress &fromAddr,

View file

@ -82,12 +82,6 @@ ifeq ($(ZT_USE_MINIUPNPC),1)
endif endif
endif endif
ifeq ($(ZT_ENABLE_NETWORK_CONTROLLER),1)
DEFS+=-DZT_ENABLE_NETWORK_CONTROLLER
LDLIBS+=-L/usr/local/lib -lsqlite3
OBJS+=controller/SqliteNetworkController.o
endif
ifeq ($(ZT_ENABLE_CLUSTER),1) ifeq ($(ZT_ENABLE_CLUSTER),1)
DEFS+=-DZT_ENABLE_CLUSTER DEFS+=-DZT_ENABLE_CLUSTER
endif endif

View file

@ -45,12 +45,6 @@ ifeq ($(ZT_USE_MINIUPNPC),1)
OBJS+=ext/libnatpmp/natpmp.o ext/libnatpmp/getgateway.o ext/miniupnpc/connecthostport.o ext/miniupnpc/igd_desc_parse.o ext/miniupnpc/minisoap.o ext/miniupnpc/minissdpc.o ext/miniupnpc/miniupnpc.o ext/miniupnpc/miniwget.o ext/miniupnpc/minixml.o ext/miniupnpc/portlistingparse.o ext/miniupnpc/receivedata.o ext/miniupnpc/upnpcommands.o ext/miniupnpc/upnpdev.o ext/miniupnpc/upnperrors.o ext/miniupnpc/upnpreplyparse.o osdep/PortMapper.o OBJS+=ext/libnatpmp/natpmp.o ext/libnatpmp/getgateway.o ext/miniupnpc/connecthostport.o ext/miniupnpc/igd_desc_parse.o ext/miniupnpc/minisoap.o ext/miniupnpc/minissdpc.o ext/miniupnpc/miniupnpc.o ext/miniupnpc/miniwget.o ext/miniupnpc/minixml.o ext/miniupnpc/portlistingparse.o ext/miniupnpc/receivedata.o ext/miniupnpc/upnpcommands.o ext/miniupnpc/upnpdev.o ext/miniupnpc/upnperrors.o ext/miniupnpc/upnpreplyparse.o osdep/PortMapper.o
endif endif
ifeq ($(ZT_ENABLE_NETWORK_CONTROLLER),1)
DEFS+=-DZT_ENABLE_NETWORK_CONTROLLER
LIBS+=-L/usr/local/lib -lsqlite3
OBJS+=controller/SqliteNetworkController.o
endif
# Debug mode -- dump trace output, build binary with -g # Debug mode -- dump trace output, build binary with -g
ifeq ($(ZT_DEBUG),1) ifeq ($(ZT_DEBUG),1)
DEFS+=-DZT_TRACE DEFS+=-DZT_TRACE

View file

@ -1,4 +1,5 @@
OBJS=\ OBJS=\
controller/EmbeddedNetworkController.o \
node/C25519.o \ node/C25519.o \
node/Capability.o \ node/Capability.o \
node/CertificateOfMembership.o \ node/CertificateOfMembership.o \

View file

@ -53,10 +53,6 @@
#include "osdep/PortMapper.hpp" #include "osdep/PortMapper.hpp"
#include "osdep/Thread.hpp" #include "osdep/Thread.hpp"
#ifdef ZT_ENABLE_NETWORK_CONTROLLER
#include "controller/SqliteNetworkController.hpp"
#endif // ZT_ENABLE_NETWORK_CONTROLLER
#ifdef __WINDOWS__ #ifdef __WINDOWS__
#include <tchar.h> #include <tchar.h>
#endif #endif

View file

@ -34,9 +34,7 @@
#include "../ext/json-parser/json.h" #include "../ext/json-parser/json.h"
#endif #endif
#ifdef ZT_ENABLE_NETWORK_CONTROLLER #include "../controller/EmbeddedNetworkController.hpp"
#include "../controller/SqliteNetworkController.hpp"
#endif
#include "../node/InetAddress.hpp" #include "../node/InetAddress.hpp"
#include "../node/Node.hpp" #include "../node/Node.hpp"
@ -254,9 +252,7 @@ static void _jsonAppend(unsigned int depth,std::string &buf,const ZT_Peer *peer)
ControlPlane::ControlPlane(OneService *svc,Node *n,const char *uiStaticPath) : ControlPlane::ControlPlane(OneService *svc,Node *n,const char *uiStaticPath) :
_svc(svc), _svc(svc),
_node(n), _node(n),
#ifdef ZT_ENABLE_NETWORK_CONTROLLER _controller((EmbeddedNetworkController *)0),
_controller((SqliteNetworkController *)0),
#endif
_uiStaticPath((uiStaticPath) ? uiStaticPath : "") _uiStaticPath((uiStaticPath) ? uiStaticPath : "")
{ {
} }
@ -499,13 +495,9 @@ unsigned int ControlPlane::handleRequest(
responseContentType = "text/plain"; responseContentType = "text/plain";
scode = 200; scode = 200;
} else { } else {
#ifdef ZT_ENABLE_NETWORK_CONTROLLER
if (_controller) if (_controller)
scode = _controller->handleControlPlaneHttpGET(std::vector<std::string>(ps.begin()+1,ps.end()),urlArgs,headers,body,responseBody,responseContentType); scode = _controller->handleControlPlaneHttpGET(std::vector<std::string>(ps.begin()+1,ps.end()),urlArgs,headers,body,responseBody,responseContentType);
else scode = 404; else scode = 404;
#else
scode = 404;
#endif
} }
} else scode = 401; // isAuth == false } else scode = 401; // isAuth == false
@ -559,13 +551,9 @@ unsigned int ControlPlane::handleRequest(
} else scode = 500; } else scode = 500;
} }
} else { } else {
#ifdef ZT_ENABLE_NETWORK_CONTROLLER
if (_controller) if (_controller)
scode = _controller->handleControlPlaneHttpPOST(std::vector<std::string>(ps.begin()+1,ps.end()),urlArgs,headers,body,responseBody,responseContentType); scode = _controller->handleControlPlaneHttpPOST(std::vector<std::string>(ps.begin()+1,ps.end()),urlArgs,headers,body,responseBody,responseContentType);
else scode = 404; else scode = 404;
#else
scode = 404;
#endif
} }
} else scode = 401; // isAuth == false } else scode = 401; // isAuth == false
@ -594,13 +582,9 @@ unsigned int ControlPlane::handleRequest(
_node->freeQueryResult((void *)nws); _node->freeQueryResult((void *)nws);
} else scode = 500; } else scode = 500;
} else { } else {
#ifdef ZT_ENABLE_NETWORK_CONTROLLER
if (_controller) if (_controller)
scode = _controller->handleControlPlaneHttpDELETE(std::vector<std::string>(ps.begin()+1,ps.end()),urlArgs,headers,body,responseBody,responseContentType); scode = _controller->handleControlPlaneHttpDELETE(std::vector<std::string>(ps.begin()+1,ps.end()),urlArgs,headers,body,responseBody,responseContentType);
else scode = 404; else scode = 404;
#else
scode = 404;
#endif
} }
} else { } else {

View file

@ -31,7 +31,7 @@ namespace ZeroTier {
class OneService; class OneService;
class Node; class Node;
class SqliteNetworkController; class EmbeddedNetworkController;
struct InetAddress; struct InetAddress;
/** /**
@ -43,18 +43,16 @@ public:
ControlPlane(OneService *svc,Node *n,const char *uiStaticPath); ControlPlane(OneService *svc,Node *n,const char *uiStaticPath);
~ControlPlane(); ~ControlPlane();
#ifdef ZT_ENABLE_NETWORK_CONTROLLER
/** /**
* Set controller, which will be available under /controller * Set controller, which will be available under /controller
* *
* @param c Network controller instance * @param c Network controller instance
*/ */
inline void setController(SqliteNetworkController *c) inline void setController(EmbeddedNetworkController *c)
{ {
Mutex::Lock _l(_lock); Mutex::Lock _l(_lock);
_controller = c; _controller = c;
} }
#endif
/** /**
* Add an authentication token for API access * Add an authentication token for API access
@ -89,9 +87,7 @@ public:
private: private:
OneService *const _svc; OneService *const _svc;
Node *const _node; Node *const _node;
#ifdef ZT_ENABLE_NETWORK_CONTROLLER EmbeddedNetworkController *_controller;
SqliteNetworkController *_controller;
#endif
std::string _uiStaticPath; std::string _uiStaticPath;
std::set<std::string> _authTokens; std::set<std::string> _authTokens;
Mutex _lock; Mutex _lock;

View file

@ -69,11 +69,7 @@
*/ */
//#define ZT_BREAK_UDP //#define ZT_BREAK_UDP
#ifdef ZT_ENABLE_NETWORK_CONTROLLER #include "../controller/EmbeddedNetworkController.hpp"
#include "../controller/SqliteNetworkController.hpp"
#else
class SqliteNetworkController;
#endif // ZT_ENABLE_NETWORK_CONTROLLER
#ifdef __WINDOWS__ #ifdef __WINDOWS__
#include <WinSock2.h> #include <WinSock2.h>
@ -129,7 +125,7 @@ namespace ZeroTier { typedef BSDEthernetTap EthernetTap; }
#define ZT_TAP_CHECK_MULTICAST_INTERVAL 5000 #define ZT_TAP_CHECK_MULTICAST_INTERVAL 5000
// Path under ZT1 home for controller database if controller is enabled // Path under ZT1 home for controller database if controller is enabled
#define ZT_CONTROLLER_DB_PATH "controller.db" #define ZT_CONTROLLER_DB_PATH "controller.d"
// TCP fallback relay host -- geo-distributed using Amazon Route53 geo-aware DNS // TCP fallback relay host -- geo-distributed using Amazon Route53 geo-aware DNS
#define ZT_TCP_FALLBACK_RELAY "tcp-fallback.zerotier.com" #define ZT_TCP_FALLBACK_RELAY "tcp-fallback.zerotier.com"
@ -487,9 +483,7 @@ public:
const std::string _homePath; const std::string _homePath;
BackgroundResolver _tcpFallbackResolver; BackgroundResolver _tcpFallbackResolver;
#ifdef ZT_ENABLE_NETWORK_CONTROLLER EmbeddedNetworkController *_controller;
SqliteNetworkController *_controller;
#endif
Phy<OneServiceImpl *> _phy; Phy<OneServiceImpl *> _phy;
Node *_node; Node *_node;
@ -579,9 +573,7 @@ public:
OneServiceImpl(const char *hp,unsigned int port) : OneServiceImpl(const char *hp,unsigned int port) :
_homePath((hp) ? hp : ".") _homePath((hp) ? hp : ".")
,_tcpFallbackResolver(ZT_TCP_FALLBACK_RELAY) ,_tcpFallbackResolver(ZT_TCP_FALLBACK_RELAY)
#ifdef ZT_ENABLE_NETWORK_CONTROLLER ,_controller((EmbeddedNetworkController *)0)
,_controller((SqliteNetworkController *)0)
#endif
,_phy(this,false,true) ,_phy(this,false,true)
,_node((Node *)0) ,_node((Node *)0)
,_controlPlane((ControlPlane *)0) ,_controlPlane((ControlPlane *)0)
@ -673,9 +665,7 @@ public:
#ifdef ZT_USE_MINIUPNPC #ifdef ZT_USE_MINIUPNPC
delete _portMapper; delete _portMapper;
#endif #endif
#ifdef ZT_ENABLE_NETWORK_CONTROLLER
delete _controller; delete _controller;
#endif
#ifdef ZT_ENABLE_CLUSTER #ifdef ZT_ENABLE_CLUSTER
delete _clusterDefinition; delete _clusterDefinition;
#endif #endif
@ -794,10 +784,8 @@ public:
} }
} }
#ifdef ZT_ENABLE_NETWORK_CONTROLLER _controller = new EmbeddedNetworkController(_node,(_homePath + ZT_PATH_SEPARATOR_S + ZT_CONTROLLER_DB_PATH).c_str());
_controller = new SqliteNetworkController(_node,(_homePath + ZT_PATH_SEPARATOR_S + ZT_CONTROLLER_DB_PATH).c_str(),(_homePath + ZT_PATH_SEPARATOR_S + "circuitTestResults.d").c_str());
_node->setNetconfMaster((void *)_controller); _node->setNetconfMaster((void *)_controller);
#endif
#ifdef ZT_ENABLE_CLUSTER #ifdef ZT_ENABLE_CLUSTER
if (OSUtils::fileExists((_homePath + ZT_PATH_SEPARATOR_S + "cluster").c_str())) { if (OSUtils::fileExists((_homePath + ZT_PATH_SEPARATOR_S + "cluster").c_str())) {
@ -850,10 +838,7 @@ public:
_controlPlane = new ControlPlane(this,_node,(_homePath + ZT_PATH_SEPARATOR_S + "ui").c_str()); _controlPlane = new ControlPlane(this,_node,(_homePath + ZT_PATH_SEPARATOR_S + "ui").c_str());
_controlPlane->addAuthToken(authToken.c_str()); _controlPlane->addAuthToken(authToken.c_str());
#ifdef ZT_ENABLE_NETWORK_CONTROLLER
_controlPlane->setController(_controller); _controlPlane->setController(_controller);
#endif
{ // Remember networks from previous session { // Remember networks from previous session
std::vector<std::string> networksDotD(OSUtils::listDirectory((_homePath + ZT_PATH_SEPARATOR_S + "networks.d").c_str())); std::vector<std::string> networksDotD(OSUtils::listDirectory((_homePath + ZT_PATH_SEPARATOR_S + "networks.d").c_str()));

View file

@ -25,18 +25,6 @@ namespace ZeroTier {
/** /**
* Local service for ZeroTier One as system VPN/NFV provider * Local service for ZeroTier One as system VPN/NFV provider
*
* If built with ZT_ENABLE_NETWORK_CONTROLLER defined, this includes and
* runs controller/SqliteNetworkController with a database called
* controller.db in the specified home directory.
*
* If built with ZT_AUTO_UPDATE, an official ZeroTier update URL is
* periodically checked and updates are automatically downloaded, verified
* against a built-in list of update signing keys, and installed. This is
* only supported for certain platforms.
*
* If built with ZT_ENABLE_CLUSTER, a 'cluster' file is checked and if
* present is read to determine the identity of other cluster members.
*/ */
class OneService class OneService
{ {