-bugfixes, tests
authorMartin Schanzenbach <mschanzenbach@posteo.de>
Mon, 12 Mar 2012 13:12:37 +0000 (13:12 +0000)
committerMartin Schanzenbach <mschanzenbach@posteo.de>
Mon, 12 Mar 2012 13:12:37 +0000 (13:12 +0000)
src/gns/Makefile.am
src/gns/gns_api.c
src/gns/gnunet-service-gns.c
src/gns/plugin_block_gns.c
src/gns/test_gns_dht_delegated_lookup.c
src/namestore/namestore_common.c

index 9aafedf16b7a8ec6d9cf1fcbd3010f8b78f74798..08da0a8e2e8b079439261e1b73122d8a4709d811 100644 (file)
@@ -30,7 +30,8 @@ check_PROGRAMS = \
   test_gns_simple_shorten \
   test_gns_simple_get_authority \
   test_gns_simple_lookup \
-  test_gns_simple_delegated_lookup
+  test_gns_simple_delegated_lookup \
+  test_gns_dht_delegated_lookup
 
 
 #  test_gns_simple_lookup
@@ -78,18 +79,20 @@ test_gns_simple_delegated_lookup_DEPENDENCIES = \
   $(top_builddir)/src/gns/libgnunetgns.la \
   $(top_builddir)/src/testing/libgnunettesting.la
 
-#test_gns_dht_delegated_lookup_SOURCES = \
-#  test_gns_dht_delegated_lookup.c
-#test_gns_dht_delegated_lookup_LDADD = \
-#  $(top_builddir)/src/util/libgnunetutil.la \
-#  $(top_builddir)/src/namestore/libgnunetnamestore.la \
-#  $(top_builddir)/src/dht/libgnunetdht.la \
-#  $(top_builddir)/src/testing/libgnunettesting.la
-#test_gns_dht_delegated_lookup_DEPENDENCIES = \
-#  $(top_builddir)/src/util/libgnunetutil.la \
-#  $(top_builddir)/src/namestore/libgnunetnamestore.la \
-#  $(top_builddir)/src/dht/libgnunetdht.la \
-#  $(top_builddir)/src/testing/libgnunettesting.la
+test_gns_dht_delegated_lookup_SOURCES = \
+  test_gns_dht_delegated_lookup.c
+test_gns_dht_delegated_lookup_LDADD = \
+  $(top_builddir)/src/util/libgnunetutil.la \
+  $(top_builddir)/src/namestore/libgnunetnamestore.la \
+  $(top_builddir)/src/dht/libgnunetdht.la \
+  $(top_builddir)/src/gns/libgnunetgns.la \
+  $(top_builddir)/src/testing/libgnunettesting.la
+test_gns_dht_delegated_lookup_DEPENDENCIES = \
+  $(top_builddir)/src/util/libgnunetutil.la \
+  $(top_builddir)/src/namestore/libgnunetnamestore.la \
+  $(top_builddir)/src/dht/libgnunetdht.la \
+  $(top_builddir)/src/gns/libgnunetgns.la \
+  $(top_builddir)/src/testing/libgnunettesting.la
 
 test_gns_simple_shorten_SOURCES = \
   test_gns_simple_shorten.c
index d15f1908e511a1758804cf9f1ba8594ea241dead..d6709a96e6875f28b80453ff1119b2a6d4a6f085 100644 (file)
@@ -636,7 +636,7 @@ GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle,
   }
 
   msize = sizeof (struct GNUNET_GNS_ClientLookupMessage) + strlen(name) + 1;
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Trying to shorten %s in GNS\n", name);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Trying to lookup %s in GNS\n", name);
 
   qe = GNUNET_malloc(sizeof (struct GNUNET_GNS_QueueEntry));
   qe->gns_handle = handle;
