aboutsummaryrefslogtreecommitdiff
path: root/src/or/networkstatus.c
diff options
context:
space:
mode:
authorMatthew Finkel <Matthew.Finkel@gmail.com>2015-01-26 19:49:48 +0000
committerNick Mathewson <nickm@torproject.org>2015-12-18 13:14:09 -0500
commite0bd6cdef25d7cdcff18d2bce7865aa7acc1f2b8 (patch)
tree2c4025a5d024781c2f4ef1d572dd739664957af1 /src/or/networkstatus.c
parent0a7d22a664505c5235031fc2d3d792b83254b5ad (diff)
downloadtor-e0bd6cdef25d7cdcff18d2bce7865aa7acc1f2b8.tar.gz
tor-e0bd6cdef25d7cdcff18d2bce7865aa7acc1f2b8.zip
Add unit test for router_pick_directory_server_impl
Diffstat (limited to 'src/or/networkstatus.c')
-rw-r--r--src/or/networkstatus.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/or/networkstatus.c b/src/or/networkstatus.c
index 173c109d60..076a2c4116 100644
--- a/src/or/networkstatus.c
+++ b/src/or/networkstatus.c
@@ -1457,6 +1457,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.