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., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file include/gnunet_peerstore_service.h
23 * @brief API to the peerstore service
24 * @author Omar Tarabai
26 #ifndef GNUNET_PEERSTORE_SERVICE_H
27 #define GNUNET_PEERSTORE_SERVICE_H
30 #include "gnunet_util_lib.h"
35 #if 0 /* keep Emacsens' auto-indent happy */
41 * Options for storing values in PEERSTORE
43 enum GNUNET_PEERSTORE_StoreOption
47 * Possibly store multiple values under given key.
49 GNUNET_PEERSTORE_STOREOPTION_MULTIPLE,
52 * Delete any previous values for the given key before
53 * storing the given value.
55 GNUNET_PEERSTORE_STOREOPTION_REPLACE,
60 * Handle to the peerstore service.
62 struct GNUNET_PEERSTORE_Handle;
65 * Context for a store request
67 struct GNUNET_PEERSTORE_StoreContext;
70 * Single PEERSTORE record
72 struct GNUNET_PEERSTORE_Record
76 * Responsible sub system string
83 struct GNUNET_PeerIdentity *peer;
96 * Size of 'value' BLOB
101 * Expiry time of entry
103 struct GNUNET_TIME_Absolute *expiry;
108 * Continuation called with a status result.
111 * @param success #GNUNET_OK or #GNUNET_SYSERR
113 typedef void (*GNUNET_PEERSTORE_Continuation)(void *cls, int success);
116 * Function called by for each matching record.
119 * @param record peerstore record information
120 * @param emsg error message, or NULL if no errors
121 * @return #GNUNET_YES to continue iterating, #GNUNET_NO to stop
123 typedef int (*GNUNET_PEERSTORE_Processor) (void *cls,
124 struct GNUNET_PEERSTORE_Record *record,
128 * Connect to the PEERSTORE service.
130 * @return NULL on error
132 struct GNUNET_PEERSTORE_Handle *
133 GNUNET_PEERSTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
136 * Disconnect from the PEERSTORE service. Any pending ITERATE and WATCH requests
137 * will be canceled. Any pending STORE requests will depend on @snyc_first flag.
139 * @param h handle to disconnect
140 * @param sync_first send any pending STORE requests before disconnecting
143 GNUNET_PEERSTORE_disconnect (struct GNUNET_PEERSTORE_Handle *h, int sync_first);
146 * Store a new entry in the PEERSTORE
148 * @param h Handle to the PEERSTORE service
149 * @param sub_system name of the sub system
150 * @param peer Peer Identity
151 * @param key entry key
152 * @param value entry value BLOB
153 * @param size size of 'value'
154 * @param expiry absolute time after which the entry is (possibly) deleted
155 * @param options store operation option
156 * @param cont Continuation function after the store request is processed
157 * @param cont_cls Closure for 'cont'
159 struct GNUNET_PEERSTORE_StoreContext *
160 GNUNET_PEERSTORE_store (struct GNUNET_PEERSTORE_Handle *h,
161 const char *sub_system,
162 const struct GNUNET_PeerIdentity *peer,
166 struct GNUNET_TIME_Absolute expiry,
167 enum GNUNET_PEERSTORE_StoreOption options,
168 GNUNET_PEERSTORE_Continuation cont,
172 * Cancel a store request
174 * @param sc Store request context
177 GNUNET_PEERSTORE_store_cancel (struct GNUNET_PEERSTORE_StoreContext *sc);
180 * Iterate over records matching supplied key information
182 * @param h handle to the PEERSTORE service
183 * @param sub_system name of sub system
184 * @param peer Peer identity (can be NULL)
185 * @param key entry key string (can be NULL)
186 * @param timeout time after which the iterate request is canceled
187 * @param callback function called with each matching record, all NULL's on end
188 * @param callback_cls closure for @a callback
190 struct GNUNET_PEERSTORE_IterateContext *
191 GNUNET_PEERSTORE_iterate (struct GNUNET_PEERSTORE_Handle *h,
192 const char *sub_system,
193 const struct GNUNET_PeerIdentity *peer,
195 struct GNUNET_TIME_Relative timeout,
196 GNUNET_PEERSTORE_Processor callback, void *callback_cls);
199 * Cancel an iterate request
200 * Please do not call after the iterate request is done
202 * @param ic Iterate request context as returned by GNUNET_PEERSTORE_iterate()
205 GNUNET_PEERSTORE_iterate_cancel (struct GNUNET_PEERSTORE_IterateContext *ic);
208 * Request watching a given key
209 * User will be notified with any new values added to key
211 * @param h handle to the PEERSTORE service
212 * @param sub_system name of sub system
213 * @param peer Peer identity
214 * @param key entry key string
215 * @param callback function called with each new value
216 * @param callback_cls closure for @a callback
217 * @return Handle to watch request
219 struct GNUNET_PEERSTORE_WatchContext *
220 GNUNET_PEERSTORE_watch (struct GNUNET_PEERSTORE_Handle *h,
221 const char *sub_system,
222 const struct GNUNET_PeerIdentity *peer,
224 GNUNET_PEERSTORE_Processor callback, void *callback_cls);
227 * Cancel a watch request
229 * @wc handle to the watch request
232 GNUNET_PEERSTORE_watch_cancel(struct GNUNET_PEERSTORE_WatchContext *wc);
234 #if 0 /* keep Emacsens' auto-indent happy */