dirlist: Add configured trusted dir to the nodelist address set

The configured, within the torrc or hardcoded, directory authorities addresses
are now added to the nodelist address set.

Signed-off-by: David Goulet <dgoulet@torproject.org>
This commit is contained in:
David Goulet 2020-01-28 09:26:28 -05:00
parent 4152c349b4
commit bd4f4cb5f0
3 changed files with 42 additions and 3 deletions

View File

@ -49,6 +49,37 @@ static smartlist_t *trusted_dir_servers = NULL;
* and all fallback directory servers. */ * and all fallback directory servers. */
static smartlist_t *fallback_dir_servers = NULL; static smartlist_t *fallback_dir_servers = NULL;
/** Helper: From a given trusted directory entry, add the v4 or/and v6 address
* to the nodelist address set. */
static void
add_trusted_dir_to_nodelist_addr_set(const dir_server_t *dir)
{
tor_assert(dir);
tor_assert(dir->is_authority);
/* Add IPv4 and then IPv6 if applicable. */
nodelist_add_addr4_to_address_set(dir->addr);
if (!tor_addr_is_null(&dir->ipv6_addr)) {
nodelist_add_addr6_to_address_set(&dir->ipv6_addr);
}
}
/** Go over the trusted directory server list and add their address(es) to the
* nodelist address set. This is called everytime a new consensus is set. */
void
dirlist_add_trusted_addresses(void)
{
if (!trusted_dir_servers) {
return;
}
SMARTLIST_FOREACH_BEGIN(trusted_dir_servers, const dir_server_t *, ent) {
if (ent->is_authority) {
add_trusted_dir_to_nodelist_addr_set(ent);
}
} SMARTLIST_FOREACH_END(ent);
}
/** Return the number of directory authorities whose type matches some bit set /** Return the number of directory authorities whose type matches some bit set
* in <b>type</b> */ * in <b>type</b> */
int int

View File

@ -44,4 +44,6 @@ void dir_server_add(dir_server_t *ent);
void clear_dir_servers(void); void clear_dir_servers(void);
void dirlist_free_all(void); void dirlist_free_all(void);
void dirlist_add_trusted_addresses(void);
#endif /* !defined(TOR_DIRLIST_H) */ #endif /* !defined(TOR_DIRLIST_H) */

View File

@ -633,9 +633,12 @@ nodelist_set_consensus(networkstatus_t *ns)
SMARTLIST_FOREACH(the_nodelist->nodes, node_t *, node, SMARTLIST_FOREACH(the_nodelist->nodes, node_t *, node,
node->rs = NULL); node->rs = NULL);
/* Conservatively estimate that every node will have 2 addresses. */ /* Conservatively estimate that every node will have 2 addresses (v4 and
const int estimated_addresses = smartlist_len(ns->routerstatus_list) * * v6). Then we add the number of configured trusted authorities we have. */
int estimated_addresses = smartlist_len(ns->routerstatus_list) *
get_estimated_address_per_node(); get_estimated_address_per_node();
estimated_addresses += (get_n_authorities(V3_DIRINFO & BRIDGE_DIRINFO) *
get_estimated_address_per_node());
address_set_free(the_nodelist->node_addrs); address_set_free(the_nodelist->node_addrs);
the_nodelist->node_addrs = address_set_new(estimated_addresses); the_nodelist->node_addrs = address_set_new(estimated_addresses);
@ -686,6 +689,9 @@ nodelist_set_consensus(networkstatus_t *ns)
SMARTLIST_FOREACH_BEGIN(the_nodelist->nodes, node_t *, node) { SMARTLIST_FOREACH_BEGIN(the_nodelist->nodes, node_t *, node) {
node_add_to_address_set(node); node_add_to_address_set(node);
} SMARTLIST_FOREACH_END(node); } SMARTLIST_FOREACH_END(node);
/* Then, add all trusted configured directories. Some might not be in the
* consensus so make sure we know them. */
dirlist_add_trusted_addresses();
if (! authdir) { if (! authdir) {
SMARTLIST_FOREACH_BEGIN(the_nodelist->nodes, node_t *, node) { SMARTLIST_FOREACH_BEGIN(the_nodelist->nodes, node_t *, node) {