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

Hidden service circuitmap: A hash table that maps binary tokens to introduction and rendezvous circuits; it's used: (a) by relays acting as intro points and rendezvous points (b) by hidden services to find intro and rend circuits and (c) by HS clients to find rendezvous circuits. More...

#include "core/or/or.h"
#include "app/config/config.h"
#include "core/or/circuitlist.h"
#include "feature/hs/hs_circuitmap.h"
#include "core/or/or_circuit_st.h"
#include "core/or/origin_circuit_st.h"

Go to the source code of this file.

Macros

#define HS_CIRCUITMAP_PRIVATE
 
#define hs_token_free(val)    FREE_AND_NULL(hs_token_t, hs_token_free_, (val))
 

Functions

static int hs_circuits_have_same_token (const circuit_t *first_circuit, const circuit_t *second_circuit)
 
static unsigned int hs_circuit_hash_token (const circuit_t *circuit)
 
 HT_PROTOTYPE (hs_circuitmap_ht, circuit_t, hs_circuitmap_node, hs_circuit_hash_token, hs_circuits_have_same_token)
 
 HT_GENERATE2 (hs_circuitmap_ht, circuit_t, hs_circuitmap_node, hs_circuit_hash_token, hs_circuits_have_same_token, 0.6, tor_reallocarray, tor_free_)
 
static hs_token_t * hs_token_new (hs_token_type_t type, size_t token_len, const uint8_t *token)
 
static void hs_token_free_ (hs_token_t *hs_token)
 
static circuit_tget_circuit_with_token (hs_token_t *search_token)
 
static void hs_circuitmap_register_impl (circuit_t *circ, hs_token_t *token)
 
static void hs_circuitmap_register_circuit (circuit_t *circ, hs_token_type_t type, size_t token_len, const uint8_t *token)
 
static circuit_ths_circuitmap_get_circuit_impl (hs_token_type_t type, size_t token_len, const uint8_t *token, uint8_t wanted_circ_purpose)
 
static origin_circuit_ths_circuitmap_get_origin_circuit (hs_token_type_t type, size_t token_len, const uint8_t *token, uint8_t wanted_circ_purpose)
 
static or_circuit_ths_circuitmap_get_or_circuit (hs_token_type_t type, size_t token_len, const uint8_t *token, uint8_t wanted_circ_purpose)
 
smartlist_ths_circuitmap_get_all_intro_circ_relay_side (void)
 
or_circuit_ths_circuitmap_get_intro_circ_v3_relay_side (const ed25519_public_key_t *auth_key)
 
or_circuit_ths_circuitmap_get_intro_circ_v2_relay_side (const uint8_t *digest)
 
or_circuit_ths_circuitmap_get_rend_circ_relay_side (const uint8_t *cookie)
 
void hs_circuitmap_register_rend_circ_relay_side (or_circuit_t *circ, const uint8_t *cookie)
 
void hs_circuitmap_register_intro_circ_v2_relay_side (or_circuit_t *circ, const uint8_t *digest)
 
void hs_circuitmap_register_intro_circ_v3_relay_side (or_circuit_t *circ, const ed25519_public_key_t *auth_key)
 
origin_circuit_ths_circuitmap_get_intro_circ_v3_service_side (const ed25519_public_key_t *auth_key)
 
origin_circuit_ths_circuitmap_get_intro_circ_v2_service_side (const uint8_t *digest)
 
origin_circuit_ths_circuitmap_get_rend_circ_service_side (const uint8_t *cookie)
 
origin_circuit_ths_circuitmap_get_rend_circ_client_side (const uint8_t *cookie)
 
origin_circuit_ths_circuitmap_get_established_rend_circ_client_side (const uint8_t *cookie)
 
void hs_circuitmap_register_intro_circ_v2_service_side (origin_circuit_t *circ, const uint8_t *digest)
 
void hs_circuitmap_register_intro_circ_v3_service_side (origin_circuit_t *circ, const ed25519_public_key_t *auth_key)
 
void hs_circuitmap_register_rend_circ_service_side (origin_circuit_t *circ, const uint8_t *cookie)
 
void hs_circuitmap_register_rend_circ_client_side (origin_circuit_t *or_circ, const uint8_t *cookie)
 
void hs_circuitmap_remove_circuit (circuit_t *circ)
 
void hs_circuitmap_init (void)
 
void hs_circuitmap_free_all (void)
 

Variables

static struct hs_circuitmap_ht * the_hs_circuitmap = NULL
 

Detailed Description

