Go to the documentation of this file.
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"
89 char *digest_rcvd_out);
95 static void connection_or_mark_bad_for_new_circs(
or_connection_t *or_conn);
142 connection_or_clear_identity(TO_OR_CONN(conn));
158 const char *rsa_digest,
166 chan = TLS_CHAN_TO_BASE(conn->
chan);
168 log_info(
LD_HANDSHAKE,
"Set identity digest for %s at %p: %s %s.",
178 const int ed_id_was_set =
180 const int rsa_changed =
182 const int ed_changed = ed_id_was_set &&
188 if (!rsa_changed && !ed_changed)
192 if (rsa_id_was_set) {
219 if (conn && conn->
chan) {
221 chan = TLS_CHAN_TO_BASE(conn->
chan);
278 char *buf,
size_t buflen)
281 const char *conn_state;
289 tor_snprintf(buf, buflen,
"%s with SSL state %s", conn_state, tls_state);
301 log_info(
LD_HANDSHAKE,
"Connection died in state '%s'", buf);
316 if (b->count < a->count)
318 else if (b->count == a->count)
326 #define MAX_REASONS_TO_REPORT 10
342 c->count = (intptr_t)countptr;
343 total += (int)c->count;
346 } STRMAP_FOREACH_END;
350 tor_log(severity, domain,
"%d connections have failed%s", total,
357 " %d connections died in state %s", (
int)c->count, c->state);
358 } SMARTLIST_FOREACH_END(c);
361 smartlist_free(items);
379 orconn_status_publish(msg);
399 tor_assert_nonfatal(conn->
proxy_type != PROXY_NONE);
406 msg->
chan = TLS_CHAN_TO_BASE(conn->
chan)->global_identifier;
410 orconn_state_publish(msg);
422 conn->base_.
state = state;
455 char *dest = dst->
body;
512 size_t size = offsetof(
var_cell_t, payload) + payload_len;
532 copy = tor_malloc_zero(size);
555 log_info(
LD_OR,
"OR connection reached EOF. Closing.");
572 switch (conn->base_.
state) {
580 log_fn(LOG_PROTOCOL_WARN,
LD_NET,
"Found leftover (%d bytes) "
581 "when transitioning from PROXY_HANDSHAKING state on %s: "
613 log_fn(LOG_PROTOCOL_WARN,
LD_NET,
"Accumulated data (%d bytes) "
614 "on non-open %s; closing.",
637 datalen = connection_get_outbuf_len(
TO_CONN(conn));
651 size_t datalen, cell_network_size;
661 datalen = connection_get_outbuf_len(
TO_CONN(conn));
663 cell_network_size = get_cell_network_size(conn->wide_circ_ids);
684 switch (conn->base_.
state) {
694 TO_CONN(conn)->proxy_state = PROXY_CONNECTED;
709 log_err(
LD_BUG,
"Called in unexpected state %d.", conn->base_.
state);
736 if (proxy_type != PROXY_NONE) {
771 or_conn->
chan->conn = NULL;
772 or_conn->
chan = NULL;
788 const char *warning = NULL;
789 if (reason == END_OR_CONN_REASON_TLS_ERROR && or_conn->
tls) {
792 if (warning == NULL) {
870 if (connection_speaks_cells(conn))
891 TLS_CHAN_TO_BASE(or_conn->
chan), is_canonical);
894 "Channel %"PRIu64
" chose an idle timeout of %d.",
896 (TLS_CHAN_TO_BASE(or_conn->
chan)->global_identifier):0,
908 const char *id_digest,
912 log_debug(
LD_HANDSHAKE,
"init conn from address %s: %s, %s (%d)",
921 conn->base_.
port = port;
942 ed_id = & TLS_CHAN_TO_BASE(conn->
chan)->ed25519_identity;
960 connection_or_set_canonical(conn, 1);
965 node_ap = &node_ipv4_ap;
967 node_ap = &node_ipv6_ap;
1016 #define TIME_BEFORE_OR_CONN_IS_TOO_OLD (60*60*24*7)
1038 "Marking %s as too old for new circuits "
1039 "(fd "TOR_SOCKET_T_FORMAT
", %d secs old).",
1043 connection_or_mark_bad_for_new_circs(or_conn);
1073 int n_old = 0, n_inprogress = 0, n_canonical = 0, n_other = 0;
1074 time_t now = time(NULL);
1091 } SMARTLIST_FOREACH_END(or_conn);
1106 "Marking %s unsuitable for new circuits: "
1107 "(fd "TOR_SOCKET_T_FORMAT
", %d secs old). It is not "
1108 "canonical, and we have another connection to that OR that is.",
1112 connection_or_mark_bad_for_new_circs(or_conn);
1118 TLS_CHAN_TO_BASE(best->
chan))) {
1121 } SMARTLIST_FOREACH_END(or_conn);
1145 if (or_conn != best &&
1147 TLS_CHAN_TO_BASE(or_conn->
chan))) {
1151 "Marking %s as unsuitable for new circuits: "
1152 "(fd "TOR_SOCKET_T_FORMAT
", %d secs old). "
1153 "We have a better canonical one "
1154 "(fd "TOR_SOCKET_T_FORMAT
"; %d secs old).",
1159 connection_or_mark_bad_for_new_circs(or_conn);
1163 "Marking %s unsuitable for new circuits: "
1164 "(fd "TOR_SOCKET_T_FORMAT
", %d secs old). We have a better "
1166 "same address (fd "TOR_SOCKET_T_FORMAT
"; %d secs old).",
1171 connection_or_mark_bad_for_new_circs(or_conn);
1174 } SMARTLIST_FOREACH_END(or_conn);
1179 #define OR_CONNECT_FAILURE_LIFETIME 60
1181 #define OR_CONNECT_FAILURE_CLEANUP_INTERVAL 60
1185 static time_t or_connect_failure_map_next_cleanup_ts = 0;
1208 time_t last_failed_connect_ts;
1214 or_connect_failures_map = HT_INITIALIZER();
1231 size_t offset = 0, addr_size;
1232 const void *addr_ptr;
1234 uint8_t data[16 +
sizeof(uint16_t) +
DIGEST_LEN];
1240 addr_ptr = &entry->addr.addr.in_addr.s_addr;
1244 addr_ptr = &entry->addr.addr.in6_addr.s6_addr;
1251 memcpy(data, addr_ptr, addr_size);
1252 offset += addr_size;
1253 memcpy(data + offset, entry->identity_digest,
DIGEST_LEN);
1256 offset +=
sizeof(uint16_t);
1258 return (
unsigned int) siphash24g(data, offset);
1262 or_connect_failure_ht_hash, or_connect_failure_ht_eq);
1265 or_connect_failure_ht_hash, or_connect_failure_ht_eq,
1271 or_connect_failure_init(
const char *identity_digest,
const tor_addr_t *addr,
1275 if (identity_digest) {
1276 memcpy(ocf->identity_digest, identity_digest,
1277 sizeof(ocf->identity_digest));
1304 TO_CONN(or_conn)->port, &lookup);
1305 return HT_FIND(or_connect_failure_ht, &or_connect_failures_map, &lookup);
1317 ocf = or_connect_failure_find(or_conn);
1319 ocf = or_connect_failure_new(or_conn);
1320 HT_INSERT(or_connect_failure_ht, &or_connect_failures_map, ocf);
1328 or_connect_failure_map_cleanup(time_t cutoff)
1332 for (ptr = HT_START(or_connect_failure_ht, &or_connect_failures_map);
1333 ptr != NULL; ptr = next) {
1335 if (entry->last_failed_connect_ts <= cutoff) {
1336 next = HT_NEXT_RMV(or_connect_failure_ht, &or_connect_failures_map, ptr);
1339 next = HT_NEXT(or_connect_failure_ht, &or_connect_failures_map, ptr);
1353 time_t connect_failed_since_ts = 0;
1359 cutoff = now - OR_CONNECT_FAILURE_LIFETIME;
1363 if (or_connect_failure_map_next_cleanup_ts <= now) {
1364 or_connect_failure_map_cleanup(cutoff);
1365 or_connect_failure_map_next_cleanup_ts =
1366 now + OR_CONNECT_FAILURE_CLEANUP_INTERVAL;
1371 ocf = or_connect_failure_find(or_conn);
1373 connect_failed_since_ts = ocf->last_failed_connect_ts;
1377 if (connect_failed_since_ts > cutoff) {
1395 int reason,
const char *msg)
1400 note_or_connect_failed(conn);
1411 int reason,
const char *msg)
1423 chan = TLS_CHAN_TO_BASE(conn->
chan);
1425 if (!CHANNEL_CONDEMNED(chan)) {
1451 const char *id_digest,
1453 channel_tls_t *chan))
1457 int socket_error = 0;
1462 uint16_t proxy_port;
1463 int proxy_type, is_pt = 0;
1470 log_info(
LD_PROTOCOL,
"Client asked me to connect to myself. Refusing.");
1474 log_info(
LD_PROTOCOL,
"Client asked me to connect to myself by Ed25519 "
1475 "identity. Refusing.");
1495 if (!should_connect_to_relay(conn)) {
1496 log_info(
LD_GENERAL,
"Can't connect to %s because we "
1497 "failed earlier. Refusing.",
1510 if (proxy_type != PROXY_NONE) {
1514 conn->
is_pt = is_pt;
1528 const char *transport_name =
1532 if (transport_name) {
1533 log_warn(
LD_GENERAL,
"We were supposed to connect to bridge '%s' "
1534 "using pluggable transport '%s', but we can't find a pluggable "
1535 "transport proxy supporting '%s'. This can happen if you "
1536 "haven't provided a ClientTransportPlugin line, or if "
1537 "your pluggable transport proxy stopped running.",
1539 transport_name, transport_name);
1542 "Can't connect to bridge",
1543 END_OR_CONN_REASON_PT_MISSING,
1547 log_warn(
LD_GENERAL,
"Tried to connect to %s through a proxy, but "
1548 "the proxy address could not be found.",
1557 &addr, port, &socket_error)) {
1564 tor_socket_strerror(socket_error));
1602 if (flush) connection_mark_and_flush_internal(
TO_CONN(orconn));
1603 else connection_mark_for_close_internal(
TO_CONN(orconn));
1605 chan = TLS_CHAN_TO_BASE(orconn->
chan);
1607 if (!CHANNEL_CONDEMNED(chan)) {
1623 if (flush) connection_mark_and_flush_internal(
TO_CONN(orconn));
1624 else connection_mark_for_close_internal(
TO_CONN(orconn));
1626 chan = TLS_CHAN_TO_BASE(orconn->
chan);
1628 if (!CHANNEL_CONDEMNED(chan)) {
1654 if (!chan_listener) {
1666 log_warn(
LD_BUG,
"tor_tls_new failed. Closing.");
1673 log_debug(
LD_HANDSHAKE,
"starting TLS handshake on fd "TOR_SOCKET_T_FORMAT,
1720 check_no_tls_errors();
1730 log_info(
LD_OR,
"tls error [%s]. breaking connection.",
1740 log_debug(
LD_OR,
"Done with initial SSL handshake (server-side). "
1741 "Expecting renegotiation or VERSIONS cell");
1754 case TOR_TLS_WANTWRITE:
1756 log_debug(
LD_OR,
"wanted write");
1758 case TOR_TLS_WANTREAD:
1759 log_debug(
LD_OR,
"wanted read");
1763 log_info(
LD_OR,
"tls closed. breaking connection.");
1812 char *digest_rcvd_out)
1817 const char *conn_type = started_here ?
"outgoing" :
"incoming";
1820 check_no_tls_errors();
1822 if (started_here && !has_cert) {
1823 log_info(
LD_HANDSHAKE,
"Tried connecting to router at %s, but it didn't "
1824 "send a cert! Closing.",
1827 }
else if (!has_cert) {
1828 log_debug(
LD_HANDSHAKE,
"Got incoming connection with no certificate. "
1831 check_no_tls_errors();
1835 conn->
tls, &identity_rcvd);
1836 if (started_here && v<0) {
1838 " has a cert but it's invalid. Closing.",
1842 log_info(
LD_HANDSHAKE,
"Incoming connection gave us an invalid cert "
1843 "chain; ignoring.");
1846 "The certificate seems to be valid on %s connection "
1847 "with %s", conn_type,
1850 check_no_tls_errors();
1853 if (identity_rcvd) {
1855 crypto_pk_free(identity_rcvd);
1865 crypto_pk_free(identity_rcvd);
1870 log_debug(
LD_HANDSHAKE,
"Calling client_learned_peer_id from "
1871 "check_valid_tls_handshake");
1873 (
const uint8_t*)digest_rcvd_out,
1906 const uint8_t *rsa_peer_id,
1910 channel_tls_t *chan_tls = conn->
chan;
1912 int changed_identity = 0;
1915 const int expected_rsa_key =
1917 const int expected_ed_key =
1920 log_info(
LD_HANDSHAKE,
"learned peer id for %s at %p: %s, %s",
1926 if (! expected_rsa_key && ! expected_ed_key) {
1927 log_info(
LD_HANDSHAKE,
"(we had no ID in mind when we made this "
1930 (
const char*)rsa_peer_id, ed_peer_id);
1936 log_info(
LD_HANDSHAKE,
"Connected to router at %s without knowing "
1937 "its key. Hoping for the best.",
1942 (
const char*)rsa_peer_id, ed_peer_id);
1943 changed_identity = 1;
1946 const int rsa_mismatch = expected_rsa_key &&
1950 const int ed25519_mismatch =
1952 (ed_peer_id == NULL ||
1955 if (rsa_mismatch || ed25519_mismatch) {
1968 strlcpy(seen_ed,
"no ed25519 key",
sizeof(seen_ed));
1973 strlcpy(expected_ed,
"no ed25519 key",
sizeof(expected_ed));
1975 const int using_hardcoded_fingerprints =
1980 const int is_authority_fingerprint = router_digest_is_trusted_dir(
1982 const int non_anonymous_mode = rend_non_anonymous_mode_enabled(options);
1984 const char *extra_log =
"";
1989 severity = LOG_PROTOCOL_WARN;
1991 if (using_hardcoded_fingerprints) {
1994 if (is_authority_fingerprint) {
1996 }
else if (is_fallback_fingerprint) {
2000 extra_log =
" Tor will try a different fallback.";
2012 "Tried connecting to router at %s, but RSA + ed25519 identity "
2013 "keys were not as expected: wanted %s + %s but got %s + %s.%s",
2015 expected_rsa, expected_ed, seen_rsa, seen_ed, extra_log);
2020 END_OR_CONN_REASON_OR_IDENTITY);
2023 "Unexpected identity in router certificate",
2024 END_OR_CONN_REASON_OR_IDENTITY,
2029 if (!expected_ed_key && ed_peer_id) {
2030 log_info(
LD_HANDSHAKE,
"(We had no Ed25519 ID in mind when we made this "
2033 (
const char*)rsa_peer_id, ed_peer_id);
2034 changed_identity = 1;
2037 if (changed_identity) {
2050 (
const char*)rsa_peer_id, ed_peer_id);
2091 log_debug(
LD_HANDSHAKE,
"%s tls handshake on %s done, using "
2092 "ciphersuite %s. verifying.",
2093 started_here?
"outgoing":
"incoming",
2095 tor_tls_get_ciphersuite_name(conn->
tls));
2106 conn->base_.
port, digest_rcvd,
2116 conn->base_.
port, digest_rcvd,
2149 log_warn(
LD_BUG,
"Duplicate call to connection_init_or_handshake_state!");
2155 s->digest_received_data = 1;
2156 if (! started_here && get_current_link_cert_cert()) {
2172 or_handshake_certs_free(state->
certs);
2193 size_t cell_network_size = get_cell_network_size(conn->wide_circ_ids);
2197 if (!state->digest_received_data)
2204 log_warn(
LD_BUG,
"We shouldn't be sending any non-variable-length cells "
2205 "while making a handshake digest. But we think we are sending "
2206 "one with type %d.", (
int)cell->
command);
2208 dptr = incoming ? &state->digest_received : &state->
digest_sent;
2215 cell_pack(&packed, cell, conn->wide_circ_ids);
2217 memwipe(&packed, 0,
sizeof(packed));
2238 if (!state->digest_received_data)
2244 dptr = incoming ? &state->digest_received : &state->
digest_sent;
2287 size_t cell_network_size = get_cell_network_size(conn->wide_circ_ids);
2292 cell_pack(&networkcell, cell, conn->wide_circ_ids);
2297 if (cell->
command == CELL_PADDING)
2300 connection_buf_add(networkcell.
body, cell_network_size,
TO_CONN(conn));
2306 if (TLS_CHAN_TO_BASE(conn->
chan)->padding_enabled) {
2308 if (cell->
command == CELL_PADDING)
2330 connection_buf_add(hdr, n,
TO_CONN(conn));
2331 connection_buf_add((
char*)cell->
payload,
2378 TOR_SOCKET_T_FORMAT
": starting, inbuf_datalen %d "
2379 "(%d pending in tls object).",
2380 conn->base_.
s,(
int)connection_get_inbuf_len(
TO_CONN(conn)),
2392 var_cell_free(var_cell);
2394 const int wide_circ_ids = conn->wide_circ_ids;
2395 size_t cell_network_size = get_cell_network_size(conn->wide_circ_ids);
2398 if (connection_get_inbuf_len(
TO_CONN(conn))
2399 < cell_network_size)
2451 const int min_version = v3_plus ? 3 : 0;
2452 const int max_version = v3_plus ? UINT16_MAX : 2;
2456 cell->
command = CELL_VERSIONS;
2459 if (v < min_version || v > max_version)
2469 var_cell_free(cell);
2473 static netinfo_addr_t *
2474 netinfo_addr_from_tor_addr(
const tor_addr_t *tor_addr)
2478 if (BUG(addr_family != AF_INET && addr_family != AF_INET6))
2481 netinfo_addr_t *netinfo_addr = netinfo_addr_new();
2483 if (addr_family == AF_INET) {
2484 netinfo_addr_set_addr_type(netinfo_addr, NETINFO_ADDR_TYPE_IPV4);
2485 netinfo_addr_set_len(netinfo_addr, 4);
2487 }
else if (addr_family == AF_INET6) {
2488 netinfo_addr_set_addr_type(netinfo_addr, NETINFO_ADDR_TYPE_IPV6);
2489 netinfo_addr_set_len(netinfo_addr, 16);
2490 uint8_t *ipv6_buf = netinfo_addr_getarray_addr_ipv6(netinfo_addr);
2495 return netinfo_addr;
2504 time_t now = time(NULL);
2511 log_warn(
LD_BUG,
"Attempted to send an extra netinfo cell on a connection "
2512 "where we already sent one.");
2516 memset(&cell, 0,
sizeof(
cell_t));
2519 netinfo_cell_t *netinfo_cell = netinfo_cell_new();
2523 netinfo_cell_set_timestamp(netinfo_cell, (uint32_t)now);
2529 netinfo_addr_t *their_addr = netinfo_addr_from_tor_addr(remote_tor_addr);
2531 netinfo_cell_set_other_addr(netinfo_cell, their_addr);
2539 netinfo_cell_set_n_my_addrs(netinfo_cell, n_my_addrs);
2541 netinfo_cell_add_my_addrs(netinfo_cell,
2542 netinfo_addr_from_tor_addr(&me->
ipv4_addr));
2545 netinfo_cell_add_my_addrs(netinfo_cell,
2546 netinfo_addr_from_tor_addr(&me->
ipv6_addr));
2550 const char *errmsg = NULL;
2551 if ((errmsg = netinfo_cell_check(netinfo_cell))) {
2552 log_warn(
LD_OR,
"Failed to validate NETINFO cell with error: %s",
2558 netinfo_cell) < 0) {
2559 log_warn(
LD_OR,
"Failed generating NETINFO cell");
2569 netinfo_cell_free(netinfo_cell);
#define log_fn(severity, domain, args,...)
time_t connection_or_client_used(or_connection_t *conn)
#define CELL_MAX_NETWORK_SIZE
#define DOWNCAST(to, ptr)
Header file for routermode.c.
const or_connection_t * CONST_TO_OR_CONN(const connection_t *c)
circuit_build_times_t * get_circuit_build_times_mutable(void)
void connection_stop_writing(connection_t *conn)
int connection_or_send_netinfo(or_connection_t *conn)
int fetch_var_cell_from_buf(buf_t *buf, var_cell_t **out, int linkproto)
void channel_tls_handle_state_change_on_orconn(channel_tls_t *chan, or_connection_t *conn, uint8_t state)
void tor_free_(void *mem)
int connection_or_finished_connecting(or_connection_t *or_conn)
static sa_family_t tor_addr_family(const tor_addr_t *a)
const char * hex_str(const char *from, size_t fromlen)
crypto_digest_t * digest_sent
int connection_or_send_versions(or_connection_t *conn, int v3_plus)
#define OR_CONN_STATE_CONNECTING
void or_handshake_state_free_(or_handshake_state_t *state)
or_handshake_state_t * handshake_state
void memwipe(void *mem, uint8_t byte, size_t sz)
int tor_tls_get_pending_bytes(tor_tls_t *tls)
#define OR_CONN_STATE_TLS_SERVER_RENEGOTIATING
void channel_timestamp_active(channel_t *chan)
#define ED25519_BASE64_LEN
#define MOCK_IMPL(rv, funcname, arglist)
static int connection_or_check_valid_tls_handshake(or_connection_t *conn, int started_here, char *digest_rcvd_out)
int var_cell_pack_header(const var_cell_t *cell, char *hdr_out, int wide_circ_ids)
void tor_tls_get_state_description(tor_tls_t *tls, char *buf, size_t sz)
void channel_tls_handle_cell(cell_t *cell, or_connection_t *conn)
int connection_or_reached_eof(or_connection_t *conn)
void channel_mark_client(channel_t *chan)
Header file for microdesc.c.
int ed25519_pubkey_eq(const ed25519_public_key_t *key1, const ed25519_public_key_t *key2)
Header file for router.c.
void connection_or_change_state(or_connection_t *conn, uint8_t state)
static void connection_or_tls_renegotiated_cb(tor_tls_t *tls, void *_conn)
void command_setup_listener(channel_listener_t *listener)
static void connection_or_state_publish(const or_connection_t *conn, uint8_t state)
int router_digest_is_me(const char *digest)
Header file for channel.c.
int control_event_or_conn_status(or_connection_t *conn, or_conn_status_event_t tp, int reason)
unsigned int started_here
void clear_broken_connection_map(int stop_recording)
@ PADDING_TYPE_ENABLED_CELL
void connection_or_clear_identity(or_connection_t *conn)
#define CASE_TOR_TLS_ERROR_ANY
void base16_encode(char *dest, size_t destlen, const char *src, size_t srclen)
const char * conn_state_to_string(int type, int state)
#define tor_fragile_assert()
int channel_is_better(channel_t *a, channel_t *b)
int connection_init_or_handshake_state(or_connection_t *conn, int started_here)
void learned_router_identity(const tor_addr_t *addr, uint16_t port, const char *digest, const ed25519_public_key_t *ed_id)
time_t channel_when_last_client(channel_t *chan)
const routerinfo_t * router_get_my_routerinfo(void)
static void set_uint8(void *cp, uint8_t v)
channel_listener_t * channel_tls_get_listener(void)
static void cell_unpack(cell_t *dest, const char *src, int wide_circ_ids)
#define OR_CONN_STATE_TLS_HANDSHAKING
Header file for reachability.c.
void * tor_reallocarray_(void *ptr, size_t sz1, size_t sz2)
unsigned int is_canonical
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)
void channel_close_from_lower_layer(channel_t *chan)
int is_or_protocol_version_known(uint16_t v)
const node_t * node_get_by_id(const char *identity_digest)
void smartlist_add(smartlist_t *sl, void *element)
void tor_addr_port_copy(tor_addr_port_t *dest, const tor_addr_port_t *source)
int router_digest_is_fallback_dir(const char *digest)
const char * tor_tls_get_last_error_msg(const tor_tls_t *tls)
void channel_tls_update_marks(or_connection_t *conn)
tor_cert_t * tor_cert_dup(const tor_cert_t *cert)
int ed25519_public_key_is_zero(const ed25519_public_key_t *pubkey)
void channel_mark_bad_for_new_circs(channel_t *chan)
void or_handshake_state_record_cell(or_connection_t *conn, or_handshake_state_t *state, const cell_t *cell, int incoming)
static unsigned int connection_or_is_bad_for_new_circs(or_connection_t *or_conn)
int tor_tls_peer_has_cert(tor_tls_t *tls)
static void connection_or_update_token_buckets_helper(or_connection_t *conn, int reset, const or_options_t *options)
const struct ed25519_public_key_t * connection_or_get_alleged_ed25519_id(const or_connection_t *conn)
var_cell_t * var_cell_copy(const var_cell_t *src)
int connection_or_finished_flushing(or_connection_t *conn)
int tor_tls_used_v1_handshake(tor_tls_t *tls)
int connection_or_process_inbuf(or_connection_t *conn)
void crypto_digest_add_bytes(crypto_digest_t *digest, const char *data, size_t len)
void connection_or_write_var_cell_to_buf(const var_cell_t *cell, or_connection_t *conn)
void var_cell_free_(var_cell_t *cell)
smartlist_t * smartlist_new(void)
Header file for reasons.c.
static void note_broken_connection(const char *state)
int tor_snprintf(char *str, size_t size, const char *format,...)
void connection_start_reading(connection_t *conn)
#define CELL_PAYLOAD_SIZE
int connection_proxy_connect(connection_t *conn, int type)
#define SMARTLIST_FOREACH(sl, type, var, cmd)
Header file for networkstatus.c.
void rep_hist_note_negotiated_link_proto(unsigned link_proto, int started_here)
Header file for scheduler*.c.
int connection_or_flushed_some(or_connection_t *conn)
const routerinfo_t * router_get_by_id_digest(const char *digest)
int node_ed25519_id_matches(const node_t *node, const ed25519_public_key_t *id)
Header file for dirlist.c.
Common functions for cryptographic routines.
void connection_or_clear_identity_map(void)
size_t buf_datalen(const buf_t *buf)
unsigned int digest_sent_data
int connection_tls_continue_handshake(or_connection_t *conn)
Header file for circuitlist.c.
Header file for mainloop.c.
#define MAX_REASONS_TO_REPORT
#define OR_CONN_STATE_OPEN
void connection_or_event_status(or_connection_t *conn, or_conn_status_event_t tp, int reason)
int errno_to_orconn_end_reason(int e)
Header file for circuitbuild.c.
or_connection_t * or_connection_new(int type, int socket_family)
@ PADDING_TYPE_ENABLED_TOTAL
Header file for command.c.
unsigned int hold_open_until_flushed
void connection_or_block_renegotiation(or_connection_t *conn)
#define tor_memneq(a, b, sz)
static uint32_t tor_addr_to_ipv4h(const tor_addr_t *a)
Header file for circuitbuild.c.
#define TIME_BEFORE_OR_CONN_IS_TOO_OLD
#define tor_assert_nonfatal_unreached()
const char * connection_describe_peer(const connection_t *conn)
unsigned int channelpadding_get_channel_idle_timeout(const channel_t *chan, int is_canonical)
void circuit_build_times_network_is_live(circuit_build_times_t *cbt)
int crypto_pk_get_digest(const crypto_pk_t *pk, char *digest_out)
#define VAR_CELL_MAX_HEADER_SIZE
const char * find_transport_name_by_bridge_addrport(const tor_addr_t *addr, uint16_t port)
int tor_digest_is_zero(const char *digest)
static int broken_state_count_compare(const void **a_ptr, const void **b_ptr)
networkstatus_t * networkstatus_get_reasonably_live_consensus(time_t now, int flavor)
int usable_consensus_flavor(void)
#define OR_CONN_STATE_PROXY_HANDSHAKING
Header file for directory authority mode.
smartlist_t * get_connection_array(void)
const char * tor_tls_err_to_string(int err)
int connection_or_single_set_badness_(time_t now, or_connection_t *or_conn, int force)
int connection_or_nonopen_was_started_here(or_connection_t *conn)
uint16_t marked_for_close
ssize_t connection_or_num_cells_writeable(or_connection_t *conn)
int connection_tls_start_handshake(or_connection_t *conn, int receiving)
Header file for nodelist.c.
int connection_or_set_state_open(or_connection_t *conn)
Header file for routerlist.c.
Header for feature/relay/relay_handshake.c.
or_handshake_certs_t * or_handshake_certs_new(void)
const routerstatus_t * router_get_consensus_status_by_id(const char *digest)
void assert_connection_ok(connection_t *conn, time_t now)
void channel_listener_queue_incoming(channel_listener_t *listener, channel_t *incoming)
Router descriptor structure.
Header file for circuitstats.c.
void token_bucket_rw_reset(token_bucket_rw_t *bucket, uint32_t now_ts)
void connection_start_writing(connection_t *conn)
Header file for buffers.c.
void connection_or_notify_error(or_connection_t *conn, int reason, const char *msg)
uint8_t payload[CELL_PAYLOAD_SIZE]
typedef HT_HEAD(hs_service_ht, hs_service_t) hs_service_ht
int tor_tls_is_server(tor_tls_t *tls)
#define OR_CONN_STATE_OR_HANDSHAKING_V2
static int connection_tls_finish_handshake(or_connection_t *conn)
channel_listener_t * channel_tls_start_listener(void)
struct ed25519_public_key_t ed25519_identity
crypto_digest_t * crypto_digest256_new(digest_algorithm_t algorithm)
void rep_hist_padding_count_write(padding_type_t type)
static int connection_or_launch_v3_or_handshake(or_connection_t *conn)
OR handshake certs structure.
char body[CELL_MAX_NETWORK_SIZE]
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)
void connection_free_(connection_t *conn)
void node_get_pref_ipv6_orport(const node_t *node, tor_addr_port_t *ap_out)
static int connection_fetch_var_cell_from_buf(or_connection_t *or_conn, var_cell_t **out)
Header file for control_events.c.
const or_options_t * get_options(void)
The or_state_t structure, which represents Tor's state file.
static const int n_or_protocol_versions
Variable-length cell structure.
Header file for circuitbuild.c.
void connection_watch_events(connection_t *conn, watchable_events_t events)
void tor_tls_set_logged_address(tor_tls_t *tls, const char *address)
static void connection_or_note_state_when_broken(or_connection_t *orconn)
static uint32_t get_uint32(const void *cp)
#define OR_CONN_STATE_OR_HANDSHAKING_V3
#define crypto_digest_free(d)
void connection_or_close_for_error(or_connection_t *orconn, int flush)
void scheduler_channel_wants_writes(channel_t *chan)
int connection_connect(connection_t *conn, const char *address, const tor_addr_t *addr, uint16_t port, int *socket_error)
int get_proxy_addrport(tor_addr_t *addr, uint16_t *port, int *proxy_type, int *is_pt_out, const connection_t *conn)
static int connection_or_process_cells_from_inbuf(or_connection_t *conn)
void channel_clear_identity_digest(channel_t *chan)
static void set_uint32(void *cp, uint32_t v)
#define IF_BUG_ONCE(cond)
channel_t * channel_tls_handle_incoming(or_connection_t *orconn)
#define OR_CONN_HIGHWATER
const char * connection_describe(const connection_t *conn)
static void connection_or_check_canonicity(or_connection_t *conn, int started_here)
int channel_is_bad_for_new_circs(channel_t *chan)
Header file for connection.c.
int connection_buf_get_bytes(char *string, size_t len, connection_t *conn)
Header file for channeltls.c.
int connection_read_proxy_handshake(connection_t *conn)
void connection_or_write_cell_to_buf(const cell_t *cell, or_connection_t *conn)
void connection_or_report_broken_states(int severity, int domain)
bool node_supports_ed25519_link_authentication(const node_t *node, bool compatible_with_us)
void connection_or_about_to_close(or_connection_t *or_conn)
uint32_t monotime_coarse_get_stamp(void)
int server_mode(const or_options_t *options)
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)
int tor_addr_is_null(const tor_addr_t *addr)
or_handshake_certs_t * certs
void connection_or_update_token_buckets(smartlist_t *conns, const or_options_t *options)
tor_addr_port_t canonical_orport
tor_tls_t * tor_tls_new(tor_socket_t sock, int is_server)
void token_bucket_rw_adjust(token_bucket_rw_t *bucket, uint32_t rate, uint32_t burst)
#define SMARTLIST_FOREACH_BEGIN(sl, type, var)
const char * node_get_nickname(const node_t *node)
void node_get_prim_orport(const node_t *node, tor_addr_port_t *ap_out)
int public_server_mode(const or_options_t *options)
static void connection_or_get_state_description(or_connection_t *orconn, char *buf, size_t buflen)
Header file for orconn_event.c.
struct tor_cert_st * own_link_cert
int tls_error_to_orconn_end_reason(int e)
int tor_tls_verify(int severity, tor_tls_t *tls, crypto_pk_t **identity)
static uint8_t get_uint8(const void *cp)
Fixed-size cell structure.
void channel_tls_handle_var_cell(var_cell_t *var_cell, or_connection_t *conn)
var_cell_t * var_cell_new(uint16_t payload_len)
int connection_or_digest_is_known_relay(const char *id_digest)
void cell_pack(packed_cell_t *dst, const cell_t *src, int wide_circ_ids)
HT_PROTOTYPE(hs_circuitmap_ht, circuit_t, hs_circuitmap_node, hs_circuit_hash_token, hs_circuits_have_same_token)
int router_ed25519_id_is_me(const ed25519_public_key_t *id)
int tor_tls_handshake(tor_tls_t *tls)
Header file for config.c.
static uint16_t get_uint16(const void *cp)
int authdir_mode_tests_reachability(const or_options_t *options)
void or_handshake_state_record_var_cell(or_connection_t *conn, or_handshake_state_t *state, const var_cell_t *cell, int incoming)
void control_event_bootstrap_prob_or(const char *warn, int reason, or_connection_t *or_conn)
void tor_tls_block_renegotiation(tor_tls_t *tls)
void channel_set_circid_type(channel_t *chan, crypto_pk_t *identity_rcvd, int consider_identity)
void tor_log(int severity, log_domain_mask_t domain, const char *format,...)
void connection_or_close_normally(or_connection_t *orconn, int flush)
static void set_uint16(void *cp, uint16_t v)
uint8_t payload[FLEXIBLE_ARRAY_MEMBER]
OR handshake state structure.
void tor_tls_set_renegotiate_callback(tor_tls_t *tls, void(*cb)(tor_tls_t *, void *arg), void *arg)
const char * orconn_end_reason_to_control_string(int r)
unsigned int channel_num_circuits(channel_t *chan)
void entry_guard_chan_failed(channel_t *chan)
static strmap_t * broken_connection_counts
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)
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_group_set_badness_(smartlist_t *group, int force)
channel_t * channel_tls_to_base(channel_tls_t *tlschan)
void smartlist_sort(smartlist_t *sl, int(*compare)(const void **a, const void **b))
#define tor_addr_to_in6_addr8(x)
static const uint16_t or_protocol_versions[]
char identity_digest[DIGEST_LEN]
or_connection_t * TO_OR_CONN(connection_t *c)
#define fast_memeq(a, b, c)
void channel_set_identity_digest(channel_t *chan, const char *identity_digest, const ed25519_public_key_t *ed_identity)
#define tor_addr_eq(a, b)
Header file for rendcommon.c.
Header file for rephist.c.
static void connection_or_set_identity_digest(or_connection_t *conn, const char *rsa_digest, const ed25519_public_key_t *ed_id)
Header file for connection_or.c.
static int disable_broken_connection_counts
void tor_addr_copy(tor_addr_t *dest, const tor_addr_t *src)
void channel_close_for_error(channel_t *chan)
Master header file for Tor-specific functionality.
uint64_t global_identifier
void channel_closed(channel_t *chan)
int connection_or_get_num_circuits(or_connection_t *conn)
void connection_or_connect_failed(or_connection_t *conn, int reason, const char *msg)