aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-01-01 23:39:24 +0000
committerChristian Grothoff <christian@grothoff.org>2012-01-01 23:39:24 +0000
commit402a25de1ef93133c9879706071081405ade61f6 (patch)
tree96763797649dd4bff0b7f8b2010a0589f8179dcb /src
parent3e73780b201b600dd8dd8725f5a628d62d9c4f51 (diff)
downloadgnunet-402a25de1ef93133c9879706071081405ade61f6.tar.gz
gnunet-402a25de1ef93133c9879706071081405ade61f6.zip
first quick hack to extract an initial DNS service API
Diffstat (limited to 'src')
-rw-r--r--src/dns/Makefile.am12
-rw-r--r--src/dns/dns_api.c (renamed from src/vpn/gnunet-daemon-vpn-dns.c)218
-rw-r--r--src/include/gnunet_dns_service.h26
-rw-r--r--src/vpn/Makefile.am2
-rw-r--r--src/vpn/gnunet-daemon-vpn-dns.h88
-rw-r--r--src/vpn/gnunet-daemon-vpn-helper.c36
-rw-r--r--src/vpn/gnunet-daemon-vpn.c21
-rw-r--r--src/vpn/gnunet-daemon-vpn.h6
8 files changed, 200 insertions, 209 deletions
diff --git a/src/dns/Makefile.am b/src/dns/Makefile.am
index 4eaade330..9e2566bca 100644
--- a/src/dns/Makefile.am
+++ b/src/dns/Makefile.am
@@ -21,7 +21,9 @@ else
21install-exec-hook: 21install-exec-hook:
22endif 22endif
23 23
24lib_LTLIBRARIES = libgnunetdnsparser.la 24lib_LTLIBRARIES = \
25 libgnunetdnsparser.la \
26 libgnunetdns.la
25 27
26bin_PROGRAMS = \ 28bin_PROGRAMS = \
27 gnunet-service-dns $(HIJACKBIN) 29 gnunet-service-dns $(HIJACKBIN)
@@ -45,4 +47,12 @@ libgnunetdnsparser_la_SOURCES = \
45libgnunetdnsparser_la_LIBADD = \ 47libgnunetdnsparser_la_LIBADD = \
46 $(top_builddir)/src/util/libgnunetutil.la $(XLIB) 48 $(top_builddir)/src/util/libgnunetutil.la $(XLIB)
47libgnunetdnsparser_la_LDFLAGS = \ 49libgnunetdnsparser_la_LDFLAGS = \
50 $(GN_LIB_LDFLAGS)
51
52
53libgnunetdns_la_SOURCES = \
54 dns_api.c
55libgnunetdns_la_LIBADD = \
56 $(top_builddir)/src/util/libgnunetutil.la $(XLIB)
57libgnunetdns_la_LDFLAGS = \
48 $(GN_LIB_LDFLAGS) \ No newline at end of file 58 $(GN_LIB_LDFLAGS) \ No newline at end of file
diff --git a/src/vpn/gnunet-daemon-vpn-dns.c b/src/dns/dns_api.c
index b24d802f7..90b4a8f42 100644
--- a/src/vpn/gnunet-daemon-vpn-dns.c
+++ b/src/dns/dns_api.c
@@ -33,19 +33,25 @@
33#include <gnunet_container_lib.h> 33#include <gnunet_container_lib.h>
34#include <block_dns.h> 34#include <block_dns.h>
35 35
36#include "gnunet-daemon-vpn-dns.h" 36#include "gnunet_dns_service.h"
37#include "gnunet-daemon-vpn.h"
38#include "gnunet-daemon-vpn-helper.h"
39#include "gnunet-vpn-packet.h"
40 37
41struct query_packet_list *head;
42struct query_packet_list *tail;
43struct GNUNET_CLIENT_Connection *dns_connection;
44unsigned char restart_hijack;
45struct answer_packet_list *answer_proc_head;
46struct answer_packet_list *answer_proc_tail;
47 38
48struct GNUNET_CLIENT_TransmitHandle *dns_transmit_handle; 39struct GNUNET_DNS_Handle
40{
41 struct query_packet_list *head;
42 struct query_packet_list *tail;
43 struct GNUNET_CLIENT_Connection *dns_connection;
44 unsigned char restart_hijack;
45
46 struct GNUNET_CLIENT_TransmitHandle *dns_transmit_handle;
47
48 const struct GNUNET_CONFIGURATION_Handle *cfg;
49
50 GNUNET_SCHEDULER_Task process_answer_cb;
51
52 void *process_answer_cb_cls;
53};
54
49 55
50/** 56/**
51 * Callback called by notify_transmit_ready; sends dns-queries or rehijack-messages 57 * Callback called by notify_transmit_ready; sends dns-queries or rehijack-messages
@@ -55,16 +61,18 @@ struct GNUNET_CLIENT_TransmitHandle *dns_transmit_handle;
55size_t 61size_t
56send_query (void *cls GNUNET_UNUSED, size_t size, void *buf) 62send_query (void *cls GNUNET_UNUSED, size_t size, void *buf)
57{ 63{
64 struct GNUNET_DNS_Handle *h = cls;
65
58 size_t len; 66 size_t len;
59 67
60 dns_transmit_handle = NULL; 68 h->dns_transmit_handle = NULL;
61 69
62 /* 70 /*
63 * Send the rehijack-message 71 * Send the rehijack-message
64 */ 72 */
65 if (restart_hijack == 1) 73 if (h->restart_hijack == 1)
66 { 74 {
67 restart_hijack = 0; 75 h->restart_hijack = 0;
68 /* 76 /*
69 * The message is just a header 77 * The message is just a header
70 */ 78 */
@@ -75,9 +83,9 @@ send_query (void *cls GNUNET_UNUSED, size_t size, void *buf)
75 hdr->size = htons (len); 83 hdr->size = htons (len);
76 hdr->type = htons (GNUNET_MESSAGE_TYPE_REHIJACK); 84 hdr->type = htons (GNUNET_MESSAGE_TYPE_REHIJACK);
77 } 85 }
78 else if (head != NULL) 86 else if (h->head != NULL)
79 { 87 {
80 struct query_packet_list *query = head; 88 struct query_packet_list *query = h->head;
81 89
82 len = ntohs (query->pkt.hdr.size); 90 len = ntohs (query->pkt.hdr.size);
83 91
@@ -85,7 +93,7 @@ send_query (void *cls GNUNET_UNUSED, size_t size, void *buf)
85 93
86 memcpy (buf, &query->pkt.hdr, len); 94 memcpy (buf, &query->pkt.hdr, len);
87 95
88 GNUNET_CONTAINER_DLL_remove (head, tail, query); 96 GNUNET_CONTAINER_DLL_remove (h->head, h->tail, query);
89 97
90 GNUNET_free (query); 98 GNUNET_free (query);
91 } 99 }
@@ -98,22 +106,22 @@ send_query (void *cls GNUNET_UNUSED, size_t size, void *buf)
98 /* 106 /*
99 * Check whether more data is to be sent 107 * Check whether more data is to be sent
100 */ 108 */
101 if (head != NULL) 109 if (h->head != NULL)
102 { 110 {
103 dns_transmit_handle = 111 h->dns_transmit_handle =
104 GNUNET_CLIENT_notify_transmit_ready (dns_connection, 112 GNUNET_CLIENT_notify_transmit_ready (h->dns_connection,
105 ntohs (head->pkt.hdr.size), 113 ntohs (h->head->pkt.hdr.size),
106 GNUNET_TIME_UNIT_FOREVER_REL, 114 GNUNET_TIME_UNIT_FOREVER_REL,
107 GNUNET_YES, &send_query, NULL); 115 GNUNET_YES, &send_query, h);
108 } 116 }
109 else if (restart_hijack == 1) 117 else if (h->restart_hijack == 1)
110 { 118 {
111 dns_transmit_handle = 119 h->dns_transmit_handle =
112 GNUNET_CLIENT_notify_transmit_ready (dns_connection, 120 GNUNET_CLIENT_notify_transmit_ready (h->dns_connection,
113 sizeof (struct 121 sizeof (struct
114 GNUNET_MessageHeader), 122 GNUNET_MessageHeader),
115 GNUNET_TIME_UNIT_FOREVER_REL, 123 GNUNET_TIME_UNIT_FOREVER_REL,
116 GNUNET_YES, &send_query, NULL); 124 GNUNET_YES, &send_query, h);
117 } 125 }
118 126
119 return len; 127 return len;
@@ -122,65 +130,30 @@ send_query (void *cls GNUNET_UNUSED, size_t size, void *buf)
122/* }}} */ 130/* }}} */
123 131
124 132
125/**
126 * Connect to the service-dns
127 */
128void
129connect_to_service_dns (void *cls GNUNET_UNUSED,
130 const struct GNUNET_SCHEDULER_TaskContext *tc)
131{
132 conn_task = GNUNET_SCHEDULER_NO_TASK;
133 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
134 return;
135 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting to service-dns\n");
136 GNUNET_assert (dns_connection == NULL);
137 dns_connection = GNUNET_CLIENT_connect ("dns", cfg);
138 /* This would most likely be a misconfiguration */
139 GNUNET_assert (NULL != dns_connection);
140 GNUNET_CLIENT_receive (dns_connection, &dns_answer_handler, NULL,
141 GNUNET_TIME_UNIT_FOREVER_REL);
142
143 /* We might not yet be connected. Yay, mps. */
144 if (NULL == dns_connection)
145 return;
146
147 /* If a packet is already in the list, schedule to send it */
148 if (dns_transmit_handle == NULL && head != NULL)
149 dns_transmit_handle =
150 GNUNET_CLIENT_notify_transmit_ready (dns_connection,
151 ntohs (head->pkt.hdr.size),
152 GNUNET_TIME_UNIT_FOREVER_REL,
153 GNUNET_YES, &send_query, NULL);
154 else if (dns_transmit_handle == NULL && restart_hijack == 1)
155 {
156 dns_transmit_handle =
157 GNUNET_CLIENT_notify_transmit_ready (dns_connection,
158 sizeof (struct
159 GNUNET_MessageHeader),
160 GNUNET_TIME_UNIT_FOREVER_REL,
161 GNUNET_YES, &send_query, NULL);
162 }
163}
164 133
165/** 134/**
166 * This receives packets from the service-dns and schedules process_answer to 135 * This receives packets from the service-dns and schedules process_answer to
167 * handle it 136 * handle it
168 */ 137 */
169void 138static void
170dns_answer_handler (void *cls GNUNET_UNUSED, 139dns_answer_handler (void *cls,
171 const struct GNUNET_MessageHeader *msg) 140 const struct GNUNET_MessageHeader *msg)
172{ 141{
142 struct GNUNET_DNS_Handle *h = cls;
143
173 /* the service disconnected, reconnect after short wait */ 144 /* the service disconnected, reconnect after short wait */
174 if (msg == NULL) 145 if (msg == NULL)
175 { 146 {
176 if (dns_transmit_handle != NULL) 147 if (h->dns_transmit_handle != NULL)
177 GNUNET_CLIENT_notify_transmit_ready_cancel (dns_transmit_handle); 148 GNUNET_CLIENT_notify_transmit_ready_cancel (h->dns_transmit_handle);
178 dns_transmit_handle = NULL; 149 h->dns_transmit_handle = NULL;
179 GNUNET_CLIENT_disconnect (dns_connection, GNUNET_NO); 150 GNUNET_CLIENT_disconnect (h->dns_connection, GNUNET_NO);
180 dns_connection = NULL; 151 h->dns_connection = NULL;
181 conn_task = 152#if 0
153 h->conn_task =
182 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 154 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
183 &connect_to_service_dns, NULL); 155 &connect_to_service_dns, h);
156#endif
184 return; 157 return;
185 } 158 }
186 159
@@ -188,16 +161,103 @@ dns_answer_handler (void *cls GNUNET_UNUSED,
188 if (msg->type != htons (GNUNET_MESSAGE_TYPE_VPN_DNS_LOCAL_RESPONSE_DNS)) 161 if (msg->type != htons (GNUNET_MESSAGE_TYPE_VPN_DNS_LOCAL_RESPONSE_DNS))
189 { 162 {
190 GNUNET_break (0); 163 GNUNET_break (0);
191 GNUNET_CLIENT_disconnect (dns_connection, GNUNET_NO); 164 GNUNET_CLIENT_disconnect (h->dns_connection, GNUNET_NO);
192 dns_connection = NULL; 165 h->dns_connection = NULL;
166#if 0
193 conn_task = GNUNET_SCHEDULER_add_now (&connect_to_service_dns, NULL); 167 conn_task = GNUNET_SCHEDULER_add_now (&connect_to_service_dns, NULL);
168#endif
194 return; 169 return;
195 } 170 }
196 void *pkt = GNUNET_malloc (ntohs (msg->size)); 171 void *pkt = GNUNET_malloc (ntohs (msg->size));
197 172
198 memcpy (pkt, msg, ntohs (msg->size)); 173 memcpy (pkt, msg, ntohs (msg->size));
199 174
200 GNUNET_SCHEDULER_add_now (process_answer, pkt); 175 GNUNET_SCHEDULER_add_now (h->process_answer_cb, pkt);
201 GNUNET_CLIENT_receive (dns_connection, &dns_answer_handler, NULL, 176 GNUNET_CLIENT_receive (h->dns_connection, &dns_answer_handler, h,
202 GNUNET_TIME_UNIT_FOREVER_REL); 177 GNUNET_TIME_UNIT_FOREVER_REL);
203} 178}
179
180
181/**
182 * Connect to the service-dns
183 */
184struct GNUNET_DNS_Handle *
185GNUNET_DNS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
186 GNUNET_SCHEDULER_Task cb,
187 void *cb_cls)
188{
189 struct GNUNET_DNS_Handle *h;
190
191 h = GNUNET_malloc (sizeof (struct GNUNET_DNS_Handle));
192 h->cfg = cfg;
193 h->process_answer_cb = cb;
194 h->process_answer_cb_cls = cb_cls;
195 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting to service-dns\n");
196 h->dns_connection = GNUNET_CLIENT_connect ("dns", h->cfg);
197 /* This would most likely be a misconfiguration */
198 GNUNET_assert (NULL != h->dns_connection);
199 GNUNET_CLIENT_receive (h->dns_connection,
200 &dns_answer_handler, NULL,
201 GNUNET_TIME_UNIT_FOREVER_REL);
202 /* If a packet is already in the list, schedule to send it */
203 if (h->dns_transmit_handle == NULL && h->head != NULL)
204 h->dns_transmit_handle =
205 GNUNET_CLIENT_notify_transmit_ready (h->dns_connection,
206 ntohs (h->head->pkt.hdr.size),
207 GNUNET_TIME_UNIT_FOREVER_REL,
208 GNUNET_YES, &send_query, h);
209 else if (h->dns_transmit_handle == NULL && h->restart_hijack == 1)
210 {
211 h->dns_transmit_handle =
212 GNUNET_CLIENT_notify_transmit_ready (h->dns_connection,
213 sizeof (struct
214 GNUNET_MessageHeader),
215 GNUNET_TIME_UNIT_FOREVER_REL,
216 GNUNET_YES, &send_query, NULL);
217 }
218 return h;
219}
220
221
222void
223GNUNET_DNS_restart_hijack (struct GNUNET_DNS_Handle *h)
224{
225 h->restart_hijack = 1;
226 if (NULL != h->dns_connection && h->dns_transmit_handle == NULL)
227 h->dns_transmit_handle =
228 GNUNET_CLIENT_notify_transmit_ready (h->dns_connection,
229 sizeof (struct
230 GNUNET_MessageHeader),
231 GNUNET_TIME_UNIT_FOREVER_REL,
232 GNUNET_YES, &send_query, h);
233}
234
235
236/**
237 * FIXME: we should not expost our internal structures like this.
238 * Just a quick initial hack.
239 */
240void
241GNUNET_DNS_queue_request (struct GNUNET_DNS_Handle *h,
242 struct query_packet_list *q)
243{
244 GNUNET_CONTAINER_DLL_insert_tail (h->head, h->tail, q);
245 if (h->dns_connection != NULL && h->dns_transmit_handle == NULL)
246 h->dns_transmit_handle =
247 GNUNET_CLIENT_notify_transmit_ready (h->dns_connection, ntohs(q->pkt.hdr.size),
248 GNUNET_TIME_UNIT_FOREVER_REL,
249 GNUNET_YES, &send_query,
250 h);
251}
252
253
254void
255GNUNET_DNS_disconnect (struct GNUNET_DNS_Handle *h)
256{
257 if (h->dns_connection != NULL)
258 {
259 GNUNET_CLIENT_disconnect (h->dns_connection, GNUNET_NO);
260 h->dns_connection = NULL;
261 }
262 GNUNET_free (h);
263}
diff --git a/src/include/gnunet_dns_service.h b/src/include/gnunet_dns_service.h
index 2423009eb..4dcf6c375 100644
--- a/src/include/gnunet_dns_service.h
+++ b/src/include/gnunet_dns_service.h
@@ -29,6 +29,7 @@
29#define GNUNET_DNS_SERVICE_H 29#define GNUNET_DNS_SERVICE_H
30 30
31#include "gnunet_common.h" 31#include "gnunet_common.h"
32#include "gnunet_util_lib.h"
32 33
33GNUNET_NETWORK_STRUCT_BEGIN 34GNUNET_NETWORK_STRUCT_BEGIN
34 35
@@ -140,4 +141,29 @@ struct answer_packet_list
140}; 141};
141GNUNET_NETWORK_STRUCT_END 142GNUNET_NETWORK_STRUCT_END
142 143
144struct GNUNET_DNS_Handle;
145
146/**
147 * Connect to the service-dns
148 */
149struct GNUNET_DNS_Handle *
150GNUNET_DNS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
151 GNUNET_SCHEDULER_Task cb,
152 void *cb_cls);
153
154void
155GNUNET_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 */
162void
163GNUNET_DNS_queue_request (struct GNUNET_DNS_Handle *h,
164 struct query_packet_list *q);
165
166void
167GNUNET_DNS_disconnect (struct GNUNET_DNS_Handle *h);
168
143#endif 169#endif
diff --git a/src/vpn/Makefile.am b/src/vpn/Makefile.am
index dfba44f0a..13928dba3 100644
--- a/src/vpn/Makefile.am
+++ b/src/vpn/Makefile.am
@@ -35,7 +35,6 @@ gnunet_helper_vpn_SOURCES = \
35gnunet_daemon_vpn_SOURCES = \ 35gnunet_daemon_vpn_SOURCES = \
36 gnunet-daemon-vpn.c gnunet-daemon-vpn.h \ 36 gnunet-daemon-vpn.c gnunet-daemon-vpn.h \
37 gnunet-daemon-vpn-helper.c gnunet-daemon-vpn-helper.h \ 37 gnunet-daemon-vpn-helper.c gnunet-daemon-vpn-helper.h \
38 gnunet-daemon-vpn-dns.c gnunet-daemon-vpn-dns.h \
39 gnunet-helper-vpn-api.c gnunet-helper-vpn-api.h \ 38 gnunet-helper-vpn-api.c gnunet-helper-vpn-api.h \
40 gnunet-vpn-checksum.c gnunet-vpn-checksum.h 39 gnunet-vpn-checksum.c gnunet-vpn-checksum.h
41gnunet_daemon_vpn_LDADD = \ 40gnunet_daemon_vpn_LDADD = \
@@ -44,6 +43,7 @@ gnunet_daemon_vpn_LDADD = \
44 $(top_builddir)/src/util/libgnunetutil.la \ 43 $(top_builddir)/src/util/libgnunetutil.la \
45 $(top_builddir)/src/mesh/libgnunetmesh.la \ 44 $(top_builddir)/src/mesh/libgnunetmesh.la \
46 $(top_builddir)/src/dns/libgnunetdnsparser.la \ 45 $(top_builddir)/src/dns/libgnunetdnsparser.la \
46 $(top_builddir)/src/dns/libgnunetdns.la \
47 $(GN_LIBINTL) 47 $(GN_LIBINTL)
48 48
49gnunet_daemon_exit_SOURCES = \ 49gnunet_daemon_exit_SOURCES = \
diff --git a/src/vpn/gnunet-daemon-vpn-dns.h b/src/vpn/gnunet-daemon-vpn-dns.h
deleted file mode 100644
index 0cd0d8b26..000000000
--- a/src/vpn/gnunet-daemon-vpn-dns.h
+++ /dev/null
@@ -1,88 +0,0 @@
1/*
2 This file is part of GNUnet.
3 (C) 2010 Christian Grothoff
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 vpn/gnunet-daemon-vpn-dns.h
23 * @brief
24 * @author Philipp Toelke
25 */
26#ifndef GNUNET_DAEMON_VPN_DNS_H
27#define GNUNET_DAEMON_VPN_DNS_H
28
29/**
30 * a list of outgoing dns-query-packets
31 */
32extern struct query_packet_list *head;
33
34/**
35 * The last element of the list of outgoing dns-query-packets
36 */
37extern struct query_packet_list *tail;
38
39/**
40 * Callback called by notify_transmit_ready; sends dns-queries or rehijack-messages
41 * to the service-dns
42 */
43size_t
44send_query (void *cls, size_t size, void *buf);
45
46/**
47 * Connect to the service-dns
48 */
49void
50connect_to_service_dns (void *cls,
51 const struct GNUNET_SCHEDULER_TaskContext *tc);
52
53/**
54 * This receives packets from the service-dns and schedules process_answer to
55 * handle it
56 */
57void
58dns_answer_handler (void *cls, const struct GNUNET_MessageHeader *msg);
59
60/**
61 * The connection to the service-dns
62 */
63extern struct GNUNET_CLIENT_Connection *dns_connection;
64
65/**
66 * A flag to show that the service-dns has to rehijack the outbound dns-packets
67 *
68 * This gets set when the helper restarts as the routing-tables are flushed when
69 * the interface vanishes.
70 */
71extern unsigned char restart_hijack;
72
73/**
74 * A list of processed dns-responses.
75 *
76 * "processed" means that the packet is complete and can be sent out via udp
77 * directly
78 */
79extern struct answer_packet_list *answer_proc_head;
80
81/**
82 * The last element of the list of processed dns-responses.
83 */
84extern struct answer_packet_list *answer_proc_tail;
85
86extern GNUNET_SCHEDULER_TaskIdentifier conn_task;
87
88#endif /* end of include guard: GNUNET-DAEMON-VPN-DNS_H */
diff --git a/src/vpn/gnunet-daemon-vpn-helper.c b/src/vpn/gnunet-daemon-vpn-helper.c
index 8f295506a..984b126e7 100644
--- a/src/vpn/gnunet-daemon-vpn-helper.c
+++ b/src/vpn/gnunet-daemon-vpn-helper.c
@@ -34,8 +34,8 @@
34#include <block_dns.h> 34#include <block_dns.h>
35#include <gnunet_configuration_lib.h> 35#include <gnunet_configuration_lib.h>
36#include <gnunet_applications.h> 36#include <gnunet_applications.h>
37#include <gnunet_dns_service.h>
37 38
38#include "gnunet-daemon-vpn-dns.h"
39#include "gnunet-daemon-vpn.h" 39#include "gnunet-daemon-vpn.h"
40#include "gnunet-daemon-vpn-helper.h" 40#include "gnunet-daemon-vpn-helper.h"
41#include "gnunet-vpn-packet.h" 41#include "gnunet-vpn-packet.h"
@@ -137,15 +137,7 @@ start_helper_and_schedule (void *cls,
137 /* Tell the dns-service to rehijack the dns-port 137 /* Tell the dns-service to rehijack the dns-port
138 * The routing-table gets flushed if an interface disappears. 138 * The routing-table gets flushed if an interface disappears.
139 */ 139 */
140 restart_hijack = 1; 140 GNUNET_DNS_restart_hijack (dns_handle);
141 if (NULL != dns_connection && dns_transmit_handle == NULL)
142 dns_transmit_handle =
143 GNUNET_CLIENT_notify_transmit_ready (dns_connection,
144 sizeof (struct
145 GNUNET_MessageHeader),
146 GNUNET_TIME_UNIT_FOREVER_REL,
147 GNUNET_YES, &send_query, NULL);
148
149 GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL, 141 GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
150 helper_handle->fh_to_helper, &helper_write, 142 helper_handle->fh_to_helper, &helper_write,
151 NULL); 143 NULL);
@@ -361,17 +353,7 @@ message_token (void *cls GNUNET_UNUSED, void *client GNUNET_UNUSED,
361 query->pkt.src_port = pkt6_udp->udp_hdr.spt; 353 query->pkt.src_port = pkt6_udp->udp_hdr.spt;
362 memcpy (query->pkt.data, pkt6_udp->data, 354 memcpy (query->pkt.data, pkt6_udp->data,
363 ntohs (pkt6_udp->udp_hdr.len) - 8); 355 ntohs (pkt6_udp->udp_hdr.len) - 8);
364 356 GNUNET_DNS_queue_request (dns_handle, query);
365 GNUNET_CONTAINER_DLL_insert_after (head, tail, tail, query);
366
367 GNUNET_assert (head != NULL);
368
369 if (dns_connection != NULL && dns_transmit_handle == NULL)
370 dns_transmit_handle =
371 GNUNET_CLIENT_notify_transmit_ready (dns_connection, len,
372 GNUNET_TIME_UNIT_FOREVER_REL,
373 GNUNET_YES, &send_query,
374 NULL);
375 break; 357 break;
376 } 358 }
377 /* fall through */ 359 /* fall through */
@@ -559,16 +541,8 @@ message_token (void *cls GNUNET_UNUSED, void *client GNUNET_UNUSED,
559 query->pkt.addrlen = 4; 541 query->pkt.addrlen = 4;
560 query->pkt.src_port = udp->udp_hdr.spt; 542 query->pkt.src_port = udp->udp_hdr.spt;
561 memcpy (query->pkt.data, udp->data, ntohs (udp->udp_hdr.len) - 8); 543 memcpy (query->pkt.data, udp->data, ntohs (udp->udp_hdr.len) - 8);
562 544
563 GNUNET_CONTAINER_DLL_insert_after (head, tail, tail, query); 545 GNUNET_DNS_queue_request (dns_handle, query);
564
565 GNUNET_assert (head != NULL);
566
567 if (dns_connection != NULL && dns_transmit_handle == NULL)
568 dns_transmit_handle =
569 GNUNET_CLIENT_notify_transmit_ready (dns_connection, len,
570 GNUNET_TIME_UNIT_FOREVER_REL,
571 GNUNET_YES, &send_query, NULL);
572 } 546 }
573 else 547 else
574 { 548 {
diff --git a/src/vpn/gnunet-daemon-vpn.c b/src/vpn/gnunet-daemon-vpn.c
index 6b65b709e..86f08d19c 100644
--- a/src/vpn/gnunet-daemon-vpn.c
+++ b/src/vpn/gnunet-daemon-vpn.c
@@ -36,7 +36,7 @@
36#include "gnunet_constants.h" 36#include "gnunet_constants.h"
37#include <block_dns.h> 37#include <block_dns.h>
38#include "gnunet-daemon-vpn-helper.h" 38#include "gnunet-daemon-vpn-helper.h"
39#include "gnunet-daemon-vpn-dns.h" 39#include "gnunet_dns_service.h"
40#include "gnunet-daemon-vpn.h" 40#include "gnunet-daemon-vpn.h"
41#include "gnunet-vpn-checksum.h" 41#include "gnunet-vpn-checksum.h"
42 42
@@ -45,6 +45,13 @@ struct GNUNET_MESH_Handle *mesh_handle;
45struct GNUNET_CONTAINER_MultiHashMap *hashmap; 45struct GNUNET_CONTAINER_MultiHashMap *hashmap;
46static struct GNUNET_CONTAINER_Heap *heap; 46static struct GNUNET_CONTAINER_Heap *heap;
47 47
48struct GNUNET_DNS_Handle *dns_handle;
49
50struct answer_packet_list *answer_proc_head;
51
52struct answer_packet_list *answer_proc_tail;
53
54
48struct tunnel_notify_queue 55struct tunnel_notify_queue
49{ 56{
50 struct tunnel_notify_queue *next; 57 struct tunnel_notify_queue *next;
@@ -87,12 +94,7 @@ cleanup (void *cls GNUNET_UNUSED,
87 cleanup_helper (helper_handle); 94 cleanup_helper (helper_handle);
88 95
89 /* close the connection to the service-dns */ 96 /* close the connection to the service-dns */
90 if (dns_connection != NULL) 97 GNUNET_DNS_disconnect (dns_handle);
91 {
92 GNUNET_CLIENT_disconnect (dns_connection, GNUNET_NO);
93 dns_connection = NULL;
94 }
95
96 if (mesh_handle != NULL) 98 if (mesh_handle != NULL)
97 { 99 {
98 GNUNET_MESH_disconnect (mesh_handle); 100 GNUNET_MESH_disconnect (mesh_handle);
@@ -1258,13 +1260,14 @@ run (void *cls, char *const *args GNUNET_UNUSED,
1258 GNUNET_MESH_connect (cfg_, 42, NULL, new_tunnel, cleaner, handlers, 1260 GNUNET_MESH_connect (cfg_, 42, NULL, new_tunnel, cleaner, handlers,
1259 types); 1261 types);
1260 cfg = cfg_; 1262 cfg = cfg_;
1261 restart_hijack = 0;
1262 hashmap = GNUNET_CONTAINER_multihashmap_create (65536); 1263 hashmap = GNUNET_CONTAINER_multihashmap_create (65536);
1263 heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); 1264 heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
1264 GNUNET_CONFIGURATION_get_value_number (cfg, "vpn", "MAX_MAPPINGg", 1265 GNUNET_CONFIGURATION_get_value_number (cfg, "vpn", "MAX_MAPPINGg",
1265 &max_mappings); 1266 &max_mappings);
1266 udp_connections = GNUNET_CONTAINER_multihashmap_create (65536); 1267 udp_connections = GNUNET_CONTAINER_multihashmap_create (65536);
1267 conn_task = GNUNET_SCHEDULER_add_now (connect_to_service_dns, NULL); 1268 dns_handle = GNUNET_DNS_connect (cfg,
1269 &process_answer,
1270 NULL);
1268 shs_task = 1271 shs_task =
1269 GNUNET_SCHEDULER_add_after (conn_task, start_helper_and_schedule, NULL); 1272 GNUNET_SCHEDULER_add_after (conn_task, start_helper_and_schedule, NULL);
1270 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup, cls); 1273 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup, cls);
diff --git a/src/vpn/gnunet-daemon-vpn.h b/src/vpn/gnunet-daemon-vpn.h
index c8bf91ebb..35520a277 100644
--- a/src/vpn/gnunet-daemon-vpn.h
+++ b/src/vpn/gnunet-daemon-vpn.h
@@ -28,6 +28,12 @@
28 28
29#include "gnunet_dns_service.h" 29#include "gnunet_dns_service.h"
30 30
31extern struct answer_packet_list *answer_proc_head;
32
33extern struct answer_packet_list *answer_proc_tail;
34
35extern struct GNUNET_DNS_Handle *dns_handle;
36
31/** 37/**
32 * This gets scheduled with cls pointing to an answer_packet and does everything 38 * This gets scheduled with cls pointing to an answer_packet and does everything
33 * needed in order to send it to the helper. 39 * needed in order to send it to the helper.