pick nodes for a circuit only from those the directory says are up
[tor.git] / src / or / or.h
blob6d750072064d80ffedee6065ffae1078ced479b0
1 /* Copyright 2001,2002,2003 Roger Dingledine, Matej Pfajfar. */
2 /* See LICENSE for licensing information */
3 /* $Id$ */
5 #ifndef __OR_H
6 #define __OR_H
8 #include "orconfig.h"
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <limits.h>
13 #ifdef HAVE_UNISTD_H
14 #include <unistd.h>
15 #endif
16 #ifdef HAVE_STRING_H
17 #include <string.h>
18 #endif
19 #ifdef HAVE_SIGNAL_H
20 #include <signal.h>
21 #endif
22 #ifdef HAVE_NETDB_H
23 #include <netdb.h>
24 #endif
25 #ifdef HAVE_CTYPE_H
26 #include <ctype.h>
27 #endif
28 #include "../common/torint.h"
29 #ifdef HAVE_SYS_POLL_H
30 #include <sys/poll.h>
31 #elif HAVE_POLL_H
32 #include <poll.h>
33 #else
34 #include "../common/fakepoll.h"
35 #endif
36 #ifdef HAVE_SYS_TYPES_H
37 #include <sys/types.h> /* Must be included before sys/stat.h for Ultrix */
38 #endif
39 #ifdef HAVE_SYS_WAIT_H
40 #include <sys/wait.h>
41 #endif
42 #ifdef HAVE_SYS_FCNTL_H
43 #include <sys/fcntl.h>
44 #endif
45 #ifdef HAVE_FCNTL_H
46 #include <fcntl.h>
47 #endif
48 #ifdef HAVE_SYS_IOCTL_H
49 #include <sys/ioctl.h>
50 #endif
51 #ifdef HAVE_SYS_SOCKET_H
52 #include <sys/socket.h>
53 #endif
54 #ifdef HAVE_SYS_TIME_H
55 #include <sys/time.h>
56 #endif
57 #ifdef HAVE_SYS_STAT_H
58 #include <sys/stat.h>
59 #endif
60 #ifdef HAVE_NETINET_IN_H
61 #include <netinet/in.h>
62 #endif
63 #ifdef HAVE_ARPA_INET_H
64 #include <arpa/inet.h>
65 #endif
66 #ifdef HAVE_ERRNO_H
67 #include <errno.h>
68 #endif
69 #ifdef HAVE_ASSERT_H
70 #include <assert.h>
71 #endif
72 #ifdef HAVE_TIME_H
73 #include <time.h>
74 #endif
75 #ifdef HAVE_PWD_H
76 #include <pwd.h>
77 #endif
78 #ifdef HAVE_GRP_H
79 #include <grp.h>
80 #endif
81 #ifdef HAVE_WINSOCK_H
82 #include <winsock.h>
83 #endif
84 #if _MSC_VER > 1300
85 #include <winsock2.h>
86 #include <ws2tcpip.h>
87 #elif defined(_MSC_VER)
88 #include <winsock.h>
89 #endif
91 #ifdef MS_WINDOWS
92 #include <io.h>
93 #include <process.h>
94 #define WIN32_LEAN_AND_MEAN
95 #include <windows.h>
96 #define snprintf _snprintf
97 #endif
99 #include "../common/crypto.h"
100 #include "../common/tortls.h"
101 #include "../common/log.h"
102 #include "../common/util.h"
104 #define MAXCONNECTIONS 1000 /* upper bound on max connections.
105 can be lowered by config file */
107 #define DEFAULT_BANDWIDTH_OP (1024 * 1000)
108 #define MAX_NICKNAME_LEN 32
109 #define MAX_DIR_SIZE 50000 /* XXX, big enough? */
111 #define CIRC_ID_TYPE_LOWER 0
112 #define CIRC_ID_TYPE_HIGHER 1
114 #define _CONN_TYPE_MIN 3
115 #define CONN_TYPE_OR_LISTENER 3
116 #define CONN_TYPE_OR 4
117 #define CONN_TYPE_EXIT 5
118 #define CONN_TYPE_AP_LISTENER 6
119 #define CONN_TYPE_AP 7
120 #define CONN_TYPE_DIR_LISTENER 8
121 #define CONN_TYPE_DIR 9
122 #define CONN_TYPE_DNSWORKER 10
123 #define CONN_TYPE_CPUWORKER 11
124 #define _CONN_TYPE_MAX 11
126 #define LISTENER_STATE_READY 0
128 #define _DNSWORKER_STATE_MIN 1
129 #define DNSWORKER_STATE_IDLE 1
130 #define DNSWORKER_STATE_BUSY 2
131 #define _DNSWORKER_STATE_MAX 2
133 #define _CPUWORKER_STATE_MIN 1
134 #define CPUWORKER_STATE_IDLE 1
135 #define CPUWORKER_STATE_BUSY_ONION 2
136 #define CPUWORKER_STATE_BUSY_HANDSHAKE 3
137 #define _CPUWORKER_STATE_MAX 3
139 #define CPUWORKER_TASK_ONION CPUWORKER_STATE_BUSY_ONION
141 #define _OR_CONN_STATE_MIN 1
142 #define OR_CONN_STATE_CONNECTING 1 /* waiting for connect() to finish */
143 #define OR_CONN_STATE_HANDSHAKING 2 /* SSL is handshaking, not done yet */
144 #define OR_CONN_STATE_OPEN 3 /* ready to send/receive cells. */
145 #define _OR_CONN_STATE_MAX 3
147 #define _EXIT_CONN_STATE_MIN 1
148 #define EXIT_CONN_STATE_RESOLVING 1 /* waiting for response from dns farm */
149 #define EXIT_CONN_STATE_CONNECTING 2 /* waiting for connect() to finish */
150 #define EXIT_CONN_STATE_OPEN 3
151 #define _EXIT_CONN_STATE_MAX 3
152 #if 0
153 #define EXIT_CONN_STATE_CLOSE 3 /* flushing the buffer, then will close */
154 #define EXIT_CONN_STATE_CLOSE_WAIT 4 /* have sent a destroy, awaiting a confirmation */
155 #endif
157 /* the AP state values must be disjoint from the EXIT state values */
158 #define _AP_CONN_STATE_MIN 4
159 #define AP_CONN_STATE_SOCKS_WAIT 4
160 #define AP_CONN_STATE_CIRCUIT_WAIT 5
161 #define AP_CONN_STATE_OPEN 6
162 #define _AP_CONN_STATE_MAX 6
164 #define _DIR_CONN_STATE_MIN 1
165 #define DIR_CONN_STATE_CONNECTING_FETCH 1
166 #define DIR_CONN_STATE_CONNECTING_UPLOAD 2
167 #define DIR_CONN_STATE_CLIENT_SENDING_FETCH 3
168 #define DIR_CONN_STATE_CLIENT_SENDING_UPLOAD 4
169 #define DIR_CONN_STATE_CLIENT_READING_FETCH 5
170 #define DIR_CONN_STATE_CLIENT_READING_UPLOAD 6
171 #define DIR_CONN_STATE_SERVER_COMMAND_WAIT 7
172 #define DIR_CONN_STATE_SERVER_WRITING 8
173 #define _DIR_CONN_STATE_MAX 8
175 #define CIRCUIT_STATE_BUILDING 0 /* I'm the OP, still haven't done all my handshakes */
176 #define CIRCUIT_STATE_ONIONSKIN_PENDING 1 /* waiting to process the onionskin */
177 #define CIRCUIT_STATE_OR_WAIT 2 /* I'm the OP, my firsthop is still connecting */
178 #define CIRCUIT_STATE_OPEN 3 /* onionskin(s) processed, ready to send/receive cells */
180 #define RELAY_COMMAND_BEGIN 1
181 #define RELAY_COMMAND_DATA 2
182 #define RELAY_COMMAND_END 3
183 #define RELAY_COMMAND_CONNECTED 4
184 #define RELAY_COMMAND_SENDME 5
185 #define RELAY_COMMAND_EXTEND 6
186 #define RELAY_COMMAND_EXTENDED 7
187 #define RELAY_COMMAND_TRUNCATE 8
188 #define RELAY_COMMAND_TRUNCATED 9
189 #define RELAY_COMMAND_DROP 10
191 #define RELAY_HEADER_SIZE 8
193 #define END_STREAM_REASON_MISC 1
194 #define END_STREAM_REASON_RESOLVEFAILED 2
195 #define END_STREAM_REASON_CONNECTFAILED 3
196 #define END_STREAM_REASON_EXITPOLICY 4
197 #define END_STREAM_REASON_DESTROY 5
198 #define END_STREAM_REASON_DONE 6
200 /* default cipher function */
201 #define DEFAULT_CIPHER CRYPTO_CIPHER_AES_CTR
202 /* Used to en/decrypt onion skins */
203 #define ONION_CIPHER DEFAULT_CIPHER
204 /* Used to en/decrypt RELAY cells */
205 #define CIRCUIT_CIPHER DEFAULT_CIPHER
207 #define CELL_DIRECTION_IN 1
208 #define CELL_DIRECTION_OUT 2
209 #define EDGE_EXIT CONN_TYPE_EXIT
210 #define EDGE_AP CONN_TYPE_AP
211 #define CELL_DIRECTION(x) ((x) == EDGE_EXIT ? CELL_DIRECTION_IN : CELL_DIRECTION_OUT)
213 #define CIRCWINDOW_START 1000
214 #define CIRCWINDOW_INCREMENT 100
216 #define STREAMWINDOW_START 500
217 #define STREAMWINDOW_INCREMENT 50
219 /* cell commands */
220 #define CELL_PADDING 0
221 #define CELL_CREATE 1
222 #define CELL_CREATED 2
223 #define CELL_RELAY 3
224 #define CELL_DESTROY 4
226 #define CELL_PAYLOAD_SIZE 248
227 #define CELL_NETWORK_SIZE 256
229 /* legal characters in a filename */
230 #define CONFIG_LEGAL_FILENAME_CHARACTERS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-_/"
231 /* legal characters in a nickname */
232 #define LEGAL_NICKNAME_CHARACTERS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
234 #define SOCKS4_NETWORK_LEN 8
236 typedef uint16_t circ_id_t;
238 /* cell definition */
239 typedef struct {
240 circ_id_t circ_id;
241 unsigned char command;
242 unsigned char length; /* of payload if relay cell */
243 uint32_t seq; /* sequence number */
245 unsigned char payload[CELL_PAYLOAD_SIZE];
246 } cell_t;
247 #define CELL_RELAY_COMMAND(c) (*(uint8_t*)((c).payload))
248 #define SET_CELL_RELAY_COMMAND(c,cmd) (*(uint8_t*)((c).payload) = (cmd))
249 #define STREAM_ID_SIZE 7
250 #define SET_CELL_STREAM_ID(c,id) memcpy((c).payload+1,(id),STREAM_ID_SIZE)
251 #define CELL_RELAY_COMMAND_END_REASON(c) (*(uint8_t)((c).payload+1))
253 #define ZERO_STREAM "\0\0\0\0\0\0\0\0"
255 typedef struct buf_t buf_t;
256 typedef struct socks_request_t socks_request_t;
258 struct connection_t {
260 uint8_t type;
261 uint8_t state;
262 uint8_t wants_to_read; /* should we start reading again once
263 * the bandwidth throttler allows it?
265 uint8_t wants_to_write; /* should we start writing again once
266 * the bandwidth throttler allows reads?
268 int s; /* our socket */
269 int poll_index; /* index of this conn into the poll_array */
270 int marked_for_close; /* should we close this conn on the next
271 * iteration of the main loop?
274 buf_t *inbuf;
275 int inbuf_reached_eof; /* did read() return 0 on this conn? */
276 time_t timestamp_lastread; /* when was the last time poll() said we could read? */
278 buf_t *outbuf;
279 int outbuf_flushlen; /* how much data should we try to flush from the outbuf? */
280 time_t timestamp_lastwritten; /* when was the last time poll() said we could write? */
282 time_t timestamp_created; /* when was this connection_t created? */
284 uint32_t addr; /* these two uniquely identify a router. Both in host order. */
285 uint16_t port; /* if non-zero, they identify the guy on the other end
286 * of the connection. */
287 char *address; /* FQDN (or IP) of the guy on the other end.
288 * strdup into this, because free_connection frees it
290 crypto_pk_env_t *onion_pkey; /* public RSA key for the other side's onions */
291 crypto_pk_env_t *link_pkey; /* public RSA key for the other side's TLS */
292 crypto_pk_env_t *identity_pkey; /* public RSA key for the other side's signing */
293 char *nickname;
295 /* Used only by OR connections: */
296 tor_tls *tls;
297 circ_id_t next_circ_id; /* Which circ_id do we try to use next on this connection?
298 * This is always in the range 0..1<<15-1.*/
300 /* bandwidth and receiver_bucket only used by ORs in OPEN state: */
301 uint32_t bandwidth; /* connection bandwidth. */
302 int receiver_bucket; /* when this hits 0, stop receiving. Every second we
303 * add 'bandwidth' to this, capping it at 10*bandwidth.
306 /* Used only by edge connections: */
307 char stream_id[STREAM_ID_SIZE];
308 struct connection_t *next_stream; /* points to the next stream at this edge, if any */
309 struct crypt_path_t *cpath_layer; /* a pointer to which node in the circ this conn exits at */
310 int package_window; /* how many more relay cells can i send into the circuit? */
311 int deliver_window; /* how many more relay cells can end at me? */
313 int done_sending; /* for half-open connections; not used currently */
314 int done_receiving;
315 char has_sent_end; /* for debugging: set once we've set the stream end,
316 and check in circuit_about_to_close_connection() */
318 /* Used only by AP connections */
319 socks_request_t *socks_request;
322 typedef struct connection_t connection_t;
324 #define EXIT_POLICY_ACCEPT 1
325 #define EXIT_POLICY_REJECT 2
327 struct exit_policy_t {
328 char policy_type;
329 char *string;
330 uint32_t addr;
331 uint32_t msk;
332 uint16_t prt;
334 struct exit_policy_t *next;
337 /* config stuff we know about the other ORs in the network */
338 typedef struct {
339 char *address;
340 char *nickname;
342 uint32_t addr; /* all host order */
343 uint16_t or_port;
344 uint16_t socks_port;
345 uint16_t dir_port;
347 time_t published_on;
349 crypto_pk_env_t *onion_pkey; /* public RSA key for onions */
350 crypto_pk_env_t *link_pkey; /* public RSA key for TLS */
351 crypto_pk_env_t *identity_pkey; /* public RSA key for signing */
353 int is_running;
355 /* link info */
356 uint32_t bandwidth;
357 struct exit_policy_t *exit_policy;
358 } routerinfo_t;
360 #define MAX_ROUTERS_IN_DIR 1024
361 typedef struct {
362 routerinfo_t **routers;
363 int n_routers;
364 char *software_versions;
365 time_t published_on;
366 } directory_t;
368 struct crypt_path_t {
370 /* crypto environments */
371 crypto_cipher_env_t *f_crypto;
372 crypto_cipher_env_t *b_crypto;
374 crypto_dh_env_t *handshake_state;
376 uint32_t addr;
377 uint16_t port;
379 uint8_t state;
380 #define CPATH_STATE_CLOSED 0
381 #define CPATH_STATE_AWAITING_KEYS 1
382 #define CPATH_STATE_OPEN 2
383 struct crypt_path_t *next;
384 struct crypt_path_t *prev; /* doubly linked list */
386 int package_window;
387 int deliver_window;
390 #define DH_KEY_LEN CRYPTO_DH_SIZE
391 #define DH_ONIONSKIN_LEN DH_KEY_LEN+16
393 typedef struct crypt_path_t crypt_path_t;
395 typedef struct {
396 int desired_path_len;
397 char *chosen_exit; /* nickname of planned exit node */
398 } cpath_build_state_t;
400 /* struct for a path (circuit) through the network */
401 struct circuit_t {
402 uint32_t n_addr;
403 uint16_t n_port;
404 connection_t *p_conn;
405 connection_t *n_conn; /* for the OR conn, if there is one */
406 connection_t *p_streams;
407 connection_t *n_streams;
408 int package_window;
409 int deliver_window;
411 circ_id_t p_circ_id; /* circuit identifiers */
412 circ_id_t n_circ_id;
414 crypto_cipher_env_t *p_crypto; /* used only for intermediate hops */
415 crypto_cipher_env_t *n_crypto;
417 cpath_build_state_t *build_state;
418 crypt_path_t *cpath;
420 char onionskin[DH_ONIONSKIN_LEN]; /* for storage while onionskin pending */
421 time_t timestamp_created;
422 time_t timestamp_dirty; /* when the circuit was first used, or 0 if clean */
424 uint8_t state;
426 void *next;
429 typedef struct circuit_t circuit_t;
431 typedef struct {
432 char *LogLevel;
433 char *LogFile;
434 char *DebugLogFile;
435 char *DataDirectory;
436 char *RouterFile;
437 char *Nickname;
438 char *Address;
439 char *PidFile;
440 char *ExitNodes;
441 char *EntryNodes;
442 char *ExitPolicy;
443 char *SocksBindAddress;
444 char *ORBindAddress;
445 char *DirBindAddress;
446 char *RecommendedVersions;
447 char *User;
448 char *Group;
449 double PathlenCoinWeight;
450 int ORPort;
451 int SocksPort;
452 int DirPort;
453 int MaxConn;
454 int TrafficShaping;
455 int LinkPadding;
456 int IgnoreVersion;
457 int RunAsDaemon;
458 int DirRebuildPeriod;
459 int DirFetchPostPeriod;
460 int KeepalivePeriod;
461 int MaxOnionsPending;
462 int NewCircuitPeriod;
463 int TotalBandwidth;
464 int NumCpus;
465 int loglevel;
466 } or_options_t;
468 #define MAX_SOCKS_REPLY_LEN 256
469 /* Not 256; addresses must fit in a begin cell. */
470 #define MAX_SOCKS_ADDR_LEN 200
471 struct socks_request_t {
472 char socks_version;
473 int replylen;
474 char reply[MAX_SOCKS_REPLY_LEN];
475 char address[MAX_SOCKS_ADDR_LEN];
476 uint16_t port;
479 /* all the function prototypes go here */
481 /********************************* buffers.c ***************************/
483 int find_on_inbuf(char *string, int string_len, buf_t *buf);
485 buf_t *buf_new();
486 buf_t *buf_new_with_capacity(size_t size);
487 void buf_free(buf_t *buf);
489 size_t buf_datalen(const buf_t *buf);
490 size_t buf_capacity(const buf_t *buf);
491 const char *_buf_peek_raw_buffer(const buf_t *buf);
493 int read_to_buf(int s, int at_most, buf_t *buf, int *reached_eof);
494 int read_to_buf_tls(tor_tls *tls, int at_most, buf_t *buf);
496 int flush_buf(int s, buf_t *buf, int *buf_flushlen);
497 int flush_buf_tls(tor_tls *tls, buf_t *buf, int *buf_flushlen);
499 int write_to_buf(const char *string, int string_len, buf_t *buf);
500 int fetch_from_buf(char *string, int string_len, buf_t *buf);
501 int fetch_from_buf_http(buf_t *buf,
502 char *headers_out, int max_headerlen,
503 char *body_out, int max_bodylen);
504 int fetch_from_buf_socks(buf_t *buf, socks_request_t *req);
506 /********************************* circuit.c ***************************/
508 void circuit_add(circuit_t *circ);
509 void circuit_remove(circuit_t *circ);
510 circuit_t *circuit_new(circ_id_t p_circ_id, connection_t *p_conn);
511 void circuit_free(circuit_t *circ);
512 void circuit_free_cpath(crypt_path_t *cpath);
514 circuit_t *circuit_get_by_circ_id_conn(circ_id_t circ_id, connection_t *conn);
515 circuit_t *circuit_get_by_conn(connection_t *conn);
516 circuit_t *circuit_get_newest(connection_t *conn, int must_be_open);
518 void circuit_expire_building(void);
519 int circuit_count_building(void);
521 int circuit_deliver_relay_cell(cell_t *cell, circuit_t *circ,
522 int cell_direction, crypt_path_t *layer_hint);
523 int relay_crypt(circuit_t *circ, char *in, int inlen, char cell_direction,
524 crypt_path_t **layer_hint, char *recognized, connection_t **conn);
525 int relay_check_recognized(circuit_t *circ, int cell_direction, char *stream, connection_t **conn);
527 void circuit_resume_edge_reading(circuit_t *circ, int edge_type, crypt_path_t *layer_hint);
528 int circuit_consider_stop_edge_reading(circuit_t *circ, int edge_type, crypt_path_t *layer_hint);
529 int circuit_consider_sending_sendme(circuit_t *circ, int edge_type, crypt_path_t *layer_hint);
531 void circuit_close(circuit_t *circ);
532 void circuit_about_to_close_connection(connection_t *conn);
534 void circuit_dump_by_conn(connection_t *conn, int severity);
536 void circuit_expire_unused_circuits(void);
537 int circuit_launch_new(void);
538 void circuit_increment_failure_count(void);
539 void circuit_reset_failure_count(void);
540 int circuit_establish_circuit(void);
541 void circuit_n_conn_open(connection_t *or_conn);
542 int circuit_send_next_onion_skin(circuit_t *circ);
543 int circuit_extend(cell_t *cell, circuit_t *circ);
544 int circuit_finish_handshake(circuit_t *circ, char *reply);
545 int circuit_truncated(circuit_t *circ, crypt_path_t *layer);
547 void assert_cpath_ok(const crypt_path_t *c);
548 void assert_cpath_layer_ok(const crypt_path_t *c);
549 void assert_circuit_ok(const circuit_t *c);
551 extern unsigned long stats_n_relay_cells_relayed;
552 extern unsigned long stats_n_relay_cells_delivered;
554 /********************************* command.c ***************************/
556 void command_process_cell(cell_t *cell, connection_t *conn);
558 extern unsigned long stats_n_padding_cells_processed;
559 extern unsigned long stats_n_create_cells_processed;
560 extern unsigned long stats_n_created_cells_processed;
561 extern unsigned long stats_n_relay_cells_processed;
562 extern unsigned long stats_n_destroy_cells_processed;
564 /********************************* config.c ***************************/
566 int getconfig(int argc, char **argv, or_options_t *options);
568 /********************************* connection.c ***************************/
570 connection_t *connection_new(int type);
571 void connection_free(connection_t *conn);
573 int connection_create_listener(char *bindaddress, uint16_t bindport, int type);
575 int connection_connect(connection_t *conn, char *address, uint32_t addr, uint16_t port);
576 int retry_all_connections(void);
578 int connection_handle_read(connection_t *conn);
579 int connection_read_to_buf(connection_t *conn);
581 int connection_fetch_from_buf(char *string, int len, connection_t *conn);
582 int connection_find_on_inbuf(char *string, int len, connection_t *conn);
584 int connection_wants_to_flush(connection_t *conn);
585 int connection_outbuf_too_full(connection_t *conn);
586 int connection_handle_write(connection_t *conn);
587 void connection_write_to_buf(const char *string, int len, connection_t *conn);
589 connection_t *connection_twin_get_by_addr_port(uint32_t addr, uint16_t port);
590 connection_t *connection_exact_get_by_addr_port(uint32_t addr, uint16_t port);
592 connection_t *connection_get_by_type(int type);
593 connection_t *connection_get_by_type_state(int type, int state);
594 connection_t *connection_get_by_type_state_lastwritten(int type, int state);
596 int connection_receiver_bucket_should_increase(connection_t *conn);
598 #define connection_speaks_cells(conn) ((conn)->type == CONN_TYPE_OR)
599 #define connection_has_pending_tls_data(conn) \
600 ((conn)->type == CONN_TYPE_OR && \
601 (conn)->state == OR_CONN_STATE_OPEN && \
602 tor_tls_get_pending_bytes(conn->tls))
603 int connection_is_listener(connection_t *conn);
604 int connection_state_is_open(connection_t *conn);
606 int connection_send_destroy(circ_id_t circ_id, connection_t *conn);
608 int connection_process_inbuf(connection_t *conn);
609 int connection_finished_flushing(connection_t *conn);
611 void assert_connection_ok(connection_t *conn, time_t now);
613 /********************************* connection_edge.c ***************************/
615 int connection_edge_process_inbuf(connection_t *conn);
616 void connection_edge_end(connection_t *conn, char reason, crypt_path_t *cpath_layer);
618 int connection_edge_send_command(connection_t *fromconn, circuit_t *circ, int relay_command,
619 void *payload, int payload_len, crypt_path_t *cpath_layer);
621 int connection_edge_process_relay_cell(cell_t *cell, circuit_t *circ, connection_t *conn,
622 int edge_type, crypt_path_t *layer_hint);
623 int connection_edge_finished_flushing(connection_t *conn);
625 int connection_edge_package_raw_inbuf(connection_t *conn);
627 void connection_exit_connect(connection_t *conn);
629 void connection_ap_attach_pending(void);
631 extern uint64_t stats_n_data_cells_packaged;
632 extern uint64_t stats_n_data_bytes_packaged;
633 extern uint64_t stats_n_data_cells_received;
634 extern uint64_t stats_n_data_bytes_received;
636 void client_dns_init(void);
637 void client_dns_clean(void);
639 /********************************* connection_or.c ***************************/
641 int connection_or_process_inbuf(connection_t *conn);
642 int connection_or_finished_flushing(connection_t *conn);
644 void connection_or_init_conn_from_router(connection_t *conn, routerinfo_t *router);
645 connection_t *connection_or_connect(routerinfo_t *router);
647 int connection_tls_start_handshake(connection_t *conn, int receiving);
648 int connection_tls_continue_handshake(connection_t *conn);
650 void connection_or_write_cell_to_buf(const cell_t *cellp, connection_t *conn);
652 /********************************* cpuworker.c *****************************/
654 void cpu_init(void);
655 int connection_cpu_finished_flushing(connection_t *conn);
656 int connection_cpu_process_inbuf(connection_t *conn);
657 int cpuworker_main(void *data);
658 int assign_to_cpuworker(connection_t *cpuworker, unsigned char question_type,
659 void *task);
661 /********************************* directory.c ***************************/
663 void directory_initiate_command(routerinfo_t *router, int command);
664 int connection_dir_process_inbuf(connection_t *conn);
665 int connection_dir_finished_flushing(connection_t *conn);
667 /********************************* dns.c ***************************/
669 void dns_init(void);
670 int connection_dns_finished_flushing(connection_t *conn);
671 int connection_dns_process_inbuf(connection_t *conn);
672 void dns_cancel_pending_resolve(char *question, connection_t *onlyconn);
673 int dns_resolve(connection_t *exitconn);
675 /********************************* main.c ***************************/
677 void set_onion_key(crypto_pk_env_t *k);
678 crypto_pk_env_t *get_onion_key(void);
679 void set_identity_key(crypto_pk_env_t *k);
680 crypto_pk_env_t *get_identity_key(void);
681 crypto_pk_env_t *get_link_key(void);
682 int connection_add(connection_t *conn);
683 int connection_remove(connection_t *conn);
684 void connection_set_poll_socket(connection_t *conn);
686 void get_connection_array(connection_t ***array, int *n);
688 void connection_watch_events(connection_t *conn, short events);
689 int connection_is_reading(connection_t *conn);
690 void connection_stop_reading(connection_t *conn);
691 void connection_start_reading(connection_t *conn);
692 void connection_stop_writing(connection_t *conn);
693 void connection_start_writing(connection_t *conn);
695 const char *router_get_my_descriptor(void);
697 int main(int argc, char *argv[]);
699 /********************************* onion.c ***************************/
701 int decide_circ_id_type(char *local_nick, char *remote_nick);
703 int onion_pending_add(circuit_t *circ);
704 circuit_t *onion_next_task(void);
705 void onion_pending_remove(circuit_t *circ);
707 int onionskin_answer(circuit_t *circ, unsigned char *payload, unsigned char *keys);
709 char **parse_nickname_list(char *start, int *num);
711 int onion_extend_cpath(crypt_path_t **head_ptr, cpath_build_state_t *state,
712 routerinfo_t **router_out);
714 int onion_skin_create(crypto_pk_env_t *router_key,
715 crypto_dh_env_t **handshake_state_out,
716 char *onion_skin_out); /* Must be DH_ONIONSKIN_LEN bytes long */
718 int onion_skin_server_handshake(char *onion_skin, /* DH_ONIONSKIN_LEN bytes long */
719 crypto_pk_env_t *private_key,
720 char *handshake_reply_out, /* DH_KEY_LEN bytes long */
721 char *key_out,
722 int key_out_len);
724 int onion_skin_client_handshake(crypto_dh_env_t *handshake_state,
725 char *handshake_reply,/* Must be DH_KEY_LEN bytes long*/
726 char *key_out,
727 int key_out_len);
729 cpath_build_state_t *onion_new_cpath_build_state(void);
731 /********************************* routers.c ***************************/
733 void router_retry_connections(void);
734 routerinfo_t *router_pick_directory_server(void);
735 routerinfo_t *router_pick_randomly_from_running(void);
736 void router_upload_desc_to_dirservers(void);
737 routerinfo_t *router_get_by_addr_port(uint32_t addr, uint16_t port);
738 routerinfo_t *router_get_by_link_pk(crypto_pk_env_t *pk);
739 routerinfo_t *router_get_by_nickname(char *nickname);
740 void router_get_directory(directory_t **pdirectory);
741 void router_mark_as_down(char *nickname);
742 int router_get_list_from_file(char *routerfile);
743 int router_get_router_hash(char *s, char *digest);
744 int router_get_dir_hash(char *s, char *digest);
746 /* Reads a list of known routers, unsigned. */
747 int router_get_list_from_string(char *s);
748 /* Exported for debugging */
749 int router_get_list_from_string_impl(char **s, directory_t **dest, int n_good_nicknames, const char *good_nickname_lst[]);
750 /* Reads a signed directory. */
751 int router_get_dir_from_string(char *s, crypto_pk_env_t *pkey);
752 /* Exported or debugging */
753 int router_get_dir_from_string_impl(char *s, directory_t **dest,
754 crypto_pk_env_t *pkey);
755 routerinfo_t *router_get_entry_from_string(char **s);
756 int router_supports_exit_address(uint32_t addr, uint16_t port,
757 routerinfo_t *router);
758 int router_compare_to_my_exit_policy(connection_t *conn);
759 int router_compare_addr_to_exit_policy(uint32_t addr, uint16_t port,
760 struct exit_policy_t *policy);
761 void routerinfo_free(routerinfo_t *router);
762 int router_dump_router_to_string(char *s, int maxlen, routerinfo_t *router,
763 crypto_pk_env_t *ident_key);
764 const routerinfo_t *router_get_desc_routerinfo(void);
765 int router_exit_policy_all_routers_reject(uint32_t addr, uint16_t port);
766 int router_exit_policy_rejects_all(routerinfo_t *router);
767 const char *router_get_my_descriptor(void);
768 int router_rebuild_descriptor(void);
769 int connection_ap_can_use_exit(connection_t *conn, routerinfo_t *exit);
771 /********************************* dirserv.c ***************************/
772 int dirserv_add_own_fingerprint(const char *nickname, crypto_pk_env_t *pk);
773 int dirserv_parse_fingerprint_file(const char *fname);
774 int dirserv_router_fingerprint_is_known(const routerinfo_t *router);
775 void dirserv_free_fingerprint_list();
776 int dirserv_add_descriptor(const char **desc);
777 int dirserv_init_from_directory_string(const char *dir);
778 void dirserv_free_descriptors();
779 int dirserv_dump_directory_to_string(char *s, int maxlen,
780 crypto_pk_env_t *private_key);
781 void directory_set_dirty();
782 size_t dirserv_get_directory(const char **cp);
785 #endif
788 Local Variables:
789 mode:c
790 indent-tabs-mode:nil
791 c-basic-offset:2
792 End: