diff options
-rw-r--r-- | m4/libtool.m4 | 27 | ||||
-rw-r--r-- | m4/ltdl.m4 | 2 | ||||
-rw-r--r-- | src/fs/Makefile.am | 46 | ||||
-rw-r--r-- | src/fs/fs_collection.c | 704 | ||||
-rw-r--r-- | src/fs/fs_directory.c | 461 | ||||
-rw-r--r-- | src/fs/test_fs_collection.c | 103 | ||||
-rw-r--r-- | src/fs/test_fs_directory.c | 167 | ||||
-rw-r--r-- | src/fs/test_fs_uri.c | 170 | ||||
-rw-r--r-- | src/fs/test_fs_uri_data.conf | 9 |
9 files changed, 1585 insertions, 104 deletions
diff --git a/m4/libtool.m4 b/m4/libtool.m4 index 39ba996cb..1e7ea47c0 100644 --- a/m4/libtool.m4 +++ b/m4/libtool.m4 | |||
@@ -2485,6 +2485,18 @@ linux* | k*bsd*-gnu) | |||
2485 | dynamic_linker='GNU/Linux ld.so' | 2485 | dynamic_linker='GNU/Linux ld.so' |
2486 | ;; | 2486 | ;; |
2487 | 2487 | ||
2488 | netbsdelf*-gnu) | ||
2489 | version_type=linux | ||
2490 | need_lib_prefix=no | ||
2491 | need_version=no | ||
2492 | library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}' | ||
2493 | soname_spec='${libname}${release}${shared_ext}$major' | ||
2494 | shlibpath_var=LD_LIBRARY_PATH | ||
2495 | shlibpath_overrides_runpath=no | ||
2496 | hardcode_into_libs=yes | ||
2497 | dynamic_linker='NetBSD ld.elf_so' | ||
2498 | ;; | ||
2499 | |||
2488 | netbsd*) | 2500 | netbsd*) |
2489 | version_type=sunos | 2501 | version_type=sunos |
2490 | need_lib_prefix=no | 2502 | need_lib_prefix=no |
@@ -3076,7 +3088,7 @@ linux* | k*bsd*-gnu) | |||
3076 | lt_cv_deplibs_check_method=pass_all | 3088 | lt_cv_deplibs_check_method=pass_all |
3077 | ;; | 3089 | ;; |
3078 | 3090 | ||
3079 | netbsd*) | 3091 | netbsd* | netbsdelf*-gnu) |
3080 | if echo __ELF__ | $CC -E - | $GREP __ELF__ > /dev/null; then | 3092 | if echo __ELF__ | $CC -E - | $GREP __ELF__ > /dev/null; then |
3081 | lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so\.[[0-9]]+\.[[0-9]]+|_pic\.a)$' | 3093 | lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so\.[[0-9]]+\.[[0-9]]+|_pic\.a)$' |
3082 | else | 3094 | else |
@@ -3757,7 +3769,7 @@ m4_if([$1], [CXX], [ | |||
3757 | ;; | 3769 | ;; |
3758 | esac | 3770 | esac |
3759 | ;; | 3771 | ;; |
3760 | netbsd*) | 3772 | netbsd* | netbsdelf*-gnu) |
3761 | ;; | 3773 | ;; |
3762 | *qnx* | *nto*) | 3774 | *qnx* | *nto*) |
3763 | # QNX uses GNU C++, but need to define -shared option too, otherwise | 3775 | # QNX uses GNU C++, but need to define -shared option too, otherwise |
@@ -4182,6 +4194,9 @@ m4_if([$1], [CXX], [ | |||
4182 | cygwin* | mingw* | cegcc*) | 4194 | cygwin* | mingw* | cegcc*) |
4183 | _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[[BCDGRS]][[ ]]/s/.*[[ ]]\([[^ ]]*\)/\1 DATA/;/^.*[[ ]]__nm__/s/^.*[[ ]]__nm__\([[^ ]]*\)[[ ]][[^ ]]*/\1 DATA/;/^I[[ ]]/d;/^[[AITW]][[ ]]/s/.* //'\'' | sort | uniq > $export_symbols' | 4195 | _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[[BCDGRS]][[ ]]/s/.*[[ ]]\([[^ ]]*\)/\1 DATA/;/^.*[[ ]]__nm__/s/^.*[[ ]]__nm__\([[^ ]]*\)[[ ]][[^ ]]*/\1 DATA/;/^I[[ ]]/d;/^[[AITW]][[ ]]/s/.* //'\'' | sort | uniq > $export_symbols' |
4184 | ;; | 4196 | ;; |
4197 | linux* | k*bsd*-gnu) | ||
4198 | _LT_TAGVAR(link_all_deplibs, $1)=no | ||
4199 | ;; | ||
4185 | *) | 4200 | *) |
4186 | _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols' | 4201 | _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols' |
4187 | ;; | 4202 | ;; |
@@ -4246,6 +4261,9 @@ dnl Note also adjust exclude_expsyms for C++ above. | |||
4246 | openbsd*) | 4261 | openbsd*) |
4247 | with_gnu_ld=no | 4262 | with_gnu_ld=no |
4248 | ;; | 4263 | ;; |
4264 | linux* | k*bsd*-gnu) | ||
4265 | _LT_TAGVAR(link_all_deplibs, $1)=no | ||
4266 | ;; | ||
4249 | esac | 4267 | esac |
4250 | 4268 | ||
4251 | _LT_TAGVAR(ld_shlibs, $1)=yes | 4269 | _LT_TAGVAR(ld_shlibs, $1)=yes |
@@ -4428,7 +4446,7 @@ _LT_EOF | |||
4428 | fi | 4446 | fi |
4429 | ;; | 4447 | ;; |
4430 | 4448 | ||
4431 | netbsd*) | 4449 | netbsd* | netbsdelf*-gnu) |
4432 | if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then | 4450 | if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then |
4433 | _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable $libobjs $deplibs $linker_flags -o $lib' | 4451 | _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable $libobjs $deplibs $linker_flags -o $lib' |
4434 | wlarc= | 4452 | wlarc= |
@@ -4603,6 +4621,7 @@ _LT_EOF | |||
4603 | if test "$aix_use_runtimelinking" = yes; then | 4621 | if test "$aix_use_runtimelinking" = yes; then |
4604 | shared_flag="$shared_flag "'${wl}-G' | 4622 | shared_flag="$shared_flag "'${wl}-G' |
4605 | fi | 4623 | fi |
4624 | _LT_TAGVAR(link_all_deplibs, $1)=no | ||
4606 | else | 4625 | else |
4607 | # not using gcc | 4626 | # not using gcc |
4608 | if test "$host_cpu" = ia64; then | 4627 | if test "$host_cpu" = ia64; then |
@@ -4841,7 +4860,7 @@ _LT_EOF | |||
4841 | _LT_TAGVAR(link_all_deplibs, $1)=yes | 4860 | _LT_TAGVAR(link_all_deplibs, $1)=yes |
4842 | ;; | 4861 | ;; |
4843 | 4862 | ||
4844 | netbsd*) | 4863 | netbsd* | netbsdelf*-gnu) |
4845 | if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then | 4864 | if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then |
4846 | _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags' # a.out | 4865 | _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags' # a.out |
4847 | else | 4866 | else |
diff --git a/m4/ltdl.m4 b/m4/ltdl.m4 index f6be54a94..46535e2e1 100644 --- a/m4/ltdl.m4 +++ b/m4/ltdl.m4 | |||
@@ -487,7 +487,7 @@ AC_CACHE_CHECK([whether deplibs are loaded by dlopen], | |||
487 | # at 6.2 and later dlopen does load deplibs. | 487 | # at 6.2 and later dlopen does load deplibs. |
488 | lt_cv_sys_dlopen_deplibs=yes | 488 | lt_cv_sys_dlopen_deplibs=yes |
489 | ;; | 489 | ;; |
490 | netbsd*) | 490 | netbsd* | netbsdelf*-gnu) |
491 | lt_cv_sys_dlopen_deplibs=yes | 491 | lt_cv_sys_dlopen_deplibs=yes |
492 | ;; | 492 | ;; |
493 | openbsd*) | 493 | openbsd*) |
diff --git a/src/fs/Makefile.am b/src/fs/Makefile.am index 266baa836..99b631668 100644 --- a/src/fs/Makefile.am +++ b/src/fs/Makefile.am | |||
@@ -27,39 +27,53 @@ libgnunetfs_la_LDFLAGS = \ | |||
27 | -version-info 0:0:0 | 27 | -version-info 0:0:0 |
28 | 28 | ||
29 | 29 | ||
30 | #bin_PROGRAMS = \ | 30 | #bin_PROGRAMS = |
31 | # gnunet-directory \ | 31 | # gnunet-directory |
32 | # gnunet-download \ | 32 | # gnunet-download |
33 | # gnunet-pseudonym \ | 33 | # gnunet-pseudonym |
34 | # gnunet-search \ | 34 | # gnunet-search |
35 | # gnunet-share \ | 35 | # gnunet-share |
36 | # gnunet-unindex | 36 | # gnunet-unindex |
37 | 37 | ||
38 | #gnunet_directory_SOURCES = \ | 38 | #gnunet_directory_SOURCES = |
39 | # gnunet-directory.c | 39 | # gnunet-directory.c |
40 | #gnunet_directory_LDADD = \ | 40 | #gnunet_directory_LDADD = |
41 | # $(top_builddir)/src/fs/libgnunetfs.la \ | 41 | # $(top_builddir)/src/fs/libgnunetfs.la |
42 | # $(top_builddir)/src/util/libgnunetutil.la \ | 42 | # $(top_builddir)/src/util/libgnunetutil.la |
43 | # $(GN_LIBINTL) | 43 | # $(GN_LIBINTL) |
44 | 44 | ||
45 | 45 | ||
46 | check_PROGRAMS = \ | 46 | check_PROGRAMS = \ |
47 | test_fs_collection \ | ||
48 | test_fs_directory \ | ||
47 | test_fs_getopt \ | 49 | test_fs_getopt \ |
48 | test_fs_uri | 50 | test_fs_uri |
49 | 51 | ||
50 | TESTS = $(check_PROGRAMS) | 52 | TESTS = $(check_PROGRAMS) |
51 | 53 | ||
52 | test_fs_uri_SOURCES = \ | 54 | test_fs_collection_SOURCES = \ |
53 | test_fs_uri.c | 55 | test_fs_collection.c |
54 | test_fs_LDADD = \ | 56 | test_fs_collection_LDADD = \ |
57 | $(top_builddir)/src/fs/libgnunetfs.la \ | ||
58 | $(top_builddir)/src/util/libgnunetutil.la | ||
59 | |||
60 | test_fs_directory_SOURCES = \ | ||
61 | test_fs_directory.c | ||
62 | test_fs_directory_LDADD = \ | ||
55 | $(top_builddir)/src/fs/libgnunetfs.la \ | 63 | $(top_builddir)/src/fs/libgnunetfs.la \ |
56 | $(top_builddir)/src/util/libgnunetutil.la | 64 | $(top_builddir)/src/util/libgnunetutil.la |
57 | 65 | ||
58 | test_fs_getopt_SOURCES = \ | 66 | test_fs_getopt_SOURCES = \ |
59 | test_fs_getopt.c | 67 | test_fs_getopt.c |
60 | test_fs_LDADD = \ | 68 | test_fs_getopt_LDADD = \ |
69 | $(top_builddir)/src/fs/libgnunetfs.la \ | ||
70 | $(top_builddir)/src/util/libgnunetutil.la | ||
71 | |||
72 | test_fs_uri_SOURCES = \ | ||
73 | test_fs_uri.c | ||
74 | test_fs_uri_LDADD = \ | ||
61 | $(top_builddir)/src/fs/libgnunetfs.la \ | 75 | $(top_builddir)/src/fs/libgnunetfs.la \ |
62 | $(top_builddir)/src/util/libgnunetutil.la | 76 | $(top_builddir)/src/util/libgnunetutil.la |
63 | 77 | ||
64 | #EXTRA_DIST = \ | 78 | EXTRA_DIST = \ |
65 | # test_fs_data.conf | 79 | test_fs_uri_data.conf |
diff --git a/src/fs/fs_collection.c b/src/fs/fs_collection.c new file mode 100644 index 000000000..01c7e3298 --- /dev/null +++ b/src/fs/fs_collection.c | |||
@@ -0,0 +1,704 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2004, 2005, 2006, 2008 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/fs_collection.c | ||
23 | * @brief Helper functions for building a collection | ||
24 | * @author Christian Grothoff | ||
25 | * | ||
26 | * A collection is a special kind of namespace. A collection is the | ||
27 | * set of files provided by the same user, but unlike namespaces it is | ||
28 | * automatically managed by the GNUnet UI. A collection is a single | ||
29 | * directory in a namespace that is automatically updated each time | ||
30 | * the user updates or deletes a file. That is, once the user starts | ||
31 | * a collection the gnunet-tools will always keep the corresponding | ||
32 | * directory and namespace entries up-to-date. | ||
33 | * | ||
34 | * A good way of thinking about a collection is a lazy user's | ||
35 | * namespace. | ||
36 | */ | ||
37 | |||
38 | #include "platform.h" | ||
39 | #include "gnunet_directories.h" | ||
40 | #include "gnunet_fs_service.h" | ||
41 | |||
42 | |||
43 | /** | ||
44 | * Initialize collection. | ||
45 | * | ||
46 | * @param h handle to the file sharing subsystem | ||
47 | * @param namespace namespace to use for the collection | ||
48 | * @return GNUNET_OK on success, GNUNET_SYSERR if another | ||
49 | * namespace is already set for our collection | ||
50 | */ | ||
51 | int | ||
52 | GNUNET_FS_collection_start (struct GNUNET_FS_Handle *h, | ||
53 | struct GNUNET_FS_Namespace *namespace) | ||
54 | { | ||
55 | return GNUNET_SYSERR; | ||
56 | } | ||
57 | |||
58 | |||
59 | /** | ||
60 | * Stop collection. | ||
61 | * | ||
62 | * @param h handle to the file sharing subsystem | ||
63 | * @return GNUNET_OK on success, GNUNET_SYSERR if no collection is active | ||
64 | */ | ||
65 | int | ||
66 | GNUNET_FS_collection_stop (struct GNUNET_FS_Handle *h) | ||
67 | { | ||
68 | return GNUNET_SYSERR; | ||
69 | } | ||
70 | |||
71 | |||
72 | /** | ||
73 | * Are we using a collection? | ||
74 | * | ||
75 | * @param h handle to the file sharing subsystem | ||
76 | * @return NULL if there is no collection, | ||
77 | */ | ||
78 | struct GNUNET_FS_Namespace * | ||
79 | GNUNET_FS_collection_get(struct GNUNET_FS_Handle *h) | ||
80 | { | ||
81 | return NULL; | ||
82 | } | ||
83 | |||
84 | |||
85 | /** | ||
86 | * Publish an update of the current collection information to the | ||
87 | * network now. The function has no effect if the collection has not | ||
88 | * changed since the last publication. If we are currently not | ||
89 | * collecting, this function does nothing. | ||
90 | * | ||
91 | * @param h handle to the file sharing subsystem | ||
92 | */ | ||
93 | void GNUNET_FS_collection_publish (struct GNUNET_FS_Handle *h) | ||
94 | { | ||
95 | } | ||
96 | |||
97 | |||
98 | /** | ||
99 | * If we are currently building a collection, publish the given file | ||
100 | * information in that collection. If we are currently not | ||
101 | * collecting, this function does nothing. | ||
102 | * | ||
103 | * @param h handle to the file sharing subsystem | ||
104 | * @param uri uri to add to the collection | ||
105 | * @param meta metadata for the uri | ||
106 | */ | ||
107 | void GNUNET_FS_collection_add (const struct GNUNET_FS_Handle *h, | ||
108 | const struct GNUNET_FS_Uri *uri, | ||
109 | const struct GNUNET_CONTAINER_MetaData *meta) | ||
110 | { | ||
111 | } | ||
112 | |||
113 | |||
114 | #if 0 | ||
115 | |||
116 | /** | ||
117 | * Filename used to store collection information | ||
118 | */ | ||
119 | #define COLLECTION "collection" | ||
120 | |||
121 | #define COLLECTION_ROOT "root" | ||
122 | |||
123 | /** | ||
124 | * How long does a collection advertisement live? | ||
125 | */ | ||
126 | #define COLLECTION_ADV_LIFETIME (12 * GNUNET_CRON_MONTHS) | ||
127 | |||
128 | /** | ||
129 | * @brief information about a collection | ||
130 | */ | ||
131 | typedef struct CollectionData | ||
132 | { | ||
133 | |||
134 | /** | ||
135 | * What is the pseudonym ID for the publication? | ||
136 | */ | ||
137 | GNUNET_HashCode pid; | ||
138 | |||
139 | /** | ||
140 | * Anonymity level for the collection. (NBO) | ||
141 | */ | ||
142 | unsigned int anonymityLevel; | ||
143 | |||
144 | /** | ||
145 | * Priority of the collection (NBO). | ||
146 | */ | ||
147 | unsigned int priority; | ||
148 | |||
149 | /** | ||
150 | * Has this collection changed since the last publication? | ||
151 | */ | ||
152 | int changed; | ||
153 | |||
154 | /** | ||
155 | * Revision counter | ||
156 | */ | ||
157 | unsigned int revision; | ||
158 | |||
159 | } CollectionData; | ||
160 | |||
161 | |||
162 | typedef struct | ||
163 | { | ||
164 | |||
165 | CollectionData data; | ||
166 | |||
167 | /** | ||
168 | * Metadata describing the collection | ||
169 | */ | ||
170 | struct GNUNET_MetaData *meta; | ||
171 | |||
172 | /** | ||
173 | * Files in the collection. | ||
174 | */ | ||
175 | GNUNET_ECRS_FileInfo *files; | ||
176 | |||
177 | /** | ||
178 | * How many files are in files? | ||
179 | */ | ||
180 | unsigned int file_count; | ||
181 | |||
182 | |||
183 | } CollectionInfo; | ||
184 | |||
185 | static CollectionInfo *collectionData; | ||
186 | |||
187 | static struct GNUNET_Mutex *lock; | ||
188 | |||
189 | static struct GNUNET_GE_Context *ectx; | ||
190 | |||
191 | static struct GNUNET_GC_Configuration *cfg; | ||
192 | |||
193 | static char * | ||
194 | getCollectionFileName () | ||
195 | { | ||
196 | return GNUNET_get_home_filename (ectx, cfg, GNUNET_NO, COLLECTION, NULL); | ||
197 | } | ||
198 | |||
199 | /** | ||
200 | * Initialize collection module. | ||
201 | */ | ||
202 | void | ||
203 | GNUNET_CO_init (struct GNUNET_GE_Context *e, | ||
204 | struct GNUNET_GC_Configuration *c) | ||
205 | { | ||
206 | char *fn; | ||
207 | int len; | ||
208 | unsigned int mlen; | ||
209 | unsigned long long size; | ||
210 | char *buf; | ||
211 | int fd; | ||
212 | const char *pos; | ||
213 | size_t rsize; | ||
214 | unsigned int i; | ||
215 | char *tmp; | ||
216 | |||
217 | cfg = c; | ||
218 | ectx = e; | ||
219 | lock = GNUNET_mutex_create (GNUNET_YES); | ||
220 | fn = getCollectionFileName (); | ||
221 | if (!GNUNET_disk_file_test (ectx, fn)) | ||
222 | { | ||
223 | GNUNET_free (fn); | ||
224 | return; | ||
225 | } | ||
226 | /* read collection data */ | ||
227 | if (GNUNET_OK != GNUNET_disk_file_size (ectx, fn, &size, GNUNET_YES)) | ||
228 | { | ||
229 | GNUNET_free (fn); | ||
230 | return; | ||
231 | } | ||
232 | if ((size > 0x7FFFFFFF) || | ||
233 | (size < sizeof (CollectionData) + 2 * sizeof (int))) | ||
234 | { | ||
235 | GNUNET_GE_BREAK (ectx, 0); | ||
236 | UNLINK (fn); | ||
237 | GNUNET_free (fn); | ||
238 | return; | ||
239 | } | ||
240 | fd = OPEN (fn, O_RDONLY | O_LARGEFILE); | ||
241 | if (fd == -1) | ||
242 | { | ||
243 | GNUNET_GE_BREAK (ectx, 0); | ||
244 | UNLINK (fn); | ||
245 | GNUNET_free (fn); | ||
246 | return; | ||
247 | } | ||
248 | rsize = (size_t) size; | ||
249 | buf = MMAP (NULL, rsize, PROT_READ, MAP_SHARED, fd, 0); | ||
250 | if (buf == MAP_FAILED) | ||
251 | { | ||
252 | GNUNET_GE_LOG_STRERROR_FILE (ectx, | ||
253 | GNUNET_GE_ERROR | GNUNET_GE_ADMIN | | ||
254 | GNUNET_GE_USER | GNUNET_GE_BULK, "mmap", | ||
255 | fn); | ||
256 | CLOSE (fd); | ||
257 | GNUNET_free (fn); | ||
258 | return; | ||
259 | } | ||
260 | collectionData = GNUNET_malloc (sizeof (CollectionInfo)); | ||
261 | memset (collectionData, 0, sizeof (CollectionInfo)); | ||
262 | memcpy (&collectionData->data, buf, sizeof (CollectionData)); | ||
263 | pos = &buf[sizeof (CollectionData)]; | ||
264 | rsize -= sizeof (CollectionData); | ||
265 | len = ntohl (*(int *) pos); | ||
266 | if (len > 1024 * 1024 * 4) | ||
267 | goto ERR; | ||
268 | pos += sizeof (int); | ||
269 | mlen = ntohl (*(unsigned int *) pos); | ||
270 | pos += sizeof (unsigned int); | ||
271 | rsize -= 2 * sizeof (int); | ||
272 | if (mlen > rsize) | ||
273 | goto ERR; | ||
274 | GNUNET_array_grow (collectionData->files, collectionData->file_count, len); | ||
275 | collectionData->meta = GNUNET_meta_data_deserialize (ectx, pos, mlen); | ||
276 | rsize -= mlen; | ||
277 | pos += mlen; | ||
278 | GNUNET_GE_BREAK (ectx, collectionData->meta != NULL); | ||
279 | for (i = 0; i < collectionData->file_count; i++) | ||
280 | { | ||
281 | if (rsize < 2 * sizeof (int)) | ||
282 | { | ||
283 | GNUNET_GE_BREAK (ectx, 0); | ||
284 | break; | ||
285 | } | ||
286 | len = ntohl (*(int *) pos); | ||
287 | pos += sizeof (int); | ||
288 | mlen = ntohl (*(int *) pos); | ||
289 | pos += sizeof (int); | ||
290 | rsize -= 2 * sizeof (int); | ||
291 | if (rsize < mlen + len) | ||
292 | { | ||
293 | GNUNET_GE_BREAK (ectx, 0); | ||
294 | break; | ||
295 | } | ||
296 | if (len > 1024 * 16) | ||
297 | { | ||
298 | GNUNET_GE_BREAK (ectx, 0); | ||
299 | len = 1024 * 16; | ||
300 | } | ||
301 | tmp = GNUNET_malloc (len + 1); | ||
302 | tmp[len] = '\0'; | ||
303 | memcpy (tmp, pos, len); | ||
304 | pos += len; | ||
305 | rsize -= len; | ||
306 | collectionData->files[i].uri = GNUNET_ECRS_string_to_uri (ectx, tmp); | ||
307 | GNUNET_GE_ASSERT (ectx, collectionData->files[i].uri != NULL); | ||
308 | GNUNET_free (tmp); | ||
309 | collectionData->files[i].meta | ||
310 | = GNUNET_meta_data_deserialize (ectx, pos, mlen); | ||
311 | GNUNET_GE_ASSERT (ectx, collectionData->files[i].meta != NULL); | ||
312 | pos += mlen; | ||
313 | rsize -= mlen; | ||
314 | } | ||
315 | GNUNET_GE_ASSERT (ectx, rsize == 0); | ||
316 | MUNMAP (buf, (size_t) size); | ||
317 | CLOSE (fd); | ||
318 | GNUNET_free (fn); | ||
319 | /* kill invalid entries (meta or uri == NULL) */ | ||
320 | for (i = 0; i < collectionData->file_count; i++) | ||
321 | { | ||
322 | if ((collectionData->files[i].uri != NULL) && | ||
323 | (collectionData->files[i].meta != NULL)) | ||
324 | continue; | ||
325 | if (collectionData->files[i].uri != NULL) | ||
326 | GNUNET_ECRS_uri_destroy (collectionData->files[i].uri); | ||
327 | if (collectionData->files[i].meta != NULL) | ||
328 | GNUNET_meta_data_destroy (collectionData->files[i].meta); | ||
329 | collectionData->files[i] | ||
330 | = collectionData->files[collectionData->file_count - 1]; | ||
331 | GNUNET_array_grow (collectionData->files, | ||
332 | collectionData->file_count, | ||
333 | collectionData->file_count - 1); | ||
334 | } | ||
335 | return; | ||
336 | ERR: | ||
337 | MUNMAP (buf, (size_t) size); | ||
338 | CLOSE (fd); | ||
339 | GNUNET_free (fn); | ||
340 | GNUNET_free (collectionData); | ||
341 | collectionData = NULL; | ||
342 | } | ||
343 | |||
344 | static void | ||
345 | WRITEINT (int fd, int val) | ||
346 | { | ||
347 | int bval; | ||
348 | |||
349 | bval = htonl (val); | ||
350 | WRITE (fd, &bval, sizeof (int)); | ||
351 | } | ||
352 | |||
353 | static void | ||
354 | writeCO () | ||
355 | { | ||
356 | char *fn; | ||
357 | unsigned int mlen; | ||
358 | char *buf; | ||
359 | int fd; | ||
360 | unsigned int i; | ||
361 | char *tmp; | ||
362 | |||
363 | if (collectionData == NULL) | ||
364 | return; | ||
365 | |||
366 | /* write collection data */ | ||
367 | mlen = | ||
368 | GNUNET_meta_data_get_serialized_size (collectionData->meta, GNUNET_NO); | ||
369 | buf = GNUNET_malloc (mlen); | ||
370 | if (mlen != GNUNET_meta_data_serialize (ectx, | ||
371 | collectionData->meta, buf, | ||
372 | mlen, GNUNET_NO)) | ||
373 | { | ||
374 | GNUNET_GE_BREAK (ectx, 0); | ||
375 | GNUNET_free (buf); | ||
376 | return; | ||
377 | } | ||
378 | |||
379 | fn = getCollectionFileName (); | ||
380 | fd = OPEN (fn, | ||
381 | O_CREAT | O_LARGEFILE | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR); | ||
382 | if (fd == -1) | ||
383 | { | ||
384 | GNUNET_GE_LOG_STRERROR_FILE (ectx, | ||
385 | GNUNET_GE_USER | GNUNET_GE_ADMIN | | ||
386 | GNUNET_GE_ERROR | GNUNET_GE_BULK, "open", | ||
387 | fn); | ||
388 | GNUNET_free (fn); | ||
389 | GNUNET_free (buf); | ||
390 | return; | ||
391 | } | ||
392 | GNUNET_GE_BREAK (ectx, collectionData->file_count <= 1024 * 1024 * 4); | ||
393 | WRITE (fd, collectionData, sizeof (CollectionData)); | ||
394 | WRITEINT (fd, collectionData->file_count); | ||
395 | WRITEINT (fd, mlen); | ||
396 | WRITE (fd, buf, mlen); | ||
397 | GNUNET_free (buf); | ||
398 | for (i = 0; i < collectionData->file_count; i++) | ||
399 | { | ||
400 | mlen = | ||
401 | GNUNET_meta_data_get_serialized_size (collectionData->files[i].meta, | ||
402 | GNUNET_NO); | ||
403 | buf = GNUNET_malloc (mlen); | ||
404 | if (mlen != GNUNET_meta_data_serialize (ectx, | ||
405 | collectionData->files[i].meta, | ||
406 | buf, mlen, GNUNET_NO)) | ||
407 | { | ||
408 | GNUNET_GE_BREAK (ectx, 0); | ||
409 | GNUNET_free (buf); | ||
410 | break; | ||
411 | } | ||
412 | tmp = GNUNET_ECRS_uri_to_string (collectionData->files[i].uri); | ||
413 | WRITEINT (fd, strlen (tmp)); | ||
414 | WRITEINT (fd, mlen); | ||
415 | GNUNET_GE_BREAK (ectx, strlen (tmp) < 16 * 1024); | ||
416 | WRITE (fd, tmp, strlen (tmp)); | ||
417 | GNUNET_free (tmp); | ||
418 | WRITE (fd, buf, mlen); | ||
419 | GNUNET_free (buf); | ||
420 | } | ||
421 | CLOSE (fd); | ||
422 | GNUNET_free (fn); | ||
423 | } | ||
424 | |||
425 | static void | ||
426 | free_collection_data () | ||
427 | { | ||
428 | unsigned int i; | ||
429 | |||
430 | if (collectionData == NULL) | ||
431 | return; | ||
432 | GNUNET_meta_data_destroy (collectionData->meta); | ||
433 | for (i = 0; i < collectionData->file_count; i++) | ||
434 | { | ||
435 | GNUNET_meta_data_destroy (collectionData->files[i].meta); | ||
436 | GNUNET_ECRS_uri_destroy (collectionData->files[i].uri); | ||
437 | } | ||
438 | GNUNET_array_grow (collectionData->files, collectionData->file_count, 0); | ||
439 | GNUNET_free (collectionData); | ||
440 | collectionData = NULL; | ||
441 | } | ||
442 | |||
443 | /** | ||
444 | * Shutdown collection module. | ||
445 | */ | ||
446 | void | ||
447 | GNUNET_CO_done () | ||
448 | { | ||
449 | writeCO (); | ||
450 | free_collection_data (); | ||
451 | GNUNET_mutex_destroy (lock); | ||
452 | lock = NULL; | ||
453 | ectx = NULL; | ||
454 | cfg = NULL; | ||
455 | } | ||
456 | |||
457 | |||
458 | /** | ||
459 | * Start collection. | ||
460 | * | ||
461 | * @param updateInterval of GNUNET_ECRS_SBLOCK_UPDATE_NONE | ||
462 | * means to update _immediately_ on any change, | ||
463 | * wherease GNUNET_ECRS_SBLOCK_UPDATE_SPORADIC means | ||
464 | * to publish updates when the CO_Context | ||
465 | * is destroyed (i.e. on exit from the UI). | ||
466 | */ | ||
467 | int | ||
468 | GNUNET_CO_collection_start (unsigned int anonymityLevel, | ||
469 | unsigned int prio, | ||
470 | const struct GNUNET_MetaData *meta) | ||
471 | { | ||
472 | struct GNUNET_ECRS_URI *advertisement; | ||
473 | struct GNUNET_ECRS_URI *rootURI; | ||
474 | const char *root = COLLECTION_ROOT; | ||
475 | |||
476 | GNUNET_mutex_lock (lock); | ||
477 | GNUNET_CO_collection_stop (); /* cancel old collection */ | ||
478 | advertisement = GNUNET_ECRS_keyword_string_to_uri (ectx, COLLECTION); | ||
479 | GNUNET_GE_ASSERT (ectx, advertisement != NULL); | ||
480 | rootURI = GNUNET_ECRS_namespace_create (ectx, | ||
481 | cfg, | ||
482 | meta, | ||
483 | anonymityLevel, | ||
484 | prio, | ||
485 | GNUNET_get_time () + | ||
486 | COLLECTION_ADV_LIFETIME, | ||
487 | advertisement, root); | ||
488 | GNUNET_ECRS_uri_destroy (advertisement); | ||
489 | if (rootURI == NULL) | ||
490 | { | ||
491 | GNUNET_mutex_unlock (lock); | ||
492 | return GNUNET_SYSERR; | ||
493 | } | ||
494 | collectionData = GNUNET_malloc (sizeof (CollectionInfo)); | ||
495 | memset (collectionData, 0, sizeof (CollectionInfo)); | ||
496 | GNUNET_ECRS_uri_get_namespace_from_sks (rootURI, &collectionData->data.pid); | ||
497 | GNUNET_ECRS_uri_destroy (rootURI); | ||
498 | collectionData->data.priority = htonl (prio); | ||
499 | collectionData->data.anonymityLevel = htonl (anonymityLevel); | ||
500 | collectionData->meta = GNUNET_meta_data_duplicate (meta); | ||
501 | GNUNET_mutex_unlock (lock); | ||
502 | return GNUNET_OK; | ||
503 | } | ||
504 | |||
505 | /** | ||
506 | * Stop collection. | ||
507 | * | ||
508 | * @return GNUNET_OK on success, GNUNET_SYSERR if no collection is active | ||
509 | */ | ||
510 | int | ||
511 | GNUNET_CO_collection_stop () | ||
512 | { | ||
513 | GNUNET_mutex_lock (lock); | ||
514 | if (collectionData == NULL) | ||
515 | { | ||
516 | GNUNET_mutex_unlock (lock); | ||
517 | return GNUNET_SYSERR; | ||
518 | } | ||
519 | GNUNET_ECRS_namespace_delete (ectx, cfg, &collectionData->data.pid); | ||
520 | free_collection_data (); | ||
521 | GNUNET_mutex_unlock (lock); | ||
522 | return GNUNET_OK; | ||
523 | } | ||
524 | |||
525 | /** | ||
526 | * Are we using a collection? | ||
527 | * | ||
528 | * @return NULL if there is no collection, otherwise its metadata | ||
529 | */ | ||
530 | struct GNUNET_MetaData * | ||
531 | GNUNET_CO_collection_get_name () | ||
532 | { | ||
533 | struct GNUNET_MetaData *meta; | ||
534 | |||
535 | GNUNET_mutex_lock (lock); | ||
536 | if (collectionData == NULL) | ||
537 | { | ||
538 | GNUNET_mutex_unlock (lock); | ||
539 | return NULL; | ||
540 | } | ||
541 | meta = GNUNET_meta_data_duplicate (collectionData->meta); | ||
542 | GNUNET_mutex_unlock (lock); | ||
543 | return meta; | ||
544 | } | ||
545 | |||
546 | /** | ||
547 | * Publish an update of the current collection information to the | ||
548 | * network now. The function has no effect if the collection has not | ||
549 | * changed since the last publication. If we are currently not | ||
550 | * collecting, this function does nothing. | ||
551 | */ | ||
552 | void | ||
553 | GNUNET_CO_collection_publish_now () | ||
554 | { | ||
555 | struct GNUNET_ECRS_URI *uri; | ||
556 | struct GNUNET_ECRS_URI *directoryURI; | ||
557 | unsigned long long dirLen; | ||
558 | char *tmpName; | ||
559 | int fd; | ||
560 | char *dirData; | ||
561 | char this_revision_string[128]; | ||
562 | char next_revision_string[128]; | ||
563 | const char *tmpdir; | ||
564 | |||
565 | GNUNET_mutex_lock (lock); | ||
566 | if ((collectionData == NULL) || | ||
567 | (ntohl (collectionData->data.changed) == GNUNET_NO)) | ||
568 | { | ||
569 | GNUNET_mutex_unlock (lock); | ||
570 | return; | ||
571 | } | ||
572 | |||
573 | tmpdir = getenv ("TMPDIR"); | ||
574 | tmpdir = tmpdir ? tmpdir : "/tmp"; | ||
575 | |||
576 | #define TEMPLATE "/gnunet-collectionXXXXXX" | ||
577 | tmpName = GNUNET_malloc (strlen (tmpdir) + sizeof (TEMPLATE) + 1); | ||
578 | strcpy (tmpName, tmpdir); | ||
579 | strcat (tmpName, TEMPLATE); | ||
580 | #undef TEMPLATE | ||
581 | fd = mkstemp (tmpName); | ||
582 | if (fd == -1) | ||
583 | { | ||
584 | GNUNET_GE_LOG_STRERROR (ectx, | ||
585 | GNUNET_GE_ERROR | GNUNET_GE_ADMIN | | ||
586 | GNUNET_GE_BULK, "mkstemp"); | ||
587 | GNUNET_free (tmpName); | ||
588 | GNUNET_mutex_unlock (lock); | ||
589 | return; | ||
590 | } | ||
591 | dirData = NULL; | ||
592 | GNUNET_GE_ASSERT (ectx, | ||
593 | GNUNET_OK == GNUNET_ECRS_directory_create (ectx, | ||
594 | &dirData, | ||
595 | &dirLen, | ||
596 | collectionData->file_count, | ||
597 | collectionData->files, | ||
598 | collectionData->meta)); | ||
599 | if (-1 == WRITE (fd, dirData, dirLen)) | ||
600 | { | ||
601 | GNUNET_GE_LOG_STRERROR (ectx, | ||
602 | GNUNET_GE_ERROR | GNUNET_GE_ADMIN | | ||
603 | GNUNET_GE_BULK, "write"); | ||
604 | GNUNET_free (tmpName); | ||
605 | GNUNET_free (dirData); | ||
606 | GNUNET_mutex_unlock (lock); | ||
607 | return; | ||
608 | } | ||
609 | GNUNET_free (dirData); | ||
610 | CLOSE (fd); | ||
611 | if (GNUNET_OK != GNUNET_ECRS_file_upload (ectx, cfg, tmpName, GNUNET_NO, /* indexing */ | ||
612 | ntohl (collectionData-> | ||
613 | data.anonymityLevel), | ||
614 | ntohl (collectionData-> | ||
615 | data.priority), | ||
616 | GNUNET_get_time () + | ||
617 | COLLECTION_ADV_LIFETIME, NULL, | ||
618 | NULL, NULL, NULL, &directoryURI)) | ||
619 | { | ||
620 | UNLINK (tmpName); | ||
621 | GNUNET_free (tmpName); | ||
622 | GNUNET_mutex_unlock (lock); | ||
623 | return; | ||
624 | } | ||
625 | UNLINK (tmpName); | ||
626 | GNUNET_free (tmpName); | ||
627 | if (ntohl (collectionData->data.revision) == 0) | ||
628 | strcpy (this_revision_string, COLLECTION_ROOT); | ||
629 | else | ||
630 | GNUNET_snprintf (this_revision_string, | ||
631 | sizeof (this_revision_string), | ||
632 | _("Revision %u"), ntohl (collectionData->data.revision)); | ||
633 | GNUNET_snprintf (next_revision_string, | ||
634 | sizeof (next_revision_string), | ||
635 | _("Revision %u"), | ||
636 | ntohl (collectionData->data.revision) + 1); | ||
637 | uri = GNUNET_ECRS_namespace_add_content (ectx, | ||
638 | cfg, | ||
639 | &collectionData->data.pid, | ||
640 | ntohl (collectionData-> | ||
641 | data.anonymityLevel), | ||
642 | ntohl (collectionData-> | ||
643 | data.priority), | ||
644 | GNUNET_get_time () + | ||
645 | COLLECTION_ADV_LIFETIME, | ||
646 | this_revision_string, | ||
647 | next_revision_string, directoryURI, | ||
648 | collectionData->meta); | ||
649 | if (uri != NULL) | ||
650 | { | ||
651 | collectionData->data.revision = | ||
652 | htonl (ntohl (collectionData->data.revision) + 1); | ||
653 | collectionData->data.changed = htonl (GNUNET_NO); | ||
654 | GNUNET_ECRS_uri_destroy (uri); | ||
655 | } | ||
656 | GNUNET_mutex_unlock (lock); | ||
657 | } | ||
658 | |||
659 | /** | ||
660 | * If we are currently building a collection, publish | ||
661 | * the given file information in that collection. | ||
662 | * If we are currently not collecting, this function | ||
663 | * does nothing. | ||
664 | */ | ||
665 | void | ||
666 | GNUNET_CO_collection_add_item (const GNUNET_ECRS_FileInfo * fi) | ||
667 | { | ||
668 | unsigned int i; | ||
669 | GNUNET_ECRS_FileInfo fc; | ||
670 | |||
671 | if ((GNUNET_ECRS_uri_test_ksk (fi->uri))) | ||
672 | { | ||
673 | GNUNET_GE_BREAK (ectx, 0); | ||
674 | return; | ||
675 | } | ||
676 | if (lock == NULL) | ||
677 | { | ||
678 | GNUNET_GE_BREAK (ectx, 0); | ||
679 | return; | ||
680 | } | ||
681 | GNUNET_mutex_lock (lock); | ||
682 | if (collectionData == NULL) | ||
683 | { | ||
684 | GNUNET_mutex_unlock (lock); | ||
685 | return; | ||
686 | } | ||
687 | for (i = 0; i < collectionData->file_count; i++) | ||
688 | { | ||
689 | if (GNUNET_ECRS_uri_test_equal (fi->uri, collectionData->files[i].uri)) | ||
690 | { | ||
691 | GNUNET_mutex_unlock (lock); | ||
692 | return; | ||
693 | } | ||
694 | } | ||
695 | fc.uri = GNUNET_ECRS_uri_duplicate (fi->uri); | ||
696 | fc.meta = GNUNET_meta_data_duplicate (fi->meta); | ||
697 | GNUNET_array_append (collectionData->files, collectionData->file_count, fc); | ||
698 | collectionData->data.changed = htonl (GNUNET_YES); | ||
699 | GNUNET_mutex_unlock (lock); | ||
700 | } | ||
701 | |||
702 | #endif | ||
703 | |||
704 | /* end of fs_collection.c */ | ||
diff --git a/src/fs/fs_directory.c b/src/fs/fs_directory.c new file mode 100644 index 000000000..1ee707cd1 --- /dev/null +++ b/src/fs/fs_directory.c | |||
@@ -0,0 +1,461 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2003, 2004, 2006, 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/fs_directory.c | ||
23 | * @brief Helper functions for building directories. | ||
24 | * @author Christian Grothoff | ||
25 | * | ||
26 | * TODO: | ||
27 | * - add support for embedded file data (use padding room!) | ||
28 | * - add directory builder API to gnunet_fs_service | ||
29 | * - modify directory builder API to support incremental | ||
30 | * generation of directories (to allow directories that | ||
31 | * would not fit into memory to be created) | ||
32 | * - modify directory processor API to support incremental | ||
33 | * iteration over FULL directories (without missing entries) | ||
34 | * to allow access to directories that do not fit entirely | ||
35 | * into memory | ||
36 | */ | ||
37 | #include "platform.h" | ||
38 | #include "gnunet_fs_service.h" | ||
39 | #include "fs.h" | ||
40 | |||
41 | |||
42 | /** | ||
43 | * Does the meta-data claim that this is a directory? | ||
44 | * Checks if the mime-type is that of a GNUnet directory. | ||
45 | * | ||
46 | * @return GNUNET_YES if it is, GNUNET_NO if it is not, GNUNET_SYSERR if | ||
47 | * we have no mime-type information (treat as 'GNUNET_NO') | ||
48 | */ | ||
49 | int | ||
50 | GNUNET_FS_meta_data_test_for_directory (const struct GNUNET_CONTAINER_MetaData *md) | ||
51 | { | ||
52 | char *mime; | ||
53 | int ret; | ||
54 | |||
55 | mime = GNUNET_CONTAINER_meta_data_get_by_type (md, EXTRACTOR_MIMETYPE); | ||
56 | if (mime == NULL) | ||
57 | return GNUNET_SYSERR; | ||
58 | ret = (0 == strcmp (mime, GNUNET_FS_DIRECTORY_MIME)) ? GNUNET_YES : GNUNET_NO; | ||
59 | GNUNET_free (mime); | ||
60 | return ret; | ||
61 | } | ||
62 | |||
63 | |||
64 | /** | ||
65 | * Set the MIMETYPE information for the given | ||
66 | * metadata to "application/gnunet-directory". | ||
67 | * | ||
68 | * @param md metadata to add mimetype to | ||
69 | */ | ||
70 | void | ||
71 | GNUNET_FS_meta_data_make_directory (struct GNUNET_CONTAINER_MetaData *md) | ||
72 | { | ||
73 | char *mime; | ||
74 | |||
75 | mime = GNUNET_CONTAINER_meta_data_get_by_type (md, EXTRACTOR_MIMETYPE); | ||
76 | if (mime != NULL) | ||
77 | { | ||
78 | GNUNET_break (0 == strcmp (mime, | ||
79 | GNUNET_FS_DIRECTORY_MIME)); | ||
80 | GNUNET_free (mime); | ||
81 | return; | ||
82 | } | ||
83 | GNUNET_CONTAINER_meta_data_insert (md, | ||
84 | EXTRACTOR_MIMETYPE, | ||
85 | GNUNET_FS_DIRECTORY_MIME); | ||
86 | } | ||
87 | |||
88 | |||
89 | /** | ||
90 | * Iterate over all entries in a directory. Note that directories | ||
91 | * are structured such that it is possible to iterate over the | ||
92 | * individual blocks as well as over the entire directory. Thus | ||
93 | * a client can call this function on the buffer in the | ||
94 | * GNUNET_FS_ProgressCallback. Also, directories can optionally | ||
95 | * include the contents of (small) files embedded in the directory | ||
96 | * itself; for those files, the processor may be given the | ||
97 | * contents of the file directly by this function. | ||
98 | * <p> | ||
99 | * | ||
100 | * Note that this function maybe called on parts of directories. Thus | ||
101 | * parser errors should not be reported _at all_ (with GNUNET_break). | ||
102 | * Still, if some entries can be recovered despite these parsing | ||
103 | * errors, the function should try to do this. | ||
104 | * | ||
105 | * @param size number of bytes in data | ||
106 | * @param data pointer to the beginning of the directory | ||
107 | * @param offset offset of data in the directory | ||
108 | * @param dep function to call on each entry | ||
109 | * @param dep_cls closure for dep | ||
110 | */ | ||
111 | void | ||
112 | GNUNET_FS_directory_list_contents (size_t size, | ||
113 | const void *data, | ||
114 | uint64_t offset, | ||
115 | GNUNET_FS_DirectoryEntryProcessor dep, | ||
116 | void *dep_cls) | ||
117 | { | ||
118 | const char *cdata = data; | ||
119 | char *emsg; | ||
120 | uint64_t pos; | ||
121 | uint64_t align; | ||
122 | uint32_t mdSize; | ||
123 | uint64_t epos; | ||
124 | struct GNUNET_FS_Uri *uri; | ||
125 | struct GNUNET_CONTAINER_MetaData *md; | ||
126 | char *filename; | ||
127 | |||
128 | pos = offset; | ||
129 | if ( (pos == 0) && | ||
130 | (size >= 8 + sizeof (uint32_t)) && | ||
131 | (0 == memcmp (cdata, GNUNET_FS_DIRECTORY_MAGIC, 8)) ) | ||
132 | { | ||
133 | memcpy (&mdSize, &cdata[8], sizeof (uint32_t)); | ||
134 | mdSize = ntohl (mdSize); | ||
135 | if (mdSize > size - 8 - sizeof (uint32_t)) | ||
136 | { | ||
137 | /* invalid size */ | ||
138 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
139 | _("Not a GNUnet directory.\n")); | ||
140 | return; | ||
141 | } | ||
142 | md = GNUNET_CONTAINER_meta_data_deserialize (&cdata[8 + | ||
143 | sizeof (uint32_t)], | ||
144 | mdSize); | ||
145 | if (md == NULL) | ||
146 | { | ||
147 | GNUNET_break (0); | ||
148 | return; /* malformed ! */ | ||
149 | } | ||
150 | dep (dep_cls, | ||
151 | NULL, | ||
152 | NULL, | ||
153 | md, | ||
154 | 0, | ||
155 | NULL); | ||
156 | GNUNET_CONTAINER_meta_data_destroy (md); | ||
157 | pos = 8 + sizeof (uint32_t) + mdSize; | ||
158 | } | ||
159 | while (pos < size) | ||
160 | { | ||
161 | /* find end of URI */ | ||
162 | if (cdata[pos] == '\0') | ||
163 | { | ||
164 | /* URI is never empty, must be end of block, | ||
165 | skip to next alignment */ | ||
166 | align = | ||
167 | ((pos / GNUNET_FS_DBLOCK_SIZE) + 1) * GNUNET_FS_DBLOCK_SIZE; | ||
168 | if (align == pos) | ||
169 | { | ||
170 | /* if we were already aligned, still skip a block! */ | ||
171 | align += GNUNET_FS_DBLOCK_SIZE; | ||
172 | } | ||
173 | pos = align; | ||
174 | if (pos >= size) | ||
175 | { | ||
176 | /* malformed - or partial download... */ | ||
177 | break; | ||
178 | } | ||
179 | } | ||
180 | epos = pos; | ||
181 | while ((epos < size) && (cdata[epos] != '\0')) | ||
182 | epos++; | ||
183 | if (epos >= size) | ||
184 | return; /* malformed - or partial download */ | ||
185 | |||
186 | uri = GNUNET_FS_uri_parse (&cdata[pos], &emsg); | ||
187 | pos = epos + 1; | ||
188 | if (uri == NULL) | ||
189 | { | ||
190 | GNUNET_free (emsg); | ||
191 | pos--; /* go back to '\0' to force going to next alignment */ | ||
192 | continue; | ||
193 | } | ||
194 | if (GNUNET_FS_uri_test_ksk (uri)) | ||
195 | { | ||
196 | GNUNET_FS_uri_destroy (uri); | ||
197 | GNUNET_break (0); | ||
198 | return; /* illegal in directory! */ | ||
199 | } | ||
200 | |||
201 | memcpy (&mdSize, &cdata[pos], sizeof (uint32_t)); | ||
202 | mdSize = ntohl (mdSize); | ||
203 | pos += sizeof (uint32_t); | ||
204 | if (pos + mdSize > size) | ||
205 | { | ||
206 | GNUNET_FS_uri_destroy (uri); | ||
207 | return; /* malformed - or partial download */ | ||
208 | } | ||
209 | |||
210 | md = GNUNET_CONTAINER_meta_data_deserialize (&cdata[pos], mdSize); | ||
211 | if (md == NULL) | ||
212 | { | ||
213 | GNUNET_FS_uri_destroy (uri); | ||
214 | GNUNET_break (0); | ||
215 | return; /* malformed ! */ | ||
216 | } | ||
217 | pos += mdSize; | ||
218 | /* FIXME: add support for embedded data */ | ||
219 | filename = GNUNET_CONTAINER_meta_data_get_by_type (md, | ||
220 | EXTRACTOR_FILENAME); | ||
221 | if (dep != NULL) | ||
222 | dep (dep_cls, | ||
223 | filename, | ||
224 | uri, | ||
225 | md, | ||
226 | 0, | ||
227 | NULL); | ||
228 | GNUNET_free_non_null (filename); | ||
229 | GNUNET_CONTAINER_meta_data_destroy (md); | ||
230 | GNUNET_FS_uri_destroy (uri); | ||
231 | } | ||
232 | } | ||
233 | |||
234 | #if 0 | ||
235 | |||
236 | |||
237 | /** | ||
238 | * Given the start and end position of a block of | ||
239 | * data, return the end position of that data | ||
240 | * after alignment to the GNUNET_FS_DBLOCK_SIZE. | ||
241 | */ | ||
242 | static uint64_t | ||
243 | do_align (uint64_t start_position, | ||
244 | uint64_t end_position) | ||
245 | { | ||
246 | uint64_t align; | ||
247 | |||
248 | align = (end_position / GNUNET_FS_DBLOCK_SIZE) * GNUNET_FS_DBLOCK_SIZE; | ||
249 | if ((start_position < align) && (end_position > align)) | ||
250 | return align + end_position - start_position; | ||
251 | return end_position; | ||
252 | } | ||
253 | |||
254 | |||
255 | /** | ||
256 | * Compute a permuation of the blocks to | ||
257 | * minimize the cost of alignment. Greedy packer. | ||
258 | * | ||
259 | * @param start starting position for the first block | ||
260 | * @param count size of the two arrays | ||
261 | * @param sizes the sizes of the individual blocks | ||
262 | * @param perm the permutation of the blocks (updated) | ||
263 | */ | ||
264 | static void | ||
265 | block_align (uint64_t start, | ||
266 | unsigned int count, | ||
267 | const uint64_t *sizes, | ||
268 | unsigned int *perm) | ||
269 | { | ||
270 | unsigned int i; | ||
271 | unsigned int j; | ||
272 | unsigned int tmp; | ||
273 | unsigned int best; | ||
274 | int64_t badness; | ||
275 | uint64_t cpos; | ||
276 | uint64_t cend; | ||
277 | int64_t cbad; | ||
278 | unsigned int cval; | ||
279 | |||
280 | cpos = start; | ||
281 | for (i = 0; i < count; i++) | ||
282 | { | ||
283 | start = cpos; | ||
284 | badness = 0x7FFFFFFF; | ||
285 | best = -1; | ||
286 | for (j = i; j < count; j++) | ||
287 | { | ||
288 | cval = perm[j]; | ||
289 | cend = cpos + sizes[cval]; | ||
290 | if (cpos % GNUNET_FS_DBLOCK_SIZE == 0) | ||
291 | { | ||
292 | /* prefer placing the largest blocks first */ | ||
293 | cbad = -(cend % GNUNET_FS_DBLOCK_SIZE); | ||
294 | } | ||
295 | else | ||
296 | { | ||
297 | if (cpos / GNUNET_FS_DBLOCK_SIZE == | ||
298 | cend / GNUNET_FS_DBLOCK_SIZE) | ||
299 | { | ||
300 | /* Data fits into the same block! Prefer small left-overs! */ | ||
301 | cbad = | ||
302 | GNUNET_FS_DBLOCK_SIZE - cend % GNUNET_FS_DBLOCK_SIZE; | ||
303 | } | ||
304 | else | ||
305 | { | ||
306 | /* Would have to waste space to re-align, add big factor, this | ||
307 | case is a real loss (proportional to space wasted)! */ | ||
308 | cbad = | ||
309 | GNUNET_FS_DBLOCK_SIZE * (GNUNET_FS_DBLOCK_SIZE - | ||
310 | cpos % | ||
311 | GNUNET_FS_DBLOCK_SIZE); | ||
312 | } | ||
313 | } | ||
314 | if (cbad < badness) | ||
315 | { | ||
316 | best = j; | ||
317 | badness = cbad; | ||
318 | } | ||
319 | } | ||
320 | tmp = perm[i]; | ||
321 | perm[i] = perm[best]; | ||
322 | perm[best] = tmp; | ||
323 | cpos += sizes[perm[i]]; | ||
324 | cpos = do_align (start, cpos); | ||
325 | } | ||
326 | } | ||
327 | |||
328 | |||
329 | /** | ||
330 | * Create a directory. We allow packing more than one variable | ||
331 | * size entry into one block (and an entry could also span more | ||
332 | * than one block), but an entry that is smaller than a single | ||
333 | * block will never cross the block boundary. This is done to | ||
334 | * allow processing entries of a directory already even if the | ||
335 | * download is still partial.<p> | ||
336 | * | ||
337 | * The first block begins with the directories MAGIC signature, | ||
338 | * followed by the meta-data about the directory itself.<p> | ||
339 | * | ||
340 | * After that, the directory consists of block-aligned pairs | ||
341 | * of URIs (0-terminated strings) and serialized meta-data. | ||
342 | * | ||
343 | * @param data pointer set to the beginning of the directory | ||
344 | * @param len set to number of bytes in data | ||
345 | * @param count number of entries in uris and mds | ||
346 | * @param uris URIs of the files in the directory | ||
347 | * @param mds meta-data for the files (must match | ||
348 | * respective values at same offset in in uris) | ||
349 | * @param mdir meta-data for the directory | ||
350 | * @return GNUNET_OK on success, GNUNET_SYSERR on error | ||
351 | */ | ||
352 | int | ||
353 | GNUNET_FS_directory_create (char **data, | ||
354 | size_t *len, | ||
355 | unsigned int count, | ||
356 | const struct GNUNET_FS_Uri **uris, | ||
357 | const struct GNUNET_CONTAINER_MetaData **mds, | ||
358 | const struct GNUNET_CONTAINER_MetaData *mdir) | ||
359 | { | ||
360 | unsigned int i; | ||
361 | unsigned int j; | ||
362 | uint64_t psize; | ||
363 | uint64_t size; | ||
364 | uint64_t pos; | ||
365 | char **ucs; | ||
366 | int ret; | ||
367 | uint64_t *sizes; | ||
368 | unsigned int *perm; | ||
369 | |||
370 | for (i = 0; i < count; i++) | ||
371 | { | ||
372 | if (GNUNET_FS_uri_test_ksk (fis[i].uri)) | ||
373 | { | ||
374 | GNUNET_break (0); | ||
375 | return GNUNET_SYSERR; /* illegal in directory! */ | ||
376 | } | ||
377 | } | ||
378 | ucs = GNUNET_malloc (sizeof (char *) * count); | ||
379 | size = 8 + sizeof (unsigned int); | ||
380 | size += GNUNET_meta_data_get_serialized_size (meta, GNUNET_SERIALIZE_FULL); | ||
381 | sizes = GNUNET_malloc (count * sizeof (unsigned long long)); | ||
382 | perm = GNUNET_malloc (count * sizeof (int)); | ||
383 | for (i = 0; i < count; i++) | ||
384 | { | ||
385 | perm[i] = i; | ||
386 | ucs[i] = GNUNET_FS_uri_to_string (fis[i].uri); | ||
387 | GNUNET_assert (ucs[i] != NULL); | ||
388 | psize = | ||
389 | GNUNET_meta_data_get_serialized_size (fis[i].meta, | ||
390 | GNUNET_SERIALIZE_FULL); | ||
391 | if (psize == -1) | ||
392 | { | ||
393 | GNUNET_break (0); | ||
394 | GNUNET_free (sizes); | ||
395 | GNUNET_free (perm); | ||
396 | while (i >= 0) | ||
397 | GNUNET_free (ucs[i--]); | ||
398 | GNUNET_free (ucs); | ||
399 | return GNUNET_SYSERR; | ||
400 | } | ||
401 | sizes[i] = psize + sizeof (unsigned int) + strlen (ucs[i]) + 1; | ||
402 | } | ||
403 | /* permutate entries to minimize alignment cost */ | ||
404 | block_align (size, count, sizes, perm); | ||
405 | |||
406 | /* compute final size with alignment */ | ||
407 | for (i = 0; i < count; i++) | ||
408 | { | ||
409 | psize = size; | ||
410 | size += sizes[perm[i]]; | ||
411 | size = do_align (psize, size); | ||
412 | } | ||
413 | *len = size; | ||
414 | *data = GNUNET_malloc (size); | ||
415 | memset (*data, 0, size); | ||
416 | |||
417 | pos = 8; | ||
418 | memcpy (*data, GNUNET_DIRECTORY_MAGIC, 8); | ||
419 | |||
420 | ret = GNUNET_CONTAINER_meta_data_serialize (meta, | ||
421 | &(*data)[pos + | ||
422 | sizeof (unsigned int)], | ||
423 | size - pos - sizeof (unsigned int), | ||
424 | GNUNET_SERIALIZE_FULL); | ||
425 | GNUNET_assert (ret != GNUNET_SYSERR); | ||
426 | ret = htonl (ret); | ||
427 | memcpy (&(*data)[pos], &ret, sizeof (unsigned int)); | ||
428 | pos += ntohl (ret) + sizeof (unsigned int); | ||
429 | |||
430 | for (j = 0; j < count; j++) | ||
431 | { | ||
432 | i = perm[j]; | ||
433 | psize = pos; | ||
434 | pos += sizes[i]; | ||
435 | pos = do_align (psize, pos); | ||
436 | pos -= sizes[i]; /* go back to beginning */ | ||
437 | memcpy (&(*data)[pos], ucs[i], strlen (ucs[i]) + 1); | ||
438 | pos += strlen (ucs[i]) + 1; | ||
439 | GNUNET_free (ucs[i]); | ||
440 | ret = GNUNET_CONTAINER_meta_data_serialize (mds[i], | ||
441 | &(*data)[pos + | ||
442 | sizeof (unsigned int)], | ||
443 | size - pos - | ||
444 | sizeof (unsigned int), | ||
445 | GNUNET_SERIALIZE_FULL); | ||
446 | GNUNET_assert (ret != GNUNET_SYSERR); | ||
447 | ret = htonl (ret); | ||
448 | memcpy (&(*data)[pos], &ret, sizeof (unsigned int)); | ||
449 | pos += ntohl (ret) + sizeof (unsigned int); | ||
450 | } | ||
451 | GNUNET_free (sizes); | ||
452 | GNUNET_free (perm); | ||
453 | GNUNET_free (ucs); | ||
454 | GNUNET_assert (pos == size); | ||
455 | return GNUNET_OK; | ||
456 | } | ||
457 | |||
458 | |||
459 | #endif | ||
460 | |||
461 | /* end of fs_directory.c */ | ||
diff --git a/src/fs/test_fs_collection.c b/src/fs/test_fs_collection.c new file mode 100644 index 000000000..421cb5060 --- /dev/null +++ b/src/fs/test_fs_collection.c | |||
@@ -0,0 +1,103 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2006, 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_collection.c | ||
23 | * @brief testcase for fs_collection.c | ||
24 | * @author Christian Grothoff | ||
25 | */ | ||
26 | |||
27 | #include "platform.h" | ||
28 | #include "gnunet_util_lib.h" | ||
29 | #include "gnunet_fs_service.h" | ||
30 | |||
31 | #define CHECK(a) if (!(a)) { ok = GNUNET_NO; GNUNET_break(0); goto FAILURE; } | ||
32 | |||
33 | int | ||
34 | main (int argc, char *argv[]) | ||
35 | { | ||
36 | struct GNUNET_CONFIGURATION_Handle *cfg; | ||
37 | int ok; | ||
38 | struct GNUNET_ClientServerConnection *sock; | ||
39 | struct GNUNET_CONTAINER_MetaData *meta; | ||
40 | struct GNUNET_CONTAINER_MetaData *have; | ||
41 | char *emsg; | ||
42 | struct GNUNET_FS_Uri *uri; | ||
43 | struct GNUNET_CONTAINER_MetaData *md; | ||
44 | struct GNUNET_FS_Handle *fsh; | ||
45 | |||
46 | GNUNET_CRYPTO_random_disable_entropy_gathering (); | ||
47 | cfg = GNUNET_CONFIGURATION_create (); | ||
48 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_parse (cfg, "check.conf")) | ||
49 | { | ||
50 | GNUNET_CONFIGURATION_destroy (cfg); | ||
51 | return -1; | ||
52 | } | ||
53 | sock = NULL; | ||
54 | meta = NULL; | ||
55 | ok = GNUNET_YES; | ||
56 | meta = GNUNET_CONTAINER_meta_data_create (); | ||
57 | GNUNET_CONTAINER_meta_data_insert (meta, EXTRACTOR_MIMETYPE, "test/foo"); | ||
58 | |||
59 | |||
60 | fsh = GNUNET_FS_start (sched, | ||
61 | cfg, | ||
62 | "test-fs-collection", | ||
63 | &progress_cb, | ||
64 | NULL); | ||
65 | |||
66 | /* ACTUAL TEST CODE */ | ||
67 | GNUNET_FS_collection_stop (fsh); | ||
68 | CHECK (NULL == GNUNET_FS_collection_get (fsh)); | ||
69 | CHECK (GNUNET_OK == GNUNET_FS_collection_start (fsh, | ||
70 | namespace)); | ||
71 | have = GNUNET_FS_collection_get (fsh); | ||
72 | CHECK (NULL != have); | ||
73 | CHECK (GNUNET_CONTAINER_meta_data_test_equal (have, meta)); | ||
74 | GNUNET_CONTAINER_meta_data_destroy (have); | ||
75 | md = meta; | ||
76 | uri = | ||
77 | GNUNET_FS_uri_parse ("gnunet://ecrs/chk/0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.0", &emsg); | ||
78 | GNUNET_FS_collection_add (fsh, uri, md); | ||
79 | GNUNET_FS_uri_destroy (uri); | ||
80 | GNUNET_FS_stop (fsh); | ||
81 | fsh = GNUNET_FS_start (sched, cfg, | ||
82 | "test-fs-collection", | ||
83 | &progress_cb, | ||
84 | NULL); | ||
85 | have = GNUNET_FS_collection_get (fsh); | ||
86 | CHECK (NULL != have); | ||
87 | CHECK (GNUNET_CONTAINER_meta_data_test_equal (have, meta)); | ||
88 | GNUNET_CONTAINER_meta_data_destroy (have); | ||
89 | GNUNET_FS_collection_publish (fsh); | ||
90 | GNUNET_FS_collection_stop (fsh); | ||
91 | CHECK (NULL == GNUNET_FS_collection_get (fsh)); | ||
92 | GNUNET_FS_stop (fsh); | ||
93 | |||
94 | /* END OF TEST CODE */ | ||
95 | FAILURE: | ||
96 | if (meta != NULL) | ||
97 | GNUNET_CONTAINER_meta_data_destroy (meta); | ||
98 | GNUNET_CONFIGURATION_destroy (cfg); | ||
99 | |||
100 | return (ok == GNUNET_YES) ? 0 : 1; | ||
101 | } | ||
102 | |||
103 | /* end of test_fs_collection.c */ | ||
diff --git a/src/fs/test_fs_directory.c b/src/fs/test_fs_directory.c new file mode 100644 index 000000000..d643e6ed9 --- /dev/null +++ b/src/fs/test_fs_directory.c | |||
@@ -0,0 +1,167 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2005, 2006, 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_directory.c | ||
23 | * @brief Test for fs_directory.c | ||
24 | * @author Christian Grothoff | ||
25 | */ | ||
26 | |||
27 | #include "platform.h" | ||
28 | #include <extractor.h> | ||
29 | #include "gnunet_util_lib.h" | ||
30 | #include "gnunet_fs_service.h" | ||
31 | #include "fs.h" | ||
32 | |||
33 | #define ABORT() { fprintf(stderr, "Error at %s:%d\n", __FILE__, __LINE__); return 1; } | ||
34 | |||
35 | struct PCLS | ||
36 | { | ||
37 | struct GNUNET_FS_Uri **uri; | ||
38 | struct GNUNET_CONTAINER_MetaData **md; | ||
39 | unsigned int pos; | ||
40 | unsigned int max; | ||
41 | }; | ||
42 | |||
43 | static void | ||
44 | processor (void *cls, | ||
45 | const char *filename, | ||
46 | const struct GNUNET_FS_Uri *uri, | ||
47 | const struct GNUNET_CONTAINER_MetaData *md, | ||
48 | size_t length, | ||
49 | const void *data) | ||
50 | { | ||
51 | struct PCLS *p = cls; | ||
52 | int i; | ||
53 | |||
54 | for (i = 0; i < p->max; i++) | ||
55 | { | ||
56 | if (GNUNET_CONTAINER_meta_data_test_equal (p->md[i], | ||
57 | md) && | ||
58 | GNUNET_FS_uri_test_equal (p->uri[i], uri)) | ||
59 | { | ||
60 | p->pos++; | ||
61 | return; | ||
62 | } | ||
63 | } | ||
64 | fprintf (stderr, "Error at %s:%d\n", __FILE__, __LINE__); | ||
65 | } | ||
66 | |||
67 | static int | ||
68 | testDirectory (unsigned int i) | ||
69 | { | ||
70 | char *data; | ||
71 | unsigned long long dlen; | ||
72 | struct GNUNET_FS_Uri **uris; | ||
73 | struct GNUNET_CONTAINER_MetaData **mds; | ||
74 | struct GNUNET_CONTAINER_MetaData *meta; | ||
75 | struct PCLS cls; | ||
76 | char *emsg; | ||
77 | int p; | ||
78 | int q; | ||
79 | char uri[512]; | ||
80 | char txt[128]; | ||
81 | int ret = 0; | ||
82 | |||
83 | cls.max = i; | ||
84 | uris = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri*) * i); | ||
85 | mds = GNUNET_malloc (sizeof (struct GNUNET_CONTAINER_MetaData*) * i); | ||
86 | for (p = 0; p < i; p++) | ||
87 | { | ||
88 | mds[p] = GNUNET_CONTAINER_meta_data_create (); | ||
89 | for (q = 0; q <= p; q++) | ||
90 | { | ||
91 | GNUNET_snprintf (txt, sizeof(txt), "%u -- %u\n", p, q); | ||
92 | GNUNET_CONTAINER_meta_data_insert (mds[p], | ||
93 | q % | ||
94 | EXTRACTOR_getHighestKeywordTypeNumber | ||
95 | (), txt); | ||
96 | } | ||
97 | GNUNET_snprintf (uri, | ||
98 | sizeof(uri), | ||
99 | "gnunet://ecrs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.%u", | ||
100 | p); | ||
101 | uris[p] = GNUNET_FS_uri_parse (uri, &emsg); | ||
102 | if (uris[p] == NULL) | ||
103 | { | ||
104 | GNUNET_CONTAINER_meta_data_destroy (mds[p]); | ||
105 | while (--p > 0) | ||
106 | { | ||
107 | GNUNET_CONTAINER_meta_data_destroy (mds[p]); | ||
108 | GNUNET_FS_uri_destroy (uris[p]); | ||
109 | } | ||
110 | GNUNET_free (mds); | ||
111 | GNUNET_free (uris); | ||
112 | ABORT (); /* error in testcase */ | ||
113 | } | ||
114 | } | ||
115 | meta = GNUNET_CONTAINER_meta_data_create (); | ||
116 | GNUNET_CONTAINER_meta_data_insert (meta, EXTRACTOR_TITLE, "A title"); | ||
117 | GNUNET_CONTAINER_meta_data_insert (meta, EXTRACTOR_AUTHOR, "An author"); | ||
118 | if (GNUNET_OK != | ||
119 | GNUNET_FS_directory_create (&dlen, &data, i, uris, mds, meta)) | ||
120 | { | ||
121 | GNUNET_CONTAINER_meta_data_destroy (meta); | ||
122 | for (p = 0; p < i; p++) | ||
123 | { | ||
124 | GNUNET_CONTAINER_meta_data_destroy (mds[p]); | ||
125 | GNUNET_FS_uri_destroy (uris[p]); | ||
126 | } | ||
127 | GNUNET_free (uris); | ||
128 | GNUNET_free (mds); | ||
129 | ABORT (); | ||
130 | } | ||
131 | cls.pos = 0; | ||
132 | cls.uri = uris; | ||
133 | cls.md = mds; | ||
134 | GNUNET_FS_directory_list_contents (dlen, data, 0, | ||
135 | &processor, &cls); | ||
136 | GNUNET_assert (cls.pos == i); | ||
137 | GNUNET_free (data); | ||
138 | GNUNET_CONTAINER_meta_data_destroy (meta); | ||
139 | for (p = 0; p < i; p++) | ||
140 | { | ||
141 | GNUNET_CONTAINER_meta_data_destroy (mds[p]); | ||
142 | GNUNET_FS_uri_destroy (uris[p]); | ||
143 | } | ||
144 | GNUNET_free (uris); | ||
145 | GNUNET_free (mds); | ||
146 | return ret; | ||
147 | } | ||
148 | |||
149 | int | ||
150 | main (int argc, char *argv[]) | ||
151 | { | ||
152 | int failureCount = 0; | ||
153 | int i; | ||
154 | |||
155 | for (i = 17; i < 2000; i *= 2) | ||
156 | { | ||
157 | fprintf (stderr, "."); | ||
158 | failureCount += testDirectory (i); | ||
159 | } | ||
160 | fprintf (stderr, "\n"); | ||
161 | |||
162 | if (failureCount != 0) | ||
163 | return 1; | ||
164 | return 0; | ||
165 | } | ||
166 | |||
167 | /* end of test_fs_directory.c */ | ||
diff --git a/src/fs/test_fs_uri.c b/src/fs/test_fs_uri.c index f07ba4179..6da56a742 100644 --- a/src/fs/test_fs_uri.c +++ b/src/fs/test_fs_uri.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | (C) 2003, 2004, 2006, 2007 Christian Grothoff (and other contributing authors) | 3 | (C) 2003, 2004, 2006, 2007, 2009 Christian Grothoff (and other contributing authors) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 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 | 6 | it under the terms of the GNU General Public License as published |
@@ -35,104 +35,110 @@ static int | |||
35 | testKeyword () | 35 | testKeyword () |
36 | { | 36 | { |
37 | char *uri; | 37 | char *uri; |
38 | struct GNUNET_ECRS_URI *ret; | 38 | struct GNUNET_FS_Uri *ret; |
39 | char *emsg; | ||
39 | 40 | ||
40 | if (NULL != GNUNET_ECRS_string_to_uri (NULL, "gnunet://ecrs/ksk/++")) | 41 | if (NULL != GNUNET_FS_uri_parse ("gnunet://ecrs/ksk/++", &emsg)) |
41 | ABORT (); | 42 | ABORT (); |
42 | ret = GNUNET_ECRS_string_to_uri (NULL, "gnunet://ecrs/ksk/foo+bar"); | 43 | GNUNET_free (emsg); |
44 | ret = GNUNET_FS_uri_parse ("gnunet://ecrs/ksk/foo+bar", &emsg); | ||
43 | if (ret == NULL) | 45 | if (ret == NULL) |
44 | ABORT (); | 46 | ABORT (); |
45 | if (!GNUNET_ECRS_uri_test_ksk (ret)) | 47 | if (!GNUNET_FS_uri_test_ksk (ret)) |
46 | { | 48 | { |
47 | GNUNET_ECRS_uri_destroy (ret); | 49 | GNUNET_FS_uri_destroy (ret); |
48 | ABORT (); | 50 | ABORT (); |
49 | } | 51 | } |
50 | if ((2 != ret->data.ksk.keywordCount) || | 52 | if ((2 != ret->data.ksk.keywordCount) || |
51 | (0 != strcmp (" foo", ret->data.ksk.keywords[0])) || | 53 | (0 != strcmp (" foo", ret->data.ksk.keywords[0])) || |
52 | (0 != strcmp (" bar", ret->data.ksk.keywords[1]))) | 54 | (0 != strcmp (" bar", ret->data.ksk.keywords[1]))) |
53 | { | 55 | { |
54 | GNUNET_ECRS_uri_destroy (ret); | 56 | GNUNET_FS_uri_destroy (ret); |
55 | ABORT (); | 57 | ABORT (); |
56 | } | 58 | } |
57 | 59 | ||
58 | uri = GNUNET_ECRS_uri_to_string (ret); | 60 | uri = GNUNET_FS_uri_to_string (ret); |
59 | if (0 != strcmp (uri, "gnunet://ecrs/ksk/foo+bar")) | 61 | if (0 != strcmp (uri, "gnunet://ecrs/ksk/foo+bar")) |
60 | { | 62 | { |
61 | GNUNET_free (uri); | 63 | GNUNET_free (uri); |
62 | GNUNET_ECRS_uri_destroy (ret); | 64 | GNUNET_FS_uri_destroy (ret); |
63 | ABORT (); | 65 | ABORT (); |
64 | } | 66 | } |
65 | GNUNET_free (uri); | 67 | GNUNET_free (uri); |
66 | GNUNET_ECRS_uri_destroy (ret); | 68 | GNUNET_FS_uri_destroy (ret); |
67 | return 0; | 69 | return 0; |
68 | } | 70 | } |
69 | 71 | ||
70 | static int | 72 | static int |
71 | testLocation () | 73 | testLocation () |
72 | { | 74 | { |
73 | struct GNUNET_ECRS_URI *uri; | 75 | struct GNUNET_FS_Uri *uri; |
74 | char *uric; | 76 | char *uric; |
75 | struct GNUNET_ECRS_URI *uri2; | 77 | struct GNUNET_FS_Uri *uri2; |
76 | GNUNET_RSA_PublicKey pk; | 78 | struct GNUNET_FS_Uri *baseURI; |
77 | struct GNUNET_RSA_PrivateKey *hk; | 79 | char *emsg; |
78 | struct GNUNET_ECRS_URI *baseURI; | 80 | struct GNUNET_CONFIGURATION_Handle *cfg; |
79 | 81 | ||
80 | baseURI = | 82 | baseURI = |
81 | GNUNET_ECRS_string_to_uri (NULL, | 83 | GNUNET_FS_uri_parse ("gnunet://ecrs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.42", &emsg); |
82 | "gnunet://ecrs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.42"); | 84 | GNUNET_assert (baseURI != NULL); |
83 | hk = GNUNET_RSA_create_key (); | 85 | cfg = GNUNET_CONFIGURATION_create (); |
84 | GNUNET_RSA_get_public_key (hk, &pk); | 86 | if (GNUNET_OK != |
85 | uri = GNUNET_ECRS_location_to_uri (baseURI, | 87 | GNUNET_CONFIGURATION_parse (cfg, "test_fs_uri_data.conf")) |
86 | &pk, 43, | 88 | { |
87 | (GNUNET_ECRS_SignFunction) & | 89 | fprintf (stderr, "Failed to parse configuration file\n"); |
88 | GNUNET_RSA_sign, hk); | 90 | GNUNET_CONFIGURATION_destroy (cfg); |
89 | GNUNET_RSA_free_key (hk); | 91 | return 1; |
92 | } | ||
93 | uri = GNUNET_FS_uri_loc_create (baseURI, | ||
94 | cfg, | ||
95 | GNUNET_TIME_absolute_get ()); | ||
90 | if (uri == NULL) | 96 | if (uri == NULL) |
91 | { | 97 | { |
92 | GNUNET_GE_BREAK (NULL, 0); | 98 | GNUNET_break (0); |
93 | GNUNET_ECRS_uri_destroy (baseURI); | 99 | GNUNET_FS_uri_destroy (baseURI); |
94 | return 1; | 100 | return 1; |
95 | } | 101 | } |
96 | if (!GNUNET_ECRS_uri_test_loc (uri)) | 102 | if (!GNUNET_FS_uri_test_loc (uri)) |
97 | { | 103 | { |
98 | GNUNET_GE_BREAK (NULL, 0); | 104 | GNUNET_break (0); |
99 | GNUNET_ECRS_uri_destroy (uri); | 105 | GNUNET_FS_uri_destroy (uri); |
100 | GNUNET_ECRS_uri_destroy (baseURI); | 106 | GNUNET_FS_uri_destroy (baseURI); |
101 | return 1; | 107 | return 1; |
102 | } | 108 | } |
103 | uri2 = GNUNET_ECRS_uri_get_content_uri_from_loc (uri); | 109 | uri2 = GNUNET_FS_uri_loc_get_uri (uri); |
104 | if (!GNUNET_ECRS_uri_test_equal (baseURI, uri2)) | 110 | if (!GNUNET_FS_uri_test_equal (baseURI, uri2)) |
105 | { | 111 | { |
106 | GNUNET_GE_BREAK (NULL, 0); | 112 | GNUNET_break (0); |
107 | GNUNET_ECRS_uri_destroy (uri); | 113 | GNUNET_FS_uri_destroy (uri); |
108 | GNUNET_ECRS_uri_destroy (uri2); | 114 | GNUNET_FS_uri_destroy (uri2); |
109 | GNUNET_ECRS_uri_destroy (baseURI); | 115 | GNUNET_FS_uri_destroy (baseURI); |
110 | return 1; | 116 | return 1; |
111 | } | 117 | } |
112 | GNUNET_ECRS_uri_destroy (uri2); | 118 | GNUNET_FS_uri_destroy (uri2); |
113 | GNUNET_ECRS_uri_destroy (baseURI); | 119 | GNUNET_FS_uri_destroy (baseURI); |
114 | uric = GNUNET_ECRS_uri_to_string (uri); | 120 | uric = GNUNET_FS_uri_to_string (uri); |
115 | #if 0 | 121 | #if 0 |
116 | /* not for the faint of heart: */ | 122 | /* not for the faint of heart: */ |
117 | printf ("URI: `%s'\n", uric); | 123 | printf ("URI: `%s'\n", uric); |
118 | #endif | 124 | #endif |
119 | uri2 = GNUNET_ECRS_string_to_uri (NULL, uric); | 125 | uri2 = GNUNET_FS_uri_parse (uric, &emsg); |
120 | GNUNET_free (uric); | 126 | GNUNET_free (uric); |
121 | if (uri2 == NULL) | 127 | if (uri2 == NULL) |
122 | { | 128 | { |
123 | GNUNET_GE_BREAK (NULL, 0); | 129 | GNUNET_break (0); |
124 | GNUNET_ECRS_uri_destroy (uri); | 130 | GNUNET_FS_uri_destroy (uri); |
125 | return 1; | 131 | return 1; |
126 | } | 132 | } |
127 | if (GNUNET_YES != GNUNET_ECRS_uri_test_equal (uri, uri2)) | 133 | if (GNUNET_YES != GNUNET_FS_uri_test_equal (uri, uri2)) |
128 | { | 134 | { |
129 | GNUNET_GE_BREAK (NULL, 0); | 135 | GNUNET_break (0); |
130 | GNUNET_ECRS_uri_destroy (uri); | 136 | GNUNET_FS_uri_destroy (uri); |
131 | GNUNET_ECRS_uri_destroy (uri2); | 137 | GNUNET_FS_uri_destroy (uri2); |
132 | return 1; | 138 | return 1; |
133 | } | 139 | } |
134 | GNUNET_ECRS_uri_destroy (uri2); | 140 | GNUNET_FS_uri_destroy (uri2); |
135 | GNUNET_ECRS_uri_destroy (uri); | 141 | GNUNET_FS_uri_destroy (uri); |
136 | return 0; | 142 | return 0; |
137 | } | 143 | } |
138 | 144 | ||
@@ -140,44 +146,42 @@ static int | |||
140 | testNamespace (int i) | 146 | testNamespace (int i) |
141 | { | 147 | { |
142 | char *uri; | 148 | char *uri; |
143 | struct GNUNET_ECRS_URI *ret; | 149 | struct GNUNET_FS_Uri *ret; |
150 | char *emsg; | ||
144 | 151 | ||
145 | if (NULL != | 152 | if (NULL != |
146 | GNUNET_ECRS_string_to_uri (NULL, | 153 | GNUNET_FS_uri_parse ("gnunet://ecrs/sks/D1KJS9H2A82Q65VKQ0ML3RFU6U1D3VUK", &emsg)) |
147 | "gnunet://ecrs/sks/D1KJS9H2A82Q65VKQ0ML3RFU6U1D3VUK")) | ||
148 | ABORT (); | 154 | ABORT (); |
149 | if (NULL != | 155 | if (NULL != |
150 | GNUNET_ECRS_string_to_uri (NULL, | 156 | GNUNET_FS_uri_parse ("gnunet://ecrs/sks/D1KJS9H2A82Q65VKQ0ML3RFU6U1D3V/test", &emsg)) |
151 | "gnunet://ecrs/sks/D1KJS9H2A82Q65VKQ0ML3RFU6U1D3V/test")) | ||
152 | ABORT (); | 157 | ABORT (); |
153 | if (NULL != GNUNET_ECRS_string_to_uri (NULL, "gnunet://ecrs/sks/test")) | 158 | if (NULL != GNUNET_FS_uri_parse ("gnunet://ecrs/sks/test", &emsg)) |
154 | ABORT (); | 159 | ABORT (); |
155 | ret = | 160 | ret = |
156 | GNUNET_ECRS_string_to_uri (NULL, | 161 | GNUNET_FS_uri_parse ("gnunet://ecrs/sks/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820/test", &emsg); |
157 | "gnunet://ecrs/sks/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820/test"); | ||
158 | if (ret == NULL) | 162 | if (ret == NULL) |
159 | ABORT (); | 163 | ABORT (); |
160 | if (GNUNET_ECRS_uri_test_ksk (ret)) | 164 | if (GNUNET_FS_uri_test_ksk (ret)) |
161 | { | 165 | { |
162 | GNUNET_ECRS_uri_destroy (ret); | 166 | GNUNET_FS_uri_destroy (ret); |
163 | ABORT (); | 167 | ABORT (); |
164 | } | 168 | } |
165 | if (!GNUNET_ECRS_uri_test_sks (ret)) | 169 | if (!GNUNET_FS_uri_test_sks (ret)) |
166 | { | 170 | { |
167 | GNUNET_ECRS_uri_destroy (ret); | 171 | GNUNET_FS_uri_destroy (ret); |
168 | ABORT (); | 172 | ABORT (); |
169 | } | 173 | } |
170 | 174 | ||
171 | uri = GNUNET_ECRS_uri_to_string (ret); | 175 | uri = GNUNET_FS_uri_to_string (ret); |
172 | if (0 != strcmp (uri, | 176 | if (0 != strcmp (uri, |
173 | "gnunet://ecrs/sks/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820/test")) | 177 | "gnunet://ecrs/sks/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820/test")) |
174 | { | 178 | { |
175 | GNUNET_ECRS_uri_destroy (ret); | 179 | GNUNET_FS_uri_destroy (ret); |
176 | GNUNET_free (uri); | 180 | GNUNET_free (uri); |
177 | ABORT (); | 181 | ABORT (); |
178 | } | 182 | } |
179 | GNUNET_free (uri); | 183 | GNUNET_free (uri); |
180 | GNUNET_ECRS_uri_destroy (ret); | 184 | GNUNET_FS_uri_destroy (ret); |
181 | return 0; | 185 | return 0; |
182 | } | 186 | } |
183 | 187 | ||
@@ -185,51 +189,51 @@ static int | |||
185 | testFile (int i) | 189 | testFile (int i) |
186 | { | 190 | { |
187 | char *uri; | 191 | char *uri; |
188 | struct GNUNET_ECRS_URI *ret; | 192 | struct GNUNET_FS_Uri *ret; |
193 | char *emsg; | ||
189 | 194 | ||
190 | if (NULL != | 195 | if (NULL != |
191 | GNUNET_ECRS_string_to_uri (NULL, | 196 | GNUNET_FS_uri_parse ("gnunet://ecrs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H00000440000.42", &emsg)) |
192 | "gnunet://ecrs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H00000440000.42")) | ||
193 | ABORT (); | 197 | ABORT (); |
198 | GNUNET_free (emsg); | ||
194 | if (NULL != | 199 | if (NULL != |
195 | GNUNET_ECRS_string_to_uri (NULL, | 200 | GNUNET_FS_uri_parse ("gnunet://ecrs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000", &emsg)) |
196 | "gnunet://ecrs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000")) | ||
197 | ABORT (); | 201 | ABORT (); |
202 | GNUNET_free (emsg); | ||
198 | if (NULL != | 203 | if (NULL != |
199 | GNUNET_ECRS_string_to_uri (NULL, | 204 | GNUNET_FS_uri_parse ("gnunet://ecrs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.FGH", &emsg)) |
200 | "gnunet://ecrs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.FGH")) | ||
201 | ABORT (); | 205 | ABORT (); |
206 | GNUNET_free (emsg); | ||
202 | ret = | 207 | ret = |
203 | GNUNET_ECRS_string_to_uri (NULL, | 208 | GNUNET_FS_uri_parse ("gnunet://ecrs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.42", &emsg); |
204 | "gnunet://ecrs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.42"); | ||
205 | if (ret == NULL) | 209 | if (ret == NULL) |
206 | ABORT (); | 210 | ABORT (); |
207 | if (GNUNET_ECRS_uri_test_ksk (ret)) | 211 | if (GNUNET_FS_uri_test_ksk (ret)) |
208 | { | 212 | { |
209 | GNUNET_ECRS_uri_destroy (ret); | 213 | GNUNET_FS_uri_destroy (ret); |
210 | ABORT (); | 214 | ABORT (); |
211 | } | 215 | } |
212 | if (GNUNET_ECRS_uri_test_sks (ret)) | 216 | if (GNUNET_FS_uri_test_sks (ret)) |
213 | { | 217 | { |
214 | GNUNET_ECRS_uri_destroy (ret); | 218 | GNUNET_FS_uri_destroy (ret); |
215 | ABORT (); | 219 | ABORT (); |
216 | } | 220 | } |
217 | if (GNUNET_ntohll (ret->data.fi.file_length) != 42) | 221 | if (GNUNET_ntohll (ret->data.chk.file_length) != 42) |
218 | { | 222 | { |
219 | GNUNET_ECRS_uri_destroy (ret); | 223 | GNUNET_FS_uri_destroy (ret); |
220 | ABORT (); | 224 | ABORT (); |
221 | } | 225 | } |
222 | 226 | ||
223 | uri = GNUNET_ECRS_uri_to_string (ret); | 227 | uri = GNUNET_FS_uri_to_string (ret); |
224 | if (0 != strcmp (uri, | 228 | if (0 != strcmp (uri, |
225 | "gnunet://ecrs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.42")) | 229 | "gnunet://ecrs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.42")) |
226 | { | 230 | { |
227 | GNUNET_free (uri); | 231 | GNUNET_free (uri); |
228 | GNUNET_ECRS_uri_destroy (ret); | 232 | GNUNET_FS_uri_destroy (ret); |
229 | ABORT (); | 233 | ABORT (); |
230 | } | 234 | } |
231 | GNUNET_free (uri); | 235 | GNUNET_free (uri); |
232 | GNUNET_ECRS_uri_destroy (ret); | 236 | GNUNET_FS_uri_destroy (ret); |
233 | return 0; | 237 | return 0; |
234 | } | 238 | } |
235 | 239 | ||
@@ -239,7 +243,7 @@ main (int argc, char *argv[]) | |||
239 | int failureCount = 0; | 243 | int failureCount = 0; |
240 | int i; | 244 | int i; |
241 | 245 | ||
242 | GNUNET_disable_entropy_gathering (); | 246 | GNUNET_CRYPTO_random_disable_entropy_gathering (); |
243 | failureCount += testKeyword (); | 247 | failureCount += testKeyword (); |
244 | failureCount += testLocation (); | 248 | failureCount += testLocation (); |
245 | for (i = 0; i < 255; i++) | 249 | for (i = 0; i < 255; i++) |
@@ -252,4 +256,4 @@ main (int argc, char *argv[]) | |||
252 | return 0; | 256 | return 0; |
253 | } | 257 | } |
254 | 258 | ||
255 | /* end of uritest.c */ | 259 | /* end of test_fs_uri.c */ |
diff --git a/src/fs/test_fs_uri_data.conf b/src/fs/test_fs_uri_data.conf new file mode 100644 index 000000000..12cf53b93 --- /dev/null +++ b/src/fs/test_fs_uri_data.conf | |||
@@ -0,0 +1,9 @@ | |||
1 | [PATHS] | ||
2 | SERVICEHOME = /tmp/gnunet-test-fs-uri/ | ||
3 | DEFAULTCONFIG = /etc/gnunetd.conf | ||
4 | |||
5 | [gnunetd] | ||
6 | HOSTKEY = $SERVICEHOME/.hostkey | ||
7 | |||
8 | [TESTING] | ||
9 | WEAKRANDOM = YES | ||