Browse Source

Add onion service activity information to our heartbeat logs.

George Kadianakis 6 years ago
parent
commit
17daab76b8
7 changed files with 111 additions and 0 deletions
  1. 3 0
      changes/bug24896
  2. 6 0
      src/or/circuituse.c
  3. 3 0
      src/or/hs_service.c
  4. 58 0
      src/or/hs_stats.c
  5. 14 0
      src/or/hs_stats.h
  6. 2 0
      src/or/include.am
  7. 25 0
      src/or/status.c

+ 3 - 0
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.

+ 6 - 0
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.",

+ 3 - 0
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:

+ 58 - 0
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;
+}
+

+ 14 - 0
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);
+

+ 2 - 0
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					\

+ 25 - 0
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);