Tor  0.4.7.0-alpha-dev
Macros | Enumerations | Functions
routerlist.h File Reference

Header file for routerlist.c. More...

#include "lib/testsupport/testsupport.h"

Go to the source code of this file.

Macros

#define DIR_503_TIMEOUT   (60*60)
 
#define routerinfo_free(router)    FREE_AND_NULL(routerinfo_t, routerinfo_free_, (router))
 
#define extrainfo_free(ei)   FREE_AND_NULL(extrainfo_t, extrainfo_free_, (ei))
 
#define routerlist_free(rl)   FREE_AND_NULL(routerlist_t, routerlist_free_, (rl))
 

Enumerations

enum  was_router_added_t {
  ROUTER_ADDED_SUCCESSFULLY = 1 , ROUTER_BAD_EI = -1 , ROUTER_IS_ALREADY_KNOWN = -2 , ROUTER_NOT_IN_CONSENSUS = -3 ,
  ROUTER_NOT_IN_CONSENSUS_OR_NETWORKSTATUS = -4 , ROUTER_AUTHDIR_REJECTS = -5 , ROUTER_WAS_NOT_WANTED = -6 , ROUTER_WAS_TOO_OLD = -7 ,
  ROUTER_CERTS_EXPIRED = -8 , ROUTER_AUTHDIR_BUG_ANNOTATIONS = -10
}
 

Functions

int router_reload_router_list (void)
 
int router_or_conn_should_skip_reachable_address_check (const or_options_t *options, int try_ip_pref)
 
int router_dir_conn_should_skip_reachable_address_check (const or_options_t *options, int try_ip_pref)
 
void router_reset_status_download_failures (void)
 
int routers_have_same_or_addrs (const routerinfo_t *r1, const routerinfo_t *r2)
 
bool router_can_choose_node (const node_t *node, int flags)
 
void router_add_running_nodes_to_smartlist (smartlist_t *sl, int flags)
 
const routerinfo_trouterlist_find_my_routerinfo (void)
 
uint32_t router_get_advertised_bandwidth (const routerinfo_t *router)
 
uint32_t router_get_advertised_bandwidth_capped (const routerinfo_t *router)
 
int hexdigest_to_digest (const char *hexdigest, char *digest)
 
const routerinfo_trouter_get_by_id_digest (const char *digest)
 
routerinfo_trouter_get_mutable_by_digest (const char *digest)
 
signed_descriptor_trouter_get_by_descriptor_digest (const char *digest)
 
signed_descriptor_trouter_get_by_extrainfo_digest (const char *digest)
 
signed_descriptor_textrainfo_get_by_descriptor_digest (const char *digest)
 
const char * signed_descriptor_get_body (const signed_descriptor_t *desc)
 
const char * signed_descriptor_get_annotations (const signed_descriptor_t *desc)
 
routerlist_trouter_get_routerlist (void)
 
void routerinfo_free_ (routerinfo_t *router)
 
void extrainfo_free_ (extrainfo_t *extrainfo)
 
void routerlist_free_ (routerlist_t *rl)
 
void dump_routerlist_mem_usage (int severity)
 
void routerlist_remove (routerlist_t *rl, routerinfo_t *ri, int make_old, time_t now)
 
void routerlist_free_all (void)
 
void routerlist_reset_warnings (void)
 
void list_pending_downloads (digestmap_t *result, digest256map_t *result256, int purpose, const char *prefix)
 
static int WRA_WAS_ADDED (was_router_added_t s)
 
static int WRA_WAS_OUTDATED (was_router_added_t s)
 
static int WRA_WAS_REJECTED (was_router_added_t s)
 
static int WRA_NEVER_DOWNLOADABLE (was_router_added_t s)
 
was_router_added_t router_add_to_routerlist (routerinfo_t *router, const char **msg, int from_cache, int from_fetch)
 
was_router_added_t router_add_extrainfo_to_routerlist (extrainfo_t *ei, const char **msg, int from_cache, int from_fetch)
 
void routerlist_descriptors_added (smartlist_t *sl, int from_cache)
 
void routerlist_remove_old_routers (void)
 
int router_load_single_router (const char *s, uint8_t purpose, int cache, const char **msg)
 
