2357851168a4ced431ed297a2ba6b8145bcc7613
[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  * A single GNS record.
53  */
54 struct GNUNET_GNS_Record;
55
56 /**
57  * Records types
58  */
59 enum GNUNET_GNS_RecordType
60 {
61   GNUNET_GNS_RECORD_A,
62   GNUNET_GNS_RECORD_AAAA,
63   GNUNET_GNS_RECORD_MX,
64   GNUNET_GNS_RECORD_PKEY
65 };
66
67 /**
68  * Initialize the connection with the GNS service.
69  *
70  * @param cfg configuration to use
71  * @param ht_len size of the internal hash table to use for parallel lookups
72  * @return NULL on error
73  */
74 struct GNUNET_GNS_Handle *
75 GNUNET_GNS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg
76                     unsigned int ht_len);
77
78
79 /**
80  * Shutdown connection with the GNS service.
81  *
82  * @param handle connection to shut down
83  */
84 void
85 GNUNET_GNS_disconnect (struct GNUNET_GNS_Handle *handle);
86
87
88 /* *************** Standard API: add and lookup ******************* */
89
90 /**
91  * Perform an add operation storing records in the GNS.
92  *
93  * @param handle handle to GNS service
94  * @param key the key to store under
95  * @param desired_replication_level estimate of how many
96  *                nearest peers this request should reach
97  * @param options routing options for this message
98  * @param type type of the value
99  * @param size number of bytes in data; must be less than 64k
100  * @param data the data to store
101  * @param exp desired expiration time for the value
102  * @param timeout how long to wait for transmission of this request
103  * @param cont continuation to call when done (transmitting request to service)
104  * @param cont_cls closure for cont
105  */
106 void
107 GNUNET_GNS_add_record (struct GNUNET_GNS_Handle *handle,
108                        const char* name,
109                        enum GNUNET_GNS_RecordType type,
110                        size_t size, const char *data,
111                        struct GNUNET_TIME_Absolute exp,
112                        struct GNUNET_TIME_Relative timeout);
113
114
115 /**
116  * Iterator called on each result obtained for a GNS
117  * operation that expects a reply TODO: eh?
118  *
119  * @param cls closure
120  * @param exp when will this value expire
121  * @param key key of the result
122  * @param records the records in reply
123  * @param num_records the number of records in reply
124  * @param type type of the result
125  */
126 typedef void (*GNUNET_GNS_LookupIterator) (void *cls,
127                                         const GNUNET_HashCode * key,
128                                         const struct GNUNET_GNS_Record *record,
129                                         unsigned int num_records);
130
131
132
133 /**
134  * Perform an asynchronous lookup operation on the GNS.
135  *
136  * @param handle handle to the GNS service
137  * @param timeout how long to wait for transmission of this request to the service
138  * @param type expected type of the response object
139  * @param key the key to look up
140  * @param desired_replication_level estimate of how many
141                   nearest peers this request should reach
142  * @param options routing options for this message
143  * @param xquery extended query data (can be NULL, depending on type)
144  * @param xquery_size number of bytes in xquery
145  * @param iter function to call on each result
146  * @param iter_cls closure for iter
147  *
148  * @return handle to stop the async get
149  */
150 struct GNUNET_GNS_LookupHandle *
151 GNUNET_GNS_lookup_start (struct GNUNET_GNS_Handle *handle,
152                       struct GNUNET_TIME_Relative timeout,
153                       const char * name,
154                       enum GNUNET_GNS_RecordType type,
155                       GNUNET_GNS_LookupIterator iter,
156                       void *iter_cls);
157
158
159 /**
160  * Stop async GNS lookup.  Frees associated resources.
161  *
162  * @param lookup_handle lookup operation to stop.
163  *
164  * On return lookup_handle will no longer be valid, caller
165  * must not use again!!!
166  */
167 void
168 GNUNET_GNS_lookup_stop (struct GNUNET_GNS_LookupHandle *lookup_handle);
169
170
171 #if 0                           /* keep Emacsens' auto-indent happy */
172 {
173 #endif
174 #ifdef __cplusplus
175 }
176 #endif
177
178
179 #endif
180 /* gnunet_gns_service.h */