- assert hard
[oweals/gnunet.git] / src / arm / test_exponential_backoff.c
index 029ed145ad1fff480b92dd3b29f5921ad2b86d54..34ebad1644a5da739456c0fdd27ead26adf3c09b 100644 (file)
@@ -28,8 +28,6 @@
 #include "gnunet_program_lib.h"
 #include "gnunet_protocols.h"
 
-#define VERBOSE GNUNET_EXTRA_LOGGING
-
 #define START_ARM GNUNET_YES
 
 #define LOG_BACKOFF GNUNET_NO
@@ -113,59 +111,43 @@ service_shutdown_handler (void *cls, const struct GNUNET_MessageHeader *msg)
 {
   struct ShutdownContext *shutdown_ctx = cls;
 
-  if ((msg == NULL) && (shutdown_ctx->confirmed != GNUNET_YES))
-    {
-      /* Means the other side closed the connection and never confirmed a shutdown */
-      GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                 "Service handle shutdown before ACK!\n");
-      if (shutdown_ctx->cont != NULL)
-       shutdown_ctx->cont (shutdown_ctx->cont_cls, GNUNET_SYSERR);
-      GNUNET_SCHEDULER_cancel (shutdown_ctx->cancel_task);
-      GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO);
-      GNUNET_free (shutdown_ctx);
-    }
-  else if ((msg == NULL) && (shutdown_ctx->confirmed == GNUNET_YES))
-    {
-#if VERBOSE
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Service shutdown complete.\n");
-#endif
-      if (shutdown_ctx->cont != NULL)
-       shutdown_ctx->cont (shutdown_ctx->cont_cls, GNUNET_NO);
-
-      GNUNET_SCHEDULER_cancel (shutdown_ctx->cancel_task);
-      GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO);
-      GNUNET_free (shutdown_ctx);
-    }
-  else
-    {
-      GNUNET_assert (ntohs (msg->size) ==
-                    sizeof (struct GNUNET_MessageHeader));
-      switch (ntohs (msg->type))
-       {
-       case GNUNET_MESSAGE_TYPE_ARM_SHUTDOWN:
-#if VERBOSE
-         GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                     "Received confirmation for service shutdown.\n");
-#endif
-         shutdown_ctx->confirmed = GNUNET_YES;
-         GNUNET_CLIENT_receive (shutdown_ctx->sock,
-                                &service_shutdown_handler, shutdown_ctx,
-                                GNUNET_TIME_UNIT_FOREVER_REL);
-         break;
-       default:                /* Fall through */
-         GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                     "Service shutdown refused!\n");
-         if (shutdown_ctx->cont != NULL)
-           shutdown_ctx->cont (shutdown_ctx->cont_cls, GNUNET_YES);
-
-         GNUNET_SCHEDULER_cancel (shutdown_ctx->cancel_task);
-         GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO);
-         GNUNET_free (shutdown_ctx);
-         break;
-       }
-    }
+  if (msg == NULL) 
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Service shutdown complete.\n");
+    if (shutdown_ctx->cont != NULL)
+      shutdown_ctx->cont (shutdown_ctx->cont_cls, GNUNET_NO);
+    
+    GNUNET_SCHEDULER_cancel (shutdown_ctx->cancel_task);
+    GNUNET_CLIENT_disconnect (shutdown_ctx->sock);
+    GNUNET_free (shutdown_ctx);
+    return;
+  }
+  GNUNET_assert (ntohs (msg->size) ==
+                sizeof (struct GNUNET_MessageHeader));
+  switch (ntohs (msg->type))
+  {
+  case GNUNET_MESSAGE_TYPE_ARM_SHUTDOWN:
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+               "Received confirmation for service shutdown.\n");
+    shutdown_ctx->confirmed = GNUNET_YES;
+    GNUNET_CLIENT_receive (shutdown_ctx->sock,
+                          &service_shutdown_handler, shutdown_ctx,
+                          GNUNET_TIME_UNIT_FOREVER_REL);
+    break;
+  default:             /* Fall through */
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+               "Service shutdown refused!\n");
+    if (shutdown_ctx->cont != NULL)
+      shutdown_ctx->cont (shutdown_ctx->cont_cls, GNUNET_YES);
+    
+    GNUNET_SCHEDULER_cancel (shutdown_ctx->cancel_task);
+    GNUNET_CLIENT_disconnect (shutdown_ctx->sock);
+    GNUNET_free (shutdown_ctx);
+    break;
+  }
 }
 
