commit 7792be2d446a35ad71d0c67fb762f868ae07b99c
Author: Nick Mathewson <nickm(a)torproject.org>
Date: Wed Jan 24 13:38:01 2018 -0500
Extract code to summarize protocol versions into new function
This will let us put this summary into routerinfo_t too.
No behavior change.
---
src/or/routerparse.c | 93 ++++++++++++++++++++++++++++++++--------------------
1 file changed, 57 insertions(+), 36 deletions(-)
diff --git a/src/or/routerparse.c b/src/or/routerparse.c
index b8f7e166a..1cbbb1728 100644
--- a/src/or/routerparse.c
+++ b/src/or/routerparse.c
@@ -2530,6 +2530,50 @@ routerstatus_parse_guardfraction(const char *guardfraction_str,
return 0;
}
+/** Summarize the protocols listed in <b>protocols</b> into <b>out</b>,
+ * falling back or correcting them based on <b>version</b> as appropriate.
+ */
+static void
+summarize_protover_flags(protover_summary_flags_t *out,
+ const char *protocols,
+ const char *version)
+{
+ tor_assert(out);
+ memset(out, 0, sizeof(*out));
+ if (protocols) {
+ out->protocols_known = 1;
+ out->supports_extend2_cells =
+ protocol_list_supports_protocol(protocols, PRT_RELAY, 2);
+ out->supports_ed25519_link_handshake_compat =
+ protocol_list_supports_protocol(protocols, PRT_LINKAUTH, 3);
+ out->supports_ed25519_link_handshake_any =
+ protocol_list_supports_protocol_or_later(protocols, PRT_LINKAUTH, 3);
+ out->supports_ed25519_hs_intro =
+ protocol_list_supports_protocol(protocols, PRT_HSINTRO, 4);
+ out->supports_v3_hsdir =
+ protocol_list_supports_protocol(protocols, PRT_HSDIR,
+ PROTOVER_HSDIR_V3);
+ out->supports_v3_rendezvous_point =
+ protocol_list_supports_protocol(protocols, PRT_HSDIR,
+ PROTOVER_HS_RENDEZVOUS_POINT_V3);
+ }
+ if (version && !strcmpstart(version, "Tor ")) {
+ if (!out->protocols_known) {
+ /* The version is a "Tor" version, and where there is no
+ * list of protocol versions that we should be looking at instead. */
+
+ out->supports_extend2_cells =
+ tor_version_as_new_as(version, "0.2.4.8-alpha");
+ out->protocols_known = 1;
+ } else {
+ /* Bug #22447 forces us to filter on this version. */
+ if (!tor_version_as_new_as(version, "0.3.0.8")) {
+ out->supports_v3_hsdir = 0;
+ }
+ }
+ }
+}
+
/** Given a string at *<b>s</b>, containing a routerstatus object, and an
* empty smartlist at <b>tokens</b>, parse and return the first router status
* object in the string, and advance *<b>s</b> to just after the end of the
@@ -2695,44 +2739,21 @@ routerstatus_parse_entry_from_string(memarea_t *area,
if (consensus_method >= MIN_METHOD_FOR_EXCLUDING_INVALID_NODES)
rs->is_valid = 1;
}
- int found_protocol_list = 0;
- if ((tok = find_opt_by_keyword(tokens, K_PROTO))) {
- found_protocol_list = 1;
- rs->pv.protocols_known = 1;
- rs->pv.supports_extend2_cells =
- protocol_list_supports_protocol(tok->args[0], PRT_RELAY, 2);
- rs->pv.supports_ed25519_link_handshake_compat =
- protocol_list_supports_protocol(tok->args[0], PRT_LINKAUTH, 3);
- rs->pv.supports_ed25519_link_handshake_any =
- protocol_list_supports_protocol_or_later(tok->args[0], PRT_LINKAUTH, 3);
- rs->pv.supports_ed25519_hs_intro =
- protocol_list_supports_protocol(tok->args[0], PRT_HSINTRO, 4);
- rs->pv.supports_v3_hsdir =
- protocol_list_supports_protocol(tok->args[0], PRT_HSDIR,
- PROTOVER_HSDIR_V3);
- rs->pv.supports_v3_rendezvous_point =
- protocol_list_supports_protocol(tok->args[0], PRT_HSDIR,
- PROTOVER_HS_RENDEZVOUS_POINT_V3);
- }
- if ((tok = find_opt_by_keyword(tokens, K_V))) {
- tor_assert(tok->n_args == 1);
- if (!strcmpstart(tok->args[0], "Tor ") && !found_protocol_list) {
- /* We only do version checks like this in the case where
- * the version is a "Tor" version, and where there is no
- * list of protocol versions that we should be looking at instead. */
- rs->pv.supports_extend2_cells =
- tor_version_as_new_as(tok->args[0], "0.2.4.8-alpha");
- rs->pv.protocols_known = 1;
- }
- if (!strcmpstart(tok->args[0], "Tor ") && found_protocol_list) {
- /* Bug #22447 forces us to filter on this version. */
- if (!tor_version_as_new_as(tok->args[0], "0.3.0.8")) {
- rs->pv.supports_v3_hsdir = 0;
+ {
+ const char *protocols = NULL, *version = NULL;
+ if ((tok = find_opt_by_keyword(tokens, K_PROTO))) {
+ tor_assert(tok->n_args == 1);
+ protocols = tok->args[0];
+ }
+ if ((tok = find_opt_by_keyword(tokens, K_V))) {
+ tor_assert(tok->n_args == 1);
+ version = tok->args[0];
+ if (vote_rs) {
+ vote_rs->version = tor_strdup(tok->args[0]);
}
}
- if (vote_rs) {
- vote_rs->version = tor_strdup(tok->args[0]);
- }
+
+ summarize_protover_flags(&rs->pv, protocols, version);
}
/* handle weighting/bandwidth info */