gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r23720 - gnunet/src/fs


From: gnunet
Subject: [GNUnet-SVN] r23720 - gnunet/src/fs
Date: Sun, 9 Sep 2012 15:28:48 +0200

Author: grothoff
Date: 2012-09-09 15:28:48 +0200 (Sun, 09 Sep 2012)
New Revision: 23720

Modified:
   gnunet/src/fs/Makefile.am
   gnunet/src/fs/fs_test_lib.c
   gnunet/src/fs/fs_test_lib.h
   gnunet/src/fs/perf_gnunet_service_fs_p2p.c
   gnunet/src/fs/perf_gnunet_service_fs_p2p_respect.c
   gnunet/src/fs/test_fs_test_lib.c
   gnunet/src/fs/test_gnunet_service_fs_migration.c
   gnunet/src/fs/test_gnunet_service_fs_p2p.c
Log:
make fs tests build against new testbed library -- they do not pass yet

Modified: gnunet/src/fs/Makefile.am
===================================================================
--- gnunet/src/fs/Makefile.am   2012-09-09 12:30:54 UTC (rev 23719)
+++ gnunet/src/fs/Makefile.am   2012-09-09 13:28:48 UTC (rev 23720)
@@ -57,7 +57,8 @@
   fs_test_lib.c fs_test_lib.h
 
 libgnunetfstest_a_LIBADD = \
-  $(top_builddir)/src/testing_old/libgnunettesting_old.la 
+  $(top_builddir)/src/testing/libgnunettesting.la \
+  $(top_builddir)/src/testbed/libgnunettestbed.la 
 
 bin_PROGRAMS = \
   gnunet-auto-share \
@@ -406,7 +407,7 @@
  test_fs_test_lib.c
 test_fs_test_lib_LDADD = \
   $(top_builddir)/src/fs/libgnunetfstest.a \
-  $(top_builddir)/src/testing_old/libgnunettesting_old.la \
+  $(top_builddir)/src/testbed/libgnunettestbed.la \
   $(top_builddir)/src/fs/libgnunetfs.la  \
   $(top_builddir)/src/util/libgnunetutil.la  
 
@@ -414,7 +415,7 @@
  test_gnunet_service_fs_p2p.c
 test_gnunet_service_fs_p2p_LDADD = \
   $(top_builddir)/src/fs/libgnunetfstest.a \
-  $(top_builddir)/src/testing_old/libgnunettesting_old.la \
+  $(top_builddir)/src/testbed/libgnunettestbed.la \
   $(top_builddir)/src/fs/libgnunetfs.la  \
   $(top_builddir)/src/util/libgnunetutil.la  
 
@@ -422,7 +423,7 @@
  test_gnunet_service_fs_migration.c
 test_gnunet_service_fs_migration_LDADD = \
   $(top_builddir)/src/fs/libgnunetfstest.a \
-  $(top_builddir)/src/testing_old/libgnunettesting_old.la \
+  $(top_builddir)/src/testbed/libgnunettestbed.la \
   $(top_builddir)/src/fs/libgnunetfs.la  \
   $(top_builddir)/src/util/libgnunetutil.la  
 
@@ -431,7 +432,7 @@
 perf_gnunet_service_fs_p2p_LDADD = \
   $(top_builddir)/src/fs/libgnunetfstest.a \
   $(top_builddir)/src/statistics/libgnunetstatistics.la \
-  $(top_builddir)/src/testing_old/libgnunettesting_old.la \
+  $(top_builddir)/src/testbed/libgnunettestbed.la \
   $(top_builddir)/src/fs/libgnunetfs.la  \
   $(top_builddir)/src/util/libgnunetutil.la  
 
@@ -440,7 +441,7 @@
 perf_gnunet_service_fs_p2p_index_LDADD = \
   $(top_builddir)/src/fs/libgnunetfstest.a \
   $(top_builddir)/src/statistics/libgnunetstatistics.la \
-  $(top_builddir)/src/testing_old/libgnunettesting_old.la \
+  $(top_builddir)/src/testbed/libgnunettestbed.la \
   $(top_builddir)/src/fs/libgnunetfs.la  \
   $(top_builddir)/src/util/libgnunetutil.la  
 
@@ -449,7 +450,7 @@
 perf_gnunet_service_fs_p2p_dht_LDADD = \
   $(top_builddir)/src/fs/libgnunetfstest.a \
   $(top_builddir)/src/statistics/libgnunetstatistics.la \
-  $(top_builddir)/src/testing_old/libgnunettesting_old.la \
+  $(top_builddir)/src/testbed/libgnunettestbed.la \
   $(top_builddir)/src/fs/libgnunetfs.la  \
   $(top_builddir)/src/util/libgnunetutil.la  
 
@@ -458,7 +459,7 @@
 perf_gnunet_service_fs_p2p_respect_LDADD = \
   $(top_builddir)/src/fs/libgnunetfstest.a \
   $(top_builddir)/src/statistics/libgnunetstatistics.la \
-  $(top_builddir)/src/testing_old/libgnunettesting_old.la \
+  $(top_builddir)/src/testbed/libgnunettestbed.la \
   $(top_builddir)/src/fs/libgnunetfs.la  \
   $(top_builddir)/src/util/libgnunetutil.la  
 

Modified: gnunet/src/fs/fs_test_lib.c
===================================================================
--- gnunet/src/fs/fs_test_lib.c 2012-09-09 12:30:54 UTC (rev 23719)
+++ gnunet/src/fs/fs_test_lib.c 2012-09-09 13:28:48 UTC (rev 23720)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     (C) 2010, 2011 Christian Grothoff (and other contributing authors)
+     (C) 2010, 2011, 2012 Christian Grothoff (and other contributing authors)
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -20,8 +20,8 @@
 
 /**
  * @file fs/fs_test_lib.c
- * @brief library routines for testing FS publishing and downloading
- *        with multiple peers; this code is limited to flat files
+ * @brief library routines for testing FS publishing and downloading;
+ *        this code is limited to flat files
  *        and no keywords (those functions can be tested with
  *        single-peer setups; this is for testing routing).
  * @author Christian Grothoff
@@ -29,23 +29,21 @@
 #include "platform.h"
 #include "fs_api.h"
 #include "fs_test_lib.h"
-#include "gnunet_testing_lib.h"
 
-#define CONNECT_ATTEMPTS 4
 
 #define CONTENT_LIFETIME GNUNET_TIME_UNIT_HOURS
 
+
 /**
- * Handle for a daemon started for testing FS.
+ * Handle for a publishing operation started for testing FS.
  */
-struct GNUNET_FS_TestDaemon
+struct TestPublishOperation
 {
 
   /**
-   * Global configuration, only stored in first test daemon,
-   * otherwise NULL.
+   * Handle for the operation to connect to the peer's 'fs' service.
    */
-  struct GNUNET_CONFIGURATION_Handle *gcfg;
+  struct GNUNET_TESTBED_Operation *fs_op;
 
   /**
    * Handle to the file sharing context using this daemon.
@@ -53,27 +51,6 @@
   struct GNUNET_FS_Handle *fs;
 
   /**
-   * Handle to the daemon via testing.
-   */
-  struct GNUNET_TESTING_Daemon *daemon;
-
-  /**
-   * Note that 'group' will be the same value for all of the
-   * daemons started jointly.
-   */
-  struct GNUNET_TESTING_PeerGroup *group;
-
-  /**
-   * Configuration for accessing this peer.
-   */
-  struct GNUNET_CONFIGURATION_Handle *cfg;
-
-  /**
-   * ID of this peer.
-   */
-  struct GNUNET_PeerIdentity id;
-
-  /**
    * Function to call when upload is done.
    */
   GNUNET_FS_TEST_UriContinuation publish_cont;
@@ -109,6 +86,49 @@
   char *publish_tmp_file;
 
   /**
+   * Size of the file.
+   */
+  uint64_t size;
+
+  /**
+   * Anonymity level used.
+   */
+  uint32_t anonymity;
+
+  /**
+   * Verbosity level of the current operation.
+   */
+  unsigned int verbose;
+
+  /**
+   * Are we testing indexing? (YES: index, NO: insert, SYSERR: simulate)
+   */
+  int do_index;
+};
+
+
+/**
+ * Handle for a download operation started for testing FS.
+ */
+struct TestDownloadOperation
+{
+
+  /**
+   * Handle for the operation to connect to the peer's 'fs' service.
+   */
+  struct GNUNET_TESTBED_Operation *fs_op;
+
+  /**
+   * Handle to the file sharing context using this daemon.
+   */
+  struct GNUNET_FS_Handle *fs;
+
+  /**
+   * Handle to the daemon via testing.
+   */
+  struct GNUNET_TESTING_Daemon *daemon;
+
+  /**
    * Function to call when download is done.
    */
   GNUNET_SCHEDULER_Task download_cont;
@@ -119,9 +139,9 @@
   void *download_cont_cls;
 
   /**
-   * Seed for download verification.
+   * URI to download.
    */
-  uint32_t download_seed;
+  struct GNUNET_FS_Uri *uri;
 
   /**
    * Task to abort downloading (timeout).
@@ -134,107 +154,108 @@
   struct GNUNET_FS_DownloadContext *download_context;
 
   /**
+   * Size of the file.
+   */
+  uint64_t size;
+
+  /**
+   * Anonymity level used.
+   */
+  uint32_t anonymity;
+
+  /**
+   * Seed for download verification.
+   */
+  uint32_t download_seed;
+
+  /**
    * Verbosity level of the current operation.
    */
-  int verbose;
+  unsigned int verbose;
 
-
 };
 
+
 /**
- * Check whether peers successfully shut down.
+ * Task scheduled to report on the completion of our publish operation.
+ *
+ * @param cls the publish operation context
+ * @param tc scheduler context (unused)
  */
 static void
-shutdown_callback (void *cls, const char *emsg)
+report_uri (void *cls, 
+           const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
-  struct GNUNET_CONFIGURATION_Handle *gcfg = cls;
+  struct TestPublishOperation *po = cls;
 
-  if (emsg != NULL)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Shutdown of peers failed: %s\n",
-                emsg);
-  }
-  else
-  {
-#if VERBOSE
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All peers successfully shut 
down!\n");
-#endif
-  }
-  if (gcfg != NULL)
-    GNUNET_CONFIGURATION_destroy (gcfg);
+  GNUNET_FS_publish_stop (po->publish_context);
+  GNUNET_TESTBED_operation_done (po->fs_op);
+  po->publish_cont (po->publish_cont_cls, po->publish_uri);
+  GNUNET_FS_uri_destroy (po->publish_uri);
+  GNUNET_free_non_null (po->publish_tmp_file);
+  GNUNET_free (po);
 }
 
 
+/**
+ * Task scheduled to run when publish operation times out.
+ *
+ * @param cls the publish operation context
+ * @param tc scheduler context (unused)
+ */
 static void
