From c12b68a6b2f8597e374a4c1386c2b95f4291932e Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Wed, 8 Nov 2017 11:32:01 -0800 Subject: More Central work. --- controller/DB.hpp | 2 +- controller/EmbeddedNetworkController.cpp | 2 +- controller/FileDB.cpp | 2 +- controller/FileDB.hpp | 2 +- controller/RethinkDB.cpp | 14 +++++++------- controller/RethinkDB.hpp | 4 ++-- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/controller/DB.hpp b/controller/DB.hpp index fe06c24d..fca41d70 100644 --- a/controller/DB.hpp +++ b/controller/DB.hpp @@ -84,7 +84,7 @@ public: virtual void eraseMember(const uint64_t networkId,const uint64_t memberId) = 0; - virtual void nodeIsOnline(const uint64_t memberId) = 0; + virtual void nodeIsOnline(const uint64_t networkId,const uint64_t memberId) = 0; protected: struct _Network diff --git a/controller/EmbeddedNetworkController.cpp b/controller/EmbeddedNetworkController.cpp index a2795d96..999319af 100644 --- a/controller/EmbeddedNetworkController.cpp +++ b/controller/EmbeddedNetworkController.cpp @@ -1175,7 +1175,7 @@ void EmbeddedNetworkController::_request( ms.lastRequestTime = now; } - _db->nodeIsOnline(identity.address().toInt()); + _db->nodeIsOnline(nwid,identity.address().toInt()); Utils::hex(nwid,nwids); _db->get(nwid,network,identity.address().toInt(),member,ns); diff --git a/controller/FileDB.cpp b/controller/FileDB.cpp index 646fa2fe..b9f36031 100644 --- a/controller/FileDB.cpp +++ b/controller/FileDB.cpp @@ -126,7 +126,7 @@ void FileDB::eraseMember(const uint64_t networkId,const uint64_t memberId) { } -void FileDB::nodeIsOnline(const uint64_t memberId) +void FileDB::nodeIsOnline(const uint64_t networkId,const uint64_t memberId) { // Nothing to do here right now in the filesystem store mode since we can just get this from the peer list } diff --git a/controller/FileDB.hpp b/controller/FileDB.hpp index 76a47936..b438e80e 100644 --- a/controller/FileDB.hpp +++ b/controller/FileDB.hpp @@ -38,7 +38,7 @@ public: virtual void eraseMember(const uint64_t networkId,const uint64_t memberId); - virtual void nodeIsOnline(const uint64_t memberId); + virtual void nodeIsOnline(const uint64_t networkId,const uint64_t memberId); protected: std::string _networksPath; diff --git a/controller/RethinkDB.cpp b/controller/RethinkDB.cpp index 031bd516..2da55177 100644 --- a/controller/RethinkDB.cpp +++ b/controller/RethinkDB.cpp @@ -227,18 +227,18 @@ RethinkDB::RethinkDB(EmbeddedNetworkController *const nc,const Address &myAddres R::Array batch; R::Object tmpobj; for(auto i=_lastOnline.begin();i!=_lastOnline.end();++i) { - char nodeId[16]; - Utils::hex10(i->first,nodeId); - tmpobj["id"] = nodeId; + char tmp[64]; + OSUtils::ztsnprintf(tmp,sizeof(tmp),"%.16llx-%.10llx",i->first.first,i->first.second); + tmpobj["id"] = tmp; tmpobj["ts"] = i->second; batch.emplace_back(tmpobj); if (batch.size() >= 256) { - R::db(this->_db).table("NodeLastOnline").insert(R::args(batch),R::optargs("conflict","update")).run(*rdb); + R::db(this->_db).table("MemberLastRequest",R::optargs("read_mode","outdated")).insert(R::args(batch),R::optargs("conflict","update")).run(*rdb); batch.clear(); } } if (batch.size() > 0) - R::db(this->_db).table("NodeLastOnline").insert(R::args(batch),R::optargs("conflict","update")).run(*rdb); + R::db(this->_db).table("MemberLastRequest",R::optargs("read_mode","outdated")).insert(R::args(batch),R::optargs("conflict","update")).run(*rdb); _lastOnline.clear(); } } catch (std::exception &e) { @@ -357,10 +357,10 @@ void RethinkDB::eraseMember(const uint64_t networkId,const uint64_t memberId) _commitQueue.post(tmp); } -void RethinkDB::nodeIsOnline(const uint64_t memberId) +void RethinkDB::nodeIsOnline(const uint64_t networkId,const uint64_t memberId) { std::lock_guard l(_lastOnline_l); - _lastOnline[memberId] = OSUtils::now(); + _lastOnline[std::pair(networkId,memberId)] = OSUtils::now(); } } // namespace ZeroTier diff --git a/controller/RethinkDB.hpp b/controller/RethinkDB.hpp index 8c8b16a6..6efa5624 100644 --- a/controller/RethinkDB.hpp +++ b/controller/RethinkDB.hpp @@ -42,7 +42,7 @@ public: virtual void eraseMember(const uint64_t networkId,const uint64_t memberId); - virtual void nodeIsOnline(const uint64_t memberId); + virtual void nodeIsOnline(const uint64_t networkId,const uint64_t memberId); protected: std::string _host; @@ -58,7 +58,7 @@ protected: BlockingQueue< nlohmann::json * > _commitQueue; std::thread _commitThread[ZT_CONTROLLER_RETHINKDB_COMMIT_THREADS]; - std::unordered_map< uint64_t,int64_t > _lastOnline; + std::unordered_map< std::pair,int64_t > _lastOnline; mutable std::mutex _lastOnline_l; std::thread _onlineNotificationThread; -- cgit v1.2.3