Răsfoiți Sursa

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.)

Adam Ierymenko 9 ani în urmă
părinte
comite
a13f4d8353

+ 10 - 10
controller/SqliteNetworkController.cpp → controller/EmbeddedNetworkController.cpp

@@ -33,7 +33,7 @@
 #include "../include/ZeroTierOne.h"
 #include "../node/Constants.hpp"
 
-#include "SqliteNetworkController.hpp"
+#include "EmbeddedNetworkController.hpp"
 
 #include "../node/Node.hpp"
 #include "../node/Utils.hpp"
@@ -337,7 +337,7 @@ static bool _parseRule(const json &r,ZT_VirtualNetworkRule &rule)
 	return false;
 }
 
-SqliteNetworkController::SqliteNetworkController(Node *node,const char *dbPath) :
+EmbeddedNetworkController::EmbeddedNetworkController(Node *node,const char *dbPath) :
 	_node(node),
 	_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))) {
 		return NetworkController::NETCONF_QUERY_INTERNAL_SERVER_ERROR;
@@ -898,7 +898,7 @@ NetworkController::ResultCode SqliteNetworkController::doNetworkConfigRequest(co
 	return NetworkController::NETCONF_QUERY_OK;
 }
 
-unsigned int SqliteNetworkController::handleControlPlaneHttpGET(
+unsigned int EmbeddedNetworkController::handleControlPlaneHttpGET(
 	const std::vector<std::string> &path,
 	const std::map<std::string,std::string> &urlArgs,
 	const std::map<std::string,std::string> &headers,
@@ -1040,7 +1040,7 @@ unsigned int SqliteNetworkController::handleControlPlaneHttpGET(
 	return 404;
 }
 
-unsigned int SqliteNetworkController::handleControlPlaneHttpPOST(
+unsigned int EmbeddedNetworkController::handleControlPlaneHttpPOST(
 	const std::vector<std::string> &path,
 	const std::map<std::string,std::string> &urlArgs,
 	const std::map<std::string,std::string> &headers,
@@ -1155,7 +1155,7 @@ unsigned int SqliteNetworkController::handleControlPlaneHttpPOST(
 					te.test = test;
 					te.jsonResults = "";
 
-					_node->circuitTestBegin(test,&(SqliteNetworkController::_circuitTestCallback));
+					_node->circuitTestBegin(test,&(EmbeddedNetworkController::_circuitTestCallback));
 
 					char json[1024];
 					Utils::snprintf(json,sizeof(json),"{\"testId\":\"%.16llx\"}",test->testId);
@@ -1348,7 +1348,7 @@ unsigned int SqliteNetworkController::handleControlPlaneHttpPOST(
 	return 404;
 }
 
-unsigned int SqliteNetworkController::handleControlPlaneHttpDELETE(
+unsigned int EmbeddedNetworkController::handleControlPlaneHttpDELETE(
 	const std::vector<std::string> &path,
 	const std::map<std::string,std::string> &urlArgs,
 	const std::map<std::string,std::string> &headers,
@@ -1394,10 +1394,10 @@ unsigned int SqliteNetworkController::handleControlPlaneHttpDELETE(
 	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];
-	SqliteNetworkController *const self = reinterpret_cast<SqliteNetworkController *>(test->ptr);
+	EmbeddedNetworkController *const self = reinterpret_cast<EmbeddedNetworkController *>(test->ptr);
 
 	if (!test)
 		return;

+ 3 - 3
controller/SqliteNetworkController.hpp → controller/EmbeddedNetworkController.hpp

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

+ 0 - 6
make-linux.mk

@@ -82,12 +82,6 @@ ifeq ($(ZT_USE_MINIUPNPC),1)
 	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)
 	DEFS+=-DZT_ENABLE_CLUSTER
 endif

+ 0 - 6
make-mac.mk

@@ -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
 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
 ifeq ($(ZT_DEBUG),1)
 	DEFS+=-DZT_TRACE

+ 1 - 0
objects.mk

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

+ 0 - 4
selftest.cpp

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

+ 2 - 18
service/ControlPlane.cpp

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

+ 3 - 7
service/ControlPlane.hpp

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

+ 5 - 20
service/OneService.cpp

@@ -69,11 +69,7 @@
  */
 //#define ZT_BREAK_UDP
 
-#ifdef ZT_ENABLE_NETWORK_CONTROLLER
-#include "../controller/SqliteNetworkController.hpp"
-#else
-class SqliteNetworkController;
-#endif // ZT_ENABLE_NETWORK_CONTROLLER
+#include "../controller/EmbeddedNetworkController.hpp"
 
 #ifdef __WINDOWS__
 #include <WinSock2.h>
@@ -129,7 +125,7 @@ namespace ZeroTier { typedef BSDEthernetTap EthernetTap; }
 #define ZT_TAP_CHECK_MULTICAST_INTERVAL 5000
 
 // 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
 #define ZT_TCP_FALLBACK_RELAY "tcp-fallback.zerotier.com"
@@ -487,9 +483,7 @@ public:
 
 	const std::string _homePath;
 	BackgroundResolver _tcpFallbackResolver;
-#ifdef ZT_ENABLE_NETWORK_CONTROLLER
-	SqliteNetworkController *_controller;
-#endif
+	EmbeddedNetworkController *_controller;
 	Phy<OneServiceImpl *> _phy;
 	Node *_node;
 
@@ -579,9 +573,7 @@ public:
 	OneServiceImpl(const char *hp,unsigned int port) :
 		_homePath((hp) ? hp : ".")
 		,_tcpFallbackResolver(ZT_TCP_FALLBACK_RELAY)
-#ifdef ZT_ENABLE_NETWORK_CONTROLLER
-		,_controller((SqliteNetworkController *)0)
-#endif
+		,_controller((EmbeddedNetworkController *)0)
 		,_phy(this,false,true)
 		,_node((Node *)0)
 		,_controlPlane((ControlPlane *)0)
@@ -673,9 +665,7 @@ public:
 #ifdef ZT_USE_MINIUPNPC
 		delete _portMapper;
 #endif
-#ifdef ZT_ENABLE_NETWORK_CONTROLLER
 		delete _controller;
-#endif
 #ifdef ZT_ENABLE_CLUSTER
 		delete _clusterDefinition;
 #endif
@@ -794,10 +784,8 @@ public:
 				}
 			}
 
-#ifdef ZT_ENABLE_NETWORK_CONTROLLER
-			_controller = new SqliteNetworkController(_node,(_homePath + ZT_PATH_SEPARATOR_S + ZT_CONTROLLER_DB_PATH).c_str(),(_homePath + ZT_PATH_SEPARATOR_S + "circuitTestResults.d").c_str());
+			_controller = new EmbeddedNetworkController(_node,(_homePath + ZT_PATH_SEPARATOR_S + ZT_CONTROLLER_DB_PATH).c_str());
 			_node->setNetconfMaster((void *)_controller);
-#endif
 
 #ifdef ZT_ENABLE_CLUSTER
 			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->addAuthToken(authToken.c_str());
-
-#ifdef ZT_ENABLE_NETWORK_CONTROLLER
 			_controlPlane->setController(_controller);
-#endif
 
 			{	// Remember networks from previous session
 				std::vector<std::string> networksDotD(OSUtils::listDirectory((_homePath + ZT_PATH_SEPARATOR_S + "networks.d").c_str()));

+ 0 - 12
service/OneService.hpp

@@ -25,18 +25,6 @@ namespace ZeroTier {
 
 /**
  * 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
 {