tor  master
Data Structures | Macros | Typedefs | Enumerations | Functions
dirserv.c File Reference

Directory server core implementation. Manages directory contents and generates directories. More...

#include "or.h"
#include "buffers.h"
#include "config.h"
#include "confparse.h"
#include "channel.h"
#include "channeltls.h"
#include "command.h"
#include "connection.h"
#include "connection_or.h"
#include "conscache.h"
#include "consdiffmgr.h"
#include "control.h"
#include "directory.h"
#include "dirserv.h"
#include "hibernate.h"
#include "keypin.h"
#include "main.h"
#include "microdesc.h"
#include "networkstatus.h"
#include "nodelist.h"
#include "policies.h"
#include "protover.h"
#include "rephist.h"
#include "router.h"
#include "routerlist.h"
#include "routerparse.h"
#include "routerset.h"
#include "torcert.h"
#include "voting_schedule.h"
#include "dirauth/dirvote.h"
Include dependency graph for dirserv.c:

Data Structures

struct  authdir_config_t
 
struct  mbw_cache_entry_s
 

Macros

#define DIRSERV_PRIVATE
 
#define ROUTER_ALLOW_SKEW   (60*60*12)
 
#define DIR_REGEN_SLACK_TIME   30
 
#define MAX_UNTRUSTED_NETWORKSTATUSES   16
 
#define FP_INVALID   2
 
#define FP_REJECT   4
 
#define FP_BADEXIT   16
 
#define DISABLE_DISABLING_ED25519
 
#define REACHABLE_TIMEOUT   (45*60)
 
#define HIBERNATION_PUBLICATION_SKEW   (60*60)
 
#define UPTIME_TO_GUARANTEE_STABLE   (3600*24*30)
 
#define MTBF_TO_GUARANTEE_STABLE   (60*60*24*5)
 
#define TIME_KNOWN_TO_GUARANTEE_FAMILIAR   (8*24*60*60)
 
#define WFU_TO_GUARANTEE_GUARD   (0.98)
 
#define ABSOLUTE_MIN_BW_VALUE_TO_CONSIDER_KB   4
 
#define ABSOLUTE_MIN_VALUE_FOR_FAST_FLAG   4
 
#define V_LINE_OVERHEAD   7
 
#define MAX_GUARDFRACTION_FILE_AGE   (7*24*60*60) /* approx a week */
 
#define GUARDFRACTION_DATE_STR   "written-at"
 
#define GUARDFRACTION_INPUTS   "n-inputs"
 
#define GUARDFRACTION_GUARD   "guard-seen"
 
#define GUARDFRACTION_VERSION   "guardfraction-file-version"
 
#define DIRSERV_CACHED_DIR_CHUNK_SIZE   8192
 
#define DIRSERV_BUFFER_MIN   16384
 
#define WORD()
 

Typedefs

typedef uint32_t router_status_t
 
typedef struct authdir_config_t authdir_config_t
 
typedef struct mbw_cache_entry_s mbw_cache_entry_t
 

Enumerations

enum  spooled_resource_flush_status_t { SRFS_ERR = -1, SRFS_MORE = 0, SRFS_DONE }
 

Functions

int dirserv_add_own_fingerprint (crypto_pk_t *pk)
 
int dirserv_load_fingerprint_file (void)
 
uint32_t dirserv_router_get_status (const routerinfo_t *router, const char **msg, int severity)
 
int dirserv_would_reject_router (const routerstatus_t *rs)
 
void dirserv_free_fingerprint_list (void)
 
int authdir_wants_to_reject_router (routerinfo_t *ri, const char **msg, int complain, int *valid_out)
 
void dirserv_set_node_flags_from_authoritative_status (node_t *node, uint32_t authstatus)
 
was_router_added_t dirserv_add_multiple_descriptors (const char *desc, uint8_t purpose, const char *source, const char **msg)
 
was_router_added_t dirserv_add_descriptor (routerinfo_t *ri, const char **msg, const char *source)
 
int running_long_enough_to_decide_unreachable (void)
 
void dirserv_set_router_is_running (routerinfo_t *router, time_t now)
 
int list_server_status_v1 (smartlist_t *routers, char **router_status_out, int for_controller)
 
int directory_fetches_from_authorities (const or_options_t *options)
 
int directory_fetches_dir_info_early (const or_options_t *options)
 
int directory_fetches_dir_info_later (const or_options_t *options)
 
