summaryrefslogtreecommitdiff
path: root/service/ControlPlane.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'service/ControlPlane.cpp')
-rw-r--r--service/ControlPlane.cpp84
1 files changed, 59 insertions, 25 deletions
diff --git a/service/ControlPlane.cpp b/service/ControlPlane.cpp
index 01582586..4978a91d 100644
--- a/service/ControlPlane.cpp
+++ b/service/ControlPlane.cpp
@@ -64,7 +64,7 @@ static std::string _jsonEscape(const char *s)
}
static std::string _jsonEscape(const std::string &s) { return _jsonEscape(s.c_str()); }
-static std::string _jsonEnumerate(const ZT1_MulticastGroup *mg,unsigned int count)
+static std::string _jsonEnumerate(const ZT_MulticastGroup *mg,unsigned int count)
{
std::string buf;
char tmp[128];
@@ -101,7 +101,7 @@ static std::string _jsonEnumerate(const struct sockaddr_storage *ss,unsigned int
return buf;
}
-static void _jsonAppend(unsigned int depth,std::string &buf,const ZT1_VirtualNetworkConfig *nc,const std::string &portDeviceName)
+static void _jsonAppend(unsigned int depth,std::string &buf,const ZT_VirtualNetworkConfig *nc,const std::string &portDeviceName)
{
char json[4096];
char prefix[32];
@@ -114,16 +114,16 @@ static void _jsonAppend(unsigned int depth,std::string &buf,const ZT1_VirtualNet
const char *nstatus = "",*ntype = "";
switch(nc->status) {
- case ZT1_NETWORK_STATUS_REQUESTING_CONFIGURATION: nstatus = "REQUESTING_CONFIGURATION"; break;
- case ZT1_NETWORK_STATUS_OK: nstatus = "OK"; break;
- case ZT1_NETWORK_STATUS_ACCESS_DENIED: nstatus = "ACCESS_DENIED"; break;
- case ZT1_NETWORK_STATUS_NOT_FOUND: nstatus = "NOT_FOUND"; break;
- case ZT1_NETWORK_STATUS_PORT_ERROR: nstatus = "PORT_ERROR"; break;
- case ZT1_NETWORK_STATUS_CLIENT_TOO_OLD: nstatus = "CLIENT_TOO_OLD"; break;
+ case ZT_NETWORK_STATUS_REQUESTING_CONFIGURATION: nstatus = "REQUESTING_CONFIGURATION"; break;
+ case ZT_NETWORK_STATUS_OK: nstatus = "OK"; break;
+ case ZT_NETWORK_STATUS_ACCESS_DENIED: nstatus = "ACCESS_DENIED"; break;
+ case ZT_NETWORK_STATUS_NOT_FOUND: nstatus = "NOT_FOUND"; break;
+ case ZT_NETWORK_STATUS_PORT_ERROR: nstatus = "PORT_ERROR"; break;
+ case ZT_NETWORK_STATUS_CLIENT_TOO_OLD: nstatus = "CLIENT_TOO_OLD"; break;
}
switch(nc->type) {
- case ZT1_NETWORK_TYPE_PRIVATE: ntype = "PRIVATE"; break;
- case ZT1_NETWORK_TYPE_PUBLIC: ntype = "PUBLIC"; break;
+ case ZT_NETWORK_TYPE_PRIVATE: ntype = "PRIVATE"; break;
+ case ZT_NETWORK_TYPE_PUBLIC: ntype = "PUBLIC"; break;
}
Utils::snprintf(json,sizeof(json),
@@ -162,7 +162,7 @@ static void _jsonAppend(unsigned int depth,std::string &buf,const ZT1_VirtualNet
buf.append(json);
}
-static std::string _jsonEnumerate(unsigned int depth,const ZT1_PeerPhysicalPath *pp,unsigned int count)
+static std::string _jsonEnumerate(unsigned int depth,const ZT_PeerPhysicalPath *pp,unsigned int count)
{
char json[1024];
char prefix[32];
@@ -182,14 +182,12 @@ static std::string _jsonEnumerate(unsigned int depth,const ZT1_PeerPhysicalPath
"%s\t\"address\": \"%s\",\n"
"%s\t\"lastSend\": %llu,\n"
"%s\t\"lastReceive\": %llu,\n"
- "%s\t\"fixed\": %s,\n"
"%s\t\"active\": %s,\n"
"%s\t\"preferred\": %s\n"
"%s}",
prefix,_jsonEscape(reinterpret_cast<const InetAddress *>(&(pp[i].address))->toString()).c_str(),
prefix,pp[i].lastSend,
prefix,pp[i].lastReceive,
- prefix,(pp[i].fixed == 0) ? "false" : "true",
prefix,(pp[i].active == 0) ? "false" : "true",
prefix,(pp[i].preferred == 0) ? "false" : "true",
prefix);
@@ -198,7 +196,7 @@ static std::string _jsonEnumerate(unsigned int depth,const ZT1_PeerPhysicalPath
return buf;
}
-static void _jsonAppend(unsigned int depth,std::string &buf,const ZT1_Peer *peer)
+static void _jsonAppend(unsigned int depth,std::string &buf,const ZT_Peer *peer)
{
char json[1024];
char prefix[32];
@@ -211,9 +209,9 @@ static void _jsonAppend(unsigned int depth,std::string &buf,const ZT1_Peer *peer
const char *prole = "";
switch(peer->role) {
- case ZT1_PEER_ROLE_LEAF: prole = "LEAF"; break;
- case ZT1_PEER_ROLE_RELAY: prole = "RELAY"; break;
- case ZT1_PEER_ROLE_ROOT: prole = "ROOT"; break;
+ case ZT_PEER_ROLE_LEAF: prole = "LEAF"; break;
+ case ZT_PEER_ROLE_RELAY: prole = "RELAY"; break;
+ case ZT_PEER_ROLE_ROOT: prole = "ROOT"; break;
}
Utils::snprintf(json,sizeof(json),
@@ -267,7 +265,7 @@ unsigned int ControlPlane::handleRequest(
std::string &responseBody,
std::string &responseContentType)
{
- char json[1024];
+ char json[8194];
unsigned int scode = 404;
std::vector<std::string> ps(Utils::split(path.c_str(),"/","",""));
std::map<std::string,std::string> urlArgs;
@@ -356,29 +354,65 @@ unsigned int ControlPlane::handleRequest(
if (ps[0] == "status") {
responseContentType = "application/json";
- ZT1_NodeStatus status;
+
+ ZT_NodeStatus status;
_node->status(&status);
+
+ std::string clusterJson;
+#ifdef ZT_ENABLE_CLUSTER
+ {
+ ZT_ClusterStatus cs;
+ _node->clusterStatus(&cs);
+
+ if (cs.clusterSize >= 1) {
+ char t[1024];
+ Utils::snprintf(t,sizeof(t),"{\n\t\t\"myId\": %u,\n\t\t\"clusterSize\": %u,\n\t\t\"members\": [",cs.myId,cs.clusterSize);
+ clusterJson.append(t);
+ for(unsigned int i=0;i<cs.clusterSize;++i) {
+ Utils::snprintf(t,sizeof(t),"%s\t\t\t{\n\t\t\t\t\"id\": %u,\n\t\t\t\t\"msSinceLastHeartbeat\": %u,\n\t\t\t\t\"alive\": %s,\n\t\t\t\t\"x\": %d,\n\t\t\t\t\"y\": %d,\n\t\t\t\t\"z\": %d,\n\t\t\t\t\"load\": %llu,\n\t\t\t\t\"peers\": %llu\n\t\t\t}",
+ ((i == 0) ? "\n" : ",\n"),
+ cs.members[i].id,
+ cs.members[i].msSinceLastHeartbeat,
+ (cs.members[i].alive != 0) ? "true" : "false",
+ cs.members[i].x,
+ cs.members[i].y,
+ cs.members[i].z,
+ cs.members[i].load,
+ cs.members[i].peers);
+ clusterJson.append(t);
+ }
+ clusterJson.append(" ]\n\t\t}");
+ }
+ }
+#endif
+
Utils::snprintf(json,sizeof(json),
"{\n"
"\t\"address\": \"%.10llx\",\n"
"\t\"publicIdentity\": \"%s\",\n"
+ "\t\"worldId\": %llu,\n"
+ "\t\"worldTimestamp\": %llu,\n"
"\t\"online\": %s,\n"
"\t\"tcpFallbackActive\": %s,\n"
"\t\"versionMajor\": %d,\n"
"\t\"versionMinor\": %d,\n"
"\t\"versionRev\": %d,\n"
"\t\"version\": \"%d.%d.%d\",\n"
- "\t\"clock\": %llu\n"
+ "\t\"clock\": %llu,\n"
+ "\t\"cluster\": %s\n"
"}\n",
status.address,
status.publicIdentity,
+ status.worldId,
+ status.worldTimestamp,
(status.online) ? "true" : "false",
(_svc->tcpFallbackActive()) ? "true" : "false",
ZEROTIER_ONE_VERSION_MAJOR,
ZEROTIER_ONE_VERSION_MINOR,
ZEROTIER_ONE_VERSION_REVISION,
ZEROTIER_ONE_VERSION_MAJOR,ZEROTIER_ONE_VERSION_MINOR,ZEROTIER_ONE_VERSION_REVISION,
- (unsigned long long)OSUtils::now());
+ (unsigned long long)OSUtils::now(),
+ ((clusterJson.length() > 0) ? clusterJson.c_str() : "null"));
responseBody = json;
scode = 200;
} else if (ps[0] == "config") {
@@ -386,7 +420,7 @@ unsigned int ControlPlane::handleRequest(
responseBody = "{}"; // TODO
scode = 200;
} else if (ps[0] == "network") {
- ZT1_VirtualNetworkList *nws = _node->networks();
+ ZT_VirtualNetworkList *nws = _node->networks();
if (nws) {
if (ps.size() == 1) {
// Return [array] of all networks
@@ -415,7 +449,7 @@ unsigned int ControlPlane::handleRequest(
_node->freeQueryResult((void *)nws);
} else scode = 500;
} else if (ps[0] == "peer") {
- ZT1_PeerList *pl = _node->peers();
+ ZT_PeerList *pl = _node->peers();
if (pl) {
if (ps.size() == 1) {
// Return [array] of all peers
@@ -473,7 +507,7 @@ unsigned int ControlPlane::handleRequest(
if (ps.size() == 2) {
uint64_t wantnw = Utils::hexStrToU64(ps[1].c_str());
_node->join(wantnw); // does nothing if we are a member
- ZT1_VirtualNetworkList *nws = _node->networks();
+ ZT_VirtualNetworkList *nws = _node->networks();
if (nws) {
for(unsigned long i=0;i<nws->networkCount;++i) {
if (nws->networks[i].nwid == wantnw) {
@@ -506,7 +540,7 @@ unsigned int ControlPlane::handleRequest(
if (ps[0] == "config") {
// TODO
} else if (ps[0] == "network") {
- ZT1_VirtualNetworkList *nws = _node->networks();
+ ZT_VirtualNetworkList *nws = _node->networks();
if (nws) {
if (ps.size() == 2) {
uint64_t wantnw = Utils::hexStrToU64(ps[1].c_str());