From: Christian Grothoff Date: Wed, 22 Feb 2017 20:42:42 +0000 (+0100) Subject: remove dead code and dead linker dependencies X-Git-Tag: taler-0.2.1~74 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=945443b67fe95893ceb711e1bcd7049477f3cba7;p=oweals%2Fgnunet.git remove dead code and dead linker dependencies --- diff --git a/src/gns/Makefile.am b/src/gns/Makefile.am index 3afad8ea7..8c952be04 100644 --- a/src/gns/Makefile.am +++ b/src/gns/Makefile.am @@ -113,7 +113,6 @@ gnunet_gns_SOURCES = \ gnunet_gns_LDADD = \ libgnunetgns.la \ $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ - $(top_builddir)/src/namestore/libgnunetnamestore.la \ $(top_builddir)/src/identity/libgnunetidentity.la \ $(top_builddir)/src/util/libgnunetutil.la \ $(GN_LIBINTL) @@ -133,7 +132,6 @@ gnunet_dns2gns_LDADD = \ libgnunetgns.la \ $(top_builddir)/src/util/libgnunetutil.la \ $(top_builddir)/src/identity/libgnunetidentity.la \ - $(top_builddir)/src/namestore/libgnunetnamestore.la \ $(top_builddir)/src/dns/libgnunetdnsparser.la \ $(top_builddir)/src/dns/libgnunetdnsstub.la \ $(GN_LIBINTL) @@ -197,7 +195,6 @@ gnunet_service_gns_LDADD = \ $(top_builddir)/src/dht/libgnunetdht.la \ $(top_builddir)/src/tun/libgnunettun.la \ $(top_builddir)/src/namecache/libgnunetnamecache.la \ - $(top_builddir)/src/namestore/libgnunetnamestore.la \ $(USE_VPN) \ $(GN_LIBINTL) diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c index 1e8d07bc5..570c07fdf 100644 --- a/src/gns/gnunet-service-gns.c +++ b/src/gns/gnunet-service-gns.c @@ -29,14 +29,11 @@ #include "gnunet_dnsparser_lib.h" #include "gnunet_dht_service.h" #include "gnunet_namecache_service.h" -#include "gnunet_namestore_service.h" #include "gnunet_identity_service.h" #include "gnunet_gns_service.h" #include "gnunet_statistics_service.h" #include "gns.h" #include "gnunet-service-gns_resolver.h" -#include "gnunet-service-gns_reverser.h" -#include "gnunet-service-gns_shorten.h" #include "gnunet-service-gns_interceptor.h" #include "gnunet_protocols.h" @@ -113,11 +110,6 @@ static struct GNUNET_DHT_Handle *dht_handle; */ static struct GNUNET_NAMECACHE_Handle *namecache_handle; -/** - * Our handle to the namestore service - */ -static struct GNUNET_NAMESTORE_Handle *namestore_handle; - /** * Our handle to the identity service */ @@ -174,11 +166,6 @@ shutdown_task (void *cls) GNUNET_NO); statistics = NULL; } - if (NULL != namestore_handle) - { - GNUNET_NAMESTORE_disconnect (namestore_handle); - namestore_handle = NULL; - } if (NULL != namecache_handle) { GNUNET_NAMECACHE_disconnect (namecache_handle); @@ -447,15 +434,7 @@ run (void *cls, v6_enabled = GNUNET_NETWORK_test_pf (PF_INET6); v4_enabled = GNUNET_NETWORK_test_pf (PF_INET); - namestore_handle = GNUNET_NAMESTORE_connect (c); - if (NULL == namestore_handle) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("Failed to connect to the namestore!\n")); - GNUNET_SCHEDULER_shutdown (); - return; - } - namecache_handle = GNUNET_NAMECACHE_connect (c); + namecache_handle = GNUNET_NAMECACHE_connect (c); if (NULL == namecache_handle) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, diff --git a/src/gns/gnunet-service-gns_resolver.c b/src/gns/gnunet-service-gns_resolver.c index 40b340ad7..c58190599 100644 --- a/src/gns/gnunet-service-gns_resolver.c +++ b/src/gns/gnunet-service-gns_resolver.c @@ -30,7 +30,6 @@ #include "gnunet_dht_service.h" #include "gnunet_gnsrecord_lib.h" #include "gnunet_namecache_service.h" -#include "gnunet_namestore_service.h" #include "gnunet_dns_service.h" #include "gnunet_resolver_service.h" #include "gnunet_revocation_service.h" @@ -39,7 +38,6 @@ #include "gnunet_gns_service.h" #include "gns.h" #include "gnunet-service-gns_resolver.h" -#include "gnunet-service-gns_shorten.h" #include "gnunet_vpn_service.h" diff --git a/src/gns/gnunet-service-gns_reverser.c b/src/gns/gnunet-service-gns_reverser.c deleted file mode 100644 index b5b8b31b7..000000000 --- a/src/gns/gnunet-service-gns_reverser.c +++ /dev/null @@ -1,601 +0,0 @@ -/* - This file is part of GNUnet. - Copyright (C) 2009-2013 GNUnet e.V. - - GNUnet is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3, or (at your - option) any later version. - - GNUnet is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with GNUnet; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ -/** - * @file gns/gnunet-service-gns_reverser.c - * @brief GNUnet GNS service - * @author Martin Schanzenbach - */ - - -#include "platform.h" -#include "gnunet_gns_service.h" -#include "gnunet-service-gns_resolver.h" -#include "gnunet-service-gns_reverser.h" - -struct ReverseRecordEntry -{ - /** - * DLL - */ - struct ReverseRecordEntry *next; - - /** - * DLL - */ - struct ReverseRecordEntry *prev; - - /** - * ReverseRecord - */ - struct GNUNET_GNSRECORD_ReverseRecord *record; - - /** - * Record length - */ - size_t record_len; - -}; - -struct IteratorHandle -{ - /** - * Records found - */ - struct ReverseRecordEntry *records_head; - - /** - * Records found - */ - struct ReverseRecordEntry *records_tail; - - /** - * Record count - */ - uint64_t record_count; - - /** - * Current delegation to expect - */ - struct GNUNET_CRYPTO_EcdsaPublicKey target; - - /** - * Queue entry - */ - struct GNUNET_NAMESTORE_QueueEntry *ns_qe; - -}; - -struct ReverseTreeNode -{ - /** - * DLL - */ - struct ReverseTreeNode *next; - - /** - * DLL - */ - struct ReverseTreeNode *prev; - - /** - * Resolved name until now - */ - char *name; - - /** - * Depth of the resolution at this node - */ - uint8_t depth; - - /** - * The pkey of the namespace - */ - struct GNUNET_CRYPTO_EcdsaPublicKey pkey; - -}; - - -struct GNS_ReverserHandle -{ - /** - * GNS resolver handle - */ - struct GNS_ResolverHandle *rh; - - /** - * The authority to look for - */ - struct GNUNET_CRYPTO_EcdsaPublicKey authority; - - /** - * Resolution candidate queue - */ - struct ReverseTreeNode *node_queue_head; - - /** - * Resolution candidate queue - */ - struct ReverseTreeNode *node_queue_tail; - - /** - * Max depth for the resolution - */ - uint8_t max_depth; - - /** - * Result callback - */ - GNS_ReverseResultProcessor proc; - - /** - * Callback closure - */ - void *proc_cls; -}; - -/** - * Reverse record collection task - */ -static struct GNUNET_SCHEDULER_Task *reverse_record_check_task; - -/** - * NS iterator task - */ -static struct GNUNET_SCHEDULER_Task *it_task; - -/** - * GNS lookup handle - */ -static struct GNS_ResolverHandle *gns_lookup_reverse; - -/** - * NS handle - */ -static struct GNUNET_NAMESTORE_Handle *ns; - -/** - * NS Iterator - */ -static struct GNUNET_NAMESTORE_ZoneIterator *namestore_iter; - -/** - * The zone target for reverse record resolution - */ -static struct GNUNET_CRYPTO_EcdsaPublicKey myzone; - -/** - * The zone target for reverse record resolution - */ -static struct GNUNET_CRYPTO_EcdsaPrivateKey pzone; - -/** - * The nick of our zone - */ -static char *mynick; - - -static void -cleanup_handle (struct GNS_ReverserHandle *rh) -{ - struct ReverseTreeNode *rtn; - - for (rtn = rh->node_queue_head; NULL != rtn; rtn = rh->node_queue_head) - { - if (NULL != rtn->name) - GNUNET_free (rtn->name); - GNUNET_CONTAINER_DLL_remove (rh->node_queue_head, - rh->node_queue_tail, - rtn); - GNUNET_free (rtn); - } - GNUNET_free (rh); -} - -static void -handle_gns_result (void *cls, - uint32_t rd_count, - const struct GNUNET_GNSRECORD_Data *rd) -{ - struct GNS_ReverserHandle *rh = cls; - const struct GNUNET_GNSRECORD_ReverseRecord *rr; - struct ReverseTreeNode *rtn; - char *result; - const char *name; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Got result (%d)\n", rd_count); - - for (int i = 0; i < rd_count; i++) - { - /** - * Check if we are in the delegation set - */ - if (GNUNET_GNSRECORD_TYPE_REVERSE != rd[i].record_type) - continue; - rr = rd[i].data; - name = (const char*) &rr[1]; - if (0 == memcmp (&rh->authority, - &rr->pkey, - sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))) - { - //Found! - GNUNET_asprintf (&result, - "%s.%s.gnu", - rh->node_queue_head->name, - name); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Found path from %s\n", result); - - rh->proc (rh->proc_cls, result); - cleanup_handle (rh); - GNUNET_free (result); - return; - } else { - if (rh->node_queue_head->depth >= rh->max_depth) - break; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Found REVERSE from %s\n", name); - - rtn = GNUNET_new (struct ReverseTreeNode); - if (NULL == rh->node_queue_head->name) - rtn->name = GNUNET_strdup (name); - else - GNUNET_asprintf (&rtn->name, - "%s.%s", - rh->node_queue_head->name, - name); - rtn->depth = rh->node_queue_head->depth + 1; - rtn->pkey = rr->pkey; - GNUNET_CONTAINER_DLL_insert_tail (rh->node_queue_head, - rh->node_queue_tail, - rtn); - } - } - - /** - * Done here remove node from queue - */ - rtn = rh->node_queue_head; - if (NULL != rtn) - GNUNET_CONTAINER_DLL_remove (rh->node_queue_head, - rh->node_queue_tail, - rtn); - if (NULL == rh->node_queue_head) - { - //No luck - rh->proc (rh->proc_cls, NULL); - cleanup_handle (rh); - return; - } - rh->rh = GNS_resolver_lookup (&rh->node_queue_head->pkey, - GNUNET_GNSRECORD_TYPE_REVERSE, - "+.gnu", - NULL, - GNUNET_GNS_LO_DEFAULT, - &handle_gns_result, - rh); -} - -/** - * Reverse lookup of a specific zone - * calls RecordLookupProcessor on result or timeout - * - * @param target the zone to perform the lookup in - * @param authority the authority - * @param proc the processor to call - * @param proc_cls the closure to pass to @a proc - * @return handle to cancel operation - */ -struct GNS_ReverserHandle * -GNS_reverse_lookup (const struct GNUNET_CRYPTO_EcdsaPublicKey *target, - const struct GNUNET_CRYPTO_EcdsaPublicKey *authority, - GNS_ReverseResultProcessor proc, - void *proc_cls) -{ - struct GNS_ReverserHandle *rh; - struct ReverseTreeNode *rtn; - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Starting reverse resolution\n"); - rh = GNUNET_new (struct GNS_ReverserHandle); - rh->proc = proc; - rh->proc_cls = proc_cls; - rtn = GNUNET_new (struct ReverseTreeNode); - rtn->name = NULL; - rtn->pkey = *target; - rtn->depth = 0; - GNUNET_CONTAINER_DLL_insert (rh->node_queue_head, - rh->node_queue_tail, - rtn); - rh->authority = *authority; - rh->max_depth = 3; //TODO make argument - rh->rh = GNS_resolver_lookup (target, - GNUNET_GNSRECORD_TYPE_REVERSE, - "+.gnu", - NULL, - GNUNET_GNS_LO_DEFAULT, - &handle_gns_result, - rh); - return rh; -} - -/** - * Cancel active resolution (i.e. client disconnected). - * - * @param rh resolution to abort - */ -void -GNS_reverse_lookup_cancel (struct GNS_ReverserHandle *rh) -{ - cleanup_handle (rh); - return; -} - -/******************************************** - * Reverse iterator - * ******************************************/ - - -static void -next_it (void *cls); - -static void -handle_gns_result_iter (void *cls, - uint32_t rd_count, - const struct GNUNET_GNSRECORD_Data *rd) -{ - struct IteratorHandle *ith = cls; - struct ReverseRecordEntry *rr; - gns_lookup_reverse = NULL; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "GNS for REVERSE (%s)\n", mynick); - - - if ((rd_count != 1) || - (GNUNET_GNSRECORD_TYPE_PKEY != rd->record_type)) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "GNS invalid REVERSE (%s)\n", mynick); - gns_lookup_reverse = NULL; - it_task = GNUNET_SCHEDULER_add_now (&next_it, ith); - return; - } - - - rr = GNUNET_new (struct ReverseRecordEntry); - rr->record_len = sizeof (struct GNUNET_GNSRECORD_ReverseRecord) - + strlen (mynick) + 1; - rr->record = GNUNET_malloc (rr->record_len); - rr->record->pkey = ith->target; - rr->record->expiration.abs_value_us = rd->expiration_time; - GNUNET_memcpy ((char*)&rr->record[1], - mynick, - strlen (mynick)); - GNUNET_CONTAINER_DLL_insert (ith->records_head, - ith->records_tail, - rr); - ith->record_count++; - it_task = GNUNET_SCHEDULER_add_now (&next_it, ith); -} - - -static void -next_it (void *cls) -{ - it_task = NULL; - GNUNET_assert (NULL != namestore_iter); - GNUNET_NAMESTORE_zone_iterator_next (namestore_iter); -} - - -static void -iterator_cb (void *cls, - const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, - const char *label, - unsigned int rd_count, - const struct GNUNET_GNSRECORD_Data *rd) -{ - struct IteratorHandle *ith = cls; - struct GNUNET_CRYPTO_EcdsaPublicKey zone; - char *name; - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "iterating for REVERSE (%s / %s)\n", - label, - mynick); - - - if ((rd_count != 1) || - (GNUNET_GNSRECORD_TYPE_PKEY != rd->record_type)) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "wrong format (%s)\n", mynick); - - - it_task = GNUNET_SCHEDULER_add_now (&next_it, ith); - return; - } - GNUNET_CRYPTO_ecdsa_key_get_public (key, - &zone); - if (0 != memcmp (&zone, &myzone, - sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "wrong zone (%s)\n", mynick); - - - it_task = GNUNET_SCHEDULER_add_now (&next_it, ith); - return; - } - ith->target = *((struct GNUNET_CRYPTO_EcdsaPublicKey *) rd->data); - GNUNET_asprintf (&name, - "%s.gnu", - mynick); - gns_lookup_reverse = GNS_resolver_lookup (&ith->target, - GNUNET_GNSRECORD_TYPE_PKEY, - name, - NULL, - GNUNET_GNS_LO_DEFAULT, - &handle_gns_result_iter, - ith); - GNUNET_free (name); -} - -static void check_reverse_records (void *cls); - -static void -store_reverse (void *cls, - int32_t success, - const char *emsg) -{ - struct IteratorHandle *ith = cls; - struct ReverseRecordEntry *rr; - - if (GNUNET_SYSERR == success) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "%s\n", - emsg); - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stored records (%s)\n", mynick); - - for (rr = ith->records_head; NULL != rr; rr = ith->records_head) - { - GNUNET_CONTAINER_DLL_remove (ith->records_head, - ith->records_tail, - rr); - GNUNET_free (rr->record); - GNUNET_free (rr); - } - reverse_record_check_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_DAYS, - &check_reverse_records, - NULL); - GNUNET_free (ith); -} - - -static void -finished_cb (void *cls) -{ - struct IteratorHandle *ith = cls; - struct ReverseRecordEntry *rr; - struct GNUNET_GNSRECORD_Data rd[ith->record_count]; - - memset (rd, 0, sizeof (struct GNUNET_GNSRECORD_Data) * ith->record_count); - - rr = ith->records_head; - for (int i = 0; i < ith->record_count; i++) - { - rd[i].data_size = rr->record_len; - rd[i].data = GNUNET_malloc (rr->record_len); - rd[i].record_type = GNUNET_GNSRECORD_TYPE_REVERSE; - rd[i].expiration_time = rr->record->expiration.abs_value_us; - GNUNET_memcpy ((char*) rd[i].data, - rr->record, - rr->record_len); - rr = rr->next; - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Finished iterating for REVERSE\n"); - - ith->ns_qe = GNUNET_NAMESTORE_records_store (ns, - &pzone, - "+", - ith->record_count, - rd, - &store_reverse, - ith); - namestore_iter = NULL; - -} - - -static void -it_error (void *cls) -{ - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Error iterating for REVERSE\n"); -} - - -static void -check_reverse_records (void *cls) -{ - struct IteratorHandle *ith; - ith = GNUNET_new (struct IteratorHandle); - ith->record_count = 0; - reverse_record_check_task = NULL; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Start iterating for REVERSE (%s)\n", mynick); - namestore_iter = GNUNET_NAMESTORE_zone_iteration_start (ns, - NULL, - &it_error, - ith, - &iterator_cb, - ith, - &finished_cb, - ith); -} - - -/** - * Initialize reverser - * - * @param nh handle to a namestore - * @param key the private key of the gns-reverse zone - * @param name the name of the gns-reverse zone - * @return GNUNET_OK - */ -int -GNS_reverse_init (struct GNUNET_NAMESTORE_Handle *nh, - const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, - const char *nick) -{ - GNUNET_asprintf (&mynick, - "%s", - nick); - GNUNET_CRYPTO_ecdsa_key_get_public (zone, - &myzone); - GNUNET_memcpy (&pzone, - zone, - sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)); - ns = nh; - reverse_record_check_task = GNUNET_SCHEDULER_add_now (&check_reverse_records, - NULL); - return GNUNET_OK; -} - -/** - * Cleanup reverser - */ -void -GNS_reverse_done () -{ - if (NULL != mynick) - GNUNET_free (mynick); - if (NULL != it_task) - GNUNET_SCHEDULER_cancel (it_task); - if (NULL != reverse_record_check_task) - GNUNET_SCHEDULER_cancel (reverse_record_check_task); - if (NULL != gns_lookup_reverse) - GNS_resolver_lookup_cancel (gns_lookup_reverse); - if (NULL != namestore_iter) - GNUNET_NAMESTORE_zone_iteration_stop (namestore_iter); -} - diff --git a/src/gns/gnunet-service-gns_reverser.h b/src/gns/gnunet-service-gns_reverser.h deleted file mode 100644 index fc9680a29..000000000 --- a/src/gns/gnunet-service-gns_reverser.h +++ /dev/null @@ -1,91 +0,0 @@ -/* - This file is part of GNUnet. - Copyright (C) 2009-2013 GNUnet e.V. - - GNUnet is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3, or (at your - option) any later version. - - GNUnet is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with GNUnet; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ -/** - * @file gns/gnunet-service-gns_reverser.h - * @brief GNUnet GNS service - * @author Martin Schanzenbach - */ -#ifndef GNS_REVERSER_H -#define GNS_REVERSER_H -#include "gns.h" -#include "gnunet_gns_service.h" - -/** - * Handle for an active request. - */ -struct GNS_ReverserHandle; - - -/** - * Function called with results for a GNS resolution. - * - * @param cls closure - * @param rd_count number of records in @a rd - * @param rd records returned for the lookup - */ -typedef void (*GNS_ReverseResultProcessor)(void *cls, - const char *name); - - -/** - * Reverse lookup of a specific zone - * calls RecordLookupProcessor on result or timeout - * - * @param target the zone to perform the lookup in - * @param authority the authority - * @param proc the processor to call - * @param proc_cls the closure to pass to @a proc - * @return handle to cancel operation - */ -struct GNS_ReverserHandle * -GNS_reverse_lookup (const struct GNUNET_CRYPTO_EcdsaPublicKey *target, - const struct GNUNET_CRYPTO_EcdsaPublicKey *authority, - GNS_ReverseResultProcessor proc, - void *proc_cls); - - -/** - * Cancel active resolution (i.e. client disconnected). - * - * @param rh resolution to abort - */ -void -GNS_reverse_lookup_cancel (struct GNS_ReverserHandle *rh); - -/** - * Initialize reverser - * - * @param nh handle to a namestore - * @param key the private key of the gns-reverse zone - * @param name the name of the gns-reverse zone - * @return GNUNET_OK - */ -int -GNS_reverse_init (struct GNUNET_NAMESTORE_Handle *nh, - const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, - const char *name); - -/** - * Cleanup reverser - */ -void -GNS_reverse_done (); - -#endif diff --git a/src/gns/gnunet-service-gns_shorten.c b/src/gns/gnunet-service-gns_shorten.c deleted file mode 100644 index 9aa0419aa..000000000 --- a/src/gns/gnunet-service-gns_shorten.c +++ /dev/null @@ -1,466 +0,0 @@ -/* - This file is part of GNUnet. - Copyright (C) 2011-2013 GNUnet e.V. - - GNUnet is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3, or (at your - option) any later version. - - GNUnet is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with GNUnet; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -/** - * @file gns/gnunet-service-gns_shorten.c - * @brief GNUnet GNS shortening logic - * @author Martin Schanzenbach - * @author Christian Grothoff - */ -#include "platform.h" -#include "gnunet_util_lib.h" -#include "gnunet_dht_service.h" -#include "gnunet_gnsrecord_lib.h" -#include "gnunet_namestore_service.h" -#include "gnunet_resolver_service.h" -#include "gnunet_gns_service.h" -#include "gns.h" -#include "gnunet-service-gns_shorten.h" -#include "gnunet_vpn_service.h" - - -/** - * Default DHT timeout for lookups. - */ -#define DHT_LOOKUP_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) - -/** - * DHT replication level - */ -#define DHT_GNS_REPLICATION_LEVEL 5 - - -/** - * Handle for a PSEU lookup used to shorten names. - */ -struct GetPseuAuthorityHandle -{ - /** - * DLL - */ - struct GetPseuAuthorityHandle *next; - - /** - * DLL - */ - struct GetPseuAuthorityHandle *prev; - - /** - * Private key of the (shorten) zone to store the resulting - * pseudonym in. - */ - struct GNUNET_CRYPTO_EcdsaPrivateKey shorten_zone_key; - - /** - * Original label (used if no PSEU record is found). - */ - char label[GNUNET_DNSPARSER_MAX_LABEL_LENGTH + 1]; - - /** - * Suggested label based on NICK record - */ - char * suggested_label; - - /** - * Label we are currently trying out - */ - char *current_label; - - /** - * The zone for which we are trying to find the PSEU record. - */ - struct GNUNET_CRYPTO_EcdsaPublicKey target_zone; - - /** - * Handle for DHT lookups. Should be NULL if no lookups are in progress - */ - struct GNUNET_DHT_GetHandle *get_handle; - - /** - * Handle to namestore request - */ - struct GNUNET_NAMESTORE_QueueEntry *namestore_task; - - /** - * Handle to namecache request - */ - struct GNUNET_NAMECACHE_QueueEntry *namecache_task; - - /** - * Task to abort DHT lookup operation. - */ - struct GNUNET_SCHEDULER_Task * timeout_task; - -}; - - -/** - * Head of PSEU/shorten operations list. - */ -static struct GetPseuAuthorityHandle *gph_head; - -/** - * Tail of PSEU/shorten operations list. - */ -static struct GetPseuAuthorityHandle *gph_tail; - -/** - * Our handle to the namestore service - */ -static struct GNUNET_NAMESTORE_Handle *namestore_handle; - -/** - * Our handle to the namecache service - */ -static struct GNUNET_NAMECACHE_Handle *namecache_handle; - -/** - * Resolver handle to the dht - */ -static struct GNUNET_DHT_Handle *dht_handle; - -/** - * Cleanup a 'struct GetPseuAuthorityHandle', terminating all - * pending activities. - * - * @param gph handle to terminate - */ -static void -free_get_pseu_authority_handle (struct GetPseuAuthorityHandle *gph) -{ - if (NULL != gph->get_handle) - { - GNUNET_DHT_get_stop (gph->get_handle); - gph->get_handle = NULL; - } - if (NULL != gph->namestore_task) - { - GNUNET_NAMESTORE_cancel (gph->namestore_task); - gph->namestore_task = NULL; - } - if (NULL != gph->namecache_task) - { - GNUNET_NAMECACHE_cancel (gph->namecache_task); - gph->namecache_task = NULL; - } - if (NULL != gph->timeout_task) - { - GNUNET_SCHEDULER_cancel (gph->timeout_task); - gph->timeout_task = NULL; - } - GNUNET_CONTAINER_DLL_remove (gph_head, gph_tail, gph); - GNUNET_free_non_null (gph->current_label); - GNUNET_free (gph); -} - - -/** - * Continuation for pkey record creation (shorten) - * - * @param cls a GetPseuAuthorityHandle - * @param success unused - * @param emsg unused - */ -static void -create_pkey_cont (void* cls, - int32_t success, - const char *emsg) -{ - struct GetPseuAuthorityHandle* gph = cls; - - gph->namestore_task = NULL; - free_get_pseu_authority_handle (gph); -} - - -/** - * Namestore calls this function if we have record for this name. - * (or with rd_count=0 to indicate no matches). - * - * @param cls the pending query - * @param rd_count the number of records with 'name' - * @param rd the record data - */ -static void -process_pseu_lookup_ns (void *cls, - unsigned int rd_count, - const struct GNUNET_GNSRECORD_Data *rd); - - -/** - * We obtained a result for our query to the shorten zone from - * the namestore. Try to decrypt. - * - * @param cls the handle to our shorten operation - * @param block resulting encrypted block - */ -static void -process_pseu_block_ns (void *cls, - const struct GNUNET_GNSRECORD_Block *block) -{ - struct GetPseuAuthorityHandle *gph = cls; - struct GNUNET_CRYPTO_EcdsaPublicKey pub; - - gph->namecache_task = NULL; - if (NULL == block) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Namecache did not return information for label `%s' \n", - gph->current_label); - process_pseu_lookup_ns (gph, 0, NULL); - return; - } - GNUNET_CRYPTO_ecdsa_key_get_public (&gph->shorten_zone_key, - &pub); - if (GNUNET_OK != - GNUNET_GNSRECORD_block_decrypt (block, - &pub, - gph->current_label, - &process_pseu_lookup_ns, - gph)) - { - GNUNET_break (0); - free_get_pseu_authority_handle (gph); - return; - } -} - - -/** - * 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 - */ -static void -perform_nick_lookup (struct GetPseuAuthorityHandle *gph, - const char *label) -{ - struct GNUNET_CRYPTO_EcdsaPublicKey pub; - struct GNUNET_HashCode query; - - GNUNET_CRYPTO_ecdsa_key_get_public (&gph->shorten_zone_key, - &pub); - GNUNET_free_non_null (gph->current_label); - gph->current_label = GNUNET_strdup (label); - GNUNET_GNSRECORD_query_from_public_key (&pub, - label, - &query); - gph->namecache_task = GNUNET_NAMECACHE_lookup_block (namecache_handle, - &query, - &process_pseu_block_ns, - gph); -} - - -/** - * Namestore calls this function if we have record for this name. - * (or with rd_count=0 to indicate no matches). - * - * @param cls the pending query - * @param rd_count the number of records with 'name' - * @param rd the record data - */ -static void -process_pseu_lookup_ns (void *cls, - unsigned int rd_count, - const struct GNUNET_GNSRECORD_Data *rd) -{ - struct GetPseuAuthorityHandle *gph = cls; - struct GNUNET_GNSRECORD_Data new_pkey; - - gph->namestore_task = NULL; - if (rd_count > 0) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Name `%s' already taken, cannot shorten.\n", - gph->current_label); - /* if this was not yet the original label, try one more - time, this time not using PSEU but the original label */ - if (0 == strcmp (gph->current_label, - gph->label)) - { - free_get_pseu_authority_handle (gph); - } - else - { - perform_nick_lookup (gph, gph->label); - } - return; - } - /* name is available */ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Shortening `%s' to `%s'\n", - GNUNET_GNSRECORD_z2s (&gph->target_zone), - gph->current_label); - new_pkey.expiration_time = UINT64_MAX; - new_pkey.data_size = sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey); - new_pkey.data = &gph->target_zone; - new_pkey.record_type = GNUNET_GNSRECORD_TYPE_PKEY; - new_pkey.flags = GNUNET_GNSRECORD_RF_NONE - | GNUNET_GNSRECORD_RF_PRIVATE; - gph->namestore_task - = GNUNET_NAMESTORE_records_store (namestore_handle, - &gph->shorten_zone_key, - gph->current_label, - 1, &new_pkey, - &create_pkey_cont, gph); -} - - -/** - * Encountered an error in zone-to-name lookup, give up on shortening. - */ -static void -zone_to_name_error_cb (void *cls) -{ - struct GetPseuAuthorityHandle* gph = cls; - - gph->namestore_task = NULL; - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "Shortening aborted, internal error talking to namestore\n"); - free_get_pseu_authority_handle (gph); -} - - -/** - * Callback called by namestore for a zone to name result. We're - * trying to see if a short name for a given zone already exists. - * - * @param cls the closure - * @param zone_key the zone we queried - * @param name the name found or NULL - * @param rd_len number of records for the name - * @param rd the record data (PKEY) for the name - */ -static void -process_zone_to_name_discover (void *cls, - const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, - const char *name, - unsigned int rd_len, - const struct GNUNET_GNSRECORD_Data *rd) -{ - struct GetPseuAuthorityHandle* gph = cls; - - gph->namestore_task = NULL; - if (0 != rd_len) - { - /* we found a match in our own zone */ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Shortening aborted, name `%s' already reserved for the zone\n", - name); - free_get_pseu_authority_handle (gph); - return; - } - else - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Shortening continuing, no name not reserved in shorten zone\n"); - } - /* record does not yet exist, check if suggested label is available */ - perform_nick_lookup (gph, gph->suggested_label); -} - - -/** - * Start shortening algorithm, try to allocate a nice short - * canonical name for @a pub in @a shorten_zone, using - * @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) -{ - struct GetPseuAuthorityHandle *gph; - struct GNUNET_CRYPTO_EcdsaPublicKey shorten_pub; - - if (strlen (original_label) > GNUNET_DNSPARSER_MAX_LABEL_LENGTH) - { - GNUNET_break (0); - return; - } - GNUNET_CRYPTO_ecdsa_key_get_public (shorten_zone, &shorten_pub); - if (0 == memcmp (&shorten_pub, pub, sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))) - { - /* Do not shorten the shorten zone */ - return; - } - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Starting shortening process for `%s' with old label `%s' and suggested nickname `%s'\n", - GNUNET_GNSRECORD_z2s (pub), - original_label, suggested_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 */ - gph->namestore_task = GNUNET_NAMESTORE_zone_to_name (namestore_handle, - shorten_zone, - pub, - &zone_to_name_error_cb, - gph, - &process_zone_to_name_discover, - gph); -} - - -/** - * Initialize the shortening subsystem - * - * @param nh the namestore handle - * @param nc the namecache handle - * @param dht the dht handle - */ -void -GNS_shorten_init (struct GNUNET_NAMESTORE_Handle *nh, - struct GNUNET_NAMECACHE_Handle *nc, - struct GNUNET_DHT_Handle *dht) -{ - namestore_handle = nh; - namecache_handle = nc; - dht_handle = dht; -} - - -/** - * Shutdown shortening. - */ -void -GNS_shorten_done () -{ - /* abort active shorten operations */ - while (NULL != gph_head) - free_get_pseu_authority_handle (gph_head); - dht_handle = NULL; - namestore_handle = NULL; - namecache_handle = NULL; -} - -/* end of gnunet-service-gns_shorten.c */ diff --git a/src/gns/gnunet-service-gns_shorten.h b/src/gns/gnunet-service-gns_shorten.h deleted file mode 100644 index d82bb52f7..000000000 --- a/src/gns/gnunet-service-gns_shorten.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - This file is part of GNUnet. - Copyright (C) 2009-2013 GNUnet e.V. - - GNUnet is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3, or (at your - option) any later version. - - GNUnet is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with GNUnet; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ -/** - * @file gns/gnunet-service-gns_shorten.h - * @brief GNUnet GNS shortening API - * @author Martin Schanzenbach - */ -#ifndef GNS_SHORTEN_H -#define GNS_SHORTEN_H -#include "gns.h" -#include "gnunet_dht_service.h" -#include "gnunet_namecache_service.h" -#include "gnunet_namestore_service.h" - - -/** - * Initialize the shorten subsystem. - * MUST be called before #GNS_shorten_start. - * - * @param nh handle to the namestore - * @param nc the namecache handle - * @param dht handle to the dht - */ -void -GNS_shorten_init (struct GNUNET_NAMESTORE_Handle *nh, - struct GNUNET_NAMECACHE_Handle *nc, - struct GNUNET_DHT_Handle *dht); - - -/** - * Cleanup shorten: Terminate pending lookups - */ -void -GNS_shorten_done (void); - - -/** - * Start shortening algorithm, try to allocate a nice short - * canonical name for @a pub in @a shorten_zone, using - * @a original_label as one possible suggestion. - * - * @param original_label original 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); - - -#endif