aboutsummaryrefslogtreecommitdiff
path: root/src/vpn
diff options
context:
space:
mode:
authorPhilipp Tölke <toelke@in.tum.de>2011-10-30 19:35:19 +0000
committerPhilipp Tölke <toelke@in.tum.de>2011-10-30 19:35:19 +0000
commit170a309a6d37b5fd0309856bb71656664ca3db6d (patch)
treeaeb4c490aa827473880a90990e879481bf075e25 /src/vpn
parent6813281cd9f9eac5e6d285fb87725d5d71b76ebb (diff)
downloadgnunet-170a309a6d37b5fd0309856bb71656664ca3db6d.tar.gz
gnunet-170a309a6d37b5fd0309856bb71656664ca3db6d.zip
gnunet-service-dns uses the new mesh
Diffstat (limited to 'src/vpn')
-rw-r--r--src/vpn/Makefile.am2
-rw-r--r--src/vpn/gnunet-service-dns.c114
2 files changed, 64 insertions, 52 deletions
diff --git a/src/vpn/Makefile.am b/src/vpn/Makefile.am
index a81a71838..7999990fe 100644
--- a/src/vpn/Makefile.am
+++ b/src/vpn/Makefile.am
@@ -53,7 +53,7 @@ gnunet_service_dns_LDADD = \
53 $(top_builddir)/src/statistics/libgnunetstatistics.la \ 53 $(top_builddir)/src/statistics/libgnunetstatistics.la \
54 $(top_builddir)/src/util/libgnunetutil.la \ 54 $(top_builddir)/src/util/libgnunetutil.la \
55 $(top_builddir)/src/dht/libgnunetdht.la \ 55 $(top_builddir)/src/dht/libgnunetdht.la \
56 $(top_builddir)/src/mesh/libgnunetmesh.la \ 56 $(top_builddir)/src/mesh/libgnunetmeshnew.la \
57 $(GN_LIBINTL) 57 $(GN_LIBINTL)
58 58
59gnunet_daemon_exit_SOURCES = \ 59gnunet_daemon_exit_SOURCES = \
diff --git a/src/vpn/gnunet-service-dns.c b/src/vpn/gnunet-service-dns.c
index 00d93ab24..df9d74163 100644
--- a/src/vpn/gnunet-service-dns.c
+++ b/src/vpn/gnunet-service-dns.c
@@ -38,7 +38,7 @@
38#include "gnunet_block_lib.h" 38#include "gnunet_block_lib.h"
39#include "block_dns.h" 39#include "block_dns.h"
40#include "gnunet_crypto_lib.h" 40#include "gnunet_crypto_lib.h"
41#include "gnunet_mesh_service.h" 41#include "gnunet_mesh_service_new.h"
42#include "gnunet_signatures.h" 42#include "gnunet_signatures.h"
43 43
44struct GNUNET_MESH_Handle *mesh_handle; 44struct GNUNET_MESH_Handle *mesh_handle;
@@ -119,6 +119,12 @@ struct tunnel_notify_queue
119 GNUNET_CONNECTION_TransmitReadyNotify cb; 119 GNUNET_CONNECTION_TransmitReadyNotify cb;
120}; 120};
121 121
122struct tunnel_state
123{
124 struct tunnel_notify_queue *head,*tail;
125 struct GNUNET_MESH_TransmitHandle *th;
126};
127
122/** 128/**
123 * Hijack all outgoing DNS-Traffic but for traffic leaving "our" port. 129 * Hijack all outgoing DNS-Traffic but for traffic leaving "our" port.
124 */ 130 */
@@ -162,6 +168,27 @@ hijack (void *cls
162 GNUNET_free (virt_dns); 168 GNUNET_free (virt_dns);
163} 169}
164 170
171static void *
172new_tunnel (void *cls __attribute__((unused)),
173 struct GNUNET_MESH_Tunnel *tunnel,
174 const struct GNUNET_PeerIdentity *initiator __attribute__((unused)),
175 const struct GNUNET_ATS_Information *ats __attribute__((unused)))
176{
177 struct tunnel_state *s = GNUNET_malloc(sizeof *s);
178 s->head = NULL;
179 s->tail = NULL;
180 s->th = NULL;
181 return s;
182}
183
184static void
185clean_tunnel (void *cls __attribute__((unused)),
186 const struct GNUNET_MESH_Tunnel *tunnel,
187 void *tunnel_ctx)
188{
189 GNUNET_free(tunnel_ctx);
190}
191
165/** 192/**
166 * Delete the hijacking-routes 193 * Delete the hijacking-routes
167 */ 194 */
@@ -252,18 +279,16 @@ mesh_send_response (void *cls, size_t size, void *buf)
252 GNUNET_assert (size >= (*sz + sizeof (struct GNUNET_MessageHeader))); 279 GNUNET_assert (size >= (*sz + sizeof (struct GNUNET_MessageHeader)));
253 280
254 memcpy (hdr + 1, dns, *sz); 281 memcpy (hdr + 1, dns, *sz);
255 282 struct tunnel_state *s = GNUNET_MESH_tunnel_get_data(*tunnel);
256 if (NULL != GNUNET_MESH_tunnel_get_head (*tunnel)) 283 if (NULL != s->head)
257 { 284 {
258 struct tunnel_notify_queue *element = GNUNET_MESH_tunnel_get_head (*tunnel); 285 struct tunnel_notify_queue *element = s->head;
259 struct tunnel_notify_queue *head = GNUNET_MESH_tunnel_get_head (*tunnel); 286 struct tunnel_notify_queue *head = s->head;
260 struct tunnel_notify_queue *tail = GNUNET_MESH_tunnel_get_tail (*tunnel); 287 struct tunnel_notify_queue *tail = s->tail;
261 288
262 GNUNET_CONTAINER_DLL_remove (head, tail, element); 289 GNUNET_CONTAINER_DLL_remove (head, tail, element);
263 290
264 GNUNET_MESH_tunnel_set_head (*tunnel, head); 291 s->th =
265 GNUNET_MESH_tunnel_set_tail (*tunnel, tail);
266 struct GNUNET_MESH_TransmitHandle *th =
267 GNUNET_MESH_notify_transmit_ready (*tunnel, 292 GNUNET_MESH_notify_transmit_ready (*tunnel,
268 GNUNET_NO, 293 GNUNET_NO,
269 42, 294 42,
@@ -272,9 +297,6 @@ mesh_send_response (void *cls, size_t size, void *buf)
272 (const struct GNUNET_PeerIdentity *) 297 (const struct GNUNET_PeerIdentity *)
273 NULL, element->len, 298 NULL, element->len,
274 element->cb, element->cls); 299 element->cb, element->cls);
275
276 /* save the handle */
277 GNUNET_MESH_tunnel_set_data (*tunnel, th);
278 } 300 }
279 301
280 GNUNET_free (cls); 302 GNUNET_free (cls);
@@ -296,20 +318,19 @@ mesh_send (void *cls, size_t size, void *buf)
296 318
297 memcpy (buf, &cls_->hdr, size); 319 memcpy (buf, &cls_->hdr, size);
298 320
299 if (NULL != GNUNET_MESH_tunnel_get_head (cls_->tunnel)) 321 struct tunnel_state *s = GNUNET_MESH_tunnel_get_data(cls_->tunnel);
322 if (NULL != s->head)
300 { 323 {
301 struct tunnel_notify_queue *element = 324 struct tunnel_notify_queue *element =
302 GNUNET_MESH_tunnel_get_head (cls_->tunnel); 325 s->head;
303 struct tunnel_notify_queue *head = 326 struct tunnel_notify_queue *head =
304 GNUNET_MESH_tunnel_get_head (cls_->tunnel); 327 s->head;
305 struct tunnel_notify_queue *tail = 328 struct tunnel_notify_queue *tail =
306 GNUNET_MESH_tunnel_get_tail (cls_->tunnel); 329 s->tail;;
307 330
308 GNUNET_CONTAINER_DLL_remove (head, tail, element); 331 GNUNET_CONTAINER_DLL_remove (head, tail, element);
309 332
310 GNUNET_MESH_tunnel_set_head (cls_->tunnel, head); 333 s->th =
311 GNUNET_MESH_tunnel_set_tail (cls_->tunnel, tail);
312 struct GNUNET_MESH_TransmitHandle *th =
313 GNUNET_MESH_notify_transmit_ready (cls_->tunnel, 334 GNUNET_MESH_notify_transmit_ready (cls_->tunnel,
314 GNUNET_NO, 335 GNUNET_NO,
315 42, 336 42,
@@ -319,8 +340,6 @@ mesh_send (void *cls, size_t size, void *buf)
319 NULL, element->len, 340 NULL, element->len,
320 element->cb, element->cls); 341 element->cb, element->cls);
321 342
322 /* save the handle */
323 GNUNET_MESH_tunnel_set_data (cls_->tunnel, th);
324 GNUNET_free (element); 343 GNUNET_free (element);
325 } 344 }
326 345
@@ -331,9 +350,7 @@ mesh_send (void *cls, size_t size, void *buf)
331void 350void
332mesh_connect (void *cls, const struct GNUNET_PeerIdentity *peer, 351mesh_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
333 const struct GNUNET_ATS_Information *atsi 352 const struct GNUNET_ATS_Information *atsi
334 __attribute__ ((unused)), 353 __attribute__ ((unused)))
335 unsigned int atsi_count
336 __attribute__ ((unused)))
337{ 354{
338 if (NULL == peer) 355 if (NULL == peer)
339 return; 356 return;
@@ -343,9 +360,10 @@ mesh_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
343 "Connected to peer %s, %x, sending query with id %d\n", 360 "Connected to peer %s, %x, sending query with id %d\n",
344 GNUNET_i2s (peer), peer, ntohs (cls_->dns.s.id)); 361 GNUNET_i2s (peer), peer, ntohs (cls_->dns.s.id));
345 362
346 if (NULL == GNUNET_MESH_tunnel_get_data (cls_->tunnel)) 363 struct tunnel_state *s = GNUNET_MESH_tunnel_get_data(cls_->tunnel);
364 if (NULL == s->head)
347 { 365 {
348 struct GNUNET_MESH_TransmitHandle *th = 366 s->th =
349 GNUNET_MESH_notify_transmit_ready (cls_->tunnel, 367 GNUNET_MESH_notify_transmit_ready (cls_->tunnel,
350 GNUNET_YES, 368 GNUNET_YES,
351 42, 369 42,
@@ -355,14 +373,13 @@ mesh_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
355 mesh_send, 373 mesh_send,
356 cls); 374 cls);
357 375
358 GNUNET_MESH_tunnel_set_data (cls_->tunnel, th);
359 } 376 }
360 else 377 else
361 { 378 {
362 struct tunnel_notify_queue *head = 379 struct tunnel_notify_queue *head =
363 GNUNET_MESH_tunnel_get_head (cls_->tunnel); 380 s->head;
364 struct tunnel_notify_queue *tail = 381 struct tunnel_notify_queue *tail =
365 GNUNET_MESH_tunnel_get_tail (cls_->tunnel); 382 s->tail;
366 383
367 struct tunnel_notify_queue *element = 384 struct tunnel_notify_queue *element =
368 GNUNET_malloc (sizeof (struct tunnel_notify_queue)); 385 GNUNET_malloc (sizeof (struct tunnel_notify_queue));
@@ -371,8 +388,6 @@ mesh_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
371 element->cb = mesh_send; 388 element->cb = mesh_send;
372 389
373 GNUNET_CONTAINER_DLL_insert_tail (head, tail, element); 390 GNUNET_CONTAINER_DLL_insert_tail (head, tail, element);
374 GNUNET_MESH_tunnel_set_head (cls_->tunnel, head);
375 GNUNET_MESH_tunnel_set_tail (cls_->tunnel, tail);
376 } 391 }
377} 392}
378 393
@@ -385,11 +400,16 @@ send_mesh_query (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
385 400
386 struct tunnel_cls *cls_ = (struct tunnel_cls *) cls; 401 struct tunnel_cls *cls_ = (struct tunnel_cls *) cls;
387 402
403 struct tunnel_state *s = GNUNET_malloc(sizeof *s);
404 s->head = NULL;
405 s->tail = NULL;
406 s->th = NULL;
407
388 cls_->tunnel = 408 cls_->tunnel =
389 GNUNET_MESH_peer_request_connect_by_type (mesh_handle, 409 GNUNET_MESH_tunnel_create(mesh_handle, s, mesh_connect, NULL, cls_);
390 GNUNET_TIME_UNIT_HOURS, 410
391 GNUNET_APPLICATION_TYPE_INTERNET_RESOLVER, 411 GNUNET_MESH_peer_request_connect_by_type (cls_->tunnel,
392 mesh_connect, NULL, cls_); 412 GNUNET_APPLICATION_TYPE_INTERNET_RESOLVER);
393 413
394 remote_pending[cls_->dns.s.id] = cls_; 414 remote_pending[cls_->dns.s.id] = cls_;
395} 415}
@@ -403,9 +423,7 @@ receive_mesh_query (void *cls
403 __attribute__ ((unused)), 423 __attribute__ ((unused)),
404 const struct GNUNET_MessageHeader *message, 424 const struct GNUNET_MessageHeader *message,
405 const struct GNUNET_ATS_Information *atsi 425 const struct GNUNET_ATS_Information *atsi
406 __attribute__ ((unused)), 426 __attribute__ ((unused)))
407 unsigned int atsi_count
408 __attribute__ ((unused)))
409{ 427{
410 struct dns_pkt *dns = (struct dns_pkt *) (message + 1); 428 struct dns_pkt *dns = (struct dns_pkt *) (message + 1);
411 429
@@ -453,9 +471,7 @@ receive_mesh_answer (void *cls
453 const struct GNUNET_PeerIdentity *sender, 471 const struct GNUNET_PeerIdentity *sender,
454 const struct GNUNET_MessageHeader *message, 472 const struct GNUNET_MessageHeader *message,
455 const struct GNUNET_ATS_Information *atsi 473 const struct GNUNET_ATS_Information *atsi
456 __attribute__ ((unused)), 474 __attribute__ ((unused)))
457 unsigned int atsi_count
458 __attribute__ ((unused)))
459{ 475{
460 /* TODo: size check */ 476 /* TODo: size check */
461 struct dns_pkt *dns = (struct dns_pkt *) (message + 1); 477 struct dns_pkt *dns = (struct dns_pkt *) (message + 1);
@@ -1282,10 +1298,10 @@ handle_response(struct dns_pkt* dns, struct sockaddr *addr, socklen_t addrlen, i
1282 1298
1283 *t = query_states[dns->s.id].tunnel; 1299 *t = query_states[dns->s.id].tunnel;
1284 memcpy (t + 1, dns, r); 1300 memcpy (t + 1, dns, r);
1285 if (NULL == 1301 struct tunnel_state *s = GNUNET_MESH_tunnel_get_data (query_states[dns->s.id].tunnel);
1286 GNUNET_MESH_tunnel_get_data (query_states[dns->s.id].tunnel)) 1302 if (NULL == s->th)
1287 { 1303 {
1288 struct GNUNET_MESH_TransmitHandle *th = 1304 s->th =
1289 GNUNET_MESH_notify_transmit_ready (query_states[dns->s.id].tunnel, 1305 GNUNET_MESH_notify_transmit_ready (query_states[dns->s.id].tunnel,
1290 GNUNET_YES, 1306 GNUNET_YES,
1291 32, 1307 32,
@@ -1295,15 +1311,13 @@ handle_response(struct dns_pkt* dns, struct sockaddr *addr, socklen_t addrlen, i
1295 sizeof (struct 1311 sizeof (struct
1296 GNUNET_MessageHeader), 1312 GNUNET_MessageHeader),
1297 mesh_send_response, c); 1313 mesh_send_response, c);
1298
1299 GNUNET_MESH_tunnel_set_data (query_states[dns->s.id].tunnel, th);
1300 } 1314 }
1301 else 1315 else
1302 { 1316 {
1303 struct tunnel_notify_queue *head = 1317 struct tunnel_notify_queue *head =
1304 GNUNET_MESH_tunnel_get_head (query_states[dns->s.id].tunnel); 1318 s->head;
1305 struct tunnel_notify_queue *tail = 1319 struct tunnel_notify_queue *tail =
1306 GNUNET_MESH_tunnel_get_tail (query_states[dns->s.id].tunnel); 1320 s->tail;
1307 1321
1308 struct tunnel_notify_queue *element = 1322 struct tunnel_notify_queue *element =
1309 GNUNET_malloc (sizeof (struct tunnel_notify_queue)); 1323 GNUNET_malloc (sizeof (struct tunnel_notify_queue));
@@ -1312,8 +1326,6 @@ handle_response(struct dns_pkt* dns, struct sockaddr *addr, socklen_t addrlen, i
1312 element->cb = mesh_send_response; 1326 element->cb = mesh_send_response;
1313 1327
1314 GNUNET_CONTAINER_DLL_insert_tail (head, tail, element); 1328 GNUNET_CONTAINER_DLL_insert_tail (head, tail, element);
1315 GNUNET_MESH_tunnel_set_head (query_states[dns->s.id].tunnel, head);
1316 GNUNET_MESH_tunnel_set_tail (query_states[dns->s.id].tunnel, tail);
1317 } 1329 }
1318 } 1330 }
1319 else 1331 else
@@ -1649,7 +1661,7 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
1649 if (GNUNET_YES == 1661 if (GNUNET_YES ==
1650 GNUNET_CONFIGURATION_get_value_yesno (cfg_, "dns", "PROVIDE_EXIT")) 1662 GNUNET_CONFIGURATION_get_value_yesno (cfg_, "dns", "PROVIDE_EXIT"))
1651 apptypes[0] = GNUNET_APPLICATION_TYPE_INTERNET_RESOLVER; 1663 apptypes[0] = GNUNET_APPLICATION_TYPE_INTERNET_RESOLVER;
1652 mesh_handle = GNUNET_MESH_connect (cfg_, NULL, NULL, mesh_handlers, apptypes); 1664 mesh_handle = GNUNET_MESH_connect (cfg_, 42, NULL, new_tunnel, clean_tunnel, mesh_handlers, apptypes);
1653 1665
1654 cfg = cfg_; 1666 cfg = cfg_;
1655 dht = GNUNET_DHT_connect (cfg, 1024); 1667 dht = GNUNET_DHT_connect (cfg, 1024);