gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r23908 - in gnunet/src: gns namestore


From: gnunet
Subject: [GNUnet-SVN] r23908 - in gnunet/src: gns namestore
Date: Thu, 20 Sep 2012 12:10:04 +0200

Author: grothoff
Date: 2012-09-20 12:10:04 +0200 (Thu, 20 Sep 2012)
New Revision: 23908

Added:
   gnunet/src/gns/gns_common.c
   gnunet/src/gns/gns_common.h
Modified:
   gnunet/src/gns/Makefile.am
   gnunet/src/gns/gnunet-gns.c
   gnunet/src/gns/gnunet-service-gns.c
   gnunet/src/gns/gnunet-service-gns_resolver.c
   gnunet/src/gns/plugin_block_gns.c
   gnunet/src/namestore/plugin_namestore_sqlite.c
Log:
-core review

Modified: gnunet/src/gns/Makefile.am
===================================================================
--- gnunet/src/gns/Makefile.am  2012-09-20 10:04:50 UTC (rev 23907)
+++ gnunet/src/gns/Makefile.am  2012-09-20 10:10:04 UTC (rev 23908)
@@ -6,6 +6,14 @@
 
 SUBDIRS = . $(NSS_SUBDIR)
 
+EXTRA_DIST = \
+  test_gns_defaults.conf \
+  test_gns_simple_lookup.conf \
+  test_gns_dht_default.conf \
+  zonefiles/188JSUMKEF25GVU8TTV0PBNNN8JVCPUEDFV1UHJJU884JD25V0T0.zkey \
+  zonefiles/OEFL7A4VEF1B40QLEMTG5D8G1CN6EN16QUSG5R2DT71GRJN34LSG.zkey \
+  zonefiles/test_zonekey
+
 if MINGW
   WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols
   DO_W32_HELPER = gnunet-gns-helper-service-w32
@@ -18,7 +26,7 @@
   AM_CFLAGS = --coverage -O0
 endif
 
-pkgcfgdir= $(pkgdatadir)/config.d/
+pkgcfgdir = $(pkgdatadir)/config.d/
 
 plugindir = $(libdir)/gnunet
 
@@ -28,8 +36,10 @@
 
 lib_LTLIBRARIES = \
   $(DO_W32_NSP) \
-  libgnunetgns.la
+  libgnunetgns.la \
+  libgnunetgns_common.la
 
+
 if HAVE_MHD
  DO_FCFSD=gnunet-gns-fcfsd
 if HAVE_GNUTLS
@@ -46,8 +56,144 @@
   gnunet-gns \
   gnunet-dns2gns
 
-bin_SCRIPTS=gnunet-gns-proxy-setup-ca
+bin_SCRIPTS = gnunet-gns-proxy-setup-ca
 
+plugin_LTLIBRARIES = \
+  libgnunet_plugin_block_gns.la
+
+gnunet_gns_SOURCES = \
+ gnunet-gns.c
+gnunet_gns_LDADD = \
+  $(top_builddir)/src/gns/libgnunetgns.la \
+  $(top_builddir)/src/util/libgnunetutil.la \
+  $(top_builddir)/src/namestore/libgnunetnamestore.la \
+  $(GN_LIBINTL)
+gnunet_gns_DEPENDENCIES = \
+  libgnunetgns.la
+
+gnunet_dns2gns_SOURCES = \
+ gnunet-dns2gns.c
+gnunet_dns2gns_LDADD = \
+  $(top_builddir)/src/gns/libgnunetgns.la \
+  $(top_builddir)/src/util/libgnunetutil.la \
+  $(top_builddir)/src/namestore/libgnunetnamestore.la \
+  $(top_builddir)/src/dns/libgnunetdnsparser.la \
+       $(top_builddir)/src/dns/libgnunetdnsstub.la \
+  $(GN_LIBINTL)
+gnunet_dns2gns_DEPENDENCIES = \
+  libgnunetgns.la
+
+gnunet_gns_proxy_SOURCES = \
+ gnunet-gns-proxy.c gns_proxy_proto.h 
+gnunet_gns_proxy_LDADD = -lmicrohttpd -lcurl -lgnutls \
+  $(top_builddir)/src/gns/libgnunetgns.la \
+  $(top_builddir)/src/util/libgnunetutil.la \
+  $(GN_LIBINTL)
+gnunet_gns_proxy_DEPENDENCIES = \
+  libgnunetgns.la
+
+gnunet_gns_helper_service_w32_SOURCES = \
+  gnunet-gns-helper-service-w32.c
+gnunet_gns_helper_service_w32_LDADD = \
+  $(top_builddir)/src/gns/libgnunetgns.la \
+  $(top_builddir)/src/util/libgnunetutil.la \
+  $(GN_LIBINTL)
+gnunet_gns_helper_service_w32_DEPENDENCIES = \
+  libgnunetgns.la
+
+w32nsp_install_SOURCES = \
+  w32nsp-install.c
+w32nsp_install_LDADD = -lws2_32
+
+w32nsp_uninstall_SOURCES = \
+  w32nsp-uninstall.c
+w32nsp_uninstall_LDADD = -lws2_32
+
+w32nsp_resolve_SOURCES = \
+  w32nsp-resolve.c
+w32nsp_resolve_LDADD = -lws2_32
+
+gnunet_service_gns_SOURCES = \
+ gnunet-service-gns.c \
+ gnunet-service-gns_resolver.c gnunet-service-gns_resolver.h \
+ gnunet-service-gns_interceptor.c gnunet-service-gns_interceptor.h 
+gnunet_service_gns_LDADD = \
+  -lm \
+  $(top_builddir)/src/statistics/libgnunetstatistics.la \
+  $(top_builddir)/src/util/libgnunetutil.la \
+  $(top_builddir)/src/gns/libgnunetgns_common.la \
+       $(top_builddir)/src/dns/libgnunetdns.la \
+       $(top_builddir)/src/dns/libgnunetdnsparser.la \
+       $(top_builddir)/src/dht/libgnunetdht.la \
+       $(top_builddir)/src/namestore/libgnunetnamestore.la \
+       $(top_builddir)/src/vpn/libgnunetvpn.la \
+  $(GN_LIBINTL)
+gnunet_service_gns_DEPENDENCIES = \
+  $(top_builddir)/src/statistics/libgnunetstatistics.la \
+  $(top_builddir)/src/util/libgnunetutil.la \
+  $(top_builddir)/src/gns/libgnunetgns_common.la \
+       $(top_builddir)/src/dns/libgnunetdns.la \
+       $(top_builddir)/src/dns/libgnunetdnsparser.la \
+       $(top_builddir)/src/dht/libgnunetdht.la \
+       $(top_builddir)/src/namestore/libgnunetnamestore.la \
+       $(top_builddir)/src/vpn/libgnunetvpn.la
+
+
+
+gnunet_gns_fcfsd_SOURCES = \
+ gnunet-gns-fcfsd.c 
+gnunet_gns_fcfsd_LDADD = -lmicrohttpd \
+  $(top_builddir)/src/util/libgnunetutil.la \
+  $(top_builddir)/src/namestore/libgnunetnamestore.la \
+  $(GN_LIBINTL)
+gnunet_gns_fcfsd_DEPENDENCIES = \
+  $(top_builddir)/src/util/libgnunetutil.la \
+  $(top_builddir)/src/namestore/libgnunetnamestore.la
+
+libw32nsp_la_SOURCES = \
+  w32nsp.c
+libw32nsp_la_LIBADD = \
+  -lole32 -lws2_32
+libw32nsp_la_LDFLAGS = \
+  -export-symbols $(top_srcdir)/src/gns/w32nsp.def \
+  $(GN_LIB_LDFLAGS)
+
+libgnunetgns_la_SOURCES = \
+ gns_api.c gns.h
+libgnunetgns_la_LIBADD = \
+ $(top_builddir)/src/util/libgnunetutil.la $(XLIB) \
+ $(top_builddir)/src/namestore/libgnunetnamestore.la
+libgnunetgns_la_LDFLAGS = \
+  $(GN_LIB_LDFLAGS)
+libgnunetgns_la_DEPENDENCIES = \
+ $(top_builddir)/src/util/libgnunetutil.la \
+ $(top_builddir)/src/namestore/libgnunetnamestore.la
+
+
+libgnunetgns_common_la_SOURCES = \
+ gns_common.c gns_common.h
+libgnunetgns_common_la_LIBADD = \
+ $(top_builddir)/src/util/libgnunetutil.la 
+libgnunetgns_common_la_DEPENDENCIES = \
+ $(top_builddir)/src/util/libgnunetutil.la 
+
+
+libgnunet_plugin_block_gns_la_SOURCES = \
+  plugin_block_gns.c
+libgnunet_plugin_block_gns_la_LIBADD = \
+  $(top_builddir)/src/util/libgnunetutil.la \
+  $(top_builddir)/src/block/libgnunetblock.la \
+  $(top_builddir)/src/gns/libgnunetgns_common.la \
+  $(top_builddir)/src/namestore/libgnunetnamestore.la
+libgnunet_plugin_block_gns_la_LDFLAGS = \
+  $(GN_PLUGIN_LDFLAGS)
+libgnunet_plugin_block_gns_la_DEPENDENCIES = \
+  $(top_builddir)/src/util/libgnunetutil.la \
+  $(top_builddir)/src/gns/libgnunetgns_common.la \
+  $(top_builddir)/src/block/libgnunetblock.la \
+  $(top_builddir)/src/namestore/libgnunetnamestore.la
+
+
 check_PROGRAMS = \
   test_gns_simple_shorten \
   test_gns_simple_get_authority \
