tor  0.4.2.1-alpha-dev
Data Structures | Macros | Functions
connection.h File Reference

Go to the source code of this file.

Data Structures

struct  listener_replacement_t
 

Macros

#define CONN_TYPE_MIN_   3
 
#define CONN_TYPE_OR_LISTENER   3
 
#define CONN_TYPE_OR   4
 
#define CONN_TYPE_EXIT   5
 
#define CONN_TYPE_AP_LISTENER   6
 
#define CONN_TYPE_AP   7
 
#define CONN_TYPE_DIR_LISTENER   8
 
#define CONN_TYPE_DIR   9
 
#define CONN_TYPE_CONTROL_LISTENER   11
 
#define CONN_TYPE_CONTROL   12
 
#define CONN_TYPE_AP_TRANS_LISTENER   13
 
#define CONN_TYPE_AP_NATD_LISTENER   14
 
#define CONN_TYPE_AP_DNS_LISTENER   15
 
#define CONN_TYPE_EXT_OR   16
 
#define CONN_TYPE_EXT_OR_LISTENER   17
 
#define CONN_TYPE_AP_HTTP_CONNECT_LISTENER   18
 
#define CONN_TYPE_MAX_   19
 
#define PROXY_INFANT   1
 
#define PROXY_HTTPS_WANT_CONNECT_OK   2
 
#define PROXY_SOCKS4_WANT_CONNECT_OK   3
 
#define PROXY_SOCKS5_WANT_AUTH_METHOD_NONE   4
 
#define PROXY_SOCKS5_WANT_AUTH_METHOD_RFC1929   5
 
#define PROXY_SOCKS5_WANT_AUTH_RFC1929_OK   6
 
#define PROXY_SOCKS5_WANT_CONNECT_OK   7
 
#define PROXY_CONNECTED   8
 
#define LISTENER_STATE_READY   0
 
#define connection_free(conn)   FREE_AND_NULL(connection_t, connection_free_, (conn))
 
#define connection_mark_for_close(c)   connection_mark_for_close_((c), __LINE__, SHORT_FILE__)
 
#define connection_mark_for_close_internal(c)   connection_mark_for_close_internal_((c), __LINE__, SHORT_FILE__)
 
#define connection_mark_and_flush_internal_(c, line, file)
 
#define connection_mark_and_flush_internal(c)   connection_mark_and_flush_internal_((c), __LINE__, SHORT_FILE__)
 
#define connection_mark_and_flush_(c, line, file)
 
#define connection_mark_and_flush(c)   connection_mark_and_flush_((c), __LINE__, SHORT_FILE__)
 
#define MAX_SOCKS5_AUTH_FIELD_SIZE   255
 
#define MAX_SOCKS5_AUTH_SIZE_TOTAL   2*MAX_SOCKS5_AUTH_FIELD_SIZE
 
#define CONN_LEN_AND_FREE_TEMPLATE(sl)
 
#define connection_speaks_cells(conn)   (((conn)->type == CONN_TYPE_OR) || 0)
 
#define CONN_LOG_PROTECT(conn, stmt)
 

Functions

listener_connection_tTO_LISTENER_CONN (connection_t *)
 
const char * conn_type_to_string (int type)
 
const char * conn_state_to_string (int type, int state)
 
int conn_listener_type_supports_af_unix (int type)
 
dir_connection_tdir_connection_new (int socket_family)
 
or_connection_tor_connection_new (int type, int socket_family)
 
edge_connection_tedge_connection_new (int type, int socket_family)
 
entry_connection_tentry_connection_new (int type, int socket_family)
 
control_connection_tcontrol_connection_new (int socket_family)
 
listener_connection_tlistener_connection_new (int type, int socket_family)
 
connection_tconnection_new (int type, int socket_family)
 
int connection_init_accepted_conn (connection_t *conn, const listener_connection_t *listener)
 
void connection_link_connections (connection_t *conn_a, connection_t *conn_b)
 
 MOCK_DECL (void, connection_free_,(connection_t *conn))
 
void connection_free_all (void)
 
void connection_about_to_close_connection (connection_t *conn)
 
void connection_close_immediate (connection_t *conn)
 
void connection_mark_for_close_ (connection_t *conn, int line, const char *file)
 
 MOCK_DECL (void, connection_mark_for_close_internal_,(connection_t *conn, int line, const char *file))
 
void connection_expire_held_open (void)
 
int connection_connect (connection_t *conn, const char *address, const tor_addr_t *addr, uint16_t port, int *socket_error)
 
int connection_proxy_connect (connection_t *conn, int type)
 
int connection_read_proxy_handshake (connection_t *conn)
 
void log_failed_proxy_connection (connection_t *conn)
 
