[tor-commits] [tor/master] Extract download_status_t into its own header.
nickm at torproject.org
nickm at torproject.org
Mon Jun 18 18:18:43 UTC 2018
commit f85d731e3af16e72682f68be4f598f08ed227618
Author: Nick Mathewson <nickm at torproject.org>
Date: Fri Jun 15 14:58:43 2018 -0400
Extract download_status_t into its own header.
---
src/or/directory.c | 21 ++++++++++++++
src/or/directory.h | 25 ++---------------
src/or/download_status_st.h | 65 +++++++++++++++++++++++++++++++++++++++++++
src/or/include.am | 1 +
src/or/or.h | 54 +----------------------------------
src/or/routerstatus_st.h | 2 ++
src/or/signed_descriptor_st.h | 2 ++
src/test/test_controller.c | 1 +
8 files changed, 95 insertions(+), 76 deletions(-)
diff --git a/src/or/directory.c b/src/or/directory.c
index 4e2e96886..f6d6d28d4 100644
--- a/src/or/directory.c
+++ b/src/or/directory.c
@@ -5632,6 +5632,27 @@ download_status_reset(download_status_t *dls)
/* Don't reset dls->want_authority or dls->increment_on */
}
+/** Return true iff, as of <b>now</b>, the resource tracked by <b>dls</b> is
+ * ready to get its download reattempted. */
+int
+download_status_is_ready(download_status_t *dls, time_t now)
+{
+ /* dls wasn't reset before it was used */
+ if (dls->next_attempt_at == 0) {
+ download_status_reset(dls);
+ }
+
+ return download_status_get_next_attempt_at(dls) <= now;
+}
+
+/** Mark <b>dl</b> as never downloadable. */
+void
+download_status_mark_impossible(download_status_t *dl)
+{
+ dl->n_download_failures = IMPOSSIBLE_TO_DOWNLOAD;
+ dl->n_download_attempts = IMPOSSIBLE_TO_DOWNLOAD;
+}
+
/** Return the number of failures on <b>dls</b> since the last success (if
* any). */
int
diff --git a/src/or/directory.h b/src/or/directory.h
index 8823de4d9..27dc986a0 100644
--- a/src/or/directory.h
+++ b/src/or/directory.h
@@ -134,30 +134,9 @@ time_t download_status_increment_attempt(download_status_t *dls,
time(NULL))
void download_status_reset(download_status_t *dls);
-static int download_status_is_ready(download_status_t *dls, time_t now);
+int download_status_is_ready(download_status_t *dls, time_t now);
time_t download_status_get_next_attempt_at(const download_status_t *dls);
-
-/** Return true iff, as of <b>now</b>, the resource tracked by <b>dls</b> is
- * ready to get its download reattempted. */
-static inline int
-download_status_is_ready(download_status_t *dls, time_t now)
-{
- /* dls wasn't reset before it was used */
- if (dls->next_attempt_at == 0) {
- download_status_reset(dls);
- }
-
- return download_status_get_next_attempt_at(dls) <= now;
-}
-
-static void download_status_mark_impossible(download_status_t *dl);
-/** Mark <b>dl</b> as never downloadable. */
-static inline void
-download_status_mark_impossible(download_status_t *dl)
-{
- dl->n_download_failures = IMPOSSIBLE_TO_DOWNLOAD;
- dl->n_download_attempts = IMPOSSIBLE_TO_DOWNLOAD;
-}
+void download_status_mark_impossible(download_status_t *dl);
int download_status_get_n_failures(const download_status_t *dls);
int download_status_get_n_attempts(const download_status_t *dls);
diff --git a/src/or/download_status_st.h b/src/or/download_status_st.h
new file mode 100644
index 000000000..8ed77aaa7
--- /dev/null
+++ b/src/or/download_status_st.h
@@ -0,0 +1,65 @@
+/* Copyright (c) 2001 Matej Pfajfar.
+ * Copyright (c) 2001-2004, Roger Dingledine.
+ * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
+ * Copyright (c) 2007-2017, The Tor Project, Inc. */
+/* See LICENSE for licensing information */
+
+#ifndef DOWNLOAD_STATUS_ST_H
+#define DOWNLOAD_STATUS_ST_H
+
+/** Information about our plans for retrying downloads for a downloadable
+ * directory object.
+ * Each type of downloadable directory object has a corresponding retry
+ * <b>schedule</b>, which can be different depending on whether the object is
+ * being downloaded from an authority or a mirror (<b>want_authority</b>).
+ * <b>next_attempt_at</b> contains the next time we will attempt to download
+ * the object.
+ * For schedules that <b>increment_on</b> failure, <b>n_download_failures</b>
+ * is used to determine the position in the schedule. (Each schedule is a
+ * smartlist of integer delays, parsed from a CSV option.) Every time a
+ * connection attempt fails, <b>n_download_failures</b> is incremented,
+ * the new delay value is looked up from the schedule, and
+ * <b>next_attempt_at</b> is set delay seconds from the time the previous
+ * connection failed. Therefore, at most one failure-based connection can be
+ * in progress for each download_status_t.
+ * For schedules that <b>increment_on</b> attempt, <b>n_download_attempts</b>
+ * is used to determine the position in the schedule. Every time a
+ * connection attempt is made, <b>n_download_attempts</b> is incremented,
+ * the new delay value is looked up from the schedule, and
+ * <b>next_attempt_at</b> is set delay seconds from the time the previous
+ * connection was attempted. Therefore, multiple concurrent attempted-based
+ * connections can be in progress for each download_status_t.
+ * After an object is successfully downloaded, any other concurrent connections
+ * are terminated. A new schedule which starts at position 0 is used for
+ * subsequent downloads of the same object.
+ */
+struct download_status_t {
+ time_t next_attempt_at; /**< When should we try downloading this object
+ * again? */
+ uint8_t n_download_failures; /**< Number of failed downloads of the most
+ * recent object, since the last success. */
+ uint8_t n_download_attempts; /**< Number of (potentially concurrent) attempts
+ * to download the most recent object, since
+ * the last success. */
+ download_schedule_bitfield_t schedule : 8; /**< What kind of object is being
+ * downloaded? This determines the
+ * schedule used for the download.
+ */
+ download_want_authority_bitfield_t want_authority : 1; /**< Is the download
+ * happening from an authority
+ * or a mirror? This determines
+ * the schedule used for the
+ * download. */
+ download_schedule_increment_bitfield_t increment_on : 1; /**< does this
+ * schedule increment on each attempt,
+ * or after each failure? */
+ uint8_t last_backoff_position; /**< number of attempts/failures, depending
+ * on increment_on, when we last recalculated
+ * the delay. Only updated if backoff
+ * == 1. */
+ int last_delay_used; /**< last delay used for random exponential backoff;
+ * only updated if backoff == 1 */
+};
+
+#endif
+
diff --git a/src/or/include.am b/src/or/include.am
index cb9f4994e..c28e95f05 100644
--- a/src/or/include.am
+++ b/src/or/include.am
@@ -217,6 +217,7 @@ ORHEADERS = \
src/or/dir_connection_st.h \
src/or/dir_server_st.h \
src/or/document_signature_st.h \
+ src/or/download_status_st.h \
src/or/dns.h \
src/or/dns_structs.h \
src/or/dnsserv.h \
diff --git a/src/or/or.h b/src/or/or.h
index 3dd1b6fe5..9668760cc 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -1449,59 +1449,7 @@ typedef enum {
#define download_schedule_increment_bitfield_t \
ENUM_BF(download_schedule_increment_t)
-/** Information about our plans for retrying downloads for a downloadable
- * directory object.
- * Each type of downloadable directory object has a corresponding retry
- * <b>schedule</b>, which can be different depending on whether the object is
- * being downloaded from an authority or a mirror (<b>want_authority</b>).
- * <b>next_attempt_at</b> contains the next time we will attempt to download
- * the object.
- * For schedules that <b>increment_on</b> failure, <b>n_download_failures</b>
- * is used to determine the position in the schedule. (Each schedule is a
- * smartlist of integer delays, parsed from a CSV option.) Every time a
- * connection attempt fails, <b>n_download_failures</b> is incremented,
- * the new delay value is looked up from the schedule, and
- * <b>next_attempt_at</b> is set delay seconds from the time the previous
- * connection failed. Therefore, at most one failure-based connection can be
- * in progress for each download_status_t.
- * For schedules that <b>increment_on</b> attempt, <b>n_download_attempts</b>
- * is used to determine the position in the schedule. Every time a
- * connection attempt is made, <b>n_download_attempts</b> is incremented,
- * the new delay value is looked up from the schedule, and
- * <b>next_attempt_at</b> is set delay seconds from the time the previous
- * connection was attempted. Therefore, multiple concurrent attempted-based
- * connections can be in progress for each download_status_t.
- * After an object is successfully downloaded, any other concurrent connections
- * are terminated. A new schedule which starts at position 0 is used for
- * subsequent downloads of the same object.
- */
-typedef struct download_status_t {
- time_t next_attempt_at; /**< When should we try downloading this object
- * again? */
- uint8_t n_download_failures; /**< Number of failed downloads of the most
- * recent object, since the last success. */
- uint8_t n_download_attempts; /**< Number of (potentially concurrent) attempts
- * to download the most recent object, since
- * the last success. */
- download_schedule_bitfield_t schedule : 8; /**< What kind of object is being
- * downloaded? This determines the
- * schedule used for the download.
- */
- download_want_authority_bitfield_t want_authority : 1; /**< Is the download
- * happening from an authority
- * or a mirror? This determines
- * the schedule used for the
- * download. */
- download_schedule_increment_bitfield_t increment_on : 1; /**< does this
- * schedule increment on each attempt,
- * or after each failure? */
- uint8_t last_backoff_position; /**< number of attempts/failures, depending
- * on increment_on, when we last recalculated
- * the delay. Only updated if backoff
- * == 1. */
- int last_delay_used; /**< last delay used for random exponential backoff;
- * only updated if backoff == 1 */
-} download_status_t;
+typedef struct download_status_t download_status_t;
/** If n_download_failures is this high, the download can never happen. */
#define IMPOSSIBLE_TO_DOWNLOAD 255
diff --git a/src/or/routerstatus_st.h b/src/or/routerstatus_st.h
index 9c25e88b6..f8a27ccac 100644
--- a/src/or/routerstatus_st.h
+++ b/src/or/routerstatus_st.h
@@ -7,6 +7,8 @@
#ifndef ROUTERSTATUS_ST_H
#define ROUTERSTATUS_ST_H
+#include "download_status_st.h"
+
/** Contents of a single router entry in a network status object.
*/
struct routerstatus_t {
diff --git a/src/or/signed_descriptor_st.h b/src/or/signed_descriptor_st.h
index 0159e9176..c057c5ddc 100644
--- a/src/or/signed_descriptor_st.h
+++ b/src/or/signed_descriptor_st.h
@@ -7,6 +7,8 @@
#ifndef SIGNED_DESCRIPTOR_ST_H
#define SIGNED_DESCRIPTOR_ST_H
+#include "download_status_st.h"
+
/** Information need to cache an onion router's descriptor. */
struct signed_descriptor_t {
/** Pointer to the raw server descriptor, preceded by annotations. Not
diff --git a/src/test/test_controller.c b/src/test/test_controller.c
index 6b8edc57c..958874fcb 100644
--- a/src/test/test_controller.c
+++ b/src/test/test_controller.c
@@ -14,6 +14,7 @@
#include "test_helpers.h"
#include "control_connection_st.h"
+#include "download_status_st.h"
static void
test_add_onion_helper_keyarg_v3(void *arg)
More information about the tor-commits
mailing list