4ede69d93fa414e637ea0ad84f462279aa882ab7
[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  * Handle to the peerstore service.
42  */
43 struct GNUNET_PEERSTORE_Handle;
44
45 /**
46  * Context for a store request
47  */
48 struct GNUNET_PEERSTORE_StoreContext;
49
50 /**
51  * Single PEERSTORE record
52  */
53 struct GNUNET_PEERSTORE_Record
54 {
55
56   /**
57    * Responsible sub system string
58    */
59   char *sub_system;
60
61   /**
62    * Peer Identity
63    */
64   struct GNUNET_PeerIdentity *peer;
65
66   /**
67    * Record key string
68    */
69   char *key;
70
71   /**
72    * Record value BLOB
73    */
74   void *value;
75
76   /**
77    * Size of 'value' BLOB
78    */
79   size_t value_size;
80
81   /**
82    * Expiry time of entry
83    */
84   struct GNUNET_TIME_Absolute *expiry;
85
86 };
87
88 /**
89  * Continuation called with a status result.
90  *
91  * @param cls closure
92  * @param success #GNUNET_OK or #GNUNET_SYSERR
93  */
94 typedef void (*GNUNET_PEERSTORE_Continuation)(void *cls, int success);
95
96 /**
97  * Function called by for each matching record.
98  *
99  * @param cls closure
100  * @param record peerstore record information
101  * @param emsg error message, or NULL if no errors
102  * @return #GNUNET_YES to continue iterating, #GNUNET_NO to stop
103  */
104 typedef int (*GNUNET_PEERSTORE_Processor) (void *cls,
105     struct GNUNET_PEERSTORE_Record *record,
106     char *emsg);
107
108 /**
109  * Connect to the PEERSTORE service.
110  *
111  * @return NULL on error
112  */
113 struct GNUNET_PEERSTORE_Handle *
114 GNUNET_PEERSTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
115
116 /**
117  * Disconnect from the PEERSTORE service
118  *
119  * @param h handle to disconnect
120  */
121 void
122 GNUNET_PEERSTORE_disconnect(struct GNUNET_PEERSTORE_Handle *h);
123
124 /**
125  * Store a new entry in the PEERSTORE
126  *
127  * @param h Handle to the PEERSTORE service
128  * @param sub_system name of the sub system
129  * @param peer Peer Identity
130  * @param key entry key
131  * @param value entry value BLOB
132  * @param size size of 'value'
133  * @param lifetime relative time after which the entry is (possibly) deleted
134  * @param cont Continuation function after the store request is processed
135  * @param cont_cls Closure for 'cont'
136  */
137 struct GNUNET_PEERSTORE_StoreContext *
138 GNUNET_PEERSTORE_store (struct GNUNET_PEERSTORE_Handle *h,
139     const char *sub_system,
140     const struct GNUNET_PeerIdentity *peer,
141     const char *key,
142     const void *value,
143     size_t size,
144     struct GNUNET_TIME_Absolute expiry,
145     GNUNET_PEERSTORE_Continuation cont,
146     void *cont_cls);
147
148 /**
149  * Cancel a store request
150  *
151  * @param sc Store request context
152  */
153 void
154 GNUNET_PEERSTORE_store_cancel (struct GNUNET_PEERSTORE_StoreContext *sc);
155
156 /**
157  * Iterate over records matching supplied key information
158  *
159  * @param h handle to the PEERSTORE service
160  * @param sub_system name of sub system
161  * @param peer Peer identity (can be NULL)
162  * @param key entry key string (can be NULL)
163  * @param timeout time after which the iterate request is canceled
164  * @param callback function called with each matching record, all NULL's on end
165  * @param callback_cls closure for @a callback
166  */
167 struct GNUNET_PEERSTORE_IterateContext *
168 GNUNET_PEERSTORE_iterate (struct GNUNET_PEERSTORE_Handle *h,
169     char *sub_system,
170     const struct GNUNET_PeerIdentity *peer,
171     const char *key,
172     struct GNUNET_TIME_Relative timeout,
173     GNUNET_PEERSTORE_Processor callback, void *callback_cls);
174
175 /**
176  * Cancel an iterate request
177  * Please do not call after the iterate request is done
178  *
179  * @param ic Iterate request context as returned by GNUNET_PEERSTORE_iterate()
180  */
181 void
182 GNUNET_PEERSTORE_iterate_cancel (struct GNUNET_PEERSTORE_IterateContext *ic);
183
184 #if 0                           /* keep Emacsens' auto-indent happy */
185 {
186 #endif
187 #ifdef __cplusplus
188 }
189 #endif
190
191 #endif