]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Refactor pathbias functions to use pathbias_should_count.
authorMike Perry <mikeperry-git@fscked.org>
Thu, 25 Oct 2012 21:05:44 +0000 (14:05 -0700)
committerMike Perry <mikeperry-git@fscked.org>
Fri, 7 Dec 2012 23:28:37 +0000 (15:28 -0800)
src/or/circuitbuild.c

index 6f91fc37fcbfb05116a7ab63d6ae04ce7f6f6ead..299ca29c0cc5bab9c21bedd0be31339e542e6487 100644 (file)
@@ -1152,34 +1152,7 @@ pathbias_count_first_hop(origin_circuit_t *circ)
     RATELIM_INIT(FIRST_HOP_NOTICE_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(&first_hop_notice_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();
-    }
+  if (!pathbias_should_count(circ)) {
     return 0;
   }
 
@@ -1276,34 +1249,7 @@ pathbias_count_success(origin_circuit_t *circ)
   char *rate_msg = NULL;
   entry_guard_t *guard = 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;
-  }
-
-  /* Ignore one hop circuits */
-  if (circ->build_state->onehop_tunnel ||
-      circ->build_state->desired_path_len == 1) {
-    /* Check for consistency */
-    if (circ->build_state->desired_path_len != 1 ||
-        !circ->build_state->onehop_tunnel) {
-      if ((rate_msg = rate_limit_log(&success_notice_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();
-    }
+  if (!pathbias_should_count(circ)) {
     return;
   }