gnunet_datacache_plugin.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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. * API for database backends for the datacache
  22. *
  23. * @defgroup datacache-plugin Data Cache plugin API
  24. * API for database backends for the datacache
  25. * @{
  26. */
  27. #ifndef PLUGIN_DATACACHE_H
  28. #define PLUGIN_DATACACHE_H
  29. #include "gnunet_datacache_lib.h"
  30. #ifdef __cplusplus
  31. extern "C"
  32. {
  33. #if 0 /* keep Emacsens' auto-indent happy */
  34. }
  35. #endif
  36. #endif
  37. /**
  38. * Function called by plugins to notify the datacache
  39. * about content deletions.
  40. *
  41. * @param cls closure
  42. * @param key key of the content that was deleted
  43. * @param size number of bytes that were made available
  44. */
  45. typedef void
  46. (*GNUNET_DATACACHE_DeleteNotifyCallback) (void *cls,
  47. const struct GNUNET_HashCode *key,
  48. size_t size);
  49. /**
  50. * The datastore service will pass a pointer to a struct
  51. * of this type as the first and only argument to the
  52. * entry point of each datastore plugin.
  53. */
  54. struct GNUNET_DATACACHE_PluginEnvironment
  55. {
  56. /**
  57. * Configuration to use.
  58. */
  59. const struct GNUNET_CONFIGURATION_Handle *cfg;
  60. /**
  61. * Configuration section to use.
  62. */
  63. const char *section;
  64. /**
  65. * Closure to use for callbacks.
  66. */
  67. void *cls;
  68. /**
  69. * Function to call whenever the plugin needs to
  70. * discard content that it was asked to store.
  71. */
  72. GNUNET_DATACACHE_DeleteNotifyCallback delete_notify;
  73. /**
  74. * How much space are we allowed to use?
  75. */
  76. unsigned long long quota;
  77. };
  78. /**
  79. * @brief struct returned by the initialization function of the plugin
  80. */
  81. struct GNUNET_DATACACHE_PluginFunctions
  82. {
  83. /**
  84. * Closure to pass to all plugin functions.
  85. */
  86. void *cls;
  87. /**
  88. * Store an item in the datastore.
  89. *
  90. * @param cls closure (internal context for the plugin)
  91. * @param key key to store the value under
  92. * @param size number of bytes in @a data
  93. * @param data data to store
  94. * @param type type of the value
  95. * @param discard_time when to discard the value in any case
  96. * @param path_info_len number of entries in @a path_info
  97. * @param path_info a path through the network
  98. * @return 0 if duplicate, -1 on error, number of bytes used otherwise
  99. */
  100. ssize_t (*put) (void *cls,
  101. const struct GNUNET_HashCode *key,
  102. size_t 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 datastore.
  111. *
  112. * @param cls closure (internal context for the plugin)
  113. * @param key key to look for
  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 (*get) (void *cls,
  120. const struct GNUNET_HashCode *key,
  121. enum GNUNET_BLOCK_Type type,
  122. GNUNET_DATACACHE_Iterator iter,
  123. void *iter_cls);
  124. /**
  125. * Delete the entry with the lowest expiration value
  126. * from the datacache right now.
  127. *
  128. * @param cls closure (internal context for the plugin)
  129. * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
  130. */
  131. int (*del) (void *cls);
  132. /**
  133. * Return a random value from the datastore.
  134. *
  135. * @param cls closure (internal context for the plugin)
  136. * @param iter maybe NULL (to just count)
  137. * @param iter_cls closure for @a iter
  138. * @return the number of results found (zero or one)
  139. */
  140. unsigned int (*get_random) (void *cls,
  141. GNUNET_DATACACHE_Iterator iter,
  142. void *iter_cls);
  143. /**
  144. * Iterate over the results that are "close" to a particular key in
  145. * the datacache. "close" is defined as numerically larger than @a
  146. * key (when interpreted as a circular address space), with small
  147. * distance.
  148. *
  149. * @param cls closure (internal context for the plugin)
  150. * @param key area of the keyspace to look into
  151. * @param num_results number of results that should be returned to @a iter
  152. * @param iter maybe NULL (to just count)
  153. * @param iter_cls closure for @a iter
  154. * @return the number of results found
  155. */
  156. unsigned int (*get_closest) (void *cls,
  157. const struct GNUNET_HashCode *key,
  158. unsigned int num_results,
  159. GNUNET_DATACACHE_Iterator iter,
  160. void *iter_cls);
  161. };
  162. #if 0 /* keep Emacsens' auto-indent happy */
  163. {
  164. #endif
  165. #ifdef __cplusplus
  166. }
  167. #endif
  168. #endif
  169. /** @} */ /* end of group */