int router_load_routers_from_string (const char *s, const char *eos, saved_location_t saved_location, smartlist_t *requested_fingerprints, int descriptor_digests, const char *prepend_annotations)
 
void router_load_extrainfo_from_string (const char *s, const char *eos, saved_location_t saved_location, smartlist_t *requested_fingerprints, int descriptor_digests)
 
void routerlist_retry_directory_downloads (time_t now)
 
int router_exit_policy_rejects_all (const routerinfo_t *router)
 
void update_consensus_router_descriptor_downloads (time_t now, int is_vote, networkstatus_t *consensus)
 
void update_router_descriptor_downloads (time_t now)
 
void update_all_descriptor_downloads (time_t now)
 
void update_extrainfo_downloads (time_t now)
 
void router_reset_descriptor_download_failures (void)
 
int router_differences_are_cosmetic (const routerinfo_t *r1, const routerinfo_t *r2)
 
int routerinfo_incompatible_with_extrainfo (const crypto_pk_t *ri, extrainfo_t *ei, signed_descriptor_t *sd, const char **msg)
 
int routerinfo_has_curve25519_onion_key (const routerinfo_t *ri)
 
int routerstatus_version_supports_extend2_cells (const routerstatus_t *rs, int allow_unknown_versions)
 
void routerlist_assert_ok (const routerlist_t *rl)
 
const char * esc_router_info (const routerinfo_t *router)
 
void routers_sort_by_identity (smartlist_t *routers)
 
void refresh_all_country_info (void)
 
void list_pending_microdesc_downloads (digest256map_t *result)
 
void launch_descriptor_downloads (int purpose, smartlist_t *downloadable, const routerstatus_t *source, time_t now)
 
int hex_digest_nickname_decode (const char *hexdigest, char *digest_out, char *nickname_qualifier_out, char *nickname_out)
 
int hex_digest_nickname_matches (const char *hexdigest, const char *identity_digest, const char *nickname)
 

Detailed Description

Header file for routerlist.c.

Definition in file routerlist.h.

Macro Definition Documentation

◆ DIR_503_TIMEOUT

#define DIR_503_TIMEOUT   (60*60)

How long do we avoid using a directory server after it's given us a 503?

Definition at line 49 of file routerlist.h.

Enumeration Type Documentation

◆ was_router_added_t

Return value for router_add_to_routerlist() and dirserv_add_descriptor()

Definition at line 17 of file routerlist.h.

Function Documentation

◆ dump_routerlist_mem_usage()

void dump_routerlist_mem_usage ( int  severity)

Log information about how much memory is being used for routerlist, at log level severity.

Definition at line 1060 of file routerlist.c.

Referenced by dumpmemusage().

◆ esc_router_info()

const char* esc_router_info ( const routerinfo_t router)

Allocate and return a new string representing the contact info and platform string for router, surrounded by quotes and using standard C escapes.

THIS FUNCTION IS NOT REENTRANT. Don't call it from outside the main thread. Also, each call invalidates the last-returned value, so don't try log_warn(LD_GENERAL, "%s %s", esc_router_info(a), esc_router_info(b));

If router is NULL, it just frees its internal memory and returns.

Definition at line 3243 of file routerlist.c.

◆ extrainfo_free_()

void extrainfo_free_ ( extrainfo_t extrainfo)

Release all storage held by extrainfo

Definition at line 950 of file routerlist.c.

Referenced by extrainfo_free_void().

◆ extrainfo_get_by_descriptor_digest()

signed_descriptor_t* extrainfo_get_by_descriptor_digest ( const char *  digest)

Return the signed descriptor for the extrainfo_t in our routerlist whose extra-info-digest is digest. Return NULL if no such extra-info document is known.

Definition at line 810 of file routerlist.c.

Referenced by get_signed_descriptor_by_fp().

◆ hex_digest_nickname_decode()

int hex_digest_nickname_decode ( const char *  hexdigest,
char *  digest_out,
char *  nickname_qualifier_char_out,
char *  nickname_out 
)

Helper: given an extended nickname in hexdigest try to decode it. Return 0 on success, -1 on failure. Store the result into the DIGEST_LEN-byte buffer at digest_out, the single character at nickname_qualifier_char_out, and the MAXNICKNAME_LEN+1-byte buffer at nickname_out.

