protover.h 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. /** List of recognized subprotocols. */
  27. /// C_RUST_COUPLED: src/rust/protover/ffi.rs `translate_to_rust`
  28. /// C_RUST_COUPLED: src/rust/protover/protover.rs `Proto`
  29. typedef enum protocol_type_t {
  30. PRT_LINK,
  31. PRT_LINKAUTH,
  32. PRT_RELAY,
  33. PRT_DIRCACHE,
  34. PRT_HSDIR,
  35. PRT_HSINTRO,
  36. PRT_HSREND,
  37. PRT_DESC,
  38. PRT_MICRODESC,
  39. PRT_CONS,
  40. } protocol_type_t;
  41. bool protover_contains_long_protocol_names(const char *s);
  42. int protover_all_supported(const char *s, char **missing);
  43. int protover_is_supported_here(protocol_type_t pr, uint32_t ver);
  44. const char *protover_get_supported_protocols(void);
  45. char *protover_compute_vote(const struct smartlist_t *list_of_proto_strings,
  46. int threshold);
  47. const char *protover_compute_for_old_tor(const char *version);
  48. int protocol_list_supports_protocol(const char *list, protocol_type_t tp,
  49. uint32_t version);
  50. int protocol_list_supports_protocol_or_later(const char *list,
  51. protocol_type_t tp,
  52. uint32_t version);
  53. void protover_free_all(void);
  54. #ifdef PROTOVER_PRIVATE
  55. /** Represents a range of subprotocols of a given type. All subprotocols
  56. * between <b>low</b> and <b>high</b> inclusive are included. */
  57. typedef struct proto_range_t {
  58. uint32_t low;
  59. uint32_t high;
  60. } proto_range_t;
  61. /** Represents a set of ranges of subprotocols of a given type. */
  62. typedef struct proto_entry_t {
  63. /** The name of the protocol.
  64. *
  65. * (This needs to handle voting on protocols which
  66. * we don't recognize yet, so it's a char* rather than a protocol_type_t.)
  67. */
  68. char *name;
  69. /** Smartlist of proto_range_t */
  70. struct smartlist_t *ranges;
  71. } proto_entry_t;
  72. #if !defined(HAVE_RUST) && defined(TOR_UNIT_TESTS)
  73. STATIC struct smartlist_t *parse_protocol_list(const char *s);
  74. STATIC char *encode_protocol_list(const struct smartlist_t *sl);
  75. STATIC const char *protocol_type_to_str(protocol_type_t pr);
  76. STATIC int str_to_protocol_type(const char *s, protocol_type_t *pr_out);
  77. STATIC void proto_entry_free_(proto_entry_t *entry);
  78. #endif /* !defined(HAVE_RUST) && defined(TOR_UNIT_TESTS) */
  79. #define proto_entry_free(entry) \
  80. FREE_AND_NULL(proto_entry_t, proto_entry_free_, (entry))
  81. #endif /* defined(PROTOVER_PRIVATE) */
  82. #endif /* !defined(TOR_PROTOVER_H) */