summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2017-05-04 12:15:48 -0400
committerNick Mathewson <nickm@torproject.org>2017-05-05 09:11:06 -0400
commitc9855928744a556ef882ef8409ba8b54afd11834 (patch)
treef2a5888c361886a079293f46f50fe2592507c6e9
parent60e97953ef4b139f4af3fbd71db664c03961f2eb (diff)
downloadtor-c9855928744a556ef882ef8409ba8b54afd11834.tar.gz
tor-c9855928744a556ef882ef8409ba8b54afd11834.zip
prop140 clients now only try to get diffs from recent consensuses
Rationale: If it's a year old, the relay won't have a diff to it. This is as specified in prop140
-rw-r--r--src/or/directory.c24
1 files changed, 20 insertions, 4 deletions
diff --git a/src/or/directory.c b/src/or/directory.c
index 67c28e1f3e..20ff53759c 100644
--- a/src/or/directory.c
+++ b/src/or/directory.c
@@ -497,11 +497,23 @@ dir_consensus_request_set_additional_headers(directory_request_t *req,
* period of 1 hour.
*/
const int DEFAULT_IF_MODIFIED_SINCE_DELAY = 180;
+ const int32_t DEFAULT_TRY_DIFF_FOR_CONSENSUS_NEWER = 72;
+ const int32_t MIN_TRY_DIFF_FOR_CONSENSUS_NEWER = 0;
+ const int32_t MAX_TRY_DIFF_FOR_CONSENSUS_NEWER = 8192;
+ const char TRY_DIFF_FOR_CONSENSUS_NEWER_NAME[] =
+ "try-diff-for-consensus-newer-than";
int flav = FLAV_NS;
if (resource)
flav = networkstatus_parse_flavor_name(resource);
+ int32_t max_age_for_diff = 3600 *
+ networkstatus_get_param(NULL,
+ TRY_DIFF_FOR_CONSENSUS_NEWER_NAME,
+ DEFAULT_TRY_DIFF_FOR_CONSENSUS_NEWER,
+ MIN_TRY_DIFF_FOR_CONSENSUS_NEWER,
+ MAX_TRY_DIFF_FOR_CONSENSUS_NEWER);
+
if (flav != -1) {
/* IF we have a parsed consensus of this type, we can do an
* if-modified-time based on it. */
@@ -517,8 +529,10 @@ dir_consensus_request_set_additional_headers(directory_request_t *req,
ims_delay = (v->fresh_until - v->valid_after)/2;
}
if_modified_since = v->valid_after + ims_delay;
- memcpy(or_diff_from, v->digest_sha3_as_signed, DIGEST256_LEN);
- or_diff_from_is_set = 1;
+ if (v->valid_after >= approx_time() - max_age_for_diff) {
+ memcpy(or_diff_from, v->digest_sha3_as_signed, DIGEST256_LEN);
+ or_diff_from_is_set = 1;
+ }
}
} else {
/* Otherwise it might be a consensus we don't parse, but which we
@@ -528,8 +542,10 @@ dir_consensus_request_set_additional_headers(directory_request_t *req,
* unparsed consensus, so we use the default. */
if (cd) {
if_modified_since = cd->published + DEFAULT_IF_MODIFIED_SINCE_DELAY;
- memcpy(or_diff_from, cd->digest_sha3_as_signed, DIGEST256_LEN);
- or_diff_from_is_set = 1;
+ if (cd->published >= approx_time() - max_age_for_diff) {
+ memcpy(or_diff_from, cd->digest_sha3_as_signed, DIGEST256_LEN);
+ or_diff_from_is_set = 1;
+ }
}
}