tor  0.4.0.0-alpha-dev
Data Structures | Macros | Typedefs | Enumerations | Functions
dirserv.h File Reference
#include "lib/testsupport/testsupport.h"

Go to the source code of this file.

Data Structures

struct  spooled_resource_t
 

Macros

#define dir_spool_source_bitfield_t   ENUM_BF(dir_spool_source_t)
 
#define spooled_resource_free(sp)   FREE_AND_NULL(spooled_resource_t, spooled_resource_free_, (sp))
 

Typedefs

typedef enum dir_spool_source_t dir_spool_source_t
 
typedef struct spooled_resource_t spooled_resource_t
 

Enumerations

enum  dir_spool_source_t {
  DIR_SPOOL_SERVER_BY_DIGEST =1, DIR_SPOOL_SERVER_BY_FP, DIR_SPOOL_EXTRA_BY_DIGEST, DIR_SPOOL_EXTRA_BY_FP,
  DIR_SPOOL_MICRODESC, DIR_SPOOL_NETWORKSTATUS, DIR_SPOOL_CONSENSUS_CACHE_ENTRY
}
 

Functions

int connection_dirserv_flushed_some (dir_connection_t *conn)
 
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)
 
cached_dir_tdirserv_get_consensus (const char *flavor_name)
 
void dirserv_set_cached_consensus_networkstatus (const char *consensus, size_t consensus_len, const char *flavor_name, const common_digests_t *digests, const uint8_t *sha3_as_signed, time_t published)
 
void dirserv_clear_old_networkstatuses (time_t cutoff)
 
int dirserv_get_routerdesc_spool (smartlist_t *spools_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_free_all (void)
 
void cached_dir_decref (cached_dir_t *d)
 
cached_dir_tnew_cached_dir (char *s, time_t published)
 
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 (struct 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)
 
void dir_conn_clear_spool (dir_connection_t *conn)
 

Detailed Description

Header file for dirserv.c.

Definition in file dirserv.h.

Typedef Documentation

◆ dir_spool_source_t

Ways to convert a spoolable_resource_t to a bunch of bytes.

◆ spooled_resource_t

Object to remember the identity of an object that we are spooling, or about to spool, in response to a directory request.

(Why do we spool? Because some directory responses are very large, and we don't want to just shove the complete answer into the output buffer: that would take a ridiculous amount of RAM.)

If the spooled resource is relatively small (like microdescriptors, descriptors, etc), we look them up by ID as needed, and add the whole thing onto the output buffer at once. If the spooled reseource is big (like networkstatus documents), we reference-count it, and add it a few K at a time.

Enumeration Type Documentation

◆ dir_spool_source_t

Ways to convert a spoolable_resource_t to a bunch of bytes.

Definition at line 20 of file dirserv.h.

Function Documentation

◆ 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.

Definition at line 186 of file dirserv.c.

References clear_cached_dir(), cached_dir_t::refcnt, and tor_free.

Referenced by dirvote_clear_votes(), free_cached_dir_(), and spooled_resource_free_().

◆ 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.

Definition at line 860 of file dirserv.c.

References DIR_CONN_STATE_SERVER_WRITING, dir_connection_t::spool, connection_t::state, and tor_assert().

Referenced by connection_flushed_some().

◆ 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.

Definition at line 905 of file dirserv.c.

References SMARTLIST_FOREACH, and dir_connection_t::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.

Definition at line 143 of file dirserv.c.

References or_options_t::BridgeRelay, dir_server_mode(), and should_refuse_unknown_exits().

Referenced by directory_too_idle_to_fetch_descriptors(), we_fetch_microdescriptors(), and we_fetch_router_descriptors().

◆ 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.

Definition at line 128 of file dirserv.c.

References or_options_t::BridgeRelay, and dir_server_mode().

◆ 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.

Definition at line 105 of file dirserv.c.

References directory_fetches_from_authorities().

Referenced by update_consensus_networkstatus_fetch_time_impl().

◆ 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.

Definition at line 117 of file dirserv.c.

References or_options_t::UseBridges.

◆ 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.

Definition at line 77 of file dirserv.c.

References or_options_t::BridgeRelay, dir_server_mode(), or_options_t::FetchDirInfoEarly, should_refuse_unknown_exits(), and routerinfo_t::supports_tunnelled_dir_requests.

Referenced by directory_fetches_dir_info_early(), directory_info_has_arrived(), and fetch_networkstatus_callback().

◆ 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.

Definition at line 159 of file dirserv.c.

References or_options_t::BridgeRelay, and dir_server_mode().

◆ 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.

Definition at line 169 of file dirserv.c.

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

Referenced by directory_info_has_arrived(), update_consensus_router_descriptor_downloads(), and update_microdesc_downloads().

◆ dirserv_free_all()

void dirserv_free_all ( void  )

Release all storage used by the directory server.

Definition at line 917 of file dirserv.c.

◆ 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.

Definition at line 263 of file dirserv.c.

References cached_consensuses.

◆ 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.

Definition at line 276 of file dirserv.c.

References router_get_routerlist(), routerlist_t::routers, and SMARTLIST_FOREACH_BEGIN.

◆ 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.

Definition at line 355 of file dirserv.c.

References dir_split_resource_into_fingerprints(), router_get_routerlist(), routerlist_t::routers, smartlist_add(), SMARTLIST_FOREACH, and strcmpstart().

◆ dirserv_set_cached_consensus_networkstatus()

void dirserv_set_cached_consensus_networkstatus ( const char *  networkstatus,
size_t  networkstatus_len,
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.

Definition at line 236 of file dirserv.c.

References cached_consensuses, and new_cached_dir().

◆ 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.

Definition at line 762 of file dirserv.c.

◆ dirserv_spool_sort()

void dirserv_spool_sort ( dir_connection_t conn)

Sort all the entries in conn by digest.

Definition at line 815 of file dirserv.c.

References dirserv_spool_sort_comparison_(), smartlist_sort(), and dir_connection_t::spool.

◆ 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.

Definition at line 197 of file dirserv.c.

Referenced by dirserv_set_cached_consensus_networkstatus().

◆ spooled_resource_free_()

void spooled_resource_free_ ( spooled_resource_t spooled)

Release all storage held by spooled.

Definition at line 478 of file dirserv.c.

References cached_dir_decref(), spooled_resource_t::cached_dir_ref, spooled_resource_t::consensus_cache_entry, and tor_free.

◆ 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.

Definition at line 457 of file dirserv.c.