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

[tor-commits] [tor/master] Use fmt_addrport where appropriate.



commit 8419d184411e8cd9457346a7a3d5f9734211a8b2
Author: David Fifield <david@xxxxxxxxxxxxxxx>
Date:   Sat Oct 6 21:25:25 2012 -0700

    Use fmt_addrport where appropriate.
    
    This is mostly a conversion from this pattern:
    	log("... %s:%d ...", fmt_and_decorate_addr(&addr), port);
    to this:
    	log("... %s ...", fmt_addrport(&addr, port));
    
    The output is the same in all cases.
---
 src/or/circuitbuild.c  |   45 +++++++++++++++++++++------------------------
 src/or/config.c        |   20 ++++++++++----------
 src/or/connection.c    |   24 +++++++++++-------------
 src/or/connection_or.c |   10 ++++------
 src/or/dirserv.c       |    6 ++----
 src/or/dirvote.c       |   10 ++++------
 src/or/rendservice.c   |    5 ++---
 src/or/statefile.c     |   12 +++++-------
 src/or/transports.c    |   40 +++++++++++++++++++++-------------------
 9 files changed, 80 insertions(+), 92 deletions(-)

diff --git a/src/or/circuitbuild.c b/src/or/circuitbuild.c
index 740efdb..71f4408 100644
--- a/src/or/circuitbuild.c
+++ b/src/or/circuitbuild.c
@@ -1955,9 +1955,9 @@ circuit_handle_first_hop(origin_circuit_t *circ)
   tor_assert(firsthop->extend_info);
 
   /* now see if we're already connected to the first OR in 'route' */
