54 #include "feature/client/circpathbias.h"
95 #include "core/or/or_circuit_st.h"
120 #define CELL_QUEUE_HIGHWATER_SIZE 256
123 #define CELL_QUEUE_LOWWATER_SIZE 64
197 if (BUG(!or_circ->
p_chan))
202 if (cell->
command == CELL_RELAY_EARLY) {
206 }
else if (cell->
command == CELL_RELAY) {
244 "relay crypt failed. Dropping connection.");
245 return -END_CIRC_REASON_INTERNAL;
255 sendme_record_received_cell_digest(circ, layer_hint);
270 log_debug(
LD_OR,
"Sending away from origin.");
274 "connection_edge_process_relay_cell (away from origin) "
281 log_debug(
LD_OR,
"Sending to origin.");
290 "connection_edge_process_relay_cell (at origin) failed.");
309 "Dropping unrecognized inbound cell on origin circuit.");
315 return -END_CIRC_REASON_TORPROTOCOL;
333 log_warn(
LD_REND,
"Error relaying cell across rendezvous; closing "
336 circuit_mark_for_close(circ, -reason);
342 "Didn't recognize cell, but circ stops here! Closing circ.");
343 return -END_CIRC_REASON_TORPROTOCOL;
346 log_debug(
LD_OR,
"Passing on unrecognized cell.");
364 const char *filename,
int lineno))
376 log_warn(
LD_BUG,
"outgoing relay cell sent from %s:%d has n_chan==NULL."
377 " Dropping. Circuit is in state %s (%d), and is "
378 "%smarked for close. (%s:%d, %d)", filename, lineno,
390 log_warn(
LD_BUG,
"outgoing relay cell sent from %s:%d on non-origin "
391 "circ. Dropping.", filename, lineno);
407 log_warn(
LD_BUG,
"incoming relay cell at origin circuit. Dropping.");
455 log_debug(LD_EXIT,
"found conn for stream %d.", rh.
stream_id);
461 for (tmpconn =
TO_OR_CIRCUIT(circ)->resolving_streams; tmpconn;
465 log_debug(LD_EXIT,
"found conn for stream %d.", rh.
stream_id);
506 case RELAY_COMMAND_BEGIN:
return "BEGIN";
507 case RELAY_COMMAND_DATA:
return "DATA";
508 case RELAY_COMMAND_END:
return "END";
509 case RELAY_COMMAND_CONNECTED:
return "CONNECTED";
510 case RELAY_COMMAND_SENDME:
return "SENDME";
511 case RELAY_COMMAND_EXTEND:
return "EXTEND";
512 case RELAY_COMMAND_EXTENDED:
return "EXTENDED";
513 case RELAY_COMMAND_TRUNCATE:
return "TRUNCATE";
514 case RELAY_COMMAND_TRUNCATED:
return "TRUNCATED";
515 case RELAY_COMMAND_DROP:
return "DROP";
516 case RELAY_COMMAND_RESOLVE:
return "RESOLVE";
517 case RELAY_COMMAND_RESOLVED:
return "RESOLVED";
518 case RELAY_COMMAND_BEGIN_DIR:
return "BEGIN_DIR";
519 case RELAY_COMMAND_ESTABLISH_INTRO:
return "ESTABLISH_INTRO";
520 case RELAY_COMMAND_ESTABLISH_RENDEZVOUS:
return "ESTABLISH_RENDEZVOUS";
521 case RELAY_COMMAND_INTRODUCE1:
return "INTRODUCE1";
522 case RELAY_COMMAND_INTRODUCE2:
return "INTRODUCE2";
523 case RELAY_COMMAND_RENDEZVOUS1:
return "RENDEZVOUS1";
524 case RELAY_COMMAND_RENDEZVOUS2:
return "RENDEZVOUS2";
525 case RELAY_COMMAND_INTRO_ESTABLISHED:
return "INTRO_ESTABLISHED";
526 case RELAY_COMMAND_RENDEZVOUS_ESTABLISHED:
527 return "RENDEZVOUS_ESTABLISHED";
528 case RELAY_COMMAND_INTRODUCE_ACK:
return "INTRODUCE_ACK";
529 case RELAY_COMMAND_EXTEND2:
return "EXTEND2";
530 case RELAY_COMMAND_EXTENDED2:
return "EXTENDED2";
531 case RELAY_COMMAND_PADDING_NEGOTIATE:
return "PADDING_NEGOTIATE";
532 case RELAY_COMMAND_PADDING_NEGOTIATED:
return "PADDING_NEGOTIATED";
534 tor_snprintf(buf,
sizeof(buf),
"Unrecognized relay command %u",
542 #define CELL_PADDING_GAP 4
579 pad_cell_payload(uint8_t *cell_payload,
size_t data_len)
581 size_t pad_offset, pad_len;
586 if (pad_offset == 0) {
595 cell_payload + pad_offset, pad_len);
609 uint8_t relay_command,
const char *payload,
611 const char *filename,
int lineno))
621 memset(&cell, 0,
sizeof(
cell_t));
633 memset(&rh, 0,
sizeof(rh));
642 pad_cell_payload(cell.
payload, payload_len);
644 log_debug(
LD_OR,
"delivering %d cell %s.", relay_command,
652 if (relay_command == RELAY_COMMAND_END && circ->
dirreq_id)
664 (relay_command == RELAY_COMMAND_EXTEND ||
665 relay_command == RELAY_COMMAND_EXTEND2 ||
666 cpath_layer != origin_circ->
cpath)) {
671 cell.
command = CELL_RELAY_EARLY;
675 log_debug(
LD_OR,
"Sending a RELAY_EARLY cell; %d remaining.",
681 }
else if (relay_command == RELAY_COMMAND_EXTEND ||
682 relay_command == RELAY_COMMAND_EXTEND2) {
688 char *commands = NULL;
693 log_warn(
LD_BUG,
"Uh-oh. We're sending a RELAY_COMMAND_EXTEND cell, "
694 "but we have run out of RELAY_EARLY cells on that circuit. "
695 "Commands sent before: %s", commands);
697 smartlist_free(commands_list);
706 stream_id, filename, lineno) < 0) {
707 log_warn(
LD_BUG,
"circuit_package_relay_cell failed. Closing.");
708 circuit_mark_for_close(circ, END_CIRC_REASON_INTERNAL);
715 if (relay_command == RELAY_COMMAND_DATA) {
716 sendme_record_cell_digest_on_circ(circ, cpath_layer);
733 uint8_t relay_command,
const char *payload,
744 "called on conn that's already marked for close at %s:%d.",
752 log_info(
LD_APP,
"no circ. Closing conn.");
754 END_STREAM_REASON_INTERNAL);
756 log_info(LD_EXIT,
"no circ. Closing conn.");
758 fromconn->
end_reason = END_STREAM_REASON_INTERNAL;
759 connection_mark_for_close(
TO_CONN(fromconn));
770 #ifdef MEASUREMENTS_21206
780 return relay_send_command_from_edge(fromconn->
stream_id, circ,
781 relay_command, payload,
782 payload_len, cpath_layer);
788 #define MAX_RESOLVE_FAILURES 3
795 return reason == END_STREAM_REASON_HIBERNATING ||
796 reason == END_STREAM_REASON_RESOURCELIMIT ||
797 reason == END_STREAM_REASON_EXITPOLICY ||
798 reason == END_STREAM_REASON_RESOLVEFAILED ||
799 reason == END_STREAM_REASON_MISC ||
800 reason == END_STREAM_REASON_NOROUTE;
819 if (reason == END_STREAM_REASON_TORPROTOCOL ||
820 reason == END_STREAM_REASON_DESTROY) {
825 return -END_CIRC_REASON_TORPROTOCOL;
826 }
else if (reason == END_STREAM_REASON_INTERNAL) {
844 reason = END_STREAM_REASON_MISC;
852 const char *chosen_exit_digest =
854 log_info(
LD_APP,
"Address '%s' refused due to '%s'. Considering retrying.",
859 case END_STREAM_REASON_EXITPOLICY: {
877 log_info(
LD_APP,
"Address '%s' resolved to 0.0.0.0. Closing,",
879 connection_mark_unattached_ap(conn, END_STREAM_REASON_TORPROTOCOL);
884 !conn->entry_cfg.ipv4_traffic) ||
886 !conn->entry_cfg.ipv6_traffic)) {
888 "Got an EXITPOLICY failure on a connection with a "
889 "mismatched family. Closing.");
890 connection_mark_unattached_ap(conn, END_STREAM_REASON_TORPROTOCOL);
893 if (
get_options()->ClientDNSRejectInternalAddresses &&
894 tor_addr_is_internal(&addr, 0)) {
895 log_info(
LD_APP,
"Address '%s' resolved to internal. Closing,",
897 connection_mark_unattached_ap(conn, END_STREAM_REASON_TORPROTOCOL);
941 case END_STREAM_REASON_CONNECTREFUSED:
947 case END_STREAM_REASON_RESOLVEFAILED:
948 case END_STREAM_REASON_TIMEOUT:
949 case END_STREAM_REASON_MISC:
950 case END_STREAM_REASON_NOROUTE:
968 "Have tried resolving or connecting to address '%s' "
969 "at %d different places. Giving up.",
976 case END_STREAM_REASON_HIBERNATING:
977 case END_STREAM_REASON_RESOURCELIMIT:
991 log_info(
LD_APP,
"Giving up on retrying; conn can't be handled.");
995 "Edge got end (%s) before we're connected. Marking for close.",
1000 connection_mark_unattached_ap(conn, control_reason);
1019 int make_reject_all = 0;
1025 if (family == AF_UNSPEC) {
1026 make_reject_all = 1;
1029 make_reject_all = 1;
1032 if (make_reject_all) {
1034 "Exitrouter %s seems to be more restrictive than its exit "
1035 "policy. Not using this router as exit for now.",
1041 if (family != AF_UNSPEC)
1089 if (bytes <= INT32_MAX)
1099 if (bytes <= INT32_MAX)
1100 *ttl_out = (int) bytes;
1125 uint8_t answer_type;
1127 address_ttl_t *addr;
1148 const uint8_t *cp_orig = cp;
1151 answer_type = *cp++;
1153 if (remaining < 2 + answer_len + 4) {
1156 if (answer_type == RESOLVED_TYPE_IPV4) {
1157 if (answer_len != 4) {
1160 addr = tor_malloc_zero(
sizeof(*addr));
1166 }
else if (answer_type == RESOLVED_TYPE_IPV6) {
1167 if (answer_len != 16)
1169 addr = tor_malloc_zero(
sizeof(*addr));
1175 }
else if (answer_type == RESOLVED_TYPE_HOSTNAME) {
1176 if (answer_len == 0) {
1179 addr = tor_malloc_zero(
sizeof(*addr));
1180 addr->hostname = tor_memdup_nulterm(cp, answer_len);
1185 }
else if (answer_type == RESOLVED_TYPE_ERROR_TRANSIENT ||
1186 answer_type == RESOLVED_TYPE_ERROR) {
1187 errcode = answer_type;
1189 cp += answer_len + 4;
1191 cp += answer_len + 4;
1193 tor_assert(((ssize_t)remaining) >= (cp - cp_orig));
1194 remaining -= (cp - cp_orig);
1197 if (errcode && smartlist_len(addrs) == 0) {
1199 *errcode_out = errcode;
1203 smartlist_free(addrs);
1210 smartlist_free(addrs);
1222 address_ttl_t *addr_ipv4 = NULL;
1223 address_ttl_t *addr_ipv6 = NULL;
1224 address_ttl_t *addr_hostname = NULL;
1225 address_ttl_t *addr_best = NULL;
1229 tor_assert(error_code == RESOLVED_TYPE_ERROR ||
1230 error_code == RESOLVED_TYPE_ERROR_TRANSIENT);
1232 error_code,0,NULL,-1,-1);
1238 if (addr->hostname) {
1239 if (!addr_hostname) {
1240 addr_hostname = addr;
1243 if (!addr_ipv4 && conn->entry_cfg.ipv4_traffic) {
1247 if (!addr_ipv6 && conn->entry_cfg.ipv6_traffic) {
1251 } SMARTLIST_FOREACH_END(addr);
1255 if (addr_hostname) {
1257 RESOLVED_TYPE_HOSTNAME,
1258 strlen(addr_hostname->hostname),
1259 (uint8_t*)addr_hostname->hostname,
1260 addr_hostname->ttl,-1);
1263 RESOLVED_TYPE_ERROR,0,NULL,-1,-1);
1268 if (conn->entry_cfg.prefer_ipv6) {
1269 addr_best = addr_ipv6 ? addr_ipv6 : addr_ipv4;
1271 addr_best = addr_ipv4 ? addr_ipv4 : addr_ipv6;
1277 RESOLVED_TYPE_ERROR,0,NULL,-1,-1);
1301 log_fn(LOG_PROTOCOL_WARN,
LD_APP,
"Got a 'resolved' cell while "
1302 "not in state resolve_wait. Dropping.");
1310 "Dropping malformed 'resolved' cell");
1311 connection_mark_unattached_ap(entry_conn, END_STREAM_REASON_TORPROTOCOL);
1315 if (
get_options()->ClientDNSRejectInternalAddresses) {
1316 int orig_len = smartlist_len(resolved_addresses);
1318 if (addr->hostname == NULL && tor_addr_is_internal(&addr->addr, 0)) {
1319 log_info(
LD_APP,
"Got a resolved cell with answer %s; dropping that "
1321 safe_str_client(
fmt_addr(&addr->addr)));
1322 address_ttl_free(addr);
1325 } SMARTLIST_FOREACH_END(addr);
1326 if (orig_len && smartlist_len(resolved_addresses) == 0) {
1327 log_info(
LD_APP,
"Got a resolved cell with only private addresses; "
1330 RESOLVED_TYPE_ERROR_TRANSIENT,
1331 0, NULL, 0, TIME_MAX);
1332 connection_mark_unattached_ap(entry_conn,
1333 END_STREAM_REASON_TORPROTOCOL);
1346 resolved_addresses);
1348 connection_mark_unattached_ap(entry_conn,
1349 END_STREAM_REASON_DONE |
1354 address_ttl_free(addr));
1355 smartlist_free(resolved_addresses);
1371 if (rh->
command == RELAY_COMMAND_END) {
1382 connection_mark_for_close(
TO_CONN(conn));
1388 rh->
command == RELAY_COMMAND_CONNECTED) {
1395 "Got 'connected' while not in state connect_wait. Dropping.");
1398 CONNECTION_AP_EXPECT_NONPENDING(entry_conn);
1400 log_info(
LD_APP,
"'connected' received for circid %u streamid %d "
1401 "after %d seconds.",
1407 "Got a badly formatted connected cell. Closing.");
1409 connection_mark_unattached_ap(entry_conn, END_STREAM_REASON_TORPROTOCOL);
1418 (
get_options()->ClientDNSRejectInternalAddresses &&
1419 tor_addr_is_internal(&addr, 0))) {
1420 log_info(
LD_APP,
"...but it claims the IP address was %s. Closing.",
1423 connection_mark_unattached_ap(entry_conn,
1424 END_STREAM_REASON_TORPROTOCOL);
1428 if ((family == AF_INET && ! entry_conn->entry_cfg.ipv4_traffic) ||
1429 (family == AF_INET6 && ! entry_conn->entry_cfg.ipv6_traffic)) {
1431 "Got a connected cell to %s with unsupported address family."
1434 connection_mark_unattached_ap(entry_conn,
1435 END_STREAM_REASON_TORPROTOCOL);
1454 log_debug(
LD_APP,
"considering");
1455 if (
TO_CONN(conn)->linked_conn &&
1488 connection_mark_for_close(
TO_CONN(conn));
1494 rh->
command == RELAY_COMMAND_RESOLVED) {
1499 "Got an unexpected relay command %d, in state %d (%s). Dropping.",
1526 ret = sendme_process_circuit_level(layer_hint, circ,
1546 log_info(domain,
"Sendme cell on circ %u valid on half-closed "
1552 log_info(domain,
"SENDME cell dropped, unknown stream (streamid %d).",
1558 ret = sendme_process_stream_level(conn, circ, rh->
length);
1577 connection_mark_for_close(
TO_CONN(conn));
1596 unsigned domain = layer_hint?
LD_APP:LD_EXIT;
1604 log_debug(domain,
"Cell handled as circuit padding");
1610 case RELAY_COMMAND_BEGIN:
1611 case RELAY_COMMAND_BEGIN_DIR:
1615 "Relay begin request unsupported at AP. Dropping.");
1621 "Relay begin request to Hidden Service "
1622 "from intermediary node. Dropping.");
1626 log_fn(LOG_PROTOCOL_WARN, domain,
1627 "Begin cell for known stream. Dropping.");
1630 if (rh->
command == RELAY_COMMAND_BEGIN_DIR &&
1636 static uint64_t next_id = 0;
1641 case RELAY_COMMAND_DATA:
1647 if (sendme_circuit_data_received(circ, layer_hint) < 0) {
1649 "(relay data) circ deliver_window below 0. Killing.");
1651 return -END_CIRC_REASON_TORPROTOCOL;
1659 "stream_id. Dropping.");
1668 "data cell on circ %u valid on half-closed "
1673 log_info(domain,
"data cell dropped, unknown stream (streamid %d).",
1682 if (sendme_stream_data_received(conn) < 0) {
1684 "(relay data) conn deliver_window below 0. Killing.");
1686 return -END_CIRC_REASON_TORPROTOCOL;
1694 if (conn->hs_ident) {
1704 #ifdef MEASUREMENTS_21206
1710 ++(
TO_DIR_CONN(linked_conn)->data_cells_received);
1714 if (!optimistic_data) {
1722 case RELAY_COMMAND_END:
1723 reason = rh->
length > 0 ?
1733 "end cell (%s) on circ %u valid on half-closed "
1740 log_info(domain,
"end cell (%s) dropped, unknown stream.",
1745 log_info(domain,TOR_SOCKET_T_FORMAT
": end cell (%s) for stream %d. "
1755 "open stream hasn't sent socks answer yet? Closing.");
1764 connection_mark_and_flush(
TO_CONN(conn));
1772 case RELAY_COMMAND_EXTEND:
1773 case RELAY_COMMAND_EXTEND2: {
1774 static uint64_t total_n_extend=0, total_nonearly=0;
1777 log_fn(LOG_PROTOCOL_WARN, domain,
1778 "'extend' cell received for non-zero stream. Dropping.");
1781 if (cell->
command != CELL_RELAY_EARLY &&
1783 #define EARLY_WARNING_INTERVAL 3600
1785 RATELIM_INIT(EARLY_WARNING_INTERVAL);
1787 if (cell->
command == CELL_RELAY) {
1790 double percentage = ((double)total_nonearly)/total_n_extend;
1792 log_fn(LOG_PROTOCOL_WARN, domain,
"EXTEND cell received, "
1793 "but not via RELAY_EARLY. Dropping.%s", m);
1794 log_fn(LOG_PROTOCOL_WARN, domain,
" (We have dropped %.02f%% of "
1795 "all EXTEND cells for this reason)", percentage);
1800 "EXTEND cell received, in a cell with type %d! Dropping.",
1807 case RELAY_COMMAND_EXTENDED:
1808 case RELAY_COMMAND_EXTENDED2:
1811 "'extended' unsupported at non-origin. Dropping.");
1814 log_debug(domain,
"Got an extended cell! Yay.");
1821 "Can't parse EXTENDED cell; killing circuit.");
1822 return -END_CIRC_REASON_TORPROTOCOL;
1826 circuit_mark_for_close(circ, -reason);
1832 log_info(domain,
"circuit_send_next_onion_skin() failed.");
1840 case RELAY_COMMAND_TRUNCATE:
1843 "'truncate' unsupported at origin. Dropping.");
1848 log_warn(
LD_BUG,
"n_chan and n_hop set on the same circuit!");
1849 extend_info_free(circ->
n_hop);
1862 log_debug(LD_EXIT,
"Processed 'truncate', replying.");
1865 payload[0] = (char)END_CIRC_REASON_REQUESTED;
1866 relay_send_command_from_edge(0, circ, RELAY_COMMAND_TRUNCATED,
1867 payload,
sizeof(payload), NULL);
1870 case RELAY_COMMAND_TRUNCATED:
1872 log_fn(LOG_PROTOCOL_WARN, LD_EXIT,
1873 "'truncated' unsupported at non-origin. Dropping.");
1886 case RELAY_COMMAND_CONNECTED:
1889 "'connected' unsupported while open. Closing circ.");
1890 return -END_CIRC_REASON_TORPROTOCOL;
1899 "connected cell on circ %u valid on half-closed "
1906 "'connected' received on circid %u for streamid %d, "
1907 "no conn attached anymore. Ignoring.",
1910 case RELAY_COMMAND_SENDME:
1912 case RELAY_COMMAND_RESOLVE:
1915 "resolve request unsupported at AP; dropping.");
1918 log_fn(LOG_PROTOCOL_WARN, domain,
1919 "resolve request for known stream; dropping.");
1922 log_fn(LOG_PROTOCOL_WARN, domain,
1923 "resolve request on circ with purpose %d; dropping",
1929 case RELAY_COMMAND_RESOLVED:
1931 log_fn(LOG_PROTOCOL_WARN, domain,
1932 "'resolved' unsupported while open. Closing circ.");
1933 return -END_CIRC_REASON_TORPROTOCOL;
1942 "resolved cell on circ %u valid on half-closed "
1949 "'resolved' received, no conn attached anymore. Ignoring.");
1951 case RELAY_COMMAND_ESTABLISH_INTRO:
1952 case RELAY_COMMAND_ESTABLISH_RENDEZVOUS:
1953 case RELAY_COMMAND_INTRODUCE1:
1954 case RELAY_COMMAND_INTRODUCE2:
1955 case RELAY_COMMAND_INTRODUCE_ACK:
1956 case RELAY_COMMAND_RENDEZVOUS1:
1957 case RELAY_COMMAND_RENDEZVOUS2:
1958 case RELAY_COMMAND_INTRO_ESTABLISHED:
1959 case RELAY_COMMAND_RENDEZVOUS_ESTABLISHED:
1966 "Received unknown relay command %d. Perhaps the other side is using "
1967 "a newer version of Tor? Dropping.",
1986 static int num_seen=0;
1988 unsigned domain = layer_hint?
LD_APP:LD_EXIT;
1989 int optimistic_data = 0;
1999 log_debug(domain,
"Now seen %d relay cells here (command %d, stream %d).",
2004 "Relay cell length field too long. Closing circuit.");
2005 return - END_CIRC_REASON_TORPROTOCOL;
2010 case RELAY_COMMAND_BEGIN:
2011 case RELAY_COMMAND_CONNECTED:
2012 case RELAY_COMMAND_END:
2013 case RELAY_COMMAND_RESOLVE:
2014 case RELAY_COMMAND_RESOLVED:
2015 case RELAY_COMMAND_BEGIN_DIR:
2017 "stream_id. Dropping.", (
int)rh.
command);
2033 rh.
command == RELAY_COMMAND_DATA) {
2037 optimistic_data = 1;
2039 log_warn(
LD_BUG,
"Somehow I had a connection that matched a "
2040 "data cell with stream ID 0.");
2043 &rh, cell, circ, conn, layer_hint);
2048 &rh, optimistic_data);
2081 #define RELAY_PAYLOAD_LENGTH_FOR_RANDOM_SENDMES \
2082 (RELAY_PAYLOAD_SIZE - CELL_PADDING_GAP - 16)
2090 int package_partial,
2097 const bool force_random_bytes =
2102 size_t target_length;
2103 if (force_random_bytes) {
2110 size_t package_length;
2111 if (n_available >= target_length) {
2112 package_length = target_length;
2114 if (package_partial)
2115 package_length = n_available;
2121 tor_assert_nonfatal(package_length > 0);
2139 return package_length;
2156 size_t bytes_to_process, length;
2160 int sending_from_optimistic = 0;
2163 const int sending_optimistically =
2173 "called on conn that's already marked for close at %s:%d.",
2178 if (max_cells && *max_cells <= 0)
2181 repeat_connection_edge_package_raw_inbuf:
2185 log_info(domain,
"conn has no circuit! Closing.");
2194 log_info(domain,
"called with package_window %d. Skipping.",
2200 sending_from_optimistic = entry_conn &&
2201 entry_conn->sending_optimistic_data != NULL;
2203 if (PREDICT_UNLIKELY(sending_from_optimistic)) {
2204 bytes_to_process =
buf_datalen(entry_conn->sending_optimistic_data);
2205 if (PREDICT_UNLIKELY(!bytes_to_process)) {
2206 log_warn(
LD_BUG,
"sending_optimistic_data was non-NULL but empty");
2207 bytes_to_process = connection_get_inbuf_len(
TO_CONN(conn));
2208 sending_from_optimistic = 0;
2211 bytes_to_process = connection_get_inbuf_len(
TO_CONN(conn));
2215 package_partial, circ);
2225 if (PREDICT_UNLIKELY(sending_from_optimistic)) {
2229 buf_get_bytes(entry_conn->sending_optimistic_data, payload, length);
2230 if (!
buf_datalen(entry_conn->sending_optimistic_data)) {
2231 buf_free(entry_conn->sending_optimistic_data);
2232 entry_conn->sending_optimistic_data = NULL;
2238 log_debug(domain,TOR_SOCKET_T_FORMAT
": Packaging %d bytes (%d waiting).",
2240 (
int)length, (
int)connection_get_inbuf_len(
TO_CONN(conn)));
2242 if (sending_optimistically && !sending_from_optimistic) {
2251 payload, length) < 0 ) {
2257 if (sendme_note_circuit_data_packaged(circ, cpath_layer) < 0) {
2260 "Circuit package window is below 0. Closing circuit.");
2261 conn->
end_reason = END_STREAM_REASON_TORPROTOCOL;
2266 if (sendme_note_stream_data_packaged(conn) < 0) {
2268 log_debug(domain,
"conn->package_window reached 0.");
2272 log_debug(domain,
"conn->package_window is now %d",conn->
package_window);
2276 if (*max_cells <= 0)
2281 goto repeat_connection_edge_package_raw_inbuf;
2293 log_debug(layer_hint?
LD_APP:LD_EXIT,
"Too big queue, no resuming");
2296 log_debug(layer_hint?
LD_APP:LD_EXIT,
"resuming");
2316 int n_packaging_streams, n_streams_left;
2317 int packaged_this_round;
2323 if (first_conn == NULL) {
2354 int num_streams = 0;
2355 for (conn = first_conn; conn; conn = conn->
next_stream) {
2359 chosen_stream = conn;
2376 n_packaging_streams = 0;
2378 for (conn=chosen_stream; conn; conn = conn->
next_stream) {
2382 if (!layer_hint || conn->
cpath_layer == layer_hint) {
2385 if (connection_get_inbuf_len(
TO_CONN(conn)) > 0)
2386 ++n_packaging_streams;
2390 for (conn = first_conn; conn != chosen_stream; conn = conn->
next_stream) {
2393 if (!layer_hint || conn->
cpath_layer == layer_hint) {
2396 if (connection_get_inbuf_len(
TO_CONN(conn)) > 0)
2397 ++n_packaging_streams;
2401 if (n_packaging_streams == 0)
2406 cells_per_conn = CEIL_DIV(max_to_package, n_packaging_streams);
2408 packaged_this_round = 0;
2416 for (conn=first_conn; conn; conn=conn->
next_stream) {
2419 if (!layer_hint || conn->
cpath_layer == layer_hint) {
2420 int n = cells_per_conn, r;
2425 packaged_this_round += (cells_per_conn-n);
2430 connection_mark_for_close(
TO_CONN(conn));
2435 if (connection_get_inbuf_len(
TO_CONN(conn)))
2451 if (packaged_this_round && packaged_this_round < max_to_package &&
2453 max_to_package -= packaged_this_round;
2454 n_packaging_streams = n_streams_left;
2471 unsigned domain = layer_hint ?
LD_APP : LD_EXIT;
2475 log_debug(domain,
"considering circ->package_window %d",
2478 log_debug(domain,
"yes, not-at-origin. stopped.");
2486 log_debug(domain,
"considering layer_hint->package_window %d",
2489 log_debug(domain,
"yes, at-origin. stopped.");
2536 n_cells += c->n_chan_cells.n;
2541 SMARTLIST_FOREACH_END(c);
2543 "%d cells allocated on %d circuits. %d cells leaked.",
2560 TOR_SIMPLEQ_INSERT_TAIL(&queue->head, cell, next);
2570 int exitward,
const cell_t *cell,
2571 int wide_circ_ids,
int use_stats)
2588 TOR_SIMPLEQ_INIT(&queue->head);
2596 while ((cell = TOR_SIMPLEQ_FIRST(&queue->head))) {
2597 TOR_SIMPLEQ_REMOVE_HEAD(&queue->head, next);
2600 TOR_SIMPLEQ_INIT(&queue->head);
2612 TOR_SIMPLEQ_REMOVE_HEAD(&queue->head, next);
2622 TOR_SIMPLEQ_INIT(&queue->head);
2630 while ((cell = TOR_SIMPLEQ_FIRST(&queue->head))) {
2631 TOR_SIMPLEQ_REMOVE_HEAD(&queue->head, next);
2634 TOR_SIMPLEQ_INIT(&queue->head);
2646 TOR_SIMPLEQ_REMOVE_HEAD(&queue->head, next);
2658 cell->circid = circid;
2659 cell->reason = reason;
2663 TOR_SIMPLEQ_INSERT_TAIL(&queue->head, cell, next);
2673 memset(&cell, 0,
sizeof(cell));
2676 cell.
payload[0] = inp->reason;
2677 cell_pack(packed, &cell, wide_circ_ids);
2693 cell_queues_get_total_allocation(
void)
2699 #define MEMORY_PRESSURE_INTERVAL (30*60)
2706 uint64_t oom_stats_n_bytes_removed_cell = 0;
2707 uint64_t oom_stats_n_bytes_removed_geoip = 0;
2708 uint64_t oom_stats_n_bytes_removed_hsdir = 0;
2716 time_t now = time(NULL);
2717 size_t alloc = cell_queues_get_total_allocation();
2719 alloc += buf_get_total_allocation();
2721 const size_t hs_cache_total = hs_cache_get_total_allocation();
2722 alloc += hs_cache_total;
2723 const size_t geoip_client_cache_total =
2724 geoip_client_cache_total_allocation();
2725 alloc += geoip_client_cache_total;
2726 const size_t dns_cache_total = dns_cache_total_allocation();
2727 alloc += dns_cache_total;
2728 if (alloc >=
get_options()->MaxMemInQueues_low_threshold) {
2737 if (hs_cache_total >
get_options()->MaxMemInQueues / 5) {
2738 const size_t bytes_to_remove =
2741 oom_stats_n_bytes_removed_hsdir += removed;
2744 if (geoip_client_cache_total >
get_options()->MaxMemInQueues / 5) {
2745 const size_t bytes_to_remove =
2746 geoip_client_cache_total -
2748 removed = geoip_client_cache_handle_oom(now, bytes_to_remove);
2749 oom_stats_n_bytes_removed_geoip += removed;
2752 if (dns_cache_total >
get_options()->MaxMemInQueues / 5) {
2753 const size_t bytes_to_remove =
2755 removed = dns_cache_handle_oom(now, bytes_to_remove);
2760 oom_stats_n_bytes_removed_cell += removed;
2782 const char *file,
int lineno)
2786 circuitmux_t *cmux = NULL;
2806 log_warn(
LD_BUG,
"called on non-attached circuit from %s:%d",
2833 chan->num_p_circuits = 0;
2851 if (circ->
n_chan == chan) {
2863 if (stream_id && edge->
stream_id != stream_id)
2894 if (wide_circ_ids) {
2905 if (wide_circ_ids) {
2919 circuitmux_t *cmux = NULL;
2925 int streams_blocked;
2934 while (n_flushed < max) {
2936 if (destroy_queue) {
2963 if (circ->
n_chan == chan) {
2974 if ( queue->
n == 0 ) {
2975 log_warn(
LD_BUG,
"Found a supposedly active circuit with no cells "
2976 "to send. Trying to recover.");
2979 circuit_mark_for_close(circ, END_CIRC_REASON_INTERNAL);
2996 uint32_t msec_waiting =
3014 if (circ->
n_chan == chan)
3054 log_debug(
LD_GENERAL,
"Made a circuit inactive.");
3092 #define RELAY_CIRC_CELL_QUEUE_SIZE_MIN CIRCWINDOW_START_MAX
3094 #define RELAY_CIRC_CELL_QUEUE_SIZE_MAX INT32_MAX
3098 #define RELAY_CIRC_CELL_QUEUE_SIZE_DEFAULT \
3099 (50 * RELAY_CIRC_CELL_QUEUE_SIZE_MIN)
3103 static int32_t max_circuit_cell_queue_size =
3104 RELAY_CIRC_CELL_QUEUE_SIZE_DEFAULT;
3115 max_circuit_cell_queue_size =
3117 RELAY_CIRC_CELL_QUEUE_SIZE_DEFAULT,
3118 RELAY_CIRC_CELL_QUEUE_SIZE_MIN,
3119 RELAY_CIRC_CELL_QUEUE_SIZE_MAX);
3136 int streams_blocked;
3151 if (PREDICT_UNLIKELY(queue->
n >= max_circuit_cell_queue_size)) {
3153 "%s circuit has %d cells in its queue, maximum allowed is %d. "
3154 "Closing circuit for safety reasons.",
3155 (exitward) ?
"Outbound" :
"Inbound", queue->
n,
3156 max_circuit_cell_queue_size);
3157 circuit_mark_for_close(circ, END_CIRC_REASON_RESOURCELIMIT);
3165 chan->wide_circ_ids, 1);
3179 if (streams_blocked && fromstream) {
3184 update_circuit_on_cmux(circ, direction);
3185 if (queue->
n == 1) {
3188 log_debug(
LD_GENERAL,
"Made a circuit active.");
3208 payload_out[0] = RESOLVED_TYPE_IPV4;
3211 memcpy(payload_out+2, &a, 4);
3214 payload_out[0] = RESOLVED_TYPE_IPV6;
3215 payload_out[1] = 16;
3232 if (payload_len < 2)
3234 if (payload_len < 2+payload[1])
3237 switch (payload[0]) {
3238 case RESOLVED_TYPE_IPV4:
3239 if (payload[1] != 4)
3243 case RESOLVED_TYPE_IPV6:
3244 if (payload[1] != 16)
3252 return payload + 2 + payload[1];
3262 if (circ->
n_chan == chan) {
3277 update_circuit_on_cmux(circ, direction);
void tor_addr_from_ipv4n(tor_addr_t *dest, uint32_t v4addr)
void tor_addr_make_unspec(tor_addr_t *a)
const char * tor_addr_to_str(char *dest, const tor_addr_t *addr, size_t len, int decorate)
int tor_addr_parse(tor_addr_t *addr, const char *src)
int tor_addr_is_null(const tor_addr_t *addr)
void tor_addr_from_ipv6_bytes(tor_addr_t *dest, const uint8_t *ipv6_bytes)
static uint32_t tor_addr_to_ipv4n(const tor_addr_t *a)
static sa_family_t tor_addr_family(const tor_addr_t *a)
#define tor_addr_to_in6_addr8(x)
#define tor_addr_from_ipv4h(dest, v4addr)
int client_dns_incr_failures(const char *address)
void client_dns_set_addressmap(entry_connection_t *for_conn, const char *address, const tor_addr_t *val, const char *exitname, int ttl)
void client_dns_clear_failures(const char *address)
int buf_add(buf_t *buf, const char *string, size_t string_len)
size_t buf_datalen(const buf_t *buf)
int buf_get_bytes(buf_t *buf, char *string, size_t string_len)
Header file for buffers.c.
static void set_uint16(void *cp, uint16_t v)
static uint16_t get_uint16(const void *cp)
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_client(channel_t *chan)
int channel_send_destroy(circid_t circ_id, channel_t *chan, int reason)
int channel_is_client(const channel_t *chan)
void channel_mark_for_close(channel_t *chan)
int channel_write_packed_cell(channel_t *chan, packed_cell_t *cell)
Header file for channel.c.
void pathbias_count_valid_cells(circuit_t *circ, const cell_t *cell)
int pathbias_check_probe_response(circuit_t *circ, const cell_t *cell)
void pathbias_mark_use_success(origin_circuit_t *circ)
void circuit_log_path(int severity, unsigned int domain, origin_circuit_t *circ)
int circuit_send_next_onion_skin(origin_circuit_t *circ)
int circuit_finish_handshake(origin_circuit_t *circ, const created_cell_t *reply)
int circuit_truncated(origin_circuit_t *circ, int reason)
Header file for circuitbuild.c.
int circuit_extend(struct cell_t *cell, struct circuit_t *circ)
Header for feature/relay/circuitbuild_relay.c.
void circuit_synchronize_written_or_bandwidth(const circuit_t *c, circuit_channel_direction_t dir)
void circuit_set_n_circid_chan(circuit_t *circ, circid_t id, channel_t *chan)
void circuit_set_state(circuit_t *circ, uint8_t state)
circuit_t * circuit_get_by_edge_conn(edge_connection_t *conn)
void assert_circuit_ok(const circuit_t *c)
smartlist_t * circuit_get_global_list(void)
origin_circuit_t * TO_ORIGIN_CIRCUIT(circuit_t *x)
size_t circuits_handle_oom(size_t current_allocation)
or_circuit_t * TO_OR_CIRCUIT(circuit_t *x)
const char * circuit_state_to_string(int state)
Header file for circuitlist.c.
#define CIRCUIT_PURPOSE_PATH_BIAS_TESTING
#define CIRCUIT_STATE_OPEN
#define CIRCUIT_IS_ORIGIN(c)
#define CIRCUIT_PURPOSE_OR
#define CIRCUIT_PURPOSE_S_REND_JOINED
#define CIRCUIT_PURPOSE_REND_ESTABLISHED
cell_direction_t circuitmux_attached_circuit_direction(circuitmux_t *cmux, circuit_t *circ)
void circuitmux_notify_xmit_destroy(circuitmux_t *cmux)
void circuitmux_detach_all_circuits(circuitmux_t *cmux, smartlist_t *detached_out)
void circuitmux_notify_xmit_cells(circuitmux_t *cmux, circuit_t *circ, unsigned int n_cells)
int circuitmux_is_circuit_attached(circuitmux_t *cmux, circuit_t *circ)
circuit_t * circuitmux_get_first_active_circuit(circuitmux_t *cmux, destroy_cell_queue_t **destroy_queue_out)
void circuitmux_set_num_cells(circuitmux_t *cmux, circuit_t *circ, unsigned int n_cells)
void circpad_deliver_sent_relay_cell_events(circuit_t *circ, uint8_t relay_command)
void circpad_deliver_unrecognized_cell_events(circuit_t *circ, cell_direction_t dir)
void circpad_machine_event_circ_has_no_relay_early(origin_circuit_t *circ)
void circpad_deliver_recognized_relay_cell_events(circuit_t *circ, uint8_t relay_command, crypt_path_t *layer_hint)
int circpad_check_received_cell(cell_t *cell, circuit_t *circ, crypt_path_t *layer_hint, const relay_header_t *rh)
Header file for circuitpadding.c.
void circuit_sent_valid_data(origin_circuit_t *circ, uint16_t relay_body_len)
void circuit_read_valid_data(origin_circuit_t *circ, uint16_t relay_body_len)
void mark_circuit_unusable_for_new_conns(origin_circuit_t *circ)
Header file for circuituse.c.
uint64_t monotime_coarse_stamp_units_to_approx_msec(uint64_t units)
uint32_t monotime_coarse_get_stamp(void)
size_t tor_compress_get_total_allocation(void)
const or_options_t * get_options(void)
tor_cmdline_mode_t command
Header file for config.c.
int connection_buf_get_bytes(char *string, size_t len, connection_t *conn)
const char * conn_state_to_string(int type, int state)
int connection_state_is_open(connection_t *conn)
Header file for connection.c.
int connection_half_edge_is_valid_data(const smartlist_t *half_conns, streamid_t stream_id)
int connection_ap_detach_retriable(entry_connection_t *conn, origin_circuit_t *circ, int reason)
void connection_ap_handshake_socks_reply(entry_connection_t *conn, char *reply, size_t replylen, int endreason)
int connection_half_edge_is_valid_end(smartlist_t *half_conns, streamid_t stream_id)
void connection_edge_end_close(edge_connection_t *conn, uint8_t reason)
int connection_exit_begin_resolve(cell_t *cell, or_circuit_t *circ)
int connection_half_edge_is_valid_connected(const smartlist_t *half_conns, streamid_t stream_id)
entry_connection_t * EDGE_TO_ENTRY_CONN(edge_connection_t *c)
void connection_ap_handshake_socks_resolved_addr(entry_connection_t *conn, const tor_addr_t *answer, int ttl, time_t expires)
int connection_half_edge_is_valid_resolved(smartlist_t *half_conns, streamid_t stream_id)
int connection_edge_end(edge_connection_t *conn, uint8_t reason)
size_t half_streams_get_total_allocation(void)
int connection_half_edge_is_valid_sendme(const smartlist_t *half_conns, streamid_t stream_id)
int connection_edge_is_rendezvous_stream(const edge_connection_t *conn)
void connection_ap_handshake_socks_resolved(entry_connection_t *conn, int answer_type, size_t answer_len, const uint8_t *answer, int ttl, time_t expires)
int connection_exit_begin_conn(cell_t *cell, circuit_t *circ)
Header file for connection_edge.c.
#define EXIT_CONN_STATE_CONNECTING
#define AP_CONN_STATE_CONNECT_WAIT
#define AP_CONN_STATE_OPEN
#define AP_CONN_STATE_RESOLVE_WAIT
#define EXIT_CONN_STATE_RESOLVING
void cell_pack(packed_cell_t *dst, const cell_t *src, int wide_circ_ids)
Header file for connection_or.c.
void control_event_boot_dir(bootstrap_status_t status, int progress)
void control_event_bootstrap(bootstrap_status_t status, int progress)
int control_event_stream_status(entry_connection_t *conn, stream_status_event_t tp, int reason_code)
Header file for control_events.c.
#define REMAP_STREAM_SOURCE_EXIT
Circuit-build-stse structure.
Common functions for using (pseudo-)random number generators.
#define crypto_fast_rng_one_in_n(rng, n)
crypto_fast_rng_t * get_thread_fast_rng(void)
unsigned crypto_fast_rng_get_uint(crypto_fast_rng_t *rng, unsigned limit)
void crypto_fast_rng_getbytes(crypto_fast_rng_t *rng, uint8_t *out, size_t n)
Common functions for cryptographic routines.
const char * node_describe(const node_t *node)
Header file for describe.c.
Destroy-cell queue structures.
Client/server directory connection structure.
dir_connection_t * TO_DIR_CONN(connection_t *c)
Header file for directory.c.
#define DIR_PURPOSE_FETCH_CERTIFICATE
#define DIR_PURPOSE_FETCH_MICRODESC
#define DIR_PURPOSE_FETCH_CONSENSUS
#define DIR_PURPOSE_FETCH_SERVERDESC
Entry connection structure.
#define ENTRY_TO_EDGE_CONN(c)
Header for core/or/extendinfo.c.
Header file for geoip_stats.c.
@ DIRREQ_CIRC_QUEUE_FLUSHED
void geoip_change_dirreq_state(uint64_t dirreq_id, dirreq_type_t type, dirreq_state_t new_state)
size_t hs_cache_handle_oom(time_t now, size_t min_remove_bytes)
Header file for hs_cache.c.
Header for feature/hs/hs_metrics.c.
#define hs_metrics_app_write_bytes(i, port, n)
void tor_log(int severity, log_domain_mask_t domain, const char *format,...)
#define log_fn(severity, domain, args,...)
void connection_stop_reading(connection_t *conn)
void connection_start_reading(connection_t *conn)
int connection_is_reading(connection_t *conn)
Header file for mainloop.c.
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)
int consensus_is_waiting_for_certs(void)
Header file for networkstatus.c.
node_t * node_get_mutable_by_id(const char *identity_digest)
int node_exit_policy_is_exact(const node_t *node, sa_family_t family)
int count_loading_descriptors_progress(void)
Header file for nodelist.c.
int extended_cell_parse(extended_cell_t *cell_out, const uint8_t command, const uint8_t *payload, size_t payload_len)
Master header file for Tor-specific functionality.
#define CELL_PAYLOAD_SIZE
#define END_STREAM_REASON_CANT_ATTACH
#define END_STREAM_REASON_FLAG_REMOTE
#define RELAY_PAYLOAD_SIZE
#define END_STREAM_REASON_FLAG_ALREADY_SOCKS_REPLIED
#define RELAY_HEADER_SIZE
#define END_CIRC_AT_ORIGIN
#define CIRCWINDOW_INCREMENT
Origin circuit structure.
void addr_policy_append_reject_addr(smartlist_t **dest, const tor_addr_t *addr)
void policies_set_node_exitpolicy_to_reject_all(node_t *node)
Header file for policies.c.
int tor_snprintf(char *str, size_t size, const char *format,...)
char * rate_limit_log(ratelim_t *lim, time_t now)
const char * stream_end_reason_to_string(int reason)
Header file for reasons.c.
int channel_flush_from_first_active_circuit(channel_t *chan, int max)
STATIC size_t connection_edge_get_inbuf_bytes_to_package(size_t n_available, int package_partial, circuit_t *on_circuit)
void destroy_cell_queue_init(destroy_cell_queue_t *queue)
static int circuit_resume_edge_reading_helper(edge_connection_t *conn, circuit_t *circ, crypt_path_t *layer_hint)
#define CELL_QUEUE_LOWWATER_SIZE
int append_address_to_payload(uint8_t *payload_out, const tor_addr_t *addr)
uint64_t stats_n_data_cells_received
void packed_cell_free_(packed_cell_t *cell)
void destroy_cell_queue_clear(destroy_cell_queue_t *queue)
void destroy_cell_queue_append(destroy_cell_queue_t *queue, circid_t circid, uint8_t reason)
void channel_unlink_all_circuits(channel_t *chan, smartlist_t *circuits_out)
void cell_queue_append_packed_copy(circuit_t *circ, cell_queue_t *queue, int exitward, const cell_t *cell, int wide_circ_ids, int use_stats)
STATIC size_t get_pad_cell_offset(size_t data_len)
uint64_t oom_stats_n_bytes_removed_dns
void dump_cell_pool_usage(int severity)
STATIC int connection_edge_process_relay_cell(cell_t *cell, circuit_t *circ, edge_connection_t *conn, crypt_path_t *layer_hint)
static packed_cell_t * destroy_cell_to_packed_cell(destroy_cell_t *inp, int wide_circ_ids)
void circuit_reset_sendme_randomness(circuit_t *circ)
const uint8_t * decode_address_from_payload(tor_addr_t *addr_out, const uint8_t *payload, int payload_len)
uint64_t stats_n_relay_cells_relayed
uint64_t stats_n_circ_max_cell_reached
STATIC packed_cell_t * packed_cell_new(void)
STATIC destroy_cell_t * destroy_cell_queue_pop(destroy_cell_queue_t *queue)
#define MAX_RESOLVE_FAILURES
static packed_cell_t * packed_cell_copy(const cell_t *cell, int wide_circ_ids)
static void remap_event_helper(entry_connection_t *conn, const tor_addr_t *new_addr)
STATIC packed_cell_t * cell_queue_pop(cell_queue_t *queue)
static int circuit_queue_streams_are_blocked(circuit_t *circ)
static void connection_ap_handshake_socks_got_resolved_cell(entry_connection_t *conn, int error_code, smartlist_t *results)
static void adjust_exit_policy_from_exitpolicy_failure(origin_circuit_t *circ, entry_connection_t *conn, node_t *node, const tor_addr_t *addr)
static void circuit_update_channel_usage(circuit_t *circ, cell_t *cell)
uint64_t stats_n_data_cells_packaged
void cell_queue_clear(cell_queue_t *queue)
STATIC int connected_cell_parse(const relay_header_t *rh, const cell_t *cell, tor_addr_t *addr_out, int *ttl_out)
static int set_streams_blocked_on_circ(circuit_t *circ, channel_t *chan, int block, streamid_t stream_id)
void circuit_clear_cell_queue(circuit_t *circ, channel_t *chan)
void cell_queue_init(cell_queue_t *queue)
int circuit_package_relay_cell(cell_t *cell, circuit_t *circ, cell_direction_t cell_direction, crypt_path_t *layer_hint, streamid_t on_stream, const char *filename, int lineno)
int have_been_under_memory_pressure(void)
uint64_t stats_n_data_bytes_received
void relay_header_pack(uint8_t *dest, const relay_header_t *src)
circid_t packed_cell_get_circid(const packed_cell_t *cell, int wide_circ_ids)
static edge_connection_t * relay_lookup_conn(circuit_t *circ, cell_t *cell, cell_direction_t cell_direction, crypt_path_t *layer_hint)
void update_circuit_on_cmux_(circuit_t *circ, cell_direction_t direction, const char *file, int lineno)
void append_cell_to_circuit_queue(circuit_t *circ, channel_t *chan, cell_t *cell, cell_direction_t direction, streamid_t fromstream)
int relay_send_command_from_edge_(streamid_t stream_id, circuit_t *circ, uint8_t relay_command, const char *payload, size_t payload_len, crypt_path_t *cpath_layer, const char *filename, int lineno)
void relay_header_unpack(relay_header_t *dest, const uint8_t *src)
static int connection_edge_process_relay_cell_not_open(relay_header_t *rh, cell_t *cell, circuit_t *circ, edge_connection_t *conn, crypt_path_t *layer_hint)
uint8_t packed_cell_get_command(const packed_cell_t *cell, int wide_circ_ids)
uint64_t stats_n_relay_cells_delivered
STATIC int cell_queues_check_size(void)
static int process_sendme_cell(const relay_header_t *rh, const cell_t *cell, circuit_t *circ, edge_connection_t *conn, crypt_path_t *layer_hint, int domain)
STATIC int handle_relay_cell_command(cell_t *cell, circuit_t *circ, edge_connection_t *conn, crypt_path_t *layer_hint, relay_header_t *rh, int optimistic_data)
static size_t total_cells_allocated
static const char * relay_command_to_string(uint8_t command)
static void packed_cell_free_unchecked(packed_cell_t *cell)
static int edge_reason_is_retriable(int reason)
static void circuit_resume_edge_reading(circuit_t *circ, crypt_path_t *layer_hint)
#define RELAY_PAYLOAD_LENGTH_FOR_RANDOM_SENDMES
STATIC void address_ttl_free_(address_ttl_t *addr)
#define MEMORY_PRESSURE_INTERVAL
void cell_queue_append(cell_queue_t *queue, packed_cell_t *cell)
static int connection_ap_process_end_not_open(relay_header_t *rh, cell_t *cell, origin_circuit_t *circ, entry_connection_t *conn, crypt_path_t *layer_hint)
int circuit_receive_relay_cell(cell_t *cell, circuit_t *circ, cell_direction_t cell_direction)
int connection_edge_package_raw_inbuf(edge_connection_t *conn, int package_partial, int *max_cells)
int connection_edge_send_command(edge_connection_t *fromconn, uint8_t relay_command, const char *payload, size_t payload_len)
STATIC int resolved_cell_parse(const cell_t *cell, const relay_header_t *rh, smartlist_t *addresses_out, int *errcode_out)
uint64_t stats_n_data_bytes_packaged
STATIC int connection_edge_process_resolved_cell(edge_connection_t *conn, const cell_t *cell, const relay_header_t *rh)
size_t packed_cell_mem_cost(void)
#define CELL_QUEUE_HIGHWATER_SIZE
static time_t last_time_under_memory_pressure
static int circuit_consider_stop_edge_reading(circuit_t *circ, crypt_path_t *layer_hint)
Header for relay_crypto.c.
void relay_encrypt_cell_outbound(cell_t *cell, origin_circuit_t *or_circ, crypt_path_t *layer_hint)
int relay_decrypt_cell(circuit_t *circ, cell_t *cell, cell_direction_t cell_direction, crypt_path_t **layer_hint, char *recognized)
void relay_encrypt_cell_inbound(cell_t *cell, or_circuit_t *or_circ)
void rend_process_relay_cell(circuit_t *circ, const crypt_path_t *layer_hint, int command, size_t length, const uint8_t *payload)
Header file for rendcommon.c.
void rep_hist_note_overload(overload_type_t overload)
Header file for rephist.c.
Router descriptor structure.
#define ROUTER_PURPOSE_GENERAL
Header file for routerlist.c.
void scheduler_channel_has_waiting_cells(channel_t *chan)
Header file for scheduler*.c.
void sendme_connection_edge_consider_sending(edge_connection_t *conn)
void sendme_circuit_consider_sending(circuit_t *circ, crypt_path_t *layer_hint)
Header file for sendme.c.
char * smartlist_join_strings(smartlist_t *sl, const char *join, int terminate, size_t *len_out)
void smartlist_add_all(smartlist_t *s1, const smartlist_t *s2)
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)
#define SMARTLIST_DEL_CURRENT(sl, var)
Client request structure.
#define SOCKS_COMMAND_RESOLVE_PTR
uint8_t payload[CELL_PAYLOAD_SIZE]
unsigned int num_n_circuits
channel_usage_info_t channel_usage
int marked_for_close_reason
uint16_t send_randomness_after_n_cells
struct create_cell_t * n_chan_create_cell
unsigned int have_sent_sufficiently_random_cell
unsigned int streams_blocked_on_n_chan
cell_queue_t n_chan_cells
uint16_t marked_for_close
const char * marked_for_close_file
smartlist_t * testing_cell_stats
unsigned int streams_blocked_on_p_chan
time_t timestamp_last_read_allowed
uint16_t marked_for_close
const char * marked_for_close_file
struct event * read_event
extend_info_t * chosen_exit
uint32_t inserted_timestamp
struct crypt_path_t * cpath_layer
struct edge_connection_t * next_stream
unsigned int edge_has_sent_end
unsigned int edge_blocked_on_circ
struct circuit_t * on_circuit
socks_request_t * socks_request
unsigned int chosen_exit_optional
unsigned int chosen_exit_retries
struct buf_t * pending_optimistic_data
char identity_digest[DIGEST_LEN]
created_cell_t created_cell
ed25519_public_key_t identity_pk
uint16_t orig_virtual_port
uint64_t total_cell_waiting_time
cell_queue_t p_chan_cells
struct or_circuit_t * rend_splice
edge_connection_t * n_streams
uint32_t n_written_circ_bw
uint32_t global_identifier
edge_connection_t * p_streams
uint8_t relay_early_commands[MAX_RELAY_EARLY_CELLS_PER_CIRCUIT]
int relay_early_cells_sent
unsigned int remaining_relay_early_cells
path_state_bitfield_t path_state
smartlist_t * prepend_policy
cpath_build_state_t * build_state
smartlist_t * half_streams
uint32_t inserted_timestamp
char body[CELL_MAX_NETWORK_SIZE]
unsigned int has_finished
char address[MAX_SOCKS_ADDR_LEN]
unsigned int waiting_time
#define MOCK_IMPL(rv, funcname, arglist)