@@ -65,7 +211,11 @@
   test_gns_dht_three_peers
  #test_gns_proxy
 
-  
+if ENABLE_TEST_RUN
+if LINUX
+TESTS = $(check_PROGRAMS)
+endif
+endif
 
 
 #  test_gns_simple_lookup
@@ -73,9 +223,6 @@
 #  test_gns_dht_delegated_lookup
 
 
-plugin_LTLIBRARIES = \
-  libgnunet_plugin_block_gns.la
-
 #test_gns_proxy_SOURCES = \
 #  test_gns_proxy.c
 #test_gns_proxy_LDADD = -lmicrohttpd @LIBCURL@ \
@@ -282,124 +429,7 @@
   $(top_builddir)/src/testing/libgnunettesting.la
 
 
-gnunet_gns_SOURCES = \
- gnunet-gns.c
-gnunet_gns_LDADD = \
-  $(top_builddir)/src/gns/libgnunetgns.la \
-  $(top_builddir)/src/util/libgnunetutil.la \
-  $(top_builddir)/src/namestore/libgnunetnamestore.la \
-  $(GN_LIBINTL)
-gnunet_gns_DEPENDENCIES = \
-  libgnunetgns.la
 
-gnunet_dns2gns_SOURCES = \
- gnunet-dns2gns.c
-gnunet_dns2gns_LDADD = \
-  $(top_builddir)/src/gns/libgnunetgns.la \
-  $(top_builddir)/src/util/libgnunetutil.la \
-  $(top_builddir)/src/namestore/libgnunetnamestore.la \
-  $(top_builddir)/src/dns/libgnunetdnsparser.la \
-       $(top_builddir)/src/dns/libgnunetdnsstub.la \
-  $(GN_LIBINTL)
-gnunet_dns2gns_DEPENDENCIES = \
-  libgnunetgns.la
-
-gnunet_gns_proxy_SOURCES = \
- gnunet-gns-proxy.c gns_proxy_proto.h 
-gnunet_gns_proxy_LDADD = -lmicrohttpd -lcurl -lgnutls \
-  $(top_builddir)/src/gns/libgnunetgns.la \
-  $(top_builddir)/src/util/libgnunetutil.la \
-  $(GN_LIBINTL)
-gnunet_gns_proxy_DEPENDENCIES = \
-  libgnunetgns.la
-
-gnunet_gns_helper_service_w32_SOURCES = \
-  gnunet-gns-helper-service-w32.c
-gnunet_gns_helper_service_w32_LDADD = \
-  $(top_builddir)/src/gns/libgnunetgns.la \
-  $(top_builddir)/src/util/libgnunetutil.la \
-  $(GN_LIBINTL)
-gnunet_gns_helper_service_w32_DEPENDENCIES = \
-  libgnunetgns.la
-
-w32nsp_install_SOURCES = \
-  w32nsp-install.c
-w32nsp_install_LDADD = -lws2_32
-
-w32nsp_uninstall_SOURCES = \
-  w32nsp-uninstall.c
-w32nsp_uninstall_LDADD = -lws2_32
-
-w32nsp_resolve_SOURCES = \
-  w32nsp-resolve.c
-w32nsp_resolve_LDADD = -lws2_32
-
-gnunet_service_gns_SOURCES = \
- gnunet-service-gns.c \
- gnunet-service-gns_resolver.c gnunet-service-gns_resolver.h \
- gnunet-service-gns_interceptor.c gnunet-service-gns_interceptor.h 
-gnunet_service_gns_LDADD = \
-  -lm \
-  $(top_builddir)/src/statistics/libgnunetstatistics.la \
-  $(top_builddir)/src/util/libgnunetutil.la \
-       $(top_builddir)/src/dns/libgnunetdns.la \
-       $(top_builddir)/src/dns/libgnunetdnsparser.la \
-       $(top_builddir)/src/dht/libgnunetdht.la \
-       $(top_builddir)/src/namestore/libgnunetnamestore.la \
-       $(top_builddir)/src/vpn/libgnunetvpn.la \
-  $(GN_LIBINTL)
-gnunet_service_gns_DEPENDENCIES = \
-  $(top_builddir)/src/statistics/libgnunetstatistics.la \
-  $(top_builddir)/src/util/libgnunetutil.la \
-       $(top_builddir)/src/dns/libgnunetdns.la \
-       $(top_builddir)/src/dns/libgnunetdnsparser.la \
-       $(top_builddir)/src/dht/libgnunetdht.la \
-       $(top_builddir)/src/namestore/libgnunetnamestore.la \
-       $(top_builddir)/src/vpn/libgnunetvpn.la
-
-
-gnunet_gns_fcfsd_SOURCES = \
- gnunet-gns-fcfsd.c 
-gnunet_gns_fcfsd_LDADD = -lmicrohttpd \
-  $(top_builddir)/src/util/libgnunetutil.la \
-  $(top_builddir)/src/namestore/libgnunetnamestore.la \
-  $(GN_LIBINTL)
-gnunet_gns_fcfsd_DEPENDENCIES = \
-  $(top_builddir)/src/util/libgnunetutil.la \
-  $(top_builddir)/src/namestore/libgnunetnamestore.la
-
-libw32nsp_la_SOURCES = \
-  w32nsp.c
-libw32nsp_la_LIBADD = \
-  -lole32 -lws2_32
-libw32nsp_la_LDFLAGS = \
-  -export-symbols $(top_srcdir)/src/gns/w32nsp.def \
-  $(GN_LIB_LDFLAGS)
-
-libgnunetgns_la_SOURCES = \
- gns_api.c gns.h
-libgnunetgns_la_LIBADD = \
- $(top_builddir)/src/util/libgnunetutil.la $(XLIB) \
- $(top_builddir)/src/namestore/libgnunetnamestore.la
-libgnunetgns_la_LDFLAGS = \
-  $(GN_LIB_LDFLAGS)
-libgnunetgns_la_DEPENDENCIES = \
- $(top_builddir)/src/util/libgnunetutil.la \
- $(top_builddir)/src/namestore/libgnunetnamestore.la
-
-libgnunet_plugin_block_gns_la_SOURCES = \
-  plugin_block_gns.c
-libgnunet_plugin_block_gns_la_LIBADD = \
-  $(top_builddir)/src/util/libgnunetutil.la \
-  $(top_builddir)/src/block/libgnunetblock.la \
-  $(top_builddir)/src/namestore/libgnunetnamestore.la
-libgnunet_plugin_block_gns_la_LDFLAGS = \
-  $(GN_PLUGIN_LDFLAGS)
-libgnunet_plugin_block_gns_la_DEPENDENCIES = \
-  $(top_builddir)/src/util/libgnunetutil.la \
-  $(top_builddir)/src/block/libgnunetblock.la \
-  $(top_builddir)/src/namestore/libgnunetnamestore.la
-
 #Build stub api
 #libgnunetnamestore_la_SOURCES = \
 # namestore_stub_api.c
@@ -410,17 +440,5 @@
 #libgnunetnamestore_la_DEPENDENCIES = \
 # $(top_builddir)/src/util/libgnunetutil.la
 
-if ENABLE_TEST_RUN
-if LINUX
-TESTS = $(check_PROGRAMS)
-endif
-endif
 
