10#define CONTROL_MODULE_PRIVATE
11#define CONTROL_EVENTS_PRIVATE
12#define OCIRC_EVENT_PRIVATE
39#include "core/or/or_circuit_st.h"
50#define STATE_IS_OPEN(s) ((s) == CONTROL_CONN_STATE_OPEN)
61#define EVENT_IS_INTERESTING(e) \
62 (!! (global_event_mask & EVENT_MASK_(e)))
65#define ANY_EVENT_IS_INTERESTING(e) \
66 (!! (global_event_mask & (e)))
69 const char *format, va_list ap)
76 const char *format, ...)
82 { EVENT_CIRCUIT_STATUS,
"CIRC" },
83 { EVENT_CIRCUIT_STATUS_MINOR,
"CIRC_MINOR" },
84 { EVENT_STREAM_STATUS,
"STREAM" },
85 { EVENT_OR_CONN_STATUS,
"ORCONN" },
86 { EVENT_BANDWIDTH_USED,
"BW" },
87 { EVENT_DEBUG_MSG,
"DEBUG" },
88 { EVENT_INFO_MSG,
"INFO" },
89 { EVENT_NOTICE_MSG,
"NOTICE" },
90 { EVENT_WARN_MSG,
"WARN" },
91 { EVENT_ERR_MSG,
"ERR" },
92 { EVENT_NEW_DESC,
"NEWDESC" },
93 { EVENT_ADDRMAP,
"ADDRMAP" },
94 { EVENT_DESCCHANGED,
"DESCCHANGED" },
96 { EVENT_STATUS_GENERAL,
"STATUS_GENERAL" },
97 { EVENT_STATUS_CLIENT,
"STATUS_CLIENT" },
98 { EVENT_STATUS_SERVER,
"STATUS_SERVER" },
99 { EVENT_GUARD,
"GUARD" },
100 { EVENT_STREAM_BANDWIDTH_USED,
"STREAM_BW" },
101 { EVENT_CLIENTS_SEEN,
"CLIENTS_SEEN" },
102 { EVENT_NEWCONSENSUS,
"NEWCONSENSUS" },
103 { EVENT_BUILDTIMEOUT_SET,
"BUILDTIMEOUT_SET" },
104 { EVENT_GOT_SIGNAL,
"SIGNAL" },
105 { EVENT_CONF_CHANGED,
"CONF_CHANGED"},
106 { EVENT_CONN_BW,
"CONN_BW" },
107 { EVENT_CELL_STATS,
"CELL_STATS" },
108 { EVENT_CIRC_BANDWIDTH_USED,
"CIRC_BW" },
109 { EVENT_TRANSPORT_LAUNCHED,
"TRANSPORT_LAUNCHED" },
110 { EVENT_HS_DESC,
"HS_DESC" },
111 { EVENT_HS_DESC_CONTENT,
"HS_DESC_CONTENT" },
112 { EVENT_NETWORK_LIVENESS,
"NETWORK_LIVENESS" },
122 case LOG_INFO:
return EVENT_INFO_MSG;
124 case LOG_WARN:
return EVENT_WARN_MSG;
125 case LOG_ERR:
return EVENT_ERR_MSG;
143 SMARTLIST_FOREACH_END(circ);
153 double timeout_rate = 0.0;
154 double close_rate = 0.0;
157 case BUILDTIMEOUT_SET_EVENT_RESET:
158 case BUILDTIMEOUT_SET_EVENT_SUSPENDED:
159 case BUILDTIMEOUT_SET_EVENT_DISCARD:
162 case BUILDTIMEOUT_SET_EVENT_COMPUTED:
163 case BUILDTIMEOUT_SET_EVENT_RESUME:
183 const double total_circuits =
185 if (total_circuits >= 1.0) {
191 "TIMEOUT_MS=%lu XM=%lu ALPHA=%f CUTOFF_QUANTILE=%f "
192 "TIMEOUT_RATE=%f CLOSE_MS=%lu CLOSE_RATE=%f",
195 (
unsigned long)cbt->
Xm, cbt->
alpha, qnt,
210 event_mask_t old_mask, new_mask;
219 control_connection_t *conn = TO_CONTROL_CONN(_conn);
220 global_event_mask |= conn->event_mask;
231#define NEWLY_ENABLED(ev) \
232 (! (old_mask & (ev)) && (new_mask & (ev)))
236 if (NEWLY_ENABLED(EVENT_STREAM_BANDWIDTH_USED)) {
240 edge_connection_t *edge_conn = TO_EDGE_CONN(conn);
241 edge_conn->n_written = edge_conn->n_read = 0;
245 if (NEWLY_ENABLED(EVENT_CIRC_BANDWIDTH_USED)) {
248 if (NEWLY_ENABLED(EVENT_BANDWIDTH_USED)) {
266 case EVENT_INFO_MSG:
return LOG_INFO;
268 case EVENT_WARN_MSG:
return LOG_WARN;
269 case EVENT_ERR_MSG:
return LOG_ERR;
281 int min_log_event=EVENT_ERR_MSG, max_log_event=EVENT_DEBUG_MSG;
283 for (i = EVENT_DEBUG_MSG; i <= EVENT_ERR_MSG; ++i) {
289 for (i = EVENT_ERR_MSG; i >= EVENT_DEBUG_MSG; --i) {
296 if (min_log_event > EVENT_NOTICE_MSG)
297 min_log_event = EVENT_NOTICE_MSG;
298 if (max_log_event < EVENT_ERR_MSG)
299 max_log_event = EVENT_ERR_MSG;
301 if (min_log_event <= max_log_event)
325 EVENT_MASK_(EVENT_BANDWIDTH_USED) |
326 EVENT_MASK_(EVENT_CELL_STATS) |
327 EVENT_MASK_(EVENT_CIRC_BANDWIDTH_USED) |
328 EVENT_MASK_(EVENT_CONN_BW) |
329 EVENT_MASK_(EVENT_STREAM_BANDWIDTH_USED)
335static uint64_t stats_prev_n_read = 0;
338static uint64_t stats_prev_n_written = 0;
369 uint64_t bytes_read, bytes_written;
405control_initialize_event_queue(
void)
427get_block_event_queue(
void)
430 if (PREDICT_UNLIKELY(val == NULL)) {
431 val = tor_malloc_zero(
sizeof(
int));
458 int *block_event_queue = get_block_event_queue();
459 if (*block_event_queue) {
469 ++*block_event_queue;
475 int activate_event = 0;
483 --*block_event_queue;
489 if (activate_event) {
495#define queued_event_free(ev) \
496 FREE_AND_NULL(queued_event_t, queued_event_free_, (ev))
526 int *block_event_queue = get_block_event_queue();
527 ++*block_event_queue;
539 !conn->marked_for_close &&
545 } SMARTLIST_FOREACH_END(conn);
548 const event_mask_t bit = ((event_mask_t)1) << ev->event;
549 const size_t msg_len = strlen(ev->msg);
552 if (control_conn->event_mask & bit) {
553 connection_buf_add(ev->msg, msg_len,
TO_CONN(control_conn));
555 } SMARTLIST_FOREACH_END(control_conn);
557 queued_event_free(ev);
558 } SMARTLIST_FOREACH_END(ev);
564 } SMARTLIST_FOREACH_END(control_conn);
567 smartlist_free(queued_events);
568 smartlist_free(controllers);
570 --*block_event_queue;
592 tor_assert(event >= EVENT_MIN_ && event <= EVENT_MAX_);
602 const char *format, va_list ap)
609 log_warn(
LD_BUG,
"Unable to format event for controller.");
621 const char *format, ...)
624 va_start(ap, format);
636 char reasons[64] =
"";
644 case CIRC_EVENT_LAUNCHED: status =
"LAUNCHED";
break;
645 case CIRC_EVENT_BUILT: status =
"BUILT";
break;
646 case CIRC_EVENT_EXTENDED: status =
"EXTENDED";
break;
647 case CIRC_EVENT_FAILED: status =
"FAILED";
break;
648 case CIRC_EVENT_CLOSED: status =
"CLOSED";
break;
650 log_warn(
LD_BUG,
"Unrecognized status code %d", (
int)tp);
655 if (tp == CIRC_EVENT_FAILED || tp == CIRC_EVENT_CLOSED) {
657 char unk_reason_buf[16];
659 tor_snprintf(unk_reason_buf, 16,
"UNKNOWN_%d", reason_code);
660 reason_str = unk_reason_buf;
664 " REASON=DESTROYED REMOTE_REASON=%s", reason_str);
667 " REASON=%s", reason_str);
673 const char *sp = strlen(circdesc) ?
" " :
"";
675 "650 CIRC %lu %s%s%s%s\r\n",
691 int purpose,
const struct timeval *tv)
693 const char *event_desc;
694 char event_tail[160] =
"";
701 case CIRC_MINOR_EVENT_PURPOSE_CHANGED:
702 event_desc =
"PURPOSE_CHANGED";
706 const char *hs_state_str =
709 " OLD_PURPOSE=%s%s%s",
711 (hs_state_str != NULL) ?
" OLD_HS_STATE=" :
"",
712 (hs_state_str != NULL) ? hs_state_str :
"");
716 case CIRC_MINOR_EVENT_CANNIBALIZED:
717 event_desc =
"CANNIBALIZED";
721 const char *hs_state_str =
723 const struct timeval *old_timestamp_began = tv;
724 char tbuf[ISO_TIME_USEC_LEN+1];
728 " OLD_PURPOSE=%s%s%s OLD_TIME_CREATED=%s",
730 (hs_state_str != NULL) ?
" OLD_HS_STATE=" :
"",
731 (hs_state_str != NULL) ? hs_state_str :
"",
737 log_warn(
LD_BUG,
"Unrecognized status code %d", (
int)e);
744 const char *sp = strlen(circdesc) ?
" " :
"";
746 "650 CIRC_MINOR %lu %s%s%s%s\r\n",
766 CIRC_MINOR_EVENT_PURPOSE_CHANGED,
778 const struct timeval *old_tv_created)
781 CIRC_MINOR_EVENT_CANNIBALIZED,
793 char addrport_buf[64];
798 const char *purpose =
"";
804 if (tp == STREAM_EVENT_CLOSED &&
810 reason_buf[0] =
'\0';
813 case STREAM_EVENT_SENT_CONNECT: status =
"SENTCONNECT";
break;
814 case STREAM_EVENT_SENT_RESOLVE: status =
"SENTRESOLVE";
break;
815 case STREAM_EVENT_SUCCEEDED: status =
"SUCCEEDED";
break;
816 case STREAM_EVENT_FAILED: status =
"FAILED";
break;
817 case STREAM_EVENT_CLOSED: status =
"CLOSED";
break;
818 case STREAM_EVENT_NEW: status =
"NEW";
break;
819 case STREAM_EVENT_NEW_RESOLVE: status =
"NEWRESOLVE";
break;
820 case STREAM_EVENT_FAILED_RETRIABLE: status =
"DETACHED";
break;
821 case STREAM_EVENT_REMAP: status =
"REMAP";
break;
822 case STREAM_EVENT_CONTROLLER_WAIT: status =
"CONTROLLER_WAIT";
break;
823 case STREAM_EVENT_XOFF_SENT: status =
"XOFF_SENT";
break;
824 case STREAM_EVENT_XOFF_RECV: status =
"XOFF_RECV";
break;
825 case STREAM_EVENT_XON_SENT: status =
"XON_SENT";
break;
826 case STREAM_EVENT_XON_RECV: status =
"XON_RECV";
break;
828 log_warn(
LD_BUG,
"Unrecognized status code %d", (
int)tp);
831 if (reason_code && (tp == STREAM_EVENT_FAILED ||
832 tp == STREAM_EVENT_CLOSED ||
833 tp == STREAM_EVENT_FAILED_RETRIABLE)) {
842 " REASON=END REMOTE_REASON=%s", reason_str);
845 " REASON=%s", reason_str);
847 }
else if (reason_code && tp == STREAM_EVENT_REMAP) {
848 switch (reason_code) {
850 strlcpy(reason_buf,
" SOURCE=CACHE",
sizeof(reason_buf));
853 strlcpy(reason_buf,
" SOURCE=EXIT",
sizeof(reason_buf));
856 tor_snprintf(reason_buf,
sizeof(reason_buf),
" REASON=UNKNOWN_%d",
863 if (tp == STREAM_EVENT_NEW || tp == STREAM_EVENT_NEW_RESOLVE) {
869 if (strcmp(
ENTRY_TO_CONN(conn)->address,
"(Tor_internal)") != 0) {
870 tor_snprintf(addrport_buf,
sizeof(addrport_buf),
" SOURCE_ADDR=%s:%d",
877 addrport_buf[0] =
'\0';
880 addrport_buf[0] =
'\0';
883 if (tp == STREAM_EVENT_NEW_RESOLVE) {
884 purpose =
" PURPOSE=DNS_REQUEST";
885 }
else if (tp == STREAM_EVENT_NEW) {
888 int linked_dir_purpose = -1;
890 linked_dir_purpose = linked->
purpose;
892 purpose =
" PURPOSE=DIR_UPLOAD";
894 purpose =
" PURPOSE=DIR_FETCH";
896 purpose =
" PURPOSE=USER";
905 const char *sp = strlen(conndesc) ?
" " :
"";
907 "650 STREAM %"PRIu64
" %s %lu %s%s%s%s%s%s\r\n",
912 buf, reason_buf, addrport_buf, purpose, sp, conndesc);
933 char ncircs_buf[32] = {0};
940 case OR_CONN_EVENT_LAUNCHED: status =
"LAUNCHED";
break;
941 case OR_CONN_EVENT_CONNECTED: status =
"CONNECTED";
break;
942 case OR_CONN_EVENT_FAILED: status =
"FAILED";
break;
943 case OR_CONN_EVENT_CLOSED: status =
"CLOSED";
break;
944 case OR_CONN_EVENT_NEW: status =
"NEW";
break;
946 log_warn(
LD_BUG,
"Unrecognized status code %d", (
int)tp);
955 if (ncircs && (tp == OR_CONN_EVENT_FAILED || tp == OR_CONN_EVENT_CLOSED)) {
956 tor_snprintf(ncircs_buf,
sizeof(ncircs_buf),
" NCIRCS=%d", ncircs);
961 "650 ORCONN %s %s%s%s%s ID=%"PRIu64
"\r\n",
963 reason ?
" REASON=" :
"",
978 char tbuf[ISO_TIME_USEC_LEN+1];
986 "650 STREAM_BW %"PRIu64
" %lu %lu %s\r\n",
988 (
unsigned long)edge_conn->
n_read,
1007 char tbuf[ISO_TIME_USEC_LEN+1];
1020 "650 STREAM_BW %"PRIu64
" %lu %lu %s\r\n",
1022 (
unsigned long)edge_conn->
n_read,
1028 SMARTLIST_FOREACH_END(conn);
1048 SMARTLIST_FOREACH_END(circ);
1065 char tbuf[ISO_TIME_USEC_LEN+1];
1086 "650 CIRC_BW ID=%d READ=%lu WRITTEN=%lu TIME=%s "
1087 "DELIVERED_READ=%lu OVERHEAD_READ=%lu "
1088 "DELIVERED_WRITTEN=%lu OVERHEAD_WRITTEN=%lu%s\r\n",
1097 ccontrol_buf ? ccontrol_buf :
"");
1114 const char *conn_type_str;
1120 switch (conn->
type) {
1122 conn_type_str =
"OR";
1125 conn_type_str =
"DIR";
1128 conn_type_str =
"EXIT";
1134 "650 CONN_BW ID=%"PRIu64
" TYPE=%s "
1135 "READ=%lu WRITTEN=%lu\r\n",
1164 memset(cell_stats, 0,
sizeof(cell_stats_t));
1167 tor_assert(ent->command <= CELL_COMMAND_MAX_);
1168 if (!ent->removed && !ent->exitward) {
1169 cell_stats->added_cells_appward[ent->command] += 1;
1170 }
else if (!ent->removed && ent->exitward) {
1171 cell_stats->added_cells_exitward[ent->command] += 1;
1172 }
else if (!ent->exitward) {
1173 cell_stats->removed_cells_appward[ent->command] += 1;
1174 cell_stats->total_time_appward[ent->command] += ent->waiting_time * 10;
1176 cell_stats->removed_cells_exitward[ent->command] += 1;
1177 cell_stats->total_time_exitward[ent->command] += ent->waiting_time * 10;
1179 } SMARTLIST_FOREACH_END(ent);
1194 const uint64_t *include_if_non_zero,
1195 const uint64_t *number_to_include)
1199 for (i = 0; i <= CELL_COMMAND_MAX_; i++) {
1200 if (include_if_non_zero[i] > 0) {
1203 (number_to_include[i]));
1206 if (smartlist_len(key_value_strings) > 0) {
1212 smartlist_free(key_value_strings);
1219 cell_stats_t *cell_stats)
1233 cell_stats->added_cells_appward,
1234 cell_stats->added_cells_appward);
1236 cell_stats->removed_cells_appward,
1237 cell_stats->removed_cells_appward);
1239 cell_stats->removed_cells_appward,
1240 cell_stats->total_time_appward);
1248 cell_stats->added_cells_exitward,
1249 cell_stats->added_cells_exitward);
1251 cell_stats->removed_cells_exitward,
1252 cell_stats->removed_cells_exitward);
1254 cell_stats->removed_cells_exitward,
1255 cell_stats->total_time_exitward);
1259 smartlist_free(event_parts);
1267 cell_stats_t *cell_stats;
1269 if (!
get_options()->TestingEnableCellStatsEvent ||
1272 cell_stats = tor_malloc(
sizeof(cell_stats_t));
1274 if (!circ->testing_cell_stats)
1279 "650 CELL_STATS %s\r\n", event_string);
1282 SMARTLIST_FOREACH_END(circ);
1288#define N_BW_EVENTS_TO_CACHE 300
1290static int next_measurement_idx = 0;
1292static int n_measurements = 0;
1296} cached_bw_events[N_BW_EVENTS_TO_CACHE];
1303 cached_bw_events[next_measurement_idx].n_read = n_read;
1304 cached_bw_events[next_measurement_idx].n_written = n_written;
1305 if (++next_measurement_idx == N_BW_EVENTS_TO_CACHE)
1306 next_measurement_idx = 0;
1307 if (n_measurements < N_BW_EVENTS_TO_CACHE)
1312 "650 BW %lu %lu\r\n",
1313 (
unsigned long)n_read,
1314 (
unsigned long)n_written);
1324 int idx = (next_measurement_idx + N_BW_EVENTS_TO_CACHE - n_measurements)
1325 % N_BW_EVENTS_TO_CACHE;
1326 tor_assert(0 <= idx && idx < N_BW_EVENTS_TO_CACHE);
1330 for (i = 0; i < n_measurements; ++i) {
1331 tor_assert(0 <= idx && idx < N_BW_EVENTS_TO_CACHE);
1335 (
unsigned)bwe->n_read,
1336 (
unsigned)bwe->n_written);
1338 idx = (idx + 1) % N_BW_EVENTS_TO_CACHE;
1344 smartlist_free(elements);
1373 for (cp = msg; *cp; ++cp) {
1374 if (*cp ==
'\r' || *cp ==
'\n') {
1381 for (--cp; *cp ==
' '; --cp) {
1415 if (strchr(msg,
'\n')) {
1416 b = tor_strdup(msg);
1424 case LOG_ERR: s =
"ERR";
break;
1425 default: s =
"UnknownLogSeverity";
break;
1481 smartlist_free(names);
1493 time_t expires,
const char *error,
1494 const int cached, uint64_t stream_id)
1496 char *stream_id_str = NULL;
1501 tor_asprintf(&stream_id_str,
" STREAMID=%"PRIu64
"", stream_id);
1504 if (expires < 3 || expires == TIME_MAX)
1506 "650 ADDRMAP %s %s NEVER %s%s"
1507 "CACHED=\"%s\"%s\r\n",
1508 from, to, error ? error :
"", error ?
" " :
"",
1509 cached ?
"YES" :
"NO",
1510 stream_id ? stream_id_str :
"");
1512 char buf[ISO_TIME_LEN+1];
1513 char buf2[ISO_TIME_LEN+1];
1517 "650 ADDRMAP %s %s \"%s\" %s%sEXPIRES=\"%s\" "
1518 "CACHED=\"%s\"%s\r\n",
1519 from, to, buf, error ? error :
"",
1520 error ?
" " :
"", buf2, cached ?
"YES" :
"NO",
1521 stream_id ? stream_id_str:
"");
1535 if (get_cached_network_liveness() <= 0) {
1537 set_cached_network_liveness(1);
1538 log_debug(
LD_CONTROL,
"Sending NETWORK_LIVENESS UP");
1540 "650 NETWORK_LIVENESS UP\r\n");
1544 if (get_cached_network_liveness() > 0) {
1546 set_cached_network_liveness(0);
1547 log_debug(
LD_CONTROL,
"Sending NETWORK_LIVENESS DOWN");
1549 "650 NETWORK_LIVENESS DOWN\r\n");
1564 const char *event_string)
1567 char *s, *esc = NULL;
1585 smartlist_free(strs);
1619 const char *type_string = NULL;
1625 case BUILDTIMEOUT_SET_EVENT_COMPUTED:
1626 type_string =
"COMPUTED";
1628 case BUILDTIMEOUT_SET_EVENT_RESET:
1629 type_string =
"RESET";
1631 case BUILDTIMEOUT_SET_EVENT_SUSPENDED:
1632 type_string =
"SUSPENDED";
1634 case BUILDTIMEOUT_SET_EVENT_DISCARD:
1635 type_string =
"DISCARD";
1637 case BUILDTIMEOUT_SET_EVENT_RESUME:
1638 type_string =
"RESUME";
1641 type_string =
"UNKNOWN";
1646 "650 BUILDTIMEOUT_SET %s %s\r\n",
1656 const char *signal_string = NULL;
1661 for (
unsigned i = 0; signal_table[i].signal_name != NULL; ++i) {
1662 if ((
int)signal_num == signal_table[i].sig) {
1663 signal_string = signal_table[i].signal_name;
1668 if (signal_string == NULL) {
1669 log_warn(
LD_BUG,
"Unrecognized signal %lu in control_event_signal",
1670 (
unsigned long)signal_num);
1693 smartlist_free(statuses);
1713 char *user_buf = NULL;
1714 char format_buf[160];
1715 const char *status, *sev;
1718 case EVENT_STATUS_GENERAL:
1719 status =
"STATUS_GENERAL";
1721 case EVENT_STATUS_CLIENT:
1722 status =
"STATUS_CLIENT";
1724 case EVENT_STATUS_SERVER:
1725 status =
"STATUS_SERVER";
1728 log_warn(
LD_BUG,
"Unrecognized status type %d", type);
1742 log_warn(
LD_BUG,
"Unrecognized status severity %d", severity);
1745 if (
tor_snprintf(format_buf,
sizeof(format_buf),
"650 %s %s",
1747 log_warn(
LD_BUG,
"Format string too long.");
1751 log_warn(
LD_BUG,
"Failed to create user buffer.");
1761#define CONTROL_EVENT_STATUS_BODY(event, sev) \
1765 if (!EVENT_IS_INTERESTING(event)) \
1768 va_start(ap, format); \
1769 r = control_event_status((event), (sev), format, ap); \
1779 CONTROL_EVENT_STATUS_BODY(EVENT_STATUS_GENERAL, severity);
1788 CONTROL_EVENT_STATUS_BODY(EVENT_STATUS_GENERAL,
LOG_ERR);
1799 CONTROL_EVENT_STATUS_BODY(EVENT_STATUS_CLIENT, severity);
1808 CONTROL_EVENT_STATUS_BODY(EVENT_STATUS_CLIENT,
LOG_ERR);
1819 CONTROL_EVENT_STATUS_BODY(EVENT_STATUS_SERVER, severity);
1828 CONTROL_EVENT_STATUS_BODY(EVENT_STATUS_SERVER,
LOG_ERR);
1852 tor_snprintf(buf,
sizeof(buf),
"$%s~%s", hbuf, nickname);
1855 "650 GUARD ENTRY %s %s\r\n", buf, status);
1874 for (
const config_line_t *line = changes; line; line = line->next) {
1875 if (line->value == NULL) {
1883 "650-CONF_CHANGED\r\n%s\r\n650 OK\r\n", result);
1886 smartlist_free(lines);
1896 "650 CLIENTS_SEEN %s\r\n", controller_str);
1910 "650 TRANSPORT_LAUNCHED %s %s %s %u\r\n",
1911 mode, transport_name,
fmt_addr(addr), port);
1920 "650 PT_LOG %s\r\n",
1930 "650 PT_STATUS %s\r\n",
1941 switch (auth_type) {
1946 str =
"REND_V3_AUTH";
1960 static const char *str_unknown =
"UNKNOWN";
1961 const char *str_ret = str_unknown;
1964 if (!onion_address) {
1968 if (onion_address[0] ==
'\0') {
1972 str_ret = onion_address;
1988 const char *id_digest,
1989 const char *desc_id,
1990 const char *hsdir_index)
1992 char *hsdir_index_field = NULL;
1994 if (BUG(!id_digest || !desc_id)) {
1999 tor_asprintf(&hsdir_index_field,
" HSDIR_INDEX=%s", hsdir_index);
2003 "650 HS_DESC REQUESTED %s %s %s %s%s\r\n",
2008 hsdir_index_field ? hsdir_index_field :
"");
2021 const char *desc_id,
2024 char *replica_field = NULL;
2026 if (BUG(!onion_address || !desc_id)) {
2035 "650 HS_DESC CREATED %s UNKNOWN UNKNOWN %s%s\r\n",
2036 onion_address, desc_id,
2037 replica_field ? replica_field :
"");
2049 const char *id_digest,
2050 const char *desc_id,
2051 const char *hsdir_index)
2053 char *hsdir_index_field = NULL;
2055 if (BUG(!onion_address || !id_digest || !desc_id)) {
2060 tor_asprintf(&hsdir_index_field,
" HSDIR_INDEX=%s", hsdir_index);
2064 "650 HS_DESC UPLOAD %s UNKNOWN %s %s%s\r\n",
2068 hsdir_index_field ? hsdir_index_field :
"");
2081 const char *onion_address,
2082 const char *desc_id,
2084 const char *hsdir_id_digest,
2087 char *reason_field = NULL;
2089 if (BUG(!action || !onion_address)) {
2098 "650 HS_DESC %s %s %s %s%s%s\r\n",
2105 desc_id ? desc_id :
"",
2106 reason_field ? reason_field :
"");
2121 const char *onion_address,
2122 const char *id_digest,
2125 char *reason_field = NULL;
2127 if (BUG(!action || !id_digest)) {
2136 "650 HS_DESC %s %s UNKNOWN %s%s\r\n",
2140 reason_field ? reason_field :
"");
2149control_event_hsv3_descriptor_received(
const char *onion_address,
2150 const char *desc_id,
2151 const char *hsdir_id_digest)
2153 char *desc_id_field = NULL;
2155 if (BUG(!onion_address || !desc_id || !hsdir_id_digest)) {
2164 REND_NO_AUTH, hsdir_id_digest, NULL);
2174 const char *onion_address)
2176 if (BUG(!id_digest)) {
2191 const char *desc_id,
2192 const char *hsdir_id_digest,
2195 char *desc_id_field = NULL;
2197 if (BUG(!onion_address || !desc_id || !reason)) {
2206 REND_NO_AUTH, hsdir_id_digest, reason);
2217 const char *desc_id,
2218 const char *hsdir_id_digest,
2219 const char *content)
2221 static const char *event_name =
"HS_DESC_CONTENT";
2222 char *esc_content = NULL;
2224 if (!onion_address || !desc_id) {
2225 log_warn(
LD_BUG,
"Called with onion_address==%p, desc_id==%p, ",
2226 onion_address, desc_id);
2230 if (content == NULL) {
2237 "650+%s %s %s %s\r\n%s650 OK\r\n",
2254 const char *onion_address,
2257 if (BUG(!id_digest)) {
2265control_events_free_all(
void)
2269 stats_prev_n_read = stats_prev_n_written = 0;
2278 if (queued_events) {
2280 queued_event_free(ev));
2281 smartlist_free(queued_events);
2291#ifdef TOR_UNIT_TESTS
2294control_testing_set_global_event_mask(uint64_t mask)
void base16_encode(char *dest, size_t destlen, const char *src, size_t srclen)
Header file for channeltls.c.
const char * circuit_purpose_to_controller_hs_state_string(uint8_t purpose)
circuit_t * circuit_get_by_edge_conn(edge_connection_t *conn)
origin_circuit_t * TO_ORIGIN_CIRCUIT(circuit_t *x)
const char * circuit_purpose_to_controller_string(uint8_t purpose)
int circuit_count_pending_on_channel(channel_t *chan)
or_circuit_t * TO_OR_CIRCUIT(circuit_t *x)
void circuit_clear_testing_cell_stats(circuit_t *circ)
smartlist_t * circuit_get_global_list(void)
Header file for circuitlist.c.
#define CIRCUIT_IS_ORIGIN(c)
double circuit_build_times_quantile_cutoff(void)
Header file for circuitstats.c.
const char * cell_command_to_string(uint8_t command)
Header file for command.c.
struct event_base * tor_libevent_get_base(void)
mainloop_event_t * mainloop_event_new(void(*cb)(mainloop_event_t *, void *), void *userdata)
void mainloop_event_activate(mainloop_event_t *event)
Header for compat_libevent.c.
tor_mutex_t * tor_mutex_new(void)
void tor_mutex_release(tor_mutex_t *m)
void tor_mutex_acquire(tor_mutex_t *m)
void * tor_threadlocal_get(tor_threadlocal_t *threadlocal)
void tor_threadlocal_set(tor_threadlocal_t *threadlocal, void *value)
int tor_threadlocal_init(tor_threadlocal_t *threadlocal)
const or_options_t * get_options(void)
Header file for config.c.
char * congestion_control_get_control_port_fields(const origin_circuit_t *circ)
Public APIs for congestion control.
int connection_flush(connection_t *conn)
Header file for connection.c.
#define CONN_TYPE_CONTROL
edge_connection_t * TO_EDGE_CONN(connection_t *c)
Header file for connection_edge.c.
int connection_or_get_num_circuits(or_connection_t *conn)
Header file for connection_or.c.
control_connection_t * TO_CONTROL_CONN(connection_t *c)
Header file for control.c.
#define CONTROL_CONN_STATE_OPEN
Controller connection structure.
void control_event_pt_status(const char *status)
int control_event_my_descriptor_changed(void)
const struct control_event_t control_event_table[]
static tor_threadlocal_t block_event_queue_flag
int control_event_server_error(const char *format,...)
int control_event_stream_bandwidth(edge_connection_t *edge_conn)
const char * rend_auth_type_to_string(rend_auth_type_t auth_type)
void control_event_pt_log(const char *log)
static mainloop_event_t * flush_queued_events_event
static void flush_queued_events_cb(mainloop_event_t *event, void *arg)
int control_event_general_status(int severity, const char *format,...)
#define EVENT_IS_INTERESTING(e)
void format_cell_stats(char **event_string, circuit_t *circ, cell_stats_t *cell_stats)
STATIC void send_control_event_string(uint16_t event, const char *msg)
void control_event_clients_seen(const char *controller_str)
static int control_event_networkstatus_changed_helper(smartlist_t *statuses, uint16_t event, const char *event_string)
int control_event_bandwidth_used(uint32_t n_read, uint32_t n_written)
static int event_to_log_severity(int event)
static void queued_events_flush_all(int force)
void control_event_hs_descriptor_content(const char *onion_address, const char *desc_id, const char *hsdir_id_digest, const char *content)
int control_event_circuit_purpose_changed(origin_circuit_t *circ, int old_purpose)
int control_event_conn_bandwidth(connection_t *conn)
int control_event_circuit_cell_stats(void)
static int flush_queued_event_pending
int control_event_buildtimeout_set(buildtimeout_set_event_t type, const char *args)
int control_event_signal(uintptr_t signal_num)
void control_event_hs_descriptor_requested(const char *onion_address, rend_auth_type_t auth_type, const char *id_digest, const char *desc_id, const char *hsdir_index)
void disable_control_logging(void)
void control_event_hs_descriptor_upload_failed(const char *id_digest, const char *onion_address, const char *reason)
void sum_up_cell_stats_by_command(circuit_t *circ, cell_stats_t *cell_stats)
int control_event_stream_bandwidth_used(void)
static event_mask_t global_event_mask
int control_event_guard(const char *nickname, const char *digest, const char *status)
STATIC void queue_control_event_string(uint16_t event, char *msg)
static void clear_circ_bw_fields(void)
static smartlist_t * queued_control_events
int control_event_circuit_status(origin_circuit_t *circ, circuit_status_event_t tp, int reason_code)
static int disable_log_messages
void control_event_hs_descriptor_upload(const char *onion_address, const char *id_digest, const char *desc_id, const char *hsdir_index)
static void send_control_event_impl(uint16_t event, const char *format, va_list ap)
void control_event_hs_descriptor_uploaded(const char *id_digest, const char *onion_address)
void control_event_hs_descriptor_upload_end(const char *action, const char *onion_address, const char *id_digest, const char *reason)
int control_event_general_error(const char *format,...)
int control_event_networkstatus_changed(smartlist_t *statuses)
int control_event_server_status(int severity, const char *format,...)
static void queued_event_free_(queued_event_t *ev)
int control_event_circ_bandwidth_used_for_circ(origin_circuit_t *ocirc)
int control_event_is_interesting(int event)
int control_event_client_error(const char *format,...)
int control_event_or_conn_status(or_connection_t *conn, or_conn_status_event_t tp, int reason)
int control_event_circ_bandwidth_used(void)
void enable_control_logging(void)
void control_event_hsv3_descriptor_failed(const char *onion_address, const char *desc_id, const char *hsdir_id_digest, const char *reason)
static tor_mutex_t * queued_control_events_lock
int control_event_network_liveness_update(int liveness)
static int control_event_status(int type, int severity, const char *format, va_list args)
void control_event_transport_launched(const char *mode, const char *transport_name, tor_addr_t *addr, uint16_t port)
void append_cell_stats_by_command(smartlist_t *event_parts, const char *key, const uint64_t *include_if_non_zero, const uint64_t *number_to_include)
int control_event_conn_bandwidth_used(void)
void control_adjust_event_log_severity(void)
int control_event_client_status(int severity, const char *format,...)
int control_event_stream_status(entry_connection_t *conn, stream_status_event_t tp, int reason_code)
int control_event_networkstatus_changed_single(const routerstatus_t *rs)
int control_event_circuit_cannibalized(origin_circuit_t *circ, int old_purpose, const struct timeval *old_tv_created)
void control_logmsg_strip_newlines(char *msg)
static int control_event_circuit_status_minor(origin_circuit_t *circ, circuit_status_minor_event_t e, int purpose, const struct timeval *tv)
static void send_control_event(uint16_t event, const char *format,...)
int control_event_descriptors_changed(smartlist_t *routers)
int control_event_newconsensus(const networkstatus_t *consensus)
static int log_severity_to_event(int severity)
int control_event_address_mapped(const char *from, const char *to, time_t expires, const char *error, const int cached, uint64_t stream_id)
static void event_hs_descriptor_receive_end(const char *action, const char *onion_address, const char *desc_id, rend_auth_type_t auth_type, const char *hsdir_id_digest, const char *reason)
static const char * rend_hsaddress_str_or_unknown(const char *onion_address)
void control_event_hs_descriptor_created(const char *onion_address, const char *desc_id, int replica)
void control_event_logmsg_pending(void)
void control_update_global_event_mask(void)
void control_per_second_events(void)
void control_event_logmsg(int severity, log_domain_mask_t domain, const char *msg)
static void control_get_bytes_rw_last_sec(uint64_t *r, uint64_t *w)
void control_event_conf_changed(const config_line_t *changes)
int control_any_per_second_event_enabled(void)
#define ANY_EVENT_IS_INTERESTING(e)
Header file for control_events.c.
#define REMAP_STREAM_SOURCE_EXIT
circuit_status_minor_event_t
#define REMAP_STREAM_SOURCE_CACHE
char * entry_connection_describe_status_for_controller(const entry_connection_t *conn)
char * circuit_describe_status_for_controller(origin_circuit_t *circ)
const char * node_describe_longname_by_id(const char *id_digest)
void orconn_target_get_name(char *name, size_t len, or_connection_t *conn)
int write_stream_target_to_buf(entry_connection_t *conn, char *buf, size_t len)
Header file for control_fmt.c.
size_t write_escaped_data(const char *data, size_t len, char **out)
Header file for control_proto.c.
void router_get_verbose_nickname(char *buf, const routerinfo_t *router)
Header file for describe.c.
Header file for directory.c.
#define DIR_PURPOSE_IS_UPLOAD(p)
Entry connection structure.
#define ENTRY_TO_EDGE_CONN(c)
char * esc_for_log(const char *s)
void change_callback_log_severity(int loglevelMin, int loglevelMax, log_callback cb)
void flush_pending_log_callbacks(void)
uint64_t log_domain_mask_t
uint64_t get_bytes_read(void)
static uint64_t stats_n_bytes_written
static uint64_t stats_n_bytes_read
smartlist_t * get_connection_array(void)
uint64_t get_bytes_written(void)
void rescan_periodic_events(const or_options_t *options)
Header file for mainloop.c.
char * networkstatus_getinfo_helper_single(const routerstatus_t *rs)
Header file for networkstatus.c.
Networkstatus consensus/vote structure.
const node_t * node_get_by_id(const char *identity_digest)
void node_get_verbose_nickname(const node_t *node, char *verbose_name_out)
Header file for nodelist.c.
Master header file for Tor-specific functionality.
#define END_STREAM_REASON_FLAG_REMOTE
#define MAX_VERBOSE_NICKNAME_LEN
#define END_STREAM_REASON_FLAG_ALREADY_SENT_CLOSED
#define END_CIRC_REASON_FLAG_REMOTE
Origin circuit structure.
int tor_vasprintf(char **strp, const char *fmt, va_list args)
int tor_asprintf(char **strp, const char *fmt,...)
int tor_snprintf(char *str, size_t size, const char *format,...)
const char * stream_end_reason_to_control_string(int reason)
const char * orconn_end_reason_to_control_string(int r)
const char * circuit_end_reason_to_control_string(int reason)
Header file for reasons.c.
void smartlist_add_asprintf(struct smartlist_t *sl, const char *pattern,...)
char * smartlist_join_strings(smartlist_t *sl, const char *join, int terminate, size_t *len_out)
void smartlist_add_strdup(struct smartlist_t *sl, const char *string)
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)
uint64_t global_identifier
uint32_t num_circ_timeouts
uint32_t num_circ_succeeded
smartlist_t * testing_cell_stats
uint64_t global_identifier
uint32_t n_written_conn_bw
socks_request_t * socks_request
unsigned int use_begindir
smartlist_t * routerstatus_list
uint32_t n_written_circ_bw
uint32_t global_identifier
uint32_t n_overhead_written_circ_bw
uint32_t n_delivered_read_circ_bw
uint32_t n_delivered_written_circ_bw
uint32_t n_overhead_read_circ_bw
#define MOCK_IMPL(rv, funcname, arglist)
void format_iso_time_nospace_usec(char *buf, const struct timeval *tv)
void format_iso_time(char *buf, time_t t)
void format_local_iso_time(char *buf, time_t t)
void tor_gettimeofday(struct timeval *timeval)
#define tor_fragile_assert()