tor  0.4.2.1-alpha-dev
Data Structures | Macros | Functions | Variables
bridges.c File Reference
#include "core/or/or.h"
#include "app/config/config.h"
#include "core/mainloop/connection.h"
#include "core/or/circuitbuild.h"
#include "core/or/policies.h"
#include "feature/client/bridges.h"
#include "feature/client/entrynodes.h"
#include "feature/client/transports.h"
#include "feature/dirclient/dirclient.h"
#include "feature/dirclient/dlstatus.h"
#include "feature/dircommon/directory.h"
#include "feature/nodelist/describe.h"
#include "feature/nodelist/dirlist.h"
#include "feature/nodelist/nodelist.h"
#include "feature/nodelist/routerinfo.h"
#include "feature/nodelist/routerlist.h"
#include "feature/nodelist/routerset.h"
#include "core/or/extend_info_st.h"
#include "feature/nodelist/node_st.h"
#include "feature/nodelist/routerinfo_st.h"
#include "feature/nodelist/routerstatus_st.h"
#include "feature/nodelist/microdesc_st.h"

Go to the source code of this file.

Data Structures

struct  bridge_info_t
 

Macros

#define TOR_BRIDGES_PRIVATE
 
#define bridge_free(bridge)   FREE_AND_NULL(bridge_info_t, bridge_free_, (bridge))
 

Functions

static void bridge_free_ (bridge_info_t *bridge)
 
static void rewrite_node_address_for_bridge (const bridge_info_t *bridge, node_t *node)
 
void mark_bridge_list (void)
 
void sweep_bridge_list (void)
 
STATIC void clear_bridge_list (void)
 
const smartlist_tbridge_list_get (void)
 
const uint8_t * bridge_get_rsa_id_digest (const bridge_info_t *bridge)
 
const tor_addr_port_tbridge_get_addr_port (const bridge_info_t *bridge)
 
STATIC bridge_info_tget_configured_bridge_by_orports_digest (const char *digest, const smartlist_t *orports)
 
bridge_info_tget_configured_bridge_by_addr_port_digest (const tor_addr_t *addr, uint16_t port, const char *digest)
 
bridge_info_tget_configured_bridge_by_exact_addr_port_digest (const tor_addr_t *addr, uint16_t port, const char *digest)
 
int addr_is_a_configured_bridge (const tor_addr_t *addr, uint16_t port, const char *digest)
 
int extend_info_is_a_configured_bridge (const extend_info_t *ei)
 
static bridge_info_tget_configured_bridge_by_routerinfo (const routerinfo_t *ri)
 
int routerinfo_is_a_configured_bridge (const routerinfo_t *ri)
 
static int bridge_exists_with_ipv4h_addr_and_port (const uint32_t ipv4_addr, const uint16_t port, const char *digest)
 
static int bridge_exists_with_ipv6_addr_and_port (const tor_addr_t *ipv6_addr, const uint16_t port, const char *digest)
 
int node_is_a_configured_bridge (const node_t *node)
 
void learned_router_identity (const tor_addr_t *addr, uint16_t port, const char *digest, const ed25519_public_key_t *ed_id)
 
static int bridge_has_digest (const bridge_info_t *bridge, const char *digest)
 
STATIC void bridge_resolve_conflicts (const tor_addr_t *addr, uint16_t port, const char *digest, const char *transport_name)
 
 MOCK_IMPL (int, transport_is_needed,(const char *transport_name))
 
void bridge_add_from_config (bridge_line_t *bridge_line)
 
STATIC bridge_info_tfind_bridge_by_digest (const char *digest)
 
const char * find_transport_name_by_bridge_addrport (const tor_addr_t *addr, uint16_t port)
 
int get_transport_by_bridge_addrport (const tor_addr_t *addr, uint16_t port, const transport_t **transport)
 
const smartlist_tget_socks_args_by_bridge_addrport (const tor_addr_t *addr, uint16_t port)
 
static void launch_direct_bridge_descriptor_fetch (bridge_info_t *bridge)
 
void retry_bridge_descriptor_fetch_directly (const char *digest)
 
void fetch_bridge_descriptors (const or_options_t *options, time_t now)
 
void learned_bridge_descriptor (routerinfo_t *ri, int from_cache)
 
 MOCK_IMPL (smartlist_t *, list_bridge_identities,(void))
 
 MOCK_IMPL (download_status_t *, get_bridge_dl_status_by_id,(const char *digest))
 
void bridges_free_all (void)
 

Variables

static smartlist_tbridge_list = NULL
 

Detailed Description

Code to manage bridges and bridge selection.

Bridges are fixed entry nodes, used for censorship circumvention.

Definition in file bridges.c.

Function Documentation

◆ addr_is_a_configured_bridge()

int addr_is_a_configured_bridge ( const tor_addr_t addr,
uint16_t  port,
const char *  digest 
)

