diff options
author | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
---|---|---|
committer | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
commit | d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb (patch) | |
tree | 9efd18ea7d425652085ed0bd5e8e45604bc5f6b9 /src/namestore/gnunet-zoneimport.c | |
parent | a0fce305c565c0937d917a92712f15e9c5736260 (diff) | |
download | gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.tar.gz gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.zip |
uncrustify as demanded.
Diffstat (limited to 'src/namestore/gnunet-zoneimport.c')
-rw-r--r-- | src/namestore/gnunet-zoneimport.c | 1801 |
1 files changed, 903 insertions, 898 deletions
diff --git a/src/namestore/gnunet-zoneimport.c b/src/namestore/gnunet-zoneimport.c index 4c5205ab3..60d8b0537 100644 --- a/src/namestore/gnunet-zoneimport.c +++ b/src/namestore/gnunet-zoneimport.c | |||
@@ -16,7 +16,7 @@ | |||
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 src/namestore/gnunet-zoneimport.c | 21 | * @file src/namestore/gnunet-zoneimport.c |
22 | * @brief import a DNS zone for publication in GNS, incremental | 22 | * @brief import a DNS zone for publication in GNS, incremental |
@@ -57,7 +57,7 @@ | |||
57 | * How long do we wait at least between series of requests? | 57 | * How long do we wait at least between series of requests? |
58 | */ | 58 | */ |
59 | #define SERIES_DELAY \ | 59 | #define SERIES_DELAY \ |
60 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MICROSECONDS, 10) | 60 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MICROSECONDS, 10) |
61 | 61 | ||
62 | /** | 62 | /** |
63 | * How long do DNS records have to last at least after being imported? | 63 | * How long do DNS records have to last at least after being imported? |
@@ -76,9 +76,7 @@ static struct GNUNET_TIME_Relative minimum_expiration_time; | |||
76 | * each dot represents a zone cut, we then need to create a | 76 | * each dot represents a zone cut, we then need to create a |
77 | * zone on-the-fly to capture those records properly. | 77 | * zone on-the-fly to capture those records properly. |
78 | */ | 78 | */ |
79 | struct Zone | 79 | struct Zone { |
80 | { | ||
81 | |||
82 | /** | 80 | /** |
83 | * Kept in a DLL. | 81 | * Kept in a DLL. |
84 | */ | 82 | */ |
@@ -104,8 +102,7 @@ struct Zone | |||
104 | /** | 102 | /** |
105 | * Record for the request to be stored by GNS. | 103 | * Record for the request to be stored by GNS. |
106 | */ | 104 | */ |
107 | struct Record | 105 | struct Record { |
108 | { | ||
109 | /** | 106 | /** |
110 | * Kept in a DLL. | 107 | * Kept in a DLL. |
111 | */ | 108 | */ |
@@ -128,8 +125,7 @@ struct Record | |||
128 | * thus optimizing it is crucial for the overall memory consumption of | 125 | * thus optimizing it is crucial for the overall memory consumption of |
129 | * the zone importer. | 126 | * the zone importer. |
130 | */ | 127 | */ |
131 | struct Request | 128 | struct Request { |
132 | { | ||
133 | /** | 129 | /** |
134 | * Requests are kept in a heap while waiting to be resolved. | 130 | * Requests are kept in a heap while waiting to be resolved. |
135 | */ | 131 | */ |
@@ -379,28 +375,28 @@ typedef void (*RecordProcessor) (void *cls, | |||
379 | * @param rp_cls closure for @a rp | 375 | * @param rp_cls closure for @a rp |
380 | */ | 376 | */ |
381 | static void | 377 | static void |
382 | for_all_records (const struct GNUNET_DNSPARSER_Packet *p, | 378 | for_all_records(const struct GNUNET_DNSPARSER_Packet *p, |
383 | RecordProcessor rp, | 379 | RecordProcessor rp, |
384 | void *rp_cls) | 380 | void *rp_cls) |
385 | { | 381 | { |
386 | for (unsigned int i = 0; i < p->num_answers; i++) | 382 | for (unsigned int i = 0; i < p->num_answers; i++) |
387 | { | 383 | { |
388 | struct GNUNET_DNSPARSER_Record *rs = &p->answers[i]; | 384 | struct GNUNET_DNSPARSER_Record *rs = &p->answers[i]; |
389 | 385 | ||
390 | rp (rp_cls, rs); | 386 | rp(rp_cls, rs); |
391 | } | 387 | } |
392 | for (unsigned int i = 0; i < p->num_authority_records; i++) | 388 | for (unsigned int i = 0; i < p->num_authority_records; i++) |
393 | { | 389 | { |
394 | struct GNUNET_DNSPARSER_Record *rs = &p->authority_records[i]; | 390 | struct GNUNET_DNSPARSER_Record *rs = &p->authority_records[i]; |
395 | 391 | ||
396 | rp (rp_cls, rs); | 392 | rp(rp_cls, rs); |
397 | } | 393 | } |
398 | for (unsigned int i = 0; i < p->num_additional_records; i++) | 394 | for (unsigned int i = 0; i < p->num_additional_records; i++) |
399 | { | 395 | { |
400 | struct GNUNET_DNSPARSER_Record *rs = &p->additional_records[i]; | 396 | struct GNUNET_DNSPARSER_Record *rs = &p->additional_records[i]; |
401 | 397 | ||
402 | rp (rp_cls, rs); | 398 | rp(rp_cls, rs); |
403 | } | 399 | } |
404 | } | 400 | } |
405 | 401 | ||
406 | 402 | ||
@@ -412,23 +408,23 @@ for_all_records (const struct GNUNET_DNSPARSER_Packet *p, | |||
412 | * overwritten upon the next request! | 408 | * overwritten upon the next request! |
413 | */ | 409 | */ |
414 | static const char * | 410 | static const char * |
415 | get_label (struct Request *req) | 411 | get_label(struct Request *req) |
416 | { | 412 | { |
417 | static char label[64]; | 413 | static char label[64]; |
418 | const char *dot; | 414 | const char *dot; |
419 | 415 | ||
420 | dot = strchr (req->hostname, (unsigned char) '.'); | 416 | dot = strchr(req->hostname, (unsigned char)'.'); |
421 | if (NULL == dot) | 417 | if (NULL == dot) |
422 | { | 418 | { |
423 | GNUNET_break (0); | 419 | GNUNET_break(0); |
424 | return NULL; | 420 | return NULL; |
425 | } | 421 | } |
426 | if (((size_t) (dot - req->hostname)) >= sizeof (label)) | 422 | if (((size_t)(dot - req->hostname)) >= sizeof(label)) |
427 | { | 423 | { |
428 | GNUNET_break (0); | 424 | GNUNET_break(0); |
429 | return NULL; | 425 | return NULL; |
430 | } | 426 | } |
431 | GNUNET_memcpy (label, req->hostname, dot - req->hostname); | 427 | GNUNET_memcpy(label, req->hostname, dot - req->hostname); |
432 | label[dot - req->hostname] = '\0'; | 428 | label[dot - req->hostname] = '\0'; |
433 | return label; | 429 | return label; |
434 | } | 430 | } |
@@ -443,7 +439,7 @@ get_label (struct Request *req) | |||
443 | * allocated query buffer | 439 | * allocated query buffer |
444 | */ | 440 | */ |
445 | static void * | 441 | static void * |
446 | build_dns_query (struct Request *req, size_t *raw_size) | 442 | build_dns_query(struct Request *req, size_t *raw_size) |
447 | { | 443 | { |
448 | static char raw[512]; | 444 | static char raw[512]; |
449 | char *rawp; | 445 | char *rawp; |
@@ -451,37 +447,37 @@ build_dns_query (struct Request *req, size_t *raw_size) | |||
451 | struct GNUNET_DNSPARSER_Query q; | 447 | struct GNUNET_DNSPARSER_Query q; |
452 | int ret; | 448 | int ret; |
453 | 449 | ||
454 | q.name = (char *) req->hostname; | 450 | q.name = (char *)req->hostname; |
455 | q.type = GNUNET_DNSPARSER_TYPE_NS; | 451 | q.type = GNUNET_DNSPARSER_TYPE_NS; |
456 | q.dns_traffic_class = GNUNET_TUN_DNS_CLASS_INTERNET; | 452 | q.dns_traffic_class = GNUNET_TUN_DNS_CLASS_INTERNET; |
457 | 453 | ||
458 | memset (&p, 0, sizeof (p)); | 454 | memset(&p, 0, sizeof(p)); |
459 | p.num_queries = 1; | 455 | p.num_queries = 1; |
460 | p.queries = &q; | 456 | p.queries = &q; |
461 | p.id = req->id; | 457 | p.id = req->id; |
462 | ret = GNUNET_DNSPARSER_pack (&p, UINT16_MAX, &rawp, raw_size); | 458 | ret = GNUNET_DNSPARSER_pack(&p, UINT16_MAX, &rawp, raw_size); |
463 | if (GNUNET_OK != ret) | 459 | if (GNUNET_OK != ret) |
464 | { | 460 | { |
465 | if (GNUNET_NO == ret) | 461 | if (GNUNET_NO == ret) |
466 | GNUNET_free (rawp); | 462 | GNUNET_free(rawp); |
467 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 463 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
468 | "Failed to pack query for hostname `%s'\n", | 464 | "Failed to pack query for hostname `%s'\n", |
469 | req->hostname); | 465 | req->hostname); |
470 | rejects++; | 466 | rejects++; |
471 | return NULL; | 467 | return NULL; |
472 | } | 468 | } |
473 | if (*raw_size > sizeof (raw)) | 469 | if (*raw_size > sizeof(raw)) |
474 | { | 470 | { |
475 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 471 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
476 | "Failed to pack query for hostname `%s'\n", | 472 | "Failed to pack query for hostname `%s'\n", |
477 | req->hostname); | 473 | req->hostname); |
478 | rejects++; | 474 | rejects++; |
479 | GNUNET_break (0); | 475 | GNUNET_break(0); |
480 | GNUNET_free (rawp); | 476 | GNUNET_free(rawp); |
481 | return NULL; | 477 | return NULL; |
482 | } | 478 | } |
483 | GNUNET_memcpy (raw, rawp, *raw_size); | 479 | GNUNET_memcpy(raw, rawp, *raw_size); |
484 | GNUNET_free (rawp); | 480 | GNUNET_free(rawp); |
485 | return raw; | 481 | return raw; |
486 | } | 482 | } |
487 | 483 | ||
@@ -492,16 +488,16 @@ build_dns_query (struct Request *req, size_t *raw_size) | |||
492 | * @param req request to free records of | 488 | * @param req request to free records of |
493 | */ | 489 | */ |
494 | static void | 490 | static void |
495 | free_records (struct Request *req) | 491 | free_records(struct Request *req) |
496 | { | 492 | { |
497 | struct Record *rec; | 493 | struct Record *rec; |
498 | 494 | ||
499 | /* Free records */ | 495 | /* Free records */ |
500 | while (NULL != (rec = req->rec_head)) | 496 | while (NULL != (rec = req->rec_head)) |
501 | { | 497 | { |
502 | GNUNET_CONTAINER_DLL_remove (req->rec_head, req->rec_tail, rec); | 498 | GNUNET_CONTAINER_DLL_remove(req->rec_head, req->rec_tail, rec); |
503 | GNUNET_free (rec); | 499 | GNUNET_free(rec); |
504 | } | 500 | } |
505 | } | 501 | } |
506 | 502 | ||
507 | 503 | ||
@@ -511,10 +507,10 @@ free_records (struct Request *req) | |||
511 | * @param req request to free | 507 | * @param req request to free |
512 | */ | 508 | */ |
513 | static void | 509 | static void |
514 | free_request (struct Request *req) | 510 | free_request(struct Request *req) |
515 | { | 511 | { |
516 | free_records (req); | 512 | free_records(req); |
517 | GNUNET_free (req); | 513 | GNUNET_free(req); |
518 | } | 514 | } |
519 | 515 | ||
520 | 516 | ||
@@ -524,7 +520,7 @@ free_request (struct Request *req) | |||
524 | * @param cls NULL | 520 | * @param cls NULL |
525 | */ | 521 | */ |
526 | static void | 522 | static void |
527 | process_queue (void *cls); | 523 | process_queue(void *cls); |
528 | 524 | ||
529 | 525 | ||
530 | /** | 526 | /** |
@@ -533,17 +529,17 @@ process_queue (void *cls); | |||
533 | * @param req request to insert into #req_heap | 529 | * @param req request to insert into #req_heap |
534 | */ | 530 | */ |
535 | static void | 531 | static void |
536 | insert_sorted (struct Request *req) | 532 | insert_sorted(struct Request *req) |
537 | { | 533 | { |
538 | req->hn = | 534 | req->hn = |
539 | GNUNET_CONTAINER_heap_insert (req_heap, req, req->expires.abs_value_us); | 535 | GNUNET_CONTAINER_heap_insert(req_heap, req, req->expires.abs_value_us); |
540 | if (req == GNUNET_CONTAINER_heap_peek (req_heap)) | 536 | if (req == GNUNET_CONTAINER_heap_peek(req_heap)) |
541 | { | 537 | { |
542 | if (NULL != t) | 538 | if (NULL != t) |
543 | GNUNET_SCHEDULER_cancel (t); | 539 | GNUNET_SCHEDULER_cancel(t); |
544 | sleep_time_reg_proc = GNUNET_TIME_absolute_get (); | 540 | sleep_time_reg_proc = GNUNET_TIME_absolute_get(); |
545 | t = GNUNET_SCHEDULER_add_at (req->expires, &process_queue, NULL); | 541 | t = GNUNET_SCHEDULER_add_at(req->expires, &process_queue, NULL); |
546 | } | 542 | } |
547 | } | 543 | } |
548 | 544 | ||
549 | 545 | ||
@@ -557,30 +553,29 @@ insert_sorted (struct Request *req) | |||
557 | * @param data_len number of bytes in @a data | 553 | * @param data_len number of bytes in @a data |
558 | */ | 554 | */ |
559 | static void | 555 | static void |
560 | add_record (struct Request *req, | 556 | add_record(struct Request *req, |
561 | uint32_t type, | 557 | uint32_t type, |
562 | struct GNUNET_TIME_Absolute expiration_time, | 558 | struct GNUNET_TIME_Absolute expiration_time, |
563 | const void *data, | 559 | const void *data, |
564 | size_t data_len) | 560 | size_t data_len) |
565 | { | 561 | { |
566 | struct Record *rec; | 562 | struct Record *rec; |
567 | 563 | ||
568 | rec = GNUNET_malloc (sizeof (struct Record) + data_len); | 564 | rec = GNUNET_malloc(sizeof(struct Record) + data_len); |
569 | rec->grd.data = &rec[1]; | 565 | rec->grd.data = &rec[1]; |
570 | rec->grd.expiration_time = expiration_time.abs_value_us; | 566 | rec->grd.expiration_time = expiration_time.abs_value_us; |
571 | rec->grd.data_size = data_len; | 567 | rec->grd.data_size = data_len; |
572 | rec->grd.record_type = type; | 568 | rec->grd.record_type = type; |
573 | rec->grd.flags = GNUNET_GNSRECORD_RF_NONE; | 569 | rec->grd.flags = GNUNET_GNSRECORD_RF_NONE; |
574 | GNUNET_memcpy (&rec[1], data, data_len); | 570 | GNUNET_memcpy(&rec[1], data, data_len); |
575 | GNUNET_CONTAINER_DLL_insert (req->rec_head, req->rec_tail, rec); | 571 | GNUNET_CONTAINER_DLL_insert(req->rec_head, req->rec_tail, rec); |
576 | } | 572 | } |
577 | 573 | ||
578 | 574 | ||
579 | /** | 575 | /** |
580 | * Closure for #check_for_glue. | 576 | * Closure for #check_for_glue. |
581 | */ | 577 | */ |
582 | struct GlueClosure | 578 | struct GlueClosure { |
583 | { | ||
584 | /** | 579 | /** |
585 | * Overall request we are processing. | 580 | * Overall request we are processing. |
586 | */ | 581 | */ |
@@ -605,113 +600,115 @@ struct GlueClosure | |||
605 | * @param rec record that may contain glue information | 600 | * @param rec record that may contain glue information |
606 | */ | 601 | */ |
607 | static void | 602 | static void |
608 | check_for_glue (void *cls, const struct GNUNET_DNSPARSER_Record *rec) | 603 | check_for_glue(void *cls, const struct GNUNET_DNSPARSER_Record *rec) |
609 | { | 604 | { |
610 | struct GlueClosure *gc = cls; | 605 | struct GlueClosure *gc = cls; |
611 | char dst[65536]; | 606 | char dst[65536]; |
612 | size_t dst_len; | 607 | size_t dst_len; |
613 | size_t off; | 608 | size_t off; |
614 | char ip[INET6_ADDRSTRLEN + 1]; | 609 | char ip[INET6_ADDRSTRLEN + 1]; |
615 | socklen_t ip_size = (socklen_t) sizeof (ip); | 610 | socklen_t ip_size = (socklen_t)sizeof(ip); |
616 | struct GNUNET_TIME_Absolute expiration_time; | 611 | struct GNUNET_TIME_Absolute expiration_time; |
617 | struct GNUNET_TIME_Relative left; | 612 | struct GNUNET_TIME_Relative left; |
618 | 613 | ||
619 | if (0 != strcasecmp (rec->name, gc->ns)) | 614 | if (0 != strcasecmp(rec->name, gc->ns)) |
620 | return; | 615 | return; |
621 | expiration_time = rec->expiration_time; | 616 | expiration_time = rec->expiration_time; |
622 | left = GNUNET_TIME_absolute_get_remaining (expiration_time); | 617 | left = GNUNET_TIME_absolute_get_remaining(expiration_time); |
623 | if (0 == left.rel_value_us) | 618 | if (0 == left.rel_value_us) |
624 | return; /* ignore expired glue records */ | 619 | return; /* ignore expired glue records */ |
625 | /* if expiration window is too short, bump it to configured minimum */ | 620 | /* if expiration window is too short, bump it to configured minimum */ |
626 | if (left.rel_value_us < minimum_expiration_time.rel_value_us) | 621 | if (left.rel_value_us < minimum_expiration_time.rel_value_us) |
627 | expiration_time = | 622 | expiration_time = |
628 | GNUNET_TIME_relative_to_absolute (minimum_expiration_time); | 623 | GNUNET_TIME_relative_to_absolute(minimum_expiration_time); |
629 | dst_len = sizeof (dst); | 624 | dst_len = sizeof(dst); |
630 | off = 0; | 625 | off = 0; |
631 | switch (rec->type) | 626 | switch (rec->type) |
632 | { | ||
633 | case GNUNET_DNSPARSER_TYPE_A: | ||
634 | if (sizeof (struct in_addr) != rec->data.raw.data_len) | ||
635 | { | ||
636 | GNUNET_break (0); | ||
637 | return; | ||
638 | } | ||
639 | if (NULL == inet_ntop (AF_INET, rec->data.raw.data, ip, ip_size)) | ||
640 | { | ||
641 | GNUNET_break (0); | ||
642 | return; | ||
643 | } | ||
644 | if ((GNUNET_OK == GNUNET_DNSPARSER_builder_add_name (dst, | ||
645 | dst_len, | ||
646 | &off, | ||
647 | gc->req->hostname)) && | ||
648 | (GNUNET_OK == | ||
649 | GNUNET_DNSPARSER_builder_add_name (dst, dst_len, &off, ip))) | ||
650 | { | ||
651 | add_record (gc->req, | ||
652 | GNUNET_GNSRECORD_TYPE_GNS2DNS, | ||
653 | expiration_time, | ||
654 | dst, | ||
655 | off); | ||
656 | gc->found = GNUNET_YES; | ||
657 | } | ||
658 | break; | ||
659 | case GNUNET_DNSPARSER_TYPE_AAAA: | ||
660 | if (sizeof (struct in6_addr) != rec->data.raw.data_len) | ||
661 | { | ||
662 | GNUNET_break (0); | ||
663 | return; | ||
664 | } | ||
665 | if (NULL == inet_ntop (AF_INET6, rec->data.raw.data, ip, ip_size)) | ||
666 | { | ||
667 | GNUNET_break (0); | ||
668 | return; | ||
669 | } | ||
670 | if ((GNUNET_OK == GNUNET_DNSPARSER_builder_add_name (dst, | ||
671 | dst_len, | ||
672 | &off, | ||
673 | gc->req->hostname)) && | ||
674 | (GNUNET_OK == | ||
675 | GNUNET_DNSPARSER_builder_add_name (dst, dst_len, &off, ip))) | ||
676 | { | ||
677 | add_record (gc->req, | ||
678 | GNUNET_GNSRECORD_TYPE_GNS2DNS, | ||
679 | expiration_time, | ||
680 | dst, | ||
681 | off); | ||
682 | gc->found = GNUNET_YES; | ||
683 | } | ||
684 | break; | ||
685 | case GNUNET_DNSPARSER_TYPE_CNAME: | ||
686 | if ((GNUNET_OK == GNUNET_DNSPARSER_builder_add_name (dst, | ||
687 | dst_len, | ||
688 | &off, | ||
689 | gc->req->hostname)) && | ||
690 | (GNUNET_OK == GNUNET_DNSPARSER_builder_add_name (dst, | ||
691 | dst_len, | ||
692 | &off, | ||
693 | rec->data.hostname))) | ||
694 | { | 627 | { |
695 | add_record (gc->req, | 628 | case GNUNET_DNSPARSER_TYPE_A: |
696 | GNUNET_GNSRECORD_TYPE_GNS2DNS, | 629 | if (sizeof(struct in_addr) != rec->data.raw.data_len) |
697 | expiration_time, | 630 | { |
698 | dst, | 631 | GNUNET_break(0); |
699 | off); | 632 | return; |
700 | gc->found = GNUNET_YES; | 633 | } |
634 | if (NULL == inet_ntop(AF_INET, rec->data.raw.data, ip, ip_size)) | ||
635 | { | ||
636 | GNUNET_break(0); | ||
637 | return; | ||
638 | } | ||
639 | if ((GNUNET_OK == GNUNET_DNSPARSER_builder_add_name(dst, | ||
640 | dst_len, | ||
641 | &off, | ||
642 | gc->req->hostname)) && | ||
643 | (GNUNET_OK == | ||
644 | GNUNET_DNSPARSER_builder_add_name(dst, dst_len, &off, ip))) | ||
645 | { | ||
646 | add_record(gc->req, | ||
647 | GNUNET_GNSRECORD_TYPE_GNS2DNS, | ||
648 | expiration_time, | ||
649 | dst, | ||
650 | off); | ||
651 | gc->found = GNUNET_YES; | ||
652 | } | ||
653 | break; | ||
654 | |||
655 | case GNUNET_DNSPARSER_TYPE_AAAA: | ||
656 | if (sizeof(struct in6_addr) != rec->data.raw.data_len) | ||
657 | { | ||
658 | GNUNET_break(0); | ||
659 | return; | ||
660 | } | ||
661 | if (NULL == inet_ntop(AF_INET6, rec->data.raw.data, ip, ip_size)) | ||
662 | { | ||
663 | GNUNET_break(0); | ||
664 | return; | ||
665 | } | ||
666 | if ((GNUNET_OK == GNUNET_DNSPARSER_builder_add_name(dst, | ||
667 | dst_len, | ||
668 | &off, | ||
669 | gc->req->hostname)) && | ||
670 | (GNUNET_OK == | ||
671 | GNUNET_DNSPARSER_builder_add_name(dst, dst_len, &off, ip))) | ||
672 | { | ||
673 | add_record(gc->req, | ||
674 | GNUNET_GNSRECORD_TYPE_GNS2DNS, | ||
675 | expiration_time, | ||
676 | dst, | ||
677 | off); | ||
678 | gc->found = GNUNET_YES; | ||
679 | } | ||
680 | break; | ||
681 | |||
682 | case GNUNET_DNSPARSER_TYPE_CNAME: | ||
683 | if ((GNUNET_OK == GNUNET_DNSPARSER_builder_add_name(dst, | ||
684 | dst_len, | ||
685 | &off, | ||
686 | gc->req->hostname)) && | ||
687 | (GNUNET_OK == GNUNET_DNSPARSER_builder_add_name(dst, | ||
688 | dst_len, | ||
689 | &off, | ||
690 | rec->data.hostname))) | ||
691 | { | ||
692 | add_record(gc->req, | ||
693 | GNUNET_GNSRECORD_TYPE_GNS2DNS, | ||
694 | expiration_time, | ||
695 | dst, | ||
696 | off); | ||
697 | gc->found = GNUNET_YES; | ||
698 | } | ||
699 | break; | ||
700 | |||
701 | default: | ||
702 | /* useless, do nothing */ | ||
703 | break; | ||
701 | } | 704 | } |
702 | break; | ||
703 | default: | ||
704 | /* useless, do nothing */ | ||
705 | break; | ||
706 | } | ||
707 | } | 705 | } |
708 | 706 | ||
709 | 707 | ||
710 | /** | 708 | /** |
711 | * Closure for #process_record(). | 709 | * Closure for #process_record(). |
712 | */ | 710 | */ |
713 | struct ProcessRecordContext | 711 | struct ProcessRecordContext { |
714 | { | ||
715 | /** | 712 | /** |
716 | * Answer we got back and are currently parsing, or NULL | 713 | * Answer we got back and are currently parsing, or NULL |
717 | * if not active. | 714 | * if not active. |
@@ -732,7 +729,7 @@ struct ProcessRecordContext | |||
732 | * @param rec response | 729 | * @param rec response |
733 | */ | 730 | */ |
734 | static void | 731 | static void |
735 | process_record (void *cls, const struct GNUNET_DNSPARSER_Record *rec) | 732 | process_record(void *cls, const struct GNUNET_DNSPARSER_Record *rec) |
736 | { | 733 | { |
737 | struct ProcessRecordContext *prc = cls; | 734 | struct ProcessRecordContext *prc = cls; |
738 | struct Request *req = prc->req; | 735 | struct Request *req = prc->req; |
@@ -742,175 +739,183 @@ process_record (void *cls, const struct GNUNET_DNSPARSER_Record *rec) | |||
742 | struct GNUNET_TIME_Absolute expiration_time; | 739 | struct GNUNET_TIME_Absolute expiration_time; |
743 | struct GNUNET_TIME_Relative left; | 740 | struct GNUNET_TIME_Relative left; |
744 | 741 | ||
745 | dst_len = sizeof (dst); | 742 | dst_len = sizeof(dst); |
746 | off = 0; | 743 | off = 0; |
747 | records++; | 744 | records++; |
748 | if (0 != strcasecmp (rec->name, req->hostname)) | 745 | if (0 != strcasecmp(rec->name, req->hostname)) |
749 | { | 746 | { |
750 | GNUNET_log ( | 747 | GNUNET_log( |
751 | GNUNET_ERROR_TYPE_DEBUG, | 748 | GNUNET_ERROR_TYPE_DEBUG, |
752 | "DNS returned record from zone `%s' of type %u while resolving `%s'\n", | 749 | "DNS returned record from zone `%s' of type %u while resolving `%s'\n", |
753 | rec->name, | 750 | rec->name, |
754 | (unsigned int) rec->type, | 751 | (unsigned int)rec->type, |
755 | req->hostname); | 752 | req->hostname); |
756 | return; /* does not match hostname, might be glue, but | 753 | return; /* does not match hostname, might be glue, but |
757 | not useful for this pass! */ | 754 | not useful for this pass! */ |
758 | } | 755 | } |
759 | expiration_time = rec->expiration_time; | 756 | expiration_time = rec->expiration_time; |
760 | left = GNUNET_TIME_absolute_get_remaining (expiration_time); | 757 | left = GNUNET_TIME_absolute_get_remaining(expiration_time); |
761 | if (0 == left.rel_value_us) | 758 | if (0 == left.rel_value_us) |
762 | { | 759 | { |
763 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 760 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
764 | "DNS returned expired record for `%s'\n", | 761 | "DNS returned expired record for `%s'\n", |
765 | req->hostname); | 762 | req->hostname); |
766 | GNUNET_STATISTICS_update (stats, | 763 | GNUNET_STATISTICS_update(stats, |
767 | "# expired records obtained from DNS", | 764 | "# expired records obtained from DNS", |
768 | 1, | 765 | 1, |
769 | GNUNET_NO); | 766 | GNUNET_NO); |
770 | return; /* record expired */ | 767 | return; /* record expired */ |
771 | } | 768 | } |
772 | 769 | ||
773 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 770 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
774 | "DNS returned record that expires at %s for `%s'\n", | 771 | "DNS returned record that expires at %s for `%s'\n", |
775 | GNUNET_STRINGS_absolute_time_to_string (expiration_time), | 772 | GNUNET_STRINGS_absolute_time_to_string(expiration_time), |
776 | req->hostname); | 773 | req->hostname); |
777 | /* if expiration window is too short, bump it to configured minimum */ | 774 | /* if expiration window is too short, bump it to configured minimum */ |
778 | if (left.rel_value_us < minimum_expiration_time.rel_value_us) | 775 | if (left.rel_value_us < minimum_expiration_time.rel_value_us) |
779 | expiration_time = | 776 | expiration_time = |
780 | GNUNET_TIME_relative_to_absolute (minimum_expiration_time); | 777 | GNUNET_TIME_relative_to_absolute(minimum_expiration_time); |
781 | switch (rec->type) | 778 | switch (rec->type) |
782 | { | 779 | { |
783 | case GNUNET_DNSPARSER_TYPE_NS: { | 780 | case GNUNET_DNSPARSER_TYPE_NS: { |
784 | struct GlueClosure gc; | 781 | struct GlueClosure gc; |
785 | 782 | ||
786 | /* check for glue */ | 783 | /* check for glue */ |
787 | gc.req = req; | 784 | gc.req = req; |
788 | gc.ns = rec->data.hostname; | 785 | gc.ns = rec->data.hostname; |
789 | gc.found = GNUNET_NO; | 786 | gc.found = GNUNET_NO; |
790 | for_all_records (prc->p, &check_for_glue, &gc); | 787 | for_all_records(prc->p, &check_for_glue, &gc); |
791 | if ((GNUNET_NO == gc.found) && | 788 | if ((GNUNET_NO == gc.found) && |
792 | (GNUNET_OK == GNUNET_DNSPARSER_builder_add_name (dst, | 789 | (GNUNET_OK == GNUNET_DNSPARSER_builder_add_name(dst, |
790 | dst_len, | ||
791 | &off, | ||
792 | req->hostname)) && | ||
793 | (GNUNET_OK == GNUNET_DNSPARSER_builder_add_name(dst, | ||
794 | dst_len, | ||
795 | &off, | ||
796 | rec->data.hostname))) | ||
797 | { | ||
798 | /* FIXME: actually check if this is out-of-bailiwick, | ||
799 | and if not request explicit resolution... */ | ||
800 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
801 | "Converted OOB (`%s') NS record for `%s'\n", | ||
802 | rec->data.hostname, | ||
803 | rec->name); | ||
804 | add_record(req, | ||
805 | GNUNET_GNSRECORD_TYPE_GNS2DNS, | ||
806 | expiration_time, | ||
807 | dst, | ||
808 | off); | ||
809 | } | ||
810 | else | ||
811 | { | ||
812 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
813 | "Converted NS record for `%s' using glue\n", | ||
814 | rec->name); | ||
815 | } | ||
816 | break; | ||
817 | } | ||
818 | |||
819 | case GNUNET_DNSPARSER_TYPE_CNAME: | ||
820 | if (GNUNET_OK == GNUNET_DNSPARSER_builder_add_name(dst, | ||
793 | dst_len, | 821 | dst_len, |
794 | &off, | 822 | &off, |
795 | req->hostname)) && | 823 | rec->data.hostname)) |
796 | (GNUNET_OK == GNUNET_DNSPARSER_builder_add_name (dst, | 824 | { |
825 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
826 | "Converting CNAME (`%s') record for `%s'\n", | ||
827 | rec->data.hostname, | ||
828 | rec->name); | ||
829 | add_record(req, rec->type, expiration_time, dst, off); | ||
830 | } | ||
831 | break; | ||
832 | |||
833 | case GNUNET_DNSPARSER_TYPE_DNAME: | ||
834 | /* No support for DNAME in GNS yet! FIXME: support later! */ | ||
835 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | ||
836 | "FIXME: not supported: %s DNAME %s\n", | ||
837 | rec->name, | ||
838 | rec->data.hostname); | ||
839 | break; | ||
840 | |||
841 | case GNUNET_DNSPARSER_TYPE_MX: | ||
842 | if (GNUNET_OK == | ||
843 | GNUNET_DNSPARSER_builder_add_mx(dst, dst_len, &off, rec->data.mx)) | ||
844 | { | ||
845 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
846 | "Converting MX (`%s') record for `%s'\n", | ||
847 | rec->data.mx->mxhost, | ||
848 | rec->name); | ||
849 | add_record(req, rec->type, expiration_time, dst, off); | ||
850 | } | ||
851 | break; | ||
852 | |||
853 | case GNUNET_DNSPARSER_TYPE_SOA: | ||
854 | if (GNUNET_OK == | ||
855 | GNUNET_DNSPARSER_builder_add_soa(dst, dst_len, &off, rec->data.soa)) | ||
856 | { | ||
857 | /* NOTE: GNS does not really use SOAs */ | ||
858 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
859 | "Converting SOA record for `%s'\n", | ||
860 | rec->name); | ||
861 | add_record(req, rec->type, expiration_time, dst, off); | ||
862 | } | ||
863 | break; | ||
864 | |||
865 | case GNUNET_DNSPARSER_TYPE_SRV: | ||
866 | if (GNUNET_OK == | ||
867 | GNUNET_DNSPARSER_builder_add_srv(dst, dst_len, &off, rec->data.srv)) | ||
868 | { | ||
869 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
870 | "Converting SRV record for `%s'\n", | ||
871 | rec->name); | ||
872 | add_record(req, rec->type, expiration_time, dst, off); | ||
873 | } | ||
874 | break; | ||
875 | |||
876 | case GNUNET_DNSPARSER_TYPE_PTR: | ||
877 | if (GNUNET_OK == GNUNET_DNSPARSER_builder_add_name(dst, | ||
797 | dst_len, | 878 | dst_len, |
798 | &off, | 879 | &off, |
799 | rec->data.hostname))) | 880 | rec->data.hostname)) |
800 | { | 881 | { |
801 | /* FIXME: actually check if this is out-of-bailiwick, | 882 | /* !?: what does a PTR record do in a regular TLD??? */ |
802 | and if not request explicit resolution... */ | 883 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
803 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 884 | "Converting PTR record for `%s' (weird)\n", |
804 | "Converted OOB (`%s') NS record for `%s'\n", | 885 | rec->name); |
805 | rec->data.hostname, | 886 | add_record(req, rec->type, expiration_time, dst, off); |
806 | rec->name); | 887 | } |
807 | add_record (req, | 888 | break; |
808 | GNUNET_GNSRECORD_TYPE_GNS2DNS, | 889 | |
809 | expiration_time, | 890 | case GNUNET_DNSPARSER_TYPE_CERT: |
810 | dst, | 891 | if (GNUNET_OK == |
811 | off); | 892 | GNUNET_DNSPARSER_builder_add_cert(dst, dst_len, &off, rec->data.cert)) |
812 | } | 893 | { |
813 | else | 894 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
814 | { | 895 | "Converting CERT record for `%s'\n", |
815 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 896 | rec->name); |
816 | "Converted NS record for `%s' using glue\n", | 897 | add_record(req, rec->type, expiration_time, dst, off); |
817 | rec->name); | 898 | } |
818 | } | 899 | break; |
819 | break; | 900 | |
820 | } | ||
821 | case GNUNET_DNSPARSER_TYPE_CNAME: | ||
822 | if (GNUNET_OK == GNUNET_DNSPARSER_builder_add_name (dst, | ||
823 | dst_len, | ||
824 | &off, | ||
825 | rec->data.hostname)) | ||
826 | { | ||
827 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
828 | "Converting CNAME (`%s') record for `%s'\n", | ||
829 | rec->data.hostname, | ||
830 | rec->name); | ||
831 | add_record (req, rec->type, expiration_time, dst, off); | ||
832 | } | ||
833 | break; | ||
834 | case GNUNET_DNSPARSER_TYPE_DNAME: | ||
835 | /* No support for DNAME in GNS yet! FIXME: support later! */ | ||
836 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
837 | "FIXME: not supported: %s DNAME %s\n", | ||
838 | rec->name, | ||
839 | rec->data.hostname); | ||
840 | break; | ||
841 | case GNUNET_DNSPARSER_TYPE_MX: | ||
842 | if (GNUNET_OK == | ||
843 | GNUNET_DNSPARSER_builder_add_mx (dst, dst_len, &off, rec->data.mx)) | ||
844 | { | ||
845 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
846 | "Converting MX (`%s') record for `%s'\n", | ||
847 | rec->data.mx->mxhost, | ||
848 | rec->name); | ||
849 | add_record (req, rec->type, expiration_time, dst, off); | ||
850 | } | ||
851 | break; | ||
852 | case GNUNET_DNSPARSER_TYPE_SOA: | ||
853 | if (GNUNET_OK == | ||
854 | GNUNET_DNSPARSER_builder_add_soa (dst, dst_len, &off, rec->data.soa)) | ||
855 | { | ||
856 | /* NOTE: GNS does not really use SOAs */ | ||
857 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
858 | "Converting SOA record for `%s'\n", | ||
859 | rec->name); | ||
860 | add_record (req, rec->type, expiration_time, dst, off); | ||
861 | } | ||
862 | break; | ||
863 | case GNUNET_DNSPARSER_TYPE_SRV: | ||
864 | if (GNUNET_OK == | ||
865 | GNUNET_DNSPARSER_builder_add_srv (dst, dst_len, &off, rec->data.srv)) | ||
866 | { | ||
867 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
868 | "Converting SRV record for `%s'\n", | ||
869 | rec->name); | ||
870 | add_record (req, rec->type, expiration_time, dst, off); | ||
871 | } | ||
872 | break; | ||
873 | case GNUNET_DNSPARSER_TYPE_PTR: | ||
874 | if (GNUNET_OK == GNUNET_DNSPARSER_builder_add_name (dst, | ||
875 | dst_len, | ||
876 | &off, | ||
877 | rec->data.hostname)) | ||
878 | { | ||
879 | /* !?: what does a PTR record do in a regular TLD??? */ | ||
880 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
881 | "Converting PTR record for `%s' (weird)\n", | ||
882 | rec->name); | ||
883 | add_record (req, rec->type, expiration_time, dst, off); | ||
884 | } | ||
885 | break; | ||
886 | case GNUNET_DNSPARSER_TYPE_CERT: | ||
887 | if (GNUNET_OK == | ||
888 | GNUNET_DNSPARSER_builder_add_cert (dst, dst_len, &off, rec->data.cert)) | ||
889 | { | ||
890 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
891 | "Converting CERT record for `%s'\n", | ||
892 | rec->name); | ||
893 | add_record (req, rec->type, expiration_time, dst, off); | ||
894 | } | ||
895 | break; | ||
896 | /* Rest is 'raw' encoded and just needs to be copied IF | 901 | /* Rest is 'raw' encoded and just needs to be copied IF |
897 | the hostname matches the requested name; otherwise we | 902 | the hostname matches the requested name; otherwise we |
898 | simply cannot use it. */ | 903 | simply cannot use it. */ |
899 | case GNUNET_DNSPARSER_TYPE_A: | 904 | case GNUNET_DNSPARSER_TYPE_A: |
900 | case GNUNET_DNSPARSER_TYPE_AAAA: | 905 | case GNUNET_DNSPARSER_TYPE_AAAA: |
901 | case GNUNET_DNSPARSER_TYPE_TXT: | 906 | case GNUNET_DNSPARSER_TYPE_TXT: |
902 | default: | 907 | default: |
903 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 908 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
904 | "Converting record of type %u for `%s'\n", | 909 | "Converting record of type %u for `%s'\n", |
905 | (unsigned int) rec->type, | 910 | (unsigned int)rec->type, |
906 | rec->name); | 911 | rec->name); |
907 | add_record (req, | 912 | add_record(req, |
908 | rec->type, | 913 | rec->type, |
909 | expiration_time, | 914 | expiration_time, |
910 | rec->data.raw.data, | 915 | rec->data.raw.data, |
911 | rec->data.raw.data_len); | 916 | rec->data.raw.data_len); |
912 | break; | 917 | break; |
913 | } | 918 | } |
914 | } | 919 | } |
915 | 920 | ||
916 | 921 | ||
@@ -925,89 +930,89 @@ process_record (void *cls, const struct GNUNET_DNSPARSER_Record *rec) | |||
925 | * @param emsg NULL on success, otherwise an error message | 930 | * @param emsg NULL on success, otherwise an error message |
926 | */ | 931 | */ |
927 | static void | 932 | static void |
928 | store_completed_cb (void *cls, int32_t success, const char *emsg) | 933 | store_completed_cb(void *cls, int32_t success, const char *emsg) |
929 | { | 934 | { |
930 | static struct GNUNET_TIME_Absolute last; | 935 | static struct GNUNET_TIME_Absolute last; |
931 | struct Request *req = cls; | 936 | struct Request *req = cls; |
932 | 937 | ||
933 | req->qe = NULL; | 938 | req->qe = NULL; |
934 | if (GNUNET_SYSERR == success) | 939 | if (GNUNET_SYSERR == success) |
935 | { | 940 | { |
936 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 941 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
937 | "Failed to store zone data for `%s': %s\n", | 942 | "Failed to store zone data for `%s': %s\n", |
938 | req->hostname, | 943 | req->hostname, |
939 | emsg); | 944 | emsg); |
940 | } | 945 | } |
941 | else | 946 | else |
942 | { | 947 | { |
943 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 948 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
944 | "Stored records under `%s' (%d)\n", | 949 | "Stored records under `%s' (%d)\n", |
945 | req->hostname, | 950 | req->hostname, |
946 | success); | 951 | success); |
947 | } | 952 | } |
948 | total_reg_proc_dns_ns++; /* finished regular processing */ | 953 | total_reg_proc_dns_ns++; /* finished regular processing */ |
949 | pending_rs--; | 954 | pending_rs--; |
950 | free_records (req); | 955 | free_records(req); |
951 | /* compute NAMESTORE statistics */ | 956 | /* compute NAMESTORE statistics */ |
952 | { | 957 | { |
953 | static uint64_t total_ns_latency_cnt; | 958 | static uint64_t total_ns_latency_cnt; |
954 | static struct GNUNET_TIME_Relative total_ns_latency; | 959 | static struct GNUNET_TIME_Relative total_ns_latency; |
955 | struct GNUNET_TIME_Relative ns_latency; | 960 | struct GNUNET_TIME_Relative ns_latency; |
956 | 961 | ||
957 | ns_latency = GNUNET_TIME_absolute_get_duration (req->op_start_time); | 962 | ns_latency = GNUNET_TIME_absolute_get_duration(req->op_start_time); |
958 | total_ns_latency = GNUNET_TIME_relative_add (total_ns_latency, ns_latency); | 963 | total_ns_latency = GNUNET_TIME_relative_add(total_ns_latency, ns_latency); |
959 | if (0 == total_ns_latency_cnt) | 964 | if (0 == total_ns_latency_cnt) |
960 | last = GNUNET_TIME_absolute_get (); | 965 | last = GNUNET_TIME_absolute_get(); |
961 | total_ns_latency_cnt++; | 966 | total_ns_latency_cnt++; |
962 | if (0 == (total_ns_latency_cnt % 1000)) | 967 | if (0 == (total_ns_latency_cnt % 1000)) |
963 | { | 968 | { |
964 | struct GNUNET_TIME_Relative delta; | 969 | struct GNUNET_TIME_Relative delta; |
965 | 970 | ||
966 | delta = GNUNET_TIME_absolute_get_duration (last); | 971 | delta = GNUNET_TIME_absolute_get_duration(last); |
967 | last = GNUNET_TIME_absolute_get (); | 972 | last = GNUNET_TIME_absolute_get(); |
968 | fprintf (stderr, | 973 | fprintf(stderr, |
969 | "Processed 1000 records in %s\n", | 974 | "Processed 1000 records in %s\n", |
970 | GNUNET_STRINGS_relative_time_to_string (delta, GNUNET_YES)); | 975 | GNUNET_STRINGS_relative_time_to_string(delta, GNUNET_YES)); |
971 | GNUNET_STATISTICS_set (stats, | 976 | GNUNET_STATISTICS_set(stats, |
972 | "# average NAMESTORE PUT latency (μs)", | 977 | "# average NAMESTORE PUT latency (μs)", |
973 | total_ns_latency.rel_value_us / | 978 | total_ns_latency.rel_value_us / |
974 | total_ns_latency_cnt, | 979 | total_ns_latency_cnt, |
975 | GNUNET_NO); | 980 | GNUNET_NO); |
976 | } | 981 | } |
977 | } | 982 | } |
978 | /* compute and publish overall velocity */ | 983 | /* compute and publish overall velocity */ |
979 | if (0 == (total_reg_proc_dns_ns % 100)) | 984 | if (0 == (total_reg_proc_dns_ns % 100)) |
980 | { | 985 | { |
981 | struct GNUNET_TIME_Relative runtime; | 986 | struct GNUNET_TIME_Relative runtime; |
982 | 987 | ||
983 | runtime = GNUNET_TIME_absolute_get_duration (start_time_reg_proc); | 988 | runtime = GNUNET_TIME_absolute_get_duration(start_time_reg_proc); |
984 | runtime = GNUNET_TIME_relative_subtract (runtime, idle_time); | 989 | runtime = GNUNET_TIME_relative_subtract(runtime, idle_time); |
985 | runtime = | 990 | runtime = |
986 | GNUNET_TIME_relative_divide (runtime, | 991 | GNUNET_TIME_relative_divide(runtime, |
987 | total_reg_proc_dns + total_reg_proc_dns_ns); | 992 | total_reg_proc_dns + total_reg_proc_dns_ns); |
988 | GNUNET_STATISTICS_set (stats, | 993 | GNUNET_STATISTICS_set(stats, |
989 | "# Regular processing completed without NAMESTORE", | 994 | "# Regular processing completed without NAMESTORE", |
990 | total_reg_proc_dns, | 995 | total_reg_proc_dns, |
991 | GNUNET_NO); | 996 | GNUNET_NO); |
992 | GNUNET_STATISTICS_set (stats, | 997 | GNUNET_STATISTICS_set(stats, |
993 | "# Regular processing completed with NAMESTORE PUT", | 998 | "# Regular processing completed with NAMESTORE PUT", |
994 | total_reg_proc_dns_ns, | 999 | total_reg_proc_dns_ns, |
995 | GNUNET_NO); | 1000 | GNUNET_NO); |
996 | GNUNET_STATISTICS_set (stats, | 1001 | GNUNET_STATISTICS_set(stats, |
997 | "# average request processing latency (μs)", | 1002 | "# average request processing latency (μs)", |
998 | runtime.rel_value_us, | 1003 | runtime.rel_value_us, |
999 | GNUNET_NO); | 1004 | GNUNET_NO); |
1000 | GNUNET_STATISTICS_set (stats, | 1005 | GNUNET_STATISTICS_set(stats, |
1001 | "# total time spent idle (μs)", | 1006 | "# total time spent idle (μs)", |
1002 | idle_time.rel_value_us, | 1007 | idle_time.rel_value_us, |
1003 | GNUNET_NO); | 1008 | GNUNET_NO); |
1004 | } | 1009 | } |
1005 | 1010 | ||
1006 | if (NULL == t) | 1011 | if (NULL == t) |
1007 | { | 1012 | { |
1008 | sleep_time_reg_proc = GNUNET_TIME_absolute_get (); | 1013 | sleep_time_reg_proc = GNUNET_TIME_absolute_get(); |
1009 | t = GNUNET_SCHEDULER_add_now (&process_queue, NULL); | 1014 | t = GNUNET_SCHEDULER_add_now(&process_queue, NULL); |
1010 | } | 1015 | } |
1011 | } | 1016 | } |
1012 | 1017 | ||
1013 | 1018 | ||
@@ -1019,148 +1024,148 @@ store_completed_cb (void *cls, int32_t success, const char *emsg) | |||
1019 | * @param dns_len number of bytes in @a dns | 1024 | * @param dns_len number of bytes in @a dns |
1020 | */ | 1025 | */ |
1021 | static void | 1026 | static void |
1022 | process_result (void *cls, | 1027 | process_result(void *cls, |
1023 | const struct GNUNET_TUN_DnsHeader *dns, | 1028 | const struct GNUNET_TUN_DnsHeader *dns, |
1024 | size_t dns_len) | 1029 | size_t dns_len) |
1025 | { | 1030 | { |
1026 | struct Request *req = cls; | 1031 | struct Request *req = cls; |
1027 | struct Record *rec; | 1032 | struct Record *rec; |
1028 | struct GNUNET_DNSPARSER_Packet *p; | 1033 | struct GNUNET_DNSPARSER_Packet *p; |
1029 | unsigned int rd_count; | 1034 | unsigned int rd_count; |
1030 | 1035 | ||
1031 | GNUNET_assert (NULL == req->hn); | 1036 | GNUNET_assert(NULL == req->hn); |
1032 | if (NULL == dns) | 1037 | if (NULL == dns) |
1033 | { | ||
1034 | /* stub gave up */ | ||
1035 | GNUNET_CONTAINER_DLL_remove (req_head, req_tail, req); | ||
1036 | pending--; | ||
1037 | if (NULL == t) | ||
1038 | { | 1038 | { |
1039 | sleep_time_reg_proc = GNUNET_TIME_absolute_get (); | 1039 | /* stub gave up */ |
1040 | t = GNUNET_SCHEDULER_add_now (&process_queue, NULL); | 1040 | GNUNET_CONTAINER_DLL_remove(req_head, req_tail, req); |
1041 | pending--; | ||
1042 | if (NULL == t) | ||
1043 | { | ||
1044 | sleep_time_reg_proc = GNUNET_TIME_absolute_get(); | ||
1045 | t = GNUNET_SCHEDULER_add_now(&process_queue, NULL); | ||
1046 | } | ||
1047 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
1048 | "Stub gave up on DNS reply for `%s'\n", | ||
1049 | req->hostname); | ||
1050 | GNUNET_STATISTICS_update(stats, "# DNS lookups timed out", 1, GNUNET_NO); | ||
1051 | if (req->issue_num > MAX_RETRIES) | ||
1052 | { | ||
1053 | failures++; | ||
1054 | free_request(req); | ||
1055 | GNUNET_STATISTICS_update(stats, "# requests given up on", 1, GNUNET_NO); | ||
1056 | return; | ||
1057 | } | ||
1058 | total_reg_proc_dns++; | ||
1059 | req->rs = NULL; | ||
1060 | insert_sorted(req); | ||
1061 | return; | ||
1041 | } | 1062 | } |
1042 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1063 | if (req->id != dns->id) |
1043 | "Stub gave up on DNS reply for `%s'\n", | ||
1044 | req->hostname); | ||
1045 | GNUNET_STATISTICS_update (stats, "# DNS lookups timed out", 1, GNUNET_NO); | ||
1046 | if (req->issue_num > MAX_RETRIES) | ||
1047 | { | 1064 | { |
1048 | failures++; | 1065 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1049 | free_request (req); | 1066 | "DNS ID did not match request, ignoring reply\n"); |
1050 | GNUNET_STATISTICS_update (stats, "# requests given up on", 1, GNUNET_NO); | 1067 | GNUNET_STATISTICS_update(stats, "# DNS ID mismatches", 1, GNUNET_NO); |
1051 | return; | 1068 | return; |
1052 | } | 1069 | } |
1053 | total_reg_proc_dns++; | 1070 | GNUNET_CONTAINER_DLL_remove(req_head, req_tail, req); |
1054 | req->rs = NULL; | 1071 | GNUNET_DNSSTUB_resolve_cancel(req->rs); |
1055 | insert_sorted (req); | ||
1056 | return; | ||
1057 | } | ||
1058 | if (req->id != dns->id) | ||
1059 | { | ||
1060 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1061 | "DNS ID did not match request, ignoring reply\n"); | ||
1062 | GNUNET_STATISTICS_update (stats, "# DNS ID mismatches", 1, GNUNET_NO); | ||
1063 | return; | ||
1064 | } | ||
1065 | GNUNET_CONTAINER_DLL_remove (req_head, req_tail, req); | ||
1066 | GNUNET_DNSSTUB_resolve_cancel (req->rs); | ||
1067 | req->rs = NULL; | 1072 | req->rs = NULL; |
1068 | pending--; | 1073 | pending--; |
1069 | p = GNUNET_DNSPARSER_parse ((const char *) dns, dns_len); | 1074 | p = GNUNET_DNSPARSER_parse((const char *)dns, dns_len); |
1070 | if (NULL == p) | 1075 | if (NULL == p) |
1071 | { | ||
1072 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1073 | "Failed to parse DNS reply for `%s'\n", | ||
1074 | req->hostname); | ||
1075 | GNUNET_STATISTICS_update (stats, "# DNS parser errors", 1, GNUNET_NO); | ||
1076 | if (NULL == t) | ||
1077 | { | ||
1078 | sleep_time_reg_proc = GNUNET_TIME_absolute_get (); | ||
1079 | t = GNUNET_SCHEDULER_add_now (&process_queue, NULL); | ||
1080 | } | ||
1081 | if (req->issue_num > MAX_RETRIES) | ||
1082 | { | 1076 | { |
1083 | failures++; | 1077 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
1084 | free_request (req); | 1078 | "Failed to parse DNS reply for `%s'\n", |
1085 | GNUNET_STATISTICS_update (stats, "# requests given up on", 1, GNUNET_NO); | 1079 | req->hostname); |
1080 | GNUNET_STATISTICS_update(stats, "# DNS parser errors", 1, GNUNET_NO); | ||
1081 | if (NULL == t) | ||
1082 | { | ||
1083 | sleep_time_reg_proc = GNUNET_TIME_absolute_get(); | ||
1084 | t = GNUNET_SCHEDULER_add_now(&process_queue, NULL); | ||
1085 | } | ||
1086 | if (req->issue_num > MAX_RETRIES) | ||
1087 | { | ||
1088 | failures++; | ||
1089 | free_request(req); | ||
1090 | GNUNET_STATISTICS_update(stats, "# requests given up on", 1, GNUNET_NO); | ||
1091 | return; | ||
1092 | } | ||
1093 | insert_sorted(req); | ||
1086 | return; | 1094 | return; |
1087 | } | 1095 | } |
1088 | insert_sorted (req); | ||
1089 | return; | ||
1090 | } | ||
1091 | /* import new records */ | 1096 | /* import new records */ |
1092 | req->issue_num = 0; /* success, reset counter! */ | 1097 | req->issue_num = 0; /* success, reset counter! */ |
1093 | { | 1098 | { |
1094 | struct ProcessRecordContext prc = {.req = req, .p = p}; | 1099 | struct ProcessRecordContext prc = { .req = req, .p = p }; |
1095 | 1100 | ||
1096 | for_all_records (p, &process_record, &prc); | 1101 | for_all_records(p, &process_record, &prc); |
1097 | } | 1102 | } |
1098 | GNUNET_DNSPARSER_free_packet (p); | 1103 | GNUNET_DNSPARSER_free_packet(p); |
1099 | /* count records found, determine minimum expiration time */ | 1104 | /* count records found, determine minimum expiration time */ |
1100 | req->expires = GNUNET_TIME_UNIT_FOREVER_ABS; | 1105 | req->expires = GNUNET_TIME_UNIT_FOREVER_ABS; |
1101 | { | 1106 | { |
1102 | struct GNUNET_TIME_Relative dns_latency; | 1107 | struct GNUNET_TIME_Relative dns_latency; |
1103 | 1108 | ||
1104 | dns_latency = GNUNET_TIME_absolute_get_duration (req->op_start_time); | 1109 | dns_latency = GNUNET_TIME_absolute_get_duration(req->op_start_time); |
1105 | total_dns_latency = | 1110 | total_dns_latency = |
1106 | GNUNET_TIME_relative_add (total_dns_latency, dns_latency); | 1111 | GNUNET_TIME_relative_add(total_dns_latency, dns_latency); |
1107 | total_dns_latency_cnt++; | 1112 | total_dns_latency_cnt++; |
1108 | if (0 == (total_dns_latency_cnt % 1000)) | 1113 | if (0 == (total_dns_latency_cnt % 1000)) |
1109 | { | 1114 | { |
1110 | GNUNET_STATISTICS_set (stats, | 1115 | GNUNET_STATISTICS_set(stats, |
1111 | "# average DNS lookup latency (μs)", | 1116 | "# average DNS lookup latency (μs)", |
1112 | total_dns_latency.rel_value_us / | 1117 | total_dns_latency.rel_value_us / |
1113 | total_dns_latency_cnt, | 1118 | total_dns_latency_cnt, |
1114 | GNUNET_NO); | 1119 | GNUNET_NO); |
1115 | } | 1120 | } |
1116 | } | 1121 | } |
1117 | rd_count = 0; | 1122 | rd_count = 0; |
1118 | for (rec = req->rec_head; NULL != rec; rec = rec->next) | 1123 | for (rec = req->rec_head; NULL != rec; rec = rec->next) |
1119 | { | 1124 | { |
1120 | struct GNUNET_TIME_Absolute at; | 1125 | struct GNUNET_TIME_Absolute at; |
1121 | 1126 | ||
1122 | at.abs_value_us = rec->grd.expiration_time; | 1127 | at.abs_value_us = rec->grd.expiration_time; |
1123 | req->expires = GNUNET_TIME_absolute_min (req->expires, at); | 1128 | req->expires = GNUNET_TIME_absolute_min(req->expires, at); |
1124 | rd_count++; | 1129 | rd_count++; |
1125 | } | 1130 | } |
1126 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1131 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
1127 | "Obtained %u records for `%s'\n", | 1132 | "Obtained %u records for `%s'\n", |
1128 | rd_count, | 1133 | rd_count, |
1129 | req->hostname); | 1134 | req->hostname); |
1130 | /* Instead of going for SOA, simplified for now to look each | 1135 | /* Instead of going for SOA, simplified for now to look each |
1131 | day in case we got an empty response */ | 1136 | day in case we got an empty response */ |
1132 | if (0 == rd_count) | 1137 | if (0 == rd_count) |
1133 | { | 1138 | { |
1134 | req->expires = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_DAYS); | 1139 | req->expires = GNUNET_TIME_relative_to_absolute(GNUNET_TIME_UNIT_DAYS); |
1135 | GNUNET_STATISTICS_update (stats, | 1140 | GNUNET_STATISTICS_update(stats, |
1136 | "# empty DNS replies (usually NXDOMAIN)", | 1141 | "# empty DNS replies (usually NXDOMAIN)", |
1137 | 1, | 1142 | 1, |
1138 | GNUNET_NO); | 1143 | GNUNET_NO); |
1139 | } | 1144 | } |
1140 | else | 1145 | else |
1141 | { | 1146 | { |
1142 | record_sets++; | 1147 | record_sets++; |
1143 | } | 1148 | } |
1144 | /* convert records to namestore import format */ | 1149 | /* convert records to namestore import format */ |
1145 | { | 1150 | { |
1146 | struct GNUNET_GNSRECORD_Data rd[GNUNET_NZL (rd_count)]; | 1151 | struct GNUNET_GNSRECORD_Data rd[GNUNET_NZL(rd_count)]; |
1147 | unsigned int off = 0; | 1152 | unsigned int off = 0; |
1148 | 1153 | ||
1149 | /* convert linked list into array */ | 1154 | /* convert linked list into array */ |
1150 | for (rec = req->rec_head; NULL != rec; rec = rec->next) | 1155 | for (rec = req->rec_head; NULL != rec; rec = rec->next) |
1151 | rd[off++] = rec->grd; | 1156 | rd[off++] = rec->grd; |
1152 | pending_rs++; | 1157 | pending_rs++; |
1153 | req->op_start_time = GNUNET_TIME_absolute_get (); | 1158 | req->op_start_time = GNUNET_TIME_absolute_get(); |
1154 | req->qe = GNUNET_NAMESTORE_records_store (ns, | 1159 | req->qe = GNUNET_NAMESTORE_records_store(ns, |
1155 | &req->zone->key, | 1160 | &req->zone->key, |
1156 | get_label (req), | 1161 | get_label(req), |
1157 | rd_count, | 1162 | rd_count, |
1158 | rd, | 1163 | rd, |
1159 | &store_completed_cb, | 1164 | &store_completed_cb, |
1160 | req); | 1165 | req); |
1161 | GNUNET_assert (NULL != req->qe); | 1166 | GNUNET_assert(NULL != req->qe); |
1162 | } | 1167 | } |
1163 | insert_sorted (req); | 1168 | insert_sorted(req); |
1164 | } | 1169 | } |
1165 | 1170 | ||
1166 | 1171 | ||
@@ -1170,7 +1175,7 @@ process_result (void *cls, | |||
1170 | * @param cls NULL | 1175 | * @param cls NULL |
1171 | */ | 1176 | */ |
1172 | static void | 1177 | static void |
1173 | process_queue (void *cls) | 1178 | process_queue(void *cls) |
1174 | { | 1179 | { |
1175 | struct Request *req; | 1180 | struct Request *req; |
1176 | unsigned int series; | 1181 | unsigned int series; |
@@ -1178,82 +1183,82 @@ process_queue (void *cls) | |||
1178 | size_t raw_size; | 1183 | size_t raw_size; |
1179 | struct GNUNET_TIME_Relative delay; | 1184 | struct GNUNET_TIME_Relative delay; |
1180 | 1185 | ||
1181 | (void) cls; | 1186 | (void)cls; |
1182 | delay = GNUNET_TIME_absolute_get_duration (sleep_time_reg_proc); | 1187 | delay = GNUNET_TIME_absolute_get_duration(sleep_time_reg_proc); |
1183 | idle_time = GNUNET_TIME_relative_add (idle_time, delay); | 1188 | idle_time = GNUNET_TIME_relative_add(idle_time, delay); |
1184 | series = 0; | 1189 | series = 0; |
1185 | t = NULL; | 1190 | t = NULL; |
1186 | while (pending + pending_rs < THRESH) | 1191 | while (pending + pending_rs < THRESH) |
1187 | { | ||
1188 | req = GNUNET_CONTAINER_heap_peek (req_heap); | ||
1189 | if (NULL == req) | ||
1190 | break; | ||
1191 | if (NULL != req->qe) | ||
1192 | return; /* namestore op still pending */ | ||
1193 | if (NULL != req->rs) | ||
1194 | { | 1192 | { |
1195 | GNUNET_break (0); | 1193 | req = GNUNET_CONTAINER_heap_peek(req_heap); |
1196 | return; /* already submitted */ | 1194 | if (NULL == req) |
1195 | break; | ||
1196 | if (NULL != req->qe) | ||
1197 | return; /* namestore op still pending */ | ||
1198 | if (NULL != req->rs) | ||
1199 | { | ||
1200 | GNUNET_break(0); | ||
1201 | return; /* already submitted */ | ||
1202 | } | ||
1203 | if (GNUNET_TIME_absolute_get_remaining(req->expires).rel_value_us > 0) | ||
1204 | break; | ||
1205 | GNUNET_assert(req == GNUNET_CONTAINER_heap_remove_root(req_heap)); | ||
1206 | req->hn = NULL; | ||
1207 | GNUNET_CONTAINER_DLL_insert(req_head, req_tail, req); | ||
1208 | GNUNET_assert(NULL == req->rs); | ||
1209 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | ||
1210 | "Requesting resolution for `%s'\n", | ||
1211 | req->hostname); | ||
1212 | raw = build_dns_query(req, &raw_size); | ||
1213 | if (NULL == raw) | ||
1214 | { | ||
1215 | GNUNET_break(0); | ||
1216 | free_request(req); | ||
1217 | continue; | ||
1218 | } | ||
1219 | req->op_start_time = GNUNET_TIME_absolute_get(); | ||
1220 | req->rs = GNUNET_DNSSTUB_resolve(ctx, raw, raw_size, &process_result, req); | ||
1221 | GNUNET_assert(NULL != req->rs); | ||
1222 | req->issue_num++; | ||
1223 | lookups++; | ||
1224 | pending++; | ||
1225 | series++; | ||
1226 | if (series > MAX_SERIES) | ||
1227 | break; | ||
1197 | } | 1228 | } |
1198 | if (GNUNET_TIME_absolute_get_remaining (req->expires).rel_value_us > 0) | 1229 | if (pending + pending_rs >= THRESH) |
1199 | break; | ||
1200 | GNUNET_assert (req == GNUNET_CONTAINER_heap_remove_root (req_heap)); | ||
1201 | req->hn = NULL; | ||
1202 | GNUNET_CONTAINER_DLL_insert (req_head, req_tail, req); | ||
1203 | GNUNET_assert (NULL == req->rs); | ||
1204 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
1205 | "Requesting resolution for `%s'\n", | ||
1206 | req->hostname); | ||
1207 | raw = build_dns_query (req, &raw_size); | ||
1208 | if (NULL == raw) | ||
1209 | { | 1230 | { |
1210 | GNUNET_break (0); | 1231 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1211 | free_request (req); | 1232 | "Stopped processing queue (%u+%u/%u)]\n", |
1212 | continue; | 1233 | pending, |
1234 | pending_rs, | ||
1235 | THRESH); | ||
1236 | return; /* wait for replies */ | ||
1213 | } | 1237 | } |
1214 | req->op_start_time = GNUNET_TIME_absolute_get (); | 1238 | req = GNUNET_CONTAINER_heap_peek(req_heap); |
1215 | req->rs = GNUNET_DNSSTUB_resolve (ctx, raw, raw_size, &process_result, req); | ||
1216 | GNUNET_assert (NULL != req->rs); | ||
1217 | req->issue_num++; | ||
1218 | lookups++; | ||
1219 | pending++; | ||
1220 | series++; | ||
1221 | if (series > MAX_SERIES) | ||
1222 | break; | ||
1223 | } | ||
1224 | if (pending + pending_rs >= THRESH) | ||
1225 | { | ||
1226 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1227 | "Stopped processing queue (%u+%u/%u)]\n", | ||
1228 | pending, | ||
1229 | pending_rs, | ||
1230 | THRESH); | ||
1231 | return; /* wait for replies */ | ||
1232 | } | ||
1233 | req = GNUNET_CONTAINER_heap_peek (req_heap); | ||
1234 | if (NULL == req) | 1239 | if (NULL == req) |
1235 | { | 1240 | { |
1236 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1241 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1237 | "Stopped processing queue: empty queue\n"); | 1242 | "Stopped processing queue: empty queue\n"); |
1238 | return; | 1243 | return; |
1239 | } | 1244 | } |
1240 | if (GNUNET_TIME_absolute_get_remaining (req->expires).rel_value_us > 0) | 1245 | if (GNUNET_TIME_absolute_get_remaining(req->expires).rel_value_us > 0) |
1241 | { | 1246 | { |
1242 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1247 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
1243 | "Waiting until %s for next record (`%s') to expire\n", | 1248 | "Waiting until %s for next record (`%s') to expire\n", |
1244 | GNUNET_STRINGS_absolute_time_to_string (req->expires), | 1249 | GNUNET_STRINGS_absolute_time_to_string(req->expires), |
1245 | req->hostname); | 1250 | req->hostname); |
1246 | if (NULL != t) | 1251 | if (NULL != t) |
1247 | GNUNET_SCHEDULER_cancel (t); | 1252 | GNUNET_SCHEDULER_cancel(t); |
1248 | sleep_time_reg_proc = GNUNET_TIME_absolute_get (); | 1253 | sleep_time_reg_proc = GNUNET_TIME_absolute_get(); |
1249 | t = GNUNET_SCHEDULER_add_at (req->expires, &process_queue, NULL); | 1254 | t = GNUNET_SCHEDULER_add_at(req->expires, &process_queue, NULL); |
1250 | return; | 1255 | return; |
1251 | } | 1256 | } |
1252 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Throttling\n"); | 1257 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Throttling\n"); |
1253 | if (NULL != t) | 1258 | if (NULL != t) |
1254 | GNUNET_SCHEDULER_cancel (t); | 1259 | GNUNET_SCHEDULER_cancel(t); |
1255 | sleep_time_reg_proc = GNUNET_TIME_absolute_get (); | 1260 | sleep_time_reg_proc = GNUNET_TIME_absolute_get(); |
1256 | t = GNUNET_SCHEDULER_add_delayed (SERIES_DELAY, &process_queue, NULL); | 1261 | t = GNUNET_SCHEDULER_add_delayed(SERIES_DELAY, &process_queue, NULL); |
1257 | } | 1262 | } |
1258 | 1263 | ||
1259 | 1264 | ||
@@ -1267,13 +1272,13 @@ process_queue (void *cls) | |||
1267 | * @return #GNUNET_OK | 1272 | * @return #GNUNET_OK |
1268 | */ | 1273 | */ |
1269 | static int | 1274 | static int |
1270 | free_request_it (void *cls, const struct GNUNET_HashCode *key, void *value) | 1275 | free_request_it(void *cls, const struct GNUNET_HashCode *key, void *value) |
1271 | { | 1276 | { |
1272 | struct Request *req = value; | 1277 | struct Request *req = value; |
1273 | 1278 | ||
1274 | (void) cls; | 1279 | (void)cls; |
1275 | (void) key; | 1280 | (void)key; |
1276 | free_request (req); | 1281 | free_request(req); |
1277 | return GNUNET_OK; | 1282 | return GNUNET_OK; |
1278 | } | 1283 | } |
1279 | 1284 | ||
@@ -1284,73 +1289,73 @@ free_request_it (void *cls, const struct GNUNET_HashCode *key, void *value) | |||
1284 | * @param cls NULL | 1289 | * @param cls NULL |
1285 | */ | 1290 | */ |
1286 | static void | 1291 | static void |
1287 | do_shutdown (void *cls) | 1292 | do_shutdown(void *cls) |
1288 | { | 1293 | { |
1289 | struct Request *req; | 1294 | struct Request *req; |
1290 | struct Zone *zone; | 1295 | struct Zone *zone; |
1291 | 1296 | ||
1292 | (void) cls; | 1297 | (void)cls; |
1293 | if (NULL != id) | 1298 | if (NULL != id) |
1294 | { | 1299 | { |
1295 | GNUNET_IDENTITY_disconnect (id); | 1300 | GNUNET_IDENTITY_disconnect(id); |
1296 | id = NULL; | 1301 | id = NULL; |
1297 | } | 1302 | } |
1298 | if (NULL != t) | 1303 | if (NULL != t) |
1299 | { | 1304 | { |
1300 | GNUNET_SCHEDULER_cancel (t); | 1305 | GNUNET_SCHEDULER_cancel(t); |
1301 | t = NULL; | 1306 | t = NULL; |
1302 | } | 1307 | } |
1303 | while (NULL != (req = req_head)) | 1308 | while (NULL != (req = req_head)) |
1304 | { | 1309 | { |
1305 | GNUNET_CONTAINER_DLL_remove (req_head, req_tail, req); | 1310 | GNUNET_CONTAINER_DLL_remove(req_head, req_tail, req); |
1306 | if (NULL != req->qe) | 1311 | if (NULL != req->qe) |
1307 | GNUNET_NAMESTORE_cancel (req->qe); | 1312 | GNUNET_NAMESTORE_cancel(req->qe); |
1308 | free_request (req); | 1313 | free_request(req); |
1309 | } | 1314 | } |
1310 | while (NULL != (req = GNUNET_CONTAINER_heap_remove_root (req_heap))) | 1315 | while (NULL != (req = GNUNET_CONTAINER_heap_remove_root(req_heap))) |
1311 | { | 1316 | { |
1312 | req->hn = NULL; | 1317 | req->hn = NULL; |
1313 | if (NULL != req->qe) | 1318 | if (NULL != req->qe) |
1314 | GNUNET_NAMESTORE_cancel (req->qe); | 1319 | GNUNET_NAMESTORE_cancel(req->qe); |
1315 | free_request (req); | 1320 | free_request(req); |
1316 | } | 1321 | } |
1317 | if (NULL != zone_it) | 1322 | if (NULL != zone_it) |
1318 | { | 1323 | { |
1319 | GNUNET_NAMESTORE_zone_iteration_stop (zone_it); | 1324 | GNUNET_NAMESTORE_zone_iteration_stop(zone_it); |
1320 | zone_it = NULL; | 1325 | zone_it = NULL; |
1321 | } | 1326 | } |
1322 | if (NULL != ns) | 1327 | if (NULL != ns) |
1323 | { | 1328 | { |
1324 | GNUNET_NAMESTORE_disconnect (ns); | 1329 | GNUNET_NAMESTORE_disconnect(ns); |
1325 | ns = NULL; | 1330 | ns = NULL; |
1326 | } | 1331 | } |
1327 | if (NULL != ctx) | 1332 | if (NULL != ctx) |
1328 | { | 1333 | { |
1329 | GNUNET_DNSSTUB_stop (ctx); | 1334 | GNUNET_DNSSTUB_stop(ctx); |
1330 | ctx = NULL; | 1335 | ctx = NULL; |
1331 | } | 1336 | } |
1332 | if (NULL != req_heap) | 1337 | if (NULL != req_heap) |
1333 | { | 1338 | { |
1334 | GNUNET_CONTAINER_heap_destroy (req_heap); | 1339 | GNUNET_CONTAINER_heap_destroy(req_heap); |
1335 | req_heap = NULL; | 1340 | req_heap = NULL; |
1336 | } | 1341 | } |
1337 | if (NULL != ns_pending) | 1342 | if (NULL != ns_pending) |
1338 | { | 1343 | { |
1339 | GNUNET_CONTAINER_multihashmap_iterate (ns_pending, &free_request_it, NULL); | 1344 | GNUNET_CONTAINER_multihashmap_iterate(ns_pending, &free_request_it, NULL); |
1340 | GNUNET_CONTAINER_multihashmap_destroy (ns_pending); | 1345 | GNUNET_CONTAINER_multihashmap_destroy(ns_pending); |
1341 | ns_pending = NULL; | 1346 | ns_pending = NULL; |
1342 | } | 1347 | } |
1343 | while (NULL != (zone = zone_head)) | 1348 | while (NULL != (zone = zone_head)) |
1344 | { | 1349 | { |
1345 | GNUNET_CONTAINER_DLL_remove (zone_head, zone_tail, zone); | 1350 | GNUNET_CONTAINER_DLL_remove(zone_head, zone_tail, zone); |
1346 | GNUNET_free (zone->domain); | 1351 | GNUNET_free(zone->domain); |
1347 | GNUNET_free (zone); | 1352 | GNUNET_free(zone); |
1348 | } | 1353 | } |
1349 | if (NULL != stats) | 1354 | if (NULL != stats) |
1350 | { | 1355 | { |
1351 | GNUNET_STATISTICS_destroy (stats, GNUNET_NO); | 1356 | GNUNET_STATISTICS_destroy(stats, GNUNET_NO); |
1352 | stats = NULL; | 1357 | stats = NULL; |
1353 | } | 1358 | } |
1354 | } | 1359 | } |
1355 | 1360 | ||
1356 | 1361 | ||
@@ -1361,7 +1366,7 @@ do_shutdown (void *cls) | |||
1361 | * @param cls NULL | 1366 | * @param cls NULL |
1362 | */ | 1367 | */ |
1363 | static void | 1368 | static void |
1364 | iterate_zones (void *cls); | 1369 | iterate_zones(void *cls); |
1365 | 1370 | ||
1366 | 1371 | ||
1367 | /** | 1372 | /** |
@@ -1371,16 +1376,16 @@ iterate_zones (void *cls); | |||
1371 | * @param cls a `struct Zone` | 1376 | * @param cls a `struct Zone` |
1372 | */ | 1377 | */ |
1373 | static void | 1378 | static void |
1374 | ns_lookup_error_cb (void *cls) | 1379 | ns_lookup_error_cb(void *cls) |
1375 | { | 1380 | { |
1376 | struct Zone *zone = cls; | 1381 | struct Zone *zone = cls; |
1377 | 1382 | ||
1378 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1383 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
1379 | "Failed to load data from namestore for zone `%s'\n", | 1384 | "Failed to load data from namestore for zone `%s'\n", |
1380 | zone->domain); | 1385 | zone->domain); |
1381 | zone_it = NULL; | 1386 | zone_it = NULL; |
1382 | ns_iterator_trigger_next = 0; | 1387 | ns_iterator_trigger_next = 0; |
1383 | iterate_zones (NULL); | 1388 | iterate_zones(NULL); |
1384 | } | 1389 | } |
1385 | 1390 | ||
1386 | 1391 | ||
@@ -1394,11 +1399,11 @@ ns_lookup_error_cb (void *cls) | |||
1394 | * @param rd array of records with data to store | 1399 | * @param rd array of records with data to store |
1395 | */ | 1400 | */ |
1396 | static void | 1401 | static void |
1397 | ns_lookup_result_cb (void *cls, | 1402 | ns_lookup_result_cb(void *cls, |
1398 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, | 1403 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, |
1399 | const char *label, | 1404 | const char *label, |
1400 | unsigned int rd_count, | 1405 | unsigned int rd_count, |
1401 | const struct GNUNET_GNSRECORD_Data *rd) | 1406 | const struct GNUNET_GNSRECORD_Data *rd) |
1402 | { | 1407 | { |
1403 | struct Zone *zone = cls; | 1408 | struct Zone *zone = cls; |
1404 | struct Request *req; | 1409 | struct Request *req; |
@@ -1406,85 +1411,85 @@ ns_lookup_result_cb (void *cls, | |||
1406 | char *fqdn; | 1411 | char *fqdn; |
1407 | 1412 | ||
1408 | ns_iterator_trigger_next--; | 1413 | ns_iterator_trigger_next--; |
1409 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1414 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1410 | "Obtained NAMESTORE reply, %llu left in round\n", | 1415 | "Obtained NAMESTORE reply, %llu left in round\n", |
1411 | (unsigned long long) ns_iterator_trigger_next); | 1416 | (unsigned long long)ns_iterator_trigger_next); |
1412 | if (0 == ns_iterator_trigger_next) | 1417 | if (0 == ns_iterator_trigger_next) |
1413 | { | 1418 | { |
1414 | ns_iterator_trigger_next = NS_BATCH_SIZE; | 1419 | ns_iterator_trigger_next = NS_BATCH_SIZE; |
1415 | GNUNET_STATISTICS_update (stats, | 1420 | GNUNET_STATISTICS_update(stats, |
1416 | "# NAMESTORE records requested from cache", | 1421 | "# NAMESTORE records requested from cache", |
1417 | ns_iterator_trigger_next, | 1422 | ns_iterator_trigger_next, |
1418 | GNUNET_NO); | 1423 | GNUNET_NO); |
1419 | GNUNET_NAMESTORE_zone_iterator_next (zone_it, ns_iterator_trigger_next); | 1424 | GNUNET_NAMESTORE_zone_iterator_next(zone_it, ns_iterator_trigger_next); |
1420 | } | 1425 | } |
1421 | GNUNET_asprintf (&fqdn, "%s.%s", label, zone->domain); | 1426 | GNUNET_asprintf(&fqdn, "%s.%s", label, zone->domain); |
1422 | GNUNET_CRYPTO_hash (fqdn, strlen (fqdn) + 1, &hc); | 1427 | GNUNET_CRYPTO_hash(fqdn, strlen(fqdn) + 1, &hc); |
1423 | GNUNET_free (fqdn); | 1428 | GNUNET_free(fqdn); |
1424 | req = GNUNET_CONTAINER_multihashmap_get (ns_pending, &hc); | 1429 | req = GNUNET_CONTAINER_multihashmap_get(ns_pending, &hc); |
1425 | if (NULL == req) | 1430 | if (NULL == req) |
1426 | { | 1431 | { |
1427 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1432 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
1428 | "Ignoring record `%s' in zone `%s': not on my list!\n", | 1433 | "Ignoring record `%s' in zone `%s': not on my list!\n", |
1429 | label, | 1434 | label, |
1430 | zone->domain); | 1435 | zone->domain); |
1431 | return; | 1436 | return; |
1432 | } | 1437 | } |
1433 | GNUNET_assert (GNUNET_OK == | 1438 | GNUNET_assert(GNUNET_OK == |
1434 | GNUNET_CONTAINER_multihashmap_remove (ns_pending, &hc, req)); | 1439 | GNUNET_CONTAINER_multihashmap_remove(ns_pending, &hc, req)); |
1435 | GNUNET_break (0 == GNUNET_memcmp (key, &req->zone->key)); | 1440 | GNUNET_break(0 == GNUNET_memcmp(key, &req->zone->key)); |
1436 | GNUNET_break (0 == strcasecmp (label, get_label (req))); | 1441 | GNUNET_break(0 == strcasecmp(label, get_label(req))); |
1437 | for (unsigned int i = 0; i < rd_count; i++) | 1442 | for (unsigned int i = 0; i < rd_count; i++) |
1438 | { | ||
1439 | struct GNUNET_TIME_Absolute at; | ||
1440 | |||
1441 | if (0 != (rd->flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION)) | ||
1442 | { | 1443 | { |
1443 | struct GNUNET_TIME_Relative rel; | 1444 | struct GNUNET_TIME_Absolute at; |
1444 | 1445 | ||
1445 | rel.rel_value_us = rd->expiration_time; | 1446 | if (0 != (rd->flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION)) |
1446 | at = GNUNET_TIME_relative_to_absolute (rel); | 1447 | { |
1448 | struct GNUNET_TIME_Relative rel; | ||
1449 | |||
1450 | rel.rel_value_us = rd->expiration_time; | ||
1451 | at = GNUNET_TIME_relative_to_absolute(rel); | ||
1452 | } | ||
1453 | else | ||
1454 | { | ||
1455 | at.abs_value_us = rd->expiration_time; | ||
1456 | } | ||
1457 | add_record(req, rd->record_type, at, rd->data, rd->data_size); | ||
1447 | } | 1458 | } |
1448 | else | 1459 | if (0 == rd_count) |
1449 | { | 1460 | { |
1450 | at.abs_value_us = rd->expiration_time; | 1461 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
1462 | "Empty record set in namestore for `%s'\n", | ||
1463 | req->hostname); | ||
1451 | } | 1464 | } |
1452 | add_record (req, rd->record_type, at, rd->data, rd->data_size); | ||
1453 | } | ||
1454 | if (0 == rd_count) | ||
1455 | { | ||
1456 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
1457 | "Empty record set in namestore for `%s'\n", | ||
1458 | req->hostname); | ||
1459 | } | ||
1460 | else | 1465 | else |
1461 | { | ||
1462 | unsigned int pos = 0; | ||
1463 | |||
1464 | cached++; | ||
1465 | req->expires = GNUNET_TIME_UNIT_FOREVER_ABS; | ||
1466 | for (struct Record *rec = req->rec_head; NULL != rec; rec = rec->next) | ||
1467 | { | 1466 | { |
1468 | struct GNUNET_TIME_Absolute at; | 1467 | unsigned int pos = 0; |
1469 | 1468 | ||
1470 | at.abs_value_us = rec->grd.expiration_time; | 1469 | cached++; |
1471 | req->expires = GNUNET_TIME_absolute_min (req->expires, at); | 1470 | req->expires = GNUNET_TIME_UNIT_FOREVER_ABS; |
1472 | pos++; | 1471 | for (struct Record *rec = req->rec_head; NULL != rec; rec = rec->next) |
1472 | { | ||
1473 | struct GNUNET_TIME_Absolute at; | ||
1474 | |||
1475 | at.abs_value_us = rec->grd.expiration_time; | ||
1476 | req->expires = GNUNET_TIME_absolute_min(req->expires, at); | ||
1477 | pos++; | ||
1478 | } | ||
1479 | if (0 == pos) | ||
1480 | req->expires = GNUNET_TIME_UNIT_ZERO_ABS; | ||
1481 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | ||
1482 | "Hot-start with %u existing records for `%s'\n", | ||
1483 | pos, | ||
1484 | req->hostname); | ||
1473 | } | 1485 | } |
1474 | if (0 == pos) | 1486 | free_records(req); |
1475 | req->expires = GNUNET_TIME_UNIT_ZERO_ABS; | ||
1476 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
1477 | "Hot-start with %u existing records for `%s'\n", | ||
1478 | pos, | ||
1479 | req->hostname); | ||
1480 | } | ||
1481 | free_records (req); | ||
1482 | 1487 | ||
1483 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1488 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1484 | "Adding `%s' to worklist to start at %s\n", | 1489 | "Adding `%s' to worklist to start at %s\n", |
1485 | req->hostname, | 1490 | req->hostname, |
1486 | GNUNET_STRINGS_absolute_time_to_string (req->expires)); | 1491 | GNUNET_STRINGS_absolute_time_to_string(req->expires)); |
1487 | insert_sorted (req); | 1492 | insert_sorted(req); |
1488 | } | 1493 | } |
1489 | 1494 | ||
1490 | 1495 | ||
@@ -1494,7 +1499,7 @@ ns_lookup_result_cb (void *cls, | |||
1494 | * @param hostname name to resolve | 1499 | * @param hostname name to resolve |
1495 | */ | 1500 | */ |
1496 | static void | 1501 | static void |
1497 | queue (const char *hostname) | 1502 | queue(const char *hostname) |
1498 | { | 1503 | { |
1499 | struct Request *req; | 1504 | struct Request *req; |
1500 | const char *dot; | 1505 | const char *dot; |
@@ -1502,55 +1507,55 @@ queue (const char *hostname) | |||
1502 | size_t hlen; | 1507 | size_t hlen; |
1503 | struct GNUNET_HashCode hc; | 1508 | struct GNUNET_HashCode hc; |
1504 | 1509 | ||
1505 | if (GNUNET_OK != GNUNET_DNSPARSER_check_name (hostname)) | 1510 | if (GNUNET_OK != GNUNET_DNSPARSER_check_name(hostname)) |
1506 | { | 1511 | { |
1507 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1512 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
1508 | "Refusing invalid hostname `%s'\n", | 1513 | "Refusing invalid hostname `%s'\n", |
1509 | hostname); | 1514 | hostname); |
1510 | rejects++; | 1515 | rejects++; |
1511 | return; | 1516 | return; |
1512 | } | 1517 | } |
1513 | dot = strchr (hostname, (unsigned char) '.'); | 1518 | dot = strchr(hostname, (unsigned char)'.'); |
1514 | if (NULL == dot) | 1519 | if (NULL == dot) |
1515 | { | 1520 | { |
1516 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1521 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
1517 | "Refusing invalid hostname `%s' (lacks '.')\n", | 1522 | "Refusing invalid hostname `%s' (lacks '.')\n", |
1518 | hostname); | 1523 | hostname); |
1519 | rejects++; | 1524 | rejects++; |
1520 | return; | 1525 | return; |
1521 | } | 1526 | } |
1522 | for (zone = zone_head; NULL != zone; zone = zone->next) | 1527 | for (zone = zone_head; NULL != zone; zone = zone->next) |
1523 | if (0 == strcmp (zone->domain, dot + 1)) | 1528 | if (0 == strcmp(zone->domain, dot + 1)) |
1524 | break; | 1529 | break; |
1525 | if (NULL == zone) | 1530 | if (NULL == zone) |
1526 | { | 1531 | { |
1527 | rejects++; | 1532 | rejects++; |
1528 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1533 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
1529 | "Domain name `%s' not in ego list!\n", | 1534 | "Domain name `%s' not in ego list!\n", |
1530 | dot + 1); | 1535 | dot + 1); |
1531 | return; | 1536 | return; |
1532 | } | 1537 | } |
1533 | 1538 | ||
1534 | hlen = strlen (hostname) + 1; | 1539 | hlen = strlen(hostname) + 1; |
1535 | req = GNUNET_malloc (sizeof (struct Request) + hlen); | 1540 | req = GNUNET_malloc(sizeof(struct Request) + hlen); |
1536 | req->zone = zone; | 1541 | req->zone = zone; |
1537 | req->hostname = (char *) &req[1]; | 1542 | req->hostname = (char *)&req[1]; |
1538 | GNUNET_memcpy (req->hostname, hostname, hlen); | 1543 | GNUNET_memcpy(req->hostname, hostname, hlen); |
1539 | req->id = (uint16_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, | 1544 | req->id = (uint16_t)GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_NONCE, |
1540 | UINT16_MAX); | 1545 | UINT16_MAX); |
1541 | GNUNET_CRYPTO_hash (req->hostname, hlen, &hc); | 1546 | GNUNET_CRYPTO_hash(req->hostname, hlen, &hc); |
1542 | if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put ( | 1547 | if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put( |
1543 | ns_pending, | 1548 | ns_pending, |
1544 | &hc, | 1549 | &hc, |
1545 | req, | 1550 | req, |
1546 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) | 1551 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) |
1547 | { | 1552 | { |
1548 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1553 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
1549 | "Duplicate hostname `%s' ignored\n", | 1554 | "Duplicate hostname `%s' ignored\n", |
1550 | hostname); | 1555 | hostname); |
1551 | GNUNET_free (req); | 1556 | GNUNET_free(req); |
1552 | return; | 1557 | return; |
1553 | } | 1558 | } |
1554 | } | 1559 | } |
1555 | 1560 | ||
1556 | 1561 | ||
@@ -1566,13 +1571,13 @@ queue (const char *hostname) | |||
1566 | * @return #GNUNET_OK (continue to iterate) | 1571 | * @return #GNUNET_OK (continue to iterate) |
1567 | */ | 1572 | */ |
1568 | static int | 1573 | static int |
1569 | move_to_queue (void *cls, const struct GNUNET_HashCode *key, void *value) | 1574 | move_to_queue(void *cls, const struct GNUNET_HashCode *key, void *value) |
1570 | { | 1575 | { |
1571 | struct Request *req = value; | 1576 | struct Request *req = value; |
1572 | 1577 | ||
1573 | (void) cls; | 1578 | (void)cls; |
1574 | (void) key; | 1579 | (void)key; |
1575 | insert_sorted (req); | 1580 | insert_sorted(req); |
1576 | return GNUNET_OK; | 1581 | return GNUNET_OK; |
1577 | } | 1582 | } |
1578 | 1583 | ||
@@ -1584,65 +1589,65 @@ move_to_queue (void *cls, const struct GNUNET_HashCode *key, void *value) | |||
1584 | * @param cls NULL | 1589 | * @param cls NULL |
1585 | */ | 1590 | */ |
1586 | static void | 1591 | static void |
1587 | iterate_zones (void *cls) | 1592 | iterate_zones(void *cls) |
1588 | { | 1593 | { |
1589 | static struct Zone *last; | 1594 | static struct Zone *last; |
1590 | 1595 | ||
1591 | (void) cls; | 1596 | (void)cls; |
1592 | if (NULL != zone_it) | 1597 | if (NULL != zone_it) |
1593 | { | 1598 | { |
1594 | zone_it = NULL; | 1599 | zone_it = NULL; |
1595 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1600 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1596 | "Finished iteration over zone `%s'!\n", | 1601 | "Finished iteration over zone `%s'!\n", |
1597 | last->domain); | 1602 | last->domain); |
1598 | /* subtract left-overs from previous iteration */ | 1603 | /* subtract left-overs from previous iteration */ |
1599 | GNUNET_STATISTICS_update (stats, | 1604 | GNUNET_STATISTICS_update(stats, |
1600 | "# NAMESTORE records requested from cache", | 1605 | "# NAMESTORE records requested from cache", |
1601 | (long long) (-ns_iterator_trigger_next), | 1606 | (long long)(-ns_iterator_trigger_next), |
1602 | GNUNET_NO); | 1607 | GNUNET_NO); |
1603 | ns_iterator_trigger_next = 0; | 1608 | ns_iterator_trigger_next = 0; |
1604 | } | 1609 | } |
1605 | GNUNET_assert (NULL != zone_tail); | 1610 | GNUNET_assert(NULL != zone_tail); |
1606 | if (zone_tail == last) | 1611 | if (zone_tail == last) |
1607 | { | 1612 | { |
1608 | /* Done iterating over relevant zones in NAMESTORE, move | 1613 | /* Done iterating over relevant zones in NAMESTORE, move |
1609 | rest of hash map to work queue as well. */ | 1614 | rest of hash map to work queue as well. */ |
1610 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1615 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1611 | "Finished all NAMESTORE iterations!\n"); | 1616 | "Finished all NAMESTORE iterations!\n"); |
1612 | GNUNET_STATISTICS_set (stats, | 1617 | GNUNET_STATISTICS_set(stats, |
1613 | "# Domain names without cached reply", | 1618 | "# Domain names without cached reply", |
1614 | GNUNET_CONTAINER_multihashmap_size (ns_pending), | 1619 | GNUNET_CONTAINER_multihashmap_size(ns_pending), |
1615 | GNUNET_NO); | 1620 | GNUNET_NO); |
1616 | GNUNET_CONTAINER_multihashmap_iterate (ns_pending, &move_to_queue, NULL); | 1621 | GNUNET_CONTAINER_multihashmap_iterate(ns_pending, &move_to_queue, NULL); |
1617 | GNUNET_CONTAINER_multihashmap_destroy (ns_pending); | 1622 | GNUNET_CONTAINER_multihashmap_destroy(ns_pending); |
1618 | ns_pending = NULL; | 1623 | ns_pending = NULL; |
1619 | start_time_reg_proc = GNUNET_TIME_absolute_get (); | 1624 | start_time_reg_proc = GNUNET_TIME_absolute_get(); |
1620 | total_reg_proc_dns = 0; | 1625 | total_reg_proc_dns = 0; |
1621 | total_reg_proc_dns_ns = 0; | 1626 | total_reg_proc_dns_ns = 0; |
1622 | return; | 1627 | return; |
1623 | } | 1628 | } |
1624 | if (NULL == last) | 1629 | if (NULL == last) |
1625 | last = zone_head; | 1630 | last = zone_head; |
1626 | else | 1631 | else |
1627 | last = last->next; | 1632 | last = last->next; |
1628 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1633 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1629 | "Starting iteration over zone `%s'!\n", | 1634 | "Starting iteration over zone `%s'!\n", |
1630 | last->domain); | 1635 | last->domain); |
1631 | /* subtract left-overs from previous iteration */ | 1636 | /* subtract left-overs from previous iteration */ |
1632 | GNUNET_STATISTICS_update (stats, | 1637 | GNUNET_STATISTICS_update(stats, |
1633 | "# NAMESTORE records requested from cache", | 1638 | "# NAMESTORE records requested from cache", |
1634 | 1, | 1639 | 1, |
1635 | GNUNET_NO); | 1640 | GNUNET_NO); |
1636 | ns_iterator_trigger_next = 1; | 1641 | ns_iterator_trigger_next = 1; |
1637 | GNUNET_STATISTICS_update (stats, "# zones iterated", 1, GNUNET_NO); | 1642 | GNUNET_STATISTICS_update(stats, "# zones iterated", 1, GNUNET_NO); |
1638 | zone_it = GNUNET_NAMESTORE_zone_iteration_start (ns, | 1643 | zone_it = GNUNET_NAMESTORE_zone_iteration_start(ns, |
1639 | &last->key, | 1644 | &last->key, |
1640 | &ns_lookup_error_cb, | 1645 | &ns_lookup_error_cb, |
1641 | NULL, | 1646 | NULL, |
1642 | &ns_lookup_result_cb, | 1647 | &ns_lookup_result_cb, |
1643 | last, | 1648 | last, |
1644 | &iterate_zones, | 1649 | &iterate_zones, |
1645 | NULL); | 1650 | NULL); |
1646 | } | 1651 | } |
1647 | 1652 | ||
1648 | 1653 | ||
@@ -1652,44 +1657,44 @@ iterate_zones (void *cls) | |||
1652 | * @param cls NULL | 1657 | * @param cls NULL |
1653 | */ | 1658 | */ |
1654 | static void | 1659 | static void |
1655 | process_stdin (void *cls) | 1660 | process_stdin(void *cls) |
1656 | { | 1661 | { |
1657 | static struct GNUNET_TIME_Absolute last; | 1662 | static struct GNUNET_TIME_Absolute last; |
1658 | static uint64_t idot; | 1663 | static uint64_t idot; |
1659 | char hn[256]; | 1664 | char hn[256]; |
1660 | 1665 | ||
1661 | (void) cls; | 1666 | (void)cls; |
1662 | t = NULL; | 1667 | t = NULL; |
1663 | if (NULL != id) | 1668 | if (NULL != id) |
1664 | { | ||
1665 | GNUNET_IDENTITY_disconnect (id); | ||
1666 | id = NULL; | ||
1667 | } | ||
1668 | while (NULL != fgets (hn, sizeof (hn), stdin)) | ||
1669 | { | ||
1670 | if (strlen (hn) > 0) | ||
1671 | hn[strlen (hn) - 1] = '\0'; /* eat newline */ | ||
1672 | if (0 == idot) | ||
1673 | last = GNUNET_TIME_absolute_get (); | ||
1674 | idot++; | ||
1675 | if (0 == idot % 100000) | ||
1676 | { | 1669 | { |
1677 | struct GNUNET_TIME_Relative delta; | 1670 | GNUNET_IDENTITY_disconnect(id); |
1678 | 1671 | id = NULL; | |
1679 | delta = GNUNET_TIME_absolute_get_duration (last); | ||
1680 | last = GNUNET_TIME_absolute_get (); | ||
1681 | fprintf (stderr, | ||
1682 | "Read 100000 domain names in %s\n", | ||
1683 | GNUNET_STRINGS_relative_time_to_string (delta, GNUNET_YES)); | ||
1684 | GNUNET_STATISTICS_set (stats, "# domain names provided", idot, GNUNET_NO); | ||
1685 | } | 1672 | } |
1686 | queue (hn); | 1673 | while (NULL != fgets(hn, sizeof(hn), stdin)) |
1687 | } | 1674 | { |
1688 | fprintf (stderr, | 1675 | if (strlen(hn) > 0) |
1689 | "Done reading %llu domain names\n", | 1676 | hn[strlen(hn) - 1] = '\0'; /* eat newline */ |
1690 | (unsigned long long) idot); | 1677 | if (0 == idot) |
1691 | GNUNET_STATISTICS_set (stats, "# domain names provided", idot, GNUNET_NO); | 1678 | last = GNUNET_TIME_absolute_get(); |
1692 | iterate_zones (NULL); | 1679 | idot++; |
1680 | if (0 == idot % 100000) | ||
1681 | { | ||
1682 | struct GNUNET_TIME_Relative delta; | ||
1683 | |||
1684 | delta = GNUNET_TIME_absolute_get_duration(last); | ||
1685 | last = GNUNET_TIME_absolute_get(); | ||
1686 | fprintf(stderr, | ||
1687 | "Read 100000 domain names in %s\n", | ||
1688 | GNUNET_STRINGS_relative_time_to_string(delta, GNUNET_YES)); | ||
1689 | GNUNET_STATISTICS_set(stats, "# domain names provided", idot, GNUNET_NO); | ||
1690 | } | ||
1691 | queue(hn); | ||
1692 | } | ||
1693 | fprintf(stderr, | ||
1694 | "Done reading %llu domain names\n", | ||
1695 | (unsigned long long)idot); | ||
1696 | GNUNET_STATISTICS_set(stats, "# domain names provided", idot, GNUNET_NO); | ||
1697 | iterate_zones(NULL); | ||
1693 | } | 1698 | } |
1694 | 1699 | ||
1695 | 1700 | ||
@@ -1728,36 +1733,36 @@ process_stdin (void *cls) | |||
1728 | * must thus no longer be used | 1733 | * must thus no longer be used |
1729 | */ | 1734 | */ |
1730 | static void | 1735 | static void |
1731 | identity_cb (void *cls, | 1736 | identity_cb(void *cls, |
1732 | struct GNUNET_IDENTITY_Ego *ego, | 1737 | struct GNUNET_IDENTITY_Ego *ego, |
1733 | void **ctx, | 1738 | void **ctx, |
1734 | const char *name) | 1739 | const char *name) |
1735 | { | 1740 | { |
1736 | (void) cls; | 1741 | (void)cls; |
1737 | (void) ctx; | 1742 | (void)ctx; |
1738 | 1743 | ||
1739 | if (NULL == ego) | 1744 | if (NULL == ego) |
1740 | { | ||
1741 | /* end of iteration */ | ||
1742 | if (NULL == zone_head) | ||
1743 | { | 1745 | { |
1744 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No zone found\n"); | 1746 | /* end of iteration */ |
1745 | GNUNET_SCHEDULER_shutdown (); | 1747 | if (NULL == zone_head) |
1748 | { | ||
1749 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "No zone found\n"); | ||
1750 | GNUNET_SCHEDULER_shutdown(); | ||
1751 | return; | ||
1752 | } | ||
1753 | /* zone_head non-null, process hostnames from stdin */ | ||
1754 | t = GNUNET_SCHEDULER_add_now(&process_stdin, NULL); | ||
1746 | return; | 1755 | return; |
1747 | } | 1756 | } |
1748 | /* zone_head non-null, process hostnames from stdin */ | ||
1749 | t = GNUNET_SCHEDULER_add_now (&process_stdin, NULL); | ||
1750 | return; | ||
1751 | } | ||
1752 | if (NULL != name) | 1757 | if (NULL != name) |
1753 | { | 1758 | { |
1754 | struct Zone *zone; | 1759 | struct Zone *zone; |
1755 | 1760 | ||
1756 | zone = GNUNET_new (struct Zone); | 1761 | zone = GNUNET_new(struct Zone); |
1757 | zone->key = *GNUNET_IDENTITY_ego_get_private_key (ego); | 1762 | zone->key = *GNUNET_IDENTITY_ego_get_private_key(ego); |
1758 | zone->domain = GNUNET_strdup (name); | 1763 | zone->domain = GNUNET_strdup(name); |
1759 | GNUNET_CONTAINER_DLL_insert (zone_head, zone_tail, zone); | 1764 | GNUNET_CONTAINER_DLL_insert(zone_head, zone_tail, zone); |
1760 | } | 1765 | } |
1761 | } | 1766 | } |
1762 | 1767 | ||
1763 | 1768 | ||
@@ -1771,52 +1776,52 @@ identity_cb (void *cls, | |||
1771 | * @param cfg configuration | 1776 | * @param cfg configuration |
1772 | */ | 1777 | */ |
1773 | static void | 1778 | static void |
1774 | run (void *cls, | 1779 | run(void *cls, |
1775 | char *const *args, | 1780 | char *const *args, |
1776 | const char *cfgfile, | 1781 | const char *cfgfile, |
1777 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 1782 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
1778 | { | 1783 | { |
1779 | (void) cls; | 1784 | (void)cls; |
1780 | (void) args; | 1785 | (void)args; |
1781 | (void) cfgfile; | 1786 | (void)cfgfile; |
1782 | stats = GNUNET_STATISTICS_create ("zoneimport", cfg); | 1787 | stats = GNUNET_STATISTICS_create("zoneimport", cfg); |
1783 | req_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); | 1788 | req_heap = GNUNET_CONTAINER_heap_create(GNUNET_CONTAINER_HEAP_ORDER_MIN); |
1784 | ns_pending = GNUNET_CONTAINER_multihashmap_create (map_size, GNUNET_NO); | 1789 | ns_pending = GNUNET_CONTAINER_multihashmap_create(map_size, GNUNET_NO); |
1785 | if (NULL == ns_pending) | 1790 | if (NULL == ns_pending) |
1786 | { | 1791 | { |
1787 | fprintf (stderr, "Failed to allocate memory for main hash map\n"); | 1792 | fprintf(stderr, "Failed to allocate memory for main hash map\n"); |
1788 | return; | 1793 | return; |
1789 | } | 1794 | } |
1790 | ctx = GNUNET_DNSSTUB_start (256); | 1795 | ctx = GNUNET_DNSSTUB_start(256); |
1791 | if (NULL == ctx) | 1796 | if (NULL == ctx) |
1792 | { | 1797 | { |
1793 | fprintf (stderr, "Failed to initialize GNUnet DNS STUB\n"); | 1798 | fprintf(stderr, "Failed to initialize GNUnet DNS STUB\n"); |
1794 | return; | 1799 | return; |
1795 | } | 1800 | } |
1796 | if (NULL == args[0]) | 1801 | if (NULL == args[0]) |
1797 | { | ||
1798 | fprintf (stderr, | ||
1799 | "You must provide a list of DNS resolvers on the command line\n"); | ||
1800 | return; | ||
1801 | } | ||
1802 | for (unsigned int i = 0; NULL != args[i]; i++) | ||
1803 | { | ||
1804 | if (GNUNET_OK != GNUNET_DNSSTUB_add_dns_ip (ctx, args[i])) | ||
1805 | { | 1802 | { |
1806 | fprintf (stderr, "Failed to use `%s' for DNS resolver\n", args[i]); | 1803 | fprintf(stderr, |
1804 | "You must provide a list of DNS resolvers on the command line\n"); | ||
1807 | return; | 1805 | return; |
1808 | } | 1806 | } |
1809 | } | 1807 | for (unsigned int i = 0; NULL != args[i]; i++) |
1808 | { | ||
1809 | if (GNUNET_OK != GNUNET_DNSSTUB_add_dns_ip(ctx, args[i])) | ||
1810 | { | ||
1811 | fprintf(stderr, "Failed to use `%s' for DNS resolver\n", args[i]); | ||
1812 | return; | ||
1813 | } | ||
1814 | } | ||
1810 | 1815 | ||
1811 | 1816 | ||
1812 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); | 1817 | GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL); |
1813 | ns = GNUNET_NAMESTORE_connect (cfg); | 1818 | ns = GNUNET_NAMESTORE_connect(cfg); |
1814 | if (NULL == ns) | 1819 | if (NULL == ns) |
1815 | { | 1820 | { |
1816 | GNUNET_SCHEDULER_shutdown (); | 1821 | GNUNET_SCHEDULER_shutdown(); |
1817 | return; | 1822 | return; |
1818 | } | 1823 | } |
1819 | id = GNUNET_IDENTITY_connect (cfg, &identity_cb, NULL); | 1824 | id = GNUNET_IDENTITY_connect(cfg, &identity_cb, NULL); |
1820 | } | 1825 | } |
1821 | 1826 | ||
1822 | 1827 | ||
@@ -1828,46 +1833,46 @@ run (void *cls, | |||
1828 | * @return 0 on success | 1833 | * @return 0 on success |
1829 | */ | 1834 | */ |
1830 | int | 1835 | int |
1831 | main (int argc, char *const *argv) | 1836 | main(int argc, char *const *argv) |
1832 | { | 1837 | { |
1833 | struct GNUNET_GETOPT_CommandLineOption options[] = | 1838 | struct GNUNET_GETOPT_CommandLineOption options[] = |
1834 | {GNUNET_GETOPT_option_uint ('s', | 1839 | { GNUNET_GETOPT_option_uint('s', |
1835 | "size", | 1840 | "size", |
1836 | "MAPSIZE", | 1841 | "MAPSIZE", |
1837 | gettext_noop ( | 1842 | gettext_noop( |
1838 | "size to use for the main hash map"), | 1843 | "size to use for the main hash map"), |
1839 | &map_size), | 1844 | &map_size), |
1840 | GNUNET_GETOPT_option_relative_time ( | 1845 | GNUNET_GETOPT_option_relative_time( |
1841 | 'm', | 1846 | 'm', |
1842 | "minimum-expiration", | 1847 | "minimum-expiration", |
1843 | "RELATIVETIME", | 1848 | "RELATIVETIME", |
1844 | gettext_noop ("minimum expiration time we assume for imported records"), | 1849 | gettext_noop("minimum expiration time we assume for imported records"), |
1845 | &minimum_expiration_time), | 1850 | &minimum_expiration_time), |
1846 | GNUNET_GETOPT_OPTION_END}; | 1851 | GNUNET_GETOPT_OPTION_END }; |
1847 | int ret; | 1852 | int ret; |
1848 | 1853 | ||
1849 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) | 1854 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) |
1850 | return 2; | 1855 | return 2; |
1851 | if (GNUNET_OK != (ret = GNUNET_PROGRAM_run (argc, | 1856 | if (GNUNET_OK != (ret = GNUNET_PROGRAM_run(argc, |
1852 | argv, | 1857 | argv, |
1853 | "gnunet-zoneimport", | 1858 | "gnunet-zoneimport", |
1854 | "import DNS zone into namestore", | 1859 | "import DNS zone into namestore", |
1855 | options, | 1860 | options, |
1856 | &run, | 1861 | &run, |
1857 | NULL))) | 1862 | NULL))) |
1858 | return ret; | 1863 | return ret; |
1859 | GNUNET_free ((void *) argv); | 1864 | GNUNET_free((void *)argv); |
1860 | fprintf (stderr, | 1865 | fprintf(stderr, |
1861 | "Rejected %u names, had %u cached, did %u lookups, stored %u record sets\n" | 1866 | "Rejected %u names, had %u cached, did %u lookups, stored %u record sets\n" |
1862 | "Found %u records, %u lookups failed, %u/%u pending on shutdown\n", | 1867 | "Found %u records, %u lookups failed, %u/%u pending on shutdown\n", |
1863 | rejects, | 1868 | rejects, |
1864 | cached, | 1869 | cached, |
1865 | lookups, | 1870 | lookups, |
1866 | record_sets, | 1871 | record_sets, |
1867 | records, | 1872 | records, |
1868 | failures, | 1873 | failures, |
1869 | pending, | 1874 | pending, |
1870 | pending_rs); | 1875 | pending_rs); |
1871 | return 0; | 1876 | return 0; |
1872 | } | 1877 | } |
1873 | 1878 | ||