-EXTRA_DIST = \
-  test_gns_defaults.conf \
-  test_gns_simple_lookup.conf \
-  test_gns_dht_default.conf \
-       zonefiles/188JSUMKEF25GVU8TTV0PBNNN8JVCPUEDFV1UHJJU884JD25V0T0.zkey \
-       zonefiles/OEFL7A4VEF1B40QLEMTG5D8G1CN6EN16QUSG5R2DT71GRJN34LSG.zkey \
-       zonefiles/test_zonekey
 

Added: gnunet/src/gns/gns_common.c
===================================================================
--- gnunet/src/gns/gns_common.c                         (rev 0)
+++ gnunet/src/gns/gns_common.c 2012-09-20 10:10:04 UTC (rev 23908)
@@ -0,0 +1,79 @@
+/*
+     This file is part of GNUnet.
+     (C) 2012 Christian Grothoff (and other contributing authors)
+
+     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., 59 Temple Place - Suite 330,
+     Boston, MA 02111-1307, USA.
+*/
+/**
+ *
+ * @file gns/gns_common.c
+ * @brief helper functions shared between GNS service and block plugin
+ * @author Martin Schanzenbach
+ */
+#include "platform.h"
+#include "gns_common.h"
+
+
+/**
+ * Compute the DHT key for a name in a zone.
+ * DHT key is H(name) xor H(pubkey).
+ *
+ * @param name name of the record
+ * @param zone GADS zone
+ * @param key where to store the DHT key for records under this name in the 
given zone
+ */
+void 
+GNUNET_GNS_get_key_for_record (const char *name,
+                              const struct GNUNET_CRYPTO_ShortHashCode *zone,
+                              struct GNUNET_HashCode *key)
+{
+  struct GNUNET_CRYPTO_ShortHashCode name_hash;
+  struct GNUNET_HashCode name_hash_double;
+  struct GNUNET_HashCode zone_hash_double;
+
+  GNUNET_CRYPTO_short_hash (name,
+                           strlen (name),
+                           &name_hash);
+  GNUNET_CRYPTO_short_hash_double (&name_hash, &name_hash_double);
+  GNUNET_CRYPTO_short_hash_double (zone, &zone_hash_double);
+  GNUNET_CRYPTO_hash_xor(&name_hash_double, &zone_hash_double, key);
+}
+
+
+/**
+ * Compute the zone identifier from a given DHT key and record name.
+ *
+ * @param name name of the record
+ * @param key DHT key of the record
+ * @param zone set to the corresponding zone hash
+ */
+void 
+GNUNET_GNS_get_zone_from_key (const char *name,
+                             const struct GNUNET_HashCode *key,                
               
+                             struct GNUNET_CRYPTO_ShortHashCode *zone)
+{
+  struct GNUNET_CRYPTO_ShortHashCode name_hash;
+  struct GNUNET_HashCode name_hash_double;
+  struct GNUNET_HashCode zone_hash_double;
+
+  GNUNET_CRYPTO_short_hash(name, strlen(name), &name_hash);
+  GNUNET_CRYPTO_short_hash_double(&name_hash, &name_hash_double);
+  GNUNET_CRYPTO_hash_xor(key, &name_hash_double, &zone_hash_double);
+  GNUNET_CRYPTO_short_hash_from_truncation (&zone_hash_double, zone);
+}                             
+
+
+/* end of gns_common.c */

Added: gnunet/src/gns/gns_common.h
===================================================================
--- gnunet/src/gns/gns_common.h                         (rev 0)
+++ gnunet/src/gns/gns_common.h 2012-09-20 10:10:04 UTC (rev 23908)
@@ -0,0 +1,58 @@
+/*
+     This file is part of GNUnet.
+     (C) 2012 Christian Grothoff (and other contributing authors)
+
+     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., 59 Temple Place - Suite 330,
+     Boston, MA 02111-1307, USA.
+*/
+/**
+ *
+ * @file gns/gns_common.h
+ * @brief helper functions shared between GNS service and block plugin
+ * @author Martin Schanzenbach
+ */
+#ifndef GNS_COMMON_H
+#define GNS_COMMON_H
+
+#include "gnunet_util_lib.h"
+
+/**
+ * Compute the DHT key for a name in a zone.
+ *
+ * @param name name of the record
+ * @param zone GADS zone
+ * @param key where to store the DHT key for records under this name in the 
given zone
+ */
+void 
+GNUNET_GNS_get_key_for_record (const char *name,
+                              const struct GNUNET_CRYPTO_ShortHashCode *zone,
+                              struct GNUNET_HashCode *key);
+
+
+/**
+ * Compute the zone identifier from a given DHT key and record name.
+ *
+ * @param name name of the record
+ * @param key DHT key of the record
+ * @param zone set to the corresponding zone hash
+ */
+void 
+GNUNET_GNS_get_zone_from_key (const char *name,
+                             const struct GNUNET_HashCode *key,                
               
+                             struct GNUNET_CRYPTO_ShortHashCode *zone);
+                              
+
+
+#endif

Modified: gnunet/src/gns/gnunet-gns.c
===================================================================
--- gnunet/src/gns/gnunet-gns.c 2012-09-20 10:04:50 UTC (rev 23907)
+++ gnunet/src/gns/gnunet-gns.c 2012-09-20 10:10:04 UTC (rev 23908)
@@ -58,7 +58,7 @@
 /**
  * raw output
  */
-static int raw = 0;
+static int raw;
 
 static enum GNUNET_GNS_RecordType rtype;
 
@@ -71,8 +71,6 @@
 /* Handle to get authority request */
 static struct GNUNET_GNS_GetAuthRequest *getauth_request;
 
-/* shutdown task */
-static GNUNET_SCHEDULER_TaskIdentifier shutdown_task;
 
 /**
  * Task run on shutdown.  Cleans up everything.
@@ -99,61 +97,61 @@
 
 
 static void
-process_shorten_result(void* cls, const char* nshort)
+process_shorten_result (void* cls, const char* nshort)
 {
+  const char *original_name = cls;
+
   shorten_request = NULL;
   if (raw)
     printf("%s", nshort);
   else
-    printf("%s shortened to %s\n", (char*) cls, nshort);
-  GNUNET_SCHEDULER_cancel (shutdown_task);
-  GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
+    printf("%s shortened to %s\n", original_name, nshort);
+  GNUNET_SCHEDULER_shutdown ();
 }
 
+
 static void
-process_lookup_result(void* cls, uint32_t rd_count,
-                      const struct GNUNET_NAMESTORE_RecordData *rd)
+process_lookup_result (void* cls, uint32_t rd_count,
+                      const struct GNUNET_NAMESTORE_RecordData *rd)
 {
-  int i;
-  char* name = (char*) cls;
+  const char* name = cls;
+  uint32_t i;
   const char* typename;
   char* string_val;
-  lookup_request = NULL;
-  
-  if (!raw) {
+
+  lookup_request = NULL; 
+  if (!raw) 
+  {
     if (rd_count == 0)
       printf("No results.\n");
     else
       printf("%s:\n", name);
   }
-
-
-
   for (i=0; i<rd_count; i++)
   {
     typename = GNUNET_NAMESTORE_number_to_typename (rd[i].record_type);
-    string_val = GNUNET_NAMESTORE_value_to_string(rd[i].record_type,
-                                                  rd[i].data,
-                                                  rd[i].data_size);
+    string_val = GNUNET_NAMESTORE_value_to_string (rd[i].record_type,
+                                                  rd[i].data,
+                                                  rd[i].data_size);
     if (raw)
-      printf("%s\n", string_val);
+      printf ("%s\n", string_val);
     else
-      printf("Got %s record: %s\n", typename, string_val);
-
+      printf ("Got `%s' record: %s\n", typename, string_val);
+    GNUNET_free_non_null (string_val);
   }
-  GNUNET_SCHEDULER_cancel (shutdown_task);
-  GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
+  GNUNET_SCHEDULER_shutdown ();
 }
 
+
 static void
-process_auth_result(void* cls, const char* auth)
+process_auth_result (void* cls, const char* auth)
 {
   getauth_request = NULL;
   printf ("%s\n", auth);
-  GNUNET_SCHEDULER_cancel (shutdown_task);
-  GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
+  GNUNET_SCHEDULER_shutdown ();
 }
 
+
 /**
  * Main function that will be run.
  *
@@ -177,124 +175,84 @@
   struct GNUNET_CRYPTO_ShortHashCode *private_zone = NULL;
   struct GNUNET_CRYPTO_ShortHashCode *shorten_zone = NULL;
 
-  shorten_request = NULL;
-  lookup_request = NULL;
-  getauth_request = NULL;
-
+  gns = GNUNET_GNS_connect (cfg);
+  if (NULL == gns)
+  {
+    fprintf (stderr,
+            _("Failed to connect to GNS\n"));
+    return;
+  }
   if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns",
                                                            "ZONEKEY", 
&keyfile))
   {
-    if (!raw)
+    if (! raw)
       GNUNET_log (GNUNET_ERROR_TYPE_INFO,
                   "No private key for root zone found, using default!\n");
-    zone = NULL;
   }
   else
   {
-    if (GNUNET_YES == GNUNET_DISK_file_test (keyfile))
-    {
-      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),
-                         &user_zone);
-      zone = &user_zone;
-      GNUNET_CRYPTO_short_hash_to_enc (zone, &zonename);
-      if (!raw)
-        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                    "Using zone: %s!\n", &zonename);
-      GNUNET_CRYPTO_rsa_key_free(key);
-    }
+    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),
+                             &user_zone);
+    zone = &user_zone;
+    GNUNET_CRYPTO_short_hash_to_enc (zone, &zonename);
+    if (!raw)
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                 "Using 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))
+                                                           "SHORTEN_ZONEKEY", 
&keyfile))
   {
-    if (!raw)
+    if (! raw)
       GNUNET_log (GNUNET_ERROR_TYPE_INFO,
                   "No shorten key found!\n");
-    shorten_key = NULL;
   }
   else
   {
-    if (GNUNET_YES == GNUNET_DISK_file_test (keyfile))
-    {
-      shorten_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
-      GNUNET_CRYPTO_rsa_key_get_public (shorten_key, &pkey);
-      shorten_zone = GNUNET_malloc (sizeof (struct 
GNUNET_CRYPTO_ShortHashCode));
-      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);
+    shorten_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
+    GNUNET_CRYPTO_rsa_key_get_public (shorten_key, &pkey);
+    shorten_zone = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_ShortHashCode));
+    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)
+    if (! raw)
       GNUNET_log (GNUNET_ERROR_TYPE_INFO,
                   "No private zone key file name specified in 
configuration!\n");
-    private_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 (private_key, &pkey);
-      private_zone = GNUNET_malloc (sizeof (struct 
GNUNET_CRYPTO_ShortHashCode));
-      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);
-    }
-    else
-    {
-      /* FIXME: shouldn't we just create the private key in this case? */
-      if (!raw)
-        fprintf (stderr,
-                _("Key file `%s' for private zone does not exist!\n"),
-                keyfile);
-
-    }
-    GNUNET_free(keyfile);
-    if (NULL != private_key)
-    {
-      GNUNET_CRYPTO_rsa_key_free (private_key);
-      private_key = NULL;
-    }
+    private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
+    GNUNET_CRYPTO_rsa_key_get_public (private_key, &pkey);
+    private_zone = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_ShortHashCode));
+    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);
   }
   
