summaryrefslogtreecommitdiff
path: root/controller
diff options
context:
space:
mode:
Diffstat (limited to 'controller')
-rw-r--r--controller/DB.cpp5
-rw-r--r--controller/DB.hpp5
-rw-r--r--controller/EmbeddedNetworkController.cpp4
-rw-r--r--controller/FileDB.cpp4
-rw-r--r--controller/FileDB.hpp2
-rw-r--r--controller/RethinkDB.cpp40
-rw-r--r--controller/RethinkDB.hpp2
7 files changed, 47 insertions, 15 deletions
diff --git a/controller/DB.cpp b/controller/DB.cpp
index 2f9a4a89..2f09205b 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 8731cb5c..4c7a16b2 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 a3ce9208..d97a1ce2 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 3f8564fa..6b02f836 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 e31b18e6..eeb1c541 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 e6b58efd..b4f07f53 100644
--- a/controller/RethinkDB.cpp
+++ b/controller/RethinkDB.cpp
@@ -18,6 +18,8 @@
#ifdef ZT_CONTROLLER_USE_RETHINKDB
+#include <unistd.h>
+
#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<R::Connection> 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<sizeof(hostname);++i) {
+ if ((hostname[i] == '.')||(hostname[i] == 0)) {
+ hostname[i] = (char)0;
+ break;
+ }
+ }
+ }
+ controllerRecord["id"] = this->_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 a69f462f..07f0abfb 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();