10 #ifndef TOR_CIRCUITPADDING_H
11 #define TOR_CIRCUITPADDING_H
13 #include "trunnel/circpad_negotiation.h"
42 CIRCPAD_EVENT_NONPADDING_RECV = 0,
44 CIRCPAD_EVENT_NONPADDING_SENT = 1,
46 CIRCPAD_EVENT_PADDING_SENT = 2,
48 CIRCPAD_EVENT_PADDING_RECV = 3,
51 CIRCPAD_EVENT_INFINITY = 4,
53 CIRCPAD_EVENT_BINS_EMPTY = 5,
55 CIRCPAD_EVENT_LENGTH_COUNT = 6
57 #define CIRCPAD_NUM_EVENTS ((int)CIRCPAD_EVENT_LENGTH_COUNT+1)
61 CIRCPAD_STATE_UNCHANGED = 0,
62 CIRCPAD_STATE_CHANGED = 1
76 #define CIRCPAD_DELAY_UNITS_PER_SECOND (1000*1000)
87 #define CIRCPAD_DELAY_INFINITE (UINT32_MAX)
93 #define CIRCPAD_DELAY_MAX_SECS \
94 ((CIRCPAD_DELAY_INFINITE/CIRCPAD_DELAY_UNITS_PER_SECOND)+1)
101 #define CIRCPAD_INFINITY_BIN(mi) ((mi)->histogram_len-1)
117 CIRCPAD_CIRC_BUILDING = 1<<0,
119 CIRCPAD_CIRC_OPENED = 1<<1,
121 CIRCPAD_CIRC_NO_STREAMS = 1<<2,
123 CIRCPAD_CIRC_STREAMS = 1<<3,
125 CIRCPAD_CIRC_HAS_RELAY_EARLY = 1<<4,
128 CIRCPAD_CIRC_HAS_NO_RELAY_EARLY = 1<<5
132 #define CIRCPAD_STATE_ALL \
133 (CIRCPAD_CIRC_BUILDING|CIRCPAD_CIRC_OPENED| \
134 CIRCPAD_CIRC_STREAMS|CIRCPAD_CIRC_NO_STREAMS| \
135 CIRCPAD_CIRC_HAS_RELAY_EARLY|CIRCPAD_CIRC_HAS_NO_RELAY_EARLY)
147 #define CIRCPAD_PURPOSE_ALL (0xFFFFFFFF)
235 CIRCPAD_DIST_NONE = 0,
237 CIRCPAD_DIST_UNIFORM = 1,
239 CIRCPAD_DIST_LOGISTIC = 2,
241 CIRCPAD_DIST_LOG_LOGISTIC = 3,
243 CIRCPAD_DIST_GEOMETRIC = 4,
245 CIRCPAD_DIST_WEIBULL = 5,
247 CIRCPAD_DIST_PARETO = 6
266 #define CIRCPAD_STATENUM_MAX (UINT16_MAX)
281 #define CIRCPAD_MAX_HISTOGRAM_LEN (100)
428 #define CIRCPAD_STATE_START 0
448 #define CIRCPAD_STATE_BURST 1
463 #define CIRCPAD_STATE_GAP 2
472 #define CIRCPAD_STATE_END CIRCPAD_STATENUM_MAX
480 #define CIRCPAD_STATE_IGNORE (CIRCPAD_STATENUM_MAX-1)
488 #define CIRCPAD_STATE_CANCEL (CIRCPAD_STATENUM_MAX-2)
494 #define CIRCPAD_MAX_MACHINE_STATES (CIRCPAD_STATE_CANCEL-1)
536 #define CIRCPAD_STATE_LENGTH_INFINITE UINT64_MAX
602 #define CIRCPAD_MAX_MACHINES (2)
611 #define CIRCPAD_GET_MACHINE(machineinfo) \
612 ((machineinfo)->on_circ->padding_machine[(machineinfo)->machine_index])
691 uint8_t relay_command);
693 uint8_t relay_command,
745 uint8_t target_hopnum,
747 uint32_t machine_ctr);
752 uint32_t machine_ctr);
772 #ifdef CIRCUITPADDING_PRIVATE
774 #define machine_spec_free(chan) \
775 FREE_AND_NULL(circpad_machine_spec_t,machine_spec_free_, (m))
810 uint8_t relay_command,
const uint8_t *payload,
811 ssize_t payload_len));
824 #ifdef TOR_UNIT_TESTS
STATIC circpad_machine_runtime_t * circpad_circuit_machineinfo_new(circuit_t *on_circ, int machine_index)
STATIC circpad_delay_t histogram_get_bin_upper_bound(const circpad_machine_runtime_t *mi, circpad_hist_index_t bin)
STATIC void machine_spec_free_(circpad_machine_spec_t *m)
STATIC bool circpad_machine_reached_padding_limit(circpad_machine_runtime_t *mi)
STATIC const node_t * circuit_get_nth_node(origin_circuit_t *circ, int hop)
STATIC const circpad_state_t * circpad_machine_current_state(const circpad_machine_runtime_t *mi)
STATIC void circpad_machine_setup_tokens(circpad_machine_runtime_t *mi)
STATIC circpad_hist_index_t circpad_histogram_usec_to_bin(const circpad_machine_runtime_t *mi, circpad_delay_t usec)
STATIC void circpad_machine_remove_higher_token(circpad_machine_runtime_t *mi, circpad_delay_t target_bin_usec)
STATIC signed_error_t circpad_send_command_to_hop(origin_circuit_t *circ, uint8_t hopnum, uint8_t relay_command, const uint8_t *payload, ssize_t payload_len)
STATIC void circpad_machine_remove_closest_token(circpad_machine_runtime_t *mi, circpad_delay_t target_bin_usec, bool use_usec)
STATIC void circpad_add_matching_machines(origin_circuit_t *on_circ, smartlist_t *machines_sl)
STATIC smartlist_t * relay_padding_machines
STATIC circpad_delay_t circpad_histogram_bin_to_usec(const circpad_machine_runtime_t *mi, circpad_hist_index_t bin)
STATIC void circpad_machine_remove_lower_token(circpad_machine_runtime_t *mi, circpad_delay_t target_bin_usec)
STATIC void circpad_machine_remove_token(circpad_machine_runtime_t *mi)
STATIC smartlist_t * origin_padding_machines
STATIC circpad_delay_t circpad_machine_sample_delay(circpad_machine_runtime_t *mi)
void circpad_machine_event_circ_has_streams(struct origin_circuit_t *circ)
void circpad_machines_init(void)
void circpad_new_consensus_params(const networkstatus_t *ns)
circpad_decision_t circpad_internal_event_infinity(circpad_machine_runtime_t *mi)
circpad_distribution_type_t
circpad_decision_t circpad_send_padding_cell_for_callback(circpad_machine_runtime_t *mi)
void circpad_cell_event_padding_sent(struct circuit_t *on_circ)
int8_t circpad_hist_index_t
circpad_decision_t circpad_internal_event_bins_empty(circpad_machine_runtime_t *)
circpad_decision_t circpad_internal_event_state_length_up(circpad_machine_runtime_t *)
bool circpad_padding_negotiated(struct circuit_t *circ, circpad_machine_num_t machine, uint8_t command, uint8_t response, uint32_t machine_ctr)
uint8_t circpad_machine_num_t
void circpad_cell_event_nonpadding_sent(struct circuit_t *on_circ)
void circpad_machine_event_circ_added_hop(struct origin_circuit_t *on_circ)
void circpad_free_all(void)
uint32_t circpad_hist_token_t
void circpad_machine_event_circ_has_no_relay_early(struct origin_circuit_t *circ)
void circpad_machines_free(void)
int circpad_marked_circuit_for_padding(circuit_t *circ, int reason)
bool circpad_padding_is_from_expected_hop(struct circuit_t *circ, crypt_path_t *from_hop)
void circpad_deliver_unrecognized_cell_events(struct circuit_t *circ, cell_direction_t dir)
void circpad_machine_states_init(circpad_machine_spec_t *machine, circpad_statenum_t num_states)
char * circpad_machine_spec_to_string(const circpad_machine_spec_t *machine)
signed_error_t circpad_handle_padding_negotiated(struct circuit_t *circ, struct cell_t *cell, crypt_path_t *layer_hint)
uint16_t circpad_statenum_t
uint32_t circpad_purpose_mask_t
circpad_purpose_mask_t circpad_circ_purpose_to_mask(uint8_t circ_purpose)
void circpad_cell_event_nonpadding_received(struct circuit_t *on_circ)
void circpad_deliver_sent_relay_cell_events(struct circuit_t *circ, uint8_t relay_command)
signed_error_t circpad_negotiate_padding(struct origin_circuit_t *circ, circpad_machine_num_t machine, uint8_t target_hopnum, uint8_t command, uint32_t machine_ctr)
circpad_decision_t circpad_machine_schedule_padding(circpad_machine_runtime_t *)
void circpad_machine_event_circ_has_no_streams(struct origin_circuit_t *circ)
#define CIRCPAD_MAX_HISTOGRAM_LEN
void circpad_cell_event_padding_received(struct circuit_t *on_circ)
void circpad_machine_event_circ_purpose_changed(struct origin_circuit_t *circ)
circpad_decision_t circpad_machine_spec_transition(circpad_machine_runtime_t *mi, circpad_event_t event)
signed_error_t circpad_handle_padding_negotiate(struct circuit_t *circ, struct cell_t *cell)
void circpad_deliver_recognized_relay_cell_events(struct circuit_t *circ, uint8_t relay_command, crypt_path_t *layer_hint)
int circpad_check_received_cell(cell_t *cell, circuit_t *circ, crypt_path_t *layer_hint, const relay_header_t *rh)
void circpad_circuit_free_all_machineinfos(struct circuit_t *circ)
void circpad_machine_event_circ_built(struct origin_circuit_t *circ)
@ CIRCPAD_TOKEN_REMOVAL_LOWER
@ CIRCPAD_TOKEN_REMOVAL_HIGHER
@ CIRCPAD_TOKEN_REMOVAL_NONE
@ CIRCPAD_TOKEN_REMOVAL_CLOSEST_USEC
@ CIRCPAD_TOKEN_REMOVAL_EXACT
@ CIRCPAD_TOKEN_REMOVAL_CLOSEST
tor_cmdline_mode_t command
circpad_purpose_mask_t apply_purpose_mask
circpad_purpose_mask_t keep_purpose_mask
unsigned reduced_padding_ok
circpad_circuit_state_t apply_state_mask
circpad_circuit_state_t keep_state_mask
unsigned requires_vanguards
unsigned is_padding_timer_scheduled
tor_timer_t * padding_timer
struct circuit_t * on_circ
circpad_hist_token_t * histogram
circpad_time_t padding_scheduled_at_usec
circpad_time_t last_received_time_usec
circpad_statenum_t current_state
circpad_hist_index_t histogram_len
time_t last_cell_time_sec
circpad_delay_t rtt_estimate_usec
circpad_hist_index_t chosen_bin
unsigned manage_circ_lifetime
unsigned should_negotiate_end
circpad_statenum_t num_states
uint8_t max_padding_percent
uint16_t allowed_padding_count
circpad_machine_num_t machine_num
circpad_machine_conditions_t conditions
circpad_distribution_t iat_dist
circpad_hist_token_t histogram[CIRCPAD_MAX_HISTOGRAM_LEN]
unsigned use_rtt_estimate
uint32_t histogram_total_tokens
circpad_distribution_t length_dist
circpad_statenum_t next_state[CIRCPAD_NUM_EVENTS]
circpad_removal_t token_removal
circpad_hist_index_t histogram_len
unsigned length_includes_nonpadding
#define MOCK_DECL(rv, funcname, arglist)