Tor 0.4.9.0-alpha-dev
Macros | Functions | Variables
congestion_control_flow.c File Reference

Code that implements flow control for congestion controlled circuits. More...

#include "core/or/or.h"
#include "core/or/relay.h"
#include "core/mainloop/connection.h"
#include "core/or/connection_edge.h"
#include "core/mainloop/mainloop.h"
#include "core/or/congestion_control_common.h"
#include "core/or/congestion_control_flow.h"
#include "core/or/congestion_control_st.h"
#include "core/or/circuitlist.h"
#include "core/or/trace_probes_cc.h"
#include "feature/nodelist/networkstatus.h"
#include "trunnel/flow_control_cells.h"
#include "feature/control/control_events.h"
#include "lib/math/stats.h"
#include "core/or/connection_st.h"
#include "core/or/cell_st.h"
#include "app/config/config.h"
#include "core/or/conflux_util.h"

Go to the source code of this file.

Macros

#define TOR_CONGESTION_CONTROL_FLOW_PRIVATE
 
#define MAX_EXPECTED_CELL_BURST   32
 
#define XON_COUNT_SCALE_AT   200
 
#define XOFF_COUNT_SCALE_AT   200
 
#define ONE_MEGABYTE   (UINT64_C(1) << 20)
 
#define TOTAL_XMIT_SCALE_AT   (10 * ONE_MEGABYTE)
 
#define CC_XOFF_CLIENT_DFLT   500
 
#define CC_XOFF_CLIENT_MIN   1
 
#define CC_XOFF_CLIENT_MAX   10000
 
#define CC_XOFF_EXIT_DFLT   500
 
#define CC_XOFF_EXIT_MIN   1
 
#define CC_XOFF_EXIT_MAX   10000
 
#define CC_XON_CHANGE_PCT_DFLT   25
 
#define CC_XON_CHANGE_PCT_MIN   1
 
#define CC_XON_CHANGE_PCT_MAX   99
 
#define CC_XON_RATE_BYTES_DFLT   (500)
 
#define CC_XON_RATE_BYTES_MIN   (1)
 
#define CC_XON_RATE_BYTES_MAX   (5000)
 
#define CC_XON_EWMA_CNT_DFLT   (2)
 
#define CC_XON_EWMA_CNT_MIN   (2)
 
#define CC_XON_EWMA_CNT_MAX   (100)
 

Functions

void flow_control_new_consensus_params (const networkstatus_t *ns)
 
static void circuit_send_stream_xoff (edge_connection_t *stream)
 
static uint32_t compute_drain_rate (const edge_connection_t *stream)
 
static void circuit_send_stream_xon (edge_connection_t *stream)
 
bool circuit_process_stream_xoff (edge_connection_t *conn, const crypt_path_t *layer_hint, const cell_t *cell)
 
bool circuit_process_stream_xon (edge_connection_t *conn, const crypt_path_t *layer_hint, const cell_t *cell)
 
int flow_control_decide_xoff (edge_connection_t *stream)
 
static bool stream_drain_rate_changed (const edge_connection_t *stream)
 
void flow_control_decide_xon (edge_connection_t *stream, size_t n_written)
 
void flow_control_note_sent_data (edge_connection_t *stream, size_t len)
 
bool edge_uses_flow_control (const edge_connection_t *stream)
 
bool conn_uses_flow_control (connection_t *conn)
 

Variables

static uint32_t xoff_client
 
static uint32_t xoff_exit
 
static uint32_t xon_change_pct
 
static uint32_t xon_ewma_cnt
 
static uint32_t xon_rate_bytes
 
uint64_t cc_stats_flow_num_xoff_sent
 
uint64_t cc_stats_flow_num_xon_sent
 
double cc_stats_flow_xoff_outbuf_ma = 0
 
double cc_stats_flow_xon_outbuf_ma = 0
 

Detailed Description

Code that implements flow control for congestion controlled circuits.

Definition in file congestion_control_flow.c.

Macro Definition Documentation

◆ MAX_EXPECTED_CELL_BURST

#define MAX_EXPECTED_CELL_BURST   32

Definition at line 50 of file congestion_control_flow.c.

◆ ONE_MEGABYTE

#define ONE_MEGABYTE   (UINT64_C(1) << 20)

Definition at line 61 of file congestion_control_flow.c.

◆ TOR_CONGESTION_CONTROL_FLOW_PRIVATE

#define TOR_CONGESTION_CONTROL_FLOW_PRIVATE

Definition at line 10 of file congestion_control_flow.c.

◆ TOTAL_XMIT_SCALE_AT

#define TOTAL_XMIT_SCALE_AT   (10 * ONE_MEGABYTE)

Definition at line 62 of file congestion_control_flow.c.

◆ XOFF_COUNT_SCALE_AT

#define XOFF_COUNT_SCALE_AT   200

Definition at line 60 of file congestion_control_flow.c.

◆ XON_COUNT_SCALE_AT

#define XON_COUNT_SCALE_AT   200

Definition at line 59 of file congestion_control_flow.c.

Function Documentation

◆ circuit_process_stream_xoff()

bool circuit_process_stream_xoff ( edge_connection_t conn,
const crypt_path_t layer_hint,
const cell_t cell 
)

