From: Martin Schanzenbach Date: Tue, 19 Jun 2012 12:33:07 +0000 (+0000) Subject: -add CNAME handling for GNS X-Git-Tag: initial-import-from-subversion-38251~12973 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=72d6a013072770ba7e2426346f962a8ade446b8c;p=oweals%2Fgnunet.git -add CNAME handling for GNS --- diff --git a/src/gns/Makefile.am b/src/gns/Makefile.am index a65ab994b..648b80df9 100644 --- a/src/gns/Makefile.am +++ b/src/gns/Makefile.am @@ -49,7 +49,8 @@ check_PROGRAMS = \ test_gns_dht_delegated_lookup \ test_gns_pseu_shorten \ test_gns_max_queries \ - test_gns_dht_threepeer + test_gns_dht_threepeer \ + test_gns_cname_lookup # test_gns_simple_lookup @@ -196,6 +197,19 @@ test_gns_max_queries_DEPENDENCIES = \ $(top_builddir)/src/gns/libgnunetgns.la \ $(top_builddir)/src/testing_old/libgnunettesting_old.la +test_gns_cname_lookup_SOURCES = \ + test_gns_cname_lookup.c +test_gns_cname_lookup_LDADD = \ + $(top_builddir)/src/util/libgnunetutil.la \ + $(top_builddir)/src/namestore/libgnunetnamestore.la \ + $(top_builddir)/src/gns/libgnunetgns.la \ + $(top_builddir)/src/testing_old/libgnunettesting_old.la +test_gns_cname_lookup_DEPENDENCIES = \ + $(top_builddir)/src/util/libgnunetutil.la \ + $(top_builddir)/src/namestore/libgnunetnamestore.la \ + $(top_builddir)/src/gns/libgnunetgns.la \ + $(top_builddir)/src/testing_old/libgnunettesting_old.la + gnunet_gns_SOURCES = \ gnunet-gns.c gnunet_gns_LDADD = \ diff --git a/src/gns/gnunet-service-gns_resolver.c b/src/gns/gnunet-service-gns_resolver.c index 35b414e79..1c1edaea5 100644 --- a/src/gns/gnunet-service-gns_resolver.c +++ b/src/gns/gnunet-service-gns_resolver.c @@ -2017,6 +2017,22 @@ process_delegation_result_dht(void* cls, GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "GNS_PHASE_DELEGATE_DHT-%llu: Got flag %d\n", rh->id, rd[i].flags); + + if ((rd[i].record_type == GNUNET_GNS_RECORD_VPN) || + (rd[i].record_type == GNUNET_GNS_RECORD_TYPE_NS) || + (rd[i].record_type == GNUNET_GNS_RECORD_TYPE_CNAME)) + { + /** + * This is a VPN,NS,CNAME entry. Let namestore handle this after caching + */ + if (strcmp(rh->name, "") == 0) + strcpy(rh->name, rh->authority_name); + else + GNUNET_snprintf(rh->name, MAX_DNS_NAME_LENGTH, "%s.%s", + rh->name, rh->authority_name); //FIXME ret + rh->answered = 1; + break; + } if ((strcmp(name, rh->authority_name) == 0) && (rd[i].record_type == GNUNET_GNS_RECORD_PKEY)) @@ -2094,7 +2110,7 @@ process_delegation_result_dht(void* cls, else { rh->proc = &handle_delegation_ns; - resolve_delegation_ns(rh); + resolve_delegation_ns (rh); } return; } @@ -2560,9 +2576,9 @@ resolve_delegation_dht(struct ResolverHandle *rh) * @param rd record data (always NULL) */ static void -handle_delegation_ns(void* cls, struct ResolverHandle *rh, - unsigned int rd_count, - const struct GNUNET_NAMESTORE_RecordData *rd) +handle_delegation_ns (void* cls, struct ResolverHandle *rh, + unsigned int rd_count, + const struct GNUNET_NAMESTORE_RecordData *rd) { struct RecordLookupHandle* rlh; rlh = (struct RecordLookupHandle*) cls; @@ -2573,22 +2589,30 @@ handle_delegation_ns(void* cls, struct ResolverHandle *rh, if (strcmp(rh->name, "") == 0) { - if (rlh->record_type == GNUNET_GNS_RECORD_PKEY) - { - GNUNET_assert(rd_count == 1); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "GNS_PHASE_DELEGATE_NS-%llu: Resolved queried PKEY in NS.\n", - rh->id); - finish_lookup(rh, rlh, rd_count, rd); - free_resolver_handle(rh); - return; - } + /* We resolved full name for delegation. resolving record */ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "GNS_PHASE_DELEGATE_NS-%llu: Resolved full name for delegation.\n", rh->id); - - if (rh->status & RSL_DELEGATE_VPN) + if (rh->status & RSL_CNAME_FOUND) + { + if (rlh->record_type == GNUNET_GNS_RECORD_TYPE_CNAME) + { + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "GNS_PHASE_DELEGATE_NS-%llu: Resolved queried CNAME in NS.\n", + rh->id); + finish_lookup(rh, rlh, rd_count, rd); + free_resolver_handle(rh); + return; + } + + /* A CNAME can only occur alone */ + GNUNET_assert (is_canonical ((char*)rd->data)); + strcpy (rh->name, rd->data); + resolve_delegation_ns (rh); + return; + } + else if (rh->status & RSL_DELEGATE_VPN) { if (rlh->record_type == GNUNET_GNS_RECORD_VPN) { @@ -2617,6 +2641,7 @@ handle_delegation_ns(void* cls, struct ResolverHandle *rh, free_resolver_handle(rh); return; } + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "GNS_PHASE_DELEGATE_NS-%llu: VPN delegation starting.\n", rh->id); @@ -2624,6 +2649,19 @@ handle_delegation_ns(void* cls, struct ResolverHandle *rh, rh->proc = &handle_record_ns; resolve_record_dns (rh, rd_count, rd); } + else if (rh->status & RSL_DELEGATE_PKEY) + { + if (rlh->record_type == GNUNET_GNS_RECORD_PKEY) + { + GNUNET_assert(rd_count == 1); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "GNS_PHASE_DELEGATE_NS-%llu: Resolved queried PKEY in NS.\n", + rh->id); + finish_lookup(rh, rlh, rd_count, rd); + free_resolver_handle(rh); + return; + } + } else { GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, @@ -2792,13 +2830,32 @@ process_delegation_result_ns(void* cls, int i; for (i=0; iid); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "GNS_PHASE_DELEGATE_NS-%llu: new name to resolve: %s.\n", + rh->id, rh->name); + + rh->status |= RSL_CNAME_FOUND; + rh->proc (rh->proc_cls, rh, rd_count, rd); + return; + } + /** * Redirect via VPN */ if (rd[i].record_type == GNUNET_GNS_RECORD_VPN) { GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "GNS_PHASE_DELEGATE_NS-%llu: VPNRR found.\n", + "GNS_PHASE_DELEGATE_NS-%llu: VPN found.\n", rh->id); rh->status |= RSL_DELEGATE_VPN; rh->proc (rh->proc_cls, rh, rd_count, rd); @@ -2821,6 +2878,8 @@ process_delegation_result_ns(void* cls, if (rd[i].record_type != GNUNET_GNS_RECORD_PKEY) continue; + rh->status |= RSL_DELEGATE_PKEY; + if (ignore_pending_records && (rd[i].flags & GNUNET_NAMESTORE_RF_PENDING)) { @@ -2875,10 +2934,10 @@ process_delegation_result_ns(void* cls, * We are done with PKEY resolution if name is empty * else resolve again with new authority */ - if (strcmp(rh->name, "") == 0) - rh->proc(rh->proc_cls, rh, rd_count, rd); + if (strcmp (rh->name, "") == 0) + rh->proc (rh->proc_cls, rh, rd_count, rd); else - resolve_delegation_ns(rh); + resolve_delegation_ns (rh); return; } @@ -2922,7 +2981,7 @@ process_delegation_result_ns(void* cls, * @param rh the resolver handle */ static void -resolve_delegation_ns(struct ResolverHandle *rh) +resolve_delegation_ns (struct ResolverHandle *rh) { GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "GNS_PHASE_DELEGATE_NS-%llu: Resolving delegation for %s\n", @@ -3475,7 +3534,7 @@ process_zone_to_name_shorten_root (void *cls, * @param rd data (NULL) */ void -handle_delegation_ns_shorten(void* cls, +handle_delegation_ns_shorten (void* cls, struct ResolverHandle *rh, uint32_t rd_count, const struct GNUNET_NAMESTORE_RecordData *rd) diff --git a/src/gns/gnunet-service-gns_resolver.h b/src/gns/gnunet-service-gns_resolver.h index 768451205..0e18f13a6 100644 --- a/src/gns/gnunet-service-gns_resolver.h +++ b/src/gns/gnunet-service-gns_resolver.h @@ -90,6 +90,8 @@ typedef void (*ResolutionResultProcessor) (void *cls, * RSL_TIMED_OUT: resolution timed out * RSL_DELEGATE_VPN: Found VPN delegation * RSL_DELEGATE_NS: Found NS delegation + * RSL_DELEGATE_PKEY: Found PKEY delegation + * RSL_CNAME_FOUND: Found CNAME record */ enum ResolutionStatus { @@ -97,7 +99,9 @@ enum ResolutionStatus RSL_RECORD_EXPIRED = 2, RSL_TIMED_OUT = 4, RSL_DELEGATE_VPN = 8, - RSL_DELEGATE_NS = 16 + RSL_DELEGATE_NS = 16, + RSL_DELEGATE_PKEY = 32, + RSL_CNAME_FOUND = 64 }; /**