int directory_caches_unknown_auth_certs (const or_options_t *options)
 
int directory_caches_dir_info (const or_options_t *options)
 
int directory_permits_begindir_requests (const or_options_t *options)
 
int directory_too_idle_to_fetch_descriptors (const or_options_t *options, time_t now)
 
void cached_dir_decref (cached_dir_t *d)
 
cached_dir_tnew_cached_dir (char *s, time_t published)
 
void dirserv_set_cached_consensus_networkstatus (const char *networkstatus, const char *flavor_name, const common_digests_t *digests, const uint8_t *sha3_as_signed, time_t published)
 
cached_dir_tdirserv_get_consensus (const char *flavor_name)
 
void dirserv_count_measured_bws (const smartlist_t *routers)
 
void dirserv_compute_performance_thresholds (digestmap_t *omit_as_sybil)
 
void dirserv_compute_bridge_flag_thresholds (void)
 
STATIC void dirserv_cache_measured_bw (const measured_bw_line_t *parsed_line, time_t as_of)
 
void dirserv_clear_measured_bw_cache (void)
 
STATIC void dirserv_expire_measured_bw_cache (time_t now)
 
int dirserv_query_measured_bw_cache_kb (const char *node_id, long *bw_kb_out, time_t *as_of_out)
 
int dirserv_has_measured_bw (const char *node_id)
 
int dirserv_get_measured_bw_cache_size (void)
 
char * dirserv_get_flag_thresholds_line (void)
 
char * routerstatus_format_entry (const routerstatus_t *rs, const char *version, const char *protocols, routerstatus_format_type_t format, int consensus_method, const vote_routerstatus_t *vrs)
 
void set_routerstatus_from_routerinfo (routerstatus_t *rs, node_t *node, routerinfo_t *ri, time_t now, int listbadexits)
 
STATIC void dirserv_set_routerstatus_testing (routerstatus_t *rs)
 
STATIC int dirserv_read_guardfraction_file_from_str (const char *guardfraction_file_str, smartlist_t *vote_routerstatuses)
 
int dirserv_read_guardfraction_file (const char *fname, smartlist_t *vote_routerstatuses)
 
STATIC int measured_bw_line_parse (measured_bw_line_t *out, const char *orig_line)
 
STATIC int measured_bw_line_apply (measured_bw_line_t *parsed_line, smartlist_t *routerstatuses)
 
int dirserv_read_measured_bandwidths (const char *from_file, smartlist_t *routerstatuses)
 
int dirserv_get_routerdesc_spool (smartlist_t *spool_out, const char *key, dir_spool_source_t source, int conn_is_encrypted, const char **msg_out)
 
int dirserv_get_routerdescs (smartlist_t *descs_out, const char *key, const char **msg)
 
void dirserv_orconn_tls_done (const tor_addr_t *addr, uint16_t or_port, const char *digest_rcvd, const ed25519_public_key_t *ed_id_rcvd)
 
int dirserv_should_launch_reachability_test (const routerinfo_t *ri, const routerinfo_t *ri_old)
 
void dirserv_single_reachability_test (time_t now, routerinfo_t *router)
 
void dirserv_test_reachability (time_t now)
 
spooled_resource_tspooled_resource_new (dir_spool_source_t source, const uint8_t *digest, size_t digestlen)
 
spooled_resource_tspooled_resource_new_from_cache_entry (consensus_cache_entry_t *entry)
 
void spooled_resource_free_ (spooled_resource_t *spooled)
 
void dirserv_spool_remove_missing_and_guess_size (dir_connection_t *conn, time_t cutoff, int compression, size_t *size_out, int *n_expired_out)
 
void dirserv_spool_sort (dir_connection_t *conn)
 
int connection_dirserv_flushed_some (dir_connection_t *conn)
 
void dir_conn_clear_spool (dir_connection_t *conn)
 
int validate_recommended_package_line (const char *line)
 
void dirserv_free_all (void)
 

Detailed Description

Directory server core implementation. Manages directory contents and generates directories.

This module implements most of directory cache functionality, and some of the directory authority functionality. The directory.c module delegates here in order to handle incoming requests from clients, via connection_dirserv_flushed_some() and its kin. In order to save RAM, this module is responsible for spooling directory objects (in whole or in part) onto buf_t instances, and then closing the dir_connection_t once the objects are totally flushed.

The directory.c module also delegates here for handling descriptor uploads via dirserv_add_multiple_descriptors().

