indentation
[oweals/gnunet.git] / src / vpn / gnunet-helper-vpn-api.c
index c2ab6081dbc8ac337955f11708a3da468ecac38c..16bfcbd2ec382afca9672771c306946636314990 100644 (file)
@@ -44,8 +44,12 @@ stop_helper (struct GNUNET_VPN_HELPER_Handle *handle)
 
   GNUNET_DISK_pipe_close (handle->helper_in);
   GNUNET_DISK_pipe_close (handle->helper_out);
+
+  GNUNET_SERVER_mst_destroy (handle->mst);
 }
 
+extern GNUNET_SCHEDULER_TaskIdentifier shs_task;
+
 /**
  * Read from the helper-process
  */
@@ -53,6 +57,7 @@ static void
 helper_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tsdkctx)
 {
   struct GNUNET_VPN_HELPER_Handle *handle = cls;
+
   /* no message can be bigger then 64k */
   char buf[65535];
 
@@ -63,23 +68,32 @@ helper_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tsdkctx)
 
   /* On read-error, restart the helper */
   if (t <= 0)
-    {
-      GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                  "Read error for header from vpn-helper: %m\n");
-      stop_helper (handle);
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                "Read error for header from vpn-helper: %m\n");
+    stop_helper (handle);
+
+    /* Restart the helper */
+    shs_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+                                             handle->restart_task, handle);
+    return;
+  }
+
+  if (GNUNET_SYSERR ==
+      GNUNET_SERVER_mst_receive (handle->mst, handle->client, buf, t, 0, 0))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "SYSERR from mst\n");
+    stop_helper (handle);
 
-      /* Restart the helper */
-      GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
-                                    handle->restart_task, handle);
-      return;
-    }
+    /* Restart the helper */
+    shs_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+                                             handle->restart_task, handle);
+    return;
 
-  /* FIXME */ GNUNET_SERVER_mst_receive (handle->mst, handle->client, buf, t,
-                                         0, 0);
+  }
 
   GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
-                                  handle->fh_from_helper, &helper_read,
-                                  handle);
+                                  handle->fh_from_helper, &helper_read, handle);
 }
 
 void
@@ -96,11 +110,10 @@ start_helper (const char *ifname,
               const char *ipv4addr,
               const char *ipv4mask, const char *process_name,
               GNUNET_SCHEDULER_Task restart_task,
-              GNUNET_SERVER_MessageTokenizerCallback cb, void *cb_cls,
-              void *client)
+              GNUNET_SERVER_MessageTokenizerCallback cb, void *cb_cls)
 {
   struct GNUNET_VPN_HELPER_Handle *handle =
-    GNUNET_malloc (sizeof (struct GNUNET_VPN_HELPER_Handle));
+      GNUNET_malloc (sizeof (struct GNUNET_VPN_HELPER_Handle));
 
   handle->helper_in = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO);
   handle->helper_out = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_NO, GNUNET_YES);
@@ -108,20 +121,20 @@ start_helper (const char *ifname,
   handle->restart_task = restart_task;
 
   if (handle->helper_in == NULL || handle->helper_out == NULL)
-    {
-      GNUNET_free (handle);
-      return NULL;
-    }
+  {
+    GNUNET_free (handle);
+    return NULL;
+  }
 
   handle->helper_proc =
-    GNUNET_OS_start_process (handle->helper_in, handle->helper_out,
-                             "gnunet-helper-vpn", process_name, ifname,
-                             ipv6addr, ipv6prefix, ipv4addr, ipv4mask, NULL);
+      GNUNET_OS_start_process (handle->helper_in, handle->helper_out,
+                               "gnunet-helper-vpn", process_name, ifname,
+                               ipv6addr, ipv6prefix, ipv4addr, ipv4mask, NULL);
 
   handle->fh_from_helper =
-    GNUNET_DISK_pipe_handle (handle->helper_out, GNUNET_DISK_PIPE_END_READ);
+      GNUNET_DISK_pipe_handle (handle->helper_out, GNUNET_DISK_PIPE_END_READ);
   handle->fh_to_helper =
-    GNUNET_DISK_pipe_handle (handle->helper_in, GNUNET_DISK_PIPE_END_WRITE);
+      GNUNET_DISK_pipe_handle (handle->helper_in, GNUNET_DISK_PIPE_END_WRITE);
 
   GNUNET_DISK_pipe_close_end (handle->helper_out, GNUNET_DISK_PIPE_END_WRITE);
   GNUNET_DISK_pipe_close_end (handle->helper_in, GNUNET_DISK_PIPE_END_READ);
@@ -129,8 +142,7 @@ start_helper (const char *ifname,
   handle->mst = GNUNET_SERVER_mst_create (cb, cb_cls);
 
   GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
-                                  handle->fh_from_helper, &helper_read,
-                                  handle);
+                                  handle->fh_from_helper, &helper_read, handle);
 
   return handle;
 }