Tor 0.4.9.0-alpha-dev
Macros | Enumerations | Functions
connection_edge.h File Reference

Header file for connection_edge.c. More...

#include "lib/testsupport/testsupport.h"
#include "lib/encoding/confline.h"
#include "feature/hs/hs_service.h"

Go to the source code of this file.

Macros

#define EXIT_CONN_STATE_MIN_   1
 
#define EXIT_CONN_STATE_RESOLVING   1
 
#define EXIT_CONN_STATE_CONNECTING   2
 
#define EXIT_CONN_STATE_OPEN   3
 
#define EXIT_CONN_STATE_RESOLVEFAILED   4
 
#define EXIT_CONN_STATE_MAX_   4
 
#define AP_CONN_STATE_MIN_   5
 
#define AP_CONN_STATE_SOCKS_WAIT   5
 
#define AP_CONN_STATE_RENDDESC_WAIT   6
 
#define AP_CONN_STATE_CONTROLLER_WAIT   7
 
#define AP_CONN_STATE_CIRCUIT_WAIT   8
 
#define AP_CONN_STATE_CONNECT_WAIT   9
 
#define AP_CONN_STATE_RESOLVE_WAIT   10
 
#define AP_CONN_STATE_OPEN   11
 
#define AP_CONN_STATE_NATD_WAIT   12
 
#define AP_CONN_STATE_HTTP_CONNECT_WAIT   13
 
#define AP_CONN_STATE_MAX_   13
 
#define EXIT_PURPOSE_MIN_   1
 
#define EXIT_PURPOSE_CONNECT   1
 
#define EXIT_PURPOSE_RESOLVE   2
 
#define EXIT_PURPOSE_MAX_   2
 
#define AP_CONN_STATE_IS_UNATTACHED(s)    ((s) <= AP_CONN_STATE_CIRCUIT_WAIT || (s) == AP_CONN_STATE_NATD_WAIT)
 
#define connection_mark_unattached_ap(conn, endreason)    connection_mark_unattached_ap_((conn), (endreason), __LINE__, SHORT_FILE__)
 
#define connection_ap_mark_as_pending_circuit(c)    connection_ap_mark_as_pending_circuit_((c), __FILE__, __LINE__)
 
#define CONNECTION_AP_EXPECT_NONPENDING(c)
 
#define MIN_DNS_TTL   (5*60)
 
#define MAX_DNS_TTL   (60*60)
 
#define MAX_DNS_ENTRY_AGE   (3*60*60)
 
#define DEFAULT_DNS_TTL   (30*60)
 
#define FUZZY_DNS_TTL   (4*60)
 
#define half_edge_free(he)    FREE_AND_NULL(half_edge_t, half_edge_free_, (he))
 
Begin-cell flags

These flags are used in RELAY_BEGIN cells to change the default behavior of the cell.

#define BEGIN_FLAG_IPV6_OK   (1u<<0)
 
#define BEGIN_FLAG_IPV4_NOT_OK   (1u<<1)
 
#define BEGIN_FLAG_IPV6_PREFERRED   (1u<<2)
 

Enumerations

enum  hostname_type_t { BAD_HOSTNAME , EXIT_HOSTNAME , NORMAL_HOSTNAME , ONION_V3_HOSTNAME }
 

Functions

edge_connection_tTO_EDGE_CONN (connection_t *)
 
entry_connection_tTO_ENTRY_CONN (connection_t *)
 
entry_connection_tEDGE_TO_ENTRY_CONN (edge_connection_t *)
 
const edge_connection_tCONST_TO_EDGE_CONN (const connection_t *)
 
const entry_connection_tCONST_TO_ENTRY_CONN (const connection_t *)
 
const entry_connection_tCONST_EDGE_TO_ENTRY_CONN (const edge_connection_t *)
 
void connection_mark_unattached_ap_ (entry_connection_t *conn, int endreason, int line, const char *file)
 
int connection_edge_reached_eof (edge_connection_t *conn)
 
int connection_edge_process_inbuf (edge_connection_t *conn, int package_partial)
 
int connection_edge_destroy (circid_t circ_id, edge_connection_t *conn)
 
int connection_edge_end (edge_connection_t *conn, uint8_t reason)
 
int connection_edge_end_errno (edge_connection_t *conn)
 
void connection_edge_end_close (edge_connection_t *conn, uint8_t reason)
 
int connection_edge_flushed_some (edge_connection_t *conn)
 
int connection_edge_finished_flushing (edge_connection_t *conn)
 
int connection_edge_finished_connecting (edge_connection_t *conn)
 
void connection_entry_set_controller_wait (entry_connection_t *conn)
 
void connection_ap_about_to_close (entry_connection_t *edge_conn)
 
void connection_exit_about_to_close (edge_connection_t *edge_conn)
 
void connection_reapply_exit_policy (config_line_t *changes)
 
int connection_ap_handshake_send_begin (entry_connection_t *ap_conn)
 
int connection_ap_handshake_send_resolve (entry_connection_t *ap_conn)
 
