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

[tor-commits] [tor/master] Move path-bias fields into a separate structure



commit be447bc7700bc91c3b0f2475c06d1e9e64c90804
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date:   Mon Nov 14 11:51:38 2016 -0500

    Move path-bias fields into a separate structure
    
    (Other than the field movement, the code changes here are just
    search-and-replace)
---
 src/or/circpathbias.c      | 216 ++++++++++++++++++++++-----------------------
 src/or/entrynodes.c        |  52 +++++------
 src/or/entrynodes.h        |  69 ++++++++-------
 src/test/test_entrynodes.c |  24 ++---
 4 files changed, 181 insertions(+), 180 deletions(-)

diff --git a/src/or/circpathbias.c b/src/or/circpathbias.c
index 2968607..6e2589c 100644
--- a/src/or/circpathbias.c
+++ b/src/or/circpathbias.c
@@ -58,14 +58,14 @@ entry_guard_inc_circ_attempt_count(entry_guard_t *guard)
 
   pathbias_measure_close_rate(guard);
 
-  if (guard->path_bias_disabled)
+  if (guard->pb.path_bias_disabled)
     return -1;
 
   pathbias_scale_close_rates(guard);
-  guard->circ_attempts++;
+  guard->pb.circ_attempts++;
 
   log_info(LD_CIRC, "Got success count %f/%f for guard %s ($%s)",
-           guard->circ_successes, guard->circ_attempts, guard->nickname,
+           guard->pb.circ_successes, guard->pb.circ_attempts, guard->nickname,
            hex_str(guard->identity, DIGEST_LEN));
   return 0;
 }
