From 4704d115c4073f6bca0496222a1e4b0738bf4bf6 Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Thu, 14 Dec 2017 08:53:24 -0800 Subject: [PATCH] Some controller fixes. --- controller/EmbeddedNetworkController.cpp | 3 --- controller/EmbeddedNetworkController.hpp | 1 - controller/RethinkDB.cpp | 22 +++++++--------------- 3 files changed, 7 insertions(+), 19 deletions(-) diff --git a/controller/EmbeddedNetworkController.cpp b/controller/EmbeddedNetworkController.cpp index d97a1ce21..d8ac1878f 100644 --- a/controller/EmbeddedNetworkController.cpp +++ b/controller/EmbeddedNetworkController.cpp @@ -1277,9 +1277,6 @@ void EmbeddedNetworkController::_request( ms.vProto = (int)vProto; ms.lastRequestMetaData = metaData; ms.identity = identity; - - if (fromAddr) - ms.physicalAddr = fromAddr; } } } else { diff --git a/controller/EmbeddedNetworkController.hpp b/controller/EmbeddedNetworkController.hpp index 31b5b2b52..5864100dc 100644 --- a/controller/EmbeddedNetworkController.hpp +++ b/controller/EmbeddedNetworkController.hpp @@ -198,7 +198,6 @@ private: int vMajor,vMinor,vRev,vProto; Dictionary lastRequestMetaData; Identity identity; - InetAddress physicalAddr; // last known physical address inline bool online(const int64_t now) const { return ((now - lastRequestTime) < (ZT_NETWORK_AUTOCONF_DELAY * 2)); } }; struct _MemberStatusHash diff --git a/controller/RethinkDB.cpp b/controller/RethinkDB.cpp index 6880370ff..b7d045711 100644 --- a/controller/RethinkDB.cpp +++ b/controller/RethinkDB.cpp @@ -16,6 +16,8 @@ * along with this program. If not, see . */ +//#define ZT_CONTROLLER_USE_RETHINKDB + #ifdef ZT_CONTROLLER_USE_RETHINKDB #include @@ -164,7 +166,7 @@ RethinkDB::RethinkDB(EmbeddedNetworkController *const nc,const Identity &myId,co while ((this->_commitQueue.get(config))&&(_run == 1)) { if (!config) continue; - json record; + nlohmann::json record; const char *table = (const char *)0; std::string deleteId; try { @@ -182,7 +184,7 @@ RethinkDB::RethinkDB(EmbeddedNetworkController *const nc,const Identity &myId,co const std::string id = (*config)["id"]; record["id"] = id; record["controllerId"] = this->_myAddressStr; - record["config"] = *config; + record["config"] = *config; table = "Network"; } else if (objtype == "trace") { record = *config; @@ -221,7 +223,7 @@ RethinkDB::RethinkDB(EmbeddedNetworkController *const nc,const Identity &myId,co R::db(this->_db).table(table).get(deleteId).delete_().run(*rdb); } else { //printf("UPSERT: %s" ZT_EOL_S,record.dump().c_str()); - R::db(this->_db).table(table).insert(R::Datum::from_json(record.dump()),R::optargs("conflict","update","return_changes",false)).run(*rdb); + R::db(this->_db).table(table).insert(R::Datum::from_json(OSUtils::jsonDump(record,-1)),R::optargs("conflict","update","return_changes",false)).run(*rdb); } break; } else { @@ -436,18 +438,8 @@ void RethinkDB::save(nlohmann::json *orig,nlohmann::json &record) waitForReady(); if (orig) { if (*orig != record) { - nlohmann::json *q = new nlohmann::json(); - try { - record["revision"] = OSUtils::jsonInt(record["revision"],0ULL) + 1; - for(auto kv=record.begin();kv!=record.end();++kv) { - if ((kv.key() == "id")||(kv.key() == "nwid")||(kv.key() == "objtype")||((*q)[kv.key()] != kv.value())) - (*q)[kv.key()] = kv.value(); - } - _commitQueue.post(new nlohmann::json(record)); - } catch ( ... ) { - delete q; - throw; - } + record["revision"] = OSUtils::jsonInt(record["revision"],0ULL) + 1; + _commitQueue.post(new nlohmann::json(record)); } } else { record["revision"] = 1;