protover.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /* Copyright (c) 2016-2019, The Tor Project, Inc. */
  2. /* See LICENSE for licensing information */
  3. /**
  4. * \file protover.h
  5. * \brief Headers and type declarations for protover.c
  6. **/
  7. #ifndef TOR_PROTOVER_H
  8. #define TOR_PROTOVER_H
  9. #include <stdbool.h>
  10. #include "lib/cc/torint.h"
  11. #include "lib/testsupport/testsupport.h"
  12. struct smartlist_t;
  13. /** The first version of Tor that included "proto" entries in its
  14. * descriptors. Authorities should use this to decide whether to
  15. * guess proto lines. */
  16. /* This is a guess. */
  17. /// C_RUST_COUPLED: src/rust/protover/protover.rs
  18. /// `FIRST_TOR_VERSION_TO_ADVERTISE_PROTOCOLS`
  19. #define FIRST_TOR_VERSION_TO_ADVERTISE_PROTOCOLS "0.2.9.3-alpha"
  20. /** The protover version number that signifies HSDir support for HSv3 */
  21. #define PROTOVER_HSDIR_V3 2
  22. /** The protover version number that signifies HSv3 intro point support */
  23. #define PROTOVER_HS_INTRO_V3 4
  24. /** The protover version number that signifies HSv3 rendezvous point support */
  25. #define PROTOVER_HS_RENDEZVOUS_POINT_V3 2
  26. /** The protover that signals support for HS circuit setup padding machines */
  27. #define PROTOVER_HS_SETUP_PADDING 2
  28. /** List of recognized subprotocols. */
  29. /// C_RUST_COUPLED: src/rust/protover/ffi.rs `translate_to_rust`
  30. /// C_RUST_COUPLED: src/rust/protover/protover.rs `Proto`
  31. typedef enum protocol_type_t {
  32. PRT_LINK = 0,
  33. PRT_LINKAUTH = 1,
  34. PRT_RELAY = 2,
  35. PRT_DIRCACHE = 3,
  36. PRT_HSDIR = 4,
  37. PRT_HSINTRO = 5,
  38. PRT_HSREND = 6,
  39. PRT_DESC = 7,
  40. PRT_MICRODESC = 8,
  41. PRT_CONS = 9,
  42. PRT_PADDING = 10,
  43. PRT_FLOWCTRL = 11,
  44. } protocol_type_t;
  45. bool protover_contains_long_protocol_names(const char *s);
  46. int protover_all_supported(const char *s, char **missing);
  47. int protover_is_supported_here(protocol_type_t pr, uint32_t ver);
  48. const char *protover_get_supported_protocols(void);
  49. char *protover_compute_vote(const struct smartlist_t *list_of_proto_strings,
  50. int threshold);
  51. const char *protover_compute_for_old_tor(const char *version);
  52. int protocol_list_supports_protocol(const char *list, protocol_type_t tp,
  53. uint32_t version);
  54. int protocol_list_supports_protocol_or_later(const char *list,
  55. protocol_type_t tp,
  56. uint32_t version);
  57. void protover_free_all(void);
  58. #ifdef PROTOVER_PRIVATE
  59. /** Represents a range of subprotocols of a given type. All subprotocols
  60. * between <b>low</b> and <b>high</b> inclusive are included. */
  61. typedef struct proto_range_t {
  62. uint32_t low;
  63. uint32_t high;
  64. } proto_range_t;
  65. /** Represents a set of ranges of subprotocols of a given type. */
  66. typedef struct proto_entry_t {
  67. /** The name of the protocol.
  68. *
  69. * (This needs to handle voting on protocols which
  70. * we don't recognize yet, so it's a char* rather than a protocol_type_t.)
  71. */
  72. char *name;
  73. /** Smartlist of proto_range_t */
  74. struct smartlist_t *ranges;
  75. } proto_entry_t;
  76. #if !defined(HAVE_RUST) && defined(TOR_UNIT_TESTS)
  77. STATIC struct smartlist_t *parse_protocol_list(const char *s);
  78. STATIC char *encode_protocol_list(const struct smartlist_t *sl);
  79. STATIC const char *protocol_type_to_str(protocol_type_t pr);
  80. STATIC int str_to_protocol_type(const char *s, protocol_type_t *pr_out);
  81. STATIC void proto_entry_free_(proto_entry_t *entry);
  82. #endif /* !defined(HAVE_RUST) && defined(TOR_UNIT_TESTS) */
  83. #define proto_entry_free(entry) \
  84. FREE_AND_NULL(proto_entry_t, proto_entry_free_, (entry))
  85. #endif /* defined(PROTOVER_PRIVATE) */
  86. #endif /* !defined(TOR_PROTOVER_H) */