Path.hpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  1. /*
  2. * Copyright (c)2013-2020 ZeroTier, Inc.
  3. *
  4. * Use of this software is governed by the Business Source License included
  5. * in the LICENSE.TXT file in the project's root directory.
  6. *
  7. * Change Date: 2025-01-01
  8. *
  9. * On the date above, in accordance with the Business Source License, use
  10. * of this software will be governed by version 2.0 of the Apache License.
  11. */
  12. /****/
  13. #ifndef ZT_PATH_HPP
  14. #define ZT_PATH_HPP
  15. #include <stdint.h>
  16. #include <string.h>
  17. #include <stdlib.h>
  18. #include <stdexcept>
  19. #include <algorithm>
  20. #include "Constants.hpp"
  21. #include "InetAddress.hpp"
  22. #include "SharedPtr.hpp"
  23. #include "AtomicCounter.hpp"
  24. #include "Utils.hpp"
  25. #include "Packet.hpp"
  26. #include "RingBuffer.hpp"
  27. #include "../osdep/Link.hpp"
  28. /**
  29. * Maximum return value of preferenceRank()
  30. */
  31. #define ZT_PATH_MAX_PREFERENCE_RANK ((ZT_INETADDRESS_MAX_SCOPE << 1) | 1)
  32. namespace ZeroTier {
  33. class RuntimeEnvironment;
  34. /**
  35. * A path across the physical network
  36. */
  37. class Path
  38. {
  39. friend class SharedPtr<Path>;
  40. friend class Bond;
  41. public:
  42. /**
  43. * Efficient unique key for paths in a Hashtable
  44. */
  45. class HashKey
  46. {
  47. public:
  48. HashKey() {}
  49. HashKey(const int64_t l,const InetAddress &r)
  50. {
  51. if (r.ss_family == AF_INET) {
  52. _k[0] = (uint64_t)reinterpret_cast<const struct sockaddr_in *>(&r)->sin_addr.s_addr;
  53. _k[1] = (uint64_t)reinterpret_cast<const struct sockaddr_in *>(&r)->sin_port;
  54. _k[2] = (uint64_t)l;
  55. } else if (r.ss_family == AF_INET6) {
  56. memcpy(_k,reinterpret_cast<const struct sockaddr_in6 *>(&r)->sin6_addr.s6_addr,16);
  57. _k[2] = ((uint64_t)reinterpret_cast<const struct sockaddr_in6 *>(&r)->sin6_port << 32) ^ (uint64_t)l;
  58. } else {
  59. memcpy(_k,&r,std::min(sizeof(_k),sizeof(InetAddress)));
  60. _k[2] += (uint64_t)l;
  61. }
  62. }
  63. inline unsigned long hashCode() const { return (unsigned long)(_k[0] + _k[1] + _k[2]); }
  64. inline bool operator==(const HashKey &k) const { return ( (_k[0] == k._k[0]) && (_k[1] == k._k[1]) && (_k[2] == k._k[2]) ); }
  65. inline bool operator!=(const HashKey &k) const { return (!(*this == k)); }
  66. private:
  67. uint64_t _k[3];
  68. };
  69. Path() :
  70. _lastOut(0),
  71. _lastIn(0),
  72. _lastTrustEstablishedPacketReceived(0),
  73. _localSocket(-1),
  74. _latency(0xffff),
  75. _addr(),
  76. _ipScope(InetAddress::IP_SCOPE_NONE),
  77. _lastAckReceived(0),
  78. _lastAckSent(0),
  79. _lastQoSMeasurement(0),
  80. _lastThroughputEstimation(0),
  81. _lastRefractoryUpdate(0),
  82. _lastAliveToggle(0),
  83. _lastEligibilityState(false),
  84. _lastTrialBegin(0),
  85. _refractoryPeriod(0),
  86. _monitorInterval(0),
  87. _upDelay(0),
  88. _downDelay(0),
  89. _ipvPref(0),
  90. _mode(0),
  91. _onlyPathOnLink(false),
  92. _enabled(false),
  93. _bonded(false),
  94. _negotiated(false),
  95. _deprecated(false),
  96. _shouldReallocateFlows(false),
  97. _assignedFlowCount(0),
  98. _latencyMean(0),
  99. _latencyVariance(0),
  100. _packetLossRatio(0),
  101. _packetErrorRatio(0),
  102. _throughputMean(0),
  103. _throughputMax(0),
  104. _throughputVariance(0),
  105. _allocation(0),
  106. _byteLoad(0),
  107. _relativeByteLoad(0),
  108. _affinity(0),
  109. _failoverScore(0),
  110. _unackedBytes(0),
  111. _packetsReceivedSinceLastAck(0),
  112. _packetsReceivedSinceLastQoS(0),
  113. _bytesAckedSinceLastThroughputEstimation(0),
  114. _packetsIn(0),
  115. _packetsOut(0)
  116. {}
  117. Path(const int64_t localSocket,const InetAddress &addr) :
  118. _lastOut(0),
  119. _lastIn(0),
  120. _lastTrustEstablishedPacketReceived(0),
  121. _localSocket(localSocket),
  122. _latency(0xffff),
  123. _addr(addr),
  124. _ipScope(addr.ipScope()),
  125. _lastAckReceived(0),
  126. _lastAckSent(0),
  127. _lastQoSMeasurement(0),
  128. _lastThroughputEstimation(0),
  129. _lastRefractoryUpdate(0),
  130. _lastAliveToggle(0),
  131. _lastEligibilityState(false),
  132. _lastTrialBegin(0),
  133. _refractoryPeriod(0),
  134. _monitorInterval(0),
  135. _upDelay(0),
  136. _downDelay(0),
  137. _ipvPref(0),
  138. _mode(0),
  139. _onlyPathOnLink(false),
  140. _enabled(false),
  141. _bonded(false),
  142. _negotiated(false),
  143. _deprecated(false),
  144. _shouldReallocateFlows(false),
  145. _assignedFlowCount(0),
  146. _latencyMean(0),
  147. _latencyVariance(0),
  148. _packetLossRatio(0),
  149. _packetErrorRatio(0),
  150. _throughputMean(0),
  151. _throughputMax(0),
  152. _throughputVariance(0),
  153. _allocation(0),
  154. _byteLoad(0),
  155. _relativeByteLoad(0),
  156. _affinity(0),
  157. _failoverScore(0),
  158. _unackedBytes(0),
  159. _packetsReceivedSinceLastAck(0),
  160. _packetsReceivedSinceLastQoS(0),
  161. _bytesAckedSinceLastThroughputEstimation(0),
  162. _packetsIn(0),
  163. _packetsOut(0)
  164. {}
  165. /**
  166. * Called when a packet is received from this remote path, regardless of content
  167. *
  168. * @param t Time of receive
  169. */
  170. inline void received(const uint64_t t) {
  171. if (!alive(t,_bonded)) {
  172. _lastAliveToggle = _lastIn;
  173. }
  174. _lastIn = t;
  175. }
  176. /**
  177. * Set time last trusted packet was received (done in Peer::received())
  178. */
  179. inline void trustedPacketReceived(const uint64_t t) { _lastTrustEstablishedPacketReceived = t; }
  180. /**
  181. * Send a packet via this path (last out time is also updated)
  182. *
  183. * @param RR Runtime environment
  184. * @param tPtr Thread pointer to be handed through to any callbacks called as a result of this call
  185. * @param data Packet data
  186. * @param len Packet length
  187. * @param now Current time
  188. * @return True if transport reported success
  189. */
  190. bool send(const RuntimeEnvironment *RR,void *tPtr,const void *data,unsigned int len,int64_t now);
  191. /**
  192. * Manually update last sent time
  193. *
  194. * @param t Time of send
  195. */
  196. inline void sent(const int64_t t) { _lastOut = t; }
  197. /**
  198. * Update path latency with a new measurement
  199. *
  200. * @param l Measured latency
  201. */
  202. inline void updateLatency(const unsigned int l, int64_t now)
  203. {
  204. unsigned int pl = _latency;
  205. if (pl < 0xffff) {
  206. _latency = (pl + l) / 2;
  207. }
  208. else {
  209. _latency = l;
  210. }
  211. }
  212. /**
  213. * @return Local socket as specified by external code
  214. */
  215. inline int64_t localSocket() const { return _localSocket; }
  216. /**
  217. * @return Physical address
  218. */
  219. inline const InetAddress &address() const { return _addr; }
  220. /**
  221. * @return IP scope -- faster shortcut for address().ipScope()
  222. */
  223. inline InetAddress::IpScope ipScope() const { return _ipScope; }
  224. /**
  225. * @return True if path has received a trust established packet (e.g. common network membership) in the past ZT_TRUST_EXPIRATION ms
  226. */
  227. inline bool trustEstablished(const int64_t now) const { return ((now - _lastTrustEstablishedPacketReceived) < ZT_TRUST_EXPIRATION); }
  228. /**
  229. * @return Preference rank, higher == better
  230. */
  231. inline unsigned int preferenceRank() const
  232. {
  233. // This causes us to rank paths in order of IP scope rank (see InetAdddress.hpp) but
  234. // within each IP scope class to prefer IPv6 over IPv4.
  235. return ( ((unsigned int)_ipScope << 1) | (unsigned int)(_addr.ss_family == AF_INET6) );
  236. }
  237. /**
  238. * Check whether this address is valid for a ZeroTier path
  239. *
  240. * This checks the address type and scope against address types and scopes
  241. * that we currently support for ZeroTier communication.
  242. *
  243. * @param a Address to check
  244. * @return True if address is good for ZeroTier path use
  245. */
  246. static inline bool isAddressValidForPath(const InetAddress &a)
  247. {
  248. if ((a.ss_family == AF_INET)||(a.ss_family == AF_INET6)) {
  249. switch(a.ipScope()) {
  250. /* Note: we don't do link-local at the moment. Unfortunately these
  251. * cause several issues. The first is that they usually require a
  252. * device qualifier, which we don't handle yet and can't portably
  253. * push in PUSH_DIRECT_PATHS. The second is that some OSes assign
  254. * these very ephemerally or otherwise strangely. So we'll use
  255. * private, pseudo-private, shared (e.g. carrier grade NAT), or
  256. * global IP addresses. */
  257. case InetAddress::IP_SCOPE_PRIVATE:
  258. case InetAddress::IP_SCOPE_PSEUDOPRIVATE:
  259. case InetAddress::IP_SCOPE_SHARED:
  260. case InetAddress::IP_SCOPE_GLOBAL:
  261. if (a.ss_family == AF_INET6) {
  262. // TEMPORARY HACK: for now, we are going to blacklist he.net IPv6
  263. // tunnels due to very spotty performance and low MTU issues over
  264. // these IPv6 tunnel links.
  265. const uint8_t *ipd = reinterpret_cast<const uint8_t *>(reinterpret_cast<const struct sockaddr_in6 *>(&a)->sin6_addr.s6_addr);
  266. if ((ipd[0] == 0x20)&&(ipd[1] == 0x01)&&(ipd[2] == 0x04)&&(ipd[3] == 0x70))
  267. return false;
  268. }
  269. return true;
  270. default:
  271. return false;
  272. }
  273. }
  274. return false;
  275. }
  276. /**
  277. * @return Latency or 0xffff if unknown
  278. */
  279. inline unsigned int latency() const { return _latency; }
  280. /**
  281. * @return Path quality -- lower is better
  282. */
  283. inline long quality(const int64_t now) const
  284. {
  285. const int l = (long)_latency;
  286. const int age = (long)std::min((now - _lastIn),(int64_t)(ZT_PATH_HEARTBEAT_PERIOD * 10)); // set an upper sanity limit to avoid overflow
  287. return (((age < (ZT_PATH_HEARTBEAT_PERIOD + 5000)) ? l : (l + 0xffff + age)) * (long)((ZT_INETADDRESS_MAX_SCOPE - _ipScope) + 1));
  288. }
  289. /**
  290. * @param bonded Whether this path is part of a bond.
  291. */
  292. inline void setBonded(bool bonded) { _bonded = bonded; }
  293. /**
  294. * @return True if this path is currently part of a bond.
  295. */
  296. inline bool bonded() { return _bonded; }
  297. /**
  298. * @return True if this path is alive (receiving heartbeats)
  299. */
  300. inline bool alive(const int64_t now, bool bondingEnabled = false) const {
  301. return (bondingEnabled && _monitorInterval) ? ((now - _lastIn) < (_monitorInterval * 3)) : ((now - _lastIn) < (ZT_PATH_HEARTBEAT_PERIOD + 5000));
  302. }
  303. /**
  304. * @return True if this path needs a heartbeat
  305. */
  306. inline bool needsHeartbeat(const int64_t now) const { return ((now - _lastOut) >= ZT_PATH_HEARTBEAT_PERIOD); }
  307. /**
  308. * @return True if this path needs a heartbeat in accordance to the user-specified path monitor frequency
  309. */
  310. inline bool needsGratuitousHeartbeat(const int64_t now) { return allowed() && (_monitorInterval > 0) && ((now - _lastOut) >= _monitorInterval); }
  311. /**
  312. * @return Last time we sent something
  313. */
  314. inline int64_t lastOut() const { return _lastOut; }
  315. /**
  316. * @return Last time we received anything
  317. */
  318. inline int64_t lastIn() const { return _lastIn; }
  319. /**
  320. * @return the age of the path in terms of receiving packets
  321. */
  322. inline int64_t age(int64_t now) { return (now - _lastIn); }
  323. /**
  324. * @return Time last trust-established packet was received
  325. */
  326. inline int64_t lastTrustEstablishedPacketReceived() const { return _lastTrustEstablishedPacketReceived; }
  327. /**
  328. * @return Time since last VERB_ACK was received
  329. */
  330. inline int64_t ackAge(int64_t now) { return _lastAckReceived ? now - _lastAckReceived : 0; }
  331. /**
  332. * Set or update a refractory period for the path.
  333. *
  334. * @param punishment How much a path should be punished
  335. * @param pathFailure Whether this call is the result of a recent path failure
  336. */
  337. inline void adjustRefractoryPeriod(int64_t now, uint32_t punishment, bool pathFailure) {
  338. if (pathFailure) {
  339. unsigned int suggestedRefractoryPeriod = _refractoryPeriod ? punishment + (_refractoryPeriod * 2) : punishment;
  340. _refractoryPeriod = std::min(suggestedRefractoryPeriod, (unsigned int)ZT_MULTIPATH_MAX_REFRACTORY_PERIOD);
  341. _lastRefractoryUpdate = 0;
  342. } else {
  343. uint32_t drainRefractory = 0;
  344. if (_lastRefractoryUpdate) {
  345. drainRefractory = (now - _lastRefractoryUpdate);
  346. } else {
  347. drainRefractory = (now - _lastAliveToggle);
  348. }
  349. _lastRefractoryUpdate = now;
  350. if (_refractoryPeriod > drainRefractory) {
  351. _refractoryPeriod -= drainRefractory;
  352. } else {
  353. _refractoryPeriod = 0;
  354. _lastRefractoryUpdate = 0;
  355. }
  356. }
  357. }
  358. /**
  359. * Determine the current state of eligibility of the path.
  360. *
  361. * @param includeRefractoryPeriod Whether current punishment should be taken into consideration
  362. * @return True if this path can be used in a bond at the current time
  363. */
  364. inline bool eligible(uint64_t now, int ackSendInterval, bool includeRefractoryPeriod = false) {
  365. if (includeRefractoryPeriod && _refractoryPeriod) {
  366. return false;
  367. }
  368. bool acceptableAge = age(now) < ((_monitorInterval * 4) + _downDelay); // Simple RX age (driven by packets of any type and gratuitous VERB_HELLOs)
  369. bool acceptableAckAge = ackAge(now) < (ackSendInterval); // Whether the remote peer is actually responding to our outgoing traffic or simply sending stuff to us
  370. bool notTooEarly = (now - _lastAliveToggle) >= _upDelay; // Whether we've waited long enough since the link last came online
  371. bool inTrial = (now - _lastTrialBegin) < _upDelay; // Whether this path is still in its trial period
  372. bool currEligibility = allowed() && (((acceptableAge || acceptableAckAge) && notTooEarly) || inTrial);
  373. return currEligibility;
  374. }
  375. /**
  376. * Record when this path first entered the bond. Each path is given a trial period where it is admitted
  377. * to the bond without requiring observations to prove its performance or reliability.
  378. */
  379. inline void startTrial(uint64_t now) { _lastTrialBegin = now; }
  380. /**
  381. * @return True if a path is permitted to be used in a bond (according to user pref.)
  382. */
  383. inline bool allowed() {
  384. return _enabled
  385. && (!_ipvPref
  386. || ((_addr.isV4() && (_ipvPref == 4 || _ipvPref == 46 || _ipvPref == 64))
  387. || ((_addr.isV6() && (_ipvPref == 6 || _ipvPref == 46 || _ipvPref == 64)))));
  388. }
  389. /**
  390. * @return True if a path is preferred over another on the same physical link (according to user pref.)
  391. */
  392. inline bool preferred() {
  393. return _onlyPathOnLink
  394. || (_addr.isV4() && (_ipvPref == 4 || _ipvPref == 46))
  395. || (_addr.isV6() && (_ipvPref == 6 || _ipvPref == 64));
  396. }
  397. /**
  398. * @param now Current time
  399. * @return Whether an ACK (VERB_ACK) packet needs to be emitted at this time
  400. */
  401. inline bool needsToSendAck(int64_t now, int ackSendInterval) {
  402. return ((now - _lastAckSent) >= ackSendInterval ||
  403. (_packetsReceivedSinceLastAck == ZT_QOS_TABLE_SIZE)) && _packetsReceivedSinceLastAck;
  404. }
  405. /**
  406. * @param now Current time
  407. * @return Whether a QoS (VERB_QOS_MEASUREMENT) packet needs to be emitted at this time
  408. */
  409. inline bool needsToSendQoS(int64_t now, int qosSendInterval) {
  410. return ((_packetsReceivedSinceLastQoS >= ZT_QOS_TABLE_SIZE) ||
  411. ((now - _lastQoSMeasurement) > qosSendInterval)) && _packetsReceivedSinceLastQoS;
  412. }
  413. /**
  414. * Reset packet counters
  415. */
  416. inline void resetPacketCounts()
  417. {
  418. _packetsIn = 0;
  419. _packetsOut = 0;
  420. }
  421. private:
  422. volatile int64_t _lastOut;
  423. volatile int64_t _lastIn;
  424. volatile int64_t _lastTrustEstablishedPacketReceived;
  425. int64_t _localSocket;
  426. volatile unsigned int _latency;
  427. InetAddress _addr;
  428. InetAddress::IpScope _ipScope; // memoize this since it's a computed value checked often
  429. AtomicCounter __refCount;
  430. std::map<uint64_t,uint64_t> qosStatsOut; // id:egress_time
  431. std::map<uint64_t,uint64_t> qosStatsIn; // id:now
  432. std::map<uint64_t,uint16_t> ackStatsIn; // id:len
  433. RingBuffer<int,ZT_QOS_SHORTTERM_SAMPLE_WIN_SIZE> qosRecordSize;
  434. RingBuffer<float,ZT_QOS_SHORTTERM_SAMPLE_WIN_SIZE> qosRecordLossSamples;
  435. RingBuffer<uint64_t,ZT_QOS_SHORTTERM_SAMPLE_WIN_SIZE> throughputSamples;
  436. RingBuffer<bool,ZT_QOS_SHORTTERM_SAMPLE_WIN_SIZE> packetValiditySamples;
  437. RingBuffer<float,ZT_QOS_SHORTTERM_SAMPLE_WIN_SIZE> _throughputVarianceSamples;
  438. RingBuffer<uint16_t,ZT_QOS_SHORTTERM_SAMPLE_WIN_SIZE> latencySamples;
  439. /**
  440. * Last time that a VERB_ACK was received on this path.
  441. */
  442. uint64_t _lastAckReceived;
  443. /**
  444. * Last time that a VERB_ACK was sent out on this path.
  445. */
  446. uint64_t _lastAckSent;
  447. /**
  448. * Last time that a VERB_QOS_MEASUREMENT was sent out on this path.
  449. */
  450. uint64_t _lastQoSMeasurement;
  451. /**
  452. * Last time that the path's throughput was estimated.
  453. */
  454. uint64_t _lastThroughputEstimation;
  455. /**
  456. * The last time that the refractory period was updated.
  457. */
  458. uint64_t _lastRefractoryUpdate;
  459. /**
  460. * The last time that the path was marked as "alive".
  461. */
  462. uint64_t _lastAliveToggle;
  463. /**
  464. * State of eligibility at last check. Used for determining state changes.
  465. */
  466. bool _lastEligibilityState;
  467. /**
  468. * Timestamp indicating when this path's trial period began.
  469. */
  470. uint64_t _lastTrialBegin;
  471. /**
  472. * Amount of time that this path will be prevented from becoming a member of a bond.
  473. */
  474. uint32_t _refractoryPeriod;
  475. /**
  476. * Monitor interval specific to this path or that was inherited from the bond controller.
  477. */
  478. int32_t _monitorInterval;
  479. /**
  480. * Up delay interval specific to this path or that was inherited from the bond controller.
  481. */
  482. uint32_t _upDelay;
  483. /**
  484. * Down delay interval specific to this path or that was inherited from the bond controller.
  485. */
  486. uint32_t _downDelay;
  487. /**
  488. * IP version preference inherited from the physical link.
  489. */
  490. uint8_t _ipvPref;
  491. /**
  492. * Mode inherited from the physical link.
  493. */
  494. uint8_t _mode;
  495. /**
  496. * IP version preference inherited from the physical link.
  497. */
  498. bool _onlyPathOnLink;
  499. /**
  500. * Enabled state inherited from the physical link.
  501. */
  502. bool _enabled;
  503. /**
  504. * Whether this path is currently part of a bond.
  505. */
  506. bool _bonded;
  507. /**
  508. * Whether this path was intentionally negotiated by either peer.
  509. */
  510. bool _negotiated;
  511. /**
  512. * Whether this path has been deprecated due to performance issues. Current traffic flows
  513. * will be re-allocated to other paths in the most non-disruptive manner (if possible),
  514. * and new traffic will not be allocated to this path.
  515. */
  516. bool _deprecated;
  517. /**
  518. * Whether flows should be moved from this path. Current traffic flows will be re-allocated
  519. * immediately.
  520. */
  521. bool _shouldReallocateFlows;
  522. /**
  523. * The number of flows currently assigned to this path.
  524. */
  525. uint16_t _assignedFlowCount;
  526. /**
  527. * The mean latency (computed from a sliding window.)
  528. */
  529. float _latencyMean;
  530. /**
  531. * Packet delay variance (computed from a sliding window.)
  532. */
  533. float _latencyVariance;
  534. /**
  535. * The ratio of lost packets to received packets.
  536. */
  537. float _packetLossRatio;
  538. /**
  539. * The ratio of packets that failed their MAC/CRC checks to those that did not.
  540. */
  541. float _packetErrorRatio;
  542. /**
  543. * The estimated mean throughput of this path.
  544. */
  545. uint64_t _throughputMean;
  546. /**
  547. * The maximum observed throughput of this path.
  548. */
  549. uint64_t _throughputMax;
  550. /**
  551. * The variance in the estimated throughput of this path.
  552. */
  553. float _throughputVariance;
  554. /**
  555. * The relative quality of this path to all others in the bond, [0-255].
  556. */
  557. uint8_t _allocation;
  558. /**
  559. * How much load this path is under.
  560. */
  561. uint64_t _byteLoad;
  562. /**
  563. * How much load this path is under (relative to other paths in the bond.)
  564. */
  565. uint8_t _relativeByteLoad;
  566. /**
  567. * Relative value expressing how "deserving" this path is of new traffic.
  568. */
  569. uint8_t _affinity;
  570. /**
  571. * Score that indicates to what degree this path is preferred over others that
  572. * are available to the bonding policy. (specifically for active-backup)
  573. */
  574. uint32_t _failoverScore;
  575. /**
  576. * Number of bytes thus far sent that have not been acknowledged by the remote peer.
  577. */
  578. int64_t _unackedBytes;
  579. /**
  580. * Number of packets received since the last VERB_ACK was sent to the remote peer.
  581. */
  582. int32_t _packetsReceivedSinceLastAck;
  583. /**
  584. * Number of packets received since the last VERB_QOS_MEASUREMENT was sent to the remote peer.
  585. */
  586. int32_t _packetsReceivedSinceLastQoS;
  587. /**
  588. * Bytes acknowledged via incoming VERB_ACK since the last estimation of throughput.
  589. */
  590. uint64_t _bytesAckedSinceLastThroughputEstimation;
  591. /**
  592. * Counters used for tracking path load.
  593. */
  594. int _packetsIn;
  595. int _packetsOut;
  596. };
  597. } // namespace ZeroTier
  598. #endif