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

[tor-commits] [tor/release-0.4.5] Introduce a new bridge_has_invalid_transport() function.



commit 71fd30b75ad028dfce69563792547f06fdf9d3c2
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date:   Thu Jan 21 13:17:16 2021 -0500

    Introduce a new bridge_has_invalid_transport() function.
    
    In addition to simplifying callsites a little, this function gives
    correct behavior for bridges without a configured transport.
---
 src/feature/client/bridges.c    | 13 ++++++++++++-
 src/feature/client/bridges.h    |  1 +
 src/feature/client/entrynodes.c |  2 +-
 3 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/src/feature/client/bridges.c b/src/feature/client/bridges.c
index 11b2ffd62d..96c3497c6f 100644
--- a/src/feature/client/bridges.c
+++ b/src/feature/client/bridges.c
@@ -175,6 +175,17 @@ bridget_get_transport_name(const bridge_info_t *bridge)
   return bridge->transport_name;
 }
 
+/**
+ * Return true if @a bridge has a transport name for which we don't actually
+ * know a transport.
+ */
+bool
+bridge_has_invalid_transport(const bridge_info_t *bridge)
+{
+  const char *tname = bridget_get_transport_name(bridge);
+  return tname && transport_get_by_name(tname) == NULL;
+}
+
 /** If we have a bridge configured whose digest matches <b>digest</b>, or a
  * bridge with no known digest whose address matches any of the
  * tor_addr_port_t's in <b>orports</b>, return that bridge.  Else return
@@ -656,7 +667,7 @@ launch_direct_bridge_descriptor_fetch(bridge_info_t *bridge)
       DIR_PURPOSE_FETCH_SERVERDESC))
     return; /* it's already on the way */
 
-  if (transport_get_by_name(bridget_get_transport_name(bridge)) == NULL) {
+  if (bridge_has_invalid_transport(bridge)) {
     download_status_mark_impossible(&bridge->fetch_status);
     log_warn(LD_CONFIG, "Can't use bridge at %s: there is no configured "
              "transport called \"%s\".",
diff --git a/src/feature/client/bridges.h b/src/feature/client/bridges.h
index 1b090e8649..f5ecc1b76d 100644
--- a/src/feature/client/bridges.h
+++ b/src/feature/client/bridges.h
@@ -24,6 +24,7 @@ const smartlist_t *bridge_list_get(void);
 const uint8_t *bridge_get_rsa_id_digest(const bridge_info_t *bridge);
 const tor_addr_port_t * bridge_get_addr_port(const bridge_info_t *bridge);
 const char *bridget_get_transport_name(const bridge_info_t *bridge);
+bool bridge_has_invalid_transport(const bridge_info_t *bridge);
 bridge_info_t *get_configured_bridge_by_addr_port_digest(
                                           const tor_addr_t *addr,
                                           uint16_t port,
diff --git a/src/feature/client/entrynodes.c b/src/feature/client/entrynodes.c
index 2676df6aae..232216c521 100644
--- a/src/feature/client/entrynodes.c
+++ b/src/feature/client/entrynodes.c
@@ -804,7 +804,7 @@ get_sampled_guard_for_bridge(guard_selection_t *gs,
   entry_guard_t *guard;
   if (BUG(!addrport))
     return NULL; // LCOV_EXCL_LINE
-  if (!transport_get_by_name(bridget_get_transport_name(bridge))) {
+  if (bridge_has_invalid_transport(bridge)) {
     return NULL;
   }
   guard = get_sampled_guard_by_bridge_addr(gs, addrport);



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