Tor  0.4.3.0-alpha-dev
dirserv.h
Go to the documentation of this file.
1 /* Copyright (c) 2001 Matej Pfajfar.
2  * Copyright (c) 2001-2004, Roger Dingledine.
3  * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
4  * Copyright (c) 2007-2019, The Tor Project, Inc. */
5 /* See LICENSE for licensing information */
6 
7 /**
8  * \file dirserv.h
9  * \brief Header file for dirserv.c.
10  **/
11 
12 #ifndef TOR_DIRSERV_H
13 #define TOR_DIRSERV_H
14 
16 
18 
19 /** Ways to convert a spoolable_resource_t to a bunch of bytes. */
20 typedef enum dir_spool_source_t {
21  DIR_SPOOL_SERVER_BY_DIGEST=1, DIR_SPOOL_SERVER_BY_FP,
22  DIR_SPOOL_EXTRA_BY_DIGEST, DIR_SPOOL_EXTRA_BY_FP,
23  DIR_SPOOL_MICRODESC,
24  DIR_SPOOL_NETWORKSTATUS,
25  DIR_SPOOL_CONSENSUS_CACHE_ENTRY,
27 #define dir_spool_source_bitfield_t ENUM_BF(dir_spool_source_t)
28 
29 /** Object to remember the identity of an object that we are spooling,
30  * or about to spool, in response to a directory request.
31  *
32  * (Why do we spool? Because some directory responses are very large,
33  * and we don't want to just shove the complete answer into the output
34  * buffer: that would take a ridiculous amount of RAM.)
35  *
36  * If the spooled resource is relatively small (like microdescriptors,
37  * descriptors, etc), we look them up by ID as needed, and add the whole
38  * thing onto the output buffer at once. If the spooled reseource is
39  * big (like networkstatus documents), we reference-count it, and add it
40  * a few K at a time.
41  */
42 typedef struct spooled_resource_t {
43  /**
44  * If true, we add the entire object to the outbuf. If false,
45  * we spool the object a few K at a time.
46  */
47  unsigned spool_eagerly : 1;
48  /**
49  * Tells us what kind of object to get, and how to look it up.
50  */
51  dir_spool_source_bitfield_t spool_source : 7;
52  /**
53  * Tells us the specific object to spool.
54  */
56  /**
57  * A large object that we're spooling. Holds a reference count. Only
58  * used when spool_eagerly is false.
59  */
61  /**
62  * A different kind of large object that we might be spooling. Also
63  * reference-counted. Also only used when spool_eagerly is false.
64  */
66  const uint8_t *cce_body;
67  size_t cce_len;
68  /**
69  * The current offset into cached_dir or cce_body. Only used when
70  * spool_eagerly is false */
73 
75 
80 int directory_caches_dir_info(const or_options_t *options);
83  time_t now);
84 
85 MOCK_DECL(cached_dir_t *, dirserv_get_consensus, (const char *flavor_name));
86 void dirserv_set_cached_consensus_networkstatus(const char *consensus,
87  size_t consensus_len,
88  const char *flavor_name,
89  const common_digests_t *digests,
90  const uint8_t *sha3_as_signed,
91  time_t published);
92 void dirserv_clear_old_networkstatuses(time_t cutoff);
93 int dirserv_get_routerdesc_spool(smartlist_t *spools_out, const char *key,
94  dir_spool_source_t source,
95  int conn_is_encrypted,
96  const char **msg_out);
97 int dirserv_get_routerdescs(smartlist_t *descs_out, const char *key,
98  const char **msg);
99 
100 void dirserv_free_all(void);
102 cached_dir_t *new_cached_dir(char *s, time_t published);
103 
104 spooled_resource_t *spooled_resource_new(dir_spool_source_t source,
105  const uint8_t *digest,
106  size_t digestlen);
108  struct consensus_cache_entry_t *entry);
110 #define spooled_resource_free(sp) \
111  FREE_AND_NULL(spooled_resource_t, spooled_resource_free_, (sp))
113  time_t cutoff,
114  int compression,
115  size_t *size_out,
116  int *n_expired_out);
119 
120 #endif /* !defined(TOR_DIRSERV_H) */
dir_spool_source_bitfield_t spool_source
Definition: dirserv.h:51
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)
Definition: dirserv.c:276
void cached_dir_decref(cached_dir_t *d)
Definition: dirserv.c:186
int directory_too_idle_to_fetch_descriptors(const or_options_t *options, time_t now)
Definition: dirserv.c:169
int directory_fetches_dir_info_early(const or_options_t *options)
Definition: dirserv.c:105
int connection_dirserv_flushed_some(dir_connection_t *conn)
Definition: dirserv.c:854
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)
Definition: dirserv.c:236
void spooled_resource_free_(spooled_resource_t *spooled)
Definition: dirserv.c:478
int directory_fetches_from_authorities(const or_options_t *options)
Definition: dirserv.c:77
int directory_caches_unknown_auth_certs(const or_options_t *options)
Definition: dirserv.c:128
int directory_caches_dir_info(const or_options_t *options)
Definition: dirserv.c:143
cached_dir_t * new_cached_dir(char *s, time_t published)
Definition: dirserv.c:197
Definition: conscache.c:32
unsigned spool_eagerly
Definition: dirserv.h:47
int dirserv_get_routerdescs(smartlist_t *descs_out, const char *key, const char **msg)
Definition: dirserv.c:355
#define DIGEST256_LEN
Definition: digest_sizes.h:23
off_t cached_dir_offset
Definition: dirserv.h:71
uint8_t digest[DIGEST256_LEN]
Definition: dirserv.h:55
int directory_fetches_dir_info_later(const or_options_t *options)
Definition: dirserv.c:117
dir_spool_source_t
Definition: dirserv.h:20
struct cached_dir_t * cached_dir_ref
Definition: dirserv.h:60
int directory_permits_begindir_requests(const or_options_t *options)
Definition: dirserv.c:159
void dirserv_spool_sort(dir_connection_t *conn)
Definition: dirserv.c:809
void dirserv_free_all(void)
Definition: dirserv.c:911
Macros to implement mocking and selective exposure for the test code.
struct consensus_cache_entry_t * consensus_cache_entry
Definition: dirserv.h:65
#define MOCK_DECL(rv, funcname, arglist)
Definition: testsupport.h:127
spooled_resource_t * spooled_resource_new_from_cache_entry(struct consensus_cache_entry_t *entry)
Definition: dirserv.c:457
void dir_conn_clear_spool(dir_connection_t *conn)
Definition: dirserv.c:899
cached_dir_t * dirserv_get_consensus(const char *flavor_name)
Definition: dirserv.c:263
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)
Definition: dirserv.c:756