index 09054d2b9e1848e6f981537f1c07ebc33512773c..480d6bea9ace27de86da3d9097f790722aa226e3 100644 (file)
@@ -863,6 +863,8 @@ process_delegation_result_dht(void* cls,
   int rd_size;
   GNUNET_HashCode zone, name_hash;
   
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Got DHT result\n");
+
   if (data == NULL)
     return;
   
index 4c8ab3eb97967f4173bec8a65f006fc01de1399b..329088280c0299c5178b79966f377376dc124bf6 100644 (file)
@@ -75,6 +75,9 @@ block_plugin_gns_evaluate (void *cls, enum GNUNET_BLOCK_Type type,
   uint32_t record_xquery;
   unsigned int record_match;
 
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+             "BLOCK_TEST\n");
+
   if (type != GNUNET_BLOCK_TYPE_GNS_NAMERECORD)
     return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED;
   if (reply_block_size == 0)
@@ -90,6 +93,15 @@ block_plugin_gns_evaluate (void *cls, enum GNUNET_BLOCK_Type type,
 
   GNUNET_CRYPTO_hash_xor(&pkey_hash, &name_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);
+
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+             "BLOCK_TEST for %s got %s expected %s\n",
+             name, (char*) &xor_got, (char*) &xor_exp);
+
   /* Check query key against public key */
   if (0 != GNUNET_CRYPTO_hash_cmp(query, &query_key))
     return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
@@ -124,6 +136,9 @@ block_plugin_gns_evaluate (void *cls, enum GNUNET_BLOCK_Type type,
     {
       
       exp = GNUNET_TIME_absolute_min (exp, rd[i].expiration);
+      
+      GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+                 "Got record of size %d\n", rd[i].data_size);
 
       if ((record_xquery != 0)
           && (rd[i].record_type == record_xquery))
@@ -131,6 +146,10 @@ block_plugin_gns_evaluate (void *cls, enum GNUNET_BLOCK_Type type,
         record_match++;
       }
     }
+    
+    GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+               "Verifying signature of %d records for name %s\n",
+               rd_count, name);
 
     if (GNUNET_OK != GNUNET_NAMESTORE_verify_signature (&nrb->public_key,
                                                         exp,
@@ -144,9 +163,12 @@ block_plugin_gns_evaluate (void *cls, enum GNUNET_BLOCK_Type type,
     }
   }
   
-  //No record matches query
   if ((record_xquery != 0) && (record_match == 0))
+  {
+    GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+               "No record matches query!\n");
     return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
+  }
 
   GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Records match\n");
   
index dc73c7b58691f8e01c01e292484f8f3657fb234f..6fc4a42bb9535d97e03b49a6099582f69b5e9f06 100644 (file)
@@ -83,6 +83,8 @@ static int ok;
 
 static struct GNUNET_NAMESTORE_Handle *namestore_handle;
 
+static struct GNUNET_GNS_Handle *gns_handle;
+
 static struct GNUNET_DHT_Handle *dht_handle;
 
 const struct GNUNET_CONFIGURATION_Handle *cfg;
@@ -108,42 +110,39 @@ shutdown_callback (void *cls, const char *emsg)
   GNUNET_log (GNUNET_ERROR_TYPE_INFO, "done(ret=%d)!\n", ok);
 }
 
-/**
- * Function scheduled to be run on the successful start of services
- * tries to look up the dns record for TEST_DOMAIN
- */
+
 static void
