tor  0.4.2.1-alpha-dev
Data Structures | Typedefs | Functions | Variables
predict_ports.c File Reference
#include "core/or/or.h"
#include "app/config/config.h"
#include "core/or/channelpadding.h"
#include "core/or/circuituse.h"
#include "feature/relay/routermode.h"
#include "feature/relay/selftest.h"
#include "feature/stats/predict_ports.h"
#include "lib/container/bitarray.h"
#include "lib/time/tvdiff.h"

Go to the source code of this file.

Data Structures

struct  predicted_port_t
 

Typedefs

typedef struct predicted_port_t predicted_port_t
 

Functions

static void predicted_ports_alloc (void)
 
int predicted_ports_prediction_time_remaining (time_t now)
 
static void add_predicted_port (time_t now, uint16_t port)
 
void rep_hist_note_used_port (time_t now, uint16_t port)
 
smartlist_trep_hist_get_predicted_ports (time_t now)
 
void rep_hist_remove_predicted_ports (const smartlist_t *rmv_ports)
 
void rep_hist_note_used_resolve (time_t now)
 
void rep_hist_note_used_internal (time_t now, int need_uptime, int need_capacity)
 
int rep_hist_get_predicted_internal (time_t now, int *need_uptime, int *need_capacity)
 
int any_predicted_circuits (time_t now)
 
int rep_hist_circbuilding_dormant (time_t now)
 
void predicted_ports_init (void)
 
void predicted_ports_free_all (void)
 

Variables

static size_t predicted_ports_total_alloc = 0
 
static smartlist_tpredicted_ports_list =NULL
 
static time_t prediction_timeout =0
 
static time_t last_prediction_add_time =0
 
static time_t predicted_internal_time = 0
 
static time_t predicted_internal_uptime_time = 0
 
static time_t predicted_internal_capacity_time = 0
 

Detailed Description

Remember what ports we've needed so we can have circuits ready.

Predicted ports are used by clients to remember how long it's been since they opened an exit connection to each given target port. Clients use this information in order to try to keep circuits open to exit nodes that can connect to the ports that they care about. (The predicted ports mechanism also handles predicted circuit usage that isn't port-specific, such as resolves, internal circuits, and so on.)

Definition in file predict_ports.c.

Typedef Documentation

◆ predicted_port_t

A single predicted port: used to remember which ports we've made connections to, so that we can try to keep making circuits that can handle those ports.

Function Documentation

◆ add_predicted_port()

static void add_predicted_port ( time_t  now,
uint16_t  port 
)
static

We just got an application request for a connection with port port. Remember it for the future, so we can keep some circuits open that will exit to this port.

Definition at line 87 of file predict_ports.c.

◆ any_predicted_circuits()

int any_predicted_circuits ( time_t  now)

Any ports used lately? These are pre-seeded if we just started up or if we're running a hidden service.

Definition at line 253 of file predict_ports.c.

References prediction_timeout.

Referenced by check_for_reachability_bw_callback(), directory_info_has_arrived(), rep_hist_circbuilding_dormant(), and rep_hist_note_used_internal().

◆ predicted_ports_alloc()

static void predicted_ports_alloc ( void  )
static

Allocate whatever memory and structs are needed for predicting which ports will be used. Also seed it with port 80, so we'll build circuits on start-up.

Definition at line 288 of file predict_ports.c.

References predicted_ports_list.

◆ predicted_ports_free_all()

void predicted_ports_free_all ( void  )

Free whatever memory is needed for predicting which ports will be used.

Definition at line 304 of file predict_ports.c.

References predicted_ports_list.

◆ predicted_ports_prediction_time_remaining()

int predicted_ports_prediction_time_remaining ( time_t  now)

How much time left until we stop predicting circuits?

Definition at line 54 of file predict_ports.c.

References last_prediction_add_time, and time_diff().

◆ rep_hist_circbuilding_dormant()

int rep_hist_circbuilding_dormant ( time_t  now)

Return 1 if we have no need for circuits currently, else return 0.

Definition at line 264 of file predict_ports.c.

References any_predicted_circuits(), check_whether_dirport_reachable(), check_whether_orport_reachable(), and circuit_enough_testing_circs().

