From eb7081d2a35dbd80f54c2932182c7be940ac5285 Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Fri, 26 Jul 2019 19:28:09 -0700 Subject: [PATCH] Fix for detecting changes in LF from other instances of the same controller. --- controller/LFDB.cpp | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/controller/LFDB.cpp b/controller/LFDB.cpp index a303d15db..f0c8ebfb9 100644 --- a/controller/LFDB.cpp +++ b/controller/LFDB.cpp @@ -107,7 +107,7 @@ LFDB::LFDB(const Identity &myId,const char *path,const char *lfOwnerPrivate,cons selectors.push_back(selector1); newrec["Selectors"] = selectors; const uint8_t *const rawip = (const uint8_t *)ms->second.lastOnlineAddress.rawIpData(); - switch(ms->second.lastOnlineAddress) { + switch(ms->second.lastOnlineAddress.ss_family) { case AF_INET: for(int j=0;j<4;++j) ip.push_back((unsigned int)rawip[j]); @@ -200,13 +200,24 @@ LFDB::LFDB(const Identity &myId,const char *path,const char *lfOwnerPrivate,cons if (network.is_object()) { const std::string idstr = network["id"]; const uint64_t id = Utils::hexStrToU64(idstr.c_str()); - if ((id >> 24) == controllerAddressInt) { + if ((id >> 24) == controllerAddressInt) { // sanity check + std::lock_guard sl(_state_l); _NetworkState &ns = _state[id]; if (!ns.dirty) { - nlohmann::json nullJson; - _networkChanged(nullJson,network,false); + nlohmann::json oldNetwork; + if (get(id,oldNetwork)) { + const uint64_t revision = network["revision"]; + const uint64_t prevRevision = oldNetwork["revision"]; + if (prevRevision < revision) { + _networkChanged(oldNetwork,network,timeRangeStart > 0); + } + } else { + nlohmann::json nullJson; + _networkChanged(nullJson,network,timeRangeStart > 0); + } } + } } } @@ -257,16 +268,23 @@ LFDB::LFDB(const Identity &myId,const char *path,const char *lfOwnerPrivate,cons const std::string idstr = member["id"]; const uint64_t nwid = Utils::hexStrToU64(nwidstr.c_str()); const uint64_t id = Utils::hexStrToU64(idstr.c_str()); - if ((id)&&((nwid >> 24) == controllerAddressInt)) { + if ((id)&&((nwid >> 24) == controllerAddressInt)) { // sanity check + std::lock_guard sl(_state_l); auto ns = _state.find(nwid); - if (ns != _state.end()) { - _MemberState &ms = ns->second.members[id]; - if (!ms.dirty) { - nlohmann::json nullJson; - _memberChanged(nullJson,member,false); + if ((ns == _state.end())||(!ns->second.members[id].dirty)) { + nlohmann::json network,oldMember; + if (get(nwid,network,id,oldMember)) { + const uint64_t revision = member["revision"]; + const uint64_t prevRevision = oldMember["revision"]; + if (prevRevision < revision) + _memberChanged(oldMember,member,timeRangeStart > 0); } + } else { + nlohmann::json nullJson; + _memberChanged(nullJson,member,timeRangeStart > 0); } + } } }