Peer.hpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  1. /*
  2. * ZeroTier One - Network Virtualization Everywhere
  3. * Copyright (C) 2011-2016 ZeroTier, Inc. https://www.zerotier.com/
  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. #ifndef ZT_PEER_HPP
  19. #define ZT_PEER_HPP
  20. #include <stdint.h>
  21. #include "Constants.hpp"
  22. #include <algorithm>
  23. #include <utility>
  24. #include <vector>
  25. #include <stdexcept>
  26. #include "../include/ZeroTierOne.h"
  27. #include "RuntimeEnvironment.hpp"
  28. #include "CertificateOfMembership.hpp"
  29. #include "Path.hpp"
  30. #include "Address.hpp"
  31. #include "Utils.hpp"
  32. #include "Identity.hpp"
  33. #include "InetAddress.hpp"
  34. #include "Packet.hpp"
  35. #include "SharedPtr.hpp"
  36. #include "AtomicCounter.hpp"
  37. #include "Hashtable.hpp"
  38. #include "Mutex.hpp"
  39. #include "NonCopyable.hpp"
  40. // Very rough computed estimate: (8 + 256 + 80 + (16 * 64) + (128 * 256) + (128 * 16))
  41. // 1048576 provides tons of headroom -- overflow would just cause peer not to be persisted
  42. #define ZT_PEER_SUGGESTED_SERIALIZATION_BUFFER_SIZE 1048576
  43. namespace ZeroTier {
  44. /**
  45. * Peer on P2P Network (virtual layer 1)
  46. */
  47. class Peer : NonCopyable
  48. {
  49. friend class SharedPtr<Peer>;
  50. private:
  51. Peer() {} // disabled to prevent bugs -- should not be constructed uninitialized
  52. public:
  53. ~Peer() { Utils::burn(_key,sizeof(_key)); }
  54. /**
  55. * Construct a new peer
  56. *
  57. * @param renv Runtime environment
  58. * @param myIdentity Identity of THIS node (for key agreement)
  59. * @param peerIdentity Identity of peer
  60. * @throws std::runtime_error Key agreement with peer's identity failed
  61. */
  62. Peer(const RuntimeEnvironment *renv,const Identity &myIdentity,const Identity &peerIdentity);
  63. /**
  64. * @return Time peer record was last used in any way
  65. */
  66. inline uint64_t lastUsed() const throw() { return _lastUsed; }
  67. /**
  68. * Log a use of this peer record (done by Topology when peers are looked up)
  69. *
  70. * @param now New time of last use
  71. */
  72. inline void use(uint64_t now) throw() { _lastUsed = now; }
  73. /**
  74. * @return This peer's ZT address (short for identity().address())
  75. */
  76. inline const Address &address() const throw() { return _id.address(); }
  77. /**
  78. * @return This peer's identity
  79. */
  80. inline const Identity &identity() const throw() { return _id; }
  81. /**
  82. * Log receipt of an authenticated packet
  83. *
  84. * This is called by the decode pipe when a packet is proven to be authentic
  85. * and appears to be valid.
  86. *
  87. * @param RR Runtime environment
  88. * @param localAddr Local address
  89. * @param remoteAddr Internet address of sender
  90. * @param hops ZeroTier (not IP) hops
  91. * @param packetId Packet ID
  92. * @param verb Packet verb
  93. * @param inRePacketId Packet ID in reply to (default: none)
  94. * @param inReVerb Verb in reply to (for OK/ERROR, default: VERB_NOP)
  95. */
  96. void received(
  97. const InetAddress &localAddr,
  98. const InetAddress &remoteAddr,
  99. unsigned int hops,
  100. uint64_t packetId,
  101. Packet::Verb verb,
  102. uint64_t inRePacketId = 0,
  103. Packet::Verb inReVerb = Packet::VERB_NOP);
  104. /**
  105. * Get the current best direct path to this peer
  106. *
  107. * @param now Current time
  108. * @return Best path or NULL if there are no active direct paths
  109. */
  110. inline Path *getBestPath(uint64_t now) { return _getBestPath(now); }
  111. /**
  112. * @param now Current time
  113. * @param addr Remote address
  114. * @return True if we have an active path to this destination
  115. */
  116. inline bool hasActivePathTo(uint64_t now,const InetAddress &addr) const
  117. {
  118. for(unsigned int p=0;p<_numPaths;++p) {
  119. if ((_paths[p].active(now))&&(_paths[p].address() == addr))
  120. return true;
  121. }
  122. return false;
  123. }
  124. /**
  125. * Set all paths in the same ss_family that are not this one to cluster suboptimal
  126. *
  127. * Addresses in other families are not affected.
  128. *
  129. * @param addr Address to make exclusive
  130. */
  131. inline void setClusterOptimalPathForAddressFamily(const InetAddress &addr)
  132. {
  133. for(unsigned int p=0;p<_numPaths;++p) {
  134. if (_paths[p].address().ss_family == addr.ss_family) {
  135. _paths[p].setClusterSuboptimal(_paths[p].address() != addr);
  136. }
  137. }
  138. }
  139. /**
  140. * Send via best path
  141. *
  142. * @param data Packet data
  143. * @param len Packet length
  144. * @param now Current time
  145. * @return Path used on success or NULL on failure
  146. */
  147. inline Path *send(const void *data,unsigned int len,uint64_t now)
  148. {
  149. Path *const bestPath = getBestPath(now);
  150. if (bestPath) {
  151. if (bestPath->send(RR,data,len,now))
  152. return bestPath;
  153. }
  154. return (Path *)0;
  155. }
  156. /**
  157. * Send a HELLO to this peer at a specified physical address
  158. *
  159. * This does not update any statistics. It's used to send initial HELLOs
  160. * for NAT traversal and path verification.
  161. *
  162. * @param localAddr Local address
  163. * @param atAddress Destination address
  164. * @param now Current time
  165. * @param ttl Desired IP TTL (default: 0 to leave alone)
  166. */
  167. void sendHELLO(const InetAddress &localAddr,const InetAddress &atAddress,uint64_t now,unsigned int ttl = 0);
  168. /**
  169. * Send pings or keepalives depending on configured timeouts
  170. *
  171. * @param now Current time
  172. * @param inetAddressFamily Keep this address family alive, or 0 to simply pick current best ignoring family
  173. * @return True if at least one direct path seems alive
  174. */
  175. bool doPingAndKeepalive(uint64_t now,int inetAddressFamily);
  176. /**
  177. * Push direct paths back to self if we haven't done so in the configured timeout
  178. *
  179. * @param localAddr Local address
  180. * @param toAddress Remote address to send push to (usually from path)
  181. * @param now Current time
  182. * @param force If true, push regardless of rate limit
  183. * @param includePrivatePaths If true, include local interface address paths (should only be done to peers with a trust relationship)
  184. * @return True if something was actually sent
  185. */
  186. bool pushDirectPaths(const InetAddress &localAddr,const InetAddress &toAddress,uint64_t now,bool force,bool includePrivatePaths);
  187. /**
  188. * @return All known direct paths to this peer (active or inactive)
  189. */
  190. inline std::vector<Path> paths() const
  191. {
  192. std::vector<Path> pp;
  193. for(unsigned int p=0,np=_numPaths;p<np;++p)
  194. pp.push_back(_paths[p]);
  195. return pp;
  196. }
  197. /**
  198. * @return Time of last receive of anything, whether direct or relayed
  199. */
  200. inline uint64_t lastReceive() const throw() { return _lastReceive; }
  201. /**
  202. * @return Time of most recent unicast frame received
  203. */
  204. inline uint64_t lastUnicastFrame() const throw() { return _lastUnicastFrame; }
  205. /**
  206. * @return Time of most recent multicast frame received
  207. */
  208. inline uint64_t lastMulticastFrame() const throw() { return _lastMulticastFrame; }
  209. /**
  210. * @return Time of most recent frame of any kind (unicast or multicast)
  211. */
  212. inline uint64_t lastFrame() const throw() { return std::max(_lastUnicastFrame,_lastMulticastFrame); }
  213. /**
  214. * @return True if this peer has sent us real network traffic recently
  215. */
  216. inline uint64_t activelyTransferringFrames(uint64_t now) const throw() { return ((now - lastFrame()) < ZT_PEER_ACTIVITY_TIMEOUT); }
  217. /**
  218. * @return Latency in milliseconds or 0 if unknown
  219. */
  220. inline unsigned int latency() const { return _latency; }
  221. /**
  222. * This computes a quality score for relays and root servers
  223. *
  224. * If we haven't heard anything from these in ZT_PEER_ACTIVITY_TIMEOUT, they
  225. * receive the worst possible quality (max unsigned int). Otherwise the
  226. * quality is a product of latency and the number of potential missed
  227. * pings. This causes roots and relays to switch over a bit faster if they
  228. * fail.
  229. *
  230. * @return Relay quality score computed from latency and other factors, lower is better
  231. */
  232. inline unsigned int relayQuality(const uint64_t now) const
  233. {
  234. const uint64_t tsr = now - _lastReceive;
  235. if (tsr >= ZT_PEER_ACTIVITY_TIMEOUT)
  236. return (~(unsigned int)0);
  237. unsigned int l = _latency;
  238. if (!l)
  239. l = 0xffff;
  240. return (l * (((unsigned int)tsr / (ZT_PEER_DIRECT_PING_DELAY + 1000)) + 1));
  241. }
  242. /**
  243. * Update latency with a new direct measurment
  244. *
  245. * @param l Direct latency measurment in ms
  246. */
  247. inline void addDirectLatencyMeasurment(unsigned int l)
  248. {
  249. unsigned int ol = _latency;
  250. if ((ol > 0)&&(ol < 10000))
  251. _latency = (ol + std::min(l,(unsigned int)65535)) / 2;
  252. else _latency = std::min(l,(unsigned int)65535);
  253. }
  254. /**
  255. * @param now Current time
  256. * @return True if this peer has at least one active direct path
  257. */
  258. inline bool hasActiveDirectPath(uint64_t now) const
  259. {
  260. for(unsigned int p=0;p<_numPaths;++p) {
  261. if (_paths[p].active(now))
  262. return true;
  263. }
  264. return false;
  265. }
  266. #ifdef ZT_ENABLE_CLUSTER
  267. /**
  268. * @param now Current time
  269. * @return True if this peer has at least one active direct path that is not cluster-suboptimal
  270. */
  271. inline bool hasClusterOptimalPath(uint64_t now) const
  272. {
  273. for(unsigned int p=0,np=_numPaths;p<np;++p) {
  274. if ((_paths[p].active(now))&&(!_paths[p].isClusterSuboptimal()))
  275. return true;
  276. }
  277. return false;
  278. }
  279. #endif
  280. /**
  281. * Reset paths within a given scope
  282. *
  283. * @param scope IP scope of paths to reset
  284. * @param now Current time
  285. * @return True if at least one path was forgotten
  286. */
  287. bool resetWithinScope(InetAddress::IpScope scope,uint64_t now);
  288. /**
  289. * @return 256-bit secret symmetric encryption key
  290. */
  291. inline const unsigned char *key() const throw() { return _key; }
  292. /**
  293. * Set the currently known remote version of this peer's client
  294. *
  295. * @param vproto Protocol version
  296. * @param vmaj Major version
  297. * @param vmin Minor version
  298. * @param vrev Revision
  299. */
  300. inline void setRemoteVersion(unsigned int vproto,unsigned int vmaj,unsigned int vmin,unsigned int vrev)
  301. {
  302. _vProto = (uint16_t)vproto;
  303. _vMajor = (uint16_t)vmaj;
  304. _vMinor = (uint16_t)vmin;
  305. _vRevision = (uint16_t)vrev;
  306. }
  307. inline unsigned int remoteVersionProtocol() const throw() { return _vProto; }
  308. inline unsigned int remoteVersionMajor() const throw() { return _vMajor; }
  309. inline unsigned int remoteVersionMinor() const throw() { return _vMinor; }
  310. inline unsigned int remoteVersionRevision() const throw() { return _vRevision; }
  311. inline bool remoteVersionKnown() const throw() { return ((_vMajor > 0)||(_vMinor > 0)||(_vRevision > 0)); }
  312. /**
  313. * Get most recently active path addresses for IPv4 and/or IPv6
  314. *
  315. * Note that v4 and v6 are not modified if they are not found, so
  316. * initialize these to a NULL address to be able to check.
  317. *
  318. * @param now Current time
  319. * @param v4 Result parameter to receive active IPv4 address, if any
  320. * @param v6 Result parameter to receive active IPv6 address, if any
  321. */
  322. void getBestActiveAddresses(uint64_t now,InetAddress &v4,InetAddress &v6) const;
  323. /**
  324. * Check network COM agreement with this peer
  325. *
  326. * @param nwid Network ID
  327. * @param com Another certificate of membership
  328. * @return True if supplied COM agrees with ours, false if not or if we don't have one
  329. */
  330. bool networkMembershipCertificatesAgree(uint64_t nwid,const CertificateOfMembership &com) const;
  331. /**
  332. * Check the validity of the COM and add/update if valid and new
  333. *
  334. * @param nwid Network ID
  335. * @param com Externally supplied COM
  336. */
  337. bool validateAndSetNetworkMembershipCertificate(uint64_t nwid,const CertificateOfMembership &com);
  338. /**
  339. * @param nwid Network ID
  340. * @param now Current time
  341. * @param updateLastPushedTime If true, go ahead and update the last pushed time regardless of return value
  342. * @return Whether or not this peer needs another COM push from us
  343. */
  344. bool needsOurNetworkMembershipCertificate(uint64_t nwid,uint64_t now,bool updateLastPushedTime);
  345. /**
  346. * Perform periodic cleaning operations
  347. *
  348. * @param now Current time
  349. */
  350. void clean(uint64_t now);
  351. /**
  352. * Update direct path push stats and return true if we should respond
  353. *
  354. * This is a circuit breaker to make VERB_PUSH_DIRECT_PATHS not particularly
  355. * useful as a DDOS amplification attack vector. Otherwise a malicious peer
  356. * could send loads of these and cause others to bombard arbitrary IPs with
  357. * traffic.
  358. *
  359. * @param now Current time
  360. * @return True if we should respond
  361. */
  362. inline bool shouldRespondToDirectPathPush(const uint64_t now)
  363. {
  364. if ((now - _lastDirectPathPushReceive) <= ZT_PUSH_DIRECT_PATHS_CUTOFF_TIME)
  365. ++_directPathPushCutoffCount;
  366. else _directPathPushCutoffCount = 0;
  367. _lastDirectPathPushReceive = now;
  368. return (_directPathPushCutoffCount < ZT_PUSH_DIRECT_PATHS_CUTOFF_LIMIT);
  369. }
  370. /**
  371. * Find a common set of addresses by which two peers can link, if any
  372. *
  373. * @param a Peer A
  374. * @param b Peer B
  375. * @param now Current time
  376. * @return Pair: B's address (to send to A), A's address (to send to B)
  377. */
  378. static inline std::pair<InetAddress,InetAddress> findCommonGround(const Peer &a,const Peer &b,uint64_t now)
  379. {
  380. std::pair<InetAddress,InetAddress> v4,v6;
  381. b.getBestActiveAddresses(now,v4.first,v6.first);
  382. a.getBestActiveAddresses(now,v4.second,v6.second);
  383. if ((v6.first)&&(v6.second)) // prefer IPv6 if both have it since NAT-t is (almost) unnecessary
  384. return v6;
  385. else if ((v4.first)&&(v4.second))
  386. return v4;
  387. else return std::pair<InetAddress,InetAddress>();
  388. }
  389. template<unsigned int C>
  390. inline void serialize(Buffer<C> &b) const
  391. {
  392. Mutex::Lock _l(_networkComs_m);
  393. const unsigned int recSizePos = b.size();
  394. b.addSize(4); // space for uint32_t field length
  395. b.append((uint16_t)1); // version of serialized Peer data
  396. _id.serialize(b,false);
  397. b.append((uint64_t)_lastUsed);
  398. b.append((uint64_t)_lastReceive);
  399. b.append((uint64_t)_lastUnicastFrame);
  400. b.append((uint64_t)_lastMulticastFrame);
  401. b.append((uint64_t)_lastAnnouncedTo);
  402. b.append((uint64_t)_lastDirectPathPushSent);
  403. b.append((uint64_t)_lastDirectPathPushReceive);
  404. b.append((uint64_t)_lastPathSort);
  405. b.append((uint16_t)_vProto);
  406. b.append((uint16_t)_vMajor);
  407. b.append((uint16_t)_vMinor);
  408. b.append((uint16_t)_vRevision);
  409. b.append((uint32_t)_latency);
  410. b.append((uint16_t)_directPathPushCutoffCount);
  411. b.append((uint16_t)_numPaths);
  412. for(unsigned int i=0;i<_numPaths;++i)
  413. _paths[i].serialize(b);
  414. b.append((uint32_t)_networkComs.size());
  415. {
  416. uint64_t *k = (uint64_t *)0;
  417. _NetworkCom *v = (_NetworkCom *)0;
  418. Hashtable<uint64_t,_NetworkCom>::Iterator i(const_cast<Peer *>(this)->_networkComs);
  419. while (i.next(k,v)) {
  420. b.append((uint64_t)*k);
  421. b.append((uint64_t)v->ts);
  422. v->com.serialize(b);
  423. }
  424. }
  425. b.append((uint32_t)_lastPushedComs.size());
  426. {
  427. uint64_t *k = (uint64_t *)0;
  428. uint64_t *v = (uint64_t *)0;
  429. Hashtable<uint64_t,uint64_t>::Iterator i(const_cast<Peer *>(this)->_lastPushedComs);
  430. while (i.next(k,v)) {
  431. b.append((uint64_t)*k);
  432. b.append((uint64_t)*v);
  433. }
  434. }
  435. b.template setAt<uint32_t>(recSizePos,(uint32_t)(b.size() - (recSizePos + 4))); // set size
  436. }
  437. /**
  438. * Create a new Peer from a serialized instance
  439. *
  440. * @param renv Runtime environment
  441. * @param myIdentity This node's identity
  442. * @param b Buffer containing serialized Peer data
  443. * @param p Pointer to current position in buffer, will be updated in place as buffer is read (value/result)
  444. * @return New instance of Peer or NULL if serialized data was corrupt or otherwise invalid (may also throw an exception via Buffer)
  445. */
  446. template<unsigned int C>
  447. static inline SharedPtr<Peer> deserializeNew(const RuntimeEnvironment *renv,const Identity &myIdentity,const Buffer<C> &b,unsigned int &p)
  448. {
  449. const unsigned int recSize = b.template at<uint32_t>(p); p += 4;
  450. if ((p + recSize) > b.size())
  451. return SharedPtr<Peer>(); // size invalid
  452. if (b.template at<uint16_t>(p) != 1)
  453. return SharedPtr<Peer>(); // version mismatch
  454. p += 2;
  455. Identity npid;
  456. p += npid.deserialize(b,p);
  457. if (!npid)
  458. return SharedPtr<Peer>();
  459. SharedPtr<Peer> np(new Peer(renv,myIdentity,npid));
  460. np->_lastUsed = b.template at<uint64_t>(p); p += 8;
  461. np->_lastReceive = b.template at<uint64_t>(p); p += 8;
  462. np->_lastUnicastFrame = b.template at<uint64_t>(p); p += 8;
  463. np->_lastMulticastFrame = b.template at<uint64_t>(p); p += 8;
  464. np->_lastAnnouncedTo = b.template at<uint64_t>(p); p += 8;
  465. np->_lastDirectPathPushSent = b.template at<uint64_t>(p); p += 8;
  466. np->_lastDirectPathPushReceive = b.template at<uint64_t>(p); p += 8;
  467. np->_lastPathSort = b.template at<uint64_t>(p); p += 8;
  468. np->_vProto = b.template at<uint16_t>(p); p += 2;
  469. np->_vMajor = b.template at<uint16_t>(p); p += 2;
  470. np->_vMinor = b.template at<uint16_t>(p); p += 2;
  471. np->_vRevision = b.template at<uint16_t>(p); p += 2;
  472. np->_latency = b.template at<uint32_t>(p); p += 4;
  473. np->_directPathPushCutoffCount = b.template at<uint16_t>(p); p += 2;
  474. const unsigned int numPaths = b.template at<uint16_t>(p); p += 2;
  475. for(unsigned int i=0;i<numPaths;++i) {
  476. if (i < ZT_MAX_PEER_NETWORK_PATHS) {
  477. p += np->_paths[np->_numPaths++].deserialize(b,p);
  478. } else {
  479. // Skip any paths beyond max, but still read stream
  480. Path foo;
  481. p += foo.deserialize(b,p);
  482. }
  483. }
  484. const unsigned int numNetworkComs = b.template at<uint32_t>(p); p += 4;
  485. for(unsigned int i=0;i<numNetworkComs;++i) {
  486. _NetworkCom &c = np->_networkComs[b.template at<uint64_t>(p)]; p += 8;
  487. c.ts = b.template at<uint64_t>(p); p += 8;
  488. p += c.com.deserialize(b,p);
  489. }
  490. const unsigned int numLastPushed = b.template at<uint32_t>(p); p += 4;
  491. for(unsigned int i=0;i<numLastPushed;++i) {
  492. const uint64_t nwid = b.template at<uint64_t>(p); p += 8;
  493. const uint64_t ts = b.template at<uint64_t>(p); p += 8;
  494. np->_lastPushedComs.set(nwid,ts);
  495. }
  496. return np;
  497. }
  498. private:
  499. void _doDeadPathDetection(Path &p,const uint64_t now);
  500. Path *_getBestPath(const uint64_t now);
  501. Path *_getBestPath(const uint64_t now,int inetAddressFamily);
  502. unsigned char _key[ZT_PEER_SECRET_KEY_LENGTH]; // computed with key agreement, not serialized
  503. const RuntimeEnvironment *RR;
  504. uint64_t _lastUsed;
  505. uint64_t _lastReceive; // direct or indirect
  506. uint64_t _lastUnicastFrame;
  507. uint64_t _lastMulticastFrame;
  508. uint64_t _lastAnnouncedTo;
  509. uint64_t _lastDirectPathPushSent;
  510. uint64_t _lastDirectPathPushReceive;
  511. uint64_t _lastPathSort;
  512. uint16_t _vProto;
  513. uint16_t _vMajor;
  514. uint16_t _vMinor;
  515. uint16_t _vRevision;
  516. Identity _id;
  517. Path _paths[ZT_MAX_PEER_NETWORK_PATHS];
  518. unsigned int _numPaths;
  519. unsigned int _latency;
  520. unsigned int _directPathPushCutoffCount;
  521. struct _NetworkCom
  522. {
  523. _NetworkCom() {}
  524. _NetworkCom(uint64_t t,const CertificateOfMembership &c) : ts(t),com(c) {}
  525. uint64_t ts;
  526. CertificateOfMembership com;
  527. };
  528. Hashtable<uint64_t,_NetworkCom> _networkComs;
  529. Hashtable<uint64_t,uint64_t> _lastPushedComs;
  530. Mutex _networkComs_m;
  531. AtomicCounter __refCount;
  532. };
  533. } // namespace ZeroTier
  534. // Add a swap() for shared ptr's to peers to speed up peer sorts
  535. namespace std {
  536. template<>
  537. inline void swap(ZeroTier::SharedPtr<ZeroTier::Peer> &a,ZeroTier::SharedPtr<ZeroTier::Peer> &b)
  538. {
  539. a.swap(b);
  540. }
  541. }
  542. #endif