summaryrefslogtreecommitdiff
path: root/src/or/protover.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2017-09-11 09:50:31 -0400
committerNick Mathewson <nickm@torproject.org>2017-09-11 09:50:31 -0400
commit362bc880b1c4bbccba8698b872c16fc6a6da168e (patch)
tree243c1f3f2d07859811db59180994419adc3784ca /src/or/protover.c
parent67a5d4cb60a9f27e981b83195cf47183a7e9abcc (diff)
downloadtor-362bc880b1c4bbccba8698b872c16fc6a6da168e.tar.gz
tor-362bc880b1c4bbccba8698b872c16fc6a6da168e.zip
Add a function to check for support for "protocol X or later"
Also, add unit tests for this new function and for the regular "does this list include support for protocol X" code.
Diffstat (limited to 'src/or/protover.c')
-rw-r--r--src/or/protover.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/or/protover.c b/src/or/protover.c
index 1a3e69be10..5aaf4f4c34 100644
--- a/src/or/protover.c
+++ b/src/or/protover.c
@@ -280,6 +280,42 @@ protocol_list_supports_protocol(const char *list, protocol_type_t tp,
return contains;
}
+/**
+ * Return true iff "list" encodes a protocol list that includes support for
+ * the indicated protocol and version, or some later version.
+ */
+int
+protocol_list_supports_protocol_or_later(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;
+ }
+ const char *pr_name = protocol_type_to_str(tp);
+
+ int contains = 0;
+ SMARTLIST_FOREACH_BEGIN(protocols, proto_entry_t *, proto) {
+ if (strcasecmp(proto->name, pr_name))
+ continue;
+ SMARTLIST_FOREACH_BEGIN(proto->ranges, const proto_range_t *, range) {
+ if (range->high >= version) {
+ contains = 1;
+ goto found;
+ }
+ } SMARTLIST_FOREACH_END(range);
+ } SMARTLIST_FOREACH_END(proto);
+
+ found:
+ 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 *