+
INCLUDES = -I$(top_srcdir)/src/include
if MINGW
test_fs_directory \
test_fs_download \
test_fs_getopt \
+ test_fs_namespace \
test_fs_search \
+ test_fs_start_stop \
test_fs_uri
-TESTS = test_fs_directory test_fs_download test_fs_uri
-
+TESTS = \
+ test_fs_directory \
+ test_fs_download \
+ test_fs_search \
+ test_fs_start_stop \
+ test_fs_uri
# $(check_PROGRAMS)
test_fs_collection_SOURCES = \
$(top_builddir)/src/arm/libgnunetarm.la \
$(top_builddir)/src/util/libgnunetutil.la
+test_fs_namespace_SOURCES = \
+ test_fs_namespace.c
+test_fs_namespace_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 = \
+test_fs_search_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 = \
$(top_builddir)/src/fs/libgnunetfs.la \
$(top_builddir)/src/arm/libgnunetarm.la \
$(top_builddir)/src/util/libgnunetutil.la
$(top_builddir)/src/util/libgnunetutil.la
EXTRA_DIST = \
+ test_fs_data.conf \
test_fs_collection_data.conf \
test_fs_download_data.conf \
+ test_fs_namespace_data.conf \
+ test_fs_search_data.conf \
test_fs_uri_data.conf
#include "fs.h"
#include "fs_tree.h"
-#define DEBUG_DOWNLOAD GNUNET_YES
+#define DEBUG_DOWNLOAD GNUNET_NO
/**
* We're storing the IBLOCKS after the
int is_new;
/* check if new */
- if (! GNUNET_FS_uri_test_ksk (uri))
+ if (! GNUNET_FS_uri_test_chk (uri))
{
GNUNET_break_op (0);
return;
}
/* decrypt */
GNUNET_CRYPTO_hash_to_aes_key (&sc->requests[i].key, &skey, &iv);
- GNUNET_CRYPTO_aes_encrypt (&kb[1],
+ GNUNET_CRYPTO_aes_decrypt (&kb[1],
size - sizeof (struct KBlock),
&skey,
&iv,
#include "gnunet_util_lib.h"
#include "fs.h"
-#define DEBUG_FS GNUNET_YES
+#define DEBUG_FS GNUNET_NO
/**
--- /dev/null
+[PATHS]
+SERVICEHOME = /tmp/gnunet-test-fs/
+DEFAULTCONFIG = test_fs_data.conf
+
+[gnunetd]
+HOSTKEY = $SERVICEHOME/.hostkey
+
+[resolver]
+PORT = 42464
+HOSTNAME = localhost
+
+[transport]
+PORT = 42465
+PLUGINS =
+
+[arm]
+PORT = 42466
+HOSTNAME = localhost
+DEFAULTSERVICES = resolver datastore transport core fs
+
+[datastore]
+#DEBUG = YES
+
+[statistics]
+PORT = 42467
+HOSTNAME = localhost
+
+[peerinfo]
+PORT = 42469
+HOSTNAME = localhost
+
+[core]
+PORT = 42470
+HOSTNAME = localhost
+
+[fs]
+PORT = 42471
+HOSTNAME = localhost
+#DEBUG = YES
+
+[testing]
+WEAKRANDOM = YES
#include "gnunet_arm_service.h"
#include "gnunet_fs_service.h"
-#define VERBOSE GNUNET_YES
+#define VERBOSE GNUNET_NO
#define START_ARM GNUNET_YES
argvx, "test-fs-download",
"nohelp", options, &run, NULL);
stop_arm (&p1);
+ GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-download/");
return 0;
}
DEFAULTSERVICES = resolver datastore transport core fs
[datastore]
-DEBUG = YES
+#DEBUG = YES
[statistics]
PORT = 42467
[fs]
PORT = 42471
HOSTNAME = localhost
-DEBUG = YES
+#DEBUG = YES
[testing]
WEAKRANDOM = YES
--- /dev/null
+/*
+ This file is part of GNUnet.
+ (C) 2005, 2006, 2008, 2009 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_namespace.c
+ * @brief Test for fs_namespace.c
+ * @author Christian Grothoff
+ */
+
+#include "platform.h"
+#include "gnunet_util_lib.h"
+#include "gnunet_arm_service.h"
+#include "gnunet_fs_service.h"
+
+#define START_ARM GNUNET_YES
+
+static struct GNUNET_SCHEDULER_Handle *sched;
+
+static struct PeerContext p1;
+
+static struct GNUNET_FS_Handle *fs;
+
+
+struct PeerContext
+{
+ struct GNUNET_CONFIGURATION_Handle *cfg;
+ struct GNUNET_PeerIdentity id;
+#if START_ARM
+ pid_t arm_pid;
+#endif
+};
+
+
+static void *
+progress_cb (void *cls,
+ const struct GNUNET_FS_ProgressInfo *event)
+{
+ 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 ("gnunet-service-arm",
+ "gnunet-service-arm",
+#if VERBOSE
+ "-L", "DEBUG",
+#endif
+ "-c", cfgname, NULL);
+ sleep (1); /* allow ARM to start */
+#endif
+ GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
+ GNUNET_ARM_start_services (p->cfg, sched, "core", NULL);
+}
+
+
+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
+spcb (void *cls,
+ const char *name,
+ const GNUNET_HashCode * key)
+{
+}
+
+
+static void
+publish_cont (void *cls,
+ const struct GNUNET_FS_Uri *uri,
+ const char *emsg)
+{
+ struct GNUNET_FS_SearchContext *search;
+
+ GNUNET_assert (NULL == emsg);
+ fprintf (stderr, "Starting namespace search...\n");
+ search = GNUNET_FS_search_start (fs, uri, 1);
+}
+
+
+static void
+testNamespace ()
+{
+ struct GNUNET_FS_Namespace *ns;
+ struct GNUNET_FS_Uri *adv;
+ struct GNUNET_FS_Uri *rootUri;
+ struct GNUNET_CONTAINER_MetaData *meta;
+ struct GNUNET_TIME_Absolute expiration;
+
+ expiration = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES);
+ meta = GNUNET_CONTAINER_meta_data_create ();
+ adv = GNUNET_FS_uri_ksk_create ("testNamespace", NULL);
+ ns = GNUNET_FS_namespace_create (fs,
+ "testNamespace");
+ rootUri = GNUNET_FS_namespace_advertise (fs,
+ ns,
+ meta,
+ 1, 1,
+ expiration,
+ adv,
+ "root");
+ GNUNET_assert (NULL != rootUri);
+ GNUNET_FS_publish_sks (fs,
+ ns,
+ "this",
+ "next",
+ meta,
+ rootUri,
+ expiration,
+ 1, 1,
+ GNUNET_FS_PUBLISH_OPTION_NONE,
+ &publish_cont,
+ NULL);
+ GNUNET_CONTAINER_meta_data_destroy (meta);
+}
+
+#if 0
+ fprintf (stderr, "Completed namespace search...\n");
+ GNUNET_assert (GNUNET_OK == GNUNET_FS_namespace_delete (NULL, cfg, &pid));
+ GNUNET_assert (GNUNET_SYSERR == GNUNET_FS_namespace_delete (NULL, cfg, &pid));
+ GNUNET_FS_uri_destroy (rootURI);
+ GNUNET_FS_uri_destroy (advURI);
+ GNUNET_assert (match == 1);
+ return 0;
+}
+#endif
+
+
+static void
+run (void *cls,
+ struct GNUNET_SCHEDULER_Handle *s,
+ char *const *args,
+ const char *cfgfile,
+ const struct GNUNET_CONFIGURATION_Handle *cfg)
+{
+ sched = s;
+ setup_peer (&p1, "test_fs_download_data.conf");
+ fs = GNUNET_FS_start (sched,
+ cfg,
+ "test-fs-namespace",
+ &progress_cb,
+ NULL,
+ GNUNET_FS_FLAGS_NONE,
+ GNUNET_FS_OPTIONS_END);
+ testNamespace ();
+}
+
+
+int
+main (int argc, char *argv[])
+{
+ char *const argvx[] = {
+ "test-fs-namespace",
+ "-c",
+ "test_fs_namespace_data.conf",
+#if VERBOSE
+ "-L", "DEBUG",
+#endif
+ NULL
+ };
+ struct GNUNET_GETOPT_CommandLineOption options[] = {
+ GNUNET_GETOPT_OPTION_END
+ };
+
+ GNUNET_log_setup ("test_fs_namespace",
+#if VERBOSE
+ "DEBUG",
+#else
+ "WARNING",
+#endif
+ NULL);
+ GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
+ argvx, "test-fs-namespace",
+ "nohelp", options, &run, NULL);
+ stop_arm (&p1);
+ GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-namespace/");
+ return 0;
+}
+
+
+
+/* end of test_fs_namespace.c */
#include "gnunet_arm_service.h"
#include "gnunet_fs_service.h"
-#define VERBOSE GNUNET_YES
+#define VERBOSE GNUNET_NO
#define START_ARM GNUNET_YES
abort_search_task (void *cls,
const struct GNUNET_SCHEDULER_TaskContext *tc)
{
- GNUNET_FS_search_stop (search);
+ if (search != NULL)
+ GNUNET_FS_search_stop (search);
search = NULL;
}
GNUNET_assert (search != NULL);
break;
case GNUNET_FS_STATUS_SEARCH_RESULT:
+#if VERBOSE
printf ("Search complete.\n");
+#endif
GNUNET_SCHEDULER_add_continuation (sched,
GNUNET_NO,
&abort_search_task,
// 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:
GNUNET_assert (search == event->value.search.sc);
GNUNET_SCHEDULER_add_continuation (sched,
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
break;
default:
- printf ("Unexpected event: %d\n",
- event->status);
+ fprintf (stderr,
+ "Unexpected event: %d\n",
+ event->status);
break;
}
return NULL;
argvx, "test-fs-search",
"nohelp", options, &run, NULL);
stop_arm (&p1);
+ GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-search/");
return 0;
}
[PATHS]
-SERVICEHOME = /tmp/gnunet-test-fs-download/
+SERVICEHOME = /tmp/gnunet-test-fs-search/
DEFAULTCONFIG = test_fs_download_data.conf
[gnunetd]
/*
This file is part of GNUnet.
- (C) 2004, 2005, 2006 Christian Grothoff (and other contributing authors)
+ (C) 2004, 2005, 2006, 2009 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
*/
/**
- * @file applications/fs/fsui/fsui_start_stop_test.c
- * @brief testcase for fsui (start-stop only)
+ * @file fs/test_fs_start_stop.c
+ * @brief testcase for fs.c (start-stop only)
* @author Christian Grothoff
*/
#include "platform.h"
-#include "gnunet_util.h"
-#include "gnunet_fsui_lib.h"
+#include "gnunet_util_lib.h"
+#include "gnunet_arm_service.h"
+#include "gnunet_fs_service.h"
-#define CHECK(a) if (!(a)) { ok = GNUNET_NO; GNUNET_GE_BREAK(NULL, 0); goto FAILURE; }
+#define START_ARM GNUNET_YES
+static struct GNUNET_SCHEDULER_Handle *sched;
+
+static struct PeerContext p1;
+
+struct PeerContext
+{
+ struct GNUNET_CONFIGURATION_Handle *cfg;
+ struct GNUNET_PeerIdentity id;
+#if START_ARM
+ pid_t arm_pid;
+#endif
+};
-static struct GNUNET_FSUI_Context *ctx;
static void *
-eventCallback (void *cls, const GNUNET_FSUI_Event * event)
+progress_cb (void *cls,
+ const struct GNUNET_FS_ProgressInfo *event)
{
return NULL;
}
-#define START_DAEMON 1
-int
-main (int argc, char *argv[])
+static void
+setup_peer (struct PeerContext *p, const char *cfgname)
{
-#if START_DAEMON
- pid_t daemon;
+ p->cfg = GNUNET_CONFIGURATION_create ();
+#if START_ARM
+ p->arm_pid = GNUNET_OS_start_process ("gnunet-service-arm",
+ "gnunet-service-arm",
+#if VERBOSE
+ "-L", "DEBUG",
#endif
- int ok;
- struct GNUNET_GC_Configuration *cfg;
-
- 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,
- 60 * GNUNET_CRON_SECONDS));
+ "-c", cfgname, NULL);
+ sleep (1); /* allow ARM to start */
#endif
- ok = GNUNET_YES;
- GNUNET_thread_sleep (5 * GNUNET_CRON_SECONDS); /* give apps time to start */
-
- /* ACTUAL TEST CODE */
- ctx = GNUNET_FSUI_start (NULL, cfg, "fsui_start_stop_test", 32, GNUNET_YES, /* do resume! */
- &eventCallback, NULL);
- CHECK (ctx != NULL);
- GNUNET_FSUI_stop (ctx);
- ctx =
- GNUNET_FSUI_start (NULL, cfg, "fsui_start_stop_test", 32, GNUNET_YES,
- &eventCallback, NULL);
- CHECK (ctx != NULL);
-FAILURE:
- if (ctx != NULL)
- GNUNET_FSUI_stop (ctx);
-#if START_DAEMON
- GNUNET_GE_ASSERT (NULL, GNUNET_OK == GNUNET_daemon_stop (NULL, daemon));
+ GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
+ GNUNET_ARM_start_services (p->cfg, sched, "core", NULL);
+}
+
+
+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_GC_free (cfg);
+ GNUNET_CONFIGURATION_destroy (p->cfg);
+}
+
- return (ok == GNUNET_YES) ? 0 : 1;
+static void
+run (void *cls,
+ struct GNUNET_SCHEDULER_Handle *s,
+ char *const *args,
+ const char *cfgfile,
+ const struct GNUNET_CONFIGURATION_Handle *cfg)
+{
+ struct GNUNET_FS_Handle *fs;
+
+ sched = s;
+ setup_peer (&p1, "test_fs_data.conf");
+ fs = GNUNET_FS_start (sched,
+ cfg,
+ "test-fs-start-stop",
+ &progress_cb,
+ NULL,
+ GNUNET_FS_FLAGS_NONE,
+ GNUNET_FS_OPTIONS_END);
+ GNUNET_assert (NULL != fs);
+ GNUNET_FS_stop (fs);
+}
+
+
+int
+main (int argc, char *argv[])
+{
+ char *const argvx[] = {
+ "test-fs-start-stop",
+ "-c",
+ "test_fs_data.conf",
+#if VERBOSE
+ "-L", "DEBUG",
+#endif
+ NULL
+ };
+ struct GNUNET_GETOPT_CommandLineOption options[] = {
+ GNUNET_GETOPT_OPTION_END
+ };
+
+ GNUNET_log_setup ("test_fs_start_stop",
+#if VERBOSE
+ "DEBUG",
+#else
+ "WARNING",
+#endif
+ NULL);
+ GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
+ argvx, "test-fs-start-stop",
+ "nohelp", options, &run, NULL);
+ stop_arm (&p1);
+ GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs/");
+ return 0;
}
-/* end of fsui_start_stop_test.c */
+/* end of test_fs_start_stop.c */
+++ /dev/null
-/*
- This file is part of GNUnet.
- (C) 2005, 2006, 2008 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/ecrs/namespacetest.c
- * @brief Test for namespace.c
- * @author Christian Grothoff
- */
-
-#include "platform.h"
-#include "gnunet_util.h"
-#include "gnunet_ecrs_lib.h"
-#include "ecrs.h"
-
-#define ABORT() { fprintf(stderr, "Error at %s:%d\n", __FILE__, __LINE__); return 1; }
-#define CHECK(c) { do { if (!(c)) ABORT(); } while(0); }
-
-#define CHECKNAME "gnunet-namespace-test"
-
-static struct GNUNET_GC_Configuration *cfg;
-
-static int match;
-
-static int
-spcb (const GNUNET_ECRS_FileInfo * fi,
- const GNUNET_HashCode * key, int isRoot, void *closure)
-{
- struct GNUNET_ECRS_URI *want = closure;
-
- if (GNUNET_ECRS_uri_test_equal (want, fi->uri))
- match = 1;
- else
- fprintf (stderr,
- "Namespace search returned unexpected result: \nHAVE: %s\nWANT: %s...\n",
- GNUNET_ECRS_uri_to_string (fi->uri),
- GNUNET_ECRS_uri_to_string (want));
- return GNUNET_OK;
-}
-
-static int
-tt (void *unused)
-{
- if (match == 1)
- return GNUNET_SYSERR;
- return GNUNET_OK;
-}
-
-static int
-testNamespace ()
-{
- GNUNET_HashCode pid;
- struct GNUNET_ECRS_URI *adv;
- struct GNUNET_ECRS_URI *advURI;
- struct GNUNET_ECRS_URI *rootURI;
- struct GNUNET_MetaData *meta;
-
- meta = GNUNET_meta_data_create ();
- adv = GNUNET_ECRS_keyword_string_to_uri (NULL, "testNamespace");
- rootURI =
- GNUNET_ECRS_namespace_create (NULL,
- cfg,
- meta,
- 0, 0,
- GNUNET_get_time () +
- 15 * GNUNET_CRON_MINUTES, adv, "root");
- CHECK (NULL != rootURI);
- GNUNET_ECRS_uri_get_namespace_from_sks (rootURI, &pid);
- advURI = GNUNET_ECRS_namespace_add_content (NULL, cfg, &pid, 1, /* anonymity */
- 1000, /* priority */
- 5 * GNUNET_CRON_MINUTES +
- GNUNET_get_time (),
- "this", "next", rootURI, meta);
- CHECK (NULL != advURI);
- fprintf (stderr, "Starting namespace search...\n");
- CHECK (GNUNET_OK == GNUNET_ECRS_search (NULL,
- cfg,
- advURI, 1, &spcb, rootURI, &tt,
- NULL));
- fprintf (stderr, "Completed namespace search...\n");
- CHECK (GNUNET_OK == GNUNET_ECRS_namespace_delete (NULL, cfg, &pid));
- CHECK (GNUNET_SYSERR == GNUNET_ECRS_namespace_delete (NULL, cfg, &pid));
- GNUNET_meta_data_destroy (meta);
- GNUNET_ECRS_uri_destroy (rootURI);
- GNUNET_ECRS_uri_destroy (advURI);
- CHECK (match == 1);
- return 0;
-}
-
-int
-main (int argc, char *argv[])
-{
- pid_t daemon;
- int failureCount = 0;
-
- GNUNET_disable_entropy_gathering ();
- cfg = GNUNET_GC_create ();
- if (-1 == GNUNET_GC_parse_configuration (cfg, "check.conf"))
- {
- GNUNET_GC_free (cfg);
- return -1;
- }
- daemon = GNUNET_daemon_start (NULL, cfg, "peer.conf", GNUNET_NO);
- GNUNET_GE_ASSERT (NULL, daemon > 0);
- if (GNUNET_OK !=
- GNUNET_wait_for_daemon_running (NULL, cfg, 60 * GNUNET_CRON_SECONDS))
- {
- failureCount++;
- }
- else
- {
- GNUNET_thread_sleep (5 * GNUNET_CRON_SECONDS);
- failureCount += testNamespace ();
- }
- GNUNET_GE_ASSERT (NULL, GNUNET_OK == GNUNET_daemon_stop (NULL, daemon));
-
- return (failureCount == 0) ? 0 : 1;
-}
-
-/* end of namespacetest.c */