dirserv.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. * \file dirserv.h
  8. * \brief Header file for dirserv.c.
  9. **/
  10. #ifndef TOR_DIRSERV_H
  11. #define TOR_DIRSERV_H
  12. struct ed25519_public_key_t;
  13. #include "lib/testsupport/testsupport.h"
  14. /** Ways to convert a spoolable_resource_t to a bunch of bytes. */
  15. typedef enum dir_spool_source_t {
  16. DIR_SPOOL_SERVER_BY_DIGEST=1, DIR_SPOOL_SERVER_BY_FP,
  17. DIR_SPOOL_EXTRA_BY_DIGEST, DIR_SPOOL_EXTRA_BY_FP,
  18. DIR_SPOOL_MICRODESC,
  19. DIR_SPOOL_NETWORKSTATUS,
  20. DIR_SPOOL_CONSENSUS_CACHE_ENTRY,
  21. } dir_spool_source_t;
  22. #define dir_spool_source_bitfield_t ENUM_BF(dir_spool_source_t)
  23. /** Object to remember the identity of an object that we are spooling,
  24. * or about to spool, in response to a directory request.
  25. *
  26. * (Why do we spool? Because some directory responses are very large,
  27. * and we don't want to just shove the complete answer into the output
  28. * buffer: that would take a ridiculous amount of RAM.)
  29. *
  30. * If the spooled resource is relatively small (like microdescriptors,
  31. * descriptors, etc), we look them up by ID as needed, and add the whole
  32. * thing onto the output buffer at once. If the spooled reseource is
  33. * big (like networkstatus documents), we reference-count it, and add it
  34. * a few K at a time.
  35. */
  36. typedef struct spooled_resource_t {
  37. /**
  38. * If true, we add the entire object to the outbuf. If false,
  39. * we spool the object a few K at a time.
  40. */
  41. unsigned spool_eagerly : 1;
  42. /**
  43. * Tells us what kind of object to get, and how to look it up.
  44. */
  45. dir_spool_source_bitfield_t spool_source : 7;
  46. /**
  47. * Tells us the specific object to spool.
  48. */
  49. uint8_t digest[DIGEST256_LEN];
  50. /**
  51. * A large object that we're spooling. Holds a reference count. Only
  52. * used when spool_eagerly is false.
  53. */
  54. struct cached_dir_t *cached_dir_ref;
  55. /**
  56. * A different kind of large object that we might be spooling. Also
  57. * reference-counted. Also only used when spool_eagerly is false.
  58. */
  59. struct consensus_cache_entry_t *consensus_cache_entry;
  60. const uint8_t *cce_body;
  61. size_t cce_len;
  62. /**
  63. * The current offset into cached_dir or cce_body. Only used when
  64. * spool_eagerly is false */
  65. off_t cached_dir_offset;
  66. } spooled_resource_t;
  67. int connection_dirserv_flushed_some(dir_connection_t *conn);
  68. int directory_fetches_from_authorities(const or_options_t *options);
  69. int directory_fetches_dir_info_early(const or_options_t *options);
  70. int directory_fetches_dir_info_later(const or_options_t *options);
  71. int directory_caches_unknown_auth_certs(const or_options_t *options);
  72. int directory_caches_dir_info(const or_options_t *options);
  73. int directory_permits_begindir_requests(const or_options_t *options);
  74. int directory_too_idle_to_fetch_descriptors(const or_options_t *options,
  75. time_t now);
  76. cached_dir_t *dirserv_get_consensus(const char *flavor_name);
  77. void dirserv_set_cached_consensus_networkstatus(const char *consensus,
  78. const char *flavor_name,
  79. const common_digests_t *digests,
  80. const uint8_t *sha3_as_signed,
  81. time_t published);
  82. void dirserv_clear_old_networkstatuses(time_t cutoff);
  83. int dirserv_get_routerdesc_spool(smartlist_t *spools_out, const char *key,
  84. dir_spool_source_t source,
  85. int conn_is_encrypted,
  86. const char **msg_out);
  87. int dirserv_get_routerdescs(smartlist_t *descs_out, const char *key,
  88. const char **msg);
  89. void dirserv_free_all(void);
  90. void cached_dir_decref(cached_dir_t *d);
  91. cached_dir_t *new_cached_dir(char *s, time_t published);
  92. spooled_resource_t *spooled_resource_new(dir_spool_source_t source,
  93. const uint8_t *digest,
  94. size_t digestlen);
  95. spooled_resource_t *spooled_resource_new_from_cache_entry(
  96. struct consensus_cache_entry_t *entry);
  97. void spooled_resource_free_(spooled_resource_t *spooled);
  98. #define spooled_resource_free(sp) \
  99. FREE_AND_NULL(spooled_resource_t, spooled_resource_free_, (sp))
  100. void dirserv_spool_remove_missing_and_guess_size(dir_connection_t *conn,
  101. time_t cutoff,
  102. int compression,
  103. size_t *size_out,
  104. int *n_expired_out);
  105. void dirserv_spool_sort(dir_connection_t *conn);
  106. void dir_conn_clear_spool(dir_connection_t *conn);
  107. #endif /* !defined(TOR_DIRSERV_H) */