2 This file is part of GNUnet
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
22 * @author Omar Tarabai
25 * API to the peerstore service
27 * @defgroup peerstore Peer Store service
29 * @see [Documentation](https://gnunet.org/gnunets-peerstore-subsystem)
33 #ifndef GNUNET_PEERSTORE_SERVICE_H
34 #define GNUNET_PEERSTORE_SERVICE_H
36 #include "gnunet_util_lib.h"
41 #if 0 /* keep Emacsens' auto-indent happy */
47 * Options for storing values in PEERSTORE
49 enum GNUNET_PEERSTORE_StoreOption
53 * Possibly store multiple values under given key.
55 GNUNET_PEERSTORE_STOREOPTION_MULTIPLE = 0,
58 * Delete any previous values for the given key before
59 * storing the given value.
61 GNUNET_PEERSTORE_STOREOPTION_REPLACE = 1
66 * Handle to the peerstore service.
68 struct GNUNET_PEERSTORE_Handle;
71 * Context for a store request
73 struct GNUNET_PEERSTORE_StoreContext;
76 * Single PEERSTORE record
78 struct GNUNET_PEERSTORE_Record
82 * Responsible sub system string
89 struct GNUNET_PeerIdentity *peer;
102 * Size of @e value BLOB
107 * Expiry time of entry
109 struct GNUNET_TIME_Absolute *expiry;
112 * Client from which this record originated.
113 * NOTE: This is internal to the service.
115 struct GNUNET_SERVICE_Client *client;
120 * Continuation called with a status result.
123 * @param success #GNUNET_OK or #GNUNET_SYSERR
126 (*GNUNET_PEERSTORE_Continuation)(void *cls,
131 * Function called by PEERSTORE for each matching record.
134 * @param record peerstore record information
135 * @param emsg error message, or NULL if no errors
138 (*GNUNET_PEERSTORE_Processor) (void *cls,
139 const struct GNUNET_PEERSTORE_Record *record,
144 * Connect to the PEERSTORE service.
146 * @return NULL on error
148 struct GNUNET_PEERSTORE_Handle *
149 GNUNET_PEERSTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
153 * Disconnect from the PEERSTORE service. Any pending ITERATE and WATCH requests
155 * Any pending STORE requests will depend on @e snyc_first flag.
157 * @param h handle to disconnect
158 * @param sync_first send any pending STORE requests before disconnecting
161 GNUNET_PEERSTORE_disconnect (struct GNUNET_PEERSTORE_Handle *h,
166 * Store a new entry in the PEERSTORE.
167 * Note that stored entries can be lost in some cases
168 * such as power failure.
170 * @param h Handle to the PEERSTORE service
171 * @param sub_system name of the sub system
172 * @param peer Peer Identity
173 * @param key entry key
174 * @param value entry value BLOB
175 * @param size size of @e value
176 * @param expiry absolute time after which the entry is (possibly) deleted
177 * @param options options specific to the storage operation
178 * @param cont Continuation function after the store request is sent
179 * @param cont_cls Closure for @a cont
181 struct GNUNET_PEERSTORE_StoreContext *
182 GNUNET_PEERSTORE_store (struct GNUNET_PEERSTORE_Handle *h,
183 const char *sub_system,
184 const struct GNUNET_PeerIdentity *peer,
188 struct GNUNET_TIME_Absolute expiry,
189 enum GNUNET_PEERSTORE_StoreOption options,
190 GNUNET_PEERSTORE_Continuation cont,
195 * Cancel a store request
197 * @param sc Store request context
200 GNUNET_PEERSTORE_store_cancel (struct GNUNET_PEERSTORE_StoreContext *sc);
204 * Iterate over records matching supplied key information
206 * @param h handle to the PEERSTORE service
207 * @param sub_system name of sub system
208 * @param peer Peer identity (can be NULL)
209 * @param key entry key string (can be NULL)
210 * @param timeout time after which the iterate request is canceled
211 * @param callback function called with each matching record, all NULL's on end
212 * @param callback_cls closure for @a callback
214 struct GNUNET_PEERSTORE_IterateContext *
215 GNUNET_PEERSTORE_iterate (struct GNUNET_PEERSTORE_Handle *h,
216 const char *sub_system,
217 const struct GNUNET_PeerIdentity *peer,
219 struct GNUNET_TIME_Relative timeout,
220 GNUNET_PEERSTORE_Processor callback,
225 * Cancel an iterate request
226 * Please do not call after the iterate request is done
228 * @param ic Iterate request context as returned by GNUNET_PEERSTORE_iterate()
231 GNUNET_PEERSTORE_iterate_cancel (struct GNUNET_PEERSTORE_IterateContext *ic);
235 * Request watching a given key
236 * User will be notified with any new values added to key.
238 * @param h handle to the PEERSTORE service
239 * @param sub_system name of sub system
240 * @param peer Peer identity
241 * @param key entry key string
242 * @param callback function called with each new value
243 * @param callback_cls closure for @a callback
244 * @return Handle to watch request
246 struct GNUNET_PEERSTORE_WatchContext *
247 GNUNET_PEERSTORE_watch (struct GNUNET_PEERSTORE_Handle *h,
248 const char *sub_system,
249 const struct GNUNET_PeerIdentity *peer,
251 GNUNET_PEERSTORE_Processor callback,
256 * Cancel a watch request
258 * @param wc handle to the watch request
261 GNUNET_PEERSTORE_watch_cancel (struct GNUNET_PEERSTORE_WatchContext *wc);
264 #if 0 /* keep Emacsens' auto-indent happy */
273 /** @} */ /* end of group */