aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/fs/Makefile.am29
-rw-r--r--src/fs/fs.h2
-rw-r--r--src/fs/fs_file_information.c6
-rw-r--r--src/fs/test_fs_file_information.c179
-rw-r--r--src/fs/test_fs_file_information_data.conf42
-rw-r--r--src/fs/test_fs_list_indexed.c322
-rw-r--r--src/fs/test_fs_list_indexed_data.conf42
-rw-r--r--src/fs/test_fs_publish.c310
-rw-r--r--src/fs/test_fs_publish_data.conf42
9 files changed, 969 insertions, 5 deletions
diff --git a/src/fs/Makefile.am b/src/fs/Makefile.am
index 59361b03e..42c78532a 100644
--- a/src/fs/Makefile.am
+++ b/src/fs/Makefile.am
@@ -106,8 +106,11 @@ check_PROGRAMS = \
106 test_fs_collection \ 106 test_fs_collection \
107 test_fs_directory \ 107 test_fs_directory \
108 test_fs_download \ 108 test_fs_download \
109 test_fs_file_information \
109 test_fs_getopt \ 110 test_fs_getopt \
111 test_fs_list_indexed \
110 test_fs_namespace \ 112 test_fs_namespace \
113 test_fs_publish \
111 test_fs_search \ 114 test_fs_search \
112 test_fs_start_stop \ 115 test_fs_start_stop \
113 test_fs_unindex \ 116 test_fs_unindex \
@@ -115,7 +118,8 @@ check_PROGRAMS = \
115 118
116TESTS = \ 119TESTS = \
117 test_fs_directory \ 120 test_fs_directory \
118 test_fs_download \ 121 test_fs_download \
122 test_fs_file_information \
119 test_fs_search \ 123 test_fs_search \
120 test_fs_start_stop \ 124 test_fs_start_stop \
121 test_fs_unindex \ 125 test_fs_unindex \
@@ -141,12 +145,25 @@ test_fs_download_LDADD = \
141 $(top_builddir)/src/arm/libgnunetarm.la \ 145 $(top_builddir)/src/arm/libgnunetarm.la \
142 $(top_builddir)/src/util/libgnunetutil.la 146 $(top_builddir)/src/util/libgnunetutil.la
143 147
148test_fs_file_information_SOURCES = \
149 test_fs_file_information.c
150test_fs_file_information_LDADD = \
151 $(top_builddir)/src/fs/libgnunetfs.la \
152 $(top_builddir)/src/util/libgnunetutil.la
153
144test_fs_getopt_SOURCES = \ 154test_fs_getopt_SOURCES = \
145 test_fs_getopt.c 155 test_fs_getopt.c
146test_fs_getopt_LDADD = \ 156test_fs_getopt_LDADD = \
147 $(top_builddir)/src/fs/libgnunetfs.la \ 157 $(top_builddir)/src/fs/libgnunetfs.la \
148 $(top_builddir)/src/util/libgnunetutil.la 158 $(top_builddir)/src/util/libgnunetutil.la
149 159
160test_fs_list_indexed_SOURCES = \
161 test_fs_list_indexed.c
162test_fs_list_indexed_LDADD = \
163 $(top_builddir)/src/fs/libgnunetfs.la \
164 $(top_builddir)/src/arm/libgnunetarm.la \
165 $(top_builddir)/src/util/libgnunetutil.la
166
150test_fs_namespace_SOURCES = \ 167test_fs_namespace_SOURCES = \
151 test_fs_namespace.c 168 test_fs_namespace.c
152test_fs_namespace_LDADD = \ 169test_fs_namespace_LDADD = \
@@ -154,6 +171,13 @@ test_fs_namespace_LDADD = \
154 $(top_builddir)/src/arm/libgnunetarm.la \ 171 $(top_builddir)/src/arm/libgnunetarm.la \
155 $(top_builddir)/src/util/libgnunetutil.la 172 $(top_builddir)/src/util/libgnunetutil.la
156 173
174test_fs_publish_SOURCES = \
175 test_fs_publish.c
176test_fs_publish_LDADD = \
177 $(top_builddir)/src/fs/libgnunetfs.la \
178 $(top_builddir)/src/arm/libgnunetarm.la \
179 $(top_builddir)/src/util/libgnunetutil.la
180
157test_fs_search_SOURCES = \ 181test_fs_search_SOURCES = \
158 test_fs_search.c 182 test_fs_search.c
159test_fs_search_LDADD = $(top_builddir)/src/fs/libgnunetfs.la \ 183test_fs_search_LDADD = $(top_builddir)/src/fs/libgnunetfs.la \
@@ -184,7 +208,10 @@ EXTRA_DIST = \
184 test_fs_data.conf \ 208 test_fs_data.conf \
185 test_fs_collection_data.conf \ 209 test_fs_collection_data.conf \
186 test_fs_download_data.conf \ 210 test_fs_download_data.conf \
211 test_fs_file_information_data.conf \
212 test_fs_list_indexed_data.conf \
187 test_fs_namespace_data.conf \ 213 test_fs_namespace_data.conf \
214 test_fs_publish_data.conf \
188 test_fs_search_data.conf \ 215 test_fs_search_data.conf \
189 test_fs_unindex_data.conf \ 216 test_fs_unindex_data.conf \
190 test_fs_uri_data.conf 217 test_fs_uri_data.conf
diff --git a/src/fs/fs.h b/src/fs/fs.h
index acfc8b1c6..ae2e67654 100644
--- a/src/fs/fs.h
+++ b/src/fs/fs.h
@@ -387,7 +387,7 @@ struct GNUNET_FS_FileInformation
387 struct { 387 struct {
388 388
389 /** 389 /**
390 * Name of the directory. 390 * Name of the directory. FIXME: currently never set!
391 */ 391 */
392 char *dirname; 392 char *dirname;
393 393
diff --git a/src/fs/fs_file_information.c b/src/fs/fs_file_information.c
index 330ddc2fc..0d9222966 100644
--- a/src/fs/fs_file_information.c
+++ b/src/fs/fs_file_information.c
@@ -631,8 +631,8 @@ GNUNET_FS_file_information_create_from_directory (void *client_info,
631 ksk = NULL; // FIXME... 631 ksk = NULL; // FIXME...
632 // FIXME: create meta! 632 // FIXME: create meta!
633 ret = GNUNET_FS_file_information_create_empty_directory (client_info, 633 ret = GNUNET_FS_file_information_create_empty_directory (client_info,
634 meta,
635 ksk, 634 ksk,
635 meta,
636 anonymity, 636 anonymity,
637 priority, 637 priority,
638 expirationTime); 638 expirationTime);
@@ -668,8 +668,8 @@ GNUNET_FS_file_information_create_from_directory (void *client_info,
668 */ 668 */
669struct GNUNET_FS_FileInformation * 669struct GNUNET_FS_FileInformation *
670GNUNET_FS_file_information_create_empty_directory (void *client_info, 670GNUNET_FS_file_information_create_empty_directory (void *client_info,
671 const struct GNUNET_CONTAINER_MetaData *meta,
672 const struct GNUNET_FS_Uri *keywords, 671 const struct GNUNET_FS_Uri *keywords,
672 const struct GNUNET_CONTAINER_MetaData *meta,
673 uint32_t anonymity, 673 uint32_t anonymity,
674 uint32_t priority, 674 uint32_t priority,
675 struct GNUNET_TIME_Absolute expirationTime) 675 struct GNUNET_TIME_Absolute expirationTime)
@@ -820,7 +820,7 @@ GNUNET_FS_file_information_destroy (struct GNUNET_FS_FileInformation *fi,
820 &fi->expirationTime, 820 &fi->expirationTime,
821 &fi->client_info); 821 &fi->client_info);
822 GNUNET_free_non_null (fi->data.dir.dir_data); 822 GNUNET_free_non_null (fi->data.dir.dir_data);
823 GNUNET_free (fi->data.dir.dirname); 823 GNUNET_free_non_null (fi->data.dir.dirname);
824 } 824 }
825 else 825 else
826 { 826 {
diff --git a/src/fs/test_fs_file_information.c b/src/fs/test_fs_file_information.c
new file mode 100644
index 000000000..36a0771a3
--- /dev/null
+++ b/src/fs/test_fs_file_information.c
@@ -0,0 +1,179 @@
1/*
2 This file is part of GNUnet.
3 (C) 2004, 2005, 2006, 2008, 2009 Christian Grothoff (and other contributing authors)
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/**
22 * @file fs/test_fs_file_information.c
23 * @brief simple testcase for file_information operations
24 * @author Christian Grothoff
25 *
26 * TODO:
27 * - test that metatdata, etc. are all correct (for example,
28 * there is a known bug with dirname never being set that is
29 * not detected!)
30 * - need to iterate over file-information structure
31 * - other API functions may not yet be tested (such as
32 * filedata-from-callback)
33 */
34
35#include "platform.h"
36#include "gnunet_util_lib.h"
37#include "gnunet_fs_service.h"
38
39#define VERBOSE GNUNET_NO
40
41/**
42 * File-size we use for testing.
43 */
44#define FILESIZE (1024 * 1024 * 2)
45
46/**
47 * How long should our test-content live?
48 */
49#define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)
50
51
52static int
53mycleaner(void *cls,
54 struct GNUNET_FS_FileInformation *fi,
55 uint64_t length,
56 struct GNUNET_CONTAINER_MetaData *meta,
57 struct GNUNET_FS_Uri **uri,
58 uint32_t *anonymity,
59 uint32_t *priority,
60 struct GNUNET_TIME_Absolute *expirationTime,
61 void **client_info)
62{
63 return GNUNET_OK;
64}
65
66
67static void
68run (void *cls,
69 struct GNUNET_SCHEDULER_Handle *s,
70 char *const *args,
71 const char *cfgfile,
72 const struct GNUNET_CONFIGURATION_Handle *cfg)
73{
74 const char *keywords[] = {
75 "down_foo",
76 "down_bar",
77 };
78 char *fn1;
79 char *fn2;
80 char *buf;
81 struct GNUNET_CONTAINER_MetaData *meta;
82 struct GNUNET_FS_Uri *kuri;
83 struct GNUNET_FS_FileInformation *fi1;
84 struct GNUNET_FS_FileInformation *fi2;
85 struct GNUNET_FS_FileInformation *fidir;
86 size_t i;
87
88 fn1 = GNUNET_DISK_mktemp ("gnunet-file_information-test-dst");
89 buf = GNUNET_malloc (FILESIZE);
90 for (i = 0; i < FILESIZE; i++)
91 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
92 GNUNET_assert (FILESIZE ==
93 GNUNET_DISK_fn_write (fn1,
94 buf,
95 FILESIZE,
96 GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE));
97 GNUNET_free (buf);
98
99 fn2 = GNUNET_DISK_mktemp ("gnunet-file_information-test-dst");
100 buf = GNUNET_malloc (FILESIZE);
101 for (i = 0; i < FILESIZE; i++)
102 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
103 GNUNET_assert (FILESIZE ==
104 GNUNET_DISK_fn_write (fn2,
105 buf,
106 FILESIZE,
107 GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE));
108 GNUNET_free (buf);
109
110 meta = GNUNET_CONTAINER_meta_data_create ();
111 kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords);
112 fi1 = GNUNET_FS_file_information_create_from_file ("file_information-context1",
113 fn1,
114 kuri,
115 meta,
116 GNUNET_YES,
117 1,
118 42,
119 GNUNET_TIME_relative_to_absolute (LIFETIME));
120 fi2 = GNUNET_FS_file_information_create_from_file ("file_information-context2",
121 fn2,
122 kuri,
123 meta,
124 GNUNET_YES,
125 1,
126 42,
127 GNUNET_TIME_relative_to_absolute (LIFETIME));
128 fidir = GNUNET_FS_file_information_create_empty_directory ("file_information-context-dir",
129 kuri,
130 meta,
131 1,
132 42,
133 GNUNET_TIME_relative_to_absolute (LIFETIME));
134 GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi1));
135 GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi2));
136 GNUNET_FS_uri_destroy (kuri);
137 GNUNET_CONTAINER_meta_data_destroy (meta);
138 GNUNET_assert (NULL != fidir);
139 /* FIXME: test more of API! */
140 GNUNET_FS_file_information_destroy (fidir,
141 &mycleaner,
142 NULL);
143 GNUNET_DISK_directory_remove (fn1);
144 GNUNET_DISK_directory_remove (fn2);
145 GNUNET_free_non_null (fn1);
146 GNUNET_free_non_null (fn2);
147}
148
149
150int
151main (int argc, char *argv[])
152{
153 char *const argvx[] = {
154 "test-fs-file_information",
155 "-c",
156 "test_fs_file_information_data.conf",
157#if VERBOSE
158 "-L", "DEBUG",
159#endif
160 NULL
161 };
162 struct GNUNET_GETOPT_CommandLineOption options[] = {
163 GNUNET_GETOPT_OPTION_END
164 };
165
166 GNUNET_log_setup ("test_fs_file_information",
167#if VERBOSE
168 "DEBUG",
169#else
170 "WARNING",
171#endif
172 NULL);
173 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
174 argvx, "test-fs-file_information",
175 "nohelp", options, &run, NULL);
176 return 0;
177}
178
179/* end of test_fs_file_information.c */
diff --git a/src/fs/test_fs_file_information_data.conf b/src/fs/test_fs_file_information_data.conf
new file mode 100644
index 000000000..5ca36d99f
--- /dev/null
+++ b/src/fs/test_fs_file_information_data.conf
@@ -0,0 +1,42 @@
1[PATHS]
2SERVICEHOME = /tmp/gnunet-test-fs-file-information/
3DEFAULTCONFIG = test_fs_file_information_data.conf
4
5[gnunetd]
6HOSTKEY = $SERVICEHOME/.hostkey
7
8[resolver]
9PORT = 42464
10HOSTNAME = localhost
11
12[transport]
13PORT = 42465
14PLUGINS =
15
16[arm]
17PORT = 42466
18HOSTNAME = localhost
19DEFAULTSERVICES = resolver datastore transport core fs
20
21[datastore]
22#DEBUG = YES
23
24[statistics]
25PORT = 42467
26HOSTNAME = localhost
27
28[peerinfo]
29PORT = 42469
30HOSTNAME = localhost
31
32[core]
33PORT = 42470
34HOSTNAME = localhost
35
36[fs]
37PORT = 42471
38HOSTNAME = localhost
39#DEBUG = YES
40
41[testing]
42WEAKRANDOM = YES
diff --git a/src/fs/test_fs_list_indexed.c b/src/fs/test_fs_list_indexed.c
new file mode 100644
index 000000000..1585e2117
--- /dev/null
+++ b/src/fs/test_fs_list_indexed.c
@@ -0,0 +1,322 @@
1/*
2 This file is part of GNUnet.
3 (C) 2004, 2005, 2006, 2008, 2009 Christian Grothoff (and other contributing authors)
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/**
22 * @file fs/test_fs_list_indexed.c
23 * @brief simple testcase for list_indexed operation (indexing, listing
24 * indexed)
25 * @author Christian Grothoff
26 *
27 * TODO:
28 * - actually call list_indexed API!
29 */
30
31#include "platform.h"
32#include "gnunet_util_lib.h"
33#include "gnunet_arm_service.h"
34#include "gnunet_fs_service.h"
35
36#define VERBOSE GNUNET_NO
37
38#define START_ARM GNUNET_YES
39
40/**
41 * File-size we use for testing.
42 */
43#define FILESIZE (1024 * 1024 * 2)
44
45/**
46 * How long until we give up on transmitting the message?
47 */
48#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15)
49
50/**
51 * How long should our test-content live?
52 */
53#define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)
54
55struct PeerContext
56{
57 struct GNUNET_CONFIGURATION_Handle *cfg;
58 struct GNUNET_PeerIdentity id;
59#if START_ARM
60 pid_t arm_pid;
61#endif
62};
63
64static struct PeerContext p1;
65
66static struct GNUNET_TIME_Absolute start;
67
68static struct GNUNET_SCHEDULER_Handle *sched;
69
70static struct GNUNET_FS_Handle *fs;
71
72static struct GNUNET_FS_PublishContext *publish;
73
74static char *fn1;
75
76static char *fn2;
77
78static int err;
79
80static void
81abort_publish_task (void *cls,
82 const struct GNUNET_SCHEDULER_TaskContext *tc)
83{
84 GNUNET_FS_publish_stop (publish);
85 publish = NULL;
86 GNUNET_DISK_directory_remove (fn1);
87 GNUNET_free (fn1);
88 fn1 = NULL;
89 GNUNET_DISK_directory_remove (fn2);
90 GNUNET_free (fn2);
91 fn2 = NULL;
92}
93
94
95static void
96list_indexed_task (void *cls,
97 const struct GNUNET_SCHEDULER_TaskContext *tc)
98{
99
100 GNUNET_SCHEDULER_add_continuation (sched,
101 GNUNET_NO,
102 &abort_publish_task,
103 NULL,
104 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
105}
106
107
108static void *
109progress_cb (void *cls,
110 const struct GNUNET_FS_ProgressInfo *event)
111{
112
113 switch (event->status)
114 {
115 case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
116 printf ("Publish complete, %llu kbps.\n",
117 (unsigned long long) (FILESIZE * 1000 / (1+GNUNET_TIME_absolute_get_duration (start).value) / 1024));
118 GNUNET_SCHEDULER_add_continuation (sched,
119 GNUNET_NO,
120 &list_indexed_task,
121 NULL,
122 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
123 break;
124 case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
125 GNUNET_assert (publish == event->value.publish.sc);
126#if VERBOSE
127 printf ("Publish is progressing (%llu/%llu at level %u off %llu)...\n",
128 (unsigned long long) event->value.publish.completed,
129 (unsigned long long) event->value.publish.size,
130 event->value.publish.specifics.progress.depth,
131 (unsigned long long) event->value.publish.specifics.progress.offset);
132#endif
133 break;
134 case GNUNET_FS_STATUS_PUBLISH_ERROR:
135 fprintf (stderr,
136 "Error publishing file: %s\n",
137 event->value.publish.specifics.error.message);
138 err = 1;
139 GNUNET_SCHEDULER_add_continuation (sched,
140 GNUNET_NO,
141 &abort_publish_task,
142 NULL,
143 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
144 break;
145 case GNUNET_FS_STATUS_PUBLISH_START:
146 GNUNET_assert (0 == strcmp ("publish-context", event->value.publish.cctx));
147 GNUNET_assert (NULL == event->value.publish.pctx);
148 GNUNET_assert (FILESIZE == event->value.publish.size);
149 GNUNET_assert (0 == event->value.publish.completed);
150 GNUNET_assert (1 == event->value.publish.anonymity);
151 break;
152 case GNUNET_FS_STATUS_PUBLISH_STOPPED:
153 GNUNET_assert (publish == event->value.publish.sc);
154 publish = NULL;
155 break;
156 default:
157 printf ("Unexpected event: %d\n",
158 event->status);
159 break;
160 }
161 return NULL;
162}
163
164
165static void
166setup_peer (struct PeerContext *p, const char *cfgname)
167{
168 p->cfg = GNUNET_CONFIGURATION_create ();
169#if START_ARM
170 p->arm_pid = GNUNET_OS_start_process ("gnunet-service-arm",
171 "gnunet-service-arm",
172#if VERBOSE
173 "-L", "DEBUG",
174#endif
175 "-c", cfgname, NULL);
176 sleep (1); /* allow ARM to start */
177#endif
178 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
179 GNUNET_ARM_start_services (p->cfg, sched, "core", NULL);
180}
181
182
183static void
184stop_arm (struct PeerContext *p)
185{
186#if START_ARM
187 if (0 != PLIBC_KILL (p->arm_pid, SIGTERM))
188 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
189 if (GNUNET_OS_process_wait(p->arm_pid) != GNUNET_OK)
190 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
191 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
192 "ARM process %u stopped\n", p->arm_pid);
193#endif
194 GNUNET_CONFIGURATION_destroy (p->cfg);
195}
196
197
198static void
199run (void *cls,
200 struct GNUNET_SCHEDULER_Handle *s,
201 char *const *args,
202 const char *cfgfile,
203 const struct GNUNET_CONFIGURATION_Handle *cfg)
204{
205 const char *keywords[] = {
206 "down_foo",
207 "down_bar",
208 };
209 char *buf;
210 struct GNUNET_CONTAINER_MetaData *meta;
211 struct GNUNET_FS_Uri *kuri;
212 struct GNUNET_FS_FileInformation *fi1;
213 struct GNUNET_FS_FileInformation *fi2;
214 struct GNUNET_FS_FileInformation *fidir;
215 size_t i;
216
217 sched = s;
218 setup_peer (&p1, "test_fs_list_indexed_data.conf");
219 fs = GNUNET_FS_start (sched,
220 cfg,
221 "test-fs-list_indexed",
222 &progress_cb,
223 NULL,
224 GNUNET_FS_FLAGS_NONE,
225 GNUNET_FS_OPTIONS_END);
226 GNUNET_assert (NULL != fs);
227 fn1 = GNUNET_DISK_mktemp ("gnunet-list_indexed-test-dst");
228 buf = GNUNET_malloc (FILESIZE);
229 for (i = 0; i < FILESIZE; i++)
230 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
231 GNUNET_assert (FILESIZE ==
232 GNUNET_DISK_fn_write (fn1,
233 buf,
234 FILESIZE,
235 GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE));
236 GNUNET_free (buf);
237
238 fn2 = GNUNET_DISK_mktemp ("gnunet-list_indexed-test-dst");
239 buf = GNUNET_malloc (FILESIZE);
240 for (i = 0; i < FILESIZE; i++)
241 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
242 GNUNET_assert (FILESIZE ==
243 GNUNET_DISK_fn_write (fn2,
244 buf,
245 FILESIZE,
246 GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE));
247 GNUNET_free (buf);
248
249 meta = GNUNET_CONTAINER_meta_data_create ();
250 kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords);
251 fi1 = GNUNET_FS_file_information_create_from_file ("list_indexed-context1",
252 fn1,
253 kuri,
254 meta,
255 GNUNET_YES,
256 1,
257 42,
258 GNUNET_TIME_relative_to_absolute (LIFETIME));
259 fi2 = GNUNET_FS_file_information_create_from_file ("list_indexed-context2",
260 fn2,
261 kuri,
262 meta,
263 GNUNET_YES,
264 1,
265 42,
266 GNUNET_TIME_relative_to_absolute (LIFETIME));
267 fidir = GNUNET_FS_file_information_create_empty_directory ("list_indexed-context-dir",
268 kuri,
269 meta,
270 1,
271 42,
272 GNUNET_TIME_relative_to_absolute (LIFETIME));
273 GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi1));
274 GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi2));
275 GNUNET_FS_uri_destroy (kuri);
276 GNUNET_CONTAINER_meta_data_destroy (meta);
277 GNUNET_assert (NULL != fidir);
278 start = GNUNET_TIME_absolute_get ();
279 publish = GNUNET_FS_publish_start (fs,
280 fidir,
281 NULL, NULL, NULL,
282 GNUNET_FS_PUBLISH_OPTION_NONE);
283 GNUNET_assert (publish != NULL);
284}
285
286
287int
288main (int argc, char *argv[])
289{
290 char *const argvx[] = {
291 "test-fs-list_indexed",
292 "-c",
293 "test_fs_list_indexed_data.conf",
294#if VERBOSE
295 "-L", "DEBUG",
296#endif
297 NULL
298 };
299 struct GNUNET_GETOPT_CommandLineOption options[] = {
300 GNUNET_GETOPT_OPTION_END
301 };
302
303 GNUNET_log_setup ("test_fs_list_indexed",
304#if VERBOSE
305 "DEBUG",
306#else
307 "WARNING",
308#endif
309 NULL);
310 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
311 argvx, "test-fs-list_indexed",
312 "nohelp", options, &run, NULL);
313 stop_arm (&p1);
314 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-list_indexed/");
315 GNUNET_DISK_directory_remove (fn1);
316 GNUNET_free_non_null (fn1);
317 GNUNET_DISK_directory_remove (fn2);
318 GNUNET_free_non_null (fn2);
319 return err;
320}
321
322/* end of test_fs_list_indexed.c */
diff --git a/src/fs/test_fs_list_indexed_data.conf b/src/fs/test_fs_list_indexed_data.conf
new file mode 100644
index 000000000..c2e76b5ae
--- /dev/null
+++ b/src/fs/test_fs_list_indexed_data.conf
@@ -0,0 +1,42 @@
1[PATHS]
2SERVICEHOME = /tmp/gnunet-test-fs-list-indexed/
3DEFAULTCONFIG = test_fs_list_indexed_data.conf
4
5[gnunetd]
6HOSTKEY = $SERVICEHOME/.hostkey
7
8[resolver]
9PORT = 42464
10HOSTNAME = localhost
11
12[transport]
13PORT = 42465
14PLUGINS =
15
16[arm]
17PORT = 42466
18HOSTNAME = localhost
19DEFAULTSERVICES = resolver datastore transport core fs
20
21[datastore]
22#DEBUG = YES
23
24[statistics]
25PORT = 42467
26HOSTNAME = localhost
27
28[peerinfo]
29PORT = 42469
30HOSTNAME = localhost
31
32[core]
33PORT = 42470
34HOSTNAME = localhost
35
36[fs]
37PORT = 42471
38HOSTNAME = localhost
39#DEBUG = YES
40
41[testing]
42WEAKRANDOM = YES
diff --git a/src/fs/test_fs_publish.c b/src/fs/test_fs_publish.c
new file mode 100644
index 000000000..0a312085d
--- /dev/null
+++ b/src/fs/test_fs_publish.c
@@ -0,0 +1,310 @@
1/*
2 This file is part of GNUnet.
3 (C) 2004, 2005, 2006, 2008, 2009 Christian Grothoff (and other contributing authors)
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/**
22 * @file fs/test_fs_publish.c
23 * @brief simple testcase for publish operation (indexing, listing
24 * indexed, directory structure)
25 * @author Christian Grothoff
26 */
27
28#include "platform.h"
29#include "gnunet_util_lib.h"
30#include "gnunet_arm_service.h"
31#include "gnunet_fs_service.h"
32
33#define VERBOSE GNUNET_NO
34
35#define START_ARM GNUNET_YES
36
37/**
38 * File-size we use for testing.
39 */
40#define FILESIZE (1024 * 1024 * 2)
41
42/**
43 * How long until we give up on transmitting the message?
44 */
45#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15)
46
47/**
48 * How long should our test-content live?
49 */
50#define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)
51
52struct PeerContext
53{
54 struct GNUNET_CONFIGURATION_Handle *cfg;
55 struct GNUNET_PeerIdentity id;
56#if START_ARM
57 pid_t arm_pid;
58#endif
59};
60
61static struct PeerContext p1;
62
63static struct GNUNET_TIME_Absolute start;
64
65static struct GNUNET_SCHEDULER_Handle *sched;
66
67static struct GNUNET_FS_Handle *fs;
68
69static struct GNUNET_FS_PublishContext *publish;
70
71static struct GNUNET_FS_PublishContext *publish;
72
73static char *fn1;
74
75static char *fn2;
76
77
78static void
79abort_publish_task (void *cls,
80 const struct GNUNET_SCHEDULER_TaskContext *tc)
81{
82 GNUNET_FS_publish_stop (publish);
83 publish = NULL;
84 GNUNET_DISK_directory_remove (fn1);
85 GNUNET_free (fn1);
86 fn1 = NULL;
87 GNUNET_DISK_directory_remove (fn2);
88 GNUNET_free (fn2);
89 fn2 = NULL;
90}
91
92
93static void *
94progress_cb (void *cls,
95 const struct GNUNET_FS_ProgressInfo *event)
96{
97
98 switch (event->status)
99 {
100 case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
101 printf ("Publish complete, %llu kbps.\n",
102 (unsigned long long) (FILESIZE * 1000 / (1+GNUNET_TIME_absolute_get_duration (start).value) / 1024));
103 GNUNET_SCHEDULER_add_continuation (sched,
104 GNUNET_NO,
105 &abort_publish_task,
106 NULL,
107 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
108 break;
109 case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
110 GNUNET_assert (publish == event->value.publish.sc);
111#if VERBOSE
112 printf ("Publish is progressing (%llu/%llu at level %u off %llu)...\n",
113 (unsigned long long) event->value.publish.completed,
114 (unsigned long long) event->value.publish.size,
115 event->value.publish.specifics.progress.depth,
116 (unsigned long long) event->value.publish.specifics.progress.offset);
117#endif
118 break;
119 case GNUNET_FS_STATUS_PUBLISH_ERROR:
120 fprintf (stderr,
121 "Error publishing file: %s\n",
122 event->value.publish.specifics.error.message);
123 GNUNET_SCHEDULER_add_continuation (sched,
124 GNUNET_NO,
125 &abort_publish_task,
126 NULL,
127 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
128 break;
129 case GNUNET_FS_STATUS_PUBLISH_START:
130 GNUNET_assert (0 == strcmp ("publish-context", event->value.publish.cctx));
131 GNUNET_assert (NULL == event->value.publish.pctx);
132 GNUNET_assert (FILESIZE == event->value.publish.size);
133 GNUNET_assert (0 == event->value.publish.completed);
134 GNUNET_assert (1 == event->value.publish.anonymity);
135 break;
136 case GNUNET_FS_STATUS_PUBLISH_STOPPED:
137 GNUNET_assert (publish == event->value.publish.sc);
138 GNUNET_SCHEDULER_add_continuation (sched,
139 GNUNET_NO,
140 &abort_publish_task,
141 NULL,
142 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
143 break;
144 default:
145 printf ("Unexpected event: %d\n",
146 event->status);
147 break;
148 }
149 return NULL;
150}
151
152
153static void
154setup_peer (struct PeerContext *p, const char *cfgname)
155{
156 p->cfg = GNUNET_CONFIGURATION_create ();
157#if START_ARM
158 p->arm_pid = GNUNET_OS_start_process ("gnunet-service-arm",
159 "gnunet-service-arm",
160#if VERBOSE
161 "-L", "DEBUG",
162#endif
163 "-c", cfgname, NULL);
164 sleep (1); /* allow ARM to start */
165#endif
166 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
167 GNUNET_ARM_start_services (p->cfg, sched, "core", NULL);
168}
169
170
171static void
172stop_arm (struct PeerContext *p)
173{
174#if START_ARM
175 if (0 != PLIBC_KILL (p->arm_pid, SIGTERM))
176 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
177 if (GNUNET_OS_process_wait(p->arm_pid) != GNUNET_OK)
178 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
179 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
180 "ARM process %u stopped\n", p->arm_pid);
181#endif
182 GNUNET_CONFIGURATION_destroy (p->cfg);
183}
184
185
186static void
187run (void *cls,
188 struct GNUNET_SCHEDULER_Handle *s,
189 char *const *args,
190 const char *cfgfile,
191 const struct GNUNET_CONFIGURATION_Handle *cfg)
192{
193 const char *keywords[] = {
194 "down_foo",
195 "down_bar",
196 };
197 char *buf;
198 struct GNUNET_CONTAINER_MetaData *meta;
199 struct GNUNET_FS_Uri *kuri;
200 struct GNUNET_FS_FileInformation *fi1;
201 struct GNUNET_FS_FileInformation *fi2;
202 struct GNUNET_FS_FileInformation *fidir;
203 size_t i;
204
205 sched = s;
206 setup_peer (&p1, "test_fs_publish_data.conf");
207 fs = GNUNET_FS_start (sched,
208 cfg,
209 "test-fs-publish",
210 &progress_cb,
211 NULL,
212 GNUNET_FS_FLAGS_NONE,
213 GNUNET_FS_OPTIONS_END);
214 GNUNET_assert (NULL != fs);
215 fn1 = GNUNET_DISK_mktemp ("gnunet-publish-test-dst");
216 buf = GNUNET_malloc (FILESIZE);
217 for (i = 0; i < FILESIZE; i++)
218 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
219 GNUNET_assert (FILESIZE ==
220 GNUNET_DISK_fn_write (fn1,
221 buf,
222 FILESIZE,
223 GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE));
224 GNUNET_free (buf);
225
226 fn2 = GNUNET_DISK_mktemp ("gnunet-publish-test-dst");
227 buf = GNUNET_malloc (FILESIZE);
228 for (i = 0; i < FILESIZE; i++)
229 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
230 GNUNET_assert (FILESIZE ==
231 GNUNET_DISK_fn_write (fn2,
232 buf,
233 FILESIZE,
234 GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE));
235 GNUNET_free (buf);
236
237 meta = GNUNET_CONTAINER_meta_data_create ();
238 kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords);
239 fi1 = GNUNET_FS_file_information_create_from_file ("publish-context1",
240 fn1,
241 kuri,
242 meta,
243 GNUNET_YES,
244 1,
245 42,
246 GNUNET_TIME_relative_to_absolute (LIFETIME));
247 fi2 = GNUNET_FS_file_information_create_from_file ("publish-context2",
248 fn2,
249 kuri,
250 meta,
251 GNUNET_YES,
252 1,
253 42,
254 GNUNET_TIME_relative_to_absolute (LIFETIME));
255 fidir = GNUNET_FS_file_information_create_empty_directory ("publish-context-dir",
256 kuri,
257 meta,
258 1,
259 42,
260 GNUNET_TIME_relative_to_absolute (LIFETIME));
261 GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi1));
262 GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi2));
263 GNUNET_FS_uri_destroy (kuri);
264 GNUNET_CONTAINER_meta_data_destroy (meta);
265 GNUNET_assert (NULL != fidir);
266 start = GNUNET_TIME_absolute_get ();
267 publish = GNUNET_FS_publish_start (fs,
268 fidir,
269 NULL, NULL, NULL,
270 GNUNET_FS_PUBLISH_OPTION_NONE);
271 GNUNET_assert (publish != NULL);
272}
273
274
275int
276main (int argc, char *argv[])
277{
278 char *const argvx[] = {
279 "test-fs-publish",
280 "-c",
281 "test_fs_publish_data.conf",
282#if VERBOSE
283 "-L", "DEBUG",
284#endif
285 NULL
286 };
287 struct GNUNET_GETOPT_CommandLineOption options[] = {
288 GNUNET_GETOPT_OPTION_END
289 };
290
291 GNUNET_log_setup ("test_fs_publish",
292#if VERBOSE
293 "DEBUG",
294#else
295 "WARNING",
296#endif
297 NULL);
298 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
299 argvx, "test-fs-publish",
300 "nohelp", options, &run, NULL);
301 stop_arm (&p1);
302 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-publish/");
303 GNUNET_DISK_directory_remove (fn1);
304 GNUNET_free_non_null (fn1);
305 GNUNET_DISK_directory_remove (fn2);
306 GNUNET_free_non_null (fn2);
307 return 0;
308}
309
310/* end of test_fs_publish.c */
diff --git a/src/fs/test_fs_publish_data.conf b/src/fs/test_fs_publish_data.conf
new file mode 100644
index 000000000..147c8bc78
--- /dev/null
+++ b/src/fs/test_fs_publish_data.conf
@@ -0,0 +1,42 @@
1[PATHS]
2SERVICEHOME = /tmp/gnunet-test-fs-publish/
3DEFAULTCONFIG = test_fs_publish_data.conf
4
5[gnunetd]
6HOSTKEY = $SERVICEHOME/.hostkey
7
8[resolver]
9PORT = 42464
10HOSTNAME = localhost
11
12[transport]
13PORT = 42465
14PLUGINS =
15
16[arm]
17PORT = 42466
18HOSTNAME = localhost
19DEFAULTSERVICES = resolver datastore transport core fs
20
21[datastore]
22#DEBUG = YES
23
24[statistics]
25PORT = 42467
26HOSTNAME = localhost
27
28[peerinfo]
29PORT = 42469
30HOSTNAME = localhost
31
32[core]
33PORT = 42470
34HOSTNAME = localhost
35
36[fs]
37PORT = 42471
38HOSTNAME = localhost
39#DEBUG = YES
40
41[testing]
42WEAKRANDOM = YES