aboutsummaryrefslogtreecommitdiff
path: root/src/vpn/gnunet-daemon-vpn-dns.c
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/vpn/gnunet-daemon-vpn-dns.c
parent3e73780b201b600dd8dd8725f5a628d62d9c4f51 (diff)
downloadgnunet-402a25de1ef93133c9879706071081405ade61f6.tar.gz
gnunet-402a25de1ef93133c9879706071081405ade61f6.zip
first quick hack to extract an initial DNS service API
Diffstat (limited to 'src/vpn/gnunet-daemon-vpn-dns.c')
-rw-r--r--src/vpn/gnunet-daemon-vpn-dns.c203
1 files changed, 0 insertions, 203 deletions
diff --git a/src/vpn/gnunet-daemon-vpn-dns.c b/src/vpn/gnunet-daemon-vpn-dns.c
deleted file mode 100644
index b24d802f7..000000000
--- a/src/vpn/gnunet-daemon-vpn-dns.c
+++ /dev/null
@@ -1,203 +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.c
23 * @brief
24 * @author Philipp Toelke
25 */
26#include <platform.h>
27#include <gnunet_common.h>
28#include <gnunet_client_lib.h>
29#include <gnunet_os_lib.h>
30#include <gnunet_mesh_service.h>
31#include <gnunet_protocols.h>
32#include <gnunet_server_lib.h>
33#include <gnunet_container_lib.h>
34#include <block_dns.h>
35
36#include "gnunet-daemon-vpn-dns.h"
37#include "gnunet-daemon-vpn.h"
38#include "gnunet-daemon-vpn-helper.h"
39#include "gnunet-vpn-packet.h"
40
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
48struct GNUNET_CLIENT_TransmitHandle *dns_transmit_handle;
49
50/**
51 * Callback called by notify_transmit_ready; sends dns-queries or rehijack-messages
52 * to the service-dns
53 * {{{
54 */
55size_t
56send_query (void *cls GNUNET_UNUSED, size_t size, void *buf)
57{
58 size_t len;
59
60 dns_transmit_handle = NULL;
61
62 /*
63 * Send the rehijack-message
64 */
65 if (restart_hijack == 1)
66 {
67 restart_hijack = 0;
68 /*
69 * The message is just a header
70 */
71 GNUNET_assert (sizeof (struct GNUNET_MessageHeader) <= size);
72 struct GNUNET_MessageHeader *hdr = buf;
73
74 len = sizeof (struct GNUNET_MessageHeader);
75 hdr->size = htons (len);
76 hdr->type = htons (GNUNET_MESSAGE_TYPE_REHIJACK);
77 }
78 else if (head != NULL)
79 {
80 struct query_packet_list *query = head;
81
82 len = ntohs (query->pkt.hdr.size);
83
84 GNUNET_assert (len <= size);
85
86 memcpy (buf, &query->pkt.hdr, len);
87
88 GNUNET_CONTAINER_DLL_remove (head, tail, query);
89
90 GNUNET_free (query);
91 }
92 else
93 {
94 GNUNET_break (0);
95 len = 0;
96 }
97
98 /*
99 * Check whether more data is to be sent
100 */
101 if (head != NULL)
102 {
103 dns_transmit_handle =
104 GNUNET_CLIENT_notify_transmit_ready (dns_connection,
105 ntohs (head->pkt.hdr.size),
106 GNUNET_TIME_UNIT_FOREVER_REL,
107 GNUNET_YES, &send_query, NULL);
108 }
109 else if (restart_hijack == 1)
110 {
111 dns_transmit_handle =
112 GNUNET_CLIENT_notify_transmit_ready (dns_connection,
113 sizeof (struct
114 GNUNET_MessageHeader),
115 GNUNET_TIME_UNIT_FOREVER_REL,
116 GNUNET_YES, &send_query, NULL);
117 }
118
119 return len;
120}
121
122/* }}} */
123
124
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
165/**
166 * This receives packets from the service-dns and schedules process_answer to
167 * handle it
168 */
169void
170dns_answer_handler (void *cls GNUNET_UNUSED,
171 const struct GNUNET_MessageHeader *msg)
172{
173 /* the service disconnected, reconnect after short wait */
174 if (msg == NULL)
175 {
176 if (dns_transmit_handle != NULL)
177 GNUNET_CLIENT_notify_transmit_ready_cancel (dns_transmit_handle);
178 dns_transmit_handle = NULL;
179 GNUNET_CLIENT_disconnect (dns_connection, GNUNET_NO);
180 dns_connection = NULL;
181 conn_task =
182 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
183 &connect_to_service_dns, NULL);
184 return;
185 }
186
187 /* the service did something strange, reconnect immediately */
188 if (msg->type != htons (GNUNET_MESSAGE_TYPE_VPN_DNS_LOCAL_RESPONSE_DNS))
189 {
190 GNUNET_break (0);
191 GNUNET_CLIENT_disconnect (dns_connection, GNUNET_NO);
192 dns_connection = NULL;
193 conn_task = GNUNET_SCHEDULER_add_now (&connect_to_service_dns, NULL);
194 return;
195 }
196 void *pkt = GNUNET_malloc (ntohs (msg->size));
197
198 memcpy (pkt, msg, ntohs (msg->size));
199
200 GNUNET_SCHEDULER_add_now (process_answer, pkt);
201 GNUNET_CLIENT_receive (dns_connection, &dns_answer_handler, NULL,
202 GNUNET_TIME_UNIT_FOREVER_REL);
203}