-  log_debug(LD_CIRC,"Looking for firsthop '%s:%u'",
-            fmt_and_decorate_addr(&firsthop->extend_info->addr),
-            firsthop->extend_info->port);
+  log_debug(LD_CIRC,"Looking for firsthop '%s'",
+            fmt_addrport(&firsthop->extend_info->addr,
+                         firsthop->extend_info->port));
 
   n_conn = connection_or_get_for_extend(firsthop->extend_info->identity_digest,
                                         &firsthop->extend_info->addr,
@@ -2470,8 +2470,8 @@ circuit_extend(cell_t *cell, circuit_t *circ)
                                         &should_launch);
 
   if (!n_conn) {
-    log_debug(LD_CIRC|LD_OR,"Next router (%s:%d): %s",
-              fmt_and_decorate_addr(&n_addr), (int)n_port, msg?msg:"????");
+    log_debug(LD_CIRC|LD_OR,"Next router (%s): %s",
+              fmt_addrport(&n_addr, n_port), msg?msg:"????");
 
     circ->n_hop = extend_info_new(NULL /*nickname*/,
                                     id_digest,
@@ -3926,8 +3926,8 @@ extend_info_from_node(const node_t *node, int for_direct_connect)
   else
     node_get_prim_orport(node, &ap);
 
-  log_debug(LD_CIRC, "using %s:%d for %s",
-            fmt_and_decorate_addr(&ap.addr), ap.port,
+  log_debug(LD_CIRC, "using %s for %s",
+            fmt_addrport(&ap.addr, ap.port),
             node->ri ? node->ri->nickname : node->rs->nickname);
 
   if (node->ri)
@@ -5318,8 +5318,8 @@ learned_router_identity(const tor_addr_t *addr, uint16_t port,
     get_configured_bridge_by_addr_port_digest(addr, port, digest);
   if (bridge && tor_digest_is_zero(bridge->identity)) {
     memcpy(bridge->identity, digest, DIGEST_LEN);
-    log_notice(LD_DIR, "Learned fingerprint %s for bridge %s:%d",
-               hex_str(digest, DIGEST_LEN), fmt_and_decorate_addr(addr), port);
+    log_notice(LD_DIR, "Learned fingerprint %s for bridge %s",
+               hex_str(digest, DIGEST_LEN), fmt_addrport(addr, port));
   }
 }
 
@@ -5364,12 +5364,12 @@ bridge_resolve_conflicts(const tor_addr_t *addr, uint16_t port,
           strcmp_opt(bridge->transport_name, transport_name)) {
         /* warn the user */
         char *bridge_description_new, *bridge_description_old;
-        tor_asprintf(&bridge_description_new, "%s:%u:%s:%s",
-                     fmt_and_decorate_addr(addr), port,
+        tor_asprintf(&bridge_description_new, "%s:%s:%s",
+                     fmt_addrport(addr, port),
                      digest ? hex_str(digest, DIGEST_LEN) : "",
                      transport_name ? transport_name : "");
-        tor_asprintf(&bridge_description_old, "%s:%u:%s:%s",
-                     fmt_and_decorate_addr(&bridge->addr), bridge->port,
+        tor_asprintf(&bridge_description_old, "%s:%s:%s",
+                     fmt_addrport(&bridge->addr, bridge->port),
                      tor_digest_is_zero(bridge->identity) ?
                      "" : hex_str(bridge->identity,DIGEST_LEN),
                      bridge->transport_name ? bridge->transport_name : "");
@@ -5582,10 +5582,9 @@ fetch_bridge_descriptors(const or_options_t *options, time_t now)
 
       if (ask_bridge_directly &&
           !fascist_firewall_allows_address_or(&bridge->addr, bridge->port)) {
-        log_notice(LD_DIR, "Bridge at '%s:%d' isn't reachable by our "
+        log_notice(LD_DIR, "Bridge at '%s' isn't reachable by our "
                    "firewall policy. %s.",
-                   fmt_and_decorate_addr(&bridge->addr),
-                   bridge->port,
+                   fmt_addrport(&bridge->addr, bridge->port),
                    can_use_bridge_authority ?
                      "Asking bridge authority instead" : "Skipping");
         if (can_use_bridge_authority)
@@ -5655,9 +5654,8 @@ rewrite_node_address_for_bridge(const bridge_info_t *bridge, node_t *node)
         ri->ipv6_orport = bridge->port;
         log_info(LD_DIR,
                  "Adjusted bridge routerinfo for '%s' to match configured "
-                 "address %s:%d.",
-                 ri->nickname, fmt_and_decorate_addr(&ri->ipv6_addr),
-                 ri->ipv6_orport);
+                 "address %s.",
+                 ri->nickname, fmt_addrport(&ri->ipv6_addr, ri->ipv6_orport));
       } else {
         log_err(LD_BUG, "Address family not supported: %d.",
                 tor_addr_family(&bridge->addr));
@@ -5676,10 +5674,10 @@ rewrite_node_address_for_bridge(const bridge_info_t *bridge, node_t *node)
       node_get_pref_orport(node, &ap);
       log_notice(LD_CONFIG,
                  "Bridge '%s' has both an IPv4 and an IPv6 address.  "
-                 "Will prefer using its %s address (%s:%d).",
+                 "Will prefer using its %s address (%s).",
                  ri->nickname,
                  tor_addr_family(&ap.addr) == AF_INET6 ? "IPv6" : "IPv4",
-                 fmt_and_decorate_addr(&ap.addr), ap.port);
+                 fmt_addrport(&ap.addr, ap.port));
     }
   }
   if (node->rs) {
@@ -5694,9 +5692,8 @@ rewrite_node_address_for_bridge(const bridge_info_t *bridge, node_t *node)
       rs->or_port = bridge->port;
       log_info(LD_DIR,
                "Adjusted bridge routerstatus for '%s' to match "
-               "configured address %s:%d.",
-               rs->nickname, fmt_and_decorate_addr(&bridge->addr),
-               rs->or_port);
+               "configured address %s.",
+               rs->nickname, fmt_addrport(&bridge->addr, rs->or_port));
     }
   }
 }
diff --git a/src/or/config.c b/src/or/config.c
index dc43dec..1233f5b 100644
--- a/src/or/config.c
+++ b/src/or/config.c
@@ -3945,8 +3945,8 @@ parse_bridge_line(const char *line, int validate_only)
   }
 
   if (!validate_only) {
-    log_debug(LD_DIR, "Bridge at %s:%d (transport: %s) (%s)",
-              fmt_and_decorate_addr(&addr), (int)port,
+    log_debug(LD_DIR, "Bridge at %s (transport: %s) (%s)",
+              fmt_addrport(&addr, port),
               transport_name ? transport_name : "no transport",
               fingerprint ? fingerprint : "no key listed");
     bridge_add_from_config(&addr, port,
@@ -4079,8 +4079,8 @@ parse_client_transport_line(const char *line, int validate_only)
       transport_add_from_config(&addr, port, smartlist_get(transport_list, 0),
                                 socks_ver);
 
-      log_info(LD_DIR, "Transport '%s' found at %s:%d",
-               transports, fmt_and_decorate_addr(&addr), (int)port);
+      log_info(LD_DIR, "Transport '%s' found at %s",
+               transports, fmt_addrport(&addr, port));
     }
   }
 
@@ -4199,8 +4199,8 @@ parse_server_transport_line(const char *line, int validate_only)
     }
 
     if (!validate_only) {
-      log_info(LD_DIR, "Server transport '%s' at %s:%d.",
-               transports, fmt_and_decorate_addr(&addr), (int)port);
+      log_info(LD_DIR, "Server transport '%s' at %s.",
+               transports, fmt_addrport(&addr, port));
     }
   }
 
