or.h 40 KB

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