]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Add the ability to count circuit timeouts for guards.
authorMike Perry <mikeperry-git@fscked.org>
Thu, 25 Oct 2012 00:34:18 +0000 (17:34 -0700)
committerMike Perry <mikeperry-git@fscked.org>
Fri, 7 Dec 2012 23:28:36 +0000 (15:28 -0800)
This is purely for informational reasons for debugging.

src/or/circuitbuild.c
src/or/circuituse.c
src/or/entrynodes.c
src/or/entrynodes.h
src/or/or.h

index 73018740c2216e4eefa7362494b9874fdc9f282b..c8c8db39674614f8fd7d33257ff99d94a2baac3c 100644 (file)
@@ -1056,6 +1056,53 @@ pathbias_state_to_string(path_state_t state)
   return "unknown";
 }
 
+/**
+ * Decide if the path bias code should count a circuit.
+ *
+ * @returns 1 if we should count it, 0 otherwise.
+ */
+static int
+pathbias_should_count(origin_circuit_t *circ)
+{
+#define PATHBIAS_COUNT_INTERVAL (600)
+  static ratelim_t count_limit =
+    RATELIM_INIT(PATHBIAS_COUNT_INTERVAL);
+  char *rate_msg = NULL;
+
+  /* We can't do path bias accounting without entry guards.
+   * Testing and controller circuits also have no guards. */
+  if (get_options()->UseEntryGuards == 0 ||
+          circ->base_.purpose == CIRCUIT_PURPOSE_TESTING ||
+          circ->base_.purpose == CIRCUIT_PURPOSE_CONTROLLER) {
+    return 0;
+  }
+
+  /* Completely ignore one hop circuits */
+  if (circ->build_state->onehop_tunnel ||
+      circ->build_state->desired_path_len == 1) {
+    /* Check for inconsistency */
+    if (circ->build_state->desired_path_len != 1 ||
+        !circ->build_state->onehop_tunnel) {
+      if ((rate_msg = rate_limit_log(&count_limit, approx_time()))) {
+        log_notice(LD_BUG,
+               "One-hop circuit has length %d. Path state is %s. "
+               "Circuit is a %s currently %s.%s",
+               circ->build_state->desired_path_len,
+               pathbias_state_to_string(circ->path_state),
+               circuit_purpose_to_string(circ->base_.purpose),
+               circuit_state_to_string(circ->base_.state),
+               rate_msg);
+        tor_free(rate_msg);
+      }
+      tor_fragile_assert();
+    }
+    return 0;
+  }
+
+  return 1;
+}
+
+
 /**
  * Check our circuit state to see if this is a successful first hop.
  * If so, record it in the current guard's path bias first_hop count.
@@ -1290,6 +1337,26 @@ pathbias_count_success(origin_circuit_t *circ)
   }
 }
 
+/**
+ * Count timeouts for path bias log messages.
+ *
+ * These counts are purely informational.
+ */
+void
+pathbias_count_timeout(origin_circuit_t *circ)
+{
+  if(!pathbias_should_count(circ)) {
+    return;
+  }
+  entry_guard_t *guard =
+      entry_guard_get_by_id_digest(circ->base_.n_chan->identity_digest);
+
+  if (guard) {
+    guard->timeouts++;
+    entry_guards_changed();
+  }
+}
+
 /** Increment the number of times we successfully extended a circuit to
  * 'guard', first checking if the failure rate is high enough that we should
  * eliminate the guard.  Return -1 if the guard looks no good; return 0 if the
index e14f9d03ca37793f9e2e7ef8c97b9c12e0284898..77822a36adb92f4e9aec92c3e1f6af4efdf5c650 100644 (file)
@@ -663,6 +663,8 @@ circuit_expire_building(void)
       circuit_mark_for_close(victim, END_CIRC_REASON_MEASUREMENT_EXPIRED);
     else
       circuit_mark_for_close(victim, END_CIRC_REASON_TIMEOUT);
+
+    pathbias_count_timeout(TO_ORIGIN_CIRCUIT(victim));
   }
 }
 
index 8712241f629816bfa83cc4e1af9bcf94213f3fa6..d9a06a65739515b85b434f7a3a2d4399ae74cbdb 100644 (file)
@@ -1021,7 +1021,7 @@ entry_guards_parse_state(or_state_t *state, int set, char **msg)
       digestmap_set(added_by, d, tor_strdup(line->value+HEX_DIGEST_LEN+1));
     } else if (!strcasecmp(line->key, "EntryGuardPathBias")) {
       const or_options_t *options = get_options();
-      unsigned hop_cnt, success_cnt;
+      unsigned hop_cnt, success_cnt, timeouts;
 
       if (!node) {
         *msg = tor_strdup("Unable to parse entry nodes: "
@@ -1029,14 +1029,20 @@ entry_guards_parse_state(or_state_t *state, int set, char **msg)
         break;
       }
 
-      if (tor_sscanf(line->value, "%u %u", &success_cnt, &hop_cnt) != 2) {
-        log_warn(LD_GENERAL, "Unable to parse guard path bias info: "
+      /* First try 3 params, then 2. */
+      if (tor_sscanf(line->value, "%u %u %u", &success_cnt, &hop_cnt,
+                     &timeouts) != 3) {
+        timeouts = 0;
+        if (tor_sscanf(line->value, "%u %u", &success_cnt, &hop_cnt) != 2) {
+          log_warn(LD_GENERAL, "Unable to parse guard path bias info: "
                  "Misformated EntryGuardPathBias %s", escaped(line->value));
-        continue;
+          continue;
+        }
       }
 
       node->first_hops = hop_cnt;
       node->circuit_successes = success_cnt;
+      node->timeouts = timeouts;
       log_info(LD_GENERAL, "Read %u/%u path bias for node %s",
                node->circuit_successes, node->first_hops, node->nickname);
       /* Note: We rely on the < comparison here to allow us to set a 0
@@ -1173,8 +1179,8 @@ entry_guards_update_state(or_state_t *state)
       if (e->first_hops) {
         *next = line = tor_malloc_zero(sizeof(config_line_t));
         line->key = tor_strdup("EntryGuardPathBias");
-        tor_asprintf(&line->value, "%u %u",
-                     e->circuit_successes, e->first_hops);
+        tor_asprintf(&line->value, "%u %u %u",
+                     e->circuit_successes, e->first_hops, e->timeouts);
         next = &(line->next);
       }
 
index 4d031c35938924d797111084f5850b67001756bd..b34744183c4c932e21633c40db3756a18a293ccd 100644 (file)
@@ -47,6 +47,8 @@ typedef struct entry_guard_t {
   unsigned first_hops; /**< Number of first hops this guard has completed */
   unsigned circuit_successes; /**< Number of successfully built circuits using
                                * this guard as first hop. */
+  unsigned timeouts; /**< Number of 'right-censored' timeouts 
+                                   for this guard. */
 } entry_guard_t;
 
 entry_guard_t *entry_guard_get_by_id_digest(const char *digest);
index 195cb2b98f8d15efeddd1297bf5b62a0ded4f7c2..59202104db6d17dcdc17db9a5a5e8c3763ad341a 100644 (file)
@@ -4067,6 +4067,8 @@ typedef struct {
   double close_ms;
 } circuit_build_times_t;
 
+void pathbias_count_timeout(origin_circuit_t *circ);
+
 /********************************* config.c ***************************/
 
 /** An error from options_trial_assign() or options_init_from_string(). */