tor  master
Macros | Functions
connection.c File Reference

General high-level functions to handle reading and writing on connections. More...

#include "or.h"
#include "bridges.h"
#include "buffers.h"
#include "buffers_tls.h"
#include "backtrace.h"
#include "channel.h"
#include "channeltls.h"
#include "circuitbuild.h"
#include "circuitlist.h"
#include "circuituse.h"
#include "config.h"
#include "connection.h"
#include "connection_edge.h"
#include "connection_or.h"
#include "control.h"
#include "crypto_util.h"
#include "directory.h"
#include "dirserv.h"
#include "dns.h"
#include "dnsserv.h"
#include "dos.h"
#include "entrynodes.h"
#include "ext_orport.h"
#include "geoip.h"
#include "main.h"
#include "hibernate.h"
#include "hs_common.h"
#include "hs_ident.h"
#include "nodelist.h"
#include "proto_http.h"
#include "proto_socks.h"
#include "policies.h"
#include "reasons.h"
#include "relay.h"
#include "rendclient.h"
#include "rendcommon.h"
#include "rephist.h"
#include "router.h"
#include "routerlist.h"
#include "transports.h"
#include "routerparse.h"
#include "sandbox.h"
Include dependency graph for connection.c:

Macros

#define CONNECTION_PRIVATE
 
#define TOR_CHANNEL_INTERNAL_
 
#define CONNECTION_PRIVATE
 
#define CASE_ANY_LISTENER_TYPE
 
#define CONN_IS_CLOSED(c)   ((c)->linked ? ((c)->linked_conn_is_closed) : (! SOCKET_OK(c->s)))
 
#define WARN_TOO_MANY_CONNS_INTERVAL   (6*60*60)
 
#define SOCKS4_STANDARD_BUFFER_SIZE   (1 + 1 + 2 + 4 + 1)
 
#define CLIENT_IDLE_TIME_FOR_PRIORITY   30
 
#define CONN_GET_ALL_TEMPLATE(var, test)
 
#define CONN_GET_TEMPLATE(var, test)
 
#define DIR_CONN_LIST_TEMPLATE(conn_var, conn_test, dirconn_var, dirconn_test)
 

Functions

const tor_addr_tconn_get_outbound_address (sa_family_t family, const or_options_t *options, unsigned int conn_type)
 
const char * conn_type_to_string (int type)
 
const char * conn_state_to_string (int type, int state)
 
dir_connection_tdir_connection_new (int socket_family)
 
or_connection_tor_connection_new (int type, int socket_family)
 
entry_connection_tentry_connection_new (int type, int socket_family)
 
edge_connection_tedge_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)
 
void connection_link_connections (connection_t *conn_a, connection_t *conn_b)
 
int conn_listener_type_supports_af_unix (int type)
 
STATIC void connection_free_minimal (connection_t *conn)
 
 MOCK_IMPL (void, connection_free_,(connection_t *conn))
 
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_IMPL (void, connection_mark_for_close_internal_,(connection_t *conn, int line, const char *file))
 
void connection_expire_held_open (void)
 
int connection_init_accepted_conn (connection_t *conn, const listener_connection_t *listener)
 
 MOCK_IMPL (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))
 
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)
 
int retry_all_listeners (smartlist_t *replaced_conns, 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_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)
 
void connection_bucket_init (void)
 
void connection_bucket_adjust (const or_options_t *options)
 
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_IMPL (void, connection_write_to_buf_impl_,(const char *string, size_t len, connection_t *conn, int zlib))
 
void connection_buf_add_buf (connection_t *conn, buf_t *buf)
 
smartlist_tconnection_list_by_type_state (int type, int state)
 
smartlist_tconnection_list_by_type_purpose (int type, int purpose)
 
 MOCK_IMPL (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_global_id (uint64_t id)
 
connection_tconnection_get_by_type (int type)
 
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_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)
 
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)
 
 MOCK_IMPL (STATIC smartlist_t *, pick_oos_victims,(int n))
 
 MOCK_IMPL (STATIC void, kill_conn_list_for_oos,(smartlist_t *conns))
 
