rehash_service.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /* GNU Guix --- Functional package management for GNU
  2. Copyright © 2020 Maxime Devos <maxime.devos@student.kuleuven.be>
  3. This file is part of GNU Guix.
  4. GNU Guix is free software; you can redistribute it and/or modify it
  5. under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or (at
  7. your option) any later version.
  8. GNU Guix is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. */
  14. /**
  15. * @author Maxime Devos
  16. *
  17. * @file
  18. * Save hash->hash mappings in the data store
  19. * API that can be used to store hash -> hash mappings on a GNUnet node.
  20. * It is backed by the data store.
  21. */
  22. #ifndef GNUNET_REHASH_SERVICE_H
  23. #define GNUNET_REHASH_SERVICE_H
  24. #include <gnunet/gnunet_fs_service.h>
  25. #include "rehash_types.h"
  26. #ifdef __cplusplus
  27. extern "C"
  28. {
  29. #if 0
  30. }
  31. #endif
  32. #endif
  33. /**
  34. * Context to control hash->hash searches.
  35. */
  36. struct GNUNET_REHASH_QueryContext;
  37. /**
  38. * Context to control hash->hash inserts.
  39. */
  40. struct GNUNET_REHASH_StoreContext;
  41. /* TODO: perhaps some monitoring
  42. and enumeration? */
  43. /**
  44. * Handle to the rehash service.
  45. */
  46. struct GNUNET_REHASH_Handle;
  47. /**
  48. * Connect to the rehash service.
  49. *
  50. * @param cfg configuration to use
  51. * @return handle to use to access the service
  52. */
  53. struct GNUNET_REHASH_Handle *
  54. GNUNET_REHASH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
  55. /**
  56. * Disconnect from the rehash service.
  57. *
  58. * @param h handle to the rehash service
  59. */
  60. void
  61. GNUNET_REHASH_disconnect (struct GNUNET_REHASH_Handle *h);
  62. /**
  63. * Callback to call when a hash->hash mapping has been inserted.
  64. *
  65. * @param cls closure
  66. */
  67. typedef void
  68. (*GNUNET_REHASH_StoreContinuation) (void *cls);
  69. /**
  70. * Where has the hash->hash mapping been found?
  71. * More locations may be defined later.
  72. * TODO is this useful?
  73. */
  74. enum GNUNET_REHASH_Origin
  75. {
  76. GNUNET_REHASH_ORIGIN_DHT = 0,
  77. GNUNET_REHASH_ORIGIN_DATASTORE = 1,
  78. };
  79. /**
  80. * Callback to call when a hash->hash mapping has been found
  81. *
  82. * The found hash may have a bogus for its type.
  83. *
  84. * @param cls closure
  85. * @param exp when will this value expire
  86. * @param origin where has this mapping been found
  87. * @param out_length size of @a out_hash
  88. * @param out_hash hash found
  89. */
  90. typedef void
  91. (*GNUNET_REHASH_QueryContinuation) (void *cls,
  92. struct GNUNET_TIME_Absolute exp,
  93. enum GNUNET_REHASH_Origin origin,
  94. size_t out_length,
  95. const char *out_hash);
  96. /**
  97. * Store an hash->hash mapping into the data store
  98. * (and DHT, anonymity permitting), to be shared with
  99. * other peers. If the entry is already present, the old
  100. * entry is considered faulty and is replaced with the
  101. * new mapping.
  102. *
  103. * TODO: memory cont? When may StoreContext be freed?
  104. * How?
  105. *
  106. * @param h handle to the rehash store
  107. * @param options anonymity, replication, ... options
  108. * @param in_type type of hash to query with
  109. * @param out_type type of hash to search for
  110. * @param input hash to search with
  111. * @param input_length length of @a input_hash
  112. * @param output hash to find
  113. * @param output_length length of @a output_hash
  114. * @param cont continuation to call when done
  115. * @param cont_cls closure for @a cont
  116. * @return handle to abort the request
  117. */
  118. struct GNUNET_REHASH_StoreContext *
  119. GNUNET_REHASH_store_start (struct GNUNET_REHASH_Handle *h,
  120. const struct GNUNET_FS_BlockOptions *options,
  121. enum GNUNET_REHASH_Hash_Type in_type,
  122. enum GNUNET_REHASH_Hash_Type out_type,
  123. const char *input,
  124. size_t input_length,
  125. const char *output,
  126. size_t output_length,
  127. GNUNET_REHASH_StoreContinuation cont,
  128. void *cls);
  129. /**
  130. * Search for hash->hash mappings.
  131. *
  132. * @param h handle to rehash service
  133. * @param options only the flag LOOPBACK_ONLY is supported
  134. * @param anonymity desired anonymity level
  135. * @param in_type type of hash to query with
  136. * @param out_type type of hash to search for
  137. * @param input hash to search with
  138. * @param input_length length of @a input_hash
  139. * @param cont continuation to call when something is found
  140. * @return handle to abort the request
  141. */
  142. struct GNUNET_REHASH_QueryContext *
  143. GNUNET_REHASH_query_start (struct GNUNET_REHASH_Handle *h,
  144. enum GNUNET_FS_SearchOptions options,
  145. uint32_t anonymity,
  146. enum GNUNET_REHASH_Hash_Type in_type,
  147. enum GNUNET_REHASH_Hash_Type out_type,
  148. const char *input,
  149. size_t input_length,
  150. GNUNET_REHASH_QueryContinuation cont,
  151. void *cls);
  152. /**
  153. * Abort trying to store a hash->hash mapping.
  154. * TODO: memory
  155. *
  156. * @param c context of action to abort
  157. */
  158. void
  159. GNUNET_REHASH_store_abort (struct GNUNET_REHASH_StoreContext *c);
  160. /**
  161. * Stop searching. TODO: memory
  162. *
  163. * @param c context of action to abort
  164. */
  165. void
  166. GNUNET_REHASH_query_abort (struct GNUNET_REHASH_QueryContext *c);
  167. #if 0
  168. {
  169. #endif
  170. #ifdef __cplusplus
  171. }
  172. #endif
  173. #endif