diff options
Diffstat (limited to 'src/or/directory.c')
-rw-r--r-- | src/or/directory.c | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/src/or/directory.c b/src/or/directory.c index d2ac42c3ff..a5121ebf6c 100644 --- a/src/or/directory.c +++ b/src/or/directory.c @@ -499,11 +499,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. */ @@ -519,8 +531,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 @@ -530,8 +544,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; + } } } |