[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r11193 - gnunet/src/fs
From: |
gnunet |
Subject: |
[GNUnet-SVN] r11193 - gnunet/src/fs |
Date: |
Wed, 5 May 2010 14:19:54 +0200 |
Author: grothoff
Date: 2010-05-05 14:19:54 +0200 (Wed, 05 May 2010)
New Revision: 11193
Added:
gnunet/src/fs/test_fs_download_persistence.c
gnunet/src/fs/test_fs_publish_persistence.c
gnunet/src/fs/test_fs_search_persistence.c
gnunet/src/fs/test_fs_unindex_persistence.c
Removed:
gnunet/src/fs/test_fs_search_persistence.c
Modified:
gnunet/src/fs/Makefile.am
Log:
tests
Modified: gnunet/src/fs/Makefile.am
===================================================================
--- gnunet/src/fs/Makefile.am 2010-05-05 11:43:29 UTC (rev 11192)
+++ gnunet/src/fs/Makefile.am 2010-05-05 12:19:54 UTC (rev 11193)
@@ -119,15 +119,19 @@
test_fs_collection \
test_fs_directory \
test_fs_download \
+ test_fs_download_persistence \
test_fs_file_information \
test_fs_getopt \
test_fs_list_indexed \
test_fs_namespace \
test_fs_publish \
+ test_fs_publish_persistence \
test_fs_search \
+ test_fs_search_persistence \
test_fs_start_stop \
test_fs_test_lib \
test_fs_unindex \
+ test_fs_unindex_persistence \
test_fs_uri \
test_gnunet_service_fs_p2p
@@ -175,6 +179,13 @@
$(top_builddir)/src/arm/libgnunetarm.la \
$(top_builddir)/src/util/libgnunetutil.la
+test_fs_download_persistence_SOURCES = \
+ test_fs_download_persistence.c
+test_fs_download_persistence_LDADD = \
+ $(top_builddir)/src/fs/libgnunetfs.la \
+ $(top_builddir)/src/arm/libgnunetarm.la \
+ $(top_builddir)/src/util/libgnunetutil.la
+
test_fs_file_information_SOURCES = \
test_fs_file_information.c
test_fs_file_information_LDADD = \
@@ -208,12 +219,25 @@
$(top_builddir)/src/arm/libgnunetarm.la \
$(top_builddir)/src/util/libgnunetutil.la
+test_fs_publish_persistence_SOURCES = \
+ test_fs_publish_persistence.c
+test_fs_publish_persistence_LDADD = \
+ $(top_builddir)/src/fs/libgnunetfs.la \
+ $(top_builddir)/src/arm/libgnunetarm.la \
+ $(top_builddir)/src/util/libgnunetutil.la
+
test_fs_search_SOURCES = \
test_fs_search.c
test_fs_search_LDADD = $(top_builddir)/src/fs/libgnunetfs.la \
$(top_builddir)/src/arm/libgnunetarm.la \
$(top_builddir)/src/util/libgnunetutil.la
+test_fs_search_persistence_SOURCES = \
+ test_fs_search_persistence.c
+test_fs_search_persistence_LDADD = $(top_builddir)/src/fs/libgnunetfs.la
\
+ $(top_builddir)/src/arm/libgnunetarm.la \
+ $(top_builddir)/src/util/libgnunetutil.la
+
test_fs_start_stop_SOURCES = \
test_fs_start_stop.c
test_fs_start_stop_LDADD = \
@@ -228,6 +252,13 @@
$(top_builddir)/src/arm/libgnunetarm.la \
$(top_builddir)/src/util/libgnunetutil.la
+test_fs_unindex_persistence_SOURCES = \
+ test_fs_unindex_persistence.c
+test_fs_unindex_persistence_LDADD = \
+ $(top_builddir)/src/fs/libgnunetfs.la \
+ $(top_builddir)/src/arm/libgnunetarm.la \
+ $(top_builddir)/src/util/libgnunetutil.la
+
test_fs_uri_SOURCES = \
test_fs_uri.c
test_fs_uri_LDADD = \
Copied: gnunet/src/fs/test_fs_download_persistence.c (from rev 11189,
gnunet/src/fs/test_fs_download.c)
===================================================================
--- gnunet/src/fs/test_fs_download_persistence.c
(rev 0)
+++ gnunet/src/fs/test_fs_download_persistence.c 2010-05-05 12:19:54 UTC
(rev 11193)
@@ -0,0 +1,413 @@
+/*
+ This file is part of GNUnet.
+ (C) 2004, 2005, 2006, 2008, 2009, 2010 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
+ by the Free Software Foundation; either version 2, or (at your
+ option) any later version.
+
+ GNUnet is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ 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.
+*/
+
+/**
+ * @file fs/test_fs_download_persistence.c
+ * @brief simple testcase for persistence of simple download operation
+ * @author Christian Grothoff
+ */
+
+#include "platform.h"
+#include "gnunet_util_lib.h"
+#include "gnunet_arm_service.h"
+#include "gnunet_fs_service.h"
+
+#define VERBOSE GNUNET_NO
+
+#define START_ARM GNUNET_YES
+
+/**
+ * File-size we use for testing.
+ */
+#define FILESIZE (1024 * 1024 * 2)
+
+/**
+ * How long until we give up on transmitting the message?
+ */
+#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
+
+/**
+ * How long should our test-content live?
+ */
+#define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)
+
+struct PeerContext
+{
+ struct GNUNET_CONFIGURATION_Handle *cfg;
+#if START_ARM
+ pid_t arm_pid;
+#endif
+};
+
+static struct PeerContext p1;
+
+static struct GNUNET_TIME_Absolute start;
+
+static struct GNUNET_SCHEDULER_Handle *sched;
+
+static const struct GNUNET_CONFIGURATION_Handle *cfg;
+
+static struct GNUNET_FS_Handle *fs;
+
+static struct GNUNET_FS_DownloadContext *download;
+
+static struct GNUNET_FS_PublishContext *publish;
+
+static GNUNET_SCHEDULER_TaskIdentifier timeout_kill;
+
+static char *fn;
+
+static int err;
+
+static void
+timeout_kill_task (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ if (download != NULL)
+ {
+ GNUNET_FS_download_stop (download, GNUNET_YES);
+ download = NULL;
+ }
+ else if (publish != NULL)
+ {
+ GNUNET_FS_publish_stop (publish);
+ publish = NULL;
+ }
+ timeout_kill = GNUNET_SCHEDULER_NO_TASK;
+ err = 1;
+}
+
+static void
+abort_publish_task (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ if (publish != NULL)
+ {
+ GNUNET_FS_publish_stop (publish);
+ publish = NULL;
+ }
+}
+
+
+static void
+abort_download_task (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ uint64_t size;
+
+ if (download != NULL)
+ {
+ GNUNET_FS_download_stop (download, GNUNET_YES);
+ download = NULL;
+ }
+ GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_size (fn, &size, GNUNET_YES));
+ GNUNET_assert (size == FILESIZE);
+ GNUNET_DISK_directory_remove (fn);
+ GNUNET_free (fn);
+ fn = NULL;
+ GNUNET_SCHEDULER_cancel (sched, timeout_kill);
+ timeout_kill = GNUNET_SCHEDULER_NO_TASK;
+}
+
+
+static void *
+progress_cb (void *cls,
+ const struct GNUNET_FS_ProgressInfo *event);
+
+
+static void
+restart_fs_task (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ GNUNET_FS_stop (fs);
+ fs = GNUNET_FS_start (sched,
+ cfg,
+ "test-fs-download-persistence",
+ &progress_cb,
+ NULL,
+ GNUNET_FS_FLAGS_PERSISTENCE,
+ GNUNET_FS_OPTIONS_END);
+}
+
+
+/**
+ * Consider scheduling the restart-task.
+ * Only runs the restart task once per event
+ * category.
+ *
+ * @param ev type of the event to consider
+ */
+static void
+consider_restart (int ev)
+{
+ static int prev[32];
+ static int off;
+ int i;
+ for (i=0;i<off;i++)
+ if (prev[i] == ev)
+ return;
+ prev[off++] = ev;
+ GNUNET_SCHEDULER_add_with_priority (sched,
+ GNUNET_SCHEDULER_PRIORITY_URGENT,
+ &restart_fs_task,
+ NULL);
+}
+
+
+static void *
+progress_cb (void *cls,
+ const struct GNUNET_FS_ProgressInfo *event)
+{
+
+ switch (event->status)
+ {
+ case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
+#if VERBOSE
+ printf ("Publish is progressing (%llu/%llu at level %u off %llu)...\n",
+ (unsigned long long) event->value.publish.completed,
+ (unsigned long long) event->value.publish.size,
+ event->value.publish.specifics.progress.depth,
+ (unsigned long long)
event->value.publish.specifics.progress.offset);
+#endif
+ break;
+ case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
+ printf ("Publishing complete, %llu kbps.\n",
+ (unsigned long long) (FILESIZE * 1000LL /
(1+GNUNET_TIME_absolute_get_duration (start).value) / 1024LL));
+ fn = GNUNET_DISK_mktemp ("gnunet-download-test-dst");
+ start = GNUNET_TIME_absolute_get ();
+ download = GNUNET_FS_download_start (fs,
+
event->value.publish.specifics.completed.chk_uri,
+ NULL,
+ fn, NULL,
+ 0,
+ FILESIZE,
+ 1,
+ GNUNET_FS_DOWNLOAD_OPTION_NONE,
+ "download",
+ NULL);
+ GNUNET_assert (download != NULL);
+ break;
+ case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED:
+ consider_restart (event->status);
+ printf ("Download complete, %llu kbps.\n",
+ (unsigned long long) (FILESIZE * 1000LL /
(1+GNUNET_TIME_absolute_get_duration (start).value) / 1024LL));
+ GNUNET_SCHEDULER_add_now (sched,
+ &abort_download_task,
+ NULL);
+ break;
+ case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS:
+ consider_restart (event->status);
+ GNUNET_assert (download == event->value.download.dc);
+#if VERBOSE
+ printf ("Download is progressing (%llu/%llu at level %u off %llu)...\n",
+ (unsigned long long) event->value.download.completed,
+ (unsigned long long) event->value.download.size,
+ event->value.download.specifics.progress.depth,
+ (unsigned long long)
event->value.download.specifics.progress.offset);
+#endif
+ break;
+ case GNUNET_FS_STATUS_PUBLISH_ERROR:
+ fprintf (stderr,
+ "Error publishing file: %s\n",
+ event->value.publish.specifics.error.message);
+ GNUNET_break (0);
+ GNUNET_SCHEDULER_add_continuation (sched,
+ &abort_publish_task,
+ NULL,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ break;
+ case GNUNET_FS_STATUS_DOWNLOAD_ERROR:
+ fprintf (stderr,
+ "Error downloading file: %s\n",
+ event->value.download.specifics.error.message);
+ GNUNET_SCHEDULER_add_now (sched,
+ &abort_download_task,
+ NULL);
+ break;
+ case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE:
+ consider_restart (event->status);
+ break;
+ case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE:
+ consider_restart (event->status);
+ break;
+ case GNUNET_FS_STATUS_PUBLISH_START:
+ GNUNET_assert (0 == strcmp ("publish-context",
event->value.publish.cctx));
+ GNUNET_assert (NULL == event->value.publish.pctx);
+ GNUNET_assert (FILESIZE == event->value.publish.size);
+ GNUNET_assert (0 == event->value.publish.completed);
+ GNUNET_assert (1 == event->value.publish.anonymity);
+ break;
+ case GNUNET_FS_STATUS_PUBLISH_STOPPED:
+ GNUNET_assert (publish == event->value.publish.sc);
+ GNUNET_assert (FILESIZE == event->value.publish.size);
+ GNUNET_assert (1 == event->value.publish.anonymity);
+ GNUNET_FS_stop (fs);
+ fs = NULL;
+ break;
+ case GNUNET_FS_STATUS_DOWNLOAD_START:
+ consider_restart (event->status);
+ GNUNET_assert (download == NULL);
+ GNUNET_assert (0 == strcmp ("download", event->value.download.cctx));
+ GNUNET_assert (NULL == event->value.download.pctx);
+ GNUNET_assert (NULL != event->value.download.uri);
+ GNUNET_assert (0 == strcmp (fn, event->value.download.filename));
+ GNUNET_assert (FILESIZE == event->value.download.size);
+ GNUNET_assert (0 == event->value.download.completed);
+ GNUNET_assert (1 == event->value.download.anonymity);
+ break;
+ case GNUNET_FS_STATUS_DOWNLOAD_STOPPED:
+ consider_restart (event->status);
+ GNUNET_assert (download == event->value.download.dc);
+ GNUNET_SCHEDULER_add_continuation (sched,
+ &abort_publish_task,
+ NULL,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ break;
+ default:
+ printf ("Unexpected event: %d\n",
+ event->status);
+ break;
+ }
+ return NULL;
+}
+
+
+static void
+setup_peer (struct PeerContext *p, const char *cfgname)
+{
+ p->cfg = GNUNET_CONFIGURATION_create ();
+#if START_ARM
+ p->arm_pid = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
+ "gnunet-service-arm",
+#if VERBOSE
+ "-L", "DEBUG",
+#endif
+ "-c", cfgname, NULL);
+#endif
+ GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
+}
+
+
+static void
+stop_arm (struct PeerContext *p)
+{
+#if START_ARM
+ if (0 != PLIBC_KILL (p->arm_pid, SIGTERM))
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
+ if (GNUNET_OS_process_wait(p->arm_pid) != GNUNET_OK)
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "ARM process %u stopped\n", p->arm_pid);
+#endif
+ GNUNET_CONFIGURATION_destroy (p->cfg);
+}
+
+
+static void
+run (void *cls,
+ struct GNUNET_SCHEDULER_Handle *s,
+ char *const *args,
+ const char *cfgfile,
+ const struct GNUNET_CONFIGURATION_Handle *c)
+{
+ const char *keywords[] = {
+ "down_foo",
+ "down_bar",
+ };
+ char *buf;
+ struct GNUNET_CONTAINER_MetaData *meta;
+ struct GNUNET_FS_Uri *kuri;
+ struct GNUNET_FS_FileInformation *fi;
+ size_t i;
+
+ sched = s;
+ cfg = c;
+ setup_peer (&p1, "test_fs_download_data.conf");
+ fs = GNUNET_FS_start (sched,
+ cfg,
+ "test-fs-download-persistence",
+ &progress_cb,
+ NULL,
+ GNUNET_FS_FLAGS_PERSISTENCE,
+ GNUNET_FS_OPTIONS_END);
+ GNUNET_assert (NULL != fs);
+ buf = GNUNET_malloc (FILESIZE);
+ for (i = 0; i < FILESIZE; i++)
+ buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
+ meta = GNUNET_CONTAINER_meta_data_create ();
+ kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords);
+ fi = GNUNET_FS_file_information_create_from_data (fs,
+ "publish-context",
+ FILESIZE,
+ buf,
+ kuri,
+ meta,
+ GNUNET_NO,
+ 1,
+ 42,
+
GNUNET_TIME_relative_to_absolute (LIFETIME));
+ GNUNET_FS_uri_destroy (kuri);
+ GNUNET_CONTAINER_meta_data_destroy (meta);
+ GNUNET_assert (NULL != fi);
+ timeout_kill = GNUNET_SCHEDULER_add_delayed (sched,
+ TIMEOUT,
+ &timeout_kill_task,
+ NULL);
+ start = GNUNET_TIME_absolute_get ();
+ publish = GNUNET_FS_publish_start (fs,
+ fi,
+ NULL, NULL, NULL,
+ GNUNET_FS_PUBLISH_OPTION_NONE);
+ GNUNET_assert (publish != NULL);
+}
+
+
+int
+main (int argc, char *argv[])
+{
+ char *const argvx[] = {
+ "test-fs-download-persistence",
+ "-c",
+ "test_fs_download_data.conf",
+#if VERBOSE
+ "-L", "DEBUG",
+#endif
+ NULL
+ };
+ struct GNUNET_GETOPT_CommandLineOption options[] = {
+ GNUNET_GETOPT_OPTION_END
+ };
+
+ GNUNET_log_setup ("test_fs_download_persistence",
+#if VERBOSE
+ "DEBUG",
+#else
+ "WARNING",
+#endif
+ NULL);
+ GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
+ argvx, "test-fs-download-persistence",
+ "nohelp", options, &run, NULL);
+ stop_arm (&p1);
+ GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-download/");
+ return err;
+}
+
+/* end of test_fs_download_persistence.c */
Copied: gnunet/src/fs/test_fs_publish_persistence.c (from rev 11189,
gnunet/src/fs/test_fs_publish.c)
===================================================================
--- gnunet/src/fs/test_fs_publish_persistence.c (rev 0)
+++ gnunet/src/fs/test_fs_publish_persistence.c 2010-05-05 12:19:54 UTC (rev
11193)
@@ -0,0 +1,394 @@
+/*
+ This file is part of GNUnet.
+ (C) 2004, 2005, 2006, 2008, 2009, 2010 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
+ by the Free Software Foundation; either version 2, or (at your
+ option) any later version.
+
+ GNUnet is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ 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.
+*/
+
+/**
+ * @file fs/test_fs_publish_persistence.c
+ * @brief simple testcase for persistence of simple publish operation
+ * @author Christian Grothoff
+ */
+
+#include "platform.h"
+#include "gnunet_util_lib.h"
+#include "gnunet_arm_service.h"
+#include "gnunet_fs_service.h"
+
+#define VERBOSE GNUNET_NO
+
+#define START_ARM GNUNET_YES
+
+/**
+ * File-size we use for testing.
+ */
+#define FILESIZE (1024 * 1024 * 2)
+
+/**
+ * How long until we give up on transmitting the message?
+ */
+#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
+
+/**
+ * How long should our test-content live?
+ */
+#define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)
+
+struct PeerContext
+{
+ struct GNUNET_CONFIGURATION_Handle *cfg;
+#if START_ARM
+ pid_t arm_pid;
+#endif
+};
+
+static struct PeerContext p1;
+
+static struct GNUNET_TIME_Absolute start;
+
+static struct GNUNET_SCHEDULER_Handle *sched;
+
+static struct GNUNET_FS_Handle *fs;
+
+static const struct GNUNET_CONFIGURATION_Handle *cfg;
+
+static struct GNUNET_FS_PublishContext *publish;
+
+static struct GNUNET_FS_PublishContext *publish;
+
+static char *fn1;
+
+static char *fn2;
+
+static int err;
+
+static void
+abort_publish_task (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ GNUNET_FS_publish_stop (publish);
+ publish = NULL;
+ GNUNET_DISK_directory_remove (fn1);
+ GNUNET_free (fn1);
+ fn1 = NULL;
+ GNUNET_DISK_directory_remove (fn2);
+ GNUNET_free (fn2);
+ fn2 = NULL;
+}
+
+
+static void *
+progress_cb (void *cls,
+ const struct GNUNET_FS_ProgressInfo *event);
+
+
+static void
+restart_fs_task (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ GNUNET_FS_stop (fs);
+ fs = GNUNET_FS_start (sched,
+ cfg,
+ "test-fs-publish-persistence",
+ &progress_cb,
+ NULL,
+ GNUNET_FS_FLAGS_PERSISTENCE,
+ GNUNET_FS_OPTIONS_END);
+}
+
+
+/**
+ * Consider scheduling the restart-task.
+ * Only runs the restart task once per event
+ * category.
+ *
+ * @param ev type of the event to consider
+ */
+static void
+consider_restart (int ev)
+{
+ static int prev[32];
+ static int off;
+ int i;
+ for (i=0;i<off;i++)
+ if (prev[i] == ev)
+ return;
+ prev[off++] = ev;
+ GNUNET_SCHEDULER_add_with_priority (sched,
+ GNUNET_SCHEDULER_PRIORITY_URGENT,
+ &restart_fs_task,
+ NULL);
+}
+
+
+static void *
+progress_cb (void *cls,
+ const struct GNUNET_FS_ProgressInfo *event)
+{
+ void *ret;
+
+ ret = NULL;
+ switch (event->status)
+ {
+ case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
+ consider_restart (event->status);
+ ret = event->value.publish.cctx;
+ printf ("Publish complete, %llu kbps.\n",
+ (unsigned long long) (FILESIZE * 1000 /
(1+GNUNET_TIME_absolute_get_duration (start).value) / 1024));
+ if (0 == strcmp ("list_indexed-context-dir",
+ event->value.publish.cctx))
+ GNUNET_SCHEDULER_add_continuation (sched,
+ &abort_publish_task,
+ NULL,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ break;
+ case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
+ consider_restart (event->status);
+ ret = event->value.publish.cctx;
+ GNUNET_assert (publish == event->value.publish.sc);
+#if VERBOSE
+ printf ("Publish is progressing (%llu/%llu at level %u off %llu)...\n",
+ (unsigned long long) event->value.publish.completed,
+ (unsigned long long) event->value.publish.size,
+ event->value.publish.specifics.progress.depth,
+ (unsigned long long)
event->value.publish.specifics.progress.offset);
+#endif
+ break;
+ case GNUNET_FS_STATUS_PUBLISH_ERROR:
+ ret = event->value.publish.cctx;
+ fprintf (stderr,
+ "Error publishing file: %s\n",
+ event->value.publish.specifics.error.message);
+ err = 1;
+ if (0 == strcmp ("list_indexed-context-dir",
+ event->value.publish.cctx))
+ GNUNET_SCHEDULER_add_continuation (sched,
+ &abort_publish_task,
+ NULL,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ break;
+ case GNUNET_FS_STATUS_PUBLISH_START:
+ consider_restart (event->status);
+ ret = event->value.publish.cctx;
+ if (0 == strcmp ("publish-context1",
+ event->value.publish.cctx))
+ {
+ GNUNET_assert (0 == strcmp ("publish-context-dir",
+ event->value.publish.pctx));
+ GNUNET_assert (FILESIZE == event->value.publish.size);
+ GNUNET_assert (0 == event->value.publish.completed);
+ GNUNET_assert (1 == event->value.publish.anonymity);
+ }
+ else if (0 == strcmp ("publish-context2",
+ event->value.publish.cctx))
+ {
+ GNUNET_assert (0 == strcmp ("publish-context-dir",
+ event->value.publish.pctx));
+ GNUNET_assert (FILESIZE == event->value.publish.size);
+ GNUNET_assert (0 == event->value.publish.completed);
+ GNUNET_assert (2 == event->value.publish.anonymity);
+ }
+ else if (0 == strcmp ("publish-context-dir",
+ event->value.publish.cctx))
+ {
+ GNUNET_assert (0 == event->value.publish.completed);
+ GNUNET_assert (3 == event->value.publish.anonymity);
+ }
+ else
+ GNUNET_assert (0);
+ break;
+ case GNUNET_FS_STATUS_PUBLISH_STOPPED:
+ consider_restart (event->status);
+ if (0 == strcmp ("list_indexed-context-dir",
+ event->value.publish.cctx))
+ {
+ GNUNET_assert (publish == event->value.publish.sc);
+ GNUNET_SCHEDULER_add_continuation (sched,
+ &abort_publish_task,
+ NULL,
+
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ }
+ break;
+ default:
+ printf ("Unexpected event: %d\n",
+ event->status);
+ break;
+ }
+ return ret;
+}
+
+
+static void
+setup_peer (struct PeerContext *p, const char *cfgname)
+{
+ p->cfg = GNUNET_CONFIGURATION_create ();
+#if START_ARM
+ p->arm_pid = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
+ "gnunet-service-arm",
+#if VERBOSE
+ "-L", "DEBUG",
+#endif
+ "-c", cfgname, NULL);
+#endif
+ GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
+}
+
+
+static void
+stop_arm (struct PeerContext *p)
+{
+#if START_ARM
+ if (0 != PLIBC_KILL (p->arm_pid, SIGTERM))
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
+ if (GNUNET_OS_process_wait(p->arm_pid) != GNUNET_OK)
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "ARM process %u stopped\n", p->arm_pid);
+#endif
+ GNUNET_CONFIGURATION_destroy (p->cfg);
+}
+
+
+static void
+run (void *cls,
+ struct GNUNET_SCHEDULER_Handle *s,
+ char *const *args,
+ const char *cfgfile,
+ const struct GNUNET_CONFIGURATION_Handle *c)
+{
+ const char *keywords[] = {
+ "down_foo",
+ "down_bar",
+ };
+ char *buf;
+ struct GNUNET_CONTAINER_MetaData *meta;
+ struct GNUNET_FS_Uri *kuri;
+ struct GNUNET_FS_FileInformation *fi1;
+ struct GNUNET_FS_FileInformation *fi2;
+ struct GNUNET_FS_FileInformation *fidir;
+ size_t i;
+
+ sched = s;
+ cfg = c;
+ setup_peer (&p1, "test_fs_publish_data.conf");
+ fs = GNUNET_FS_start (sched,
+ cfg,
+ "test-fs-publish-persistence",
+ &progress_cb,
+ NULL,
+ GNUNET_FS_FLAGS_PERSISTENCE,
+ GNUNET_FS_OPTIONS_END);
+ GNUNET_assert (NULL != fs);
+ fn1 = GNUNET_DISK_mktemp ("gnunet-publish-test-dst");
+ buf = GNUNET_malloc (FILESIZE);
+ for (i = 0; i < FILESIZE; i++)
+ buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
+ GNUNET_assert (FILESIZE ==
+ GNUNET_DISK_fn_write (fn1,
+ buf,
+ FILESIZE,
+ GNUNET_DISK_PERM_USER_READ |
GNUNET_DISK_PERM_USER_WRITE));
+ GNUNET_free (buf);
+
+ fn2 = GNUNET_DISK_mktemp ("gnunet-publish-test-dst");
+ buf = GNUNET_malloc (FILESIZE);
+ for (i = 0; i < FILESIZE; i++)
+ buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
+ GNUNET_assert (FILESIZE ==
+ GNUNET_DISK_fn_write (fn2,
+ buf,
+ FILESIZE,
+ GNUNET_DISK_PERM_USER_READ |
GNUNET_DISK_PERM_USER_WRITE));
+ GNUNET_free (buf);
+
+ meta = GNUNET_CONTAINER_meta_data_create ();
+ kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords);
+ fi1 = GNUNET_FS_file_information_create_from_file (fs,
+ "publish-context1",
+ fn1,
+ kuri,
+ meta,
+ GNUNET_YES,
+ 1,
+ 42,
+
GNUNET_TIME_relative_to_absolute (LIFETIME));
+ fi2 = GNUNET_FS_file_information_create_from_file (fs,
+ "publish-context2",
+ fn2,
+ kuri,
+ meta,
+ GNUNET_YES,
+ 2,
+ 42,
+
GNUNET_TIME_relative_to_absolute (LIFETIME));
+ fidir = GNUNET_FS_file_information_create_empty_directory (fs,
+
"publish-context-dir",
+ kuri,
+ meta,
+ 3,
+ 42,
+
GNUNET_TIME_relative_to_absolute (LIFETIME));
+ GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi1));
+ GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi2));
+ GNUNET_FS_uri_destroy (kuri);
+ GNUNET_CONTAINER_meta_data_destroy (meta);
+ GNUNET_assert (NULL != fidir);
+ start = GNUNET_TIME_absolute_get ();
+ publish = GNUNET_FS_publish_start (fs,
+ fidir,
+ NULL, NULL, NULL,
+ GNUNET_FS_PUBLISH_OPTION_NONE);
+ GNUNET_assert (publish != NULL);
+}
+
+
+int
+main (int argc, char *argv[])
+{
+ char *const argvx[] = {
+ "test-fs-publish-persistence",
+ "-c",
+ "test_fs_publish_data.conf",
+#if VERBOSE
+ "-L", "DEBUG",
+#endif
+ NULL
+ };
+ struct GNUNET_GETOPT_CommandLineOption options[] = {
+ GNUNET_GETOPT_OPTION_END
+ };
+
+ GNUNET_log_setup ("test_fs_publish_persistence",
+#if VERBOSE
+ "DEBUG",
+#else
+ "WARNING",
+#endif
+ NULL);
+ GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
+ argvx, "test-fs-publish",
+ "nohelp", options, &run, NULL);
+ stop_arm (&p1);
+ GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-publish/");
+ GNUNET_DISK_directory_remove (fn1);
+ GNUNET_free_non_null (fn1);
+ GNUNET_DISK_directory_remove (fn2);
+ GNUNET_free_non_null (fn2);
+ return err;
+}
+
+/* end of test_fs_publish_persistence.c */
Deleted: gnunet/src/fs/test_fs_search_persistence.c
===================================================================
--- gnunet/src/fs/test_fs_search_persistence.c 2010-05-05 11:43:29 UTC (rev
11192)
+++ gnunet/src/fs/test_fs_search_persistence.c 2010-05-05 12:19:54 UTC (rev
11193)
@@ -1,213 +0,0 @@
-/*
- This file is part of GNUnet.
- (C) 2004, 2005, 2006 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
- by the Free Software Foundation; either version 2, or (at your
- option) any later version.
-
- GNUnet is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- 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.
-*/
-
-/**
- * @file applications/fs/fsui/search_persistence_test.c
- * @brief testcase for fsui download persistence for search
- * @author Christian Grothoff
- */
-
-#include "platform.h"
-#include "gnunet_util.h"
-#include "gnunet_fsui_lib.h"
-
-#define DEBUG_VERBOSE GNUNET_NO
-
-#define UPLOAD_PREFIX "/tmp/gnunet-fsui-search_persistence_test"
-
-#define CHECK(a) if (!(a)) { ok = GNUNET_NO; GNUNET_GE_BREAK(ectx, 0); goto
FAILURE; }
-
-static struct GNUNET_GE_Context *ectx;
-
-static struct GNUNET_FSUI_Context *ctx;
-static struct GNUNET_FSUI_SearchList *search;
-static int have_error;
-
-static void *
-eventCallback (void *cls, const GNUNET_FSUI_Event * event)
-{
- switch (event->type)
- {
- case GNUNET_FSUI_search_suspended:
- search = NULL;
- break;
- case GNUNET_FSUI_search_resumed:
-#if DEBUG_VERBOSE
- printf ("Search resuming\n");
-#endif
- search = event->data.SearchResumed.sc.pos;
- break;
- case GNUNET_FSUI_search_result:
-#if DEBUG_VERBOSE
- printf ("Received search result\n");
-#endif
- break;
- case GNUNET_FSUI_upload_progress:
-#if DEBUG_VERBOSE
- printf ("Upload is progressing (%llu/%llu)...\n",
- event->data.UploadProgress.completed,
- event->data.UploadProgress.total);
-#endif
- break;
- case GNUNET_FSUI_upload_completed:
-#if DEBUG_VERBOSE
- printf ("Upload complete.\n");
-#endif
- break;
- case GNUNET_FSUI_unindex_progress:
-#if DEBUG_VERBOSE
- printf ("Unindex is progressing (%llu/%llu)...\n",
- event->data.UnindexProgress.completed,
- event->data.UnindexProgress.total);
-#endif
- break;
- case GNUNET_FSUI_unindex_completed:
-#if DEBUG_VERBOSE
- printf ("Unindex complete.\n");
-#endif
- break;
- case GNUNET_FSUI_unindex_error:
- case GNUNET_FSUI_upload_error:
- case GNUNET_FSUI_download_error:
- fprintf (stderr, "Received ERROR: %d\n", event->type);
- GNUNET_GE_BREAK (ectx, 0);
- break;
- case GNUNET_FSUI_download_aborted:
-#if DEBUG_VERBOSE
- printf ("Received download aborted event.\n");
-#endif
- break;
- case GNUNET_FSUI_unindex_suspended:
- case GNUNET_FSUI_upload_suspended:
-#if DEBUG_VERBOSE
- fprintf (stderr, "Received SUSPENDING: %d\n", event->type);
-#endif
- break;
- case GNUNET_FSUI_upload_started:
- case GNUNET_FSUI_upload_stopped:
- case GNUNET_FSUI_search_started:
- case GNUNET_FSUI_search_aborted:
- case GNUNET_FSUI_search_stopped:
- case GNUNET_FSUI_search_update:
- case GNUNET_FSUI_unindex_started:
- case GNUNET_FSUI_unindex_stopped:
- break;
- default:
- printf ("Unexpected event: %d\n", event->type);
- break;
- }
- return NULL;
-}
-
-#define FILESIZE (1024)
-
-#define START_DAEMON 1
-
-int
-main (int argc, char *argv[])
-{
-#if START_DAEMON
- pid_t daemon;
-#endif
- int ok;
- struct GNUNET_ECRS_URI *uri = NULL;
- char *keywords[] = {
- "down_foo",
- "down_bar",
- };
- char keyword[40];
- int prog;
- struct GNUNET_GC_Configuration *cfg;
- int suspendRestart = 0;
-
-
- ok = GNUNET_YES;
- cfg = GNUNET_GC_create ();
- if (-1 == GNUNET_GC_parse_configuration (cfg, "check.conf"))
- {
- GNUNET_GC_free (cfg);
- return -1;
- }
-#if START_DAEMON
- daemon = GNUNET_daemon_start (NULL, cfg, "peer.conf", GNUNET_NO);
- GNUNET_GE_ASSERT (NULL, daemon > 0);
- CHECK (GNUNET_OK ==
- GNUNET_wait_for_daemon_running (NULL, cfg,
- 30 * GNUNET_CRON_SECONDS));
- GNUNET_thread_sleep (5 * GNUNET_CRON_SECONDS); /* give apps time to
start */
- /* ACTUAL TEST CODE */
-#endif
- ctx = GNUNET_FSUI_start (NULL,
- cfg, "search_persistence_test", 32, GNUNET_YES,
- &eventCallback, NULL);
- CHECK (ctx != NULL);
- GNUNET_snprintf (keyword, 40, "+%s +%s", keywords[0], keywords[1]);
- uri = GNUNET_ECRS_keyword_string_to_uri (ectx, keyword);
- search = GNUNET_FSUI_search_start (ctx, 0, uri);
- CHECK (search != NULL);
- prog = 0;
- suspendRestart = 10;
- while (prog < 100)
- {
- prog++;
- GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
- if ((suspendRestart > 0)
- && (GNUNET_random_u32 (GNUNET_RANDOM_QUALITY_WEAK, 10) == 0))
- {
-#if 1
-#if DEBUG_VERBOSE
- printf ("Testing FSUI suspend-resume\n");
-#endif
- GNUNET_FSUI_stop (ctx); /* download possibly incomplete
- at this point, thus testing resume
*/
- CHECK (search == NULL);
- ctx = GNUNET_FSUI_start (NULL,
- cfg,
- "search_persistence_test", 32, GNUNET_YES,
- &eventCallback, NULL);
-#if DEBUG_VERBOSE
- printf ("Resumed...\n");
-#endif
-#endif
- suspendRestart--;
- }
- if (GNUNET_shutdown_test () == GNUNET_YES)
- break;
- }
- GNUNET_FSUI_search_abort (search);
- GNUNET_FSUI_search_stop (search);
- search = NULL;
- /* END OF TEST CODE */
-FAILURE:
- if (ctx != NULL)
- GNUNET_FSUI_stop (ctx);
- if (uri != NULL)
- GNUNET_ECRS_uri_destroy (uri);
-
-#if START_DAEMON
- GNUNET_GE_BREAK (NULL, GNUNET_OK == GNUNET_daemon_stop (NULL, daemon));
-#endif
- GNUNET_GC_free (cfg);
- if (have_error)
- ok = GNUNET_NO;
- return (ok == GNUNET_YES) ? 0 : 1;
-}
-
-/* end of search_persistence_test.c */
Copied: gnunet/src/fs/test_fs_search_persistence.c (from rev 11189,
gnunet/src/fs/test_fs_search.c)
===================================================================
--- gnunet/src/fs/test_fs_search_persistence.c (rev 0)
+++ gnunet/src/fs/test_fs_search_persistence.c 2010-05-05 12:19:54 UTC (rev
11193)
@@ -0,0 +1,356 @@
+/*
+ This file is part of GNUnet.
+ (C) 2004, 2005, 2006, 2008, 2009, 2010 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
+ by the Free Software Foundation; either version 2, or (at your
+ option) any later version.
+
+ GNUnet is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ 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.
+*/
+
+/**
+ * @file fs/test_fs_search_persistence.c
+ * @brief simple testcase for persistence of search operation
+ * @author Christian Grothoff
+ */
+
+#include "platform.h"
+#include "gnunet_util_lib.h"
+#include "gnunet_arm_service.h"
+#include "gnunet_fs_service.h"
+
+#define VERBOSE GNUNET_NO
+
+#define START_ARM GNUNET_YES
+
+/**
+ * File-size we use for testing.
+ */
+#define FILESIZE 1024
+
+/**
+ * How long until we give up on transmitting the message?
+ */
+#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
+
+/**
+ * How long should our test-content live?
+ */
+#define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)
+
+struct PeerContext
+{
+ struct GNUNET_CONFIGURATION_Handle *cfg;
+ struct GNUNET_PeerIdentity id;
+#if START_ARM
+ pid_t arm_pid;
+#endif
+};
+
+static struct PeerContext p1;
+
+static struct GNUNET_TIME_Absolute start;
+
+static struct GNUNET_SCHEDULER_Handle *sched;
+
+static struct GNUNET_FS_Handle *fs;
+
+static struct GNUNET_FS_SearchContext *search;
+
+static struct GNUNET_FS_PublishContext *publish;
+
+static const struct GNUNET_CONFIGURATION_Handle *cfg;
+
+static void
+abort_publish_task (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ GNUNET_FS_publish_stop (publish);
+ publish = NULL;
+}
+
+
+static void
+abort_search_task (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ if (search != NULL)
+ GNUNET_FS_search_stop (search);
+ search = NULL;
+}
+
+
+static void *
+progress_cb (void *cls,
+ const struct GNUNET_FS_ProgressInfo *event);
+
+
+static void
+restart_fs_task (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ GNUNET_FS_stop (fs);
+ fs = GNUNET_FS_start (sched,
+ cfg,
+ "test-fs-search-persistence",
+ &progress_cb,
+ NULL,
+ GNUNET_FS_FLAGS_PERSISTENCE,
+ GNUNET_FS_OPTIONS_END);
+}
+
+
+
+
+/**
+ * Consider scheduling the restart-task.
+ * Only runs the restart task once per event
+ * category.
+ *
+ * @param ev type of the event to consider
+ */
+static void
+consider_restart (int ev)
+{
+ static int prev[32];
+ static int off;
+ int i;
+ for (i=0;i<off;i++)
+ if (prev[i] == ev)
+ return;
+ prev[off++] = ev;
+ GNUNET_SCHEDULER_add_with_priority (sched,
+ GNUNET_SCHEDULER_PRIORITY_URGENT,
+ &restart_fs_task,
+ NULL);
+}
+
+
+static void *
+progress_cb (void *cls,
+ const struct GNUNET_FS_ProgressInfo *event)
+{
+ const char *keywords[] = {
+ "down_foo"
+ };
+ struct GNUNET_FS_Uri *kuri;
+
+ switch (event->status)
+ {
+ case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
+#if VERBOSE
+ printf ("Publish is progressing (%llu/%llu at level %u off %llu)...\n",
+ (unsigned long long) event->value.publish.completed,
+ (unsigned long long) event->value.publish.size,
+ event->value.publish.specifics.progress.depth,
+ (unsigned long long)
event->value.publish.specifics.progress.offset);
+#endif
+ break;
+ case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
+ kuri = GNUNET_FS_uri_ksk_create_from_args (1, keywords);
+ start = GNUNET_TIME_absolute_get ();
+ search = GNUNET_FS_search_start (fs,
+ kuri,
+ 1,
+ GNUNET_FS_SEARCH_OPTION_NONE,
+ "search");
+ GNUNET_FS_uri_destroy (kuri);
+ GNUNET_assert (search != NULL);
+ break;
+ case GNUNET_FS_STATUS_SEARCH_RESULT:
+ consider_restart (event->status);
+#if VERBOSE
+ printf ("Search complete.\n");
+#endif
+ GNUNET_SCHEDULER_add_continuation (sched,
+ &abort_search_task,
+ NULL,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ break;
+ case GNUNET_FS_STATUS_PUBLISH_ERROR:
+ fprintf (stderr,
+ "Error publishing file: %s\n",
+ event->value.publish.specifics.error.message);
+ GNUNET_break (0);
+ GNUNET_SCHEDULER_add_continuation (sched,
+ &abort_publish_task,
+ NULL,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ break;
+ case GNUNET_FS_STATUS_SEARCH_ERROR:
+ fprintf (stderr,
+ "Error searching file: %s\n",
+ event->value.search.specifics.error.message);
+ GNUNET_SCHEDULER_add_continuation (sched,
+ &abort_search_task,
+ NULL,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ break;
+ case GNUNET_FS_STATUS_PUBLISH_START:
+ GNUNET_assert (0 == strcmp ("publish-context",
event->value.publish.cctx));
+ GNUNET_assert (NULL == event->value.publish.pctx);
+ GNUNET_assert (FILESIZE == event->value.publish.size);
+ GNUNET_assert (0 == event->value.publish.completed);
+ GNUNET_assert (1 == event->value.publish.anonymity);
+ break;
+ case GNUNET_FS_STATUS_PUBLISH_STOPPED:
+ GNUNET_assert (publish == event->value.publish.sc);
+ GNUNET_assert (FILESIZE == event->value.publish.size);
+ GNUNET_assert (1 == event->value.publish.anonymity);
+ GNUNET_FS_stop (fs);
+ fs = NULL;
+ break;
+ case GNUNET_FS_STATUS_SEARCH_START:
+ consider_restart (event->status);
+ GNUNET_assert (search == NULL);
+ GNUNET_assert (0 == strcmp ("search", event->value.search.cctx));
+ GNUNET_assert (1 == event->value.search.anonymity);
+ break;
+ case GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED:
+ break;
+ case GNUNET_FS_STATUS_SEARCH_STOPPED:
+ consider_restart (event->status);
+ GNUNET_assert (search == event->value.search.sc);
+ GNUNET_SCHEDULER_add_continuation (sched,
+ &abort_publish_task,
+ NULL,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ break;
+ default:
+ fprintf (stderr,
+ "Unexpected event: %d\n",
+ event->status);
+ break;
+ }
+ return NULL;
+}
+
+
+static void
+setup_peer (struct PeerContext *p, const char *cfgname)
+{
+ p->cfg = GNUNET_CONFIGURATION_create ();
+#if START_ARM
+ p->arm_pid = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
+ "gnunet-service-arm",
+#if VERBOSE
+ "-L", "DEBUG",
+#endif
+ "-c", cfgname, NULL);
+#endif
+ GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
+}
+
+
+static void
+stop_arm (struct PeerContext *p)
+{
+#if START_ARM
+ if (0 != PLIBC_KILL (p->arm_pid, SIGTERM))
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
+ if (GNUNET_OS_process_wait(p->arm_pid) != GNUNET_OK)
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "ARM process %u stopped\n", p->arm_pid);
+#endif
+ GNUNET_CONFIGURATION_destroy (p->cfg);
+}
+
+
+static void
+run (void *cls,
+ struct GNUNET_SCHEDULER_Handle *s,
+ char *const *args,
+ const char *cfgfile,
+ const struct GNUNET_CONFIGURATION_Handle *c)
+{
+ const char *keywords[] = {
+ "down_foo",
+ "down_bar"
+ };
+ char *buf;
+ struct GNUNET_CONTAINER_MetaData *meta;
+ struct GNUNET_FS_Uri *kuri;
+ struct GNUNET_FS_FileInformation *fi;
+ size_t i;
+
+ sched = s;
+ cfg = c;
+ setup_peer (&p1, "test_fs_search_data.conf");
+ fs = GNUNET_FS_start (sched,
+ cfg,
+ "test-fs-search-persistence",
+ &progress_cb,
+ NULL,
+ GNUNET_FS_FLAGS_PERSISTENCE,
+ GNUNET_FS_OPTIONS_END);
+ GNUNET_assert (NULL != fs);
+ buf = GNUNET_malloc (FILESIZE);
+ for (i = 0; i < FILESIZE; i++)
+ buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
+ meta = GNUNET_CONTAINER_meta_data_create ();
+ kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords);
+ fi = GNUNET_FS_file_information_create_from_data (fs,
+ "publish-context",
+ FILESIZE,
+ buf,
+ kuri,
+ meta,
+ GNUNET_NO,
+ 1,
+ 42,
+
GNUNET_TIME_relative_to_absolute (LIFETIME));
+ GNUNET_FS_uri_destroy (kuri);
+ GNUNET_CONTAINER_meta_data_destroy (meta);
+ GNUNET_assert (NULL != fi);
+ start = GNUNET_TIME_absolute_get ();
+ publish = GNUNET_FS_publish_start (fs,
+ fi,
+ NULL, NULL, NULL,
+ GNUNET_FS_PUBLISH_OPTION_NONE);
+ GNUNET_assert (publish != NULL);
+}
+
+
+int
+main (int argc, char *argv[])
+{
+ char *const argvx[] = {
+ "test-fs-search-persistence",
+ "-c",
+ "test_fs_search_data.conf",
+#if VERBOSE
+ "-L", "DEBUG",
+#endif
+ NULL
+ };
+ struct GNUNET_GETOPT_CommandLineOption options[] = {
+ GNUNET_GETOPT_OPTION_END
+ };
+
+ GNUNET_log_setup ("test_fs_search_persistence",
+#if VERBOSE
+ "DEBUG",
+#else
+ "WARNING",
+#endif
+ NULL);
+ GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
+ argvx, "test-fs-search-persistencce",
+ "nohelp", options, &run, NULL);
+ stop_arm (&p1);
+ GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-search/");
+ return 0;
+}
+
+/* end of test_fs_search_persistence.c */
Copied: gnunet/src/fs/test_fs_unindex_persistence.c (from rev 11189,
gnunet/src/fs/test_fs_unindex.c)
===================================================================
--- gnunet/src/fs/test_fs_unindex_persistence.c (rev 0)
+++ gnunet/src/fs/test_fs_unindex_persistence.c 2010-05-05 12:19:54 UTC (rev
11193)
@@ -0,0 +1,366 @@
+/*
+ This file is part of GNUnet.
+ (C) 2004, 2005, 2006, 2008, 2009, 2010 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
+ by the Free Software Foundation; either version 2, or (at your
+ option) any later version.
+
+ GNUnet is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ 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.
+*/
+
+/**
+ * @file fs/test_fs_unindex_persistence.c
+ * @brief simple testcase for simple publish + unindex operation
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "gnunet_util_lib.h"
+#include "gnunet_arm_service.h"
+#include "gnunet_fs_service.h"
+
+#define VERBOSE GNUNET_NO
+
+#define START_ARM GNUNET_YES
+
+/**
+ * File-size we use for testing.
+ */
+#define FILESIZE (1024 * 1024 * 2)
+
+/**
+ * How long until we give up on transmitting the message?
+ */
+#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
+
+/**
+ * How long should our test-content live?
+ */
+#define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)
+
+struct PeerContext
+{
+ struct GNUNET_CONFIGURATION_Handle *cfg;
+#if START_ARM
+ pid_t arm_pid;
+#endif
+};
+
+static struct PeerContext p1;
+
+static struct GNUNET_TIME_Absolute start;
+
+static struct GNUNET_SCHEDULER_Handle *sched;
+
+static struct GNUNET_FS_Handle *fs;
+
+static struct GNUNET_FS_UnindexContext *unindex;
+
+static struct GNUNET_FS_PublishContext *publish;
+
+static char *fn;
+
+static const struct GNUNET_CONFIGURATION_Handle *cfg;
+
+static void
+abort_publish_task (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ GNUNET_FS_publish_stop (publish);
+ publish = NULL;
+}
+
+
+static void
+abort_unindex_task (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ GNUNET_FS_unindex_stop (unindex);
+ unindex = NULL;
+ GNUNET_DISK_directory_remove (fn);
+ GNUNET_free (fn);
+ fn = NULL;
+}
+
+
+static void *
+progress_cb (void *cls,
+ const struct GNUNET_FS_ProgressInfo *event);
+
+
+static void
+restart_fs_task (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ GNUNET_FS_stop (fs);
+ fs = GNUNET_FS_start (sched,
+ cfg,
+ "test-fs-unindex-persistence",
+ &progress_cb,
+ NULL,
+ GNUNET_FS_FLAGS_PERSISTENCE,
+ GNUNET_FS_OPTIONS_END);
+}
+
+
+/**
+ * Consider scheduling the restart-task.
+ * Only runs the restart task once per event
+ * category.
+ *
+ * @param ev type of the event to consider
+ */
+static void
+consider_restart (int ev)
+{
+ static int prev[32];
+ static int off;
+ int i;
+ for (i=0;i<off;i++)
+ if (prev[i] == ev)
+ return;
+ prev[off++] = ev;
+ GNUNET_SCHEDULER_add_with_priority (sched,
+ GNUNET_SCHEDULER_PRIORITY_URGENT,
+ &restart_fs_task,
+ NULL);
+}
+
+
+static void *
+progress_cb (void *cls,
+ const struct GNUNET_FS_ProgressInfo *event)
+{
+ switch (event->status)
+ {
+ case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
+#if VERBOSE
+ printf ("Publish is progressing (%llu/%llu at level %u off %llu)...\n",
+ (unsigned long long) event->value.publish.completed,
+ (unsigned long long) event->value.publish.size,
+ event->value.publish.specifics.progress.depth,
+ (unsigned long long)
event->value.publish.specifics.progress.offset);
+#endif
+ break;
+ case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
+ printf ("Publishing complete, %llu kbps.\n",
+ (unsigned long long) (FILESIZE * 1000 /
(1+GNUNET_TIME_absolute_get_duration (start).value) / 1024));
+ start = GNUNET_TIME_absolute_get ();
+ unindex = GNUNET_FS_unindex_start (fs,
+ fn,
+ "unindex");
+ GNUNET_assert (unindex != NULL);
+ break;
+ case GNUNET_FS_STATUS_UNINDEX_COMPLETED:
+ consider_restart (event->status);
+ printf ("Unindex complete, %llu kbps.\n",
+ (unsigned long long) (FILESIZE * 1000 /
(1+GNUNET_TIME_absolute_get_duration (start).value) / 1024));
+ GNUNET_SCHEDULER_add_continuation (sched,
+ &abort_unindex_task,
+ NULL,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ break;
+ case GNUNET_FS_STATUS_UNINDEX_PROGRESS:
+ consider_restart (event->status);
+ GNUNET_assert (unindex == event->value.unindex.uc);
+#if VERBOSE
+ printf ("Unindex is progressing (%llu/%llu at level %u off %llu)...\n",
+ (unsigned long long) event->value.unindex.completed,
+ (unsigned long long) event->value.unindex.size,
+ event->value.unindex.specifics.progress.depth,
+ (unsigned long long)
event->value.unindex.specifics.progress.offset);
+#endif
+ break;
+ case GNUNET_FS_STATUS_PUBLISH_ERROR:
+ fprintf (stderr,
+ "Error publishing file: %s\n",
+ event->value.publish.specifics.error.message);
+ GNUNET_break (0);
+ GNUNET_SCHEDULER_add_continuation (sched,
+ &abort_publish_task,
+ NULL,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ break;
+ case GNUNET_FS_STATUS_UNINDEX_ERROR:
+ fprintf (stderr,
+ "Error unindexing file: %s\n",
+ event->value.unindex.specifics.error.message);
+ GNUNET_SCHEDULER_add_continuation (sched,
+ &abort_unindex_task,
+ NULL,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ break;
+ case GNUNET_FS_STATUS_PUBLISH_START:
+ GNUNET_assert (0 == strcmp ("publish-context",
event->value.publish.cctx));
+ GNUNET_assert (NULL == event->value.publish.pctx);
+ GNUNET_assert (FILESIZE == event->value.publish.size);
+ GNUNET_assert (0 == event->value.publish.completed);
+ GNUNET_assert (1 == event->value.publish.anonymity);
+ break;
+ case GNUNET_FS_STATUS_PUBLISH_STOPPED:
+ GNUNET_assert (publish == event->value.publish.sc);
+ GNUNET_assert (FILESIZE == event->value.publish.size);
+ GNUNET_assert (1 == event->value.publish.anonymity);
+ GNUNET_FS_stop (fs);
+ fs = NULL;
+ break;
+ case GNUNET_FS_STATUS_UNINDEX_START:
+ consider_restart (event->status);
+ GNUNET_assert (unindex == NULL);
+ GNUNET_assert (0 == strcmp ("unindex", event->value.unindex.cctx));
+ GNUNET_assert (0 == strcmp (fn, event->value.unindex.filename));
+ GNUNET_assert (FILESIZE == event->value.unindex.size);
+ GNUNET_assert (0 == event->value.unindex.completed);
+ break;
+ case GNUNET_FS_STATUS_UNINDEX_STOPPED:
+ consider_restart (event->status);
+ GNUNET_assert (unindex == event->value.unindex.uc);
+ GNUNET_SCHEDULER_add_continuation (sched,
+ &abort_publish_task,
+ NULL,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ break;
+ default:
+ printf ("Unexpected event: %d\n",
+ event->status);
+ break;
+ }
+ return NULL;
+}
+
+
+static void
+setup_peer (struct PeerContext *p, const char *cfgname)
+{
+ p->cfg = GNUNET_CONFIGURATION_create ();
+#if START_ARM
+ p->arm_pid = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
+ "gnunet-service-arm",
+#if VERBOSE
+ "-L", "DEBUG",
+#endif
+ "-c", cfgname, NULL);
+#endif
+ GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
+}
+
+
+static void
+stop_arm (struct PeerContext *p)
+{
+#if START_ARM
+ if (0 != PLIBC_KILL (p->arm_pid, SIGTERM))
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
+ if (GNUNET_OS_process_wait(p->arm_pid) != GNUNET_OK)
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "ARM process %u stopped\n", p->arm_pid);
+#endif
+ GNUNET_CONFIGURATION_destroy (p->cfg);
+}
+
+
+static void
+run (void *cls,
+ struct GNUNET_SCHEDULER_Handle *s,
+ char *const *args,
+ const char *cfgfile,
+ const struct GNUNET_CONFIGURATION_Handle *c)
+{
+ const char *keywords[] = {
+ "down_foo",
+ "down_bar",
+ };
+ char *buf;
+ struct GNUNET_CONTAINER_MetaData *meta;
+ struct GNUNET_FS_Uri *kuri;
+ struct GNUNET_FS_FileInformation *fi;
+ size_t i;
+
+ sched = s;
+ cfg = c;
+ setup_peer (&p1, "test_fs_unindex_data.conf");
+ fn = GNUNET_DISK_mktemp ("gnunet-unindex-test-dst");
+ fs = GNUNET_FS_start (sched,
+ cfg,
+ "test-fs-unindex-persistence",
+ &progress_cb,
+ NULL,
+ GNUNET_FS_FLAGS_PERSISTENCE,
+ GNUNET_FS_OPTIONS_END);
+ GNUNET_assert (NULL != fs);
+ buf = GNUNET_malloc (FILESIZE);
+ for (i = 0; i < FILESIZE; i++)
+ buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
+ GNUNET_assert (FILESIZE ==
+ GNUNET_DISK_fn_write (fn,
+ buf,
+ FILESIZE,
+ GNUNET_DISK_PERM_USER_READ |
GNUNET_DISK_PERM_USER_WRITE));
+ GNUNET_free (buf);
+ meta = GNUNET_CONTAINER_meta_data_create ();
+ kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords);
+ fi = GNUNET_FS_file_information_create_from_file (fs,
+ "publish-context",
+ fn,
+ kuri,
+ meta,
+ GNUNET_YES,
+ 1,
+ 42,
+
GNUNET_TIME_relative_to_absolute (LIFETIME));
+ GNUNET_FS_uri_destroy (kuri);
+ GNUNET_CONTAINER_meta_data_destroy (meta);
+ GNUNET_assert (NULL != fi);
+ start = GNUNET_TIME_absolute_get ();
+ publish = GNUNET_FS_publish_start (fs,
+ fi,
+ NULL, NULL, NULL,
+ GNUNET_FS_PUBLISH_OPTION_NONE);
+ GNUNET_assert (publish != NULL);
+}
+
+
+int
+main (int argc, char *argv[])
+{
+ char *const argvx[] = {
+ "test-fs-unindex",
+ "-c",
+ "test_fs_unindex_data.conf",
+#if VERBOSE
+ "-L", "DEBUG",
+#endif
+ NULL
+ };
+ struct GNUNET_GETOPT_CommandLineOption options[] = {
+ GNUNET_GETOPT_OPTION_END
+ };
+
+ GNUNET_log_setup ("test_fs_unindex_persistence",
+#if VERBOSE
+ "DEBUG",
+#else
+ "WARNING",
+#endif
+ NULL);
+ GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
+ argvx, "test-fs-unindex",
+ "nohelp", options, &run, NULL);
+ stop_arm (&p1);
+ GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-unindex/");
+ GNUNET_DISK_directory_remove (fn);
+ GNUNET_free_non_null (fn);
+ return 0;
+}
+
+/* end of test_fs_unindex_persistence.c */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r11193 - gnunet/src/fs,
gnunet <=