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