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