protover.h 3.1 KB

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