54#define CHANNEL_OBJECT_PRIVATE
57#define CHANNEL_FILE_PRIVATE
63#include "core/or/channelpadding.h"
70#include "core/or/dos.h"
123 channel_id_hash, channel_id_eq);
124HT_GENERATE2(channel_gid_map,
channel_t, gidmap_node,
125 channel_id_hash, channel_id_eq,
131static uint64_t n_channels_allocated = 0;
141static
HT_HEAD(channel_idmap, channel_idmap_entry_t) channel_identity_map =
144typedef struct channel_idmap_entry_t {
145 HT_ENTRY(channel_idmap_entry_t) node;
147 TOR_LIST_HEAD(channel_list_t,
channel_t) channel_list;
148} channel_idmap_entry_t;
150static inline unsigned
151channel_idmap_hash(
const channel_idmap_entry_t *ent)
153 return (
unsigned) siphash24g(ent->digest,
DIGEST_LEN);
157channel_idmap_eq(
const channel_idmap_entry_t *a,
158 const channel_idmap_entry_t *b)
163HT_PROTOTYPE(channel_idmap, channel_idmap_entry_t, node, channel_idmap_hash,
165HT_GENERATE2(channel_idmap, channel_idmap_entry_t, node, channel_idmap_hash,
328 descr =
"channel error";
331 descr =
"temporarily suspended for maintenance";
341 descr =
"unknown or invalid channel state";
363 descr =
"channel listener error";
370 descr =
"unknown or invalid channel listener state";
396 "Registering channel %p (ID %"PRIu64
") "
397 "in state %s (%d) with digest %s",
405 channel_t *oldval = HT_REPLACE(channel_gid_map, &channel_gid_map, chan);
409 if (CHANNEL_FINISHED(chan)) {
419 if (!CHANNEL_IS_CLOSING(chan)) {
426 "Channel %p (global ID %"PRIu64
") "
427 "in state %s (%d) registered with no identity digest",
453 if (CHANNEL_FINISHED(chan)) {
463 channel_t *oldval = HT_REMOVE(channel_gid_map, &channel_gid_map, chan);
471 !(CHANNEL_CONDEMNED(chan))) {
492 "Registering channel listener %p (ID %"PRIu64
") "
506 if (!finished_listeners) finished_listeners =
smartlist_new();
563 channel_idmap_entry_t *ent, search;
574 ent = HT_FIND(channel_idmap, &channel_identity_map, &search);
576 ent = tor_malloc(
sizeof(channel_idmap_entry_t));
578 TOR_LIST_INIT(&ent->channel_list);
579 HT_INSERT(channel_idmap, &channel_identity_map, ent);
581 TOR_LIST_INSERT_HEAD(&ent->channel_list, chan, next_with_same_id);
584 "Added channel %p (global ID %"PRIu64
") "
585 "to identity map in state %s (%d) with digest %s",
600 channel_idmap_entry_t *ent, search;
608 TOR_LIST_REMOVE(chan, next_with_same_id);
611 ent = HT_FIND(channel_idmap, &channel_identity_map, &search);
617 if (TOR_LIST_EMPTY(&ent->channel_list)) {
618 HT_REMOVE(channel_idmap, &channel_identity_map, ent);
623 "Removed channel %p (global ID %"PRIu64
") from "
624 "identity map in state %s (%d) with digest %s",
631 "Trying to remove channel %p (global ID %"PRIu64
") with "
632 "digest %s from identity map, but couldn't find any with "
657 rv = HT_FIND(channel_gid_map, &channel_gid_map, &lookup);
669 const char *rsa_id_digest,
702 channel_idmap_entry_t *ent, search;
713 memcpy(search.digest, rsa_id_digest,
DIGEST_LEN);
714 ent = HT_FIND(channel_idmap, &channel_identity_map, &search);
716 rv = TOR_LIST_FIRST(&ent->channel_list);
736 return TOR_LIST_NEXT(chan, next_with_same_id);
751 channel_idmap_entry_t **iter;
753 int total_dirauth_connections = 0, total_dirauths = 0;
754 int total_relay_connections = 0, total_relays = 0, total_canonical = 0;
755 int total_half_canonical = 0;
756 int total_gt_one_connection = 0, total_gt_two_connections = 0;
757 int total_gt_four_connections = 0;
759 HT_FOREACH(iter, channel_idmap, &channel_identity_map) {
760 int connections_to_relay = 0;
761 const char *id_digest = (
char *) (*iter)->digest;
769 const bool is_dirauth = router_digest_is_trusted_dir(id_digest);
773 for (chan = TOR_LIST_FIRST(&(*iter)->channel_list); chan;
776 if (CHANNEL_CONDEMNED(chan) || !CHANNEL_IS_OPEN(chan))
779 connections_to_relay++;
780 total_relay_connections++;
782 total_dirauth_connections++;
787 total_half_canonical++;
791 if (connections_to_relay > 1) total_gt_one_connection++;
792 if (connections_to_relay > 2) total_gt_two_connections++;
793 if (connections_to_relay > 4) total_gt_four_connections++;
799#define MIN_RELAY_CONNECTIONS_TO_WARN 25
803#define MAX_AVG_RELAY_CONNECTIONS 1.5
807#define MAX_AVG_DIRAUTH_CONNECTIONS 4
811 const int max_tolerable_connections = (int)(
812 (total_relays-total_dirauths) * MAX_AVG_RELAY_CONNECTIONS +
813 total_dirauths * MAX_AVG_DIRAUTH_CONNECTIONS);
816 if (total_relays > MIN_RELAY_CONNECTIONS_TO_WARN &&
817 total_relay_connections > max_tolerable_connections) {
819 "Your relay has a very large number of connections to other relays. "
820 "Is your outbound address the same as your relay address? "
821 "Found %d connections to authorities, %d connections to %d relays. "
822 "Found %d current canonical connections, "
823 "in %d of which we were a non-canonical peer. "
824 "%d relays had more than 1 connection, %d had more than 2, and "
825 "%d had more than 4 connections.",
826 total_dirauth_connections, total_relay_connections,
827 total_relays, total_canonical, total_half_canonical,
828 total_gt_one_connection, total_gt_two_connections,
829 total_gt_four_connections);
831 log_info(
LD_OR,
"Performed connection pruning. "
832 "Found %d connections to authorities, %d connections to %d relays. "
833 "Found %d current canonical connections, "
834 "in %d of which we were a non-canonical peer. "
835 "%d relays had more than 1 connection, %d had more than 2, and "
836 "%d had more than 4 connections.",
837 total_dirauth_connections, total_relay_connections,
838 total_relays, total_canonical, total_half_canonical,
839 total_gt_one_connection, total_gt_two_connections,
840 total_gt_four_connections);
866 memset(&chan->next_with_same_id, 0,
sizeof(chan->next_with_same_id));
918 "Freeing channel %"PRIu64
" at %p",
922 scheduler_release_channel(chan);
935 channel_handles_clear(chan);
946 circuitmux_free(chan->
cmux);
964 "Freeing channel_listener_t %"PRIu64
" at %p",
991 "Force-freeing channel %"PRIu64
" at %p",
995 scheduler_release_channel(chan);
1008 channel_handles_clear(chan);
1017 circuitmux_free(chan->
cmux);
1035 "Force-freeing channel_listener_t %"PRIu64
" at %p",
1051 } SMARTLIST_FOREACH_END(qchan);
1068 channel_listener_fn_ptr listener)
1074 "Setting listener callback for channel listener %p "
1075 "(global ID %"PRIu64
") to %p",
1089channel_cell_handler_fn_ptr
1094 if (CHANNEL_CAN_HANDLE_CELLS(chan))
1108 channel_cell_handler_fn_ptr cell_handler)
1114 "Setting cell_handler callback for channel %p to %p",
1115 chan, cell_handler);
1148 if (CHANNEL_CONDEMNED(chan))
1152 "Closing channel %p (global ID %"PRIu64
") "
1192 "Closing channel listener %p (global ID %"PRIu64
") "
1203 chan_l->
close(chan_l);
1226 if (CHANNEL_CONDEMNED(chan))
1230 "Closing channel %p (global ID %"PRIu64
") "
1231 "due to lower-layer event",
1254 if (CHANNEL_CONDEMNED(chan))
1258 "Closing channel %p due to lower-layer error",
1282 if (CHANNEL_FINISHED(chan))
1309 int state_not_in_map;
1314 "Clearing remote endpoint digest on channel %p with "
1315 "global ID %"PRIu64,
1318 state_not_in_map = CHANNEL_CONDEMNED(chan);
1337 const char *identity_digest,
1340 int was_in_digest_map, should_be_in_digest_map, state_not_in_map;
1345 "Setting remote endpoint digest on channel %p with "
1346 "global ID %"PRIu64
" to digest %s",
1351 state_not_in_map = CHANNEL_CONDEMNED(chan);
1354 !state_not_in_map &&
1357 should_be_in_digest_map =
1358 !state_not_in_map &&
1363 if (was_in_digest_map)
1369 if (identity_digest) {
1384 if (should_be_in_digest_map)
1397 int state_not_in_map;
1402 "Clearing remote endpoint identity on channel %p with "
1403 "global ID %"PRIu64,
1406 state_not_in_map = CHANNEL_CONDEMNED(chan);
1445 cell_bytes = get_cell_network_size(chan->wide_circ_ids);
1448 if (!CHANNEL_IS_OPEN(chan)) {
1460 chan->n_bytes_xmitted += cell_bytes;
1496 if (CHANNEL_IS_CLOSING(chan)) {
1497 log_debug(
LD_CHANNEL,
"Discarding %p on closing channel %p with "
1498 "global ID %"PRIu64, cell, chan,
1503 "Writing %p to channel %p with global ID "
1512 packed_cell_free(cell);
1527 unsigned char was_active, is_active;
1528 unsigned char was_in_id_map, is_in_id_map;
1531 from_state = chan->
state;
1538 if (from_state == to_state) {
1540 "Got no-op transition from \"%s\" to itself on channel %p"
1541 "(global ID %"PRIu64
")",
1555 "Changing state of channel %p (global ID %"PRIu64
1556 ") from \"%s\" to \"%s\"",
1562 chan->
state = to_state;
1572 if (was_active && !is_active) {
1574 if (!finished_channels) finished_channels =
smartlist_new();
1579 else if (!was_active && is_active) {
1595 else if (was_in_id_map && !is_in_id_map)
1607 scheduler_release_channel(chan);
1648 unsigned char was_active, is_active;
1651 from_state = chan_l->
state;
1658 if (from_state == to_state) {
1660 "Got no-op transition from \"%s\" to itself on channel "
1661 "listener %p (global ID %"PRIu64
")",
1675 "Changing state of channel listener %p (global ID %"PRIu64
1676 "from \"%s\" to \"%s\"",
1681 chan_l->
state = to_state;
1691 if (was_active && !is_active) {
1693 if (!finished_listeners) finished_listeners =
smartlist_new();
1698 else if (!was_active && is_active) {
1714#define MAX_CELLS_TO_GET_FROM_CIRCUITS_FOR_UNLIMITED 256
1737 unsigned int unlimited = 0;
1738 ssize_t flushed = 0;
1739 int clamped_num_cells;
1743 if (num_cells < 0) unlimited = 1;
1744 if (!unlimited && num_cells <= flushed)
goto done;
1747 if (CHANNEL_IS_OPEN(chan)) {
1751 clamped_num_cells = MAX_CELLS_TO_GET_FROM_CIRCUITS_FOR_UNLIMITED;
1753 if (num_cells - flushed >
1754 MAX_CELLS_TO_GET_FROM_CIRCUITS_FOR_UNLIMITED) {
1755 clamped_num_cells = MAX_CELLS_TO_GET_FROM_CIRCUITS_FOR_UNLIMITED;
1757 clamped_num_cells = (int)(num_cells - flushed);
1763 chan, clamped_num_cells);
1825 "Processing queue of incoming connections for channel "
1826 "listener %p (global ID %"PRIu64
")",
1836 "Handling incoming channel %p (%"PRIu64
") "
1837 "for listener %p (%"PRIu64
")",
1844 listener->
listener(listener, chan);
1845 } SMARTLIST_FOREACH_END(chan);
1868 int close_origin_circuits = 0;
1883 channel_tls_t *tlschan = BASE_CHAN_TO_TLS(chan);
1884 if (!tlschan->conn->tracked_for_dos_mitigation) {
1885 char *transport_name = NULL;
1886 if (chan->get_transport_name(chan, &transport_name) < 0) {
1887 transport_name = NULL;
1890 &remote_addr, transport_name,
1892 if (tlschan && tlschan->conn) {
1893 dos_new_client_conn(tlschan->conn, transport_name);
1907 }
else if (hs_service_allow_non_anonymous_connection(
get_options()) &&
1909 CHANNELPADDING_SOS_PARAM,
1910 CHANNELPADDING_SOS_DEFAULT, 0, 1)) {
1914 }
else if (
get_options()->ReducedConnectionPadding) {
1935 int need_to_queue = 0;
1942 "Queueing incoming channel %p (global ID %"PRIu64
") on "
1943 "channel listener %p (global ID %"PRIu64
")",
1948 if (!(listener->
listener)) need_to_queue = 1;
1964 if (!need_to_queue) {
1966 listener->
listener(listener, incoming);
1986 tor_assert(CHANNEL_IS_CLOSING(chan) || CHANNEL_IS_MAINT(chan) ||
1987 CHANNEL_IS_OPEN(chan));
1998 chan->n_bytes_recved += get_cell_network_size(chan->wide_circ_ids);
2001 "Processing incoming cell_t %p for channel %p (global ID "
2002 "%"PRIu64
")", cell, chan,
2016 if (chan->wide_circ_ids) {
2017 if (packed_cell->
body[4] == CELL_DESTROY) {
2022 if (packed_cell->
body[2] == CELL_DESTROY) {
2042 log_warn(
LD_BUG,
"Attempted to send a destroy cell for circID 0 "
2043 "on a channel %"PRIu64
" at %p in state %s (%d)",
2051 if (!CHANNEL_CONDEMNED(chan) && chan->
cmux) {
2053 circuitmux_append_destroy_cell(chan, chan->
cmux, circ_id, reason);
2055 "Sending destroy (circID %u) on channel %p "
2056 "(global ID %"PRIu64
")",
2057 (
unsigned)circ_id, chan,
2061 "Someone called channel_send_destroy() for circID %u "
2062 "on a channel %"PRIu64
" at %p in state %s (%d)",
2080 if (all_channels && smartlist_len(all_channels) > 0) {
2082 "Dumping statistics about %d channels:",
2083 smartlist_len(all_channels));
2085 "%d are active, and %d are done and waiting for cleanup",
2086 (active_channels != NULL) ?
2087 smartlist_len(active_channels) : 0,
2088 (finished_channels != NULL) ?
2089 smartlist_len(finished_channels) : 0);
2095 "Done spamming about channels now");
2098 "No channels to dump");
2111 if (all_listeners && smartlist_len(all_listeners) > 0) {
2113 "Dumping statistics about %d channel listeners:",
2114 smartlist_len(all_listeners));
2116 "%d are active and %d are done and waiting for cleanup",
2117 (active_listeners != NULL) ?
2118 smartlist_len(active_listeners) : 0,
2119 (finished_listeners != NULL) ?
2120 smartlist_len(finished_listeners) : 0);
2126 "Done spamming about channel listeners now");
2129 "No channel listeners to dump");
2145 if (!finished_channels || smartlist_len(finished_channels) == 0)
return;
2156 } SMARTLIST_FOREACH_END(curr);
2171 if (!finished_listeners || smartlist_len(finished_listeners) == 0)
return;
2181 channel_listener_free(tmp);
2182 } SMARTLIST_FOREACH_END(curr);
2191 if (!channels)
return;
2197 "Cleaning up channel %p (global ID %"PRIu64
") "
2199 curr, (curr->global_identifier),
2207 if (mark_for_close) {
2208 if (!CHANNEL_CONDEMNED(curr)) {
2212 }
else channel_free(curr);
2213 } SMARTLIST_FOREACH_END(curr);
2222 if (!listeners)
return;
2228 "Cleaning up channel listener %p (global ID %"PRIu64
") "
2230 curr, (curr->global_identifier),
2233 if (mark_for_close) {
2240 }
else channel_listener_free(curr);
2241 } SMARTLIST_FOREACH_END(curr);
2256 "Shutting down channels...");
2259 if (finished_channels) {
2261 smartlist_free(finished_channels);
2262 finished_channels = NULL;
2266 if (finished_listeners) {
2268 smartlist_free(finished_listeners);
2269 finished_listeners = NULL;
2273 if (active_channels) {
2275 smartlist_free(active_channels);
2276 active_channels = NULL;
2280 if (active_listeners) {
2282 smartlist_free(active_listeners);
2283 active_listeners = NULL;
2289 smartlist_free(all_channels);
2290 all_channels = NULL;
2294 if (all_listeners) {
2296 smartlist_free(all_listeners);
2297 all_listeners = NULL;
2302 "Freeing channel_identity_map");
2304 HT_CLEAR(channel_idmap, &channel_identity_map);
2308 "Freeing channel_gid_map");
2309 HT_CLEAR(channel_gid_map, &channel_gid_map);
2312 "Done cleaning up after channels");
2327 const char *id_digest,
2346 int a_is_canonical, b_is_canonical;
2362 if (a_is_canonical && !b_is_canonical)
return 1;
2363 if (!a_is_canonical && b_is_canonical)
return 0;
2414 bool for_origin_circ,
2415 const char **msg_out,
2419 int n_inprogress_goodaddr = 0, n_old = 0;
2420 int n_noncanonical = 0;
2432 if (CHANNEL_CONDEMNED(chan))
2446 const bool matches_target =
2451 if (!CHANNEL_IS_OPEN(chan)) {
2454 if (matches_target) {
2455 ++n_inprogress_goodaddr;
2456 if (for_origin_circ) {
2489 *msg_out =
"Connection is fine; using it.";
2492 }
else if (n_inprogress_goodaddr) {
2493 *msg_out =
"Connection in progress; waiting.";
2496 }
else if (n_old || n_noncanonical) {
2497 *msg_out =
"Connections all too old, or too non-canonical. "
2498 " Launching a new one.";
2502 *msg_out =
"Not connected. Connecting.";
2546 double avg, interval, age;
2547 time_t now = time(NULL);
2549 int have_remote_addr;
2550 char *remote_addr_str;
2557 "Channel %"PRIu64
" (at %p) with transport %s is in state "
2563 " * Channel %"PRIu64
" was created at %"PRIu64
2564 " (%"PRIu64
" seconds ago) "
2565 "and last active at %"PRIu64
" (%"PRIu64
" seconds ago)",
2569 (uint64_t)(chan->timestamp_active),
2570 (uint64_t)(now - chan->timestamp_active));
2575 " * Channel %"PRIu64
" says it is connected "
2576 "to an OR with digest %s",
2581 " * Channel %"PRIu64
" does not know the digest"
2582 " of the OR it is connected to",
2588 if (have_remote_addr) {
2592 " * Channel %"PRIu64
" says its remote address"
2593 " is %s, and gives a canonical description of \"%s\" and an "
2594 "actual description of \"%s\"",
2596 safe_str(remote_addr_str),
2604 " * Channel %"PRIu64
" does not know its remote "
2605 "address, but gives a canonical description of \"%s\" and an "
2606 "actual description of \"%s\"",
2615 " * Channel %"PRIu64
" has these marks: %s %s %s %s %s",
2618 "bad_for_new_circs" :
"!bad_for_new_circs",
2620 "canonical" :
"!canonical",
2622 "client" :
"!client",
2626 "incoming" :
"outgoing");
2630 " * Channel %"PRIu64
" has %d active circuits out of"
2633 (chan->
cmux != NULL) ?
2635 (chan->
cmux != NULL) ?
2641 " * Channel %"PRIu64
" was never used by a "
2645 " * Channel %"PRIu64
" was last used by a "
2646 "client at %"PRIu64
" (%"PRIu64
" seconds ago)",
2653 " * Channel %"PRIu64
" never received a cell",
2657 " * Channel %"PRIu64
" last received a cell "
2658 "at %"PRIu64
" (%"PRIu64
" seconds ago)",
2665 " * Channel %"PRIu64
" never transmitted a cell",
2669 " * Channel %"PRIu64
" last transmitted a cell "
2670 "at %"PRIu64
" (%"PRIu64
" seconds ago)",
2678 " * Channel %"PRIu64
" has received "
2679 "%"PRIu64
" bytes in %"PRIu64
" cells and transmitted "
2680 "%"PRIu64
" bytes in %"PRIu64
" cells",
2682 (chan->n_bytes_recved),
2684 (chan->n_bytes_xmitted),
2688 if (chan->n_bytes_recved > 0) {
2689 avg = (double)(chan->n_bytes_recved) / age;
2691 " * Channel %"PRIu64
" has averaged %f "
2692 "bytes received per second",
2699 " * Channel %"PRIu64
" has averaged %f "
2700 "cells received per second",
2702 }
else if (avg >= 0.0) {
2703 interval = 1.0 / avg;
2705 " * Channel %"PRIu64
" has averaged %f "
2706 "seconds between received cells",
2710 if (chan->n_bytes_xmitted > 0) {
2711 avg = (double)(chan->n_bytes_xmitted) / age;
2713 " * Channel %"PRIu64
" has averaged %f "
2714 "bytes transmitted per second",
2721 " * Channel %"PRIu64
" has averaged %f "
2722 "cells transmitted per second",
2724 }
else if (avg >= 0.0) {
2725 interval = 1.0 / avg;
2727 " * Channel %"PRIu64
" has averaged %f "
2728 "seconds between transmitted cells",
2746 double avg, interval, age;
2747 time_t now = time(NULL);
2754 "Channel listener %"PRIu64
" (at %p) with transport %s is in "
2760 " * Channel listener %"PRIu64
" was created at %"PRIu64
2761 " (%"PRIu64
" seconds ago) "
2762 "and last active at %"PRIu64
" (%"PRIu64
" seconds ago)",
2766 (uint64_t)(chan_l->timestamp_active),
2767 (uint64_t)(now - chan_l->timestamp_active));
2770 " * Channel listener %"PRIu64
" last accepted an incoming "
2771 "channel at %"PRIu64
" (%"PRIu64
" seconds ago) "
2772 "and has accepted %"PRIu64
" channels in total",
2788 " * Channel listener %"PRIu64
" has averaged %f incoming "
2789 "channels per second",
2791 }
else if (avg >= 0.0) {
2792 interval = 1.0 / avg;
2794 " * Channel listener %"PRIu64
" has averaged %f seconds "
2795 "between incoming channels",
2866 return chan->get_remote_addr(chan, addr_out);
3090 result = chan->num_cells_writeable(chan);
3091 if (result < 0) result = 0;
3113 time_t now = time(NULL);
3129 time_t now = time(NULL);
3149 time_t now = time(NULL);
3154 chan->timestamp_active = now;
3166 time_t now = time(NULL);
3170 chan_l->timestamp_active = now;
3183 time_t now = time(NULL);
3187 chan_l->timestamp_active = now;
3200 time_t now = time(NULL);
3216 time_t now = time(NULL);
3220 chan->timestamp_active = now;
3236 time_t now = time(NULL);
3241 chan->timestamp_active = now;
3322 IF_BUG_ONCE(!target_ipv4_addr && !target_ipv6_addr)
3325 if (target_ipv4_addr && chan->
matches_target(chan, target_ipv4_addr))
3328 if (target_ipv6_addr && chan->
matches_target(chan, target_ipv6_addr))
3346 chan->num_p_circuits;
3358 int consider_identity))
3367 if (! consider_identity) {
3375 our_identity = started_here ?
3378 if (identity_rcvd) {
3390channel_sort_by_ed25519_identity(
const void **a_,
const void **b_)
3395 &b->ed25519_identity.pubkey,
3413 if (PREDICT_LIKELY(!TOR_LIST_NEXT(chan, next_with_same_id))) {
3415 time(NULL), BASE_CHAN_TO_TLS(chan)->conn, force);
3421 TOR_LIST_FOREACH(chan, lst, next_with_same_id) {
3422 if (BASE_CHAN_TO_TLS(chan)->conn) {
3435 if (!common_ed25519_identity)
3436 common_ed25519_identity = &channel->ed25519_identity;
3439 common_ed25519_identity)) {
3442 common_ed25519_identity = &channel->ed25519_identity;
3446 } SMARTLIST_FOREACH_END(channel);
3453 smartlist_free(or_conns);
3454 smartlist_free(channels);
3466 channel_idmap_entry_t *ent;
3467 channel_idmap_entry_t search;
3468 memset(&search, 0,
sizeof(search));
3470 ent = HT_FIND(channel_idmap, &channel_identity_map, &search);
3478 channel_idmap_entry_t **iter;
3479 HT_FOREACH(iter, channel_idmap, &channel_identity_map) {
void tor_addr_make_unspec(tor_addr_t *a)
char * tor_addr_to_str_dup(const tor_addr_t *addr)
const char * hex_str(const char *from, size_t fromlen)
static uint16_t get_uint16(const void *cp)
static uint32_t get_uint32(const void *cp)
int channel_has_queued_writes(channel_t *chan)
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)
static void channel_remove_from_digest_map(channel_t *chan)
int channel_is_outgoing(channel_t *chan)
void channel_listener_process_incoming(channel_listener_t *listener)
void channel_timestamp_recv(channel_t *chan)
void channel_run_cleanup(void)
void channel_update_bad_for_new_circs(const char *digest, int force)
void channel_dumpstats(int severity)
void channel_timestamp_client(channel_t *chan)
void channel_set_identity_digest(channel_t *chan, const char *identity_digest, const ed25519_public_key_t *ed_identity)
void channel_listener_unregister(channel_listener_t *chan_l)
void channel_listener_dump_statistics(channel_listener_t *chan_l, int severity)
void channel_mark_local(channel_t *chan)
void channel_set_cell_handlers(channel_t *chan, channel_cell_handler_fn_ptr cell_handler)
void channel_mark_client(channel_t *chan)
time_t channel_when_last_xmit(channel_t *chan)
void channel_listener_run_cleanup(void)
static void channel_force_xfree(channel_t *chan)
void channel_mark_incoming(channel_t *chan)
void channel_closed(channel_t *chan)
void channel_init_listener(channel_listener_t *chan_l)
int channel_listener_state_can_transition(channel_listener_state_t from, channel_listener_state_t to)
STATIC void channel_add_to_digest_map(channel_t *chan)
int channel_state_is_valid(channel_state_t state)
channel_t * channel_get_for_extend(const char *rsa_id_digest, const ed25519_public_key_t *ed_id, const tor_addr_t *target_ipv4_addr, const tor_addr_t *target_ipv6_addr, bool for_origin_circ, const char **msg_out, int *launch_out)
void channel_do_open_actions(channel_t *chan)
void channel_listener_mark_for_close(channel_listener_t *chan_l)
void channel_close_from_lower_layer(channel_t *chan)
void channel_check_for_duplicates(void)
void channel_process_cell(channel_t *chan, cell_t *cell)
void channel_change_state_open(channel_t *chan)
void channel_listener_queue_incoming(channel_listener_t *listener, channel_t *incoming)
int channel_is_canonical(channel_t *chan)
int channel_listener_state_is_valid(channel_listener_state_t state)
const char * channel_state_to_string(channel_state_t state)
void channel_timestamp_created(channel_t *chan)
static void channel_free_list(smartlist_t *channels, int mark_for_close)
int channel_matches_extend_info(channel_t *chan, extend_info_t *extend_info)
int channel_state_can_transition(channel_state_t from, channel_state_t to)
const char * channel_describe_transport(channel_t *chan)
int channel_remote_identity_matches(const channel_t *chan, const char *rsa_id_digest, const ed25519_public_key_t *ed_id)
void channel_listener_set_listener_fn(channel_listener_t *chan_l, channel_listener_fn_ptr listener)
void channel_register(channel_t *chan)
time_t channel_when_last_client(channel_t *chan)
void channel_listener_timestamp_created(channel_listener_t *chan_l)
void channel_listener_timestamp_active(channel_listener_t *chan_l)
void channel_listener_register(channel_listener_t *chan_l)
const char * channel_listener_describe_transport(channel_listener_t *chan_l)
void channel_listener_dump_transport_statistics(channel_listener_t *chan_l, int severity)
static void channel_change_state_(channel_t *chan, channel_state_t to_state)
static HT_HEAD(channel_gid_map, channel_t)
int channel_send_destroy(circid_t circ_id, channel_t *chan, int reason)
channel_t * channel_connect(const tor_addr_t *addr, uint16_t port, const char *id_digest, const ed25519_public_key_t *ed_id)
void channel_mark_bad_for_new_circs(channel_t *chan)
int channel_is_incoming(channel_t *chan)
int channel_is_client(const channel_t *chan)
const char * channel_listener_state_to_string(channel_listener_state_t state)
channel_t * channel_find_by_remote_identity(const char *rsa_id_digest, const ed25519_public_key_t *ed_id)
void channel_mark_remote(channel_t *chan)
void channel_unregister(channel_t *chan)
static void channel_rsa_id_group_set_badness(struct channel_list_t *lst, int force)
channel_cell_handler_fn_ptr channel_get_cell_handler(channel_t *chan)
ssize_t channel_flush_some_cells(channel_t *chan, ssize_t num_cells)
static void channel_listener_free_list(smartlist_t *channels, int mark_for_close)
int packed_cell_is_destroy(channel_t *chan, const packed_cell_t *packed_cell, circid_t *circid_out)
STATIC bool channel_matches_target_addr_for_extend(channel_t *chan, const tor_addr_t *target_ipv4_addr, const tor_addr_t *target_ipv6_addr)
void channel_close_for_error(channel_t *chan)
void channel_listener_free_(channel_listener_t *chan_l)
void channel_listener_dumpstats(int severity)
static int write_packed_cell(channel_t *chan, packed_cell_t *cell)
int channel_is_local(channel_t *chan)
void channel_listener_timestamp_accepted(channel_listener_t *chan_l)
void channel_notify_flushed(channel_t *chan)
int channel_num_cells_writeable(channel_t *chan)
channel_t * channel_find_by_global_id(uint64_t global_identifier)
void channel_timestamp_xmit(channel_t *chan)
int channel_get_addr_if_possible(const channel_t *chan, tor_addr_t *addr_out)
channel_t * channel_next_with_rsa_identity(channel_t *chan)
const char * channel_describe_peer(channel_t *chan)
void channel_mark_for_close(channel_t *chan)
void channel_clear_identity_digest(channel_t *chan)
void channel_clear_remote_end(channel_t *chan)
void channel_listener_change_state(channel_listener_t *chan_l, channel_listener_state_t to_state)
void channel_mark_outgoing(channel_t *chan)
static void channel_listener_force_xfree(channel_listener_t *chan_l)
void channel_dump_statistics(channel_t *chan, int severity)
void channel_free_all(void)
int channel_more_to_flush(channel_t *chan)
void channel_dump_transport_statistics(channel_t *chan, int severity)
unsigned int channel_num_circuits(channel_t *chan)
void channel_clear_client(channel_t *chan)
int channel_write_packed_cell(channel_t *chan, packed_cell_t *cell)
time_t channel_when_created(channel_t *chan)
void channel_init(channel_t *chan)
void channel_free_(channel_t *chan)
void channel_change_state(channel_t *chan, channel_state_t to_state)
Header file for channel.c.
void channel_mark_as_used_for_origin_circuit(channel_t *chan)
@ CHANNEL_LISTENER_STATE_ERROR
@ CHANNEL_LISTENER_STATE_LAST
@ CHANNEL_LISTENER_STATE_LISTENING
@ CHANNEL_LISTENER_STATE_CLOSING
@ CHANNEL_LISTENER_STATE_CLOSED
void channelpadding_disable_padding_on_channel(channel_t *chan)
void channelpadding_reduce_padding_on_channel(channel_t *chan)
channel_t * channel_tls_connect(const tor_addr_t *addr, uint16_t port, const char *id_digest, const ed25519_public_key_t *ed_id)
Header file for channeltls.c.
void circuit_n_chan_done(channel_t *chan, int status, int close_origin_circuits)
Header file for circuitbuild.c.
void channel_note_destroy_pending(channel_t *chan, circid_t id)
void channel_note_destroy_not_pending(channel_t *chan, circid_t id)
void circuit_unlink_all_from_channel(channel_t *chan, int reason)
Header file for circuitlist.c.
void circuitmux_mark_destroyed_circids_usable(circuitmux_t *cmux, channel_t *chan)
void circuitmux_detach_all_circuits(circuitmux_t *cmux, smartlist_t *detached_out)
void circuitmux_set_policy(circuitmux_t *cmux, const circuitmux_policy_t *pol)
unsigned int circuitmux_num_active_circuits(circuitmux_t *cmux)
unsigned int circuitmux_num_circuits(circuitmux_t *cmux)
unsigned int circuitmux_num_cells(circuitmux_t *cmux)
Header file for circuitmux.c.
circuit_build_times_t * get_circuit_build_times_mutable(void)
void circuit_build_times_network_is_live(circuit_build_times_t *cbt)
Header file for circuitstats.c.
Functions and types for monotonic times.
const or_options_t * get_options(void)
tor_cmdline_mode_t command
Header file for config.c.
int connection_or_single_set_badness_(time_t now, or_connection_t *or_conn, int force)
int connection_or_digest_is_known_relay(const char *id_digest)
void connection_or_group_set_badness_(smartlist_t *group, int force)
Header file for connection_or.c.
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_cmp_keys(const crypto_pk_t *a, const crypto_pk_t *b)
int tor_memeq(const void *a, const void *b, size_t sz)
#define fast_memcmp(a, b, c)
#define tor_memneq(a, b, sz)
Header file for dirlist.c.
Header file for circuitbuild.c.
Header file for geoip_stats.c.
@ DIRREQ_CHANNEL_BUFFER_FLUSHED
void geoip_change_dirreq_state(uint64_t dirreq_id, dirreq_type_t type, dirreq_state_t new_state)
void geoip_note_client_seen(geoip_client_action_t action, const tor_addr_t *addr, const char *transport_name, time_t now)
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.
void tor_log(int severity, log_domain_mask_t domain, const char *format,...)
void mainloop_schedule_postloop_cleanup(void)
Header file for mainloop.c.
void * tor_reallocarray_(void *ptr, size_t sz1, size_t sz2)
void tor_free_(void *mem)
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 router_set_status(const char *digest, int up)
Header file for nodelist.c.
Master header file for Tor-specific functionality.
int channel_flush_from_first_active_circuit(channel_t *chan, int max)
uint8_t packed_cell_get_command(const packed_cell_t *cell, int wide_circ_ids)
void rep_hist_padding_count_write(padding_type_t type)
Header file for rephist.c.
@ PADDING_TYPE_ENABLED_CELL
@ PADDING_TYPE_ENABLED_TOTAL
crypto_pk_t * get_tlsclient_identity_key(void)
Header file for router.c.
Header file for routerlist.c.
void scheduler_channel_doesnt_want_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)
void smartlist_clear(smartlist_t *sl)
void smartlist_remove(smartlist_t *sl, const void *element)
#define SMARTLIST_FOREACH_BEGIN(sl, type, var)
#define SMARTLIST_FOREACH(sl, type, var, cmd)
#define SMARTLIST_DEL_CURRENT(sl, var)
channel_listener_state_t state
const char *(* describe_transport)(channel_listener_t *)
enum channel_listener_t::@10 reason_for_closing
void(* dumpstats)(channel_listener_t *, int)
uint64_t global_identifier
void(* free_fn)(channel_listener_t *)
smartlist_t * incoming_list
channel_listener_fn_ptr listener
time_t timestamp_accepted
void(* close)(channel_listener_t *)
void(* free_fn)(channel_t *)
int(* is_canonical)(channel_t *)
void(* close)(channel_t *)
monotime_coarse_t next_padding_time
void(* dumpstats)(channel_t *, int)
time_t timestamp_last_had_circuits
unsigned int num_n_circuits
int(* matches_extend_info)(channel_t *, extend_info_t *)
enum channel_t::@9 scheduler_state
circ_id_type_bitfield_t circ_id_type
unsigned int padding_enabled
char identity_digest[DIGEST_LEN]
uint64_t global_identifier
int(* write_packed_cell)(channel_t *, packed_cell_t *)
struct channel_handle_t * timer_handle
const char *(* describe_transport)(channel_t *)
tor_addr_t addr_according_to_peer
channel_cell_handler_fn_ptr cell_handler
int(* matches_target)(channel_t *, const tor_addr_t *)
const char *(* describe_peer)(const channel_t *)
struct ed25519_public_key_t ed25519_identity
unsigned int has_been_open
monotime_coarse_t timestamp_xfer
unsigned int is_bad_for_new_circs
unsigned int is_canonical_to_peer
struct tor_timer_t * padding_timer
ratelim_t last_warned_circ_ids_exhausted
int(* has_queued_writes)(channel_t *)
enum channel_t::@8 reason_for_closing
char body[CELL_MAX_NETWORK_SIZE]
#define MOCK_IMPL(rv, funcname, arglist)
#define IF_BUG_ONCE(cond)
int tor_digest_is_zero(const char *digest)
#define ED25519_PUBKEY_LEN