rehash_service.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. /* rehash --- a decentralised hash<->hash store
  2. Copyright © 2020 Maxime Devos <maxime.devos@student.kuleuven.be>
  3. This file is part of rehash.
  4. rehash 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. rehash 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 rehash. 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 REHASH_SERVICE_H
  23. #define 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 REHASH_QueryContext;
  37. /**
  38. * Context to control hash->hash inserts.
  39. */
  40. struct REHASH_StoreContext;
  41. /* TODO: perhaps some monitoring
  42. and enumeration? */
  43. /**
  44. * Handle to the rehash service.
  45. */
  46. struct REHASH_Handle;
  47. /**
  48. * Connect to the rehash service.
  49. *
  50. * If the connection failed (e.g. because the service isn't up yet),
  51. * a usable handle is returned anyway, and put / get requests
  52. * will be queued until the appropriate services are up.
  53. *
  54. * The scheduler has to be running while using the functions
  55. * defined here.
  56. *
  57. * @param cfg configuration to use
  58. * @return handle to use to access the service
  59. */
  60. struct REHASH_Handle *
  61. REHASH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
  62. /**
  63. * Disconnect from the rehash service.
  64. *
  65. * The handle @a h will be freed, as well as
  66. * all associated queries and stores.
  67. * @param h handle to the rehash service
  68. */
  69. void
  70. REHASH_disconnect (struct REHASH_Handle *h);
  71. /**
  72. * Check if @a h is connected to the rehash service.
  73. *
  74. * @param h handle to the rehash service
  75. * @return #GNUNET_OK if connected,
  76. * #GNUNET_NO or #GNUNET_SYSERR otherwise
  77. */
  78. int
  79. REHASH_connected (struct REHASH_Handle *h);
  80. /**
  81. * If @a h isn't connected yet / anymore to the rehash service,
  82. * retry. Otherwise a no-op.
  83. *
  84. * @param h handle to the rehash service
  85. */
  86. void
  87. REHASH_retry_connect (struct REHASH_Handle *h);
  88. /**
  89. * Callback to call when a hash->hash mapping has been inserted.
  90. * The store context has been freed by now.
  91. *
  92. * @param cls closure
  93. */
  94. typedef void
  95. (*REHASH_StoreContinuation) (void *cls);
  96. /**
  97. * Where has the hash->hash mapping been found?
  98. * More locations may be defined later.
  99. * TODO is this useful?
  100. */
  101. enum REHASH_Origin
  102. {
  103. REHASH_ORIGIN_DHT = 0,
  104. REHASH_ORIGIN_DATASTORE = 1,
  105. };
  106. /**
  107. * Callback to call when a hash->hash mapping has been found
  108. *
  109. * The found hash may have a bogus length for its type,
  110. * and incorrect hash->hash mappings can be found.
  111. *
  112. * @param cls closure
  113. * @param exp when will this value expire
  114. * @param origin where has this mapping been found
  115. * @param out_length size of @a out_hash
  116. * @param out_hash hash found
  117. */
  118. typedef void
  119. (*REHASH_QueryContinuation) (void *cls,
  120. struct GNUNET_TIME_Absolute exp,
  121. enum REHASH_Origin origin,
  122. size_t out_length,
  123. const char *out_hash);
  124. /**
  125. * Store an hash->hash mapping into the data store
  126. * (and DHT, anonymity permitting), to be shared with
  127. * other peers. If the entry is already present, the old
  128. * entry is considered faulty and is replaced with the
  129. * new mapping.
  130. *
  131. * The store context will be freed upon success,
  132. * and then the callback @var{cont} is called once.
  133. *
  134. * @param h handle to the rehash store
  135. * @param options anonymity, replication, ... options
  136. * @param in_type type of hash to query with
  137. * @param out_type type of hash to search for
  138. * @param input hash to search with
  139. * @param input_length length of @a input_hash
  140. * @param output hash to find
  141. * @param output_length length of @a output_hash
  142. * @param cont continuation to call when done
  143. * @param cont_cls closure for @a cont
  144. * @return handle to abort the request
  145. */
  146. struct REHASH_StoreContext *
  147. REHASH_store_start (struct REHASH_Handle *h,
  148. const struct GNUNET_FS_BlockOptions *options,
  149. enum REHASH_Hash_Type in_type,
  150. enum REHASH_Hash_Type out_type,
  151. const char *input,
  152. size_t input_length,
  153. const char *output,
  154. size_t output_length,
  155. REHASH_StoreContinuation cont,
  156. void *cls);
  157. /**
  158. * Search for hash->hash mappings.
  159. *
  160. * @param h handle to rehash service
  161. * @param options only the flag LOOPBACK_ONLY is supported
  162. * @param anonymity desired anonymity level
  163. * @param in_type type of hash to query with
  164. * @param out_type type of hash to search for
  165. * @param input hash to search with
  166. * @param input_length length of @a input_hash
  167. * @param cont continuation to call when something is found
  168. * @return handle to abort the request
  169. */
  170. struct REHASH_QueryContext *
  171. REHASH_query_start (struct REHASH_Handle *h,
  172. enum GNUNET_FS_SearchOptions options,
  173. uint32_t anonymity,
  174. enum REHASH_Hash_Type in_type,
  175. enum REHASH_Hash_Type out_type,
  176. const char *input,
  177. size_t input_length,
  178. REHASH_QueryContinuation cont,
  179. void *cls);
  180. /**
  181. * Abort trying to store a hash->hash mapping.
  182. *
  183. * This deallocates @var{c}. No callbacks associated with @var{c}
  184. * will be called anymore.
  185. *
  186. * @param c context of action to abort
  187. */
  188. void
  189. REHASH_store_abort (struct REHASH_StoreContext *c);
  190. /**
  191. * Abort a search.
  192. *
  193. * This deallocates @var{c}. No callbacks associated with @var{c}
  194. * will be called anymore.
  195. *
  196. * @param c context of action to abort
  197. */
  198. void
  199. REHASH_query_abort (struct REHASH_QueryContext *c);
  200. #if 0
  201. {
  202. #endif
  203. #ifdef __cplusplus
  204. }
  205. #endif
  206. #endif