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 
14 #ifndef ZT_CONSTANTS_HPP
15 #define ZT_CONSTANTS_HPP
16 
17 #include "../include/ZeroTierOne.h"
18 
19 //
20 // This include file also auto-detects and canonicalizes some environment
21 // information defines:
22 //
23 // __LINUX__
24 // __APPLE__
25 // __BSD__ (OSX also defines this)
26 // __UNIX_LIKE__ (Linux, BSD, etc.)
27 // __WINDOWS__
28 //
29 // Also makes sure __BYTE_ORDER is defined reasonably.
30 //
31 
32 #ifndef ZT_INLINE
33 #define ZT_INLINE inline
34 #endif
35 
36 #define restrict
37 
38 // Hack: make sure __GCC__ is defined on old GCC compilers
39 #ifndef __GCC__
40 #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)
41 #define __GCC__
42 #endif
43 #endif
44 
45 #if defined(__linux__) || defined(linux) || defined(__LINUX__) || defined(__linux)
46 #ifndef __LINUX__
47 #define __LINUX__
48 #endif
49 #ifndef __UNIX_LIKE__
50 #define __UNIX_LIKE__
51 #endif
52 #include <endian.h>
53 #endif
54 
55 #ifdef __APPLE__
56 #define likely(x) __builtin_expect((x),1)
57 #define unlikely(x) __builtin_expect((x),0)
58 #include <TargetConditionals.h>
59 #ifndef __UNIX_LIKE__
60 #define __UNIX_LIKE__
61 #endif
62 #ifndef __BSD__
63 #define __BSD__
64 #endif
65 #include <machine/endian.h>
66 #endif
67 
68 #if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__)
69 #ifndef __UNIX_LIKE__
70 #define __UNIX_LIKE__
71 #endif
72 #ifndef __BSD__
73 #define __BSD__
74 #endif
75 #include <machine/endian.h>
76 #ifndef __BYTE_ORDER
77 #define __BYTE_ORDER _BYTE_ORDER
78 #define __LITTLE_ENDIAN _LITTLE_ENDIAN
79 #define __BIG_ENDIAN _BIG_ENDIAN
80 #endif
81 #endif
82 
83 #if defined(_WIN32) || defined(_WIN64)
84 #ifndef __WINDOWS__
85 #define __WINDOWS__
86 #endif
87 #ifndef NOMINMAX
88 #define NOMINMAX
89 #endif
90 #pragma warning(disable : 4290)
91 #pragma warning(disable : 4996)
92 #pragma warning(disable : 4101)
93 #undef __UNIX_LIKE__
94 #undef __BSD__
95 #include <WinSock2.h>
96 #include <Windows.h>
97 #endif
98 
99 #ifdef __NetBSD__
100 #ifndef RTF_MULTICAST
101 #define RTF_MULTICAST   0x20000000
102 #endif
103 #endif
104 
105 #if (defined(__amd64) || defined(__amd64__) || defined(__x86_64) || defined(__x86_64__) || defined(__AMD64) || defined(__AMD64__) || defined(_M_X64))
106 #define ZT_ARCH_X64 1
107 #include <xmmintrin.h>
108 #include <emmintrin.h>
109 #include <immintrin.h>
110 #endif
111 
112 #if (defined(__ARM_NEON) || defined(__ARM_NEON__) || defined(ZT_ARCH_ARM_HAS_NEON))
113 #if (defined(__APPLE__) && !defined(__LP64__)) || (defined(__ANDROID__) && defined(__arm__))
114 #ifdef ZT_ARCH_ARM_HAS_NEON
115 #undef ZT_ARCH_ARM_HAS_NEON
116 #endif
117 #else
118 #ifndef ZT_ARCH_ARM_HAS_NEON
119 #define ZT_ARCH_ARM_HAS_NEON 1
120 #endif
121 #include <arm_neon.h>
122 /*#include <arm_acle.h>*/
123 #endif
124 #endif
125 
126 // Define ZT_NO_TYPE_PUNNING to disable reckless casts on anything other than x86/x64.
127 #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)))
128 #ifndef ZT_NO_TYPE_PUNNING
129 #define ZT_NO_TYPE_PUNNING 1
130 #endif
131 #endif
132 #ifdef ZT_NO_TYPE_PUNNING
133 #ifndef ZT_NO_UNALIGNED_ACCESS
134 #define ZT_NO_UNALIGNED_ACCESS 1
135 #endif
136 #endif
137 
138 // Assume little endian if not defined
139 #if (defined(__APPLE__) || defined(__WINDOWS__)) && (!defined(__BYTE_ORDER))
140 #undef __BYTE_ORDER
141 #undef __LITTLE_ENDIAN
142 #undef __BIG_ENDIAN
143 #define __BIG_ENDIAN 4321
144 #define __LITTLE_ENDIAN 1234
145 #define __BYTE_ORDER 1234
146 #endif
147 
148 #ifdef __WINDOWS__
149 #define ZT_PATH_SEPARATOR '\\'
150 #define ZT_PATH_SEPARATOR_S "\\"
151 #define ZT_EOL_S "\r\n"
152 #else
153 #define ZT_PATH_SEPARATOR '/'
154 #define ZT_PATH_SEPARATOR_S "/"
155 #define ZT_EOL_S "\n"
156 #endif
157 
158 #ifndef __BYTE_ORDER
159 #include <endian.h>
160 #endif
161 
162 #if (defined(__GNUC__) && (__GNUC__ >= 3)) || (defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 800)) || defined(__clang__)
163 #ifndef likely
164 #define likely(x) __builtin_expect((x),1)
165 #endif
166 #ifndef unlikely
167 #define unlikely(x) __builtin_expect((x),0)
168 #endif
169 #else
170 #ifndef likely
171 #define likely(x) (x)
172 #endif
173 #ifndef unlikely
174 #define unlikely(x) (x)
175 #endif
176 #endif
177 
178 #ifdef __WINDOWS__
179 #define ZT_PACKED_STRUCT(D) __pragma(pack(push,1)) D __pragma(pack(pop))
180 #else
181 #define ZT_PACKED_STRUCT(D) D __attribute__((packed))
182 #endif
183 
184 /**
185  * Length of a ZeroTier address in bytes
186  */
187 #define ZT_ADDRESS_LENGTH 5
188 
189 /**
190  * Length of a hexadecimal ZeroTier address
191  */
192 #define ZT_ADDRESS_LENGTH_HEX 10
193 
194 /**
195  * Size of symmetric key (only the first 32 bits are used for some ciphers)
196  */
197 #define ZT_SYMMETRIC_KEY_SIZE 48
198 
199 /**
200  * Addresses beginning with this byte are reserved for the joy of in-band signaling
201  */
202 #define ZT_ADDRESS_RESERVED_PREFIX 0xff
203 
204 /**
205  * Default MTU used for Ethernet tap device
206  */
207 #define ZT_DEFAULT_MTU 2800
208 
209 /**
210  * Maximum number of packet fragments we'll support (protocol max: 16)
211  */
212 #define ZT_MAX_PACKET_FRAGMENTS 7
213 
214 /**
215  * Size of RX queue
216  */
217 #define ZT_RX_QUEUE_SIZE 32
218 
219 /**
220  * Size of TX queue
221  */
222 #define ZT_TX_QUEUE_SIZE 32
223 
224 /**
225  * Minimum delay between timer task checks to prevent thrashing
226  */
227 #define ZT_CORE_TIMER_TASK_GRANULARITY 60
228 
229 /**
230  * How often Topology::clean() and Network::clean() and similar are called, in ms
231  */
232 #define ZT_HOUSEKEEPING_PERIOD 30000
233 
234 /**
235  * Delay between WHOIS retries in ms
236  */
237 #define ZT_WHOIS_RETRY_DELAY 500
238 
239 /**
240  * Transmit queue entry timeout
241  */
242 #define ZT_TRANSMIT_QUEUE_TIMEOUT 5000
243 
244 /**
245  * Receive queue entry timeout
246  */
247 #define ZT_RECEIVE_QUEUE_TIMEOUT 5000
248 
249 /**
250  * Maximum number of ZT hops allowed (this is not IP hops/TTL)
251  *
252  * The protocol allows up to 7, but we limit it to something smaller.
253  */
254 #define ZT_RELAY_MAX_HOPS 3
255 
256 /**
257  * Expire time for multicast 'likes' and indirect multicast memberships in ms
258  */
259 #define ZT_MULTICAST_LIKE_EXPIRE 600000
260 
261 /**
262  * Period for multicast LIKE announcements
263  */
264 #define ZT_MULTICAST_ANNOUNCE_PERIOD 60000
265 
266 /**
267  * Delay between explicit MULTICAST_GATHER requests for a given multicast channel
268  */
269 #define ZT_MULTICAST_EXPLICIT_GATHER_DELAY (ZT_MULTICAST_LIKE_EXPIRE / 10)
270 
271 /**
272  * Timeout for outgoing multicasts
273  *
274  * This is how long we wait for explicit or implicit gather results.
275  */
276 #define ZT_MULTICAST_TRANSMIT_TIMEOUT 5000
277 
278 /**
279  * Delay between checks of peer pings, etc., and also related housekeeping tasks
280  */
281 #define ZT_PING_CHECK_INVERVAL 5000
282 
283 /**
284  * How often the local.conf file is checked for changes (service, should be moved there)
285  */
286 #define ZT_LOCAL_CONF_FILE_CHECK_INTERVAL 10000
287 
288 /**
289  * How frequently to send heartbeats over in-use paths
290  */
291 #define ZT_PATH_HEARTBEAT_PERIOD 14000
292 
293 /**
294  * Do not accept HELLOs over a given path more often than this
295  */
296 #define ZT_PATH_HELLO_RATE_LIMIT 1000
297 
298 /**
299  * Delay between full-fledge pings of directly connected peers
300  */
301 #define ZT_PEER_PING_PERIOD 60000
302 
303 /**
304  * Paths are considered expired if they have not sent us a real packet in this long
305  */
306 #define ZT_PEER_PATH_EXPIRATION ((ZT_PEER_PING_PERIOD * 4) + 3000)
307 
308 /**
309  * How often to retry expired paths that we're still remembering
310  */
311 #define ZT_PEER_EXPIRED_PATH_TRIAL_PERIOD (ZT_PEER_PING_PERIOD * 10)
312 
313 /**
314  * Outgoing packets are only used for QoS/ACK statistical sampling if their
315  * packet ID is divisible by this integer. This is to provide a mechanism for
316  * both peers to agree on which packets need special treatment without having
317  * to exchange information. Changing this value would be a breaking change and
318  * would necessitate a protocol version upgrade. Since each incoming and
319  * outgoing packet ID is checked against this value its evaluation is of the
320  * form:
321  *
322  * (id & (divisor - 1)) == 0, thus the divisor must be a power of 2.
323  *
324  * This value is set at (16) so that given a normally-distributed RNG output
325  * we will sample 1/16th (or ~6.25%) of packets.
326  */
327 #define ZT_QOS_ACK_DIVISOR 0x2
328 
329 /**
330  * Time horizon for VERB_QOS_MEASUREMENT and VERB_ACK packet processing cutoff
331  */
332 #define ZT_QOS_ACK_CUTOFF_TIME 30000
333 
334 /**
335  * Maximum number of VERB_QOS_MEASUREMENT and VERB_ACK packets allowed to be
336  * processed within cutoff time. Separate totals are kept for each type but
337  * the limit is the same for both.
338  *
339  * This limits how often this peer will compute statistical estimates
340  * of various QoS measures from a VERB_QOS_MEASUREMENT or VERB_ACK packets to
341  * CUTOFF_LIMIT times per CUTOFF_TIME milliseconds per peer to prevent
342  * this from being useful for DOS amplification attacks.
343  */
344 #define ZT_QOS_ACK_CUTOFF_LIMIT 128
345 
346 /**
347  * Minimum acceptable size for a VERB_QOS_MEASUREMENT packet
348  */
349 #define ZT_QOS_MIN_PACKET_SIZE (8 + 1)
350 
351 /**
352  * Maximum acceptable size for a VERB_QOS_MEASUREMENT packet
353  */
354 #define ZT_QOS_MAX_PACKET_SIZE 1400
355 
356 /**
357  * How many ID:sojourn time pairs are in a single QoS packet
358  */
359 #define ZT_QOS_TABLE_SIZE ((ZT_QOS_MAX_PACKET_SIZE * 8) / (64 + 16))
360 
361 /**
362  * Maximum number of outgoing packets we monitor for QoS information
363  */
364 #define ZT_QOS_MAX_OUTSTANDING_RECORDS (1024 * 16)
365 
366 /**
367  * Interval used for rate-limiting the computation of path quality estimates.
368  */
369 #define ZT_QOS_COMPUTE_INTERVAL 1000
370 
371 /**
372  * Number of samples to consider when processing real-time path statistics
373  */
374 #define ZT_QOS_SHORTTERM_SAMPLE_WIN_SIZE 32
375 
376 /**
377  * Max allowable time spent in any queue (in ms)
378  */
379 #define ZT_AQM_TARGET 5
380 
381 /**
382  * Time period where the time spent in the queue by a packet should fall below.
383  * target at least once. (in ms)
384  */
385 #define ZT_AQM_INTERVAL 100
386 
387 /**
388  * The number of bytes that each queue is allowed to send during each DRR cycle.
389  * This approximates a single-byte-based fairness queuing scheme.
390  */
391 #define ZT_AQM_QUANTUM ZT_DEFAULT_MTU
392 
393 /**
394  * The maximum total number of packets that can be queued among all
395  * active/inactive, old/new queues.
396  */
397 #define ZT_AQM_MAX_ENQUEUED_PACKETS 1024
398 
399 /**
400  * Number of QoS queues (buckets)
401  */
402 #define ZT_AQM_NUM_BUCKETS 9
403 
404 /**
405  * All unspecified traffic is put in this bucket. Anything in a bucket with a
406  * smaller value is de-prioritized. Anything in a bucket with a higher value is
407  prioritized over other traffic.
408  */
409 #define ZT_AQM_DEFAULT_BUCKET 0
410 
411 /**
412  * Timeout for overall peer activity (measured from last receive)
413  */
414 #ifndef ZT_SDK
415 #define ZT_PEER_ACTIVITY_TIMEOUT 500000
416 #else
417 #define ZT_PEER_ACTIVITY_TIMEOUT 30000
418 #endif
419 
420 /**
421  * General rate limit timeout for multiple packet types (HELLO, etc.)
422  */
423 #define ZT_PEER_GENERAL_INBOUND_RATE_LIMIT 500
424 
425 /**
426  * General limit for max RTT for requests over the network
427  */
428 #define ZT_GENERAL_RTT_LIMIT 5000
429 
430 /**
431  * Delay between requests for updated network autoconf information
432  *
433  * Don't lengthen this as it affects things like QoS / uptime monitoring
434  * via ZeroTier Central. This is the heartbeat, basically.
435  */
436 #define ZT_NETWORK_AUTOCONF_DELAY 60000
437 
438 /**
439  * Minimum interval between attempts by relays to unite peers
440  *
441  * When a relay gets a packet destined for another peer, it sends both peers
442  * a RENDEZVOUS message no more than this often. This instructs the peers
443  * to attempt NAT-t and gives each the other's corresponding IP:port pair.
444  */
445 #define ZT_MIN_UNITE_INTERVAL 30000
446 
447 /**
448  * How often should peers try memorized or statically defined paths?
449  */
450 #define ZT_TRY_MEMORIZED_PATH_INTERVAL 30000
451 
452 /**
453  * Sanity limit on maximum bridge routes
454  *
455  * If the number of bridge routes exceeds this, we cull routes from the
456  * bridges with the most MACs behind them until it doesn't. This is a
457  * sanity limit to prevent memory-filling DOS attacks, nothing more. No
458  * physical LAN has anywhere even close to this many nodes. Note that this
459  * does not limit the size of ZT virtual LANs, only bridge routing.
460  */
461 #define ZT_MAX_BRIDGE_ROUTES 67108864
462 
463 /**
464  * If there is no known L2 bridging route, spam to up to this many active bridges
465  */
466 #define ZT_MAX_BRIDGE_SPAM 32
467 
468 /**
469  * Interval between direct path pushes in milliseconds
470  */
471 #define ZT_DIRECT_PATH_PUSH_INTERVAL 15000
472 
473 /**
474  * Interval between direct path pushes in milliseconds if we already have a path
475  */
476 #define ZT_DIRECT_PATH_PUSH_INTERVAL_HAVEPATH 120000
477 
478 /**
479  * Time horizon for push direct paths cutoff
480  */
481 #define ZT_PUSH_DIRECT_PATHS_CUTOFF_TIME 30000
482 
483 /**
484  * Drainage constants for VERB_ECHO rate-limiters
485  */
486 #define ZT_ECHO_CUTOFF_LIMIT ((1000 / ZT_CORE_TIMER_TASK_GRANULARITY) * ZT_MAX_PEER_NETWORK_PATHS)
487 #define ZT_ECHO_DRAINAGE_DIVISOR (1000 / ZT_ECHO_CUTOFF_LIMIT)
488 
489 /**
490  * Drainage constants for VERB_QOS rate-limiters
491  */
492 #define ZT_QOS_CUTOFF_LIMIT ((1000 / ZT_CORE_TIMER_TASK_GRANULARITY) * ZT_MAX_PEER_NETWORK_PATHS)
493 #define ZT_QOS_DRAINAGE_DIVISOR (1000 / ZT_QOS_CUTOFF_LIMIT)
494 
495 /**
496  * Drainage constants for VERB_ACK rate-limiters
497  */
498 #define ZT_ACK_CUTOFF_LIMIT 128
499 #define ZT_ACK_DRAINAGE_DIVISOR (1000 / ZT_ACK_CUTOFF_LIMIT)
500 
501 #define ZT_BOND_DEFAULT_REFRCTORY_PERIOD 8000
502 #define ZT_BOND_MAX_REFRACTORY_PERIOD 600000
503 
504 /**
505  * Maximum number of direct path pushes within cutoff time
506  *
507  * This limits response to PUSH_DIRECT_PATHS to CUTOFF_LIMIT responses
508  * per CUTOFF_TIME milliseconds per peer to prevent this from being
509  * useful for DOS amplification attacks.
510  */
511 #define ZT_PUSH_DIRECT_PATHS_CUTOFF_LIMIT 8
512 
513 /**
514  * Maximum number of paths per IP scope (e.g. global, link-local) and family (e.g. v4/v6)
515  */
516 #define ZT_PUSH_DIRECT_PATHS_MAX_PER_SCOPE_AND_FAMILY 8
517 
518 /**
519  * Time horizon for VERB_NETWORK_CREDENTIALS cutoff
520  */
521 #define ZT_PEER_CREDENTIALS_CUTOFF_TIME 60000
522 
523 /**
524  * Maximum number of VERB_NETWORK_CREDENTIALS within cutoff time
525  */
526 #define ZT_PEER_CREDEITIALS_CUTOFF_LIMIT 15
527 
528 /**
529  * WHOIS rate limit (we allow these to be pretty fast)
530  */
531 #define ZT_PEER_WHOIS_RATE_LIMIT 100
532 
533 /**
534  * General rate limit for other kinds of rate-limited packets (HELLO, credential request, etc.) both inbound and outbound
535  */
536 #define ZT_PEER_GENERAL_RATE_LIMIT 1000
537 
538 
539 /**
540  * Minimum allowed amount of time between flow/path optimizations (anti-flapping)
541  */
542 #define ZT_BOND_OPTIMIZE_INTERVAL 15000
543 
544 /**
545  * Maximum number of flows allowed before we start forcibly forgetting old ones
546  */
547 #define ZT_FLOW_MAX_COUNT (1024 * 64)
548 
549 /**
550  * How often we emit a bond summary for each bond
551  */
552 #define ZT_BOND_STATUS_INTERVAL 30000
553 
554 /**
555  * How long before we consider a path to be dead in the general sense. This is
556  * used while searching for default or alternative paths to try in the absence
557  * of direct guidance from the user or a selection policy.
558  */
559 #define ZT_BOND_FAILOVER_DEFAULT_INTERVAL 5000
560 
561 /**
562  * Anything below this value gets into thrashing territory since we divide
563  * this value by ZT_BOND_ECHOS_PER_FAILOVER_INTERVAL to send ECHOs often.
564  */
565 #define ZT_BOND_FAILOVER_MIN_INTERVAL 250
566 
567 /**
568  * How many times per failover interval that an ECHO is sent. This should be
569  * at least 2. Anything more then 4 starts to increase overhead significantly.
570  */
571 #define ZT_BOND_ECHOS_PER_FAILOVER_INTERVAL 4
572 
573 /**
574  * A defensive timer to prevent path quality metrics from being
575  * processed too often.
576  */
577 #define ZT_BOND_BACKGROUND_TASK_MIN_INTERVAL ZT_CORE_TIMER_TASK_GRANULARITY
578 
579 /**
580  * How often a bonding policy's background tasks are processed,
581  * some need more frequent attention than others.
582  */
583 #define ZT_BOND_ACTIVE_BACKUP_CHECK_INTERVAL ZT_CORE_TIMER_TASK_GRANULARITY
584 
585 /**
586  * Time horizon for path negotiation paths cutoff
587  */
588 #define ZT_PATH_NEGOTIATION_CUTOFF_TIME 60000
589 
590 /**
591  * Maximum number of path negotiations within cutoff time
592  *
593  * This limits response to PATH_NEGOTIATION to CUTOFF_LIMIT responses
594  * per CUTOFF_TIME milliseconds per peer to prevent this from being
595  * useful for DOS amplification attacks.
596  */
597 #define ZT_PATH_NEGOTIATION_CUTOFF_LIMIT 8
598 
599 /**
600  * How many times a peer will attempt to petition another peer to synchronize its
601  * traffic to the same path before giving up and surrendering to the other peer's preference.
602  */
603 #define ZT_PATH_NEGOTIATION_TRY_COUNT 3
604 
605 /**
606  * How much greater the quality of a path should be before an
607  * optimization procedure triggers a switch.
608  */
609 #define ZT_BOND_ACTIVE_BACKUP_OPTIMIZE_MIN_THRESHOLD 0.10
610 
611 /**
612  * Artificially inflates the failover score for paths which meet
613  * certain non-performance-related policy ranking criteria.
614  */
615 #define ZT_BOND_FAILOVER_HANDICAP_PREFERRED  500
616 #define ZT_BOND_FAILOVER_HANDICAP_PRIMARY    1000
617 #define ZT_BOND_FAILOVER_HANDICAP_NEGOTIATED 5000
618 
619 /**
620  * An indicator that no flow is to be associated with the given packet
621  */
622 #define ZT_QOS_NO_FLOW -1
623 
624 /**
625  * Don't do expensive identity validation more often than this
626  *
627  * IPv4 and IPv6 address prefixes are hashed down to 14-bit (0-16383) integers
628  * using the first 24 bits for IPv4 or the first 48 bits for IPv6. These are
629  * then rate limited to one identity validation per this often milliseconds.
630  */
631 #if (defined(__amd64) || defined(__amd64__) || defined(__x86_64) || defined(__x86_64__) || defined(__AMD64) || defined(__AMD64__) || defined(_M_X64) || defined(_M_AMD64))
632 // AMD64 machines can do anywhere from one every 50ms to one every 10ms. This provides plenty of margin.
633 #define ZT_IDENTITY_VALIDATION_SOURCE_RATE_LIMIT 2000
634 #else
635 #if (defined(__i386__) || defined(__i486__) || defined(__i586__) || defined(__i686__) || defined(_M_IX86) || defined(_X86_) || defined(__I86__))
636 // 32-bit Intel machines usually average about one every 100ms
637 #define ZT_IDENTITY_VALIDATION_SOURCE_RATE_LIMIT 5000
638 #else
639 // This provides a safe margin for ARM, MIPS, etc. that usually average one every 250-400ms
640 #define ZT_IDENTITY_VALIDATION_SOURCE_RATE_LIMIT 10000
641 #endif
642 #endif
643 
644 /**
645  * 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?
646  */
647 #define ZT_TRUST_EXPIRATION 600000
648 
649 /**
650  * Desired buffer size for UDP sockets (used in service and osdep but defined here)
651  */
652 #define ZT_UDP_DESIRED_BUF_SIZE 1048576
653 
654 /**
655  * Desired / recommended min stack size for threads (used on some platforms to reset thread stack size)
656  */
657 #define ZT_THREAD_MIN_STACK_SIZE 1048576
658 
659 // Exceptions thrown in core ZT code
660 #define ZT_EXCEPTION_OUT_OF_BOUNDS 100
661 #define ZT_EXCEPTION_OUT_OF_MEMORY 101
662 #define ZT_EXCEPTION_PRIVATE_KEY_REQUIRED 102
663 #define ZT_EXCEPTION_INVALID_ARGUMENT 103
664 #define ZT_EXCEPTION_INVALID_SERIALIZED_DATA_INVALID_TYPE 200
665 #define ZT_EXCEPTION_INVALID_SERIALIZED_DATA_OVERFLOW 201
666 #define ZT_EXCEPTION_INVALID_SERIALIZED_DATA_INVALID_CRYPTOGRAPHIC_TOKEN 202
667 #define ZT_EXCEPTION_INVALID_SERIALIZED_DATA_BAD_ENCODING 203
668 
669 #endif
670