Constants.hpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  1. /*
  2. * ZeroTier One - Network Virtualization Everywhere
  3. * Copyright (C) 2011-2019 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. * --
  19. *
  20. * You can be released from the requirements of the license by purchasing
  21. * a commercial license. Buying such a license is mandatory as soon as you
  22. * develop commercial closed-source software that incorporates or links
  23. * directly against ZeroTier software without disclosing the source code
  24. * of your own application.
  25. */
  26. #ifndef ZT_CONSTANTS_HPP
  27. #define ZT_CONSTANTS_HPP
  28. #include "../include/ZeroTierOne.h"
  29. #if __has_include("version.h")
  30. #include "version.h"
  31. #else /* dummy values for use inside IDEs, etc. */
  32. #define ZEROTIER_ONE_VERSION_MAJOR 255
  33. #define ZEROTIER_ONE_VERSION_MINOR 255
  34. #define ZEROTIER_ONE_VERSION_REVISION 255
  35. #define ZEROTIER_ONE_VERSION_BUILD 255
  36. #endif
  37. #ifndef ZT_BUILD_ARCHITECTURE
  38. #define ZT_BUILD_ARCHITECTURE 0
  39. #endif
  40. #ifndef ZT_BUILD_PLATFORM
  41. #define ZT_BUILD_PLATFORM 0
  42. #endif
  43. //
  44. // This include file also auto-detects and canonicalizes some environment
  45. // information defines:
  46. //
  47. // __LINUX__
  48. // __APPLE__
  49. // __BSD__ (OSX also defines this)
  50. // __UNIX_LIKE__ (Linux, BSD, etc.)
  51. // __WINDOWS__
  52. //
  53. // Also makes sure __BYTE_ORDER is defined reasonably.
  54. //
  55. // Hack: make sure __GCC__ is defined on old GCC compilers
  56. #ifndef __GCC__
  57. #if defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1) || defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2) || defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4)
  58. #define __GCC__
  59. #endif
  60. #endif
  61. #if defined(__linux__) || defined(linux) || defined(__LINUX__) || defined(__linux)
  62. #ifndef __LINUX__
  63. #define __LINUX__
  64. #endif
  65. #ifndef __UNIX_LIKE__
  66. #define __UNIX_LIKE__
  67. #endif
  68. #include <endian.h>
  69. #endif
  70. #ifdef __APPLE__
  71. #include <TargetConditionals.h>
  72. #ifndef __UNIX_LIKE__
  73. #define __UNIX_LIKE__
  74. #endif
  75. #ifndef __BSD__
  76. #define __BSD__
  77. #endif
  78. #include <machine/endian.h>
  79. #endif
  80. #if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
  81. #ifndef __UNIX_LIKE__
  82. #define __UNIX_LIKE__
  83. #endif
  84. #ifndef __BSD__
  85. #define __BSD__
  86. #endif
  87. #include <sys/endian.h>
  88. #ifndef __BYTE_ORDER
  89. #define __BYTE_ORDER _BYTE_ORDER
  90. #define __LITTLE_ENDIAN _LITTLE_ENDIAN
  91. #define __BIG_ENDIAN _BIG_ENDIAN
  92. #endif
  93. #endif
  94. #if defined(_WIN32) || defined(_WIN64)
  95. #ifndef __WINDOWS__
  96. #define __WINDOWS__
  97. #endif
  98. #ifndef NOMINMAX
  99. #define NOMINMAX
  100. #endif
  101. #pragma warning(disable : 4290)
  102. #pragma warning(disable : 4996)
  103. #pragma warning(disable : 4101)
  104. #undef __UNIX_LIKE__
  105. #undef __BSD__
  106. #include <WinSock2.h>
  107. #include <Windows.h>
  108. #endif
  109. #ifdef __NetBSD__
  110. #ifndef RTF_MULTICAST
  111. #define RTF_MULTICAST 0x20000000
  112. #endif
  113. #endif
  114. // Define ZT_NO_TYPE_PUNNING to disable reckless casts on anything other than x86 and x86_64.
  115. #if (!(defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64) || defined(_M_AMD64) || defined(_M_X64) || defined(i386) || defined(__i386) || defined(__i386__) || defined(__i486__) || defined(__i586__) || defined(__i686__) || defined(_M_IX86) || defined(__X86__) || defined(_X86_) || defined(__I86__) || defined(__INTEL__) || defined(__386)))
  116. #ifndef ZT_NO_TYPE_PUNNING
  117. #define ZT_NO_TYPE_PUNNING
  118. #endif
  119. #endif
  120. // Assume little endian if not defined on Mac and Windows as these don't run on any BE architectures.
  121. #if (defined(__APPLE__) || defined(__WINDOWS__)) && (!defined(__BYTE_ORDER))
  122. #undef __BYTE_ORDER
  123. #undef __LITTLE_ENDIAN
  124. #undef __BIG_ENDIAN
  125. #define __BIG_ENDIAN 4321
  126. #define __LITTLE_ENDIAN 1234
  127. #define __BYTE_ORDER 1234
  128. #endif
  129. #ifdef __WINDOWS__
  130. #define ZT_PATH_SEPARATOR '\\'
  131. #define ZT_PATH_SEPARATOR_S "\\"
  132. #define ZT_EOL_S "\r\n"
  133. #else
  134. #define ZT_PATH_SEPARATOR '/'
  135. #define ZT_PATH_SEPARATOR_S "/"
  136. #define ZT_EOL_S "\n"
  137. #endif
  138. #ifndef __BYTE_ORDER
  139. #include <endian.h>
  140. #endif
  141. #if (defined(__GNUC__) && (__GNUC__ >= 3)) || (defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 800)) || defined(__clang__)
  142. #ifndef likely
  143. #define likely(x) __builtin_expect((x),1)
  144. #endif
  145. #ifndef unlikely
  146. #define unlikely(x) __builtin_expect((x),0)
  147. #endif
  148. #else
  149. #ifndef likely
  150. #define likely(x) (x)
  151. #endif
  152. #ifndef unlikely
  153. #define unlikely(x) (x)
  154. #endif
  155. #endif
  156. #if defined(__WINDOWS__) && !defined(__GNUC__) && !defined (__clang__) && !defined(__INTEL_COMPILER)
  157. #define ZT_PACKED_STRUCT(D) __pragma(pack(push,1)) D __pragma(pack(pop))
  158. #else
  159. #define ZT_PACKED_STRUCT(D) D __attribute__((packed))
  160. #endif
  161. /**
  162. * Length of a ZeroTier address in bytes
  163. */
  164. #define ZT_ADDRESS_LENGTH 5
  165. /**
  166. * Length of a hexadecimal ZeroTier address
  167. */
  168. #define ZT_ADDRESS_LENGTH_HEX 10
  169. /**
  170. * Addresses beginning with this byte are reserved for the joy of in-band signaling
  171. */
  172. #define ZT_ADDRESS_RESERVED_PREFIX 0xff
  173. /**
  174. * Default virtual network MTU (not physical)
  175. */
  176. #define ZT_DEFAULT_MTU 2800
  177. /**
  178. * Maximum number of packet fragments we'll support (protocol max: 16)
  179. */
  180. #define ZT_MAX_PACKET_FRAGMENTS 7
  181. /**
  182. * Size of RX queue in packets
  183. */
  184. #define ZT_RX_QUEUE_SIZE 32
  185. /**
  186. * Size of TX queue in packets
  187. */
  188. #define ZT_TX_QUEUE_SIZE 32
  189. /**
  190. * Length of peer shared secrets (256-bit, do not change)
  191. */
  192. #define ZT_PEER_SECRET_KEY_LENGTH 32
  193. /**
  194. * Minimum delay between timer task checks to prevent thrashing
  195. */
  196. #define ZT_CORE_TIMER_TASK_GRANULARITY 500
  197. /**
  198. * How often Topology::clean() and Network::clean() and similar are called, in ms
  199. */
  200. #define ZT_HOUSEKEEPING_PERIOD 60000
  201. /**
  202. * Delay between WHOIS retries in ms
  203. */
  204. #define ZT_WHOIS_RETRY_DELAY 500
  205. /**
  206. * Transmit queue entry timeout
  207. */
  208. #define ZT_TRANSMIT_QUEUE_TIMEOUT 5000
  209. /**
  210. * Receive queue entry timeout
  211. */
  212. #define ZT_RECEIVE_QUEUE_TIMEOUT 5000
  213. /**
  214. * Maximum number of ZT hops allowed (this is not IP hops/TTL)
  215. *
  216. * The protocol allows up to 7, but we limit it to something smaller.
  217. */
  218. #define ZT_RELAY_MAX_HOPS 4
  219. /**
  220. * Expire time for multicast 'likes' and indirect multicast memberships in ms
  221. */
  222. #define ZT_MULTICAST_LIKE_EXPIRE 600000
  223. /**
  224. * Period for multicast LIKE announcements
  225. */
  226. #define ZT_MULTICAST_ANNOUNCE_PERIOD 120000
  227. /**
  228. * Delay between explicit MULTICAST_GATHER requests for a given multicast channel
  229. */
  230. #define ZT_MULTICAST_EXPLICIT_GATHER_DELAY (ZT_MULTICAST_LIKE_EXPIRE / 10)
  231. /**
  232. * Timeout for outgoing multicasts
  233. *
  234. * This is how long we wait for explicit or implicit gather results.
  235. */
  236. #define ZT_MULTICAST_TRANSMIT_TIMEOUT 5000
  237. /**
  238. * Delay between checks of peer pings, etc., and also related housekeeping tasks
  239. */
  240. #define ZT_PING_CHECK_INVERVAL 5000
  241. /**
  242. * How frequently to check for changes to the system's network interfaces. When
  243. * the service decides to use this constant it's because we want to react more
  244. * quickly to new interfaces that pop up or go down.
  245. */
  246. #define ZT_MULTIPATH_BINDER_REFRESH_PERIOD 5000
  247. /**
  248. * Packets are only used for QoS/ACK statistical sampling if their packet ID is divisible by
  249. * this integer. This is to provide a mechanism for both peers to agree on which packets need
  250. * special treatment without having to exchange information. Changing this value would be
  251. * a breaking change and would necessitate a protocol version upgrade. Since each incoming and
  252. * outgoing packet ID is checked against this value its evaluation is of the form:
  253. * (id & (divisor - 1)) == 0, thus the divisor must be a power of 2.
  254. *
  255. * This value is set at (16) so that given a normally-distributed RNG output we will sample
  256. * 1/16th (or ~6.25%) of packets.
  257. */
  258. #define ZT_PATH_QOS_ACK_PROTOCOL_DIVISOR 0x10
  259. /**
  260. * Time horizon for VERB_QOS_MEASUREMENT and VERB_ACK packet processing cutoff
  261. */
  262. #define ZT_PATH_QOS_ACK_CUTOFF_TIME 30000
  263. /**
  264. * Maximum number of VERB_QOS_MEASUREMENT and VERB_ACK packets allowed to be
  265. * processed within cutoff time. Separate totals are kept for each type but
  266. * the limit is the same for both.
  267. *
  268. * This limits how often this peer will compute statistical estimates
  269. * of various QoS measures from a VERB_QOS_MEASUREMENT or VERB_ACK packets to
  270. * CUTOFF_LIMIT times per CUTOFF_TIME milliseconds per peer to prevent
  271. * this from being useful for DOS amplification attacks.
  272. */
  273. #define ZT_PATH_QOS_ACK_CUTOFF_LIMIT 128
  274. /**
  275. * Path choice history window size. This is used to keep track of which paths were
  276. * previously selected so that we can maintain a target allocation over time.
  277. */
  278. #define ZT_MULTIPATH_PROPORTION_WIN_SZ 128
  279. /**
  280. * How often we will sample packet latency. Should be at least greater than ZT_PING_CHECK_INVERVAL
  281. * since we will record a 0 bit/s measurement if no valid latency measurement was made within this
  282. * window of time.
  283. */
  284. #define ZT_PATH_LATENCY_SAMPLE_INTERVAL (ZT_MULTIPATH_PEER_PING_PERIOD * 2)
  285. /**
  286. * Interval used for rate-limiting the computation of path quality estimates.
  287. */
  288. #define ZT_PATH_QUALITY_COMPUTE_INTERVAL 1000
  289. /**
  290. * Number of samples to consider when computing real-time path statistics
  291. */
  292. #define ZT_PATH_QUALITY_METRIC_REALTIME_CONSIDERATION_WIN_SZ 128
  293. /**
  294. * Number of samples to consider when computing performing long-term path quality analysis.
  295. * By default this value is set to ZT_PATH_QUALITY_METRIC_REALTIME_CONSIDERATION_WIN_SZ but can
  296. * be set to any value greater than that to observe longer-term path quality behavior.
  297. */
  298. #define ZT_PATH_QUALITY_METRIC_WIN_SZ ZT_PATH_QUALITY_METRIC_REALTIME_CONSIDERATION_WIN_SZ
  299. /**
  300. * Maximum acceptable Packet Delay Variance (PDV) over a path
  301. */
  302. #define ZT_PATH_MAX_PDV 1000
  303. /**
  304. * Maximum acceptable time interval between expectation and receipt of at least one ACK over a path
  305. */
  306. #define ZT_PATH_MAX_AGE 30000
  307. /**
  308. * Maximum acceptable mean latency over a path
  309. */
  310. #define ZT_PATH_MAX_MEAN_LATENCY 1000
  311. /**
  312. * How much each factor contributes to the "stability" score of a path
  313. */
  314. #define ZT_PATH_CONTRIB_PDV (1.0 / 3.0)
  315. #define ZT_PATH_CONTRIB_LATENCY (1.0 / 3.0)
  316. #define ZT_PATH_CONTRIB_THROUGHPUT_DISTURBANCE (1.0 / 3.0)
  317. /**
  318. * How much each factor contributes to the "quality" score of a path
  319. */
  320. #define ZT_PATH_CONTRIB_STABILITY (0.75 / 3.0)
  321. #define ZT_PATH_CONTRIB_THROUGHPUT (1.50 / 3.0)
  322. #define ZT_PATH_CONTRIB_SCOPE (0.75 / 3.0)
  323. /**
  324. * How often a QoS packet is sent
  325. */
  326. #define ZT_PATH_QOS_INTERVAL 3000
  327. /**
  328. * Min and max acceptable sizes for a VERB_QOS_MEASUREMENT packet
  329. */
  330. #define ZT_PATH_MIN_QOS_PACKET_SZ 8 + 1
  331. #define ZT_PATH_MAX_QOS_PACKET_SZ 1400
  332. /**
  333. * How many ID:sojourn time pairs in a single QoS packet
  334. */
  335. #define ZT_PATH_QOS_TABLE_SIZE ((ZT_PATH_MAX_QOS_PACKET_SZ * 8) / (64 + 16))
  336. /**
  337. * Maximum number of outgoing packets we monitor for QoS information
  338. */
  339. #define ZT_PATH_MAX_OUTSTANDING_QOS_RECORDS 128
  340. /**
  341. * Timeout for QoS records
  342. */
  343. #define ZT_PATH_QOS_TIMEOUT (ZT_PATH_QOS_INTERVAL * 2)
  344. /**
  345. * How often the service tests the path throughput
  346. */
  347. #define ZT_PATH_THROUGHPUT_MEASUREMENT_INTERVAL (ZT_PATH_ACK_INTERVAL * 8)
  348. /**
  349. * Minimum amount of time between each ACK packet
  350. */
  351. #define ZT_PATH_ACK_INTERVAL 1000
  352. /**
  353. * How often an aggregate link statistics report is emitted into this tracing system
  354. */
  355. #define ZT_PATH_AGGREGATE_STATS_REPORT_INTERVAL 60000
  356. /**
  357. * How much an aggregate link's component paths can vary from their target allocation
  358. * before the link is considered to be in a state of imbalance.
  359. */
  360. #define ZT_PATH_IMBALANCE_THRESHOLD 0.20
  361. /**
  362. * Max allowable time spent in any queue
  363. */
  364. #define ZT_QOS_TARGET 5 // ms
  365. /**
  366. * Time period where the time spent in the queue by a packet should fall below
  367. * target at least once
  368. */
  369. #define ZT_QOS_INTERVAL 100 // ms
  370. /**
  371. * The number of bytes that each queue is allowed to send during each DRR cycle.
  372. * This approximates a single-byte-based fairness queuing scheme
  373. */
  374. #define ZT_QOS_QUANTUM ZT_DEFAULT_MTU
  375. /**
  376. * The maximum total number of packets that can be queued among all
  377. * active/inactive, old/new queues
  378. */
  379. #define ZT_QOS_MAX_ENQUEUED_PACKETS 1024
  380. /**
  381. * Number of QoS queues (buckets)
  382. */
  383. #define ZT_QOS_NUM_BUCKETS 9
  384. /**
  385. * All unspecified traffic is put in this bucket. Anything in a bucket with a smaller
  386. * value is de-prioritized. Anything in a bucket with a higher value is prioritized over
  387. * other traffic.
  388. */
  389. #define ZT_QOS_DEFAULT_BUCKET 0
  390. /**
  391. * How frequently to send heartbeats over in-use paths
  392. */
  393. #define ZT_PATH_HEARTBEAT_PERIOD 14000
  394. /**
  395. * Do not accept HELLOs over a given path more often than this
  396. */
  397. #define ZT_PATH_HELLO_RATE_LIMIT 1000
  398. /**
  399. * Delay between full-fledge pings of directly connected peers
  400. */
  401. #define ZT_PEER_PING_PERIOD 60000
  402. /**
  403. * Delay between full-fledge pings of directly connected peers.
  404. *
  405. * With multipath bonding enabled ping peers more often to measure
  406. * packet loss and latency. This uses more bandwidth so is disabled
  407. * by default to avoid increasing idle bandwidth use for regular
  408. * links.
  409. */
  410. #define ZT_MULTIPATH_PEER_PING_PERIOD 5000
  411. /**
  412. * Paths are considered expired if they have not sent us a real packet in this long
  413. */
  414. #define ZT_PEER_PATH_EXPIRATION ((ZT_PEER_PING_PERIOD * 4) + 3000)
  415. /**
  416. * How often to retry expired paths that we're still remembering
  417. */
  418. #define ZT_PEER_EXPIRED_PATH_TRIAL_PERIOD (ZT_PEER_PING_PERIOD * 10)
  419. /**
  420. * Timeout for overall peer activity (measured from last receive)
  421. */
  422. #ifndef ZT_SDK
  423. #define ZT_PEER_ACTIVITY_TIMEOUT 500000
  424. #else
  425. #define ZT_PEER_ACTIVITY_TIMEOUT 30000
  426. #endif
  427. /**
  428. * General rate limit timeout for multiple packet types (HELLO, etc.)
  429. */
  430. #define ZT_PEER_GENERAL_INBOUND_RATE_LIMIT 500
  431. /**
  432. * General limit for max RTT for requests over the network
  433. */
  434. #define ZT_GENERAL_RTT_LIMIT 5000
  435. /**
  436. * Delay between requests for updated network autoconf information
  437. *
  438. * Don't lengthen this as it affects things like QoS / uptime monitoring
  439. * via ZeroTier Central. This is the heartbeat, basically.
  440. */
  441. #define ZT_NETWORK_AUTOCONF_DELAY 60000
  442. /**
  443. * Minimum interval between attempts by relays to unite peers
  444. *
  445. * When a relay gets a packet destined for another peer, it sends both peers
  446. * a RENDEZVOUS message no more than this often. This instructs the peers
  447. * to attempt NAT-t and gives each the other's corresponding IP:port pair.
  448. */
  449. #define ZT_MIN_UNITE_INTERVAL 30000
  450. /**
  451. * How often should peers try memorized or statically defined paths?
  452. */
  453. #define ZT_TRY_MEMORIZED_PATH_INTERVAL 30000
  454. /**
  455. * Sanity limit on maximum bridge routes
  456. *
  457. * If the number of bridge routes exceeds this, we cull routes from the
  458. * bridges with the most MACs behind them until it doesn't. This is a
  459. * sanity limit to prevent memory-filling DOS attacks, nothing more. No
  460. * physical LAN has anywhere even close to this many nodes. Note that this
  461. * does not limit the size of ZT virtual LANs, only bridge routing.
  462. */
  463. #define ZT_MAX_BRIDGE_ROUTES 67108864
  464. /**
  465. * If there is no known L2 bridging route, spam to up to this many active bridges
  466. */
  467. #define ZT_MAX_BRIDGE_SPAM 32
  468. /**
  469. * Interval between direct path pushes in milliseconds
  470. */
  471. #define ZT_DIRECT_PATH_PUSH_INTERVAL 15000
  472. /**
  473. * Interval between direct path pushes in milliseconds if we already have a path
  474. */
  475. #define ZT_DIRECT_PATH_PUSH_INTERVAL_HAVEPATH 120000
  476. /**
  477. * Time horizon for push direct paths cutoff
  478. */
  479. #define ZT_PUSH_DIRECT_PATHS_CUTOFF_TIME 30000
  480. /**
  481. * Maximum number of direct path pushes within cutoff time
  482. *
  483. * This limits response to PUSH_DIRECT_PATHS to CUTOFF_LIMIT responses
  484. * per CUTOFF_TIME milliseconds per peer to prevent this from being
  485. * useful for DOS amplification attacks.
  486. */
  487. #define ZT_PUSH_DIRECT_PATHS_CUTOFF_LIMIT 8
  488. /**
  489. * Maximum number of paths per IP scope (e.g. global, link-local) and family (e.g. v4/v6)
  490. */
  491. #define ZT_PUSH_DIRECT_PATHS_MAX_PER_SCOPE_AND_FAMILY 8
  492. /**
  493. * Time horizon for VERB_NETWORK_CREDENTIALS cutoff
  494. */
  495. #define ZT_PEER_CREDENTIALS_CUTOFF_TIME 60000
  496. /**
  497. * Maximum number of VERB_NETWORK_CREDENTIALS within cutoff time
  498. */
  499. #define ZT_PEER_CREDEITIALS_CUTOFF_LIMIT 15
  500. /**
  501. * WHOIS rate limit (we allow these to be pretty fast)
  502. */
  503. #define ZT_PEER_WHOIS_RATE_LIMIT 100
  504. /**
  505. * General rate limit for other kinds of rate-limited packets (HELLO, credential request, etc.) both inbound and outbound
  506. */
  507. #define ZT_PEER_GENERAL_RATE_LIMIT 1000
  508. /**
  509. * Don't do expensive identity validation more often than this
  510. *
  511. * IPv4 and IPv6 address prefixes are hashed down to 14-bit (0-16383) integers
  512. * using the first 24 bits for IPv4 or the first 48 bits for IPv6. These are
  513. * then rate limited to one identity validation per this often milliseconds.
  514. */
  515. #if (defined(__amd64) || defined(__amd64__) || defined(__x86_64) || defined(__x86_64__) || defined(__AMD64) || defined(__AMD64__) || defined(_M_X64) || defined(_M_AMD64))
  516. // AMD64 machines can do anywhere from one every 50ms to one every 10ms. This provides plenty of margin.
  517. #define ZT_IDENTITY_VALIDATION_SOURCE_RATE_LIMIT 2000
  518. #else
  519. #if (defined(__i386__) || defined(__i486__) || defined(__i586__) || defined(__i686__) || defined(_M_IX86) || defined(_X86_) || defined(__I86__))
  520. // 32-bit Intel machines usually average about one every 100ms
  521. #define ZT_IDENTITY_VALIDATION_SOURCE_RATE_LIMIT 5000
  522. #else
  523. // This provides a safe margin for ARM, MIPS, etc. that usually average one every 250-400ms
  524. #define ZT_IDENTITY_VALIDATION_SOURCE_RATE_LIMIT 10000
  525. #endif
  526. #endif
  527. /**
  528. * How long is a path or peer considered to have a trust relationship with us (for e.g. relay policy) since last trusted established packet?
  529. */
  530. #define ZT_TRUST_EXPIRATION 600000
  531. /**
  532. * Size of a buffer to store either a C25519 or an ECC P-384 signature
  533. */
  534. #define ZT_SIGNATURE_BUFFER_SIZE 96
  535. /**
  536. * Desired buffer size for UDP sockets (used in service and osdep but defined here)
  537. */
  538. #if (defined(__amd64) || defined(__amd64__) || defined(__x86_64) || defined(__x86_64__) || defined(__AMD64) || defined(__AMD64__))
  539. #define ZT_UDP_DESIRED_BUF_SIZE 1048576
  540. #else
  541. #define ZT_UDP_DESIRED_BUF_SIZE 131072
  542. #endif
  543. /**
  544. * Desired / recommended min stack size for threads (used on some platforms to reset thread stack size)
  545. */
  546. #define ZT_THREAD_MIN_STACK_SIZE 1048576
  547. #define ZT_CRYPTO_ALG_C25519 0
  548. #define ZT_CRYPTO_ALG_P384 1
  549. // Exceptions thrown in core ZT code
  550. #define ZT_EXCEPTION_OUT_OF_BOUNDS 100
  551. #define ZT_EXCEPTION_OUT_OF_MEMORY 101
  552. #define ZT_EXCEPTION_PRIVATE_KEY_REQUIRED 102
  553. #define ZT_EXCEPTION_INVALID_ARGUMENT 103
  554. #define ZT_EXCEPTION_INVALID_SERIALIZED_DATA_INVALID_TYPE 200
  555. #define ZT_EXCEPTION_INVALID_SERIALIZED_DATA_OVERFLOW 201
  556. #define ZT_EXCEPTION_INVALID_SERIALIZED_DATA_INVALID_CRYPTOGRAPHIC_TOKEN 202
  557. #define ZT_EXCEPTION_INVALID_SERIALIZED_DATA_BAD_ENCODING 203
  558. #endif