aboutsummaryrefslogtreecommitdiff
path: root/src/app/config/resolve_addr.c
diff options
context:
space:
mode:
authorDavid Goulet <dgoulet@torproject.org>2020-07-06 09:42:10 -0400
committerDavid Goulet <dgoulet@torproject.org>2020-07-07 10:41:10 -0400
commit192d367b411019760f92f58adde7592476341d6b (patch)
tree19a56865b81a4bc6ee41cd6d652059531bc427fa /src/app/config/resolve_addr.c
parentf57ce632fe3d391e62d288c0b8acd0001bf670df (diff)
downloadtor-192d367b411019760f92f58adde7592476341d6b.tar.gz
tor-192d367b411019760f92f58adde7592476341d6b.zip
addr: New function relay_address_new_suggestion()
This behaves like router_new_address_suggestion() but differs in couple of ways: 1. It takes a tor_addr_t instead of an address string and supports both AF_INET and AF_INET6. 2. It does _not_ use the last_guessed_ip local cache and instead only relies on the last resolved address cache in resolve_addr.c It is not used at this commit. This function is made to process a suggested address found in a NETINFO cell exactly like router_new_address_suggestion() does with the address a directory suggests us. Related to #40022 Signed-off-by: David Goulet <dgoulet@torproject.org>
Diffstat (limited to 'src/app/config/resolve_addr.c')
-rw-r--r--src/app/config/resolve_addr.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/app/config/resolve_addr.c b/src/app/config/resolve_addr.c
index 2a11ba3c00..75b5eb75b1 100644
--- a/src/app/config/resolve_addr.c
+++ b/src/app/config/resolve_addr.c
@@ -44,6 +44,12 @@ typedef enum {
/** Last resolved addresses. */
static tor_addr_t last_resolved_addrs[IDX_SIZE];
+/** Last suggested addresses.
+ *
+ * These addresses come from a NETINFO cell from a trusted relay (currently
+ * only authorities). We only use those in last resort. */
+static tor_addr_t last_suggested_addrs[IDX_SIZE];
+
static inline int
af_to_idx(const int family)
{
@@ -60,6 +66,29 @@ af_to_idx(const int family)
}
}
+/** Copy the last suggested address of family into addr_out.
+ *
+ * If no last suggested address exists, the addr_out is a null address (use
+ * tor_addr_is_null() to confirm). */
+void
+resolved_addr_get_suggested(int family, tor_addr_t *addr_out)
+{
+ tor_addr_copy(addr_out, &last_suggested_addrs[af_to_idx(family)]);
+}
+
+/** Set the last suggested address into our cache. This is called when we get
+ * a new NETINFO cell from a trusted source. */
+void
+resolved_addr_set_suggested(const tor_addr_t *addr)
+{
+ if (BUG(tor_addr_family(addr) != AF_INET ||
+ tor_addr_family(addr) != AF_INET6)) {
+ return;
+ }
+ tor_addr_copy(&last_suggested_addrs[af_to_idx(tor_addr_family(addr))],
+ addr);
+}
+
/** Copy the last resolved address of family into addr_out.
*
* If not last resolved address existed, the addr_out is a null address (use