aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2020-02-25 12:58:23 -0500
committerNick Mathewson <nickm@torproject.org>2020-02-25 12:58:23 -0500
commit11adf0f46f88bc07c0c080b3b8f1725b0ad382c6 (patch)
treed033ff3529317e18c7a1feb51fc4be5594fb5093
parentc9bd3579f7e77076eb3543cc5875ed8f9a0d689a (diff)
parent84f2e282049dfb892f4ba849fae4e0c19b7a4166 (diff)
downloadtor-11adf0f46f88bc07c0c080b3b8f1725b0ad382c6.tar.gz
tor-11adf0f46f88bc07c0c080b3b8f1725b0ad382c6.zip
Merge remote-tracking branch 'tor-github/pr/1750/head'
-rw-r--r--changes/ticket327204
-rw-r--r--src/core/or/status.c3
-rw-r--r--src/feature/control/control_bootstrap.c6
-rw-r--r--src/feature/control/control_events.h1
-rw-r--r--src/feature/dirclient/dirclient.c49
-rw-r--r--src/feature/dirclient/dirclient.h2
6 files changed, 65 insertions, 0 deletions
diff --git a/changes/ticket32720 b/changes/ticket32720
new file mode 100644
index 0000000000..87c540b7ff
--- /dev/null
+++ b/changes/ticket32720
@@ -0,0 +1,4 @@
+ o Minor features (directory):
+ - Remember the number of bytes we have downloaded for each directory
+ purpose while bootstrapping, and while fully bootstrapped. Log this
+ information as part of the heartbeat message. Closes ticket 32720.
diff --git a/src/core/or/status.c b/src/core/or/status.c
index f9f603f3b7..ed8448883c 100644
--- a/src/core/or/status.c
+++ b/src/core/or/status.c
@@ -17,6 +17,7 @@
#include "core/or/or.h"
#include "core/or/circuituse.h"
#include "app/config/config.h"
+#include "feature/dirclient/dirclient.h"
#include "core/or/status.h"
#include "feature/nodelist/nodelist.h"
#include "core/or/relay.h"
@@ -146,6 +147,8 @@ log_heartbeat(time_t now)
uptime, count_circuits(), bw_sent, bw_rcvd,
hibernating?" We are currently hibernating.":"");
+ dirclient_dump_total_dls();
+
if (server_mode(options) && accounting_is_enabled(options) && !hibernating) {
log_accounting(now, options);
}
diff --git a/src/feature/control/control_bootstrap.c b/src/feature/control/control_bootstrap.c
index 2e78fad690..fee7612ba2 100644
--- a/src/feature/control/control_bootstrap.c
+++ b/src/feature/control/control_bootstrap.c
@@ -171,6 +171,12 @@ control_event_bootstrap_core(int loglevel, bootstrap_status_t status,
control_event_client_status(LOG_NOTICE, "%s", buf);
}
+int
+control_get_bootstrap_percent(void)
+{
+ return bootstrap_percent;
+}
+
/** Called when Tor has made progress at bootstrapping its directory
* information and initial circuits.
*
diff --git a/src/feature/control/control_events.h b/src/feature/control/control_events.h
index 74bbc0047d..4f960b2443 100644
--- a/src/feature/control/control_events.h
+++ b/src/feature/control/control_events.h
@@ -164,6 +164,7 @@ int control_event_buildtimeout_set(buildtimeout_set_event_t type,
int control_event_signal(uintptr_t signal);
void control_event_bootstrap(bootstrap_status_t status, int progress);
+int control_get_bootstrap_percent(void);
MOCK_DECL(void, control_event_bootstrap_prob_or,(const char *warn,
int reason,
or_connection_t *or_conn));
diff --git a/src/feature/dirclient/dirclient.c b/src/feature/dirclient/dirclient.c
index a216e5e27a..a2ad69649c 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,44 @@ 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)
+{
+ const or_options_t *options = get_options();
+ for (int bootstrapped = 0; bootstrapped < 2; ++bootstrapped) {
+ bool first_time = true;
+ for (int i=0; i < DIR_PURPOSE_MAX_; ++i) {
+ uint64_t n = total_dl[i][0];
+ if (n == 0)
+ continue;
+ if (options->SafeLogging_ != SAFELOG_SCRUB_NONE &&
+ purpose_needs_anonymity(i, ROUTER_PURPOSE_GENERAL, NULL))
+ continue;
+ if (first_time) {
+ log_notice(LD_NET,
+ "While %sbootstrapping, fetched this many bytes: ",
+ bootstrapped?"not ":"");
+ first_time = false;
+ }
+ log_notice(LD_NET, " %"PRIu64" (%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 +2036,16 @@ connection_dir_client_reached_eof(dir_connection_t *conn)
received_bytes = connection_get_inbuf_len(TO_CONN(conn));
+ log_debug(LD_DIR, "Downloaded %"TOR_PRIuSZ" 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,