@@ -518,11 +518,11 @@ pathbias_count_build_success(origin_circuit_t *circ)
     if (guard) {
       if (circ->path_state == PATH_STATE_BUILD_ATTEMPTED) {
         circ->path_state = PATH_STATE_BUILD_SUCCEEDED;
-        guard->circ_successes++;
+        guard->pb.circ_successes++;
         entry_guards_changed();
 
         log_info(LD_CIRC, "Got success count %f/%f for guard %s ($%s)",
-                 guard->circ_successes, guard->circ_attempts,
+                 guard->pb.circ_successes, guard->pb.circ_attempts,
                  guard->nickname, hex_str(guard->identity, DIGEST_LEN));
       } else {
         if ((rate_msg = rate_limit_log(&success_notice_limit,
@@ -538,10 +538,10 @@ pathbias_count_build_success(origin_circuit_t *circ)
         }
       }
 
-      if (guard->circ_attempts < guard->circ_successes) {
+      if (guard->pb.circ_attempts < guard->pb.circ_successes) {
         log_notice(LD_BUG, "Unexpectedly high successes counts (%f/%f) "
                  "for guard %s ($%s)",
-                 guard->circ_successes, guard->circ_attempts,
+                 guard->pb.circ_successes, guard->pb.circ_attempts,
                  guard->nickname, hex_str(guard->identity, DIGEST_LEN));
       }
     /* In rare cases, CIRCUIT_PURPOSE_TESTING can get converted to
@@ -604,13 +604,13 @@ pathbias_count_use_attempt(origin_circuit_t *circ)
     if (guard) {
       pathbias_measure_use_rate(guard);
       pathbias_scale_use_rates(guard);
-      guard->use_attempts++;
+      guard->pb.use_attempts++;
       entry_guards_changed();
 
       log_debug(LD_CIRC,
                "Marked circuit %d (%f/%f) as used for guard %s ($%s).",
                circ->global_identifier,
-               guard->use_successes, guard->use_attempts,
+               guard->pb.use_successes, guard->pb.use_attempts,
                guard->nickname, hex_str(guard->identity, DIGEST_LEN));
     }
 
@@ -713,21 +713,21 @@ pathbias_count_use_success(origin_circuit_t *circ)
     guard = entry_guard_get_by_id_digest(
                 circ->cpath->extend_info->identity_digest);
     if (guard) {
-      guard->use_successes++;
+      guard->pb.use_successes++;
       entry_guards_changed();
 
-      if (guard->use_attempts < guard->use_successes) {
+      if (guard->pb.use_attempts < guard->pb.use_successes) {
         log_notice(LD_BUG, "Unexpectedly high use successes counts (%f/%f) "
                  "for guard %s=%s",
-                 guard->use_successes, guard->use_attempts,
+                 guard->pb.use_successes, guard->pb.use_attempts,
                  guard->nickname, hex_str(guard->identity, DIGEST_LEN));
       }
 
       log_debug(LD_CIRC,
                 "Marked circuit %d (%f/%f) as used successfully for guard "
                 "%s ($%s).",
-                circ->global_identifier, guard->use_successes,
-                guard->use_attempts, guard->nickname,
+                circ->global_identifier, guard->pb.use_successes,
+                guard->pb.use_attempts, guard->nickname,
                 hex_str(guard->identity, DIGEST_LEN));
     }
   }
@@ -1031,7 +1031,7 @@ pathbias_count_successful_close(origin_circuit_t *circ)
   if (guard) {
     /* In the long run: circuit_success ~= successful_circuit_close +
      *                                     circ_failure + stream_failure */
-    guard->successful_circuits_closed++;
+    guard->pb.successful_circuits_closed++;
     entry_guards_changed();
   } else if (circ->base_.purpose != CIRCUIT_PURPOSE_C_MEASURE_TIMEOUT) {
    /* In rare cases, CIRCUIT_PURPOSE_TESTING can get converted to
@@ -1068,7 +1068,7 @@ pathbias_count_collapse(origin_circuit_t *circ)
   }
 
   if (guard) {
-    guard->collapsed_circuits++;
+    guard->pb.collapsed_circuits++;
     entry_guards_changed();
   } else if (circ->base_.purpose != CIRCUIT_PURPOSE_C_MEASURE_TIMEOUT) {
    /* In rare cases, CIRCUIT_PURPOSE_TESTING can get converted to
@@ -1101,7 +1101,7 @@ pathbias_count_use_failed(origin_circuit_t *circ)
   }
 
   if (guard) {
-    guard->unusable_circuits++;
+    guard->pb.unusable_circuits++;
     entry_guards_changed();
   } else if (circ->base_.purpose != CIRCUIT_PURPOSE_C_MEASURE_TIMEOUT) {
    /* In rare cases, CIRCUIT_PURPOSE_TESTING can get converted to
@@ -1144,7 +1144,7 @@ pathbias_count_timeout(origin_circuit_t *circ)
   }
 
   if (guard) {
-    guard->timeouts++;
+    guard->pb.timeouts++;
     entry_guards_changed();
   }
 }
@@ -1200,7 +1200,7 @@ pathbias_count_circs_in_states(entry_guard_t *guard,
 double
 pathbias_get_close_success_count(entry_guard_t *guard)
 {
-  return guard->successful_circuits_closed +
+  return guard->pb.successful_circuits_closed +
          pathbias_count_circs_in_states(guard,
                        PATH_STATE_BUILD_SUCCEEDED,
                        PATH_STATE_USE_SUCCEEDED);
@@ -1216,7 +1216,7 @@ pathbias_get_close_success_count(entry_guard_t *guard)
 double
 pathbias_get_use_success_count(entry_guard_t *guard)
 {
-  return guard->use_successes +
+  return guard->pb.use_successes +
          pathbias_count_circs_in_states(guard,
                        PATH_STATE_USE_ATTEMPTED,
                        PATH_STATE_USE_SUCCEEDED);
@@ -1235,15 +1235,15 @@ pathbias_measure_use_rate(entry_guard_t *guard)
 {
   const or_options_t *options = get_options();
 
-  if (guard->use_attempts > pathbias_get_min_use(options)) {
+  if (guard->pb.use_attempts > pathbias_get_min_use(options)) {
     /* Note: We rely on the < comparison here to allow us to set a 0
      * rate and disable the feature entirely. If refactoring, don't
      * change to <= */
-    if (pathbias_get_use_success_count(guard)/guard->use_attempts
+    if (pathbias_get_use_success_count(guard)/guard->pb.use_attempts
         < pathbias_get_extreme_use_rate(options)) {
       /* Dropping is currently disabled by default. */
       if (pathbias_get_dropguards(options)) {
-        if (!guard->path_bias_disabled) {
+        if (!guard->pb.path_bias_disabled) {
           log_warn(LD_CIRC,
                  "Your Guard %s ($%s) is failing to carry an extremely large "
                  "amount of stream on its circuits. "
@@ -1255,21 +1255,21 @@ pathbias_measure_use_rate(entry_guard_t *guard)
                  "For reference, your timeout cutoff is %ld seconds.",
                  guard->nickname, hex_str(guard->identity, DIGEST_LEN),
                  tor_lround(pathbias_get_use_success_count(guard)),
-                 tor_lround(guard->use_attempts),
+                 tor_lround(guard->pb.use_attempts),
                  tor_lround(pathbias_get_close_success_count(guard)),
-                 tor_lround(guard->circ_attempts),
-                 tor_lround(guard->circ_successes),
-                 tor_lround(guard->unusable_circuits),
-                 tor_lround(guard->collapsed_circuits),
-                 tor_lround(guard->timeouts),
+                 tor_lround(guard->pb.circ_attempts),
+                 tor_lround(guard->pb.circ_successes),
+                 tor_lround(guard->pb.unusable_circuits),
+                 tor_lround(guard->pb.collapsed_circuits),
+                 tor_lround(guard->pb.timeouts),
                  tor_lround(get_circuit_build_close_time_ms()/1000));
-          guard->path_bias_disabled = 1;
+          guard->pb.path_bias_disabled = 1;
           guard->bad_since = approx_time();
           entry_guards_changed();
           return;
         }
-      } else if (!guard->path_bias_use_extreme) {
-        guard->path_bias_use_extreme = 1;
+      } else if (!guard->pb.path_bias_use_extreme) {
+        guard->pb.path_bias_use_extreme = 1;
         log_warn(LD_CIRC,
                  "Your Guard %s ($%s) is failing to carry an extremely large "
                  "amount of streams on its circuits. "
@@ -1281,19 +1281,19 @@ pathbias_measure_use_rate(entry_guard_t *guard)
                  "For reference, your timeout cutoff is %ld seconds.",
                  guard->nickname, hex_str(guard->identity, DIGEST_LEN),
                  tor_lround(pathbias_get_use_success_count(guard)),
-                 tor_lround(guard->use_attempts),
+                 tor_lround(guard->pb.use_attempts),
                  tor_lround(pathbias_get_close_success_count(guard)),
-                 tor_lround(guard->circ_attempts),
-                 tor_lround(guard->circ_successes),
-                 tor_lround(guard->unusable_circuits),
-                 tor_lround(guard->collapsed_circuits),
-                 tor_lround(guard->timeouts),
+                 tor_lround(guard->pb.circ_attempts),
+                 tor_lround(guard->pb.circ_successes),
+                 tor_lround(guard->pb.unusable_circuits),
+                 tor_lround(guard->pb.collapsed_circuits),
+                 tor_lround(guard->pb.timeouts),
                  tor_lround(get_circuit_build_close_time_ms()/1000));
       }
-    } else if (pathbias_get_use_success_count(guard)/guard->use_attempts
+    } else if (pathbias_get_use_success_count(guard)/guard->pb.use_attempts
                < pathbias_get_notice_use_rate(options)) {
-      if (!guard->path_bias_use_noticed) {
-        guard->path_bias_use_noticed = 1;
+      if (!guard->pb.path_bias_use_noticed) {
+        guard->pb.path_bias_use_noticed = 1;
         log_notice(LD_CIRC,
                  "Your Guard %s ($%s) is failing to carry more streams on its "
                  "circuits than usual. "
@@ -1305,13 +1305,13 @@ pathbias_measure_use_rate(entry_guard_t *guard)
                  "For reference, your timeout cutoff is %ld seconds.",
                  guard->nickname, hex_str(guard->identity, DIGEST_LEN),
                  tor_lround(pathbias_get_use_success_count(guard)),
-                 tor_lround(guard->use_attempts),
+                 tor_lround(guard->pb.use_attempts),
                  tor_lround(pathbias_get_close_success_count(guard)),
-                 tor_lround(guard->circ_attempts),
-                 tor_lround(guard->circ_successes),
-                 tor_lround(guard->unusable_circuits),
-                 tor_lround(guard->collapsed_circuits),
-                 tor_lround(guard->timeouts),
+                 tor_lround(guard->pb.circ_attempts),
+                 tor_lround(guard->pb.circ_successes),
+                 tor_lround(guard->pb.unusable_circuits),
+                 tor_lround(guard->pb.collapsed_circuits),
+                 tor_lround(guard->pb.timeouts),
                  tor_lround(get_circuit_build_close_time_ms()/1000));
       }
     }
@@ -1341,15 +1341,15 @@ pathbias_measure_close_rate(entry_guard_t *guard)
 {
   const or_options_t *options = get_options();
 
-  if (guard->circ_attempts > pathbias_get_min_circs(options)) {
+  if (guard->pb.circ_attempts > pathbias_get_min_circs(options)) {
     /* Note: We rely on the < comparison here to allow us to set a 0
      * rate and disable the feature entirely. If refactoring, don't
      * change to <= */
-    if (pathbias_get_close_success_count(guard)/guard->circ_attempts
+    if (pathbias_get_close_success_count(guard)/guard->pb.circ_attempts
         < pathbias_get_extreme_rate(options)) {
       /* Dropping is currently disabled by default. */
       if (pathbias_get_dropguards(options)) {
-        if (!guard->path_bias_disabled) {
+        if (!guard->pb.path_bias_disabled) {
           log_warn(LD_CIRC,
                  "Your Guard %s ($%s) is failing an extremely large "
                  "amount of circuits. "
@@ -1361,21 +1361,21 @@ pathbias_measure_close_rate(entry_guard_t *guard)
                  "For reference, your timeout cutoff is %ld seconds.",
                  guard->nickname, hex_str(guard->identity, DIGEST_LEN),
                  tor_lround(pathbias_get_close_success_count(guard)),
-                 tor_lround(guard->circ_attempts),
+                 tor_lround(guard->pb.circ_attempts),
                  tor_lround(pathbias_get_use_success_count(guard)),
-                 tor_lround(guard->use_attempts),
-                 tor_lround(guard->circ_successes),
-                 tor_lround(guard->unusable_circuits),
-                 tor_lround(guard->collapsed_circuits),
-                 tor_lround(guard->timeouts),
+                 tor_lround(guard->pb.use_attempts),
+                 tor_lround(guard->pb.circ_successes),
+                 tor_lround(guard->pb.unusable_circuits),
+                 tor_lround(guard->pb.collapsed_circuits),
+                 tor_lround(guard->pb.timeouts),
                  tor_lround(get_circuit_build_close_time_ms()/1000));
-          guard->path_bias_disabled = 1;
+          guard->pb.path_bias_disabled = 1;
           guard->bad_since = approx_time();
           entry_guards_changed();
           return;
         }
-      } else if (!guard->path_bias_extreme) {
-        guard->path_bias_extreme = 1;
+      } else if (!guard->pb.path_bias_extreme) {
+        guard->pb.path_bias_extreme = 1;
         log_warn(LD_CIRC,
                  "Your Guard %s ($%s) is failing an extremely large "
                  "amount of circuits. "
@@ -1387,19 +1387,19 @@ pathbias_measure_close_rate(entry_guard_t *guard)
                  "For reference, your timeout cutoff is %ld seconds.",
                  guard->nickname, hex_str(guard->identity, DIGEST_LEN),
                  tor_lround(pathbias_get_close_success_count(guard)),
-                 tor_lround(guard->circ_attempts),
+                 tor_lround(guard->pb.circ_attempts),
                  tor_lround(pathbias_get_use_success_count(guard)),
-                 tor_lround(guard->use_attempts),
-                 tor_lround(guard->circ_successes),
-                 tor_lround(guard->unusable_circuits),
-                 tor_lround(guard->collapsed_circuits),
-                 tor_lround(guard->timeouts),
+                 tor_lround(guard->pb.use_attempts),
+                 tor_lround(guard->pb.circ_successes),
+                 tor_lround(guard->pb.unusable_circuits),
+                 tor_lround(guard->pb.collapsed_circuits),
+                 tor_lround(guard->pb.timeouts),
                  tor_lround(get_circuit_build_close_time_ms()/1000));
       }
-    } else if (pathbias_get_close_success_count(guard)/guard->circ_attempts
+    } else if (pathbias_get_close_success_count(guard)/guard->pb.circ_attempts
                 < pathbias_get_warn_rate(options)) {
-      if (!guard->path_bias_warned) {
-        guard->path_bias_warned = 1;
+      if (!guard->pb.path_bias_warned) {
+        guard->pb.path_bias_warned = 1;
         log_warn(LD_CIRC,
                  "Your Guard %s ($%s) is failing a very large "
                  "amount of circuits. "
@@ -1412,19 +1412,19 @@ pathbias_measure_close_rate(entry_guard_t *guard)
                  "For reference, your timeout cutoff is %ld seconds.",
                  guard->nickname, hex_str(guard->identity, DIGEST_LEN),
                  tor_lround(pathbias_get_close_success_count(guard)),
-                 tor_lround(guard->circ_attempts),
+                 tor_lround(guard->pb.circ_attempts),
                  tor_lround(pathbias_get_use_success_count(guard)),
-                 tor_lround(guard->use_attempts),
-                 tor_lround(guard->circ_successes),
-                 tor_lround(guard->unusable_circuits),
-                 tor_lround(guard->collapsed_circuits),
-                 tor_lround(guard->timeouts),
+                 tor_lround(guard->pb.use_attempts),
+                 tor_lround(guard->pb.circ_successes),
+                 tor_lround(guard->pb.unusable_circuits),
+                 tor_lround(guard->pb.collapsed_circuits),
+                 tor_lround(guard->pb.timeouts),
                  tor_lround(get_circuit_build_close_time_ms()/1000));
       }
-    } else if (pathbias_get_close_success_count(guard)/guard->circ_attempts
+    } else if (pathbias_get_close_success_count(guard)/guard->pb.circ_attempts
                < pathbias_get_notice_rate(options)) {
-      if (!guard->path_bias_noticed) {
-        guard->path_bias_noticed = 1;
+      if (!guard->pb.path_bias_noticed) {
+        guard->pb.path_bias_noticed = 1;
         log_notice(LD_CIRC,
                  "Your Guard %s ($%s) is failing more circuits than "
                  "usual. "
@@ -1435,13 +1435,13 @@ pathbias_measure_close_rate(entry_guard_t *guard)
                  "For reference, your timeout cutoff is %ld seconds.",
                  guard->nickname, hex_str(guard->identity, DIGEST_LEN),
                  tor_lround(pathbias_get_close_success_count(guard)),
-                 tor_lround(guard->circ_attempts),
+                 tor_lround(guard->pb.circ_attempts),
                  tor_lround(pathbias_get_use_success_count(guard)),
-                 tor_lround(guard->use_attempts),
-                 tor_lround(guard->circ_successes),
-                 tor_lround(guard->unusable_circuits),
-                 tor_lround(guard->collapsed_circuits),
-                 tor_lround(guard->timeouts),
+                 tor_lround(guard->pb.use_attempts),
+                 tor_lround(guard->pb.circ_successes),
+                 tor_lround(guard->pb.unusable_circuits),
+                 tor_lround(guard->pb.collapsed_circuits),
+                 tor_lround(guard->pb.timeouts),
                  tor_lround(get_circuit_build_close_time_ms()/1000));
       }
     }
@@ -1463,7 +1463,7 @@ pathbias_scale_close_rates(entry_guard_t *guard)
   const or_options_t *options = get_options();
 
   /* If we get a ton of circuits, just scale everything down */
-  if (guard->circ_attempts > pathbias_get_scale_threshold(options)) {
+  if (guard->pb.circ_attempts > pathbias_get_scale_threshold(options)) {
     double scale_ratio = pathbias_get_scale_ratio(options);
     int opened_attempts = pathbias_count_circs_in_states(guard,
             PATH_STATE_BUILD_ATTEMPTED, PATH_STATE_BUILD_ATTEMPTED);
@@ -1471,36 +1471,36 @@ pathbias_scale_close_rates(entry_guard_t *guard)
                         PATH_STATE_BUILD_SUCCEEDED,
                         PATH_STATE_USE_FAILED);
     /* Verify that the counts are sane before and after scaling */
-    int counts_are_sane = (guard->circ_attempts >= guard->circ_successes);
+    int counts_are_sane = (guard->pb.circ_attempts >= guard->pb.circ_successes);
 
-    guard->circ_attempts -= (opened_attempts+opened_built);
-    guard->circ_successes -= opened_built;
+    guard->pb.circ_attempts -= (opened_attempts+opened_built);
+    guard->pb.circ_successes -= opened_built;
 
-    guard->circ_attempts *= scale_ratio;
-    guard->circ_successes *= scale_ratio;
-    guard->timeouts *= scale_ratio;
-    guard->successful_circuits_closed *= scale_ratio;
-    guard->collapsed_circuits *= scale_ratio;
-    guard->unusable_circuits *= scale_ratio;
+    guard->pb.circ_attempts *= scale_ratio;
+    guard->pb.circ_successes *= scale_ratio;
+    guard->pb.timeouts *= scale_ratio;
+    guard->pb.successful_circuits_closed *= scale_ratio;
+    guard->pb.collapsed_circuits *= scale_ratio;
+    guard->pb.unusable_circuits *= scale_ratio;
 
-    guard->circ_attempts += (opened_attempts+opened_built);
-    guard->circ_successes += opened_built;
+    guard->pb.circ_attempts += (opened_attempts+opened_built);
+    guard->pb.circ_successes += opened_built;
 
     entry_guards_changed();
 
     log_info(LD_CIRC,
              "Scaled pathbias counts to (%f,%f)/%f (%d/%d open) for guard "
              "%s ($%s)",
-             guard->circ_successes, guard->successful_circuits_closed,
-             guard->circ_attempts, opened_built, opened_attempts,
+             guard->pb.circ_successes, guard->pb.successful_circuits_closed,
+             guard->pb.circ_attempts, opened_built, opened_attempts,
              guard->nickname, hex_str(guard->identity, DIGEST_LEN));
 
     /* Have the counts just become invalid by this scaling attempt? */
-    if (counts_are_sane && guard->circ_attempts < guard->circ_successes) {
+    if (counts_are_sane && guard->pb.circ_attempts < guard->pb.circ_successes) {
       log_notice(LD_BUG,
                "Scaling has mangled pathbias counts to %f/%f (%d/%d open) "
                "for guard %s ($%s)",
-               guard->circ_successes, guard->circ_attempts, opened_built,
+               guard->pb.circ_successes, guard->pb.circ_attempts, opened_built,
                opened_attempts, guard->nickname,
                hex_str(guard->identity, DIGEST_LEN));
     }
@@ -1522,31 +1522,31 @@ pathbias_scale_use_rates(entry_guard_t *guard)
   const or_options_t *options = get_options();
 
   /* If we get a ton of circuits, just scale everything down */
-  if (guard->use_attempts > pathbias_get_scale_use_threshold(options)) {
+  if (guard->pb.use_attempts > pathbias_get_scale_use_threshold(options)) {
     double scale_ratio = pathbias_get_scale_ratio(options);
     int opened_attempts = pathbias_count_circs_in_states(guard,
             PATH_STATE_USE_ATTEMPTED, PATH_STATE_USE_SUCCEEDED);
     /* Verify that the counts are sane before and after scaling */
-    int counts_are_sane = (guard->use_attempts >= guard->use_successes);
+    int counts_are_sane = (guard->pb.use_attempts >= guard->pb.use_successes);
 
-    guard->use_attempts -= opened_attempts;
+    guard->pb.use_attempts -= opened_attempts;
 
-    guard->use_attempts *= scale_ratio;
-    guard->use_successes *= scale_ratio;
+    guard->pb.use_attempts *= scale_ratio;
+    guard->pb.use_successes *= scale_ratio;
 
-    guard->use_attempts += opened_attempts;
+    guard->pb.use_attempts += opened_attempts;
 
     log_info(LD_CIRC,
            "Scaled pathbias use counts to %f/%f (%d open) for guard %s ($%s)",
-           guard->use_successes, guard->use_attempts, opened_attempts,
+           guard->pb.use_successes, guard->pb.use_attempts, opened_attempts,
            guard->nickname, hex_str(guard->identity, DIGEST_LEN));
 
     /* Have the counts just become invalid by this scaling attempt? */
-    if (counts_are_sane && guard->use_attempts < guard->use_successes) {
+    if (counts_are_sane && guard->pb.use_attempts < guard->pb.use_successes) {
       log_notice(LD_BUG,
                "Scaling has mangled pathbias usage counts to %f/%f "
                "(%d open) for guard %s ($%s)",
-               guard->circ_successes, guard->circ_attempts,
+               guard->pb.circ_successes, guard->pb.circ_attempts,
                opened_attempts, guard->nickname,
                hex_str(guard->identity, DIGEST_LEN));
     }
diff --git a/src/or/entrynodes.c b/src/or/entrynodes.c
index 434f2f6..c1940a1 100644
--- a/src/or/entrynodes.c
+++ b/src/or/entrynodes.c
@@ -192,7 +192,7 @@ entry_guard_set_status(entry_guard_t *e, const node_t *node,
   /* We only care about OR connection connectivity for entry guards. */
   else if (!fascist_firewall_allows_node(node, FIREWALL_OR_CONNECTION, 0))
     *reason = "unreachable by config";
-  else if (e->path_bias_disabled)
+  else if (e->pb.path_bias_disabled)
     *reason = "path-biased";
 
   if (*reason && ! e->bad_since) {
@@ -297,7 +297,7 @@ entry_is_live(const entry_guard_t *e, entry_is_live_flags_t flags,
 
   tor_assert(msg);
 
-  if (e->path_bias_disabled) {
+  if (e->pb.path_bias_disabled) {
     *msg = "path-biased";
     return NULL;
   }
@@ -748,7 +748,7 @@ remove_dead_entry_guards(guard_selection_t *gs, time_t now)
   for (i = 0; i < smartlist_len(gs->chosen_entry_guards); ) {
     entry_guard_t *entry = smartlist_get(gs->chosen_entry_guards, i);
     if (entry->bad_since &&
-        ! entry->path_bias_disabled &&
+        ! entry->pb.path_bias_disabled &&
         entry->bad_since + ENTRY_GUARD_REMOVE_AFTER < now) {
 
       base16_encode(dbuf, sizeof(dbuf), entry->identity, DIGEST_LEN);
@@ -1534,22 +1534,22 @@ entry_guards_parse_state_for_guard_selection(
         success_cnt = use_cnt;
       }
 
-      node->use_attempts = use_cnt;
-      node->use_successes = success_cnt;
+      node->pb.use_attempts = use_cnt;
+      node->pb.use_successes = success_cnt;
 
       log_info(LD_GENERAL, "Read %f/%f path use bias for node %s",
-               node->use_successes, node->use_attempts, node->nickname);
+               node->pb.use_successes, node->pb.use_attempts, node->nickname);
 
       /* Note: We rely on the < comparison here to allow us to set a 0
        * rate and disable the feature entirely. If refactoring, don't
        * change to <= */
-      if (pathbias_get_use_success_count(node)/node->use_attempts
+      if (pathbias_get_use_success_count(node)/node->pb.use_attempts
             < pathbias_get_extreme_use_rate(options) &&
           pathbias_get_dropguards(options)) {
-        node->path_bias_disabled = 1;
+        node->pb.path_bias_disabled = 1;
         log_info(LD_GENERAL,
                  "Path use bias is too high (%f/%f); disabling node %s",
-                 node->circ_successes, node->circ_attempts, node->nickname);
+                 node->pb.circ_successes, node->pb.circ_attempts, node->nickname);
       }
     } else if (!strcasecmp(line->key, "EntryGuardPathBias")) {
       const or_options_t *options = get_options();
@@ -1599,26 +1599,26 @@ entry_guards_parse_state_for_guard_selection(
         success_cnt = hop_cnt;
       }
 
-      node->circ_attempts = hop_cnt;
-      node->circ_successes = success_cnt;
+      node->pb.circ_attempts = hop_cnt;
+      node->pb.circ_successes = success_cnt;
 
-      node->successful_circuits_closed = successful_closed;
-      node->timeouts = timeouts;
-      node->collapsed_circuits = collapsed;
-      node->unusable_circuits = unusable;
+      node->pb.successful_circuits_closed = successful_closed;
+      node->pb.timeouts = timeouts;
+      node->pb.collapsed_circuits = collapsed;
+      node->pb.unusable_circuits = unusable;
 
       log_info(LD_GENERAL, "Read %f/%f path bias for node %s",
-               node->circ_successes, node->circ_attempts, node->nickname);
+               node->pb.circ_successes, node->pb.circ_attempts, node->nickname);
       /* Note: We rely on the < comparison here to allow us to set a 0
        * rate and disable the feature entirely. If refactoring, don't
        * change to <= */
-      if (pathbias_get_close_success_count(node)/node->circ_attempts
+      if (pathbias_get_close_success_count(node)/node->pb.circ_attempts
             < pathbias_get_extreme_rate(options) &&
           pathbias_get_dropguards(options)) {
-        node->path_bias_disabled = 1;
+        node->pb.path_bias_disabled = 1;
         log_info(LD_GENERAL,
                  "Path bias is too high (%f/%f); disabling node %s",
-                 node->circ_successes, node->circ_attempts, node->nickname);
+                 node->pb.circ_successes, node->pb.circ_attempts, node->nickname);
       }
 
     } else {
@@ -1644,7 +1644,7 @@ entry_guards_parse_state_for_guard_selection(
          e->chosen_by_version = tor_strdup(state_version);
        }
      }
-     if (e->path_bias_disabled && !e->bad_since)
+     if (e->pb.path_bias_disabled && !e->bad_since)
        e->bad_since = time(NULL);
     }
   SMARTLIST_FOREACH_END(e);
@@ -1788,25 +1788,25 @@ entry_guards_update_state(or_state_t *state)
                      d, e->chosen_by_version, t);
         next = &(line->next);
       }
-      if (e->circ_attempts > 0) {
+      if (e->pb.circ_attempts > 0) {
         *next = line = tor_malloc_zero(sizeof(config_line_t));
         line->key = tor_strdup("EntryGuardPathBias");
         /* In the long run: circuit_success ~= successful_circuit_close +
          *                                     collapsed_circuits +
          *                                     unusable_circuits */
         tor_asprintf(&line->value, "%f %f %f %f %f %f",
-                     e->circ_attempts, e->circ_successes,
+                     e->pb.circ_attempts, e->pb.circ_successes,
                      pathbias_get_close_success_count(e),
-                     e->collapsed_circuits,
-                     e->unusable_circuits, e->timeouts);
+                     e->pb.collapsed_circuits,
+                     e->pb.unusable_circuits, e->pb.timeouts);
         next = &(line->next);
       }
-      if (e->use_attempts > 0) {
+      if (e->pb.use_attempts > 0) {
         *next = line = tor_malloc_zero(sizeof(config_line_t));
         line->key = tor_strdup("EntryGuardPathUseBias");
 
         tor_asprintf(&line->value, "%f %f",
-                     e->use_attempts,
+                     e->pb.use_attempts,
                      pathbias_get_use_success_count(e));
         next = &(line->next);
       }
diff --git a/src/or/entrynodes.h b/src/or/entrynodes.h
index 7f5a911..3320c5c 100644
--- a/src/or/entrynodes.h
+++ b/src/or/entrynodes.h
@@ -18,22 +18,11 @@ typedef struct guard_selection_s guard_selection_t;
 /* Forward declare for entry_guard_t; the real declaration is private. */
 typedef struct entry_guard_t entry_guard_t;
 
-#if defined(ENTRYNODES_PRIVATE) || defined(ENTRYNODES_EXPOSE_STRUCT)
-/** An entry_guard_t represents our information about a chosen long-term
- * first hop, known as a "helper" node in the literature. We can't just
- * use a node_t, since we want to remember these even when we
- * don't have any directory info. */
-struct entry_guard_t {
-  char nickname[MAX_NICKNAME_LEN+1];
-  char identity[DIGEST_LEN];
-  time_t chosen_on_date; /**< Approximately when was this guard added?
-                          * "0" if we don't know. */
-  char *chosen_by_version; /**< What tor version added this guard? NULL
-                            * if we don't know. */
-  unsigned int made_contact : 1; /**< 0 if we have never connected to this
-                                  * router, 1 if we have. */
-  unsigned int can_retry : 1; /**< Should we retry connecting to this entry,
-                               * in spite of having it marked as unreachable?*/
+/* Information about a guard's pathbias status.
+ * These fields are used in circpathbias.c to try to detect entry
+ * nodes that are failing circuits at a suspicious frequency.
+ */
+typedef struct guard_pathbias_t {
   unsigned int path_bias_noticed : 1; /**< Did we alert the user about path
                                        * bias for this node already? */
   unsigned int path_bias_warned : 1; /**< Did we alert the user about path bias
@@ -46,23 +35,6 @@ struct entry_guard_t {
                                        * use bias for this node already? */
   unsigned int path_bias_use_extreme : 1; /**< Did we alert the user about path
                                        * use bias for this node already? */
-  unsigned int is_dir_cache : 1; /**< Is this node a directory cache? */
-  time_t bad_since; /**< 0 if this guard is currently usable, or the time at
-                      * which it was observed to become (according to the
-                      * directory or the user configuration) unusable. */
-  time_t unreachable_since; /**< 0 if we can connect to this guard, or the
-                             * time at which we first noticed we couldn't
-                             * connect to it. */
-  time_t last_attempted; /**< 0 if we can connect to this guard, or the time
-                          * at which we last failed to connect to it. */
-
-  /**
-   * @name circpathbias fields
-   *
-   * These fields are used in circpathbias.c to try to detect entry
-   * nodes that are failing circuits at a suspicious frequency.
-   */
-  /**@{*/
 
   double circ_attempts; /**< Number of circuits this guard has "attempted" */
   double circ_successes; /**< Number of successfully built circuits using
@@ -79,7 +51,36 @@ struct entry_guard_t {
   double use_attempts; /**< Number of circuits we tried to use with streams */
   double use_successes; /**< Number of successfully used circuits using
                                * this guard as first hop. */
-  /**@}*/
+} guard_pathbias_t;
+
+#if defined(ENTRYNODES_PRIVATE) || defined(ENTRYNODES_EXPOSE_STRUCT)
+/** An entry_guard_t represents our information about a chosen long-term
+ * first hop, known as a "helper" node in the literature. We can't just
+ * use a node_t, since we want to remember these even when we
+ * don't have any directory info. */
+struct entry_guard_t {
+  char nickname[MAX_NICKNAME_LEN+1];
+  char identity[DIGEST_LEN];
+  time_t chosen_on_date; /**< Approximately when was this guard added?
+                          * "0" if we don't know. */
+  char *chosen_by_version; /**< What tor version added this guard? NULL
+                            * if we don't know. */
+  unsigned int made_contact : 1; /**< 0 if we have never connected to this
+                                  * router, 1 if we have. */
+  unsigned int can_retry : 1; /**< Should we retry connecting to this entry,
+                               * in spite of having it marked as unreachable?*/
+  unsigned int is_dir_cache : 1; /**< Is this node a directory cache? */
+  time_t bad_since; /**< 0 if this guard is currently usable, or the time at
+                      * which it was observed to become (according to the
+                      * directory or the user configuration) unusable. */
+  time_t unreachable_since; /**< 0 if we can connect to this guard, or the
+                             * time at which we first noticed we couldn't
+                             * connect to it. */
+  time_t last_attempted; /**< 0 if we can connect to this guard, or the time
+                          * at which we last failed to connect to it. */
+
+  /** Path bias information for this guard. */
+  guard_pathbias_t pb;
 };
 #endif
 
diff --git a/src/test/test_entrynodes.c b/src/test/test_entrynodes.c
index 8e4f406..781fa4d 100644
--- a/src/test/test_entrynodes.c
+++ b/src/test/test_entrynodes.c
@@ -477,12 +477,12 @@ test_entry_guards_parse_state_simple(void *arg)
     /* The rest should be unset */
     tt_assert(!e->unreachable_since);
     tt_assert(!e->can_retry);
-    tt_assert(!e->path_bias_noticed);
-    tt_assert(!e->path_bias_warned);
-    tt_assert(!e->path_bias_extreme);
-    tt_assert(!e->path_bias_disabled);
-    tt_assert(!e->path_bias_use_noticed);
-    tt_assert(!e->path_bias_use_extreme);
+    tt_assert(!e->pb.path_bias_noticed);
+    tt_assert(!e->pb.path_bias_warned);
+    tt_assert(!e->pb.path_bias_extreme);
+    tt_assert(!e->pb.path_bias_disabled);
+    tt_assert(!e->pb.path_bias_use_noticed);
+    tt_assert(!e->pb.path_bias_use_extreme);
     tt_assert(!e->last_attempted);
   }
 
@@ -563,13 +563,13 @@ test_entry_guards_parse_state_pathbias(void *arg)
     tt_assert(!e->can_retry);
 
     /* XXX tt_double_op doesn't support equality. Cast to int for now. */
-    tt_int_op((int)e->circ_attempts, OP_EQ, (int)circ_attempts);
-    tt_int_op((int)e->circ_successes, OP_EQ, (int)circ_successes);
-    tt_int_op((int)e->successful_circuits_closed, OP_EQ,
+    tt_int_op((int)e->pb.circ_attempts, OP_EQ, (int)circ_attempts);
+    tt_int_op((int)e->pb.circ_successes, OP_EQ, (int)circ_successes);
+    tt_int_op((int)e->pb.successful_circuits_closed, OP_EQ,
               (int)successful_closed);
-    tt_int_op((int)e->timeouts, OP_EQ, (int)timeouts);
-    tt_int_op((int)e->collapsed_circuits, OP_EQ, (int)collapsed);
-    tt_int_op((int)e->unusable_circuits, OP_EQ, (int)unusable);
+    tt_int_op((int)e->pb.timeouts, OP_EQ, (int)timeouts);
+    tt_int_op((int)e->pb.collapsed_circuits, OP_EQ, (int)collapsed);
+    tt_int_op((int)e->pb.unusable_circuits, OP_EQ, (int)unusable);
   }
 
  done:



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