-report_uri (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+publish_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
-  struct GNUNET_FS_TestDaemon *daemon = cls;
-  GNUNET_FS_TEST_UriContinuation cont;
-  struct GNUNET_FS_Uri *uri;
+  struct TestPublishOperation *po = cls;
 
-  GNUNET_FS_publish_stop (daemon->publish_context);
-  daemon->publish_context = NULL;
-  cont = daemon->publish_cont;
-  daemon->publish_cont = NULL;
-  uri = daemon->publish_uri;
-  cont (daemon->publish_cont_cls, uri);
-  GNUNET_FS_uri_destroy (uri);
+  po->publish_timeout_task = GNUNET_SCHEDULER_NO_TASK;
+  GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+              "Timeout while trying to publish data\n");
+  if (NULL == po->fs)
+    GNUNET_TESTBED_operation_cancel (po->fs_op);
+  else
+    GNUNET_TESTBED_operation_done (po->fs_op);
+  GNUNET_FS_publish_stop (po->publish_context);
+  GNUNET_TESTBED_operation_done (po->fs_op);
+  po->publish_cont (po->publish_cont_cls, NULL);
+  GNUNET_free_non_null (po->publish_tmp_file);
+  GNUNET_free (po);
 }
 
 
-static void
-report_success (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
-  struct GNUNET_FS_TestDaemon *daemon = cls;
-
-  GNUNET_FS_download_stop (daemon->download_context, GNUNET_YES);
-  daemon->download_context = NULL;
-  GNUNET_SCHEDULER_add_continuation (daemon->download_cont,
-                                     daemon->download_cont_cls,
-                                     GNUNET_SCHEDULER_REASON_PREREQ_DONE);
-  daemon->download_cont = NULL;
-}
-
-
+/**
+ * Progress callback for file-sharing events while publishing.
+ *
+ * @param cls the publish operation context
+ * @param info information about the event
+ */
 static void *
-progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
+publish_progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
 {
-  struct GNUNET_FS_TestDaemon *daemon = cls;
+  struct TestPublishOperation *po = cls;
 
   switch (info->status)
   {
   case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
-    GNUNET_SCHEDULER_cancel (daemon->publish_timeout_task);
-    daemon->publish_timeout_task = GNUNET_SCHEDULER_NO_TASK;
-    daemon->publish_uri =
+    GNUNET_SCHEDULER_cancel (po->publish_timeout_task);
+    po->publish_timeout_task = GNUNET_SCHEDULER_NO_TASK;
+    po->publish_uri =
         GNUNET_FS_uri_dup (info->value.publish.specifics.completed.chk_uri);
-    GNUNET_SCHEDULER_add_continuation (&report_uri, daemon,
+    GNUNET_SCHEDULER_add_continuation (&report_uri, po,
                                        GNUNET_SCHEDULER_REASON_PREREQ_DONE);
     break;
   case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
-    if (daemon->verbose)
+    if (po->verbose)
       GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Publishing at %llu/%llu bytes\n",
                   (unsigned long long) info->value.publish.completed,
                   (unsigned long long) info->value.publish.size);
     break;
   case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS:
-    if (daemon->verbose)
+    if (po->verbose)
       GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Download at %llu/%llu bytes\n",
                   (unsigned long long) info->value.download.completed,
                   (unsigned long long) info->value.download.size);
     break;
-  case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED:
-    GNUNET_SCHEDULER_cancel (daemon->download_timeout_task);
-    daemon->download_timeout_task = GNUNET_SCHEDULER_NO_TASK;
-    GNUNET_SCHEDULER_add_continuation (&report_success, daemon,
-                                       GNUNET_SCHEDULER_REASON_PREREQ_DONE);
-    break;
-  case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE:
-  case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE:
-    break;
-    /* FIXME: monitor data correctness during download progress */
-    /* FIXME: do performance reports given sufficient verbosity */
-    /* FIXME: advance timeout task to "immediate" on error */
   default:
     break;
   }
@@ -242,460 +263,347 @@
 }
 
 
-struct StartContext
+/**
+ * Generate test data for publishing test.
+ *
+ * @param cls pointer to uint32_t with publishing seed
+ * @param offset offset to generate data for
+ * @param max maximum number of bytes to generate
+ * @param buf where to write generated data 
+ * @param emsg where to store error message (unused)
+ * @return number of bytes written to buf
+ */
+static size_t
+file_generator (void *cls, 
+               uint64_t offset,
+               size_t max, 
+               void *buf, 
+               char **emsg)
 {
-  struct GNUNET_TIME_Relative timeout;
-  unsigned int total;
-  unsigned int have;
-  struct GNUNET_FS_TestDaemon **daemons;
-  GNUNET_SCHEDULER_Task cont;
-  void *cont_cls;
-  struct GNUNET_TESTING_PeerGroup *group;
-  struct GNUNET_CONFIGURATION_Handle *cfg;
-  GNUNET_SCHEDULER_TaskIdentifier timeout_task;
-};
+  uint32_t *publish_seed = cls;
+  uint64_t pos;
+  uint8_t *cbuf = buf;
+  int mod;
 
-
-static void
-notify_running (void *cls, const struct GNUNET_PeerIdentity *id,
-                const struct GNUNET_CONFIGURATION_Handle *cfg,
-                struct GNUNET_TESTING_Daemon *d, const char *emsg)
-{
-  struct StartContext *sctx = cls;
-  unsigned int i;
-
   if (emsg != NULL)
+    *emsg = NULL;
+  if (buf == NULL)
+    return 0;
+  for (pos = 0; pos < 8; pos++)
+    cbuf[pos] = (uint8_t) (offset >> pos * 8);
+  for (pos = 8; pos < max; pos++)
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Failed to start daemon: %s\n"),
-                emsg);
-    return;
+    mod = (255 - (offset / 1024 / 32));
+    if (mod == 0)
+      mod = 1;
+    cbuf[pos] = (uint8_t) ((offset * (*publish_seed)) % mod);
   }
-  i = 0;
-  while (i < sctx->total)
-  {
-    if (GNUNET_TESTING_daemon_get (sctx->group, i) == d)
-      break;
-    i++;
-  }
-  GNUNET_assert (i < sctx->total);
-  GNUNET_assert (sctx->have < sctx->total);
-  GNUNET_assert (sctx->daemons[i]->cfg == NULL);
-  sctx->daemons[i]->cfg = GNUNET_CONFIGURATION_dup (cfg);
-  sctx->daemons[i]->group = sctx->group;
-  sctx->daemons[i]->daemon = d;
-  sctx->daemons[i]->id = *id;
-  sctx->have++;
-  if (sctx->have == sctx->total)
-  {
-    GNUNET_SCHEDULER_add_continuation (sctx->cont, sctx->cont_cls,
-                                       GNUNET_SCHEDULER_REASON_PREREQ_DONE);
-    sctx->daemons[0]->gcfg = sctx->cfg;
-    GNUNET_SCHEDULER_cancel (sctx->timeout_task);
-    for (i = 0; i < sctx->total; i++)
-    {
-      sctx->daemons[i]->fs =
-          GNUNET_FS_start (sctx->daemons[i]->cfg, "<tester>", &progress_cb,
-                           sctx->daemons[i], GNUNET_FS_FLAGS_NONE,
-                           GNUNET_FS_OPTIONS_END);
-    }
-    GNUNET_free (sctx);
-  }
+  return max;
 }
 
 
-static void
-start_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+/**
+ * Connect adapter for publishing operation.
+ * 
+ * @param cls the 'struct TestPublishOperation'
+ * @param cfg configuration of the peer to connect to; will be available until
+ *          GNUNET_TESTBED_operation_done() is called on the operation returned
+ *          from GNUNET_TESTBED_service_connect()
+ * @return service handle to return in 'op_result', NULL on error
+ */
+static void *
+publish_connect_adapter (void *cls,
+                        const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
-  struct StartContext *sctx = cls;
-  unsigned int i;
-
-  GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-              "Timeout while trying to start daemons\n");
-  GNUNET_TESTING_daemons_stop (sctx->group,
-                               GNUNET_TIME_relative_multiply
-                               (GNUNET_TIME_UNIT_SECONDS, 30),
-                               &shutdown_callback, NULL);
-  for (i = 0; i < sctx->total; i++)
-  {
-    if (i < sctx->have)
-      GNUNET_CONFIGURATION_destroy (sctx->daemons[i]->cfg);
-    GNUNET_free (sctx->daemons[i]);
-    sctx->daemons[i] = NULL;
-  }
-  GNUNET_CONFIGURATION_destroy (sctx->cfg);
-  GNUNET_SCHEDULER_add_continuation (sctx->cont, sctx->cont_cls,
-                                     GNUNET_SCHEDULER_REASON_TIMEOUT);
-  GNUNET_free (sctx);
+  struct TestPublishOperation *po = cls;
+ 
+  return GNUNET_FS_start (cfg,
+                         "fs-test-publish",
+                         &publish_progress_cb, po,
+                         GNUNET_FS_OPTIONS_END);
 }
 
 
 /**
- * Start daemons for testing.
- *
- * @param template_cfg_file configuration template to use
- * @param timeout if this operation cannot be completed within the
- *                given period, call the continuation with an error code
- * @param total number of daemons to start
- * @param daemons array of 'total' entries to be initialized
- *                (array must already be allocated, will be filled)
- * @param cont function to call when done
- * @param cont_cls closure for cont
+ * Adapter function called to destroy connection to file-sharing service.
+ * 
+ * @param cls the 'struct GNUNET_FS_Handle'
+ * @param op_result unused (different for publish/download!)
  */
-void
-GNUNET_FS_TEST_daemons_start (const char *template_cfg_file,
-                              struct GNUNET_TIME_Relative timeout,
-                              unsigned int total,
-                              struct GNUNET_FS_TestDaemon **daemons,
-                              GNUNET_SCHEDULER_Task cont, void *cont_cls)
+static void 
+fs_disconnect_adapter (void *cls,
+                      void *op_result)
 {
-  struct StartContext *sctx;
-  unsigned int i;
+  struct GNUNET_FS_Handle *fs = op_result;
 
-  GNUNET_assert (total > 0);
-  sctx = GNUNET_malloc (sizeof (struct StartContext));
-  sctx->daemons = daemons;
-  sctx->total = total;
-  sctx->cont = cont;
-  sctx->cont_cls = cont_cls;
-  sctx->cfg = GNUNET_CONFIGURATION_create ();
-  if (GNUNET_OK != GNUNET_CONFIGURATION_load (sctx->cfg, template_cfg_file))
-  {
-    GNUNET_break (0);
-    GNUNET_CONFIGURATION_destroy (sctx->cfg);
-    GNUNET_free (sctx);
-    GNUNET_SCHEDULER_add_continuation (cont, cont_cls,
-                                       GNUNET_SCHEDULER_REASON_TIMEOUT);
-    return;
-  }
-  for (i = 0; i < total; i++)
-    daemons[i] = GNUNET_malloc (sizeof (struct GNUNET_FS_TestDaemon));
-  sctx->group = GNUNET_TESTING_daemons_start (sctx->cfg, total, total,  /* 
Outstanding connections */
-                                              total,    /* Outstanding ssh 
connections */
-                                              timeout, NULL, NULL,
-                                              &notify_running, sctx, NULL, 
NULL,
-                                              NULL);
-  sctx->timeout_task =
-      GNUNET_SCHEDULER_add_delayed (timeout, &start_timeout, sctx);
+  GNUNET_FS_stop (fs);
 }
 
 