The recognized format is: HexName = Dollar? HexDigest NamePart? Dollar = '?' HexDigest = HexChar*20 HexChar = 'a'..'f' | 'A'..'F' | '0'..'9' NamePart = QualChar Name QualChar = '=' | '~' Name = NameChar*(1..MAX_NICKNAME_LEN) NameChar = Any ASCII alphanumeric character

Definition at line 684 of file routerlist.c.

Referenced by hex_digest_nickname_matches(), and node_get_by_hex_id().

◆ hex_digest_nickname_matches()

int hex_digest_nickname_matches ( const char *  hexdigest,
const char *  identity_digest,
const char *  nickname 
)

Helper: Return true iff the identity_digest and nickname combination of a router, encoded in hexadecimal, matches hexdigest (which is optionally prefixed with a single dollar sign). Return false if hexdigest is malformed, or it doesn't match.

Definition at line 720 of file routerlist.c.

Referenced by node_nickname_matches().

◆ hexdigest_to_digest()

int hexdigest_to_digest ( const char *  hexdigest,
char *  digest 
)

If hexdigest is correctly formed, base16_decode it into digest, which must have DIGEST_LEN space in it. Return 0 on success, -1 on failure.

Definition at line 749 of file routerlist.c.

Referenced by connection_ap_fail_onehop().

◆ launch_descriptor_downloads()

void launch_descriptor_downloads ( int  purpose,
smartlist_t downloadable,
const routerstatus_t source,
time_t  now 
)

Given a purpose (FETCH_MICRODESC or FETCH_SERVERDESC) and a list of router descriptor digests or microdescriptor digest256s in downloadable, decide whether to delay fetching until we have more. If we don't want to delay, launch one or more requests to the appropriate directory authorities.

Definition at line 2520 of file routerlist.c.

◆ list_pending_downloads()

void list_pending_downloads ( digestmap_t *  result,
digest256map_t *  result256,
int  purpose,
const char *  prefix 
)

For every current directory connection whose purpose is purpose, and where the resource being downloaded begins with prefix, split rest of the resource into base16 fingerprints (or base64 fingerprints if purpose==DIR_PURPOSE_FETCH_MICRODESC), decode them, and set the corresponding elements of result to a nonzero value.

Definition at line 2342 of file routerlist.c.

Referenced by list_pending_descriptor_downloads(), and list_pending_microdesc_downloads().

◆ list_pending_microdesc_downloads()

void list_pending_microdesc_downloads ( digest256map_t *  result)

For every microdescriptor we are currently downloading by descriptor digest, set result[d] to (void*)1.

Definition at line 2396 of file routerlist.c.

◆ refresh_all_country_info()

void refresh_all_country_info ( void  )

Called when we change a node set, or when we reload the geoip IPv4 list: recompute all country info in all configuration node sets and in the routerlist.

Definition at line 3284 of file routerlist.c.

Referenced by config_maybe_load_geoip_files_().

◆ router_add_extrainfo_to_routerlist()

was_router_added_t router_add_extrainfo_to_routerlist ( extrainfo_t ei,
const char **  msg,
int  from_cache,
int  from_fetch 
)

Insert ei into the routerlist, or free it. Other arguments are as for router_add_to_routerlist(). Return ROUTER_ADDED_SUCCESSFULLY iff we actually inserted it, ROUTER_BAD_EI otherwise.

Definition at line 1749 of file routerlist.c.

◆ router_add_running_nodes_to_smartlist()

void router_add_running_nodes_to_smartlist ( smartlist_t sl,
int  flags 
)

Add every suitable node from our nodelist to sl, so that we can pick a node for a circuit based on flags.

See router_can_choose_node() for details of flags.

Definition at line 615 of file routerlist.c.

Referenced by pick_restricted_middle_node().

◆ router_add_to_routerlist()

was_router_added_t router_add_to_routerlist ( routerinfo_t router,
const char **  msg,
int  from_cache,
int  from_fetch 
)

Add router to the routerlist, if we don't already have it. Replace older entries (if any) with the same key.

