99028f60cf4f72ee167b49d435e81d4c048813f6
[oweals/gnunet.git] / src / include / gnunet_gns_service.h
1 /*
2       This file is part of GNUnet
3       (C) 2012 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   // FIXME: should be based on GNUNET_DNSPARSER_TYPE's (standard DNS),
62   // and then maybe our extensions in the area > 255?
63   GNUNET_GNS_RECORD_A,
64   GNUNET_GNS_RECORD_AAAA,
65   GNUNET_GNS_RECORD_MX,
66   GNUNET_GNS_RECORD_PKEY
67 };
68
69 /**
70  * Initialize the connection with the GNS service.
71  *
72  * @param cfg configuration to use
73  * @param ht_len size of the internal hash table to use for parallel lookups
74  * @return NULL on error
75  */
76 struct GNUNET_GNS_Handle *
77 GNUNET_GNS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg
78                     unsigned int ht_len);
79
80
81 /**
82  * Shutdown connection with the GNS service.
83  *
84  * @param handle connection to shut down
85  */
86 void
87 GNUNET_GNS_disconnect (struct GNUNET_GNS_Handle *handle);
88
89
90 /* *************** Standard API: add and lookup ******************* */
91
92 /**
93  * Perform an add operation storing records in the GNS.
94  *
95  * FIXME: Yes, we need this kind of API, but should it not be with the
96  * NameDataStore, rather than the GNS-service?
97  *
98  * @param handle handle to GNS service
99  * @param name the key to store under
100  * // FIXME: need to be precise here what 'name' is. Does it
101    // include '.gnunet'?  What happens if we specify 'a.b.c.gnunet'
102    //  but 'b.c.gnunet' has been delegated? (error?)  
103  * @param desired_replication_level estimate of how many
104  *                nearest peers this request should reach
105  * @param options routing options for this message
106    // FIXME: which are? where is the arg?
107    // FIXME: we should probably distinguish between 'private' and 'public'
108    //        records;
109  * @param type type of the value
110  * @param size number of bytes in data; must be less than 64k
111  * @param data the data to store
112    // FIXME: what is the exact format of data?
113  * @param exp desired expiration time for the value
114  * @param timeout how long to wait for transmission of this request
115  * @param cont continuation to call when done (transmitting request to service)
116  * @param cont_cls closure for cont
117  * // FIXME: where are the continuations?
118  */
119 void
120 GNUNET_GNS_add_record (struct GNUNET_GNS_Handle *handle,
121                        const char* name,
122                        enum GNUNET_GNS_RecordType type,
123                        size_t size, const char *data,
124                        struct GNUNET_TIME_Absolute exp,
125                        struct GNUNET_TIME_Relative timeout);
126
127
128 /**
129  * Iterator called on each result obtained for a GNS
130  * operation that expects a reply TODO: eh?
131  *
132  *
133  * @param cls closure
134  * @param exp when will this value expire
135  * @param key key of the result
136  * // how does the key relate to the name exactly? Why not give the name?
137  * @param record the records in reply
138  * // FIXME: shouldn't this then be an array of pointers?
139  * @param num_records the number of records in reply
140  * @param type type of the result
141  * // FIXME: not in signature
142  */
143 typedef void (*GNUNET_GNS_LookupIterator) (void *cls,
144                                         const GNUNET_HashCode * key,
145                                         const struct GNUNET_GNS_Record *record,
146                                         unsigned int num_records);
147
148
149
150 /**
151  * Perform an asynchronous lookup operation on the GNS.
152  *
153  * @param handle handle to the GNS service
154  * @param timeout how long to wait for transmission of this request to the service
155  * // FIXME: what happens afterwards?
156  * @param type expected type of the response object
157  * @param key the key to look up
158  * // FIXME: key, name, what format?
159  * @param desired_replication_level estimate of how many
160                   nearest peers this request should reach
161  * @param options routing options for this message
162  * //FIXME: missmatch between documented and actual options...
163  * @param xquery extended query data (can be NULL, depending on type)
164  * @param xquery_size number of bytes in xquery
165  * @param iter function to call on each result
166  * @param iter_cls closure for iter
167  *
168  * @return handle to stop the async get
169  */
170 struct GNUNET_GNS_LookupHandle *
171 GNUNET_GNS_lookup_start (struct GNUNET_GNS_Handle *handle,
172                       struct GNUNET_TIME_Relative timeout,
173                       const char * name,
174                       enum GNUNET_GNS_RecordType type,
175                       GNUNET_GNS_LookupIterator iter,
176                       void *iter_cls);
177
178
179 /**
180  * Stop async GNS lookup.  Frees associated resources.
181  *
182  * @param lookup_handle lookup operation to stop.
183  *
184  * On return lookup_handle will no longer be valid, caller
185  * must not use again!!!
186  */
187 void
188 GNUNET_GNS_lookup_stop (struct GNUNET_GNS_LookupHandle *lookup_handle);
189
190
191 #if 0                           /* keep Emacsens' auto-indent happy */
192 {
193 #endif
194 #ifdef __cplusplus
195 }
196 #endif
197
198
199 #endif
200 /* gnunet_gns_service.h */