Commit bd4f4cb5 authored by David Goulet's avatar David Goulet 🆘
Browse files

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's avatarDavid Goulet <dgoulet@torproject.org>
parent 4152c349
......@@ -49,6 +49,37 @@ static smartlist_t *trusted_dir_servers = NULL;
* and all fallback directory servers. */
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
* in <b>type</b> */
int
......
......@@ -44,4 +44,6 @@ void dir_server_add(dir_server_t *ent);
void clear_dir_servers(void);
void dirlist_free_all(void);
void dirlist_add_trusted_addresses(void);
#endif /* !defined(TOR_DIRLIST_H) */
......@@ -633,9 +633,12 @@ nodelist_set_consensus(networkstatus_t *ns)
SMARTLIST_FOREACH(the_nodelist->nodes, node_t *, node,
node->rs = NULL);
/* Conservatively estimate that every node will have 2 addresses. */
const int estimated_addresses = smartlist_len(ns->routerstatus_list) *
get_estimated_address_per_node();
/* Conservatively estimate that every node will have 2 addresses (v4 and
* 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();
estimated_addresses += (get_n_authorities(V3_DIRINFO & BRIDGE_DIRINFO) *
get_estimated_address_per_node());
address_set_free(the_nodelist->node_addrs);
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) {
node_add_to_address_set(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) {
SMARTLIST_FOREACH_BEGIN(the_nodelist->nodes, node_t *, node) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment