tor  0.4.2.1-alpha-dev
Macros | Functions
connection_or.h File Reference
#include "core/or/orconn_event.h"

Go to the source code of this file.

Macros

#define or_handshake_state_free(state)   FREE_AND_NULL(or_handshake_state_t, or_handshake_state_free_, (state))
 
#define var_cell_free(cell)   FREE_AND_NULL(var_cell_t, var_cell_free_, (cell))
 
#define MIN_LINK_PROTO_FOR_WIDE_CIRC_IDS   4
 
#define MIN_LINK_PROTO_FOR_CHANNEL_PADDING   5
 
#define MAX_LINK_PROTO   MIN_LINK_PROTO_FOR_CHANNEL_PADDING
 

Functions

or_connection_tTO_OR_CONN (connection_t *)
 
void connection_or_clear_identity (or_connection_t *conn)
 
void connection_or_clear_identity_map (void)
 
void clear_broken_connection_map (int disable)
 
or_connection_tconnection_or_get_for_extend (const char *digest, const tor_addr_t *target_addr, const char **msg_out, int *launch_out)
 
void connection_or_block_renegotiation (or_connection_t *conn)
 
int connection_or_reached_eof (or_connection_t *conn)
 
int connection_or_process_inbuf (or_connection_t *conn)
 
ssize_t connection_or_num_cells_writeable (or_connection_t *conn)
 
int connection_or_flushed_some (or_connection_t *conn)
 
int connection_or_finished_flushing (or_connection_t *conn)
 
int connection_or_finished_connecting (or_connection_t *conn)
 
void connection_or_about_to_close (or_connection_t *conn)
 
int connection_or_digest_is_known_relay (const char *id_digest)
 
void connection_or_update_token_buckets (smartlist_t *conns, const or_options_t *options)
 
void connection_or_connect_failed (or_connection_t *conn, int reason, const char *msg)
 
void connection_or_notify_error (or_connection_t *conn, int reason, const char *msg)
 
 MOCK_DECL (or_connection_t *, connection_or_connect,(const tor_addr_t *addr, uint16_t port, const char *id_digest, const struct ed25519_public_key_t *ed_id, channel_tls_t *chan))
 
void connection_or_close_normally (or_connection_t *orconn, int flush)
 
 MOCK_DECL (void, connection_or_close_for_error,(or_connection_t *orconn, int flush))
 
void connection_or_report_broken_states (int severity, int domain)
 
void connection_or_event_status (or_connection_t *conn, or_conn_status_event_t tp, int reason)
 
 MOCK_DECL (int, connection_tls_start_handshake,(or_connection_t *conn, int receiving))
 
int connection_tls_continue_handshake (or_connection_t *conn)
 
void connection_or_set_canonical (or_connection_t *or_conn, int is_canonical)
 
int connection_init_or_handshake_state (or_connection_t *conn, int started_here)
 
void connection_or_init_conn_from_address (or_connection_t *conn, const tor_addr_t *addr, uint16_t port, const char *rsa_id_digest, const struct ed25519_public_key_t *ed_id, int started_here)
 
int connection_or_client_learned_peer_id (or_connection_t *conn, const uint8_t *rsa_peer_id, const struct ed25519_public_key_t *ed_peer_id)
 
time_t connection_or_client_used (or_connection_t *conn)
 
 MOCK_DECL (int, connection_or_get_num_circuits,(or_connection_t *conn))
 
void or_handshake_state_free_ (or_handshake_state_t *state)
 
void or_handshake_state_record_cell (or_connection_t *conn, or_handshake_state_t *state, const cell_t *cell, int incoming)
 
void or_handshake_state_record_var_cell (or_connection_t *conn, or_handshake_state_t *state, const var_cell_t *cell, int incoming)
 
int connection_or_set_state_open (or_connection_t *conn)
 
void connection_or_write_cell_to_buf (const cell_t *cell, or_connection_t *conn)
 
 MOCK_DECL (void, connection_or_write_var_cell_to_buf,(const var_cell_t *cell, or_connection_t *conn))
 
int connection_or_send_versions (or_connection_t *conn, int v3_plus)
 
 MOCK_DECL (int, connection_or_send_netinfo,(or_connection_t *conn))
 
int connection_or_send_certs_cell (or_connection_t *conn)
 