Referenced by directory_too_idle_to_fetch_descriptors().

◆ rep_hist_get_predicted_internal()

int rep_hist_get_predicted_internal ( time_t  now,
int *  need_uptime,
int *  need_capacity 
)

Return 1 if we've used an internal circ recently; else return 0.

Definition at line 229 of file predict_ports.c.

References predicted_internal_capacity_time, predicted_internal_time, predicted_internal_uptime_time, and prediction_timeout.

◆ rep_hist_get_predicted_ports()

smartlist_t* rep_hist_get_predicted_ports ( time_t  now)

Return a newly allocated pointer to a list of uint16_t * for ports that are likely to be asked for in the near future.

Definition at line 142 of file predict_ports.c.

References predicted_ports_list, prediction_timeout, SMARTLIST_FOREACH_BEGIN, and tor_assert().

Referenced by circuit_get_unhandled_ports().

◆ rep_hist_note_used_internal()

void rep_hist_note_used_internal ( time_t  now,
int  need_uptime,
int  need_capacity 
)

Remember that we used an internal circ at time now.

Definition at line 206 of file predict_ports.c.

References any_predicted_circuits(), last_prediction_add_time, and prediction_timeout.

◆ rep_hist_note_used_port()

void rep_hist_note_used_port ( time_t  now,
uint16_t  port 
)

Remember that port has been asked for as of time now. This is used for predicting what sorts of streams we'll make in the future and making exit circuits to anticipate that.

Definition at line 115 of file predict_ports.c.

References last_prediction_add_time, predicted_ports_list, SMARTLIST_FOREACH_BEGIN, and tor_assert().

Referenced by rep_hist_note_used_resolve().

◆ rep_hist_note_used_resolve()

void rep_hist_note_used_resolve ( time_t  now)

The user asked us to do a resolve. Rather than keeping track of timings and such of resolves, we fake it for now by treating it the same way as a connection to port 80. This way we will continue to have circuits lying around if the user only uses Tor for resolves.

Definition at line 192 of file predict_ports.c.

References rep_hist_note_used_port().

◆ rep_hist_remove_predicted_ports()

void rep_hist_remove_predicted_ports ( const smartlist_t rmv_ports)

Take a list of uint16_t *, and remove every port in the list from the current list of predicted ports.

Definition at line 170 of file predict_ports.c.

References bitarray_init_zero(), bitarray_is_set(), bitarray_set(), predicted_ports_list, SMARTLIST_FOREACH, SMARTLIST_FOREACH_BEGIN, and tor_free.

Variable Documentation

◆ last_prediction_add_time

time_t last_prediction_add_time =0
static

When was the last time we added a prediction entry (HS or port)

Definition at line 48 of file predict_ports.c.

Referenced by predicted_ports_prediction_time_remaining(), rep_hist_note_used_internal(), and rep_hist_note_used_port().

◆ predicted_internal_capacity_time

time_t predicted_internal_capacity_time = 0
static

The last time we needed an internal circ with good capacity.

Definition at line 202 of file predict_ports.c.

Referenced by rep_hist_get_predicted_internal().

◆ predicted_internal_time

time_t predicted_internal_time = 0
static

The last time at which we needed an internal circ.

Definition at line 198 of file predict_ports.c.

Referenced by rep_hist_get_predicted_internal().

◆ predicted_internal_uptime_time

time_t predicted_internal_uptime_time = 0
static

The last time we needed an internal circ with good uptime.

Definition at line 200 of file predict_ports.c.

Referenced by rep_hist_get_predicted_internal().

◆ predicted_ports_list

smartlist_t* predicted_ports_list =NULL
static

A list of port numbers that have been used recently.

Definition at line 44 of file predict_ports.c.

Referenced by predicted_ports_alloc(), predicted_ports_free_all(), rep_hist_get_predicted_ports(), rep_hist_note_used_port(), and rep_hist_remove_predicted_ports().

◆ prediction_timeout

time_t prediction_timeout =0
static

How long do we keep predicting circuits?

Definition at line 46 of file predict_ports.c.

Referenced by any_predicted_circuits(), rep_hist_get_predicted_internal(), rep_hist_get_predicted_ports(), and rep_hist_note_used_internal().