Hidden service circuitmap: A hash table that maps binary tokens to introduction and rendezvous circuits; it's used: (a) by relays acting as intro points and rendezvous points (b) by hidden services to find intro and rend circuits and (c) by HS clients to find rendezvous circuits.

Definition in file hs_circuitmap.c.

Function Documentation

◆ get_circuit_with_token()

static circuit_t* get_circuit_with_token ( hs_token_t *  search_token)
static

Return the circuit from the circuitmap with token search_token.

Definition at line 130 of file hs_circuitmap.c.

Referenced by hs_circuitmap_register_impl().

◆ hs_circuit_hash_token()

static unsigned int hs_circuit_hash_token ( const circuit_t circuit)
inlinestatic

This is a helper function for the hash table code (HT_). It hashes a circuit HS token into an unsigned int for use as a key by the hash table routines.

Definition at line 67 of file hs_circuitmap.c.

◆ hs_circuitmap_free_all()

void hs_circuitmap_free_all ( void  )

Public function: Free all memory allocated by the global HS circuitmap.

Definition at line 607 of file hs_circuitmap.c.

Referenced by hs_free_all().

◆ hs_circuitmap_get_all_intro_circ_relay_side()

smartlist_t* hs_circuitmap_get_all_intro_circ_relay_side ( void  )

Public function: Return v2 and v3 introduction circuit to this relay. Always return a newly allocated list for which it is the caller's responsability to free it.

Definition at line 280 of file hs_circuitmap.c.

Referenced by update_intro_circuits().

◆ hs_circuitmap_get_circuit_impl()

static circuit_t* hs_circuitmap_get_circuit_impl ( hs_token_type_t  type,
size_t  token_len,
const uint8_t *  token,
uint8_t  wanted_circ_purpose 
)
static

Helper function for hs_circuitmap_get_origin_circuit() and hs_circuitmap_get_or_circuit(). Because only circuit_t are indexed in the circuitmap, this function returns object type so the specialized functions using this helper can upcast it to the right type.

Return NULL if not such circuit is found.

Definition at line 197 of file hs_circuitmap.c.

◆ hs_circuitmap_get_established_rend_circ_client_side()

origin_circuit_t* hs_circuitmap_get_established_rend_circ_client_side ( const uint8_t *  cookie)

Public function: Return client-side established rendezvous circuit with rendezvous cookie. It will look for circuits with the following purposes:

a) CIRCUIT_PURPOSE_C_REND_READY: Established rend circuit (received RENDEZVOUS_ESTABLISHED). Waiting for RENDEZVOUS2 from service, and for INTRODUCE_ACK from intro point.

b) CIRCUIT_PURPOSE_C_REND_READY_INTRO_ACKED: Established rend circuit and introduce circuit acked. Waiting for RENDEZVOUS2 from service.

c) CIRCUIT_PURPOSE_C_REND_JOINED: Established rend circuit and received RENDEZVOUS2 from service.

Return NULL if no such circuit is found in the circuitmap.

Definition at line 492 of file hs_circuitmap.c.

Referenced by hs_circuitmap_get_rend_circ_client_side().

◆ hs_circuitmap_get_intro_circ_v2_relay_side()

or_circuit_t* hs_circuitmap_get_intro_circ_v2_relay_side ( const uint8_t *  digest)

Public function: Return v2 introduction circuit to this relay with digest. Return NULL if no such circuit is found in the circuitmap.

Definition at line 318 of file hs_circuitmap.c.

◆ hs_circuitmap_get_intro_circ_v2_service_side()

origin_circuit_t* hs_circuitmap_get_intro_circ_v2_service_side ( const uint8_t *  digest)

Public function: Return v2 introduction circuit originating from this hidden service with digest. Return NULL if no such circuit is found in the circuitmap.

Definition at line 400 of file hs_circuitmap.c.

Referenced by hs_circ_service_get_established_intro_circ(), and hs_circ_service_get_intro_circ().

◆ hs_circuitmap_get_intro_circ_v3_relay_side()

or_circuit_t* hs_circuitmap_get_intro_circ_v3_relay_side ( const ed25519_public_key_t auth_key)

Public function: Return a v3 introduction circuit to this relay with auth_key. Return NULL if no such circuit is found in the circuitmap.

Definition at line 307 of file hs_circuitmap.c.

◆ hs_circuitmap_get_intro_circ_v3_service_side()

origin_circuit_t* hs_circuitmap_get_intro_circ_v3_service_side ( const ed25519_public_key_t auth_key)

Public function: Return v3 introduction circuit with auth_key originating from this hidden service. Return NULL if no such circuit is found in the circuitmap.

Definition at line 375 of file hs_circuitmap.c.

Referenced by hs_circ_service_get_established_intro_circ(), and hs_circ_service_get_intro_circ().

◆ hs_circuitmap_get_or_circuit()

static or_circuit_t* hs_circuitmap_get_or_circuit ( hs_token_type_t  type,
size_t  token_len,
const uint8_t *  token,
uint8_t  wanted_circ_purpose 
)
static

Helper function: Query circuitmap for OR circuit with token of size token_len and type. Only returns a circuit with purpose equal to the wanted_circ_purpose parameter and if it is NOT marked for close. Return NULL if no such circuit is found.

Definition at line 253 of file hs_circuitmap.c.

Referenced by hs_circuitmap_get_intro_circ_v2_relay_side(), hs_circuitmap_get_intro_circ_v3_relay_side(), and hs_circuitmap_get_rend_circ_relay_side().

◆ hs_circuitmap_get_origin_circuit()

static origin_circuit_t* hs_circuitmap_get_origin_circuit ( hs_token_type_t  type,
size_t  token_len,
const uint8_t *  token,
uint8_t  wanted_circ_purpose 
)
static

Helper function: Query circuitmap for origin circuit with token of size token_len and type. Only returns a circuit with purpose equal to the wanted_circ_purpose parameter and if it is NOT marked for close. Return NULL if no such circuit is found.

Definition at line 229 of file hs_circuitmap.c.

Referenced by hs_circuitmap_get_established_rend_circ_client_side(), hs_circuitmap_get_intro_circ_v2_service_side(), hs_circuitmap_get_intro_circ_v3_service_side(), hs_circuitmap_get_rend_circ_client_side(), and hs_circuitmap_get_rend_circ_service_side().

◆ hs_circuitmap_get_rend_circ_client_side()

origin_circuit_t* hs_circuitmap_get_rend_circ_client_side ( const uint8_t *  cookie)

Public function: Return client-side rendezvous circuit with rendezvous cookie. It will look for circuits with the following purposes:

a) CIRCUIT_PURPOSE_C_REND_READY: Established rend circuit (received RENDEZVOUS_ESTABLISHED). Waiting for RENDEZVOUS2 from service, and for INTRODUCE_ACK from intro point.

b) CIRCUIT_PURPOSE_C_REND_READY_INTRO_ACKED: Established rend circuit and introduce circuit acked. Waiting for RENDEZVOUS2 from service.

c) CIRCUIT_PURPOSE_C_REND_JOINED: Established rend circuit and received RENDEZVOUS2 from service.

d) CIRCUIT_PURPOSE_C_ESTABLISH_REND: Rend circuit open but not yet established.

Return NULL if no such circuit is found in the circuitmap.

Definition at line 461 of file hs_circuitmap.c.

◆ hs_circuitmap_get_rend_circ_relay_side()

or_circuit_t* hs_circuitmap_get_rend_circ_relay_side ( const uint8_t *  cookie)

Public function: Return rendezvous circuit to this relay with rendezvous cookie. Return NULL if no such circuit is found in the circuitmap.

Definition at line 328 of file hs_circuitmap.c.

◆ hs_circuitmap_get_rend_circ_service_side()

origin_circuit_t* hs_circuitmap_get_rend_circ_service_side ( const uint8_t *  cookie)

Public function: Return rendezvous circuit originating from this hidden service with rendezvous cookie. Return NULL if no such circuit is found in the circuitmap.

Definition at line 424 of file hs_circuitmap.c.

◆ hs_circuitmap_init()

void hs_circuitmap_init ( void  )

Public function: Initialize the global HS circuitmap.

Definition at line 597 of file hs_circuitmap.c.

Referenced by hs_init().

◆ hs_circuitmap_register_circuit()

static void hs_circuitmap_register_circuit ( circuit_t circ,
hs_token_type_t  type,
size_t  token_len,
const uint8_t *  token 
)
static

Helper function: Register circ of type on the HS circuitmap. Use the HS token as the key to the hash table. If token is not set, clear the circuit of any HS tokens.

Definition at line 177 of file hs_circuitmap.c.

Referenced by hs_circuitmap_register_intro_circ_v2_relay_side(), hs_circuitmap_register_intro_circ_v2_service_side(), hs_circuitmap_register_intro_circ_v3_relay_side(), hs_circuitmap_register_intro_circ_v3_service_side(), hs_circuitmap_register_rend_circ_relay_side(), and hs_circuitmap_register_rend_circ_service_side().

◆ hs_circuitmap_register_impl()

static void hs_circuitmap_register_impl ( circuit_t circ,
hs_token_t *  token 
)
static

