diff --git a/controller/DB.hpp b/controller/DB.hpp index fca41d708..8731cb5c4 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 networkId,const uint64_t memberId) = 0; + virtual void nodeIsOnline(const uint64_t networkId,const uint64_t memberId,const InetAddress &physicalAddress) = 0; protected: struct _Network diff --git a/controller/EmbeddedNetworkController.cpp b/controller/EmbeddedNetworkController.cpp index 999319af3..0f82ff633 100644 --- a/controller/EmbeddedNetworkController.cpp +++ b/controller/EmbeddedNetworkController.cpp @@ -1175,7 +1175,7 @@ void EmbeddedNetworkController::_request( ms.lastRequestTime = now; } - _db->nodeIsOnline(nwid,identity.address().toInt()); + _db->nodeIsOnline(nwid,identity.address().toInt(),fromAddr); Utils::hex(nwid,nwids); _db->get(nwid,network,identity.address().toInt(),member,ns); diff --git a/controller/FileDB.cpp b/controller/FileDB.cpp index b9f360316..728cec6b5 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 networkId,const uint64_t memberId) +void FileDB::nodeIsOnline(const uint64_t networkId,const uint64_t memberId,const InetAddress &physicalAddress) { // 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 b438e80ee..e31b18e60 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 networkId,const uint64_t memberId); + virtual void nodeIsOnline(const uint64_t networkId,const uint64_t memberId,const InetAddress &physicalAddress); protected: std::string _networksPath; diff --git a/controller/RethinkDB.cpp b/controller/RethinkDB.cpp index 6583f23cb..cd968e26f 100644 --- a/controller/RethinkDB.cpp +++ b/controller/RethinkDB.cpp @@ -227,10 +227,11 @@ RethinkDB::RethinkDB(EmbeddedNetworkController *const nc,const Address &myAddres R::Array batch; R::Object tmpobj; for(auto i=_lastOnline.begin();i!=_lastOnline.end();++i) { - char tmp[64]; + char tmp[64],tmp2[64]; OSUtils::ztsnprintf(tmp,sizeof(tmp),"%.16llx-%.10llx",i->first.first,i->first.second); tmpobj["id"] = tmp; - tmpobj["ts"] = i->second; + tmpobj["ts"] = i->second.first; + tmpobj["phy"] = i->second.second.toIpString(tmp2); batch.emplace_back(tmpobj); if (batch.size() >= 256) { R::db(this->_db).table("MemberLastRequest",R::optargs("read_mode","outdated")).insert(batch,R::optargs("conflict","update")).run(*rdb); @@ -357,10 +358,13 @@ void RethinkDB::eraseMember(const uint64_t networkId,const uint64_t memberId) _commitQueue.post(tmp); } -void RethinkDB::nodeIsOnline(const uint64_t networkId,const uint64_t memberId) +void RethinkDB::nodeIsOnline(const uint64_t networkId,const uint64_t memberId,const InetAddress &physicalAddress) { std::lock_guard l(_lastOnline_l); - _lastOnline[std::pair(networkId,memberId)] = OSUtils::now(); + std::pair &i = _lastOnline[std::pair(networkId,memberId)]; + i.first = OSUtils::now(); + if (physicalAddress) + i.second = physicalAddress; } } // namespace ZeroTier diff --git a/controller/RethinkDB.hpp b/controller/RethinkDB.hpp index 269870192..a69f462f4 100644 --- a/controller/RethinkDB.hpp +++ b/controller/RethinkDB.hpp @@ -48,7 +48,7 @@ public: virtual void eraseMember(const uint64_t networkId,const uint64_t memberId); - virtual void nodeIsOnline(const uint64_t networkId,const uint64_t memberId); + virtual void nodeIsOnline(const uint64_t networkId,const uint64_t memberId,const InetAddress &physicalAddress); protected: struct _PairHasher @@ -69,7 +69,7 @@ protected: BlockingQueue< nlohmann::json * > _commitQueue; std::thread _commitThread[ZT_CONTROLLER_RETHINKDB_COMMIT_THREADS]; - std::unordered_map< std::pair,int64_t,_PairHasher > _lastOnline; + std::unordered_map< std::pair,std::pair,_PairHasher > _lastOnline; mutable std::mutex _lastOnline_l; std::thread _onlineNotificationThread;