Network.hpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751
  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() { memset(_signature.data,0,_signature.size()); }
  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 throw() { return (_signedBy); }
  188. /**
  189. * @return Address that signed this certificate or null address if none
  190. */
  191. inline const Address &signedBy() const throw() { return _signedBy; }
  192. private:
  193. struct _Qualifier
  194. {
  195. _Qualifier() throw() {}
  196. _Qualifier(uint64_t i,uint64_t v,uint64_t m) throw() :
  197. id(i),
  198. value(v),
  199. maxDelta(m) {}
  200. uint64_t id;
  201. uint64_t value;
  202. uint64_t maxDelta;
  203. inline bool operator==(const _Qualifier &q) const throw() { return (id == q.id); } // for unique
  204. inline bool operator<(const _Qualifier &q) const throw() { return (id < q.id); } // for sort
  205. };
  206. std::vector<_Qualifier> _qualifiers; // sorted by id and unique
  207. Address _signedBy;
  208. C25519::Signature _signature;
  209. };
  210. /**
  211. * Preload and rates of accrual for multicast group bandwidth limits
  212. *
  213. * Key is multicast group in lower case hex format: MAC (without :s) /
  214. * ADI (hex). Value is preload, maximum balance, and rate of accrual in
  215. * hex.
  216. */
  217. class MulticastRates : private Dictionary
  218. {
  219. public:
  220. /**
  221. * Preload and accrual parameter tuple
  222. */
  223. struct Rate
  224. {
  225. Rate() {}
  226. Rate(uint32_t pl,uint32_t maxb,uint32_t acc)
  227. {
  228. preload = pl;
  229. maxBalance = maxb;
  230. accrual = acc;
  231. }
  232. uint32_t preload;
  233. uint32_t maxBalance;
  234. uint32_t accrual;
  235. };
  236. MulticastRates() {}
  237. MulticastRates(const char *s) : Dictionary(s) {}
  238. MulticastRates(const std::string &s) : Dictionary(s) {}
  239. inline std::string toString() const { return Dictionary::toString(); }
  240. /**
  241. * A very minimal default rate, fast enough for ARP
  242. */
  243. static const Rate GLOBAL_DEFAULT_RATE;
  244. /**
  245. * @return Default rate, or GLOBAL_DEFAULT_RATE if not specified
  246. */
  247. inline Rate defaultRate() const
  248. {
  249. Rate r;
  250. const_iterator dfl(find("*"));
  251. if (dfl == end())
  252. return GLOBAL_DEFAULT_RATE;
  253. return _toRate(dfl->second);
  254. }
  255. /**
  256. * Get the rate for a given multicast group
  257. *
  258. * @param mg Multicast group
  259. * @return Rate or default() rate if not specified
  260. */
  261. inline Rate get(const MulticastGroup &mg) const
  262. {
  263. const_iterator r(find(mg.toString()));
  264. if (r == end())
  265. return defaultRate();
  266. return _toRate(r->second);
  267. }
  268. private:
  269. static inline Rate _toRate(const std::string &s)
  270. {
  271. char tmp[16384];
  272. Utils::scopy(tmp,sizeof(tmp),s.c_str());
  273. Rate r(0,0,0);
  274. char *saveptr = (char *)0;
  275. unsigned int fn = 0;
  276. for(char *f=Utils::stok(tmp,",",&saveptr);(f);f=Utils::stok((char *)0,",",&saveptr)) {
  277. switch(fn++) {
  278. case 0:
  279. r.preload = (uint32_t)Utils::hexStrToULong(f);
  280. break;
  281. case 1:
  282. r.maxBalance = (uint32_t)Utils::hexStrToULong(f);
  283. break;
  284. case 2:
  285. r.accrual = (uint32_t)Utils::hexStrToULong(f);
  286. break;
  287. }
  288. }
  289. return r;
  290. }
  291. };
  292. /**
  293. * A network configuration for a given node
  294. *
  295. * Configuration fields:
  296. *
  297. * nwid=<hex network ID> (required)
  298. * name=short name
  299. * desc=long(er) description
  300. * com=Serialized certificate of membership
  301. * mr=MulticastRates (serialized dictionary)
  302. * md=multicast propagation depth
  303. * mpb=multicast propagation prefix bits (2^mpb packets are sent by origin)
  304. * o=open network? (1 or 0, default false if missing)
  305. * et=ethertype whitelist (comma-delimited list of ethertypes in decimal)
  306. * v4s=IPv4 static assignments / netmasks (comma-delimited)
  307. * v6s=IPv6 static assignments / netmasks (comma-delimited)
  308. *
  309. * Notes:
  310. *
  311. * If zero appears in the 'et' list, the sense is inverted. It becomes an
  312. * ethertype blacklist instead of a whitelist and anything not blacklisted
  313. * is permitted.
  314. */
  315. class Config : private Dictionary
  316. {
  317. public:
  318. Config() {}
  319. Config(const char *s) : Dictionary(s) {}
  320. Config(const std::string &s) : Dictionary(s) {}
  321. inline std::string toString() const { return Dictionary::toString(); }
  322. /**
  323. * @return True if configuration is valid and contains required fields
  324. */
  325. inline operator bool() const throw() { return (find("nwid") != end()); }
  326. /**
  327. * @return Network ID
  328. * @throws std::invalid_argument Network ID field missing
  329. */
  330. inline uint64_t networkId() const
  331. throw(std::invalid_argument)
  332. {
  333. return Utils::hexStrToU64(get("nwid").c_str());
  334. }
  335. /**
  336. * Get this network's short name, or its ID in hex if unspecified
  337. *
  338. * @return Short name of this network (e.g. "earth")
  339. */
  340. inline std::string name() const
  341. {
  342. const_iterator n(find("name"));
  343. if (n == end())
  344. return get("nwid");
  345. return n->second;
  346. }
  347. /**
  348. * @return Long description of network or empty string if not present
  349. */
  350. inline std::string desc() const
  351. {
  352. return get("desc",std::string());
  353. }
  354. /**
  355. * @return Certificate of membership for this network, or empty cert if none
  356. */
  357. inline CertificateOfMembership certificateOfMembership() const
  358. {
  359. const_iterator cm(find("com"));
  360. if (cm == end())
  361. return CertificateOfMembership();
  362. else return CertificateOfMembership(cm->second);
  363. }
  364. /**
  365. * @return Multicast rates for this network
  366. */
  367. inline MulticastRates multicastRates() const
  368. {
  369. const_iterator mr(find("mr"));
  370. if (mr == end())
  371. return MulticastRates();
  372. else return MulticastRates(mr->second);
  373. }
  374. /**
  375. * @return Number of bits in propagation prefix for this network
  376. */
  377. inline unsigned int multicastPrefixBits() const
  378. {
  379. const_iterator mpb(find("mpb"));
  380. if (mpb == end())
  381. return ZT_DEFAULT_MULTICAST_PREFIX_BITS;
  382. unsigned int tmp = Utils::hexStrToUInt(mpb->second.c_str());
  383. if (tmp)
  384. return tmp;
  385. else return ZT_DEFAULT_MULTICAST_PREFIX_BITS;
  386. }
  387. /**
  388. * @return Maximum multicast propagation depth for this network
  389. */
  390. inline unsigned int multicastDepth() const
  391. {
  392. const_iterator md(find("md"));
  393. if (md == end())
  394. return ZT_DEFAULT_MULTICAST_DEPTH;
  395. unsigned int tmp = Utils::hexStrToUInt(md->second.c_str());
  396. if (tmp)
  397. return tmp;
  398. else return ZT_DEFAULT_MULTICAST_DEPTH;
  399. }
  400. /**
  401. * @return True if this is an open non-access-controlled network
  402. */
  403. inline bool isOpen() const
  404. {
  405. const_iterator o(find("o"));
  406. if (o == end())
  407. return false;
  408. else if (!o->second.length())
  409. return false;
  410. else return (o->second[0] == '1');
  411. }
  412. /**
  413. * @return Network ethertype whitelist
  414. */
  415. inline std::set<unsigned int> etherTypes() const
  416. {
  417. char tmp[16384];
  418. char *saveptr = (char *)0;
  419. std::set<unsigned int> et;
  420. if (!Utils::scopy(tmp,sizeof(tmp),get("et","").c_str()))
  421. return et; // sanity check, packet can't really be that big
  422. for(char *f=Utils::stok(tmp,",",&saveptr);(f);f=Utils::stok((char *)0,",",&saveptr)) {
  423. unsigned int t = Utils::hexStrToUInt(f);
  424. if (t)
  425. et.insert(t);
  426. }
  427. return et;
  428. }
  429. /**
  430. * @return All static addresses / netmasks, IPv4 or IPv6
  431. */
  432. inline std::set<InetAddress> staticAddresses() const
  433. {
  434. std::set<InetAddress> sa;
  435. std::vector<std::string> ips(Utils::split(get("v4s","").c_str(),",","",""));
  436. for(std::vector<std::string>::const_iterator i(ips.begin());i!=ips.end();++i)
  437. sa.insert(InetAddress(*i));
  438. ips = Utils::split(get("v6s","").c_str(),",","","");
  439. for(std::vector<std::string>::const_iterator i(ips.begin());i!=ips.end();++i)
  440. sa.insert(InetAddress(*i));
  441. return sa;
  442. }
  443. };
  444. /**
  445. * Status for networks
  446. */
  447. enum Status
  448. {
  449. NETWORK_WAITING_FOR_FIRST_AUTOCONF,
  450. NETWORK_OK,
  451. NETWORK_ACCESS_DENIED
  452. };
  453. /**
  454. * @param s Status
  455. * @return String description
  456. */
  457. static const char *statusString(const Status s)
  458. throw();
  459. private:
  460. // Only NodeConfig can create, only SharedPtr can delete
  461. // Actual construction happens in newInstance()
  462. Network()
  463. throw() :
  464. _tap((EthernetTap *)0)
  465. {
  466. }
  467. ~Network();
  468. /**
  469. * Create a new Network instance and restore any saved state
  470. *
  471. * If there is no saved state, a dummy .conf is created on disk to remember
  472. * this network across restarts.
  473. *
  474. * @param renv Runtime environment
  475. * @param id Network ID
  476. * @return Reference counted pointer to new network
  477. * @throws std::runtime_error Unable to create tap device or other fatal error
  478. */
  479. static SharedPtr<Network> newInstance(const RuntimeEnvironment *renv,uint64_t id)
  480. throw(std::runtime_error);
  481. /**
  482. * Causes all persistent disk presence to be erased on delete
  483. */
  484. inline void destroyOnDelete()
  485. throw()
  486. {
  487. _destroyOnDelete = true;
  488. }
  489. public:
  490. /**
  491. * @return Network ID
  492. */
  493. inline uint64_t id() const throw() { return _id; }
  494. /**
  495. * @return Ethernet tap
  496. */
  497. inline EthernetTap &tap() throw() { return *_tap; }
  498. /**
  499. * @return Address of network's controlling node
  500. */
  501. inline Address controller() throw() { return Address(_id >> 24); }
  502. /**
  503. * @return Network ID in hexadecimal form
  504. */
  505. inline std::string idString()
  506. {
  507. char buf[64];
  508. Utils::snprintf(buf,sizeof(buf),"%.16llx",(unsigned long long)_id);
  509. return std::string(buf);
  510. }
  511. /**
  512. * @return True if network is open (no membership required)
  513. */
  514. inline bool isOpen() const
  515. throw()
  516. {
  517. Mutex::Lock _l(_lock);
  518. return _isOpen;
  519. }
  520. /**
  521. * Update multicast groups for this network's tap
  522. *
  523. * @return True if internal multicast group set has changed
  524. */
  525. inline bool updateMulticastGroups()
  526. {
  527. Mutex::Lock _l(_lock);
  528. return _tap->updateMulticastGroups(_multicastGroups);
  529. }
  530. /**
  531. * @return Latest set of multicast groups for this network's tap
  532. */
  533. inline std::set<MulticastGroup> multicastGroups() const
  534. {
  535. Mutex::Lock _l(_lock);
  536. return _multicastGroups;
  537. }
  538. /**
  539. * Set or update this network's configuration
  540. *
  541. * This is called by PacketDecoder when an update comes over the wire, or
  542. * internally when an old config is reloaded from disk.
  543. *
  544. * @param conf Configuration in key/value dictionary form
  545. */
  546. void setConfiguration(const Config &conf);
  547. /**
  548. * Causes this network to request an updated configuration from its master node now
  549. */
  550. void requestConfiguration();
  551. /**
  552. * Add or update a peer's membership certificate
  553. *
  554. * The certificate must already have been validated via signature checking.
  555. *
  556. * @param peer Peer that owns certificate
  557. * @param cert Certificate itself
  558. */
  559. void addMembershipCertificate(const Address &peer,const CertificateOfMembership &cert);
  560. /**
  561. * @param peer Peer address to check
  562. * @return True if peer is allowed to communicate on this network
  563. */
  564. bool isAllowed(const Address &peer) const;
  565. /**
  566. * Perform cleanup and possibly save state
  567. */
  568. void clean();
  569. /**
  570. * @return Time of last updated configuration or 0 if none
  571. */
  572. inline uint64_t lastConfigUpdate() const
  573. throw()
  574. {
  575. return _lastConfigUpdate;
  576. }
  577. /**
  578. * @return Status of this network
  579. */
  580. Status status() const;
  581. /**
  582. * Determine whether frames of a given ethernet type are allowed on this network
  583. *
  584. * @param etherType Ethernet frame type
  585. * @return True if network permits this type
  586. */
  587. inline bool permitsEtherType(unsigned int etherType) const
  588. throw()
  589. {
  590. if (!etherType)
  591. return false;
  592. else if (etherType > 65535)
  593. return false;
  594. else if ((_etWhitelist[0] & 1)) // if type 0 is in the whitelist, sense is inverted from whitelist to blacklist
  595. return ((_etWhitelist[etherType / 8] & (unsigned char)(1 << (etherType & 7))) == 0);
  596. else return ((_etWhitelist[etherType / 8] & (unsigned char)(1 << (etherType & 7))) != 0);
  597. }
  598. /**
  599. * Update multicast balance for an address and multicast group, return whether packet is allowed
  600. *
  601. * @param a Address that wants to send/relay packet
  602. * @param mg Multicast group
  603. * @param bytes Size of packet
  604. * @return True if packet is within budget
  605. */
  606. inline bool updateAndCheckMulticastBalance(const Address &a,const MulticastGroup &mg,unsigned int bytes)
  607. {
  608. Mutex::Lock _l(_lock);
  609. std::pair<Address,MulticastGroup> k(a,mg);
  610. std::map< std::pair<Address,MulticastGroup>,BandwidthAccount >::iterator bal(_multicastRateAccounts.find(k));
  611. if (bal == _multicastRateAccounts.end()) {
  612. MulticastRates::Rate r(_mcRates.get(mg));
  613. bal = _multicastRateAccounts.insert(std::pair< std::pair<Address,MulticastGroup>,BandwidthAccount >(k,BandwidthAccount(r.preload,r.maxBalance,r.accrual))).first;
  614. }
  615. return bal->second.deduct(bytes);
  616. //bool tmp = bal->second.deduct(bytes);
  617. //printf("%s: BAL: %u\n",mg.toString().c_str(),(unsigned int)bal->second.balance());
  618. //return tmp;
  619. }
  620. /**
  621. * @return True if this network allows bridging
  622. */
  623. inline bool permitsBridging() const
  624. throw()
  625. {
  626. return false; // TODO: bridging not implemented yet
  627. }
  628. /**
  629. * @return Bits in multicast restriciton prefix
  630. */
  631. inline unsigned int multicastPrefixBits() const
  632. throw()
  633. {
  634. return _multicastPrefixBits;
  635. }
  636. /**
  637. * @return Max depth (TTL) for a multicast frame
  638. */
  639. inline unsigned int multicastDepth() const
  640. throw()
  641. {
  642. return _multicastDepth;
  643. }
  644. private:
  645. static void _CBhandleTapData(void *arg,const MAC &from,const MAC &to,unsigned int etherType,const Buffer<4096> &data);
  646. void _restoreState();
  647. const RuntimeEnvironment *_r;
  648. // Multicast bandwidth accounting for peers on this network
  649. std::map< std::pair<Address,MulticastGroup>,BandwidthAccount > _multicastRateAccounts;
  650. // Tap and tap multicast memberships for this node on this network
  651. EthernetTap *_tap;
  652. std::set<MulticastGroup> _multicastGroups;
  653. // Membership certificates supplied by other peers on this network
  654. std::map<Address,CertificateOfMembership> _membershipCertificates;
  655. // Configuration from network master node
  656. Config _configuration;
  657. CertificateOfMembership _myCertificate; // memoized from _configuration
  658. MulticastRates _mcRates; // memoized from _configuration
  659. std::set<InetAddress> _staticAddresses; // memoized from _configuration
  660. bool _isOpen; // memoized from _configuration
  661. unsigned int _multicastPrefixBits; // memoized from _configuration
  662. unsigned int _multicastDepth; // memoized from _configuration
  663. // Ethertype whitelist bit field, set from config, for really fast lookup
  664. unsigned char _etWhitelist[65536 / 8];
  665. uint64_t _id;
  666. volatile uint64_t _lastConfigUpdate;
  667. volatile bool _destroyOnDelete;
  668. volatile bool _ready;
  669. Mutex _lock;
  670. AtomicCounter __refCount;
  671. };
  672. } // naemspace ZeroTier
  673. #endif