1 /* Copyright 2001,2002 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>
81 #elif defined(_MSC_VER)
87 #define WIN32_LEAN_AND_MEAN
89 #define snprintf _snprintf
92 #include "../common/crypto.h"
93 #include "../common/tortls.h"
94 #include "../common/log.h"
95 #include "../common/util.h"
97 #define RECOMMENDED_SOFTWARE_VERSIONS "0.0.2pre8,0.0.2pre9"
99 #define MAXCONNECTIONS 1000 /* upper bound on max connections.
100 can be lowered by config file */
102 #define MAX_BUF_SIZE (640*1024)
103 #define DEFAULT_BANDWIDTH_OP (1024 * 1000)
104 #define MAX_NICKNAME_LEN 32
105 #define MAX_DIR_SIZE 50000 /* XXX, big enough? */
107 #define ACI_TYPE_LOWER 0
108 #define ACI_TYPE_HIGHER 1
109 #define ACI_TYPE_BOTH 2
111 #define _CONN_TYPE_MIN 3
112 #define CONN_TYPE_OR_LISTENER 3
113 #define CONN_TYPE_OR 4
114 #define CONN_TYPE_EXIT 5
115 #define CONN_TYPE_AP_LISTENER 6
116 #define CONN_TYPE_AP 7
117 #define CONN_TYPE_DIR_LISTENER 8
118 #define CONN_TYPE_DIR 9
119 #define CONN_TYPE_DNSWORKER 10
120 #define CONN_TYPE_CPUWORKER 11
121 #define _CONN_TYPE_MAX 11
123 #define LISTENER_STATE_READY 0
125 #define _DNSWORKER_STATE_MIN 1
126 #define DNSWORKER_STATE_IDLE 1
127 #define DNSWORKER_STATE_BUSY 2
128 #define _DNSWORKER_STATE_MAX 2
130 #define _CPUWORKER_STATE_MIN 1
131 #define CPUWORKER_STATE_IDLE 1
132 #define CPUWORKER_STATE_BUSY_ONION 2
133 #define CPUWORKER_STATE_BUSY_HANDSHAKE 3
134 #define _CPUWORKER_STATE_MAX 3
136 #define CPUWORKER_TASK_ONION CPUWORKER_STATE_BUSY_ONION
138 #define _OR_CONN_STATE_MIN 1
139 #define OR_CONN_STATE_CONNECTING 1 /* waiting for connect() to finish */
140 #define OR_CONN_STATE_HANDSHAKING 2 /* SSL is handshaking, not done yet */
141 #define OR_CONN_STATE_OPEN 3 /* ready to send/receive cells. */
142 #define _OR_CONN_STATE_MAX 3
144 #define _EXIT_CONN_STATE_MIN 1
145 #define EXIT_CONN_STATE_RESOLVING 1 /* waiting for response from dns farm */
146 #define EXIT_CONN_STATE_CONNECTING 2 /* waiting for connect() to finish */
147 #define EXIT_CONN_STATE_OPEN 3
148 #define _EXIT_CONN_STATE_MAX 3
150 #define EXIT_CONN_STATE_CLOSE 3 /* flushing the buffer, then will close */
151 #define EXIT_CONN_STATE_CLOSE_WAIT 4 /* have sent a destroy, awaiting a confirmation */
154 /* the AP state values must be disjoint from the EXIT state values */
155 #define _AP_CONN_STATE_MIN 4
156 #define AP_CONN_STATE_SOCKS_WAIT 4
157 #define AP_CONN_STATE_OR_WAIT 5
158 #define AP_CONN_STATE_OPEN 6
159 #define _AP_CONN_STATE_MAX 6
161 #define _DIR_CONN_STATE_MIN 1
162 #define DIR_CONN_STATE_CONNECTING_FETCH 1
163 #define DIR_CONN_STATE_CONNECTING_UPLOAD 2
164 #define DIR_CONN_STATE_CLIENT_SENDING_FETCH 3
165 #define DIR_CONN_STATE_CLIENT_SENDING_UPLOAD 4
166 #define DIR_CONN_STATE_CLIENT_READING_FETCH 5
167 #define DIR_CONN_STATE_CLIENT_READING_UPLOAD 6
168 #define DIR_CONN_STATE_SERVER_COMMAND_WAIT 7
169 #define DIR_CONN_STATE_SERVER_WRITING 8
170 #define _DIR_CONN_STATE_MAX 8
172 #define CIRCUIT_STATE_BUILDING 0 /* I'm the OP, still haven't done all my handshakes */
173 #define CIRCUIT_STATE_ONIONSKIN_PENDING 1 /* waiting to process the onionskin */
174 #define CIRCUIT_STATE_OR_WAIT 2 /* I'm the OP, my firsthop is still connecting */
175 #define CIRCUIT_STATE_OPEN 3 /* onionskin(s) processed, ready to send/receive cells */
177 #define RELAY_COMMAND_BEGIN 1
178 #define RELAY_COMMAND_DATA 2
179 #define RELAY_COMMAND_END 3
180 #define RELAY_COMMAND_CONNECTED 4
181 #define RELAY_COMMAND_SENDME 5
182 #define RELAY_COMMAND_EXTEND 6
183 #define RELAY_COMMAND_EXTENDED 7
184 #define RELAY_COMMAND_TRUNCATE 8
185 #define RELAY_COMMAND_TRUNCATED 9
187 #define RELAY_HEADER_SIZE 8
189 /* default cipher function */
190 #define DEFAULT_CIPHER CRYPTO_CIPHER_AES_CTR
191 /* Used to en/decrypt onion skins */
192 #define ONION_CIPHER DEFAULT_CIPHER
193 /* Used to en/decrypt RELAY cells */
194 #define CIRCUIT_CIPHER DEFAULT_CIPHER
196 #define CELL_DIRECTION_IN 1
197 #define CELL_DIRECTION_OUT 2
198 #define EDGE_EXIT CONN_TYPE_EXIT
199 #define EDGE_AP CONN_TYPE_AP
200 #define CELL_DIRECTION(x) ((x) == EDGE_EXIT ? CELL_DIRECTION_IN : CELL_DIRECTION_OUT)
202 #define CIRCWINDOW_START 1000
203 #define CIRCWINDOW_INCREMENT 100
205 #define STREAMWINDOW_START 500
206 #define STREAMWINDOW_INCREMENT 50
209 #define CELL_PADDING 0
210 #define CELL_CREATE 1
211 #define CELL_CREATED 2
213 #define CELL_DESTROY 4
215 #define CELL_PAYLOAD_SIZE 248
216 #define CELL_NETWORK_SIZE 256
218 /* legal characters in a filename */
219 #define CONFIG_LEGAL_FILENAME_CHARACTERS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-_/"
220 /* legal characters in a nickname */
221 #define LEGAL_NICKNAME_CHARACTERS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
223 /* structure of a socks client operation */
225 unsigned char version
; /* socks version number */
226 unsigned char command
; /* command code */
227 uint16_t destport
; /* destination port, host order */
228 uint32_t destip
; /* destination address, host order */
229 /* userid follows, terminated by a \0 */
230 /* dest host follows, terminated by a \0 */
233 #define SOCKS4_NETWORK_LEN 8
235 typedef uint16_t aci_t
;
237 /* cell definition */
239 aci_t aci
; /* Anonymous Connection Identifier */
240 unsigned char command
;
241 unsigned char length
; /* of payload if relay cell */
242 uint32_t seq
; /* sequence number */
244 unsigned char payload
[CELL_PAYLOAD_SIZE
];
246 #define CELL_RELAY_COMMAND(c) (*(uint8_t*)((c).payload))
247 #define SET_CELL_RELAY_COMMAND(c,cmd) (*(uint8_t*)((c).payload) = (cmd))
248 #define STREAM_ID_SIZE 7
249 #define SET_CELL_STREAM_ID(c,id) memcpy((c).payload+1,(id),STREAM_ID_SIZE)
251 #define ZERO_STREAM "\0\0\0\0\0\0\0\0"
253 typedef struct buf_t buf_t
;
255 struct connection_t
{
259 uint8_t wants_to_read
; /* should we start reading again once
260 * the bandwidth throttler allows it?
262 uint8_t wants_to_write
; /* should we start writing again once
263 * the bandwidth throttler allows reads?
265 int s
; /* our socket */
266 int poll_index
; /* index of this conn into the poll_array */
267 int marked_for_close
; /* should we close this conn on the next
268 * iteration of the main loop?
272 int inbuf_reached_eof
; /* did read() return 0 on this conn? */
273 long timestamp_lastread
; /* when was the last time poll() said we could read? */
276 int outbuf_flushlen
; /* how much data should we try to flush from the outbuf? */
277 long timestamp_lastwritten
; /* when was the last time poll() said we could write? */
279 long timestamp_created
; /* when was this connection_t created? */
281 uint32_t addr
; /* these two uniquely identify a router. Both in host order. */
282 uint16_t port
; /* if non-zero, they identify the guy on the other end
283 * of the connection. */
284 char *address
; /* FQDN (or IP) of the guy on the other end.
285 * strdup into this, because free_connection frees it
287 crypto_pk_env_t
*onion_pkey
; /* public RSA key for the other side's onions */
288 crypto_pk_env_t
*link_pkey
; /* public RSA key for the other side's TLS */
289 crypto_pk_env_t
*identity_pkey
; /* public RSA key for the other side's signing */
292 /* Used only by OR connections: */
294 uint16_t next_aci
; /* Which ACI do we try to use next on this connection?
295 * This is always in the range 0..1<<15-1.*/
297 /* bandwidth and receiver_bucket only used by ORs in OPEN state: */
298 uint32_t bandwidth
; /* connection bandwidth. */
299 int receiver_bucket
; /* when this hits 0, stop receiving. Every second we
300 * add 'bandwidth' to this, capping it at 10*bandwidth.
303 /* Used only by edge connections: */
304 char stream_id
[STREAM_ID_SIZE
];
305 struct connection_t
*next_stream
; /* points to the next stream at this edge, if any */
306 struct crypt_path_t
*cpath_layer
; /* a pointer to which node in the circ this conn exits at */
307 int package_window
; /* how many more relay cells can i send into the circuit? */
308 int deliver_window
; /* how many more relay cells can end at me? */
310 int done_sending
; /* for half-open connections; not used currently */
314 typedef struct connection_t connection_t
;
316 #define EXIT_POLICY_ACCEPT 1
317 #define EXIT_POLICY_REJECT 2
319 struct exit_policy_t
{
325 struct exit_policy_t
*next
;
328 /* config stuff we know about the other ORs in the network */
333 uint32_t addr
; /* all host order */
340 crypto_pk_env_t
*onion_pkey
; /* public RSA key for onions */
341 crypto_pk_env_t
*link_pkey
; /* public RSA key for TLS */
342 crypto_pk_env_t
*identity_pkey
; /* public RSA key for signing */
348 struct exit_policy_t
*exit_policy
;
351 #define MAX_ROUTERS_IN_DIR 1024
353 routerinfo_t
**routers
;
355 char *software_versions
;
359 struct crypt_path_t
{
361 /* crypto environments */
362 crypto_cipher_env_t
*f_crypto
;
363 crypto_cipher_env_t
*b_crypto
;
365 crypto_dh_env_t
*handshake_state
;
371 #define CPATH_STATE_CLOSED 0
372 #define CPATH_STATE_AWAITING_KEYS 1
373 #define CPATH_STATE_OPEN 2
374 struct crypt_path_t
*next
;
375 struct crypt_path_t
*prev
; /* doubly linked list */
381 #define DH_KEY_LEN CRYPTO_DH_SIZE
382 #define DH_ONIONSKIN_LEN DH_KEY_LEN+16
384 typedef struct crypt_path_t crypt_path_t
;
386 /* struct for a path (circuit) through the network */
390 connection_t
*p_conn
;
391 connection_t
*n_conn
; /* for the OR conn, if there is one */
392 connection_t
*p_streams
;
393 connection_t
*n_streams
;
397 aci_t p_aci
; /* circuit identifiers */
400 crypto_cipher_env_t
*p_crypto
; /* used only for intermediate hops */
401 crypto_cipher_env_t
*n_crypto
;
405 char onionskin
[DH_ONIONSKIN_LEN
]; /* for storage while onionskin pending */
406 long timestamp_created
;
407 uint8_t dirty
; /* whether this circuit has been used yet */
414 typedef struct circuit_t circuit_t
;
432 int DirRebuildPeriod
;
433 int DirFetchPostPeriod
;
435 int MaxOnionsPending
;
436 int NewCircuitPeriod
;
443 /* all the function prototypes go here */
445 /********************************* buffers.c ***************************/
447 int find_on_inbuf(char *string
, int string_len
, buf_t
*buf
);
450 buf_t
*buf_new_with_capacity(size_t size
);
451 void buf_free(buf_t
*buf
);
453 size_t buf_datalen(const buf_t
*buf
);
454 size_t buf_capacity(const buf_t
*buf
);
455 const char *_buf_peek_raw_buffer(const buf_t
*buf
);
457 int read_to_buf(int s
, int at_most
, buf_t
*buf
, int *reached_eof
);
458 int read_to_buf_tls(tor_tls
*tls
, int at_most
, buf_t
*buf
);
460 int flush_buf(int s
, buf_t
*buf
, int *buf_flushlen
);
461 int flush_buf_tls(tor_tls
*tls
, buf_t
*buf
, int *buf_flushlen
);
463 int write_to_buf(const char *string
, int string_len
, buf_t
*buf
);
464 int fetch_from_buf(char *string
, int string_len
, buf_t
*buf
);
465 int fetch_from_buf_http(buf_t
*buf
,
466 char *headers_out
, int max_headerlen
,
467 char *body_out
, int max_bodylen
);
468 int fetch_from_buf_socks(buf_t
*buf
,
469 char *addr_out
, int max_addrlen
,
472 /********************************* circuit.c ***************************/
474 void circuit_add(circuit_t
*circ
);
475 void circuit_remove(circuit_t
*circ
);
476 circuit_t
*circuit_new(aci_t p_aci
, connection_t
*p_conn
);
477 void circuit_free(circuit_t
*circ
);
479 circuit_t
*circuit_enumerate_by_naddr_nport(circuit_t
*start
, uint32_t naddr
, uint16_t nport
);
480 circuit_t
*circuit_get_by_aci_conn(aci_t aci
, connection_t
*conn
);
481 circuit_t
*circuit_get_by_conn(connection_t
*conn
);
482 circuit_t
*circuit_get_newest_open(void);
484 int circuit_deliver_relay_cell(cell_t
*cell
, circuit_t
*circ
,
485 int cell_direction
, crypt_path_t
*layer_hint
);
486 int relay_crypt(circuit_t
*circ
, char *in
, int inlen
, char cell_direction
,
487 crypt_path_t
**layer_hint
, char *recognized
, connection_t
**conn
);
488 int relay_check_recognized(circuit_t
*circ
, int cell_direction
, char *stream
, connection_t
**conn
);
490 void circuit_resume_edge_reading(circuit_t
*circ
, int edge_type
, crypt_path_t
*layer_hint
);
491 int circuit_consider_stop_edge_reading(circuit_t
*circ
, int edge_type
, crypt_path_t
*layer_hint
);
492 int circuit_consider_sending_sendme(circuit_t
*circ
, int edge_type
, crypt_path_t
*layer_hint
);
494 void circuit_close(circuit_t
*circ
);
495 void circuit_about_to_close_connection(connection_t
*conn
);
497 void circuit_dump_by_conn(connection_t
*conn
);
499 void circuit_expire_unused_circuits(void);
500 void circuit_launch_new(int failure_status
);
501 int circuit_establish_circuit(void);
502 void circuit_n_conn_open(connection_t
*or_conn
);
503 int circuit_send_next_onion_skin(circuit_t
*circ
);
504 int circuit_extend(cell_t
*cell
, circuit_t
*circ
);
505 int circuit_finish_handshake(circuit_t
*circ
, char *reply
);
506 int circuit_truncated(circuit_t
*circ
, crypt_path_t
*layer
);
508 void assert_cpath_ok(const crypt_path_t
*c
);
509 void assert_cpath_layer_ok(const crypt_path_t
*c
);
510 void assert_circuit_ok(const circuit_t
*c
);
512 /********************************* command.c ***************************/
514 void command_process_cell(cell_t
*cell
, connection_t
*conn
);
516 /********************************* config.c ***************************/
518 int getconfig(int argc
, char **argv
, or_options_t
*options
);
520 /********************************* connection.c ***************************/
522 connection_t
*connection_new(int type
);
523 void connection_free(connection_t
*conn
);
525 int connection_create_listener(struct sockaddr_in
*bindaddr
, int type
);
526 int connection_handle_listener_read(connection_t
*conn
, int new_type
);
528 int connection_connect(connection_t
*conn
, char *address
, uint32_t addr
, uint16_t port
);
529 int retry_all_connections(uint16_t or_listenport
, uint16_t ap_listenport
, uint16_t dir_listenport
);
531 int connection_handle_read(connection_t
*conn
);
532 int connection_read_to_buf(connection_t
*conn
);
534 int connection_fetch_from_buf(char *string
, int len
, connection_t
*conn
);
535 int connection_find_on_inbuf(char *string
, int len
, connection_t
*conn
);
537 int connection_wants_to_flush(connection_t
*conn
);
538 int connection_outbuf_too_full(connection_t
*conn
);
539 int connection_flush_buf(connection_t
*conn
);
540 int connection_handle_write(connection_t
*conn
);
541 int connection_write_to_buf(const char *string
, int len
, connection_t
*conn
);
543 connection_t
*connection_twin_get_by_addr_port(uint32_t addr
, uint16_t port
);
544 connection_t
*connection_exact_get_by_addr_port(uint32_t addr
, uint16_t port
);
546 connection_t
*connection_get_by_type(int type
);
547 connection_t
*connection_get_by_type_state(int type
, int state
);
548 connection_t
*connection_get_by_type_state_lastwritten(int type
, int state
);
550 int connection_receiver_bucket_should_increase(connection_t
*conn
);
552 #define connection_speaks_cells(conn) ((conn)->type == CONN_TYPE_OR)
553 int connection_is_listener(connection_t
*conn
);
554 int connection_state_is_open(connection_t
*conn
);
556 int connection_send_destroy(aci_t aci
, connection_t
*conn
);
558 int connection_process_inbuf(connection_t
*conn
);
559 int connection_finished_flushing(connection_t
*conn
);
561 void assert_connection_ok(connection_t
*conn
, time_t now
);
563 /********************************* connection_edge.c ***************************/
565 int connection_edge_process_inbuf(connection_t
*conn
);
566 int connection_edge_send_command(connection_t
*fromconn
, circuit_t
*circ
, int relay_command
);
567 int connection_edge_process_relay_cell(cell_t
*cell
, circuit_t
*circ
, connection_t
*conn
,
568 int edge_type
, crypt_path_t
*layer_hint
);
569 int connection_edge_finished_flushing(connection_t
*conn
);
571 int connection_package_raw_inbuf(connection_t
*conn
);
572 int connection_consider_sending_sendme(connection_t
*conn
, int edge_type
);
574 int connection_exit_connect(connection_t
*conn
);
576 /********************************* connection_or.c ***************************/
578 int connection_or_process_inbuf(connection_t
*conn
);
579 int connection_or_finished_flushing(connection_t
*conn
);
581 void connection_or_init_conn_from_router(connection_t
*conn
, routerinfo_t
*router
);
582 connection_t
*connection_or_connect(routerinfo_t
*router
);
584 int connection_tls_start_handshake(connection_t
*conn
, int receiving
);
585 int connection_tls_continue_handshake(connection_t
*conn
);
587 int connection_write_cell_to_buf(const cell_t
*cellp
, connection_t
*conn
);
588 int connection_process_cell_from_inbuf(connection_t
*conn
);
590 /********************************* cpuworker.c *****************************/
593 int connection_cpu_finished_flushing(connection_t
*conn
);
594 int connection_cpu_process_inbuf(connection_t
*conn
);
595 int cpuworker_main(void *data
);
596 int assign_to_cpuworker(connection_t
*cpuworker
, unsigned char question_type
,
599 /********************************* directory.c ***************************/
601 void directory_initiate_command(routerinfo_t
*router
, int command
);
602 int connection_dir_process_inbuf(connection_t
*conn
);
603 int connection_dir_finished_flushing(connection_t
*conn
);
605 /********************************* dns.c ***************************/
608 int connection_dns_finished_flushing(connection_t
*conn
);
609 int connection_dns_process_inbuf(connection_t
*conn
);
610 void dns_cancel_pending_resolve(char *question
, connection_t
*onlyconn
);
611 int dns_resolve(connection_t
*exitconn
);
613 /********************************* main.c ***************************/
615 void set_onion_key(crypto_pk_env_t
*k
);
616 crypto_pk_env_t
*get_onion_key(void);
617 void set_identity_key(crypto_pk_env_t
*k
);
618 crypto_pk_env_t
*get_identity_key(void);
619 crypto_pk_env_t
*get_link_key(void);
620 int connection_add(connection_t
*conn
);
621 int connection_remove(connection_t
*conn
);
622 void connection_set_poll_socket(connection_t
*conn
);
624 void get_connection_array(connection_t
***array
, int *n
);
626 void connection_watch_events(connection_t
*conn
, short events
);
627 int connection_is_reading(connection_t
*conn
);
628 void connection_stop_reading(connection_t
*conn
);
629 void connection_start_reading(connection_t
*conn
);
630 void connection_stop_writing(connection_t
*conn
);
631 void connection_start_writing(connection_t
*conn
);
633 const char *router_get_my_descriptor(void);
635 int main(int argc
, char *argv
[]);
637 /********************************* onion.c ***************************/
639 int decide_aci_type(uint32_t local_addr
, uint16_t local_port
,
640 uint32_t remote_addr
, uint16_t remote_port
);
642 int onion_pending_add(circuit_t
*circ
);
643 circuit_t
*onion_next_task(void);
644 void onion_pending_remove(circuit_t
*circ
);
646 int onionskin_answer(circuit_t
*circ
, unsigned char *payload
, unsigned char *keys
);
648 crypt_path_t
*onion_generate_cpath(routerinfo_t
**firsthop
);
650 int onion_skin_create(crypto_pk_env_t
*router_key
,
651 crypto_dh_env_t
**handshake_state_out
,
652 char *onion_skin_out
); /* Must be DH_ONIONSKIN_LEN bytes long */
654 int onion_skin_server_handshake(char *onion_skin
, /* DH_ONIONSKIN_LEN bytes long */
655 crypto_pk_env_t
*private_key
,
656 char *handshake_reply_out
, /* DH_KEY_LEN bytes long */
660 int onion_skin_client_handshake(crypto_dh_env_t
*handshake_state
,
661 char *handshake_reply
,/* Must be DH_KEY_LEN bytes long*/
665 /********************************* routers.c ***************************/
667 int learn_my_address(struct sockaddr_in
*me
);
668 void router_retry_connections(void);
669 routerinfo_t
*router_pick_directory_server(void);
670 void router_upload_desc_to_dirservers(void);
671 routerinfo_t
*router_get_by_addr_port(uint32_t addr
, uint16_t port
);
672 routerinfo_t
*router_get_by_link_pk(crypto_pk_env_t
*pk
);
673 routerinfo_t
*router_get_by_nickname(char *nickname
);
674 void router_get_directory(directory_t
**pdirectory
);
675 int router_is_me(uint32_t addr
, uint16_t port
);
676 void router_mark_as_down(char *nickname
);
677 int router_get_list_from_file(char *routerfile
);
678 int router_get_router_hash(char *s
, char *digest
);
679 int router_get_dir_hash(char *s
, char *digest
);
681 /* Reads a list of known routers, unsigned. */
682 int router_get_list_from_string(char *s
);
683 /* Exported for debugging */
684 int router_get_list_from_string_impl(char **s
, directory_t
**dest
, int n_good_nicknames
, const char *good_nickname_lst
[]);
685 /* Reads a signed directory. */
686 int router_get_dir_from_string(char *s
, crypto_pk_env_t
*pkey
);
687 /* Exported or debugging */
688 int router_get_dir_from_string_impl(char *s
, directory_t
**dest
,
689 crypto_pk_env_t
*pkey
);
690 routerinfo_t
*router_get_entry_from_string(char **s
);
691 int router_compare_to_exit_policy(connection_t
*conn
);
692 void routerinfo_free(routerinfo_t
*router
);
693 int router_dump_router_to_string(char *s
, int maxlen
, routerinfo_t
*router
,
694 crypto_pk_env_t
*ident_key
);
695 const routerinfo_t
*router_get_desc_routerinfo(void);
696 const char *router_get_my_descriptor(void);
697 int router_rebuild_descriptor(void);
699 /********************************* dirserv.c ***************************/
700 int dirserv_add_own_fingerprint(const char *nickname
, crypto_pk_env_t
*pk
);
701 int dirserv_parse_fingerprint_file(const char *fname
);
702 int dirserv_router_fingerprint_is_known(const routerinfo_t
*router
);
703 void dirserv_free_fingerprint_list();
704 int dirserv_add_descriptor(const char **desc
);
705 int dirserv_init_from_directory_string(const char *dir
);
706 void dirserv_free_descriptors();
707 int dirserv_dump_directory_to_string(char *s
, int maxlen
,
708 crypto_pk_env_t
*private_key
);
709 void directory_set_dirty();
710 size_t dirserv_get_directory(const char **cp
);