Extract protover summary flags into a new structure

This will let us use them on routerinfo_t as well as on
routerstatus_t, and save some time on relays.

No behavioral changes here.
This commit is contained in:
Nick Mathewson
2018-01-24 13:26:50 -05:00
parent fd8ee1d7c3
commit d9fbd34f42
5 changed files with 59 additions and 51 deletions
+8 -8
View File
@@ -447,7 +447,7 @@ nodelist_set_routerinfo(routerinfo_t *ri, routerinfo_t **ri_old_out)
/* Setting the HSDir index requires the ed25519 identity key which can
* only be found either in the ri or md. This is why this is called here.
* Only nodes supporting HSDir=2 protocol version needs this index. */
if (node->rs && node->rs->supports_v3_hsdir) {
if (node->rs && node->rs->pv.supports_v3_hsdir) {
node_set_hsdir_index(node,
networkstatus_get_latest_consensus());
}
@@ -487,7 +487,7 @@ nodelist_add_microdesc(microdesc_t *md)
/* Setting the HSDir index requires the ed25519 identity key which can
* only be found either in the ri or md. This is why this is called here.
* Only nodes supporting HSDir=2 protocol version needs this index. */
if (rs->supports_v3_hsdir) {
if (rs->pv.supports_v3_hsdir) {
node_set_hsdir_index(node, ns);
}
node_add_to_ed25519_map(node);
@@ -531,7 +531,7 @@ nodelist_set_consensus(networkstatus_t *ns)
}
}
if (rs->supports_v3_hsdir) {
if (rs->pv.supports_v3_hsdir) {
node_set_hsdir_index(node, ns);
}
node_set_country(node);
@@ -980,9 +980,9 @@ node_supports_ed25519_link_authentication(const node_t *node,
}
if (node->rs) {
if (compatible_with_us)
return node->rs->supports_ed25519_link_handshake_compat;
return node->rs->pv.supports_ed25519_link_handshake_compat;
else
return node->rs->supports_ed25519_link_handshake_any;
return node->rs->pv.supports_ed25519_link_handshake_any;
}
tor_assert_nonfatal_unreached_once();
return 0;
@@ -996,7 +996,7 @@ node_supports_v3_hsdir(const node_t *node)
tor_assert(node);
if (node->rs) {
return node->rs->supports_v3_hsdir;
return node->rs->pv.supports_v3_hsdir;
}
if (node->ri) {
if (node->ri->protocol_list == NULL) {
@@ -1026,7 +1026,7 @@ node_supports_ed25519_hs_intro(const node_t *node)
tor_assert(node);
if (node->rs) {
return node->rs->supports_ed25519_hs_intro;
return node->rs->pv.supports_ed25519_hs_intro;
}
if (node->ri) {
if (node->ri->protocol_list == NULL) {
@@ -1047,7 +1047,7 @@ node_supports_v3_rendezvous_point(const node_t *node)
tor_assert(node);
if (node->rs) {
return node->rs->supports_v3_rendezvous_point;
return node->rs->pv.supports_v3_rendezvous_point;
}
if (node->ri) {
if (node->ri->protocol_list == NULL) {
+38 -30
View File
@@ -2196,6 +2196,41 @@ typedef struct signed_descriptor_t {
/** A signed integer representing a country code. */
typedef int16_t country_t;
/** Flags used to summarize the declared protocol versions of a relay,
* so we don't need to parse them again and again. */
typedef struct protover_summary_flags_t {
/** True iff we have a proto line for this router, or a versions line
* from which we could infer the protocols. */
unsigned int protocols_known:1;
/** True iff this router has a version or protocol list that allows it to
* accept EXTEND2 cells */
unsigned int supports_extend2_cells:1;
/** True iff this router has a protocol list that allows it to negotiate
* ed25519 identity keys on a link handshake with us. */
unsigned int supports_ed25519_link_handshake_compat:1;
/** True iff this router has a protocol list that allows it to negotiate
* ed25519 identity keys on a link handshake, at all. */
unsigned int supports_ed25519_link_handshake_any:1;
/** True iff this router has a protocol list that allows it to be an
* introduction point supporting ed25519 authentication key which is part of
* the v3 protocol detailed in proposal 224. This requires HSIntro=4. */
unsigned int supports_ed25519_hs_intro : 1;
/** True iff this router has a protocol list that allows it to be an hidden
* service directory supporting version 3 as seen in proposal 224. This
* requires HSDir=2. */
unsigned int supports_v3_hsdir : 1;
/** True iff this router has a protocol list that allows it to be an hidden
* service rendezvous point supporting version 3 as seen in proposal 224.
* This requires HSRend=2. */
unsigned int supports_v3_rendezvous_point: 1;
} protover_summary_flags_t;
/** Information about another onion router in the network. */
typedef struct {
signed_descriptor_t cache_info;
@@ -2342,42 +2377,15 @@ typedef struct routerstatus_t {
unsigned int is_v2_dir:1; /** True iff this router publishes an open DirPort
* or it claims to accept tunnelled dir requests.
*/
/** True iff we have a proto line for this router, or a versions line
* from which we could infer the protocols. */
unsigned int protocols_known:1;
/** True iff this router has a version or protocol list that allows it to
* accept EXTEND2 cells */
unsigned int supports_extend2_cells:1;
/** True iff this router has a protocol list that allows it to negotiate
* ed25519 identity keys on a link handshake with us. */
unsigned int supports_ed25519_link_handshake_compat:1;
/** True iff this router has a protocol list that allows it to negotiate
* ed25519 identity keys on a link handshake, at all. */
unsigned int supports_ed25519_link_handshake_any:1;
/** True iff this router has a protocol list that allows it to be an
* introduction point supporting ed25519 authentication key which is part of
* the v3 protocol detailed in proposal 224. This requires HSIntro=4. */
unsigned int supports_ed25519_hs_intro : 1;
/** True iff this router has a protocol list that allows it to be an hidden
* service directory supporting version 3 as seen in proposal 224. This
* requires HSDir=2. */
unsigned int supports_v3_hsdir : 1;
/** True iff this router has a protocol list that allows it to be an hidden
* service rendezvous point supporting version 3 as seen in proposal 224.
* This requires HSRend=2. */
unsigned int supports_v3_rendezvous_point: 1;
unsigned int has_bandwidth:1; /**< The vote/consensus had bw info */
unsigned int has_exitsummary:1; /**< The vote/consensus had exit summaries */
unsigned int bw_is_unmeasured:1; /**< This is a consensus entry, with
* the Unmeasured flag set. */
/** Flags to summarize the protocol versions for this routerstatus_t. */
protover_summary_flags_t pv;
uint32_t bandwidth_kb; /**< Bandwidth (capacity) of the router as reported in
* the vote/consensus, in kilobytes/sec. */
+2 -2
View File
@@ -5665,11 +5665,11 @@ routerstatus_version_supports_extend2_cells(const routerstatus_t *rs,
return allow_unknown_versions;
}
if (!rs->protocols_known) {
if (!rs->pv.protocols_known) {
return allow_unknown_versions;
}
return rs->supports_extend2_cells;
return rs->pv.supports_extend2_cells;
}
/** Assert that the internal representation of <b>rl</b> is
+10 -10
View File
@@ -2698,19 +2698,19 @@ routerstatus_parse_entry_from_string(memarea_t *area,
int found_protocol_list = 0;
if ((tok = find_opt_by_keyword(tokens, K_PROTO))) {
found_protocol_list = 1;
rs->protocols_known = 1;
rs->supports_extend2_cells =
rs->pv.protocols_known = 1;
rs->pv.supports_extend2_cells =
protocol_list_supports_protocol(tok->args[0], PRT_RELAY, 2);
rs->supports_ed25519_link_handshake_compat =
rs->pv.supports_ed25519_link_handshake_compat =
protocol_list_supports_protocol(tok->args[0], PRT_LINKAUTH, 3);
rs->supports_ed25519_link_handshake_any =
rs->pv.supports_ed25519_link_handshake_any =
protocol_list_supports_protocol_or_later(tok->args[0], PRT_LINKAUTH, 3);
rs->supports_ed25519_hs_intro =
rs->pv.supports_ed25519_hs_intro =
protocol_list_supports_protocol(tok->args[0], PRT_HSINTRO, 4);
rs->supports_v3_hsdir =
rs->pv.supports_v3_hsdir =
protocol_list_supports_protocol(tok->args[0], PRT_HSDIR,
PROTOVER_HSDIR_V3);
rs->supports_v3_rendezvous_point =
rs->pv.supports_v3_rendezvous_point =
protocol_list_supports_protocol(tok->args[0], PRT_HSDIR,
PROTOVER_HS_RENDEZVOUS_POINT_V3);
}
@@ -2720,14 +2720,14 @@ routerstatus_parse_entry_from_string(memarea_t *area,
/* 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->supports_extend2_cells =
rs->pv.supports_extend2_cells =
tor_version_as_new_as(tok->args[0], "0.2.4.8-alpha");
rs->protocols_known = 1;
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->supports_v3_hsdir = 0;
rs->pv.supports_v3_hsdir = 0;
}
}
if (vote_rs) {
+1 -1
View File
@@ -289,7 +289,7 @@ helper_add_hsdir_to_networkstatus(networkstatus_t *ns,
memcpy(rs->identity_digest, identity, DIGEST_LEN);
rs->is_hs_dir = is_hsdir;
rs->supports_v3_hsdir = 1;
rs->pv.supports_v3_hsdir = 1;
strlcpy(rs->nickname, nickname, sizeof(rs->nickname));
tor_addr_parse(&ipv4_addr, "1.2.3.4");
ri->addr = tor_addr_to_ipv4h(&ipv4_addr);