-struct GNUNET_FS_TEST_ConnectContext
-{
-  GNUNET_SCHEDULER_Task cont;
-  void *cont_cls;
-  struct GNUNET_TESTING_ConnectContext *cc;
-};
-
-
 /**
- * Prototype of a function that will be called whenever
- * two daemons are connected by the testing library.
+ * Callback to be called when testbed has connected to the fs service
  *
- * @param cls closure
- * @param first peer id for first daemon
- * @param second peer id for the second daemon
- * @param distance distance between the connected peers
- * @param first_cfg config for the first daemon
- * @param second_cfg config for the second daemon
- * @param first_daemon handle for the first daemon
- * @param second_daemon handle for the second daemon
- * @param emsg error message (NULL on success)
+ * @param cls the 'struct TestPublishOperation'
+ * @param op the operation that has been finished
+ * @param ca_result the 'struct GNUNET_FS_Handle ' (NULL on error)
+ * @param emsg error message in case the operation has failed; will be NULL if
+ *          operation has executed successfully.
  */
 static void
-notify_connection (void *cls, const struct GNUNET_PeerIdentity *first,
-                   const struct GNUNET_PeerIdentity *second, uint32_t distance,
-                   const struct GNUNET_CONFIGURATION_Handle *first_cfg,
-                   const struct GNUNET_CONFIGURATION_Handle *second_cfg,
-                   struct GNUNET_TESTING_Daemon *first_daemon,
-                   struct GNUNET_TESTING_Daemon *second_daemon,
-                   const char *emsg)
+publish_fs_connect_complete_cb (void *cls,
+                               struct GNUNET_TESTBED_Operation *op,
+                               void *ca_result,
+                               const char *emsg)
 {
-  struct GNUNET_FS_TEST_ConnectContext *cc = cls;
+  struct TestPublishOperation *po = cls;
+  struct GNUNET_FS_FileInformation *fi;
+  struct GNUNET_DISK_FileHandle *fh;
+  char *em;
+  uint64_t off;
+  char buf[DBLOCK_SIZE];
+  size_t bsize;
+  struct GNUNET_FS_BlockOptions bo;
 
-  cc->cc = NULL;
-  if (emsg != NULL)
-    GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to connect peers: %s\n",
-                emsg);
-  GNUNET_SCHEDULER_add_continuation (cc->cont, cc->cont_cls,
-                                     (emsg !=
-                                      NULL) ? GNUNET_SCHEDULER_REASON_TIMEOUT :
-                                     GNUNET_SCHEDULER_REASON_PREREQ_DONE);
-  GNUNET_free (cc);
+  if (NULL == ca_result)
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to connect to FS for 
publishing: %s\n", emsg);
+      po->publish_cont (po->publish_cont_cls,
+                       NULL);
+      GNUNET_TESTBED_operation_done (po->fs_op);
+      GNUNET_free (po);
+      return;
+    }
+  po->fs = ca_result;
+
+  bo.expiration_time = GNUNET_TIME_relative_to_absolute (CONTENT_LIFETIME);
+  bo.anonymity_level = po->anonymity;
+  bo.content_priority = 42;
+  bo.replication_level = 1;
+  if (GNUNET_YES == po->do_index)
+  {
+    po->publish_tmp_file = GNUNET_DISK_mktemp ("fs-test-publish-index");
+    GNUNET_assert (po->publish_tmp_file != NULL);
+    fh = GNUNET_DISK_file_open (po->publish_tmp_file,
+                                GNUNET_DISK_OPEN_WRITE |
+                                GNUNET_DISK_OPEN_CREATE,
+                                GNUNET_DISK_PERM_USER_READ |
+                                GNUNET_DISK_PERM_USER_WRITE);
+    GNUNET_assert (NULL != fh);
+    off = 0;
+    while (off < po->size)
+    {
+      bsize = GNUNET_MIN (sizeof (buf), po->size - off);
+      emsg = NULL;
+      GNUNET_assert (bsize == file_generator (&po->publish_seed, off, bsize, 
buf, &em));
+      GNUNET_assert (em == NULL);
+      GNUNET_assert (bsize == GNUNET_DISK_file_write (fh, buf, bsize));
+      off += bsize;
+    }
+    GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fh));
+    fi = GNUNET_FS_file_information_create_from_file (po->fs, po,
+                                                      po->publish_tmp_file,
+                                                      NULL, NULL, po->do_index,
+                                                      &bo);
+  }
+  else
+  {
+    fi = GNUNET_FS_file_information_create_from_reader (po->fs, po,
+                                                        po->size, 
+                                                       &file_generator, 
&po->publish_seed, 
+                                                       NULL, NULL,
+                                                        po->do_index, &bo);
+  }
+  po->publish_context =
+    GNUNET_FS_publish_start (po->fs, fi, NULL, NULL, NULL,
+                            GNUNET_FS_PUBLISH_OPTION_NONE);
 }
 
 
 /**
- * Connect two daemons for testing.
+ * Publish a file at the given peer.
  *
- * @param daemon1 first daemon to connect
- * @param daemon2 second first daemon to connect
+ * @param peer where to publish
  * @param timeout if this operation cannot be completed within the
  *                given period, call the continuation with an error code
+ * @param anonymity option for publication
+ * @param do_index GNUNET_YES for index, GNUNET_NO for insertion,
+ *                GNUNET_SYSERR for simulation
+ * @param size size of the file to publish
+ * @param seed seed to use for file generation
+ * @param verbose how verbose to be in reporting
  * @param cont function to call when done
  * @param cont_cls closure for cont
  */
-struct GNUNET_FS_TEST_ConnectContext *
-GNUNET_FS_TEST_daemons_connect (struct GNUNET_FS_TestDaemon *daemon1,
-                                struct GNUNET_FS_TestDaemon *daemon2,
-                                struct GNUNET_TIME_Relative timeout,
-                                GNUNET_SCHEDULER_Task cont, void *cont_cls)
+void
+GNUNET_FS_TEST_publish (struct GNUNET_TESTBED_Peer *peer,
+                        struct GNUNET_TIME_Relative timeout, uint32_t 
anonymity,
+                        int do_index, uint64_t size, uint32_t seed,
+                        unsigned int verbose,
+                        GNUNET_FS_TEST_UriContinuation cont, void *cont_cls)
 {
-  struct GNUNET_FS_TEST_ConnectContext *ncc;
+  struct TestPublishOperation *po;
 
-  ncc = GNUNET_malloc (sizeof (struct GNUNET_FS_TEST_ConnectContext));
-  ncc->cont = cont;
-  ncc->cont_cls = cont_cls;
-  ncc->cc =
-      GNUNET_TESTING_daemons_connect (daemon1->daemon, daemon2->daemon, 
timeout,
-                                      CONNECT_ATTEMPTS, GNUNET_YES,
-                                      &notify_connection, ncc);
-  return ncc;
+  po = GNUNET_malloc (sizeof (struct TestPublishOperation));
+  po->publish_cont = cont;
+  po->publish_cont_cls = cont_cls;
+  po->publish_seed = seed;
+  po->anonymity = anonymity;
+  po->size = size;
+  po->verbose = verbose;
+  po->do_index = do_index;
+  po->fs_op = GNUNET_TESTBED_service_connect (po,
+                                             peer,
+                                             "fs",
+                                             &publish_fs_connect_complete_cb,
+                                             po,
+                                             &publish_connect_adapter,
+                                             &fs_disconnect_adapter,
+                                             po);
+  po->publish_timeout_task =
+      GNUNET_SCHEDULER_add_delayed (timeout, &publish_timeout, po);
 }
 
 
+/* ************************** download ************************ */
+
+
 /**
- * Cancel connect operation.
+ * Task scheduled to run when download operation times out.
  *
- * @param cc operation to cancel
+ * @param cls the download operation context
+ * @param tc scheduler context (unused)
  */
-void
-GNUNET_FS_TEST_daemons_connect_cancel (struct GNUNET_FS_TEST_ConnectContext 
*cc)
+static void
+download_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
-  GNUNET_TESTING_daemons_connect_cancel (cc->cc);
-  GNUNET_free (cc);
+  struct TestDownloadOperation *dop = cls;
+
+  GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+              "Timeout while trying to download file\n");
+  dop->download_timeout_task = GNUNET_SCHEDULER_NO_TASK;
+  GNUNET_FS_download_stop (dop->download_context, GNUNET_YES);
+  GNUNET_SCHEDULER_add_continuation (dop->download_cont,
+                                     dop->download_cont_cls,
+                                     GNUNET_SCHEDULER_REASON_TIMEOUT);
+  if (NULL == dop->fs)
+    GNUNET_TESTBED_operation_cancel (dop->fs_op);
+  else
+    GNUNET_TESTBED_operation_done (dop->fs_op);
+  GNUNET_FS_uri_destroy (dop->uri);
+  GNUNET_free (dop);
 }
 
 
 /**
- * Obtain peer configuration used for testing.
+ * Task scheduled to report on the completion of our download operation.
  *
- * @param daemons array with the daemons
- * @param off which configuration to get
- * @return peer configuration
+ * @param cls the download operation context
+ * @param tc scheduler context (unused)
  */
-const struct GNUNET_CONFIGURATION_Handle *
-GNUNET_FS_TEST_get_configuration (struct GNUNET_FS_TestDaemon **daemons,
-                                  unsigned int off)
+static void
+report_success (void *cls,
+               const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
-  return daemons[off]->cfg;
-}
+  struct TestDownloadOperation *dop = cls;
 
