Tor 0.4.9.0-alpha-dev
|
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 } |
Header file for routerlist.c.
Definition in file routerlist.h.
#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.
#define extrainfo_free | ( | ei | ) | FREE_AND_NULL(extrainfo_t, extrainfo_free_, (ei)) |
Definition at line 83 of file routerlist.h.
#define routerinfo_free | ( | router | ) | FREE_AND_NULL(routerinfo_t, routerinfo_free_, (router)) |
Definition at line 80 of file routerlist.h.
#define routerlist_free | ( | rl | ) | FREE_AND_NULL(routerlist_t, routerlist_free_, (rl)) |
Definition at line 85 of file routerlist.h.
enum was_router_added_t |
Return value for router_add_to_routerlist() and dirserv_add_descriptor()
Definition at line 17 of file routerlist.h.
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 1063 of file routerlist.c.
Referenced by dumpmemusage().
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 3302 of file routerlist.c.
void extrainfo_free_ | ( | extrainfo_t * | extrainfo | ) |
Release all storage held by extrainfo
Definition at line 953 of file routerlist.c.
Referenced by extrainfo_free_void().
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 813 of file routerlist.c.
Referenced by get_signed_descriptor_by_fp().
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 687 of file routerlist.c.
Referenced by hex_digest_nickname_matches(), and node_get_by_hex_id().
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 723 of file routerlist.c.
Referenced by node_nickname_matches().
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 752 of file routerlist.c.
Referenced by connection_ap_fail_onehop().
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 2552 of file routerlist.c.
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 2374 of file routerlist.c.
Referenced by list_pending_descriptor_downloads(), and 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 2428 of file routerlist.c.
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 3343 of file routerlist.c.
Referenced by config_maybe_load_geoip_files_().
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 1759 of file routerlist.c.
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 618 of file routerlist.c.
Referenced by pick_restricted_middle_node().
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 1576 of file routerlist.c.
bool router_can_choose_node | ( | const node_t * | node, |
int | flags | ||
) |
Definition at line 550 of file routerlist.c.
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 2982 of file routerlist.c.
int router_dir_conn_should_skip_reachable_address_check | ( | const or_options_t * | options, |
int | try_ip_pref | ||
) |
Definition at line 495 of file routerlist.c.
int router_exit_policy_rejects_all | ( | const routerinfo_t * | router | ) |
Return true iff router does not permit exit streams.
Definition at line 2362 of file routerlist.c.
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 646 of file routerlist.c.
Referenced by dirserv_get_bandwidth_for_router_kb().
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 660 of file routerlist.c.
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 787 of file routerlist.c.
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 800 of file routerlist.c.
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 779 of file routerlist.c.
Referenced by connection_or_digest_is_known_relay(), and get_signed_descriptor_by_fp().
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 765 of file routerlist.c.
Referenced by dirserv_add_extrainfo(), and router_get_by_id_digest().
routerlist_t * router_get_routerlist | ( | void | ) |
Return the current list of all known routers.
Definition at line 898 of file routerlist.c.
Referenced by controller_get_routerdescs(), directory_remove_invalid(), dirserv_get_routerdesc_spool(), dirserv_set_bridges_running(), networkstatus_getinfo_by_purpose(), nodelist_assert_ok(), router_add_extrainfo_to_routerlist(), router_reload_router_list(), routers_update_all_from_networkstatus(), signed_descriptor_get_body_impl(), and update_extrainfo_downloads().
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 2245 of file routerlist.c.
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 2146 of file routerlist.c.
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 2079 of file routerlist.c.
Referenced by handle_control_postdescriptor().
int router_or_conn_should_skip_reachable_address_check | ( | const or_options_t * | options, |
int | try_ip_pref | ||
) |
Definition at line 479 of file routerlist.c.
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 458 of file routerlist.c.
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 2932 of file routerlist.c.
void router_reset_status_download_failures | ( | void | ) |
void routerinfo_free_ | ( | routerinfo_t * | router | ) |
Free all storage held by router.
Definition at line 923 of file routerlist.c.
int routerinfo_has_curve25519_onion_key | ( | const routerinfo_t * | ri | ) |
Definition at line 3173 of file routerlist.c.
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 3077 of file routerlist.c.
void routerlist_assert_ok | ( | const routerlist_t * | rl | ) |
Assert that the internal representation of rl is self-consistent.
Definition at line 3214 of file routerlist.c.
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 2050 of file routerlist.c.
void routerlist_drop_bridge_descriptors | ( | void | ) |
Definition at line 2027 of file routerlist.c.
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 630 of file routerlist.c.
void routerlist_free_ | ( | routerlist_t * | rl | ) |
Free all storage held by a routerlist rl.
Definition at line 1031 of file routerlist.c.
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 1518 of file routerlist.c.
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 1278 of file routerlist.c.
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 1902 of file routerlist.c.
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 1536 of file routerlist.c.
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 2347 of file routerlist.c.
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 507 of file routerlist.c.
Referenced by nodelist_set_routerinfo().
void routers_sort_by_identity | ( | smartlist_t * | routers | ) |
Sort a list of routerinfo_t in ascending order of identity digest.
Definition at line 3334 of file routerlist.c.
int routerstatus_version_supports_extend2_cells | ( | const routerstatus_t * | rs, |
int | allow_unknown_versions | ||
) |
Definition at line 3197 of file routerlist.c.
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 891 of file routerlist.c.
Referenced by routerlist_reparse_old().
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 883 of file routerlist.c.
Referenced by getinfo_helper_dir(), munge_extrainfo_into_routerinfo(), and router_get_my_descriptor().
void update_all_descriptor_downloads | ( | time_t | now | ) |
Update downloads for router descriptors and/or microdescriptors as appropriate.
Definition at line 2336 of file routerlist.c.
Referenced by directory_info_has_arrived().
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 2650 of file routerlist.c.
Referenced by update_router_descriptor_downloads().
void update_extrainfo_downloads | ( | time_t | now | ) |
Launch extrainfo downloads as needed.
Definition at line 2821 of file routerlist.c.
Referenced by directory_info_has_arrived().
void update_router_descriptor_downloads | ( | time_t | now | ) |
Launch downloads for router status as needed.
Definition at line 2807 of file routerlist.c.
Referenced by update_all_descriptor_downloads().
|
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.
|
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().
|
inlinestatic |
Return true iff the outcome code in s indicates that the descriptor was not added because it was either:
Definition at line 116 of file routerlist.h.
|
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.