aboutsummaryrefslogtreecommitdiff
path: root/src/pt/gnunet-daemon-pt.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/pt/gnunet-daemon-pt.c')
-rw-r--r--src/pt/gnunet-daemon-pt.c1115
1 files changed, 558 insertions, 557 deletions
diff --git a/src/pt/gnunet-daemon-pt.c b/src/pt/gnunet-daemon-pt.c
index 99cbfebf8..ad22eaab8 100644
--- a/src/pt/gnunet-daemon-pt.c
+++ b/src/pt/gnunet-daemon-pt.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file pt/gnunet-daemon-pt.c 21 * @file pt/gnunet-daemon-pt.c
22 * @brief tool to manipulate DNS and VPN services to perform protocol translation (IPvX over GNUnet) 22 * @brief tool to manipulate DNS and VPN services to perform protocol translation (IPvX over GNUnet)
@@ -58,8 +58,7 @@
58/** 58/**
59 * Which group of DNS records are we currently processing? 59 * Which group of DNS records are we currently processing?
60 */ 60 */
61enum RequestGroup 61enum RequestGroup {
62{
63 /** 62 /**
64 * DNS answers 63 * DNS answers
65 */ 64 */
@@ -85,8 +84,7 @@ enum RequestGroup
85/** 84/**
86 * Information tracked per DNS reply that we are processing. 85 * Information tracked per DNS reply that we are processing.
87 */ 86 */
88struct ReplyContext 87struct ReplyContext {
89{
90 /** 88 /**
91 * Handle to submit the final result. 89 * Handle to submit the final result.
92 */ 90 */
@@ -116,7 +114,6 @@ struct ReplyContext
116 * Group that is being modified 114 * Group that is being modified
117 */ 115 */
118 enum RequestGroup group; 116 enum RequestGroup group;
119
120}; 117};
121 118
122 119
@@ -125,9 +122,7 @@ struct ReplyContext
125 * as a DNS exit. We try to keep a few channels open and a few 122 * as a DNS exit. We try to keep a few channels open and a few
126 * peers in reserve. 123 * peers in reserve.
127 */ 124 */
128struct CadetExit 125struct CadetExit {
129{
130
131 /** 126 /**
132 * Kept in a DLL. 127 * Kept in a DLL.
133 */ 128 */
@@ -178,7 +173,6 @@ struct CadetExit
178 * Size of the window, 0 if we are busy. 173 * Size of the window, 0 if we are busy.
179 */ 174 */
180 /* unsigned */ int idle; 175 /* unsigned */ int idle;
181
182}; 176};
183 177
184 178
@@ -186,8 +180,7 @@ struct CadetExit
186/** 180/**
187 * State we keep for a request that is going out via CADET. 181 * State we keep for a request that is going out via CADET.
188 */ 182 */
189struct RequestContext 183struct RequestContext {
190{
191 /** 184 /**
192 * We keep these in a DLL. 185 * We keep these in a DLL.
193 */ 186 */
@@ -227,7 +220,6 @@ struct RequestContext
227 * ID of the original DNS request (used to match the reply). 220 * ID of the original DNS request (used to match the reply).
228 */ 221 */
229 uint16_t dns_id; 222 uint16_t dns_id;
230
231}; 223};
232 224
233 225
@@ -310,7 +302,7 @@ static unsigned int dns_exit_available;
310 * We are short on cadet exits, try to open another one. 302 * We are short on cadet exits, try to open another one.
311 */ 303 */
312static void 304static void
313try_open_exit (void); 305try_open_exit(void);
314 306
315 307
316/** 308/**
@@ -323,24 +315,24 @@ try_open_exit (void);
323 * @return weight of the channel 315 * @return weight of the channel
324 */ 316 */
325static uint32_t 317static uint32_t
326get_channel_weight (struct CadetExit *exit) 318get_channel_weight(struct CadetExit *exit)
327{ 319{
328 uint32_t dropped; 320 uint32_t dropped;
329 uint32_t drop_percent; 321 uint32_t drop_percent;
330 uint32_t good_percent; 322 uint32_t good_percent;
331 323
332 GNUNET_assert (exit->num_transmitted >= exit->num_answered); 324 GNUNET_assert(exit->num_transmitted >= exit->num_answered);
333 dropped = exit->num_transmitted - exit->num_answered; 325 dropped = exit->num_transmitted - exit->num_answered;
334 if (exit->num_transmitted > 0) 326 if (exit->num_transmitted > 0)
335 drop_percent = (uint32_t) ((100LL * dropped) / exit->num_transmitted); 327 drop_percent = (uint32_t)((100LL * dropped) / exit->num_transmitted);
336 else 328 else
337 drop_percent = 50; /* no data */ 329 drop_percent = 50; /* no data */
338 if ( (exit->num_transmitted > 20) && 330 if ((exit->num_transmitted > 20) &&
339 (drop_percent > 25) ) 331 (drop_percent > 25))
340 return 0; /* statistically significant, and > 25% loss, die */ 332 return 0; /* statistically significant, and > 25% loss, die */
341 good_percent = 100 - drop_percent; 333 good_percent = 100 - drop_percent;
342 GNUNET_assert (0 != good_percent); 334 GNUNET_assert(0 != good_percent);
343 if ( UINT32_MAX / good_percent / good_percent < exit->num_transmitted) 335 if (UINT32_MAX / good_percent / good_percent < exit->num_transmitted)
344 return UINT32_MAX; /* formula below would overflow */ 336 return UINT32_MAX; /* formula below would overflow */
345 return 1 + good_percent * good_percent * exit->num_transmitted; 337 return 1 + good_percent * good_percent * exit->num_transmitted;
346} 338}
@@ -358,7 +350,7 @@ get_channel_weight (struct CadetExit *exit)
358 * exit that we should use to queue a message with 350 * exit that we should use to queue a message with
359 */ 351 */
360static struct CadetExit * 352static struct CadetExit *
361choose_exit () 353choose_exit()
362{ 354{
363 struct CadetExit *pos; 355 struct CadetExit *pos;
364 uint64_t total_transmitted; 356 uint64_t total_transmitted;
@@ -367,36 +359,36 @@ choose_exit ()
367 359
368 total_transmitted = 0; 360 total_transmitted = 0;
369 for (pos = exit_head; NULL != pos; pos = pos->next) 361 for (pos = exit_head; NULL != pos; pos = pos->next)
370 { 362 {
371 if (NULL == pos->cadet_channel) 363 if (NULL == pos->cadet_channel)
372 break; 364 break;
373 channel_weight = get_channel_weight (pos); 365 channel_weight = get_channel_weight(pos);
374 total_transmitted += channel_weight;
375 /* double weight for idle channels */
376 if (0 != pos->idle)
377 total_transmitted += channel_weight; 366 total_transmitted += channel_weight;
378 } 367 /* double weight for idle channels */
368 if (0 != pos->idle)
369 total_transmitted += channel_weight;
370 }
379 if (0 == total_transmitted) 371 if (0 == total_transmitted)
380 { 372 {
381 /* no channels available, or only a very bad one... */ 373 /* no channels available, or only a very bad one... */
382 return exit_head; 374 return exit_head;
383 } 375 }
384 selected_offset = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, 376 selected_offset = GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK,
385 total_transmitted); 377 total_transmitted);
386 total_transmitted = 0; 378 total_transmitted = 0;
387 for (pos = exit_head; NULL != pos; pos = pos->next) 379 for (pos = exit_head; NULL != pos; pos = pos->next)
388 { 380 {
389 if (NULL == pos->cadet_channel) 381 if (NULL == pos->cadet_channel)
390 break; 382 break;
391 channel_weight = get_channel_weight (pos); 383 channel_weight = get_channel_weight(pos);
392 total_transmitted += channel_weight;
393 /* double weight for idle channels */
394 if (0 != pos->idle)
395 total_transmitted += channel_weight; 384 total_transmitted += channel_weight;
396 if (total_transmitted > selected_offset) 385 /* double weight for idle channels */
397 return pos; 386 if (0 != pos->idle)
398 } 387 total_transmitted += channel_weight;
399 GNUNET_break (0); 388 if (total_transmitted > selected_offset)
389 return pos;
390 }
391 GNUNET_break(0);
400 return NULL; 392 return NULL;
401} 393}
402 394
@@ -408,33 +400,33 @@ choose_exit ()
408 * @param rc context to process 400 * @param rc context to process
409 */ 401 */
410static void 402static void
411finish_request (struct ReplyContext *rc) 403finish_request(struct ReplyContext *rc)
412{ 404{
413 char *buf; 405 char *buf;
414 size_t buf_len; 406 size_t buf_len;
415 407
416 if (GNUNET_SYSERR == 408 if (GNUNET_SYSERR ==
417 GNUNET_DNSPARSER_pack (rc->dns, 409 GNUNET_DNSPARSER_pack(rc->dns,
418 MAX_DNS_SIZE, 410 MAX_DNS_SIZE,
419 &buf, 411 &buf,
420 &buf_len)) 412 &buf_len))
421 { 413 {
422 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 414 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
423 _("Failed to pack DNS request. Dropping.\n")); 415 _("Failed to pack DNS request. Dropping.\n"));
424 GNUNET_DNS_request_drop (rc->rh); 416 GNUNET_DNS_request_drop(rc->rh);
425 } 417 }
426 else 418 else
427 { 419 {
428 GNUNET_STATISTICS_update (stats, 420 GNUNET_STATISTICS_update(stats,
429 gettext_noop ("# DNS requests mapped to VPN"), 421 gettext_noop("# DNS requests mapped to VPN"),
430 1, GNUNET_NO); 422 1, GNUNET_NO);
431 GNUNET_DNS_request_answer (rc->rh, 423 GNUNET_DNS_request_answer(rc->rh,
432 buf_len, 424 buf_len,
433 buf); 425 buf);
434 GNUNET_free (buf); 426 GNUNET_free(buf);
435 } 427 }
436 GNUNET_DNSPARSER_free_packet (rc->dns); 428 GNUNET_DNSPARSER_free_packet(rc->dns);
437 GNUNET_free (rc); 429 GNUNET_free(rc);
438} 430}
439 431
440 432
@@ -446,7 +438,7 @@ finish_request (struct ReplyContext *rc)
446 * @param rc context to process 438 * @param rc context to process
447 */ 439 */
448static void 440static void
449submit_request (struct ReplyContext *rc); 441submit_request(struct ReplyContext *rc);
450 442
451 443
452/** 444/**
@@ -465,44 +457,46 @@ submit_request (struct ReplyContext *rc);
465 * specified target peer; NULL on error 457 * specified target peer; NULL on error
466 */ 458 */
467static void 459static void
468vpn_allocation_callback (void *cls, 460vpn_allocation_callback(void *cls,
469 int af, 461 int af,
470 const void *address) 462 const void *address)
471{ 463{
472 struct ReplyContext *rc = cls; 464 struct ReplyContext *rc = cls;
473 465
474 rc->rr = NULL; 466 rc->rr = NULL;
475 if (af == AF_UNSPEC) 467 if (af == AF_UNSPEC)
476 { 468 {
477 GNUNET_DNS_request_drop (rc->rh); 469 GNUNET_DNS_request_drop(rc->rh);
478 GNUNET_DNSPARSER_free_packet (rc->dns); 470 GNUNET_DNSPARSER_free_packet(rc->dns);
479 GNUNET_free (rc); 471 GNUNET_free(rc);
480 return; 472 return;
481 } 473 }
482 GNUNET_STATISTICS_update (stats, 474 GNUNET_STATISTICS_update(stats,
483 gettext_noop ("# DNS records modified"), 475 gettext_noop("# DNS records modified"),
484 1, 476 1,
485 GNUNET_NO); 477 GNUNET_NO);
486 switch (rc->rec->type) 478 switch (rc->rec->type)
487 { 479 {
488 case GNUNET_DNSPARSER_TYPE_A: 480 case GNUNET_DNSPARSER_TYPE_A:
489 GNUNET_assert (AF_INET == af); 481 GNUNET_assert(AF_INET == af);
490 GNUNET_memcpy (rc->rec->data.raw.data, 482 GNUNET_memcpy(rc->rec->data.raw.data,
491 address, 483 address,
492 sizeof (struct in_addr)); 484 sizeof(struct in_addr));
493 break; 485 break;
494 case GNUNET_DNSPARSER_TYPE_AAAA: 486
495 GNUNET_assert (AF_INET6 == af); 487 case GNUNET_DNSPARSER_TYPE_AAAA:
496 GNUNET_memcpy (rc->rec->data.raw.data, 488 GNUNET_assert(AF_INET6 == af);
497 address, 489 GNUNET_memcpy(rc->rec->data.raw.data,
498 sizeof (struct in6_addr)); 490 address,
499 break; 491 sizeof(struct in6_addr));
500 default: 492 break;
501 GNUNET_assert (0); 493
502 return; 494 default:
503 } 495 GNUNET_assert(0);
496 return;
497 }
504 rc->rec = NULL; 498 rc->rec = NULL;
505 submit_request (rc); 499 submit_request(rc);
506} 500}
507 501
508 502
@@ -516,33 +510,35 @@ vpn_allocation_callback (void *cls,
516 * @param rec record to modify 510 * @param rec record to modify
517 */ 511 */
518static void 512static void
519modify_address (struct ReplyContext *rc, 513modify_address(struct ReplyContext *rc,
520 struct GNUNET_DNSPARSER_Record *rec) 514 struct GNUNET_DNSPARSER_Record *rec)
521{ 515{
522 int af; 516 int af;
523 517
524 switch (rec->type) 518 switch (rec->type)
525 { 519 {
526 case GNUNET_DNSPARSER_TYPE_A: 520 case GNUNET_DNSPARSER_TYPE_A:
527 af = AF_INET; 521 af = AF_INET;
528 GNUNET_assert (rec->data.raw.data_len == sizeof (struct in_addr)); 522 GNUNET_assert(rec->data.raw.data_len == sizeof(struct in_addr));
529 break; 523 break;
530 case GNUNET_DNSPARSER_TYPE_AAAA: 524
531 af = AF_INET6; 525 case GNUNET_DNSPARSER_TYPE_AAAA:
532 GNUNET_assert (rec->data.raw.data_len == sizeof (struct in6_addr)); 526 af = AF_INET6;
533 break; 527 GNUNET_assert(rec->data.raw.data_len == sizeof(struct in6_addr));
534 default: 528 break;
535 GNUNET_assert (0); 529
536 return; 530 default:
537 } 531 GNUNET_assert(0);
532 return;
533 }
538 rc->rec = rec; 534 rc->rec = rec;
539 rc->rr = GNUNET_VPN_redirect_to_ip (vpn_handle, 535 rc->rr = GNUNET_VPN_redirect_to_ip(vpn_handle,
540 af, 536 af,
541 af, 537 af,
542 rec->data.raw.data, 538 rec->data.raw.data,
543 GNUNET_TIME_relative_to_absolute (TIMEOUT), 539 GNUNET_TIME_relative_to_absolute(TIMEOUT),
544 &vpn_allocation_callback, 540 &vpn_allocation_callback,
545 rc); 541 rc);
546} 542}
547 543
548 544
@@ -554,60 +550,65 @@ modify_address (struct ReplyContext *rc,
554 * @param rc context to process 550 * @param rc context to process
555 */ 551 */
556static void 552static void
557submit_request (struct ReplyContext *rc) 553submit_request(struct ReplyContext *rc)
558{ 554{
559 struct GNUNET_DNSPARSER_Record *ra; 555 struct GNUNET_DNSPARSER_Record *ra;
560 unsigned int ra_len; 556 unsigned int ra_len;
561 unsigned int i; 557 unsigned int i;
562 558
563 while (1) 559 while (1)
564 {
565 switch (rc->group)
566 { 560 {
567 case ANSWERS: 561 switch (rc->group)
568 ra = rc->dns->answers; 562 {
569 ra_len = rc->dns->num_answers; 563 case ANSWERS:
570 break; 564 ra = rc->dns->answers;
571 case AUTHORITY_RECORDS: 565 ra_len = rc->dns->num_answers;
572 ra = rc->dns->authority_records; 566 break;
573 ra_len = rc->dns->num_authority_records; 567
574 break; 568 case AUTHORITY_RECORDS:
575 case ADDITIONAL_RECORDS: 569 ra = rc->dns->authority_records;
576 ra = rc->dns->additional_records; 570 ra_len = rc->dns->num_authority_records;
577 ra_len = rc->dns->num_additional_records; 571 break;
578 break; 572
579 case END: 573 case ADDITIONAL_RECORDS:
580 finish_request (rc); 574 ra = rc->dns->additional_records;
581 return; 575 ra_len = rc->dns->num_additional_records;
582 default: 576 break;
583 GNUNET_assert (0); 577
578 case END:
579 finish_request(rc);
580 return;
581
582 default:
583 GNUNET_assert(0);
584 }
585 for (i = rc->offset; i < ra_len; i++)
586 {
587 switch (ra[i].type)
588 {
589 case GNUNET_DNSPARSER_TYPE_A:
590 if (ipv4_pt)
591 {
592 rc->offset = i + 1;
593 modify_address(rc,
594 &ra[i]);
595 return;
596 }
597 break;
598
599 case GNUNET_DNSPARSER_TYPE_AAAA:
600 if (ipv6_pt)
601 {
602 rc->offset = i + 1;
603 modify_address(rc,
604 &ra[i]);
605 return;
606 }
607 break;
608 }
609 }
610 rc->group++;
584 } 611 }
585 for (i=rc->offset;i<ra_len;i++)
586 {
587 switch (ra[i].type)
588 {
589 case GNUNET_DNSPARSER_TYPE_A:
590 if (ipv4_pt)
591 {
592 rc->offset = i + 1;
593 modify_address (rc,
594 &ra[i]);
595 return;
596 }
597 break;
598 case GNUNET_DNSPARSER_TYPE_AAAA:
599 if (ipv6_pt)
600 {
601 rc->offset = i + 1;
602 modify_address (rc,
603 &ra[i]);
604 return;
605 }
606 break;
607 }
608 }
609 rc->group++;
610 }
611} 612}
612 613
613 614
@@ -619,25 +620,26 @@ submit_request (struct ReplyContext *rc)
619 * @return #GNUNET_YES if any of the given records require protocol-translation 620 * @return #GNUNET_YES if any of the given records require protocol-translation
620 */ 621 */
621static int 622static int
622work_test (const struct GNUNET_DNSPARSER_Record *ra, 623work_test(const struct GNUNET_DNSPARSER_Record *ra,
623 unsigned int ra_len) 624 unsigned int ra_len)
624{ 625{
625 unsigned int i; 626 unsigned int i;
626 627
627 for (i=0;i<ra_len;i++) 628 for (i = 0; i < ra_len; i++)
628 {
629 switch (ra[i].type)
630 { 629 {
631 case GNUNET_DNSPARSER_TYPE_A: 630 switch (ra[i].type)
632 if (ipv4_pt) 631 {
633 return GNUNET_YES; 632 case GNUNET_DNSPARSER_TYPE_A:
634 break; 633 if (ipv4_pt)
635 case GNUNET_DNSPARSER_TYPE_AAAA: 634 return GNUNET_YES;
636 if (ipv6_pt) 635 break;
637 return GNUNET_YES; 636
638 break; 637 case GNUNET_DNSPARSER_TYPE_AAAA:
638 if (ipv6_pt)
639 return GNUNET_YES;
640 break;
641 }
639 } 642 }
640 }
641 return GNUNET_NO; 643 return GNUNET_NO;
642} 644}
643 645
@@ -654,46 +656,46 @@ work_test (const struct GNUNET_DNSPARSER_Record *ra,
654 * @param request udp payload of the DNS request 656 * @param request udp payload of the DNS request
655 */ 657 */
656static void 658static void
657dns_post_request_handler (void *cls, 659dns_post_request_handler(void *cls,
658 struct GNUNET_DNS_RequestHandle *rh, 660 struct GNUNET_DNS_RequestHandle *rh,
659 size_t request_length, 661 size_t request_length,
660 const char *request) 662 const char *request)
661{ 663{
662 struct GNUNET_DNSPARSER_Packet *dns; 664 struct GNUNET_DNSPARSER_Packet *dns;
663 struct ReplyContext *rc; 665 struct ReplyContext *rc;
664 int work; 666 int work;
665 667
666 GNUNET_STATISTICS_update (stats, 668 GNUNET_STATISTICS_update(stats,
667 gettext_noop ("# DNS replies intercepted"), 669 gettext_noop("# DNS replies intercepted"),
668 1, GNUNET_NO); 670 1, GNUNET_NO);
669 dns = GNUNET_DNSPARSER_parse (request, 671 dns = GNUNET_DNSPARSER_parse(request,
670 request_length); 672 request_length);
671 if (NULL == dns) 673 if (NULL == dns)
672 { 674 {
673 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 675 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
674 _("Failed to parse DNS request. Dropping.\n")); 676 _("Failed to parse DNS request. Dropping.\n"));
675 GNUNET_DNS_request_drop (rh); 677 GNUNET_DNS_request_drop(rh);
676 return; 678 return;
677 } 679 }
678 work = GNUNET_NO; 680 work = GNUNET_NO;
679 work |= work_test (dns->answers, 681 work |= work_test(dns->answers,
680 dns->num_answers); 682 dns->num_answers);
681 work |= work_test (dns->authority_records, 683 work |= work_test(dns->authority_records,
682 dns->num_authority_records); 684 dns->num_authority_records);
683 work |= work_test (dns->additional_records, 685 work |= work_test(dns->additional_records,
684 dns->num_additional_records); 686 dns->num_additional_records);
685 if (! work) 687 if (!work)
686 { 688 {
687 GNUNET_DNS_request_forward (rh); 689 GNUNET_DNS_request_forward(rh);
688 GNUNET_DNSPARSER_free_packet (dns); 690 GNUNET_DNSPARSER_free_packet(dns);
689 return; 691 return;
690 } 692 }
691 rc = GNUNET_new (struct ReplyContext); 693 rc = GNUNET_new(struct ReplyContext);
692 rc->rh = rh; 694 rc->rh = rh;
693 rc->dns = dns; 695 rc->dns = dns;
694 rc->offset = 0; 696 rc->offset = 0;
695 rc->group = ANSWERS; 697 rc->group = ANSWERS;
696 submit_request (rc); 698 submit_request(rc);
697} 699}
698 700
699 701
@@ -703,41 +705,41 @@ dns_post_request_handler (void *cls,
703 * @param cls the `struct RequestContext` to abort 705 * @param cls the `struct RequestContext` to abort
704 */ 706 */
705static void 707static void
706timeout_request (void *cls) 708timeout_request(void *cls)
707{ 709{
708 struct RequestContext *rc = cls; 710 struct RequestContext *rc = cls;
709 struct CadetExit *exit = rc->exit; 711 struct CadetExit *exit = rc->exit;
710 712
711 GNUNET_STATISTICS_update (stats, 713 GNUNET_STATISTICS_update(stats,
712 gettext_noop ("# DNS requests dropped (timeout)"), 714 gettext_noop("# DNS requests dropped (timeout)"),
713 1, 715 1,
714 GNUNET_NO); 716 GNUNET_NO);
715 GNUNET_DNS_request_drop (rc->rh); 717 GNUNET_DNS_request_drop(rc->rh);
716 GNUNET_free (rc); 718 GNUNET_free(rc);
717 if ( (0 == get_channel_weight (exit)) && 719 if ((0 == get_channel_weight(exit)) &&
718 (NULL == exit->receive_queue_head) ) 720 (NULL == exit->receive_queue_head))
719 { 721 {
720 /* this straw broke the camel's back: this channel now has 722 /* this straw broke the camel's back: this channel now has
721 such a low score that it will not be used; close it! */ 723 such a low score that it will not be used; close it! */
722 GNUNET_CADET_channel_destroy (exit->cadet_channel); 724 GNUNET_CADET_channel_destroy(exit->cadet_channel);
723 exit->cadet_channel = NULL; 725 exit->cadet_channel = NULL;
724 GNUNET_CONTAINER_DLL_remove (exit_head, 726 GNUNET_CONTAINER_DLL_remove(exit_head,
725 exit_tail, 727 exit_tail,
726 exit); 728 exit);
727 GNUNET_CONTAINER_DLL_insert_tail (exit_head, 729 GNUNET_CONTAINER_DLL_insert_tail(exit_head,
728 exit_tail, 730 exit_tail,
729 exit); 731 exit);
730 /* go back to semi-innocent: mark as not great, but 732 /* go back to semi-innocent: mark as not great, but
731 avoid a prohibitively negative score (see 733 avoid a prohibitively negative score (see
732 #get_channel_weight(), which checks for a certain 734 #get_channel_weight(), which checks for a certain
733 minimum number of transmissions before making 735 minimum number of transmissions before making
734 up an opinion) */ 736 up an opinion) */
735 exit->num_transmitted = 5; 737 exit->num_transmitted = 5;
736 exit->num_answered = 0; 738 exit->num_answered = 0;
737 dns_exit_available--; 739 dns_exit_available--;
738 /* now try to open an alternative exit */ 740 /* now try to open an alternative exit */
739 try_open_exit (); 741 try_open_exit();
740 } 742 }
741} 743}
742 744
743 745
@@ -753,10 +755,10 @@ timeout_request (void *cls)
753 * @param request udp payload of the DNS request 755 * @param request udp payload of the DNS request
754 */ 756 */
755static void 757static void
756dns_pre_request_handler (void *cls, 758dns_pre_request_handler(void *cls,
757 struct GNUNET_DNS_RequestHandle *rh, 759 struct GNUNET_DNS_RequestHandle *rh,
758 size_t request_length, 760 size_t request_length,
759 const char *request) 761 const char *request)
760{ 762{
761 struct RequestContext *rc; 763 struct RequestContext *rc;
762 struct GNUNET_MQ_Envelope *env; 764 struct GNUNET_MQ_Envelope *env;
@@ -764,54 +766,54 @@ dns_pre_request_handler (void *cls,
764 struct GNUNET_TUN_DnsHeader dns; 766 struct GNUNET_TUN_DnsHeader dns;
765 struct CadetExit *exit; 767 struct CadetExit *exit;
766 768
767 GNUNET_STATISTICS_update (stats, 769 GNUNET_STATISTICS_update(stats,
768 gettext_noop ("# DNS requests intercepted"), 770 gettext_noop("# DNS requests intercepted"),
769 1, GNUNET_NO); 771 1, GNUNET_NO);
770 if (0 == dns_exit_available) 772 if (0 == dns_exit_available)
771 { 773 {
772 GNUNET_STATISTICS_update (stats, 774 GNUNET_STATISTICS_update(stats,
773 gettext_noop ("# DNS requests dropped (DNS cadet channel down)"), 775 gettext_noop("# DNS requests dropped (DNS cadet channel down)"),
774 1, GNUNET_NO); 776 1, GNUNET_NO);
775 GNUNET_DNS_request_drop (rh); 777 GNUNET_DNS_request_drop(rh);
776 return; 778 return;
777 } 779 }
778 if (request_length < sizeof (dns)) 780 if (request_length < sizeof(dns))
779 { 781 {
780 GNUNET_STATISTICS_update (stats, 782 GNUNET_STATISTICS_update(stats,
781 gettext_noop ("# DNS requests dropped (malformed)"), 783 gettext_noop("# DNS requests dropped (malformed)"),
782 1, GNUNET_NO); 784 1, GNUNET_NO);
783 GNUNET_DNS_request_drop (rh); 785 GNUNET_DNS_request_drop(rh);
784 return; 786 return;
785 } 787 }
786 exit = choose_exit (); 788 exit = choose_exit();
787 GNUNET_assert (NULL != exit); 789 GNUNET_assert(NULL != exit);
788 GNUNET_assert (NULL != exit->cadet_channel); 790 GNUNET_assert(NULL != exit->cadet_channel);
789 791
790 env = GNUNET_MQ_msg_extra (hdr, 792 env = GNUNET_MQ_msg_extra(hdr,
791 request_length, 793 request_length,
792 GNUNET_MESSAGE_TYPE_VPN_DNS_TO_INTERNET); 794 GNUNET_MESSAGE_TYPE_VPN_DNS_TO_INTERNET);
793 GNUNET_memcpy (&hdr[1], 795 GNUNET_memcpy(&hdr[1],
794 request, 796 request,
795 request_length); 797 request_length);
796 rc = GNUNET_new (struct RequestContext); 798 rc = GNUNET_new(struct RequestContext);
797 rc->exit = exit; 799 rc->exit = exit;
798 rc->rh = rh; 800 rc->rh = rh;
799 rc->timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 801 rc->timeout_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,
800 &timeout_request, 802 &timeout_request,
801 rc); 803 rc);
802 GNUNET_memcpy (&dns, 804 GNUNET_memcpy(&dns,
803 request, 805 request,
804 sizeof (dns)); 806 sizeof(dns));
805 rc->dns_id = dns.id; 807 rc->dns_id = dns.id;
806 rc->env = env; 808 rc->env = env;
807 GNUNET_CONTAINER_DLL_remove (exit->receive_queue_head, 809 GNUNET_CONTAINER_DLL_remove(exit->receive_queue_head,
808 exit->receive_queue_tail, 810 exit->receive_queue_tail,
809 rc); 811 rc);
810 if (0 < exit->idle) 812 if (0 < exit->idle)
811 exit->idle--; 813 exit->idle--;
812 exit->num_transmitted++; 814 exit->num_transmitted++;
813 GNUNET_MQ_send (GNUNET_CADET_get_mq (exit->cadet_channel), 815 GNUNET_MQ_send(GNUNET_CADET_get_mq(exit->cadet_channel),
814 GNUNET_MQ_env_copy (env)); 816 GNUNET_MQ_env_copy(env));
815} 817}
816 818
817 819
@@ -820,8 +822,7 @@ GNUNET_NETWORK_STRUCT_BEGIN
820/** 822/**
821 * Message with a DNS response. 823 * Message with a DNS response.
822 */ 824 */
823struct DnsResponseMessage 825struct DnsResponseMessage {
824{
825 /** 826 /**
826 * GNUnet header, of type #GNUNET_MESSAGE_TYPE_VPN_DNS_FROM_INTERNET 827 * GNUnet header, of type #GNUNET_MESSAGE_TYPE_VPN_DNS_FROM_INTERNET
827 */ 828 */
@@ -846,8 +847,8 @@ GNUNET_NETWORK_STRUCT_END
846 * #GNUNET_SYSERR to close it (signal serious error) 847 * #GNUNET_SYSERR to close it (signal serious error)
847 */ 848 */
848static int 849static int
849check_dns_response (void *cls, 850check_dns_response(void *cls,
850 const struct DnsResponseMessage *msg) 851 const struct DnsResponseMessage *msg)
851{ 852{
852 return GNUNET_OK; /* all OK */ 853 return GNUNET_OK; /* all OK */
853} 854}
@@ -860,38 +861,38 @@ check_dns_response (void *cls,
860 * @param msg the actual message 861 * @param msg the actual message
861 */ 862 */
862static void 863static void
863handle_dns_response (void *cls, 864handle_dns_response(void *cls,
864 const struct DnsResponseMessage *msg) 865 const struct DnsResponseMessage *msg)
865{ 866{
866 struct CadetExit *exit = cls; 867 struct CadetExit *exit = cls;
867 size_t mlen; 868 size_t mlen;
868 struct RequestContext *rc; 869 struct RequestContext *rc;
869 870
870 mlen = ntohs (msg->header.size) - sizeof (*msg); 871 mlen = ntohs(msg->header.size) - sizeof(*msg);
871 for (rc = exit->receive_queue_head; NULL != rc; rc = rc->next) 872 for (rc = exit->receive_queue_head; NULL != rc; rc = rc->next)
872 {
873 if (msg->dns.id == rc->dns_id)
874 { 873 {
875 GNUNET_STATISTICS_update (stats, 874 if (msg->dns.id == rc->dns_id)
876 gettext_noop ("# DNS replies received"), 875 {
877 1, 876 GNUNET_STATISTICS_update(stats,
878 GNUNET_NO); 877 gettext_noop("# DNS replies received"),
879 GNUNET_DNS_request_answer (rc->rh, 878 1,
880 mlen + sizeof (struct GNUNET_TUN_DnsHeader), 879 GNUNET_NO);
881 (const void*) &msg->dns); 880 GNUNET_DNS_request_answer(rc->rh,
882 GNUNET_CONTAINER_DLL_remove (exit->receive_queue_head, 881 mlen + sizeof(struct GNUNET_TUN_DnsHeader),
883 exit->receive_queue_tail, 882 (const void*)&msg->dns);
884 rc); 883 GNUNET_CONTAINER_DLL_remove(exit->receive_queue_head,
885 GNUNET_SCHEDULER_cancel (rc->timeout_task); 884 exit->receive_queue_tail,
886 GNUNET_MQ_discard (rc->env); 885 rc);
887 GNUNET_free (rc); 886 GNUNET_SCHEDULER_cancel(rc->timeout_task);
888 exit->num_answered++; 887 GNUNET_MQ_discard(rc->env);
889 return; 888 GNUNET_free(rc);
889 exit->num_answered++;
890 return;
891 }
890 } 892 }
891 } 893 GNUNET_STATISTICS_update(stats,
892 GNUNET_STATISTICS_update (stats, 894 gettext_noop("# DNS replies dropped (too late?)"),
893 gettext_noop ("# DNS replies dropped (too late?)"), 895 1, GNUNET_NO);
894 1, GNUNET_NO);
895} 896}
896 897
897 898
@@ -901,20 +902,20 @@ handle_dns_response (void *cls,
901 * @param exit cadet exit to abort requests for 902 * @param exit cadet exit to abort requests for
902 */ 903 */
903static void 904static void
904abort_all_requests (struct CadetExit *exit) 905abort_all_requests(struct CadetExit *exit)
905{ 906{
906 struct RequestContext *rc; 907 struct RequestContext *rc;
907 908
908 while (NULL != (rc = exit->receive_queue_head)) 909 while (NULL != (rc = exit->receive_queue_head))
909 { 910 {
910 GNUNET_CONTAINER_DLL_remove (exit->receive_queue_head, 911 GNUNET_CONTAINER_DLL_remove(exit->receive_queue_head,
911 exit->receive_queue_tail, 912 exit->receive_queue_tail,
912 rc); 913 rc);
913 GNUNET_DNS_request_drop (rc->rh); 914 GNUNET_DNS_request_drop(rc->rh);
914 GNUNET_SCHEDULER_cancel (rc->timeout_task); 915 GNUNET_SCHEDULER_cancel(rc->timeout_task);
915 GNUNET_MQ_discard (rc->env); 916 GNUNET_MQ_discard(rc->env);
916 GNUNET_free (rc); 917 GNUNET_free(rc);
917 } 918 }
918} 919}
919 920
920 921
@@ -924,60 +925,60 @@ abort_all_requests (struct CadetExit *exit)
924 * @param cls closure, NULL 925 * @param cls closure, NULL
925 */ 926 */
926static void 927static void
927cleanup (void *cls) 928cleanup(void *cls)
928{ 929{
929 struct CadetExit *exit; 930 struct CadetExit *exit;
930 931
931 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 932 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
932 "Protocol translation daemon is shutting down now\n"); 933 "Protocol translation daemon is shutting down now\n");
933 if (NULL != vpn_handle) 934 if (NULL != vpn_handle)
934 { 935 {
935 GNUNET_VPN_disconnect (vpn_handle); 936 GNUNET_VPN_disconnect(vpn_handle);
936 vpn_handle = NULL; 937 vpn_handle = NULL;
937 } 938 }
938 while (NULL != (exit = exit_head)) 939 while (NULL != (exit = exit_head))
939 {
940 GNUNET_CONTAINER_DLL_remove (exit_head,
941 exit_tail,
942 exit);
943 if (NULL != exit->cadet_channel)
944 { 940 {
945 GNUNET_CADET_channel_destroy (exit->cadet_channel); 941 GNUNET_CONTAINER_DLL_remove(exit_head,
946 exit->cadet_channel = NULL; 942 exit_tail,
943 exit);
944 if (NULL != exit->cadet_channel)
945 {
946 GNUNET_CADET_channel_destroy(exit->cadet_channel);
947 exit->cadet_channel = NULL;
948 }
949 abort_all_requests(exit);
950 GNUNET_free(exit);
947 } 951 }
948 abort_all_requests (exit);
949 GNUNET_free (exit);
950 }
951 if (NULL != cadet_handle) 952 if (NULL != cadet_handle)
952 { 953 {
953 GNUNET_CADET_disconnect (cadet_handle); 954 GNUNET_CADET_disconnect(cadet_handle);
954 cadet_handle = NULL; 955 cadet_handle = NULL;
955 } 956 }
956 if (NULL != dns_post_handle) 957 if (NULL != dns_post_handle)
957 { 958 {
958 GNUNET_DNS_disconnect (dns_post_handle); 959 GNUNET_DNS_disconnect(dns_post_handle);
959 dns_post_handle = NULL; 960 dns_post_handle = NULL;
960 } 961 }
961 if (NULL != dns_pre_handle) 962 if (NULL != dns_pre_handle)
962 { 963 {
963 GNUNET_DNS_disconnect (dns_pre_handle); 964 GNUNET_DNS_disconnect(dns_pre_handle);
964 dns_pre_handle = NULL; 965 dns_pre_handle = NULL;
965 } 966 }
966 if (NULL != stats) 967 if (NULL != stats)
967 { 968 {
968 GNUNET_STATISTICS_destroy (stats, GNUNET_YES); 969 GNUNET_STATISTICS_destroy(stats, GNUNET_YES);
969 stats = NULL; 970 stats = NULL;
970 } 971 }
971 if (NULL != dht_get) 972 if (NULL != dht_get)
972 { 973 {
973 GNUNET_DHT_get_stop (dht_get); 974 GNUNET_DHT_get_stop(dht_get);
974 dht_get = NULL; 975 dht_get = NULL;
975 } 976 }
976 if (NULL != dht) 977 if (NULL != dht)
977 { 978 {
978 GNUNET_DHT_disconnect (dht); 979 GNUNET_DHT_disconnect(dht);
979 dht = NULL; 980 dht = NULL;
980 } 981 }
981} 982}
982 983
983 984
@@ -993,8 +994,8 @@ cleanup (void *cls)
993 * with the channel is stored 994 * with the channel is stored
994 */ 995 */
995static void 996static void
996cadet_channel_end_cb (void *cls, 997cadet_channel_end_cb(void *cls,
997 const struct GNUNET_CADET_Channel *channel) 998 const struct GNUNET_CADET_Channel *channel)
998{ 999{
999 struct CadetExit *exit = cls; 1000 struct CadetExit *exit = cls;
1000 struct CadetExit *alt; 1001 struct CadetExit *alt;
@@ -1005,20 +1006,20 @@ cadet_channel_end_cb (void *cls,
1005 /* open alternative channels */ 1006 /* open alternative channels */
1006 /* our channel is now closed, move our requests to an alternative 1007 /* our channel is now closed, move our requests to an alternative
1007 channel */ 1008 channel */
1008 alt = choose_exit (); 1009 alt = choose_exit();
1009 while (NULL != (rc = exit->receive_queue_head)) 1010 while (NULL != (rc = exit->receive_queue_head))
1010 { 1011 {
1011 GNUNET_CONTAINER_DLL_remove (exit->receive_queue_head, 1012 GNUNET_CONTAINER_DLL_remove(exit->receive_queue_head,
1012 exit->receive_queue_tail, 1013 exit->receive_queue_tail,
1013 rc); 1014 rc);
1014 rc->exit = alt; 1015 rc->exit = alt;
1015 GNUNET_CONTAINER_DLL_insert (alt->receive_queue_head, 1016 GNUNET_CONTAINER_DLL_insert(alt->receive_queue_head,
1016 alt->receive_queue_tail, 1017 alt->receive_queue_tail,
1017 rc); 1018 rc);
1018 GNUNET_MQ_send (GNUNET_CADET_get_mq (alt->cadet_channel), 1019 GNUNET_MQ_send(GNUNET_CADET_get_mq(alt->cadet_channel),
1019 GNUNET_MQ_env_copy (rc->env)); 1020 GNUNET_MQ_env_copy(rc->env));
1020 } 1021 }
1021 try_open_exit (); 1022 try_open_exit();
1022} 1023}
1023 1024
1024 1025
@@ -1030,9 +1031,9 @@ cadet_channel_end_cb (void *cls,
1030 * @param window_size how much capacity do we have 1031 * @param window_size how much capacity do we have
1031 */ 1032 */
1032static void 1033static void
1033channel_idle_notify_cb (void *cls, 1034channel_idle_notify_cb(void *cls,
1034 const struct GNUNET_CADET_Channel *channel, 1035 const struct GNUNET_CADET_Channel *channel,
1035 int window_size) 1036 int window_size)
1036{ 1037{
1037 struct CadetExit *pos = cls; 1038 struct CadetExit *pos = cls;
1038 1039
@@ -1044,69 +1045,69 @@ channel_idle_notify_cb (void *cls,
1044 * We are short on cadet exits, try to open another one. 1045 * We are short on cadet exits, try to open another one.
1045 */ 1046 */
1046static void 1047static void
1047try_open_exit () 1048try_open_exit()
1048{ 1049{
1049 struct CadetExit *pos; 1050 struct CadetExit *pos;
1050 uint32_t candidate_count; 1051 uint32_t candidate_count;
1051 uint32_t candidate_selected; 1052 uint32_t candidate_selected;
1052 struct GNUNET_HashCode port; 1053 struct GNUNET_HashCode port;
1053 1054
1054 GNUNET_CRYPTO_hash (GNUNET_APPLICATION_PORT_INTERNET_RESOLVER, 1055 GNUNET_CRYPTO_hash(GNUNET_APPLICATION_PORT_INTERNET_RESOLVER,
1055 strlen (GNUNET_APPLICATION_PORT_INTERNET_RESOLVER), 1056 strlen(GNUNET_APPLICATION_PORT_INTERNET_RESOLVER),
1056 &port); 1057 &port);
1057 candidate_count = 0; 1058 candidate_count = 0;
1058 for (pos = exit_head; NULL != pos; pos = pos->next) 1059 for (pos = exit_head; NULL != pos; pos = pos->next)
1059 if (NULL == pos->cadet_channel) 1060 if (NULL == pos->cadet_channel)
1060 candidate_count++; 1061 candidate_count++;
1061 if (0 == candidate_count) 1062 if (0 == candidate_count)
1062 { 1063 {
1063 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1064 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
1064 "No DNS exits available yet.\n"); 1065 "No DNS exits available yet.\n");
1065 return; 1066 return;
1066 } 1067 }
1067 candidate_selected = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 1068 candidate_selected = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK,
1068 candidate_count); 1069 candidate_count);
1069 candidate_count = 0; 1070 candidate_count = 0;
1070 for (pos = exit_head; NULL != pos; pos = pos->next) 1071 for (pos = exit_head; NULL != pos; pos = pos->next)
1071 if (NULL == pos->cadet_channel) 1072 if (NULL == pos->cadet_channel)
1072 {
1073 candidate_count++;
1074 if (candidate_selected < candidate_count)
1075 { 1073 {
1076 struct GNUNET_MQ_MessageHandler cadet_handlers[] = { 1074 candidate_count++;
1077 GNUNET_MQ_hd_var_size (dns_response, 1075 if (candidate_selected < candidate_count)
1078 GNUNET_MESSAGE_TYPE_VPN_DNS_FROM_INTERNET, 1076 {
1079 struct DnsResponseMessage, 1077 struct GNUNET_MQ_MessageHandler cadet_handlers[] = {
1080 pos), 1078 GNUNET_MQ_hd_var_size(dns_response,
1081 GNUNET_MQ_handler_end () 1079 GNUNET_MESSAGE_TYPE_VPN_DNS_FROM_INTERNET,
1082 }; 1080 struct DnsResponseMessage,
1083 1081 pos),
1084 1082 GNUNET_MQ_handler_end()
1085 /* move to the head of the DLL */ 1083 };
1086 pos->cadet_channel 1084
1087 = GNUNET_CADET_channel_create (cadet_handle, 1085
1088 pos, 1086 /* move to the head of the DLL */
1089 &pos->peer, 1087 pos->cadet_channel
1090 &port, 1088 = GNUNET_CADET_channel_create(cadet_handle,
1091 &channel_idle_notify_cb, 1089 pos,
1092 &cadet_channel_end_cb, 1090 &pos->peer,
1093 cadet_handlers); 1091 &port,
1094 if (NULL == pos->cadet_channel) 1092 &channel_idle_notify_cb,
1095 { 1093 &cadet_channel_end_cb,
1096 GNUNET_break (0); 1094 cadet_handlers);
1097 continue; 1095 if (NULL == pos->cadet_channel)
1098 } 1096 {
1099 GNUNET_CONTAINER_DLL_remove (exit_head, 1097 GNUNET_break(0);
1100 exit_tail, 1098 continue;
1101 pos); 1099 }
1102 GNUNET_CONTAINER_DLL_insert (exit_head, 1100 GNUNET_CONTAINER_DLL_remove(exit_head,
1103 exit_tail, 1101 exit_tail,
1104 pos); 1102 pos);
1105 dns_exit_available++; 1103 GNUNET_CONTAINER_DLL_insert(exit_head,
1106 return; 1104 exit_tail,
1105 pos);
1106 dns_exit_available++;
1107 return;
1108 }
1107 } 1109 }
1108 } 1110 GNUNET_assert(NULL == exit_head);
1109 GNUNET_assert (NULL == exit_head);
1110} 1111}
1111 1112
1112 1113
@@ -1130,42 +1131,42 @@ try_open_exit ()
1130 * @param data pointer to the result data 1131 * @param data pointer to the result data
1131 */ 1132 */
1132static void 1133static void
1133handle_dht_result (void *cls, 1134handle_dht_result(void *cls,
1134 struct GNUNET_TIME_Absolute exp, 1135 struct GNUNET_TIME_Absolute exp,
1135 const struct GNUNET_HashCode *key, 1136 const struct GNUNET_HashCode *key,
1136 const struct GNUNET_PeerIdentity *get_path, 1137 const struct GNUNET_PeerIdentity *get_path,
1137 unsigned int get_path_length, 1138 unsigned int get_path_length,
1138 const struct GNUNET_PeerIdentity *put_path, 1139 const struct GNUNET_PeerIdentity *put_path,
1139 unsigned int put_path_length, 1140 unsigned int put_path_length,
1140 enum GNUNET_BLOCK_Type type, 1141 enum GNUNET_BLOCK_Type type,
1141 size_t size, const void *data) 1142 size_t size, const void *data)
1142{ 1143{
1143 const struct GNUNET_DNS_Advertisement *ad; 1144 const struct GNUNET_DNS_Advertisement *ad;
1144 struct CadetExit *exit; 1145 struct CadetExit *exit;
1145 1146
1146 if (sizeof (struct GNUNET_DNS_Advertisement) != size) 1147 if (sizeof(struct GNUNET_DNS_Advertisement) != size)
1147 { 1148 {
1148 GNUNET_break (0); 1149 GNUNET_break(0);
1149 return; 1150 return;
1150 } 1151 }
1151 ad = data; 1152 ad = data;
1152 for (exit = exit_head; NULL != exit; exit = exit->next) 1153 for (exit = exit_head; NULL != exit; exit = exit->next)
1153 if (0 == GNUNET_memcmp (&ad->peer, 1154 if (0 == GNUNET_memcmp(&ad->peer,
1154 &exit->peer)) 1155 &exit->peer))
1155 break; 1156 break;
1156 if (NULL == exit) 1157 if (NULL == exit)
1157 { 1158 {
1158 exit = GNUNET_new (struct CadetExit); 1159 exit = GNUNET_new(struct CadetExit);
1159 exit->peer = ad->peer; 1160 exit->peer = ad->peer;
1160 /* channel is closed, so insert at the end */ 1161 /* channel is closed, so insert at the end */
1161 GNUNET_CONTAINER_DLL_insert_tail (exit_head, 1162 GNUNET_CONTAINER_DLL_insert_tail(exit_head,
1162 exit_tail, 1163 exit_tail,
1163 exit); 1164 exit);
1164 } 1165 }
1165 exit->expiration = GNUNET_TIME_absolute_max (exit->expiration, 1166 exit->expiration = GNUNET_TIME_absolute_max(exit->expiration,
1166 GNUNET_TIME_absolute_ntoh (ad->expiration_time)); 1167 GNUNET_TIME_absolute_ntoh(ad->expiration_time));
1167 if (dns_exit_available < MAX_OPEN_TUNNELS) 1168 if (dns_exit_available < MAX_OPEN_TUNNELS)
1168 try_open_exit (); 1169 try_open_exit();
1169} 1170}
1170 1171
1171 1172
@@ -1178,102 +1179,102 @@ handle_dht_result (void *cls,
1178 * @param cfg_ configuration 1179 * @param cfg_ configuration
1179 */ 1180 */
1180static void 1181static void
1181run (void *cls, char *const *args GNUNET_UNUSED, 1182run(void *cls, char *const *args GNUNET_UNUSED,
1182 const char *cfgfile GNUNET_UNUSED, 1183 const char *cfgfile GNUNET_UNUSED,
1183 const struct GNUNET_CONFIGURATION_Handle *cfg_) 1184 const struct GNUNET_CONFIGURATION_Handle *cfg_)
1184{ 1185{
1185 struct GNUNET_HashCode dns_key; 1186 struct GNUNET_HashCode dns_key;
1186 1187
1187 cfg = cfg_; 1188 cfg = cfg_;
1188 stats = GNUNET_STATISTICS_create ("pt", 1189 stats = GNUNET_STATISTICS_create("pt",
1189 cfg); 1190 cfg);
1190 ipv4_pt = GNUNET_CONFIGURATION_get_value_yesno (cfg, 1191 ipv4_pt = GNUNET_CONFIGURATION_get_value_yesno(cfg,
1191 "pt", 1192 "pt",
1192 "TUNNEL_IPV4"); 1193 "TUNNEL_IPV4");
1193 ipv6_pt = GNUNET_CONFIGURATION_get_value_yesno (cfg, 1194 ipv6_pt = GNUNET_CONFIGURATION_get_value_yesno(cfg,
1194 "pt", 1195 "pt",
1195 "TUNNEL_IPV6"); 1196 "TUNNEL_IPV6");
1196 dns_channel = GNUNET_CONFIGURATION_get_value_yesno (cfg, 1197 dns_channel = GNUNET_CONFIGURATION_get_value_yesno(cfg,
1197 "pt", 1198 "pt",
1198 "TUNNEL_DNS"); 1199 "TUNNEL_DNS");
1199 if (! (ipv4_pt || ipv6_pt || dns_channel)) 1200 if (!(ipv4_pt || ipv6_pt || dns_channel))
1200 {
1201 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1202 _("No useful service enabled. Exiting.\n"));
1203 GNUNET_SCHEDULER_shutdown ();
1204 return;
1205 }
1206 GNUNET_SCHEDULER_add_shutdown (&cleanup, cls);
1207 if (ipv4_pt || ipv6_pt)
1208 {
1209 dns_post_handle
1210 = GNUNET_DNS_connect (cfg,
1211 GNUNET_DNS_FLAG_POST_RESOLUTION,
1212 &dns_post_request_handler,
1213 NULL);
1214 if (NULL == dns_post_handle)
1215 { 1201 {
1216 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1202 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1217 _("Failed to connect to %s service. Exiting.\n"), 1203 _("No useful service enabled. Exiting.\n"));
1218 "DNS"); 1204 GNUNET_SCHEDULER_shutdown();
1219 GNUNET_SCHEDULER_shutdown ();
1220 return; 1205 return;
1221 } 1206 }
1222 vpn_handle = GNUNET_VPN_connect (cfg); 1207 GNUNET_SCHEDULER_add_shutdown(&cleanup, cls);
1223 if (NULL == vpn_handle) 1208 if (ipv4_pt || ipv6_pt)
1224 { 1209 {
1225 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1210 dns_post_handle
1226 _("Failed to connect to %s service. Exiting.\n"), 1211 = GNUNET_DNS_connect(cfg,
1227 "VPN"); 1212 GNUNET_DNS_FLAG_POST_RESOLUTION,
1228 GNUNET_SCHEDULER_shutdown (); 1213 &dns_post_request_handler,
1229 return; 1214 NULL);
1215 if (NULL == dns_post_handle)
1216 {
1217 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1218 _("Failed to connect to %s service. Exiting.\n"),
1219 "DNS");
1220 GNUNET_SCHEDULER_shutdown();
1221 return;
1222 }
1223 vpn_handle = GNUNET_VPN_connect(cfg);
1224 if (NULL == vpn_handle)
1225 {
1226 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1227 _("Failed to connect to %s service. Exiting.\n"),
1228 "VPN");
1229 GNUNET_SCHEDULER_shutdown();
1230 return;
1231 }
1230 } 1232 }
1231 }
1232 if (dns_channel) 1233 if (dns_channel)
1233 {
1234 dns_pre_handle
1235 = GNUNET_DNS_connect (cfg,
1236 GNUNET_DNS_FLAG_PRE_RESOLUTION,
1237 &dns_pre_request_handler,
1238 NULL);
1239 if (NULL == dns_pre_handle)
1240 { 1234 {
1241 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1235 dns_pre_handle
1242 _("Failed to connect to %s service. Exiting.\n"), 1236 = GNUNET_DNS_connect(cfg,
1243 "DNS"); 1237 GNUNET_DNS_FLAG_PRE_RESOLUTION,
1244 GNUNET_SCHEDULER_shutdown (); 1238 &dns_pre_request_handler,
1245 return; 1239 NULL);
1246 } 1240 if (NULL == dns_pre_handle)
1247 cadet_handle = GNUNET_CADET_connect (cfg); 1241 {
1248 if (NULL == cadet_handle) 1242 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1249 { 1243 _("Failed to connect to %s service. Exiting.\n"),
1250 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1244 "DNS");
1251 _("Failed to connect to %s service. Exiting.\n"), 1245 GNUNET_SCHEDULER_shutdown();
1252 "CADET"); 1246 return;
1253 GNUNET_SCHEDULER_shutdown (); 1247 }
1254 return; 1248 cadet_handle = GNUNET_CADET_connect(cfg);
1255 } 1249 if (NULL == cadet_handle)
1256 dht = GNUNET_DHT_connect (cfg, 1); 1250 {
1257 if (NULL == dht) 1251 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1258 { 1252 _("Failed to connect to %s service. Exiting.\n"),
1259 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1253 "CADET");
1260 _("Failed to connect to %s service. Exiting.\n"), 1254 GNUNET_SCHEDULER_shutdown();
1261 "DHT"); 1255 return;
1262 GNUNET_SCHEDULER_shutdown (); 1256 }
1263 return; 1257 dht = GNUNET_DHT_connect(cfg, 1);
1258 if (NULL == dht)
1259 {
1260 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1261 _("Failed to connect to %s service. Exiting.\n"),
1262 "DHT");
1263 GNUNET_SCHEDULER_shutdown();
1264 return;
1265 }
1266 GNUNET_CRYPTO_hash("dns",
1267 strlen("dns"),
1268 &dns_key);
1269 dht_get = GNUNET_DHT_get_start(dht,
1270 GNUNET_BLOCK_TYPE_DNS,
1271 &dns_key,
1272 1,
1273 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
1274 NULL, 0,
1275 &handle_dht_result,
1276 NULL);
1264 } 1277 }
1265 GNUNET_CRYPTO_hash ("dns",
1266 strlen ("dns"),
1267 &dns_key);
1268 dht_get = GNUNET_DHT_get_start (dht,
1269 GNUNET_BLOCK_TYPE_DNS,
1270 &dns_key,
1271 1,
1272 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
1273 NULL, 0,
1274 &handle_dht_result,
1275 NULL);
1276 }
1277} 1278}
1278 1279
1279 1280
@@ -1285,30 +1286,30 @@ run (void *cls, char *const *args GNUNET_UNUSED,
1285 * @return 0 ok, 1 on error 1286 * @return 0 ok, 1 on error
1286 */ 1287 */
1287int 1288int
1288main (int argc, 1289main(int argc,
1289 char *const *argv) 1290 char *const *argv)
1290{ 1291{
1291 static const struct GNUNET_GETOPT_CommandLineOption options[] = { 1292 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
1292 GNUNET_GETOPT_OPTION_END 1293 GNUNET_GETOPT_OPTION_END
1293 }; 1294 };
1294 int ret; 1295 int ret;
1295 1296
1296 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, 1297 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc,
1297 argv, 1298 argv,
1298 &argc, 1299 &argc,
1299 &argv)) 1300 &argv))
1300 return 2; 1301 return 2;
1301 ret = (GNUNET_OK == 1302 ret = (GNUNET_OK ==
1302 GNUNET_PROGRAM_run (argc, 1303 GNUNET_PROGRAM_run(argc,
1303 argv, 1304 argv,
1304 "gnunet-daemon-pt", 1305 "gnunet-daemon-pt",
1305 gettext_noop ("Daemon to run to perform IP protocol translation to GNUnet"), 1306 gettext_noop("Daemon to run to perform IP protocol translation to GNUnet"),
1306 options, 1307 options,
1307 &run, 1308 &run,
1308 NULL)) 1309 NULL))
1309 ? 0 1310 ? 0
1310 : 1; 1311 : 1;
1311 GNUNET_free ((void*) argv); 1312 GNUNET_free((void*)argv);
1312 return ret; 1313 return ret;
1313} 1314}
1314 1315