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
31 #ifndef GNUNET_PEERSTORE_SERVICE_H
32 #define GNUNET_PEERSTORE_SERVICE_H
35 #include "gnunet_util_lib.h"
40 #if 0 /* keep Emacsens' auto-indent happy */
46 * Options for storing values in PEERSTORE
48 enum GNUNET_PEERSTORE_StoreOption
52 * Possibly store multiple values under given key.
54 GNUNET_PEERSTORE_STOREOPTION_MULTIPLE = 0,
57 * Delete any previous values for the given key before
58 * storing the given value.
60 GNUNET_PEERSTORE_STOREOPTION_REPLACE = 1
65 * Handle to the peerstore service.
67 struct GNUNET_PEERSTORE_Handle;
70 * Context for a store request
72 struct GNUNET_PEERSTORE_StoreContext;
75 * Single PEERSTORE record
77 struct GNUNET_PEERSTORE_Record
81 * Responsible sub system string
88 struct GNUNET_PeerIdentity *peer;
101 * Size of @e value BLOB
106 * Expiry time of entry
108 struct GNUNET_TIME_Absolute *expiry;
111 * Client from which this record originated
113 struct GNUNET_SERVER_Client *client;
118 * Continuation called with a status result.
121 * @param success #GNUNET_OK or #GNUNET_SYSERR
124 (*GNUNET_PEERSTORE_Continuation)(void *cls,
129 * Function called by PEERSTORE for each matching record.
132 * @param record peerstore record information
133 * @param emsg error message, or NULL if no errors
134 * @return #GNUNET_YES to continue iterating, #GNUNET_NO to stop
137 (*GNUNET_PEERSTORE_Processor) (void *cls,
138 const struct GNUNET_PEERSTORE_Record *record,
142 * Connect to the PEERSTORE service.
144 * @return NULL on error
146 struct GNUNET_PEERSTORE_Handle *
147 GNUNET_PEERSTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
151 * Disconnect from the PEERSTORE service. Any pending ITERATE and WATCH requests
153 * Any pending STORE requests will depend on @e snyc_first flag.
155 * @param h handle to disconnect
156 * @param sync_first send any pending STORE requests before disconnecting
159 GNUNET_PEERSTORE_disconnect (struct GNUNET_PEERSTORE_Handle *h,
164 * Store a new entry in the PEERSTORE.
165 * Note that stored entries can be lost in some cases
166 * such as power failure.
168 * @param h Handle to the PEERSTORE service
169 * @param sub_system name of the sub system
170 * @param peer Peer Identity
171 * @param key entry key
172 * @param value entry value BLOB
173 * @param size size of @e value
174 * @param expiry absolute time after which the entry is (possibly) deleted
175 * @param options options specific to the storage operation
176 * @param cont Continuation function after the store request is sent
177 * @param cont_cls Closure for @a cont
179 struct GNUNET_PEERSTORE_StoreContext *
180 GNUNET_PEERSTORE_store (struct GNUNET_PEERSTORE_Handle *h,
181 const char *sub_system,
182 const struct GNUNET_PeerIdentity *peer,
186 struct GNUNET_TIME_Absolute expiry,
187 enum GNUNET_PEERSTORE_StoreOption options,
188 GNUNET_PEERSTORE_Continuation cont,
193 * Cancel a store request
195 * @param sc Store request context
198 GNUNET_PEERSTORE_store_cancel (struct GNUNET_PEERSTORE_StoreContext *sc);
202 * Iterate over records matching supplied key information
204 * @param h handle to the PEERSTORE service
205 * @param sub_system name of sub system
206 * @param peer Peer identity (can be NULL)
207 * @param key entry key string (can be NULL)
208 * @param timeout time after which the iterate request is canceled
209 * @param callback function called with each matching record, all NULL's on end
210 * @param callback_cls closure for @a callback
212 struct GNUNET_PEERSTORE_IterateContext *
213 GNUNET_PEERSTORE_iterate (struct GNUNET_PEERSTORE_Handle *h,
214 const char *sub_system,
215 const struct GNUNET_PeerIdentity *peer,
217 struct GNUNET_TIME_Relative timeout,
218 GNUNET_PEERSTORE_Processor callback,
223 * Cancel an iterate request
224 * Please do not call after the iterate request is done
226 * @param ic Iterate request context as returned by GNUNET_PEERSTORE_iterate()
229 GNUNET_PEERSTORE_iterate_cancel (struct GNUNET_PEERSTORE_IterateContext *ic);
233 * Request watching a given key
234 * User will be notified with any new values added to key.
236 * @param h handle to the PEERSTORE service
237 * @param sub_system name of sub system
238 * @param peer Peer identity
239 * @param key entry key string
240 * @param callback function called with each new value
241 * @param callback_cls closure for @a callback
242 * @return Handle to watch request
244 struct GNUNET_PEERSTORE_WatchContext *
245 GNUNET_PEERSTORE_watch (struct GNUNET_PEERSTORE_Handle *h,
246 const char *sub_system,
247 const struct GNUNET_PeerIdentity *peer,
249 GNUNET_PEERSTORE_Processor callback,
254 * Cancel a watch request
256 * @param wc handle to the watch request
259 GNUNET_PEERSTORE_watch_cancel (struct GNUNET_PEERSTORE_WatchContext *wc);
262 #if 0 /* keep Emacsens' auto-indent happy */
271 /** @} */ /* end of group */