fixme
[oweals/gnunet.git] / src / transport / test_plugin_transport.c
index a106470ea3e51f83d7cafecad99457876ce5d5dc..b43c534c56483c9079928b6e1794861df8a7c297 100644 (file)
@@ -21,6 +21,7 @@
  * @file transport/test_transport_api.c
  * @brief testcase for transport_api.c
  * @author Sailor Siraj
+ * @author Christian Grothoff
  */
 
 #include "platform.h"
@@ -36,7 +37,7 @@
 #include "plugin_transport.h"
 #include "transport.h"
 
-#define VERBOSE GNUNET_YES
+#define VERBOSE GNUNET_NO
 
 /**
  * How long until we give up on transmitting the message?
@@ -66,7 +67,7 @@ struct GNUNET_SCHEDULER_Handle *sched;
 /**
  * Our configuration.
  */
-struct GNUNET_CONFIGURATION_Handle *cfg;
+const struct GNUNET_CONFIGURATION_Handle *cfg;
 
 /**
  * Number of neighbours we'd like to have.
@@ -134,7 +135,8 @@ void lookup (void *cls,
  * @param cfg configuration to use
  */
 static void
-unload_plugins (void *cls, struct GNUNET_CONFIGURATION_Handle *cfg)
+unload_plugins (void *cls, 
+               const struct GNUNET_CONFIGURATION_Handle *cfg)
 {  
   GNUNET_assert (NULL == GNUNET_PLUGIN_unload ("libgnunet_plugin_transport_tcp",api));
   if (my_private_key != NULL)
@@ -143,6 +145,15 @@ unload_plugins (void *cls, struct GNUNET_CONFIGURATION_Handle *cfg)
 }
 
 
+static void
+unload_task (void *cls,
+            const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+  struct GNUNET_CONFIGURATION_Handle *cfg = cls;
+  unload_plugins (NULL, cfg);
+}
+
+
 static GNUNET_SCHEDULER_TaskIdentifier validation_timeout_task;
 
 
@@ -156,10 +167,10 @@ validation_notification (void *cls,
   /* Sailor: 'test_validation' should get here
      if the validation worked; so we cancel the
      "delayed" task that will cause failure */
-  if (validation_timeout_task != GNUNET_SCHEDULER_NO_PREREQUISITE_TASK)
+  if (validation_timeout_task != GNUNET_SCHEDULER_NO_TASK)
     {
       GNUNET_SCHEDULER_cancel (sched, validation_timeout_task);
-      validation_timeout_task = GNUNET_SCHEDULER_NO_PREREQUISITE_TASK;
+      validation_timeout_task = GNUNET_SCHEDULER_NO_TASK;
     }
 
   GNUNET_assert (challenge == 42);
@@ -167,7 +178,10 @@ validation_notification (void *cls,
   /* Sailor: if this is the last test, calling this function
      here will end the process. */
   ok = 0; /* if the last test succeeded, report success */
-  unload_plugins (NULL, cfg);
+  GNUNET_SCHEDULER_add_continuation (sched,
+                                    &unload_task,
+                                    (void*) cfg,
+                                    GNUNET_SCHEDULER_REASON_PREREQ_DONE);
 }
 
 
@@ -175,7 +189,7 @@ static void
 validation_failed (void *cls,
                   const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
-  validation_timeout_task = GNUNET_SCHEDULER_NO_PREREQUISITE_TASK;
+  validation_timeout_task = GNUNET_SCHEDULER_NO_TASK;
   GNUNET_break (0); /* output error */
   /* the "validation_notification" was not called
      in a timely fashion; we should set an error
@@ -195,12 +209,18 @@ validation_failed (void *cls,
  *  work for other plugins; we should ask
  *  the plugin about its address instead...).
  */
+/* FIXME: won't work on IPv6 enabled systems where IPv4 bridge
+ * mode isn't enabled (eg. FreeBSD > 4)
+ */
 static void
 test_validation ()
 {
   struct sockaddr_in soaddr;
   
   memset (&soaddr, 0, sizeof(soaddr));
+#if HAVE_SOCKADDR_IN_SIN_LEN
+  soaddr.sin_len = sizeof (soaddr);
+#endif
   soaddr.sin_family = AF_INET;
   /* Sailor: set this port to 2367 to see the
      testcase fail after 30s (because validation
@@ -218,9 +238,6 @@ test_validation ()
   /* add job to catch failure (timeout) */
   validation_timeout_task =
     GNUNET_SCHEDULER_add_delayed (sched,
-                                 GNUNET_NO,
-                                 GNUNET_SCHEDULER_PRIORITY_KEEP,
-                                 GNUNET_SCHEDULER_NO_PREREQUISITE_TASK,
                                  TIMEOUT,
                                  &validation_failed,
                                  NULL);
@@ -255,7 +272,7 @@ run (void *cls,
      struct GNUNET_SCHEDULER_Handle *s,
      char *const *args,
      const char *cfgfile,
-     struct GNUNET_CONFIGURATION_Handle *c)
+     const struct GNUNET_CONFIGURATION_Handle *c)
 { 
   unsigned long long tneigh;
   char *keyfile;
@@ -304,6 +321,7 @@ run (void *cls,
   GNUNET_asprintf (&libname, "libgnunet_plugin_transport_tcp");
 
   api = GNUNET_PLUGIN_load(libname, &env);
+  GNUNET_free (libname);
   if (api == NULL)
     {
       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -339,6 +357,7 @@ main (int argc, char *const *argv)
   static struct GNUNET_GETOPT_CommandLineOption options[] = {
     GNUNET_GETOPT_OPTION_END
   };
+  int ret;
   char *const argv_prog[] = {
     "test_plugin_transport",
     "-c",
@@ -359,13 +378,15 @@ main (int argc, char *const *argv)
 #endif
                     NULL);       
   ok = 1; /* set to fail */
-  return (GNUNET_OK ==
+  ret = (GNUNET_OK ==
           GNUNET_PROGRAM_run (5,
                               argv_prog,
                               "test-plugin-transport",
                              "testcase",
                              options,
                               &run, NULL)) ? ok : 1;
+  GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-plugin-transport");
+  return ret;
 }
 
 /* end of test_plugin_transport.c */