405fcd2fce749605baca57f878673810a89eff72
[oweals/gnunet.git] / src / include / gnunet_gns_service.h
1 /*
2       This file is part of GNUnet
3       (C) 2004, 2005, 2006, 2008, 2009, 2011 Christian Grothoff (and other contributing authors)
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_gns_service.h
23  * @brief API to the GNS service
24  * @author Martin Schanzenbach
25  */
26
27 #ifndef GNUNET_GNS_SERVICE_H
28 #define GNUNET_GNS_SERVICE_H
29
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 /**
42  * Connection to the GNS service.
43  */
44 struct GNUNET_GNS_Handle;
45
46 /**
47  * Handle to control a get operation.
48  */
49 struct GNUNET_GNS_LookupHandle;
50
51 /**
52  * Initialize the connection with the GNS service.
53  *
54  * @param cfg configuration to use
55  * @return NULL on error
56  */
57 struct GNUNET_GNS_Handle *
58 GNUNET_GNS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
59
60
61 /**
62  * Shutdown connection with the GNS service.
63  *
64  * @param handle connection to shut down
65  */
66 void
67 GNUNET_GNS_disconnect (struct GNUNET_GNS_Handle *handle);
68
69
70 /* *************** Standard API: add and lookup ******************* */
71
72 /**
73  * Perform an add operation storing records in the GNS.
74  *
75  * @param handle handle to GNS service
76  * @param key the key to store under
77  * @param desired_replication_level estimate of how many
78  *                nearest peers this request should reach
79  * @param options routing options for this message
80  * @param type type of the value
81  * @param size number of bytes in data; must be less than 64k
82  * @param data the data to store
83  * @param exp desired expiration time for the value
84  * @param timeout how long to wait for transmission of this request
85  * @param cont continuation to call when done (transmitting request to service)
86  * @param cont_cls closure for cont
87  */
88 void
89 GNUNET_GNS_add (struct GNUNET_GNS_Handle *handle, const GNUNET_HashCode * key,
90                 uint32_t desired_replication_level,
91                 enum GNUNET_DHT_RouteOption options,
92                 enum GNUNET_BLOCK_Type type, size_t size, const char *data,
93                 struct GNUNET_TIME_Absolute exp,
94                 struct GNUNET_TIME_Relative timeout, GNUNET_SCHEDULER_Task cont,
95                 void *cont_cls);
96
97
98 /**
99  * Iterator called on each result obtained for a GNS
100  * operation that expects a reply TODO: eh?
101  *
102  * @param cls closure
103  * @param exp when will this value expire
104  * @param key key of the result
105  * @param get_path peers on reply path (or NULL if not recorded)
106  * @param get_path_length number of entries in get_path
107  * @param put_path peers on the PUT path (or NULL if not recorded)
108  * @param put_path_length number of entries in get_path
109  * @param type type of the result
110  * @param size number of bytes in data
111  * @param data pointer to the result data
112  */
113 typedef void (*GNUNET_GNS_LookupIterator) (void *cls,
114                                         struct GNUNET_TIME_Absolute exp,
115                                         const GNUNET_HashCode * key,
116                                         const struct GNUNET_PeerIdentity *
117                                         get_path, unsigned int get_path_length,
118                                         const struct GNUNET_PeerIdentity *
119                                         put_path, unsigned int put_path_length,
120                                         enum GNUNET_BLOCK_Type type,
121                                         size_t size, const void *data);
122
123
124
125 /**
126  * Perform an asynchronous lookup operation on the GNS.
127  *
128  * @param handle handle to the GNS service
129  * @param timeout how long to wait for transmission of this request to the service
130  * @param type expected type of the response object
131  * @param key the key to look up
132  * @param desired_replication_level estimate of how many
133                   nearest peers this request should reach
134  * @param options routing options for this message
135  * @param xquery extended query data (can be NULL, depending on type)
136  * @param xquery_size number of bytes in xquery
137  * @param iter function to call on each result
138  * @param iter_cls closure for iter
139  *
140  * @return handle to stop the async get
141  */
142 struct GNUNET_GNS_LookupHandle *
143 GNUNET_GNS_lookup_start (struct GNUNET_GNS_Handle *handle,
144                       struct GNUNET_TIME_Relative timeout,
145                       enum GNUNET_BLOCK_Type type, const GNUNET_HashCode * key,
146                       uint32_t desired_replication_level,
147                       enum GNUNET_DHT_RouteOption options, const void *xquery,
148                       size_t xquery_size, GNUNET_GNS_LookupIterator iter,
149                       void *iter_cls);
150
151
152 /**
153  * Stop async GNS lookup.  Frees associated resources.
154  *
155  * @param lookup_handle lookup operation to stop.
156  *
157  * On return lookup_handle will no longer be valid, caller
158  * must not use again!!!
159  */
160 void
161 GNUNET_GNS_lookup_stop (struct GNUNET_GNS_LookupHandle *lookup_handle);
162
163
164 #if 0                           /* keep Emacsens' auto-indent happy */
165 {
166 #endif
167 #ifdef __cplusplus
168 }
169 #endif
170
171
172 #endif
173 /* gnunet_gns_service.h */