]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Use protocols to see when EXTEND2 support exists.
authorNick Mathewson <nickm@torproject.org>
Fri, 26 Aug 2016 16:49:00 +0000 (12:49 -0400)
committerNick Mathewson <nickm@torproject.org>
Mon, 26 Sep 2016 17:56:51 +0000 (10:56 -0700)
(Technically, we could just remove extend2 cell checking entirely,
since all Tor versions on our network are required to have it, but
let's keep this around as an example of How To Do It.)

src/or/or.h
src/or/protover.c
src/or/protover.h
src/or/routerlist.c
src/or/routerparse.c

index 50851391210233cf14a1b206c1aada829ab93560..befbf716af60b419136c10d3d7f02671c8dd69a6 100644 (file)
@@ -2198,9 +2198,12 @@ typedef struct routerstatus_t {
    * if the number of traits we care about ever becomes incredibly big. */
   unsigned int version_known:1;
 
-  /** True iff this router has a version that allows it to accept EXTEND2
-   * cells */
-  unsigned int version_supports_extend2_cells:1;
+  /** True iff we have a proto line for this router.*/
+  unsigned int protocols_known:1;
+
+  /** True iff this router has a version or protocol list that allows it to
+   * accept EXTEND2 cells */
+  unsigned int supports_extend2_cells:1;
 
   unsigned int has_bandwidth:1; /**< The vote/consensus had bw info */
   unsigned int has_exitsummary:1; /**< The vote/consensus had exit summaries */
index 7feec0c5c7e195f45d626bf42602388bca17f9c0..ca03a71acd3adc9cdd9363a5c21a6703c5a19640 100644 (file)
@@ -235,6 +235,28 @@ protover_is_supported_here(protocol_type_t pr, uint32_t ver)
   return protocol_list_contains(ours, pr, ver);
 }
 
+/**
+ * Return true iff "list" encodes a protocol list that includes support for
+ * the indicated protocol and version.
+ */
+int
+protocol_list_supports_protocol(const char *list, protocol_type_t tp,
+                                uint32_t version)
+{
+  /* NOTE: This is a pretty inefficient implementation. If it ever shows
+   * up in profiles, we should memoize it.
+   */
+  smartlist_t *protocols = parse_protocol_list(list);
+  if (!protocols) {
+    return 0;
+  }
+  int contains = protocol_list_contains(protocols, tp, version);
+
+  SMARTLIST_FOREACH(protocols, proto_entry_t *, ent, proto_entry_free(ent));
+  smartlist_free(protocols);
+  return contains;
+}
+
 /** Return the canonical string containing the list of protocols
  * that we support. */
 const char *
index d37862775941a08b5bfab1e1e332d3fbee1cd5e1..352fa7cbe8dc852f6dceb0d86c43fba367f72135 100644 (file)
@@ -33,7 +33,8 @@ const char *get_supported_protocols(void);
 char * compute_protover_vote(const smartlist_t *list_of_proto_strings,
                              int threshold);
 const char *protover_compute_for_old_tor(const char *version);
-
+int protocol_list_supports_protocol(const char *list, protocol_type_t tp,
+                                    uint32_t version);
 
 void protover_free_all(void);
 
index 56e2385ebeecbca976aadd8aee0ca9f45ba36d13..0a03f13a562fc378348fb786217438031294a274 100644 (file)
@@ -5536,11 +5536,11 @@ routerstatus_version_supports_ntor(const routerstatus_t *rs,
     return allow_unknown_versions;
   }
 
-  if (!rs->version_known) {
+  if (!rs->version_known && !rs->protocols_known) {
     return allow_unknown_versions;
   }
 
-  return rs->version_supports_extend2_cells;
+  return rs->supports_extend2_cells;
 }
 
 /** Assert that the internal representation of <b>rl</b> is
index 9428e4560af1b288e3f487958a8f7c46c16c6671..459a939fb7040aa6c4720ad583ec746dda0c55a7 100644 (file)
@@ -17,6 +17,7 @@
 #include "dirserv.h"
 #include "dirvote.h"
 #include "policies.h"
+#include "protover.h"
 #include "rendcommon.h"
 #include "router.h"
 #include "routerlist.h"
@@ -2904,12 +2905,21 @@ routerstatus_parse_entry_from_string(memarea_t *area,
       }
     }
   }
+  int found_protocol_list = 0;
+  if ((tok = find_opt_by_keyword(tokens, K_PROTO))) {
+    found_protocol_list = 1;
+    rs->protocols_known = 1;
+    rs->supports_extend2_cells =
+      protocol_list_supports_protocol(tok->args[0], PRT_RELAY, 2);
+  }
   if ((tok = find_opt_by_keyword(tokens, K_V))) {
     tor_assert(tok->n_args == 1);
     rs->version_known = 1;
-    if (strcmpstart(tok->args[0], "Tor ")) {
-    } else {
-      rs->version_supports_extend2_cells =
+    if (!strcmpstart(tok->args[0], "Tor ") && !found_protocol_list) {
+      /* We only do version checks like this in the case where
+       * the version is a "Tor" version, and where there is no
+       * list of protocol versions that we should be looking at instead. */
+      rs->supports_extend2_cells =
         tor_version_as_new_as(tok->args[0], "0.2.4.8-alpha");
     }
     if (vote_rs) {