int connection_or_send_auth_challenge_cell (or_connection_t *conn)
 
int authchallenge_type_is_supported (uint16_t challenge_type)
 
int authchallenge_type_is_better (uint16_t challenge_type_a, uint16_t challenge_type_b)
 
var_cell_tconnection_or_compute_authenticate_cell_body (or_connection_t *conn, const int authtype, crypto_pk_t *signing_key, const struct ed25519_keypair_t *ed_signing_key, int server)
 
 MOCK_DECL (int, connection_or_send_authenticate_cell,(or_connection_t *conn, int type))
 
int is_or_protocol_version_known (uint16_t version)
 
void cell_pack (packed_cell_t *dest, const cell_t *src, int wide_circ_ids)
 
int var_cell_pack_header (const var_cell_t *cell, char *hdr_out, int wide_circ_ids)
 
var_cell_tvar_cell_new (uint16_t payload_len)
 
var_cell_tvar_cell_copy (const var_cell_t *src)
 
void var_cell_free_ (var_cell_t *cell)
 
int connection_or_single_set_badness_ (time_t now, or_connection_t *or_conn, int force)
 
void connection_or_group_set_badness_ (smartlist_t *group, int force)
 

Detailed Description

Header file for connection_or.c.

Definition in file connection_or.h.

Function Documentation

◆ authchallenge_type_is_better()

int authchallenge_type_is_better ( uint16_t  challenge_type_a,
uint16_t  challenge_type_b 
)

Return true iff challenge_type_a is one that we would rather use than challenge_type_b.

Definition at line 2772 of file connection_or.c.

References authchallenge_type_is_supported().

◆ authchallenge_type_is_supported()

int authchallenge_type_is_supported ( uint16_t  challenge_type)

Return true iff challenge_type is an AUTHCHALLENGE type that we can send and receive.

Definition at line 2752 of file connection_or.c.

References AUTHTYPE_RSA_SHA256_TLSSECRET.

Referenced by authchallenge_type_is_better(), and connection_or_send_auth_challenge_cell().

◆ cell_pack()

void cell_pack ( packed_cell_t dst,
const cell_t src,
int  wide_circ_ids 
)

Pack the cell_t host-order structure src into network-order in the buffer dest. See tor-spec.txt for details about the wire format.

Note that this function doesn't touch dst->next: the caller should set it or clear it as appropriate.

Definition at line 496 of file connection_or.c.

References packed_cell_t::body, CELL_MAX_NETWORK_SIZE, cell_t::circ_id, set_uint16(), and set_uint32().

Referenced by packed_cell_copy().

◆ clear_broken_connection_map()

void clear_broken_connection_map ( int  stop_recording)

Forget all recorded states for failed connections. If stop_recording is true, don't record any more.

Definition at line 306 of file connection_or.c.

References broken_connection_counts.

Referenced by connection_free_all().

◆ connection_init_or_handshake_state()

int connection_init_or_handshake_state ( or_connection_t conn,
int  started_here 
)

Allocate a new connection handshake state for the connection conn. Return 0 on success, -1 on failure.

Definition at line 2160 of file connection_or.c.

References or_connection_t::handshake_state.

Referenced by connection_or_launch_v3_or_handshake().

◆ connection_or_about_to_close()

void connection_or_about_to_close ( or_connection_t or_conn)

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

Definition at line 784 of file connection_or.c.

References or_connection_t::chan, channel_closed(), and TO_CONN.

Referenced by connection_about_to_close_connection().

◆ connection_or_block_renegotiation()

void connection_or_block_renegotiation ( or_connection_t conn)

Block all future attempts to renegotiate on 'conn'

Definition at line 1703 of file connection_or.c.

References or_connection_t::tls, tor_tls_block_renegotiation(), and tor_tls_set_renegotiate_callback().

Referenced by connection_or_tls_renegotiated_cb().

◆ connection_or_clear_identity()

void connection_or_clear_identity ( or_connection_t conn)

Clear clear conn->identity_digest and update other data structures as appropriate.

Definition at line 126 of file connection_or.c.

References DIGEST_LEN, or_connection_t::identity_digest, and tor_assert().

Referenced by connection_unlink().

◆ connection_or_clear_identity_map()

void connection_or_clear_identity_map ( void  )

Clear all identities in OR conns.