If we have a bridge configured whose digest matches digest, or a bridge with no known digest whose address matches addr:port, return 1. Else return 0. If digest is NULL, check for address/port matches only.

Definition at line 251 of file bridges.c.

References get_configured_bridge_by_addr_port_digest(), and tor_assert().

Referenced by extend_info_is_a_configured_bridge().

◆ bridge_add_from_config()

void bridge_add_from_config ( bridge_line_t bridge_line)

Register the bridge information in bridge_line to the bridge subsystem. Steals reference of bridge_line.

Definition at line 521 of file bridges.c.

◆ bridge_exists_with_ipv4h_addr_and_port()

static int bridge_exists_with_ipv4h_addr_and_port ( const uint32_t  ipv4_addr,
const uint16_t  port,
const char *  digest 
)
static

Return 1 iff bridge_list contains entry matching given; IPv4 address in host byte order (ipv4_addr and port (and no identity digest) OR it contains an entry whose identity matches digest. Otherwise, return 0.

Definition at line 299 of file bridges.c.

◆ bridge_exists_with_ipv6_addr_and_port()

static int bridge_exists_with_ipv6_addr_and_port ( const tor_addr_t ipv6_addr,
const uint16_t  port,
const char *  digest 
)
static

Return 1 iff bridge_list contains entry matching given ipv6_addr and port (and no identity digest) OR it contains an entry whose identity matches digest. Otherwise, return 0.

Definition at line 326 of file bridges.c.

◆ bridge_free_()

static void bridge_free_ ( bridge_info_t bridge)
static

Free the bridge bridge.

Definition at line 119 of file bridges.c.

References SMARTLIST_FOREACH, bridge_info_t::socks_args, tor_free, and bridge_info_t::transport_name.

◆ bridge_get_addr_port()

const tor_addr_port_t* bridge_get_addr_port ( const bridge_info_t bridge)

Given a bridge, return a pointer to its configured addr:port combination.

Definition at line 161 of file bridges.c.

References bridge_info_t::addrport_configured, and tor_assert().

Referenced by bridge_passes_guard_filter(), entry_guard_add_bridge_to_sample(), get_sampled_guard_for_bridge(), and routerset_contains_bridge().

◆ bridge_get_rsa_id_digest()

const uint8_t* bridge_get_rsa_id_digest ( const bridge_info_t bridge)

Given a bridge, return a pointer to its RSA identity digest, or NULL if we don't know one for it.

Definition at line 147 of file bridges.c.

References bridge_info_t::identity, tor_assert(), and tor_digest_is_zero().

Referenced by entry_guard_add_bridge_to_sample(), get_sampled_guard_for_bridge(), and routerset_contains_bridge().

◆ bridge_has_digest()

static int bridge_has_digest ( const bridge_info_t bridge,
const char *  digest 
)
static

Return true if bridge has the same identity digest as digest. If digest is NULL, it matches bridges with unspecified identity digests.

Definition at line 440 of file bridges.c.

References DIGEST_LEN, bridge_info_t::identity, tor_digest_is_zero(), and tor_memeq().

Referenced by bridge_resolve_conflicts().

◆ bridge_list_get()

const smartlist_t* bridge_list_get ( void  )

Return a list of all the configured bridges, as bridge_info_t pointers.

Definition at line 135 of file bridges.c.

References bridge_list.

Referenced by get_eligible_guards().

◆ bridge_resolve_conflicts()

STATIC void bridge_resolve_conflicts ( const tor_addr_t addr,
uint16_t  port,
const char *  digest,
const char *  transport_name 
)

We are about to add a new bridge at addr:port, with optional digest and transport_name. Mark for removal any previously existing bridge with the same address and port, and warn the user as appropriate.

Definition at line 454 of file bridges.c.

References bridge_has_digest(), bridge_list, DIGEST_LEN, fmt_addrport(), hex_str(), SMARTLIST_FOREACH_BEGIN, strcmp_opt(), tor_addr_eq, tor_asprintf(), and tor_digest_is_zero().

◆ bridges_free_all()

void bridges_free_all ( void  )

Release all storage held in bridges.c

Definition at line 1025 of file bridges.c.

References clear_bridge_list().

◆ clear_bridge_list()

STATIC void clear_bridge_list ( void  )

Initialize the bridge list to empty, creating it if needed.

Definition at line 109 of file bridges.c.

References bridge_list, and SMARTLIST_FOREACH.

Referenced by bridges_free_all().

◆ extend_info_is_a_configured_bridge()

int extend_info_is_a_configured_bridge ( const extend_info_t ei)

If we have a bridge configured whose digest matches ei->identity_digest, or a bridge with no known digest whose address matches ei->addr:ei->port, return 1. Else return 0. If ei->onion_key is NULL, check for address/port matches only.

Definition at line 264 of file bridges.c.

References extend_info_t::addr, addr_is_a_configured_bridge(), extend_info_t::identity_digest, extend_info_t::onion_key, and extend_info_t::port.

◆ fetch_bridge_descriptors()

void fetch_bridge_descriptors ( const or_options_t options,
time_t  now 
)

For each bridge in our list for which we don't currently have a descriptor, fetch a new copy of its descriptor – either directly from the bridge or via a bridge authority.

Definition at line 722 of file bridges.c.

References BRIDGE_DIRINFO, bridge_list, download_status_is_ready(), download_status_mark_impossible(), or_options_t::ExcludeNodes, get_n_authorities(), pt_proxies_configuration_pending(), routerset_contains_bridge(), and SMARTLIST_FOREACH_BEGIN.

Referenced by second_elapsed_callback().

◆ find_bridge_by_digest()

STATIC bridge_info_t* find_bridge_by_digest ( const char *  digest)

If digest is one of our known bridges, return it.

Definition at line 575 of file bridges.c.

References bridge_list, DIGEST_LEN, SMARTLIST_FOREACH, and tor_memeq().

Referenced by retry_bridge_descriptor_fetch_directly().

◆ find_transport_name_by_bridge_addrport()

const char* find_transport_name_by_bridge_addrport ( const tor_addr_t addr,
uint16_t  port 
)

Given the addr and port of a bridge, if that bridge supports a pluggable transport, return its name. Otherwise, return NULL.

Definition at line 591 of file bridges.c.

References bridge_list, SMARTLIST_FOREACH_BEGIN, and tor_addr_eq.

Referenced by learned_router_identity().

◆ get_configured_bridge_by_addr_port_digest()

bridge_info_t* get_configured_bridge_by_addr_port_digest ( const tor_addr_t addr,
uint16_t  port,
const char *  digest 
)

If we have a bridge configured whose digest matches digest, or a bridge with no known digest whose address matches addr:port, return that bridge. Else return NULL. If digest is NULL, check for address/port matches only.

Definition at line 200 of file bridges.c.

References bridge_list, SMARTLIST_FOREACH_BEGIN, tor_addr_compare(), and tor_digest_is_zero().

Referenced by addr_is_a_configured_bridge(), and get_socks_args_by_bridge_addrport().

◆ get_configured_bridge_by_exact_addr_port_digest()

bridge_info_t* get_configured_bridge_by_exact_addr_port_digest ( const tor_addr_t addr,
uint16_t  port,
const char *  digest 
)

As get_configured_bridge_by_addr_port, but require that the address match addr:port, and that the ID digest match digest. (The other function will ignore the address if the digest matches.)

Definition at line 226 of file bridges.c.

References bridge_list, SMARTLIST_FOREACH_BEGIN, and tor_addr_compare().

Referenced by learned_router_identity().

◆ get_configured_bridge_by_orports_digest()

STATIC bridge_info_t* get_configured_bridge_by_orports_digest ( const char *  digest,
const smartlist_t orports 
)

If we have a bridge configured whose digest matches digest, or a bridge with no known digest whose address matches any of the tor_addr_port_t's in orports, return that bridge. Else return NULL.

Definition at line 172 of file bridges.c.

References bridge_list, SMARTLIST_FOREACH_BEGIN, tor_addr_compare(), and tor_digest_is_zero().

Referenced by get_configured_bridge_by_routerinfo().

◆ get_configured_bridge_by_routerinfo()

static bridge_info_t* get_configured_bridge_by_routerinfo ( const routerinfo_t ri)
static

◆ get_socks_args_by_bridge_addrport()

const smartlist_t* get_socks_args_by_bridge_addrport ( const tor_addr_t addr,
uint16_t  port 
)

Return a smartlist containing all the SOCKS arguments that we should pass to the SOCKS proxy.

Definition at line 644 of file bridges.c.

References get_configured_bridge_by_addr_port_digest(), and bridge_info_t::socks_args.

Referenced by pt_get_socks_args_for_proxy_addrport().

◆ get_transport_by_bridge_addrport()

int get_transport_by_bridge_addrport ( const tor_addr_t addr,
uint16_t  port,
const transport_t **  transport 
)

If addr and port match the address and port of a bridge of ours that uses pluggable transports, place its transport in transport.

Return 0 on success (found a transport, or found a bridge with no transport, or found no bridge); return -1 if we should be using a transport, but the transport could not be found.

Definition at line 614 of file bridges.c.

References bridge_list, SMARTLIST_FOREACH_BEGIN, and tor_addr_eq.

Referenced by conn_get_proxy_type(), and get_proxy_addrport().

◆ launch_direct_bridge_descriptor_fetch()

static void launch_direct_bridge_descriptor_fetch ( bridge_info_t bridge)
static

◆ learned_bridge_descriptor()

void learned_bridge_descriptor ( routerinfo_t ri,
int  from_cache 
)

◆ learned_router_identity()

void learned_router_identity ( const tor_addr_t addr,
uint16_t  port,
const char *  digest,
const ed25519_public_key_t ed_id 
)

We made a connection to a router at addr:port without knowing its digest. Its digest turned out to be digest. If it was a bridge, and we still don't know its digest, record it.

Definition at line 397 of file bridges.c.

References DIGEST_LEN, ed25519_public_key_is_zero(), find_transport_name_by_bridge_addrport(), get_configured_bridge_by_exact_addr_port_digest(), bridge_info_t::identity, tor_asprintf(), and tor_digest_is_zero().

◆ mark_bridge_list()

void mark_bridge_list ( void  )

Mark every entry of the bridge list to be removed on our next call to sweep_bridge_list unless it has first been un-marked.

Definition at line 84 of file bridges.c.

References bridge_list, bridge_info_t::marked_for_removal, and SMARTLIST_FOREACH.

◆ MOCK_IMPL() [1/3]

MOCK_IMPL ( int  ,
transport_is_needed  ,
(const char *transport_name)   
)

Return True if we have a bridge that uses a transport with name transport_name.

Definition at line 503 of file bridges.c.

References bridge_list, and SMARTLIST_FOREACH_BEGIN.

◆ MOCK_IMPL() [2/3]

MOCK_IMPL ( smartlist_t ,
list_bridge_identities  ,
(void)   
)

Return a smartlist containing all bridge identity digests

Definition at line 986 of file bridges.c.

References bridge_list, and SMARTLIST_FOREACH_BEGIN.

◆ MOCK_IMPL() [3/3]

MOCK_IMPL ( download_status_t ,
get_bridge_dl_status_by_id  ,
(const char *digest)   
)

Get the download status for a bridge descriptor given its identity

Definition at line 1006 of file bridges.c.

References bridge_list, DIGEST_LEN, SMARTLIST_FOREACH_BEGIN, and tor_memeq().

◆ node_is_a_configured_bridge()

int node_is_a_configured_bridge ( const node_t node)

Return 1 if node is one of our configured bridges, else 0. More specifically, return 1 iff: a bridge_info_t object exists in bridge_list such that: 1) It's identity is equal to node identity OR 2) It's identity digest is zero, but it matches address and port of any ORPort in the node.