-/**
- * Obtain peer group used for testing.
- *
- * @param daemons array with the daemons (must contain at least one)
- * @return peer group
- */
-struct GNUNET_TESTING_PeerGroup *
-GNUNET_FS_TEST_get_group (struct GNUNET_FS_TestDaemon **daemons)
-{
-  return daemons[0]->group;
+  GNUNET_FS_download_stop (dop->download_context, GNUNET_YES);
+  GNUNET_SCHEDULER_add_continuation (dop->download_cont,
+                                     dop->download_cont_cls,
+                                     GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+  GNUNET_TESTBED_operation_done (dop->fs_op);
+  GNUNET_FS_uri_destroy (dop->uri);
+  GNUNET_free (dop);
 }
 
 
 /**
- * Stop daemons used for testing.
+ * Progress callback for file-sharing events while downloading.
  *
- * @param total number of daemons to stop
- * @param daemons array with the daemons (values will be clobbered)
+ * @param cls the download operation context
+ * @param info information about the event
  */
-void
-GNUNET_FS_TEST_daemons_stop (unsigned int total,
-                             struct GNUNET_FS_TestDaemon **daemons)
+static void *
+download_progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
 {
-  unsigned int i;
-  struct GNUNET_TESTING_PeerGroup *pg;
-  struct GNUNET_CONFIGURATION_Handle *gcfg;
-  struct GNUNET_FS_TestDaemon *daemon;
+  struct TestDownloadOperation *dop = cls;
 
-  GNUNET_assert (total > 0);
-  GNUNET_assert (daemons[0] != NULL);
-  pg = daemons[0]->group;
-  gcfg = daemons[0]->gcfg;
-  for (i = 0; i < total; i++)
+  switch (info->status)
   {
-    daemon = daemons[i];
-    if (daemon->download_timeout_task != GNUNET_SCHEDULER_NO_TASK)
-    {
-      GNUNET_SCHEDULER_cancel (daemon->download_timeout_task);
-      daemon->download_timeout_task = GNUNET_SCHEDULER_NO_TASK;
-    }
-    if (daemon->publish_timeout_task != GNUNET_SCHEDULER_NO_TASK)
-    {
-      GNUNET_SCHEDULER_cancel (daemon->publish_timeout_task);
-      daemon->publish_timeout_task = GNUNET_SCHEDULER_NO_TASK;
-    }
-    if (NULL != daemon->download_context)
-    {
-      GNUNET_FS_download_stop (daemon->download_context, GNUNET_YES);
-      daemon->download_context = NULL;
-    }
-    if (daemon->fs != NULL)
-      GNUNET_FS_stop (daemon->fs);
-    if (daemon->cfg != NULL)
-      GNUNET_CONFIGURATION_destroy (daemon->cfg);
-    if (NULL != daemon->publish_tmp_file)
-    {
-      GNUNET_break (GNUNET_OK ==
-                    GNUNET_DISK_directory_remove (daemon->publish_tmp_file));
-      GNUNET_free (daemon->publish_tmp_file);
-      daemon->publish_tmp_file = NULL;
-    }
-    GNUNET_free (daemon);
-    daemons[i] = NULL;
+  case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS:
+    if (dop->verbose)
+      GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Download at %llu/%llu bytes\n",
+                  (unsigned long long) info->value.download.completed,
+                  (unsigned long long) info->value.download.size);
+    break;
+  case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED:
+    GNUNET_SCHEDULER_cancel (dop->download_timeout_task);
+    dop->download_timeout_task = GNUNET_SCHEDULER_NO_TASK;
+    GNUNET_SCHEDULER_add_continuation (&report_success, dop,
+                                       GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+    break;
+  case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE:
+  case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE:
+    break;
+    /* FIXME: monitor data correctness during download progress */
+    /* FIXME: do performance reports given sufficient verbosity */
+    /* FIXME: advance timeout task to "immediate" on error */
+  default:
+    break;
   }
-  GNUNET_TESTING_daemons_stop (pg,
-                               GNUNET_TIME_relative_multiply
-                               (GNUNET_TIME_UNIT_SECONDS, 30),
-                               &shutdown_callback, gcfg);
+  return NULL;
 }
 
 
-static void
-publish_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+/**
+ * Connect adapter for download operation.
+ * 
+ * @param cls the 'struct TestDownloadOperation'
+ * @param cfg configuration of the peer to connect to; will be available until
+ *          GNUNET_TESTBED_operation_done() is called on the operation returned
+ *          from GNUNET_TESTBED_service_connect()
+ * @return service handle to return in 'op_result', NULL on error
+ */
+static void *
+download_connect_adapter (void *cls,
+                        const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
-  struct GNUNET_FS_TestDaemon *daemon = cls;
-  GNUNET_FS_TEST_UriContinuation cont;
-
-  GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-              "Timeout while trying to publish data\n");
-  cont = daemon->publish_cont;
-  daemon->publish_timeout_task = GNUNET_SCHEDULER_NO_TASK;
-  daemon->publish_cont = NULL;
-  GNUNET_FS_publish_stop (daemon->publish_context);
-  daemon->publish_context = NULL;
-  cont (daemon->publish_cont_cls, NULL);
+  struct TestPublishOperation *po = cls;
+ 
+  return GNUNET_FS_start (cfg,
+                         "fs-test-download",
+                         &download_progress_cb, po,
+                         GNUNET_FS_OPTIONS_END);
 }
 
 
-static size_t
-file_generator (void *cls, uint64_t offset, size_t max, void *buf, char **emsg)
-{
-  struct GNUNET_FS_TestDaemon *daemon = cls;
-  uint64_t pos;
-  uint8_t *cbuf = buf;
-  int mod;
-
-  if (emsg != NULL)
-    *emsg = NULL;
-  if (buf == NULL)
-    return 0;
-  for (pos = 0; pos < 8; pos++)
-    cbuf[pos] = (uint8_t) (offset >> pos * 8);
-  for (pos = 8; pos < max; pos++)
-  {
-    mod = (255 - (offset / 1024 / 32));
-    if (mod == 0)
-      mod = 1;
-    cbuf[pos] = (uint8_t) ((offset * daemon->publish_seed) % mod);
-  }
-  return max;
-}
-
-
-
 /**
- * Publish a file at the given daemon.
+ * Callback to be called when testbed has connected to the fs service
  *
- * @param daemon where to publish
- * @param timeout if this operation cannot be completed within the
- *                given period, call the continuation with an error code
- * @param anonymity option for publication
- * @param do_index GNUNET_YES for index, GNUNET_NO for insertion,
- *                GNUNET_SYSERR for simulation
- * @param size size of the file to publish
- * @param seed seed to use for file generation
- * @param verbose how verbose to be in reporting
- * @param cont function to call when done
- * @param cont_cls closure for cont
+ * @param cls the 'struct TestPublishOperation'
+ * @param op the operation that has been finished
+ * @param ca_result the 'struct GNUNET_FS_Handle ' (NULL on error)
+ * @param emsg error message in case the operation has failed; will be NULL if
+ *          operation has executed successfully.
  */
-void
-GNUNET_FS_TEST_publish (struct GNUNET_FS_TestDaemon *daemon,
-                        struct GNUNET_TIME_Relative timeout, uint32_t 
anonymity,
-                        int do_index, uint64_t size, uint32_t seed,
-                        unsigned int verbose,
-                        GNUNET_FS_TEST_UriContinuation cont, void *cont_cls)
-{
-  struct GNUNET_FS_FileInformation *fi;
-  struct GNUNET_DISK_FileHandle *fh;
-  char *emsg;
-  uint64_t off;
-  char buf[DBLOCK_SIZE];
-  size_t bsize;
-  struct GNUNET_FS_BlockOptions bo;
-
-  GNUNET_assert (daemon->publish_cont == NULL);
-  daemon->publish_cont = cont;
-  daemon->publish_cont_cls = cont_cls;
-  daemon->publish_seed = seed;
-  daemon->verbose = verbose;
-  bo.expiration_time = GNUNET_TIME_relative_to_absolute (CONTENT_LIFETIME);
-  bo.anonymity_level = anonymity;
-  bo.content_priority = 42;
-  bo.replication_level = 1;
-  if (GNUNET_YES == do_index)
-  {
-    GNUNET_assert (daemon->publish_tmp_file == NULL);
-    daemon->publish_tmp_file = GNUNET_DISK_mktemp ("fs-test-publish-index");
-    GNUNET_assert (daemon->publish_tmp_file != NULL);
-    fh = GNUNET_DISK_file_open (daemon->publish_tmp_file,
-                                GNUNET_DISK_OPEN_WRITE |
-                                GNUNET_DISK_OPEN_CREATE,
-                                GNUNET_DISK_PERM_USER_READ |
-                                GNUNET_DISK_PERM_USER_WRITE);
-    GNUNET_assert (NULL != fh);
-    off = 0;
-    while (off < size)
-    {
-      bsize = GNUNET_MIN (sizeof (buf), size - off);
-      emsg = NULL;
-      GNUNET_assert (bsize == file_generator (daemon, off, bsize, buf, &emsg));
-      GNUNET_assert (emsg == NULL);
-      GNUNET_assert (bsize == GNUNET_DISK_file_write (fh, buf, bsize));
-      off += bsize;
-    }
-    GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fh));
-    fi = GNUNET_FS_file_information_create_from_file (daemon->fs, daemon,
-                                                      daemon->publish_tmp_file,
-                                                      NULL, NULL, do_index,
-                                                      &bo);
-  }
-  else
-  {
-    fi = GNUNET_FS_file_information_create_from_reader (daemon->fs, daemon,
-                                                        size, &file_generator,
-                                                        daemon, NULL, NULL,
-                                                        do_index, &bo);
-  }
-  daemon->publish_context =
-      GNUNET_FS_publish_start (daemon->fs, fi, NULL, NULL, NULL,
-                               GNUNET_FS_PUBLISH_OPTION_NONE);
-  daemon->publish_timeout_task =
-      GNUNET_SCHEDULER_add_delayed (timeout, &publish_timeout, daemon);
-}
-
-
 static void
-download_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+download_fs_connect_complete_cb (void *cls,
+                                struct GNUNET_TESTBED_Operation *op,
+                                void *ca_result,
+                                const char *emsg)
 {
-  struct GNUNET_FS_TestDaemon *daemon = cls;
+  struct TestDownloadOperation *dop = cls;
 
-  GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-              "Timeout while trying to download file\n");
-  daemon->download_timeout_task = GNUNET_SCHEDULER_NO_TASK;
-  GNUNET_FS_download_stop (daemon->download_context, GNUNET_YES);
-  daemon->download_context = NULL;
-  GNUNET_SCHEDULER_add_continuation (daemon->download_cont,
-                                     daemon->download_cont_cls,
-                                     GNUNET_SCHEDULER_REASON_TIMEOUT);
-  daemon->download_cont = NULL;
+  dop->download_context =
+    GNUNET_FS_download_start (dop->fs, dop->uri, NULL, NULL, NULL, 0, 
dop->size,
+                             dop->anonymity, GNUNET_FS_DOWNLOAD_OPTION_NONE,
+                             NULL, NULL);
 }
 
 
 /**
  * Perform test download.
  *
- * @param daemon which peer to download from
+ * @param peer which peer to download from
  * @param timeout if this operation cannot be completed within the
  *                given period, call the continuation with an error code
  * @param anonymity option for download
@@ -706,26 +614,34 @@
  * @param cont_cls closure for cont
  */
 void
