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

[tor-commits] [tor/master] Rename router_get_advertised_*() functions.



commit 088100d698d24d77a02675c23a553d6fe7da9c16
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date:   Tue Jul 21 12:59:03 2020 -0400

    Rename router_get_advertised_*() functions.
    
    These now (or_port and dir_port) now have "find" names, since they
    look at the portcfg first, then at the actual ports from the
    listeners.
    
    This is an automated commit, generated by this command:
    
    ./scripts/maint/rename_c_identifier.py \
            router_get_advertised_or_port routerconf_find_or_port \
            router_get_advertised_ipv6_or_ap routerconf_find_ipv6_or_ap \
            router_has_advertised_ipv6_orport routerconf_has_ipv6_orport \
            router_get_advertised_dir_port routerconf_find_dir_port
---
 src/core/mainloop/connection.c | 12 ++++++------
 src/feature/dirauth/dirvote.c  |  4 ++--
 src/feature/relay/router.c     | 34 +++++++++++++++++-----------------
 src/feature/relay/router.h     |  8 ++++----
 src/test/test_router.c         | 34 +++++++++++++++++-----------------
 5 files changed, 46 insertions(+), 46 deletions(-)

diff --git a/src/core/mainloop/connection.c b/src/core/mainloop/connection.c
index 0fc5e6a88b..efde9df7ed 100644
--- a/src/core/mainloop/connection.c
+++ b/src/core/mainloop/connection.c
@@ -3168,10 +3168,10 @@ retry_all_listeners(smartlist_t *new_conns, int close_all_noncontrol)
   smartlist_t *replacements = smartlist_new();
   const or_options_t *options = get_options();
   int retval = 0;
-  const uint16_t old_or_port = router_get_advertised_or_port(options, AF_INET);
+  const uint16_t old_or_port = routerconf_find_or_port(options, AF_INET);
   const uint16_t old_or_port_ipv6 =
