or.h 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094
  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-2019, 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/buffers.h"
  25. #include "lib/container/smartlist.h"
  26. #include "lib/crypt_ops/crypto_cipher.h"
  27. #include "lib/crypt_ops/crypto_rsa.h"
  28. #include "lib/ctime/di_ops.h"
  29. #include "lib/defs/dh_sizes.h"
  30. #include "lib/encoding/binascii.h"
  31. #include "lib/encoding/cstring.h"
  32. #include "lib/encoding/time_fmt.h"
  33. #include "lib/err/torerr.h"
  34. #include "lib/fs/dir.h"
  35. #include "lib/fs/files.h"
  36. #include "lib/fs/mmap.h"
  37. #include "lib/fs/path.h"
  38. #include "lib/fs/userdb.h"
  39. #include "lib/geoip/country.h"
  40. #include "lib/intmath/addsub.h"
  41. #include "lib/intmath/bits.h"
  42. #include "lib/intmath/cmp.h"
  43. #include "lib/intmath/logic.h"
  44. #include "lib/intmath/muldiv.h"
  45. #include "lib/log/escape.h"
  46. #include "lib/log/ratelim.h"
  47. #include "lib/log/util_bug.h"
  48. #include "lib/malloc/malloc.h"
  49. #include "lib/net/address.h"
  50. #include "lib/net/inaddr.h"
  51. #include "lib/net/socket.h"
  52. #include "lib/string/compat_ctype.h"
  53. #include "lib/string/compat_string.h"
  54. #include "lib/string/parse_int.h"
  55. #include "lib/string/printf.h"
  56. #include "lib/string/scanf.h"
  57. #include "lib/string/util_string.h"
  58. #include "lib/testsupport/testsupport.h"
  59. #include "lib/thread/threads.h"
  60. #include "lib/time/compat_time.h"
  61. #include "lib/wallclock/approx_time.h"
  62. #include "lib/wallclock/timeval.h"
  63. #include "ht.h"
  64. // These, more than other includes, are for keeping the other struct
  65. // definitions working. We should remove them when we minimize our includes.
  66. #include "core/or/entry_port_cfg_st.h"
  67. struct ed25519_public_key_t;
  68. struct curve25519_public_key_t;
  69. /* These signals are defined to help handle_control_signal work.
  70. */
  71. #ifndef SIGHUP
  72. #define SIGHUP 1
  73. #endif
  74. #ifndef SIGINT
  75. #define SIGINT 2
  76. #endif
  77. #ifndef SIGUSR1
  78. #define SIGUSR1 10
  79. #endif
  80. #ifndef SIGUSR2
  81. #define SIGUSR2 12
  82. #endif
  83. #ifndef SIGTERM
  84. #define SIGTERM 15
  85. #endif
  86. /* Controller signals start at a high number so we don't
  87. * conflict with system-defined signals. */
  88. #define SIGNEWNYM 129
  89. #define SIGCLEARDNSCACHE 130
  90. #define SIGHEARTBEAT 131
  91. #if (SIZEOF_CELL_T != 0)
  92. /* On Irix, stdlib.h defines a cell_t type, so we need to make sure
  93. * that our stuff always calls cell_t something different. */
  94. #define cell_t tor_cell_t
  95. #endif
  96. /** Helper macro: Given a pointer to to.base_, of type from*, return &to. */
  97. #define DOWNCAST(to, ptr) ((to*)SUBTYPE_P(ptr, to, base_))
  98. /** Length of longest allowable configured nickname. */
  99. #define MAX_NICKNAME_LEN 19
  100. /** Length of a router identity encoded as a hexadecimal digest, plus
  101. * possible dollar sign. */
  102. #define MAX_HEX_NICKNAME_LEN (HEX_DIGEST_LEN+1)
  103. /** Maximum length of verbose router identifier: dollar sign, hex ID digest,
  104. * equal sign or tilde, nickname. */
  105. #define MAX_VERBOSE_NICKNAME_LEN (1+HEX_DIGEST_LEN+1+MAX_NICKNAME_LEN)
  106. /** For HTTP parsing: Maximum number of bytes we'll accept in the headers
  107. * of an HTTP request or response. */
  108. #define MAX_HEADERS_SIZE 50000
  109. /** Maximum size, in bytes, of a single router descriptor uploaded to us
  110. * as a directory authority. Caches and clients fetch whatever descriptors
  111. * the authorities tell them to fetch, and don't care about size. */
  112. #define MAX_DESCRIPTOR_UPLOAD_SIZE 20000
  113. /** Maximum size of a single extrainfo document, as above. */
  114. #define MAX_EXTRAINFO_UPLOAD_SIZE 50000
  115. /** Minimum lifetime for an onion key in days. */
  116. #define MIN_ONION_KEY_LIFETIME_DAYS (1)
  117. /** Maximum lifetime for an onion key in days. */
  118. #define MAX_ONION_KEY_LIFETIME_DAYS (90)
  119. /** Default lifetime for an onion key in days. */
  120. #define DEFAULT_ONION_KEY_LIFETIME_DAYS (28)
  121. /** Minimum grace period for acceptance of an onion key in days.
  122. * The maximum value is defined in proposal #274 as being the current network
  123. * consensus parameter for "onion-key-rotation-days". */
  124. #define MIN_ONION_KEY_GRACE_PERIOD_DAYS (1)
  125. /** Default grace period for acceptance of an onion key in days. */
  126. #define DEFAULT_ONION_KEY_GRACE_PERIOD_DAYS (7)
  127. /** How often we should check the network consensus if it is time to rotate or
  128. * expire onion keys. */
  129. #define ONION_KEY_CONSENSUS_CHECK_INTERVAL (60*60)
  130. /** How often do we rotate TLS contexts? */
  131. #define MAX_SSL_KEY_LIFETIME_INTERNAL (2*60*60)
  132. /** How old do we allow a router to get before removing it
  133. * from the router list? In seconds. */
  134. #define ROUTER_MAX_AGE (60*60*48)
  135. /** How old can a router get before we (as a server) will no longer
  136. * consider it live? In seconds. */
  137. #define ROUTER_MAX_AGE_TO_PUBLISH (60*60*24)
  138. /** How old do we let a saved descriptor get before force-removing it? */
  139. #define OLD_ROUTER_DESC_MAX_AGE (60*60*24*5)
  140. /* Proxy client types */
  141. #define PROXY_NONE 0
  142. #define PROXY_CONNECT 1
  143. #define PROXY_SOCKS4 2
  144. #define PROXY_SOCKS5 3
  145. /* !!!! If there is ever a PROXY_* type over 3, we must grow the proxy_type
  146. * field in or_connection_t */
  147. /* Pluggable transport proxy type. Don't use this in or_connection_t,
  148. * instead use the actual underlying proxy type (see above). */
  149. #define PROXY_PLUGGABLE 4
  150. /** How many circuits do we want simultaneously in-progress to handle
  151. * a given stream? */
  152. #define MIN_CIRCUITS_HANDLING_STREAM 2
  153. /* These RELAY_COMMAND constants define values for relay cell commands, and
  154. * must match those defined in tor-spec.txt. */
  155. #define RELAY_COMMAND_BEGIN 1
  156. #define RELAY_COMMAND_DATA 2
  157. #define RELAY_COMMAND_END 3
  158. #define RELAY_COMMAND_CONNECTED 4
  159. #define RELAY_COMMAND_SENDME 5
  160. #define RELAY_COMMAND_EXTEND 6
  161. #define RELAY_COMMAND_EXTENDED 7
  162. #define RELAY_COMMAND_TRUNCATE 8
  163. #define RELAY_COMMAND_TRUNCATED 9
  164. #define RELAY_COMMAND_DROP 10
  165. #define RELAY_COMMAND_RESOLVE 11
  166. #define RELAY_COMMAND_RESOLVED 12
  167. #define RELAY_COMMAND_BEGIN_DIR 13
  168. #define RELAY_COMMAND_EXTEND2 14
  169. #define RELAY_COMMAND_EXTENDED2 15
  170. #define RELAY_COMMAND_ESTABLISH_INTRO 32
  171. #define RELAY_COMMAND_ESTABLISH_RENDEZVOUS 33
  172. #define RELAY_COMMAND_INTRODUCE1 34
  173. #define RELAY_COMMAND_INTRODUCE2 35
  174. #define RELAY_COMMAND_RENDEZVOUS1 36
  175. #define RELAY_COMMAND_RENDEZVOUS2 37
  176. #define RELAY_COMMAND_INTRO_ESTABLISHED 38
  177. #define RELAY_COMMAND_RENDEZVOUS_ESTABLISHED 39
  178. #define RELAY_COMMAND_INTRODUCE_ACK 40
  179. /* Reasons why an OR connection is closed. */
  180. #define END_OR_CONN_REASON_DONE 1
  181. #define END_OR_CONN_REASON_REFUSED 2 /* connection refused */
  182. #define END_OR_CONN_REASON_OR_IDENTITY 3
  183. #define END_OR_CONN_REASON_CONNRESET 4 /* connection reset by peer */
  184. #define END_OR_CONN_REASON_TIMEOUT 5
  185. #define END_OR_CONN_REASON_NO_ROUTE 6 /* no route to host/net */
  186. #define END_OR_CONN_REASON_IO_ERROR 7 /* read/write error */
  187. #define END_OR_CONN_REASON_RESOURCE_LIMIT 8 /* sockets, buffers, etc */
  188. #define END_OR_CONN_REASON_PT_MISSING 9 /* PT failed or not available */
  189. #define END_OR_CONN_REASON_MISC 10
  190. /* Reasons why we (or a remote OR) might close a stream. See tor-spec.txt for
  191. * documentation of these. The values must match. */
  192. #define END_STREAM_REASON_MISC 1
  193. #define END_STREAM_REASON_RESOLVEFAILED 2
  194. #define END_STREAM_REASON_CONNECTREFUSED 3
  195. #define END_STREAM_REASON_EXITPOLICY 4
  196. #define END_STREAM_REASON_DESTROY 5
  197. #define END_STREAM_REASON_DONE 6
  198. #define END_STREAM_REASON_TIMEOUT 7
  199. #define END_STREAM_REASON_NOROUTE 8
  200. #define END_STREAM_REASON_HIBERNATING 9
  201. #define END_STREAM_REASON_INTERNAL 10
  202. #define END_STREAM_REASON_RESOURCELIMIT 11
  203. #define END_STREAM_REASON_CONNRESET 12
  204. #define END_STREAM_REASON_TORPROTOCOL 13
  205. #define END_STREAM_REASON_NOTDIRECTORY 14
  206. #define END_STREAM_REASON_ENTRYPOLICY 15
  207. /* These high-numbered end reasons are not part of the official spec,
  208. * and are not intended to be put in relay end cells. They are here
  209. * to be more informative when sending back socks replies to the
  210. * application. */
  211. /* XXXX 256 is no longer used; feel free to reuse it. */
  212. /** We were unable to attach the connection to any circuit at all. */
  213. /* XXXX the ways we use this one don't make a lot of sense. */
  214. #define END_STREAM_REASON_CANT_ATTACH 257
  215. /** We can't connect to any directories at all, so we killed our streams
  216. * before they can time out. */
  217. #define END_STREAM_REASON_NET_UNREACHABLE 258
  218. /** This is a SOCKS connection, and the client used (or misused) the SOCKS
  219. * protocol in a way we couldn't handle. */
  220. #define END_STREAM_REASON_SOCKSPROTOCOL 259
  221. /** This is a transparent proxy connection, but we can't extract the original
  222. * target address:port. */
  223. #define END_STREAM_REASON_CANT_FETCH_ORIG_DEST 260
  224. /** This is a connection on the NATD port, and the destination IP:Port was
  225. * either ill-formed or out-of-range. */
  226. #define END_STREAM_REASON_INVALID_NATD_DEST 261
  227. /** The target address is in a private network (like 127.0.0.1 or 10.0.0.1);
  228. * you don't want to do that over a randomly chosen exit */
  229. #define END_STREAM_REASON_PRIVATE_ADDR 262
  230. /** This is an HTTP tunnel connection and the client used or misused HTTP in a
  231. * way we can't handle.
  232. */
  233. #define END_STREAM_REASON_HTTPPROTOCOL 263
  234. /** Bitwise-and this value with endreason to mask out all flags. */
  235. #define END_STREAM_REASON_MASK 511
  236. /** Bitwise-or this with the argument to control_event_stream_status
  237. * to indicate that the reason came from an END cell. */
  238. #define END_STREAM_REASON_FLAG_REMOTE 512
  239. /** Bitwise-or this with the argument to control_event_stream_status
  240. * to indicate that we already sent a CLOSED stream event. */
  241. #define END_STREAM_REASON_FLAG_ALREADY_SENT_CLOSED 1024
  242. /** Bitwise-or this with endreason to indicate that we already sent
  243. * a socks reply, and no further reply needs to be sent from
  244. * connection_mark_unattached_ap(). */
  245. #define END_STREAM_REASON_FLAG_ALREADY_SOCKS_REPLIED 2048
  246. /* 'type' values to use in RESOLVED cells. Specified in tor-spec.txt. */
  247. #define RESOLVED_TYPE_HOSTNAME 0
  248. #define RESOLVED_TYPE_IPV4 4
  249. #define RESOLVED_TYPE_IPV6 6
  250. #define RESOLVED_TYPE_ERROR_TRANSIENT 0xF0
  251. #define RESOLVED_TYPE_ERROR 0xF1
  252. /* Negative reasons are internal: we never send them in a DESTROY or TRUNCATE
  253. * call; they only go to the controller for tracking */
  254. /* Closing introduction point that were opened in parallel. */
  255. #define END_CIRC_REASON_IP_NOW_REDUNDANT -4
  256. /** Our post-timeout circuit time measurement period expired.
  257. * We must give up now */
  258. #define END_CIRC_REASON_MEASUREMENT_EXPIRED -3
  259. /** We couldn't build a path for this circuit. */
  260. #define END_CIRC_REASON_NOPATH -2
  261. /** Catch-all "other" reason for closing origin circuits. */
  262. #define END_CIRC_AT_ORIGIN -1
  263. /* Reasons why we (or a remote OR) might close a circuit. See tor-spec.txt
  264. * section 5.4 for documentation of these. */
  265. #define END_CIRC_REASON_MIN_ 0
  266. #define END_CIRC_REASON_NONE 0
  267. #define END_CIRC_REASON_TORPROTOCOL 1
  268. #define END_CIRC_REASON_INTERNAL 2
  269. #define END_CIRC_REASON_REQUESTED 3
  270. #define END_CIRC_REASON_HIBERNATING 4
  271. #define END_CIRC_REASON_RESOURCELIMIT 5
  272. #define END_CIRC_REASON_CONNECTFAILED 6
  273. #define END_CIRC_REASON_OR_IDENTITY 7
  274. #define END_CIRC_REASON_CHANNEL_CLOSED 8
  275. #define END_CIRC_REASON_FINISHED 9
  276. #define END_CIRC_REASON_TIMEOUT 10
  277. #define END_CIRC_REASON_DESTROYED 11
  278. #define END_CIRC_REASON_NOSUCHSERVICE 12
  279. #define END_CIRC_REASON_MAX_ 12
  280. /** Bitwise-OR this with the argument to circuit_mark_for_close() or
  281. * control_event_circuit_status() to indicate that the reason was
  282. * passed through from a destroy or truncate cell. */
  283. #define END_CIRC_REASON_FLAG_REMOTE 512
  284. /** Length of 'y' portion of 'y.onion' URL. */
  285. #define REND_SERVICE_ID_LEN_BASE32 16
  286. /** Length of 'y.onion' including '.onion' URL. */
  287. #define REND_SERVICE_ADDRESS_LEN (16+1+5)
  288. /** Length of a binary-encoded rendezvous service ID. */
  289. #define REND_SERVICE_ID_LEN 10
  290. /** Time period for which a v2 descriptor will be valid. */
  291. #define REND_TIME_PERIOD_V2_DESC_VALIDITY (24*60*60)
  292. /** Time period within which two sets of v2 descriptors will be uploaded in
  293. * parallel. */
  294. #define REND_TIME_PERIOD_OVERLAPPING_V2_DESCS (60*60)
  295. /** Number of non-consecutive replicas (i.e. distributed somewhere
  296. * in the ring) for a descriptor. */
  297. #define REND_NUMBER_OF_NON_CONSECUTIVE_REPLICAS 2
  298. /** Number of consecutive replicas for a descriptor. */
  299. #define REND_NUMBER_OF_CONSECUTIVE_REPLICAS 3
  300. /** Length of v2 descriptor ID (32 base32 chars = 160 bits). */
  301. #define REND_DESC_ID_V2_LEN_BASE32 BASE32_DIGEST_LEN
  302. /** Length of the base32-encoded secret ID part of versioned hidden service
  303. * descriptors. */
  304. #define REND_SECRET_ID_PART_LEN_BASE32 BASE32_DIGEST_LEN
  305. /** Length of the base32-encoded hash of an introduction point's
  306. * identity key. */
  307. #define REND_INTRO_POINT_ID_LEN_BASE32 BASE32_DIGEST_LEN
  308. /** Length of the descriptor cookie that is used for client authorization
  309. * to hidden services. */
  310. #define REND_DESC_COOKIE_LEN 16
  311. /** Length of the base64-encoded descriptor cookie that is used for
  312. * exchanging client authorization between hidden service and client. */
  313. #define REND_DESC_COOKIE_LEN_BASE64 22
  314. /** Length of client identifier in encrypted introduction points for hidden
  315. * service authorization type 'basic'. */
  316. #define REND_BASIC_AUTH_CLIENT_ID_LEN 4
  317. /** Multiple of the number of clients to which the real number of clients
  318. * is padded with fake clients for hidden service authorization type
  319. * 'basic'. */
  320. #define REND_BASIC_AUTH_CLIENT_MULTIPLE 16
  321. /** Length of client entry consisting of client identifier and encrypted
  322. * session key for hidden service authorization type 'basic'. */
  323. #define REND_BASIC_AUTH_CLIENT_ENTRY_LEN (REND_BASIC_AUTH_CLIENT_ID_LEN \
  324. + CIPHER_KEY_LEN)
  325. /** Maximum size of v2 hidden service descriptors. */
  326. #define REND_DESC_MAX_SIZE (20 * 1024)
  327. /** Legal characters for use in authorized client names for a hidden
  328. * service. */
  329. #define REND_LEGAL_CLIENTNAME_CHARACTERS \
  330. "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+-_"
  331. /** Maximum length of authorized client names for a hidden service. */
  332. #define REND_CLIENTNAME_MAX_LEN 16
  333. /** Length of the rendezvous cookie that is used to connect circuits at the
  334. * rendezvous point. */
  335. #define REND_COOKIE_LEN DIGEST_LEN
  336. /** Client authorization type that a hidden service performs. */
  337. typedef enum rend_auth_type_t {
  338. REND_NO_AUTH = 0,
  339. REND_BASIC_AUTH = 1,
  340. REND_STEALTH_AUTH = 2,
  341. } rend_auth_type_t;
  342. /** Client-side configuration of authorization for a hidden service. */
  343. typedef struct rend_service_authorization_t {
  344. uint8_t descriptor_cookie[REND_DESC_COOKIE_LEN];
  345. char onion_address[REND_SERVICE_ADDRESS_LEN+1];
  346. rend_auth_type_t auth_type;
  347. } rend_service_authorization_t;
  348. /** Client- and server-side data that is used for hidden service connection
  349. * establishment. Not all fields contain data depending on where this struct
  350. * is used. */
  351. typedef struct rend_data_t {
  352. /* Hidden service protocol version of this base object. */
  353. uint32_t version;
  354. /** List of HSDir fingerprints on which this request has been sent to. This
  355. * contains binary identity digest of the directory of size DIGEST_LEN. */
  356. smartlist_t *hsdirs_fp;
  357. /** Rendezvous cookie used by both, client and service. */
  358. char rend_cookie[REND_COOKIE_LEN];
  359. /** Number of streams associated with this rendezvous circuit. */
  360. int nr_streams;
  361. } rend_data_t;
  362. typedef struct rend_data_v2_t {
  363. /* Rendezvous base data. */
  364. rend_data_t base_;
  365. /** Onion address (without the .onion part) that a client requests. */
  366. char onion_address[REND_SERVICE_ID_LEN_BASE32+1];
  367. /** Descriptor ID for each replicas computed from the onion address. If
  368. * the onion address is empty, this array MUST be empty. We keep them so
  369. * we know when to purge our entry in the last hsdir request table. */
  370. char descriptor_id[REND_NUMBER_OF_NON_CONSECUTIVE_REPLICAS][DIGEST_LEN];
  371. /** (Optional) descriptor cookie that is used by a client. */
  372. char descriptor_cookie[REND_DESC_COOKIE_LEN];
  373. /** Authorization type for accessing a service used by a client. */
  374. rend_auth_type_t auth_type;
  375. /** Descriptor ID for a client request. The control port command HSFETCH
  376. * uses this. It's set if the descriptor query should only use this
  377. * descriptor ID. */
  378. char desc_id_fetch[DIGEST_LEN];
  379. /** Hash of the hidden service's PK used by a service. */
  380. char rend_pk_digest[DIGEST_LEN];
  381. } rend_data_v2_t;
  382. /* From a base rend_data_t object <b>d</d>, return the v2 object. */
  383. static inline
  384. rend_data_v2_t *TO_REND_DATA_V2(const rend_data_t *d)
  385. {
  386. tor_assert(d);
  387. tor_assert(d->version == 2);
  388. return DOWNCAST(rend_data_v2_t, d);
  389. }
  390. /* Stub because we can't include hs_ident.h. */
  391. struct hs_ident_edge_conn_t;
  392. struct hs_ident_dir_conn_t;
  393. struct hs_ident_circuit_t;
  394. typedef struct hsdir_index_t hsdir_index_t;
  395. /** Time interval for tracking replays of DH public keys received in
  396. * INTRODUCE2 cells. Used only to avoid launching multiple
  397. * simultaneous attempts to connect to the same rendezvous point. */
  398. #define REND_REPLAY_TIME_INTERVAL (5 * 60)
  399. /** Used to indicate which way a cell is going on a circuit. */
  400. typedef enum {
  401. CELL_DIRECTION_IN=1, /**< The cell is moving towards the origin. */
  402. CELL_DIRECTION_OUT=2, /**< The cell is moving away from the origin. */
  403. } cell_direction_t;
  404. /**
  405. * An enum to allow us to specify which channel in a circuit
  406. * we're interested in.
  407. *
  408. * This is needed because our data structures and other fields
  409. * for channel delivery are disassociated from the channel.
  410. */
  411. typedef enum {
  412. CIRCUIT_N_CHAN = 0,
  413. CIRCUIT_P_CHAN = 1
  414. } circuit_channel_direction_t;
  415. /** Initial value for both sides of a circuit transmission window when the
  416. * circuit is initialized. Measured in cells. */
  417. #define CIRCWINDOW_START 1000
  418. #define CIRCWINDOW_START_MIN 100
  419. #define CIRCWINDOW_START_MAX 1000
  420. /** Amount to increment a circuit window when we get a circuit SENDME. */
  421. #define CIRCWINDOW_INCREMENT 100
  422. /** Initial value on both sides of a stream transmission window when the
  423. * stream is initialized. Measured in cells. */
  424. #define STREAMWINDOW_START 500
  425. #define STREAMWINDOW_START_MAX 500
  426. /** Amount to increment a stream window when we get a stream SENDME. */
  427. #define STREAMWINDOW_INCREMENT 50
  428. /** Maximum number of queued cells on a circuit for which we are the
  429. * midpoint before we give up and kill it. This must be >= circwindow
  430. * to avoid killing innocent circuits, and >= circwindow*2 to give
  431. * leaky-pipe a chance of working someday. The ORCIRC_MAX_MIDDLE_KILL_THRESH
  432. * ratio controls the margin of error between emitting a warning and
  433. * killing the circuit.
  434. */
  435. #define ORCIRC_MAX_MIDDLE_CELLS (CIRCWINDOW_START_MAX*2)
  436. /** Ratio of hard (circuit kill) to soft (warning) thresholds for the
  437. * ORCIRC_MAX_MIDDLE_CELLS tests.
  438. */
  439. #define ORCIRC_MAX_MIDDLE_KILL_THRESH (1.1f)
  440. /* Cell commands. These values are defined in tor-spec.txt. */
  441. #define CELL_PADDING 0
  442. #define CELL_CREATE 1
  443. #define CELL_CREATED 2
  444. #define CELL_RELAY 3
  445. #define CELL_DESTROY 4
  446. #define CELL_CREATE_FAST 5
  447. #define CELL_CREATED_FAST 6
  448. #define CELL_VERSIONS 7
  449. #define CELL_NETINFO 8
  450. #define CELL_RELAY_EARLY 9
  451. #define CELL_CREATE2 10
  452. #define CELL_CREATED2 11
  453. #define CELL_PADDING_NEGOTIATE 12
  454. #define CELL_VPADDING 128
  455. #define CELL_CERTS 129
  456. #define CELL_AUTH_CHALLENGE 130
  457. #define CELL_AUTHENTICATE 131
  458. #define CELL_AUTHORIZE 132
  459. #define CELL_COMMAND_MAX_ 132
  460. /** How long to test reachability before complaining to the user. */
  461. #define TIMEOUT_UNTIL_UNREACHABILITY_COMPLAINT (20*60)
  462. /** Legal characters in a nickname. */
  463. #define LEGAL_NICKNAME_CHARACTERS \
  464. "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
  465. /** Name to use in client TLS certificates if no nickname is given. Once
  466. * Tor 0.1.2.x is obsolete, we can remove this. */
  467. #define DEFAULT_CLIENT_NICKNAME "client"
  468. /** Name chosen by routers that don't configure nicknames */
  469. #define UNNAMED_ROUTER_NICKNAME "Unnamed"
  470. /** Number of bytes in a SOCKS4 header. */
  471. #define SOCKS4_NETWORK_LEN 8
  472. /*
  473. * Relay payload:
  474. * Relay command [1 byte]
  475. * Recognized [2 bytes]
  476. * Stream ID [2 bytes]
  477. * Partial SHA-1 [4 bytes]
  478. * Length [2 bytes]
  479. * Relay payload [498 bytes]
  480. */
  481. /** Number of bytes in a cell, minus cell header. */
  482. #define CELL_PAYLOAD_SIZE 509
  483. /** Number of bytes in a cell transmitted over the network, in the longest
  484. * form */
  485. #define CELL_MAX_NETWORK_SIZE 514
  486. /** Maximum length of a header on a variable-length cell. */
  487. #define VAR_CELL_MAX_HEADER_SIZE 7
  488. static int get_cell_network_size(int wide_circ_ids);
  489. static inline int get_cell_network_size(int wide_circ_ids)
  490. {
  491. return wide_circ_ids ? CELL_MAX_NETWORK_SIZE : CELL_MAX_NETWORK_SIZE - 2;
  492. }
  493. static int get_var_cell_header_size(int wide_circ_ids);
  494. static inline int get_var_cell_header_size(int wide_circ_ids)
  495. {
  496. return wide_circ_ids ? VAR_CELL_MAX_HEADER_SIZE :
  497. VAR_CELL_MAX_HEADER_SIZE - 2;
  498. }
  499. static int get_circ_id_size(int wide_circ_ids);
  500. static inline int get_circ_id_size(int wide_circ_ids)
  501. {
  502. return wide_circ_ids ? 4 : 2;
  503. }
  504. /** Number of bytes in a relay cell's header (not including general cell
  505. * header). */
  506. #define RELAY_HEADER_SIZE (1+2+2+4+2)
  507. /** Largest number of bytes that can fit in a relay cell payload. */
  508. #define RELAY_PAYLOAD_SIZE (CELL_PAYLOAD_SIZE-RELAY_HEADER_SIZE)
  509. /** Identifies a circuit on an or_connection */
  510. typedef uint32_t circid_t;
  511. /** Identifies a stream on a circuit */
  512. typedef uint16_t streamid_t;
  513. /* channel_t typedef; struct channel_s is in channel.h */
  514. typedef struct channel_s channel_t;
  515. /* channel_listener_t typedef; struct channel_listener_s is in channel.h */
  516. typedef struct channel_listener_s channel_listener_t;
  517. /* TLS channel stuff */
  518. typedef struct channel_tls_s channel_tls_t;
  519. /* circuitmux_t typedef; struct circuitmux_s is in circuitmux.h */
  520. typedef struct circuitmux_s circuitmux_t;
  521. typedef struct cell_t cell_t;
  522. typedef struct var_cell_t var_cell_t;
  523. typedef struct packed_cell_t packed_cell_t;
  524. typedef struct cell_queue_t cell_queue_t;
  525. typedef struct destroy_cell_t destroy_cell_t;
  526. typedef struct destroy_cell_queue_t destroy_cell_queue_t;
  527. typedef struct ext_or_cmd_t ext_or_cmd_t;
  528. /** Beginning of a RELAY cell payload. */
  529. typedef struct {
  530. uint8_t command; /**< The end-to-end relay command. */
  531. uint16_t recognized; /**< Used to tell whether cell is for us. */
  532. streamid_t stream_id; /**< Which stream is this cell associated with? */
  533. char integrity[4]; /**< Used to tell whether cell is corrupted. */
  534. uint16_t length; /**< How long is the payload body? */
  535. } relay_header_t;
  536. typedef struct socks_request_t socks_request_t;
  537. typedef struct entry_port_cfg_t entry_port_cfg_t;
  538. typedef struct server_port_cfg_t server_port_cfg_t;
  539. /** Minimum length of the random part of an AUTH_CHALLENGE cell. */
  540. #define OR_AUTH_CHALLENGE_LEN 32
  541. /**
  542. * @name Certificate types for CERTS cells.
  543. *
  544. * These values are defined by the protocol, and affect how an X509
  545. * certificate in a CERTS cell is interpreted and used.
  546. *
  547. * @{ */
  548. /** A certificate that authenticates a TLS link key. The subject key
  549. * must match the key used in the TLS handshake; it must be signed by
  550. * the identity key. */
  551. #define OR_CERT_TYPE_TLS_LINK 1
  552. /** A self-signed identity certificate. The subject key must be a
  553. * 1024-bit RSA key. */
  554. #define OR_CERT_TYPE_ID_1024 2
  555. /** A certificate that authenticates a key used in an AUTHENTICATE cell
  556. * in the v3 handshake. The subject key must be a 1024-bit RSA key; it
  557. * must be signed by the identity key */
  558. #define OR_CERT_TYPE_AUTH_1024 3
  559. /* DOCDOC */
  560. #define OR_CERT_TYPE_RSA_ED_CROSSCERT 7
  561. /**@}*/
  562. /** The first supported type of AUTHENTICATE cell. It contains
  563. * a bunch of structures signed with an RSA1024 key. The signed
  564. * structures include a HMAC using negotiated TLS secrets, and a digest
  565. * of all cells sent or received before the AUTHENTICATE cell (including
  566. * the random server-generated AUTH_CHALLENGE cell).
  567. */
  568. #define AUTHTYPE_RSA_SHA256_TLSSECRET 1
  569. /** As AUTHTYPE_RSA_SHA256_TLSSECRET, but instead of using the
  570. * negotiated TLS secrets, uses exported keying material from the TLS
  571. * session as described in RFC 5705.
  572. *
  573. * Not used by today's tors, since everything that supports this
  574. * also supports ED25519_SHA256_5705, which is better.
  575. **/
  576. #define AUTHTYPE_RSA_SHA256_RFC5705 2
  577. /** As AUTHTYPE_RSA_SHA256_RFC5705, but uses an Ed25519 identity key to
  578. * authenticate. */
  579. #define AUTHTYPE_ED25519_SHA256_RFC5705 3
  580. /*
  581. * NOTE: authchallenge_type_is_better() relies on these AUTHTYPE codes
  582. * being sorted in order of preference. If we someday add one with
  583. * a higher numerical value that we don't like as much, we should revise
  584. * authchallenge_type_is_better().
  585. */
  586. /** The length of the part of the AUTHENTICATE cell body that the client and
  587. * server can generate independently (when using RSA_SHA256_TLSSECRET). It
  588. * contains everything except the client's timestamp, the client's randomly
  589. * generated nonce, and the signature. */
  590. #define V3_AUTH_FIXED_PART_LEN (8+(32*6))
  591. /** The length of the part of the AUTHENTICATE cell body that the client
  592. * signs. */
  593. #define V3_AUTH_BODY_LEN (V3_AUTH_FIXED_PART_LEN + 8 + 16)
  594. typedef struct or_handshake_certs_t or_handshake_certs_t;
  595. typedef struct or_handshake_state_t or_handshake_state_t;
  596. /** Length of Extended ORPort connection identifier. */
  597. #define EXT_OR_CONN_ID_LEN DIGEST_LEN /* 20 */
  598. /*
  599. * OR_CONN_HIGHWATER and OR_CONN_LOWWATER moved from connection_or.c so
  600. * channeltls.c can see them too.
  601. */
  602. /** When adding cells to an OR connection's outbuf, keep adding until the
  603. * outbuf is at least this long, or we run out of cells. */
  604. #define OR_CONN_HIGHWATER (32*1024)
  605. /** Add cells to an OR connection's outbuf whenever the outbuf's data length
  606. * drops below this size. */
  607. #define OR_CONN_LOWWATER (16*1024)
  608. typedef struct connection_t connection_t;
  609. typedef struct control_connection_t control_connection_t;
  610. typedef struct dir_connection_t dir_connection_t;
  611. typedef struct edge_connection_t edge_connection_t;
  612. typedef struct entry_connection_t entry_connection_t;
  613. typedef struct listener_connection_t listener_connection_t;
  614. typedef struct or_connection_t or_connection_t;
  615. /** Cast a connection_t subtype pointer to a connection_t **/
  616. #define TO_CONN(c) (&(((c)->base_)))
  617. /** Cast a entry_connection_t subtype pointer to a connection_t **/
  618. #define ENTRY_TO_CONN(c) (TO_CONN(ENTRY_TO_EDGE_CONN(c)))
  619. typedef struct addr_policy_t addr_policy_t;
  620. typedef struct cached_dir_t cached_dir_t;
  621. /** Enum used to remember where a signed_descriptor_t is stored and how to
  622. * manage the memory for signed_descriptor_body. */
  623. typedef enum {
  624. /** The descriptor isn't stored on disk at all: the copy in memory is
  625. * canonical; the saved_offset field is meaningless. */
  626. SAVED_NOWHERE=0,
  627. /** The descriptor is stored in the cached_routers file: the
  628. * signed_descriptor_body is meaningless; the signed_descriptor_len and
  629. * saved_offset are used to index into the mmaped cache file. */
  630. SAVED_IN_CACHE,
  631. /** The descriptor is stored in the cached_routers.new file: the
  632. * signed_descriptor_body and saved_offset fields are both set. */
  633. /* FFFF (We could also mmap the file and grow the mmap as needed, or
  634. * lazy-load the descriptor text by using seek and read. We don't, for
  635. * now.)
  636. */
  637. SAVED_IN_JOURNAL
  638. } saved_location_t;
  639. #define saved_location_bitfield_t ENUM_BF(saved_location_t)
  640. /** Enumeration: what directory object is being downloaded?
  641. * This determines which schedule is selected to perform the download. */
  642. typedef enum {
  643. DL_SCHED_GENERIC = 0,
  644. DL_SCHED_CONSENSUS = 1,
  645. DL_SCHED_BRIDGE = 2,
  646. } download_schedule_t;
  647. #define download_schedule_bitfield_t ENUM_BF(download_schedule_t)
  648. /** Enumeration: is the download schedule for downloading from an authority,
  649. * or from any available directory mirror?
  650. * During bootstrap, "any" means a fallback (or an authority, if there
  651. * are no fallbacks).
  652. * When we have a valid consensus, "any" means any directory server. */
  653. typedef enum {
  654. DL_WANT_ANY_DIRSERVER = 0,
  655. DL_WANT_AUTHORITY = 1,
  656. } download_want_authority_t;
  657. #define download_want_authority_bitfield_t \
  658. ENUM_BF(download_want_authority_t)
  659. /** Enumeration: do we want to increment the schedule position each time a
  660. * connection is attempted (these attempts can be concurrent), or do we want
  661. * to increment the schedule position after a connection fails? */
  662. typedef enum {
  663. DL_SCHED_INCREMENT_FAILURE = 0,
  664. DL_SCHED_INCREMENT_ATTEMPT = 1,
  665. } download_schedule_increment_t;
  666. #define download_schedule_increment_bitfield_t \
  667. ENUM_BF(download_schedule_increment_t)
  668. typedef struct download_status_t download_status_t;
  669. /** If n_download_failures is this high, the download can never happen. */
  670. #define IMPOSSIBLE_TO_DOWNLOAD 255
  671. /** The max size we expect router descriptor annotations we create to
  672. * be. We'll accept larger ones if we see them on disk, but we won't
  673. * create any that are larger than this. */
  674. #define ROUTER_ANNOTATION_BUF_LEN 256
  675. typedef struct signed_descriptor_t signed_descriptor_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) */