Definition at line 134 of file connection_or.c.

References CONN_TYPE_OR, and SMARTLIST_FOREACH.

Referenced by connection_free_all().

◆ connection_or_client_used()

time_t connection_or_client_used ( or_connection_t conn)

Return when we last used this channel for client activity (origin circuits). This is called from connection.c, since client_used is now one of the timestamps in channel_t

Definition at line 2075 of file connection_or.c.

References or_connection_t::chan, channel_when_last_client(), and tor_assert().

Referenced by connection_counts_as_relayed_traffic().

◆ connection_or_close_normally()

void connection_or_close_normally ( or_connection_t orconn,
int  flush 
)

Mark orconn for close and transition the associated channel, if any, to the closing state.

It's safe to call this and connection_or_close_for_error() any time, and channel layer will treat it as a connection closing for reasons outside its control, like the remote end closing it. It can also be a local reason that's specific to connection_t/or_connection_t rather than the channel mechanism, such as expiration of old connections in run_connection_housekeeping(). If you want to close a channel_t from somewhere that logically works in terms of generic channels rather than connections, use channel_mark_for_close(); see also the comment on that function in channel.c.

Definition at line 1616 of file connection_or.c.

References tor_assert().

◆ connection_or_connect_failed()

void connection_or_connect_failed ( or_connection_t conn,
int  reason,
const char *  msg 
)

conn is in the 'connecting' state, and it failed to complete a TCP connection. Send notifications appropriately.

reason specifies the or_conn_end_reason for the failure; msg specifies the strerror-style error message.

Definition at line 1412 of file connection_or.c.

References connection_or_event_status().

Referenced by connection_or_notify_error().

◆ connection_or_digest_is_known_relay()

int connection_or_digest_is_known_relay ( const char *  id_digest)

Return 1 if identity digest id_digest is known to be a currently or recently running relay. Otherwise return 0.

Definition at line 831 of file connection_or.c.

References router_get_by_id_digest(), and router_get_consensus_status_by_id().

Referenced by connection_or_update_token_buckets_helper().

◆ connection_or_event_status()

void connection_or_event_status ( or_connection_t conn,
or_conn_status_event_t  tp,
int  reason 
)

Helper function to publish an OR connection status event

Publishes a messages to subscribers of ORCONN messages, and sends the control event.

Definition at line 414 of file connection_or.c.

Referenced by connection_ext_or_transition(), connection_init_accepted_conn(), connection_or_connect_failed(), and connection_or_set_state_open().

◆ connection_or_finished_connecting()

int connection_or_finished_connecting ( or_connection_t or_conn)

Connected handler for OR connections: begin the TLS handshake.

Definition at line 749 of file connection_or.c.

References OR_CONN_STATE_CONNECTING, or_connection_t::proxy_type, connection_t::state, TO_CONN, and tor_assert().

Referenced by connection_finished_connecting().

◆ connection_or_finished_flushing()

int connection_or_finished_flushing ( or_connection_t conn)

Connection conn has finished writing and has no bytes left on its outbuf.

Otherwise it's in state "open": stop writing and return.

If conn is broken, mark it for close and return -1, else return 0.

Definition at line 722 of file connection_or.c.

References assert_connection_ok(), OR_CONN_STATE_OPEN, OR_CONN_STATE_OR_HANDSHAKING_V2, OR_CONN_STATE_OR_HANDSHAKING_V3, OR_CONN_STATE_PROXY_HANDSHAKING, connection_t::state, TO_CONN, and tor_assert().

Referenced by connection_finished_flushing().

◆ connection_or_flushed_some()

int connection_or_flushed_some ( or_connection_t conn)

Called whenever we have flushed some data on an or_conn: add more data from active circuits.

Definition at line 670 of file connection_or.c.

References or_connection_t::chan, and channel_timestamp_active().

Referenced by connection_flushed_some().

◆ connection_or_group_set_badness_()

void connection_or_group_set_badness_ ( smartlist_t group,
int  force 
)

Given a list of all the or_connections with a given identity, set elements of that list as is_bad_for_new_circs as appropriate. Helper for connection_or_set_bad_connections().