Note: Callers should not hold their pointers to router if this function fails; router will either be inserted into the routerlist or freed. Similarly, even if this call succeeds, they should not hold their pointers to router after subsequent calls with other routerinfo's – they might cause the original routerinfo to get freed.

Returns the status for the operation. Might set *msg if it wants the poster of the router to know something.

If from_cache, this descriptor came from our disk cache. If from_fetch, we received it in response to a request we made. (If both are false, that means it was uploaded to us as an auth dir server or via the controller.)

This function should be called after routers_update_status_from_consensus_networkstatus; subsequently, you should call router_rebuild_store and routerlist_descriptors_added.

Definition at line 1573 of file routerlist.c.

◆ router_differences_are_cosmetic()

int router_differences_are_cosmetic ( const routerinfo_t r1,
const routerinfo_t r2 
)

Return true iff the only differences between r1 and r2 are such that would not cause a recent (post 0.1.1.6) dirserver to republish.

Definition at line 2922 of file routerlist.c.

◆ router_exit_policy_rejects_all()

int router_exit_policy_rejects_all ( const routerinfo_t router)

Return true iff router does not permit exit streams.

Definition at line 2330 of file routerlist.c.

◆ router_get_advertised_bandwidth()

uint32_t router_get_advertised_bandwidth ( const routerinfo_t router)

Return the smaller of the router's configured BandwidthRate and its advertised capacity.

Definition at line 643 of file routerlist.c.

Referenced by dirserv_get_bandwidth_for_router_kb().

◆ router_get_advertised_bandwidth_capped()

uint32_t router_get_advertised_bandwidth_capped ( const routerinfo_t router)

Return the smaller of the router's configured BandwidthRate and its advertised capacity, capped by max-believe-bw.

Definition at line 657 of file routerlist.c.

◆ router_get_by_descriptor_digest()

signed_descriptor_t* router_get_by_descriptor_digest ( const char *  digest)

Return the router in our routerlist whose 20-byte descriptor is digest. Return NULL if no such router is known.

Definition at line 784 of file routerlist.c.

◆ router_get_by_extrainfo_digest()

signed_descriptor_t* router_get_by_extrainfo_digest ( const char *  digest)

Return the signed descriptor for the router in our routerlist whose 20-byte extra-info digest is digest. Return NULL if no such router is known.

Definition at line 797 of file routerlist.c.

◆ router_get_by_id_digest()

const routerinfo_t* router_get_by_id_digest ( const char *  digest)

Return the router in our routerlist whose 20-byte key digest is digest. Return NULL if no such router is known.

Definition at line 776 of file routerlist.c.

Referenced by connection_or_digest_is_known_relay(), and get_signed_descriptor_by_fp().

◆ router_get_mutable_by_digest()

routerinfo_t* router_get_mutable_by_digest ( const char *  digest)

As router_get_by_id_digest,but return a pointer that you're allowed to modify

Definition at line 762 of file routerlist.c.

Referenced by dirserv_add_extrainfo(), and router_get_by_id_digest().

◆ router_get_routerlist()

routerlist_t* router_get_routerlist ( void  )

◆ router_load_extrainfo_from_string()

void router_load_extrainfo_from_string ( const char *  s,
const char *  eos,
saved_location_t  saved_location,
smartlist_t requested_fingerprints,
int  descriptor_digests 
)

Parse one or more extrainfos from s (ending immediately before eos if eos is present). Other arguments are as for router_load_routers_from_string().

Definition at line 2213 of file routerlist.c.

◆ router_load_routers_from_string()

int router_load_routers_from_string ( const char *  s,
const char *  eos,
saved_location_t  saved_location,
smartlist_t requested_fingerprints,
int  descriptor_digests,
const char *  prepend_annotations 
)

Given a string s containing some routerdescs, parse it and put the routers into our directory. If saved_location is SAVED_NOWHERE, the routers are in response to a query to the network: cache them by adding them to the journal.

Return the number of routers actually added.

If requested_fingerprints is provided, it must contain a list of uppercased fingerprints. Do not update any router whose fingerprint is not on the list; after updating a router, remove its fingerprint from the list.

If descriptor_digests is non-zero, then the requested_fingerprints are descriptor digests. Otherwise they are identity digests.

