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

Bootstrap tracker for OR connections. More...

#include <stdbool.h>
#include "core/or/or.h"
#include "core/or/ocirc_event.h"
#include "core/or/orconn_event.h"
#include "feature/control/btrack_orconn.h"
#include "feature/control/btrack_orconn_cevent.h"
#include "feature/control/btrack_orconn_maps.h"
#include "lib/log/log.h"
#include "lib/pubsub/pubsub.h"

Go to the source code of this file.

Data Structures

struct  bto_best_t
 

Functions

 DECLARE_SUBSCRIBE (orconn_state, bto_state_rcvr)
 
 DECLARE_SUBSCRIBE (orconn_status, bto_status_rcvr)
 
 DECLARE_SUBSCRIBE (ocirc_chan, bto_chan_rcvr)
 
static bool bto_update_best (const bt_orconn_t *bto, bto_best_t *best, const char *type)
 
static void bto_update_bests (const bt_orconn_t *bto)
 
static void bto_reset_bests (void)
 
static void bto_state_rcvr (const msg_t *msg, const orconn_state_msg_t *arg)
 
static void bto_status_rcvr (const msg_t *msg, const orconn_status_msg_t *arg)
 
static void bto_chan_rcvr (const msg_t *msg, const ocirc_chan_msg_t *arg)
 
int btrack_orconn_init (void)
 
int btrack_orconn_add_pubsub (pubsub_connector_t *connector)
 
void btrack_orconn_fini (void)
 

Variables

static bto_best_t best_any = { 0, -1 }
 
static bto_best_t best_ap = { 0, -1 }
 

Detailed Description

Bootstrap tracker for OR connections.

Track state changes of OR connections, as published by the connection subsystem. Also track circuit launch events, because they're one of the few ways to discover the association between a channel (and OR connection) and a circuit.

We track all OR connections that we receive events for, whether or not they're carrying origin circuits. (An OR connection might carry origin circuits only after we first find out about that connection.)

All origin ORCONN events update the "any" state variables, while only application ORCONN events update the "ap" state variables (and also update the "any") variables.

We do this because we want to report the first increments of connection progress as the earliest bootstrap phases. This results in a better user experience because failures here translate into zero or very small amounts of displayed progress, instead of progress stuck near completion. The first connection to a relay might be a one-hop circuit for directory lookups, or it might be a connection for an application circuit because we already have enough directory info to build an application circuit.

We call functions in btrack_orconn_cevent.c to generate the actual controller events, because some of the state decoding we need to do is complicated.

Definition in file btrack_orconn.c.

Function Documentation

◆ bto_chan_rcvr()

static void bto_chan_rcvr ( const msg_t msg,
const ocirc_chan_msg_t arg 
)
static

Create or update a cached ORCONN state for a newly launched connection, including whether it's launched by an origin circuit and whether it's a one-hop circuit.

Definition at line 159 of file btrack_orconn.c.

◆ bto_reset_bests()

static void bto_reset_bests ( void  )
static

Reset cached "best" values

Definition at line 107 of file btrack_orconn.c.

Referenced by btrack_orconn_fini().

◆ bto_state_rcvr()

static void bto_state_rcvr ( const msg_t msg,
const orconn_state_msg_t arg 
)
static

Update cached states of ORCONNs from the incoming message. This message comes from code in connection_or.c.

Definition at line 118 of file btrack_orconn.c.

◆ bto_status_rcvr()

static void bto_status_rcvr ( const msg_t msg,
const orconn_status_msg_t arg 
)
static

Delete a cached ORCONN state if we get an incoming message saying the ORCONN is failed or closed. This message comes from code in control.c.

Definition at line 139 of file btrack_orconn.c.

◆ bto_update_best()

static bool bto_update_best ( const bt_orconn_t *  bto,
bto_best_t best,
const char *  type 
)
static

Update a cached state of a best ORCONN progress we've seen so far.

Return true if the new state is better than the old.

Definition at line 71 of file btrack_orconn.c.

Referenced by bto_update_bests().

◆ bto_update_bests()

static void bto_update_bests ( const bt_orconn_t *  bto)
static

Update cached states of best ORCONN progress we've seen

Only update the application ORCONN state if we know it's carrying an application circuit.

Definition at line 95 of file btrack_orconn.c.

◆ btrack_orconn_fini()

void btrack_orconn_fini ( void  )

Clear the hash maps and reset the "best" states

Definition at line 201 of file btrack_orconn.c.

◆ btrack_orconn_init()

int btrack_orconn_init ( void  )

Initialize the hash maps and subscribe to ORCONN and origin circuit events.

Definition at line 180 of file btrack_orconn.c.

Variable Documentation

◆ best_any

bto_best_t best_any = { 0, -1 }
static

GID and state of the best ORCONN we've seen so far

Definition at line 61 of file btrack_orconn.c.

Referenced by bto_reset_bests(), and bto_update_bests().

◆ best_ap

bto_best_t best_ap = { 0, -1 }
static

GID and state of the best application circuit ORCONN we've seen so far

Definition at line 63 of file btrack_orconn.c.

Referenced by bto_reset_bests(), and bto_update_bests().