diff options
author | Nick Mathewson <nickm@torproject.org> | 2017-11-09 09:17:53 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2017-11-09 09:17:53 -0500 |
commit | 06260315645945ca9e08b5a19b67c8adad65a698 (patch) | |
tree | 52d4a7cd26645cceb9f4204eb72bca29eea27766 /src/or/protover.c | |
parent | 59c1016aba63c62e658065475add3cf77f665afa (diff) | |
parent | 3124c921e7af15548b8b16d5f239bfdcd178b2ca (diff) | |
download | tor-06260315645945ca9e08b5a19b67c8adad65a698.tar.gz tor-06260315645945ca9e08b5a19b67c8adad65a698.zip |
Merge branch 'ticket20895'
Diffstat (limited to 'src/or/protover.c')
-rw-r--r-- | src/or/protover.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/or/protover.c b/src/or/protover.c index 0e74deb112..8b61d96630 100644 --- a/src/or/protover.c +++ b/src/or/protover.c @@ -282,6 +282,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 * |