- add 2s for new state, reduce buffer
[oweals/gnunet.git] / src / arm / arm_api.c
index 6dfe657025e4d016e7818dc22e4148cf3f32594a..1b83c31063e84d25519ee1ac4994ea21e0916893 100644 (file)
@@ -308,11 +308,12 @@ arm_termination_handler (void *cls, const struct GNUNET_MessageHeader *msg)
 /**
  * Handler for ARM replies.
  *
- * @param cls our "struct GNUNET_ARM_Handle"
+ * @param cls our `struct GNUNET_ARM_Handle`
  * @param msg the message received from the arm service
  */
 static void
-client_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg)
+client_notify_handler (void *cls,
+                       const struct GNUNET_MessageHeader *msg)
 {
   struct GNUNET_ARM_Handle *h = cls;
   const struct GNUNET_ARM_Message *arm_msg;
@@ -348,11 +349,14 @@ client_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg)
     return;
   }
   arm_msg = (const struct GNUNET_ARM_Message *) msg;
+  GNUNET_break (0 == ntohl (arm_msg->reserved));
   id = GNUNET_ntohll (arm_msg->request_id);
   cm = find_cm_by_id (h, id);
   if (NULL == cm)
   {
-    LOG (GNUNET_ERROR_TYPE_DEBUG, "Message with unknown id %llu\n", id);
+    LOG (GNUNET_ERROR_TYPE_DEBUG,
+         "Message with unknown id %llu\n",
+         id);
     return;
   }
   fail = GNUNET_NO;
@@ -459,7 +463,7 @@ client_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg)
     if (NULL != cm->list_cont)
         cm->list_cont (cm->cont_cls, GNUNET_ARM_REQUEST_SENT_OK, rcount,
                        list);
-    GNUNET_free (list);
+    GNUNET_free_non_null (list);
     break;
   }
   GNUNET_free (cm->msg);
@@ -470,10 +474,10 @@ client_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg)
 /**
  * Transmit the next message to the arm service.
  *
- * @param cls closure with the 'struct GNUNET_ARM_Handle'
- * @param size number of bytes available in buf
+ * @param cls closure with the `struct GNUNET_ARM_Handle`
+ * @param size number of bytes available in @a buf
  * @param buf where the callee should write the message
- * @return number of bytes written to buf
+ * @return number of bytes written to @a buf
  */
 static size_t
 transmit_arm_message (void *cls, size_t size, void *buf)
@@ -487,8 +491,8 @@ transmit_arm_message (void *cls, size_t size, void *buf)
 
   notify_connection = GNUNET_NO;
   LOG (GNUNET_ERROR_TYPE_DEBUG,
-      "transmit_arm_message is running with %p buffer of size %lu. ARM is known to be %s\n",
-      buf, size, h->currently_down ? "unconnected" : "connected");
+       "transmit_arm_message is running with %p buffer of size %lu. ARM is known to be %s\n",
+       buf, size, h->currently_down ? "unconnected" : "connected");
   GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == h->reconnect_task);
   h->cth = NULL;
   if ((GNUNET_YES == h->currently_down) && (NULL != buf))
@@ -508,7 +512,8 @@ transmit_arm_message (void *cls, size_t size, void *buf)
   }
   if (NULL == (cm = h->control_pending_head))
   {
-    LOG (GNUNET_ERROR_TYPE_DEBUG, "Queue is empty, not sending anything\n");
+    LOG (GNUNET_ERROR_TYPE_DEBUG,
+         "Queue is empty, not sending anything\n");
     msize = 0;
     goto end;
   }
@@ -529,6 +534,7 @@ transmit_arm_message (void *cls, size_t size, void *buf)
   LOG (GNUNET_ERROR_TYPE_DEBUG,
        "Transmitting control message with %u bytes of type %u to arm with id %llu\n",
        (unsigned int) msize, (unsigned int) ntohs (cm->msg->header.type), request_id);
+  arm_msg->reserved = htonl (0);
   arm_msg->request_id = GNUNET_htonll (request_id);
   memcpy (buf, cm->msg, msize);
   /* Otherwise we won't be able to find it later! */
