]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
rephist: Track number of streams seen per type
authorDavid Goulet <dgoulet@torproject.org>
Thu, 13 Oct 2022 14:32:16 +0000 (10:32 -0400)
committerDavid Goulet <dgoulet@torproject.org>
Wed, 26 Oct 2022 19:16:48 +0000 (15:16 -0400)
Related to #40194

Signed-off-by: David Goulet <dgoulet@torproject.org>
src/core/or/connection_edge.c
src/feature/stats/rephist.c
src/feature/stats/rephist.h

index 7ba7ecc4c53ddd7cbc94ad56a8cfb444999800e5..2a79d0cf585e4f8c0717ce7e4285c63c19cd8099 100644 (file)
@@ -4119,6 +4119,9 @@ connection_exit_begin_resolve(cell_t *cell, or_circuit_t *circ)
   if (rh.length > RELAY_PAYLOAD_SIZE)
     return -1;
 
+  /* Note the RESOLVE stream as seen. */
+  rep_hist_note_stream(RELAY_COMMAND_RESOLVE);
+
   /* This 'dummy_conn' only exists to remember the stream ID
    * associated with the resolve request; and to make the
    * implementation of dns.c more uniform.  (We really only need to
@@ -4241,6 +4244,10 @@ connection_exit_connect(edge_connection_t *edge_conn)
     return;
   }
 
+  /* Note the BEGIN stream as seen. We do this after the Exit policy check in
+   * order to only account for valid streams. */
+  rep_hist_note_stream(RELAY_COMMAND_BEGIN);
+
 #ifdef HAVE_SYS_UN_H
   if (conn->socket_family != AF_UNIX) {
 #else
@@ -4336,6 +4343,9 @@ connection_exit_connect_dir(edge_connection_t *exitconn)
 
   log_info(LD_EXIT, "Opening local connection for anonymized directory exit");
 
+  /* Note the BEGIN_DIR stream as seen. */
+  rep_hist_note_stream(RELAY_COMMAND_BEGIN_DIR);
+
   exitconn->base_.state = EXIT_CONN_STATE_OPEN;
 
   dirconn = dir_connection_new(tor_addr_family(&exitconn->base_.addr));
index f12b1e8a70a176989ef4e8904d66d1cb73f675a1..962450e72bd9771f035cdf0a58584a7efd8f49f4 100644 (file)
@@ -1639,6 +1639,50 @@ rep_hist_note_exit_stream_opened(uint16_t port)
   log_debug(LD_HIST, "Opened exit stream to port %d", port);
 }
 
+/*** Streams statistics ***/
+
+/** Number of BEGIN streams seen. */
+static uint64_t streams_begin_seen;
+/** Number of BEGIN_DIR streams seen. */
+static uint64_t streams_begindir_seen;
+/** Number of RESOLVE streams seen. */
+static uint64_t streams_resolve_seen;
+
+/** Note a stream as seen for the given relay command. */
+void
+rep_hist_note_stream(unsigned int cmd)
+{
+  switch (cmd) {
+  case RELAY_COMMAND_BEGIN:
+    streams_begin_seen++;
+    break;
+  case RELAY_COMMAND_BEGIN_DIR:
+    streams_begindir_seen++;
+    break;
+  case RELAY_COMMAND_RESOLVE:
+    streams_resolve_seen++;
+    break;
+  default:
+    break;
+  }
+}
+
+/** Return number of stream seen for the given command. */
+uint64_t
+rep_hist_get_stream_seen(unsigned int cmd)
+{
+  switch (cmd) {
+  case RELAY_COMMAND_BEGIN:
+    return streams_begin_seen;
+  case RELAY_COMMAND_BEGIN_DIR:
+    return streams_begindir_seen;
+  case RELAY_COMMAND_RESOLVE:
+    return streams_resolve_seen;
+  default:
+    return 0;
+  }
+}
+
 /******* Connections statistics *******/
 
 #define CONN_DIRECTION_INITIATED 0
index 2a83dd185e2a5d49f2e53a4c2b3c9e1db366ffaa..c1352ae7f8a09bba2fe9fb529fdf57208353bb9f 100644 (file)
@@ -48,6 +48,9 @@ uint64_t rep_hist_get_conn_created(bool initiated, unsigned int type);
 uint64_t rep_hist_get_conn_opened(bool initiated, unsigned int type);
 uint64_t rep_hist_get_conn_rejected(unsigned int type);
 
+void rep_hist_note_stream(unsigned int cmd);
+uint64_t rep_hist_get_stream_seen(unsigned int cmd);
+
 void rep_hist_buffer_stats_init(time_t now);
 void rep_hist_buffer_stats_add_circ(circuit_t *circ,
                                     time_t end_of_interval);