10 #define CONTROL_MODULE_PRIVATE
11 #define CONTROL_EVENTS_PRIVATE
12 #define OCIRC_EVENT_PRIVATE
38 #include "core/or/or_circuit_st.h"
49 #define STATE_IS_OPEN(s) ((s) == CONTROL_CONN_STATE_OPEN)
60 #define EVENT_IS_INTERESTING(e) \
61 (!! (global_event_mask & EVENT_MASK_(e)))
64 #define ANY_EVENT_IS_INTERESTING(e) \
65 (!! (global_event_mask & (e)))
68 const char *format, va_list ap)
75 const char *format, ...)
81 { EVENT_CIRCUIT_STATUS,
"CIRC" },
82 { EVENT_CIRCUIT_STATUS_MINOR,
"CIRC_MINOR" },
83 { EVENT_STREAM_STATUS,
"STREAM" },
84 { EVENT_OR_CONN_STATUS,
"ORCONN" },
85 { EVENT_BANDWIDTH_USED,
"BW" },
86 { EVENT_DEBUG_MSG,
"DEBUG" },
87 { EVENT_INFO_MSG,
"INFO" },
88 { EVENT_NOTICE_MSG,
"NOTICE" },
89 { EVENT_WARN_MSG,
"WARN" },
90 { EVENT_ERR_MSG,
"ERR" },
91 { EVENT_NEW_DESC,
"NEWDESC" },
92 { EVENT_ADDRMAP,
"ADDRMAP" },
93 { EVENT_DESCCHANGED,
"DESCCHANGED" },
95 { EVENT_STATUS_GENERAL,
"STATUS_GENERAL" },
96 { EVENT_STATUS_CLIENT,
"STATUS_CLIENT" },
97 { EVENT_STATUS_SERVER,
"STATUS_SERVER" },
98 { EVENT_GUARD,
"GUARD" },
99 { EVENT_STREAM_BANDWIDTH_USED,
"STREAM_BW" },
100 { EVENT_CLIENTS_SEEN,
"CLIENTS_SEEN" },
101 { EVENT_NEWCONSENSUS,
"NEWCONSENSUS" },
102 { EVENT_BUILDTIMEOUT_SET,
"BUILDTIMEOUT_SET" },
103 { EVENT_GOT_SIGNAL,
"SIGNAL" },
104 { EVENT_CONF_CHANGED,
"CONF_CHANGED"},
105 { EVENT_CONN_BW,
"CONN_BW" },
106 { EVENT_CELL_STATS,
"CELL_STATS" },
107 { EVENT_CIRC_BANDWIDTH_USED,
"CIRC_BW" },
108 { EVENT_TRANSPORT_LAUNCHED,
"TRANSPORT_LAUNCHED" },
109 { EVENT_HS_DESC,
"HS_DESC" },
110 { EVENT_HS_DESC_CONTENT,
"HS_DESC_CONTENT" },
111 { EVENT_NETWORK_LIVENESS,
"NETWORK_LIVENESS" },
121 case LOG_INFO:
return EVENT_INFO_MSG;
123 case LOG_WARN:
return EVENT_WARN_MSG;
124 case LOG_ERR:
return EVENT_ERR_MSG;
142 SMARTLIST_FOREACH_END(circ);
152 double timeout_rate = 0.0;
153 double close_rate = 0.0;
156 case BUILDTIMEOUT_SET_EVENT_RESET:
157 case BUILDTIMEOUT_SET_EVENT_SUSPENDED:
158 case BUILDTIMEOUT_SET_EVENT_DISCARD:
161 case BUILDTIMEOUT_SET_EVENT_COMPUTED:
162 case BUILDTIMEOUT_SET_EVENT_RESUME:
182 const double total_circuits =
184 if (total_circuits >= 1.0) {
190 "TIMEOUT_MS=%lu XM=%lu ALPHA=%f CUTOFF_QUANTILE=%f "
191 "TIMEOUT_RATE=%f CLOSE_MS=%lu CLOSE_RATE=%f",
194 (
unsigned long)cbt->
Xm, cbt->
alpha, qnt,
209 event_mask_t old_mask, new_mask;
218 control_connection_t *conn = TO_CONTROL_CONN(_conn);
219 global_event_mask |= conn->event_mask;
230 #define NEWLY_ENABLED(ev) \
231 (! (old_mask & (ev)) && (new_mask & (ev)))
235 if (NEWLY_ENABLED(EVENT_STREAM_BANDWIDTH_USED)) {
239 edge_connection_t *edge_conn = TO_EDGE_CONN(conn);
240 edge_conn->n_written = edge_conn->n_read = 0;
244 if (NEWLY_ENABLED(EVENT_CIRC_BANDWIDTH_USED)) {
247 if (NEWLY_ENABLED(EVENT_BANDWIDTH_USED)) {
265 case EVENT_INFO_MSG:
return LOG_INFO;
267 case EVENT_WARN_MSG:
return LOG_WARN;
268 case EVENT_ERR_MSG:
return LOG_ERR;
280 int min_log_event=EVENT_ERR_MSG, max_log_event=EVENT_DEBUG_MSG;
282 for (i = EVENT_DEBUG_MSG; i <= EVENT_ERR_MSG; ++i) {
288 for (i = EVENT_ERR_MSG; i >= EVENT_DEBUG_MSG; --i) {
295 if (min_log_event > EVENT_NOTICE_MSG)
296 min_log_event = EVENT_NOTICE_MSG;
297 if (max_log_event < EVENT_ERR_MSG)
298 max_log_event = EVENT_ERR_MSG;
300 if (min_log_event <= max_log_event)
324 EVENT_MASK_(EVENT_BANDWIDTH_USED) |
325 EVENT_MASK_(EVENT_CELL_STATS) |
326 EVENT_MASK_(EVENT_CIRC_BANDWIDTH_USED) |
327 EVENT_MASK_(EVENT_CONN_BW) |
328 EVENT_MASK_(EVENT_STREAM_BANDWIDTH_USED)
334 static uint64_t stats_prev_n_read = 0;
337 static uint64_t stats_prev_n_written = 0;
368 uint64_t bytes_read, bytes_written;
404 control_initialize_event_queue(
void)
426 get_block_event_queue(
void)
429 if (PREDICT_UNLIKELY(val == NULL)) {
430 val = tor_malloc_zero(
sizeof(
int));
457 int *block_event_queue = get_block_event_queue();
458 if (*block_event_queue) {
468 ++*block_event_queue;
474 int activate_event = 0;
482 --*block_event_queue;
488 if (activate_event) {
494 #define queued_event_free(ev) \
495 FREE_AND_NULL(queued_event_t, queued_event_free_, (ev))
525 int *block_event_queue = get_block_event_queue();
526 ++*block_event_queue;
538 !conn->marked_for_close &&
544 } SMARTLIST_FOREACH_END(conn);
547 const event_mask_t bit = ((event_mask_t)1) << ev->event;
548 const size_t msg_len = strlen(ev->msg);
551 if (control_conn->event_mask & bit) {
552 connection_buf_add(ev->msg, msg_len,
TO_CONN(control_conn));
554 } SMARTLIST_FOREACH_END(control_conn);
556 queued_event_free(ev);
557 } SMARTLIST_FOREACH_END(ev);
563 } SMARTLIST_FOREACH_END(control_conn);
566 smartlist_free(queued_events);
567 smartlist_free(controllers);
569 --*block_event_queue;
591 tor_assert(event >= EVENT_MIN_ && event <= EVENT_MAX_);
601 const char *format, va_list ap)
608 log_warn(
LD_BUG,
"Unable to format event for controller.");
620 const char *format, ...)
623 va_start(ap, format);
635 char reasons[64] =
"";
643 case CIRC_EVENT_LAUNCHED: status =
"LAUNCHED";
break;
644 case CIRC_EVENT_BUILT: status =
"BUILT";
break;
645 case CIRC_EVENT_EXTENDED: status =
"EXTENDED";
break;
646 case CIRC_EVENT_FAILED: status =
"FAILED";
break;
647 case CIRC_EVENT_CLOSED: status =
"CLOSED";
break;
649 log_warn(
LD_BUG,
"Unrecognized status code %d", (
int)tp);
654 if (tp == CIRC_EVENT_FAILED || tp == CIRC_EVENT_CLOSED) {
656 char unk_reason_buf[16];
658 tor_snprintf(unk_reason_buf, 16,
"UNKNOWN_%d", reason_code);
659 reason_str = unk_reason_buf;
663 " REASON=DESTROYED REMOTE_REASON=%s", reason_str);
666 " REASON=%s", reason_str);
672 const char *sp = strlen(circdesc) ?
" " :
"";
674 "650 CIRC %lu %s%s%s%s\r\n",
690 int purpose,
const struct timeval *tv)
692 const char *event_desc;
693 char event_tail[160] =
"";
700 case CIRC_MINOR_EVENT_PURPOSE_CHANGED:
701 event_desc =
"PURPOSE_CHANGED";
705 const char *hs_state_str =
708 " OLD_PURPOSE=%s%s%s",
710 (hs_state_str != NULL) ?
" OLD_HS_STATE=" :
"",
711 (hs_state_str != NULL) ? hs_state_str :
"");
715 case CIRC_MINOR_EVENT_CANNIBALIZED:
716 event_desc =
"CANNIBALIZED";
720 const char *hs_state_str =
722 const struct timeval *old_timestamp_began = tv;
723 char tbuf[ISO_TIME_USEC_LEN+1];
727 " OLD_PURPOSE=%s%s%s OLD_TIME_CREATED=%s",
729 (hs_state_str != NULL) ?
" OLD_HS_STATE=" :
"",
730 (hs_state_str != NULL) ? hs_state_str :
"",
736 log_warn(
LD_BUG,
"Unrecognized status code %d", (
int)e);
743 const char *sp = strlen(circdesc) ?
" " :
"";
745 "650 CIRC_MINOR %lu %s%s%s%s\r\n",
765 CIRC_MINOR_EVENT_PURPOSE_CHANGED,
777 const struct timeval *old_tv_created)
780 CIRC_MINOR_EVENT_CANNIBALIZED,
792 char addrport_buf[64];
797 const char *purpose =
"";
803 if (tp == STREAM_EVENT_CLOSED &&
809 reason_buf[0] =
'\0';
812 case STREAM_EVENT_SENT_CONNECT: status =
"SENTCONNECT";
break;
813 case STREAM_EVENT_SENT_RESOLVE: status =
"SENTRESOLVE";
break;
814 case STREAM_EVENT_SUCCEEDED: status =
"SUCCEEDED";
break;
815 case STREAM_EVENT_FAILED: status =
"FAILED";
break;
816 case STREAM_EVENT_CLOSED: status =
"CLOSED";
break;
817 case STREAM_EVENT_NEW: status =
"NEW";
break;
818 case STREAM_EVENT_NEW_RESOLVE: status =
"NEWRESOLVE";
break;
819 case STREAM_EVENT_FAILED_RETRIABLE: status =
"DETACHED";
break;
820 case STREAM_EVENT_REMAP: status =
"REMAP";
break;
821 case STREAM_EVENT_CONTROLLER_WAIT: status =
"CONTROLLER_WAIT";
break;
823 log_warn(
LD_BUG,
"Unrecognized status code %d", (
int)tp);
826 if (reason_code && (tp == STREAM_EVENT_FAILED ||
827 tp == STREAM_EVENT_CLOSED ||
828 tp == STREAM_EVENT_FAILED_RETRIABLE)) {
837 " REASON=END REMOTE_REASON=%s", reason_str);
840 " REASON=%s", reason_str);
842 }
else if (reason_code && tp == STREAM_EVENT_REMAP) {
843 switch (reason_code) {
845 strlcpy(reason_buf,
" SOURCE=CACHE",
sizeof(reason_buf));
848 strlcpy(reason_buf,
" SOURCE=EXIT",
sizeof(reason_buf));
851 tor_snprintf(reason_buf,
sizeof(reason_buf),
" REASON=UNKNOWN_%d",
858 if (tp == STREAM_EVENT_NEW || tp == STREAM_EVENT_NEW_RESOLVE) {
864 if (strcmp(
ENTRY_TO_CONN(conn)->address,
"(Tor_internal)") != 0) {
865 tor_snprintf(addrport_buf,
sizeof(addrport_buf),
" SOURCE_ADDR=%s:%d",
872 addrport_buf[0] =
'\0';
875 addrport_buf[0] =
'\0';
878 if (tp == STREAM_EVENT_NEW_RESOLVE) {
879 purpose =
" PURPOSE=DNS_REQUEST";
880 }
else if (tp == STREAM_EVENT_NEW) {
883 int linked_dir_purpose = -1;
885 linked_dir_purpose = linked->
purpose;
887 purpose =
" PURPOSE=DIR_UPLOAD";
889 purpose =
" PURPOSE=DIR_FETCH";
891 purpose =
" PURPOSE=USER";
900 const char *sp = strlen(conndesc) ?
" " :
"";
902 "650 STREAM %"PRIu64
" %s %lu %s%s%s%s%s%s\r\n",
907 buf, reason_buf, addrport_buf, purpose, sp, conndesc);
928 char ncircs_buf[32] = {0};
935 case OR_CONN_EVENT_LAUNCHED: status =
"LAUNCHED";
break;
936 case OR_CONN_EVENT_CONNECTED: status =
"CONNECTED";
break;
937 case OR_CONN_EVENT_FAILED: status =
"FAILED";
break;
938 case OR_CONN_EVENT_CLOSED: status =
"CLOSED";
break;
939 case OR_CONN_EVENT_NEW: status =
"NEW";
break;
941 log_warn(
LD_BUG,
"Unrecognized status code %d", (
int)tp);
950 if (ncircs && (tp == OR_CONN_EVENT_FAILED || tp == OR_CONN_EVENT_CLOSED)) {
951 tor_snprintf(ncircs_buf,
sizeof(ncircs_buf),
" NCIRCS=%d", ncircs);
956 "650 ORCONN %s %s%s%s%s ID=%"PRIu64
"\r\n",
958 reason ?
" REASON=" :
"",
973 char tbuf[ISO_TIME_USEC_LEN+1];
981 "650 STREAM_BW %"PRIu64
" %lu %lu %s\r\n",
983 (
unsigned long)edge_conn->
n_read,
1002 char tbuf[ISO_TIME_USEC_LEN+1];
1015 "650 STREAM_BW %"PRIu64
" %lu %lu %s\r\n",
1017 (
unsigned long)edge_conn->
n_read,
1023 SMARTLIST_FOREACH_END(conn);
1043 SMARTLIST_FOREACH_END(circ);
1060 char tbuf[ISO_TIME_USEC_LEN+1];
1079 "650 CIRC_BW ID=%d READ=%lu WRITTEN=%lu TIME=%s "
1080 "DELIVERED_READ=%lu OVERHEAD_READ=%lu "
1081 "DELIVERED_WRITTEN=%lu OVERHEAD_WRITTEN=%lu\r\n",
1102 const char *conn_type_str;
1108 switch (conn->
type) {
1110 conn_type_str =
"OR";
1113 conn_type_str =
"DIR";
1116 conn_type_str =
"EXIT";
1122 "650 CONN_BW ID=%"PRIu64
" TYPE=%s "
1123 "READ=%lu WRITTEN=%lu\r\n",
1152 memset(cell_stats, 0,
sizeof(cell_stats_t));
1155 tor_assert(ent->command <= CELL_COMMAND_MAX_);
1156 if (!ent->removed && !ent->exitward) {
1157 cell_stats->added_cells_appward[ent->command] += 1;
1158 }
else if (!ent->removed && ent->exitward) {
1159 cell_stats->added_cells_exitward[ent->command] += 1;
1160 }
else if (!ent->exitward) {
1161 cell_stats->removed_cells_appward[ent->command] += 1;
1162 cell_stats->total_time_appward[ent->command] += ent->waiting_time * 10;
1164 cell_stats->removed_cells_exitward[ent->command] += 1;
1165 cell_stats->total_time_exitward[ent->command] += ent->waiting_time * 10;
1167 } SMARTLIST_FOREACH_END(ent);
1182 const uint64_t *include_if_non_zero,
1183 const uint64_t *number_to_include)
1187 for (i = 0; i <= CELL_COMMAND_MAX_; i++) {
1188 if (include_if_non_zero[i] > 0) {
1191 (number_to_include[i]));
1194 if (smartlist_len(key_value_strings) > 0) {
1200 smartlist_free(key_value_strings);
1207 cell_stats_t *cell_stats)
1221 cell_stats->added_cells_appward,
1222 cell_stats->added_cells_appward);
1224 cell_stats->removed_cells_appward,
1225 cell_stats->removed_cells_appward);
1227 cell_stats->removed_cells_appward,
1228 cell_stats->total_time_appward);
1236 cell_stats->added_cells_exitward,
1237 cell_stats->added_cells_exitward);
1239 cell_stats->removed_cells_exitward,
1240 cell_stats->removed_cells_exitward);
1242 cell_stats->removed_cells_exitward,
1243 cell_stats->total_time_exitward);
1247 smartlist_free(event_parts);
1255 cell_stats_t *cell_stats;
1257 if (!
get_options()->TestingEnableCellStatsEvent ||
1260 cell_stats = tor_malloc(
sizeof(cell_stats_t));
1262 if (!circ->testing_cell_stats)
1267 "650 CELL_STATS %s\r\n", event_string);
1270 SMARTLIST_FOREACH_END(circ);
1276 #define N_BW_EVENTS_TO_CACHE 300
1278 static int next_measurement_idx = 0;
1280 static int n_measurements = 0;
1284 } cached_bw_events[N_BW_EVENTS_TO_CACHE];
1291 cached_bw_events[next_measurement_idx].n_read = n_read;
1292 cached_bw_events[next_measurement_idx].n_written = n_written;
1293 if (++next_measurement_idx == N_BW_EVENTS_TO_CACHE)
1294 next_measurement_idx = 0;
1295 if (n_measurements < N_BW_EVENTS_TO_CACHE)
1300 "650 BW %lu %lu\r\n",
1301 (
unsigned long)n_read,
1302 (
unsigned long)n_written);
1309 get_bw_samples(
void)
1312 int idx = (next_measurement_idx + N_BW_EVENTS_TO_CACHE - n_measurements)
1313 % N_BW_EVENTS_TO_CACHE;
1314 tor_assert(0 <= idx && idx < N_BW_EVENTS_TO_CACHE);
1318 for (i = 0; i < n_measurements; ++i) {
1319 tor_assert(0 <= idx && idx < N_BW_EVENTS_TO_CACHE);
1323 (
unsigned)bwe->n_read,
1324 (
unsigned)bwe->n_written);
1326 idx = (idx + 1) % N_BW_EVENTS_TO_CACHE;
1332 smartlist_free(elements);
1361 for (cp = msg; *cp; ++cp) {
1362 if (*cp ==
'\r' || *cp ==
'\n') {
1369 for (--cp; *cp ==
' '; --cp) {
1403 if (strchr(msg,
'\n')) {
1404 b = tor_strdup(msg);
1412 case LOG_ERR: s =
"ERR";
break;
1413 default: s =
"UnknownLogSeverity";
break;
1469 smartlist_free(names);
1481 time_t expires,
const char *error,
1482 const int cached, uint64_t stream_id)
1484 char *stream_id_str = NULL;
1489 tor_asprintf(&stream_id_str,
" STREAMID=%"PRIu64
"", stream_id);
1492 if (expires < 3 || expires == TIME_MAX)
1494 "650 ADDRMAP %s %s NEVER %s%s"
1495 "CACHED=\"%s\"%s\r\n",
1496 from, to, error ? error :
"", error ?
" " :
"",
1497 cached ?
"YES" :
"NO",
1498 stream_id ? stream_id_str :
"");
1500 char buf[ISO_TIME_LEN+1];
1501 char buf2[ISO_TIME_LEN+1];
1505 "650 ADDRMAP %s %s \"%s\" %s%sEXPIRES=\"%s\" "
1506 "CACHED=\"%s\"%s\r\n",
1507 from, to, buf, error ? error :
"",
1508 error ?
" " :
"", buf2, cached ?
"YES" :
"NO",
1509 stream_id ? stream_id_str:
"");
1523 if (get_cached_network_liveness() <= 0) {
1525 set_cached_network_liveness(1);
1526 log_debug(
LD_CONTROL,
"Sending NETWORK_LIVENESS UP");
1528 "650 NETWORK_LIVENESS UP\r\n");
1532 if (get_cached_network_liveness() > 0) {
1534 set_cached_network_liveness(0);
1535 log_debug(
LD_CONTROL,
"Sending NETWORK_LIVENESS DOWN");
1537 "650 NETWORK_LIVENESS DOWN\r\n");
1552 const char *event_string)
1555 char *s, *esc = NULL;
1573 smartlist_free(strs);
1607 const char *type_string = NULL;
1613 case BUILDTIMEOUT_SET_EVENT_COMPUTED:
1614 type_string =
"COMPUTED";
1616 case BUILDTIMEOUT_SET_EVENT_RESET:
1617 type_string =
"RESET";
1619 case BUILDTIMEOUT_SET_EVENT_SUSPENDED:
1620 type_string =
"SUSPENDED";
1622 case BUILDTIMEOUT_SET_EVENT_DISCARD:
1623 type_string =
"DISCARD";
1625 case BUILDTIMEOUT_SET_EVENT_RESUME:
1626 type_string =
"RESUME";
1629 type_string =
"UNKNOWN";
1634 "650 BUILDTIMEOUT_SET %s %s\r\n",
1644 const char *signal_string = NULL;
1649 for (
unsigned i = 0; signal_table[i].signal_name != NULL; ++i) {
1650 if ((
int)signal_num == signal_table[i].sig) {
1651 signal_string = signal_table[i].signal_name;
1656 if (signal_string == NULL) {
1657 log_warn(
LD_BUG,
"Unrecognized signal %lu in control_event_signal",
1658 (
unsigned long)signal_num);
1681 smartlist_free(statuses);
1701 char *user_buf = NULL;
1702 char format_buf[160];
1703 const char *status, *sev;
1706 case EVENT_STATUS_GENERAL:
1707 status =
"STATUS_GENERAL";
1709 case EVENT_STATUS_CLIENT:
1710 status =
"STATUS_CLIENT";
1712 case EVENT_STATUS_SERVER:
1713 status =
"STATUS_SERVER";
1716 log_warn(
LD_BUG,
"Unrecognized status type %d", type);
1730 log_warn(
LD_BUG,
"Unrecognized status severity %d", severity);
1733 if (
tor_snprintf(format_buf,
sizeof(format_buf),
"650 %s %s",
1735 log_warn(
LD_BUG,
"Format string too long.");
1739 log_warn(
LD_BUG,
"Failed to create user buffer.");
1749 #define CONTROL_EVENT_STATUS_BODY(event, sev) \
1753 if (!EVENT_IS_INTERESTING(event)) \
1756 va_start(ap, format); \
1757 r = control_event_status((event), (sev), format, ap); \
1767 CONTROL_EVENT_STATUS_BODY(EVENT_STATUS_GENERAL, severity);
1776 CONTROL_EVENT_STATUS_BODY(EVENT_STATUS_GENERAL,
LOG_ERR);
1787 CONTROL_EVENT_STATUS_BODY(EVENT_STATUS_CLIENT, severity);
1796 CONTROL_EVENT_STATUS_BODY(EVENT_STATUS_CLIENT,
LOG_ERR);
1807 CONTROL_EVENT_STATUS_BODY(EVENT_STATUS_SERVER, severity);
1816 CONTROL_EVENT_STATUS_BODY(EVENT_STATUS_SERVER,
LOG_ERR);
1840 tor_snprintf(buf,
sizeof(buf),
"$%s~%s", hbuf, nickname);
1843 "650 GUARD ENTRY %s %s\r\n", buf, status);
1862 for (
const config_line_t *line = changes; line; line = line->next) {
1863 if (line->value == NULL) {
1871 "650-CONF_CHANGED\r\n%s\r\n650 OK\r\n", result);
1874 smartlist_free(lines);
1884 "650 CLIENTS_SEEN %s\r\n", controller_str);
1898 "650 TRANSPORT_LAUNCHED %s %s %s %u\r\n",
1899 mode, transport_name,
fmt_addr(addr), port);
1908 "650 PT_LOG %s\r\n",
1918 "650 PT_STATUS %s\r\n",
1929 switch (auth_type) {
1934 str =
"REND_V3_AUTH";
1948 static const char *str_unknown =
"UNKNOWN";
1949 const char *str_ret = str_unknown;
1952 if (!onion_address) {
1956 if (onion_address[0] ==
'\0') {
1960 str_ret = onion_address;
1976 const char *id_digest,
1977 const char *desc_id,
1978 const char *hsdir_index)
1980 char *hsdir_index_field = NULL;
1982 if (BUG(!id_digest || !desc_id)) {
1987 tor_asprintf(&hsdir_index_field,
" HSDIR_INDEX=%s", hsdir_index);
1991 "650 HS_DESC REQUESTED %s %s %s %s%s\r\n",
1996 hsdir_index_field ? hsdir_index_field :
"");
2009 const char *desc_id,
2012 char *replica_field = NULL;
2014 if (BUG(!onion_address || !desc_id)) {
2023 "650 HS_DESC CREATED %s UNKNOWN UNKNOWN %s%s\r\n",
2024 onion_address, desc_id,
2025 replica_field ? replica_field :
"");
2037 const char *id_digest,
2038 const char *desc_id,
2039 const char *hsdir_index)
2041 char *hsdir_index_field = NULL;
2043 if (BUG(!onion_address || !id_digest || !desc_id)) {
2048 tor_asprintf(&hsdir_index_field,
" HSDIR_INDEX=%s", hsdir_index);
2052 "650 HS_DESC UPLOAD %s UNKNOWN %s %s%s\r\n",
2056 hsdir_index_field ? hsdir_index_field :
"");
2069 const char *onion_address,
2070 const char *desc_id,
2072 const char *hsdir_id_digest,
2075 char *reason_field = NULL;
2077 if (BUG(!action || !onion_address)) {
2086 "650 HS_DESC %s %s %s %s%s%s\r\n",
2093 desc_id ? desc_id :
"",
2094 reason_field ? reason_field :
"");
2109 const char *onion_address,
2110 const char *id_digest,
2113 char *reason_field = NULL;
2115 if (BUG(!action || !id_digest)) {
2124 "650 HS_DESC %s %s UNKNOWN %s%s\r\n",
2128 reason_field ? reason_field :
"");
2137 control_event_hsv3_descriptor_received(
const char *onion_address,
2138 const char *desc_id,
2139 const char *hsdir_id_digest)
2141 char *desc_id_field = NULL;
2143 if (BUG(!onion_address || !desc_id || !hsdir_id_digest)) {
2152 REND_NO_AUTH, hsdir_id_digest, NULL);
2162 const char *onion_address)
2164 if (BUG(!id_digest)) {
2179 const char *desc_id,
2180 const char *hsdir_id_digest,
2183 char *desc_id_field = NULL;
2185 if (BUG(!onion_address || !desc_id || !reason)) {
2194 REND_NO_AUTH, hsdir_id_digest, reason);
2205 const char *desc_id,
2206 const char *hsdir_id_digest,
2207 const char *content)
2209 static const char *event_name =
"HS_DESC_CONTENT";
2210 char *esc_content = NULL;
2212 if (!onion_address || !desc_id) {
2213 log_warn(
LD_BUG,
"Called with onion_address==%p, desc_id==%p, ",
2214 onion_address, desc_id);
2218 if (content == NULL) {
2225 "650+%s %s %s %s\r\n%s650 OK\r\n",
2242 const char *onion_address,
2245 if (BUG(!id_digest)) {
2253 control_events_free_all(
void)
2257 stats_prev_n_read = stats_prev_n_written = 0;
2266 if (queued_events) {
2268 queued_event_free(ev));
2269 smartlist_free(queued_events);
2279 #ifdef TOR_UNIT_TESTS
2282 control_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)
const char * circuit_purpose_to_controller_string(uint8_t purpose)
smartlist_t * circuit_get_global_list(void)
int circuit_count_pending_on_channel(channel_t *chan)
origin_circuit_t * TO_ORIGIN_CIRCUIT(circuit_t *x)
or_circuit_t * TO_OR_CIRCUIT(circuit_t *x)
void circuit_clear_testing_cell_stats(circuit_t *circ)
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.
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)
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,...)
static const char * rend_hsaddress_str_or_unknown(const char *onion_address)
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)
const char * rend_auth_type_to_string(rend_auth_type_t auth_type)
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)
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)
const char * node_describe_longname_by_id(const char *id_digest)
char * circuit_describe_status_for_controller(origin_circuit_t *circ)
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)
smartlist_t * smartlist_new(void)
void smartlist_add_strdup(struct smartlist_t *sl, const char *string)
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()