-GNUNET_FS_TEST_download (struct GNUNET_FS_TestDaemon *daemon,
+GNUNET_FS_TEST_download (struct GNUNET_TESTBED_Peer *peer,
                          struct GNUNET_TIME_Relative timeout,
                          uint32_t anonymity, uint32_t seed,
                          const struct GNUNET_FS_Uri *uri, unsigned int verbose,
                          GNUNET_SCHEDULER_Task cont, void *cont_cls)
 {
-  uint64_t size;
+  struct TestDownloadOperation *dop;
 
-  GNUNET_assert (daemon->download_cont == NULL);
-  size = GNUNET_FS_uri_chk_get_file_size (uri);
-  daemon->verbose = verbose;
-  daemon->download_cont = cont;
-  daemon->download_cont_cls = cont_cls;
-  daemon->download_seed = seed;
-  daemon->download_context =
-      GNUNET_FS_download_start (daemon->fs, uri, NULL, NULL, NULL, 0, size,
-                                anonymity, GNUNET_FS_DOWNLOAD_OPTION_NONE, 
NULL,
-                                NULL);
-  daemon->download_timeout_task =
-      GNUNET_SCHEDULER_add_delayed (timeout, &download_timeout, daemon);
+  dop = GNUNET_malloc (sizeof (struct TestDownloadOperation));
+  dop->uri = GNUNET_FS_uri_dup (uri);
+  dop->size = GNUNET_FS_uri_chk_get_file_size (uri);
+  dop->verbose = verbose;
+  dop->anonymity = anonymity;
+  dop->download_cont = cont;
+  dop->download_cont_cls = cont_cls;
+  dop->download_seed = seed;
+
+  dop->fs_op = GNUNET_TESTBED_service_connect (dop,
+                                              peer,
+                                              "fs",
+                                              &download_fs_connect_complete_cb,
+                                              dop,
+                                              &download_connect_adapter,
+                                              &fs_disconnect_adapter,
+                                              dop);
+  dop->download_timeout_task =
+      GNUNET_SCHEDULER_add_delayed (timeout, &download_timeout, dop);
 }
 
-/* end of test_fs_lib.c */
+
+/* end of fs_test_lib.c */

Modified: gnunet/src/fs/fs_test_lib.h
===================================================================
--- gnunet/src/fs/fs_test_lib.h 2012-09-09 12:30:54 UTC (rev 23719)
+++ gnunet/src/fs/fs_test_lib.h 2012-09-09 13:28:48 UTC (rev 23720)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     (C) 2010 Christian Grothoff (and other contributing authors)
+     (C) 2010, 2012 Christian Grothoff (and other contributing authors)
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -20,8 +20,8 @@
 
 /**
  * @file fs/fs_test_lib.h
- * @brief library routines for testing FS publishing and downloading
- *        with multiple peers; this code is limited to flat files
+ * @brief library routines for testing FS publishing and downloading;
+ *        this code is limited to flat files
  *        and no keywords (those functions can be tested with
  *        single-peer setups; this is for testing routing).
  * @author Christian Grothoff
@@ -31,100 +31,10 @@
 
 #include "gnunet_util_lib.h"
 #include "gnunet_fs_service.h"
+#include "gnunet_testbed_service.h"
 
-/**
- * Handle for a daemon started for testing FS.
- */
-struct GNUNET_FS_TestDaemon;
 
-
 /**
- * Start daemons for testing.
- *
- * @param template_cfg_file configuration template to use
- * @param timeout if this operation cannot be completed within the
- *                given period, call the continuation with an error code
- * @param total number of daemons to start
- * @param daemons array of 'total' entries to be initialized
- *                (array must already be allocated, will be filled)
- * @param cont function to call when done; note that if 'cont'
- *             is called with reason "TIMEOUT", then starting the
- *             daemons has failed and the client MUST NOT call
- *             'GNUNET_FS_TEST_daemons_stop'!
- * @param cont_cls closure for cont
- */
-void
-GNUNET_FS_TEST_daemons_start (const char *template_cfg_file,
-                              struct GNUNET_TIME_Relative timeout,
-                              unsigned int total,
-                              struct GNUNET_FS_TestDaemon **daemons,
-                              GNUNET_SCHEDULER_Task cont, void *cont_cls);
-
-
-struct GNUNET_FS_TEST_ConnectContext;
-
-
-/**
- * Connect two daemons for testing.
- *
- * @param daemon1 first daemon to connect
- * @param daemon2 second first daemon to connect
- * @param timeout if this operation cannot be completed within the
- *                given period, call the continuation with an error code
- * @param cont function to call when done
- * @param cont_cls closure for cont
- */
-struct GNUNET_FS_TEST_ConnectContext *
-GNUNET_FS_TEST_daemons_connect (struct GNUNET_FS_TestDaemon *daemon1,
-                                struct GNUNET_FS_TestDaemon *daemon2,
-                                struct GNUNET_TIME_Relative timeout,
-                                GNUNET_SCHEDULER_Task cont, void *cont_cls);
-
-
-/**
- * Cancel connect operation.
- *
- * @param cc operation to cancel
- */
-void
-GNUNET_FS_TEST_daemons_connect_cancel (struct GNUNET_FS_TEST_ConnectContext
-                                       *cc);
-
-
-/**
- * Obtain peer group used for testing.
- *
- * @param daemons array with the daemons (must contain at least one)
- * @return peer group
- */
-struct GNUNET_TESTING_PeerGroup *
-GNUNET_FS_TEST_get_group (struct GNUNET_FS_TestDaemon **daemons);
-
-
-
-/**
- * Obtain peer configuration used for testing.
- *
- * @param daemons array with the daemons
- * @param off which configuration to get
- * @return peer configuration
- */
-const struct GNUNET_CONFIGURATION_Handle *
-GNUNET_FS_TEST_get_configuration (struct GNUNET_FS_TestDaemon **daemons,
-                                  unsigned int off);
-
-/**
- * Stop daemons used for testing.
- *
- * @param total number of daemons to stop
- * @param daemons array with the daemons (values will be clobbered)
- */
-void
-GNUNET_FS_TEST_daemons_stop (unsigned int total,
-                             struct GNUNET_FS_TestDaemon **daemons);
-
-
-/**
  * Function signature.
  *
  * @param cls closure (user defined)
@@ -138,7 +48,7 @@
 /**
  * Publish a file at the given daemon.
  *
- * @param daemon where to publish
+ * @param peer where to publish
  * @param timeout if this operation cannot be completed within the
  *                given period, call the continuation with an error code
  * @param anonymity option for publication
@@ -151,7 +61,7 @@
  * @param cont_cls closure for cont
  */
 void
-GNUNET_FS_TEST_publish (struct GNUNET_FS_TestDaemon *daemon,
+GNUNET_FS_TEST_publish (struct GNUNET_TESTBED_Peer *peer,
                         struct GNUNET_TIME_Relative timeout, uint32_t 
anonymity,
                         int do_index, uint64_t size, uint32_t seed,
                         unsigned int verbose,
@@ -161,7 +71,7 @@
 /**
  * Perform test download.
  *
- * @param daemon which peer to download from
+ * @param peer which peer to download from
  * @param timeout if this operation cannot be completed within the
  *                given period, call the continuation with an error code
  * @param anonymity option for download
@@ -172,7 +82,7 @@
  * @param cont_cls closure for cont
  */
 void
-GNUNET_FS_TEST_download (struct GNUNET_FS_TestDaemon *daemon,
+GNUNET_FS_TEST_download (struct GNUNET_TESTBED_Peer *peer,
                          struct GNUNET_TIME_Relative timeout,
                          uint32_t anonymity, uint32_t seed,
                          const struct GNUNET_FS_Uri *uri, unsigned int verbose,

Modified: gnunet/src/fs/perf_gnunet_service_fs_p2p.c
===================================================================
--- gnunet/src/fs/perf_gnunet_service_fs_p2p.c  2012-09-09 12:30:54 UTC (rev 
23719)
+++ gnunet/src/fs/perf_gnunet_service_fs_p2p.c  2012-09-09 13:28:48 UTC (rev 
23720)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     (C) 2010 Christian Grothoff (and other contributing authors)
+     (C) 2010, 2012 Christian Grothoff (and other contributing authors)
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -25,7 +25,7 @@
  */
 #include "platform.h"
 #include "fs_test_lib.h"
-#include "gnunet_testing_lib.h"
+#include "gnunet_testbed_service.h"
 
 #define VERBOSE GNUNET_NO
 
@@ -43,7 +43,7 @@
 
 #define SEED 42
 
-static struct GNUNET_FS_TestDaemon *daemons[NUM_DAEMONS];
+static struct GNUNET_TESTBED_Peer *daemons[NUM_DAEMONS];
 
 static int ok;
 
@@ -51,19 +51,14 @@
 
 static const char *progname;
 
-static void
-do_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
-  GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, daemons);
-}
 
-
 /**
  * Master context for 'stat_run'.
  */
 struct StatMaster
 {
   struct GNUNET_STATISTICS_Handle *stat;
+  struct GNUNET_TESTBED_Operation *op;
   unsigned int daemon;
   unsigned int value;
 };
@@ -130,7 +125,10 @@
  * Function that gathers stats from all daemons.
  */
 static void
-stat_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
+stat_run (void *cls, 
+         struct GNUNET_TESTBED_Operation *op,
+         void *ca_result,
+         const char *emsg);
 
 
 /**
@@ -143,18 +141,65 @@
 
   GNUNET_break (GNUNET_OK == success);
   sm->value++;
-  GNUNET_SCHEDULER_add_now (&stat_run, sm);
+  stat_run (sm, sm->op, sm->stat, NULL);
 }
 
 
 /**
+ * Adapter function called to establish a connection to
+ * statistics service.
+ * 
+ * @param cls closure
+ * @param cfg configuration of the peer to connect to; will be available until
+ *          GNUNET_TESTBED_operation_done() is called on the operation returned
+ *          from GNUNET_TESTBED_service_connect()
+ * @return service handle to return in 'op_result', NULL on error
+ */
+static void *
+statistics_connect_adapter (void *cls,
+                           const struct GNUNET_CONFIGURATION_Handle *cfg)
+{
+  return GNUNET_STATISTICS_create ("<driver>",
+                                  cfg);
+}
+
+
+/**
+ * Adapter function called to destroy a connection to
+ * statistics service.
+ * 
+ * @param cls closure
+ * @param op_result service handle returned from the connect adapter
+ */
+static void 
+statistics_disconnect_adapter (void *cls,
+                              void *op_result)
+{
+  GNUNET_STATISTICS_destroy (op_result, GNUNET_NO);
+}
+
+
+/**
  * Function that gathers stats from all daemons.
  */
 static void
-stat_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+stat_run (void *cls, 
+         struct GNUNET_TESTBED_Operation *op,
+         void *ca_result,
+         const char *emsg)
 {
   struct StatMaster *sm = cls;
 
+  if (NULL != emsg)
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                 "Failed to statistics service: %s\n",
+                 emsg);
+      GNUNET_SCHEDULER_shutdown ();
+      return;
+    }
+  sm->stat = ca_result;
+
   if (stats[sm->value].name != NULL)
   {
     GNUNET_STATISTICS_get (sm->stat,
@@ -167,20 +212,23 @@
                            sm);
     return;
   }
-  GNUNET_STATISTICS_destroy (sm->stat, GNUNET_NO);
+  GNUNET_TESTBED_operation_done (sm->op);
   sm->value = 0;
   sm->daemon++;
-  if (sm->daemon == NUM_DAEMONS)
+  if (NUM_DAEMONS == sm->daemon)
   {
     GNUNET_free (sm);
-    GNUNET_SCHEDULER_add_now (&do_stop, NULL);
+    GNUNET_SCHEDULER_shutdown ();
     return;
   }
-  sm->stat =
-      GNUNET_STATISTICS_create ("<driver>",
-                                GNUNET_FS_TEST_get_configuration (daemons,
-                                                                  sm->daemon));
-  GNUNET_SCHEDULER_add_now (&stat_run, sm);
+  sm->op =
+    GNUNET_TESTBED_service_connect (NULL,
+                                   daemons[sm->daemon],
+                                   "statistics",
+                                   &stat_run, sm,
+                                   &statistics_connect_adapter,
+                                   &statistics_disconnect_adapter,
+                                   NULL);
 }
 
 
@@ -191,32 +239,33 @@
   char *fancy;
   struct StatMaster *sm;
 
-  if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT))
+  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT)) 
   {
-    del = GNUNET_TIME_absolute_get_duration (start_time);
-    if (del.rel_value == 0)
-      del.rel_value = 1;
-    fancy =
-        GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) *
-                                        1000LL / del.rel_value);
-    FPRINTF (stdout, "Download speed was %s/s\n", fancy);
-    GNUNET_free (fancy);
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Finished download, shutting down\n",
-                (unsigned long long) FILESIZE);
-    sm = GNUNET_malloc (sizeof (struct StatMaster));
-    sm->stat =
-        GNUNET_STATISTICS_create ("<driver>",
-                                  GNUNET_FS_TEST_get_configuration (daemons,
-                                                                    
sm->daemon));
-    GNUNET_SCHEDULER_add_now (&stat_run, sm);
-  }
-  else
-  {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "Timeout during download, shutting down with error\n");
     ok = 1;