Definition at line 348 of file bridges.c.

Referenced by node_has_preferred_descriptor().

◆ retry_bridge_descriptor_fetch_directly()

void retry_bridge_descriptor_fetch_directly ( const char *  digest)

Fetching the bridge descriptor from the bridge authority returned a "not found". Fall back to trying a direct fetch.

Definition at line 709 of file bridges.c.

References find_bridge_by_digest(), and launch_direct_bridge_descriptor_fetch().

◆ rewrite_node_address_for_bridge()

static void rewrite_node_address_for_bridge ( const bridge_info_t bridge,
node_t node 
)
static

If our bridge is configured to be a different address than the bridge gives in node, rewrite the routerinfo we received to use the address we meant to use. Now we handle multihomed bridges better.

Definition at line 806 of file bridges.c.

References routerinfo_t::addr, bridge_info_t::addr, tor_addr_compare(), and tor_addr_from_ipv4h.

Referenced by learned_bridge_descriptor().

◆ routerinfo_is_a_configured_bridge()

int routerinfo_is_a_configured_bridge ( const routerinfo_t ri)

Return 1 if ri is one of our known bridges, else 0.

Definition at line 286 of file bridges.c.

References get_configured_bridge_by_routerinfo().

◆ sweep_bridge_list()

void sweep_bridge_list ( void  )

Remove every entry of the bridge list that was marked with mark_bridge_list if it has not subsequently been un-marked.

Definition at line 95 of file bridges.c.

References bridge_list, SMARTLIST_DEL_CURRENT, and SMARTLIST_FOREACH_BEGIN.

Variable Documentation

◆ bridge_list

smartlist_t* bridge_list = NULL
static

A list of configured bridges. Whenever we actually get a descriptor for one, we add it as an entry guard. Note that the order of bridges in this list does not necessarily correspond to the order of bridges in the torrc.

Definition at line 79 of file bridges.c.

Referenced by bridge_list_get(), bridge_resolve_conflicts(), clear_bridge_list(), fetch_bridge_descriptors(), find_bridge_by_digest(), find_transport_name_by_bridge_addrport(), get_configured_bridge_by_addr_port_digest(), get_configured_bridge_by_exact_addr_port_digest(), get_configured_bridge_by_orports_digest(), get_transport_by_bridge_addrport(), mark_bridge_list(), MOCK_IMPL(), and sweep_bridge_list().