Definition at line 2114 of file routerlist.c.

◆ router_load_single_router()

int router_load_single_router ( const char *  s,
uint8_t  purpose,
int  cache,
const char **  msg 
)

Code to parse a single router descriptor and insert it into the routerlist. Return -1 if the descriptor was ill-formed; 0 if the descriptor was well-formed but could not be added; and 1 if the descriptor was added.

If we don't add it and msg is not NULL, then assign to *msg a static string describing the reason for refusing the descriptor.

This is used only by the controller.

Definition at line 2047 of file routerlist.c.

Referenced by handle_control_postdescriptor().

◆ router_reload_router_list()

int router_reload_router_list ( void  )

Load all cached router descriptors and extra-info documents from the store. Return 0 on success and -1 on failure.

Definition at line 460 of file routerlist.c.

◆ router_reset_descriptor_download_failures()

void router_reset_descriptor_download_failures ( void  )

Reset the consensus and extra-info download failure count on all routers. When we get a new consensus, routers_update_status_from_consensus_networkstatus() will reset the download statuses on the descriptors in that consensus.

Definition at line 2890 of file routerlist.c.

◆ router_reset_status_download_failures()

void router_reset_status_download_failures ( void  )

Reset all internal variables used to count failed downloads of network status objects.

Definition at line 151 of file dirlist.c.

◆ routerinfo_free_()

void routerinfo_free_ ( routerinfo_t router)

Free all storage held by router.

Definition at line 920 of file routerlist.c.

◆ routerinfo_incompatible_with_extrainfo()

int routerinfo_incompatible_with_extrainfo ( const crypto_pk_t identity_pkey,
extrainfo_t ei,
signed_descriptor_t sd,
const char **  msg 
)

Check whether sd describes a router descriptor compatible with the extrainfo document ei.

identity_pkey (which must also be provided) is RSA1024 identity key for the router. We use it to check the signature of the extrainfo document, if it has not already been checked.

If no router is compatible with ei, ei should be dropped. Return 0 for "compatible", return 1 for "reject, and inform whoever uploaded <b>ei</b>, and return -1 for "reject silently.". If msg is present, set *msg to a description of the incompatibility (if any).

Set the extrainfo_is_bogus field in sd if the digests matched but the extrainfo was nonetheless incompatible.

Definition at line 3018 of file routerlist.c.

◆ routerlist_assert_ok()

void routerlist_assert_ok ( const routerlist_t rl)

Assert that the internal representation of rl is self-consistent.

Definition at line 3155 of file routerlist.c.

◆ routerlist_descriptors_added()

void routerlist_descriptors_added ( smartlist_t sl,
int  from_cache 
)

We just added a new set of descriptors. Take whatever extra steps we need.

Definition at line 2018 of file routerlist.c.

◆ routerlist_find_my_routerinfo()

const routerinfo_t* routerlist_find_my_routerinfo ( void  )

Look through the routerlist until we find a router that has my key. Return it.

Definition at line 627 of file routerlist.c.

◆ routerlist_free_()

void routerlist_free_ ( routerlist_t rl)

Free all storage held by a routerlist rl.

Definition at line 1028 of file routerlist.c.

◆ routerlist_free_all()

void routerlist_free_all ( void  )

Free all memory held by the routerlist module. Note: Calling routerlist_free_all() should always be paired with a call to nodelist_free_all(). These should only be called during cleanup.

Definition at line 1515 of file routerlist.c.

◆ routerlist_remove()

void routerlist_remove ( routerlist_t rl,
routerinfo_t ri,
int  make_old,
time_t  now 
)

Remove an item ri from the routerlist rl, updating indices as needed. If idx is nonnegative and smartlist_get(rl->routers, idx) == ri, we don't need to do a linear search over the list to decide which to remove. We fill the gap in rl->routers with a later element in the list, if any exists. ri is freed.

If make_old is true, instead of deleting the router, we try adding it to rl->old_routers.

Definition at line 1275 of file routerlist.c.

◆ routerlist_remove_old_routers()

void routerlist_remove_old_routers ( void  )

Deactivate any routers from the routerlist that are more than ROUTER_MAX_AGE seconds old and not recommended by any networkstatuses; remove old routers from the list of cached routers if we have too many.