Additionally, this module handles some aspects of voting, including: deciding how to vote on individual flags (based on decisions reached in rephist.c), of formatting routerstatus lines, and deciding what relays to include in an authority's vote. (TODO: Those functions could profitably be split off. They only live in this file because historically they were shared among the v1, v2, and v3 directory code.)

Macro Definition Documentation

◆ ABSOLUTE_MIN_BW_VALUE_TO_CONSIDER_KB

#define ABSOLUTE_MIN_BW_VALUE_TO_CONSIDER_KB   4

Don't consider routers with less bandwidth than this when computing thresholds.

◆ DIR_REGEN_SLACK_TIME

#define DIR_REGEN_SLACK_TIME   30

How many seconds do we wait before regenerating the directory?

◆ DIRSERV_BUFFER_MIN

#define DIRSERV_BUFFER_MIN   16384

When we're spooling data onto our outbuf, add more whenever we dip below this threshold.

◆ DIRSERV_CACHED_DIR_CHUNK_SIZE

#define DIRSERV_CACHED_DIR_CHUNK_SIZE   8192

When spooling data from a cached_dir_t object, we always add at least this much.

◆ FP_BADEXIT

#define FP_BADEXIT   16

We'll tell clients not to use this as an exit.

◆ FP_INVALID

#define FP_INVALID   2

Believed invalid.

◆ FP_REJECT

#define FP_REJECT   4

We will not publish this router.

◆ GUARDFRACTION_DATE_STR

#define GUARDFRACTION_DATE_STR   "written-at"

Static strings of guardfraction files.

◆ HIBERNATION_PUBLICATION_SKEW

#define HIBERNATION_PUBLICATION_SKEW   (60*60)

If we tested a router and found it reachable at least this long after it declared itself hibernating, it is probably done hibernating and we just missed a descriptor from it.

◆ MAX_UNTRUSTED_NETWORKSTATUSES

#define MAX_UNTRUSTED_NETWORKSTATUSES   16

If we're a cache, keep this many networkstatuses around from non-trusted directory authorities.

◆ MTBF_TO_GUARANTEE_STABLE

#define MTBF_TO_GUARANTEE_STABLE   (60*60*24*5)

If a router's MTBF is at least this value, then it is always stable. See above. (Corresponds to about 7 days for current decay rates.)

◆ REACHABLE_TIMEOUT

#define REACHABLE_TIMEOUT   (45*60)

Each server needs to have passed a reachability test no more than this number of seconds ago, or it is listed as down in the directory.

◆ ROUTER_ALLOW_SKEW

#define ROUTER_ALLOW_SKEW   (60*60*12)

How far in the future do we allow a router to get? (seconds)

◆ TIME_KNOWN_TO_GUARANTEE_FAMILIAR

#define TIME_KNOWN_TO_GUARANTEE_FAMILIAR   (8*24*60*60)

Similarly, every node with at least this much weighted time known can be considered familiar enough to be a guard. Corresponds to about 20 days for current decay rates.

◆ UPTIME_TO_GUARANTEE_STABLE

#define UPTIME_TO_GUARANTEE_STABLE   (3600*24*30)

If a router's uptime is at least this value, then it is always considered stable, regardless of the rest of the network. This way we resist attacks where an attacker doubles the size of the network using allegedly high-uptime nodes, displacing all the current guards.

◆ WFU_TO_GUARANTEE_GUARD

#define WFU_TO_GUARANTEE_GUARD   (0.98)

Similarly, every node with sufficient WFU is around enough to be a guard.

◆ WORD

#define WORD ( )
Value:
do { \
if (*cp == ' ') \
return 0; \
cp = strchr(cp, ' '); \
if (!cp) \
return 0; \
} while (0)

Typedef Documentation

◆ authdir_config_t

List of nickname->identity fingerprint mappings for all the routers that we name. Used to prevent router impersonation.

◆ mbw_cache_entry_t

Measured bandwidth cache entry

◆ router_status_t

typedef uint32_t router_status_t

Target of status_by_digest map.

Enumeration Type Documentation

◆ spooled_resource_flush_status_t

Return code for spooled_resource_flush_some

Function Documentation

◆ authdir_wants_to_reject_router()

int authdir_wants_to_reject_router ( routerinfo_t ri,
const char **  msg,
int  complain,
int *  valid_out 
)