@@ -4372,17 +4372,17 @@ warn_nonlocal_client_ports(const smartlist_t *ports, const char *portname)
     if (port->is_unix_addr) {
       /* Unix sockets aren't accessible over a network. */
     } else if (!tor_addr_is_internal(&port->addr, 1)) {
-      log_warn(LD_CONFIG, "You specified a public address '%s:%d' for %sPort. "
+      log_warn(LD_CONFIG, "You specified a public address '%s' for %sPort. "
                "Other people on the Internet might find your computer and "
                "use it as an open proxy. Please don't allow this unless you "
                "have a good reason.",
-               fmt_and_decorate_addr(&port->addr), port->port, portname);
+               fmt_addrport(&port->addr, port->port), portname);
     } else if (!tor_addr_is_loopback(&port->addr)) {
-      log_notice(LD_CONFIG, "You configured a non-loopback address '%s:%d' "
+      log_notice(LD_CONFIG, "You configured a non-loopback address '%s' "
                  "for %sPort. This allows everybody on your local network to "
                  "use your machine as a proxy. Make sure this is what you "
                  "wanted.",
-                 fmt_and_decorate_addr(&port->addr), port->port, portname);
+                 fmt_addrport(&port->addr, port->port), portname);
     }
   } SMARTLIST_FOREACH_END(port);
 }
diff --git a/src/or/connection.c b/src/or/connection.c
index b5c4a20..d559da5 100644
--- a/src/or/connection.c
+++ b/src/or/connection.c
@@ -904,9 +904,8 @@ connection_listener_new(const struct sockaddr *listensockaddr,
 
     tor_addr_from_sockaddr(&addr, listensockaddr, &usePort);
 
-    log_notice(LD_NET, "Opening %s on %s:%d",
-               conn_type_to_string(type), fmt_and_decorate_addr(&addr),
-               usePort);
+    log_notice(LD_NET, "Opening %s on %s",
+               conn_type_to_string(type), fmt_addrport(&addr, usePort));
 
     s = tor_open_socket(tor_addr_family(&addr),
                         is_tcp ? SOCK_STREAM : SOCK_DGRAM,
@@ -1512,17 +1511,17 @@ connection_proxy_connect(connection_t *conn, int type)
       }
 
       if (base64_authenticator) {
-        const char *addr = fmt_and_decorate_addr(&conn->addr);
-        tor_snprintf(buf, sizeof(buf), "CONNECT %s:%d HTTP/1.1\r\n"
-                     "Host: %s:%d\r\n"
+        const char *addrport = fmt_addrport(&conn->addr, conn->port);
+        tor_snprintf(buf, sizeof(buf), "CONNECT %s HTTP/1.1\r\n"
+                     "Host: %s\r\n"
                      "Proxy-Authorization: Basic %s\r\n\r\n",
-                     addr, conn->port,
-                     addr, conn->port,
+                     addrport,
+                     addrport,
                      base64_authenticator);
         tor_free(base64_authenticator);
       } else {
-        tor_snprintf(buf, sizeof(buf), "CONNECT %s:%d HTTP/1.0\r\n\r\n",
-                     fmt_and_decorate_addr(&conn->addr), conn->port);
+        tor_snprintf(buf, sizeof(buf), "CONNECT %s HTTP/1.0\r\n\r\n",
+                     fmt_addrport(&conn->addr, conn->port));
       }
 
       connection_write_to_buf(buf, strlen(buf), conn);
@@ -4235,11 +4234,10 @@ log_failed_proxy_connection(connection_t *conn)
     return; /* if we have no proxy set up, leave this function. */
 
   log_warn(LD_NET,
-           "The connection to the %s proxy server at %s:%u just failed. "
+           "The connection to the %s proxy server at %s just failed. "
            "Make sure that the proxy server is up and running.",
            proxy_type_to_string(get_proxy_type()),
-           fmt_and_decorate_addr(&proxy_addr),
-           proxy_port);
+           fmt_addrport(&proxy_addr, proxy_port));
 }
 
 /** Return string representation of <b>proxy_type</b>. */
