protover.h 3.4 KB

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