fix
[oweals/gnunet.git] / src / arm / test_arm_api.c
index 22fa3716ed8d7b16691f47d3b2bbe9166017c54b..6ec95f4a0b1747c51bdb6d7fc818c42a30132e7f 100644 (file)
@@ -4,7 +4,7 @@
 
      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 2, or (at your
+     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
@@ -34,7 +34,9 @@
 
 #define START_ARM GNUNET_YES
 
-#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
+#define START_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 500)
+
+#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15)
 
 static struct GNUNET_SCHEDULER_Handle *sched;
 
@@ -44,13 +46,21 @@ static struct GNUNET_ARM_Handle *arm;
 
 static int ok = 1;
 
+static void
+arm_stopped (void *cls, int success)
+{
+  if (success != GNUNET_NO)        
+    ok = 3;
+  else if (ok == 1)
+    ok = 0;
+}
 
 static void
 arm_notify_stop (void *cls, int success)
 {
   GNUNET_assert (success == GNUNET_NO);
 #if START_ARM
-  GNUNET_ARM_stop_service (arm, "arm", TIMEOUT, NULL, NULL);
+  GNUNET_ARM_stop_service (arm, "arm", TIMEOUT, &arm_stopped, NULL);
 #endif
 }
 
@@ -60,7 +70,11 @@ dns_notify (void *cls, const struct sockaddr *addr, socklen_t addrlen)
 {
   if (addr == NULL)
     {
-      GNUNET_assert (ok == 0);
+      if (ok != 0)
+       {
+         GNUNET_break (0);
+         ok = 2;
+       }
       GNUNET_ARM_stop_service (arm, "resolver", TIMEOUT, &arm_notify_stop, NULL);
       return;
     }
@@ -72,7 +86,15 @@ dns_notify (void *cls, const struct sockaddr *addr, socklen_t addrlen)
 static void
 resolver_notify (void *cls, int success)
 {
-  GNUNET_assert (success == GNUNET_YES);
+  if (success != GNUNET_YES)
+    {
+      GNUNET_break (0);
+      ok = 2;
+#if START_ARM
+      GNUNET_ARM_stop_service (arm, "arm", TIMEOUT, &arm_stopped, NULL);
+#endif
+      return;
+    }
   GNUNET_RESOLVER_ip_get (sched,
                           cfg,
                           "localhost", AF_INET, TIMEOUT, &dns_notify, NULL);
@@ -82,8 +104,15 @@ resolver_notify (void *cls, int success)
 static void
 arm_notify (void *cls, int success)
 {
-  GNUNET_assert (success == GNUNET_YES);
-  GNUNET_ARM_start_service (arm, "resolver", TIMEOUT, &resolver_notify, NULL);
+  if (success != GNUNET_YES)
+    {
+      GNUNET_break (0);
+      ok = 2;
+#if START_ARM
+      GNUNET_ARM_stop_service (arm, "arm", TIMEOUT, &arm_stopped, NULL);
+#endif
+    }
+  GNUNET_ARM_start_service (arm, "resolver", START_TIMEOUT, &resolver_notify, NULL);
 }
 
 
@@ -98,7 +127,7 @@ task (void *cls,
   sched = s;
   arm = GNUNET_ARM_connect (cfg, sched, NULL);
 #if START_ARM
-  GNUNET_ARM_start_service (arm, "arm", TIMEOUT, &arm_notify, NULL);
+  GNUNET_ARM_start_service (arm, "arm", START_TIMEOUT, &arm_notify, NULL);
 #else
   arm_notify (NULL, GNUNET_YES);
 #endif