Check whether we, as a directory server, want to accept ri. If so, set its is_valid,running fields and return 0. Otherwise, return -1.

If the router is rejected, set *msg to an explanation of why.

If complain then explain at log-level 'notice' why we refused a descriptor; else explain at log-level 'info'.

Here is the call graph for this function:

◆ cached_dir_decref()

void cached_dir_decref ( cached_dir_t d)

Decrement the reference count on d, and free it if it no longer has any references.

Here is the caller graph for this function:

◆ connection_dirserv_flushed_some()

int connection_dirserv_flushed_some ( dir_connection_t conn)

Called whenever we have flushed some directory data in state SERVER_WRITING, or whenever we want to fill the buffer with initial directory data (so that subsequent writes will occur, and trigger this function again.)

Return 0 on success, and -1 on failure.

◆ dir_conn_clear_spool()

void dir_conn_clear_spool ( dir_connection_t conn)

Remove every element from conn's outgoing spool, and delete the spool.

◆ directory_caches_dir_info()

int directory_caches_dir_info ( const or_options_t options)

Return 1 if we want to fetch and serve descriptors, networkstatuses, etc Else return 0. Check options->DirPort_set and directory_permits_begindir_requests() to see if we are willing to serve these directory documents to others via the DirPort and begindir-over-ORPort, respectively.

To check if we should fetch documents, use we_want_to_fetch_flavor and we_want_to_fetch_unknown_auth_certs instead of this function.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ directory_caches_unknown_auth_certs()

int directory_caches_unknown_auth_certs ( const or_options_t options)

Return true iff we want to serve certificates for authorities that we don't acknowledge as authorities ourself. Use we_want_to_fetch_unknown_auth_certs to check if we want to fetch and keep these certificates.

Here is the call graph for this function:

◆ directory_fetches_dir_info_early()

int directory_fetches_dir_info_early ( const or_options_t options)

Return 1 if we should fetch new networkstatuses, descriptors, etc on the "mirror" schedule rather than the "client" schedule.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ directory_fetches_dir_info_later()

int directory_fetches_dir_info_later ( const or_options_t options)

Return 1 if we should fetch new networkstatuses, descriptors, etc on a very passive schedule – waiting long enough for ordinary clients to probably have the info we want. These would include bridge users, and maybe others in the future e.g. if a Tor client uses another Tor client as a directory guard.

◆ directory_fetches_from_authorities()

int directory_fetches_from_authorities ( const or_options_t options)

Return 1 if we fetch our directory material directly from the authorities, rather than from a mirror.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ directory_permits_begindir_requests()

int directory_permits_begindir_requests ( const or_options_t options)

Return 1 if we want to allow remote clients to ask us directory requests via the "begin_dir" interface, which doesn't require having any separate port open.

Here is the call graph for this function:

◆ directory_too_idle_to_fetch_descriptors()

int directory_too_idle_to_fetch_descriptors ( const or_options_t options,
time_t  now 
)

Return 1 if we have no need to fetch new descriptors. This generally happens when we're not a dir cache and we haven't built any circuits lately.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dirserv_add_descriptor()

was_router_added_t dirserv_add_descriptor ( routerinfo_t ri,
const char **  msg,
const char *  source 
)

Examine the parsed server descriptor in ri and maybe insert it into the list of server descriptors. Set *msg to a message that should be passed back to the origin of this descriptor, or NULL if there is no such message. Use source to produce better log messages.

If ri is not added to the list of server descriptors, free it. That means the caller must not access ri after this function returns, since it might have been freed.

Return the status of the operation.

This function is only called when fresh descriptors are posted, not when we re-load the cache.

◆ dirserv_add_multiple_descriptors()

was_router_added_t dirserv_add_multiple_descriptors ( const char *  desc,
uint8_t  purpose,
const char *  source,
const char **  msg 
)

As for dirserv_add_descriptor(), but accepts multiple documents, and returns the most severe error that occurred for any one of them.

◆ dirserv_add_own_fingerprint()

int dirserv_add_own_fingerprint ( crypto_pk_t pk)

Add the fingerprint for this OR to the global list of recognized identity key fingerprints.

Here is the call graph for this function:

◆ dirserv_cache_measured_bw()

STATIC void dirserv_cache_measured_bw ( const measured_bw_line_t *  parsed_line,
time_t  as_of 
)

Store a measured bandwidth cache entry when reading the measured bandwidths file.

◆ dirserv_clear_measured_bw_cache()

