gnunet_datacache_lib.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /*
  2. This file is part of GNUnet
  3. Copyright (C) 2006, 2009, 2015 GNUnet e.V.
  4. GNUnet is free software: you can redistribute it and/or modify it
  5. under the terms of the GNU Affero General Public License as published
  6. by the Free Software Foundation, either version 3 of the License,
  7. or (at your option) any later version.
  8. GNUnet 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 GNU
  11. Affero General Public License for more details.
  12. You should have received a copy of the GNU Affero General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. SPDX-License-Identifier: AGPL3.0-or-later
  15. */
  16. /**
  17. * @author Christian Grothoff
  18. *
  19. * @file
  20. * datacache API
  21. *
  22. * @defgroup datacache Data Cache library
  23. * Simple, transient hash table of bounded size with content expiration.
  24. *
  25. * In contrast to the sqstore there is
  26. * no prioritization, deletion or iteration.
  27. * All of the data is discarded when the peer shuts down!
  28. *
  29. * @{
  30. */
  31. #ifndef GNUNET_DATACACHE_LIB_H
  32. #define GNUNET_DATACACHE_LIB_H
  33. #include "gnunet_util_lib.h"
  34. #include "gnunet_block_lib.h"
  35. #ifdef __cplusplus
  36. extern "C"
  37. {
  38. #if 0 /* keep Emacsens' auto-indent happy */
  39. }
  40. #endif
  41. #endif
  42. /**
  43. * Handle to the cache.
  44. */
  45. struct GNUNET_DATACACHE_Handle;
  46. /**
  47. * Create a data cache.
  48. *
  49. * @param cfg configuration to use
  50. * @param section section in the configuration that contains our options
  51. * @return handle to use to access the service
  52. */
  53. struct GNUNET_DATACACHE_Handle *
  54. GNUNET_DATACACHE_create (const struct GNUNET_CONFIGURATION_Handle *cfg,
  55. const char *section);
  56. /**
  57. * Destroy a data cache (and free associated resources).
  58. *
  59. * @param h handle to the datastore
  60. */
  61. void
  62. GNUNET_DATACACHE_destroy (struct GNUNET_DATACACHE_Handle *h);
  63. /**
  64. * An iterator over a set of items stored in the datacache.
  65. *
  66. * @param cls closure
  67. * @param key key for the content
  68. * @param data_size number of bytes in @a data
  69. * @param data content stored
  70. * @param type type of the content
  71. * @param exp when will the content expire?
  72. * @param path_info_len number of entries in @a path_info
  73. * @param path_info a path through the network
  74. * @return #GNUNET_OK to continue iterating, #GNUNET_SYSERR to abort
  75. */
  76. typedef int
  77. (*GNUNET_DATACACHE_Iterator) (void *cls,
  78. const struct GNUNET_HashCode *key,
  79. size_t data_size,
  80. const char *data,
  81. enum GNUNET_BLOCK_Type type,
  82. struct GNUNET_TIME_Absolute exp,
  83. unsigned int path_info_len,
  84. const struct GNUNET_PeerIdentity *path_info);
  85. /**
  86. * Store an item in the datacache.
  87. *
  88. * @param h handle to the datacache
  89. * @param key key to store data under
  90. * @param how close is @a key to our pid?
  91. * @param data_size number of bytes in @a data
  92. * @param data data to store
  93. * @param type type of the value
  94. * @param discard_time when to discard the value in any case
  95. * @param path_info_len number of entries in @a path_info
  96. * @param path_info a path through the network
  97. * @return #GNUNET_OK on success, #GNUNET_SYSERR on error, #GNUNET_NO if duplicate
  98. */
  99. int
  100. GNUNET_DATACACHE_put (struct GNUNET_DATACACHE_Handle *h,
  101. const struct GNUNET_HashCode *key,
  102. uint32_t xor_distance,
  103. size_t data_size,
  104. const char *data,
  105. enum GNUNET_BLOCK_Type type,
  106. struct GNUNET_TIME_Absolute discard_time,
  107. unsigned int path_info_len,
  108. const struct GNUNET_PeerIdentity *path_info);
  109. /**
  110. * Iterate over the results for a particular key
  111. * in the datacache.
  112. *
  113. * @param h handle to the datacache
  114. * @param key what to look up
  115. * @param type entries of which type are relevant?
  116. * @param iter maybe NULL (to just count)
  117. * @param iter_cls closure for @a iter
  118. * @return the number of results found
  119. */
  120. unsigned int
  121. GNUNET_DATACACHE_get (struct GNUNET_DATACACHE_Handle *h,
  122. const struct GNUNET_HashCode *key,
  123. enum GNUNET_BLOCK_Type type,
  124. GNUNET_DATACACHE_Iterator iter,
  125. void *iter_cls);
  126. /**
  127. * Obtain a random element from the datacache.
  128. *
  129. * @param h handle to the datacache
  130. * @param iter maybe NULL (to just count)
  131. * @param iter_cls closure for @a iter
  132. * @return the number of results found (zero or 1)
  133. */
  134. unsigned int
  135. GNUNET_DATACACHE_get_random (struct GNUNET_DATACACHE_Handle *h,
  136. GNUNET_DATACACHE_Iterator iter,
  137. void *iter_cls);
  138. /**
  139. * Iterate over the results that are "close" to a particular key in
  140. * the datacache. "close" is defined as numerically larger than @a
  141. * key (when interpreted as a circular address space), with small
  142. * distance.
  143. *
  144. * @param h handle to the datacache
  145. * @param key area of the keyspace to look into
  146. * @param num_results number of results that should be returned to @a iter
  147. * @param iter maybe NULL (to just count)
  148. * @param iter_cls closure for @a iter
  149. * @return the number of results found
  150. */
  151. unsigned int
  152. GNUNET_DATACACHE_get_closest (struct GNUNET_DATACACHE_Handle *h,
  153. const struct GNUNET_HashCode *key,
  154. unsigned int num_results,
  155. GNUNET_DATACACHE_Iterator iter,
  156. void *iter_cls);
  157. #if 0 /* keep Emacsens' auto-indent happy */
  158. {
  159. #endif
  160. #ifdef __cplusplus
  161. }
  162. #endif
  163. #endif
  164. /** @} */ /* end of group */