Tor  0.4.5.0-alpha-dev
Macros | Functions | Variables
selftest.c File Reference

Relay self-testing. More...

#include "core/or/or.h"
#include "app/config/config.h"
#include "core/mainloop/connection.h"
#include "core/mainloop/mainloop.h"
#include "core/mainloop/netstatus.h"
#include "core/or/circuitbuild.h"
#include "core/or/circuitlist.h"
#include "core/or/circuituse.h"
#include "core/or/crypt_path_st.h"
#include "core/or/extendinfo.h"
#include "core/or/extend_info_st.h"
#include "core/or/origin_circuit_st.h"
#include "core/or/relay.h"
#include "feature/control/control_events.h"
#include "feature/dirclient/dirclient.h"
#include "feature/dircommon/directory.h"
#include "feature/nodelist/authority_cert_st.h"
#include "feature/nodelist/routerinfo.h"
#include "feature/nodelist/routerinfo_st.h"
#include "feature/nodelist/routerlist.h"
#include "feature/nodelist/routerset.h"
#include "feature/nodelist/torcert.h"
#include "feature/relay/relay_periodic.h"
#include "feature/relay/router.h"
#include "feature/relay/selftest.h"

Go to the source code of this file.

Macros

#define SELF_EXCLUDED_WARN_INTERVAL   3600
 

Functions

static bool have_orport_for_family (int family)
 
static void inform_testing_reachability (const tor_addr_t *addr, uint16_t port, bool is_dirport)
 
void router_reset_reachability (void)
 
static int router_reachability_checks_disabled (const or_options_t *options)
 
int router_orport_seems_reachable (const or_options_t *options, int family)
 
int router_dirport_seems_reachable (const or_options_t *options)
 
static int router_should_check_reachability (int test_or, int test_dir)
 
static extend_info_textend_info_from_router (const routerinfo_t *r, int family)
 
static void router_do_orport_reachability_checks (const routerinfo_t *me, int family, int orport_reachable)
 
static void router_do_dirport_reachability_checks (const routerinfo_t *me)
 
void router_do_reachability_checks (int test_or, int test_dir)
 
static bool ready_to_publish (const or_options_t *options)
 
void router_orport_found_reachable (int family)
 
void router_dirport_found_reachable (void)
 
void router_perform_bandwidth_test (int num_circs, time_t now)
 

Variables

static bool can_reach_or_port_ipv4 = false
 
static bool can_reach_or_port_ipv6 = false
 
static bool can_reach_dir_port = false
 
static bool have_informed_testing_or_port_ipv4 = false
 
static bool have_informed_testing_or_port_ipv6 = false
 
static bool have_informed_testing_dir_port = false
 

Detailed Description

Relay self-testing.

Relays need to make sure that their own ports are reachable, and estimate their own bandwidth, before publishing.

Definition in file selftest.c.

Function Documentation

◆ extend_info_from_router()

static extend_info_t* extend_info_from_router ( const routerinfo_t r,
int  family 
)
static

Allocate and return a new extend_info_t that can be used to build a circuit to or through the router r, using an address from family (if available).

Clients don't have routerinfos, so this function should only be called on a server.

If the requested address is not available, returns NULL.

Definition at line 218 of file selftest.c.

Referenced by router_do_orport_reachability_checks().

◆ have_orport_for_family()

static bool have_orport_for_family ( int  family)
static

Return true if we have configured an ORPort for the given family that we would like to advertise.

Like other self-testing functions, this function looks at our most recently built descriptor.

Definition at line 195 of file selftest.c.

◆ inform_testing_reachability()

static void inform_testing_reachability ( const tor_addr_t addr,
uint16_t  port,
bool  is_dirport 
)
static

Log a message informing the user that we are testing a port for reachability, if we have not already logged such a message.

If is_dirport is true, then the port is a DirPort; otherwise it is an ORPort.

Calls to router_reset_reachability() will reset our view of whether we have logged this message for a given port.

Definition at line 370 of file selftest.c.

◆ ready_to_publish()

static bool ready_to_publish ( const or_options_t options)
static

Return true if this module knows of no reason why we shouldn't publish a server descriptor.

Definition at line 417 of file selftest.c.

◆ router_dirport_found_reachable()

void router_dirport_found_reachable ( void  )

Annotate that we found our DirPort reachable.

Definition at line 477 of file selftest.c.

◆ router_dirport_seems_reachable()

int router_dirport_seems_reachable ( const or_options_t options)

Return 0 if we need to do a DirPort reachability check, because:

  • no reachability check has been done yet, or
  • we've initiated reachability checks, but none have succeeded. Return 1 if we don't need to do a DirPort reachability check, because:
  • we've seen a successful reachability check, or
  • there is no DirPort set, or
  • AssumeReachable is set, or
  • the network is disabled.

Definition at line 148 of file selftest.c.

Referenced by router_do_reachability_checks().

◆ router_do_dirport_reachability_checks()

static void router_do_dirport_reachability_checks ( const routerinfo_t me)
static

Launch a self-testing circuit, and ask an exit to connect to our DirPort. me is our own routerinfo.