-  
-  gns = GNUNET_GNS_connect (cfg);
   if (NULL != lookup_type)
     rtype = GNUNET_NAMESTORE_typename_to_number (lookup_type);
   else
     rtype = GNUNET_GNS_RECORD_A;
 
-  if (NULL == gns)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-               _("Failed to connect to GNS\n"));
-    if (NULL != shorten_key)
-    {
-      GNUNET_CRYPTO_rsa_key_free (shorten_key);
-      shorten_key = NULL;
-    }
-    return;
-  }
-  
   if ((NULL != shorten_name) && (NULL != shorten_zone) && (NULL != 
private_zone))
   {
     shorten_request = GNUNET_GNS_shorten_zone (gns, shorten_name,
@@ -304,31 +262,25 @@
                              &process_shorten_result,
                              shorten_name);
   }
-
   if (NULL != lookup_name)
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "Lookup\n");
     lookup_request = GNUNET_GNS_lookup_zone (gns, lookup_name,
-                            zone,
-                            rtype,
-                            GNUNET_NO, //Use DHT
-                            shorten_key,
-                            &process_lookup_result, lookup_name);
+                                            zone,
+                                            rtype,
+                                            GNUNET_NO, /* Use DHT */
+                                            shorten_key,
+                                            &process_lookup_result, 
lookup_name);
   }
-
   if (NULL != auth_name)
   {
-    getauth_request = GNUNET_GNS_get_authority(gns, auth_name,
-                                               &process_auth_result, 
auth_name);
+    getauth_request = GNUNET_GNS_get_authority (gns, auth_name,
+                                               &process_auth_result, 
auth_name);
   }
 
   if (NULL != shorten_key)
     GNUNET_CRYPTO_rsa_key_free (shorten_key);
-
   if (NULL != shorten_zone)
     GNUNET_free (shorten_zone);
-
   if (NULL != private_zone)
     GNUNET_free (private_zone);
   
@@ -336,15 +288,14 @@
       (NULL == shorten_name) &&
       (NULL == lookup_name))
   {
-    if (!raw)
-      GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-                 "Please specify lookup, shorten or authority operation!\n");
+    fprintf (stderr,
+            _("Please specify lookup, shorten or authority operation!\n"));
     GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
     return;
   }
 
-  shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
-                                                &do_shutdown, NULL);
+  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
+                               &do_shutdown, NULL);
 }
 
 

Modified: gnunet/src/gns/gnunet-service-gns.c
===================================================================
--- gnunet/src/gns/gnunet-service-gns.c 2012-09-20 10:04:50 UTC (rev 23907)
+++ gnunet/src/gns/gnunet-service-gns.c 2012-09-20 10:10:04 UTC (rev 23908)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     (C) 2009, 2010, 2011 Christian Grothoff (and other contributing authors)
+     (C) 2009, 2010, 2011, 2012 Christian Grothoff (and other contributing 
authors)
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -35,6 +35,7 @@
 #include "gnunet_statistics_service.h"
 #include "block_gns.h"
 #include "gns.h"
+#include "gns_common.h"
 #include "gnunet-service-gns_resolver.h"
 #include "gnunet-service-gns_interceptor.h"
 #include "gnunet_protocols.h"
@@ -102,7 +103,7 @@
   uint64_t unique_id;
 
   /* name to lookup authority */
-  char* name;
+  char *name;
 
 };
 
@@ -132,9 +133,10 @@
   struct GNUNET_CRYPTO_RsaPrivateKey *shorten_key;
 
   /* the name to look up */
-  char* name; //Needed?
+  char *name; 
 };
 
+
 /**
  * Our handle to the DHT
  */
@@ -143,25 +145,20 @@
 /**
  * Our zone's private key
  */
-struct GNUNET_CRYPTO_RsaPrivateKey *zone_key;
+static struct GNUNET_CRYPTO_RsaPrivateKey *zone_key;
 
 /**
  * Our handle to the namestore service
  * FIXME maybe need a second handle for iteration
  */
-struct GNUNET_NAMESTORE_Handle *namestore_handle;
+static struct GNUNET_NAMESTORE_Handle *namestore_handle;
 
 /**
  * Handle to iterate over our authoritative zone in namestore
  */
-struct GNUNET_NAMESTORE_ZoneIterator *namestore_iter;
+static struct GNUNET_NAMESTORE_ZoneIterator *namestore_iter;
 
 /**
- * The configuration the GNS service is running with
- */
-const struct GNUNET_CONFIGURATION_Handle *GNS_cfg;
-
-/**
  * Our notification context.
  */
 static struct GNUNET_SERVER_NotificationContext *nc;
@@ -169,7 +166,7 @@
 /**
  * Our zone hash
  */
-struct GNUNET_CRYPTO_ShortHashCode zone_hash;
+static struct GNUNET_CRYPTO_ShortHashCode zone_hash;
 
 /**
  * Useful for zone update for DHT put
@@ -190,7 +187,7 @@
 static struct GNUNET_TIME_Relative record_put_interval;
 
 /* zone update task */
-GNUNET_SCHEDULER_TaskIdentifier zone_update_taskid = GNUNET_SCHEDULER_NO_TASK;
+static GNUNET_SCHEDULER_TaskIdentifier zone_update_taskid;
 
 /* automatic pkey import for name shortening */
 static int auto_import_pkey;
@@ -256,7 +253,7 @@
  * @param tc task context
  */
 static void
