dirvote.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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-2013, 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. /** Lowest allowable value for VoteSeconds. */
  14. #define MIN_VOTE_SECONDS 2
  15. /** Lowest allowable value for DistSeconds. */
  16. #define MIN_DIST_SECONDS 2
  17. /** Smallest allowable voting interval. */
  18. #define MIN_VOTE_INTERVAL 300
  19. /** The highest consensus method that we currently support. */
  20. #define MAX_SUPPORTED_CONSENSUS_METHOD 18
  21. /** Lowest consensus method that contains a 'directory-footer' marker */
  22. #define MIN_METHOD_FOR_FOOTER 9
  23. /** Lowest consensus method that contains bandwidth weights */
  24. #define MIN_METHOD_FOR_BW_WEIGHTS 9
  25. /** Lowest consensus method that contains consensus params */
  26. #define MIN_METHOD_FOR_PARAMS 7
  27. /** Lowest consensus method that generates microdescriptors */
  28. #define MIN_METHOD_FOR_MICRODESC 8
  29. /** Lowest consensus method that doesn't count bad exits as exits for weight */
  30. #define MIN_METHOD_TO_CUT_BADEXIT_WEIGHT 11
  31. /** Lowest consensus method that ensures a majority of authorities voted
  32. * for a param. */
  33. #define MIN_METHOD_FOR_MAJORITY_PARAMS 12
  34. /** Lowest consensus method where microdesc consensuses omit any entry
  35. * with no microdesc. */
  36. #define MIN_METHOD_FOR_MANDATORY_MICRODESC 13
  37. /** Lowest consensus method that contains "a" lines. */
  38. #define MIN_METHOD_FOR_A_LINES 14
  39. /** Lowest consensus method where microdescs may include a "p6" line. */
  40. #define MIN_METHOD_FOR_P6_LINES 15
  41. /** Lowest consensus method where microdescs may include an onion-key-ntor
  42. * line */
  43. #define MIN_METHOD_FOR_NTOR_KEY 16
  44. /** Lowest consensus method that ensures that authorities output an
  45. * Unmeasured=1 flag for unmeasured bandwidths */
  46. #define MIN_METHOD_TO_CLIP_UNMEASURED_BW 17
  47. /** Lowest consensus method where authorities may include an "id" line in
  48. * microdescriptors. */
  49. #define MIN_METHOD_FOR_ID_HASH_IN_MD 18
  50. /** Default bandwidth to clip unmeasured bandwidths to using method >=
  51. * MIN_METHOD_TO_CLIP_UNMEASURED_BW */
  52. #define DEFAULT_MAX_UNMEASURED_BW_KB 20
  53. void dirvote_free_all(void);
  54. /* vote manipulation */
  55. char *networkstatus_compute_consensus(smartlist_t *votes,
  56. int total_authorities,
  57. crypto_pk_t *identity_key,
  58. crypto_pk_t *signing_key,
  59. const char *legacy_identity_key_digest,
  60. crypto_pk_t *legacy_signing_key,
  61. consensus_flavor_t flavor);
  62. int networkstatus_add_detached_signatures(networkstatus_t *target,
  63. ns_detached_signatures_t *sigs,
  64. const char *source,
  65. int severity,
  66. const char **msg_out);
  67. char *networkstatus_get_detached_signatures(smartlist_t *consensuses);
  68. void ns_detached_signatures_free(ns_detached_signatures_t *s);
  69. /* cert manipulation */
  70. authority_cert_t *authority_cert_dup(authority_cert_t *cert);
  71. /* vote scheduling */
  72. void dirvote_get_preferred_voting_intervals(vote_timing_t *timing_out);
  73. time_t dirvote_get_start_of_next_interval(time_t now,
  74. int interval,
  75. int offset);
  76. void dirvote_recalculate_timing(const or_options_t *options, time_t now);
  77. void dirvote_act(const or_options_t *options, time_t now);
  78. /* invoked on timers and by outside triggers. */
  79. struct pending_vote_t * dirvote_add_vote(const char *vote_body,
  80. const char **msg_out,
  81. int *status_out);
  82. int dirvote_add_signatures(const char *detached_signatures_body,
  83. const char *source,
  84. const char **msg_out);
  85. /* Item access */
  86. const char *dirvote_get_pending_consensus(consensus_flavor_t flav);
  87. const char *dirvote_get_pending_detached_signatures(void);
  88. #define DGV_BY_ID 1
  89. #define DGV_INCLUDE_PENDING 2
  90. #define DGV_INCLUDE_PREVIOUS 4
  91. const cached_dir_t *dirvote_get_vote(const char *fp, int flags);
  92. void set_routerstatus_from_routerinfo(routerstatus_t *rs,
  93. node_t *node,
  94. routerinfo_t *ri, time_t now,
  95. int naming, int listbadexits,
  96. int listbaddirs, int vote_on_hsdirs);
  97. networkstatus_t *
  98. dirserv_generate_networkstatus_vote_obj(crypto_pk_t *private_key,
  99. authority_cert_t *cert);
  100. microdesc_t *dirvote_create_microdescriptor(const routerinfo_t *ri,
  101. int consensus_method);
  102. ssize_t dirvote_format_microdesc_vote_line(char *out, size_t out_len,
  103. const microdesc_t *md,
  104. int consensus_method_low,
  105. int consensus_method_high);
  106. vote_microdesc_hash_t *dirvote_format_all_microdesc_vote_lines(
  107. const routerinfo_t *ri,
  108. time_t now,
  109. smartlist_t *microdescriptors_out);
  110. int vote_routerstatus_find_microdesc_hash(char *digest256_out,
  111. const vote_routerstatus_t *vrs,
  112. int method,
  113. digest_algorithm_t alg);
  114. document_signature_t *voter_get_sig_by_algorithm(
  115. const networkstatus_voter_info_t *voter,
  116. digest_algorithm_t alg);
  117. #ifdef DIRVOTE_PRIVATE
  118. STATIC char *format_networkstatus_vote(crypto_pk_t *private_key,
  119. networkstatus_t *v3_ns);
  120. STATIC char *dirvote_compute_params(smartlist_t *votes, int method,
  121. int total_authorities);
  122. #endif
  123. #endif