69 #define REPHIST_PRIVATE
85 #include "core/or/or_circuit_st.h"
87 #include <event2/dns.h>
100 #define STABILITY_EPSILON 0.0001
103 #define STABILITY_ALPHA 0.95
105 #define STABILITY_INTERVAL (12*60*60)
135 time_t start_of_downtime;
136 unsigned long weighted_uptime;
137 unsigned long total_weighted_time;
183 static time_t started_tracking_stability = 0;
194 time_t overload_general_time;
197 time_t overload_ratelimits_time;
199 uint64_t overload_read_count;
201 uint64_t overload_write_count;
204 time_t overload_fd_exhausted_time;
206 uint64_t overload_fd_exhausted;
215 static uint64_t stats_n_write_limit_reached = 0;
225 uint64_t stats_n_error_none;
226 uint64_t stats_n_error_format;
227 uint64_t stats_n_error_serverfailed;
228 uint64_t stats_n_error_notexist;
229 uint64_t stats_n_error_notimpl;
230 uint64_t stats_n_error_refused;
233 uint64_t stats_n_error_truncated;
234 uint64_t stats_n_error_unknown;
235 uint64_t stats_n_error_timeout;
236 uint64_t stats_n_error_shutdown;
237 uint64_t stats_n_error_cancel;
238 uint64_t stats_n_error_nodata;
243 uint64_t stats_n_request;
261 return &dns_PTR_stats;
263 return &dns_AAAA_stats;
275 if (BUG(!dns_stats)) {
281 return dns_stats->stats_n_error_none;
283 return dns_stats->stats_n_error_format;
284 case DNS_ERR_SERVERFAILED:
285 return dns_stats->stats_n_error_serverfailed;
286 case DNS_ERR_NOTEXIST:
287 return dns_stats->stats_n_error_notexist;
288 case DNS_ERR_NOTIMPL:
289 return dns_stats->stats_n_error_notimpl;
290 case DNS_ERR_REFUSED:
291 return dns_stats->stats_n_error_refused;
292 case DNS_ERR_TRUNCATED:
293 return dns_stats->stats_n_error_truncated;
294 case DNS_ERR_UNKNOWN:
295 return dns_stats->stats_n_error_unknown;
296 case DNS_ERR_TIMEOUT:
297 return dns_stats->stats_n_error_timeout;
298 case DNS_ERR_SHUTDOWN:
299 return dns_stats->stats_n_error_shutdown;
301 return dns_stats->stats_n_error_cancel;
303 return dns_stats->stats_n_error_nodata;
316 if (BUG(!dns_stats)) {
319 return dns_stats->stats_n_request;
335 dns_stats->stats_n_error_none++;
338 dns_stats->stats_n_error_format++;
340 case DNS_ERR_SERVERFAILED:
341 dns_stats->stats_n_error_serverfailed++;
343 case DNS_ERR_NOTEXIST:
344 dns_stats->stats_n_error_notexist++;
346 case DNS_ERR_NOTIMPL:
347 dns_stats->stats_n_error_notimpl++;
349 case DNS_ERR_REFUSED:
350 dns_stats->stats_n_error_refused++;
352 case DNS_ERR_TRUNCATED:
353 dns_stats->stats_n_error_truncated++;
355 case DNS_ERR_UNKNOWN:
356 dns_stats->stats_n_error_unknown++;
358 case DNS_ERR_TIMEOUT:
359 dns_stats->stats_n_error_timeout++;
361 case DNS_ERR_SHUTDOWN:
362 dns_stats->stats_n_error_shutdown++;
365 dns_stats->stats_n_error_cancel++;
368 dns_stats->stats_n_error_nodata++;
381 if (BUG(!dns_stats)) {
384 dns_stats->stats_n_request++;
394 if (overload_time >
approx_time() - 3600 * n_hours) {
401 #define OVERLOAD_STATS_VERSION 1
414 return stats_n_write_limit_reached;
423 char tbuf[ISO_TIME_LEN+1];
429 OVERLOAD_STATS_VERSION, tbuf);
442 char tbuf[ISO_TIME_LEN+1];
449 "overload-ratelimits %d %s %" PRIu64
" %" PRIu64
450 " %" PRIu64
" %" PRIu64
"\n",
451 OVERLOAD_STATS_VERSION, tbuf,
462 OVERLOAD_STATS_VERSION, tbuf);
466 if (smartlist_len(chunks) == 0) {
474 smartlist_free(chunks);
479 #define SET_TO_START_OF_HOUR(a) STMT_BEGIN \
480 (a) = approx_time() - (approx_time() % 3600); \
487 static time_t last_read_counted = 0;
488 static time_t last_write_counted = 0;
491 case OVERLOAD_GENERAL:
494 case OVERLOAD_READ: {
503 case OVERLOAD_WRITE: {
504 stats_n_write_limit_reached++;
512 case OVERLOAD_FD_EXHAUSTED:
578 const uint16_t at_port, time_t when)
582 char tbuf[ISO_TIME_LEN+1];
583 int addr_changed, port_changed;
586 tor_assert((!at_addr && !at_port) || (at_addr && at_port));
593 if (!started_tracking_stability)
594 started_tracking_stability = time(NULL);
599 if (hist->start_of_downtime) {
603 log_info(
LD_HIST,
"Router %s is now Running; it had been down since %s.",
606 log_info(
LD_HIST,
" (Paradoxically, it was already Running too.)");
608 down_length = when - hist->start_of_downtime;
609 hist->total_weighted_time += down_length;
610 hist->start_of_downtime = 0;
611 }
else if (addr_changed || port_changed) {
623 penalty = (int)(fresh_interval + live_interval) / 2;
626 log_info(
LD_HIST,
"Router %s still seems Running, but its address appears "
627 "to have changed since the last time it was reachable. I'm "
628 "going to treat it as having been down for %d seconds",
635 log_debug(
LD_HIST,
"Router %s is still Running; it has been Running "
638 log_info(
LD_HIST,
"Router %s is now Running; it was previously untracked",
653 char tbuf[ISO_TIME_LEN+1];
655 if (!started_tracking_stability)
656 started_tracking_stability = time(NULL);
667 if (run_length < 0) {
668 unsigned long penalty = -run_length;
669 #define SUBTRACT_CLAMPED(var, penalty) \
670 do { (var) = (var) < (penalty) ? 0 : (var) - (penalty); } while (0)
673 SUBTRACT_CLAMPED(hist->weighted_uptime, penalty);
676 hist->weighted_uptime += run_length;
677 hist->total_weighted_time += run_length;
680 log_info(
LD_HIST,
"Router %s is now non-Running: it had previously been "
681 "Running since %s. Its total weighted uptime is %lu/%lu.",
683 hist->total_weighted_time);
685 if (!hist->start_of_downtime) {
686 hist->start_of_downtime = when;
689 log_info(
LD_HIST,
"Router %s is now non-Running; it was previously "
695 log_info(
LD_HIST,
"Router %s is still non-Running; it has been "
712 hist->weighted_uptime = 0;
720 digestmap_iter_t *orhist_it;
739 log_info(
LD_HIST,
"Discounting all old stability info by a factor of %f",
744 !digestmap_iter_done(orhist_it);
745 orhist_it = digestmap_iter_next(
history_map,orhist_it)) {
746 digestmap_iter_get(orhist_it, &digest1, &hist_p);
753 hist->weighted_uptime = (
unsigned long)(hist->weighted_uptime * alpha);
754 hist->total_weighted_time = (
unsigned long)
755 (hist->total_weighted_time * alpha);
772 total_weights += 1.0;
779 return total / total_weights;
787 long total = hist->total_weighted_time;
790 }
else if (hist->start_of_downtime) {
791 total += (when - hist->start_of_downtime);
801 long total = hist->total_weighted_time;
802 long up = hist->weighted_uptime;
808 }
else if (hist->start_of_downtime) {
809 total += (when - hist->start_of_downtime);
819 return ((
double) up) / total;
883 return started_tracking_stability < time(NULL) - 4*60*60;
892 digestmap_iter_t *orhist_it;
893 const char *name1, *digest1;
901 tor_log(severity,
LD_HIST,
"--------------- Dumping history information:");
904 !digestmap_iter_done(orhist_it);
905 orhist_it = digestmap_iter_next(
history_map,orhist_it)) {
908 digestmap_iter_get(orhist_it, &digest1, &or_history_p);
919 "OR %s [%s]: wmtbf %lu:%02lu:%02lu",
921 stability/3600, (stability/60)%60, stability%60);
934 digestmap_iter_t *orhist_it;
938 while (!digestmap_iter_done(orhist_it)) {
940 digestmap_iter_get(orhist_it, &d1, &or_history_p);
941 or_history = or_history_p;
943 should_remove = authority ?
946 : (or_history->
changed < before);
948 orhist_it = digestmap_iter_next_rmv(
history_map, orhist_it);
952 orhist_it = digestmap_iter_next(
history_map, orhist_it);
964 char time_buf[ISO_TIME_LEN+1];
966 digestmap_iter_t *orhist_it;
974 char *filename = get_datadir_fname(
"router-stability");
991 #define PUT(s) STMT_BEGIN if (fputs((s),f)<0) goto err; STMT_END
992 #define PRINTF(args) STMT_BEGIN if (fprintf args <0) goto err; STMT_END
997 PRINTF((f,
"stored-at %s\n", time_buf));
999 if (started_tracking_stability) {
1001 PRINTF((f,
"tracked-since %s\n", time_buf));
1005 PRINTF((f,
"last-downrated %s\n", time_buf));
1013 for (orhist_it = digestmap_iter_init(
history_map);
1014 !digestmap_iter_done(orhist_it);
1015 orhist_it = digestmap_iter_next(
history_map,orhist_it)) {
1017 const char *t = NULL;
1018 digestmap_iter_get(orhist_it, &digest, &or_history_p);
1029 "Relay '%s' is listed as up in rephist, but it's not in "
1030 "our routerlist. Correcting.", dbuf);
1034 PRINTF((f,
"R %s\n", dbuf));
1039 PRINTF((f,
"+MTBF %lu %.5f%s%s\n",
1041 t ?
" S=" :
"", t ? t :
""));
1043 if (hist->start_of_downtime > 0) {
1047 PRINTF((f,
"+WFU %lu %lu%s%s\n",
1048 hist->weighted_uptime, hist->total_weighted_time,
1049 t ?
" S=" :
"", t ? t :
""));
1069 for ( ; i < smartlist_len(sl); ++i) {
1070 const char *line = smartlist_get(sl, i);
1088 strlcpy(b, s,
sizeof(b));
1104 static inline time_t
1105 correct_time(time_t t, time_t now, time_t stored_at, time_t started_measuring)
1107 if (t < started_measuring - 24*60*60*365)
1109 else if (t < started_measuring)
1110 return started_measuring;
1111 else if (t > stored_at)
1114 long run_length = stored_at - t;
1115 t = (time_t)(now - run_length);
1116 if (t < started_measuring)
1117 t = started_measuring;
1129 const char *line = NULL;
1131 time_t last_downrated = 0, stored_at = 0, tracked_since = 0;
1132 time_t latest_possible_start = now;
1136 char *filename = get_datadir_fname(
"router-stability");
1147 const char *firstline;
1148 if (smartlist_len(lines)>4) {
1149 firstline = smartlist_get(lines, 0);
1152 10, -1, LONG_MAX, NULL, NULL);
1155 if (format != 1 && format != 2) {
1157 "Unrecognized format in mtbf history file. Skipping.");
1160 for (i = 1; i < smartlist_len(lines); ++i) {
1161 line = smartlist_get(lines, i);
1162 if (!strcmp(line,
"data"))
1165 if (
parse_iso_time(line+strlen(
"last-downrated "), &last_downrated)<0)
1166 log_warn(
LD_HIST,
"Couldn't parse downrate time in mtbf "
1171 log_warn(
LD_HIST,
"Couldn't parse stored time in mtbf "
1175 if (
parse_iso_time(line+strlen(
"tracked-since "), &tracked_since)<0)
1176 log_warn(
LD_HIST,
"Couldn't parse started-tracking time in mtbf "
1180 if (last_downrated > now)
1181 last_downrated = now;
1182 if (tracked_since > now)
1183 tracked_since = now;
1186 log_warn(
LD_HIST,
"No stored time recorded.");
1190 if (line && !strcmp(line,
"data"))
1195 for (; i < smartlist_len(lines); ++i) {
1198 char mtbf_timebuf[ISO_TIME_LEN+1];
1199 char wfu_timebuf[ISO_TIME_LEN+1];
1200 time_t start_of_run = 0;
1201 time_t start_of_downtime = 0;
1202 int have_mtbf = 0, have_wfu = 0;
1205 long wt_uptime = 0, total_wt_time = 0;
1208 line = smartlist_get(lines, i);
1209 if (!strcmp(line,
"."))
1212 mtbf_timebuf[0] =
'\0';
1213 wfu_timebuf[0] =
'\0';
1216 n =
tor_sscanf(line,
"%40s %ld %lf S=%10s %8s",
1217 hexbuf, &wrl, &trw, mtbf_timebuf, mtbf_timebuf+11);
1218 if (n != 3 && n != 5) {
1225 int mtbf_idx, wfu_idx;
1228 strlcpy(hexbuf, line+2,
sizeof(hexbuf));
1231 if (mtbf_idx >= 0) {
1232 const char *mtbfline = smartlist_get(lines, mtbf_idx);
1233 n =
tor_sscanf(mtbfline,
"+MTBF %lu %lf S=%10s %8s",
1234 &wrl, &trw, mtbf_timebuf, mtbf_timebuf+11);
1235 if (n == 2 || n == 4) {
1238 log_warn(
LD_HIST,
"Couldn't scan +MTBF line %s",
1243 const char *wfuline = smartlist_get(lines, wfu_idx);
1244 n =
tor_sscanf(wfuline,
"+WFU %lu %lu S=%10s %8s",
1245 &wt_uptime, &total_wt_time,
1246 wfu_timebuf, wfu_timebuf+11);
1247 if (n == 2 || n == 4) {
1250 log_warn(
LD_HIST,
"Couldn't scan +WFU line %s",
escaped(wfuline));
1268 if (mtbf_timebuf[0]) {
1269 mtbf_timebuf[10] =
' ';
1271 log_warn(
LD_HIST,
"Couldn't parse time %s",
1277 latest_possible_start = (time_t)(hist->
start_of_run - wrl);
1283 if (wfu_timebuf[0]) {
1284 wfu_timebuf[10] =
' ';
1286 log_warn(
LD_HIST,
"Couldn't parse time %s",
escaped(wfu_timebuf));
1289 hist->start_of_downtime =
correct_time(start_of_downtime, now, stored_at,
1291 hist->weighted_uptime = wt_uptime;
1292 hist->total_weighted_time = total_wt_time;
1294 if (strcmp(line,
"."))
1295 log_warn(
LD_HIST,
"Truncated MTBF file.");
1297 if (tracked_since < 86400*365)
1298 tracked_since = latest_possible_start;
1301 started_tracking_stability = tracked_since;
1308 smartlist_free(lines);
1316 #define EXIT_STATS_ROUND_UP_BYTES 1024
1318 #define EXIT_STATS_ROUND_UP_STREAMS 4
1320 #define EXIT_STATS_NUM_PORTS 65536
1322 #define EXIT_STATS_TOP_N_PORTS 10
1375 return (*(
int*)x - *(
int*)y);
1384 int i, j, top_elements = 0, cur_min_idx = 0, cur_port;
1387 uint64_t cur_bytes = 0, other_read = 0, other_written = 0,
1388 total_read = 0, total_written = 0;
1389 uint32_t total_streams = 0, other_streams = 0;
1390 smartlist_t *written_strings, *read_strings, *streams_strings;
1391 char *written_string, *read_string, *streams_string;
1392 char t[ISO_TIME_LEN+1];
1431 if (cur_bytes == 0) {
1435 top_bytes[top_elements] = cur_bytes;
1436 top_ports[top_elements++] = i;
1437 }
else if (cur_bytes > top_bytes[cur_min_idx]) {
1438 top_bytes[cur_min_idx] = cur_bytes;
1439 top_ports[cur_min_idx] = i;
1444 for (j = 1; j < top_elements; j++) {
1445 if (top_bytes[j] < top_bytes[cur_min_idx]) {
1455 other_read = total_read;
1456 other_written = total_written;
1457 other_streams = total_streams;
1460 qsort(top_ports, top_elements,
sizeof(
int),
compare_int_);
1461 for (j = 0; j < top_elements; j++) {
1462 cur_port = top_ports[j];
1493 other_written /= 1024;
1512 smartlist_free(written_strings);
1513 smartlist_free(read_strings);
1514 smartlist_free(streams_strings);
1519 "exit-kibibytes-written %s\n"
1520 "exit-kibibytes-read %s\n"
1521 "exit-streams-opened %s\n",
1546 log_info(
LD_HIST,
"Writing exit port statistics to disk.");
1574 log_debug(
LD_HIST,
"Written %lu bytes and read %lu bytes to/from an "
1575 "exit connection to port %d.",
1576 (
unsigned long)num_written, (
unsigned long)num_read, port);
1586 log_debug(
LD_HIST,
"Opened exit stream to port %d", port);
1621 double mean_time_cells_in_queue, uint32_t processed_cells)
1641 time_t start_of_interval;
1642 int interval_length;
1644 double mean_num_cells_in_queue, mean_time_cells_in_queue;
1645 uint32_t processed_cells;
1655 interval_length = (int) (end_of_interval - start_of_interval);
1656 if (interval_length <= 0)
1661 (
double) interval_length / 1000.0 / 2.0;
1662 mean_time_cells_in_queue =
1668 mean_time_cells_in_queue,
1714 uint64_t processed_cells[SHARES];
1715 uint32_t circs_in_share[SHARES];
1716 int number_of_circuits, i;
1717 double queued_cells[SHARES], time_in_queue[SHARES];
1718 smartlist_t *processed_cells_strings, *queued_cells_strings,
1719 *time_in_queue_strings;
1720 char *processed_cells_string, *queued_cells_string,
1721 *time_in_queue_string;
1722 char t[ISO_TIME_LEN+1];
1731 memset(processed_cells, 0, SHARES *
sizeof(uint64_t));
1732 memset(circs_in_share, 0, SHARES *
sizeof(uint32_t));
1733 memset(queued_cells, 0, SHARES *
sizeof(
double));
1734 memset(time_in_queue, 0, SHARES *
sizeof(
double));
1738 if (number_of_circuits > 0) {
1745 int share = i++ * SHARES / number_of_circuits;
1746 processed_cells[share] += stats->processed_cells;
1747 queued_cells[share] += stats->mean_num_cells_in_queue;
1748 time_in_queue[share] += stats->mean_time_cells_in_queue;
1749 circs_in_share[share]++;
1751 SMARTLIST_FOREACH_END(stats);
1758 for (i = 0; i < SHARES; i++) {
1760 "%"PRIu64, !circs_in_share[i] ? 0 :
1761 (processed_cells[i] /
1762 circs_in_share[i]));
1764 for (i = 0; i < SHARES; i++) {
1766 circs_in_share[i] == 0 ? 0.0 :
1767 queued_cells[i] / (
double) circs_in_share[i]);
1769 for (i = 0; i < SHARES; i++) {
1771 circs_in_share[i] == 0 ? 0.0 :
1772 time_in_queue[i] / (
double) circs_in_share[i]);
1785 smartlist_free(processed_cells_strings);
1786 smartlist_free(queued_cells_strings);
1787 smartlist_free(time_in_queue_strings);
1792 "cell-processed-cells %s\n"
1793 "cell-queued-cells %s\n"
1794 "cell-time-in-queue %s\n"
1795 "cell-circuits-per-decile %d\n",
1797 processed_cells_string,
1798 queued_cells_string,
1799 time_in_queue_string,
1800 CEIL_DIV(number_of_circuits, SHARES));
1827 SMARTLIST_FOREACH_END(circ);
1864 log_warn(
LD_BUG,
"Called rep_hist_desc_stats_init() when desc stats were "
1865 "already initialized. This is probably harmless.");
1899 char t[ISO_TIME_LEN+1];
1902 digestmap_iter_t *iter;
1906 int *vals, max = 0, q3 = 0, md = 0, q1 = 0, min = 0;
1914 vals = tor_calloc(size,
sizeof(
int));
1916 !digestmap_iter_done(iter);
1919 digestmap_iter_get(iter, &key, &val);
1920 count = (uintptr_t)val;
1921 vals[n++] = (int)count;
1924 max = find_nth_int(vals, size, size-1);
1925 q3 = find_nth_int(vals, size, (3*size-1)/4);
1926 md = find_nth_int(vals, size, (size-1)/2);
1927 q1 = find_nth_int(vals, size, (size-1)/4);
1928 min = find_nth_int(vals, size, 0);
1935 "served-descs-stats-end %s (%d s) total=%lu unique=%u "
1936 "max=%d q3=%d md=%d q1=%d min=%d\n",
1940 size, max, q3, md, q1, min);
1953 char *filename = NULL, *str = NULL;
1966 filename = get_datadir_fname2(
"stats",
"served-desc-stats");
1968 log_warn(
LD_HIST,
"Unable to write served descs statistics to disk!");
1989 count = (uintptr_t)val;
1990 if (count != INT_MAX)
2003 STATIC int onion_handshakes_assigned[MAX_ONION_HANDSHAKE_TYPE+1] = {0};
2004 STATIC uint64_t onion_handshakes_dropped[MAX_ONION_HANDSHAKE_TYPE+1] = {0};
2011 if (type <= MAX_ONION_HANDSHAKE_TYPE)
2020 if (type <= MAX_ONION_HANDSHAKE_TYPE)
2021 onion_handshakes_assigned[type]++;
2029 if (type <= MAX_ONION_HANDSHAKE_TYPE)
2030 onion_handshakes_dropped[type]++;
2037 if (BUG(type > MAX_ONION_HANDSHAKE_TYPE)) {
2047 if (BUG(type > MAX_ONION_HANDSHAKE_TYPE)) {
2050 return onion_handshakes_assigned[type];
2057 if (BUG(type > MAX_ONION_HANDSHAKE_TYPE)) {
2060 return onion_handshakes_dropped[type];
2068 log_notice(
LD_HEARTBEAT,
"Circuit handshake stats since last time: "
2069 "%d/%d TAP, %d/%d NTor.",
2070 onion_handshakes_assigned[ONION_HANDSHAKE_TYPE_TAP],
2072 onion_handshakes_assigned[ONION_HANDSHAKE_TYPE_NTOR],
2074 memset(onion_handshakes_assigned, 0,
sizeof(onion_handshakes_assigned));
2090 static hs_v2_stats_t *
2093 hs_v2_stats_t *new_hs_v2_stats = tor_malloc_zero(
sizeof(hs_v2_stats_t));
2095 return new_hs_v2_stats;
2098 #define hs_v2_stats_free(val) \
2099 FREE_AND_NULL(hs_v2_stats_t, hs_v2_stats_free_, (val))
2105 if (!victim_hs_v2_stats) {
2162 static hs_v3_stats_t *
2165 hs_v3_stats_t *new_hs_v3_stats = tor_malloc_zero(
sizeof(hs_v3_stats_t));
2166 new_hs_v3_stats->v3_onions_seen_this_period = digest256map_new();
2168 return new_hs_v3_stats;
2171 #define hs_v3_stats_free(val) \
2172 FREE_AND_NULL(hs_v3_stats_t, hs_v3_stats_free_, (val))
2178 if (!victim_hs_v3_stats) {
2182 digest256map_free(victim_hs_v3_stats->v3_onions_seen_this_period, NULL);
2195 digest256map_free(
hs_v3_stats->v3_onions_seen_this_period, NULL);
2196 hs_v3_stats->v3_onions_seen_this_period = digest256map_new();
2230 !!digest256map_get(
hs_v3_stats->v3_onions_seen_this_period,
2233 log_info(
LD_GENERAL,
"Considering v3 descriptor with %s (%sseen before)",
2234 safe_str(
hex_str((
char*)blinded_key, 32)),
2235 seen_before ?
"" :
"not ");
2239 digest256map_set(
hs_v3_stats->v3_onions_seen_this_period,
2240 blinded_key, (
void*)(uintptr_t)1);
2249 log_debug(
LD_GENERAL,
"New RP cell (%d)", is_v2);
2293 #define REND_CELLS_DELTA_F 2048
2297 #define REND_CELLS_EPSILON 0.3
2300 #define REND_CELLS_BIN_SIZE 1024
2304 #define ONIONS_SEEN_DELTA_F 8
2308 #define ONIONS_SEEN_EPSILON 0.3
2311 #define ONIONS_SEEN_BIN_SIZE 8
2320 char t[ISO_TIME_LEN+1];
2321 char *hs_stats_string;
2322 int64_t obfuscated_onions_seen, obfuscated_cells_seen;
2324 uint64_t rp_cells_seen = is_v3 ?
2326 size_t onions_seen = is_v3 ?
2327 digest256map_size(
hs_v3_stats->v3_onions_seen_this_period) : 0;
2328 time_t start_of_hs_stats_interval = is_v3 ?
2331 uint64_t rounded_cells_seen
2333 rounded_cells_seen = MIN(rounded_cells_seen, INT64_MAX);
2338 uint64_t rounded_onions_seen =
2340 rounded_onions_seen = MIN(rounded_onions_seen, INT64_MAX);
2343 ONIONS_SEEN_EPSILON);
2347 "%s %"PRId64
" delta_f=%d epsilon=%.2f bin_size=%d\n"
2348 "%s %"PRId64
" delta_f=%d epsilon=%.2f bin_size=%d\n",
2349 is_v3 ?
"hidserv-v3-stats-end" :
"hidserv-stats-end",
2350 t, (
unsigned) (now - start_of_hs_stats_interval),
2352 "hidserv-rend-v3-relayed-cells" :
"hidserv-rend-relayed-cells",
2354 REND_CELLS_EPSILON, REND_CELLS_BIN_SIZE,
2355 is_v3 ?
"hidserv-dir-v3-onions-seen" :
"hidserv-dir-onions-seen",
2356 obfuscated_onions_seen, ONIONS_SEEN_DELTA_F,
2357 ONIONS_SEEN_EPSILON, ONIONS_SEEN_BIN_SIZE);
2359 return hs_stats_string;
2373 time_t start_of_hs_stats_interval = is_v3 ?
2376 if (!start_of_hs_stats_interval) {
2380 if (start_of_hs_stats_interval + WRITE_STATS_INTERVAL > now) {
2397 is_v3 ?
"hidserv-v3-stats" :
"hidserv-stats",
2398 str,
"hidden service stats");
2403 return start_of_hs_stats_interval + WRITE_STATS_INTERVAL;
2406 static uint64_t link_proto_count[MAX_LINK_PROTO+1][2];
2414 started_here = !!started_here;
2415 if (link_proto > MAX_LINK_PROTO) {
2416 log_warn(
LD_BUG,
"Can't log link protocol %u", link_proto);
2420 link_proto_count[link_proto][started_here]++;
2506 #define MIN_CELL_COUNTS_TO_PUBLISH 1
2507 #define ROUND_CELL_COUNTS_TO 10000
2509 rep_hist_prep_published_padding_counts(time_t now)
2520 #define ROUND_AND_SET_COUNT(x) (x) = round_uint64_to_next_multiple_of((x), \
2521 ROUND_CELL_COUNTS_TO)
2532 #undef ROUND_AND_SET_COUNT
2542 char *result = NULL;
2551 " write-drop=%"PRIu64
2552 " write-pad=%"PRIu64
2553 " write-total=%"PRIu64
2554 " read-drop=%"PRIu64
2556 " read-total=%"PRIu64
2557 " enabled-read-pad=%"PRIu64
2558 " enabled-read-total=%"PRIu64
2559 " enabled-write-pad=%"PRIu64
2560 " enabled-write-total=%"PRIu64
2561 " max-chanpad-timers=%"PRIu64
2565 (uint64_t)ROUND_CELL_COUNTS_TO,
2590 for (
int i = 1; i <= MAX_LINK_PROTO; i++) {
2592 tor_asprintf(&line,
"initiated %"PRIu64
" and received "
2593 "%"PRIu64
" v%d connections", link_proto_count[i][1],
2594 link_proto_count[i][0], i);
2600 log_notice(
LD_HEARTBEAT,
"Since startup we %s.", log_line);
2603 smartlist_free(lines);
2635 #ifdef TOR_UNIT_TESTS
2637 const hs_v2_stats_t *
2638 rep_hist_get_hs_v2_stats(
void)
2644 const hs_v3_stats_t *
2645 rep_hist_get_hs_v3_stats(
void)
void tor_addr_copy(tor_addr_t *dest, const tor_addr_t *src)
void tor_addr_make_unspec(tor_addr_t *a)
int tor_addr_compare(const tor_addr_t *addr1, const tor_addr_t *addr2, tor_addr_comparison_t how)
int tor_addr_is_null(const tor_addr_t *addr)
int authdir_mode(const or_options_t *options)
Header file for directory authority mode.
const char * hex_str(const char *from, size_t fromlen)
int base16_decode(char *dest, size_t destlen, const char *src, size_t srclen)
void base16_encode(char *dest, size_t destlen, const char *src, size_t srclen)
smartlist_t * circuit_get_global_list(void)
or_circuit_t * TO_OR_CIRCUIT(circuit_t *x)
Header file for circuitlist.c.
#define CIRCUIT_IS_ORIGIN(c)
const or_options_t * get_options(void)
int check_or_create_data_subdir(const char *subdir)
int write_to_data_subdir(const char *subdir, const char *fname, const char *str, const char *descr)
Header file for config.c.
int connection_or_digest_is_known_relay(const char *id_digest)
Header file for connection_or.c.
void conn_stats_free_all(void)
Header for feature/stats/connstats.c.
Common functions for using (pseudo-)random number generators.
double crypto_rand_double(void)
const char * escaped(const char *s)
#define RFTS_IGNORE_MISSING
int finish_writing_to_file(open_file_t *file_data)
int append_bytes_to_file(const char *fname, const char *str, size_t len, int bin)
FILE * start_writing_to_stdio_file(const char *fname, int open_flags, int mode, open_file_t **data_out)
int abort_writing_to_file(open_file_t *file_data)
time_t hs_get_start_time_of_next_time_period(time_t now)
int64_t add_laplace_noise(int64_t signal_, double random_, double delta_f, double epsilon)
void tor_log(int severity, log_domain_mask_t domain, const char *format,...)
uint32_t round_uint32_to_next_multiple_of(uint32_t number, uint32_t divisor)
uint64_t round_uint64_to_next_multiple_of(uint64_t number, uint64_t divisor)
networkstatus_t * networkstatus_get_latest_consensus(void)
Header file for networkstatus.c.
Networkstatus consensus/vote structure.
const char * node_get_nickname(const node_t *node)
const node_t * node_get_by_id(const char *identity_digest)
Header file for nodelist.c.
Master header file for Tor-specific functionality.
long tor_parse_long(const char *s, int base, long min, long max, int *ok, char **next)
void predicted_ports_free_all(void)
Header file for predict_ports.c.
int tor_asprintf(char **strp, const char *fmt,...)
void rep_hist_note_dns_error(int type, uint8_t error)
static int parse_possibly_bad_iso_time(const char *s, time_t *time_out)
void rep_hist_note_desc_served(const char *desc)
void rep_hist_buffer_stats_term(void)
time_t rep_hist_downrate_old_runs(time_t now)
void rep_hist_note_exit_bytes(uint16_t port, size_t num_written, size_t num_read)
static time_t start_of_hs_v2_stats_interval
void rep_hist_note_negotiated_link_proto(unsigned link_proto, int started_here)
void rep_hist_note_router_reachable(const char *id, const tor_addr_t *at_addr, const uint16_t at_port, time_t when)
uint64_t rephist_total_alloc
void rep_hist_seen_new_rp_cell(bool is_v2)
static padding_counts_t padding_current
STATIC int onion_handshakes_requested[MAX_ONION_HANDSHAKE_TYPE+1]
void rep_hist_desc_stats_term(void)
static hs_v3_stats_t * hs_v3_stats
static time_t stability_last_downrated
static long get_total_weighted_time(or_history_t *hist, time_t when)
static digestmap_t * served_descs
uint64_t rep_hist_get_n_dns_request(int type)
void rep_hist_hs_stats_term(void)
uint64_t rep_hist_get_circuit_handshake_dropped(uint16_t type)
static time_t start_of_served_descs_stats_interval
static dns_stats_t * get_dns_stats_by_type(const int type)
void rep_hist_reset_padding_counts(void)
double rep_hist_get_stability(const char *id, time_t when)
static bool overload_happened_recently(time_t overload_time, int n_hours)
static void hs_v2_stats_free_(hs_v2_stats_t *victim_hs_v2_stats)
static uint32_t * exit_streams
#define EXIT_STATS_TOP_N_PORTS
int rep_hist_load_mtbf_data(time_t now)
void rep_hist_note_circuit_handshake_dropped(uint16_t type)
static or_history_t * get_or_history(const char *id)
void rep_hist_free_all(void)
static uint64_t * exit_bytes_written
static overload_stats_t overload_stats
#define EXIT_STATS_ROUND_UP_BYTES
int rep_hist_get_circuit_handshake_assigned(uint16_t type)
time_t rep_hist_desc_stats_write(time_t now)
char * rep_hist_get_overload_stats_lines(void)
void rep_hist_buffer_stats_init(time_t now)
void rep_hist_exit_stats_init(time_t now)
static void hs_v3_stats_free_(hs_v3_stats_t *victim_hs_v3_stats)
void rep_hist_note_exit_stream_opened(uint16_t port)
static char * rep_hist_format_desc_stats(time_t now)
double rep_hist_get_weighted_fractional_uptime(const char *id, time_t when)
static hs_v2_stats_t * hs_v2_stats_new(void)
static uint64_t stats_n_read_limit_reached
void rep_hist_buffer_stats_add_circ(circuit_t *circ, time_t end_of_interval)
static int find_next_with(smartlist_t *sl, int i, const char *prefix)
void rep_hist_note_dns_request(int type)
void rep_hist_padding_count_write(padding_type_t type)
char * rep_hist_get_overload_general_line(void)
long rep_hist_get_uptime(const char *id, time_t when)
static int buffer_stats_compare_entries_(const void **_a, const void **_b)
static digestmap_t * history_map
long rep_hist_get_weighted_time_known(const char *id, time_t when)
static padding_counts_t padding_published
static uint64_t * exit_bytes_read
void rep_hist_dump_stats(time_t now, int severity)
static time_t start_of_exit_stats_interval
static uint64_t stats_n_tcp_exhaustion
void rep_hist_reset_buffer_stats(time_t now)
static time_t start_of_buffer_stats_interval
void rep_hist_note_router_unreachable(const char *id, time_t when)
void rep_hist_hs_stats_init(time_t now)
void rep_hist_hsdir_stored_maybe_new_v3_onion(const uint8_t *blinded_key)
static time_t start_of_hs_v3_stats_interval
char * rep_hist_format_exit_stats(time_t now)
void rep_hist_log_link_protocol_counts(void)
STATIC char * rep_hist_format_hs_stats(time_t now, bool is_v3)
uint32_t rephist_total_num
char * rep_hist_get_padding_count_lines(void)
#define SET_TO_START_OF_HOUR(a)
static hs_v3_stats_t * hs_v3_stats_new(void)
void rep_hist_add_buffer_stats(double mean_num_cells_in_queue, double mean_time_cells_in_queue, uint32_t processed_cells)
static double get_weighted_fractional_uptime(or_history_t *hist, time_t when)
void rep_hist_note_circuit_handshake_requested(uint16_t type)
int rep_hist_get_circuit_handshake_requested(uint16_t type)
void rep_history_clean(time_t before)
static hs_v2_stats_t * hs_v2_stats
void rep_hist_desc_stats_init(time_t now)
uint64_t rep_hist_get_n_dns_error(int type, uint8_t error)
static void free_or_history(void *_hist)
#define EXIT_STATS_ROUND_UP_STREAMS
uint64_t rep_hist_get_n_read_limit_reached(void)
static void rep_hist_reset_hs_v2_stats(time_t now)
#define REND_CELLS_DELTA_F
static unsigned long total_descriptor_downloads
uint64_t rep_hist_get_n_tcp_exhaustion(void)
#define STABILITY_EPSILON
static smartlist_t * circuits_for_buffer_stats
static int compare_int_(const void *x, const void *y)
static time_t correct_time(time_t t, time_t now, time_t stored_at, time_t started_measuring)
int rep_hist_record_mtbf_data(time_t now, int missing_means_down)
char * rep_hist_format_buffer_stats(time_t now)
#define EXIT_STATS_NUM_PORTS
void rep_hist_reset_exit_stats(time_t now)
void rep_hist_padding_count_timers(uint64_t num_timers)
time_t rep_hist_hs_stats_write(time_t now, bool is_v3)
time_t rep_hist_buffer_stats_write(time_t now)
void rep_hist_make_router_pessimal(const char *id, time_t when)
void rep_hist_exit_stats_term(void)
void rep_hist_note_overload(overload_type_t overload)
#define STABILITY_INTERVAL
STATIC bool should_collect_v3_stats(void)
void rep_hist_log_circuit_handshake_stats(time_t now)
void rep_hist_note_circuit_handshake_assigned(uint16_t type)
#define MIN_CELL_COUNTS_TO_PUBLISH
static void rep_hist_reset_hs_v3_stats(time_t now)
void rep_hist_note_tcp_exhaustion(void)
void rep_hist_padding_count_read(padding_type_t type)
int rep_hist_have_measured_enough_stability(void)
static void rep_hist_reset_desc_stats(time_t now)
uint64_t rep_hist_get_n_write_limit_reached(void)
static dns_stats_t dns_A_stats
time_t rep_hist_exit_stats_write(time_t now)
static double get_stability(or_history_t *hist, time_t when)
Header file for rephist.c.
@ PADDING_TYPE_ENABLED_CELL
@ PADDING_TYPE_ENABLED_TOTAL
#define REPHIST_CELL_PADDING_COUNTS_INTERVAL
int tor_sscanf(const char *buf, const char *pattern,...)
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_sort(smartlist_t *sl, int(*compare)(const void **a, const void **b))
smartlist_t * smartlist_new(void)
void smartlist_add(smartlist_t *sl, void *element)
void smartlist_clear(smartlist_t *sl)
#define SMARTLIST_FOREACH_BEGIN(sl, type, var)
#define SMARTLIST_FOREACH(sl, type, var, cmd)
int smartlist_split_string(smartlist_t *sl, const char *str, const char *sep, int flags, int max)
double mean_num_cells_in_queue
double mean_time_cells_in_queue
struct timeval timestamp_created
uint64_t total_cell_waiting_time
unsigned long weighted_run_length
uint16_t last_reached_port
tor_addr_t last_reached_addr
uint64_t maximum_chanpad_timers
uint64_t read_pad_cell_count
uint64_t enabled_read_pad_cell_count
uint64_t write_pad_cell_count
char first_published_at[ISO_TIME_LEN+1]
uint64_t enabled_write_cell_count
uint64_t write_drop_cell_count
uint64_t write_cell_count
uint64_t enabled_read_cell_count
uint64_t enabled_write_pad_cell_count
uint64_t read_drop_cell_count
#define MOCK_IMPL(rv, funcname, arglist)
int parse_iso_time(const char *cp, time_t *t)
void format_iso_time(char *buf, time_t t)
void format_local_iso_time(char *buf, time_t t)
int strcmpstart(const char *s1, const char *s2)
int tor_digest_is_zero(const char *digest)