-rps: open channel when inserting peer in view
[oweals/gnunet.git] / src / testbed / test_testbed_logger_api.c
index 438b131d0053591b2efdeeba78eeac5893a59075..f140dfbadc88c0a0fbad48efecacc6f1e76842f0 100644 (file)
@@ -1,6 +1,6 @@
 /*
       This file is part of GNUnet
-      (C) 2008--2013 Christian Grothoff (and other contributing authors)
+      Copyright (C) 2008--2013 GNUnet e.V.
 
       GNUnet is free software; you can redistribute it and/or modify
       it under the terms of the GNU General Public License as published
@@ -14,8 +14,8 @@
 
       You should have received a copy of the GNU General Public License
       along with GNUnet; see the file COPYING.  If not, write to the
-      Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-      Boston, MA 02111-1307, USA.
+      Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+      Boston, MA 02110-1301, USA.
  */
 
 /**
@@ -53,16 +53,16 @@ static char *search_dir;
 /**
  * Abort task identifier
  */
-static GNUNET_SCHEDULER_TaskIdentifier abort_task;
-static GNUNET_SCHEDULER_TaskIdentifier write_task;
+static struct GNUNET_SCHEDULER_Task * abort_task;
+static struct GNUNET_SCHEDULER_Task * write_task;
 
 static int result;
 
 #define CANCEL_TASK(task) do {                  \
-    if (GNUNET_SCHEDULER_NO_TASK != task) \
+    if (NULL != task) \
     {                                           \
       GNUNET_SCHEDULER_cancel (task);     \
-      task = GNUNET_SCHEDULER_NO_TASK;    \
+      task = NULL;    \
     }                                           \
   } while (0)
 
@@ -90,15 +90,17 @@ shutdown_now ()
   CANCEL_TASK (abort_task);
   CANCEL_TASK (write_task);
   GNUNET_free_non_null (search_dir);
+  if (NULL != h)
+    GNUNET_TESTBED_LOGGER_disconnect (h);
   GNUNET_SCHEDULER_shutdown ();
 }
 
 
 static void
-do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+do_abort (void *cls)
 {
   LOG (GNUNET_ERROR_TYPE_WARNING, "Aborting\n");
-  abort_task = GNUNET_SCHEDULER_NO_TASK;
+  abort_task = NULL;
   shutdown_now ();
 }
 
@@ -110,50 +112,40 @@ do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
  * Function called to iterate over a directory.
  *
  * @param cls closure
- * @param di argument to pass to "GNUNET_DISK_directory_iterator_next" to
- *           get called on the next entry (or finish cleanly);
- *           NULL on error (will be the last call in that case)
  * @param filename complete filename (absolute path)
- * @param dirname directory name (absolute path)
+ * @return #GNUNET_OK to continue to iterate,
+ *  #GNUNET_NO to stop iteration with no error,
+ *  #GNUNET_SYSERR to abort iteration with error!
  */
-static void
-iterator_cb (void *cls, struct GNUNET_DISK_DirectoryIterator *di,
-             const char *filename, const char *dirname)
+static int
+iterator_cb (void *cls,
+             const char *filename)
 {
   const char *fn;
   size_t len;
   uint64_t fs;
-  int cancel;
 
-  cancel = GNUNET_NO;
-  if (NULL == filename)
-    goto iteration_cont;
   len = strlen (filename);
   if (len < 5)                  /* log file: `pid'.dat */
-    goto iteration_cont;
+    return GNUNET_OK;
+
   fn = filename + len;
   if (0 != strcasecmp (".dat", fn - 4))
-    goto iteration_cont;
-  if (GNUNET_OK != GNUNET_DISK_file_size (filename, &fs,
-                                          GNUNET_NO, GNUNET_YES))
-    goto iteration_cont;
+    return GNUNET_OK;
+  if (GNUNET_OK !=
+      GNUNET_DISK_file_size (filename, &fs,
+                            GNUNET_NO, GNUNET_YES))
+    return GNUNET_SYSERR;
   if ((BSIZE * 2) != fs)        /* The file size should be equal to what we
                                    have written */
-    goto iteration_cont;
-  
-  cancel = GNUNET_YES;
-  result = GNUNET_OK;
-    
- iteration_cont:
-  if ( (NULL != di) && 
-       (GNUNET_YES == GNUNET_DISK_directory_iterator_next (di, cancel)) )
-    return;
-  shutdown_now ();
+    return GNUNET_SYSERR;
+  return GNUNET_OK;
 }
 
+
 /**
- * Functions of this type are called to notify a successful transmission of the
- * message to the logger service
+ * Functions of this type are called to notify a successful
+ * transmission of the message to the logger service
  *
  * @param cls the closure given to GNUNET_TESTBED_LOGGER_send()
  * @param size the amount of data sent
@@ -164,45 +156,52 @@ flush_comp (void *cls, size_t size)
   FAIL_TEST (&write_task == cls, return);
   FAIL_TEST ((BSIZE * 2) == size, return);
   FAIL_TEST (GNUNET_OK == GNUNET_TESTING_peer_stop (peer), return);
-  FAIL_TEST (GNUNET_YES == GNUNET_DISK_directory_iterator_start
-             (GNUNET_SCHEDULER_PRIORITY_DEFAULT, search_dir,
-              &iterator_cb, NULL), return);
+  FAIL_TEST (GNUNET_SYSERR !=
+            GNUNET_DISK_directory_scan (search_dir,
+                                        &iterator_cb,
+                                        NULL),
+            return);
+  shutdown_now ();
 }
 
 
 static void
-do_write (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+do_write (void *cls)
 {
   static int i;
   char buf[BSIZE];
 
-  write_task = GNUNET_SCHEDULER_NO_TASK;
+  write_task = NULL;
   if (0 == i)
-    write_task = GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS(1), &do_write, NULL);
+    write_task = GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS(1),
+                                              &do_write,
+                                              NULL);
   (void) memset (buf, i, BSIZE);
   GNUNET_TESTBED_LOGGER_write (h, buf, BSIZE);
   if (0 == i++)
     return;
-  GNUNET_TESTBED_LOGGER_flush (h, &flush_comp, &write_task);
+  GNUNET_TESTBED_LOGGER_flush (h,
+                              GNUNET_TIME_UNIT_FOREVER_REL,
+                               &flush_comp, &write_task);
 }
 
 
 /**
  * Signature of the 'main' function for a (single-peer) testcase that
- * is run using 'GNUNET_TESTING_peer_run'.
- * 
+ * is run using #GNUNET_TESTING_peer_run().
+ *
  * @param cls closure
  * @param cfg configuration of the peer that was started
  * @param peer identity of the peer that was created
  */
 static void
-test_main (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg,
+test_main (void *cls,
+          const struct GNUNET_CONFIGURATION_Handle *cfg,
            struct GNUNET_TESTING_Peer *p)
 {
   FAIL_TEST (NULL != (h = GNUNET_TESTBED_LOGGER_connect (cfg)), return);
-  FAIL_TEST (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string
+  FAIL_TEST (GNUNET_OK == GNUNET_CONFIGURATION_get_value_filename
              (cfg, "testbed-logger", "dir", &search_dir), return);
-  search_dir = GNUNET_CONFIGURATION_expand_dollar (cfg, search_dir);
   peer = p;
   write_task = GNUNET_SCHEDULER_add_now (&do_write, NULL);
   abort_task = GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS (10),