|
@@ -85,38 +85,35 @@ FileDB::~FileDB()
|
|
bool FileDB::waitForReady() { return true; }
|
|
bool FileDB::waitForReady() { return true; }
|
|
bool FileDB::isReady() { return true; }
|
|
bool FileDB::isReady() { return true; }
|
|
|
|
|
|
-void FileDB::save(nlohmann::json *orig,nlohmann::json &record)
|
|
|
|
|
|
+void FileDB::save(nlohmann::json &record)
|
|
{
|
|
{
|
|
char p1[4096],p2[4096],pb[4096];
|
|
char p1[4096],p2[4096],pb[4096];
|
|
try {
|
|
try {
|
|
- if (orig) {
|
|
|
|
- if (*orig != record) {
|
|
|
|
- record["revision"] = OSUtils::jsonInt(record["revision"],0ULL) + 1;
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- record["revision"] = 1;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
const std::string objtype = record["objtype"];
|
|
const std::string objtype = record["objtype"];
|
|
if (objtype == "network") {
|
|
if (objtype == "network") {
|
|
|
|
+
|
|
const uint64_t nwid = OSUtils::jsonIntHex(record["id"],0ULL);
|
|
const uint64_t nwid = OSUtils::jsonIntHex(record["id"],0ULL);
|
|
if (nwid) {
|
|
if (nwid) {
|
|
nlohmann::json old;
|
|
nlohmann::json old;
|
|
get(nwid,old);
|
|
get(nwid,old);
|
|
if ((!old.is_object())||(old != record)) {
|
|
if ((!old.is_object())||(old != record)) {
|
|
|
|
+ record["revision"] = OSUtils::jsonInt(record["revision"],0ULL) + 1ULL;
|
|
OSUtils::ztsnprintf(p1,sizeof(p1),"%s" ZT_PATH_SEPARATOR_S "%.16llx.json",_networksPath.c_str(),nwid);
|
|
OSUtils::ztsnprintf(p1,sizeof(p1),"%s" ZT_PATH_SEPARATOR_S "%.16llx.json",_networksPath.c_str(),nwid);
|
|
if (!OSUtils::writeFile(p1,OSUtils::jsonDump(record,-1)))
|
|
if (!OSUtils::writeFile(p1,OSUtils::jsonDump(record,-1)))
|
|
fprintf(stderr,"WARNING: controller unable to write to path: %s" ZT_EOL_S,p1);
|
|
fprintf(stderr,"WARNING: controller unable to write to path: %s" ZT_EOL_S,p1);
|
|
_networkChanged(old,record,true);
|
|
_networkChanged(old,record,true);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
} else if (objtype == "member") {
|
|
} else if (objtype == "member") {
|
|
|
|
+
|
|
const uint64_t id = OSUtils::jsonIntHex(record["id"],0ULL);
|
|
const uint64_t id = OSUtils::jsonIntHex(record["id"],0ULL);
|
|
const uint64_t nwid = OSUtils::jsonIntHex(record["nwid"],0ULL);
|
|
const uint64_t nwid = OSUtils::jsonIntHex(record["nwid"],0ULL);
|
|
if ((id)&&(nwid)) {
|
|
if ((id)&&(nwid)) {
|
|
nlohmann::json network,old;
|
|
nlohmann::json network,old;
|
|
get(nwid,network,id,old);
|
|
get(nwid,network,id,old);
|
|
if ((!old.is_object())||(old != record)) {
|
|
if ((!old.is_object())||(old != record)) {
|
|
|
|
+ record["revision"] = OSUtils::jsonInt(record["revision"],0ULL) + 1ULL;
|
|
OSUtils::ztsnprintf(pb,sizeof(pb),"%s" ZT_PATH_SEPARATOR_S "%.16llx" ZT_PATH_SEPARATOR_S "member",_networksPath.c_str(),(unsigned long long)nwid);
|
|
OSUtils::ztsnprintf(pb,sizeof(pb),"%s" ZT_PATH_SEPARATOR_S "%.16llx" ZT_PATH_SEPARATOR_S "member",_networksPath.c_str(),(unsigned long long)nwid);
|
|
OSUtils::ztsnprintf(p1,sizeof(p1),"%s" ZT_PATH_SEPARATOR_S "%.10llx.json",pb,(unsigned long long)id);
|
|
OSUtils::ztsnprintf(p1,sizeof(p1),"%s" ZT_PATH_SEPARATOR_S "%.10llx.json",pb,(unsigned long long)id);
|
|
if (!OSUtils::writeFile(p1,OSUtils::jsonDump(record,-1))) {
|
|
if (!OSUtils::writeFile(p1,OSUtils::jsonDump(record,-1))) {
|
|
@@ -129,12 +126,7 @@ void FileDB::save(nlohmann::json *orig,nlohmann::json &record)
|
|
_memberChanged(old,record,true);
|
|
_memberChanged(old,record,true);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- } else if (objtype == "trace") {
|
|
|
|
- const std::string id = record["id"];
|
|
|
|
- if (id.length() > 0) {
|
|
|
|
- OSUtils::ztsnprintf(p1,sizeof(p1),"%s" ZT_PATH_SEPARATOR_S "%s.json",_tracePath.c_str(),id.c_str());
|
|
|
|
- OSUtils::writeFile(p1,OSUtils::jsonDump(record,-1));
|
|
|
|
- }
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
} catch ( ... ) {} // drop invalid records missing fields
|
|
} catch ( ... ) {} // drop invalid records missing fields
|
|
}
|
|
}
|