Network.hpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759
  1. /*
  2. * ZeroTier One - Global Peer to Peer Ethernet
  3. * Copyright (C) 2012-2013 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. #ifndef _ZT_NETWORK_HPP
  28. #define _ZT_NETWORK_HPP
  29. #include <stdint.h>
  30. #include <string>
  31. #include <set>
  32. #include <map>
  33. #include <vector>
  34. #include <algorithm>
  35. #include <stdexcept>
  36. #include "Constants.hpp"
  37. #include "Utils.hpp"
  38. #include "EthernetTap.hpp"
  39. #include "Address.hpp"
  40. #include "Mutex.hpp"
  41. #include "SharedPtr.hpp"
  42. #include "AtomicCounter.hpp"
  43. #include "MulticastGroup.hpp"
  44. #include "NonCopyable.hpp"
  45. #include "MAC.hpp"
  46. #include "Dictionary.hpp"
  47. #include "Identity.hpp"
  48. #include "InetAddress.hpp"
  49. #include "BandwidthAccount.hpp"
  50. #include "C25519.hpp"
  51. namespace ZeroTier {
  52. class RuntimeEnvironment;
  53. class NodeConfig;
  54. /**
  55. * A virtual LAN
  56. *
  57. * Networks can be open or closed. Each network has an ID whose most
  58. * significant 40 bits are the ZeroTier address of the node that should
  59. * be contacted for network configuration. The least significant 24
  60. * bits are arbitrary, allowing up to 2^24 networks per managing
  61. * node.
  62. *
  63. * Open networks do not track membership. Anyone is allowed to communicate
  64. * over them.
  65. *
  66. * Closed networks track membership by way of timestamped signatures. When
  67. * the network requests its configuration, one of the fields returned is
  68. * a signature for the identity of the peer on the network. This signature
  69. * includes a timestamp. When a peer communicates with other peers on a
  70. * closed network, it periodically (and pre-emptively) propagates this
  71. * signature to the peers with which it is communicating. Peers reject
  72. * packets with an error if no recent signature is on file.
  73. */
  74. class Network : NonCopyable
  75. {
  76. friend class SharedPtr<Network>;
  77. friend class NodeConfig;
  78. public:
  79. /**
  80. * Certificate of network membership
  81. *
  82. * The COM contains a sorted set of three-element tuples called qualifiers.
  83. * These contain an id, a value, and a maximum delta.
  84. *
  85. * The ID is arbitrary and should be assigned using a scheme that makes
  86. * every ID globally unique. ID 0 is reserved for the always-present
  87. * validity timestamp and range, and ID 1 is reserved for the always-present
  88. * network ID. IDs less than 65536 are reserved for future global
  89. * assignment.
  90. *
  91. * The value's meaning is ID-specific and isn't important here. What's
  92. * important is the value and the third member of the tuple: the maximum
  93. * delta. The maximum delta is the maximum difference permitted between
  94. * values for a given ID between certificates for the two certificates to
  95. * themselves agree.
  96. *
  97. * Network membership is checked by checking whether a peer's certificate
  98. * agrees with your own. The timestamp provides the fundamental criterion--
  99. * each member of a private network must constantly obtain new certificates
  100. * often enough to stay within the max delta for this qualifier. But other
  101. * criteria could be added in the future for very special behaviors, things
  102. * like latitude and longitude for instance.
  103. */
  104. class CertificateOfMembership
  105. {
  106. public:
  107. /**
  108. * Certificate type codes, used in serialization
  109. *
  110. * Only one so far, and only one hopefully there shall be for quite some
  111. * time.
  112. */
  113. enum Type
  114. {
  115. COM_UINT64_ED25519 = 1 // tuples of unsigned 64's signed with Ed25519
  116. };
  117. /**
  118. * Reserved COM IDs
  119. *
  120. * IDs below 65536 should be considered reserved for future global
  121. * assignment here.
  122. */
  123. enum ReservedIds
  124. {
  125. COM_RESERVED_ID_TIMESTAMP = 0, // timestamp, max delta defines cert life
  126. COM_RESERVED_ID_NETWORK_ID = 1 // network ID, max delta always 0
  127. };
  128. CertificateOfMembership() {}
  129. CertificateOfMembership(const char *s) { fromString(s); }
  130. CertificateOfMembership(const std::string &s) { fromString(s.c_str()); }
  131. /**
  132. * Add or update a qualifier in this certificate
  133. *
  134. * Any signature is invalidated and signedBy is set to null.
  135. *
  136. * @param id Qualifier ID
  137. * @param value Qualifier value
  138. * @param maxDelta Qualifier maximum allowed difference (absolute value of difference)
  139. */
  140. void setQualifier(uint64_t id,uint64_t value,uint64_t maxDelta);
  141. /**
  142. * @return String-serialized representation of this certificate
  143. */
  144. std::string toString() const;
  145. /**
  146. * Set this certificate equal to the hex-serialized string
  147. *
  148. * Invalid strings will result in invalid or undefined certificate
  149. * contents. These will subsequently fail validation and comparison.
  150. *
  151. * @param s String to deserialize
  152. */
  153. void fromString(const char *s);
  154. inline void fromString(const std::string &s) { fromString(s.c_str()); }
  155. /**
  156. * Compare two certificates for parameter agreement
  157. *
  158. * This compares this certificate with the other and returns true if all
  159. * paramters in this cert are present in the other and if they agree to
  160. * within this cert's max delta value for each given parameter.
  161. *
  162. * Tuples present in other but not in this cert are ignored, but any
  163. * tuples present in this cert but not in other result in 'false'.
  164. *
  165. * @param other Cert to compare with
  166. * @return True if certs agree and 'other' may be communicated with
  167. */
  168. bool agreesWith(const CertificateOfMembership &other) const
  169. throw();
  170. /**
  171. * Sign this certificate
  172. *
  173. * @param with Identity to sign with, must include private key
  174. * @return True if signature was successful
  175. */
  176. bool sign(const Identity &with);
  177. /**
  178. * Verify certificate against an identity
  179. *
  180. * @param id Identity to verify against
  181. * @return True if certificate is signed by this identity and verification was successful
  182. */
  183. bool verify(const Identity &id) const;
  184. /**
  185. * @return True if signed
  186. */
  187. inline bool isSigned() const
  188. throw()
  189. {
  190. return (_signedBy);
  191. }
  192. /**
  193. * @return Address that signed this certificate or null address if none
  194. */
  195. inline const Address &signedBy() const
  196. throw()
  197. {
  198. return _signedBy;
  199. }
  200. private:
  201. struct _Qualifier
  202. {
  203. _Qualifier() throw() {}
  204. _Qualifier(uint64_t i,uint64_t v,uint64_t m) throw() :
  205. id(i),
  206. value(v),
  207. maxDelta(m) {}
  208. uint64_t id;
  209. uint64_t value;
  210. uint64_t maxDelta;
  211. inline bool operator==(const _Qualifier &q) const throw() { return (id == q.id); } // for unique
  212. inline bool operator<(const _Qualifier &q) const throw() { return (id < q.id); } // for sort
  213. };
  214. std::vector<_Qualifier> _qualifiers; // sorted by id and unique
  215. Address _signedBy;
  216. C25519::Signature _signature;
  217. };
  218. /**
  219. * Preload and rates of accrual for multicast group bandwidth limits
  220. *
  221. * Key is multicast group in lower case hex format: MAC (without :s) /
  222. * ADI (hex). Value is preload, maximum balance, and rate of accrual in
  223. * hex.
  224. */
  225. class MulticastRates : private Dictionary
  226. {
  227. public:
  228. /**
  229. * Preload and accrual parameter tuple
  230. */
  231. struct Rate
  232. {
  233. Rate() {}
  234. Rate(uint32_t pl,uint32_t maxb,uint32_t acc)
  235. {
  236. preload = pl;
  237. maxBalance = maxb;
  238. accrual = acc;
  239. }
  240. uint32_t preload;
  241. uint32_t maxBalance;
  242. uint32_t accrual;
  243. };
  244. MulticastRates() {}
  245. MulticastRates(const char *s) : Dictionary(s) {}
  246. MulticastRates(const std::string &s) : Dictionary(s) {}
  247. inline std::string toString() const { return Dictionary::toString(); }
  248. /**
  249. * A very minimal default rate, fast enough for ARP
  250. */
  251. static const Rate GLOBAL_DEFAULT_RATE;
  252. /**
  253. * @return Default rate, or GLOBAL_DEFAULT_RATE if not specified
  254. */
  255. inline Rate defaultRate() const
  256. {
  257. Rate r;
  258. const_iterator dfl(find("*"));
  259. if (dfl == end())
  260. return GLOBAL_DEFAULT_RATE;
  261. return _toRate(dfl->second);
  262. }
  263. /**
  264. * Get the rate for a given multicast group
  265. *
  266. * @param mg Multicast group
  267. * @return Rate or default() rate if not specified
  268. */
  269. inline Rate get(const MulticastGroup &mg) const
  270. {
  271. const_iterator r(find(mg.toString()));
  272. if (r == end())
  273. return defaultRate();
  274. return _toRate(r->second);
  275. }
  276. private:
  277. static inline Rate _toRate(const std::string &s)
  278. {
  279. char tmp[16384];
  280. Utils::scopy(tmp,sizeof(tmp),s.c_str());
  281. Rate r(0,0,0);
  282. char *saveptr = (char *)0;
  283. unsigned int fn = 0;
  284. for(char *f=Utils::stok(tmp,",",&saveptr);(f);f=Utils::stok((char *)0,",",&saveptr)) {
  285. switch(fn++) {
  286. case 0:
  287. r.preload = (uint32_t)Utils::hexStrToULong(f);
  288. break;
  289. case 1:
  290. r.maxBalance = (uint32_t)Utils::hexStrToULong(f);
  291. break;
  292. case 2:
  293. r.accrual = (uint32_t)Utils::hexStrToULong(f);
  294. break;
  295. }
  296. }
  297. return r;
  298. }
  299. };
  300. /**
  301. * A network configuration for a given node
  302. *
  303. * Configuration fields:
  304. *
  305. * nwid=<hex network ID> (required)
  306. * name=short name
  307. * desc=long(er) description
  308. * com=Serialized certificate of membership
  309. * mr=MulticastRates (serialized dictionary)
  310. * md=multicast propagation depth
  311. * mpb=multicast propagation prefix bits (2^mpb packets are sent by origin)
  312. * o=open network? (1 or 0, default false if missing)
  313. * et=ethertype whitelist (comma-delimited list of ethertypes in decimal)
  314. * v4s=IPv4 static assignments / netmasks (comma-delimited)
  315. * v6s=IPv6 static assignments / netmasks (comma-delimited)
  316. *
  317. * Notes:
  318. *
  319. * If zero appears in the 'et' list, the sense is inverted. It becomes an
  320. * ethertype blacklist instead of a whitelist and anything not blacklisted
  321. * is permitted.
  322. */
  323. class Config : private Dictionary
  324. {
  325. public:
  326. Config() {}
  327. Config(const char *s) : Dictionary(s) {}
  328. Config(const std::string &s) : Dictionary(s) {}
  329. inline std::string toString() const { return Dictionary::toString(); }
  330. /**
  331. * @return True if configuration is valid and contains required fields
  332. */
  333. inline operator bool() const throw() { return (find("nwid") != end()); }
  334. /**
  335. * @return Network ID
  336. * @throws std::invalid_argument Network ID field missing
  337. */
  338. inline uint64_t networkId() const
  339. throw(std::invalid_argument)
  340. {
  341. return Utils::hexStrToU64(get("nwid").c_str());
  342. }
  343. /**
  344. * Get this network's short name, or its ID in hex if unspecified
  345. *
  346. * @return Short name of this network (e.g. "earth")
  347. */
  348. inline std::string name() const
  349. {
  350. const_iterator n(find("name"));
  351. if (n == end())
  352. return get("nwid");
  353. return n->second;
  354. }
  355. /**
  356. * @return Long description of network or empty string if not present
  357. */
  358. inline std::string desc() const
  359. {
  360. return get("desc",std::string());
  361. }
  362. /**
  363. * @return Certificate of membership for this network, or empty cert if none
  364. */
  365. inline CertificateOfMembership certificateOfMembership() const
  366. {
  367. const_iterator cm(find("com"));
  368. if (cm == end())
  369. return CertificateOfMembership();
  370. else return CertificateOfMembership(cm->second);
  371. }
  372. /**
  373. * @return Multicast rates for this network
  374. */
  375. inline MulticastRates multicastRates() const
  376. {
  377. const_iterator mr(find("mr"));
  378. if (mr == end())
  379. return MulticastRates();
  380. else return MulticastRates(mr->second);
  381. }
  382. /**
  383. * @return Number of bits in propagation prefix for this network
  384. */
  385. inline unsigned int multicastPrefixBits() const
  386. {
  387. const_iterator mpb(find("mpb"));
  388. if (mpb == end())
  389. return ZT_DEFAULT_MULTICAST_PREFIX_BITS;
  390. unsigned int tmp = Utils::hexStrToUInt(mpb->second.c_str());
  391. if (tmp)
  392. return tmp;
  393. else return ZT_DEFAULT_MULTICAST_PREFIX_BITS;
  394. }
  395. /**
  396. * @return Maximum multicast propagation depth for this network
  397. */
  398. inline unsigned int multicastDepth() const
  399. {
  400. const_iterator md(find("md"));
  401. if (md == end())
  402. return ZT_DEFAULT_MULTICAST_DEPTH;
  403. unsigned int tmp = Utils::hexStrToUInt(md->second.c_str());
  404. if (tmp)
  405. return tmp;
  406. else return ZT_DEFAULT_MULTICAST_DEPTH;
  407. }
  408. /**
  409. * @return True if this is an open non-access-controlled network
  410. */
  411. inline bool isOpen() const
  412. {
  413. const_iterator o(find("o"));
  414. if (o == end())
  415. return false;
  416. else if (!o->second.length())
  417. return false;
  418. else return (o->second[0] == '1');
  419. }
  420. /**
  421. * @return Network ethertype whitelist
  422. */
  423. inline std::set<unsigned int> etherTypes() const
  424. {
  425. char tmp[16384];
  426. char *saveptr = (char *)0;
  427. std::set<unsigned int> et;
  428. if (!Utils::scopy(tmp,sizeof(tmp),get("et","").c_str()))
  429. return et; // sanity check, packet can't really be that big
  430. for(char *f=Utils::stok(tmp,",",&saveptr);(f);f=Utils::stok((char *)0,",",&saveptr)) {
  431. unsigned int t = Utils::hexStrToUInt(f);
  432. if (t)
  433. et.insert(t);
  434. }
  435. return et;
  436. }
  437. /**
  438. * @return All static addresses / netmasks, IPv4 or IPv6
  439. */
  440. inline std::set<InetAddress> staticAddresses() const
  441. {
  442. std::set<InetAddress> sa;
  443. std::vector<std::string> ips(Utils::split(get("v4s","").c_str(),",","",""));
  444. for(std::vector<std::string>::const_iterator i(ips.begin());i!=ips.end();++i)
  445. sa.insert(InetAddress(*i));
  446. ips = Utils::split(get("v6s","").c_str(),",","","");
  447. for(std::vector<std::string>::const_iterator i(ips.begin());i!=ips.end();++i)
  448. sa.insert(InetAddress(*i));
  449. return sa;
  450. }
  451. };
  452. /**
  453. * Status for networks
  454. */
  455. enum Status
  456. {
  457. NETWORK_WAITING_FOR_FIRST_AUTOCONF,
  458. NETWORK_OK,
  459. NETWORK_ACCESS_DENIED
  460. };
  461. /**
  462. * @param s Status
  463. * @return String description
  464. */
  465. static const char *statusString(const Status s)
  466. throw();
  467. private:
  468. // Only NodeConfig can create, only SharedPtr can delete
  469. // Actual construction happens in newInstance()
  470. Network()
  471. throw() :
  472. _tap((EthernetTap *)0)
  473. {
  474. }
  475. ~Network();
  476. /**
  477. * Create a new Network instance and restore any saved state
  478. *
  479. * If there is no saved state, a dummy .conf is created on disk to remember
  480. * this network across restarts.
  481. *
  482. * @param renv Runtime environment
  483. * @param id Network ID
  484. * @return Reference counted pointer to new network
  485. * @throws std::runtime_error Unable to create tap device or other fatal error
  486. */
  487. static SharedPtr<Network> newInstance(const RuntimeEnvironment *renv,uint64_t id)
  488. throw(std::runtime_error);
  489. /**
  490. * Causes all persistent disk presence to be erased on delete
  491. */
  492. inline void destroyOnDelete()
  493. throw()
  494. {
  495. _destroyOnDelete = true;
  496. }
  497. public:
  498. /**
  499. * @return Network ID
  500. */
  501. inline uint64_t id() const throw() { return _id; }
  502. /**
  503. * @return Ethernet tap
  504. */
  505. inline EthernetTap &tap() throw() { return *_tap; }
  506. /**
  507. * @return Address of network's controlling node
  508. */
  509. inline Address controller() throw() { return Address(_id >> 24); }
  510. /**
  511. * @return Network ID in hexadecimal form
  512. */
  513. inline std::string idString()
  514. {
  515. char buf[64];
  516. Utils::snprintf(buf,sizeof(buf),"%.16llx",(unsigned long long)_id);
  517. return std::string(buf);
  518. }
  519. /**
  520. * @return True if network is open (no membership required)
  521. */
  522. inline bool isOpen() const
  523. throw()
  524. {
  525. Mutex::Lock _l(_lock);
  526. return _isOpen;
  527. }
  528. /**
  529. * Update multicast groups for this network's tap
  530. *
  531. * @return True if internal multicast group set has changed
  532. */
  533. inline bool updateMulticastGroups()
  534. {
  535. Mutex::Lock _l(_lock);
  536. return _tap->updateMulticastGroups(_multicastGroups);
  537. }
  538. /**
  539. * @return Latest set of multicast groups for this network's tap
  540. */
  541. inline std::set<MulticastGroup> multicastGroups() const
  542. {
  543. Mutex::Lock _l(_lock);
  544. return _multicastGroups;
  545. }
  546. /**
  547. * Set or update this network's configuration
  548. *
  549. * This is called by PacketDecoder when an update comes over the wire, or
  550. * internally when an old config is reloaded from disk.
  551. *
  552. * @param conf Configuration in key/value dictionary form
  553. */
  554. void setConfiguration(const Config &conf);
  555. /**
  556. * Causes this network to request an updated configuration from its master node now
  557. */
  558. void requestConfiguration();
  559. /**
  560. * Add or update a peer's membership certificate
  561. *
  562. * The certificate must already have been validated via signature checking.
  563. *
  564. * @param peer Peer that owns certificate
  565. * @param cert Certificate itself
  566. */
  567. void addMembershipCertificate(const Address &peer,const CertificateOfMembership &cert);
  568. /**
  569. * @param peer Peer address to check
  570. * @return True if peer is allowed to communicate on this network
  571. */
  572. bool isAllowed(const Address &peer) const;
  573. /**
  574. * Perform cleanup and possibly save state
  575. */
  576. void clean();
  577. /**
  578. * @return Time of last updated configuration or 0 if none
  579. */
  580. inline uint64_t lastConfigUpdate() const
  581. throw()
  582. {
  583. return _lastConfigUpdate;
  584. }
  585. /**
  586. * @return Status of this network
  587. */
  588. Status status() const;
  589. /**
  590. * Determine whether frames of a given ethernet type are allowed on this network
  591. *
  592. * @param etherType Ethernet frame type
  593. * @return True if network permits this type
  594. */
  595. inline bool permitsEtherType(unsigned int etherType) const
  596. throw()
  597. {
  598. if (!etherType)
  599. return false;
  600. else if (etherType > 65535)
  601. return false;
  602. else if ((_etWhitelist[0] & 1)) // if type 0 is in the whitelist, sense is inverted from whitelist to blacklist
  603. return ((_etWhitelist[etherType / 8] & (unsigned char)(1 << (etherType & 7))) == 0);
  604. else return ((_etWhitelist[etherType / 8] & (unsigned char)(1 << (etherType & 7))) != 0);
  605. }
  606. /**
  607. * Update multicast balance for an address and multicast group, return whether packet is allowed
  608. *
  609. * @param a Address that wants to send/relay packet
  610. * @param mg Multicast group
  611. * @param bytes Size of packet
  612. * @return True if packet is within budget
  613. */
  614. inline bool updateAndCheckMulticastBalance(const Address &a,const MulticastGroup &mg,unsigned int bytes)
  615. {
  616. Mutex::Lock _l(_lock);
  617. std::pair<Address,MulticastGroup> k(a,mg);
  618. std::map< std::pair<Address,MulticastGroup>,BandwidthAccount >::iterator bal(_multicastRateAccounts.find(k));
  619. if (bal == _multicastRateAccounts.end()) {
  620. MulticastRates::Rate r(_mcRates.get(mg));
  621. bal = _multicastRateAccounts.insert(std::pair< std::pair<Address,MulticastGroup>,BandwidthAccount >(k,BandwidthAccount(r.preload,r.maxBalance,r.accrual))).first;
  622. }
  623. return bal->second.deduct(bytes);
  624. //bool tmp = bal->second.deduct(bytes);
  625. //printf("%s: BAL: %u\n",mg.toString().c_str(),(unsigned int)bal->second.balance());
  626. //return tmp;
  627. }
  628. /**
  629. * @return True if this network allows bridging
  630. */
  631. inline bool permitsBridging() const
  632. throw()
  633. {
  634. return false; // TODO: bridging not implemented yet
  635. }
  636. /**
  637. * @return Bits in multicast restriciton prefix
  638. */
  639. inline unsigned int multicastPrefixBits() const
  640. throw()
  641. {
  642. return _multicastPrefixBits;
  643. }
  644. /**
  645. * @return Max depth (TTL) for a multicast frame
  646. */
  647. inline unsigned int multicastDepth() const
  648. throw()
  649. {
  650. return _multicastDepth;
  651. }
  652. private:
  653. static void _CBhandleTapData(void *arg,const MAC &from,const MAC &to,unsigned int etherType,const Buffer<4096> &data);
  654. void _restoreState();
  655. const RuntimeEnvironment *_r;
  656. // Multicast bandwidth accounting for peers on this network
  657. std::map< std::pair<Address,MulticastGroup>,BandwidthAccount > _multicastRateAccounts;
  658. // Tap and tap multicast memberships for this node on this network
  659. EthernetTap *_tap;
  660. std::set<MulticastGroup> _multicastGroups;
  661. // Membership certificates supplied by other peers on this network
  662. std::map<Address,CertificateOfMembership> _membershipCertificates;
  663. // Configuration from network master node
  664. Config _configuration;
  665. CertificateOfMembership _myCertificate; // memoized from _configuration
  666. MulticastRates _mcRates; // memoized from _configuration
  667. std::set<InetAddress> _staticAddresses; // memoized from _configuration
  668. bool _isOpen; // memoized from _configuration
  669. unsigned int _multicastPrefixBits; // memoized from _configuration
  670. unsigned int _multicastDepth; // memoized from _configuration
  671. // Ethertype whitelist bit field, set from config, for really fast lookup
  672. unsigned char _etWhitelist[65536 / 8];
  673. uint64_t _id;
  674. volatile uint64_t _lastConfigUpdate;
  675. volatile bool _destroyOnDelete;
  676. volatile bool _ready;
  677. Mutex _lock;
  678. AtomicCounter __refCount;
  679. };
  680. } // naemspace ZeroTier
  681. #endif