void connection_check_oos (int n_socks, int failed)
 
void connection_dump_buffer_mem_stats (int severity)
 
void assert_connection_ok (connection_t *conn, time_t now)
 
int get_proxy_addrport (tor_addr_t *addr, uint16_t *port, int *proxy_type, const connection_t *conn)
 
void log_failed_proxy_connection (connection_t *conn)
 
void connection_free_all (void)
 
 MOCK_IMPL (void, clock_skew_warning,(const connection_t *conn, long apparent_skew, int trusted, log_domain_mask_t domain, const char *received, const char *source))
 

Detailed Description

General high-level functions to handle reading and writing on connections.

Each connection (ideally) represents a TLS connection, a TCP socket, a unix socket, or a UDP socket on which reads and writes can occur. (But see connection_edge.c for cases where connections can also represent streams that do not have a corresponding socket.)

The module implements the abstract type, connection_t. The subtypes are:

The base type implemented in this module is responsible for basic rate limiting, flow control, and marshalling bytes onto and off of the network (either directly or via TLS).

Connections are registered with the main loop with connection_add(). As they become able to read or write register the fact with the event main loop by calling connection_watch_events(), connection_start_reading(), or connection_start_writing(). When they no longer want to read or write, they call connection_stop_reading() or connection_stop_writing().

To queue data to be written on a connection, call connection_buf_add(). When data arrives, the connection_process_inbuf() callback is invoked, which dispatches to a type-specific function (such as connection_edge_process_inbuf() for example). Connection types that need notice of when data has been written receive notification via connection_flushed_some() and connection_finished_flushing(). These functions all delegate to type-specific implementations.

Additionally, beyond the core of connection_t, this module also implements:

Macro Definition Documentation

◆ CASE_ANY_LISTENER_TYPE

#define CASE_ANY_LISTENER_TYPE
Value:
#define CONN_TYPE_OR_LISTENER
Definition: or.h:197
#define CONN_TYPE_CONTROL_LISTENER
Definition: or.h:214
#define CONN_TYPE_EXT_OR_LISTENER
Definition: or.h:229
#define CONN_TYPE_AP_DNS_LISTENER
Definition: or.h:224
#define CONN_TYPE_AP_NATD_LISTENER
Definition: or.h:222
#define CONN_TYPE_AP_TRANS_LISTENER
Definition: or.h:219
#define CONN_TYPE_DIR_LISTENER
Definition: or.h:209
#define CONN_TYPE_AP_LISTENER
Definition: or.h:204
#define CONN_TYPE_AP_HTTP_CONNECT_LISTENER
Definition: or.h:231

◆ CLIENT_IDLE_TIME_FOR_PRIORITY

#define CLIENT_IDLE_TIME_FOR_PRIORITY   30

How many seconds of no active local circuits will make the connection revert to the "relayed" bandwidth class?

◆ CONN_GET_ALL_TEMPLATE

#define CONN_GET_ALL_TEMPLATE (   var,
  test 
)
Value:
STMT_BEGIN \
smartlist_t *conns = get_connection_array(); \
smartlist_t *ret_conns = smartlist_new(); \
SMARTLIST_FOREACH_BEGIN(conns, connection_t *, var) { \
if (var && (test) && !var->marked_for_close) \
smartlist_add(ret_conns, var); \
} SMARTLIST_FOREACH_END(var); \
return ret_conns; \
STMT_END
Definition: or.h:1326

◆ CONN_GET_TEMPLATE

#define CONN_GET_TEMPLATE (   var,
  test 
)
Value:
STMT_BEGIN \
smartlist_t *conns = get_connection_array(); \
SMARTLIST_FOREACH(conns, connection_t *, var, \
{ \
if (var && (test) && !var->marked_for_close) \
return var; \
}); \
return NULL; \
STMT_END
Definition: or.h:1326