int get_proxy_addrport (tor_addr_t *addr, uint16_t *port, int *proxy_type, int *is_pt_out, const connection_t *conn)
 
int retry_all_listeners (smartlist_t *new_conns, int close_all_noncontrol)
 
void connection_mark_all_noncontrol_listeners (void)
 
void connection_mark_all_noncontrol_connections (void)
 
ssize_t connection_bucket_write_limit (connection_t *conn, time_t now)
 
int global_write_bucket_low (connection_t *conn, size_t attempt, int priority)
 
void connection_bucket_init (void)
 
void connection_bucket_adjust (const or_options_t *options)
 
void connection_bucket_refill_all (time_t now, uint32_t now_ts)
 
void connection_read_bw_exhausted (connection_t *conn, bool is_global_bw)
 
void connection_write_bw_exhausted (connection_t *conn, bool is_global_bw)
 
void connection_consider_empty_read_buckets (connection_t *conn)
 
void connection_consider_empty_write_buckets (connection_t *conn)
 
int connection_handle_read (connection_t *conn)
 
int connection_buf_get_bytes (char *string, size_t len, connection_t *conn)
 
int connection_buf_get_line (connection_t *conn, char *data, size_t *data_len)
 
int connection_fetch_from_buf_http (connection_t *conn, char **headers_out, size_t max_headerlen, char **body_out, size_t *body_used, size_t max_bodylen, int force_complete)
 
int connection_wants_to_flush (connection_t *conn)
 
int connection_outbuf_too_full (connection_t *conn)
 
int connection_handle_write (connection_t *conn, int force)
 
int connection_flush (connection_t *conn)
 
 MOCK_DECL (void, connection_write_to_buf_impl_,(const char *string, size_t len, connection_t *conn, int zlib))
 
static void connection_buf_add (const char *string, size_t len, connection_t *conn)
 
void connection_dir_buf_add (const char *string, size_t len, dir_connection_t *dir_conn, int done)
 
void connection_buf_add_compress (const char *string, size_t len, dir_connection_t *conn, int done)
 
void connection_buf_add_buf (connection_t *conn, struct buf_t *buf)
 
size_t connection_get_inbuf_len (connection_t *conn)
 
size_t connection_get_outbuf_len (connection_t *conn)
 
connection_tconnection_get_by_global_id (uint64_t id)
 
connection_tconnection_get_by_type (int type)
 
 MOCK_DECL (connection_t *, connection_get_by_type_nonlinked,(int type))
 
 MOCK_DECL (connection_t *, connection_get_by_type_addr_port_purpose,(int type, const tor_addr_t *addr, uint16_t port, int purpose))
 
connection_tconnection_get_by_type_state (int type, int state)
 
connection_tconnection_get_by_type_state_rendquery (int type, int state, const char *rendquery)
 
smartlist_tconnection_list_by_type_state (int type, int state)
 
smartlist_tconnection_list_by_type_purpose (int type, int purpose)
 
smartlist_tconnection_dir_list_by_purpose_and_resource (int purpose, const char *resource)
 
smartlist_tconnection_dir_list_by_purpose_resource_and_state (int purpose, const char *resource, int state)
 
static int connection_dir_count_by_purpose_and_resource (int purpose, const char *resource)
 
static int connection_dir_count_by_purpose_resource_and_state (int purpose, const char *resource, int state)
 
int any_other_active_or_conns (const or_connection_t *this_conn)
 
int connection_is_listener (connection_t *conn)
 
int connection_state_is_open (connection_t *conn)
 
int connection_state_is_connecting (connection_t *conn)
 
char * alloc_http_authenticator (const char *authenticator)
 
void assert_connection_ok (connection_t *conn, time_t now)
 
int connection_or_nonopen_was_started_here (or_connection_t *conn)
 
void connection_dump_buffer_mem_stats (int severity)
 
 MOCK_DECL (void, clock_skew_warning,(const connection_t *conn, long apparent_skew, int trusted, log_domain_mask_t domain, const char *received, const char *source))
 
int connection_is_moribund (connection_t *conn)
 
void connection_check_oos (int n_socks, int failed)
 

Detailed Description

Header file for connection.c.

Definition in file connection.h.

Macro Definition Documentation

◆ CONN_LEN_AND_FREE_TEMPLATE

#define CONN_LEN_AND_FREE_TEMPLATE (   sl)
Value:
STMT_BEGIN \
int len = smartlist_len(sl); \
smartlist_free(sl); \
return len; \
STMT_END

Definition at line 262 of file connection.h.

◆ CONN_LOG_PROTECT