diff --git a/src/or/connection_or.c b/src/or/connection_or.c
index 04cbf40..06b1268 100644
--- a/src/or/connection_or.c
+++ b/src/or/connection_or.c
@@ -1084,19 +1084,17 @@ connection_or_connect(const tor_addr_t *_addr, uint16_t port,
                                              TO_CONN(conn)->port);
 
     if (transport_name) {
-      log_warn(LD_GENERAL, "We were supposed to connect to bridge '%s:%u' "
+      log_warn(LD_GENERAL, "We were supposed to connect to bridge '%s' "
                "using pluggable transport '%s', but we can't find a pluggable "
                "transport proxy supporting '%s'. This can happen if you "
                "haven't provided a ClientTransportPlugin line, or if "
                "your pluggable transport proxy stopped running.",
-               fmt_and_decorate_addr(&TO_CONN(conn)->addr),
-               TO_CONN(conn)->port,
+               fmt_addrport(&TO_CONN(conn)->addr, TO_CONN(conn)->port),
                transport_name, transport_name);
     } else {
-      log_warn(LD_GENERAL, "Tried to connect to '%s:%u' through a proxy, but "
+      log_warn(LD_GENERAL, "Tried to connect to '%s' through a proxy, but "
                "the proxy address could not be found.",
-               fmt_and_decorate_addr(&TO_CONN(conn)->addr),
-               TO_CONN(conn)->port);
+               fmt_addrport(&TO_CONN(conn)->addr, TO_CONN(conn)->port));
     }
 
     connection_free(TO_CONN(conn));
diff --git a/src/or/dirserv.c b/src/or/dirserv.c
index 0d98324..71c0197 100644
--- a/src/or/dirserv.c
+++ b/src/or/dirserv.c
@@ -2116,11 +2116,9 @@ routerstatus_format_entry(char *buf, size_t buf_len,
 
   /* Possible "a" line. At most one for now. */
   if (!tor_addr_is_null(&rs->ipv6_addr)) {
-    const char *addr_str = fmt_and_decorate_addr(&rs->ipv6_addr);
     r = tor_snprintf(cp, buf_len - (cp-buf),
-                     "a %s:%d\n",
-                     addr_str,
-                     (int)rs->ipv6_orport);
+                     "a %s\n",
+                     fmt_addrport(&rs->ipv6_addr, rs->ipv6_orport));
     if (r<0) {
       log_warn(LD_BUG, "Not enough space in buffer.");
       return -1;
diff --git a/src/or/dirvote.c b/src/or/dirvote.c
index 21ad836..d98e18b 100644
--- a/src/or/dirvote.c
+++ b/src/or/dirvote.c
@@ -489,10 +489,9 @@ compute_routerstatus_consensus(smartlist_t *votes, int consensus_method,
                                                   _compare_orports);
     if (most_alt_orport) {
       memcpy(best_alt_orport_out, most_alt_orport, sizeof(tor_addr_port_t));
-      log_debug(LD_DIR, "\"a\" line winner for %s is %s:%d",
+      log_debug(LD_DIR, "\"a\" line winner for %s is %s",
                 most->status.nickname,
-                fmt_and_decorate_addr(&most_alt_orport->addr),
-                most_alt_orport->port);
+                fmt_addrport(&most_alt_orport->addr, most_alt_orport->port));
     }
 
     SMARTLIST_FOREACH(alt_orports, tor_addr_port_t *, ap, tor_free(ap));
@@ -3561,9 +3560,8 @@ dirvote_create_microdescriptor(const routerinfo_t *ri, int consensus_method)
 
   if (consensus_method >= MIN_METHOD_FOR_A_LINES &&
       !tor_addr_is_null(&ri->ipv6_addr) && ri->ipv6_orport)
-    smartlist_add_asprintf(chunks, "a %s:%d\n",
-                           fmt_and_decorate_addr(&ri->ipv6_addr),
-                           ri->ipv6_orport);
+    smartlist_add_asprintf(chunks, "a %s\n",
+                           fmt_addrport(&ri->ipv6_addr, ri->ipv6_orport));
 
   if (family)
     smartlist_add_asprintf(chunks, "family %s\n", family);
diff --git a/src/or/rendservice.c b/src/or/rendservice.c
index 6cae4bc..a1d4ac6 100644
--- a/src/or/rendservice.c
+++ b/src/or/rendservice.c
@@ -272,9 +272,8 @@ rend_add_service(rend_service_t *service)
               service->directory);
     for (i = 0; i < smartlist_len(service->ports); ++i) {
       p = smartlist_get(service->ports, i);
-      log_debug(LD_REND,"Service maps port %d to %s:%d",
-                p->virtual_port, fmt_and_decorate_addr(&p->real_addr),
-                p->real_port);
+      log_debug(LD_REND,"Service maps port %d to %s",
+                p->virtual_port, fmt_addrport(&p->real_addr, p->real_port));
     }
   }
 }
