Macros | Functions | Variables
rendclient.c File Reference
#include "core/or/or.h"
#include "app/config/config.h"
#include "core/mainloop/connection.h"
#include "core/mainloop/mainloop.h"
#include "core/or/circuitbuild.h"
#include "core/or/circuitlist.h"
#include "core/or/circuituse.h"
#include "core/or/connection_edge.h"
#include "core/or/relay.h"
#include "feature/client/circpathbias.h"
#include "feature/control/control_events.h"
#include "feature/dirclient/dirclient.h"
#include "feature/dircommon/directory.h"
#include "feature/hs/hs_circuit.h"
#include "feature/hs/hs_client.h"
#include "feature/hs/hs_common.h"
#include "feature/nodelist/describe.h"
#include "feature/nodelist/networkstatus.h"
#include "feature/nodelist/nodelist.h"
#include "feature/nodelist/routerlist.h"
#include "feature/nodelist/routerset.h"
#include "feature/rend/rendclient.h"
#include "feature/rend/rendcommon.h"
#include "feature/stats/rephist.h"
#include "lib/crypt_ops/crypto_dh.h"
#include "lib/crypt_ops/crypto_rand.h"
#include "lib/crypt_ops/crypto_util.h"
#include "lib/encoding/confline.h"
#include "core/or/cpath_build_state_st.h"
#include "core/or/crypt_path_st.h"
#include "feature/dircommon/dir_connection_st.h"
#include "core/or/entry_connection_st.h"
#include "core/or/extend_info_st.h"
#include "core/or/origin_circuit_st.h"
#include "feature/rend/rend_intro_point_st.h"
#include "feature/rend/rend_service_descriptor_st.h"
#include "feature/nodelist/routerstatus_st.h"

Go to the source code of this file.


#define rend_service_authorization_free(val)


static extend_info_trend_client_get_random_intro_impl (const rend_cache_entry_t *rend_query, const int strict, const int warnings)
void rend_client_purge_state (void)
void rend_client_introcirc_has_opened (origin_circuit_t *circ)
static int rend_client_send_establish_rendezvous (origin_circuit_t *circ)
int rend_client_send_introduction (origin_circuit_t *introcirc, origin_circuit_t *rendcirc)
void rend_client_rendcirc_has_opened (origin_circuit_t *circ)
static void rend_client_close_other_intros (const uint8_t *rend_pk_digest)
int rend_client_introduction_acked (origin_circuit_t *circ, const uint8_t *request, size_t request_len)
static int directory_get_from_hs_dir (const char *desc_id, const rend_data_t *rend_query, routerstatus_t *rs_hsdir)
static void purge_v2_hidserv_req (const char *desc_id)
static int fetch_v2_desc_by_descid (const char *desc_id, const rend_data_t *rend_query, smartlist_t *hsdirs)
static int fetch_v2_desc_by_addr (rend_data_t *rend_query, smartlist_t *hsdirs)
int rend_client_fetch_v2_desc (rend_data_t *query, smartlist_t *hsdirs)
void rend_client_refetch_v2_renddesc (rend_data_t *rend_query)
void rend_client_cancel_descriptor_fetches (void)
int rend_client_report_intro_point_failure (extend_info_t *failed_intro, rend_data_t *rend_data, unsigned int failure_type)
int rend_client_receive_rendezvous (origin_circuit_t *circ, const uint8_t *request, size_t request_len)
void rend_client_desc_trynow (const char *query)
void rend_client_note_connection_attempt_ended (const rend_data_t *rend_data)
extend_info_trend_client_get_random_intro (const rend_data_t *rend_query)
int rend_client_any_intro_points_usable (const rend_cache_entry_t *entry)
rend_service_authorization_trend_client_lookup_service_authorization (const char *onion_address)
static void rend_service_authorization_free_ (rend_service_authorization_t *auth)
static void rend_service_authorization_free_void (void *service_auth)
void rend_service_authorization_free_all (void)
int rend_parse_service_authorization (const or_options_t *options, int validate_only)


static strmap_t * auth_hid_servs = NULL

Detailed Description

Client code to access location-hidden services.

Definition in file rendclient.c.

Macro Definition Documentation

◆ rend_service_authorization_free

#define rend_service_authorization_free (   val)
static void rend_service_authorization_free_(rend_service_authorization_t *auth)
Definition: rendclient.c:1142

Definition at line 1136 of file rendclient.c.

Function Documentation

◆ directory_get_from_hs_dir()

