2422178660d1689e765a730a8de9253f11c573e8
[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  * TODO:
27  * - decide what goes into storage API and what into GNS-service API
28  * - decide where to pass/expose/check keys / signatures
29  * - are GNS private keys per peer or per user?
30  */
31
32
33 #ifndef GNUNET_GNS_SERVICE_H
34 #define GNUNET_GNS_SERVICE_H
35
36 #include "gnunet_util_lib.h"
37 #include "gnunet_namestore_service.h"
38
39 #ifdef __cplusplus
40 extern "C"
41 {
42 #if 0                           /* keep Emacsens' auto-indent happy */
43 }
44 #endif
45 #endif
46
47
48 /**
49  * Connection to the GNS service.
50  */
51 struct GNUNET_GNS_Handle;
52
53 /**
54  * Handle to control a get operation.
55  */
56 struct GNUNET_GNS_LookupHandle;
57
58 /**
59  * Record types
60  * Based on GNUNET_DNSPARSER_TYPEs (standard DNS)
61  */
62 enum GNUNET_GNS_RecordType
63 {
64   /* Standard DNS */
65   GNUNET_GNS_RECORD_TYPE_A = 1,
66   GNUNET_GNS_RECORD_TYPE_NS = 2,
67   GNUNET_GNS_RECORD_TYPE_CNAME = 5,
68   GNUNET_GNS_RECORD_TYPE_SOA = 6,
69   GNUNET_GNS_RECORD_TYPE_PTR = 12,
70   GNUNET_GNS_RECORD_MX = 15,
71   GNUNET_GNS_RECORD_TXT = 16,
72   GNUNET_GNS_RECORD_AAAA = 28,
73
74   /* GNS specific */
75   GNUNET_GNS_RECORD_PKEY = 256
76 };
77
78 /**
79  * Initialize the connection with the GNS service.
80  * FIXME: Do we need the ht_len?
81  *
82  * @param cfg configuration to use
83  * @param ht_len size of the internal hash table to use for parallel lookups
84  * @return NULL on error
85  */
86 struct GNUNET_GNS_Handle *
87 GNUNET_GNS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
88                     unsigned int ht_len);
89
90
91 /**
92  * Shutdown connection with the GNS service.
93  *
94  * @param handle connection to shut down
95  */
96 void
97 GNUNET_GNS_disconnect (struct GNUNET_GNS_Handle *handle);
98
99
100 /* *************** Standard API: lookup ******************* */
101
102 /**
103  * Iterator called on each result obtained for a GNS
104  * lookup
105  *
106  * @param cls closure
107  * @param name "name" of the original lookup
108  * @param record the records in reply
109  * @param num_records the number of records in reply
110  */
111 typedef void (*GNUNET_GNS_LookupIterator) (void *cls,
112                                         const char * name,
113                                         const struct GNUNET_NAMESTORE_RecordData *record,
114                                         unsigned int num_records);
115
116
117
118 /**
119  * Perform an asynchronous lookup operation on the GNS.
120  *
121  * @param handle handle to the GNS service
122  * @param timeout how long to wait for transmission of this request to the service
123  * // FIXME: what happens afterwards?
124  * @param handle handle to the GNS service
125  * @param timeout timeout of request
126  * @param name the name to look up
127  * @param type the GNUNET_GNS_RecordType to look for
128  * @param iter function to call on each result
129  * @param iter_cls closure for iter
130  *
131  * @return handle to stop the async lookup
132  */
133 struct GNUNET_GNS_LookupHandle *
134 GNUNET_GNS_lookup_start (struct GNUNET_GNS_Handle *handle,
135                          struct GNUNET_TIME_Relative timeout,
136                          const char * name,
137                          enum GNUNET_GNS_RecordType type,
138                          GNUNET_GNS_LookupIterator iter,
139                          void *iter_cls);
140
141
142 /**
143  * Stop async GNS lookup.  Frees associated resources.
144  *
145  * @param lookup_handle lookup operation to stop.
146  *
147  * On return lookup_handle will no longer be valid, caller
148  * must not use again!!!
149  */
150 void
151 GNUNET_GNS_lookup_stop (struct GNUNET_GNS_LookupHandle *lookup_handle);
152
153
154 #if 0                           /* keep Emacsens' auto-indent happy */
155 {
156 #endif
157 #ifdef __cplusplus
158 }
159 #endif
160
161
162 #endif
163 /* gnunet_gns_service.h */