entry_connection_tconnection_ap_make_link (connection_t *partner, char *address, uint16_t port, const char *digest, int session_group, int isolation_flags, int use_begindir, int want_onehop)
 
void connection_ap_handshake_socks_reply (entry_connection_t *conn, char *reply, size_t replylen, int endreason)
 
void connection_ap_handshake_socks_resolved (entry_connection_t *conn, int answer_type, size_t answer_len, const uint8_t *answer, int ttl, time_t expires)
 
void connection_ap_handshake_socks_resolved_addr (entry_connection_t *conn, const tor_addr_t *answer, int ttl, time_t expires)
 
int connection_exit_begin_conn (cell_t *cell, circuit_t *circ)
 
int connection_exit_begin_resolve (cell_t *cell, or_circuit_t *circ)
 
void connection_exit_connect (edge_connection_t *conn)
 
int connection_edge_is_rendezvous_stream (const edge_connection_t *conn)
 
int connection_ap_can_use_exit (const entry_connection_t *conn, const node_t *exit)
 
void connection_ap_expire_beginning (void)
 
void connection_ap_rescan_and_attach_pending (void)
 
void connection_ap_attach_pending (int retry)
 
void connection_ap_mark_as_pending_circuit_ (entry_connection_t *entry_conn, const char *file, int line)
 
void connection_ap_mark_as_non_pending_circuit (entry_connection_t *entry_conn)
 
void connection_ap_mark_as_waiting_for_renddesc (entry_connection_t *entry_conn)
 
void connection_ap_fail_onehop (const char *failed_digest, cpath_build_state_t *build_state)
 
void circuit_discard_optional_exit_enclaves (extend_info_t *info)
 
int connection_ap_detach_retriable (entry_connection_t *conn, origin_circuit_t *circ, int reason)
 
int connection_ap_process_transparent (entry_connection_t *conn)
 
int address_is_invalid_destination (const char *address, int client)
 
int connection_ap_rewrite_and_attach_if_allowed (entry_connection_t *conn, origin_circuit_t *circ, crypt_path_t *cpath)
 
int connection_ap_handshake_rewrite_and_attach (entry_connection_t *conn, origin_circuit_t *circ, crypt_path_t *cpath)
 
int connection_edge_compatible_with_circuit (const entry_connection_t *conn, const origin_circuit_t *circ)
 
int connection_edge_update_circuit_isolation (const entry_connection_t *conn, origin_circuit_t *circ, int dry_run)
 
void circuit_clear_isolation (origin_circuit_t *circ)
 
streamid_t get_unique_stream_id_by_circ (origin_circuit_t *circ)
 
void connection_edge_free_all (void)
 
void connection_ap_warn_and_unmark_if_pending_circ (entry_connection_t *entry_conn, const char *where)
 
uint32_t clip_dns_ttl (uint32_t ttl)
 
uint32_t clip_dns_fuzzy_ttl (uint32_t ttl)
 
int connection_half_edge_is_valid_data (const smartlist_t *half_conns, streamid_t stream_id)
 
int connection_half_edge_is_valid_sendme (const smartlist_t *half_conns, streamid_t stream_id)
 
int connection_half_edge_is_valid_connected (const smartlist_t *half_conns, streamid_t stream_id)
 
int connection_half_edge_is_valid_end (smartlist_t *half_conns, streamid_t stream_id)
 
int connection_half_edge_is_valid_resolved (smartlist_t *half_conns, streamid_t stream_id)
 
bool connection_half_edges_waiting (const origin_circuit_t *circ)
 
size_t half_streams_get_total_allocation (void)
 
void half_edge_free_ (struct half_edge_t *he)
 

Detailed Description

Header file for connection_edge.c.

Definition in file connection_edge.h.

Macro Definition Documentation

◆ AP_CONN_STATE_CIRCUIT_WAIT

#define AP_CONN_STATE_CIRCUIT_WAIT   8

State for a SOCKS connection: waiting for a completed circuit.

Definition at line 50 of file connection_edge.h.

◆ AP_CONN_STATE_CONNECT_WAIT

#define AP_CONN_STATE_CONNECT_WAIT   9

State for a SOCKS connection: sent BEGIN, waiting for CONNECTED.

Definition at line 52 of file connection_edge.h.

◆ AP_CONN_STATE_CONTROLLER_WAIT

#define AP_CONN_STATE_CONTROLLER_WAIT   7

The controller will attach this connection to a circuit; it isn't our job to do so.

Definition at line 48 of file connection_edge.h.

◆ AP_CONN_STATE_HTTP_CONNECT_WAIT

#define AP_CONN_STATE_HTTP_CONNECT_WAIT   13

State for an HTTP tunnel: waiting for an HTTP CONNECT command.

Definition at line 61 of file connection_edge.h.

◆ AP_CONN_STATE_IS_UNATTACHED

#define AP_CONN_STATE_IS_UNATTACHED (   s)     ((s) <= AP_CONN_STATE_CIRCUIT_WAIT || (s) == AP_CONN_STATE_NATD_WAIT)

