hs_cache.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  1. /* Copyright (c) 2016-2017, The Tor Project, Inc. */
  2. /* See LICENSE for licensing information */
  3. /**
  4. * \file hs_cache.c
  5. * \brief Handle hidden service descriptor caches.
  6. **/
  7. /* For unit tests.*/
  8. #define HS_CACHE_PRIVATE
  9. #include "or.h"
  10. #include "config.h"
  11. #include "hs_ident.h"
  12. #include "hs_common.h"
  13. #include "hs_client.h"
  14. #include "hs_descriptor.h"
  15. #include "networkstatus.h"
  16. #include "rendcache.h"
  17. #include "hs_cache.h"
  18. /********************** Directory HS cache ******************/
  19. /* Directory descriptor cache. Map indexed by blinded key. */
  20. static digest256map_t *hs_cache_v3_dir;
  21. /* Remove a given descriptor from our cache. */
  22. static void
  23. remove_v3_desc_as_dir(const hs_cache_dir_descriptor_t *desc)
  24. {
  25. tor_assert(desc);
  26. digest256map_remove(hs_cache_v3_dir, desc->key);
  27. }
  28. /* Store a given descriptor in our cache. */
  29. static void
  30. store_v3_desc_as_dir(hs_cache_dir_descriptor_t *desc)
  31. {
  32. tor_assert(desc);
  33. digest256map_set(hs_cache_v3_dir, desc->key, desc);
  34. }
  35. /* Query our cache and return the entry or NULL if not found. */
  36. static hs_cache_dir_descriptor_t *
  37. lookup_v3_desc_as_dir(const uint8_t *key)
  38. {
  39. tor_assert(key);
  40. return digest256map_get(hs_cache_v3_dir, key);
  41. }
  42. /* Free a directory descriptor object. */
  43. static void
  44. cache_dir_desc_free(hs_cache_dir_descriptor_t *desc)
  45. {
  46. if (desc == NULL) {
  47. return;
  48. }
  49. hs_desc_plaintext_data_free(desc->plaintext_data);
  50. tor_free(desc->encoded_desc);
  51. tor_free(desc);
  52. }
  53. /* Helper function: Use by the free all function using the digest256map
  54. * interface to cache entries. */
  55. static void
  56. cache_dir_desc_free_(void *ptr)
  57. {
  58. hs_cache_dir_descriptor_t *desc = ptr;
  59. cache_dir_desc_free(desc);
  60. }
  61. /* Create a new directory cache descriptor object from a encoded descriptor.
  62. * On success, return the heap-allocated cache object, otherwise return NULL if
  63. * we can't decode the descriptor. */
  64. static hs_cache_dir_descriptor_t *
  65. cache_dir_desc_new(const char *desc)
  66. {
  67. hs_cache_dir_descriptor_t *dir_desc;
  68. tor_assert(desc);
  69. dir_desc = tor_malloc_zero(sizeof(hs_cache_dir_descriptor_t));
  70. dir_desc->plaintext_data =
  71. tor_malloc_zero(sizeof(hs_desc_plaintext_data_t));
  72. dir_desc->encoded_desc = tor_strdup(desc);
  73. if (hs_desc_decode_plaintext(desc, dir_desc->plaintext_data) < 0) {
  74. log_debug(LD_DIR, "Unable to decode descriptor. Rejecting.");
  75. goto err;
  76. }
  77. /* The blinded pubkey is the indexed key. */
  78. dir_desc->key = dir_desc->plaintext_data->blinded_pubkey.pubkey;
  79. dir_desc->created_ts = time(NULL);
  80. return dir_desc;
  81. err:
  82. cache_dir_desc_free(dir_desc);
  83. return NULL;
  84. }
  85. /* Return the size of a cache entry in bytes. */
  86. static size_t
  87. cache_get_dir_entry_size(const hs_cache_dir_descriptor_t *entry)
  88. {
  89. return (sizeof(*entry) + hs_desc_plaintext_obj_size(entry->plaintext_data)
  90. + strlen(entry->encoded_desc));
  91. }
  92. /* Try to store a valid version 3 descriptor in the directory cache. Return 0
  93. * on success else a negative value is returned indicating that we have a
  94. * newer version in our cache. On error, caller is responsible to free the
  95. * given descriptor desc. */
  96. static int
  97. cache_store_v3_as_dir(hs_cache_dir_descriptor_t *desc)
  98. {
  99. hs_cache_dir_descriptor_t *cache_entry;
  100. tor_assert(desc);
  101. /* Verify if we have an entry in the cache for that key and if yes, check
  102. * if we should replace it? */
  103. cache_entry = lookup_v3_desc_as_dir(desc->key);
  104. if (cache_entry != NULL) {
  105. /* Only replace descriptor if revision-counter is greater than the one
  106. * in our cache */
  107. if (cache_entry->plaintext_data->revision_counter >=
  108. desc->plaintext_data->revision_counter) {
  109. log_info(LD_REND, "Descriptor revision counter in our cache is "
  110. "greater or equal than the one we received (%d/%d). "
  111. "Rejecting!",
  112. (int)cache_entry->plaintext_data->revision_counter,
  113. (int)desc->plaintext_data->revision_counter);
  114. goto err;
  115. }
  116. /* We now know that the descriptor we just received is a new one so
  117. * remove the entry we currently have from our cache so we can then
  118. * store the new one. */
  119. remove_v3_desc_as_dir(cache_entry);
  120. rend_cache_decrement_allocation(cache_get_dir_entry_size(cache_entry));
  121. cache_dir_desc_free(cache_entry);
  122. }
  123. /* Store the descriptor we just got. We are sure here that either we
  124. * don't have the entry or we have a newer descriptor and the old one
  125. * has been removed from the cache. */
  126. store_v3_desc_as_dir(desc);
  127. /* Update our total cache size with this entry for the OOM. This uses the
  128. * old HS protocol cache subsystem for which we are tied with. */
  129. rend_cache_increment_allocation(cache_get_dir_entry_size(desc));
  130. /* XXX: Update HS statistics. We should have specific stats for v3. */
  131. return 0;
  132. err:
  133. return -1;
  134. }
  135. /* Using the query which is the base64 encoded blinded key of a version 3
  136. * descriptor, lookup in our directory cache the entry. If found, 1 is
  137. * returned and desc_out is populated with a newly allocated string being the
  138. * encoded descriptor. If not found, 0 is returned and desc_out is untouched.
  139. * On error, a negative value is returned and desc_out is untouched. */
  140. static int
  141. cache_lookup_v3_as_dir(const char *query, const char **desc_out)
  142. {
  143. int found = 0;
  144. ed25519_public_key_t blinded_key;
  145. const hs_cache_dir_descriptor_t *entry;
  146. tor_assert(query);
  147. /* Decode blinded key using the given query value. */
  148. if (ed25519_public_from_base64(&blinded_key, query) < 0) {
  149. log_info(LD_REND, "Unable to decode the v3 HSDir query %s.",
  150. safe_str_client(query));
  151. goto err;
  152. }
  153. entry = lookup_v3_desc_as_dir(blinded_key.pubkey);
  154. if (entry != NULL) {
  155. found = 1;
  156. if (desc_out) {
  157. *desc_out = entry->encoded_desc;
  158. }
  159. }
  160. return found;
  161. err:
  162. return -1;
  163. }
  164. /* Clean the v3 cache by removing any entry that has expired using the
  165. * <b>global_cutoff</b> value. If <b>global_cutoff</b> is 0, the cleaning
  166. * process will use the lifetime found in the plaintext data section. Return
  167. * the number of bytes cleaned. */
  168. STATIC size_t
  169. cache_clean_v3_as_dir(time_t now, time_t global_cutoff)
  170. {
  171. size_t bytes_removed = 0;
  172. /* Code flow error if this ever happens. */
  173. tor_assert(global_cutoff >= 0);
  174. if (!hs_cache_v3_dir) { /* No cache to clean. Just return. */
  175. return 0;
  176. }
  177. DIGEST256MAP_FOREACH_MODIFY(hs_cache_v3_dir, key,
  178. hs_cache_dir_descriptor_t *, entry) {
  179. size_t entry_size;
  180. time_t cutoff = global_cutoff;
  181. if (!cutoff) {
  182. /* Cutoff is the lifetime of the entry found in the descriptor. */
  183. cutoff = now - entry->plaintext_data->lifetime_sec;
  184. }
  185. /* If the entry has been created _after_ the cutoff, not expired so
  186. * continue to the next entry in our v3 cache. */
  187. if (entry->created_ts > cutoff) {
  188. continue;
  189. }
  190. /* Here, our entry has expired, remove and free. */
  191. MAP_DEL_CURRENT(key);
  192. entry_size = cache_get_dir_entry_size(entry);
  193. bytes_removed += entry_size;
  194. /* Entry is not in the cache anymore, destroy it. */
  195. cache_dir_desc_free(entry);
  196. /* Update our cache entry allocation size for the OOM. */
  197. rend_cache_decrement_allocation(entry_size);
  198. /* Logging. */
  199. {
  200. char key_b64[BASE64_DIGEST256_LEN + 1];
  201. base64_encode(key_b64, sizeof(key_b64), (const char *) key,
  202. DIGEST256_LEN, 0);
  203. log_info(LD_REND, "Removing v3 descriptor '%s' from HSDir cache",
  204. safe_str_client(key_b64));
  205. }
  206. } DIGEST256MAP_FOREACH_END;
  207. return bytes_removed;
  208. }
  209. /* Given an encoded descriptor, store it in the directory cache depending on
  210. * which version it is. Return a negative value on error. On success, 0 is
  211. * returned. */
  212. int
  213. hs_cache_store_as_dir(const char *desc)
  214. {
  215. hs_cache_dir_descriptor_t *dir_desc = NULL;
  216. tor_assert(desc);
  217. /* Create a new cache object. This can fail if the descriptor plaintext data
  218. * is unparseable which in this case a log message will be triggered. */
  219. dir_desc = cache_dir_desc_new(desc);
  220. if (dir_desc == NULL) {
  221. goto err;
  222. }
  223. /* Call the right function against the descriptor version. At this point,
  224. * we are sure that the descriptor's version is supported else the
  225. * decoding would have failed. */
  226. switch (dir_desc->plaintext_data->version) {
  227. case HS_VERSION_THREE:
  228. default:
  229. if (cache_store_v3_as_dir(dir_desc) < 0) {
  230. goto err;
  231. }
  232. break;
  233. }
  234. return 0;
  235. err:
  236. cache_dir_desc_free(dir_desc);
  237. return -1;
  238. }
  239. /* Using the query, lookup in our directory cache the entry. If found, 1 is
  240. * returned and desc_out is populated with a newly allocated string being
  241. * the encoded descriptor. If not found, 0 is returned and desc_out is
  242. * untouched. On error, a negative value is returned and desc_out is
  243. * untouched. */
  244. int
  245. hs_cache_lookup_as_dir(uint32_t version, const char *query,
  246. const char **desc_out)
  247. {
  248. int found;
  249. tor_assert(query);
  250. /* This should never be called with an unsupported version. */
  251. tor_assert(hs_desc_is_supported_version(version));
  252. switch (version) {
  253. case HS_VERSION_THREE:
  254. default:
  255. found = cache_lookup_v3_as_dir(query, desc_out);
  256. break;
  257. }
  258. return found;
  259. }
  260. /* Clean all directory caches using the current time now. */
  261. void
  262. hs_cache_clean_as_dir(time_t now)
  263. {
  264. time_t cutoff;
  265. /* Start with v2 cache cleaning. */
  266. cutoff = now - rend_cache_max_entry_lifetime();
  267. rend_cache_clean_v2_descs_as_dir(cutoff);
  268. /* Now, clean the v3 cache. Set the cutoff to 0 telling the cleanup function
  269. * to compute the cutoff by itself using the lifetime value. */
  270. cache_clean_v3_as_dir(now, 0);
  271. }
  272. /********************** Client-side HS cache ******************/
  273. /* Client-side HS descriptor cache. Map indexed by service identity key. */
  274. static digest256map_t *hs_cache_v3_client;
  275. /* Remove a given descriptor from our cache. */
  276. static void
  277. remove_v3_desc_as_client(const hs_cache_client_descriptor_t *desc)
  278. {
  279. tor_assert(desc);
  280. digest256map_remove(hs_cache_v3_client, desc->key.pubkey);
  281. }
  282. /* Store a given descriptor in our cache. */
  283. static void
  284. store_v3_desc_as_client(hs_cache_client_descriptor_t *desc)
  285. {
  286. tor_assert(desc);
  287. digest256map_set(hs_cache_v3_client, desc->key.pubkey, desc);
  288. }
  289. /* Query our cache and return the entry or NULL if not found. */
  290. STATIC hs_cache_client_descriptor_t *
  291. lookup_v3_desc_as_client(const uint8_t *key)
  292. {
  293. tor_assert(key);
  294. return digest256map_get(hs_cache_v3_client, key);
  295. }
  296. /* Return the size of a client cache entry in bytes. */
  297. static size_t
  298. cache_get_client_entry_size(const hs_cache_client_descriptor_t *entry)
  299. {
  300. return sizeof(*entry) +
  301. strlen(entry->encoded_desc) + hs_desc_obj_size(entry->desc);
  302. }
  303. /* Parse the encoded descriptor in <b>desc_str</b> using
  304. * <b>service_identity_pk<b> to decrypt it first.
  305. *
  306. * If everything goes well, allocate and return a new
  307. * hs_cache_client_descriptor_t object. In case of error, return NULL. */
  308. static hs_cache_client_descriptor_t *
  309. cache_client_desc_new(const char *desc_str,
  310. const ed25519_public_key_t *service_identity_pk)
  311. {
  312. hs_descriptor_t *desc = NULL;
  313. hs_cache_client_descriptor_t *client_desc = NULL;
  314. tor_assert(desc_str);
  315. tor_assert(service_identity_pk);
  316. /* Decode the descriptor we just fetched. */
  317. if (hs_client_decode_descriptor(desc_str, service_identity_pk, &desc) < 0) {
  318. goto end;
  319. }
  320. tor_assert(desc);
  321. /* All is good: make a cache object for this descriptor */
  322. client_desc = tor_malloc_zero(sizeof(hs_cache_client_descriptor_t));
  323. ed25519_pubkey_copy(&client_desc->key, service_identity_pk);
  324. client_desc->created_ts = approx_time();
  325. client_desc->desc = desc;
  326. client_desc->encoded_desc = tor_strdup(desc_str);
  327. end:
  328. return client_desc;
  329. }
  330. /** Free memory allocated by <b>desc</b>. */
  331. static void
  332. cache_client_desc_free(hs_cache_client_descriptor_t *desc)
  333. {
  334. if (desc == NULL) {
  335. return;
  336. }
  337. hs_descriptor_free(desc->desc);
  338. memwipe(&desc->key, 0, sizeof(desc->key));
  339. memwipe(desc->encoded_desc, 0, strlen(desc->encoded_desc));
  340. tor_free(desc->encoded_desc);
  341. tor_free(desc);
  342. }
  343. /** Helper function: Use by the free all function to clear the client cache */
  344. static void
  345. cache_client_desc_free_(void *ptr)
  346. {
  347. hs_cache_client_descriptor_t *desc = ptr;
  348. cache_client_desc_free(desc);
  349. }
  350. /** Check whether <b>client_desc</b> is useful for us, and store it in the
  351. * client-side HS cache if so. The client_desc is freed if we already have a
  352. * fresher (higher revision counter count) in the cache. */
  353. static int
  354. cache_store_as_client(hs_cache_client_descriptor_t *client_desc)
  355. {
  356. hs_cache_client_descriptor_t *cache_entry;
  357. /* TODO: Heavy code duplication with cache_store_as_dir(). Consider
  358. * refactoring and uniting! */
  359. tor_assert(client_desc);
  360. /* Check if we already have a descriptor from this HS in cache. If we do,
  361. * check if this descriptor is newer than the cached one */
  362. cache_entry = lookup_v3_desc_as_client(client_desc->key.pubkey);
  363. if (cache_entry != NULL) {
  364. /* If we have an entry in our cache that has a revision counter greater
  365. * than the one we just fetched, discard the one we fetched. */
  366. if (cache_entry->desc->plaintext_data.revision_counter >
  367. client_desc->desc->plaintext_data.revision_counter) {
  368. log_info(LD_REND, "We already have fresher descriptor. Ignoring.");
  369. cache_client_desc_free(client_desc);
  370. goto done;
  371. }
  372. /* Remove old entry. Make space for the new one! */
  373. remove_v3_desc_as_client(cache_entry);
  374. rend_cache_decrement_allocation(cache_get_client_entry_size(cache_entry));
  375. cache_client_desc_free(cache_entry);
  376. }
  377. /* Store descriptor in cache */
  378. store_v3_desc_as_client(client_desc);
  379. /* Update cache size with this entry for the OOM handler. */
  380. rend_cache_increment_allocation(cache_get_client_entry_size(client_desc));
  381. done:
  382. return 0;
  383. }
  384. /* Clean the client cache using now as the current time. Return the total size
  385. * of removed bytes from the cache. */
  386. static size_t
  387. cache_clean_v3_as_client(time_t now)
  388. {
  389. size_t bytes_removed = 0;
  390. if (!hs_cache_v3_client) { /* No cache to clean. Just return. */
  391. return 0;
  392. }
  393. DIGEST256MAP_FOREACH_MODIFY(hs_cache_v3_client, key,
  394. hs_cache_client_descriptor_t *, entry) {
  395. size_t entry_size;
  396. time_t cutoff = now - rend_cache_max_entry_lifetime();
  397. /* If the entry has been created _after_ the cutoff, not expired so
  398. * continue to the next entry in our v3 cache. */
  399. if (entry->created_ts > cutoff) {
  400. continue;
  401. }
  402. /* Here, our entry has expired, remove and free. */
  403. MAP_DEL_CURRENT(key);
  404. entry_size = cache_get_client_entry_size(entry);
  405. bytes_removed += entry_size;
  406. /* Entry is not in the cache anymore, destroy it. */
  407. cache_client_desc_free(entry);
  408. /* Update our cache entry allocation size for the OOM. */
  409. rend_cache_decrement_allocation(entry_size);
  410. /* Logging. */
  411. {
  412. char key_b64[BASE64_DIGEST256_LEN + 1];
  413. base64_encode(key_b64, sizeof(key_b64), (const char *) key,
  414. DIGEST256_LEN, 0);
  415. log_info(LD_REND, "Removing hidden service v3 descriptor '%s' "
  416. "from client cache",
  417. safe_str_client(key_b64));
  418. }
  419. } DIGEST256MAP_FOREACH_END;
  420. return bytes_removed;
  421. }
  422. /** Public API: Given the HS ed25519 identity public key in <b>key</b>, return
  423. * its HS descriptor if it's stored in our cache, or NULL if not. */
  424. const hs_descriptor_t *
  425. hs_cache_lookup_as_client(const ed25519_public_key_t *key)
  426. {
  427. hs_cache_client_descriptor_t *cached_desc = NULL;
  428. tor_assert(key);
  429. cached_desc = lookup_v3_desc_as_client(key->pubkey);
  430. if (cached_desc) {
  431. tor_assert(cached_desc->desc);
  432. return cached_desc->desc;
  433. }
  434. return NULL;
  435. }
  436. /** Public API: Given an encoded descriptor, store it in the client HS
  437. * cache. Return -1 on error, 0 on success .*/
  438. int
  439. hs_cache_store_as_client(const char *desc_str,
  440. const ed25519_public_key_t *identity_pk)
  441. {
  442. hs_cache_client_descriptor_t *client_desc = NULL;
  443. tor_assert(desc_str);
  444. tor_assert(identity_pk);
  445. /* Create client cache descriptor object */
  446. client_desc = cache_client_desc_new(desc_str, identity_pk);
  447. if (!client_desc) {
  448. log_warn(LD_GENERAL, "Failed to parse received descriptor %s.",
  449. escaped(desc_str));
  450. goto err;
  451. }
  452. /* Push it to the cache */
  453. if (cache_store_as_client(client_desc) < 0) {
  454. goto err;
  455. }
  456. return 0;
  457. err:
  458. cache_client_desc_free(client_desc);
  459. return -1;
  460. }
  461. /* Clean all client caches using the current time now. */
  462. void
  463. hs_cache_clean_as_client(time_t now)
  464. {
  465. /* Start with v2 cache cleaning. */
  466. rend_cache_clean(now, REND_CACHE_TYPE_CLIENT);
  467. /* Now, clean the v3 cache. Set the cutoff to 0 telling the cleanup function
  468. * to compute the cutoff by itself using the lifetime value. */
  469. cache_clean_v3_as_client(now);
  470. }
  471. /**************** Generics *********************************/
  472. /* Do a round of OOM cleanup on all directory caches. Return the amount of
  473. * removed bytes. It is possible that the returned value is lower than
  474. * min_remove_bytes if the caches get emptied out so the caller should be
  475. * aware of this. */
  476. size_t
  477. hs_cache_handle_oom(time_t now, size_t min_remove_bytes)
  478. {
  479. time_t k;
  480. size_t bytes_removed = 0;
  481. /* Our OOM handler called with 0 bytes to remove is a code flow error. */
  482. tor_assert(min_remove_bytes != 0);
  483. /* The algorithm is as follow. K is the oldest expected descriptor age.
  484. *
  485. * 1) Deallocate all entries from v2 cache that are older than K hours.
  486. * 1.1) If the amount of remove bytes has been reached, stop.
  487. * 2) Deallocate all entries from v3 cache that are older than K hours
  488. * 2.1) If the amount of remove bytes has been reached, stop.
  489. * 3) Set K = K - RendPostPeriod and repeat process until K is < 0.
  490. *
  491. * This ends up being O(Kn).
  492. */
  493. /* Set K to the oldest expected age in seconds which is the maximum
  494. * lifetime of a cache entry. We'll use the v2 lifetime because it's much
  495. * bigger than the v3 thus leading to cleaning older descriptors. */
  496. k = rend_cache_max_entry_lifetime();
  497. do {
  498. time_t cutoff;
  499. /* If K becomes negative, it means we've empty the caches so stop and
  500. * return what we were able to cleanup. */
  501. if (k < 0) {
  502. break;
  503. }
  504. /* Compute a cutoff value with K and the current time. */
  505. cutoff = now - k;
  506. /* Start by cleaning the v2 cache with that cutoff. */
  507. bytes_removed += rend_cache_clean_v2_descs_as_dir(cutoff);
  508. if (bytes_removed < min_remove_bytes) {
  509. /* We haven't remove enough bytes so clean v3 cache. */
  510. bytes_removed += cache_clean_v3_as_dir(now, cutoff);
  511. /* Decrement K by a post period to shorten the cutoff. */
  512. k -= get_options()->RendPostPeriod;
  513. }
  514. } while (bytes_removed < min_remove_bytes);
  515. return bytes_removed;
  516. }
  517. /* Return the maximum size of a v3 HS descriptor. */
  518. unsigned int
  519. hs_cache_get_max_descriptor_size(void)
  520. {
  521. return (unsigned) networkstatus_get_param(NULL,
  522. "HSV3MaxDescriptorSize",
  523. HS_DESC_MAX_LEN, 1, INT32_MAX);
  524. }
  525. /* Initialize the hidden service cache subsystem. */
  526. void
  527. hs_cache_init(void)
  528. {
  529. /* Calling this twice is very wrong code flow. */
  530. tor_assert(!hs_cache_v3_dir);
  531. hs_cache_v3_dir = digest256map_new();
  532. tor_assert(!hs_cache_v3_client);
  533. hs_cache_v3_client = digest256map_new();
  534. }
  535. /* Cleanup the hidden service cache subsystem. */
  536. void
  537. hs_cache_free_all(void)
  538. {
  539. digest256map_free(hs_cache_v3_dir, cache_dir_desc_free_);
  540. hs_cache_v3_dir = NULL;
  541. digest256map_free(hs_cache_v3_client, cache_client_desc_free_);
  542. hs_cache_v3_client = NULL;
  543. }