mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-04-09 04:04:13 +00:00
Merge branch 'dev' into edge
This commit is contained in:
commit
52cc482521
@ -114,6 +114,28 @@ public:
|
||||
}
|
||||
|
||||
protected:
|
||||
inline bool _compareRecords(const nlohmann::json &a,const nlohmann::json &b)
|
||||
{
|
||||
if (a.is_object() == b.is_object()) {
|
||||
if (a.is_object()) {
|
||||
if (a.size() != b.size())
|
||||
return false;
|
||||
auto amap = a.get<nlohmann::json::object_t>();
|
||||
auto bmap = b.get<nlohmann::json::object_t>();
|
||||
for(auto ai=amap.begin();ai!=amap.end();++ai) {
|
||||
if (ai->first != "revision") { // ignore revision, compare only non-revision-counter fields
|
||||
auto bi = bmap.find(ai->first);
|
||||
if ((bi == bmap.end())||(bi->second != ai->second))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return (a == b);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
struct _Network
|
||||
{
|
||||
_Network() : mostRecentDeauthTime(0) {}
|
||||
|
@ -125,14 +125,14 @@ bool DBMirrorSet::save(nlohmann::json &record,bool notifyListeners)
|
||||
}
|
||||
if (notifyListeners) {
|
||||
for(auto d=dbs.begin();d!=dbs.end();++d) {
|
||||
if ((*d)->save(record,notifyListeners))
|
||||
if ((*d)->save(record,true))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
} else {
|
||||
bool modified = false;
|
||||
for(auto d=dbs.begin();d!=dbs.end();++d) {
|
||||
modified |= (*d)->save(record,notifyListeners);
|
||||
modified |= (*d)->save(record,false);
|
||||
}
|
||||
return modified;
|
||||
}
|
||||
|
@ -96,7 +96,7 @@ bool FileDB::save(nlohmann::json &record,bool notifyListeners)
|
||||
if (nwid) {
|
||||
nlohmann::json old;
|
||||
get(nwid,old);
|
||||
if ((!old.is_object())||(old != record)) {
|
||||
if ((!old.is_object())||(!_compareRecords(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);
|
||||
if (!OSUtils::writeFile(p1,OSUtils::jsonDump(record,-1)))
|
||||
@ -113,7 +113,7 @@ bool FileDB::save(nlohmann::json &record,bool notifyListeners)
|
||||
if ((id)&&(nwid)) {
|
||||
nlohmann::json network,old;
|
||||
get(nwid,network,id,old);
|
||||
if ((!old.is_object())||(old != record)) {
|
||||
if ((!old.is_object())||(!_compareRecords(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(p1,sizeof(p1),"%s" ZT_PATH_SEPARATOR_S "%.10llx.json",pb,(unsigned long long)id);
|
||||
|
@ -369,7 +369,7 @@ bool LFDB::save(nlohmann::json &record,bool notifyListeners)
|
||||
if (nwid) {
|
||||
nlohmann::json old;
|
||||
get(nwid,old);
|
||||
if ((!old.is_object())||(old != record)) {
|
||||
if ((!old.is_object())||(!_compareRecords(old,record))) {
|
||||
record["revision"] = OSUtils::jsonInt(record["revision"],0ULL) + 1ULL;
|
||||
_networkChanged(old,record,notifyListeners);
|
||||
{
|
||||
@ -385,7 +385,7 @@ bool LFDB::save(nlohmann::json &record,bool notifyListeners)
|
||||
if ((id)&&(nwid)) {
|
||||
nlohmann::json network,old;
|
||||
get(nwid,network,id,old);
|
||||
if ((!old.is_object())||(old != record)) {
|
||||
if ((!old.is_object())||(!_compareRecords(old,record))) {
|
||||
record["revision"] = OSUtils::jsonInt(record["revision"],0ULL) + 1ULL;
|
||||
_memberChanged(old,record,notifyListeners);
|
||||
{
|
||||
|
@ -183,7 +183,7 @@ bool PostgreSQL::save(nlohmann::json &record,bool notifyListeners)
|
||||
if (nwid) {
|
||||
nlohmann::json old;
|
||||
get(nwid,old);
|
||||
if ((!old.is_object())||(old != record)) {
|
||||
if ((!old.is_object())||(!_compareRecords(old,record))) {
|
||||
record["revision"] = OSUtils::jsonInt(record["revision"],0ULL) + 1ULL;
|
||||
_commitQueue.post(std::pair<nlohmann::json,bool>(record,notifyListeners));
|
||||
modified = true;
|
||||
@ -195,25 +195,13 @@ bool PostgreSQL::save(nlohmann::json &record,bool notifyListeners)
|
||||
if ((id)&&(nwid)) {
|
||||
nlohmann::json network,old;
|
||||
get(nwid,network,id,old);
|
||||
if ((!old.is_object())||(old != record)) {
|
||||
if ((!old.is_object())||(!_compareRecords(old,record))) {
|
||||
record["revision"] = OSUtils::jsonInt(record["revision"],0ULL) + 1ULL;
|
||||
_commitQueue.post(std::pair<nlohmann::json,bool>(record,notifyListeners));
|
||||
modified = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
waitForReady();
|
||||
if (orig) {
|
||||
if (*orig != record) {
|
||||
record["revision"] = OSUtils::jsonInt(record["revision"],0ULL) + 1;
|
||||
_commitQueue.post(new nlohmann::json(record));
|
||||
}
|
||||
} else {
|
||||
record["revision"] = 1;
|
||||
_commitQueue.post(new nlohmann::json(record));
|
||||
}
|
||||
*/
|
||||
} catch (std::exception &e) {
|
||||
fprintf(stderr, "Error on PostgreSQL::save: %s\n", e.what());
|
||||
} catch (...) {
|
||||
|
@ -100,6 +100,9 @@ using json = nlohmann::json;
|
||||
#include "../controller/EmbeddedNetworkController.hpp"
|
||||
#include "../controller/RabbitMQ.hpp"
|
||||
#include "../osdep/EthernetTap.hpp"
|
||||
#ifdef __WINDOWS__
|
||||
#include "../osdep/WindowsEthernetTap.hpp"
|
||||
#endif
|
||||
|
||||
#ifndef ZT_SOFTWARE_UPDATE_DEFAULT
|
||||
#define ZT_SOFTWARE_UPDATE_DEFAULT "disable"
|
||||
@ -1639,7 +1642,7 @@ public:
|
||||
if (syncRoutes) {
|
||||
char tapdev[64];
|
||||
#if defined(__WINDOWS__) && !defined(ZT_SDK)
|
||||
OSUtils::ztsnprintf(tapdev,sizeof(tapdev),"%.16llx",(unsigned long long)n.tap->luid().Value);
|
||||
OSUtils::ztsnprintf(tapdev,sizeof(tapdev),"%.16llx",(unsigned long long)((WindowsEthernetTap *)(n.tap.get()))->luid().Value);
|
||||
#else
|
||||
Utils::scopy(tapdev,sizeof(tapdev),n.tap->deviceName().c_str());
|
||||
#endif
|
||||
@ -2065,7 +2068,7 @@ public:
|
||||
// without WindowsEthernetTap::isInitialized() returning true, the won't actually
|
||||
// be online yet and setting managed routes on it will fail.
|
||||
const int MAX_SLEEP_COUNT = 500;
|
||||
for (int i = 0; !n.tap->isInitialized() && i < MAX_SLEEP_COUNT; i++) {
|
||||
for (int i = 0; !((WindowsEthernetTap *)(n.tap.get()))->isInitialized() && i < MAX_SLEEP_COUNT; i++) {
|
||||
Sleep(10);
|
||||
}
|
||||
#endif
|
||||
@ -2081,7 +2084,7 @@ public:
|
||||
case ZT_VIRTUAL_NETWORK_CONFIG_OPERATION_DESTROY:
|
||||
if (n.tap) { // sanity check
|
||||
#if defined(__WINDOWS__) && !defined(ZT_SDK)
|
||||
std::string winInstanceId(n.tap->instanceId());
|
||||
std::string winInstanceId(((WindowsEthernetTap *)(n.tap.get()))->instanceId());
|
||||
#endif
|
||||
*nuptr = (void *)0;
|
||||
n.tap.reset();
|
||||
|
@ -28,6 +28,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\controller\DB.cpp" />
|
||||
<ClCompile Include="..\..\controller\DBMirrorSet.cpp" />
|
||||
<ClCompile Include="..\..\controller\EmbeddedNetworkController.cpp" />
|
||||
<ClCompile Include="..\..\controller\FileDB.cpp" />
|
||||
<ClCompile Include="..\..\controller\LFDB.cpp" />
|
||||
@ -94,6 +95,7 @@
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">false</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Profile|x64'">false</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\osdep\EthernetTap.cpp" />
|
||||
<ClCompile Include="..\..\osdep\Http.cpp" />
|
||||
<ClCompile Include="..\..\osdep\ManagedRoute.cpp" />
|
||||
<ClCompile Include="..\..\osdep\OSUtils.cpp" />
|
||||
@ -115,6 +117,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\controller\DB.hpp" />
|
||||
<ClInclude Include="..\..\controller\DBMirrorSet.hpp" />
|
||||
<ClInclude Include="..\..\controller\EmbeddedNetworkController.hpp" />
|
||||
<ClInclude Include="..\..\controller\FileDB.hpp" />
|
||||
<ClInclude Include="..\..\controller\LFDB.hpp" />
|
||||
@ -182,6 +185,7 @@
|
||||
<ClInclude Include="..\..\node\Utils.hpp" />
|
||||
<ClInclude Include="..\..\node\World.hpp" />
|
||||
<ClInclude Include="..\..\osdep\Binder.hpp" />
|
||||
<ClInclude Include="..\..\osdep\EthernetTap.hpp" />
|
||||
<ClInclude Include="..\..\osdep\Http.hpp" />
|
||||
<ClInclude Include="..\..\osdep\ManagedRoute.hpp" />
|
||||
<ClInclude Include="..\..\osdep\OSUtils.hpp" />
|
||||
|
@ -270,6 +270,12 @@
|
||||
<ClCompile Include="..\..\controller\LFDB.cpp">
|
||||
<Filter>Source Files\controller</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\controller\DBMirrorSet.cpp">
|
||||
<Filter>Source Files\controller</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\osdep\EthernetTap.cpp">
|
||||
<Filter>Source Files\osdep</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="resource.h">
|
||||
@ -518,6 +524,12 @@
|
||||
<ClInclude Include="..\..\ext\cpp-httplib\httplib.h">
|
||||
<Filter>Header Files\ext\cpp-httplib</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\controller\DBMirrorSet.hpp">
|
||||
<Filter>Header Files\controller</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\osdep\EthernetTap.hpp">
|
||||
<Filter>Header Files\osdep</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="ZeroTierOne.rc">
|
||||
|
Loading…
x
Reference in New Issue
Block a user