#define CONN_LOG_PROTECT (   conn,
  stmt 
)
Value:
STMT_BEGIN \
int _log_conn_is_control; \
tor_assert(conn); \
_log_conn_is_control = (conn->type == CONN_TYPE_CONTROL); \
if (_log_conn_is_control) \
disable_control_logging(); \
STMT_BEGIN stmt; STMT_END; \
if (_log_conn_is_control) \
enable_control_logging(); \
STMT_END
#define CONN_TYPE_CONTROL
Definition: connection.h:40

Execute the statement stmt, which may log events concerning the connection conn. To prevent infinite loops, disable log messages being sent to controllers if conn is a control connection.

Stmt must not contain any return or goto statements.

Definition at line 328 of file connection.h.

◆ CONN_TYPE_AP

#define CONN_TYPE_AP   7

A SOCKS proxy connection from the user application to the onion proxy.

Definition at line 31 of file connection.h.

◆ CONN_TYPE_AP_DNS_LISTENER

#define CONN_TYPE_AP_DNS_LISTENER   15

Type for sockets listening for DNS requests.

Definition at line 48 of file connection.h.

◆ CONN_TYPE_AP_HTTP_CONNECT_LISTENER

#define CONN_TYPE_AP_HTTP_CONNECT_LISTENER   18

Type for sockets listening for HTTP CONNECT tunnel connections.

Definition at line 55 of file connection.h.

◆ CONN_TYPE_AP_LISTENER

#define CONN_TYPE_AP_LISTENER   6

Type for sockets listening for SOCKS connections.

Definition at line 28 of file connection.h.

◆ CONN_TYPE_AP_NATD_LISTENER

#define CONN_TYPE_AP_NATD_LISTENER   14

Type for sockets listening for transparent connections redirected by natd.

Definition at line 46 of file connection.h.

◆ CONN_TYPE_AP_TRANS_LISTENER

#define CONN_TYPE_AP_TRANS_LISTENER   13

Type for sockets listening for transparent connections redirected by pf or netfilter.

Definition at line 43 of file connection.h.

◆ CONN_TYPE_CONTROL

#define CONN_TYPE_CONTROL   12

Type for connections from user interface process.

Definition at line 40 of file connection.h.

◆ CONN_TYPE_CONTROL_LISTENER

#define CONN_TYPE_CONTROL_LISTENER   11

Type for listening for connections from user interface process.

Definition at line 38 of file connection.h.

◆ CONN_TYPE_DIR

#define CONN_TYPE_DIR   9

Type for HTTP connections to the directory server.

Definition at line 35 of file connection.h.

◆ CONN_TYPE_DIR_LISTENER

#define CONN_TYPE_DIR_LISTENER   8

Type for sockets listening for HTTP connections to the directory server.

Definition at line 33 of file connection.h.

◆ CONN_TYPE_EXIT

#define CONN_TYPE_EXIT   5

A TCP connection from an onion router to a stream's destination.

Definition at line 26 of file connection.h.

◆ CONN_TYPE_EXT_OR

#define CONN_TYPE_EXT_OR   16

Type for connections from the Extended ORPort.

Definition at line 51 of file connection.h.

◆ CONN_TYPE_EXT_OR_LISTENER

#define CONN_TYPE_EXT_OR_LISTENER   17

Type for sockets listening for Extended ORPort connections.

Definition at line 53 of file connection.h.

◆ CONN_TYPE_OR

#define CONN_TYPE_OR   4

A bidirectional TLS connection transmitting a sequence of cells. May be from an OR to an OR, or from an OP to an OR.

Definition at line 24 of file connection.h.

◆ CONN_TYPE_OR_LISTENER

#define CONN_TYPE_OR_LISTENER   3

Type for sockets listening for OR connections.

Definition at line 21 of file connection.h.

◆ connection_mark_and_flush_

#define connection_mark_and_flush_ (   c,
  line,
  file 
)
Value:
do { \
connection_t *tmp_conn_ = (c); \
if (tmp_conn_->type == CONN_TYPE_OR) { \
log_warn(LD_CHANNEL | LD_BUG, \
"Something tried to close (and flush) an or_connection_t" \
" without going through channels at %s:%d", \
file, line); \
connection_or_close_for_error(TO_OR_CONN(tmp_conn_), 1); \
} else { \
connection_mark_and_flush_internal_(c, line, file); \
} \
} while (0)
#define CONN_TYPE_OR
Definition: connection.h:24
or_connection_t * TO_OR_CONN(connection_t *c)
#define LD_CHANNEL
Definition: log.h:103
#define LD_BUG
Definition: log.h:84

Mark 'c' for close, but try to hold it open until all the data is written.

Definition at line 148 of file connection.h.

◆ connection_mark_and_flush_internal_

#define connection_mark_and_flush_internal_ (   c,
  line,
  file 
)
Value:
do { \
connection_t *tmp_conn__ = (c); \
connection_mark_for_close_internal_(tmp_conn__, (line), (file)); \
tmp_conn__->hold_open_until_flushed = 1; \
} while (0)

