first quick hack to extract an initial DNS service API
[oweals/gnunet.git] / src / include / gnunet_dns_service.h
1 /*
2       This file is part of GNUnet
3       (C) 2010, 2011, 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 2, 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_dns_service.h
23  * @brief API to access the DNS service.  Not finished at all,
24  *        currently only contains the structs for the IPC, which
25  *        don't even belong here (legacy code in transition)
26  * @author Philipp Toelke
27  */
28 #ifndef GNUNET_DNS_SERVICE_H
29 #define GNUNET_DNS_SERVICE_H
30
31 #include "gnunet_common.h"
32 #include "gnunet_util_lib.h"
33
34 GNUNET_NETWORK_STRUCT_BEGIN
35
36 struct query_packet
37 {
38   struct GNUNET_MessageHeader hdr;
39
40         /**
41          * The IP-Address this query was originally sent to
42          */
43   char orig_to[16];
44         /**
45          * The IP-Address this query was originally sent from
46          */
47   char orig_from[16];
48         /**
49          * The UDP-Portthis query was originally sent from
50          */
51   char addrlen;
52   uint16_t src_port GNUNET_PACKED;
53
54   unsigned char data[1];        /* The DNS-Packet */
55 };
56
57 struct query_packet_list
58 {
59   struct query_packet_list *next GNUNET_PACKED;
60   struct query_packet_list *prev GNUNET_PACKED;
61   struct query_packet pkt;
62 };
63
64 enum GNUNET_DNS_ANSWER_Subtype
65 {
66     /**
67      * Answers of this type contain a dns-packet that just has to be transmitted
68      */
69   GNUNET_DNS_ANSWER_TYPE_IP,
70
71     /**
72      * Answers of this type contain an incomplete dns-packet. The IP-Address
73      * is all 0s. The addroffset points to it.
74      */
75   GNUNET_DNS_ANSWER_TYPE_SERVICE,
76
77     /**
78      * Answers of this type contain an incomplete dns-packet as answer to a
79      * PTR-Query. The resolved name is not allocated. The addroffset points to it.
80      */
81   GNUNET_DNS_ANSWER_TYPE_REV,
82
83     /**
84      * Answers of this type contains an IP6-Address but traffic to this IP should
85      * be routed through the GNUNet.
86      */
87   GNUNET_DNS_ANSWER_TYPE_REMOTE_AAAA,
88
89     /**
90      * Answers of this type contains an IP4-Address but traffic to this IP should
91      * be routed through the GNUNet.
92      */
93   GNUNET_DNS_ANSWER_TYPE_REMOTE_A
94 };
95
96 struct GNUNET_vpn_service_descriptor
97 {
98   GNUNET_HashCode peer GNUNET_PACKED;
99   GNUNET_HashCode service_descriptor GNUNET_PACKED;
100   uint64_t ports GNUNET_PACKED;
101   uint32_t service_type GNUNET_PACKED;
102 };
103
104 struct answer_packet
105 {
106   /* General data */
107   struct GNUNET_MessageHeader hdr;
108   enum GNUNET_DNS_ANSWER_Subtype subtype GNUNET_PACKED;
109
110   char from[16];
111   char to[16];
112   char addrlen;
113   unsigned dst_port:16 GNUNET_PACKED;
114   /* -- */
115
116   /* Data for GNUNET_DNS_ANSWER_TYPE_SERVICE */
117   struct GNUNET_vpn_service_descriptor service_descr;
118   /* -- */
119
120   /* Data for GNUNET_DNS_ANSWER_TYPE_REV */
121   /* The offsett in octets from the beginning of the struct to the field
122    * in data where the IP-Address has to go. */
123   uint16_t addroffset GNUNET_PACKED;
124   /* -- */
125
126   /* Data for GNUNET_DNS_ANSWER_TYPE_REMOTE */
127   /* either 4 or 16 */
128   char addrsize;
129   unsigned char addr[16];
130   /* -- */
131
132   unsigned char data[1];
133 };
134
135 struct answer_packet_list
136 {
137   struct answer_packet_list *next GNUNET_PACKED;
138   struct answer_packet_list *prev GNUNET_PACKED;
139   struct GNUNET_SERVER_Client *client;
140   struct answer_packet pkt;
141 };
142 GNUNET_NETWORK_STRUCT_END
143
144 struct GNUNET_DNS_Handle;
145
146 /**
147  * Connect to the service-dns
148  */
149 struct GNUNET_DNS_Handle *
150 GNUNET_DNS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
151                     GNUNET_SCHEDULER_Task cb,
152                     void *cb_cls);
153
154 void
155 GNUNET_DNS_restart_hijack (struct GNUNET_DNS_Handle *h);
156
157
158 /**
159  * FIXME: we should not expost our internal structures like this.
160  * Just a quick initial hack.
161  */
162 void
163 GNUNET_DNS_queue_request (struct GNUNET_DNS_Handle *h,
164                           struct query_packet_list *q);
165
166 void
167 GNUNET_DNS_disconnect (struct GNUNET_DNS_Handle *h);
168
169 #endif