12 #ifndef TOR_CONNECTION_H
13 #define TOR_CONNECTION_H
18 #ifdef HAVE_SYS_SOCKET_H
19 #include <sys/socket.h>
39 #define CONN_TYPE_MIN_ 3
41 #define CONN_TYPE_OR_LISTENER 3
44 #define CONN_TYPE_OR 4
46 #define CONN_TYPE_EXIT 5
48 #define CONN_TYPE_AP_LISTENER 6
51 #define CONN_TYPE_AP 7
53 #define CONN_TYPE_DIR_LISTENER 8
55 #define CONN_TYPE_DIR 9
58 #define CONN_TYPE_CONTROL_LISTENER 11
60 #define CONN_TYPE_CONTROL 12
63 #define CONN_TYPE_AP_TRANS_LISTENER 13
66 #define CONN_TYPE_AP_NATD_LISTENER 14
68 #define CONN_TYPE_AP_DNS_LISTENER 15
71 #define CONN_TYPE_EXT_OR 16
73 #define CONN_TYPE_EXT_OR_LISTENER 17
75 #define CONN_TYPE_AP_HTTP_CONNECT_LISTENER 18
77 #define CONN_TYPE_METRICS_LISTENER 19
79 #define CONN_TYPE_METRICS 20
81 #define CONN_TYPE_MAX_ 21
87 #define PROXY_INFANT 1
89 #define PROXY_HTTPS_WANT_CONNECT_OK 2
91 #define PROXY_SOCKS4_WANT_CONNECT_OK 3
94 #define PROXY_SOCKS5_WANT_AUTH_METHOD_NONE 4
97 #define PROXY_SOCKS5_WANT_AUTH_METHOD_RFC1929 5
99 #define PROXY_SOCKS5_WANT_AUTH_RFC1929_OK 6
101 #define PROXY_SOCKS5_WANT_CONNECT_OK 7
103 #define PROXY_HAPROXY_WAIT_FOR_FLUSH 8
105 #define PROXY_CONNECTED 9
108 #define LISTENER_STATE_READY 0
141 #define connection_free(conn) \
142 FREE_AND_NULL(struct connection_t, connection_free_, (conn))
147 int line,
const char *file);
149 (
struct connection_t *conn,
int line,
const char *file));
151 #define connection_mark_for_close(c) \
152 connection_mark_for_close_((c), __LINE__, SHORT_FILE__)
153 #define connection_mark_for_close_internal(c) \
154 connection_mark_for_close_internal_((c), __LINE__, SHORT_FILE__)
166 #define connection_mark_and_flush_internal_(c,line,file) \
168 struct connection_t *tmp_conn__ = (c); \
169 connection_mark_for_close_internal_(tmp_conn__, (line), (file)); \
170 tmp_conn__->hold_open_until_flushed = 1; \
173 #define connection_mark_and_flush_internal(c) \
174 connection_mark_and_flush_internal_((c), __LINE__, SHORT_FILE__)
179 #define connection_mark_and_flush_(c,line,file) \
181 struct connection_t *tmp_conn_ = (c); \
182 if (tmp_conn_->type == CONN_TYPE_OR) { \
183 log_warn(LD_CHANNEL | LD_BUG, \
184 "Something tried to close (and flush) an or_connection_t" \
185 " without going through channels at %s:%d", \
187 connection_or_close_for_error(TO_OR_CONN(tmp_conn_), 1); \
189 connection_mark_and_flush_internal_(c, line, file); \
193 #define connection_mark_and_flush(c) \
194 connection_mark_and_flush_((c), __LINE__, SHORT_FILE__)
200 uint16_t
port,
int *socket_error);
204 int connection_connect_unix(
struct connection_t *conn,
const char *socket_path,
211 #define MAX_SOCKS5_AUTH_FIELD_SIZE 255
215 #define MAX_SOCKS5_AUTH_SIZE_TOTAL 2*MAX_SOCKS5_AUTH_FIELD_SIZE
225 int close_all_noncontrol);
235 void connection_bucket_refill_all(time_t now,
251 char **headers_out,
size_t max_headerlen,
252 char **body_out,
size_t *body_used,
253 size_t max_bodylen,
int force_complete);
257 int connection_handle_write(
struct connection_t *conn,
int force);
261 (
const char *
string,
size_t len,
struct connection_t *conn,
264 static void connection_buf_add(
const char *
string,
size_t len,
269 connection_buf_add(
const char *
string,
size_t len,
struct connection_t *conn)
273 void connection_buf_add_compress(
const char *
string,
size_t len,
277 size_t connection_get_inbuf_len(
struct connection_t *conn);
278 size_t connection_get_outbuf_len(
struct connection_t *conn);
288 struct connection_t *connection_get_by_type_state_rendquery(
290 const char *rendquery);
291 struct smartlist_t *connection_list_by_type_state(
int type,
int state);
292 struct smartlist_t *connection_list_by_type_purpose(
int type,
int purpose);
295 const char *resource);
298 const char *resource,
301 #define CONN_LEN_AND_FREE_TEMPLATE(sl) \
303 int len = smartlist_len(sl); \
304 smartlist_free(sl); \
313 const char *resource)
318 CONN_LEN_AND_FREE_TEMPLATE(conns);
326 const char *resource,
334 CONN_LEN_AND_FREE_TEMPLATE(conns);
337 #undef CONN_LEN_AND_FREE_TEMPLATE
342 #define connection_speaks_cells(conn) (((conn)->type == CONN_TYPE_OR) || 0)
354 (
const struct connection_t *conn,
long apparent_skew,
int trusted,
356 const char *source));
367 #define CONN_LOG_PROTECT(conn, stmt) \
369 int _log_conn_is_control; \
371 _log_conn_is_control = (conn->type == CONN_TYPE_CONTROL); \
372 if (_log_conn_is_control) \
373 disable_control_logging(); \
374 STMT_BEGIN stmt; STMT_END; \
375 if (_log_conn_is_control) \
376 enable_control_logging(); \
379 #ifdef CONNECTION_PRIVATE
385 const struct sockaddr *sa,
387 const struct sockaddr *bindaddr,
388 socklen_t bindaddr_len,
connection_t * connection_get_by_type_addr_port_purpose(int type, const tor_addr_t *addr, uint16_t port, int purpose)
const listener_connection_t * CONST_TO_LISTENER_CONN(const connection_t *c)
void clock_skew_warning(const connection_t *conn, long apparent_skew, int trusted, log_domain_mask_t domain, const char *received, const char *source)
bool connection_dir_is_global_write_low(const connection_t *conn, size_t attempt)
int get_proxy_addrport(tor_addr_t *addr, uint16_t *port, int *proxy_type, int *is_pt_out, const connection_t *conn)
STATIC void connection_free_minimal(connection_t *conn)
void connection_bucket_adjust(const or_options_t *options)
int any_other_active_or_conns(const or_connection_t *this_conn)
int connection_init_accepted_conn(connection_t *conn, const listener_connection_t *listener)
STATIC int connection_connect_sockaddr(connection_t *conn, const struct sockaddr *sa, socklen_t sa_len, const struct sockaddr *bindaddr, socklen_t bindaddr_len, int *socket_error)
STATIC smartlist_t * pick_oos_victims(int n)
STATIC void kill_conn_list_for_oos(smartlist_t *conns)
int connection_connect(connection_t *conn, const char *address, const tor_addr_t *addr, uint16_t port, int *socket_error)
void connection_mark_all_noncontrol_listeners(void)
struct smartlist_t * connection_dir_list_by_purpose_and_resource(int purpose, const char *resource)
const char * conn_state_to_string(int type, int state)
void connection_dir_buf_add(const char *string, size_t len, struct dir_connection_t *dir_conn, int done)
struct connection_t * connection_get_by_type(int type)
void connection_mark_for_close_internal_(struct connection_t *conn, int line, const char *file)
struct listener_connection_t * listener_connection_new(int type, int socket_family)
void assert_connection_ok(struct connection_t *conn, time_t now)
int connection_is_listener(struct connection_t *conn)
void connection_close_immediate(struct connection_t *conn)
struct edge_connection_t * edge_connection_new(int type, int socket_family)
struct connection_t * connection_get_by_type_state(int type, int state)
struct entry_connection_t * entry_connection_new(int type, int socket_family)
void connection_write_to_buf_impl_(const char *string, size_t len, struct connection_t *conn, int zlib)
struct connection_t * connection_new(int type, int socket_family)
void log_failed_proxy_connection(struct connection_t *conn)
void connection_consider_empty_write_buckets(struct connection_t *conn)
static int connection_dir_count_by_purpose_and_resource(int purpose, const char *resource)
void connection_dump_buffer_mem_stats(int severity)
int connection_wants_to_flush(struct connection_t *conn)
void connection_bucket_init(void)
int connection_flush(struct connection_t *conn)
void connection_free_(struct connection_t *conn)
int connection_buf_get_line(struct connection_t *conn, char *data, size_t *data_len)
struct smartlist_t * connection_dir_list_by_purpose_resource_and_state(int purpose, const char *resource, int state)
const char * connection_describe(const connection_t *conn)
int connection_fetch_from_buf_http(struct connection_t *conn, char **headers_out, size_t max_headerlen, char **body_out, size_t *body_used, size_t max_bodylen, int force_complete)
void connection_link_connections(struct connection_t *conn_a, struct connection_t *conn_b)
int connection_or_nonopen_was_started_here(struct or_connection_t *conn)
int connection_buf_get_bytes(char *string, size_t len, struct connection_t *conn)
int connection_read_proxy_handshake(struct connection_t *conn)
void connection_write_bw_exhausted(struct connection_t *conn, bool is_global_bw)
const char * connection_describe_peer(const connection_t *conn)
void connection_about_to_close_connection(struct connection_t *conn)
struct listener_connection_t * TO_LISTENER_CONN(struct connection_t *)
const char * conn_type_to_string(int type)
int conn_listener_type_supports_af_unix(int type)
void connection_free_all(void)
void connection_consider_empty_read_buckets(struct connection_t *conn)
void connection_mark_for_close_(struct connection_t *conn, int line, const char *file)
char * alloc_http_authenticator(const char *authenticator)
ssize_t connection_bucket_write_limit(struct connection_t *conn, time_t now)
int connection_is_moribund(struct connection_t *conn)
void connection_read_bw_exhausted(struct connection_t *conn, bool is_global_bw)
int retry_all_listeners(struct smartlist_t *new_conns, int close_all_noncontrol)
int connection_state_is_open(struct connection_t *conn)
int connection_state_is_connecting(struct connection_t *conn)
void connection_buf_add_buf(struct connection_t *conn, struct buf_t *buf)
struct connection_t * connection_get_by_type_nonlinked(int type)
int connection_proxy_connect(struct connection_t *conn, int type)
int connection_outbuf_too_full(struct connection_t *conn)
void connection_mark_all_noncontrol_connections(void)
static int connection_dir_count_by_purpose_resource_and_state(int purpose, const char *resource, int state)
struct dir_connection_t * dir_connection_new(int socket_family)
struct or_connection_t * or_connection_new(int type, int socket_family)
struct connection_t * connection_get_by_global_id(uint64_t id)
void connection_expire_held_open(void)
void connection_check_oos(int n_socks, int failed)
struct control_connection_t * control_connection_new(int socket_family)
uint64_t log_domain_mask_t
Top-level declarations for the smartlist_t dynamic array type.
#define MOCK_DECL(rv, funcname, arglist)