gnunet_peerstore_service.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. /*
  2. This file is part of GNUnet
  3. Copyright (C)
  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 Omar Tarabai
  19. *
  20. * @file
  21. * API to the peerstore service
  22. *
  23. * @defgroup peerstore Peer Store service
  24. *
  25. * @{
  26. */
  27. #ifndef GNUNET_PEERSTORE_SERVICE_H
  28. #define GNUNET_PEERSTORE_SERVICE_H
  29. #include "platform.h"
  30. #include "gnunet_util_lib.h"
  31. #ifdef __cplusplus
  32. extern "C"
  33. {
  34. #if 0 /* keep Emacsens' auto-indent happy */
  35. }
  36. #endif
  37. #endif
  38. /**
  39. * Options for storing values in PEERSTORE
  40. */
  41. enum GNUNET_PEERSTORE_StoreOption
  42. {
  43. /**
  44. * Possibly store multiple values under given key.
  45. */
  46. GNUNET_PEERSTORE_STOREOPTION_MULTIPLE = 0,
  47. /**
  48. * Delete any previous values for the given key before
  49. * storing the given value.
  50. */
  51. GNUNET_PEERSTORE_STOREOPTION_REPLACE = 1
  52. };
  53. /**
  54. * Handle to the peerstore service.
  55. */
  56. struct GNUNET_PEERSTORE_Handle;
  57. /**
  58. * Context for a store request
  59. */
  60. struct GNUNET_PEERSTORE_StoreContext;
  61. /**
  62. * Single PEERSTORE record
  63. */
  64. struct GNUNET_PEERSTORE_Record
  65. {
  66. /**
  67. * Responsible sub system string
  68. */
  69. char *sub_system;
  70. /**
  71. * Peer Identity
  72. */
  73. struct GNUNET_PeerIdentity *peer;
  74. /**
  75. * Record key string
  76. */
  77. char *key;
  78. /**
  79. * Record value BLOB
  80. */
  81. void *value;
  82. /**
  83. * Size of @e value BLOB
  84. */
  85. size_t value_size;
  86. /**
  87. * Expiry time of entry
  88. */
  89. struct GNUNET_TIME_Absolute *expiry;
  90. /**
  91. * Client from which this record originated
  92. */
  93. struct GNUNET_SERVER_Client *client;
  94. };
  95. /**
  96. * Continuation called with a status result.
  97. *
  98. * @param cls closure
  99. * @param success #GNUNET_OK or #GNUNET_SYSERR
  100. */
  101. typedef void
  102. (*GNUNET_PEERSTORE_Continuation)(void *cls,
  103. int success);
  104. /**
  105. * Function called by PEERSTORE for each matching record.
  106. *
  107. * @param cls closure
  108. * @param record peerstore record information
  109. * @param emsg error message, or NULL if no errors
  110. * @return #GNUNET_YES to continue iterating, #GNUNET_NO to stop
  111. */
  112. typedef int
  113. (*GNUNET_PEERSTORE_Processor) (void *cls,
  114. const struct GNUNET_PEERSTORE_Record *record,
  115. const char *emsg);
  116. /**
  117. * Connect to the PEERSTORE service.
  118. *
  119. * @return NULL on error
  120. */
  121. struct GNUNET_PEERSTORE_Handle *
  122. GNUNET_PEERSTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
  123. /**
  124. * Disconnect from the PEERSTORE service. Any pending ITERATE and WATCH requests
  125. * will be canceled.
  126. * Any pending STORE requests will depend on @e snyc_first flag.
  127. *
  128. * @param h handle to disconnect
  129. * @param sync_first send any pending STORE requests before disconnecting
  130. */
  131. void
  132. GNUNET_PEERSTORE_disconnect (struct GNUNET_PEERSTORE_Handle *h,
  133. int sync_first);
  134. /**
  135. * Store a new entry in the PEERSTORE.
  136. * Note that stored entries can be lost in some cases
  137. * such as power failure.
  138. *
  139. * @param h Handle to the PEERSTORE service
  140. * @param sub_system name of the sub system
  141. * @param peer Peer Identity
  142. * @param key entry key
  143. * @param value entry value BLOB
  144. * @param size size of @e value
  145. * @param expiry absolute time after which the entry is (possibly) deleted
  146. * @param options options specific to the storage operation
  147. * @param cont Continuation function after the store request is sent
  148. * @param cont_cls Closure for @a cont
  149. */
  150. struct GNUNET_PEERSTORE_StoreContext *
  151. GNUNET_PEERSTORE_store (struct GNUNET_PEERSTORE_Handle *h,
  152. const char *sub_system,
  153. const struct GNUNET_PeerIdentity *peer,
  154. const char *key,
  155. const void *value,
  156. size_t size,
  157. struct GNUNET_TIME_Absolute expiry,
  158. enum GNUNET_PEERSTORE_StoreOption options,
  159. GNUNET_PEERSTORE_Continuation cont,
  160. void *cont_cls);
  161. /**
  162. * Cancel a store request
  163. *
  164. * @param sc Store request context
  165. */
  166. void
  167. GNUNET_PEERSTORE_store_cancel (struct GNUNET_PEERSTORE_StoreContext *sc);
  168. /**
  169. * Iterate over records matching supplied key information
  170. *
  171. * @param h handle to the PEERSTORE service
  172. * @param sub_system name of sub system
  173. * @param peer Peer identity (can be NULL)
  174. * @param key entry key string (can be NULL)
  175. * @param timeout time after which the iterate request is canceled
  176. * @param callback function called with each matching record, all NULL's on end
  177. * @param callback_cls closure for @a callback
  178. */
  179. struct GNUNET_PEERSTORE_IterateContext *
  180. GNUNET_PEERSTORE_iterate (struct GNUNET_PEERSTORE_Handle *h,
  181. const char *sub_system,
  182. const struct GNUNET_PeerIdentity *peer,
  183. const char *key,
  184. struct GNUNET_TIME_Relative timeout,
  185. GNUNET_PEERSTORE_Processor callback,
  186. void *callback_cls);
  187. /**
  188. * Cancel an iterate request
  189. * Please do not call after the iterate request is done
  190. *
  191. * @param ic Iterate request context as returned by GNUNET_PEERSTORE_iterate()
  192. */
  193. void
  194. GNUNET_PEERSTORE_iterate_cancel (struct GNUNET_PEERSTORE_IterateContext *ic);
  195. /**
  196. * Request watching a given key
  197. * User will be notified with any new values added to key.
  198. *
  199. * @param h handle to the PEERSTORE service
  200. * @param sub_system name of sub system
  201. * @param peer Peer identity
  202. * @param key entry key string
  203. * @param callback function called with each new value
  204. * @param callback_cls closure for @a callback
  205. * @return Handle to watch request
  206. */
  207. struct GNUNET_PEERSTORE_WatchContext *
  208. GNUNET_PEERSTORE_watch (struct GNUNET_PEERSTORE_Handle *h,
  209. const char *sub_system,
  210. const struct GNUNET_PeerIdentity *peer,
  211. const char *key,
  212. GNUNET_PEERSTORE_Processor callback,
  213. void *callback_cls);
  214. /**
  215. * Cancel a watch request
  216. *
  217. * @param wc handle to the watch request
  218. */
  219. void
  220. GNUNET_PEERSTORE_watch_cancel (struct GNUNET_PEERSTORE_WatchContext *wc);
  221. #if 0 /* keep Emacsens' auto-indent happy */
  222. {
  223. #endif
  224. #ifdef __cplusplus
  225. }
  226. #endif
  227. #endif
  228. /** @} */ /* end of group */