or.h 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136
  1. /* Copyright 2001,2002,2003 Roger Dingledine, Matej Pfajfar. */
  2. /* See LICENSE for licensing information */
  3. /* $Id$ */
  4. #ifndef __OR_H
  5. #define __OR_H
  6. #include "orconfig.h"
  7. #ifdef MS_WINDOWS
  8. #define WIN32_WINNT 0x400
  9. #define _WIN32_WINNT 0x400
  10. #define WIN32_LEAN_AND_MEAN
  11. /* Number of fds that select will accept; default is 64. */
  12. #define FD_SETSIZE 512
  13. #endif
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <limits.h>
  17. #ifdef HAVE_UNISTD_H
  18. #include <unistd.h>
  19. #endif
  20. #ifdef HAVE_STRING_H
  21. #include <string.h>
  22. #endif
  23. #ifdef HAVE_SIGNAL_H
  24. #include <signal.h>
  25. #endif
  26. #ifdef HAVE_NETDB_H
  27. #include <netdb.h>
  28. #endif
  29. #ifdef HAVE_CTYPE_H
  30. #include <ctype.h>
  31. #endif
  32. #include "../common/torint.h"
  33. #include "../common/fakepoll.h"
  34. #ifdef HAVE_SYS_TYPES_H
  35. #include <sys/types.h> /* Must be included before sys/stat.h for Ultrix */
  36. #endif
  37. #ifdef HAVE_SYS_WAIT_H
  38. #include <sys/wait.h>
  39. #endif
  40. #ifdef HAVE_SYS_FCNTL_H
  41. #include <sys/fcntl.h>
  42. #endif
  43. #ifdef HAVE_FCNTL_H
  44. #include <fcntl.h>
  45. #endif
  46. #ifdef HAVE_SYS_IOCTL_H
  47. #include <sys/ioctl.h>
  48. #endif
  49. #ifdef HAVE_SYS_SOCKET_H
  50. #include <sys/socket.h>
  51. #endif
  52. #ifdef HAVE_SYS_TIME_H
  53. #include <sys/time.h>
  54. #endif
  55. #ifdef HAVE_SYS_STAT_H
  56. #include <sys/stat.h>
  57. #endif
  58. #ifdef HAVE_NETINET_IN_H
  59. #include <netinet/in.h>
  60. #endif
  61. #ifdef HAVE_ARPA_INET_H
  62. #include <arpa/inet.h>
  63. #endif
  64. #ifdef HAVE_ERRNO_H
  65. #include <errno.h>
  66. #endif
  67. #ifdef HAVE_ASSERT_H
  68. #include <assert.h>
  69. #endif
  70. #ifdef HAVE_TIME_H
  71. #include <time.h>
  72. #endif
  73. #ifdef HAVE_WINSOCK_H
  74. #include <winsock.h>
  75. #endif
  76. #if _MSC_VER > 1300
  77. #include <winsock2.h>
  78. #include <ws2tcpip.h>
  79. #elif defined(_MSC_VER)
  80. #include <winsock.h>
  81. #endif
  82. #ifdef MS_WINDOWS
  83. #include <io.h>
  84. #include <process.h>
  85. #include <direct.h>
  86. #include <windows.h>
  87. #define snprintf _snprintf
  88. #endif
  89. #include "../common/crypto.h"
  90. #include "../common/tortls.h"
  91. #include "../common/log.h"
  92. #include "../common/util.h"
  93. #define MAXCONNECTIONS 1000 /* upper bound on max connections.
  94. can be lowered by config file */
  95. #define DEFAULT_BANDWIDTH_OP (1024 * 1000)
  96. #define MAX_NICKNAME_LEN 19
  97. #define MAX_DIR_SIZE 500000
  98. #ifdef TOR_PERF
  99. #define MAX_DNS_ENTRY_AGE (150*60)
  100. #else
  101. #define MAX_DNS_ENTRY_AGE (15*60)
  102. #endif
  103. #define CIRC_ID_TYPE_LOWER 0
  104. #define CIRC_ID_TYPE_HIGHER 1
  105. #define _CONN_TYPE_MIN 3
  106. #define CONN_TYPE_OR_LISTENER 3
  107. #define CONN_TYPE_OR 4
  108. #define CONN_TYPE_EXIT 5
  109. #define CONN_TYPE_AP_LISTENER 6
  110. #define CONN_TYPE_AP 7
  111. #define CONN_TYPE_DIR_LISTENER 8
  112. #define CONN_TYPE_DIR 9
  113. #define CONN_TYPE_DNSWORKER 10
  114. #define CONN_TYPE_CPUWORKER 11
  115. #define _CONN_TYPE_MAX 11
  116. #define LISTENER_STATE_READY 0
  117. #define _DNSWORKER_STATE_MIN 1
  118. #define DNSWORKER_STATE_IDLE 1
  119. #define DNSWORKER_STATE_BUSY 2
  120. #define _DNSWORKER_STATE_MAX 2
  121. #define _CPUWORKER_STATE_MIN 1
  122. #define CPUWORKER_STATE_IDLE 1
  123. #define CPUWORKER_STATE_BUSY_ONION 2
  124. #define CPUWORKER_STATE_BUSY_HANDSHAKE 3
  125. #define _CPUWORKER_STATE_MAX 3
  126. #define CPUWORKER_TASK_ONION CPUWORKER_STATE_BUSY_ONION
  127. #define _OR_CONN_STATE_MIN 1
  128. #define OR_CONN_STATE_CONNECTING 1 /* waiting for connect() to finish */
  129. #define OR_CONN_STATE_HANDSHAKING 2 /* SSL is handshaking, not done yet */
  130. #define OR_CONN_STATE_OPEN 3 /* ready to send/receive cells. */
  131. #define _OR_CONN_STATE_MAX 3
  132. #define _EXIT_CONN_STATE_MIN 1
  133. #define EXIT_CONN_STATE_RESOLVING 1 /* waiting for response from dns farm */
  134. #define EXIT_CONN_STATE_CONNECTING 2 /* waiting for connect() to finish */
  135. #define EXIT_CONN_STATE_OPEN 3
  136. #define EXIT_CONN_STATE_RESOLVEFAILED 4 /* waiting to be removed */
  137. #define _EXIT_CONN_STATE_MAX 4
  138. #if 0
  139. #define EXIT_CONN_STATE_CLOSE 3 /* flushing the buffer, then will close */
  140. #define EXIT_CONN_STATE_CLOSE_WAIT 4 /* have sent a destroy, awaiting a confirmation */
  141. #endif
  142. /* the AP state values must be disjoint from the EXIT state values */
  143. #define _AP_CONN_STATE_MIN 5
  144. #define AP_CONN_STATE_SOCKS_WAIT 5
  145. #define AP_CONN_STATE_RENDDESC_WAIT 6
  146. #define AP_CONN_STATE_CIRCUIT_WAIT 7
  147. #define AP_CONN_STATE_CONNECT_WAIT 8
  148. #define AP_CONN_STATE_OPEN 9
  149. #define _AP_CONN_STATE_MAX 9
  150. #define _DIR_CONN_STATE_MIN 1
  151. #define DIR_CONN_STATE_CONNECTING 1
  152. #define DIR_CONN_STATE_CLIENT_SENDING 2
  153. #define DIR_CONN_STATE_CLIENT_READING 3
  154. #define DIR_CONN_STATE_SERVER_COMMAND_WAIT 4
  155. #define DIR_CONN_STATE_SERVER_WRITING 5
  156. #define _DIR_CONN_STATE_MAX 5
  157. #define _DIR_PURPOSE_MIN 1
  158. #define DIR_PURPOSE_FETCH_DIR 1
  159. #define DIR_PURPOSE_FETCH_RENDDESC 2
  160. #define DIR_PURPOSE_HAS_FETCHED_RENDDESC 3
  161. #define DIR_PURPOSE_UPLOAD_DIR 4
  162. #define DIR_PURPOSE_UPLOAD_RENDDESC 5
  163. #define DIR_PURPOSE_SERVER 6
  164. #define _DIR_PURPOSE_MAX 6
  165. #define CIRCUIT_STATE_BUILDING 0 /* I'm the OP, still haven't done all my handshakes */
  166. #define CIRCUIT_STATE_ONIONSKIN_PENDING 1 /* waiting to process the onionskin */
  167. #define CIRCUIT_STATE_OR_WAIT 2 /* I'm the OP, my firsthop is still connecting */
  168. #define CIRCUIT_STATE_OPEN 3 /* onionskin(s) processed, ready to send/receive cells */
  169. #define _CIRCUIT_PURPOSE_MIN 1
  170. /* these circuits were initiated elsewhere */
  171. #define _CIRCUIT_PURPOSE_OR_MIN 1
  172. #define CIRCUIT_PURPOSE_OR 1 /* normal circuit, at OR. */
  173. #define CIRCUIT_PURPOSE_INTRO_POINT 2 /* At OR, from Bob, waiting for intro from Alices */
  174. #define CIRCUIT_PURPOSE_REND_POINT_WAITING 3 /* At OR, from Alice, waiting for Bob */
  175. #define CIRCUIT_PURPOSE_REND_ESTABLISHED 4 /* At OR, both circuits have this purpose */
  176. #define _CIRCUIT_PURPOSE_OR_MAX 4
  177. /* these circuits originate at this node */
  178. /* here's how circ client-side purposes work:
  179. * normal circuits are C_GENERAL.
  180. * circuits that are c_introducing are either on their way to
  181. * becoming open, or they are open but haven't been used yet.
  182. * (as soon as they are used, they are destroyed.)
  183. * circuits that are c_establish_rend are either on their way
  184. * to becoming open, or they are open and have sent the
  185. * establish_rendezvous cell but haven't received an ack.
  186. * circuits that are c_rend_ready are open and have received an
  187. * ack, but haven't heard from bob yet. if they have a
  188. * buildstate->pending_final_cpath then they're expecting a
  189. * cell from bob, else they're not.
  190. * circuits that are c_rend_joined are open, have heard from
  191. * bob, and are talking to him.
  192. */
  193. #define CIRCUIT_PURPOSE_C_GENERAL 5 /* normal circuit, with cpath */
  194. #define CIRCUIT_PURPOSE_C_INTRODUCING 6 /* at Alice, connecting to intro point */
  195. #define CIRCUIT_PURPOSE_C_INTRODUCE_ACK_WAIT 7 /* at alice, sent INTRODUCE1 to intro point, waiting for ACK/NAK */
  196. #define CIRCUIT_PURPOSE_C_ESTABLISH_REND 8 /* at Alice, waiting for ack */
  197. #define CIRCUIT_PURPOSE_C_REND_READY 9 /* at Alice, waiting for Bob */
  198. #define CIRCUIT_PURPOSE_C_REND_JOINED 10 /* at Alice, rendezvous established */
  199. #define CIRCUIT_PURPOSE_S_ESTABLISH_INTRO 11 /* at Bob, waiting for introductions */
  200. #define CIRCUIT_PURPOSE_S_INTRO 12 /* at Bob, successfully established intro */
  201. #define CIRCUIT_PURPOSE_S_CONNECT_REND 13 /* at Bob, connecting to rend point */
  202. #define CIRCUIT_PURPOSE_S_REND_JOINED 14 /* at Bob, rendezvous established.*/
  203. #define _CIRCUIT_PURPOSE_MAX 14
  204. #define CIRCUIT_PURPOSE_IS_ORIGIN(p) ((p)>_CIRCUIT_PURPOSE_OR_MAX)
  205. #define CIRCUIT_IS_ORIGIN(c) (CIRCUIT_PURPOSE_IS_ORIGIN((c)->purpose))
  206. #define RELAY_COMMAND_BEGIN 1
  207. #define RELAY_COMMAND_DATA 2
  208. #define RELAY_COMMAND_END 3
  209. #define RELAY_COMMAND_CONNECTED 4
  210. #define RELAY_COMMAND_SENDME 5
  211. #define RELAY_COMMAND_EXTEND 6
  212. #define RELAY_COMMAND_EXTENDED 7
  213. #define RELAY_COMMAND_TRUNCATE 8
  214. #define RELAY_COMMAND_TRUNCATED 9
  215. #define RELAY_COMMAND_DROP 10
  216. #define RELAY_COMMAND_RESOLVE 11
  217. #define RELAY_COMMAND_RESOLVED 12
  218. #define RELAY_COMMAND_ESTABLISH_INTRO 32
  219. #define RELAY_COMMAND_ESTABLISH_RENDEZVOUS 33
  220. #define RELAY_COMMAND_INTRODUCE1 34
  221. #define RELAY_COMMAND_INTRODUCE2 35
  222. #define RELAY_COMMAND_RENDEZVOUS1 36
  223. #define RELAY_COMMAND_RENDEZVOUS2 37
  224. /* DOCDOC Spec these next two. */
  225. #define RELAY_COMMAND_INTRO_ESTABLISHED 38
  226. #define RELAY_COMMAND_RENDEZVOUS_ESTABLISHED 39
  227. #define RELAY_COMMAND_INTRODUCE_ACK 40
  228. #define _MIN_END_STREAM_REASON 1
  229. #define END_STREAM_REASON_MISC 1
  230. #define END_STREAM_REASON_RESOLVEFAILED 2
  231. #define END_STREAM_REASON_CONNECTFAILED 3
  232. #define END_STREAM_REASON_EXITPOLICY 4
  233. #define END_STREAM_REASON_DESTROY 5
  234. #define END_STREAM_REASON_DONE 6
  235. #define END_STREAM_REASON_TIMEOUT 7
  236. #define _MAX_END_STREAM_REASON 7
  237. /* length of 'y' portion of 'y.onion' URL. */
  238. #define REND_SERVICE_ID_LEN 16
  239. /* Reasons used by connection_mark_for_close */
  240. #define CLOSE_REASON_UNUSED_OR_CONN 100
  241. #define CELL_DIRECTION_IN 1
  242. #define CELL_DIRECTION_OUT 2
  243. //#define EDGE_EXIT CONN_TYPE_EXIT
  244. //#define EDGE_AP CONN_TYPE_AP
  245. //#define CELL_DIRECTION(x) ((x) == EDGE_EXIT ? CELL_DIRECTION_IN : CELL_DIRECTION_OUT)
  246. #ifdef TOR_PERF
  247. #define CIRCWINDOW_START 10000
  248. #define CIRCWINDOW_INCREMENT 1000
  249. #define STREAMWINDOW_START 5000
  250. #define STREAMWINDOW_INCREMENT 500
  251. #else
  252. #define CIRCWINDOW_START 1000
  253. #define CIRCWINDOW_INCREMENT 100
  254. #define STREAMWINDOW_START 500
  255. #define STREAMWINDOW_INCREMENT 50
  256. #endif
  257. /* cell commands */
  258. #define CELL_PADDING 0
  259. #define CELL_CREATE 1
  260. #define CELL_CREATED 2
  261. #define CELL_RELAY 3
  262. #define CELL_DESTROY 4
  263. /* legal characters in a nickname */
  264. #define LEGAL_NICKNAME_CHARACTERS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
  265. #define SOCKS4_NETWORK_LEN 8
  266. /*
  267. * Relay payload:
  268. * Relay command [1 byte]
  269. * Recognized [2 bytes]
  270. * Stream ID [2 bytes]
  271. * Partial SHA-1 [4 bytes]
  272. * Length [2 bytes]
  273. * Relay payload [498 bytes]
  274. */
  275. #if 0
  276. #define CELL_RELAY_COMMAND(c) (*(uint8_t*)((c).payload))
  277. #define SET_CELL_RELAY_COMMAND(c,cmd) (*(uint8_t*)((c).payload) = (cmd))
  278. #define CELL_RELAY_RECOGNIZED(c) (ntohs(*(uint16_t*)((c).payload+1)))
  279. #define SET_CELL_RELAY_RECOGNIZED(c,r) (*(uint16_t*)((c).payload+1) = htons(r))
  280. #define STREAM_ID_SIZE 2
  281. //#define SET_CELL_STREAM_ID(c,id) memcpy((c).payload+1,(id),STREAM_ID_SIZE)
  282. #define CELL_RELAY_STREAM_ID(c) (ntohs(*(uint16_t*)((c).payload+3)))
  283. #define SET_CELL_RELAY_STREAM_ID(c,id) (*(uint16_t*)((c).payload+3) = htons(id))
  284. #define ZERO_STREAM 0
  285. /* integrity is the first 32 bits (in network order) of a sha-1 of all
  286. * cell payloads that are relay cells that have been sent / delivered
  287. * to the hop on the * circuit (the integrity is zeroed while doing
  288. * each calculation)
  289. */
  290. #define CELL_RELAY_INTEGRITY(c) (ntohl(*(uint32_t*)((c).payload+5)))
  291. #define SET_CELL_RELAY_INTEGRITY(c,i) (*(uint32_t*)((c).payload+5) = htonl(i))
  292. /* relay length is how many bytes are used in the cell payload past relay_header_size */
  293. #define CELL_RELAY_LENGTH(c) (ntohs(*(uint16_t*)((c).payload+9)))
  294. #define SET_CELL_RELAY_LENGTH(c,len) (*(uint16_t*)((c).payload+9) = htons(len))
  295. #endif
  296. #define CELL_PAYLOAD_SIZE 509
  297. #define CELL_NETWORK_SIZE 512
  298. #define RELAY_HEADER_SIZE (1+2+2+4+2)
  299. #define RELAY_PAYLOAD_SIZE (CELL_PAYLOAD_SIZE-RELAY_HEADER_SIZE)
  300. /* cell definition */
  301. typedef struct {
  302. uint16_t circ_id;
  303. unsigned char command;
  304. unsigned char payload[CELL_PAYLOAD_SIZE];
  305. } cell_t;
  306. typedef struct {
  307. uint8_t command;
  308. uint16_t recognized;
  309. uint16_t stream_id;
  310. char integrity[4];
  311. uint16_t length;
  312. } relay_header_t;
  313. typedef struct buf_t buf_t;
  314. typedef struct socks_request_t socks_request_t;
  315. #define CONNECTION_MAGIC 0x7C3C304Eu
  316. struct connection_t {
  317. uint32_t magic; /* for memory debugging */
  318. uint8_t type;
  319. uint8_t state;
  320. uint8_t purpose; /* only used for DIR types currently */
  321. uint8_t wants_to_read; /* should we start reading again once
  322. * the bandwidth throttler allows it?
  323. */
  324. uint8_t wants_to_write; /* should we start writing again once
  325. * the bandwidth throttler allows reads?
  326. */
  327. int s; /* our socket */
  328. int poll_index; /* index of this conn into the poll_array */
  329. int marked_for_close; /* should we close this conn on the next
  330. * iteration of the main loop?
  331. */
  332. char *marked_for_close_file; /* for debugging: in which file were we marked
  333. * for close? */
  334. int hold_open_until_flushed;
  335. buf_t *inbuf;
  336. int inbuf_reached_eof; /* did read() return 0 on this conn? */
  337. time_t timestamp_lastread; /* when was the last time poll() said we could read? */
  338. buf_t *outbuf;
  339. int outbuf_flushlen; /* how much data should we try to flush from the outbuf? */
  340. time_t timestamp_lastwritten; /* when was the last time poll() said we could write? */
  341. time_t timestamp_created; /* when was this connection_t created? */
  342. uint32_t addr; /* these two uniquely identify a router. Both in host order. */
  343. uint16_t port; /* if non-zero, they identify the guy on the other end
  344. * of the connection. */
  345. char *address; /* FQDN (or IP) of the guy on the other end.
  346. * strdup into this, because free_connection frees it
  347. */
  348. crypto_pk_env_t *onion_pkey; /* public RSA key for the other side's onions */
  349. crypto_pk_env_t *link_pkey; /* public RSA key for the other side's TLS */
  350. crypto_pk_env_t *identity_pkey; /* public RSA key for the other side's signing */
  351. char *nickname;
  352. /* Used only by OR connections: */
  353. tor_tls *tls;
  354. uint16_t next_circ_id; /* Which circ_id do we try to use next on this connection?
  355. * This is always in the range 0..1<<15-1.*/
  356. /* bandwidth and receiver_bucket only used by ORs in OPEN state: */
  357. int bandwidth; /* connection bandwidth. */
  358. int receiver_bucket; /* when this hits 0, stop receiving. Every second we
  359. * add 'bandwidth' to this, capping it at 10*bandwidth.
  360. */
  361. /* Used only by DIR and AP connections: */
  362. char rend_query[REND_SERVICE_ID_LEN+1];
  363. /* Used only by edge connections: */
  364. uint16_t stream_id;
  365. struct connection_t *next_stream; /* points to the next stream at this edge, if any */
  366. struct crypt_path_t *cpath_layer; /* a pointer to which node in the circ this conn exits at */
  367. int package_window; /* how many more relay cells can i send into the circuit? */
  368. int deliver_window; /* how many more relay cells can end at me? */
  369. int done_sending; /* for half-open connections; not used currently */
  370. int done_receiving;
  371. char has_sent_end; /* for debugging: set once we've set the stream end,
  372. and check in circuit_about_to_close_connection() */
  373. char num_retries; /* how many times have we re-tried beginning this stream? */
  374. /* Used only by AP connections */
  375. socks_request_t *socks_request;
  376. };
  377. typedef struct connection_t connection_t;
  378. #define EXIT_POLICY_ACCEPT 1
  379. #define EXIT_POLICY_REJECT 2
  380. struct exit_policy_t {
  381. char policy_type;
  382. char *string;
  383. uint32_t addr;
  384. uint32_t msk;
  385. uint16_t prt_min;
  386. uint16_t prt_max;
  387. struct exit_policy_t *next;
  388. };
  389. /* config stuff we know about the other ORs in the network */
  390. typedef struct {
  391. char *address;
  392. char *nickname;
  393. uint32_t addr; /* all host order */
  394. uint16_t or_port;
  395. uint16_t socks_port;
  396. uint16_t dir_port;
  397. time_t published_on;
  398. crypto_pk_env_t *onion_pkey; /* public RSA key for onions */
  399. crypto_pk_env_t *link_pkey; /* public RSA key for TLS */
  400. crypto_pk_env_t *identity_pkey; /* public RSA key for signing */
  401. int is_running;
  402. char *platform;
  403. /* link info */
  404. uint32_t bandwidthrate;
  405. uint32_t bandwidthburst;
  406. struct exit_policy_t *exit_policy;
  407. } routerinfo_t;
  408. #define MAX_ROUTERS_IN_DIR 1024
  409. typedef struct {
  410. smartlist_t *routers;
  411. char *software_versions;
  412. time_t published_on;
  413. } routerlist_t;
  414. struct crypt_path_t {
  415. /* crypto environments */
  416. crypto_cipher_env_t *f_crypto;
  417. crypto_cipher_env_t *b_crypto;
  418. crypto_digest_env_t *f_digest; /* for integrity checking */
  419. crypto_digest_env_t *b_digest;
  420. crypto_dh_env_t *handshake_state;
  421. char handshake_digest[DIGEST_LEN];/* KH in tor-spec.txt */
  422. uint32_t addr;
  423. uint16_t port;
  424. uint8_t state;
  425. #define CPATH_STATE_CLOSED 0
  426. #define CPATH_STATE_AWAITING_KEYS 1
  427. #define CPATH_STATE_OPEN 2
  428. struct crypt_path_t *next;
  429. struct crypt_path_t *prev; /* doubly linked list */
  430. int package_window;
  431. int deliver_window;
  432. };
  433. #define DH_KEY_LEN DH_BYTES
  434. #define ONIONSKIN_CHALLENGE_LEN (16+DH_KEY_LEN)
  435. #define ONIONSKIN_REPLY_LEN (DH_KEY_LEN+20)
  436. #define REND_COOKIE_LEN DIGEST_LEN
  437. typedef struct crypt_path_t crypt_path_t;
  438. typedef struct {
  439. int desired_path_len;
  440. /* nickname of planned exit node */
  441. char *chosen_exit;
  442. /* cpath to append after rendezvous. */
  443. struct crypt_path_t *pending_final_cpath;
  444. } cpath_build_state_t;
  445. /* struct for a path (circuit) through the network */
  446. #define CIRCUIT_MAGIC 0x35315243u
  447. struct circuit_t {
  448. uint32_t magic; /* for memory debugging. */
  449. int marked_for_close; /* Should we close this circuit at the end of the main
  450. * loop? */
  451. char *marked_for_close_file;
  452. uint32_t n_addr;
  453. uint16_t n_port;
  454. connection_t *p_conn;
  455. connection_t *n_conn; /* for the OR conn, if there is one */
  456. connection_t *p_streams;
  457. connection_t *n_streams;
  458. uint16_t next_stream_id;
  459. int package_window;
  460. int deliver_window;
  461. uint16_t p_circ_id; /* circuit identifiers */
  462. uint16_t n_circ_id;
  463. crypto_cipher_env_t *p_crypto; /* used only for intermediate hops */
  464. crypto_cipher_env_t *n_crypto;
  465. crypto_digest_env_t *p_digest; /* for integrity checking, */
  466. crypto_digest_env_t *n_digest; /* intermediate hops only */
  467. cpath_build_state_t *build_state;
  468. crypt_path_t *cpath;
  469. char onionskin[ONIONSKIN_CHALLENGE_LEN]; /* for storage while onionskin pending */
  470. char handshake_digest[DIGEST_LEN]; /* Stores KH for intermediate hops */
  471. time_t timestamp_created;
  472. time_t timestamp_dirty; /* when the circuit was first used, or 0 if clean */
  473. uint8_t state;
  474. uint8_t purpose;
  475. /*
  476. * rend_query holds y portion of y.onion (nul-terminated) if purpose
  477. * is C_INTRODUCING or C_ESTABLISH_REND, or is a C_GENERAL for a
  478. * hidden service, or is S_*.
  479. */
  480. char rend_query[REND_SERVICE_ID_LEN+1];
  481. /* rend_pk_digest holds a hash of location-hidden service's PK if
  482. * purpose is INTRO_POINT or S_ESTABLISH_INTRO or S_RENDEZVOUSING
  483. */
  484. char rend_pk_digest[DIGEST_LEN];
  485. /* Holds rendezvous cookie if purpose is REND_POINT_WAITING or
  486. * C_ESTABLISH_REND. Filled with zeroes otherwise.
  487. */
  488. char rend_cookie[REND_COOKIE_LEN];
  489. /* Points to spliced circuit if purpose is REND_ESTABLISHED, and circuit
  490. * is not marked for close. */
  491. struct circuit_t *rend_splice;
  492. struct circuit_t *next;
  493. };
  494. typedef struct circuit_t circuit_t;
  495. typedef struct circuit_data_rend_point_t {
  496. /* for CIRCUIT_PURPOSE_INTRO_POINT (at OR, from Bob, waiting for intro) */
  497. char rend_cookie[20];
  498. } circuit_data_intro_point_t;
  499. typedef struct {
  500. char *LogLevel;
  501. char *LogFile;
  502. char *DebugLogFile;
  503. char *DataDirectory;
  504. char *RouterFile;
  505. char *Nickname;
  506. char *Address;
  507. char *PidFile;
  508. char *ExitNodes;
  509. char *EntryNodes;
  510. char *ExcludeNodes;
  511. char *RendNodes;
  512. char *RendExcludeNodes;
  513. char *ExitPolicy;
  514. char *SocksBindAddress;
  515. char *ORBindAddress;
  516. char *DirBindAddress;
  517. char *RecommendedVersions;
  518. char *User;
  519. char *Group;
  520. double PathlenCoinWeight;
  521. int ORPort;
  522. int SocksPort;
  523. int DirPort;
  524. int MaxConn;
  525. int TrafficShaping;
  526. int LinkPadding;
  527. int IgnoreVersion;
  528. int RunAsDaemon;
  529. int DirRebuildPeriod;
  530. int DirFetchPostPeriod;
  531. int KeepalivePeriod;
  532. int MaxOnionsPending;
  533. int NewCircuitPeriod;
  534. int BandwidthRate;
  535. int BandwidthBurst;
  536. int NumCpus;
  537. int loglevel;
  538. int RunTesting;
  539. struct config_line_t *RendConfigLines;
  540. } or_options_t;
  541. /* XXX are these good enough defaults? */
  542. #define MAX_SOCKS_REPLY_LEN 1024
  543. #define MAX_SOCKS_ADDR_LEN 256
  544. struct socks_request_t {
  545. char socks_version;
  546. int replylen;
  547. char reply[MAX_SOCKS_REPLY_LEN];
  548. int has_finished; /* has the socks handshake finished? */
  549. char address[MAX_SOCKS_ADDR_LEN];
  550. uint16_t port;
  551. };
  552. /* all the function prototypes go here */
  553. /********************************* buffers.c ***************************/
  554. int find_on_inbuf(char *string, int string_len, buf_t *buf);
  555. buf_t *buf_new();
  556. buf_t *buf_new_with_capacity(size_t size);
  557. void buf_free(buf_t *buf);
  558. void buf_clear(buf_t *buf);
  559. size_t buf_datalen(const buf_t *buf);
  560. size_t buf_capacity(const buf_t *buf);
  561. const char *_buf_peek_raw_buffer(const buf_t *buf);
  562. int read_to_buf(int s, int at_most, buf_t *buf, int *reached_eof);
  563. int read_to_buf_tls(tor_tls *tls, int at_most, buf_t *buf);
  564. int flush_buf(int s, buf_t *buf, int *buf_flushlen);
  565. int flush_buf_tls(tor_tls *tls, buf_t *buf, int *buf_flushlen);
  566. int write_to_buf(const char *string, int string_len, buf_t *buf);
  567. int fetch_from_buf(char *string, int string_len, buf_t *buf);
  568. int fetch_from_buf_http(buf_t *buf,
  569. char **headers_out, int max_headerlen,
  570. char **body_out, int *body_used, int max_bodylen);
  571. int fetch_from_buf_socks(buf_t *buf, socks_request_t *req);
  572. void assert_buf_ok(buf_t *buf);
  573. /********************************* circuit.c ***************************/
  574. extern char *circuit_state_to_string[];
  575. void circuit_add(circuit_t *circ);
  576. void circuit_remove(circuit_t *circ);
  577. circuit_t *circuit_new(uint16_t p_circ_id, connection_t *p_conn);
  578. void circuit_close_all_marked(void);
  579. void circuit_free(circuit_t *circ);
  580. void circuit_free_cpath(crypt_path_t *cpath);
  581. int _circuit_mark_for_close(circuit_t *circ);
  582. #define circuit_mark_for_close(c) \
  583. do { \
  584. if (_circuit_mark_for_close(c)<0) { \
  585. log(LOG_WARN,"Duplicate call to circuit_mark_for_close at %s:%d (first at %s:%d)", \
  586. __FILE__,__LINE__,c->marked_for_close_file,c->marked_for_close); \
  587. } else { \
  588. c->marked_for_close_file = __FILE__; \
  589. c->marked_for_close = __LINE__; \
  590. } \
  591. } while (0)
  592. circuit_t *circuit_get_by_circ_id_conn(uint16_t circ_id, connection_t *conn);
  593. circuit_t *circuit_get_by_conn(connection_t *conn);
  594. circuit_t *circuit_get_best(connection_t *conn,
  595. int must_be_open, uint8_t purpose);
  596. circuit_t *circuit_get_next_by_pk_and_purpose(circuit_t *circuit,
  597. const char *servid, uint8_t purpose);
  598. circuit_t *circuit_get_rendezvous(const char *cookie);
  599. void circuit_expire_building(void);
  600. int circuit_count_building(void);
  601. int circuit_stream_is_being_handled(connection_t *conn);
  602. void circuit_build_needed_circs(time_t now);
  603. int circuit_receive_relay_cell(cell_t *cell, circuit_t *circ,
  604. int cell_direction);
  605. int circuit_package_relay_cell(cell_t *cell, circuit_t *circ,
  606. int cell_direction, crypt_path_t *layer_hint);
  607. void circuit_resume_edge_reading(circuit_t *circ, crypt_path_t *layer_hint);
  608. int circuit_consider_stop_edge_reading(circuit_t *circ, crypt_path_t *layer_hint);
  609. void circuit_consider_sending_sendme(circuit_t *circ, crypt_path_t *layer_hint);
  610. void circuit_detach_stream(circuit_t *circ, connection_t *conn);
  611. void circuit_about_to_close_connection(connection_t *conn);
  612. void circuit_log_path(int severity, circuit_t *circ);
  613. void circuit_dump_by_conn(connection_t *conn, int severity);
  614. void circuit_expire_unused_circuits(void);
  615. circuit_t *circuit_launch_new(uint8_t purpose, const char *exit_nickname);
  616. void circuit_increment_failure_count(void);
  617. void circuit_reset_failure_count(void);
  618. void circuit_n_conn_open(connection_t *or_conn);
  619. int circuit_send_next_onion_skin(circuit_t *circ);
  620. int circuit_extend(cell_t *cell, circuit_t *circ);
  621. #define CPATH_KEY_MATERIAL_LEN (20*2+16*2)
  622. int circuit_init_cpath_crypto(crypt_path_t *cpath, char *key_data,int reverse);
  623. int circuit_finish_handshake(circuit_t *circ, char *reply);
  624. int circuit_truncated(circuit_t *circ, crypt_path_t *layer);
  625. void assert_cpath_ok(const crypt_path_t *c);
  626. void assert_cpath_layer_ok(const crypt_path_t *c);
  627. void assert_circuit_ok(const circuit_t *c);
  628. extern unsigned long stats_n_relay_cells_relayed;
  629. extern unsigned long stats_n_relay_cells_delivered;
  630. /********************************* command.c ***************************/
  631. void command_process_cell(cell_t *cell, connection_t *conn);
  632. extern unsigned long stats_n_padding_cells_processed;
  633. extern unsigned long stats_n_create_cells_processed;
  634. extern unsigned long stats_n_created_cells_processed;
  635. extern unsigned long stats_n_relay_cells_processed;
  636. extern unsigned long stats_n_destroy_cells_processed;
  637. /********************************* config.c ***************************/
  638. struct config_line_t {
  639. char *key;
  640. char *value;
  641. struct config_line_t *next;
  642. };
  643. int config_assign_default_dirservers(void);
  644. int getconfig(int argc, char **argv, or_options_t *options);
  645. /********************************* connection.c ***************************/
  646. #define CONN_TYPE_TO_STRING(t) (((t) < _CONN_TYPE_MIN || (t) > _CONN_TYPE_MAX) ? \
  647. "Unknown" : conn_type_to_string[(t)])
  648. extern char *conn_type_to_string[];
  649. connection_t *connection_new(int type);
  650. void connection_free(connection_t *conn);
  651. void connection_free_all(void);
  652. void connection_close_immediate(connection_t *conn);
  653. int _connection_mark_for_close(connection_t *conn, char reason);
  654. #define connection_mark_for_close(c,r) \
  655. do { \
  656. if (_connection_mark_for_close(c,r)<0) { \
  657. log(LOG_WARN,"Duplicate call to connection_mark_for_close at %s:%d (first at %s:%d)", \
  658. __FILE__,__LINE__,c->marked_for_close_file,c->marked_for_close); \
  659. } else { \
  660. c->marked_for_close_file = __FILE__; \
  661. c->marked_for_close = __LINE__; \
  662. } \
  663. } while (0)
  664. void connection_expire_held_open(void);
  665. int connection_create_listener(char *bindaddress, uint16_t bindport, int type);
  666. int connection_connect(connection_t *conn, char *address, uint32_t addr, uint16_t port);
  667. int retry_all_connections(void);
  668. void connection_bucket_init(void);
  669. void connection_bucket_refill(struct timeval *now);
  670. int connection_handle_read(connection_t *conn);
  671. int connection_read_to_buf(connection_t *conn);
  672. int connection_fetch_from_buf(char *string, int len, connection_t *conn);
  673. int connection_find_on_inbuf(char *string, int len, connection_t *conn);
  674. int connection_wants_to_flush(connection_t *conn);
  675. int connection_outbuf_too_full(connection_t *conn);
  676. int connection_handle_write(connection_t *conn);
  677. void connection_write_to_buf(const char *string, int len, connection_t *conn);
  678. connection_t *connection_twin_get_by_addr_port(uint32_t addr, uint16_t port);
  679. connection_t *connection_exact_get_by_addr_port(uint32_t addr, uint16_t port);
  680. connection_t *connection_get_by_type(int type);
  681. connection_t *connection_get_by_type_state(int type, int state);
  682. connection_t *connection_get_by_type_state_lastwritten(int type, int state);
  683. connection_t *connection_get_by_type_rendquery(int type, char *rendquery);
  684. #define connection_speaks_cells(conn) ((conn)->type == CONN_TYPE_OR)
  685. #define connection_has_pending_tls_data(conn) \
  686. ((conn)->type == CONN_TYPE_OR && \
  687. (conn)->state == OR_CONN_STATE_OPEN && \
  688. tor_tls_get_pending_bytes((conn)->tls))
  689. int connection_is_listener(connection_t *conn);
  690. int connection_state_is_open(connection_t *conn);
  691. int connection_send_destroy(uint16_t circ_id, connection_t *conn);
  692. int connection_process_inbuf(connection_t *conn);
  693. int connection_finished_flushing(connection_t *conn);
  694. void assert_connection_ok(connection_t *conn, time_t now);
  695. /********************************* connection_edge.c ***************************/
  696. void relay_header_pack(char *dest, const relay_header_t *src);
  697. void relay_header_unpack(relay_header_t *dest, const char *src);
  698. int connection_edge_process_inbuf(connection_t *conn);
  699. int connection_edge_destroy(uint16_t circ_id, connection_t *conn);
  700. int connection_edge_end(connection_t *conn, char reason, crypt_path_t *cpath_layer);
  701. int connection_edge_send_command(connection_t *fromconn, circuit_t *circ,
  702. int relay_command, const char *payload,
  703. int payload_len, crypt_path_t *cpath_layer);
  704. int connection_edge_process_relay_cell(cell_t *cell, circuit_t *circ,
  705. connection_t *conn,
  706. crypt_path_t *layer_hint);
  707. int connection_edge_finished_flushing(connection_t *conn);
  708. int connection_edge_package_raw_inbuf(connection_t *conn);
  709. int connection_ap_handshake_attach_circuit(connection_t *conn);
  710. int connection_ap_handshake_send_begin(connection_t *ap_conn, circuit_t *circ);
  711. int connection_ap_make_bridge(char *address, uint16_t port);
  712. void connection_ap_handshake_socks_reply(connection_t *conn, char *reply,
  713. int replylen, char success);
  714. void connection_exit_connect(connection_t *conn);
  715. int connection_edge_is_rendezvous_stream(connection_t *conn);
  716. int connection_ap_can_use_exit(connection_t *conn, routerinfo_t *exit);
  717. void connection_ap_expire_beginning(void);
  718. void connection_ap_attach_pending(void);
  719. extern uint64_t stats_n_data_cells_packaged;
  720. extern uint64_t stats_n_data_bytes_packaged;
  721. extern uint64_t stats_n_data_cells_received;
  722. extern uint64_t stats_n_data_bytes_received;
  723. void client_dns_init(void);
  724. void client_dns_clean(void);
  725. /********************************* connection_or.c ***************************/
  726. int connection_or_process_inbuf(connection_t *conn);
  727. int connection_or_finished_flushing(connection_t *conn);
  728. void connection_or_init_conn_from_router(connection_t *conn, routerinfo_t *router);
  729. connection_t *connection_or_connect(routerinfo_t *router);
  730. int connection_tls_start_handshake(connection_t *conn, int receiving);
  731. int connection_tls_continue_handshake(connection_t *conn);
  732. void connection_or_write_cell_to_buf(const cell_t *cell, connection_t *conn);
  733. /********************************* cpuworker.c *****************************/
  734. void cpu_init(void);
  735. int connection_cpu_finished_flushing(connection_t *conn);
  736. int connection_cpu_process_inbuf(connection_t *conn);
  737. int cpuworker_main(void *data);
  738. int assign_to_cpuworker(connection_t *cpuworker, unsigned char question_type,
  739. void *task);
  740. /********************************* directory.c ***************************/
  741. void directory_initiate_command(routerinfo_t *router, int purpose,
  742. const char *payload, int payload_len);
  743. int connection_dir_process_inbuf(connection_t *conn);
  744. int connection_dir_finished_flushing(connection_t *conn);
  745. /********************************* dns.c ***************************/
  746. void dns_init(void);
  747. int connection_dns_finished_flushing(connection_t *conn);
  748. int connection_dns_process_inbuf(connection_t *conn);
  749. void connection_dns_remove(connection_t *conn);
  750. void assert_connection_edge_not_dns_pending(connection_t *conn);
  751. void assert_all_pending_dns_resolves_ok(void);
  752. void dns_cancel_pending_resolve(char *question);
  753. int dns_resolve(connection_t *exitconn);
  754. /********************************* main.c ***************************/
  755. int connection_add(connection_t *conn);
  756. int connection_remove(connection_t *conn);
  757. void connection_set_poll_socket(connection_t *conn);
  758. void get_connection_array(connection_t ***array, int *n);
  759. void connection_watch_events(connection_t *conn, short events);
  760. int connection_is_reading(connection_t *conn);
  761. void connection_stop_reading(connection_t *conn);
  762. void connection_start_reading(connection_t *conn);
  763. int connection_is_writing(connection_t *conn);
  764. void connection_stop_writing(connection_t *conn);
  765. void connection_start_writing(connection_t *conn);
  766. void directory_has_arrived(void);
  767. int main(int argc, char *argv[]);
  768. /********************************* onion.c ***************************/
  769. int decide_circ_id_type(char *local_nick, char *remote_nick);
  770. int onion_pending_add(circuit_t *circ);
  771. circuit_t *onion_next_task(void);
  772. void onion_pending_remove(circuit_t *circ);
  773. int onionskin_answer(circuit_t *circ, unsigned char *payload, unsigned char *keys);
  774. void onion_append_to_cpath(crypt_path_t **head_ptr, crypt_path_t *new_hop);
  775. int onion_extend_cpath(crypt_path_t **head_ptr, cpath_build_state_t *state,
  776. routerinfo_t **router_out);
  777. int onion_skin_create(crypto_pk_env_t *router_key,
  778. crypto_dh_env_t **handshake_state_out,
  779. char *onion_skin_out);
  780. int onion_skin_server_handshake(char *onion_skin,
  781. crypto_pk_env_t *private_key,
  782. char *handshake_reply_out,
  783. char *key_out,
  784. int key_out_len);
  785. int onion_skin_client_handshake(crypto_dh_env_t *handshake_state,
  786. char *handshake_reply,
  787. char *key_out,
  788. int key_out_len);
  789. cpath_build_state_t *onion_new_cpath_build_state(uint8_t purpose,
  790. const char *exit_nickname);
  791. /********************************* router.c ***************************/
  792. void set_onion_key(crypto_pk_env_t *k);
  793. crypto_pk_env_t *get_onion_key(void);
  794. void set_identity_key(crypto_pk_env_t *k);
  795. crypto_pk_env_t *get_identity_key(void);
  796. crypto_pk_env_t *get_link_key(void);
  797. int init_keys(void);
  798. crypto_pk_env_t *init_key_from_file(const char *fname);
  799. void router_retry_connections(void);
  800. void router_upload_dir_desc_to_dirservers(void);
  801. void router_post_to_dirservers(uint8_t purpose, const char *payload, int payload_len);
  802. int router_compare_to_my_exit_policy(connection_t *conn);
  803. routerinfo_t *router_get_my_routerinfo(void);
  804. const char *router_get_my_descriptor(void);
  805. int router_is_me(routerinfo_t *router);
  806. int router_rebuild_descriptor(void);
  807. int router_dump_router_to_string(char *s, int maxlen, routerinfo_t *router,
  808. crypto_pk_env_t *ident_key);
  809. /********************************* routerlist.c ***************************/
  810. routerinfo_t *router_pick_directory_server(void);
  811. struct smartlist_t;
  812. routerinfo_t *router_choose_random_node(routerlist_t *dir,
  813. char *preferred, char *excluded,
  814. struct smartlist_t *excludedsmartlist);
  815. routerinfo_t *router_get_by_addr_port(uint32_t addr, uint16_t port);
  816. routerinfo_t *router_get_by_link_pk(crypto_pk_env_t *pk);
  817. routerinfo_t *router_get_by_nickname(char *nickname);
  818. void router_get_routerlist(routerlist_t **prouterlist);
  819. void routerinfo_free(routerinfo_t *router);
  820. routerinfo_t *routerinfo_copy(const routerinfo_t *router);
  821. int router_version_supports_rendezvous(routerinfo_t *router);
  822. void router_add_nonrendezvous_to_list(smartlist_t *sl);
  823. void router_mark_as_down(char *nickname);
  824. int router_set_routerlist_from_file(char *routerfile);
  825. int router_set_routerlist_from_string(const char *s);
  826. int router_get_dir_hash(const char *s, char *digest);
  827. int router_get_router_hash(const char *s, char *digest);
  828. int router_set_routerlist_from_directory(const char *s, crypto_pk_env_t *pkey);
  829. routerinfo_t *router_get_entry_from_string(const char *s, const char *end);
  830. int router_add_exit_policy_from_string(routerinfo_t *router, const char *s);
  831. int router_compare_addr_to_exit_policy(uint32_t addr, uint16_t port,
  832. struct exit_policy_t *policy);
  833. #define ADDR_POLICY_ACCEPTED 0
  834. #define ADDR_POLICY_REJECTED -1
  835. #define ADDR_POLICY_UNKNOWN 1
  836. int router_exit_policy_all_routers_reject(uint32_t addr, uint16_t port);
  837. int router_exit_policy_rejects_all(routerinfo_t *router);
  838. /********************************* dirserv.c ***************************/
  839. int dirserv_add_own_fingerprint(const char *nickname, crypto_pk_env_t *pk);
  840. int dirserv_parse_fingerprint_file(const char *fname);
  841. int dirserv_router_fingerprint_is_known(const routerinfo_t *router);
  842. void dirserv_free_fingerprint_list();
  843. int dirserv_add_descriptor(const char **desc);
  844. int dirserv_init_from_directory_string(const char *dir);
  845. void dirserv_free_descriptors();
  846. int dirserv_dump_directory_to_string(char *s, int maxlen,
  847. crypto_pk_env_t *private_key);
  848. void directory_set_dirty(void);
  849. size_t dirserv_get_directory(const char **cp);
  850. void dirserv_remove_old_servers(void);
  851. /********************************* rephist.c ***************************/
  852. void rep_hist_init(void);
  853. void rep_hist_note_connect_failed(const char* nickname, time_t when);
  854. void rep_hist_note_connect_succeeded(const char* nickname, time_t when);
  855. void rep_hist_note_disconnect(const char* nickname, time_t when);
  856. void rep_hist_note_connection_died(const char* nickname, time_t when);
  857. void rep_hist_note_extend_succeeded(const char *from_name,
  858. const char *to_name);
  859. void rep_hist_note_extend_failed(const char *from_name, const char *to_name);
  860. void rep_hist_dump_stats(time_t now, int severity);
  861. /********************************* rendclient.c ***************************/
  862. void rend_client_introcirc_is_open(circuit_t *circ);
  863. void rend_client_rendcirc_is_open(circuit_t *circ);
  864. int rend_client_introduction_acked(circuit_t *circ, const char *request, int request_len);
  865. int rend_client_rendezvous_acked(circuit_t *circ, const char *request, int request_len);
  866. int rend_client_receive_rendezvous(circuit_t *circ, const char *request, int request_len);
  867. void rend_client_desc_fetched(char *query, int success);
  868. int rend_cmp_service_ids(char *one, char *two);
  869. char *rend_client_get_random_intro(char *query);
  870. int rend_parse_rendezvous_address(char *address);
  871. int rend_client_send_establish_rendezvous(circuit_t *circ);
  872. int rend_client_send_introduction(circuit_t *introcirc, circuit_t *rendcirc);
  873. /********************************* rendcommon.c ***************************/
  874. typedef struct rend_service_descriptor_t {
  875. crypto_pk_env_t *pk;
  876. time_t timestamp;
  877. int n_intro_points;
  878. char **intro_points;
  879. } rend_service_descriptor_t;
  880. void rend_process_relay_cell(circuit_t *circ, int command, int length,
  881. const char *payload);
  882. void rend_service_descriptor_free(rend_service_descriptor_t *desc);
  883. int rend_encode_service_descriptor(rend_service_descriptor_t *desc,
  884. crypto_pk_env_t *key,
  885. char **str_out,
  886. int *len_out);
  887. rend_service_descriptor_t *rend_parse_service_descriptor(const char *str, int len);
  888. int rend_get_service_id(crypto_pk_env_t *pk, char *out);
  889. typedef struct rend_cache_entry_t {
  890. int len; /* Length of desc */
  891. time_t received; /* When did we get the descriptor? */
  892. char *desc; /* Service descriptor */
  893. rend_service_descriptor_t *parsed; /* Parsed value of 'desc' */
  894. } rend_cache_entry_t;
  895. void rend_cache_init(void);
  896. void rend_cache_clean(void);
  897. int rend_valid_service_id(char *query);
  898. int rend_cache_lookup_desc(char *query, const char **desc, int *desc_len);
  899. int rend_cache_lookup_entry(char *query, rend_cache_entry_t **entry_out);
  900. int rend_cache_store(char *desc, int desc_len);
  901. /********************************* rendservice.c ***************************/
  902. int rend_config_services(or_options_t *options);
  903. int rend_service_init_keys(void);
  904. int rend_services_init(void);
  905. void rend_service_intro_is_ready(circuit_t *circuit);
  906. int rend_service_intro_established(circuit_t *circuit, const char *request, int request_len);
  907. void rend_service_rendezvous_is_ready(circuit_t *circuit);
  908. int rend_service_introduce(circuit_t *circuit, const char *request, int request_len);
  909. int rend_service_set_connection_addr_port(connection_t *conn, circuit_t *circ);
  910. void rend_service_dump_stats(int severity);
  911. /********************************* rendmid.c *******************************/
  912. int rend_mid_establish_intro(circuit_t *circ, const char *request, int request_len);
  913. int rend_mid_introduce(circuit_t *circ, const char *request, int request_len);
  914. int rend_mid_establish_rendezvous(circuit_t *circ, const char *request, int request_len);
  915. int rend_mid_rendezvous(circuit_t *circ, const char *request, int request_len);
  916. #endif
  917. /*
  918. Local Variables:
  919. mode:c
  920. indent-tabs-mode:nil
  921. c-basic-offset:2
  922. End:
  923. */