-update_zone_dht_next(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+update_zone_dht_next (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   zone_update_taskid = GNUNET_SCHEDULER_NO_TASK;
   GNUNET_NAMESTORE_zone_iterator_next (namestore_iter);
@@ -284,6 +281,7 @@
 static void
 update_zone_dht_start(void *cls, const struct GNUNET_SCHEDULER_TaskContext 
*tc);
 
+
 /**
  * Function used to put all records successively into the DHT.
  *
@@ -305,19 +303,18 @@
                 const struct GNUNET_CRYPTO_RsaSignature *signature)
 {  
   struct GNSNameRecordBlock *nrb;
-  struct GNUNET_CRYPTO_ShortHashCode name_hash;
   struct GNUNET_CRYPTO_ShortHashCode zhash;
-  struct GNUNET_HashCode xor_hash;
-  struct GNUNET_HashCode name_hash_double;
-  struct GNUNET_HashCode zone_hash_double;
+  struct GNUNET_HashCode dht_key;
   uint32_t rd_payload_length;
   char* nrb_data = NULL;
   size_t namelen;
   struct GNUNET_TIME_Relative next_put_interval; 
 
-  /* we're done */
   if (NULL == name)
   {
+    /* we're done */
+    namestore_iter = NULL;
+    last_num_public_records = num_public_records;
     first_zone_iteration = GNUNET_NO;
     if (0 == num_public_records)
     {
@@ -329,49 +326,41 @@
       zone_iteration_interval = GNUNET_TIME_relative_divide 
(record_put_interval,
                                                              1);
 
-      GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
-                 "No records in db.\n");
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
+                 "No records in db.\n");
     }
     else
     {
       zone_iteration_interval = GNUNET_TIME_relative_divide 
(record_put_interval,
                                                              
num_public_records);
     }
-
     zone_iteration_interval = GNUNET_TIME_relative_max 
(MINIMUM_ZONE_ITERATION_INTERVAL,
                                                         
zone_iteration_interval);
 
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-               "Adjusted zone iteration interval to %s\n",
+               "Zone iteration finished. Adjusted zone iteration interval to 
%s\n",
                GNUNET_STRINGS_relative_time_to_string 
(zone_iteration_interval, GNUNET_YES));
     GNUNET_STATISTICS_set (statistics,
-                           "Current zone iteration interval [msec]",
+                           "Current zone iteration interval (in ms)",
                            zone_iteration_interval.rel_value,
                            GNUNET_NO);
-    
-    GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
-               "Zone iteration finished. Rescheduling zone iteration\n");
-
-    namestore_iter = NULL;
-    if (num_public_records == 0)
-      zone_update_taskid = GNUNET_SCHEDULER_add_delayed 
(zone_iteration_interval,
-                                                         
&update_zone_dht_start,
-                                                         NULL);
-    else
-      zone_update_taskid = GNUNET_SCHEDULER_add_now (&update_zone_dht_start, 
NULL);
     GNUNET_STATISTICS_update (statistics,
                               "Number of zone iterations", 1, GNUNET_NO);
-
-    last_num_public_records = num_public_records;
     GNUNET_STATISTICS_set (statistics,
                            "Number of public records in DHT",
                            last_num_public_records,
                            GNUNET_NO);
+    if (0 == num_public_records)
+      zone_update_taskid = GNUNET_SCHEDULER_add_delayed 
(zone_iteration_interval,
+                                                         
&update_zone_dht_start,
+                                                         NULL);
+    else
+      zone_update_taskid = GNUNET_SCHEDULER_add_now (&update_zone_dht_start, 
NULL);
     return;
   }
   
-  namelen = strlen(name) + 1;
-  if (rd_count == 0)
+  namelen = strlen (name) + 1;
+  if (0 == rd_count)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                "No records for name `%s'! Skipping.\n",
@@ -380,7 +369,7 @@
                                                    NULL);
     return;
   }
-  if (signature == NULL)
+  if (NULL == signature)
   {
     GNUNET_break (0);
     zone_update_taskid = GNUNET_SCHEDULER_add_now (&update_zone_dht_next,
@@ -389,15 +378,14 @@
   }
   
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-             "Putting records for `%s' into the DHT\n", name);
-  
+             "Putting records for `%s' into the DHT\n", name); 
   rd_payload_length = GNUNET_NAMESTORE_records_get_size (rd_count, rd); 
-  nrb = GNUNET_malloc(rd_payload_length + namelen
-                      + sizeof(struct GNSNameRecordBlock));
+  nrb = GNUNET_malloc (rd_payload_length + namelen
+                      + sizeof (struct GNSNameRecordBlock));
   nrb->signature = *signature;
   nrb->public_key = *key;
-  nrb->rd_count = htonl(rd_count);
-  memcpy(&nrb[1], name, namelen);
+  nrb->rd_count = htonl (rd_count);
+  memcpy (&nrb[1], name, namelen);
   nrb_data = (char *) &nrb[1];
   nrb_data += namelen;
   rd_payload_length += sizeof(struct GNSNameRecordBlock) + namelen;
@@ -419,27 +407,20 @@
     return;
   }
 
-  /*
-   * calculate DHT key: H(name) xor H(pubkey)
-   */
-  GNUNET_CRYPTO_short_hash(name, strlen(name), &name_hash);
-  GNUNET_CRYPTO_short_hash_double (&name_hash, &name_hash_double);
-  GNUNET_CRYPTO_short_hash_double (&zhash, &zone_hash_double);
-  GNUNET_CRYPTO_hash_xor(&zone_hash_double, &name_hash_double, &xor_hash);
-
+  GNUNET_GNS_get_key_for_record (name, &zhash, &dht_key);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "putting %u records from zone %s for `%s' under key: %s with size 
%u and timeout %s\n",
              rd_count,
-             GNUNET_h2s (&zone_hash_double) /* FIXME: write converter for 
short hash... */,
+             GNUNET_short_h2s (&zhash),
              name, 
-             GNUNET_h2s (&xor_hash), 
+             GNUNET_h2s (&dht_key), 
              (unsigned int) rd_payload_length,
              GNUNET_STRINGS_relative_time_to_string (DHT_OPERATION_TIMEOUT, 
GNUNET_YES));
   
   GNUNET_STATISTICS_update (statistics,
                             "Record bytes put into DHT", rd_payload_length, 
GNUNET_NO);
 
-  (void) GNUNET_DHT_put (dht_handle, &xor_hash,
+  (void) GNUNET_DHT_put (dht_handle, &dht_key,
                         DHT_GNS_REPLICATION_LEVEL,
                         GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
                         GNUNET_BLOCK_TYPE_GNS_NAMERECORD,
@@ -449,36 +430,29 @@
                         DHT_OPERATION_TIMEOUT,
                         &record_dht_put,
                         NULL); 
-  
-  num_public_records++;
-  
-  if ((num_public_records > last_num_public_records)
-      && (first_zone_iteration == GNUNET_NO))
+  GNUNET_free (nrb);
+
+  num_public_records++;  
+  if ( (num_public_records > last_num_public_records)
+       && (GNUNET_NO == first_zone_iteration) )
   {
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+               "Last record count was lower than current record count.  
Reducing interval.\n");
     zone_iteration_interval = GNUNET_TIME_relative_divide (record_put_interval,
                                                            num_public_records);
-    GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
-               "Last record count was lower than current record count... 
increasing.\n");
     next_put_interval = GNUNET_TIME_relative_divide (zone_iteration_interval,
-                                                 
LATE_ITERATION_SPEEDUP_FACTOR);
-
+                                                    
LATE_ITERATION_SPEEDUP_FACTOR);
   }
   else
     next_put_interval = zone_iteration_interval;
 
   GNUNET_STATISTICS_set (statistics,
-                            "Current zone iteration interval [msec]",
-                            next_put_interval.rel_value,
-                            GNUNET_NO);
-  
-  /**
-   * Reschedule periodic put
-   */
+                        "Current zone iteration interval (ms)",
+                        next_put_interval.rel_value,
+                        GNUNET_NO); 
   zone_update_taskid = GNUNET_SCHEDULER_add_delayed (next_put_interval,
-                                &update_zone_dht_next,
-                                NULL);
-
-  GNUNET_free(nrb);
+                                                    &update_zone_dht_next,
+                                                    NULL);
 }
 
 
@@ -493,20 +467,21 @@
 {
   zone_update_taskid = GNUNET_SCHEDULER_NO_TASK;
 
-  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Scheduling DHT zone update!\n");
-  
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Scheduling DHT zone update!\n");  
   /* start counting again */
   num_public_records = 0;
   namestore_iter = GNUNET_NAMESTORE_zone_iteration_start (namestore_handle,
-                                                 NULL, //All zones
-                                                 GNUNET_NAMESTORE_RF_AUTHORITY,
-                                                 GNUNET_NAMESTORE_RF_PRIVATE,
-                                                 &put_gns_record,
-                                                 NULL);
+                                                         NULL, /* All zones */
+                                                         
GNUNET_NAMESTORE_RF_AUTHORITY,
+                                                         
GNUNET_NAMESTORE_RF_PRIVATE,
+                                                         &put_gns_record,
+                                                         NULL);
 }
 