void dirserv_clear_measured_bw_cache ( void  )

Clear and free the measured bandwidth cache

◆ dirserv_compute_performance_thresholds()

void dirserv_compute_performance_thresholds ( digestmap_t *  omit_as_sybil)

Look through the routerlist, the Mean Time Between Failure history, and the Weighted Fractional Uptime history, and use them to set thresholds for the Stable, Fast, and Guard flags. Update the fields stable_uptime, stable_mtbf, enough_mtbf_info, guard_wfu, guard_tk, fast_bandwidth, guard_bandwidth_including_exits, and guard_bandwidth_excluding_exits.

Also, set the is_exit flag of each router appropriately.

◆ dirserv_count_measured_bws()

void dirserv_count_measured_bws ( const smartlist_t routers)

Look through the routerlist, and using the measured bandwidth cache count how many measured bandwidths we know. This is used to decide whether we ever trust advertised bandwidths for purposes of assigning flags.

◆ dirserv_expire_measured_bw_cache()

STATIC void dirserv_expire_measured_bw_cache ( time_t  now)

Scan the measured bandwidth cache and remove expired entries

◆ dirserv_free_all()

void dirserv_free_all ( void  )

Release all storage used by the directory server.

Here is the call graph for this function:

◆ dirserv_free_fingerprint_list()

void dirserv_free_fingerprint_list ( void  )

Clear the current fingerprint list.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dirserv_get_consensus()

cached_dir_t* dirserv_get_consensus ( const char *  flavor_name)

Return the latest downloaded consensus networkstatus in encoded, signed, optionally compressed format, suitable for sending to clients.

Here is the caller graph for this function:

◆ dirserv_get_flag_thresholds_line()

char* dirserv_get_flag_thresholds_line ( void  )

Give a statement of our current performance thresholds for inclusion in a vote document.

◆ dirserv_get_measured_bw_cache_size()

int dirserv_get_measured_bw_cache_size ( void  )

Get the current size of the measured bandwidth cache

◆ dirserv_get_routerdesc_spool()

int dirserv_get_routerdesc_spool ( smartlist_t spool_out,
const char *  key,
dir_spool_source_t  source,
int  conn_is_encrypted,
const char **  msg_out 
)

As dirserv_get_routerdescs(), but instead of getting signed_descriptor_t pointers, adds copies of digests to fps_out, and doesn't use the /tor/server/ prefix. For a /d/ request, adds descriptor digests; for other requests, adds identity digests.

Here is the call graph for this function:

◆ dirserv_get_routerdescs()

int dirserv_get_routerdescs ( smartlist_t descs_out,
const char *  key,
const char **  msg 
)

Add a signed_descriptor_t to descs_out for each router matching key. The key should be either

  • "/tor/server/authority" for our own routerinfo;
  • "/tor/server/all" for all the routerinfos we have, concatenated;
  • "/tor/server/fp/FP" where FP is a plus-separated sequence of hex identity digests; or
  • "/tor/server/d/D" where D is a plus-separated sequence of server descriptor digests, in hex.

Return 0 if we found some matching descriptors, or -1 if we do not have any descriptors, no matching descriptors, or if we did not recognize the key (URL). If -1 is returned *msg will be set to an appropriate error message.

XXXX rename this function. It's only called from the controller. XXXX in fact, refactor this function, merging as much as possible.

Here is the call graph for this function:

◆ dirserv_has_measured_bw()

int dirserv_has_measured_bw ( const char *  node_id)

Predicate wrapper for dirserv_query_measured_bw_cache()

Here is the call graph for this function:

◆ dirserv_load_fingerprint_file()

int dirserv_load_fingerprint_file ( void  )

Load the nickname->fingerprint mappings stored in the approved-routers file. The file format is line-based, with each non-blank holding one nickname, some space, and a fingerprint for that nickname. On success, replace the current fingerprint list with the new list and return 0. On failure, leave the current fingerprint list untouched, and return -1.

◆ dirserv_orconn_tls_done()

void dirserv_orconn_tls_done ( const tor_addr_t addr,
uint16_t  or_port,
const char *  digest_rcvd,
const ed25519_public_key_t ed_id_rcvd 
)

Called when a TLS handshake has completed successfully with a router listening at address:or_port, and has yielded a certificate with digest digest_rcvd.

Inform the reachability checker that we could get to this relay.

Here is the call graph for this function:

