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

[tor-commits] [tor/main] Add congestion control fields to CIRC_BW control port event



commit 646a1d5f9ae481667f0ec43e45879b94ea2dd28a
Author: Mike Perry <mikeperry-git@xxxxxxxxxxxxxx>
Date:   Thu Mar 3 20:06:38 2022 +0000

    Add congestion control fields to CIRC_BW control port event
---
 src/core/or/congestion_control_common.c | 42 +++++++++++++++++++++++++++++++++
 src/core/or/congestion_control_common.h |  1 +
 src/feature/control/control_events.c    | 12 ++++++++--
 3 files changed, 53 insertions(+), 2 deletions(-)

diff --git a/src/core/or/congestion_control_common.c b/src/core/or/congestion_control_common.c
index 93d3a9f2c5..36099cc1c6 100644
--- a/src/core/or/congestion_control_common.c
+++ b/src/core/or/congestion_control_common.c
@@ -1442,3 +1442,45 @@ congestion_control_parse_ext_response(const uint8_t *msg,
 
   return (int)ret;
 }
+
+/**
+ * Returns a formatted string of fields containing congestion
+ * control information, for the CIRC_BW control port event.
+ *
+ * An origin circuit can have a ccontrol object directly on it,
+ * if it is an onion service, or onion client. Exit-bound clients
+ * will have the ccontrol on the cpath associated with their exit
+ * (the last one in the cpath list).
+ *
+ * WARNING: This function does not support leaky-pipe topology. It
+ * is to be used for control port information only.
+ */
+char *
+congestion_control_get_control_port_fields(const origin_circuit_t *circ)
+{
+  const congestion_control_t *ccontrol = NULL;
+  char *ret = NULL;
+  int len;
+
+  if (TO_CIRCUIT(circ)->ccontrol) {
+    ccontrol = TO_CIRCUIT(circ)->ccontrol;
+  } else if (circ->cpath && circ->cpath->prev->ccontrol) {
+    /* Get ccontrol for last hop (exit) if it exists */
+    ccontrol = circ->cpath->prev->ccontrol;
+  }
+
+  if (!ccontrol)
+    return NULL;
+
+  len = tor_asprintf(&ret,
+                     " SS=%d CWND=%"PRIu64" RTT=%"PRIu64" MIN_RTT=%"PRIu64,
+                     ccontrol->in_slow_start, ccontrol->cwnd,
+                     ccontrol->ewma_rtt_usec/1000,
+                     ccontrol->min_rtt_usec/1000);
+  if (len < 0) {
+    log_warn(LD_BUG, "Unable to format event for controller.");
+    return NULL;
+  }
+
+  return ret;
+}
diff --git a/src/core/or/congestion_control_common.h b/src/core/or/congestion_control_common.h
index 1a57d71331..71e984f914 100644
--- a/src/core/or/congestion_control_common.h
+++ b/src/core/or/congestion_control_common.h
@@ -80,6 +80,7 @@ int congestion_control_parse_ext_response(const uint8_t *msg,
                                           const size_t msg_len,
                                           circuit_params_t *params_out);
 bool congestion_control_validate_sendme_increment(uint8_t sendme_inc);
+char *congestion_control_get_control_port_fields(const origin_circuit_t *);
 
 /* Ugh, C.. these are private. Use the getter instead, when
  * external to the congestion control code. */
diff --git a/src/feature/control/control_events.c b/src/feature/control/control_events.c
index e2aca6c03e..f9b7caf934 100644
--- a/src/feature/control/control_events.c
+++ b/src/feature/control/control_events.c
@@ -21,6 +21,7 @@
 #include "core/or/command.h"
 #include "core/or/connection_edge.h"
 #include "core/or/connection_or.h"
+#include "core/or/congestion_control_common.h"
 #include "core/or/reasons.h"
 #include "feature/control/control.h"
 #include "feature/control/control_events.h"
@@ -1075,10 +1076,12 @@ control_event_circ_bandwidth_used_for_circ(origin_circuit_t *ocirc)
 
   tor_gettimeofday(&now);
   format_iso_time_nospace_usec(tbuf, &now);
+
+  char *ccontrol_buf = congestion_control_get_control_port_fields(ocirc);
   send_control_event(EVENT_CIRC_BANDWIDTH_USED,
                      "650 CIRC_BW ID=%d READ=%lu WRITTEN=%lu TIME=%s "
                      "DELIVERED_READ=%lu OVERHEAD_READ=%lu "
-                     "DELIVERED_WRITTEN=%lu OVERHEAD_WRITTEN=%lu\r\n",
+                     "DELIVERED_WRITTEN=%lu OVERHEAD_WRITTEN=%lu%s\r\n",
                      ocirc->global_identifier,
                      (unsigned long)ocirc->n_read_circ_bw,
                      (unsigned long)ocirc->n_written_circ_bw,
@@ -1086,11 +1089,16 @@ control_event_circ_bandwidth_used_for_circ(origin_circuit_t *ocirc)
                      (unsigned long)ocirc->n_delivered_read_circ_bw,
                      (unsigned long)ocirc->n_overhead_read_circ_bw,
                      (unsigned long)ocirc->n_delivered_written_circ_bw,
-                     (unsigned long)ocirc->n_overhead_written_circ_bw);
+                     (unsigned long)ocirc->n_overhead_written_circ_bw,
+                     ccontrol_buf ? ccontrol_buf : "");
+
   ocirc->n_written_circ_bw = ocirc->n_read_circ_bw = 0;
   ocirc->n_overhead_written_circ_bw = ocirc->n_overhead_read_circ_bw = 0;
   ocirc->n_delivered_written_circ_bw = ocirc->n_delivered_read_circ_bw = 0;
 
+  if (ccontrol_buf)
+    tor_free(ccontrol_buf);
+
   return 0;
 }
 


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