mirror of
https://github.com/ZeroTier/ZeroTierOne
synced 2025-08-14 02:27:38 -07:00
Abiltiy to post a test via the controller web API, and parsing of CIRCUIT_TEST_REPORT messages.
This commit is contained in:
parent
273f0d18b0
commit
a3876353ca
3 changed files with 111 additions and 41 deletions
|
@ -505,6 +505,52 @@ unsigned int SqliteNetworkController::handleControlPlaneHttpPOST(
|
|||
}
|
||||
|
||||
return _doCPGet(path,urlArgs,headers,body,responseBody,responseContentType);
|
||||
} else if ((path.size() == 3)&&(path[2] == "test")) {
|
||||
ZT_CircuitTest *test = (ZT_CircuitTest *)malloc(sizeof(ZT_CircuitTest));
|
||||
memset(test,0,sizeof(ZT_CircuitTest));
|
||||
|
||||
Utils::getSecureRandom(&(test->testId),sizeof(test->testId));
|
||||
test->credentialNetworkId = nwid;
|
||||
test->ptr = (void *)this;
|
||||
|
||||
json_value *j = json_parse(body.c_str(),body.length());
|
||||
if (j) {
|
||||
if (j->type == json_object) {
|
||||
for(unsigned int k=0;k<j->u.object.length;++k) {
|
||||
|
||||
if (!strcmp(j->u.object.values[k].name,"hops")) {
|
||||
if (j->u.object.values[k].value->type == json_array) {
|
||||
for(unsigned int kk=0;kk<j->u.object.values[k].value->u.array.length;++kk) {
|
||||
json_value *hop = j->u.object.values[k].value->u.array.values[kk];
|
||||
if (hop->type == json_array) {
|
||||
for(unsigned int kkk=0;kkk<hop->u.array.length;++kkk) {
|
||||
if (hop->u.array.values[kkk].type == json_string) {
|
||||
test->hops[test->hopCount].addresses[test->hops[test->hopCount].breadth++] = Utils::hexStrToU64(hop->u.array.values[kkk].u.string.ptr) & 0xffffffffffULL;
|
||||
}
|
||||
}
|
||||
++test->hopCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (!strcmp(j->u.object.values[k].name,"reportAtEveryHop")) {
|
||||
if (j->u.object.values[k].value->type == json_boolean)
|
||||
test->reportAtEveryHop = (j->u.object.values[k].value->u.boolean == 0) ? 0 : 1;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
json_value_free(j);
|
||||
}
|
||||
|
||||
if (!test->hopCount) {
|
||||
::free((void *)test);
|
||||
return 500;
|
||||
}
|
||||
|
||||
test->timestamp = OSUtils::now();
|
||||
_node->circuitTestBegin(test,&(SqliteNetworkController::_circuitTestCallback));
|
||||
|
||||
return 200;
|
||||
} // else 404
|
||||
|
||||
} else {
|
||||
|
@ -1819,4 +1865,8 @@ NetworkController::ResultCode SqliteNetworkController::_doNetworkConfigRequest(c
|
|||
return NetworkController::NETCONF_QUERY_OK;
|
||||
}
|
||||
|
||||
static void _circuitTestCallback(ZT_Node *node,ZT_CircuitTest *test,const ZT_CircuitTestReport *report)
|
||||
{
|
||||
}
|
||||
|
||||
} // namespace ZeroTier
|
||||
|
|
|
@ -43,6 +43,9 @@
|
|||
// Number of in-memory last log entries to maintain per user
|
||||
#define ZT_SQLITENETWORKCONTROLLER_IN_MEMORY_LOG_SIZE 32
|
||||
|
||||
// How long do circuit tests "live"? This is just to prevent buildup in memory.
|
||||
#define ZT_SQLITENETWORKCONTROLLER_CIRCUIT_TEST_TIMEOUT 300000
|
||||
|
||||
namespace ZeroTier {
|
||||
|
||||
class Node;
|
||||
|
@ -106,6 +109,8 @@ private:
|
|||
const Dictionary &metaData,
|
||||
Dictionary &netconf);
|
||||
|
||||
static void _circuitTestCallback(ZT_Node *node,ZT_CircuitTest *test,const ZT_CircuitTestReport *report);
|
||||
|
||||
Node *_node;
|
||||
std::string _dbPath;
|
||||
std::string _circuitTestPath;
|
||||
|
@ -140,6 +145,9 @@ private:
|
|||
// Last log entries by address and network ID pair
|
||||
std::map< std::pair<Address,uint64_t>,_LLEntry > _lastLog;
|
||||
|
||||
// Circuit tests outstanding
|
||||
std::map< uint64_t,ZT_CircuitTest * > _circuitTests;
|
||||
|
||||
sqlite3 *_db;
|
||||
|
||||
sqlite3_stmt *_sGetNetworkById;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue