mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-01-18 18:56:24 +00:00
Send member uptime in pong posts.
This commit is contained in:
parent
718e1d6c08
commit
bcc6799902
@ -569,26 +569,6 @@ unsigned int EmbeddedNetworkController::handleControlPlaneHttpGET(
|
|||||||
|
|
||||||
} // else 404
|
} // else 404
|
||||||
|
|
||||||
} else if ((path.size() == 1)&&(path[0] == "memberStatus")) {
|
|
||||||
|
|
||||||
const uint64_t now = OSUtils::now();
|
|
||||||
Mutex::Lock _l(_memberStatus_m);
|
|
||||||
responseBody.push_back('{');
|
|
||||||
_db.eachId([this,&responseBody,&now](uint64_t networkId,uint64_t nodeId) {
|
|
||||||
char tmp[64];
|
|
||||||
auto ms = this->_memberStatus.find(_MemberStatusKey(networkId,nodeId));
|
|
||||||
Utils::snprintf(tmp,sizeof(tmp),"%s\"%.16llx-%.10llx\":%s",
|
|
||||||
(responseBody.length() > 1) ? "," : "",
|
|
||||||
(unsigned long long)networkId,
|
|
||||||
(unsigned long long)nodeId,
|
|
||||||
((ms != _memberStatus.end())&&(ms->second.online(now))) ? "true" : "false");
|
|
||||||
responseBody.append(tmp);
|
|
||||||
});
|
|
||||||
responseBody.push_back('}');
|
|
||||||
responseContentType = "application/json";
|
|
||||||
|
|
||||||
return 200;
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
char tmp[4096];
|
char tmp[4096];
|
||||||
@ -1071,14 +1051,31 @@ unsigned int EmbeddedNetworkController::handleControlPlaneHttpPOST(
|
|||||||
|
|
||||||
} else if (path[0] == "ping") {
|
} else if (path[0] == "ping") {
|
||||||
|
|
||||||
json testRec;
|
|
||||||
const uint64_t now = OSUtils::now();
|
const uint64_t now = OSUtils::now();
|
||||||
testRec["clock"] = now;
|
bool first = true;
|
||||||
testRec["startTime"] = _startTime;
|
std::string pong("{\"memberStatus\":{");
|
||||||
testRec["content"] = b;
|
{
|
||||||
responseBody = OSUtils::jsonDump(testRec);
|
Mutex::Lock _l(_memberStatus_m);
|
||||||
_db.writeRaw("pong",responseBody);
|
_db.eachId([this,&pong,&now,&first](uint64_t networkId,uint64_t nodeId) {
|
||||||
|
char tmp[64];
|
||||||
|
auto ms = this->_memberStatus.find(_MemberStatusKey(networkId,nodeId));
|
||||||
|
Utils::snprintf(tmp,sizeof(tmp),"%s\"%.16llx-%.10llx\":%s",
|
||||||
|
(first) ? "" : ",",
|
||||||
|
(unsigned long long)networkId,
|
||||||
|
(unsigned long long)nodeId,
|
||||||
|
((ms != _memberStatus.end())&&(ms->second.online(now))) ? "true" : "false");
|
||||||
|
pong.append(tmp);
|
||||||
|
first = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
char tmp2[256];
|
||||||
|
Utils::snprintf(tmp2,sizeof(tmp2),"},\"clock\":%llu,\"startTime\":%llu}",(unsigned long long)now,(unsigned long long)_startTime);
|
||||||
|
pong.append(tmp2);
|
||||||
|
_db.writeRaw("pong",pong);
|
||||||
|
|
||||||
|
responseBody = "{}";
|
||||||
responseContentType = "application/json";
|
responseContentType = "application/json";
|
||||||
|
|
||||||
return 200;
|
return 200;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -114,7 +114,6 @@ private:
|
|||||||
if (!member.count("authorized")) member["authorized"] = false;
|
if (!member.count("authorized")) member["authorized"] = false;
|
||||||
if (!member.count("authHistory")) member["authHistory"] = nlohmann::json::array();
|
if (!member.count("authHistory")) member["authHistory"] = nlohmann::json::array();
|
||||||
if (!member.count("ipAssignments")) member["ipAssignments"] = nlohmann::json::array();
|
if (!member.count("ipAssignments")) member["ipAssignments"] = nlohmann::json::array();
|
||||||
if (!member.count("recentLog")) member["recentLog"] = nlohmann::json::array();
|
|
||||||
if (!member.count("activeBridge")) member["activeBridge"] = false;
|
if (!member.count("activeBridge")) member["activeBridge"] = false;
|
||||||
if (!member.count("tags")) member["tags"] = nlohmann::json::array();
|
if (!member.count("tags")) member["tags"] = nlohmann::json::array();
|
||||||
if (!member.count("capabilities")) member["capabilities"] = nlohmann::json::array();
|
if (!member.count("capabilities")) member["capabilities"] = nlohmann::json::array();
|
||||||
@ -123,6 +122,11 @@ private:
|
|||||||
if (!member.count("revision")) member["revision"] = 0ULL;
|
if (!member.count("revision")) member["revision"] = 0ULL;
|
||||||
if (!member.count("lastDeauthorizedTime")) member["lastDeauthorizedTime"] = 0ULL;
|
if (!member.count("lastDeauthorizedTime")) member["lastDeauthorizedTime"] = 0ULL;
|
||||||
if (!member.count("lastAuthorizedTime")) member["lastAuthorizedTime"] = 0ULL;
|
if (!member.count("lastAuthorizedTime")) member["lastAuthorizedTime"] = 0ULL;
|
||||||
|
if (!member.count("vMajor")) member["vMajor"] = -1;
|
||||||
|
if (!member.count("vMinor")) member["vMinor"] = -1;
|
||||||
|
if (!member.count("vRev")) member["vRev"] = -1;
|
||||||
|
if (!member.count("vProto")) member["vProto"] = -1;
|
||||||
|
if (!member.count("physicalAddr")) member["physicalAddr"] = nlohmann::json();
|
||||||
member["objtype"] = "member";
|
member["objtype"] = "member";
|
||||||
}
|
}
|
||||||
inline void _initNetwork(nlohmann::json &network)
|
inline void _initNetwork(nlohmann::json &network)
|
||||||
@ -162,6 +166,8 @@ private:
|
|||||||
network.erase("authorizedMemberCount");
|
network.erase("authorizedMemberCount");
|
||||||
network.erase("activeMemberCount");
|
network.erase("activeMemberCount");
|
||||||
network.erase("totalMemberCount");
|
network.erase("totalMemberCount");
|
||||||
|
// legacy fields
|
||||||
|
network.erase("lastModified");
|
||||||
}
|
}
|
||||||
inline void _addMemberNonPersistedFields(uint64_t nwid,uint64_t nodeId,nlohmann::json &member,uint64_t now)
|
inline void _addMemberNonPersistedFields(uint64_t nwid,uint64_t nodeId,nlohmann::json &member,uint64_t now)
|
||||||
{
|
{
|
||||||
@ -172,6 +178,10 @@ private:
|
|||||||
inline void _removeMemberNonPersistedFields(nlohmann::json &member)
|
inline void _removeMemberNonPersistedFields(nlohmann::json &member)
|
||||||
{
|
{
|
||||||
member.erase("clock");
|
member.erase("clock");
|
||||||
|
// legacy fields
|
||||||
|
member.erase("recentLog");
|
||||||
|
member.erase("lastModified");
|
||||||
|
member.erase("lastRequestMetaData");
|
||||||
}
|
}
|
||||||
|
|
||||||
const uint64_t _startTime;
|
const uint64_t _startTime;
|
||||||
|
Loading…
Reference in New Issue
Block a user