aboutsummaryrefslogtreecommitdiff
path: root/src/core/or/status.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/or/status.c')
-rw-r--r--src/core/or/status.c46
1 files changed, 44 insertions, 2 deletions
diff --git a/src/core/or/status.c b/src/core/or/status.c
index 46494ca76c..00a88a3178 100644
--- a/src/core/or/status.c
+++ b/src/core/or/status.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2010-2019, The Tor Project, Inc. */
+/* Copyright (c) 2010-2020, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/**
@@ -17,6 +17,7 @@
#include "core/or/or.h"
#include "core/or/circuituse.h"
#include "app/config/config.h"
+#include "feature/dirclient/dirclient.h"
#include "core/or/status.h"
#include "feature/nodelist/nodelist.h"
#include "core/or/relay.h"
@@ -112,6 +113,41 @@ log_onion_service_stats(void)
hs_stats_get_n_rendezvous_launches());
}
+/**
+ * @name connection counts for heartbeat
+ *
+ * Tracks incoming and outgoing connections on IPv4/IPv6, for heartbeat
+ * logs.
+ **/
+/**@{*/
+static unsigned n_incoming_ipv4;
+static unsigned n_incoming_ipv6;
+static unsigned n_outgoing_ipv4;
+static unsigned n_outgoing_ipv6;
+/**@}*/
+
+/**
+ * Note that a connection has arrived or has been made, for use in the
+ * heartbeat message.
+ **/
+void
+note_connection(bool inbound, int family)
+{
+ if (family == AF_INET) {
+ if (inbound) {
+ ++n_incoming_ipv4;
+ } else {
+ ++n_outgoing_ipv4;
+ }
+ } else if (family == AF_INET6) {
+ if (inbound) {
+ ++n_incoming_ipv6;
+ } else {
+ ++n_outgoing_ipv6;
+ }
+ }
+}
+
/** Log a "heartbeat" message describing Tor's status and history so that the
* user can know that there is indeed a running Tor. Return 0 on success and
* -1 on failure. */
@@ -142,10 +178,16 @@ log_heartbeat(time_t now)
bw_sent = bytes_to_usage(get_bytes_written());
log_fn(LOG_NOTICE, LD_HEARTBEAT, "Heartbeat: Tor's uptime is %s, with %d "
- "circuits open. I've sent %s and received %s.%s",
+ "circuits open. I've sent %s and received %s. I've received %u "
+ "connections on IPv4 and %u on IPv6. I've made %u connections "
+ "with IPv4 and %u with IPv6.%s",
uptime, count_circuits(), bw_sent, bw_rcvd,
+ n_incoming_ipv4, n_incoming_ipv6,
+ n_outgoing_ipv4, n_outgoing_ipv6,
hibernating?" We are currently hibernating.":"");
+ dirclient_dump_total_dls();
+
if (server_mode(options) && accounting_is_enabled(options) && !hibernating) {
log_accounting(now, options);
}