mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-12-06 19:41:15 +01:00
Fix O(n^2) performance when parsing a big pile of extrainfos
We were doing an O(n) strlen in router_get_extrainfo_hash() for every one we tried to parse. Instead, have router_get_extrainfo_hash() take the length of the extrainfo as an argument, so that when it's called from extrainfo_parse_from_string(), it doesn't do a strlen() over the whole pile of extrainfos.
This commit is contained in:
committed by
Roger Dingledine
parent
62f8e3926d
commit
02a650786b
+2
-1
@@ -1655,6 +1655,7 @@ router_rebuild_descriptor(int force)
|
||||
ei->cache_info.signed_descriptor_len =
|
||||
strlen(ei->cache_info.signed_descriptor_body);
|
||||
router_get_extrainfo_hash(ei->cache_info.signed_descriptor_body,
|
||||
ei->cache_info.signed_descriptor_len,
|
||||
ei->cache_info.signed_descriptor_digest);
|
||||
}
|
||||
|
||||
@@ -2359,7 +2360,7 @@ extrainfo_dump_to_string(char **s_out, extrainfo_t *extrainfo,
|
||||
}
|
||||
|
||||
memset(sig, 0, sizeof(sig));
|
||||
if (router_get_extrainfo_hash(s, digest) < 0 ||
|
||||
if (router_get_extrainfo_hash(s, strlen(s), digest) < 0 ||
|
||||
router_append_dirobj_signature(sig, sizeof(sig), digest, DIGEST_LEN,
|
||||
ident_key) < 0) {
|
||||
log_warn(LD_BUG, "Could not append signature to extra-info "
|
||||
|
||||
Reference in New Issue
Block a user