]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Add congestion control fields to CIRC_BW control port event
authorMike Perry <mikeperry-git@torproject.org>
Thu, 3 Mar 2022 20:06:38 +0000 (20:06 +0000)
committerMike Perry <mikeperry-git@torproject.org>
Thu, 3 Mar 2022 20:06:38 +0000 (20:06 +0000)
src/core/or/congestion_control_common.c
src/core/or/congestion_control_common.h
src/feature/control/control_events.c

index 93d3a9f2c5ebb875ab5e4937add08198f2c4aa9f..36099cc1c634959ca0d85c5106b6f26a9a0e8c82 100644 (file)
@@ -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;
+}
index 1a57d713311d750ab7cb40b5dca6842d693e63b5..71e984f914216a9a74dc9a74e926d7b421925fa5 100644 (file)
@@ -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. */
index e2aca6c03eedca357f17770e2efc0a195f7176b9..f9b7caf9346c309287d2ea4bbff25be2e364e9eb 100644 (file)
@@ -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;
 }