gnunet_datacache_lib.h 5.7 KB

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