Node.cpp 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014
  1. /*
  2. * ZeroTier One - Global Peer to Peer Ethernet
  3. * Copyright (C) 2011-2014 ZeroTier Networks LLC
  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. * --
  19. *
  20. * ZeroTier may be used and distributed under the terms of the GPLv3, which
  21. * are available at: http://www.gnu.org/licenses/gpl-3.0.html
  22. *
  23. * If you would like to embed ZeroTier into a commercial application or
  24. * redistribute it in a modified binary form, please contact ZeroTier Networks
  25. * LLC. Start here: http://www.zerotier.com/
  26. */
  27. #include <stdio.h>
  28. #include <stdlib.h>
  29. #include <string.h>
  30. #include <errno.h>
  31. #include <sys/stat.h>
  32. #include <map>
  33. #include <set>
  34. #include <utility>
  35. #include <algorithm>
  36. #include <list>
  37. #include <vector>
  38. #include <string>
  39. #include "Constants.hpp"
  40. #ifdef __WINDOWS__
  41. #include <WinSock2.h>
  42. #include <Windows.h>
  43. #include <ShlObj.h>
  44. #else
  45. #include <fcntl.h>
  46. #include <unistd.h>
  47. #include <signal.h>
  48. #include <sys/file.h>
  49. #endif
  50. #include "../version.h"
  51. #include "Node.hpp"
  52. #include "RuntimeEnvironment.hpp"
  53. #include "Logger.hpp"
  54. #include "Utils.hpp"
  55. #include "Defaults.hpp"
  56. #include "Identity.hpp"
  57. #include "Topology.hpp"
  58. #include "SocketManager.hpp"
  59. #include "Packet.hpp"
  60. #include "Switch.hpp"
  61. #include "EthernetTap.hpp"
  62. #include "CMWC4096.hpp"
  63. #include "NodeConfig.hpp"
  64. #include "Network.hpp"
  65. #include "MulticastGroup.hpp"
  66. #include "Mutex.hpp"
  67. #include "Service.hpp"
  68. #include "SoftwareUpdater.hpp"
  69. #include "Buffer.hpp"
  70. #include "AntiRecursion.hpp"
  71. #include "RoutingTable.hpp"
  72. #include "HttpClient.hpp"
  73. namespace ZeroTier {
  74. struct _NodeImpl
  75. {
  76. RuntimeEnvironment renv;
  77. unsigned int udpPort,tcpPort;
  78. std::string reasonForTerminationStr;
  79. volatile Node::ReasonForTermination reasonForTermination;
  80. volatile bool started;
  81. volatile bool running;
  82. volatile bool resynchronize;
  83. volatile bool disableRootTopologyUpdates;
  84. // This function performs final node tear-down
  85. inline Node::ReasonForTermination terminate()
  86. {
  87. RuntimeEnvironment *RR = &renv;
  88. LOG("terminating: %s",reasonForTerminationStr.c_str());
  89. renv.shutdownInProgress = true;
  90. Thread::sleep(500);
  91. running = false;
  92. #ifndef __WINDOWS__
  93. delete renv.netconfService;
  94. #endif
  95. delete renv.updater; renv.updater = (SoftwareUpdater *)0;
  96. delete renv.nc; renv.nc = (NodeConfig *)0; // shut down all networks, close taps, etc.
  97. delete renv.topology; renv.topology = (Topology *)0; // now we no longer need routing info
  98. delete renv.sm; renv.sm = (SocketManager *)0; // close all sockets
  99. delete renv.sw; renv.sw = (Switch *)0; // order matters less from here down
  100. delete renv.antiRec; renv.antiRec = (AntiRecursion *)0;
  101. delete renv.http; renv.http = (HttpClient *)0;
  102. delete renv.prng; renv.prng = (CMWC4096 *)0;
  103. delete renv.log; renv.log = (Logger *)0; // but stop logging last of all
  104. return reasonForTermination;
  105. }
  106. inline Node::ReasonForTermination terminateBecause(Node::ReasonForTermination r,const char *rstr)
  107. {
  108. reasonForTerminationStr = rstr;
  109. reasonForTermination = r;
  110. return terminate();
  111. }
  112. };
  113. #ifndef __WINDOWS__ // "services" are not supported on Windows
  114. static void _netconfServiceMessageHandler(void *renv,Service &svc,const Dictionary &msg)
  115. {
  116. if (!renv)
  117. return; // sanity check
  118. const RuntimeEnvironment *RR = (const RuntimeEnvironment *)renv;
  119. try {
  120. //TRACE("from netconf:\n%s",msg.toString().c_str());
  121. const std::string &type = msg.get("type");
  122. if (type == "ready") {
  123. LOG("received 'ready' from netconf.service, sending netconf-init with identity information...");
  124. Dictionary initMessage;
  125. initMessage["type"] = "netconf-init";
  126. initMessage["netconfId"] = RR->identity.toString(true);
  127. RR->netconfService->send(initMessage);
  128. } else if (type == "netconf-response") {
  129. uint64_t inRePacketId = strtoull(msg.get("requestId").c_str(),(char **)0,16);
  130. uint64_t nwid = strtoull(msg.get("nwid").c_str(),(char **)0,16);
  131. Address peerAddress(msg.get("peer").c_str());
  132. if (peerAddress) {
  133. if (msg.contains("error")) {
  134. Packet::ErrorCode errCode = Packet::ERROR_INVALID_REQUEST;
  135. const std::string &err = msg.get("error");
  136. if (err == "OBJ_NOT_FOUND")
  137. errCode = Packet::ERROR_OBJ_NOT_FOUND;
  138. else if (err == "ACCESS_DENIED")
  139. errCode = Packet::ERROR_NETWORK_ACCESS_DENIED_;
  140. Packet outp(peerAddress,RR->identity.address(),Packet::VERB_ERROR);
  141. outp.append((unsigned char)Packet::VERB_NETWORK_CONFIG_REQUEST);
  142. outp.append(inRePacketId);
  143. outp.append((unsigned char)errCode);
  144. outp.append(nwid);
  145. RR->sw->send(outp,true);
  146. } else if (msg.contains("netconf")) {
  147. const std::string &netconf = msg.get("netconf");
  148. if (netconf.length() < 2048) { // sanity check
  149. Packet outp(peerAddress,RR->identity.address(),Packet::VERB_OK);
  150. outp.append((unsigned char)Packet::VERB_NETWORK_CONFIG_REQUEST);
  151. outp.append(inRePacketId);
  152. outp.append(nwid);
  153. outp.append((uint16_t)netconf.length());
  154. outp.append(netconf.data(),netconf.length());
  155. outp.compress();
  156. RR->sw->send(outp,true);
  157. }
  158. }
  159. }
  160. } else if (type == "netconf-push") {
  161. if (msg.contains("to")) {
  162. Dictionary to(msg.get("to")); // key: peer address, value: comma-delimited network list
  163. for(Dictionary::iterator t(to.begin());t!=to.end();++t) {
  164. Address ztaddr(t->first);
  165. if (ztaddr) {
  166. Packet outp(ztaddr,RR->identity.address(),Packet::VERB_NETWORK_CONFIG_REFRESH);
  167. char *saveptr = (char *)0;
  168. // Note: this loop trashes t->second, which is quasi-legal C++ but
  169. // shouldn't break anything as long as we don't try to use 'to'
  170. // for anything interesting after doing this.
  171. for(char *p=Utils::stok(const_cast<char *>(t->second.c_str()),",",&saveptr);(p);p=Utils::stok((char *)0,",",&saveptr)) {
  172. uint64_t nwid = Utils::hexStrToU64(p);
  173. if (nwid) {
  174. if ((outp.size() + sizeof(uint64_t)) >= ZT_UDP_DEFAULT_PAYLOAD_MTU) {
  175. RR->sw->send(outp,true);
  176. outp.reset(ztaddr,RR->identity.address(),Packet::VERB_NETWORK_CONFIG_REFRESH);
  177. }
  178. outp.append(nwid);
  179. }
  180. }
  181. if (outp.payloadLength())
  182. RR->sw->send(outp,true);
  183. }
  184. }
  185. }
  186. }
  187. } catch (std::exception &exc) {
  188. LOG("unexpected exception parsing response from netconf service: %s",exc.what());
  189. } catch ( ... ) {
  190. LOG("unexpected exception parsing response from netconf service: unknown exception");
  191. }
  192. }
  193. #endif // !__WINDOWS__
  194. Node::Node(
  195. const char *hp,
  196. EthernetTapFactory *tf,
  197. RoutingTable *rt,
  198. unsigned int udpPort,
  199. unsigned int tcpPort,
  200. bool resetIdentity)
  201. throw() :
  202. _impl(new _NodeImpl)
  203. {
  204. _NodeImpl *impl = (_NodeImpl *)_impl;
  205. if ((hp)&&(hp[0]))
  206. impl->renv.homePath = hp;
  207. else impl->renv.homePath = ZT_DEFAULTS.defaultHomePath;
  208. impl->renv.tapFactory = tf;
  209. impl->renv.routingTable = rt;
  210. if (resetIdentity) {
  211. // Forget identity and peer database, peer keys, etc.
  212. Utils::rm((impl->renv.homePath + ZT_PATH_SEPARATOR_S + "identity.public").c_str());
  213. Utils::rm((impl->renv.homePath + ZT_PATH_SEPARATOR_S + "identity.secret").c_str());
  214. Utils::rm((impl->renv.homePath + ZT_PATH_SEPARATOR_S + "peers.persist").c_str());
  215. // Truncate network config information in networks.d but leave the files since we
  216. // still want to remember any networks we have joined. This will force those networks
  217. // to be reconfigured with our newly regenerated identity after startup.
  218. std::string networksDotD(impl->renv.homePath + ZT_PATH_SEPARATOR_S + "networks.d");
  219. std::map< std::string,bool > nwfiles(Utils::listDirectory(networksDotD.c_str()));
  220. for(std::map<std::string,bool>::iterator nwf(nwfiles.begin());nwf!=nwfiles.end();++nwf) {
  221. FILE *trun = fopen((networksDotD + ZT_PATH_SEPARATOR_S + nwf->first).c_str(),"w");
  222. if (trun)
  223. fclose(trun);
  224. }
  225. }
  226. impl->udpPort = udpPort & 0xffff;
  227. impl->tcpPort = tcpPort & 0xffff;
  228. impl->reasonForTermination = Node::NODE_RUNNING;
  229. impl->started = false;
  230. impl->running = false;
  231. impl->resynchronize = false;
  232. impl->disableRootTopologyUpdates = false;
  233. }
  234. Node::~Node()
  235. {
  236. delete (_NodeImpl *)_impl;
  237. }
  238. static void _CBztTraffic(const SharedPtr<Socket> &fromSock,void *arg,const InetAddress &from,Buffer<ZT_SOCKET_MAX_MESSAGE_LEN> &data)
  239. {
  240. const RuntimeEnvironment *RR = (const RuntimeEnvironment *)arg;
  241. if ((RR->sw)&&(!RR->shutdownInProgress))
  242. RR->sw->onRemotePacket(fromSock,from,data);
  243. }
  244. static void _cbHandleGetRootTopology(void *arg,int code,const std::string &url,const std::string &body)
  245. {
  246. RuntimeEnvironment *RR = (RuntimeEnvironment *)arg;
  247. if (RR->shutdownInProgress)
  248. return;
  249. if ((code != 200)||(body.length() == 0)) {
  250. TRACE("failed to retrieve %s",url.c_str());
  251. return;
  252. }
  253. try {
  254. Dictionary rt(body);
  255. if (!Topology::authenticateRootTopology(rt)) {
  256. LOG("discarded invalid root topology update from %s (signature check failed)",url.c_str());
  257. return;
  258. }
  259. {
  260. std::string rootTopologyPath(RR->homePath + ZT_PATH_SEPARATOR_S + "root-topology");
  261. std::string rootTopology;
  262. if (Utils::readFile(rootTopologyPath.c_str(),rootTopology)) {
  263. Dictionary alreadyHave(rootTopology);
  264. if (alreadyHave == rt) {
  265. TRACE("retrieved root topology from %s but no change (same as on disk)",url.c_str());
  266. return;
  267. } else if (alreadyHave.signatureTimestamp() > rt.signatureTimestamp()) {
  268. TRACE("retrieved root topology from %s but no change (ours is newer)",url.c_str());
  269. return;
  270. }
  271. }
  272. Utils::writeFile(rootTopologyPath.c_str(),body);
  273. }
  274. RR->topology->setSupernodes(Dictionary(rt.get("supernodes")));
  275. } catch ( ... ) {
  276. LOG("discarded invalid root topology update from %s (format invalid)",url.c_str());
  277. return;
  278. }
  279. }
  280. Node::ReasonForTermination Node::run()
  281. throw()
  282. {
  283. _NodeImpl *impl = (_NodeImpl *)_impl;
  284. RuntimeEnvironment *RR = (RuntimeEnvironment *)&(impl->renv);
  285. impl->started = true;
  286. impl->running = true;
  287. try {
  288. #ifdef ZT_LOG_STDOUT
  289. RR->log = new Logger((const char *)0,(const char *)0,0);
  290. #else
  291. RR->log = new Logger((RR->homePath + ZT_PATH_SEPARATOR_S + "node.log").c_str(),(const char *)0,131072);
  292. #endif
  293. LOG("starting version %s",versionString());
  294. // Create non-crypto PRNG right away in case other code in init wants to use it
  295. RR->prng = new CMWC4096();
  296. // Read identity public and secret, generating if not present
  297. {
  298. bool gotId = false;
  299. std::string identitySecretPath(RR->homePath + ZT_PATH_SEPARATOR_S + "identity.secret");
  300. std::string identityPublicPath(RR->homePath + ZT_PATH_SEPARATOR_S + "identity.public");
  301. std::string idser;
  302. if (Utils::readFile(identitySecretPath.c_str(),idser))
  303. gotId = RR->identity.fromString(idser);
  304. if ((gotId)&&(!RR->identity.locallyValidate()))
  305. gotId = false;
  306. if (gotId) {
  307. // Make sure identity.public matches identity.secret
  308. idser = std::string();
  309. Utils::readFile(identityPublicPath.c_str(),idser);
  310. std::string pubid(RR->identity.toString(false));
  311. if (idser != pubid) {
  312. if (!Utils::writeFile(identityPublicPath.c_str(),pubid))
  313. return impl->terminateBecause(Node::NODE_UNRECOVERABLE_ERROR,"could not write identity.public (home path not writable?)");
  314. }
  315. } else {
  316. LOG("no identity found or identity invalid, generating one... this might take a few seconds...");
  317. RR->identity.generate();
  318. LOG("generated new identity: %s",RR->identity.address().toString().c_str());
  319. idser = RR->identity.toString(true);
  320. if (!Utils::writeFile(identitySecretPath.c_str(),idser))
  321. return impl->terminateBecause(Node::NODE_UNRECOVERABLE_ERROR,"could not write identity.secret (home path not writable?)");
  322. idser = RR->identity.toString(false);
  323. if (!Utils::writeFile(identityPublicPath.c_str(),idser))
  324. return impl->terminateBecause(Node::NODE_UNRECOVERABLE_ERROR,"could not write identity.public (home path not writable?)");
  325. }
  326. Utils::lockDownFile(identitySecretPath.c_str(),false);
  327. }
  328. // Make sure networks.d exists
  329. {
  330. std::string networksDotD(RR->homePath + ZT_PATH_SEPARATOR_S + "networks.d");
  331. #ifdef __WINDOWS__
  332. CreateDirectoryA(networksDotD.c_str(),NULL);
  333. #else
  334. mkdir(networksDotD.c_str(),0700);
  335. #endif
  336. }
  337. RR->http = new HttpClient();
  338. RR->antiRec = new AntiRecursion();
  339. RR->sw = new Switch(_r);
  340. RR->sm = new SocketManager(impl->udpPort,impl->tcpPort,&_CBztTraffic,_r);
  341. RR->topology = new Topology(RR,Utils::fileExists((RR->homePath + ZT_PATH_SEPARATOR_S + "iddb.d").c_str()));
  342. try {
  343. RR->nc = new NodeConfig(_r);
  344. } catch (std::exception &exc) {
  345. return impl->terminateBecause(Node::NODE_UNRECOVERABLE_ERROR,"unable to initialize IPC socket: is ZeroTier One already running?");
  346. }
  347. RR->node = this;
  348. #ifdef ZT_AUTO_UPDATE
  349. if (ZT_DEFAULTS.updateLatestNfoURL.length()) {
  350. RR->updater = new SoftwareUpdater(_r);
  351. RR->updater->cleanOldUpdates(); // clean out updates.d on startup
  352. } else {
  353. LOG("WARNING: unable to enable software updates: latest .nfo URL from ZT_DEFAULTS is empty (does this platform actually support software updates?)");
  354. }
  355. #endif
  356. // Initialize root topology from defaults or root-toplogy file in home path on disk
  357. {
  358. std::string rootTopologyPath(RR->homePath + ZT_PATH_SEPARATOR_S + "root-topology");
  359. std::string rootTopology;
  360. if (!Utils::readFile(rootTopologyPath.c_str(),rootTopology))
  361. rootTopology = ZT_DEFAULTS.defaultRootTopology;
  362. try {
  363. Dictionary rt(rootTopology);
  364. if (Topology::authenticateRootTopology(rt)) {
  365. // Set supernodes if root topology signature is valid
  366. RR->topology->setSupernodes(Dictionary(rt.get("supernodes",""))); // set supernodes from root-topology
  367. // If root-topology contains noupdate=1, disable further updates and only use what was on disk
  368. impl->disableRootTopologyUpdates = (Utils::strToInt(rt.get("noupdate","0").c_str()) > 0);
  369. } else {
  370. // Revert to built-in defaults if root topology fails signature check
  371. LOG("%s failed signature check, using built-in defaults instead",rootTopologyPath.c_str());
  372. Utils::rm(rootTopologyPath.c_str());
  373. RR->topology->setSupernodes(Dictionary(Dictionary(ZT_DEFAULTS.defaultRootTopology).get("supernodes","")));
  374. impl->disableRootTopologyUpdates = false;
  375. }
  376. } catch ( ... ) {
  377. return impl->terminateBecause(Node::NODE_UNRECOVERABLE_ERROR,"invalid root-topology format");
  378. }
  379. }
  380. } catch (std::bad_alloc &exc) {
  381. return impl->terminateBecause(Node::NODE_UNRECOVERABLE_ERROR,"memory allocation failure");
  382. } catch (std::runtime_error &exc) {
  383. return impl->terminateBecause(Node::NODE_UNRECOVERABLE_ERROR,exc.what());
  384. } catch ( ... ) {
  385. return impl->terminateBecause(Node::NODE_UNRECOVERABLE_ERROR,"unknown exception during initialization");
  386. }
  387. // Start external service subprocesses, which is only used by special nodes
  388. // right now and isn't available on Windows.
  389. #ifndef __WINDOWS__
  390. try {
  391. std::string netconfServicePath(RR->homePath + ZT_PATH_SEPARATOR_S + "services.d" + ZT_PATH_SEPARATOR_S + "netconf.service");
  392. if (Utils::fileExists(netconfServicePath.c_str())) {
  393. LOG("netconf.d/netconf.service appears to exist, starting...");
  394. RR->netconfService = new Service(RR,"netconf",netconfServicePath.c_str(),&_netconfServiceMessageHandler,_r);
  395. Dictionary initMessage;
  396. initMessage["type"] = "netconf-init";
  397. initMessage["netconfId"] = RR->identity.toString(true);
  398. RR->netconfService->send(initMessage);
  399. }
  400. } catch ( ... ) {
  401. LOG("unexpected exception attempting to start services");
  402. }
  403. #endif
  404. // Core I/O loop
  405. try {
  406. /* Shut down if this file exists but fails to open. This is used on Mac to
  407. * shut down automatically on .app deletion by symlinking this to the
  408. * Info.plist file inside the ZeroTier One application. This causes the
  409. * service to die when the user throws away the app, allowing uninstallation
  410. * in the natural Mac way. */
  411. std::string shutdownIfUnreadablePath(RR->homePath + ZT_PATH_SEPARATOR_S + "shutdownIfUnreadable");
  412. uint64_t lastNetworkAutoconfCheck = Utils::now() - 5000ULL; // check autoconf again after 5s for startup
  413. uint64_t lastPingCheck = 0;
  414. uint64_t lastClean = Utils::now(); // don't need to do this immediately
  415. uint64_t lastNetworkFingerprintCheck = 0;
  416. uint64_t lastMulticastCheck = 0;
  417. uint64_t lastSupernodePingCheck = 0;
  418. uint64_t lastBeacon = 0;
  419. uint64_t lastRootTopologyFetch = 0;
  420. uint64_t lastShutdownIfUnreadableCheck = 0;
  421. long lastDelayDelta = 0;
  422. uint64_t networkConfigurationFingerprint = 0;
  423. RR->timeOfLastResynchronize = Utils::now();
  424. // We are up and running
  425. RR->initialized = true;
  426. while (impl->reasonForTermination == NODE_RUNNING) {
  427. uint64_t now = Utils::now();
  428. bool resynchronize = false;
  429. /* This is how the service automatically shuts down when the OSX .app is
  430. * thrown in the trash. It's not used on any other platform for now but
  431. * could do similar things. It's disabled on Windows since it doesn't really
  432. * work there. */
  433. #ifdef __UNIX_LIKE__
  434. if ((now - lastShutdownIfUnreadableCheck) > 10000) {
  435. lastShutdownIfUnreadableCheck = now;
  436. if (Utils::fileExists(shutdownIfUnreadablePath.c_str(),false)) {
  437. int tmpfd = ::open(shutdownIfUnreadablePath.c_str(),O_RDONLY,0);
  438. if (tmpfd < 0) {
  439. return impl->terminateBecause(Node::NODE_NORMAL_TERMINATION,"shutdownIfUnreadable exists but is not readable");
  440. } else ::close(tmpfd);
  441. }
  442. }
  443. #endif
  444. // If it looks like the computer slept and woke, resynchronize.
  445. if (lastDelayDelta >= ZT_SLEEP_WAKE_DETECTION_THRESHOLD) {
  446. resynchronize = true;
  447. LOG("probable suspend/resume detected, pausing a moment for things to settle...");
  448. Thread::sleep(ZT_SLEEP_WAKE_SETTLE_TIME);
  449. }
  450. // If our network environment looks like it changed, resynchronize.
  451. if ((resynchronize)||((now - lastNetworkFingerprintCheck) >= ZT_NETWORK_FINGERPRINT_CHECK_DELAY)) {
  452. lastNetworkFingerprintCheck = now;
  453. uint64_t fp = RR->routingTable->networkEnvironmentFingerprint(RR->nc->networkTapDeviceNames());
  454. if (fp != networkConfigurationFingerprint) {
  455. LOG("netconf fingerprint change: %.16llx != %.16llx, resyncing with network",networkConfigurationFingerprint,fp);
  456. networkConfigurationFingerprint = fp;
  457. resynchronize = true;
  458. }
  459. }
  460. // Supernodes do not resynchronize unless explicitly ordered via SIGHUP.
  461. if ((resynchronize)&&(RR->topology->amSupernode()))
  462. resynchronize = false;
  463. // Check for SIGHUP / force resync.
  464. if (impl->resynchronize) {
  465. impl->resynchronize = false;
  466. resynchronize = true;
  467. LOG("resynchronize forced by user, syncing with network");
  468. }
  469. if (resynchronize) {
  470. RR->tcpTunnelingEnabled = false; // turn off TCP tunneling master switch at first, will be reenabled on persistent UDP failure
  471. RR->timeOfLastResynchronize = now;
  472. }
  473. /* Supernodes are pinged separately and more aggressively. The
  474. * ZT_STARTUP_AGGRO parameter sets a limit on how rapidly they are
  475. * tried, while PingSupernodesThatNeedPing contains the logic for
  476. * determining if they need PING. */
  477. if ((now - lastSupernodePingCheck) >= ZT_STARTUP_AGGRO) {
  478. lastSupernodePingCheck = now;
  479. uint64_t lastReceiveFromAnySupernode = 0; // function object result paramter
  480. RR->topology->eachSupernodePeer(Topology::FindMostRecentDirectReceiveTimestamp(lastReceiveFromAnySupernode));
  481. // Turn on TCP tunneling master switch if we haven't heard anything since before
  482. // the last resynchronize and we've been trying long enough.
  483. uint64_t tlr = RR->timeOfLastResynchronize;
  484. if ((lastReceiveFromAnySupernode < tlr)&&((now - tlr) >= ZT_TCP_TUNNEL_FAILOVER_TIMEOUT)) {
  485. TRACE("network still unreachable after %u ms, TCP TUNNELING ENABLED",(unsigned int)ZT_TCP_TUNNEL_FAILOVER_TIMEOUT);
  486. RR->tcpTunnelingEnabled = true;
  487. }
  488. RR->topology->eachSupernodePeer(Topology::PingSupernodesThatNeedPing(RR,now));
  489. }
  490. if (resynchronize) {
  491. /* Send NOP to all peers on resynchronize, directly to supernodes and
  492. * indirectly to regular nodes (to trigger RENDEZVOUS). Also clear
  493. * learned paths since they're likely no longer valid, and close
  494. * TCP sockets since they're also likely invalid. */
  495. RR->sm->closeTcpSockets();
  496. RR->topology->eachPeer(Topology::ResetActivePeers(RR,now));
  497. } else {
  498. /* Periodically check for changes in our local multicast subscriptions
  499. * and broadcast those changes to directly connected peers. */
  500. if ((now - lastMulticastCheck) >= ZT_MULTICAST_LOCAL_POLL_PERIOD) {
  501. lastMulticastCheck = now;
  502. try {
  503. std::vector< SharedPtr<Network> > networks(RR->nc->networks());
  504. for(std::vector< SharedPtr<Network> >::const_iterator nw(networks.begin());nw!=networks.end();++nw)
  505. (*nw)->updateMulticastGroups());
  506. } catch (std::exception &exc) {
  507. LOG("unexpected exception announcing multicast groups: %s",exc.what());
  508. } catch ( ... ) {
  509. LOG("unexpected exception announcing multicast groups: (unknown)");
  510. }
  511. }
  512. /* Periodically ping all our non-stale direct peers unless we're a supernode.
  513. * Supernodes only ping each other (which is done above). */
  514. if ((!RR->topology->amSupernode())&&((now - lastPingCheck) >= ZT_PING_CHECK_DELAY)) {
  515. lastPingCheck = now;
  516. try {
  517. RR->topology->eachPeer(Topology::PingPeersThatNeedPing(RR,now));
  518. } catch (std::exception &exc) {
  519. LOG("unexpected exception running ping check cycle: %s",exc.what());
  520. } catch ( ... ) {
  521. LOG("unexpected exception running ping check cycle: (unkonwn)");
  522. }
  523. }
  524. }
  525. // Update network configurations when needed.
  526. if ((resynchronize)||((now - lastNetworkAutoconfCheck) >= ZT_NETWORK_AUTOCONF_CHECK_DELAY)) {
  527. lastNetworkAutoconfCheck = now;
  528. std::vector< SharedPtr<Network> > nets(RR->nc->networks());
  529. for(std::vector< SharedPtr<Network> >::iterator n(nets.begin());n!=nets.end();++n) {
  530. if ((now - (*n)->lastConfigUpdate()) >= ZT_NETWORK_AUTOCONF_DELAY)
  531. (*n)->requestConfiguration();
  532. }
  533. }
  534. // Do periodic tasks in submodules.
  535. if ((now - lastClean) >= ZT_DB_CLEAN_PERIOD) {
  536. lastClean = now;
  537. RR->mc->clean();
  538. RR->topology->clean();
  539. RR->nc->clean();
  540. if (RR->updater)
  541. RR->updater->checkIfMaxIntervalExceeded(now);
  542. }
  543. // Send beacons to physical local LANs
  544. if ((resynchronize)||((now - lastBeacon) >= ZT_BEACON_INTERVAL)) {
  545. lastBeacon = now;
  546. char bcn[ZT_PROTO_BEACON_LENGTH];
  547. void *bcnptr = bcn;
  548. *((uint32_t *)(bcnptr)) = RR->prng->next32();
  549. bcnptr = bcn + 4;
  550. *((uint32_t *)(bcnptr)) = RR->prng->next32();
  551. RR->identity.address().copyTo(bcn + ZT_PROTO_BEACON_IDX_ADDRESS,ZT_ADDRESS_LENGTH);
  552. TRACE("sending LAN beacon to %s",ZT_DEFAULTS.v4Broadcast.toString().c_str());
  553. RR->antiRec->logOutgoingZT(bcn,ZT_PROTO_BEACON_LENGTH);
  554. RR->sm->send(ZT_DEFAULTS.v4Broadcast,false,false,bcn,ZT_PROTO_BEACON_LENGTH);
  555. }
  556. // Check for updates to root topology (supernodes) periodically
  557. if ((now - lastRootTopologyFetch) >= ZT_UPDATE_ROOT_TOPOLOGY_CHECK_INTERVAL) {
  558. lastRootTopologyFetch = now;
  559. if (!impl->disableRootTopologyUpdates) {
  560. TRACE("fetching root topology from %s",ZT_DEFAULTS.rootTopologyUpdateURL.c_str());
  561. RR->http->GET(ZT_DEFAULTS.rootTopologyUpdateURL,HttpClient::NO_HEADERS,60,&_cbHandleGetRootTopology,_r);
  562. }
  563. }
  564. // Sleep for loop interval or until something interesting happens.
  565. try {
  566. unsigned long delay = std::min((unsigned long)ZT_MAX_SERVICE_LOOP_INTERVAL,RR->sw->doTimerTasks());
  567. uint64_t start = Utils::now();
  568. RR->sm->poll(delay);
  569. lastDelayDelta = (long)(Utils::now() - start) - (long)delay; // used to detect sleep/wake
  570. } catch (std::exception &exc) {
  571. LOG("unexpected exception running Switch doTimerTasks: %s",exc.what());
  572. } catch ( ... ) {
  573. LOG("unexpected exception running Switch doTimerTasks: (unknown)");
  574. }
  575. }
  576. } catch ( ... ) {
  577. LOG("FATAL: unexpected exception in core loop: unknown exception");
  578. return impl->terminateBecause(Node::NODE_UNRECOVERABLE_ERROR,"unexpected exception during outer main I/O loop");
  579. }
  580. return impl->terminate();
  581. }
  582. const char *Node::terminationMessage() const
  583. throw()
  584. {
  585. if ((!((_NodeImpl *)_impl)->started)||(((_NodeImpl *)_impl)->running))
  586. return (const char *)0;
  587. return ((_NodeImpl *)_impl)->reasonForTerminationStr.c_str();
  588. }
  589. void Node::terminate(ReasonForTermination reason,const char *reasonText)
  590. throw()
  591. {
  592. ((_NodeImpl *)_impl)->reasonForTermination = reason;
  593. ((_NodeImpl *)_impl)->reasonForTerminationStr = ((reasonText) ? reasonText : "");
  594. ((_NodeImpl *)_impl)->renv.sm->whack();
  595. }
  596. void Node::resync()
  597. throw()
  598. {
  599. ((_NodeImpl *)_impl)->resynchronize = true;
  600. ((_NodeImpl *)_impl)->renv.sm->whack();
  601. }
  602. bool Node::online()
  603. throw()
  604. {
  605. _NodeImpl *impl = (_NodeImpl *)_impl;
  606. if (!impl->running)
  607. return false;
  608. RuntimeEnvironment *RR = (RuntimeEnvironment *)&(impl->renv);
  609. uint64_t now = Utils::now();
  610. uint64_t since = RR->timeOfLastResynchronize;
  611. std::vector< SharedPtr<Peer> > snp(RR->topology->supernodePeers());
  612. for(std::vector< SharedPtr<Peer> >::const_iterator sn(snp.begin());sn!=snp.end();++sn) {
  613. uint64_t lastRec = (*sn)->lastDirectReceive();
  614. if ((lastRec)&&(lastRec > since)&&((now - lastRec) < ZT_PEER_PATH_ACTIVITY_TIMEOUT))
  615. return true;
  616. }
  617. return false;
  618. }
  619. bool Node::started()
  620. throw()
  621. {
  622. _NodeImpl *impl = (_NodeImpl *)_impl;
  623. return impl->started;
  624. }
  625. bool Node::running()
  626. throw()
  627. {
  628. _NodeImpl *impl = (_NodeImpl *)_impl;
  629. return impl->running;
  630. }
  631. bool Node::initialized()
  632. throw()
  633. {
  634. _NodeImpl *impl = (_NodeImpl *)_impl;
  635. RuntimeEnvironment *RR = (RuntimeEnvironment *)&(impl->renv);
  636. return ((_r)&&(RR->initialized));
  637. }
  638. uint64_t Node::address()
  639. throw()
  640. {
  641. _NodeImpl *impl = (_NodeImpl *)_impl;
  642. RuntimeEnvironment *RR = (RuntimeEnvironment *)&(impl->renv);
  643. if ((!_r)||(!RR->initialized))
  644. return 0;
  645. return RR->identity.address().toInt();
  646. }
  647. void Node::join(uint64_t nwid)
  648. throw()
  649. {
  650. _NodeImpl *impl = (_NodeImpl *)_impl;
  651. RuntimeEnvironment *RR = (RuntimeEnvironment *)&(impl->renv);
  652. RR->nc->join(nwid);
  653. }
  654. void Node::leave(uint64_t nwid)
  655. throw()
  656. {
  657. _NodeImpl *impl = (_NodeImpl *)_impl;
  658. RuntimeEnvironment *RR = (RuntimeEnvironment *)&(impl->renv);
  659. RR->nc->leave(nwid);
  660. }
  661. struct GatherPeerStatistics
  662. {
  663. uint64_t now;
  664. ZT1_Node_Status *status;
  665. inline void operator()(Topology &t,const SharedPtr<Peer> &p)
  666. {
  667. ++status->knownPeers;
  668. if (p->hasActiveDirectPath(now))
  669. ++status->directlyConnectedPeers;
  670. if (p->alive(now))
  671. ++status->alivePeers;
  672. }
  673. };
  674. void Node::status(ZT1_Node_Status *status)
  675. throw()
  676. {
  677. _NodeImpl *impl = (_NodeImpl *)_impl;
  678. RuntimeEnvironment *RR = (RuntimeEnvironment *)&(impl->renv);
  679. memset(status,0,sizeof(ZT1_Node_Status));
  680. Utils::scopy(status->publicIdentity,sizeof(status->publicIdentity),RR->identity.toString(false).c_str());
  681. RR->identity.address().toString(status->address,sizeof(status->address));
  682. status->rawAddress = RR->identity.address().toInt();
  683. status->knownPeers = 0;
  684. status->supernodes = RR->topology->numSupernodes();
  685. status->directlyConnectedPeers = 0;
  686. status->alivePeers = 0;
  687. GatherPeerStatistics gps;
  688. gps.now = Utils::now();
  689. gps.status = status;
  690. RR->topology->eachPeer<GatherPeerStatistics &>(gps);
  691. if (status->alivePeers > 0) {
  692. double dlsr = (double)status->directlyConnectedPeers / (double)status->alivePeers;
  693. if (dlsr > 1.0) dlsr = 1.0;
  694. if (dlsr < 0.0) dlsr = 0.0;
  695. status->directLinkSuccessRate = (float)dlsr;
  696. } else status->directLinkSuccessRate = 1.0f; // no connections to no active peers == 100% success at nothing
  697. status->online = online();
  698. status->running = impl->running;
  699. }
  700. struct CollectPeersAndPaths
  701. {
  702. std::vector< std::pair< SharedPtr<Peer>,std::vector<Path> > > data;
  703. inline void operator()(Topology &t,const SharedPtr<Peer> &p) { this->data.push_back(std::pair< SharedPtr<Peer>,std::vector<Path> >(p,p->paths())); }
  704. };
  705. struct SortPeersAndPathsInAscendingAddressOrder
  706. {
  707. inline bool operator()(const std::pair< SharedPtr<Peer>,std::vector<Path> > &a,const std::pair< SharedPtr<Peer>,std::vector<Path> > &b) const { return (a.first->address() < b.first->address()); }
  708. };
  709. ZT1_Node_PeerList *Node::listPeers()
  710. throw()
  711. {
  712. _NodeImpl *impl = (_NodeImpl *)_impl;
  713. RuntimeEnvironment *RR = (RuntimeEnvironment *)&(impl->renv);
  714. CollectPeersAndPaths pp;
  715. RR->topology->eachPeer<CollectPeersAndPaths &>(pp);
  716. std::sort(pp.data.begin(),pp.data.end(),SortPeersAndPathsInAscendingAddressOrder());
  717. unsigned int returnBufSize = sizeof(ZT1_Node_PeerList);
  718. for(std::vector< std::pair< SharedPtr<Peer>,std::vector<Path> > >::iterator p(pp.data.begin());p!=pp.data.end();++p)
  719. returnBufSize += sizeof(ZT1_Node_Peer) + (sizeof(ZT1_Node_PhysicalPath) * p->second.size());
  720. char *buf = (char *)::malloc(returnBufSize);
  721. if (!buf)
  722. return (ZT1_Node_PeerList *)0;
  723. memset(buf,0,returnBufSize);
  724. ZT1_Node_PeerList *pl = (ZT1_Node_PeerList *)buf;
  725. buf += sizeof(ZT1_Node_PeerList);
  726. pl->peers = (ZT1_Node_Peer *)buf;
  727. buf += (sizeof(ZT1_Node_Peer) * pp.data.size());
  728. pl->numPeers = 0;
  729. uint64_t now = Utils::now();
  730. for(std::vector< std::pair< SharedPtr<Peer>,std::vector<Path> > >::iterator p(pp.data.begin());p!=pp.data.end();++p) {
  731. ZT1_Node_Peer *prec = &(pl->peers[pl->numPeers++]);
  732. if (p->first->remoteVersionKnown())
  733. Utils::snprintf(prec->remoteVersion,sizeof(prec->remoteVersion),"%u.%u.%u",p->first->remoteVersionMajor(),p->first->remoteVersionMinor(),p->first->remoteVersionRevision());
  734. p->first->address().toString(prec->address,sizeof(prec->address));
  735. prec->rawAddress = p->first->address().toInt();
  736. prec->latency = p->first->latency();
  737. prec->paths = (ZT1_Node_PhysicalPath *)buf;
  738. buf += sizeof(ZT1_Node_PhysicalPath) * p->second.size();
  739. prec->numPaths = 0;
  740. for(std::vector<Path>::iterator pi(p->second.begin());pi!=p->second.end();++pi) {
  741. ZT1_Node_PhysicalPath *path = &(prec->paths[prec->numPaths++]);
  742. path->type = static_cast<typeof(path->type)>(pi->type());
  743. if (pi->address().isV6()) {
  744. path->address.type = ZT1_Node_PhysicalAddress::ZT1_Node_PhysicalAddress_TYPE_IPV6;
  745. memcpy(path->address.bits,pi->address().rawIpData(),16);
  746. // TODO: zoneIndex not supported yet, but should be once echo-location works w/V6
  747. } else {
  748. path->address.type = ZT1_Node_PhysicalAddress::ZT1_Node_PhysicalAddress_TYPE_IPV4;
  749. memcpy(path->address.bits,pi->address().rawIpData(),4);
  750. }
  751. path->address.port = pi->address().port();
  752. Utils::scopy(path->address.ascii,sizeof(path->address.ascii),pi->address().toIpString().c_str());
  753. path->lastSend = (pi->lastSend() > 0) ? ((long)(now - pi->lastSend())) : (long)-1;
  754. path->lastReceive = (pi->lastReceived() > 0) ? ((long)(now - pi->lastReceived())) : (long)-1;
  755. path->lastPing = (pi->lastPing() > 0) ? ((long)(now - pi->lastPing())) : (long)-1;
  756. path->active = pi->active(now);
  757. path->fixed = pi->fixed();
  758. }
  759. }
  760. return pl;
  761. }
  762. // Fills out everything but ips[] and numIps, which must be done more manually
  763. static void _fillNetworkQueryResultBuffer(const SharedPtr<Network> &network,const SharedPtr<NetworkConfig> &nconf,ZT1_Node_Network *nbuf)
  764. {
  765. nbuf->nwid = network->id();
  766. Utils::snprintf(nbuf->nwidHex,sizeof(nbuf->nwidHex),"%.16llx",(unsigned long long)network->id());
  767. if (nconf) {
  768. Utils::scopy(nbuf->name,sizeof(nbuf->name),nconf->name().c_str());
  769. Utils::scopy(nbuf->description,sizeof(nbuf->description),nconf->description().c_str());
  770. }
  771. Utils::scopy(nbuf->device,sizeof(nbuf->device),network->tapDeviceName().c_str());
  772. Utils::scopy(nbuf->statusStr,sizeof(nbuf->statusStr),Network::statusString(network->status()));
  773. network->mac().toString(nbuf->macStr,sizeof(nbuf->macStr));
  774. network->mac().copyTo(nbuf->mac,sizeof(nbuf->mac));
  775. uint64_t lcu = network->lastConfigUpdate();
  776. if (lcu > 0)
  777. nbuf->configAge = (long)(Utils::now() - lcu);
  778. else nbuf->configAge = -1;
  779. nbuf->status = static_cast<typeof(nbuf->status)>(network->status());
  780. nbuf->enabled = network->enabled();
  781. nbuf->isPrivate = (nconf) ? nconf->isPrivate() : true;
  782. }
  783. ZT1_Node_Network *Node::getNetworkStatus(uint64_t nwid)
  784. throw()
  785. {
  786. _NodeImpl *impl = (_NodeImpl *)_impl;
  787. RuntimeEnvironment *RR = (RuntimeEnvironment *)&(impl->renv);
  788. SharedPtr<Network> network(RR->nc->network(nwid));
  789. if (!network)
  790. return (ZT1_Node_Network *)0;
  791. SharedPtr<NetworkConfig> nconf(network->config2());
  792. std::set<InetAddress> ips(network->ips());
  793. char *buf = (char *)::malloc(sizeof(ZT1_Node_Network) + (sizeof(ZT1_Node_PhysicalAddress) * ips.size()));
  794. if (!buf)
  795. return (ZT1_Node_Network *)0;
  796. memset(buf,0,sizeof(ZT1_Node_Network) + (sizeof(ZT1_Node_PhysicalAddress) * ips.size()));
  797. ZT1_Node_Network *nbuf = (ZT1_Node_Network *)buf;
  798. buf += sizeof(ZT1_Node_Network);
  799. _fillNetworkQueryResultBuffer(network,nconf,nbuf);
  800. nbuf->ips = (ZT1_Node_PhysicalAddress *)buf;
  801. nbuf->numIps = 0;
  802. for(std::set<InetAddress>::iterator ip(ips.begin());ip!=ips.end();++ip) {
  803. ZT1_Node_PhysicalAddress *ipb = &(nbuf->ips[nbuf->numIps++]);
  804. if (ip->isV6()) {
  805. ipb->type = ZT1_Node_PhysicalAddress::ZT1_Node_PhysicalAddress_TYPE_IPV6;
  806. memcpy(ipb->bits,ip->rawIpData(),16);
  807. } else {
  808. ipb->type = ZT1_Node_PhysicalAddress::ZT1_Node_PhysicalAddress_TYPE_IPV4;
  809. memcpy(ipb->bits,ip->rawIpData(),4);
  810. }
  811. ipb->port = ip->port();
  812. Utils::scopy(ipb->ascii,sizeof(ipb->ascii),ip->toIpString().c_str());
  813. }
  814. return nbuf;
  815. }
  816. ZT1_Node_NetworkList *Node::listNetworks()
  817. throw()
  818. {
  819. _NodeImpl *impl = (_NodeImpl *)_impl;
  820. RuntimeEnvironment *RR = (RuntimeEnvironment *)&(impl->renv);
  821. std::vector< SharedPtr<Network> > networks(RR->nc->networks());
  822. std::vector< SharedPtr<NetworkConfig> > nconfs(networks.size());
  823. std::vector< std::set<InetAddress> > ipsv(networks.size());
  824. unsigned long returnBufSize = sizeof(ZT1_Node_NetworkList);
  825. for(unsigned long i=0;i<networks.size();++i) {
  826. nconfs[i] = networks[i]->config2();
  827. ipsv[i] = networks[i]->ips();
  828. returnBufSize += sizeof(ZT1_Node_Network) + (sizeof(ZT1_Node_PhysicalAddress) * ipsv[i].size());
  829. }
  830. char *buf = (char *)::malloc(returnBufSize);
  831. if (!buf)
  832. return (ZT1_Node_NetworkList *)0;
  833. memset(buf,0,returnBufSize);
  834. ZT1_Node_NetworkList *nl = (ZT1_Node_NetworkList *)buf;
  835. buf += sizeof(ZT1_Node_NetworkList);
  836. nl->networks = (ZT1_Node_Network *)buf;
  837. buf += sizeof(ZT1_Node_Network) * networks.size();
  838. for(unsigned long i=0;i<networks.size();++i) {
  839. ZT1_Node_Network *nbuf = &(nl->networks[nl->numNetworks++]);
  840. _fillNetworkQueryResultBuffer(networks[i],nconfs[i],nbuf);
  841. nbuf->ips = (ZT1_Node_PhysicalAddress *)buf;
  842. buf += sizeof(ZT1_Node_PhysicalAddress);
  843. nbuf->numIps = 0;
  844. for(std::set<InetAddress>::iterator ip(ipsv[i].begin());ip!=ipsv[i].end();++ip) {
  845. ZT1_Node_PhysicalAddress *ipb = &(nbuf->ips[nbuf->numIps++]);
  846. if (ip->isV6()) {
  847. ipb->type = ZT1_Node_PhysicalAddress::ZT1_Node_PhysicalAddress_TYPE_IPV6;
  848. memcpy(ipb->bits,ip->rawIpData(),16);
  849. } else {
  850. ipb->type = ZT1_Node_PhysicalAddress::ZT1_Node_PhysicalAddress_TYPE_IPV4;
  851. memcpy(ipb->bits,ip->rawIpData(),4);
  852. }
  853. ipb->port = ip->port();
  854. Utils::scopy(ipb->ascii,sizeof(ipb->ascii),ip->toIpString().c_str());
  855. }
  856. }
  857. return nl;
  858. }
  859. void Node::freeQueryResult(void *qr)
  860. throw()
  861. {
  862. if (qr)
  863. ::free(qr);
  864. }
  865. bool Node::updateCheck()
  866. throw()
  867. {
  868. _NodeImpl *impl = (_NodeImpl *)_impl;
  869. RuntimeEnvironment *RR = (RuntimeEnvironment *)&(impl->renv);
  870. if (RR->updater) {
  871. RR->updater->checkNow();
  872. return true;
  873. }
  874. return false;
  875. }
  876. class _VersionStringMaker
  877. {
  878. public:
  879. char vs[32];
  880. _VersionStringMaker()
  881. {
  882. Utils::snprintf(vs,sizeof(vs),"%d.%d.%d",(int)ZEROTIER_ONE_VERSION_MAJOR,(int)ZEROTIER_ONE_VERSION_MINOR,(int)ZEROTIER_ONE_VERSION_REVISION);
  883. }
  884. ~_VersionStringMaker() {}
  885. };
  886. static const _VersionStringMaker __versionString;
  887. const char *Node::versionString() throw() { return __versionString.vs; }
  888. unsigned int Node::versionMajor() throw() { return ZEROTIER_ONE_VERSION_MAJOR; }
  889. unsigned int Node::versionMinor() throw() { return ZEROTIER_ONE_VERSION_MINOR; }
  890. unsigned int Node::versionRevision() throw() { return ZEROTIER_ONE_VERSION_REVISION; }
  891. } // namespace ZeroTier