protover.h 3.3 KB

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