Constants.hpp 17 KB

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