+
 /* END DHT ZONE PROPAGATION */
 
+
 /**
  * Send shorten response back to client
  * 
@@ -514,7 +489,7 @@
  * @param name the shortened name result or NULL if cannot be shortened
  */
 static void
-send_shorten_response(void* cls, const char* name)
+send_shorten_response (void* cls, const char* name)
 {
   struct ClientShortenHandle *csh = cls;
   struct GNUNET_GNS_ClientShortenResultMessage *rmsg;
@@ -529,8 +504,8 @@
   GNUNET_STATISTICS_update (statistics,
                             "Name shorten results", 1, GNUNET_NO);
 
-  rmsg = GNUNET_malloc(sizeof(struct GNUNET_GNS_ClientShortenResultMessage) +
-                       name_len);
+  rmsg = GNUNET_malloc (sizeof (struct GNUNET_GNS_ClientShortenResultMessage) +
+                       name_len);
   
   rmsg->id = csh->unique_id;
   rmsg->header.type = htons(GNUNET_MESSAGE_TYPE_GNS_SHORTEN_RESULT);
@@ -538,11 +513,9 @@
     htons(sizeof(struct GNUNET_GNS_ClientShortenResultMessage) +
           name_len);
   memcpy (&rmsg[1], name, name_len);
-
   GNUNET_SERVER_notification_context_unicast (nc, csh->client,
                                              &rmsg->header,
                                              GNUNET_NO);
-  GNUNET_SERVER_receive_done (csh->client, GNUNET_OK);
   if (NULL != csh->namestore_task)
     GNUNET_NAMESTORE_cancel (csh->namestore_task); 
   GNUNET_free (rmsg);
@@ -564,18 +537,18 @@
  */
 static void
 process_shorten_in_private_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)
+                                       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;
   struct GNUNET_CRYPTO_ShortHashCode *szone = &csh->shorten_zone;
   struct GNUNET_CRYPTO_ShortHashCode *pzone = &csh->private_zone;
 
+  csh->namestore_task = NULL;
   if (0 == strcmp (csh->private_zone_id, ""))
     pzone = NULL;
   
@@ -583,14 +556,11 @@
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "No shorten zone in private zone!\n");
-
     strcpy (csh->shorten_zone_id, "");
     szone = NULL;
-
   }
   else
   {
-
     GNUNET_assert (rd_count == 1);
 
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -635,10 +605,10 @@
                       const struct GNUNET_CRYPTO_RsaSignature *signature)
 {
   struct ClientShortenHandle *csh = cls;
-  csh->namestore_task = NULL;
   struct GNUNET_CRYPTO_ShortHashCode *szone = &csh->shorten_zone;
   struct GNUNET_CRYPTO_ShortHashCode *pzone = &csh->private_zone;
   
+  csh->namestore_task = NULL;
   if (0 == strcmp (csh->private_zone_id, ""))
     pzone = NULL;
 
@@ -762,33 +732,24 @@
                struct GNUNET_SERVER_Client * client,
                const struct GNUNET_MessageHeader * message)
 {
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "SHORTEN");
-
   size_t msg_size = 0;
   struct ClientShortenHandle *csh;
   char name[MAX_DNS_NAME_LENGTH];
   char* nameptr = name;
 
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "SHORTEN");
   if (ntohs (message->size) < sizeof (struct GNUNET_GNS_ClientShortenMessage))
   {
-    GNUNET_break_op (0);
-    GNUNET_SERVER_receive_done (client, GNUNET_OK);
+    GNUNET_break (0);
+    GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
     return;
   }
 
 
-  struct GNUNET_GNS_ClientShortenMessage *sh_msg =
-    (struct GNUNET_GNS_ClientShortenMessage *) message;
+  const struct GNUNET_GNS_ClientShortenMessage *sh_msg =
+    (const struct GNUNET_GNS_ClientShortenMessage *) message;
   
-  msg_size = ntohs(message->size);
-
-  if (msg_size > GNUNET_SERVER_MAX_MESSAGE_SIZE)
-  {
-    GNUNET_break_op (0);
-    GNUNET_SERVER_receive_done (client, GNUNET_OK);
-    return;
-  }
-
+  msg_size = ntohs (message->size);
   csh = GNUNET_malloc(sizeof (struct ClientShortenHandle));
   csh->client = client;
   csh->unique_id = sh_msg->id;
@@ -805,6 +766,7 @@
                "SHORTEN: %s is too short\n", name);
     GNUNET_CONTAINER_DLL_remove (csh_head, csh_tail, csh);
     send_shorten_response(csh, name);
+    GNUNET_SERVER_receive_done (client, GNUNET_OK);
     return;
   }
 
@@ -813,6 +775,7 @@
                "SHORTEN: %s is too long\n", name);
     GNUNET_CONTAINER_DLL_remove (csh_head, csh_tail, csh);
     send_shorten_response(csh, name);
+    GNUNET_SERVER_receive_done (client, GNUNET_OK);
     return;
   }
   
@@ -822,6 +785,7 @@
                 "%s is not our domain. Returning\n", name);
     GNUNET_CONTAINER_DLL_remove (csh_head, csh_tail, csh);
     send_shorten_response(csh, name);
+    GNUNET_SERVER_receive_done (client, GNUNET_OK);
     return;
   }
 
@@ -840,7 +804,7 @@
 
   GNUNET_STATISTICS_update (statistics,
                             "Name shorten attempts", 1, GNUNET_NO);
-  
+  GNUNET_SERVER_receive_done (client, GNUNET_OK);
 }
 
 
@@ -850,24 +814,21 @@
  * @param cls the closure containing a client get auth handle
  * @param name the shortened name result or NULL if cannot be shortened
  */
-static void
+static void 
 send_get_auth_response(void *cls, const char* name)
 {
+  struct ClientGetAuthHandle *cah = cls;
+  struct GNUNET_GNS_ClientGetAuthResultMessage *rmsg;
+  
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message with %s\n",
               "GET_AUTH_RESULT", name);
-  struct GNUNET_GNS_ClientGetAuthResultMessage *rmsg;
-  struct ClientGetAuthHandle *cah = (struct ClientGetAuthHandle *)cls;
-  
   if (name != NULL)
   {
     GNUNET_STATISTICS_update (statistics,
                               "Authorities resolved", 1, GNUNET_NO);
-  }
-  
-  if (name == NULL)
-  {
-    name = "";
-  }
+  }  
+  if (name == NULL)  
+    name = "";  
 
   rmsg = GNUNET_malloc(sizeof(struct GNUNET_GNS_ClientGetAuthResultMessage)
                        + strlen(name) + 1);
@@ -877,9 +838,8 @@
   rmsg->header.size = 
     htons(sizeof(struct GNUNET_GNS_ClientGetAuthResultMessage) +
           strlen(name) + 1);
+  strcpy ((char*)&rmsg[1], name);
 
-  strcpy((char*)&rmsg[1], name);
-
   GNUNET_SERVER_notification_context_unicast (nc, cah->client,
                                              &rmsg->header,
                                              GNUNET_NO);
@@ -887,10 +847,7 @@
   
   GNUNET_free(rmsg);
   GNUNET_free_non_null(cah->name);
-  GNUNET_free(cah);
-
-  
-  
+  GNUNET_free(cah);  
 }
 
 
@@ -901,21 +858,20 @@
  * @param client the client
  * @param message the message
  */
-static void handle_get_authority(void *cls,
-                           struct GNUNET_SERVER_Client * client,
-                           const struct GNUNET_MessageHeader * message)
+static void 
+handle_get_authority (void *cls,
+                     struct GNUNET_SERVER_Client * client,
+                     const struct GNUNET_MessageHeader * message)
 {
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "GET_AUTH");
-
   size_t msg_size = 0;
   struct ClientGetAuthHandle *cah;
   char name[MAX_DNS_NAME_LENGTH];
   char* nameptr = name;
 
-
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "GET_AUTH");
   if (ntohs (message->size) < sizeof (struct GNUNET_GNS_ClientGetAuthMessage))
   {
-    GNUNET_break_op (0);
+    GNUNET_break (0);
     GNUNET_SERVER_receive_done (client, GNUNET_OK);
     return;
   }
