#include <or.h>
Data Fields | |
uint32_t | magic |
uint8_t | state |
unsigned int | type:4 |
unsigned int | purpose:5 |
unsigned int | read_blocked_on_bw:1 |
unsigned int | write_blocked_on_bw:1 |
unsigned int | hold_open_until_flushed:1 |
unsigned int | inbuf_reached_eof:1 |
unsigned int | in_flushed_some:1 |
unsigned int | linked:1 |
unsigned int | reading_from_linked_conn:1 |
unsigned int | writing_to_linked_conn:1 |
unsigned int | active_on_link:1 |
unsigned int | linked_conn_is_closed:1 |
unsigned int | proxy_state:4 |
evutil_socket_t | s |
int | conn_array_index |
struct event * | read_event |
struct event * | write_event |
buf_t * | inbuf |
buf_t * | outbuf |
size_t | outbuf_flushlen |
time_t | timestamp_lastread |
time_t | timestamp_lastwritten |
time_t | timestamp_created |
int | socket_family |
tor_addr_t | addr |
uint16_t | port |
uint16_t | marked_for_close |
const char * | marked_for_close_file |
char * | address |
struct connection_t * | linked_conn |
uint64_t | global_identifier |
struct evdns_server_port * | dns_server_port |
uint64_t | dirreq_id |
A connection is named based on what it's connected to -- an "OR connection" has a Tor node on the other end, an "exit connection" has a website or other server on the other end, and an "AP connection" has an application proxy (and thus a user) on the other end.
Every connection has a type and a state. Connections never change their type, but can go through many state changes in their lifetime.
Every connection has two associated input and output buffers. Listeners don't use them. For non-listener connections, incoming data is appended to conn->inbuf, and outgoing data is taken from conn->outbuf. Connections differ primarily in the functions called to fill and drain these buffers.
uint32_t connection_t::magic |
For memory debugging: must equal one of *_CONNECTION_MAGIC.
Referenced by _connection_free(), assert_connection_ok(), connection_init(), connection_or_get_for_extend(), HT_HEAD(), TO_CONTROL_CONN(), TO_DIR_CONN(), TO_EDGE_CONN(), and TO_OR_CONN().
uint8_t connection_t::state |
Current state of this connection.
Referenced by _connection_free(), ap_stream_wants_exit_attention(), assert_connection_ok(), assign_onionskin_to_cpuworker(), circuit_get_open_circ_or_launch(), command_process_cell(), command_process_netinfo_cell(), command_process_var_cell(), command_process_versions_cell(), conn_close_if_marked(), connection_about_to_close_connection(), connection_ap_detach_retriable(), connection_ap_expire_beginning(), connection_ap_handshake_attach_chosen_circuit(), connection_ap_handshake_attach_circuit(), connection_ap_handshake_process_socks(), connection_ap_handshake_send_begin(), connection_ap_handshake_send_resolve(), connection_ap_make_link(), connection_ap_process_natd(), connection_ap_process_transparent(), connection_bucket_read_limit(), connection_bucket_should_increase(), connection_bucket_write_limit(), connection_buckets_decrement(), connection_close_immediate(), connection_consider_empty_read_buckets(), connection_consider_empty_write_buckets(), connection_control_process_inbuf(), connection_cpu_process_inbuf(), connection_cpu_reached_eof(), connection_create_listener(), connection_dir_finished_connecting(), connection_dir_finished_flushing(), connection_dir_process_inbuf(), connection_dir_reached_eof(), connection_dirserv_flushed_some(), connection_dns_remove(), connection_edge_finished_connecting(), connection_edge_finished_flushing(), connection_edge_process_inbuf(), connection_edge_process_relay_cell_not_open(), connection_exit_begin_conn(), connection_exit_begin_resolve(), connection_exit_connect(), connection_exit_connect_dir(), connection_flushed_some(), connection_handle_read_impl(), connection_handle_write_impl(), connection_init_accepted_conn(), connection_or_connect(), connection_or_finished_connecting(), connection_or_finished_flushing(), connection_or_get_for_extend(), connection_or_group_set_badness(), connection_or_process_inbuf(), connection_or_set_state_open(), connection_read_to_buf(), connection_state_is_connecting(), connection_state_is_open(), connection_tls_continue_handshake(), connection_tls_finish_handshake(), connection_tls_start_handshake(), directory_handle_command_get(), directory_handle_command_post(), directory_initiate_command_rend(), dns_cancel_pending_resolve(), dns_found_answer(), dns_resolve(), dnsserv_launch_request(), evdns_server_callback(), getinfo_helper_events(), handle_control_attachstream(), handle_control_authenticate(), is_valid_initial_command(), rend_client_desc_trynow(), rend_client_remove_intro_point(), run_connection_housekeeping(), and spawn_cpuworker().
unsigned int connection_t::type |
What kind of connection is this?
Referenced by _connection_free(), _connection_mark_unattached_ap(), _connection_write_to_buf_impl(), ap_stream_wants_exit_attention(), assert_circuit_ok(), assert_connection_ok(), check_sockaddr_family_match(), circuit_dump_by_conn(), conn_close_if_marked(), conn_read_callback(), conn_write_callback(), connection_about_to_close_connection(), connection_add(), connection_ap_can_use_exit(), connection_ap_handshake_process_socks(), connection_ap_handshake_send_begin(), connection_ap_handshake_send_resolve(), connection_ap_process_natd(), connection_ap_process_transparent(), connection_bucket_read_limit(), connection_bucket_write_limit(), connection_buckets_decrement(), connection_close_immediate(), connection_counts_as_relayed_traffic(), connection_cpu_finished_flushing(), connection_cpu_process_inbuf(), connection_dir_finished_connecting(), connection_dir_finished_flushing(), connection_dir_process_inbuf(), connection_dns_remove(), connection_edge_destroy(), connection_edge_finished_connecting(), connection_edge_process_inbuf(), connection_edge_process_relay_cell_not_open(), connection_edge_send_command(), connection_exit_connect_dir(), connection_finished_connecting(), connection_finished_flushing(), connection_flushed_some(), connection_free(), connection_handle_listener_read(), connection_handle_read_impl(), connection_handle_write_impl(), connection_init(), connection_init_accepted_conn(), connection_is_listener(), connection_or_get_for_extend(), connection_or_nonopen_was_started_here(), connection_process_inbuf(), connection_reached_eof(), connection_read_to_buf(), connection_remove(), connection_state_is_connecting(), connection_state_is_open(), connection_unlink(), control_event_stream_status(), directory_handle_command(), directory_send_command(), dnsserv_close_listener(), dnsserv_configure_listener(), get_stream(), hibernate_begin(), hibernate_go_dormant(), retry_listeners(), and run_connection_housekeeping().
unsigned int connection_t::purpose |
Only used for DIR and EXIT types currently.
Referenced by assert_connection_ok(), conn_close_if_marked(), connection_about_to_close_connection(), connection_dir_client_reached_eof(), connection_dir_download_cert_failed(), connection_dir_download_networkstatus_failed(), connection_dir_download_routerdesc_failed(), connection_dir_request_failed(), connection_edge_process_relay_cell_not_open(), connection_exit_begin_conn(), connection_exit_begin_resolve(), connection_exit_connect_dir(), connection_init_accepted_conn(), control_event_stream_status(), directory_initiate_command_rend(), dns_found_answer(), dns_resolve(), and run_connection_housekeeping().
unsigned int connection_t::read_blocked_on_bw |
Boolean: should we start reading again once the bandwidth throttler allows it?
Referenced by connection_consider_empty_read_buckets().
unsigned int connection_t::write_blocked_on_bw |
Boolean: should we start writing again once the bandwidth throttler allows writes?
Referenced by assert_connection_ok(), connection_consider_empty_write_buckets(), and connection_handle_write_impl().
unsigned int connection_t::hold_open_until_flushed |
Despite this connection's being marked for close, do we flush it before closing it?
Referenced by _connection_mark_unattached_ap(), _connection_write_to_buf_impl(), assert_connection_ok(), conn_close_if_marked(), connection_about_to_close_connection(), connection_control_process_inbuf(), connection_edge_destroy(), connection_edge_process_relay_cell(), and run_connection_housekeeping().
unsigned int connection_t::inbuf_reached_eof |
Boolean: did read() return 0 on this conn?
Referenced by connection_dir_process_inbuf(), connection_handle_read_impl(), and connection_read_to_buf().
unsigned int connection_t::in_flushed_some |
Set to 1 when we're inside connection_flushed_some to keep us from calling connection_handle_write() recursively.
Referenced by _connection_write_to_buf_impl(), connection_flushed_some(), and connection_handle_write_impl().
unsigned int connection_t::linked |
True if there is, or has been, a linked_conn.
Referenced by _connection_free(), assert_connection_ok(), connection_add(), connection_ap_make_link(), connection_close_immediate(), connection_is_rate_limited(), connection_link_connections(), connection_read_to_buf(), connection_should_read_from_linked_conn(), connection_start_reading(), connection_start_reading_from_linked_conn(), connection_start_writing(), connection_stop_reading(), connection_stop_reading_from_linked_conn(), and connection_stop_writing().
unsigned int connection_t::reading_from_linked_conn |
True iff we'd like to be notified about read events from the linked conn.
Referenced by connection_free(), connection_is_reading(), connection_should_read_from_linked_conn(), connection_start_reading(), connection_stop_reading(), and connection_unlink().
unsigned int connection_t::writing_to_linked_conn |
True iff we're willing to write to the linked conn.
Referenced by connection_is_writing(), connection_should_read_from_linked_conn(), connection_start_writing(), and connection_stop_writing().
unsigned int connection_t::active_on_link |
True iff we're currently able to read on the linked conn, and our read_event should be made active with libevent.
Referenced by connection_handle_read_impl(), connection_start_reading_from_linked_conn(), and connection_stop_reading_from_linked_conn().
unsigned int connection_t::linked_conn_is_closed |
True iff we've called connection_close_immediate() on this linked connection.
Referenced by connection_close_immediate().
unsigned int connection_t::proxy_state |
CONNECT/SOCKS proxy client handshake state (for outgoing connections).
Referenced by connection_proxy_connect(), connection_read_proxy_handshake(), and connection_send_socks5_connect().
evutil_socket_t connection_t::s |
Our socket; -1 if this connection is closed, or has no socket.
Referenced by _connection_free(), _connection_write_to_buf_impl(), assert_all_pending_dns_resolves_ok(), assert_connection_ok(), conn_close_if_marked(), conn_read_callback(), conn_write_callback(), connection_add(), connection_ap_get_original_destination(), connection_ap_handshake_send_begin(), connection_ap_handshake_send_resolve(), connection_close_immediate(), connection_connect(), connection_create_listener(), connection_dns_remove(), connection_edge_end(), connection_edge_end_errno(), connection_edge_package_raw_inbuf(), connection_edge_process_relay_cell(), connection_edge_reached_eof(), connection_handle_listener_read(), connection_handle_write_impl(), connection_init(), connection_link_connections(), connection_or_group_set_badness(), connection_or_process_cells_from_inbuf(), connection_read_to_buf(), connection_remove(), connection_start_reading(), connection_start_writing(), connection_stop_reading(), connection_stop_writing(), connection_tls_start_handshake(), connection_unregister_events(), dns_cancel_pending_resolve(), dns_resolve_impl(), dnsserv_configure_listener(), handle_control_authenticate(), purge_expired_resolves(), run_connection_housekeeping(), and spawn_cpuworker().
Index into the global connection array.
Referenced by circuit_dump_by_conn(), close_closeable_connections(), connection_add(), connection_init(), connection_remove(), and connection_unlink().
struct event* connection_t::read_event [read] |
Libevent event structure.
Referenced by _connection_free(), connection_add(), connection_is_reading(), connection_start_reading(), connection_stop_reading(), connection_unregister_events(), and set_streams_blocked_on_circ().
struct event* connection_t::write_event [read] |
Libevent event structure.
Referenced by _connection_free(), connection_add(), connection_is_writing(), connection_start_writing(), connection_stop_writing(), and connection_unregister_events().
Buffer holding data read over this connection.
Referenced by _connection_free(), assert_connection_ok(), conn_close_if_marked(), connection_ap_handshake_process_socks(), connection_ap_process_natd(), connection_control_process_inbuf(), connection_cpu_process_inbuf(), connection_dir_client_reached_eof(), connection_dir_process_inbuf(), connection_edge_package_raw_inbuf(), connection_edge_reached_eof(), connection_fetch_from_buf(), connection_fetch_var_cell_from_buf(), connection_handle_read_impl(), connection_init(), connection_or_process_cells_from_inbuf(), connection_read_https_proxy_response(), connection_read_proxy_handshake(), connection_read_to_buf(), directory_handle_command(), and run_connection_housekeeping().
Buffer holding data to write over this connection.
Referenced by _connection_free(), _connection_write_to_buf_impl(), append_cell_to_circuit_queue(), assert_connection_ok(), conn_close_if_marked(), connection_close_immediate(), connection_dirserv_add_dir_bytes_to_outbuf(), connection_dirserv_add_microdescs_to_outbuf(), connection_dirserv_add_networkstatus_bytes_to_outbuf(), connection_dirserv_add_servers_to_outbuf(), connection_dirserv_flushed_some(), connection_handle_read_impl(), connection_handle_write_impl(), connection_init(), connection_or_flushed_some(), connection_read_to_buf(), connection_should_read_from_linked_conn(), and run_connection_housekeeping().
How much data should we try to flush from the outbuf?
Referenced by _connection_write_to_buf_impl(), assert_connection_ok(), conn_close_if_marked(), connection_bucket_write_limit(), connection_close_immediate(), connection_edge_consider_sending_sendme(), connection_handle_write_impl(), connection_outbuf_too_full(), connection_read_to_buf(), and connection_wants_to_flush().
When was the last time libevent said we could read?
Referenced by connection_ap_detach_retriable(), connection_ap_expire_beginning(), connection_edge_process_relay_cell_not_open(), connection_handle_read_impl(), connection_init(), link_apconn_to_circ(), rend_client_desc_trynow(), and run_connection_housekeeping().
When was the last time libevent said we could write?
Referenced by _connection_mark_for_close(), assign_onionskin_to_cpuworker(), conn_close_if_marked(), connection_dir_client_reached_eof(), connection_handle_write_impl(), connection_init(), rend_client_desc_trynow(), and run_connection_housekeeping().
When was this connection_t created?
Referenced by command_process_create_cell(), connection_ap_expire_beginning(), connection_ap_handshake_attach_circuit(), connection_cpu_process_inbuf(), connection_init(), connection_or_group_set_badness(), connection_or_is_better(), and rend_client_desc_trynow().
Address family of this connection's socket. Usually AF_INET, but it can also be AF_UNIX, or in the future AF_INET6
Referenced by _connection_free(), check_sockaddr_family_match(), connection_create_listener(), connection_handle_listener_read(), connection_init(), and retry_listeners().
IP of the other side of the connection; used to identify routers, along with port.
Referenced by circuit_dump_by_conn(), circuit_get_all_pending_on_or_conn(), circuit_n_conn_done(), connection_ap_expire_beginning(), connection_ap_get_original_destination(), connection_ap_handshake_attach_circuit(), connection_ap_make_link(), connection_edge_end(), connection_edge_finished_connecting(), connection_exit_begin_conn(), connection_exit_connect(), connection_exit_connect_dir(), connection_handle_listener_read(), connection_is_rate_limited(), connection_or_init_conn_from_address(), connection_or_send_netinfo(), connection_proxy_connect(), connection_send_socks5_connect(), connection_tls_finish_handshake(), directory_conn_is_self_reachability_test(), directory_handle_command_get(), directory_initiate_command_rend(), dns_found_answer(), dns_resolve_impl(), onionskin_answer(), router_compare_to_my_exit_policy(), router_new_address_suggestion(), send_resolved_cell(), and write_http_response_header_impl().
uint16_t connection_t::port |
If non-zero, port on the other end of the connection.
Referenced by circuit_build_failed(), circuit_dump_by_conn(), circuit_expire_building(), circuit_extend(), circuit_get_all_pending_on_or_conn(), circuit_n_conn_done(), command_process_create_cell(), command_process_destroy_cell(), command_process_netinfo_cell(), command_process_relay_cell(), command_process_versions_cell(), connection_ap_expire_beginning(), connection_ap_get_original_destination(), connection_ap_handshake_attach_circuit(), connection_ap_make_link(), connection_buckets_decrement(), connection_create_listener(), connection_dir_client_reached_eof(), connection_dir_finished_connecting(), connection_edge_finished_connecting(), connection_exit_begin_conn(), connection_exit_begin_resolve(), connection_exit_connect(), connection_exit_connect_dir(), connection_handle_listener_read(), connection_or_check_valid_tls_handshake(), connection_or_finished_connecting(), connection_or_group_set_badness(), connection_or_init_conn_from_address(), connection_proxy_connect(), connection_read_proxy_handshake(), connection_send_socks5_connect(), connection_tls_finish_handshake(), directory_conn_is_self_reachability_test(), directory_initiate_command_rend(), directory_send_command(), orconn_target_get_name(), rend_service_set_connection_addr_port(), retry_listeners(), router_compare_to_my_exit_policy(), and run_connection_housekeeping().
uint16_t connection_t::marked_for_close |
Should we close this conn on the next iteration of the main loop? (If true, holds the line number where this connection was marked.)
Referenced by _circuit_mark_for_close(), _connection_mark_for_close(), _connection_mark_unattached_ap(), _connection_write_to_buf_impl(), add_connection_to_closeable_list(), ap_stream_wants_exit_attention(), assert_connection_ok(), circuit_resume_edge_reading_helper(), conn_close_if_marked(), conn_read_callback(), conn_write_callback(), connection_about_to_close_connection(), connection_ap_attach_pending(), connection_ap_expire_beginning(), connection_ap_make_link(), connection_ap_process_end_not_open(), connection_cpu_process_inbuf(), connection_edge_destroy(), connection_edge_end(), connection_edge_package_raw_inbuf(), connection_edge_process_relay_cell(), connection_edge_reached_eof(), connection_edge_send_command(), connection_exit_begin_resolve(), connection_free(), connection_handle_read_impl(), connection_handle_write_impl(), connection_or_get_for_extend(), connection_or_group_set_badness(), connection_read_to_buf(), connection_state_is_connecting(), connection_state_is_open(), connection_unlink(), dns_cancel_pending_resolve(), dns_resolve(), get_stream(), relay_lookup_conn(), rend_client_desc_trynow(), retry_listeners(), and run_connection_housekeeping().
const char* connection_t::marked_for_close_file |
For debugging: in which file were we marked for close?
Referenced by _connection_mark_for_close(), conn_close_if_marked(), connection_about_to_close_connection(), connection_edge_end(), connection_edge_package_raw_inbuf(), and connection_edge_send_command().
char* connection_t::address |
FQDN (or IP) of the guy on the other end. strdup into this, because free_connection() frees it.
Referenced by _connection_free(), assert_connection_edge_not_dns_pending(), assert_connection_ok(), circuit_build_failed(), circuit_expire_building(), circuit_extend(), circuit_n_conn_done(), command_process_create_cell(), command_process_destroy_cell(), command_process_netinfo_cell(), command_process_relay_cell(), command_process_versions_cell(), conn_close_if_marked(), connection_add(), connection_ap_handshake_send_resolve(), connection_ap_make_link(), connection_create_listener(), connection_dir_client_reached_eof(), connection_dir_finished_connecting(), connection_dir_request_failed(), connection_dns_remove(), connection_edge_finished_connecting(), connection_exit_begin_conn(), connection_exit_begin_resolve(), connection_exit_connect(), connection_exit_connect_dir(), connection_handle_listener_read(), connection_or_check_valid_tls_handshake(), connection_or_connect(), connection_or_finished_connecting(), connection_or_group_set_badness(), connection_or_init_conn_from_address(), connection_read_https_proxy_response(), connection_read_proxy_handshake(), connection_read_to_buf(), connection_tls_finish_handshake(), connection_tls_start_handshake(), directory_handle_command(), directory_handle_command_post(), directory_initiate_command_rend(), directory_send_command(), dns_resolve(), dns_resolve_impl(), http_set_address_origin(), launch_resolve(), orconn_target_get_name(), retry_listeners(), router_new_address_suggestion(), run_connection_housekeeping(), spawn_cpuworker(), and write_http_response_header_impl().
struct connection_t* connection_t::linked_conn [read] |
Another connection that's connected to this one in lieu of a socket.
Referenced by assert_connection_ok(), conn_close_if_marked(), connection_free(), connection_handle_read_impl(), connection_link_connections(), connection_read_to_buf(), connection_should_read_from_linked_conn(), connection_start_writing(), connection_stop_writing(), and connection_unlink().
uint64_t connection_t::global_identifier |
Unique identifier for this connection on this Tor instance.
Referenced by assign_onionskin_to_cpuworker(), connection_init(), control_event_stream_bandwidth(), control_event_stream_bandwidth_used(), control_event_stream_status(), and getinfo_helper_events().
struct evdns_server_port* connection_t::dns_server_port [read] |
If the connection is a CONN_TYPE_AP_DNS_LISTENER, this field points to the evdns_server_port is uses to listen to and answer connections.
Referenced by connection_unregister_events(), dnsserv_close_listener(), and dnsserv_configure_listener().
uint64_t connection_t::dirreq_id |
Unique ID for measuring tunneled network status requests.
Referenced by connection_handle_write_impl().