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-2021, The Tor Project, Inc. */
5 /* See LICENSE for licensing information */
9 * \brief Header file for dirserv.c.
15 struct ed25519_public_key_t
;
17 #include "lib/testsupport/testsupport.h"
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
,
24 DIR_SPOOL_NETWORKSTATUS
,
25 DIR_SPOOL_CONSENSUS_CACHE_ENTRY
,
27 #define dir_spool_source_bitfield_t ENUM_BF(dir_spool_source_t)
29 /** Object to remember the identity of an object that we are spooling,
30 * or about to spool, in response to a directory request.
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.)
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
42 typedef struct spooled_resource_t
{
44 * If true, we add the entire object to the outbuf. If false,
45 * we spool the object a few K at a time.
47 unsigned spool_eagerly
: 1;
49 * Tells us what kind of object to get, and how to look it up.
51 dir_spool_source_bitfield_t spool_source
: 7;
53 * Tells us the specific object to spool.
55 uint8_t digest
[DIGEST256_LEN
];
57 * A large object that we're spooling. Holds a reference count. Only
58 * used when spool_eagerly is false.
60 struct cached_dir_t
*cached_dir_ref
;
62 * A different kind of large object that we might be spooling. Also
63 * reference-counted. Also only used when spool_eagerly is false.
65 struct consensus_cache_entry_t
*consensus_cache_entry
;
66 const uint8_t *cce_body
;
69 * The current offset into cached_dir or cce_body. Only used when
70 * spool_eagerly is false */
71 off_t cached_dir_offset
;
74 int connection_dirserv_flushed_some(dir_connection_t
*conn
);
76 enum dir_spool_source_t
;
77 int dir_split_resource_into_spoolable(const char *resource
,
78 enum dir_spool_source_t source
,
79 smartlist_t
*spool_out
,
83 #ifdef HAVE_MODULE_DIRCACHE
84 /** Is the dircache module enabled? */
85 #define have_module_dircache() (1)
86 int directory_caches_unknown_auth_certs(const or_options_t
*options
);
87 int directory_caches_dir_info(const or_options_t
*options
);
88 int directory_permits_begindir_requests(const or_options_t
*options
);
89 MOCK_DECL(cached_dir_t
*, dirserv_get_consensus
, (const char *flavor_name
));
90 void dirserv_set_cached_consensus_networkstatus(const char *consensus
,
92 const char *flavor_name
,
93 const common_digests_t
*digests
,
94 const uint8_t *sha3_as_signed
,
96 #else /* !defined(HAVE_MODULE_DIRCACHE) */
97 #define have_module_dircache() (0)
98 #define directory_caches_unknown_auth_certs(opt) \
100 #define directory_caches_dir_info(opt) \
102 #define directory_permits_begindir_requests(opt) \
104 #define dirserv_get_consensus(flav) \
106 #define dirserv_set_cached_consensus_networkstatus(a,b,c,d,e,f) \
115 #endif /* defined(HAVE_MODULE_DIRCACHE) */
117 void dirserv_clear_old_networkstatuses(time_t cutoff
);
118 int dirserv_get_routerdesc_spool(smartlist_t
*spools_out
, const char *key
,
119 dir_spool_source_t source
,
120 int conn_is_encrypted
,
121 const char **msg_out
);
123 void dirserv_free_all(void);
124 void cached_dir_decref(cached_dir_t
*d
);
125 cached_dir_t
*new_cached_dir(char *s
, time_t published
);
127 spooled_resource_t
*spooled_resource_new(dir_spool_source_t source
,
128 const uint8_t *digest
,
130 spooled_resource_t
*spooled_resource_new_from_cache_entry(
131 struct consensus_cache_entry_t
*entry
);
132 void spooled_resource_free_(spooled_resource_t
*spooled
);
133 #define spooled_resource_free(sp) \
134 FREE_AND_NULL(spooled_resource_t, spooled_resource_free_, (sp))
135 void dirserv_spool_remove_missing_and_guess_size(dir_connection_t
*conn
,
140 void dirserv_spool_sort(dir_connection_t
*conn
);
141 void dir_conn_clear_spool(dir_connection_t
*conn
);
143 #endif /* !defined(TOR_DIRSERV_H) */