[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] relay: Add a cache that tracks which address was configured



commit fda0fa02bfcf2faef4a973d24877dc7966f6d428
Author: David Goulet <dgoulet@xxxxxxxxxxxxxx>
Date:   Fri Jul 24 09:19:49 2020 -0400

    relay: Add a cache that tracks which address was configured
    
    Related to #33247
    
    Signed-off-by: David Goulet <dgoulet@xxxxxxxxxxxxxx>
---
 src/app/config/resolve_addr.c | 24 ++++++++++++++++++++++++
 src/app/config/resolve_addr.h |  2 ++
 2 files changed, 26 insertions(+)

diff --git a/src/app/config/resolve_addr.c b/src/app/config/resolve_addr.c
index a9db2655c1..a153d63974 100644
--- a/src/app/config/resolve_addr.c
+++ b/src/app/config/resolve_addr.c
@@ -55,6 +55,11 @@ static tor_addr_t last_suggested_addrs[] =
   { TOR_ADDR_NULL, TOR_ADDR_NULL, TOR_ADDR_NULL };
 CTASSERT(ARRAY_LENGTH(last_suggested_addrs) == IDX_SIZE);
 
+/** True iff the address was found to be configured that is from the
+ * configuration file either using Address or ORPort. */
+static bool last_addrs_configured[] = { false, false, false };
+CTASSERT(ARRAY_LENGTH(last_addrs_configured) == IDX_SIZE);
+
 static inline int
 af_to_idx(const int family)
 {
@@ -94,6 +99,18 @@ resolved_addr_method_to_str(const resolved_addr_method_t method)
   }
 }
 
+/** Return true if the last address of family was configured or not. An
+ * address is considered configured if it was found in the Address or ORPort
+ * statement.
+ *
+ * This applies to the address returned by the function
+ * resolved_addr_get_last() which is the cache of discovered addresses. */
+bool
+resolved_addr_is_configured(int family)
+{
+  return last_addrs_configured[af_to_idx(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
@@ -565,6 +582,13 @@ resolved_addr_set_last(const tor_addr_t *addr,
   /* Copy address to cache. */
   tor_addr_copy(last_resolved, addr);
   *done_one_resolve = true;
+
+  /* Flag true if the address was configured. Else, indicate it was not. */
+  last_addrs_configured[idx] = false;
+  if (method_used == RESOLVED_ADDR_CONFIGURED ||
+      method_used == RESOLVED_ADDR_CONFIGURED_ORPORT) {
+    last_addrs_configured[idx] = true;
+  }
 }
 
 /** Ease our lives. Typedef to the address discovery function signature. */
diff --git a/src/app/config/resolve_addr.h b/src/app/config/resolve_addr.h
index f435f9f41f..96c86eeeea 100644
--- a/src/app/config/resolve_addr.h
+++ b/src/app/config/resolve_addr.h
@@ -49,6 +49,8 @@ void resolved_addr_set_last(const tor_addr_t *addr,
 void resolved_addr_get_suggested(int family, tor_addr_t *addr_out);
 void resolved_addr_set_suggested(const tor_addr_t *addr);
 
+bool resolved_addr_is_configured(int family);
+
 MOCK_DECL(bool, is_local_to_resolve_addr, (const tor_addr_t *addr));
 
 #ifdef RESOLVE_ADDR_PRIVATE



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits