tor  0.4.0.0-alpha-dev
Data Structures | Macros | Functions | Variables
microdesc.c File Reference
#include "core/or/or.h"
#include "lib/fdio/fdio.h"
#include "app/config/config.h"
#include "core/or/circuitbuild.h"
#include "core/or/policies.h"
#include "feature/client/entrynodes.h"
#include "feature/dircache/dirserv.h"
#include "feature/dirclient/dlstatus.h"
#include "feature/dircommon/directory.h"
#include "feature/dirparse/microdesc_parse.h"
#include "feature/nodelist/dirlist.h"
#include "feature/nodelist/microdesc.h"
#include "feature/nodelist/networkstatus.h"
#include "feature/nodelist/nodefamily.h"
#include "feature/nodelist/nodelist.h"
#include "feature/nodelist/routerlist.h"
#include "feature/relay/router.h"
#include "feature/nodelist/microdesc_st.h"
#include "feature/nodelist/networkstatus_st.h"
#include "feature/nodelist/node_st.h"
#include "feature/nodelist/routerstatus_st.h"

Go to the source code of this file.

Data Structures

struct  microdesc_cache_t
 

Macros

#define TOO_MANY_OUTDATED_DIRSERVERS   30
 
#define TOLERATE_MICRODESC_AGE   (7*24*60*60)
 

Functions

static microdesc_cache_tget_microdesc_cache_noload (void)
 
static unsigned int microdesc_hash_ (microdesc_t *md)
 
static int microdesc_eq_ (microdesc_t *a, microdesc_t *b)
 
 HT_PROTOTYPE (HT_GENERATE2(microdesc_map, HT_GENERATE2(microdesc_t, HT_GENERATE2(node, HT_GENERATE2(microdesc_hash_, HT_GENERATE2(microdesc_eq_)
 
int microdesc_relay_is_outdated_dirserver (const char *relay_digest)
 
void microdesc_reset_outdated_dirservers_list (void)
 
static ssize_t dump_microdescriptor (int fd, microdesc_t *md, size_t *annotation_len_out)
 
microdesc_cache_tget_microdesc_cache (void)
 
smartlist_tmicrodescs_add_to_cache (microdesc_cache_t *cache, const char *s, const char *eos, saved_location_t where, int no_save, time_t listed_at, smartlist_t *requested_digests256)
 
smartlist_tmicrodescs_add_list_to_cache (microdesc_cache_t *cache, smartlist_t *descriptors, saved_location_t where, int no_save)
 
void microdesc_cache_clear (microdesc_cache_t *cache)
 
int microdesc_cache_reload (microdesc_cache_t *cache)
 
void microdesc_cache_clean (microdesc_cache_t *cache, time_t cutoff, int force)
 
static int should_rebuild_md_cache (microdesc_cache_t *cache)
 
static void microdesc_wipe_body (microdesc_t *md)
 
int microdesc_cache_rebuild (microdesc_cache_t *cache, int force)
 
void microdesc_check_counts (void)
 
void microdesc_free_ (microdesc_t *md, const char *fname, int lineno)
 
void microdesc_free_all (void)
 
microdesc_tmicrodesc_cache_lookup_by_digest256 (microdesc_cache_t *cache, const char *d)
 
smartlist_tmicrodesc_list_missing_digest256 (networkstatus_t *ns, microdesc_cache_t *cache, int downloadable_only, digest256map_t *skip)
 
void update_microdesc_downloads (time_t now)
 
void update_microdescs_from_networkstatus (time_t now)
 
int we_use_microdescriptors_for_circuits (const or_options_t *options)
 
int we_fetch_microdescriptors (const or_options_t *options)
 
int we_fetch_router_descriptors (const or_options_t *options)
 
 MOCK_IMPL (int, usable_consensus_flavor,(void))
 

Variables

static microdesc_cache_tthe_microdesc_cache = NULL
 

Detailed Description

Implements microdescriptors – an abbreviated description of less-frequently-changing router information.

Definition in file microdesc.c.

Macro Definition Documentation

◆ TOLERATE_MICRODESC_AGE

#define TOLERATE_MICRODESC_AGE   (7*24*60*60)

By default, we remove any microdescriptors that have gone at least this long without appearing in a current consensus.

Definition at line 533 of file microdesc.c.

Function Documentation

◆ dump_microdescriptor()

static ssize_t dump_microdescriptor ( int  fd,
microdesc_t md,
size_t *  annotation_len_out 
)
static

Write the body of md into f, with appropriate annotations. On success, return the total number of bytes written, and set *annotation_len_out to the number of bytes written as annotations.

Definition at line 199 of file microdesc.c.

References microdesc_t::body, and microdesc_t::last_listed.

◆ get_microdesc_cache()

microdesc_cache_t* get_microdesc_cache ( void  )

Return a pointer to the microdescriptor cache, loading it if necessary.

Definition at line 245 of file microdesc.c.

References get_microdesc_cache_noload().

Referenced by microdesc_cache_lookup_by_digest256(), and update_microdescs_from_networkstatus().

◆ get_microdesc_cache_noload()

static microdesc_cache_t * get_microdesc_cache_noload ( void  )
static

Return a pointer to the microdescriptor cache, creating (but not loading) it if necessary.

Definition at line 257 of file microdesc.c.

Referenced by get_microdesc_cache(), and microdesc_free_().

◆ HT_PROTOTYPE()

HT_PROTOTYPE ( HT_GENERATE2(  microdesc_map,
HT_GENERATE2(  microdesc_t,
HT_GENERATE2(  node,
HT_GENERATE2(  microdesc_hash_,
HT_GENERATE2(  microdesc_eq_ 
)

Note that we failed to fetch a microdescriptor from the relay with relay_digest (of size DIGEST_LEN).

Definition at line 89 of file microdesc.c.

◆ microdesc_cache_clean()

void microdesc_cache_clean ( microdesc_cache_t cache,
time_t  cutoff,
int  force 
)

Remove all microdescriptors from cache that haven't been listed for a long time. Does not rebuild the cache on disk. If cutoff is positive, specifically remove microdescriptors that have been unlisted since cutoff. If force is true, remove microdescriptors even if we have no current live microdescriptor consensus.

Definition at line 542 of file microdesc.c.

Referenced by microdesc_cache_rebuild().

◆ microdesc_cache_clear()

void microdesc_cache_clear ( microdesc_cache_t cache)

Remove every microdescriptor in cache.

Definition at line 459 of file microdesc.c.

References microdesc_t::held_in_map.

Referenced by microdesc_cache_reload(), and microdesc_free_all().

◆ microdesc_cache_lookup_by_digest256()

microdesc_t* microdesc_cache_lookup_by_digest256 ( microdesc_cache_t cache,
const char *  d 
)

If there is a microdescriptor in cache whose sha256 digest is d, return it. Otherwise return NULL.

Definition at line 916 of file microdesc.c.

References microdesc_t::digest, DIGEST256_LEN, and get_microdesc_cache().

◆ microdesc_cache_rebuild()

int microdesc_cache_rebuild ( microdesc_cache_t cache,
int  force 
)

Regenerate the main cache file for cache, clear the journal file, and update every microdesc_t in the cache with pointers to its new location. If force is true, do this unconditionally. If force is false, do it only if we expect to save space on disk.

Definition at line 675 of file microdesc.c.

References microdesc_cache_clean(), and the_microdesc_cache.

◆ microdesc_cache_reload()

int microdesc_cache_reload ( microdesc_cache_t cache)

Reload the contents of cache from disk. If it is empty, load it for the first time. Return 0 on success, -1 on failure.

Definition at line 488 of file microdesc.c.

References microdesc_cache_clear().

◆ microdesc_check_counts()

void microdesc_check_counts ( void  )

Make sure that the reference count of every microdescriptor in cache is accurate.

Definition at line 814 of file microdesc.c.

References microdesc_t::held_by_nodes, SMARTLIST_FOREACH, the_microdesc_cache, and tor_assert().

◆ microdesc_eq_()

static int microdesc_eq_ ( microdesc_t a,
microdesc_t b 
)
inlinestatic

Helper: compares a and b for equality for hash-table purposes.

Definition at line 84 of file microdesc.c.

References microdesc_t::digest, DIGEST256_LEN, and tor_memeq().

◆ microdesc_free_()

void microdesc_free_ ( microdesc_t md,
const char *  fname,
int  lineno 
)

Deallocate a single microdescriptor. Note: the microdescriptor MUST have previously been removed from the cache if it had ever been inserted.

Definition at line 836 of file microdesc.c.

References get_microdesc_cache_noload(), and microdesc_t::held_in_map.

◆ microdesc_free_all()

void microdesc_free_all ( void  )

Free all storage held in the microdesc.c module.

Definition at line 898 of file microdesc.c.

References microdesc_cache_clear(), SMARTLIST_FOREACH, the_microdesc_cache, and tor_free.

◆ microdesc_hash_()

static unsigned int microdesc_hash_ ( microdesc_t md)
inlinestatic

Helper: computes a hash of md to place it in a hash table.

Definition at line 76 of file microdesc.c.

References microdesc_t::digest.

◆ microdesc_list_missing_digest256()

smartlist_t* microdesc_list_missing_digest256 ( networkstatus_t ns,
microdesc_cache_t cache,
int  downloadable_only,
digest256map_t *  skip 
)

Return a smartlist of all the sha256 digest of the microdescriptors that are listed in ns but not present in cache. Returns pointers to internals of ns; you should not free the members of the resulting smartlist. Omit all microdescriptors whose digest appear in skip.

Definition at line 931 of file microdesc.c.

References networkstatus_t::flavor, and tor_assert().

◆ microdesc_relay_is_outdated_dirserver()

int microdesc_relay_is_outdated_dirserver ( const char *  relay_digest)

Return True if the relay with relay_digest (size DIGEST_LEN) is an outdated dirserver

Definition at line 159 of file microdesc.c.

References base16_encode(), DIGEST_LEN, HEX_DIGEST_LEN, and smartlist_contains_string().

Referenced by guard_obeys_md_dirserver_restriction().

◆ microdesc_reset_outdated_dirservers_list()

void microdesc_reset_outdated_dirservers_list ( void  )

Reset the list of outdated dirservers.

Definition at line 182 of file microdesc.c.

References smartlist_clear(), SMARTLIST_FOREACH, and tor_free.

◆ microdesc_wipe_body()

static void microdesc_wipe_body ( microdesc_t md)
static

Mark md as having no body, and release any storage previously held by its body.

Definition at line 655 of file microdesc.c.

References microdesc_t::body, microdesc_t::bodylen, microdesc_t::no_save, microdesc_t::off, SAVED_IN_CACHE, microdesc_t::saved_location, SAVED_NOWHERE, and tor_free.

◆ microdescs_add_list_to_cache()

smartlist_t* microdescs_add_list_to_cache ( microdesc_cache_t cache,
smartlist_t descriptors,
saved_location_t  where,
int  no_save 
)

As microdescs_add_to_cache, but takes a list of microdescriptors instead of a string to decode. Frees any members of descriptors that it does not add.

Definition at line 377 of file microdesc.c.

References SAVED_NOWHERE, and start_writing_to_file().

◆ microdescs_add_to_cache()

smartlist_t* microdescs_add_to_cache ( microdesc_cache_t cache,
const char *  s,
const char *  eos,
saved_location_t  where,
int  no_save,
time_t  listed_at,
smartlist_t requested_digests256 
)

Decode the microdescriptors from the string starting at s and ending at eos, and store them in cache. If no_save, mark them as non-writable to disk. If where is SAVED_IN_CACHE, leave their bodies as pointers to the mmap'd cache. If where is SAVED_NOWHERE, do not allow annotations. If listed_at is not -1, set the last_listed field of every microdesc to listed_at. If requested_digests is non-null, then it contains a list of digests we mean to allow, so we should reject any non-requested microdesc with a different digest, and alter the list to contain only the digests of those microdescs we didn't find. Return a newly allocated list of the added microdescriptors, or NULL

Definition at line 287 of file microdesc.c.

References microdesc_t::last_listed, microdescs_parse_from_string(), SAVED_NOWHERE, SMARTLIST_DEL_CURRENT, SMARTLIST_FOREACH, SMARTLIST_FOREACH_BEGIN, and tor_free.

◆ MOCK_IMPL()

MOCK_IMPL ( int  ,
usable_consensus_flavor  ,
(void)   
)

Return the consensus flavor we actually want to use to build circuits.

Definition at line 1055 of file microdesc.c.

References we_use_microdescriptors_for_circuits().

◆ update_microdesc_downloads()

void update_microdesc_downloads ( time_t  now)

Launch download requests for microdescriptors as appropriate.

Specifically, we should launch download requests if we are configured to download mirodescriptors, and there are some microdescriptors listed in the current microdesc consensus that we don't have, and either we never asked for them, or we failed to download them but we're willing to retry.

Definition at line 963 of file microdesc.c.

References directory_too_idle_to_fetch_descriptors(), and should_delay_dir_fetches().

Referenced by update_all_descriptor_downloads().

◆ update_microdescs_from_networkstatus()

void update_microdescs_from_networkstatus ( time_t  now)

For every microdescriptor listed in the current microdescriptor consensus, update its last_listed field to be at least as recent as the publication time of the current microdescriptor consensus.

Definition at line 1003 of file microdesc.c.

References get_microdesc_cache().

◆ we_fetch_microdescriptors()

int we_fetch_microdescriptors ( const or_options_t options)

Return true iff we should try to download microdescriptors at all.

Definition at line 1034 of file microdesc.c.

References directory_caches_dir_info(), or_options_t::FetchUselessDescriptors, and we_use_microdescriptors_for_circuits().

◆ we_fetch_router_descriptors()

int we_fetch_router_descriptors ( const or_options_t options)

Return true iff we should try to download router descriptors at all.

Definition at line 1045 of file microdesc.c.

References directory_caches_dir_info(), or_options_t::FetchUselessDescriptors, and we_use_microdescriptors_for_circuits().

Referenced by update_router_descriptor_downloads().

◆ we_use_microdescriptors_for_circuits()

int we_use_microdescriptors_for_circuits ( const or_options_t options)

Return true iff we should prefer to use microdescriptors rather than routerdescs for building circuits.

Definition at line 1025 of file microdesc.c.

References or_options_t::UseMicrodescriptors.

Referenced by MOCK_IMPL(), node_has_preferred_descriptor(), we_fetch_microdescriptors(), and we_fetch_router_descriptors().

Variable Documentation

◆ the_microdesc_cache

microdesc_cache_t* the_microdesc_cache = NULL
static

Holds a pointer to the current microdesc_cache_t object, or NULL if no such object has been allocated.

Definition at line 241 of file microdesc.c.

Referenced by microdesc_cache_rebuild(), microdesc_check_counts(), and microdesc_free_all().