1 /* Copyright (c) 2001 Matej Pfajfar.
2 * Copyright (c) 2001-2004, Roger Dingledine.
3 * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
4 * Copyright (c) 2007-2010, The Tor Project, Inc. */
5 /* See LICENSE for licensing information */
9 * \brief Header file for connection.c.
12 #ifndef _TOR_CONNECTION_H
13 #define _TOR_CONNECTION_H
15 const char *conn_type_to_string(int type
);
16 const char *conn_state_to_string(int type
, int state
);
18 dir_connection_t
*dir_connection_new(int socket_family
);
19 or_connection_t
*or_connection_new(int socket_family
);
20 edge_connection_t
*edge_connection_new(int type
, int socket_family
);
21 control_connection_t
*control_connection_new(int socket_family
);
22 connection_t
*connection_new(int type
, int socket_family
);
24 void connection_link_connections(connection_t
*conn_a
, connection_t
*conn_b
);
25 void connection_free(connection_t
*conn
);
26 void connection_free_all(void);
27 void connection_about_to_close_connection(connection_t
*conn
);
28 void connection_close_immediate(connection_t
*conn
);
29 void _connection_mark_for_close(connection_t
*conn
,int line
, const char *file
);
31 #define connection_mark_for_close(c) \
32 _connection_mark_for_close((c), __LINE__, _SHORT_FILE_)
34 void connection_expire_held_open(void);
36 int connection_connect(connection_t
*conn
, const char *address
,
37 const tor_addr_t
*addr
,
38 uint16_t port
, int *socket_error
);
40 int connection_proxy_connect(connection_t
*conn
, int type
);
41 int connection_read_proxy_handshake(connection_t
*conn
);
43 int retry_all_listeners(smartlist_t
*replaced_conns
,
44 smartlist_t
*new_conns
);
46 ssize_t
connection_bucket_write_limit(connection_t
*conn
, time_t now
);
47 int global_write_bucket_low(connection_t
*conn
, size_t attempt
, int priority
);
48 void connection_bucket_init(void);
49 void connection_bucket_refill(int seconds_elapsed
, time_t now
);
51 int connection_handle_read(connection_t
*conn
);
53 int connection_fetch_from_buf(char *string
, size_t len
, connection_t
*conn
);
55 int connection_wants_to_flush(connection_t
*conn
);
56 int connection_outbuf_too_full(connection_t
*conn
);
57 int connection_handle_write(connection_t
*conn
, int force
);
58 void _connection_write_to_buf_impl(const char *string
, size_t len
,
59 connection_t
*conn
, int zlib
);
60 static void connection_write_to_buf(const char *string
, size_t len
,
62 static void connection_write_to_buf_zlib(const char *string
, size_t len
,
63 dir_connection_t
*conn
, int done
);
65 connection_write_to_buf(const char *string
, size_t len
, connection_t
*conn
)
67 _connection_write_to_buf_impl(string
, len
, conn
, 0);
70 connection_write_to_buf_zlib(const char *string
, size_t len
,
71 dir_connection_t
*conn
, int done
)
73 _connection_write_to_buf_impl(string
, len
, TO_CONN(conn
), done
? -1 : 1);
76 connection_t
*connection_get_by_global_id(uint64_t id
);
78 connection_t
*connection_get_by_type(int type
);
79 connection_t
*connection_get_by_type_purpose(int type
, int purpose
);
80 connection_t
*connection_get_by_type_addr_port_purpose(int type
,
81 const tor_addr_t
*addr
,
82 uint16_t port
, int purpose
);
83 connection_t
*connection_get_by_type_state(int type
, int state
);
84 connection_t
*connection_get_by_type_state_rendquery(int type
, int state
,
85 const char *rendquery
);
87 #define connection_speaks_cells(conn) ((conn)->type == CONN_TYPE_OR)
88 int connection_is_listener(connection_t
*conn
);
89 int connection_state_is_open(connection_t
*conn
);
90 int connection_state_is_connecting(connection_t
*conn
);
92 char *alloc_http_authenticator(const char *authenticator
);
94 void assert_connection_ok(connection_t
*conn
, time_t now
);
95 int connection_or_nonopen_was_started_here(or_connection_t
*conn
);
96 void connection_dump_buffer_mem_stats(int severity
);
97 void remove_file_if_very_old(const char *fname
, time_t now
);