From 17daab76b87a9cc7491bdfdc46dd10c9d5d7023f Mon Sep 17 00:00:00 2001 From: George Kadianakis Date: Tue, 23 Jan 2018 12:31:06 +0200 Subject: [PATCH] Add onion service activity information to our heartbeat logs. --- changes/bug24896 | 3 +++ src/or/circuituse.c | 6 +++++ src/or/hs_service.c | 3 +++ src/or/hs_stats.c | 58 +++++++++++++++++++++++++++++++++++++++++++++ src/or/hs_stats.h | 14 +++++++++++ src/or/include.am | 2 ++ src/or/status.c | 25 +++++++++++++++++++ 7 files changed, 111 insertions(+) create mode 100644 changes/bug24896 create mode 100644 src/or/hs_stats.c create mode 100644 src/or/hs_stats.h diff --git a/changes/bug24896 b/changes/bug24896 new file mode 100644 index 0000000000..7d2dd74779 --- /dev/null +++ b/changes/bug24896 @@ -0,0 +1,3 @@ + o Minor features (heartbeat): + - Add onion service information to our heartbeat logs, displaying stats + about the activity of configured onion services. Closes ticket 24896. \ No newline at end of file diff --git a/src/or/circuituse.c b/src/or/circuituse.c index 5f9567ea16..2599685964 100644 --- a/src/or/circuituse.c +++ b/src/or/circuituse.c @@ -45,6 +45,7 @@ #include "hs_client.h" #include "hs_circuit.h" #include "hs_ident.h" +#include "hs_stats.h" #include "nodelist.h" #include "networkstatus.h" #include "policies.h" @@ -2026,6 +2027,11 @@ circuit_launch_by_extend_info(uint8_t purpose, int have_path = have_enough_path_info(! (flags & CIRCLAUNCH_IS_INTERNAL) ); int need_specific_rp = 0; + /* Keep some stats about our attempts to launch HS rendezvous circuits */ + if (purpose == CIRCUIT_PURPOSE_S_CONNECT_REND) { + hs_stats_note_service_rendezvous_launch(); + } + if (!onehop_tunnel && (!router_have_minimum_dir_info() || !have_path)) { log_debug(LD_CIRC,"Haven't %s yet; canceling " "circuit launch.", diff --git a/src/or/hs_service.c b/src/or/hs_service.c index 0db22991c2..64ab9c9ee7 100644 --- a/src/or/hs_service.c +++ b/src/or/hs_service.c @@ -36,6 +36,7 @@ #include "hs_ident.h" #include "hs_intropoint.h" #include "hs_service.h" +#include "hs_stats.h" /* Trunnel */ #include "ed25519_cert.h" @@ -3304,8 +3305,10 @@ hs_service_receive_introduce2(origin_circuit_t *circ, const uint8_t *payload, if (circ->hs_ident) { ret = service_handle_introduce2(circ, payload, payload_len); + hs_stats_note_introduce2_cell(1); } else { ret = rend_service_receive_introduction(circ, payload, payload_len); + hs_stats_note_introduce2_cell(0); } done: diff --git a/src/or/hs_stats.c b/src/or/hs_stats.c new file mode 100644 index 0000000000..3e183a5bfc --- /dev/null +++ b/src/or/hs_stats.c @@ -0,0 +1,58 @@ +/* Copyright (c) 2016-2018, The Tor Project, Inc. */ +/* See LICENSE for licensing information */ + +/** + * \file hs_stats.c + * \brief Keeps stats about the activity of our hidden service. + **/ + +#include "or.h" +#include "hs_stats.h" +#include "hs_service.h" + +/** Number of v3 INTRODUCE2 cells received */ +static uint32_t n_introduce2_v3 = 0; +/** Number of v2 INTRODUCE2 cells received */ +static uint32_t n_introduce2_v2 = 0; +/** Number of attempts to make a circuit to a rendezvous point */ +static uint32_t n_rendezvous_launches = 0; + +/** Note that we received another INTRODUCE2 cell. */ +void +hs_stats_note_introduce2_cell(int is_hsv3) +{ + if (is_hsv3) { + n_introduce2_v3++; + } else { + n_introduce2_v2++; + } +} + +/** Return the number of v3 INTRODUCE2 cells we have received. */ +uint32_t +hs_stats_get_n_introduce2_v3_cells(void) +{ + return n_introduce2_v3; +} + +/** Return the number of v2 INTRODUCE2 cells we have received. */ +uint32_t +hs_stats_get_n_introduce2_v2_cells(void) +{ + return n_introduce2_v2; +} + +/** Note that we attempted to launch another circuit to a rendezvous point */ +void +hs_stats_note_service_rendezvous_launch(void) +{ + n_rendezvous_launches++; +} + +/** Return the number of rendezvous circuits we have attempted to launch */ +uint32_t +hs_stats_get_n_rendezvous_launches(void) +{ + return n_rendezvous_launches; +} + diff --git a/src/or/hs_stats.h b/src/or/hs_stats.h new file mode 100644 index 0000000000..a946ad75e5 --- /dev/null +++ b/src/or/hs_stats.h @@ -0,0 +1,14 @@ +/* Copyright (c) 2016-2018, The Tor Project, Inc. */ +/* See LICENSE for licensing information */ + +/** + * \file hs_stats.h + * \brief Header file for hs_stats.c + **/ + +void hs_stats_note_introduce2_cell(int is_hsv3); +uint32_t hs_stats_get_n_introduce2_v3_cells(void); +uint32_t hs_stats_get_n_introduce2_v2_cells(void); +void hs_stats_note_service_rendezvous_launch(void); +uint32_t hs_stats_get_n_rendezvous_launches(void); + diff --git a/src/or/include.am b/src/or/include.am index 1c66cd2de3..09be125617 100644 --- a/src/or/include.am +++ b/src/or/include.am @@ -66,6 +66,7 @@ LIBTOR_A_SOURCES = \ src/or/hs_intropoint.c \ src/or/hs_ntor.c \ src/or/hs_service.c \ + src/or/hs_stats.c \ src/or/keypin.c \ src/or/main.c \ src/or/microdesc.c \ @@ -207,6 +208,7 @@ ORHEADERS = \ src/or/hs_ident.h \ src/or/hs_intropoint.h \ src/or/hs_ntor.h \ + src/or/hs_stats.h \ src/or/hs_service.h \ src/or/keypin.h \ src/or/main.h \ diff --git a/src/or/status.c b/src/or/status.c index 1a8885e83e..187dc4ad22 100644 --- a/src/or/status.c +++ b/src/or/status.c @@ -27,6 +27,8 @@ #include "hibernate.h" #include "rephist.h" #include "statefile.h" +#include "hs_stats.h" +#include "hs_service.h" static void log_accounting(const time_t now, const or_options_t *options); #include "geoip.h" @@ -85,6 +87,26 @@ bytes_to_usage(uint64_t bytes) return bw_string; } +/** Log some usage info about our hidden service */ +static void +log_onion_service_stats(void) +{ + unsigned int num_services = hs_service_get_num_services(); + + /* If there are no active hidden services, no need to print logs */ + if (num_services == 0) { + return; + } + + log_notice(LD_HEARTBEAT, + "Our hidden service%s received %u v2 and %u v3 INTRODUCE2 cells " + "and attempted to launch %d rendezvous circuits.", + num_services == 1 ? "" : "s", + hs_stats_get_n_introduce2_v2_cells(), + hs_stats_get_n_introduce2_v3_cells(), + hs_stats_get_n_rendezvous_launches()); +} + /** 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. */ @@ -171,6 +193,9 @@ log_heartbeat(time_t now) U64_PRINTF_ARG(main_loop_idle_count)); } + /** Now, if we are an HS service, log some stats about our usage */ + log_onion_service_stats(); + tor_free(uptime); tor_free(bw_sent); tor_free(bw_rcvd);