Return a connection_t * from get_connection_array() that satisfies test on var, and that is not marked for close.

◆ CONN_IS_CLOSED

#define CONN_IS_CLOSED (   c)    ((c)->linked ? ((c)->linked_conn_is_closed) : (! SOCKET_OK(c->s)))

Return true iff connection_close_immediate() has been called on this connection.

◆ DIR_CONN_LIST_TEMPLATE

#define DIR_CONN_LIST_TEMPLATE (   conn_var,
  conn_test,
  dirconn_var,
  dirconn_test 
)
Value:
STMT_BEGIN \
smartlist_t *conns = get_connection_array(); \
smartlist_t *dir_conns = smartlist_new(); \
SMARTLIST_FOREACH_BEGIN(conns, connection_t *, conn_var) { \
if (conn_var && (conn_test) \
&& conn_var->type == CONN_TYPE_DIR \
&& !conn_var->marked_for_close) { \
dir_connection_t *dirconn_var = TO_DIR_CONN(conn_var); \
if (dirconn_var && (dirconn_test)) { \
smartlist_add(dir_conns, dirconn_var); \
} \
} \
} SMARTLIST_FOREACH_END(conn_var); \
return dir_conns; \
STMT_END
Definition: or.h:1326
#define CONN_TYPE_DIR
Definition: or.h:211

Return a new smartlist of dir_connection_t * from get_connection_array() that satisfy conn_test on connection_t *conn_var, and dirconn_test on dir_connection_t *dirconn_var. conn_var must be of CONN_TYPE_DIR and not marked for close to be included in the list.

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.

Here is the call graph for this function:

◆ 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.

◆ 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.

Here is the caller graph for this function:

◆ conn_get_outbound_address()

const tor_addr_t * conn_get_outbound_address ( sa_family_t  family,
const or_options_t options,
unsigned int  conn_type 
)

Retrieve the outbound address depending on the protocol (IPv4 or IPv6) and the connection type (relay, exit, ...) Return a socket address or NULL in case nothing is configured.

Here is the call graph for this function:

◆ 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.

◆ 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

Here is the caller graph for this function:

◆ conn_type_to_string()

const char* conn_type_to_string ( int  type)

Return the human-readable name for the connection type type

Here is the caller graph for this function:

◆ 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.
Here is the call graph for this function:

◆ connection_bucket_adjust()

void connection_bucket_adjust ( const or_options_t options)

Update the global connection bucket settings to a new value.

Here is the call graph for this function:

◆ connection_bucket_init()

void connection_bucket_init ( void  )

Initialize the global buckets to the values configured in the options

Here is the call graph for this function:

◆ 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?

◆ 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.)

◆ connection_buf_get_bytes()

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

A pass-through to fetch_from_buf.

Here is the call graph for this function:

◆ 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.

Here is the call graph for this function:

◆ 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.

◆ 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().

Here is the call graph for this function:

◆ 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.

◆ 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.

◆ 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.

◆ 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.

Here is the call graph for this function:

◆ 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.

Here is the call graph for this function:

◆ 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.

◆ 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.

Here is the call graph for this function:

◆ 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.

Here is the caller graph for this function:

◆ 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.

◆ 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.

◆ connection_free_minimal()

STATIC void connection_free_minimal ( connection_t conn)

Deallocate memory used by conn. Deallocate its buffers if necessary, close its socket if necessary, and mark the directory as dirty if conn is an OR or OP connection.

◆ 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.

◆ connection_get_by_type()

connection_t* connection_get_by_type ( int  type)

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

◆ 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.

◆ 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.

◆ 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.

Here is the call graph for this function:

◆ connection_is_listener()

int connection_is_listener ( connection_t conn)

Return 1 if conn is a listener conn, else return 0.

Here is the caller graph for this function:

◆ connection_link_connections()

