Tor  0.4.7.0-alpha-dev
Macros | Functions | Variables
control_bootstrap.c File Reference

Provide bootstrap progress events for the control port. More...

#include "core/or/or.h"
#include "app/config/config.h"
#include "core/mainloop/connection.h"
#include "core/or/connection_or.h"
#include "core/or/connection_st.h"
#include "core/or/or_connection_st.h"
#include "core/or/reasons.h"
#include "feature/control/control_events.h"
#include "feature/hibernate/hibernate.h"
#include "lib/malloc/malloc.h"

Go to the source code of this file.

Macros

#define BOOTSTRAP_MSG_LEN   1024
 
#define N_BOOT_TO_STR   (sizeof(boot_to_str_tab)/sizeof(boot_to_str_tab[0]))
 
#define BOOTSTRAP_PROBLEM_THRESHOLD   10
 
#define BOOTSTRAP_PCT_INCREMENT   5
 

Functions

static int bootstrap_status_to_string (bootstrap_status_t s, const char **tag, const char **summary)
 
static void control_event_bootstrap_core (int loglevel, bootstrap_status_t status, int progress)
 
int control_get_bootstrap_percent (void)
 
void control_event_bootstrap (bootstrap_status_t status, int progress)
 
void control_event_boot_dir (bootstrap_status_t status, int progress)
 
void control_event_boot_first_orconn (void)
 
void control_event_bootstrap_problem (const char *warn, const char *reason, const connection_t *conn, int dowarn)
 
void control_event_bootstrap_prob_or (const char *warn, int reason, or_connection_t *or_conn)
 
char * control_event_boot_last_msg (void)
 
void control_event_bootstrap_reset (void)
 

Variables

static char last_sent_bootstrap_message [BOOTSTRAP_MSG_LEN]
 
struct {
   bootstrap_status_t   status
 
   const char *   tag
 
