Tor 0.4.9.0-alpha-dev
|
Directory server core implementation. Manages directory contents and generates directory documents. More...
#include "core/or/or.h"
#include "app/config/config.h"
#include "core/mainloop/connection.h"
#include "feature/dircache/conscache.h"
#include "feature/dircache/consdiffmgr.h"
#include "feature/dircommon/directory.h"
#include "feature/dircache/dirserv.h"
#include "feature/nodelist/microdesc.h"
#include "feature/nodelist/routerlist.h"
#include "feature/relay/router.h"
#include "feature/relay/routermode.h"
#include "feature/stats/predict_ports.h"
#include "feature/dircache/cached_dir_st.h"
#include "feature/dircommon/dir_connection_st.h"
#include "feature/nodelist/extrainfo_st.h"
#include "feature/nodelist/microdesc_st.h"
#include "feature/nodelist/routerinfo_st.h"
#include "feature/nodelist/routerlist_st.h"
#include "lib/compress/compress.h"
Go to the source code of this file.
Macros | |
#define | DIRSERV_CACHED_DIR_CHUNK_SIZE 8192 |
#define | DIRSERV_BUFFER_MIN 16384 |
Enumerations | |
enum | spooled_resource_flush_status_t { SRFS_ERR = -1 , SRFS_MORE = 0 , SRFS_DONE } |
Variables | |
static strmap_t * | cached_consensuses = NULL |
Directory server core implementation. Manages directory contents and generates directory documents.
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.)
Definition in file dirserv.c.
#define DIRSERV_BUFFER_MIN 16384 |
#define DIRSERV_CACHED_DIR_CHUNK_SIZE 8192 |
When spooling data from a cached_dir_t object, we always add at least this much.
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 124 of file dirserv.c.
Referenced by free_cached_dir_(), and spooled_resource_free_().
|
static |
Remove all storage held in d, but do not free d itself.
Definition at line 151 of file dirserv.c.
Referenced by cached_dir_decref().
int connection_dirserv_flushed_some | ( | dir_connection_t * | conn | ) |
void dir_conn_clear_spool | ( | dir_connection_t * | conn | ) |
int dir_split_resource_into_spoolable | ( | const char * | resource, |
dir_spool_source_t | source, | ||
smartlist_t * | spool_out, | ||
int * | compressed_out, | ||
int | flags | ||
) |
As dir_split_resource_into_fingerprints, but instead fills spool_out with a list of spoolable_resource_t for the resource identified through source.
Definition at line 212 of file dirserv.c.
Referenced by handle_get_microdesc().
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 94 of file dirserv.c.
Referenced by dirclient_too_idle_to_fetch_descriptors(), we_fetch_microdescriptors(), and we_fetch_router_descriptors().
int directory_caches_unknown_auth_certs | ( | const or_options_t * | options | ) |
int directory_permits_begindir_requests | ( | const or_options_t * | options | ) |
void dirserv_free_all | ( | void | ) |
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 201 of file dirserv.c.
Referenced by handle_response_fetch_consensus().
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.
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 | ||
) |
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.
void dirserv_spool_sort | ( | dir_connection_t * | conn | ) |
|
static |
Helper: used to sort a connection's spool.
Definition at line 688 of file dirserv.c.
Referenced by dirserv_spool_sort().
|
static |
Return an compression ratio for compressing objects from source.
Definition at line 389 of file dirserv.c.
Referenced by spooled_resource_estimate_size().
|
static |
Free all storage held by the cached_dir_t in d.
|
static |
|
static |
Given a fingerprint fp which is either set if we're looking for a v2 status, or zeroes if we're looking for a v3 status, or a NUL-padded flavor name if we want a flavored v3 status, return a pointer to the appropriate cached dir object, or NULL if there isn't one available.
Definition at line 624 of file dirserv.c.
Referenced by spooled_resource_lookup_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 135 of file dirserv.c.
Referenced by dirserv_set_cached_consensus_networkstatus().
|
static |
|
static |
void spooled_resource_free_ | ( | spooled_resource_t * | spooled | ) |
|
static |
Helper: Look up the body for an eagerly-served spooled_resource. If conn_is_encrypted is false, don't look up any resource that shouldn't be sent over an unencrypted connection. On success, set body_out, size_out, and published_out to refer to the resource's body, size, and publication date, and return 0. On failure return -1.
Definition at line 551 of file dirserv.c.
Referenced by spooled_resource_estimate_size(), and spooled_resource_flush_some().
|
static |
Helper: find the cached_dir_t for a spooled_resource_t, for sending it to conn. Set *published_out, if provided, to the published time of the cached_dir_t.
DOES NOT increase the reference count on the result. Callers must do that themselves if they mean to hang on to it.
Definition at line 532 of file dirserv.c.
Referenced by spooled_resource_estimate_size().
spooled_resource_t * spooled_resource_new | ( | dir_spool_source_t | source, |
const uint8_t * | digest, | ||
size_t | digestlen | ||
) |
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.
|
static |
Map from flavor name to the cached_dir_t for the v3 consensuses that we're currently serving.
Definition at line 119 of file dirserv.c.
Referenced by dirserv_get_consensus(), dirserv_set_cached_consensus_networkstatus(), and lookup_cached_dir_by_fp().