59 int conn_is_encrypted,
60 const uint8_t **body_out,
62 time_t *published_out);
65 time_t *published_out);
126 if (!d || --d->
refcnt > 0)
144 log_warn(
LD_BUG,
"Error compressing directory");
175 size_t networkstatus_len,
176 const char *flavor_name,
178 const uint8_t *sha3_as_signed,
187 new_cached_dir(tor_memdup_nulterm(networkstatus, networkstatus_len),
194 if (old_networkstatus)
221 const size_t digest_len =
225 compressed_out, flags);
229 spooled_resource_new(source, digest, digest_len);
233 } SMARTLIST_FOREACH_END(digest);
235 smartlist_free(fingerprints);
248 int conn_is_encrypted,
249 const char **msg_out)
253 if (!strcmp(key,
"all")) {
257 spooled = spooled_resource_new(source,
258 (
const uint8_t *)r->cache_info.identity_digest,
261 conn_is_encrypted = 0;
263 } SMARTLIST_FOREACH_END(r);
264 }
else if (!strcmp(key,
"authority")) {
268 spooled_resource_new(source,
274 DSR_HEX|DSR_SORT_UNIQ);
276 key += strlen(
"fp/");
278 DSR_HEX|DSR_SORT_UNIQ);
280 *msg_out =
"Not found";
284 if (! conn_is_encrypted) {
287 const uint8_t *body = NULL;
290 &body, &bodylen, NULL);
291 if (r < 0 || body == NULL || bodylen == 0) {
293 spooled_resource_free(spooled);
295 } SMARTLIST_FOREACH_END(spooled);
298 if (!smartlist_len(spool_out)) {
299 *msg_out =
"Servers unavailable";
311 const uint8_t *digest,
size_t digestlen)
316 case DIR_SPOOL_NETWORKSTATUS:
319 case DIR_SPOOL_SERVER_BY_DIGEST:
320 case DIR_SPOOL_SERVER_BY_FP:
321 case DIR_SPOOL_EXTRA_BY_DIGEST:
322 case DIR_SPOOL_EXTRA_BY_FP:
323 case DIR_SPOOL_MICRODESC:
327 case DIR_SPOOL_CONSENSUS_CACHE_ENTRY:
328 tor_assert_unreached();
333 memcpy(spooled->
digest, digest, digestlen);
348 spooled->
spool_source = DIR_SPOOL_CONSENSUS_CACHE_ENTRY;
359 spooled_resource_free(spooled);
384#define DIRSERV_CACHED_DIR_CHUNK_SIZE 8192
407 time_t *published_out)
410 const uint8_t *body = NULL;
416 if (r == -1 || body == NULL || bodylen == 0)
420 bodylen = (size_t)(bodylen * ratio);
431 return spooled->cce_len;
439 if (cached == NULL) {
465 const uint8_t *body = NULL;
469 &body, &bodylen, NULL);
470 if (r == -1 || body == NULL || bodylen == 0) {
481 if (cached == NULL && cce == NULL) {
493 if (BUG(!cached && !cce))
502 total_len = spooled->cce_len;
503 ptr = (
const char *)spooled->cce_body;
508 if (BUG(remaining < 0))
533 time_t *published_out)
552 int conn_is_encrypted,
553 const uint8_t **body_out,
555 time_t *published_out)
562 case DIR_SPOOL_EXTRA_BY_FP: {
566 case DIR_SPOOL_SERVER_BY_FP: {
570 case DIR_SPOOL_SERVER_BY_DIGEST: {
574 case DIR_SPOOL_EXTRA_BY_DIGEST: {
578 case DIR_SPOOL_MICRODESC: {
581 (
const char *)spooled->
digest);
582 if (! md || ! md->
body) {
585 *body_out = (
const uint8_t *)md->
body;
588 *published_out = TIME_MAX;
591 case DIR_SPOOL_NETWORKSTATUS:
592 case DIR_SPOOL_CONSENSUS_CACHE_ENTRY:
605 if (sd->send_unencrypted == 0 && ! conn_is_encrypted) {
664 time_t published = TIME_MAX;
666 compression, &published);
667 if (published < cutoff) {
670 spooled_resource_free(spooled);
671 }
else if (sz == 0) {
673 spooled_resource_free(spooled);
677 } SMARTLIST_FOREACH_END(spooled);
680 *size_out = (total > SIZE_MAX) ? SIZE_MAX : (
size_t)total;
683 *n_expired_out = n_expired;
699 if (conn->
spool == NULL)
723 return &ri->cache_info;
731#define DIRSERV_BUFFER_MIN 16384
745 if (conn->
spool == NULL)
749 smartlist_len(conn->
spool)) {
751 smartlist_get(conn->
spool, smartlist_len(conn->
spool)-1);
754 if (status == SRFS_ERR) {
756 }
else if (status == SRFS_MORE) {
763 spooled_resource_free(spooled);
766 if (smartlist_len(conn->
spool) > 0) {
772 smartlist_free(conn->
spool);
777 connection_buf_add_compress(
"", 0, conn, 1);
789 if (!conn || ! conn->
spool)
792 spooled_resource_free(s));
793 smartlist_free(conn->
spool);
Cached large directory object structure.
int tor_compress(char **out, size_t *out_len, const char *in, size_t in_len, compress_method_t method)
Header file for config.c.
void connection_dir_buf_add(const char *string, size_t len, dir_connection_t *dir_conn, int done)
Header file for connection.c.
void consensus_cache_entry_incref(consensus_cache_entry_t *ent)
void consensus_cache_entry_decref(consensus_cache_entry_t *ent)
int consensus_cache_entry_get_body(const consensus_cache_entry_t *ent, const uint8_t **body_out, size_t *sz_out)
int consensus_cache_entry_get_valid_after(const consensus_cache_entry_t *ent, time_t *out)
Header for consdiffmgr.c.
#define fast_memcmp(a, b, c)
Client/server directory connection structure.
int connection_dir_is_encrypted(const dir_connection_t *conn)
int dir_split_resource_into_fingerprints(const char *resource, smartlist_t *fp_out, int *compressed_out, int flags)
Header file for directory.c.
#define DIR_CONN_STATE_SERVER_WRITING
static int dirserv_spool_sort_comparison_(const void **a_, const void **b_)
void cached_dir_decref(cached_dir_t *d)
void dirserv_spool_sort(dir_connection_t *conn)
#define DIRSERV_CACHED_DIR_CHUNK_SIZE
static void clear_cached_dir(cached_dir_t *d)
static cached_dir_t * spooled_resource_lookup_cached_dir(const spooled_resource_t *spooled, time_t *published_out)
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)
static void free_cached_dir_(void *_d)
spooled_resource_flush_status_t
static spooled_resource_flush_status_t spooled_resource_flush_some(spooled_resource_t *spooled, dir_connection_t *conn)
int directory_caches_dir_info(const or_options_t *options)
int directory_caches_unknown_auth_certs(const or_options_t *options)
void spooled_resource_free_(spooled_resource_t *spooled)
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)
#define DIRSERV_BUFFER_MIN
int directory_permits_begindir_requests(const or_options_t *options)
static cached_dir_t * lookup_cached_dir_by_fp(const uint8_t *fp)
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 dir_conn_clear_spool(dir_connection_t *conn)
static double estimate_compression_ratio(dir_spool_source_t source)
cached_dir_t * dirserv_get_consensus(const char *flavor_name)
static int spooled_resource_lookup_body(const spooled_resource_t *spooled, int conn_is_encrypted, const uint8_t **body_out, size_t *size_out, time_t *published_out)
spooled_resource_t * spooled_resource_new_from_cache_entry(consensus_cache_entry_t *entry)
static size_t spooled_resource_estimate_size(const spooled_resource_t *spooled, dir_connection_t *conn, int compressed, time_t *published_out)
static strmap_t * cached_consensuses
void dirserv_free_all(void)
int connection_dirserv_flushed_some(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)
cached_dir_t * new_cached_dir(char *s, time_t published)
static const signed_descriptor_t * get_signed_descriptor_by_fp(const uint8_t *fp, int extrainfo)
Header file for dirserv.c.
microdesc_t * microdesc_cache_lookup_by_digest256(microdesc_cache_t *cache, const char *d)
microdesc_cache_t * get_microdesc_cache(void)
Header file for microdesc.c.
Microdescriptor structure.
Master header file for Tor-specific functionality.
Header file for predict_ports.c.
extrainfo_t * router_get_my_extrainfo(void)
int router_digest_is_me(const char *digest)
const routerinfo_t * router_get_my_routerinfo(void)
int router_my_exit_policy_is_reject_star(void)
int should_refuse_unknown_exits(const or_options_t *options)
Header file for router.c.
Router descriptor structure.
const char * signed_descriptor_get_body(const signed_descriptor_t *desc)
routerlist_t * router_get_routerlist(void)
signed_descriptor_t * router_get_by_descriptor_digest(const char *digest)
const routerinfo_t * router_get_by_id_digest(const char *digest)
signed_descriptor_t * extrainfo_get_by_descriptor_digest(const char *digest)
Header file for routerlist.c.
Router descriptor list structure.
int advertised_server_mode(void)
int dir_server_mode(const or_options_t *options)
int server_mode(const or_options_t *options)
Header file for routermode.c.
void smartlist_sort(smartlist_t *sl, int(*compare)(const void **a, const void **b))
void * smartlist_pop_last(smartlist_t *sl)
smartlist_t * smartlist_new(void)
void smartlist_add(smartlist_t *sl, void *element)
#define SMARTLIST_FOREACH_BEGIN(sl, type, var)
#define SMARTLIST_FOREACH(sl, type, var, cmd)
#define SMARTLIST_DEL_CURRENT(sl, var)
uint8_t digest_sha3_as_signed[DIGEST256_LEN]
size_t dir_compressed_len
struct tor_compress_state_t * compress_state
char extra_info_digest[DIGEST_LEN]
char identity_digest[DIGEST_LEN]
size_t signed_descriptor_len
dir_spool_source_bitfield_t spool_source
uint8_t digest[DIGEST256_LEN]
struct consensus_cache_entry_t * consensus_cache_entry
struct cached_dir_t * cached_dir_ref
#define MOCK_IMPL(rv, funcname, arglist)
#define tor_assert_nonfatal_unreached()
int strcmpstart(const char *s1, const char *s2)
int tor_digest_is_zero(const char *digest)