Process a stream XOFF, parsing it, and then stopping reading on the edge connection.

Record that we have received an xoff, so we know not to resume reading on this edge conn until we get an XON.

Returns false if the XOFF did not validate; true if it does.

Definition at line 234 of file congestion_control_flow.c.

◆ circuit_process_stream_xon()

bool circuit_process_stream_xon ( edge_connection_t conn,
const crypt_path_t layer_hint,
const cell_t cell 
)

Process a stream XON, and if it validates, clear the xoff flag and resume reading on this edge connection.

Also, use provided rate information to rate limit reading on this edge (or packagaing from it onto the circuit), to avoid XON/XOFF chatter.

Returns true if the XON validates, false otherwise.

Definition at line 328 of file congestion_control_flow.c.

◆ circuit_send_stream_xoff()

static void circuit_send_stream_xoff ( edge_connection_t stream)
static

Send an XOFF for this stream, and note that we sent one

Definition at line 119 of file congestion_control_flow.c.

◆ circuit_send_stream_xon()

static void circuit_send_stream_xon ( edge_connection_t stream)
static

Send an XON for this stream, with appropriate advisory rate information.

Reverts the xoff sent status, and stores the rate information we sent, in case it changes.

Definition at line 187 of file congestion_control_flow.c.

◆ compute_drain_rate()

static uint32_t compute_drain_rate ( const edge_connection_t stream)
inlinestatic

Compute the recent drain rate (write rate) for this edge connection and return it, in KB/sec (1000 bytes/sec).

Returns 0 if the monotime clock is busted.

Definition at line 156 of file congestion_control_flow.c.

◆ conn_uses_flow_control()

bool conn_uses_flow_control ( connection_t conn)

Returns true if a connection is an edge conn that uses flow control

Definition at line 702 of file congestion_control_flow.c.

◆ edge_uses_flow_control()

bool edge_uses_flow_control ( const edge_connection_t stream)

Returns true if an edge connection uses flow control

Definition at line 691 of file congestion_control_flow.c.

Referenced by conn_uses_flow_control().

◆ flow_control_decide_xoff()

int flow_control_decide_xoff ( edge_connection_t stream)

Called from sendme_stream_data_received(), when data arrives from a circuit to our edge's outbuf, to decide if we need to send an XOFF.

Returns the amount of cells remaining until the buffer is full, at which point it sends an XOFF, and returns 0.

Returns less than 0 if we have queued more than a congestion window worth of data and need to close the circuit.

Definition at line 442 of file congestion_control_flow.c.

◆ flow_control_decide_xon()

void flow_control_decide_xon ( edge_connection_t stream,
size_t  n_written 
)

Called whenever we drain an edge connection outbuf by writing on its socket, to decide if it is time to send an xon.

The n_written parameter tells us how many bytes we have written this time, which is used to compute the advisory drain rate fields.

Definition at line 530 of file congestion_control_flow.c.

◆ flow_control_new_consensus_params()

void flow_control_new_consensus_params ( const networkstatus_t ns)

Update global congestion control related consensus parameter values, every consensus update.

More details for each of the parameters can be found in proposal 324, section 6.5 including tuning notes.

Definition at line 72 of file congestion_control_flow.c.

◆ flow_control_note_sent_data()

void flow_control_note_sent_data ( edge_connection_t stream,
size_t  len 
)

Note that we packaged some data on this stream. Used to enforce client-side dropmark limits

Definition at line 672 of file congestion_control_flow.c.

◆ stream_drain_rate_changed()

static bool stream_drain_rate_changed ( const edge_connection_t stream)
static

Returns true if the stream's drain rate has changed significantly.

Returns false if the monotime clock is stalled, or if we have no previous drain rate information.

Definition at line 499 of file congestion_control_flow.c.

Variable Documentation

◆ cc_stats_flow_num_xoff_sent

uint64_t cc_stats_flow_num_xoff_sent

Metricsport stats

Definition at line 42 of file congestion_control_flow.c.

Referenced by fill_cc_counters_values().

◆ cc_stats_flow_num_xon_sent

uint64_t cc_stats_flow_num_xon_sent

Definition at line 43 of file congestion_control_flow.c.

◆ cc_stats_flow_xoff_outbuf_ma

double cc_stats_flow_xoff_outbuf_ma = 0

Definition at line 44 of file congestion_control_flow.c.

◆ cc_stats_flow_xon_outbuf_ma

double cc_stats_flow_xon_outbuf_ma = 0

Definition at line 45 of file congestion_control_flow.c.

◆ xoff_client

uint32_t xoff_client
static

Cache consensus parameters

Definition at line 34 of file congestion_control_flow.c.

Referenced by flow_control_new_consensus_params().

◆ xoff_exit

uint32_t xoff_exit
static

Definition at line 35 of file congestion_control_flow.c.

◆ xon_change_pct

uint32_t xon_change_pct
static

Definition at line 37 of file congestion_control_flow.c.

◆ xon_ewma_cnt

uint32_t xon_ewma_cnt
static

Definition at line 38 of file congestion_control_flow.c.

◆ xon_rate_bytes

uint32_t xon_rate_bytes
static

Definition at line 39 of file congestion_control_flow.c.