put out 0.0.2pre12
[tor.git] / src / or / or.h
blob239b7c0b61c430d37ad090d7b0a6626b935e4e1d
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_WINSOCK_H
76 #include <winsock.h>
77 #endif
78 #if _MSC_VER > 1300
79 #include <winsock2.h>
80 #include <ws2tcpip.h>
81 #elif defined(_MSC_VER)
82 #include <winsock.h>
83 #endif
85 #ifdef MS_WINDOWS
86 #include <io.h>
87 #include <process.h>
88 #define WIN32_LEAN_AND_MEAN
89 #include <windows.h>
90 #define snprintf _snprintf
91 #endif
93 #include "../common/crypto.h"
94 #include "../common/tortls.h"
95 #include "../common/log.h"
96 #include "../common/util.h"
98 #define RECOMMENDED_SOFTWARE_VERSIONS "0.0.2pre8,0.0.2pre9,0.0.2pre10,0.0.2pre11,0.0.2pre12,0.0.2pre13"
100 #define MAXCONNECTIONS 1000 /* upper bound on max connections.
101 can be lowered by config file */
103 #define MAX_BUF_SIZE (640*1024)
104 #define DEFAULT_BANDWIDTH_OP (1024 * 1000)
105 #define MAX_NICKNAME_LEN 32
106 #define MAX_DIR_SIZE 50000 /* XXX, big enough? */
108 #define ACI_TYPE_LOWER 0
109 #define ACI_TYPE_HIGHER 1
110 #define ACI_TYPE_BOTH 2
112 #define _CONN_TYPE_MIN 3
113 #define CONN_TYPE_OR_LISTENER 3
114 #define CONN_TYPE_OR 4
115 #define CONN_TYPE_EXIT 5
116 #define CONN_TYPE_AP_LISTENER 6
117 #define CONN_TYPE_AP 7
118 #define CONN_TYPE_DIR_LISTENER 8
119 #define CONN_TYPE_DIR 9
120 #define CONN_TYPE_DNSWORKER 10
121 #define CONN_TYPE_CPUWORKER 11
122 #define _CONN_TYPE_MAX 11
124 #define LISTENER_STATE_READY 0
126 #define _DNSWORKER_STATE_MIN 1
127 #define DNSWORKER_STATE_IDLE 1
128 #define DNSWORKER_STATE_BUSY 2
129 #define _DNSWORKER_STATE_MAX 2
131 #define _CPUWORKER_STATE_MIN 1
132 #define CPUWORKER_STATE_IDLE 1
133 #define CPUWORKER_STATE_BUSY_ONION 2
134 #define CPUWORKER_STATE_BUSY_HANDSHAKE 3
135 #define _CPUWORKER_STATE_MAX 3
137 #define CPUWORKER_TASK_ONION CPUWORKER_STATE_BUSY_ONION
139 #define _OR_CONN_STATE_MIN 1
140 #define OR_CONN_STATE_CONNECTING 1 /* waiting for connect() to finish */
141 #define OR_CONN_STATE_HANDSHAKING 2 /* SSL is handshaking, not done yet */
142 #define OR_CONN_STATE_OPEN 3 /* ready to send/receive cells. */
143 #define _OR_CONN_STATE_MAX 3
145 #define _EXIT_CONN_STATE_MIN 1
146 #define EXIT_CONN_STATE_RESOLVING 1 /* waiting for response from dns farm */
147 #define EXIT_CONN_STATE_CONNECTING 2 /* waiting for connect() to finish */
148 #define EXIT_CONN_STATE_OPEN 3
149 #define _EXIT_CONN_STATE_MAX 3
150 #if 0
151 #define EXIT_CONN_STATE_CLOSE 3 /* flushing the buffer, then will close */
152 #define EXIT_CONN_STATE_CLOSE_WAIT 4 /* have sent a destroy, awaiting a confirmation */
153 #endif
155 /* the AP state values must be disjoint from the EXIT state values */
156 #define _AP_CONN_STATE_MIN 4
157 #define AP_CONN_STATE_SOCKS_WAIT 4
158 #define AP_CONN_STATE_OR_WAIT 5
159 #define AP_CONN_STATE_OPEN 6
160 #define _AP_CONN_STATE_MAX 6
162 #define _DIR_CONN_STATE_MIN 1
163 #define DIR_CONN_STATE_CONNECTING_FETCH 1
164 #define DIR_CONN_STATE_CONNECTING_UPLOAD 2
165 #define DIR_CONN_STATE_CLIENT_SENDING_FETCH 3
166 #define DIR_CONN_STATE_CLIENT_SENDING_UPLOAD 4
167 #define DIR_CONN_STATE_CLIENT_READING_FETCH 5
168 #define DIR_CONN_STATE_CLIENT_READING_UPLOAD 6
169 #define DIR_CONN_STATE_SERVER_COMMAND_WAIT 7
170 #define DIR_CONN_STATE_SERVER_WRITING 8
171 #define _DIR_CONN_STATE_MAX 8
173 #define CIRCUIT_STATE_BUILDING 0 /* I'm the OP, still haven't done all my handshakes */
174 #define CIRCUIT_STATE_ONIONSKIN_PENDING 1 /* waiting to process the onionskin */
175 #define CIRCUIT_STATE_OR_WAIT 2 /* I'm the OP, my firsthop is still connecting */
176 #define CIRCUIT_STATE_OPEN 3 /* onionskin(s) processed, ready to send/receive cells */
178 #define RELAY_COMMAND_BEGIN 1
179 #define RELAY_COMMAND_DATA 2
180 #define RELAY_COMMAND_END 3
181 #define RELAY_COMMAND_CONNECTED 4
182 #define RELAY_COMMAND_SENDME 5
183 #define RELAY_COMMAND_EXTEND 6
184 #define RELAY_COMMAND_EXTENDED 7
185 #define RELAY_COMMAND_TRUNCATE 8
186 #define RELAY_COMMAND_TRUNCATED 9
188 #define RELAY_HEADER_SIZE 8
190 /* default cipher function */
191 #define DEFAULT_CIPHER CRYPTO_CIPHER_AES_CTR
192 /* Used to en/decrypt onion skins */
193 #define ONION_CIPHER DEFAULT_CIPHER
194 /* Used to en/decrypt RELAY cells */
195 #define CIRCUIT_CIPHER DEFAULT_CIPHER
197 #define CELL_DIRECTION_IN 1
198 #define CELL_DIRECTION_OUT 2
199 #define EDGE_EXIT CONN_TYPE_EXIT
200 #define EDGE_AP CONN_TYPE_AP
201 #define CELL_DIRECTION(x) ((x) == EDGE_EXIT ? CELL_DIRECTION_IN : CELL_DIRECTION_OUT)
203 #define CIRCWINDOW_START 1000
204 #define CIRCWINDOW_INCREMENT 100
206 #define STREAMWINDOW_START 500
207 #define STREAMWINDOW_INCREMENT 50
209 /* cell commands */
210 #define CELL_PADDING 0
211 #define CELL_CREATE 1
212 #define CELL_CREATED 2
213 #define CELL_RELAY 3
214 #define CELL_DESTROY 4
216 #define CELL_PAYLOAD_SIZE 248
217 #define CELL_NETWORK_SIZE 256
219 /* legal characters in a filename */
220 #define CONFIG_LEGAL_FILENAME_CHARACTERS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-_/"
221 /* legal characters in a nickname */
222 #define LEGAL_NICKNAME_CHARACTERS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
224 /* structure of a socks client operation */
225 typedef struct {
226 unsigned char version; /* socks version number */
227 unsigned char command; /* command code */
228 uint16_t destport; /* destination port, host order */
229 uint32_t destip; /* destination address, host order */
230 /* userid follows, terminated by a \0 */
231 /* dest host follows, terminated by a \0 */
232 } socks4_t;
234 #define SOCKS4_NETWORK_LEN 8
236 typedef uint16_t aci_t;
238 /* cell definition */
239 typedef struct {
240 aci_t aci; /* Anonymous Connection Identifier */
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)
252 #define ZERO_STREAM "\0\0\0\0\0\0\0\0"
254 typedef struct buf_t buf_t;
256 struct connection_t {
258 uint8_t type;
259 uint8_t state;
260 uint8_t wants_to_read; /* should we start reading again once
261 * the bandwidth throttler allows it?
263 uint8_t wants_to_write; /* should we start writing again once
264 * the bandwidth throttler allows reads?
266 int s; /* our socket */
267 int poll_index; /* index of this conn into the poll_array */
268 int marked_for_close; /* should we close this conn on the next
269 * iteration of the main loop?
272 buf_t *inbuf;
273 int inbuf_reached_eof; /* did read() return 0 on this conn? */
274 long timestamp_lastread; /* when was the last time poll() said we could read? */
276 buf_t *outbuf;
277 int outbuf_flushlen; /* how much data should we try to flush from the outbuf? */
278 long timestamp_lastwritten; /* when was the last time poll() said we could write? */
280 long timestamp_created; /* when was this connection_t created? */
282 uint32_t addr; /* these two uniquely identify a router. Both in host order. */
283 uint16_t port; /* if non-zero, they identify the guy on the other end
284 * of the connection. */
285 char *address; /* FQDN (or IP) of the guy on the other end.
286 * strdup into this, because free_connection frees it
288 crypto_pk_env_t *onion_pkey; /* public RSA key for the other side's onions */
289 crypto_pk_env_t *link_pkey; /* public RSA key for the other side's TLS */
290 crypto_pk_env_t *identity_pkey; /* public RSA key for the other side's signing */
291 char *nickname;
293 /* Used only by OR connections: */
294 tor_tls *tls;
295 uint16_t next_aci; /* Which ACI do we try to use next on this connection?
296 * This is always in the range 0..1<<15-1.*/
298 /* bandwidth and receiver_bucket only used by ORs in OPEN state: */
299 uint32_t bandwidth; /* connection bandwidth. */
300 int receiver_bucket; /* when this hits 0, stop receiving. Every second we
301 * add 'bandwidth' to this, capping it at 10*bandwidth.
304 /* Used only by edge connections: */
305 char socks_version;
306 char stream_id[STREAM_ID_SIZE];
307 struct connection_t *next_stream; /* points to the next stream at this edge, if any */
308 struct crypt_path_t *cpath_layer; /* a pointer to which node in the circ this conn exits at */
309 int package_window; /* how many more relay cells can i send into the circuit? */
310 int deliver_window; /* how many more relay cells can end at me? */
312 int done_sending; /* for half-open connections; not used currently */
313 int done_receiving;
316 typedef struct connection_t connection_t;
318 #define EXIT_POLICY_ACCEPT 1
319 #define EXIT_POLICY_REJECT 2
321 struct exit_policy_t {
322 char policy_type;
323 char *string;
324 char *address;
325 char *port;
327 struct exit_policy_t *next;
330 /* config stuff we know about the other ORs in the network */
331 typedef struct {
332 char *address;
333 char *nickname;
335 uint32_t addr; /* all host order */
336 uint16_t or_port;
337 uint16_t ap_port;
338 uint16_t dir_port;
340 time_t published_on;
342 crypto_pk_env_t *onion_pkey; /* public RSA key for onions */
343 crypto_pk_env_t *link_pkey; /* public RSA key for TLS */
344 crypto_pk_env_t *identity_pkey; /* public RSA key for signing */
346 int is_running;
348 /* link info */
349 uint32_t bandwidth;
350 struct exit_policy_t *exit_policy;
351 } routerinfo_t;
353 #define MAX_ROUTERS_IN_DIR 1024
354 typedef struct {
355 routerinfo_t **routers;
356 int n_routers;
357 char *software_versions;
358 time_t published_on;
359 } directory_t;
361 struct crypt_path_t {
363 /* crypto environments */
364 crypto_cipher_env_t *f_crypto;
365 crypto_cipher_env_t *b_crypto;
367 crypto_dh_env_t *handshake_state;
369 uint32_t addr;
370 uint16_t port;
372 uint8_t state;
373 #define CPATH_STATE_CLOSED 0
374 #define CPATH_STATE_AWAITING_KEYS 1
375 #define CPATH_STATE_OPEN 2
376 struct crypt_path_t *next;
377 struct crypt_path_t *prev; /* doubly linked list */
379 int package_window;
380 int deliver_window;
383 #define DH_KEY_LEN CRYPTO_DH_SIZE
384 #define DH_ONIONSKIN_LEN DH_KEY_LEN+16
386 typedef struct crypt_path_t crypt_path_t;
388 /* struct for a path (circuit) through the network */
389 struct circuit_t {
390 uint32_t n_addr;
391 uint16_t n_port;
392 connection_t *p_conn;
393 connection_t *n_conn; /* for the OR conn, if there is one */
394 connection_t *p_streams;
395 connection_t *n_streams;
396 int package_window;
397 int deliver_window;
399 aci_t p_aci; /* circuit identifiers */
400 aci_t n_aci;
402 crypto_cipher_env_t *p_crypto; /* used only for intermediate hops */
403 crypto_cipher_env_t *n_crypto;
405 crypt_path_t *cpath;
407 char onionskin[DH_ONIONSKIN_LEN]; /* for storage while onionskin pending */
408 long timestamp_created;
409 uint8_t dirty; /* whether this circuit has been used yet */
411 uint8_t state;
413 void *next;
416 typedef struct circuit_t circuit_t;
418 typedef struct {
419 char *LogLevel;
420 char *DataDirectory;
421 char *RouterFile;
422 char *Nickname;
423 char *Address;
424 char *PidFile;
425 char *ExitPolicy;
426 double CoinWeight;
427 int Daemon;
428 int ORPort;
429 int APPort;
430 int DirPort;
431 int MaxConn;
432 int OnionRouter;
433 int TrafficShaping;
434 int LinkPadding;
435 int IgnoreVersion;
436 int DirRebuildPeriod;
437 int DirFetchPostPeriod;
438 int KeepalivePeriod;
439 int MaxOnionsPending;
440 int NewCircuitPeriod;
441 int TotalBandwidth;
442 int NumCpus;
443 int Role;
444 int loglevel;
445 } or_options_t;
447 /* all the function prototypes go here */
449 /********************************* buffers.c ***************************/
451 int find_on_inbuf(char *string, int string_len, buf_t *buf);
453 buf_t *buf_new();
454 buf_t *buf_new_with_capacity(size_t size);
455 void buf_free(buf_t *buf);
457 size_t buf_datalen(const buf_t *buf);
458 size_t buf_capacity(const buf_t *buf);
459 const char *_buf_peek_raw_buffer(const buf_t *buf);
461 int read_to_buf(int s, int at_most, buf_t *buf, int *reached_eof);
462 int read_to_buf_tls(tor_tls *tls, int at_most, buf_t *buf);
464 int flush_buf(int s, buf_t *buf, int *buf_flushlen);
465 int flush_buf_tls(tor_tls *tls, buf_t *buf, int *buf_flushlen);
467 int write_to_buf(const char *string, int string_len, buf_t *buf);
468 int fetch_from_buf(char *string, int string_len, buf_t *buf);
469 int fetch_from_buf_http(buf_t *buf,
470 char *headers_out, int max_headerlen,
471 char *body_out, int max_bodylen);
472 int fetch_from_buf_socks(buf_t *buf, char *socks_version,
473 char *reply, int *replylen,
474 char *addr_out, int max_addrlen,
475 uint16_t *port_out);
477 /********************************* circuit.c ***************************/
479 void circuit_add(circuit_t *circ);
480 void circuit_remove(circuit_t *circ);
481 circuit_t *circuit_new(aci_t p_aci, connection_t *p_conn);
482 void circuit_free(circuit_t *circ);
484 circuit_t *circuit_enumerate_by_naddr_nport(circuit_t *start, uint32_t naddr, uint16_t nport);
485 circuit_t *circuit_get_by_aci_conn(aci_t aci, connection_t *conn);
486 circuit_t *circuit_get_by_conn(connection_t *conn);
487 circuit_t *circuit_get_newest_open(void);
489 int circuit_deliver_relay_cell(cell_t *cell, circuit_t *circ,
490 int cell_direction, crypt_path_t *layer_hint);
491 int relay_crypt(circuit_t *circ, char *in, int inlen, char cell_direction,
492 crypt_path_t **layer_hint, char *recognized, connection_t **conn);
493 int relay_check_recognized(circuit_t *circ, int cell_direction, char *stream, connection_t **conn);
495 void circuit_resume_edge_reading(circuit_t *circ, int edge_type, crypt_path_t *layer_hint);
496 int circuit_consider_stop_edge_reading(circuit_t *circ, int edge_type, crypt_path_t *layer_hint);
497 int circuit_consider_sending_sendme(circuit_t *circ, int edge_type, crypt_path_t *layer_hint);
499 void circuit_close(circuit_t *circ);
500 void circuit_about_to_close_connection(connection_t *conn);
502 void circuit_dump_by_conn(connection_t *conn);
504 void circuit_expire_unused_circuits(void);
505 void circuit_launch_new(int failure_status);
506 int circuit_establish_circuit(void);
507 void circuit_n_conn_open(connection_t *or_conn);
508 int circuit_send_next_onion_skin(circuit_t *circ);
509 int circuit_extend(cell_t *cell, circuit_t *circ);
510 int circuit_finish_handshake(circuit_t *circ, char *reply);
511 int circuit_truncated(circuit_t *circ, crypt_path_t *layer);
513 void assert_cpath_ok(const crypt_path_t *c);
514 void assert_cpath_layer_ok(const crypt_path_t *c);
515 void assert_circuit_ok(const circuit_t *c);
517 extern unsigned long stats_n_relay_cells_relayed;
518 extern unsigned long stats_n_relay_cells_delivered;
520 /********************************* command.c ***************************/
522 void command_process_cell(cell_t *cell, connection_t *conn);
524 extern unsigned long stats_n_padding_cells_processed;
525 extern unsigned long stats_n_create_cells_processed;
526 extern unsigned long stats_n_created_cells_processed;
527 extern unsigned long stats_n_relay_cells_processed;
528 extern unsigned long stats_n_destroy_cells_processed;
530 /********************************* config.c ***************************/
532 int getconfig(int argc, char **argv, or_options_t *options);
534 /********************************* connection.c ***************************/
536 connection_t *connection_new(int type);
537 void connection_free(connection_t *conn);
539 int connection_create_listener(struct sockaddr_in *bindaddr, int type);
541 int connection_connect(connection_t *conn, char *address, uint32_t addr, uint16_t port);
542 int retry_all_connections(uint16_t or_listenport, uint16_t ap_listenport, uint16_t dir_listenport);
544 int connection_handle_read(connection_t *conn);
545 int connection_read_to_buf(connection_t *conn);
547 int connection_fetch_from_buf(char *string, int len, connection_t *conn);
548 int connection_find_on_inbuf(char *string, int len, connection_t *conn);
550 int connection_wants_to_flush(connection_t *conn);
551 int connection_outbuf_too_full(connection_t *conn);
552 int connection_flush_buf(connection_t *conn);
553 int connection_handle_write(connection_t *conn);
554 void connection_write_to_buf(const char *string, int len, connection_t *conn);
556 connection_t *connection_twin_get_by_addr_port(uint32_t addr, uint16_t port);
557 connection_t *connection_exact_get_by_addr_port(uint32_t addr, uint16_t port);
559 connection_t *connection_get_by_type(int type);
560 connection_t *connection_get_by_type_state(int type, int state);
561 connection_t *connection_get_by_type_state_lastwritten(int type, int state);
563 int connection_receiver_bucket_should_increase(connection_t *conn);
565 #define connection_speaks_cells(conn) ((conn)->type == CONN_TYPE_OR)
566 #define connection_has_pending_tls_data(conn) \
567 ((conn)->type == CONN_TYPE_OR && \
568 (conn)->state == OR_CONN_STATE_OPEN && \
569 tor_tls_get_pending_bytes(conn->tls))
570 int connection_is_listener(connection_t *conn);
571 int connection_state_is_open(connection_t *conn);
573 int connection_send_destroy(aci_t aci, connection_t *conn);
575 int connection_process_inbuf(connection_t *conn);
576 int connection_finished_flushing(connection_t *conn);
578 void assert_connection_ok(connection_t *conn, time_t now);
580 /********************************* connection_edge.c ***************************/
582 int connection_edge_process_inbuf(connection_t *conn);
583 void connection_edge_send_command(connection_t *fromconn, circuit_t *circ, int relay_command,
584 void *payload, int payload_len, crypt_path_t *cpath_layer);
586 int connection_edge_process_relay_cell(cell_t *cell, circuit_t *circ, connection_t *conn,
587 int edge_type, crypt_path_t *layer_hint);
588 int connection_edge_finished_flushing(connection_t *conn);
590 int connection_edge_package_raw_inbuf(connection_t *conn);
592 int connection_exit_connect(connection_t *conn);
594 extern uint64_t stats_n_data_cells_packaged;
595 extern uint64_t stats_n_data_bytes_packaged;
596 extern uint64_t stats_n_data_cells_received;
597 extern uint64_t stats_n_data_bytes_received;
599 /********************************* connection_or.c ***************************/
601 int connection_or_process_inbuf(connection_t *conn);
602 int connection_or_finished_flushing(connection_t *conn);
604 void connection_or_init_conn_from_router(connection_t *conn, routerinfo_t *router);
605 connection_t *connection_or_connect(routerinfo_t *router);
607 int connection_tls_start_handshake(connection_t *conn, int receiving);
608 int connection_tls_continue_handshake(connection_t *conn);
610 void connection_or_write_cell_to_buf(const cell_t *cellp, connection_t *conn);
612 /********************************* cpuworker.c *****************************/
614 void cpu_init(void);
615 int connection_cpu_finished_flushing(connection_t *conn);
616 int connection_cpu_process_inbuf(connection_t *conn);
617 int cpuworker_main(void *data);
618 int assign_to_cpuworker(connection_t *cpuworker, unsigned char question_type,
619 void *task);
621 /********************************* directory.c ***************************/
623 void directory_initiate_command(routerinfo_t *router, int command);
624 int connection_dir_process_inbuf(connection_t *conn);
625 int connection_dir_finished_flushing(connection_t *conn);
627 /********************************* dns.c ***************************/
629 void dns_init(void);
630 int connection_dns_finished_flushing(connection_t *conn);
631 int connection_dns_process_inbuf(connection_t *conn);
632 void dns_cancel_pending_resolve(char *question, connection_t *onlyconn);
633 int dns_resolve(connection_t *exitconn);
635 /********************************* main.c ***************************/
637 void set_onion_key(crypto_pk_env_t *k);
638 crypto_pk_env_t *get_onion_key(void);
639 void set_identity_key(crypto_pk_env_t *k);
640 crypto_pk_env_t *get_identity_key(void);
641 crypto_pk_env_t *get_link_key(void);
642 int connection_add(connection_t *conn);
643 int connection_remove(connection_t *conn);
644 void connection_set_poll_socket(connection_t *conn);
646 void get_connection_array(connection_t ***array, int *n);
648 void connection_watch_events(connection_t *conn, short events);
649 int connection_is_reading(connection_t *conn);
650 void connection_stop_reading(connection_t *conn);
651 void connection_start_reading(connection_t *conn);
652 void connection_stop_writing(connection_t *conn);
653 void connection_start_writing(connection_t *conn);
655 const char *router_get_my_descriptor(void);
657 int main(int argc, char *argv[]);
659 /********************************* onion.c ***************************/
661 int decide_aci_type(char *local_nick, char *remote_nick);
663 int onion_pending_add(circuit_t *circ);
664 circuit_t *onion_next_task(void);
665 void onion_pending_remove(circuit_t *circ);
667 int onionskin_answer(circuit_t *circ, unsigned char *payload, unsigned char *keys);
669 crypt_path_t *onion_generate_cpath(routerinfo_t **firsthop);
671 int onion_skin_create(crypto_pk_env_t *router_key,
672 crypto_dh_env_t **handshake_state_out,
673 char *onion_skin_out); /* Must be DH_ONIONSKIN_LEN bytes long */
675 int onion_skin_server_handshake(char *onion_skin, /* DH_ONIONSKIN_LEN bytes long */
676 crypto_pk_env_t *private_key,
677 char *handshake_reply_out, /* DH_KEY_LEN bytes long */
678 char *key_out,
679 int key_out_len);
681 int onion_skin_client_handshake(crypto_dh_env_t *handshake_state,
682 char *handshake_reply,/* Must be DH_KEY_LEN bytes long*/
683 char *key_out,
684 int key_out_len);
686 /********************************* routers.c ***************************/
688 int learn_my_address(struct sockaddr_in *me);
689 void router_retry_connections(void);
690 routerinfo_t *router_pick_directory_server(void);
691 void router_upload_desc_to_dirservers(void);
692 routerinfo_t *router_get_by_addr_port(uint32_t addr, uint16_t port);
693 routerinfo_t *router_get_by_link_pk(crypto_pk_env_t *pk);
694 routerinfo_t *router_get_by_nickname(char *nickname);
695 void router_get_directory(directory_t **pdirectory);
696 int router_is_me(uint32_t addr, uint16_t port);
697 void router_mark_as_down(char *nickname);
698 int router_get_list_from_file(char *routerfile);
699 int router_get_router_hash(char *s, char *digest);
700 int router_get_dir_hash(char *s, char *digest);
702 /* Reads a list of known routers, unsigned. */
703 int router_get_list_from_string(char *s);
704 /* Exported for debugging */
705 int router_get_list_from_string_impl(char **s, directory_t **dest, int n_good_nicknames, const char *good_nickname_lst[]);
706 /* Reads a signed directory. */
707 int router_get_dir_from_string(char *s, crypto_pk_env_t *pkey);
708 /* Exported or debugging */
709 int router_get_dir_from_string_impl(char *s, directory_t **dest,
710 crypto_pk_env_t *pkey);
711 routerinfo_t *router_get_entry_from_string(char **s);
712 int router_compare_to_exit_policy(connection_t *conn);
713 void routerinfo_free(routerinfo_t *router);
714 int router_dump_router_to_string(char *s, int maxlen, routerinfo_t *router,
715 crypto_pk_env_t *ident_key);
716 const routerinfo_t *router_get_desc_routerinfo(void);
717 const char *router_get_my_descriptor(void);
718 int router_rebuild_descriptor(void);
720 /********************************* dirserv.c ***************************/
721 int dirserv_add_own_fingerprint(const char *nickname, crypto_pk_env_t *pk);
722 int dirserv_parse_fingerprint_file(const char *fname);
723 int dirserv_router_fingerprint_is_known(const routerinfo_t *router);
724 void dirserv_free_fingerprint_list();
725 int dirserv_add_descriptor(const char **desc);
726 int dirserv_init_from_directory_string(const char *dir);
727 void dirserv_free_descriptors();
728 int dirserv_dump_directory_to_string(char *s, int maxlen,
729 crypto_pk_env_t *private_key);
730 void directory_set_dirty();
731 size_t dirserv_get_directory(const char **cp);
734 #endif
737 Local Variables:
738 mode:c
739 indent-tabs-mode:nil
740 c-basic-offset:2
741 End: