protover.h 2.7 KB

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