◆ dirserv_query_measured_bw_cache_kb()

int dirserv_query_measured_bw_cache_kb ( const char *  node_id,
long *  bw_kb_out,
time_t *  as_of_out 
)

Query the cache by identity digest, return value indicates whether we found it. The bw_out and as_of_out pointers receive the cached bandwidth value and the time it was cached if not NULL.

Here is the caller graph for this function:

◆ dirserv_read_guardfraction_file()

int dirserv_read_guardfraction_file ( const char *  fname,
smartlist_t vote_routerstatuses 
)

Read a guardfraction file at fname and load all its information to vote_routerstatuses.

◆ dirserv_read_guardfraction_file_from_str()

STATIC int dirserv_read_guardfraction_file_from_str ( const char *  guardfraction_file_str,
smartlist_t vote_routerstatuses 
)

Given a guardfraction file in a string, parse it and register the guardfraction information to the provided vote routerstatuses.

This is the rough format of the guardfraction file:

guardfraction-file-version 1
written-at <date and time>
n-inputs <number of consesuses parsed> <number of days considered>

guard-seen <fpr 1> <guardfraction percentage> <consensus appearances>
guard-seen <fpr 2> <guardfraction percentage> <consensus appearances>
guard-seen <fpr 3> <guardfraction percentage> <consensus appearances>
guard-seen <fpr 4> <guardfraction percentage> <consensus appearances>
guard-seen <fpr 5> <guardfraction percentage> <consensus appearances>
...

Return -1 if the parsing failed and 0 if it went smoothly. Parsing should tolerate errors in all lines but the written-at header.

◆ dirserv_read_measured_bandwidths()

int dirserv_read_measured_bandwidths ( const char *  from_file,
smartlist_t routerstatuses 
)

Read the measured bandwidth file and apply it to the list of vote_routerstatus_t. Returns -1 on error, 0 otherwise.

Here is the call graph for this function:

◆ dirserv_router_get_status()

uint32_t dirserv_router_get_status ( const routerinfo_t router,
const char **  msg,
int  severity 
)

Check whether router has a nickname/identity key combination that we recognize from the fingerprint list, or an IP we automatically act on according to our configuration. Return the appropriate router status.

If the status is 'FP_REJECT' and msg is provided, set *msg to an explanation of why.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dirserv_set_cached_consensus_networkstatus()

void dirserv_set_cached_consensus_networkstatus ( const char *  networkstatus,
const char *  flavor_name,
const common_digests_t digests,
const uint8_t *  sha3_as_signed,
time_t  published 
)

Replace the v3 consensus networkstatus of type flavor_name that we're serving with networkstatus, published at published. No validation is performed.

◆ dirserv_set_node_flags_from_authoritative_status()

void dirserv_set_node_flags_from_authoritative_status ( node_t node,
uint32_t  authstatus 
)

Update the relevant flags of node based on our opinion as a directory authority in authstatus, as returned by dirserv_router_get_status or equivalent.

◆ dirserv_set_router_is_running()

void dirserv_set_router_is_running ( routerinfo_t router,
time_t  now 
)

Treat a router as alive if

  • It's me, and I'm not hibernating. or - We've found it reachable recently.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ dirserv_set_routerstatus_testing()

STATIC void dirserv_set_routerstatus_testing ( routerstatus_t rs)

Use TestingDirAuthVoteExit, TestingDirAuthVoteGuard, and TestingDirAuthVoteHSDir to give out the Exit, Guard, and HSDir flags, respectively. But don't set the corresponding node flags. Should only be called if TestingTorNetwork is set.

Here is the call graph for this function:

◆ dirserv_should_launch_reachability_test()

int dirserv_should_launch_reachability_test ( const routerinfo_t ri,
const routerinfo_t ri_old 
)

Called when we, as an authority, receive a new router descriptor either as an upload or a download. Used to decide whether to relaunch reachability testing for the server.

Here is the call graph for this function:

◆ dirserv_single_reachability_test()

void dirserv_single_reachability_test ( time_t  now,
routerinfo_t router 
)

Helper function for dirserv_test_reachability(). Start a TLS connection to router, and annotate it with when we started the test.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dirserv_spool_remove_missing_and_guess_size()

void dirserv_spool_remove_missing_and_guess_size ( dir_connection_t conn,
time_t  cutoff,
int  compression,
size_t *  size_out,
int *  n_expired_out 
)