Relays don't advertise IPv6 DirPorts, so this function only supports IPv4.

See router_do_reachability_checks() for details.

Definition at line 294 of file selftest.c.

Referenced by router_do_reachability_checks().

◆ router_do_orport_reachability_checks()

static void router_do_orport_reachability_checks ( const routerinfo_t me,
int  family,
int  orport_reachable 
)
static

Launch a self-testing circuit to one of our ORPorts, using an address from family (if available). The circuit can be used to test reachability or bandwidth. me is our own routerinfo.

Logs an info-level status message. If orport_reachable is false, call it a reachability circuit. Otherwise, call it a bandwidth circuit.

See router_do_reachability_checks() for details.

Definition at line 261 of file selftest.c.

Referenced by router_do_reachability_checks().

◆ router_do_reachability_checks()

void router_do_reachability_checks ( int  test_or,
int  test_dir 
)

Some time has passed, or we just got new directory information. See if we currently believe our ORPort or DirPort to be unreachable. If so, launch a new test for it.

For ORPort, we simply try making a circuit that ends at ourselves. Success is noticed in onionskin_answer().

For DirPort, we make a connection via Tor to our DirPort and ask for our own server descriptor. Success is noticed in connection_dir_client_reached_eof().

Definition at line 333 of file selftest.c.

Referenced by check_for_reachability_bw_callback(), and directory_info_has_arrived().

◆ router_orport_found_reachable()

void router_orport_found_reachable ( int  family)

Annotate that we found our ORPort reachable with a given address family.

Definition at line 427 of file selftest.c.

◆ router_orport_seems_reachable()

int router_orport_seems_reachable ( const or_options_t options,
int  family 
)

Return 0 if we need to do an ORPort reachability check, because:

  • no reachability check has been done yet, or
  • we've initiated reachability checks, but none have succeeded. Return 1 if we don't need to do an ORPort reachability check, because:
  • we've seen a successful reachability check, or
  • AssumeReachable is set, or
  • the network is disabled.

If ‘family’`is AF_INET or AF_INET6, return true only when we should skip the given family's orport check (Because it's been checked, or because we aren't checking it.) If family is 0, return true if we can skip all orport checks.

Definition at line 106 of file selftest.c.

Referenced by circuit_testing_opened(), reachability_warnings_callback(), and router_do_reachability_checks().

◆ router_perform_bandwidth_test()

void router_perform_bandwidth_test ( int  num_circs,
time_t  now 
)

We have enough testing circuits open. Send a bunch of "drop" cells down each of them, to exercise our bandwidth.

May use IPv4 and IPv6 testing circuits (if available).

Definition at line 514 of file selftest.c.

◆ router_reachability_checks_disabled()

static int router_reachability_checks_disabled ( const or_options_t options)
static

Return 1 if we won't do reachability checks, because:

  • AssumeReachable is set, or
  • the network is disabled. Otherwise, return 0.

Definition at line 86 of file selftest.c.

Referenced by router_dirport_seems_reachable().

◆ router_reset_reachability()

void router_reset_reachability ( void  )

Forget what we have learned about our reachability status.

Definition at line 72 of file selftest.c.

◆ router_should_check_reachability()

static int router_should_check_reachability ( int  test_or,
int  test_dir 
)
static

See if we currently believe our ORPort or DirPort to be unreachable. If so, return 1 else return 0.

Definition at line 160 of file selftest.c.

Referenced by router_do_reachability_checks().

Variable Documentation

◆ can_reach_dir_port

bool can_reach_dir_port = false
static

Whether we can reach our DirPort from the outside.

Definition at line 58 of file selftest.c.

Referenced by router_dirport_found_reachable(), router_dirport_seems_reachable(), and router_reset_reachability().

◆ can_reach_or_port_ipv4

bool can_reach_or_port_ipv4 = false
static

Whether we can reach our IPv4 ORPort from the outside.

Definition at line 54 of file selftest.c.

Referenced by router_orport_found_reachable(), and router_reset_reachability().

◆ can_reach_or_port_ipv6

bool can_reach_or_port_ipv6 = false
static

Whether we can reach our IPv6 ORPort from the outside.

Definition at line 56 of file selftest.c.

Referenced by router_orport_found_reachable(), and router_reset_reachability().

◆ have_informed_testing_dir_port

bool have_informed_testing_dir_port = false
static

Has informed_testing_reachable logged a message about testing our DirPort?

Definition at line 68 of file selftest.c.

Referenced by inform_testing_reachability(), and router_reset_reachability().

◆ have_informed_testing_or_port_ipv4

bool have_informed_testing_or_port_ipv4 = false
static

Has informed_testing_reachable logged a message about testing our IPv4 ORPort?

Definition at line 62 of file selftest.c.

Referenced by inform_testing_reachability(), and router_reset_reachability().

◆ have_informed_testing_or_port_ipv6

bool have_informed_testing_or_port_ipv6 = false
static

Has informed_testing_reachable logged a message about testing our IPv6 ORPort?

Definition at line 65 of file selftest.c.

Referenced by inform_testing_reachability(), and router_reset_reachability().