[or-cvs] [tor/master] Log bandwidth_weight_rule_t as a string, not an integer.

nickm at torproject.org nickm at torproject.org
Mon Apr 12 22:11:54 UTC 2010


Author: Nick Mathewson <nickm at torproject.org>
Date: Mon, 12 Apr 2010 18:12:49 -0400
Subject: Log bandwidth_weight_rule_t as a string, not an integer.
Commit: 311aca5a3472cd318b72ca21d7a530182154e75c

I'm adding this because I can never remember what stuff like 'rule 3'
means.  That's the one where if somebody goes limp or taps out, the
fight is over, right?
---
 src/or/or.h         |    5 ++++-
 src/or/reasons.c    |   21 +++++++++++++++++++++
 src/or/routerlist.c |   16 +++++++++-------
 3 files changed, 34 insertions(+), 8 deletions(-)

diff --git a/src/or/or.h b/src/or/or.h
index 737c197..7c1e5a7 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -4493,6 +4493,9 @@ const char *circuit_end_reason_to_control_string(int reason);
 const char *socks4_response_code_to_string(uint8_t code);
 const char *socks5_response_code_to_string(uint8_t code);
 
+enum bandwidth_weight_rule_t;
+const char *bandwidth_weight_rule_to_string(enum bandwidth_weight_rule_t rule);
+
 /********************************* relay.c ***************************/
 
 extern uint64_t stats_n_relay_cells_relayed;
@@ -4963,7 +4966,7 @@ uint32_t router_get_advertised_bandwidth_capped(routerinfo_t *router);
 
 /** Possible ways to weight routers when choosing one randomly.  See
  * routerlist_sl_choose_by_bandwidth() for more information.*/
-typedef enum {
+typedef enum bandwidth_weight_rule_t {
   NO_WEIGHTING, WEIGHT_FOR_EXIT, WEIGHT_FOR_MID, WEIGHT_FOR_GUARD,
   WEIGHT_FOR_DIR
 } bandwidth_weight_rule_t;
diff --git a/src/or/reasons.c b/src/or/reasons.c
index 46483b2..e1c64eb 100644
--- a/src/or/reasons.c
+++ b/src/or/reasons.c
@@ -372,3 +372,24 @@ socks5_response_code_to_string(uint8_t code)
   }
 }
 
+/** Return a string corresponding to a bandwidht_weight_rule_t */
+const char *
+bandwidth_weight_rule_to_string(bandwidth_weight_rule_t rule)
+{
+  switch (rule)
+    {
+    case NO_WEIGHTING:
+      return "no weighting";
+    case WEIGHT_FOR_EXIT:
+      return "weight as exit";
+    case WEIGHT_FOR_MID:
+      return "weight as middle node";
+    case WEIGHT_FOR_GUARD:
+      return "weight as guard";
+    case WEIGHT_FOR_DIR:
+      return "weight as directory";
+    default:
+      return "unknown rule";
+  }
+}
+
diff --git a/src/or/routerlist.c b/src/or/routerlist.c
index 0173c27..13123e4 100644
--- a/src/or/routerlist.c
+++ b/src/or/routerlist.c
@@ -1577,7 +1577,8 @@ smartlist_choose_by_bandwidth_weights(smartlist_t *sl,
   if (smartlist_len(sl) == 0) {
     log_info(LD_CIRC,
              "Empty routerlist passed in to consensus weight node "
-             "selection for rule %d", rule);
+             "selection for rule %s",
+             bandwidth_weight_rule_to_string(rule));
     return NULL;
   }
 
@@ -1695,15 +1696,16 @@ smartlist_choose_by_bandwidth_weights(smartlist_t *sl,
     weighted_bw += weight*this_bw;
   }
 
-  log_debug(LD_CIRC, "Choosing node for rule %d based on weights "
-            "Wg=%lf Wm=%lf We=%lf Wd=%lf with total bw %lf", rule,
+  log_debug(LD_CIRC, "Choosing node for rule %s based on weights "
+            "Wg=%lf Wm=%lf We=%lf Wd=%lf with total bw %lf",
+            bandwidth_weight_rule_to_string(rule),
             Wg, Wm, We, Wd, weighted_bw);
 
   /* If there is no bandwidth, choose at random */
   if (DBL_TO_U64(weighted_bw) == 0) {
     log_warn(LD_CIRC,
-             "Weighted bandwidth is %lf in node selection for rule %d",
-             weighted_bw, rule);
+             "Weighted bandwidth is %lf in node selection for rule %s",
+             weighted_bw, bandwidth_weight_rule_to_string(rule));
     tor_free(bandwidths);
     return smartlist_choose(sl);
   }
@@ -1783,8 +1785,8 @@ smartlist_choose_by_bandwidth(smartlist_t *sl, bandwidth_weight_rule_t rule,
 
   if (smartlist_len(sl) == 0) {
     log_info(LD_CIRC,
-             "Empty routerlist passed in to old node selection for rule %d",
-             rule);
+             "Empty routerlist passed in to old node selection for rule %s",
+             bandwidth_weight_rule_to_string(rule));
     return NULL;
   }
 
-- 
1.6.5



More information about the tor-commits mailing list