+
 /**
  * Shutting down took too long, cancel receive and return error.
  *
@@ -180,7 +162,7 @@ service_shutdown_cancel (void *cls,
 
   GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "service_shutdown_cancel called!\n");
   shutdown_ctx->cont (shutdown_ctx->cont_cls, GNUNET_SYSERR);
-  GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO);
+  GNUNET_CLIENT_disconnect (shutdown_ctx->sock);
   GNUNET_free (shutdown_ctx);
 }
 
@@ -205,7 +187,7 @@ write_shutdown (void *cls, size_t size, void *buf)
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                  _("Failed to transmit shutdown request to client.\n"));
       shutdown_ctx->cont (shutdown_ctx->cont_cls, GNUNET_SYSERR);
-      GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO);
+      GNUNET_CLIENT_disconnect (shutdown_ctx->sock);
       GNUNET_free (shutdown_ctx);
       return 0;                        /* client disconnected */
     }
@@ -282,7 +264,7 @@ static void
 arm_notify (void *cls, enum GNUNET_ARM_ProcessStatus status)
 {
   GNUNET_assert (status == GNUNET_ARM_PROCESS_STARTING);
-  GNUNET_ARM_start_service (arm, "do-nothing", TIMEOUT, &do_nothing_notify,
+  GNUNET_ARM_start_service (arm, "do-nothing", GNUNET_OS_INHERIT_STD_OUT_AND_ERR, TIMEOUT, &do_nothing_notify,
                            NULL);
 }
 
@@ -303,15 +285,15 @@ do_nothing_restarted_notify_task (void *cls,
 #if LOG_BACKOFF
   if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
     {
-      fprintf (killLogFilePtr, "%d.Reason is shutdown!\n", trialCount);
+      FPRINTF (killLogFilePtr, "%d.Reason is shutdown!\n", trialCount);
     }
   else if ((tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT) != 0)
     {
-      fprintf (killLogFilePtr, "%d.Reason is timeout!\n", trialCount);
+      FPRINTF (killLogFilePtr, "%d.Reason is timeout!\n", trialCount);
     }
   else if ((tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE) != 0)
     {
-      fprintf (killLogFilePtr, "%d.Service is running!\n", trialCount);
+      FPRINTF (killLogFilePtr, "%d.Service is running!\n", trialCount);
     }
 #endif
   GNUNET_SCHEDULER_add_now (&kill_task, &a);
@@ -345,7 +327,7 @@ kill_task (void *cbData, const struct GNUNET_SCHEDULER_TaskContext *tc)
       waitedFor = GNUNET_TIME_absolute_get_duration (startedWaitingAt);
 
 #if LOG_BACKOFF
-      fprintf (killLogFilePtr, "Waited for: %llu ms\n",
+      FPRINTF (killLogFilePtr, "Waited for: %llu ms\n",
               (unsigned long long) waitedFor.rel_value);
 #endif
     }
@@ -358,7 +340,7 @@ kill_task (void *cbData, const struct GNUNET_SCHEDULER_TaskContext *tc)
   GNUNET_assert (doNothingConnection != NULL);
   if (trialCount == 12)
     {
-      GNUNET_CLIENT_disconnect (doNothingConnection, GNUNET_NO);
+      GNUNET_CLIENT_disconnect (doNothingConnection);
       GNUNET_ARM_stop_service (arm, "do-nothing", TIMEOUT, &arm_notify_stop,
                               NULL);
       ok = 0;
@@ -377,7 +359,7 @@ task (void *cls, char *const *args, const char *cfgfile,
 
   arm = GNUNET_ARM_connect (cfg, NULL);
 #if START_ARM
-  GNUNET_ARM_start_service (arm, "arm", GNUNET_TIME_UNIT_ZERO, &arm_notify,
+  GNUNET_ARM_start_service (arm, "arm", GNUNET_OS_INHERIT_STD_OUT_AND_ERR, GNUNET_TIME_UNIT_ZERO, &arm_notify,
                            NULL);
 #else
   arm_do_nothing (NULL, GNUNET_YES);
@@ -391,9 +373,6 @@ check ()
   char *const argv[] = {
     "test-exponential-backoff",
     "-c", "test_arm_api_data.conf",
-#if VERBOSE
-    "-L", "DEBUG",
-#endif
     NULL
   };
   struct GNUNET_GETOPT_CommandLineOption options[] = {
@@ -443,11 +422,7 @@ main (int argc, char *argv[])
   int ret;
 
   GNUNET_log_setup ("test-exponential-backoff",
-#if VERBOSE
-                   "DEBUG",
-#else
                    "WARNING",
-#endif
                    NULL);
 
   init ();