Node.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  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. * --
  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 "../version.h"
  28. #include "Constants.hpp"
  29. #include "Node.hpp"
  30. #include "RuntimeEnvironment.hpp"
  31. #include "NetworkConfigMaster.hpp"
  32. #include "CMWC4096.hpp"
  33. #include "Switch.hpp"
  34. #include "Multicaster.hpp"
  35. #include "AntiRecursion.hpp"
  36. #include "Topology.hpp"
  37. #include "Buffer.hpp"
  38. #include "Packet.hpp"
  39. #include "Address.hpp"
  40. #include "Identity.hpp"
  41. #include "SelfAwareness.hpp"
  42. #include "Defaults.hpp"
  43. namespace ZeroTier {
  44. /****************************************************************************/
  45. /* Public Node interface (C++, exposed via CAPI bindings) */
  46. /****************************************************************************/
  47. Node::Node(
  48. uint64_t now,
  49. ZT1_DataStoreGetFunction dataStoreGetFunction,
  50. ZT1_DataStorePutFunction dataStorePutFunction,
  51. ZT1_WirePacketSendFunction wirePacketSendFunction,
  52. ZT1_VirtualNetworkFrameFunction virtualNetworkFrameFunction,
  53. ZT1_VirtualNetworkConfigFunction virtualNetworkConfigFunction,
  54. ZT1_EventCallback eventCallback,
  55. const char *overrideRootTopology) :
  56. RR(new RuntimeEnvironment(this)),
  57. _dataStoreGetFunction(dataStoreGetFunction),
  58. _dataStorePutFunction(dataStorePutFunction),
  59. _wirePacketSendFunction(wirePacketSendFunction),
  60. _virtualNetworkFrameFunction(virtualNetworkFrameFunction),
  61. _virtualNetworkConfigFunction(virtualNetworkConfigFunction),
  62. _eventCallback(eventCallback),
  63. _networks(),
  64. _networks_m(),
  65. _now(now),
  66. _startTimeAfterInactivity(0),
  67. _lastPingCheck(0),
  68. _lastHousekeepingRun(0),
  69. _coreDesperation(0)
  70. {
  71. _newestVersionSeen[0] = ZEROTIER_ONE_VERSION_MAJOR;
  72. _newestVersionSeen[1] = ZEROTIER_ONE_VERSION_MINOR;
  73. _newestVersionSeen[2] = ZEROTIER_ONE_VERSION_REVISION;
  74. std::string idtmp(dataStoreGet("identity.secret"));
  75. if ((!idtmp.length())||(!RR->identity.fromString(idtmp))||(!RR->identity.hasPrivate())) {
  76. RR->identity.generate();
  77. idtmp = RR->identity.toString(true);
  78. if (!dataStorePut("identity.secret",idtmp,true)) {
  79. delete RR;
  80. throw std::runtime_error("unable to write identity.secret");
  81. }
  82. idtmp = RR->identity.toString(false);
  83. if (!dataStorePut("identity.public",idtmp,false)) {
  84. delete RR;
  85. throw std::runtime_error("unable to write identity.public");
  86. }
  87. }
  88. try {
  89. RR->prng = new CMWC4096();
  90. RR->sw = new Switch(RR);
  91. RR->mc = new Multicaster(RR);
  92. RR->antiRec = new AntiRecursion();
  93. RR->topology = new Topology(RR);
  94. RR->sa = new SelfAwareness(RR);
  95. } catch ( ... ) {
  96. delete RR->sa;
  97. delete RR->topology;
  98. delete RR->antiRec;
  99. delete RR->mc;
  100. delete RR->sw;
  101. delete RR->prng;
  102. delete RR;
  103. throw;
  104. }
  105. Dictionary rt;
  106. if (overrideRootTopology) {
  107. rt.fromString(std::string(overrideRootTopology));
  108. } else {
  109. std::string rttmp(dataStoreGet("root-topology"));
  110. if (rttmp.length() > 0) {
  111. rt.fromString(rttmp);
  112. if (!Topology::authenticateRootTopology(rt))
  113. rt.clear();
  114. }
  115. if (!rt.size())
  116. rt.fromString(ZT_DEFAULTS.defaultRootTopology);
  117. }
  118. RR->topology->setSupernodes(Dictionary(rt.get("supernodes","")));
  119. postEvent(ZT1_EVENT_UP);
  120. }
  121. Node::~Node()
  122. {
  123. delete RR->sa;
  124. delete RR->topology;
  125. delete RR->antiRec;
  126. delete RR->mc;
  127. delete RR->sw;
  128. delete RR->prng;
  129. delete RR;
  130. }
  131. ZT1_ResultCode Node::processWirePacket(
  132. uint64_t now,
  133. const struct sockaddr_storage *remoteAddress,
  134. unsigned int linkDesperation,
  135. const void *packetData,
  136. unsigned int packetLength,
  137. uint64_t *nextBackgroundTaskDeadline)
  138. {
  139. if (now >= *nextBackgroundTaskDeadline) {
  140. ZT1_ResultCode rc = processBackgroundTasks(now,nextBackgroundTaskDeadline);
  141. if (rc != ZT1_RESULT_OK)
  142. return rc;
  143. } else _now = now;
  144. RR->sw->onRemotePacket(*(reinterpret_cast<const InetAddress *>(remoteAddress)),linkDesperation,packetData,packetLength);
  145. return ZT1_RESULT_OK;
  146. }
  147. ZT1_ResultCode Node::processVirtualNetworkFrame(
  148. uint64_t now,
  149. uint64_t nwid,
  150. uint64_t sourceMac,
  151. uint64_t destMac,
  152. unsigned int etherType,
  153. unsigned int vlanId,
  154. const void *frameData,
  155. unsigned int frameLength,
  156. uint64_t *nextBackgroundTaskDeadline)
  157. {
  158. if (now >= *nextBackgroundTaskDeadline) {
  159. ZT1_ResultCode rc = processBackgroundTasks(now,nextBackgroundTaskDeadline);
  160. if (rc != ZT1_RESULT_OK)
  161. return rc;
  162. } else _now = now;
  163. SharedPtr<Network> nw(network(nwid));
  164. if (nw)
  165. RR->sw->onLocalEthernet(nw,MAC(sourceMac),MAC(destMac),etherType,vlanId,frameData,frameLength);
  166. else return ZT1_RESULT_ERROR_NETWORK_NOT_FOUND;
  167. return ZT1_RESULT_OK;
  168. }
  169. class _PingPeersThatNeedPing
  170. {
  171. public:
  172. _PingPeersThatNeedPing(const RuntimeEnvironment *renv,uint64_t now) :
  173. lastReceiveFromSupernode(0),
  174. RR(renv),
  175. _now(now),
  176. _supernodes(RR->topology->supernodeAddresses()) {}
  177. uint64_t lastReceiveFromSupernode;
  178. inline void operator()(Topology &t,const SharedPtr<Peer> &p)
  179. {
  180. if (std::find(_supernodes.begin(),_supernodes.end(),p->address()) != _supernodes.end()) {
  181. p->doPingAndKeepalive(RR,_now);
  182. if (p->lastReceive() > lastReceiveFromSupernode)
  183. lastReceiveFromSupernode = p->lastReceive();
  184. } else if (p->alive(_now)) {
  185. p->doPingAndKeepalive(RR,_now);
  186. }
  187. }
  188. private:
  189. const RuntimeEnvironment *RR;
  190. uint64_t _now;
  191. std::vector<Address> _supernodes;
  192. };
  193. ZT1_ResultCode Node::processBackgroundTasks(uint64_t now,uint64_t *nextBackgroundTaskDeadline)
  194. {
  195. _now = now;
  196. Mutex::Lock bl(_backgroundTasksLock);
  197. if ((now - _lastPingCheck) >= ZT_PING_CHECK_INVERVAL) {
  198. _lastPingCheck = now;
  199. if ((now - _startTimeAfterInactivity) > (ZT_PING_CHECK_INVERVAL * 3))
  200. _startTimeAfterInactivity = now;
  201. try {
  202. _PingPeersThatNeedPing pfunc(RR,now);
  203. RR->topology->eachPeer<_PingPeersThatNeedPing &>(pfunc);
  204. _coreDesperation = (unsigned int)((now - std::max(_startTimeAfterInactivity,pfunc.lastReceiveFromSupernode)) / (ZT_PING_CHECK_INVERVAL * ZT_CORE_DESPERATION_INCREMENT));
  205. } catch ( ... ) {
  206. return ZT1_RESULT_FATAL_ERROR_INTERNAL;
  207. }
  208. try {
  209. Mutex::Lock _l(_networks_m);
  210. for(std::map< uint64_t,SharedPtr<Network> >::const_iterator n(_networks.begin());n!=_networks.end();++n) {
  211. if ((now - n->second->lastConfigUpdate()) >= ZT_NETWORK_AUTOCONF_DELAY)
  212. n->second->requestConfiguration();
  213. }
  214. } catch ( ... ) {
  215. return ZT1_RESULT_FATAL_ERROR_INTERNAL;
  216. }
  217. }
  218. if ((now - _lastHousekeepingRun) >= ZT_HOUSEKEEPING_PERIOD) {
  219. _lastHousekeepingRun = now;
  220. try {
  221. RR->topology->clean(now);
  222. } catch ( ... ) {
  223. return ZT1_RESULT_FATAL_ERROR_INTERNAL;
  224. }
  225. try {
  226. RR->mc->clean(now);
  227. } catch ( ... ) {
  228. return ZT1_RESULT_FATAL_ERROR_INTERNAL;
  229. }
  230. }
  231. try {
  232. *nextBackgroundTaskDeadline = now + (uint64_t)std::max(std::min((unsigned long)ZT_PING_CHECK_INVERVAL,RR->sw->doTimerTasks(now)),(unsigned long)ZT_CORE_TIMER_TASK_GRANULARITY);
  233. } catch ( ... ) {
  234. return ZT1_RESULT_FATAL_ERROR_INTERNAL;
  235. }
  236. return ZT1_RESULT_OK;
  237. }
  238. ZT1_ResultCode Node::join(uint64_t nwid)
  239. {
  240. Mutex::Lock _l(_networks_m);
  241. SharedPtr<Network> &nw = _networks[nwid];
  242. if (!nw)
  243. nw = SharedPtr<Network>(new Network(RR,nwid));
  244. return ZT1_RESULT_OK;
  245. }
  246. ZT1_ResultCode Node::leave(uint64_t nwid)
  247. {
  248. Mutex::Lock _l(_networks_m);
  249. std::map< uint64_t,SharedPtr<Network> >::iterator nw(_networks.find(nwid));
  250. if (nw != _networks.end()) {
  251. nw->second->destroy();
  252. _networks.erase(nw);
  253. }
  254. }
  255. ZT1_ResultCode Node::multicastSubscribe(uint64_t nwid,uint64_t multicastGroup,unsigned long multicastAdi)
  256. {
  257. Mutex::Lock _l(_networks_m);
  258. std::map< uint64_t,SharedPtr<Network> >::iterator nw(_networks.find(nwid));
  259. if (nw != _networks.end())
  260. nw->second->multicastSubscribe(MulticastGroup(MAC(multicastGroup),(uint32_t)(multicastAdi & 0xffffffff)));
  261. }
  262. ZT1_ResultCode Node::multicastUnsubscribe(uint64_t nwid,uint64_t multicastGroup,unsigned long multicastAdi)
  263. {
  264. Mutex::Lock _l(_networks_m);
  265. std::map< uint64_t,SharedPtr<Network> >::iterator nw(_networks.find(nwid));
  266. if (nw != _networks.end())
  267. nw->second->multicastUnsubscribe(MulticastGroup(MAC(multicastGroup),(uint32_t)(multicastAdi & 0xffffffff)));
  268. }
  269. void Node::status(ZT1_NodeStatus *status)
  270. {
  271. }
  272. ZT1_PeerList *Node::peers()
  273. {
  274. }
  275. ZT1_VirtualNetworkConfig *Node::networkConfig(uint64_t nwid)
  276. {
  277. Mutex::Lock _l(_networks_m);
  278. std::map< uint64_t,SharedPtr<Network> >::iterator nw(_networks.find(nwid));
  279. if (nw != _networks.end()) {
  280. ZT1_VirtualNetworkConfig *nc = (ZT1_VirtualNetworkConfig *)::malloc(sizeof(ZT1_VirtualNetworkConfig));
  281. nw->second->externalConfig(nc);
  282. return nc;
  283. }
  284. return (ZT1_VirtualNetworkConfig *)0;
  285. }
  286. ZT1_VirtualNetworkList *Node::networks()
  287. {
  288. }
  289. void Node::freeQueryResult(void *qr)
  290. {
  291. if (qr)
  292. ::free(qr);
  293. }
  294. void Node::setNetconfMaster(void *networkConfigMasterInstance)
  295. {
  296. RR->netconfMaster = reinterpret_cast<NetworkConfigMaster *>(networkConfigMasterInstance);
  297. }
  298. /****************************************************************************/
  299. /* Node methods used only within node/ */
  300. /****************************************************************************/
  301. std::string Node::dataStoreGet(const char *name)
  302. {
  303. char buf[16384];
  304. std::string r;
  305. unsigned long olen = 0;
  306. do {
  307. long n = _dataStoreGetFunction(reinterpret_cast<ZT1_Node *>(this),name,buf,sizeof(buf),r.length(),&olen);
  308. if (n <= 0)
  309. return std::string();
  310. r.append(buf,n);
  311. } while (r.length() < olen);
  312. return r;
  313. }
  314. void Node::postNewerVersionIfNewer(unsigned int major,unsigned int minor,unsigned int rev)
  315. {
  316. if (Peer::compareVersion(major,minor,rev,_newestVersionSeen[0],_newestVersionSeen[1],_newestVersionSeen[2]) > 0) {
  317. _newestVersionSeen[0] = major;
  318. _newestVersionSeen[1] = minor;
  319. _newestVersionSeen[2] = rev;
  320. this->postEvent(ZT1_EVENT_SAW_MORE_RECENT_VERSION,(const void *)_newestVersionSeen);
  321. }
  322. }
  323. #ifdef ZT_TRACE
  324. void Node::postTrace(const char *module,unsigned int line,const char *fmt,...)
  325. {
  326. static Mutex traceLock;
  327. va_list ap;
  328. char tmp1[1024],tmp2[1024],tmp3[256];
  329. Mutex::Lock _l(traceLock);
  330. #ifdef __WINDOWS__
  331. ctime_s(tmp3,sizeof(tmp3),&now);
  332. const char *nowstr = tmp3;
  333. #else
  334. const char *nowstr = ctime_r(&now,tmp3);
  335. #endif
  336. va_start(ap,fmt);
  337. vsnprintf(tmp2,sizeof(tmp2),fmt,ap);
  338. va_end(ap);
  339. tmp2[sizeof(tmp2)-1] = (char)0;
  340. Utils::snprintf(tmp1,sizeof(tmp1),"[%s] %s:%u %s",nowstr,module,line,tmp2);
  341. postEvent(ZT1_EVENT_TRACE,tmp1);
  342. }
  343. #endif // ZT_TRACE
  344. } // namespace ZeroTier
  345. /****************************************************************************/
  346. /* CAPI bindings */
  347. /****************************************************************************/
  348. extern "C" {
  349. enum ZT1_ResultCode ZT1_Node_new(
  350. ZT1_Node **node,
  351. uint64_t now,
  352. ZT1_DataStoreGetFunction dataStoreGetFunction,
  353. ZT1_DataStorePutFunction dataStorePutFunction,
  354. ZT1_WirePacketSendFunction wirePacketSendFunction,
  355. ZT1_VirtualNetworkFrameFunction virtualNetworkFrameFunction,
  356. ZT1_VirtualNetworkConfigFunction virtualNetworkConfigFunction,
  357. ZT1_EventCallback eventCallback,
  358. const char *overrideRootTopology)
  359. {
  360. *node = (ZT1_Node *)0;
  361. try {
  362. *node = reinterpret_cast<ZT1_Node *>(new ZeroTier::Node(now,dataStoreGetFunction,dataStorePutFunction,wirePacketSendFunction,virtualNetworkFrameFunction,virtualNetworkConfigFunction,eventCallback,overrideRootTopology));
  363. return ZT1_RESULT_OK;
  364. } catch (std::bad_alloc &exc) {
  365. return ZT1_RESULT_FATAL_ERROR_OUT_OF_MEMORY;
  366. } catch (std::runtime_error &exc) {
  367. return ZT1_RESULT_FATAL_ERROR_DATA_STORE_FAILED;
  368. } catch ( ... ) {
  369. return ZT1_RESULT_FATAL_ERROR_INTERNAL;
  370. }
  371. }
  372. void ZT1_Node_delete(ZT1_Node *node)
  373. {
  374. try {
  375. delete (reinterpret_cast<ZeroTier::Node *>(node));
  376. } catch ( ... ) {}
  377. }
  378. enum ZT1_ResultCode ZT1_Node_processWirePacket(
  379. ZT1_Node *node,
  380. uint64_t now,
  381. const struct sockaddr_storage *remoteAddress,
  382. unsigned int linkDesperation,
  383. const void *packetData,
  384. unsigned int packetLength,
  385. uint64_t *nextBackgroundTaskDeadline)
  386. {
  387. try {
  388. return reinterpret_cast<ZeroTier::Node *>(node)->processWirePacket(now,remoteAddress,linkDesperation,packetData,packetLength,nextBackgroundTaskDeadline);
  389. } catch (std::bad_alloc &exc) {
  390. return ZT1_RESULT_FATAL_ERROR_OUT_OF_MEMORY;
  391. } catch ( ... ) {
  392. reinterpret_cast<ZeroTier::Node *>(node)->postEvent(ZT1_EVENT_INVALID_PACKET,(const void *)remoteAddress);
  393. return ZT1_RESULT_OK;
  394. }
  395. }
  396. enum ZT1_ResultCode ZT1_Node_processVirtualNetworkFrame(
  397. ZT1_Node *node,
  398. uint64_t now,
  399. uint64_t nwid,
  400. uint64_t sourceMac,
  401. uint64_t destMac,
  402. unsigned int etherType,
  403. unsigned int vlanId,
  404. const void *frameData,
  405. unsigned int frameLength,
  406. uint64_t *nextBackgroundTaskDeadline)
  407. {
  408. try {
  409. return reinterpret_cast<ZeroTier::Node *>(node)->processVirtualNetworkFrame(now,nwid,sourceMac,destMac,etherType,vlanId,frameData,frameLength,nextBackgroundTaskDeadline);
  410. } catch (std::bad_alloc &exc) {
  411. return ZT1_RESULT_FATAL_ERROR_OUT_OF_MEMORY;
  412. } catch ( ... ) {
  413. return ZT1_RESULT_FATAL_ERROR_INTERNAL;
  414. }
  415. }
  416. enum ZT1_ResultCode ZT1_Node_processBackgroundTasks(ZT1_Node *node,uint64_t now,uint64_t *nextBackgroundTaskDeadline)
  417. {
  418. try {
  419. return reinterpret_cast<ZeroTier::Node *>(node)->processBackgroundTasks(now,nextBackgroundTaskDeadline);
  420. } catch (std::bad_alloc &exc) {
  421. return ZT1_RESULT_FATAL_ERROR_OUT_OF_MEMORY;
  422. } catch ( ... ) {
  423. return ZT1_RESULT_FATAL_ERROR_INTERNAL;
  424. }
  425. }
  426. enum ZT1_ResultCode ZT1_Node_join(ZT1_Node *node,uint64_t nwid)
  427. {
  428. try {
  429. return reinterpret_cast<ZeroTier::Node *>(node)->join(nwid);
  430. } catch (std::bad_alloc &exc) {
  431. return ZT1_RESULT_FATAL_ERROR_OUT_OF_MEMORY;
  432. } catch ( ... ) {
  433. return ZT1_RESULT_FATAL_ERROR_INTERNAL;
  434. }
  435. }
  436. enum ZT1_ResultCode ZT1_Node_leave(ZT1_Node *node,uint64_t nwid)
  437. {
  438. try {
  439. return reinterpret_cast<ZeroTier::Node *>(node)->leave(nwid);
  440. } catch (std::bad_alloc &exc) {
  441. return ZT1_RESULT_FATAL_ERROR_OUT_OF_MEMORY;
  442. } catch ( ... ) {
  443. return ZT1_RESULT_FATAL_ERROR_INTERNAL;
  444. }
  445. }
  446. enum ZT1_ResultCode ZT1_Node_multicastSubscribe(ZT1_Node *node,uint64_t nwid,uint64_t multicastGroup,unsigned long multicastAdi)
  447. {
  448. try {
  449. return reinterpret_cast<ZeroTier::Node *>(node)->multicastSubscribe(nwid,multicastGroup,multicastAdi);
  450. } catch (std::bad_alloc &exc) {
  451. return ZT1_RESULT_FATAL_ERROR_OUT_OF_MEMORY;
  452. } catch ( ... ) {
  453. return ZT1_RESULT_FATAL_ERROR_INTERNAL;
  454. }
  455. }
  456. enum ZT1_ResultCode ZT1_Node_multicastUnsubscribe(ZT1_Node *node,uint64_t nwid,uint64_t multicastGroup,unsigned long multicastAdi)
  457. {
  458. try {
  459. return reinterpret_cast<ZeroTier::Node *>(node)->multicastUnsubscribe(nwid,multicastGroup,multicastAdi);
  460. } catch (std::bad_alloc &exc) {
  461. return ZT1_RESULT_FATAL_ERROR_OUT_OF_MEMORY;
  462. } catch ( ... ) {
  463. return ZT1_RESULT_FATAL_ERROR_INTERNAL;
  464. }
  465. }
  466. void ZT1_Node_status(ZT1_Node *node,ZT1_NodeStatus *status)
  467. {
  468. try {
  469. reinterpret_cast<ZeroTier::Node *>(node)->status(status);
  470. } catch ( ... ) {}
  471. }
  472. ZT1_PeerList *ZT1_Node_peers(ZT1_Node *node)
  473. {
  474. try {
  475. return reinterpret_cast<ZeroTier::Node *>(node)->peers();
  476. } catch ( ... ) {
  477. return (ZT1_PeerList *)0;
  478. }
  479. }
  480. ZT1_VirtualNetworkConfig *ZT1_Node_networkConfig(ZT1_Node *node,uint64_t nwid)
  481. {
  482. try {
  483. return reinterpret_cast<ZeroTier::Node *>(node)->networkConfig(nwid);
  484. } catch ( ... ) {
  485. return (ZT1_VirtualNetworkConfig *)0;
  486. }
  487. }
  488. ZT1_VirtualNetworkList *ZT1_Node_networks(ZT1_Node *node)
  489. {
  490. try {
  491. return reinterpret_cast<ZeroTier::Node *>(node)->networks();
  492. } catch ( ... ) {
  493. return (ZT1_VirtualNetworkList *)0;
  494. }
  495. }
  496. void ZT1_Node_freeQueryResult(ZT1_Node *node,void *qr)
  497. {
  498. try {
  499. reinterpret_cast<ZeroTier::Node *>(node)->freeQueryResult(qr);
  500. } catch ( ... ) {}
  501. }
  502. void ZT1_Node_setNetconfMaster(ZT1_Node *node,void *networkConfigMasterInstance)
  503. {
  504. try {
  505. reinterpret_cast<ZeroTier::Node *>(node)->setNetconfMaster(networkConfigMasterInstance);
  506. } catch ( ... ) {}
  507. }
  508. void ZT1_version(int *major,int *minor,int *revision,unsigned long *featureFlags)
  509. {
  510. if (major) *major = ZEROTIER_ONE_VERSION_MAJOR;
  511. if (minor) *minor = ZEROTIER_ONE_VERSION_MINOR;
  512. if (revision) *revision = ZEROTIER_ONE_VERSION_REVISION;
  513. if (featureFlags) {
  514. *featureFlags = (
  515. ZT1_FEATURE_FLAG_THREAD_SAFE
  516. #ifdef ZT_OFFICIAL_BUILD
  517. | ZT1_FEATURE_FLAG_OFFICIAL
  518. #endif
  519. );
  520. }
  521. }
  522. } // extern "C"