@@ -634,7 +640,7 @@ GNUNET_ARM_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
 {
   struct GNUNET_ARM_Handle *h;
 
-  h = GNUNET_malloc (sizeof (struct GNUNET_ARM_Handle));
+  h = GNUNET_new (struct GNUNET_ARM_Handle);
   h->cfg = GNUNET_CONFIGURATION_dup (cfg);
   h->currently_down = GNUNET_YES;
   h->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
@@ -712,6 +718,7 @@ control_message_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *t
 {
   struct ARMControlMessage *cm = cls;
   struct GNUNET_ARM_Message *arm_msg;
+
   LOG (GNUNET_ERROR_TYPE_DEBUG,
        "Control message timed out\n");
   arm_msg = cm->msg;
@@ -734,9 +741,6 @@ control_message_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *t
 }
 
 
-#include "do_start_process.c"
-
-
 /**
  * A client specifically requested starting of ARM itself.
  * This function is called with information about whether
@@ -756,6 +760,7 @@ arm_service_report (void *cls,
   unsigned char test_is_active;
   char *cbinary;
   char *binary;
+  char *quotedbinary;
   char *config;
   char *loprefix;
   char *lopostfix;
@@ -814,6 +819,9 @@ arm_service_report (void *cls,
       cm->h->cfg, "arm", "CONFIG", &config))
     config = NULL;
   binary = GNUNET_OS_get_libexec_binary_path (cbinary);
+  GNUNET_asprintf (&quotedbinary,
+                  "\"%s\"",
+                  binary);
   GNUNET_free (cbinary);
   if ((GNUNET_YES == GNUNET_CONFIGURATION_have_value (
           cm->h->cfg, "TESTING", "WEAKRANDOM")) &&
@@ -825,28 +833,30 @@ arm_service_report (void *cls,
     /* Means we are ONLY running locally */
     /* we're clearly running a test, don't daemonize */
     if (NULL == config)
-      proc = do_start_process (GNUNET_NO, cm->std_inheritance,
-                              NULL, loprefix, binary,
-                              /* no daemonization! */
-                              lopostfix, NULL);
+      proc = GNUNET_OS_start_process_s (GNUNET_NO, cm->std_inheritance,
+                                        NULL, loprefix, quotedbinary,
+                                        /* no daemonization! */
+                                        lopostfix, NULL);
     else
-      proc = do_start_process (GNUNET_NO, cm->std_inheritance,
-                              NULL, loprefix, binary, "-c", config,
-                              /* no daemonization! */
-                              lopostfix, NULL);
+      proc = GNUNET_OS_start_process_s (GNUNET_NO, cm->std_inheritance,
+                              NULL, loprefix, quotedbinary, "-c", config,
+                                        /* no daemonization! */
+                                        lopostfix, NULL);
   }
   else
   {
     if (NULL == config)
-      proc = do_start_process (GNUNET_NO, cm->std_inheritance,
-                              NULL, loprefix, binary,
-                              "-d", lopostfix, NULL);
+      proc = GNUNET_OS_start_process_s (GNUNET_NO, cm->std_inheritance,
+                                        NULL, loprefix, quotedbinary,
+                                        "-d", lopostfix, NULL);
     else
-      proc = do_start_process (GNUNET_NO, cm->std_inheritance,
-                              NULL, loprefix, binary, "-c", config,
-                              "-d", lopostfix, NULL);
+      proc = GNUNET_OS_start_process_s (GNUNET_NO, cm->std_inheritance,
+                                        NULL, loprefix, quotedbinary, "-c",
+                                        config,
+                                        "-d", lopostfix, NULL);
   }
   GNUNET_free (binary);
+  GNUNET_free (quotedbinary);
   GNUNET_free_non_null (config);
   GNUNET_free (loprefix);
   GNUNET_free (lopostfix);
@@ -908,6 +918,7 @@ change_service (struct GNUNET_ARM_Handle *h, const char *service_name,
   msg = GNUNET_malloc (sizeof (struct GNUNET_ARM_Message) + slen);
   msg->header.size = htons (sizeof (struct GNUNET_ARM_Message) + slen);
   msg->header.type = htons (type);
+  msg->reserved = htonl (0);
   memcpy (&msg[1], service_name, slen);
   cm->msg = msg;
   LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -1060,7 +1071,7 @@ GNUNET_ARM_request_service_list (struct GNUNET_ARM_Handle *h,
   LOG (GNUNET_ERROR_TYPE_DEBUG,
        "Requesting LIST from ARM service with timeout: %s\n",
        GNUNET_STRINGS_relative_time_to_string (timeout, GNUNET_YES));
-  cm = GNUNET_malloc (sizeof (struct ARMControlMessage));
+  cm = GNUNET_new (struct ARMControlMessage);
   cm->h = h;
   cm->list_cont = cont;
   cm->cont_cls = cont_cls;
@@ -1068,6 +1079,7 @@ GNUNET_ARM_request_service_list (struct GNUNET_ARM_Handle *h,
   msg = GNUNET_malloc (sizeof (struct GNUNET_ARM_Message));
   msg->header.size = htons (sizeof (struct GNUNET_ARM_Message));
   msg->header.type = htons (GNUNET_MESSAGE_TYPE_ARM_LIST);
+  msg->reserved = htonl (0);
   cm->msg = msg;
   GNUNET_CONTAINER_DLL_insert_tail (h->control_pending_head,
                                     h->control_pending_tail, cm);