   const char *   summary
 
boot_to_str_tab []
 
static int bootstrap_percent = BOOTSTRAP_STATUS_UNDEF
 
static int bootstrap_phase = BOOTSTRAP_STATUS_UNDEF
 
static int notice_bootstrap_percent = 0
 
static int bootstrap_problems = 0
 
static int bootstrap_first_orconn = 0
 
static int bootstrap_dir_phase = BOOTSTRAP_STATUS_UNDEF
 
static int bootstrap_dir_progress = BOOTSTRAP_STATUS_UNDEF
 

Detailed Description

Provide bootstrap progress events for the control port.

Definition in file control_bootstrap.c.

Macro Definition Documentation

◆ BOOTSTRAP_MSG_LEN

#define BOOTSTRAP_MSG_LEN   1024

A sufficiently large size to record the last bootstrap phase string.

Definition at line 22 of file control_bootstrap.c.

◆ BOOTSTRAP_PCT_INCREMENT

#define BOOTSTRAP_PCT_INCREMENT   5

When our bootstrapping progress level changes, but our bootstrapping status has not advanced, we only log at NOTICE when we have made at least this much progress.

Definition at line 146 of file control_bootstrap.c.

◆ BOOTSTRAP_PROBLEM_THRESHOLD

#define BOOTSTRAP_PROBLEM_THRESHOLD   10

We only tell the controller once we've hit a threshold of problems for the current phase.

Definition at line 140 of file control_bootstrap.c.

Function Documentation

◆ bootstrap_status_to_string()

static int bootstrap_status_to_string ( bootstrap_status_t  s,
const char **  tag,
const char **  summary 
)
static

Convert the name of a bootstrapping phase s into strings tag and summary suitable for display by the controller.

Definition at line 99 of file control_bootstrap.c.

◆ control_event_boot_dir()

void control_event_boot_dir ( bootstrap_status_t  status,
int  progress 
)

Defer directory info bootstrap events until we have successfully completed our first connection to a router.

Definition at line 234 of file control_bootstrap.c.

◆ control_event_boot_first_orconn()

void control_event_boot_first_orconn ( void  )

Set a flag to allow reporting of directory bootstrap progress. (Code that reports completion of an OR_CONN calls this.) Also, report directory progress so far.

Definition at line 255 of file control_bootstrap.c.

◆ control_event_boot_last_msg()

char* control_event_boot_last_msg ( void  )

Return a copy of the last sent bootstrap message.

Definition at line 384 of file control_bootstrap.c.

◆ control_event_bootstrap()

void control_event_bootstrap ( bootstrap_status_t  status,
int  progress 
)

Called when Tor has made progress at bootstrapping its directory information and initial circuits.

status is the new status, that is, what task we will be doing next. progress is zero if we just started this task, else it represents progress on the task.

Definition at line 188 of file control_bootstrap.c.

Referenced by bto_cevent_anyconn(), bto_cevent_apconn(), and control_event_boot_first_orconn().

◆ control_event_bootstrap_core()

static void control_event_bootstrap_core ( int  loglevel,
bootstrap_status_t  status,
int  progress 
)
static

Do the actual logging and notifications for control_event_bootstrap(). Doesn't change any state beyond that.

Definition at line 152 of file control_bootstrap.c.

◆ control_event_bootstrap_prob_or()

void control_event_bootstrap_prob_or ( const char *  warn,
int  reason,
or_connection_t or_conn 
)

Called when Tor has failed to make bootstrapping progress in a way that indicates a problem. warn gives a hint as to why, and reason provides an "or_conn_end_reason" tag. or_conn is the connection that caused this problem.

Definition at line 347 of file control_bootstrap.c.

◆ control_event_bootstrap_problem()

void control_event_bootstrap_problem ( const char *  warn,
const char *  reason,
const connection_t conn,
int  dowarn 
)

Called when Tor has failed to make bootstrapping progress in a way that indicates a problem. warn gives a human-readable hint as to why, and reason provides a controller-facing short tag. conn is the connection that caused this problem and can be NULL if a connection cannot be easily identified.

Definition at line 268 of file control_bootstrap.c.

◆ control_event_bootstrap_reset()

void control_event_bootstrap_reset ( void  )

Reset bootstrap tracking state.

Definition at line 391 of file control_bootstrap.c.

Variable Documentation

◆ 

const { ... } boot_to_str_tab[]

Table to convert bootstrap statuses to strings.

◆ bootstrap_dir_phase

int bootstrap_dir_phase = BOOTSTRAP_STATUS_UNDEF
static

Like bootstrap_phase, but for (possibly deferred) directory progress

Definition at line 226 of file control_bootstrap.c.

Referenced by control_event_boot_first_orconn().

◆ bootstrap_dir_progress

int bootstrap_dir_progress = BOOTSTRAP_STATUS_UNDEF
static

Like bootstrap_problems, but for (possibly deferred) directory progress

Definition at line 229 of file control_bootstrap.c.

Referenced by control_event_boot_first_orconn().

◆ bootstrap_first_orconn

int bootstrap_first_orconn = 0
static

Flag whether we've opened an OR_CONN yet

Definition at line 223 of file control_bootstrap.c.

Referenced by control_event_boot_first_orconn().

◆ bootstrap_percent

int bootstrap_percent = BOOTSTRAP_STATUS_UNDEF
static

What percentage through the bootstrap process are we? We remember this so we can avoid sending redundant bootstrap status events, and so we can guess context for the bootstrap messages which are ambiguous. It starts at 'undef', but gets set to 'starting' while Tor initializes.

Definition at line 119 of file control_bootstrap.c.

Referenced by control_event_bootstrap_reset().

◆ bootstrap_phase

int bootstrap_phase = BOOTSTRAP_STATUS_UNDEF
static

Like bootstrap_percent, but only takes on the enumerated values in bootstrap_status_t.

Definition at line 124 of file control_bootstrap.c.

◆ bootstrap_problems

int bootstrap_problems = 0
static

How many problems have we had getting to the next bootstrapping phase? These include failure to establish a connection to a Tor relay, failures to finish the TLS handshake, failures to validate the consensus document, etc.

Definition at line 136 of file control_bootstrap.c.

◆ last_sent_bootstrap_message

char last_sent_bootstrap_message[BOOTSTRAP_MSG_LEN]
static

What was the last bootstrap phase message we sent? We keep track of this so we can respond to getinfo status/bootstrap-phase queries.

Definition at line 26 of file control_bootstrap.c.

◆ notice_bootstrap_percent

int notice_bootstrap_percent = 0
static

As bootstrap_percent, but holds the bootstrapping level at which we last logged a NOTICE-level message. We use this, plus BOOTSTRAP_PCT_INCREMENT, to avoid flooding the log with a new message every time we get a few more microdescriptors

Definition at line 130 of file control_bootstrap.c.