@@ -926,17 +882,9 @@
     (struct GNUNET_GNS_ClientGetAuthMessage *) message;
   
   msg_size = ntohs(message->size);
+  GNUNET_STRINGS_utf8_tolower((const char*)&sh_msg[1], &nameptr);
 
-  if (msg_size > GNUNET_SERVER_MAX_MESSAGE_SIZE)
-  {
-    GNUNET_break_op (0);
-    GNUNET_SERVER_receive_done (client, GNUNET_OK);
-    return;
-  }
-  
-  GNUNET_STRINGS_utf8_tolower((char*)&sh_msg[1], &nameptr);
 
-
   cah = GNUNET_malloc(sizeof(struct ClientGetAuthHandle));
   cah->client = client;
   cah->unique_id = sh_msg->id;
@@ -950,7 +898,8 @@
     return;
   }
   
-  if (strlen (name) > MAX_DNS_NAME_LENGTH) {
+  if (strlen (name) > MAX_DNS_NAME_LENGTH) 
+  {
     GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
                "GET_AUTH: %s is too long", name);
     cah->name = NULL;
@@ -1074,7 +1023,7 @@
 
   if (ntohs (message->size) < sizeof (struct GNUNET_GNS_ClientLookupMessage))
   {
-    GNUNET_break_op (0);
+    GNUNET_break (0);
     GNUNET_SERVER_receive_done (client, GNUNET_OK);
     return;
   }
@@ -1085,16 +1034,8 @@
     (struct GNUNET_GNS_ClientLookupMessage *) message;
   
   msg_size = ntohs(message->size);
-
-  if (msg_size > GNUNET_SERVER_MAX_MESSAGE_SIZE)
+  if (GNUNET_YES == ntohl(sh_msg->have_key))
   {
-    GNUNET_break_op (0);
-    GNUNET_SERVER_receive_done (client, GNUNET_OK);
-    return;
-  }
-
-  if (1 == ntohl(sh_msg->have_key))
-  {
     pkey = (struct GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded *)&sh_msg[1];
     tmp_pkey = (char*)&sh_msg[1];
     key = GNUNET_CRYPTO_rsa_decode_key (tmp_pkey, ntohs(pkey->len));
@@ -1172,6 +1113,7 @@
                             "Record lookup attempts", 1, GNUNET_NO);
 }
 
+
 /**
  * Test if the given AF is supported by this system.
  *
@@ -1199,6 +1141,7 @@
   return GNUNET_OK;
 }
 
+
 /**
  * Process GNS requests.
  *
@@ -1210,9 +1153,6 @@
 run (void *cls, struct GNUNET_SERVER_Handle *server,
      const struct GNUNET_CONFIGURATION_Handle *c)
 {
-
-  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Initializing GNS\n");
-  
   char* keyfile;
   struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pkey;
   unsigned long long max_parallel_bg_queries = 0;
@@ -1225,8 +1165,6 @@
     {&handle_get_authority, NULL, GNUNET_MESSAGE_TYPE_GNS_GET_AUTH, 0}
   };
 
-  GNS_cfg = c;
-
   v6_enabled = test_af (AF_INET6);
   v4_enabled = test_af (AF_INET);
 
@@ -1249,25 +1187,16 @@
                      sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
                      &zone_hash);
   GNUNET_free(keyfile);
-  
-  /**
-   * handle to our local namestore
-   */
-  namestore_handle = GNUNET_NAMESTORE_connect(c);
-
+  namestore_handle = GNUNET_NAMESTORE_connect (c);
   if (NULL == namestore_handle)
   {
-    //FIXME do error handling;
-    GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
-               "Failed to connect to the namestore!\n");
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+               _("Failed to connect to the namestore!\n"));
     GNUNET_SCHEDULER_shutdown ();
     return;
   }
   
-  
-
   auto_import_pkey = GNUNET_NO;
-
   if (GNUNET_YES ==
       GNUNET_CONFIGURATION_get_value_yesno (c, "gns",
                                             "AUTO_IMPORT_PKEY"))
@@ -1287,9 +1216,9 @@
                                              "RECORD_PUT_INTERVAL",
                                              &record_put_interval))
   {
-    GNUNET_log(GNUNET_ERROR_TYPE_INFO,
-               "Record put interval: %llu\n",
-               record_put_interval);
+    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+               "Record put interval: %s\n",
+               GNUNET_STRINGS_relative_time_to_string (record_put_interval, 
GNUNET_YES));
   }
 
   if (GNUNET_OK ==
@@ -1332,7 +1261,7 @@
 
   if (NULL == dht_handle)
   {
-    GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Could not connect to DHT!\n");
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not connect to DHT!\n");
   }
   
   if (gns_resolver_init(namestore_handle, dht_handle, zone_hash, c,

Modified: gnunet/src/gns/gnunet-service-gns_resolver.c
===================================================================
--- gnunet/src/gns/gnunet-service-gns_resolver.c        2012-09-20 10:04:50 UTC 
(rev 23907)
+++ gnunet/src/gns/gnunet-service-gns_resolver.c        2012-09-20 10:10:04 UTC 
(rev 23908)
@@ -35,6 +35,7 @@
 #include "gnunet_dnsparser_lib.h"
 #include "gns_protocol.h"
 #include "gnunet_gns_service.h"
+#include "gns_common.h"
 #include "block_gns.h"
 #include "gns.h"
 #include "gnunet-service-gns_resolver.h"
@@ -459,30 +460,19 @@
                       const struct GNUNET_CRYPTO_RsaSignature *signature)
 {
   struct GetPseuAuthorityHandle* gph = cls;
-  struct GNUNET_CRYPTO_ShortHashCode name_hash;
   struct GNUNET_HashCode lookup_key;
-  struct GNUNET_CRYPTO_HashAsciiEncoded lookup_key_string;
-  struct GNUNET_HashCode name_hash_double;
-  struct GNUNET_HashCode zone_hash_double;
-  int i;
+  unsigned int i;
   uint32_t xquery;
   
   gph->namestore_task = NULL;
   /* no pseu found */
   if (0 == rd_count)
   {
-    /**
-     * check dht
-     */
-    GNUNET_CRYPTO_short_hash ("+", strlen ("+"), &name_hash);
-    GNUNET_CRYPTO_short_hash_double (&name_hash, &name_hash_double);
-    GNUNET_CRYPTO_short_hash_double (&gph->auth->zone, &zone_hash_double);
-    GNUNET_CRYPTO_hash_xor (&name_hash_double, &zone_hash_double, &lookup_key);
-    GNUNET_CRYPTO_hash_to_enc (&lookup_key, &lookup_key_string);
-
+    GNUNET_GNS_get_key_for_record (GNUNET_GNS_TLD_PLUS, &gph->auth->zone, 
&lookup_key);
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-               "GNS_AUTO_PSEU: starting dht lookup for %s with key: %s\n",
-               "+", (char*)&lookup_key_string);
+               "GNS_AUTO_PSEU: starting dht lookup for %s with key: %s\n",
+               GNUNET_GNS_TLD_PLUS, 
+               GNUNET_h2s (&lookup_key));
 
     gph->timeout = GNUNET_SCHEDULER_add_delayed (DHT_LOOKUP_TIMEOUT,
                                          &handle_auth_discovery_timeout, gph);
@@ -505,7 +495,7 @@
 
   for (i=0; i < rd_count; i++)
   {
-    if (0 != (strcmp (name, "+")))
+    if (0 != (strcmp (name, GNUNET_GNS_TLD_PLUS)))
       continue;
 
     if (rd[i].record_type != GNUNET_GNS_RECORD_PSEU)
@@ -1127,23 +1117,14 @@
 resolve_record_dht (struct ResolverHandle *rh)
 {
   uint32_t xquery;
-  struct GNUNET_CRYPTO_ShortHashCode name_hash;
   struct GNUNET_HashCode lookup_key;
-  struct GNUNET_HashCode name_hash_double;
-  struct GNUNET_HashCode zone_hash_double;
-  struct GNUNET_CRYPTO_HashAsciiEncoded lookup_key_string;
   struct RecordLookupHandle *rlh = rh->proc_cls;
   struct ResolverHandle *rh_heap_root;
 
-  GNUNET_CRYPTO_short_hash (rh->name, strlen (rh->name), &name_hash);
-  GNUNET_CRYPTO_short_hash_double (&name_hash, &name_hash_double);
-  GNUNET_CRYPTO_short_hash_double (&rh->authority, &zone_hash_double);
-  GNUNET_CRYPTO_hash_xor (&name_hash_double, &zone_hash_double, &lookup_key);
-  GNUNET_CRYPTO_hash_to_enc (&lookup_key, &lookup_key_string);
-
+  GNUNET_GNS_get_key_for_record (rh->name, &rh->authority, &lookup_key);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "GNS_PHASE_REC-%llu: starting dht lookup for %s with key: %s\n",
-              rh->id, rh->name, (char*)&lookup_key_string);
+              rh->id, rh->name, GNUNET_h2s (&lookup_key));
 
   //rh->timeout_task = GNUNET_SCHEDULER_NO_TASK;
   rh->dht_heap_node = NULL;
@@ -2191,10 +2172,9 @@
   uint32_t num_records;
   char* name = NULL;
   char* rd_data = (char*) data;
-  int i;
+  uint32_t i;
   int rd_size;
-  struct GNUNET_CRYPTO_ShortHashCode zone, name_hash;
-  struct GNUNET_HashCode zone_hash_double, name_hash_double;
+  struct GNUNET_CRYPTO_ShortHashCode zone;
 
   GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
              "GNS_PHASE_DELEGATE_DHT-%llu: Got DHT result\n", rh->id);
@@ -2301,13 +2281,9 @@
       }
 
     }
