Tor
0.4.7.0-alpha-dev
|
Link-level padding code. More...
#include "core/or/or.h"
#include "core/or/channel.h"
#include "core/or/channelpadding.h"
#include "core/or/channeltls.h"
#include "app/config/config.h"
#include "feature/nodelist/networkstatus.h"
#include "core/mainloop/connection.h"
#include "core/or/connection_or.h"
#include "lib/crypt_ops/crypto_rand.h"
#include "core/mainloop/mainloop.h"
#include "feature/stats/rephist.h"
#include "feature/relay/router.h"
#include "feature/relay/routermode.h"
#include "lib/time/compat_time.h"
#include "lib/evloop/timers.h"
#include "feature/hs/hs_service.h"
#include "core/or/cell_st.h"
#include "core/or/or_connection_st.h"
Go to the source code of this file.
Macros | |
#define | CHANNEL_OBJECT_PRIVATE |
#define | TOR_MSEC_PER_SEC 1000 |
#define | TOR_USEC_PER_MSEC 1000 |
#define | TOR_HOUSEKEEPING_CALLBACK_MSEC 1000 |
#define | TOR_HOUSEKEEPING_CALLBACK_SLACK_MSEC 100 |
#define | CHANNEL_IS_CLIENT(chan, options) |
#define | DFLT_NETFLOW_INACTIVE_KEEPALIVE_LOW 1500 |
#define | DFLT_NETFLOW_INACTIVE_KEEPALIVE_HIGH 9500 |
#define | DFLT_NETFLOW_INACTIVE_KEEPALIVE_MIN 0 |
#define | DFLT_NETFLOW_INACTIVE_KEEPALIVE_MAX 60000 |
#define | DFLT_NETFLOW_REDUCED_KEEPALIVE_LOW 9000 |
#define | DFLT_NETFLOW_REDUCED_KEEPALIVE_HIGH 14000 |
#define | DFLT_NETFLOW_REDUCED_KEEPALIVE_MIN 0 |
#define | DFLT_NETFLOW_REDUCED_KEEPALIVE_MAX 60000 |
#define | CONNTIMEOUT_RELAYS_DFLT (60*60) |
#define | CONNTIMEOUT_RELAYS_MIN 60 |
#define | CONNTIMEOUT_RELAYS_MAX (7*24*60*60) |
#define | CIRCTIMEOUT_CLIENTS_DFLT (30*60) |
#define | CIRCTIMEOUT_CLIENTS_MIN 60 |
#define | CIRCTIMEOUT_CLIENTS_MAX (24*60*60) |
#define | CHANNELPADDING_TIME_LATER -1 |
#define | CHANNELPADDING_TIME_DISABLED -2 |
#define | NETFLOW_MISSED_WINDOW (150000 - DFLT_NETFLOW_INACTIVE_KEEPALIVE_HIGH) |
#define | CONNTIMEOUT_CLIENTS_BASE 180 |
Variables | |
static uint64_t | total_timers_pending |
static int | consensus_nf_ito_low |
static int | consensus_nf_ito_high |
static int | consensus_nf_ito_low_reduced |
static int | consensus_nf_ito_high_reduced |
static int | consensus_nf_conntimeout_relays |
static int | consensus_nf_conntimeout_clients |
static int | consensus_nf_pad_before_usage |
static int | consensus_nf_pad_relays |
static int | consensus_nf_pad_single_onion |
Link-level padding code.
Definition in file channelpadding.c.
#define CHANNEL_IS_CLIENT | ( | chan, | |
options | |||
) |
This macro tells us if either end of the channel is connected to a client. (If we're not a server, we're definitely a client. If the channel thinks it's a client, use that. Then finally verify in the consensus).
Definition at line 82 of file channelpadding.c.
#define CHANNELPADDING_TIME_LATER -1 |
Calculates the number of milliseconds from now to schedule a padding cell.
Returns the number of milliseconds from now (relative) to schedule the padding callback. If the padding timer is more than 1.1 seconds in the future, we return -1, to avoid scheduling excessive callbacks. If padding is disabled in the consensus, we return -2.
Side-effects: Updates chan->next_padding_time_ms, storing an (absolute, not relative) millisecond representation of when we should send padding, unless other activity happens first. This side-effect allows us to avoid scheduling a libevent callback until we're within 1.1 seconds of the padding time.
Definition at line 507 of file channelpadding.c.
#define TOR_HOUSEKEEPING_CALLBACK_MSEC 1000 |
How often do we get called by the connection housekeeping (ie: once per second)
Definition at line 70 of file channelpadding.c.
#define TOR_HOUSEKEEPING_CALLBACK_SLACK_MSEC 100 |
Additional extra time buffer on the housekeeping callback, since it can be delayed. This extra slack is used to decide if we should schedule a timer or wait for the next callback.
Definition at line 75 of file channelpadding.c.
channelpadding_decision_t channelpadding_decide_to_pad_channel | ( | channel_t * | chan | ) |
This function is called once per second by run_connection_housekeeping(), but only if the channel is still open, valid, and non-wedged.
It decides if and when we should send a padding cell, and if needed, schedules a callback to send that cell at the appropriate time.
Returns an enum that represents the current padding decision state. Return value is currently used only by unit tests.
Definition at line 721 of file channelpadding.c.
void channelpadding_disable_padding_on_channel | ( | channel_t * | chan | ) |
Calling this function on a channel causes it to tell the other side not to send padding, and disables sending padding from this side as well.
Definition at line 678 of file channelpadding.c.
unsigned int channelpadding_get_channel_idle_timeout | ( | const channel_t * | chan, |
int | is_canonical | ||
) |
Returns a randomized value for channel idle timeout in seconds. The channel idle timeout governs how quickly we close a channel after its last circuit has disappeared.
There are three classes of channels:
Also allows the default relay-to-relay value to be controlled by the consensus.
Definition at line 595 of file channelpadding.c.
int channelpadding_get_circuits_available_timeout | ( | void | ) |
This function controls how long we keep idle circuits open, and how long we build predicted circuits. This behavior is under the control of channelpadding because circuit availability is the dominant factor in channel lifespan, which influences total padding overhead.
Returns a randomized number of seconds in a range from CircuitsAvailableTimeout to 2*CircuitsAvailableTimeout. This value is halved if ReducedConnectionPadding is set. The default value of CircuitsAvailableTimeout can be controlled by the consensus.
Definition at line 642 of file channelpadding.c.
Referenced by rep_hist_note_used_internal().
Get a random netflow inactive timeout keepalive period in milliseconds, the range for which is determined by consensus parameters, negotiation, configuration, or default values. The consensus parameters enforce the minimum possible value, to avoid excessively frequent padding.
The ranges for this value were chosen to be low enough to ensure that routers do not emit a new netflow record for a connection due to it being idle.
Specific timeout values for major routers are listed in Proposal 251. No major router appeared capable of setting an inactive timeout below 10 seconds, so we set the defaults below that value, since we can always scale back if it ends up being too much padding.
Returns the next timeout period (in milliseconds) after which we should send a padding packet, or 0 if padding is disabled.
Definition at line 173 of file channelpadding.c.
void channelpadding_new_consensus_params | ( | const networkstatus_t * | ns | ) |
This function is called to update cached consensus parameters every time there is a consensus update. This allows us to move the consensus param search off of the critical path, so it does not need to be evaluated for every single connection, every second.
Definition at line 93 of file channelpadding.c.
void channelpadding_reduce_padding_on_channel | ( | channel_t * | chan | ) |
Calling this function on a channel causes it to tell the other side not to send padding, and reduces the rate that padding is sent from this side.
Definition at line 692 of file channelpadding.c.
|
static |
Schedules a callback to send padding on a channel in_ms milliseconds from now.
Returns CHANNELPADDING_WONTPAD on error, CHANNELPADDING_PADDING_SENT if we sent the packet immediately without a timer, and CHANNELPADDING_PADDING_SCHEDULED if we decided to schedule a timer.
Definition at line 459 of file channelpadding.c.
Sends a CELL_PADDING_NEGOTIATE on the channel to tell the other side not to send padding.
Returns -1 on error, 0 on success.
Definition at line 300 of file channelpadding.c.
Referenced by channelpadding_disable_padding_on_channel(), and channelpadding_reduce_padding_on_channel().
int channelpadding_send_enable_command | ( | channel_t * | chan, |
uint16_t | low_timeout, | ||
uint16_t | high_timeout | ||
) |
Sends a CELL_PADDING_NEGOTIATE on the channel to tell the other side to resume sending padding at some rate.
Returns -1 on error, 0 on success.
Definition at line 332 of file channelpadding.c.
|
static |
tor_timer callback function for us to send padding on an idle channel.
This function just obtains the channel from the callback handle, ensures it is still valid, and then hands it off to channelpadding_send_padding_cell_for_callback(), which checks if the channel is still idle before sending padding.
Definition at line 428 of file channelpadding.c.
|
static |
Sends a CELL_PADDING cell on a channel if it has been idle since our callback was scheduled.
This function also clears the pending padding timer and the callback flags.
Definition at line 368 of file channelpadding.c.
Referenced by channelpadding_schedule_padding().
int channelpadding_update_padding_for_channel | ( | channel_t * | chan, |
const channelpadding_negotiate_t * | pad_vars | ||
) |
Update this channel's padding settings based on the PADDING_NEGOTIATE contents.
Returns -1 on error; 1 on success.
Definition at line 245 of file channelpadding.c.
|
static |
The connection timeout for client connections
Definition at line 56 of file channelpadding.c.
Referenced by channelpadding_get_circuits_available_timeout().
|
static |
The connection timeout between relays
Definition at line 54 of file channelpadding.c.
|
static |
The timeout upper bound that is allowed before sending padding
Definition at line 48 of file channelpadding.c.
Referenced by channelpadding_get_netflow_inactive_timeout_ms().
|
static |
The timeout upper bound that is allowed before sending reduced padding
Definition at line 52 of file channelpadding.c.
Referenced by channelpadding_reduce_padding_on_channel().
|
static |
These are cached consensus parameters for netflow The timeout lower bound that is allowed before sending padding
Definition at line 46 of file channelpadding.c.
Referenced by channelpadding_get_netflow_inactive_timeout_ms(), and channelpadding_new_consensus_params().
|
static |
The timeout lower bound that is allowed before sending reduced padding
Definition at line 50 of file channelpadding.c.
Referenced by channelpadding_reduce_padding_on_channel().
|
static |
Should we pad before circuits are actually used for client data?
Definition at line 58 of file channelpadding.c.
|
static |
Should we pad relay-to-relay connections?
Definition at line 60 of file channelpadding.c.
|
static |
Should we pad rosos connections?
Definition at line 62 of file channelpadding.c.
|
static |
The total number of pending channelpadding timers
Definition at line 42 of file channelpadding.c.