-    GNUNET_SCHEDULER_add_now (&do_stop, NULL);
+    GNUNET_SCHEDULER_shutdown ();
+    return;
   }
+  del = GNUNET_TIME_absolute_get_duration (start_time);
+  if (del.rel_value == 0)
+    del.rel_value = 1;
+  fancy =
+    GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) *
+                                   1000LL / del.rel_value);
+  FPRINTF (stdout, "Download speed was %s/s\n", fancy);
+  GNUNET_free (fancy);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Finished download, shutting down\n",
+             (unsigned long long) FILESIZE);
+  sm = GNUNET_malloc (sizeof (struct StatMaster));
+  sm->op =
+    GNUNET_TESTBED_service_connect (NULL,
+                                   daemons[sm->daemon],
+                                   "statistics",
+                                   &stat_run, sm,
+                                   &statistics_connect_adapter,
+                                   &statistics_disconnect_adapter,
+                                   NULL);
 }
 
 
@@ -226,8 +275,8 @@
   int anonymity;
 
   if (NULL == uri)
-  {
-    GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, daemons);
+    {
+    GNUNET_SCHEDULER_shutdown ();
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "Timeout during upload attempt, shutting down with error\n");
     ok = 1;
@@ -246,14 +295,16 @@
 
 
 static void
-do_publish (void *cls, const char *emsg)
+do_publish (void *cls,
+           struct GNUNET_TESTBED_Operation *op,
+           const char *emsg)
 {
   int do_index;
   int anonymity;
 
   if (NULL != emsg)
   {
-    GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, daemons);
+    GNUNET_SCHEDULER_shutdown ();
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error trying to connect: %s\n", 
emsg);
     ok = 1;
     return;
@@ -276,54 +327,33 @@
 
 
 static void
-do_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+do_connect (void *cls, 
+           unsigned int num_peers,
+           struct GNUNET_TESTBED_Peer **peers)
 {
-  struct GNUNET_TESTING_PeerGroup *pg;
-
-  GNUNET_assert (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE));
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Daemons started, will now try to connect them\n");
-  pg = GNUNET_FS_TEST_get_group (daemons);
-  GNUNET_break ((NUM_DAEMONS - 1) * 2 ==
-                (GNUNET_TESTING_create_topology
-                 (pg, GNUNET_TESTING_TOPOLOGY_LINE,
-                  GNUNET_TESTING_TOPOLOGY_NONE, NULL)));
-  GNUNET_TESTING_connect_topology (pg, GNUNET_TESTING_TOPOLOGY_LINE,
-                                   GNUNET_TESTING_TOPOLOGY_OPTION_NONE, 0.0,
-                                   TIMEOUT, NUM_DAEMONS, &do_publish, NULL);
+  unsigned int i;
+ 
+  GNUNET_assert (NUM_DAEMONS == num_peers);
+  for (i=0;i<num_peers;i++)
+    daemons[i] = peers[i];
+  GNUNET_TESTBED_overlay_connect (NULL,
+                                 &do_publish,
+                                 NULL,
+                                 peers[0],
+                                 peers[1]);
+  // FIXME: was supposed to connect in line...
 }
 
 
-static void
-run (void *cls, char *const *args, const char *cfgfile,
-     const struct GNUNET_CONFIGURATION_Handle *cfg)
-{
-  GNUNET_FS_TEST_daemons_start ("perf_gnunet_service_fs_p2p.conf", TIMEOUT, 
NUM_DAEMONS,
-                                daemons, &do_connect, NULL);
-}
-
-
 int
 main (int argc, char *argv[])
 {
-  char *const argvx[] = {
-    "perf-gnunet-service-fs-p2p",
-    "-c",
-    "perf_gnunet_service_fs_p2p.conf",
-    NULL
-  };
-  struct GNUNET_GETOPT_CommandLineOption options[] = {
-    GNUNET_GETOPT_OPTION_END
-  };
-  progname = argv[0];
+  GNUNET_TESTBED_test_run ("perf-gnunet-service-fs-p2p",
+                          "perf_gnunet_service_fs_p2p.conf",
+                          NUM_DAEMONS,
+                          0, NULL, NULL,
+                          &do_connect, NULL);
   GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/");
-  GNUNET_log_setup ("perf_gnunet_service_fs_p2p_index",
-                    "WARNING",
-                    NULL);
-  GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx,
-                      "perf-gnunet-service-fs-p2p-index", "nohelp", options,
-                      &run, NULL);
-  GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/");
   return ok;
 }
 

Modified: gnunet/src/fs/perf_gnunet_service_fs_p2p_respect.c
===================================================================
--- gnunet/src/fs/perf_gnunet_service_fs_p2p_respect.c  2012-09-09 12:30:54 UTC 
(rev 23719)
+++ gnunet/src/fs/perf_gnunet_service_fs_p2p_respect.c  2012-09-09 13:28:48 UTC 
(rev 23720)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     (C) 2010, 2011 Christian Grothoff (and other contributing authors)
+     (C) 2010, 2011, 2012 Christian Grothoff (and other contributing authors)
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -45,7 +45,7 @@
  */
 #include "platform.h"
 #include "fs_test_lib.h"
-#include "gnunet_testing_lib.h"
+#include "gnunet_testbed_service.h"
 
 #define VERBOSE GNUNET_NO
 
@@ -74,7 +74,7 @@
  */
 #define SEED2 43
 
-static struct GNUNET_FS_TestDaemon *daemons[NUM_DAEMONS];
+static struct GNUNET_TESTBED_Peer *daemons[NUM_DAEMONS];
 
 static int ok;
 
@@ -86,19 +86,14 @@
 
 static struct GNUNET_FS_Uri *uri2;
 
-static void
-do_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
-  GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, daemons);
-}
 
-
 /**
  * Master context for 'stat_run'.
  */
 struct StatMaster
 {
   struct GNUNET_STATISTICS_Handle *stat;
+  struct GNUNET_TESTBED_Operation *op;
   unsigned int daemon;
   unsigned int value;
 };
@@ -163,7 +158,10 @@
  * Function that gathers stats from all daemons.
  */
 static void
-stat_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
+stat_run (void *cls, 
+         struct GNUNET_TESTBED_Operation *op,
+         void *ca_result,
+         const char *emsg);
 
 
 /**
@@ -176,15 +174,53 @@
 
   GNUNET_break (GNUNET_OK == success);
   sm->value++;
-  GNUNET_SCHEDULER_add_now (&stat_run, sm);
+  stat_run (sm, sm->op, sm->stat, NULL);
 }
 
 
+
 /**
+ * Adapter function called to establish a connection to
+ * statistics service.
+ * 
+ * @param cls closure
+ * @param cfg configuration of the peer to connect to; will be available until
+ *          GNUNET_TESTBED_operation_done() is called on the operation returned
+ *          from GNUNET_TESTBED_service_connect()
+ * @return service handle to return in 'op_result', NULL on error
+ */
+static void *
+statistics_connect_adapter (void *cls,
+                           const struct GNUNET_CONFIGURATION_Handle *cfg)
+{
+  return GNUNET_STATISTICS_create ("<driver>",
+                                  cfg);
+}
+
+
+/**
+ * Adapter function called to destroy a connection to
+ * statistics service.
+ * 
+ * @param cls closure
+ * @param op_result service handle returned from the connect adapter
+ */
+static void 
+statistics_disconnect_adapter (void *cls,
+                              void *op_result)
+{
+  GNUNET_STATISTICS_destroy (op_result, GNUNET_NO);
+}
+
+
+/**
  * Function that gathers stats from all daemons.
  */
 static void
-stat_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+stat_run (void *cls, 
+         struct GNUNET_TESTBED_Operation *op,
+         void *ca_result,
+         const char *emsg)
 {
   struct StatMaster *sm = cls;
 
@@ -200,20 +236,23 @@
                            sm);
     return;
   }
-  GNUNET_STATISTICS_destroy (sm->stat, GNUNET_NO);
+  GNUNET_TESTBED_operation_done (sm->op);
   sm->value = 0;
   sm->daemon++;
-  if (sm->daemon == NUM_DAEMONS)
+  if (NUM_DAEMONS == sm->daemon)
   {
     GNUNET_free (sm);
-    GNUNET_SCHEDULER_add_now (&do_stop, NULL);
+    GNUNET_SCHEDULER_shutdown ();
     return;
   }
-  sm->stat =
-      GNUNET_STATISTICS_create ("<driver>",
-                                GNUNET_FS_TEST_get_configuration (daemons,
-                                                                  sm->daemon));
-  GNUNET_SCHEDULER_add_now (&stat_run, sm);
+  sm->op =
+    GNUNET_TESTBED_service_connect (NULL,
+                                   daemons[sm->daemon],
+                                   "statistics",
+                                   &stat_run, sm,
+                                   &statistics_connect_adapter,
+                                   &statistics_disconnect_adapter,
+                                   NULL);
 }
 
 
@@ -226,36 +265,37 @@
   char *fancy;
   struct StatMaster *sm;
 
