gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r20450 - gnunet/src/gns


From: gnunet
Subject: [GNUnet-SVN] r20450 - gnunet/src/gns
Date: Mon, 12 Mar 2012 11:32:05 +0100

Author: schanzen
Date: 2012-03-12 11:32:05 +0100 (Mon, 12 Mar 2012)
New Revision: 20450

Modified:
   gnunet/src/gns/Makefile.am
   gnunet/src/gns/test_gns_simple_delegated_lookup.c
Log:
-new test


Modified: gnunet/src/gns/Makefile.am
===================================================================
--- gnunet/src/gns/Makefile.am  2012-03-12 10:18:53 UTC (rev 20449)
+++ gnunet/src/gns/Makefile.am  2012-03-12 10:32:05 UTC (rev 20450)
@@ -28,7 +28,8 @@
 
 check_PROGRAMS = \
   test_gns_simple_shorten \
-  test_gns_simple_lookup
+  test_gns_simple_lookup \
+  test_gns_simple_delegated_lookup
 
 
 #  test_gns_simple_lookup
@@ -63,16 +64,18 @@
   $(top_builddir)/src/gns/libgnunetgns.la \
   $(top_builddir)/src/testing/libgnunettesting.la
 
-#test_gns_simple_delegated_lookup_SOURCES = \
-#  test_gns_simple_delegated_lookup.c
-#test_gns_simple_delegated_lookup_LDADD = \
-#  $(top_builddir)/src/util/libgnunetutil.la \
-#  $(top_builddir)/src/namestore/libgnunetnamestore.la \
-#  $(top_builddir)/src/testing/libgnunettesting.la
-#test_gns_simple_delegated_lookup_DEPENDENCIES = \
-#  $(top_builddir)/src/util/libgnunetutil.la \
-#  $(top_builddir)/src/namestore/libgnunetnamestore.la \
-#  $(top_builddir)/src/testing/libgnunettesting.la
+test_gns_simple_delegated_lookup_SOURCES = \
+  test_gns_simple_delegated_lookup.c
+test_gns_simple_delegated_lookup_LDADD = \
+  $(top_builddir)/src/util/libgnunetutil.la \
+  $(top_builddir)/src/namestore/libgnunetnamestore.la \
+  $(top_builddir)/src/gns/libgnunetgns.la \
+  $(top_builddir)/src/testing/libgnunettesting.la
+test_gns_simple_delegated_lookup_DEPENDENCIES = \
+  $(top_builddir)/src/util/libgnunetutil.la \
+  $(top_builddir)/src/namestore/libgnunetnamestore.la \
+  $(top_builddir)/src/gns/libgnunetgns.la \
+  $(top_builddir)/src/testing/libgnunettesting.la
 
 #test_gns_dht_delegated_lookup_SOURCES = \
 #  test_gns_dht_delegated_lookup.c

Modified: gnunet/src/gns/test_gns_simple_delegated_lookup.c
===================================================================
--- gnunet/src/gns/test_gns_simple_delegated_lookup.c   2012-03-12 10:18:53 UTC 
(rev 20449)
+++ gnunet/src/gns/test_gns_simple_delegated_lookup.c   2012-03-12 10:32:05 UTC 
(rev 20450)
@@ -80,6 +80,8 @@
 
 static struct GNUNET_NAMESTORE_Handle *namestore_handle;
 
+static struct GNUNET_GNS_Handle *gns_handle;
+
 const struct GNUNET_CONFIGURATION_Handle *cfg;
 
 /**
@@ -98,43 +100,38 @@
   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, int32_t success, const char *emsg)
+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_log (GNUNET_ERROR_TYPE_DEBUG,
-              "disconnecting from namestore\n");
-  GNUNET_NAMESTORE_disconnect(namestore_handle, GNUNET_YES);
-
-  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
       {
@@ -147,7 +144,29 @@
                               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.
  */
@@ -236,7 +255,9 @@
   rd.data_size = sizeof(struct in_addr);
   rd.data = web;
   rd.record_type = GNUNET_DNSPARSER_TYPE_A;
-  sig = GNUNET_NAMESTORE_create_signature(bob_key, TEST_RECORD_NAME,
+  sig = GNUNET_NAMESTORE_create_signature(bob_key,
+                                          GNUNET_TIME_absolute_get_forever(),
+                                          TEST_RECORD_NAME,
                                           &rd, 1);
 
   GNUNET_NAMESTORE_record_put (namestore_handle,
@@ -246,7 +267,7 @@
                                1,
                                &rd,
                                sig,
-                               &finish_testing,
+                               &commence_testing,
                                NULL);
 
 }




reply via email to

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