aboutsummaryrefslogtreecommitdiff
path: root/src/feature/dirclient
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2019-12-12 12:11:09 -0500
committerNick Mathewson <nickm@torproject.org>2020-02-18 11:25:18 -0500
commit93af83e16a620a8e8d9972f65b724e4e3a520434 (patch)
treef6e6f4ab85213764747491286012f1d83634c309 /src/feature/dirclient
parent17724a7cdeb9b98539831f1164a82784f1fb050f (diff)
downloadtor-93af83e16a620a8e8d9972f65b724e4e3a520434.tar.gz
tor-93af83e16a620a8e8d9972f65b724e4e3a520434.zip
Remember dirctory bw usage, and log it in the heartbeat
Closes ticket 32720.
Diffstat (limited to 'src/feature/dirclient')
-rw-r--r--src/feature/dirclient/dirclient.c45
-rw-r--r--src/feature/dirclient/dirclient.h2
2 files changed, 47 insertions, 0 deletions
diff --git a/src/feature/dirclient/dirclient.c b/src/feature/dirclient/dirclient.c
index 1b6eed12f0..7c7057b102 100644
--- a/src/feature/dirclient/dirclient.c
+++ b/src/feature/dirclient/dirclient.c
@@ -21,6 +21,7 @@
#include "feature/client/entrynodes.h"
#include "feature/control/control_events.h"
#include "feature/dirauth/authmode.h"
+#include "feature/dirclient/dirclient.h"
#include "feature/dirauth/dirvote.h"
#include "feature/dirauth/shared_random.h"
#include "feature/dircache/dirserv.h"
@@ -1964,6 +1965,40 @@ dir_client_decompress_response_body(char **bodyp, size_t *bodylenp,
return rv;
}
+/**
+ * Total number of bytes downloaded of each directory purpose, when
+ * bootstrapped, and when not bootstrapped.
+ *
+ * (For example, the number of bytes downloaded of purpose p while
+ * not fully bootstrapped is total_dl[p][false].)
+ **/
+static uint64_t total_dl[DIR_PURPOSE_MAX_][2];
+
+/**
+ * Heartbeat: dump a summary of how many bytes of which purpose we've
+ * downloaded, when bootstrapping and when not bootstrapping.
+ **/
+void
+dirclient_dump_total_dls(void)
+{
+ log_notice(LD_NET,
+ "While bootstrapping, fetched this many bytes: ");
+ for (int i=0; i < DIR_PURPOSE_MAX_; ++i) {
+ uint64_t n = total_dl[i][0];
+ if (n) {
+ log_notice(LD_NET, " %zu (%s)", n, dir_conn_purpose_to_string(i));
+ }
+ }
+ log_notice(LD_NET,
+ "While not bootsrapping, fetched this many bytes: ");
+ for (int i=0; i < DIR_PURPOSE_MAX_; ++i) {
+ uint64_t n = total_dl[i][1];
+ if (n) {
+ log_notice(LD_NET, " %zu (%s)", n, dir_conn_purpose_to_string(i));
+ }
+ }
+}
+
/** We are a client, and we've finished reading the server's
* response. Parse it and act appropriately.
*
@@ -1997,6 +2032,16 @@ connection_dir_client_reached_eof(dir_connection_t *conn)
received_bytes = connection_get_inbuf_len(TO_CONN(conn));
+ log_debug(LD_DIR, "Downloaded %zu bytes on connection of purpose "
+ "%s; bootstrap %d%%",
+ received_bytes,
+ dir_conn_purpose_to_string(conn->base_.purpose),
+ control_get_bootstrap_percent());
+ {
+ bool bootstrapped = control_get_bootstrap_percent() == 100;
+ total_dl[conn->base_.purpose][bootstrapped] += received_bytes;
+ }
+
switch (connection_fetch_from_buf_http(TO_CONN(conn),
&headers, MAX_HEADERS_SIZE,
&body, &body_len, MAX_DIR_DL_SIZE,
diff --git a/src/feature/dirclient/dirclient.h b/src/feature/dirclient/dirclient.h
index 08209721bb..096b197526 100644
--- a/src/feature/dirclient/dirclient.h
+++ b/src/feature/dirclient/dirclient.h
@@ -14,6 +14,8 @@
#include "feature/hs/hs_ident.h"
+void dirclient_dump_total_dls(void);
+
int directories_have_accepted_server_descriptor(void);
void directory_post_to_dirservers(uint8_t dir_purpose, uint8_t router_purpose,
dirinfo_type_t type, const char *payload,