mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-11 13:43:47 +01:00
Tweak CIRC_BW event based on comments by nickm.
- Rename n_read and n_written in origin_circuit_t to make it clear that these are only used for CIRC_BW events. - Extract new code in control_update_global_event_mask to new clear_circ_bw_fields function.
This commit is contained in:
parent
ef67077fba
commit
b33b366a7f
@ -3271,7 +3271,7 @@ connection_read_to_buf(connection_t *conn, ssize_t *max_to_read,
|
|||||||
/* change *max_to_read */
|
/* change *max_to_read */
|
||||||
*max_to_read = at_most - n_read;
|
*max_to_read = at_most - n_read;
|
||||||
|
|
||||||
/* Update edge_conn->n_read and ocirc->n_read */
|
/* Update edge_conn->n_read and ocirc->n_read_circ_bw */
|
||||||
if (conn->type == CONN_TYPE_AP) {
|
if (conn->type == CONN_TYPE_AP) {
|
||||||
edge_connection_t *edge_conn = TO_EDGE_CONN(conn);
|
edge_connection_t *edge_conn = TO_EDGE_CONN(conn);
|
||||||
circuit_t *circ = circuit_get_by_edge_conn(edge_conn);
|
circuit_t *circ = circuit_get_by_edge_conn(edge_conn);
|
||||||
@ -3285,10 +3285,10 @@ connection_read_to_buf(connection_t *conn, ssize_t *max_to_read,
|
|||||||
|
|
||||||
if (circ && CIRCUIT_IS_ORIGIN(circ)) {
|
if (circ && CIRCUIT_IS_ORIGIN(circ)) {
|
||||||
ocirc = TO_ORIGIN_CIRCUIT(circ);
|
ocirc = TO_ORIGIN_CIRCUIT(circ);
|
||||||
if (PREDICT_LIKELY(UINT32_MAX - ocirc->n_read > n_read))
|
if (PREDICT_LIKELY(UINT32_MAX - ocirc->n_read_circ_bw > n_read))
|
||||||
ocirc->n_read += (int)n_read;
|
ocirc->n_read_circ_bw += (int)n_read;
|
||||||
else
|
else
|
||||||
ocirc->n_read = UINT32_MAX;
|
ocirc->n_read_circ_bw = UINT32_MAX;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3752,10 +3752,10 @@ connection_handle_write_impl(connection_t *conn, int force)
|
|||||||
|
|
||||||
if (circ && CIRCUIT_IS_ORIGIN(circ)) {
|
if (circ && CIRCUIT_IS_ORIGIN(circ)) {
|
||||||
ocirc = TO_ORIGIN_CIRCUIT(circ);
|
ocirc = TO_ORIGIN_CIRCUIT(circ);
|
||||||
if (PREDICT_LIKELY(UINT32_MAX - ocirc->n_written > n_written))
|
if (PREDICT_LIKELY(UINT32_MAX - ocirc->n_written_circ_bw > n_written))
|
||||||
ocirc->n_written += (int)n_written;
|
ocirc->n_written_circ_bw += (int)n_written;
|
||||||
else
|
else
|
||||||
ocirc->n_written = UINT32_MAX;
|
ocirc->n_written_circ_bw = UINT32_MAX;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -237,6 +237,20 @@ log_severity_to_event(int severity)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Helper: clear bandwidth counters of all origin circuits. */
|
||||||
|
static void
|
||||||
|
clear_circ_bw_fields(void)
|
||||||
|
{
|
||||||
|
circuit_t *circ;
|
||||||
|
origin_circuit_t *ocirc;
|
||||||
|
for (circ = circuit_get_global_list_(); circ; circ = circ->next) {
|
||||||
|
if (!CIRCUIT_IS_ORIGIN(circ))
|
||||||
|
continue;
|
||||||
|
ocirc = TO_ORIGIN_CIRCUIT(circ);
|
||||||
|
ocirc->n_written_circ_bw = ocirc->n_read_circ_bw = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** Set <b>global_event_mask*</b> to the bitwise OR of each live control
|
/** Set <b>global_event_mask*</b> to the bitwise OR of each live control
|
||||||
* connection's event_mask field. */
|
* connection's event_mask field. */
|
||||||
void
|
void
|
||||||
@ -276,14 +290,7 @@ control_update_global_event_mask(void)
|
|||||||
}
|
}
|
||||||
if (! (old_mask & EVENT_CIRC_BANDWIDTH_USED) &&
|
if (! (old_mask & EVENT_CIRC_BANDWIDTH_USED) &&
|
||||||
(new_mask & EVENT_CIRC_BANDWIDTH_USED)) {
|
(new_mask & EVENT_CIRC_BANDWIDTH_USED)) {
|
||||||
circuit_t *circ;
|
clear_circ_bw_fields();
|
||||||
origin_circuit_t *ocirc;
|
|
||||||
for (circ = circuit_get_global_list_(); circ; circ = circ->next) {
|
|
||||||
if (!CIRCUIT_IS_ORIGIN(circ))
|
|
||||||
continue;
|
|
||||||
ocirc = TO_ORIGIN_CIRCUIT(circ);
|
|
||||||
ocirc->n_written = ocirc->n_read = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3893,8 +3900,8 @@ control_event_stream_bandwidth(edge_connection_t *edge_conn)
|
|||||||
circ = circuit_get_by_edge_conn(edge_conn);
|
circ = circuit_get_by_edge_conn(edge_conn);
|
||||||
if (circ && CIRCUIT_IS_ORIGIN(circ)) {
|
if (circ && CIRCUIT_IS_ORIGIN(circ)) {
|
||||||
ocirc = TO_ORIGIN_CIRCUIT(circ);
|
ocirc = TO_ORIGIN_CIRCUIT(circ);
|
||||||
ocirc->n_read += edge_conn->n_read;
|
ocirc->n_read_circ_bw += edge_conn->n_read;
|
||||||
ocirc->n_written += edge_conn->n_written;
|
ocirc->n_written_circ_bw += edge_conn->n_written;
|
||||||
}
|
}
|
||||||
edge_conn->n_written = edge_conn->n_read = 0;
|
edge_conn->n_written = edge_conn->n_read = 0;
|
||||||
}
|
}
|
||||||
@ -3947,14 +3954,14 @@ control_event_circ_bandwidth_used(void)
|
|||||||
if (!CIRCUIT_IS_ORIGIN(circ))
|
if (!CIRCUIT_IS_ORIGIN(circ))
|
||||||
continue;
|
continue;
|
||||||
ocirc = TO_ORIGIN_CIRCUIT(circ);
|
ocirc = TO_ORIGIN_CIRCUIT(circ);
|
||||||
if (!ocirc->n_read && !ocirc->n_written)
|
if (!ocirc->n_read_circ_bw && !ocirc->n_written_circ_bw)
|
||||||
continue;
|
continue;
|
||||||
send_control_event(EVENT_CIRC_BANDWIDTH_USED, ALL_FORMATS,
|
send_control_event(EVENT_CIRC_BANDWIDTH_USED, ALL_FORMATS,
|
||||||
"650 CIRC_BW ID=%d READ=%lu WRITTEN=%lu\r\n",
|
"650 CIRC_BW ID=%d READ=%lu WRITTEN=%lu\r\n",
|
||||||
ocirc->global_identifier,
|
ocirc->global_identifier,
|
||||||
(unsigned long)ocirc->n_read,
|
(unsigned long)ocirc->n_read_circ_bw,
|
||||||
(unsigned long)ocirc->n_written);
|
(unsigned long)ocirc->n_written_circ_bw);
|
||||||
ocirc->n_written = ocirc->n_read = 0;
|
ocirc->n_written_circ_bw = ocirc->n_read_circ_bw = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
10
src/or/or.h
10
src/or/or.h
@ -2971,12 +2971,14 @@ typedef struct origin_circuit_t {
|
|||||||
edge_connection_t *p_streams;
|
edge_connection_t *p_streams;
|
||||||
|
|
||||||
/** Bytes read from any attached stream since last call to
|
/** Bytes read from any attached stream since last call to
|
||||||
* control_event_circ_bandwidth_used() */
|
* control_event_circ_bandwidth_used(). Only used if we're configured
|
||||||
uint32_t n_read;
|
* to emit CIRC_BW events. */
|
||||||
|
uint32_t n_read_circ_bw;
|
||||||
|
|
||||||
/** Bytes written to any attached stream since last call to
|
/** Bytes written to any attached stream since last call to
|
||||||
* control_event_circ_bandwidth_used() */
|
* control_event_circ_bandwidth_used(). Only used if we're configured
|
||||||
uint32_t n_written;
|
* to emit CIRC_BW events. */
|
||||||
|
uint32_t n_written_circ_bw;
|
||||||
|
|
||||||
/** Build state for this circuit. It includes the intended path
|
/** Build state for this circuit. It includes the intended path
|
||||||
* length, the chosen exit router, rendezvous information, etc.
|
* length, the chosen exit router, rendezvous information, etc.
|
||||||
|
Loading…
Reference in New Issue
Block a user