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

[tor-commits] [tor/master] Relocate CBT event to control_events.c



commit 220ed863ceac693583aa0e8127866df11110643a
Author: Mike Perry <mikeperry-git@xxxxxxxxxxxxxx>
Date:   Mon Jun 22 14:45:19 2020 -0500

    Relocate CBT event to control_events.c
    
    Needed to satisfy practracker.
---
 src/core/or/circuitstats.c           | 58 -----------------------------------
 src/core/or/circuitstats.h           |  7 -----
 src/feature/control/control_events.c | 59 ++++++++++++++++++++++++++++++++++++
 src/feature/control/control_events.h |  2 ++
 4 files changed, 61 insertions(+), 65 deletions(-)

diff --git a/src/core/or/circuitstats.c b/src/core/or/circuitstats.c
index 08d12d0d6..6a9d84df9 100644
--- a/src/core/or/circuitstats.c
+++ b/src/core/or/circuitstats.c
@@ -1890,61 +1890,3 @@ circuit_build_times_update_last_circ(circuit_build_times_t *cbt)
 {
   cbt->last_circ_at = approx_time();
 }
-
-void
-cbt_control_event_buildtimeout_set(const circuit_build_times_t *cbt,
-                                   buildtimeout_set_event_t type)
-{
-  char *args = NULL;
-  double qnt;
-  double timeout_rate = 0.0;
-  double close_rate = 0.0;
-
-  switch (type) {
-    case BUILDTIMEOUT_SET_EVENT_RESET:
-    case BUILDTIMEOUT_SET_EVENT_SUSPENDED:
-    case BUILDTIMEOUT_SET_EVENT_DISCARD:
-      qnt = 1.0;
-      break;
-    case BUILDTIMEOUT_SET_EVENT_COMPUTED:
-    case BUILDTIMEOUT_SET_EVENT_RESUME:
-    default:
-      qnt = circuit_build_times_quantile_cutoff();
-      break;
-  }
-
-  /* The timeout rate is the ratio of the timeout count over
-   * the total number of circuits attempted. The total number of
-   * circuits is (timeouts+succeeded), since every circuit
-   * either succeeds, or times out. "Closed" circuits are
-   * MEASURE_TIMEOUT circuits whose measurement period expired.
-   * All MEASURE_TIMEOUT circuits are counted in the timeouts stat
-   * before transitioning to MEASURE_TIMEOUT (in
-   * circuit_build_times_mark_circ_as_measurement_only()).
-   * MEASURE_TIMEOUT circuits that succeed are *not* counted as
-   * "succeeded". See circuit_build_times_handle_completed_hop().
-   *
-   * We cast the denominator
-   * to promote it to double before the addition, to avoid int32
-   * overflow. */
-  const double total_circuits =
-    ((double)cbt->num_circ_timeouts) + cbt->num_circ_succeeded;
-  if (total_circuits >= 1.0) {
-    timeout_rate = cbt->num_circ_timeouts / total_circuits;
-    close_rate = cbt->num_circ_closed / total_circuits;
-  }
-
-  tor_asprintf(&args, "TOTAL_TIMES=%lu "
-               "TIMEOUT_MS=%lu XM=%lu ALPHA=%f CUTOFF_QUANTILE=%f "
-               "TIMEOUT_RATE=%f CLOSE_MS=%lu CLOSE_RATE=%f",
-               (unsigned long)cbt->total_build_times,
-               (unsigned long)cbt->timeout_ms,
-               (unsigned long)cbt->Xm, cbt->alpha, qnt,
-               timeout_rate,
-               (unsigned long)cbt->close_ms,
-               close_rate);
-
-  control_event_buildtimeout_set(type, args);
-
-  tor_free(args);
-}
diff --git a/src/core/or/circuitstats.h b/src/core/or/circuitstats.h
index a89fc1e96..317eeac20 100644
--- a/src/core/or/circuitstats.h
+++ b/src/core/or/circuitstats.h
@@ -12,8 +12,6 @@
 #ifndef TOR_CIRCUITSTATS_H
 #define TOR_CIRCUITSTATS_H
 
-#include "feature/control/control_events.h"
-
 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);
@@ -52,9 +50,6 @@ double circuit_build_times_close_rate(const circuit_build_times_t *cbt);
 void circuit_build_times_update_last_circ(circuit_build_times_t *cbt);
 void circuit_build_times_mark_circ_as_measurement_only(origin_circuit_t *circ);
 void circuit_build_times_reset(circuit_build_times_t *cbt);
-void cbt_control_event_buildtimeout_set(
-                                  const circuit_build_times_t *cbt,
-                                  buildtimeout_set_event_t type);
 
 /** Total size of the circuit timeout history to accumulate.
  * 1000 is approx 2.5 days worth of continual-use circuits. */
