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