or.h 40 KB

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