mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-28 14:23:30 +01:00
Return "304 not modified" if a client already have the most recent consensus.
This makes our directory code check if a client is trying to fetch a document that matches a digest from our latest consensus document. See: https://bugs.torproject.org/22702
This commit is contained in:
parent
07f2940b45
commit
0a4af86335
@ -3883,6 +3883,30 @@ find_best_compression_method(unsigned compression_methods, int stream)
|
||||
return NO_METHOD;
|
||||
}
|
||||
|
||||
/** Check if any of the digests in <b>digests</b> matches the latest consensus
|
||||
* flavor (given in <b>flavor</b>) that we have available. */
|
||||
static int
|
||||
digest_list_contains_best_consensus(consensus_flavor_t flavor,
|
||||
const smartlist_t *digests)
|
||||
{
|
||||
const networkstatus_t *ns = NULL;
|
||||
|
||||
if (digests == NULL)
|
||||
return 0;
|
||||
|
||||
ns = networkstatus_get_latest_consensus_by_flavor(flavor);
|
||||
|
||||
if (ns == NULL)
|
||||
return 0;
|
||||
|
||||
SMARTLIST_FOREACH_BEGIN(digests, const uint8_t *, digest) {
|
||||
if (tor_memeq(ns->digest_sha3_as_signed, digest, DIGEST256_LEN))
|
||||
return 1;
|
||||
} SMARTLIST_FOREACH_END(digest);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** Check if the given compression method is allowed for a connection that is
|
||||
* supposed to be anonymous. Returns 1 if the compression method is allowed,
|
||||
* otherwise 0. */
|
||||
@ -4052,6 +4076,13 @@ handle_get_current_consensus(dir_connection_t *conn,
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (digest_list_contains_best_consensus(req.flav,
|
||||
req.diff_from_digests)) {
|
||||
write_http_status_line(conn, 304, "Not modified");
|
||||
geoip_note_ns_response(GEOIP_REJECT_NOT_MODIFIED);
|
||||
goto done;
|
||||
}
|
||||
|
||||
struct consensus_cache_entry_t *cached_consensus = NULL;
|
||||
|
||||
compress_method_t compression_used = NO_METHOD;
|
||||
|
Loading…
Reference in New Issue
Block a user