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