towards peerstore iterate
[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  * Continuation called with a status result.
52  *
53  * @param cls closure
54  * @param success #GNUNET_OK or #GNUNET_SYSERR
55  */
56 typedef void (*GNUNET_PEERSTORE_Continuation)(void *cls, int success);
57
58 /**
59  * Function called by for each matching record.
60  *
61  * @param cls closure
62  * @param peer peer identity
63  * @param sub_system name of the GNUnet sub system responsible
64  * @param value stored value
65  * @param size size of stored value
66  * @return #GNUNET_YES to continue iterating, #GNUNET_NO to stop
67  */
68 typedef int (*GNUNET_PEERSTORE_Processor) (void *cls,
69     const char *sub_system,
70     const struct GNUNET_PeerIdentity *peer,
71     const char *key,
72     const void *value,
73     size_t size,
74     struct GNUNET_TIME_Absolute expiry);
75
76 /**
77  * Connect to the PEERSTORE service.
78  *
79  * @return NULL on error
80  */
81 struct GNUNET_PEERSTORE_Handle *
82 GNUNET_PEERSTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
83
84 /**
85  * Disconnect from the PEERSTORE service
86  *
87  * @param h handle to disconnect
88  */
89 void
90 GNUNET_PEERSTORE_disconnect(struct GNUNET_PEERSTORE_Handle *h);
91
92 /**
93  * Store a new entry in the PEERSTORE
94  *
95  * @param h Handle to the PEERSTORE service
96  * @param sub_system name of the sub system
97  * @param peer Peer Identity
98  * @param key entry key
99  * @param value entry value BLOB
100  * @param size size of 'value'
101  * @param lifetime relative time after which the entry is (possibly) deleted
102  * @param cont Continuation function after the store request is processed
103  * @param cont_cls Closure for 'cont'
104  */
105 struct GNUNET_PEERSTORE_StoreContext *
106 GNUNET_PEERSTORE_store (struct GNUNET_PEERSTORE_Handle *h,
107     const char *sub_system,
108     const struct GNUNET_PeerIdentity *peer,
109     const char *key,
110     const void *value,
111     size_t size,
112     struct GNUNET_TIME_Absolute expiry,
113     GNUNET_PEERSTORE_Continuation cont,
114     void *cont_cls);
115
116 /**
117  * Cancel a store request
118  *
119  * @param sc Store request context
120  */
121 void
122 GNUNET_PEERSTORE_store_cancel (struct GNUNET_PEERSTORE_StoreContext *sc);
123
124 #if 0                           /* keep Emacsens' auto-indent happy */
125 {
126 #endif
127 #ifdef __cplusplus
128 }
129 #endif
130
131 #endif