@@ -163,7 +158,6 @@ void circuit_build_times_network_is_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);
 
-#ifdef CIRCUITSTATS_PRIVATE
 /** Information about the state of our local network connection */
 typedef struct {
   /** The timestamp we last completed a TLS handshake or received a cell */
@@ -213,6 +207,5 @@ struct circuit_build_times_t {
   uint32_t num_circ_closed;
 
 };
-#endif /* defined(CIRCUITSTATS_PRIVATE) */
 
 #endif /* !defined(TOR_CIRCUITSTATS_H) */
diff --git a/src/feature/control/control_events.c b/src/feature/control/control_events.c
index 916ccea87..8e69c772f 100644
--- a/src/feature/control/control_events.c
+++ b/src/feature/control/control_events.c
@@ -17,6 +17,7 @@
 #include "core/mainloop/mainloop.h"
 #include "core/or/channeltls.h"
 #include "core/or/circuitlist.h"
+#include "core/or/circuitstats.h"
 #include "core/or/command.h"
 #include "core/or/connection_edge.h"
 #include "core/or/connection_or.h"
@@ -141,6 +142,64 @@ clear_circ_bw_fields(void)
   SMARTLIST_FOREACH_END(circ);
 }
 
+/* Helper to emit the BUILDTIMEOUT_SET circuit build time event */
+void
+cbt_control_event_buildtimeout_set(const circuit_build_times_t *cbt,
+                                   buildtimeout_set_event_t type)
+{
+  char *args = NULL;
+  double qnt;
+  double timeout_rate = 0.0;
+  double close_rate = 0.0;
+
+  switch (type) {
+    case BUILDTIMEOUT_SET_EVENT_RESET:
+    case BUILDTIMEOUT_SET_EVENT_SUSPENDED:
+    case BUILDTIMEOUT_SET_EVENT_DISCARD:
+      qnt = 1.0;
+      break;
+    case BUILDTIMEOUT_SET_EVENT_COMPUTED:
+    case BUILDTIMEOUT_SET_EVENT_RESUME:
+    default:
+      qnt = circuit_build_times_quantile_cutoff();
+      break;
+  }
+
+  /* The timeout rate is the ratio of the timeout count over
+   * the total number of circuits attempted. The total number of
+   * circuits is (timeouts+succeeded), since every circuit
+   * either succeeds, or times out. "Closed" circuits are
+   * MEASURE_TIMEOUT circuits whose measurement period expired.
+   * All MEASURE_TIMEOUT circuits are counted in the timeouts stat
+   * before transitioning to MEASURE_TIMEOUT (in
+   * circuit_build_times_mark_circ_as_measurement_only()).
+   * MEASURE_TIMEOUT circuits that succeed are *not* counted as
+   * "succeeded". See circuit_build_times_handle_completed_hop().
+   *
+   * We cast the denominator
+   * to promote it to double before the addition, to avoid int32
+   * overflow. */
+  const double total_circuits =
+    ((double)cbt->num_circ_timeouts) + cbt->num_circ_succeeded;
+  if (total_circuits >= 1.0) {
+    timeout_rate = cbt->num_circ_timeouts / total_circuits;
+    close_rate = cbt->num_circ_closed / total_circuits;
+  }
+
+  tor_asprintf(&args, "TOTAL_TIMES=%lu "
+               "TIMEOUT_MS=%lu XM=%lu ALPHA=%f CUTOFF_QUANTILE=%f "
+               "TIMEOUT_RATE=%f CLOSE_MS=%lu CLOSE_RATE=%f",
+               (unsigned long)cbt->total_build_times,
+               (unsigned long)cbt->timeout_ms,
+               (unsigned long)cbt->Xm, cbt->alpha, qnt,
+               timeout_rate,
+               (unsigned long)cbt->close_ms,
+               close_rate);
+
+  control_event_buildtimeout_set(type, args);
+
+  tor_free(args);
+}
 /** Set <b>global_event_mask*</b> to the bitwise OR of each live control
  * connection's event_mask field. */
 void
diff --git a/src/feature/control/control_events.h b/src/feature/control/control_events.h
index 4a5492b51..0c8448e0f 100644
--- a/src/feature/control/control_events.h
+++ b/src/feature/control/control_events.h
@@ -223,6 +223,8 @@ void control_event_hs_descriptor_content(const char *onion_address,
                                          const char *desc_id,
                                          const char *hsdir_fp,
                                          const char *content);
+void cbt_control_event_buildtimeout_set(const circuit_build_times_t *cbt,
+                                        buildtimeout_set_event_t type);
 
 void control_events_free_all(void);
 



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