[tor-commits] [tor/master] Separate mutable/const accessors for circuit_build_times

nickm at torproject.org nickm at torproject.org
Thu Aug 22 14:22:30 UTC 2013


commit 775c491502e43f0490023b2917c4e1a05b38b5b8
Author: Nick Mathewson <nickm at torproject.org>
Date:   Wed Aug 21 12:10:05 2013 -0400

    Separate mutable/const accessors for circuit_build_times
    
    (These have proved invaluable for other global accessors.)
---
 src/or/channel.c       |    2 +-
 src/or/circuitbuild.c  |    6 +++---
 src/or/circuitlist.c   |    2 +-
 src/or/circuitstats.c  |   22 ++++++++++++++--------
 src/or/circuitstats.h  |   13 +++++++------
 src/or/circuituse.c    |   12 +++++++-----
 src/or/connection_or.c |    8 ++++----
 src/or/entrynodes.c    |    2 +-
 src/or/networkstatus.c |    2 +-
 src/or/statefile.c     |    2 +-
 10 files changed, 40 insertions(+), 31 deletions(-)

diff --git a/src/or/channel.c b/src/or/channel.c
index 8743437..7f39549 100644
--- a/src/or/channel.c
+++ b/src/or/channel.c
@@ -2361,7 +2361,7 @@ channel_do_open_actions(channel_t *chan)
   started_here = channel_is_outgoing(chan);
 
   if (started_here) {
-    circuit_build_times_network_is_live(get_circuit_build_times());
+    circuit_build_times_network_is_live(get_circuit_build_times_mutable());
     rep_hist_note_connect_succeeded(chan->identity_digest, now);
     if (entry_guard_register_connect_status(
           chan->identity_digest, 1, 0, now) < 0) {
diff --git a/src/or/circuitbuild.c b/src/or/circuitbuild.c
index cb2f423..a203cee 100644
--- a/src/or/circuitbuild.c
+++ b/src/or/circuitbuild.c
@@ -782,14 +782,14 @@ circuit_send_next_onion_skin(origin_circuit_t *circ)
           /* Only count circuit times if the network is live */
           if (circuit_build_times_network_check_live(
               get_circuit_build_times())) {
-            circuit_build_times_add_time(get_circuit_build_times(),
+            circuit_build_times_add_time(get_circuit_build_times_mutable(),
                 (build_time_t)timediff);
-            circuit_build_times_set_timeout(get_circuit_build_times());
+            circuit_build_times_set_timeout(get_circuit_build_times_mutable());
           }
 
           if (circ->base_.purpose != CIRCUIT_PURPOSE_C_MEASURE_TIMEOUT) {
             circuit_build_times_network_circ_success(
-                get_circuit_build_times());
+                get_circuit_build_times_mutable());
           }
         }
       }
diff --git a/src/or/circuitlist.c b/src/or/circuitlist.c
index 1edea85..50caf37 100644
--- a/src/or/circuitlist.c
+++ b/src/or/circuitlist.c
@@ -678,7 +678,7 @@ origin_circuit_new(void)
 
   init_circuit_base(TO_CIRCUIT(circ));
 
-  get_circuit_build_times()->last_circ_at = approx_time();
+  get_circuit_build_times_mutable()->last_circ_at = approx_time();
 
   return circ;
 }
diff --git a/src/or/circuitstats.c b/src/or/circuitstats.c
index 25813de..0d60a19 100644
--- a/src/or/circuitstats.c
+++ b/src/or/circuitstats.c
@@ -36,12 +36,18 @@ static int unit_tests = 0;
 #define unit_tests 0
 #endif
 
-circuit_build_times_t *
+const circuit_build_times_t *
 get_circuit_build_times(void)
 {
   return &circ_times;
 }
 
