mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2025-02-24 22:58:50 +01:00
nodelist: Helper to add an address to the nodelist address set
We separate v4 and v6 because we often use an IPv4 address represented with a uint32_t instead of a tor_addr_t. This will be used to also add the trusted directory addresses taken from the configuration. The trusted directories from the consensus are already added to the address set from their descriptor. Signed-off-by: David Goulet <dgoulet@torproject.org>
This commit is contained in:
parent
872f95ca06
commit
4152c349b4
2 changed files with 28 additions and 5 deletions
|
@ -455,22 +455,43 @@ node_add_to_address_set(const node_t *node)
|
|||
|
||||
if (node->rs) {
|
||||
if (node->rs->addr)
|
||||
address_set_add_ipv4h(the_nodelist->node_addrs, node->rs->addr);
|
||||
nodelist_add_addr4_to_address_set(node->rs->addr);
|
||||
if (!tor_addr_is_null(&node->rs->ipv6_addr))
|
||||
address_set_add(the_nodelist->node_addrs, &node->rs->ipv6_addr);
|
||||
nodelist_add_addr6_to_address_set(&node->rs->ipv6_addr);
|
||||
}
|
||||
if (node->ri) {
|
||||
if (node->ri->addr)
|
||||
address_set_add_ipv4h(the_nodelist->node_addrs, node->ri->addr);
|
||||
nodelist_add_addr4_to_address_set(node->ri->addr);
|
||||
if (!tor_addr_is_null(&node->ri->ipv6_addr))
|
||||
address_set_add(the_nodelist->node_addrs, &node->ri->ipv6_addr);
|
||||
nodelist_add_addr6_to_address_set(&node->ri->ipv6_addr);
|
||||
}
|
||||
if (node->md) {
|
||||
if (!tor_addr_is_null(&node->md->ipv6_addr))
|
||||
address_set_add(the_nodelist->node_addrs, &node->md->ipv6_addr);
|
||||
nodelist_add_addr6_to_address_set(&node->md->ipv6_addr);
|
||||
}
|
||||
}
|
||||
|
||||
/** Add the given v4 address into the nodelist address set. */
|
||||
void
|
||||
nodelist_add_addr4_to_address_set(const uint32_t addr)
|
||||
{
|
||||
if (!the_nodelist || !the_nodelist->node_addrs || addr == 0) {
|
||||
return;
|
||||
}
|
||||
address_set_add_ipv4h(the_nodelist->node_addrs, addr);
|
||||
}
|
||||
|
||||
/** Add the given v6 address into the nodelist address set. */
|
||||
void
|
||||
nodelist_add_addr6_to_address_set(const tor_addr_t *addr)
|
||||
{
|
||||
if (BUG(!addr) || tor_addr_is_null(addr) || tor_addr_is_v4(addr) ||
|
||||
!the_nodelist || !the_nodelist->node_addrs) {
|
||||
return;
|
||||
}
|
||||
address_set_add(the_nodelist->node_addrs, addr);
|
||||
}
|
||||
|
||||
/** Return true if <b>addr</b> is the address of some node in the nodelist.
|
||||
* If not, probably return false. */
|
||||
int
|
||||
|
|
|
@ -35,6 +35,8 @@ node_t *nodelist_add_microdesc(microdesc_t *md);
|
|||
void nodelist_set_consensus(networkstatus_t *ns);
|
||||
void nodelist_ensure_freshness(networkstatus_t *ns);
|
||||
int nodelist_probably_contains_address(const tor_addr_t *addr);
|
||||
void nodelist_add_addr4_to_address_set(const uint32_t addr);
|
||||
void nodelist_add_addr6_to_address_set(const tor_addr_t *addr);
|
||||
|
||||
void nodelist_remove_microdesc(const char *identity_digest, microdesc_t *md);
|
||||
void nodelist_remove_routerinfo(routerinfo_t *ri);
|
||||
|
|
Loading…
Add table
Reference in a new issue