Tor  0.4.7.0-alpha-dev
Data Structures | Functions | Variables
predict_ports.c File Reference

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

#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
 

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.

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.

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 286 of file predict_ports.c.

◆ 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 302 of file predict_ports.c.

◆ 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.

◆ 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.

Referenced by dirclient_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.

◆ 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.

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.

◆ 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.

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.

◆ 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.

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().