Definition at line 1892 of file routerlist.c.

◆ routerlist_reset_warnings()

void routerlist_reset_warnings ( void  )

Forget that we have issued any router-related warnings, so that we'll warn again if we see the same errors.

Definition at line 1533 of file routerlist.c.

◆ routerlist_retry_directory_downloads()

void routerlist_retry_directory_downloads ( time_t  now)

Clear all our timeouts for fetching v3 directory stuff, and then give it all a try again.

Definition at line 2315 of file routerlist.c.

◆ routers_have_same_or_addrs()

int routers_have_same_or_addrs ( const routerinfo_t r1,
const routerinfo_t r2 
)

Return true iff r1 and r2 have the same address and OR port.

Definition at line 509 of file routerlist.c.

Referenced by nodelist_set_routerinfo().

◆ routers_sort_by_identity()

void routers_sort_by_identity ( smartlist_t routers)

Sort a list of routerinfo_t in ascending order of identity digest.

Definition at line 3275 of file routerlist.c.

◆ signed_descriptor_get_annotations()

const char* signed_descriptor_get_annotations ( const signed_descriptor_t desc)

As signed_descriptor_get_body(), but points to the beginning of the annotations section rather than the beginning of the descriptor.

Definition at line 888 of file routerlist.c.

Referenced by routerlist_reparse_old().

◆ signed_descriptor_get_body()

const char* signed_descriptor_get_body ( const signed_descriptor_t desc)

Return a pointer to the signed textual representation of a descriptor. The returned string is not guaranteed to be NUL-terminated: the string's length will be in desc->signed_descriptor_len.

The caller must not free the string returned.

Definition at line 880 of file routerlist.c.

Referenced by getinfo_helper_dir(), munge_extrainfo_into_routerinfo(), and router_get_my_descriptor().

◆ update_all_descriptor_downloads()

void update_all_descriptor_downloads ( time_t  now)

Update downloads for router descriptors and/or microdescriptors as appropriate.

Definition at line 2304 of file routerlist.c.

Referenced by directory_info_has_arrived().

◆ update_consensus_router_descriptor_downloads()

void update_consensus_router_descriptor_downloads ( time_t  now,
int  is_vote,
networkstatus_t consensus 
)

For any descriptor that we want that's currently listed in consensus, download it as appropriate.

Definition at line 2618 of file routerlist.c.

Referenced by update_router_descriptor_downloads().

◆ update_extrainfo_downloads()

void update_extrainfo_downloads ( time_t  now)

Launch extrainfo downloads as needed.

Definition at line 2779 of file routerlist.c.

Referenced by directory_info_has_arrived().

◆ update_router_descriptor_downloads()

void update_router_descriptor_downloads ( time_t  now)

Launch downloads for router status as needed.

Definition at line 2765 of file routerlist.c.

Referenced by update_all_descriptor_downloads().

◆ WRA_NEVER_DOWNLOADABLE()

static int WRA_NEVER_DOWNLOADABLE ( was_router_added_t  s)
inlinestatic

Return true iff the outcome code in s indicates that the descriptor was flat-out rejected.

Definition at line 132 of file routerlist.h.

◆ WRA_WAS_ADDED()

static int WRA_WAS_ADDED ( was_router_added_t  s)
inlinestatic

Return true iff the outcome code in s indicates that the descriptor was added. It might still be necessary to check whether the descriptor generator should be notified.

Definition at line 106 of file routerlist.h.

Referenced by router_add_extrainfo_to_routerlist().

◆ WRA_WAS_OUTDATED()

static int WRA_WAS_OUTDATED ( was_router_added_t  s)
inlinestatic

Return true iff the outcome code in s indicates that the descriptor was not added because it was either:

  • not in the consensus
  • neither in the consensus nor in any networkstatus document
  • it was outdated.
  • its certificates were expired.

Definition at line 116 of file routerlist.h.

◆ WRA_WAS_REJECTED()

static int WRA_WAS_REJECTED ( was_router_added_t  s)
inlinestatic

Return true iff the outcome code in s indicates that the descriptor was flat-out rejected.

Definition at line 126 of file routerlist.h.