34#include "core/or/dos.h"
41static void log_accounting(
const time_t now,
const or_options_t *options);
55 long int days = secs / 86400;
56 int hours = (int)((secs - (days * 86400)) / 3600);
57 int minutes = (int)((secs - (days * 86400) - (hours * 3600)) / 60);
58 char *uptime_string = NULL;
62 tor_asprintf(&uptime_string,
"%d:%02d hours", hours, minutes);
66 days, hours, minutes);
70 days, hours, minutes);
82 char *bw_string = NULL;
84 if (bytes < (1<<20)) {
86 }
else if (bytes < (1<<30)) {
87 double bw = ((double)bytes);
90 double bw = ((double)bytes);
104 if (num_services == 0) {
109 "Heartbeat: Our onion service%s received %u v3 INTRODUCE2 cells "
110 "and attempted to launch %d rendezvous circuits.",
111 num_services == 1 ?
"" :
"s",
123static unsigned n_incoming_ipv4;
124static unsigned n_incoming_ipv6;
125static unsigned n_outgoing_ipv4;
126static unsigned n_outgoing_ipv6;
160static unsigned n_circs_closed_for_unrecognized_cells;
161static uint64_t n_unrecognized_cells_discarded;
162static uint64_t n_secs_on_circs_with_unrecognized_cells;
173 ++n_circs_closed_for_unrecognized_cells;
174 n_unrecognized_cells_discarded += n_cells;
176 n_secs_on_circs_with_unrecognized_cells += (uint64_t) n_seconds;
185 char *bw_sent = NULL;
186 char *bw_rcvd = NULL;
201 "in the cached consensus.");
209 "circuits open. I've sent %s and received %s. I've received %u "
210 "connections on IPv4 and %u on IPv6. I've made %u connections "
211 "with IPv4 and %u with IPv6.%s",
213 n_incoming_ipv4, n_incoming_ipv6,
214 n_outgoing_ipv4, n_outgoing_ipv6,
215 hibernating?
" We are currently hibernating.":
"");
220 log_accounting(now, options);
223 double fullness_pct = 100;
229 const double overhead_pct = ( r - 1.0 ) * 100.0;
231#define FULLNESS_PCT_THRESHOLD 80
232#define TLS_OVERHEAD_THRESHOLD 15
234 const int severity = (fullness_pct < FULLNESS_PCT_THRESHOLD ||
235 overhead_pct > TLS_OVERHEAD_THRESHOLD)
239 "Average packaged cell fullness: %2.3f%%. "
240 "TLS write overhead: %.f%%", fullness_pct, overhead_pct);
264 "%"PRIu64
" successful returns, "
265 "%"PRIu64
" erroneous returns, and "
266 "%"PRIu64
" idle returns.",
267 (main_loop_success_count),
268 (main_loop_error_count),
269 (main_loop_idle_count));
272 if (n_circs_closed_for_unrecognized_cells) {
273 double avg_time_alive = ((double) n_secs_on_circs_with_unrecognized_cells)
274 / n_circs_closed_for_unrecognized_cells;
275 double avg_cells = ((double) n_unrecognized_cells_discarded)
276 / n_circs_closed_for_unrecognized_cells;
278 "Since our last heartbeat, %u circuits were closed because of "
279 "unrecognized cells while we were the last hop. On average, each "
280 "one was alive for %lf seconds, and had %lf unrecognized cells.",
281 n_circs_closed_for_unrecognized_cells,
284 n_circs_closed_for_unrecognized_cells = 0;
285 n_unrecognized_cells_discarded = 0;
286 n_secs_on_circs_with_unrecognized_cells = 0;
300log_accounting(
const time_t now,
const or_options_t *options)
303 char *acc_rcvd =
bytes_to_usage(state->AccountingBytesReadInInterval);
304 char *acc_sent =
bytes_to_usage(state->AccountingBytesWrittenInInterval);
309 char end_buf[ISO_TIME_LEN + 1];
310 char *remaining = NULL;
315 const char *acc_rule;
316 switch (options->AccountingRule) {
317 case ACCT_MAX: acc_rule =
"max";
319 case ACCT_SUM: acc_rule =
"sum";
321 case ACCT_OUT: acc_rule =
"out";
323 case ACCT_IN: acc_rule =
"in";
325 default: acc_rule =
"max";
329 log_notice(
LD_HEARTBEAT,
"Heartbeat: Accounting enabled. "
330 "Sent: %s, Received: %s, Used: %s / %s, Rule: %s. The "
331 "current accounting interval ends on %s, in %s.",
332 acc_sent, acc_rcvd, acc_used, acc_max, acc_rule, end_buf, remaining);
smartlist_t * circuit_get_global_list(void)
Header file for circuitlist.c.
void circuit_log_ancient_one_hop_circuits(int age)
Header file for circuituse.c.
const or_options_t * get_options(void)
Header file for config.c.
Base connection structure.
void dirclient_dump_total_dls(void)
Header file for dirclient.c.
Header file for geoip_stats.c.
char * format_client_stats_heartbeat(time_t now)
time_t accounting_get_end_time(void)
int accounting_is_enabled(const or_options_t *options)
int we_are_hibernating(void)
uint64_t get_accounting_bytes(void)
Header file for hibernate.c.
unsigned int hs_service_get_num_services(void)
Header file containing service data for the HS subsystem.
uint32_t hs_stats_get_n_introduce2_v3_cells(void)
uint32_t hs_stats_get_n_rendezvous_launches(void)
Header file for hs_stats.c.
#define log_fn(severity, domain, args,...)
uint64_t get_bytes_read(void)
uint64_t get_main_loop_error_count(void)
uint64_t get_main_loop_idle_count(void)
uint64_t get_main_loop_success_count(void)
uint64_t get_bytes_written(void)
Header file for mainloop.c.
const node_t * node_get_by_id(const char *identity_digest)
Header file for nodelist.c.
Master header file for Tor-specific functionality.
#define RELAY_PAYLOAD_SIZE
The or_state_t structure, which represents Tor's state file.
int tor_asprintf(char **strp, const char *fmt,...)
uint64_t stats_n_data_cells_packaged
uint64_t stats_n_data_bytes_packaged
void rep_hist_log_link_protocol_counts(void)
void rep_hist_note_conn_opened(bool from_listener, unsigned int type, int af)
void rep_hist_log_circuit_handshake_stats(time_t now)
Header file for rephist.c.
const routerinfo_t * router_get_my_routerinfo(void)
Header file for router.c.
Router descriptor structure.
int public_server_mode(const or_options_t *options)
int server_mode(const or_options_t *options)
Header file for routermode.c.
or_state_t * get_or_state(void)
STATIC int count_circuits(void)
void note_circ_closed_for_unrecognized_cells(time_t n_seconds, uint32_t n_cells)
STATIC char * bytes_to_usage(uint64_t bytes)
static void log_onion_service_stats(void)
STATIC char * secs_to_uptime(long secs)
void note_connection(bool inbound, const connection_t *conn)
int log_heartbeat(time_t now)
char identity_digest[DIGEST_LEN]
void format_local_iso_time(char *buf, time_t t)
double tls_get_write_overhead_ratio(void)