diff options
Diffstat (limited to 'src/fs/test_fs_unindex.c')
-rw-r--r-- | src/fs/test_fs_unindex.c | 265 |
1 files changed, 131 insertions, 134 deletions
diff --git a/src/fs/test_fs_unindex.c b/src/fs/test_fs_unindex.c index 6774d0dfa..70a9e0bcf 100644 --- a/src/fs/test_fs_unindex.c +++ b/src/fs/test_fs_unindex.c | |||
@@ -45,7 +45,7 @@ | |||
45 | 45 | ||
46 | /** | 46 | /** |
47 | * How long should our test-content live? | 47 | * How long should our test-content live? |
48 | */ | 48 | */ |
49 | #define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) | 49 | #define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) |
50 | 50 | ||
51 | struct PeerContext | 51 | struct PeerContext |
@@ -70,8 +70,7 @@ static char *fn; | |||
70 | 70 | ||
71 | 71 | ||
72 | static void | 72 | static void |
73 | abort_publish_task (void *cls, | 73 | abort_publish_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
74 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
75 | { | 74 | { |
76 | GNUNET_FS_publish_stop (publish); | 75 | GNUNET_FS_publish_stop (publish); |
77 | publish = NULL; | 76 | publish = NULL; |
@@ -79,8 +78,7 @@ abort_publish_task (void *cls, | |||
79 | 78 | ||
80 | 79 | ||
81 | static void | 80 | static void |
82 | abort_unindex_task (void *cls, | 81 | abort_unindex_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
83 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
84 | { | 82 | { |
85 | GNUNET_FS_unindex_stop (unindex); | 83 | GNUNET_FS_unindex_stop (unindex); |
86 | unindex = NULL; | 84 | unindex = NULL; |
@@ -91,96 +89,99 @@ abort_unindex_task (void *cls, | |||
91 | 89 | ||
92 | 90 | ||
93 | static void * | 91 | static void * |
94 | progress_cb (void *cls, | 92 | progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) |
95 | const struct GNUNET_FS_ProgressInfo *event) | ||
96 | { | 93 | { |
97 | 94 | ||
98 | switch (event->status) | 95 | switch (event->status) |
99 | { | 96 | { |
100 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: | 97 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: |
101 | #if VERBOSE | 98 | #if VERBOSE |
102 | printf ("Publish is progressing (%llu/%llu at level %u off %llu)...\n", | 99 | printf ("Publish is progressing (%llu/%llu at level %u off %llu)...\n", |
103 | (unsigned long long) event->value.publish.completed, | 100 | (unsigned long long) event->value.publish.completed, |
104 | (unsigned long long) event->value.publish.size, | 101 | (unsigned long long) event->value.publish.size, |
105 | event->value.publish.specifics.progress.depth, | 102 | event->value.publish.specifics.progress.depth, |
106 | (unsigned long long) event->value.publish.specifics.progress.offset); | 103 | (unsigned long long) event->value.publish.specifics. |
107 | #endif | 104 | progress.offset); |
108 | break; | 105 | #endif |
109 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: | 106 | break; |
110 | printf ("Publishing complete, %llu kbps.\n", | 107 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: |
111 | (unsigned long long) (FILESIZE * 1000 / (1+GNUNET_TIME_absolute_get_duration (start).rel_value) / 1024)); | 108 | printf ("Publishing complete, %llu kbps.\n", |
112 | start = GNUNET_TIME_absolute_get (); | 109 | (unsigned long long) (FILESIZE * 1000 / |
113 | unindex = GNUNET_FS_unindex_start (fs, | 110 | (1 + |
114 | fn, | 111 | GNUNET_TIME_absolute_get_duration |
115 | "unindex"); | 112 | (start).rel_value) / 1024)); |
116 | GNUNET_assert (unindex != NULL); | 113 | start = GNUNET_TIME_absolute_get (); |
117 | break; | 114 | unindex = GNUNET_FS_unindex_start (fs, fn, "unindex"); |
118 | case GNUNET_FS_STATUS_UNINDEX_COMPLETED: | 115 | GNUNET_assert (unindex != NULL); |
119 | printf ("Unindex complete, %llu kbps.\n", | 116 | break; |
120 | (unsigned long long) (FILESIZE * 1000 / (1+GNUNET_TIME_absolute_get_duration (start).rel_value) / 1024)); | 117 | case GNUNET_FS_STATUS_UNINDEX_COMPLETED: |
121 | GNUNET_SCHEDULER_add_continuation (&abort_unindex_task, | 118 | printf ("Unindex complete, %llu kbps.\n", |
122 | NULL, | 119 | (unsigned long long) (FILESIZE * 1000 / |
123 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | 120 | (1 + |
124 | break; | 121 | GNUNET_TIME_absolute_get_duration |
125 | case GNUNET_FS_STATUS_UNINDEX_PROGRESS: | 122 | (start).rel_value) / 1024)); |
126 | GNUNET_assert (unindex == event->value.unindex.uc); | 123 | GNUNET_SCHEDULER_add_continuation (&abort_unindex_task, NULL, |
124 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | ||
125 | break; | ||
126 | case GNUNET_FS_STATUS_UNINDEX_PROGRESS: | ||
127 | GNUNET_assert (unindex == event->value.unindex.uc); | ||
127 | #if VERBOSE | 128 | #if VERBOSE |
128 | printf ("Unindex is progressing (%llu/%llu at level %u off %llu)...\n", | 129 | printf ("Unindex is progressing (%llu/%llu at level %u off %llu)...\n", |
129 | (unsigned long long) event->value.unindex.completed, | 130 | (unsigned long long) event->value.unindex.completed, |
130 | (unsigned long long) event->value.unindex.size, | 131 | (unsigned long long) event->value.unindex.size, |
131 | event->value.unindex.specifics.progress.depth, | 132 | event->value.unindex.specifics.progress.depth, |
132 | (unsigned long long) event->value.unindex.specifics.progress.offset); | 133 | (unsigned long long) event->value.unindex.specifics. |
134 | progress.offset); | ||
133 | #endif | 135 | #endif |
134 | break; | 136 | break; |
135 | case GNUNET_FS_STATUS_PUBLISH_ERROR: | 137 | case GNUNET_FS_STATUS_PUBLISH_ERROR: |
136 | fprintf (stderr, | 138 | fprintf (stderr, |
137 | "Error publishing file: %s\n", | 139 | "Error publishing file: %s\n", |
138 | event->value.publish.specifics.error.message); | 140 | event->value.publish.specifics.error.message); |
139 | GNUNET_break (0); | 141 | GNUNET_break (0); |
140 | GNUNET_SCHEDULER_add_continuation (&abort_publish_task, | 142 | GNUNET_SCHEDULER_add_continuation (&abort_publish_task, |
141 | NULL, | 143 | NULL, |
142 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | 144 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); |
143 | break; | 145 | break; |
144 | case GNUNET_FS_STATUS_UNINDEX_ERROR: | 146 | case GNUNET_FS_STATUS_UNINDEX_ERROR: |
145 | fprintf (stderr, | 147 | fprintf (stderr, |
146 | "Error unindexing file: %s\n", | 148 | "Error unindexing file: %s\n", |
147 | event->value.unindex.specifics.error.message); | 149 | event->value.unindex.specifics.error.message); |
148 | GNUNET_SCHEDULER_add_continuation (&abort_unindex_task, | 150 | GNUNET_SCHEDULER_add_continuation (&abort_unindex_task, |
149 | NULL, | 151 | NULL, |
150 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | 152 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); |
151 | break; | 153 | break; |
152 | case GNUNET_FS_STATUS_PUBLISH_START: | 154 | case GNUNET_FS_STATUS_PUBLISH_START: |
153 | GNUNET_assert (0 == strcmp ("publish-context", event->value.publish.cctx)); | 155 | GNUNET_assert (0 == strcmp ("publish-context", event->value.publish.cctx)); |
154 | GNUNET_assert (NULL == event->value.publish.pctx); | 156 | GNUNET_assert (NULL == event->value.publish.pctx); |
155 | GNUNET_assert (FILESIZE == event->value.publish.size); | 157 | GNUNET_assert (FILESIZE == event->value.publish.size); |
156 | GNUNET_assert (0 == event->value.publish.completed); | 158 | GNUNET_assert (0 == event->value.publish.completed); |
157 | GNUNET_assert (1 == event->value.publish.anonymity); | 159 | GNUNET_assert (1 == event->value.publish.anonymity); |
158 | break; | 160 | break; |
159 | case GNUNET_FS_STATUS_PUBLISH_STOPPED: | 161 | case GNUNET_FS_STATUS_PUBLISH_STOPPED: |
160 | GNUNET_assert (publish == event->value.publish.pc); | 162 | GNUNET_assert (publish == event->value.publish.pc); |
161 | GNUNET_assert (FILESIZE == event->value.publish.size); | 163 | GNUNET_assert (FILESIZE == event->value.publish.size); |
162 | GNUNET_assert (1 == event->value.publish.anonymity); | 164 | GNUNET_assert (1 == event->value.publish.anonymity); |
163 | GNUNET_FS_stop (fs); | 165 | GNUNET_FS_stop (fs); |
164 | fs = NULL; | 166 | fs = NULL; |
165 | break; | 167 | break; |
166 | case GNUNET_FS_STATUS_UNINDEX_START: | 168 | case GNUNET_FS_STATUS_UNINDEX_START: |
167 | GNUNET_assert (unindex == NULL); | 169 | GNUNET_assert (unindex == NULL); |
168 | GNUNET_assert (0 == strcmp ("unindex", event->value.unindex.cctx)); | 170 | GNUNET_assert (0 == strcmp ("unindex", event->value.unindex.cctx)); |
169 | GNUNET_assert (0 == strcmp (fn, event->value.unindex.filename)); | 171 | GNUNET_assert (0 == strcmp (fn, event->value.unindex.filename)); |
170 | GNUNET_assert (FILESIZE == event->value.unindex.size); | 172 | GNUNET_assert (FILESIZE == event->value.unindex.size); |
171 | GNUNET_assert (0 == event->value.unindex.completed); | 173 | GNUNET_assert (0 == event->value.unindex.completed); |
172 | break; | 174 | break; |
173 | case GNUNET_FS_STATUS_UNINDEX_STOPPED: | 175 | case GNUNET_FS_STATUS_UNINDEX_STOPPED: |
174 | GNUNET_assert (unindex == event->value.unindex.uc); | 176 | GNUNET_assert (unindex == event->value.unindex.uc); |
175 | GNUNET_SCHEDULER_add_continuation (&abort_publish_task, | 177 | GNUNET_SCHEDULER_add_continuation (&abort_publish_task, |
176 | NULL, | 178 | NULL, |
177 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | 179 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); |
178 | break; | 180 | break; |
179 | default: | 181 | default: |
180 | printf ("Unexpected event: %d\n", | 182 | printf ("Unexpected event: %d\n", event->status); |
181 | event->status); | 183 | break; |
182 | break; | 184 | } |
183 | } | ||
184 | return NULL; | 185 | return NULL; |
185 | } | 186 | } |
186 | 187 | ||
@@ -191,11 +192,11 @@ setup_peer (struct PeerContext *p, const char *cfgname) | |||
191 | p->cfg = GNUNET_CONFIGURATION_create (); | 192 | p->cfg = GNUNET_CONFIGURATION_create (); |
192 | #if START_ARM | 193 | #if START_ARM |
193 | p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", | 194 | p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", |
194 | "gnunet-service-arm", | 195 | "gnunet-service-arm", |
195 | #if VERBOSE | 196 | #if VERBOSE |
196 | "-L", "DEBUG", | 197 | "-L", "DEBUG", |
197 | #endif | 198 | #endif |
198 | "-c", cfgname, NULL); | 199 | "-c", cfgname, NULL); |
199 | #endif | 200 | #endif |
200 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); | 201 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); |
201 | } | 202 | } |
@@ -206,16 +207,17 @@ stop_arm (struct PeerContext *p) | |||
206 | { | 207 | { |
207 | #if START_ARM | 208 | #if START_ARM |
208 | if (NULL != p->arm_proc) | 209 | if (NULL != p->arm_proc) |
209 | { | 210 | { |
210 | if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) | 211 | if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) |
211 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | 212 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); |
212 | if (GNUNET_OS_process_wait(p->arm_proc) != GNUNET_OK) | 213 | if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK) |
213 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); | 214 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); |
214 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 215 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
215 | "ARM process %u stopped\n", GNUNET_OS_process_get_pid (p->arm_proc)); | 216 | "ARM process %u stopped\n", |
216 | GNUNET_OS_process_close (p->arm_proc); | 217 | GNUNET_OS_process_get_pid (p->arm_proc)); |
217 | p->arm_proc = NULL; | 218 | GNUNET_OS_process_close (p->arm_proc); |
218 | } | 219 | p->arm_proc = NULL; |
220 | } | ||
219 | #endif | 221 | #endif |
220 | GNUNET_CONFIGURATION_destroy (p->cfg); | 222 | GNUNET_CONFIGURATION_destroy (p->cfg); |
221 | } | 223 | } |
@@ -224,8 +226,7 @@ stop_arm (struct PeerContext *p) | |||
224 | static void | 226 | static void |
225 | run (void *cls, | 227 | run (void *cls, |
226 | char *const *args, | 228 | char *const *args, |
227 | const char *cfgfile, | 229 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) |
228 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
229 | { | 230 | { |
230 | const char *keywords[] = { | 231 | const char *keywords[] = { |
231 | "down_foo", | 232 | "down_foo", |
@@ -241,20 +242,19 @@ run (void *cls, | |||
241 | setup_peer (&p1, "test_fs_unindex_data.conf"); | 242 | setup_peer (&p1, "test_fs_unindex_data.conf"); |
242 | fn = GNUNET_DISK_mktemp ("gnunet-unindex-test-dst"); | 243 | fn = GNUNET_DISK_mktemp ("gnunet-unindex-test-dst"); |
243 | fs = GNUNET_FS_start (cfg, | 244 | fs = GNUNET_FS_start (cfg, |
244 | "test-fs-unindex", | 245 | "test-fs-unindex", |
245 | &progress_cb, | 246 | &progress_cb, |
246 | NULL, | 247 | NULL, GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); |
247 | GNUNET_FS_FLAGS_NONE, | 248 | GNUNET_assert (NULL != fs); |
248 | GNUNET_FS_OPTIONS_END); | ||
249 | GNUNET_assert (NULL != fs); | ||
250 | buf = GNUNET_malloc (FILESIZE); | 249 | buf = GNUNET_malloc (FILESIZE); |
251 | for (i = 0; i < FILESIZE; i++) | 250 | for (i = 0; i < FILESIZE; i++) |
252 | buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); | 251 | buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); |
253 | GNUNET_assert (FILESIZE == | 252 | GNUNET_assert (FILESIZE == |
254 | GNUNET_DISK_fn_write (fn, | 253 | GNUNET_DISK_fn_write (fn, |
255 | buf, | 254 | buf, |
256 | FILESIZE, | 255 | FILESIZE, |
257 | GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE)); | 256 | GNUNET_DISK_PERM_USER_READ | |
257 | GNUNET_DISK_PERM_USER_WRITE)); | ||
258 | GNUNET_free (buf); | 258 | GNUNET_free (buf); |
259 | meta = GNUNET_CONTAINER_meta_data_create (); | 259 | meta = GNUNET_CONTAINER_meta_data_create (); |
260 | kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords); | 260 | kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords); |
@@ -263,20 +263,18 @@ run (void *cls, | |||
263 | bo.replication_level = 0; | 263 | bo.replication_level = 0; |
264 | bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME); | 264 | bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME); |
265 | fi = GNUNET_FS_file_information_create_from_file (fs, | 265 | fi = GNUNET_FS_file_information_create_from_file (fs, |
266 | "publish-context", | 266 | "publish-context", |
267 | fn, | 267 | fn, |
268 | kuri, | 268 | kuri, |
269 | meta, | 269 | meta, GNUNET_YES, &bo); |
270 | GNUNET_YES, | ||
271 | &bo); | ||
272 | GNUNET_FS_uri_destroy (kuri); | 270 | GNUNET_FS_uri_destroy (kuri); |
273 | GNUNET_CONTAINER_meta_data_destroy (meta); | 271 | GNUNET_CONTAINER_meta_data_destroy (meta); |
274 | GNUNET_assert (NULL != fi); | 272 | GNUNET_assert (NULL != fi); |
275 | start = GNUNET_TIME_absolute_get (); | 273 | start = GNUNET_TIME_absolute_get (); |
276 | publish = GNUNET_FS_publish_start (fs, | 274 | publish = GNUNET_FS_publish_start (fs, |
277 | fi, | 275 | fi, |
278 | NULL, NULL, NULL, | 276 | NULL, NULL, NULL, |
279 | GNUNET_FS_PUBLISH_OPTION_NONE); | 277 | GNUNET_FS_PUBLISH_OPTION_NONE); |
280 | GNUNET_assert (publish != NULL); | 278 | GNUNET_assert (publish != NULL); |
281 | } | 279 | } |
282 | 280 | ||
@@ -284,7 +282,7 @@ run (void *cls, | |||
284 | int | 282 | int |
285 | main (int argc, char *argv[]) | 283 | main (int argc, char *argv[]) |
286 | { | 284 | { |
287 | char *const argvx[] = { | 285 | char *const argvx[] = { |
288 | "test-fs-unindex", | 286 | "test-fs-unindex", |
289 | "-c", | 287 | "-c", |
290 | "test_fs_unindex_data.conf", | 288 | "test_fs_unindex_data.conf", |
@@ -297,23 +295,22 @@ main (int argc, char *argv[]) | |||
297 | GNUNET_GETOPT_OPTION_END | 295 | GNUNET_GETOPT_OPTION_END |
298 | }; | 296 | }; |
299 | 297 | ||
300 | GNUNET_log_setup ("test_fs_unindex", | 298 | GNUNET_log_setup ("test_fs_unindex", |
301 | #if VERBOSE | 299 | #if VERBOSE |
302 | "DEBUG", | 300 | "DEBUG", |
303 | #else | 301 | #else |
304 | "WARNING", | 302 | "WARNING", |
305 | #endif | 303 | #endif |
306 | NULL); | 304 | NULL); |
307 | GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, | 305 | GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, |
308 | argvx, "test-fs-unindex", | 306 | argvx, "test-fs-unindex", "nohelp", options, &run, NULL); |
309 | "nohelp", options, &run, NULL); | ||
310 | stop_arm (&p1); | 307 | stop_arm (&p1); |
311 | GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-unindex/"); | 308 | GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-unindex/"); |
312 | if (NULL != fn) | 309 | if (NULL != fn) |
313 | { | 310 | { |
314 | GNUNET_DISK_directory_remove (fn); | 311 | GNUNET_DISK_directory_remove (fn); |
315 | GNUNET_free (fn); | 312 | GNUNET_free (fn); |
316 | } | 313 | } |
317 | return 0; | 314 | return 0; |
318 | } | 315 | } |
319 | 316 | ||