-  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE))
+  if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE))
   {
-    del = GNUNET_TIME_absolute_get_duration (start_time);
-    if (del.rel_value == 0)
-      del.rel_value = 1;
-    fancy =
-        GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) *
-                                        1000LL / del.rel_value);
-    FPRINTF (stderr, "Download speed of type `%s' was %s/s\n", type, fancy);
-    GNUNET_free (fancy);
-    if (NUM_DAEMONS != ++download_counter)
-      return;                   /* more downloads to come */
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "Finished all downloads, shutting down\n",
-                (unsigned long long) FILESIZE);
-    sm = GNUNET_malloc (sizeof (struct StatMaster));
-    sm->stat =
-        GNUNET_STATISTICS_create ("<driver>",
-                                  GNUNET_FS_TEST_get_configuration (daemons,
-                                                                    
sm->daemon));
-    GNUNET_SCHEDULER_add_now (&stat_run, sm);
-  }
-  else
-  {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "Timeout during download for type `%s', shutting down with 
error\n",
                 type);
     ok = 1;
-    GNUNET_SCHEDULER_add_now (&do_stop, NULL);
+    GNUNET_SCHEDULER_shutdown ();
+    return;
   }
+  del = GNUNET_TIME_absolute_get_duration (start_time);
+  if (del.rel_value == 0)
+    del.rel_value = 1;
+  fancy =
+    GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) *
+                                   1000LL / del.rel_value);
+  FPRINTF (stderr, "Download speed of type `%s' was %s/s\n", type, fancy);
+  GNUNET_free (fancy);
+  if (NUM_DAEMONS != ++download_counter)
+    return;                   /* more downloads to come */
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+             "Finished all downloads, shutting down\n",
+             (unsigned long long) FILESIZE);
+  sm = GNUNET_malloc (sizeof (struct StatMaster));
+  sm->op =
+    GNUNET_TESTBED_service_connect (NULL,
+                                   daemons[sm->daemon],
+                                   "statistics",
+                                   &stat_run, sm,
+                                   &statistics_connect_adapter,
+                                   &statistics_disconnect_adapter,
+                                   NULL);
 }
 
 
@@ -267,7 +307,7 @@
 
   if (NULL == u2)
   {
-    GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, daemons);
+    GNUNET_SCHEDULER_shutdown ();
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "Timeout during upload attempt, shutting down with error\n");
     ok = 1;
@@ -298,14 +338,15 @@
 
 
 static void
-do_publish2 (void *cls, const struct GNUNET_FS_Uri *u1)
+do_publish2 (void *cls,             
+            const struct GNUNET_FS_Uri *u1)
 {
   int do_index;
   int anonymity;
 
   if (NULL == u1)
-  {
-    GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, daemons);
+    {
+    GNUNET_SCHEDULER_shutdown ();
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "Timeout during upload attempt, shutting down with error\n");
     ok = 1;
@@ -329,18 +370,23 @@
 }
 
 static void
-do_publish1 (void *cls, const char *emsg)
+do_publish1 (void *cls, 
+            struct GNUNET_TESTBED_Operation *op,
+            const char *emsg)
 {
+  unsigned int *coco = cls;
   int do_index;
   int anonymity;
 
   if (NULL != emsg)
   {
-    GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, daemons);
+    GNUNET_SCHEDULER_shutdown ();
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error trying to connect: %s\n", 
emsg);
     ok = 1;
     return;
   }
+  if (0 != (--(*coco)))
+    return; /* more connections to be created */
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Publishing %llu bytes\n",
               (unsigned long long) FILESIZE);
   if (NULL != strstr (progname, "index"))
@@ -351,7 +397,6 @@
     anonymity = 0;
   else
     anonymity = 1;
-
   GNUNET_FS_TEST_publish (daemons[NUM_DAEMONS - 1], TIMEOUT, anonymity,
                           do_index, FILESIZE, SEED1, VERBOSE, &do_publish2,
                           NULL);
@@ -359,52 +404,39 @@
 
 
 static void
-do_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+do_connect (void *cls, 
+           unsigned int num_peers,
+           struct GNUNET_TESTBED_Peer **peers)
 {
-  struct GNUNET_TESTING_PeerGroup *pg;
-
-  GNUNET_assert (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE));
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Daemons started, will now try to connect them\n");
-  pg = GNUNET_FS_TEST_get_group (daemons);
-  GNUNET_TESTING_create_topology (pg, GNUNET_TESTING_TOPOLOGY_CLIQUE,
-                                  GNUNET_TESTING_TOPOLOGY_NONE, NULL);
-  GNUNET_TESTING_connect_topology (pg, GNUNET_TESTING_TOPOLOGY_CLIQUE,
-                                   GNUNET_TESTING_TOPOLOGY_OPTION_NONE, 0.0,
-                                   TIMEOUT, NUM_DAEMONS, &do_publish1, NULL);
+  static unsigned int coco;
+  unsigned int i;
+  unsigned int j;
+ 
+  GNUNET_assert (NUM_DAEMONS == num_peers);
+  for (i=0;i<num_peers;i++)
+    daemons[i] = peers[i];
+  for (i=0;i<NUM_DAEMONS;i++)
+    for (j=i+1;j<NUM_DAEMONS;j++)
+      {
+       coco++;
+       GNUNET_TESTBED_overlay_connect (NULL,
+                                       &do_publish1,
+                                       &coco,
+                                       peers[i],
+                                       peers[j]);
+      }
 }
 
 
-static void
-run (void *cls, char *const *args, const char *cfgfile,
-     const struct GNUNET_CONFIGURATION_Handle *cfg)
-{
-  GNUNET_FS_TEST_daemons_start ("fs_test_lib_data.conf", TIMEOUT, NUM_DAEMONS,
-                                daemons, &do_connect, NULL);
-}
-
-
 int
 main (int argc, char *argv[])
 {
-  char *const argvx[] = {
-    "perf-gnunet-service-fs-p2p",
-    "-c",
-    "fs_test_lib_data.conf",
-    NULL
-  };
-  struct GNUNET_GETOPT_CommandLineOption options[] = {
-    GNUNET_GETOPT_OPTION_END
-  };
-  progname = argv[0];
+  GNUNET_TESTBED_test_run ("perf-gnunet-service-fs-p2p-respect",
+                          "perf_gnunet_service_fs_p2p.conf",
+                          NUM_DAEMONS,
+                          0, NULL, NULL,
+                          &do_connect, NULL);
   GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/");
-  GNUNET_log_setup ("perf_gnunet_service_fs_p2p_respect",
-                    "WARNING",
-                    NULL);
-  GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx,
-                      "perf-gnunet-service-fs-p2p-respect", "nohelp", options,
-                      &run, NULL);
-  GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/");
   return ok;
 }
 

Modified: gnunet/src/fs/test_fs_test_lib.c
===================================================================
--- gnunet/src/fs/test_fs_test_lib.c    2012-09-09 12:30:54 UTC (rev 23719)
+++ gnunet/src/fs/test_fs_test_lib.c    2012-09-09 13:28:48 UTC (rev 23720)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     (C) 2010 Christian Grothoff (and other contributing authors)
+     (C) 2010, 2012 Christian Grothoff (and other contributing authors)
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -42,20 +42,14 @@
 
 #define SEED 42
 
-static struct GNUNET_FS_TestDaemon *daemons[NUM_DAEMONS];
+static struct GNUNET_TESTBED_Peer *the_peers[NUM_DAEMONS];
 
-static struct GNUNET_FS_TEST_ConnectContext *cc;
-
 static int ret;
 
+
 static void
 do_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
-  if (NULL != cc)
-  {
-    GNUNET_FS_TEST_daemons_connect_cancel (cc);
-    cc = NULL;
-  }
   if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE))
   {
     GNUNET_break (0);
@@ -66,7 +60,7 @@
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Finished download, shutting down\n",
                 (unsigned long long) FILESIZE);
   }
-  GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, daemons);
+  GNUNET_SCHEDULER_shutdown ();
 }
 
 
@@ -76,80 +70,80 @@
   if (NULL == uri)
   {
     GNUNET_break (0);
-    GNUNET_SCHEDULER_add_now (&do_stop, NULL);
+    GNUNET_SCHEDULER_shutdown ();
     ret = 1;
     return;
   }
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Downloading %llu bytes\n",
               (unsigned long long) FILESIZE);
-  GNUNET_FS_TEST_download (daemons[0], TIMEOUT, 1, SEED, uri, VERBOSE, 
&do_stop,
+  GNUNET_FS_TEST_download (the_peers[0], TIMEOUT, 1, SEED, uri, VERBOSE, 
&do_stop,
                            NULL);
 }
 
 
 static void
-do_publish (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+do_publish (void *cls, 
+           struct GNUNET_TESTBED_Operation *op,
+           const char *emsg)
 {
-  cc = NULL;
-  if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE))
+  if (NULL != emsg)
   {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to connect peers: %s\n", 
emsg);
     GNUNET_break (0);
     ret = 1;
-    GNUNET_SCHEDULER_add_now (&do_stop, NULL);
+    GNUNET_SCHEDULER_shutdown ();
     return;
   }
+  GNUNET_TESTBED_operation_done (op);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Publishing %llu bytes\n",
               (unsigned long long) FILESIZE);
-  GNUNET_FS_TEST_publish (daemons[0], TIMEOUT, 1, GNUNET_NO, FILESIZE, SEED,
+  GNUNET_FS_TEST_publish (the_peers[0], TIMEOUT, 1, GNUNET_NO, FILESIZE, SEED,
                           VERBOSE, &do_download, NULL);
-}
 
-
-static void
-do_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
-  if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE))
-  {
-    GNUNET_break (0);
-    ret = 1;
-    GNUNET_SCHEDULER_add_now (&do_stop, NULL);
-    return;
-  }
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Daemons started, will now try to connect them\n");
-  cc = GNUNET_FS_TEST_daemons_connect (daemons[0], daemons[1], TIMEOUT,
-                                       &do_publish, NULL);
 }
 
 
+/**
+ * Actual main function for the test.
+ * 
+ * @param cls closure
+ * @param num_peers number of peers in 'peers'
+ * @param peers handle to peers run in the testbed
+ */
 static void
-run (void *cls, char *const *args, const char *cfgfile,
-     const struct GNUNET_CONFIGURATION_Handle *cfg)
+run (void *cls, 
+     unsigned int num_peers,
+     struct GNUNET_TESTBED_Peer **peers)
 {
-  GNUNET_FS_TEST_daemons_start ("fs_test_lib_data.conf", TIMEOUT, NUM_DAEMONS,
-                                daemons, &do_connect, NULL);
+  unsigned int i;
+ 
+  GNUNET_assert (NUM_DAEMONS == num_peers);
+  for (i=0;i<num_peers;i++)
+    the_peers[i] = peers[i];
+  GNUNET_TESTBED_overlay_connect (NULL,
+                                 &do_publish,
+                                 NULL,
+                                 peers[0],
+                                 peers[1]);
 }
 
 
