Node.cpp 16 KB

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