-    router_get_advertised_or_port(options,AF_INET6);
-  const uint16_t old_dir_port = router_get_advertised_dir_port(options, 0);
+    routerconf_find_or_port(options,AF_INET6);
+  const uint16_t old_dir_port = routerconf_find_dir_port(options, 0);
 
   SMARTLIST_FOREACH_BEGIN(get_connection_array(), connection_t *, conn) {
     if (connection_is_listener(conn) && !conn->marked_for_close)
@@ -3241,9 +3241,9 @@ retry_all_listeners(smartlist_t *new_conns, int close_all_noncontrol)
   SMARTLIST_FOREACH(replacements, listener_replacement_t *, r, tor_free(r));
   smartlist_free(replacements);
 
-  if (old_or_port != router_get_advertised_or_port(options, AF_INET) ||
-      old_or_port_ipv6 != router_get_advertised_or_port(options, AF_INET6) ||
-      old_dir_port != router_get_advertised_dir_port(options, 0)) {
+  if (old_or_port != routerconf_find_or_port(options, AF_INET) ||
+      old_or_port_ipv6 != routerconf_find_or_port(options, AF_INET6) ||
+      old_dir_port != routerconf_find_dir_port(options, 0)) {
     /* Our chosen ORPort or DirPort is not what it used to be: the
      * descriptor we had (if any) should be regenerated.  (We won't
      * automatically notice this because of changes in the option,
diff --git a/src/feature/dirauth/dirvote.c b/src/feature/dirauth/dirvote.c
index b0583a42f7..c3ab6fae15 100644
--- a/src/feature/dirauth/dirvote.c
+++ b/src/feature/dirauth/dirvote.c
@@ -4724,8 +4724,8 @@ dirserv_generate_networkstatus_vote_obj(crypto_pk_t *private_key,
   voter->sigs = smartlist_new();
   voter->address = hostname;
   tor_addr_copy(&voter->ipv4_addr, &addr);
-  voter->ipv4_dirport = router_get_advertised_dir_port(options, 0);
-  voter->ipv4_orport = router_get_advertised_or_port(options, AF_INET);
+  voter->ipv4_dirport = routerconf_find_dir_port(options, 0);
+  voter->ipv4_orport = routerconf_find_or_port(options, AF_INET);
   voter->contact = tor_strdup(contact);
   if (options->V3AuthUseLegacyKey) {
     authority_cert_t *c = get_my_v3_legacy_cert();
diff --git a/src/feature/relay/router.c b/src/feature/relay/router.c
index 0f85db44d5..997be643dc 100644
--- a/src/feature/relay/router.c
+++ b/src/feature/relay/router.c
@@ -1151,10 +1151,10 @@ init_keys(void)
   ds = router_get_trusteddirserver_by_digest(digest);
   if (!ds) {
     tor_addr_port_t ipv6_orport;
-    router_get_advertised_ipv6_or_ap(options, &ipv6_orport);
+    routerconf_find_ipv6_or_ap(options, &ipv6_orport);
     ds = trusted_dir_server_new(options->Nickname, NULL,
-                                router_get_advertised_dir_port(options, 0),
-                                router_get_advertised_or_port(options,AF_INET),
+                                routerconf_find_dir_port(options, 0),
+                                routerconf_find_or_port(options,AF_INET),
                                 &ipv6_orport,
                                 digest,
                                 v3_digest,
@@ -1306,10 +1306,10 @@ decide_to_advertise_dir_impl(const or_options_t *options,
     return 1;
   if (net_is_disabled())
     return 0;
-  if (dir_port && !router_get_advertised_dir_port(options, dir_port))
+  if (dir_port && !routerconf_find_dir_port(options, dir_port))
     return 0;
   if (supports_tunnelled_dir_requests &&
-      !router_get_advertised_or_port(options, AF_INET))
+      !routerconf_find_or_port(options, AF_INET))
     return 0;
 
   /* Part two: consider config options that could make us choose to
@@ -1390,7 +1390,7 @@ decide_if_publishable_server(void)
     return 0;
   if (authdir_mode(options))
     return 1;
-  if (!router_get_advertised_or_port(options, AF_INET))
+  if (!routerconf_find_or_port(options, AF_INET))
     return 0;
   if (!router_orport_seems_reachable(options, AF_INET)) {
     // We have an ipv4 orport, and it doesn't seem reachable.
@@ -1463,7 +1463,7 @@ router_get_active_listener_port_by_type_af(int listener_type,
  * family; this is either the one configured in the ORPort option, or the one
  * we actually bound to if ORPort is "auto". Returns 0 if no port is found. */
 uint16_t
-router_get_advertised_or_port(const or_options_t *options,
+routerconf_find_or_port(const or_options_t *options,
                               sa_family_t family)
 {
   int port = portconf_get_first_advertised_port(CONN_TYPE_OR_LISTENER,
@@ -1479,11 +1479,11 @@ router_get_advertised_or_port(const or_options_t *options,
   return port;
 }
 
-/** As router_get_advertised_or_port(), but returns the IPv6 address and
+/** As routerconf_find_or_port(), but returns the IPv6 address and
  *  port in ipv6_ap_out, which must not be NULL. Returns a null address and
  * zero port, if no ORPort is found. */
 void
-router_get_advertised_ipv6_or_ap(const or_options_t *options,
+routerconf_find_ipv6_or_ap(const or_options_t *options,
                                  tor_addr_port_t *ipv6_ap_out)
 {
   /* Bug in calling function, we can't return a sensible result, and it
@@ -1497,7 +1497,7 @@ router_get_advertised_ipv6_or_ap(const or_options_t *options,
   const tor_addr_t *addr = portconf_get_first_advertised_addr(
                                                       CONN_TYPE_OR_LISTENER,
                                                       AF_INET6);
-  const uint16_t port = router_get_advertised_or_port(options,
+  const uint16_t port = routerconf_find_or_port(options,
                                                       AF_INET6);
 
   if (!addr || port == 0) {
@@ -1524,10 +1524,10 @@ router_get_advertised_ipv6_or_ap(const or_options_t *options,
 
 /** Returns true if this router has an advertised IPv6 ORPort. */
 bool
-router_has_advertised_ipv6_orport(const or_options_t *options)
+routerconf_has_ipv6_orport(const or_options_t *options)
 {
   tor_addr_port_t ipv6_ap;
-  router_get_advertised_ipv6_or_ap(options, &ipv6_ap);
+  routerconf_find_ipv6_or_ap(options, &ipv6_ap);
   return tor_addr_port_is_valid_ap(&ipv6_ap, 0);
 }
 
@@ -1552,7 +1552,7 @@ router_can_extend_over_ipv6,(const or_options_t *options))
 {
   /* We might add some extra checks here, such as ExtendAllowIPv6Addresses
   * from ticket 33818. */
-  return router_has_advertised_ipv6_orport(options);
+  return routerconf_has_ipv6_orport(options);
 }
 
 /** Return the port that we should advertise as our DirPort;
@@ -1561,7 +1561,7 @@ router_can_extend_over_ipv6,(const or_options_t *options))
  * the one configured in the DirPort option,
  * or the one we actually bound to if DirPort is "auto". */
 uint16_t
-router_get_advertised_dir_port(const or_options_t *options, uint16_t dirport)
+routerconf_find_dir_port(const or_options_t *options, uint16_t dirport)
 {
   int dirport_configured = portconf_get_primary_dir_port();
   (void)options;
@@ -2056,13 +2056,13 @@ router_build_fresh_unsigned_routerinfo,(routerinfo_t **ri_out))
 
   /* IPv4. */
   tor_addr_copy(&ri->ipv4_addr, &ipv4_addr);
-  ri->ipv4_orport = router_get_advertised_or_port(options, AF_INET);
-  ri->ipv4_dirport = router_get_advertised_dir_port(options, 0);
+  ri->ipv4_orport = routerconf_find_or_port(options, AF_INET);
+  ri->ipv4_dirport = routerconf_find_dir_port(options, 0);
 
   /* IPv6. Do not publish an IPv6 if we don't have an ORPort that can be used
    * with the address. This is possible for instance if the ORPort is
    * IPv4Only. */
-  ipv6_orport = router_get_advertised_or_port(options, AF_INET6);
+  ipv6_orport = routerconf_find_or_port(options, AF_INET6);
   if (have_v6 && ipv6_orport != 0) {
     tor_addr_copy(&ri->ipv6_addr, &ipv6_addr);
     ri->ipv6_orport = ipv6_orport;
diff --git a/src/feature/relay/router.h b/src/feature/relay/router.h
index e53f1dd3e2..c4e9af039f 100644
--- a/src/feature/relay/router.h
+++ b/src/feature/relay/router.h
@@ -65,13 +65,13 @@ int init_keys_client(void);
 
 uint16_t router_get_active_listener_port_by_type_af(int listener_type,
                                                     sa_family_t family);
-void router_get_advertised_ipv6_or_ap(const or_options_t *options,
+void routerconf_find_ipv6_or_ap(const or_options_t *options,
                                       tor_addr_port_t *ipv6_ap_out);
-bool router_has_advertised_ipv6_orport(const or_options_t *options);
+bool routerconf_has_ipv6_orport(const or_options_t *options);
 MOCK_DECL(bool, router_can_extend_over_ipv6,(const or_options_t *options));
-uint16_t router_get_advertised_or_port(const or_options_t *options,
+uint16_t routerconf_find_or_port(const or_options_t *options,
                                        sa_family_t family);
-uint16_t router_get_advertised_dir_port(const or_options_t *options,
+uint16_t routerconf_find_dir_port(const or_options_t *options,
                                         uint16_t dirport);
 
 int router_should_advertise_dirport(const or_options_t *options,
diff --git a/src/test/test_router.c b/src/test/test_router.c
index d87f9f8acf..ddd043b941 100644
--- a/src/test/test_router.c
+++ b/src/test/test_router.c
@@ -507,12 +507,12 @@ test_router_get_advertised_or_port(void *arg)
   listener_connection_t *listener = NULL;
   tor_addr_port_t ipv6;
 
-  // Test one failing case of router_get_advertised_ipv6_or_ap().
-  router_get_advertised_ipv6_or_ap(opts, &ipv6);
+  // Test one failing case of routerconf_find_ipv6_or_ap().
+  routerconf_find_ipv6_or_ap(opts, &ipv6);
   tt_str_op(fmt_addrport(&ipv6.addr, ipv6.port), OP_EQ, "[::]:0");
 
-  // And one failing case of router_get_advertised_or_port().
-  tt_int_op(0, OP_EQ, router_get_advertised_or_port(opts, AF_INET));
+  // And one failing case of routerconf_find_or_port().
+  tt_int_op(0, OP_EQ, routerconf_find_or_port(opts, AF_INET));
 
   // Set up a couple of configured ports.
   config_line_append(&opts->ORPort_lines, "ORPort", "[1234::5678]:auto");
@@ -521,12 +521,12 @@ test_router_get_advertised_or_port(void *arg)
   tt_assert(r == 0);
 
   // There are no listeners, so the "auto" case will turn up no results.
-  tt_int_op(0, OP_EQ, router_get_advertised_or_port(opts, AF_INET6));
-  router_get_advertised_ipv6_or_ap(opts, &ipv6);
+  tt_int_op(0, OP_EQ, routerconf_find_or_port(opts, AF_INET6));
+  routerconf_find_ipv6_or_ap(opts, &ipv6);
   tt_str_op(fmt_addrport(&ipv6.addr, ipv6.port), OP_EQ, "[::]:0");
 
   // This will return the matching value from the configured port.
-  tt_int_op(9999, OP_EQ, router_get_advertised_or_port(opts, AF_INET));
+  tt_int_op(9999, OP_EQ, routerconf_find_or_port(opts, AF_INET));
 
   // Now set up a dummy listener.
   MOCK(get_connection_array, mock_get_connection_array);
@@ -536,15 +536,15 @@ test_router_get_advertised_or_port(void *arg)
   smartlist_add(fake_connection_array, TO_CONN(listener));
 
   // We should get a port this time.
-  tt_int_op(54321, OP_EQ, router_get_advertised_or_port(opts, AF_INET6));
+  tt_int_op(54321, OP_EQ, routerconf_find_or_port(opts, AF_INET6));
 
-  // Test one succeeding case of router_get_advertised_ipv6_or_ap().
-  router_get_advertised_ipv6_or_ap(opts, &ipv6);
+  // Test one succeeding case of routerconf_find_ipv6_or_ap().
+  routerconf_find_ipv6_or_ap(opts, &ipv6);
   tt_str_op(fmt_addrport(&ipv6.addr, ipv6.port), OP_EQ,
             "[1234::5678]:54321");
 
   // This will return the matching value from the configured port.
-  tt_int_op(9999, OP_EQ, router_get_advertised_or_port(opts, AF_INET));
+  tt_int_op(9999, OP_EQ, routerconf_find_or_port(opts, AF_INET));
 
  done:
   or_options_free(opts);
@@ -570,26 +570,26 @@ test_router_get_advertised_or_port_localhost(void *arg)
   tt_assert(r == 0);
 
   // We should refuse to advertise them, since we have default dirauths.
-  router_get_advertised_ipv6_or_ap(opts, &ipv6);
+  routerconf_find_ipv6_or_ap(opts, &ipv6);
   tt_str_op(fmt_addrport(&ipv6.addr, ipv6.port), OP_EQ, "[::]:0");
   // But the lower-level function should still report the correct value
-  tt_int_op(9999, OP_EQ, router_get_advertised_or_port(opts, AF_INET6));
+  tt_int_op(9999, OP_EQ, routerconf_find_or_port(opts, AF_INET6));
 
   // The IPv4 checks are done in resolve_my_address(), which doesn't use
   // ORPorts so we can't test them here. (See #33681.) Both these lower-level
   // functions should still report the correct value.
-  tt_int_op(8888, OP_EQ, router_get_advertised_or_port(opts, AF_INET));
+  tt_int_op(8888, OP_EQ, routerconf_find_or_port(opts, AF_INET));
 
   // Now try with a fake authority set up.
   config_line_append(&opts->DirAuthorities, "DirAuthority",
                      "127.0.0.1:1066 "
                      "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
 
-  tt_int_op(9999, OP_EQ, router_get_advertised_or_port(opts, AF_INET6));
-  router_get_advertised_ipv6_or_ap(opts, &ipv6);
+  tt_int_op(9999, OP_EQ, routerconf_find_or_port(opts, AF_INET6));
+  routerconf_find_ipv6_or_ap(opts, &ipv6);
   tt_str_op(fmt_addrport(&ipv6.addr, ipv6.port), OP_EQ, "[::1]:9999");
 
-  tt_int_op(8888, OP_EQ, router_get_advertised_or_port(opts, AF_INET));
+  tt_int_op(8888, OP_EQ, routerconf_find_or_port(opts, AF_INET));
 
  done:
   or_options_free(opts);



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