From c6a0a7573374a3e7718687df73c953c67301f400 Mon Sep 17 00:00:00 2001 From: Matthias Wachs Date: Wed, 13 Nov 2013 16:38:16 +0000 Subject: [PATCH] use nick instead of PSEU lookup --- src/gns/gnunet-service-gns_resolver.c | 29 +++++++++++++++++-- src/gns/gnunet-service-gns_shorten.c | 40 +++++++++++++++++++++++++-- src/gns/gnunet-service-gns_shorten.h | 5 ++-- 3 files changed, 68 insertions(+), 6 deletions(-) diff --git a/src/gns/gnunet-service-gns_resolver.c b/src/gns/gnunet-service-gns_resolver.c index 2ab3c9a88..8f21b0d13 100644 --- a/src/gns/gnunet-service-gns_resolver.c +++ b/src/gns/gnunet-service-gns_resolver.c @@ -1078,6 +1078,7 @@ handle_gns_cname_result (struct GNS_ResolverHandle *rh, /* tigger shortening */ if (NULL != rh->shorten_key) GNS_shorten_start (rh->ac_tail->label, + NULL, &ac->authority_info.gns_authority, rh->shorten_key); /* add AC to tail */ @@ -1333,12 +1334,14 @@ handle_gns_resolution_result (void *cls, struct VpnContext *vpn_ctx; const struct GNUNET_TUN_GnsVpnRecord *vpn; const char *vname; + const char *suggested_label; struct GNUNET_HashCode vhash; int af; char scratch[UINT16_MAX]; size_t scratch_off; size_t scratch_start; size_t off; + int c2; struct GNUNET_GNSRECORD_Data rd_new[rd_count]; unsigned int rd_off; @@ -1612,7 +1615,17 @@ handle_gns_resolution_result (void *cls, /* tigger shortening */ if (NULL != rh->shorten_key) { - GNS_shorten_start (rh->ac_tail->label, + suggested_label = NULL; + for (c2 = 0; c2< rd_count; c2++) + { + if ((GNUNET_GNSRECORD_TYPE_NICK ==rd[c2].record_type) && + (rd[i].data_size > 0) && + (((const char *) rd[c2].data)[rd[c2].data_size -1] == '\0')) + suggested_label = (const char *) rd->data; + } + if (NULL != suggested_label) + GNS_shorten_start (rh->ac_tail->label, + suggested_label, &pub, rh->shorten_key); } @@ -1684,9 +1697,21 @@ handle_gns_resolution_result (void *cls, ac->label = resolver_lookup_get_next_label (rh); /* tigger shortening */ if (NULL != rh->shorten_key) - GNS_shorten_start (rh->ac_tail->label, + { + suggested_label = NULL; + for (c2 = 0; c2< rd_count; c2++) + { + if ((GNUNET_GNSRECORD_TYPE_NICK ==rd[c2].record_type) && + (rd[c2].data_size > 0) && + ((const char *) rd[c2].data)[rd[c2].data_size -1] == '\0') + suggested_label = (const char *) rd[c2].data; + } + if (NULL != suggested_label) + GNS_shorten_start (rh->ac_tail->label, + suggested_label, &ac->authority_info.gns_authority, rh->shorten_key); + } /* add AC to tail */ GNUNET_CONTAINER_DLL_insert_tail (rh->ac_head, rh->ac_tail, diff --git a/src/gns/gnunet-service-gns_shorten.c b/src/gns/gnunet-service-gns_shorten.c index 9c27da16f..55b7ca3d7 100644 --- a/src/gns/gnunet-service-gns_shorten.c +++ b/src/gns/gnunet-service-gns_shorten.c @@ -73,6 +73,11 @@ struct GetPseuAuthorityHandle */ char label[GNUNET_DNSPARSER_MAX_LABEL_LENGTH + 1]; + /** + * Suggested label based on NICK record + */ + char * suggested_label; + /** * Label we are currently trying out (during #perform_pseu_lookup). */ @@ -236,7 +241,7 @@ process_pseu_block_ns (void *cls, /** - * Lookup in the namestore for the shorten zone the given label. + * Lookup in the namecache for the shorten zone the given label. * * @param gph the handle to our shorten operation * @param label the label to lookup @@ -476,6 +481,25 @@ process_auth_discovery_dht_result (void* cls, } } +static void suggested_lookup_cb (void *cls, + const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, + const char *label, + unsigned int rd_count, + const struct GNUNET_GNSRECORD_Data *rd) +{ + struct GetPseuAuthorityHandle* gph = cls; + gph->namestore_task = NULL; + if ((0 == strcmp (label, gph->suggested_label)) && (0 == rd_count) && (NULL == rd)) + { + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Shortening to suggested name `%s' possible\n", + gph->suggested_label); + process_pseu_result (gph, gph->suggested_label); + } +} + + /** * Callback called by namestore for a zone to name result. We're @@ -495,7 +519,9 @@ process_zone_to_name_discover (void *cls, const struct GNUNET_GNSRECORD_Data *rd) { struct GetPseuAuthorityHandle* gph = cls; +#if 0 struct GNUNET_HashCode lookup_key; +#endif gph->namestore_task = NULL; if (0 != rd_len) @@ -507,7 +533,13 @@ process_zone_to_name_discover (void *cls, free_get_pseu_authority_handle (gph); return; } - /* record does not yet exist, go into DHT to find PSEU record */ + /* record does not yet exist, check if suggested label is available */ + + if (NULL != gph->suggested_label) + gph->namestore_task = GNUNET_NAMESTORE_records_lookup (namestore_handle, zone_key, + gph->suggested_label, &suggested_lookup_cb, gph); + +#if 0 GNUNET_GNSRECORD_query_from_public_key (&gph->target_zone, GNUNET_GNS_TLD_PLUS, &lookup_key); @@ -527,6 +559,7 @@ process_zone_to_name_discover (void *cls, NULL, 0, &process_auth_discovery_dht_result, gph); +#endif } @@ -536,11 +569,13 @@ process_zone_to_name_discover (void *cls, * @a original_label as one possible suggestion. * * @param original_label original label for the zone + * @param suggested_label suggested label for the zone * @param pub public key of the zone to shorten * @param shorten_zone private key of the target zone for the new record */ void GNS_shorten_start (const char *original_label, + const char *suggested_label, const struct GNUNET_CRYPTO_EcdsaPublicKey *pub, const struct GNUNET_CRYPTO_EcdsaPrivateKey *shorten_zone) { @@ -558,6 +593,7 @@ GNS_shorten_start (const char *original_label, gph = GNUNET_new (struct GetPseuAuthorityHandle); gph->shorten_zone_key = *shorten_zone; gph->target_zone = *pub; + gph->suggested_label = GNUNET_strdup (suggested_label); strcpy (gph->label, original_label); GNUNET_CONTAINER_DLL_insert (gph_head, gph_tail, gph); /* first, check if we *already* have a record for this zone */ diff --git a/src/gns/gnunet-service-gns_shorten.h b/src/gns/gnunet-service-gns_shorten.h index f99d465f9..1e55a89d7 100644 --- a/src/gns/gnunet-service-gns_shorten.h +++ b/src/gns/gnunet-service-gns_shorten.h @@ -62,8 +62,9 @@ GNS_shorten_done (void); */ void GNS_shorten_start (const char *original_label, - const struct GNUNET_CRYPTO_EcdsaPublicKey *pub, - const struct GNUNET_CRYPTO_EcdsaPrivateKey *shorten_zone); + const char *suggested_label, + const struct GNUNET_CRYPTO_EcdsaPublicKey *pub, + const struct GNUNET_CRYPTO_EcdsaPrivateKey *shorten_zone); #endif -- 2.25.1