Mark 'c' for close, but try to hold it open until all the data is written. Use the _internal versions of connection_mark_for_close; this should be called when you either are sure that if this is an or_connection_t the controlling channel has been notified (e.g. with connection_or_notify_error()), or you actually are the connection_or_close_for_error() or connection_or_close_normally function. For all other cases, use connection_mark_and_flush() instead, which checks for or_connection_t properly, instead. See below.

Definition at line 135 of file connection.h.

◆ LISTENER_STATE_READY

#define LISTENER_STATE_READY   0

State for any listener connection.

Definition at line 82 of file connection.h.

◆ MAX_SOCKS5_AUTH_FIELD_SIZE

#define MAX_SOCKS5_AUTH_FIELD_SIZE   255

Maximum size of information that we can fit into SOCKS5 username or password fields.

Definition at line 180 of file connection.h.

◆ MAX_SOCKS5_AUTH_SIZE_TOTAL

#define MAX_SOCKS5_AUTH_SIZE_TOTAL   2*MAX_SOCKS5_AUTH_FIELD_SIZE

Total maximum size of information that we can fit into SOCKS5 username and password fields.

Definition at line 184 of file connection.h.

Function Documentation

◆ alloc_http_authenticator()

char* alloc_http_authenticator ( const char *  authenticator)

Allocates a base64'ed authenticator for use in http or https auth, based on the input string authenticator. Returns it if success, else returns NULL.

Definition at line 4685 of file connection.c.

References base64_encode_size().

◆ any_other_active_or_conns()

int any_other_active_or_conns ( const or_connection_t this_conn)

Return 1 if there are any active OR connections apart from this_conn.

We use this to guess if we should tell the controller that we didn't manage to connect to any of our bridges.

Definition at line 4607 of file connection.c.

References connection_get_another_active_or_conn().

◆ assert_connection_ok()

void assert_connection_ok ( connection_t conn,
time_t  now 
)

Verify that connection conn has all of its invariants correct. Trigger an assert if anything is invalid.

Definition at line 5251 of file connection.c.

References tor_assert(), and connection_t::type.

Referenced by add_connection_to_closeable_list(), assert_all_pending_dns_resolves_ok(), connection_close_immediate(), connection_mark_for_close_(), connection_or_finished_flushing(), inform_pending_connections(), and MOCK_IMPL().

◆ conn_listener_type_supports_af_unix()

int conn_listener_type_supports_af_unix ( int  type)

Return true iff the provided connection listener type supports AF_UNIX sockets.

Definition at line 553 of file connection.c.

◆ conn_state_to_string()

const char* conn_state_to_string ( int  type,
int  state 
)

Return the human-readable name for the connection state state for the connection type type

Definition at line 275 of file connection.c.

Referenced by connection_expire_held_open(), connection_or_get_state_description(), and dumpstats().

◆ conn_type_to_string()

const char* conn_type_to_string ( int  type)

Return the human-readable name for the connection type type

Definition at line 243 of file connection.c.

Referenced by connection_expire_held_open(), and dumpstats().

◆ connection_about_to_close_connection()

void connection_about_to_close_connection ( connection_t conn)

Called when we're about to finally unlink and free a connection: perform necessary accounting and cleanup

  • Directory conns that failed to fetch a rendezvous descriptor need to inform pending rendezvous streams.
  • OR conns need to call rep_hist_note_*() to record status.
  • AP conns need to send a socks reject if necessary.
  • Exit conns need to call connection_dns_remove() if necessary.
  • AP and Exit conns need to send an end cell if they can.
  • DNS conns need to fail any resolves that are pending on them.
  • OR and edge connections need to be unlinked from circuits.

Definition at line 813 of file connection.c.

References CONN_TYPE_AP, CONN_TYPE_DIR, CONN_TYPE_EXT_OR, CONN_TYPE_OR, connection_ap_about_to_close(), connection_dir_about_to_close(), connection_or_about_to_close(), connection_t::marked_for_close, TO_DIR_CONN(), TO_OR_CONN(), tor_assert(), and connection_t::type.

Referenced by connection_unlink().

◆ connection_bucket_adjust()

void connection_bucket_adjust ( const or_options_t options)

Update the global connection bucket settings to a new value.

Definition at line 3441 of file connection.c.

References token_bucket_rw_adjust().

◆ connection_bucket_init()

void connection_bucket_init ( void  )

Initialize the global buckets to the values configured in the options

Definition at line 3416 of file connection.c.

References monotime_coarse_get_stamp(), and token_bucket_rw_init().

◆ connection_bucket_write_limit()