True iff the AP_CONN_STATE_* value s means that the corresponding edge connection is not attached to any circuit.

Definition at line 73 of file connection_edge.h.

◆ AP_CONN_STATE_MAX_

#define AP_CONN_STATE_MAX_   13

Definition at line 62 of file connection_edge.h.

◆ AP_CONN_STATE_MIN_

#define AP_CONN_STATE_MIN_   5

Definition at line 40 of file connection_edge.h.

◆ AP_CONN_STATE_NATD_WAIT

#define AP_CONN_STATE_NATD_WAIT   12

State for a transparent natd connection: waiting for original destination.

Definition at line 59 of file connection_edge.h.

◆ AP_CONN_STATE_OPEN

#define AP_CONN_STATE_OPEN   11

State for a SOCKS connection: ready to send and receive.

Definition at line 56 of file connection_edge.h.

◆ AP_CONN_STATE_RENDDESC_WAIT

#define AP_CONN_STATE_RENDDESC_WAIT   6

State for a SOCKS connection: got a y.onion URL; waiting to receive rendezvous descriptor.

Definition at line 45 of file connection_edge.h.

◆ AP_CONN_STATE_RESOLVE_WAIT

#define AP_CONN_STATE_RESOLVE_WAIT   10

State for a SOCKS connection: sent RESOLVE, waiting for RESOLVED.

Definition at line 54 of file connection_edge.h.

◆ AP_CONN_STATE_SOCKS_WAIT

#define AP_CONN_STATE_SOCKS_WAIT   5

State for a SOCKS connection: waiting for SOCKS request.

Definition at line 42 of file connection_edge.h.

◆ BEGIN_FLAG_IPV4_NOT_OK

#define BEGIN_FLAG_IPV4_NOT_OK   (1u<<1)

When this flag is set, the client DOES NOT support connecting to IPv4 addresses. (The sense of this flag is inverted from IPV6_OK, so that the old default behavior of Tor is equivalent to having all flags set to 0.)

Definition at line 245 of file connection_edge.h.

◆ BEGIN_FLAG_IPV6_OK

#define BEGIN_FLAG_IPV6_OK   (1u<<0)

When this flag is set, the client is willing to get connected to IPv6 addresses

Definition at line 240 of file connection_edge.h.

◆ BEGIN_FLAG_IPV6_PREFERRED

#define BEGIN_FLAG_IPV6_PREFERRED   (1u<<2)

When this flag is set, if we find both an IPv4 and an IPv6 address, we use the IPv6 address. Otherwise we use the IPv4 address.

Definition at line 248 of file connection_edge.h.

◆ CONNECTION_AP_EXPECT_NONPENDING

#define CONNECTION_AP_EXPECT_NONPENDING (   c)
Value:
do { \
log_warn(LD_BUG, "At %s:%d: %p was unexpectedly in circuit_wait.", \
__FILE__, __LINE__, (c)); \
connection_ap_mark_as_non_pending_circuit(c); \
} \
} while (0)
#define AP_CONN_STATE_CIRCUIT_WAIT
#define LD_BUG
Definition: log.h:86
#define ENTRY_TO_CONN(c)
Definition: or.h:615

Definition at line 149 of file connection_edge.h.

◆ connection_ap_mark_as_pending_circuit

#define connection_ap_mark_as_pending_circuit (   c)     connection_ap_mark_as_pending_circuit_((c), __FILE__, __LINE__)

Definition at line 143 of file connection_edge.h.

◆ connection_mark_unattached_ap

#define connection_mark_unattached_ap (   conn,
  endreason 
)     connection_mark_unattached_ap_((conn), (endreason), __LINE__, SHORT_FILE__)

Definition at line 76 of file connection_edge.h.

◆ DEFAULT_DNS_TTL

#define DEFAULT_DNS_TTL   (30*60)

How long do we cache/tell clients to cache DNS records when no TTL is known?

Definition at line 201 of file connection_edge.h.

◆ EXIT_CONN_STATE_CONNECTING

#define EXIT_CONN_STATE_CONNECTING   2

State for an exit connection: waiting for connect() to finish.

Definition at line 32 of file connection_edge.h.

◆ EXIT_CONN_STATE_MAX_

#define EXIT_CONN_STATE_MAX_   4

Definition at line 37 of file connection_edge.h.

◆ EXIT_CONN_STATE_MIN_

#define EXIT_CONN_STATE_MIN_   1

Definition at line 28 of file connection_edge.h.

◆ EXIT_CONN_STATE_OPEN

#define EXIT_CONN_STATE_OPEN   3

State for an exit connection: open and ready to transmit data.

Definition at line 34 of file connection_edge.h.

◆ EXIT_CONN_STATE_RESOLVEFAILED

#define EXIT_CONN_STATE_RESOLVEFAILED   4

State for an exit connection: waiting to be removed.

Definition at line 36 of file connection_edge.h.

◆ EXIT_CONN_STATE_RESOLVING

