gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r22287 - gnunet/src/gns
Date: Tue, 26 Jun 2012 13:50:14 +0200

Author: schanzen
Date: 2012-06-26 13:50:13 +0200 (Tue, 26 Jun 2012)
New Revision: 22287

Modified:
   gnunet/src/gns/test_gns_ns_lookup.c
Log:
-test for working system resolver

Modified: gnunet/src/gns/test_gns_ns_lookup.c
===================================================================
--- gnunet/src/gns/test_gns_ns_lookup.c 2012-06-26 11:47:56 UTC (rev 22286)
+++ gnunet/src/gns/test_gns_ns_lookup.c 2012-06-26 11:50:13 UTC (rev 22287)
@@ -28,6 +28,7 @@
 #include "block_dns.h"
 #include "gnunet_signatures.h"
 #include "gnunet_namestore_service.h"
+#include "gnunet_resolver_service.h"
 #include "gnunet_dnsparser_lib.h"
 #include "gnunet_gns_service.h"
 
@@ -65,10 +66,14 @@
 /* Global return value (0 for success, anything else for failure) */
 static int ok;
 
+static int resolver_working;
+
 static struct GNUNET_NAMESTORE_Handle *namestore_handle;
 
 static struct GNUNET_GNS_Handle *gns_handle;
 
+static struct GNUNET_RESOLVER_RequestHandle *resolver_handle;
+
 const struct GNUNET_CONFIGURATION_Handle *cfg;
 
 /**
@@ -224,18 +229,12 @@
 }
 
 
-/**
- * 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)
+start_lookup (void)
 {
+
   
-  
-  GNUNET_NAMESTORE_disconnect(namestore_handle, GNUNET_YES);
-  
-  gns_handle = GNUNET_GNS_connect(cfg);
+  gns_handle = GNUNET_GNS_connect (cfg);
 
   if (NULL == gns_handle)
   {
@@ -244,21 +243,76 @@
     ok = 2;
   }
 
-  GNUNET_GNS_lookup(gns_handle, TEST_DOMAIN, GNUNET_GNS_RECORD_TYPE_A,
-                    GNUNET_YES,
-                    NULL,
-                    &on_lookup_result, TEST_DOMAIN);
+  GNUNET_GNS_lookup (gns_handle, TEST_DOMAIN, GNUNET_GNS_RECORD_TYPE_A,
+                     GNUNET_YES,
+                     NULL,
+                     &on_lookup_result, TEST_DOMAIN);
 }
 
 
+static void
+handle_dns_test (void *cls,
+                 const struct sockaddr *addr,
+                 socklen_t addrlen)
+{
+  struct sockaddr_in* sai;
+
+  if (NULL == addr)
+  {
+    /* end of results */
+    if (GNUNET_YES != resolver_working)
+    {
+      ok = 0;
+      GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                  "System resolver not working. Test inconclusive!\n");
+      GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Shutting down peer1!\n");
+      GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
+      return;
+    }
+    start_lookup ();
+    return;
+  }
+
+  if (addrlen == sizeof (struct sockaddr_in))
+  {
+    sai = (struct sockaddr_in*) addr;
+    if (0 == strcmp (TEST_IP, inet_ntoa (sai->sin_addr)))
+      resolver_working = GNUNET_YES;
+  }
+}
+
+
+
+
 /**
+ * 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);
+  resolver_working = GNUNET_NO;
+
+  GNUNET_RESOLVER_connect (cfg);
+  resolver_handle = GNUNET_RESOLVER_ip_get (TEST_RECORD_NS,
+                                            AF_INET,
+                                            TIMEOUT,
+                                            &handle_dns_test,
+                                            NULL);
+}
+
+
+/**
  * Continuation for the GNUNET_DHT_get_stop call, so that we don't shut
  * down the peers without freeing memory associated with GET request.
  */
 static void
 end_badly_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
-
+  if (resolver_handle != NULL)
+    GNUNET_RESOLVER_request_cancel (resolver_handle);
   if (pg != NULL)
     GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
   GNUNET_SCHEDULER_cancel (die_task);




reply via email to

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