+circuit_build_times_t *
+get_circuit_build_times_mutable(void)
+{
+  return &circ_times;
+}
+
 double
 get_circuit_build_close_time_ms(void)
 {
@@ -175,7 +181,7 @@ circuit_build_times_min_circs_to_observe(void)
 /** Return true iff <b>cbt</b> has recorded enough build times that we
  * want to start acting on the timeout it implies. */
 int
-circuit_build_times_enough_to_compute(circuit_build_times_t *cbt)
+circuit_build_times_enough_to_compute(const circuit_build_times_t *cbt)
 {
   return cbt->total_build_times >= circuit_build_times_min_circs_to_observe();
 }
@@ -578,7 +584,7 @@ circuit_build_times_add_time(circuit_build_times_t *cbt, build_time_t time)
  * Return maximum circuit build time
  */
 static build_time_t
-circuit_build_times_max(circuit_build_times_t *cbt)
+circuit_build_times_max(const circuit_build_times_t *cbt)
 {
   int i = 0;
   build_time_t max_build_time = 0;
@@ -619,7 +625,7 @@ circuit_build_times_min(circuit_build_times_t *cbt)
  * The return value must be freed by the caller.
  */
 static uint32_t *
-circuit_build_times_create_histogram(circuit_build_times_t *cbt,
+circuit_build_times_create_histogram(const circuit_build_times_t *cbt,
                                      build_time_t *nbins)
 {
   uint32_t *histogram;
@@ -709,7 +715,7 @@ circuit_build_times_get_xm(circuit_build_times_t *cbt)
  * the or_state_t state structure.
  */
 void
-circuit_build_times_update_state(circuit_build_times_t *cbt,
+circuit_build_times_update_state(const circuit_build_times_t *cbt,
                                  or_state_t *state)
 {
   uint32_t *histogram;
@@ -1146,7 +1152,7 @@ circuit_build_times_initial_alpha(circuit_build_times_t *cbt,
  * Returns true if we need circuits to be built
  */
 int
-circuit_build_times_needs_circuits(circuit_build_times_t *cbt)
+circuit_build_times_needs_circuits(const circuit_build_times_t *cbt)
 {
   /* Return true if < MIN_CIRCUITS_TO_OBSERVE */
   return !circuit_build_times_enough_to_compute(cbt);
@@ -1157,7 +1163,7 @@ circuit_build_times_needs_circuits(circuit_build_times_t *cbt)
  * right now.
  */
 int
-circuit_build_times_needs_circuits_now(circuit_build_times_t *cbt)
+circuit_build_times_needs_circuits_now(const circuit_build_times_t *cbt)
 {
   return circuit_build_times_needs_circuits(cbt) &&
     approx_time()-cbt->last_circ_at > circuit_build_times_test_frequency();
@@ -1290,7 +1296,7 @@ circuit_build_times_network_close(circuit_build_times_t *cbt,
  * in the case of recent liveness changes.
  */
 int
-circuit_build_times_network_check_live(circuit_build_times_t *cbt)
+circuit_build_times_network_check_live(const circuit_build_times_t *cbt)
 {
   if (cbt->liveness.nonlive_timeouts > 0) {
     return 0;
diff --git a/src/or/circuitstats.h b/src/or/circuitstats.h
index 4115b68..196af3f 100644
--- a/src/or/circuitstats.h
+++ b/src/or/circuitstats.h
@@ -12,13 +12,14 @@
 #ifndef TOR_CIRCUITSTATS_H
 #define TOR_CIRCUITSTATS_H
 
-circuit_build_times_t *get_circuit_build_times(void);
+const circuit_build_times_t *get_circuit_build_times(void);
+circuit_build_times_t *get_circuit_build_times_mutable(void);
 double get_circuit_build_close_time_ms(void);
 double get_circuit_build_timeout_ms(void);
 
 int circuit_build_times_disabled(void);
-int circuit_build_times_enough_to_compute(circuit_build_times_t *cbt);
-void circuit_build_times_update_state(circuit_build_times_t *cbt,
+int circuit_build_times_enough_to_compute(const circuit_build_times_t *cbt);
+void circuit_build_times_update_state(const circuit_build_times_t *cbt,
                                       or_state_t *state);
 int circuit_build_times_parse_state(circuit_build_times_t *cbt,
                                     or_state_t *state);
@@ -29,9 +30,9 @@ int circuit_build_times_count_close(circuit_build_times_t *cbt,
 void circuit_build_times_set_timeout(circuit_build_times_t *cbt);
 int circuit_build_times_add_time(circuit_build_times_t *cbt,
                                  build_time_t time);
-int circuit_build_times_needs_circuits(circuit_build_times_t *cbt);
+int circuit_build_times_needs_circuits(const circuit_build_times_t *cbt);
 
-int circuit_build_times_needs_circuits_now(circuit_build_times_t *cbt);
+int circuit_build_times_needs_circuits_now(const circuit_build_times_t *cbt);
 void circuit_build_times_init(circuit_build_times_t *cbt);
 void circuit_build_times_free_timeouts(circuit_build_times_t *cbt);
 void circuit_build_times_new_consensus_params(circuit_build_times_t *cbt,
@@ -61,7 +62,7 @@ void circuitbuild_running_unit_tests(void);
 
 /* Network liveness functions */
 void circuit_build_times_network_is_live(circuit_build_times_t *cbt);
-int circuit_build_times_network_check_live(circuit_build_times_t *cbt);
+int circuit_build_times_network_check_live(const circuit_build_times_t *cbt);
 void circuit_build_times_network_circ_success(circuit_build_times_t *cbt);
 
 #endif
diff --git a/src/or/circuituse.c b/src/or/circuituse.c
index 919ca35..e3c0d0c 100644
--- a/src/or/circuituse.c
+++ b/src/or/circuituse.c
@@ -545,7 +545,7 @@ circuit_expire_building(void)
            * was a timeout, and the timeout value needs to reset if we
            * see enough of them. Note this means we also need to avoid
            * double-counting below, too. */
-          circuit_build_times_count_timeout(get_circuit_build_times(),
+          circuit_build_times_count_timeout(get_circuit_build_times_mutable(),
               first_hop_succeeded);
           TO_ORIGIN_CIRCUIT(victim)->relaxed_timeout = 1;
         }
@@ -658,8 +658,9 @@ circuit_expire_building(void)
            * have a timeout. We also want to avoid double-counting
            * already "relaxed" circuits, which are counted above. */
           if (!TO_ORIGIN_CIRCUIT(victim)->relaxed_timeout) {
-            circuit_build_times_count_timeout(get_circuit_build_times(),
-                                              first_hop_succeeded);
+            circuit_build_times_count_timeout(
+                                         get_circuit_build_times_mutable(),
+                                         first_hop_succeeded);
           }
           continue;
         }
@@ -676,10 +677,11 @@ circuit_expire_building(void)
                      (long)(now.tv_sec - victim->timestamp_began.tv_sec),
                      victim->purpose,
                      circuit_purpose_to_string(victim->purpose));
-        } else if (circuit_build_times_count_close(get_circuit_build_times(),
+        } else if (circuit_build_times_count_close(
+                                         get_circuit_build_times_mutable(),
                                          first_hop_succeeded,
                                          victim->timestamp_created.tv_sec)) {
-          circuit_build_times_set_timeout(get_circuit_build_times());
+          circuit_build_times_set_timeout(get_circuit_build_times_mutable());
         }
       }
     }
diff --git a/src/or/connection_or.c b/src/or/connection_or.c
index b7e72fd..7912bfb 100644
--- a/src/or/connection_or.c
+++ b/src/or/connection_or.c
@@ -1749,7 +1749,7 @@ connection_tls_finish_handshake(or_connection_t *conn)
                                               digest_rcvd) < 0)
     return -1;
 
-  circuit_build_times_network_is_live(get_circuit_build_times());
+  circuit_build_times_network_is_live(get_circuit_build_times_mutable());
 
   if (tor_tls_used_v1_handshake(conn->tls)) {
     conn->link_proto = 1;
@@ -1783,7 +1783,7 @@ connection_or_launch_v3_or_handshake(or_connection_t *conn)
   tor_assert(connection_or_nonopen_was_started_here(conn));
   tor_assert(tor_tls_received_v3_certificate(conn->tls));
 
-  circuit_build_times_network_is_live(get_circuit_build_times());
+  circuit_build_times_network_is_live(get_circuit_build_times_mutable());
 
   connection_or_change_state(conn, OR_CONN_STATE_OR_HANDSHAKING_V3);
   if (connection_init_or_handshake_state(conn, 1) < 0)
@@ -2016,7 +2016,7 @@ connection_or_process_cells_from_inbuf(or_connection_t *conn)
       if (conn->chan)
         channel_timestamp_active(TLS_CHAN_TO_BASE(conn->chan));
 
-      circuit_build_times_network_is_live(get_circuit_build_times());
+      circuit_build_times_network_is_live(get_circuit_build_times_mutable());
       channel_tls_handle_var_cell(var_cell, conn);
       var_cell_free(var_cell);
     } else {
@@ -2032,7 +2032,7 @@ connection_or_process_cells_from_inbuf(or_connection_t *conn)
       if (conn->chan)
         channel_timestamp_active(TLS_CHAN_TO_BASE(conn->chan));
 
-      circuit_build_times_network_is_live(get_circuit_build_times());
+      circuit_build_times_network_is_live(get_circuit_build_times_mutable());
       connection_fetch_from_buf(buf, cell_network_size, TO_CONN(conn));
 
       /* retrieve cell info from buf (create the host-order struct from the
diff --git a/src/or/entrynodes.c b/src/or/entrynodes.c
index b3764a9..b66cc2b 100644
--- a/src/or/entrynodes.c
+++ b/src/or/entrynodes.c
@@ -2279,6 +2279,6 @@ entry_guards_free_all(void)
   clear_bridge_list();
   smartlist_free(bridge_list);
   bridge_list = NULL;
-  circuit_build_times_free_timeouts(get_circuit_build_times());
+  circuit_build_times_free_timeouts(get_circuit_build_times_mutable());
 }
 
diff --git a/src/or/networkstatus.c b/src/or/networkstatus.c
index 8b4a791..35a20b0 100644
--- a/src/or/networkstatus.c
+++ b/src/or/networkstatus.c
@@ -1822,7 +1822,7 @@ networkstatus_set_current_consensus(const char *consensus,
      * current consensus really alter our view of any OR's rate limits? */
     connection_or_update_token_buckets(get_connection_array(), options);
 
-    circuit_build_times_new_consensus_params(get_circuit_build_times(),
+    circuit_build_times_new_consensus_params(get_circuit_build_times_mutable(),
         current_consensus);
   }
 
diff --git a/src/or/statefile.c b/src/or/statefile.c
index 4b61fde..db9091c 100644
--- a/src/or/statefile.c
+++ b/src/or/statefile.c
@@ -239,7 +239,7 @@ or_state_set(or_state_t *new_state)
     ret = -1;
   }
   if (circuit_build_times_parse_state(
-      get_circuit_build_times(),global_state) < 0) {
+      get_circuit_build_times_mutable(),global_state) < 0) {
     ret = -1;
   }
   return ret;





More information about the tor-commits mailing list