Helper function that registers circ with token on the HS circuitmap. This function steals reference of token.

Definition at line 143 of file hs_circuitmap.c.

◆ hs_circuitmap_register_intro_circ_v2_relay_side()

void hs_circuitmap_register_intro_circ_v2_relay_side ( or_circuit_t circ,
const uint8_t *  digest 
)

Public function: Register v2 intro circuit with key digest to the circuitmap.

Definition at line 350 of file hs_circuitmap.c.

◆ hs_circuitmap_register_intro_circ_v2_service_side()

void hs_circuitmap_register_intro_circ_v2_service_side ( origin_circuit_t circ,
const uint8_t *  digest 
)

Public function: Register v2 intro circuit with key digest to the circuitmap.

Definition at line 521 of file hs_circuitmap.c.

Referenced by register_intro_circ().

◆ hs_circuitmap_register_intro_circ_v3_relay_side()

void hs_circuitmap_register_intro_circ_v3_relay_side ( or_circuit_t circ,
const ed25519_public_key_t auth_key 
)

Public function: Register v3 intro circuit with key auth_key to the circuitmap.

Definition at line 361 of file hs_circuitmap.c.

◆ hs_circuitmap_register_intro_circ_v3_service_side()

void hs_circuitmap_register_intro_circ_v3_service_side ( origin_circuit_t circ,
const ed25519_public_key_t auth_key 
)

Public function: Register v3 intro circuit with key auth_key to the circuitmap.

Definition at line 532 of file hs_circuitmap.c.

Referenced by register_intro_circ().

◆ hs_circuitmap_register_rend_circ_client_side()

void hs_circuitmap_register_rend_circ_client_side ( origin_circuit_t or_circ,
const uint8_t *  cookie 
)

Public function: Register rendezvous circuit with key cookie to the client-side circuitmap.

Definition at line 554 of file hs_circuitmap.c.

◆ hs_circuitmap_register_rend_circ_relay_side()

void hs_circuitmap_register_rend_circ_relay_side ( or_circuit_t circ,
const uint8_t *  cookie 
)

Public relay-side setters: Public function: Register rendezvous circuit with key cookie to the circuitmap.

Definition at line 340 of file hs_circuitmap.c.

◆ hs_circuitmap_register_rend_circ_service_side()

void hs_circuitmap_register_rend_circ_service_side ( origin_circuit_t circ,
const uint8_t *  cookie 
)

Public function: Register rendezvous circuit with key cookie to the circuitmap.

Definition at line 543 of file hs_circuitmap.c.

◆ hs_circuitmap_remove_circuit()

void hs_circuitmap_remove_circuit ( circuit_t circ)

Public function: Remove this circuit from the HS circuitmap. Clear its HS token, and remove it from the hashtable.

Definition at line 571 of file hs_circuitmap.c.

Referenced by hs_circ_cleanup_on_close(), hs_circ_cleanup_on_free(), hs_circ_cleanup_on_repurpose(), and hs_circuitmap_register_impl().

◆ hs_circuits_have_same_token()

static int hs_circuits_have_same_token ( const circuit_t first_circuit,
const circuit_t second_circuit 
)
static

This is a helper function used by the hash table code (HT_). It returns 1 if two circuits have the same HS token.

Definition at line 34 of file hs_circuitmap.c.

◆ hs_token_free_()

static void hs_token_free_ ( hs_token_t *  hs_token)
static

Free memory allocated by this hs_token.

Definition at line 118 of file hs_circuitmap.c.

◆ hs_token_new()

static hs_token_t* hs_token_new ( hs_token_type_t  type,
size_t  token_len,
const uint8_t *  token 
)
static

Return a new HS token of type type containing token.

Definition at line 100 of file hs_circuitmap.c.

◆ HT_PROTOTYPE()

HT_PROTOTYPE ( hs_circuitmap_ht  ,
circuit_t  ,
hs_circuitmap_node  ,
hs_circuit_hash_token  ,
hs_circuits_have_same_token   
)

Register the circuitmap hash table

Variable Documentation

◆ the_hs_circuitmap

struct hs_circuitmap_ht* the_hs_circuitmap = NULL
static

This is the hidden service circuitmap. It's a hash table that maps introduction and rendezvous tokens to specific circuits such that given a token it's easy to find the corresponding circuit.

Definition at line 29 of file hs_circuitmap.c.

Referenced by get_circuit_with_token(), hs_circuitmap_free_all(), hs_circuitmap_get_all_intro_circ_relay_side(), hs_circuitmap_init(), hs_circuitmap_register_impl(), and hs_circuitmap_remove_circuit().