void connection_link_connections ( connection_t conn_a,
connection_t conn_b 
)

Create a link between conn_a and conn_b.

◆ connection_mark_all_noncontrol_connections()

void connection_mark_all_noncontrol_connections ( void  )

Mark every external connection not used for controllers for close.

◆ connection_mark_all_noncontrol_listeners()

void connection_mark_all_noncontrol_listeners ( void  )

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

Here is the call graph for this function:

◆ 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.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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.

◆ 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().

Here is the caller graph for this function:

◆ 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.

◆ 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.

◆ 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.

Here is the caller graph for this function:

◆ connection_state_is_connecting()

int connection_state_is_connecting ( connection_t conn)

Return 1 if conn is in 'connecting' state, else return 0.

◆ connection_state_is_open()

int connection_state_is_open ( connection_t conn)

Return 1 if conn is in state "open" and is not marked for close, else return 0.

◆ 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.

◆ 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.

◆ 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().

◆ 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().

◆ 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().

Here is the caller graph for this function:

◆ 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.

◆ get_proxy_addrport()

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

Fills addr and port with the details of the global proxy server we are using. conn contains the connection we are using the proxy for.

Return 0 on success, -1 on failure.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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.

◆ 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().

◆ 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.

Here is the call graph for this function:

◆ MOCK_IMPL() [1/8]

MOCK_IMPL ( void  ,
connection_free_  ,
(connection_t *conn)   
)

Make sure conn isn't in any of the global conn lists; then free it.

Here is the call graph for this function:

◆ MOCK_IMPL() [2/8]

MOCK_IMPL ( void  ,
connection_mark_for_close_internal_  ,
(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; the _internal version bypasses the CONN_TYPE_OR checks; 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.

Here is the call graph for this function:

◆ MOCK_IMPL() [3/8]

MOCK_IMPL ( 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)   
)

Take conn, make a nonblocking socket; try to connect to sa, binding to bindaddr if sa is not localhost. If fail, return -1 and if applicable put your best guess about errno into *socket_error. If connected return 1, if EAGAIN return 0.

Here is the call graph for this function:

◆ MOCK_IMPL() [4/8]

MOCK_IMPL ( void  ,
connection_write_to_buf_impl_  ,
(const char *string, size_t len, connection_t *conn, int zlib)   
)

Append len bytes of string onto conn's outbuf, and ask it to start writing.

If zlib is nonzero, this is a directory connection that should get its contents compressed or decompressed as they're written. If zlib is negative, this is the last data to be compressed, and the connection's zlib state should be flushed.

◆ MOCK_IMPL() [5/8]

MOCK_IMPL ( connection_t ,
connection_get_by_type_addr_port_purpose  ,
(int type, const tor_addr_t *addr, uint16_t port, int purpose)   
)

Return a connection with given type, address, port, and purpose; or NULL if no such connection exists (or if all such connections are marked for close).

◆ MOCK_IMPL() [6/8]

MOCK_IMPL ( STATIC smartlist_t ,
pick_oos_victims  ,
(int n)   
)

Pick n victim connections for the OOS handler and return them in a smartlist.

◆ MOCK_IMPL() [7/8]

MOCK_IMPL ( STATIC  void,
kill_conn_list_for_oos  ,
(smartlist_t *conns)   
)

Kill a list of connections for the OOS handler.

◆ MOCK_IMPL() [8/8]

MOCK_IMPL ( void  ,
clock_skew_warning  ,
(const connection_t *conn, long apparent_skew, int trusted, log_domain_mask_t domain, const char *received, const char *source)   
)

Log a warning, and possibly emit a control event, that received came at a skewed time. trusted indicates that the source was one that we had more faith in and therefore the warning level should have higher severity.

Here is the call graph for this function:

◆ 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.

◆ retry_all_listeners()

int retry_all_listeners ( smartlist_t replaced_conns,
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 old conns that should be closed to replaced_conns. 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.

Here is the call graph for this function: