diff options
author | Martin Schanzenbach <mschanzenbach@posteo.de> | 2012-02-23 23:23:05 +0000 |
---|---|---|
committer | Martin Schanzenbach <mschanzenbach@posteo.de> | 2012-02-23 23:23:05 +0000 |
commit | 5f166428c7922336c1bbfdf5eb7e311aa08120b1 (patch) | |
tree | 0cf93bc24035c6e5a06cedfd892a915153af64aa | |
parent | 5c7ab9ecb73fb7b232149de884b4b7a18bb602cd (diff) | |
download | gnunet-5f166428c7922336c1bbfdf5eb7e311aa08120b1.tar.gz gnunet-5f166428c7922336c1bbfdf5eb7e311aa08120b1.zip |
-dnsparser stuff, still incomplete
-rw-r--r-- | src/gns/gnunet-service-gns.c | 60 |
1 files changed, 42 insertions, 18 deletions
diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c index 6b4606c5d..4bdf1daf3 100644 --- a/src/gns/gnunet-service-gns.c +++ b/src/gns/gnunet-service-gns.c | |||
@@ -565,16 +565,14 @@ void | |||
565 | reply_to_dns(struct GNUNET_GNS_PendingQuery *answer) | 565 | reply_to_dns(struct GNUNET_GNS_PendingQuery *answer) |
566 | { | 566 | { |
567 | struct GNUNET_GNS_QueryRecordList *i; | 567 | struct GNUNET_GNS_QueryRecordList *i; |
568 | struct GNUNET_DNSPARSER_Packet *packet; | ||
569 | struct GNUNET_DNSPARSER_Flags dnsflags; | 568 | struct GNUNET_DNSPARSER_Flags dnsflags; |
570 | int j; | 569 | int j; |
571 | size_t len; | 570 | size_t len; |
572 | int ret; | 571 | int ret; |
573 | char *buf; | 572 | char *buf; |
574 | 573 | struct GNUNET_DNSPARSER_Packet packet; | |
575 | packet = GNUNET_malloc(sizeof(struct GNUNET_DNSPARSER_Packet)); | 574 | struct GNUNET_DNSPARSER_Record answer_records[answer->num_records]; |
576 | packet->answers = | 575 | packet.answers = answer_records; |
577 | GNUNET_malloc(sizeof(struct GNUNET_DNSPARSER_Record) * answer->num_records); | ||
578 | 576 | ||
579 | len = sizeof(struct GNUNET_DNSPARSER_Record*); | 577 | len = sizeof(struct GNUNET_DNSPARSER_Record*); |
580 | j = 0; | 578 | j = 0; |
@@ -582,28 +580,30 @@ reply_to_dns(struct GNUNET_GNS_PendingQuery *answer) | |||
582 | { | 580 | { |
583 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 581 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
584 | "Adding type %d to DNS response\n", i->record->record_type); | 582 | "Adding type %d to DNS response\n", i->record->record_type); |
585 | //FIXME build proper dnsparser record! this will fail! | 583 | answer_records[j].name = answer->original_name; //FIXME yes? |
586 | //memcpy(&packet->answers[j], | 584 | answer_records[j].type = i->record->record_type; |
587 | // i->record, | 585 | answer_records[j].data.raw.data_len = i->record->data_size; |
588 | // sizeof (struct GNUNET_DNSPARSER_Record)); | 586 | answer_records[j].data.raw.data = (char*)i->record->data; |
589 | GNUNET_free(i->record); | 587 | answer_records[j].expiration_time = i->record->expiration; |
588 | answer_records[j].class = GNUNET_DNSPARSER_CLASS_INTERNET;//hmmn | ||
589 | //GNUNET_free(i->record); DO this later! | ||
590 | j++; | 590 | j++; |
591 | } | 591 | } |
592 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "after memcpy\n"); | 592 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "after memcpy\n"); |
593 | /* FIXME how to handle auth, additional etc */ | 593 | /* FIXME how to handle auth, additional etc */ |
594 | packet->num_answers = answer->num_records; | 594 | packet.num_answers = answer->num_records; |
595 | packet->num_authority_records = answer->num_authority_records; | 595 | packet.num_authority_records = answer->num_authority_records; |
596 | 596 | ||
597 | dnsflags.authoritative_answer = 1; | 597 | dnsflags.authoritative_answer = 1; |
598 | dnsflags.opcode = GNUNET_DNSPARSER_OPCODE_QUERY; | 598 | dnsflags.opcode = GNUNET_DNSPARSER_OPCODE_QUERY; |
599 | dnsflags.return_code = GNUNET_DNSPARSER_RETURN_CODE_NO_ERROR; //not sure | 599 | dnsflags.return_code = GNUNET_DNSPARSER_RETURN_CODE_NO_ERROR; //not sure |
600 | dnsflags.query_or_response = 1; | 600 | dnsflags.query_or_response = 1; |
601 | packet->flags = dnsflags; | 601 | packet.flags = dnsflags; |
602 | 602 | ||
603 | packet->id = answer->id; | 603 | packet.id = answer->id; |
604 | 604 | ||
605 | //FIXME this is silently discarded | 605 | //FIXME this is silently discarded |
606 | ret = GNUNET_DNSPARSER_pack (packet, | 606 | ret = GNUNET_DNSPARSER_pack (&packet, |
607 | 1024, /* FIXME magic from dns redirector */ | 607 | 1024, /* FIXME magic from dns redirector */ |
608 | &buf, | 608 | &buf, |
609 | &len); | 609 | &len); |
@@ -653,9 +653,12 @@ process_authoritative_result(void* cls, | |||
653 | struct GNUNET_GNS_PendingQuery *query; | 653 | struct GNUNET_GNS_PendingQuery *query; |
654 | struct GNUNET_GNS_QueryRecordList *qrecord; | 654 | struct GNUNET_GNS_QueryRecordList *qrecord; |
655 | struct GNUNET_NAMESTORE_RecordData *record; | 655 | struct GNUNET_NAMESTORE_RecordData *record; |
656 | struct GNUNET_TIME_Relative remaining_time; | ||
656 | GNUNET_HashCode zone; | 657 | GNUNET_HashCode zone; |
658 | |||
657 | query = (struct GNUNET_GNS_PendingQuery *) cls; | 659 | query = (struct GNUNET_GNS_PendingQuery *) cls; |
658 | GNUNET_CRYPTO_hash(key, GNUNET_CRYPTO_RSA_KEY_LENGTH, &zone); | 660 | GNUNET_CRYPTO_hash(key, GNUNET_CRYPTO_RSA_KEY_LENGTH, &zone); |
661 | remaining_time = GNUNET_TIME_absolute_get_remaining (expiration); | ||
659 | 662 | ||
660 | //FIXME Handle results in rd | 663 | //FIXME Handle results in rd |
661 | 664 | ||
@@ -675,9 +678,16 @@ process_authoritative_result(void* cls, | |||
675 | */ | 678 | */ |
676 | if (!GNUNET_CRYPTO_hash_cmp(&zone, &zone_hash)) | 679 | if (!GNUNET_CRYPTO_hash_cmp(&zone, &zone_hash)) |
677 | { | 680 | { |
678 | //FIXME if very recent dht lookup -> cannot resolve | 681 | remaining_time = GNUNET_TIME_absolute_get_remaining (expiration); |
679 | resolve_name_dht(query, name); | 682 | if (remaining_time.rel_value == 0) |
680 | return; | 683 | { |
684 | resolve_name_dht(query, name); | ||
685 | return; | ||
686 | } | ||
687 | else | ||
688 | { | ||
689 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Record is still recent. No DHT lookup\n"); | ||
690 | } | ||
681 | } | 691 | } |
682 | 692 | ||
683 | /** | 693 | /** |
@@ -697,11 +707,25 @@ process_authoritative_result(void* cls, | |||
697 | * FIXME Check record expiration and dht expiration | 707 | * FIXME Check record expiration and dht expiration |
698 | * consult dht if necessary | 708 | * consult dht if necessary |
699 | */ | 709 | */ |
710 | if (remaining_time.rel_value == 0) | ||
711 | { | ||
712 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
713 | "This dht entry is old. Refreshing.\n"); | ||
714 | resolve_name_dht(query, name); | ||
715 | return; | ||
716 | } | ||
700 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 717 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
701 | "Processing additional result %s from namestore\n", name); | 718 | "Processing additional result %s from namestore\n", name); |
702 | int i; | 719 | int i; |
703 | for (i=0; i<rd_count;i++) | 720 | for (i=0; i<rd_count;i++) |
704 | { | 721 | { |
722 | if ((GNUNET_TIME_absolute_get_remaining (rd[i].expiration)).rel_value | ||
723 | == 0) | ||
724 | { | ||
725 | //FIXME there is a catch here... | ||
726 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "This record is expired. Skipping\n"); | ||
727 | continue; | ||
728 | } | ||
705 | // A time will come when this has to be freed | 729 | // A time will come when this has to be freed |
706 | qrecord = GNUNET_malloc(sizeof(struct GNUNET_GNS_QueryRecordList)); | 730 | qrecord = GNUNET_malloc(sizeof(struct GNUNET_GNS_QueryRecordList)); |
707 | record = GNUNET_malloc(sizeof(struct GNUNET_NAMESTORE_RecordData)); | 731 | record = GNUNET_malloc(sizeof(struct GNUNET_NAMESTORE_RecordData)); |