#define EXIT_CONN_STATE_RESOLVING   1

State for an exit connection: waiting for response from DNS farm.

Definition at line 30 of file connection_edge.h.

◆ EXIT_PURPOSE_CONNECT

#define EXIT_PURPOSE_CONNECT   1

This exit stream wants to do an ordinary connect.

Definition at line 66 of file connection_edge.h.

◆ EXIT_PURPOSE_MAX_

#define EXIT_PURPOSE_MAX_   2

Definition at line 69 of file connection_edge.h.

◆ EXIT_PURPOSE_MIN_

#define EXIT_PURPOSE_MIN_   1

Definition at line 64 of file connection_edge.h.

◆ EXIT_PURPOSE_RESOLVE

#define EXIT_PURPOSE_RESOLVE   2

This exit stream wants to do a resolve (either normal or reverse).

Definition at line 68 of file connection_edge.h.

◆ FUZZY_DNS_TTL

#define FUZZY_DNS_TTL   (4*60)

How much should we +- each TTL to make it fuzzy with uniform sampling at exits? The value 4 minutes was chosen so that the lowest possible clip is 60s. Such low clips were used in the past for all TTLs due to a bug in Tor, see "The effect of DNS on Tor's Anonymity" by Greschbach et al. In other words, sampling such low clips is unlikely to cause any breakage at exits.

Definition at line 208 of file connection_edge.h.

◆ half_edge_free

#define half_edge_free (   he)     FREE_AND_NULL(half_edge_t, half_edge_free_, (he))

Definition at line 228 of file connection_edge.h.

◆ MAX_DNS_ENTRY_AGE

#define MAX_DNS_ENTRY_AGE   (3*60*60)

How long do we keep DNS cache entries before purging them (regardless of their TTL)?

Definition at line 198 of file connection_edge.h.

◆ MAX_DNS_TTL

#define MAX_DNS_TTL   (60*60)

Highest value for DNS ttl clipping excluding the random addition.

Definition at line 195 of file connection_edge.h.

◆ MIN_DNS_TTL

#define MIN_DNS_TTL   (5*60)

Lowest value for DNS ttl clipping excluding the random addition.

Definition at line 193 of file connection_edge.h.

Enumeration Type Documentation

◆ hostname_type_t

Possible return values for parse_extended_hostname.

Definition at line 80 of file connection_edge.h.

Function Documentation

◆ address_is_invalid_destination()

int address_is_invalid_destination ( const char *  address,
int  client 
)

Return 1 if address has funny characters in it like colons. Return 0 if it's fine, or if we're configured to allow it anyway. client should be true if we're using this address as a client; false if we're using it as a server.

Definition at line 1082 of file addressmap.c.

Referenced by address_is_invalid_mapaddress_target(), and addressmap_register_auto().

◆ circuit_clear_isolation()

void circuit_clear_isolation ( origin_circuit_t circ)

Clear the isolation settings on circ.