+    GNUNET_GNS_get_zone_from_key (name, key, &zone);
 
 
-    GNUNET_CRYPTO_short_hash(name, strlen(name), &name_hash);
-    GNUNET_CRYPTO_short_hash_double(&name_hash, &name_hash_double);
-    GNUNET_CRYPTO_hash_xor(key, &name_hash_double, &zone_hash_double);
-    GNUNET_CRYPTO_short_hash_from_truncation (&zone_hash_double, &zone);
-
     /* Save to namestore
     if (0 != GNUNET_CRYPTO_short_hash_cmp(&rh->authority_chain_head->zone,
                                           &zone))
@@ -2802,21 +2778,12 @@
 resolve_delegation_dht(struct ResolverHandle *rh)
 {
   uint32_t xquery;
-  struct GNUNET_CRYPTO_ShortHashCode name_hash;
-  struct GNUNET_HashCode name_hash_double;
-  struct GNUNET_HashCode zone_hash_double;
   struct GNUNET_HashCode lookup_key;
   struct ResolverHandle *rh_heap_root;
   
   pop_tld(rh->name, rh->authority_name);
 
-  //FIXME handle return values here
-  GNUNET_CRYPTO_short_hash(rh->authority_name,
-                     strlen(rh->authority_name),
-                     &name_hash);
-  GNUNET_CRYPTO_short_hash_double(&name_hash, &name_hash_double);
-  GNUNET_CRYPTO_short_hash_double(&rh->authority, &zone_hash_double);
-  GNUNET_CRYPTO_hash_xor(&name_hash_double, &zone_hash_double, &lookup_key);
+  GNUNET_GNS_get_key_for_record (rh->authority_name, &rh->authority, 
&lookup_key);
   
   rh->dht_heap_node = NULL;
 

Modified: gnunet/src/gns/plugin_block_gns.c
===================================================================
--- gnunet/src/gns/plugin_block_gns.c   2012-09-20 10:04:50 UTC (rev 23907)
+++ gnunet/src/gns/plugin_block_gns.c   2012-09-20 10:10:04 UTC (rev 23908)
@@ -29,6 +29,7 @@
 #include "gnunet_namestore_service.h"
 #include "block_gns.h"
 #include "gnunet_signatures.h"
+#include "gns_common.h"
 
 /**
  * Number of bits we set per entry in the bloomfilter.
@@ -62,15 +63,14 @@
                           size_t xquery_size, const void *reply_block,
                           size_t reply_block_size)
 {
-  char* name;
-  struct GNUNET_HashCode pkey_hash_double;
+  const char* name;
   struct GNUNET_HashCode query_key;
-  struct GNUNET_HashCode name_hash_double;
   struct GNUNET_HashCode mhash;
   struct GNUNET_HashCode chash;
   struct GNUNET_CRYPTO_ShortHashCode pkey_hash;
-  struct GNUNET_CRYPTO_ShortHashCode name_hash;
   struct GNSNameRecordBlock *nrb;
+  struct GNUNET_CRYPTO_HashAsciiEncoded xor_exp;
+  struct GNUNET_CRYPTO_HashAsciiEncoded xor_got;
   uint32_t rd_count;
   char* rd_data = NULL;
   int rd_len;
@@ -98,20 +98,13 @@
   /* this is a reply */
 
   nrb = (struct GNSNameRecordBlock *)reply_block;
-  name = (char*)&nrb[1];
-  GNUNET_CRYPTO_short_hash(&nrb->public_key,
-                     sizeof(nrb->public_key),
-                     &pkey_hash);
-
-  GNUNET_CRYPTO_short_hash(name, strlen(name), &name_hash);
+  name = (const char*)&nrb[1];
   
-  GNUNET_CRYPTO_short_hash_double(&name_hash, &name_hash_double);
-  GNUNET_CRYPTO_short_hash_double(&pkey_hash, &pkey_hash_double);
-
-  GNUNET_CRYPTO_hash_xor(&pkey_hash_double, &name_hash_double, &query_key);
+  GNUNET_CRYPTO_short_hash (&nrb->public_key,
+                           sizeof(nrb->public_key),
+                           &pkey_hash);
+  GNUNET_GNS_get_key_for_record (name, &pkey_hash, &query_key);
   
-  struct GNUNET_CRYPTO_HashAsciiEncoded xor_exp;
-  struct GNUNET_CRYPTO_HashAsciiEncoded xor_got;
   GNUNET_CRYPTO_hash_to_enc (&query_key, &xor_exp);
   GNUNET_CRYPTO_hash_to_enc (query, &xor_got);
 
@@ -220,25 +213,23 @@
                          const void *block, size_t block_size,
                          struct GNUNET_HashCode * key)
 {
+  struct GNUNET_CRYPTO_ShortHashCode pkey_hash;
+  const struct GNSNameRecordBlock *nrb = (const struct GNSNameRecordBlock 
*)block;
+  const char *name;
+
   if (type != GNUNET_BLOCK_TYPE_GNS_NAMERECORD)
     return GNUNET_SYSERR;
-  struct GNUNET_CRYPTO_ShortHashCode name_hash;
-  struct GNUNET_CRYPTO_ShortHashCode pkey_hash;
-  struct GNUNET_HashCode name_hash_double;
-  struct GNUNET_HashCode pkey_hash_double;
-
-  struct GNSNameRecordBlock *nrb = (struct GNSNameRecordBlock *)block;
-
-  GNUNET_CRYPTO_short_hash(&nrb[1], strlen((char*)&nrb[1]), &name_hash);
-  GNUNET_CRYPTO_short_hash(&nrb->public_key,
-                     sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
-                     &pkey_hash);
-  
-  GNUNET_CRYPTO_short_hash_double(&name_hash, &name_hash_double);
-  GNUNET_CRYPTO_short_hash_double(&pkey_hash, &pkey_hash_double);
-
-  GNUNET_CRYPTO_hash_xor(&name_hash_double, &pkey_hash_double, key);
-  
+  name = (const char *) &nrb[1];
+  if (NULL == memchr (name, '\0', block_size - sizeof (struct 
GNSNameRecordBlock)))
+  {
+    /* malformed, no 0-termination in name */
+    GNUNET_break_op (0);
+    return GNUNET_SYSERR; 
+  }
+  GNUNET_CRYPTO_short_hash (&nrb->public_key,
+                           sizeof (struct 
GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
+                           &pkey_hash);
+  GNUNET_GNS_get_key_for_record (name, &pkey_hash, key);
   return GNUNET_OK;
 }
 

Modified: gnunet/src/namestore/plugin_namestore_sqlite.c
===================================================================
--- gnunet/src/namestore/plugin_namestore_sqlite.c      2012-09-20 10:04:50 UTC 
(rev 23907)
+++ gnunet/src/namestore/plugin_namestore_sqlite.c      2012-09-20 10:10:04 UTC 
(rev 23908)
@@ -405,6 +405,7 @@
   struct GNUNET_CRYPTO_ShortHashCode nh;
   size_t name_len;
   int n;
+
   name_len = strlen (name);
   GNUNET_CRYPTO_short_hash (name, name_len, &nh);
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]