Specifically, we set the is_bad_for_new_circs flag on:

  • all connections if force is true.
  • all connections that are too old.
  • all open non-canonical connections for which a canonical connection exists to the same router.
  • all open canonical connections for which a 'better' canonical connection exists to the same router.
  • all open non-canonical connections for which a 'better' non-canonical connection exists to the same router at the same address.

See channel_is_better() in channel.c for our idea of what makes one OR connection better than another.

Definition at line 1088 of file connection_or.c.

References connection_or_is_bad_for_new_circs(), connection_or_single_set_badness_(), or_connection_t::is_canonical, OR_CONN_STATE_OPEN, SMARTLIST_FOREACH_BEGIN, and connection_t::state.

◆ connection_or_notify_error()

void connection_or_notify_error ( or_connection_t conn,
int  reason,
const char *  msg 
)

conn got an error in connection_handle_read_impl() or connection_handle_write_impl() and is going to die soon.

reason specifies the or_conn_end_reason for the failure; msg specifies the strerror-style error message.

Definition at line 1428 of file connection_or.c.

References or_connection_t::chan, connection_or_connect_failed(), OR_CONN_STATE_CONNECTING, TO_CONN, and tor_assert().

Referenced by connection_handle_read_impl().

◆ connection_or_num_cells_writeable()

ssize_t connection_or_num_cells_writeable ( or_connection_t conn)

This is for channeltls.c to ask how many cells we could accept if they were available.

Definition at line 692 of file connection_or.c.

References tor_assert().

◆ connection_or_process_inbuf()

int connection_or_process_inbuf ( or_connection_t conn)

Handle any new bytes that have come in on connection conn. If conn is in 'open' state, hand it to connection_or_process_cells_from_inbuf() (else do nothing).

Don't let the inbuf of a nonopen OR connection grow beyond this many bytes: it's either a broken client, a non-Tor client, or a DOS attempt.

Definition at line 610 of file connection_or.c.

References connection_read_proxy_handshake(), OR_CONN_STATE_PROXY_HANDSHAKING, connection_t::state, TO_CONN, and tor_assert().

Referenced by connection_process_inbuf().

◆ connection_or_reached_eof()

int connection_or_reached_eof ( or_connection_t conn)

We've received an EOF from conn. Mark it for close and return.

Definition at line 594 of file connection_or.c.

References tor_assert().

Referenced by connection_reached_eof().

◆ connection_or_report_broken_states()

void connection_or_report_broken_states ( int  severity,
int  domain 
)

Report a list of the top states for failed OR connections at log level severity, in log domain domain.

Definition at line 374 of file connection_or.c.

References broken_connection_counts, and disable_broken_connection_counts.

◆ connection_or_send_auth_challenge_cell()

int connection_or_send_auth_challenge_cell ( or_connection_t conn)

◆ connection_or_send_certs_cell()

int connection_or_send_certs_cell ( or_connection_t conn)

Send a CERTS cell on the connection conn. Return 0 on success, -1 on failure.

Definition at line 2654 of file connection_or.c.

References or_connection_t::handshake_state, OR_CONN_STATE_OR_HANDSHAKING_V3, or_handshake_state_t::started_here, connection_t::state, or_connection_t::tls, tor_assert(), and tor_tls_get_my_certs().

◆ connection_or_send_versions()

int connection_or_send_versions ( or_connection_t conn,
int  v3_plus 
)

Send a VERSIONS cell on conn, telling the other host about the link protocol versions that this Tor can support.

If v3_plus, this is part of a V3 protocol handshake, so only allow protocol version v3 or later. If not v3_plus, this is not part of a v3 protocol handshake, so don't allow protocol v3 or later.

Definition at line 2461 of file connection_or.c.

References var_cell_t::command, or_connection_t::handshake_state, n_or_protocol_versions, or_handshake_state_t::sent_versions_at, tor_assert(), and var_cell_new().

Referenced by connection_or_launch_v3_or_handshake().

◆ connection_or_set_state_open()

int connection_or_set_state_open ( or_connection_t conn)

Set conn's state to OR_CONN_STATE_OPEN, and tell other subsystems as appropriate. Called when we are done with all TLS and OR handshaking.

Definition at line 2276 of file connection_or.c.

References connection_or_change_state(), connection_or_event_status(), and OR_CONN_STATE_OPEN.

◆ connection_or_single_set_badness_()

int connection_or_single_set_badness_ ( time_t  now,
or_connection_t or_conn,
int  force 
)

