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