ssize_t connection_bucket_write_limit ( connection_t conn,
time_t  now 
)

How many bytes at most can we write onto this connection?

Definition at line 3153 of file connection.c.

References CONN_TYPE_DIR, connection_t::outbuf_flushlen, RELAY_PAYLOAD_SIZE, and connection_t::type.

◆ connection_buf_add_buf()

void connection_buf_add_buf ( connection_t conn,
buf_t *  buf 
)

Add all bytes from buf to conn's outbuf, draining them from buf. (If the connection is marked and will soon be closed, nothing is drained.)

Definition at line 4390 of file connection.c.

References buf_move_all(), connection_may_write_to_buf(), connection_write_to_buf_commit(), connection_t::outbuf, and tor_assert().

◆ connection_buf_get_bytes()

int connection_buf_get_bytes ( char *  string,
size_t  len,
connection_t conn 
)

A pass-through to fetch_from_buf.

Definition at line 3885 of file connection.c.

References buf_get_bytes(), and connection_t::inbuf.

◆ connection_buf_get_line()

int connection_buf_get_line ( connection_t conn,
char *  data,
size_t *  data_len 
)

As buf_get_line(), but read from a connection's input buffer.

Definition at line 3892 of file connection.c.

References buf_get_line(), and connection_t::inbuf.

◆ connection_check_oos()

void connection_check_oos ( int  n_socks,
int  failed 
)

Out-of-Sockets handler; n_socks is the current number of open sockets, and failed is non-zero if a socket exhaustion related error immediately preceded this call. This is where to do circuit-killing heuristics as needed.

Definition at line 5118 of file connection.c.

References tor_assert().

◆ connection_close_immediate()

void connection_close_immediate ( connection_t conn)

Close the underlying socket for conn, so we don't try to flush it. Must be used in conjunction with (right before) connection_mark_for_close().

Definition at line 844 of file connection.c.

References assert_connection_ok(), and CONN_IS_CLOSED.

◆ connection_connect()

int connection_connect ( connection_t conn,
const char *  address,
const tor_addr_t addr,
uint16_t  port,
int *  socket_error 
)

Take conn, make a nonblocking socket; try to connect to addr:port (port arrives in host order). If fail, return -1 and if applicable put your best guess about errno into *socket_error. Else assign s to conn->s: if connected return 1, if EAGAIN return 0.

addr:port can be different to conn->addr:conn->port if connecting through a proxy.

address is used to make the logs useful.

On success, add conn to the list of polled connections.

Definition at line 2179 of file connection.c.

◆ connection_consider_empty_read_buckets()

void connection_consider_empty_read_buckets ( connection_t conn)

If we have exhausted our global buckets, or the buckets for conn, stop reading.

Definition at line 3359 of file connection.c.

References connection_is_rate_limited().

◆ connection_consider_empty_write_buckets()

void connection_consider_empty_write_buckets ( connection_t conn)

If we have exhausted our global buckets, or the buckets for conn, stop writing.

Definition at line 3388 of file connection.c.

References connection_is_rate_limited().

◆ connection_dir_buf_add()

void connection_dir_buf_add ( const char *  string,
size_t  len,
dir_connection_t dir_conn,
int  done 
)