static int directory_get_from_hs_dir ( const char *  desc_id,
const rend_data_t rend_query,
routerstatus_t rs_hsdir 

Determine the responsible hidden service directories for desc_id and fetch the descriptor with that ID from one of them. Only send a request to a hidden service directory that we have not yet tried during this attempt to connect to this hidden service; on success, return 1, in the case that no hidden service directory is left to ask for the descriptor, return 0, and in case of a failure -1.

Definition at line 461 of file rendclient.c.


Referenced by fetch_v2_desc_by_descid().

◆ fetch_v2_desc_by_addr()

static int fetch_v2_desc_by_addr ( rend_data_t rend_query,
smartlist_t hsdirs 

Fetch a v2 descriptor using the onion address in the given query object. This will compute the descriptor id for each replicas and fetch it on the given hsdir(s) if any or the responsible ones that are chosen automatically.

On success, 1 is returned. If no hidden service is left to ask, return 0. On error, -1 is returned.

Definition at line 610 of file rendclient.c.


◆ fetch_v2_desc_by_descid()

static int fetch_v2_desc_by_descid ( const char *  desc_id,
const rend_data_t rend_query,
smartlist_t hsdirs 

Fetch a v2 descriptor using the given descriptor id. If any hsdir(s) are given, they will be used instead.

On success, 1 is returned. If no hidden service is left to ask, return 0. On error, -1 is returned.

Definition at line 576 of file rendclient.c.

References directory_get_from_hs_dir(), SMARTLIST_FOREACH_BEGIN, and tor_assert().

◆ purge_v2_hidserv_req()

static void purge_v2_hidserv_req ( const char *  desc_id)

Remove tracked HSDir requests from our history for this hidden service descriptor desc_id (of size DIGEST_LEN)

Definition at line 559 of file rendclient.c.

References base32_encode(), DIGEST_LEN, hs_purge_hid_serv_from_last_hid_serv_requests(), and REND_DESC_ID_V2_LEN_BASE32.

◆ rend_client_any_intro_points_usable()

int rend_client_any_intro_points_usable ( const rend_cache_entry_t entry)

Return true iff any introduction points still listed in entry are usable.

Definition at line 1110 of file rendclient.c.

References rend_client_get_random_intro_impl().

◆ rend_client_cancel_descriptor_fetches()

void rend_client_cancel_descriptor_fetches ( void  )

Cancel all rendezvous descriptor fetches currently in progress.

Definition at line 741 of file rendclient.c.


Referenced by rend_client_purge_state().

◆ rend_client_close_other_intros()

static void rend_client_close_other_intros ( const uint8_t *  rend_pk_digest)

Called to close other intro circuits we launched in parallel.

Definition at line 353 of file rendclient.c.


◆ rend_client_desc_trynow()

void rend_client_desc_trynow ( const char *  query)

Find all the apconns in state AP_CONN_STATE_RENDDESC_WAIT that are waiting on query. If there's a working cache entry here with at least one intro point, move them to the next state.

Definition at line 915 of file rendclient.c.


◆ rend_client_fetch_v2_desc()

int rend_client_fetch_v2_desc ( rend_data_t query,
smartlist_t hsdirs 

Fetch a v2 descriptor using the given query. If any hsdir are specified, use them for the fetch.

On success, 1 is returned. If no hidden service is left to ask, return 0. On error, -1 is returned.

Definition at line 675 of file rendclient.c.

References tor_assert().

◆ rend_client_get_random_intro()

extend_info_t* rend_client_get_random_intro ( const rend_data_t rend_query)

Return a newly allocated extend_info_t* for a randomly chosen introduction point for the named hidden service. Return NULL if all introduction points have been tried and failed.

Definition at line 1009 of file rendclient.c.

◆ rend_client_get_random_intro_impl()

static extend_info_t * rend_client_get_random_intro_impl ( const rend_cache_entry_t entry,
const int  strict,
const int  warnings 

As rend_client_get_random_intro, except assume that StrictNodes is set iff strict is true. If warnings is false, don't complain to the user when we're out of nodes, even if StrictNodes is true.

Definition at line 1041 of file rendclient.c.

References rend_service_descriptor_t::intro_nodes, rend_cache_entry_t::parsed, smartlist_add_all(), and SMARTLIST_FOREACH.

Referenced by rend_client_any_intro_points_usable().

◆ rend_client_introcirc_has_opened()

void rend_client_introcirc_has_opened ( origin_circuit_t circ)

Called when we've established a circuit to an introduction point: send the introduction request.

Definition at line 67 of file rendclient.c.

References CIRCUIT_PURPOSE_C_INTRODUCING, origin_circuit_t::cpath, circuit_t::purpose, and tor_assert().

◆ rend_client_introduction_acked()

int rend_client_introduction_acked ( origin_circuit_t circ,
const uint8_t *  request,
size_t  request_len 

Called when get an ACK or a NAK for a REND_INTRODUCE1 cell.

Definition at line 376 of file rendclient.c.

References origin_circuit_t::build_state, cpath_build_state_t::chosen_exit, and tor_assert().

◆ rend_client_lookup_service_authorization()

rend_service_authorization_t* rend_client_lookup_service_authorization ( const char *  onion_address)

Look up the client-side authorization for the hidden service with onion_address. Return NULL if no authorization is available for that address.

Definition at line 1129 of file rendclient.c.

References auth_hid_servs, and tor_assert().

◆ rend_client_note_connection_attempt_ended()

void rend_client_note_connection_attempt_ended ( const rend_data_t rend_data)

Clear temporary state used only during an attempt to connect to the hidden service with rend_data. Called when a connection attempt has ended; it is possible for this to be called multiple times while handling an ended connection attempt, and any future changes to this function must ensure it remains idempotent.

Definition at line 967 of file rendclient.c.

Referenced by MOCK_IMPL().

◆ rend_client_purge_state()

void rend_client_purge_state ( void  )

Purge all potentially remotely-detectable state held in the hidden service client code. Called on SIGNAL NEWNYM.

Definition at line 56 of file rendclient.c.

References hs_purge_last_hid_serv_requests(), rend_cache_failure_purge(), rend_cache_purge(), and rend_client_cancel_descriptor_fetches().

◆ rend_client_receive_rendezvous()

int rend_client_receive_rendezvous ( origin_circuit_t circ,
const uint8_t *  request,
size_t  request_len 

The service sent us a rendezvous cell; join the circuits.

Definition at line 891 of file rendclient.c.

References DH1024_KEY_LEN, and DIGEST_LEN.

◆ rend_client_refetch_v2_renddesc()

void rend_client_refetch_v2_renddesc ( rend_data_t rend_query)

Unless we already have a descriptor for rend_query with at least one (possibly) working introduction point in it, start a connection to a hidden service directory to fetch a v2 rendezvous service descriptor.

Definition at line 709 of file rendclient.c.

◆ rend_client_rendcirc_has_opened()

void rend_client_rendcirc_has_opened ( origin_circuit_t circ)

Called when a rendezvous circuit is open; sends a establish rendezvous circuit as appropriate.

Definition at line 337 of file rendclient.c.

References CIRCUIT_PURPOSE_C_ESTABLISH_REND, circuit_t::purpose, and tor_assert().

◆ rend_client_report_intro_point_failure()

int rend_client_report_intro_point_failure ( extend_info_t failed_intro,
rend_data_t rend_data,
unsigned int  failure_type 

Mark failed_intro as a failed introduction point for the hidden service specified by rend_query. If the HS now has no usable intro points, or we do not have an HS descriptor for it, then launch a new renddesc fetch.

If failure_type is INTRO_POINT_FAILURE_GENERIC, remove the intro point from (our parsed copy of) the HS descriptor.

If failure_type is INTRO_POINT_FAILURE_TIMEOUT, mark the intro point as 'timed out'; it will not be retried until the current hidden service connection attempt has ended or it has appeared in a newly fetched rendezvous descriptor.

If failure_type is INTRO_POINT_FAILURE_UNREACHABLE, increment the intro point's reachability-failure count; if it has now failed MAX_INTRO_POINT_REACHABILITY_FAILURES or more times, remove the intro point from (our parsed copy of) the HS descriptor.

Return -1 if error, 0 if no usable intro points remain or service unrecognized, 1 if recognized and some intro points remain.

Definition at line 794 of file rendclient.c.

◆ rend_client_send_establish_rendezvous()

static int rend_client_send_establish_rendezvous ( origin_circuit_t circ)

Send the establish-rendezvous cell along a rendezvous circuit. if it fails, mark the circ for close and return -1. else return 0.

Definition at line 80 of file rendclient.c.

References CIRCUIT_PURPOSE_C_ESTABLISH_REND, circuit_t::purpose, origin_circuit_t::rend_data, and tor_assert().

◆ rend_client_send_introduction()

int rend_client_send_introduction ( origin_circuit_t introcirc,
origin_circuit_t rendcirc 

Called when we're trying to connect an ap conn; sends an INTRODUCE1 cell down introcirc if possible.

Definition at line 112 of file rendclient.c.


◆ rend_parse_service_authorization()

int rend_parse_service_authorization ( const or_options_t options,
int  validate_only 

Parse config_line as a client-side authorization for a hidden service and add it to the local map of hidden service authorizations. Return 0 for success and -1 for failure.

Definition at line 1170 of file rendclient.c.

References or_options_t::HidServAuth, smartlist_clear(), SMARTLIST_FOREACH, smartlist_split_string(), and tor_free.

◆ rend_service_authorization_free_()

static void rend_service_authorization_free_ ( rend_service_authorization_t auth)

Helper: Free storage held by rend_service_authorization_t.

Definition at line 1142 of file rendclient.c.

References tor_free.

Referenced by rend_service_authorization_free_void().

◆ rend_service_authorization_free_all()

void rend_service_authorization_free_all ( void  )

Release all the storage held in auth_hid_servs.

Definition at line 1157 of file rendclient.c.

References auth_hid_servs.

◆ rend_service_authorization_free_void()

static void rend_service_authorization_free_void ( void *  service_auth)

Helper for strmap_free.

Definition at line 1149 of file rendclient.c.

References rend_service_authorization_free_().

Variable Documentation

◆ auth_hid_servs

strmap_t* auth_hid_servs = NULL

Client-side authorizations for hidden services; map of onion address to rend_service_authorization_t*.

Definition at line 1123 of file rendclient.c.

Referenced by rend_client_lookup_service_authorization(), and rend_service_authorization_free_all().