or.h 40 KB

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