or.h 40 KB

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