1 /* Copyright 2001,2002,2003 Roger Dingledine, Matej Pfajfar. */
2 /* See LICENSE for licensing information */
28 #include "../common/torint.h"
29 #ifdef HAVE_SYS_POLL_H
34 #include "../common/fakepoll.h"
36 #ifdef HAVE_SYS_TYPES_H
37 #include <sys/types.h> /* Must be included before sys/stat.h for Ultrix */
39 #ifdef HAVE_SYS_WAIT_H
42 #ifdef HAVE_SYS_FCNTL_H
43 #include <sys/fcntl.h>
48 #ifdef HAVE_SYS_IOCTL_H
49 #include <sys/ioctl.h>
51 #ifdef HAVE_SYS_SOCKET_H
52 #include <sys/socket.h>
54 #ifdef HAVE_SYS_TIME_H
57 #ifdef HAVE_SYS_STAT_H
60 #ifdef HAVE_NETINET_IN_H
61 #include <netinet/in.h>
63 #ifdef HAVE_ARPA_INET_H
64 #include <arpa/inet.h>
87 #elif defined(_MSC_VER)
94 #define WIN32_LEAN_AND_MEAN
96 #define snprintf _snprintf
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 500000
112 #define MAX_DNS_ENTRY_AGE (150*60)
114 #define MAX_DNS_ENTRY_AGE (15*60)
117 #define CIRC_ID_TYPE_LOWER 0
118 #define CIRC_ID_TYPE_HIGHER 1
120 #define _CONN_TYPE_MIN 3
121 #define CONN_TYPE_OR_LISTENER 3
122 #define CONN_TYPE_OR 4
123 #define CONN_TYPE_EXIT 5
124 #define CONN_TYPE_AP_LISTENER 6
125 #define CONN_TYPE_AP 7
126 #define CONN_TYPE_DIR_LISTENER 8
127 #define CONN_TYPE_DIR 9
128 #define CONN_TYPE_DNSWORKER 10
129 #define CONN_TYPE_CPUWORKER 11
130 #define _CONN_TYPE_MAX 11
132 #define LISTENER_STATE_READY 0
134 #define _DNSWORKER_STATE_MIN 1
135 #define DNSWORKER_STATE_IDLE 1
136 #define DNSWORKER_STATE_BUSY 2
137 #define _DNSWORKER_STATE_MAX 2
139 #define _CPUWORKER_STATE_MIN 1
140 #define CPUWORKER_STATE_IDLE 1
141 #define CPUWORKER_STATE_BUSY_ONION 2
142 #define CPUWORKER_STATE_BUSY_HANDSHAKE 3
143 #define _CPUWORKER_STATE_MAX 3
145 #define CPUWORKER_TASK_ONION CPUWORKER_STATE_BUSY_ONION
147 #define _OR_CONN_STATE_MIN 1
148 #define OR_CONN_STATE_CONNECTING 1 /* waiting for connect() to finish */
149 #define OR_CONN_STATE_HANDSHAKING 2 /* SSL is handshaking, not done yet */
150 #define OR_CONN_STATE_OPEN 3 /* ready to send/receive cells. */
151 #define _OR_CONN_STATE_MAX 3
153 #define _EXIT_CONN_STATE_MIN 1
154 #define EXIT_CONN_STATE_RESOLVING 1 /* waiting for response from dns farm */
155 #define EXIT_CONN_STATE_CONNECTING 2 /* waiting for connect() to finish */
156 #define EXIT_CONN_STATE_OPEN 3
157 #define _EXIT_CONN_STATE_MAX 3
159 #define EXIT_CONN_STATE_CLOSE 3 /* flushing the buffer, then will close */
160 #define EXIT_CONN_STATE_CLOSE_WAIT 4 /* have sent a destroy, awaiting a confirmation */
163 /* the AP state values must be disjoint from the EXIT state values */
164 #define _AP_CONN_STATE_MIN 4
165 #define AP_CONN_STATE_SOCKS_WAIT 4
166 #define AP_CONN_STATE_CIRCUIT_WAIT 5
167 #define AP_CONN_STATE_OPEN 6
168 #define _AP_CONN_STATE_MAX 6
170 #define _DIR_CONN_STATE_MIN 1
171 #define DIR_CONN_STATE_CONNECTING_FETCH 1
172 #define DIR_CONN_STATE_CONNECTING_UPLOAD 2
173 #define DIR_CONN_STATE_CLIENT_SENDING_FETCH 3
174 #define DIR_CONN_STATE_CLIENT_SENDING_UPLOAD 4
175 #define DIR_CONN_STATE_CLIENT_READING_FETCH 5
176 #define DIR_CONN_STATE_CLIENT_READING_UPLOAD 6
177 #define DIR_CONN_STATE_SERVER_COMMAND_WAIT 7
178 #define DIR_CONN_STATE_SERVER_WRITING 8
179 #define _DIR_CONN_STATE_MAX 8
181 #define CIRCUIT_STATE_BUILDING 0 /* I'm the OP, still haven't done all my handshakes */
182 #define CIRCUIT_STATE_ONIONSKIN_PENDING 1 /* waiting to process the onionskin */
183 #define CIRCUIT_STATE_OR_WAIT 2 /* I'm the OP, my firsthop is still connecting */
184 #define CIRCUIT_STATE_OPEN 3 /* onionskin(s) processed, ready to send/receive cells */
186 #define RELAY_COMMAND_BEGIN 1
187 #define RELAY_COMMAND_DATA 2
188 #define RELAY_COMMAND_END 3
189 #define RELAY_COMMAND_CONNECTED 4
190 #define RELAY_COMMAND_SENDME 5
191 #define RELAY_COMMAND_EXTEND 6
192 #define RELAY_COMMAND_EXTENDED 7
193 #define RELAY_COMMAND_TRUNCATE 8
194 #define RELAY_COMMAND_TRUNCATED 9
195 #define RELAY_COMMAND_DROP 10
197 #define END_STREAM_REASON_MISC 1
198 #define END_STREAM_REASON_RESOLVEFAILED 2
199 #define END_STREAM_REASON_CONNECTFAILED 3
200 #define END_STREAM_REASON_EXITPOLICY 4
201 #define END_STREAM_REASON_DESTROY 5
202 #define END_STREAM_REASON_DONE 6
204 /* default cipher function */
205 #define DEFAULT_CIPHER CRYPTO_CIPHER_AES_CTR
206 /* Used to en/decrypt onion skins */
207 #define ONION_CIPHER DEFAULT_CIPHER
208 /* Used to en/decrypt RELAY cells */
209 #define CIRCUIT_CIPHER DEFAULT_CIPHER
211 #define CELL_DIRECTION_IN 1
212 #define CELL_DIRECTION_OUT 2
213 #define EDGE_EXIT CONN_TYPE_EXIT
214 #define EDGE_AP CONN_TYPE_AP
215 #define CELL_DIRECTION(x) ((x) == EDGE_EXIT ? CELL_DIRECTION_IN : CELL_DIRECTION_OUT)
218 #define CIRCWINDOW_START 10000
219 #define CIRCWINDOW_INCREMENT 1000
220 #define STREAMWINDOW_START 5000
221 #define STREAMWINDOW_INCREMENT 500
223 #define CIRCWINDOW_START 1000
224 #define CIRCWINDOW_INCREMENT 100
225 #define STREAMWINDOW_START 500
226 #define STREAMWINDOW_INCREMENT 50
230 #define CELL_PADDING 0
231 #define CELL_CREATE 1
232 #define CELL_CREATED 2
234 #define CELL_DESTROY 4
236 /* legal characters in a filename */
237 #define CONFIG_LEGAL_FILENAME_CHARACTERS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-_/"
238 /* legal characters in a nickname */
239 #define LEGAL_NICKNAME_CHARACTERS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
241 #define SOCKS4_NETWORK_LEN 8
245 * Relay command [1 byte]
246 * Recognized [2 bytes]
247 * Stream ID [2 bytes]
248 * Partial SHA-1 [4 bytes]
250 * Relay payload [498 bytes]
254 #define CELL_RELAY_COMMAND(c) (*(uint8_t*)((c).payload))
255 #define SET_CELL_RELAY_COMMAND(c,cmd) (*(uint8_t*)((c).payload) = (cmd))
257 #define CELL_RELAY_RECOGNIZED(c) (ntohs(*(uint16_t*)((c).payload+1)))
258 #define SET_CELL_RELAY_RECOGNIZED(c,r) (*(uint16_t*)((c).payload+1) = htons(r))
260 #define STREAM_ID_SIZE 2
261 //#define SET_CELL_STREAM_ID(c,id) memcpy((c).payload+1,(id),STREAM_ID_SIZE)
262 #define CELL_RELAY_STREAM_ID(c) (ntohs(*(uint16_t*)((c).payload+3)))
263 #define SET_CELL_RELAY_STREAM_ID(c,id) (*(uint16_t*)((c).payload+3) = htons(id))
264 #define ZERO_STREAM 0
266 /* integrity is the first 32 bits (in network order) of a sha-1 of all
267 * cell payloads that are relay cells that have been sent / delivered
268 * to the hop on the * circuit (the integrity is zeroed while doing
271 #define CELL_RELAY_INTEGRITY(c) (ntohl(*(uint32_t*)((c).payload+5)))
272 #define SET_CELL_RELAY_INTEGRITY(c,i) (*(uint32_t*)((c).payload+5) = htonl(i))
274 /* relay length is how many bytes are used in the cell payload past relay_header_size */
275 #define CELL_RELAY_LENGTH(c) (ntohs(*(uint16_t*)((c).payload+9)))
276 #define SET_CELL_RELAY_LENGTH(c,len) (*(uint16_t*)((c).payload+9) = htons(len))
279 #define CELL_PAYLOAD_SIZE 509
280 #define CELL_NETWORK_SIZE 512
282 #define RELAY_HEADER_SIZE (1+2+2+4+2)
283 #define RELAY_PAYLOAD_SIZE (CELL_PAYLOAD_SIZE-RELAY_HEADER_SIZE)
285 /* cell definition */
288 unsigned char command
;
289 unsigned char payload
[CELL_PAYLOAD_SIZE
];
300 typedef struct buf_t buf_t
;
301 typedef struct socks_request_t socks_request_t
;
303 struct connection_t
{
307 uint8_t wants_to_read
; /* should we start reading again once
308 * the bandwidth throttler allows it?
310 uint8_t wants_to_write
; /* should we start writing again once
311 * the bandwidth throttler allows reads?
313 int s
; /* our socket */
314 int poll_index
; /* index of this conn into the poll_array */
315 int marked_for_close
; /* should we close this conn on the next
316 * iteration of the main loop?
320 int inbuf_reached_eof
; /* did read() return 0 on this conn? */
321 time_t timestamp_lastread
; /* when was the last time poll() said we could read? */
324 int outbuf_flushlen
; /* how much data should we try to flush from the outbuf? */
325 time_t timestamp_lastwritten
; /* when was the last time poll() said we could write? */
327 time_t timestamp_created
; /* when was this connection_t created? */
329 uint32_t addr
; /* these two uniquely identify a router. Both in host order. */
330 uint16_t port
; /* if non-zero, they identify the guy on the other end
331 * of the connection. */
332 char *address
; /* FQDN (or IP) of the guy on the other end.
333 * strdup into this, because free_connection frees it
335 crypto_pk_env_t
*onion_pkey
; /* public RSA key for the other side's onions */
336 crypto_pk_env_t
*link_pkey
; /* public RSA key for the other side's TLS */
337 crypto_pk_env_t
*identity_pkey
; /* public RSA key for the other side's signing */
340 /* Used only by OR connections: */
342 uint16_t next_circ_id
; /* Which circ_id do we try to use next on this connection?
343 * This is always in the range 0..1<<15-1.*/
345 /* bandwidth and receiver_bucket only used by ORs in OPEN state: */
346 uint32_t bandwidth
; /* connection bandwidth. */
347 int receiver_bucket
; /* when this hits 0, stop receiving. Every second we
348 * add 'bandwidth' to this, capping it at 10*bandwidth.
351 /* Used only by edge connections: */
353 struct connection_t
*next_stream
; /* points to the next stream at this edge, if any */
354 struct crypt_path_t
*cpath_layer
; /* a pointer to which node in the circ this conn exits at */
355 int package_window
; /* how many more relay cells can i send into the circuit? */
356 int deliver_window
; /* how many more relay cells can end at me? */
358 int done_sending
; /* for half-open connections; not used currently */
360 char has_sent_end
; /* for debugging: set once we've set the stream end,
361 and check in circuit_about_to_close_connection() */
363 /* Used only by AP connections */
364 socks_request_t
*socks_request
;
367 typedef struct connection_t connection_t
;
369 #define EXIT_POLICY_ACCEPT 1
370 #define EXIT_POLICY_REJECT 2
372 struct exit_policy_t
{
380 struct exit_policy_t
*next
;
383 /* config stuff we know about the other ORs in the network */
388 uint32_t addr
; /* all host order */
395 crypto_pk_env_t
*onion_pkey
; /* public RSA key for onions */
396 crypto_pk_env_t
*link_pkey
; /* public RSA key for TLS */
397 crypto_pk_env_t
*identity_pkey
; /* public RSA key for signing */
402 uint32_t bandwidthrate
;
403 uint32_t bandwidthburst
;
404 struct exit_policy_t
*exit_policy
;
407 #define MAX_ROUTERS_IN_DIR 1024
409 routerinfo_t
**routers
;
411 char *software_versions
;
415 struct crypt_path_t
{
417 /* crypto environments */
418 crypto_cipher_env_t
*f_crypto
;
419 crypto_cipher_env_t
*b_crypto
;
421 crypto_digest_env_t
*f_digest
; /* for integrity checking */
422 crypto_digest_env_t
*b_digest
;
424 crypto_dh_env_t
*handshake_state
;
430 #define CPATH_STATE_CLOSED 0
431 #define CPATH_STATE_AWAITING_KEYS 1
432 #define CPATH_STATE_OPEN 2
433 struct crypt_path_t
*next
;
434 struct crypt_path_t
*prev
; /* doubly linked list */
440 #define DH_KEY_LEN CRYPTO_DH_SIZE
441 #define ONIONSKIN_CHALLENGE_LEN (16+DH_KEY_LEN)
442 #define ONIONSKIN_REPLY_LEN (DH_KEY_LEN+20)
444 typedef struct crypt_path_t crypt_path_t
;
447 int desired_path_len
;
448 char *chosen_exit
; /* nickname of planned exit node */
449 } cpath_build_state_t
;
451 /* struct for a path (circuit) through the network */
455 connection_t
*p_conn
;
456 connection_t
*n_conn
; /* for the OR conn, if there is one */
457 connection_t
*p_streams
;
458 connection_t
*n_streams
;
459 uint16_t next_stream_id
;
463 uint16_t p_circ_id
; /* circuit identifiers */
466 crypto_cipher_env_t
*p_crypto
; /* used only for intermediate hops */
467 crypto_cipher_env_t
*n_crypto
;
469 crypto_digest_env_t
*p_digest
; /* for integrity checking, */
470 crypto_digest_env_t
*n_digest
; /* intermediate hops only */
472 cpath_build_state_t
*build_state
;
475 char onionskin
[ONIONSKIN_CHALLENGE_LEN
]; /* for storage while onionskin pending */
476 time_t timestamp_created
;
477 time_t timestamp_dirty
; /* when the circuit was first used, or 0 if clean */
484 typedef struct circuit_t circuit_t
;
499 char *SocksBindAddress
;
501 char *DirBindAddress
;
502 char *RecommendedVersions
;
505 double PathlenCoinWeight
;
514 int DirRebuildPeriod
;
515 int DirFetchPostPeriod
;
517 int MaxOnionsPending
;
518 int NewCircuitPeriod
;
525 /* XXX are these good enough defaults? */
526 #define MAX_SOCKS_REPLY_LEN 256
527 /* Not 256; addresses must fit in a begin cell. */
528 #define MAX_SOCKS_ADDR_LEN 200
529 struct socks_request_t
{
532 char reply
[MAX_SOCKS_REPLY_LEN
];
533 char address
[MAX_SOCKS_ADDR_LEN
];
537 /* all the function prototypes go here */
539 /********************************* buffers.c ***************************/
541 int find_on_inbuf(char *string
, int string_len
, buf_t
*buf
);
544 buf_t
*buf_new_with_capacity(size_t size
);
545 void buf_free(buf_t
*buf
);
547 size_t buf_datalen(const buf_t
*buf
);
548 size_t buf_capacity(const buf_t
*buf
);
549 const char *_buf_peek_raw_buffer(const buf_t
*buf
);
551 int read_to_buf(int s
, int at_most
, buf_t
*buf
, int *reached_eof
);
552 int read_to_buf_tls(tor_tls
*tls
, int at_most
, buf_t
*buf
);
554 int flush_buf(int s
, buf_t
*buf
, int *buf_flushlen
);
555 int flush_buf_tls(tor_tls
*tls
, buf_t
*buf
, int *buf_flushlen
);
557 int write_to_buf(const char *string
, int string_len
, buf_t
*buf
);
558 int fetch_from_buf(char *string
, int string_len
, buf_t
*buf
);
559 int fetch_from_buf_http(buf_t
*buf
,
560 char **headers_out
, int max_headerlen
,
561 char **body_out
, int max_bodylen
);
562 int fetch_from_buf_socks(buf_t
*buf
, socks_request_t
*req
);
564 /********************************* circuit.c ***************************/
566 void circuit_add(circuit_t
*circ
);
567 void circuit_remove(circuit_t
*circ
);
568 circuit_t
*circuit_new(uint16_t p_circ_id
, connection_t
*p_conn
);
569 void circuit_free(circuit_t
*circ
);
570 void circuit_free_cpath(crypt_path_t
*cpath
);
572 circuit_t
*circuit_get_by_circ_id_conn(uint16_t circ_id
, connection_t
*conn
);
573 circuit_t
*circuit_get_by_conn(connection_t
*conn
);
574 circuit_t
*circuit_get_newest(connection_t
*conn
, int must_be_open
);
576 void circuit_expire_building(void);
577 int circuit_count_building(void);
578 int circuit_stream_is_being_handled(connection_t
*conn
);
580 int circuit_receive_relay_cell(cell_t
*cell
, circuit_t
*circ
,
582 int circuit_package_relay_cell(cell_t
*cell
, circuit_t
*circ
,
583 int cell_direction
, crypt_path_t
*layer_hint
);
585 void circuit_resume_edge_reading(circuit_t
*circ
, int edge_type
, crypt_path_t
*layer_hint
);
586 int circuit_consider_stop_edge_reading(circuit_t
*circ
, int edge_type
, crypt_path_t
*layer_hint
);
587 void circuit_consider_sending_sendme(circuit_t
*circ
, int edge_type
, crypt_path_t
*layer_hint
);
589 void circuit_close(circuit_t
*circ
);
590 void circuit_about_to_close_connection(connection_t
*conn
);
592 void circuit_dump_by_conn(connection_t
*conn
, int severity
);
594 void circuit_expire_unused_circuits(void);
595 int circuit_launch_new(void);
596 void circuit_increment_failure_count(void);
597 void circuit_reset_failure_count(void);
598 int circuit_establish_circuit(void);
599 void circuit_n_conn_open(connection_t
*or_conn
);
600 int circuit_send_next_onion_skin(circuit_t
*circ
);
601 int circuit_extend(cell_t
*cell
, circuit_t
*circ
);
602 int circuit_finish_handshake(circuit_t
*circ
, char *reply
);
603 int circuit_truncated(circuit_t
*circ
, crypt_path_t
*layer
);
605 void assert_cpath_ok(const crypt_path_t
*c
);
606 void assert_cpath_layer_ok(const crypt_path_t
*c
);
607 void assert_circuit_ok(const circuit_t
*c
);
609 extern unsigned long stats_n_relay_cells_relayed
;
610 extern unsigned long stats_n_relay_cells_delivered
;
612 /********************************* command.c ***************************/
614 void command_process_cell(cell_t
*cell
, connection_t
*conn
);
616 extern unsigned long stats_n_padding_cells_processed
;
617 extern unsigned long stats_n_create_cells_processed
;
618 extern unsigned long stats_n_created_cells_processed
;
619 extern unsigned long stats_n_relay_cells_processed
;
620 extern unsigned long stats_n_destroy_cells_processed
;
622 /********************************* config.c ***************************/
624 int getconfig(int argc
, char **argv
, or_options_t
*options
);
626 /********************************* connection.c ***************************/
628 connection_t
*connection_new(int type
);
629 void connection_free(connection_t
*conn
);
630 void connection_free_all(void);
632 int connection_create_listener(char *bindaddress
, uint16_t bindport
, int type
);
634 int connection_connect(connection_t
*conn
, char *address
, uint32_t addr
, uint16_t port
);
635 int retry_all_connections(void);
637 int connection_handle_read(connection_t
*conn
);
638 int connection_read_to_buf(connection_t
*conn
);
640 int connection_fetch_from_buf(char *string
, int len
, connection_t
*conn
);
641 int connection_find_on_inbuf(char *string
, int len
, connection_t
*conn
);
643 int connection_wants_to_flush(connection_t
*conn
);
644 int connection_outbuf_too_full(connection_t
*conn
);
645 int connection_handle_write(connection_t
*conn
);
646 void connection_write_to_buf(const char *string
, int len
, connection_t
*conn
);
648 connection_t
*connection_twin_get_by_addr_port(uint32_t addr
, uint16_t port
);
649 connection_t
*connection_exact_get_by_addr_port(uint32_t addr
, uint16_t port
);
651 connection_t
*connection_get_by_type(int type
);
652 connection_t
*connection_get_by_type_state(int type
, int state
);
653 connection_t
*connection_get_by_type_state_lastwritten(int type
, int state
);
655 int connection_receiver_bucket_should_increase(connection_t
*conn
);
657 #define connection_speaks_cells(conn) ((conn)->type == CONN_TYPE_OR)
658 #define connection_has_pending_tls_data(conn) \
659 ((conn)->type == CONN_TYPE_OR && \
660 (conn)->state == OR_CONN_STATE_OPEN && \
661 tor_tls_get_pending_bytes(conn->tls))
662 int connection_is_listener(connection_t
*conn
);
663 int connection_state_is_open(connection_t
*conn
);
665 int connection_send_destroy(uint16_t circ_id
, connection_t
*conn
);
667 int connection_process_inbuf(connection_t
*conn
);
668 int connection_finished_flushing(connection_t
*conn
);
670 void assert_connection_ok(connection_t
*conn
, time_t now
);
672 /********************************* connection_edge.c ***************************/
674 void relay_header_pack(char *dest
, const relay_header_t
*src
);
675 void relay_header_unpack(relay_header_t
*dest
, const char *src
);
676 int connection_edge_process_inbuf(connection_t
*conn
);
677 int connection_edge_end(connection_t
*conn
, char reason
, crypt_path_t
*cpath_layer
);
679 int connection_edge_send_command(connection_t
*fromconn
, circuit_t
*circ
, int relay_command
,
680 void *payload
, int payload_len
, crypt_path_t
*cpath_layer
);
682 int connection_edge_process_relay_cell(cell_t
*cell
, circuit_t
*circ
, connection_t
*conn
,
683 int edge_type
, crypt_path_t
*layer_hint
);
684 int connection_edge_finished_flushing(connection_t
*conn
);
686 int connection_edge_package_raw_inbuf(connection_t
*conn
);
688 void connection_exit_connect(connection_t
*conn
);
689 int connection_ap_can_use_exit(connection_t
*conn
, routerinfo_t
*exit
);
690 void connection_ap_attach_pending(void);
692 extern uint64_t stats_n_data_cells_packaged
;
693 extern uint64_t stats_n_data_bytes_packaged
;
694 extern uint64_t stats_n_data_cells_received
;
695 extern uint64_t stats_n_data_bytes_received
;
697 void client_dns_init(void);
698 void client_dns_clean(void);
700 /********************************* connection_or.c ***************************/
702 int connection_or_process_inbuf(connection_t
*conn
);
703 int connection_or_finished_flushing(connection_t
*conn
);
705 void connection_or_init_conn_from_router(connection_t
*conn
, routerinfo_t
*router
);
706 connection_t
*connection_or_connect(routerinfo_t
*router
);
708 int connection_tls_start_handshake(connection_t
*conn
, int receiving
);
709 int connection_tls_continue_handshake(connection_t
*conn
);
711 void connection_or_write_cell_to_buf(const cell_t
*cell
, connection_t
*conn
);
713 /********************************* cpuworker.c *****************************/
716 int connection_cpu_finished_flushing(connection_t
*conn
);
717 int connection_cpu_process_inbuf(connection_t
*conn
);
718 int cpuworker_main(void *data
);
719 int assign_to_cpuworker(connection_t
*cpuworker
, unsigned char question_type
,
722 /********************************* directory.c ***************************/
724 void directory_initiate_command(routerinfo_t
*router
, int command
);
725 int connection_dir_process_inbuf(connection_t
*conn
);
726 int connection_dir_finished_flushing(connection_t
*conn
);
728 /********************************* dns.c ***************************/
731 int connection_dns_finished_flushing(connection_t
*conn
);
732 int connection_dns_process_inbuf(connection_t
*conn
);
733 void dns_cancel_pending_resolve(char *question
, connection_t
*onlyconn
);
734 int dns_resolve(connection_t
*exitconn
);
736 /********************************* main.c ***************************/
738 int connection_add(connection_t
*conn
);
739 int connection_remove(connection_t
*conn
);
740 void connection_set_poll_socket(connection_t
*conn
);
742 void get_connection_array(connection_t
***array
, int *n
);
744 void connection_watch_events(connection_t
*conn
, short events
);
745 int connection_is_reading(connection_t
*conn
);
746 void connection_stop_reading(connection_t
*conn
);
747 void connection_start_reading(connection_t
*conn
);
748 void connection_stop_writing(connection_t
*conn
);
749 void connection_start_writing(connection_t
*conn
);
751 int main(int argc
, char *argv
[]);
753 /********************************* onion.c ***************************/
755 int decide_circ_id_type(char *local_nick
, char *remote_nick
);
757 int onion_pending_add(circuit_t
*circ
);
758 circuit_t
*onion_next_task(void);
759 void onion_pending_remove(circuit_t
*circ
);
761 int onionskin_answer(circuit_t
*circ
, unsigned char *payload
, unsigned char *keys
);
763 int onion_extend_cpath(crypt_path_t
**head_ptr
, cpath_build_state_t
*state
,
764 routerinfo_t
**router_out
);
766 int onion_skin_create(crypto_pk_env_t
*router_key
,
767 crypto_dh_env_t
**handshake_state_out
,
768 char *onion_skin_out
);
770 int onion_skin_server_handshake(char *onion_skin
,
771 crypto_pk_env_t
*private_key
,
772 char *handshake_reply_out
,
776 int onion_skin_client_handshake(crypto_dh_env_t
*handshake_state
,
777 char *handshake_reply
,
781 cpath_build_state_t
*onion_new_cpath_build_state(void);
783 /********************************* router.c ***************************/
785 void set_onion_key(crypto_pk_env_t
*k
);
786 crypto_pk_env_t
*get_onion_key(void);
787 void set_identity_key(crypto_pk_env_t
*k
);
788 crypto_pk_env_t
*get_identity_key(void);
789 crypto_pk_env_t
*get_link_key(void);
792 void router_retry_connections(void);
793 void router_upload_desc_to_dirservers(void);
794 int router_compare_to_my_exit_policy(connection_t
*conn
);
795 const char *router_get_my_descriptor(void);
796 int router_rebuild_descriptor(void);
797 int router_dump_router_to_string(char *s
, int maxlen
, routerinfo_t
*router
,
798 crypto_pk_env_t
*ident_key
);
800 /********************************* routerlist.c ***************************/
802 routerinfo_t
*router_pick_directory_server(void);
803 routerinfo_t
*router_get_by_addr_port(uint32_t addr
, uint16_t port
);
804 routerinfo_t
*router_get_by_link_pk(crypto_pk_env_t
*pk
);
805 routerinfo_t
*router_get_by_nickname(char *nickname
);
806 void router_get_routerlist(routerlist_t
**prouterlist
);
807 void routerinfo_free(routerinfo_t
*router
);
808 void router_mark_as_down(char *nickname
);
809 int router_set_routerlist_from_file(char *routerfile
);
810 int router_get_dir_hash(const char *s
, char *digest
);
811 int router_get_router_hash(const char *s
, char *digest
);
812 int router_set_routerlist_from_directory(const char *s
, crypto_pk_env_t
*pkey
);
813 routerinfo_t
*router_get_entry_from_string(const char **s
);
814 int router_add_exit_policy_from_string(routerinfo_t
*router
, const char *s
);
815 int router_compare_addr_to_exit_policy(uint32_t addr
, uint16_t port
,
816 struct exit_policy_t
*policy
);
817 int router_exit_policy_all_routers_reject(uint32_t addr
, uint16_t port
);
818 int router_exit_policy_rejects_all(routerinfo_t
*router
);
820 /********************************* dirserv.c ***************************/
821 int dirserv_add_own_fingerprint(const char *nickname
, crypto_pk_env_t
*pk
);
822 int dirserv_parse_fingerprint_file(const char *fname
);
823 int dirserv_router_fingerprint_is_known(const routerinfo_t
*router
);
824 void dirserv_free_fingerprint_list();
825 int dirserv_add_descriptor(const char **desc
);
826 int dirserv_init_from_directory_string(const char *dir
);
827 void dirserv_free_descriptors();
828 int dirserv_dump_directory_to_string(char *s
, int maxlen
,
829 crypto_pk_env_t
*private_key
);
830 void directory_set_dirty();
831 size_t dirserv_get_directory(const char **cp
);