diff options
author | Philipp Tölke <toelke@in.tum.de> | 2011-08-02 07:34:33 +0000 |
---|---|---|
committer | Philipp Tölke <toelke@in.tum.de> | 2011-08-02 07:34:33 +0000 |
commit | ecc8c4da9b35b704b62ff0dc905dcd0a61f1886a (patch) | |
tree | eaacf8854d6da2c18a2324633f0f6779299f76a1 /src/vpn/gnunet-service-dns.c | |
parent | 726c3e734871747854475792050311a4254205ac (diff) | |
download | gnunet-ecc8c4da9b35b704b62ff0dc905dcd0a61f1886a.tar.gz gnunet-ecc8c4da9b35b704b62ff0dc905dcd0a61f1886a.zip |
really reuse the dns-tunnel
Diffstat (limited to 'src/vpn/gnunet-service-dns.c')
-rw-r--r-- | src/vpn/gnunet-service-dns.c | 34 |
1 files changed, 29 insertions, 5 deletions
diff --git a/src/vpn/gnunet-service-dns.c b/src/vpn/gnunet-service-dns.c index ce27fe6a0..f0bbb5c79 100644 --- a/src/vpn/gnunet-service-dns.c +++ b/src/vpn/gnunet-service-dns.c | |||
@@ -48,6 +48,8 @@ struct GNUNET_MESH_Handle *mesh_handle; | |||
48 | */ | 48 | */ |
49 | static struct GNUNET_MESH_Tunnel* dns_tunnel; | 49 | static struct GNUNET_MESH_Tunnel* dns_tunnel; |
50 | 50 | ||
51 | char dns_tunnel_connected; | ||
52 | |||
51 | /** | 53 | /** |
52 | * The UDP-Socket through which DNS-Resolves will be sent if they are not to be | 54 | * The UDP-Socket through which DNS-Resolves will be sent if they are not to be |
53 | * sent through gnunet. The port of this socket will not be hijacked. | 55 | * sent through gnunet. The port of this socket will not be hijacked. |
@@ -230,6 +232,7 @@ mesh_send_response (void *cls, size_t size, void *buf) | |||
230 | struct GNUNET_MessageHeader *hdr = buf; | 232 | struct GNUNET_MessageHeader *hdr = buf; |
231 | uint32_t *sz = cls; | 233 | uint32_t *sz = cls; |
232 | struct GNUNET_MESH_Tunnel **tunnel = (struct GNUNET_MESH_Tunnel**)(sz+1); | 234 | struct GNUNET_MESH_Tunnel **tunnel = (struct GNUNET_MESH_Tunnel**)(sz+1); |
235 | GNUNET_MESH_tunnel_set_data(*tunnel, NULL); | ||
233 | struct dns_pkt *dns = (struct dns_pkt *) (tunnel + 1); | 236 | struct dns_pkt *dns = (struct dns_pkt *) (tunnel + 1); |
234 | hdr->type = htons (GNUNET_MESSAGE_TYPE_REMOTE_ANSWER_DNS); | 237 | hdr->type = htons (GNUNET_MESSAGE_TYPE_REMOTE_ANSWER_DNS); |
235 | hdr->size = htons (*sz + sizeof (struct GNUNET_MessageHeader)); | 238 | hdr->size = htons (*sz + sizeof (struct GNUNET_MessageHeader)); |
@@ -314,12 +317,17 @@ mesh_connect (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
314 | const struct GNUNET_TRANSPORT_ATS_Information *atsi | 317 | const struct GNUNET_TRANSPORT_ATS_Information *atsi |
315 | __attribute__ ((unused))) | 318 | __attribute__ ((unused))) |
316 | { | 319 | { |
320 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "mesh_connect called with %x, %x\n", cls, peer); | ||
321 | return; | ||
317 | if (NULL == peer) | 322 | if (NULL == peer) |
318 | return; | 323 | return; |
319 | struct tunnel_cls *cls_ = (struct tunnel_cls *) cls; | 324 | struct tunnel_cls *cls_ = (struct tunnel_cls *) cls; |
320 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 325 | if ((struct GNUNET_PeerIdentity*)1 != peer) |
321 | "Connected to peer %s, sending query with id %d\n", | 326 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
322 | GNUNET_i2s (peer), ntohs (cls_->dns.s.id)); | 327 | "Connected to peer %s, sending query with id %d\n", |
328 | GNUNET_i2s (peer), ntohs (cls_->dns.s.id)); | ||
329 | |||
330 | dns_tunnel_connected = 1; | ||
323 | 331 | ||
324 | if (NULL == GNUNET_MESH_tunnel_get_data (cls_->tunnel)) | 332 | if (NULL == GNUNET_MESH_tunnel_get_data (cls_->tunnel)) |
325 | { | 333 | { |
@@ -351,6 +359,15 @@ mesh_connect (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
351 | } | 359 | } |
352 | } | 360 | } |
353 | 361 | ||
362 | static void | ||
363 | call_mesh_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
364 | { | ||
365 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | ||
366 | return; | ||
367 | |||
368 | mesh_connect (cls, (struct GNUNET_PeerIdentity *) 1, NULL); | ||
369 | } | ||
370 | |||
354 | 371 | ||
355 | static void | 372 | static void |
356 | send_mesh_query (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 373 | send_mesh_query (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
@@ -360,13 +377,18 @@ send_mesh_query (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
360 | 377 | ||
361 | struct tunnel_cls *cls_ = (struct tunnel_cls*)cls; | 378 | struct tunnel_cls *cls_ = (struct tunnel_cls*)cls; |
362 | 379 | ||
363 | if (NULL == dns_tunnel) | 380 | if (NULL == dns_tunnel || dns_tunnel_connected == 0) |
364 | dns_tunnel = GNUNET_MESH_peer_request_connect_by_type(mesh_handle, | 381 | { |
382 | dns_tunnel = GNUNET_MESH_peer_request_connect_by_type(mesh_handle, | ||
365 | GNUNET_TIME_UNIT_HOURS, | 383 | GNUNET_TIME_UNIT_HOURS, |
366 | GNUNET_APPLICATION_TYPE_INTERNET_RESOLVER, | 384 | GNUNET_APPLICATION_TYPE_INTERNET_RESOLVER, |
367 | mesh_connect, | 385 | mesh_connect, |
368 | NULL, | 386 | NULL, |
369 | cls_); | 387 | cls_); |
388 | } | ||
389 | else | ||
390 | GNUNET_SCHEDULER_add_now(call_mesh_connect, cls_); | ||
391 | |||
370 | cls_->tunnel = dns_tunnel; | 392 | cls_->tunnel = dns_tunnel; |
371 | remote_pending[cls_->dns.s.id] = cls_; | 393 | remote_pending[cls_->dns.s.id] = cls_; |
372 | } | 394 | } |
@@ -411,6 +433,8 @@ receive_mesh_answer (void *cls __attribute__((unused)), | |||
411 | /* TODo: size check */ | 433 | /* TODo: size check */ |
412 | struct dns_pkt *dns = (struct dns_pkt *) (message + 1); | 434 | struct dns_pkt *dns = (struct dns_pkt *) (message + 1); |
413 | 435 | ||
436 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "received dns-answer via %x, id=%d/%\nd\n", tunnel, dns->s.id, ntohs(dns->s.id)); | ||
437 | |||
414 | /* They sent us a packet we were not waiting for */ | 438 | /* They sent us a packet we were not waiting for */ |
415 | if (remote_pending[dns->s.id] == NULL | 439 | if (remote_pending[dns->s.id] == NULL |
416 | || remote_pending[dns->s.id]->tunnel != tunnel) | 440 | || remote_pending[dns->s.id]->tunnel != tunnel) |