This only works on an open circuit that has never had a stream attached to it, and whose isolation settings are hypothetical. (We set hypothetical isolation settings on circuits as we're launching them, so that we know whether they can handle more streams or whether we need to launch even more circuits. Once the circuit is open, if it turns out that we no longer have any streams to attach to it, we clear the isolation flags and data so that other streams can have a chance.)

Definition at line 4821 of file connection_edge.c.

Referenced by circuit_try_clearing_isolation_state().

◆ circuit_discard_optional_exit_enclaves()

void circuit_discard_optional_exit_enclaves ( extend_info_t info)

A circuit failed to finish on its last hop info. If there are any streams waiting with this exit node in mind, but they don't absolutely require it, make them give up on it.

Definition at line 1558 of file connection_edge.c.

◆ clip_dns_fuzzy_ttl()

uint32_t clip_dns_fuzzy_ttl ( uint32_t  ttl)

Given a TTL (in seconds), determine what TTL an exit relay should use by first clipping as usual and then adding some randomness which is sampled uniformly at random from [-FUZZY_DNS_TTL, FUZZY_DNS_TTL]. This facilitates fuzzy TTLs, which makes it harder to infer when a website was visited via side-channels like DNS (see "Website Fingerprinting with Website Oracles").

Note that this can't underflow because FUZZY_DNS_TTL < MIN_DNS_TTL.

Definition at line 500 of file connection_edge.c.

◆ clip_dns_ttl()

uint32_t clip_dns_ttl ( uint32_t  ttl)

Given a TTL (in seconds) from a DNS response or from a relay, determine what TTL clients and relays should actually use for caching it.

Definition at line 479 of file connection_edge.c.

Referenced by client_dns_set_addressmap_impl(), and clip_dns_fuzzy_ttl().

◆ connection_ap_about_to_close()

void connection_ap_about_to_close ( entry_connection_t entry_conn)

Called when we're about to finally unlink and free an AP (client) connection: perform necessary accounting and cleanup

Definition at line 1095 of file connection_edge.c.

Referenced by connection_about_to_close_connection().

◆ connection_ap_attach_pending()

void connection_ap_attach_pending ( int  retry)

Tell any AP streams that are listed as waiting for a new circuit to try again. If there is an available circuit for a stream, attach it. Otherwise, launch a new circuit.

If retry is false, only check the list if it contains at least one streams that we have not yet tried to attach to a circuit.

Definition at line 1354 of file connection_edge.c.

Referenced by circuit_try_attaching_streams().

◆ connection_ap_can_use_exit()

int connection_ap_can_use_exit ( const entry_connection_t conn,
const node_t exit_node 
)

Return 1 if router exit_node is likely to allow stream conn to exit from it, or 0 if it probably will not allow it. (We might be uncertain if conn's destination address has not yet been resolved.)

Definition at line 4589 of file connection_edge.c.

◆ connection_ap_detach_retriable()

int connection_ap_detach_retriable ( entry_connection_t conn,
origin_circuit_t circ,
int  reason 
)

The AP connection conn has just failed while attaching or sending a BEGIN or resolving on circ, but another circuit might work. Detach the circuit, and either reattach it, launch a new circuit, tell the controller, or give up as appropriate.

Returns -1 on err, 1 on success, 0 on not-yet-sure.

Definition at line 1619 of file connection_edge.c.

◆ connection_ap_expire_beginning()

void connection_ap_expire_beginning ( void  )

Find all general-purpose AP streams waiting for a response that sent their begin/resolve cell too long ago. Detach from their current circuit, and mark their current circuit as unsuitable for new streams. Then call connection_ap_handshake_attach_circuit() to attach to a new circuit (if available) or launch a new one.

For rendezvous streams, simply give up after SocksTimeout seconds (with no retry attempt).

Definition at line 1187 of file connection_edge.c.

Referenced by second_elapsed_callback().

◆ connection_ap_fail_onehop()

void connection_ap_fail_onehop ( const char *  failed_digest,
cpath_build_state_t build_state 
)

Tell any AP streams that are waiting for a one-hop tunnel to failed_digest that they are going to fail.

Definition at line 1517 of file connection_edge.c.

◆ connection_ap_handshake_rewrite_and_attach()

int connection_ap_handshake_rewrite_and_attach ( entry_connection_t conn,
origin_circuit_t circ,
crypt_path_t cpath 
)

Connection conn just finished its socks handshake, or the controller asked us to take care of it. If circ is defined, then that's where we'll want to attach it. Otherwise we have to figure it out ourselves.

First, parse whether it's a .exit address, remap it, and so on. Then if it's for a general circuit, try to attach it to a circuit (or launch one as needed), else if it's for a rendezvous circuit, fetch a rendezvous descriptor first (or attach/launch a circuit if the rendezvous descriptor is already here and fresh enough).

The stream will exit from the hop indicated by cpath, or from the last hop in circ's cpath if cpath is NULL.

Definition at line 2143 of file connection_edge.c.

Referenced by connection_ap_rewrite_and_attach_if_allowed().

◆ connection_ap_handshake_send_begin()

int connection_ap_handshake_send_begin ( entry_connection_t ap_conn)

Write a relay begin cell, using destaddr and destport from ap_conn's socks_request field, and send it down circ.

If ap_conn is broken, mark it for close and return -1. Else return 0.

Definition at line 3239 of file connection_edge.c.

Referenced by connection_ap_handshake_attach_chosen_circuit().

◆ connection_ap_handshake_send_resolve()

int connection_ap_handshake_send_resolve ( entry_connection_t ap_conn)

Write a relay resolve cell, using destaddr and destport from ap_conn's socks_request field, and send it down circ.

If ap_conn is broken, mark it for close and return -1. Else return 0.

Definition at line 3360 of file connection_edge.c.

Referenced by connection_ap_handshake_attach_chosen_circuit().

◆ connection_ap_handshake_socks_reply()

void connection_ap_handshake_socks_reply ( entry_connection_t conn,
char *  reply,
size_t  replylen,
int  endreason 
)

Send a socks reply to stream conn, using the appropriate socks version, etc, and mark conn as completed with SOCKS handshaking.

If reply is defined, then write replylen bytes of it to conn and return, else reply based on endreason (one of END_STREAM_REASON_*). If reply is undefined, endreason can't be 0 or REASON_DONE. Send endreason to the controller, if appropriate.

Definition at line 3708 of file connection_edge.c.

◆ connection_ap_handshake_socks_resolved()

void connection_ap_handshake_socks_resolved ( entry_connection_t conn,
int  answer_type,
size_t  answer_len,
const uint8_t *  answer,
int  ttl,
time_t  expires 
)

Send an answer to an AP connection that has requested a DNS lookup via SOCKS. The type should be one of RESOLVED_TYPE_(IPV4|IPV6|HOSTNAME) or -1 for unreachable; the answer should be in the format specified in the socks extensions document. ttl is the ttl for the answer, or -1 on certain errors or for values that didn't come via DNS. expires is a time when the answer expires, or -1 or TIME_MAX if there's a good TTL.

Definition at line 3595 of file connection_edge.c.

Referenced by connection_ap_handshake_socks_resolved_addr().

◆ connection_ap_handshake_socks_resolved_addr()

void connection_ap_handshake_socks_resolved_addr ( entry_connection_t conn,
const tor_addr_t answer,
int  ttl,
time_t  expires 
)

As connection_ap_handshake_socks_resolved, but take a tor_addr_t to send as the answer.

Definition at line 3557 of file connection_edge.c.

◆ connection_ap_make_link()

entry_connection_t * connection_ap_make_link ( connection_t partner,
char *  address,
uint16_t  port,
const char *  digest,
int  session_group,
int  isolation_flags,
int  use_begindir,
int  want_onehop 
)

Make an AP connection_t linked to the connection_t partner. make a new linked connection pair, and attach one side to the conn, connection_add it, initialize it to circuit_wait, and call connection_ap_handshake_attach_circuit(conn) on it.

Return the newly created end of the linked connection pair, or -1 if error.

Definition at line 3451 of file connection_edge.c.

◆ connection_ap_mark_as_non_pending_circuit()

void connection_ap_mark_as_non_pending_circuit ( entry_connection_t entry_conn)

Mark entry_conn as no longer waiting for a circuit.

Definition at line 1476 of file connection_edge.c.

Referenced by connection_ap_mark_as_waiting_for_renddesc().

◆ connection_ap_mark_as_pending_circuit_()

void connection_ap_mark_as_pending_circuit_ ( entry_connection_t entry_conn,
const char *  fname,
int  lineno 
)

Mark entry_conn as needing to get attached to a circuit.

And entry_conn must be in AP_CONN_STATE_CIRCUIT_WAIT, should not already be pending a circuit. The circuit will get launched or the connection will get attached the next time we call connection_ap_attach_pending().

Definition at line 1432 of file connection_edge.c.

◆ connection_ap_mark_as_waiting_for_renddesc()

void connection_ap_mark_as_waiting_for_renddesc ( entry_connection_t entry_conn)

Mark entry_conn as waiting for a rendezvous descriptor. This function will remove the entry connection from the waiting for a circuit list (pending_entry_connections).

This pattern is used across the code base because a connection in state AP_CONN_STATE_RENDDESC_WAIT must not be in the pending list.

Definition at line 1490 of file connection_edge.c.

◆ connection_ap_process_transparent()

int connection_ap_process_transparent ( entry_connection_t conn)

connection_init_accepted_conn() found a new trans AP conn. Get the original destination and send it to connection_ap_handshake_rewrite_and_attach().

Return -1 if an unexpected error with conn (and it should be marked for close), else return 0.

Definition at line 2882 of file connection_edge.c.

◆ connection_ap_rescan_and_attach_pending()

void connection_ap_rescan_and_attach_pending ( void  )

As connection_ap_attach_pending, but first scans the entire connection array to see if any elements are missing.

Definition at line 1316 of file connection_edge.c.

◆ connection_ap_rewrite_and_attach_if_allowed()

int connection_ap_rewrite_and_attach_if_allowed ( entry_connection_t conn,
origin_circuit_t circ,
crypt_path_t cpath 
)

Call connection_ap_handshake_rewrite_and_attach() unless a controller asked us to leave streams unattached. Return 0 in that case.

See connection_ap_handshake_rewrite_and_attach()'s documentation for arguments and return value.

Definition at line 1781 of file connection_edge.c.

◆ connection_ap_warn_and_unmark_if_pending_circ()

void connection_ap_warn_and_unmark_if_pending_circ ( entry_connection_t entry_conn,
const char *  where 
)

Definition at line 1500 of file connection_edge.c.

◆ connection_edge_compatible_with_circuit()

int connection_edge_compatible_with_circuit ( const entry_connection_t conn,
const origin_circuit_t circ 
)

Return true iff none of the isolation flags and fields in conn should prevent it from being attached to circ.

Definition at line 4673 of file connection_edge.c.

◆ connection_edge_destroy()

int connection_edge_destroy ( circid_t  circ_id,
edge_connection_t conn 
)

This edge needs to be closed, because its circuit has closed. Mark it for close and return 0.

Definition at line 400 of file connection_edge.c.

◆ connection_edge_end()

int connection_edge_end ( edge_connection_t conn,
uint8_t  reason 
)

Send a relay end cell from stream conn down conn's circuit, and remember that we've done so. If this is not a client connection, set the relay end cell's reason for closing as reason.

Return -1 if this function has already been called on this conn, else return 0.

Definition at line 514 of file connection_edge.c.

Referenced by connection_edge_end_close(), and inform_pending_connections().

◆ connection_edge_end_close()

void connection_edge_end_close ( edge_connection_t conn,
uint8_t  reason 
)

Send an END and mark for close the given edge connection conn using the given reason that has to be a stream reason.

Note: We don't unattached the AP connection (if applicable) because we don't want to flush the remaining data. This function aims at ending everything quickly regardless of the connection state.

This function can't fail and does nothing if conn is NULL.

Definition at line 4863 of file connection_edge.c.

◆ connection_edge_end_errno()

int connection_edge_end_errno ( edge_connection_t conn)

An error has just occurred on an operation on an edge connection conn. Extract the errno; convert it to an end reason, and send an appropriate relay end cell to the other end of the connection's circuit.

Definition at line 867 of file connection_edge.c.

◆ connection_edge_finished_connecting()

int connection_edge_finished_connecting ( edge_connection_t edge_conn)

Connected handler for exit connections: start writing pending data, deliver 'CONNECTED' relay cells as appropriate, and check any pending data that may have been received.

Definition at line 1020 of file connection_edge.c.

Referenced by connection_finished_connecting().

◆ connection_edge_finished_flushing()

int connection_edge_finished_flushing ( edge_connection_t conn)

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

If it's in state 'open', stop writing, consider responding with a sendme, and return. Otherwise, stop writing and return.

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

Definition at line 908 of file connection_edge.c.

Referenced by connection_finished_flushing().

◆ connection_edge_flushed_some()

int connection_edge_flushed_some ( edge_connection_t conn)

We just wrote some data to conn; act appropriately.

(That is, if it's open, consider sending a stream-level sendme cell if we have just flushed enough.)

Definition at line 881 of file connection_edge.c.

◆ connection_edge_free_all()

void connection_edge_free_all ( void  )

Free all storage held in module-scoped variables for connection_edge.c

Definition at line 4875 of file connection_edge.c.

◆ connection_edge_is_rendezvous_stream()

int connection_edge_is_rendezvous_stream ( const edge_connection_t conn)

Return 1 if conn is a rendezvous stream, or 0 if it is a general stream.

Definition at line 4573 of file connection_edge.c.

Referenced by ap_stream_wants_exit_attention(), connection_exit_connect(), hs_client_note_connection_attempt_succeeded(), and write_stream_target_to_buf().

◆ connection_edge_process_inbuf()

int connection_edge_process_inbuf ( edge_connection_t conn,
int  package_partial 
)

Handle new bytes on conn->inbuf based on state:

  • If it's waiting for socks info, try to read another step of the socks handshake out of conn->inbuf.
  • If it's waiting for the original destination, fetch it.
  • If it's open, then package more relay cells from the stream.
  • Else, leave the bytes on inbuf alone for now.

Mark and return -1 if there was an unexpected error with the conn, else return 0.

Definition at line 326 of file connection_edge.c.

Referenced by connection_process_inbuf().

◆ connection_edge_reached_eof()

int connection_edge_reached_eof ( edge_connection_t conn)

There was an EOF. Send an end and mark the connection for close.

Definition at line 292 of file connection_edge.c.

Referenced by connection_reached_eof().

◆ connection_edge_update_circuit_isolation()

int connection_edge_update_circuit_isolation ( const entry_connection_t conn,
origin_circuit_t circ,
int  dry_run 
)

If dry_run is false, update circ's isolation flags and fields to reflect having had conn attached to it, and return 0. Otherwise, if dry_run is true, then make no changes to circ, and return a bitfield of isolation flags that we would have to set in isolation_flags_mixed to add conn to circ, or -1 if circ has had no streams attached to it.

Definition at line 4743 of file connection_edge.c.

◆ connection_entry_set_controller_wait()

void connection_entry_set_controller_wait ( entry_connection_t conn)

Set the connection state to CONTROLLER_WAIT and send an control port event.

Definition at line 1604 of file connection_edge.c.

Referenced by connection_ap_rewrite_and_attach_if_allowed().

◆ connection_exit_about_to_close()

void connection_exit_about_to_close ( edge_connection_t edge_conn)

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

Definition at line 1146 of file connection_edge.c.

Referenced by connection_about_to_close_connection().

◆ connection_exit_begin_conn()

int connection_exit_begin_conn ( cell_t cell,
circuit_t circ 
)

A relay 'begin' or 'begin_dir' cell has arrived, and either we are an exit hop for the circuit, or we are the origin and it is a rendezvous begin.

Launch a new exit connection and initialize things appropriately.

If it's a rendezvous stream, call connection_exit_connect() on it.

For general streams, call dns_resolve() on it first, and only call connection_exit_connect() if the dns answer is already known.

Note that we don't call connection_add() on the new stream! We wait for connection_exit_connect() to do that.

Return -(some circuit end reason) if we want to tear down circ. Else return 0.

Definition at line 3981 of file connection_edge.c.

◆ connection_exit_begin_resolve()

int connection_exit_begin_resolve ( cell_t cell,
or_circuit_t circ 
)

Called when we receive a RELAY_COMMAND_RESOLVE cell 'cell' along the circuit circ; begin resolving the hostname, and (eventually) reply with a RESOLVED cell.

Return -(some circuit end reason) if we want to tear down circ. Else return 0.

Definition at line 4199 of file connection_edge.c.

◆ connection_exit_connect()

void connection_exit_connect ( edge_connection_t edge_conn)

Connect to conn's specified addr and port. If it worked, conn has now been added to the connection_array.

Send back a connected cell. Include the resolved IP of the destination address, but only if it's a general exit stream. (Rendezvous streams must not reveal what IP they connected to.)

Definition at line 4365 of file connection_edge.c.

◆ connection_half_edge_is_valid_connected()

int connection_half_edge_is_valid_connected ( const smartlist_t half_conns,
streamid_t  stream_id 
)

Check if this stream_id is in a half-closed state. If so, check if it still has a connected cell pending, and decrement that window if so.

Return 1 if the connected window was not empty. Return 0 otherwise.

Definition at line 774 of file connection_edge.c.

◆ connection_half_edge_is_valid_data()

int connection_half_edge_is_valid_data ( const smartlist_t half_conns,
streamid_t  stream_id 
)

Check if this stream_id is in a half-closed state. If so, check if it still has data cells pending, and decrement that window if so.

Return 1 if the data window was not empty. Return 0 otherwise.

Definition at line 742 of file connection_edge.c.

◆ connection_half_edge_is_valid_end()

int connection_half_edge_is_valid_end ( smartlist_t half_conns,
streamid_t  stream_id 
)

Check if this stream_id is in a half-closed state. If so, remove it from the list. No other data should come after the END cell.

Return 1 if stream_id was in half-closed state. Return 0 otherwise.

Definition at line 829 of file connection_edge.c.

Referenced by connection_half_edge_is_valid_resolved().

◆ connection_half_edge_is_valid_resolved()

int connection_half_edge_is_valid_resolved ( smartlist_t half_conns,
streamid_t  stream_id 
)

Streams that were used to send a RESOLVE cell are closed when they get the RESOLVED, without an end. So treat a RESOLVED just like an end, and remove from the list.

Definition at line 856 of file connection_edge.c.

◆ connection_half_edge_is_valid_sendme()

int connection_half_edge_is_valid_sendme ( const smartlist_t half_conns,
streamid_t  stream_id 
)

Check if this stream_id is in a half-closed state. If so, check if it still has sendme cells pending, and decrement that window if so.

Return 1 if the sendme window was not empty. Return 0 otherwise.

Definition at line 800 of file connection_edge.c.

◆ connection_half_edges_waiting()

bool connection_half_edges_waiting ( const origin_circuit_t circ)

Return true if the circuit has any half-closed connections that are still within the end_ack_expected_usec timestamp from now.

Definition at line 686 of file connection_edge.c.

Referenced by circuit_expire_old_circuits_clientside().

◆ connection_mark_unattached_ap_()

void connection_mark_unattached_ap_ ( entry_connection_t conn,
int  endreason,
int  line,
const char *  file 
)

An AP stream has failed/finished. If it hasn't already sent back a socks reply, send one now (based on endreason). Also set has_sent_end to 1, and mark the conn.

Definition at line 256 of file connection_edge.c.

◆ connection_reapply_exit_policy()

void connection_reapply_exit_policy ( config_line_t changes)

Definition at line 4283 of file connection_edge.c.

◆ CONST_EDGE_TO_ENTRY_CONN()

const entry_connection_t * CONST_EDGE_TO_ENTRY_CONN ( const edge_connection_t c)

Cast a const edge_connection_t * to a const entry_connection_t *.

Exit with an assertion failure if the input is not an entry_connection_t.

Definition at line 245 of file connection_edge.c.

◆ CONST_TO_EDGE_CONN()

const edge_connection_t * CONST_TO_EDGE_CONN ( const connection_t c)

Cast a const connection_t * to a const edge_connection_t *.

Exit with an assertion failure if the input is not an edge_connection_t.

Definition at line 195 of file connection_edge.c.

◆ CONST_TO_ENTRY_CONN()

const entry_connection_t * CONST_TO_ENTRY_CONN ( const connection_t c)

Cast a const connection_t * to a const entry_connection_t *.

Exit with an assertion failure if the input is not an entry_connection_t.

Definition at line 220 of file connection_edge.c.

◆ EDGE_TO_ENTRY_CONN()

entry_connection_t * EDGE_TO_ENTRY_CONN ( edge_connection_t c)

◆ get_unique_stream_id_by_circ()

streamid_t get_unique_stream_id_by_circ ( origin_circuit_t circ)

Iterate over the two bytes of stream_id until we get one that is not already in use; return it. Return 0 if can't get a unique stream_id.

Definition at line 3121 of file connection_edge.c.

◆ half_edge_free_()

void half_edge_free_ ( half_edge_t he)

Release space held by he

Definition at line 701 of file connection_edge.c.

◆ half_streams_get_total_allocation()

size_t half_streams_get_total_allocation ( void  )

Return the number of bytes devoted to storing info on half-open streams.

Definition at line 711 of file connection_edge.c.

◆ TO_EDGE_CONN()

edge_connection_t * TO_EDGE_CONN ( connection_t c)

◆ TO_ENTRY_CONN()

entry_connection_t * TO_ENTRY_CONN ( connection_t c)