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 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
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 */
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
220 #define CELL_PADDING 0
221 #define CELL_CREATE 1
222 #define CELL_CREATED 2
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 */
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
];
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
{
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?
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? */
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 */
295 /* Used only by OR connections: */
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 */
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
{
334 struct exit_policy_t
*next
;
337 /* config stuff we know about the other ORs in the network */
342 uint32_t addr
; /* all host order */
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 */
357 struct exit_policy_t
*exit_policy
;
360 #define MAX_ROUTERS_IN_DIR 1024
362 routerinfo_t
**routers
;
364 char *software_versions
;
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
;
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 */
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
;
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 */
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
;
411 circ_id_t p_circ_id
; /* circuit identifiers */
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
;
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 */
429 typedef struct circuit_t circuit_t
;
443 char *SocksBindAddress
;
445 char *DirBindAddress
;
446 char *RecommendedVersions
;
449 double PathlenCoinWeight
;
458 int DirRebuildPeriod
;
459 int DirFetchPostPeriod
;
461 int MaxOnionsPending
;
462 int NewCircuitPeriod
;
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
{
474 char reply
[MAX_SOCKS_REPLY_LEN
];
475 char address
[MAX_SOCKS_ADDR_LEN
];
479 /* all the function prototypes go here */
481 /********************************* buffers.c ***************************/
483 int find_on_inbuf(char *string
, int string_len
, buf_t
*buf
);
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 *****************************/
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
,
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 ***************************/
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 int connection_add(connection_t
*conn
);
678 int connection_remove(connection_t
*conn
);
679 void connection_set_poll_socket(connection_t
*conn
);
681 void get_connection_array(connection_t
***array
, int *n
);
683 void connection_watch_events(connection_t
*conn
, short events
);
684 int connection_is_reading(connection_t
*conn
);
685 void connection_stop_reading(connection_t
*conn
);
686 void connection_start_reading(connection_t
*conn
);
687 void connection_stop_writing(connection_t
*conn
);
688 void connection_start_writing(connection_t
*conn
);
690 int main(int argc
, char *argv
[]);
692 /********************************* onion.c ***************************/
694 int decide_circ_id_type(char *local_nick
, char *remote_nick
);
696 int onion_pending_add(circuit_t
*circ
);
697 circuit_t
*onion_next_task(void);
698 void onion_pending_remove(circuit_t
*circ
);
700 int onionskin_answer(circuit_t
*circ
, unsigned char *payload
, unsigned char *keys
);
702 char **parse_nickname_list(char *start
, int *num
);
704 int onion_extend_cpath(crypt_path_t
**head_ptr
, cpath_build_state_t
*state
,
705 routerinfo_t
**router_out
);
707 int onion_skin_create(crypto_pk_env_t
*router_key
,
708 crypto_dh_env_t
**handshake_state_out
,
709 char *onion_skin_out
); /* Must be DH_ONIONSKIN_LEN bytes long */
711 int onion_skin_server_handshake(char *onion_skin
, /* DH_ONIONSKIN_LEN bytes long */
712 crypto_pk_env_t
*private_key
,
713 char *handshake_reply_out
, /* DH_KEY_LEN bytes long */
717 int onion_skin_client_handshake(crypto_dh_env_t
*handshake_state
,
718 char *handshake_reply
,/* Must be DH_KEY_LEN bytes long*/
722 cpath_build_state_t
*onion_new_cpath_build_state(void);
724 /********************************* router.c ***************************/
726 void set_onion_key(crypto_pk_env_t
*k
);
727 crypto_pk_env_t
*get_onion_key(void);
728 void set_identity_key(crypto_pk_env_t
*k
);
729 crypto_pk_env_t
*get_identity_key(void);
730 crypto_pk_env_t
*get_link_key(void);
733 void router_retry_connections(void);
734 void router_upload_desc_to_dirservers(void);
735 int router_compare_to_my_exit_policy(connection_t
*conn
);
736 const char *router_get_my_descriptor(void);
737 int router_rebuild_descriptor(void);
738 int router_dump_router_to_string(char *s
, int maxlen
, routerinfo_t
*router
,
739 crypto_pk_env_t
*ident_key
);
741 /********************************* routerlist.c ***************************/
743 routerinfo_t
*router_pick_directory_server(void);
744 routerinfo_t
*router_pick_randomly_from_running(void);
745 routerinfo_t
*router_get_by_addr_port(uint32_t addr
, uint16_t port
);
746 routerinfo_t
*router_get_by_link_pk(crypto_pk_env_t
*pk
);
747 routerinfo_t
*router_get_by_nickname(char *nickname
);
748 void router_get_routerlist(routerlist_t
**prouterlist
);
749 void routerinfo_free(routerinfo_t
*router
);
750 void router_mark_as_down(char *nickname
);
751 int router_set_routerlist_from_file(char *routerfile
);
752 int router_get_dir_hash(char *s
, char *digest
);
753 int router_get_router_hash(char *s
, char *digest
);
754 int router_set_routerlist_from_directory(char *s
, crypto_pk_env_t
*pkey
);
755 routerinfo_t
*router_get_entry_from_string(char**s
);
756 int router_add_exit_policy_from_string(routerinfo_t
*router
, char *s
);
757 int router_supports_exit_address(uint32_t addr
, uint16_t port
,
758 routerinfo_t
*router
);
759 int router_compare_addr_to_exit_policy(uint32_t addr
, uint16_t port
,
760 struct exit_policy_t
*policy
);
761 int router_exit_policy_all_routers_reject(uint32_t addr
, uint16_t port
);
762 int router_exit_policy_rejects_all(routerinfo_t
*router
);
764 /********************************* dirserv.c ***************************/
765 int dirserv_add_own_fingerprint(const char *nickname
, crypto_pk_env_t
*pk
);
766 int dirserv_parse_fingerprint_file(const char *fname
);
767 int dirserv_router_fingerprint_is_known(const routerinfo_t
*router
);
768 void dirserv_free_fingerprint_list();
769 int dirserv_add_descriptor(const char **desc
);
770 int dirserv_init_from_directory_string(const char *dir
);
771 void dirserv_free_descriptors();
772 int dirserv_dump_directory_to_string(char *s
, int maxlen
,
773 crypto_pk_env_t
*private_key
);
774 void directory_set_dirty();
775 size_t dirserv_get_directory(const char **cp
);