Expire an or_connection if it is too old. Helper for connection_or_group_set_badness_ and fast path for channel_rsa_id_group_set_badness.

Returns 1 if the connection was already expired, else 0.

Definition at line 1047 of file connection_or.c.

References connection_or_is_bad_for_new_circs(), connection_t::marked_for_close, TIME_BEFORE_OR_CONN_IS_TOO_OLD, and connection_t::timestamp_created.

Referenced by connection_or_group_set_badness_().

◆ connection_or_update_token_buckets()

void connection_or_update_token_buckets ( smartlist_t conns,
const or_options_t options 
)

Either our set of relays or our per-conn rate limits have changed. Go through all the OR connections and update their token buckets to make sure they don't exceed their maximum values.

Definition at line 883 of file connection_or.c.

References SMARTLIST_FOREACH.

◆ connection_or_write_cell_to_buf()

void connection_or_write_cell_to_buf ( const cell_t cell,
or_connection_t conn 
)

Pack cell into wire-format, and write it onto conn's outbuf. For cells that use or affect a circuit, this should only be called by connection_or_flush_from_first_active_circuit().

Definition at line 2299 of file connection_or.c.

◆ connection_tls_continue_handshake()

int connection_tls_continue_handshake ( or_connection_t conn)

Move forward with the tls handshake. If it finishes, hand conn to connection_tls_finish_handshake().

Return -1 if conn is broken, else return 0.

Definition at line 1736 of file connection_or.c.

◆ is_or_protocol_version_known()

int is_or_protocol_version_known ( uint16_t  v)

Return true iff v is a link protocol version that this Tor implementation believes it can support.

Definition at line 2442 of file connection_or.c.

◆ or_handshake_state_free_()

void or_handshake_state_free_ ( or_handshake_state_t state)

Free all storage held by state.

Definition at line 2181 of file connection_or.c.

◆ or_handshake_state_record_cell()

void or_handshake_state_record_cell ( or_connection_t conn,
or_handshake_state_t state,
const cell_t cell,
int  incoming 
)

Remember that cell has been transmitted (if incoming is false) or received (if incoming is true) during a V3 handshake using state.

(We don't record the cell, but we keep a digest of everything sent or received during the v3 handshake, and the client signs it in an authenticate cell.)

Definition at line 2203 of file connection_or.c.

◆ or_handshake_state_record_var_cell()

void or_handshake_state_record_var_cell ( or_connection_t conn,
or_handshake_state_t state,
const var_cell_t cell,
int  incoming 
)

Remember that a variable-length cell has been transmitted (if incoming is false) or received (if incoming is true) during a V3 handshake using state.

(We don't record the cell, but we keep a digest of everything sent or received during the v3 handshake, and the client signs it in an authenticate cell.)

Definition at line 2244 of file connection_or.c.

References crypto_digest256_new(), or_handshake_state_t::digest_sent, or_handshake_state_t::digest_sent_data, and VAR_CELL_MAX_HEADER_SIZE.

◆ TO_OR_CONN()

or_connection_t* TO_OR_CONN ( connection_t c)

◆ var_cell_copy()

var_cell_t* var_cell_copy ( const var_cell_t src)

Copy a var_cell_t

Definition at line 568 of file connection_or.c.

References var_cell_t::payload_len.

◆ var_cell_free_()

void var_cell_free_ ( var_cell_t cell)

Release all space held by cell.

Definition at line 587 of file connection_or.c.

References tor_free.

◆ var_cell_new()

var_cell_t* var_cell_new ( uint16_t  payload_len)

Allocate and return a new var_cell_t with payload_len bytes of payload space.

Definition at line 553 of file connection_or.c.

Referenced by connection_or_send_auth_challenge_cell(), and connection_or_send_versions().

◆ var_cell_pack_header()

int var_cell_pack_header ( const var_cell_t cell,
char *  hdr_out,
int  wide_circ_ids 
)

Write the header of cell into the first VAR_CELL_MAX_HEADER_SIZE bytes of hdr_out. Returns number of bytes used.

Definition at line 533 of file connection_or.c.

References var_cell_t::circ_id, set_uint16(), set_uint32(), and VAR_CELL_MAX_HEADER_SIZE.

Referenced by MOCK_IMPL().