From e6d0c3119a3348eeb539a7e52113e12a7bb37a5f Mon Sep 17 00:00:00 2001 From: Martin Schanzenbach Date: Fri, 29 Jun 2012 14:36:19 +0000 Subject: [PATCH] -fix 2447 --- src/gns/gns.conf.in | 3 - src/gns/gns.h | 10 + src/gns/gns_api.c | 22 ++- src/gns/gnunet-gns-proxy.c | 71 ++++++- src/gns/gnunet-gns.c | 43 +++++ src/gns/gnunet-service-gns.c | 257 ++++++++++++++++++-------- src/gns/gnunet-service-gns_resolver.c | 64 ++++--- src/gns/test_gns_pseu_shorten.c | 8 +- src/include/gnunet_gns_service.h | 16 +- 9 files changed, 366 insertions(+), 128 deletions(-) diff --git a/src/gns/gns.conf.in b/src/gns/gns.conf.in index 406d59464..4e13e4778 100644 --- a/src/gns/gns.conf.in +++ b/src/gns/gns.conf.in @@ -6,13 +6,10 @@ CONFIG = $DEFAULTCONFIG BINARY = gnunet-service-gns UNIXPATH = /tmp/gnunet-service-gns.sock ZONEKEY = $SERVICEHOME/gns/zonekey.zkey -PRIVATE_ZONE = private PRIVATE_ZONEKEY = $SERVICEHOME/gns/zonekey_priv.zkey -SHORTEN_ZONE = short SHORTEN_ZONEKEY = $SERVICEHOME/gns/zonekey_short.zkey HIJACK_DNS = NO AUTO_IMPORT_PKEY = YES -AUTO_IMPORT_ZONEKEY = $SERVICEHOME/gns/shorten_zonekey.zkey AUTO_IMPORT_CONFIRMATION_REQ = NO MAX_PARALLEL_BACKGROUND_QUERIES = 25 DEFAULT_LOOKUP_TIMEOUT = 10 diff --git a/src/gns/gns.h b/src/gns/gns.h index e856a3312..49bfd9093 100644 --- a/src/gns/gns.h +++ b/src/gns/gns.h @@ -133,6 +133,16 @@ struct GNUNET_GNS_ClientShortenMessage * If use_default_zone is empty this zone is used for lookup */ struct GNUNET_CRYPTO_ShortHashCode zone; + + /** + * Shorten zone + */ + struct GNUNET_CRYPTO_ShortHashCode shorten_zone; + + /** + * Private zone + */ + struct GNUNET_CRYPTO_ShortHashCode private_zone; /* Followed by the name to shorten up */ }; diff --git a/src/gns/gns_api.c b/src/gns/gns_api.c index 28d29f58a..ac7f87241 100644 --- a/src/gns/gns_api.c +++ b/src/gns/gns_api.c @@ -766,6 +766,8 @@ GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle, * * @param handle handle to the GNS service * @param name the name to look up + * @param private_zone the public zone of the private zone + * @param shorten_zone the public zone of the shorten zone * @param zone the zone to start the resolution in * @param proc function to call on result * @param proc_cls closure for processor @@ -773,10 +775,12 @@ GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle, */ struct GNUNET_GNS_QueueEntry * GNUNET_GNS_shorten_zone (struct GNUNET_GNS_Handle *handle, - const char * name, - struct GNUNET_CRYPTO_ShortHashCode *zone, - GNUNET_GNS_ShortenResultProcessor proc, - void *proc_cls) + const char * name, + struct GNUNET_CRYPTO_ShortHashCode *private_zone, + struct GNUNET_CRYPTO_ShortHashCode *shorten_zone, + struct GNUNET_CRYPTO_ShortHashCode *zone, + GNUNET_GNS_ShortenResultProcessor proc, + void *proc_cls) { /* IPC to shorten gns names, return shorten_handle */ struct GNUNET_GNS_ClientShortenMessage *shorten_msg; @@ -809,6 +813,8 @@ GNUNET_GNS_shorten_zone (struct GNUNET_GNS_Handle *handle, shorten_msg->header.type = htons (GNUNET_MESSAGE_TYPE_GNS_SHORTEN); shorten_msg->header.size = htons (msize); shorten_msg->id = htonl(qe->r_id); + shorten_msg->private_zone = *private_zone; + shorten_msg->shorten_zone = *shorten_zone; if (NULL != zone) { @@ -836,6 +842,8 @@ GNUNET_GNS_shorten_zone (struct GNUNET_GNS_Handle *handle, * * @param handle handle to the GNS service * @param name the name to look up + * @param private_zone the public zone of the private zone + * @param shorten_zone the public zone of the shorten zone * @param proc function to call on result * @param proc_cls closure for processor * @return handle to the operation @@ -843,10 +851,14 @@ GNUNET_GNS_shorten_zone (struct GNUNET_GNS_Handle *handle, struct GNUNET_GNS_QueueEntry * GNUNET_GNS_shorten (struct GNUNET_GNS_Handle *handle, const char * name, + struct GNUNET_CRYPTO_ShortHashCode *private_zone, + struct GNUNET_CRYPTO_ShortHashCode *shorten_zone, GNUNET_GNS_ShortenResultProcessor proc, void *proc_cls) { - return GNUNET_GNS_shorten_zone (handle, name, NULL, proc, proc_cls); + return GNUNET_GNS_shorten_zone (handle, name, + private_zone, shorten_zone, + NULL, proc, proc_cls); } /** * Perform an authority lookup for a given name. diff --git a/src/gns/gnunet-gns-proxy.c b/src/gns/gnunet-gns-proxy.c index 51bd51f2f..856d98f07 100644 --- a/src/gns/gnunet-gns-proxy.c +++ b/src/gns/gnunet-gns-proxy.c @@ -292,6 +292,12 @@ static regex_t re_dotplus; /* The users local GNS zone hash */ static struct GNUNET_CRYPTO_ShortHashCode local_gns_zone; +/* The users local private zone */ +static struct GNUNET_CRYPTO_ShortHashCode local_private_zone; + +/* The users local shorten zone */ +static struct GNUNET_CRYPTO_ShortHashCode local_shorten_zone; + /* The CA for SSL certificate generation */ static struct ProxyCA proxy_ca; @@ -687,10 +693,13 @@ mhd_content_cb (void *cls, ctask->is_postprocessing = GNUNET_YES; ctask->pp_finished = GNUNET_NO; - GNUNET_GNS_shorten (gns_handle, - ctask->pp_buf, - &process_shorten, - ctask); + GNUNET_GNS_shorten_zone (gns_handle, + ctask->pp_buf, + &local_private_zone, + &local_shorten_zone, + &local_gns_zone, + &process_shorten, + ctask); return 0; } @@ -2358,6 +2367,60 @@ load_local_zone_key (const struct GNUNET_CONFIGURATION_Handle *cfg) "Using zone: %s!\n", &zonename); GNUNET_CRYPTO_rsa_key_free(key); GNUNET_free(keyfile); + + if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns", + "PRIVATE_ZONEKEY", &keyfile)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Unable to load private zone key config value!\n"); + return GNUNET_NO; + } + + if (GNUNET_NO == GNUNET_DISK_file_test (keyfile)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Unable to load private zone key %s!\n", keyfile); + GNUNET_free(keyfile); + return GNUNET_NO; + } + + key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile); + GNUNET_CRYPTO_rsa_key_get_public (key, &pkey); + GNUNET_CRYPTO_short_hash(&pkey, + sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), + &local_private_zone); + GNUNET_CRYPTO_short_hash_to_enc (zone, &zonename); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Using private zone: %s!\n", &zonename); + GNUNET_CRYPTO_rsa_key_free(key); + GNUNET_free(keyfile); + + if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns", + "SHORTEN_ZONEKEY", &keyfile)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Unable to load shorten zone key config value!\n"); + return GNUNET_NO; + } + + if (GNUNET_NO == GNUNET_DISK_file_test (keyfile)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Unable to load shorten zone key %s!\n", keyfile); + GNUNET_free(keyfile); + return GNUNET_NO; + } + + key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile); + GNUNET_CRYPTO_rsa_key_get_public (key, &pkey); + GNUNET_CRYPTO_short_hash(&pkey, + sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), + &local_shorten_zone); + GNUNET_CRYPTO_short_hash_to_enc (zone, &zonename); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Using shorten zone: %s!\n", &zonename); + GNUNET_CRYPTO_rsa_key_free(key); + GNUNET_free(keyfile); return GNUNET_YES; } diff --git a/src/gns/gnunet-gns.c b/src/gns/gnunet-gns.c index 069dc2121..95733618c 100644 --- a/src/gns/gnunet-gns.c +++ b/src/gns/gnunet-gns.c @@ -152,6 +152,9 @@ run (void *cls, char *const *args, const char *cfgfile, struct GNUNET_CRYPTO_ShortHashCode user_zone; struct GNUNET_CRYPTO_ShortHashAsciiEncoded zonename; struct GNUNET_CRYPTO_RsaPrivateKey *shorten_key = NULL; + struct GNUNET_CRYPTO_RsaPrivateKey *private_key = NULL; + struct GNUNET_CRYPTO_ShortHashCode private_zone; + struct GNUNET_CRYPTO_ShortHashCode shorten_zone; if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns", "ZONEKEY", &keyfile)) @@ -193,10 +196,48 @@ run (void *cls, char *const *args, const char *cfgfile, if (GNUNET_YES == GNUNET_DISK_file_test (keyfile)) { shorten_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile); + GNUNET_CRYPTO_rsa_key_get_public (key, &pkey); + GNUNET_CRYPTO_short_hash(&pkey, + sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), + &shorten_zone); + GNUNET_CRYPTO_short_hash_to_enc (&shorten_zone, &zonename); + if (!raw) + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Using shorten zone: %s!\n", &zonename); + + } + GNUNET_free(keyfile); + } + + + if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns", + "PRIVATE_ZONEKEY", &keyfile)) + { + if (!raw) + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "No private zone key found!\n"); + shorten_key = NULL; + } + else + { + if (GNUNET_YES == GNUNET_DISK_file_test (keyfile)) + { + private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile); + GNUNET_CRYPTO_rsa_key_get_public (key, &pkey); + GNUNET_CRYPTO_short_hash(&pkey, + sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), + &private_zone); + GNUNET_CRYPTO_short_hash_to_enc (&private_zone, &zonename); + if (!raw) + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Using private zone: %s!\n", &zonename); + } GNUNET_free(keyfile); + GNUNET_CRYPTO_rsa_key_free (private_key); } + gns = GNUNET_GNS_connect (cfg); if (lookup_type != NULL) rtype = GNUNET_NAMESTORE_typename_to_number(lookup_type); @@ -214,6 +255,8 @@ run (void *cls, char *const *args, const char *cfgfile, { /** shorten name */ GNUNET_GNS_shorten_zone (gns, shorten_name, + &private_zone, + &shorten_zone, zone, &process_shorten_result, shorten_name); diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c index aac54dafa..879e58a00 100644 --- a/src/gns/gnunet-service-gns.c +++ b/src/gns/gnunet-service-gns.c @@ -51,6 +51,13 @@ */ struct ClientShortenHandle { + + /* DLL */ + struct ClientShortenHandle *next; + + /* DLL */ + struct ClientShortenHandle *prev; + /* the requesting client that */ struct GNUNET_SERVER_Client *client; @@ -60,12 +67,15 @@ struct ClientShortenHandle /* request type */ enum GNUNET_GNS_RecordType type; - /* optional zone private key used for shorten */ - struct GNUNET_CRYPTO_RsaPrivateKey *shorten_key; - /* name to shorten */ char name[MAX_DNS_NAME_LENGTH]; + /* name of private zone (relative to root) */ + char private_zone_id[MAX_DNS_NAME_LENGTH]; + + /* name of shorten zone (relative to root) */ + char shorten_zone_id[MAX_DNS_NAME_LENGTH]; + /* root zone */ struct GNUNET_CRYPTO_ShortHashCode root_zone; @@ -74,6 +84,10 @@ struct ClientShortenHandle /* shorten zone */ struct GNUNET_CRYPTO_ShortHashCode shorten_zone; + + /* Namestore lookup task */ + struct GNUNET_NAMESTORE_QueueEntry *namestore_task; + }; @@ -99,6 +113,7 @@ struct ClientGetAuthHandle */ struct ClientLookupHandle { + /* the requesting client that */ struct GNUNET_SERVER_Client *client; @@ -181,18 +196,28 @@ static int auto_import_pkey; /* lookup timeout */ static struct GNUNET_TIME_Relative default_lookup_timeout; -/* name of the private zone */ -static char *private_zone_id; - -/* name of the public zone */ -static char *shorten_zone_id; - /* ipv6 support */ static int v6_enabled; /* ipv4 support */ static int v4_enabled; +/* Shorten DLL for cancelling NS requests */ +static struct ClientShortenHandle *csh_head; + +/* Shorten DLL for cancelling NS requests */ +static struct ClientShortenHandle *csh_tail; + +/** + * Send shorten response back to client + * + * @param cls the closure containing a client shorten handle + * @param name the shortened name result or NULL if cannot be shortened + */ +static void +send_shorten_response(void* cls, const char* name); + + /** * Continue shutdown */ @@ -214,10 +239,16 @@ on_resolver_cleanup(void) static void shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { + struct ClientShortenHandle *csh_tmp = csh_head; GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Shutting down!"); + while (csh_tmp != NULL) + { + GNUNET_CONTAINER_DLL_remove (csh_head, csh_tail, csh_tmp); + send_shorten_response (csh_tmp, csh_tmp->name); + } GNUNET_SERVER_notification_context_destroy (nc); @@ -489,16 +520,24 @@ send_shorten_response(void* cls, const char* name) (const struct GNUNET_MessageHeader *) rmsg, GNUNET_NO); GNUNET_SERVER_receive_done (csh->client, GNUNET_OK); + + if (NULL != csh->namestore_task) + GNUNET_NAMESTORE_cancel (csh->namestore_task); GNUNET_free(rmsg); - GNUNET_free_non_null(csh->shorten_key); GNUNET_free(csh); } +/** + * Lookup the zone infos and shorten name + * + * @param csh the shorten handle + * + */ static void -process_shorten_zone_shorten (void *cls, +process_shorten_in_private_zone_lookup (void *cls, const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *key, struct GNUNET_TIME_Absolute expiration, const char *name, @@ -507,36 +546,55 @@ process_shorten_zone_shorten (void *cls, const struct GNUNET_CRYPTO_RsaSignature *signature) { struct ClientShortenHandle *csh = cls; - struct GNUNET_TIME_Relative remaining_time; - struct GNUNET_TIME_Absolute et; + csh->namestore_task = NULL; + struct GNUNET_CRYPTO_ShortHashCode *szone = &csh->shorten_zone; + struct GNUNET_CRYPTO_ShortHashCode *pzone = &csh->private_zone; + + if (0 == strcmp (csh->private_zone_id, "")) + pzone = NULL; + + if (rd_count == 0) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "No shorten zone in private zone!\n"); - remaining_time = GNUNET_TIME_absolute_get_remaining (expiration); + strcpy (csh->shorten_zone_id, ""); + szone = NULL; - if ((rd_count == 1) && - (remaining_time.rel_value != 0)) + } + else { - GNUNET_break (0 == (rd->flags & GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION)); - et.abs_value = rd->expiration_time; - remaining_time = GNUNET_TIME_absolute_get_remaining (et); - if ((rd->record_type == GNUNET_GNS_RECORD_PKEY) && - (remaining_time.rel_value != 0)) - { - csh->shorten_zone = *((struct GNUNET_CRYPTO_ShortHashCode*)rd->data); - } + + GNUNET_assert (rd_count == 1); + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Shorten zone %s found in private zone %s\n", + name, csh->private_zone_id); + + sprintf (csh->shorten_zone_id, "%s.%s", name, csh->private_zone_id); } + + GNUNET_CONTAINER_DLL_remove (csh_head, csh_tail, csh); + gns_resolver_shorten_name (&csh->root_zone, - &csh->private_zone, - &csh->shorten_zone, + pzone, + szone, csh->name, - private_zone_id, - shorten_zone_id, + csh->private_zone_id, + csh->shorten_zone_id, &send_shorten_response, csh); } +/** + * Lookup the zone infos and shorten name + * + * @param csh the shorten handle + * + */ static void -process_private_zone_shorten (void *cls, +process_shorten_in_root_zone_lookup (void *cls, const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *key, struct GNUNET_TIME_Absolute expiration, const char *name, @@ -544,46 +602,94 @@ process_private_zone_shorten (void *cls, const struct GNUNET_NAMESTORE_RecordData *rd, const struct GNUNET_CRYPTO_RsaSignature *signature) { - struct GNUNET_TIME_Relative remaining_time; struct ClientShortenHandle *csh = cls; - struct GNUNET_TIME_Absolute et; - - remaining_time = GNUNET_TIME_absolute_get_remaining (expiration); + csh->namestore_task = NULL; + struct GNUNET_CRYPTO_ShortHashCode *szone = &csh->shorten_zone; + struct GNUNET_CRYPTO_ShortHashCode *pzone = &csh->private_zone; + + if (0 == strcmp (csh->private_zone_id, "")) + pzone = NULL; - if ((rd_count == 1) && - (remaining_time.rel_value != 0)) + if (rd_count == 0) { - GNUNET_break (0 == (rd->flags & GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION)); - et.abs_value = rd->expiration_time; - remaining_time = GNUNET_TIME_absolute_get_remaining (et); - if ((rd->record_type == GNUNET_GNS_RECORD_PKEY) && - (remaining_time.rel_value != 0)) - { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "No shorten zone in zone and no private zone!\n"); + strcpy (csh->shorten_zone_id, ""); - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Looking for shorten zone in private zone\n"); - csh->private_zone = *((struct GNUNET_CRYPTO_ShortHashCode*)rd->data); - GNUNET_NAMESTORE_lookup_record (namestore_handle, - &csh->private_zone, - shorten_zone_id, - GNUNET_GNS_RECORD_ANY, - &process_shorten_zone_shorten, - cls); - } + GNUNET_CONTAINER_DLL_remove (csh_head, csh_tail, csh); + szone = NULL; + + gns_resolver_shorten_name (&csh->root_zone, + pzone, + szone, + csh->name, + csh->private_zone_id, + csh->shorten_zone_id, + &send_shorten_response, csh); return; } - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "No private zone found!\n"); - gns_resolver_shorten_name (&csh->root_zone, - &csh->private_zone, - &csh->shorten_zone, - csh->name, - private_zone_id, - shorten_zone_id, - &send_shorten_response, csh); + GNUNET_assert (rd_count == 1); + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Private zone %s found in root zone\n", name); + + strcpy (csh->private_zone_id, name); + + csh->namestore_task = GNUNET_NAMESTORE_zone_to_name (namestore_handle, + pzone, + szone, + &process_shorten_in_private_zone_lookup, + csh); +} + + +/** + * Lookup the zone infos and shorten name + * + * @param csh the shorten handle + * + */ +static void +process_private_in_root_zone_lookup (void *cls, + const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *key, + struct GNUNET_TIME_Absolute expiration, + const char *name, + unsigned int rd_count, + const struct GNUNET_NAMESTORE_RecordData *rd, + const struct GNUNET_CRYPTO_RsaSignature *signature) +{ + struct ClientShortenHandle *csh = cls; + csh->namestore_task = NULL; + + if (rd_count == 0) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "No private zone in root zone\n"); + + strcpy (csh->private_zone_id, ""); + + csh->namestore_task = GNUNET_NAMESTORE_zone_to_name (namestore_handle, + &csh->root_zone, + &csh->shorten_zone, + &process_shorten_in_root_zone_lookup, + csh); + return; + } + + GNUNET_assert (rd_count == 1); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Private zone %s found in root zone\n", name); + + strcpy (csh->private_zone_id, name); + + csh->namestore_task = GNUNET_NAMESTORE_zone_to_name (namestore_handle, + &csh->private_zone, + &csh->shorten_zone, + &process_shorten_in_private_zone_lookup, + csh); } /** @@ -596,13 +702,12 @@ static void start_shorten_name (struct ClientShortenHandle *csh) { GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Looking for private zone in root zone\n"); + "Looking for private zone name in root zone\n"); - GNUNET_NAMESTORE_lookup_record (namestore_handle, + csh->namestore_task = GNUNET_NAMESTORE_zone_to_name (namestore_handle, &csh->root_zone, - private_zone_id, - GNUNET_GNS_RECORD_ANY, - &process_private_zone_shorten, + &csh->private_zone, + &process_private_in_root_zone_lookup, csh); } @@ -648,7 +753,8 @@ static void handle_shorten (void *cls, csh = GNUNET_malloc(sizeof(struct ClientShortenHandle)); csh->client = client; csh->unique_id = sh_msg->id; - csh->shorten_key = NULL; + + GNUNET_CONTAINER_DLL_insert (csh_head, csh_tail, csh); GNUNET_STRINGS_utf8_tolower((char*)&sh_msg[1], &nameptr); @@ -674,6 +780,9 @@ static void handle_shorten (void *cls, return; } + csh->shorten_zone = sh_msg->shorten_zone; + csh->private_zone = sh_msg->private_zone; + strcpy (csh->name, name); GNUNET_SERVER_notification_context_add (nc, client); @@ -1099,22 +1208,6 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, } - if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (c, "gns", - "PRIVATE_ZONE", - &private_zone_id)) - { - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Private zone id: %s\n", private_zone_id); - } - - if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (c, "gns", - "SHORTEN_ZONE", - &shorten_zone_id)) - { - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Shorten zone id: %s\n", shorten_zone_id); - } - dht_max_update_interval = GNUNET_GNS_DHT_MAX_UPDATE_INTERVAL; if (GNUNET_OK == diff --git a/src/gns/gnunet-service-gns_resolver.c b/src/gns/gnunet-service-gns_resolver.c index 5b54cf576..f17ff7135 100644 --- a/src/gns/gnunet-service-gns_resolver.c +++ b/src/gns/gnunet-service-gns_resolver.c @@ -3726,22 +3726,20 @@ process_zone_to_name_shorten_shorten (void *cls, /* we found a match in our own root zone */ if (rd_len != 0) { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "result strlen %d\n", strlen(name)); answer_len = strlen(rh->name) + strlen(name) + strlen(GNUNET_GNS_TLD) + 3; memset(result, 0, answer_len); if (strlen(rh->name) > 0) { - sprintf (result, "%s.%s.%s.%s.%s", + sprintf (result, "%s.%s.%s.%s", rh->name, name, - nsh->shorten_zone_name, nsh->private_zone_name, + nsh->shorten_zone_name, GNUNET_GNS_TLD); } else { - sprintf (result, "%s.%s.%s.%s", name, - nsh->shorten_zone_name, nsh->private_zone_name, + sprintf (result, "%s.%s.%s", name, + nsh->shorten_zone_name, GNUNET_GNS_TLD); } @@ -3759,9 +3757,9 @@ process_zone_to_name_shorten_shorten (void *cls, * shorten to our zone to a "" record??) */ - sprintf (result, "%s.%s.%s.%s", + sprintf (result, "%s.%s.%s", rh->name, - nsh->shorten_zone_name, nsh->private_zone_name, + nsh->shorten_zone_name, GNUNET_GNS_TLD); GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Our zone: Found %s as shorten result\n", result); @@ -3840,8 +3838,6 @@ process_zone_to_name_shorten_private (void *cls, /* we found a match in our own root zone */ if (rd_len != 0) { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "result strlen %d\n", strlen(name)); answer_len = strlen(rh->name) + strlen(name) + strlen(GNUNET_GNS_TLD) + 3; memset(result, 0, answer_len); @@ -3876,7 +3872,7 @@ process_zone_to_name_shorten_private (void *cls, strcpy (nsh->result, result); } - if (nsh->shorten_zone != NULL) + if (0 != strcmp (nsh->shorten_zone_name, "")) { /* backtrack authorities for names in priv zone */ rh->namestore_task = GNUNET_NAMESTORE_zone_to_name (namestore_handle, @@ -3953,8 +3949,6 @@ process_zone_to_name_shorten_root (void *cls, /* we found a match in our own root zone */ if (rd_len != 0) { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "result strlen %d\n", strlen(name)); answer_len = strlen(rh->name) + strlen(name) + strlen(GNUNET_GNS_TLD) + 3; memset(result, 0, answer_len); @@ -3988,7 +3982,7 @@ process_zone_to_name_shorten_root (void *cls, strcpy (nsh->result, result); } - if (nsh->private_zone != NULL) + if (0 != strcmp (nsh->private_zone_name, "")) { /* backtrack authorities for names in priv zone */ rh->namestore_task = GNUNET_NAMESTORE_zone_to_name (namestore_handle, @@ -3997,6 +3991,15 @@ process_zone_to_name_shorten_root (void *cls, &process_zone_to_name_shorten_private, rh); } + else if (0 != strcmp (nsh->shorten_zone_name, "")) + { + /* backtrack authorities for names in shorten zone */ + rh->namestore_task = GNUNET_NAMESTORE_zone_to_name (namestore_handle, + nsh->shorten_zone, + &rh->authority_chain_head->zone, + &process_zone_to_name_shorten_shorten, + rh); + } else { /** @@ -4089,14 +4092,18 @@ handle_delegation_ns_shorten (void* cls, * (it shouldn't be, usually FIXME what happens if we * shorten to our zone to a "" record??) */ + if (0 != strcmp (nsh->private_zone_name, "")) + { - sprintf (result, "%s.%s.%s", - rh->name, nsh->private_zone_name, GNUNET_GNS_TLD); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Our zone: Found %s as shorten result %s\n", result); + sprintf (result, "%s.%s.%s", + rh->name, nsh->private_zone_name, GNUNET_GNS_TLD); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Our zone: Found %s as shorten result in private zone %s\n", + result); - if (strlen (nsh->result) > strlen (result)) - strcpy (nsh->result, result); + if (strlen (nsh->result) > strlen (result)) + strcpy (nsh->result, result); + } } else if (GNUNET_CRYPTO_short_hash_cmp(&rh->authority_chain_head->zone, nsh->shorten_zone) == 0) @@ -4106,14 +4113,17 @@ handle_delegation_ns_shorten (void* cls, * (it shouldn't be, usually FIXME what happens if we * shorten to our zone to a "" record??) */ + if (0 != strcmp (nsh->shorten_zone_name, "")) + { + sprintf (result, "%s.%s.%s", + rh->name, nsh->private_zone_name, GNUNET_GNS_TLD); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Our zone: Found %s as shorten result in shorten zone\n", + result); - sprintf (result, "%s.%s.%s", - rh->name, nsh->private_zone_name, GNUNET_GNS_TLD); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Our zone: Found %s as shorten result\n", result); - - if (strlen (nsh->result) > strlen (result)) - strcpy (nsh->result, result); + if (strlen (nsh->result) > strlen (result)) + strcpy (nsh->result, result); + } } diff --git a/src/gns/test_gns_pseu_shorten.c b/src/gns/test_gns_pseu_shorten.c index 6944aff03..f3a3c59a2 100644 --- a/src/gns/test_gns_pseu_shorten.c +++ b/src/gns/test_gns_pseu_shorten.c @@ -173,9 +173,11 @@ static void do_shorten(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { GNUNET_GNS_shorten_zone (gns_handle, TEST_DOMAIN, - &our_zone, - &process_shorten_result, - TEST_DOMAIN); + &priv_zone, + &short_zone, + &our_zone, + &process_shorten_result, + TEST_DOMAIN); } static void diff --git a/src/include/gnunet_gns_service.h b/src/include/gnunet_gns_service.h index c2d642aed..5921d9370 100644 --- a/src/include/gnunet_gns_service.h +++ b/src/include/gnunet_gns_service.h @@ -190,6 +190,8 @@ typedef void (*GNUNET_GNS_ShortenResultProcessor) (void *cls, * * @param handle handle to the GNS service * @param name the name to look up + * @param private_zone the public zone of the private zone + * @param shorten_zone the public zone of the shorten zone * @param proc function to call on result * @param proc_cls closure for processor * @return handle to the operation @@ -197,6 +199,8 @@ typedef void (*GNUNET_GNS_ShortenResultProcessor) (void *cls, struct GNUNET_GNS_QueueEntry * GNUNET_GNS_shorten (struct GNUNET_GNS_Handle *handle, const char * name, + struct GNUNET_CRYPTO_ShortHashCode *private_zone, + struct GNUNET_CRYPTO_ShortHashCode *shorten_zone, GNUNET_GNS_ShortenResultProcessor proc, void *proc_cls); @@ -206,6 +210,8 @@ GNUNET_GNS_shorten (struct GNUNET_GNS_Handle *handle, * * @param handle handle to the GNS service * @param name the name to look up + * @param private_zone the public zone of the private zone + * @param shorten_zone the public zone of the shorten zone * @param zone the zone to start the resolution in * @param proc function to call on result * @param proc_cls closure for processor @@ -213,10 +219,12 @@ GNUNET_GNS_shorten (struct GNUNET_GNS_Handle *handle, */ struct GNUNET_GNS_QueueEntry * GNUNET_GNS_shorten_zone (struct GNUNET_GNS_Handle *handle, - const char * name, - struct GNUNET_CRYPTO_ShortHashCode *zone, - GNUNET_GNS_ShortenResultProcessor proc, - void *proc_cls); + const char * name, + struct GNUNET_CRYPTO_ShortHashCode *private_zone, + struct GNUNET_CRYPTO_ShortHashCode *shorten_zone, + struct GNUNET_CRYPTO_ShortHashCode *zone, + GNUNET_GNS_ShortenResultProcessor proc, + void *proc_cls); /* *************** Standard API: get authority ******************* */ -- 2.25.1