or.h 40 KB

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