]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
protover: Add function to get the value of a single type
authorDavid Goulet <dgoulet@torproject.org>
Thu, 4 Nov 2021 14:20:07 +0000 (10:20 -0400)
committerMike Perry <mikeperry-git@torproject.org>
Tue, 22 Feb 2022 19:28:34 +0000 (19:28 +0000)
We can now query the protover subsystem to get the current value we
support for a specific protover type.

This will be useful for prop324 onion service part which puts in the
FlowCtrl value in the service descriptor.

No behavior change.

Signed-off-by: David Goulet <dgoulet@torproject.org>
src/core/or/protover.c
src/core/or/protover.h

index ff986b62e2c1715c49b737eb6864ce22327a006d..4cd6510da7b0c234f2f0cce1ff5061a56eaf4f70 100644 (file)
@@ -385,6 +385,46 @@ protocol_list_supports_protocol_or_later(const char *list,
 /*
  * XXX START OF HAZARDOUS ZONE XXX
  */
+/* All protocol version that this relay version supports. */
+#define PR_CONS_V      "1-2"
+#define PR_DESC_V      "1-2"
+#define PR_DIRCACHE_V  "2"
+#define PR_FLOWCTRL_V  "1-2"
+#define PR_HSDIR_V     "2"
+#define PR_HSINTRO_V   "4-5"
+#define PR_HSREND_V    "1-2"
+#define PR_LINK_V      "1-5"
+#ifdef HAVE_WORKING_TOR_TLS_GET_TLSSECRETS
+#define PR_LINKAUTH_V  "1,3"
+#else
+#define PR_LINKAUTH_V  "3"
+#endif
+#define PR_MICRODESC_V "1-2"
+#define PR_PADDING_V   "2"
+#define PR_RELAY_V     "1-4"
+
+/** Return the string containing the supported version for the given protocol
+ * type. */
+const char *
+protover_get_supported(const protocol_type_t type)
+{
+  switch (type) {
+  case PRT_CONS: return PR_CONS_V;
+  case PRT_DESC: return PR_DESC_V;
+  case PRT_DIRCACHE: return PR_DIRCACHE_V;
+  case PRT_FLOWCTRL: return PR_FLOWCTRL_V;
+  case PRT_HSDIR: return PR_HSDIR_V;
+  case PRT_HSINTRO:  return PR_HSINTRO_V;
+  case PRT_HSREND: return PR_HSREND_V;
+  case PRT_LINK: return PR_LINK_V;
+  case PRT_LINKAUTH: return PR_LINKAUTH_V;
+  case PRT_MICRODESC: return PR_MICRODESC_V;
+  case PRT_PADDING: return PR_PADDING_V;
+  case PRT_RELAY: return PR_RELAY_V;
+  default:
+    tor_assert_unreached();
+  }
+}
 
 /** Return the canonical string containing the list of protocols
  * that we support.
@@ -431,22 +471,18 @@ protover_get_supported_protocols(void)
    */
 
   return
-    "Cons=1-2 "
-    "Desc=1-2 "
-    "DirCache=2 "
-    "FlowCtrl=1-2 "
-    "HSDir=2 "
-    "HSIntro=4-5 "
-    "HSRend=1-2 "
-    "Link=1-5 "
-#ifdef HAVE_WORKING_TOR_TLS_GET_TLSSECRETS
-    "LinkAuth=1,3 "
-#else
-    "LinkAuth=3 "
-#endif
-    "Microdesc=1-2 "
-    "Padding=2 "
-    "Relay=1-4";
+    "Cons=" PR_CONS_V " "
+    "Desc=" PR_DESC_V " "
+    "DirCache=" PR_DIRCACHE_V " "
+    "FlowCtrl=" PR_FLOWCTRL_V " "
+    "HSDir=" PR_HSDIR_V " "
+    "HSIntro=" PR_HSINTRO_V " "
+    "HSRend=" PR_HSREND_V " "
+    "Link=" PR_LINK_V " "
+    "LinkAuth=" PR_LINKAUTH_V " "
+    "Microdesc=" PR_MICRODESC_V " "
+    "Padding=" PR_PADDING_V " "
+    "Relay=" PR_RELAY_V;
 }
 
 /*
index 410a67a9f71d9d9dbba2ad8372f414272f716121..8f15c02fb2447f8593f202923d5bb5dd1b101c5e 100644 (file)
@@ -75,6 +75,7 @@ typedef enum protocol_type_t {
 } protocol_type_t;
 
 bool protover_list_is_invalid(const char *s);
+const char *protover_get_supported(const protocol_type_t type);
 int protover_all_supported(const char *s, char **missing);
 int protover_is_supported_here(protocol_type_t pr, uint32_t ver);
 const char *protover_get_supported_protocols(void);