aboutsummaryrefslogtreecommitdiff
path: root/src/core/mainloop/connection.c
diff options
context:
space:
mode:
authorDavid Goulet <dgoulet@torproject.org>2022-10-11 13:17:35 -0400
committerDavid Goulet <dgoulet@torproject.org>2022-10-12 09:25:19 -0400
commit5603baf2570a427c2ea56145ed5607aae504d6b7 (patch)
tree80010152a5373ce3fa2a69552abfae5ceef6f8e6 /src/core/mainloop/connection.c
parentd09414858e2f5c5efa2ece4b3a32a6b47374dfdd (diff)
downloadtor-5603baf2570a427c2ea56145ed5607aae504d6b7.tar.gz
tor-5603baf2570a427c2ea56145ed5607aae504d6b7.zip
conn: Keep stats of opened and closed connections
Related to #40194 Signed-off-by: David Goulet <dgoulet@torproject.org>
Diffstat (limited to 'src/core/mainloop/connection.c')
-rw-r--r--src/core/mainloop/connection.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/core/mainloop/connection.c b/src/core/mainloop/connection.c
index 9271a70914..c6af478c44 100644
--- a/src/core/mainloop/connection.c
+++ b/src/core/mainloop/connection.c
@@ -658,6 +658,9 @@ listener_connection_new(int type, int socket_family)
listener_connection_t *listener_conn =
tor_malloc_zero(sizeof(listener_connection_t));
connection_init(time(NULL), TO_CONN(listener_conn), type, socket_family);
+ /* Listener connections aren't accounted for with note_connection() so do
+ * this explicitly so to count them. */
+ rep_hist_note_conn_opened(false, type);
return listener_conn;
}
@@ -1160,6 +1163,9 @@ connection_mark_for_close_internal_, (connection_t *conn,
* the number of seconds since last successful write, so
* we get our whole 15 seconds */
conn->timestamp_last_write_allowed = time(NULL);
+
+ /* Note the connection close. */
+ rep_hist_note_conn_closed(conn->from_listener, conn->type);
}
/** Find each connection that has hold_open_until_flushed set to
@@ -2074,6 +2080,9 @@ connection_handle_listener_read(connection_t *conn, int new_type)
tor_assert(0);
};
+ /* We are receiving this connection. */
+ newconn->from_listener = 1;
+
if (connection_add(newconn) < 0) { /* no space, forget it */
connection_free(newconn);
return 0; /* no need to tear down the parent */
@@ -2085,7 +2094,7 @@ connection_handle_listener_read(connection_t *conn, int new_type)
return 0;
}
- note_connection(true /* inbound */, conn->socket_family);
+ note_connection(true /* inbound */, newconn);
return 0;
}
@@ -2258,7 +2267,7 @@ connection_connect_sockaddr,(connection_t *conn,
}
}
- note_connection(false /* outbound */, conn->socket_family);
+ note_connection(false /* outbound */, conn);
/* it succeeded. we're connected. */
log_fn(inprogress ? LOG_DEBUG : LOG_INFO, LD_NET,