protover.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682
  1. #define PROTOVER_PRIVATE
  2. #include "or.h"
  3. #include "protover.h"
  4. #include "routerparse.h"
  5. static const smartlist_t *get_supported_protocol_list(void);
  6. static int protocol_list_contains(const smartlist_t *protos,
  7. protocol_type_t pr, uint32_t ver);
  8. /** Mapping between protocol type string and protocol type. */
  9. static const struct {
  10. protocol_type_t protover_type;
  11. const char *name;
  12. } PROTOCOL_NAMES[] = {
  13. { PRT_LINK, "Link" },
  14. { PRT_LINKAUTH, "LinkAuth" },
  15. { PRT_RELAY, "Relay" },
  16. { PRT_HSMID, "HSMid" },
  17. { PRT_DIRCACHE, "DirCache" },
  18. { PRT_HSDIR, "HSDir" },
  19. { PRT_DESC, "Desc" },
  20. { PRT_MICRODESC, "Microdesc"},
  21. { PRT_CONS, "Cons" }
  22. };
  23. #define N_PROTOCOL_NAMES ARRAY_LENGTH(PROTOCOL_NAMES)
  24. /**
  25. * Given a protocol_type_t, return the corresponding string used in
  26. * descriptors.
  27. */
  28. STATIC const char *
  29. protocol_type_to_str(protocol_type_t pr)
  30. {
  31. unsigned i;
  32. for (i=0; i < N_PROTOCOL_NAMES; ++i) {
  33. if (PROTOCOL_NAMES[i].protover_type == pr)
  34. return PROTOCOL_NAMES[i].name;
  35. }
  36. /* LCOV_EXCL_START */
  37. tor_assert_nonfatal_unreached_once();
  38. return "UNKNOWN";
  39. /* LCOV_EXCL_STOP */
  40. }
  41. /**
  42. * Given a string, find the corresponding protocol type and store it in
  43. * <b>pr_out</b>. Return 0 on success, -1 on failure.
  44. */
  45. STATIC int
  46. str_to_protocol_type(const char *s, protocol_type_t *pr_out)
  47. {
  48. if (BUG(!pr_out))
  49. return -1;
  50. unsigned i;
  51. for (i=0; i < N_PROTOCOL_NAMES; ++i) {
  52. if (0 == strcmp(s, PROTOCOL_NAMES[i].name)) {
  53. *pr_out = PROTOCOL_NAMES[i].protover_type;
  54. return 0;
  55. }
  56. }
  57. return -1;
  58. }
  59. /**
  60. * Release all space held by a single proto_entry_t structure
  61. */
  62. STATIC void
  63. proto_entry_free(proto_entry_t *entry)
  64. {
  65. if (!entry)
  66. return;
  67. tor_free(entry->name);
  68. SMARTLIST_FOREACH(entry->ranges, proto_range_t *, r, tor_free(r));
  69. smartlist_free(entry->ranges);
  70. tor_free(entry);
  71. }
  72. /**
  73. * Given a string <b>s</b> and optional end-of-string pointer
  74. * <b>end_of_range</b>, parse the protocol range and store it in
  75. * <b>low_out</b> and <b>high_out</b>. A protocol range has the format U, or
  76. * U-U, where U is an unsigned 32-bit integer.
  77. */
  78. static int
  79. parse_version_range(const char *s, const char *end_of_range,
  80. uint32_t *low_out, uint32_t *high_out)
  81. {
  82. uint32_t low, high;
  83. char *next = NULL;
  84. int ok;
  85. tor_assert(high_out);
  86. tor_assert(low_out);
  87. if (BUG(!end_of_range))
  88. end_of_range = s + strlen(s); // LCOV_EXCL_LINE
  89. /* Note that this wouldn't be safe if we didn't know that eventually,
  90. * we'd hit a NUL */
  91. low = (uint32_t) tor_parse_ulong(s, 10, 0, UINT32_MAX, &ok, &next);
  92. if (!ok)
  93. goto error;
  94. if (next > end_of_range)
  95. goto error;
  96. if (next == end_of_range) {
  97. high = low;
  98. goto done;
  99. }
  100. if (*next != '-')
  101. goto error;
  102. s = next+1;
  103. /* ibid */
  104. high = (uint32_t) tor_parse_ulong(s, 10, 0, UINT32_MAX, &ok, &next);
  105. if (!ok)
  106. goto error;
  107. if (next != end_of_range)
  108. goto error;
  109. done:
  110. *high_out = high;
  111. *low_out = low;
  112. return 0;
  113. error:
  114. return -1;
  115. }
  116. /** Parse a single protocol entry from <b>s</b> up to an optional
  117. * <b>end_of_entry</b> pointer, and return that protocol entry. Return NULL
  118. * on error.
  119. *
  120. * A protocol entry has a keyword, an = sign, and zero or more ranges. */
  121. static proto_entry_t *
  122. parse_single_entry(const char *s, const char *end_of_entry)
  123. {
  124. proto_entry_t *out = tor_malloc_zero(sizeof(proto_entry_t));
  125. const char *equals;
  126. out->ranges = smartlist_new();
  127. if (BUG (!end_of_entry))
  128. end_of_entry = s + strlen(s); // LCOV_EXCL_LINE
  129. /* There must be an =. */
  130. equals = memchr(s, '=', end_of_entry - s);
  131. if (!equals)
  132. goto error;
  133. /* The name must be nonempty */
  134. if (equals == s)
  135. goto error;
  136. out->name = tor_strndup(s, equals-s);
  137. tor_assert(equals < end_of_entry);
  138. s = equals + 1;
  139. while (s < end_of_entry) {
  140. const char *comma = memchr(s, ',', end_of_entry-s);
  141. proto_range_t *range = tor_malloc_zero(sizeof(proto_range_t));
  142. if (! comma)
  143. comma = end_of_entry;
  144. smartlist_add(out->ranges, range);
  145. if (parse_version_range(s, comma, &range->low, &range->high) < 0) {
  146. goto error;
  147. }
  148. if (range->low > range->high) {
  149. goto error;
  150. }
  151. s = comma;
  152. while (*s == ',' && s < end_of_entry)
  153. ++s;
  154. }
  155. return out;
  156. error:
  157. proto_entry_free(out);
  158. return NULL;
  159. }
  160. /**
  161. * Parse the protocol list from <b>s</b> and return it as a smartlist of
  162. * proto_entry_t
  163. */
  164. STATIC smartlist_t *
  165. parse_protocol_list(const char *s)
  166. {
  167. smartlist_t *entries = smartlist_new();
  168. while (*s) {
  169. /* Find the next space or the NUL. */
  170. const char *end_of_entry = strchr(s, ' ');
  171. proto_entry_t *entry;
  172. if (!end_of_entry)
  173. end_of_entry = s + strlen(s);
  174. entry = parse_single_entry(s, end_of_entry);
  175. if (! entry)
  176. goto error;
  177. smartlist_add(entries, entry);
  178. s = end_of_entry;
  179. while (*s == ' ')
  180. ++s;
  181. }
  182. return entries;
  183. error:
  184. SMARTLIST_FOREACH(entries, proto_entry_t *, ent, proto_entry_free(ent));
  185. smartlist_free(entries);
  186. return NULL;
  187. }
  188. /**
  189. * Given a protocol type and version number, return true iff we know
  190. * how to speak that protocol.
  191. */
  192. int
  193. protover_is_supported_here(protocol_type_t pr, uint32_t ver)
  194. {
  195. const smartlist_t *ours = get_supported_protocol_list();
  196. return protocol_list_contains(ours, pr, ver);
  197. }
  198. /**
  199. * Return true iff "list" encodes a protocol list that includes support for
  200. * the indicated protocol and version.
  201. */
  202. int
  203. protocol_list_supports_protocol(const char *list, protocol_type_t tp,
  204. uint32_t version)
  205. {
  206. /* NOTE: This is a pretty inefficient implementation. If it ever shows
  207. * up in profiles, we should memoize it.
  208. */
  209. smartlist_t *protocols = parse_protocol_list(list);
  210. if (!protocols) {
  211. return 0;
  212. }
  213. int contains = protocol_list_contains(protocols, tp, version);
  214. SMARTLIST_FOREACH(protocols, proto_entry_t *, ent, proto_entry_free(ent));
  215. smartlist_free(protocols);
  216. return contains;
  217. }
  218. /** Return the canonical string containing the list of protocols
  219. * that we support. */
  220. const char *
  221. get_supported_protocols(void)
  222. {
  223. return
  224. "Cons=1-2 "
  225. "Desc=1-2 "
  226. "DirCache=1 "
  227. "HSDir=1 "
  228. "HSMid=1 "
  229. "Link=1-4 "
  230. "LinkAuth=1 "
  231. "Microdesc=1-2 "
  232. "Relay=1-2";
  233. }
  234. /** The protocols from get_supported_protocols(), as parsed into a list of
  235. * proto_entry_t values. Access this via get_supported_protocol_list. */
  236. static smartlist_t *supported_protocol_list = NULL;
  237. /** Return a pointer to a smartlist of proto_entry_t for the protocols
  238. * we support. */
  239. static const smartlist_t *
  240. get_supported_protocol_list(void)
  241. {
  242. if (PREDICT_UNLIKELY(supported_protocol_list == NULL)) {
  243. supported_protocol_list = parse_protocol_list(get_supported_protocols());
  244. }
  245. return supported_protocol_list;
  246. }
  247. /**
  248. * Given a protocol entry, encode it at the end of the smartlist <b>chunks</b>
  249. * as one or more newly allocated strings.
  250. */
  251. static void
  252. proto_entry_encode_into(smartlist_t *chunks, const proto_entry_t *entry)
  253. {
  254. smartlist_add_asprintf(chunks, "%s=", entry->name);
  255. SMARTLIST_FOREACH_BEGIN(entry->ranges, proto_range_t *, range) {
  256. const char *comma = "";
  257. if (range_sl_idx != 0)
  258. comma = ",";
  259. if (range->low == range->high) {
  260. smartlist_add_asprintf(chunks, "%s%lu",
  261. comma, (unsigned long)range->low);
  262. } else {
  263. smartlist_add_asprintf(chunks, "%s%lu-%lu",
  264. comma, (unsigned long)range->low,
  265. (unsigned long)range->high);
  266. }
  267. } SMARTLIST_FOREACH_END(range);
  268. }
  269. /** Given a list of space-separated proto_entry_t items,
  270. * encode it into a newly allocated space-separated string. */
  271. STATIC char *
  272. encode_protocol_list(const smartlist_t *sl)
  273. {
  274. const char *separator = "";
  275. smartlist_t *chunks = smartlist_new();
  276. SMARTLIST_FOREACH_BEGIN(sl, const proto_entry_t *, ent) {
  277. smartlist_add(chunks, tor_strdup(separator));
  278. proto_entry_encode_into(chunks, ent);
  279. separator = " ";
  280. } SMARTLIST_FOREACH_END(ent);
  281. char *result = smartlist_join_strings(chunks, "", 0, NULL);
  282. SMARTLIST_FOREACH(chunks, char *, cp, tor_free(cp));
  283. smartlist_free(chunks);
  284. return result;
  285. }
  286. /** Voting helper: Given a list of proto_entry_t, return a newly allocated
  287. * smartlist of newly allocated strings, one for each included protocol
  288. * version. (So 'Foo=3,5-7' expands to a list of 'Foo=3', 'Foo=5', 'Foo=6',
  289. * 'Foo=7'.)
  290. *
  291. * Do not list any protocol version more than once. */
  292. static smartlist_t *
  293. expand_protocol_list(const smartlist_t *protos)
  294. {
  295. // XXXX This can make really huge lists from small inputs; that's a DoS
  296. // problem.
  297. smartlist_t *expanded = smartlist_new();
  298. if (!protos)
  299. return expanded;
  300. SMARTLIST_FOREACH_BEGIN(protos, const proto_entry_t *, ent) {
  301. const char *name = ent->name;
  302. SMARTLIST_FOREACH_BEGIN(ent->ranges, const proto_range_t *, range) {
  303. uint32_t u;
  304. for (u = range->low; u <= range->high; ++u) {
  305. smartlist_add_asprintf(expanded, "%s=%lu", name, (unsigned long)u);
  306. }
  307. } SMARTLIST_FOREACH_END(range);
  308. } SMARTLIST_FOREACH_END(ent);
  309. smartlist_sort_strings(expanded);
  310. smartlist_uniq_strings(expanded); // This makes voting work. do not remove
  311. return expanded;
  312. }
  313. /** Voting helper: compare two singleton proto_entry_t items by version
  314. * alone. (A singleton item is one with a single range entry where
  315. * low==high.) */
  316. static int
  317. cmp_single_ent_by_version(const void **a_, const void **b_)
  318. {
  319. const proto_entry_t *ent_a = *a_;
  320. const proto_entry_t *ent_b = *b_;
  321. tor_assert(smartlist_len(ent_a->ranges) == 1);
  322. tor_assert(smartlist_len(ent_b->ranges) == 1);
  323. const proto_range_t *a = smartlist_get(ent_a->ranges, 0);
  324. const proto_range_t *b = smartlist_get(ent_b->ranges, 0);
  325. tor_assert(a->low == a->high);
  326. tor_assert(b->low == b->high);
  327. if (a->low < b->low) {
  328. return -1;
  329. } else if (a->low == b->low) {
  330. return 0;
  331. } else {
  332. return 1;
  333. }
  334. }
  335. /** Voting helper: Given a list of singleton protocol strings (of the form
  336. * Foo=7), return a canonical listing of all the protocol versions listed,
  337. * with as few ranges as possible, with protocol versions sorted lexically and
  338. * versions sorted in numerically increasing order, using as few range entries
  339. * as possible.
  340. **/
  341. static char *
  342. contract_protocol_list(const smartlist_t *proto_strings)
  343. {
  344. // map from name to list of single-version entries
  345. strmap_t *entry_lists_by_name = strmap_new();
  346. // list of protocol names
  347. smartlist_t *all_names = smartlist_new();
  348. // list of strings for the output we're building
  349. smartlist_t *chunks = smartlist_new();
  350. // Parse each item and stick it entry_lists_by_name. Build
  351. // 'all_names' at the same time.
  352. SMARTLIST_FOREACH_BEGIN(proto_strings, const char *, s) {
  353. if (BUG(!s))
  354. continue;// LCOV_EXCL_LINE
  355. proto_entry_t *ent = parse_single_entry(s, s+strlen(s));
  356. if (BUG(!ent))
  357. continue; // LCOV_EXCL_LINE
  358. smartlist_t *lst = strmap_get(entry_lists_by_name, ent->name);
  359. if (!lst) {
  360. smartlist_add(all_names, ent->name);
  361. lst = smartlist_new();
  362. strmap_set(entry_lists_by_name, ent->name, lst);
  363. }
  364. smartlist_add(lst, ent);
  365. } SMARTLIST_FOREACH_END(s);
  366. // We want to output the protocols sorted by their name.
  367. smartlist_sort_strings(all_names);
  368. SMARTLIST_FOREACH_BEGIN(all_names, const char *, name) {
  369. const int first_entry = (name_sl_idx == 0);
  370. smartlist_t *lst = strmap_get(entry_lists_by_name, name);
  371. tor_assert(lst);
  372. // Sort every entry with this name by version. They are
  373. // singletons, so there can't be overlap.
  374. smartlist_sort(lst, cmp_single_ent_by_version);
  375. if (! first_entry)
  376. smartlist_add(chunks, tor_strdup(" "));
  377. /* We're going to construct this entry from the ranges. */
  378. proto_entry_t *entry = tor_malloc_zero(sizeof(proto_entry_t));
  379. entry->ranges = smartlist_new();
  380. entry->name = tor_strdup(name);
  381. // Now, find all the ranges of versions start..end where
  382. // all of start, start+1, start+2, ..end are included.
  383. int start_of_cur_series = 0;
  384. while (start_of_cur_series < smartlist_len(lst)) {
  385. const proto_entry_t *ent = smartlist_get(lst, start_of_cur_series);
  386. const proto_range_t *range = smartlist_get(ent->ranges, 0);
  387. const uint32_t ver_low = range->low;
  388. uint32_t ver_high = ver_low;
  389. int idx;
  390. for (idx = start_of_cur_series+1; idx < smartlist_len(lst); ++idx) {
  391. ent = smartlist_get(lst, idx);
  392. range = smartlist_get(ent->ranges, 0);
  393. if (range->low != ver_high + 1)
  394. break;
  395. ver_high += 1;
  396. }
  397. // Now idx is either off the end of the list, or the first sequence
  398. // break in the list.
  399. start_of_cur_series = idx;
  400. proto_range_t *new_range = tor_malloc_zero(sizeof(proto_range_t));
  401. new_range->low = ver_low;
  402. new_range->high = ver_high;
  403. smartlist_add(entry->ranges, new_range);
  404. }
  405. proto_entry_encode_into(chunks, entry);
  406. proto_entry_free(entry);
  407. } SMARTLIST_FOREACH_END(name);
  408. // Build the result...
  409. char *result = smartlist_join_strings(chunks, "", 0, NULL);
  410. // And free all the stuff we allocated.
  411. SMARTLIST_FOREACH_BEGIN(all_names, const char *, name) {
  412. smartlist_t *lst = strmap_get(entry_lists_by_name, name);
  413. tor_assert(lst);
  414. SMARTLIST_FOREACH(lst, proto_entry_t *, e, proto_entry_free(e));
  415. smartlist_free(lst);
  416. } SMARTLIST_FOREACH_END(name);
  417. strmap_free(entry_lists_by_name, NULL);
  418. smartlist_free(all_names);
  419. SMARTLIST_FOREACH(chunks, char *, cp, tor_free(cp));
  420. smartlist_free(chunks);
  421. return result;
  422. }
  423. /**
  424. * Protocol voting implementation.
  425. *
  426. * Given a list of strings describing protocol versions, return a newly
  427. * allocated string encoding all of the protocols that are listed by at
  428. * least <b>threshold</b> of the inputs.
  429. *
  430. * The string is minimal and sorted according to the rules of
  431. * contract_protocol_list above.
  432. */
  433. char *
  434. compute_protover_vote(const smartlist_t *list_of_proto_strings,
  435. int threshold)
  436. {
  437. // XXXX This algorithm can be made to use too much RAM. Fix that.
  438. smartlist_t *all_entries = smartlist_new();
  439. // First, parse the inputs and break them into singleton entries.
  440. SMARTLIST_FOREACH_BEGIN(list_of_proto_strings, const char *, vote) {
  441. smartlist_t *unexpanded = parse_protocol_list(vote);
  442. smartlist_t *this_vote = expand_protocol_list(unexpanded);
  443. smartlist_add_all(all_entries, this_vote);
  444. smartlist_free(this_vote);
  445. SMARTLIST_FOREACH(unexpanded, proto_entry_t *, e, proto_entry_free(e));
  446. smartlist_free(unexpanded);
  447. } SMARTLIST_FOREACH_END(vote);
  448. // Now sort the singleton entries
  449. smartlist_sort_strings(all_entries);
  450. // Now find all the strings that appear at least 'threshold' times.
  451. smartlist_t *include_entries = smartlist_new();
  452. const char *cur_entry = smartlist_get(all_entries, 0);
  453. int n_times = 0;
  454. SMARTLIST_FOREACH_BEGIN(all_entries, const char *, ent) {
  455. if (!strcmp(ent, cur_entry)) {
  456. n_times++;
  457. } else {
  458. if (n_times >= threshold && cur_entry)
  459. smartlist_add(include_entries, (void*)cur_entry);
  460. cur_entry = ent;
  461. n_times = 1 ;
  462. }
  463. } SMARTLIST_FOREACH_END(ent);
  464. if (n_times >= threshold && cur_entry)
  465. smartlist_add(include_entries, (void*)cur_entry);
  466. // Finally, compress that list.
  467. char *result = contract_protocol_list(include_entries);
  468. smartlist_free(include_entries);
  469. SMARTLIST_FOREACH(all_entries, char *, cp, tor_free(cp));
  470. smartlist_free(all_entries);
  471. return result;
  472. }
  473. /** Return true if every protocol version described in the string <b>s</b> is
  474. * one that we support, and false otherwise. If <b>missing_out</b> is
  475. * provided, set it to the list of protocols we do not support.
  476. *
  477. * NOTE: This is quadratic, but we don't do it much: only a few times per
  478. * consensus. Checking signatures should be way more expensive than this
  479. * ever would be.
  480. **/
  481. int
  482. protover_all_supported(const char *s, char **missing_out)
  483. {
  484. int all_supported = 1;
  485. smartlist_t *missing;
  486. if (!s) {
  487. return 1;
  488. }
  489. smartlist_t *entries = parse_protocol_list(s);
  490. missing = smartlist_new();
  491. SMARTLIST_FOREACH_BEGIN(entries, const proto_entry_t *, ent) {
  492. protocol_type_t tp;
  493. if (str_to_protocol_type(ent->name, &tp) < 0) {
  494. if (smartlist_len(ent->ranges)) {
  495. goto unsupported;
  496. }
  497. continue;
  498. }
  499. SMARTLIST_FOREACH_BEGIN(ent->ranges, const proto_range_t *, range) {
  500. uint32_t i;
  501. for (i = range->low; i <= range->high; ++i) {
  502. if (!protover_is_supported_here(tp, i)) {
  503. goto unsupported;
  504. }
  505. }
  506. } SMARTLIST_FOREACH_END(range);
  507. continue;
  508. unsupported:
  509. all_supported = 0;
  510. smartlist_add(missing, (void*) ent);
  511. } SMARTLIST_FOREACH_END(ent);
  512. if (missing_out && !all_supported) {
  513. tor_assert(0 != smartlist_len(missing));
  514. *missing_out = encode_protocol_list(missing);
  515. }
  516. smartlist_free(missing);
  517. SMARTLIST_FOREACH(entries, proto_entry_t *, ent, proto_entry_free(ent));
  518. smartlist_free(entries);
  519. return all_supported;
  520. }
  521. static int
  522. protocol_list_contains(const smartlist_t *protos,
  523. protocol_type_t pr, uint32_t ver)
  524. {
  525. if (BUG(protos == NULL)) {
  526. return 0; // LCOV_EXCL_LINE
  527. }
  528. const char *pr_name = protocol_type_to_str(pr);
  529. if (BUG(pr_name == NULL)) {
  530. return 0; // LCOV_EXCL_LINE
  531. }
  532. SMARTLIST_FOREACH_BEGIN(protos, const proto_entry_t *, ent) {
  533. if (strcasecmp(ent->name, pr_name))
  534. continue;
  535. /* name matches; check the ranges */
  536. SMARTLIST_FOREACH_BEGIN(ent->ranges, const proto_range_t *, range) {
  537. if (ver >= range->low && ver <= range->high)
  538. return 1;
  539. } SMARTLIST_FOREACH_END(range);
  540. } SMARTLIST_FOREACH_END(ent);
  541. return 0;
  542. }
  543. /** Return a string describing the protocols supported by tor version
  544. * <b>version</b>, or an empty string if we cannot tell.
  545. *
  546. * Note that this is only used to infer protocols for Tor versions that
  547. * can't declare their own.
  548. **/
  549. const char *
  550. protover_compute_for_old_tor(const char *version)
  551. {
  552. if (tor_version_as_new_as(version,
  553. FIRST_TOR_VERSION_TO_ADVERTISE_PROTOCOLS)) {
  554. return "";
  555. } else if (tor_version_as_new_as(version, "0.2.7.5")) {
  556. /* 0.2.7-stable added Desc=2, Microdesc=2, Cons=2, which indicate
  557. * ed25519 support. We'll call them present only in "stable" 027,
  558. * though. */
  559. return "Cons=1-2 Desc=1-2 DirCache=1 HSDir=1 HSMid=1 Link=1-4 LinkAuth=1 "
  560. "Microdesc=1-2 Relay=1-2";
  561. } else if (tor_version_as_new_as(version, "0.2.4.19")) {
  562. /* No currently supported Tor server versions are older than this, or
  563. * lack these protocols. */
  564. return "Cons=1 Desc=1 DirCache=1 HSDir=1 HSMid=1 Link=1-4 LinkAuth=1 "
  565. "Microdesc=1 Relay=1-2";
  566. } else {
  567. /* Cannot infer protocols. */
  568. return "";
  569. }
  570. }
  571. void
  572. protover_free_all(void)
  573. {
  574. if (supported_protocol_list) {
  575. smartlist_t *entries = supported_protocol_list;
  576. SMARTLIST_FOREACH(entries, proto_entry_t *, ent, proto_entry_free(ent));
  577. smartlist_free(entries);
  578. supported_protocol_list = NULL;
  579. }
  580. }