+/**
+ * Main function that initializes the testbed.
+ *
+ * @param argc ignored 
+ * @param argv ignored
+ * @return 0 on success
+ */
 int
 main (int argc, char *argv[])
 {
-  char *const argvx[] = {
-    "test-fs-test-lib",
-    "-c",
-    "fs_test_lib_data.conf",
-    NULL
-  };
-  struct GNUNET_GETOPT_CommandLineOption options[] = {
-    GNUNET_GETOPT_OPTION_END
-  };
-
   GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/");
-  GNUNET_log_setup ("test_fs_test_lib",
-                    "WARNING",
-                    NULL);
-  GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx,
-                      "test-fs-test-lib", "nohelp", options, &run, NULL);
+  GNUNET_TESTBED_test_run ("test_fs_test_lib",
+                          "fs_test_lib_data.conf",
+                          NUM_DAEMONS, 
+                          0, NULL, NULL,
+                          &run, NULL);
   GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/");
   return ret;
 }

Modified: gnunet/src/fs/test_gnunet_service_fs_migration.c
===================================================================
--- gnunet/src/fs/test_gnunet_service_fs_migration.c    2012-09-09 12:30:54 UTC 
(rev 23719)
+++ gnunet/src/fs/test_gnunet_service_fs_migration.c    2012-09-09 13:28:48 UTC 
(rev 23720)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     (C) 2010 Christian Grothoff (and other contributing authors)
+     (C) 2010, 2012 Christian Grothoff (and other contributing authors)
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -25,7 +25,7 @@
  */
 #include "platform.h"
 #include "fs_test_lib.h"
-#include "gnunet_testing_lib.h"
+#include "gnunet_testbed_service.h"
 
 #define VERBOSE GNUNET_NO
 
@@ -46,13 +46,12 @@
 
 #define SEED 42
 
-static struct GNUNET_FS_TestDaemon *daemons[2];
+static struct GNUNET_TESTBED_Peer *daemons[2];
 
 static int ok;
 
 static struct GNUNET_TIME_Absolute start_time;
 
-static struct GNUNET_FS_TEST_ConnectContext *cc;
 
 static void
 do_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
@@ -60,12 +59,7 @@
   struct GNUNET_TIME_Relative del;
   char *fancy;
 
-  if (NULL != cc)
-  {
-    GNUNET_FS_TEST_daemons_connect_cancel (cc);
-    cc = NULL;
-  }
-  GNUNET_FS_TEST_daemons_stop (2, daemons);
+  GNUNET_SCHEDULER_shutdown ();
   if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT))
   {
     del = GNUNET_TIME_absolute_get_duration (start_time);
@@ -89,13 +83,14 @@
 
 
 static void
-do_download (void *cls, const char *emsg)
+do_download (void *cls, 
+            const char *emsg)
 {
   struct GNUNET_FS_Uri *uri = cls;
 
-  if (emsg != NULL)
+  if (NULL != emsg)
   {
-    GNUNET_FS_TEST_daemons_stop (2, daemons);
+    GNUNET_SCHEDULER_shutdown ();
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to stop source daemon: %s\n",
                 emsg);
     GNUNET_FS_uri_destroy (uri);
@@ -115,11 +110,9 @@
 stop_source_peer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   struct GNUNET_FS_Uri *uri = cls;
-  struct GNUNET_TESTING_PeerGroup *pg;
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping source peer\n");
-  pg = GNUNET_FS_TEST_get_group (daemons);
-  GNUNET_TESTING_daemons_vary (pg, 1, GNUNET_NO, TIMEOUT, &do_download, uri);
+  GNUNET_TESTBED_peer_stop (daemons[1], &do_download, uri);
 }
 
 
@@ -130,7 +123,7 @@
 
   if (NULL == uri)
   {
-    GNUNET_FS_TEST_daemons_stop (2, daemons);
+    GNUNET_SCHEDULER_shutdown ();
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "Timeout during upload attempt, shutting down with error\n");
     ok = 1;
@@ -143,14 +136,16 @@
 
 
 static void
-do_publish (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+do_publish (void *cls, 
+           struct GNUNET_TESTBED_Operation *op,
+           const char *emsg)
 {
-  cc = NULL;
-  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT))
+  if (NULL != emsg)
   {
-    GNUNET_FS_TEST_daemons_stop (2, daemons);
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "Timeout during connect attempt, shutting down with error\n");
+    GNUNET_SCHEDULER_shutdown ();
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Error connecting peers: %s\n",
+               emsg);
     ok = 1;
     return;
   }
@@ -162,59 +157,33 @@
 
 
 static void
-do_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+do_connect (void *cls, 
+           unsigned int num_peers,
+           struct GNUNET_TESTBED_Peer **peers)
 {
-  if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE))
-  {
-    FPRINTF (stderr, "%s",  "Daemons failed to start!\n");
-    GNUNET_break (0);
-    ok = 1;
-    return;
-  }
+  unsigned int i;
+
+  GNUNET_assert (2 == num_peers);
+  for (i=0;i<num_peers;i++)
+    daemons[i] = peers[i];
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Daemons started, will now try to connect them\n");
-  cc = GNUNET_FS_TEST_daemons_connect (daemons[0], daemons[1], TIMEOUT,
-                                       &do_publish, NULL);
+  GNUNET_TESTBED_overlay_connect (NULL,
+                                 &do_publish, NULL,
+                                 daemons[0], daemons[1]);
 }
 
 
-static void
-run (void *cls, char *const *args, const char *cfgfile,
-     const struct GNUNET_CONFIGURATION_Handle *cfg)
-{
-  GNUNET_FS_TEST_daemons_start ("test_gnunet_service_fs_migration_data.conf",
-                                TIMEOUT, 2, daemons, &do_connect, NULL);
-}
-
-
 int
 main (int argc, char *argv[])
 {
-  char *const argvx[] = {
-    "test-gnunet-service-fs-migration",
-    "-c",
-    "fs_test_lib_data.conf",
-#if VERBOSE
-    "-L", "DEBUG",
-#endif
-    NULL
-  };
-  struct GNUNET_GETOPT_CommandLineOption options[] = {
-    GNUNET_GETOPT_OPTION_END
-  };
-
+  GNUNET_TESTBED_test_run ("test-gnunet-service-fs-migration",
+                          "fs_test_lib_data.conf",
+                          2,
+                          0, NULL, NULL,
+                          &do_connect,
+                          NULL);
   GNUNET_DISK_directory_remove ("/tmp/test-gnunet-service-fs-migration/");
-  GNUNET_log_setup ("test_gnunet_service_fs_migration",
-#if VERBOSE
-                    "DEBUG",
-#else
-                    "WARNING",
-#endif
-                    NULL);
-  GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx,
-                      "test-gnunet-service-fs-migration", "nohelp", options,
-                      &run, NULL);
-  GNUNET_DISK_directory_remove ("/tmp/test-gnunet-service-fs-migration/");
   return ok;
 }
 

Modified: gnunet/src/fs/test_gnunet_service_fs_p2p.c
===================================================================
--- gnunet/src/fs/test_gnunet_service_fs_p2p.c  2012-09-09 12:30:54 UTC (rev 
23719)
+++ gnunet/src/fs/test_gnunet_service_fs_p2p.c  2012-09-09 13:28:48 UTC (rev 
23720)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     (C) 2010 Christian Grothoff (and other contributing authors)
+     (C) 2010, 2012 Christian Grothoff (and other contributing authors)
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -42,13 +42,12 @@
 
 #define SEED 42
 
-static struct GNUNET_FS_TestDaemon *daemons[NUM_DAEMONS];
+static struct GNUNET_TESTBED_Peer *daemons[NUM_DAEMONS];
 
 static int ok;
 
 static struct GNUNET_TIME_Absolute start_time;
 
-static struct GNUNET_FS_TEST_ConnectContext *cc;
 
 static void
 do_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
@@ -56,12 +55,7 @@
   struct GNUNET_TIME_Relative del;
   char *fancy;
 
-  if (NULL != cc)
-  {
-    GNUNET_FS_TEST_daemons_connect_cancel (cc);
-    cc = NULL;
-  }
-  GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, daemons);
+  GNUNET_SCHEDULER_shutdown ();
   if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT))
   {
     del = GNUNET_TIME_absolute_get_duration (start_time);
@@ -89,7 +83,7 @@
 {
   if (NULL == uri)
   {
-    GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, daemons);
+    GNUNET_SCHEDULER_shutdown ();
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "Timeout during upload attempt, shutting down with error\n");
     ok = 1;
@@ -104,14 +98,16 @@
 
 
 static void
-do_publish (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+do_publish (void *cls,
+           struct GNUNET_TESTBED_Operation *op,
+           const char *emsg)
 {
-  cc = NULL;
-  if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE))
+  if (NULL != emsg)
   {
-    GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, daemons);
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "Timeout during connect attempt, shutting down with error\n");
+    GNUNET_SCHEDULER_shutdown ();
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Timeout during connect attempt, shutting down with error: 
%s\n",
+               emsg);
     ok = 1;
     return;
   }
@@ -123,53 +119,32 @@
 
 
 static void
-do_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+do_connect (void *cls,
+           unsigned int num_peers,
+           struct GNUNET_TESTBED_Peer **peers)
 {
-  GNUNET_assert (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE));
+  unsigned int i;
+ 
+  GNUNET_assert (NUM_DAEMONS == num_peers);
+  for (i=0;i<num_peers;i++)
+    daemons[i] = peers[i];
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Daemons started, will now try to connect them\n");
-  cc = GNUNET_FS_TEST_daemons_connect (daemons[0], daemons[1], TIMEOUT,
-                                       &do_publish, NULL);
+  GNUNET_TESTBED_overlay_connect (NULL,
+                                 &do_publish, NULL,
+                                 daemons[0], daemons[1]);
 }
 
 
-static void
-run (void *cls, char *const *args, const char *cfgfile,
-     const struct GNUNET_CONFIGURATION_Handle *cfg)
-{
-  GNUNET_FS_TEST_daemons_start ("fs_test_lib_data.conf", TIMEOUT, NUM_DAEMONS,
-                                daemons, &do_connect, NULL);
-}
-
-
 int
 main (int argc, char *argv[])
 {
-  char *const argvx[] = {
-    "test-gnunet-service-fs-p2p",
-    "-c",
-    "fs_test_lib_data.conf",
-#if VERBOSE
-    "-L", "DEBUG",
-#endif
-    NULL
-  };
-  struct GNUNET_GETOPT_CommandLineOption options[] = {
-    GNUNET_GETOPT_OPTION_END
-  };
-
+  GNUNET_TESTBED_test_run ("test-gnunet-service-fs-p2p",
+                          "fs_test_lib_data.conf",
+                          NUM_DAEMONS,
+                          0, NULL, NULL,
+                          &do_connect, NULL);
   GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/");
-  GNUNET_log_setup ("test_gnunet_service_fs_p2p",
-#if VERBOSE
-                    "DEBUG",
-#else
-                    "WARNING",
-#endif
-                    NULL);
-  GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx,
-                      "test-gnunet-service-fs-p2p", "nohelp", options, &run,
-                      NULL);
-  GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/");
   return ok;
 }
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]