Add congestion control fields to CIRC_BW control port event

This commit is contained in:
Mike Perry
2022-03-03 20:06:38 +00:00
parent 331b2aa348
commit 646a1d5f9a
3 changed files with 53 additions and 2 deletions
+42
View 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;
}
+1
View 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. */
+10 -2
View 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;
}