Write a string (of size len to directory connection dir_conn. Apply compression if connection is configured to use it and finalize it if done is true.

Definition at line 4366 of file connection.c.

References dir_connection_t::compress_state.

◆ connection_dir_count_by_purpose_and_resource()

static int connection_dir_count_by_purpose_and_resource ( int  purpose,
const char *  resource 
)
inlinestatic

Return a count of directory connections that are fetching the item described by purpose/resource.

Definition at line 272 of file connection.h.

References connection_dir_list_by_purpose_and_resource().

Referenced by update_consensus_networkstatus_downloads().

◆ connection_dir_count_by_purpose_resource_and_state()

static int connection_dir_count_by_purpose_resource_and_state ( int  purpose,
const char *  resource,
int  state 
)
inlinestatic

Return a count of directory connections that are fetching the item described by purpose/resource/state.

Definition at line 285 of file connection.h.

References connection_dir_list_by_purpose_resource_and_state().

◆ connection_dir_list_by_purpose_and_resource()

smartlist_t* connection_dir_list_by_purpose_and_resource ( int  purpose,
const char *  resource 
)

Return a list of directory connections that are fetching the item described by purpose/resource. If there are none, return an empty list. This list must be freed using smartlist_free, but the pointers in it must not be freed. Note that this list should not be cached, as the pointers in it can be freed if their connections close.

Definition at line 4558 of file connection.c.

References DIR_CONN_LIST_TEMPLATE, and strcmp_opt().

Referenced by connection_dir_count_by_purpose_and_resource().

◆ connection_dir_list_by_purpose_resource_and_state()

smartlist_t* connection_dir_list_by_purpose_resource_and_state ( int  purpose,
const char *  resource,
int  state 
)

Return a list of directory connections that are fetching the item described by purpose/resource/state. If there are none, return an empty list. This list must be freed using smartlist_free, but the pointers in it must not be freed. Note that this list should not be cached, as the pointers in it can be freed if their connections close.

Definition at line 4576 of file connection.c.

References DIR_CONN_LIST_TEMPLATE, and strcmp_opt().

Referenced by connection_dir_count_by_purpose_resource_and_state().

◆ connection_dump_buffer_mem_stats()

void connection_dump_buffer_mem_stats ( int  severity)

Log how many bytes are used by buffers of different kinds and sizes.

Definition at line 5202 of file connection.c.

Referenced by dumpmemusage().

◆ connection_expire_held_open()

void connection_expire_held_open ( void  )

Find each connection that has hold_open_until_flushed set to 1 but hasn't written in the past 15 seconds, and set hold_open_until_flushed to 0. This means it will get cleaned up in the next loop through close_if_marked() in main.c.

Definition at line 955 of file connection.c.

References conn_state_to_string(), CONN_TYPE_DIR, CONN_TYPE_EXIT, conn_type_to_string(), DIR_PURPOSE_SERVER, connection_t::hold_open_until_flushed, LD_NET, log_fn, LOG_INFO, LOG_NOTICE, connection_t::marked_for_close, connection_t::purpose, connection_t::s, SMARTLIST_FOREACH_BEGIN, connection_t::state, connection_t::timestamp_last_write_allowed, tor_assert(), and connection_t::type.

Referenced by second_elapsed_callback().

◆ connection_fetch_from_buf_http()

int connection_fetch_from_buf_http ( connection_t conn,
char **  headers_out,
size_t  max_headerlen,
char **  body_out,
size_t *  body_used,
size_t  max_bodylen,
int  force_complete 
)

As fetch_from_buf_http, but fetches from a connection's input buffer_t as appropriate.

Definition at line 3901 of file connection.c.

References connection_t::inbuf.

Referenced by directory_handle_command().

◆ connection_flush()

int connection_flush ( connection_t conn)

Try to flush data that's waiting for a write on conn. Return -1 on failure, 0 on success.

Don't use this function for regular writing; the buffers system should be good enough at scheduling writes there. Instead, this function is for cases when we're about to exit or something and we want to report it right away.

Definition at line 4252 of file connection.c.

◆ connection_free_all()

void connection_free_all ( void  )

Call connection_free_minimal() on every connection in our array, and release all storage held by connection.c.

Don't do the checks in connection_free(), because they will fail.

Definition at line 5499 of file connection.c.

References clear_broken_connection_map(), CONN_TYPE_CONTROL, connection_free_minimal(), connection_or_clear_ext_or_id_map(), connection_or_clear_identity_map(), control_update_global_event_mask(), outgoing_addrs, SMARTLIST_FOREACH, TO_CONTROL_CONN(), and tor_free.

◆ connection_get_by_global_id()

connection_t* connection_get_by_global_id ( uint64_t  id)

Return the stream with id id if it is not already marked for close.

Definition at line 4469 of file connection.c.

References CONN_GET_TEMPLATE.

Referenced by get_stream().

◆ connection_get_by_type()

connection_t* connection_get_by_type ( int  type)

Return a connection of type type that is not marked for close.

Definition at line 4477 of file connection.c.

◆ connection_get_by_type_state()

connection_t* connection_get_by_type_state ( int  type,
int  state 
)

Return a connection of type type that is in state state, and that is not marked for close.

Definition at line 4486 of file connection.c.

Referenced by directory_all_unreachable_cb().

◆ connection_get_by_type_state_rendquery()

connection_t* connection_get_by_type_state_rendquery ( int  type,
int  state,
const char *  rendquery 
)

Return a connection of type type that has rendquery equal to rendquery, and that is not marked for close. If state is non-zero, conn must be of that state too.

Definition at line 4506 of file connection.c.

◆ connection_init_accepted_conn()

int connection_init_accepted_conn ( connection_t conn,
const listener_connection_t listener 
)

Initialize states for newly accepted connection conn.

If conn is an OR, start the TLS handshake.

If conn is a transparent AP, get its original destination and place it in circuit_wait.

The listener parameter is only used for AP connections.

Definition at line 1869 of file connection.c.

References CONN_TYPE_EXT_OR, CONN_TYPE_OR, connection_ext_or_start_auth(), connection_or_event_status(), TO_OR_CONN(), and connection_t::type.

◆ connection_is_listener()

int connection_is_listener ( connection_t conn)

◆ connection_is_moribund()

int connection_is_moribund ( connection_t conn)

Check if a connection is on the way out so the OOS handler doesn't try to kill more than it needs.

Definition at line 5101 of file connection.c.

References connection_t::conn_array_index, and connection_t::marked_for_close.

Referenced by MOCK_IMPL().

◆ connection_link_connections()

void connection_link_connections ( connection_t conn_a,
connection_t conn_b 
)

Create a link between conn_a and conn_b.

Definition at line 539 of file connection.c.

References connection_t::linked, connection_t::linked_conn, connection_t::s, SOCKET_OK, and tor_assert().

◆ connection_mark_all_noncontrol_connections()

void connection_mark_all_noncontrol_connections ( void  )

Mark every external connection not used for controllers for close.

Definition at line 3007 of file connection.c.

References CONN_TYPE_AP, CONN_TYPE_CONTROL, CONN_TYPE_CONTROL_LISTENER, connection_t::marked_for_close, SMARTLIST_FOREACH_BEGIN, and connection_t::type.

◆ connection_mark_all_noncontrol_listeners()

void connection_mark_all_noncontrol_listeners ( void  )

Mark every listener of type other than CONTROL_LISTENER to be closed.

Definition at line 2993 of file connection.c.

References CONN_TYPE_CONTROL_LISTENER, connection_is_listener(), connection_t::marked_for_close, SMARTLIST_FOREACH_BEGIN, and connection_t::type.

◆ connection_mark_for_close_()

void connection_mark_for_close_ ( connection_t conn,
int  line,
const char *  file 
)

Mark conn to be closed next time we loop through conn_close_if_marked() in main.c.

Definition at line 878 of file connection.c.

References assert_connection_ok(), CONN_TYPE_OR, tor_assert(), and connection_t::type.

Referenced by MOCK_IMPL().

◆ connection_new()

connection_t* connection_new ( int  type,
int  socket_family 
)

Allocate, initialize, and return a new connection_t subtype of type to make or receive connections of address family socket_family. The type should be one of the CONN_TYPE_* constants.

Definition at line 450 of file connection.c.

◆ connection_or_nonopen_was_started_here()

int connection_or_nonopen_was_started_here ( or_connection_t conn)

◆ connection_outbuf_too_full()

int connection_outbuf_too_full ( connection_t conn)

Are there too many bytes on edge connection conn's outbuf to send back a relay-level sendme yet? Return 1 if so, 0 if not. Used by connection_edge_consider_sending_sendme().

Definition at line 3923 of file connection.c.

References CELL_PAYLOAD_SIZE, and connection_t::outbuf_flushlen.

◆ connection_proxy_connect()

int connection_proxy_connect ( connection_t conn,
int  type 
)

Write a proxy request of type (socks4, socks5, https) to conn for conn->addr:conn->port, authenticating with the auth details given in the configuration (if available). SOCKS 5 and HTTP CONNECT proxies support authentication.

Returns -1 if conn->addr is incompatible with the proxy protocol, and 0 otherwise.

Use connection_read_proxy_handshake() to complete the handshake.

Definition at line 2334 of file connection.c.

◆ connection_read_bw_exhausted()

void connection_read_bw_exhausted ( connection_t conn,
bool  is_global_bw 
)

Mark conn as needing to stop reading because bandwidth has been exhausted. If is_global_bw, it is closing because global bandwidth limit has been exhausted. Otherwise, it is closing because its own bandwidth limit has been exhausted.

Definition at line 3333 of file connection.c.

References connection_t::read_blocked_on_bw, and reenable_blocked_connection_schedule().

◆ connection_read_proxy_handshake()

int connection_read_proxy_handshake ( connection_t conn)

Call this from connection_*_process_inbuf() to advance the proxy handshake.

No matter what proxy protocol is used, if this function returns 1, the handshake is complete, and the data remaining on inbuf may contain the start of the communication with the requested server.

Returns 0 if the current buffer contains an incomplete response, and -1 on error.

Definition at line 2599 of file connection.c.

Referenced by connection_or_process_inbuf().

◆ connection_state_is_connecting()

int connection_state_is_connecting ( connection_t conn)

◆ connection_state_is_open()

int connection_state_is_open ( connection_t conn)

◆ connection_wants_to_flush()

int connection_wants_to_flush ( connection_t conn)

Return conn->outbuf_flushlen: how many bytes conn wants to flush from its outbuf.

Definition at line 3913 of file connection.c.

References connection_t::outbuf_flushlen.

◆ connection_write_bw_exhausted()

void connection_write_bw_exhausted ( connection_t conn,
bool  is_global_bw 
)

Mark conn as needing to stop reading because write bandwidth has been exhausted. If is_global_bw, it is closing because global bandwidth limit has been exhausted. Otherwise, it is closing because its own bandwidth limit has been exhausted.

Definition at line 3348 of file connection.c.

References reenable_blocked_connection_schedule(), and connection_t::write_blocked_on_bw.

◆ control_connection_new()

control_connection_t* control_connection_new ( int  socket_family)

Allocate and return a new control_connection_t, initialized as by connection_init().

Definition at line 426 of file connection.c.

◆ dir_connection_new()

dir_connection_t* dir_connection_new ( int  socket_family)

Allocate and return a new dir_connection_t, initialized as by connection_init().

Definition at line 360 of file connection.c.

◆ edge_connection_new()

edge_connection_t* edge_connection_new ( int  type,
int  socket_family 
)

Allocate and return a new edge_connection_t, initialized as by connection_init().

Definition at line 415 of file connection.c.

Referenced by connection_exit_begin_resolve().

◆ entry_connection_new()

entry_connection_t* entry_connection_new ( int  type,
int  socket_family 
)

Allocate and return a new entry_connection_t, initialized as by connection_init().

Allocate space to store the socks_request.

Definition at line 396 of file connection.c.

◆ get_proxy_addrport()

int get_proxy_addrport ( tor_addr_t addr,
uint16_t *  port,
int *  proxy_type,
int *  is_pt_out,
const connection_t conn 
)

Fills addr and port with the details of the global proxy server we are using. Store a 1 to the int pointed to by is_put_out if the connection is using a pluggable transport; store 0 otherwise. conn contains the connection we are using the proxy for.

Return 0 on success, -1 on failure.

Definition at line 5405 of file connection.c.

References transport_t::addr, connection_t::addr, or_options_t::ClientTransportPlugin, get_transport_by_bridge_addrport(), or_options_t::HTTPSProxy, or_options_t::HTTPSProxyAddr, or_options_t::HTTPSProxyPort, transport_t::port, connection_t::port, transport_t::socks_version, and tor_addr_copy().

Referenced by log_failed_proxy_connection().

◆ global_write_bucket_low()

int global_write_bucket_low ( connection_t conn,
size_t  attempt,
int  priority 
)

Return 1 if the global write buckets are low enough that we shouldn't send attempt bytes of low-priority directory stuff out to conn. Else return 0.

Priority was 1 for v1 requests (directories and running-routers), and 2 for v2 requests and later (statuses and descriptors).

There are a lot of parameters we could use here:

  • global_relayed_write_bucket. Low is bad.
  • global_write_bucket. Low is bad.
  • bandwidthrate. Low is bad.
  • bandwidthburst. Not a big factor?
  • attempt. High is bad.
  • total bytes queued on outbufs. High is bad. But I'm wary of using this, since a few slow-flushing queues will pump up the number without meaning what we meant to mean. What we really mean is "total directory bytes added to outbufs recently", but that's harder to quantify and harder to keep track of.

Definition at line 3203 of file connection.c.

◆ listener_connection_new()

listener_connection_t* listener_connection_new ( int  type,
int  socket_family 
)

Allocate and return a new listener_connection_t, initialized as by connection_init().

Definition at line 438 of file connection.c.

◆ log_failed_proxy_connection()

void log_failed_proxy_connection ( connection_t conn)

Log a failed connection to a proxy server. conn is the connection we use the proxy server for.

Definition at line 5459 of file connection.c.

References get_proxy_addrport().

◆ or_connection_new()

or_connection_t* or_connection_new ( int  type,
int  socket_family 
)

Allocate and return a new or_connection_t, initialized as by connection_init().

Initialize active_circuit_pqueue.

Set active_circuit_pqueue_last_recalibrated to current cell_ewma tick.

Definition at line 375 of file connection.c.

◆ retry_all_listeners()

int retry_all_listeners ( smartlist_t new_conns,
int  close_all_noncontrol 
)

Launch listeners for each port you should have open. Only launch listeners who are not already open, and only close listeners we no longer want.

Add all new connections to new_conns.

If close_all_noncontrol is true, then we only open control listeners, and we close all other listeners.

Definition at line 2899 of file connection.c.

References connection_is_listener(), connection_t::marked_for_close, router_get_advertised_dir_port(), router_get_advertised_or_port(), router_get_advertised_or_port_by_af(), smartlist_add(), and SMARTLIST_FOREACH_BEGIN.

Referenced by retry_listeners_callback().

◆ TO_LISTENER_CONN()

listener_connection_t* TO_LISTENER_CONN ( connection_t c)

Convert a connection_t* to an listener_connection_t*; assert if the cast is invalid.

Definition at line 221 of file connection.c.

References DOWNCAST, connection_t::magic, and tor_assert().

Referenced by dnsserv_close_listener(), and dnsserv_configure_listener().