Tor  0.4.4.0-alpha-dev
microdesc.c
Go to the documentation of this file.
1 /* Copyright (c) 2009-2020, The Tor Project, Inc. */
2 /* See LICENSE for licensing information */
3 
4 /**
5  * \file microdesc.c
6  *
7  * \brief Implements microdescriptors -- an abbreviated description of
8  * less-frequently-changing router information.
9  */
10 
11 #include "core/or/or.h"
12 
13 #include "lib/fdio/fdio.h"
14 
15 #include "app/config/config.h"
16 #include "core/or/circuitbuild.h"
17 #include "core/or/policies.h"
30 #include "feature/relay/router.h"
31 
36 
37 #ifdef HAVE_FCNTL_H
38 #include <fcntl.h>
39 #endif
40 #ifdef HAVE_SYS_STAT_H
41 #include <sys/stat.h>
42 #endif
43 
44 /** A data structure to hold a bunch of cached microdescriptors. There are
45  * two active files in the cache: a "cache file" that we mmap, and a "journal
46  * file" that we append to. Periodically, we rebuild the cache file to hold
47  * only the microdescriptors that we want to keep */
49  /** Map from sha256-digest to microdesc_t for every microdesc_t in the
50  * cache. */
51  HT_HEAD(microdesc_map, microdesc_t) map;
52 
53  /** Name of the cache file. */
54  char *cache_fname;
55  /** Name of the journal file. */
56  char *journal_fname;
57  /** Mmap'd contents of the cache file, or NULL if there is none. */
58  tor_mmap_t *cache_content;
59  /** Number of bytes used in the journal file. */
60  size_t journal_len;
61  /** Number of bytes in descriptors removed as too old. */
62  size_t bytes_dropped;
63 
64  /** Total bytes of microdescriptor bodies we have added to this cache */
65  uint64_t total_len_seen;
66  /** Total number of microdescriptors we have added to this cache */
67  unsigned n_seen;
68 
69  /** True iff we have loaded this cache from disk ever. */
70  int is_loaded;
71 };
72 
74 static void warn_if_nul_found(const char *inp, size_t len, int64_t offset,
75  const char *activity);
76 
77 /** Helper: computes a hash of <b>md</b> to place it in a hash table. */
78 static inline unsigned int
80 {
81  return (unsigned) siphash24g(md->digest, sizeof(md->digest));
82 }
83 
84 /** Helper: compares <b>a</b> and <b>b</b> for equality for hash-table
85  * purposes. */
86 static inline int
88 {
89  return tor_memeq(a->digest, b->digest, DIGEST256_LEN);
90 }
91 
92 HT_PROTOTYPE(microdesc_map, microdesc_t, node,
94 HT_GENERATE2(microdesc_map, microdesc_t, node,
97 
98 /************************* md fetch fail cache *****************************/
99 
100 /* If we end up with too many outdated dirservers, something probably went
101  * wrong so clean up the list. */
102 #define TOO_MANY_OUTDATED_DIRSERVERS 30
103 
104 /** List of dirservers with outdated microdesc information. The smartlist is
105  * filled with the hex digests of outdated dirservers. */
107 
108 /** Note that we failed to fetch a microdescriptor from the relay with
109  * <b>relay_digest</b> (of size DIGEST_LEN). */
110 void
111 microdesc_note_outdated_dirserver(const char *relay_digest)
112 {
113  char relay_hexdigest[HEX_DIGEST_LEN+1];
114 
115  /* If we have a reasonably live consensus, then most of our dirservers should
116  * still be caching all the microdescriptors in it. Reasonably live
117  * consensuses are up to a day old (or a day in the future). But
118  * microdescriptors expire 7 days after the last consensus that referenced
119  * them. */
121  FLAV_MICRODESC)) {
122  return;
123  }
124 
127  }
128 
130 
131  /* If the list grows too big, clean it up */
132  if (BUG(smartlist_len(outdated_dirserver_list) >
133  TOO_MANY_OUTDATED_DIRSERVERS)) {
135  }
136 
137  /* Turn the binary relay digest to a hex since smartlists have better support
138  * for strings than digests. */
139  base16_encode(relay_hexdigest,sizeof(relay_hexdigest),
140  relay_digest, DIGEST_LEN);
141 
142  /* Make sure we don't add a dirauth as an outdated dirserver */
143  if (router_get_trusteddirserver_by_digest(relay_digest)) {
144  log_info(LD_GENERAL, "Auth %s gave us outdated dirinfo.", relay_hexdigest);
145  return;
146  }
147 
148  /* Don't double-add outdated dirservers */
149  if (smartlist_contains_string(outdated_dirserver_list, relay_hexdigest)) {
150  return;
151  }
152 
153  /* Add it to the list of outdated dirservers */
155 
156  log_info(LD_GENERAL, "Noted %s as outdated md dirserver", relay_hexdigest);
157 }
158 
159 /** Return True if the relay with <b>relay_digest</b> (size DIGEST_LEN) is an
160  * outdated dirserver */
161 int
162 microdesc_relay_is_outdated_dirserver(const char *relay_digest)
163 {
164  char relay_hexdigest[HEX_DIGEST_LEN+1];
165 
167  return 0;
168  }
169 
170  /* Convert identity digest to hex digest */
171  base16_encode(relay_hexdigest, sizeof(relay_hexdigest),
172  relay_digest, DIGEST_LEN);
173 
174  /* Last time we tried to fetch microdescs, was this directory mirror missing
175  * any mds we asked for? */
176  if (smartlist_contains_string(outdated_dirserver_list, relay_hexdigest)) {
177  return 1;
178  }
179 
180  return 0;
181 }
182 
183 /** Reset the list of outdated dirservers. */
184 void
186 {
188  return;
189  }
190 
193 }
194 
195 /****************************************************************************/
196 
197 /** Write the body of <b>md</b> into <b>f</b>, with appropriate annotations.
198  * On success, return the total number of bytes written, and set
199  * *<b>annotation_len_out</b> to the number of bytes written as
200  * annotations. */
201 static ssize_t
202 dump_microdescriptor(int fd, microdesc_t *md, size_t *annotation_len_out)
203 {
204  ssize_t r = 0;
205  ssize_t written;
206  if (md->body == NULL) {
207  *annotation_len_out = 0;
208  return 0;
209  }
210  /* XXXX drops unknown annotations. */
211  if (md->last_listed) {
212  char buf[ISO_TIME_LEN+1];
213  char annotation[ISO_TIME_LEN+32];
214  format_iso_time(buf, md->last_listed);
215  tor_snprintf(annotation, sizeof(annotation), "@last-listed %s\n", buf);
216  if (write_all_to_fd(fd, annotation, strlen(annotation)) < 0) {
217  log_warn(LD_DIR,
218  "Couldn't write microdescriptor annotation: %s",
219  strerror(errno));
220  return -1;
221  }
222  r += strlen(annotation);
223  *annotation_len_out = r;
224  } else {
225  *annotation_len_out = 0;
226  }
227 
228  md->off = tor_fd_getpos(fd);
229  warn_if_nul_found(md->body, md->bodylen, (int64_t) md->off,
230  "dumping a microdescriptor");
231  written = write_all_to_fd(fd, md->body, md->bodylen);
232  if (written != (ssize_t)md->bodylen) {
233  written = written < 0 ? 0 : written;
234  log_warn(LD_DIR,
235  "Couldn't dump microdescriptor (wrote %ld out of %lu): %s",
236  (long)written, (unsigned long)md->bodylen,
237  strerror(errno));
238  return -1;
239  }
240  r += md->bodylen;
241  return r;
242 }
243 
244 /** Holds a pointer to the current microdesc_cache_t object, or NULL if no
245  * such object has been allocated. */
247 
248 /** Return a pointer to the microdescriptor cache, loading it if necessary. */
251 {
253  if (PREDICT_UNLIKELY(cache->is_loaded == 0)) {
254  microdesc_cache_reload(cache);
255  }
256  return cache;
257 }
258 
259 /** Return a pointer to the microdescriptor cache, creating (but not loading)
260  * it if necessary. */
261 static microdesc_cache_t *
263 {
264  if (PREDICT_UNLIKELY(the_microdesc_cache==NULL)) {
265  microdesc_cache_t *cache = tor_malloc_zero(sizeof(*cache));
266  HT_INIT(microdesc_map, &cache->map);
267  cache->cache_fname = get_cachedir_fname("cached-microdescs");
268  cache->journal_fname = get_cachedir_fname("cached-microdescs.new");
269  the_microdesc_cache = cache;
270  }
271  return the_microdesc_cache;
272 }
273 
274 /* There are three sources of microdescriptors:
275  1) Generated by us while acting as a directory authority.
276  2) Loaded from the cache on disk.
277  3) Downloaded.
278 */
279 
280 /** Decode the microdescriptors from the string starting at <b>s</b> and
281  * ending at <b>eos</b>, and store them in <b>cache</b>. If <b>no_save</b>,
282  * mark them as non-writable to disk. If <b>where</b> is SAVED_IN_CACHE,
283  * leave their bodies as pointers to the mmap'd cache. If where is
284  * <b>SAVED_NOWHERE</b>, do not allow annotations. If listed_at is not -1,
285  * set the last_listed field of every microdesc to listed_at. If
286  * requested_digests is non-null, then it contains a list of digests we mean
287  * to allow, so we should reject any non-requested microdesc with a different
288  * digest, and alter the list to contain only the digests of those microdescs
289  * we didn't find.
290  * Return a newly allocated list of the added microdescriptors, or NULL */
291 smartlist_t *
293  const char *s, const char *eos, saved_location_t where,
294  int no_save, time_t listed_at,
295  smartlist_t *requested_digests256)
296 {
297  void * const DIGEST_REQUESTED = (void*)1;
298  void * const DIGEST_RECEIVED = (void*)2;
299  void * const DIGEST_INVALID = (void*)3;
300 
301  smartlist_t *descriptors, *added;
302  const int allow_annotations = (where != SAVED_NOWHERE);
303  smartlist_t *invalid_digests = smartlist_new();
304 
305  descriptors = microdescs_parse_from_string(s, eos,
306  allow_annotations,
307  where, invalid_digests);
308  if (listed_at != (time_t)-1) {
309  SMARTLIST_FOREACH(descriptors, microdesc_t *, md,
310  md->last_listed = listed_at);
311  }
312  if (requested_digests256) {
313  digest256map_t *requested;
314  requested = digest256map_new();
315  /* Set requested[d] to DIGEST_REQUESTED for every md we requested. */
316  SMARTLIST_FOREACH(requested_digests256, const uint8_t *, cp,
317  digest256map_set(requested, cp, DIGEST_REQUESTED));
318  /* Set requested[d] to DIGEST_INVALID for every md we requested which we
319  * will never be able to parse. Remove the ones we didn't request from
320  * invalid_digests.
321  */
322  SMARTLIST_FOREACH_BEGIN(invalid_digests, uint8_t *, cp) {
323  if (digest256map_get(requested, cp)) {
324  digest256map_set(requested, cp, DIGEST_INVALID);
325  } else {
326  tor_free(cp);
327  SMARTLIST_DEL_CURRENT(invalid_digests, cp);
328  }
329  } SMARTLIST_FOREACH_END(cp);
330  /* Update requested[d] to 2 for the mds we asked for and got. Delete the
331  * ones we never requested from the 'descriptors' smartlist.
332  */
333  SMARTLIST_FOREACH_BEGIN(descriptors, microdesc_t *, md) {
334  if (digest256map_get(requested, (const uint8_t*)md->digest)) {
335  digest256map_set(requested, (const uint8_t*)md->digest,
336  DIGEST_RECEIVED);
337  } else {
338  log_fn(LOG_PROTOCOL_WARN, LD_DIR, "Received non-requested microdesc");
339  microdesc_free(md);
340  SMARTLIST_DEL_CURRENT(descriptors, md);
341  }
342  } SMARTLIST_FOREACH_END(md);
343  /* Remove the ones we got or the invalid ones from requested_digests256.
344  */
345  SMARTLIST_FOREACH_BEGIN(requested_digests256, uint8_t *, cp) {
346  void *status = digest256map_get(requested, cp);
347  if (status == DIGEST_RECEIVED || status == DIGEST_INVALID) {
348  tor_free(cp);
349  SMARTLIST_DEL_CURRENT(requested_digests256, cp);
350  }
351  } SMARTLIST_FOREACH_END(cp);
352  digest256map_free(requested, NULL);
353  }
354 
355  /* For every requested microdescriptor that was unparseable, mark it
356  * as not to be retried. */
357  if (smartlist_len(invalid_digests)) {
358  networkstatus_t *ns =
360  if (ns) {
361  SMARTLIST_FOREACH_BEGIN(invalid_digests, char *, d) {
362  routerstatus_t *rs =
364  if (rs && tor_memeq(d, rs->descriptor_digest, DIGEST256_LEN)) {
365  download_status_mark_impossible(&rs->dl_status);
366  }
367  } SMARTLIST_FOREACH_END(d);
368  }
369  }
370  SMARTLIST_FOREACH(invalid_digests, uint8_t *, d, tor_free(d));
371  smartlist_free(invalid_digests);
372 
373  added = microdescs_add_list_to_cache(cache, descriptors, where, no_save);
374  smartlist_free(descriptors);
375  return added;
376 }
377 
378 /** As microdescs_add_to_cache, but takes a list of microdescriptors instead of
379  * a string to decode. Frees any members of <b>descriptors</b> that it does
380  * not add. */
381 smartlist_t *
383  smartlist_t *descriptors, saved_location_t where,
384  int no_save)
385 {
386  smartlist_t *added;
387  open_file_t *open_file = NULL;
388  int fd = -1;
389  // int n_added = 0;
390  ssize_t size = 0;
391 
392  if (where == SAVED_NOWHERE && !no_save) {
393  fd = start_writing_to_file(cache->journal_fname,
394  OPEN_FLAGS_APPEND|O_BINARY,
395  0600, &open_file);
396  if (fd < 0) {
397  log_warn(LD_DIR, "Couldn't append to journal in %s: %s",
398  cache->journal_fname, strerror(errno));
399  }
400  }
401 
402  added = smartlist_new();
403  SMARTLIST_FOREACH_BEGIN(descriptors, microdesc_t *, md) {
404  microdesc_t *md2;
405  md2 = HT_FIND(microdesc_map, &cache->map, md);
406  if (md2) {
407  /* We already had this one. */
408  if (md2->last_listed < md->last_listed)
409  md2->last_listed = md->last_listed;
410  microdesc_free(md);
411  if (where != SAVED_NOWHERE)
412  cache->bytes_dropped += size;
413  continue;
414  }
415 
416  /* Okay, it's a new one. */
417  if (fd >= 0) {
418  size_t annotation_len;
419  size = dump_microdescriptor(fd, md, &annotation_len);
420  if (size < 0) {
421  /* we already warned in dump_microdescriptor */
422  abort_writing_to_file(open_file);
423  fd = -1;
424  } else {
425  md->saved_location = SAVED_IN_JOURNAL;
426  cache->journal_len += size;
427  }
428  } else {
429  md->saved_location = where;
430  }
431 
432  md->no_save = no_save;
433 
434  HT_INSERT(microdesc_map, &cache->map, md);
435  md->held_in_map = 1;
436  smartlist_add(added, md);
437  ++cache->n_seen;
438  cache->total_len_seen += md->bodylen;
439  } SMARTLIST_FOREACH_END(md);
440 
441  if (fd >= 0) {
442  if (finish_writing_to_file(open_file) < 0) {
443  log_warn(LD_DIR, "Error appending to microdescriptor file: %s",
444  strerror(errno));
445  smartlist_clear(added);
446  return added;
447  }
448  }
449 
450  {
452  if (ns && ns->flavor == FLAV_MICRODESC)
454  }
455 
456  if (smartlist_len(added))
458 
459  return added;
460 }
461 
462 /** Remove every microdescriptor in <b>cache</b>. */
463 void
465 {
466  microdesc_t **entry, **next;
467 
468  for (entry = HT_START(microdesc_map, &cache->map); entry; entry = next) {
469  microdesc_t *md = *entry;
470  next = HT_NEXT_RMV(microdesc_map, &cache->map, entry);
471  md->held_in_map = 0;
472  microdesc_free(md);
473  }
474  HT_CLEAR(microdesc_map, &cache->map);
475  if (cache->cache_content) {
476  int res = tor_munmap_file(cache->cache_content);
477  if (res != 0) {
478  log_warn(LD_FS,
479  "tor_munmap_file() failed clearing microdesc cache; "
480  "we are probably about to leak memory.");
481  /* TODO something smarter? */
482  }
483  cache->cache_content = NULL;
484  }
485  cache->total_len_seen = 0;
486  cache->n_seen = 0;
487  cache->bytes_dropped = 0;
488 }
489 
490 static void
491 warn_if_nul_found(const char *inp, size_t len, int64_t offset,
492  const char *activity)
493 {
494  const char *nul_found = memchr(inp, 0, len);
495  if (BUG(nul_found)) {
496  log_warn(LD_BUG, "Found unexpected NUL while %s, offset %"PRId64
497  "at position %"TOR_PRIuSZ"/%"TOR_PRIuSZ".",
498  activity, offset, (nul_found - inp), len);
499  const char *start_excerpt_at, *eos = inp + len;
500  if ((nul_found - inp) >= 16)
501  start_excerpt_at = nul_found - 16;
502  else
503  start_excerpt_at = inp;
504  size_t excerpt_len = MIN(32, eos - start_excerpt_at);
505  char tmp[65];
506  base16_encode(tmp, sizeof(tmp), start_excerpt_at, excerpt_len);
507  log_warn(LD_BUG, " surrounding string: %s", tmp);
508  }
509 }
510 
511 /** Reload the contents of <b>cache</b> from disk. If it is empty, load it
512  * for the first time. Return 0 on success, -1 on failure. */
513 int
515 {
516  struct stat st;
517  char *journal_content;
518  smartlist_t *added;
519  tor_mmap_t *mm;
520  int total = 0;
521 
522  microdesc_cache_clear(cache);
523 
524  cache->is_loaded = 1;
525 
526  mm = cache->cache_content = tor_mmap_file(cache->cache_fname);
527  if (mm) {
528  warn_if_nul_found(mm->data, mm->size, 0, "scanning microdesc cache");
529  added = microdescs_add_to_cache(cache, mm->data, mm->data+mm->size,
530  SAVED_IN_CACHE, 0, -1, NULL);
531  if (added) {
532  total += smartlist_len(added);
533  smartlist_free(added);
534  }
535  }
536 
537  journal_content = read_file_to_str(cache->journal_fname,
538  RFTS_IGNORE_MISSING, &st);
539  if (journal_content) {
540  cache->journal_len = strlen(journal_content);
541  warn_if_nul_found(journal_content, (size_t)st.st_size, 0,
542  "reading microdesc journal");
543  added = microdescs_add_to_cache(cache, journal_content,
544  journal_content+st.st_size,
545  SAVED_IN_JOURNAL, 0, -1, NULL);
546  if (added) {
547  total += smartlist_len(added);
548  smartlist_free(added);
549  }
550  tor_free(journal_content);
551  }
552  log_info(LD_DIR, "Reloaded microdescriptor cache. Found %d descriptors.",
553  total);
554 
555  microdesc_cache_rebuild(cache, 0 /* don't force */);
556 
557  return 0;
558 }
559 
560 /** By default, we remove any microdescriptors that have gone at least this
561  * long without appearing in a current consensus. */
562 #define TOLERATE_MICRODESC_AGE (7*24*60*60)
563 
564 /** Remove all microdescriptors from <b>cache</b> that haven't been listed for
565  * a long time. Does not rebuild the cache on disk. If <b>cutoff</b> is
566  * positive, specifically remove microdescriptors that have been unlisted
567  * since <b>cutoff</b>. If <b>force</b> is true, remove microdescriptors even
568  * if we have no current live microdescriptor consensus.
569  */
570 void
571 microdesc_cache_clean(microdesc_cache_t *cache, time_t cutoff, int force)
572 {
573  microdesc_t **mdp, *victim;
574  int dropped=0, kept=0;
575  size_t bytes_dropped = 0;
576  time_t now = time(NULL);
577 
578  /* If we don't know a reasonably live consensus, don't believe last_listed
579  * values: we might be starting up after being down for a while. */
580  if (! force &&
581  ! networkstatus_get_reasonably_live_consensus(now, FLAV_MICRODESC))
582  return;
583 
584  if (cutoff <= 0)
585  cutoff = now - TOLERATE_MICRODESC_AGE;
586 
587  for (mdp = HT_START(microdesc_map, &cache->map); mdp != NULL; ) {
588  const int is_old = (*mdp)->last_listed < cutoff;
589  const unsigned held_by_nodes = (*mdp)->held_by_nodes;
590  if (is_old && !held_by_nodes) {
591  ++dropped;
592  victim = *mdp;
593  mdp = HT_NEXT_RMV(microdesc_map, &cache->map, mdp);
594  victim->held_in_map = 0;
595  bytes_dropped += victim->bodylen;
596  microdesc_free(victim);
597  } else {
598  if (is_old) {
599  /* It's old, but it has held_by_nodes set. That's not okay. */
600  /* Let's try to diagnose and fix #7164 . */
603  long networkstatus_age = -1;
604  const int ht_badness = HT_REP_IS_BAD_(microdesc_map, &cache->map);
605  if (ns) {
606  networkstatus_age = now - ns->valid_after;
607  }
608  log_warn(LD_BUG, "Microdescriptor seemed very old "
609  "(last listed %d hours ago vs %d hour cutoff), but is still "
610  "marked as being held by %d node(s). I found %d node(s) "
611  "holding it. Current networkstatus is %ld hours old. "
612  "Hashtable badness is %d.",
613  (int)((now - (*mdp)->last_listed) / 3600),
614  (int)((now - cutoff) / 3600),
615  held_by_nodes,
616  smartlist_len(nodes),
617  networkstatus_age / 3600,
618  ht_badness);
619 
620  SMARTLIST_FOREACH_BEGIN(nodes, const node_t *, node) {
621  const char *rs_match = "No RS";
622  const char *rs_present = "";
623  if (node->rs) {
624  if (tor_memeq(node->rs->descriptor_digest,
625  (*mdp)->digest, DIGEST256_LEN)) {
626  rs_match = "Microdesc digest in RS matches";
627  } else {
628  rs_match = "Microdesc digest in RS does match";
629  }
630  if (ns) {
631  /* This should be impossible, but let's see! */
632  rs_present = " RS not present in networkstatus.";
634  if (rs == node->rs) {
635  rs_present = " RS okay in networkstatus.";
636  }
637  });
638  }
639  }
640  log_warn(LD_BUG, " [%d]: ID=%s. md=%p, rs=%p, ri=%p. %s.%s",
641  node_sl_idx,
642  hex_str(node->identity, DIGEST_LEN),
643  node->md, node->rs, node->ri, rs_match, rs_present);
644  } SMARTLIST_FOREACH_END(node);
645  smartlist_free(nodes);
646  (*mdp)->last_listed = now;
647  }
648 
649  ++kept;
650  mdp = HT_NEXT(microdesc_map, &cache->map, mdp);
651  }
652  }
653 
654  if (dropped) {
655  log_info(LD_DIR, "Removed %d/%d microdescriptors as old.",
656  dropped,dropped+kept);
657  cache->bytes_dropped += bytes_dropped;
658  }
659 }
660 
661 static int
662 should_rebuild_md_cache(microdesc_cache_t *cache)
663 {
664  const size_t old_len =
665  cache->cache_content ? cache->cache_content->size : 0;
666  const size_t journal_len = cache->journal_len;
667  const size_t dropped = cache->bytes_dropped;
668 
669  if (journal_len < 16384)
670  return 0; /* Don't bother, not enough has happened yet. */
671  if (dropped > (journal_len + old_len) / 3)
672  return 1; /* We could save 1/3 or more of the currently used space. */
673  if (journal_len > old_len / 2)
674  return 1; /* We should append to the regular file */
675 
676  return 0;
677 }
678 
679 /**
680  * Mark <b>md</b> as having no body, and release any storage previously held
681  * by its body.
682  */
683 static void
685 {
686  if (!md)
687  return;
688 
689  if (md->saved_location != SAVED_IN_CACHE)
690  tor_free(md->body);
691 
692  md->off = 0;
694  md->body = NULL;
695  md->bodylen = 0;
696  md->no_save = 1;
697 }
698 
699 /** Regenerate the main cache file for <b>cache</b>, clear the journal file,
700  * and update every microdesc_t in the cache with pointers to its new
701  * location. If <b>force</b> is true, do this unconditionally. If
702  * <b>force</b> is false, do it only if we expect to save space on disk. */
703 int
705 {
706  open_file_t *open_file;
707  int fd = -1, res;
708  microdesc_t **mdp;
709  smartlist_t *wrote;
710  ssize_t size;
711  off_t off = 0, off_real;
712  int orig_size, new_size;
713 
714  if (cache == NULL) {
715  cache = the_microdesc_cache;
716  if (cache == NULL)
717  return 0;
718  }
719 
720  /* Remove dead descriptors */
721  microdesc_cache_clean(cache, 0/*cutoff*/, 0/*force*/);
722 
723  if (!force && !should_rebuild_md_cache(cache))
724  return 0;
725 
726  log_info(LD_DIR, "Rebuilding the microdescriptor cache...");
727 
728  orig_size = (int)(cache->cache_content ? cache->cache_content->size : 0);
729  orig_size += (int)cache->journal_len;
730 
731  fd = start_writing_to_file(cache->cache_fname,
732  OPEN_FLAGS_REPLACE|O_BINARY,
733  0600, &open_file);
734  if (fd < 0)
735  return -1;
736 
737  wrote = smartlist_new();
738 
739  HT_FOREACH(mdp, microdesc_map, &cache->map) {
740  microdesc_t *md = *mdp;
741  size_t annotation_len;
742  if (md->no_save || !md->body)
743  continue;
744 
745  size = dump_microdescriptor(fd, md, &annotation_len);
746  if (size < 0) {
748 
749  /* rewind, in case it was a partial write. */
750  tor_fd_setpos(fd, off);
751  continue;
752  }
753  tor_assert(((size_t)size) == annotation_len + md->bodylen);
754  md->off = off + annotation_len;
755  off += size;
756  off_real = tor_fd_getpos(fd);
757  if (off_real != off) {
758  log_warn(LD_BUG, "Discontinuity in position in microdescriptor cache."
759  "By my count, I'm at %"PRId64
760  ", but I should be at %"PRId64,
761  (int64_t)(off), (int64_t)(off_real));
762  if (off_real >= 0)
763  off = off_real;
764  }
765  if (md->saved_location != SAVED_IN_CACHE) {
766  tor_free(md->body);
768  }
769  smartlist_add(wrote, md);
770  }
771 
772  /* We must do this unmap _before_ we call finish_writing_to_file(), or
773  * windows will not actually replace the file. */
774  if (cache->cache_content) {
775  res = tor_munmap_file(cache->cache_content);
776  if (res != 0) {
777  log_warn(LD_FS,
778  "Failed to unmap old microdescriptor cache while rebuilding");
779  }
780  cache->cache_content = NULL;
781  }
782 
783  if (finish_writing_to_file(open_file) < 0) {
784  log_warn(LD_DIR, "Error rebuilding microdescriptor cache: %s",
785  strerror(errno));
786  /* Okay. Let's prevent from making things worse elsewhere. */
787  cache->cache_content = NULL;
788  HT_FOREACH(mdp, microdesc_map, &cache->map) {
789  microdesc_t *md = *mdp;
790  if (md->saved_location == SAVED_IN_CACHE) {
792  }
793  }
794  smartlist_free(wrote);
795  return -1;
796  }
797 
798  cache->cache_content = tor_mmap_file(cache->cache_fname);
799 
800  if (!cache->cache_content && smartlist_len(wrote)) {
801  log_err(LD_DIR, "Couldn't map file that we just wrote to %s!",
802  cache->cache_fname);
803  smartlist_free(wrote);
804  return -1;
805  }
806  SMARTLIST_FOREACH_BEGIN(wrote, microdesc_t *, md) {
807  tor_assert(md->saved_location == SAVED_IN_CACHE);
808  md->body = (char*)cache->cache_content->data + md->off;
809  if (PREDICT_UNLIKELY(
810  md->bodylen < 9 || fast_memneq(md->body, "onion-key", 9) != 0)) {
811  /* XXXX once bug 2022 is solved, we can kill this block and turn it
812  * into just the tor_assert(fast_memeq) */
813  off_t avail = cache->cache_content->size - md->off;
814  char *bad_str;
815  tor_assert(avail >= 0);
816  bad_str = tor_strndup(md->body, MIN(128, (size_t)avail));
817  log_err(LD_BUG, "After rebuilding microdesc cache, offsets seem wrong. "
818  " At offset %d, I expected to find a microdescriptor starting "
819  " with \"onion-key\". Instead I got %s.",
820  (int)md->off, escaped(bad_str));
821  tor_free(bad_str);
822  tor_assert(fast_memeq(md->body, "onion-key", 9));
823  }
824  } SMARTLIST_FOREACH_END(md);
825 
826  smartlist_free(wrote);
827 
828  write_str_to_file(cache->journal_fname, "", 1);
829  cache->journal_len = 0;
830  cache->bytes_dropped = 0;
831 
832  new_size = cache->cache_content ? (int)cache->cache_content->size : 0;
833  log_info(LD_DIR, "Done rebuilding microdesc cache. "
834  "Saved %d bytes; %d still used.",
835  orig_size-new_size, new_size);
836 
837  return 0;
838 }
839 
840 /** Make sure that the reference count of every microdescriptor in cache is
841  * accurate. */
842 void
844 {
845  microdesc_t **mdp;
846  if (!the_microdesc_cache)
847  return;
848 
849  HT_FOREACH(mdp, microdesc_map, &the_microdesc_cache->map) {
850  microdesc_t *md = *mdp;
851  unsigned int found=0;
852  const smartlist_t *nodes = nodelist_get_list();
853  SMARTLIST_FOREACH(nodes, node_t *, node, {
854  if (node->md == md) {
855  ++found;
856  }
857  });
858  tor_assert(found == md->held_by_nodes);
859  }
860 }
861 
862 /** Deallocate a single microdescriptor. Note: the microdescriptor MUST have
863  * previously been removed from the cache if it had ever been inserted. */
864 void
865 microdesc_free_(microdesc_t *md, const char *fname, int lineno)
866 {
867  if (!md)
868  return;
869 
870  /* Make sure that the microdesc was really removed from the appropriate data
871  structures. */
872  if (md->held_in_map) {
874  microdesc_t *md2 = HT_FIND(microdesc_map, &cache->map, md);
875  if (md2 == md) {
876  log_warn(LD_BUG, "microdesc_free() called from %s:%d, but md was still "
877  "in microdesc_map", fname, lineno);
878  HT_REMOVE(microdesc_map, &cache->map, md);
879  } else {
880  log_warn(LD_BUG, "microdesc_free() called from %s:%d with held_in_map "
881  "set, but microdesc was not in the map.", fname, lineno);
882  }
884  }
885  if (md->held_by_nodes) {
887  int found=0;
888  const smartlist_t *nodes = nodelist_get_list();
889  const int ht_badness = HT_REP_IS_BAD_(microdesc_map, &cache->map);
890  SMARTLIST_FOREACH(nodes, node_t *, node, {
891  if (node->md == md) {
892  ++found;
893  node->md = NULL;
894  }
895  });
896  if (found) {
897  log_warn(LD_BUG, "microdesc_free() called from %s:%d, but md was still "
898  "referenced %d node(s); held_by_nodes == %u, ht_badness == %d",
899  fname, lineno, found, md->held_by_nodes, ht_badness);
900  } else {
901  log_warn(LD_BUG, "microdesc_free() called from %s:%d with held_by_nodes "
902  "set to %u, but md was not referenced by any nodes. "
903  "ht_badness == %d",
904  fname, lineno, md->held_by_nodes, ht_badness);
905  }
907  }
908  //tor_assert(md->held_in_map == 0);
909  //tor_assert(md->held_by_nodes == 0);
910 
911  if (md->onion_pkey)
912  tor_free(md->onion_pkey);
915  if (md->body && md->saved_location != SAVED_IN_CACHE)
916  tor_free(md->body);
917 
918  nodefamily_free(md->family);
919  short_policy_free(md->exit_policy);
920  short_policy_free(md->ipv6_exit_policy);
921 
922  tor_free(md);
923 }
924 
925 /** Free all storage held in the microdesc.c module. */
926 void
928 {
929  if (the_microdesc_cache) {
931  tor_free(the_microdesc_cache->cache_fname);
932  tor_free(the_microdesc_cache->journal_fname);
934  }
935 
938  smartlist_free(outdated_dirserver_list);
939  }
940 }
941 
942 /** If there is a microdescriptor in <b>cache</b> whose sha256 digest is
943  * <b>d</b>, return it. Otherwise return NULL. */
944 microdesc_t *
946 {
947  microdesc_t *md, search;
948  if (!cache)
949  cache = get_microdesc_cache();
950  memcpy(search.digest, d, DIGEST256_LEN);
951  md = HT_FIND(microdesc_map, &cache->map, &search);
952  return md;
953 }
954 
955 /** Return a smartlist of all the sha256 digest of the microdescriptors that
956  * are listed in <b>ns</b> but not present in <b>cache</b>. Returns pointers
957  * to internals of <b>ns</b>; you should not free the members of the resulting
958  * smartlist. Omit all microdescriptors whose digest appear in <b>skip</b>. */
959 smartlist_t *
961  int downloadable_only, digest256map_t *skip)
962 {
963  smartlist_t *result = smartlist_new();
964  time_t now = time(NULL);
965  tor_assert(ns->flavor == FLAV_MICRODESC);
967  if (microdesc_cache_lookup_by_digest256(cache, rs->descriptor_digest))
968  continue;
969  if (downloadable_only &&
970  !download_status_is_ready(&rs->dl_status, now))
971  continue;
972  if (skip && digest256map_get(skip, (const uint8_t*)rs->descriptor_digest))
973  continue;
974  if (fast_mem_is_zero(rs->descriptor_digest, DIGEST256_LEN))
975  continue;
976  /* XXXX Also skip if we're a noncache and wouldn't use this router.
977  * XXXX NM Microdesc
978  */
979  smartlist_add(result, rs->descriptor_digest);
980  } SMARTLIST_FOREACH_END(rs);
981  return result;
982 }
983 
984 /** Launch download requests for microdescriptors as appropriate.
985  *
986  * Specifically, we should launch download requests if we are configured to
987  * download mirodescriptors, and there are some microdescriptors listed in the
988  * current microdesc consensus that we don't have, and either we never asked
989  * for them, or we failed to download them but we're willing to retry.
990  */
991 void
993 {
994  const or_options_t *options = get_options();
995  networkstatus_t *consensus;
996  smartlist_t *missing;
997  digest256map_t *pending;
998 
999  if (should_delay_dir_fetches(options, NULL))
1000  return;
1001  if (dirclient_too_idle_to_fetch_descriptors(options, now))
1002  return;
1003 
1004  /* Give up if we don't have a reasonably live consensus. */
1005  consensus = networkstatus_get_reasonably_live_consensus(now, FLAV_MICRODESC);
1006  if (!consensus)
1007  return;
1008 
1009  if (!we_fetch_microdescriptors(options))
1010  return;
1011 
1012  pending = digest256map_new();
1014 
1015  missing = microdesc_list_missing_digest256(consensus,
1017  1,
1018  pending);
1019  digest256map_free(pending, NULL);
1020 
1022  missing, NULL, now);
1023 
1024  smartlist_free(missing);
1025 }
1026 
1027 /** For every microdescriptor listed in the current microdescriptor consensus,
1028  * update its last_listed field to be at least as recent as the publication
1029  * time of the current microdescriptor consensus.
1030  */
1031 void
1033 {
1035  microdesc_t *md;
1036  networkstatus_t *ns =
1037  networkstatus_get_reasonably_live_consensus(now, FLAV_MICRODESC);
1038 
1039  if (! ns)
1040  return;
1041 
1042  tor_assert(ns->flavor == FLAV_MICRODESC);
1043 
1045  md = microdesc_cache_lookup_by_digest256(cache, rs->descriptor_digest);
1046  if (md && ns->valid_after > md->last_listed)
1047  md->last_listed = ns->valid_after;
1048  } SMARTLIST_FOREACH_END(rs);
1049 }
1050 
1051 /** Return true iff we should prefer to use microdescriptors rather than
1052  * routerdescs for building circuits. */
1053 int
1055 {
1056  if (options->UseMicrodescriptors == 0)
1057  return 0; /* the user explicitly picked no */
1058  return 1; /* yes and auto both mean yes */
1059 }
1060 
1061 /** Return true iff we should try to download microdescriptors at all. */
1062 int
1064 {
1065  if (directory_caches_dir_info(options))
1066  return 1;
1067  if (options->FetchUselessDescriptors)
1068  return 1;
1069  return we_use_microdescriptors_for_circuits(options);
1070 }
1071 
1072 /** Return true iff we should try to download router descriptors at all. */
1073 int
1075 {
1076  if (directory_caches_dir_info(options))
1077  return 1;
1078  if (options->FetchUselessDescriptors)
1079  return 1;
1080  return ! we_use_microdescriptors_for_circuits(options);
1081 }
1082 
1083 /** Return the consensus flavor we actually want to use to build circuits. */
1084 MOCK_IMPL(int,
1086 {
1088  return FLAV_MICRODESC;
1089  } else {
1090  return FLAV_NS;
1091  }
1092 }
log_fn
#define log_fn(severity, domain, args,...)
Definition: log.h:287
finish_writing_to_file
int finish_writing_to_file(open_file_t *file_data)
Definition: files.c:449
microdesc_t
Definition: microdesc_st.h:27
router_get_mutable_consensus_status_by_descriptor_digest
routerstatus_t * router_get_mutable_consensus_status_by_descriptor_digest(networkstatus_t *consensus, const char *digest)
Definition: networkstatus.c:748
tor_free
#define tor_free(p)
Definition: malloc.h:52
tor_free_
void tor_free_(void *mem)
Definition: malloc.c:227
hex_str
const char * hex_str(const char *from, size_t fromlen)
Definition: binascii.c:34
download_status_mark_impossible
void download_status_mark_impossible(download_status_t *dl)
Definition: dlstatus.c:393
microdesc_note_outdated_dirserver
void microdesc_note_outdated_dirserver(const char *relay_digest)
Definition: microdesc.c:111
microdesc_parse.h
Header file for microdesc_parse.c.
smartlist_add_strdup
void smartlist_add_strdup(struct smartlist_t *sl, const char *string)
Definition: smartlist_core.c:137
approx_time
time_t approx_time(void)
Definition: approx_time.c:32
MOCK_IMPL
#define MOCK_IMPL(rv, funcname, arglist)
Definition: testsupport.h:133
microdesc_eq_
static int microdesc_eq_(microdesc_t *a, microdesc_t *b)
Definition: microdesc.c:87
microdesc_wipe_body
static void microdesc_wipe_body(microdesc_t *md)
Definition: microdesc.c:684
microdesc_t::digest
char digest[DIGEST256_LEN]
Definition: microdesc_st.h:62
tor_assert
#define tor_assert(expr)
Definition: util_bug.h:102
microdesc.h
Header file for microdesc.c.
dump_microdescriptor
static ssize_t dump_microdescriptor(int fd, microdesc_t *md, size_t *annotation_len_out)
Definition: microdesc.c:202
LD_BUG
#define LD_BUG
Definition: log.h:86
router.h
Header file for router.c.
DIR_PURPOSE_FETCH_MICRODESC
#define DIR_PURPOSE_FETCH_MICRODESC
Definition: directory.h:70
format_iso_time
void format_iso_time(char *buf, time_t t)
Definition: time_fmt.c:295
fast_mem_is_zero
int fast_mem_is_zero(const char *mem, size_t len)
Definition: util_string.c:74
TOLERATE_MICRODESC_AGE
#define TOLERATE_MICRODESC_AGE
Definition: microdesc.c:562
LD_GENERAL
#define LD_GENERAL
Definition: log.h:62
base16_encode
void base16_encode(char *dest, size_t destlen, const char *src, size_t srclen)
Definition: binascii.c:478
tor_fragile_assert
#define tor_fragile_assert()
Definition: util_bug.h:259
tor_reallocarray_
void * tor_reallocarray_(void *ptr, size_t sz1, size_t sz2)
Definition: malloc.c:146
microdesc_cache_reload
int microdesc_cache_reload(microdesc_cache_t *cache)
Definition: microdesc.c:514
or_options_t::UseMicrodescriptors
int UseMicrodescriptors
Definition: or_options_st.h:819
smartlist_add
void smartlist_add(smartlist_t *sl, void *element)
Definition: smartlist_core.c:117
we_fetch_microdescriptors
int we_fetch_microdescriptors(const or_options_t *options)
Definition: microdesc.c:1063
routerstatus_t
Definition: routerstatus_st.h:19
tor_mmap_t::data
const char * data
Definition: mmap.h:26
smartlist_new
smartlist_t * smartlist_new(void)
Definition: smartlist_core.c:26
microdesc_t::off
off_t off
Definition: microdesc_st.h:50
tor_snprintf
int tor_snprintf(char *str, size_t size, const char *format,...)
Definition: printf.c:27
launch_descriptor_downloads
void launch_descriptor_downloads(int purpose, smartlist_t *downloadable, const routerstatus_t *source, time_t now)
Definition: routerlist.c:2432
open_file_t
Definition: files.c:273
microdesc_t::body
char * body
Definition: microdesc_st.h:58
update_microdescs_from_networkstatus
void update_microdescs_from_networkstatus(time_t now)
Definition: microdesc.c:1032
microdesc_check_counts
void microdesc_check_counts(void)
Definition: microdesc.c:843
SMARTLIST_FOREACH
#define SMARTLIST_FOREACH(sl, type, var, cmd)
Definition: smartlist_foreach.h:112
tor_mmap_t::size
size_t size
Definition: mmap.h:27
router_get_trusteddirserver_by_digest
dir_server_t * router_get_trusteddirserver_by_digest(const char *digest)
Definition: dirlist.c:144
microdesc_cache_clean
void microdesc_cache_clean(microdesc_cache_t *cache, time_t cutoff, int force)
Definition: microdesc.c:571
networkstatus.h
Header file for networkstatus.c.
nodelist_find_nodes_with_microdesc
smartlist_t * nodelist_find_nodes_with_microdesc(const microdesc_t *md)
Definition: nodelist.c:794
tor_memeq
int tor_memeq(const void *a, const void *b, size_t sz)
Definition: di_ops.c:107
dirlist.h
Header file for dirlist.c.
microdesc_t::last_listed
time_t last_listed
Definition: microdesc_st.h:36
microdesc_t::no_save
unsigned int no_save
Definition: microdesc_st.h:40
nodelist_add_microdesc
node_t * nodelist_add_microdesc(microdesc_t *md)
Definition: nodelist.c:570
write_str_to_file
int write_str_to_file(const char *fname, const char *str, int bin)
Definition: files.c:258
DIGEST_LEN
#define DIGEST_LEN
Definition: digest_sizes.h:20
microdesc_t::onion_pkey
char * onion_pkey
Definition: microdesc_st.h:70
microdescs_parse_from_string
smartlist_t * microdescs_parse_from_string(const char *s, const char *eos, int allow_annotations, saved_location_t where, smartlist_t *invalid_digests_out)
Definition: microdesc_parse.c:293
networkstatus_get_latest_consensus_by_flavor
networkstatus_t * networkstatus_get_latest_consensus_by_flavor(consensus_flavor_t f)
Definition: networkstatus.c:1401
LD_FS
#define LD_FS
Definition: log.h:70
microdesc_cache_clear
void microdesc_cache_clear(microdesc_cache_t *cache)
Definition: microdesc.c:464
entrynodes.h
Header file for circuitbuild.c.
microdesc_list_missing_digest256
smartlist_t * microdesc_list_missing_digest256(networkstatus_t *ns, microdesc_cache_t *cache, int downloadable_only, digest256map_t *skip)
Definition: microdesc.c:960
networkstatus_get_latest_consensus
networkstatus_t * networkstatus_get_latest_consensus(void)
Definition: networkstatus.c:1390
node_t
Definition: node_st.h:34
RFTS_IGNORE_MISSING
#define RFTS_IGNORE_MISSING
Definition: files.h:97
get_microdesc_cache_noload
static microdesc_cache_t * get_microdesc_cache_noload(void)
Definition: microdesc.c:262
microdesc_t::ed25519_identity_pkey
struct ed25519_public_key_t * ed25519_identity_pkey
Definition: microdesc_st.h:77
networkstatus_t::flavor
consensus_flavor_t flavor
Definition: networkstatus_st.h:28
microdesc_t::exit_policy
struct short_policy_t * exit_policy
Definition: microdesc_st.h:85
microdesc_cache_lookup_by_digest256
microdesc_t * microdesc_cache_lookup_by_digest256(microdesc_cache_t *cache, const char *d)
Definition: microdesc.c:945
directory.h
Header file for directory.c.
start_writing_to_file
int start_writing_to_file(const char *fname, int open_flags, int mode, open_file_t **data_out)
Definition: files.c:301
networkstatus_get_reasonably_live_consensus
networkstatus_t * networkstatus_get_reasonably_live_consensus(time_t now, int flavor)
Definition: networkstatus.c:1477
escaped
const char * escaped(const char *s)
Definition: escape.c:126
usable_consensus_flavor
int usable_consensus_flavor(void)
Definition: microdesc.c:1085
we_fetch_router_descriptors
int we_fetch_router_descriptors(const or_options_t *options)
Definition: microdesc.c:1074
SAVED_IN_JOURNAL
@ SAVED_IN_JOURNAL
Definition: or.h:760
microdesc_st.h
Microdescriptor structure.
tor_mmap_t
Definition: mmap.h:25
microdesc_cache_rebuild
int microdesc_cache_rebuild(microdesc_cache_t *cache, int force)
Definition: microdesc.c:704
nodelist.h
Header file for nodelist.c.
routerlist.h
Header file for routerlist.c.
microdesc_free_all
void microdesc_free_all(void)
Definition: microdesc.c:927
write_all_to_fd
ssize_t write_all_to_fd(int fd, const char *buf, size_t count)
Definition: files.c:162
microdesc_t::family
struct nodefamily_t * family
Definition: microdesc_st.h:83
smartlist_contains_string
int smartlist_contains_string(const smartlist_t *sl, const char *element)
Definition: smartlist.c:93
microdesc_relay_is_outdated_dirserver
int microdesc_relay_is_outdated_dirserver(const char *relay_digest)
Definition: microdesc.c:162
outdated_dirserver_list
static smartlist_t * outdated_dirserver_list
Definition: microdesc.c:106
DIGEST256_LEN
#define DIGEST256_LEN
Definition: digest_sizes.h:23
abort_writing_to_file
int abort_writing_to_file(open_file_t *file_data)
Definition: files.c:457
networkstatus_t::routerstatus_list
smartlist_t * routerstatus_list
Definition: networkstatus_st.h:96
saved_location_t
saved_location_t
Definition: or.h:746
HT_HEAD
typedef HT_HEAD(hs_service_ht, hs_service_t) hs_service_ht
nodefamily.h
Header file for nodefamily.c.
microdescs_add_to_cache
smartlist_t * microdescs_add_to_cache(microdesc_cache_t *cache, const char *s, const char *eos, saved_location_t where, int no_save, time_t listed_at, smartlist_t *requested_digests256)
Definition: microdesc.c:292
fast_memneq
#define fast_memneq(a, b, c)
Definition: di_ops.h:42
get_options
const or_options_t * get_options(void)
Definition: config.c:925
routerstatus_t::descriptor_digest
char descriptor_digest[DIGEST256_LEN]
Definition: routerstatus_st.h:31
microdesc_free_
void microdesc_free_(microdesc_t *md, const char *fname, int lineno)
Definition: microdesc.c:865
SAVED_IN_CACHE
@ SAVED_IN_CACHE
Definition: or.h:753
circuitbuild.h
Header file for circuitbuild.c.
smartlist_clear
void smartlist_clear(smartlist_t *sl)
Definition: smartlist_core.c:50
routerstatus_st.h
Routerstatus (consensus entry) structure.
microdesc_t::onion_curve25519_pkey
struct curve25519_public_key_t * onion_curve25519_pkey
Definition: microdesc_st.h:75
nodelist_get_list
const smartlist_t * nodelist_get_list(void)
Definition: nodelist.c:975
get_microdesc_cache
microdesc_cache_t * get_microdesc_cache(void)
Definition: microdesc.c:250
directory_caches_dir_info
int directory_caches_dir_info(const or_options_t *options)
Definition: dirserv.c:94
microdescs_add_list_to_cache
smartlist_t * microdescs_add_list_to_cache(microdesc_cache_t *cache, smartlist_t *descriptors, saved_location_t where, int no_save)
Definition: microdesc.c:382
networkstatus_t::valid_after
time_t valid_after
Definition: networkstatus_st.h:33
dirserv.h
Header file for dirserv.c.
microdesc_hash_
static unsigned int microdesc_hash_(microdesc_t *md)
Definition: microdesc.c:79
download_status_is_ready
int download_status_is_ready(download_status_t *dls, time_t now)
Definition: dlstatus.c:381
SMARTLIST_FOREACH_BEGIN
#define SMARTLIST_FOREACH_BEGIN(sl, type, var)
Definition: smartlist_foreach.h:78
dlstatus.h
Header file for dlstatus.c.
fdio.h
Header for fdio.c.
SMARTLIST_DEL_CURRENT
#define SMARTLIST_DEL_CURRENT(sl, var)
Definition: smartlist_foreach.h:120
update_microdesc_downloads
void update_microdesc_downloads(time_t now)
Definition: microdesc.c:992
list_pending_microdesc_downloads
void list_pending_microdesc_downloads(digest256map_t *result)
Definition: routerlist.c:2308
HEX_DIGEST_LEN
#define HEX_DIGEST_LEN
Definition: crypto_digest.h:35
microdesc_cache_t
Definition: microdesc.c:48
node_st.h
Node information structure.
or_options_t::FetchUselessDescriptors
int FetchUselessDescriptors
Definition: or_options_st.h:269
microdesc_t::held_in_map
unsigned int held_in_map
Definition: microdesc_st.h:42
microdesc_t::held_by_nodes
unsigned int held_by_nodes
Definition: microdesc_st.h:46
policies.h
Header file for policies.c.
HT_PROTOTYPE
HT_PROTOTYPE(hs_circuitmap_ht, circuit_t, hs_circuitmap_node, hs_circuit_hash_token, hs_circuits_have_same_token)
dirclient_too_idle_to_fetch_descriptors
int dirclient_too_idle_to_fetch_descriptors(const or_options_t *options, time_t now)
Definition: dirclient_modes.c:90
config.h
Header file for config.c.
tor_fd_setpos
int tor_fd_setpos(int fd, off_t pos)
Definition: fdio.c:80
microdesc_t::saved_location
saved_location_bitfield_t saved_location
Definition: microdesc_st.h:38
the_microdesc_cache
static microdesc_cache_t * the_microdesc_cache
Definition: microdesc.c:246
should_delay_dir_fetches
int should_delay_dir_fetches(const or_options_t *options, const char **msg_out)
Definition: networkstatus.c:1253
or_options_t
Definition: or_options_st.h:39
microdesc_t::ipv6_exit_policy
struct short_policy_t * ipv6_exit_policy
Definition: microdesc_st.h:87
microdesc_t::bodylen
size_t bodylen
Definition: microdesc_st.h:60
we_use_microdescriptors_for_circuits
int we_use_microdescriptors_for_circuits(const or_options_t *options)
Definition: microdesc.c:1054
LD_DIR
#define LD_DIR
Definition: log.h:88
networkstatus_st.h
Networkstatus consensus/vote structure.
dirclient_modes.h
Header for feature/dirclient/dirclient_modes.c.
networkstatus_t
Definition: networkstatus_st.h:26
SAVED_NOWHERE
@ SAVED_NOWHERE
Definition: or.h:749
router_dir_info_changed
void router_dir_info_changed(void)
Definition: nodelist.c:2367
smartlist_t
Definition: smartlist_core.h:26
fast_memeq
#define fast_memeq(a, b, c)
Definition: di_ops.h:35
or.h
Master header file for Tor-specific functionality.
microdesc_reset_outdated_dirservers_list
void microdesc_reset_outdated_dirservers_list(void)
Definition: microdesc.c:185
tor_fd_getpos
off_t tor_fd_getpos(int fd)
Definition: fdio.c:48