-avoid 'hu', as it is unsigned short, not uint16_t
[oweals/gnunet.git] / src / include / gnunet_peerstore_service.h
1 /*
2       This file is part of GNUnet
3       (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., 59 Temple Place - Suite 330,
18       Boston, MA 02111-1307, 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,
50
51   /**
52    * Delete any previous values for the given key before
53    * storing the given value.
54    */
55   GNUNET_PEERSTORE_STOREOPTION_REPLACE,
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 '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
107 /**
108  * Continuation called with a status result.
109  *
110  * @param cls closure
111  * @param success #GNUNET_OK or #GNUNET_SYSERR
112  */
113 typedef void (*GNUNET_PEERSTORE_Continuation)(void *cls, int success);
114
115 /**
116  * Function called by for each matching record.
117  *
118  * @param cls closure
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
122  */
123 typedef int (*GNUNET_PEERSTORE_Processor) (void *cls,
124     struct GNUNET_PEERSTORE_Record *record,
125     char *emsg);
126
127 /**
128  * Connect to the PEERSTORE service.
129  *
130  * @return NULL on error
131  */
132 struct GNUNET_PEERSTORE_Handle *
133 GNUNET_PEERSTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
134
135 /**
136  * Disconnect from the PEERSTORE service
137  *
138  * @param h handle to disconnect
139  */
140 void
141 GNUNET_PEERSTORE_disconnect(struct GNUNET_PEERSTORE_Handle *h);
142
143 /**
144  * Store a new entry in the PEERSTORE
145  *
146  * @param h Handle to the PEERSTORE service
147  * @param sub_system name of the sub system
148  * @param peer Peer Identity
149  * @param key entry key
150  * @param value entry value BLOB
151  * @param size size of 'value'
152  * @param expiry absolute time after which the entry is (possibly) deleted
153  * @param options store operation option
154  * @param cont Continuation function after the store request is processed
155  * @param cont_cls Closure for 'cont'
156  */
157 struct GNUNET_PEERSTORE_StoreContext *
158 GNUNET_PEERSTORE_store (struct GNUNET_PEERSTORE_Handle *h,
159     const char *sub_system,
160     const struct GNUNET_PeerIdentity *peer,
161     const char *key,
162     const void *value,
163     size_t size,
164     struct GNUNET_TIME_Absolute expiry,
165     enum GNUNET_PEERSTORE_StoreOption options,
166     GNUNET_PEERSTORE_Continuation cont,
167     void *cont_cls);
168
169 /**
170  * Cancel a store request
171  *
172  * @param sc Store request context
173  */
174 void
175 GNUNET_PEERSTORE_store_cancel (struct GNUNET_PEERSTORE_StoreContext *sc);
176
177 /**
178  * Iterate over records matching supplied key information
179  *
180  * @param h handle to the PEERSTORE service
181  * @param sub_system name of sub system
182  * @param peer Peer identity (can be NULL)
183  * @param key entry key string (can be NULL)
184  * @param timeout time after which the iterate request is canceled
185  * @param callback function called with each matching record, all NULL's on end
186  * @param callback_cls closure for @a callback
187  */
188 struct GNUNET_PEERSTORE_IterateContext *
189 GNUNET_PEERSTORE_iterate (struct GNUNET_PEERSTORE_Handle *h,
190     const char *sub_system,
191     const struct GNUNET_PeerIdentity *peer,
192     const char *key,
193     struct GNUNET_TIME_Relative timeout,
194     GNUNET_PEERSTORE_Processor callback, void *callback_cls);
195
196 /**
197  * Cancel an iterate request
198  * Please do not call after the iterate request is done
199  *
200  * @param ic Iterate request context as returned by GNUNET_PEERSTORE_iterate()
201  */
202 void
203 GNUNET_PEERSTORE_iterate_cancel (struct GNUNET_PEERSTORE_IterateContext *ic);
204
205 /**
206  * Request watching a given key
207  * User will be notified with any new values added to key
208  *
209  * @param h handle to the PEERSTORE service
210  * @param sub_system name of sub system
211  * @param peer Peer identity
212  * @param key entry key string
213  * @param callback function called with each new value
214  * @param callback_cls closure for @a callback
215  * @return Handle to watch request
216  */
217 struct GNUNET_PEERSTORE_WatchContext *
218 GNUNET_PEERSTORE_watch (struct GNUNET_PEERSTORE_Handle *h,
219     const char *sub_system,
220     const struct GNUNET_PeerIdentity *peer,
221     const char *key,
222     GNUNET_PEERSTORE_Processor callback, void *callback_cls);
223
224 /**
225  * Cancel a watch request
226  *
227  * @wc handle to the watch request
228  */
229 void
230 GNUNET_PEERSTORE_watch_cancel(struct GNUNET_PEERSTORE_WatchContext *wc);
231
232 #if 0                           /* keep Emacsens' auto-indent happy */
233 {
234 #endif
235 #ifdef __cplusplus
236 }
237 #endif
238
239 #endif