rendcommon.h 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /* Copyright (c) 2001 Matej Pfajfar.
  2. * Copyright (c) 2001-2004, Roger Dingledine.
  3. * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
  4. * Copyright (c) 2007-2015, The Tor Project, Inc. */
  5. /* See LICENSE for licensing information */
  6. /**
  7. * \file rendcommon.h
  8. * \brief Header file for rendcommon.c.
  9. **/
  10. #ifndef TOR_RENDCOMMON_H
  11. #define TOR_RENDCOMMON_H
  12. #include "rendcache.h"
  13. /** Free all storage associated with <b>data</b> */
  14. static INLINE void
  15. rend_data_free(rend_data_t *data)
  16. {
  17. if (!data) {
  18. return;
  19. }
  20. /* Cleanup the HSDir identity digest. */
  21. SMARTLIST_FOREACH(data->hsdirs_fp, char *, d, tor_free(d));
  22. smartlist_free(data->hsdirs_fp);
  23. tor_free(data);
  24. }
  25. int rend_cmp_service_ids(const char *one, const char *two);
  26. void rend_process_relay_cell(circuit_t *circ, const crypt_path_t *layer_hint,
  27. int command, size_t length,
  28. const uint8_t *payload);
  29. void rend_service_descriptor_free(rend_service_descriptor_t *desc);
  30. int rend_get_service_id(crypto_pk_t *pk, char *out);
  31. void rend_encoded_v2_service_descriptor_free(
  32. rend_encoded_v2_service_descriptor_t *desc);
  33. void rend_intro_point_free(rend_intro_point_t *intro);
  34. void rend_cache_init(void);
  35. void rend_cache_clean(time_t now);
  36. void rend_cache_clean_v2_descs_as_dir(time_t now, size_t min_to_remove);
  37. void rend_cache_purge(void);
  38. void rend_cache_free_all(void);
  39. int rend_valid_service_id(const char *query);
  40. int rend_valid_descriptor_id(const char *query);
  41. int rend_cache_lookup_entry(const char *query, int version,
  42. rend_cache_entry_t **entry_out);
  43. int rend_cache_lookup_v2_desc_as_dir(const char *query, const char **desc);
  44. /** Return value from rend_cache_store_v2_desc_as_{dir,client}. */
  45. typedef enum {
  46. RCS_NOTDIR = -2, /**< We're not a directory */
  47. RCS_BADDESC = -1, /**< This descriptor is no good. */
  48. RCS_OKAY = 0 /**< All worked as expected */
  49. } rend_cache_store_status_t;
  50. rend_cache_store_status_t rend_cache_store_v2_desc_as_dir(const char *desc);
  51. rend_cache_store_status_t rend_cache_store_v2_desc_as_client(const char *desc,
  52. const char *desc_id_base32,
  53. const rend_data_t *rend_query,
  54. rend_cache_entry_t **entry);
  55. int rend_encode_v2_descriptors(smartlist_t *descs_out,
  56. rend_service_descriptor_t *desc, time_t now,
  57. uint8_t period, rend_auth_type_t auth_type,
  58. crypto_pk_t *client_key,
  59. smartlist_t *client_cookies);
  60. int rend_compute_v2_desc_id(char *desc_id_out, const char *service_id,
  61. const char *descriptor_cookie,
  62. time_t now, uint8_t replica);
  63. int rend_id_is_in_interval(const char *a, const char *b, const char *c);
  64. void rend_get_descriptor_id_bytes(char *descriptor_id_out,
  65. const char *service_id,
  66. const char *secret_id_part);
  67. size_t rend_cache_get_total_allocation(void);
  68. rend_data_t *rend_data_dup(const rend_data_t *data);
  69. rend_data_t *rend_data_client_create(const char *onion_address,
  70. const char *desc_id,
  71. const char *cookie,
  72. rend_auth_type_t auth_type);
  73. rend_data_t *rend_data_service_create(const char *onion_address,
  74. const char *pk_digest,
  75. const uint8_t *cookie,
  76. rend_auth_type_t auth_type);
  77. #endif