diff --git a/src/or/statefile.c b/src/or/statefile.c
index dd9d102..001c4c3 100644
--- a/src/or/statefile.c
+++ b/src/or/statefile.c
@@ -553,8 +553,7 @@ save_transport_to_state(const char *transport,
   if (transport_line) { /* if transport already exists in state... */
     const char *prev_bindaddr = /* get its addrport... */
       get_transport_bindaddr(transport_line->value, transport);
-    tor_asprintf(&transport_addrport, "%s:%d", fmt_and_decorate_addr(addr),
-                 (int)port);
+    transport_addrport = tor_strdup(fmt_addrport(addr, port));
 
     /* if transport in state has the same address as this one, life is good */
     if (!strcmp(prev_bindaddr, transport_addrport)) {
@@ -566,9 +565,9 @@ save_transport_to_state(const char *transport,
                "address:port. Let's update the state file with the new "
                "address:port");
       tor_free(transport_line->value); /* free the old line */
-      tor_asprintf(&transport_line->value, "%s %s:%d", transport,
-                   fmt_and_decorate_addr(addr),
-                   (int) port); /* replace old addrport line with new line */
+      /* replace old addrport line with new line */
+      tor_asprintf(&transport_line->value, "%s %s", transport,
+                   fmt_addrport(addr, port));
     }
   } else { /* never seen this one before; save it in state for next time */
     log_info(LD_CONFIG, "It's the first time we see this transport. "
@@ -585,8 +584,7 @@ save_transport_to_state(const char *transport,
     /* allocate space for the new line and fill it in */
     *next = line = tor_malloc_zero(sizeof(config_line_t));
     line->key = tor_strdup("TransportProxy");
-    tor_asprintf(&line->value, "%s %s:%d", transport,
-                 fmt_and_decorate_addr(addr), (int) port);
+    tor_asprintf(&line->value, "%s %s", transport, fmt_addrport(addr, port));
 
     next = &(line->next);
   }
diff --git a/src/or/transports.c b/src/or/transports.c
index ed4a295..56ab600 100644
--- a/src/or/transports.c
+++ b/src/or/transports.c
@@ -270,24 +270,26 @@ transport_resolve_conflicts(const transport_t *t)
       t_tmp->marked_for_removal = 0;
       return 1;
     } else { /* same name but different addrport */
-      char *new_transport_addr = tor_strdup(fmt_and_decorate_addr(&t->addr));
+      char *new_transport_addrport =
+        tor_strdup(fmt_addrport(&t->addr, t->port));
       if (t_tmp->marked_for_removal) { /* marked for removal */
-        log_notice(LD_GENERAL, "You tried to add transport '%s' at '%s:%u' "
+        log_notice(LD_GENERAL, "You tried to add transport '%s' at '%s' "
                    "but there was already a transport marked for deletion at "
-                   "'%s:%u'. We deleted the old transport and registered the "
-                   "new one.", t->name, new_transport_addr, t->port,
-                   fmt_and_decorate_addr(&t_tmp->addr), t_tmp->port);
+                   "'%s'. We deleted the old transport and registered the "
+                   "new one.", t->name, new_transport_addrport,
+                   fmt_addrport(&t_tmp->addr, t_tmp->port));
         smartlist_remove(transport_list, t_tmp);
         transport_free(t_tmp);
-        tor_free(new_transport_addr);
+        tor_free(new_transport_addrport);
       } else { /* *not* marked for removal */
-        log_notice(LD_GENERAL, "You tried to add transport '%s' at '%s:%u' "
-                   "but the same transport already exists at '%s:%u'. "
-                   "Skipping.", t->name, new_transport_addr, t->port,
-                   fmt_and_decorate_addr(&t_tmp->addr), t_tmp->port);
-        tor_free(new_transport_addr);
+        log_notice(LD_GENERAL, "You tried to add transport '%s' at '%s' "
+                   "but the same transport already exists at '%s'. "
+                   "Skipping.", t->name, new_transport_addrport,
+                   fmt_addrport(&t_tmp->addr, t_tmp->port));
+        tor_free(new_transport_addrport);
         return -1;
       }
+      tor_free(new_transport_addrport);
     }
   }
 
@@ -332,18 +334,18 @@ transport_add_from_config(const tor_addr_t *addr, uint16_t port,
   switch (r) {
   case -1:
   default:
-    log_notice(LD_GENERAL, "Could not add transport %s at %s:%u. Skipping.",
-               t->name, fmt_and_decorate_addr(&t->addr), t->port);
+    log_notice(LD_GENERAL, "Could not add transport %s at %s. Skipping.",
+               t->name, fmt_addrport(&t->addr, t->port));
     transport_free(t);
     return -1;
   case 1:
-    log_info(LD_GENERAL, "Succesfully registered transport %s at %s:%u.",
-             t->name, fmt_and_decorate_addr(&t->addr), t->port);
+    log_info(LD_GENERAL, "Succesfully registered transport %s at %s.",
+             t->name, fmt_addrport(&t->addr, t->port));
      transport_free(t); /* falling */
      return 0;
   case 0:
-    log_info(LD_GENERAL, "Succesfully registered transport %s at %s:%u.",
-             t->name, fmt_and_decorate_addr(&t->addr), t->port);
+    log_info(LD_GENERAL, "Succesfully registered transport %s at %s.",
+             t->name, fmt_addrport(&t->addr, t->port));
     return 0;
   }
 }
@@ -644,8 +646,8 @@ register_server_proxy(const managed_proxy_t *mp)
 
   SMARTLIST_FOREACH_BEGIN(mp->transports, transport_t *, t) {
     save_transport_to_state(t->name, &t->addr, t->port);
-    log_notice(LD_GENERAL, "Registered server transport '%s' at '%s:%d'",
-               t->name, fmt_and_decorate_addr(&t->addr), (int)t->port);
+    log_notice(LD_GENERAL, "Registered server transport '%s' at '%s'",
+               t->name, fmt_addrport(&t->addr, t->port));
   } SMARTLIST_FOREACH_END(t);
 }
 



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