-finish_testing (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+on_lookup_result(void *cls, uint32_t rd_count,
+                 const struct GNUNET_NAMESTORE_RecordData *rd)
 {
-  struct hostent *he;
   struct in_addr a;
+  int i;
   char* addr;
-  GNUNET_NAMESTORE_disconnect(namestore_handle, GNUNET_YES);
-  GNUNET_DHT_disconnect(dht_handle);
-
-  he = gethostbyname (TEST_DOMAIN);
-
-  if (!he)
+  
+  if (rd_count == 0)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                "gethostbyname failed, rp_filtering?\n");
+                "Lookup failed, rp_filtering?\n");
     ok = 2;
   }
   else
   {
     ok = 1;
-    GNUNET_log (GNUNET_ERROR_TYPE_INFO, "name: %s\n", he->h_name);
-    while (*he->h_addr_list)
+    GNUNET_log (GNUNET_ERROR_TYPE_INFO, "name: %s\n", (char*)cls);
+    for (i=0; i<rd_count; i++)
     {
-      memcpy(&a, *he->h_addr_list++, sizeof(a));
-      addr = inet_ntoa(a);
-      GNUNET_log (GNUNET_ERROR_TYPE_INFO, "address: %s\n", addr);
-      if (0 == strcmp(addr, TEST_IP))
+      GNUNET_log (GNUNET_ERROR_TYPE_INFO, "type: %d\n", rd[i].record_type);
+      if (rd[i].record_type == GNUNET_GNS_RECORD_TYPE_A)
       {
-        GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+        memcpy(&a, rd[i].data, sizeof(a));
+        addr = inet_ntoa(a);
+        GNUNET_log (GNUNET_ERROR_TYPE_INFO, "address: %s\n", addr);
+        if (0 == strcmp(addr, TEST_IP))
+        {
+          GNUNET_log (GNUNET_ERROR_TYPE_INFO,
                     "%s correctly resolved to %s!\n", TEST_DOMAIN, addr);
-        ok = 0;
+          ok = 0;
+        }
       }
       else
       {
@@ -156,6 +155,28 @@ finish_testing (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
                               GNUNET_YES, GNUNET_NO);
 }
 
+
+/**
+ * Function scheduled to be run on the successful start of services
+ * tries to look up the dns record for TEST_DOMAIN
+ */
+static void
+commence_testing (void *cls, int32_t success, const char *emsg)
+{
+  GNUNET_NAMESTORE_disconnect(namestore_handle, GNUNET_YES);
+
+  gns_handle = GNUNET_GNS_connect(cfg);
+
+  if (NULL == gns_handle)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Failed to connect to GNS!\n");
+  }
+
+  GNUNET_GNS_lookup(gns_handle, TEST_DOMAIN, GNUNET_GNS_RECORD_TYPE_A,
+                    &on_lookup_result, TEST_DOMAIN);
+}
+
 /**
  * Continuation for the GNUNET_DHT_get_stop call, so that we don't shut
  * down the peers without freeing memory associated with GET request.
@@ -214,7 +235,7 @@ put_dht(void *cls, int32_t success, const char *emsg)
   nrb->public_key = bob_pkey;
   nrb->rd_count = htonl(1);
   memset(&nrb[1], 0, strlen(TEST_RECORD_NAME) + 1);
-  memcpy(&nrb[1], TEST_RECORD_NAME, strlen(TEST_RECORD_NAME));
+  strcpy(&nrb[1], TEST_RECORD_NAME);
   nrb_data = (char*)&nrb[1];
   nrb_data += strlen(TEST_RECORD_NAME) + 1;
 
@@ -247,7 +268,7 @@ put_dht(void *cls, int32_t success, const char *emsg)
                   NULL,
                   NULL);
   GNUNET_free (nrb);
-  GNUNET_SCHEDULER_add_delayed(TIMEOUT, &finish_testing, NULL);
+  GNUNET_SCHEDULER_add_delayed(TIMEOUT, &commence_testing, NULL);
 }
 
 static void
@@ -345,7 +366,7 @@ check ()
   int ret;
 
   /* Arguments for GNUNET_PROGRAM_run */
-  char *const argv[] = { "test-gns-simple-lookup", /* Name to give running binary */
+  char *const argv[] = { "test-gns-dht-delegated-lookup", /* Name to give running binary */
     "-c",
     "test_gns_simple_lookup.conf",       /* Config file to use */
 #if VERBOSE
@@ -359,12 +380,12 @@ check ()
   /* Run the run function as a new program */
   ret =
       GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
-                          "test-gns-simple-lookup", "nohelp", options, &run,
+                          "test-gns-dht-delegated-lookup", "nohelp", options, &run,
                           &ok);
   if (ret != GNUNET_OK)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                "`test-gns-simple-lookup': Failed with error code %d\n", ret);
+                "`test-gns-dht-delegated-lookup': Failed with error code %d\n", ret);
   }
   return ok;
 }
index b8236edf0b64bb7987c0c77cbcda4e613d8e00cf..72a2625aedf482bfac1798078e0a75b22551f2b5 100644 (file)
@@ -86,7 +86,7 @@ GNUNET_NAMESTORE_records_get_size (unsigned int rd_count,
   ret = sizeof (struct NetworkRecord) * rd_count;
   for (i=0;i<rd_count;i++)
   {
-    GNUNET_assert (ret + rd[i].data_size >= ret);
+    GNUNET_assert ((ret + rd[i].data_size) >= ret);
     ret += rd[i].data_size;
   }
   return ret;