or.h 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084
  1. /* Copyright (c) 2001 Matej Pfajfar.
  2. * Copyright (c) 2001-2004, Roger Dingledine.
  3. * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
  4. * Copyright (c) 2007-2018, The Tor Project, Inc. */
  5. /* See LICENSE for licensing information */
  6. /**
  7. * \file or.h
  8. * \brief Master header file for Tor-specific functionality.
  9. **/
  10. #ifndef TOR_OR_H
  11. #define TOR_OR_H
  12. #include "orconfig.h"
  13. #include "lib/cc/torint.h"
  14. #ifdef HAVE_SIGNAL_H
  15. #include <signal.h>
  16. #endif
  17. #ifdef HAVE_TIME_H
  18. #include <time.h>
  19. #endif
  20. #include "lib/arch/bytes.h"
  21. #include "lib/cc/compat_compiler.h"
  22. #include "lib/cc/torint.h"
  23. #include "lib/container/map.h"
  24. #include "lib/container/smartlist.h"
  25. #include "lib/crypt_ops/crypto.h"
  26. #include "lib/ctime/di_ops.h"
  27. #include "lib/defs/dh_sizes.h"
  28. #include "lib/encoding/binascii.h"
  29. #include "lib/encoding/cstring.h"
  30. #include "lib/encoding/time_fmt.h"
  31. #include "lib/err/torerr.h"
  32. #include "lib/fs/dir.h"
  33. #include "lib/fs/files.h"
  34. #include "lib/fs/mmap.h"
  35. #include "lib/fs/path.h"
  36. #include "lib/fs/userdb.h"
  37. #include "lib/intmath/addsub.h"
  38. #include "lib/intmath/bits.h"
  39. #include "lib/intmath/cmp.h"
  40. #include "lib/intmath/logic.h"
  41. #include "lib/intmath/muldiv.h"
  42. #include "lib/log/escape.h"
  43. #include "lib/log/ratelim.h"
  44. #include "lib/log/util_bug.h"
  45. #include "lib/malloc/util_malloc.h"
  46. #include "lib/net/address.h"
  47. #include "lib/net/ipv4.h"
  48. #include "lib/net/ipv6.h"
  49. #include "lib/net/resolve.h"
  50. #include "lib/net/socket.h"
  51. #include "lib/string/compat_ctype.h"
  52. #include "lib/string/compat_string.h"
  53. #include "lib/string/parse_int.h"
  54. #include "lib/string/printf.h"
  55. #include "lib/string/scanf.h"
  56. #include "lib/string/util_string.h"
  57. #include "lib/testsupport/testsupport.h"
  58. #include "lib/thread/threads.h"
  59. #include "lib/time/compat_time.h"
  60. #include "lib/wallclock/approx_time.h"
  61. #include "lib/wallclock/timeval.h"
  62. #include "ht.h"
  63. // These, more than other includes, are for keeping the other struct
  64. // definitions working. We should remove them when we minimize our includes.
  65. #include "core/or/entry_port_cfg_st.h"
  66. struct ed25519_public_key_t;
  67. struct curve25519_public_key_t;
  68. /* These signals are defined to help handle_control_signal work.
  69. */
  70. #ifndef SIGHUP
  71. #define SIGHUP 1
  72. #endif
  73. #ifndef SIGINT
  74. #define SIGINT 2
  75. #endif
  76. #ifndef SIGUSR1
  77. #define SIGUSR1 10
  78. #endif
  79. #ifndef SIGUSR2
  80. #define SIGUSR2 12
  81. #endif
  82. #ifndef SIGTERM
  83. #define SIGTERM 15
  84. #endif
  85. /* Controller signals start at a high number so we don't
  86. * conflict with system-defined signals. */
  87. #define SIGNEWNYM 129
  88. #define SIGCLEARDNSCACHE 130
  89. #define SIGHEARTBEAT 131
  90. #if (SIZEOF_CELL_T != 0)
  91. /* On Irix, stdlib.h defines a cell_t type, so we need to make sure
  92. * that our stuff always calls cell_t something different. */
  93. #define cell_t tor_cell_t
  94. #endif
  95. /** Helper macro: Given a pointer to to.base_, of type from*, return &to. */
  96. #define DOWNCAST(to, ptr) ((to*)SUBTYPE_P(ptr, to, base_))
  97. /** Length of longest allowable configured nickname. */
  98. #define MAX_NICKNAME_LEN 19
  99. /** Length of a router identity encoded as a hexadecimal digest, plus
  100. * possible dollar sign. */
  101. #define MAX_HEX_NICKNAME_LEN (HEX_DIGEST_LEN+1)
  102. /** Maximum length of verbose router identifier: dollar sign, hex ID digest,
  103. * equal sign or tilde, nickname. */
  104. #define MAX_VERBOSE_NICKNAME_LEN (1+HEX_DIGEST_LEN+1+MAX_NICKNAME_LEN)
  105. /** For HTTP parsing: Maximum number of bytes we'll accept in the headers
  106. * of an HTTP request or response. */
  107. #define MAX_HEADERS_SIZE 50000
  108. /** Maximum size, in bytes, of a single router descriptor uploaded to us
  109. * as a directory authority. Caches and clients fetch whatever descriptors
  110. * the authorities tell them to fetch, and don't care about size. */
  111. #define MAX_DESCRIPTOR_UPLOAD_SIZE 20000
  112. /** Maximum size of a single extrainfo document, as above. */
  113. #define MAX_EXTRAINFO_UPLOAD_SIZE 50000
  114. /** Minimum lifetime for an onion key in days. */
  115. #define MIN_ONION_KEY_LIFETIME_DAYS (1)
  116. /** Maximum lifetime for an onion key in days. */
  117. #define MAX_ONION_KEY_LIFETIME_DAYS (90)
  118. /** Default lifetime for an onion key in days. */
  119. #define DEFAULT_ONION_KEY_LIFETIME_DAYS (28)
  120. /** Minimum grace period for acceptance of an onion key in days.
  121. * The maximum value is defined in proposal #274 as being the current network
  122. * consensus parameter for "onion-key-rotation-days". */
  123. #define MIN_ONION_KEY_GRACE_PERIOD_DAYS (1)
  124. /** Default grace period for acceptance of an onion key in days. */
  125. #define DEFAULT_ONION_KEY_GRACE_PERIOD_DAYS (7)
  126. /** How often we should check the network consensus if it is time to rotate or
  127. * expire onion keys. */
  128. #define ONION_KEY_CONSENSUS_CHECK_INTERVAL (60*60)
  129. /** How often do we rotate TLS contexts? */
  130. #define MAX_SSL_KEY_LIFETIME_INTERNAL (2*60*60)
  131. /** How old do we allow a router to get before removing it
  132. * from the router list? In seconds. */
  133. #define ROUTER_MAX_AGE (60*60*48)
  134. /** How old can a router get before we (as a server) will no longer
  135. * consider it live? In seconds. */
  136. #define ROUTER_MAX_AGE_TO_PUBLISH (60*60*24)
  137. /** How old do we let a saved descriptor get before force-removing it? */
  138. #define OLD_ROUTER_DESC_MAX_AGE (60*60*24*5)
  139. /* Proxy client types */
  140. #define PROXY_NONE 0
  141. #define PROXY_CONNECT 1
  142. #define PROXY_SOCKS4 2
  143. #define PROXY_SOCKS5 3
  144. /* !!!! If there is ever a PROXY_* type over 3, we must grow the proxy_type
  145. * field in or_connection_t */
  146. /* Pluggable transport proxy type. Don't use this in or_connection_t,
  147. * instead use the actual underlying proxy type (see above). */
  148. #define PROXY_PLUGGABLE 4
  149. /** How many circuits do we want simultaneously in-progress to handle
  150. * a given stream? */
  151. #define MIN_CIRCUITS_HANDLING_STREAM 2
  152. /* These RELAY_COMMAND constants define values for relay cell commands, and
  153. * must match those defined in tor-spec.txt. */
  154. #define RELAY_COMMAND_BEGIN 1
  155. #define RELAY_COMMAND_DATA 2
  156. #define RELAY_COMMAND_END 3
  157. #define RELAY_COMMAND_CONNECTED 4
  158. #define RELAY_COMMAND_SENDME 5
  159. #define RELAY_COMMAND_EXTEND 6
  160. #define RELAY_COMMAND_EXTENDED 7
  161. #define RELAY_COMMAND_TRUNCATE 8
  162. #define RELAY_COMMAND_TRUNCATED 9
  163. #define RELAY_COMMAND_DROP 10
  164. #define RELAY_COMMAND_RESOLVE 11
  165. #define RELAY_COMMAND_RESOLVED 12
  166. #define RELAY_COMMAND_BEGIN_DIR 13
  167. #define RELAY_COMMAND_EXTEND2 14
  168. #define RELAY_COMMAND_EXTENDED2 15
  169. #define RELAY_COMMAND_ESTABLISH_INTRO 32
  170. #define RELAY_COMMAND_ESTABLISH_RENDEZVOUS 33
  171. #define RELAY_COMMAND_INTRODUCE1 34
  172. #define RELAY_COMMAND_INTRODUCE2 35
  173. #define RELAY_COMMAND_RENDEZVOUS1 36
  174. #define RELAY_COMMAND_RENDEZVOUS2 37
  175. #define RELAY_COMMAND_INTRO_ESTABLISHED 38
  176. #define RELAY_COMMAND_RENDEZVOUS_ESTABLISHED 39
  177. #define RELAY_COMMAND_INTRODUCE_ACK 40
  178. /* Reasons why an OR connection is closed. */
  179. #define END_OR_CONN_REASON_DONE 1
  180. #define END_OR_CONN_REASON_REFUSED 2 /* connection refused */
  181. #define END_OR_CONN_REASON_OR_IDENTITY 3
  182. #define END_OR_CONN_REASON_CONNRESET 4 /* connection reset by peer */
  183. #define END_OR_CONN_REASON_TIMEOUT 5
  184. #define END_OR_CONN_REASON_NO_ROUTE 6 /* no route to host/net */
  185. #define END_OR_CONN_REASON_IO_ERROR 7 /* read/write error */
  186. #define END_OR_CONN_REASON_RESOURCE_LIMIT 8 /* sockets, buffers, etc */
  187. #define END_OR_CONN_REASON_PT_MISSING 9 /* PT failed or not available */
  188. #define END_OR_CONN_REASON_MISC 10
  189. /* Reasons why we (or a remote OR) might close a stream. See tor-spec.txt for
  190. * documentation of these. The values must match. */
  191. #define END_STREAM_REASON_MISC 1
  192. #define END_STREAM_REASON_RESOLVEFAILED 2
  193. #define END_STREAM_REASON_CONNECTREFUSED 3
  194. #define END_STREAM_REASON_EXITPOLICY 4
  195. #define END_STREAM_REASON_DESTROY 5
  196. #define END_STREAM_REASON_DONE 6
  197. #define END_STREAM_REASON_TIMEOUT 7
  198. #define END_STREAM_REASON_NOROUTE 8
  199. #define END_STREAM_REASON_HIBERNATING 9
  200. #define END_STREAM_REASON_INTERNAL 10
  201. #define END_STREAM_REASON_RESOURCELIMIT 11
  202. #define END_STREAM_REASON_CONNRESET 12
  203. #define END_STREAM_REASON_TORPROTOCOL 13
  204. #define END_STREAM_REASON_NOTDIRECTORY 14
  205. #define END_STREAM_REASON_ENTRYPOLICY 15
  206. /* These high-numbered end reasons are not part of the official spec,
  207. * and are not intended to be put in relay end cells. They are here
  208. * to be more informative when sending back socks replies to the
  209. * application. */
  210. /* XXXX 256 is no longer used; feel free to reuse it. */
  211. /** We were unable to attach the connection to any circuit at all. */
  212. /* XXXX the ways we use this one don't make a lot of sense. */
  213. #define END_STREAM_REASON_CANT_ATTACH 257
  214. /** We can't connect to any directories at all, so we killed our streams
  215. * before they can time out. */
  216. #define END_STREAM_REASON_NET_UNREACHABLE 258
  217. /** This is a SOCKS connection, and the client used (or misused) the SOCKS
  218. * protocol in a way we couldn't handle. */
  219. #define END_STREAM_REASON_SOCKSPROTOCOL 259
  220. /** This is a transparent proxy connection, but we can't extract the original
  221. * target address:port. */
  222. #define END_STREAM_REASON_CANT_FETCH_ORIG_DEST 260
  223. /** This is a connection on the NATD port, and the destination IP:Port was
  224. * either ill-formed or out-of-range. */
  225. #define END_STREAM_REASON_INVALID_NATD_DEST 261
  226. /** The target address is in a private network (like 127.0.0.1 or 10.0.0.1);
  227. * you don't want to do that over a randomly chosen exit */
  228. #define END_STREAM_REASON_PRIVATE_ADDR 262
  229. /** This is an HTTP tunnel connection and the client used or misused HTTP in a
  230. * way we can't handle.
  231. */
  232. #define END_STREAM_REASON_HTTPPROTOCOL 263
  233. /** Bitwise-and this value with endreason to mask out all flags. */
  234. #define END_STREAM_REASON_MASK 511
  235. /** Bitwise-or this with the argument to control_event_stream_status
  236. * to indicate that the reason came from an END cell. */
  237. #define END_STREAM_REASON_FLAG_REMOTE 512
  238. /** Bitwise-or this with the argument to control_event_stream_status
  239. * to indicate that we already sent a CLOSED stream event. */
  240. #define END_STREAM_REASON_FLAG_ALREADY_SENT_CLOSED 1024
  241. /** Bitwise-or this with endreason to indicate that we already sent
  242. * a socks reply, and no further reply needs to be sent from
  243. * connection_mark_unattached_ap(). */
  244. #define END_STREAM_REASON_FLAG_ALREADY_SOCKS_REPLIED 2048
  245. /* 'type' values to use in RESOLVED cells. Specified in tor-spec.txt. */
  246. #define RESOLVED_TYPE_HOSTNAME 0
  247. #define RESOLVED_TYPE_IPV4 4
  248. #define RESOLVED_TYPE_IPV6 6
  249. #define RESOLVED_TYPE_ERROR_TRANSIENT 0xF0
  250. #define RESOLVED_TYPE_ERROR 0xF1
  251. /* Negative reasons are internal: we never send them in a DESTROY or TRUNCATE
  252. * call; they only go to the controller for tracking */
  253. /* Closing introduction point that were opened in parallel. */
  254. #define END_CIRC_REASON_IP_NOW_REDUNDANT -4
  255. /** Our post-timeout circuit time measurement period expired.
  256. * We must give up now */
  257. #define END_CIRC_REASON_MEASUREMENT_EXPIRED -3
  258. /** We couldn't build a path for this circuit. */
  259. #define END_CIRC_REASON_NOPATH -2
  260. /** Catch-all "other" reason for closing origin circuits. */
  261. #define END_CIRC_AT_ORIGIN -1
  262. /* Reasons why we (or a remote OR) might close a circuit. See tor-spec.txt
  263. * section 5.4 for documentation of these. */
  264. #define END_CIRC_REASON_MIN_ 0
  265. #define END_CIRC_REASON_NONE 0
  266. #define END_CIRC_REASON_TORPROTOCOL 1
  267. #define END_CIRC_REASON_INTERNAL 2
  268. #define END_CIRC_REASON_REQUESTED 3
  269. #define END_CIRC_REASON_HIBERNATING 4
  270. #define END_CIRC_REASON_RESOURCELIMIT 5
  271. #define END_CIRC_REASON_CONNECTFAILED 6
  272. #define END_CIRC_REASON_OR_IDENTITY 7
  273. #define END_CIRC_REASON_CHANNEL_CLOSED 8
  274. #define END_CIRC_REASON_FINISHED 9
  275. #define END_CIRC_REASON_TIMEOUT 10
  276. #define END_CIRC_REASON_DESTROYED 11
  277. #define END_CIRC_REASON_NOSUCHSERVICE 12
  278. #define END_CIRC_REASON_MAX_ 12
  279. /** Bitwise-OR this with the argument to circuit_mark_for_close() or
  280. * control_event_circuit_status() to indicate that the reason was
  281. * passed through from a destroy or truncate cell. */
  282. #define END_CIRC_REASON_FLAG_REMOTE 512
  283. /** Length of 'y' portion of 'y.onion' URL. */
  284. #define REND_SERVICE_ID_LEN_BASE32 16
  285. /** Length of 'y.onion' including '.onion' URL. */
  286. #define REND_SERVICE_ADDRESS_LEN (16+1+5)
  287. /** Length of a binary-encoded rendezvous service ID. */
  288. #define REND_SERVICE_ID_LEN 10
  289. /** Time period for which a v2 descriptor will be valid. */
  290. #define REND_TIME_PERIOD_V2_DESC_VALIDITY (24*60*60)
  291. /** Time period within which two sets of v2 descriptors will be uploaded in
  292. * parallel. */
  293. #define REND_TIME_PERIOD_OVERLAPPING_V2_DESCS (60*60)
  294. /** Number of non-consecutive replicas (i.e. distributed somewhere
  295. * in the ring) for a descriptor. */
  296. #define REND_NUMBER_OF_NON_CONSECUTIVE_REPLICAS 2
  297. /** Number of consecutive replicas for a descriptor. */
  298. #define REND_NUMBER_OF_CONSECUTIVE_REPLICAS 3
  299. /** Length of v2 descriptor ID (32 base32 chars = 160 bits). */
  300. #define REND_DESC_ID_V2_LEN_BASE32 BASE32_DIGEST_LEN
  301. /** Length of the base32-encoded secret ID part of versioned hidden service
  302. * descriptors. */
  303. #define REND_SECRET_ID_PART_LEN_BASE32 BASE32_DIGEST_LEN
  304. /** Length of the base32-encoded hash of an introduction point's
  305. * identity key. */
  306. #define REND_INTRO_POINT_ID_LEN_BASE32 BASE32_DIGEST_LEN
  307. /** Length of the descriptor cookie that is used for client authorization
  308. * to hidden services. */
  309. #define REND_DESC_COOKIE_LEN 16
  310. /** Length of the base64-encoded descriptor cookie that is used for
  311. * exchanging client authorization between hidden service and client. */
  312. #define REND_DESC_COOKIE_LEN_BASE64 22
  313. /** Length of client identifier in encrypted introduction points for hidden
  314. * service authorization type 'basic'. */
  315. #define REND_BASIC_AUTH_CLIENT_ID_LEN 4
  316. /** Multiple of the number of clients to which the real number of clients
  317. * is padded with fake clients for hidden service authorization type
  318. * 'basic'. */
  319. #define REND_BASIC_AUTH_CLIENT_MULTIPLE 16
  320. /** Length of client entry consisting of client identifier and encrypted
  321. * session key for hidden service authorization type 'basic'. */
  322. #define REND_BASIC_AUTH_CLIENT_ENTRY_LEN (REND_BASIC_AUTH_CLIENT_ID_LEN \
  323. + CIPHER_KEY_LEN)
  324. /** Maximum size of v2 hidden service descriptors. */
  325. #define REND_DESC_MAX_SIZE (20 * 1024)
  326. /** Legal characters for use in authorized client names for a hidden
  327. * service. */
  328. #define REND_LEGAL_CLIENTNAME_CHARACTERS \
  329. "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+-_"
  330. /** Maximum length of authorized client names for a hidden service. */
  331. #define REND_CLIENTNAME_MAX_LEN 16
  332. /** Length of the rendezvous cookie that is used to connect circuits at the
  333. * rendezvous point. */
  334. #define REND_COOKIE_LEN DIGEST_LEN
  335. /** Client authorization type that a hidden service performs. */
  336. typedef enum rend_auth_type_t {
  337. REND_NO_AUTH = 0,
  338. REND_BASIC_AUTH = 1,
  339. REND_STEALTH_AUTH = 2,
  340. } rend_auth_type_t;
  341. /** Client-side configuration of authorization for a hidden service. */
  342. typedef struct rend_service_authorization_t {
  343. uint8_t descriptor_cookie[REND_DESC_COOKIE_LEN];
  344. char onion_address[REND_SERVICE_ADDRESS_LEN+1];
  345. rend_auth_type_t auth_type;
  346. } rend_service_authorization_t;
  347. /** Client- and server-side data that is used for hidden service connection
  348. * establishment. Not all fields contain data depending on where this struct
  349. * is used. */
  350. typedef struct rend_data_t {
  351. /* Hidden service protocol version of this base object. */
  352. uint32_t version;
  353. /** List of HSDir fingerprints on which this request has been sent to. This
  354. * contains binary identity digest of the directory of size DIGEST_LEN. */
  355. smartlist_t *hsdirs_fp;
  356. /** Rendezvous cookie used by both, client and service. */
  357. char rend_cookie[REND_COOKIE_LEN];
  358. /** Number of streams associated with this rendezvous circuit. */
  359. int nr_streams;
  360. } rend_data_t;
  361. typedef struct rend_data_v2_t {
  362. /* Rendezvous base data. */
  363. rend_data_t base_;
  364. /** Onion address (without the .onion part) that a client requests. */
  365. char onion_address[REND_SERVICE_ID_LEN_BASE32+1];
  366. /** Descriptor ID for each replicas computed from the onion address. If
  367. * the onion address is empty, this array MUST be empty. We keep them so
  368. * we know when to purge our entry in the last hsdir request table. */
  369. char descriptor_id[REND_NUMBER_OF_NON_CONSECUTIVE_REPLICAS][DIGEST_LEN];
  370. /** (Optional) descriptor cookie that is used by a client. */
  371. char descriptor_cookie[REND_DESC_COOKIE_LEN];
  372. /** Authorization type for accessing a service used by a client. */
  373. rend_auth_type_t auth_type;
  374. /** Descriptor ID for a client request. The control port command HSFETCH
  375. * uses this. It's set if the descriptor query should only use this
  376. * descriptor ID. */
  377. char desc_id_fetch[DIGEST_LEN];
  378. /** Hash of the hidden service's PK used by a service. */
  379. char rend_pk_digest[DIGEST_LEN];
  380. } rend_data_v2_t;
  381. /* From a base rend_data_t object <b>d</d>, return the v2 object. */
  382. static inline
  383. rend_data_v2_t *TO_REND_DATA_V2(const rend_data_t *d)
  384. {
  385. tor_assert(d);
  386. tor_assert(d->version == 2);
  387. return DOWNCAST(rend_data_v2_t, d);
  388. }
  389. /* Stub because we can't include hs_ident.h. */
  390. struct hs_ident_edge_conn_t;
  391. struct hs_ident_dir_conn_t;
  392. struct hs_ident_circuit_t;
  393. typedef struct hsdir_index_t hsdir_index_t;
  394. /** Time interval for tracking replays of DH public keys received in
  395. * INTRODUCE2 cells. Used only to avoid launching multiple
  396. * simultaneous attempts to connect to the same rendezvous point. */
  397. #define REND_REPLAY_TIME_INTERVAL (5 * 60)
  398. /** Used to indicate which way a cell is going on a circuit. */
  399. typedef enum {
  400. CELL_DIRECTION_IN=1, /**< The cell is moving towards the origin. */
  401. CELL_DIRECTION_OUT=2, /**< The cell is moving away from the origin. */
  402. } cell_direction_t;
  403. /** Initial value for both sides of a circuit transmission window when the
  404. * circuit is initialized. Measured in cells. */
  405. #define CIRCWINDOW_START 1000
  406. #define CIRCWINDOW_START_MIN 100
  407. #define CIRCWINDOW_START_MAX 1000
  408. /** Amount to increment a circuit window when we get a circuit SENDME. */
  409. #define CIRCWINDOW_INCREMENT 100
  410. /** Initial value on both sides of a stream transmission window when the
  411. * stream is initialized. Measured in cells. */
  412. #define STREAMWINDOW_START 500
  413. #define STREAMWINDOW_START_MAX 500
  414. /** Amount to increment a stream window when we get a stream SENDME. */
  415. #define STREAMWINDOW_INCREMENT 50
  416. /** Maximum number of queued cells on a circuit for which we are the
  417. * midpoint before we give up and kill it. This must be >= circwindow
  418. * to avoid killing innocent circuits, and >= circwindow*2 to give
  419. * leaky-pipe a chance of working someday. The ORCIRC_MAX_MIDDLE_KILL_THRESH
  420. * ratio controls the margin of error between emitting a warning and
  421. * killing the circuit.
  422. */
  423. #define ORCIRC_MAX_MIDDLE_CELLS (CIRCWINDOW_START_MAX*2)
  424. /** Ratio of hard (circuit kill) to soft (warning) thresholds for the
  425. * ORCIRC_MAX_MIDDLE_CELLS tests.
  426. */
  427. #define ORCIRC_MAX_MIDDLE_KILL_THRESH (1.1f)
  428. /* Cell commands. These values are defined in tor-spec.txt. */
  429. #define CELL_PADDING 0
  430. #define CELL_CREATE 1
  431. #define CELL_CREATED 2
  432. #define CELL_RELAY 3
  433. #define CELL_DESTROY 4
  434. #define CELL_CREATE_FAST 5
  435. #define CELL_CREATED_FAST 6
  436. #define CELL_VERSIONS 7
  437. #define CELL_NETINFO 8
  438. #define CELL_RELAY_EARLY 9
  439. #define CELL_CREATE2 10
  440. #define CELL_CREATED2 11
  441. #define CELL_PADDING_NEGOTIATE 12
  442. #define CELL_VPADDING 128
  443. #define CELL_CERTS 129
  444. #define CELL_AUTH_CHALLENGE 130
  445. #define CELL_AUTHENTICATE 131
  446. #define CELL_AUTHORIZE 132
  447. #define CELL_COMMAND_MAX_ 132
  448. /** How long to test reachability before complaining to the user. */
  449. #define TIMEOUT_UNTIL_UNREACHABILITY_COMPLAINT (20*60)
  450. /** Legal characters in a nickname. */
  451. #define LEGAL_NICKNAME_CHARACTERS \
  452. "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
  453. /** Name to use in client TLS certificates if no nickname is given. Once
  454. * Tor 0.1.2.x is obsolete, we can remove this. */
  455. #define DEFAULT_CLIENT_NICKNAME "client"
  456. /** Name chosen by routers that don't configure nicknames */
  457. #define UNNAMED_ROUTER_NICKNAME "Unnamed"
  458. /** Number of bytes in a SOCKS4 header. */
  459. #define SOCKS4_NETWORK_LEN 8
  460. /*
  461. * Relay payload:
  462. * Relay command [1 byte]
  463. * Recognized [2 bytes]
  464. * Stream ID [2 bytes]
  465. * Partial SHA-1 [4 bytes]
  466. * Length [2 bytes]
  467. * Relay payload [498 bytes]
  468. */
  469. /** Number of bytes in a cell, minus cell header. */
  470. #define CELL_PAYLOAD_SIZE 509
  471. /** Number of bytes in a cell transmitted over the network, in the longest
  472. * form */
  473. #define CELL_MAX_NETWORK_SIZE 514
  474. /** Maximum length of a header on a variable-length cell. */
  475. #define VAR_CELL_MAX_HEADER_SIZE 7
  476. static int get_cell_network_size(int wide_circ_ids);
  477. static inline int get_cell_network_size(int wide_circ_ids)
  478. {
  479. return wide_circ_ids ? CELL_MAX_NETWORK_SIZE : CELL_MAX_NETWORK_SIZE - 2;
  480. }
  481. static int get_var_cell_header_size(int wide_circ_ids);
  482. static inline int get_var_cell_header_size(int wide_circ_ids)
  483. {
  484. return wide_circ_ids ? VAR_CELL_MAX_HEADER_SIZE :
  485. VAR_CELL_MAX_HEADER_SIZE - 2;
  486. }
  487. static int get_circ_id_size(int wide_circ_ids);
  488. static inline int get_circ_id_size(int wide_circ_ids)
  489. {
  490. return wide_circ_ids ? 4 : 2;
  491. }
  492. /** Number of bytes in a relay cell's header (not including general cell
  493. * header). */
  494. #define RELAY_HEADER_SIZE (1+2+2+4+2)
  495. /** Largest number of bytes that can fit in a relay cell payload. */
  496. #define RELAY_PAYLOAD_SIZE (CELL_PAYLOAD_SIZE-RELAY_HEADER_SIZE)
  497. /** Identifies a circuit on an or_connection */
  498. typedef uint32_t circid_t;
  499. /** Identifies a stream on a circuit */
  500. typedef uint16_t streamid_t;
  501. /* channel_t typedef; struct channel_s is in channel.h */
  502. typedef struct channel_s channel_t;
  503. /* channel_listener_t typedef; struct channel_listener_s is in channel.h */
  504. typedef struct channel_listener_s channel_listener_t;
  505. /* TLS channel stuff */
  506. typedef struct channel_tls_s channel_tls_t;
  507. /* circuitmux_t typedef; struct circuitmux_s is in circuitmux.h */
  508. typedef struct circuitmux_s circuitmux_t;
  509. typedef struct cell_t cell_t;
  510. typedef struct var_cell_t var_cell_t;
  511. typedef struct packed_cell_t packed_cell_t;
  512. typedef struct cell_queue_t cell_queue_t;
  513. typedef struct destroy_cell_t destroy_cell_t;
  514. typedef struct destroy_cell_queue_t destroy_cell_queue_t;
  515. typedef struct ext_or_cmd_t ext_or_cmd_t;
  516. /** Beginning of a RELAY cell payload. */
  517. typedef struct {
  518. uint8_t command; /**< The end-to-end relay command. */
  519. uint16_t recognized; /**< Used to tell whether cell is for us. */
  520. streamid_t stream_id; /**< Which stream is this cell associated with? */
  521. char integrity[4]; /**< Used to tell whether cell is corrupted. */
  522. uint16_t length; /**< How long is the payload body? */
  523. } relay_header_t;
  524. typedef struct socks_request_t socks_request_t;
  525. typedef struct entry_port_cfg_t entry_port_cfg_t;
  526. typedef struct server_port_cfg_t server_port_cfg_t;
  527. /** Minimum length of the random part of an AUTH_CHALLENGE cell. */
  528. #define OR_AUTH_CHALLENGE_LEN 32
  529. /**
  530. * @name Certificate types for CERTS cells.
  531. *
  532. * These values are defined by the protocol, and affect how an X509
  533. * certificate in a CERTS cell is interpreted and used.
  534. *
  535. * @{ */
  536. /** A certificate that authenticates a TLS link key. The subject key
  537. * must match the key used in the TLS handshake; it must be signed by
  538. * the identity key. */
  539. #define OR_CERT_TYPE_TLS_LINK 1
  540. /** A self-signed identity certificate. The subject key must be a
  541. * 1024-bit RSA key. */
  542. #define OR_CERT_TYPE_ID_1024 2
  543. /** A certificate that authenticates a key used in an AUTHENTICATE cell
  544. * in the v3 handshake. The subject key must be a 1024-bit RSA key; it
  545. * must be signed by the identity key */
  546. #define OR_CERT_TYPE_AUTH_1024 3
  547. /* DOCDOC */
  548. #define OR_CERT_TYPE_RSA_ED_CROSSCERT 7
  549. /**@}*/
  550. /** The first supported type of AUTHENTICATE cell. It contains
  551. * a bunch of structures signed with an RSA1024 key. The signed
  552. * structures include a HMAC using negotiated TLS secrets, and a digest
  553. * of all cells sent or received before the AUTHENTICATE cell (including
  554. * the random server-generated AUTH_CHALLENGE cell).
  555. */
  556. #define AUTHTYPE_RSA_SHA256_TLSSECRET 1
  557. /** As AUTHTYPE_RSA_SHA256_TLSSECRET, but instead of using the
  558. * negotiated TLS secrets, uses exported keying material from the TLS
  559. * session as described in RFC 5705.
  560. *
  561. * Not used by today's tors, since everything that supports this
  562. * also supports ED25519_SHA256_5705, which is better.
  563. **/
  564. #define AUTHTYPE_RSA_SHA256_RFC5705 2
  565. /** As AUTHTYPE_RSA_SHA256_RFC5705, but uses an Ed25519 identity key to
  566. * authenticate. */
  567. #define AUTHTYPE_ED25519_SHA256_RFC5705 3
  568. /*
  569. * NOTE: authchallenge_type_is_better() relies on these AUTHTYPE codes
  570. * being sorted in order of preference. If we someday add one with
  571. * a higher numerical value that we don't like as much, we should revise
  572. * authchallenge_type_is_better().
  573. */
  574. /** The length of the part of the AUTHENTICATE cell body that the client and
  575. * server can generate independently (when using RSA_SHA256_TLSSECRET). It
  576. * contains everything except the client's timestamp, the client's randomly
  577. * generated nonce, and the signature. */
  578. #define V3_AUTH_FIXED_PART_LEN (8+(32*6))
  579. /** The length of the part of the AUTHENTICATE cell body that the client
  580. * signs. */
  581. #define V3_AUTH_BODY_LEN (V3_AUTH_FIXED_PART_LEN + 8 + 16)
  582. typedef struct or_handshake_certs_t or_handshake_certs_t;
  583. typedef struct or_handshake_state_t or_handshake_state_t;
  584. /** Length of Extended ORPort connection identifier. */
  585. #define EXT_OR_CONN_ID_LEN DIGEST_LEN /* 20 */
  586. /*
  587. * OR_CONN_HIGHWATER and OR_CONN_LOWWATER moved from connection_or.c so
  588. * channeltls.c can see them too.
  589. */
  590. /** When adding cells to an OR connection's outbuf, keep adding until the
  591. * outbuf is at least this long, or we run out of cells. */
  592. #define OR_CONN_HIGHWATER (32*1024)
  593. /** Add cells to an OR connection's outbuf whenever the outbuf's data length
  594. * drops below this size. */
  595. #define OR_CONN_LOWWATER (16*1024)
  596. typedef struct connection_t connection_t;
  597. typedef struct control_connection_t control_connection_t;
  598. typedef struct dir_connection_t dir_connection_t;
  599. typedef struct edge_connection_t edge_connection_t;
  600. typedef struct entry_connection_t entry_connection_t;
  601. typedef struct listener_connection_t listener_connection_t;
  602. typedef struct or_connection_t or_connection_t;
  603. /** Cast a connection_t subtype pointer to a connection_t **/
  604. #define TO_CONN(c) (&(((c)->base_)))
  605. /** Cast a entry_connection_t subtype pointer to a connection_t **/
  606. #define ENTRY_TO_CONN(c) (TO_CONN(ENTRY_TO_EDGE_CONN(c)))
  607. typedef struct addr_policy_t addr_policy_t;
  608. typedef struct cached_dir_t cached_dir_t;
  609. /** Enum used to remember where a signed_descriptor_t is stored and how to
  610. * manage the memory for signed_descriptor_body. */
  611. typedef enum {
  612. /** The descriptor isn't stored on disk at all: the copy in memory is
  613. * canonical; the saved_offset field is meaningless. */
  614. SAVED_NOWHERE=0,
  615. /** The descriptor is stored in the cached_routers file: the
  616. * signed_descriptor_body is meaningless; the signed_descriptor_len and
  617. * saved_offset are used to index into the mmaped cache file. */
  618. SAVED_IN_CACHE,
  619. /** The descriptor is stored in the cached_routers.new file: the
  620. * signed_descriptor_body and saved_offset fields are both set. */
  621. /* FFFF (We could also mmap the file and grow the mmap as needed, or
  622. * lazy-load the descriptor text by using seek and read. We don't, for
  623. * now.)
  624. */
  625. SAVED_IN_JOURNAL
  626. } saved_location_t;
  627. #define saved_location_bitfield_t ENUM_BF(saved_location_t)
  628. /** Enumeration: what directory object is being downloaded?
  629. * This determines which schedule is selected to perform the download. */
  630. typedef enum {
  631. DL_SCHED_GENERIC = 0,
  632. DL_SCHED_CONSENSUS = 1,
  633. DL_SCHED_BRIDGE = 2,
  634. } download_schedule_t;
  635. #define download_schedule_bitfield_t ENUM_BF(download_schedule_t)
  636. /** Enumeration: is the download schedule for downloading from an authority,
  637. * or from any available directory mirror?
  638. * During bootstrap, "any" means a fallback (or an authority, if there
  639. * are no fallbacks).
  640. * When we have a valid consensus, "any" means any directory server. */
  641. typedef enum {
  642. DL_WANT_ANY_DIRSERVER = 0,
  643. DL_WANT_AUTHORITY = 1,
  644. } download_want_authority_t;
  645. #define download_want_authority_bitfield_t \
  646. ENUM_BF(download_want_authority_t)
  647. /** Enumeration: do we want to increment the schedule position each time a
  648. * connection is attempted (these attempts can be concurrent), or do we want
  649. * to increment the schedule position after a connection fails? */
  650. typedef enum {
  651. DL_SCHED_INCREMENT_FAILURE = 0,
  652. DL_SCHED_INCREMENT_ATTEMPT = 1,
  653. } download_schedule_increment_t;
  654. #define download_schedule_increment_bitfield_t \
  655. ENUM_BF(download_schedule_increment_t)
  656. typedef struct download_status_t download_status_t;
  657. /** If n_download_failures is this high, the download can never happen. */
  658. #define IMPOSSIBLE_TO_DOWNLOAD 255
  659. /** The max size we expect router descriptor annotations we create to
  660. * be. We'll accept larger ones if we see them on disk, but we won't
  661. * create any that are larger than this. */
  662. #define ROUTER_ANNOTATION_BUF_LEN 256
  663. typedef struct signed_descriptor_t signed_descriptor_t;
  664. /** A signed integer representing a country code. */
  665. typedef int16_t country_t;
  666. /** Flags used to summarize the declared protocol versions of a relay,
  667. * so we don't need to parse them again and again. */
  668. typedef struct protover_summary_flags_t {
  669. /** True iff we have a proto line for this router, or a versions line
  670. * from which we could infer the protocols. */
  671. unsigned int protocols_known:1;
  672. /** True iff this router has a version or protocol list that allows it to
  673. * accept EXTEND2 cells. This requires Relay=2. */
  674. unsigned int supports_extend2_cells:1;
  675. /** True iff this router has a protocol list that allows it to negotiate
  676. * ed25519 identity keys on a link handshake with us. This
  677. * requires LinkAuth=3. */
  678. unsigned int supports_ed25519_link_handshake_compat:1;
  679. /** True iff this router has a protocol list that allows it to negotiate
  680. * ed25519 identity keys on a link handshake, at all. This requires some
  681. * LinkAuth=X for X >= 3. */
  682. unsigned int supports_ed25519_link_handshake_any:1;
  683. /** True iff this router has a protocol list that allows it to be an
  684. * introduction point supporting ed25519 authentication key which is part of
  685. * the v3 protocol detailed in proposal 224. This requires HSIntro=4. */
  686. unsigned int supports_ed25519_hs_intro : 1;
  687. /** True iff this router has a protocol list that allows it to be an hidden
  688. * service directory supporting version 3 as seen in proposal 224. This
  689. * requires HSDir=2. */
  690. unsigned int supports_v3_hsdir : 1;
  691. /** True iff this router has a protocol list that allows it to be an hidden
  692. * service rendezvous point supporting version 3 as seen in proposal 224.
  693. * This requires HSRend=2. */
  694. unsigned int supports_v3_rendezvous_point: 1;
  695. } protover_summary_flags_t;
  696. typedef struct routerinfo_t routerinfo_t;
  697. typedef struct extrainfo_t extrainfo_t;
  698. typedef struct routerstatus_t routerstatus_t;
  699. typedef struct microdesc_t microdesc_t;
  700. typedef struct node_t node_t;
  701. typedef struct vote_microdesc_hash_t vote_microdesc_hash_t;
  702. typedef struct vote_routerstatus_t vote_routerstatus_t;
  703. typedef struct document_signature_t document_signature_t;
  704. typedef struct networkstatus_voter_info_t networkstatus_voter_info_t;
  705. typedef struct networkstatus_sr_info_t networkstatus_sr_info_t;
  706. /** Enumerates recognized flavors of a consensus networkstatus document. All
  707. * flavors of a consensus are generated from the same set of votes, but they
  708. * present different types information to different versions of Tor. */
  709. typedef enum {
  710. FLAV_NS = 0,
  711. FLAV_MICRODESC = 1,
  712. } consensus_flavor_t;
  713. /** How many different consensus flavors are there? */
  714. #define N_CONSENSUS_FLAVORS ((int)(FLAV_MICRODESC)+1)
  715. typedef struct networkstatus_t networkstatus_t;
  716. typedef struct ns_detached_signatures_t ns_detached_signatures_t;
  717. typedef struct desc_store_t desc_store_t;
  718. typedef struct routerlist_t routerlist_t;
  719. typedef struct extend_info_t extend_info_t;
  720. typedef struct authority_cert_t authority_cert_t;
  721. /** Bitfield enum type listing types of information that directory authorities
  722. * can be authoritative about, and that directory caches may or may not cache.
  723. *
  724. * Note that the granularity here is based on authority granularity and on
  725. * cache capabilities. Thus, one particular bit may correspond in practice to
  726. * a few types of directory info, so long as every authority that pronounces
  727. * officially about one of the types prounounces officially about all of them,
  728. * and so long as every cache that caches one of them caches all of them.
  729. */
  730. typedef enum {
  731. NO_DIRINFO = 0,
  732. /** Serves/signs v3 directory information: votes, consensuses, certs */
  733. V3_DIRINFO = 1 << 2,
  734. /** Serves bridge descriptors. */
  735. BRIDGE_DIRINFO = 1 << 4,
  736. /** Serves extrainfo documents. */
  737. EXTRAINFO_DIRINFO=1 << 5,
  738. /** Serves microdescriptors. */
  739. MICRODESC_DIRINFO=1 << 6,
  740. } dirinfo_type_t;
  741. #define ALL_DIRINFO ((dirinfo_type_t)((1<<7)-1))
  742. #define ONION_HANDSHAKE_TYPE_TAP 0x0000
  743. #define ONION_HANDSHAKE_TYPE_FAST 0x0001
  744. #define ONION_HANDSHAKE_TYPE_NTOR 0x0002
  745. #define MAX_ONION_HANDSHAKE_TYPE 0x0002
  746. typedef struct onion_handshake_state_t onion_handshake_state_t;
  747. typedef struct relay_crypto_t relay_crypto_t;
  748. typedef struct crypt_path_t crypt_path_t;
  749. typedef struct crypt_path_reference_t crypt_path_reference_t;
  750. #define CPATH_KEY_MATERIAL_LEN (20*2+16*2)
  751. typedef struct cpath_build_state_t cpath_build_state_t;
  752. struct create_cell_t;
  753. /** Entry in the cell stats list of a circuit; used only if CELL_STATS
  754. * events are enabled. */
  755. typedef struct testing_cell_stats_entry_t {
  756. uint8_t command; /**< cell command number. */
  757. /** Waiting time in centiseconds if this event is for a removed cell,
  758. * or 0 if this event is for adding a cell to the queue. 22 bits can
  759. * store more than 11 hours, enough to assume that a circuit with this
  760. * delay would long have been closed. */
  761. unsigned int waiting_time:22;
  762. unsigned int removed:1; /**< 0 for added to, 1 for removed from queue. */
  763. unsigned int exitward:1; /**< 0 for app-ward, 1 for exit-ward. */
  764. } testing_cell_stats_entry_t;
  765. typedef struct circuit_t circuit_t;
  766. typedef struct origin_circuit_t origin_circuit_t;
  767. typedef struct or_circuit_t or_circuit_t;
  768. /** Largest number of relay_early cells that we can send on a given
  769. * circuit. */
  770. #define MAX_RELAY_EARLY_CELLS_PER_CIRCUIT 8
  771. typedef enum path_state_t path_state_t;
  772. #define path_state_bitfield_t ENUM_BF(path_state_t)
  773. #if REND_COOKIE_LEN != DIGEST_LEN
  774. #error "The REND_TOKEN_LEN macro assumes REND_COOKIE_LEN == DIGEST_LEN"
  775. #endif
  776. #define REND_TOKEN_LEN DIGEST_LEN
  777. /** Convert a circuit subtype to a circuit_t. */
  778. #define TO_CIRCUIT(x) (&((x)->base_))
  779. /** @name Isolation flags
  780. Ways to isolate client streams
  781. @{
  782. */
  783. /** Isolate based on destination port */
  784. #define ISO_DESTPORT (1u<<0)
  785. /** Isolate based on destination address */
  786. #define ISO_DESTADDR (1u<<1)
  787. /** Isolate based on SOCKS authentication */
  788. #define ISO_SOCKSAUTH (1u<<2)
  789. /** Isolate based on client protocol choice */
  790. #define ISO_CLIENTPROTO (1u<<3)
  791. /** Isolate based on client address */
  792. #define ISO_CLIENTADDR (1u<<4)
  793. /** Isolate based on session group (always on). */
  794. #define ISO_SESSIONGRP (1u<<5)
  795. /** Isolate based on newnym epoch (always on). */
  796. #define ISO_NYM_EPOCH (1u<<6)
  797. /** Isolate all streams (Internal only). */
  798. #define ISO_STREAM (1u<<7)
  799. /**@}*/
  800. /** Default isolation level for ports. */
  801. #define ISO_DEFAULT (ISO_CLIENTADDR|ISO_SOCKSAUTH|ISO_SESSIONGRP|ISO_NYM_EPOCH)
  802. /** Indicates that we haven't yet set a session group on a port_cfg_t. */
  803. #define SESSION_GROUP_UNSET -1
  804. /** Session group reserved for directory connections */
  805. #define SESSION_GROUP_DIRCONN -2
  806. /** Session group reserved for resolve requests launched by a controller */
  807. #define SESSION_GROUP_CONTROL_RESOLVE -3
  808. /** First automatically allocated session group number */
  809. #define SESSION_GROUP_FIRST_AUTO -4
  810. typedef struct port_cfg_t port_cfg_t;
  811. typedef struct routerset_t routerset_t;
  812. /** A magic value for the (Socks|OR|...)Port options below, telling Tor
  813. * to pick its own port. */
  814. #define CFG_AUTO_PORT 0xc4005e
  815. typedef struct or_options_t or_options_t;
  816. #define LOG_PROTOCOL_WARN (get_protocol_warning_severity_level())
  817. typedef struct or_state_t or_state_t;
  818. #define MAX_SOCKS_ADDR_LEN 256
  819. /********************************* circuitbuild.c **********************/
  820. /** How many hops does a general-purpose circuit have by default? */
  821. #define DEFAULT_ROUTE_LEN 3
  822. /* Circuit Build Timeout "public" structures. */
  823. /** Precision multiplier for the Bw weights */
  824. #define BW_WEIGHT_SCALE 10000
  825. #define BW_MIN_WEIGHT_SCALE 1
  826. #define BW_MAX_WEIGHT_SCALE INT32_MAX
  827. typedef struct circuit_build_times_s circuit_build_times_t;
  828. /********************************* config.c ***************************/
  829. /********************************* connection_edge.c *************************/
  830. /** Enumerates possible origins of a client-side address mapping. */
  831. typedef enum {
  832. /** We're remapping this address because the controller told us to. */
  833. ADDRMAPSRC_CONTROLLER,
  834. /** We're remapping this address because of an AutomapHostsOnResolve
  835. * configuration. */
  836. ADDRMAPSRC_AUTOMAP,
  837. /** We're remapping this address because our configuration (via torrc, the
  838. * command line, or a SETCONF command) told us to. */
  839. ADDRMAPSRC_TORRC,
  840. /** We're remapping this address because we have TrackHostExit configured,
  841. * and we want to remember to use the same exit next time. */
  842. ADDRMAPSRC_TRACKEXIT,
  843. /** We're remapping this address because we got a DNS resolution from a
  844. * Tor server that told us what its value was. */
  845. ADDRMAPSRC_DNS,
  846. /** No remapping has occurred. This isn't a possible value for an
  847. * addrmap_entry_t; it's used as a null value when we need to answer "Why
  848. * did this remapping happen." */
  849. ADDRMAPSRC_NONE
  850. } addressmap_entry_source_t;
  851. #define addressmap_entry_source_bitfield_t ENUM_BF(addressmap_entry_source_t)
  852. #define WRITE_STATS_INTERVAL (24*60*60)
  853. /********************************* dirvote.c ************************/
  854. typedef struct vote_timing_t vote_timing_t;
  855. /********************************* microdesc.c *************************/
  856. typedef struct microdesc_cache_t microdesc_cache_t;
  857. /********************************* rendcommon.c ***************************/
  858. typedef struct rend_authorized_client_t rend_authorized_client_t;
  859. typedef struct rend_encoded_v2_service_descriptor_t
  860. rend_encoded_v2_service_descriptor_t;
  861. /** The maximum number of non-circuit-build-timeout failures a hidden
  862. * service client will tolerate while trying to build a circuit to an
  863. * introduction point. See also rend_intro_point_t.unreachable_count. */
  864. #define MAX_INTRO_POINT_REACHABILITY_FAILURES 5
  865. /** The minimum and maximum number of distinct INTRODUCE2 cells which a
  866. * hidden service's introduction point will receive before it begins to
  867. * expire. */
  868. #define INTRO_POINT_MIN_LIFETIME_INTRODUCTIONS 16384
  869. /* Double the minimum value so the interval is [min, min * 2]. */
  870. #define INTRO_POINT_MAX_LIFETIME_INTRODUCTIONS \
  871. (INTRO_POINT_MIN_LIFETIME_INTRODUCTIONS * 2)
  872. /** The minimum number of seconds that an introduction point will last
  873. * before expiring due to old age. (If it receives
  874. * INTRO_POINT_LIFETIME_INTRODUCTIONS INTRODUCE2 cells, it may expire
  875. * sooner.)
  876. *
  877. * XXX Should this be configurable? */
  878. #define INTRO_POINT_LIFETIME_MIN_SECONDS (18*60*60)
  879. /** The maximum number of seconds that an introduction point will last
  880. * before expiring due to old age.
  881. *
  882. * XXX Should this be configurable? */
  883. #define INTRO_POINT_LIFETIME_MAX_SECONDS (24*60*60)
  884. /** The maximum number of circuit creation retry we do to an intro point
  885. * before giving up. We try to reuse intro point that fails during their
  886. * lifetime so this is a hard limit on the amount of time we do that. */
  887. #define MAX_INTRO_POINT_CIRCUIT_RETRIES 3
  888. typedef struct rend_intro_point_t rend_intro_point_t;
  889. typedef struct rend_service_descriptor_t rend_service_descriptor_t;
  890. /********************************* routerlist.c ***************************/
  891. typedef struct dir_server_t dir_server_t;
  892. #define RELAY_REQUIRED_MIN_BANDWIDTH (75*1024)
  893. #define BRIDGE_REQUIRED_MIN_BANDWIDTH (50*1024)
  894. #define ROUTER_MAX_DECLARED_BANDWIDTH INT32_MAX
  895. typedef struct tor_version_t tor_version_t;
  896. #endif /* !defined(TOR_OR_H) */