From 8d9464c4140e5882b0fc9276388401514f29e62a Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Thu, 7 Dec 2017 13:39:25 -0800 Subject: [PATCH] docs, and make RethinkDB controller DB driver upsert into the Controller DB and also update the hostname field. --- RELEASE-NOTES.md | 13 ++++++++ controller/DB.cpp | 5 +-- controller/DB.hpp | 5 +-- controller/EmbeddedNetworkController.cpp | 4 +-- controller/FileDB.cpp | 4 +-- controller/FileDB.hpp | 2 +- controller/RethinkDB.cpp | 40 +++++++++++++++++++++--- controller/RethinkDB.hpp | 2 +- 8 files changed, 60 insertions(+), 15 deletions(-) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 195e88881..86522cea0 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -1,6 +1,19 @@ ZeroTier Release Notes ====== +# 2017-12-XX -- Version 1.2.6 + + * Network Hypervisor + * We've made some improvements to dead path detection and path selection. These also include changes under the hood to prepare for multi-path trunking and faster fail-over support. + * Platform-Specific Changes + * MacOS + * Installer now loads the kernel extension right away so that High Sierra users will see the prompt to authorize it. This is done in the "Security & Privacy" preference pane and must be done driectly on the console (not via remote desktop). + * Windows + * The Windows installer should now install the driver without requiring a special prompt in most cases. This should make it easier for our packages to be accepted into and updated in the Chocolatey repository and should make it easier to perform remote installs. + * The Windows official packages are now signed with an EV certificate (with hardware key) from DigiCert. + * The Windows UI now contains a preview of features to more deeply integrate it with ZeroTier Central. You can enter a ZeroTier Central API key and join networks, etc. from the UI itself. We'll be expanding this in the future and possibly changing it, so this is just a test to see how users respond. + * The `zerotier-idtool` command should now work on Windows. + # 2017-04-20 -- Version 1.2.4 * Managed routes are now only bifurcated for the default route. This is a change in behavior, though few people will probably notice. Bifurcating all managed routes was causing more trouble than it was worth for most users. diff --git a/controller/DB.cpp b/controller/DB.cpp index 2f9a4a896..2f09205b9 100644 --- a/controller/DB.cpp +++ b/controller/DB.cpp @@ -27,9 +27,10 @@ using json = nlohmann::json; namespace ZeroTier { -DB::DB(EmbeddedNetworkController *const nc,const Address &myAddress,const char *path) : +DB::DB(EmbeddedNetworkController *const nc,const Identity &myId,const char *path) : _controller(nc), - _myAddress(myAddress), + _myId(myId), + _myAddress(myId.address()), _path((path) ? path : "") { char tmp[32]; diff --git a/controller/DB.hpp b/controller/DB.hpp index 8731cb5c4..4c7a16b2c 100644 --- a/controller/DB.hpp +++ b/controller/DB.hpp @@ -20,7 +20,7 @@ #define ZT_CONTROLLER_DB_HPP #include "../node/Constants.hpp" -#include "../node/Address.hpp" +#include "../node/Identity.hpp" #include "../node/InetAddress.hpp" #include "../osdep/OSUtils.hpp" #include "../osdep/BlockingQueue.hpp" @@ -58,7 +58,7 @@ public: int64_t mostRecentDeauthTime; }; - DB(EmbeddedNetworkController *const nc,const Address &myAddress,const char *path); + DB(EmbeddedNetworkController *const nc,const Identity &myId,const char *path); virtual ~DB(); virtual bool waitForReady() = 0; @@ -104,6 +104,7 @@ protected: void _fillSummaryInfo(const std::shared_ptr<_Network> &nw,NetworkSummaryInfo &info); EmbeddedNetworkController *const _controller; + const Identity _myId; const Address _myAddress; const std::string _path; std::string _myAddressStr; diff --git a/controller/EmbeddedNetworkController.cpp b/controller/EmbeddedNetworkController.cpp index a3ce92085..d97a1ce21 100644 --- a/controller/EmbeddedNetworkController.cpp +++ b/controller/EmbeddedNetworkController.cpp @@ -477,10 +477,10 @@ void EmbeddedNetworkController::init(const Identity &signingId,Sender *sender) _signingIdAddressString = signingId.address().toString(tmp); #ifdef ZT_CONTROLLER_USE_RETHINKDB if ((_path.length() > 10)&&(_path.substr(0,10) == "rethinkdb:")) - _db.reset(new RethinkDB(this,_signingId.address(),_path.c_str())); + _db.reset(new RethinkDB(this,_signingId,_path.c_str())); else // else use FileDB after endif #endif - _db.reset(new FileDB(this,_signingId.address(),_path.c_str())); + _db.reset(new FileDB(this,_signingId,_path.c_str())); _db->waitForReady(); } diff --git a/controller/FileDB.cpp b/controller/FileDB.cpp index 3f8564fae..6b02f8369 100644 --- a/controller/FileDB.cpp +++ b/controller/FileDB.cpp @@ -21,8 +21,8 @@ namespace ZeroTier { -FileDB::FileDB(EmbeddedNetworkController *const nc,const Address &myAddress,const char *path) : - DB(nc,myAddress,path), +FileDB::FileDB(EmbeddedNetworkController *const nc,const Identity &myId,const char *path) : + DB(nc,myId,path), _networksPath(_path + ZT_PATH_SEPARATOR_S + "network") { OSUtils::mkdir(_path.c_str()); diff --git a/controller/FileDB.hpp b/controller/FileDB.hpp index e31b18e60..eeb1c541b 100644 --- a/controller/FileDB.hpp +++ b/controller/FileDB.hpp @@ -27,7 +27,7 @@ namespace ZeroTier class FileDB : public DB { public: - FileDB(EmbeddedNetworkController *const nc,const Address &myAddress,const char *path); + FileDB(EmbeddedNetworkController *const nc,const Identity &myId,const char *path); virtual ~FileDB(); virtual bool waitForReady(); diff --git a/controller/RethinkDB.cpp b/controller/RethinkDB.cpp index e6b58efd9..b4f07f53b 100644 --- a/controller/RethinkDB.cpp +++ b/controller/RethinkDB.cpp @@ -18,6 +18,8 @@ #ifdef ZT_CONTROLLER_USE_RETHINKDB +#include + #include "RethinkDB.hpp" #include "EmbeddedNetworkController.hpp" @@ -34,8 +36,8 @@ using json = nlohmann::json; namespace ZeroTier { -RethinkDB::RethinkDB(EmbeddedNetworkController *const nc,const Address &myAddress,const char *path) : - DB(nc,myAddress,path), +RethinkDB::RethinkDB(EmbeddedNetworkController *const nc,const Identity &myId,const char *path) : + DB(nc,myId,path), _ready(2), // two tables need to be synchronized before we're ready, so this is ready when it reaches 0 _run(1), _waitNoticePrinted(false) @@ -317,16 +319,44 @@ RethinkDB::RethinkDB(EmbeddedNetworkController *const nc,const Address &myAddres _heartbeatThread = std::thread([this]() { try { - char tmp[1024]; + R::Object controllerRecord; std::unique_ptr rdb; + + { + char publicId[1024]; + char secretId[1024]; + char hostname[1024]; + this->_myId.toString(publicId,false); + this->_myId.toString(secretId,true); + if (gethostname(hostname,sizeof(hostname)) != 0) { + hostname[0] = (char)0; + } else { + for(int i=0;i_myAddressStr.c_str(); + controllerRecord["publicIdentity"] = publicId; + controllerRecord["secretIdentity"] = secretId; + if (hostname[0]) + controllerRecord["clusterHost"] = hostname; + controllerRecord["vMajor"] = ZEROTIER_ONE_VERSION_MAJOR; + controllerRecord["vMinor"] = ZEROTIER_ONE_VERSION_MINOR; + controllerRecord["vRev"] = ZEROTIER_ONE_VERSION_REVISION; + controllerRecord["vBuild"] = ZEROTIER_ONE_VERSION_BUILD; + } + while (_run == 1) { try { if (!rdb) rdb = R::connect(this->_host,this->_port,this->_auth); if (rdb) { - OSUtils::ztsnprintf(tmp,sizeof(tmp),"{\"id\":\"%s\",\"lastAlive\":%lld,\"version\":\"%d.%d.%d\"}",this->_myAddressStr.c_str(),(long long)OSUtils::now(),ZEROTIER_ONE_VERSION_MAJOR,ZEROTIER_ONE_VERSION_MINOR,ZEROTIER_ONE_VERSION_REVISION); + controllerRecord["lastAlive"] = OSUtils::now(); //printf("HEARTBEAT: %s" ZT_EOL_S,tmp); - R::db(this->_db).table("Controller").update(R::Datum::from_json(tmp)).run(*rdb); + R::db(this->_db).table("Controller",R::optargs("read_mode","outdated")).insert(controllerRecord,R::optargs("conflict","update")).run(*rdb); } } catch ( ... ) { rdb.reset(); diff --git a/controller/RethinkDB.hpp b/controller/RethinkDB.hpp index a69f462f4..07f0abfbb 100644 --- a/controller/RethinkDB.hpp +++ b/controller/RethinkDB.hpp @@ -37,7 +37,7 @@ namespace ZeroTier class RethinkDB : public DB { public: - RethinkDB(EmbeddedNetworkController *const nc,const Address &myAddress,const char *path); + RethinkDB(EmbeddedNetworkController *const nc,const Identity &myId,const char *path); virtual ~RethinkDB(); virtual bool waitForReady();