From 174ba8884ee68c3a54776ce7fe3f8249aa934ac6 Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Thu, 17 Aug 2017 13:10:10 -0700 Subject: Delete support in harnessed mode. --- controller/JSONDB.cpp | 44 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 9 deletions(-) (limited to 'controller/JSONDB.cpp') diff --git a/controller/JSONDB.cpp b/controller/JSONDB.cpp index 9813239e..f362acf3 100644 --- a/controller/JSONDB.cpp +++ b/controller/JSONDB.cpp @@ -294,9 +294,9 @@ void JSONDB::threadMain() if (obj.is_array()) { for(unsigned long i=0;i &m = _networks[nwid].members[mid]; - update = !m.empty(); + if (!m.empty()) { + update = true; + nlohmann::json oldm(nlohmann::json::from_msgpack(m)); + deauth = ((OSUtils::jsonBool(oldm["authorized"],false))&&(!OSUtils::jsonBool(j["authorized"],false))); + } m = nlohmann::json::to_msgpack(j); _members[mid].insert(nwid); } - if (update) + if (update) { _parent->onNetworkMemberUpdate(nwid,mid); + if (deauth) + _parent->onNetworkMemberDeauthorize(nwid,mid); + } _recomputeSummaryInfo(nwid); return true; } + + } else if (objtype == "_delete") { // pseudo-object-type, only used in Central harnessed mode + + const std::string deleteType(OSUtils::jsonString(j["deleteType"],"")); + id = OSUtils::jsonString(j["deleteId"],""); + if ((deleteType == "network")&&(id.length() == 16)) { + eraseNetwork(Utils::hexStrToU64(id.c_str())); + } else if ((deleteType == "member")&&(id.length() == 10)) { + const std::string networkId(OSUtils::jsonString(j["deleteNetworkId"],"")); + const uint64_t nwid = Utils::hexStrToU64(networkId.c_str()); + const uint64_t mid = Utils::hexStrToU64(id.c_str()); + if (networkId.length() == 16) + eraseNetworkMember(nwid,mid,true); + _parent->onNetworkMemberDeauthorize(nwid,mid); + } + } } } catch ( ... ) {} @@ -455,7 +481,7 @@ bool JSONDB::_load(const std::string &p) std::string buf; if (OSUtils::readFile((p + ZT_PATH_SEPARATOR_S + *di).c_str(),buf)) { try { - _add(OSUtils::jsonParse(buf)); + _addOrUpdate(OSUtils::jsonParse(buf)); } catch ( ... ) {} } } else { -- cgit v1.2.3