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

[tor-commits] [tor/master] relay: Deciding to fetch from authority, use new find address API



commit 1a347b4790719d6ae1576c0b023dac343b65e5a1
Author: David Goulet <dgoulet@xxxxxxxxxxxxxx>
Date:   Tue Jul 14 12:58:36 2020 -0400

    relay: Deciding to fetch from authority, use new find address API
    
    Use the new relay_has_address_set() interface when deciding if we need to
    fetch directory information from an authority as a relay.
    
    If no IPv4 address is found, we'll proceed with a fetch so we can learn our
    address in the HTTP header or NETINFO cell that a trusted authority will send
    us back.
    
    Related to #40025
    
    Signed-off-by: David Goulet <dgoulet@xxxxxxxxxxxxxx>
---
 src/feature/dirclient/dirclient_modes.c | 12 ++++++++----
 src/feature/relay/relay_find_addr.c     | 11 +++++++++++
 src/feature/relay/relay_find_addr.h     |  2 ++
 3 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/src/feature/dirclient/dirclient_modes.c b/src/feature/dirclient/dirclient_modes.c
index 31a3f8af58..62cdad6c36 100644
--- a/src/feature/dirclient/dirclient_modes.c
+++ b/src/feature/dirclient/dirclient_modes.c
@@ -40,15 +40,19 @@ int
 dirclient_fetches_from_authorities(const or_options_t *options)
 {
   const routerinfo_t *me;
-  uint32_t addr;
   int refuseunknown;
   if (options->FetchDirInfoEarly)
     return 1;
   if (options->BridgeRelay == 1)
     return 0;
-  if (server_mode(options) &&
-      router_pick_published_address(options, &addr, 1) < 0)
-    return 1; /* we don't know our IP address; ask an authority. */
+  /* We don't know our IP address; ask an authority. IPv4 is still mandatory
+   * to have thus if we don't have it, we ought to learn it from an authority
+   * through the NETINFO cell or the HTTP header it sends us back.
+   *
+   * Note that at the moment, relay do a direct connection so no NETINFO cell
+   * for now. */
+  if (server_mode(options) && !relay_has_address_set(AF_INET))
+    return 1;
   refuseunknown = ! router_my_exit_policy_is_reject_star() &&
     should_refuse_unknown_exits(options);
   if (!dir_server_mode(options) && !refuseunknown)
diff --git a/src/feature/relay/relay_find_addr.c b/src/feature/relay/relay_find_addr.c
index dabf985751..d685145934 100644
--- a/src/feature/relay/relay_find_addr.c
+++ b/src/feature/relay/relay_find_addr.c
@@ -254,3 +254,14 @@ router_pick_published_address, (const or_options_t *options, uint32_t *addr,
   /* We have no useful cached answers. Return failure. */
   return -1;
 }
+
+/** Return true iff this relay has an address set for the given family.
+ *
+ * This only checks the caches so it will not trigger a full discovery of the
+ * address. */
+bool
+relay_has_address_set(int family)
+{
+  tor_addr_t addr;
+  return relay_find_addr_to_publish(get_options(), family, 1, &addr);
+}
diff --git a/src/feature/relay/relay_find_addr.h b/src/feature/relay/relay_find_addr.h
index e28ceb933a..399ac8dc44 100644
--- a/src/feature/relay/relay_find_addr.h
+++ b/src/feature/relay/relay_find_addr.h
@@ -22,6 +22,8 @@ void relay_address_new_suggestion(const tor_addr_t *suggested_addr,
 bool relay_find_addr_to_publish(const or_options_t *options, int family,
                                 bool cache_only, tor_addr_t *addr_out);
 
+bool relay_has_address_set(int family);
+
 #ifdef RELAY_FIND_ADDR_PRIVATE
 
 #endif /* RELAY_FIND_ADDR_PRIVATE */



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