dirvote.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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-2015, The Tor Project, Inc. */
  5. /* See LICENSE for licensing information */
  6. /**
  7. * \file dirvote.h
  8. * \brief Header file for dirvote.c.
  9. **/
  10. #ifndef TOR_DIRVOTE_H
  11. #define TOR_DIRVOTE_H
  12. #include "testsupport.h"
  13. /*
  14. * Ideally, assuming synced clocks, we should only need 1 second for each of:
  15. * - Vote
  16. * - Distribute
  17. * - Consensus Publication
  18. * As we can gather descriptors continuously.
  19. * (Could we even go as far as publishing the previous consensus,
  20. * in the same second that we vote for the next one?)
  21. * But we're not there yet: these are the lowest working values at this time.
  22. */
  23. /** Lowest allowable value for VoteSeconds. */
  24. #define MIN_VOTE_SECONDS 2
  25. /** Lowest allowable value for VoteSeconds when TestingTorNetwork is 1 */
  26. #define MIN_VOTE_SECONDS_TESTING 2
  27. /** Lowest allowable value for DistSeconds. */
  28. #define MIN_DIST_SECONDS 2
  29. /** Lowest allowable value for DistSeconds when TestingTorNetwork is 1 */
  30. #define MIN_DIST_SECONDS_TESTING 2
  31. /** Lowest allowable voting interval. */
  32. #define MIN_VOTE_INTERVAL 300
  33. /** Lowest allowable voting interval when TestingTorNetwork is 1:
  34. * Voting Interval can be:
  35. * 10, 12, 15, 18, 20, 24, 25, 30, 36, 40, 45, 50, 60, ...
  36. * Testing Initial Voting Interval can be:
  37. * 5, 6, 8, 9, or any of the possible values for Voting Interval,
  38. * as they both need to evenly divide 30 minutes.
  39. * If clock desynchronisation is an issue, use an interval of at least:
  40. * 18 * drift in seconds, to allow for a clock slop factor */
  41. #define MIN_VOTE_INTERVAL_TESTING \
  42. (((MIN_VOTE_SECONDS_TESTING)+(MIN_DIST_SECONDS_TESTING)+1)*2)
  43. #define MIN_VOTE_INTERVAL_TESTING_INITIAL \
  44. ((MIN_VOTE_SECONDS_TESTING)+(MIN_DIST_SECONDS_TESTING)+1)
  45. /** The lowest consensus method that we currently support. */
  46. #define MIN_SUPPORTED_CONSENSUS_METHOD 13
  47. /** The highest consensus method that we currently support. */
  48. #define MAX_SUPPORTED_CONSENSUS_METHOD 19
  49. /** Lowest consensus method where microdesc consensuses omit any entry
  50. * with no microdesc. */
  51. #define MIN_METHOD_FOR_MANDATORY_MICRODESC 13
  52. /** Lowest consensus method that contains "a" lines. */
  53. #define MIN_METHOD_FOR_A_LINES 14
  54. /** Lowest consensus method where microdescs may include a "p6" line. */
  55. #define MIN_METHOD_FOR_P6_LINES 15
  56. /** Lowest consensus method where microdescs may include an onion-key-ntor
  57. * line */
  58. #define MIN_METHOD_FOR_NTOR_KEY 16
  59. /** Lowest consensus method that ensures that authorities output an
  60. * Unmeasured=1 flag for unmeasured bandwidths */
  61. #define MIN_METHOD_TO_CLIP_UNMEASURED_BW 17
  62. /** Lowest consensus method where authorities may include an "id" line in
  63. * microdescriptors. */
  64. #define MIN_METHOD_FOR_ID_HASH_IN_MD 18
  65. /** Lowest consensus method where authorities may include
  66. * GuardFraction information in microdescriptors. */
  67. #define MIN_METHOD_FOR_GUARDFRACTION 19
  68. /** Default bandwidth to clip unmeasured bandwidths to using method >=
  69. * MIN_METHOD_TO_CLIP_UNMEASURED_BW */
  70. #define DEFAULT_MAX_UNMEASURED_BW_KB 20
  71. void dirvote_free_all(void);
  72. /* vote manipulation */
  73. char *networkstatus_compute_consensus(smartlist_t *votes,
  74. int total_authorities,
  75. crypto_pk_t *identity_key,
  76. crypto_pk_t *signing_key,
  77. const char *legacy_identity_key_digest,
  78. crypto_pk_t *legacy_signing_key,
  79. consensus_flavor_t flavor);
  80. int networkstatus_add_detached_signatures(networkstatus_t *target,
  81. ns_detached_signatures_t *sigs,
  82. const char *source,
  83. int severity,
  84. const char **msg_out);
  85. char *networkstatus_get_detached_signatures(smartlist_t *consensuses);
  86. void ns_detached_signatures_free(ns_detached_signatures_t *s);
  87. /* cert manipulation */
  88. authority_cert_t *authority_cert_dup(authority_cert_t *cert);
  89. /* vote scheduling */
  90. void dirvote_get_preferred_voting_intervals(vote_timing_t *timing_out);
  91. time_t dirvote_get_start_of_next_interval(time_t now,
  92. int interval,
  93. int offset);
  94. void dirvote_recalculate_timing(const or_options_t *options, time_t now);
  95. void dirvote_act(const or_options_t *options, time_t now);
  96. /* invoked on timers and by outside triggers. */
  97. struct pending_vote_t * dirvote_add_vote(const char *vote_body,
  98. const char **msg_out,
  99. int *status_out);
  100. int dirvote_add_signatures(const char *detached_signatures_body,
  101. const char *source,
  102. const char **msg_out);
  103. /* Item access */
  104. const char *dirvote_get_pending_consensus(consensus_flavor_t flav);
  105. const char *dirvote_get_pending_detached_signatures(void);
  106. #define DGV_BY_ID 1
  107. #define DGV_INCLUDE_PENDING 2
  108. #define DGV_INCLUDE_PREVIOUS 4
  109. const cached_dir_t *dirvote_get_vote(const char *fp, int flags);
  110. void set_routerstatus_from_routerinfo(routerstatus_t *rs,
  111. node_t *node,
  112. routerinfo_t *ri, time_t now,
  113. int listbadexits,
  114. int vote_on_hsdirs);
  115. networkstatus_t *
  116. dirserv_generate_networkstatus_vote_obj(crypto_pk_t *private_key,
  117. authority_cert_t *cert);
  118. microdesc_t *dirvote_create_microdescriptor(const routerinfo_t *ri,
  119. int consensus_method);
  120. ssize_t dirvote_format_microdesc_vote_line(char *out, size_t out_len,
  121. const microdesc_t *md,
  122. int consensus_method_low,
  123. int consensus_method_high);
  124. vote_microdesc_hash_t *dirvote_format_all_microdesc_vote_lines(
  125. const routerinfo_t *ri,
  126. time_t now,
  127. smartlist_t *microdescriptors_out);
  128. int vote_routerstatus_find_microdesc_hash(char *digest256_out,
  129. const vote_routerstatus_t *vrs,
  130. int method,
  131. digest_algorithm_t alg);
  132. document_signature_t *voter_get_sig_by_algorithm(
  133. const networkstatus_voter_info_t *voter,
  134. digest_algorithm_t alg);
  135. #ifdef DIRVOTE_PRIVATE
  136. STATIC char *format_networkstatus_vote(crypto_pk_t *private_key,
  137. networkstatus_t *v3_ns);
  138. STATIC char *dirvote_compute_params(smartlist_t *votes, int method,
  139. int total_authorities);
  140. #endif
  141. #endif