diff options
author | Nick Mathewson <nickm@torproject.org> | 2015-12-18 13:16:49 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2015-12-18 13:16:49 -0500 |
commit | c4fb7ad0348a190be8496b429aa96982f1b26917 (patch) | |
tree | 5898237d9b67e5669448b8265ae1415fc1c19aab /src/or/networkstatus.c | |
parent | 14c9b9905180a21b8aa648b642ff5d3f7d86e29f (diff) | |
parent | ea6f88478cec6b3151a992cf2fd99539997ebb94 (diff) | |
download | tor-c4fb7ad0348a190be8496b429aa96982f1b26917.tar.gz tor-c4fb7ad0348a190be8496b429aa96982f1b26917.zip |
Merge branch 'feature12538_028_01_squashed'
Diffstat (limited to 'src/or/networkstatus.c')
-rw-r--r-- | src/or/networkstatus.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/or/networkstatus.c b/src/or/networkstatus.c index 0cf8873f03..f3a8276689 100644 --- a/src/or/networkstatus.c +++ b/src/or/networkstatus.c @@ -1461,6 +1461,38 @@ networkstatus_copy_old_consensus_info(networkstatus_t *new_c, } SMARTLIST_FOREACH_JOIN_END(rs_old, rs_new); } +#ifdef TOR_UNIT_TESTS +/**Accept a <b>flavor</b> consensus <b>c</b> without any additional + * validation. This is exclusively for unit tests. + * We copy any ancillary information from a pre-existing consensus + * and then free the current one and replace it with the newly + * provided instance. Returns -1 on unrecognized flavor, 0 otherwise. + */ +int +networkstatus_set_current_consensus_from_ns(networkstatus_t *c, + const char *flavor) +{ + int flav = networkstatus_parse_flavor_name(flavor); + switch (flav) { + case FLAV_NS: + if (current_ns_consensus) { + networkstatus_copy_old_consensus_info(c, current_ns_consensus); + networkstatus_vote_free(current_ns_consensus); + } + current_ns_consensus = c; + break; + case FLAV_MICRODESC: + if (current_md_consensus) { + networkstatus_copy_old_consensus_info(c, current_md_consensus); + networkstatus_vote_free(current_md_consensus); + } + current_md_consensus = c; + break; + } + return current_md_consensus ? 0 : -1; +} +#endif //TOR_UNIT_TESTS + /** Try to replace the current cached v3 networkstatus with the one in * <b>consensus</b>. If we don't have enough certificates to validate it, * store it in consensus_waiting_for_certs and launch a certificate fetch. |