summaryrefslogtreecommitdiff
path: root/src/or/networkstatus.c
diff options
context:
space:
mode:
authorteor <teor2345@gmail.com>2017-12-02 23:01:07 +1100
committerteor <teor2345@gmail.com>2017-12-11 00:34:19 +1100
commit28d4355a6ebe69c84d0ae31d7a0763f0a17f0151 (patch)
tree8593797ea4d3432d783cd7fca47c04efb9762d60 /src/or/networkstatus.c
parent241b676638285e63bd6e4ca5225444a4b16207be (diff)
downloadtor-28d4355a6ebe69c84d0ae31d7a0763f0a17f0151.tar.gz
tor-28d4355a6ebe69c84d0ae31d7a0763f0a17f0151.zip
Add networkstatus_consensus_has_ipv6() and unit tests
networkstatus_consensus_has_ipv6() tells us whether the consensus method of our current consensus supports IPv6 ORPorts in the consensus. Part of #23827.
Diffstat (limited to 'src/or/networkstatus.c')
-rw-r--r--src/or/networkstatus.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/or/networkstatus.c b/src/or/networkstatus.c
index 2843d06262..61cca1b9b6 100644
--- a/src/or/networkstatus.c
+++ b/src/or/networkstatus.c
@@ -1507,6 +1507,32 @@ networkstatus_consensus_is_already_downloading(const char *resource)
return answer;
}
+/* Does the current, reasonably live consensus have IPv6 addresses?
+ * Returns 1 if there is a reasonably live consensus and its consensus method
+ * includes IPv6 addresses in the consensus.
+ * Otherwise, if there is no consensus, or the method does not include IPv6
+ * addresses, returns 0. */
+int
+networkstatus_consensus_has_ipv6(const or_options_t* options)
+{
+ const networkstatus_t *cons = networkstatus_get_reasonably_live_consensus(
+ approx_time(),
+ usable_consensus_flavor());
+
+ /* If we have no consensus, we have no IPv6 in it */
+ if (!cons) {
+ return 0;
+ }
+
+ /* Different flavours of consensus gained IPv6 at different times */
+ if (we_use_microdescriptors_for_circuits(options)) {
+ return
+ cons->consensus_method >= MIN_METHOD_FOR_A_LINES_IN_MICRODESC_CONSENSUS;
+ } else {
+ return cons->consensus_method >= MIN_METHOD_FOR_A_LINES;
+ }
+}
+
/** Given two router status entries for the same router identity, return 1 if
* if the contents have changed between them. Otherwise, return 0. */
static int