Try to guess the number of bytes that will be needed to send the spooled objects for conn's outgoing spool. In the process, remove every element of the spool that refers to an absent object, or which was published earlier than cutoff. Set *size_out to the number of bytes, and *n_expired_out to the number of objects removed for being too old.

◆ dirserv_spool_sort()

void dirserv_spool_sort ( dir_connection_t conn)

Sort all the entries in conn by digest.

Here is the call graph for this function:

◆ dirserv_test_reachability()

void dirserv_test_reachability ( time_t  now)

Auth dir server only: load balance such that we only try a few connections per call.

The load balancing is such that if we get called once every ten seconds, we will cycle through all the tests in REACHABILITY_TEST_CYCLE_PERIOD seconds (a bit over 20 minutes).

Here is the call graph for this function:

◆ dirserv_would_reject_router()

int dirserv_would_reject_router ( const routerstatus_t rs)

Return true if there is no point in downloading the router described by rs because this directory would reject it.

◆ list_server_status_v1()

int list_server_status_v1 ( smartlist_t routers,
char **  router_status_out,
int  for_controller 
)

Based on the routerinfo_ts in routers, allocate the contents of a v1-style router-status line, and store it in *router_status_out. Return 0 on success, -1 on failure.

If for_controller is true, include the routers with very old descriptors.

This is deprecated: it's only used for controllers that want outputs in the old format.

Here is the call graph for this function:

◆ measured_bw_line_apply()

STATIC int measured_bw_line_apply ( measured_bw_line_t *  parsed_line,
smartlist_t routerstatuses 
)

Helper function to apply a parsed measurement line to a list of bandwidth statuses. Returns true if a line is found, false otherwise.

Here is the call graph for this function:

◆ measured_bw_line_parse()

STATIC int measured_bw_line_parse ( measured_bw_line_t *  out,
const char *  orig_line 
)

Helper function to parse out a line in the measured bandwidth file into a measured_bw_line_t output structure. Returns -1 on failure or 0 on success.

◆ new_cached_dir()

cached_dir_t* new_cached_dir ( char *  s,
time_t  published 
)

Allocate and return a new cached_dir_t containing the string s, published at published.

◆ routerstatus_format_entry()

char* routerstatus_format_entry ( const routerstatus_t rs,
const char *  version,
const char *  protocols,
routerstatus_format_type_t  format,
int  consensus_method,
const vote_routerstatus_t vrs 
)

Helper: write the router-status information in rs into a newly allocated character buffer. Use the same format as in network-status documents. If version is non-NULL, add a "v" line for the platform.

consensus_method is the current consensus method when format is NS_V3_CONSENSUS or NS_V3_CONSENSUS_MICRODESC. It is ignored for other formats: pass ROUTERSTATUS_FORMAT_NO_CONSENSUS_METHOD.

Return 0 on success, -1 on failure.

The format argument has one of the following values: NS_V2 - Output an entry suitable for a V2 NS opinion document NS_V3_CONSENSUS - Output the first portion of a V3 NS consensus entry for consensus_method. NS_V3_CONSENSUS_MICRODESC - Output the first portion of a V3 microdesc consensus entry for consensus_method. NS_V3_VOTE - Output a complete V3 NS vote. If vrs is present, it contains additional information for the vote. NS_CONTROL_PORT - Output a NS document for the control port.

Here is the caller graph for this function:

◆ set_routerstatus_from_routerinfo()

void set_routerstatus_from_routerinfo ( routerstatus_t rs,
node_t node,
routerinfo_t ri,
time_t  now,
int  listbadexits 
)

Extract status information from ri and from other authority functions and store it in rs. rs is zeroed out before it is set.

We assume that ri->is_running has already been set, e.g. by dirserv_set_router_is_running(ri, now);

◆ spooled_resource_free_()

void spooled_resource_free_ ( spooled_resource_t spooled)

Release all storage held by spooled.

Here is the call graph for this function:

◆ spooled_resource_new_from_cache_entry()

spooled_resource_t* spooled_resource_new_from_cache_entry ( consensus_cache_entry_t entry)

Create a new spooled_resource_t to spool the contents of entry to the user. Return the spooled object on success, or NULL on failure (which is probably caused by a failure to map the body of the item from disk).

Adds a reference to entry's reference counter.

◆ validate_recommended_package_line()

int validate_recommended_package_line ( const char *  line)

Return true iff line is a valid RecommendedPackages line.

Here is the caller graph for this function: