summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@gmail.com>2019-07-26 19:28:09 -0700
committerAdam Ierymenko <adam.ierymenko@gmail.com>2019-07-26 19:28:09 -0700
commiteb7081d2a35dbd80f54c2932182c7be940ac5285 (patch)
treeedaa5d3ed56029ff26f3052a0afde528d9de4c12
parentd9befe3fb38973a014f383a38fa126ca218ca732 (diff)
downloadinfinitytier-eb7081d2a35dbd80f54c2932182c7be940ac5285.tar.gz
infinitytier-eb7081d2a35dbd80f54c2932182c7be940ac5285.zip
Fix for detecting changes in LF from other instances of the same controller.
-rw-r--r--controller/LFDB.cpp38
1 files changed, 28 insertions, 10 deletions
diff --git a/controller/LFDB.cpp b/controller/LFDB.cpp
index a303d15d..f0c8ebfb 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<std::mutex> 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<std::mutex> 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);
}
+
}
}
}