aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2018-04-10 20:24:40 +0200
committerChristian Grothoff <christian@grothoff.org>2018-04-10 20:24:40 +0200
commitbb7e8254409c774653216dd3d16a3416e2707017 (patch)
tree612c4c0d3a8f77daf1585caa93e4714549b85db9 /src
parent9e1586de67362991a11e0d902f9a3deafbdba514 (diff)
downloadgnunet-bb7e8254409c774653216dd3d16a3416e2707017.tar.gz
gnunet-bb7e8254409c774653216dd3d16a3416e2707017.zip
more logging, manage slow down based on TTL
Diffstat (limited to 'src')
-rw-r--r--src/namestore/gnunet-zoneimport.c156
1 files changed, 138 insertions, 18 deletions
diff --git a/src/namestore/gnunet-zoneimport.c b/src/namestore/gnunet-zoneimport.c
index f2e5c7ba8..75bf6d639 100644
--- a/src/namestore/gnunet-zoneimport.c
+++ b/src/namestore/gnunet-zoneimport.c
@@ -456,7 +456,24 @@ check_for_glue (void *cls,
456 } 456 }
457 break; 457 break;
458 case GNUNET_DNSPARSER_TYPE_CNAME: 458 case GNUNET_DNSPARSER_TYPE_CNAME:
459 GNUNET_break (0); /* FIXME: implement! */ 459 if ( (GNUNET_OK ==
460 GNUNET_DNSPARSER_builder_add_name (dst,
461 dst_len,
462 &off,
463 gc->req->hostname)) &&
464 (GNUNET_OK ==
465 GNUNET_DNSPARSER_builder_add_name (dst,
466 dst_len,
467 &off,
468 rec->data.hostname)) )
469 {
470 add_record (gc->req,
471 rec->type,
472 rec->expiration_time,
473 dst,
474 off);
475 gc->found = GNUNET_YES;
476 }
460 break; 477 break;
461 default: 478 default:
462 /* useless, do nothing */ 479 /* useless, do nothing */
@@ -485,11 +502,23 @@ process_record (void *cls,
485 records++; 502 records++;
486 if (0 != strcasecmp (rec->name, 503 if (0 != strcasecmp (rec->name,
487 req->hostname)) 504 req->hostname))
505 {
506 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
507 "DNS returned record for `%s' of type %u while resolving `%s'\n",
508 rec->name,
509 (unsigned int) rec->type,
510 req->hostname);
488 return; /* does not match hostname, might be glue, but 511 return; /* does not match hostname, might be glue, but
489 not useful for this pass! */ 512 not useful for this pass! */
513 }
490 if (0 == 514 if (0 ==
491 GNUNET_TIME_absolute_get_remaining (rec->expiration_time).rel_value_us) 515 GNUNET_TIME_absolute_get_remaining (rec->expiration_time).rel_value_us)
516 {
517 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
518 "DNS returned expired record for `%s'\n",
519 req->hostname);
492 return; /* record expired */ 520 return; /* record expired */
521 }
493 switch (rec->type) 522 switch (rec->type)
494 { 523 {
495 case GNUNET_DNSPARSER_TYPE_NS: 524 case GNUNET_DNSPARSER_TYPE_NS:
@@ -514,25 +543,49 @@ process_record (void *cls,
514 dst_len, 543 dst_len,
515 &off, 544 &off,
516 rec->data.hostname)) ) 545 rec->data.hostname)) )
546 {
547 /* FIXME: actually check if this is out-of-bailiwick,
548 and if not request explicit resolution... */
549 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
550 "Converted OOB (`%s') NS record for `%s'\n",
551 rec->data.hostname,
552 rec->name);
517 add_record (req, 553 add_record (req,
518 rec->type, 554 rec->type,
519 rec->expiration_time, 555 rec->expiration_time,
520 dst, 556 dst,
521 off); 557 off);
558 }
559 else
560 {
561 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
562 "Converted NS record for `%s' using glue\n",
563 rec->name);
564 }
522 break; 565 break;
523 } 566 }
524 case GNUNET_DNSPARSER_TYPE_CNAME: 567 case GNUNET_DNSPARSER_TYPE_CNAME:
525 /* Special logic required, FIXME: support later! */ 568 if (GNUNET_OK ==
526 fprintf (stdout, 569 GNUNET_DNSPARSER_builder_add_name (dst,
527 "%s CNAME %s\n", 570 dst_len,
528 rec->name, 571 &off,
529 rec->data.hostname); 572 rec->data.hostname))
573 {
574 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
575 "Converting CNAME (`%s') record for `%s'\n",
576 rec->data.hostname,
577 rec->name);
578 add_record (req,
579 rec->type,
580 rec->expiration_time,
581 dst,
582 off);
583 }
530 break; 584 break;
531 case GNUNET_DNSPARSER_TYPE_DNAME: 585 case GNUNET_DNSPARSER_TYPE_DNAME:
532 /* Very special logic required (no support for DNAME 586 /* No support for DNAME in GNS yet! FIXME: support later! */
533 in GNS yet!), FIXME: support later! */
534 fprintf (stdout, 587 fprintf (stdout,
535 "FIMXE: %s DNAME %s\n", 588 "FIXME: not supported: %s DNAME %s\n",
536 rec->name, 589 rec->name,
537 rec->data.hostname); 590 rec->data.hostname);
538 break; 591 break;
@@ -542,11 +595,17 @@ process_record (void *cls,
542 dst_len, 595 dst_len,
543 &off, 596 &off,
544 rec->data.mx)) 597 rec->data.mx))
598 {
599 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
600 "Converting MX (`%s') record for `%s'\n",
601 rec->data.mx->mxhost,
602 rec->name);
545 add_record (req, 603 add_record (req,
546 rec->type, 604 rec->type,
547 rec->expiration_time, 605 rec->expiration_time,
548 dst, 606 dst,
549 off); 607 off);
608 }
550 break; 609 break;
551 case GNUNET_DNSPARSER_TYPE_SOA: 610 case GNUNET_DNSPARSER_TYPE_SOA:
552 if (GNUNET_OK == 611 if (GNUNET_OK ==
@@ -554,11 +613,17 @@ process_record (void *cls,
554 dst_len, 613 dst_len,
555 &off, 614 &off,
556 rec->data.soa)) 615 rec->data.soa))
616 {
617 /* NOTE: GNS does not really use SOAs */
618 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
619 "Converting SOA record for `%s'\n",
620 rec->name);
557 add_record (req, 621 add_record (req,
558 rec->type, 622 rec->type,
559 rec->expiration_time, 623 rec->expiration_time,
560 dst, 624 dst,
561 off); 625 off);
626 }
562 break; 627 break;
563 case GNUNET_DNSPARSER_TYPE_SRV: 628 case GNUNET_DNSPARSER_TYPE_SRV:
564 if (GNUNET_OK == 629 if (GNUNET_OK ==
@@ -566,11 +631,16 @@ process_record (void *cls,
566 dst_len, 631 dst_len,
567 &off, 632 &off,
568 rec->data.srv)) 633 rec->data.srv))
634 {
635 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
636 "Converting SRV record for `%s'\n",
637 rec->name);
569 add_record (req, 638 add_record (req,
570 rec->type, 639 rec->type,
571 rec->expiration_time, 640 rec->expiration_time,
572 dst, 641 dst,
573 off); 642 off);
643 }
574 break; 644 break;
575 case GNUNET_DNSPARSER_TYPE_PTR: 645 case GNUNET_DNSPARSER_TYPE_PTR:
576 if (GNUNET_OK == 646 if (GNUNET_OK ==
@@ -578,11 +648,17 @@ process_record (void *cls,
578 dst_len, 648 dst_len,
579 &off, 649 &off,
580 rec->data.hostname)) 650 rec->data.hostname))
651 {
652 /* !?: what does a PTR record do in a regular TLD??? */
653 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
654 "Converting PTR record for `%s' (weird)\n",
655 rec->name);
581 add_record (req, 656 add_record (req,
582 rec->type, 657 rec->type,
583 rec->expiration_time, 658 rec->expiration_time,
584 dst, 659 dst,
585 off); 660 off);
661 }
586 break; 662 break;
587 case GNUNET_DNSPARSER_TYPE_CERT: 663 case GNUNET_DNSPARSER_TYPE_CERT:
588 if (GNUNET_OK == 664 if (GNUNET_OK ==
@@ -590,11 +666,16 @@ process_record (void *cls,
590 dst_len, 666 dst_len,
591 &off, 667 &off,
592 rec->data.cert)) 668 rec->data.cert))
669 {
670 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
671 "Converting CERT record for `%s'\n",
672 rec->name);
593 add_record (req, 673 add_record (req,
594 rec->type, 674 rec->type,
595 rec->expiration_time, 675 rec->expiration_time,
596 dst, 676 dst,
597 off); 677 off);
678 }
598 break; 679 break;
599 /* Rest is 'raw' encoded and just needs to be copied IF 680 /* Rest is 'raw' encoded and just needs to be copied IF
600 the hostname matches the requested name; otherwise we 681 the hostname matches the requested name; otherwise we
@@ -603,6 +684,10 @@ process_record (void *cls,
603 case GNUNET_DNSPARSER_TYPE_AAAA: 684 case GNUNET_DNSPARSER_TYPE_AAAA:
604 case GNUNET_DNSPARSER_TYPE_TXT: 685 case GNUNET_DNSPARSER_TYPE_TXT:
605 default: 686 default:
687 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
688 "Converting record of type %u for `%s'\n",
689 (unsigned int) rec->type,
690 rec->name);
606 add_record (req, 691 add_record (req,
607 rec->type, 692 rec->type,
608 rec->expiration_time, 693 rec->expiration_time,
@@ -709,6 +794,10 @@ process_result (void *cls,
709 at); 794 at);
710 rd_count++; 795 rd_count++;
711 } 796 }
797 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
798 "Obtained %u records for `%s'\n",
799 rd_count,
800 req->hostname);
712 /* Instead of going for SOA, simplified for now to look each 801 /* Instead of going for SOA, simplified for now to look each
713 day in case we got an empty response */ 802 day in case we got an empty response */
714 if (0 == rd_count) 803 if (0 == rd_count)
@@ -752,18 +841,19 @@ process_result (void *cls,
752static int 841static int
753submit_req (struct Request *req) 842submit_req (struct Request *req)
754{ 843{
755 static struct timeval last_request; 844 static struct GNUNET_TIME_Absolute last_request;
756 struct timeval now; 845 struct GNUNET_TIME_Absolute now;
757 846
758 if (NULL != req->rs) 847 if (NULL != req->rs)
759 return GNUNET_NO; /* already submitted */ 848 return GNUNET_NO; /* already submitted */
760 gettimeofday (&now, 849 now = GNUNET_TIME_absolute_get ();
761 NULL); 850 if ( (now.abs_value_us - last_request.abs_value_us < TIME_THRESH) ||
762 if ( ( ( (now.tv_sec - last_request.tv_sec) == 0) &&
763 ( (now.tv_usec - last_request.tv_usec) < TIME_THRESH) ) ||
764 (pending >= THRESH) ) 851 (pending >= THRESH) )
765 return GNUNET_SYSERR; 852 return GNUNET_SYSERR;
766 GNUNET_assert (NULL == req->rs); 853 GNUNET_assert (NULL == req->rs);
854 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
855 "Requesting resolution for `%s'\n",
856 req->hostname);
767 req->rs = GNUNET_DNSSTUB_resolve2 (ctx, 857 req->rs = GNUNET_DNSSTUB_resolve2 (ctx,
768 req->raw, 858 req->raw,
769 req->raw_len, 859 req->raw_len,
@@ -793,15 +883,37 @@ process_queue(void *cls)
793 NULL != req; 883 NULL != req;
794 req = req->next) 884 req = req->next)
795 { 885 {
886 if (GNUNET_TIME_absolute_get_remaining (req->expires).rel_value_us > 0)
887 break;
796 if (GNUNET_SYSERR == submit_req (req)) 888 if (GNUNET_SYSERR == submit_req (req))
797 break; 889 break;
798 } 890 }
799 if (NULL != req_head) 891 if (NULL != req_head)
800 t = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS, 892 {
801 &process_queue, 893 if (GNUNET_TIME_absolute_get_remaining (req_head->expires).rel_value_us > 0)
802 NULL); 894 {
895 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
896 "Waiting until %s for next record to expire\n",
897 GNUNET_STRINGS_absolute_time_to_string (req_head->expires));
898 t = GNUNET_SCHEDULER_add_at (req_head->expires,
899 &process_queue,
900 NULL);
901 }
902 else
903 {
904 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
905 "Throttling for 1ms\n");
906 t = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS,
907 &process_queue,
908 NULL);
909 }
910 }
803 else 911 else
912 {
913 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
914 "No more pending requests, terminating\n");
804 GNUNET_SCHEDULER_shutdown (); 915 GNUNET_SCHEDULER_shutdown ();
916 }
805} 917}
806 918
807 919
@@ -897,6 +1009,10 @@ queue (const char *hostname)
897 hostname); 1009 hostname);
898 return; 1010 return;
899 } 1011 }
1012 /* TODO: may later support importing zones that
1013 are not TLD, for this we mostly need to change
1014 the logic here to remove the zone's suffix
1015 instead of just ".tld" */
900 dot = strrchr (hostname, 1016 dot = strrchr (hostname,
901 (unsigned char) '.'); 1017 (unsigned char) '.');
902 if (NULL == dot) 1018 if (NULL == dot)
@@ -959,6 +1075,10 @@ queue (const char *hostname)
959 "Failed to load data from namestore for `%s'\n", 1075 "Failed to load data from namestore for `%s'\n",
960 req->label); 1076 req->label);
961 } 1077 }
1078 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1079 "Adding `%s' to worklist to start at %s\n",
1080 req->hostname,
1081 GNUNET_STRINGS_absolute_time_to_string (req->expires));
962 insert_sorted (req); 1082 insert_sorted (req);
963} 1083}
964 1084