31 #define CHANNEL_OBJECT_PRIVATE
32 #define CONNECTION_OR_PRIVATE
33 #define ORCONN_EVENT_PRIVATE
50 #include "trunnel/netinfo.h"
67 #include "core/or/channelpadding.h"
90 char *digest_rcvd_out);
96 static void connection_or_mark_bad_for_new_circs(
or_connection_t *or_conn);
143 connection_or_clear_identity(TO_OR_CONN(conn));
159 const char *rsa_digest,
167 chan = TLS_CHAN_TO_BASE(conn->
chan);
169 log_info(
LD_HANDSHAKE,
"Set identity digest for %s at %p: %s %s.",
179 const int ed_id_was_set =
181 const int rsa_changed =
183 const int ed_changed = ed_id_was_set &&
189 if (!rsa_changed && !ed_changed)
193 if (rsa_id_was_set) {
220 if (conn && conn->
chan) {
222 chan = TLS_CHAN_TO_BASE(conn->
chan);
279 char *buf,
size_t buflen)
282 const char *conn_state;
290 tor_snprintf(buf, buflen,
"%s with SSL state %s", conn_state, tls_state);
302 log_info(
LD_HANDSHAKE,
"Connection died in state '%s'", buf);
317 if (b->count < a->count)
319 else if (b->count == a->count)
327 #define MAX_REASONS_TO_REPORT 10
343 c->count = (intptr_t)countptr;
344 total += (int)c->count;
347 } STRMAP_FOREACH_END;
351 tor_log(severity, domain,
"%d connections have failed%s", total,
358 " %d connections died in state %s", (
int)c->count, c->state);
359 } SMARTLIST_FOREACH_END(c);
362 smartlist_free(items);
380 orconn_status_publish(msg);
400 tor_assert_nonfatal(conn->
proxy_type != PROXY_NONE);
407 msg->
chan = TLS_CHAN_TO_BASE(conn->
chan)->global_identifier;
411 orconn_state_publish(msg);
423 conn->base_.
state = state;
456 char *dest = dst->
body;
513 size_t size = offsetof(
var_cell_t, payload) + payload_len;
533 copy = tor_malloc_zero(size);
556 log_info(
LD_OR,
"OR connection reached EOF. Closing.");
573 switch (conn->base_.
state) {
581 log_fn(LOG_PROTOCOL_WARN,
LD_NET,
"Found leftover (%d bytes) "
582 "when transitioning from PROXY_HANDSHAKING state on %s: "
614 log_fn(LOG_PROTOCOL_WARN,
LD_NET,
"Accumulated data (%d bytes) "
615 "on non-open %s; closing.",
638 datalen = connection_get_outbuf_len(
TO_CONN(conn));
652 size_t datalen, cell_network_size;
662 datalen = connection_get_outbuf_len(
TO_CONN(conn));
664 cell_network_size = get_cell_network_size(conn->wide_circ_ids);
685 switch (conn->base_.
state) {
695 TO_CONN(conn)->proxy_state = PROXY_CONNECTED;
710 log_err(
LD_BUG,
"Called in unexpected state %d.", conn->base_.
state);
737 if (proxy_type != PROXY_NONE) {
772 or_conn->
chan->conn = NULL;
773 or_conn->
chan = NULL;
789 const char *warning = NULL;
790 if (reason == END_OR_CONN_REASON_TLS_ERROR && or_conn->
tls) {
793 if (warning == NULL) {
871 if (connection_speaks_cells(conn))
892 TLS_CHAN_TO_BASE(or_conn->
chan), is_canonical);
895 "Channel %"PRIu64
" chose an idle timeout of %d.",
897 (TLS_CHAN_TO_BASE(or_conn->
chan)->global_identifier):0,
909 const char *id_digest,
913 log_debug(
LD_HANDSHAKE,
"init conn from address %s: %s, %s (%d)",
922 conn->base_.
port = port;
943 ed_id = & TLS_CHAN_TO_BASE(conn->
chan)->ed25519_identity;
961 connection_or_set_canonical(conn, 1);
966 node_ap = &node_ipv4_ap;
968 node_ap = &node_ipv6_ap;
1017 #define TIME_BEFORE_OR_CONN_IS_TOO_OLD (60*60*24*7)
1039 "Marking %s as too old for new circuits "
1040 "(fd "TOR_SOCKET_T_FORMAT
", %d secs old).",
1044 connection_or_mark_bad_for_new_circs(or_conn);
1074 int n_old = 0, n_inprogress = 0, n_canonical = 0, n_other = 0;
1075 time_t now = time(NULL);
1092 } SMARTLIST_FOREACH_END(or_conn);
1107 "Marking %s unsuitable for new circuits: "
1108 "(fd "TOR_SOCKET_T_FORMAT
", %d secs old). It is not "
1109 "canonical, and we have another connection to that OR that is.",
1113 connection_or_mark_bad_for_new_circs(or_conn);
1119 TLS_CHAN_TO_BASE(best->
chan))) {
1122 } SMARTLIST_FOREACH_END(or_conn);
1146 if (or_conn != best &&
1148 TLS_CHAN_TO_BASE(or_conn->
chan))) {
1152 "Marking %s as unsuitable for new circuits: "
1153 "(fd "TOR_SOCKET_T_FORMAT
", %d secs old). "
1154 "We have a better canonical one "
1155 "(fd "TOR_SOCKET_T_FORMAT
"; %d secs old).",
1160 connection_or_mark_bad_for_new_circs(or_conn);
1164 "Marking %s unsuitable for new circuits: "
1165 "(fd "TOR_SOCKET_T_FORMAT
", %d secs old). We have a better "
1167 "same address (fd "TOR_SOCKET_T_FORMAT
"; %d secs old).",
1172 connection_or_mark_bad_for_new_circs(or_conn);
1175 } SMARTLIST_FOREACH_END(or_conn);
1180 #define OR_CONNECT_FAILURE_LIFETIME 60
1182 #define OR_CONNECT_FAILURE_CLEANUP_INTERVAL 60
1186 static time_t or_connect_failure_map_next_cleanup_ts = 0;
1209 time_t last_failed_connect_ts;
1215 or_connect_failures_map = HT_INITIALIZER();
1232 size_t offset = 0, addr_size;
1233 const void *addr_ptr;
1235 uint8_t data[16 +
sizeof(uint16_t) +
DIGEST_LEN];
1241 addr_ptr = &entry->addr.addr.in_addr.s_addr;
1245 addr_ptr = &entry->addr.addr.in6_addr.s6_addr;
1252 memcpy(data, addr_ptr, addr_size);
1253 offset += addr_size;
1254 memcpy(data + offset, entry->identity_digest,
DIGEST_LEN);
1257 offset +=
sizeof(uint16_t);
1259 return (
unsigned int) siphash24g(data, offset);
1263 or_connect_failure_ht_hash, or_connect_failure_ht_eq);
1266 or_connect_failure_ht_hash, or_connect_failure_ht_eq,
1272 or_connect_failure_init(
const char *identity_digest,
const tor_addr_t *addr,
1276 if (identity_digest) {
1277 memcpy(ocf->identity_digest, identity_digest,
1278 sizeof(ocf->identity_digest));
1305 TO_CONN(or_conn)->port, &lookup);
1306 return HT_FIND(or_connect_failure_ht, &or_connect_failures_map, &lookup);
1318 ocf = or_connect_failure_find(or_conn);
1320 ocf = or_connect_failure_new(or_conn);
1321 HT_INSERT(or_connect_failure_ht, &or_connect_failures_map, ocf);
1329 or_connect_failure_map_cleanup(time_t cutoff)
1333 for (ptr = HT_START(or_connect_failure_ht, &or_connect_failures_map);
1334 ptr != NULL; ptr = next) {
1336 if (entry->last_failed_connect_ts <= cutoff) {
1337 next = HT_NEXT_RMV(or_connect_failure_ht, &or_connect_failures_map, ptr);
1340 next = HT_NEXT(or_connect_failure_ht, &or_connect_failures_map, ptr);
1354 time_t connect_failed_since_ts = 0;
1360 cutoff = now - OR_CONNECT_FAILURE_LIFETIME;
1364 if (or_connect_failure_map_next_cleanup_ts <= now) {
1365 or_connect_failure_map_cleanup(cutoff);
1366 or_connect_failure_map_next_cleanup_ts =
1367 now + OR_CONNECT_FAILURE_CLEANUP_INTERVAL;
1372 ocf = or_connect_failure_find(or_conn);
1374 connect_failed_since_ts = ocf->last_failed_connect_ts;
1378 if (connect_failed_since_ts > cutoff) {
1396 int reason,
const char *msg)
1401 note_or_connect_failed(conn);
1412 int reason,
const char *msg)
1424 chan = TLS_CHAN_TO_BASE(conn->
chan);
1426 if (!CHANNEL_CONDEMNED(chan)) {
1452 const char *id_digest,
1454 channel_tls_t *chan))
1458 int socket_error = 0;
1463 uint16_t proxy_port;
1464 int proxy_type, is_pt = 0;
1471 log_info(
LD_PROTOCOL,
"Client asked me to connect to myself. Refusing.");
1475 log_info(
LD_PROTOCOL,
"Client asked me to connect to myself by Ed25519 "
1476 "identity. Refusing.");
1496 if (!should_connect_to_relay(conn)) {
1497 log_info(
LD_GENERAL,
"Can't connect to %s because we "
1498 "failed earlier. Refusing.",
1511 if (proxy_type != PROXY_NONE) {
1515 conn->
is_pt = is_pt;
1529 const char *transport_name =
1533 if (transport_name) {
1534 log_warn(
LD_GENERAL,
"We were supposed to connect to bridge '%s' "
1535 "using pluggable transport '%s', but we can't find a pluggable "
1536 "transport proxy supporting '%s'. This can happen if you "
1537 "haven't provided a ClientTransportPlugin line, or if "
1538 "your pluggable transport proxy stopped running.",
1540 transport_name, transport_name);
1543 "Can't connect to bridge",
1544 END_OR_CONN_REASON_PT_MISSING,
1548 log_warn(
LD_GENERAL,
"Tried to connect to %s through a proxy, but "
1549 "the proxy address could not be found.",
1558 &addr, port, &socket_error)) {
1565 tor_socket_strerror(socket_error));
1603 if (flush) connection_mark_and_flush_internal(
TO_CONN(orconn));
1604 else connection_mark_for_close_internal(
TO_CONN(orconn));
1606 chan = TLS_CHAN_TO_BASE(orconn->
chan);
1608 if (!CHANNEL_CONDEMNED(chan)) {
1624 if (flush) connection_mark_and_flush_internal(
TO_CONN(orconn));
1625 else connection_mark_for_close_internal(
TO_CONN(orconn));
1627 chan = TLS_CHAN_TO_BASE(orconn->
chan);
1629 if (!CHANNEL_CONDEMNED(chan)) {
1655 if (!chan_listener) {
1667 log_warn(
LD_BUG,
"tor_tls_new failed. Closing.");
1674 log_debug(
LD_HANDSHAKE,
"starting TLS handshake on fd "TOR_SOCKET_T_FORMAT,
1721 check_no_tls_errors();
1731 log_info(
LD_OR,
"tls error [%s]. breaking connection.",
1741 log_debug(
LD_OR,
"Done with initial SSL handshake (server-side). "
1742 "Expecting renegotiation or VERSIONS cell");
1755 case TOR_TLS_WANTWRITE:
1757 log_debug(
LD_OR,
"wanted write");
1759 case TOR_TLS_WANTREAD:
1760 log_debug(
LD_OR,
"wanted read");
1764 log_info(
LD_OR,
"tls closed. breaking connection.");
1813 char *digest_rcvd_out)
1818 const char *conn_type = started_here ?
"outgoing" :
"incoming";
1821 check_no_tls_errors();
1823 if (started_here && !has_cert) {
1824 log_info(
LD_HANDSHAKE,
"Tried connecting to router at %s, but it didn't "
1825 "send a cert! Closing.",
1828 }
else if (!has_cert) {
1829 log_debug(
LD_HANDSHAKE,
"Got incoming connection with no certificate. "
1832 check_no_tls_errors();
1836 conn->
tls, &identity_rcvd);
1837 if (started_here && v<0) {
1839 " has a cert but it's invalid. Closing.",
1843 log_info(
LD_HANDSHAKE,
"Incoming connection gave us an invalid cert "
1844 "chain; ignoring.");
1847 "The certificate seems to be valid on %s connection "
1848 "with %s", conn_type,
1851 check_no_tls_errors();
1854 if (identity_rcvd) {
1856 crypto_pk_free(identity_rcvd);
1866 crypto_pk_free(identity_rcvd);
1871 log_debug(
LD_HANDSHAKE,
"Calling client_learned_peer_id from "
1872 "check_valid_tls_handshake");
1874 (
const uint8_t*)digest_rcvd_out,
1907 const uint8_t *rsa_peer_id,
1911 channel_tls_t *chan_tls = conn->
chan;
1913 int changed_identity = 0;
1916 const int expected_rsa_key =
1918 const int expected_ed_key =
1921 log_info(
LD_HANDSHAKE,
"learned peer id for %s at %p: %s, %s",
1927 if (! expected_rsa_key && ! expected_ed_key) {
1928 log_info(
LD_HANDSHAKE,
"(we had no ID in mind when we made this "
1931 (
const char*)rsa_peer_id, ed_peer_id);
1937 log_info(
LD_HANDSHAKE,
"Connected to router at %s without knowing "
1938 "its key. Hoping for the best.",
1943 (
const char*)rsa_peer_id, ed_peer_id);
1944 changed_identity = 1;
1947 const int rsa_mismatch = expected_rsa_key &&
1951 const int ed25519_mismatch =
1953 (ed_peer_id == NULL ||
1956 if (rsa_mismatch || ed25519_mismatch) {
1969 strlcpy(seen_ed,
"no ed25519 key",
sizeof(seen_ed));
1974 strlcpy(expected_ed,
"no ed25519 key",
sizeof(expected_ed));
1976 const int using_hardcoded_fingerprints =
1981 const int is_authority_fingerprint = router_digest_is_trusted_dir(
1983 const int non_anonymous_mode =
1984 hs_service_non_anonymous_mode_enabled(options);
1986 const char *extra_log =
"";
1991 severity = LOG_PROTOCOL_WARN;
1993 if (using_hardcoded_fingerprints) {
1996 if (is_authority_fingerprint) {
1998 }
else if (is_fallback_fingerprint) {
2002 extra_log =
" Tor will try a different fallback.";
2014 "Tried connecting to router at %s, but RSA + ed25519 identity "
2015 "keys were not as expected: wanted %s + %s but got %s + %s.%s",
2017 expected_rsa, expected_ed, seen_rsa, seen_ed, extra_log);
2022 END_OR_CONN_REASON_OR_IDENTITY);
2025 "Unexpected identity in router certificate",
2026 END_OR_CONN_REASON_OR_IDENTITY,
2031 if (!expected_ed_key && ed_peer_id) {
2032 log_info(
LD_HANDSHAKE,
"(We had no Ed25519 ID in mind when we made this "
2035 (
const char*)rsa_peer_id, ed_peer_id);
2036 changed_identity = 1;
2039 if (changed_identity) {
2052 (
const char*)rsa_peer_id, ed_peer_id);
2093 log_debug(
LD_HANDSHAKE,
"%s tls handshake on %s done, using "
2094 "ciphersuite %s. verifying.",
2095 started_here?
"outgoing":
"incoming",
2097 tor_tls_get_ciphersuite_name(conn->
tls));
2108 conn->base_.
port, digest_rcvd,
2118 conn->base_.
port, digest_rcvd,
2151 log_warn(
LD_BUG,
"Duplicate call to connection_init_or_handshake_state!");
2157 s->digest_received_data = 1;
2158 if (! started_here && get_current_link_cert_cert()) {
2174 or_handshake_certs_free(state->
certs);
2195 size_t cell_network_size = get_cell_network_size(conn->wide_circ_ids);
2199 if (!state->digest_received_data)
2206 log_warn(
LD_BUG,
"We shouldn't be sending any non-variable-length cells "
2207 "while making a handshake digest. But we think we are sending "
2208 "one with type %d.", (
int)cell->
command);
2210 dptr = incoming ? &state->digest_received : &state->
digest_sent;
2217 cell_pack(&packed, cell, conn->wide_circ_ids);
2219 memwipe(&packed, 0,
sizeof(packed));
2240 if (!state->digest_received_data)
2246 dptr = incoming ? &state->digest_received : &state->
digest_sent;
2289 size_t cell_network_size = get_cell_network_size(conn->wide_circ_ids);
2294 cell_pack(&networkcell, cell, conn->wide_circ_ids);
2299 if (cell->
command == CELL_PADDING)
2302 connection_buf_add(networkcell.
body, cell_network_size,
TO_CONN(conn));
2308 if (TLS_CHAN_TO_BASE(conn->
chan)->padding_enabled) {
2310 if (cell->
command == CELL_PADDING)
2332 connection_buf_add(hdr, n,
TO_CONN(conn));
2333 connection_buf_add((
char*)cell->
payload,
2380 TOR_SOCKET_T_FORMAT
": starting, inbuf_datalen %d "
2381 "(%d pending in tls object).",
2382 conn->base_.
s,(
int)connection_get_inbuf_len(
TO_CONN(conn)),
2394 var_cell_free(var_cell);
2396 const int wide_circ_ids = conn->wide_circ_ids;
2397 size_t cell_network_size = get_cell_network_size(conn->wide_circ_ids);
2400 if (connection_get_inbuf_len(
TO_CONN(conn))
2401 < cell_network_size)
2453 const int min_version = v3_plus ? 3 : 0;
2454 const int max_version = v3_plus ? UINT16_MAX : 2;
2458 cell->
command = CELL_VERSIONS;
2461 if (v < min_version || v > max_version)
2471 var_cell_free(cell);
2475 static netinfo_addr_t *
2476 netinfo_addr_from_tor_addr(
const tor_addr_t *tor_addr)
2480 if (BUG(addr_family != AF_INET && addr_family != AF_INET6))
2483 netinfo_addr_t *netinfo_addr = netinfo_addr_new();
2485 if (addr_family == AF_INET) {
2486 netinfo_addr_set_addr_type(netinfo_addr, NETINFO_ADDR_TYPE_IPV4);
2487 netinfo_addr_set_len(netinfo_addr, 4);
2489 }
else if (addr_family == AF_INET6) {
2490 netinfo_addr_set_addr_type(netinfo_addr, NETINFO_ADDR_TYPE_IPV6);
2491 netinfo_addr_set_len(netinfo_addr, 16);
2492 uint8_t *ipv6_buf = netinfo_addr_getarray_addr_ipv6(netinfo_addr);
2497 return netinfo_addr;
2506 time_t now = time(NULL);
2513 log_warn(
LD_BUG,
"Attempted to send an extra netinfo cell on a connection "
2514 "where we already sent one.");
2518 memset(&cell, 0,
sizeof(
cell_t));
2521 netinfo_cell_t *netinfo_cell = netinfo_cell_new();
2525 netinfo_cell_set_timestamp(netinfo_cell, (uint32_t)now);
2531 netinfo_addr_t *their_addr = netinfo_addr_from_tor_addr(remote_tor_addr);
2533 netinfo_cell_set_other_addr(netinfo_cell, their_addr);
2541 netinfo_cell_set_n_my_addrs(netinfo_cell, n_my_addrs);
2543 netinfo_cell_add_my_addrs(netinfo_cell,
2544 netinfo_addr_from_tor_addr(&me->
ipv4_addr));
2547 netinfo_cell_add_my_addrs(netinfo_cell,
2548 netinfo_addr_from_tor_addr(&me->
ipv6_addr));
2552 const char *errmsg = NULL;
2553 if ((errmsg = netinfo_cell_check(netinfo_cell))) {
2554 log_warn(
LD_OR,
"Failed to validate NETINFO cell with error: %s",
2560 netinfo_cell) < 0) {
2561 log_warn(
LD_OR,
"Failed generating NETINFO cell");
2571 netinfo_cell_free(netinfo_cell);
void tor_addr_copy(tor_addr_t *dest, const tor_addr_t *src)
int tor_addr_is_null(const tor_addr_t *addr)
void tor_addr_port_copy(tor_addr_port_t *dest, const tor_addr_port_t *source)
static sa_family_t tor_addr_family(const tor_addr_t *a)
static uint32_t tor_addr_to_ipv4h(const tor_addr_t *a)
#define tor_addr_to_in6_addr8(x)
#define tor_addr_eq(a, b)
int authdir_mode_tests_reachability(const or_options_t *options)
Header file for directory authority mode.
const char * hex_str(const char *from, size_t fromlen)
void base16_encode(char *dest, size_t destlen, const char *src, size_t srclen)
const char * find_transport_name_by_bridge_addrport(const tor_addr_t *addr, uint16_t port)
void learned_router_identity(const tor_addr_t *addr, uint16_t port, const char *digest, const ed25519_public_key_t *ed_id)
Header file for circuitbuild.c.
size_t buf_datalen(const buf_t *buf)
Header file for buffers.c.
static void set_uint16(void *cp, uint16_t v)
static uint16_t get_uint16(const void *cp)
static void set_uint32(void *cp, uint32_t v)
static uint8_t get_uint8(const void *cp)
static void set_uint8(void *cp, uint8_t v)
static uint32_t get_uint32(const void *cp)
Fixed-size cell structure.
void channel_timestamp_active(channel_t *chan)
void channel_set_circid_type(channel_t *chan, crypto_pk_t *identity_rcvd, int consider_identity)
int channel_is_better(channel_t *a, channel_t *b)
int channel_is_bad_for_new_circs(channel_t *chan)
void channel_set_identity_digest(channel_t *chan, const char *identity_digest, const ed25519_public_key_t *ed_identity)
void channel_mark_client(channel_t *chan)
void channel_closed(channel_t *chan)
void channel_close_from_lower_layer(channel_t *chan)
void channel_listener_queue_incoming(channel_listener_t *listener, channel_t *incoming)
time_t channel_when_last_client(channel_t *chan)
void channel_mark_bad_for_new_circs(channel_t *chan)
void channel_close_for_error(channel_t *chan)
void channel_clear_identity_digest(channel_t *chan)
unsigned int channel_num_circuits(channel_t *chan)
Header file for channel.c.
unsigned int channelpadding_get_channel_idle_timeout(const channel_t *chan, int is_canonical)
void channel_tls_handle_var_cell(var_cell_t *var_cell, or_connection_t *conn)
channel_t * channel_tls_to_base(channel_tls_t *tlschan)
void channel_tls_handle_state_change_on_orconn(channel_tls_t *chan, or_connection_t *conn, uint8_t state)
channel_listener_t * channel_tls_get_listener(void)
void channel_tls_handle_cell(cell_t *cell, or_connection_t *conn)
void channel_tls_update_marks(or_connection_t *conn)
channel_listener_t * channel_tls_start_listener(void)
channel_t * channel_tls_handle_incoming(or_connection_t *orconn)
Header file for channeltls.c.
Header file for circuitbuild.c.
Header file for circuitlist.c.
void circuit_build_times_network_is_live(circuit_build_times_t *cbt)
circuit_build_times_t * get_circuit_build_times_mutable(void)
Header file for circuitstats.c.
void command_setup_listener(channel_listener_t *listener)
Header file for command.c.
uint32_t monotime_coarse_get_stamp(void)
const or_options_t * get_options(void)
Header file for config.c.
or_connection_t * or_connection_new(int type, int socket_family)
int connection_buf_get_bytes(char *string, size_t len, connection_t *conn)
const char * conn_state_to_string(int type, int state)
int get_proxy_addrport(tor_addr_t *addr, uint16_t *port, int *proxy_type, int *is_pt_out, const connection_t *conn)
int connection_proxy_connect(connection_t *conn, int type)
const char * connection_describe(const connection_t *conn)
void assert_connection_ok(connection_t *conn, time_t now)
int connection_read_proxy_handshake(connection_t *conn)
const char * connection_describe_peer(const connection_t *conn)
void connection_free_(connection_t *conn)
int connection_connect(connection_t *conn, const char *address, const tor_addr_t *addr, uint16_t port, int *socket_error)
Header file for connection.c.
static int connection_tls_finish_handshake(or_connection_t *conn)
or_connection_t * connection_or_connect(const tor_addr_t *_addr, uint16_t port, const char *id_digest, const ed25519_public_key_t *ed_id, channel_tls_t *chan)
void connection_or_event_status(or_connection_t *conn, or_conn_status_event_t tp, int reason)
static void connection_or_tls_renegotiated_cb(tor_tls_t *tls, void *_conn)
int is_or_protocol_version_known(uint16_t v)
int connection_or_set_state_open(or_connection_t *conn)
int connection_or_reached_eof(or_connection_t *conn)
static const int n_or_protocol_versions
int connection_tls_continue_handshake(or_connection_t *conn)
static void connection_or_set_identity_digest(or_connection_t *conn, const char *rsa_digest, const ed25519_public_key_t *ed_id)
void connection_or_notify_error(or_connection_t *conn, int reason, const char *msg)
void connection_or_write_cell_to_buf(const cell_t *cell, or_connection_t *conn)
int connection_or_process_inbuf(or_connection_t *conn)
static int connection_fetch_var_cell_from_buf(or_connection_t *or_conn, var_cell_t **out)
void connection_or_clear_identity(or_connection_t *conn)
int connection_or_send_versions(or_connection_t *conn, int v3_plus)
var_cell_t * var_cell_new(uint16_t payload_len)
int connection_or_client_learned_peer_id(or_connection_t *conn, const uint8_t *rsa_peer_id, const ed25519_public_key_t *ed_peer_id)
static void connection_or_update_token_buckets_helper(or_connection_t *conn, int reset, const or_options_t *options)
time_t connection_or_client_used(or_connection_t *conn)
void cell_pack(packed_cell_t *dst, const cell_t *src, int wide_circ_ids)
static void connection_or_note_state_when_broken(or_connection_t *orconn)
void or_handshake_state_free_(or_handshake_state_t *state)
void or_handshake_state_record_var_cell(or_connection_t *conn, or_handshake_state_t *state, const var_cell_t *cell, int incoming)
int var_cell_pack_header(const var_cell_t *cell, char *hdr_out, int wide_circ_ids)
int connection_or_finished_flushing(or_connection_t *conn)
static unsigned int connection_or_is_bad_for_new_circs(or_connection_t *or_conn)
void clear_broken_connection_map(int stop_recording)
static void cell_unpack(cell_t *dest, const char *src, int wide_circ_ids)
void connection_or_connect_failed(or_connection_t *conn, int reason, const char *msg)
static int connection_or_process_cells_from_inbuf(or_connection_t *conn)
int connection_or_send_netinfo(or_connection_t *conn)
void var_cell_free_(var_cell_t *cell)
int connection_or_single_set_badness_(time_t now, or_connection_t *or_conn, int force)
int connection_tls_start_handshake(or_connection_t *conn, int receiving)
static int connection_or_check_valid_tls_handshake(or_connection_t *conn, int started_here, char *digest_rcvd_out)
void connection_or_change_state(or_connection_t *conn, uint8_t state)
var_cell_t * var_cell_copy(const var_cell_t *src)
void or_handshake_state_record_cell(or_connection_t *conn, or_handshake_state_t *state, const cell_t *cell, int incoming)
static int connection_or_launch_v3_or_handshake(or_connection_t *conn)
static void note_broken_connection(const char *state)
void connection_or_report_broken_states(int severity, int domain)
static void connection_or_check_canonicity(or_connection_t *conn, int started_here)
int connection_or_digest_is_known_relay(const char *id_digest)
#define MAX_REASONS_TO_REPORT
void connection_or_init_conn_from_address(or_connection_t *conn, const tor_addr_t *addr, uint16_t port, const char *id_digest, const ed25519_public_key_t *ed_id, int started_here)
static const uint16_t or_protocol_versions[]
int connection_or_get_num_circuits(or_connection_t *conn)
int connection_or_flushed_some(or_connection_t *conn)
int connection_or_nonopen_was_started_here(or_connection_t *conn)
static int disable_broken_connection_counts
const struct ed25519_public_key_t * connection_or_get_alleged_ed25519_id(const or_connection_t *conn)
void connection_or_close_for_error(or_connection_t *orconn, int flush)
static strmap_t * broken_connection_counts
void connection_or_update_token_buckets(smartlist_t *conns, const or_options_t *options)
static void connection_or_get_state_description(or_connection_t *orconn, char *buf, size_t buflen)
void connection_or_group_set_badness_(smartlist_t *group, int force)
const or_connection_t * CONST_TO_OR_CONN(const connection_t *c)
int connection_or_finished_connecting(or_connection_t *or_conn)
void connection_or_about_to_close(or_connection_t *or_conn)
or_connection_t * TO_OR_CONN(connection_t *c)
static int broken_state_count_compare(const void **a_ptr, const void **b_ptr)
ssize_t connection_or_num_cells_writeable(or_connection_t *conn)
int connection_init_or_handshake_state(or_connection_t *conn, int started_here)
void connection_or_block_renegotiation(or_connection_t *conn)
void connection_or_clear_identity_map(void)
void connection_or_close_normally(or_connection_t *orconn, int flush)
static void connection_or_state_publish(const or_connection_t *conn, uint8_t state)
void connection_or_write_var_cell_to_buf(const var_cell_t *cell, or_connection_t *conn)
#define TIME_BEFORE_OR_CONN_IS_TOO_OLD
Header file for connection_or.c.
void control_event_bootstrap_prob_or(const char *warn, int reason, or_connection_t *or_conn)
int control_event_or_conn_status(or_connection_t *conn, or_conn_status_event_t tp, int reason)
Header file for control_events.c.
crypto_digest_t * crypto_digest256_new(digest_algorithm_t algorithm)
#define crypto_digest_free(d)
void crypto_digest_add_bytes(crypto_digest_t *digest, const char *data, size_t len)
int ed25519_public_key_is_zero(const ed25519_public_key_t *pubkey)
int ed25519_pubkey_eq(const ed25519_public_key_t *key1, const ed25519_public_key_t *key2)
int crypto_pk_get_digest(const crypto_pk_t *pk, char *digest_out)
void memwipe(void *mem, uint8_t byte, size_t sz)
Common functions for cryptographic routines.
#define fast_memeq(a, b, c)
#define tor_memneq(a, b, sz)
int router_digest_is_fallback_dir(const char *digest)
Header file for dirlist.c.
void entry_guard_chan_failed(channel_t *chan)
Header file for circuitbuild.c.
HT_PROTOTYPE(hs_circuitmap_ht, circuit_t, hs_circuitmap_node, hs_circuit_hash_token, hs_circuits_have_same_token)
Header file containing service data for the HS subsystem.
typedef HT_HEAD(hs_service_ht, hs_service_t) hs_service_ht
void tor_log(int severity, log_domain_mask_t domain, const char *format,...)
#define log_fn(severity, domain, args,...)
void connection_watch_events(connection_t *conn, watchable_events_t events)
void connection_start_reading(connection_t *conn)
void connection_start_writing(connection_t *conn)
smartlist_t * get_connection_array(void)
void connection_stop_writing(connection_t *conn)
Header file for mainloop.c.
void tor_free_(void *mem)
void * tor_reallocarray_(void *ptr, size_t sz1, size_t sz2)
int usable_consensus_flavor(void)
Header file for microdesc.c.
networkstatus_t * networkstatus_get_reasonably_live_consensus(time_t now, int flavor)
const routerstatus_t * router_get_consensus_status_by_id(const char *digest)
int32_t networkstatus_get_param(const networkstatus_t *ns, const char *param_name, int32_t default_val, int32_t min_val, int32_t max_val)
Header file for networkstatus.c.
void node_get_prim_orport(const node_t *node, tor_addr_port_t *ap_out)
const char * node_get_nickname(const node_t *node)
bool node_supports_ed25519_link_authentication(const node_t *node, bool compatible_with_us)
int node_ed25519_id_matches(const node_t *node, const ed25519_public_key_t *id)
const node_t * node_get_by_id(const char *identity_digest)
void node_get_pref_ipv6_orport(const node_t *node, tor_addr_port_t *ap_out)
Header file for nodelist.c.
Master header file for Tor-specific functionality.
#define CELL_PAYLOAD_SIZE
#define VAR_CELL_MAX_HEADER_SIZE
#define OR_CONN_HIGHWATER
#define CELL_MAX_NETWORK_SIZE
#define DOWNCAST(to, ptr)
OR handshake certs structure.
OR handshake state structure.
The or_state_t structure, which represents Tor's state file.
Header file for orconn_event.c.
#define OR_CONN_STATE_TLS_SERVER_RENEGOTIATING
#define OR_CONN_STATE_CONNECTING
#define OR_CONN_STATE_OR_HANDSHAKING_V2
#define OR_CONN_STATE_PROXY_HANDSHAKING
#define OR_CONN_STATE_TLS_HANDSHAKING
#define OR_CONN_STATE_OR_HANDSHAKING_V3
#define OR_CONN_STATE_OPEN
int tor_snprintf(char *str, size_t size, const char *format,...)
int fetch_var_cell_from_buf(buf_t *buf, var_cell_t **out, int linkproto)
void dirserv_orconn_tls_done(const tor_addr_t *addr, uint16_t or_port, const char *digest_rcvd, const ed25519_public_key_t *ed_id_rcvd)
Header file for reachability.c.
int tls_error_to_orconn_end_reason(int e)
int errno_to_orconn_end_reason(int e)
const char * orconn_end_reason_to_control_string(int r)
Header file for reasons.c.
Header for feature/relay/relay_handshake.c.
Header file for rendcommon.c.
void rep_hist_note_negotiated_link_proto(unsigned link_proto, int started_here)
void rep_hist_padding_count_write(padding_type_t type)
Header file for rephist.c.
@ PADDING_TYPE_ENABLED_CELL
@ PADDING_TYPE_ENABLED_TOTAL
const routerinfo_t * router_get_my_routerinfo(void)
int router_digest_is_me(const char *digest)
Header file for router.c.
Router descriptor structure.
int router_ed25519_id_is_me(const ed25519_public_key_t *id)
const routerinfo_t * router_get_by_id_digest(const char *digest)
Header file for routerlist.c.
int public_server_mode(const or_options_t *options)
int server_mode(const or_options_t *options)
Header file for routermode.c.
void scheduler_channel_wants_writes(channel_t *chan)
Header file for scheduler*.c.
void smartlist_sort(smartlist_t *sl, int(*compare)(const void **a, const void **b))
smartlist_t * smartlist_new(void)
void smartlist_add(smartlist_t *sl, void *element)
#define SMARTLIST_FOREACH_BEGIN(sl, type, var)
#define SMARTLIST_FOREACH(sl, type, var, cmd)
uint8_t payload[CELL_PAYLOAD_SIZE]
struct ed25519_public_key_t ed25519_identity
unsigned int hold_open_until_flushed
uint64_t global_identifier
uint16_t marked_for_close
char identity_digest[DIGEST_LEN]
or_handshake_state_t * handshake_state
tor_addr_port_t canonical_orport
unsigned int is_canonical
struct tor_cert_st * own_link_cert
unsigned int started_here
unsigned int digest_sent_data
crypto_digest_t * digest_sent
or_handshake_certs_t * certs
char body[CELL_MAX_NETWORK_SIZE]
uint8_t payload[FLEXIBLE_ARRAY_MEMBER]
#define MOCK_IMPL(rv, funcname, arglist)
void token_bucket_rw_adjust(token_bucket_rw_t *bucket, uint32_t rate, uint32_t burst)
void token_bucket_rw_reset(token_bucket_rw_t *bucket, uint32_t now_ts)
or_handshake_certs_t * or_handshake_certs_new(void)
tor_cert_t * tor_cert_dup(const tor_cert_t *cert)
int tor_tls_is_server(tor_tls_t *tls)
void tor_tls_set_logged_address(tor_tls_t *tls, const char *address)
const char * tor_tls_err_to_string(int err)
int tor_tls_verify(int severity, tor_tls_t *tls, crypto_pk_t **identity)
void tor_tls_block_renegotiation(tor_tls_t *tls)
int tor_tls_peer_has_cert(tor_tls_t *tls)
int tor_tls_used_v1_handshake(tor_tls_t *tls)
void tor_tls_set_renegotiate_callback(tor_tls_t *tls, void(*cb)(tor_tls_t *, void *arg), void *arg)
#define CASE_TOR_TLS_ERROR_ANY
int tor_tls_get_pending_bytes(tor_tls_t *tls)
int tor_tls_handshake(tor_tls_t *tls)
const char * tor_tls_get_last_error_msg(const tor_tls_t *tls)
void tor_tls_get_state_description(tor_tls_t *tls, char *buf, size_t sz)
tor_tls_t * tor_tls_new(tor_socket_t sock, int is_server)
#define tor_assert_nonfatal_unreached()
#define tor_fragile_assert()
#define IF_BUG_ONCE(cond)
int tor_digest_is_zero(const char *digest)
Variable-length cell structure.
#define ED25519_BASE64_LEN