JSONDB.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568
  1. /*
  2. * ZeroTier One - Network Virtualization Everywhere
  3. * Copyright (C) 2011-2015 ZeroTier, Inc.
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <stdint.h>
  21. #ifndef _WIN32
  22. #include <unistd.h>
  23. #include <fcntl.h>
  24. #include <sys/time.h>
  25. #include <sys/types.h>
  26. #include <sys/socket.h>
  27. #include <sys/select.h>
  28. #endif
  29. #include "JSONDB.hpp"
  30. #define ZT_JSONDB_HTTP_TIMEOUT 60000
  31. namespace ZeroTier {
  32. static const nlohmann::json _EMPTY_JSON(nlohmann::json::object());
  33. static const std::map<std::string,std::string> _ZT_JSONDB_GET_HEADERS;
  34. JSONDB::JSONDB(const std::string &basePath) :
  35. _basePath(basePath),
  36. _rawInput(-1),
  37. _rawOutput(-1),
  38. _summaryThreadRun(true),
  39. _dataReady(false)
  40. {
  41. if ((_basePath.length() > 7)&&(_basePath.substr(0,7) == "http://")) {
  42. // If base path is http:// we run in HTTP mode
  43. // TODO: this doesn't yet support IPv6 since bracketed address notiation isn't supported.
  44. // Typically it's just used with 127.0.0.1 anyway.
  45. std::string hn = _basePath.substr(7);
  46. std::size_t hnend = hn.find_first_of('/');
  47. if (hnend != std::string::npos)
  48. hn = hn.substr(0,hnend);
  49. std::size_t hnsep = hn.find_last_of(':');
  50. if (hnsep != std::string::npos)
  51. hn[hnsep] = '/';
  52. _httpAddr.fromString(hn.c_str());
  53. if (hnend != std::string::npos)
  54. _basePath = _basePath.substr(7 + hnend);
  55. if (_basePath.length() == 0)
  56. _basePath = "/";
  57. if (_basePath[0] != '/')
  58. _basePath = std::string("/") + _basePath;
  59. #ifndef __WINDOWS__
  60. } else if (_basePath == "-") {
  61. // If base path is "-" we run in stdin/stdout mode and expect our database to be populated on startup via stdin
  62. // Not supported on Windows
  63. _rawInput = STDIN_FILENO;
  64. _rawOutput = STDOUT_FILENO;
  65. fcntl(_rawInput,F_SETFL,O_NONBLOCK);
  66. #endif
  67. } else {
  68. // Default mode of operation is to store files in the filesystem
  69. OSUtils::mkdir(_basePath.c_str());
  70. OSUtils::lockDownFile(_basePath.c_str(),true); // networks might contain auth tokens, etc., so restrict directory permissions
  71. }
  72. _networks_m.lock(); // locked until data is loaded, etc.
  73. if (_rawInput < 0) {
  74. unsigned int cnt = 0;
  75. while (!_load(_basePath)) {
  76. if ((++cnt & 7) == 0)
  77. fprintf(stderr,"WARNING: controller still waiting to read '%s'..." ZT_EOL_S,_basePath.c_str());
  78. Thread::sleep(250);
  79. }
  80. for(std::unordered_map<uint64_t,_NW>::iterator n(_networks.begin());n!=_networks.end();++n)
  81. _summaryThreadToDo.push_back(n->first);
  82. if (_summaryThreadToDo.size() > 0) {
  83. _summaryThread = Thread::start(this);
  84. } else {
  85. _dataReady = true;
  86. _networks_m.unlock();
  87. }
  88. } else {
  89. // In IPC mode we wait for the first message to start, and we start
  90. // this thread since this thread is responsible for reading from stdin.
  91. _summaryThread = Thread::start(this);
  92. }
  93. }
  94. JSONDB::~JSONDB()
  95. {
  96. Thread t;
  97. {
  98. Mutex::Lock _l(_summaryThread_m);
  99. _summaryThreadRun = false;
  100. t = _summaryThread;
  101. }
  102. if (t)
  103. Thread::join(t);
  104. }
  105. bool JSONDB::writeRaw(const std::string &n,const std::string &obj)
  106. {
  107. if (_rawOutput >= 0) {
  108. #ifndef __WINDOWS__
  109. if (obj.length() > 0) {
  110. Mutex::Lock _l(_rawLock);
  111. if ((long)write(_rawOutput,obj.data(),obj.length()) == (long)obj.length()) {
  112. if (write(_rawOutput,"\n",1) == 1)
  113. return true;
  114. }
  115. } else return true;
  116. #endif
  117. return false;
  118. } else if (_httpAddr) {
  119. std::map<std::string,std::string> headers;
  120. std::string body;
  121. std::map<std::string,std::string> reqHeaders;
  122. char tmp[64];
  123. OSUtils::ztsnprintf(tmp,sizeof(tmp),"%lu",(unsigned long)obj.length());
  124. reqHeaders["Content-Length"] = tmp;
  125. reqHeaders["Content-Type"] = "application/json";
  126. const unsigned int sc = Http::PUT(0,ZT_JSONDB_HTTP_TIMEOUT,reinterpret_cast<const struct sockaddr *>(&_httpAddr),(_basePath+"/"+n).c_str(),reqHeaders,obj.data(),(unsigned long)obj.length(),headers,body);
  127. return (sc == 200);
  128. } else {
  129. const std::string path(_genPath(n,true));
  130. if (!path.length())
  131. return false;
  132. return OSUtils::writeFile(path.c_str(),obj);
  133. }
  134. }
  135. bool JSONDB::hasNetwork(const uint64_t networkId) const
  136. {
  137. Mutex::Lock _l(_networks_m);
  138. return (_networks.find(networkId) != _networks.end());
  139. }
  140. bool JSONDB::getNetwork(const uint64_t networkId,nlohmann::json &config) const
  141. {
  142. Mutex::Lock _l(_networks_m);
  143. const std::unordered_map<uint64_t,_NW>::const_iterator i(_networks.find(networkId));
  144. if (i == _networks.end())
  145. return false;
  146. config = nlohmann::json::from_msgpack(i->second.config);
  147. return true;
  148. }
  149. bool JSONDB::getNetworkSummaryInfo(const uint64_t networkId,NetworkSummaryInfo &ns) const
  150. {
  151. Mutex::Lock _l(_networks_m);
  152. const std::unordered_map<uint64_t,_NW>::const_iterator i(_networks.find(networkId));
  153. if (i == _networks.end())
  154. return false;
  155. ns = i->second.summaryInfo;
  156. return true;
  157. }
  158. int JSONDB::getNetworkAndMember(const uint64_t networkId,const uint64_t nodeId,nlohmann::json &networkConfig,nlohmann::json &memberConfig,NetworkSummaryInfo &ns) const
  159. {
  160. Mutex::Lock _l(_networks_m);
  161. const std::unordered_map<uint64_t,_NW>::const_iterator i(_networks.find(networkId));
  162. if (i == _networks.end())
  163. return 0;
  164. const std::unordered_map< uint64_t,std::vector<uint8_t> >::const_iterator j(i->second.members.find(nodeId));
  165. if (j == i->second.members.end())
  166. return 1;
  167. networkConfig = nlohmann::json::from_msgpack(i->second.config);
  168. memberConfig = nlohmann::json::from_msgpack(j->second);
  169. ns = i->second.summaryInfo;
  170. return 3;
  171. }
  172. bool JSONDB::getNetworkMember(const uint64_t networkId,const uint64_t nodeId,nlohmann::json &memberConfig) const
  173. {
  174. Mutex::Lock _l(_networks_m);
  175. const std::unordered_map<uint64_t,_NW>::const_iterator i(_networks.find(networkId));
  176. if (i == _networks.end())
  177. return false;
  178. const std::unordered_map< uint64_t,std::vector<uint8_t> >::const_iterator j(i->second.members.find(nodeId));
  179. if (j == i->second.members.end())
  180. return false;
  181. memberConfig = nlohmann::json::from_msgpack(j->second);
  182. return true;
  183. }
  184. void JSONDB::saveNetwork(const uint64_t networkId,const nlohmann::json &networkConfig)
  185. {
  186. char n[64];
  187. OSUtils::ztsnprintf(n,sizeof(n),"network/%.16llx",(unsigned long long)networkId);
  188. writeRaw(n,OSUtils::jsonDump(networkConfig,-1));
  189. {
  190. Mutex::Lock _l(_networks_m);
  191. _networks[networkId].config = nlohmann::json::to_msgpack(networkConfig);
  192. }
  193. _recomputeSummaryInfo(networkId);
  194. }
  195. void JSONDB::saveNetworkMember(const uint64_t networkId,const uint64_t nodeId,const nlohmann::json &memberConfig)
  196. {
  197. char n[256];
  198. OSUtils::ztsnprintf(n,sizeof(n),"network/%.16llx/member/%.10llx",(unsigned long long)networkId,(unsigned long long)nodeId);
  199. writeRaw(n,OSUtils::jsonDump(memberConfig,-1));
  200. {
  201. Mutex::Lock _l(_networks_m);
  202. _networks[networkId].members[nodeId] = nlohmann::json::to_msgpack(memberConfig);
  203. _members[nodeId].insert(networkId);
  204. }
  205. _recomputeSummaryInfo(networkId);
  206. }
  207. nlohmann::json JSONDB::eraseNetwork(const uint64_t networkId)
  208. {
  209. if (!_httpAddr) { // Member deletion is done by Central in harnessed mode, and deleting the cache network entry also deletes all members
  210. std::vector<uint64_t> memberIds;
  211. {
  212. Mutex::Lock _l(_networks_m);
  213. const std::unordered_map<uint64_t,_NW>::iterator i(_networks.find(networkId));
  214. if (i == _networks.end())
  215. return _EMPTY_JSON;
  216. for(std::unordered_map< uint64_t,std::vector<uint8_t> >::iterator m(i->second.members.begin());m!=i->second.members.end();++m)
  217. memberIds.push_back(m->first);
  218. }
  219. for(std::vector<uint64_t>::iterator m(memberIds.begin());m!=memberIds.end();++m)
  220. eraseNetworkMember(networkId,*m,false);
  221. }
  222. char n[256];
  223. OSUtils::ztsnprintf(n,sizeof(n),"network/%.16llx",(unsigned long long)networkId);
  224. if (_rawOutput >= 0) {
  225. // In harnessed mode, deletes occur in Central or other management
  226. // software and do not need to be executed this way.
  227. } else if (_httpAddr) {
  228. std::map<std::string,std::string> headers;
  229. std::string body;
  230. Http::DEL(0,ZT_JSONDB_HTTP_TIMEOUT,reinterpret_cast<const struct sockaddr *>(&_httpAddr),(_basePath+"/"+n).c_str(),_ZT_JSONDB_GET_HEADERS,headers,body);
  231. } else {
  232. const std::string path(_genPath(n,false));
  233. if (path.length())
  234. OSUtils::rm(path.c_str());
  235. }
  236. {
  237. Mutex::Lock _l(_networks_m);
  238. std::unordered_map<uint64_t,_NW>::iterator i(_networks.find(networkId));
  239. if (i == _networks.end())
  240. return _EMPTY_JSON; // sanity check, shouldn't happen
  241. nlohmann::json tmp(nlohmann::json::from_msgpack(i->second.config));
  242. _networks.erase(i);
  243. return tmp;
  244. }
  245. }
  246. nlohmann::json JSONDB::eraseNetworkMember(const uint64_t networkId,const uint64_t nodeId,bool recomputeSummaryInfo)
  247. {
  248. char n[256];
  249. OSUtils::ztsnprintf(n,sizeof(n),"network/%.16llx/member/%.10llx",(unsigned long long)networkId,(unsigned long long)nodeId);
  250. if (_rawOutput >= 0) {
  251. // In harnessed mode, deletes occur in Central or other management
  252. // software and do not need to be executed this way.
  253. } else if (_httpAddr) {
  254. std::map<std::string,std::string> headers;
  255. std::string body;
  256. Http::DEL(0,ZT_JSONDB_HTTP_TIMEOUT,reinterpret_cast<const struct sockaddr *>(&_httpAddr),(_basePath+"/"+n).c_str(),_ZT_JSONDB_GET_HEADERS,headers,body);
  257. } else {
  258. const std::string path(_genPath(n,false));
  259. if (path.length())
  260. OSUtils::rm(path.c_str());
  261. }
  262. {
  263. Mutex::Lock _l(_networks_m);
  264. _members[nodeId].erase(networkId);
  265. std::unordered_map<uint64_t,_NW>::iterator i(_networks.find(networkId));
  266. if (i == _networks.end())
  267. return _EMPTY_JSON;
  268. std::unordered_map< uint64_t,std::vector<uint8_t> >::iterator j(i->second.members.find(nodeId));
  269. if (j == i->second.members.end())
  270. return _EMPTY_JSON;
  271. nlohmann::json tmp(j->second);
  272. i->second.members.erase(j);
  273. if (recomputeSummaryInfo)
  274. _recomputeSummaryInfo(networkId);
  275. return tmp;
  276. }
  277. }
  278. void JSONDB::threadMain()
  279. throw()
  280. {
  281. #ifndef __WINDOWS__
  282. fd_set readfds,nullfds;
  283. char *const readbuf = (_rawInput >= 0) ? (new char[1048576]) : (char *)0;
  284. std::string rawInputBuf;
  285. FD_ZERO(&readfds);
  286. FD_ZERO(&nullfds);
  287. struct timeval tv;
  288. #endif
  289. std::vector<uint64_t> todo;
  290. while (_summaryThreadRun) {
  291. #ifndef __WINDOWS__
  292. if (_rawInput < 0) {
  293. // In HTTP and filesystem mode we just wait for summary to-do items
  294. Thread::sleep(25);
  295. } else {
  296. // In IPC mode we wait but also select() on STDIN to read database updates
  297. FD_SET(_rawInput,&readfds);
  298. tv.tv_sec = 0;
  299. tv.tv_usec = 25000;
  300. select(_rawInput+1,&readfds,&nullfds,&nullfds,&tv);
  301. if (FD_ISSET(_rawInput,&readfds)) {
  302. const long rn = (long)read(_rawInput,readbuf,1048576);
  303. bool gotMessage = false;
  304. for(long i=0;i<rn;++i) {
  305. if ((readbuf[i] != '\n')&&(readbuf[i] != '\r')&&(readbuf[i] != 0)) { // compatible with nodeJS IPC
  306. rawInputBuf.push_back(readbuf[i]);
  307. } else if (rawInputBuf.length() > 0) {
  308. try {
  309. const nlohmann::json obj(OSUtils::jsonParse(rawInputBuf));
  310. gotMessage = true;
  311. if (!_dataReady) {
  312. _dataReady = true;
  313. _networks_m.unlock();
  314. }
  315. if (obj.is_array()) {
  316. for(unsigned long i=0;i<obj.size();++i)
  317. _add(obj[i]);
  318. } else if (obj.is_object()) {
  319. _add(obj);
  320. }
  321. } catch ( ... ) {} // ignore malformed JSON
  322. rawInputBuf.clear();
  323. }
  324. }
  325. if (!gotMessage) // select() again immediately until we get at least one full message
  326. continue;
  327. }
  328. }
  329. #else
  330. Thread::sleep(25);
  331. #endif
  332. {
  333. Mutex::Lock _l(_summaryThread_m);
  334. if (_summaryThreadToDo.empty())
  335. continue;
  336. else _summaryThreadToDo.swap(todo);
  337. }
  338. if (!_dataReady) {
  339. _dataReady = true;
  340. _networks_m.unlock();
  341. }
  342. const uint64_t now = OSUtils::now();
  343. try {
  344. Mutex::Lock _l(_networks_m);
  345. for(std::vector<uint64_t>::iterator ii(todo.begin());ii!=todo.end();++ii) {
  346. const uint64_t networkId = *ii;
  347. std::unordered_map<uint64_t,_NW>::iterator n(_networks.find(networkId));
  348. if (n != _networks.end()) {
  349. NetworkSummaryInfo &ns = n->second.summaryInfo;
  350. ns.activeBridges.clear();
  351. ns.allocatedIps.clear();
  352. ns.authorizedMemberCount = 0;
  353. ns.activeMemberCount = 0;
  354. ns.totalMemberCount = 0;
  355. ns.mostRecentDeauthTime = 0;
  356. for(std::unordered_map< uint64_t,std::vector<uint8_t> >::const_iterator m(n->second.members.begin());m!=n->second.members.end();++m) {
  357. try {
  358. nlohmann::json member(nlohmann::json::from_msgpack(m->second));
  359. if (OSUtils::jsonBool(member["authorized"],false)) {
  360. ++ns.authorizedMemberCount;
  361. try {
  362. const nlohmann::json &mlog = member["recentLog"];
  363. if ((mlog.is_array())&&(mlog.size() > 0)) {
  364. const nlohmann::json &mlog1 = mlog[0];
  365. if (mlog1.is_object()) {
  366. if ((now - OSUtils::jsonInt(mlog1["ts"],0ULL)) < (ZT_NETWORK_AUTOCONF_DELAY * 2))
  367. ++ns.activeMemberCount;
  368. }
  369. }
  370. } catch ( ... ) {}
  371. try {
  372. if (OSUtils::jsonBool(member["activeBridge"],false))
  373. ns.activeBridges.push_back(Address(m->first));
  374. } catch ( ... ) {}
  375. try {
  376. const nlohmann::json &mips = member["ipAssignments"];
  377. if (mips.is_array()) {
  378. for(unsigned long i=0;i<mips.size();++i) {
  379. InetAddress mip(OSUtils::jsonString(mips[i],"").c_str());
  380. if ((mip.ss_family == AF_INET)||(mip.ss_family == AF_INET6))
  381. ns.allocatedIps.push_back(mip);
  382. }
  383. }
  384. } catch ( ... ) {}
  385. } else {
  386. try {
  387. ns.mostRecentDeauthTime = std::max(ns.mostRecentDeauthTime,OSUtils::jsonInt(member["lastDeauthorizedTime"],0ULL));
  388. } catch ( ... ) {}
  389. }
  390. ++ns.totalMemberCount;
  391. } catch ( ... ) {}
  392. }
  393. std::sort(ns.activeBridges.begin(),ns.activeBridges.end());
  394. std::sort(ns.allocatedIps.begin(),ns.allocatedIps.end());
  395. n->second.summaryInfoLastComputed = now;
  396. }
  397. }
  398. } catch ( ... ) {}
  399. todo.clear();
  400. }
  401. if (!_dataReady) // sanity check
  402. _networks_m.unlock();
  403. #ifndef __WINDOWS__
  404. delete [] readbuf;
  405. #endif
  406. }
  407. bool JSONDB::_add(const nlohmann::json &j)
  408. {
  409. try {
  410. if (j.is_object()) {
  411. std::string id(OSUtils::jsonString(j["id"],"0"));
  412. std::string objtype(OSUtils::jsonString(j["objtype"],""));
  413. if ((id.length() == 16)&&(objtype == "network")) {
  414. const uint64_t nwid = Utils::hexStrToU64(id.c_str());
  415. if (nwid) {
  416. Mutex::Lock _l(_networks_m);
  417. _networks[nwid].config = nlohmann::json::to_msgpack(j);
  418. return true;
  419. }
  420. } else if ((id.length() == 10)&&(objtype == "member")) {
  421. const uint64_t mid = Utils::hexStrToU64(id.c_str());
  422. const uint64_t nwid = Utils::hexStrToU64(OSUtils::jsonString(j["nwid"],"0").c_str());
  423. if ((mid)&&(nwid)) {
  424. Mutex::Lock _l(_networks_m);
  425. _networks[nwid].members[mid] = nlohmann::json::to_msgpack(j);
  426. _members[mid].insert(nwid);
  427. return true;
  428. }
  429. }
  430. }
  431. } catch ( ... ) {}
  432. return false;
  433. }
  434. bool JSONDB::_load(const std::string &p)
  435. {
  436. // This is not used in stdin/stdout mode. Instead data is populated by
  437. // sending it all to stdin.
  438. if (_httpAddr) {
  439. // In HTTP harnessed mode we download our entire working data set on startup.
  440. std::string body;
  441. std::map<std::string,std::string> headers;
  442. const unsigned int sc = Http::GET(0,ZT_JSONDB_HTTP_TIMEOUT,reinterpret_cast<const struct sockaddr *>(&_httpAddr),_basePath.c_str(),_ZT_JSONDB_GET_HEADERS,headers,body);
  443. if (sc == 200) {
  444. try {
  445. nlohmann::json dbImg(OSUtils::jsonParse(body));
  446. std::string tmp;
  447. if (dbImg.is_object()) {
  448. Mutex::Lock _l(_networks_m);
  449. for(nlohmann::json::iterator i(dbImg.begin());i!=dbImg.end();++i) {
  450. try {
  451. _add(i.value());
  452. } catch ( ... ) {}
  453. }
  454. return true;
  455. }
  456. } catch ( ... ) {} // invalid JSON, so maybe incomplete request
  457. }
  458. return false;
  459. } else {
  460. // In regular mode we recursively read it from controller.d/ on disk
  461. std::vector<std::string> dl(OSUtils::listDirectory(p.c_str(),true));
  462. for(std::vector<std::string>::const_iterator di(dl.begin());di!=dl.end();++di) {
  463. if ((di->length() > 5)&&(di->substr(di->length() - 5) == ".json")) {
  464. std::string buf;
  465. if (OSUtils::readFile((p + ZT_PATH_SEPARATOR_S + *di).c_str(),buf)) {
  466. try {
  467. _add(OSUtils::jsonParse(buf));
  468. } catch ( ... ) {}
  469. }
  470. } else {
  471. this->_load((p + ZT_PATH_SEPARATOR_S + *di));
  472. }
  473. }
  474. return true;
  475. }
  476. }
  477. void JSONDB::_recomputeSummaryInfo(const uint64_t networkId)
  478. {
  479. Mutex::Lock _l(_summaryThread_m);
  480. if (std::find(_summaryThreadToDo.begin(),_summaryThreadToDo.end(),networkId) == _summaryThreadToDo.end())
  481. _summaryThreadToDo.push_back(networkId);
  482. if (!_summaryThread)
  483. _summaryThread = Thread::start(this);
  484. }
  485. std::string JSONDB::_genPath(const std::string &n,bool create)
  486. {
  487. std::vector<std::string> pt(OSUtils::split(n.c_str(),"/","",""));
  488. if (pt.size() == 0)
  489. return std::string();
  490. char sep;
  491. if (_httpAddr) {
  492. sep = '/';
  493. create = false;
  494. } else {
  495. sep = ZT_PATH_SEPARATOR;
  496. }
  497. std::string p(_basePath);
  498. if (create) OSUtils::mkdir(p.c_str());
  499. for(unsigned long i=0,j=(unsigned long)(pt.size()-1);i<j;++i) {
  500. p.push_back(sep);
  501. p.append(pt[i]);
  502. if (create) OSUtils::mkdir(p.c_str());
  503. }
  504. p.push_back(sep);
  505. p.append(pt[pt.size()-1]);
  506. p.append(".json");
  507. return p;
  508. }
  509. } // namespace ZeroTier