Tor  0.4.3.0-alpha-dev
protover.h
Go to the documentation of this file.
1 /* Copyright (c) 2016-2019, The Tor Project, Inc. */
2 /* See LICENSE for licensing information */
3 
4 /**
5  * \file protover.h
6  * \brief Headers and type declarations for protover.c
7  **/
8 
9 #ifndef TOR_PROTOVER_H
10 #define TOR_PROTOVER_H
11 
12 #include <stdbool.h>
13 #include "lib/cc/torint.h"
15 struct smartlist_t;
16 
17 /** The first version of Tor that included "proto" entries in its
18  * descriptors. Authorities should use this to decide whether to
19  * guess proto lines. */
20 /* This is a guess. */
21 /// C_RUST_COUPLED: src/rust/protover/protover.rs
22 /// `FIRST_TOR_VERSION_TO_ADVERTISE_PROTOCOLS`
23 #define FIRST_TOR_VERSION_TO_ADVERTISE_PROTOCOLS "0.2.9.3-alpha"
24 
25 /** The protover version number that signifies HSDir support for HSv3 */
26 #define PROTOVER_HSDIR_V3 2
27 /** The protover version number that signifies HSv3 intro point support */
28 #define PROTOVER_HS_INTRO_V3 4
29 /** The protover version number that signifies HSv3 rendezvous point support */
30 #define PROTOVER_HS_RENDEZVOUS_POINT_V3 2
31 /** The protover that signals support for HS circuit setup padding machines */
32 #define PROTOVER_HS_SETUP_PADDING 2
33 
34 /** List of recognized subprotocols. */
35 /// C_RUST_COUPLED: src/rust/protover/ffi.rs `translate_to_rust`
36 /// C_RUST_COUPLED: src/rust/protover/protover.rs `Proto`
37 typedef enum protocol_type_t {
38  PRT_LINK = 0,
39  PRT_LINKAUTH = 1,
40  PRT_RELAY = 2,
41  PRT_DIRCACHE = 3,
42  PRT_HSDIR = 4,
43  PRT_HSINTRO = 5,
44  PRT_HSREND = 6,
45  PRT_DESC = 7,
46  PRT_MICRODESC = 8,
47  PRT_CONS = 9,
48  PRT_PADDING = 10,
49  PRT_FLOWCTRL = 11,
51 
52 bool protover_contains_long_protocol_names(const char *s);
53 int protover_all_supported(const char *s, char **missing);
54 int protover_is_supported_here(protocol_type_t pr, uint32_t ver);
55 const char *protover_get_supported_protocols(void);
56 
57 char *protover_compute_vote(const struct smartlist_t *list_of_proto_strings,
58  int threshold);
59 const char *protover_compute_for_old_tor(const char *version);
61  uint32_t version);
63  protocol_type_t tp,
64  uint32_t version);
65 
66 void protover_free_all(void);
67 
68 #ifdef PROTOVER_PRIVATE
69 /** Represents a range of subprotocols of a given type. All subprotocols
70  * between <b>low</b> and <b>high</b> inclusive are included. */
71 typedef struct proto_range_t {
72  uint32_t low;
73  uint32_t high;
74 } proto_range_t;
75 
76 /** Represents a set of ranges of subprotocols of a given type. */
77 typedef struct proto_entry_t {
78  /** The name of the protocol.
79  *
80  * (This needs to handle voting on protocols which
81  * we don't recognize yet, so it's a char* rather than a protocol_type_t.)
82  */
83  char *name;
84  /** Smartlist of proto_range_t */
85  struct smartlist_t *ranges;
86 } proto_entry_t;
87 
88 #if !defined(HAVE_RUST) && defined(TOR_UNIT_TESTS)
89 STATIC struct smartlist_t *parse_protocol_list(const char *s);
90 STATIC char *encode_protocol_list(const struct smartlist_t *sl);
92 STATIC int str_to_protocol_type(const char *s, protocol_type_t *pr_out);
93 STATIC void proto_entry_free_(proto_entry_t *entry);
94 #endif /* !defined(HAVE_RUST) && defined(TOR_UNIT_TESTS) */
95 
96 #define proto_entry_free(entry) \
97  FREE_AND_NULL(proto_entry_t, proto_entry_free_, (entry))
98 
99 #endif /* defined(PROTOVER_PRIVATE) */
100 
101 #endif /* !defined(TOR_PROTOVER_H) */
int protover_all_supported(const char *s, char **missing)
Definition: protover.c:748
STATIC smartlist_t * parse_protocol_list(const char *s)
Definition: protover.c:269
const char * protover_compute_for_old_tor(const char *version)
C_RUST_COUPLED: src/rust/protover/protover.rs compute_for_old_tor
Definition: protover.c:902
void protover_free_all(void)
Definition: protover.c:940
const char * name
Definition: config.c:2211
Integer definitions used throughout Tor.
#define STATIC
Definition: testsupport.h:32
void ** list
int protocol_list_supports_protocol_or_later(const char *list, protocol_type_t tp, uint32_t version)
Definition: protover.c:353
protocol_type_t
Definition: protover.h:37
int protover_is_supported_here(protocol_type_t pr, uint32_t ver)
Definition: protover.c:320
const char * protover_get_supported_protocols(void)
C_RUST_COUPLED: src/rust/protover/protover.rs SUPPORTED_PROTOCOLS
Definition: protover.c:388
STATIC int str_to_protocol_type(const char *s, protocol_type_t *pr_out)
Definition: protover.c:90
STATIC void proto_entry_free_(proto_entry_t *entry)
Definition: protover.c:110
STATIC const char * protocol_type_to_str(protocol_type_t pr)
Definition: protover.c:72
Macros to implement mocking and selective exposure for the test code.
int protocol_list_supports_protocol(const char *list, protocol_type_t tp, uint32_t version)
Definition: protover.c:331
bool protover_contains_long_protocol_names(const char *s)
Definition: protover.c:305
char * protover_compute_vote(const smartlist_t *list_of_proto_strings, int threshold)
Definition: protover.c:671
STATIC char * encode_protocol_list(const smartlist_t *sl)
Definition: protover.c:454