aboutsummaryrefslogtreecommitdiff
path: root/src/fs
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-08-15 21:46:35 +0000
committerChristian Grothoff <christian@grothoff.org>2011-08-15 21:46:35 +0000
commit502af2167f7c218366666ca4944bd7cc54b5b19a (patch)
treea91fec5cc9769d260640bd91c6633cb9cf395524 /src/fs
parent03af5a603b7cc53432249d5854cd412aa90dde0d (diff)
downloadgnunet-502af2167f7c218366666ca4944bd7cc54b5b19a.tar.gz
gnunet-502af2167f7c218366666ca4944bd7cc54b5b19a.zip
indentation
Diffstat (limited to 'src/fs')
-rw-r--r--src/fs/fs.c2804
-rw-r--r--src/fs/fs.h272
-rw-r--r--src/fs/fs_directory.c551
-rw-r--r--src/fs/fs_download.c2467
-rw-r--r--src/fs/fs_file_information.c503
-rw-r--r--src/fs/fs_getopt.c204
-rw-r--r--src/fs/fs_list_indexed.c146
-rw-r--r--src/fs/fs_misc.c99
-rw-r--r--src/fs/fs_namespace.c1063
-rw-r--r--src/fs/fs_publish.c1552
-rw-r--r--src/fs/fs_search.c1159
-rw-r--r--src/fs/fs_test_lib.c580
-rw-r--r--src/fs/fs_test_lib.h63
-rw-r--r--src/fs/fs_tree.c247
-rw-r--r--src/fs/fs_tree.h70
-rw-r--r--src/fs/fs_unindex.c437
-rw-r--r--src/fs/fs_uri.c1357
-rw-r--r--src/fs/gnunet-directory.c125
-rw-r--r--src/fs/gnunet-download.c235
-rw-r--r--src/fs/gnunet-pseudonym.c267
-rw-r--r--src/fs/gnunet-publish.c655
-rw-r--r--src/fs/gnunet-search.c269
-rw-r--r--src/fs/gnunet-service-fs.c255
-rw-r--r--src/fs/gnunet-service-fs.h6
-rw-r--r--src/fs/gnunet-service-fs_cp.c1373
-rw-r--r--src/fs/gnunet-service-fs_cp.h112
-rw-r--r--src/fs/gnunet-service-fs_indexing.c659
-rw-r--r--src/fs/gnunet-service-fs_indexing.h35
-rw-r--r--src/fs/gnunet-service-fs_lc.c306
-rw-r--r--src/fs/gnunet-service-fs_lc.h18
-rw-r--r--src/fs/gnunet-service-fs_pe.c374
-rw-r--r--src/fs/gnunet-service-fs_pe.h15
-rw-r--r--src/fs/gnunet-service-fs_pr.c1486
-rw-r--r--src/fs/gnunet-service-fs_pr.h141
-rw-r--r--src/fs/gnunet-service-fs_push.c385
-rw-r--r--src/fs/gnunet-service-fs_push.h12
-rw-r--r--src/fs/gnunet-service-fs_put.c149
-rw-r--r--src/fs/gnunet-service-fs_put.h6
-rw-r--r--src/fs/gnunet-unindex.c137
-rw-r--r--src/fs/perf_gnunet_service_fs_p2p.c284
-rw-r--r--src/fs/perf_gnunet_service_fs_p2p_trust.c347
-rw-r--r--src/fs/test_fs.c140
-rw-r--r--src/fs/test_fs_directory.c165
-rw-r--r--src/fs/test_fs_download.c335
-rw-r--r--src/fs/test_fs_download_indexed.c355
-rw-r--r--src/fs/test_fs_download_persistence.c408
-rw-r--r--src/fs/test_fs_download_recursive.c311
-rw-r--r--src/fs/test_fs_file_information.c138
-rw-r--r--src/fs/test_fs_getopt.c8
-rw-r--r--src/fs/test_fs_list_indexed.c280
-rw-r--r--src/fs/test_fs_namespace.c384
-rw-r--r--src/fs/test_fs_namespace_list_updateable.c142
-rw-r--r--src/fs/test_fs_publish.c274
-rw-r--r--src/fs/test_fs_publish_persistence.c324
-rw-r--r--src/fs/test_fs_search.c234
-rw-r--r--src/fs/test_fs_search_persistence.c300
-rw-r--r--src/fs/test_fs_search_ranking.c153
-rw-r--r--src/fs/test_fs_start_stop.c55
-rw-r--r--src/fs/test_fs_test_lib.c120
-rw-r--r--src/fs/test_fs_unindex.c265
-rw-r--r--src/fs/test_fs_unindex_persistence.c347
-rw-r--r--src/fs/test_fs_uri.c308
-rw-r--r--src/fs/test_gnunet_service_fs_migration.c178
-rw-r--r--src/fs/test_gnunet_service_fs_p2p.c128
64 files changed, 12336 insertions, 14241 deletions
diff --git a/src/fs/fs.c b/src/fs/fs.c
index 046c4dbb0..318b7088e 100644
--- a/src/fs/fs.c
+++ b/src/fs/fs.c
@@ -43,21 +43,18 @@ start_job (struct GNUNET_FS_QueueEntry *qe)
43 GNUNET_assert (NULL == qe->client); 43 GNUNET_assert (NULL == qe->client);
44 qe->client = GNUNET_CLIENT_connect ("fs", qe->h->cfg); 44 qe->client = GNUNET_CLIENT_connect ("fs", qe->h->cfg);
45 if (qe->client == NULL) 45 if (qe->client == NULL)
46 { 46 {
47 GNUNET_break (0); 47 GNUNET_break (0);
48 return; 48 return;
49 } 49 }
50 qe->start (qe->cls, qe->client); 50 qe->start (qe->cls, qe->client);
51 qe->start_times++; 51 qe->start_times++;
52 qe->h->active_blocks += qe->blocks; 52 qe->h->active_blocks += qe->blocks;
53 qe->start_time = GNUNET_TIME_absolute_get (); 53 qe->start_time = GNUNET_TIME_absolute_get ();
54 GNUNET_CONTAINER_DLL_remove (qe->h->pending_head, 54 GNUNET_CONTAINER_DLL_remove (qe->h->pending_head, qe->h->pending_tail, qe);
55 qe->h->pending_tail,
56 qe);
57 GNUNET_CONTAINER_DLL_insert_after (qe->h->running_head, 55 GNUNET_CONTAINER_DLL_insert_after (qe->h->running_head,
58 qe->h->running_tail, 56 qe->h->running_tail,
59 qe->h->running_tail, 57 qe->h->running_tail, qe);
60 qe);
61} 58}
62 59
63 60
@@ -75,14 +72,12 @@ stop_job (struct GNUNET_FS_QueueEntry *qe)
75 qe->h->active_downloads--; 72 qe->h->active_downloads--;
76 qe->h->active_blocks -= qe->blocks; 73 qe->h->active_blocks -= qe->blocks;
77 qe->run_time = GNUNET_TIME_relative_add (qe->run_time, 74 qe->run_time = GNUNET_TIME_relative_add (qe->run_time,
78 GNUNET_TIME_absolute_get_duration (qe->start_time)); 75 GNUNET_TIME_absolute_get_duration
79 GNUNET_CONTAINER_DLL_remove (qe->h->running_head, 76 (qe->start_time));
80 qe->h->running_tail, 77 GNUNET_CONTAINER_DLL_remove (qe->h->running_head, qe->h->running_tail, qe);
81 qe);
82 GNUNET_CONTAINER_DLL_insert_after (qe->h->pending_head, 78 GNUNET_CONTAINER_DLL_insert_after (qe->h->pending_head,
83 qe->h->pending_tail, 79 qe->h->pending_tail,
84 qe->h->pending_tail, 80 qe->h->pending_tail, qe);
85 qe);
86} 81}
87 82
88 83
@@ -94,8 +89,7 @@ stop_job (struct GNUNET_FS_QueueEntry *qe)
94 * @param tc scheduler context 89 * @param tc scheduler context
95 */ 90 */
96static void 91static void
97process_job_queue (void *cls, 92process_job_queue (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
98 const struct GNUNET_SCHEDULER_TaskContext *tc)
99{ 93{
100 struct GNUNET_FS_Handle *h = cls; 94 struct GNUNET_FS_Handle *h = cls;
101 struct GNUNET_FS_QueueEntry *qe; 95 struct GNUNET_FS_QueueEntry *qe;
@@ -108,40 +102,38 @@ process_job_queue (void *cls,
108 h->queue_job = GNUNET_SCHEDULER_NO_TASK; 102 h->queue_job = GNUNET_SCHEDULER_NO_TASK;
109 next = h->pending_head; 103 next = h->pending_head;
110 while (NULL != (qe = next)) 104 while (NULL != (qe = next))
105 {
106 next = qe->next;
107 if (h->running_head == NULL)
108 {
109 start_job (qe);
110 continue;
111 }
112 if ((qe->blocks + h->active_blocks <= h->max_parallel_requests) &&
113 (h->active_downloads + 1 <= h->max_parallel_downloads))
111 { 114 {
112 next = qe->next; 115 start_job (qe);
113 if (h->running_head == NULL) 116 continue;
114 {
115 start_job (qe);
116 continue;
117 }
118 if ( (qe->blocks + h->active_blocks <= h->max_parallel_requests) &&
119 (h->active_downloads + 1 <= h->max_parallel_downloads) )
120 {
121 start_job (qe);
122 continue;
123 }
124 } 117 }
118 }
125 if (h->pending_head == NULL) 119 if (h->pending_head == NULL)
126 return; /* no need to stop anything */ 120 return; /* no need to stop anything */
127 restart_at = GNUNET_TIME_UNIT_FOREVER_REL; 121 restart_at = GNUNET_TIME_UNIT_FOREVER_REL;
128 next = h->running_head; 122 next = h->running_head;
129 while (NULL != (qe = next)) 123 while (NULL != (qe = next))
130 { 124 {
131 next = qe->next; 125 next = qe->next;
132 run_time = GNUNET_TIME_relative_multiply (h->avg_block_latency, 126 run_time = GNUNET_TIME_relative_multiply (h->avg_block_latency,
133 qe->blocks * qe->start_times); 127 qe->blocks * qe->start_times);
134 end_time = GNUNET_TIME_absolute_add (qe->start_time, 128 end_time = GNUNET_TIME_absolute_add (qe->start_time, run_time);
135 run_time); 129 rst = GNUNET_TIME_absolute_get_remaining (end_time);
136 rst = GNUNET_TIME_absolute_get_remaining (end_time); 130 restart_at = GNUNET_TIME_relative_min (rst, restart_at);
137 restart_at = GNUNET_TIME_relative_min (rst, restart_at); 131 if (rst.rel_value > 0)
138 if (rst.rel_value > 0) 132 continue;
139 continue; 133 stop_job (qe);
140 stop_job (qe); 134 }
141 }
142 h->queue_job = GNUNET_SCHEDULER_add_delayed (restart_at, 135 h->queue_job = GNUNET_SCHEDULER_add_delayed (restart_at,
143 &process_job_queue, 136 &process_job_queue, h);
144 h);
145} 137}
146 138
147 139
@@ -157,10 +149,8 @@ process_job_queue (void *cls,
157 */ 149 */
158struct GNUNET_FS_QueueEntry * 150struct GNUNET_FS_QueueEntry *
159GNUNET_FS_queue_ (struct GNUNET_FS_Handle *h, 151GNUNET_FS_queue_ (struct GNUNET_FS_Handle *h,
160 GNUNET_FS_QueueStart start, 152 GNUNET_FS_QueueStart start,
161 GNUNET_FS_QueueStop stop, 153 GNUNET_FS_QueueStop stop, void *cls, unsigned int blocks)
162 void *cls,
163 unsigned int blocks)
164{ 154{
165 struct GNUNET_FS_QueueEntry *qe; 155 struct GNUNET_FS_QueueEntry *qe;
166 156
@@ -172,14 +162,10 @@ GNUNET_FS_queue_ (struct GNUNET_FS_Handle *h,
172 qe->queue_time = GNUNET_TIME_absolute_get (); 162 qe->queue_time = GNUNET_TIME_absolute_get ();
173 qe->blocks = blocks; 163 qe->blocks = blocks;
174 GNUNET_CONTAINER_DLL_insert_after (h->pending_head, 164 GNUNET_CONTAINER_DLL_insert_after (h->pending_head,
175 h->pending_tail, 165 h->pending_tail, h->pending_tail, qe);
176 h->pending_tail,
177 qe);
178 if (h->queue_job != GNUNET_SCHEDULER_NO_TASK) 166 if (h->queue_job != GNUNET_SCHEDULER_NO_TASK)
179 GNUNET_SCHEDULER_cancel (h->queue_job); 167 GNUNET_SCHEDULER_cancel (h->queue_job);
180 h->queue_job 168 h->queue_job = GNUNET_SCHEDULER_add_now (&process_job_queue, h);
181 = GNUNET_SCHEDULER_add_now (&process_job_queue,
182 h);
183 return qe; 169 return qe;
184} 170}
185 171
@@ -194,17 +180,13 @@ GNUNET_FS_dequeue_ (struct GNUNET_FS_QueueEntry *qh)
194 struct GNUNET_FS_Handle *h; 180 struct GNUNET_FS_Handle *h;
195 181
196 h = qh->h; 182 h = qh->h;
197 if (qh->client != NULL) 183 if (qh->client != NULL)
198 stop_job (qh); 184 stop_job (qh);
199 GNUNET_CONTAINER_DLL_remove (h->pending_head, 185 GNUNET_CONTAINER_DLL_remove (h->pending_head, h->pending_tail, qh);
200 h->pending_tail,
201 qh);
202 GNUNET_free (qh); 186 GNUNET_free (qh);
203 if (h->queue_job != GNUNET_SCHEDULER_NO_TASK) 187 if (h->queue_job != GNUNET_SCHEDULER_NO_TASK)
204 GNUNET_SCHEDULER_cancel (h->queue_job); 188 GNUNET_SCHEDULER_cancel (h->queue_job);
205 h->queue_job 189 h->queue_job = GNUNET_SCHEDULER_add_now (&process_job_queue, h);
206 = GNUNET_SCHEDULER_add_now (&process_job_queue,
207 h);
208} 190}
209 191
210 192
@@ -218,17 +200,14 @@ GNUNET_FS_dequeue_ (struct GNUNET_FS_QueueEntry *qh)
218 */ 200 */
219struct TopLevelActivity * 201struct TopLevelActivity *
220GNUNET_FS_make_top (struct GNUNET_FS_Handle *h, 202GNUNET_FS_make_top (struct GNUNET_FS_Handle *h,
221 SuspendSignalFunction ssf, 203 SuspendSignalFunction ssf, void *ssf_cls)
222 void *ssf_cls)
223{ 204{
224 struct TopLevelActivity *ret; 205 struct TopLevelActivity *ret;
225 206
226 ret = GNUNET_malloc (sizeof (struct TopLevelActivity)); 207 ret = GNUNET_malloc (sizeof (struct TopLevelActivity));
227 ret->ssf = ssf; 208 ret->ssf = ssf;
228 ret->ssf_cls = ssf_cls; 209 ret->ssf_cls = ssf_cls;
229 GNUNET_CONTAINER_DLL_insert (h->top_head, 210 GNUNET_CONTAINER_DLL_insert (h->top_head, h->top_tail, ret);
230 h->top_tail,
231 ret);
232 return ret; 211 return ret;
233} 212}
234 213
@@ -240,12 +219,9 @@ GNUNET_FS_make_top (struct GNUNET_FS_Handle *h,
240 * @param top top level activity entry 219 * @param top top level activity entry
241 */ 220 */
242void 221void
243GNUNET_FS_end_top (struct GNUNET_FS_Handle *h, 222GNUNET_FS_end_top (struct GNUNET_FS_Handle *h, struct TopLevelActivity *top)
244 struct TopLevelActivity *top)
245{ 223{
246 GNUNET_CONTAINER_DLL_remove (h->top_head, 224 GNUNET_CONTAINER_DLL_remove (h->top_head, h->top_tail, top);
247 h->top_tail,
248 top);
249 GNUNET_free (top); 225 GNUNET_free (top);
250} 226}
251 227
@@ -285,54 +261,49 @@ struct FileInfo
285 * @return number of bytes written, usually "max", 0 on error 261 * @return number of bytes written, usually "max", 0 on error
286 */ 262 */
287size_t 263size_t
288GNUNET_FS_data_reader_file_(void *cls, 264GNUNET_FS_data_reader_file_ (void *cls,
289 uint64_t offset, 265 uint64_t offset,
290 size_t max, 266 size_t max, void *buf, char **emsg)
291 void *buf,
292 char **emsg)
293{ 267{
294 struct FileInfo *fi = cls; 268 struct FileInfo *fi = cls;
295 ssize_t ret; 269 ssize_t ret;
296 270
297 if (max == 0) 271 if (max == 0)
298 { 272 {
299 if (fi->fd != NULL) 273 if (fi->fd != NULL)
300 GNUNET_DISK_file_close (fi->fd); 274 GNUNET_DISK_file_close (fi->fd);
301 GNUNET_free (fi->filename); 275 GNUNET_free (fi->filename);
302 GNUNET_free (fi); 276 GNUNET_free (fi);
303 return 0; 277 return 0;
304 } 278 }
305 if (fi->fd == NULL) 279 if (fi->fd == NULL)
306 { 280 {
307 fi->fd = GNUNET_DISK_file_open (fi->filename, 281 fi->fd = GNUNET_DISK_file_open (fi->filename,
308 GNUNET_DISK_OPEN_READ, 282 GNUNET_DISK_OPEN_READ,
309 GNUNET_DISK_PERM_NONE); 283 GNUNET_DISK_PERM_NONE);
310 if (fi->fd == NULL) 284 if (fi->fd == NULL)
311 { 285 {
312 GNUNET_asprintf (emsg, 286 GNUNET_asprintf (emsg,
313 _("Could not open file `%s': %s"), 287 _("Could not open file `%s': %s"),
314 fi->filename, 288 fi->filename, STRERROR (errno));
315 STRERROR (errno)); 289 return 0;
316 return 0;
317 }
318 } 290 }
291 }
319 GNUNET_DISK_file_seek (fi->fd, offset, GNUNET_DISK_SEEK_SET); 292 GNUNET_DISK_file_seek (fi->fd, offset, GNUNET_DISK_SEEK_SET);
320 ret = GNUNET_DISK_file_read (fi->fd, buf, max); 293 ret = GNUNET_DISK_file_read (fi->fd, buf, max);
321 if (ret == -1) 294 if (ret == -1)
322 { 295 {
323 GNUNET_asprintf (emsg, 296 GNUNET_asprintf (emsg,
324 _("Could not read file `%s': %s"), 297 _("Could not read file `%s': %s"),
325 fi->filename, 298 fi->filename, STRERROR (errno));
326 STRERROR (errno)); 299 return 0;
327 return 0; 300 }
328 }
329 if (ret != max) 301 if (ret != max)
330 { 302 {
331 GNUNET_asprintf (emsg, 303 GNUNET_asprintf (emsg,
332 _("Short read reading from file `%s'!"), 304 _("Short read reading from file `%s'!"), fi->filename);
333 fi->filename); 305 return 0;
334 return 0; 306 }
335 }
336 return max; 307 return max;
337} 308}
338 309
@@ -348,13 +319,13 @@ GNUNET_FS_make_file_reader_context_ (const char *filename)
348{ 319{
349 struct FileInfo *fi; 320 struct FileInfo *fi;
350 321
351 fi = GNUNET_malloc (sizeof(struct FileInfo)); 322 fi = GNUNET_malloc (sizeof (struct FileInfo));
352 fi->filename = GNUNET_STRINGS_filename_expand (filename); 323 fi->filename = GNUNET_STRINGS_filename_expand (filename);
353 if (fi->filename == NULL) 324 if (fi->filename == NULL)
354 { 325 {
355 GNUNET_free (fi); 326 GNUNET_free (fi);
356 return NULL; 327 return NULL;
357 } 328 }
358 return fi; 329 return fi;
359} 330}
360 331
@@ -376,19 +347,17 @@ GNUNET_FS_make_file_reader_context_ (const char *filename)
376 * @return number of bytes written, usually "max", 0 on error 347 * @return number of bytes written, usually "max", 0 on error
377 */ 348 */
378size_t 349size_t
379GNUNET_FS_data_reader_copy_ (void *cls, 350GNUNET_FS_data_reader_copy_ (void *cls,
380 uint64_t offset, 351 uint64_t offset,
381 size_t max, 352 size_t max, void *buf, char **emsg)
382 void *buf,
383 char **emsg)
384{ 353{
385 char *data = cls; 354 char *data = cls;
386 355
387 if (max == 0) 356 if (max == 0)
388 { 357 {
389 GNUNET_free_non_null (data); 358 GNUNET_free_non_null (data);
390 return 0; 359 return 0;
391 } 360 }
392 memcpy (buf, &data[offset], max); 361 memcpy (buf, &data[offset], max);
393 return max; 362 return max;
394} 363}
@@ -405,29 +374,23 @@ GNUNET_FS_data_reader_copy_ (void *cls,
405 */ 374 */
406static char * 375static char *
407get_serialization_file_name (struct GNUNET_FS_Handle *h, 376get_serialization_file_name (struct GNUNET_FS_Handle *h,
408 const char *ext, 377 const char *ext, const char *ent)
409 const char *ent)
410{ 378{
411 char *basename; 379 char *basename;
412 char *ret; 380 char *ret;
413 381
414 if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE)) 382 if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE))
415 return NULL; /* persistence not requested */ 383 return NULL; /* persistence not requested */
416 if (GNUNET_OK != 384 if (GNUNET_OK !=
417 GNUNET_CONFIGURATION_get_value_filename (h->cfg, 385 GNUNET_CONFIGURATION_get_value_filename (h->cfg,
418 "fs", 386 "fs", "STATE_DIR", &basename))
419 "STATE_DIR",
420 &basename))
421 return NULL; 387 return NULL;
422 GNUNET_asprintf (&ret, 388 GNUNET_asprintf (&ret,
423 "%s%s%s%s%s%s%s", 389 "%s%s%s%s%s%s%s",
424 basename, 390 basename,
425 DIR_SEPARATOR_STR, 391 DIR_SEPARATOR_STR,
426 h->client_name, 392 h->client_name,
427 DIR_SEPARATOR_STR, 393 DIR_SEPARATOR_STR, ext, DIR_SEPARATOR_STR, ent);
428 ext,
429 DIR_SEPARATOR_STR,
430 ent);
431 GNUNET_free (basename); 394 GNUNET_free (basename);
432 return ret; 395 return ret;
433} 396}
@@ -446,32 +409,25 @@ get_serialization_file_name (struct GNUNET_FS_Handle *h,
446 */ 409 */
447static char * 410static char *
448get_serialization_file_name_in_dir (struct GNUNET_FS_Handle *h, 411get_serialization_file_name_in_dir (struct GNUNET_FS_Handle *h,
449 const char *ext, 412 const char *ext,
450 const char *uni, 413 const char *uni, const char *ent)
451 const char *ent)
452{ 414{
453 char *basename; 415 char *basename;
454 char *ret; 416 char *ret;
455 417
456 if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE)) 418 if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE))
457 return NULL; /* persistence not requested */ 419 return NULL; /* persistence not requested */
458 if (GNUNET_OK != 420 if (GNUNET_OK !=
459 GNUNET_CONFIGURATION_get_value_filename (h->cfg, 421 GNUNET_CONFIGURATION_get_value_filename (h->cfg,
460 "fs", 422 "fs", "STATE_DIR", &basename))
461 "STATE_DIR",
462 &basename))
463 return NULL; 423 return NULL;
464 GNUNET_asprintf (&ret, 424 GNUNET_asprintf (&ret,
465 "%s%s%s%s%s%s%s.dir%s%s", 425 "%s%s%s%s%s%s%s.dir%s%s",
466 basename, 426 basename,
467 DIR_SEPARATOR_STR, 427 DIR_SEPARATOR_STR,
468 h->client_name, 428 h->client_name,
469 DIR_SEPARATOR_STR, 429 DIR_SEPARATOR_STR,
470 ext, 430 ext, DIR_SEPARATOR_STR, uni, DIR_SEPARATOR_STR, ent);
471 DIR_SEPARATOR_STR,
472 uni,
473 DIR_SEPARATOR_STR,
474 ent);
475 GNUNET_free (basename); 431 GNUNET_free (basename);
476 return ret; 432 return ret;
477} 433}
@@ -486,9 +442,7 @@ get_serialization_file_name_in_dir (struct GNUNET_FS_Handle *h,
486 * @return NULL on error 442 * @return NULL on error
487 */ 443 */
488static struct GNUNET_BIO_ReadHandle * 444static struct GNUNET_BIO_ReadHandle *
489get_read_handle (struct GNUNET_FS_Handle *h, 445get_read_handle (struct GNUNET_FS_Handle *h, const char *ext, const char *ent)
490 const char *ext,
491 const char *ent)
492{ 446{
493 char *fn; 447 char *fn;
494 struct GNUNET_BIO_ReadHandle *ret; 448 struct GNUNET_BIO_ReadHandle *ret;
@@ -511,18 +465,16 @@ get_read_handle (struct GNUNET_FS_Handle *h,
511 * @return NULL on error 465 * @return NULL on error
512 */ 466 */
513static struct GNUNET_BIO_WriteHandle * 467static struct GNUNET_BIO_WriteHandle *
514get_write_handle (struct GNUNET_FS_Handle *h, 468get_write_handle (struct GNUNET_FS_Handle *h, const char *ext, const char *ent)
515 const char *ext,
516 const char *ent)
517{ 469{
518 char *fn; 470 char *fn;
519 struct GNUNET_BIO_WriteHandle *ret; 471 struct GNUNET_BIO_WriteHandle *ret;
520 472
521 fn = get_serialization_file_name (h, ext, ent); 473 fn = get_serialization_file_name (h, ext, ent);
522 if (fn == NULL) 474 if (fn == NULL)
523 { 475 {
524 return NULL; 476 return NULL;
525 } 477 }
526 ret = GNUNET_BIO_write_open (fn); 478 ret = GNUNET_BIO_write_open (fn);
527 if (ret == NULL) 479 if (ret == NULL)
528 GNUNET_break (0); 480 GNUNET_break (0);
@@ -542,9 +494,7 @@ get_write_handle (struct GNUNET_FS_Handle *h,
542 */ 494 */
543static struct GNUNET_BIO_WriteHandle * 495static struct GNUNET_BIO_WriteHandle *
544get_write_handle_in_dir (struct GNUNET_FS_Handle *h, 496get_write_handle_in_dir (struct GNUNET_FS_Handle *h,
545 const char *ext, 497 const char *ext, const char *uni, const char *ent)
546 const char *uni,
547 const char *ent)
548{ 498{
549 char *fn; 499 char *fn;
550 struct GNUNET_BIO_WriteHandle *ret; 500 struct GNUNET_BIO_WriteHandle *ret;
@@ -567,26 +517,22 @@ get_write_handle_in_dir (struct GNUNET_FS_Handle *h,
567 */ 517 */
568void 518void
569GNUNET_FS_remove_sync_file_ (struct GNUNET_FS_Handle *h, 519GNUNET_FS_remove_sync_file_ (struct GNUNET_FS_Handle *h,
570 const char *ext, 520 const char *ext, const char *ent)
571 const char *ent)
572{ 521{
573 char *filename; 522 char *filename;
574 523
575 if ( (NULL == ent) || 524 if ((NULL == ent) || (0 == strlen (ent)))
576 (0 == strlen (ent)) ) 525 {
577 { 526 GNUNET_break (0);
578 GNUNET_break (0); 527 return;
579 return; 528 }
580 }
581 filename = get_serialization_file_name (h, ext, ent); 529 filename = get_serialization_file_name (h, ext, ent);
582 if (filename != NULL) 530 if (filename != NULL)
583 { 531 {
584 if (0 != UNLINK (filename)) 532 if (0 != UNLINK (filename))
585 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, 533 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", filename);
586 "unlink", 534 GNUNET_free (filename);
587 filename); 535 }
588 GNUNET_free (filename);
589 }
590} 536}
591 537
592 538
@@ -600,27 +546,22 @@ GNUNET_FS_remove_sync_file_ (struct GNUNET_FS_Handle *h,
600 */ 546 */
601static void 547static void
602remove_sync_file_in_dir (struct GNUNET_FS_Handle *h, 548remove_sync_file_in_dir (struct GNUNET_FS_Handle *h,
603 const char *ext, 549 const char *ext, const char *uni, const char *ent)
604 const char *uni,
605 const char *ent)
606{ 550{
607 char *filename; 551 char *filename;
608 552
609 if ( (NULL == ent) || 553 if ((NULL == ent) || (0 == strlen (ent)))
610 (0 == strlen (ent)) ) 554 {
611 { 555 GNUNET_break (0);
612 GNUNET_break (0); 556 return;
613 return; 557 }
614 }
615 filename = get_serialization_file_name_in_dir (h, ext, uni, ent); 558 filename = get_serialization_file_name_in_dir (h, ext, uni, ent);
616 if (filename != NULL) 559 if (filename != NULL)
617 { 560 {
618 if (0 != UNLINK (filename)) 561 if (0 != UNLINK (filename))
619 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, 562 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", filename);
620 "unlink", 563 GNUNET_free (filename);
621 filename); 564 }
622 GNUNET_free (filename);
623 }
624} 565}
625 566
626 567
@@ -633,8 +574,7 @@ remove_sync_file_in_dir (struct GNUNET_FS_Handle *h,
633 */ 574 */
634void 575void
635GNUNET_FS_remove_sync_dir_ (struct GNUNET_FS_Handle *h, 576GNUNET_FS_remove_sync_dir_ (struct GNUNET_FS_Handle *h,
636 const char *ext, 577 const char *ext, const char *uni)
637 const char *uni)
638{ 578{
639 char *dn; 579 char *dn;
640 580
@@ -643,11 +583,9 @@ GNUNET_FS_remove_sync_dir_ (struct GNUNET_FS_Handle *h,
643 dn = get_serialization_file_name_in_dir (h, ext, uni, ""); 583 dn = get_serialization_file_name_in_dir (h, ext, uni, "");
644 if (dn == NULL) 584 if (dn == NULL)
645 return; 585 return;
646 if ( (GNUNET_OK == GNUNET_DISK_directory_test (dn)) && 586 if ((GNUNET_OK == GNUNET_DISK_directory_test (dn)) &&
647 (GNUNET_OK != GNUNET_DISK_directory_remove (dn)) ) 587 (GNUNET_OK != GNUNET_DISK_directory_remove (dn)))
648 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, 588 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "rmdir", dn);
649 "rmdir",
650 dn);
651 GNUNET_free (dn); 589 GNUNET_free (dn);
652} 590}
653 591
@@ -668,7 +606,7 @@ GNUNET_FS_remove_sync_dir_ (struct GNUNET_FS_Handle *h,
668 */ 606 */
669static int 607static int
670write_start_time (struct GNUNET_BIO_WriteHandle *wh, 608write_start_time (struct GNUNET_BIO_WriteHandle *wh,
671 struct GNUNET_TIME_Absolute timestamp) 609 struct GNUNET_TIME_Absolute timestamp)
672{ 610{
673 struct GNUNET_TIME_Relative dur; 611 struct GNUNET_TIME_Relative dur;
674 612
@@ -693,14 +631,13 @@ write_start_time (struct GNUNET_BIO_WriteHandle *wh,
693 */ 631 */
694static int 632static int
695read_start_time (struct GNUNET_BIO_ReadHandle *rh, 633read_start_time (struct GNUNET_BIO_ReadHandle *rh,
696 struct GNUNET_TIME_Absolute *timestamp) 634 struct GNUNET_TIME_Absolute *timestamp)
697{ 635{
698 struct GNUNET_TIME_Relative dur; 636 struct GNUNET_TIME_Relative dur;
699 if (GNUNET_OK != 637
700 GNUNET_BIO_read_int64 (rh, &dur.rel_value)) 638 if (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dur.rel_value))
701 return GNUNET_SYSERR; 639 return GNUNET_SYSERR;
702 *timestamp = GNUNET_TIME_absolute_subtract (GNUNET_TIME_absolute_get (), 640 *timestamp = GNUNET_TIME_absolute_subtract (GNUNET_TIME_absolute_get (), dur);
703 dur);
704 return GNUNET_OK; 641 return GNUNET_OK;
705} 642}
706 643
@@ -714,9 +651,12 @@ read_start_time (struct GNUNET_BIO_ReadHandle *rh,
714 * the infromation 651 * the infromation
715 * @return NULL on error 652 * @return NULL on error
716 */ 653 */
717static struct GNUNET_FS_FileInformation * 654static struct GNUNET_FS_FileInformation *deserialize_file_information (struct
718deserialize_file_information (struct GNUNET_FS_Handle *h, 655 GNUNET_FS_Handle
719 const char *filename); 656 *h,
657 const
658 char
659 *filename);
720 660
721 661
722/** 662/**
@@ -731,8 +671,7 @@ deserialize_file_information (struct GNUNET_FS_Handle *h,
731 */ 671 */
732static struct GNUNET_FS_FileInformation * 672static struct GNUNET_FS_FileInformation *
733deserialize_fi_node (struct GNUNET_FS_Handle *h, 673deserialize_fi_node (struct GNUNET_FS_Handle *h,
734 const char *fn, 674 const char *fn, struct GNUNET_BIO_ReadHandle *rh)
735 struct GNUNET_BIO_ReadHandle *rh)
736{ 675{
737 struct GNUNET_FS_FileInformation *ret; 676 struct GNUNET_FS_FileInformation *ret;
738 struct GNUNET_FS_FileInformation *nxt; 677 struct GNUNET_FS_FileInformation *nxt;
@@ -742,195 +681,199 @@ deserialize_fi_node (struct GNUNET_FS_Handle *h,
742 char *filename; 681 char *filename;
743 uint32_t dsize; 682 uint32_t dsize;
744 683
745 if (GNUNET_OK != 684 if (GNUNET_OK != GNUNET_BIO_read (rh, "status flag", &b, sizeof (b)))
746 GNUNET_BIO_read (rh, "status flag", &b, sizeof(b))) 685 {
747 { 686 GNUNET_break (0);
748 GNUNET_break (0); 687 return NULL;
749 return NULL; 688 }
750 }
751 ret = GNUNET_malloc (sizeof (struct GNUNET_FS_FileInformation)); 689 ret = GNUNET_malloc (sizeof (struct GNUNET_FS_FileInformation));
752 ret->h = h; 690 ret->h = h;
753 ksks = NULL; 691 ksks = NULL;
754 chks = NULL; 692 chks = NULL;
755 filename = NULL; 693 filename = NULL;
756 if ( (GNUNET_OK != 694 if ((GNUNET_OK !=
757 GNUNET_BIO_read_meta_data (rh, "metadata", &ret->meta)) || 695 GNUNET_BIO_read_meta_data (rh, "metadata", &ret->meta)) ||
758 (GNUNET_OK != 696 (GNUNET_OK !=
759 GNUNET_BIO_read_string (rh, "ksk-uri", &ksks, 32*1024)) || 697 GNUNET_BIO_read_string (rh, "ksk-uri", &ksks, 32 * 1024)) ||
760 ( (ksks != NULL) && 698 ((ksks != NULL) &&
761 (NULL == 699 (NULL ==
762 (ret->keywords = GNUNET_FS_uri_parse (ksks, NULL))) ) || 700 (ret->keywords = GNUNET_FS_uri_parse (ksks, NULL)))) ||
763 (GNUNET_YES != 701 (GNUNET_YES !=
764 GNUNET_FS_uri_test_ksk (ret->keywords)) || 702 GNUNET_FS_uri_test_ksk (ret->keywords)) ||
765 (GNUNET_OK != 703 (GNUNET_OK !=
766 GNUNET_BIO_read_string (rh, "chk-uri", &chks, 1024)) || 704 GNUNET_BIO_read_string (rh, "chk-uri", &chks, 1024)) ||
767 ( (chks != NULL) && 705 ((chks != NULL) &&
768 ( (NULL == 706 ((NULL ==
769 (ret->chk_uri = GNUNET_FS_uri_parse (chks, NULL))) || 707 (ret->chk_uri = GNUNET_FS_uri_parse (chks, NULL))) ||
770 (GNUNET_YES != 708 (GNUNET_YES !=
771 GNUNET_FS_uri_test_chk (ret->chk_uri)) ) ) || 709 GNUNET_FS_uri_test_chk (ret->chk_uri)))) ||
772 (GNUNET_OK != 710 (GNUNET_OK !=
773 read_start_time (rh, &ret->start_time)) || 711 read_start_time (rh, &ret->start_time)) ||
774 (GNUNET_OK != 712 (GNUNET_OK !=
775 GNUNET_BIO_read_string (rh, "emsg", &ret->emsg, 16*1024)) || 713 GNUNET_BIO_read_string (rh, "emsg", &ret->emsg, 16 * 1024)) ||
776 (GNUNET_OK != 714 (GNUNET_OK !=
777 GNUNET_BIO_read_string (rh, "fn", &ret->filename, 16*1024)) || 715 GNUNET_BIO_read_string (rh, "fn", &ret->filename, 16 * 1024)) ||
778 (GNUNET_OK != 716 (GNUNET_OK !=
779 GNUNET_BIO_read_int64 (rh, &ret->bo.expiration_time.abs_value)) || 717 GNUNET_BIO_read_int64 (rh, &ret->bo.expiration_time.abs_value)) ||
780 (GNUNET_OK != 718 (GNUNET_OK !=
781 GNUNET_BIO_read_int32 (rh, &ret->bo.anonymity_level)) || 719 GNUNET_BIO_read_int32 (rh, &ret->bo.anonymity_level)) ||
782 (GNUNET_OK != 720 (GNUNET_OK !=
783 GNUNET_BIO_read_int32 (rh, &ret->bo.content_priority)) || 721 GNUNET_BIO_read_int32 (rh, &ret->bo.content_priority)) ||
784 (GNUNET_OK != 722 (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &ret->bo.replication_level)))
785 GNUNET_BIO_read_int32 (rh, &ret->bo.replication_level)) ) 723 {
724 GNUNET_break (0);
725 goto cleanup;
726 }
727 switch (b)
728 {
729 case 0: /* file-insert */
730 if (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size))
786 { 731 {
787 GNUNET_break (0); 732 GNUNET_break (0);
788 goto cleanup; 733 goto cleanup;
789 } 734 }
790 switch (b) 735 ret->is_directory = GNUNET_NO;
736 ret->data.file.do_index = GNUNET_NO;
737 ret->data.file.have_hash = GNUNET_NO;
738 ret->data.file.index_start_confirmed = GNUNET_NO;
739 if (GNUNET_NO == ret->is_published)
791 { 740 {
792 case 0: /* file-insert */
793 if (GNUNET_OK !=
794 GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size))
795 {
796 GNUNET_break (0);
797 goto cleanup;
798 }
799 ret->is_directory = GNUNET_NO;
800 ret->data.file.do_index = GNUNET_NO;
801 ret->data.file.have_hash = GNUNET_NO;
802 ret->data.file.index_start_confirmed = GNUNET_NO;
803 if (GNUNET_NO == ret->is_published)
804 {
805 if (NULL == ret->filename)
806 {
807 ret->data.file.reader = &GNUNET_FS_data_reader_copy_;
808 ret->data.file.reader_cls = GNUNET_malloc_large (ret->data.file.file_size);
809 if (ret->data.file.reader_cls == NULL)
810 goto cleanup;
811 if (GNUNET_OK !=
812 GNUNET_BIO_read (rh, "file-data", ret->data.file.reader_cls, ret->data.file.file_size))
813 {
814 GNUNET_break (0);
815 goto cleanup;
816 }
817 }
818 else
819 {
820 ret->data.file.reader = &GNUNET_FS_data_reader_file_;
821 ret->data.file.reader_cls = GNUNET_FS_make_file_reader_context_ (ret->filename);
822 }
823 }
824 break;
825 case 1: /* file-index, no hash */
826 if (NULL == ret->filename)
827 {
828 GNUNET_break (0);
829 goto cleanup;
830 }
831 if (GNUNET_OK !=
832 GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size))
833 {
834 GNUNET_break (0);
835 goto cleanup;
836 }
837 ret->is_directory = GNUNET_NO;
838 ret->data.file.do_index = GNUNET_YES;
839 ret->data.file.have_hash = GNUNET_NO;
840 ret->data.file.index_start_confirmed = GNUNET_NO;
841 ret->data.file.reader = &GNUNET_FS_data_reader_file_;
842 ret->data.file.reader_cls = GNUNET_FS_make_file_reader_context_ (ret->filename);
843 break;
844 case 2: /* file-index-with-hash */
845 if (NULL == ret->filename)
846 {
847 GNUNET_break (0);
848 goto cleanup;
849 }
850 if ( (GNUNET_OK !=
851 GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size)) ||
852 (GNUNET_OK !=
853 GNUNET_BIO_read (rh, "fileid", &ret->data.file.file_id, sizeof (GNUNET_HashCode))) )
854 {
855 GNUNET_break (0);
856 goto cleanup;
857 }
858 ret->is_directory = GNUNET_NO;
859 ret->data.file.do_index = GNUNET_YES;
860 ret->data.file.have_hash = GNUNET_YES;
861 ret->data.file.index_start_confirmed = GNUNET_NO;
862 ret->data.file.reader = &GNUNET_FS_data_reader_file_;
863 ret->data.file.reader_cls = GNUNET_FS_make_file_reader_context_ (ret->filename);
864 break;
865 case 3: /* file-index-with-hash-confirmed */
866 if (NULL == ret->filename) 741 if (NULL == ret->filename)
867 { 742 {
868 GNUNET_break (0); 743 ret->data.file.reader = &GNUNET_FS_data_reader_copy_;
869 goto cleanup; 744 ret->data.file.reader_cls =
870 } 745 GNUNET_malloc_large (ret->data.file.file_size);
871 if ( (GNUNET_OK != 746 if (ret->data.file.reader_cls == NULL)
872 GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size)) || 747 goto cleanup;
873 (GNUNET_OK != 748 if (GNUNET_OK !=
874 GNUNET_BIO_read (rh, "fileid", &ret->data.file.file_id, sizeof (GNUNET_HashCode))) ) 749 GNUNET_BIO_read (rh, "file-data", ret->data.file.reader_cls,
875 { 750 ret->data.file.file_size))
876 GNUNET_break (0); 751 {
877 goto cleanup; 752 GNUNET_break (0);
878 } 753 goto cleanup;
879 ret->is_directory = GNUNET_NO; 754 }
880 ret->data.file.do_index = GNUNET_YES; 755 }
881 ret->data.file.have_hash = GNUNET_YES; 756 else
882 ret->data.file.index_start_confirmed = GNUNET_YES; 757 {
883 ret->data.file.reader = &GNUNET_FS_data_reader_file_; 758 ret->data.file.reader = &GNUNET_FS_data_reader_file_;
884 ret->data.file.reader_cls = GNUNET_FS_make_file_reader_context_ (ret->filename); 759 ret->data.file.reader_cls =
885 break; 760 GNUNET_FS_make_file_reader_context_ (ret->filename);
886 case 4: /* directory */ 761 }
887 ret->is_directory = GNUNET_YES; 762 }
888 if ( (GNUNET_OK != 763 break;
889 GNUNET_BIO_read_int32 (rh, &dsize)) || 764 case 1: /* file-index, no hash */
890 (NULL == (ret->data.dir.dir_data = GNUNET_malloc_large (dsize))) || 765 if (NULL == ret->filename)
891 (GNUNET_OK != 766 {
892 GNUNET_BIO_read (rh, "dir-data", ret->data.dir.dir_data, dsize)) ||
893 (GNUNET_OK !=
894 GNUNET_BIO_read_string (rh, "ent-filename", &filename, 16*1024)) )
895 {
896 GNUNET_break (0);
897 goto cleanup;
898 }
899 ret->data.dir.dir_size = (uint32_t) dsize;
900 if (filename != NULL)
901 {
902 ret->data.dir.entries = deserialize_file_information (h, filename);
903 GNUNET_free (filename);
904 filename = NULL;
905 nxt = ret->data.dir.entries;
906 while (nxt != NULL)
907 {
908 nxt->dir = ret;
909 nxt = nxt->next;
910 }
911 }
912 break;
913 default:
914 GNUNET_break (0); 767 GNUNET_break (0);
915 goto cleanup; 768 goto cleanup;
916 } 769 }
917 ret->serialization = GNUNET_strdup (fn); 770 if (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size))
918 if (GNUNET_OK !=
919 GNUNET_BIO_read_string (rh, "nxt-filename", &filename, 16*1024))
920 { 771 {
921 GNUNET_break (0); 772 GNUNET_break (0);
922 goto cleanup; 773 goto cleanup;
923 } 774 }
924 if (filename != NULL) 775 ret->is_directory = GNUNET_NO;
776 ret->data.file.do_index = GNUNET_YES;
777 ret->data.file.have_hash = GNUNET_NO;
778 ret->data.file.index_start_confirmed = GNUNET_NO;
779 ret->data.file.reader = &GNUNET_FS_data_reader_file_;
780 ret->data.file.reader_cls =
781 GNUNET_FS_make_file_reader_context_ (ret->filename);
782 break;
783 case 2: /* file-index-with-hash */
784 if (NULL == ret->filename)
925 { 785 {
926 ret->next = deserialize_file_information (h, filename); 786 GNUNET_break (0);
787 goto cleanup;
788 }
789 if ((GNUNET_OK !=
790 GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size)) ||
791 (GNUNET_OK !=
792 GNUNET_BIO_read (rh, "fileid", &ret->data.file.file_id,
793 sizeof (GNUNET_HashCode))))
794 {
795 GNUNET_break (0);
796 goto cleanup;
797 }
798 ret->is_directory = GNUNET_NO;
799 ret->data.file.do_index = GNUNET_YES;
800 ret->data.file.have_hash = GNUNET_YES;
801 ret->data.file.index_start_confirmed = GNUNET_NO;
802 ret->data.file.reader = &GNUNET_FS_data_reader_file_;
803 ret->data.file.reader_cls =
804 GNUNET_FS_make_file_reader_context_ (ret->filename);
805 break;
806 case 3: /* file-index-with-hash-confirmed */
807 if (NULL == ret->filename)
808 {
809 GNUNET_break (0);
810 goto cleanup;
811 }
812 if ((GNUNET_OK !=
813 GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size)) ||
814 (GNUNET_OK !=
815 GNUNET_BIO_read (rh, "fileid", &ret->data.file.file_id,
816 sizeof (GNUNET_HashCode))))
817 {
818 GNUNET_break (0);
819 goto cleanup;
820 }
821 ret->is_directory = GNUNET_NO;
822 ret->data.file.do_index = GNUNET_YES;
823 ret->data.file.have_hash = GNUNET_YES;
824 ret->data.file.index_start_confirmed = GNUNET_YES;
825 ret->data.file.reader = &GNUNET_FS_data_reader_file_;
826 ret->data.file.reader_cls =
827 GNUNET_FS_make_file_reader_context_ (ret->filename);
828 break;
829 case 4: /* directory */
830 ret->is_directory = GNUNET_YES;
831 if ((GNUNET_OK !=
832 GNUNET_BIO_read_int32 (rh, &dsize)) ||
833 (NULL == (ret->data.dir.dir_data = GNUNET_malloc_large (dsize))) ||
834 (GNUNET_OK !=
835 GNUNET_BIO_read (rh, "dir-data", ret->data.dir.dir_data, dsize)) ||
836 (GNUNET_OK !=
837 GNUNET_BIO_read_string (rh, "ent-filename", &filename, 16 * 1024)))
838 {
839 GNUNET_break (0);
840 goto cleanup;
841 }
842 ret->data.dir.dir_size = (uint32_t) dsize;
843 if (filename != NULL)
844 {
845 ret->data.dir.entries = deserialize_file_information (h, filename);
927 GNUNET_free (filename); 846 GNUNET_free (filename);
928 filename = NULL; 847 filename = NULL;
929 } 848 nxt = ret->data.dir.entries;
849 while (nxt != NULL)
850 {
851 nxt->dir = ret;
852 nxt = nxt->next;
853 }
854 }
855 break;
856 default:
857 GNUNET_break (0);
858 goto cleanup;
859 }
860 ret->serialization = GNUNET_strdup (fn);
861 if (GNUNET_OK !=
862 GNUNET_BIO_read_string (rh, "nxt-filename", &filename, 16 * 1024))
863 {
864 GNUNET_break (0);
865 goto cleanup;
866 }
867 if (filename != NULL)
868 {
869 ret->next = deserialize_file_information (h, filename);
870 GNUNET_free (filename);
871 filename = NULL;
872 }
930 GNUNET_free_non_null (ksks); 873 GNUNET_free_non_null (ksks);
931 GNUNET_free_non_null (chks); 874 GNUNET_free_non_null (chks);
932 return ret; 875 return ret;
933 cleanup: 876cleanup:
934 GNUNET_free_non_null (ksks); 877 GNUNET_free_non_null (ksks);
935 GNUNET_free_non_null (chks); 878 GNUNET_free_non_null (chks);
936 GNUNET_free_non_null (filename); 879 GNUNET_free_non_null (filename);
@@ -949,8 +892,7 @@ deserialize_fi_node (struct GNUNET_FS_Handle *h,
949 * @return NULL on error 892 * @return NULL on error
950 */ 893 */
951static struct GNUNET_FS_FileInformation * 894static struct GNUNET_FS_FileInformation *
952deserialize_file_information (struct GNUNET_FS_Handle *h, 895deserialize_file_information (struct GNUNET_FS_Handle *h, const char *filename)
953 const char *filename)
954{ 896{
955 struct GNUNET_FS_FileInformation *ret; 897 struct GNUNET_FS_FileInformation *ret;
956 struct GNUNET_BIO_ReadHandle *rh; 898 struct GNUNET_BIO_ReadHandle *rh;
@@ -960,22 +902,18 @@ deserialize_file_information (struct GNUNET_FS_Handle *h,
960 if (rh == NULL) 902 if (rh == NULL)
961 return NULL; 903 return NULL;
962 ret = deserialize_fi_node (h, filename, rh); 904 ret = deserialize_fi_node (h, filename, rh);
963 if (GNUNET_OK != 905 if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
964 GNUNET_BIO_read_close (rh, &emsg)) 906 {
965 { 907 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
966 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 908 _("Failed to resume publishing information `%s': %s\n"),
967 _("Failed to resume publishing information `%s': %s\n"), 909 filename, emsg);
968 filename, 910 GNUNET_free (emsg);
969 emsg); 911 }
970 GNUNET_free (emsg);
971 }
972 if (ret == NULL) 912 if (ret == NULL)
973 { 913 {
974 if (0 != UNLINK (filename)) 914 if (0 != UNLINK (filename))
975 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, 915 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", filename);
976 "unlink", 916 }
977 filename);
978 }
979 return ret; 917 return ret;
980} 918}
981 919
@@ -997,21 +935,20 @@ get_serialization_short_name (const char *fullname)
997 end = NULL; 935 end = NULL;
998 nxt = fullname; 936 nxt = fullname;
999 /* FIXME: we could do this faster since we know 937 /* FIXME: we could do this faster since we know
1000 the length of 'end'... */ 938 * the length of 'end'... */
1001 while ('\0' != *nxt) 939 while ('\0' != *nxt)
1002 { 940 {
1003 if (DIR_SEPARATOR == *nxt) 941 if (DIR_SEPARATOR == *nxt)
1004 end = nxt + 1; 942 end = nxt + 1;
1005 nxt++; 943 nxt++;
1006 } 944 }
1007 if ( (end == NULL) || 945 if ((end == NULL) || (strlen (end) == 0))
1008 (strlen (end) == 0) ) 946 {
1009 { 947 GNUNET_break (0);
1010 GNUNET_break (0); 948 return NULL;
1011 return NULL; 949 }
1012 }
1013 GNUNET_break (6 == strlen (end)); 950 GNUNET_break (6 == strlen (end));
1014 return GNUNET_strdup (end); 951 return GNUNET_strdup (end);
1015} 952}
1016 953
1017 954
@@ -1024,28 +961,26 @@ get_serialization_short_name (const char *fullname)
1024 * @return NULL on errror 961 * @return NULL on errror
1025 */ 962 */
1026static char * 963static char *
1027make_serialization_file_name (struct GNUNET_FS_Handle *h, 964make_serialization_file_name (struct GNUNET_FS_Handle *h, const char *ext)
1028 const char *ext)
1029{ 965{
1030 char *fn; 966 char *fn;
1031 char *dn; 967 char *dn;
1032 char *ret; 968 char *ret;
1033 969
1034 if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE)) 970 if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE))
1035 return NULL; /* persistence not requested */ 971 return NULL; /* persistence not requested */
1036 dn = get_serialization_file_name (h, ext, ""); 972 dn = get_serialization_file_name (h, ext, "");
1037 if (dn == NULL) 973 if (dn == NULL)
1038 return NULL; 974 return NULL;
1039 if (GNUNET_OK != 975 if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (dn))
1040 GNUNET_DISK_directory_create_for_file (dn)) 976 {
1041 { 977 GNUNET_free (dn);
1042 GNUNET_free (dn); 978 return NULL;
1043 return NULL; 979 }
1044 }
1045 fn = GNUNET_DISK_mktemp (dn); 980 fn = GNUNET_DISK_mktemp (dn);
1046 GNUNET_free (dn); 981 GNUNET_free (dn);
1047 if (fn == NULL) 982 if (fn == NULL)
1048 return NULL; /* epic fail */ 983 return NULL; /* epic fail */
1049 ret = get_serialization_short_name (fn); 984 ret = get_serialization_short_name (fn);
1050 GNUNET_free (fn); 985 GNUNET_free (fn);
1051 return ret; 986 return ret;
@@ -1063,28 +998,26 @@ make_serialization_file_name (struct GNUNET_FS_Handle *h,
1063 */ 998 */
1064static char * 999static char *
1065make_serialization_file_name_in_dir (struct GNUNET_FS_Handle *h, 1000make_serialization_file_name_in_dir (struct GNUNET_FS_Handle *h,
1066 const char *ext, 1001 const char *ext, const char *uni)
1067 const char *uni)
1068{ 1002{
1069 char *fn; 1003 char *fn;
1070 char *dn; 1004 char *dn;
1071 char *ret; 1005 char *ret;
1072 1006
1073 if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE)) 1007 if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE))
1074 return NULL; /* persistence not requested */ 1008 return NULL; /* persistence not requested */
1075 dn = get_serialization_file_name_in_dir (h, ext, uni, ""); 1009 dn = get_serialization_file_name_in_dir (h, ext, uni, "");
1076 if (dn == NULL) 1010 if (dn == NULL)
1077 return NULL; 1011 return NULL;
1078 if (GNUNET_OK != 1012 if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (dn))
1079 GNUNET_DISK_directory_create_for_file (dn)) 1013 {
1080 { 1014 GNUNET_free (dn);
1081 GNUNET_free (dn); 1015 return NULL;
1082 return NULL; 1016 }
1083 }
1084 fn = GNUNET_DISK_mktemp (dn); 1017 fn = GNUNET_DISK_mktemp (dn);
1085 GNUNET_free (dn); 1018 GNUNET_free (dn);
1086 if (fn == NULL) 1019 if (fn == NULL)
1087 return NULL; /* epic fail */ 1020 return NULL; /* epic fail */
1088 ret = get_serialization_short_name (fn); 1021 ret = get_serialization_short_name (fn);
1089 GNUNET_free (fn); 1022 GNUNET_free (fn);
1090 return ret; 1023 return ret;
@@ -1100,7 +1033,7 @@ make_serialization_file_name_in_dir (struct GNUNET_FS_Handle *h,
1100 */ 1033 */
1101static int 1034static int
1102copy_from_reader (struct GNUNET_BIO_WriteHandle *wh, 1035copy_from_reader (struct GNUNET_BIO_WriteHandle *wh,
1103 struct GNUNET_FS_FileInformation * fi) 1036 struct GNUNET_FS_FileInformation *fi)
1104{ 1037{
1105 char buf[32 * 1024]; 1038 char buf[32 * 1024];
1106 uint64_t off; 1039 uint64_t off;
@@ -1111,22 +1044,19 @@ copy_from_reader (struct GNUNET_BIO_WriteHandle *wh,
1111 emsg = NULL; 1044 emsg = NULL;
1112 off = 0; 1045 off = 0;
1113 while (off < fi->data.file.file_size) 1046 while (off < fi->data.file.file_size)
1047 {
1048 left = GNUNET_MIN (sizeof (buf), fi->data.file.file_size - off);
1049 ret = fi->data.file.reader (fi->data.file.reader_cls,
1050 off, left, buf, &emsg);
1051 if (ret == 0)
1114 { 1052 {
1115 left = GNUNET_MIN (sizeof(buf), fi->data.file.file_size - off); 1053 GNUNET_free (emsg);
1116 ret = fi->data.file.reader (fi->data.file.reader_cls, 1054 return GNUNET_SYSERR;
1117 off, left,
1118 buf,
1119 &emsg);
1120 if (ret == 0)
1121 {
1122 GNUNET_free (emsg);
1123 return GNUNET_SYSERR;
1124 }
1125 if (GNUNET_OK !=
1126 GNUNET_BIO_write (wh, buf, ret))
1127 return GNUNET_SYSERR;
1128 off += ret;
1129 } 1055 }
1056 if (GNUNET_OK != GNUNET_BIO_write (wh, buf, ret))
1057 return GNUNET_SYSERR;
1058 off += ret;
1059 }
1130 return GNUNET_OK; 1060 return GNUNET_OK;
1131} 1061}
1132 1062
@@ -1138,7 +1068,7 @@ copy_from_reader (struct GNUNET_BIO_WriteHandle *wh,
1138 * @param fi file information to sync with disk 1068 * @param fi file information to sync with disk
1139 */ 1069 */
1140void 1070void
1141GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation * fi) 1071GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *fi)
1142{ 1072{
1143 char *fn; 1073 char *fn;
1144 struct GNUNET_BIO_WriteHandle *wh; 1074 struct GNUNET_BIO_WriteHandle *wh;
@@ -1146,17 +1076,19 @@ GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation * fi)
1146 char *ksks; 1076 char *ksks;
1147 char *chks; 1077 char *chks;
1148 1078
1149 if (NULL == fi->serialization) 1079 if (NULL == fi->serialization)
1150 fi->serialization = make_serialization_file_name (fi->h, GNUNET_FS_SYNC_PATH_FILE_INFO); 1080 fi->serialization =
1081 make_serialization_file_name (fi->h, GNUNET_FS_SYNC_PATH_FILE_INFO);
1151 if (NULL == fi->serialization) 1082 if (NULL == fi->serialization)
1152 return; 1083 return;
1153 wh = get_write_handle (fi->h, GNUNET_FS_SYNC_PATH_FILE_INFO, fi->serialization); 1084 wh = get_write_handle (fi->h, GNUNET_FS_SYNC_PATH_FILE_INFO,
1085 fi->serialization);
1154 if (wh == NULL) 1086 if (wh == NULL)
1155 { 1087 {
1156 GNUNET_free (fi->serialization); 1088 GNUNET_free (fi->serialization);
1157 fi->serialization = NULL; 1089 fi->serialization = NULL;
1158 return; 1090 return;
1159 } 1091 }
1160 if (GNUNET_YES == fi->is_directory) 1092 if (GNUNET_YES == fi->is_directory)
1161 b = 4; 1093 b = 4;
1162 else if (GNUNET_YES == fi->data.file.index_start_confirmed) 1094 else if (GNUNET_YES == fi->data.file.index_start_confirmed)
@@ -1175,131 +1107,130 @@ GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation * fi)
1175 chks = GNUNET_FS_uri_to_string (fi->chk_uri); 1107 chks = GNUNET_FS_uri_to_string (fi->chk_uri);
1176 else 1108 else
1177 chks = NULL; 1109 chks = NULL;
1178 if ( (GNUNET_OK != 1110 if ((GNUNET_OK !=
1179 GNUNET_BIO_write (wh, &b, sizeof (b))) || 1111 GNUNET_BIO_write (wh, &b, sizeof (b))) ||
1180 (GNUNET_OK != 1112 (GNUNET_OK !=
1181 GNUNET_BIO_write_meta_data (wh, fi->meta)) || 1113 GNUNET_BIO_write_meta_data (wh, fi->meta)) ||
1182 (GNUNET_OK != 1114 (GNUNET_OK !=
1183 GNUNET_BIO_write_string (wh, ksks)) || 1115 GNUNET_BIO_write_string (wh, ksks)) ||
1184 (GNUNET_OK != 1116 (GNUNET_OK !=
1185 GNUNET_BIO_write_string (wh, chks)) || 1117 GNUNET_BIO_write_string (wh, chks)) ||
1186 (GNUNET_OK != 1118 (GNUNET_OK !=
1187 write_start_time (wh, fi->start_time)) || 1119 write_start_time (wh, fi->start_time)) ||
1188 (GNUNET_OK != 1120 (GNUNET_OK !=
1189 GNUNET_BIO_write_string (wh, fi->emsg)) || 1121 GNUNET_BIO_write_string (wh, fi->emsg)) ||
1190 (GNUNET_OK != 1122 (GNUNET_OK !=
1191 GNUNET_BIO_write_string (wh, fi->filename)) || 1123 GNUNET_BIO_write_string (wh, fi->filename)) ||
1192 (GNUNET_OK != 1124 (GNUNET_OK !=
1193 GNUNET_BIO_write_int64 (wh, fi->bo.expiration_time.abs_value)) || 1125 GNUNET_BIO_write_int64 (wh, fi->bo.expiration_time.abs_value)) ||
1194 (GNUNET_OK != 1126 (GNUNET_OK !=
1195 GNUNET_BIO_write_int32 (wh, fi->bo.anonymity_level)) || 1127 GNUNET_BIO_write_int32 (wh, fi->bo.anonymity_level)) ||
1196 (GNUNET_OK != 1128 (GNUNET_OK !=
1197 GNUNET_BIO_write_int32 (wh, fi->bo.content_priority)) || 1129 GNUNET_BIO_write_int32 (wh, fi->bo.content_priority)) ||
1198 (GNUNET_OK != 1130 (GNUNET_OK != GNUNET_BIO_write_int32 (wh, fi->bo.replication_level)))
1199 GNUNET_BIO_write_int32 (wh, fi->bo.replication_level)) ) 1131 {
1200 { 1132 GNUNET_break (0);
1201 GNUNET_break (0); 1133 goto cleanup;
1202 goto cleanup; 1134 }
1203 }
1204 GNUNET_free_non_null (chks); 1135 GNUNET_free_non_null (chks);
1205 chks = NULL; 1136 chks = NULL;
1206 GNUNET_free_non_null (ksks); 1137 GNUNET_free_non_null (ksks);
1207 ksks = NULL; 1138 ksks = NULL;
1208 1139
1209 switch (b) 1140 switch (b)
1141 {
1142 case 0: /* file-insert */
1143 if (GNUNET_OK != GNUNET_BIO_write_int64 (wh, fi->data.file.file_size))
1210 { 1144 {
1211 case 0: /* file-insert */ 1145 GNUNET_break (0);
1212 if (GNUNET_OK !=
1213 GNUNET_BIO_write_int64 (wh, fi->data.file.file_size))
1214 {
1215 GNUNET_break (0);
1216 goto cleanup;
1217 }
1218 if ( (GNUNET_NO == fi->is_published) &&
1219 (NULL == fi->filename) )
1220 if (GNUNET_OK !=
1221 copy_from_reader (wh, fi))
1222 {
1223 GNUNET_break (0);
1224 goto cleanup;
1225 }
1226 break;
1227 case 1: /* file-index, no hash */
1228 if (NULL == fi->filename)
1229 {
1230 GNUNET_break (0);
1231 goto cleanup;
1232 }
1233 if (GNUNET_OK !=
1234 GNUNET_BIO_write_int64 (wh, fi->data.file.file_size))
1235 {
1236 GNUNET_break (0);
1237 goto cleanup;
1238 }
1239 break;
1240 case 2: /* file-index-with-hash */
1241 case 3: /* file-index-with-hash-confirmed */
1242 if (NULL == fi->filename)
1243 {
1244 GNUNET_break (0);
1245 goto cleanup;
1246 }
1247 if ( (GNUNET_OK !=
1248 GNUNET_BIO_write_int64 (wh, fi->data.file.file_size)) ||
1249 (GNUNET_OK !=
1250 GNUNET_BIO_write (wh, &fi->data.file.file_id, sizeof (GNUNET_HashCode))) )
1251 {
1252 GNUNET_break (0);
1253 goto cleanup;
1254 }
1255 break;
1256 case 4: /* directory */
1257 if ( (GNUNET_OK !=
1258 GNUNET_BIO_write_int32 (wh, fi->data.dir.dir_size)) ||
1259 (GNUNET_OK !=
1260 GNUNET_BIO_write (wh, fi->data.dir.dir_data, (uint32_t) fi->data.dir.dir_size)) ||
1261 (GNUNET_OK !=
1262 GNUNET_BIO_write_string (wh,
1263 (fi->data.dir.entries == NULL)
1264 ? NULL
1265 : fi->data.dir.entries->serialization)) )
1266 {
1267 GNUNET_break (0);
1268 goto cleanup;
1269 }
1270 break;
1271 default:
1272 GNUNET_assert (0);
1273 goto cleanup; 1146 goto cleanup;
1274 } 1147 }
1275 if (GNUNET_OK != 1148 if ((GNUNET_NO == fi->is_published) && (NULL == fi->filename))
1276 GNUNET_BIO_write_string (wh, (fi->next != NULL) ? fi->next->serialization : NULL)) 1149 if (GNUNET_OK != copy_from_reader (wh, fi))
1150 {
1151 GNUNET_break (0);
1152 goto cleanup;
1153 }
1154 break;
1155 case 1: /* file-index, no hash */
1156 if (NULL == fi->filename)
1277 { 1157 {
1278 GNUNET_break (0); 1158 GNUNET_break (0);
1279 goto cleanup; 1159 goto cleanup;
1280 } 1160 }
1281 if (GNUNET_OK != 1161 if (GNUNET_OK != GNUNET_BIO_write_int64 (wh, fi->data.file.file_size))
1282 GNUNET_BIO_write_close (wh)) 1162 {
1163 GNUNET_break (0);
1164 goto cleanup;
1165 }
1166 break;
1167 case 2: /* file-index-with-hash */
1168 case 3: /* file-index-with-hash-confirmed */
1169 if (NULL == fi->filename)
1283 { 1170 {
1284 wh = NULL;
1285 GNUNET_break (0); 1171 GNUNET_break (0);
1286 goto cleanup; 1172 goto cleanup;
1287 } 1173 }
1288 return; /* done! */ 1174 if ((GNUNET_OK !=
1289 cleanup: 1175 GNUNET_BIO_write_int64 (wh, fi->data.file.file_size)) ||
1176 (GNUNET_OK !=
1177 GNUNET_BIO_write (wh, &fi->data.file.file_id,
1178 sizeof (GNUNET_HashCode))))
1179 {
1180 GNUNET_break (0);
1181 goto cleanup;
1182 }
1183 break;
1184 case 4: /* directory */
1185 if ((GNUNET_OK !=
1186 GNUNET_BIO_write_int32 (wh, fi->data.dir.dir_size)) ||
1187 (GNUNET_OK !=
1188 GNUNET_BIO_write (wh, fi->data.dir.dir_data,
1189 (uint32_t) fi->data.dir.dir_size)) ||
1190 (GNUNET_OK !=
1191 GNUNET_BIO_write_string (wh,
1192 (fi->data.dir.entries ==
1193 NULL) ? NULL : fi->data.dir.
1194 entries->serialization)))
1195 {
1196 GNUNET_break (0);
1197 goto cleanup;
1198 }
1199 break;
1200 default:
1201 GNUNET_assert (0);
1202 goto cleanup;
1203 }
1204 if (GNUNET_OK !=
1205 GNUNET_BIO_write_string (wh,
1206 (fi->next !=
1207 NULL) ? fi->next->serialization : NULL))
1208 {
1209 GNUNET_break (0);
1210 goto cleanup;
1211 }
1212 if (GNUNET_OK != GNUNET_BIO_write_close (wh))
1213 {
1214 wh = NULL;
1215 GNUNET_break (0);
1216 goto cleanup;
1217 }
1218 return; /* done! */
1219cleanup:
1290 if (wh != NULL) 1220 if (wh != NULL)
1291 (void) GNUNET_BIO_write_close (wh); 1221 (void) GNUNET_BIO_write_close (wh);
1292 GNUNET_free_non_null (chks); 1222 GNUNET_free_non_null (chks);
1293 GNUNET_free_non_null (ksks); 1223 GNUNET_free_non_null (ksks);
1294 fn = get_serialization_file_name (fi->h, GNUNET_FS_SYNC_PATH_FILE_INFO, fi->serialization); 1224 fn = get_serialization_file_name (fi->h, GNUNET_FS_SYNC_PATH_FILE_INFO,
1225 fi->serialization);
1295 if (NULL != fn) 1226 if (NULL != fn)
1296 { 1227 {
1297 if (0 != UNLINK (fn)) 1228 if (0 != UNLINK (fn))
1298 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn); 1229 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn);
1299 GNUNET_free (fn); 1230 GNUNET_free (fn);
1300 } 1231 }
1301 GNUNET_free (fi->serialization); 1232 GNUNET_free (fi->serialization);
1302 fi->serialization = NULL; 1233 fi->serialization = NULL;
1303} 1234}
1304 1235
1305 1236
@@ -1313,25 +1244,22 @@ GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation * fi)
1313 * @return NULL if srch was not found in this subtree 1244 * @return NULL if srch was not found in this subtree
1314 */ 1245 */
1315static struct GNUNET_FS_FileInformation * 1246static struct GNUNET_FS_FileInformation *
1316find_file_position (struct GNUNET_FS_FileInformation *pos, 1247find_file_position (struct GNUNET_FS_FileInformation *pos, const char *srch)
1317 const char *srch)
1318{ 1248{
1319 struct GNUNET_FS_FileInformation *r; 1249 struct GNUNET_FS_FileInformation *r;
1320 1250
1321 while (pos != NULL) 1251 while (pos != NULL)
1252 {
1253 if (0 == strcmp (srch, pos->serialization))
1254 return pos;
1255 if (pos->is_directory)
1322 { 1256 {
1323 if (0 == strcmp (srch, 1257 r = find_file_position (pos->data.dir.entries, srch);
1324 pos->serialization)) 1258 if (r != NULL)
1325 return pos; 1259 return r;
1326 if (pos->is_directory)
1327 {
1328 r = find_file_position (pos->data.dir.entries,
1329 srch);
1330 if (r != NULL)
1331 return r;
1332 }
1333 pos = pos->next;
1334 } 1260 }
1261 pos = pos->next;
1262 }
1335 return NULL; 1263 return NULL;
1336} 1264}
1337 1265
@@ -1351,14 +1279,13 @@ find_file_position (struct GNUNET_FS_FileInformation *pos,
1351 * @return GNUNET_OK to continue (always) 1279 * @return GNUNET_OK to continue (always)
1352 */ 1280 */
1353static int 1281static int
1354fip_signal_resume(void *cls, 1282fip_signal_resume (void *cls,
1355 struct GNUNET_FS_FileInformation *fi, 1283 struct GNUNET_FS_FileInformation *fi,
1356 uint64_t length, 1284 uint64_t length,
1357 struct GNUNET_CONTAINER_MetaData *meta, 1285 struct GNUNET_CONTAINER_MetaData *meta,
1358 struct GNUNET_FS_Uri **uri, 1286 struct GNUNET_FS_Uri **uri,
1359 struct GNUNET_FS_BlockOptions *bo, 1287 struct GNUNET_FS_BlockOptions *bo,
1360 int *do_index, 1288 int *do_index, void **client_info)
1361 void **client_info)
1362{ 1289{
1363 struct GNUNET_FS_PublishContext *sc = cls; 1290 struct GNUNET_FS_PublishContext *sc = cls;
1364 struct GNUNET_FS_ProgressInfo pi; 1291 struct GNUNET_FS_ProgressInfo pi;
@@ -1380,8 +1307,7 @@ fip_signal_resume(void *cls,
1380 * @return GNUNET_OK (continue to iterate) 1307 * @return GNUNET_OK (continue to iterate)
1381 */ 1308 */
1382static int 1309static int
1383deserialize_publish_file (void *cls, 1310deserialize_publish_file (void *cls, const char *filename)
1384 const char *filename)
1385{ 1311{
1386 struct GNUNET_FS_Handle *h = cls; 1312 struct GNUNET_FS_Handle *h = cls;
1387 struct GNUNET_BIO_ReadHandle *rh; 1313 struct GNUNET_BIO_ReadHandle *rh;
@@ -1401,117 +1327,109 @@ deserialize_publish_file (void *cls,
1401 ns = NULL; 1327 ns = NULL;
1402 rh = GNUNET_BIO_read_open (filename); 1328 rh = GNUNET_BIO_read_open (filename);
1403 if (rh == NULL) 1329 if (rh == NULL)
1404 { 1330 {
1405 GNUNET_break (0); 1331 GNUNET_break (0);
1406 goto cleanup; 1332 goto cleanup;
1407 } 1333 }
1408 if ( (GNUNET_OK != 1334 if ((GNUNET_OK !=
1409 GNUNET_BIO_read_string (rh, "publish-nid", &pc->nid, 1024)) || 1335 GNUNET_BIO_read_string (rh, "publish-nid", &pc->nid, 1024)) ||
1410 (GNUNET_OK != 1336 (GNUNET_OK !=
1411 GNUNET_BIO_read_string (rh, "publish-nuid", &pc->nuid, 1024)) || 1337 GNUNET_BIO_read_string (rh, "publish-nuid", &pc->nuid, 1024)) ||
1412 (GNUNET_OK != 1338 (GNUNET_OK !=
1413 GNUNET_BIO_read_int32 (rh, &options)) || 1339 GNUNET_BIO_read_int32 (rh, &options)) ||
1414 (GNUNET_OK != 1340 (GNUNET_OK !=
1415 GNUNET_BIO_read_int32 (rh, &all_done)) || 1341 GNUNET_BIO_read_int32 (rh, &all_done)) ||
1416 (GNUNET_OK != 1342 (GNUNET_OK !=
1417 GNUNET_BIO_read_string (rh, "publish-firoot", &fi_root, 128)) || 1343 GNUNET_BIO_read_string (rh, "publish-firoot", &fi_root, 128)) ||
1418 (GNUNET_OK != 1344 (GNUNET_OK !=
1419 GNUNET_BIO_read_string (rh, "publish-fipos", &fi_pos, 128)) || 1345 GNUNET_BIO_read_string (rh, "publish-fipos", &fi_pos, 128)) ||
1420 (GNUNET_OK != 1346 (GNUNET_OK != GNUNET_BIO_read_string (rh, "publish-ns", &ns, 1024)))
1421 GNUNET_BIO_read_string (rh, "publish-ns", &ns, 1024)) ) 1347 {
1422 { 1348 GNUNET_break (0);
1423 GNUNET_break (0); 1349 goto cleanup;
1424 goto cleanup; 1350 }
1425 }
1426 pc->options = options; 1351 pc->options = options;
1427 pc->all_done = all_done; 1352 pc->all_done = all_done;
1428 if (NULL == fi_root) 1353 if (NULL == fi_root)
1429 { 1354 {
1430 GNUNET_break (0); 1355 GNUNET_break (0);
1431 goto cleanup; 1356 goto cleanup;
1432 } 1357 }
1433 pc->fi = deserialize_file_information (h, fi_root); 1358 pc->fi = deserialize_file_information (h, fi_root);
1434 if (pc->fi == NULL) 1359 if (pc->fi == NULL)
1435 { 1360 {
1436 GNUNET_break (0); 1361 GNUNET_break (0);
1437 goto cleanup; 1362 goto cleanup;
1438 } 1363 }
1439 if (ns != NULL) 1364 if (ns != NULL)
1365 {
1366 pc->namespace = GNUNET_FS_namespace_create (h, ns);
1367 if (pc->namespace == NULL)
1440 { 1368 {
1441 pc->namespace = GNUNET_FS_namespace_create (h, ns); 1369 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1442 if (pc->namespace == NULL) 1370 _
1443 { 1371 ("Failed to recover namespace `%s', cannot resume publishing operation.\n"),
1444 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1372 ns);
1445 _("Failed to recover namespace `%s', cannot resume publishing operation.\n"), 1373 goto cleanup;
1446 ns);
1447 goto cleanup;
1448 }
1449 } 1374 }
1450 if ( (0 == (pc->options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY)) && 1375 }
1451 (GNUNET_YES != pc->all_done) ) 1376 if ((0 == (pc->options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY)) &&
1452 { 1377 (GNUNET_YES != pc->all_done))
1453 pc->dsh = GNUNET_DATASTORE_connect (h->cfg); 1378 {
1454 if (NULL == pc->dsh) 1379 pc->dsh = GNUNET_DATASTORE_connect (h->cfg);
1455 goto cleanup; 1380 if (NULL == pc->dsh)
1456 } 1381 goto cleanup;
1382 }
1457 if (fi_pos != NULL) 1383 if (fi_pos != NULL)
1384 {
1385 pc->fi_pos = find_file_position (pc->fi, fi_pos);
1386 GNUNET_free (fi_pos);
1387 fi_pos = NULL;
1388 if (pc->fi_pos == NULL)
1458 { 1389 {
1459 pc->fi_pos = find_file_position (pc->fi, 1390 /* failed to find position for resuming, outch! Will start from root! */
1460 fi_pos); 1391 GNUNET_break (0);
1461 GNUNET_free (fi_pos); 1392 if (pc->all_done != GNUNET_YES)
1462 fi_pos = NULL; 1393 pc->fi_pos = pc->fi;
1463 if (pc->fi_pos == NULL)
1464 {
1465 /* failed to find position for resuming, outch! Will start from root! */
1466 GNUNET_break (0);
1467 if (pc->all_done != GNUNET_YES)
1468 pc->fi_pos = pc->fi;
1469 }
1470 } 1394 }
1395 }
1471 GNUNET_free (fi_root); 1396 GNUNET_free (fi_root);
1472 fi_root = NULL; 1397 fi_root = NULL;
1473 /* generate RESUME event(s) */ 1398 /* generate RESUME event(s) */
1474 GNUNET_FS_file_information_inspect (pc->fi, 1399 GNUNET_FS_file_information_inspect (pc->fi, &fip_signal_resume, pc);
1475 &fip_signal_resume, 1400
1476 pc);
1477
1478 /* re-start publishing (if needed)... */ 1401 /* re-start publishing (if needed)... */
1479 if (pc->all_done != GNUNET_YES) 1402 if (pc->all_done != GNUNET_YES)
1480 { 1403 {
1481 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == pc->upload_task); 1404 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == pc->upload_task);
1482 pc->upload_task 1405 pc->upload_task
1483 = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, 1406 =
1484 &GNUNET_FS_publish_main_, 1407 GNUNET_SCHEDULER_add_with_priority
1485 pc); 1408 (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, &GNUNET_FS_publish_main_, pc);
1486 } 1409 }
1487 if (GNUNET_OK != 1410 if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
1488 GNUNET_BIO_read_close (rh, &emsg)) 1411 {
1489 { 1412 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1490 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1413 _("Failure while resuming publishing operation `%s': %s\n"),
1491 _("Failure while resuming publishing operation `%s': %s\n"), 1414 filename, emsg);
1492 filename, 1415 GNUNET_free (emsg);
1493 emsg); 1416 }
1494 GNUNET_free (emsg);
1495 }
1496 GNUNET_free_non_null (ns); 1417 GNUNET_free_non_null (ns);
1497 pc->top = GNUNET_FS_make_top (h, &GNUNET_FS_publish_signal_suspend_, pc); 1418 pc->top = GNUNET_FS_make_top (h, &GNUNET_FS_publish_signal_suspend_, pc);
1498 return GNUNET_OK; 1419 return GNUNET_OK;
1499 cleanup: 1420cleanup:
1500 GNUNET_free_non_null (pc->nid); 1421 GNUNET_free_non_null (pc->nid);
1501 GNUNET_free_non_null (pc->nuid); 1422 GNUNET_free_non_null (pc->nuid);
1502 GNUNET_free_non_null (fi_root); 1423 GNUNET_free_non_null (fi_root);
1503 GNUNET_free_non_null (fi_pos); 1424 GNUNET_free_non_null (fi_pos);
1504 GNUNET_free_non_null (ns); 1425 GNUNET_free_non_null (ns);
1505 if ( (rh != NULL) && 1426 if ((rh != NULL) && (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)))
1506 (GNUNET_OK != 1427 {
1507 GNUNET_BIO_read_close (rh, &emsg)) ) 1428 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1508 { 1429 _("Failed to resume publishing operation `%s': %s\n"),
1509 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1430 filename, emsg);
1510 _("Failed to resume publishing operation `%s': %s\n"), 1431 GNUNET_free (emsg);
1511 filename, 1432 }
1512 emsg);
1513 GNUNET_free (emsg);
1514 }
1515 if (pc->fi != NULL) 1433 if (pc->fi != NULL)
1516 GNUNET_FS_file_information_destroy (pc->fi, NULL, NULL); 1434 GNUNET_FS_file_information_destroy (pc->fi, NULL, NULL);
1517 if (0 != UNLINK (filename)) 1435 if (0 != UNLINK (filename))
@@ -1532,59 +1450,64 @@ deserialize_publish_file (void *cls,
1532 */ 1450 */
1533void 1451void
1534GNUNET_FS_publish_sync_ (struct GNUNET_FS_PublishContext *pc) 1452GNUNET_FS_publish_sync_ (struct GNUNET_FS_PublishContext *pc)
1535{ 1453{
1536 struct GNUNET_BIO_WriteHandle *wh; 1454 struct GNUNET_BIO_WriteHandle *wh;
1537 1455
1538 if (NULL == pc->serialization) 1456 if (NULL == pc->serialization)
1539 pc->serialization = make_serialization_file_name (pc->h, 1457 pc->serialization = make_serialization_file_name (pc->h,
1540 GNUNET_FS_SYNC_PATH_MASTER_PUBLISH); 1458 GNUNET_FS_SYNC_PATH_MASTER_PUBLISH);
1541 if (NULL == pc->serialization) 1459 if (NULL == pc->serialization)
1542 return; 1460 return;
1543 if (NULL == pc->fi) 1461 if (NULL == pc->fi)
1544 return; 1462 return;
1545 if (NULL == pc->fi->serialization) 1463 if (NULL == pc->fi->serialization)
1546 { 1464 {
1547 GNUNET_break (0); 1465 GNUNET_break (0);
1548 return; 1466 return;
1549 } 1467 }
1550 wh = get_write_handle (pc->h, GNUNET_FS_SYNC_PATH_MASTER_PUBLISH, pc->serialization); 1468 wh = get_write_handle (pc->h, GNUNET_FS_SYNC_PATH_MASTER_PUBLISH,
1469 pc->serialization);
1551 if (wh == NULL) 1470 if (wh == NULL)
1552 { 1471 {
1553 GNUNET_break (0); 1472 GNUNET_break (0);
1554 goto cleanup; 1473 goto cleanup;
1555 } 1474 }
1556 if ( (GNUNET_OK != 1475 if ((GNUNET_OK !=
1557 GNUNET_BIO_write_string (wh, pc->nid)) || 1476 GNUNET_BIO_write_string (wh, pc->nid)) ||
1558 (GNUNET_OK != 1477 (GNUNET_OK !=
1559 GNUNET_BIO_write_string (wh, pc->nuid)) || 1478 GNUNET_BIO_write_string (wh, pc->nuid)) ||
1560 (GNUNET_OK != 1479 (GNUNET_OK !=
1561 GNUNET_BIO_write_int32 (wh, pc->options)) || 1480 GNUNET_BIO_write_int32 (wh, pc->options)) ||
1562 (GNUNET_OK != 1481 (GNUNET_OK !=
1563 GNUNET_BIO_write_int32 (wh, pc->all_done)) || 1482 GNUNET_BIO_write_int32 (wh, pc->all_done)) ||
1564 (GNUNET_OK != 1483 (GNUNET_OK !=
1565 GNUNET_BIO_write_string (wh, pc->fi->serialization)) || 1484 GNUNET_BIO_write_string (wh, pc->fi->serialization)) ||
1566 (GNUNET_OK != 1485 (GNUNET_OK !=
1567 GNUNET_BIO_write_string (wh, (pc->fi_pos == NULL) ? NULL : pc->fi_pos->serialization)) || 1486 GNUNET_BIO_write_string (wh,
1568 (GNUNET_OK != 1487 (pc->fi_pos ==
1569 GNUNET_BIO_write_string (wh, (pc->namespace == NULL) ? NULL : pc->namespace->name)) ) 1488 NULL) ? NULL : pc->fi_pos->serialization)) ||
1570 { 1489 (GNUNET_OK !=
1571 GNUNET_break (0); 1490 GNUNET_BIO_write_string (wh,
1572 goto cleanup; 1491 (pc->namespace ==
1573 } 1492 NULL) ? NULL : pc->namespace->name)))
1574 if (GNUNET_OK != 1493 {
1575 GNUNET_BIO_write_close (wh)) 1494 GNUNET_break (0);
1576 { 1495 goto cleanup;
1577 wh = NULL; 1496 }
1578 GNUNET_break (0); 1497 if (GNUNET_OK != GNUNET_BIO_write_close (wh))
1579 goto cleanup; 1498 {
1580 } 1499 wh = NULL;
1581 return; 1500 GNUNET_break (0);
1582 cleanup: 1501 goto cleanup;
1583 if (wh != NULL) 1502 }
1584 (void) GNUNET_BIO_write_close (wh); 1503 return;
1585 GNUNET_FS_remove_sync_file_ (pc->h, GNUNET_FS_SYNC_PATH_MASTER_PUBLISH, pc->serialization); 1504cleanup:
1586 GNUNET_free (pc->serialization); 1505 if (wh != NULL)
1587 pc->serialization = NULL; 1506 (void) GNUNET_BIO_write_close (wh);
1507 GNUNET_FS_remove_sync_file_ (pc->h, GNUNET_FS_SYNC_PATH_MASTER_PUBLISH,
1508 pc->serialization);
1509 GNUNET_free (pc->serialization);
1510 pc->serialization = NULL;
1588} 1511}
1589 1512
1590 1513
@@ -1603,45 +1526,45 @@ GNUNET_FS_unindex_sync_ (struct GNUNET_FS_UnindexContext *uc)
1603 1526
1604 if (NULL == uc->serialization) 1527 if (NULL == uc->serialization)
1605 uc->serialization = make_serialization_file_name (uc->h, 1528 uc->serialization = make_serialization_file_name (uc->h,
1606 GNUNET_FS_SYNC_PATH_MASTER_UNINDEX); 1529 GNUNET_FS_SYNC_PATH_MASTER_UNINDEX);
1607 if (NULL == uc->serialization) 1530 if (NULL == uc->serialization)
1608 return; 1531 return;
1609 wh = get_write_handle (uc->h, GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, uc->serialization); 1532 wh = get_write_handle (uc->h, GNUNET_FS_SYNC_PATH_MASTER_UNINDEX,
1533 uc->serialization);
1610 if (wh == NULL) 1534 if (wh == NULL)
1611 { 1535 {
1612 GNUNET_break (0); 1536 GNUNET_break (0);
1613 goto cleanup; 1537 goto cleanup;
1614 } 1538 }
1615 if ( (GNUNET_OK != 1539 if ((GNUNET_OK !=
1616 GNUNET_BIO_write_string (wh, uc->filename)) || 1540 GNUNET_BIO_write_string (wh, uc->filename)) ||
1617 (GNUNET_OK != 1541 (GNUNET_OK !=
1618 GNUNET_BIO_write_int64 (wh, uc->file_size)) || 1542 GNUNET_BIO_write_int64 (wh, uc->file_size)) ||
1619 (GNUNET_OK != 1543 (GNUNET_OK !=
1620 write_start_time (wh, uc->start_time)) || 1544 write_start_time (wh, uc->start_time)) ||
1621 (GNUNET_OK != 1545 (GNUNET_OK !=
1622 GNUNET_BIO_write_int32 (wh, (uint32_t) uc->state)) || 1546 GNUNET_BIO_write_int32 (wh, (uint32_t) uc->state)) ||
1623 ( (uc->state == UNINDEX_STATE_FS_NOTIFY) && 1547 ((uc->state == UNINDEX_STATE_FS_NOTIFY) &&
1624 (GNUNET_OK != 1548 (GNUNET_OK !=
1625 GNUNET_BIO_write (wh, &uc->file_id, sizeof (GNUNET_HashCode))) ) || 1549 GNUNET_BIO_write (wh, &uc->file_id, sizeof (GNUNET_HashCode)))) ||
1626 ( (uc->state == UNINDEX_STATE_ERROR) && 1550 ((uc->state == UNINDEX_STATE_ERROR) &&
1627 (GNUNET_OK != 1551 (GNUNET_OK != GNUNET_BIO_write_string (wh, uc->emsg))))
1628 GNUNET_BIO_write_string (wh, uc->emsg)) ) ) 1552 {
1629 { 1553 GNUNET_break (0);
1630 GNUNET_break (0); 1554 goto cleanup;
1631 goto cleanup; 1555 }
1632 } 1556 if (GNUNET_OK != GNUNET_BIO_write_close (wh))
1633 if (GNUNET_OK != 1557 {
1634 GNUNET_BIO_write_close (wh)) 1558 wh = NULL;
1635 { 1559 GNUNET_break (0);
1636 wh = NULL; 1560 goto cleanup;
1637 GNUNET_break (0); 1561 }
1638 goto cleanup;
1639 }
1640 return; 1562 return;
1641 cleanup: 1563cleanup:
1642 if (wh != NULL) 1564 if (wh != NULL)
1643 (void) GNUNET_BIO_write_close (wh); 1565 (void) GNUNET_BIO_write_close (wh);
1644 GNUNET_FS_remove_sync_file_ (uc->h, GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, uc->serialization); 1566 GNUNET_FS_remove_sync_file_ (uc->h, GNUNET_FS_SYNC_PATH_MASTER_UNINDEX,
1567 uc->serialization);
1645 GNUNET_free (uc->serialization); 1568 GNUNET_free (uc->serialization);
1646 uc->serialization = NULL; 1569 uc->serialization = NULL;
1647} 1570}
@@ -1656,26 +1579,24 @@ GNUNET_FS_unindex_sync_ (struct GNUNET_FS_UnindexContext *uc)
1656 */ 1579 */
1657static int 1580static int
1658write_download_request (struct GNUNET_BIO_WriteHandle *wh, 1581write_download_request (struct GNUNET_BIO_WriteHandle *wh,
1659 struct DownloadRequest *dr) 1582 struct DownloadRequest *dr)
1660{ 1583{
1661 unsigned int i; 1584 unsigned int i;
1662 1585
1663 if ( (GNUNET_OK != 1586 if ((GNUNET_OK !=
1664 GNUNET_BIO_write_int32 (wh, dr->state)) || 1587 GNUNET_BIO_write_int32 (wh, dr->state)) ||
1665 (GNUNET_OK != 1588 (GNUNET_OK !=
1666 GNUNET_BIO_write_int64 (wh, dr->offset)) || 1589 GNUNET_BIO_write_int64 (wh, dr->offset)) ||
1667 (GNUNET_OK != 1590 (GNUNET_OK !=
1668 GNUNET_BIO_write_int32 (wh, dr->num_children)) || 1591 GNUNET_BIO_write_int32 (wh, dr->num_children)) ||
1669 (GNUNET_OK != 1592 (GNUNET_OK != GNUNET_BIO_write_int32 (wh, dr->depth)))
1670 GNUNET_BIO_write_int32 (wh, dr->depth)) )
1671 return GNUNET_NO;
1672 if ( (dr->state == BRS_CHK_SET) &&
1673 (GNUNET_OK !=
1674 GNUNET_BIO_write (wh, &dr->chk, sizeof (struct ContentHashKey))) )
1675 return GNUNET_NO; 1593 return GNUNET_NO;
1676 for (i=0;i<dr->num_children;i++) 1594 if ((dr->state == BRS_CHK_SET) &&
1677 if (GNUNET_NO == 1595 (GNUNET_OK !=
1678 write_download_request (wh, dr->children[i])) 1596 GNUNET_BIO_write (wh, &dr->chk, sizeof (struct ContentHashKey))))
1597 return GNUNET_NO;
1598 for (i = 0; i < dr->num_children; i++)
1599 if (GNUNET_NO == write_download_request (wh, dr->children[i]))
1679 return GNUNET_NO; 1600 return GNUNET_NO;
1680 return GNUNET_YES; 1601 return GNUNET_YES;
1681} 1602}
@@ -1689,59 +1610,59 @@ write_download_request (struct GNUNET_BIO_WriteHandle *wh,
1689 */ 1610 */
1690static struct DownloadRequest * 1611static struct DownloadRequest *
1691read_download_request (struct GNUNET_BIO_ReadHandle *rh) 1612read_download_request (struct GNUNET_BIO_ReadHandle *rh)
1692{ 1613{
1693 struct DownloadRequest *dr; 1614 struct DownloadRequest *dr;
1694 unsigned int i; 1615 unsigned int i;
1695 1616
1696 dr = GNUNET_malloc (sizeof (struct DownloadRequest)); 1617 dr = GNUNET_malloc (sizeof (struct DownloadRequest));
1697 1618
1698 if ( (GNUNET_OK != 1619 if ((GNUNET_OK !=
1699 GNUNET_BIO_read_int32 (rh, &dr->state)) || 1620 GNUNET_BIO_read_int32 (rh, &dr->state)) ||
1700 (GNUNET_OK != 1621 (GNUNET_OK !=
1701 GNUNET_BIO_read_int64 (rh, &dr->offset)) || 1622 GNUNET_BIO_read_int64 (rh, &dr->offset)) ||
1702 (GNUNET_OK != 1623 (GNUNET_OK !=
1703 GNUNET_BIO_read_int32 (rh, &dr->num_children)) || 1624 GNUNET_BIO_read_int32 (rh, &dr->num_children)) ||
1704 (dr->num_children > CHK_PER_INODE) || 1625 (dr->num_children > CHK_PER_INODE) ||
1705 (GNUNET_OK != 1626 (GNUNET_OK !=
1706 GNUNET_BIO_read_int32 (rh, &dr->depth)) || 1627 GNUNET_BIO_read_int32 (rh, &dr->depth)) ||
1707 ( (dr->depth == 0) && (dr->num_children > 0) ) || 1628 ((dr->depth == 0) && (dr->num_children > 0)) ||
1708 ( (dr->depth > 0) && (dr->num_children == 0) ) ) 1629 ((dr->depth > 0) && (dr->num_children == 0)))
1709 { 1630 {
1710 GNUNET_break (0); 1631 GNUNET_break (0);
1711 dr->num_children = 0; 1632 dr->num_children = 0;
1712 goto cleanup; 1633 goto cleanup;
1713 } 1634 }
1714 if (dr->num_children > 0) 1635 if (dr->num_children > 0)
1715 dr->children = GNUNET_malloc (dr->num_children * 1636 dr->children = GNUNET_malloc (dr->num_children *
1716 sizeof (struct ContentHashKey)); 1637 sizeof (struct ContentHashKey));
1717 switch (dr->state) 1638 switch (dr->state)
1718 { 1639 {
1719 case BRS_INIT: 1640 case BRS_INIT:
1720 case BRS_RECONSTRUCT_DOWN: 1641 case BRS_RECONSTRUCT_DOWN:
1721 case BRS_RECONSTRUCT_META_UP: 1642 case BRS_RECONSTRUCT_META_UP:
1722 case BRS_RECONSTRUCT_UP: 1643 case BRS_RECONSTRUCT_UP:
1723 break; 1644 break;
1724 case BRS_CHK_SET: 1645 case BRS_CHK_SET:
1725 if (GNUNET_OK != 1646 if (GNUNET_OK !=
1726 GNUNET_BIO_read (rh, "chk", &dr->chk, sizeof (struct ContentHashKey))) 1647 GNUNET_BIO_read (rh, "chk", &dr->chk, sizeof (struct ContentHashKey)))
1727 goto cleanup;
1728 break;
1729 case BRS_DOWNLOAD_DOWN:
1730 case BRS_DOWNLOAD_UP:
1731 case BRS_ERROR:
1732 break;
1733 default:
1734 GNUNET_break (0);
1735 goto cleanup; 1648 goto cleanup;
1736 } 1649 break;
1737 for (i=0;i<dr->num_children;i++) 1650 case BRS_DOWNLOAD_DOWN:
1738 { 1651 case BRS_DOWNLOAD_UP:
1739 if (NULL == (dr->children[i] = read_download_request (rh))) 1652 case BRS_ERROR:
1740 goto cleanup; 1653 break;
1741 dr->children[i]->parent = dr; 1654 default:
1742 } 1655 GNUNET_break (0);
1656 goto cleanup;
1657 }
1658 for (i = 0; i < dr->num_children; i++)
1659 {
1660 if (NULL == (dr->children[i] = read_download_request (rh)))
1661 goto cleanup;
1662 dr->children[i]->parent = dr;
1663 }
1743 return dr; 1664 return dr;
1744 cleanup: 1665cleanup:
1745 GNUNET_FS_free_download_request_ (dr); 1666 GNUNET_FS_free_download_request_ (dr);
1746 return NULL; 1667 return NULL;
1747} 1668}
@@ -1758,29 +1679,23 @@ read_download_request (struct GNUNET_BIO_ReadHandle *rh)
1758 */ 1679 */
1759static char * 1680static char *
1760get_download_sync_filename (struct GNUNET_FS_DownloadContext *dc, 1681get_download_sync_filename (struct GNUNET_FS_DownloadContext *dc,
1761 const char *uni, 1682 const char *uni, const char *ext)
1762 const char *ext)
1763{ 1683{
1764 char *par; 1684 char *par;
1765 char *epar; 1685 char *epar;
1766 1686
1767 if (dc->parent == NULL) 1687 if (dc->parent == NULL)
1768 return get_serialization_file_name (dc->h, 1688 return get_serialization_file_name (dc->h,
1769 (dc->search != NULL) ? 1689 (dc->search != NULL) ?
1770 GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD : 1690 GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD :
1771 GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD, 1691 GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD,
1772 uni); 1692 uni);
1773 if (dc->parent->serialization == NULL) 1693 if (dc->parent->serialization == NULL)
1774 return NULL; 1694 return NULL;
1775 par = get_download_sync_filename (dc->parent, dc->parent->serialization, ""); 1695 par = get_download_sync_filename (dc->parent, dc->parent->serialization, "");
1776 if (par == NULL) 1696 if (par == NULL)
1777 return NULL; 1697 return NULL;
1778 GNUNET_asprintf (&epar, 1698 GNUNET_asprintf (&epar, "%s.dir%s%s%s", par, DIR_SEPARATOR_STR, uni, ext);
1779 "%s.dir%s%s%s",
1780 par,
1781 DIR_SEPARATOR_STR,
1782 uni,
1783 ext);
1784 GNUNET_free (par); 1699 GNUNET_free (par);
1785 return epar; 1700 return epar;
1786} 1701}
@@ -1802,97 +1717,93 @@ GNUNET_FS_download_sync_ (struct GNUNET_FS_DownloadContext *dc)
1802 char *fn; 1717 char *fn;
1803 char *dir; 1718 char *dir;
1804 1719
1805 if (NULL == dc->serialization) 1720 if (NULL == dc->serialization)
1721 {
1722 dir = get_download_sync_filename (dc, "", "");
1723 if (dir == NULL)
1724 return;
1725 if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (dir))
1806 { 1726 {
1807 dir = get_download_sync_filename (dc, "", "");
1808 if (dir == NULL)
1809 return;
1810 if (GNUNET_OK !=
1811 GNUNET_DISK_directory_create_for_file (dir))
1812 {
1813 GNUNET_free (dir);
1814 return;
1815 }
1816 fn = GNUNET_DISK_mktemp (dir);
1817 GNUNET_free (dir); 1727 GNUNET_free (dir);
1818 if (fn == NULL) 1728 return;
1819 return;
1820 dc->serialization = get_serialization_short_name (fn);
1821 } 1729 }
1730 fn = GNUNET_DISK_mktemp (dir);
1731 GNUNET_free (dir);
1732 if (fn == NULL)
1733 return;
1734 dc->serialization = get_serialization_short_name (fn);
1735 }
1822 else 1736 else
1823 { 1737 {
1824 fn = get_download_sync_filename (dc, dc->serialization, ""); 1738 fn = get_download_sync_filename (dc, dc->serialization, "");
1825 if (fn == NULL) 1739 if (fn == NULL)
1826 {
1827 GNUNET_free (dc->serialization);
1828 dc->serialization = NULL;
1829 GNUNET_free (fn);
1830 return;
1831 }
1832 }
1833 wh = GNUNET_BIO_write_open (fn);
1834 if (wh == NULL)
1835 { 1740 {
1836 GNUNET_free (dc->serialization); 1741 GNUNET_free (dc->serialization);
1837 dc->serialization = NULL; 1742 dc->serialization = NULL;
1838 GNUNET_free (fn); 1743 GNUNET_free (fn);
1839 return; 1744 return;
1840 } 1745 }
1841 GNUNET_assert ( (GNUNET_YES == GNUNET_FS_uri_test_chk (dc->uri)) || 1746 }
1842 (GNUNET_YES == GNUNET_FS_uri_test_loc (dc->uri)) ); 1747 wh = GNUNET_BIO_write_open (fn);
1748 if (wh == NULL)
1749 {
1750 GNUNET_free (dc->serialization);
1751 dc->serialization = NULL;
1752 GNUNET_free (fn);
1753 return;
1754 }
1755 GNUNET_assert ((GNUNET_YES == GNUNET_FS_uri_test_chk (dc->uri)) ||
1756 (GNUNET_YES == GNUNET_FS_uri_test_loc (dc->uri)));
1843 uris = GNUNET_FS_uri_to_string (dc->uri); 1757 uris = GNUNET_FS_uri_to_string (dc->uri);
1844 if ( (GNUNET_OK != 1758 if ((GNUNET_OK !=
1845 GNUNET_BIO_write_string (wh, uris)) || 1759 GNUNET_BIO_write_string (wh, uris)) ||
1846 (GNUNET_OK != 1760 (GNUNET_OK !=
1847 GNUNET_BIO_write_meta_data (wh, dc->meta)) || 1761 GNUNET_BIO_write_meta_data (wh, dc->meta)) ||
1848 (GNUNET_OK != 1762 (GNUNET_OK !=
1849 GNUNET_BIO_write_string (wh, dc->emsg)) || 1763 GNUNET_BIO_write_string (wh, dc->emsg)) ||
1850 (GNUNET_OK != 1764 (GNUNET_OK !=
1851 GNUNET_BIO_write_string (wh, dc->filename)) || 1765 GNUNET_BIO_write_string (wh, dc->filename)) ||
1852 (GNUNET_OK != 1766 (GNUNET_OK !=
1853 GNUNET_BIO_write_string (wh, dc->temp_filename)) || 1767 GNUNET_BIO_write_string (wh, dc->temp_filename)) ||
1854 (GNUNET_OK != 1768 (GNUNET_OK !=
1855 GNUNET_BIO_write_int64 (wh, dc->old_file_size)) || 1769 GNUNET_BIO_write_int64 (wh, dc->old_file_size)) ||
1856 (GNUNET_OK != 1770 (GNUNET_OK !=
1857 GNUNET_BIO_write_int64 (wh, dc->offset)) || 1771 GNUNET_BIO_write_int64 (wh, dc->offset)) ||
1858 (GNUNET_OK != 1772 (GNUNET_OK !=
1859 GNUNET_BIO_write_int64 (wh, dc->length)) || 1773 GNUNET_BIO_write_int64 (wh, dc->length)) ||
1860 (GNUNET_OK != 1774 (GNUNET_OK !=
1861 GNUNET_BIO_write_int64 (wh, dc->completed)) || 1775 GNUNET_BIO_write_int64 (wh, dc->completed)) ||
1862 (GNUNET_OK != 1776 (GNUNET_OK !=
1863 write_start_time (wh, dc->start_time)) || 1777 write_start_time (wh, dc->start_time)) ||
1864 (GNUNET_OK != 1778 (GNUNET_OK !=
1865 GNUNET_BIO_write_int32 (wh, dc->anonymity)) || 1779 GNUNET_BIO_write_int32 (wh, dc->anonymity)) ||
1866 (GNUNET_OK != 1780 (GNUNET_OK !=
1867 GNUNET_BIO_write_int32 (wh, (uint32_t) dc->options)) || 1781 GNUNET_BIO_write_int32 (wh, (uint32_t) dc->options)) ||
1868 (GNUNET_OK != 1782 (GNUNET_OK != GNUNET_BIO_write_int32 (wh, (uint32_t) dc->has_finished)))
1869 GNUNET_BIO_write_int32 (wh, (uint32_t) dc->has_finished)) ) 1783 {
1870 { 1784 GNUNET_break (0);
1871 GNUNET_break (0); 1785 goto cleanup;
1872 goto cleanup; 1786 }
1873 }
1874 if (NULL == dc->emsg) 1787 if (NULL == dc->emsg)
1788 {
1789 GNUNET_assert (dc->top_request != NULL);
1790 if (GNUNET_YES != write_download_request (wh, dc->top_request))
1875 { 1791 {
1876 GNUNET_assert (dc->top_request != NULL);
1877 if (GNUNET_YES !=
1878 write_download_request (wh, dc->top_request))
1879 {
1880 GNUNET_break (0);
1881 goto cleanup;
1882 }
1883 }
1884 GNUNET_free_non_null (uris);
1885 uris = NULL;
1886 if (GNUNET_OK !=
1887 GNUNET_BIO_write_close (wh))
1888 {
1889 wh = NULL;
1890 GNUNET_break (0); 1792 GNUNET_break (0);
1891 goto cleanup; 1793 goto cleanup;
1892 } 1794 }
1795 }
1796 GNUNET_free_non_null (uris);
1797 uris = NULL;
1798 if (GNUNET_OK != GNUNET_BIO_write_close (wh))
1799 {
1800 wh = NULL;
1801 GNUNET_break (0);
1802 goto cleanup;
1803 }
1893 GNUNET_free (fn); 1804 GNUNET_free (fn);
1894 return; 1805 return;
1895 cleanup: 1806cleanup:
1896 if (NULL != wh) 1807 if (NULL != wh)
1897 (void) GNUNET_BIO_write_close (wh); 1808 (void) GNUNET_BIO_write_close (wh);
1898 GNUNET_free_non_null (uris); 1809 GNUNET_free_non_null (uris);
@@ -1921,65 +1832,65 @@ GNUNET_FS_search_result_sync_ (struct GNUNET_FS_SearchResult *sr)
1921 uris = NULL; 1832 uris = NULL;
1922 if (NULL == sr->serialization) 1833 if (NULL == sr->serialization)
1923 sr->serialization = make_serialization_file_name_in_dir (sr->sc->h, 1834 sr->serialization = make_serialization_file_name_in_dir (sr->sc->h,
1924 (sr->sc->psearch_result == NULL) 1835 (sr->
1925 ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH 1836 sc->psearch_result
1926 : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, 1837 ==
1927 sr->sc->serialization); 1838 NULL) ?
1839 GNUNET_FS_SYNC_PATH_MASTER_SEARCH
1840 :
1841 GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
1842 sr->
1843 sc->serialization);
1928 if (NULL == sr->serialization) 1844 if (NULL == sr->serialization)
1929 return; 1845 return;
1930 wh = get_write_handle_in_dir (sr->sc->h, 1846 wh = get_write_handle_in_dir (sr->sc->h,
1931 (sr->sc->psearch_result == NULL) 1847 (sr->sc->psearch_result == NULL)
1932 ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH 1848 ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH
1933 : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, 1849 : GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
1934 sr->sc->serialization, 1850 sr->sc->serialization, sr->serialization);
1935 sr->serialization);
1936 if (wh == NULL) 1851 if (wh == NULL)
1937 { 1852 {
1938 GNUNET_break (0); 1853 GNUNET_break (0);
1939 goto cleanup; 1854 goto cleanup;
1940 } 1855 }
1941 uris = GNUNET_FS_uri_to_string (sr->uri); 1856 uris = GNUNET_FS_uri_to_string (sr->uri);
1942 if ( (GNUNET_OK != 1857 if ((GNUNET_OK !=
1943 GNUNET_BIO_write_string (wh, uris)) || 1858 GNUNET_BIO_write_string (wh, uris)) ||
1944 (GNUNET_OK != 1859 (GNUNET_OK !=
1945 GNUNET_BIO_write_string (wh, sr->download != NULL ? sr->download->serialization : NULL)) || 1860 GNUNET_BIO_write_string (wh,
1946 (GNUNET_OK != 1861 sr->download !=
1947 GNUNET_BIO_write_string (wh, sr->update_search != NULL ? sr->update_search->serialization : NULL)) || 1862 NULL ? sr->download->serialization : NULL)) ||
1948 (GNUNET_OK != 1863 (GNUNET_OK !=
1949 GNUNET_BIO_write_meta_data (wh, sr->meta)) || 1864 GNUNET_BIO_write_string (wh,
1950 (GNUNET_OK != 1865 sr->update_search !=
1951 GNUNET_BIO_write (wh, &sr->key, sizeof (GNUNET_HashCode))) || 1866 NULL ? sr->update_search->serialization : NULL))
1952 (GNUNET_OK != 1867 || (GNUNET_OK != GNUNET_BIO_write_meta_data (wh, sr->meta)) ||
1953 GNUNET_BIO_write_int32 (wh, sr->mandatory_missing)) || 1868 (GNUNET_OK != GNUNET_BIO_write (wh, &sr->key, sizeof (GNUNET_HashCode)))
1954 (GNUNET_OK != 1869 || (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sr->mandatory_missing)) ||
1955 GNUNET_BIO_write_int32 (wh, sr->optional_support)) || 1870 (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sr->optional_support)) ||
1956 (GNUNET_OK != 1871 (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sr->availability_success)) ||
1957 GNUNET_BIO_write_int32 (wh, sr->availability_success)) || 1872 (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sr->availability_trials)))
1958 (GNUNET_OK != 1873 {
1959 GNUNET_BIO_write_int32 (wh, sr->availability_trials)) ) 1874 GNUNET_break (0);
1960 { 1875 goto cleanup;
1961 GNUNET_break (0); 1876 }
1962 goto cleanup; 1877 if (GNUNET_OK != GNUNET_BIO_write_close (wh))
1963 } 1878 {
1964 if (GNUNET_OK != 1879 wh = NULL;
1965 GNUNET_BIO_write_close (wh)) 1880 GNUNET_break (0);
1966 { 1881 goto cleanup;
1967 wh = NULL; 1882 }
1968 GNUNET_break (0);
1969 goto cleanup;
1970 }
1971 GNUNET_free_non_null (uris); 1883 GNUNET_free_non_null (uris);
1972 return; 1884 return;
1973 cleanup: 1885cleanup:
1974 GNUNET_free_non_null (uris); 1886 GNUNET_free_non_null (uris);
1975 if (wh != NULL) 1887 if (wh != NULL)
1976 (void) GNUNET_BIO_write_close (wh); 1888 (void) GNUNET_BIO_write_close (wh);
1977 remove_sync_file_in_dir (sr->sc->h, 1889 remove_sync_file_in_dir (sr->sc->h,
1978 (sr->sc->psearch_result == NULL) 1890 (sr->sc->psearch_result == NULL)
1979 ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH 1891 ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH
1980 : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, 1892 : GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
1981 sr->sc->serialization, 1893 sr->sc->serialization, sr->serialization);
1982 sr->serialization);
1983 GNUNET_free (sr->serialization); 1894 GNUNET_free (sr->serialization);
1984 sr->serialization = NULL; 1895 sr->serialization = NULL;
1985} 1896}
@@ -1995,58 +1906,54 @@ GNUNET_FS_search_result_sync_ (struct GNUNET_FS_SearchResult *sr)
1995 */ 1906 */
1996void 1907void
1997GNUNET_FS_search_sync_ (struct GNUNET_FS_SearchContext *sc) 1908GNUNET_FS_search_sync_ (struct GNUNET_FS_SearchContext *sc)
1998{ 1909{
1999 struct GNUNET_BIO_WriteHandle *wh; 1910 struct GNUNET_BIO_WriteHandle *wh;
2000 char *uris; 1911 char *uris;
2001 char in_pause; 1912 char in_pause;
2002 const char *category; 1913 const char *category;
2003 1914
2004 category = (sc->psearch_result == NULL) 1915 category = (sc->psearch_result == NULL)
2005 ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH 1916 ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH : GNUNET_FS_SYNC_PATH_CHILD_SEARCH;
2006 : GNUNET_FS_SYNC_PATH_CHILD_SEARCH;
2007 if (NULL == sc->serialization) 1917 if (NULL == sc->serialization)
2008 sc->serialization = make_serialization_file_name (sc->h, 1918 sc->serialization = make_serialization_file_name (sc->h, category);
2009 category);
2010 if (NULL == sc->serialization) 1919 if (NULL == sc->serialization)
2011 return; 1920 return;
2012 uris = NULL; 1921 uris = NULL;
2013 wh = get_write_handle (sc->h, category, sc->serialization); 1922 wh = get_write_handle (sc->h, category, sc->serialization);
2014 if (wh == NULL) 1923 if (wh == NULL)
2015 { 1924 {
2016 GNUNET_break (0); 1925 GNUNET_break (0);
2017 goto cleanup; 1926 goto cleanup;
2018 } 1927 }
2019 GNUNET_assert ( (GNUNET_YES == GNUNET_FS_uri_test_ksk (sc->uri)) || 1928 GNUNET_assert ((GNUNET_YES == GNUNET_FS_uri_test_ksk (sc->uri)) ||
2020 (GNUNET_YES == GNUNET_FS_uri_test_sks (sc->uri)) ); 1929 (GNUNET_YES == GNUNET_FS_uri_test_sks (sc->uri)));
2021 uris = GNUNET_FS_uri_to_string (sc->uri); 1930 uris = GNUNET_FS_uri_to_string (sc->uri);
2022 in_pause = (sc->task != GNUNET_SCHEDULER_NO_TASK) ? 'r' : '\0'; 1931 in_pause = (sc->task != GNUNET_SCHEDULER_NO_TASK) ? 'r' : '\0';
2023 if ( (GNUNET_OK != 1932 if ((GNUNET_OK !=
2024 GNUNET_BIO_write_string (wh, uris)) || 1933 GNUNET_BIO_write_string (wh, uris)) ||
2025 (GNUNET_OK != 1934 (GNUNET_OK !=
2026 write_start_time (wh, sc->start_time)) || 1935 write_start_time (wh, sc->start_time)) ||
2027 (GNUNET_OK != 1936 (GNUNET_OK !=
2028 GNUNET_BIO_write_string (wh, sc->emsg)) || 1937 GNUNET_BIO_write_string (wh, sc->emsg)) ||
2029 (GNUNET_OK != 1938 (GNUNET_OK !=
2030 GNUNET_BIO_write_int32 (wh, (uint32_t) sc->options)) || 1939 GNUNET_BIO_write_int32 (wh, (uint32_t) sc->options)) ||
2031 (GNUNET_OK != 1940 (GNUNET_OK !=
2032 GNUNET_BIO_write (wh, &in_pause, sizeof (in_pause))) || 1941 GNUNET_BIO_write (wh, &in_pause, sizeof (in_pause))) ||
2033 (GNUNET_OK != 1942 (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sc->anonymity)))
2034 GNUNET_BIO_write_int32 (wh, sc->anonymity)) ) 1943 {
2035 { 1944 GNUNET_break (0);
2036 GNUNET_break (0); 1945 goto cleanup;
2037 goto cleanup; 1946 }
2038 }
2039 GNUNET_free (uris); 1947 GNUNET_free (uris);
2040 uris = NULL; 1948 uris = NULL;
2041 if (GNUNET_OK != 1949 if (GNUNET_OK != GNUNET_BIO_write_close (wh))
2042 GNUNET_BIO_write_close (wh)) 1950 {
2043 { 1951 wh = NULL;
2044 wh = NULL; 1952 GNUNET_break (0);
2045 GNUNET_break (0); 1953 goto cleanup;
2046 goto cleanup; 1954 }
2047 }
2048 return; 1955 return;
2049 cleanup: 1956cleanup:
2050 if (wh != NULL) 1957 if (wh != NULL)
2051 (void) GNUNET_BIO_write_close (wh); 1958 (void) GNUNET_BIO_write_close (wh);
2052 GNUNET_free_non_null (uris); 1959 GNUNET_free_non_null (uris);
@@ -2065,8 +1972,7 @@ GNUNET_FS_search_sync_ (struct GNUNET_FS_SearchContext *sc)
2065 * @return GNUNET_OK (continue to iterate) 1972 * @return GNUNET_OK (continue to iterate)
2066 */ 1973 */
2067static int 1974static int
2068deserialize_unindex_file (void *cls, 1975deserialize_unindex_file (void *cls, const char *filename)
2069 const char *filename)
2070{ 1976{
2071 struct GNUNET_FS_Handle *h = cls; 1977 struct GNUNET_FS_Handle *h = cls;
2072 struct GNUNET_BIO_ReadHandle *rh; 1978 struct GNUNET_BIO_ReadHandle *rh;
@@ -2080,109 +1986,100 @@ deserialize_unindex_file (void *cls,
2080 uc->serialization = get_serialization_short_name (filename); 1986 uc->serialization = get_serialization_short_name (filename);
2081 rh = GNUNET_BIO_read_open (filename); 1987 rh = GNUNET_BIO_read_open (filename);
2082 if (rh == NULL) 1988 if (rh == NULL)
1989 {
1990 GNUNET_break (0);
1991 goto cleanup;
1992 }
1993 if ((GNUNET_OK !=
1994 GNUNET_BIO_read_string (rh, "unindex-fn", &uc->filename, 10 * 1024)) ||
1995 (GNUNET_OK !=
1996 GNUNET_BIO_read_int64 (rh, &uc->file_size)) ||
1997 (GNUNET_OK !=
1998 read_start_time (rh, &uc->start_time)) ||
1999 (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &state)))
2000 {
2001 GNUNET_break (0);
2002 goto cleanup;
2003 }
2004 uc->state = (enum UnindexState) state;
2005 switch (state)
2006 {
2007 case UNINDEX_STATE_HASHING:
2008 break;
2009 case UNINDEX_STATE_FS_NOTIFY:
2010 if (GNUNET_OK !=
2011 GNUNET_BIO_read (rh, "unindex-hash", &uc->file_id,
2012 sizeof (GNUNET_HashCode)))
2083 { 2013 {
2084 GNUNET_break (0); 2014 GNUNET_break (0);
2085 goto cleanup; 2015 goto cleanup;
2086 } 2016 }
2087 if ( (GNUNET_OK != 2017 break;
2088 GNUNET_BIO_read_string (rh, "unindex-fn", &uc->filename, 10*1024)) || 2018 case UNINDEX_STATE_DS_REMOVE:
2089 (GNUNET_OK != 2019 break;
2090 GNUNET_BIO_read_int64 (rh, &uc->file_size)) || 2020 case UNINDEX_STATE_COMPLETE:
2091 (GNUNET_OK != 2021 break;
2092 read_start_time (rh, &uc->start_time)) || 2022 case UNINDEX_STATE_ERROR:
2093 (GNUNET_OK != 2023 if (GNUNET_OK !=
2094 GNUNET_BIO_read_int32 (rh, &state)) ) 2024 GNUNET_BIO_read_string (rh, "unindex-emsg", &uc->emsg, 10 * 1024))
2095 { 2025 {
2096 GNUNET_break (0);
2097 goto cleanup;
2098 }
2099 uc->state = (enum UnindexState) state;
2100 switch (state)
2101 {
2102 case UNINDEX_STATE_HASHING:
2103 break;
2104 case UNINDEX_STATE_FS_NOTIFY:
2105 if (GNUNET_OK !=
2106 GNUNET_BIO_read (rh, "unindex-hash", &uc->file_id, sizeof (GNUNET_HashCode)))
2107 {
2108 GNUNET_break (0);
2109 goto cleanup;
2110 }
2111 break;
2112 case UNINDEX_STATE_DS_REMOVE:
2113 break;
2114 case UNINDEX_STATE_COMPLETE:
2115 break;
2116 case UNINDEX_STATE_ERROR:
2117 if (GNUNET_OK !=
2118 GNUNET_BIO_read_string (rh, "unindex-emsg", &uc->emsg, 10*1024))
2119 {
2120 GNUNET_break (0);
2121 goto cleanup;
2122 }
2123 break;
2124 default:
2125 GNUNET_break (0); 2026 GNUNET_break (0);
2126 goto cleanup; 2027 goto cleanup;
2127 } 2028 }
2128 uc->top = GNUNET_FS_make_top (h, 2029 break;
2129 &GNUNET_FS_unindex_signal_suspend_, 2030 default:
2130 uc); 2031 GNUNET_break (0);
2032 goto cleanup;
2033 }
2034 uc->top = GNUNET_FS_make_top (h, &GNUNET_FS_unindex_signal_suspend_, uc);
2131 pi.status = GNUNET_FS_STATUS_UNINDEX_RESUME; 2035 pi.status = GNUNET_FS_STATUS_UNINDEX_RESUME;
2132 pi.value.unindex.specifics.resume.message = uc->emsg; 2036 pi.value.unindex.specifics.resume.message = uc->emsg;
2133 GNUNET_FS_unindex_make_status_ (&pi, 2037 GNUNET_FS_unindex_make_status_ (&pi,
2134 uc, 2038 uc,
2135 (uc->state == UNINDEX_STATE_COMPLETE) 2039 (uc->state == UNINDEX_STATE_COMPLETE)
2136 ? uc->file_size 2040 ? uc->file_size : 0);
2137 : 0);
2138 switch (uc->state) 2041 switch (uc->state)
2139 { 2042 {
2140 case UNINDEX_STATE_HASHING: 2043 case UNINDEX_STATE_HASHING:
2141 uc->fhc = GNUNET_CRYPTO_hash_file (GNUNET_SCHEDULER_PRIORITY_IDLE, 2044 uc->fhc = GNUNET_CRYPTO_hash_file (GNUNET_SCHEDULER_PRIORITY_IDLE,
2142 uc->filename, 2045 uc->filename,
2143 HASHING_BLOCKSIZE, 2046 HASHING_BLOCKSIZE,
2144 &GNUNET_FS_unindex_process_hash_, 2047 &GNUNET_FS_unindex_process_hash_, uc);
2145 uc); 2048 break;
2146 break; 2049 case UNINDEX_STATE_FS_NOTIFY:
2147 case UNINDEX_STATE_FS_NOTIFY: 2050 uc->state = UNINDEX_STATE_HASHING;
2148 uc->state = UNINDEX_STATE_HASHING; 2051 GNUNET_FS_unindex_process_hash_ (uc, &uc->file_id);
2149 GNUNET_FS_unindex_process_hash_ (uc, 2052 break;
2150 &uc->file_id); 2053 case UNINDEX_STATE_DS_REMOVE:
2151 break; 2054 GNUNET_FS_unindex_do_remove_ (uc);
2152 case UNINDEX_STATE_DS_REMOVE: 2055 break;
2153 GNUNET_FS_unindex_do_remove_ (uc); 2056 case UNINDEX_STATE_COMPLETE:
2154 break; 2057 case UNINDEX_STATE_ERROR:
2155 case UNINDEX_STATE_COMPLETE: 2058 /* no need to resume any operation, we were done */
2156 case UNINDEX_STATE_ERROR: 2059 break;
2157 /* no need to resume any operation, we were done */ 2060 default:
2158 break; 2061 break;
2159 default: 2062 }
2160 break; 2063 if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
2161 } 2064 {
2162 if (GNUNET_OK != 2065 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2163 GNUNET_BIO_read_close (rh, &emsg)) 2066 _("Failure while resuming unindexing operation `%s': %s\n"),
2164 { 2067 filename, emsg);
2165 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2068 GNUNET_free (emsg);
2166 _("Failure while resuming unindexing operation `%s': %s\n"), 2069 }
2167 filename,
2168 emsg);
2169 GNUNET_free (emsg);
2170 }
2171 return GNUNET_OK; 2070 return GNUNET_OK;
2172 cleanup: 2071cleanup:
2173 GNUNET_free_non_null (uc->filename); 2072 GNUNET_free_non_null (uc->filename);
2174 if ( (rh != NULL) && 2073 if ((rh != NULL) && (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)))
2175 (GNUNET_OK != 2074 {
2176 GNUNET_BIO_read_close (rh, &emsg)) ) 2075 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2177 { 2076 _("Failed to resume unindexing operation `%s': %s\n"),
2178 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2077 filename, emsg);
2179 _("Failed to resume unindexing operation `%s': %s\n"), 2078 GNUNET_free (emsg);
2180 filename, 2079 }
2181 emsg);
2182 GNUNET_free (emsg);
2183 }
2184 if (uc->serialization != NULL) 2080 if (uc->serialization != NULL)
2185 GNUNET_FS_remove_sync_file_ (h, GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, uc->serialization); 2081 GNUNET_FS_remove_sync_file_ (h, GNUNET_FS_SYNC_PATH_MASTER_UNINDEX,
2082 uc->serialization);
2186 GNUNET_free_non_null (uc->serialization); 2083 GNUNET_free_non_null (uc->serialization);
2187 GNUNET_free (uc); 2084 GNUNET_free (uc);
2188 return GNUNET_OK; 2085 return GNUNET_OK;
@@ -2200,10 +2097,10 @@ deserialize_unindex_file (void *cls,
2200 */ 2097 */
2201static void 2098static void
2202deserialize_download (struct GNUNET_FS_Handle *h, 2099deserialize_download (struct GNUNET_FS_Handle *h,
2203 struct GNUNET_BIO_ReadHandle *rh, 2100 struct GNUNET_BIO_ReadHandle *rh,
2204 struct GNUNET_FS_DownloadContext *parent, 2101 struct GNUNET_FS_DownloadContext *parent,
2205 struct GNUNET_FS_SearchResult *search, 2102 struct GNUNET_FS_SearchResult *search,
2206 const char *serialization); 2103 const char *serialization);
2207 2104
2208 2105
2209/** 2106/**
@@ -2214,11 +2111,16 @@ deserialize_download (struct GNUNET_FS_Handle *h,
2214 * @param psearch_result parent search result 2111 * @param psearch_result parent search result
2215 * @param serialization name under which the search was serialized 2112 * @param serialization name under which the search was serialized
2216 */ 2113 */
2217static struct GNUNET_FS_SearchContext * 2114static struct GNUNET_FS_SearchContext *deserialize_search (struct
2218deserialize_search (struct GNUNET_FS_Handle *h, 2115 GNUNET_FS_Handle *h,
2219 struct GNUNET_BIO_ReadHandle *rh, 2116 struct
2220 struct GNUNET_FS_SearchResult *psearch_result, 2117 GNUNET_BIO_ReadHandle
2221 const char *serialization); 2118 *rh,
2119 struct
2120 GNUNET_FS_SearchResult
2121 *psearch_result,
2122 const char
2123 *serialization);
2222 2124
2223 2125
2224/** 2126/**
@@ -2230,8 +2132,7 @@ deserialize_search (struct GNUNET_FS_Handle *h,
2230 * @return GNUNET_OK (continue to iterate) 2132 * @return GNUNET_OK (continue to iterate)
2231 */ 2133 */
2232static int 2134static int
2233deserialize_search_result (void *cls, 2135deserialize_search_result (void *cls, const char *filename)
2234 const char *filename)
2235{ 2136{
2236 struct GNUNET_FS_SearchContext *sc = cls; 2137 struct GNUNET_FS_SearchContext *sc = cls;
2237 char *ser; 2138 char *ser;
@@ -2246,130 +2147,107 @@ deserialize_search_result (void *cls,
2246 ser = get_serialization_short_name (filename); 2147 ser = get_serialization_short_name (filename);
2247 rh = GNUNET_BIO_read_open (filename); 2148 rh = GNUNET_BIO_read_open (filename);
2248 if (rh == NULL) 2149 if (rh == NULL)
2249 { 2150 {
2250 if (ser != NULL) 2151 if (ser != NULL)
2251 { 2152 {
2252 remove_sync_file_in_dir (sc->h, 2153 remove_sync_file_in_dir (sc->h,
2253 (sc->psearch_result == NULL) 2154 (sc->psearch_result == NULL)
2254 ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH 2155 ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH
2255 : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, 2156 : GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
2256 sc->serialization, 2157 sc->serialization, ser);
2257 ser); 2158 GNUNET_free (ser);
2258 GNUNET_free (ser);
2259 }
2260 return GNUNET_OK;
2261 } 2159 }
2160 return GNUNET_OK;
2161 }
2262 emsg = NULL; 2162 emsg = NULL;
2263 uris = NULL; 2163 uris = NULL;
2264 download = NULL; 2164 download = NULL;
2265 update_srch = NULL; 2165 update_srch = NULL;
2266 sr = GNUNET_malloc (sizeof (struct GNUNET_FS_SearchResult)); 2166 sr = GNUNET_malloc (sizeof (struct GNUNET_FS_SearchResult));
2267 sr->serialization = ser; 2167 sr->serialization = ser;
2268 if ( (GNUNET_OK != 2168 if ((GNUNET_OK !=
2269 GNUNET_BIO_read_string (rh, "result-uri", &uris, 10*1024)) || 2169 GNUNET_BIO_read_string (rh, "result-uri", &uris, 10 * 1024)) ||
2270 (NULL == (sr->uri = GNUNET_FS_uri_parse (uris, &emsg))) || 2170 (NULL == (sr->uri = GNUNET_FS_uri_parse (uris, &emsg))) ||
2271 (GNUNET_OK != 2171 (GNUNET_OK !=
2272 GNUNET_BIO_read_string (rh, "download-lnk", &download, 16)) || 2172 GNUNET_BIO_read_string (rh, "download-lnk", &download, 16)) ||
2273 (GNUNET_OK != 2173 (GNUNET_OK !=
2274 GNUNET_BIO_read_string (rh, "search-lnk", &update_srch, 16)) || 2174 GNUNET_BIO_read_string (rh, "search-lnk", &update_srch, 16)) ||
2275 (GNUNET_OK != 2175 (GNUNET_OK !=
2276 GNUNET_BIO_read_meta_data (rh, "result-meta", &sr->meta)) || 2176 GNUNET_BIO_read_meta_data (rh, "result-meta", &sr->meta)) ||
2277 (GNUNET_OK != 2177 (GNUNET_OK !=
2278 GNUNET_BIO_read (rh, "result-key", &sr->key, sizeof (GNUNET_HashCode))) || 2178 GNUNET_BIO_read (rh, "result-key", &sr->key, sizeof (GNUNET_HashCode)))
2279 (GNUNET_OK != 2179 || (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sr->mandatory_missing)) ||
2280 GNUNET_BIO_read_int32 (rh, &sr->mandatory_missing)) || 2180 (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sr->optional_support)) ||
2281 (GNUNET_OK != 2181 (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sr->availability_success)) ||
2282 GNUNET_BIO_read_int32 (rh, &sr->optional_support)) || 2182 (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sr->availability_trials)))
2283 (GNUNET_OK != 2183 {
2284 GNUNET_BIO_read_int32 (rh, &sr->availability_success)) || 2184 GNUNET_break (0);
2285 (GNUNET_OK != 2185 goto cleanup;
2286 GNUNET_BIO_read_int32 (rh, &sr->availability_trials)) ) 2186 }
2287 {
2288 GNUNET_break (0);
2289 goto cleanup;
2290 }
2291 GNUNET_free (uris); 2187 GNUNET_free (uris);
2292 if (download != NULL) 2188 if (download != NULL)
2293 { 2189 {
2294 drh = get_read_handle (sc->h, 2190 drh = get_read_handle (sc->h, GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD, download);
2295 GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD, 2191 if (drh != NULL)
2296 download); 2192 {
2297 if (drh != NULL) 2193 deserialize_download (sc->h, drh, NULL, sr, download);
2298 { 2194 if (GNUNET_OK != GNUNET_BIO_read_close (drh, &emsg))
2299 deserialize_download (sc->h, 2195 {
2300 drh, 2196 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2301 NULL, 2197 _("Failed to resume sub-download `%s': %s\n"),
2302 sr, 2198 download, emsg);
2303 download); 2199 GNUNET_free (emsg);
2304 if (GNUNET_OK != 2200 }
2305 GNUNET_BIO_read_close (drh, &emsg)) 2201 }
2306 { 2202 GNUNET_free (download);
2307 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2203 }
2308 _("Failed to resume sub-download `%s': %s\n"),
2309 download,
2310 emsg);
2311 GNUNET_free (emsg);
2312 }
2313 }
2314 GNUNET_free (download);
2315 }
2316 if (update_srch != NULL) 2204 if (update_srch != NULL)
2317 { 2205 {
2318 drh = get_read_handle (sc->h, 2206 drh = get_read_handle (sc->h,
2319 GNUNET_FS_SYNC_PATH_CHILD_SEARCH, 2207 GNUNET_FS_SYNC_PATH_CHILD_SEARCH, update_srch);
2320 update_srch); 2208 if (drh != NULL)
2321 if (drh != NULL) 2209 {
2322 { 2210 deserialize_search (sc->h, drh, sr, update_srch);
2323 deserialize_search (sc->h, 2211 if (GNUNET_OK != GNUNET_BIO_read_close (drh, &emsg))
2324 drh, 2212 {
2325 sr, 2213 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2326 update_srch); 2214 _("Failed to resume sub-search `%s': %s\n"),
2327 if (GNUNET_OK != 2215 update_srch, emsg);
2328 GNUNET_BIO_read_close (drh, &emsg)) 2216 GNUNET_free (emsg);
2329 { 2217 }
2330 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2218 }
2331 _("Failed to resume sub-search `%s': %s\n"), 2219 GNUNET_free (update_srch);
2332 update_srch, 2220 }
2333 emsg);
2334 GNUNET_free (emsg);
2335 }
2336 }
2337 GNUNET_free (update_srch);
2338 }
2339 GNUNET_CONTAINER_multihashmap_put (sc->master_result_map, 2221 GNUNET_CONTAINER_multihashmap_put (sc->master_result_map,
2340 &sr->key, 2222 &sr->key,
2341 sr, 2223 sr,
2342 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 2224 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
2343 if (GNUNET_OK != 2225 if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
2344 GNUNET_BIO_read_close (rh, &emsg)) 2226 {
2345 { 2227 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2346 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2228 _("Failure while resuming search operation `%s': %s\n"),
2347 _("Failure while resuming search operation `%s': %s\n"), 2229 filename, emsg);
2348 filename, 2230 GNUNET_free (emsg);
2349 emsg); 2231 }
2350 GNUNET_free (emsg);
2351 }
2352 return GNUNET_OK; 2232 return GNUNET_OK;
2353 cleanup: 2233cleanup:
2354 GNUNET_free_non_null (download); 2234 GNUNET_free_non_null (download);
2355 GNUNET_free_non_null (emsg); 2235 GNUNET_free_non_null (emsg);
2356 GNUNET_free_non_null (uris); 2236 GNUNET_free_non_null (uris);
2357 GNUNET_free_non_null (update_srch); 2237 GNUNET_free_non_null (update_srch);
2358 if (sr->uri != NULL) 2238 if (sr->uri != NULL)
2359 GNUNET_FS_uri_destroy (sr->uri); 2239 GNUNET_FS_uri_destroy (sr->uri);
2360 if (sr->meta != NULL) 2240 if (sr->meta != NULL)
2361 GNUNET_CONTAINER_meta_data_destroy (sr->meta); 2241 GNUNET_CONTAINER_meta_data_destroy (sr->meta);
2362 GNUNET_free (sr->serialization); 2242 GNUNET_free (sr->serialization);
2363 GNUNET_free (sr); 2243 GNUNET_free (sr);
2364 if (GNUNET_OK != 2244 if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
2365 GNUNET_BIO_read_close (rh, &emsg)) 2245 {
2366 { 2246 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2367 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2247 _("Failure while resuming search operation `%s': %s\n"),
2368 _("Failure while resuming search operation `%s': %s\n"), 2248 filename, emsg);
2369 filename, 2249 GNUNET_free (emsg);
2370 emsg); 2250 }
2371 GNUNET_free (emsg);
2372 }
2373 return GNUNET_OK; 2251 return GNUNET_OK;
2374} 2252}
2375 2253
@@ -2387,18 +2265,17 @@ signal_download_resume (struct GNUNET_FS_DownloadContext *dc)
2387{ 2265{
2388 struct GNUNET_FS_DownloadContext *dcc; 2266 struct GNUNET_FS_DownloadContext *dcc;
2389 struct GNUNET_FS_ProgressInfo pi; 2267 struct GNUNET_FS_ProgressInfo pi;
2390 2268
2391 pi.status = GNUNET_FS_STATUS_DOWNLOAD_RESUME; 2269 pi.status = GNUNET_FS_STATUS_DOWNLOAD_RESUME;
2392 pi.value.download.specifics.resume.meta = dc->meta; 2270 pi.value.download.specifics.resume.meta = dc->meta;
2393 pi.value.download.specifics.resume.message = dc->emsg; 2271 pi.value.download.specifics.resume.message = dc->emsg;
2394 GNUNET_FS_download_make_status_ (&pi, 2272 GNUNET_FS_download_make_status_ (&pi, dc);
2395 dc);
2396 dcc = dc->child_head; 2273 dcc = dc->child_head;
2397 while (NULL != dcc) 2274 while (NULL != dcc)
2398 { 2275 {
2399 signal_download_resume (dcc); 2276 signal_download_resume (dcc);
2400 dcc = dcc->next; 2277 dcc = dcc->next;
2401 } 2278 }
2402 if (dc->pending_head != NULL) 2279 if (dc->pending_head != NULL)
2403 GNUNET_FS_download_start_downloading_ (dc); 2280 GNUNET_FS_download_start_downloading_ (dc);
2404} 2281}
@@ -2410,8 +2287,7 @@ signal_download_resume (struct GNUNET_FS_DownloadContext *dc)
2410 * 2287 *
2411 * @param sc search being resumed 2288 * @param sc search being resumed
2412 */ 2289 */
2413static void 2290static void signal_search_resume (struct GNUNET_FS_SearchContext *sc);
2414signal_search_resume (struct GNUNET_FS_SearchContext *sc);
2415 2291
2416 2292
2417/** 2293/**
@@ -2424,34 +2300,34 @@ signal_search_resume (struct GNUNET_FS_SearchContext *sc);
2424 * @return GNUNET_YES (we should continue to iterate) 2300 * @return GNUNET_YES (we should continue to iterate)
2425 */ 2301 */
2426static int 2302static int
2427signal_result_resume (void *cls, 2303signal_result_resume (void *cls, const GNUNET_HashCode * key, void *value)
2428 const GNUNET_HashCode * key,
2429 void *value)
2430{ 2304{
2431 struct GNUNET_FS_SearchContext *sc = cls; 2305 struct GNUNET_FS_SearchContext *sc = cls;
2432 struct GNUNET_FS_ProgressInfo pi; 2306 struct GNUNET_FS_ProgressInfo pi;
2433 struct GNUNET_FS_SearchResult *sr = value; 2307 struct GNUNET_FS_SearchResult *sr = value;
2434 2308
2435 if (0 == sr->mandatory_missing) 2309 if (0 == sr->mandatory_missing)
2436 { 2310 {
2437 pi.status = GNUNET_FS_STATUS_SEARCH_RESUME_RESULT; 2311 pi.status = GNUNET_FS_STATUS_SEARCH_RESUME_RESULT;
2438 pi.value.search.specifics.resume_result.meta = sr->meta; 2312 pi.value.search.specifics.resume_result.meta = sr->meta;
2439 pi.value.search.specifics.resume_result.uri = sr->uri; 2313 pi.value.search.specifics.resume_result.uri = sr->uri;
2440 pi.value.search.specifics.resume_result.result = sr; 2314 pi.value.search.specifics.resume_result.result = sr;
2441 pi.value.search.specifics.resume_result.availability_rank = 2*sr->availability_success - sr->availability_trials; 2315 pi.value.search.specifics.resume_result.availability_rank =
2442 pi.value.search.specifics.resume_result.availability_certainty = sr->availability_trials; 2316 2 * sr->availability_success - sr->availability_trials;
2443 pi.value.search.specifics.resume_result.applicability_rank = sr->optional_support; 2317 pi.value.search.specifics.resume_result.availability_certainty =
2444 sr->client_info = GNUNET_FS_search_make_status_ (&pi, 2318 sr->availability_trials;
2445 sc); 2319 pi.value.search.specifics.resume_result.applicability_rank =
2446 } 2320 sr->optional_support;
2321 sr->client_info = GNUNET_FS_search_make_status_ (&pi, sc);
2322 }
2447 if (sr->download != NULL) 2323 if (sr->download != NULL)
2448 { 2324 {
2449 signal_download_resume (sr->download); 2325 signal_download_resume (sr->download);
2450 } 2326 }
2451 else 2327 else
2452 { 2328 {
2453 GNUNET_FS_search_start_probe_ (sr); 2329 GNUNET_FS_search_start_probe_ (sr);
2454 } 2330 }
2455 if (sr->update_search != NULL) 2331 if (sr->update_search != NULL)
2456 signal_search_resume (sr->update_search); 2332 signal_search_resume (sr->update_search);
2457 return GNUNET_YES; 2333 return GNUNET_YES;
@@ -2463,8 +2339,7 @@ signal_result_resume (void *cls,
2463 * 2339 *
2464 * @param sc search context to free 2340 * @param sc search context to free
2465 */ 2341 */
2466static void 2342static void free_search_context (struct GNUNET_FS_SearchContext *sc);
2467free_search_context (struct GNUNET_FS_SearchContext *sc);
2468 2343
2469 2344
2470/** 2345/**
@@ -2476,17 +2351,15 @@ free_search_context (struct GNUNET_FS_SearchContext *sc);
2476 * @return GNUNET_YES (we should continue to iterate) 2351 * @return GNUNET_YES (we should continue to iterate)
2477 */ 2352 */
2478static int 2353static int
2479free_result (void *cls, 2354free_result (void *cls, const GNUNET_HashCode * key, void *value)
2480 const GNUNET_HashCode * key,
2481 void *value)
2482{ 2355{
2483 struct GNUNET_FS_SearchResult *sr = value; 2356 struct GNUNET_FS_SearchResult *sr = value;
2484 2357
2485 if (sr->update_search != NULL) 2358 if (sr->update_search != NULL)
2486 { 2359 {
2487 free_search_context (sr->update_search); 2360 free_search_context (sr->update_search);
2488 GNUNET_assert (NULL == sr->update_search); 2361 GNUNET_assert (NULL == sr->update_search);
2489 } 2362 }
2490 GNUNET_CONTAINER_meta_data_destroy (sr->meta); 2363 GNUNET_CONTAINER_meta_data_destroy (sr->meta);
2491 GNUNET_FS_uri_destroy (sr->uri); 2364 GNUNET_FS_uri_destroy (sr->uri);
2492 GNUNET_free (sr); 2365 GNUNET_free (sr);
@@ -2503,29 +2376,28 @@ static void
2503free_search_context (struct GNUNET_FS_SearchContext *sc) 2376free_search_context (struct GNUNET_FS_SearchContext *sc)
2504{ 2377{
2505 if (sc->serialization != NULL) 2378 if (sc->serialization != NULL)
2506 { 2379 {
2507 GNUNET_FS_remove_sync_file_ (sc->h, 2380 GNUNET_FS_remove_sync_file_ (sc->h,
2508 (sc->psearch_result == NULL) 2381 (sc->psearch_result == NULL)
2509 ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH 2382 ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH
2510 : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, 2383 : GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
2511 sc->serialization); 2384 sc->serialization);
2512 GNUNET_FS_remove_sync_dir_ (sc->h, 2385 GNUNET_FS_remove_sync_dir_ (sc->h,
2513 (sc->psearch_result == NULL) 2386 (sc->psearch_result == NULL)
2514 ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH 2387 ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH
2515 : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, 2388 : GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
2516 sc->serialization); 2389 sc->serialization);
2517 } 2390 }
2518 GNUNET_free_non_null (sc->serialization); 2391 GNUNET_free_non_null (sc->serialization);
2519 GNUNET_free_non_null (sc->emsg); 2392 GNUNET_free_non_null (sc->emsg);
2520 if (sc->uri != NULL) 2393 if (sc->uri != NULL)
2521 GNUNET_FS_uri_destroy (sc->uri); 2394 GNUNET_FS_uri_destroy (sc->uri);
2522 if (sc->master_result_map != NULL) 2395 if (sc->master_result_map != NULL)
2523 { 2396 {
2524 GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, 2397 GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map,
2525 &free_result, 2398 &free_result, sc);
2526 sc); 2399 GNUNET_CONTAINER_multihashmap_destroy (sc->master_result_map);
2527 GNUNET_CONTAINER_multihashmap_destroy (sc->master_result_map); 2400 }
2528 }
2529 GNUNET_free (sc); 2401 GNUNET_free (sc);
2530} 2402}
2531 2403
@@ -2539,8 +2411,7 @@ free_search_context (struct GNUNET_FS_SearchContext *sc)
2539 * @return GNUNET_OK (continue to iterate) 2411 * @return GNUNET_OK (continue to iterate)
2540 */ 2412 */
2541static int 2413static int
2542deserialize_subdownload (void *cls, 2414deserialize_subdownload (void *cls, const char *filename)
2543 const char *filename)
2544{ 2415{
2545 struct GNUNET_FS_DownloadContext *parent = cls; 2416 struct GNUNET_FS_DownloadContext *parent = cls;
2546 char *ser; 2417 char *ser;
@@ -2550,28 +2421,21 @@ deserialize_subdownload (void *cls,
2550 ser = get_serialization_short_name (filename); 2421 ser = get_serialization_short_name (filename);
2551 rh = GNUNET_BIO_read_open (filename); 2422 rh = GNUNET_BIO_read_open (filename);
2552 if (rh == NULL) 2423 if (rh == NULL)
2553 { 2424 {
2554 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2425 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2555 _("Failed to resume sub-download `%s': could not open file `%s'\n"), 2426 _
2556 ser, 2427 ("Failed to resume sub-download `%s': could not open file `%s'\n"),
2557 filename); 2428 ser, filename);
2558 GNUNET_free (ser); 2429 GNUNET_free (ser);
2559 return GNUNET_OK; 2430 return GNUNET_OK;
2560 } 2431 }
2561 deserialize_download (parent->h, 2432 deserialize_download (parent->h, rh, parent, NULL, ser);
2562 rh, 2433 if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
2563 parent, 2434 {
2564 NULL, 2435 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2565 ser); 2436 _("Failed to resume sub-download `%s': %s\n"), ser, emsg);
2566 if (GNUNET_OK != 2437 GNUNET_free (emsg);
2567 GNUNET_BIO_read_close (rh, &emsg)) 2438 }
2568 {
2569 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2570 _("Failed to resume sub-download `%s': %s\n"),
2571 ser,
2572 emsg);
2573 GNUNET_free (emsg);
2574 }
2575 GNUNET_free (ser); 2439 GNUNET_free (ser);
2576 return GNUNET_OK; 2440 return GNUNET_OK;
2577} 2441}
@@ -2598,15 +2462,13 @@ free_download_context (struct GNUNET_FS_DownloadContext *dc)
2598 GNUNET_free_non_null (dc->filename); 2462 GNUNET_free_non_null (dc->filename);
2599 GNUNET_free_non_null (dc->serialization); 2463 GNUNET_free_non_null (dc->serialization);
2600 while (NULL != (dcc = dc->child_head)) 2464 while (NULL != (dcc = dc->child_head))
2601 { 2465 {
2602 GNUNET_CONTAINER_DLL_remove (dc->child_head, 2466 GNUNET_CONTAINER_DLL_remove (dc->child_head, dc->child_tail, dcc);
2603 dc->child_tail, 2467 free_download_context (dcc);
2604 dcc); 2468 }
2605 free_download_context (dcc);
2606 }
2607 GNUNET_FS_free_download_request_ (dc->top_request); 2469 GNUNET_FS_free_download_request_ (dc->top_request);
2608 if (NULL != dc->active) 2470 if (NULL != dc->active)
2609 GNUNET_CONTAINER_multihashmap_destroy (dc->active); 2471 GNUNET_CONTAINER_multihashmap_destroy (dc->active);
2610 GNUNET_free (dc); 2472 GNUNET_free (dc);
2611} 2473}
2612 2474
@@ -2622,10 +2484,10 @@ free_download_context (struct GNUNET_FS_DownloadContext *dc)
2622 */ 2484 */
2623static void 2485static void
2624deserialize_download (struct GNUNET_FS_Handle *h, 2486deserialize_download (struct GNUNET_FS_Handle *h,
2625 struct GNUNET_BIO_ReadHandle *rh, 2487 struct GNUNET_BIO_ReadHandle *rh,
2626 struct GNUNET_FS_DownloadContext *parent, 2488 struct GNUNET_FS_DownloadContext *parent,
2627 struct GNUNET_FS_SearchResult *search, 2489 struct GNUNET_FS_SearchResult *search,
2628 const char *serialization) 2490 const char *serialization)
2629{ 2491{
2630 struct GNUNET_FS_DownloadContext *dc; 2492 struct GNUNET_FS_DownloadContext *dc;
2631 char *emsg; 2493 char *emsg;
@@ -2640,89 +2502,77 @@ deserialize_download (struct GNUNET_FS_Handle *h,
2640 dc->parent = parent; 2502 dc->parent = parent;
2641 dc->h = h; 2503 dc->h = h;
2642 dc->serialization = GNUNET_strdup (serialization); 2504 dc->serialization = GNUNET_strdup (serialization);
2643 if ( (GNUNET_OK != 2505 if ((GNUNET_OK !=
2644 GNUNET_BIO_read_string (rh, "download-uri", &uris, 10*1024)) || 2506 GNUNET_BIO_read_string (rh, "download-uri", &uris, 10 * 1024)) ||
2645 (NULL == (dc->uri = GNUNET_FS_uri_parse (uris, &emsg))) || 2507 (NULL == (dc->uri = GNUNET_FS_uri_parse (uris, &emsg))) ||
2646 ( (GNUNET_YES != GNUNET_FS_uri_test_chk (dc->uri)) && 2508 ((GNUNET_YES != GNUNET_FS_uri_test_chk (dc->uri)) &&
2647 (GNUNET_YES != GNUNET_FS_uri_test_loc (dc->uri)) ) || 2509 (GNUNET_YES != GNUNET_FS_uri_test_loc (dc->uri))) ||
2648 (GNUNET_OK != 2510 (GNUNET_OK !=
2649 GNUNET_BIO_read_meta_data (rh, "download-meta", &dc->meta)) || 2511 GNUNET_BIO_read_meta_data (rh, "download-meta", &dc->meta)) ||
2650 (GNUNET_OK != 2512 (GNUNET_OK !=
2651 GNUNET_BIO_read_string (rh, "download-emsg", &dc->emsg, 10*1024)) || 2513 GNUNET_BIO_read_string (rh, "download-emsg", &dc->emsg, 10 * 1024)) ||
2652 (GNUNET_OK != 2514 (GNUNET_OK !=
2653 GNUNET_BIO_read_string (rh, "download-fn", &dc->filename, 10*1024)) || 2515 GNUNET_BIO_read_string (rh, "download-fn", &dc->filename, 10 * 1024)) ||
2654 (GNUNET_OK != 2516 (GNUNET_OK !=
2655 GNUNET_BIO_read_string (rh, "download-tfn", &dc->temp_filename, 10*1024)) || 2517 GNUNET_BIO_read_string (rh, "download-tfn", &dc->temp_filename,
2656 (GNUNET_OK != 2518 10 * 1024)) ||
2657 GNUNET_BIO_read_int64 (rh, &dc->old_file_size)) || 2519 (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dc->old_file_size)) ||
2658 (GNUNET_OK != 2520 (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dc->offset)) ||
2659 GNUNET_BIO_read_int64 (rh, &dc->offset)) || 2521 (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dc->length)) ||
2660 (GNUNET_OK != 2522 (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dc->completed)) ||
2661 GNUNET_BIO_read_int64 (rh, &dc->length)) || 2523 (GNUNET_OK != read_start_time (rh, &dc->start_time)) ||
2662 (GNUNET_OK != 2524 (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &dc->anonymity)) ||
2663 GNUNET_BIO_read_int64 (rh, &dc->completed)) || 2525 (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &options)) ||
2664 (GNUNET_OK != 2526 (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &status)))
2665 read_start_time (rh, &dc->start_time)) || 2527 {
2666 (GNUNET_OK != 2528 GNUNET_break (0);
2667 GNUNET_BIO_read_int32 (rh, &dc->anonymity)) || 2529 goto cleanup;
2668 (GNUNET_OK != 2530 }
2669 GNUNET_BIO_read_int32 (rh, &options)) ||
2670 (GNUNET_OK !=
2671 GNUNET_BIO_read_int32 (rh, &status)) )
2672 {
2673 GNUNET_break (0);
2674 goto cleanup;
2675 }
2676 dc->options = (enum GNUNET_FS_DownloadOptions) options; 2531 dc->options = (enum GNUNET_FS_DownloadOptions) options;
2677 dc->active = GNUNET_CONTAINER_multihashmap_create (1 + 2 * (dc->length / DBLOCK_SIZE)); 2532 dc->active =
2533 GNUNET_CONTAINER_multihashmap_create (1 + 2 * (dc->length / DBLOCK_SIZE));
2678 dc->has_finished = (int) status; 2534 dc->has_finished = (int) status;
2679 dc->treedepth = GNUNET_FS_compute_depth (GNUNET_FS_uri_chk_get_file_size (dc->uri)); 2535 dc->treedepth =
2536 GNUNET_FS_compute_depth (GNUNET_FS_uri_chk_get_file_size (dc->uri));
2680 if (GNUNET_FS_uri_test_loc (dc->uri)) 2537 if (GNUNET_FS_uri_test_loc (dc->uri))
2681 GNUNET_assert (GNUNET_OK == 2538 GNUNET_assert (GNUNET_OK ==
2682 GNUNET_FS_uri_loc_get_peer_identity (dc->uri, 2539 GNUNET_FS_uri_loc_get_peer_identity (dc->uri, &dc->target));
2683 &dc->target));
2684 if (dc->emsg == NULL) 2540 if (dc->emsg == NULL)
2541 {
2542 dc->top_request = read_download_request (rh);
2543 if (dc->top_request == NULL)
2685 { 2544 {
2686 dc->top_request = read_download_request (rh); 2545 GNUNET_break (0);
2687 if (dc->top_request == NULL) 2546 goto cleanup;
2688 {
2689 GNUNET_break (0);
2690 goto cleanup;
2691 }
2692 } 2547 }
2548 }
2693 dn = get_download_sync_filename (dc, dc->serialization, ".dir"); 2549 dn = get_download_sync_filename (dc, dc->serialization, ".dir");
2694 if (dn != NULL) 2550 if (dn != NULL)
2695 { 2551 {
2696 if (GNUNET_YES == 2552 if (GNUNET_YES == GNUNET_DISK_directory_test (dn))
2697 GNUNET_DISK_directory_test (dn)) 2553 GNUNET_DISK_directory_scan (dn, &deserialize_subdownload, dc);
2698 GNUNET_DISK_directory_scan (dn, &deserialize_subdownload, dc); 2554 GNUNET_free (dn);
2699 GNUNET_free (dn); 2555 }
2700 }
2701 if (parent != NULL) 2556 if (parent != NULL)
2702 { 2557 {
2703 abort (); // for debugging for now 2558 abort (); // for debugging for now
2704 GNUNET_CONTAINER_DLL_insert (parent->child_head, 2559 GNUNET_CONTAINER_DLL_insert (parent->child_head, parent->child_tail, dc);
2705 parent->child_tail, 2560 }
2706 dc);
2707 }
2708 if (search != NULL) 2561 if (search != NULL)
2709 { 2562 {
2710 dc->search = search; 2563 dc->search = search;
2711 search->download = dc; 2564 search->download = dc;
2712 } 2565 }
2713 if ( (parent == NULL) && 2566 if ((parent == NULL) && (search == NULL))
2714 (search == NULL) ) 2567 {
2715 { 2568 dc->top = GNUNET_FS_make_top (dc->h,
2716 dc->top = GNUNET_FS_make_top (dc->h, 2569 &GNUNET_FS_download_signal_suspend_, dc);
2717 &GNUNET_FS_download_signal_suspend_, 2570 signal_download_resume (dc);
2718 dc); 2571 }
2719 signal_download_resume (dc);
2720 }
2721 GNUNET_free (uris); 2572 GNUNET_free (uris);
2722 dc->task 2573 dc->task = GNUNET_SCHEDULER_add_now (&GNUNET_FS_download_start_task_, dc);
2723 = GNUNET_SCHEDULER_add_now (&GNUNET_FS_download_start_task_, dc);
2724 return; 2574 return;
2725 cleanup: 2575cleanup:
2726 GNUNET_free_non_null (uris); 2576 GNUNET_free_non_null (uris);
2727 GNUNET_free_non_null (emsg); 2577 GNUNET_free_non_null (emsg);
2728 free_download_context (dc); 2578 free_download_context (dc);
@@ -2742,12 +2592,11 @@ signal_search_resume (struct GNUNET_FS_SearchContext *sc)
2742 2592
2743 pi.status = GNUNET_FS_STATUS_SEARCH_RESUME; 2593 pi.status = GNUNET_FS_STATUS_SEARCH_RESUME;
2744 pi.value.search.specifics.resume.message = sc->emsg; 2594 pi.value.search.specifics.resume.message = sc->emsg;
2745 pi.value.search.specifics.resume.is_paused = (sc->client == NULL) ? GNUNET_YES : GNUNET_NO; 2595 pi.value.search.specifics.resume.is_paused =
2746 sc->client_info = GNUNET_FS_search_make_status_ (&pi, 2596 (sc->client == NULL) ? GNUNET_YES : GNUNET_NO;
2747 sc); 2597 sc->client_info = GNUNET_FS_search_make_status_ (&pi, sc);
2748 GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, 2598 GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map,
2749 &signal_result_resume, 2599 &signal_result_resume, sc);
2750 sc);
2751 2600
2752} 2601}
2753 2602
@@ -2762,9 +2611,9 @@ signal_search_resume (struct GNUNET_FS_SearchContext *sc)
2762 */ 2611 */
2763static struct GNUNET_FS_SearchContext * 2612static struct GNUNET_FS_SearchContext *
2764deserialize_search (struct GNUNET_FS_Handle *h, 2613deserialize_search (struct GNUNET_FS_Handle *h,
2765 struct GNUNET_BIO_ReadHandle *rh, 2614 struct GNUNET_BIO_ReadHandle *rh,
2766 struct GNUNET_FS_SearchResult *psearch_result, 2615 struct GNUNET_FS_SearchResult *psearch_result,
2767 const char *serialization) 2616 const char *serialization)
2768{ 2617{
2769 struct GNUNET_FS_SearchContext *sc; 2618 struct GNUNET_FS_SearchContext *sc;
2770 char *emsg; 2619 char *emsg;
@@ -2773,67 +2622,63 @@ deserialize_search (struct GNUNET_FS_Handle *h,
2773 uint32_t options; 2622 uint32_t options;
2774 char in_pause; 2623 char in_pause;
2775 2624
2776 if ( (psearch_result != NULL) && 2625 if ((psearch_result != NULL) && (psearch_result->update_search != NULL))
2777 (psearch_result->update_search != NULL) ) 2626 {
2778 { 2627 GNUNET_break (0);
2779 GNUNET_break (0); 2628 return NULL;
2780 return NULL; 2629 }
2781 }
2782 uris = NULL; 2630 uris = NULL;
2783 emsg = NULL; 2631 emsg = NULL;
2784 sc = GNUNET_malloc (sizeof (struct GNUNET_FS_SearchContext)); 2632 sc = GNUNET_malloc (sizeof (struct GNUNET_FS_SearchContext));
2785 if (psearch_result != NULL) 2633 if (psearch_result != NULL)
2786 { 2634 {
2787 sc->psearch_result = psearch_result; 2635 sc->psearch_result = psearch_result;
2788 psearch_result->update_search = sc; 2636 psearch_result->update_search = sc;
2789 } 2637 }
2790 sc->h = h; 2638 sc->h = h;
2791 sc->serialization = GNUNET_strdup (serialization); 2639 sc->serialization = GNUNET_strdup (serialization);
2792 if ( (GNUNET_OK != 2640 if ((GNUNET_OK !=
2793 GNUNET_BIO_read_string (rh, "search-uri", &uris, 10*1024)) || 2641 GNUNET_BIO_read_string (rh, "search-uri", &uris, 10 * 1024)) ||
2794 (NULL == (sc->uri = GNUNET_FS_uri_parse (uris, &emsg))) || 2642 (NULL == (sc->uri = GNUNET_FS_uri_parse (uris, &emsg))) ||
2795 ( (GNUNET_YES != GNUNET_FS_uri_test_ksk (sc->uri)) && 2643 ((GNUNET_YES != GNUNET_FS_uri_test_ksk (sc->uri)) &&
2796 (GNUNET_YES != GNUNET_FS_uri_test_sks (sc->uri)) ) || 2644 (GNUNET_YES != GNUNET_FS_uri_test_sks (sc->uri))) ||
2797 (GNUNET_OK != 2645 (GNUNET_OK !=
2798 read_start_time (rh, &sc->start_time)) || 2646 read_start_time (rh, &sc->start_time)) ||
2799 (GNUNET_OK != 2647 (GNUNET_OK !=
2800 GNUNET_BIO_read_string (rh, "search-emsg", &sc->emsg, 10*1024)) || 2648 GNUNET_BIO_read_string (rh, "search-emsg", &sc->emsg, 10 * 1024)) ||
2801 (GNUNET_OK != 2649 (GNUNET_OK !=
2802 GNUNET_BIO_read_int32 (rh, &options)) || 2650 GNUNET_BIO_read_int32 (rh, &options)) ||
2803 (GNUNET_OK != 2651 (GNUNET_OK !=
2804 GNUNET_BIO_read (rh, "search-pause", &in_pause, sizeof (in_pause))) || 2652 GNUNET_BIO_read (rh, "search-pause", &in_pause, sizeof (in_pause))) ||
2805 (GNUNET_OK != 2653 (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sc->anonymity)))
2806 GNUNET_BIO_read_int32 (rh, &sc->anonymity)) ) 2654 {
2807 { 2655 GNUNET_break (0);
2808 GNUNET_break (0); 2656 goto cleanup;
2809 goto cleanup; 2657 }
2810 }
2811 sc->options = (enum GNUNET_FS_SearchOptions) options; 2658 sc->options = (enum GNUNET_FS_SearchOptions) options;
2812 sc->master_result_map = GNUNET_CONTAINER_multihashmap_create (16); 2659 sc->master_result_map = GNUNET_CONTAINER_multihashmap_create (16);
2813 dn = get_serialization_file_name_in_dir (h, 2660 dn = get_serialization_file_name_in_dir (h,
2814 (sc->psearch_result == NULL) 2661 (sc->psearch_result == NULL)
2815 ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH 2662 ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH
2816 : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, 2663 : GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
2817 sc->serialization, 2664 sc->serialization, "");
2818 "");
2819 if (dn != NULL) 2665 if (dn != NULL)
2820 { 2666 {
2821 if (GNUNET_YES == 2667 if (GNUNET_YES == GNUNET_DISK_directory_test (dn))
2822 GNUNET_DISK_directory_test (dn)) 2668 GNUNET_DISK_directory_scan (dn, &deserialize_search_result, sc);
2823 GNUNET_DISK_directory_scan (dn, &deserialize_search_result, sc); 2669 GNUNET_free (dn);
2824 GNUNET_free (dn); 2670 }
2825 } 2671 if (('\0' == in_pause) &&
2826 if ( ('\0' == in_pause) && 2672 (GNUNET_OK != GNUNET_FS_search_start_searching_ (sc)))
2827 (GNUNET_OK != 2673 {
2828 GNUNET_FS_search_start_searching_ (sc)) ) 2674 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2829 { 2675 _
2830 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2676 ("Could not resume running search, will resume as paused search\n"));
2831 _("Could not resume running search, will resume as paused search\n")); 2677 }
2832 }
2833 signal_search_resume (sc); 2678 signal_search_resume (sc);
2834 GNUNET_free (uris); 2679 GNUNET_free (uris);
2835 return sc; 2680 return sc;
2836 cleanup: 2681cleanup:
2837 GNUNET_free_non_null (emsg); 2682 GNUNET_free_non_null (emsg);
2838 free_search_context (sc); 2683 free_search_context (sc);
2839 GNUNET_free_non_null (uris); 2684 GNUNET_free_non_null (uris);
@@ -2850,8 +2695,7 @@ deserialize_search (struct GNUNET_FS_Handle *h,
2850 * @return GNUNET_OK (continue to iterate) 2695 * @return GNUNET_OK (continue to iterate)
2851 */ 2696 */
2852static int 2697static int
2853deserialize_search_file (void *cls, 2698deserialize_search_file (void *cls, const char *filename)
2854 const char *filename)
2855{ 2699{
2856 struct GNUNET_FS_Handle *h = cls; 2700 struct GNUNET_FS_Handle *h = cls;
2857 char *ser; 2701 char *ser;
@@ -2862,27 +2706,25 @@ deserialize_search_file (void *cls,
2862 ser = get_serialization_short_name (filename); 2706 ser = get_serialization_short_name (filename);
2863 rh = GNUNET_BIO_read_open (filename); 2707 rh = GNUNET_BIO_read_open (filename);
2864 if (rh == NULL) 2708 if (rh == NULL)
2709 {
2710 if (ser != NULL)
2865 { 2711 {
2866 if (ser != NULL) 2712 GNUNET_FS_remove_sync_file_ (h, GNUNET_FS_SYNC_PATH_MASTER_SEARCH, ser);
2867 { 2713 GNUNET_free (ser);
2868 GNUNET_FS_remove_sync_file_ (h, GNUNET_FS_SYNC_PATH_MASTER_SEARCH, ser);
2869 GNUNET_free (ser);
2870 }
2871 return GNUNET_OK;
2872 } 2714 }
2715 return GNUNET_OK;
2716 }
2873 sc = deserialize_search (h, rh, NULL, ser); 2717 sc = deserialize_search (h, rh, NULL, ser);
2874 if (sc != NULL) 2718 if (sc != NULL)
2875 sc->top = GNUNET_FS_make_top (h, &GNUNET_FS_search_signal_suspend_, sc); 2719 sc->top = GNUNET_FS_make_top (h, &GNUNET_FS_search_signal_suspend_, sc);
2876 GNUNET_free (ser); 2720 GNUNET_free (ser);
2877 if (GNUNET_OK != 2721 if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
2878 GNUNET_BIO_read_close (rh, &emsg)) 2722 {
2879 { 2723 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2880 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2724 _("Failure while resuming search operation `%s': %s\n"),
2881 _("Failure while resuming search operation `%s': %s\n"), 2725 filename, emsg);
2882 filename, 2726 GNUNET_free (emsg);
2883 emsg); 2727 }
2884 GNUNET_free (emsg);
2885 }
2886 return GNUNET_OK; 2728 return GNUNET_OK;
2887} 2729}
2888 2730
@@ -2896,8 +2738,7 @@ deserialize_search_file (void *cls,
2896 * @return GNUNET_OK (continue to iterate) 2738 * @return GNUNET_OK (continue to iterate)
2897 */ 2739 */
2898static int 2740static int
2899deserialize_download_file (void *cls, 2741deserialize_download_file (void *cls, const char *filename)
2900 const char *filename)
2901{ 2742{
2902 struct GNUNET_FS_Handle *h = cls; 2743 struct GNUNET_FS_Handle *h = cls;
2903 char *ser; 2744 char *ser;
@@ -2907,25 +2748,21 @@ deserialize_download_file (void *cls,
2907 ser = get_serialization_short_name (filename); 2748 ser = get_serialization_short_name (filename);
2908 rh = GNUNET_BIO_read_open (filename); 2749 rh = GNUNET_BIO_read_open (filename);
2909 if (rh == NULL) 2750 if (rh == NULL)
2910 { 2751 {
2911 if (0 != UNLINK (filename)) 2752 if (0 != UNLINK (filename))
2912 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, 2753 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", filename);
2913 "unlink", 2754 GNUNET_free (ser);
2914 filename); 2755 return GNUNET_OK;
2915 GNUNET_free (ser); 2756 }
2916 return GNUNET_OK;
2917 }
2918 deserialize_download (h, rh, NULL, NULL, ser); 2757 deserialize_download (h, rh, NULL, NULL, ser);
2919 GNUNET_free (ser); 2758 GNUNET_free (ser);
2920 if (GNUNET_OK != 2759 if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
2921 GNUNET_BIO_read_close (rh, &emsg)) 2760 {
2922 { 2761 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2923 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2762 _("Failure while resuming download operation `%s': %s\n"),
2924 _("Failure while resuming download operation `%s': %s\n"), 2763 filename, emsg);
2925 filename, 2764 GNUNET_free (emsg);
2926 emsg); 2765 }
2927 GNUNET_free (emsg);
2928 }
2929 return GNUNET_OK; 2766 return GNUNET_OK;
2930} 2767}
2931 2768
@@ -2939,18 +2776,17 @@ deserialize_download_file (void *cls,
2939 */ 2776 */
2940static void 2777static void
2941deserialization_master (const char *master_path, 2778deserialization_master (const char *master_path,
2942 GNUNET_FileNameCallback proc, 2779 GNUNET_FileNameCallback proc,
2943 struct GNUNET_FS_Handle *h) 2780 struct GNUNET_FS_Handle *h)
2944{ 2781{
2945 char *dn; 2782 char *dn;
2946 2783
2947 dn = get_serialization_file_name (h, master_path, ""); 2784 dn = get_serialization_file_name (h, master_path, "");
2948 if (dn == NULL) 2785 if (dn == NULL)
2949 return; 2786 return;
2950 if (GNUNET_YES == 2787 if (GNUNET_YES == GNUNET_DISK_directory_test (dn))
2951 GNUNET_DISK_directory_test (dn))
2952 GNUNET_DISK_directory_scan (dn, proc, h); 2788 GNUNET_DISK_directory_scan (dn, proc, h);
2953 GNUNET_free (dn); 2789 GNUNET_free (dn);
2954} 2790}
2955 2791
2956 2792
@@ -2967,11 +2803,9 @@ deserialization_master (const char *master_path,
2967 */ 2803 */
2968struct GNUNET_FS_Handle * 2804struct GNUNET_FS_Handle *
2969GNUNET_FS_start (const struct GNUNET_CONFIGURATION_Handle *cfg, 2805GNUNET_FS_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
2970 const char *client_name, 2806 const char *client_name,
2971 GNUNET_FS_ProgressCallback upcb, 2807 GNUNET_FS_ProgressCallback upcb,
2972 void *upcb_cls, 2808 void *upcb_cls, enum GNUNET_FS_Flags flags, ...)
2973 enum GNUNET_FS_Flags flags,
2974 ...)
2975{ 2809{
2976 struct GNUNET_FS_Handle *ret; 2810 struct GNUNET_FS_Handle *ret;
2977 enum GNUNET_FS_OPTIONS opt; 2811 enum GNUNET_FS_OPTIONS opt;
@@ -2985,42 +2819,40 @@ GNUNET_FS_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
2985 ret->flags = flags; 2819 ret->flags = flags;
2986 ret->max_parallel_downloads = 1; 2820 ret->max_parallel_downloads = 1;
2987 ret->max_parallel_requests = 1; 2821 ret->max_parallel_requests = 1;
2988 ret->avg_block_latency = GNUNET_TIME_UNIT_MINUTES; /* conservative starting point */ 2822 ret->avg_block_latency = GNUNET_TIME_UNIT_MINUTES; /* conservative starting point */
2989 va_start (ap, flags); 2823 va_start (ap, flags);
2990 while (GNUNET_FS_OPTIONS_END != (opt = va_arg (ap, enum GNUNET_FS_OPTIONS))) 2824 while (GNUNET_FS_OPTIONS_END != (opt = va_arg (ap, enum GNUNET_FS_OPTIONS)))
2825 {
2826 switch (opt)
2991 { 2827 {
2992 switch (opt) 2828 case GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM:
2993 { 2829 ret->max_parallel_downloads = va_arg (ap, unsigned int);
2994 case GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM: 2830
2995 ret->max_parallel_downloads = va_arg (ap, unsigned int); 2831 break;
2996 break; 2832 case GNUNET_FS_OPTIONS_REQUEST_PARALLELISM:
2997 case GNUNET_FS_OPTIONS_REQUEST_PARALLELISM: 2833 ret->max_parallel_requests = va_arg (ap, unsigned int);
2998 ret->max_parallel_requests = va_arg (ap, unsigned int); 2834
2999 break; 2835 break;
3000 default: 2836 default:
3001 GNUNET_break (0); 2837 GNUNET_break (0);
3002 GNUNET_free (ret->client_name); 2838 GNUNET_free (ret->client_name);
3003 GNUNET_free (ret); 2839 GNUNET_free (ret);
3004 va_end (ap); 2840 va_end (ap);
3005 return NULL; 2841 return NULL;
3006 }
3007 } 2842 }
2843 }
3008 va_end (ap); 2844 va_end (ap);
3009 if (0 != (GNUNET_FS_FLAGS_PERSISTENCE & flags)) 2845 if (0 != (GNUNET_FS_FLAGS_PERSISTENCE & flags))
3010 { 2846 {
3011 deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_PUBLISH, 2847 deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_PUBLISH,
3012 &deserialize_publish_file, 2848 &deserialize_publish_file, ret);
3013 ret); 2849 deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_SEARCH,
3014 deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_SEARCH, 2850 &deserialize_search_file, ret);
3015 &deserialize_search_file, 2851 deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD,
3016 ret); 2852 &deserialize_download_file, ret);
3017 deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD, 2853 deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_UNINDEX,
3018 &deserialize_download_file, 2854 &deserialize_unindex_file, ret);
3019 ret); 2855 }
3020 deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_UNINDEX,
3021 &deserialize_unindex_file,
3022 ret);
3023 }
3024 return ret; 2856 return ret;
3025} 2857}
3026 2858
@@ -3031,8 +2863,8 @@ GNUNET_FS_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
3031 * called after this function returns. 2863 * called after this function returns.
3032 * 2864 *
3033 * @param h handle that was returned from GNUNET_FS_start 2865 * @param h handle that was returned from GNUNET_FS_start
3034 */ 2866 */
3035void 2867void
3036GNUNET_FS_stop (struct GNUNET_FS_Handle *h) 2868GNUNET_FS_stop (struct GNUNET_FS_Handle *h)
3037{ 2869{
3038 while (h->top_head != NULL) 2870 while (h->top_head != NULL)
diff --git a/src/fs/fs.h b/src/fs/fs.h
index 954fe0599..1d3fc6611 100644
--- a/src/fs/fs.h
+++ b/src/fs/fs.h
@@ -240,7 +240,7 @@
240/** 240/**
241 * @brief content hash key 241 * @brief content hash key
242 */ 242 */
243struct ContentHashKey 243struct ContentHashKey
244{ 244{
245 /** 245 /**
246 * Hash of the original content, used for encryption. 246 * Hash of the original content, used for encryption.
@@ -307,27 +307,27 @@ struct Location
307 * Types of URIs. 307 * Types of URIs.
308 */ 308 */
309enum uri_types 309enum uri_types
310 { 310{
311 /** 311 /**
312 * Content-hash-key (simple file). 312 * Content-hash-key (simple file).
313 */ 313 */
314 chk, 314 chk,
315 315
316 /** 316 /**
317 * Signed key space (file in namespace). 317 * Signed key space (file in namespace).
318 */ 318 */
319 sks, 319 sks,
320 320
321 /** 321 /**
322 * Keyword search key (query with keywords). 322 * Keyword search key (query with keywords).
323 */ 323 */
324 ksk, 324 ksk,
325 325
326 /** 326 /**
327 * Location (chk with identity of hosting peer). 327 * Location (chk with identity of hosting peer).
328 */ 328 */
329 loc 329 loc
330 }; 330};
331 331
332/** 332/**
333 * A Universal Resource Identifier (URI), opaque. 333 * A Universal Resource Identifier (URI), opaque.
@@ -356,7 +356,7 @@ struct GNUNET_FS_Uri
356 * (only in URI-strings). 356 * (only in URI-strings).
357 */ 357 */
358 char **keywords; 358 char **keywords;
359 359
360 /** 360 /**
361 * Size of the keywords array. 361 * Size of the keywords array.
362 */ 362 */
@@ -453,7 +453,7 @@ struct GNUNET_FS_FileInformation
453 * using 'mktemp'. 453 * using 'mktemp'.
454 */ 454 */
455 char *serialization; 455 char *serialization;
456 456
457 /** 457 /**
458 * Encoder being used to publish this file. 458 * Encoder being used to publish this file.
459 */ 459 */
@@ -478,7 +478,8 @@ struct GNUNET_FS_FileInformation
478 /** 478 /**
479 * Data for a file. 479 * Data for a file.
480 */ 480 */
481 struct { 481 struct
482 {
482 483
483 /** 484 /**
484 * Function that can be used to read the data for the file. 485 * Function that can be used to read the data for the file.
@@ -524,8 +525,9 @@ struct GNUNET_FS_FileInformation
524 /** 525 /**
525 * Data for a directory. 526 * Data for a directory.
526 */ 527 */
527 struct { 528 struct
528 529 {
530
529 /** 531 /**
530 * Linked list of entries in the directory. 532 * Linked list of entries in the directory.
531 */ 533 */
@@ -567,15 +569,15 @@ struct GNUNET_FS_FileInformation
567 * @param cls closure 569 * @param cls closure
568 * @param client handle to use for FS communication 570 * @param client handle to use for FS communication
569 */ 571 */
570typedef void (*GNUNET_FS_QueueStart)(void *cls, 572typedef void (*GNUNET_FS_QueueStart) (void *cls,
571 struct GNUNET_CLIENT_Connection *client); 573 struct GNUNET_CLIENT_Connection * client);
572 574
573 575
574/** 576/**
575 * The job must now stop to run and should destry the client handle as 577 * The job must now stop to run and should destry the client handle as
576 * soon as possible (ideally prior to returning). 578 * soon as possible (ideally prior to returning).
577 */ 579 */
578typedef void (*GNUNET_FS_QueueStop)(void *cls); 580typedef void (*GNUNET_FS_QueueStop) (void *cls);
579 581
580 582
581/** 583/**
@@ -610,7 +612,7 @@ struct GNUNET_FS_QueueEntry
610 612
611 /** 613 /**
612 * Handle to FS primary context. 614 * Handle to FS primary context.
613 */ 615 */
614 struct GNUNET_FS_Handle *h; 616 struct GNUNET_FS_Handle *h;
615 617
616 /** 618 /**
@@ -757,20 +759,17 @@ struct GNUNET_FS_SearchResult
757 * @param blocks number of blocks this download has 759 * @param blocks number of blocks this download has
758 * @return queue handle 760 * @return queue handle
759 */ 761 */
760struct GNUNET_FS_QueueEntry * 762struct GNUNET_FS_QueueEntry *GNUNET_FS_queue_ (struct GNUNET_FS_Handle *h,
761GNUNET_FS_queue_ (struct GNUNET_FS_Handle *h, 763 GNUNET_FS_QueueStart start,
762 GNUNET_FS_QueueStart start, 764 GNUNET_FS_QueueStop stop,
763 GNUNET_FS_QueueStop stop, 765 void *cls, unsigned int blocks);
764 void *cls,
765 unsigned int blocks);
766 766
767 767
768/** 768/**
769 * Dequeue a job from the queue. 769 * Dequeue a job from the queue.
770 * @param qh handle for the job 770 * @param qh handle for the job
771 */ 771 */
772void 772void GNUNET_FS_dequeue_ (struct GNUNET_FS_QueueEntry *qh);
773GNUNET_FS_dequeue_ (struct GNUNET_FS_QueueEntry *qh);
774 773
775 774
776/** 775/**
@@ -790,11 +789,16 @@ GNUNET_FS_dequeue_ (struct GNUNET_FS_QueueEntry *qh);
790 * @return number of bytes written, usually "max", 0 on error 789 * @return number of bytes written, usually "max", 0 on error
791 */ 790 */
792size_t 791size_t
793GNUNET_FS_data_reader_file_(void *cls, 792
794 uint64_t offset, 793
795 size_t max, 794
796 void *buf, 795
797 char **emsg); 796
797
798
799GNUNET_FS_data_reader_file_ (void *cls,
800 uint64_t offset,
801 size_t max, void *buf, char **emsg);
798 802
799 803
800/** 804/**
@@ -803,8 +807,7 @@ GNUNET_FS_data_reader_file_(void *cls,
803 * @param filename file to read 807 * @param filename file to read
804 * @return closure to use 808 * @return closure to use
805 */ 809 */
806void * 810void *GNUNET_FS_make_file_reader_context_ (const char *filename);
807GNUNET_FS_make_file_reader_context_ (const char *filename);
808 811
809 812
810 813
@@ -825,11 +828,9 @@ GNUNET_FS_make_file_reader_context_ (const char *filename);
825 * @return number of bytes written, usually "max", 0 on error 828 * @return number of bytes written, usually "max", 0 on error
826 */ 829 */
827size_t 830size_t
828GNUNET_FS_data_reader_copy_(void *cls, 831GNUNET_FS_data_reader_copy_ (void *cls,
829 uint64_t offset, 832 uint64_t offset,
830 size_t max, 833 size_t max, void *buf, char **emsg);
831 void *buf,
832 char **emsg);
833 834
834/** 835/**
835 * Notification of FS that a search probe has made progress. 836 * Notification of FS that a search probe has made progress.
@@ -846,9 +847,9 @@ GNUNET_FS_data_reader_copy_(void *cls,
846 * will be passed to future callbacks in the respective 847 * will be passed to future callbacks in the respective
847 * field in the GNUNET_FS_ProgressInfo struct. 848 * field in the GNUNET_FS_ProgressInfo struct.
848 */ 849 */
849void* 850void *GNUNET_FS_search_probe_progress_ (void *cls,
850GNUNET_FS_search_probe_progress_ (void *cls, 851 const struct GNUNET_FS_ProgressInfo
851 const struct GNUNET_FS_ProgressInfo *info); 852 *info);
852 853
853 854
854/** 855/**
@@ -859,7 +860,7 @@ GNUNET_FS_search_probe_progress_ (void *cls,
859 */ 860 */
860void 861void
861GNUNET_FS_publish_main_ (void *cls, 862GNUNET_FS_publish_main_ (void *cls,
862 const struct GNUNET_SCHEDULER_TaskContext *tc); 863 const struct GNUNET_SCHEDULER_TaskContext *tc);
863 864
864 865
865/** 866/**
@@ -869,9 +870,8 @@ GNUNET_FS_publish_main_ (void *cls,
869 * @param cls closure, unindex context 870 * @param cls closure, unindex context
870 * @param file_id computed hash, NULL on error 871 * @param file_id computed hash, NULL on error
871 */ 872 */
872void 873void
873GNUNET_FS_unindex_process_hash_ (void *cls, 874GNUNET_FS_unindex_process_hash_ (void *cls, const GNUNET_HashCode * file_id);
874 const GNUNET_HashCode *file_id);
875 875
876 876
877/** 877/**
@@ -884,11 +884,10 @@ GNUNET_FS_unindex_process_hash_ (void *cls,
884 * @param offset where in the file are we so far 884 * @param offset where in the file are we so far
885 * @return value returned from callback 885 * @return value returned from callback
886 */ 886 */
887void * 887void *GNUNET_FS_publish_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
888GNUNET_FS_publish_make_status_ (struct GNUNET_FS_ProgressInfo *pi, 888 struct GNUNET_FS_PublishContext *sc,
889 struct GNUNET_FS_PublishContext *sc, 889 const struct GNUNET_FS_FileInformation *p,
890 const struct GNUNET_FS_FileInformation *p, 890 uint64_t offset);
891 uint64_t offset);
892 891
893 892
894/** 893/**
@@ -900,7 +899,7 @@ GNUNET_FS_publish_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
900 */ 899 */
901void 900void
902GNUNET_FS_download_make_status_ (struct GNUNET_FS_ProgressInfo *pi, 901GNUNET_FS_download_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
903 struct GNUNET_FS_DownloadContext *dc); 902 struct GNUNET_FS_DownloadContext *dc);
904 903
905 904
906/** 905/**
@@ -912,7 +911,7 @@ GNUNET_FS_download_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
912 */ 911 */
913void 912void
914GNUNET_FS_download_start_task_ (void *cls, 913GNUNET_FS_download_start_task_ (void *cls,
915 const struct GNUNET_SCHEDULER_TaskContext *tc); 914 const struct GNUNET_SCHEDULER_TaskContext *tc);
916 915
917 916
918 917
@@ -926,8 +925,8 @@ GNUNET_FS_download_start_task_ (void *cls,
926 */ 925 */
927void 926void
928GNUNET_FS_unindex_make_status_ (struct GNUNET_FS_ProgressInfo *pi, 927GNUNET_FS_unindex_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
929 struct GNUNET_FS_UnindexContext *uc, 928 struct GNUNET_FS_UnindexContext *uc,
930 uint64_t offset); 929 uint64_t offset);
931 930
932/** 931/**
933 * Fill in all of the generic fields for a search event and 932 * Fill in all of the generic fields for a search event and
@@ -937,9 +936,8 @@ GNUNET_FS_unindex_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
937 * @param sc overall search context 936 * @param sc overall search context
938 * @return value returned by the callback 937 * @return value returned by the callback
939 */ 938 */
940void * 939void *GNUNET_FS_search_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
941GNUNET_FS_search_make_status_ (struct GNUNET_FS_ProgressInfo *pi, 940 struct GNUNET_FS_SearchContext *sc);
942 struct GNUNET_FS_SearchContext *sc);
943 941
944 942
945/** 943/**
@@ -947,8 +945,7 @@ GNUNET_FS_search_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
947 * 945 *
948 * @param uc context for the unindex operation. 946 * @param uc context for the unindex operation.
949 */ 947 */
950void 948void GNUNET_FS_unindex_do_remove_ (struct GNUNET_FS_UnindexContext *uc);
951GNUNET_FS_unindex_do_remove_ (struct GNUNET_FS_UnindexContext *uc);
952 949
953/** 950/**
954 * Build the request and actually initiate the search using the 951 * Build the request and actually initiate the search using the
@@ -957,8 +954,7 @@ GNUNET_FS_unindex_do_remove_ (struct GNUNET_FS_UnindexContext *uc);
957 * @param sc search context 954 * @param sc search context
958 * @return GNUNET_OK on success, GNUNET_SYSERR on error 955 * @return GNUNET_OK on success, GNUNET_SYSERR on error
959 */ 956 */
960int 957int GNUNET_FS_search_start_searching_ (struct GNUNET_FS_SearchContext *sc);
961GNUNET_FS_search_start_searching_ (struct GNUNET_FS_SearchContext *sc);
962 958
963/** 959/**
964 * Start the downloading process (by entering the queue). 960 * Start the downloading process (by entering the queue).
@@ -974,8 +970,7 @@ GNUNET_FS_download_start_downloading_ (struct GNUNET_FS_DownloadContext *dc);
974 * 970 *
975 * @param sr the search result 971 * @param sr the search result
976 */ 972 */
977void 973void GNUNET_FS_search_start_probe_ (struct GNUNET_FS_SearchResult *sr);
978GNUNET_FS_search_start_probe_ (struct GNUNET_FS_SearchResult *sr);
979 974
980/** 975/**
981 * Remove serialization/deserialization file from disk. 976 * Remove serialization/deserialization file from disk.
@@ -986,8 +981,7 @@ GNUNET_FS_search_start_probe_ (struct GNUNET_FS_SearchResult *sr);
986 */ 981 */
987void 982void
988GNUNET_FS_remove_sync_file_ (struct GNUNET_FS_Handle *h, 983GNUNET_FS_remove_sync_file_ (struct GNUNET_FS_Handle *h,
989 const char *ext, 984 const char *ext, const char *ent);
990 const char *ent);
991 985
992 986
993/** 987/**
@@ -999,8 +993,7 @@ GNUNET_FS_remove_sync_file_ (struct GNUNET_FS_Handle *h,
999 */ 993 */
1000void 994void
1001GNUNET_FS_remove_sync_dir_ (struct GNUNET_FS_Handle *h, 995GNUNET_FS_remove_sync_dir_ (struct GNUNET_FS_Handle *h,
1002 const char *ext, 996 const char *ext, const char *uni);
1003 const char *uni);
1004 997
1005 998
1006/** 999/**
@@ -1011,8 +1004,7 @@ GNUNET_FS_remove_sync_dir_ (struct GNUNET_FS_Handle *h,
1011 * 1004 *
1012 * @param fi the struct to sync 1005 * @param fi the struct to sync
1013 */ 1006 */
1014void 1007void GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *f);
1015GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *f);
1016 1008
1017/** 1009/**
1018 * Synchronize this publishing struct with its mirror 1010 * Synchronize this publishing struct with its mirror
@@ -1022,8 +1014,7 @@ GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *f);
1022 * 1014 *
1023 * @param pc the struct to sync 1015 * @param pc the struct to sync
1024 */ 1016 */
1025void 1017void GNUNET_FS_publish_sync_ (struct GNUNET_FS_PublishContext *pc);
1026GNUNET_FS_publish_sync_ (struct GNUNET_FS_PublishContext *pc);
1027 1018
1028/** 1019/**
1029 * Synchronize this unindex struct with its mirror 1020 * Synchronize this unindex struct with its mirror
@@ -1033,8 +1024,7 @@ GNUNET_FS_publish_sync_ (struct GNUNET_FS_PublishContext *pc);
1033 * 1024 *
1034 * @param uc the struct to sync 1025 * @param uc the struct to sync
1035 */ 1026 */
1036void 1027void GNUNET_FS_unindex_sync_ (struct GNUNET_FS_UnindexContext *uc);
1037GNUNET_FS_unindex_sync_ (struct GNUNET_FS_UnindexContext *uc);
1038 1028
1039/** 1029/**
1040 * Synchronize this search struct with its mirror 1030 * Synchronize this search struct with its mirror
@@ -1044,8 +1034,7 @@ GNUNET_FS_unindex_sync_ (struct GNUNET_FS_UnindexContext *uc);
1044 * 1034 *
1045 * @param sc the struct to sync 1035 * @param sc the struct to sync
1046 */ 1036 */
1047void 1037void GNUNET_FS_search_sync_ (struct GNUNET_FS_SearchContext *sc);
1048GNUNET_FS_search_sync_ (struct GNUNET_FS_SearchContext *sc);
1049 1038
1050/** 1039/**
1051 * Synchronize this search result with its mirror 1040 * Synchronize this search result with its mirror
@@ -1055,8 +1044,7 @@ GNUNET_FS_search_sync_ (struct GNUNET_FS_SearchContext *sc);
1055 * 1044 *
1056 * @param sr the struct to sync 1045 * @param sr the struct to sync
1057 */ 1046 */
1058void 1047void GNUNET_FS_search_result_sync_ (struct GNUNET_FS_SearchResult *sr);
1059GNUNET_FS_search_result_sync_ (struct GNUNET_FS_SearchResult *sr);
1060 1048
1061/** 1049/**
1062 * Synchronize this download struct with its mirror 1050 * Synchronize this download struct with its mirror
@@ -1066,8 +1054,7 @@ GNUNET_FS_search_result_sync_ (struct GNUNET_FS_SearchResult *sr);
1066 * 1054 *
1067 * @param dc the struct to sync 1055 * @param dc the struct to sync
1068 */ 1056 */
1069void 1057void GNUNET_FS_download_sync_ (struct GNUNET_FS_DownloadContext *dc);
1070GNUNET_FS_download_sync_ (struct GNUNET_FS_DownloadContext *dc);
1071 1058
1072/** 1059/**
1073 * Create SUSPEND event for the given publish operation 1060 * Create SUSPEND event for the given publish operation
@@ -1075,8 +1062,7 @@ GNUNET_FS_download_sync_ (struct GNUNET_FS_DownloadContext *dc);
1075 * 1062 *
1076 * @param cls the 'struct GNUNET_FS_PublishContext' to signal for 1063 * @param cls the 'struct GNUNET_FS_PublishContext' to signal for
1077 */ 1064 */
1078void 1065void GNUNET_FS_publish_signal_suspend_ (void *cls);
1079GNUNET_FS_publish_signal_suspend_ (void *cls);
1080 1066
1081/** 1067/**
1082 * Create SUSPEND event for the given search operation 1068 * Create SUSPEND event for the given search operation
@@ -1084,8 +1070,7 @@ GNUNET_FS_publish_signal_suspend_ (void *cls);
1084 * 1070 *
1085 * @param cls the 'struct GNUNET_FS_SearchContext' to signal for 1071 * @param cls the 'struct GNUNET_FS_SearchContext' to signal for
1086 */ 1072 */
1087void 1073void GNUNET_FS_search_signal_suspend_ (void *cls);
1088GNUNET_FS_search_signal_suspend_ (void *cls);
1089 1074
1090/** 1075/**
1091 * Create SUSPEND event for the given download operation 1076 * Create SUSPEND event for the given download operation
@@ -1093,8 +1078,7 @@ GNUNET_FS_search_signal_suspend_ (void *cls);
1093 * 1078 *
1094 * @param cls the 'struct GNUNET_FS_DownloadContext' to signal for 1079 * @param cls the 'struct GNUNET_FS_DownloadContext' to signal for
1095 */ 1080 */
1096void 1081void GNUNET_FS_download_signal_suspend_ (void *cls);
1097GNUNET_FS_download_signal_suspend_ (void *cls);
1098 1082
1099/** 1083/**
1100 * Create SUSPEND event for the given unindex operation 1084 * Create SUSPEND event for the given unindex operation
@@ -1102,8 +1086,7 @@ GNUNET_FS_download_signal_suspend_ (void *cls);
1102 * 1086 *
1103 * @param cls the 'struct GNUNET_FS_UnindexContext' to signal for 1087 * @param cls the 'struct GNUNET_FS_UnindexContext' to signal for
1104 */ 1088 */
1105void 1089void GNUNET_FS_unindex_signal_suspend_ (void *cls);
1106GNUNET_FS_unindex_signal_suspend_ (void *cls);
1107 1090
1108/** 1091/**
1109 * Function signature of the functions that can be called 1092 * Function signature of the functions that can be called
@@ -1112,7 +1095,7 @@ GNUNET_FS_unindex_signal_suspend_ (void *cls);
1112 * 1095 *
1113 * @param cls closure 1096 * @param cls closure
1114 */ 1097 */
1115typedef void (*SuspendSignalFunction)(void *cls); 1098typedef void (*SuspendSignalFunction) (void *cls);
1116 1099
1117/** 1100/**
1118 * We track all of the top-level activities of FS 1101 * We track all of the top-level activities of FS
@@ -1122,12 +1105,12 @@ struct TopLevelActivity
1122{ 1105{
1123 /** 1106 /**
1124 * This is a doubly-linked list. 1107 * This is a doubly-linked list.
1125 */ 1108 */
1126 struct TopLevelActivity *next; 1109 struct TopLevelActivity *next;
1127 1110
1128 /** 1111 /**
1129 * This is a doubly-linked list. 1112 * This is a doubly-linked list.
1130 */ 1113 */
1131 struct TopLevelActivity *prev; 1114 struct TopLevelActivity *prev;
1132 1115
1133 /** 1116 /**
@@ -1150,10 +1133,9 @@ struct TopLevelActivity
1150 * @param ssf_cls closure for ssf 1133 * @param ssf_cls closure for ssf
1151 * @return fresh top-level activity handle 1134 * @return fresh top-level activity handle
1152 */ 1135 */
1153struct TopLevelActivity * 1136struct TopLevelActivity *GNUNET_FS_make_top (struct GNUNET_FS_Handle *h,
1154GNUNET_FS_make_top (struct GNUNET_FS_Handle *h, 1137 SuspendSignalFunction ssf,
1155 SuspendSignalFunction ssf, 1138 void *ssf_cls);
1156 void *ssf_cls);
1157 1139
1158 1140
1159/** 1141/**
@@ -1163,8 +1145,7 @@ GNUNET_FS_make_top (struct GNUNET_FS_Handle *h,
1163 * @param top top level activity entry 1145 * @param top top level activity entry
1164 */ 1146 */
1165void 1147void
1166GNUNET_FS_end_top (struct GNUNET_FS_Handle *h, 1148GNUNET_FS_end_top (struct GNUNET_FS_Handle *h, struct TopLevelActivity *top);
1167 struct TopLevelActivity *top);
1168 1149
1169 1150
1170 1151
@@ -1270,7 +1251,7 @@ struct GNUNET_FS_PublishContext
1270{ 1251{
1271 /** 1252 /**
1272 * Handle to the global fs context. 1253 * Handle to the global fs context.
1273 */ 1254 */
1274 struct GNUNET_FS_Handle *h; 1255 struct GNUNET_FS_Handle *h;
1275 1256
1276 /** 1257 /**
@@ -1378,37 +1359,36 @@ struct GNUNET_FS_PublishContext
1378 1359
1379/** 1360/**
1380 * Phases of unindex processing (state machine). 1361 * Phases of unindex processing (state machine).
1381 */ 1362 */
1382enum UnindexState 1363enum UnindexState
1383 { 1364{
1384 /** 1365 /**
1385 * We're currently hashing the file. 1366 * We're currently hashing the file.
1386 */ 1367 */
1387 UNINDEX_STATE_HASHING = 0, 1368 UNINDEX_STATE_HASHING = 0,
1388 1369
1389 /** 1370 /**
1390 * We're telling the datastore to delete 1371 * We're telling the datastore to delete
1391 * the respective entries. 1372 * the respective entries.
1392 */ 1373 */
1393 UNINDEX_STATE_DS_REMOVE = 1, 1374 UNINDEX_STATE_DS_REMOVE = 1,
1394 1375
1395 /** 1376 /**
1396 * We're notifying the FS service about 1377 * We're notifying the FS service about
1397 * the unindexing. 1378 * the unindexing.
1398 */ 1379 */
1399 UNINDEX_STATE_FS_NOTIFY = 2, 1380 UNINDEX_STATE_FS_NOTIFY = 2,
1400 1381
1401 /** 1382 /**
1402 * We're done. 1383 * We're done.
1403 */ 1384 */
1404 UNINDEX_STATE_COMPLETE = 3, 1385 UNINDEX_STATE_COMPLETE = 3,
1405 1386
1406 /** 1387 /**
1407 * We've encountered a fatal error. 1388 * We've encountered a fatal error.
1408 */ 1389 */
1409 UNINDEX_STATE_ERROR = 4 1390 UNINDEX_STATE_ERROR = 4
1410 1391};
1411 };
1412 1392
1413 1393
1414/** 1394/**
@@ -1416,7 +1396,7 @@ enum UnindexState
1416 */ 1396 */
1417struct GNUNET_FS_UnindexContext 1397struct GNUNET_FS_UnindexContext
1418{ 1398{
1419 1399
1420 /** 1400 /**
1421 * Global FS context. 1401 * Global FS context.
1422 */ 1402 */
@@ -1476,7 +1456,7 @@ struct GNUNET_FS_UnindexContext
1476 1456
1477 /** 1457 /**
1478 * Overall size of the file. 1458 * Overall size of the file.
1479 */ 1459 */
1480 uint64_t file_size; 1460 uint64_t file_size;
1481 1461
1482 /** 1462 /**
@@ -1488,11 +1468,11 @@ struct GNUNET_FS_UnindexContext
1488 * Hash of the file's contents (once computed). 1468 * Hash of the file's contents (once computed).
1489 */ 1469 */
1490 GNUNET_HashCode file_id; 1470 GNUNET_HashCode file_id;
1491 1471
1492 /** 1472 /**
1493 * Current operatinonal phase. 1473 * Current operatinonal phase.
1494 */ 1474 */
1495 enum UnindexState state; 1475 enum UnindexState state;
1496 1476
1497}; 1477};
1498 1478
@@ -1512,7 +1492,7 @@ struct SearchRequestEntry
1512 /** 1492 /**
1513 * Hash of the public key, also known as the query. 1493 * Hash of the public key, also known as the query.
1514 */ 1494 */
1515 GNUNET_HashCode query; 1495 GNUNET_HashCode query;
1516 1496
1517 /** 1497 /**
1518 * Map that contains a "struct GNUNET_FS_SearchResult" for each result that 1498 * Map that contains a "struct GNUNET_FS_SearchResult" for each result that
@@ -1592,7 +1572,7 @@ struct GNUNET_FS_SearchContext
1592 * have exactly as many entries as there were keywords. 1572 * have exactly as many entries as there were keywords.
1593 */ 1573 */
1594 struct SearchRequestEntry *requests; 1574 struct SearchRequestEntry *requests;
1595 1575
1596 /** 1576 /**
1597 * When did we start? 1577 * When did we start?
1598 */ 1578 */
@@ -1617,7 +1597,7 @@ struct GNUNET_FS_SearchContext
1617 * map have been passed to the service so far? 1597 * map have been passed to the service so far?
1618 */ 1598 */
1619 unsigned int keyword_offset; 1599 unsigned int keyword_offset;
1620 1600
1621 /** 1601 /**
1622 * Anonymity level for the search. 1602 * Anonymity level for the search.
1623 */ 1603 */
@@ -1631,7 +1611,7 @@ struct GNUNET_FS_SearchContext
1631 /** 1611 /**
1632 * Options for the search. 1612 * Options for the search.
1633 */ 1613 */
1634 enum GNUNET_FS_SearchOptions options; 1614 enum GNUNET_FS_SearchOptions options;
1635}; 1615};
1636 1616
1637 1617
@@ -1641,12 +1621,12 @@ struct GNUNET_FS_SearchContext
1641 * are documented in the comments. 1621 * are documented in the comments.
1642 */ 1622 */
1643enum BlockRequestState 1623enum BlockRequestState
1644 { 1624{
1645 /** 1625 /**
1646 * Initial state, block has only been allocated (since it is 1626 * Initial state, block has only been allocated (since it is
1647 * relevant to the overall download request). 1627 * relevant to the overall download request).
1648 */ 1628 */
1649 BRS_INIT = 0, 1629 BRS_INIT = 0,
1650 1630
1651 /** 1631 /**
1652 * We've checked the block on the path down the tree, and the 1632 * We've checked the block on the path down the tree, and the
@@ -1654,7 +1634,7 @@ enum BlockRequestState
1654 * the way down, so at the bottom some blocks will still 1634 * the way down, so at the bottom some blocks will still
1655 * need to be reconstructed). 1635 * need to be reconstructed).
1656 */ 1636 */
1657 BRS_RECONSTRUCT_DOWN = 1, 1637 BRS_RECONSTRUCT_DOWN = 1,
1658 1638
1659 /** 1639 /**
1660 * We've calculated the CHK bottom-up based on the meta data. 1640 * We've calculated the CHK bottom-up based on the meta data.
@@ -1662,7 +1642,7 @@ enum BlockRequestState
1662 * disk at the end (and we still need to check against the 1642 * disk at the end (and we still need to check against the
1663 * CHK set on top). 1643 * CHK set on top).
1664 */ 1644 */
1665 BRS_RECONSTRUCT_META_UP = 2, 1645 BRS_RECONSTRUCT_META_UP = 2,
1666 1646
1667 /** 1647 /**
1668 * We've calculated the CHK bottom-up based on what we have on 1648 * We've calculated the CHK bottom-up based on what we have on
@@ -1670,7 +1650,7 @@ enum BlockRequestState
1670 * reconstructed CHKs match whatever comes from above, we're 1650 * reconstructed CHKs match whatever comes from above, we're
1671 * done with the respective subtree. 1651 * done with the respective subtree.
1672 */ 1652 */
1673 BRS_RECONSTRUCT_UP = 3, 1653 BRS_RECONSTRUCT_UP = 3,
1674 1654
1675 /** 1655 /**
1676 * We've determined the real, desired CHK for this block 1656 * We've determined the real, desired CHK for this block
@@ -1679,7 +1659,7 @@ enum BlockRequestState
1679 * the top-level request, the state machine for the subtree 1659 * the top-level request, the state machine for the subtree
1680 * would have moved to BRS_DOWNLOAD_UP. 1660 * would have moved to BRS_DOWNLOAD_UP.
1681 */ 1661 */
1682 BRS_CHK_SET = 4, 1662 BRS_CHK_SET = 4,
1683 1663
1684 /** 1664 /**
1685 * We've successfully downloaded this block, but the children 1665 * We've successfully downloaded this block, but the children
@@ -1688,27 +1668,26 @@ enum BlockRequestState
1688 * state machine for this block may move to 1668 * state machine for this block may move to
1689 * BRS_DOWNLOAD_ERROR instead. 1669 * BRS_DOWNLOAD_ERROR instead.
1690 */ 1670 */
1691 BRS_DOWNLOAD_DOWN = 5, 1671 BRS_DOWNLOAD_DOWN = 5,
1692 1672
1693 /** 1673 /**
1694 * This block and all of its children have been downloaded 1674 * This block and all of its children have been downloaded
1695 * successfully (full completion propagates up). 1675 * successfully (full completion propagates up).
1696 */ 1676 */
1697 BRS_DOWNLOAD_UP = 6, 1677 BRS_DOWNLOAD_UP = 6,
1698 1678
1699 /** 1679 /**
1700 * We got a block back that matched the query but did not hash to 1680 * We got a block back that matched the query but did not hash to
1701 * the key (malicious publisher or hash collision); this block 1681 * the key (malicious publisher or hash collision); this block
1702 * can never be downloaded (error propagates up). 1682 * can never be downloaded (error propagates up).
1703 */ 1683 */
1704 BRS_ERROR = 7 1684 BRS_ERROR = 7
1705 1685};
1706 };
1707 1686
1708 1687
1709/** 1688/**
1710 * Information about an active download request. 1689 * Information about an active download request.
1711 */ 1690 */
1712struct DownloadRequest 1691struct DownloadRequest
1713{ 1692{
1714 /** 1693 /**
@@ -1735,7 +1714,7 @@ struct DownloadRequest
1735 * CHK for the request for this block (set during reconstruction 1714 * CHK for the request for this block (set during reconstruction
1736 * to what we have on disk, later to what we want to have). 1715 * to what we have on disk, later to what we want to have).
1737 */ 1716 */
1738 struct ContentHashKey chk; 1717 struct ContentHashKey chk;
1739 1718
1740 /** 1719 /**
1741 * Offset of the corresponding block. Specifically, first (!) byte of 1720 * Offset of the corresponding block. Specifically, first (!) byte of
@@ -1772,8 +1751,7 @@ struct DownloadRequest
1772 * 1751 *
1773 * @param dr request to free 1752 * @param dr request to free
1774 */ 1753 */
1775void 1754void GNUNET_FS_free_download_request_ (struct DownloadRequest *dr);
1776GNUNET_FS_free_download_request_ (struct DownloadRequest *dr);
1777 1755
1778 1756
1779/** 1757/**
@@ -1781,17 +1759,17 @@ GNUNET_FS_free_download_request_ (struct DownloadRequest *dr);
1781 */ 1759 */
1782struct GNUNET_FS_DownloadContext 1760struct GNUNET_FS_DownloadContext
1783{ 1761{
1784 1762
1785 /** 1763 /**
1786 * Global FS context. 1764 * Global FS context.
1787 */ 1765 */
1788 struct GNUNET_FS_Handle *h; 1766 struct GNUNET_FS_Handle *h;
1789 1767
1790 /** 1768 /**
1791 * Our top-level activity entry (if we are top-level, otherwise NULL). 1769 * Our top-level activity entry (if we are top-level, otherwise NULL).
1792 */ 1770 */
1793 struct TopLevelActivity *top; 1771 struct TopLevelActivity *top;
1794 1772
1795 /** 1773 /**
1796 * Connection to the FS service. 1774 * Connection to the FS service.
1797 */ 1775 */
@@ -2019,7 +1997,7 @@ struct NamespaceUpdateNode
2019 * freshness of the tree_id. 1997 * freshness of the tree_id.
2020 */ 1998 */
2021 unsigned int nug; 1999 unsigned int nug;
2022 2000
2023 /** 2001 /**
2024 * TREE this entry belongs to (if nug is current). 2002 * TREE this entry belongs to (if nug is current).
2025 */ 2003 */
@@ -2035,7 +2013,7 @@ struct GNUNET_FS_Namespace
2035 * Handle to the FS service context. 2013 * Handle to the FS service context.
2036 */ 2014 */
2037 struct GNUNET_FS_Handle *h; 2015 struct GNUNET_FS_Handle *h;
2038 2016
2039 /** 2017 /**
2040 * Array with information about nodes in the namespace. 2018 * Array with information about nodes in the namespace.
2041 */ 2019 */
@@ -2059,7 +2037,7 @@ struct GNUNET_FS_Namespace
2059 2037
2060 /** 2038 /**
2061 * Name of the namespace. 2039 * Name of the namespace.
2062 */ 2040 */
2063 char *name; 2041 char *name;
2064 2042
2065 /** 2043 /**
@@ -2113,7 +2091,7 @@ struct IndexStartMessage
2113 * full hash recomputation. 2091 * full hash recomputation.
2114 */ 2092 */
2115 uint64_t device GNUNET_PACKED; 2093 uint64_t device GNUNET_PACKED;
2116 2094
2117 /** 2095 /**
2118 * Inode of the file on the given device, as seen by the client 2096 * Inode of the file on the given device, as seen by the client
2119 * ("st_ino" field from "struct stat"). Use 0 if the OS does not 2097 * ("st_ino" field from "struct stat"). Use 0 if the OS does not
@@ -2128,8 +2106,8 @@ struct IndexStartMessage
2128 GNUNET_HashCode file_id; 2106 GNUNET_HashCode file_id;
2129 2107
2130 /* this is followed by a 0-terminated 2108 /* this is followed by a 0-terminated
2131 filename of a file with the hash 2109 * filename of a file with the hash
2132 "file_id" as seen by the client */ 2110 * "file_id" as seen by the client */
2133 2111
2134}; 2112};
2135 2113
@@ -2157,9 +2135,9 @@ struct IndexInfoMessage
2157 GNUNET_HashCode file_id; 2135 GNUNET_HashCode file_id;
2158 2136
2159 /* this is followed by a 0-terminated 2137 /* this is followed by a 0-terminated
2160 filename of a file with the hash 2138 * filename of a file with the hash
2161 "file_id" as seen by the client */ 2139 * "file_id" as seen by the client */
2162 2140
2163}; 2141};
2164 2142
2165 2143
@@ -2245,10 +2223,10 @@ struct SearchMessage
2245 GNUNET_HashCode query; 2223 GNUNET_HashCode query;
2246 2224
2247 /* this is followed by the hash codes of already-known 2225 /* this is followed by the hash codes of already-known
2248 results (which should hence be excluded from what 2226 * results (which should hence be excluded from what
2249 the service returns); naturally, this only applies 2227 * the service returns); naturally, this only applies
2250 to queries that can have multiple results, such as 2228 * to queries that can have multiple results, such as
2251 those for KBLOCKS (KSK) and SBLOCKS (SKS) */ 2229 * those for KBLOCKS (KSK) and SBLOCKS (SKS) */
2252}; 2230};
2253 2231
2254 2232
@@ -2333,10 +2311,10 @@ struct GetMessage
2333 GNUNET_HashCode query GNUNET_PACKED; 2311 GNUNET_HashCode query GNUNET_PACKED;
2334 2312
2335 /* this is followed by hash codes 2313 /* this is followed by hash codes
2336 as specified in the "hash_bitmap"; 2314 * as specified in the "hash_bitmap";
2337 after that, an optional bloomfilter 2315 * after that, an optional bloomfilter
2338 (with bits set for replies that should 2316 * (with bits set for replies that should
2339 be suppressed) can be present */ 2317 * be suppressed) can be present */
2340}; 2318};
2341 2319
2342 2320
diff --git a/src/fs/fs_directory.c b/src/fs/fs_directory.c
index dbd10c35e..f22480d5f 100644
--- a/src/fs/fs_directory.c
+++ b/src/fs/fs_directory.c
@@ -50,20 +50,22 @@
50 * @return GNUNET_YES if it is, GNUNET_NO if it is not, GNUNET_SYSERR if 50 * @return GNUNET_YES if it is, GNUNET_NO if it is not, GNUNET_SYSERR if
51 * we have no mime-type information (treat as 'GNUNET_NO') 51 * we have no mime-type information (treat as 'GNUNET_NO')
52 */ 52 */
53int 53int
54GNUNET_FS_meta_data_test_for_directory (const struct GNUNET_CONTAINER_MetaData *md) 54GNUNET_FS_meta_data_test_for_directory (const struct GNUNET_CONTAINER_MetaData
55 *md)
55{ 56{
56 char *mime; 57 char *mime;
57 int ret; 58 int ret;
58 59
59 if (NULL == md) 60 if (NULL == md)
60 return GNUNET_SYSERR; 61 return GNUNET_SYSERR;
61 mime = GNUNET_CONTAINER_meta_data_get_by_type (md, EXTRACTOR_METATYPE_MIMETYPE); 62 mime =
63 GNUNET_CONTAINER_meta_data_get_by_type (md, EXTRACTOR_METATYPE_MIMETYPE);
62 if (mime == NULL) 64 if (mime == NULL)
63 return GNUNET_SYSERR; 65 return GNUNET_SYSERR;
64 ret = (0 == strcmp (mime, GNUNET_FS_DIRECTORY_MIME)) ? GNUNET_YES : GNUNET_NO; 66 ret = (0 == strcmp (mime, GNUNET_FS_DIRECTORY_MIME)) ? GNUNET_YES : GNUNET_NO;
65 GNUNET_free (mime); 67 GNUNET_free (mime);
66 return ret; 68 return ret;
67} 69}
68 70
69 71
@@ -77,29 +79,29 @@ void
77GNUNET_FS_meta_data_make_directory (struct GNUNET_CONTAINER_MetaData *md) 79GNUNET_FS_meta_data_make_directory (struct GNUNET_CONTAINER_MetaData *md)
78{ 80{
79 char *mime; 81 char *mime;
80 82
81 mime = GNUNET_CONTAINER_meta_data_get_by_type (md, EXTRACTOR_METATYPE_MIMETYPE); 83 mime =
84 GNUNET_CONTAINER_meta_data_get_by_type (md, EXTRACTOR_METATYPE_MIMETYPE);
82 if (mime != NULL) 85 if (mime != NULL)
83 { 86 {
84 GNUNET_break (0 == strcmp (mime, 87 GNUNET_break (0 == strcmp (mime, GNUNET_FS_DIRECTORY_MIME));
85 GNUNET_FS_DIRECTORY_MIME)); 88 GNUNET_free (mime);
86 GNUNET_free (mime); 89 return;
87 return; 90 }
88 } 91 GNUNET_CONTAINER_meta_data_insert (md,
89 GNUNET_CONTAINER_meta_data_insert (md, 92 "<gnunet>",
90 "<gnunet>", 93 EXTRACTOR_METATYPE_MIMETYPE,
91 EXTRACTOR_METATYPE_MIMETYPE, 94 EXTRACTOR_METAFORMAT_UTF8,
92 EXTRACTOR_METAFORMAT_UTF8, 95 "text/plain",
93 "text/plain", 96 GNUNET_FS_DIRECTORY_MIME,
94 GNUNET_FS_DIRECTORY_MIME, 97 strlen (GNUNET_FS_DIRECTORY_MIME) + 1);
95 strlen (GNUNET_FS_DIRECTORY_MIME)+1);
96} 98}
97 99
98 100
99/** 101/**
100 * Closure for 'find_full_data'. 102 * Closure for 'find_full_data'.
101 */ 103 */
102struct GetFullDataClosure 104struct GetFullDataClosure
103{ 105{
104 106
105 /** 107 /**
@@ -130,30 +132,26 @@ struct GetFullDataClosure
130 * @param data actual meta-data found 132 * @param data actual meta-data found
131 * @param data_len number of bytes in data 133 * @param data_len number of bytes in data
132 * @return 0 to continue extracting, 1 to abort 134 * @return 0 to continue extracting, 1 to abort
133 */ 135 */
134static int 136static int
135find_full_data (void *cls, 137find_full_data (void *cls,
136 const char *plugin_name, 138 const char *plugin_name,
137 enum EXTRACTOR_MetaType type, 139 enum EXTRACTOR_MetaType type,
138 enum EXTRACTOR_MetaFormat format, 140 enum EXTRACTOR_MetaFormat format,
139 const char *data_mime_type, 141 const char *data_mime_type, const char *data, size_t data_len)
140 const char *data,
141 size_t data_len)
142{ 142{
143 struct GetFullDataClosure *gfdc = cls; 143 struct GetFullDataClosure *gfdc = cls;
144 144
145 if (type == EXTRACTOR_METATYPE_GNUNET_FULL_DATA) 145 if (type == EXTRACTOR_METATYPE_GNUNET_FULL_DATA)
146 {
147 gfdc->size = data_len;
148 if (data_len > 0)
146 { 149 {
147 gfdc->size = data_len; 150 gfdc->data = GNUNET_malloc (data_len);
148 if (data_len > 0) 151 memcpy (gfdc->data, data, data_len);
149 {
150 gfdc->data = GNUNET_malloc (data_len);
151 memcpy (gfdc->data,
152 data,
153 data_len);
154 }
155 return 1;
156 } 152 }
153 return 1;
154 }
157 return 0; 155 return 0;
158} 156}
159 157
@@ -183,12 +181,12 @@ find_full_data (void *cls,
183 * GNUNET_NO if this could be part of a directory (but not 100% OK) 181 * GNUNET_NO if this could be part of a directory (but not 100% OK)
184 * GNUNET_SYSERR if 'data' does not represent a directory 182 * GNUNET_SYSERR if 'data' does not represent a directory
185 */ 183 */
186int 184int
187GNUNET_FS_directory_list_contents (size_t size, 185GNUNET_FS_directory_list_contents (size_t size,
188 const void *data, 186 const void *data,
189 uint64_t offset, 187 uint64_t offset,
190 GNUNET_FS_DirectoryEntryProcessor dep, 188 GNUNET_FS_DirectoryEntryProcessor dep,
191 void *dep_cls) 189 void *dep_cls)
192{ 190{
193 struct GetFullDataClosure full_data; 191 struct GetFullDataClosure full_data;
194 const char *cdata = data; 192 const char *cdata = data;
@@ -201,123 +199,110 @@ GNUNET_FS_directory_list_contents (size_t size,
201 struct GNUNET_CONTAINER_MetaData *md; 199 struct GNUNET_CONTAINER_MetaData *md;
202 char *filename; 200 char *filename;
203 201
204 if ( (offset == 0) && 202 if ((offset == 0) &&
205 ( (size < 8 + sizeof (uint32_t)) || 203 ((size < 8 + sizeof (uint32_t)) ||
206 (0 != memcmp (cdata, GNUNET_FS_DIRECTORY_MAGIC, 8)) ) ) 204 (0 != memcmp (cdata, GNUNET_FS_DIRECTORY_MAGIC, 8))))
205 {
206 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
207 _("MAGIC mismatch. This is not a GNUnet directory.\n"));
208 return GNUNET_SYSERR;
209 }
210 pos = offset;
211 if (offset == 0)
212 {
213 memcpy (&mdSize, &cdata[8], sizeof (uint32_t));
214 mdSize = ntohl (mdSize);
215 if (mdSize > size - 8 - sizeof (uint32_t))
207 { 216 {
217 /* invalid size */
208 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 218 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
209 _("MAGIC mismatch. This is not a GNUnet directory.\n")); 219 _("MAGIC mismatch. This is not a GNUnet directory.\n"));
210 return GNUNET_SYSERR; 220 return GNUNET_SYSERR;
211 } 221 }
212 pos = offset; 222 md = GNUNET_CONTAINER_meta_data_deserialize (&cdata[8 +
213 if (offset == 0) 223 sizeof (uint32_t)],
224 mdSize);
225 if (md == NULL)
214 { 226 {
215 memcpy (&mdSize, &cdata[8], sizeof (uint32_t)); 227 GNUNET_break (0);
216 mdSize = ntohl (mdSize); 228 return GNUNET_SYSERR; /* malformed ! */
217 if (mdSize > size - 8 - sizeof (uint32_t))
218 {
219 /* invalid size */
220 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
221 _("MAGIC mismatch. This is not a GNUnet directory.\n"));
222 return GNUNET_SYSERR;
223 }
224 md = GNUNET_CONTAINER_meta_data_deserialize (&cdata[8 +
225 sizeof (uint32_t)],
226 mdSize);
227 if (md == NULL)
228 {
229 GNUNET_break (0);
230 return GNUNET_SYSERR; /* malformed ! */
231 }
232 dep (dep_cls,
233 NULL,
234 NULL,
235 md,
236 0,
237 NULL);
238 GNUNET_CONTAINER_meta_data_destroy (md);
239 pos = 8 + sizeof (uint32_t) + mdSize;
240 } 229 }
230 dep (dep_cls, NULL, NULL, md, 0, NULL);
231 GNUNET_CONTAINER_meta_data_destroy (md);
232 pos = 8 + sizeof (uint32_t) + mdSize;
233 }
241 while (pos < size) 234 while (pos < size)
235 {
236 /* find end of URI */
237 if (cdata[pos] == '\0')
242 { 238 {
243 /* find end of URI */ 239 /* URI is never empty, must be end of block,
244 if (cdata[pos] == '\0') 240 * skip to next alignment */
245 { 241 align = ((pos / DBLOCK_SIZE) + 1) * DBLOCK_SIZE;
246 /* URI is never empty, must be end of block, 242 if (align == pos)
247 skip to next alignment */ 243 {
248 align = 244 /* if we were already aligned, still skip a block! */
249 ((pos / DBLOCK_SIZE) + 1) * DBLOCK_SIZE; 245 align += DBLOCK_SIZE;
250 if (align == pos) 246 }
251 { 247 pos = align;
252 /* if we were already aligned, still skip a block! */ 248 if (pos >= size)
253 align += DBLOCK_SIZE; 249 {
254 } 250 /* malformed - or partial download... */
255 pos = align; 251 break;
256 if (pos >= size) 252 }
257 { 253 }
258 /* malformed - or partial download... */ 254 epos = pos;
259 break; 255 while ((epos < size) && (cdata[epos] != '\0'))
260 } 256 epos++;
261 } 257 if (epos >= size)
262 epos = pos; 258 return GNUNET_NO; /* malformed - or partial download */
263 while ((epos < size) && (cdata[epos] != '\0')) 259
264 epos++; 260 uri = GNUNET_FS_uri_parse (&cdata[pos], &emsg);
265 if (epos >= size) 261 pos = epos + 1;
266 return GNUNET_NO; /* malformed - or partial download */ 262 if (uri == NULL)
267 263 {
268 uri = GNUNET_FS_uri_parse (&cdata[pos], &emsg); 264 GNUNET_free (emsg);
269 pos = epos + 1; 265 pos--; /* go back to '\0' to force going to next alignment */
270 if (uri == NULL) 266 continue;
271 { 267 }
272 GNUNET_free (emsg); 268 if (GNUNET_FS_uri_test_ksk (uri))
273 pos--; /* go back to '\0' to force going to next alignment */ 269 {
274 continue; 270 GNUNET_FS_uri_destroy (uri);
275 } 271 GNUNET_break (0);
276 if (GNUNET_FS_uri_test_ksk (uri)) 272 return GNUNET_NO; /* illegal in directory! */
277 { 273 }
278 GNUNET_FS_uri_destroy (uri);
279 GNUNET_break (0);
280 return GNUNET_NO; /* illegal in directory! */
281 }
282 274
283 memcpy (&mdSize, &cdata[pos], sizeof (uint32_t)); 275 memcpy (&mdSize, &cdata[pos], sizeof (uint32_t));
284 mdSize = ntohl (mdSize); 276 mdSize = ntohl (mdSize);
285 pos += sizeof (uint32_t); 277 pos += sizeof (uint32_t);
286 if (pos + mdSize > size) 278 if (pos + mdSize > size)
287 { 279 {
288 GNUNET_FS_uri_destroy (uri); 280 GNUNET_FS_uri_destroy (uri);
289 return GNUNET_NO; /* malformed - or partial download */ 281 return GNUNET_NO; /* malformed - or partial download */
290 } 282 }
291 283
292 md = GNUNET_CONTAINER_meta_data_deserialize (&cdata[pos], mdSize); 284 md = GNUNET_CONTAINER_meta_data_deserialize (&cdata[pos], mdSize);
293 if (md == NULL) 285 if (md == NULL)
294 { 286 {
295 GNUNET_FS_uri_destroy (uri);
296 GNUNET_break (0);
297 return GNUNET_NO; /* malformed ! */
298 }
299 pos += mdSize;
300 filename = GNUNET_CONTAINER_meta_data_get_by_type (md,
301 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME);
302 full_data.size = 0;
303 full_data.data = NULL;
304 GNUNET_CONTAINER_meta_data_iterate (md,
305 &find_full_data,
306 &full_data);
307 if (dep != NULL)
308 {
309 dep (dep_cls,
310 filename,
311 uri,
312 md,
313 full_data.size,
314 full_data.data);
315 }
316 GNUNET_free_non_null (full_data.data);
317 GNUNET_free_non_null (filename);
318 GNUNET_CONTAINER_meta_data_destroy (md);
319 GNUNET_FS_uri_destroy (uri); 287 GNUNET_FS_uri_destroy (uri);
288 GNUNET_break (0);
289 return GNUNET_NO; /* malformed ! */
320 } 290 }
291 pos += mdSize;
292 filename = GNUNET_CONTAINER_meta_data_get_by_type (md,
293 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME);
294 full_data.size = 0;
295 full_data.data = NULL;
296 GNUNET_CONTAINER_meta_data_iterate (md, &find_full_data, &full_data);
297 if (dep != NULL)
298 {
299 dep (dep_cls, filename, uri, md, full_data.size, full_data.data);
300 }
301 GNUNET_free_non_null (full_data.data);
302 GNUNET_free_non_null (filename);
303 GNUNET_CONTAINER_meta_data_destroy (md);
304 GNUNET_FS_uri_destroy (uri);
305 }
321 return GNUNET_OK; 306 return GNUNET_OK;
322} 307}
323 308
@@ -330,7 +315,7 @@ struct BuilderEntry
330 * This is a linked list. 315 * This is a linked list.
331 */ 316 */
332 struct BuilderEntry *next; 317 struct BuilderEntry *next;
333 318
334 /** 319 /**
335 * Length of this entry. 320 * Length of this entry.
336 */ 321 */
@@ -365,11 +350,12 @@ struct GNUNET_FS_DirectoryBuilder
365 * @param mdir metadata for the directory 350 * @param mdir metadata for the directory
366 */ 351 */
367struct GNUNET_FS_DirectoryBuilder * 352struct GNUNET_FS_DirectoryBuilder *
368GNUNET_FS_directory_builder_create (const struct GNUNET_CONTAINER_MetaData *mdir) 353GNUNET_FS_directory_builder_create (const struct GNUNET_CONTAINER_MetaData
354 *mdir)
369{ 355{
370 struct GNUNET_FS_DirectoryBuilder *ret; 356 struct GNUNET_FS_DirectoryBuilder *ret;
371 357
372 ret = GNUNET_malloc(sizeof(struct GNUNET_FS_DirectoryBuilder)); 358 ret = GNUNET_malloc (sizeof (struct GNUNET_FS_DirectoryBuilder));
373 if (mdir != NULL) 359 if (mdir != NULL)
374 ret->meta = GNUNET_CONTAINER_meta_data_duplicate (mdir); 360 ret->meta = GNUNET_CONTAINER_meta_data_duplicate (mdir);
375 else 361 else
@@ -391,9 +377,9 @@ GNUNET_FS_directory_builder_create (const struct GNUNET_CONTAINER_MetaData *mdir
391 */ 377 */
392void 378void
393GNUNET_FS_directory_builder_add (struct GNUNET_FS_DirectoryBuilder *bld, 379GNUNET_FS_directory_builder_add (struct GNUNET_FS_DirectoryBuilder *bld,
394 const struct GNUNET_FS_Uri *uri, 380 const struct GNUNET_FS_Uri *uri,
395 const struct GNUNET_CONTAINER_MetaData *md, 381 const struct GNUNET_CONTAINER_MetaData *md,
396 const void *data) 382 const void *data)
397{ 383{
398 struct GNUNET_FS_Uri *curi; 384 struct GNUNET_FS_Uri *curi;
399 struct BuilderEntry *e; 385 struct BuilderEntry *e;
@@ -409,68 +395,64 @@ GNUNET_FS_directory_builder_add (struct GNUNET_FS_DirectoryBuilder *bld,
409 struct GNUNET_CONTAINER_MetaData *meta; 395 struct GNUNET_CONTAINER_MetaData *meta;
410 const struct GNUNET_CONTAINER_MetaData *meta_use; 396 const struct GNUNET_CONTAINER_MetaData *meta_use;
411 397
412 GNUNET_assert (! GNUNET_FS_uri_test_ksk (uri)); 398 GNUNET_assert (!GNUNET_FS_uri_test_ksk (uri));
413 if (NULL != data) 399 if (NULL != data)
400 {
401 GNUNET_assert (!GNUNET_FS_uri_test_sks (uri));
402 if (GNUNET_FS_uri_test_chk (uri))
414 { 403 {
415 GNUNET_assert (! GNUNET_FS_uri_test_sks (uri)); 404 fsize = GNUNET_FS_uri_chk_get_file_size (uri);
416 if (GNUNET_FS_uri_test_chk (uri))
417 {
418 fsize = GNUNET_FS_uri_chk_get_file_size (uri);
419 }
420 else
421 {
422 curi = GNUNET_FS_uri_loc_get_uri (uri);
423 GNUNET_assert (NULL != curi);
424 fsize = GNUNET_FS_uri_chk_get_file_size (curi);
425 GNUNET_FS_uri_destroy (curi);
426 }
427 } 405 }
428 else 406 else
429 { 407 {
430 fsize = 0; /* not given */ 408 curi = GNUNET_FS_uri_loc_get_uri (uri);
409 GNUNET_assert (NULL != curi);
410 fsize = GNUNET_FS_uri_chk_get_file_size (curi);
411 GNUNET_FS_uri_destroy (curi);
431 } 412 }
413 }
414 else
415 {
416 fsize = 0; /* not given */
417 }
432 if (fsize > MAX_INLINE_SIZE) 418 if (fsize > MAX_INLINE_SIZE)
433 fsize = 0; /* too large */ 419 fsize = 0; /* too large */
434 uris = GNUNET_FS_uri_to_string (uri); 420 uris = GNUNET_FS_uri_to_string (uri);
435 slen = strlen (uris) + 1; 421 slen = strlen (uris) + 1;
436 mds = 422 mds = GNUNET_CONTAINER_meta_data_get_serialized_size (md);
437 GNUNET_CONTAINER_meta_data_get_serialized_size (md);
438 meta_use = md; 423 meta_use = md;
439 meta = NULL; 424 meta = NULL;
440 if (fsize > 0) 425 if (fsize > 0)
426 {
427 meta = GNUNET_CONTAINER_meta_data_duplicate (md);
428 GNUNET_CONTAINER_meta_data_insert (meta,
429 "<gnunet>",
430 EXTRACTOR_METATYPE_GNUNET_FULL_DATA,
431 EXTRACTOR_METAFORMAT_BINARY,
432 NULL, data, fsize);
433 mdxs = GNUNET_CONTAINER_meta_data_get_serialized_size (meta);
434 if ((slen + sizeof (uint32_t) + mdxs - 1) / DBLOCK_SIZE ==
435 (slen + sizeof (uint32_t) + mds - 1) / DBLOCK_SIZE)
441 { 436 {
442 meta = GNUNET_CONTAINER_meta_data_duplicate (md); 437 /* adding full data would not cause us to cross
443 GNUNET_CONTAINER_meta_data_insert (meta, 438 * additional blocks, so add it! */
444 "<gnunet>", 439 meta_use = meta;
445 EXTRACTOR_METATYPE_GNUNET_FULL_DATA, 440 mds = mdxs;
446 EXTRACTOR_METAFORMAT_BINARY,
447 NULL,
448 data,
449 fsize);
450 mdxs =
451 GNUNET_CONTAINER_meta_data_get_serialized_size (meta);
452 if ( (slen + sizeof (uint32_t) + mdxs - 1) / DBLOCK_SIZE ==
453 (slen + sizeof (uint32_t) + mds - 1) / DBLOCK_SIZE)
454 {
455 /* adding full data would not cause us to cross
456 additional blocks, so add it! */
457 meta_use = meta;
458 mds = mdxs;
459 }
460 } 441 }
442 }
461 443
462 if (mds > GNUNET_MAX_MALLOC_CHECKED / 2) 444 if (mds > GNUNET_MAX_MALLOC_CHECKED / 2)
463 mds = GNUNET_MAX_MALLOC_CHECKED / 2; 445 mds = GNUNET_MAX_MALLOC_CHECKED / 2;
464 e = GNUNET_malloc (sizeof(struct BuilderEntry) + 446 e = GNUNET_malloc (sizeof (struct BuilderEntry) +
465 slen + mds + sizeof (uint32_t)); 447 slen + mds + sizeof (uint32_t));
466 ser = (char*) &e[1]; 448 ser = (char *) &e[1];
467 memcpy (ser, uris, slen); 449 memcpy (ser, uris, slen);
468 GNUNET_free (uris); 450 GNUNET_free (uris);
469 sptr = &ser[slen + sizeof(uint32_t)]; 451 sptr = &ser[slen + sizeof (uint32_t)];
470 ret = GNUNET_CONTAINER_meta_data_serialize (meta_use, 452 ret = GNUNET_CONTAINER_meta_data_serialize (meta_use,
471 &sptr, 453 &sptr,
472 mds, 454 mds,
473 GNUNET_CONTAINER_META_DATA_SERIALIZE_PART); 455 GNUNET_CONTAINER_META_DATA_SERIALIZE_PART);
474 if (NULL != meta) 456 if (NULL != meta)
475 GNUNET_CONTAINER_meta_data_destroy (meta); 457 GNUNET_CONTAINER_meta_data_destroy (meta);
476 if (ret == -1) 458 if (ret == -1)
@@ -492,11 +474,10 @@ GNUNET_FS_directory_builder_add (struct GNUNET_FS_DirectoryBuilder *bld,
492 * after alignment to the DBLOCK_SIZE. 474 * after alignment to the DBLOCK_SIZE.
493 */ 475 */
494static size_t 476static size_t
495do_align (size_t start_position, 477do_align (size_t start_position, size_t end_position)
496 size_t end_position)
497{ 478{
498 size_t align; 479 size_t align;
499 480
500 align = (end_position / DBLOCK_SIZE) * DBLOCK_SIZE; 481 align = (end_position / DBLOCK_SIZE) * DBLOCK_SIZE;
501 if ((start_position < align) && (end_position > align)) 482 if ((start_position < align) && (end_position > align))
502 return align + end_position - start_position; 483 return align + end_position - start_position;
@@ -515,9 +496,7 @@ do_align (size_t start_position,
515 */ 496 */
516static void 497static void
517block_align (size_t start, 498block_align (size_t start,
518 unsigned int count, 499 unsigned int count, const size_t * sizes, unsigned int *perm)
519 const size_t *sizes,
520 unsigned int *perm)
521{ 500{
522 unsigned int i; 501 unsigned int i;
523 unsigned int j; 502 unsigned int j;
@@ -531,51 +510,46 @@ block_align (size_t start,
531 510
532 cpos = start; 511 cpos = start;
533 for (i = 0; i < count; i++) 512 for (i = 0; i < count; i++)
513 {
514 start = cpos;
515 badness = 0x7FFFFFFF;
516 best = -1;
517 for (j = i; j < count; j++)
534 { 518 {
535 start = cpos; 519 cval = perm[j];
536 badness = 0x7FFFFFFF; 520 cend = cpos + sizes[cval];
537 best = -1; 521 if (cpos % DBLOCK_SIZE == 0)
538 for (j = i; j < count; j++) 522 {
523 /* prefer placing the largest blocks first */
524 cbad = -(cend % DBLOCK_SIZE);
525 }
526 else
527 {
528 if (cpos / DBLOCK_SIZE == cend / DBLOCK_SIZE)
529 {
530 /* Data fits into the same block! Prefer small left-overs! */
531 cbad = DBLOCK_SIZE - cend % DBLOCK_SIZE;
532 }
533 else
539 { 534 {
540 cval = perm[j]; 535 /* Would have to waste space to re-align, add big factor, this
541 cend = cpos + sizes[cval]; 536 * case is a real loss (proportional to space wasted)! */
542 if (cpos % DBLOCK_SIZE == 0) 537 cbad = DBLOCK_SIZE * (DBLOCK_SIZE - cpos % DBLOCK_SIZE);
543 {
544 /* prefer placing the largest blocks first */
545 cbad = -(cend % DBLOCK_SIZE);
546 }
547 else
548 {
549 if (cpos / DBLOCK_SIZE ==
550 cend / DBLOCK_SIZE)
551 {
552 /* Data fits into the same block! Prefer small left-overs! */
553 cbad =
554 DBLOCK_SIZE - cend % DBLOCK_SIZE;
555 }
556 else
557 {
558 /* Would have to waste space to re-align, add big factor, this
559 case is a real loss (proportional to space wasted)! */
560 cbad =
561 DBLOCK_SIZE * (DBLOCK_SIZE -
562 cpos %
563 DBLOCK_SIZE);
564 }
565 }
566 if (cbad < badness)
567 {
568 best = j;
569 badness = cbad;
570 }
571 } 538 }
572 GNUNET_assert (best != -1); 539 }
573 tmp = perm[i]; 540 if (cbad < badness)
574 perm[i] = perm[best]; 541 {
575 perm[best] = tmp; 542 best = j;
576 cpos += sizes[perm[i]]; 543 badness = cbad;
577 cpos = do_align (start, cpos); 544 }
578 } 545 }
546 GNUNET_assert (best != -1);
547 tmp = perm[i];
548 perm[i] = perm[best];
549 perm[best] = tmp;
550 cpos += sizes[perm[i]];
551 cpos = do_align (start, cpos);
552 }
579} 553}
580 554
581 555
@@ -591,8 +565,7 @@ block_align (size_t start,
591 */ 565 */
592int 566int
593GNUNET_FS_directory_builder_finish (struct GNUNET_FS_DirectoryBuilder *bld, 567GNUNET_FS_directory_builder_finish (struct GNUNET_FS_DirectoryBuilder *bld,
594 size_t *rsize, 568 size_t * rsize, void **rdata)
595 void **rdata)
596{ 569{
597 char *data; 570 char *data;
598 char *sptr; 571 char *sptr;
@@ -614,71 +587,65 @@ GNUNET_FS_directory_builder_finish (struct GNUNET_FS_DirectoryBuilder *bld,
614 perm = NULL; 587 perm = NULL;
615 bes = NULL; 588 bes = NULL;
616 if (0 < bld->count) 589 if (0 < bld->count)
590 {
591 sizes = GNUNET_malloc (bld->count * sizeof (size_t));
592 perm = GNUNET_malloc (bld->count * sizeof (unsigned int));
593 bes = GNUNET_malloc (bld->count * sizeof (struct BuilderEntry *));
594 pos = bld->head;
595 for (i = 0; i < bld->count; i++)
596 {
597 perm[i] = i;
598 bes[i] = pos;
599 sizes[i] = pos->len;
600 pos = pos->next;
601 }
602 block_align (size, bld->count, sizes, perm);
603 /* compute final size with alignment */
604 for (i = 0; i < bld->count; i++)
617 { 605 {
618 sizes = GNUNET_malloc (bld->count * sizeof (size_t)); 606 psize = size;
619 perm = GNUNET_malloc (bld->count * sizeof (unsigned int)); 607 size += sizes[perm[i]];
620 bes = GNUNET_malloc (bld->count * sizeof (struct BuilderEntry *)); 608 size = do_align (psize, size);
621 pos = bld->head;
622 for (i = 0; i < bld->count; i++)
623 {
624 perm[i] = i;
625 bes[i] = pos;
626 sizes[i] = pos->len;
627 pos = pos->next;
628 }
629 block_align (size,
630 bld->count,
631 sizes,
632 perm);
633 /* compute final size with alignment */
634 for (i = 0; i < bld->count; i++)
635 {
636 psize = size;
637 size += sizes[perm[i]];
638 size = do_align (psize, size);
639 }
640 } 609 }
610 }
641 *rsize = size; 611 *rsize = size;
642 data = GNUNET_malloc_large (size); 612 data = GNUNET_malloc_large (size);
643 if (data == NULL) 613 if (data == NULL)
644 { 614 {
645 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, 615 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "malloc");
646 "malloc"); 616 *rsize = 0;
647 *rsize = 0; 617 *rdata = NULL;
648 *rdata = NULL; 618 GNUNET_free_non_null (sizes);
649 GNUNET_free_non_null (sizes); 619 GNUNET_free_non_null (perm);
650 GNUNET_free_non_null (perm); 620 GNUNET_free_non_null (bes);
651 GNUNET_free_non_null (bes); 621 return GNUNET_SYSERR;
652 return GNUNET_SYSERR; 622 }
653 }
654 *rdata = data; 623 *rdata = data;
655 memcpy (data, GNUNET_DIRECTORY_MAGIC, strlen (GNUNET_DIRECTORY_MAGIC)); 624 memcpy (data, GNUNET_DIRECTORY_MAGIC, strlen (GNUNET_DIRECTORY_MAGIC));
656 off = strlen (GNUNET_DIRECTORY_MAGIC); 625 off = strlen (GNUNET_DIRECTORY_MAGIC);
657 626
658 sptr = &data[off + sizeof (uint32_t)]; 627 sptr = &data[off + sizeof (uint32_t)];
659 ret = GNUNET_CONTAINER_meta_data_serialize (bld->meta, 628 ret = GNUNET_CONTAINER_meta_data_serialize (bld->meta,
660 &sptr, 629 &sptr,
661 size - off - sizeof (uint32_t), 630 size - off - sizeof (uint32_t),
662 GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL); 631 GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL);
663 GNUNET_assert (ret != -1); 632 GNUNET_assert (ret != -1);
664 big = htonl (ret); 633 big = htonl (ret);
665 memcpy (&data[off], &big, sizeof (uint32_t)); 634 memcpy (&data[off], &big, sizeof (uint32_t));
666 off += sizeof (uint32_t) + ret; 635 off += sizeof (uint32_t) + ret;
667 for (j = 0; j < bld->count; j++) 636 for (j = 0; j < bld->count; j++)
668 { 637 {
669 i = perm[j]; 638 i = perm[j];
670 psize = off; 639 psize = off;
671 off += sizes[i]; 640 off += sizes[i];
672 off = do_align (psize, off); 641 off = do_align (psize, off);
673 memcpy (&data[off - sizes[i]], 642 memcpy (&data[off - sizes[i]], &(bes[i])[1], sizes[i]);
674 &(bes[i])[1], 643 GNUNET_free (bes[i]);
675 sizes[i]); 644 }
676 GNUNET_free (bes[i]);
677 }
678 GNUNET_free_non_null (sizes); 645 GNUNET_free_non_null (sizes);
679 GNUNET_free_non_null (perm); 646 GNUNET_free_non_null (perm);
680 GNUNET_free_non_null (bes); 647 GNUNET_free_non_null (bes);
681 GNUNET_assert (off == size); 648 GNUNET_assert (off == size);
682 GNUNET_CONTAINER_meta_data_destroy (bld->meta); 649 GNUNET_CONTAINER_meta_data_destroy (bld->meta);
683 GNUNET_free (bld); 650 GNUNET_free (bld);
684 return GNUNET_OK; 651 return GNUNET_OK;
diff --git a/src/fs/fs_download.c b/src/fs/fs_download.c
index e515b147d..6b72b4e56 100644
--- a/src/fs/fs_download.c
+++ b/src/fs/fs_download.c
@@ -40,14 +40,15 @@
40static int 40static int
41is_recursive_download (struct GNUNET_FS_DownloadContext *dc) 41is_recursive_download (struct GNUNET_FS_DownloadContext *dc)
42{ 42{
43 return (0 != (dc->options & GNUNET_FS_DOWNLOAD_OPTION_RECURSIVE)) && 43 return (0 != (dc->options & GNUNET_FS_DOWNLOAD_OPTION_RECURSIVE)) &&
44 ( (GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (dc->meta)) || 44 ((GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (dc->meta)) ||
45 ( (dc->meta == NULL) && 45 ((dc->meta == NULL) &&
46 ( (NULL == dc->filename) || 46 ((NULL == dc->filename) ||
47 ( (strlen (dc->filename) >= strlen (GNUNET_FS_DIRECTORY_EXT)) && 47 ((strlen (dc->filename) >= strlen (GNUNET_FS_DIRECTORY_EXT)) &&
48 (NULL != 48 (NULL !=
49 strstr (dc->filename + strlen(dc->filename) - strlen(GNUNET_FS_DIRECTORY_EXT), 49 strstr (dc->filename + strlen (dc->filename) -
50 GNUNET_FS_DIRECTORY_EXT)) ) ) ) ); 50 strlen (GNUNET_FS_DIRECTORY_EXT),
51 GNUNET_FS_DIRECTORY_EXT))))));
51} 52}
52 53
53 54
@@ -68,31 +69,31 @@ is_recursive_download (struct GNUNET_FS_DownloadContext *dc)
68 * with the range for any other block 69 * with the range for any other block
69 */ 70 */
70static uint64_t 71static uint64_t
71compute_disk_offset (uint64_t fsize, 72compute_disk_offset (uint64_t fsize, uint64_t off, unsigned int depth)
72 uint64_t off,
73 unsigned int depth)
74{ 73{
75 unsigned int i; 74 unsigned int i;
76 uint64_t lsize; /* what is the size of all IBlocks for depth "i"? */ 75 uint64_t lsize; /* what is the size of all IBlocks for depth "i"? */
77 uint64_t loff; /* where do IBlocks for depth "i" start? */ 76 uint64_t loff; /* where do IBlocks for depth "i" start? */
78 unsigned int ioff; /* which IBlock corresponds to "off" at depth "i"? */ 77 unsigned int ioff; /* which IBlock corresponds to "off" at depth "i"? */
79 78
80 if (depth == 0) 79 if (depth == 0)
81 return off; 80 return off;
82 /* first IBlocks start at the end of file, rounded up 81 /* first IBlocks start at the end of file, rounded up
83 to full DBLOCK_SIZE */ 82 * to full DBLOCK_SIZE */
84 loff = ((fsize + DBLOCK_SIZE - 1) / DBLOCK_SIZE) * DBLOCK_SIZE; 83 loff = ((fsize + DBLOCK_SIZE - 1) / DBLOCK_SIZE) * DBLOCK_SIZE;
85 lsize = ( (fsize + DBLOCK_SIZE - 1) / DBLOCK_SIZE) * sizeof (struct ContentHashKey); 84 lsize =
85 ((fsize + DBLOCK_SIZE -
86 1) / DBLOCK_SIZE) * sizeof (struct ContentHashKey);
86 GNUNET_assert (0 == (off % DBLOCK_SIZE)); 87 GNUNET_assert (0 == (off % DBLOCK_SIZE));
87 ioff = (off / DBLOCK_SIZE); 88 ioff = (off / DBLOCK_SIZE);
88 for (i=1;i<depth;i++) 89 for (i = 1; i < depth; i++)
89 { 90 {
90 loff += lsize; 91 loff += lsize;
91 lsize = (lsize + CHK_PER_INODE - 1) / CHK_PER_INODE; 92 lsize = (lsize + CHK_PER_INODE - 1) / CHK_PER_INODE;
92 GNUNET_assert (lsize > 0); 93 GNUNET_assert (lsize > 0);
93 GNUNET_assert (0 == (ioff % CHK_PER_INODE)); 94 GNUNET_assert (0 == (ioff % CHK_PER_INODE));
94 ioff /= CHK_PER_INODE; 95 ioff /= CHK_PER_INODE;
95 } 96 }
96 return loff + ioff * sizeof (struct ContentHashKey); 97 return loff + ioff * sizeof (struct ContentHashKey);
97} 98}
98 99
@@ -106,38 +107,28 @@ compute_disk_offset (uint64_t fsize,
106 */ 107 */
107void 108void
108GNUNET_FS_download_make_status_ (struct GNUNET_FS_ProgressInfo *pi, 109GNUNET_FS_download_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
109 struct GNUNET_FS_DownloadContext *dc) 110 struct GNUNET_FS_DownloadContext *dc)
110{ 111{
111 pi->value.download.dc = dc; 112 pi->value.download.dc = dc;
112 pi->value.download.cctx 113 pi->value.download.cctx = dc->client_info;
113 = dc->client_info;
114 pi->value.download.pctx 114 pi->value.download.pctx
115 = (dc->parent == NULL) ? NULL : dc->parent->client_info; 115 = (dc->parent == NULL) ? NULL : dc->parent->client_info;
116 pi->value.download.sctx 116 pi->value.download.sctx
117 = (dc->search == NULL) ? NULL : dc->search->client_info; 117 = (dc->search == NULL) ? NULL : dc->search->client_info;
118 pi->value.download.uri 118 pi->value.download.uri = dc->uri;
119 = dc->uri; 119 pi->value.download.filename = dc->filename;
120 pi->value.download.filename 120 pi->value.download.size = dc->length;
121 = dc->filename;
122 pi->value.download.size
123 = dc->length;
124 pi->value.download.duration 121 pi->value.download.duration
125 = GNUNET_TIME_absolute_get_duration (dc->start_time); 122 = GNUNET_TIME_absolute_get_duration (dc->start_time);
126 pi->value.download.completed 123 pi->value.download.completed = dc->completed;
127 = dc->completed; 124 pi->value.download.anonymity = dc->anonymity;
128 pi->value.download.anonymity
129 = dc->anonymity;
130 pi->value.download.eta 125 pi->value.download.eta
131 = GNUNET_TIME_calculate_eta (dc->start_time, 126 = GNUNET_TIME_calculate_eta (dc->start_time, dc->completed, dc->length);
132 dc->completed,
133 dc->length);
134 pi->value.download.is_active = (dc->client == NULL) ? GNUNET_NO : GNUNET_YES; 127 pi->value.download.is_active = (dc->client == NULL) ? GNUNET_NO : GNUNET_YES;
135 if (0 == (dc->options & GNUNET_FS_DOWNLOAD_IS_PROBE)) 128 if (0 == (dc->options & GNUNET_FS_DOWNLOAD_IS_PROBE))
136 dc->client_info = dc->h->upcb (dc->h->upcb_cls, 129 dc->client_info = dc->h->upcb (dc->h->upcb_cls, pi);
137 pi);
138 else 130 else
139 dc->client_info = GNUNET_FS_search_probe_progress_ (NULL, 131 dc->client_info = GNUNET_FS_search_probe_progress_ (NULL, pi);
140 pi);
141} 132}
142 133
143 134
@@ -152,10 +143,7 @@ GNUNET_FS_download_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
152 * @param buf where the callee should write the message 143 * @param buf where the callee should write the message
153 * @return number of bytes written to buf 144 * @return number of bytes written to buf
154 */ 145 */
155static size_t 146static size_t transmit_download_request (void *cls, size_t size, void *buf);
156transmit_download_request (void *cls,
157 size_t size,
158 void *buf);
159 147
160 148
161/** 149/**
@@ -163,7 +151,7 @@ transmit_download_request (void *cls,
163 */ 151 */
164struct ProcessResultClosure 152struct ProcessResultClosure
165{ 153{
166 154
167 /** 155 /**
168 * Hash of data. 156 * Hash of data.
169 */ 157 */
@@ -171,14 +159,14 @@ struct ProcessResultClosure
171 159
172 /** 160 /**
173 * Data found in P2P network. 161 * Data found in P2P network.
174 */ 162 */
175 const void *data; 163 const void *data;
176 164
177 /** 165 /**
178 * Our download context. 166 * Our download context.
179 */ 167 */
180 struct GNUNET_FS_DownloadContext *dc; 168 struct GNUNET_FS_DownloadContext *dc;
181 169
182 /** 170 /**
183 * Number of bytes in data. 171 * Number of bytes in data.
184 */ 172 */
@@ -193,7 +181,7 @@ struct ProcessResultClosure
193 * Flag to indicate if this block should be stored on disk. 181 * Flag to indicate if this block should be stored on disk.
194 */ 182 */
195 int do_store; 183 int do_store;
196 184
197}; 185};
198 186
199 187
@@ -208,8 +196,7 @@ struct ProcessResultClosure
208 */ 196 */
209static int 197static int
210process_result_with_request (void *cls, 198process_result_with_request (void *cls,
211 const GNUNET_HashCode * key, 199 const GNUNET_HashCode * key, void *value);
212 void *value);
213 200
214 201
215/** 202/**
@@ -227,53 +214,42 @@ process_result_with_request (void *cls,
227 */ 214 */
228static int 215static int
229encrypt_existing_match (struct GNUNET_FS_DownloadContext *dc, 216encrypt_existing_match (struct GNUNET_FS_DownloadContext *dc,
230 const struct ContentHashKey *chk, 217 const struct ContentHashKey *chk,
231 struct DownloadRequest *dr, 218 struct DownloadRequest *dr,
232 const char * block, 219 const char *block, size_t len, int do_store)
233 size_t len,
234 int do_store)
235{ 220{
236 struct ProcessResultClosure prc; 221 struct ProcessResultClosure prc;
237 char enc[len]; 222 char enc[len];
238 struct GNUNET_CRYPTO_AesSessionKey sk; 223 struct GNUNET_CRYPTO_AesSessionKey sk;
239 struct GNUNET_CRYPTO_AesInitializationVector iv; 224 struct GNUNET_CRYPTO_AesInitializationVector iv;
240 GNUNET_HashCode query; 225 GNUNET_HashCode query;
241 226
242 GNUNET_CRYPTO_hash_to_aes_key (&chk->key, &sk, &iv); 227 GNUNET_CRYPTO_hash_to_aes_key (&chk->key, &sk, &iv);
243 if (-1 == GNUNET_CRYPTO_aes_encrypt (block, len, 228 if (-1 == GNUNET_CRYPTO_aes_encrypt (block, len, &sk, &iv, enc))
244 &sk, 229 {
245 &iv, 230 GNUNET_break (0);
246 enc)) 231 return GNUNET_SYSERR;
247 { 232 }
248 GNUNET_break (0);
249 return GNUNET_SYSERR;
250 }
251 GNUNET_CRYPTO_hash (enc, len, &query); 233 GNUNET_CRYPTO_hash (enc, len, &query);
252 if (0 != memcmp (&query, 234 if (0 != memcmp (&query, &chk->query, sizeof (GNUNET_HashCode)))
253 &chk->query, 235 {
254 sizeof (GNUNET_HashCode))) 236 GNUNET_break_op (0);
255 { 237 return GNUNET_SYSERR;
256 GNUNET_break_op (0); 238 }
257 return GNUNET_SYSERR;
258 }
259#if DEBUG_DOWNLOAD 239#if DEBUG_DOWNLOAD
260 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 240 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
261 "Matching block for `%s' at offset %llu already present, no need for download!\n", 241 "Matching block for `%s' at offset %llu already present, no need for download!\n",
262 dc->filename, 242 dc->filename, (unsigned long long) dr->offset);
263 (unsigned long long) dr->offset);
264#endif 243#endif
265 /* already got it! */ 244 /* already got it! */
266 prc.dc = dc; 245 prc.dc = dc;
267 prc.data = enc; 246 prc.data = enc;
268 prc.size = len; 247 prc.size = len;
269 prc.type = (0 == dr->depth) 248 prc.type = (0 == dr->depth)
270 ? GNUNET_BLOCK_TYPE_FS_DBLOCK 249 ? GNUNET_BLOCK_TYPE_FS_DBLOCK : GNUNET_BLOCK_TYPE_FS_IBLOCK;
271 : GNUNET_BLOCK_TYPE_FS_IBLOCK;
272 prc.query = chk->query; 250 prc.query = chk->query;
273 prc.do_store = do_store; 251 prc.do_store = do_store;
274 process_result_with_request (&prc, 252 process_result_with_request (&prc, &chk->key, dr);
275 &chk->key,
276 dr);
277 return GNUNET_OK; 253 return GNUNET_OK;
278} 254}
279 255
@@ -285,8 +261,7 @@ encrypt_existing_match (struct GNUNET_FS_DownloadContext *dc,
285 * 261 *
286 * @param dc download context that is having trouble 262 * @param dc download context that is having trouble
287 */ 263 */
288static void 264static void try_reconnect (struct GNUNET_FS_DownloadContext *dc);
289try_reconnect (struct GNUNET_FS_DownloadContext *dc);
290 265
291 266
292/** 267/**
@@ -300,13 +275,12 @@ try_reconnect (struct GNUNET_FS_DownloadContext *dc);
300 * @param length number of bytes in data 275 * @param length number of bytes in data
301 * @param data contents of the file (or NULL if they were not inlined) 276 * @param data contents of the file (or NULL if they were not inlined)
302 */ 277 */
303static void 278static void
304trigger_recursive_download (void *cls, 279trigger_recursive_download (void *cls,
305 const char *filename, 280 const char *filename,
306 const struct GNUNET_FS_Uri *uri, 281 const struct GNUNET_FS_Uri *uri,
307 const struct GNUNET_CONTAINER_MetaData *meta, 282 const struct GNUNET_CONTAINER_MetaData *meta,
308 size_t length, 283 size_t length, const void *data);
309 const void *data);
310 284
311 285
312/** 286/**
@@ -323,55 +297,51 @@ full_recursive_download (struct GNUNET_FS_DownloadContext *dc)
323 void *data; 297 void *data;
324 struct GNUNET_DISK_FileHandle *h; 298 struct GNUNET_DISK_FileHandle *h;
325 struct GNUNET_DISK_MapHandle *m; 299 struct GNUNET_DISK_MapHandle *m;
326 300
327 size64 = GNUNET_FS_uri_chk_get_file_size (dc->uri); 301 size64 = GNUNET_FS_uri_chk_get_file_size (dc->uri);
328 size = (size_t) size64; 302 size = (size_t) size64;
329 if (size64 != (uint64_t) size) 303 if (size64 != (uint64_t) size)
330 { 304 {
331 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 305 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
332 _("Recursive downloads of directories larger than 4 GB are not supported on 32-bit systems\n")); 306 _
333 return; 307 ("Recursive downloads of directories larger than 4 GB are not supported on 32-bit systems\n"));
334 } 308 return;
309 }
335 if (dc->filename != NULL) 310 if (dc->filename != NULL)
336 { 311 {
337 h = GNUNET_DISK_file_open (dc->filename, 312 h = GNUNET_DISK_file_open (dc->filename,
338 GNUNET_DISK_OPEN_READ, 313 GNUNET_DISK_OPEN_READ, GNUNET_DISK_PERM_NONE);
339 GNUNET_DISK_PERM_NONE); 314 }
340 }
341 else 315 else
342 { 316 {
343 GNUNET_assert (dc->temp_filename != NULL); 317 GNUNET_assert (dc->temp_filename != NULL);
344 h = GNUNET_DISK_file_open (dc->temp_filename, 318 h = GNUNET_DISK_file_open (dc->temp_filename,
345 GNUNET_DISK_OPEN_READ, 319 GNUNET_DISK_OPEN_READ, GNUNET_DISK_PERM_NONE);
346 GNUNET_DISK_PERM_NONE); 320 }
347 }
348 if (h == NULL) 321 if (h == NULL)
349 return; /* oops */ 322 return; /* oops */
350 data = GNUNET_DISK_file_map (h, &m, GNUNET_DISK_MAP_TYPE_READ, size); 323 data = GNUNET_DISK_file_map (h, &m, GNUNET_DISK_MAP_TYPE_READ, size);
351 if (data == NULL) 324 if (data == NULL)
352 { 325 {
353 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 326 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
354 _("Directory too large for system address space\n")); 327 _("Directory too large for system address space\n"));
355 } 328 }
356 else 329 else
357 { 330 {
358 GNUNET_FS_directory_list_contents (size, 331 GNUNET_FS_directory_list_contents (size,
359 data, 332 data,
360 0, 333 0, &trigger_recursive_download, dc);
361 &trigger_recursive_download, 334 GNUNET_DISK_file_unmap (m);
362 dc); 335 }
363 GNUNET_DISK_file_unmap (m);
364 }
365 GNUNET_DISK_file_close (h); 336 GNUNET_DISK_file_close (h);
366 if (dc->filename == NULL) 337 if (dc->filename == NULL)
367 { 338 {
368 if (0 != UNLINK (dc->temp_filename)) 339 if (0 != UNLINK (dc->temp_filename))
369 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, 340 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
370 "unlink", 341 "unlink", dc->temp_filename);
371 dc->temp_filename); 342 GNUNET_free (dc->temp_filename);
372 GNUNET_free (dc->temp_filename); 343 dc->temp_filename = NULL;
373 dc->temp_filename = NULL; 344 }
374 }
375} 345}
376 346
377 347
@@ -392,28 +362,25 @@ check_completed (struct GNUNET_FS_DownloadContext *dc)
392 struct GNUNET_FS_DownloadContext *pos; 362 struct GNUNET_FS_DownloadContext *pos;
393 363
394 /* first, check if we need to download children */ 364 /* first, check if we need to download children */
395 if ( (dc->child_head == NULL) && 365 if ((dc->child_head == NULL) && (is_recursive_download (dc)))
396 (is_recursive_download (dc)) ) 366 full_recursive_download (dc);
397 full_recursive_download (dc);
398 /* then, check if children are done already */ 367 /* then, check if children are done already */
399 pos = dc->child_head; 368 pos = dc->child_head;
400 while (pos != NULL) 369 while (pos != NULL)
401 { 370 {
402 if ( (pos->emsg == NULL) && 371 if ((pos->emsg == NULL) && (pos->completed < pos->length))
403 (pos->completed < pos->length) ) 372 return; /* not done yet */
404 return; /* not done yet */ 373 if ((pos->child_head != NULL) && (pos->has_finished != GNUNET_YES))
405 if ( (pos->child_head != NULL) && 374 return; /* not transitively done yet */
406 (pos->has_finished != GNUNET_YES) ) 375 pos = pos->next;
407 return; /* not transitively done yet */ 376 }
408 pos = pos->next;
409 }
410 /* All of our children are done, so mark this download done */ 377 /* All of our children are done, so mark this download done */
411 dc->has_finished = GNUNET_YES; 378 dc->has_finished = GNUNET_YES;
412 if (dc->job_queue != NULL) 379 if (dc->job_queue != NULL)
413 { 380 {
414 GNUNET_FS_dequeue_ (dc->job_queue); 381 GNUNET_FS_dequeue_ (dc->job_queue);
415 dc->job_queue = NULL; 382 dc->job_queue = NULL;
416 } 383 }
417 GNUNET_FS_download_sync_ (dc); 384 GNUNET_FS_download_sync_ (dc);
418 385
419 /* signal completion */ 386 /* signal completion */
@@ -422,7 +389,7 @@ check_completed (struct GNUNET_FS_DownloadContext *dc)
422 389
423 /* let parent know */ 390 /* let parent know */
424 if (dc->parent != NULL) 391 if (dc->parent != NULL)
425 check_completed (dc->parent); 392 check_completed (dc->parent);
426} 393}
427 394
428 395
@@ -435,12 +402,10 @@ check_completed (struct GNUNET_FS_DownloadContext *dc)
435 * @param dr download request to match against 402 * @param dr download request to match against
436 * @param data plaintext data, starting from the beginning of the file 403 * @param data plaintext data, starting from the beginning of the file
437 * @param data_len number of bytes in data 404 * @param data_len number of bytes in data
438 */ 405 */
439static void 406static void
440try_match_block (struct GNUNET_FS_DownloadContext *dc, 407try_match_block (struct GNUNET_FS_DownloadContext *dc,
441 struct DownloadRequest *dr, 408 struct DownloadRequest *dr, const char *data, size_t data_len)
442 const char *data,
443 size_t data_len)
444{ 409{
445 struct GNUNET_FS_ProgressInfo pi; 410 struct GNUNET_FS_ProgressInfo pi;
446 unsigned int i; 411 unsigned int i;
@@ -456,134 +421,112 @@ try_match_block (struct GNUNET_FS_DownloadContext *dc,
456 const char *fn; 421 const char *fn;
457 const char *odata; 422 const char *odata;
458 size_t odata_len; 423 size_t odata_len;
459 424
460 odata = data; 425 odata = data;
461 odata_len = data_len; 426 odata_len = data_len;
462 if (BRS_DOWNLOAD_UP == dr->state) 427 if (BRS_DOWNLOAD_UP == dr->state)
463 return; 428 return;
464 if (dr->depth > 0) 429 if (dr->depth > 0)
430 {
431 complete = GNUNET_YES;
432 for (i = 0; i < dr->num_children; i++)
465 { 433 {
466 complete = GNUNET_YES; 434 drc = dr->children[i];
467 for (i=0;i<dr->num_children;i++) 435 try_match_block (dc, drc, data, data_len);
468 { 436 if (drc->state != BRS_RECONSTRUCT_META_UP)
469 drc = dr->children[i]; 437 complete = GNUNET_NO;
470 try_match_block (dc, 438 else
471 drc, 439 chks[i] = drc->chk;
472 data, data_len);
473 if (drc->state != BRS_RECONSTRUCT_META_UP)
474 complete = GNUNET_NO;
475 else
476 chks[i] = drc->chk;
477 }
478 if (GNUNET_YES != complete)
479 return;
480 data = (const char*) chks;
481 dlen = dr->num_children * sizeof (struct ContentHashKey);
482 } 440 }
441 if (GNUNET_YES != complete)
442 return;
443 data = (const char *) chks;
444 dlen = dr->num_children * sizeof (struct ContentHashKey);
445 }
483 else 446 else
484 { 447 {
485 if (dr->offset > data_len) 448 if (dr->offset > data_len)
486 return; /* oops */ 449 return; /* oops */
487 dlen = GNUNET_MIN (data_len - dr->offset, 450 dlen = GNUNET_MIN (data_len - dr->offset, DBLOCK_SIZE);
488 DBLOCK_SIZE); 451 }
489 } 452 GNUNET_CRYPTO_hash (&data[dr->offset], dlen, &in_chk.key);
490 GNUNET_CRYPTO_hash (&data[dr->offset],
491 dlen,
492 &in_chk.key);
493 GNUNET_CRYPTO_hash_to_aes_key (&in_chk.key, &sk, &iv); 453 GNUNET_CRYPTO_hash_to_aes_key (&in_chk.key, &sk, &iv);
494 if (-1 == GNUNET_CRYPTO_aes_encrypt (&data[dr->offset], dlen, 454 if (-1 == GNUNET_CRYPTO_aes_encrypt (&data[dr->offset], dlen, &sk, &iv, enc))
495 &sk, 455 {
496 &iv, 456 GNUNET_break (0);
497 enc)) 457 return;
498 { 458 }
499 GNUNET_break (0);
500 return;
501 }
502 GNUNET_CRYPTO_hash (enc, dlen, &in_chk.query); 459 GNUNET_CRYPTO_hash (enc, dlen, &in_chk.query);
503 switch (dr->state) 460 switch (dr->state)
504 { 461 {
505 case BRS_INIT: 462 case BRS_INIT:
506 dr->chk = in_chk; 463 dr->chk = in_chk;
507 dr->state = BRS_RECONSTRUCT_META_UP; 464 dr->state = BRS_RECONSTRUCT_META_UP;
465 break;
466 case BRS_CHK_SET:
467 if (0 != memcmp (&in_chk, &dr->chk, sizeof (struct ContentHashKey)))
468 {
469 /* other peer provided bogus meta data */
470 GNUNET_break_op (0);
508 break; 471 break;
509 case BRS_CHK_SET: 472 }
510 if (0 != memcmp (&in_chk, 473 /* write block to disk */
511 &dr->chk, 474 fn = dc->filename != NULL ? dc->filename : dc->temp_filename;
512 sizeof (struct ContentHashKey))) 475 fh = GNUNET_DISK_file_open (fn,
513 { 476 GNUNET_DISK_OPEN_READWRITE |
514 /* other peer provided bogus meta data */ 477 GNUNET_DISK_OPEN_CREATE |
515 GNUNET_break_op (0); 478 GNUNET_DISK_OPEN_TRUNCATE,
516 break; 479 GNUNET_DISK_PERM_USER_READ |
517 } 480 GNUNET_DISK_PERM_USER_WRITE |
518 /* write block to disk */ 481 GNUNET_DISK_PERM_GROUP_READ |
519 fn = dc->filename != NULL 482 GNUNET_DISK_PERM_OTHER_READ);
520 ? dc->filename 483 if (fh == NULL)
521 : dc->temp_filename; 484 {
522 fh = GNUNET_DISK_file_open (fn, 485 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", fn);
523 GNUNET_DISK_OPEN_READWRITE | 486 GNUNET_asprintf (&dc->emsg,
524 GNUNET_DISK_OPEN_CREATE | 487 _("Failed to open file `%s' for writing"), fn);
525 GNUNET_DISK_OPEN_TRUNCATE,
526 GNUNET_DISK_PERM_USER_READ |
527 GNUNET_DISK_PERM_USER_WRITE |
528 GNUNET_DISK_PERM_GROUP_READ |
529 GNUNET_DISK_PERM_OTHER_READ);
530 if (fh == NULL)
531 {
532 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
533 "open",
534 fn);
535 GNUNET_asprintf (&dc->emsg,
536 _("Failed to open file `%s' for writing"),
537 fn);
538 GNUNET_DISK_file_close (fh);
539 dr->state = BRS_ERROR;
540 pi.status = GNUNET_FS_STATUS_DOWNLOAD_ERROR;
541 pi.value.download.specifics.error.message = dc->emsg;
542 GNUNET_FS_download_make_status_ (&pi, dc);
543 return;
544 }
545 if (data_len !=
546 GNUNET_DISK_file_write (fh,
547 odata,
548 odata_len))
549 {
550 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
551 "write",
552 fn);
553 GNUNET_asprintf (&dc->emsg,
554 _("Failed to open file `%s' for writing"),
555 fn);
556 GNUNET_DISK_file_close (fh);
557 dr->state = BRS_ERROR;
558 pi.status = GNUNET_FS_STATUS_DOWNLOAD_ERROR;
559 pi.value.download.specifics.error.message = dc->emsg;
560 GNUNET_FS_download_make_status_ (&pi, dc);
561 return;
562 }
563 GNUNET_DISK_file_close (fh); 488 GNUNET_DISK_file_close (fh);
564 /* signal success */ 489 dr->state = BRS_ERROR;
565 dr->state = BRS_DOWNLOAD_UP; 490 pi.status = GNUNET_FS_STATUS_DOWNLOAD_ERROR;
566 dc->completed = dc->length; 491 pi.value.download.specifics.error.message = dc->emsg;
567 GNUNET_FS_download_sync_ (dc);
568 pi.status = GNUNET_FS_STATUS_DOWNLOAD_PROGRESS;
569 pi.value.download.specifics.progress.data = data;
570 pi.value.download.specifics.progress.offset = 0;
571 pi.value.download.specifics.progress.data_len = dlen;
572 pi.value.download.specifics.progress.depth = 0;
573 GNUNET_FS_download_make_status_ (&pi, dc); 492 GNUNET_FS_download_make_status_ (&pi, dc);
574 if ( (NULL != dc->filename) && 493 return;
575 (0 != truncate (dc->filename, 494 }
576 GNUNET_ntohll (dc->uri->data.chk.file_length))) ) 495 if (data_len != GNUNET_DISK_file_write (fh, odata, odata_len))
577 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, 496 {
578 "truncate", 497 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "write", fn);
579 dc->filename); 498 GNUNET_asprintf (&dc->emsg,
580 check_completed (dc); 499 _("Failed to open file `%s' for writing"), fn);
581 break; 500 GNUNET_DISK_file_close (fh);
582 default: 501 dr->state = BRS_ERROR;
583 /* how did we get here? */ 502 pi.status = GNUNET_FS_STATUS_DOWNLOAD_ERROR;
584 GNUNET_break (0); 503 pi.value.download.specifics.error.message = dc->emsg;
585 break; 504 GNUNET_FS_download_make_status_ (&pi, dc);
505 return;
586 } 506 }
507 GNUNET_DISK_file_close (fh);
508 /* signal success */
509 dr->state = BRS_DOWNLOAD_UP;
510 dc->completed = dc->length;
511 GNUNET_FS_download_sync_ (dc);
512 pi.status = GNUNET_FS_STATUS_DOWNLOAD_PROGRESS;
513 pi.value.download.specifics.progress.data = data;
514 pi.value.download.specifics.progress.offset = 0;
515 pi.value.download.specifics.progress.data_len = dlen;
516 pi.value.download.specifics.progress.depth = 0;
517 GNUNET_FS_download_make_status_ (&pi, dc);
518 if ((NULL != dc->filename) &&
519 (0 != truncate (dc->filename,
520 GNUNET_ntohll (dc->uri->data.chk.file_length))))
521 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
522 "truncate", dc->filename);
523 check_completed (dc);
524 break;
525 default:
526 /* how did we get here? */
527 GNUNET_break (0);
528 break;
529 }
587} 530}
588 531
589 532
@@ -604,34 +547,28 @@ try_match_block (struct GNUNET_FS_DownloadContext *dc,
604 * @param data actual meta-data found 547 * @param data actual meta-data found
605 * @param data_len number of bytes in data 548 * @param data_len number of bytes in data
606 * @return 0 to continue extracting, 1 to abort 549 * @return 0 to continue extracting, 1 to abort
607 */ 550 */
608static int 551static int
609match_full_data (void *cls, 552match_full_data (void *cls,
610 const char *plugin_name, 553 const char *plugin_name,
611 enum EXTRACTOR_MetaType type, 554 enum EXTRACTOR_MetaType type,
612 enum EXTRACTOR_MetaFormat format, 555 enum EXTRACTOR_MetaFormat format,
613 const char *data_mime_type, 556 const char *data_mime_type, const char *data, size_t data_len)
614 const char *data,
615 size_t data_len)
616{ 557{
617 struct GNUNET_FS_DownloadContext *dc = cls; 558 struct GNUNET_FS_DownloadContext *dc = cls;
618 559
619 if (type != EXTRACTOR_METATYPE_GNUNET_FULL_DATA) 560 if (type != EXTRACTOR_METATYPE_GNUNET_FULL_DATA)
620 return 0; 561 return 0;
621#if DEBUG_DOWNLOAD 562#if DEBUG_DOWNLOAD
622 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 563 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
623 "Found %u bytes of FD!\n", 564 "Found %u bytes of FD!\n", (unsigned int) data_len);
624 (unsigned int) data_len);
625#endif 565#endif
626 if (GNUNET_FS_uri_chk_get_file_size (dc->uri) != data_len) 566 if (GNUNET_FS_uri_chk_get_file_size (dc->uri) != data_len)
627 { 567 {
628 GNUNET_break_op (0); 568 GNUNET_break_op (0);
629 return 1; /* bogus meta data */ 569 return 1; /* bogus meta data */
630 } 570 }
631 try_match_block (dc, 571 try_match_block (dc, dc->top_request, data, data_len);
632 dc->top_request,
633 data,
634 data_len);
635 return 1; 572 return 1;
636} 573}
637 574
@@ -648,15 +585,15 @@ propagate_up (struct DownloadRequest *dr)
648 unsigned int i; 585 unsigned int i;
649 586
650 do 587 do
651 { 588 {
652 dr->state = BRS_DOWNLOAD_UP; 589 dr->state = BRS_DOWNLOAD_UP;
653 dr = dr->parent; 590 dr = dr->parent;
654 if (dr == NULL) 591 if (dr == NULL)
655 break; 592 break;
656 for (i=0;i<dr->num_children;i++) 593 for (i = 0; i < dr->num_children; i++)
657 if (dr->children[i]->state != BRS_DOWNLOAD_UP) 594 if (dr->children[i]->state != BRS_DOWNLOAD_UP)
658 break; 595 break;
659 } 596 }
660 while (i == dr->num_children); 597 while (i == dr->num_children);
661} 598}
662 599
@@ -673,7 +610,7 @@ propagate_up (struct DownloadRequest *dr)
673 */ 610 */
674static void 611static void
675try_top_down_reconstruction (struct GNUNET_FS_DownloadContext *dc, 612try_top_down_reconstruction (struct GNUNET_FS_DownloadContext *dc,
676 struct DownloadRequest *dr) 613 struct DownloadRequest *dr)
677{ 614{
678 uint64_t off; 615 uint64_t off;
679 char block[DBLOCK_SIZE]; 616 char block[DBLOCK_SIZE];
@@ -686,87 +623,66 @@ try_top_down_reconstruction (struct GNUNET_FS_DownloadContext *dc,
686 uint64_t child_block_size; 623 uint64_t child_block_size;
687 const struct ContentHashKey *chks; 624 const struct ContentHashKey *chks;
688 int up_done; 625 int up_done;
689 626
690 GNUNET_assert (dc->rfh != NULL); 627 GNUNET_assert (dc->rfh != NULL);
691 GNUNET_assert (dr->state == BRS_CHK_SET); 628 GNUNET_assert (dr->state == BRS_CHK_SET);
692 total = GNUNET_FS_uri_chk_get_file_size (dc->uri); 629 total = GNUNET_FS_uri_chk_get_file_size (dc->uri);
693 GNUNET_assert (dr->depth < dc->treedepth); 630 GNUNET_assert (dr->depth < dc->treedepth);
694 len = GNUNET_FS_tree_calculate_block_size (total, 631 len = GNUNET_FS_tree_calculate_block_size (total, dr->offset, dr->depth);
695 dr->offset,
696 dr->depth);
697 GNUNET_assert (len <= DBLOCK_SIZE); 632 GNUNET_assert (len <= DBLOCK_SIZE);
698 off = compute_disk_offset (total, 633 off = compute_disk_offset (total, dr->offset, dr->depth);
699 dr->offset, 634 if (dc->old_file_size < off + len)
700 dr->depth); 635 return; /* failure */
701 if (dc->old_file_size < off + len) 636 if (off != GNUNET_DISK_file_seek (dc->rfh, off, GNUNET_DISK_SEEK_SET))
702 return; /* failure */ 637 {
703 if (off != 638 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "seek", dc->filename);
704 GNUNET_DISK_file_seek (dc->rfh, 639 return; /* failure */
705 off, 640 }
706 GNUNET_DISK_SEEK_SET) ) 641 if (len != GNUNET_DISK_file_read (dc->rfh, block, len))
707 { 642 {
708 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, 643 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "read", dc->filename);
709 "seek", 644 return; /* failure */
710 dc->filename); 645 }
711 return; /* failure */
712 }
713 if (len !=
714 GNUNET_DISK_file_read (dc->rfh,
715 block,
716 len))
717 {
718 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
719 "read",
720 dc->filename);
721 return; /* failure */
722 }
723 GNUNET_CRYPTO_hash (block, len, &key); 646 GNUNET_CRYPTO_hash (block, len, &key);
724 if (0 != memcmp (&key, 647 if (0 != memcmp (&key, &dr->chk.key, sizeof (GNUNET_HashCode)))
725 &dr->chk.key, 648 return; /* mismatch */
726 sizeof (GNUNET_HashCode)))
727 return; /* mismatch */
728 if (GNUNET_OK != 649 if (GNUNET_OK !=
729 encrypt_existing_match (dc, 650 encrypt_existing_match (dc, &dr->chk, dr, block, len, GNUNET_NO))
730 &dr->chk, 651 {
731 dr, 652 /* hash matches but encrypted block does not, really bad */
732 block, 653 dr->state = BRS_ERROR;
733 len, 654 /* propagate up */
734 GNUNET_NO)) 655 while (dr->parent != NULL)
735 { 656 {
736 /* hash matches but encrypted block does not, really bad */ 657 dr = dr->parent;
737 dr->state = BRS_ERROR; 658 dr->state = BRS_ERROR;
738 /* propagate up */
739 while (dr->parent != NULL)
740 {
741 dr = dr->parent;
742 dr->state = BRS_ERROR;
743 }
744 return;
745 } 659 }
660 return;
661 }
746 /* block matches */ 662 /* block matches */
747 dr->state = BRS_DOWNLOAD_DOWN; 663 dr->state = BRS_DOWNLOAD_DOWN;
748 664
749 /* set CHKs for children */ 665 /* set CHKs for children */
750 up_done = GNUNET_YES; 666 up_done = GNUNET_YES;
751 chks = (const struct ContentHashKey*) block; 667 chks = (const struct ContentHashKey *) block;
752 for (i=0;i<dr->num_children;i++) 668 for (i = 0; i < dr->num_children; i++)
753 { 669 {
754 drc = dr->children[i]; 670 drc = dr->children[i];
755 GNUNET_assert (drc->offset >= dr->offset); 671 GNUNET_assert (drc->offset >= dr->offset);
756 child_block_size = GNUNET_FS_tree_compute_tree_size (drc->depth); 672 child_block_size = GNUNET_FS_tree_compute_tree_size (drc->depth);
757 GNUNET_assert (0 == (drc->offset - dr->offset) % child_block_size); 673 GNUNET_assert (0 == (drc->offset - dr->offset) % child_block_size);
758 chk_off = (drc->offset - dr->offset) / child_block_size; 674 chk_off = (drc->offset - dr->offset) / child_block_size;
759 if (drc->state == BRS_INIT) 675 if (drc->state == BRS_INIT)
760 { 676 {
761 drc->state = BRS_CHK_SET; 677 drc->state = BRS_CHK_SET;
762 drc->chk = chks[chk_off]; 678 drc->chk = chks[chk_off];
763 try_top_down_reconstruction (dc, drc); 679 try_top_down_reconstruction (dc, drc);
764 } 680 }
765 if (drc->state != BRS_DOWNLOAD_UP) 681 if (drc->state != BRS_DOWNLOAD_UP)
766 up_done = GNUNET_NO; /* children not all done */ 682 up_done = GNUNET_NO; /* children not all done */
767 } 683 }
768 if (up_done == GNUNET_YES) 684 if (up_done == GNUNET_YES)
769 propagate_up (dr); /* children all done (or no children...) */ 685 propagate_up (dr); /* children all done (or no children...) */
770} 686}
771 687
772 688
@@ -778,67 +694,63 @@ try_top_down_reconstruction (struct GNUNET_FS_DownloadContext *dc,
778 */ 694 */
779static void 695static void
780schedule_block_download (struct GNUNET_FS_DownloadContext *dc, 696schedule_block_download (struct GNUNET_FS_DownloadContext *dc,
781 struct DownloadRequest *dr) 697 struct DownloadRequest *dr)
782{ 698{
783 unsigned int i; 699 unsigned int i;
784 700
785 switch (dr->state) 701 switch (dr->state)
786 { 702 {
787 case BRS_INIT: 703 case BRS_INIT:
788 GNUNET_assert (0); 704 GNUNET_assert (0);
789 break; 705 break;
790 case BRS_RECONSTRUCT_DOWN: 706 case BRS_RECONSTRUCT_DOWN:
791 GNUNET_assert (0); 707 GNUNET_assert (0);
792 break; 708 break;
793 case BRS_RECONSTRUCT_META_UP: 709 case BRS_RECONSTRUCT_META_UP:
794 GNUNET_assert (0); 710 GNUNET_assert (0);
795 break; 711 break;
796 case BRS_RECONSTRUCT_UP: 712 case BRS_RECONSTRUCT_UP:
797 GNUNET_assert (0); 713 GNUNET_assert (0);
798 break; 714 break;
799 case BRS_CHK_SET: 715 case BRS_CHK_SET:
800 /* normal case, start download */ 716 /* normal case, start download */
801 break; 717 break;
802 case BRS_DOWNLOAD_DOWN: 718 case BRS_DOWNLOAD_DOWN:
803 for (i=0;i<dr->num_children;i++) 719 for (i = 0; i < dr->num_children; i++)
804 schedule_block_download (dc, dr->children[i]); 720 schedule_block_download (dc, dr->children[i]);
805 return; 721 return;
806 case BRS_DOWNLOAD_UP: 722 case BRS_DOWNLOAD_UP:
807 /* We're done! */ 723 /* We're done! */
808 return; 724 return;
809 case BRS_ERROR: 725 case BRS_ERROR:
810 GNUNET_break (0); 726 GNUNET_break (0);
811 return; 727 return;
812 } 728 }
813#if DEBUG_DOWNLOAD 729#if DEBUG_DOWNLOAD
814 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 730 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
815 "Scheduling download at offset %llu and depth %u for `%s'\n", 731 "Scheduling download at offset %llu and depth %u for `%s'\n",
816 (unsigned long long) dr->offset, 732 (unsigned long long) dr->offset,
817 dr->depth, 733 dr->depth, GNUNET_h2s (&dr->chk.query));
818 GNUNET_h2s (&dr->chk.query));
819#endif 734#endif
820 if (GNUNET_NO != 735 if (GNUNET_NO !=
821 GNUNET_CONTAINER_multihashmap_contains_value (dc->active, 736 GNUNET_CONTAINER_multihashmap_contains_value (dc->active,
822 &dr->chk.query, 737 &dr->chk.query, dr))
823 dr)) 738 return; /* already active */
824 return; /* already active */
825 GNUNET_CONTAINER_multihashmap_put (dc->active, 739 GNUNET_CONTAINER_multihashmap_put (dc->active,
826 &dr->chk.query, 740 &dr->chk.query,
827 dr, 741 dr,
828 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 742 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
829 if (dc->client == NULL) 743 if (dc->client == NULL)
830 return; /* download not active */ 744 return; /* download not active */
831 GNUNET_CONTAINER_DLL_insert (dc->pending_head, 745 GNUNET_CONTAINER_DLL_insert (dc->pending_head, dc->pending_tail, dr);
832 dc->pending_tail,
833 dr);
834 dr->is_pending = GNUNET_YES; 746 dr->is_pending = GNUNET_YES;
835 if (NULL == dc->th) 747 if (NULL == dc->th)
836 dc->th = GNUNET_CLIENT_notify_transmit_ready (dc->client, 748 dc->th = GNUNET_CLIENT_notify_transmit_ready (dc->client,
837 sizeof (struct SearchMessage), 749 sizeof (struct SearchMessage),
838 GNUNET_CONSTANTS_SERVICE_TIMEOUT, 750 GNUNET_CONSTANTS_SERVICE_TIMEOUT,
839 GNUNET_NO, 751 GNUNET_NO,
840 &transmit_download_request, 752 &transmit_download_request,
841 dc); 753 dc);
842} 754}
843 755
844 756
@@ -855,15 +767,14 @@ schedule_block_download (struct GNUNET_FS_DownloadContext *dc,
855 * @param length number of bytes in data 767 * @param length number of bytes in data
856 * @param data contents of the file (or NULL if they were not inlined) 768 * @param data contents of the file (or NULL if they were not inlined)
857 */ 769 */
858static void 770static void
859trigger_recursive_download (void *cls, 771trigger_recursive_download (void *cls,
860 const char *filename, 772 const char *filename,
861 const struct GNUNET_FS_Uri *uri, 773 const struct GNUNET_FS_Uri *uri,
862 const struct GNUNET_CONTAINER_MetaData *meta, 774 const struct GNUNET_CONTAINER_MetaData *meta,
863 size_t length, 775 size_t length, const void *data)
864 const void *data)
865{ 776{
866 struct GNUNET_FS_DownloadContext *dc = cls; 777 struct GNUNET_FS_DownloadContext *dc = cls;
867 struct GNUNET_FS_DownloadContext *cpos; 778 struct GNUNET_FS_DownloadContext *cpos;
868 char *temp_name; 779 char *temp_name;
869 char *fn; 780 char *fn;
@@ -875,129 +786,116 @@ trigger_recursive_download (void *cls,
875 char *sfn; 786 char *sfn;
876 787
877 if (NULL == uri) 788 if (NULL == uri)
878 return; /* entry for the directory itself */ 789 return; /* entry for the directory itself */
879 cpos = dc->child_head; 790 cpos = dc->child_head;
880 while (cpos != NULL) 791 while (cpos != NULL)
881 { 792 {
882 if ( (GNUNET_FS_uri_test_equal (uri, 793 if ((GNUNET_FS_uri_test_equal (uri,
883 cpos->uri)) || 794 cpos->uri)) ||
884 ( (filename != NULL) && 795 ((filename != NULL) && (0 == strcmp (cpos->filename, filename))))
885 (0 == strcmp (cpos->filename, 796 break;
886 filename)) ) ) 797 cpos = cpos->next;
887 break; 798 }
888 cpos = cpos->next;
889 }
890 if (cpos != NULL) 799 if (cpos != NULL)
891 return; /* already exists */ 800 return; /* already exists */
892 fn = NULL; 801 fn = NULL;
893 if (NULL == filename) 802 if (NULL == filename)
894 { 803 {
895 fn = GNUNET_FS_meta_data_suggest_filename (meta); 804 fn = GNUNET_FS_meta_data_suggest_filename (meta);
896 if (fn == NULL) 805 if (fn == NULL)
897 { 806 {
898 us = GNUNET_FS_uri_to_string (uri); 807 us = GNUNET_FS_uri_to_string (uri);
899 fn = GNUNET_strdup (&us [strlen (GNUNET_FS_URI_CHK_PREFIX)]); 808 fn = GNUNET_strdup (&us[strlen (GNUNET_FS_URI_CHK_PREFIX)]);
900 GNUNET_free (us); 809 GNUNET_free (us);
901 } 810 }
902 else if (fn[0] == '.') 811 else if (fn[0] == '.')
903 { 812 {
904 ext = fn; 813 ext = fn;
905 us = GNUNET_FS_uri_to_string (uri); 814 us = GNUNET_FS_uri_to_string (uri);
906 GNUNET_asprintf (&fn, 815 GNUNET_asprintf (&fn,
907 "%s%s", 816 "%s%s", &us[strlen (GNUNET_FS_URI_CHK_PREFIX)], ext);
908 &us[strlen (GNUNET_FS_URI_CHK_PREFIX)], ext); 817 GNUNET_free (ext);
909 GNUNET_free (ext); 818 GNUNET_free (us);
910 GNUNET_free (us); 819 }
911 } 820 /* change '\' to '/' (this should have happened
912 /* change '\' to '/' (this should have happened 821 * during insertion, but malicious peers may
913 during insertion, but malicious peers may 822 * not have done this) */
914 not have done this) */ 823 while (NULL != (pos = strstr (fn, "\\")))
915 while (NULL != (pos = strstr (fn, "\\"))) 824 *pos = '/';
916 *pos = '/'; 825 /* remove '../' everywhere (again, well-behaved
917 /* remove '../' everywhere (again, well-behaved 826 * peers don't do this, but don't trust that
918 peers don't do this, but don't trust that 827 * we did not get something nasty) */
919 we did not get something nasty) */ 828 while (NULL != (pos = strstr (fn, "../")))
920 while (NULL != (pos = strstr (fn, "../"))) 829 {
921 { 830 pos[0] = '_';
922 pos[0] = '_'; 831 pos[1] = '_';
923 pos[1] = '_'; 832 pos[2] = '_';
924 pos[2] = '_'; 833 }
925 } 834 filename = fn;
926 filename = fn; 835 }
927 }
928 if (dc->filename == NULL) 836 if (dc->filename == NULL)
929 { 837 {
930 full_name = NULL; 838 full_name = NULL;
931 } 839 }
932 else 840 else
933 { 841 {
934 dn = GNUNET_strdup (dc->filename); 842 dn = GNUNET_strdup (dc->filename);
935 GNUNET_break ( (strlen (dn) >= strlen (GNUNET_FS_DIRECTORY_EXT)) && 843 GNUNET_break ((strlen (dn) >= strlen (GNUNET_FS_DIRECTORY_EXT)) &&
936 (NULL != 844 (NULL !=
937 strstr (dn + strlen(dn) - strlen(GNUNET_FS_DIRECTORY_EXT), 845 strstr (dn + strlen (dn) - strlen (GNUNET_FS_DIRECTORY_EXT),
938 GNUNET_FS_DIRECTORY_EXT)) ); 846 GNUNET_FS_DIRECTORY_EXT)));
939 sfn = GNUNET_strdup (filename); 847 sfn = GNUNET_strdup (filename);
940 while ( (strlen (sfn) > 0) && 848 while ((strlen (sfn) > 0) && (filename[strlen (sfn) - 1] == '/'))
941 (filename[strlen(sfn)-1] == '/') ) 849 sfn[strlen (sfn) - 1] = '\0';
942 sfn[strlen(sfn)-1] = '\0'; 850 if ((strlen (dn) >= strlen (GNUNET_FS_DIRECTORY_EXT)) &&
943 if ( (strlen (dn) >= strlen (GNUNET_FS_DIRECTORY_EXT)) && 851 (NULL !=
944 (NULL != 852 strstr (dn + strlen (dn) - strlen (GNUNET_FS_DIRECTORY_EXT),
945 strstr (dn + strlen(dn) - strlen(GNUNET_FS_DIRECTORY_EXT), 853 GNUNET_FS_DIRECTORY_EXT)))
946 GNUNET_FS_DIRECTORY_EXT)) ) 854 dn[strlen (dn) - strlen (GNUNET_FS_DIRECTORY_EXT)] = '\0';
947 dn[strlen(dn) - strlen (GNUNET_FS_DIRECTORY_EXT)] = '\0'; 855 if ((GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (meta)) &&
948 if ( (GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (meta)) && 856 ((strlen (filename) < strlen (GNUNET_FS_DIRECTORY_EXT)) ||
949 ( (strlen (filename) < strlen (GNUNET_FS_DIRECTORY_EXT)) || 857 (NULL ==
950 (NULL == 858 strstr (filename + strlen (filename) -
951 strstr (filename + strlen(filename) - strlen(GNUNET_FS_DIRECTORY_EXT), 859 strlen (GNUNET_FS_DIRECTORY_EXT), GNUNET_FS_DIRECTORY_EXT))))
952 GNUNET_FS_DIRECTORY_EXT)) ) ) 860 {
953 { 861 GNUNET_asprintf (&full_name,
954 GNUNET_asprintf (&full_name, 862 "%s%s%s%s",
955 "%s%s%s%s", 863 dn, DIR_SEPARATOR_STR, sfn, GNUNET_FS_DIRECTORY_EXT);
956 dn, 864 }
957 DIR_SEPARATOR_STR, 865 else
958 sfn, 866 {
959 GNUNET_FS_DIRECTORY_EXT); 867 GNUNET_asprintf (&full_name, "%s%s%s", dn, DIR_SEPARATOR_STR, sfn);
960 } 868 }
961 else 869 GNUNET_free (sfn);
962 { 870 GNUNET_free (dn);
963 GNUNET_asprintf (&full_name, 871 }
964 "%s%s%s", 872 if ((full_name != NULL) &&
965 dn, 873 (GNUNET_OK != GNUNET_DISK_directory_create_for_file (full_name)))
966 DIR_SEPARATOR_STR, 874 {
967 sfn); 875 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
968 } 876 _
969 GNUNET_free (sfn); 877 ("Failed to create directory for recursive download of `%s'\n"),
970 GNUNET_free (dn); 878 full_name);
971 } 879 GNUNET_free (full_name);
972 if ( (full_name != NULL) && 880 GNUNET_free_non_null (fn);
973 (GNUNET_OK != 881 return;
974 GNUNET_DISK_directory_create_for_file (full_name)) ) 882 }
975 {
976 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
977 _("Failed to create directory for recursive download of `%s'\n"),
978 full_name);
979 GNUNET_free (full_name);
980 GNUNET_free_non_null (fn);
981 return;
982 }
983 883
984 temp_name = NULL; 884 temp_name = NULL;
985#if DEBUG_DOWNLOAD 885#if DEBUG_DOWNLOAD
986 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 886 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
987 "Triggering recursive download of size %llu with %u bytes MD\n", 887 "Triggering recursive download of size %llu with %u bytes MD\n",
988 (unsigned long long) GNUNET_FS_uri_chk_get_file_size (uri), 888 (unsigned long long) GNUNET_FS_uri_chk_get_file_size (uri),
989 (unsigned int) GNUNET_CONTAINER_meta_data_get_serialized_size (meta)); 889 (unsigned int)
890 GNUNET_CONTAINER_meta_data_get_serialized_size (meta));
990#endif 891#endif
991 GNUNET_FS_download_start (dc->h, 892 GNUNET_FS_download_start (dc->h,
992 uri, 893 uri,
993 meta, 894 meta,
994 full_name, temp_name, 895 full_name, temp_name,
995 0, 896 0,
996 GNUNET_FS_uri_chk_get_file_size (uri), 897 GNUNET_FS_uri_chk_get_file_size (uri),
997 dc->anonymity, 898 dc->anonymity, dc->options, NULL, dc);
998 dc->options,
999 NULL,
1000 dc);
1001 GNUNET_free_non_null (full_name); 899 GNUNET_free_non_null (full_name);
1002 GNUNET_free_non_null (temp_name); 900 GNUNET_free_non_null (temp_name);
1003 GNUNET_free_non_null (fn); 901 GNUNET_free_non_null (fn);
@@ -1016,7 +914,7 @@ GNUNET_FS_free_download_request_ (struct DownloadRequest *dr)
1016 914
1017 if (dr == NULL) 915 if (dr == NULL)
1018 return; 916 return;
1019 for (i=0;i<dr->num_children;i++) 917 for (i = 0; i < dr->num_children; i++)
1020 GNUNET_FS_free_download_request_ (dr->children[i]); 918 GNUNET_FS_free_download_request_ (dr->children[i]);
1021 GNUNET_free_non_null (dr->children); 919 GNUNET_free_non_null (dr->children);
1022 GNUNET_free (dr); 920 GNUNET_free (dr);
@@ -1034,8 +932,7 @@ GNUNET_FS_free_download_request_ (struct DownloadRequest *dr)
1034 */ 932 */
1035static int 933static int
1036process_result_with_request (void *cls, 934process_result_with_request (void *cls,
1037 const GNUNET_HashCode *key, 935 const GNUNET_HashCode * key, void *value)
1038 void *value)
1039{ 936{
1040 struct ProcessResultClosure *prc = cls; 937 struct ProcessResultClosure *prc = cls;
1041 struct DownloadRequest *dr = value; 938 struct DownloadRequest *dr = value;
@@ -1054,152 +951,132 @@ process_result_with_request (void *cls,
1054 951
1055#if DEBUG_DOWNLOAD 952#if DEBUG_DOWNLOAD
1056 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 953 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1057 "Received block `%s' matching pending request at depth %u and offset %llu/%llu\n", 954 "Received block `%s' matching pending request at depth %u and offset %llu/%llu\n",
1058 GNUNET_h2s (key), 955 GNUNET_h2s (key),
1059 dr->depth, 956 dr->depth,
1060 (unsigned long long) dr->offset, 957 (unsigned long long) dr->offset,
1061 (unsigned long long) GNUNET_ntohll (dc->uri->data.chk.file_length)); 958 (unsigned long long) GNUNET_ntohll (dc->uri->data.
1062 959 chk.file_length));
960
1063#endif 961#endif
1064 bs = GNUNET_FS_tree_calculate_block_size (GNUNET_ntohll (dc->uri->data.chk.file_length), 962 bs = GNUNET_FS_tree_calculate_block_size (GNUNET_ntohll
1065 dr->offset, 963 (dc->uri->data.chk.file_length),
1066 dr->depth); 964 dr->offset, dr->depth);
1067 if (prc->size != bs) 965 if (prc->size != bs)
966 {
967 GNUNET_asprintf (&dc->emsg,
968 _
969 ("Internal error or bogus download URI (expected %u bytes at depth %u and offset %llu/%llu, got %u bytes)\n"),
970 bs, dr->depth, (unsigned long long) dr->offset,
971 (unsigned long long) GNUNET_ntohll (dc->uri->data.
972 chk.file_length),
973 prc->size);
974 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "%s", dc->emsg);
975 while (dr->parent != NULL)
1068 { 976 {
1069 GNUNET_asprintf (&dc->emsg,
1070 _("Internal error or bogus download URI (expected %u bytes at depth %u and offset %llu/%llu, got %u bytes)\n"),
1071 bs,
1072 dr->depth,
1073 (unsigned long long) dr->offset,
1074 (unsigned long long) GNUNET_ntohll (dc->uri->data.chk.file_length),
1075 prc->size);
1076 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1077 "%s",
1078 dc->emsg);
1079 while (dr->parent != NULL)
1080 {
1081 dr->state = BRS_ERROR;
1082 dr = dr->parent;
1083 }
1084 dr->state = BRS_ERROR; 977 dr->state = BRS_ERROR;
1085 goto signal_error; 978 dr = dr->parent;
1086 } 979 }
980 dr->state = BRS_ERROR;
981 goto signal_error;
982 }
1087 983
1088 (void) GNUNET_CONTAINER_multihashmap_remove (dc->active, 984 (void) GNUNET_CONTAINER_multihashmap_remove (dc->active, &prc->query, dr);
1089 &prc->query,
1090 dr);
1091 if (GNUNET_YES == dr->is_pending) 985 if (GNUNET_YES == dr->is_pending)
1092 { 986 {
1093 GNUNET_CONTAINER_DLL_remove (dc->pending_head, 987 GNUNET_CONTAINER_DLL_remove (dc->pending_head, dc->pending_tail, dr);
1094 dc->pending_tail, 988 dr->is_pending = GNUNET_NO;
1095 dr); 989 }
1096 dr->is_pending = GNUNET_NO;
1097 }
1098 990
1099 991
1100 GNUNET_CRYPTO_hash_to_aes_key (&dr->chk.key, &skey, &iv); 992 GNUNET_CRYPTO_hash_to_aes_key (&dr->chk.key, &skey, &iv);
1101 if (-1 == GNUNET_CRYPTO_aes_decrypt (prc->data, 993 if (-1 == GNUNET_CRYPTO_aes_decrypt (prc->data, prc->size, &skey, &iv, pt))
1102 prc->size, 994 {
1103 &skey, 995 GNUNET_break (0);
1104 &iv, 996 dc->emsg = GNUNET_strdup (_("internal error decrypting content"));
1105 pt)) 997 goto signal_error;
1106 { 998 }
1107 GNUNET_break (0);
1108 dc->emsg = GNUNET_strdup (_("internal error decrypting content"));
1109 goto signal_error;
1110 }
1111 off = compute_disk_offset (GNUNET_ntohll (dc->uri->data.chk.file_length), 999 off = compute_disk_offset (GNUNET_ntohll (dc->uri->data.chk.file_length),
1112 dr->offset, 1000 dr->offset, dr->depth);
1113 dr->depth);
1114 /* save to disk */ 1001 /* save to disk */
1115 if ( ( GNUNET_YES == prc->do_store) && 1002 if ((GNUNET_YES == prc->do_store) &&
1116 ( (dc->filename != NULL) || 1003 ((dc->filename != NULL) ||
1117 (is_recursive_download (dc)) ) && 1004 (is_recursive_download (dc))) &&
1118 ( (dr->depth == dc->treedepth) || 1005 ((dr->depth == dc->treedepth) ||
1119 (0 == (dc->options & GNUNET_FS_DOWNLOAD_NO_TEMPORARIES)) ) ) 1006 (0 == (dc->options & GNUNET_FS_DOWNLOAD_NO_TEMPORARIES))))
1007 {
1008 fh = GNUNET_DISK_file_open (dc->filename != NULL
1009 ? dc->filename
1010 : dc->temp_filename,
1011 GNUNET_DISK_OPEN_READWRITE |
1012 GNUNET_DISK_OPEN_CREATE,
1013 GNUNET_DISK_PERM_USER_READ |
1014 GNUNET_DISK_PERM_USER_WRITE |
1015 GNUNET_DISK_PERM_GROUP_READ |
1016 GNUNET_DISK_PERM_OTHER_READ);
1017 if (NULL == fh)
1120 { 1018 {
1121 fh = GNUNET_DISK_file_open (dc->filename != NULL 1019 GNUNET_asprintf (&dc->emsg,
1122 ? dc->filename 1020 _("Download failed: could not open file `%s': %s\n"),
1123 : dc->temp_filename, 1021 dc->filename, STRERROR (errno));
1124 GNUNET_DISK_OPEN_READWRITE | 1022 goto signal_error;
1125 GNUNET_DISK_OPEN_CREATE, 1023 }
1126 GNUNET_DISK_PERM_USER_READ |
1127 GNUNET_DISK_PERM_USER_WRITE |
1128 GNUNET_DISK_PERM_GROUP_READ |
1129 GNUNET_DISK_PERM_OTHER_READ);
1130 if (NULL == fh)
1131 {
1132 GNUNET_asprintf (&dc->emsg,
1133 _("Download failed: could not open file `%s': %s\n"),
1134 dc->filename,
1135 STRERROR (errno));
1136 goto signal_error;
1137 }
1138#if DEBUG_DOWNLOAD 1024#if DEBUG_DOWNLOAD
1139 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1025 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1140 "Saving decrypted block to disk at offset %llu\n", 1026 "Saving decrypted block to disk at offset %llu\n",
1141 (unsigned long long) off); 1027 (unsigned long long) off);
1142#endif 1028#endif
1143 if ( (off != 1029 if ((off != GNUNET_DISK_file_seek (fh, off, GNUNET_DISK_SEEK_SET)))
1144 GNUNET_DISK_file_seek (fh, 1030 {
1145 off, 1031 GNUNET_asprintf (&dc->emsg,
1146 GNUNET_DISK_SEEK_SET) ) ) 1032 _("Failed to seek to offset %llu in file `%s': %s\n"),
1147 { 1033 (unsigned long long) off,
1148 GNUNET_asprintf (&dc->emsg, 1034 dc->filename, STRERROR (errno));
1149 _("Failed to seek to offset %llu in file `%s': %s\n"), 1035 goto signal_error;
1150 (unsigned long long) off,
1151 dc->filename,
1152 STRERROR (errno));
1153 goto signal_error;
1154 }
1155 if (prc->size !=
1156 GNUNET_DISK_file_write (fh,
1157 pt,
1158 prc->size))
1159 {
1160 GNUNET_asprintf (&dc->emsg,
1161 _("Failed to write block of %u bytes at offset %llu in file `%s': %s\n"),
1162 (unsigned int) prc->size,
1163 (unsigned long long) off,
1164 dc->filename,
1165 STRERROR (errno));
1166 goto signal_error;
1167 }
1168 GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close (fh));
1169 fh = NULL;
1170 } 1036 }
1037 if (prc->size != GNUNET_DISK_file_write (fh, pt, prc->size))
1038 {
1039 GNUNET_asprintf (&dc->emsg,
1040 _
1041 ("Failed to write block of %u bytes at offset %llu in file `%s': %s\n"),
1042 (unsigned int) prc->size, (unsigned long long) off,
1043 dc->filename, STRERROR (errno));
1044 goto signal_error;
1045 }
1046 GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close (fh));
1047 fh = NULL;
1048 }
1171 1049
1172 if (dr->depth == 0) 1050 if (dr->depth == 0)
1051 {
1052 /* DBLOCK, update progress and try recursion if applicable */
1053 app = prc->size;
1054 if (dr->offset < dc->offset)
1173 { 1055 {
1174 /* DBLOCK, update progress and try recursion if applicable */ 1056 /* starting offset begins in the middle of pt,
1175 app = prc->size; 1057 * do not count first bytes as progress */
1176 if (dr->offset < dc->offset) 1058 GNUNET_assert (app > (dc->offset - dr->offset));
1177 { 1059 app -= (dc->offset - dr->offset);
1178 /* starting offset begins in the middle of pt,
1179 do not count first bytes as progress */
1180 GNUNET_assert (app > (dc->offset - dr->offset));
1181 app -= (dc->offset - dr->offset);
1182 }
1183 if (dr->offset + prc->size > dc->offset + dc->length)
1184 {
1185 /* end of block is after relevant range,
1186 do not count last bytes as progress */
1187 GNUNET_assert (app > (dr->offset + prc->size) - (dc->offset + dc->length));
1188 app -= (dr->offset + prc->size) - (dc->offset + dc->length);
1189 }
1190 dc->completed += app;
1191
1192 /* do recursive download if option is set and either meta data
1193 says it is a directory or if no meta data is given AND filename
1194 ends in '.gnd' (top-level case) */
1195 if (is_recursive_download (dc))
1196 GNUNET_FS_directory_list_contents (prc->size,
1197 pt,
1198 off,
1199 &trigger_recursive_download,
1200 dc);
1201
1202 } 1060 }
1061 if (dr->offset + prc->size > dc->offset + dc->length)
1062 {
1063 /* end of block is after relevant range,
1064 * do not count last bytes as progress */
1065 GNUNET_assert (app >
1066 (dr->offset + prc->size) - (dc->offset + dc->length));
1067 app -= (dr->offset + prc->size) - (dc->offset + dc->length);
1068 }
1069 dc->completed += app;
1070
1071 /* do recursive download if option is set and either meta data
1072 * says it is a directory or if no meta data is given AND filename
1073 * ends in '.gnd' (top-level case) */
1074 if (is_recursive_download (dc))
1075 GNUNET_FS_directory_list_contents (prc->size,
1076 pt,
1077 off, &trigger_recursive_download, dc);
1078
1079 }
1203 dr->state = BRS_DOWNLOAD_DOWN; 1080 dr->state = BRS_DOWNLOAD_DOWN;
1204 pi.status = GNUNET_FS_STATUS_DOWNLOAD_PROGRESS; 1081 pi.status = GNUNET_FS_STATUS_DOWNLOAD_PROGRESS;
1205 pi.value.download.specifics.progress.data = pt; 1082 pi.value.download.specifics.progress.data = pt;
@@ -1208,84 +1085,83 @@ process_result_with_request (void *cls,
1208 pi.value.download.specifics.progress.depth = dr->depth; 1085 pi.value.download.specifics.progress.depth = dr->depth;
1209 GNUNET_FS_download_make_status_ (&pi, dc); 1086 GNUNET_FS_download_make_status_ (&pi, dc);
1210 GNUNET_assert (dc->completed <= dc->length); 1087 GNUNET_assert (dc->completed <= dc->length);
1211 if (dr->depth == 0) 1088 if (dr->depth == 0)
1212 propagate_up (dr); 1089 propagate_up (dr);
1213 1090
1214 if (dc->completed == dc->length) 1091 if (dc->completed == dc->length)
1215 { 1092 {
1216 /* download completed, signal */ 1093 /* download completed, signal */
1217#if DEBUG_DOWNLOAD 1094#if DEBUG_DOWNLOAD
1218 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1095 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1219 "Download completed, truncating file to desired length %llu\n", 1096 "Download completed, truncating file to desired length %llu\n",
1220 (unsigned long long) GNUNET_ntohll (dc->uri->data.chk.file_length)); 1097 (unsigned long long) GNUNET_ntohll (dc->uri->data.
1098 chk.file_length));
1221#endif 1099#endif
1222 /* truncate file to size (since we store IBlocks at the end) */ 1100 /* truncate file to size (since we store IBlocks at the end) */
1223 if (dc->filename != NULL) 1101 if (dc->filename != NULL)
1224 {
1225 if (0 != truncate (dc->filename,
1226 GNUNET_ntohll (dc->uri->data.chk.file_length)))
1227 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
1228 "truncate",
1229 dc->filename);
1230 }
1231 GNUNET_assert (dr->depth == 0);
1232 check_completed (dc);
1233 }
1234 if (dr->depth == 0)
1235 { 1102 {
1236 /* bottom of the tree, no child downloads possible, just sync */ 1103 if (0 != truncate (dc->filename,
1237 GNUNET_FS_download_sync_ (dc); 1104 GNUNET_ntohll (dc->uri->data.chk.file_length)))
1238 return GNUNET_YES; 1105 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
1106 "truncate", dc->filename);
1239 } 1107 }
1108 GNUNET_assert (dr->depth == 0);
1109 check_completed (dc);
1110 }
1111 if (dr->depth == 0)
1112 {
1113 /* bottom of the tree, no child downloads possible, just sync */
1114 GNUNET_FS_download_sync_ (dc);
1115 return GNUNET_YES;
1116 }
1240 1117
1241#if DEBUG_DOWNLOAD 1118#if DEBUG_DOWNLOAD
1242 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1119 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1243 "Triggering downloads of children (this block was at depth %u and offset %llu)\n", 1120 "Triggering downloads of children (this block was at depth %u and offset %llu)\n",
1244 dr->depth, 1121 dr->depth, (unsigned long long) dr->offset);
1245 (unsigned long long) dr->offset);
1246#endif 1122#endif
1247 GNUNET_assert (0 == (prc->size % sizeof(struct ContentHashKey))); 1123 GNUNET_assert (0 == (prc->size % sizeof (struct ContentHashKey)));
1248 chkarr = (struct ContentHashKey*) pt; 1124 chkarr = (struct ContentHashKey *) pt;
1249 for (i=(prc->size / sizeof(struct ContentHashKey))-1;i>=0;i--) 1125 for (i = (prc->size / sizeof (struct ContentHashKey)) - 1; i >= 0; i--)
1126 {
1127 drc = dr->children[i];
1128 switch (drc->state)
1250 { 1129 {
1251 drc = dr->children[i]; 1130 case BRS_INIT:
1252 switch (drc->state) 1131 drc->chk = chkarr[i];
1253 { 1132 drc->state = BRS_CHK_SET;
1254 case BRS_INIT: 1133 schedule_block_download (dc, drc);
1255 drc->chk = chkarr[i]; 1134 break;
1256 drc->state = BRS_CHK_SET; 1135 case BRS_RECONSTRUCT_DOWN:
1257 schedule_block_download (dc, drc); 1136 GNUNET_assert (0);
1258 break; 1137 break;
1259 case BRS_RECONSTRUCT_DOWN: 1138 case BRS_RECONSTRUCT_META_UP:
1260 GNUNET_assert (0); 1139 GNUNET_assert (0);
1261 break; 1140 break;
1262 case BRS_RECONSTRUCT_META_UP: 1141 case BRS_RECONSTRUCT_UP:
1263 GNUNET_assert (0); 1142 GNUNET_assert (0);
1264 break; 1143 break;
1265 case BRS_RECONSTRUCT_UP: 1144 case BRS_CHK_SET:
1266 GNUNET_assert (0); 1145 GNUNET_assert (0);
1267 break; 1146 break;
1268 case BRS_CHK_SET: 1147 case BRS_DOWNLOAD_DOWN:
1269 GNUNET_assert (0); 1148 GNUNET_assert (0);
1270 break; 1149 break;
1271 case BRS_DOWNLOAD_DOWN: 1150 case BRS_DOWNLOAD_UP:
1272 GNUNET_assert (0); 1151 GNUNET_assert (0);
1273 break; 1152 break;
1274 case BRS_DOWNLOAD_UP: 1153 case BRS_ERROR:
1275 GNUNET_assert (0); 1154 GNUNET_assert (0);
1276 break; 1155 break;
1277 case BRS_ERROR: 1156 default:
1278 GNUNET_assert (0); 1157 GNUNET_assert (0);
1279 break; 1158 break;
1280 default:
1281 GNUNET_assert (0);
1282 break;
1283 }
1284 } 1159 }
1160 }
1285 GNUNET_FS_download_sync_ (dc); 1161 GNUNET_FS_download_sync_ (dc);
1286 return GNUNET_YES; 1162 return GNUNET_YES;
1287 1163
1288 signal_error: 1164signal_error:
1289 if (fh != NULL) 1165 if (fh != NULL)
1290 GNUNET_DISK_file_close (fh); 1166 GNUNET_DISK_file_close (fh);
1291 pi.status = GNUNET_FS_STATUS_DOWNLOAD_ERROR; 1167 pi.status = GNUNET_FS_STATUS_DOWNLOAD_ERROR;
@@ -1293,10 +1169,10 @@ process_result_with_request (void *cls,
1293 GNUNET_FS_download_make_status_ (&pi, dc); 1169 GNUNET_FS_download_make_status_ (&pi, dc);
1294 /* abort all pending requests */ 1170 /* abort all pending requests */
1295 if (NULL != dc->th) 1171 if (NULL != dc->th)
1296 { 1172 {
1297 GNUNET_CLIENT_notify_transmit_ready_cancel (dc->th); 1173 GNUNET_CLIENT_notify_transmit_ready_cancel (dc->th);
1298 dc->th = NULL; 1174 dc->th = NULL;
1299 } 1175 }
1300 GNUNET_CLIENT_disconnect (dc->client, GNUNET_NO); 1176 GNUNET_CLIENT_disconnect (dc->client, GNUNET_NO);
1301 dc->in_receive = GNUNET_NO; 1177 dc->in_receive = GNUNET_NO;
1302 dc->client = NULL; 1178 dc->client = NULL;
@@ -1321,9 +1197,7 @@ process_result_with_request (void *cls,
1321 */ 1197 */
1322static void 1198static void
1323process_result (struct GNUNET_FS_DownloadContext *dc, 1199process_result (struct GNUNET_FS_DownloadContext *dc,
1324 enum GNUNET_BLOCK_Type type, 1200 enum GNUNET_BLOCK_Type type, const void *data, size_t size)
1325 const void *data,
1326 size_t size)
1327{ 1201{
1328 struct ProcessResultClosure prc; 1202 struct ProcessResultClosure prc;
1329 1203
@@ -1335,14 +1209,13 @@ process_result (struct GNUNET_FS_DownloadContext *dc,
1335 GNUNET_CRYPTO_hash (data, size, &prc.query); 1209 GNUNET_CRYPTO_hash (data, size, &prc.query);
1336#if DEBUG_DOWNLOAD 1210#if DEBUG_DOWNLOAD
1337 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1211 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1338 "Received result for query `%s' from `%s'-service\n", 1212 "Received result for query `%s' from `%s'-service\n",
1339 GNUNET_h2s (&prc.query), 1213 GNUNET_h2s (&prc.query), "FS");
1340 "FS");
1341#endif 1214#endif
1342 GNUNET_CONTAINER_multihashmap_get_multiple (dc->active, 1215 GNUNET_CONTAINER_multihashmap_get_multiple (dc->active,
1343 &prc.query, 1216 &prc.query,
1344 &process_result_with_request, 1217 &process_result_with_request,
1345 &prc); 1218 &prc);
1346} 1219}
1347 1220
1348 1221
@@ -1353,35 +1226,30 @@ process_result (struct GNUNET_FS_DownloadContext *dc,
1353 * @param cls closure 1226 * @param cls closure
1354 * @param msg message received, NULL on timeout or fatal error 1227 * @param msg message received, NULL on timeout or fatal error
1355 */ 1228 */
1356static void 1229static void
1357receive_results (void *cls, 1230receive_results (void *cls, const struct GNUNET_MessageHeader *msg)
1358 const struct GNUNET_MessageHeader * msg)
1359{ 1231{
1360 struct GNUNET_FS_DownloadContext *dc = cls; 1232 struct GNUNET_FS_DownloadContext *dc = cls;
1361 const struct PutMessage *cm; 1233 const struct PutMessage *cm;
1362 uint16_t msize; 1234 uint16_t msize;
1363 1235
1364 if ( (NULL == msg) || 1236 if ((NULL == msg) ||
1365 (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_FS_PUT) || 1237 (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_FS_PUT) ||
1366 (sizeof (struct PutMessage) > ntohs(msg->size)) ) 1238 (sizeof (struct PutMessage) > ntohs (msg->size)))
1367 { 1239 {
1368 GNUNET_break (msg == NULL); 1240 GNUNET_break (msg == NULL);
1369 try_reconnect (dc); 1241 try_reconnect (dc);
1370 return; 1242 return;
1371 } 1243 }
1372 msize = ntohs(msg->size); 1244 msize = ntohs (msg->size);
1373 cm = (const struct PutMessage*) msg; 1245 cm = (const struct PutMessage *) msg;
1374 process_result (dc, 1246 process_result (dc,
1375 ntohl (cm->type), 1247 ntohl (cm->type), &cm[1], msize - sizeof (struct PutMessage));
1376 &cm[1],
1377 msize - sizeof (struct PutMessage));
1378 if (dc->client == NULL) 1248 if (dc->client == NULL)
1379 return; /* fatal error */ 1249 return; /* fatal error */
1380 /* continue receiving */ 1250 /* continue receiving */
1381 GNUNET_CLIENT_receive (dc->client, 1251 GNUNET_CLIENT_receive (dc->client,
1382 &receive_results, 1252 &receive_results, dc, GNUNET_TIME_UNIT_FOREVER_REL);
1383 dc,
1384 GNUNET_TIME_UNIT_FOREVER_REL);
1385} 1253}
1386 1254
1387 1255
@@ -1398,9 +1266,7 @@ receive_results (void *cls,
1398 * @return number of bytes written to buf 1266 * @return number of bytes written to buf
1399 */ 1267 */
1400static size_t 1268static size_t
1401transmit_download_request (void *cls, 1269transmit_download_request (void *cls, size_t size, void *buf)
1402 size_t size,
1403 void *buf)
1404{ 1270{
1405 struct GNUNET_FS_DownloadContext *dc = cls; 1271 struct GNUNET_FS_DownloadContext *dc = cls;
1406 size_t msize; 1272 size_t msize;
@@ -1409,65 +1275,60 @@ transmit_download_request (void *cls,
1409 1275
1410 dc->th = NULL; 1276 dc->th = NULL;
1411 if (NULL == buf) 1277 if (NULL == buf)
1412 { 1278 {
1413#if DEBUG_DOWNLOAD 1279#if DEBUG_DOWNLOAD
1414 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1280 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1415 "Transmitting download request failed, trying to reconnect\n"); 1281 "Transmitting download request failed, trying to reconnect\n");
1416#endif 1282#endif
1417 try_reconnect (dc); 1283 try_reconnect (dc);
1418 return 0; 1284 return 0;
1419 } 1285 }
1420 GNUNET_assert (size >= sizeof (struct SearchMessage)); 1286 GNUNET_assert (size >= sizeof (struct SearchMessage));
1421 msize = 0; 1287 msize = 0;
1422 sm = buf; 1288 sm = buf;
1423 while ( (NULL != (dr = dc->pending_head)) && 1289 while ((NULL != (dr = dc->pending_head)) &&
1424 (size >= msize + sizeof (struct SearchMessage)) ) 1290 (size >= msize + sizeof (struct SearchMessage)))
1425 { 1291 {
1426#if DEBUG_DOWNLOAD 1292#if DEBUG_DOWNLOAD
1427 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1293 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1428 "Transmitting download request for `%s' to `%s'-service\n", 1294 "Transmitting download request for `%s' to `%s'-service\n",
1429 GNUNET_h2s (&dr->chk.query), 1295 GNUNET_h2s (&dr->chk.query), "FS");
1430 "FS");
1431#endif 1296#endif
1432 memset (sm, 0, sizeof (struct SearchMessage)); 1297 memset (sm, 0, sizeof (struct SearchMessage));
1433 sm->header.size = htons (sizeof (struct SearchMessage)); 1298 sm->header.size = htons (sizeof (struct SearchMessage));
1434 sm->header.type = htons (GNUNET_MESSAGE_TYPE_FS_START_SEARCH); 1299 sm->header.type = htons (GNUNET_MESSAGE_TYPE_FS_START_SEARCH);
1435 if (0 != (dc->options & GNUNET_FS_DOWNLOAD_OPTION_LOOPBACK_ONLY)) 1300 if (0 != (dc->options & GNUNET_FS_DOWNLOAD_OPTION_LOOPBACK_ONLY))
1436 sm->options = htonl (1); 1301 sm->options = htonl (1);
1437 else 1302 else
1438 sm->options = htonl (0); 1303 sm->options = htonl (0);
1439 if (dr->depth == 0) 1304 if (dr->depth == 0)
1440 sm->type = htonl (GNUNET_BLOCK_TYPE_FS_DBLOCK); 1305 sm->type = htonl (GNUNET_BLOCK_TYPE_FS_DBLOCK);
1441 else 1306 else
1442 sm->type = htonl (GNUNET_BLOCK_TYPE_FS_IBLOCK); 1307 sm->type = htonl (GNUNET_BLOCK_TYPE_FS_IBLOCK);
1443 sm->anonymity_level = htonl (dc->anonymity); 1308 sm->anonymity_level = htonl (dc->anonymity);
1444 sm->target = dc->target.hashPubKey; 1309 sm->target = dc->target.hashPubKey;
1445 sm->query = dr->chk.query; 1310 sm->query = dr->chk.query;
1446 GNUNET_CONTAINER_DLL_remove (dc->pending_head, 1311 GNUNET_CONTAINER_DLL_remove (dc->pending_head, dc->pending_tail, dr);
1447 dc->pending_tail, 1312 dr->is_pending = GNUNET_NO;
1448 dr); 1313 msize += sizeof (struct SearchMessage);
1449 dr->is_pending = GNUNET_NO; 1314 sm++;
1450 msize += sizeof (struct SearchMessage); 1315 }
1451 sm++;
1452 }
1453 if (dc->pending_head != NULL) 1316 if (dc->pending_head != NULL)
1454 { 1317 {
1455 dc->th = GNUNET_CLIENT_notify_transmit_ready (dc->client, 1318 dc->th = GNUNET_CLIENT_notify_transmit_ready (dc->client,
1456 sizeof (struct SearchMessage), 1319 sizeof (struct SearchMessage),
1457 GNUNET_CONSTANTS_SERVICE_TIMEOUT, 1320 GNUNET_CONSTANTS_SERVICE_TIMEOUT,
1458 GNUNET_NO, 1321 GNUNET_NO,
1459 &transmit_download_request, 1322 &transmit_download_request,
1460 dc); 1323 dc);
1461 GNUNET_assert (dc->th != NULL); 1324 GNUNET_assert (dc->th != NULL);
1462 } 1325 }
1463 if (GNUNET_NO == dc->in_receive) 1326 if (GNUNET_NO == dc->in_receive)
1464 { 1327 {
1465 dc->in_receive = GNUNET_YES; 1328 dc->in_receive = GNUNET_YES;
1466 GNUNET_CLIENT_receive (dc->client, 1329 GNUNET_CLIENT_receive (dc->client,
1467 &receive_results, 1330 &receive_results, dc, GNUNET_TIME_UNIT_FOREVER_REL);
1468 dc, 1331 }
1469 GNUNET_TIME_UNIT_FOREVER_REL);
1470 }
1471 return msize; 1332 return msize;
1472} 1333}
1473 1334
@@ -1479,34 +1340,31 @@ transmit_download_request (void *cls,
1479 * @param tc unused 1340 * @param tc unused
1480 */ 1341 */
1481static void 1342static void
1482do_reconnect (void *cls, 1343do_reconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1483 const struct GNUNET_SCHEDULER_TaskContext *tc)
1484{ 1344{
1485 struct GNUNET_FS_DownloadContext *dc = cls; 1345 struct GNUNET_FS_DownloadContext *dc = cls;
1486 struct GNUNET_CLIENT_Connection *client; 1346 struct GNUNET_CLIENT_Connection *client;
1487 1347
1488 dc->task = GNUNET_SCHEDULER_NO_TASK; 1348 dc->task = GNUNET_SCHEDULER_NO_TASK;
1489 client = GNUNET_CLIENT_connect ("fs", 1349 client = GNUNET_CLIENT_connect ("fs", dc->h->cfg);
1490 dc->h->cfg);
1491 if (NULL == client) 1350 if (NULL == client)
1492 { 1351 {
1493 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1352 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1494 "Connecting to `%s'-service failed, will try again.\n", 1353 "Connecting to `%s'-service failed, will try again.\n", "FS");
1495 "FS"); 1354 try_reconnect (dc);
1496 try_reconnect (dc); 1355 return;
1497 return; 1356 }
1498 }
1499 dc->client = client; 1357 dc->client = client;
1500 if (dc->pending_head != NULL) 1358 if (dc->pending_head != NULL)
1501 { 1359 {
1502 dc->th = GNUNET_CLIENT_notify_transmit_ready (client, 1360 dc->th = GNUNET_CLIENT_notify_transmit_ready (client,
1503 sizeof (struct SearchMessage), 1361 sizeof (struct SearchMessage),
1504 GNUNET_CONSTANTS_SERVICE_TIMEOUT, 1362 GNUNET_CONSTANTS_SERVICE_TIMEOUT,
1505 GNUNET_NO, 1363 GNUNET_NO,
1506 &transmit_download_request, 1364 &transmit_download_request,
1507 dc); 1365 dc);
1508 GNUNET_assert (dc->th != NULL); 1366 GNUNET_assert (dc->th != NULL);
1509 } 1367 }
1510} 1368}
1511 1369
1512 1370
@@ -1519,18 +1377,14 @@ do_reconnect (void *cls,
1519 * @return GNUNET_OK 1377 * @return GNUNET_OK
1520 */ 1378 */
1521static int 1379static int
1522retry_entry (void *cls, 1380retry_entry (void *cls, const GNUNET_HashCode * key, void *entry)
1523 const GNUNET_HashCode *key,
1524 void *entry)
1525{ 1381{
1526 struct GNUNET_FS_DownloadContext *dc = cls; 1382 struct GNUNET_FS_DownloadContext *dc = cls;
1527 struct DownloadRequest *dr = entry; 1383 struct DownloadRequest *dr = entry;
1528 1384
1529 dr->next = NULL; 1385 dr->next = NULL;
1530 dr->prev = NULL; 1386 dr->prev = NULL;
1531 GNUNET_CONTAINER_DLL_insert (dc->pending_head, 1387 GNUNET_CONTAINER_DLL_insert (dc->pending_head, dc->pending_tail, dr);
1532 dc->pending_tail,
1533 dr);
1534 dr->is_pending = GNUNET_YES; 1388 dr->is_pending = GNUNET_YES;
1535 return GNUNET_OK; 1389 return GNUNET_OK;
1536} 1390}
@@ -1546,36 +1400,32 @@ retry_entry (void *cls,
1546static void 1400static void
1547try_reconnect (struct GNUNET_FS_DownloadContext *dc) 1401try_reconnect (struct GNUNET_FS_DownloadContext *dc)
1548{ 1402{
1549 1403
1550 if (NULL != dc->client) 1404 if (NULL != dc->client)
1551 { 1405 {
1552#if DEBUG_DOWNLOAD 1406#if DEBUG_DOWNLOAD
1553 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1407 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1554 "Moving all requests back to pending list\n"); 1408 "Moving all requests back to pending list\n");
1555#endif 1409#endif
1556 if (NULL != dc->th) 1410 if (NULL != dc->th)
1557 { 1411 {
1558 GNUNET_CLIENT_notify_transmit_ready_cancel (dc->th); 1412 GNUNET_CLIENT_notify_transmit_ready_cancel (dc->th);
1559 dc->th = NULL; 1413 dc->th = NULL;
1560 }
1561 /* full reset of the pending list */
1562 dc->pending_head = NULL;
1563 dc->pending_tail = NULL;
1564 GNUNET_CONTAINER_multihashmap_iterate (dc->active,
1565 &retry_entry,
1566 dc);
1567 GNUNET_CLIENT_disconnect (dc->client, GNUNET_NO);
1568 dc->in_receive = GNUNET_NO;
1569 dc->client = NULL;
1570 } 1414 }
1415 /* full reset of the pending list */
1416 dc->pending_head = NULL;
1417 dc->pending_tail = NULL;
1418 GNUNET_CONTAINER_multihashmap_iterate (dc->active, &retry_entry, dc);
1419 GNUNET_CLIENT_disconnect (dc->client, GNUNET_NO);
1420 dc->in_receive = GNUNET_NO;
1421 dc->client = NULL;
1422 }
1571#if DEBUG_DOWNLOAD 1423#if DEBUG_DOWNLOAD
1572 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1424 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Will try to reconnect in 1s\n");
1573 "Will try to reconnect in 1s\n");
1574#endif 1425#endif
1575 dc->task 1426 dc->task
1576 = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 1427 = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
1577 &do_reconnect, 1428 &do_reconnect, dc);
1578 dc);
1579} 1429}
1580 1430
1581 1431
@@ -1586,15 +1436,13 @@ try_reconnect (struct GNUNET_FS_DownloadContext *dc)
1586 * @param client handle to use for communcation with FS (we must destroy it!) 1436 * @param client handle to use for communcation with FS (we must destroy it!)
1587 */ 1437 */
1588static void 1438static void
1589activate_fs_download (void *cls, 1439activate_fs_download (void *cls, struct GNUNET_CLIENT_Connection *client)
1590 struct GNUNET_CLIENT_Connection *client)
1591{ 1440{
1592 struct GNUNET_FS_DownloadContext *dc = cls; 1441 struct GNUNET_FS_DownloadContext *dc = cls;
1593 struct GNUNET_FS_ProgressInfo pi; 1442 struct GNUNET_FS_ProgressInfo pi;
1594 1443
1595#if DEBUG_DOWNLOAD 1444#if DEBUG_DOWNLOAD
1596 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1445 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download activated\n");
1597 "Download activated\n");
1598#endif 1446#endif
1599 GNUNET_assert (NULL != client); 1447 GNUNET_assert (NULL != client);
1600 GNUNET_assert (dc->client == NULL); 1448 GNUNET_assert (dc->client == NULL);
@@ -1604,23 +1452,21 @@ activate_fs_download (void *cls,
1604 GNUNET_FS_download_make_status_ (&pi, dc); 1452 GNUNET_FS_download_make_status_ (&pi, dc);
1605 dc->pending_head = NULL; 1453 dc->pending_head = NULL;
1606 dc->pending_tail = NULL; 1454 dc->pending_tail = NULL;
1607 GNUNET_CONTAINER_multihashmap_iterate (dc->active, 1455 GNUNET_CONTAINER_multihashmap_iterate (dc->active, &retry_entry, dc);
1608 &retry_entry,
1609 dc);
1610#if DEBUG_DOWNLOAD 1456#if DEBUG_DOWNLOAD
1611 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1457 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1612 "Asking for transmission to FS service\n"); 1458 "Asking for transmission to FS service\n");
1613#endif 1459#endif
1614 if (dc->pending_head != NULL) 1460 if (dc->pending_head != NULL)
1615 { 1461 {
1616 dc->th = GNUNET_CLIENT_notify_transmit_ready (dc->client, 1462 dc->th = GNUNET_CLIENT_notify_transmit_ready (dc->client,
1617 sizeof (struct SearchMessage), 1463 sizeof (struct SearchMessage),
1618 GNUNET_CONSTANTS_SERVICE_TIMEOUT, 1464 GNUNET_CONSTANTS_SERVICE_TIMEOUT,
1619 GNUNET_NO, 1465 GNUNET_NO,
1620 &transmit_download_request, 1466 &transmit_download_request,
1621 dc); 1467 dc);
1622 GNUNET_assert (dc->th != NULL); 1468 GNUNET_assert (dc->th != NULL);
1623 } 1469 }
1624} 1470}
1625 1471
1626 1472
@@ -1636,20 +1482,19 @@ deactivate_fs_download (void *cls)
1636 struct GNUNET_FS_ProgressInfo pi; 1482 struct GNUNET_FS_ProgressInfo pi;
1637 1483
1638#if DEBUG_DOWNLOAD 1484#if DEBUG_DOWNLOAD
1639 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1485 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download deactivated\n");
1640 "Download deactivated\n"); 1486#endif
1641#endif
1642 if (NULL != dc->th) 1487 if (NULL != dc->th)
1643 { 1488 {
1644 GNUNET_CLIENT_notify_transmit_ready_cancel (dc->th); 1489 GNUNET_CLIENT_notify_transmit_ready_cancel (dc->th);
1645 dc->th = NULL; 1490 dc->th = NULL;
1646 } 1491 }
1647 if (NULL != dc->client) 1492 if (NULL != dc->client)
1648 { 1493 {
1649 GNUNET_CLIENT_disconnect (dc->client, GNUNET_NO); 1494 GNUNET_CLIENT_disconnect (dc->client, GNUNET_NO);
1650 dc->in_receive = GNUNET_NO; 1495 dc->in_receive = GNUNET_NO;
1651 dc->client = NULL; 1496 dc->client = NULL;
1652 } 1497 }
1653 dc->pending_head = NULL; 1498 dc->pending_head = NULL;
1654 dc->pending_tail = NULL; 1499 dc->pending_tail = NULL;
1655 pi.status = GNUNET_FS_STATUS_DOWNLOAD_INACTIVE; 1500 pi.status = GNUNET_FS_STATUS_DOWNLOAD_INACTIVE;
@@ -1677,54 +1522,55 @@ deactivate_fs_download (void *cls)
1677 */ 1522 */
1678static struct DownloadRequest * 1523static struct DownloadRequest *
1679create_download_request (struct DownloadRequest *parent, 1524create_download_request (struct DownloadRequest *parent,
1680 unsigned int depth, 1525 unsigned int depth,
1681 uint64_t dr_offset, 1526 uint64_t dr_offset,
1682 uint64_t file_start_offset, 1527 uint64_t file_start_offset, uint64_t desired_length)
1683 uint64_t desired_length)
1684{ 1528{
1685 struct DownloadRequest *dr; 1529 struct DownloadRequest *dr;
1686 unsigned int i; 1530 unsigned int i;
1687 unsigned int head_skip; 1531 unsigned int head_skip;
1688 uint64_t child_block_size; 1532 uint64_t child_block_size;
1689 1533
1690 dr = GNUNET_malloc (sizeof (struct DownloadRequest)); 1534 dr = GNUNET_malloc (sizeof (struct DownloadRequest));
1691 dr->parent = parent; 1535 dr->parent = parent;
1692 dr->depth = depth; 1536 dr->depth = depth;
1693 dr->offset = dr_offset; 1537 dr->offset = dr_offset;
1694 if (depth > 0) 1538 if (depth > 0)
1695 { 1539 {
1696 child_block_size = GNUNET_FS_tree_compute_tree_size (depth - 1); 1540 child_block_size = GNUNET_FS_tree_compute_tree_size (depth - 1);
1697 1541
1698 /* calculate how many blocks at this level are not interesting 1542 /* calculate how many blocks at this level are not interesting
1699 from the start (rounded down), either because of the requested 1543 * from the start (rounded down), either because of the requested
1700 file offset or because this IBlock is further along */ 1544 * file offset or because this IBlock is further along */
1701 if (dr_offset < file_start_offset) 1545 if (dr_offset < file_start_offset)
1702 head_skip = file_start_offset / child_block_size; 1546 head_skip = file_start_offset / child_block_size;
1703 else 1547 else
1704 head_skip = dr_offset / child_block_size; 1548 head_skip = dr_offset / child_block_size;
1705 1549
1706 /* calculate index of last block at this level that is interesting (rounded up) */ 1550 /* calculate index of last block at this level that is interesting (rounded up) */
1707 dr->num_children = file_start_offset + desired_length / child_block_size; 1551 dr->num_children = file_start_offset + desired_length / child_block_size;
1708 if (dr->num_children * child_block_size < file_start_offset + desired_length) 1552 if (dr->num_children * child_block_size <
1709 dr->num_children++; /* round up */ 1553 file_start_offset + desired_length)
1710 1554 dr->num_children++; /* round up */
1711 /* now we can get the total number of children for this block */ 1555
1712 dr->num_children -= head_skip; 1556 /* now we can get the total number of children for this block */
1713 if (dr->num_children > CHK_PER_INODE) 1557 dr->num_children -= head_skip;
1714 dr->num_children = CHK_PER_INODE; /* cap at max */ 1558 if (dr->num_children > CHK_PER_INODE)
1715 1559 dr->num_children = CHK_PER_INODE; /* cap at max */
1716 /* why else would we have gotten here to begin with? (that'd be a bad logic error) */ 1560
1717 GNUNET_assert (dr->num_children > 0); 1561 /* why else would we have gotten here to begin with? (that'd be a bad logic error) */
1718 1562 GNUNET_assert (dr->num_children > 0);
1719 dr->children = GNUNET_malloc (dr->num_children * 1563
1720 sizeof (struct DownloadRequest *)); 1564 dr->children = GNUNET_malloc (dr->num_children *
1721 for (i=0;i<dr->num_children;i++) 1565 sizeof (struct DownloadRequest *));
1722 dr->children[i] = create_download_request (dr, 1566 for (i = 0; i < dr->num_children; i++)
1723 depth - 1, 1567 dr->children[i] = create_download_request (dr,
1724 dr_offset + i * child_block_size, 1568 depth - 1,
1725 file_start_offset, 1569 dr_offset +
1726 desired_length); 1570 i * child_block_size,
1727 } 1571 file_start_offset,
1572 desired_length);
1573 }
1728 return dr; 1574 return dr;
1729} 1575}
1730 1576
@@ -1737,30 +1583,28 @@ create_download_request (struct DownloadRequest *parent,
1737 * @param tc scheduler context 1583 * @param tc scheduler context
1738 */ 1584 */
1739static void 1585static void
1740reconstruct_cont (void *cls, 1586reconstruct_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1741 const struct GNUNET_SCHEDULER_TaskContext *tc)
1742{ 1587{
1743 struct GNUNET_FS_DownloadContext *dc = cls; 1588 struct GNUNET_FS_DownloadContext *dc = cls;
1744 1589
1745 /* clean up state from tree encoder */ 1590 /* clean up state from tree encoder */
1746 if (dc->te != NULL) 1591 if (dc->te != NULL)
1747 { 1592 {
1748 GNUNET_FS_tree_encoder_finish (dc->te, NULL, NULL); 1593 GNUNET_FS_tree_encoder_finish (dc->te, NULL, NULL);
1749 dc->te = NULL; 1594 dc->te = NULL;
1750 } 1595 }
1751 if (dc->task != GNUNET_SCHEDULER_NO_TASK) 1596 if (dc->task != GNUNET_SCHEDULER_NO_TASK)
1752 { 1597 {
1753 GNUNET_SCHEDULER_cancel (dc->task); 1598 GNUNET_SCHEDULER_cancel (dc->task);
1754 dc->task = GNUNET_SCHEDULER_NO_TASK; 1599 dc->task = GNUNET_SCHEDULER_NO_TASK;
1755 } 1600 }
1756 if (dc->rfh != NULL) 1601 if (dc->rfh != NULL)
1757 { 1602 {
1758 GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close (dc->rfh)); 1603 GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close (dc->rfh));
1759 dc->rfh = NULL; 1604 dc->rfh = NULL;
1760 } 1605 }
1761 /* start "normal" download */ 1606 /* start "normal" download */
1762 schedule_block_download (dc, 1607 schedule_block_download (dc, dc->top_request);
1763 dc->top_request);
1764} 1608}
1765 1609
1766 1610
@@ -1771,8 +1615,7 @@ reconstruct_cont (void *cls,
1771 * @param tc task context 1615 * @param tc task context
1772 */ 1616 */
1773static void 1617static void
1774get_next_block (void *cls, 1618get_next_block (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1775 const struct GNUNET_SCHEDULER_TaskContext *tc)
1776{ 1619{
1777 struct GNUNET_FS_DownloadContext *dc = cls; 1620 struct GNUNET_FS_DownloadContext *dc = cls;
1778 1621
@@ -1799,14 +1642,13 @@ get_next_block (void *cls,
1799 * @param block the (encrypted) block 1642 * @param block the (encrypted) block
1800 * @param block_size size of block (in bytes) 1643 * @param block_size size of block (in bytes)
1801 */ 1644 */
1802static void 1645static void
1803reconstruct_cb (void *cls, 1646reconstruct_cb (void *cls,
1804 const struct ContentHashKey *chk, 1647 const struct ContentHashKey *chk,
1805 uint64_t offset, 1648 uint64_t offset,
1806 unsigned int depth, 1649 unsigned int depth,
1807 enum GNUNET_BLOCK_Type type, 1650 enum GNUNET_BLOCK_Type type,
1808 const void *block, 1651 const void *block, uint16_t block_size)
1809 uint16_t block_size)
1810{ 1652{
1811 struct GNUNET_FS_DownloadContext *dc = cls; 1653 struct GNUNET_FS_DownloadContext *dc = cls;
1812 struct GNUNET_FS_ProgressInfo pi; 1654 struct GNUNET_FS_ProgressInfo pi;
@@ -1817,67 +1659,62 @@ reconstruct_cb (void *cls,
1817 /* find corresponding request entry */ 1659 /* find corresponding request entry */
1818 dr = dc->top_request; 1660 dr = dc->top_request;
1819 while (dr->depth > depth) 1661 while (dr->depth > depth)
1820 { 1662 {
1821 blen = GNUNET_FS_tree_compute_tree_size (dr->depth); 1663 blen = GNUNET_FS_tree_compute_tree_size (dr->depth);
1822 chld = (offset - dr->offset) / blen; 1664 chld = (offset - dr->offset) / blen;
1823 GNUNET_assert (chld < dr->num_children); 1665 GNUNET_assert (chld < dr->num_children);
1824 dr = dr->children[chld]; 1666 dr = dr->children[chld];
1825 } 1667 }
1826 switch (dr->state) 1668 switch (dr->state)
1827 { 1669 {
1828 case BRS_INIT: 1670 case BRS_INIT:
1829 break; 1671 break;
1830 case BRS_RECONSTRUCT_DOWN: 1672 case BRS_RECONSTRUCT_DOWN:
1831 break; 1673 break;
1832 case BRS_RECONSTRUCT_META_UP: 1674 case BRS_RECONSTRUCT_META_UP:
1833 break; 1675 break;
1834 case BRS_RECONSTRUCT_UP: 1676 case BRS_RECONSTRUCT_UP:
1835 break; 1677 break;
1836 case BRS_CHK_SET: 1678 case BRS_CHK_SET:
1837 if (0 == memcmp (chk, 1679 if (0 == memcmp (chk, &dr->chk, sizeof (struct ContentHashKey)))
1838 &dr->chk, 1680 {
1839 sizeof (struct ContentHashKey))) 1681 /* block matches, hence tree below matches;
1840 { 1682 * this request is done! */
1841 /* block matches, hence tree below matches; 1683 dr->state = BRS_DOWNLOAD_UP;
1842 this request is done! */ 1684 /* calculate how many bytes of payload this block
1843 dr->state = BRS_DOWNLOAD_UP; 1685 * corresponds to */
1844 /* calculate how many bytes of payload this block 1686 blen = GNUNET_FS_tree_compute_tree_size (dr->depth);
1845 corresponds to */ 1687 /* how many of those bytes are in the requested range? */
1846 blen = GNUNET_FS_tree_compute_tree_size (dr->depth); 1688 blen = GNUNET_MIN (blen, dc->length + dc->offset - dr->offset);
1847 /* how many of those bytes are in the requested range? */ 1689 /* signal progress */
1848 blen = GNUNET_MIN (blen, 1690 dc->completed += blen;
1849 dc->length + dc->offset - dr->offset); 1691 pi.status = GNUNET_FS_STATUS_DOWNLOAD_PROGRESS;
1850 /* signal progress */ 1692 pi.value.download.specifics.progress.data = NULL;
1851 dc->completed += blen; 1693 pi.value.download.specifics.progress.offset = offset;
1852 pi.status = GNUNET_FS_STATUS_DOWNLOAD_PROGRESS; 1694 pi.value.download.specifics.progress.data_len = 0;
1853 pi.value.download.specifics.progress.data = NULL; 1695 pi.value.download.specifics.progress.depth = 0;
1854 pi.value.download.specifics.progress.offset = offset; 1696 GNUNET_FS_download_make_status_ (&pi, dc);
1855 pi.value.download.specifics.progress.data_len = 0;
1856 pi.value.download.specifics.progress.depth = 0;
1857 GNUNET_FS_download_make_status_ (&pi, dc);
1858 }
1859 else
1860 {
1861 }
1862 break;
1863 case BRS_DOWNLOAD_DOWN:
1864 break;
1865 case BRS_DOWNLOAD_UP:
1866 break;
1867 case BRS_ERROR:
1868 break;
1869 default:
1870 GNUNET_assert (0);
1871 break;
1872 }
1873 if ( (dr == dc->top_request) &&
1874 (dr->state == BRS_DOWNLOAD_UP) )
1875 {
1876 check_completed (dc);
1877 return;
1878 } 1697 }
1879 dc->task = GNUNET_SCHEDULER_add_now (&get_next_block, 1698 else
1880 dc); 1699 {
1700 }
1701 break;
1702 case BRS_DOWNLOAD_DOWN:
1703 break;
1704 case BRS_DOWNLOAD_UP:
1705 break;
1706 case BRS_ERROR:
1707 break;
1708 default:
1709 GNUNET_assert (0);
1710 break;
1711 }
1712 if ((dr == dc->top_request) && (dr->state == BRS_DOWNLOAD_UP))
1713 {
1714 check_completed (dc);
1715 return;
1716 }
1717 dc->task = GNUNET_SCHEDULER_add_now (&get_next_block, dc);
1881} 1718}
1882 1719
1883 1720
@@ -1894,31 +1731,24 @@ reconstruct_cb (void *cls,
1894 * @return number of bytes copied to buf, 0 on error 1731 * @return number of bytes copied to buf, 0 on error
1895 */ 1732 */
1896static size_t 1733static size_t
1897fh_reader (void *cls, 1734fh_reader (void *cls, uint64_t offset, size_t max, void *buf, char **emsg)
1898 uint64_t offset,
1899 size_t max,
1900 void *buf,
1901 char **emsg)
1902{ 1735{
1903 struct GNUNET_FS_DownloadContext *dc = cls; 1736 struct GNUNET_FS_DownloadContext *dc = cls;
1904 struct GNUNET_DISK_FileHandle *fh = dc->rfh; 1737 struct GNUNET_DISK_FileHandle *fh = dc->rfh;
1905 ssize_t ret; 1738 ssize_t ret;
1906 1739
1907 *emsg = NULL; 1740 *emsg = NULL;
1908 if (offset != 1741 if (offset != GNUNET_DISK_file_seek (fh, offset, GNUNET_DISK_SEEK_SET))
1909 GNUNET_DISK_file_seek (fh, 1742 {
1910 offset, 1743 *emsg = GNUNET_strdup (strerror (errno));
1911 GNUNET_DISK_SEEK_SET)) 1744 return 0;
1912 { 1745 }
1913 *emsg = GNUNET_strdup (strerror (errno));
1914 return 0;
1915 }
1916 ret = GNUNET_DISK_file_read (fh, buf, max); 1746 ret = GNUNET_DISK_file_read (fh, buf, max);
1917 if (ret < 0) 1747 if (ret < 0)
1918 { 1748 {
1919 *emsg = GNUNET_strdup (strerror (errno)); 1749 *emsg = GNUNET_strdup (strerror (errno));
1920 return 0; 1750 return 0;
1921 } 1751 }
1922 return ret; 1752 return ret;
1923} 1753}
1924 1754
@@ -1932,149 +1762,141 @@ fh_reader (void *cls,
1932 */ 1762 */
1933void 1763void
1934GNUNET_FS_download_start_task_ (void *cls, 1764GNUNET_FS_download_start_task_ (void *cls,
1935 const struct GNUNET_SCHEDULER_TaskContext *tc) 1765 const struct GNUNET_SCHEDULER_TaskContext *tc)
1936{ 1766{
1937 struct GNUNET_FS_DownloadContext *dc = cls; 1767 struct GNUNET_FS_DownloadContext *dc = cls;
1938 struct GNUNET_FS_ProgressInfo pi; 1768 struct GNUNET_FS_ProgressInfo pi;
1939 struct GNUNET_DISK_FileHandle *fh; 1769 struct GNUNET_DISK_FileHandle *fh;
1940 1770
1941#if DEBUG_DOWNLOAD 1771#if DEBUG_DOWNLOAD
1942 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1772 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Start task running...\n");
1943 "Start task running...\n");
1944#endif 1773#endif
1945 dc->task = GNUNET_SCHEDULER_NO_TASK; 1774 dc->task = GNUNET_SCHEDULER_NO_TASK;
1946 if (dc->length == 0) 1775 if (dc->length == 0)
1947 { 1776 {
1948 /* no bytes required! */ 1777 /* no bytes required! */
1949 if (dc->filename != NULL) 1778 if (dc->filename != NULL)
1950 { 1779 {
1951 fh = GNUNET_DISK_file_open (dc->filename, 1780 fh = GNUNET_DISK_file_open (dc->filename,
1952 GNUNET_DISK_OPEN_READWRITE | 1781 GNUNET_DISK_OPEN_READWRITE |
1953 GNUNET_DISK_OPEN_CREATE | 1782 GNUNET_DISK_OPEN_CREATE |
1954 ( (0 == GNUNET_FS_uri_chk_get_file_size (dc->uri)) 1783 ((0 ==
1955 ? GNUNET_DISK_OPEN_TRUNCATE : 0), 1784 GNUNET_FS_uri_chk_get_file_size (dc->uri)) ?
1956 GNUNET_DISK_PERM_USER_READ | 1785 GNUNET_DISK_OPEN_TRUNCATE : 0),
1957 GNUNET_DISK_PERM_USER_WRITE | 1786 GNUNET_DISK_PERM_USER_READ |
1958 GNUNET_DISK_PERM_GROUP_READ | 1787 GNUNET_DISK_PERM_USER_WRITE |
1959 GNUNET_DISK_PERM_OTHER_READ); 1788 GNUNET_DISK_PERM_GROUP_READ |
1960 GNUNET_DISK_file_close (fh); 1789 GNUNET_DISK_PERM_OTHER_READ);
1961 } 1790 GNUNET_DISK_file_close (fh);
1962 GNUNET_FS_download_sync_ (dc);
1963 check_completed (dc);
1964 return;
1965 } 1791 }
1966 if (dc->emsg != NULL) 1792 GNUNET_FS_download_sync_ (dc);
1793 check_completed (dc);
1794 return;
1795 }
1796 if (dc->emsg != NULL)
1967 return; 1797 return;
1968 if (dc->top_request == NULL) 1798 if (dc->top_request == NULL)
1969 { 1799 {
1970 dc->top_request = create_download_request (NULL, dc->treedepth - 1, 0, 1800 dc->top_request = create_download_request (NULL, dc->treedepth - 1, 0,
1971 dc->offset, dc->length); 1801 dc->offset, dc->length);
1972 dc->top_request->state = BRS_CHK_SET; 1802 dc->top_request->state = BRS_CHK_SET;
1973 dc->top_request->chk = (dc->uri->type == chk) 1803 dc->top_request->chk = (dc->uri->type == chk)
1974 ? dc->uri->data.chk.chk 1804 ? dc->uri->data.chk.chk : dc->uri->data.loc.fi.chk;
1975 : dc->uri->data.loc.fi.chk; 1805 /* signal start */
1976 /* signal start */ 1806 GNUNET_FS_download_sync_ (dc);
1977 GNUNET_FS_download_sync_ (dc); 1807 pi.status = GNUNET_FS_STATUS_DOWNLOAD_START;
1978 pi.status = GNUNET_FS_STATUS_DOWNLOAD_START; 1808 pi.value.download.specifics.start.meta = dc->meta;
1979 pi.value.download.specifics.start.meta = dc->meta; 1809 GNUNET_FS_download_make_status_ (&pi, dc);
1980 GNUNET_FS_download_make_status_ (&pi, dc); 1810 }
1981 }
1982 GNUNET_FS_download_start_downloading_ (dc); 1811 GNUNET_FS_download_start_downloading_ (dc);
1983 /* attempt reconstruction from disk */ 1812 /* attempt reconstruction from disk */
1984 if (GNUNET_YES == GNUNET_DISK_file_test (dc->filename)) 1813 if (GNUNET_YES == GNUNET_DISK_file_test (dc->filename))
1985 dc->rfh = GNUNET_DISK_file_open (dc->filename, 1814 dc->rfh = GNUNET_DISK_file_open (dc->filename,
1986 GNUNET_DISK_OPEN_READ, 1815 GNUNET_DISK_OPEN_READ,
1987 GNUNET_DISK_PERM_NONE); 1816 GNUNET_DISK_PERM_NONE);
1988 if (dc->top_request->state == BRS_CHK_SET) 1817 if (dc->top_request->state == BRS_CHK_SET)
1818 {
1819 if (dc->rfh != NULL)
1989 { 1820 {
1990 if (dc->rfh != NULL) 1821 /* first, try top-down */
1991 {
1992 /* first, try top-down */
1993#if DEBUG_DOWNLOAD 1822#if DEBUG_DOWNLOAD
1994 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1823 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1995 "Trying top-down reconstruction for `%s'\n", 1824 "Trying top-down reconstruction for `%s'\n", dc->filename);
1996 dc->filename);
1997#endif 1825#endif
1998 try_top_down_reconstruction (dc, dc->top_request); 1826 try_top_down_reconstruction (dc, dc->top_request);
1999 switch (dc->top_request->state) 1827 switch (dc->top_request->state)
2000 { 1828 {
2001 case BRS_CHK_SET: 1829 case BRS_CHK_SET:
2002 break; /* normal */ 1830 break; /* normal */
2003 case BRS_DOWNLOAD_DOWN: 1831 case BRS_DOWNLOAD_DOWN:
2004 break; /* normal, some blocks already down */ 1832 break; /* normal, some blocks already down */
2005 case BRS_DOWNLOAD_UP: 1833 case BRS_DOWNLOAD_UP:
2006 /* already done entirely, party! */ 1834 /* already done entirely, party! */
2007 if (dc->rfh != NULL) 1835 if (dc->rfh != NULL)
2008 { 1836 {
2009 /* avoid hanging on to file handle longer than 1837 /* avoid hanging on to file handle longer than
2010 necessary */ 1838 * necessary */
2011 GNUNET_DISK_file_close (dc->rfh); 1839 GNUNET_DISK_file_close (dc->rfh);
2012 dc->rfh = NULL; 1840 dc->rfh = NULL;
2013 } 1841 }
2014 return; 1842 return;
2015 case BRS_ERROR: 1843 case BRS_ERROR:
2016 GNUNET_asprintf (&dc->emsg, 1844 GNUNET_asprintf (&dc->emsg, _("Invalid URI"));
2017 _("Invalid URI")); 1845 GNUNET_FS_download_sync_ (dc);
2018 GNUNET_FS_download_sync_ (dc); 1846 pi.status = GNUNET_FS_STATUS_DOWNLOAD_ERROR;
2019 pi.status = GNUNET_FS_STATUS_DOWNLOAD_ERROR; 1847 pi.value.download.specifics.error.message = dc->emsg;
2020 pi.value.download.specifics.error.message = dc->emsg; 1848 GNUNET_FS_download_make_status_ (&pi, dc);
2021 GNUNET_FS_download_make_status_ (&pi, dc); 1849 return;
2022 return; 1850 default:
2023 default: 1851 GNUNET_assert (0);
2024 GNUNET_assert (0); 1852 break;
2025 break; 1853 }
2026 } 1854 }
2027 } 1855 }
2028 }
2029 /* attempt reconstruction from meta data */ 1856 /* attempt reconstruction from meta data */
2030 if ( (GNUNET_FS_uri_chk_get_file_size (dc->uri) <= MAX_INLINE_SIZE) && 1857 if ((GNUNET_FS_uri_chk_get_file_size (dc->uri) <= MAX_INLINE_SIZE) &&
2031 (NULL != dc->meta) ) 1858 (NULL != dc->meta))
2032 { 1859 {
2033#if DEBUG_DOWNLOAD 1860#if DEBUG_DOWNLOAD
2034 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1861 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2035 "Trying to find embedded meta data for download of size %llu with %u bytes MD\n", 1862 "Trying to find embedded meta data for download of size %llu with %u bytes MD\n",
2036 (unsigned long long) GNUNET_FS_uri_chk_get_file_size (dc->uri), 1863 (unsigned long long) GNUNET_FS_uri_chk_get_file_size (dc->uri),
2037 (unsigned int) GNUNET_CONTAINER_meta_data_get_serialized_size (dc->meta)); 1864 (unsigned int)
1865 GNUNET_CONTAINER_meta_data_get_serialized_size (dc->meta));
2038#endif 1866#endif
2039 GNUNET_CONTAINER_meta_data_iterate (dc->meta, 1867 GNUNET_CONTAINER_meta_data_iterate (dc->meta, &match_full_data, dc);
2040 &match_full_data, 1868 if (dc->top_request->state == BRS_DOWNLOAD_UP)
2041 dc);
2042 if (dc->top_request->state == BRS_DOWNLOAD_UP)
2043 {
2044 if (dc->rfh != NULL)
2045 {
2046 /* avoid hanging on to file handle longer than
2047 necessary */
2048 GNUNET_DISK_file_close (dc->rfh);
2049 dc->rfh = NULL;
2050 }
2051 return; /* finished, status update was already done for us */
2052 }
2053 }
2054 if (dc->rfh != NULL)
2055 { 1869 {
2056 /* finally, try bottom-up */ 1870 if (dc->rfh != NULL)
1871 {
1872 /* avoid hanging on to file handle longer than
1873 * necessary */
1874 GNUNET_DISK_file_close (dc->rfh);
1875 dc->rfh = NULL;
1876 }
1877 return; /* finished, status update was already done for us */
1878 }
1879 }
1880 if (dc->rfh != NULL)
1881 {
1882 /* finally, try bottom-up */
2057#if DEBUG_DOWNLOAD 1883#if DEBUG_DOWNLOAD
2058 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1884 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2059 "Trying bottom-up reconstruction of file `%s'\n", 1885 "Trying bottom-up reconstruction of file `%s'\n", dc->filename);
2060 dc->filename);
2061#endif 1886#endif
2062 dc->te = GNUNET_FS_tree_encoder_create (dc->h, 1887 dc->te = GNUNET_FS_tree_encoder_create (dc->h,
2063 dc->old_file_size, 1888 dc->old_file_size,
2064 dc, 1889 dc,
2065 &fh_reader, 1890 &fh_reader,
2066 &reconstruct_cb, 1891 &reconstruct_cb,
2067 NULL, 1892 NULL, &reconstruct_cont);
2068 &reconstruct_cont); 1893 dc->task = GNUNET_SCHEDULER_add_now (&get_next_block, dc);
2069 dc->task = GNUNET_SCHEDULER_add_now (&get_next_block, 1894 }
2070 dc);
2071 }
2072 else 1895 else
2073 { 1896 {
2074 /* simple, top-level download */ 1897 /* simple, top-level download */
2075 schedule_block_download (dc, 1898 schedule_block_download (dc, dc->top_request);
2076 dc->top_request); 1899 }
2077 }
2078 if (dc->top_request->state == BRS_DOWNLOAD_UP) 1900 if (dc->top_request->state == BRS_DOWNLOAD_UP)
2079 check_completed (dc); 1901 check_completed (dc);
2080} 1902}
@@ -2095,44 +1917,43 @@ GNUNET_FS_download_signal_suspend_ (void *cls)
2095 if (dc->top != NULL) 1917 if (dc->top != NULL)
2096 GNUNET_FS_end_top (dc->h, dc->top); 1918 GNUNET_FS_end_top (dc->h, dc->top);
2097 while (NULL != dc->child_head) 1919 while (NULL != dc->child_head)
2098 GNUNET_FS_download_signal_suspend_ (dc->child_head); 1920 GNUNET_FS_download_signal_suspend_ (dc->child_head);
2099 if (dc->search != NULL) 1921 if (dc->search != NULL)
2100 { 1922 {
2101 dc->search->download = NULL; 1923 dc->search->download = NULL;
2102 dc->search = NULL; 1924 dc->search = NULL;
2103 } 1925 }
2104 if (dc->job_queue != NULL) 1926 if (dc->job_queue != NULL)
2105 { 1927 {
2106 GNUNET_FS_dequeue_ (dc->job_queue); 1928 GNUNET_FS_dequeue_ (dc->job_queue);
2107 dc->job_queue = NULL; 1929 dc->job_queue = NULL;
2108 } 1930 }
2109 if (dc->parent != NULL) 1931 if (dc->parent != NULL)
2110 GNUNET_CONTAINER_DLL_remove (dc->parent->child_head, 1932 GNUNET_CONTAINER_DLL_remove (dc->parent->child_head,
2111 dc->parent->child_tail, 1933 dc->parent->child_tail, dc);
2112 dc);
2113 if (dc->task != GNUNET_SCHEDULER_NO_TASK) 1934 if (dc->task != GNUNET_SCHEDULER_NO_TASK)
2114 { 1935 {
2115 GNUNET_SCHEDULER_cancel (dc->task); 1936 GNUNET_SCHEDULER_cancel (dc->task);
2116 dc->task = GNUNET_SCHEDULER_NO_TASK; 1937 dc->task = GNUNET_SCHEDULER_NO_TASK;
2117 } 1938 }
2118 pi.status = GNUNET_FS_STATUS_DOWNLOAD_SUSPEND; 1939 pi.status = GNUNET_FS_STATUS_DOWNLOAD_SUSPEND;
2119 GNUNET_FS_download_make_status_ (&pi, dc); 1940 GNUNET_FS_download_make_status_ (&pi, dc);
2120 if (dc->te != NULL) 1941 if (dc->te != NULL)
2121 { 1942 {
2122 GNUNET_FS_tree_encoder_finish (dc->te, NULL, NULL); 1943 GNUNET_FS_tree_encoder_finish (dc->te, NULL, NULL);
2123 dc->te = NULL; 1944 dc->te = NULL;
2124 } 1945 }
2125 if (dc->rfh != NULL) 1946 if (dc->rfh != NULL)
2126 { 1947 {
2127 GNUNET_DISK_file_close (dc->rfh); 1948 GNUNET_DISK_file_close (dc->rfh);
2128 dc->rfh = NULL; 1949 dc->rfh = NULL;
2129 } 1950 }
2130 GNUNET_FS_free_download_request_ (dc->top_request); 1951 GNUNET_FS_free_download_request_ (dc->top_request);
2131 if (dc->active != NULL) 1952 if (dc->active != NULL)
2132 { 1953 {
2133 GNUNET_CONTAINER_multihashmap_destroy (dc->active); 1954 GNUNET_CONTAINER_multihashmap_destroy (dc->active);
2134 dc->active = NULL; 1955 dc->active = NULL;
2135 } 1956 }
2136 GNUNET_free_non_null (dc->filename); 1957 GNUNET_free_non_null (dc->filename);
2137 GNUNET_CONTAINER_meta_data_destroy (dc->meta); 1958 GNUNET_CONTAINER_meta_data_destroy (dc->meta);
2138 GNUNET_FS_uri_destroy (dc->uri); 1959 GNUNET_FS_uri_destroy (dc->uri);
@@ -2174,87 +1995,77 @@ GNUNET_FS_download_signal_suspend_ (void *cls)
2174 */ 1995 */
2175struct GNUNET_FS_DownloadContext * 1996struct GNUNET_FS_DownloadContext *
2176GNUNET_FS_download_start (struct GNUNET_FS_Handle *h, 1997GNUNET_FS_download_start (struct GNUNET_FS_Handle *h,
2177 const struct GNUNET_FS_Uri *uri, 1998 const struct GNUNET_FS_Uri *uri,
2178 const struct GNUNET_CONTAINER_MetaData *meta, 1999 const struct GNUNET_CONTAINER_MetaData *meta,
2179 const char *filename, 2000 const char *filename,
2180 const char *tempname, 2001 const char *tempname,
2181 uint64_t offset, 2002 uint64_t offset,
2182 uint64_t length, 2003 uint64_t length,
2183 uint32_t anonymity, 2004 uint32_t anonymity,
2184 enum GNUNET_FS_DownloadOptions options, 2005 enum GNUNET_FS_DownloadOptions options,
2185 void *cctx, 2006 void *cctx, struct GNUNET_FS_DownloadContext *parent)
2186 struct GNUNET_FS_DownloadContext *parent)
2187{ 2007{
2188 struct GNUNET_FS_DownloadContext *dc; 2008 struct GNUNET_FS_DownloadContext *dc;
2189 2009
2190 GNUNET_assert (GNUNET_FS_uri_test_chk (uri) || 2010 GNUNET_assert (GNUNET_FS_uri_test_chk (uri) || GNUNET_FS_uri_test_loc (uri));
2191 GNUNET_FS_uri_test_loc (uri) ); 2011
2192 2012 if ((offset + length < offset) ||
2193 if ( (offset + length < offset) || 2013 (offset + length > GNUNET_FS_uri_chk_get_file_size (uri)))
2194 (offset + length > GNUNET_FS_uri_chk_get_file_size (uri)) ) 2014 {
2195 { 2015 GNUNET_break (0);
2196 GNUNET_break (0); 2016 return NULL;
2197 return NULL; 2017 }
2198 }
2199#if DEBUG_DOWNLOAD 2018#if DEBUG_DOWNLOAD
2200 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2019 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2201 "Starting download `%s' of %llu bytes\n", 2020 "Starting download `%s' of %llu bytes\n",
2202 filename, 2021 filename, (unsigned long long) length);
2203 (unsigned long long) length);
2204#endif 2022#endif
2205 dc = GNUNET_malloc (sizeof(struct GNUNET_FS_DownloadContext)); 2023 dc = GNUNET_malloc (sizeof (struct GNUNET_FS_DownloadContext));
2206 dc->h = h; 2024 dc->h = h;
2207 dc->parent = parent; 2025 dc->parent = parent;
2208 if (parent != NULL) 2026 if (parent != NULL)
2209 { 2027 {
2210 GNUNET_CONTAINER_DLL_insert (parent->child_head, 2028 GNUNET_CONTAINER_DLL_insert (parent->child_head, parent->child_tail, dc);
2211 parent->child_tail, 2029 }
2212 dc);
2213 }
2214 dc->uri = GNUNET_FS_uri_dup (uri); 2030 dc->uri = GNUNET_FS_uri_dup (uri);
2215 dc->meta = GNUNET_CONTAINER_meta_data_duplicate (meta); 2031 dc->meta = GNUNET_CONTAINER_meta_data_duplicate (meta);
2216 dc->client_info = cctx; 2032 dc->client_info = cctx;
2217 dc->start_time = GNUNET_TIME_absolute_get (); 2033 dc->start_time = GNUNET_TIME_absolute_get ();
2218 if (NULL != filename) 2034 if (NULL != filename)
2219 { 2035 {
2220 dc->filename = GNUNET_strdup (filename); 2036 dc->filename = GNUNET_strdup (filename);
2221 if (GNUNET_YES == GNUNET_DISK_file_test (filename)) 2037 if (GNUNET_YES == GNUNET_DISK_file_test (filename))
2222 GNUNET_DISK_file_size (filename, 2038 GNUNET_DISK_file_size (filename, &dc->old_file_size, GNUNET_YES);
2223 &dc->old_file_size, 2039 }
2224 GNUNET_YES);
2225 }
2226 if (GNUNET_FS_uri_test_loc (dc->uri)) 2040 if (GNUNET_FS_uri_test_loc (dc->uri))
2227 GNUNET_assert (GNUNET_OK == 2041 GNUNET_assert (GNUNET_OK ==
2228 GNUNET_FS_uri_loc_get_peer_identity (dc->uri, 2042 GNUNET_FS_uri_loc_get_peer_identity (dc->uri, &dc->target));
2229 &dc->target));
2230 dc->offset = offset; 2043 dc->offset = offset;
2231 dc->length = length; 2044 dc->length = length;
2232 dc->anonymity = anonymity; 2045 dc->anonymity = anonymity;
2233 dc->options = options; 2046 dc->options = options;
2234 dc->active = GNUNET_CONTAINER_multihashmap_create (1 + 2 * (length / DBLOCK_SIZE)); 2047 dc->active =
2235 dc->treedepth = GNUNET_FS_compute_depth (GNUNET_FS_uri_chk_get_file_size(dc->uri)); 2048 GNUNET_CONTAINER_multihashmap_create (1 + 2 * (length / DBLOCK_SIZE));
2236 if ( (filename == NULL) && 2049 dc->treedepth =
2237 (is_recursive_download (dc) ) ) 2050 GNUNET_FS_compute_depth (GNUNET_FS_uri_chk_get_file_size (dc->uri));
2238 { 2051 if ((filename == NULL) && (is_recursive_download (dc)))
2239 if (tempname != NULL) 2052 {
2240 dc->temp_filename = GNUNET_strdup (tempname); 2053 if (tempname != NULL)
2241 else 2054 dc->temp_filename = GNUNET_strdup (tempname);
2242 dc->temp_filename = GNUNET_DISK_mktemp ("gnunet-directory-download-tmp"); 2055 else
2243 } 2056 dc->temp_filename = GNUNET_DISK_mktemp ("gnunet-directory-download-tmp");
2057 }
2244 2058
2245#if DEBUG_DOWNLOAD 2059#if DEBUG_DOWNLOAD
2246 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2060 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2247 "Download tree has depth %u\n", 2061 "Download tree has depth %u\n", dc->treedepth);
2248 dc->treedepth);
2249#endif 2062#endif
2250 if (parent == NULL) 2063 if (parent == NULL)
2251 { 2064 {
2252 dc->top = GNUNET_FS_make_top (dc->h, 2065 dc->top = GNUNET_FS_make_top (dc->h,
2253 &GNUNET_FS_download_signal_suspend_, 2066 &GNUNET_FS_download_signal_suspend_, dc);
2254 dc); 2067 }
2255 } 2068 dc->task = GNUNET_SCHEDULER_add_now (&GNUNET_FS_download_start_task_, dc);
2256 dc->task = GNUNET_SCHEDULER_add_now (&GNUNET_FS_download_start_task_,
2257 dc);
2258 return dc; 2069 return dc;
2259} 2070}
2260 2071
@@ -2295,85 +2106,79 @@ GNUNET_FS_download_start (struct GNUNET_FS_Handle *h,
2295 */ 2106 */
2296struct GNUNET_FS_DownloadContext * 2107struct GNUNET_FS_DownloadContext *
2297GNUNET_FS_download_start_from_search (struct GNUNET_FS_Handle *h, 2108GNUNET_FS_download_start_from_search (struct GNUNET_FS_Handle *h,
2298 struct GNUNET_FS_SearchResult *sr, 2109 struct GNUNET_FS_SearchResult *sr,
2299 const char *filename, 2110 const char *filename,
2300 const char *tempname, 2111 const char *tempname,
2301 uint64_t offset, 2112 uint64_t offset,
2302 uint64_t length, 2113 uint64_t length,
2303 uint32_t anonymity, 2114 uint32_t anonymity,
2304 enum GNUNET_FS_DownloadOptions options, 2115 enum GNUNET_FS_DownloadOptions options,
2305 void *cctx) 2116 void *cctx)
2306{ 2117{
2307 struct GNUNET_FS_DownloadContext *dc; 2118 struct GNUNET_FS_DownloadContext *dc;
2308 2119
2309 if ( (sr == NULL) || 2120 if ((sr == NULL) || (sr->download != NULL))
2310 (sr->download != NULL) ) 2121 {
2311 { 2122 GNUNET_break (0);
2312 GNUNET_break (0); 2123 return NULL;
2313 return NULL; 2124 }
2314 }
2315 GNUNET_assert (GNUNET_FS_uri_test_chk (sr->uri) || 2125 GNUNET_assert (GNUNET_FS_uri_test_chk (sr->uri) ||
2316 GNUNET_FS_uri_test_loc (sr->uri) ); 2126 GNUNET_FS_uri_test_loc (sr->uri));
2317 if ( (offset + length < offset) || 2127 if ((offset + length < offset) ||
2318 (offset + length > sr->uri->data.chk.file_length) ) 2128 (offset + length > sr->uri->data.chk.file_length))
2319 { 2129 {
2320 GNUNET_break (0); 2130 GNUNET_break (0);
2321 return NULL; 2131 return NULL;
2322 } 2132 }
2323#if DEBUG_DOWNLOAD 2133#if DEBUG_DOWNLOAD
2324 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2134 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2325 "Starting download `%s' of %llu bytes\n", 2135 "Starting download `%s' of %llu bytes\n",
2326 filename, 2136 filename, (unsigned long long) length);
2327 (unsigned long long) length);
2328#endif 2137#endif
2329 dc = GNUNET_malloc (sizeof(struct GNUNET_FS_DownloadContext)); 2138 dc = GNUNET_malloc (sizeof (struct GNUNET_FS_DownloadContext));
2330 dc->h = h; 2139 dc->h = h;
2331 dc->search = sr; 2140 dc->search = sr;
2332 sr->download = dc; 2141 sr->download = dc;
2333 if (sr->probe_ctx != NULL) 2142 if (sr->probe_ctx != NULL)
2334 { 2143 {
2335 GNUNET_FS_download_stop (sr->probe_ctx, GNUNET_YES); 2144 GNUNET_FS_download_stop (sr->probe_ctx, GNUNET_YES);
2336 sr->probe_ctx = NULL; 2145 sr->probe_ctx = NULL;
2337 } 2146 }
2338 dc->uri = GNUNET_FS_uri_dup (sr->uri); 2147 dc->uri = GNUNET_FS_uri_dup (sr->uri);
2339 dc->meta = GNUNET_CONTAINER_meta_data_duplicate (sr->meta); 2148 dc->meta = GNUNET_CONTAINER_meta_data_duplicate (sr->meta);
2340 dc->client_info = cctx; 2149 dc->client_info = cctx;
2341 dc->start_time = GNUNET_TIME_absolute_get (); 2150 dc->start_time = GNUNET_TIME_absolute_get ();
2342 if (NULL != filename) 2151 if (NULL != filename)
2343 { 2152 {
2344 dc->filename = GNUNET_strdup (filename); 2153 dc->filename = GNUNET_strdup (filename);
2345 if (GNUNET_YES == GNUNET_DISK_file_test (filename)) 2154 if (GNUNET_YES == GNUNET_DISK_file_test (filename))
2346 GNUNET_DISK_file_size (filename, 2155 GNUNET_DISK_file_size (filename, &dc->old_file_size, GNUNET_YES);
2347 &dc->old_file_size, 2156 }
2348 GNUNET_YES);
2349 }
2350 if (GNUNET_FS_uri_test_loc (dc->uri)) 2157 if (GNUNET_FS_uri_test_loc (dc->uri))
2351 GNUNET_assert (GNUNET_OK == 2158 GNUNET_assert (GNUNET_OK ==
2352 GNUNET_FS_uri_loc_get_peer_identity (dc->uri, 2159 GNUNET_FS_uri_loc_get_peer_identity (dc->uri, &dc->target));
2353 &dc->target));
2354 dc->offset = offset; 2160 dc->offset = offset;
2355 dc->length = length; 2161 dc->length = length;
2356 dc->anonymity = anonymity; 2162 dc->anonymity = anonymity;
2357 dc->options = options; 2163 dc->options = options;
2358 dc->active = GNUNET_CONTAINER_multihashmap_create (1 + 2 * (length / DBLOCK_SIZE)); 2164 dc->active =
2359 dc->treedepth = GNUNET_FS_compute_depth (GNUNET_ntohll(dc->uri->data.chk.file_length)); 2165 GNUNET_CONTAINER_multihashmap_create (1 + 2 * (length / DBLOCK_SIZE));
2360 if ( (filename == NULL) && 2166 dc->treedepth =
2361 (is_recursive_download (dc) ) ) 2167 GNUNET_FS_compute_depth (GNUNET_ntohll (dc->uri->data.chk.file_length));
2362 { 2168 if ((filename == NULL) && (is_recursive_download (dc)))
2363 if (tempname != NULL) 2169 {
2364 dc->temp_filename = GNUNET_strdup (tempname); 2170 if (tempname != NULL)
2365 else 2171 dc->temp_filename = GNUNET_strdup (tempname);
2366 dc->temp_filename = GNUNET_DISK_mktemp ("gnunet-directory-download-tmp"); 2172 else
2367 } 2173 dc->temp_filename = GNUNET_DISK_mktemp ("gnunet-directory-download-tmp");
2174 }
2368 2175
2369#if DEBUG_DOWNLOAD 2176#if DEBUG_DOWNLOAD
2370 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2177 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2371 "Download tree has depth %u\n", 2178 "Download tree has depth %u\n", dc->treedepth);
2372 dc->treedepth);
2373#endif 2179#endif
2374 dc->task = GNUNET_SCHEDULER_add_now (&GNUNET_FS_download_start_task_, 2180 dc->task = GNUNET_SCHEDULER_add_now (&GNUNET_FS_download_start_task_, dc);
2375 dc); 2181 return dc;
2376 return dc;
2377} 2182}
2378 2183
2379 2184
@@ -2388,11 +2193,12 @@ GNUNET_FS_download_start_downloading_ (struct GNUNET_FS_DownloadContext *dc)
2388 if (dc->completed == dc->length) 2193 if (dc->completed == dc->length)
2389 return; 2194 return;
2390 GNUNET_assert (dc->job_queue == NULL); 2195 GNUNET_assert (dc->job_queue == NULL);
2391 dc->job_queue = GNUNET_FS_queue_ (dc->h, 2196 dc->job_queue = GNUNET_FS_queue_ (dc->h,
2392 &activate_fs_download, 2197 &activate_fs_download,
2393 &deactivate_fs_download, 2198 &deactivate_fs_download,
2394 dc, 2199 dc,
2395 (dc->length + DBLOCK_SIZE-1) / DBLOCK_SIZE); 2200 (dc->length + DBLOCK_SIZE -
2201 1) / DBLOCK_SIZE);
2396} 2202}
2397 2203
2398 2204
@@ -2403,8 +2209,7 @@ GNUNET_FS_download_start_downloading_ (struct GNUNET_FS_DownloadContext *dc)
2403 * @param do_delete delete files of incomplete downloads 2209 * @param do_delete delete files of incomplete downloads
2404 */ 2210 */
2405void 2211void
2406GNUNET_FS_download_stop (struct GNUNET_FS_DownloadContext *dc, 2212GNUNET_FS_download_stop (struct GNUNET_FS_DownloadContext *dc, int do_delete)
2407 int do_delete)
2408{ 2213{
2409 struct GNUNET_FS_ProgressInfo pi; 2214 struct GNUNET_FS_ProgressInfo pi;
2410 int have_children; 2215 int have_children;
@@ -2414,77 +2219,71 @@ GNUNET_FS_download_stop (struct GNUNET_FS_DownloadContext *dc,
2414 2219
2415 2220
2416 if (dc->task != GNUNET_SCHEDULER_NO_TASK) 2221 if (dc->task != GNUNET_SCHEDULER_NO_TASK)
2417 { 2222 {
2418 GNUNET_SCHEDULER_cancel (dc->task); 2223 GNUNET_SCHEDULER_cancel (dc->task);
2419 dc->task = GNUNET_SCHEDULER_NO_TASK; 2224 dc->task = GNUNET_SCHEDULER_NO_TASK;
2420 } 2225 }
2421 if (dc->search != NULL) 2226 if (dc->search != NULL)
2422 { 2227 {
2423 dc->search->download = NULL; 2228 dc->search->download = NULL;
2424 dc->search = NULL; 2229 dc->search = NULL;
2425 } 2230 }
2426 if (dc->job_queue != NULL) 2231 if (dc->job_queue != NULL)
2427 { 2232 {
2428 GNUNET_FS_dequeue_ (dc->job_queue); 2233 GNUNET_FS_dequeue_ (dc->job_queue);
2429 dc->job_queue = NULL; 2234 dc->job_queue = NULL;
2430 } 2235 }
2431 if (dc->te != NULL) 2236 if (dc->te != NULL)
2432 { 2237 {
2433 GNUNET_FS_tree_encoder_finish (dc->te, NULL, NULL); 2238 GNUNET_FS_tree_encoder_finish (dc->te, NULL, NULL);
2434 dc->te = NULL; 2239 dc->te = NULL;
2435 } 2240 }
2436 have_children = (NULL != dc->child_head) ? GNUNET_YES : GNUNET_NO; 2241 have_children = (NULL != dc->child_head) ? GNUNET_YES : GNUNET_NO;
2437 while (NULL != dc->child_head) 2242 while (NULL != dc->child_head)
2438 GNUNET_FS_download_stop (dc->child_head, 2243 GNUNET_FS_download_stop (dc->child_head, do_delete);
2439 do_delete);
2440 if (dc->parent != NULL) 2244 if (dc->parent != NULL)
2441 GNUNET_CONTAINER_DLL_remove (dc->parent->child_head, 2245 GNUNET_CONTAINER_DLL_remove (dc->parent->child_head,
2442 dc->parent->child_tail, 2246 dc->parent->child_tail, dc);
2443 dc);
2444 if (dc->serialization != NULL) 2247 if (dc->serialization != NULL)
2445 GNUNET_FS_remove_sync_file_ (dc->h, 2248 GNUNET_FS_remove_sync_file_ (dc->h,
2446 ( (dc->parent != NULL) || (dc->search != NULL) ) 2249 ((dc->parent != NULL) || (dc->search != NULL))
2447 ? GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD 2250 ? GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD
2448 : GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD , 2251 : GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD,
2449 dc->serialization); 2252 dc->serialization);
2450 if ( (GNUNET_YES == have_children) && 2253 if ((GNUNET_YES == have_children) && (dc->parent == NULL))
2451 (dc->parent == NULL) ) 2254 GNUNET_FS_remove_sync_dir_ (dc->h,
2452 GNUNET_FS_remove_sync_dir_ (dc->h, 2255 (dc->search != NULL)
2453 (dc->search != NULL) 2256 ? GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD
2454 ? GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD 2257 : GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD,
2455 : GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD, 2258 dc->serialization);
2456 dc->serialization);
2457 pi.status = GNUNET_FS_STATUS_DOWNLOAD_STOPPED; 2259 pi.status = GNUNET_FS_STATUS_DOWNLOAD_STOPPED;
2458 GNUNET_FS_download_make_status_ (&pi, dc); 2260 GNUNET_FS_download_make_status_ (&pi, dc);
2459 GNUNET_FS_free_download_request_ (dc->top_request); 2261 GNUNET_FS_free_download_request_ (dc->top_request);
2460 dc->top_request = NULL; 2262 dc->top_request = NULL;
2461 if (dc->active != NULL) 2263 if (dc->active != NULL)
2462 { 2264 {
2463 GNUNET_CONTAINER_multihashmap_destroy (dc->active); 2265 GNUNET_CONTAINER_multihashmap_destroy (dc->active);
2464 dc->active = NULL; 2266 dc->active = NULL;
2465 } 2267 }
2466 if (dc->filename != NULL) 2268 if (dc->filename != NULL)
2269 {
2270 if ((dc->completed != dc->length) && (GNUNET_YES == do_delete))
2467 { 2271 {
2468 if ( (dc->completed != dc->length) && 2272 if (0 != UNLINK (dc->filename))
2469 (GNUNET_YES == do_delete) ) 2273 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
2470 { 2274 "unlink", dc->filename);
2471 if (0 != UNLINK (dc->filename))
2472 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
2473 "unlink",
2474 dc->filename);
2475 }
2476 GNUNET_free (dc->filename);
2477 } 2275 }
2276 GNUNET_free (dc->filename);
2277 }
2478 GNUNET_CONTAINER_meta_data_destroy (dc->meta); 2278 GNUNET_CONTAINER_meta_data_destroy (dc->meta);
2479 GNUNET_FS_uri_destroy (dc->uri); 2279 GNUNET_FS_uri_destroy (dc->uri);
2480 if (NULL != dc->temp_filename) 2280 if (NULL != dc->temp_filename)
2481 { 2281 {
2482 if (0 != UNLINK (dc->temp_filename)) 2282 if (0 != UNLINK (dc->temp_filename))
2483 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, 2283 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
2484 "unlink", 2284 "unlink", dc->temp_filename);
2485 dc->temp_filename); 2285 GNUNET_free (dc->temp_filename);
2486 GNUNET_free (dc->temp_filename); 2286 }
2487 }
2488 GNUNET_free_non_null (dc->serialization); 2287 GNUNET_free_non_null (dc->serialization);
2489 GNUNET_free (dc); 2288 GNUNET_free (dc);
2490} 2289}
diff --git a/src/fs/fs_file_information.c b/src/fs/fs_file_information.c
index 62ae285d8..bb323bbbc 100644
--- a/src/fs/fs_file_information.c
+++ b/src/fs/fs_file_information.c
@@ -52,22 +52,19 @@
52 * @return always 0 to continue extracting 52 * @return always 0 to continue extracting
53 */ 53 */
54static int 54static int
55add_to_md(void *cls, 55add_to_md (void *cls,
56 const char *plugin_name, 56 const char *plugin_name,
57 enum EXTRACTOR_MetaType type, 57 enum EXTRACTOR_MetaType type,
58 enum EXTRACTOR_MetaFormat format, 58 enum EXTRACTOR_MetaFormat format,
59 const char *data_mime_type, 59 const char *data_mime_type, const char *data, size_t data_len)
60 const char *data,
61 size_t data_len)
62{ 60{
63 struct GNUNET_CONTAINER_MetaData *md = cls; 61 struct GNUNET_CONTAINER_MetaData *md = cls;
62
64 (void) GNUNET_CONTAINER_meta_data_insert (md, 63 (void) GNUNET_CONTAINER_meta_data_insert (md,
65 plugin_name, 64 plugin_name,
66 type, 65 type,
67 format, 66 format,
68 data_mime_type, 67 data_mime_type, data, data_len);
69 data,
70 data_len);
71 return 0; 68 return 0;
72} 69}
73 70
@@ -80,9 +77,8 @@ add_to_md(void *cls,
80 */ 77 */
81int 78int
82GNUNET_FS_meta_data_extract_from_file (struct GNUNET_CONTAINER_MetaData 79GNUNET_FS_meta_data_extract_from_file (struct GNUNET_CONTAINER_MetaData
83 *md, const char *filename, 80 *md, const char *filename,
84 struct EXTRACTOR_PluginList * 81 struct EXTRACTOR_PluginList *extractors)
85 extractors)
86{ 82{
87 int old; 83 int old;
88 84
@@ -92,11 +88,7 @@ GNUNET_FS_meta_data_extract_from_file (struct GNUNET_CONTAINER_MetaData
92 return 0; 88 return 0;
93 old = GNUNET_CONTAINER_meta_data_iterate (md, NULL, NULL); 89 old = GNUNET_CONTAINER_meta_data_iterate (md, NULL, NULL);
94 GNUNET_assert (old >= 0); 90 GNUNET_assert (old >= 0);
95 EXTRACTOR_extract (extractors, 91 EXTRACTOR_extract (extractors, filename, NULL, 0, &add_to_md, md);
96 filename,
97 NULL, 0,
98 &add_to_md,
99 md);
100 return (GNUNET_CONTAINER_meta_data_iterate (md, NULL, NULL) - old); 92 return (GNUNET_CONTAINER_meta_data_iterate (md, NULL, NULL) - old);
101} 93}
102 94
@@ -137,44 +129,44 @@ GNUNET_FS_file_information_get_id (struct GNUNET_FS_FileInformation *s)
137 */ 129 */
138struct GNUNET_FS_FileInformation * 130struct GNUNET_FS_FileInformation *
139GNUNET_FS_file_information_create_from_file (struct GNUNET_FS_Handle *h, 131GNUNET_FS_file_information_create_from_file (struct GNUNET_FS_Handle *h,
140 void *client_info, 132 void *client_info,
141 const char *filename, 133 const char *filename,
142 const struct GNUNET_FS_Uri *keywords, 134 const struct GNUNET_FS_Uri
143 const struct GNUNET_CONTAINER_MetaData *meta, 135 *keywords,
144 int do_index, 136 const struct
145 const struct GNUNET_FS_BlockOptions *bo) 137 GNUNET_CONTAINER_MetaData *meta,
138 int do_index,
139 const struct GNUNET_FS_BlockOptions
140 *bo)
146{ 141{
147 struct FileInfo *fi; 142 struct FileInfo *fi;
148 struct stat sbuf; 143 struct stat sbuf;
149 struct GNUNET_FS_FileInformation *ret; 144 struct GNUNET_FS_FileInformation *ret;
150 const char *fn; 145 const char *fn;
151 const char *ss; 146 const char *ss;
147
152#if WINDOWS 148#if WINDOWS
153 char fn_conv[MAX_PATH]; 149 char fn_conv[MAX_PATH];
154#endif 150#endif
155 151
156 if (0 != STAT (filename, &sbuf)) 152 if (0 != STAT (filename, &sbuf))
157 { 153 {
158 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, 154 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "stat", filename);
159 "stat", 155 return NULL;
160 filename); 156 }
161 return NULL;
162 }
163 fi = GNUNET_FS_make_file_reader_context_ (filename); 157 fi = GNUNET_FS_make_file_reader_context_ (filename);
164 if (fi == NULL) 158 if (fi == NULL)
165 { 159 {
166 GNUNET_break (0); 160 GNUNET_break (0);
167 return NULL; 161 return NULL;
168 } 162 }
169 ret = GNUNET_FS_file_information_create_from_reader (h, 163 ret = GNUNET_FS_file_information_create_from_reader (h,
170 client_info, 164 client_info,
171 sbuf.st_size, 165 sbuf.st_size,
172 &GNUNET_FS_data_reader_file_, 166 &GNUNET_FS_data_reader_file_,
173 fi, 167 fi,
174 keywords, 168 keywords,
175 meta, 169 meta, do_index, bo);
176 do_index,
177 bo);
178 if (ret == NULL) 170 if (ret == NULL)
179 return NULL; 171 return NULL;
180 ret->h = h; 172 ret->h = h;
@@ -185,16 +177,13 @@ GNUNET_FS_file_information_create_from_file (struct GNUNET_FS_Handle *h,
185 plibc_conv_to_win_path (filename, fn_conv); 177 plibc_conv_to_win_path (filename, fn_conv);
186 fn = fn_conv; 178 fn = fn_conv;
187#endif 179#endif
188 while (NULL != (ss = strstr (fn, 180 while (NULL != (ss = strstr (fn, DIR_SEPARATOR_STR)))
189 DIR_SEPARATOR_STR)))
190 fn = ss + 1; 181 fn = ss + 1;
191 GNUNET_CONTAINER_meta_data_insert (ret->meta, 182 GNUNET_CONTAINER_meta_data_insert (ret->meta,
192 "<gnunet>", 183 "<gnunet>",
193 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME, 184 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME,
194 EXTRACTOR_METAFORMAT_C_STRING, 185 EXTRACTOR_METAFORMAT_C_STRING,
195 "text/plain", 186 "text/plain", fn, strlen (fn) + 1);
196 fn,
197 strlen (fn) + 1);
198 return ret; 187 return ret;
199} 188}
200 189
@@ -217,28 +206,29 @@ GNUNET_FS_file_information_create_from_file (struct GNUNET_FS_Handle *h,
217 */ 206 */
218struct GNUNET_FS_FileInformation * 207struct GNUNET_FS_FileInformation *
219GNUNET_FS_file_information_create_from_data (struct GNUNET_FS_Handle *h, 208GNUNET_FS_file_information_create_from_data (struct GNUNET_FS_Handle *h,
220 void *client_info, 209 void *client_info,
221 uint64_t length, 210 uint64_t length,
222 void *data, 211 void *data,
223 const struct GNUNET_FS_Uri *keywords, 212 const struct GNUNET_FS_Uri
224 const struct GNUNET_CONTAINER_MetaData *meta, 213 *keywords,
225 int do_index, 214 const struct
226 const struct GNUNET_FS_BlockOptions *bo) 215 GNUNET_CONTAINER_MetaData *meta,
216 int do_index,
217 const struct GNUNET_FS_BlockOptions
218 *bo)
227{ 219{
228 if (GNUNET_YES == do_index) 220 if (GNUNET_YES == do_index)
229 { 221 {
230 GNUNET_break (0); 222 GNUNET_break (0);
231 return NULL; 223 return NULL;
232 } 224 }
233 return GNUNET_FS_file_information_create_from_reader (h, 225 return GNUNET_FS_file_information_create_from_reader (h,
234 client_info, 226 client_info,
235 length, 227 length,
236 &GNUNET_FS_data_reader_copy_, 228 &GNUNET_FS_data_reader_copy_,
237 data, 229 data,
238 keywords, 230 keywords,
239 meta, 231 meta, do_index, bo);
240 do_index,
241 bo);
242} 232}
243 233
244 234
@@ -260,31 +250,33 @@ GNUNET_FS_file_information_create_from_data (struct GNUNET_FS_Handle *h,
260 */ 250 */
261struct GNUNET_FS_FileInformation * 251struct GNUNET_FS_FileInformation *
262GNUNET_FS_file_information_create_from_reader (struct GNUNET_FS_Handle *h, 252GNUNET_FS_file_information_create_from_reader (struct GNUNET_FS_Handle *h,
263 void *client_info, 253 void *client_info,
264 uint64_t length, 254 uint64_t length,
265 GNUNET_FS_DataReader reader, 255 GNUNET_FS_DataReader reader,
266 void *reader_cls, 256 void *reader_cls,
267 const struct GNUNET_FS_Uri *keywords, 257 const struct GNUNET_FS_Uri
268 const struct GNUNET_CONTAINER_MetaData *meta, 258 *keywords,
269 int do_index, 259 const struct
270 const struct GNUNET_FS_BlockOptions *bo) 260 GNUNET_CONTAINER_MetaData *meta,
261 int do_index,
262 const struct
263 GNUNET_FS_BlockOptions *bo)
271{ 264{
272 struct GNUNET_FS_FileInformation *ret; 265 struct GNUNET_FS_FileInformation *ret;
273 266
274 if ( (GNUNET_YES == do_index) && 267 if ((GNUNET_YES == do_index) && (reader != &GNUNET_FS_data_reader_file_))
275 (reader != &GNUNET_FS_data_reader_file_) ) 268 {
276 { 269 GNUNET_break (0);
277 GNUNET_break (0); 270 return NULL;
278 return NULL; 271 }
279 }
280 ret = GNUNET_malloc (sizeof (struct GNUNET_FS_FileInformation)); 272 ret = GNUNET_malloc (sizeof (struct GNUNET_FS_FileInformation));
281 ret->h = h; 273 ret->h = h;
282 ret->client_info = client_info; 274 ret->client_info = client_info;
283 ret->meta = GNUNET_CONTAINER_meta_data_duplicate (meta); 275 ret->meta = GNUNET_CONTAINER_meta_data_duplicate (meta);
284 if (ret->meta == NULL) 276 if (ret->meta == NULL)
285 ret->meta = GNUNET_CONTAINER_meta_data_create (); 277 ret->meta = GNUNET_CONTAINER_meta_data_create ();
286 ret->keywords = (keywords == NULL) ? NULL : GNUNET_FS_uri_dup (keywords); 278 ret->keywords = (keywords == NULL) ? NULL : GNUNET_FS_uri_dup (keywords);
287 ret->data.file.reader = reader; 279 ret->data.file.reader = reader;
288 ret->data.file.reader_cls = reader_cls; 280 ret->data.file.reader_cls = reader_cls;
289 ret->data.file.do_index = do_index; 281 ret->data.file.do_index = do_index;
290 ret->data.file.file_size = length; 282 ret->data.file.file_size = length;
@@ -296,7 +288,7 @@ GNUNET_FS_file_information_create_from_reader (struct GNUNET_FS_Handle *h,
296/** 288/**
297 * Closure for "dir_scan_cb". 289 * Closure for "dir_scan_cb".
298 */ 290 */
299struct DirScanCls 291struct DirScanCls
300{ 292{
301 /** 293 /**
302 * Metadata extractors to use. 294 * Metadata extractors to use.
@@ -305,14 +297,14 @@ struct DirScanCls
305 297
306 /** 298 /**
307 * Master context. 299 * Master context.
308 */ 300 */
309 struct GNUNET_FS_Handle *h; 301 struct GNUNET_FS_Handle *h;
310 302
311 /** 303 /**
312 * Function to call on each directory entry. 304 * Function to call on each directory entry.
313 */ 305 */
314 GNUNET_FS_FileProcessor proc; 306 GNUNET_FS_FileProcessor proc;
315 307
316 /** 308 /**
317 * Closure for proc. 309 * Closure for proc.
318 */ 310 */
@@ -331,7 +323,7 @@ struct DirScanCls
331 /** 323 /**
332 * Set to an error message (if any). 324 * Set to an error message (if any).
333 */ 325 */
334 char *emsg; 326 char *emsg;
335 327
336 /** 328 /**
337 * Block options. 329 * Block options.
@@ -340,7 +332,7 @@ struct DirScanCls
340 332
341 /** 333 /**
342 * Should files be indexed? 334 * Should files be indexed?
343 */ 335 */
344 int do_index; 336 int do_index;
345 337
346}; 338};
@@ -354,10 +346,9 @@ struct DirScanCls
354 * @return GNUNET_OK on success, GNUNET_SYSERR to abort 346 * @return GNUNET_OK on success, GNUNET_SYSERR to abort
355 */ 347 */
356static int 348static int
357dir_scan_cb (void *cls, 349dir_scan_cb (void *cls, const char *filename)
358 const char *filename)
359{ 350{
360 struct DirScanCls *dsc = cls; 351 struct DirScanCls *dsc = cls;
361 struct stat sbuf; 352 struct stat sbuf;
362 struct GNUNET_FS_FileInformation *fi; 353 struct GNUNET_FS_FileInformation *fi;
363 struct GNUNET_FS_Uri *ksk_uri; 354 struct GNUNET_FS_Uri *ksk_uri;
@@ -365,52 +356,44 @@ dir_scan_cb (void *cls,
365 struct GNUNET_CONTAINER_MetaData *meta; 356 struct GNUNET_CONTAINER_MetaData *meta;
366 357
367 if (0 != STAT (filename, &sbuf)) 358 if (0 != STAT (filename, &sbuf))
368 { 359 {
369 GNUNET_asprintf (&dsc->emsg, 360 GNUNET_asprintf (&dsc->emsg,
370 _("`%s' failed on file `%s': %s"), 361 _("`%s' failed on file `%s': %s"),
371 "stat", 362 "stat", filename, STRERROR (errno));
372 filename, 363 return GNUNET_SYSERR;
373 STRERROR (errno)); 364 }
374 return GNUNET_SYSERR;
375 }
376 if (S_ISDIR (sbuf.st_mode)) 365 if (S_ISDIR (sbuf.st_mode))
366 {
367 fi = GNUNET_FS_file_information_create_from_directory (dsc->h,
368 NULL,
369 filename,
370 dsc->scanner,
371 dsc->scanner_cls,
372 dsc->do_index,
373 dsc->bo, &dsc->emsg);
374 if (NULL == fi)
377 { 375 {
378 fi = GNUNET_FS_file_information_create_from_directory (dsc->h, 376 GNUNET_assert (NULL != dsc->emsg);
379 NULL, 377 return GNUNET_SYSERR;
380 filename,
381 dsc->scanner,
382 dsc->scanner_cls,
383 dsc->do_index,
384 dsc->bo,
385 &dsc->emsg);
386 if (NULL == fi)
387 {
388 GNUNET_assert (NULL != dsc->emsg);
389 return GNUNET_SYSERR;
390 }
391 } 378 }
379 }
392 else 380 else
393 { 381 {
394 meta = GNUNET_CONTAINER_meta_data_create (); 382 meta = GNUNET_CONTAINER_meta_data_create ();
395 GNUNET_FS_meta_data_extract_from_file (meta, 383 GNUNET_FS_meta_data_extract_from_file (meta, filename, dsc->extractors);
396 filename, 384 keywords = GNUNET_FS_uri_ksk_create_from_meta_data (meta);
397 dsc->extractors); 385 ksk_uri = GNUNET_FS_uri_ksk_canonicalize (keywords);
398 keywords = GNUNET_FS_uri_ksk_create_from_meta_data (meta); 386 fi = GNUNET_FS_file_information_create_from_file (dsc->h,
399 ksk_uri = GNUNET_FS_uri_ksk_canonicalize (keywords); 387 NULL,
400 fi = GNUNET_FS_file_information_create_from_file (dsc->h, 388 filename,
401 NULL, 389 ksk_uri,
402 filename, 390 meta,
403 ksk_uri, 391 dsc->do_index, dsc->bo);
404 meta, 392 GNUNET_CONTAINER_meta_data_destroy (meta);
405 dsc->do_index, 393 GNUNET_FS_uri_destroy (keywords);
406 dsc->bo); 394 GNUNET_FS_uri_destroy (ksk_uri);
407 GNUNET_CONTAINER_meta_data_destroy (meta); 395 }
408 GNUNET_FS_uri_destroy (keywords); 396 dsc->proc (dsc->proc_cls, filename, fi);
409 GNUNET_FS_uri_destroy (ksk_uri);
410 }
411 dsc->proc (dsc->proc_cls,
412 filename,
413 fi);
414 return GNUNET_OK; 397 return GNUNET_OK;
415} 398}
416 399
@@ -438,13 +421,12 @@ dir_scan_cb (void *cls,
438 */ 421 */
439int 422int
440GNUNET_FS_directory_scanner_default (void *cls, 423GNUNET_FS_directory_scanner_default (void *cls,
441 struct GNUNET_FS_Handle *h, 424 struct GNUNET_FS_Handle *h,
442 const char *dirname, 425 const char *dirname,
443 int do_index, 426 int do_index,
444 const struct GNUNET_FS_BlockOptions *bo, 427 const struct GNUNET_FS_BlockOptions *bo,
445 GNUNET_FS_FileProcessor proc, 428 GNUNET_FS_FileProcessor proc,
446 void *proc_cls, 429 void *proc_cls, char **emsg)
447 char **emsg)
448{ 430{
449 struct EXTRACTOR_PluginList *ex = cls; 431 struct EXTRACTOR_PluginList *ex = cls;
450 struct DirScanCls dsc; 432 struct DirScanCls dsc;
@@ -457,14 +439,12 @@ GNUNET_FS_directory_scanner_default (void *cls,
457 dsc.scanner_cls = cls; 439 dsc.scanner_cls = cls;
458 dsc.do_index = do_index; 440 dsc.do_index = do_index;
459 dsc.bo = bo; 441 dsc.bo = bo;
460 if (-1 == GNUNET_DISK_directory_scan (dirname, 442 if (-1 == GNUNET_DISK_directory_scan (dirname, &dir_scan_cb, &dsc))
461 &dir_scan_cb, 443 {
462 &dsc)) 444 GNUNET_assert (NULL != dsc.emsg);
463 { 445 *emsg = dsc.emsg;
464 GNUNET_assert (NULL != dsc.emsg); 446 return GNUNET_SYSERR;
465 *emsg = dsc.emsg; 447 }
466 return GNUNET_SYSERR;
467 }
468 return GNUNET_OK; 448 return GNUNET_OK;
469} 449}
470 450
@@ -491,9 +471,7 @@ struct EntryProcCls
491 * @param fi information for publishing the file 471 * @param fi information for publishing the file
492 */ 472 */
493static void 473static void
494dirproc (void *cls, 474dirproc (void *cls, const char *filename, struct GNUNET_FS_FileInformation *fi)
495 const char *filename,
496 struct GNUNET_FS_FileInformation *fi)
497{ 475{
498 struct EntryProcCls *dc = cls; 476 struct EntryProcCls *dc = cls;
499 477
@@ -526,13 +504,14 @@ dirproc (void *cls,
526 */ 504 */
527struct GNUNET_FS_FileInformation * 505struct GNUNET_FS_FileInformation *
528GNUNET_FS_file_information_create_from_directory (struct GNUNET_FS_Handle *h, 506GNUNET_FS_file_information_create_from_directory (struct GNUNET_FS_Handle *h,
529 void *client_info, 507 void *client_info,
530 const char *filename, 508 const char *filename,
531 GNUNET_FS_DirectoryScanner scanner, 509 GNUNET_FS_DirectoryScanner
532 void *scanner_cls, 510 scanner, void *scanner_cls,
533 int do_index, 511 int do_index,
534 const struct GNUNET_FS_BlockOptions *bo, 512 const struct
535 char **emsg) 513 GNUNET_FS_BlockOptions *bo,
514 char **emsg)
536{ 515{
537 struct GNUNET_FS_FileInformation *ret; 516 struct GNUNET_FS_FileInformation *ret;
538 struct EntryProcCls dc; 517 struct EntryProcCls dc;
@@ -545,43 +524,28 @@ GNUNET_FS_file_information_create_from_directory (struct GNUNET_FS_Handle *h,
545 dc.entries = NULL; 524 dc.entries = NULL;
546 meta = GNUNET_CONTAINER_meta_data_create (); 525 meta = GNUNET_CONTAINER_meta_data_create ();
547 GNUNET_FS_meta_data_make_directory (meta); 526 GNUNET_FS_meta_data_make_directory (meta);
548 scanner (scanner_cls, 527 scanner (scanner_cls, h, filename, do_index, bo, &dirproc, &dc, emsg);
549 h, 528 ksk = NULL; // FIXME...
550 filename,
551 do_index,
552 bo,
553 &dirproc,
554 &dc,
555 emsg);
556 ksk = NULL; // FIXME...
557 // FIXME: create meta! 529 // FIXME: create meta!
558 ret = GNUNET_FS_file_information_create_empty_directory (h, 530 ret = GNUNET_FS_file_information_create_empty_directory (h,
559 client_info, 531 client_info,
560 ksk, 532 ksk, meta, bo);
561 meta,
562 bo);
563 GNUNET_CONTAINER_meta_data_destroy (meta); 533 GNUNET_CONTAINER_meta_data_destroy (meta);
564 ret->data.dir.entries = dc.entries; 534 ret->data.dir.entries = dc.entries;
565 while (dc.entries != NULL) 535 while (dc.entries != NULL)
566 { 536 {
567 dc.entries->dir = ret; 537 dc.entries->dir = ret;
568 dc.entries = dc.entries->next; 538 dc.entries = dc.entries->next;
569 } 539 }
570 fn = filename; 540 fn = filename;
571 while ( (NULL != (ss = strstr (fn, 541 while ((NULL != (ss = strstr (fn, DIR_SEPARATOR_STR))) && (strlen (ss) > 1))
572 DIR_SEPARATOR_STR))) &&
573 (strlen (ss) > 1) )
574 fn = ss + 1; 542 fn = ss + 1;
575 GNUNET_asprintf (&dn, 543 GNUNET_asprintf (&dn, "%s/", fn);
576 "%s/",
577 fn);
578 GNUNET_CONTAINER_meta_data_insert (ret->meta, 544 GNUNET_CONTAINER_meta_data_insert (ret->meta,
579 "<gnunet>", 545 "<gnunet>",
580 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME, 546 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME,
581 EXTRACTOR_METAFORMAT_C_STRING, 547 EXTRACTOR_METAFORMAT_C_STRING,
582 "text/plain", 548 "text/plain", dn, strlen (dn) + 1);
583 dn,
584 strlen (dn) + 1);
585 GNUNET_free (dn); 549 GNUNET_free (dn);
586 ret->filename = GNUNET_strdup (filename); 550 ret->filename = GNUNET_strdup (filename);
587 return ret; 551 return ret;
@@ -595,7 +559,8 @@ GNUNET_FS_file_information_create_from_directory (struct GNUNET_FS_Handle *h,
595 * @return GNUNET_YES if so, GNUNET_NO if not 559 * @return GNUNET_YES if so, GNUNET_NO if not
596 */ 560 */
597int 561int
598GNUNET_FS_file_information_is_directory (const struct GNUNET_FS_FileInformation *ent) 562GNUNET_FS_file_information_is_directory (const struct GNUNET_FS_FileInformation
563 *ent)
599{ 564{
600 return ent->is_directory; 565 return ent->is_directory;
601} 566}
@@ -617,10 +582,14 @@ GNUNET_FS_file_information_is_directory (const struct GNUNET_FS_FileInformation
617 */ 582 */
618struct GNUNET_FS_FileInformation * 583struct GNUNET_FS_FileInformation *
619GNUNET_FS_file_information_create_empty_directory (struct GNUNET_FS_Handle *h, 584GNUNET_FS_file_information_create_empty_directory (struct GNUNET_FS_Handle *h,
620 void *client_info, 585 void *client_info,
621 const struct GNUNET_FS_Uri *keywords, 586 const struct GNUNET_FS_Uri
622 const struct GNUNET_CONTAINER_MetaData *meta, 587 *keywords,
623 const struct GNUNET_FS_BlockOptions *bo) 588 const struct
589 GNUNET_CONTAINER_MetaData
590 *meta,
591 const struct
592 GNUNET_FS_BlockOptions *bo)
624{ 593{
625 struct GNUNET_FS_FileInformation *ret; 594 struct GNUNET_FS_FileInformation *ret;
626 595
@@ -648,15 +617,13 @@ GNUNET_FS_file_information_create_empty_directory (struct GNUNET_FS_Handle *h,
648 */ 617 */
649int 618int
650GNUNET_FS_file_information_add (struct GNUNET_FS_FileInformation *dir, 619GNUNET_FS_file_information_add (struct GNUNET_FS_FileInformation *dir,
651 struct GNUNET_FS_FileInformation *ent) 620 struct GNUNET_FS_FileInformation *ent)
652{ 621{
653 if ( (ent->dir != NULL) || 622 if ((ent->dir != NULL) || (ent->next != NULL) || (!dir->is_directory))
654 (ent->next != NULL) || 623 {
655 (! dir->is_directory) ) 624 GNUNET_break (0);
656 { 625 return GNUNET_SYSERR;
657 GNUNET_break (0); 626 }
658 return GNUNET_SYSERR;
659 }
660 ent->dir = dir; 627 ent->dir = dir;
661 ent->next = dir->data.dir.entries; 628 ent->next = dir->data.dir.entries;
662 dir->data.dir.entries = ent; 629 dir->data.dir.entries = ent;
@@ -681,41 +648,37 @@ GNUNET_FS_file_information_add (struct GNUNET_FS_FileInformation *dir,
681 */ 648 */
682void 649void
683GNUNET_FS_file_information_inspect (struct GNUNET_FS_FileInformation *dir, 650GNUNET_FS_file_information_inspect (struct GNUNET_FS_FileInformation *dir,
684 GNUNET_FS_FileInformationProcessor proc, 651 GNUNET_FS_FileInformationProcessor proc,
685 void *proc_cls) 652 void *proc_cls)
686{ 653{
687 struct GNUNET_FS_FileInformation *pos; 654 struct GNUNET_FS_FileInformation *pos;
688 int no; 655 int no;
689 656
690 no = GNUNET_NO; 657 no = GNUNET_NO;
691 if (GNUNET_OK != 658 if (GNUNET_OK !=
692 proc (proc_cls, 659 proc (proc_cls,
693 dir, 660 dir,
694 (dir->is_directory) ? dir->data.dir.dir_size : dir->data.file.file_size, 661 (dir->is_directory) ? dir->data.dir.dir_size : dir->data.
695 dir->meta, 662 file.file_size, dir->meta, &dir->keywords, &dir->bo,
696 &dir->keywords, 663 (dir->is_directory) ? &no : &dir->data.file.do_index,
697 &dir->bo, 664 &dir->client_info))
698 (dir->is_directory) ? &no : &dir->data.file.do_index,
699 &dir->client_info))
700 return; 665 return;
701 if (! dir->is_directory) 666 if (!dir->is_directory)
702 return; 667 return;
703 pos = dir->data.dir.entries; 668 pos = dir->data.dir.entries;
704 while (pos != NULL) 669 while (pos != NULL)
705 { 670 {
706 no = GNUNET_NO; 671 no = GNUNET_NO;
707 if (GNUNET_OK != 672 if (GNUNET_OK !=
708 proc (proc_cls, 673 proc (proc_cls,
709 pos, 674 pos,
710 (pos->is_directory) ? pos->data.dir.dir_size : pos->data.file.file_size, 675 (pos->is_directory) ? pos->data.dir.dir_size : pos->data.
711 pos->meta, 676 file.file_size, pos->meta, &pos->keywords, &pos->bo,
712 &pos->keywords, 677 (dir->is_directory) ? &no : &dir->data.file.do_index,
713 &pos->bo, 678 &pos->client_info))
714 (dir->is_directory) ? &no : &dir->data.file.do_index, 679 break;
715 &pos->client_info)) 680 pos = pos->next;
716 break; 681 }
717 pos = pos->next;
718 }
719} 682}
720 683
721 684
@@ -731,70 +694,60 @@ GNUNET_FS_file_information_inspect (struct GNUNET_FS_FileInformation *dir,
731 */ 694 */
732void 695void
733GNUNET_FS_file_information_destroy (struct GNUNET_FS_FileInformation *fi, 696GNUNET_FS_file_information_destroy (struct GNUNET_FS_FileInformation *fi,
734 GNUNET_FS_FileInformationProcessor cleaner, 697 GNUNET_FS_FileInformationProcessor cleaner,
735 void *cleaner_cls) 698 void *cleaner_cls)
736{ 699{
737 struct GNUNET_FS_FileInformation *pos; 700 struct GNUNET_FS_FileInformation *pos;
738 int no; 701 int no;
739 702
740 no = GNUNET_NO; 703 no = GNUNET_NO;
741 if (fi->is_directory) 704 if (fi->is_directory)
705 {
706 /* clean up directory */
707 while (NULL != (pos = fi->data.dir.entries))
742 { 708 {
743 /* clean up directory */ 709 fi->data.dir.entries = pos->next;
744 while (NULL != (pos = fi->data.dir.entries)) 710 GNUNET_FS_file_information_destroy (pos, cleaner, cleaner_cls);
745 {
746 fi->data.dir.entries = pos->next;
747 GNUNET_FS_file_information_destroy (pos, cleaner, cleaner_cls);
748 }
749 /* clean up client-info */
750 if (NULL != cleaner)
751 cleaner (cleaner_cls,
752 fi,
753 fi->data.dir.dir_size,
754 fi->meta,
755 &fi->keywords,
756 &fi->bo,
757 &no,
758 &fi->client_info);
759 GNUNET_free_non_null (fi->data.dir.dir_data);
760 } 711 }
712 /* clean up client-info */
713 if (NULL != cleaner)
714 cleaner (cleaner_cls,
715 fi,
716 fi->data.dir.dir_size,
717 fi->meta, &fi->keywords, &fi->bo, &no, &fi->client_info);
718 GNUNET_free_non_null (fi->data.dir.dir_data);
719 }
761 else 720 else
762 { 721 {
763 /* call clean-up function of the reader */ 722 /* call clean-up function of the reader */
764 if (fi->data.file.reader != NULL) 723 if (fi->data.file.reader != NULL)
765 fi->data.file.reader (fi->data.file.reader_cls, 0, 0, 724 fi->data.file.reader (fi->data.file.reader_cls, 0, 0, NULL, NULL);
766 NULL, NULL); 725 /* clean up client-info */
767 /* clean up client-info */ 726 if (NULL != cleaner)
768 if (NULL != cleaner) 727 cleaner (cleaner_cls,
769 cleaner (cleaner_cls, 728 fi,
770 fi, 729 fi->data.file.file_size,
771 fi->data.file.file_size, 730 fi->meta,
772 fi->meta, 731 &fi->keywords,
773 &fi->keywords, 732 &fi->bo, &fi->data.file.do_index, &fi->client_info);
774 &fi->bo, 733 }
775 &fi->data.file.do_index,
776 &fi->client_info);
777 }
778 GNUNET_free_non_null (fi->filename); 734 GNUNET_free_non_null (fi->filename);
779 GNUNET_free_non_null (fi->emsg); 735 GNUNET_free_non_null (fi->emsg);
780 GNUNET_free_non_null (fi->chk_uri); 736 GNUNET_free_non_null (fi->chk_uri);
781 /* clean up serialization */ 737 /* clean up serialization */
782 if ( (NULL != fi->serialization) && 738 if ((NULL != fi->serialization) && (0 != UNLINK (fi->serialization)))
783 (0 != UNLINK (fi->serialization)) )
784 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, 739 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
785 "unlink", 740 "unlink", fi->serialization);
786 fi->serialization);
787 if (NULL != fi->keywords) 741 if (NULL != fi->keywords)
788 GNUNET_FS_uri_destroy (fi->keywords); 742 GNUNET_FS_uri_destroy (fi->keywords);
789 if (NULL != fi->meta) 743 if (NULL != fi->meta)
790 GNUNET_CONTAINER_meta_data_destroy (fi->meta); 744 GNUNET_CONTAINER_meta_data_destroy (fi->meta);
791 GNUNET_free_non_null (fi->serialization); 745 GNUNET_free_non_null (fi->serialization);
792 if (fi->te != NULL) 746 if (fi->te != NULL)
793 { 747 {
794 GNUNET_FS_tree_encoder_finish (fi->te, 748 GNUNET_FS_tree_encoder_finish (fi->te, NULL, NULL);
795 NULL, NULL); 749 fi->te = NULL;
796 fi->te = NULL; 750 }
797 }
798 GNUNET_free (fi); 751 GNUNET_free (fi);
799} 752}
800 753
diff --git a/src/fs/fs_getopt.c b/src/fs/fs_getopt.c
index 0db7237f7..6c54fd69b 100644
--- a/src/fs/fs_getopt.c
+++ b/src/fs/fs_getopt.c
@@ -42,10 +42,9 @@
42 * @return GNUNET_OK on success 42 * @return GNUNET_OK on success
43 */ 43 */
44int 44int
45GNUNET_FS_getopt_set_keywords (struct GNUNET_GETOPT_CommandLineProcessorContext* ctx, 45GNUNET_FS_getopt_set_keywords (struct GNUNET_GETOPT_CommandLineProcessorContext
46 void *scls, 46 *ctx, void *scls, const char *option,
47 const char *option, 47 const char *value)
48 const char *value)
49{ 48{
50 struct GNUNET_FS_Uri **uri = scls; 49 struct GNUNET_FS_Uri **uri = scls;
51 struct GNUNET_FS_Uri *u = *uri; 50 struct GNUNET_FS_Uri *u = *uri;
@@ -53,60 +52,58 @@ GNUNET_FS_getopt_set_keywords (struct GNUNET_GETOPT_CommandLineProcessorContext*
53 size_t slen; 52 size_t slen;
54 53
55 if (u == NULL) 54 if (u == NULL)
56 { 55 {
57 u = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri)); 56 u = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri));
58 *uri = u; 57 *uri = u;
59 u->type = ksk; 58 u->type = ksk;
60 u->data.ksk.keywordCount = 0; 59 u->data.ksk.keywordCount = 0;
61 u->data.ksk.keywords = NULL; 60 u->data.ksk.keywords = NULL;
62 } 61 }
63 else 62 else
64 { 63 {
65 GNUNET_assert (u->type == ksk); 64 GNUNET_assert (u->type == ksk);
66 } 65 }
67 slen = strlen (value); 66 slen = strlen (value);
68 if (slen == 0) 67 if (slen == 0)
69 return GNUNET_SYSERR; /* cannot be empty */ 68 return GNUNET_SYSERR; /* cannot be empty */
70 if (value[0] == '+') 69 if (value[0] == '+')
70 {
71 /* simply preserve the "mandatory" flag */
72 if (slen < 2)
73 return GNUNET_SYSERR; /* empty keywords not allowed */
74 if ((value[1] == '"') && (slen > 3) && (value[slen - 1] == '"'))
71 { 75 {
72 /* simply preserve the "mandatory" flag */ 76 /* remove the quotes, keep the '+' */
73 if (slen < 2) 77 val = GNUNET_malloc (slen - 1);
74 return GNUNET_SYSERR; /* empty keywords not allowed */ 78 val[0] = '+';
75 if ((value[1] == '"') && (slen > 3) && (value[slen - 1] == '"')) 79 memcpy (&val[1], &value[2], slen - 3);
76 { 80 val[slen - 2] = '\0';
77 /* remove the quotes, keep the '+' */
78 val = GNUNET_malloc (slen - 1);
79 val[0] = '+';
80 memcpy (&val[1], &value[2], slen - 3);
81 val[slen - 2] = '\0';
82 }
83 else
84 {
85 /* no quotes, just keep the '+' */
86 val = GNUNET_strdup (value);
87 }
88 } 81 }
82 else
83 {
84 /* no quotes, just keep the '+' */
85 val = GNUNET_strdup (value);
86 }
87 }
89 else 88 else
89 {
90 if ((value[0] == '"') && (slen > 2) && (value[slen - 1] == '"'))
91 {
92 /* remove the quotes, add a space */
93 val = GNUNET_malloc (slen);
94 val[0] = ' ';
95 memcpy (&val[1], &value[1], slen - 2);
96 val[slen - 1] = '\0';
97 }
98 else
90 { 99 {
91 if ((value[0] == '"') && (slen > 2) && (value[slen - 1] == '"')) 100 /* add a space to indicate "not mandatory" */
92 { 101 val = GNUNET_malloc (slen + 2);
93 /* remove the quotes, add a space */ 102 strcpy (val, " ");
94 val = GNUNET_malloc (slen); 103 strcat (val, value);
95 val[0] = ' ';
96 memcpy (&val[1], &value[1], slen - 2);
97 val[slen - 1] = '\0';
98 }
99 else
100 {
101 /* add a space to indicate "not mandatory" */
102 val = GNUNET_malloc (slen + 2);
103 strcpy (val, " ");
104 strcat (val, value);
105 }
106 } 104 }
107 GNUNET_array_append (u->data.ksk.keywords, 105 }
108 u->data.ksk.keywordCount, 106 GNUNET_array_append (u->data.ksk.keywords, u->data.ksk.keywordCount, val);
109 val);
110 return GNUNET_OK; 107 return GNUNET_OK;
111} 108}
112 109
@@ -124,11 +121,9 @@ GNUNET_FS_getopt_set_keywords (struct GNUNET_GETOPT_CommandLineProcessorContext*
124 * @return GNUNET_OK on success 121 * @return GNUNET_OK on success
125 */ 122 */
126int 123int
127GNUNET_FS_getopt_set_metadata (struct GNUNET_GETOPT_CommandLineProcessorContext* ctx, 124GNUNET_FS_getopt_set_metadata (struct GNUNET_GETOPT_CommandLineProcessorContext
128 void *scls, 125 *ctx, void *scls, const char *option,
129 const char *option, 126 const char *value)
130 const char *value)
131
132{ 127{
133 struct GNUNET_CONTAINER_MetaData **mm = scls; 128 struct GNUNET_CONTAINER_MetaData **mm = scls;
134 enum EXTRACTOR_MetaType type; 129 enum EXTRACTOR_MetaType type;
@@ -139,69 +134,68 @@ GNUNET_FS_getopt_set_metadata (struct GNUNET_GETOPT_CommandLineProcessorContext*
139 134
140 meta = *mm; 135 meta = *mm;
141 if (meta == NULL) 136 if (meta == NULL)
142 { 137 {
143 meta = GNUNET_CONTAINER_meta_data_create (); 138 meta = GNUNET_CONTAINER_meta_data_create ();
144 *mm = meta; 139 *mm = meta;
145 } 140 }
146 141
147#if ENABLE_NLS 142#if ENABLE_NLS
148 tmp = GNUNET_STRINGS_to_utf8 (value, strlen (value), 143 tmp = GNUNET_STRINGS_to_utf8 (value, strlen (value), nl_langinfo (CODESET));
149 nl_langinfo (CODESET));
150#else 144#else
151 tmp = GNUNET_STRINGS_to_utf8 (value, strlen (value), 145 tmp = GNUNET_STRINGS_to_utf8 (value, strlen (value), "utf-8");
152 "utf-8");
153#endif 146#endif
154 type = EXTRACTOR_metatype_get_max (); 147 type = EXTRACTOR_metatype_get_max ();
155 while (type > 0) 148 while (type > 0)
149 {
150 type--;
151 typename = EXTRACTOR_metatype_to_string (type);
152 typename_i18n = dgettext (LIBEXTRACTOR_GETTEXT_DOMAIN, typename);
153 if ((strlen (tmp) >= strlen (typename) + 1) &&
154 (tmp[strlen (typename)] == ':') &&
155 (0 == strncmp (typename, tmp, strlen (typename))))
156 { 156 {
157 type--; 157 GNUNET_CONTAINER_meta_data_insert (meta,
158 typename = EXTRACTOR_metatype_to_string (type); 158 "<gnunet>",
159 typename_i18n = dgettext (LIBEXTRACTOR_GETTEXT_DOMAIN, typename); 159 type,
160 if ((strlen (tmp) >= strlen (typename) + 1) && 160 EXTRACTOR_METAFORMAT_UTF8,
161 (tmp[strlen (typename)] == ':') && 161 "text/plain",
162 (0 == strncmp (typename, tmp, strlen (typename)))) 162 &tmp[strlen (typename) + 1],
163 { 163 strlen (&tmp[strlen (typename) + 1]) +
164 GNUNET_CONTAINER_meta_data_insert (meta, 164 1);
165 "<gnunet>", 165 GNUNET_free (tmp);
166 type, 166 tmp = NULL;
167 EXTRACTOR_METAFORMAT_UTF8, 167 break;
168 "text/plain",
169 &tmp[strlen (typename) + 1],
170 strlen (&tmp[strlen (typename) + 1])+1);
171 GNUNET_free (tmp);
172 tmp = NULL;
173 break;
174 }
175 if ((strlen (tmp) >= strlen (typename_i18n) + 1) &&
176 (tmp[strlen (typename_i18n)] == ':') &&
177 (0 == strncmp (typename_i18n, tmp, strlen (typename_i18n))))
178 {
179 GNUNET_CONTAINER_meta_data_insert (meta,
180 "<gnunet>",
181 type,
182 EXTRACTOR_METAFORMAT_UTF8,
183 "text/plain",
184 &tmp[strlen (typename_i18n) + 1],
185 strlen (&tmp[strlen (typename_i18n) + 1]) + 1);
186 GNUNET_free (tmp);
187 tmp = NULL;
188 break;
189 }
190 } 168 }
191 if (tmp != NULL) 169 if ((strlen (tmp) >= strlen (typename_i18n) + 1) &&
170 (tmp[strlen (typename_i18n)] == ':') &&
171 (0 == strncmp (typename_i18n, tmp, strlen (typename_i18n))))
192 { 172 {
193 GNUNET_CONTAINER_meta_data_insert (meta, 173 GNUNET_CONTAINER_meta_data_insert (meta,
194 "<gnunet>", 174 "<gnunet>",
195 EXTRACTOR_METATYPE_UNKNOWN, 175 type,
196 EXTRACTOR_METAFORMAT_UTF8, 176 EXTRACTOR_METAFORMAT_UTF8,
197 "text/plain", 177 "text/plain",
198 tmp, 178 &tmp[strlen (typename_i18n) + 1],
199 strlen(tmp) + 1); 179 strlen (&tmp
180 [strlen (typename_i18n) + 1]) +
181 1);
200 GNUNET_free (tmp); 182 GNUNET_free (tmp);
201 printf (_ 183 tmp = NULL;
202 ("Unknown metadata type in metadata option `%s'. Using metadata type `unknown' instead.\n"), 184 break;
203 value);
204 } 185 }
186 }
187 if (tmp != NULL)
188 {
189 GNUNET_CONTAINER_meta_data_insert (meta,
190 "<gnunet>",
191 EXTRACTOR_METATYPE_UNKNOWN,
192 EXTRACTOR_METAFORMAT_UTF8,
193 "text/plain", tmp, strlen (tmp) + 1);
194 GNUNET_free (tmp);
195 printf (_
196 ("Unknown metadata type in metadata option `%s'. Using metadata type `unknown' instead.\n"),
197 value);
198 }
205 return GNUNET_OK; 199 return GNUNET_OK;
206} 200}
207 201
diff --git a/src/fs/fs_list_indexed.c b/src/fs/fs_list_indexed.c
index fec127763..1eb290f11 100644
--- a/src/fs/fs_list_indexed.c
+++ b/src/fs/fs_list_indexed.c
@@ -76,8 +76,7 @@ struct GetIndexedContext
76 * @param msg message with indexing information 76 * @param msg message with indexing information
77 */ 77 */
78static void 78static void
79handle_index_info (void *cls, 79handle_index_info (void *cls, const struct GNUNET_MessageHeader *msg)
80 const struct GNUNET_MessageHeader *msg)
81{ 80{
82 struct GetIndexedContext *gic = cls; 81 struct GetIndexedContext *gic = cls;
83 const struct IndexInfoMessage *iim; 82 const struct IndexInfoMessage *iim;
@@ -85,64 +84,58 @@ handle_index_info (void *cls,
85 const char *filename; 84 const char *filename;
86 85
87 if (NULL == msg) 86 if (NULL == msg)
88 { 87 {
89 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 88 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
90 _("Failed to receive response for `%s' request from `%s' service.\n"), 89 _
91 "GET_INDEXED", 90 ("Failed to receive response for `%s' request from `%s' service.\n"),
92 "fs"); 91 "GET_INDEXED", "fs");
93 GNUNET_SCHEDULER_add_continuation (gic->cont, 92 GNUNET_SCHEDULER_add_continuation (gic->cont, gic->cont_cls,
94 gic->cont_cls, 93 GNUNET_SCHEDULER_REASON_TIMEOUT);
95 GNUNET_SCHEDULER_REASON_TIMEOUT); 94 GNUNET_CLIENT_disconnect (gic->client, GNUNET_NO);
96 GNUNET_CLIENT_disconnect (gic->client, GNUNET_NO); 95 GNUNET_free (gic);
97 GNUNET_free (gic); 96 return;
98 return; 97 }
99 }
100 if (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_END) 98 if (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_END)
101 { 99 {
102 /* normal end-of-list */ 100 /* normal end-of-list */
103 GNUNET_SCHEDULER_add_continuation (gic->cont, 101 GNUNET_SCHEDULER_add_continuation (gic->cont,
104 gic->cont_cls, 102 gic->cont_cls,
105 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 103 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
106 GNUNET_CLIENT_disconnect (gic->client, GNUNET_NO); 104 GNUNET_CLIENT_disconnect (gic->client, GNUNET_NO);
107 GNUNET_free (gic); 105 GNUNET_free (gic);
108 return; 106 return;
109 } 107 }
110 msize = ntohs (msg->size); 108 msize = ntohs (msg->size);
111 iim = (const struct IndexInfoMessage*) msg; 109 iim = (const struct IndexInfoMessage *) msg;
112 filename = (const char*) &iim[1]; 110 filename = (const char *) &iim[1];
113 if ( (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY) || 111 if ((ntohs (msg->type) != GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY) ||
114 (msize <= sizeof (struct IndexInfoMessage)) || 112 (msize <= sizeof (struct IndexInfoMessage)) ||
115 (filename[msize-sizeof (struct IndexInfoMessage) -1] != '\0') ) 113 (filename[msize - sizeof (struct IndexInfoMessage) - 1] != '\0'))
116 { 114 {
117 /* bogus reply */ 115 /* bogus reply */
118 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 116 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
119 _("Failed to receive valid response for `%s' request from `%s' service.\n"), 117 _
120 "GET_INDEXED", 118 ("Failed to receive valid response for `%s' request from `%s' service.\n"),
121 "fs"); 119 "GET_INDEXED", "fs");
122 GNUNET_SCHEDULER_add_continuation (gic->cont, 120 GNUNET_SCHEDULER_add_continuation (gic->cont, gic->cont_cls,
123 gic->cont_cls, 121 GNUNET_SCHEDULER_REASON_TIMEOUT);
124 GNUNET_SCHEDULER_REASON_TIMEOUT); 122 GNUNET_CLIENT_disconnect (gic->client, GNUNET_NO);
125 GNUNET_CLIENT_disconnect (gic->client, GNUNET_NO); 123 GNUNET_free (gic);
126 GNUNET_free (gic); 124 return;
127 return; 125 }
128 } 126 if (GNUNET_OK != gic->iterator (gic->iterator_cls, filename, &iim->file_id))
129 if (GNUNET_OK != 127 {
130 gic->iterator (gic->iterator_cls, 128 GNUNET_SCHEDULER_add_continuation (gic->cont,
131 filename, 129 gic->cont_cls,
132 &iim->file_id)) 130 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
133 { 131 GNUNET_CLIENT_disconnect (gic->client, GNUNET_NO);
134 GNUNET_SCHEDULER_add_continuation (gic->cont, 132 GNUNET_free (gic);
135 gic->cont_cls, 133 return;
136 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 134 }
137 GNUNET_CLIENT_disconnect (gic->client, GNUNET_NO);
138 GNUNET_free (gic);
139 return;
140 }
141 /* get more */ 135 /* get more */
142 GNUNET_CLIENT_receive (gic->client, 136 GNUNET_CLIENT_receive (gic->client,
143 &handle_index_info, 137 &handle_index_info,
144 gic, 138 gic, GNUNET_CONSTANTS_SERVICE_TIMEOUT);
145 GNUNET_CONSTANTS_SERVICE_TIMEOUT);
146} 139}
147 140
148 141
@@ -157,29 +150,26 @@ handle_index_info (void *cls,
157 * error) or "PREREQ_DONE" (on success) 150 * error) or "PREREQ_DONE" (on success)
158 * @param cont_cls closure for cont 151 * @param cont_cls closure for cont
159 */ 152 */
160void 153void
161GNUNET_FS_get_indexed_files (struct GNUNET_FS_Handle *h, 154GNUNET_FS_get_indexed_files (struct GNUNET_FS_Handle *h,
162 GNUNET_FS_IndexedFileProcessor iterator, 155 GNUNET_FS_IndexedFileProcessor iterator,
163 void *iterator_cls, 156 void *iterator_cls,
164 GNUNET_SCHEDULER_Task cont, 157 GNUNET_SCHEDULER_Task cont, void *cont_cls)
165 void *cont_cls)
166{ 158{
167 struct GNUNET_CLIENT_Connection *client; 159 struct GNUNET_CLIENT_Connection *client;
168 struct GetIndexedContext *gic; 160 struct GetIndexedContext *gic;
169 struct GNUNET_MessageHeader msg; 161 struct GNUNET_MessageHeader msg;
170 162
171 client = GNUNET_CLIENT_connect ("fs", 163 client = GNUNET_CLIENT_connect ("fs", h->cfg);
172 h->cfg);
173 if (NULL == client) 164 if (NULL == client)
174 { 165 {
175 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 166 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
176 _("Failed to not connect to `%s' service.\n"), 167 _("Failed to not connect to `%s' service.\n"), "fs");
177 "fs"); 168 GNUNET_SCHEDULER_add_continuation (cont,
178 GNUNET_SCHEDULER_add_continuation (cont, 169 cont_cls,
179 cont_cls, 170 GNUNET_SCHEDULER_REASON_TIMEOUT);
180 GNUNET_SCHEDULER_REASON_TIMEOUT); 171 return;
181 return; 172 }
182 }
183 173
184 gic = GNUNET_malloc (sizeof (struct GetIndexedContext)); 174 gic = GNUNET_malloc (sizeof (struct GetIndexedContext));
185 gic->h = h; 175 gic->h = h;
@@ -191,12 +181,12 @@ GNUNET_FS_get_indexed_files (struct GNUNET_FS_Handle *h,
191 msg.size = htons (sizeof (struct GNUNET_MessageHeader)); 181 msg.size = htons (sizeof (struct GNUNET_MessageHeader));
192 msg.type = htons (GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_GET); 182 msg.type = htons (GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_GET);
193 GNUNET_assert (GNUNET_OK == 183 GNUNET_assert (GNUNET_OK ==
194 GNUNET_CLIENT_transmit_and_get_response (client, 184 GNUNET_CLIENT_transmit_and_get_response (client,
195 &msg, 185 &msg,
196 GNUNET_CONSTANTS_SERVICE_TIMEOUT, 186 GNUNET_CONSTANTS_SERVICE_TIMEOUT,
197 GNUNET_YES, 187 GNUNET_YES,
198 &handle_index_info, 188 &handle_index_info,
199 gic)); 189 gic));
200} 190}
201 191
202/* end of fs_list_indexed.c */ 192/* end of fs_list_indexed.c */
diff --git a/src/fs/fs_misc.c b/src/fs/fs_misc.c
index 73dcd4e36..9fa86a5c4 100644
--- a/src/fs/fs_misc.c
+++ b/src/fs/fs_misc.c
@@ -35,7 +35,8 @@
35 * @return NULL if meta data is useless for suggesting a filename 35 * @return NULL if meta data is useless for suggesting a filename
36 */ 36 */
37char * 37char *
38GNUNET_FS_meta_data_suggest_filename (const struct GNUNET_CONTAINER_MetaData *md) 38GNUNET_FS_meta_data_suggest_filename (const struct GNUNET_CONTAINER_MetaData
39 *md)
39{ 40{
40 static const char *mimeMap[][2] = { 41 static const char *mimeMap[][2] = {
41 {"application/bz2", ".bz2"}, 42 {"application/bz2", ".bz2"},
@@ -65,12 +66,12 @@ GNUNET_FS_meta_data_suggest_filename (const struct GNUNET_CONTAINER_MetaData *md
65 {"application/x-xcf", ".xcf"}, 66 {"application/x-xcf", ".xcf"},
66 {"application/x-xfig", ".xfig"}, 67 {"application/x-xfig", ".xfig"},
67 {"application/zip", ".zip"}, 68 {"application/zip", ".zip"},
68 69
69 {"audio/midi", ".midi"}, 70 {"audio/midi", ".midi"},
70 {"audio/mpeg", ".mp3"}, 71 {"audio/mpeg", ".mp3"},
71 {"audio/real", ".rm"}, 72 {"audio/real", ".rm"},
72 {"audio/x-wav", ".wav"}, 73 {"audio/x-wav", ".wav"},
73 74
74 {"image/gif", ".gif"}, 75 {"image/gif", ".gif"},
75 {"image/jpeg", ".jpg"}, 76 {"image/jpeg", ".jpg"},
76 {"image/pcx", ".pcx"}, 77 {"image/pcx", ".pcx"},
@@ -78,7 +79,7 @@ GNUNET_FS_meta_data_suggest_filename (const struct GNUNET_CONTAINER_MetaData *md
78 {"image/tiff", ".tiff"}, 79 {"image/tiff", ".tiff"},
79 {"image/x-ms-bmp", ".bmp"}, 80 {"image/x-ms-bmp", ".bmp"},
80 {"image/x-xpixmap", ".xpm"}, 81 {"image/x-xpixmap", ".xpm"},
81 82
82 {"text/css", ".css"}, 83 {"text/css", ".css"},
83 {"text/html", ".html"}, 84 {"text/html", ".html"},
84 {"text/plain", ".txt"}, 85 {"text/plain", ".txt"},
@@ -93,7 +94,7 @@ GNUNET_FS_meta_data_suggest_filename (const struct GNUNET_CONTAINER_MetaData *md
93 {"text/x-perl", ".pl"}, 94 {"text/x-perl", ".pl"},
94 {"text/x-python", ".py"}, 95 {"text/x-python", ".py"},
95 {"text/x-tex", ".tex"}, 96 {"text/x-tex", ".tex"},
96 97
97 {"video/avi", ".avi"}, 98 {"video/avi", ".avi"},
98 {"video/mpeg", ".mpeg"}, 99 {"video/mpeg", ".mpeg"},
99 {"video/quicktime", ".qt"}, 100 {"video/quicktime", ".qt"},
@@ -108,56 +109,50 @@ GNUNET_FS_meta_data_suggest_filename (const struct GNUNET_CONTAINER_MetaData *md
108 const char *ext; 109 const char *ext;
109 110
110 ret = GNUNET_CONTAINER_meta_data_get_by_type (md, 111 ret = GNUNET_CONTAINER_meta_data_get_by_type (md,
111 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME); 112 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME);
112 if (ret != NULL) 113 if (ret != NULL)
113 return ret; 114 return ret;
114 ext = NULL; 115 ext = NULL;
115 mime = GNUNET_CONTAINER_meta_data_get_by_type (md, 116 mime = GNUNET_CONTAINER_meta_data_get_by_type (md,
116 EXTRACTOR_METATYPE_MIMETYPE); 117 EXTRACTOR_METATYPE_MIMETYPE);
117 if (mime != NULL) 118 if (mime != NULL)
118 { 119 {
119 i = 0; 120 i = 0;
120 while ( (mimeMap[i][0] != NULL) && 121 while ((mimeMap[i][0] != NULL) && (0 != strcmp (mime, mimeMap[i][0])))
121 (0 != strcmp (mime, mimeMap[i][0]))) 122 i++;
122 i++; 123 if (mimeMap[i][1] == NULL)
123 if (mimeMap[i][1] == NULL) 124 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG |
124 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | 125 GNUNET_ERROR_TYPE_BULK,
125 GNUNET_ERROR_TYPE_BULK, 126 _("Did not find mime type `%s' in extension list.\n"), mime);
126 _("Did not find mime type `%s' in extension list.\n"), 127 else
127 mime); 128 ext = mimeMap[i][1];
128 else 129 GNUNET_free (mime);
129 ext = mimeMap[i][1]; 130 }
130 GNUNET_free (mime);
131 }
132 base = GNUNET_CONTAINER_meta_data_get_first_by_types (md, 131 base = GNUNET_CONTAINER_meta_data_get_first_by_types (md,
133 EXTRACTOR_METATYPE_TITLE, 132 EXTRACTOR_METATYPE_TITLE,
134 EXTRACTOR_METATYPE_BOOK_TITLE, 133 EXTRACTOR_METATYPE_BOOK_TITLE,
135 EXTRACTOR_METATYPE_ORIGINAL_TITLE, 134 EXTRACTOR_METATYPE_ORIGINAL_TITLE,
136 EXTRACTOR_METATYPE_PACKAGE_NAME, 135 EXTRACTOR_METATYPE_PACKAGE_NAME,
137 EXTRACTOR_METATYPE_URL, 136 EXTRACTOR_METATYPE_URL,
138 EXTRACTOR_METATYPE_URI, 137 EXTRACTOR_METATYPE_URI,
139 EXTRACTOR_METATYPE_DESCRIPTION, 138 EXTRACTOR_METATYPE_DESCRIPTION,
140 EXTRACTOR_METATYPE_ISRC, 139 EXTRACTOR_METATYPE_ISRC,
141 EXTRACTOR_METATYPE_JOURNAL_NAME, 140 EXTRACTOR_METATYPE_JOURNAL_NAME,
142 EXTRACTOR_METATYPE_AUTHOR_NAME, 141 EXTRACTOR_METATYPE_AUTHOR_NAME,
143 EXTRACTOR_METATYPE_SUBJECT, 142 EXTRACTOR_METATYPE_SUBJECT,
144 EXTRACTOR_METATYPE_ALBUM, 143 EXTRACTOR_METATYPE_ALBUM,
145 EXTRACTOR_METATYPE_ARTIST, 144 EXTRACTOR_METATYPE_ARTIST,
146 EXTRACTOR_METATYPE_KEYWORDS, 145 EXTRACTOR_METATYPE_KEYWORDS,
147 EXTRACTOR_METATYPE_COMMENT, 146 EXTRACTOR_METATYPE_COMMENT,
148 EXTRACTOR_METATYPE_UNKNOWN, 147 EXTRACTOR_METATYPE_UNKNOWN,
149 -1); 148 -1);
150 if ( (base == NULL) && 149 if ((base == NULL) && (ext == NULL))
151 (ext == NULL) )
152 return NULL; 150 return NULL;
153 if (base == NULL) 151 if (base == NULL)
154 return GNUNET_strdup (ext); 152 return GNUNET_strdup (ext);
155 if (ext == NULL) 153 if (ext == NULL)
156 return base; 154 return base;
157 GNUNET_asprintf (&ret, 155 GNUNET_asprintf (&ret, "%s%s", base, ext);
158 "%s%s",
159 base,
160 ext);
161 GNUNET_free (base); 156 GNUNET_free (base);
162 return ret; 157 return ret;
163} 158}
@@ -168,7 +163,7 @@ GNUNET_FS_meta_data_suggest_filename (const struct GNUNET_CONTAINER_MetaData *md
168 */ 163 */
169unsigned int 164unsigned int
170GNUNET_FS_get_current_year () 165GNUNET_FS_get_current_year ()
171{ 166{
172 time_t tp; 167 time_t tp;
173 struct tm *t; 168 struct tm *t;
174 169
@@ -195,18 +190,18 @@ GNUNET_FS_year_to_time (unsigned int year)
195 190
196 memset (&t, 0, sizeof (t)); 191 memset (&t, 0, sizeof (t));
197 if (year < 1900) 192 if (year < 1900)
198 { 193 {
199 GNUNET_break (0); 194 GNUNET_break (0);
200 return GNUNET_TIME_absolute_get (); /* now */ 195 return GNUNET_TIME_absolute_get (); /* now */
201 } 196 }
202 t.tm_year = year - 1900; 197 t.tm_year = year - 1900;
203 t.tm_mday = 1; 198 t.tm_mday = 1;
204 t.tm_mon = 1; 199 t.tm_mon = 1;
205 t.tm_wday = 1; 200 t.tm_wday = 1;
206 t.tm_yday = 1; 201 t.tm_yday = 1;
207 tp = mktime (&t); 202 tp = mktime (&t);
208 GNUNET_break (tp != (time_t) -1); 203 GNUNET_break (tp != (time_t) - 1);
209 ret.abs_value = tp * 1000LL; /* seconds to ms */ 204 ret.abs_value = tp * 1000LL; /* seconds to ms */
210 return ret; 205 return ret;
211} 206}
212 207
diff --git a/src/fs/fs_namespace.c b/src/fs/fs_namespace.c
index cd0bfc415..e8dd56ef4 100644
--- a/src/fs/fs_namespace.c
+++ b/src/fs/fs_namespace.c
@@ -46,16 +46,13 @@ get_namespace_directory (struct GNUNET_FS_Handle *h)
46 46
47 if (GNUNET_OK != 47 if (GNUNET_OK !=
48 GNUNET_CONFIGURATION_get_value_filename (h->cfg, 48 GNUNET_CONFIGURATION_get_value_filename (h->cfg,
49 "FS", 49 "FS", "IDENTITY_DIR", &dn))
50 "IDENTITY_DIR", 50 {
51 &dn)) 51 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
52 { 52 _("Configuration fails to specify `%s' in section `%s'\n"),
53 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 53 "IDENTITY_DIR", "fs");
54 _("Configuration fails to specify `%s' in section `%s'\n"), 54 return NULL;
55 "IDENTITY_DIR", 55 }
56 "fs");
57 return NULL;
58 }
59 return dn; 56 return dn;
60} 57}
61 58
@@ -75,21 +72,14 @@ get_update_information_directory (struct GNUNET_FS_Namespace *ns)
75 72
76 if (GNUNET_OK != 73 if (GNUNET_OK !=
77 GNUNET_CONFIGURATION_get_value_filename (ns->h->cfg, 74 GNUNET_CONFIGURATION_get_value_filename (ns->h->cfg,
78 "FS", 75 "FS", "UPDATE_DIR", &dn))
79 "UPDATE_DIR", 76 {
80 &dn)) 77 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
81 { 78 _("Configuration fails to specify `%s' in section `%s'\n"),
82 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 79 "UPDATE_DIR", "fs");
83 _("Configuration fails to specify `%s' in section `%s'\n"), 80 return NULL;
84 "UPDATE_DIR", 81 }
85 "fs"); 82 GNUNET_asprintf (&ret, "%s%s%s", dn, DIR_SEPARATOR_STR, ns->name);
86 return NULL;
87 }
88 GNUNET_asprintf (&ret,
89 "%s%s%s",
90 dn,
91 DIR_SEPARATOR_STR,
92 ns->name);
93 GNUNET_free (dn); 83 GNUNET_free (dn);
94 return ret; 84 return ret;
95} 85}
@@ -103,7 +93,7 @@ get_update_information_directory (struct GNUNET_FS_Namespace *ns)
103static void 93static void
104write_update_information_graph (struct GNUNET_FS_Namespace *ns) 94write_update_information_graph (struct GNUNET_FS_Namespace *ns)
105{ 95{
106 char * fn; 96 char *fn;
107 struct GNUNET_BIO_WriteHandle *wh; 97 struct GNUNET_BIO_WriteHandle *wh;
108 unsigned int i; 98 unsigned int i;
109 struct NamespaceUpdateNode *n; 99 struct NamespaceUpdateNode *n;
@@ -112,39 +102,35 @@ write_update_information_graph (struct GNUNET_FS_Namespace *ns)
112 fn = get_update_information_directory (ns); 102 fn = get_update_information_directory (ns);
113 wh = GNUNET_BIO_write_open (fn); 103 wh = GNUNET_BIO_write_open (fn);
114 if (wh == NULL) 104 if (wh == NULL)
115 { 105 {
116 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 106 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
117 _("Failed to open `%s' for writing: %s\n"), 107 _("Failed to open `%s' for writing: %s\n"), STRERROR (errno));
118 STRERROR (errno)); 108 GNUNET_free (fn);
119 GNUNET_free (fn); 109 return;
120 return; 110 }
121 } 111 if (GNUNET_OK != GNUNET_BIO_write_int32 (wh, ns->update_node_count))
122 if (GNUNET_OK !=
123 GNUNET_BIO_write_int32 (wh, ns->update_node_count))
124 goto END; 112 goto END;
125 for (i=0;i<ns->update_node_count;i++) 113 for (i = 0; i < ns->update_node_count; i++)
114 {
115 n = ns->update_nodes[i];
116 uris = GNUNET_FS_uri_to_string (n->uri);
117 if ((GNUNET_OK !=
118 GNUNET_BIO_write_string (wh, n->id)) ||
119 (GNUNET_OK !=
120 GNUNET_BIO_write_meta_data (wh, n->md)) ||
121 (GNUNET_OK !=
122 GNUNET_BIO_write_string (wh, n->update)) ||
123 (GNUNET_OK != GNUNET_BIO_write_string (wh, uris)))
126 { 124 {
127 n = ns->update_nodes[i];
128 uris = GNUNET_FS_uri_to_string (n->uri);
129 if ( (GNUNET_OK !=
130 GNUNET_BIO_write_string (wh, n->id)) ||
131 (GNUNET_OK !=
132 GNUNET_BIO_write_meta_data (wh, n->md)) ||
133 (GNUNET_OK !=
134 GNUNET_BIO_write_string (wh, n->update)) ||
135 (GNUNET_OK !=
136 GNUNET_BIO_write_string (wh, uris)) )
137 {
138 GNUNET_free (uris);
139 break;
140 }
141 GNUNET_free (uris); 125 GNUNET_free (uris);
126 break;
142 } 127 }
143 END: 128 GNUNET_free (uris);
129 }
130END:
144 if (GNUNET_OK != GNUNET_BIO_write_close (wh)) 131 if (GNUNET_OK != GNUNET_BIO_write_close (wh))
145 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 132 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
146 _("Failed to write `%s': %s\n"), 133 _("Failed to write `%s': %s\n"), STRERROR (errno));
147 STRERROR (errno));
148 GNUNET_free (fn); 134 GNUNET_free (fn);
149} 135}
150 136
@@ -157,89 +143,85 @@ write_update_information_graph (struct GNUNET_FS_Namespace *ns)
157static void 143static void
158read_update_information_graph (struct GNUNET_FS_Namespace *ns) 144read_update_information_graph (struct GNUNET_FS_Namespace *ns)
159{ 145{
160 char * fn; 146 char *fn;
161 struct GNUNET_BIO_ReadHandle *rh; 147 struct GNUNET_BIO_ReadHandle *rh;
162 unsigned int i; 148 unsigned int i;
163 struct NamespaceUpdateNode *n; 149 struct NamespaceUpdateNode *n;
164 char *uris; 150 char *uris;
165 uint32_t count; 151 uint32_t count;
166 char *emsg; 152 char *emsg;
167 153
168 fn = get_update_information_directory (ns); 154 fn = get_update_information_directory (ns);
169 if (GNUNET_YES != 155 if (GNUNET_YES != GNUNET_DISK_file_test (fn))
170 GNUNET_DISK_file_test (fn)) 156 {
171 { 157 GNUNET_free (fn);
172 GNUNET_free (fn); 158 return;
173 return; 159 }
174 }
175 rh = GNUNET_BIO_read_open (fn); 160 rh = GNUNET_BIO_read_open (fn);
176 if (rh == NULL) 161 if (rh == NULL)
177 { 162 {
178 GNUNET_free (fn); 163 GNUNET_free (fn);
179 return; 164 return;
180 } 165 }
181 if (GNUNET_OK != 166 if (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &count))
182 GNUNET_BIO_read_int32 (rh, &count)) 167 {
183 { 168 GNUNET_break (0);
184 GNUNET_break (0); 169 goto END;
185 goto END; 170 }
186 }
187 if (count > 1024 * 1024) 171 if (count > 1024 * 1024)
188 { 172 {
189 GNUNET_break (0); 173 GNUNET_break (0);
190 goto END; 174 goto END;
191 } 175 }
192 if (count == 0) 176 if (count == 0)
177 {
178 GNUNET_break (GNUNET_OK == GNUNET_BIO_read_close (rh, NULL));
179 GNUNET_free (fn);
180 return;
181 }
182 ns->update_nodes =
183 GNUNET_malloc (count * sizeof (struct NamespaceUpdateNode *));
184
185 for (i = 0; i < count; i++)
186 {
187 n = GNUNET_malloc (sizeof (struct NamespaceUpdateNode));
188 if ((GNUNET_OK !=
189 GNUNET_BIO_read_string (rh, "identifier", &n->id, 1024)) ||
190 (GNUNET_OK !=
191 GNUNET_BIO_read_meta_data (rh, "meta", &n->md)) ||
192 (GNUNET_OK !=
193 GNUNET_BIO_read_string (rh, "update-id", &n->update, 1024)) ||
194 (GNUNET_OK != GNUNET_BIO_read_string (rh, "uri", &uris, 1024 * 2)))
193 { 195 {
194 GNUNET_break (GNUNET_OK == GNUNET_BIO_read_close (rh, NULL)); 196 GNUNET_break (0);
195 GNUNET_free (fn); 197 GNUNET_free_non_null (n->id);
196 return; 198 GNUNET_free_non_null (n->update);
199 if (n->md != NULL)
200 GNUNET_CONTAINER_meta_data_destroy (n->md);
201 GNUNET_free (n);
202 break;
197 } 203 }
198 ns->update_nodes = GNUNET_malloc (count * sizeof (struct NamespaceUpdateNode*)); 204 n->uri = GNUNET_FS_uri_parse (uris, &emsg);
199 205 GNUNET_free (uris);
200 for (i=0;i<count;i++) 206 if (n->uri == NULL)
201 { 207 {
202 n = GNUNET_malloc (sizeof (struct NamespaceUpdateNode)); 208 GNUNET_break (0);
203 if ( (GNUNET_OK != 209 GNUNET_free (emsg);
204 GNUNET_BIO_read_string (rh, "identifier", &n->id, 1024)) || 210 GNUNET_free (n->id);
205 (GNUNET_OK != 211 GNUNET_free_non_null (n->update);
206 GNUNET_BIO_read_meta_data (rh, "meta", &n->md)) || 212 GNUNET_CONTAINER_meta_data_destroy (n->md);
207 (GNUNET_OK != 213 GNUNET_free (n);
208 GNUNET_BIO_read_string (rh, "update-id", &n->update, 1024)) || 214 break;
209 (GNUNET_OK !=
210 GNUNET_BIO_read_string (rh, "uri", &uris, 1024 * 2)) )
211 {
212 GNUNET_break (0);
213 GNUNET_free_non_null (n->id);
214 GNUNET_free_non_null (n->update);
215 if (n->md != NULL)
216 GNUNET_CONTAINER_meta_data_destroy (n->md);
217 GNUNET_free (n);
218 break;
219 }
220 n->uri = GNUNET_FS_uri_parse (uris, &emsg);
221 GNUNET_free (uris);
222 if (n->uri == NULL)
223 {
224 GNUNET_break (0);
225 GNUNET_free (emsg);
226 GNUNET_free (n->id);
227 GNUNET_free_non_null (n->update);
228 GNUNET_CONTAINER_meta_data_destroy (n->md);
229 GNUNET_free (n);
230 break;
231 }
232 ns->update_nodes[i] = n;
233 } 215 }
216 ns->update_nodes[i] = n;
217 }
234 ns->update_node_count = i; 218 ns->update_node_count = i;
235 END: 219END:
236 if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) 220 if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
237 { 221 {
238 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 222 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Failed to write `%s': %s\n"), emsg);
239 _("Failed to write `%s': %s\n"), 223 GNUNET_free (emsg);
240 emsg); 224 }
241 GNUNET_free (emsg);
242 }
243 GNUNET_free (fn); 225 GNUNET_free (fn);
244} 226}
245 227
@@ -266,7 +248,7 @@ struct AdvertisementContext
266 248
267 /** 249 /**
268 * Our KSK URI. 250 * Our KSK URI.
269 */ 251 */
270 struct GNUNET_FS_Uri *ksk_uri; 252 struct GNUNET_FS_Uri *ksk_uri;
271 253
272 /** 254 /**
@@ -291,7 +273,7 @@ struct AdvertisementContext
291 273
292 /** 274 /**
293 * Number of bytes of plaintext. 275 * Number of bytes of plaintext.
294 */ 276 */
295 size_t pt_size; 277 size_t pt_size;
296 278
297 /** 279 /**
@@ -308,13 +290,11 @@ struct AdvertisementContext
308 * @param tc scheduler context 290 * @param tc scheduler context
309 */ 291 */
310static void 292static void
311do_disconnect (void *cls, 293do_disconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
312 const struct GNUNET_SCHEDULER_TaskContext *tc)
313{ 294{
314 struct GNUNET_DATASTORE_Handle *dsh = cls; 295 struct GNUNET_DATASTORE_Handle *dsh = cls;
315 296
316 GNUNET_DATASTORE_disconnect (dsh, 297 GNUNET_DATASTORE_disconnect (dsh, GNUNET_NO);
317 GNUNET_NO);
318} 298}
319 299
320 300
@@ -327,9 +307,7 @@ do_disconnect (void *cls,
327 * @param msg NULL on success, otherwise an error message 307 * @param msg NULL on success, otherwise an error message
328 */ 308 */
329static void 309static void
330advertisement_cont (void *cls, 310advertisement_cont (void *cls, int success, const char *msg)
331 int success,
332 const char *msg)
333{ 311{
334 struct AdvertisementContext *ac = cls; 312 struct AdvertisementContext *ac = cls;
335 const char *keyword; 313 const char *keyword;
@@ -338,81 +316,75 @@ advertisement_cont (void *cls,
338 struct GNUNET_CRYPTO_AesSessionKey skey; 316 struct GNUNET_CRYPTO_AesSessionKey skey;
339 struct GNUNET_CRYPTO_AesInitializationVector iv; 317 struct GNUNET_CRYPTO_AesInitializationVector iv;
340 struct GNUNET_CRYPTO_RsaPrivateKey *pk; 318 struct GNUNET_CRYPTO_RsaPrivateKey *pk;
341 319
342 if (GNUNET_OK != success) 320 if (GNUNET_OK != success)
321 {
322 /* error! */
323 GNUNET_SCHEDULER_add_continuation (&do_disconnect,
324 ac->dsh,
325 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
326 if (msg == NULL)
343 { 327 {
344 /* error! */ 328 GNUNET_break (0);
345 GNUNET_SCHEDULER_add_continuation (&do_disconnect, 329 msg = _("Unknown error");
346 ac->dsh,
347 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
348 if (msg == NULL)
349 {
350 GNUNET_break (0);
351 msg = _("Unknown error");
352 }
353 if (ac->cont != NULL)
354 ac->cont (ac->cont_cls, NULL, msg);
355 GNUNET_FS_uri_destroy (ac->ksk_uri);
356 GNUNET_free (ac->pt);
357 GNUNET_free (ac->nb);
358 GNUNET_FS_namespace_delete (ac->ns, GNUNET_NO);
359 GNUNET_free (ac);
360 return;
361 } 330 }
331 if (ac->cont != NULL)
332 ac->cont (ac->cont_cls, NULL, msg);
333 GNUNET_FS_uri_destroy (ac->ksk_uri);
334 GNUNET_free (ac->pt);
335 GNUNET_free (ac->nb);
336 GNUNET_FS_namespace_delete (ac->ns, GNUNET_NO);
337 GNUNET_free (ac);
338 return;
339 }
362 if (ac->pos == ac->ksk_uri->data.ksk.keywordCount) 340 if (ac->pos == ac->ksk_uri->data.ksk.keywordCount)
363 { 341 {
364 /* done! */ 342 /* done! */
365 GNUNET_SCHEDULER_add_continuation (&do_disconnect, 343 GNUNET_SCHEDULER_add_continuation (&do_disconnect,
366 ac->dsh, 344 ac->dsh,
367 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 345 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
368 if (ac->cont != NULL) 346 if (ac->cont != NULL)
369 ac->cont (ac->cont_cls, ac->ksk_uri, NULL); 347 ac->cont (ac->cont_cls, ac->ksk_uri, NULL);
370 GNUNET_FS_uri_destroy (ac->ksk_uri); 348 GNUNET_FS_uri_destroy (ac->ksk_uri);
371 GNUNET_free (ac->pt); 349 GNUNET_free (ac->pt);
372 GNUNET_free (ac->nb); 350 GNUNET_free (ac->nb);
373 GNUNET_FS_namespace_delete (ac->ns, GNUNET_NO); 351 GNUNET_FS_namespace_delete (ac->ns, GNUNET_NO);
374 GNUNET_free (ac); 352 GNUNET_free (ac);
375 return; 353 return;
376 } 354 }
377 keyword = ac->ksk_uri->data.ksk.keywords[ac->pos++]; 355 keyword = ac->ksk_uri->data.ksk.keywords[ac->pos++];
378 /* first character of keyword indicates if it is 356 /* first character of keyword indicates if it is
379 mandatory or not -- ignore for hashing */ 357 * mandatory or not -- ignore for hashing */
380 GNUNET_CRYPTO_hash (&keyword[1], strlen (&keyword[1]), &key); 358 GNUNET_CRYPTO_hash (&keyword[1], strlen (&keyword[1]), &key);
381 GNUNET_CRYPTO_hash_to_aes_key (&key, &skey, &iv); 359 GNUNET_CRYPTO_hash_to_aes_key (&key, &skey, &iv);
382 GNUNET_CRYPTO_aes_encrypt (ac->pt, 360 GNUNET_CRYPTO_aes_encrypt (ac->pt, ac->pt_size, &skey, &iv, &ac->nb[1]);
383 ac->pt_size, 361 GNUNET_break (GNUNET_OK ==
384 &skey, 362 GNUNET_CRYPTO_rsa_sign (ac->ns->key,
385 &iv, 363 &ac->nb->ns_purpose,
386 &ac->nb[1]); 364 &ac->nb->ns_signature));
387 GNUNET_break (GNUNET_OK ==
388 GNUNET_CRYPTO_rsa_sign (ac->ns->key,
389 &ac->nb->ns_purpose,
390 &ac->nb->ns_signature));
391 pk = GNUNET_CRYPTO_rsa_key_create_from_hash (&key); 365 pk = GNUNET_CRYPTO_rsa_key_create_from_hash (&key);
392 GNUNET_assert (pk != NULL); 366 GNUNET_assert (pk != NULL);
393 GNUNET_CRYPTO_rsa_key_get_public (pk, &ac->nb->keyspace); 367 GNUNET_CRYPTO_rsa_key_get_public (pk, &ac->nb->keyspace);
394 GNUNET_CRYPTO_hash (&ac->nb->keyspace, 368 GNUNET_CRYPTO_hash (&ac->nb->keyspace,
395 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), 369 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
396 &query); 370 &query);
397 GNUNET_break (GNUNET_OK == 371 GNUNET_break (GNUNET_OK ==
398 GNUNET_CRYPTO_rsa_sign (pk, 372 GNUNET_CRYPTO_rsa_sign (pk,
399 &ac->nb->ksk_purpose, 373 &ac->nb->ksk_purpose,
400 &ac->nb->ksk_signature)); 374 &ac->nb->ksk_signature));
401 GNUNET_CRYPTO_rsa_key_free (pk); 375 GNUNET_CRYPTO_rsa_key_free (pk);
402 GNUNET_DATASTORE_put (ac->dsh, 376 GNUNET_DATASTORE_put (ac->dsh, 0 /* no reservation */ ,
403 0 /* no reservation */, 377 &query,
404 &query, 378 ac->pt_size + sizeof (struct NBlock),
405 ac->pt_size + sizeof (struct NBlock), 379 ac->nb,
406 ac->nb, 380 GNUNET_BLOCK_TYPE_FS_NBLOCK,
407 GNUNET_BLOCK_TYPE_FS_NBLOCK, 381 ac->bo.content_priority,
408 ac->bo.content_priority, 382 ac->bo.anonymity_level,
409 ac->bo.anonymity_level, 383 ac->bo.replication_level,
410 ac->bo.replication_level, 384 ac->bo.expiration_time,
411 ac->bo.expiration_time, 385 -2, 1,
412 -2, 1, 386 GNUNET_CONSTANTS_SERVICE_TIMEOUT,
413 GNUNET_CONSTANTS_SERVICE_TIMEOUT, 387 &advertisement_cont, ac);
414 &advertisement_cont,
415 ac);
416} 388}
417 389
418 390
@@ -430,13 +402,13 @@ advertisement_cont (void *cls,
430 */ 402 */
431void 403void
432GNUNET_FS_namespace_advertise (struct GNUNET_FS_Handle *h, 404GNUNET_FS_namespace_advertise (struct GNUNET_FS_Handle *h,
433 struct GNUNET_FS_Uri *ksk_uri, 405 struct GNUNET_FS_Uri *ksk_uri,
434 struct GNUNET_FS_Namespace *namespace, 406 struct GNUNET_FS_Namespace *namespace,
435 const struct GNUNET_CONTAINER_MetaData *meta, 407 const struct GNUNET_CONTAINER_MetaData *meta,
436 const struct GNUNET_FS_BlockOptions *bo, 408 const struct GNUNET_FS_BlockOptions *bo,
437 const char *rootEntry, 409 const char *rootEntry,
438 GNUNET_FS_PublishContinuation cont, 410 GNUNET_FS_PublishContinuation cont,
439 void *cont_cls) 411 void *cont_cls)
440{ 412{
441 size_t reslen; 413 size_t reslen;
442 size_t size; 414 size_t size;
@@ -450,50 +422,52 @@ GNUNET_FS_namespace_advertise (struct GNUNET_FS_Handle *h,
450 /* create advertisements */ 422 /* create advertisements */
451 mdsize = GNUNET_CONTAINER_meta_data_get_serialized_size (meta); 423 mdsize = GNUNET_CONTAINER_meta_data_get_serialized_size (meta);
452 if (-1 == mdsize) 424 if (-1 == mdsize)
453 { 425 {
454 cont (cont_cls, NULL, _("Failed to serialize meta data")); 426 cont (cont_cls, NULL, _("Failed to serialize meta data"));
455 return; 427 return;
456 } 428 }
457 reslen = strlen (rootEntry) + 1; 429 reslen = strlen (rootEntry) + 1;
458 size = mdsize + sizeof (struct NBlock) + reslen; 430 size = mdsize + sizeof (struct NBlock) + reslen;
459 if (size > MAX_NBLOCK_SIZE) 431 if (size > MAX_NBLOCK_SIZE)
460 { 432 {
461 size = MAX_NBLOCK_SIZE; 433 size = MAX_NBLOCK_SIZE;
462 mdsize = size - sizeof (struct NBlock) - reslen; 434 mdsize = size - sizeof (struct NBlock) - reslen;
463 } 435 }
464 436
465 pt = GNUNET_malloc (mdsize + reslen); 437 pt = GNUNET_malloc (mdsize + reslen);
466 memcpy (pt, rootEntry, reslen); 438 memcpy (pt, rootEntry, reslen);
467 mdst = &pt[reslen]; 439 mdst = &pt[reslen];
468 mdsize = GNUNET_CONTAINER_meta_data_serialize (meta, 440 mdsize = GNUNET_CONTAINER_meta_data_serialize (meta,
469 &mdst, 441 &mdst,
470 mdsize, 442 mdsize,
471 GNUNET_CONTAINER_META_DATA_SERIALIZE_PART); 443 GNUNET_CONTAINER_META_DATA_SERIALIZE_PART);
472 if (mdsize == -1) 444 if (mdsize == -1)
473 { 445 {
474 GNUNET_break (0); 446 GNUNET_break (0);
475 GNUNET_free (pt); 447 GNUNET_free (pt);
476 cont (cont_cls, NULL, _("Failed to serialize meta data")); 448 cont (cont_cls, NULL, _("Failed to serialize meta data"));
477 return; 449 return;
478 } 450 }
479 size = mdsize + sizeof (struct NBlock) + reslen; 451 size = mdsize + sizeof (struct NBlock) + reslen;
480 nb = GNUNET_malloc (size); 452 nb = GNUNET_malloc (size);
481 GNUNET_CRYPTO_rsa_key_get_public (namespace->key, 453 GNUNET_CRYPTO_rsa_key_get_public (namespace->key, &nb->subspace);
482 &nb->subspace); 454 nb->ns_purpose.size = htonl (mdsize + reslen +
483 nb->ns_purpose.size = htonl (mdsize + reslen + 455 sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose)
484 sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) + 456 +
485 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); 457 sizeof (struct
458 GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
486 nb->ns_purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_FS_NBLOCK); 459 nb->ns_purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_FS_NBLOCK);
487 nb->ksk_purpose.size = htonl (size - sizeof (struct GNUNET_CRYPTO_RsaSignature)); 460 nb->ksk_purpose.size =
461 htonl (size - sizeof (struct GNUNET_CRYPTO_RsaSignature));
488 nb->ksk_purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_FS_NBLOCK_KSIG); 462 nb->ksk_purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_FS_NBLOCK_KSIG);
489 dsh = GNUNET_DATASTORE_connect (h->cfg); 463 dsh = GNUNET_DATASTORE_connect (h->cfg);
490 if (NULL == dsh) 464 if (NULL == dsh)
491 { 465 {
492 GNUNET_free (nb); 466 GNUNET_free (nb);
493 GNUNET_free (pt); 467 GNUNET_free (pt);
494 cont (cont_cls, NULL, _("Failed to connect to datastore service")); 468 cont (cont_cls, NULL, _("Failed to connect to datastore service"));
495 return; 469 return;
496 } 470 }
497 ctx = GNUNET_malloc (sizeof (struct AdvertisementContext)); 471 ctx = GNUNET_malloc (sizeof (struct AdvertisementContext));
498 ctx->cont = cont; 472 ctx->cont = cont;
499 ctx->cont_cls = cont_cls; 473 ctx->cont_cls = cont_cls;
@@ -518,33 +492,28 @@ GNUNET_FS_namespace_advertise (struct GNUNET_FS_Handle *h,
518 * @return handle to the namespace, NULL on error 492 * @return handle to the namespace, NULL on error
519 */ 493 */
520struct GNUNET_FS_Namespace * 494struct GNUNET_FS_Namespace *
521GNUNET_FS_namespace_create (struct GNUNET_FS_Handle *h, 495GNUNET_FS_namespace_create (struct GNUNET_FS_Handle *h, const char *name)
522 const char *name)
523{ 496{
524 char *dn; 497 char *dn;
525 char *fn; 498 char *fn;
526 struct GNUNET_FS_Namespace *ret; 499 struct GNUNET_FS_Namespace *ret;
527 500
528 dn = get_namespace_directory (h); 501 dn = get_namespace_directory (h);
529 GNUNET_asprintf (&fn, 502 GNUNET_asprintf (&fn, "%s%s%s", dn, DIR_SEPARATOR_STR, name);
530 "%s%s%s",
531 dn,
532 DIR_SEPARATOR_STR,
533 name);
534 GNUNET_free (dn); 503 GNUNET_free (dn);
535 ret = GNUNET_malloc (sizeof (struct GNUNET_FS_Namespace)); 504 ret = GNUNET_malloc (sizeof (struct GNUNET_FS_Namespace));
536 ret->h = h; 505 ret->h = h;
537 ret->rc = 1; 506 ret->rc = 1;
538 ret->key = GNUNET_CRYPTO_rsa_key_create_from_file (fn); 507 ret->key = GNUNET_CRYPTO_rsa_key_create_from_file (fn);
539 if (ret->key == NULL) 508 if (ret->key == NULL)
540 { 509 {
541 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 510 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
542 _("Failed to create or read private key for namespace `%s'\n"), 511 _("Failed to create or read private key for namespace `%s'\n"),
543 name); 512 name);
544 GNUNET_free (ret); 513 GNUNET_free (ret);
545 GNUNET_free (fn); 514 GNUNET_free (fn);
546 return NULL; 515 return NULL;
547 } 516 }
548 ret->name = GNUNET_strdup (name); 517 ret->name = GNUNET_strdup (name);
549 ret->filename = fn; 518 ret->filename = fn;
550 return ret; 519 return ret;
@@ -562,42 +531,39 @@ GNUNET_FS_namespace_create (struct GNUNET_FS_Handle *h,
562 * 531 *
563 * @return GNUNET_OK on success, GNUNET_SYSERR on error 532 * @return GNUNET_OK on success, GNUNET_SYSERR on error
564 */ 533 */
565int 534int
566GNUNET_FS_namespace_delete (struct GNUNET_FS_Namespace *namespace, 535GNUNET_FS_namespace_delete (struct GNUNET_FS_Namespace *namespace, int freeze)
567 int freeze)
568{ 536{
569 unsigned int i; 537 unsigned int i;
570 struct NamespaceUpdateNode *nsn; 538 struct NamespaceUpdateNode *nsn;
571 539
572 namespace->rc--; 540 namespace->rc--;
573 if (freeze) 541 if (freeze)
574 { 542 {
575 if (0 != UNLINK (namespace->filename)) 543 if (0 != UNLINK (namespace->filename))
576 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, 544 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
577 "unlink", 545 "unlink", namespace->filename);
578 namespace->filename); 546 }
579 }
580 if (0 == namespace->rc) 547 if (0 == namespace->rc)
548 {
549 GNUNET_CRYPTO_rsa_key_free (namespace->key);
550 GNUNET_free (namespace->filename);
551 GNUNET_free (namespace->name);
552 for (i = 0; i < namespace->update_node_count; i++)
581 { 553 {
582 GNUNET_CRYPTO_rsa_key_free (namespace->key); 554 nsn = namespace->update_nodes[i];
583 GNUNET_free (namespace->filename); 555 GNUNET_CONTAINER_meta_data_destroy (nsn->md);
584 GNUNET_free (namespace->name); 556 GNUNET_FS_uri_destroy (nsn->uri);
585 for (i=0;i<namespace->update_node_count;i++) 557 GNUNET_free (nsn->id);
586 { 558 GNUNET_free (nsn->update);
587 nsn = namespace->update_nodes[i]; 559 GNUNET_free (nsn);
588 GNUNET_CONTAINER_meta_data_destroy (nsn->md);
589 GNUNET_FS_uri_destroy (nsn->uri);
590 GNUNET_free (nsn->id);
591 GNUNET_free (nsn->update);
592 GNUNET_free (nsn);
593 }
594 GNUNET_array_grow (namespace->update_nodes,
595 namespace->update_node_count,
596 0);
597 if (namespace->update_map != NULL)
598 GNUNET_CONTAINER_multihashmap_destroy (namespace->update_map);
599 GNUNET_free (namespace);
600 } 560 }
561 GNUNET_array_grow (namespace->update_nodes,
562 namespace->update_node_count, 0);
563 if (namespace->update_map != NULL)
564 GNUNET_CONTAINER_multihashmap_destroy (namespace->update_map);
565 GNUNET_free (namespace);
566 }
601 return GNUNET_OK; 567 return GNUNET_OK;
602} 568}
603 569
@@ -630,8 +596,7 @@ struct ProcessNamespaceContext
630 * GNUNET_SYSERR to abort iteration with error! 596 * GNUNET_SYSERR to abort iteration with error!
631 */ 597 */
632static int 598static int
633process_namespace (void *cls, 599process_namespace (void *cls, const char *filename)
634 const char *filename)
635{ 600{
636 struct ProcessNamespaceContext *pnc = cls; 601 struct ProcessNamespaceContext *pnc = cls;
637 struct GNUNET_CRYPTO_RsaPrivateKey *key; 602 struct GNUNET_CRYPTO_RsaPrivateKey *key;
@@ -642,25 +607,22 @@ process_namespace (void *cls,
642 607
643 key = GNUNET_CRYPTO_rsa_key_create_from_file (filename); 608 key = GNUNET_CRYPTO_rsa_key_create_from_file (filename);
644 if (key == NULL) 609 if (key == NULL)
645 { 610 {
646 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 611 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
647 _("Failed to read namespace private key file `%s', deleting it!\n"), 612 _
648 filename); 613 ("Failed to read namespace private key file `%s', deleting it!\n"),
649 if (0 != UNLINK (filename)) 614 filename);
650 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, 615 if (0 != UNLINK (filename))
651 "unlink", 616 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", filename);
652 filename); 617 return GNUNET_OK;
653 return GNUNET_OK; 618 }
654 }
655 GNUNET_CRYPTO_rsa_key_get_public (key, &pk); 619 GNUNET_CRYPTO_rsa_key_get_public (key, &pk);
656 GNUNET_CRYPTO_rsa_key_free (key); 620 GNUNET_CRYPTO_rsa_key_free (key);
657 GNUNET_CRYPTO_hash (&pk, sizeof(pk), &id); 621 GNUNET_CRYPTO_hash (&pk, sizeof (pk), &id);
658 name = filename; 622 name = filename;
659 while (NULL != (t = strstr (name, DIR_SEPARATOR_STR))) 623 while (NULL != (t = strstr (name, DIR_SEPARATOR_STR)))
660 name = t + 1; 624 name = t + 1;
661 pnc->cb (pnc->cb_cls, 625 pnc->cb (pnc->cb_cls, name, &id);
662 name,
663 &id);
664 return GNUNET_OK; 626 return GNUNET_OK;
665} 627}
666 628
@@ -674,22 +636,19 @@ process_namespace (void *cls,
674 * @param cb function to call on each known namespace 636 * @param cb function to call on each known namespace
675 * @param cb_cls closure for cb 637 * @param cb_cls closure for cb
676 */ 638 */
677void 639void
678GNUNET_FS_namespace_list (struct GNUNET_FS_Handle *h, 640GNUNET_FS_namespace_list (struct GNUNET_FS_Handle *h,
679 GNUNET_FS_NamespaceInfoProcessor cb, 641 GNUNET_FS_NamespaceInfoProcessor cb, void *cb_cls)
680 void *cb_cls)
681{ 642{
682 char *dn; 643 char *dn;
683 struct ProcessNamespaceContext ctx; 644 struct ProcessNamespaceContext ctx;
684 645
685 dn = get_namespace_directory (h); 646 dn = get_namespace_directory (h);
686 if (dn == NULL) 647 if (dn == NULL)
687 return; 648 return;
688 ctx.cb = cb; 649 ctx.cb = cb;
689 ctx.cb_cls = cb_cls; 650 ctx.cb_cls = cb_cls;
690 GNUNET_DISK_directory_scan (dn, 651 GNUNET_DISK_directory_scan (dn, &process_namespace, &ctx);
691 &process_namespace,
692 &ctx);
693 GNUNET_free (dn); 652 GNUNET_free (dn);
694} 653}
695 654
@@ -730,7 +689,7 @@ struct PublishSksContext
730 689
731 /** 690 /**
732 * Closure for cont. 691 * Closure for cont.
733 */ 692 */
734 void *cont_cls; 693 void *cont_cls;
735 694
736}; 695};
@@ -745,66 +704,56 @@ struct PublishSksContext
745 * @param msg error message (or NULL) 704 * @param msg error message (or NULL)
746 */ 705 */
747static void 706static void
748sb_put_cont (void *cls, 707sb_put_cont (void *cls, int success, const char *msg)
749 int success,
750 const char *msg)
751{ 708{
752 struct PublishSksContext *psc = cls; 709 struct PublishSksContext *psc = cls;
753 GNUNET_HashCode hc; 710 GNUNET_HashCode hc;
754 711
755 if (NULL != psc->dsh) 712 if (NULL != psc->dsh)
756 { 713 {
757 GNUNET_DATASTORE_disconnect (psc->dsh, GNUNET_NO); 714 GNUNET_DATASTORE_disconnect (psc->dsh, GNUNET_NO);
758 psc->dsh = NULL; 715 psc->dsh = NULL;
759 } 716 }
760 if (GNUNET_OK != success) 717 if (GNUNET_OK != success)
761 { 718 {
762 if (psc->cont != NULL) 719 if (psc->cont != NULL)
763 psc->cont (psc->cont_cls, 720 psc->cont (psc->cont_cls, NULL, msg);
764 NULL, 721 }
765 msg);
766 }
767 else 722 else
723 {
724 if (psc->nsn != NULL)
768 { 725 {
769 if (psc->nsn != NULL) 726 /* FIXME: this can be done much more
770 { 727 * efficiently by simply appending to the
771 /* FIXME: this can be done much more 728 * file and overwriting the 4-byte header */
772 efficiently by simply appending to the 729 if (psc->namespace->update_nodes == NULL)
773 file and overwriting the 4-byte header */ 730 read_update_information_graph (psc->namespace);
774 if (psc->namespace->update_nodes == NULL) 731 GNUNET_array_append (psc->namespace->update_nodes,
775 read_update_information_graph (psc->namespace); 732 psc->namespace->update_node_count, psc->nsn);
776 GNUNET_array_append (psc->namespace->update_nodes, 733 if (psc->namespace->update_map != NULL)
777 psc->namespace->update_node_count, 734 {
778 psc->nsn); 735 GNUNET_CRYPTO_hash (psc->nsn->id, strlen (psc->nsn->id), &hc);
779 if (psc->namespace->update_map != NULL) 736 GNUNET_CONTAINER_multihashmap_put (psc->namespace->update_map,
780 { 737 &hc,
781 GNUNET_CRYPTO_hash (psc->nsn->id, 738 psc->nsn,
782 strlen (psc->nsn->id), 739 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
783 &hc); 740 }
784 GNUNET_CONTAINER_multihashmap_put (psc->namespace->update_map, 741 psc->nsn = NULL;
785 &hc, 742 write_update_information_graph (psc->namespace);
786 psc->nsn,
787 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
788 }
789 psc->nsn = NULL;
790 write_update_information_graph (psc->namespace);
791 }
792 if (psc->cont != NULL)
793 psc->cont (psc->cont_cls,
794 psc->uri,
795 NULL);
796 } 743 }
797 GNUNET_FS_namespace_delete (psc->namespace, 744 if (psc->cont != NULL)
798 GNUNET_NO); 745 psc->cont (psc->cont_cls, psc->uri, NULL);
746 }
747 GNUNET_FS_namespace_delete (psc->namespace, GNUNET_NO);
799 GNUNET_FS_uri_destroy (psc->uri); 748 GNUNET_FS_uri_destroy (psc->uri);
800 if (psc->nsn != NULL) 749 if (psc->nsn != NULL)
801 { 750 {
802 GNUNET_CONTAINER_meta_data_destroy (psc->nsn->md); 751 GNUNET_CONTAINER_meta_data_destroy (psc->nsn->md);
803 GNUNET_FS_uri_destroy (psc->nsn->uri); 752 GNUNET_FS_uri_destroy (psc->nsn->uri);
804 GNUNET_free (psc->nsn->id); 753 GNUNET_free (psc->nsn->id);
805 GNUNET_free (psc->nsn->update); 754 GNUNET_free (psc->nsn->update);
806 GNUNET_free (psc->nsn); 755 GNUNET_free (psc->nsn);
807 } 756 }
808 GNUNET_free (psc); 757 GNUNET_free (psc);
809} 758}
810 759
@@ -825,15 +774,14 @@ sb_put_cont (void *cls,
825 */ 774 */
826void 775void
827GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h, 776GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h,
828 struct GNUNET_FS_Namespace *namespace, 777 struct GNUNET_FS_Namespace *namespace,
829 const char *identifier, 778 const char *identifier,
830 const char *update, 779 const char *update,
831 const struct GNUNET_CONTAINER_MetaData *meta, 780 const struct GNUNET_CONTAINER_MetaData *meta,
832 const struct GNUNET_FS_Uri *uri, 781 const struct GNUNET_FS_Uri *uri,
833 const struct GNUNET_FS_BlockOptions *bo, 782 const struct GNUNET_FS_BlockOptions *bo,
834 enum GNUNET_FS_PublishOptions options, 783 enum GNUNET_FS_PublishOptions options,
835 GNUNET_FS_PublishContinuation cont, 784 GNUNET_FS_PublishContinuation cont, void *cont_cls)
836 void *cont_cls)
837{ 785{
838 struct PublishSksContext *psc; 786 struct PublishSksContext *psc;
839 struct GNUNET_CRYPTO_AesSessionKey sk; 787 struct GNUNET_CRYPTO_AesSessionKey sk;
@@ -849,9 +797,9 @@ GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h,
849 struct SBlock *sb_enc; 797 struct SBlock *sb_enc;
850 char *dest; 798 char *dest;
851 struct GNUNET_CONTAINER_MetaData *mmeta; 799 struct GNUNET_CONTAINER_MetaData *mmeta;
852 GNUNET_HashCode key; /* hash of thisId = key */ 800 GNUNET_HashCode key; /* hash of thisId = key */
853 GNUNET_HashCode id; /* hash of hc = identifier */ 801 GNUNET_HashCode id; /* hash of hc = identifier */
854 GNUNET_HashCode query; /* id ^ nsid = DB query */ 802 GNUNET_HashCode query; /* id ^ nsid = DB query */
855 803
856 if (NULL == meta) 804 if (NULL == meta)
857 mmeta = GNUNET_CONTAINER_meta_data_create (); 805 mmeta = GNUNET_CONTAINER_meta_data_create ();
@@ -867,10 +815,10 @@ GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h,
867 mdsize = GNUNET_CONTAINER_meta_data_get_serialized_size (mmeta); 815 mdsize = GNUNET_CONTAINER_meta_data_get_serialized_size (mmeta);
868 size = sizeof (struct SBlock) + slen + nidlen + mdsize; 816 size = sizeof (struct SBlock) + slen + nidlen + mdsize;
869 if (size > MAX_SBLOCK_SIZE) 817 if (size > MAX_SBLOCK_SIZE)
870 { 818 {
871 size = MAX_SBLOCK_SIZE; 819 size = MAX_SBLOCK_SIZE;
872 mdsize = size - (sizeof (struct SBlock) + slen + nidlen); 820 mdsize = size - (sizeof (struct SBlock) + slen + nidlen);
873 } 821 }
874 sb = GNUNET_malloc (sizeof (struct SBlock) + size); 822 sb = GNUNET_malloc (sizeof (struct SBlock) + size);
875 dest = (char *) &sb[1]; 823 dest = (char *) &sb[1];
876 if (update != NULL) 824 if (update != NULL)
@@ -882,19 +830,17 @@ GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h,
882 GNUNET_free (uris); 830 GNUNET_free (uris);
883 dest += slen; 831 dest += slen;
884 mdsize = GNUNET_CONTAINER_meta_data_serialize (mmeta, 832 mdsize = GNUNET_CONTAINER_meta_data_serialize (mmeta,
885 &dest, 833 &dest,
886 mdsize, 834 mdsize,
887 GNUNET_CONTAINER_META_DATA_SERIALIZE_PART); 835 GNUNET_CONTAINER_META_DATA_SERIALIZE_PART);
888 GNUNET_CONTAINER_meta_data_destroy (mmeta); 836 GNUNET_CONTAINER_meta_data_destroy (mmeta);
889 if (mdsize == -1) 837 if (mdsize == -1)
890 { 838 {
891 GNUNET_break (0); 839 GNUNET_break (0);
892 GNUNET_free (sb); 840 GNUNET_free (sb);
893 cont (cont_cls, 841 cont (cont_cls, NULL, _("Internal error."));
894 NULL, 842 return;
895 _("Internal error.")); 843 }
896 return;
897 }
898 size = sizeof (struct SBlock) + mdsize + slen + nidlen; 844 size = sizeof (struct SBlock) + mdsize + slen + nidlen;
899 sb_enc = GNUNET_malloc (size); 845 sb_enc = GNUNET_malloc (size);
900 GNUNET_CRYPTO_hash (identifier, idlen, &key); 846 GNUNET_CRYPTO_hash (identifier, idlen, &key);
@@ -903,76 +849,64 @@ GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h,
903 sks_uri->type = sks; 849 sks_uri->type = sks;
904 GNUNET_CRYPTO_rsa_key_get_public (namespace->key, &sb_enc->subspace); 850 GNUNET_CRYPTO_rsa_key_get_public (namespace->key, &sb_enc->subspace);
905 GNUNET_CRYPTO_hash (&sb_enc->subspace, 851 GNUNET_CRYPTO_hash (&sb_enc->subspace,
906 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), 852 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
907 &sks_uri->data.sks.namespace); 853 &sks_uri->data.sks.namespace);
908 sks_uri->data.sks.identifier = GNUNET_strdup (identifier); 854 sks_uri->data.sks.identifier = GNUNET_strdup (identifier);
909 GNUNET_CRYPTO_hash_xor (&id, 855 GNUNET_CRYPTO_hash_xor (&id,
910 &sks_uri->data.sks.namespace, 856 &sks_uri->data.sks.namespace, &sb_enc->identifier);
911 &sb_enc->identifier);
912 GNUNET_CRYPTO_hash_to_aes_key (&key, &sk, &iv); 857 GNUNET_CRYPTO_hash_to_aes_key (&key, &sk, &iv);
913 GNUNET_CRYPTO_aes_encrypt (&sb[1], 858 GNUNET_CRYPTO_aes_encrypt (&sb[1],
914 size - sizeof (struct SBlock), 859 size - sizeof (struct SBlock),
915 &sk, 860 &sk, &iv, &sb_enc[1]);
916 &iv,
917 &sb_enc[1]);
918 sb_enc->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_FS_SBLOCK); 861 sb_enc->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_FS_SBLOCK);
919 sb_enc->purpose.size = htonl(slen + mdsize + nidlen 862 sb_enc->purpose.size = htonl (slen + mdsize + nidlen
920 + sizeof(struct SBlock) 863 + sizeof (struct SBlock)
921 - sizeof(struct GNUNET_CRYPTO_RsaSignature)); 864 - sizeof (struct GNUNET_CRYPTO_RsaSignature));
922 GNUNET_assert (GNUNET_OK == 865 GNUNET_assert (GNUNET_OK ==
923 GNUNET_CRYPTO_rsa_sign (namespace->key, 866 GNUNET_CRYPTO_rsa_sign (namespace->key,
924 &sb_enc->purpose, 867 &sb_enc->purpose, &sb_enc->signature));
925 &sb_enc->signature)); 868 psc = GNUNET_malloc (sizeof (struct PublishSksContext));
926 psc = GNUNET_malloc (sizeof(struct PublishSksContext));
927 psc->uri = sks_uri; 869 psc->uri = sks_uri;
928 psc->cont = cont; 870 psc->cont = cont;
929 psc->namespace = namespace; 871 psc->namespace = namespace;
930 namespace->rc++; 872 namespace->rc++;
931 psc->cont_cls = cont_cls; 873 psc->cont_cls = cont_cls;
932 if (0 != (options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY)) 874 if (0 != (options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY))
933 { 875 {
934 GNUNET_free (sb_enc); 876 GNUNET_free (sb_enc);
935 GNUNET_free (sb); 877 GNUNET_free (sb);
936 sb_put_cont (psc, 878 sb_put_cont (psc, GNUNET_OK, NULL);
937 GNUNET_OK, 879 return;
938 NULL); 880 }
939 return;
940 }
941 psc->dsh = GNUNET_DATASTORE_connect (h->cfg); 881 psc->dsh = GNUNET_DATASTORE_connect (h->cfg);
942 if (NULL == psc->dsh) 882 if (NULL == psc->dsh)
943 { 883 {
944 GNUNET_free (sb_enc); 884 GNUNET_free (sb_enc);
945 GNUNET_free (sb); 885 GNUNET_free (sb);
946 sb_put_cont (psc, 886 sb_put_cont (psc, GNUNET_NO, _("Failed to connect to datastore."));
947 GNUNET_NO, 887 return;
948 _("Failed to connect to datastore.")); 888 }
949 return; 889 GNUNET_CRYPTO_hash_xor (&sks_uri->data.sks.namespace, &id, &query);
950 }
951 GNUNET_CRYPTO_hash_xor (&sks_uri->data.sks.namespace,
952 &id,
953 &query);
954 if (NULL != update) 890 if (NULL != update)
955 { 891 {
956 psc->nsn = GNUNET_malloc (sizeof (struct NamespaceUpdateNode)); 892 psc->nsn = GNUNET_malloc (sizeof (struct NamespaceUpdateNode));
957 psc->nsn->id = GNUNET_strdup (identifier); 893 psc->nsn->id = GNUNET_strdup (identifier);
958 psc->nsn->update = GNUNET_strdup (update); 894 psc->nsn->update = GNUNET_strdup (update);
959 psc->nsn->md = GNUNET_CONTAINER_meta_data_duplicate (meta); 895 psc->nsn->md = GNUNET_CONTAINER_meta_data_duplicate (meta);
960 psc->nsn->uri = GNUNET_FS_uri_dup (uri); 896 psc->nsn->uri = GNUNET_FS_uri_dup (uri);
961 } 897 }
962 GNUNET_DATASTORE_put (psc->dsh, 898 GNUNET_DATASTORE_put (psc->dsh,
963 0, 899 0,
964 &sb_enc->identifier, 900 &sb_enc->identifier,
965 size, 901 size,
966 sb_enc, 902 sb_enc,
967 GNUNET_BLOCK_TYPE_FS_SBLOCK, 903 GNUNET_BLOCK_TYPE_FS_SBLOCK,
968 bo->content_priority, 904 bo->content_priority,
969 bo->anonymity_level, 905 bo->anonymity_level,
970 bo->replication_level, 906 bo->replication_level,
971 bo->expiration_time, 907 bo->expiration_time,
972 -2, 1, 908 -2, 1,
973 GNUNET_CONSTANTS_SERVICE_TIMEOUT, 909 GNUNET_CONSTANTS_SERVICE_TIMEOUT, &sb_put_cont, psc);
974 &sb_put_cont,
975 psc);
976 GNUNET_free (sb); 910 GNUNET_free (sb);
977 GNUNET_free (sb_enc); 911 GNUNET_free (sb_enc);
978} 912}
@@ -981,7 +915,7 @@ GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h,
981/** 915/**
982 * Closure for 'process_update_node'. 916 * Closure for 'process_update_node'.
983 */ 917 */
984struct ProcessUpdateClosure 918struct ProcessUpdateClosure
985{ 919{
986 /** 920 /**
987 * Function to call for each node. 921 * Function to call for each node.
@@ -1006,18 +940,12 @@ struct ProcessUpdateClosure
1006 * GNUNET_NO if not. 940 * GNUNET_NO if not.
1007 */ 941 */
1008static int 942static int
1009process_update_node (void *cls, 943process_update_node (void *cls, const GNUNET_HashCode * key, void *value)
1010 const GNUNET_HashCode * key,
1011 void *value)
1012{ 944{
1013 struct ProcessUpdateClosure *pc = cls; 945 struct ProcessUpdateClosure *pc = cls;
1014 struct NamespaceUpdateNode *nsn = value; 946 struct NamespaceUpdateNode *nsn = value;
1015 947
1016 pc->ip (pc->ip_cls, 948 pc->ip (pc->ip_cls, nsn->id, nsn->uri, nsn->md, nsn->update);
1017 nsn->id,
1018 nsn->uri,
1019 nsn->md,
1020 nsn->update);
1021 return GNUNET_YES; 949 return GNUNET_YES;
1022} 950}
1023 951
@@ -1025,7 +953,7 @@ process_update_node (void *cls,
1025/** 953/**
1026 * Closure for 'find_trees'. 954 * Closure for 'find_trees'.
1027 */ 955 */
1028struct FindTreeClosure 956struct FindTreeClosure
1029{ 957{
1030 /** 958 /**
1031 * Namespace we are operating on. 959 * Namespace we are operating on.
@@ -1075,42 +1003,36 @@ struct FindTreeClosure
1075 * GNUNET_NO if not. 1003 * GNUNET_NO if not.
1076 */ 1004 */
1077static int 1005static int
1078find_trees (void *cls, 1006find_trees (void *cls, const GNUNET_HashCode * key, void *value)
1079 const GNUNET_HashCode * key,
1080 void *value)
1081{ 1007{
1082 struct FindTreeClosure *fc = cls; 1008 struct FindTreeClosure *fc = cls;
1083 struct NamespaceUpdateNode *nsn = value; 1009 struct NamespaceUpdateNode *nsn = value;
1084 GNUNET_HashCode hc; 1010 GNUNET_HashCode hc;
1085 1011
1086 if (nsn->nug == fc->nug) 1012 if (nsn->nug == fc->nug)
1087 { 1013 {
1088 if (nsn->tree_id == UINT_MAX) 1014 if (nsn->tree_id == UINT_MAX)
1089 return GNUNET_YES; /* circular */ 1015 return GNUNET_YES; /* circular */
1090 GNUNET_assert (nsn->tree_id < fc->tree_array_size); 1016 GNUNET_assert (nsn->tree_id < fc->tree_array_size);
1091 if (fc->tree_array[nsn->tree_id] != nsn) 1017 if (fc->tree_array[nsn->tree_id] != nsn)
1092 return GNUNET_YES; /* part of "another" (directed) TREE, 1018 return GNUNET_YES; /* part of "another" (directed) TREE,
1093 and not root of it, end trace */ 1019 * and not root of it, end trace */
1094 if (nsn->tree_id == fc->id) 1020 if (nsn->tree_id == fc->id)
1095 return GNUNET_YES; /* that's our own root (can this be?) */ 1021 return GNUNET_YES; /* that's our own root (can this be?) */
1096 /* merge existing TREE, we have a root for both */ 1022 /* merge existing TREE, we have a root for both */
1097 fc->tree_array[nsn->tree_id] = NULL; 1023 fc->tree_array[nsn->tree_id] = NULL;
1098 if (fc->id == UINT_MAX) 1024 if (fc->id == UINT_MAX)
1099 fc->id = nsn->tree_id; /* take over ID */ 1025 fc->id = nsn->tree_id; /* take over ID */
1100 } 1026 }
1101 else 1027 else
1102 { 1028 {
1103 nsn->nug = fc->nug; 1029 nsn->nug = fc->nug;
1104 nsn->tree_id = UINT_MAX; /* mark as undef */ 1030 nsn->tree_id = UINT_MAX; /* mark as undef */
1105 /* trace */ 1031 /* trace */
1106 GNUNET_CRYPTO_hash (nsn->update, 1032 GNUNET_CRYPTO_hash (nsn->update, strlen (nsn->update), &hc);
1107 strlen (nsn->update), 1033 GNUNET_CONTAINER_multihashmap_get_multiple (fc->namespace->update_map,
1108 &hc); 1034 &hc, &find_trees, fc);
1109 GNUNET_CONTAINER_multihashmap_get_multiple (fc->namespace->update_map, 1035 }
1110 &hc,
1111 &find_trees,
1112 fc);
1113 }
1114 return GNUNET_YES; 1036 return GNUNET_YES;
1115} 1037}
1116 1038
@@ -1139,9 +1061,9 @@ find_trees (void *cls,
1139 */ 1061 */
1140void 1062void
1141GNUNET_FS_namespace_list_updateable (struct GNUNET_FS_Namespace *namespace, 1063GNUNET_FS_namespace_list_updateable (struct GNUNET_FS_Namespace *namespace,
1142 const char *next_id, 1064 const char *next_id,
1143 GNUNET_FS_IdentifierProcessor ip, 1065 GNUNET_FS_IdentifierProcessor ip,
1144 void *ip_cls) 1066 void *ip_cls)
1145{ 1067{
1146 unsigned int i; 1068 unsigned int i;
1147 unsigned int nug; 1069 unsigned int nug;
@@ -1153,154 +1075,125 @@ GNUNET_FS_namespace_list_updateable (struct GNUNET_FS_Namespace *namespace,
1153 if (namespace->update_nodes == NULL) 1075 if (namespace->update_nodes == NULL)
1154 read_update_information_graph (namespace); 1076 read_update_information_graph (namespace);
1155 if (namespace->update_nodes == NULL) 1077 if (namespace->update_nodes == NULL)
1156 { 1078 {
1157#if DEBUG_NAMESPACE 1079#if DEBUG_NAMESPACE
1158 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1080 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1159 "No updateable nodes found for ID `%s'\n", 1081 "No updateable nodes found for ID `%s'\n", next_id);
1160 next_id);
1161#endif 1082#endif
1162 return; /* no nodes */ 1083 return; /* no nodes */
1163 } 1084 }
1164 if (namespace->update_map == NULL) 1085 if (namespace->update_map == NULL)
1086 {
1087 /* need to construct */
1088 namespace->update_map =
1089 GNUNET_CONTAINER_multihashmap_create (2 +
1090 3 * namespace->update_node_count /
1091 4);
1092 for (i = 0; i < namespace->update_node_count; i++)
1165 { 1093 {
1166 /* need to construct */ 1094 nsn = namespace->update_nodes[i];
1167 namespace->update_map = GNUNET_CONTAINER_multihashmap_create (2 + 3 * namespace->update_node_count / 4); 1095 GNUNET_CRYPTO_hash (nsn->id, strlen (nsn->id), &hc);
1168 for (i=0;i<namespace->update_node_count;i++) 1096 GNUNET_CONTAINER_multihashmap_put (namespace->update_map,
1169 { 1097 &hc,
1170 nsn = namespace->update_nodes[i]; 1098 nsn,
1171 GNUNET_CRYPTO_hash (nsn->id, 1099 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
1172 strlen (nsn->id),
1173 &hc);
1174 GNUNET_CONTAINER_multihashmap_put (namespace->update_map,
1175 &hc,
1176 nsn,
1177 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
1178 }
1179 } 1100 }
1101 }
1180 if (next_id != NULL) 1102 if (next_id != NULL)
1181 { 1103 {
1182 GNUNET_CRYPTO_hash (next_id, 1104 GNUNET_CRYPTO_hash (next_id, strlen (next_id), &hc);
1183 strlen (next_id), 1105 pc.ip = ip;
1184 &hc); 1106 pc.ip_cls = ip_cls;
1185 pc.ip = ip; 1107 GNUNET_CONTAINER_multihashmap_get_multiple (namespace->update_map,
1186 pc.ip_cls = ip_cls; 1108 &hc, &process_update_node, &pc);
1187 GNUNET_CONTAINER_multihashmap_get_multiple (namespace->update_map, 1109 return;
1188 &hc, 1110 }
1189 &process_update_node,
1190 &pc);
1191 return;
1192 }
1193#if DEBUG_NAMESPACE 1111#if DEBUG_NAMESPACE
1194 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1112 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1195 "Calculating TREEs to find roots of update trees\n"); 1113 "Calculating TREEs to find roots of update trees\n");
1196#endif 1114#endif
1197 /* Find heads of TREEs in update graph */ 1115 /* Find heads of TREEs in update graph */
1198 nug = ++namespace->nug_gen; 1116 nug = ++namespace->nug_gen;
1199 fc.tree_array = NULL; 1117 fc.tree_array = NULL;
1200 fc.tree_array_size = 0; 1118 fc.tree_array_size = 0;
1201 1119
1202 for (i=0;i<namespace->update_node_count;i++) 1120 for (i = 0; i < namespace->update_node_count; i++)
1121 {
1122 nsn = namespace->update_nodes[i];
1123 if (nsn->nug == nug)
1203 { 1124 {
1204 nsn = namespace->update_nodes[i];
1205 if (nsn->nug == nug)
1206 {
1207#if DEBUG_NAMESPACE 1125#if DEBUG_NAMESPACE
1208 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1126 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1209 "TREE of node `%s' is %u\n", 1127 "TREE of node `%s' is %u\n", nsn->id, nsn->nug);
1210 nsn->id,
1211 nsn->nug);
1212#endif 1128#endif
1213 continue; /* already placed in TREE */ 1129 continue; /* already placed in TREE */
1214 } 1130 }
1215 GNUNET_CRYPTO_hash (nsn->update, 1131 GNUNET_CRYPTO_hash (nsn->update, strlen (nsn->update), &hc);
1216 strlen (nsn->update), 1132 nsn->nug = nug;
1217 &hc); 1133 fc.id = UINT_MAX;
1218 nsn->nug = nug; 1134 fc.nug = nug;
1219 fc.id = UINT_MAX; 1135 fc.namespace = namespace;
1136 GNUNET_CONTAINER_multihashmap_get_multiple (namespace->update_map,
1137 &hc, &find_trees, &fc);
1138 if (fc.id == UINT_MAX)
1139 {
1140 /* start new TREE */
1141 for (fc.id = 0; fc.id < fc.tree_array_size; fc.id++)
1142 {
1143 if (fc.tree_array[fc.id] == NULL)
1144 {
1145 fc.tree_array[fc.id] = nsn;
1146 nsn->tree_id = fc.id;
1147 break;
1148 }
1149 }
1150 if (fc.id == fc.tree_array_size)
1151 {
1152 GNUNET_array_append (fc.tree_array, fc.tree_array_size, nsn);
1153 nsn->tree_id = fc.id;
1154 }
1155#if DEBUG_NAMESPACE
1156 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1157 "Starting new TREE %u with node `%s'\n",
1158 nsn->tree_id, nsn->id);
1159#endif
1160 /* put all nodes with same identifier into this TREE */
1161 GNUNET_CRYPTO_hash (nsn->id, strlen (nsn->id), &hc);
1162 fc.id = nsn->tree_id;
1220 fc.nug = nug; 1163 fc.nug = nug;
1221 fc.namespace = namespace; 1164 fc.namespace = namespace;
1222 GNUNET_CONTAINER_multihashmap_get_multiple (namespace->update_map, 1165 GNUNET_CONTAINER_multihashmap_get_multiple (namespace->update_map,
1223 &hc, 1166 &hc, &find_trees, &fc);
1224 &find_trees, 1167 }
1225 &fc); 1168 else
1226 if (fc.id == UINT_MAX) 1169 {
1227 { 1170 /* make head of TREE "id" */
1228 /* start new TREE */ 1171 fc.tree_array[fc.id] = nsn;
1229 for (fc.id=0;fc.id<fc.tree_array_size;fc.id++) 1172 nsn->tree_id = fc.id;
1230 { 1173 }
1231 if (fc.tree_array[fc.id] == NULL)
1232 {
1233 fc.tree_array[fc.id] = nsn;
1234 nsn->tree_id = fc.id;
1235 break;
1236 }
1237 }
1238 if (fc.id == fc.tree_array_size)
1239 {
1240 GNUNET_array_append (fc.tree_array,
1241 fc.tree_array_size,
1242 nsn);
1243 nsn->tree_id = fc.id;
1244 }
1245#if DEBUG_NAMESPACE
1246 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1247 "Starting new TREE %u with node `%s'\n",
1248 nsn->tree_id,
1249 nsn->id);
1250#endif
1251 /* put all nodes with same identifier into this TREE */
1252 GNUNET_CRYPTO_hash (nsn->id,
1253 strlen (nsn->id),
1254 &hc);
1255 fc.id = nsn->tree_id;
1256 fc.nug = nug;
1257 fc.namespace = namespace;
1258 GNUNET_CONTAINER_multihashmap_get_multiple (namespace->update_map,
1259 &hc,
1260 &find_trees,
1261 &fc);
1262 }
1263 else
1264 {
1265 /* make head of TREE "id" */
1266 fc.tree_array[fc.id] = nsn;
1267 nsn->tree_id = fc.id;
1268 }
1269#if DEBUG_NAMESPACE 1174#if DEBUG_NAMESPACE
1270 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1175 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1271 "TREE of node `%s' is %u\n", 1176 "TREE of node `%s' is %u\n", nsn->id, fc.id);
1272 nsn->id,
1273 fc.id);
1274#endif 1177#endif
1275 } 1178 }
1276 for (i=0;i<fc.tree_array_size;i++) 1179 for (i = 0; i < fc.tree_array_size; i++)
1180 {
1181 nsn = fc.tree_array[i];
1182 if (NULL != nsn)
1277 { 1183 {
1278 nsn = fc.tree_array[i];
1279 if (NULL != nsn)
1280 {
1281#if DEBUG_NAMESPACE 1184#if DEBUG_NAMESPACE
1282 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1185 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1283 "Root of TREE %u is node `%s'\n", 1186 "Root of TREE %u is node `%s'\n", i, nsn->id);
1284 i,
1285 nsn->id);
1286#endif 1187#endif
1287 1188
1288 ip (ip_cls, 1189 ip (ip_cls, nsn->id, nsn->uri, nsn->md, nsn->update);
1289 nsn->id,
1290 nsn->uri,
1291 nsn->md,
1292 nsn->update);
1293 }
1294 } 1190 }
1295 GNUNET_array_grow (fc.tree_array, 1191 }
1296 fc.tree_array_size, 1192 GNUNET_array_grow (fc.tree_array, fc.tree_array_size, 0);
1297 0);
1298#if DEBUG_NAMESPACE 1193#if DEBUG_NAMESPACE
1299 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1194 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Done processing TREEs\n");
1300 "Done processing TREEs\n");
1301#endif 1195#endif
1302} 1196}
1303 1197
1304 1198
1305/* end of fs_namespace.c */ 1199/* end of fs_namespace.c */
1306
diff --git a/src/fs/fs_publish.c b/src/fs/fs_publish.c
index a52856c1f..87161501b 100644
--- a/src/fs/fs_publish.c
+++ b/src/fs/fs_publish.c
@@ -49,28 +49,25 @@
49 */ 49 */
50void * 50void *
51GNUNET_FS_publish_make_status_ (struct GNUNET_FS_ProgressInfo *pi, 51GNUNET_FS_publish_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
52 struct GNUNET_FS_PublishContext *pc, 52 struct GNUNET_FS_PublishContext *pc,
53 const struct GNUNET_FS_FileInformation *p, 53 const struct GNUNET_FS_FileInformation *p,
54 uint64_t offset) 54 uint64_t offset)
55{ 55{
56 pi->value.publish.pc = pc; 56 pi->value.publish.pc = pc;
57 pi->value.publish.fi = p; 57 pi->value.publish.fi = p;
58 pi->value.publish.cctx 58 pi->value.publish.cctx = p->client_info;
59 = p->client_info; 59 pi->value.publish.pctx = (NULL == p->dir) ? NULL : p->dir->client_info;
60 pi->value.publish.pctx
61 = (NULL == p->dir) ? NULL : p->dir->client_info;
62 pi->value.publish.filename = p->filename; 60 pi->value.publish.filename = p->filename;
63 pi->value.publish.size 61 pi->value.publish.size
64 = (p->is_directory) ? p->data.dir.dir_size : p->data.file.file_size; 62 = (p->is_directory) ? p->data.dir.dir_size : p->data.file.file_size;
65 pi->value.publish.eta 63 pi->value.publish.eta
66 = GNUNET_TIME_calculate_eta (p->start_time, 64 = GNUNET_TIME_calculate_eta (p->start_time,
67 offset, 65 offset, pi->value.publish.size);
68 pi->value.publish.size);
69 pi->value.publish.completed = offset; 66 pi->value.publish.completed = offset;
70 pi->value.publish.duration = GNUNET_TIME_absolute_get_duration (p->start_time); 67 pi->value.publish.duration =
68 GNUNET_TIME_absolute_get_duration (p->start_time);
71 pi->value.publish.anonymity = p->bo.anonymity_level; 69 pi->value.publish.anonymity = p->bo.anonymity_level;
72 return pc->h->upcb (pc->h->upcb_cls, 70 return pc->h->upcb (pc->h->upcb_cls, pi);
73 pi);
74} 71}
75 72
76 73
@@ -81,39 +78,37 @@ GNUNET_FS_publish_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
81 * @param tc scheduler context 78 * @param tc scheduler context
82 */ 79 */
83static void 80static void
84publish_cleanup (void *cls, 81publish_cleanup (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
85 const struct GNUNET_SCHEDULER_TaskContext *tc)
86{ 82{
87 struct GNUNET_FS_PublishContext *pc = cls; 83 struct GNUNET_FS_PublishContext *pc = cls;
88 84
89#if DEBUG_PUBLISH 85#if DEBUG_PUBLISH
90 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 86 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up publish context (done!)\n");
91 "Cleaning up publish context (done!)\n");
92#endif 87#endif
93 if (pc->fhc != NULL) 88 if (pc->fhc != NULL)
94 { 89 {
95 GNUNET_CRYPTO_hash_file_cancel (pc->fhc); 90 GNUNET_CRYPTO_hash_file_cancel (pc->fhc);
96 pc->fhc = NULL; 91 pc->fhc = NULL;
97 } 92 }
98 GNUNET_FS_file_information_destroy (pc->fi, NULL, NULL); 93 GNUNET_FS_file_information_destroy (pc->fi, NULL, NULL);
99 if (pc->namespace != NULL) 94 if (pc->namespace != NULL)
100 { 95 {
101 GNUNET_FS_namespace_delete (pc->namespace, GNUNET_NO); 96 GNUNET_FS_namespace_delete (pc->namespace, GNUNET_NO);
102 pc->namespace = NULL; 97 pc->namespace = NULL;
103 } 98 }
104 GNUNET_free_non_null (pc->nid); 99 GNUNET_free_non_null (pc->nid);
105 GNUNET_free_non_null (pc->nuid); 100 GNUNET_free_non_null (pc->nuid);
106 GNUNET_free_non_null (pc->serialization); 101 GNUNET_free_non_null (pc->serialization);
107 if (pc->dsh != NULL) 102 if (pc->dsh != NULL)
108 { 103 {
109 GNUNET_DATASTORE_disconnect (pc->dsh, GNUNET_NO); 104 GNUNET_DATASTORE_disconnect (pc->dsh, GNUNET_NO);
110 pc->dsh = NULL; 105 pc->dsh = NULL;
111 } 106 }
112 if (pc->client != NULL) 107 if (pc->client != NULL)
113 { 108 {
114 GNUNET_CLIENT_disconnect (pc->client, GNUNET_NO); 109 GNUNET_CLIENT_disconnect (pc->client, GNUNET_NO);
115 pc->client = NULL; 110 pc->client = NULL;
116 } 111 }
117 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == pc->upload_task); 112 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == pc->upload_task);
118 GNUNET_free (pc); 113 GNUNET_free (pc);
119} 114}
@@ -128,48 +123,42 @@ publish_cleanup (void *cls,
128 * @param msg error message (or NULL) 123 * @param msg error message (or NULL)
129 */ 124 */
130static void 125static void
131ds_put_cont (void *cls, 126ds_put_cont (void *cls, int success, const char *msg)
132 int success,
133 const char *msg)
134{ 127{
135 struct GNUNET_FS_PublishContext *pc = cls; 128 struct GNUNET_FS_PublishContext *pc = cls;
136 struct GNUNET_FS_ProgressInfo pi; 129 struct GNUNET_FS_ProgressInfo pi;
137 130
138 pc->qre = NULL; 131 pc->qre = NULL;
139 if (GNUNET_SYSERR == pc->in_network_wait) 132 if (GNUNET_SYSERR == pc->in_network_wait)
140 { 133 {
141 /* we were aborted in the meantime, finish shutdown! */ 134 /* we were aborted in the meantime, finish shutdown! */
142 GNUNET_SCHEDULER_add_continuation (&publish_cleanup, 135 GNUNET_SCHEDULER_add_continuation (&publish_cleanup,
143 pc, 136 pc, GNUNET_SCHEDULER_REASON_PREREQ_DONE);
144 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 137 return;
145 return; 138 }
146 }
147 GNUNET_assert (GNUNET_YES == pc->in_network_wait); 139 GNUNET_assert (GNUNET_YES == pc->in_network_wait);
148 pc->in_network_wait = GNUNET_NO; 140 pc->in_network_wait = GNUNET_NO;
149 if (GNUNET_SYSERR == success) 141 if (GNUNET_SYSERR == success)
142 {
143 GNUNET_asprintf (&pc->fi_pos->emsg, _("Publishing failed: %s"), msg);
144 pi.status = GNUNET_FS_STATUS_PUBLISH_ERROR;
145 pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL;
146 pi.value.publish.specifics.error.message = pc->fi_pos->emsg;
147 pc->fi_pos->client_info =
148 GNUNET_FS_publish_make_status_ (&pi, pc, pc->fi_pos, 0);
149 if ((pc->fi_pos->is_directory == GNUNET_NO) &&
150 (pc->fi_pos->filename != NULL) &&
151 (pc->fi_pos->data.file.do_index == GNUNET_YES))
150 { 152 {
151 GNUNET_asprintf (&pc->fi_pos->emsg, 153 /* run unindex to clean up */
152 _("Publishing failed: %s"), 154 GNUNET_FS_unindex_start (pc->h, pc->fi_pos->filename, NULL);
153 msg);
154 pi.status = GNUNET_FS_STATUS_PUBLISH_ERROR;
155 pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL;
156 pi.value.publish.specifics.error.message = pc->fi_pos->emsg;
157 pc->fi_pos->client_info = GNUNET_FS_publish_make_status_ (&pi, pc, pc->fi_pos, 0);
158 if ( (pc->fi_pos->is_directory == GNUNET_NO) &&
159 (pc->fi_pos->filename != NULL) &&
160 (pc->fi_pos->data.file.do_index == GNUNET_YES) )
161 {
162 /* run unindex to clean up */
163 GNUNET_FS_unindex_start (pc->h,
164 pc->fi_pos->filename,
165 NULL);
166 }
167 } 155 }
156 }
168 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == pc->upload_task); 157 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == pc->upload_task);
169 pc->upload_task 158 pc->upload_task
170 = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, 159 =
171 &GNUNET_FS_publish_main_, 160 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_BACKGROUND,
172 pc); 161 &GNUNET_FS_publish_main_, pc);
173} 162}
174 163
175 164
@@ -181,17 +170,19 @@ ds_put_cont (void *cls,
181 * @param p the completed upload 170 * @param p the completed upload
182 * @param pc context of the publication 171 * @param pc context of the publication
183 */ 172 */
184static void 173static void
185signal_publish_completion (struct GNUNET_FS_FileInformation *p, 174signal_publish_completion (struct GNUNET_FS_FileInformation *p,
186 struct GNUNET_FS_PublishContext *pc) 175 struct GNUNET_FS_PublishContext *pc)
187{ 176{
188 struct GNUNET_FS_ProgressInfo pi; 177 struct GNUNET_FS_ProgressInfo pi;
189 178
190 pi.status = GNUNET_FS_STATUS_PUBLISH_COMPLETED; 179 pi.status = GNUNET_FS_STATUS_PUBLISH_COMPLETED;
191 pi.value.publish.eta = GNUNET_TIME_UNIT_ZERO; 180 pi.value.publish.eta = GNUNET_TIME_UNIT_ZERO;
192 pi.value.publish.specifics.completed.chk_uri = p->chk_uri; 181 pi.value.publish.specifics.completed.chk_uri = p->chk_uri;
193 p->client_info = GNUNET_FS_publish_make_status_ (&pi, pc, p, 182 p->client_info = GNUNET_FS_publish_make_status_ (&pi, pc, p,
194 GNUNET_ntohll (p->chk_uri->data.chk.file_length)); 183 GNUNET_ntohll (p->
184 chk_uri->data.
185 chk.file_length));
195} 186}
196 187
197 188
@@ -204,28 +195,24 @@ signal_publish_completion (struct GNUNET_FS_FileInformation *p,
204 * @param pc context of the publication 195 * @param pc context of the publication
205 * @param emsg error message 196 * @param emsg error message
206 */ 197 */
207static void 198static void
208signal_publish_error (struct GNUNET_FS_FileInformation *p, 199signal_publish_error (struct GNUNET_FS_FileInformation *p,
209 struct GNUNET_FS_PublishContext *pc, 200 struct GNUNET_FS_PublishContext *pc, const char *emsg)
210 const char *emsg)
211{ 201{
212 struct GNUNET_FS_ProgressInfo pi; 202 struct GNUNET_FS_ProgressInfo pi;
213 203
214 p->emsg = GNUNET_strdup (emsg); 204 p->emsg = GNUNET_strdup (emsg);
215 pi.status = GNUNET_FS_STATUS_PUBLISH_ERROR; 205 pi.status = GNUNET_FS_STATUS_PUBLISH_ERROR;
216 pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL; 206 pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL;
217 pi.value.publish.specifics.error.message =emsg; 207 pi.value.publish.specifics.error.message = emsg;
218 p->client_info = GNUNET_FS_publish_make_status_ (&pi, pc, p, 0); 208 p->client_info = GNUNET_FS_publish_make_status_ (&pi, pc, p, 0);
219 if ( (p->is_directory == GNUNET_NO) && 209 if ((p->is_directory == GNUNET_NO) &&
220 (p->filename != NULL) && 210 (p->filename != NULL) && (p->data.file.do_index == GNUNET_YES))
221 (p->data.file.do_index == GNUNET_YES) ) 211 {
222 { 212 /* run unindex to clean up */
223 /* run unindex to clean up */ 213 GNUNET_FS_unindex_start (pc->h, p->filename, NULL);
224 GNUNET_FS_unindex_start (pc->h, 214 }
225 p->filename, 215
226 NULL);
227 }
228
229} 216}
230 217
231 218
@@ -237,16 +224,13 @@ signal_publish_error (struct GNUNET_FS_FileInformation *p,
237 * @param msg error message (typically NULL, not used) 224 * @param msg error message (typically NULL, not used)
238 */ 225 */
239static void 226static void
240finish_release_reserve (void *cls, 227finish_release_reserve (void *cls, int success, const char *msg)
241 int success,
242 const char *msg)
243{ 228{
244 struct GNUNET_FS_PublishContext *pc = cls; 229 struct GNUNET_FS_PublishContext *pc = cls;
245 230
246 pc->qre = NULL; 231 pc->qre = NULL;
247#if DEBUG_PUBLISH 232#if DEBUG_PUBLISH
248 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 233 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Releasing reserve done!\n");
249 "Releasing reserve done!\n");
250#endif 234#endif
251 signal_publish_completion (pc->fi, pc); 235 signal_publish_completion (pc->fi, pc);
252 pc->all_done = GNUNET_YES; 236 pc->all_done = GNUNET_YES;
@@ -264,34 +248,30 @@ finish_release_reserve (void *cls,
264 */ 248 */
265static void 249static void
266publish_sblocks_cont (void *cls, 250publish_sblocks_cont (void *cls,
267 const struct GNUNET_FS_Uri *uri, 251 const struct GNUNET_FS_Uri *uri, const char *emsg)
268 const char *emsg)
269{ 252{
270 struct GNUNET_FS_PublishContext *pc = cls; 253 struct GNUNET_FS_PublishContext *pc = cls;
254
271 if (NULL != emsg) 255 if (NULL != emsg)
272 { 256 {
273 signal_publish_error (pc->fi, 257 signal_publish_error (pc->fi, pc, emsg);
274 pc, 258 GNUNET_FS_publish_sync_ (pc);
275 emsg); 259 return;
276 GNUNET_FS_publish_sync_ (pc); 260 }
277 return;
278 }
279 GNUNET_assert (pc->qre == NULL); 261 GNUNET_assert (pc->qre == NULL);
280 if ( (pc->dsh != NULL) && 262 if ((pc->dsh != NULL) && (pc->rid != 0))
281 (pc->rid != 0) ) 263 {
282 { 264 pc->qre = GNUNET_DATASTORE_release_reserve (pc->dsh,
283 pc->qre = GNUNET_DATASTORE_release_reserve (pc->dsh, 265 pc->rid,
284 pc->rid, 266 UINT_MAX,
285 UINT_MAX, 267 UINT_MAX,
286 UINT_MAX, 268 GNUNET_TIME_UNIT_FOREVER_REL,
287 GNUNET_TIME_UNIT_FOREVER_REL, 269 &finish_release_reserve, pc);
288 &finish_release_reserve, 270 }
289 pc);
290 }
291 else 271 else
292 { 272 {
293 finish_release_reserve (pc, GNUNET_OK, NULL); 273 finish_release_reserve (pc, GNUNET_OK, NULL);
294 } 274 }
295} 275}
296 276
297 277
@@ -306,15 +286,12 @@ publish_sblock (struct GNUNET_FS_PublishContext *pc)
306{ 286{
307 if (NULL != pc->namespace) 287 if (NULL != pc->namespace)
308 GNUNET_FS_publish_sks (pc->h, 288 GNUNET_FS_publish_sks (pc->h,
309 pc->namespace, 289 pc->namespace,
310 pc->nid, 290 pc->nid,
311 pc->nuid, 291 pc->nuid,
312 pc->fi->meta, 292 pc->fi->meta,
313 pc->fi->chk_uri, 293 pc->fi->chk_uri,
314 &pc->fi->bo, 294 &pc->fi->bo, pc->options, &publish_sblocks_cont, pc);
315 pc->options,
316 &publish_sblocks_cont,
317 pc);
318 else 295 else
319 publish_sblocks_cont (pc, NULL, NULL); 296 publish_sblocks_cont (pc, NULL, NULL);
320} 297}
@@ -331,35 +308,33 @@ publish_sblock (struct GNUNET_FS_PublishContext *pc)
331 */ 308 */
332static void 309static void
333publish_kblocks_cont (void *cls, 310publish_kblocks_cont (void *cls,
334 const struct GNUNET_FS_Uri *uri, 311 const struct GNUNET_FS_Uri *uri, const char *emsg)
335 const char *emsg)
336{ 312{
337 struct GNUNET_FS_PublishContext *pc = cls; 313 struct GNUNET_FS_PublishContext *pc = cls;
338 struct GNUNET_FS_FileInformation *p = pc->fi_pos; 314 struct GNUNET_FS_FileInformation *p = pc->fi_pos;
339 315
340 if (NULL != emsg) 316 if (NULL != emsg)
341 { 317 {
342#if DEBUG_PUBLISH 318#if DEBUG_PUBLISH
343 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 319 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
344 "Error uploading KSK blocks: %s\n", 320 "Error uploading KSK blocks: %s\n", emsg);
345 emsg);
346#endif 321#endif
347 signal_publish_error (p, pc, emsg); 322 signal_publish_error (p, pc, emsg);
348 GNUNET_FS_file_information_sync_ (p); 323 GNUNET_FS_file_information_sync_ (p);
349 GNUNET_FS_publish_sync_ (pc); 324 GNUNET_FS_publish_sync_ (pc);
350 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == pc->upload_task); 325 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == pc->upload_task);
351 pc->upload_task 326 pc->upload_task
352 = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, 327 =
353 &GNUNET_FS_publish_main_, 328 GNUNET_SCHEDULER_add_with_priority
354 pc); 329 (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, &GNUNET_FS_publish_main_, pc);
355 return; 330 return;
356 } 331 }
357#if DEBUG_PUBLISH 332#if DEBUG_PUBLISH
358 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 333 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
359 "KSK blocks published, moving on to next file\n"); 334 "KSK blocks published, moving on to next file\n");
360#endif 335#endif
361 if (NULL != p->dir) 336 if (NULL != p->dir)
362 signal_publish_completion (p, pc); 337 signal_publish_completion (p, pc);
363 /* move on to next file */ 338 /* move on to next file */
364 if (NULL != p->next) 339 if (NULL != p->next)
365 pc->fi_pos = p->next; 340 pc->fi_pos = p->next;
@@ -367,10 +342,10 @@ publish_kblocks_cont (void *cls,
367 pc->fi_pos = p->dir; 342 pc->fi_pos = p->dir;
368 GNUNET_FS_publish_sync_ (pc); 343 GNUNET_FS_publish_sync_ (pc);
369 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == pc->upload_task); 344 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == pc->upload_task);
370 pc->upload_task 345 pc->upload_task
371 = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, 346 =
372 &GNUNET_FS_publish_main_, 347 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_BACKGROUND,
373 pc); 348 &GNUNET_FS_publish_main_, pc);
374} 349}
375 350
376 351
@@ -388,11 +363,7 @@ publish_kblocks_cont (void *cls,
388 * @return number of bytes copied to buf, 0 on error 363 * @return number of bytes copied to buf, 0 on error
389 */ 364 */
390static size_t 365static size_t
391block_reader (void *cls, 366block_reader (void *cls, uint64_t offset, size_t max, void *buf, char **emsg)
392 uint64_t offset,
393 size_t max,
394 void *buf,
395 char **emsg)
396{ 367{
397 struct GNUNET_FS_PublishContext *pc = cls; 368 struct GNUNET_FS_PublishContext *pc = cls;
398 struct GNUNET_FS_FileInformation *p; 369 struct GNUNET_FS_FileInformation *p;
@@ -401,29 +372,22 @@ block_reader (void *cls,
401 372
402 p = pc->fi_pos; 373 p = pc->fi_pos;
403 if (p->is_directory) 374 if (p->is_directory)
404 { 375 {
405 pt_size = GNUNET_MIN(max, 376 pt_size = GNUNET_MIN (max, p->data.dir.dir_size - offset);
406 p->data.dir.dir_size - offset); 377 dd = p->data.dir.dir_data;
407 dd = p->data.dir.dir_data; 378 memcpy (buf, &dd[offset], pt_size);
408 memcpy (buf, 379 }
409 &dd[offset],
410 pt_size);
411 }
412 else 380 else
413 { 381 {
414 pt_size = GNUNET_MIN(max, 382 pt_size = GNUNET_MIN (max, p->data.file.file_size - offset);
415 p->data.file.file_size - offset); 383 if (pt_size == 0)
416 if (pt_size == 0) 384 return 0; /* calling reader with pt_size==0
417 return 0; /* calling reader with pt_size==0 385 * might free buf, so don't! */
418 might free buf, so don't! */ 386 if (pt_size !=
419 if (pt_size != 387 p->data.file.reader (p->data.file.reader_cls,
420 p->data.file.reader (p->data.file.reader_cls, 388 offset, pt_size, buf, emsg))
421 offset, 389 return 0;
422 pt_size, 390 }
423 buf,
424 emsg))
425 return 0;
426 }
427 return pt_size; 391 return pt_size;
428} 392}
429 393
@@ -436,9 +400,8 @@ block_reader (void *cls,
436 * @param cls our publishing context 400 * @param cls our publishing context
437 * @param tc scheduler's task context (not used) 401 * @param tc scheduler's task context (not used)
438 */ 402 */
439static void 403static void
440encode_cont (void *cls, 404encode_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
441 const struct GNUNET_SCHEDULER_TaskContext *tc)
442{ 405{
443 struct GNUNET_FS_PublishContext *pc = cls; 406 struct GNUNET_FS_PublishContext *pc = cls;
444 struct GNUNET_FS_FileInformation *p; 407 struct GNUNET_FS_FileInformation *p;
@@ -447,30 +410,23 @@ encode_cont (void *cls,
447 uint64_t flen; 410 uint64_t flen;
448 411
449 p = pc->fi_pos; 412 p = pc->fi_pos;
450 GNUNET_FS_tree_encoder_finish (p->te, 413 GNUNET_FS_tree_encoder_finish (p->te, &p->chk_uri, &emsg);
451 &p->chk_uri,
452 &emsg);
453 p->te = NULL; 414 p->te = NULL;
454 if (NULL != emsg) 415 if (NULL != emsg)
455 { 416 {
456#if DEBUG_PUBLISH 417#if DEBUG_PUBLISH
457 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 418 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Error during tree walk: %s\n", emsg);
458 "Error during tree walk: %s\n",
459 emsg);
460#endif 419#endif
461 GNUNET_asprintf (&p->emsg, 420 GNUNET_asprintf (&p->emsg, _("Publishing failed: %s"), emsg);
462 _("Publishing failed: %s"), 421 GNUNET_free (emsg);
463 emsg); 422 pi.status = GNUNET_FS_STATUS_PUBLISH_ERROR;
464 GNUNET_free (emsg); 423 pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL;
465 pi.status = GNUNET_FS_STATUS_PUBLISH_ERROR; 424 pi.value.publish.specifics.error.message = p->emsg;
466 pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL; 425 p->client_info = GNUNET_FS_publish_make_status_ (&pi, pc, p, 0);
467 pi.value.publish.specifics.error.message = p->emsg; 426 }
468 p->client_info = GNUNET_FS_publish_make_status_ (&pi, pc, p, 0);
469 }
470#if DEBUG_PUBLISH 427#if DEBUG_PUBLISH
471 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 428 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Finished with tree encoder\n");
472 "Finished with tree encoder\n"); 429#endif
473#endif
474 /* final progress event */ 430 /* final progress event */
475 flen = GNUNET_FS_uri_chk_get_file_size (p->chk_uri); 431 flen = GNUNET_FS_uri_chk_get_file_size (p->chk_uri);
476 pi.status = GNUNET_FS_STATUS_PUBLISH_PROGRESS; 432 pi.status = GNUNET_FS_STATUS_PUBLISH_PROGRESS;
@@ -482,10 +438,10 @@ encode_cont (void *cls,
482 438
483 /* continue with main */ 439 /* continue with main */
484 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == pc->upload_task); 440 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == pc->upload_task);
485 pc->upload_task 441 pc->upload_task
486 = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, 442 =
487 &GNUNET_FS_publish_main_, 443 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_BACKGROUND,
488 pc); 444 &GNUNET_FS_publish_main_, pc);
489} 445}
490 446
491 447
@@ -503,14 +459,12 @@ encode_cont (void *cls,
503 * @param block the (encrypted) block 459 * @param block the (encrypted) block
504 * @param block_size size of block (in bytes) 460 * @param block_size size of block (in bytes)
505 */ 461 */
506static void 462static void
507block_proc (void *cls, 463block_proc (void *cls,
508 const struct ContentHashKey *chk, 464 const struct ContentHashKey *chk,
509 uint64_t offset, 465 uint64_t offset,
510 unsigned int depth, 466 unsigned int depth,
511 enum GNUNET_BLOCK_Type type, 467 enum GNUNET_BLOCK_Type type, const void *block, uint16_t block_size)
512 const void *block,
513 uint16_t block_size)
514{ 468{
515 struct GNUNET_FS_PublishContext *pc = cls; 469 struct GNUNET_FS_PublishContext *pc = cls;
516 struct GNUNET_FS_FileInformation *p; 470 struct GNUNET_FS_FileInformation *p;
@@ -518,73 +472,68 @@ block_proc (void *cls,
518 472
519 p = pc->fi_pos; 473 p = pc->fi_pos;
520 if (NULL == pc->dsh) 474 if (NULL == pc->dsh)
521 { 475 {
522#if DEBUG_PUBLISH 476#if DEBUG_PUBLISH
523 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 477 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Waiting for datastore connection\n");
524 "Waiting for datastore connection\n");
525#endif 478#endif
526 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == pc->upload_task); 479 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == pc->upload_task);
527 pc->upload_task 480 pc->upload_task
528 = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, 481 =
529 &GNUNET_FS_publish_main_, 482 GNUNET_SCHEDULER_add_with_priority
530 pc); 483 (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, &GNUNET_FS_publish_main_, pc);
531 return; 484 return;
532 } 485 }
533 486
534 GNUNET_assert (GNUNET_NO == pc->in_network_wait); 487 GNUNET_assert (GNUNET_NO == pc->in_network_wait);
535 pc->in_network_wait = GNUNET_YES; 488 pc->in_network_wait = GNUNET_YES;
536 if ( (! p->is_directory) && 489 if ((!p->is_directory) &&
537 (GNUNET_YES == p->data.file.do_index) && 490 (GNUNET_YES == p->data.file.do_index) &&
538 (type == GNUNET_BLOCK_TYPE_FS_DBLOCK) ) 491 (type == GNUNET_BLOCK_TYPE_FS_DBLOCK))
539 { 492 {
540#if DEBUG_PUBLISH 493#if DEBUG_PUBLISH
541 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 494 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
542 "Indexing block `%s' for offset %llu with index size %u\n", 495 "Indexing block `%s' for offset %llu with index size %u\n",
543 GNUNET_h2s (&chk->query), 496 GNUNET_h2s (&chk->query),
544 (unsigned long long) offset, 497 (unsigned long long) offset, sizeof (struct OnDemandBlock));
545 sizeof (struct OnDemandBlock));
546#endif 498#endif
547 odb.offset = GNUNET_htonll (offset); 499 odb.offset = GNUNET_htonll (offset);
548 odb.file_id = p->data.file.file_id; 500 odb.file_id = p->data.file.file_id;
549 GNUNET_assert (pc->qre == NULL); 501 GNUNET_assert (pc->qre == NULL);
550 pc->qre = GNUNET_DATASTORE_put (pc->dsh, 502 pc->qre = GNUNET_DATASTORE_put (pc->dsh,
551 (p->is_directory) ? 0 : pc->rid, 503 (p->is_directory) ? 0 : pc->rid,
552 &chk->query, 504 &chk->query,
553 sizeof (struct OnDemandBlock), 505 sizeof (struct OnDemandBlock),
554 &odb, 506 &odb,
555 GNUNET_BLOCK_TYPE_FS_ONDEMAND, 507 GNUNET_BLOCK_TYPE_FS_ONDEMAND,
556 p->bo.content_priority, 508 p->bo.content_priority,
557 p->bo.anonymity_level, 509 p->bo.anonymity_level,
558 p->bo.replication_level, 510 p->bo.replication_level,
559 p->bo.expiration_time, 511 p->bo.expiration_time,
560 -2, 1, 512 -2, 1,
561 GNUNET_CONSTANTS_SERVICE_TIMEOUT, 513 GNUNET_CONSTANTS_SERVICE_TIMEOUT,
562 &ds_put_cont, 514 &ds_put_cont, pc);
563 pc); 515 return;
564 return; 516 }
565 }
566#if DEBUG_PUBLISH 517#if DEBUG_PUBLISH
567 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 518 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
568 "Publishing block `%s' for offset %llu with size %u\n", 519 "Publishing block `%s' for offset %llu with size %u\n",
569 GNUNET_h2s (&chk->query), 520 GNUNET_h2s (&chk->query),
570 (unsigned long long) offset, 521 (unsigned long long) offset, (unsigned int) block_size);
571 (unsigned int) block_size);
572#endif 522#endif
573 GNUNET_assert (pc->qre == NULL); 523 GNUNET_assert (pc->qre == NULL);
574 pc->qre = GNUNET_DATASTORE_put (pc->dsh, 524 pc->qre = GNUNET_DATASTORE_put (pc->dsh,
575 (p->is_directory) ? 0 : pc->rid, 525 (p->is_directory) ? 0 : pc->rid,
576 &chk->query, 526 &chk->query,
577 block_size, 527 block_size,
578 block, 528 block,
579 type, 529 type,
580 p->bo.content_priority, 530 p->bo.content_priority,
581 p->bo.anonymity_level, 531 p->bo.anonymity_level,
582 p->bo.replication_level, 532 p->bo.replication_level,
583 p->bo.expiration_time, 533 p->bo.expiration_time,
584 -2, 1, 534 -2, 1,
585 GNUNET_CONSTANTS_SERVICE_TIMEOUT, 535 GNUNET_CONSTANTS_SERVICE_TIMEOUT,
586 &ds_put_cont, 536 &ds_put_cont, pc);
587 pc);
588} 537}
589 538
590 539
@@ -598,13 +547,11 @@ block_proc (void *cls,
598 * @param pt_size size of pt_block 547 * @param pt_size size of pt_block
599 * @param depth depth of the block in the tree, 0 for DBLOCK 548 * @param depth depth of the block in the tree, 0 for DBLOCK
600 */ 549 */
601static void 550static void
602progress_proc (void *cls, 551progress_proc (void *cls,
603 uint64_t offset, 552 uint64_t offset,
604 const void *pt_block, 553 const void *pt_block, size_t pt_size, unsigned int depth)
605 size_t pt_size, 554{
606 unsigned int depth)
607{
608 struct GNUNET_FS_PublishContext *pc = cls; 555 struct GNUNET_FS_PublishContext *pc = cls;
609 struct GNUNET_FS_FileInformation *p; 556 struct GNUNET_FS_FileInformation *p;
610 struct GNUNET_FS_ProgressInfo pi; 557 struct GNUNET_FS_ProgressInfo pi;
@@ -627,7 +574,7 @@ progress_proc (void *cls,
627 * @param pc overall upload data 574 * @param pc overall upload data
628 */ 575 */
629static void 576static void
630publish_content (struct GNUNET_FS_PublishContext *pc) 577publish_content (struct GNUNET_FS_PublishContext *pc)
631{ 578{
632 struct GNUNET_FS_FileInformation *p; 579 struct GNUNET_FS_FileInformation *p;
633 char *emsg; 580 char *emsg;
@@ -639,77 +586,69 @@ publish_content (struct GNUNET_FS_PublishContext *pc)
639 p = pc->fi_pos; 586 p = pc->fi_pos;
640 GNUNET_assert (p != NULL); 587 GNUNET_assert (p != NULL);
641 if (NULL == p->te) 588 if (NULL == p->te)
589 {
590 if (p->is_directory)
642 { 591 {
643 if (p->is_directory)
644 {
645#if DEBUG_PUBLISH 592#if DEBUG_PUBLISH
646 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 593 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating directory\n");
647 "Creating directory\n");
648#endif 594#endif
649 db = GNUNET_FS_directory_builder_create (p->meta); 595 db = GNUNET_FS_directory_builder_create (p->meta);
650 dirpos = p->data.dir.entries; 596 dirpos = p->data.dir.entries;
651 while (NULL != dirpos) 597 while (NULL != dirpos)
652 { 598 {
653 if (dirpos->is_directory) 599 if (dirpos->is_directory)
654 { 600 {
655 raw_data = dirpos->data.dir.dir_data; 601 raw_data = dirpos->data.dir.dir_data;
656 dirpos->data.dir.dir_data = NULL; 602 dirpos->data.dir.dir_data = NULL;
657 } 603 }
658 else 604 else
659 { 605 {
660 raw_data = NULL; 606 raw_data = NULL;
661 if ( (dirpos->data.file.file_size < MAX_INLINE_SIZE) && 607 if ((dirpos->data.file.file_size < MAX_INLINE_SIZE) &&
662 (dirpos->data.file.file_size > 0) ) 608 (dirpos->data.file.file_size > 0))
663 { 609 {
664 raw_data = GNUNET_malloc (dirpos->data.file.file_size); 610 raw_data = GNUNET_malloc (dirpos->data.file.file_size);
665 emsg = NULL; 611 emsg = NULL;
666 if (dirpos->data.file.file_size != 612 if (dirpos->data.file.file_size !=
667 dirpos->data.file.reader (dirpos->data.file.reader_cls, 613 dirpos->data.file.reader (dirpos->data.file.reader_cls,
668 0, 614 0,
669 dirpos->data.file.file_size, 615 dirpos->data.file.file_size,
670 raw_data, 616 raw_data, &emsg))
671 &emsg)) 617 {
672 { 618 GNUNET_free_non_null (emsg);
673 GNUNET_free_non_null (emsg); 619 GNUNET_free (raw_data);
674 GNUNET_free (raw_data); 620 raw_data = NULL;
675 raw_data = NULL; 621 }
676 } 622 }
677 } 623 }
678 } 624 GNUNET_FS_directory_builder_add (db,
679 GNUNET_FS_directory_builder_add (db, 625 dirpos->chk_uri,
680 dirpos->chk_uri, 626 dirpos->meta, raw_data);
681 dirpos->meta, 627 GNUNET_free_non_null (raw_data);
682 raw_data); 628 dirpos = dirpos->next;
683 GNUNET_free_non_null (raw_data); 629 }
684 dirpos = dirpos->next; 630 GNUNET_free_non_null (p->data.dir.dir_data);
685 } 631 p->data.dir.dir_data = NULL;
686 GNUNET_free_non_null (p->data.dir.dir_data); 632 p->data.dir.dir_size = 0;
687 p->data.dir.dir_data = NULL; 633 GNUNET_FS_directory_builder_finish (db,
688 p->data.dir.dir_size = 0; 634 &p->data.dir.dir_size,
689 GNUNET_FS_directory_builder_finish (db, 635 &p->data.dir.dir_data);
690 &p->data.dir.dir_size, 636 GNUNET_FS_file_information_sync_ (p);
691 &p->data.dir.dir_data); 637 }
692 GNUNET_FS_file_information_sync_ (p); 638 size = (p->is_directory) ? p->data.dir.dir_size : p->data.file.file_size;
693 }
694 size = (p->is_directory)
695 ? p->data.dir.dir_size
696 : p->data.file.file_size;
697#if DEBUG_PUBLISH 639#if DEBUG_PUBLISH
698 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 640 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating tree encoder\n");
699 "Creating tree encoder\n");
700#endif 641#endif
701 p->te = GNUNET_FS_tree_encoder_create (pc->h, 642 p->te = GNUNET_FS_tree_encoder_create (pc->h,
702 size, 643 size,
703 pc, 644 pc,
704 &block_reader, 645 &block_reader,
705 &block_proc, 646 &block_proc,
706 &progress_proc, 647 &progress_proc, &encode_cont);
707 &encode_cont); 648
708 649 }
709 }
710#if DEBUG_PUBLISH 650#if DEBUG_PUBLISH
711 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 651 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Processing next block from tree\n");
712 "Processing next block from tree\n");
713#endif 652#endif
714 GNUNET_FS_tree_encoder_next (p->te); 653 GNUNET_FS_tree_encoder_next (p->te);
715} 654}
@@ -723,8 +662,7 @@ publish_content (struct GNUNET_FS_PublishContext *pc)
723 * @param msg the response we got 662 * @param msg the response we got
724 */ 663 */
725static void 664static void
726process_index_start_response (void *cls, 665process_index_start_response (void *cls, const struct GNUNET_MessageHeader *msg)
727 const struct GNUNET_MessageHeader *msg)
728{ 666{
729 struct GNUNET_FS_PublishContext *pc = cls; 667 struct GNUNET_FS_PublishContext *pc = cls;
730 struct GNUNET_FS_FileInformation *p; 668 struct GNUNET_FS_FileInformation *p;
@@ -735,32 +673,33 @@ process_index_start_response (void *cls,
735 pc->client = NULL; 673 pc->client = NULL;
736 p = pc->fi_pos; 674 p = pc->fi_pos;
737 if (msg == NULL) 675 if (msg == NULL)
738 { 676 {
739 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 677 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
740 _("Can not index file `%s': %s. Will try to insert instead.\n"), 678 _
741 p->filename, 679 ("Can not index file `%s': %s. Will try to insert instead.\n"),
742 _("timeout on index-start request to `fs' service")); 680 p->filename,
743 p->data.file.do_index = GNUNET_NO; 681 _("timeout on index-start request to `fs' service"));
744 GNUNET_FS_file_information_sync_ (p); 682 p->data.file.do_index = GNUNET_NO;
745 publish_content (pc); 683 GNUNET_FS_file_information_sync_ (p);
746 return; 684 publish_content (pc);
747 } 685 return;
686 }
748 if (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_FS_INDEX_START_OK) 687 if (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_FS_INDEX_START_OK)
749 { 688 {
750 msize = ntohs (msg->size); 689 msize = ntohs (msg->size);
751 emsg = (const char *) &msg[1]; 690 emsg = (const char *) &msg[1];
752 if ( (msize <= sizeof (struct GNUNET_MessageHeader)) || 691 if ((msize <= sizeof (struct GNUNET_MessageHeader)) ||
753 (emsg[msize - sizeof(struct GNUNET_MessageHeader) - 1] != '\0') ) 692 (emsg[msize - sizeof (struct GNUNET_MessageHeader) - 1] != '\0'))
754 emsg = gettext_noop ("unknown error"); 693 emsg = gettext_noop ("unknown error");
755 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 694 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
756 _("Can not index file `%s': %s. Will try to insert instead.\n"), 695 _
757 p->filename, 696 ("Can not index file `%s': %s. Will try to insert instead.\n"),
758 gettext (emsg)); 697 p->filename, gettext (emsg));
759 p->data.file.do_index = GNUNET_NO; 698 p->data.file.do_index = GNUNET_NO;
760 GNUNET_FS_file_information_sync_ (p); 699 GNUNET_FS_file_information_sync_ (p);
761 publish_content (pc); 700 publish_content (pc);
762 return; 701 return;
763 } 702 }
764 p->data.file.index_start_confirmed = GNUNET_YES; 703 p->data.file.index_start_confirmed = GNUNET_YES;
765 /* success! continue with indexing */ 704 /* success! continue with indexing */
766 GNUNET_FS_file_information_sync_ (p); 705 GNUNET_FS_file_information_sync_ (p);
@@ -775,10 +714,8 @@ process_index_start_response (void *cls,
775 * @param cls closure, our publishing context 714 * @param cls closure, our publishing context
776 * @param res resulting hash, NULL on error 715 * @param res resulting hash, NULL on error
777 */ 716 */
778static void 717static void
779hash_for_index_cb (void *cls, 718hash_for_index_cb (void *cls, const GNUNET_HashCode * res)
780 const GNUNET_HashCode *
781 res)
782{ 719{
783 struct GNUNET_FS_PublishContext *pc = cls; 720 struct GNUNET_FS_PublishContext *pc = cls;
784 struct GNUNET_FS_FileInformation *p; 721 struct GNUNET_FS_FileInformation *p;
@@ -791,106 +728,97 @@ hash_for_index_cb (void *cls,
791 728
792 pc->fhc = NULL; 729 pc->fhc = NULL;
793 p = pc->fi_pos; 730 p = pc->fi_pos;
794 if (NULL == res) 731 if (NULL == res)
795 { 732 {
796 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 733 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
797 _("Can not index file `%s': %s. Will try to insert instead.\n"), 734 _
798 p->filename, 735 ("Can not index file `%s': %s. Will try to insert instead.\n"),
799 _("failed to compute hash")); 736 p->filename, _("failed to compute hash"));
800 p->data.file.do_index = GNUNET_NO; 737 p->data.file.do_index = GNUNET_NO;
801 GNUNET_FS_file_information_sync_ (p); 738 GNUNET_FS_file_information_sync_ (p);
802 publish_content (pc); 739 publish_content (pc);
803 return; 740 return;
804 } 741 }
805 if (GNUNET_YES == p->data.file.index_start_confirmed) 742 if (GNUNET_YES == p->data.file.index_start_confirmed)
806 { 743 {
807 publish_content (pc); 744 publish_content (pc);
808 return; 745 return;
809 } 746 }
810 fn = GNUNET_STRINGS_filename_expand (p->filename); 747 fn = GNUNET_STRINGS_filename_expand (p->filename);
811 GNUNET_assert (fn != NULL); 748 GNUNET_assert (fn != NULL);
812 slen = strlen (fn) + 1; 749 slen = strlen (fn) + 1;
813 if (slen >= GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof(struct IndexStartMessage)) 750 if (slen >=
814 { 751 GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (struct IndexStartMessage))
815 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 752 {
816 _("Can not index file `%s': %s. Will try to insert instead.\n"), 753 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
817 fn, 754 _
818 _("filename too long")); 755 ("Can not index file `%s': %s. Will try to insert instead.\n"),
819 GNUNET_free (fn); 756 fn, _("filename too long"));
820 p->data.file.do_index = GNUNET_NO; 757 GNUNET_free (fn);
821 GNUNET_FS_file_information_sync_ (p); 758 p->data.file.do_index = GNUNET_NO;
822 publish_content (pc); 759 GNUNET_FS_file_information_sync_ (p);
823 return; 760 publish_content (pc);
824 } 761 return;
762 }
825#if DEBUG_PUBLISH 763#if DEBUG_PUBLISH
826 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 764 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
827 "Hash of indexed file `%s' is `%s'\n", 765 "Hash of indexed file `%s' is `%s'\n",
828 p->filename, 766 p->filename, GNUNET_h2s (res));
829 GNUNET_h2s (res));
830#endif 767#endif
831 if (0 != (pc->options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY)) 768 if (0 != (pc->options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY))
832 { 769 {
833 p->data.file.file_id = *res; 770 p->data.file.file_id = *res;
834 p->data.file.have_hash = GNUNET_YES; 771 p->data.file.have_hash = GNUNET_YES;
835 p->data.file.index_start_confirmed = GNUNET_YES; 772 p->data.file.index_start_confirmed = GNUNET_YES;
836 GNUNET_FS_file_information_sync_ (p); 773 GNUNET_FS_file_information_sync_ (p);
837 publish_content (pc); 774 publish_content (pc);
838 GNUNET_free (fn); 775 GNUNET_free (fn);
839 return; 776 return;
840 } 777 }
841 client = GNUNET_CLIENT_connect ("fs", 778 client = GNUNET_CLIENT_connect ("fs", pc->h->cfg);
842 pc->h->cfg);
843 if (NULL == client) 779 if (NULL == client)
844 { 780 {
845 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 781 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
846 _("Can not index file `%s': %s. Will try to insert instead.\n"), 782 _
847 p->filename, 783 ("Can not index file `%s': %s. Will try to insert instead.\n"),
848 _("could not connect to `fs' service")); 784 p->filename, _("could not connect to `fs' service"));
849 p->data.file.do_index = GNUNET_NO; 785 p->data.file.do_index = GNUNET_NO;
850 publish_content (pc); 786 publish_content (pc);
851 GNUNET_free (fn); 787 GNUNET_free (fn);
852 return; 788 return;
853 } 789 }
854 if (p->data.file.have_hash != GNUNET_YES) 790 if (p->data.file.have_hash != GNUNET_YES)
855 { 791 {
856 p->data.file.file_id = *res; 792 p->data.file.file_id = *res;
857 p->data.file.have_hash = GNUNET_YES; 793 p->data.file.have_hash = GNUNET_YES;
858 GNUNET_FS_file_information_sync_ (p); 794 GNUNET_FS_file_information_sync_ (p);
859 } 795 }
860 ism = GNUNET_malloc (sizeof(struct IndexStartMessage) + 796 ism = GNUNET_malloc (sizeof (struct IndexStartMessage) + slen);
861 slen); 797 ism->header.size = htons (sizeof (struct IndexStartMessage) + slen);
862 ism->header.size = htons(sizeof(struct IndexStartMessage) + 798 ism->header.type = htons (GNUNET_MESSAGE_TYPE_FS_INDEX_START);
863 slen); 799 if (GNUNET_OK == GNUNET_DISK_file_get_identifiers (p->filename, &dev, &ino))
864 ism->header.type = htons(GNUNET_MESSAGE_TYPE_FS_INDEX_START); 800 {
865 if (GNUNET_OK == 801 ism->device = GNUNET_htonll (dev);
866 GNUNET_DISK_file_get_identifiers (p->filename, 802 ism->inode = GNUNET_htonll (ino);
867 &dev, 803 }
868 &ino))
869 {
870 ism->device = GNUNET_htonll (dev);
871 ism->inode = GNUNET_htonll(ino);
872 }
873#if DEBUG_PUBLISH 804#if DEBUG_PUBLISH
874 else 805 else
875 { 806 {
876 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 807 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
877 _("Failed to get file identifiers for `%s'\n"), 808 _("Failed to get file identifiers for `%s'\n"), p->filename);
878 p->filename); 809 }
879 }
880#endif 810#endif
881 ism->file_id = *res; 811 ism->file_id = *res;
882 memcpy (&ism[1], 812 memcpy (&ism[1], fn, slen);
883 fn,
884 slen);
885 GNUNET_free (fn); 813 GNUNET_free (fn);
886 pc->client = client; 814 pc->client = client;
887 GNUNET_break (GNUNET_YES == 815 GNUNET_break (GNUNET_YES ==
888 GNUNET_CLIENT_transmit_and_get_response (client, 816 GNUNET_CLIENT_transmit_and_get_response (client,
889 &ism->header, 817 &ism->header,
890 GNUNET_TIME_UNIT_FOREVER_REL, 818 GNUNET_TIME_UNIT_FOREVER_REL,
891 GNUNET_YES, 819 GNUNET_YES,
892 &process_index_start_response, 820 &process_index_start_response,
893 pc)); 821 pc));
894 GNUNET_free (ism); 822 GNUNET_free (ism);
895} 823}
896 824
@@ -903,7 +831,7 @@ hash_for_index_cb (void *cls,
903 */ 831 */
904void 832void
905GNUNET_FS_publish_main_ (void *cls, 833GNUNET_FS_publish_main_ (void *cls,
906 const struct GNUNET_SCHEDULER_TaskContext *tc) 834 const struct GNUNET_SCHEDULER_TaskContext *tc)
907{ 835{
908 struct GNUNET_FS_PublishContext *pc = cls; 836 struct GNUNET_FS_PublishContext *pc = cls;
909 struct GNUNET_FS_ProgressInfo pi; 837 struct GNUNET_FS_ProgressInfo pi;
@@ -911,135 +839,119 @@ GNUNET_FS_publish_main_ (void *cls,
911 struct GNUNET_FS_Uri *loc; 839 struct GNUNET_FS_Uri *loc;
912 char *fn; 840 char *fn;
913 841
914 pc->upload_task = GNUNET_SCHEDULER_NO_TASK; 842 pc->upload_task = GNUNET_SCHEDULER_NO_TASK;
915 p = pc->fi_pos; 843 p = pc->fi_pos;
916 if (NULL == p) 844 if (NULL == p)
917 { 845 {
918#if DEBUG_PUBLISH 846#if DEBUG_PUBLISH
919 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 847 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
920 "Publishing complete, now publishing SKS and KSK blocks.\n"); 848 "Publishing complete, now publishing SKS and KSK blocks.\n");
921#endif 849#endif
922 /* upload of entire hierarchy complete, 850 /* upload of entire hierarchy complete,
923 publish namespace entries */ 851 * publish namespace entries */
924 GNUNET_FS_publish_sync_ (pc); 852 GNUNET_FS_publish_sync_ (pc);
925 publish_sblock (pc); 853 publish_sblock (pc);
926 return; 854 return;
927 } 855 }
928 /* find starting position */ 856 /* find starting position */
929 while ( (p->is_directory) && 857 while ((p->is_directory) &&
930 (NULL != p->data.dir.entries) && 858 (NULL != p->data.dir.entries) &&
931 (NULL == p->emsg) && 859 (NULL == p->emsg) && (NULL == p->data.dir.entries->chk_uri))
932 (NULL == p->data.dir.entries->chk_uri) ) 860 {
933 { 861 p = p->data.dir.entries;
934 p = p->data.dir.entries; 862 pc->fi_pos = p;
935 pc->fi_pos = p; 863 GNUNET_FS_publish_sync_ (pc);
936 GNUNET_FS_publish_sync_ (pc); 864 }
937 }
938 /* abort on error */ 865 /* abort on error */
939 if (NULL != p->emsg) 866 if (NULL != p->emsg)
940 { 867 {
941#if DEBUG_PUBLISH 868#if DEBUG_PUBLISH
942 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 869 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Error uploading: %s\n", p->emsg);
943 "Error uploading: %s\n",
944 p->emsg);
945#endif 870#endif
946 /* error with current file, abort all 871 /* error with current file, abort all
947 related files as well! */ 872 * related files as well! */
948 while (NULL != p->dir) 873 while (NULL != p->dir)
949 { 874 {
950 fn = GNUNET_CONTAINER_meta_data_get_by_type (p->meta, 875 fn = GNUNET_CONTAINER_meta_data_get_by_type (p->meta,
951 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME); 876 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME);
952 p = p->dir; 877 p = p->dir;
953 if (fn != NULL) 878 if (fn != NULL)
954 { 879 {
955 GNUNET_asprintf (&p->emsg, 880 GNUNET_asprintf (&p->emsg,
956 _("Recursive upload failed at `%s': %s"), 881 _("Recursive upload failed at `%s': %s"), fn, p->emsg);
957 fn, 882 GNUNET_free (fn);
958 p->emsg); 883 }
959 GNUNET_free (fn); 884 else
960 } 885 {
961 else 886 GNUNET_asprintf (&p->emsg, _("Recursive upload failed: %s"), p->emsg);
962 { 887 }
963 GNUNET_asprintf (&p->emsg, 888 pi.status = GNUNET_FS_STATUS_PUBLISH_ERROR;
964 _("Recursive upload failed: %s"), 889 pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL;
965 p->emsg); 890 pi.value.publish.specifics.error.message = p->emsg;
966 } 891 p->client_info = GNUNET_FS_publish_make_status_ (&pi, pc, p, 0);
967 pi.status = GNUNET_FS_STATUS_PUBLISH_ERROR;
968 pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL;
969 pi.value.publish.specifics.error.message = p->emsg;
970 p->client_info = GNUNET_FS_publish_make_status_ (&pi, pc, p, 0);
971 }
972 pc->all_done = GNUNET_YES;
973 GNUNET_FS_publish_sync_ (pc);
974 return;
975 } 892 }
893 pc->all_done = GNUNET_YES;
894 GNUNET_FS_publish_sync_ (pc);
895 return;
896 }
976 /* handle completion */ 897 /* handle completion */
977 if (NULL != p->chk_uri) 898 if (NULL != p->chk_uri)
978 { 899 {
979#if DEBUG_PUBLISH 900#if DEBUG_PUBLISH
980 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 901 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
981 "File upload complete, now publishing KSK blocks.\n"); 902 "File upload complete, now publishing KSK blocks.\n");
982#endif 903#endif
983 if (0 == p->bo.anonymity_level) 904 if (0 == p->bo.anonymity_level)
984 { 905 {
985 /* zero anonymity, box CHK URI in LOC URI */ 906 /* zero anonymity, box CHK URI in LOC URI */
986 loc = GNUNET_FS_uri_loc_create (p->chk_uri, 907 loc = GNUNET_FS_uri_loc_create (p->chk_uri,
987 pc->h->cfg, 908 pc->h->cfg, p->bo.expiration_time);
988 p->bo.expiration_time); 909 GNUNET_FS_uri_destroy (p->chk_uri);
989 GNUNET_FS_uri_destroy (p->chk_uri); 910 p->chk_uri = loc;
990 p->chk_uri = loc;
991 }
992 GNUNET_FS_publish_sync_ (pc);
993 /* upload of "p" complete, publish KBlocks! */
994 if (p->keywords != NULL)
995 {
996 GNUNET_FS_publish_ksk (pc->h,
997 p->keywords,
998 p->meta,
999 p->chk_uri,
1000 &p->bo,
1001 pc->options,
1002 &publish_kblocks_cont,
1003 pc);
1004 }
1005 else
1006 {
1007 publish_kblocks_cont (pc,
1008 p->chk_uri,
1009 NULL);
1010 }
1011 return;
1012 } 911 }
1013 if ( (!p->is_directory) && 912 GNUNET_FS_publish_sync_ (pc);
1014 (p->data.file.do_index) ) 913 /* upload of "p" complete, publish KBlocks! */
914 if (p->keywords != NULL)
1015 { 915 {
1016 if (NULL == p->filename) 916 GNUNET_FS_publish_ksk (pc->h,
1017 { 917 p->keywords,
1018 p->data.file.do_index = GNUNET_NO; 918 p->meta,
1019 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 919 p->chk_uri,
1020 _("Can not index file `%s': %s. Will try to insert instead.\n"), 920 &p->bo, pc->options, &publish_kblocks_cont, pc);
1021 "<no-name>", 921 }
1022 _("needs to be an actual file")); 922 else
1023 GNUNET_FS_file_information_sync_ (p); 923 {
1024 publish_content (pc); 924 publish_kblocks_cont (pc, p->chk_uri, NULL);
1025 return; 925 }
1026 } 926 return;
1027 if (p->data.file.have_hash) 927 }
1028 { 928 if ((!p->is_directory) && (p->data.file.do_index))
1029 hash_for_index_cb (pc, 929 {
1030 &p->data.file.file_id); 930 if (NULL == p->filename)
1031 } 931 {
1032 else 932 p->data.file.do_index = GNUNET_NO;
1033 { 933 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1034 p->start_time = GNUNET_TIME_absolute_get (); 934 _
1035 pc->fhc = GNUNET_CRYPTO_hash_file (GNUNET_SCHEDULER_PRIORITY_IDLE, 935 ("Can not index file `%s': %s. Will try to insert instead.\n"),
1036 p->filename, 936 "<no-name>", _("needs to be an actual file"));
1037 HASHING_BLOCKSIZE, 937 GNUNET_FS_file_information_sync_ (p);
1038 &hash_for_index_cb, 938 publish_content (pc);
1039 pc);
1040 }
1041 return; 939 return;
1042 } 940 }
941 if (p->data.file.have_hash)
942 {
943 hash_for_index_cb (pc, &p->data.file.file_id);
944 }
945 else
946 {
947 p->start_time = GNUNET_TIME_absolute_get ();
948 pc->fhc = GNUNET_CRYPTO_hash_file (GNUNET_SCHEDULER_PRIORITY_IDLE,
949 p->filename,
950 HASHING_BLOCKSIZE,
951 &hash_for_index_cb, pc);
952 }
953 return;
954 }
1043 publish_content (pc); 955 publish_content (pc);
1044} 956}
1045 957
@@ -1059,14 +971,13 @@ GNUNET_FS_publish_main_ (void *cls,
1059 * @return GNUNET_OK to continue (always) 971 * @return GNUNET_OK to continue (always)
1060 */ 972 */
1061static int 973static int
1062fip_signal_start(void *cls, 974fip_signal_start (void *cls,
1063 struct GNUNET_FS_FileInformation *fi, 975 struct GNUNET_FS_FileInformation *fi,
1064 uint64_t length, 976 uint64_t length,
1065 struct GNUNET_CONTAINER_MetaData *meta, 977 struct GNUNET_CONTAINER_MetaData *meta,
1066 struct GNUNET_FS_Uri **uri, 978 struct GNUNET_FS_Uri **uri,
1067 struct GNUNET_FS_BlockOptions *bo, 979 struct GNUNET_FS_BlockOptions *bo,
1068 int *do_index, 980 int *do_index, void **client_info)
1069 void **client_info)
1070{ 981{
1071 struct GNUNET_FS_PublishContext *pc = cls; 982 struct GNUNET_FS_PublishContext *pc = cls;
1072 struct GNUNET_FS_ProgressInfo pi; 983 struct GNUNET_FS_ProgressInfo pi;
@@ -1074,38 +985,39 @@ fip_signal_start(void *cls,
1074 uint64_t left; 985 uint64_t left;
1075 986
1076#if DEBUG_PUBLISH 987#if DEBUG_PUBLISH
1077 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 988 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting publish operation\n");
1078 "Starting publish operation\n");
1079#endif 989#endif
1080 if (*do_index) 990 if (*do_index)
1081 { 991 {
1082 /* space for on-demand blocks */ 992 /* space for on-demand blocks */
1083 pc->reserve_space += ((length + DBLOCK_SIZE - 1) / DBLOCK_SIZE) * sizeof (struct OnDemandBlock); 993 pc->reserve_space +=
1084 } 994 ((length + DBLOCK_SIZE -
995 1) / DBLOCK_SIZE) * sizeof (struct OnDemandBlock);
996 }
1085 else 997 else
1086 { 998 {
1087 /* space for DBlocks */ 999 /* space for DBlocks */
1088 pc->reserve_space += length; 1000 pc->reserve_space += length;
1089 } 1001 }
1090 /* entries for IBlocks and DBlocks, space for IBlocks */ 1002 /* entries for IBlocks and DBlocks, space for IBlocks */
1091 left = length; 1003 left = length;
1092 while (1) 1004 while (1)
1093 { 1005 {
1094 left = (left + DBLOCK_SIZE - 1) / DBLOCK_SIZE; 1006 left = (left + DBLOCK_SIZE - 1) / DBLOCK_SIZE;
1095 pc->reserve_entries += left; 1007 pc->reserve_entries += left;
1096 if (left <= 1) 1008 if (left <= 1)
1097 break; 1009 break;
1098 left = left * sizeof (struct ContentHashKey); 1010 left = left * sizeof (struct ContentHashKey);
1099 pc->reserve_space += left; 1011 pc->reserve_space += left;
1100 } 1012 }
1101 pc->reserve_entries++; 1013 pc->reserve_entries++;
1102 /* entries and space for keywords */ 1014 /* entries and space for keywords */
1103 if (NULL != *uri) 1015 if (NULL != *uri)
1104 { 1016 {
1105 kc = GNUNET_FS_uri_ksk_get_keyword_count (*uri); 1017 kc = GNUNET_FS_uri_ksk_get_keyword_count (*uri);
1106 pc->reserve_entries += kc; 1018 pc->reserve_entries += kc;
1107 pc->reserve_space += GNUNET_SERVER_MAX_MESSAGE_SIZE * kc; 1019 pc->reserve_space += GNUNET_SERVER_MAX_MESSAGE_SIZE * kc;
1108 } 1020 }
1109 pi.status = GNUNET_FS_STATUS_PUBLISH_START; 1021 pi.status = GNUNET_FS_STATUS_PUBLISH_START;
1110 *client_info = GNUNET_FS_publish_make_status_ (&pi, pc, fi, 0); 1022 *client_info = GNUNET_FS_publish_make_status_ (&pi, pc, fi, 0);
1111 GNUNET_FS_file_information_sync_ (fi); 1023 GNUNET_FS_file_information_sync_ (fi);
@@ -1128,39 +1040,37 @@ fip_signal_start(void *cls,
1128 * @return GNUNET_OK to continue (always) 1040 * @return GNUNET_OK to continue (always)
1129 */ 1041 */
1130static int 1042static int
1131fip_signal_suspend(void *cls, 1043fip_signal_suspend (void *cls,
1132 struct GNUNET_FS_FileInformation *fi, 1044 struct GNUNET_FS_FileInformation *fi,
1133 uint64_t length, 1045 uint64_t length,
1134 struct GNUNET_CONTAINER_MetaData *meta, 1046 struct GNUNET_CONTAINER_MetaData *meta,
1135 struct GNUNET_FS_Uri **uri, 1047 struct GNUNET_FS_Uri **uri,
1136 struct GNUNET_FS_BlockOptions *bo, 1048 struct GNUNET_FS_BlockOptions *bo,
1137 int *do_index, 1049 int *do_index, void **client_info)
1138 void **client_info)
1139{ 1050{
1140 struct GNUNET_FS_PublishContext*pc = cls; 1051 struct GNUNET_FS_PublishContext *pc = cls;
1141 struct GNUNET_FS_ProgressInfo pi; 1052 struct GNUNET_FS_ProgressInfo pi;
1142 uint64_t off; 1053 uint64_t off;
1143 1054
1144#if DEBUG_PUBLISH 1055#if DEBUG_PUBLISH
1145 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1056 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Suspending publish operation\n");
1146 "Suspending publish operation\n");
1147#endif 1057#endif
1148 GNUNET_free_non_null (fi->serialization); 1058 GNUNET_free_non_null (fi->serialization);
1149 fi->serialization = NULL; 1059 fi->serialization = NULL;
1150 off = (fi->chk_uri == NULL) ? 0 : length; 1060 off = (fi->chk_uri == NULL) ? 0 : length;
1151 pi.status = GNUNET_FS_STATUS_PUBLISH_SUSPEND; 1061 pi.status = GNUNET_FS_STATUS_PUBLISH_SUSPEND;
1152 GNUNET_break (NULL == GNUNET_FS_publish_make_status_ (&pi, pc, fi, off)); 1062 GNUNET_break (NULL == GNUNET_FS_publish_make_status_ (&pi, pc, fi, off));
1153 *client_info = NULL; 1063 *client_info = NULL;
1154 if (NULL != pc->qre) 1064 if (NULL != pc->qre)
1155 { 1065 {
1156 GNUNET_DATASTORE_cancel (pc->qre); 1066 GNUNET_DATASTORE_cancel (pc->qre);
1157 pc->qre = NULL; 1067 pc->qre = NULL;
1158 } 1068 }
1159 if (NULL != pc->dsh) 1069 if (NULL != pc->dsh)
1160 { 1070 {
1161 GNUNET_DATASTORE_disconnect (pc->dsh, GNUNET_NO); 1071 GNUNET_DATASTORE_disconnect (pc->dsh, GNUNET_NO);
1162 pc->dsh = NULL; 1072 pc->dsh = NULL;
1163 } 1073 }
1164 pc->rid = 0; 1074 pc->rid = 0;
1165 return GNUNET_OK; 1075 return GNUNET_OK;
1166} 1076}
@@ -1178,13 +1088,11 @@ GNUNET_FS_publish_signal_suspend_ (void *cls)
1178 struct GNUNET_FS_PublishContext *pc = cls; 1088 struct GNUNET_FS_PublishContext *pc = cls;
1179 1089
1180 if (GNUNET_SCHEDULER_NO_TASK != pc->upload_task) 1090 if (GNUNET_SCHEDULER_NO_TASK != pc->upload_task)
1181 { 1091 {
1182 GNUNET_SCHEDULER_cancel (pc->upload_task); 1092 GNUNET_SCHEDULER_cancel (pc->upload_task);
1183 pc->upload_task = GNUNET_SCHEDULER_NO_TASK; 1093 pc->upload_task = GNUNET_SCHEDULER_NO_TASK;
1184 } 1094 }
1185 GNUNET_FS_file_information_inspect (pc->fi, 1095 GNUNET_FS_file_information_inspect (pc->fi, &fip_signal_suspend, pc);
1186 &fip_signal_suspend,
1187 pc);
1188 GNUNET_FS_end_top (pc->h, pc->top); 1096 GNUNET_FS_end_top (pc->h, pc->top);
1189 pc->top = NULL; 1097 pc->top = NULL;
1190 publish_cleanup (pc, NULL); 1098 publish_cleanup (pc, NULL);
@@ -1200,35 +1108,27 @@ GNUNET_FS_publish_signal_suspend_ (void *cls)
1200 * @param msg error message on error, otherwise NULL 1108 * @param msg error message on error, otherwise NULL
1201 */ 1109 */
1202static void 1110static void
1203finish_reserve (void *cls, 1111finish_reserve (void *cls, int success, const char *msg)
1204 int success,
1205 const char *msg)
1206{ 1112{
1207 struct GNUNET_FS_PublishContext *pc = cls; 1113 struct GNUNET_FS_PublishContext *pc = cls;
1208 1114
1209 pc->qre = NULL; 1115 pc->qre = NULL;
1210#if DEBUG_PUBLISH 1116#if DEBUG_PUBLISH
1211 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1117 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Reservation complete (%d)!\n", success);
1212 "Reservation complete (%d)!\n",
1213 success);
1214#endif 1118#endif
1215 if ( (msg != NULL) || 1119 if ((msg != NULL) || (success <= 0))
1216 (success <= 0) ) 1120 {
1217 { 1121 GNUNET_asprintf (&pc->fi->emsg,
1218 GNUNET_asprintf (&pc->fi->emsg, 1122 _("Insufficient space for publishing: %s"), msg);
1219 _("Insufficient space for publishing: %s"), 1123 signal_publish_error (pc->fi, pc, pc->fi->emsg);
1220 msg); 1124 return;
1221 signal_publish_error (pc->fi, 1125 }
1222 pc,
1223 pc->fi->emsg);
1224 return;
1225 }
1226 pc->rid = success; 1126 pc->rid = success;
1227 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == pc->upload_task); 1127 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == pc->upload_task);
1228 pc->upload_task 1128 pc->upload_task
1229 = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, 1129 =
1230 &GNUNET_FS_publish_main_, 1130 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_BACKGROUND,
1231 pc); 1131 &GNUNET_FS_publish_main_, pc);
1232} 1132}
1233 1133
1234 1134
@@ -1247,26 +1147,26 @@ finish_reserve (void *cls,
1247 */ 1147 */
1248struct GNUNET_FS_PublishContext * 1148struct GNUNET_FS_PublishContext *
1249GNUNET_FS_publish_start (struct GNUNET_FS_Handle *h, 1149GNUNET_FS_publish_start (struct GNUNET_FS_Handle *h,
1250 struct GNUNET_FS_FileInformation *fi, 1150 struct GNUNET_FS_FileInformation *fi,
1251 struct GNUNET_FS_Namespace *namespace, 1151 struct GNUNET_FS_Namespace *namespace,
1252 const char *nid, 1152 const char *nid,
1253 const char *nuid, 1153 const char *nuid,
1254 enum GNUNET_FS_PublishOptions options) 1154 enum GNUNET_FS_PublishOptions options)
1255{ 1155{
1256 struct GNUNET_FS_PublishContext *ret; 1156 struct GNUNET_FS_PublishContext *ret;
1257 struct GNUNET_DATASTORE_Handle *dsh; 1157 struct GNUNET_DATASTORE_Handle *dsh;
1258 1158
1259 GNUNET_assert (NULL != h); 1159 GNUNET_assert (NULL != h);
1260 if (0 == (options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY)) 1160 if (0 == (options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY))
1261 { 1161 {
1262 dsh = GNUNET_DATASTORE_connect (h->cfg); 1162 dsh = GNUNET_DATASTORE_connect (h->cfg);
1263 if (NULL == dsh) 1163 if (NULL == dsh)
1264 return NULL; 1164 return NULL;
1265 } 1165 }
1266 else 1166 else
1267 { 1167 {
1268 dsh = NULL; 1168 dsh = NULL;
1269 } 1169 }
1270 ret = GNUNET_malloc (sizeof (struct GNUNET_FS_PublishContext)); 1170 ret = GNUNET_malloc (sizeof (struct GNUNET_FS_PublishContext));
1271 ret->dsh = dsh; 1171 ret->dsh = dsh;
1272 ret->h = h; 1172 ret->h = h;
@@ -1274,44 +1174,40 @@ GNUNET_FS_publish_start (struct GNUNET_FS_Handle *h,
1274 ret->namespace = namespace; 1174 ret->namespace = namespace;
1275 ret->options = options; 1175 ret->options = options;
1276 if (namespace != NULL) 1176 if (namespace != NULL)
1277 { 1177 {
1278 namespace->rc++; 1178 namespace->rc++;
1279 GNUNET_assert (NULL != nid); 1179 GNUNET_assert (NULL != nid);
1280 ret->nid = GNUNET_strdup (nid); 1180 ret->nid = GNUNET_strdup (nid);
1281 if (NULL != nuid) 1181 if (NULL != nuid)
1282 ret->nuid = GNUNET_strdup (nuid); 1182 ret->nuid = GNUNET_strdup (nuid);
1283 } 1183 }
1284 /* signal start */ 1184 /* signal start */
1285 GNUNET_FS_file_information_inspect (ret->fi, 1185 GNUNET_FS_file_information_inspect (ret->fi, &fip_signal_start, ret);
1286 &fip_signal_start,
1287 ret);
1288 ret->fi_pos = ret->fi; 1186 ret->fi_pos = ret->fi;
1289 ret->top = GNUNET_FS_make_top (h, &GNUNET_FS_publish_signal_suspend_, ret); 1187 ret->top = GNUNET_FS_make_top (h, &GNUNET_FS_publish_signal_suspend_, ret);
1290 GNUNET_FS_publish_sync_ (ret); 1188 GNUNET_FS_publish_sync_ (ret);
1291 if (NULL != ret->dsh) 1189 if (NULL != ret->dsh)
1292 { 1190 {
1293 GNUNET_assert (NULL == ret->qre); 1191 GNUNET_assert (NULL == ret->qre);
1294 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1192 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1295 _("Reserving space for %u entries and %llu bytes for publication\n"), 1193 _
1296 (unsigned int) ret->reserve_entries, 1194 ("Reserving space for %u entries and %llu bytes for publication\n"),
1297 (unsigned long long) ret->reserve_space); 1195 (unsigned int) ret->reserve_entries,
1298 ret->qre = GNUNET_DATASTORE_reserve (ret->dsh, 1196 (unsigned long long) ret->reserve_space);
1299 ret->reserve_space, 1197 ret->qre =
1300 ret->reserve_entries, 1198 GNUNET_DATASTORE_reserve (ret->dsh, ret->reserve_space,
1301 UINT_MAX, 1199 ret->reserve_entries, UINT_MAX, UINT_MAX,
1302 UINT_MAX, 1200 GNUNET_TIME_UNIT_FOREVER_REL, &finish_reserve,
1303 GNUNET_TIME_UNIT_FOREVER_REL, 1201 ret);
1304 &finish_reserve, 1202 }
1305 ret);
1306 }
1307 else 1203 else
1308 { 1204 {
1309 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == ret->upload_task); 1205 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == ret->upload_task);
1310 ret->upload_task 1206 ret->upload_task
1311 = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, 1207 =
1312 &GNUNET_FS_publish_main_, 1208 GNUNET_SCHEDULER_add_with_priority
1313 ret); 1209 (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, &GNUNET_FS_publish_main_, ret);
1314 } 1210 }
1315 return ret; 1211 return ret;
1316} 1212}
1317 1213
@@ -1331,27 +1227,26 @@ GNUNET_FS_publish_start (struct GNUNET_FS_Handle *h,
1331 * @return GNUNET_OK to continue (always) 1227 * @return GNUNET_OK to continue (always)
1332 */ 1228 */
1333static int 1229static int
1334fip_signal_stop(void *cls, 1230fip_signal_stop (void *cls,
1335 struct GNUNET_FS_FileInformation *fi, 1231 struct GNUNET_FS_FileInformation *fi,
1336 uint64_t length, 1232 uint64_t length,
1337 struct GNUNET_CONTAINER_MetaData *meta, 1233 struct GNUNET_CONTAINER_MetaData *meta,
1338 struct GNUNET_FS_Uri **uri, 1234 struct GNUNET_FS_Uri **uri,
1339 struct GNUNET_FS_BlockOptions *bo, 1235 struct GNUNET_FS_BlockOptions *bo,
1340 int *do_index, 1236 int *do_index, void **client_info)
1341 void **client_info)
1342{ 1237{
1343 struct GNUNET_FS_PublishContext*pc = cls; 1238 struct GNUNET_FS_PublishContext *pc = cls;
1344 struct GNUNET_FS_ProgressInfo pi; 1239 struct GNUNET_FS_ProgressInfo pi;
1345 uint64_t off; 1240 uint64_t off;
1346 1241
1347 if (fi->serialization != NULL) 1242 if (fi->serialization != NULL)
1348 { 1243 {
1349 GNUNET_FS_remove_sync_file_ (pc->h, 1244 GNUNET_FS_remove_sync_file_ (pc->h,
1350 GNUNET_FS_SYNC_PATH_FILE_INFO, 1245 GNUNET_FS_SYNC_PATH_FILE_INFO,
1351 fi->serialization); 1246 fi->serialization);
1352 GNUNET_free (fi->serialization); 1247 GNUNET_free (fi->serialization);
1353 fi->serialization = NULL; 1248 fi->serialization = NULL;
1354 } 1249 }
1355 off = (fi->chk_uri == NULL) ? 0 : length; 1250 off = (fi->chk_uri == NULL) ? 0 : length;
1356 pi.status = GNUNET_FS_STATUS_PUBLISH_STOPPED; 1251 pi.status = GNUNET_FS_STATUS_PUBLISH_STOPPED;
1357 GNUNET_break (NULL == GNUNET_FS_publish_make_status_ (&pi, pc, fi, off)); 1252 GNUNET_break (NULL == GNUNET_FS_publish_make_status_ (&pi, pc, fi, off));
@@ -1368,43 +1263,41 @@ fip_signal_stop(void *cls,
1368 * 1263 *
1369 * @param pc context for the upload to stop 1264 * @param pc context for the upload to stop
1370 */ 1265 */
1371void 1266void
1372GNUNET_FS_publish_stop (struct GNUNET_FS_PublishContext *pc) 1267GNUNET_FS_publish_stop (struct GNUNET_FS_PublishContext *pc)
1373{ 1268{
1374#if DEBUG_PUBLISH 1269#if DEBUG_PUBLISH
1375 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1270 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Publish stop called\n");
1376 "Publish stop called\n");
1377#endif 1271#endif
1378 GNUNET_FS_end_top (pc->h, pc->top); 1272 GNUNET_FS_end_top (pc->h, pc->top);
1379 if (NULL != pc->qre) 1273 if (NULL != pc->qre)
1380 { 1274 {
1381 GNUNET_DATASTORE_cancel (pc->qre); 1275 GNUNET_DATASTORE_cancel (pc->qre);
1382 pc->qre = NULL; 1276 pc->qre = NULL;
1383 } 1277 }
1384 if (NULL != pc->dsh) 1278 if (NULL != pc->dsh)
1385 { 1279 {
1386 GNUNET_DATASTORE_disconnect (pc->dsh, GNUNET_NO); 1280 GNUNET_DATASTORE_disconnect (pc->dsh, GNUNET_NO);
1387 pc->dsh = NULL; 1281 pc->dsh = NULL;
1388 } 1282 }
1389 if (GNUNET_SCHEDULER_NO_TASK != pc->upload_task) 1283 if (GNUNET_SCHEDULER_NO_TASK != pc->upload_task)
1390 { 1284 {
1391 GNUNET_SCHEDULER_cancel (pc->upload_task); 1285 GNUNET_SCHEDULER_cancel (pc->upload_task);
1392 pc->upload_task = GNUNET_SCHEDULER_NO_TASK; 1286 pc->upload_task = GNUNET_SCHEDULER_NO_TASK;
1393 } 1287 }
1394 if (pc->serialization != NULL) 1288 if (pc->serialization != NULL)
1395 { 1289 {
1396 GNUNET_FS_remove_sync_file_ (pc->h, GNUNET_FS_SYNC_PATH_MASTER_PUBLISH, pc->serialization); 1290 GNUNET_FS_remove_sync_file_ (pc->h, GNUNET_FS_SYNC_PATH_MASTER_PUBLISH,
1397 GNUNET_free (pc->serialization); 1291 pc->serialization);
1398 pc->serialization = NULL; 1292 GNUNET_free (pc->serialization);
1399 } 1293 pc->serialization = NULL;
1400 GNUNET_FS_file_information_inspect (pc->fi, 1294 }
1401 &fip_signal_stop, 1295 GNUNET_FS_file_information_inspect (pc->fi, &fip_signal_stop, pc);
1402 pc);
1403 if (GNUNET_YES == pc->in_network_wait) 1296 if (GNUNET_YES == pc->in_network_wait)
1404 { 1297 {
1405 pc->in_network_wait = GNUNET_SYSERR; 1298 pc->in_network_wait = GNUNET_SYSERR;
1406 return; 1299 return;
1407 } 1300 }
1408 publish_cleanup (pc, NULL); 1301 publish_cleanup (pc, NULL);
1409} 1302}
1410 1303
@@ -1435,7 +1328,7 @@ struct PublishKskContext
1435 /** 1328 /**
1436 * Buffer of the same size as "kb" for 1329 * Buffer of the same size as "kb" for
1437 * the encrypted version. 1330 * the encrypted version.
1438 */ 1331 */
1439 struct KBlock *cpy; 1332 struct KBlock *cpy;
1440 1333
1441 /** 1334 /**
@@ -1456,7 +1349,7 @@ struct PublishKskContext
1456 1349
1457 /** 1350 /**
1458 * Closure for cont. 1351 * Closure for cont.
1459 */ 1352 */
1460 void *cont_cls; 1353 void *cont_cls;
1461 1354
1462 /** 1355 /**
@@ -1491,8 +1384,7 @@ struct PublishKskContext
1491 * @param tc unused 1384 * @param tc unused
1492 */ 1385 */
1493static void 1386static void
1494publish_ksk_cont (void *cls, 1387publish_ksk_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
1495 const struct GNUNET_SCHEDULER_TaskContext *tc);
1496 1388
1497 1389
1498/** 1390/**
@@ -1504,36 +1396,30 @@ publish_ksk_cont (void *cls,
1504 * @param msg error message (or NULL) 1396 * @param msg error message (or NULL)
1505 */ 1397 */
1506static void 1398static void
1507kb_put_cont (void *cls, 1399kb_put_cont (void *cls, int success, const char *msg)
1508 int success,
1509 const char *msg)
1510{ 1400{
1511 struct PublishKskContext *pkc = cls; 1401 struct PublishKskContext *pkc = cls;
1512 1402
1513 pkc->qre = NULL; 1403 pkc->qre = NULL;
1514 if (GNUNET_OK != success) 1404 if (GNUNET_OK != success)
1515 { 1405 {
1516#if DEBUG_PUBLISH 1406#if DEBUG_PUBLISH
1517 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1407 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "KB PUT operation complete\n");
1518 "KB PUT operation complete\n");
1519#endif 1408#endif
1520 if (NULL != pkc->dsh) 1409 if (NULL != pkc->dsh)
1521 { 1410 {
1522 GNUNET_DATASTORE_disconnect (pkc->dsh, GNUNET_NO); 1411 GNUNET_DATASTORE_disconnect (pkc->dsh, GNUNET_NO);
1523 pkc->dsh = NULL; 1412 pkc->dsh = NULL;
1524 }
1525 GNUNET_free (pkc->cpy);
1526 GNUNET_free (pkc->kb);
1527 pkc->cont (pkc->cont_cls,
1528 NULL,
1529 msg);
1530 GNUNET_FS_uri_destroy (pkc->ksk_uri);
1531 GNUNET_free (pkc);
1532 return;
1533 } 1413 }
1414 GNUNET_free (pkc->cpy);
1415 GNUNET_free (pkc->kb);
1416 pkc->cont (pkc->cont_cls, NULL, msg);
1417 GNUNET_FS_uri_destroy (pkc->ksk_uri);
1418 GNUNET_free (pkc);
1419 return;
1420 }
1534 GNUNET_SCHEDULER_add_continuation (&publish_ksk_cont, 1421 GNUNET_SCHEDULER_add_continuation (&publish_ksk_cont,
1535 pkc, 1422 pkc, GNUNET_SCHEDULER_REASON_PREREQ_DONE);
1536 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
1537} 1423}
1538 1424
1539 1425
@@ -1545,8 +1431,7 @@ kb_put_cont (void *cls,
1545 * @param tc unused 1431 * @param tc unused
1546 */ 1432 */
1547static void 1433static void
1548publish_ksk_cont (void *cls, 1434publish_ksk_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1549 const struct GNUNET_SCHEDULER_TaskContext *tc)
1550{ 1435{
1551 struct PublishKskContext *pkc = cls; 1436 struct PublishKskContext *pkc = cls;
1552 const char *keyword; 1437 const char *keyword;
@@ -1557,69 +1442,60 @@ publish_ksk_cont (void *cls,
1557 struct GNUNET_CRYPTO_RsaPrivateKey *pk; 1442 struct GNUNET_CRYPTO_RsaPrivateKey *pk;
1558 1443
1559 1444
1560 if ( (pkc->i == pkc->ksk_uri->data.ksk.keywordCount) || 1445 if ((pkc->i == pkc->ksk_uri->data.ksk.keywordCount) || (NULL == pkc->dsh))
1561 (NULL == pkc->dsh) ) 1446 {
1562 {
1563#if DEBUG_PUBLISH 1447#if DEBUG_PUBLISH
1564 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1448 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "KSK PUT operation complete\n");
1565 "KSK PUT operation complete\n");
1566#endif 1449#endif
1567 if (NULL != pkc->dsh) 1450 if (NULL != pkc->dsh)
1568 { 1451 {
1569 GNUNET_DATASTORE_disconnect (pkc->dsh, GNUNET_NO); 1452 GNUNET_DATASTORE_disconnect (pkc->dsh, GNUNET_NO);
1570 pkc->dsh = NULL; 1453 pkc->dsh = NULL;
1571 }
1572 GNUNET_free (pkc->cpy);
1573 GNUNET_free (pkc->kb);
1574 pkc->cont (pkc->cont_cls,
1575 pkc->ksk_uri,
1576 NULL);
1577 GNUNET_FS_uri_destroy (pkc->ksk_uri);
1578 GNUNET_free (pkc);
1579 return;
1580 } 1454 }
1455 GNUNET_free (pkc->cpy);
1456 GNUNET_free (pkc->kb);
1457 pkc->cont (pkc->cont_cls, pkc->ksk_uri, NULL);
1458 GNUNET_FS_uri_destroy (pkc->ksk_uri);
1459 GNUNET_free (pkc);
1460 return;
1461 }
1581 keyword = pkc->ksk_uri->data.ksk.keywords[pkc->i++]; 1462 keyword = pkc->ksk_uri->data.ksk.keywords[pkc->i++];
1582#if DEBUG_PUBLISH 1463#if DEBUG_PUBLISH
1583 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1464 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1584 "Publishing under keyword `%s'\n", 1465 "Publishing under keyword `%s'\n", keyword);
1585 keyword);
1586#endif 1466#endif
1587 /* first character of keyword indicates if it is 1467 /* first character of keyword indicates if it is
1588 mandatory or not -- ignore for hashing */ 1468 * mandatory or not -- ignore for hashing */
1589 GNUNET_CRYPTO_hash (&keyword[1], strlen (&keyword[1]), &key); 1469 GNUNET_CRYPTO_hash (&keyword[1], strlen (&keyword[1]), &key);
1590 GNUNET_CRYPTO_hash_to_aes_key (&key, &skey, &iv); 1470 GNUNET_CRYPTO_hash_to_aes_key (&key, &skey, &iv);
1591 GNUNET_CRYPTO_aes_encrypt (&pkc->kb[1], 1471 GNUNET_CRYPTO_aes_encrypt (&pkc->kb[1],
1592 pkc->slen + pkc->mdsize, 1472 pkc->slen + pkc->mdsize, &skey, &iv, &pkc->cpy[1]);
1593 &skey,
1594 &iv,
1595 &pkc->cpy[1]);
1596 pk = GNUNET_CRYPTO_rsa_key_create_from_hash (&key); 1473 pk = GNUNET_CRYPTO_rsa_key_create_from_hash (&key);
1597 GNUNET_assert (NULL != pk); 1474 GNUNET_assert (NULL != pk);
1598 GNUNET_CRYPTO_rsa_key_get_public (pk, &pkc->cpy->keyspace); 1475 GNUNET_CRYPTO_rsa_key_get_public (pk, &pkc->cpy->keyspace);
1599 GNUNET_CRYPTO_hash (&pkc->cpy->keyspace, 1476 GNUNET_CRYPTO_hash (&pkc->cpy->keyspace,
1600 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), 1477 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
1601 &query); 1478 &query);
1602 GNUNET_assert (GNUNET_OK == 1479 GNUNET_assert (GNUNET_OK ==
1603 GNUNET_CRYPTO_rsa_sign (pk, 1480 GNUNET_CRYPTO_rsa_sign (pk,
1604 &pkc->cpy->purpose, 1481 &pkc->cpy->purpose,
1605 &pkc->cpy->signature)); 1482 &pkc->cpy->signature));
1606 GNUNET_CRYPTO_rsa_key_free (pk); 1483 GNUNET_CRYPTO_rsa_key_free (pk);
1607 pkc->qre = GNUNET_DATASTORE_put (pkc->dsh, 1484 pkc->qre = GNUNET_DATASTORE_put (pkc->dsh,
1608 0, 1485 0,
1609 &query, 1486 &query,
1610 pkc->mdsize + 1487 pkc->mdsize +
1611 sizeof (struct KBlock) + 1488 sizeof (struct KBlock) +
1612 pkc->slen, 1489 pkc->slen,
1613 pkc->cpy, 1490 pkc->cpy,
1614 GNUNET_BLOCK_TYPE_FS_KBLOCK, 1491 GNUNET_BLOCK_TYPE_FS_KBLOCK,
1615 pkc->bo.content_priority, 1492 pkc->bo.content_priority,
1616 pkc->bo.anonymity_level, 1493 pkc->bo.anonymity_level,
1617 pkc->bo.replication_level, 1494 pkc->bo.replication_level,
1618 pkc->bo.expiration_time, 1495 pkc->bo.expiration_time,
1619 -2, 1, 1496 -2, 1,
1620 GNUNET_CONSTANTS_SERVICE_TIMEOUT, 1497 GNUNET_CONSTANTS_SERVICE_TIMEOUT,
1621 &kb_put_cont, 1498 &kb_put_cont, pkc);
1622 pkc);
1623} 1499}
1624 1500
1625 1501
@@ -1637,13 +1513,12 @@ publish_ksk_cont (void *cls,
1637 */ 1513 */
1638void 1514void
1639GNUNET_FS_publish_ksk (struct GNUNET_FS_Handle *h, 1515GNUNET_FS_publish_ksk (struct GNUNET_FS_Handle *h,
1640 const struct GNUNET_FS_Uri *ksk_uri, 1516 const struct GNUNET_FS_Uri *ksk_uri,
1641 const struct GNUNET_CONTAINER_MetaData *meta, 1517 const struct GNUNET_CONTAINER_MetaData *meta,
1642 const struct GNUNET_FS_Uri *uri, 1518 const struct GNUNET_FS_Uri *uri,
1643 const struct GNUNET_FS_BlockOptions *bo, 1519 const struct GNUNET_FS_BlockOptions *bo,
1644 enum GNUNET_FS_PublishOptions options, 1520 enum GNUNET_FS_PublishOptions options,
1645 GNUNET_FS_PublishContinuation cont, 1521 GNUNET_FS_PublishContinuation cont, void *cont_cls)
1646 void *cont_cls)
1647{ 1522{
1648 struct PublishKskContext *pkc; 1523 struct PublishKskContext *pkc;
1649 char *uris; 1524 char *uris;
@@ -1658,15 +1533,15 @@ GNUNET_FS_publish_ksk (struct GNUNET_FS_Handle *h,
1658 pkc->cont = cont; 1533 pkc->cont = cont;
1659 pkc->cont_cls = cont_cls; 1534 pkc->cont_cls = cont_cls;
1660 if (0 == (options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY)) 1535 if (0 == (options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY))
1536 {
1537 pkc->dsh = GNUNET_DATASTORE_connect (h->cfg);
1538 if (pkc->dsh == NULL)
1661 { 1539 {
1662 pkc->dsh = GNUNET_DATASTORE_connect (h->cfg); 1540 cont (cont_cls, NULL, _("Could not connect to datastore."));
1663 if (pkc->dsh == NULL) 1541 GNUNET_free (pkc);
1664 { 1542 return;
1665 cont (cont_cls, NULL, _("Could not connect to datastore."));
1666 GNUNET_free (pkc);
1667 return;
1668 }
1669 } 1543 }
1544 }
1670 if (meta == NULL) 1545 if (meta == NULL)
1671 pkc->mdsize = 0; 1546 pkc->mdsize = 0;
1672 else 1547 else
@@ -1676,10 +1551,10 @@ GNUNET_FS_publish_ksk (struct GNUNET_FS_Handle *h,
1676 pkc->slen = strlen (uris) + 1; 1551 pkc->slen = strlen (uris) + 1;
1677 size = pkc->mdsize + sizeof (struct KBlock) + pkc->slen; 1552 size = pkc->mdsize + sizeof (struct KBlock) + pkc->slen;
1678 if (size > MAX_KBLOCK_SIZE) 1553 if (size > MAX_KBLOCK_SIZE)
1679 { 1554 {
1680 size = MAX_KBLOCK_SIZE; 1555 size = MAX_KBLOCK_SIZE;
1681 pkc->mdsize = size - sizeof (struct KBlock) - pkc->slen; 1556 pkc->mdsize = size - sizeof (struct KBlock) - pkc->slen;
1682 } 1557 }
1683 pkc->kb = GNUNET_malloc (size); 1558 pkc->kb = GNUNET_malloc (size);
1684 kbe = (char *) &pkc->kb[1]; 1559 kbe = (char *) &pkc->kb[1];
1685 memcpy (kbe, uris, pkc->slen); 1560 memcpy (kbe, uris, pkc->slen);
@@ -1687,34 +1562,33 @@ GNUNET_FS_publish_ksk (struct GNUNET_FS_Handle *h,
1687 sptr = &kbe[pkc->slen]; 1562 sptr = &kbe[pkc->slen];
1688 if (meta != NULL) 1563 if (meta != NULL)
1689 pkc->mdsize = GNUNET_CONTAINER_meta_data_serialize (meta, 1564 pkc->mdsize = GNUNET_CONTAINER_meta_data_serialize (meta,
1690 &sptr, 1565 &sptr,
1691 pkc->mdsize, 1566 pkc->mdsize,
1692 GNUNET_CONTAINER_META_DATA_SERIALIZE_PART); 1567 GNUNET_CONTAINER_META_DATA_SERIALIZE_PART);
1693 if (pkc->mdsize == -1) 1568 if (pkc->mdsize == -1)
1569 {
1570 GNUNET_break (0);
1571 GNUNET_free (pkc->kb);
1572 if (pkc->dsh != NULL)
1694 { 1573 {
1695 GNUNET_break (0); 1574 GNUNET_DATASTORE_disconnect (pkc->dsh, GNUNET_NO);
1696 GNUNET_free (pkc->kb); 1575 pkc->dsh = NULL;
1697 if (pkc->dsh != NULL)
1698 {
1699 GNUNET_DATASTORE_disconnect (pkc->dsh, GNUNET_NO);
1700 pkc->dsh = NULL;
1701 }
1702 cont (cont_cls, NULL, _("Internal error."));
1703 GNUNET_free (pkc);
1704 return;
1705 } 1576 }
1577 cont (cont_cls, NULL, _("Internal error."));
1578 GNUNET_free (pkc);
1579 return;
1580 }
1706 size = sizeof (struct KBlock) + pkc->slen + pkc->mdsize; 1581 size = sizeof (struct KBlock) + pkc->slen + pkc->mdsize;
1707 1582
1708 pkc->cpy = GNUNET_malloc (size); 1583 pkc->cpy = GNUNET_malloc (size);
1709 pkc->cpy->purpose.size = htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) + 1584 pkc->cpy->purpose.size =
1710 sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) + 1585 htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) +
1711 pkc->mdsize + 1586 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) +
1712 pkc->slen); 1587 pkc->mdsize + pkc->slen);
1713 pkc->cpy->purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_FS_KBLOCK); 1588 pkc->cpy->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_FS_KBLOCK);
1714 pkc->ksk_uri = GNUNET_FS_uri_dup (ksk_uri); 1589 pkc->ksk_uri = GNUNET_FS_uri_dup (ksk_uri);
1715 GNUNET_SCHEDULER_add_continuation (&publish_ksk_cont, 1590 GNUNET_SCHEDULER_add_continuation (&publish_ksk_cont,
1716 pkc, 1591 pkc, GNUNET_SCHEDULER_REASON_PREREQ_DONE);
1717 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
1718} 1592}
1719 1593
1720 1594
diff --git a/src/fs/fs_search.c b/src/fs/fs_search.c
index 526e6513b..60b7a1cc8 100644
--- a/src/fs/fs_search.c
+++ b/src/fs/fs_search.c
@@ -42,20 +42,19 @@
42 */ 42 */
43void * 43void *
44GNUNET_FS_search_make_status_ (struct GNUNET_FS_ProgressInfo *pi, 44GNUNET_FS_search_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
45 struct GNUNET_FS_SearchContext *sc) 45 struct GNUNET_FS_SearchContext *sc)
46{ 46{
47 void *ret; 47 void *ret;
48
48 pi->value.search.sc = sc; 49 pi->value.search.sc = sc;
49 pi->value.search.cctx 50 pi->value.search.cctx = sc->client_info;
50 = sc->client_info;
51 pi->value.search.pctx 51 pi->value.search.pctx
52 = (sc->psearch_result == NULL) ? NULL : sc->psearch_result->client_info; 52 = (sc->psearch_result == NULL) ? NULL : sc->psearch_result->client_info;
53 pi->value.search.query 53 pi->value.search.query = sc->uri;
54 = sc->uri; 54 pi->value.search.duration =
55 pi->value.search.duration = GNUNET_TIME_absolute_get_duration (sc->start_time); 55 GNUNET_TIME_absolute_get_duration (sc->start_time);
56 pi->value.search.anonymity = sc->anonymity; 56 pi->value.search.anonymity = sc->anonymity;
57 ret = sc->h->upcb (sc->h->upcb_cls, 57 ret = sc->h->upcb (sc->h->upcb_cls, pi);
58 pi);
59 return ret; 58 return ret;
60} 59}
61 60
@@ -72,15 +71,12 @@ GNUNET_FS_search_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
72 * GNUNET_OK otherwise 71 * GNUNET_OK otherwise
73 */ 72 */
74static int 73static int
75test_result_present (void *cls, 74test_result_present (void *cls, const GNUNET_HashCode * key, void *value)
76 const GNUNET_HashCode * key,
77 void *value)
78{ 75{
79 const struct GNUNET_FS_Uri *uri = cls; 76 const struct GNUNET_FS_Uri *uri = cls;
80 struct GNUNET_FS_SearchResult *sr = value; 77 struct GNUNET_FS_SearchResult *sr = value;
81 78
82 if (GNUNET_FS_uri_test_equal (uri, 79 if (GNUNET_FS_uri_test_equal (uri, sr->uri))
83 sr->uri))
84 return GNUNET_SYSERR; 80 return GNUNET_SYSERR;
85 return GNUNET_OK; 81 return GNUNET_OK;
86} 82}
@@ -94,9 +90,9 @@ test_result_present (void *cls,
94 * @param sr the specific result 90 * @param sr the specific result
95 */ 91 */
96static void 92static void
97notify_client_chk_result (struct GNUNET_FS_SearchContext *sc, 93notify_client_chk_result (struct GNUNET_FS_SearchContext *sc,
98 struct GNUNET_FS_SearchResult *sr) 94 struct GNUNET_FS_SearchResult *sr)
99{ 95{
100 struct GNUNET_FS_ProgressInfo pi; 96 struct GNUNET_FS_ProgressInfo pi;
101 97
102 pi.status = GNUNET_FS_STATUS_SEARCH_RESULT; 98 pi.status = GNUNET_FS_STATUS_SEARCH_RESULT;
@@ -116,9 +112,9 @@ notify_client_chk_result (struct GNUNET_FS_SearchContext *sc,
116 * @param sr the specific result 112 * @param sr the specific result
117 */ 113 */
118static void 114static void
119notify_client_chk_update (struct GNUNET_FS_SearchContext *sc, 115notify_client_chk_update (struct GNUNET_FS_SearchContext *sc,
120 struct GNUNET_FS_SearchResult *sr) 116 struct GNUNET_FS_SearchResult *sr)
121{ 117{
122 struct GNUNET_FS_ProgressInfo pi; 118 struct GNUNET_FS_ProgressInfo pi;
123 119
124 pi.status = GNUNET_FS_STATUS_SEARCH_UPDATE; 120 pi.status = GNUNET_FS_STATUS_SEARCH_UPDATE;
@@ -126,11 +122,10 @@ notify_client_chk_update (struct GNUNET_FS_SearchContext *sc,
126 pi.value.search.specifics.update.meta = sr->meta; 122 pi.value.search.specifics.update.meta = sr->meta;
127 pi.value.search.specifics.update.uri = sr->uri; 123 pi.value.search.specifics.update.uri = sr->uri;
128 pi.value.search.specifics.update.availability_rank 124 pi.value.search.specifics.update.availability_rank
129 = 2*sr->availability_success - sr->availability_trials; 125 = 2 * sr->availability_success - sr->availability_trials;
130 pi.value.search.specifics.update.availability_certainty 126 pi.value.search.specifics.update.availability_certainty
131 = sr->availability_trials; 127 = sr->availability_trials;
132 pi.value.search.specifics.update.applicability_rank 128 pi.value.search.specifics.update.applicability_rank = sr->optional_support;
133 = sr->optional_support;
134 sr->client_info = GNUNET_FS_search_make_status_ (&pi, sc); 129 sr->client_info = GNUNET_FS_search_make_status_ (&pi, sc);
135} 130}
136 131
@@ -138,7 +133,7 @@ notify_client_chk_update (struct GNUNET_FS_SearchContext *sc,
138/** 133/**
139 * Context for "get_result_present". 134 * Context for "get_result_present".
140 */ 135 */
141struct GetResultContext 136struct GetResultContext
142{ 137{
143 /** 138 /**
144 * The URI we're looking for. 139 * The URI we're looking for.
@@ -164,15 +159,12 @@ struct GetResultContext
164 * @return GNUNET_OK 159 * @return GNUNET_OK
165 */ 160 */
166static int 161static int
167get_result_present (void *cls, 162get_result_present (void *cls, const GNUNET_HashCode * key, void *value)
168 const GNUNET_HashCode * key,
169 void *value)
170{ 163{
171 struct GetResultContext *grc = cls; 164 struct GetResultContext *grc = cls;
172 struct GNUNET_FS_SearchResult *sr = value; 165 struct GNUNET_FS_SearchResult *sr = value;
173 166
174 if (GNUNET_FS_uri_test_equal (grc->uri, 167 if (GNUNET_FS_uri_test_equal (grc->uri, sr->uri))
175 sr->uri))
176 grc->sr = sr; 168 grc->sr = sr;
177 return GNUNET_OK; 169 return GNUNET_OK;
178} 170}
@@ -192,7 +184,8 @@ signal_probe_result (struct GNUNET_FS_SearchResult *sr)
192 pi.value.search.specifics.update.meta = sr->meta; 184 pi.value.search.specifics.update.meta = sr->meta;
193 pi.value.search.specifics.update.uri = sr->uri; 185 pi.value.search.specifics.update.uri = sr->uri;
194 pi.value.search.specifics.update.availability_rank = sr->availability_success; 186 pi.value.search.specifics.update.availability_rank = sr->availability_success;
195 pi.value.search.specifics.update.availability_certainty = sr->availability_trials; 187 pi.value.search.specifics.update.availability_certainty =
188 sr->availability_trials;
196 pi.value.search.specifics.update.applicability_rank = sr->optional_support; 189 pi.value.search.specifics.update.applicability_rank = sr->optional_support;
197 sr->sc->client_info = GNUNET_FS_search_make_status_ (&pi, sr->sc); 190 sr->sc->client_info = GNUNET_FS_search_make_status_ (&pi, sr->sc);
198 GNUNET_FS_search_start_probe_ (sr); 191 GNUNET_FS_search_start_probe_ (sr);
@@ -206,10 +199,10 @@ signal_probe_result (struct GNUNET_FS_SearchResult *sr)
206 * @param tc scheduler context 199 * @param tc scheduler context
207 */ 200 */
208static void 201static void
209probe_failure_handler (void *cls, 202probe_failure_handler (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
210 const struct GNUNET_SCHEDULER_TaskContext *tc)
211{ 203{
212 struct GNUNET_FS_SearchResult *sr = cls; 204 struct GNUNET_FS_SearchResult *sr = cls;
205
213 sr->availability_trials++; 206 sr->availability_trials++;
214 GNUNET_FS_search_result_sync_ (sr); 207 GNUNET_FS_search_result_sync_ (sr);
215 signal_probe_result (sr); 208 signal_probe_result (sr);
@@ -223,10 +216,10 @@ probe_failure_handler (void *cls,
223 * @param tc scheduler context 216 * @param tc scheduler context
224 */ 217 */
225static void 218static void
226probe_success_handler (void *cls, 219probe_success_handler (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
227 const struct GNUNET_SCHEDULER_TaskContext *tc)
228{ 220{
229 struct GNUNET_FS_SearchResult *sr = cls; 221 struct GNUNET_FS_SearchResult *sr = cls;
222
230 sr->availability_trials++; 223 sr->availability_trials++;
231 sr->availability_success++; 224 sr->availability_success++;
232 GNUNET_FS_search_result_sync_ (sr); 225 GNUNET_FS_search_result_sync_ (sr);
@@ -249,79 +242,79 @@ probe_success_handler (void *cls,
249 * will be passed to future callbacks in the respective 242 * will be passed to future callbacks in the respective
250 * field in the GNUNET_FS_ProgressInfo struct. 243 * field in the GNUNET_FS_ProgressInfo struct.
251 */ 244 */
252void* 245void *
253GNUNET_FS_search_probe_progress_ (void *cls, 246GNUNET_FS_search_probe_progress_ (void *cls,
254 const struct GNUNET_FS_ProgressInfo *info) 247 const struct GNUNET_FS_ProgressInfo *info)
255{ 248{
256 struct GNUNET_FS_SearchResult *sr = info->value.download.cctx; 249 struct GNUNET_FS_SearchResult *sr = info->value.download.cctx;
257 struct GNUNET_TIME_Relative dur; 250 struct GNUNET_TIME_Relative dur;
258 251
259 switch (info->status) 252 switch (info->status)
253 {
254 case GNUNET_FS_STATUS_DOWNLOAD_START:
255 /* ignore */
256 break;
257 case GNUNET_FS_STATUS_DOWNLOAD_RESUME:
258 /* probes should never be resumed */
259 GNUNET_assert (0);
260 break;
261 case GNUNET_FS_STATUS_DOWNLOAD_SUSPEND:
262 /* probes should never be suspended */
263 GNUNET_break (0);
264 break;
265 case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS:
266 /* ignore */
267 break;
268 case GNUNET_FS_STATUS_DOWNLOAD_ERROR:
269 if (sr->probe_cancel_task != GNUNET_SCHEDULER_NO_TASK)
260 { 270 {
261 case GNUNET_FS_STATUS_DOWNLOAD_START: 271 GNUNET_SCHEDULER_cancel (sr->probe_cancel_task);
262 /* ignore */ 272 sr->probe_cancel_task = GNUNET_SCHEDULER_NO_TASK;
263 break; 273 }
264 case GNUNET_FS_STATUS_DOWNLOAD_RESUME: 274 sr->probe_cancel_task =
265 /* probes should never be resumed */ 275 GNUNET_SCHEDULER_add_delayed (sr->remaining_probe_time,
266 GNUNET_assert (0); 276 &probe_failure_handler, sr);
267 break; 277 break;
268 case GNUNET_FS_STATUS_DOWNLOAD_SUSPEND: 278 case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED:
269 /* probes should never be suspended */ 279 if (sr->probe_cancel_task != GNUNET_SCHEDULER_NO_TASK)
270 GNUNET_break (0); 280 {
271 break; 281 GNUNET_SCHEDULER_cancel (sr->probe_cancel_task);
272 case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: 282 sr->probe_cancel_task = GNUNET_SCHEDULER_NO_TASK;
273 /* ignore */ 283 }
274 break; 284 sr->probe_cancel_task =
275 case GNUNET_FS_STATUS_DOWNLOAD_ERROR: 285 GNUNET_SCHEDULER_add_delayed (sr->remaining_probe_time,
276 if (sr->probe_cancel_task != GNUNET_SCHEDULER_NO_TASK) 286 &probe_success_handler, sr);
277 { 287 break;
278 GNUNET_SCHEDULER_cancel (sr->probe_cancel_task); 288 case GNUNET_FS_STATUS_DOWNLOAD_STOPPED:
279 sr->probe_cancel_task = GNUNET_SCHEDULER_NO_TASK; 289 if (sr->probe_cancel_task != GNUNET_SCHEDULER_NO_TASK)
280 } 290 {
281 sr->probe_cancel_task = GNUNET_SCHEDULER_add_delayed (sr->remaining_probe_time, 291 GNUNET_SCHEDULER_cancel (sr->probe_cancel_task);
282 &probe_failure_handler, 292 sr->probe_cancel_task = GNUNET_SCHEDULER_NO_TASK;
283 sr);
284 break;
285 case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED:
286 if (sr->probe_cancel_task != GNUNET_SCHEDULER_NO_TASK)
287 {
288 GNUNET_SCHEDULER_cancel (sr->probe_cancel_task);
289 sr->probe_cancel_task = GNUNET_SCHEDULER_NO_TASK;
290 }
291 sr->probe_cancel_task = GNUNET_SCHEDULER_add_delayed (sr->remaining_probe_time,
292 &probe_success_handler,
293 sr);
294 break;
295 case GNUNET_FS_STATUS_DOWNLOAD_STOPPED:
296 if (sr->probe_cancel_task != GNUNET_SCHEDULER_NO_TASK)
297 {
298 GNUNET_SCHEDULER_cancel (sr->probe_cancel_task);
299 sr->probe_cancel_task = GNUNET_SCHEDULER_NO_TASK;
300 }
301 sr = NULL;
302 break;
303 case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE:
304 GNUNET_assert (sr->probe_cancel_task == GNUNET_SCHEDULER_NO_TASK);
305 sr->probe_active_time = GNUNET_TIME_absolute_get ();
306 sr->probe_cancel_task = GNUNET_SCHEDULER_add_delayed (sr->remaining_probe_time,
307 &probe_failure_handler,
308 sr);
309 break;
310 case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE:
311 if (sr->probe_cancel_task != GNUNET_SCHEDULER_NO_TASK)
312 {
313 GNUNET_SCHEDULER_cancel (sr->probe_cancel_task);
314 sr->probe_cancel_task = GNUNET_SCHEDULER_NO_TASK;
315 }
316 dur = GNUNET_TIME_absolute_get_duration (sr->probe_active_time);
317 sr->remaining_probe_time = GNUNET_TIME_relative_subtract (sr->remaining_probe_time,
318 dur);
319 GNUNET_FS_search_result_sync_ (sr);
320 break;
321 default:
322 GNUNET_break (0);
323 return NULL;
324 } 293 }
294 sr = NULL;
295 break;
296 case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE:
297 GNUNET_assert (sr->probe_cancel_task == GNUNET_SCHEDULER_NO_TASK);
298 sr->probe_active_time = GNUNET_TIME_absolute_get ();
299 sr->probe_cancel_task =
300 GNUNET_SCHEDULER_add_delayed (sr->remaining_probe_time,
301 &probe_failure_handler, sr);
302 break;
303 case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE:
304 if (sr->probe_cancel_task != GNUNET_SCHEDULER_NO_TASK)
305 {
306 GNUNET_SCHEDULER_cancel (sr->probe_cancel_task);
307 sr->probe_cancel_task = GNUNET_SCHEDULER_NO_TASK;
308 }
309 dur = GNUNET_TIME_absolute_get_duration (sr->probe_active_time);
310 sr->remaining_probe_time =
311 GNUNET_TIME_relative_subtract (sr->remaining_probe_time, dur);
312 GNUNET_FS_search_result_sync_ (sr);
313 break;
314 default:
315 GNUNET_break (0);
316 return NULL;
317 }
325 return sr; 318 return sr;
326} 319}
327 320
@@ -336,7 +329,7 @@ GNUNET_FS_search_start_probe_ (struct GNUNET_FS_SearchResult *sr)
336{ 329{
337 uint64_t off; 330 uint64_t off;
338 uint64_t len; 331 uint64_t len;
339 332
340 if (sr->probe_ctx != NULL) 333 if (sr->probe_ctx != NULL)
341 return; 334 return;
342 if (sr->download != NULL) 335 if (sr->download != NULL)
@@ -348,7 +341,7 @@ GNUNET_FS_search_start_probe_ (struct GNUNET_FS_SearchResult *sr)
348 len = GNUNET_FS_uri_chk_get_file_size (sr->uri); 341 len = GNUNET_FS_uri_chk_get_file_size (sr->uri);
349 if (len == 0) 342 if (len == 0)
350 return; 343 return;
351 if ( (len <= DBLOCK_SIZE) && (sr->availability_success > 0)) 344 if ((len <= DBLOCK_SIZE) && (sr->availability_success > 0))
352 return; 345 return;
353 off = len / DBLOCK_SIZE; 346 off = len / DBLOCK_SIZE;
354 if (off > 0) 347 if (off > 0)
@@ -358,17 +351,14 @@ GNUNET_FS_search_start_probe_ (struct GNUNET_FS_SearchResult *sr)
358 len = len - off; 351 len = len - off;
359 else 352 else
360 len = DBLOCK_SIZE; 353 len = DBLOCK_SIZE;
361 sr->remaining_probe_time = GNUNET_TIME_relative_multiply (sr->sc->h->avg_block_latency, 354 sr->remaining_probe_time =
362 2 * (1 + sr->availability_trials)); 355 GNUNET_TIME_relative_multiply (sr->sc->h->avg_block_latency,
363 sr->probe_ctx = GNUNET_FS_download_start (sr->sc->h, 356 2 * (1 + sr->availability_trials));
364 sr->uri, 357 sr->probe_ctx =
365 sr->meta, 358 GNUNET_FS_download_start (sr->sc->h, sr->uri, sr->meta, NULL, NULL, off,
366 NULL, NULL, 359 len, sr->sc->anonymity,
367 off, len, 360 GNUNET_FS_DOWNLOAD_NO_TEMPORARIES |
368 sr->sc->anonymity, 361 GNUNET_FS_DOWNLOAD_IS_PROBE, sr, NULL);
369 GNUNET_FS_DOWNLOAD_NO_TEMPORARIES |
370 GNUNET_FS_DOWNLOAD_IS_PROBE,
371 sr, NULL);
372} 362}
373 363
374 364
@@ -383,10 +373,10 @@ GNUNET_FS_search_start_probe_ (struct GNUNET_FS_SearchResult *sr)
383 * under the "ent" keyword 373 * under the "ent" keyword
384 */ 374 */
385static void 375static void
386process_ksk_result (struct GNUNET_FS_SearchContext *sc, 376process_ksk_result (struct GNUNET_FS_SearchContext *sc,
387 struct SearchRequestEntry *ent, 377 struct SearchRequestEntry *ent,
388 const struct GNUNET_FS_Uri *uri, 378 const struct GNUNET_FS_Uri *uri,
389 const struct GNUNET_CONTAINER_MetaData *meta) 379 const struct GNUNET_CONTAINER_MetaData *meta)
390{ 380{
391 GNUNET_HashCode key; 381 GNUNET_HashCode key;
392 struct GNUNET_FS_SearchResult *sr; 382 struct GNUNET_FS_SearchResult *sr;
@@ -397,36 +387,34 @@ process_ksk_result (struct GNUNET_FS_SearchContext *sc,
397 GNUNET_FS_uri_to_key (uri, &key); 387 GNUNET_FS_uri_to_key (uri, &key);
398 if (GNUNET_SYSERR == 388 if (GNUNET_SYSERR ==
399 GNUNET_CONTAINER_multihashmap_get_multiple (ent->results, 389 GNUNET_CONTAINER_multihashmap_get_multiple (ent->results,
400 &key, 390 &key,
401 &test_result_present, 391 &test_result_present,
402 (void*) uri)) 392 (void *) uri))
403 return; /* duplicate result */ 393 return; /* duplicate result */
404 /* try to find search result in master map */ 394 /* try to find search result in master map */
405 grc.sr = NULL; 395 grc.sr = NULL;
406 grc.uri = uri; 396 grc.uri = uri;
407 GNUNET_CONTAINER_multihashmap_get_multiple (sc->master_result_map, 397 GNUNET_CONTAINER_multihashmap_get_multiple (sc->master_result_map,
408 &key, 398 &key, &get_result_present, &grc);
409 &get_result_present,
410 &grc);
411 sr = grc.sr; 399 sr = grc.sr;
412 is_new = (NULL == sr) || (sr->mandatory_missing > 0); 400 is_new = (NULL == sr) || (sr->mandatory_missing > 0);
413 if (NULL == sr) 401 if (NULL == sr)
414 { 402 {
415 sr = GNUNET_malloc (sizeof (struct GNUNET_FS_SearchResult)); 403 sr = GNUNET_malloc (sizeof (struct GNUNET_FS_SearchResult));
416 sr->sc = sc; 404 sr->sc = sc;
417 sr->uri = GNUNET_FS_uri_dup (uri); 405 sr->uri = GNUNET_FS_uri_dup (uri);
418 sr->meta = GNUNET_CONTAINER_meta_data_duplicate (meta); 406 sr->meta = GNUNET_CONTAINER_meta_data_duplicate (meta);
419 sr->mandatory_missing = sc->mandatory_count; 407 sr->mandatory_missing = sc->mandatory_count;
420 sr->key = key; 408 sr->key = key;
421 GNUNET_CONTAINER_multihashmap_put (sc->master_result_map, 409 GNUNET_CONTAINER_multihashmap_put (sc->master_result_map,
422 &key, 410 &key,
423 sr, 411 sr,
424 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 412 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
425 } 413 }
426 else 414 else
427 { 415 {
428 GNUNET_CONTAINER_meta_data_merge (sr->meta, meta); 416 GNUNET_CONTAINER_meta_data_merge (sr->meta, meta);
429 } 417 }
430 /* check if mandatory satisfied */ 418 /* check if mandatory satisfied */
431 if (ent->mandatory) 419 if (ent->mandatory)
432 sr->mandatory_missing--; 420 sr->mandatory_missing--;
@@ -455,13 +443,15 @@ process_ksk_result (struct GNUNET_FS_SearchContext *sc,
455 * @param psearch parent search result (for namespace update searches) 443 * @param psearch parent search result (for namespace update searches)
456 * @return context that can be used to control the search 444 * @return context that can be used to control the search
457 */ 445 */
458static struct GNUNET_FS_SearchContext * 446static struct GNUNET_FS_SearchContext *search_start (struct GNUNET_FS_Handle *h,
459search_start (struct GNUNET_FS_Handle *h, 447 const struct GNUNET_FS_Uri
460 const struct GNUNET_FS_Uri *uri, 448 *uri, uint32_t anonymity,
461 uint32_t anonymity, 449 enum
462 enum GNUNET_FS_SearchOptions options, 450 GNUNET_FS_SearchOptions
463 void *cctx, 451 options, void *cctx,
464 struct GNUNET_FS_SearchResult *psearch); 452 struct
453 GNUNET_FS_SearchResult
454 *psearch);
465 455
466 456
467/** 457/**
@@ -474,10 +464,10 @@ search_start (struct GNUNET_FS_Handle *h,
474 * @param meta metadata associated with the URI 464 * @param meta metadata associated with the URI
475 */ 465 */
476static void 466static void
477process_sks_result (struct GNUNET_FS_SearchContext *sc, 467process_sks_result (struct GNUNET_FS_SearchContext *sc,
478 const char *id_update, 468 const char *id_update,
479 const struct GNUNET_FS_Uri *uri, 469 const struct GNUNET_FS_Uri *uri,
480 const struct GNUNET_CONTAINER_MetaData *meta) 470 const struct GNUNET_CONTAINER_MetaData *meta)
481{ 471{
482 struct GNUNET_FS_Uri uu; 472 struct GNUNET_FS_Uri uu;
483 GNUNET_HashCode key; 473 GNUNET_HashCode key;
@@ -486,39 +476,33 @@ process_sks_result (struct GNUNET_FS_SearchContext *sc,
486 /* check if new */ 476 /* check if new */
487 GNUNET_FS_uri_to_key (uri, &key); 477 GNUNET_FS_uri_to_key (uri, &key);
488 GNUNET_CRYPTO_hash_xor (&uri->data.chk.chk.key, 478 GNUNET_CRYPTO_hash_xor (&uri->data.chk.chk.key,
489 &uri->data.chk.chk.query, 479 &uri->data.chk.chk.query, &key);
490 &key);
491 if (GNUNET_SYSERR == 480 if (GNUNET_SYSERR ==
492 GNUNET_CONTAINER_multihashmap_get_multiple (sc->master_result_map, 481 GNUNET_CONTAINER_multihashmap_get_multiple (sc->master_result_map,
493 &key, 482 &key,
494 &test_result_present, 483 &test_result_present,
495 (void*) uri)) 484 (void *) uri))
496 return; /* duplicate result */ 485 return; /* duplicate result */
497 sr = GNUNET_malloc (sizeof (struct GNUNET_FS_SearchResult)); 486 sr = GNUNET_malloc (sizeof (struct GNUNET_FS_SearchResult));
498 sr->sc = sc; 487 sr->sc = sc;
499 sr->uri = GNUNET_FS_uri_dup (uri); 488 sr->uri = GNUNET_FS_uri_dup (uri);
500 sr->meta = GNUNET_CONTAINER_meta_data_duplicate (meta); 489 sr->meta = GNUNET_CONTAINER_meta_data_duplicate (meta);
501 sr->key = key; 490 sr->key = key;
502 GNUNET_CONTAINER_multihashmap_put (sc->master_result_map, 491 GNUNET_CONTAINER_multihashmap_put (sc->master_result_map,
503 &key, 492 &key,
504 sr, 493 sr,
505 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 494 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
506 GNUNET_FS_search_result_sync_ (sr); 495 GNUNET_FS_search_result_sync_ (sr);
507 GNUNET_FS_search_start_probe_ (sr); 496 GNUNET_FS_search_start_probe_ (sr);
508 /* notify client */ 497 /* notify client */
509 notify_client_chk_result (sc, sr); 498 notify_client_chk_result (sc, sr);
510 /* search for updates */ 499 /* search for updates */
511 if (strlen (id_update) == 0) 500 if (strlen (id_update) == 0)
512 return; /* no updates */ 501 return; /* no updates */
513 uu.type = sks; 502 uu.type = sks;
514 uu.data.sks.namespace = sc->uri->data.sks.namespace; 503 uu.data.sks.namespace = sc->uri->data.sks.namespace;
515 uu.data.sks.identifier = GNUNET_strdup (id_update); 504 uu.data.sks.identifier = GNUNET_strdup (id_update);
516 (void) search_start (sc->h, 505 (void) search_start (sc->h, &uu, sc->anonymity, sc->options, NULL, sr);
517 &uu,
518 sc->anonymity,
519 sc->options,
520 NULL,
521 sr);
522 GNUNET_free (uu.data.sks.identifier); 506 GNUNET_free (uu.data.sks.identifier);
523} 507}
524 508
@@ -532,8 +516,7 @@ process_sks_result (struct GNUNET_FS_SearchContext *sc,
532 */ 516 */
533static void 517static void
534process_kblock (struct GNUNET_FS_SearchContext *sc, 518process_kblock (struct GNUNET_FS_SearchContext *sc,
535 const struct KBlock *kb, 519 const struct KBlock *kb, size_t size)
536 size_t size)
537{ 520{
538 unsigned int i; 521 unsigned int i;
539 size_t j; 522 size_t j;
@@ -545,59 +528,54 @@ process_kblock (struct GNUNET_FS_SearchContext *sc,
545 struct GNUNET_CONTAINER_MetaData *meta; 528 struct GNUNET_CONTAINER_MetaData *meta;
546 struct GNUNET_FS_Uri *uri; 529 struct GNUNET_FS_Uri *uri;
547 char *emsg; 530 char *emsg;
548 531
549 GNUNET_CRYPTO_hash (&kb->keyspace, 532 GNUNET_CRYPTO_hash (&kb->keyspace,
550 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), 533 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
551 &q); 534 &q);
552 /* find key */ 535 /* find key */
553 for (i=0;i<sc->uri->data.ksk.keywordCount;i++) 536 for (i = 0; i < sc->uri->data.ksk.keywordCount; i++)
554 if (0 == memcmp (&q, 537 if (0 == memcmp (&q, &sc->requests[i].query, sizeof (GNUNET_HashCode)))
555 &sc->requests[i].query,
556 sizeof (GNUNET_HashCode)))
557 break; 538 break;
558 if (i == sc->uri->data.ksk.keywordCount) 539 if (i == sc->uri->data.ksk.keywordCount)
559 { 540 {
560 /* oops, does not match any of our keywords!? */ 541 /* oops, does not match any of our keywords!? */
561 GNUNET_break (0); 542 GNUNET_break (0);
562 return; 543 return;
563 } 544 }
564 /* decrypt */ 545 /* decrypt */
565 GNUNET_CRYPTO_hash_to_aes_key (&sc->requests[i].key, &skey, &iv); 546 GNUNET_CRYPTO_hash_to_aes_key (&sc->requests[i].key, &skey, &iv);
566 if (-1 == GNUNET_CRYPTO_aes_decrypt (&kb[1], 547 if (-1 == GNUNET_CRYPTO_aes_decrypt (&kb[1],
567 size - sizeof (struct KBlock), 548 size - sizeof (struct KBlock),
568 &skey, 549 &skey, &iv, pt))
569 &iv, 550 {
570 pt)) 551 GNUNET_break (0);
571 { 552 return;
572 GNUNET_break (0); 553 }
573 return;
574 }
575 /* parse */ 554 /* parse */
576 eos = memchr (pt, 0, sizeof (pt)); 555 eos = memchr (pt, 0, sizeof (pt));
577 if (NULL == eos) 556 if (NULL == eos)
578 { 557 {
579 GNUNET_break_op (0); 558 GNUNET_break_op (0);
580 return; 559 return;
581 } 560 }
582 j = eos - pt + 1; 561 j = eos - pt + 1;
583 if (sizeof (pt) == j) 562 if (sizeof (pt) == j)
584 meta = GNUNET_CONTAINER_meta_data_create (); 563 meta = GNUNET_CONTAINER_meta_data_create ();
585 else 564 else
586 meta = GNUNET_CONTAINER_meta_data_deserialize (&pt[j], 565 meta = GNUNET_CONTAINER_meta_data_deserialize (&pt[j], sizeof (pt) - j);
587 sizeof (pt) - j);
588 if (meta == NULL) 566 if (meta == NULL)
589 { 567 {
590 GNUNET_break_op (0); /* kblock malformed */ 568 GNUNET_break_op (0); /* kblock malformed */
591 return; 569 return;
592 } 570 }
593 uri = GNUNET_FS_uri_parse (pt, &emsg); 571 uri = GNUNET_FS_uri_parse (pt, &emsg);
594 if (uri == NULL) 572 if (uri == NULL)
595 { 573 {
596 GNUNET_break_op (0); /* kblock malformed */ 574 GNUNET_break_op (0); /* kblock malformed */
597 GNUNET_free_non_null (emsg); 575 GNUNET_free_non_null (emsg);
598 GNUNET_CONTAINER_meta_data_destroy (meta); 576 GNUNET_CONTAINER_meta_data_destroy (meta);
599 return; 577 return;
600 } 578 }
601 /* process */ 579 /* process */
602 process_ksk_result (sc, &sc->requests[i], uri, meta); 580 process_ksk_result (sc, &sc->requests[i], uri, meta);
603 581
@@ -616,8 +594,7 @@ process_kblock (struct GNUNET_FS_SearchContext *sc,
616 */ 594 */
617static void 595static void
618process_nblock (struct GNUNET_FS_SearchContext *sc, 596process_nblock (struct GNUNET_FS_SearchContext *sc,
619 const struct NBlock *nb, 597 const struct NBlock *nb, size_t size)
620 size_t size)
621{ 598{
622 unsigned int i; 599 unsigned int i;
623 size_t j; 600 size_t j;
@@ -629,70 +606,61 @@ process_nblock (struct GNUNET_FS_SearchContext *sc,
629 struct GNUNET_CONTAINER_MetaData *meta; 606 struct GNUNET_CONTAINER_MetaData *meta;
630 struct GNUNET_FS_Uri *uri; 607 struct GNUNET_FS_Uri *uri;
631 char *uris; 608 char *uris;
632 609
633 GNUNET_CRYPTO_hash (&nb->keyspace, 610 GNUNET_CRYPTO_hash (&nb->keyspace,
634 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), 611 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
635 &q); 612 &q);
636 /* find key */ 613 /* find key */
637 for (i=0;i<sc->uri->data.ksk.keywordCount;i++) 614 for (i = 0; i < sc->uri->data.ksk.keywordCount; i++)
638 if (0 == memcmp (&q, 615 if (0 == memcmp (&q, &sc->requests[i].query, sizeof (GNUNET_HashCode)))
639 &sc->requests[i].query,
640 sizeof (GNUNET_HashCode)))
641 break; 616 break;
642 if (i == sc->uri->data.ksk.keywordCount) 617 if (i == sc->uri->data.ksk.keywordCount)
643 { 618 {
644 /* oops, does not match any of our keywords!? */ 619 /* oops, does not match any of our keywords!? */
645 GNUNET_break (0); 620 GNUNET_break (0);
646 return; 621 return;
647 } 622 }
648 /* decrypt */ 623 /* decrypt */
649 GNUNET_CRYPTO_hash_to_aes_key (&sc->requests[i].key, &skey, &iv); 624 GNUNET_CRYPTO_hash_to_aes_key (&sc->requests[i].key, &skey, &iv);
650 if (-1 == GNUNET_CRYPTO_aes_decrypt (&nb[1], 625 if (-1 == GNUNET_CRYPTO_aes_decrypt (&nb[1],
651 size - sizeof (struct NBlock), 626 size - sizeof (struct NBlock),
652 &skey, 627 &skey, &iv, pt))
653 &iv, 628 {
654 pt)) 629 GNUNET_break (0);
655 { 630 return;
656 GNUNET_break (0); 631 }
657 return;
658 }
659 /* parse */ 632 /* parse */
660 eos = memchr (pt, 0, sizeof (pt)); 633 eos = memchr (pt, 0, sizeof (pt));
661 if (NULL == eos) 634 if (NULL == eos)
662 { 635 {
663 GNUNET_break_op (0); 636 GNUNET_break_op (0);
664 return; 637 return;
665 } 638 }
666 j = eos - pt + 1; 639 j = eos - pt + 1;
667 if (sizeof (pt) == j) 640 if (sizeof (pt) == j)
668 meta = GNUNET_CONTAINER_meta_data_create (); 641 meta = GNUNET_CONTAINER_meta_data_create ();
669 else 642 else
670 meta = GNUNET_CONTAINER_meta_data_deserialize (&pt[j], 643 meta = GNUNET_CONTAINER_meta_data_deserialize (&pt[j], sizeof (pt) - j);
671 sizeof (pt) - j);
672 if (meta == NULL) 644 if (meta == NULL)
673 { 645 {
674 GNUNET_break_op (0); /* nblock malformed */ 646 GNUNET_break_op (0); /* nblock malformed */
675 return; 647 return;
676 } 648 }
677 649
678 uri = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri)); 650 uri = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri));
679 uri->type = sks; 651 uri->type = sks;
680 uri->data.sks.identifier = GNUNET_strdup (pt); 652 uri->data.sks.identifier = GNUNET_strdup (pt);
681 GNUNET_CRYPTO_hash (&nb->subspace, 653 GNUNET_CRYPTO_hash (&nb->subspace,
682 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), 654 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
683 &uri->data.sks.namespace); 655 &uri->data.sks.namespace);
684 uris = GNUNET_FS_uri_to_string (uri); 656 uris = GNUNET_FS_uri_to_string (uri);
685 GNUNET_CONTAINER_meta_data_insert (meta, 657 GNUNET_CONTAINER_meta_data_insert (meta,
686 "<gnunet>", 658 "<gnunet>",
687 EXTRACTOR_METATYPE_URI, 659 EXTRACTOR_METATYPE_URI,
688 EXTRACTOR_METAFORMAT_UTF8, 660 EXTRACTOR_METAFORMAT_UTF8,
689 "text/plain", 661 "text/plain", uris, strlen (uris) + 1);
690 uris,
691 strlen (uris)+1);
692 GNUNET_free (uris); 662 GNUNET_free (uris);
693 GNUNET_PSEUDONYM_add (sc->h->cfg, 663 GNUNET_PSEUDONYM_add (sc->h->cfg, &uri->data.sks.namespace, meta);
694 &uri->data.sks.namespace,
695 meta);
696 /* process */ 664 /* process */
697 process_ksk_result (sc, &sc->requests[i], uri, meta); 665 process_ksk_result (sc, &sc->requests[i], uri, meta);
698 666
@@ -711,8 +679,7 @@ process_nblock (struct GNUNET_FS_SearchContext *sc,
711 */ 679 */
712static void 680static void
713process_sblock (struct GNUNET_FS_SearchContext *sc, 681process_sblock (struct GNUNET_FS_SearchContext *sc,
714 const struct SBlock *sb, 682 const struct SBlock *sb, size_t size)
715 size_t size)
716{ 683{
717 size_t len = size - sizeof (struct SBlock); 684 size_t len = size - sizeof (struct SBlock);
718 char pt[len]; 685 char pt[len];
@@ -729,48 +696,36 @@ process_sblock (struct GNUNET_FS_SearchContext *sc,
729 696
730 /* decrypt */ 697 /* decrypt */
731 identifier = sc->uri->data.sks.identifier; 698 identifier = sc->uri->data.sks.identifier;
732 GNUNET_CRYPTO_hash (identifier, 699 GNUNET_CRYPTO_hash (identifier, strlen (identifier), &key);
733 strlen (identifier),
734 &key);
735 GNUNET_CRYPTO_hash_to_aes_key (&key, &skey, &iv); 700 GNUNET_CRYPTO_hash_to_aes_key (&key, &skey, &iv);
736 if (-1 == GNUNET_CRYPTO_aes_decrypt (&sb[1], 701 if (-1 == GNUNET_CRYPTO_aes_decrypt (&sb[1], len, &skey, &iv, pt))
737 len, 702 {
738 &skey, 703 GNUNET_break (0);
739 &iv, 704 return;
740 pt)) 705 }
741 {
742 GNUNET_break (0);
743 return;
744 }
745 /* parse */ 706 /* parse */
746 off = GNUNET_STRINGS_buffer_tokenize (pt, 707 off = GNUNET_STRINGS_buffer_tokenize (pt, len, 2, &id, &uris);
747 len,
748 2,
749 &id,
750 &uris);
751 if (off == 0) 708 if (off == 0)
752 { 709 {
753 GNUNET_break_op (0); /* sblock malformed */ 710 GNUNET_break_op (0); /* sblock malformed */
754 return; 711 return;
755 } 712 }
756 meta = GNUNET_CONTAINER_meta_data_deserialize (&pt[off], 713 meta = GNUNET_CONTAINER_meta_data_deserialize (&pt[off], len - off);
757 len - off);
758 if (meta == NULL) 714 if (meta == NULL)
759 { 715 {
760 GNUNET_break_op (0); /* sblock malformed */ 716 GNUNET_break_op (0); /* sblock malformed */
761 return; 717 return;
762 } 718 }
763 uri = GNUNET_FS_uri_parse (uris, &emsg); 719 uri = GNUNET_FS_uri_parse (uris, &emsg);
764 if (uri == NULL) 720 if (uri == NULL)
765 { 721 {
766 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 722 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
767 "Failed to parse URI `%s': %s\n", 723 "Failed to parse URI `%s': %s\n", uris, emsg);
768 uris, emsg); 724 GNUNET_break_op (0); /* sblock malformed */
769 GNUNET_break_op (0); /* sblock malformed */ 725 GNUNET_free_non_null (emsg);
770 GNUNET_free_non_null (emsg); 726 GNUNET_CONTAINER_meta_data_destroy (meta);
771 GNUNET_CONTAINER_meta_data_destroy (meta); 727 return;
772 return; 728 }
773 }
774 /* process */ 729 /* process */
775 process_sks_result (sc, id, uri, meta); 730 process_sks_result (sc, id, uri, meta);
776 /* clean up */ 731 /* clean up */
@@ -790,76 +745,74 @@ process_sblock (struct GNUNET_FS_SearchContext *sc,
790 */ 745 */
791static void 746static void
792process_result (struct GNUNET_FS_SearchContext *sc, 747process_result (struct GNUNET_FS_SearchContext *sc,
793 enum GNUNET_BLOCK_Type type, 748 enum GNUNET_BLOCK_Type type,
794 struct GNUNET_TIME_Absolute expiration, 749 struct GNUNET_TIME_Absolute expiration,
795 const void *data, 750 const void *data, size_t size)
796 size_t size)
797{ 751{
798 if (GNUNET_TIME_absolute_get_duration (expiration).rel_value > 0) 752 if (GNUNET_TIME_absolute_get_duration (expiration).rel_value > 0)
799 { 753 {
800 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 754 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
801 "Result received has already expired.\n"); 755 "Result received has already expired.\n");
802 return; /* result expired */ 756 return; /* result expired */
803 } 757 }
804 switch (type) 758 switch (type)
759 {
760 case GNUNET_BLOCK_TYPE_FS_KBLOCK:
761 if (!GNUNET_FS_uri_test_ksk (sc->uri))
805 { 762 {
806 case GNUNET_BLOCK_TYPE_FS_KBLOCK:
807 if (! GNUNET_FS_uri_test_ksk (sc->uri))
808 {
809 GNUNET_break (0);
810 return;
811 }
812 if (sizeof (struct KBlock) > size)
813 {
814 GNUNET_break_op (0);
815 return;
816 }
817 process_kblock (sc, data, size);
818 break;
819 case GNUNET_BLOCK_TYPE_FS_SBLOCK:
820 if (! GNUNET_FS_uri_test_sks (sc->uri))
821 {
822 GNUNET_break (0);
823 return;
824 }
825 if (sizeof (struct SBlock) > size)
826 {
827 GNUNET_break_op (0);
828 return;
829 }
830 process_sblock (sc, data, size);
831 break;
832 case GNUNET_BLOCK_TYPE_FS_NBLOCK:
833 if (! GNUNET_FS_uri_test_ksk (sc->uri))
834 {
835 GNUNET_break (0);
836 return;
837 }
838 if (sizeof (struct NBlock) > size)
839 {
840 GNUNET_break_op (0);
841 return;
842 }
843 process_nblock (sc, data, size);
844 break;
845 case GNUNET_BLOCK_TYPE_ANY:
846 GNUNET_break (0);
847 break;
848 case GNUNET_BLOCK_TYPE_FS_DBLOCK:
849 GNUNET_break (0); 763 GNUNET_break (0);
850 break; 764 return;
851 case GNUNET_BLOCK_TYPE_FS_ONDEMAND: 765 }
766 if (sizeof (struct KBlock) > size)
767 {
768 GNUNET_break_op (0);
769 return;
770 }
771 process_kblock (sc, data, size);
772 break;
773 case GNUNET_BLOCK_TYPE_FS_SBLOCK:
774 if (!GNUNET_FS_uri_test_sks (sc->uri))
775 {
852 GNUNET_break (0); 776 GNUNET_break (0);
853 break; 777 return;
854 case GNUNET_BLOCK_TYPE_FS_IBLOCK: 778 }
779 if (sizeof (struct SBlock) > size)
780 {
781 GNUNET_break_op (0);
782 return;
783 }
784 process_sblock (sc, data, size);
785 break;
786 case GNUNET_BLOCK_TYPE_FS_NBLOCK:
787 if (!GNUNET_FS_uri_test_ksk (sc->uri))
788 {
855 GNUNET_break (0); 789 GNUNET_break (0);
856 break; 790 return;
857 default:
858 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
859 _("Got result with unknown block type `%d', ignoring"),
860 type);
861 break;
862 } 791 }
792 if (sizeof (struct NBlock) > size)
793 {
794 GNUNET_break_op (0);
795 return;
796 }
797 process_nblock (sc, data, size);
798 break;
799 case GNUNET_BLOCK_TYPE_ANY:
800 GNUNET_break (0);
801 break;
802 case GNUNET_BLOCK_TYPE_FS_DBLOCK:
803 GNUNET_break (0);
804 break;
805 case GNUNET_BLOCK_TYPE_FS_ONDEMAND:
806 GNUNET_break (0);
807 break;
808 case GNUNET_BLOCK_TYPE_FS_IBLOCK:
809 GNUNET_break (0);
810 break;
811 default:
812 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
813 _("Got result with unknown block type `%d', ignoring"), type);
814 break;
815 }
863} 816}
864 817
865 818
@@ -870,8 +823,7 @@ process_result (struct GNUNET_FS_SearchContext *sc,
870 * 823 *
871 * @param sc the search to reconnec 824 * @param sc the search to reconnec
872 */ 825 */
873static void 826static void try_reconnect (struct GNUNET_FS_SearchContext *sc);
874try_reconnect (struct GNUNET_FS_SearchContext *sc);
875 827
876 828
877/** 829/**
@@ -881,36 +833,31 @@ try_reconnect (struct GNUNET_FS_SearchContext *sc);
881 * @param cls closure 833 * @param cls closure
882 * @param msg message received, NULL on timeout or fatal error 834 * @param msg message received, NULL on timeout or fatal error
883 */ 835 */
884static void 836static void
885receive_results (void *cls, 837receive_results (void *cls, const struct GNUNET_MessageHeader *msg)
886 const struct GNUNET_MessageHeader * msg)
887{ 838{
888 struct GNUNET_FS_SearchContext *sc = cls; 839 struct GNUNET_FS_SearchContext *sc = cls;
889 const struct PutMessage *cm; 840 const struct PutMessage *cm;
890 uint16_t msize; 841 uint16_t msize;
891 842
892 if ( (NULL == msg) || 843 if ((NULL == msg) ||
893 (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_FS_PUT) || 844 (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_FS_PUT) ||
894 (ntohs (msg->size) <= sizeof (struct PutMessage)) ) 845 (ntohs (msg->size) <= sizeof (struct PutMessage)))
895 { 846 {
896 try_reconnect (sc); 847 try_reconnect (sc);
897 return; 848 return;
898 } 849 }
899 msize = ntohs (msg->size); 850 msize = ntohs (msg->size);
900 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 851 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
901 "Receiving %u bytes of result from fs service\n", 852 "Receiving %u bytes of result from fs service\n", msize);
902 msize); 853 cm = (const struct PutMessage *) msg;
903 cm = (const struct PutMessage*) msg; 854 process_result (sc,
904 process_result (sc, 855 ntohl (cm->type),
905 ntohl (cm->type), 856 GNUNET_TIME_absolute_ntoh (cm->expiration),
906 GNUNET_TIME_absolute_ntoh (cm->expiration), 857 &cm[1], msize - sizeof (struct PutMessage));
907 &cm[1],
908 msize - sizeof (struct PutMessage));
909 /* continue receiving */ 858 /* continue receiving */
910 GNUNET_CLIENT_receive (sc->client, 859 GNUNET_CLIENT_receive (sc->client,
911 &receive_results, 860 &receive_results, sc, GNUNET_TIME_UNIT_FOREVER_REL);
912 sc,
913 GNUNET_TIME_UNIT_FOREVER_REL);
914} 861}
915 862
916 863
@@ -967,22 +914,19 @@ struct MessageBuilderContext
967 * @return GNUNET_OK to continue iterating 914 * @return GNUNET_OK to continue iterating
968 */ 915 */
969static int 916static int
970build_result_set (void *cls, 917build_result_set (void *cls, const GNUNET_HashCode * key, void *value)
971 const GNUNET_HashCode *key,
972 void *value)
973{ 918{
974 struct MessageBuilderContext *mbc = cls; 919 struct MessageBuilderContext *mbc = cls;
975 struct GNUNET_FS_SearchResult *sr = value; 920 struct GNUNET_FS_SearchResult *sr = value;
976 921
977 if ( (mbc->uri != NULL) && 922 if ((mbc->uri != NULL) &&
978 (GNUNET_YES != GNUNET_FS_uri_test_equal (mbc->uri, 923 (GNUNET_YES != GNUNET_FS_uri_test_equal (mbc->uri, sr->uri)))
979 sr->uri)) )
980 return GNUNET_OK; 924 return GNUNET_OK;
981 if (mbc->skip_cnt > 0) 925 if (mbc->skip_cnt > 0)
982 { 926 {
983 mbc->skip_cnt--; 927 mbc->skip_cnt--;
984 return GNUNET_OK; 928 return GNUNET_OK;
985 } 929 }
986 if (mbc->put_cnt == 0) 930 if (mbc->put_cnt == 0)
987 return GNUNET_SYSERR; 931 return GNUNET_SYSERR;
988 mbc->sc->search_request_map_offset++; 932 mbc->sc->search_request_map_offset++;
@@ -1002,16 +946,13 @@ build_result_set (void *cls,
1002 * @return GNUNET_OK to continue iterating 946 * @return GNUNET_OK to continue iterating
1003 */ 947 */
1004static int 948static int
1005find_result_set (void *cls, 949find_result_set (void *cls, const GNUNET_HashCode * key, void *value)
1006 const GNUNET_HashCode *key,
1007 void *value)
1008{ 950{
1009 struct MessageBuilderContext *mbc = cls; 951 struct MessageBuilderContext *mbc = cls;
1010 struct GNUNET_FS_SearchResult *sr = value; 952 struct GNUNET_FS_SearchResult *sr = value;
1011 953
1012 if ( (mbc->uri != NULL) && 954 if ((mbc->uri != NULL) &&
1013 (GNUNET_YES != GNUNET_FS_uri_test_equal (mbc->uri, 955 (GNUNET_YES != GNUNET_FS_uri_test_equal (mbc->uri, sr->uri)))
1014 sr->uri)) )
1015 return GNUNET_OK; 956 return GNUNET_OK;
1016 mbc->put_cnt++; 957 mbc->put_cnt++;
1017 return GNUNET_OK; 958 return GNUNET_OK;
@@ -1028,9 +969,7 @@ find_result_set (void *cls,
1028 * @return number of bytes written to buf 969 * @return number of bytes written to buf
1029 */ 970 */
1030static size_t 971static size_t
1031transmit_search_request (void *cls, 972transmit_search_request (void *cls, size_t size, void *buf)
1032 size_t size,
1033 void *buf)
1034{ 973{
1035 struct GNUNET_FS_SearchContext *sc = cls; 974 struct GNUNET_FS_SearchContext *sc = cls;
1036 struct MessageBuilderContext mbc; 975 struct MessageBuilderContext mbc;
@@ -1042,105 +981,91 @@ transmit_search_request (void *cls,
1042 unsigned int sqms; 981 unsigned int sqms;
1043 982
1044 if (NULL == buf) 983 if (NULL == buf)
1045 { 984 {
1046 try_reconnect (sc); 985 try_reconnect (sc);
1047 return 0; 986 return 0;
1048 } 987 }
1049 mbc.sc = sc; 988 mbc.sc = sc;
1050 mbc.skip_cnt = sc->search_request_map_offset; 989 mbc.skip_cnt = sc->search_request_map_offset;
1051 sm = buf; 990 sm = buf;
1052 sm->header.type = htons (GNUNET_MESSAGE_TYPE_FS_START_SEARCH); 991 sm->header.type = htons (GNUNET_MESSAGE_TYPE_FS_START_SEARCH);
1053 mbc.xoff = (GNUNET_HashCode* ) &sm[1]; 992 mbc.xoff = (GNUNET_HashCode *) & sm[1];
1054 if (GNUNET_FS_uri_test_ksk (sc->uri)) 993 if (GNUNET_FS_uri_test_ksk (sc->uri))
994 {
995 msize = sizeof (struct SearchMessage);
996 GNUNET_assert (size >= msize);
997 mbc.uri = NULL;
998 mbc.put_cnt = 0;
999 GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map,
1000 &find_result_set, &mbc);
1001 sqms = mbc.put_cnt;
1002 mbc.put_cnt = (size - msize) / sizeof (GNUNET_HashCode);
1003 mbc.put_cnt = GNUNET_MIN (mbc.put_cnt, sqms - mbc.skip_cnt);
1004 if (sc->search_request_map_offset < sqms)
1005 GNUNET_assert (mbc.put_cnt > 0);
1006
1007 sm->header.size = htons (msize);
1008 if (0 != (sc->options & GNUNET_FS_SEARCH_OPTION_LOOPBACK_ONLY))
1009 sm->options = htonl (1);
1010 else
1011 sm->options = htonl (0);
1012 sm->type = htonl (GNUNET_BLOCK_TYPE_ANY);
1013 sm->anonymity_level = htonl (sc->anonymity);
1014 memset (&sm->target, 0, sizeof (GNUNET_HashCode));
1015 sm->query = sc->requests[sc->keyword_offset].query;
1016 msize += sizeof (GNUNET_HashCode) * mbc.put_cnt;
1017 GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map,
1018 &build_result_set, &mbc);
1019 sm->header.size = htons (msize);
1020 if (sqms != sc->search_request_map_offset)
1021 {
1022 /* more requesting to be done... */
1023 schedule_transmit_search_request (sc);
1024 return msize;
1025 }
1026 sc->keyword_offset++;
1027 if (sc->uri->data.ksk.keywordCount != sc->keyword_offset)
1055 { 1028 {
1056 msize = sizeof (struct SearchMessage); 1029 /* more requesting to be done... */
1057 GNUNET_assert (size >= msize); 1030 schedule_transmit_search_request (sc);
1058 mbc.uri = NULL; 1031 return msize;
1059 mbc.put_cnt = 0;
1060 GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map,
1061 &find_result_set,
1062 &mbc);
1063 sqms = mbc.put_cnt;
1064 mbc.put_cnt = (size - msize) / sizeof (GNUNET_HashCode);
1065 mbc.put_cnt = GNUNET_MIN (mbc.put_cnt,
1066 sqms - mbc.skip_cnt);
1067 if (sc->search_request_map_offset < sqms)
1068 GNUNET_assert (mbc.put_cnt > 0);
1069
1070 sm->header.size = htons (msize);
1071 if (0 != (sc->options & GNUNET_FS_SEARCH_OPTION_LOOPBACK_ONLY))
1072 sm->options = htonl (1);
1073 else
1074 sm->options = htonl (0);
1075 sm->type = htonl (GNUNET_BLOCK_TYPE_ANY);
1076 sm->anonymity_level = htonl (sc->anonymity);
1077 memset (&sm->target, 0, sizeof (GNUNET_HashCode));
1078 sm->query = sc->requests[sc->keyword_offset].query;
1079 msize += sizeof (GNUNET_HashCode) * mbc.put_cnt;
1080 GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map,
1081 &build_result_set,
1082 &mbc);
1083 sm->header.size = htons (msize);
1084 if (sqms != sc->search_request_map_offset)
1085 {
1086 /* more requesting to be done... */
1087 schedule_transmit_search_request (sc);
1088 return msize;
1089 }
1090 sc->keyword_offset++;
1091 if (sc->uri->data.ksk.keywordCount !=
1092 sc->keyword_offset)
1093 {
1094 /* more requesting to be done... */
1095 schedule_transmit_search_request (sc);
1096 return msize;
1097 }
1098 } 1032 }
1033 }
1099 else 1034 else
1035 {
1036 GNUNET_assert (GNUNET_FS_uri_test_sks (sc->uri));
1037 msize = sizeof (struct SearchMessage);
1038 GNUNET_assert (size >= msize);
1039 if (0 != (sc->options & GNUNET_FS_SEARCH_OPTION_LOOPBACK_ONLY))
1040 sm->options = htonl (1);
1041 else
1042 sm->options = htonl (0);
1043 sm->type = htonl (GNUNET_BLOCK_TYPE_FS_SBLOCK);
1044 sm->anonymity_level = htonl (sc->anonymity);
1045 sm->target = sc->uri->data.sks.namespace;
1046 identifier = sc->uri->data.sks.identifier;
1047 GNUNET_CRYPTO_hash (identifier, strlen (identifier), &key);
1048 GNUNET_CRYPTO_hash (&key, sizeof (GNUNET_HashCode), &idh);
1049 GNUNET_CRYPTO_hash_xor (&idh, &sm->target, &sm->query);
1050 mbc.put_cnt = (size - msize) / sizeof (GNUNET_HashCode);
1051 sqms = GNUNET_CONTAINER_multihashmap_size (sc->master_result_map);
1052 mbc.put_cnt = GNUNET_MIN (mbc.put_cnt, sqms - mbc.skip_cnt);
1053 mbc.uri = NULL;
1054 if (sc->search_request_map_offset < sqms)
1055 GNUNET_assert (mbc.put_cnt > 0);
1056 msize += sizeof (GNUNET_HashCode) * mbc.put_cnt;
1057 GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map,
1058 &build_result_set, &mbc);
1059 sm->header.size = htons (msize);
1060 if (sqms != sc->search_request_map_offset)
1100 { 1061 {
1101 GNUNET_assert (GNUNET_FS_uri_test_sks (sc->uri)); 1062 /* more requesting to be done... */
1102 msize = sizeof (struct SearchMessage); 1063 schedule_transmit_search_request (sc);
1103 GNUNET_assert (size >= msize); 1064 return msize;
1104 if (0 != (sc->options & GNUNET_FS_SEARCH_OPTION_LOOPBACK_ONLY))
1105 sm->options = htonl (1);
1106 else
1107 sm->options = htonl (0);
1108 sm->type = htonl (GNUNET_BLOCK_TYPE_FS_SBLOCK);
1109 sm->anonymity_level = htonl (sc->anonymity);
1110 sm->target = sc->uri->data.sks.namespace;
1111 identifier = sc->uri->data.sks.identifier;
1112 GNUNET_CRYPTO_hash (identifier,
1113 strlen (identifier),
1114 &key);
1115 GNUNET_CRYPTO_hash (&key,
1116 sizeof (GNUNET_HashCode),
1117 &idh);
1118 GNUNET_CRYPTO_hash_xor (&idh,
1119 &sm->target,
1120 &sm->query);
1121 mbc.put_cnt = (size - msize) / sizeof (GNUNET_HashCode);
1122 sqms = GNUNET_CONTAINER_multihashmap_size (sc->master_result_map);
1123 mbc.put_cnt = GNUNET_MIN (mbc.put_cnt,
1124 sqms - mbc.skip_cnt);
1125 mbc.uri = NULL;
1126 if (sc->search_request_map_offset < sqms)
1127 GNUNET_assert (mbc.put_cnt > 0);
1128 msize += sizeof (GNUNET_HashCode) * mbc.put_cnt;
1129 GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map,
1130 &build_result_set,
1131 &mbc);
1132 sm->header.size = htons (msize);
1133 if (sqms != sc->search_request_map_offset)
1134 {
1135 /* more requesting to be done... */
1136 schedule_transmit_search_request (sc);
1137 return msize;
1138 }
1139 } 1065 }
1066 }
1140 GNUNET_CLIENT_receive (sc->client, 1067 GNUNET_CLIENT_receive (sc->client,
1141 &receive_results, 1068 &receive_results, sc, GNUNET_TIME_UNIT_FOREVER_REL);
1142 sc,
1143 GNUNET_TIME_UNIT_FOREVER_REL);
1144 return msize; 1069 return msize;
1145} 1070}
1146 1071
@@ -1159,16 +1084,16 @@ schedule_transmit_search_request (struct GNUNET_FS_SearchContext *sc)
1159 unsigned int fit; 1084 unsigned int fit;
1160 1085
1161 size = sizeof (struct SearchMessage); 1086 size = sizeof (struct SearchMessage);
1162 sqms = GNUNET_CONTAINER_multihashmap_size (sc->master_result_map) - sc->search_request_map_offset; 1087 sqms =
1088 GNUNET_CONTAINER_multihashmap_size (sc->master_result_map) -
1089 sc->search_request_map_offset;
1163 fit = (GNUNET_SERVER_MAX_MESSAGE_SIZE - 1 - size) / sizeof (GNUNET_HashCode); 1090 fit = (GNUNET_SERVER_MAX_MESSAGE_SIZE - 1 - size) / sizeof (GNUNET_HashCode);
1164 fit = GNUNET_MIN (fit, sqms); 1091 fit = GNUNET_MIN (fit, sqms);
1165 size += sizeof (GNUNET_HashCode) * fit; 1092 size += sizeof (GNUNET_HashCode) * fit;
1166 GNUNET_CLIENT_notify_transmit_ready (sc->client, 1093 GNUNET_CLIENT_notify_transmit_ready (sc->client,
1167 size, 1094 size,
1168 GNUNET_CONSTANTS_SERVICE_TIMEOUT, 1095 GNUNET_CONSTANTS_SERVICE_TIMEOUT,
1169 GNUNET_NO, 1096 GNUNET_NO, &transmit_search_request, sc);
1170 &transmit_search_request,
1171 sc);
1172 1097
1173} 1098}
1174 1099
@@ -1181,20 +1106,18 @@ schedule_transmit_search_request (struct GNUNET_FS_SearchContext *sc)
1181 * @param tc unused 1106 * @param tc unused
1182 */ 1107 */
1183static void 1108static void
1184do_reconnect (void *cls, 1109do_reconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1185 const struct GNUNET_SCHEDULER_TaskContext *tc)
1186{ 1110{
1187 struct GNUNET_FS_SearchContext *sc = cls; 1111 struct GNUNET_FS_SearchContext *sc = cls;
1188 struct GNUNET_CLIENT_Connection *client; 1112 struct GNUNET_CLIENT_Connection *client;
1189 1113
1190 sc->task = GNUNET_SCHEDULER_NO_TASK; 1114 sc->task = GNUNET_SCHEDULER_NO_TASK;
1191 client = GNUNET_CLIENT_connect ("fs", 1115 client = GNUNET_CLIENT_connect ("fs", sc->h->cfg);
1192 sc->h->cfg);
1193 if (NULL == client) 1116 if (NULL == client)
1194 { 1117 {
1195 try_reconnect (sc); 1118 try_reconnect (sc);
1196 return; 1119 return;
1197 } 1120 }
1198 sc->client = client; 1121 sc->client = client;
1199 sc->search_request_map_offset = 0; 1122 sc->search_request_map_offset = 0;
1200 sc->keyword_offset = 0; 1123 sc->keyword_offset = 0;
@@ -1209,18 +1132,17 @@ do_reconnect (void *cls,
1209 * 1132 *
1210 * @param sc the search to reconnec 1133 * @param sc the search to reconnec
1211 */ 1134 */
1212static void 1135static void
1213try_reconnect (struct GNUNET_FS_SearchContext *sc) 1136try_reconnect (struct GNUNET_FS_SearchContext *sc)
1214{ 1137{
1215 if (NULL != sc->client) 1138 if (NULL != sc->client)
1216 { 1139 {
1217 GNUNET_CLIENT_disconnect (sc->client, GNUNET_NO); 1140 GNUNET_CLIENT_disconnect (sc->client, GNUNET_NO);
1218 sc->client = NULL; 1141 sc->client = NULL;
1219 } 1142 }
1220 sc->task 1143 sc->task
1221 = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 1144 = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
1222 &do_reconnect, 1145 &do_reconnect, sc);
1223 sc);
1224} 1146}
1225 1147
1226 1148
@@ -1238,36 +1160,34 @@ try_reconnect (struct GNUNET_FS_SearchContext *sc)
1238 */ 1160 */
1239static struct GNUNET_FS_SearchContext * 1161static struct GNUNET_FS_SearchContext *
1240search_start (struct GNUNET_FS_Handle *h, 1162search_start (struct GNUNET_FS_Handle *h,
1241 const struct GNUNET_FS_Uri *uri, 1163 const struct GNUNET_FS_Uri *uri,
1242 uint32_t anonymity, 1164 uint32_t anonymity,
1243 enum GNUNET_FS_SearchOptions options, 1165 enum GNUNET_FS_SearchOptions options,
1244 void *cctx, 1166 void *cctx, struct GNUNET_FS_SearchResult *psearch)
1245 struct GNUNET_FS_SearchResult *psearch)
1246{ 1167{
1247 struct GNUNET_FS_SearchContext *sc; 1168 struct GNUNET_FS_SearchContext *sc;
1248 struct GNUNET_FS_ProgressInfo pi; 1169 struct GNUNET_FS_ProgressInfo pi;
1249 1170
1250 sc = GNUNET_malloc (sizeof(struct GNUNET_FS_SearchContext)); 1171 sc = GNUNET_malloc (sizeof (struct GNUNET_FS_SearchContext));
1251 sc->h = h; 1172 sc->h = h;
1252 sc->options = options; 1173 sc->options = options;
1253 sc->uri = GNUNET_FS_uri_dup (uri); 1174 sc->uri = GNUNET_FS_uri_dup (uri);
1254 sc->anonymity = anonymity; 1175 sc->anonymity = anonymity;
1255 sc->start_time = GNUNET_TIME_absolute_get (); 1176 sc->start_time = GNUNET_TIME_absolute_get ();
1256 if (psearch != NULL) 1177 if (psearch != NULL)
1257 { 1178 {
1258 sc->psearch_result = psearch; 1179 sc->psearch_result = psearch;
1259 psearch->update_search = sc; 1180 psearch->update_search = sc;
1260 } 1181 }
1261 sc->master_result_map = GNUNET_CONTAINER_multihashmap_create (16); 1182 sc->master_result_map = GNUNET_CONTAINER_multihashmap_create (16);
1262 sc->client_info = cctx; 1183 sc->client_info = cctx;
1263 if (GNUNET_OK != 1184 if (GNUNET_OK != GNUNET_FS_search_start_searching_ (sc))
1264 GNUNET_FS_search_start_searching_ (sc)) 1185 {
1265 { 1186 GNUNET_FS_uri_destroy (sc->uri);
1266 GNUNET_FS_uri_destroy (sc->uri); 1187 GNUNET_CONTAINER_multihashmap_destroy (sc->master_result_map);
1267 GNUNET_CONTAINER_multihashmap_destroy (sc->master_result_map); 1188 GNUNET_free (sc);
1268 GNUNET_free (sc); 1189 return NULL;
1269 return NULL; 1190 }
1270 }
1271 GNUNET_FS_search_sync_ (sc); 1191 GNUNET_FS_search_sync_ (sc);
1272 pi.status = GNUNET_FS_STATUS_SEARCH_START; 1192 pi.status = GNUNET_FS_STATUS_SEARCH_START;
1273 sc->client_info = GNUNET_FS_search_make_status_ (&pi, sc); 1193 sc->client_info = GNUNET_FS_search_make_status_ (&pi, sc);
@@ -1288,39 +1208,35 @@ GNUNET_FS_search_start_searching_ (struct GNUNET_FS_SearchContext *sc)
1288 unsigned int i; 1208 unsigned int i;
1289 const char *keyword; 1209 const char *keyword;
1290 GNUNET_HashCode hc; 1210 GNUNET_HashCode hc;
1291 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pub; 1211 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pub;
1292 struct GNUNET_CRYPTO_RsaPrivateKey *pk; 1212 struct GNUNET_CRYPTO_RsaPrivateKey *pk;
1293 1213
1294 GNUNET_assert (NULL == sc->client); 1214 GNUNET_assert (NULL == sc->client);
1295 if (GNUNET_FS_uri_test_ksk (sc->uri)) 1215 if (GNUNET_FS_uri_test_ksk (sc->uri))
1216 {
1217 GNUNET_assert (0 != sc->uri->data.ksk.keywordCount);
1218 sc->requests = GNUNET_malloc (sizeof (struct SearchRequestEntry) *
1219 sc->uri->data.ksk.keywordCount);
1220 for (i = 0; i < sc->uri->data.ksk.keywordCount; i++)
1296 { 1221 {
1297 GNUNET_assert (0 != sc->uri->data.ksk.keywordCount); 1222 keyword = &sc->uri->data.ksk.keywords[i][1];
1298 sc->requests = GNUNET_malloc (sizeof (struct SearchRequestEntry) * 1223 GNUNET_CRYPTO_hash (keyword, strlen (keyword), &hc);
1299 sc->uri->data.ksk.keywordCount); 1224 pk = GNUNET_CRYPTO_rsa_key_create_from_hash (&hc);
1300 for (i=0;i<sc->uri->data.ksk.keywordCount;i++) 1225 GNUNET_assert (pk != NULL);
1301 { 1226 GNUNET_CRYPTO_rsa_key_get_public (pk, &pub);
1302 keyword = &sc->uri->data.ksk.keywords[i][1]; 1227 GNUNET_CRYPTO_rsa_key_free (pk);
1303 GNUNET_CRYPTO_hash (keyword, 1228 GNUNET_CRYPTO_hash (&pub,
1304 strlen (keyword), 1229 sizeof (struct
1305 &hc); 1230 GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
1306 pk = GNUNET_CRYPTO_rsa_key_create_from_hash (&hc); 1231 &sc->requests[i].query);
1307 GNUNET_assert (pk != NULL); 1232 sc->requests[i].mandatory = (sc->uri->data.ksk.keywords[i][0] == '+');
1308 GNUNET_CRYPTO_rsa_key_get_public (pk, &pub); 1233 if (sc->requests[i].mandatory)
1309 GNUNET_CRYPTO_rsa_key_free (pk); 1234 sc->mandatory_count++;
1310 GNUNET_CRYPTO_hash (&pub, 1235 sc->requests[i].results = GNUNET_CONTAINER_multihashmap_create (4);
1311 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), 1236 GNUNET_CRYPTO_hash (keyword, strlen (keyword), &sc->requests[i].key);
1312 &sc->requests[i].query);
1313 sc->requests[i].mandatory = (sc->uri->data.ksk.keywords[i][0] == '+');
1314 if (sc->requests[i].mandatory)
1315 sc->mandatory_count++;
1316 sc->requests[i].results = GNUNET_CONTAINER_multihashmap_create (4);
1317 GNUNET_CRYPTO_hash (keyword,
1318 strlen (keyword),
1319 &sc->requests[i].key);
1320 }
1321 } 1237 }
1322 sc->client = GNUNET_CLIENT_connect ("fs", 1238 }
1323 sc->h->cfg); 1239 sc->client = GNUNET_CLIENT_connect ("fs", sc->h->cfg);
1324 if (NULL == sc->client) 1240 if (NULL == sc->client)
1325 return GNUNET_SYSERR; 1241 return GNUNET_SYSERR;
1326 schedule_transmit_search_request (sc); 1242 schedule_transmit_search_request (sc);
@@ -1338,21 +1254,20 @@ GNUNET_FS_search_start_searching_ (struct GNUNET_FS_SearchContext *sc)
1338 */ 1254 */
1339static int 1255static int
1340search_result_freeze_probes (void *cls, 1256search_result_freeze_probes (void *cls,
1341 const GNUNET_HashCode * key, 1257 const GNUNET_HashCode * key, void *value)
1342 void *value)
1343{ 1258{
1344 struct GNUNET_FS_SearchResult *sr = value; 1259 struct GNUNET_FS_SearchResult *sr = value;
1345 1260
1346 if (sr->probe_ctx != NULL) 1261 if (sr->probe_ctx != NULL)
1347 { 1262 {
1348 GNUNET_FS_download_stop (sr->probe_ctx, GNUNET_YES); 1263 GNUNET_FS_download_stop (sr->probe_ctx, GNUNET_YES);
1349 sr->probe_ctx = NULL; 1264 sr->probe_ctx = NULL;
1350 } 1265 }
1351 if (sr->probe_cancel_task != GNUNET_SCHEDULER_NO_TASK) 1266 if (sr->probe_cancel_task != GNUNET_SCHEDULER_NO_TASK)
1352 { 1267 {
1353 GNUNET_SCHEDULER_cancel (sr->probe_cancel_task); 1268 GNUNET_SCHEDULER_cancel (sr->probe_cancel_task);
1354 sr->probe_cancel_task = GNUNET_SCHEDULER_NO_TASK; 1269 sr->probe_cancel_task = GNUNET_SCHEDULER_NO_TASK;
1355 } 1270 }
1356 if (sr->update_search != NULL) 1271 if (sr->update_search != NULL)
1357 GNUNET_FS_search_pause (sr->update_search); 1272 GNUNET_FS_search_pause (sr->update_search);
1358 return GNUNET_OK; 1273 return GNUNET_OK;
@@ -1369,8 +1284,7 @@ search_result_freeze_probes (void *cls,
1369 */ 1284 */
1370static int 1285static int
1371search_result_resume_probes (void *cls, 1286search_result_resume_probes (void *cls,
1372 const GNUNET_HashCode * key, 1287 const GNUNET_HashCode * key, void *value)
1373 void *value)
1374{ 1288{
1375 struct GNUNET_FS_SearchResult *sr = value; 1289 struct GNUNET_FS_SearchResult *sr = value;
1376 1290
@@ -1390,9 +1304,7 @@ search_result_resume_probes (void *cls,
1390 * @return GNUNET_OK 1304 * @return GNUNET_OK
1391 */ 1305 */
1392static int 1306static int
1393search_result_suspend (void *cls, 1307search_result_suspend (void *cls, const GNUNET_HashCode * key, void *value)
1394 const GNUNET_HashCode * key,
1395 void *value)
1396{ 1308{
1397 struct GNUNET_FS_SearchContext *sc = cls; 1309 struct GNUNET_FS_SearchContext *sc = cls;
1398 struct GNUNET_FS_SearchResult *sr = value; 1310 struct GNUNET_FS_SearchResult *sr = value;
@@ -1412,7 +1324,7 @@ search_result_suspend (void *cls,
1412 GNUNET_FS_uri_destroy (sr->uri); 1324 GNUNET_FS_uri_destroy (sr->uri);
1413 GNUNET_CONTAINER_meta_data_destroy (sr->meta); 1325 GNUNET_CONTAINER_meta_data_destroy (sr->meta);
1414 if (sr->probe_ctx != NULL) 1326 if (sr->probe_ctx != NULL)
1415 GNUNET_FS_download_stop (sr->probe_ctx, GNUNET_YES); 1327 GNUNET_FS_download_stop (sr->probe_ctx, GNUNET_YES);
1416 if (sr->probe_cancel_task != GNUNET_SCHEDULER_NO_TASK) 1328 if (sr->probe_cancel_task != GNUNET_SCHEDULER_NO_TASK)
1417 GNUNET_SCHEDULER_cancel (sr->probe_cancel_task); 1329 GNUNET_SCHEDULER_cancel (sr->probe_cancel_task);
1418 GNUNET_free (sr); 1330 GNUNET_free (sr);
@@ -1435,8 +1347,7 @@ GNUNET_FS_search_signal_suspend_ (void *cls)
1435 1347
1436 GNUNET_FS_end_top (sc->h, sc->top); 1348 GNUNET_FS_end_top (sc->h, sc->top);
1437 GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, 1349 GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map,
1438 &search_result_suspend, 1350 &search_result_suspend, sc);
1439 sc);
1440 pi.status = GNUNET_FS_STATUS_SEARCH_SUSPEND; 1351 pi.status = GNUNET_FS_STATUS_SEARCH_SUSPEND;
1441 sc->client_info = GNUNET_FS_search_make_status_ (&pi, sc); 1352 sc->client_info = GNUNET_FS_search_make_status_ (&pi, sc);
1442 GNUNET_break (NULL == sc->client_info); 1353 GNUNET_break (NULL == sc->client_info);
@@ -1446,11 +1357,11 @@ GNUNET_FS_search_signal_suspend_ (void *cls)
1446 GNUNET_CLIENT_disconnect (sc->client, GNUNET_NO); 1357 GNUNET_CLIENT_disconnect (sc->client, GNUNET_NO);
1447 GNUNET_CONTAINER_multihashmap_destroy (sc->master_result_map); 1358 GNUNET_CONTAINER_multihashmap_destroy (sc->master_result_map);
1448 if (sc->requests != NULL) 1359 if (sc->requests != NULL)
1449 { 1360 {
1450 GNUNET_assert (GNUNET_FS_uri_test_ksk (sc->uri)); 1361 GNUNET_assert (GNUNET_FS_uri_test_ksk (sc->uri));
1451 for (i=0;i<sc->uri->data.ksk.keywordCount;i++) 1362 for (i = 0; i < sc->uri->data.ksk.keywordCount; i++)
1452 GNUNET_CONTAINER_multihashmap_destroy (sc->requests[i].results); 1363 GNUNET_CONTAINER_multihashmap_destroy (sc->requests[i].results);
1453 } 1364 }
1454 GNUNET_free_non_null (sc->requests); 1365 GNUNET_free_non_null (sc->requests);
1455 GNUNET_free_non_null (sc->emsg); 1366 GNUNET_free_non_null (sc->emsg);
1456 GNUNET_FS_uri_destroy (sc->uri); 1367 GNUNET_FS_uri_destroy (sc->uri);
@@ -1472,12 +1383,12 @@ GNUNET_FS_search_signal_suspend_ (void *cls)
1472 */ 1383 */
1473struct GNUNET_FS_SearchContext * 1384struct GNUNET_FS_SearchContext *
1474GNUNET_FS_search_start (struct GNUNET_FS_Handle *h, 1385GNUNET_FS_search_start (struct GNUNET_FS_Handle *h,
1475 const struct GNUNET_FS_Uri *uri, 1386 const struct GNUNET_FS_Uri *uri,
1476 uint32_t anonymity, 1387 uint32_t anonymity,
1477 enum GNUNET_FS_SearchOptions options, 1388 enum GNUNET_FS_SearchOptions options, void *cctx)
1478 void *cctx)
1479{ 1389{
1480 struct GNUNET_FS_SearchContext *ret; 1390 struct GNUNET_FS_SearchContext *ret;
1391
1481 ret = search_start (h, uri, anonymity, options, cctx, NULL); 1392 ret = search_start (h, uri, anonymity, options, cctx, NULL);
1482 if (ret == NULL) 1393 if (ret == NULL)
1483 return NULL; 1394 return NULL;
@@ -1491,7 +1402,7 @@ GNUNET_FS_search_start (struct GNUNET_FS_Handle *h,
1491 * 1402 *
1492 * @param sc context for the search that should be paused 1403 * @param sc context for the search that should be paused
1493 */ 1404 */
1494void 1405void
1495GNUNET_FS_search_pause (struct GNUNET_FS_SearchContext *sc) 1406GNUNET_FS_search_pause (struct GNUNET_FS_SearchContext *sc)
1496{ 1407{
1497 struct GNUNET_FS_ProgressInfo pi; 1408 struct GNUNET_FS_ProgressInfo pi;
@@ -1504,8 +1415,7 @@ GNUNET_FS_search_pause (struct GNUNET_FS_SearchContext *sc)
1504 sc->client = NULL; 1415 sc->client = NULL;
1505 GNUNET_FS_search_sync_ (sc); 1416 GNUNET_FS_search_sync_ (sc);
1506 GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, 1417 GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map,
1507 &search_result_freeze_probes, 1418 &search_result_freeze_probes, sc);
1508 sc);
1509 pi.status = GNUNET_FS_STATUS_SEARCH_PAUSED; 1419 pi.status = GNUNET_FS_STATUS_SEARCH_PAUSED;
1510 sc->client_info = GNUNET_FS_search_make_status_ (&pi, sc); 1420 sc->client_info = GNUNET_FS_search_make_status_ (&pi, sc);
1511} 1421}
@@ -1516,7 +1426,7 @@ GNUNET_FS_search_pause (struct GNUNET_FS_SearchContext *sc)
1516 * 1426 *
1517 * @param sc context for the search that should be resumed 1427 * @param sc context for the search that should be resumed
1518 */ 1428 */
1519void 1429void
1520GNUNET_FS_search_continue (struct GNUNET_FS_SearchContext *sc) 1430GNUNET_FS_search_continue (struct GNUNET_FS_SearchContext *sc)
1521{ 1431{
1522 struct GNUNET_FS_ProgressInfo pi; 1432 struct GNUNET_FS_ProgressInfo pi;
@@ -1528,8 +1438,7 @@ GNUNET_FS_search_continue (struct GNUNET_FS_SearchContext *sc)
1528 pi.status = GNUNET_FS_STATUS_SEARCH_CONTINUED; 1438 pi.status = GNUNET_FS_STATUS_SEARCH_CONTINUED;
1529 sc->client_info = GNUNET_FS_search_make_status_ (&pi, sc); 1439 sc->client_info = GNUNET_FS_search_make_status_ (&pi, sc);
1530 GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, 1440 GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map,
1531 &search_result_resume_probes, 1441 &search_result_resume_probes, sc);
1532 sc);
1533} 1442}
1534 1443
1535 1444
@@ -1542,39 +1451,36 @@ GNUNET_FS_search_continue (struct GNUNET_FS_SearchContext *sc)
1542 * @return GNUNET_OK 1451 * @return GNUNET_OK
1543 */ 1452 */
1544static int 1453static int
1545search_result_free (void *cls, 1454search_result_free (void *cls, const GNUNET_HashCode * key, void *value)
1546 const GNUNET_HashCode * key,
1547 void *value)
1548{ 1455{
1549 struct GNUNET_FS_SearchContext *sc = cls; 1456 struct GNUNET_FS_SearchContext *sc = cls;
1550 struct GNUNET_FS_SearchResult *sr = value; 1457 struct GNUNET_FS_SearchResult *sr = value;
1551 struct GNUNET_FS_ProgressInfo pi; 1458 struct GNUNET_FS_ProgressInfo pi;
1552 1459
1553 if (NULL != sr->download) 1460 if (NULL != sr->download)
1461 {
1462 sr->download->search = NULL;
1463 sr->download->top = GNUNET_FS_make_top (sr->download->h,
1464 &GNUNET_FS_download_signal_suspend_,
1465 sr->download);
1466 if (NULL != sr->download->serialization)
1554 { 1467 {
1555 sr->download->search = NULL; 1468 GNUNET_FS_remove_sync_file_ (sc->h,
1556 sr->download->top = GNUNET_FS_make_top (sr->download->h, 1469 GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD,
1557 &GNUNET_FS_download_signal_suspend_, 1470 sr->download->serialization);
1558 sr->download); 1471 GNUNET_free (sr->download->serialization);
1559 if (NULL != sr->download->serialization) 1472 sr->download->serialization = NULL;
1560 {
1561 GNUNET_FS_remove_sync_file_ (sc->h,
1562 GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD,
1563 sr->download->serialization);
1564 GNUNET_free (sr->download->serialization);
1565 sr->download->serialization = NULL;
1566 }
1567 pi.status = GNUNET_FS_STATUS_DOWNLOAD_LOST_PARENT;
1568 GNUNET_FS_download_make_status_ (&pi,
1569 sr->download);
1570 GNUNET_FS_download_sync_ (sr->download);
1571 sr->download = NULL;
1572 } 1473 }
1474 pi.status = GNUNET_FS_STATUS_DOWNLOAD_LOST_PARENT;
1475 GNUNET_FS_download_make_status_ (&pi, sr->download);
1476 GNUNET_FS_download_sync_ (sr->download);
1477 sr->download = NULL;
1478 }
1573 if (NULL != sr->update_search) 1479 if (NULL != sr->update_search)
1574 { 1480 {
1575 GNUNET_FS_search_stop (sr->update_search); 1481 GNUNET_FS_search_stop (sr->update_search);
1576 GNUNET_assert (sr->update_search == NULL); 1482 GNUNET_assert (sr->update_search == NULL);
1577 } 1483 }
1578 pi.status = GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED; 1484 pi.status = GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED;
1579 pi.value.search.specifics.result_stopped.cctx = sr->client_info; 1485 pi.value.search.specifics.result_stopped.cctx = sr->client_info;
1580 pi.value.search.specifics.result_stopped.meta = sr->meta; 1486 pi.value.search.specifics.result_stopped.meta = sr->meta;
@@ -1585,7 +1491,7 @@ search_result_free (void *cls,
1585 GNUNET_FS_uri_destroy (sr->uri); 1491 GNUNET_FS_uri_destroy (sr->uri);
1586 GNUNET_CONTAINER_meta_data_destroy (sr->meta); 1492 GNUNET_CONTAINER_meta_data_destroy (sr->meta);
1587 if (sr->probe_ctx != NULL) 1493 if (sr->probe_ctx != NULL)
1588 GNUNET_FS_download_stop (sr->probe_ctx, GNUNET_YES); 1494 GNUNET_FS_download_stop (sr->probe_ctx, GNUNET_YES);
1589 if (sr->probe_cancel_task != GNUNET_SCHEDULER_NO_TASK) 1495 if (sr->probe_cancel_task != GNUNET_SCHEDULER_NO_TASK)
1590 GNUNET_SCHEDULER_cancel (sr->probe_cancel_task); 1496 GNUNET_SCHEDULER_cancel (sr->probe_cancel_task);
1591 GNUNET_free (sr); 1497 GNUNET_free (sr);
@@ -1598,7 +1504,7 @@ search_result_free (void *cls,
1598 * 1504 *
1599 * @param sc context for the search that should be stopped 1505 * @param sc context for the search that should be stopped
1600 */ 1506 */
1601void 1507void
1602GNUNET_FS_search_stop (struct GNUNET_FS_SearchContext *sc) 1508GNUNET_FS_search_stop (struct GNUNET_FS_SearchContext *sc)
1603{ 1509{
1604 struct GNUNET_FS_ProgressInfo pi; 1510 struct GNUNET_FS_ProgressInfo pi;
@@ -1609,22 +1515,21 @@ GNUNET_FS_search_stop (struct GNUNET_FS_SearchContext *sc)
1609 if (sc->psearch_result != NULL) 1515 if (sc->psearch_result != NULL)
1610 sc->psearch_result->update_search = NULL; 1516 sc->psearch_result->update_search = NULL;
1611 GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, 1517 GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map,
1612 &search_result_free, 1518 &search_result_free, sc);
1613 sc);
1614 if (sc->serialization != NULL) 1519 if (sc->serialization != NULL)
1615 { 1520 {
1616 GNUNET_FS_remove_sync_file_ (sc->h, 1521 GNUNET_FS_remove_sync_file_ (sc->h,
1617 (sc->psearch_result != NULL) 1522 (sc->psearch_result != NULL)
1618 ? GNUNET_FS_SYNC_PATH_CHILD_SEARCH 1523 ? GNUNET_FS_SYNC_PATH_CHILD_SEARCH
1619 : GNUNET_FS_SYNC_PATH_MASTER_SEARCH, 1524 : GNUNET_FS_SYNC_PATH_MASTER_SEARCH,
1620 sc->serialization); 1525 sc->serialization);
1621 GNUNET_FS_remove_sync_dir_ (sc->h, 1526 GNUNET_FS_remove_sync_dir_ (sc->h,
1622 (sc->psearch_result != NULL) 1527 (sc->psearch_result != NULL)
1623 ? GNUNET_FS_SYNC_PATH_CHILD_SEARCH 1528 ? GNUNET_FS_SYNC_PATH_CHILD_SEARCH
1624 : GNUNET_FS_SYNC_PATH_MASTER_SEARCH, 1529 : GNUNET_FS_SYNC_PATH_MASTER_SEARCH,
1625 sc->serialization); 1530 sc->serialization);
1626 GNUNET_free (sc->serialization); 1531 GNUNET_free (sc->serialization);
1627 } 1532 }
1628 pi.status = GNUNET_FS_STATUS_SEARCH_STOPPED; 1533 pi.status = GNUNET_FS_STATUS_SEARCH_STOPPED;
1629 sc->client_info = GNUNET_FS_search_make_status_ (&pi, sc); 1534 sc->client_info = GNUNET_FS_search_make_status_ (&pi, sc);
1630 GNUNET_break (NULL == sc->client_info); 1535 GNUNET_break (NULL == sc->client_info);
@@ -1634,11 +1539,11 @@ GNUNET_FS_search_stop (struct GNUNET_FS_SearchContext *sc)
1634 GNUNET_CLIENT_disconnect (sc->client, GNUNET_NO); 1539 GNUNET_CLIENT_disconnect (sc->client, GNUNET_NO);
1635 GNUNET_CONTAINER_multihashmap_destroy (sc->master_result_map); 1540 GNUNET_CONTAINER_multihashmap_destroy (sc->master_result_map);
1636 if (sc->requests != NULL) 1541 if (sc->requests != NULL)
1637 { 1542 {
1638 GNUNET_assert (GNUNET_FS_uri_test_ksk (sc->uri)); 1543 GNUNET_assert (GNUNET_FS_uri_test_ksk (sc->uri));
1639 for (i=0;i<sc->uri->data.ksk.keywordCount;i++) 1544 for (i = 0; i < sc->uri->data.ksk.keywordCount; i++)
1640 GNUNET_CONTAINER_multihashmap_destroy (sc->requests[i].results); 1545 GNUNET_CONTAINER_multihashmap_destroy (sc->requests[i].results);
1641 } 1546 }
1642 GNUNET_free_non_null (sc->requests); 1547 GNUNET_free_non_null (sc->requests);
1643 GNUNET_free_non_null (sc->emsg); 1548 GNUNET_free_non_null (sc->emsg);
1644 GNUNET_FS_uri_destroy (sc->uri); 1549 GNUNET_FS_uri_destroy (sc->uri);
diff --git a/src/fs/fs_test_lib.c b/src/fs/fs_test_lib.c
index 522967f13..334432232 100644
--- a/src/fs/fs_test_lib.c
+++ b/src/fs/fs_test_lib.c
@@ -77,7 +77,7 @@ struct GNUNET_FS_TestDaemon
77 * Function to call when upload is done. 77 * Function to call when upload is done.
78 */ 78 */
79 GNUNET_FS_TEST_UriContinuation publish_cont; 79 GNUNET_FS_TEST_UriContinuation publish_cont;
80 80
81 /** 81 /**
82 * Closure for publish_cont. 82 * Closure for publish_cont.
83 */ 83 */
@@ -105,7 +105,7 @@ struct GNUNET_FS_TestDaemon
105 105
106 /** 106 /**
107 * Name of the temporary file used, or NULL for none. 107 * Name of the temporary file used, or NULL for none.
108 */ 108 */
109 char *publish_tmp_file; 109 char *publish_tmp_file;
110 110
111 /** 111 /**
@@ -130,7 +130,7 @@ struct GNUNET_FS_TestDaemon
130 130
131 /** 131 /**
132 * Context for current download operation. 132 * Context for current download operation.
133 */ 133 */
134 struct GNUNET_FS_DownloadContext *download_context; 134 struct GNUNET_FS_DownloadContext *download_context;
135 135
136 /** 136 /**
@@ -138,39 +138,35 @@ struct GNUNET_FS_TestDaemon
138 */ 138 */
139 int verbose; 139 int verbose;
140 140
141 141
142}; 142};
143 143
144/** 144/**
145 * Check whether peers successfully shut down. 145 * Check whether peers successfully shut down.
146 */ 146 */
147static void 147static void
148shutdown_callback (void *cls, 148shutdown_callback (void *cls, const char *emsg)
149 const char *emsg)
150{ 149{
151 struct GNUNET_CONFIGURATION_Handle *gcfg = cls; 150 struct GNUNET_CONFIGURATION_Handle *gcfg = cls;
152 151
153 if (emsg != NULL) 152 if (emsg != NULL)
154 { 153 {
155 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 154 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
156 "Shutdown of peers failed: %s\n", 155 "Shutdown of peers failed: %s\n", emsg);
157 emsg); 156 }
158 }
159 else 157 else
160 { 158 {
161#if VERBOSE 159#if VERBOSE
162 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 160 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All peers successfully shut down!\n");
163 "All peers successfully shut down!\n");
164#endif 161#endif
165 } 162 }
166 if (gcfg != NULL) 163 if (gcfg != NULL)
167 GNUNET_CONFIGURATION_destroy (gcfg); 164 GNUNET_CONFIGURATION_destroy (gcfg);
168} 165}
169 166
170 167
171static void 168static void
172report_uri (void *cls, 169report_uri (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
173 const struct GNUNET_SCHEDULER_TaskContext *tc)
174{ 170{
175 struct GNUNET_FS_TestDaemon *daemon = cls; 171 struct GNUNET_FS_TestDaemon *daemon = cls;
176 GNUNET_FS_TEST_UriContinuation cont; 172 GNUNET_FS_TEST_UriContinuation cont;
@@ -181,73 +177,70 @@ report_uri (void *cls,
181 cont = daemon->publish_cont; 177 cont = daemon->publish_cont;
182 daemon->publish_cont = NULL; 178 daemon->publish_cont = NULL;
183 uri = daemon->publish_uri; 179 uri = daemon->publish_uri;
184 cont (daemon->publish_cont_cls, 180 cont (daemon->publish_cont_cls, uri);
185 uri);
186 GNUNET_FS_uri_destroy (uri); 181 GNUNET_FS_uri_destroy (uri);
187} 182}
188 183
189 184
190static void 185static void
191report_success (void *cls, 186report_success (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
192 const struct GNUNET_SCHEDULER_TaskContext *tc)
193{ 187{
194 struct GNUNET_FS_TestDaemon *daemon = cls; 188 struct GNUNET_FS_TestDaemon *daemon = cls;
195 189
196 GNUNET_FS_download_stop (daemon->download_context, GNUNET_YES); 190 GNUNET_FS_download_stop (daemon->download_context, GNUNET_YES);
197 daemon->download_context = NULL; 191 daemon->download_context = NULL;
198 GNUNET_SCHEDULER_add_continuation (daemon->download_cont, 192 GNUNET_SCHEDULER_add_continuation (daemon->download_cont,
199 daemon->download_cont_cls, 193 daemon->download_cont_cls,
200 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 194 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
201 daemon->download_cont = NULL; 195 daemon->download_cont = NULL;
202} 196}
203 197
204 198
205static void* 199static void *
206progress_cb (void *cls, 200progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
207 const struct GNUNET_FS_ProgressInfo *info)
208{ 201{
209 struct GNUNET_FS_TestDaemon *daemon = cls; 202 struct GNUNET_FS_TestDaemon *daemon = cls;
210 203
211 switch (info->status) 204 switch (info->status)
212 { 205 {
213 case GNUNET_FS_STATUS_PUBLISH_COMPLETED: 206 case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
214 GNUNET_SCHEDULER_cancel (daemon->publish_timeout_task); 207 GNUNET_SCHEDULER_cancel (daemon->publish_timeout_task);
215 daemon->publish_timeout_task = GNUNET_SCHEDULER_NO_TASK; 208 daemon->publish_timeout_task = GNUNET_SCHEDULER_NO_TASK;
216 daemon->publish_uri = GNUNET_FS_uri_dup (info->value.publish.specifics.completed.chk_uri); 209 daemon->publish_uri =
217 GNUNET_SCHEDULER_add_continuation (&report_uri, 210 GNUNET_FS_uri_dup (info->value.publish.specifics.completed.chk_uri);
218 daemon, 211 GNUNET_SCHEDULER_add_continuation (&report_uri, daemon,
219 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 212 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
220 break; 213 break;
221 case GNUNET_FS_STATUS_PUBLISH_PROGRESS: 214 case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
222 if (daemon->verbose) 215 if (daemon->verbose)
223 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 216 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
224 "Publishing at %llu/%llu bytes\n", 217 "Publishing at %llu/%llu bytes\n",
225 (unsigned long long) info->value.publish.completed, 218 (unsigned long long) info->value.publish.completed,
226 (unsigned long long) info->value.publish.size); 219 (unsigned long long) info->value.publish.size);
227 break; 220 break;
228 case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: 221 case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS:
229 if (daemon->verbose) 222 if (daemon->verbose)
230 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 223 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
231 "Download at %llu/%llu bytes\n", 224 "Download at %llu/%llu bytes\n",
232 (unsigned long long) info->value.download.completed, 225 (unsigned long long) info->value.download.completed,
233 (unsigned long long) info->value.download.size); 226 (unsigned long long) info->value.download.size);
234 break; 227 break;
235 case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: 228 case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED:
236 GNUNET_SCHEDULER_cancel (daemon->download_timeout_task); 229 GNUNET_SCHEDULER_cancel (daemon->download_timeout_task);
237 daemon->download_timeout_task = GNUNET_SCHEDULER_NO_TASK; 230 daemon->download_timeout_task = GNUNET_SCHEDULER_NO_TASK;
238 GNUNET_SCHEDULER_add_continuation (&report_success, 231 GNUNET_SCHEDULER_add_continuation (&report_success,
239 daemon, 232 daemon,
240 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 233 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
241 break; 234 break;
242 case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE: 235 case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE:
243 case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE: 236 case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE:
244 break; 237 break;
245 /* FIXME: monitor data correctness during download progress */ 238 /* FIXME: monitor data correctness during download progress */
246 /* FIXME: do performance reports given sufficient verbosity */ 239 /* FIXME: do performance reports given sufficient verbosity */
247 /* FIXME: advance timeout task to "immediate" on error */ 240 /* FIXME: advance timeout task to "immediate" on error */
248 default: 241 default:
249 break; 242 break;
250 } 243 }
251 return NULL; 244 return NULL;
252} 245}
253 246
@@ -266,31 +259,28 @@ struct StartContext
266}; 259};
267 260
268 261
269static void 262static void
270notify_running (void *cls, 263notify_running (void *cls,
271 const struct GNUNET_PeerIdentity *id, 264 const struct GNUNET_PeerIdentity *id,
272 const struct GNUNET_CONFIGURATION_Handle *cfg, 265 const struct GNUNET_CONFIGURATION_Handle *cfg,
273 struct GNUNET_TESTING_Daemon *d, 266 struct GNUNET_TESTING_Daemon *d, const char *emsg)
274 const char *emsg)
275{ 267{
276 struct StartContext *sctx = cls; 268 struct StartContext *sctx = cls;
277 unsigned int i; 269 unsigned int i;
278 270
279 if (emsg != NULL) 271 if (emsg != NULL)
280 { 272 {
281 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 273 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
282 _("Failed to start daemon: %s\n"), 274 _("Failed to start daemon: %s\n"), emsg);
283 emsg); 275 return;
284 return; 276 }
285 }
286 i = 0; 277 i = 0;
287 while (i < sctx->total) 278 while (i < sctx->total)
288 { 279 {
289 if (GNUNET_TESTING_daemon_get (sctx->group, 280 if (GNUNET_TESTING_daemon_get (sctx->group, i) == d)
290 i) == d) 281 break;
291 break; 282 i++;
292 i++; 283 }
293 }
294 GNUNET_assert (i < sctx->total); 284 GNUNET_assert (i < sctx->total);
295 GNUNET_assert (sctx->have < sctx->total); 285 GNUNET_assert (sctx->have < sctx->total);
296 GNUNET_assert (sctx->daemons[i]->cfg == NULL); 286 GNUNET_assert (sctx->daemons[i]->cfg == NULL);
@@ -300,50 +290,49 @@ notify_running (void *cls,
300 sctx->daemons[i]->id = *id; 290 sctx->daemons[i]->id = *id;
301 sctx->have++; 291 sctx->have++;
302 if (sctx->have == sctx->total) 292 if (sctx->have == sctx->total)
293 {
294 GNUNET_SCHEDULER_add_continuation (sctx->cont,
295 sctx->cont_cls,
296 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
297 sctx->daemons[0]->gcfg = sctx->cfg;
298 GNUNET_SCHEDULER_cancel (sctx->timeout_task);
299 for (i = 0; i < sctx->total; i++)
303 { 300 {
304 GNUNET_SCHEDULER_add_continuation (sctx->cont, 301 sctx->daemons[i]->fs = GNUNET_FS_start (sctx->daemons[i]->cfg,
305 sctx->cont_cls, 302 "<tester>",
306 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 303 &progress_cb,
307 sctx->daemons[0]->gcfg = sctx->cfg; 304 sctx->daemons[i],
308 GNUNET_SCHEDULER_cancel (sctx->timeout_task); 305 GNUNET_FS_FLAGS_NONE,
309 for (i=0;i<sctx->total;i++) 306 GNUNET_FS_OPTIONS_END);
310 {
311 sctx->daemons[i]->fs = GNUNET_FS_start (sctx->daemons[i]->cfg,
312 "<tester>",
313 &progress_cb,
314 sctx->daemons[i],
315 GNUNET_FS_FLAGS_NONE,
316 GNUNET_FS_OPTIONS_END);
317 }
318 GNUNET_free (sctx);
319 } 307 }
308 GNUNET_free (sctx);
309 }
320} 310}
321 311
322 312
323static void 313static void
324start_timeout (void *cls, 314start_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
325 const struct GNUNET_SCHEDULER_TaskContext *tc)
326{ 315{
327 struct StartContext *sctx = cls; 316 struct StartContext *sctx = cls;
328 unsigned int i; 317 unsigned int i;
329 318
330 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 319 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
331 "Timeout while trying to start daemons\n"); 320 "Timeout while trying to start daemons\n");
332 GNUNET_TESTING_daemons_stop (sctx->group, 321 GNUNET_TESTING_daemons_stop (sctx->group,
333 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30), 322 GNUNET_TIME_relative_multiply
334 &shutdown_callback, 323 (GNUNET_TIME_UNIT_SECONDS, 30),
335 NULL); 324 &shutdown_callback, NULL);
336 for (i=0;i<sctx->total;i++) 325 for (i = 0; i < sctx->total; i++)
337 { 326 {
338 if (i < sctx->have) 327 if (i < sctx->have)
339 GNUNET_CONFIGURATION_destroy (sctx->daemons[i]->cfg); 328 GNUNET_CONFIGURATION_destroy (sctx->daemons[i]->cfg);
340 GNUNET_free (sctx->daemons[i]); 329 GNUNET_free (sctx->daemons[i]);
341 sctx->daemons[i] = NULL; 330 sctx->daemons[i] = NULL;
342 } 331 }
343 GNUNET_CONFIGURATION_destroy (sctx->cfg); 332 GNUNET_CONFIGURATION_destroy (sctx->cfg);
344 GNUNET_SCHEDULER_add_continuation (sctx->cont, 333 GNUNET_SCHEDULER_add_continuation (sctx->cont,
345 sctx->cont_cls, 334 sctx->cont_cls,
346 GNUNET_SCHEDULER_REASON_TIMEOUT); 335 GNUNET_SCHEDULER_REASON_TIMEOUT);
347 GNUNET_free (sctx); 336 GNUNET_free (sctx);
348} 337}
349 338
@@ -362,11 +351,10 @@ start_timeout (void *cls,
362 */ 351 */
363void 352void
364GNUNET_FS_TEST_daemons_start (const char *template_cfg_file, 353GNUNET_FS_TEST_daemons_start (const char *template_cfg_file,
365 struct GNUNET_TIME_Relative timeout, 354 struct GNUNET_TIME_Relative timeout,
366 unsigned int total, 355 unsigned int total,
367 struct GNUNET_FS_TestDaemon **daemons, 356 struct GNUNET_FS_TestDaemon **daemons,
368 GNUNET_SCHEDULER_Task cont, 357 GNUNET_SCHEDULER_Task cont, void *cont_cls)
369 void *cont_cls)
370{ 358{
371 struct StartContext *sctx; 359 struct StartContext *sctx;
372 unsigned int i; 360 unsigned int i;
@@ -378,34 +366,27 @@ GNUNET_FS_TEST_daemons_start (const char *template_cfg_file,
378 sctx->cont = cont; 366 sctx->cont = cont;
379 sctx->cont_cls = cont_cls; 367 sctx->cont_cls = cont_cls;
380 sctx->cfg = GNUNET_CONFIGURATION_create (); 368 sctx->cfg = GNUNET_CONFIGURATION_create ();
381 if (GNUNET_OK != 369 if (GNUNET_OK != GNUNET_CONFIGURATION_load (sctx->cfg, template_cfg_file))
382 GNUNET_CONFIGURATION_load (sctx->cfg, 370 {
383 template_cfg_file)) 371 GNUNET_break (0);
384 { 372 GNUNET_CONFIGURATION_destroy (sctx->cfg);
385 GNUNET_break (0); 373 GNUNET_free (sctx);
386 GNUNET_CONFIGURATION_destroy (sctx->cfg); 374 GNUNET_SCHEDULER_add_continuation (cont,
387 GNUNET_free (sctx); 375 cont_cls,
388 GNUNET_SCHEDULER_add_continuation (cont, 376 GNUNET_SCHEDULER_REASON_TIMEOUT);
389 cont_cls, 377 return;
390 GNUNET_SCHEDULER_REASON_TIMEOUT); 378 }
391 return; 379 for (i = 0; i < total; i++)
392 }
393 for (i=0;i<total;i++)
394 daemons[i] = GNUNET_malloc (sizeof (struct GNUNET_FS_TestDaemon)); 380 daemons[i] = GNUNET_malloc (sizeof (struct GNUNET_FS_TestDaemon));
395 sctx->group = GNUNET_TESTING_daemons_start (sctx->cfg, 381 sctx->group = GNUNET_TESTING_daemons_start (sctx->cfg, total, total, /* Outstanding connections */
396 total, 382 total, /* Outstanding ssh connections */
397 total, /* Outstanding connections */ 383 timeout,
398 total, /* Outstanding ssh connections */ 384 NULL,
399 timeout, 385 NULL,
400 NULL, 386 &notify_running,
401 NULL, 387 sctx, NULL, NULL, NULL);
402 &notify_running,
403 sctx,
404 NULL, NULL,
405 NULL);
406 sctx->timeout_task = GNUNET_SCHEDULER_add_delayed (timeout, 388 sctx->timeout_task = GNUNET_SCHEDULER_add_delayed (timeout,
407 &start_timeout, 389 &start_timeout, sctx);
408 sctx);
409} 390}
410 391
411 392
@@ -432,26 +413,25 @@ struct ConnectContext
432 */ 413 */
433static void 414static void
434notify_connection (void *cls, 415notify_connection (void *cls,
435 const struct GNUNET_PeerIdentity *first, 416 const struct GNUNET_PeerIdentity *first,
436 const struct GNUNET_PeerIdentity *second, 417 const struct GNUNET_PeerIdentity *second,
437 uint32_t distance, 418 uint32_t distance,
438 const struct GNUNET_CONFIGURATION_Handle *first_cfg, 419 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
439 const struct GNUNET_CONFIGURATION_Handle *second_cfg, 420 const struct GNUNET_CONFIGURATION_Handle *second_cfg,
440 struct GNUNET_TESTING_Daemon *first_daemon, 421 struct GNUNET_TESTING_Daemon *first_daemon,
441 struct GNUNET_TESTING_Daemon *second_daemon, 422 struct GNUNET_TESTING_Daemon *second_daemon,
442 const char *emsg) 423 const char *emsg)
443{ 424{
444 struct ConnectContext *cc = cls; 425 struct ConnectContext *cc = cls;
445 426
446 if (emsg != NULL) 427 if (emsg != NULL)
447 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 428 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
448 "Failed to connect peers: %s\n", 429 "Failed to connect peers: %s\n", emsg);
449 emsg);
450 GNUNET_SCHEDULER_add_continuation (cc->cont, 430 GNUNET_SCHEDULER_add_continuation (cc->cont,
451 cc->cont_cls, 431 cc->cont_cls,
452 (emsg != NULL) 432 (emsg != NULL)
453 ? GNUNET_SCHEDULER_REASON_TIMEOUT 433 ? GNUNET_SCHEDULER_REASON_TIMEOUT
454 : GNUNET_SCHEDULER_REASON_PREREQ_DONE); 434 : GNUNET_SCHEDULER_REASON_PREREQ_DONE);
455 GNUNET_free (cc); 435 GNUNET_free (cc);
456} 436}
457 437
@@ -468,10 +448,9 @@ notify_connection (void *cls,
468 */ 448 */
469void 449void
470GNUNET_FS_TEST_daemons_connect (struct GNUNET_FS_TestDaemon *daemon1, 450GNUNET_FS_TEST_daemons_connect (struct GNUNET_FS_TestDaemon *daemon1,
471 struct GNUNET_FS_TestDaemon *daemon2, 451 struct GNUNET_FS_TestDaemon *daemon2,
472 struct GNUNET_TIME_Relative timeout, 452 struct GNUNET_TIME_Relative timeout,
473 GNUNET_SCHEDULER_Task cont, 453 GNUNET_SCHEDULER_Task cont, void *cont_cls)
474 void *cont_cls)
475{ 454{
476 struct ConnectContext *ncc; 455 struct ConnectContext *ncc;
477 456
@@ -479,12 +458,10 @@ GNUNET_FS_TEST_daemons_connect (struct GNUNET_FS_TestDaemon *daemon1,
479 ncc->cont = cont; 458 ncc->cont = cont;
480 ncc->cont_cls = cont_cls; 459 ncc->cont_cls = cont_cls;
481 GNUNET_TESTING_daemons_connect (daemon1->daemon, 460 GNUNET_TESTING_daemons_connect (daemon1->daemon,
482 daemon2->daemon, 461 daemon2->daemon,
483 timeout, 462 timeout,
484 CONNECT_ATTEMPTS, 463 CONNECT_ATTEMPTS,
485 GNUNET_YES, 464 GNUNET_YES, &notify_connection, ncc);
486 &notify_connection,
487 ncc);
488} 465}
489 466
490 467
@@ -497,9 +474,9 @@ GNUNET_FS_TEST_daemons_connect (struct GNUNET_FS_TestDaemon *daemon1,
497 */ 474 */
498const struct GNUNET_CONFIGURATION_Handle * 475const struct GNUNET_CONFIGURATION_Handle *
499GNUNET_FS_TEST_get_configuration (struct GNUNET_FS_TestDaemon **daemons, 476GNUNET_FS_TEST_get_configuration (struct GNUNET_FS_TestDaemon **daemons,
500 unsigned int off) 477 unsigned int off)
501{ 478{
502 return daemons[off]->cfg; 479 return daemons[off]->cfg;
503} 480}
504 481
505/** 482/**
@@ -511,7 +488,7 @@ GNUNET_FS_TEST_get_configuration (struct GNUNET_FS_TestDaemon **daemons,
511struct GNUNET_TESTING_PeerGroup * 488struct GNUNET_TESTING_PeerGroup *
512GNUNET_FS_TEST_get_group (struct GNUNET_FS_TestDaemon **daemons) 489GNUNET_FS_TEST_get_group (struct GNUNET_FS_TestDaemon **daemons)
513{ 490{
514 return daemons[0]->group; 491 return daemons[0]->group;
515} 492}
516 493
517 494
@@ -523,7 +500,7 @@ GNUNET_FS_TEST_get_group (struct GNUNET_FS_TestDaemon **daemons)
523 */ 500 */
524void 501void
525GNUNET_FS_TEST_daemons_stop (unsigned int total, 502GNUNET_FS_TEST_daemons_stop (unsigned int total,
526 struct GNUNET_FS_TestDaemon **daemons) 503 struct GNUNET_FS_TestDaemon **daemons)
527{ 504{
528 unsigned int i; 505 unsigned int i;
529 struct GNUNET_TESTING_PeerGroup *pg; 506 struct GNUNET_TESTING_PeerGroup *pg;
@@ -534,70 +511,64 @@ GNUNET_FS_TEST_daemons_stop (unsigned int total,
534 GNUNET_assert (daemons[0] != NULL); 511 GNUNET_assert (daemons[0] != NULL);
535 pg = daemons[0]->group; 512 pg = daemons[0]->group;
536 gcfg = daemons[0]->gcfg; 513 gcfg = daemons[0]->gcfg;
537 for (i=0;i<total;i++) 514 for (i = 0; i < total; i++)
515 {
516 daemon = daemons[i];
517 if (daemon->download_timeout_task != GNUNET_SCHEDULER_NO_TASK)
518 {
519 GNUNET_SCHEDULER_cancel (daemon->download_timeout_task);
520 daemon->download_timeout_task = GNUNET_SCHEDULER_NO_TASK;
521 }
522 if (daemon->publish_timeout_task != GNUNET_SCHEDULER_NO_TASK)
538 { 523 {
539 daemon = daemons[i]; 524 GNUNET_SCHEDULER_cancel (daemon->publish_timeout_task);
540 if (daemon->download_timeout_task != GNUNET_SCHEDULER_NO_TASK) 525 daemon->publish_timeout_task = GNUNET_SCHEDULER_NO_TASK;
541 { 526 }
542 GNUNET_SCHEDULER_cancel (daemon->download_timeout_task); 527 if (NULL != daemon->download_context)
543 daemon->download_timeout_task = GNUNET_SCHEDULER_NO_TASK; 528 {
544 } 529 GNUNET_FS_download_stop (daemon->download_context, GNUNET_YES);
545 if (daemon->publish_timeout_task != GNUNET_SCHEDULER_NO_TASK) 530 daemon->download_context = NULL;
546 { 531 }
547 GNUNET_SCHEDULER_cancel (daemon->publish_timeout_task); 532 if (daemon->fs != NULL)
548 daemon->publish_timeout_task = GNUNET_SCHEDULER_NO_TASK; 533 GNUNET_FS_stop (daemon->fs);
549 } 534 if (daemon->cfg != NULL)
550 if (NULL != daemon->download_context) 535 GNUNET_CONFIGURATION_destroy (daemon->cfg);
551 { 536 if (NULL != daemon->publish_tmp_file)
552 GNUNET_FS_download_stop (daemon->download_context, GNUNET_YES); 537 {
553 daemon->download_context = NULL; 538 GNUNET_break (GNUNET_OK ==
554 } 539 GNUNET_DISK_directory_remove (daemon->publish_tmp_file));
555 if (daemon->fs != NULL) 540 GNUNET_free (daemon->publish_tmp_file);
556 GNUNET_FS_stop (daemon->fs); 541 daemon->publish_tmp_file = NULL;
557 if (daemon->cfg != NULL) 542 }
558 GNUNET_CONFIGURATION_destroy (daemon->cfg); 543 GNUNET_free (daemon);
559 if (NULL != daemon->publish_tmp_file) 544 daemons[i] = NULL;
560 { 545 }
561 GNUNET_break (GNUNET_OK == 546 GNUNET_TESTING_daemons_stop (pg,
562 GNUNET_DISK_directory_remove (daemon->publish_tmp_file)); 547 GNUNET_TIME_relative_multiply
563 GNUNET_free (daemon->publish_tmp_file); 548 (GNUNET_TIME_UNIT_SECONDS, 30),
564 daemon->publish_tmp_file = NULL; 549 &shutdown_callback, gcfg);
565 }
566 GNUNET_free (daemon);
567 daemons[i] = NULL;
568 }
569 GNUNET_TESTING_daemons_stop (pg,
570 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30),
571 &shutdown_callback,
572 gcfg);
573} 550}
574 551
575 552
576static void 553static void
577publish_timeout (void *cls, 554publish_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
578 const struct GNUNET_SCHEDULER_TaskContext *tc)
579{ 555{
580 struct GNUNET_FS_TestDaemon *daemon = cls; 556 struct GNUNET_FS_TestDaemon *daemon = cls;
581 GNUNET_FS_TEST_UriContinuation cont; 557 GNUNET_FS_TEST_UriContinuation cont;
582 558
583 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 559 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
584 "Timeout while trying to publish data\n"); 560 "Timeout while trying to publish data\n");
585 cont = daemon->publish_cont; 561 cont = daemon->publish_cont;
586 daemon->publish_timeout_task = GNUNET_SCHEDULER_NO_TASK; 562 daemon->publish_timeout_task = GNUNET_SCHEDULER_NO_TASK;
587 daemon->publish_cont = NULL; 563 daemon->publish_cont = NULL;
588 GNUNET_FS_publish_stop (daemon->publish_context); 564 GNUNET_FS_publish_stop (daemon->publish_context);
589 daemon->publish_context = NULL; 565 daemon->publish_context = NULL;
590 cont (daemon->publish_cont_cls, 566 cont (daemon->publish_cont_cls, NULL);
591 NULL);
592} 567}
593 568
594 569
595static size_t 570static size_t
596file_generator (void *cls, 571file_generator (void *cls, uint64_t offset, size_t max, void *buf, char **emsg)
597 uint64_t offset,
598 size_t max,
599 void *buf,
600 char **emsg)
601{ 572{
602 struct GNUNET_FS_TestDaemon *daemon = cls; 573 struct GNUNET_FS_TestDaemon *daemon = cls;
603 uint64_t pos; 574 uint64_t pos;
@@ -608,15 +579,15 @@ file_generator (void *cls,
608 *emsg = NULL; 579 *emsg = NULL;
609 if (buf == NULL) 580 if (buf == NULL)
610 return 0; 581 return 0;
611 for (pos=0;pos<8;pos++) 582 for (pos = 0; pos < 8; pos++)
612 cbuf[pos] = (uint8_t) (offset >> pos*8); 583 cbuf[pos] = (uint8_t) (offset >> pos * 8);
613 for (pos=8;pos<max;pos++) 584 for (pos = 8; pos < max; pos++)
614 { 585 {
615 mod = (255 - (offset / 1024 / 32)); 586 mod = (255 - (offset / 1024 / 32));
616 if (mod == 0) 587 if (mod == 0)
617 mod = 1; 588 mod = 1;
618 cbuf[pos] = (uint8_t) ((offset * daemon->publish_seed) % mod); 589 cbuf[pos] = (uint8_t) ((offset * daemon->publish_seed) % mod);
619 } 590 }
620 return max; 591 return max;
621} 592}
622 593
@@ -639,14 +610,13 @@ file_generator (void *cls,
639 */ 610 */
640void 611void
641GNUNET_FS_TEST_publish (struct GNUNET_FS_TestDaemon *daemon, 612GNUNET_FS_TEST_publish (struct GNUNET_FS_TestDaemon *daemon,
642 struct GNUNET_TIME_Relative timeout, 613 struct GNUNET_TIME_Relative timeout,
643 uint32_t anonymity, 614 uint32_t anonymity,
644 int do_index, 615 int do_index,
645 uint64_t size, 616 uint64_t size,
646 uint32_t seed, 617 uint32_t seed,
647 unsigned int verbose, 618 unsigned int verbose,
648 GNUNET_FS_TEST_UriContinuation cont, 619 GNUNET_FS_TEST_UriContinuation cont, void *cont_cls)
649 void *cont_cls)
650{ 620{
651 struct GNUNET_FS_FileInformation *fi; 621 struct GNUNET_FS_FileInformation *fi;
652 struct GNUNET_DISK_FileHandle *fh; 622 struct GNUNET_DISK_FileHandle *fh;
@@ -655,7 +625,7 @@ GNUNET_FS_TEST_publish (struct GNUNET_FS_TestDaemon *daemon,
655 char buf[DBLOCK_SIZE]; 625 char buf[DBLOCK_SIZE];
656 size_t bsize; 626 size_t bsize;
657 struct GNUNET_FS_BlockOptions bo; 627 struct GNUNET_FS_BlockOptions bo;
658 628
659 GNUNET_assert (daemon->publish_cont == NULL); 629 GNUNET_assert (daemon->publish_cont == NULL);
660 daemon->publish_cont = cont; 630 daemon->publish_cont = cont;
661 daemon->publish_cont_cls = cont_cls; 631 daemon->publish_cont_cls = cont_cls;
@@ -666,78 +636,66 @@ GNUNET_FS_TEST_publish (struct GNUNET_FS_TestDaemon *daemon,
666 bo.content_priority = 42; 636 bo.content_priority = 42;
667 bo.replication_level = 1; 637 bo.replication_level = 1;
668 if (GNUNET_YES == do_index) 638 if (GNUNET_YES == do_index)
639 {
640 GNUNET_assert (daemon->publish_tmp_file == NULL);
641 daemon->publish_tmp_file = GNUNET_DISK_mktemp ("fs-test-publish-index");
642 GNUNET_assert (daemon->publish_tmp_file != NULL);
643 fh = GNUNET_DISK_file_open (daemon->publish_tmp_file,
644 GNUNET_DISK_OPEN_WRITE |
645 GNUNET_DISK_OPEN_CREATE,
646 GNUNET_DISK_PERM_USER_READ |
647 GNUNET_DISK_PERM_USER_WRITE);
648 GNUNET_assert (NULL != fh);
649 off = 0;
650 while (off < size)
669 { 651 {
670 GNUNET_assert (daemon->publish_tmp_file == NULL); 652 bsize = GNUNET_MIN (sizeof (buf), size - off);
671 daemon->publish_tmp_file = GNUNET_DISK_mktemp ("fs-test-publish-index"); 653 emsg = NULL;
672 GNUNET_assert (daemon->publish_tmp_file != NULL); 654 GNUNET_assert (bsize == file_generator (daemon, off, bsize, buf, &emsg));
673 fh = GNUNET_DISK_file_open (daemon->publish_tmp_file, 655 GNUNET_assert (emsg == NULL);
674 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE, 656 GNUNET_assert (bsize == GNUNET_DISK_file_write (fh, buf, bsize));
675 GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE); 657 off += bsize;
676 GNUNET_assert (NULL != fh);
677 off = 0;
678 while (off < size)
679 {
680 bsize = GNUNET_MIN (sizeof (buf),
681 size - off);
682 emsg = NULL;
683 GNUNET_assert (bsize ==
684 file_generator (daemon,
685 off,
686 bsize,
687 buf,
688 &emsg));
689 GNUNET_assert (emsg == NULL);
690 GNUNET_assert (bsize ==
691 GNUNET_DISK_file_write (fh,
692 buf,
693 bsize));
694 off += bsize;
695 }
696 GNUNET_assert (GNUNET_OK ==
697 GNUNET_DISK_file_close (fh));
698 fi = GNUNET_FS_file_information_create_from_file (daemon->fs,
699 daemon,
700 daemon->publish_tmp_file,
701 NULL, NULL,
702 do_index,
703 &bo);
704 } 658 }
659 GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fh));
660 fi = GNUNET_FS_file_information_create_from_file (daemon->fs,
661 daemon,
662 daemon->publish_tmp_file,
663 NULL, NULL,
664 do_index, &bo);
665 }
705 else 666 else
706 { 667 {
707 fi = GNUNET_FS_file_information_create_from_reader (daemon->fs, 668 fi = GNUNET_FS_file_information_create_from_reader (daemon->fs,
708 daemon, 669 daemon,
709 size, 670 size,
710 &file_generator, 671 &file_generator,
711 daemon, 672 daemon,
712 NULL, 673 NULL,
713 NULL, 674 NULL, do_index, &bo);
714 do_index, 675 }
715 &bo);
716 }
717 daemon->publish_context = GNUNET_FS_publish_start (daemon->fs, 676 daemon->publish_context = GNUNET_FS_publish_start (daemon->fs,
718 fi, 677 fi,
719 NULL, NULL, NULL, 678 NULL, NULL, NULL,
720 GNUNET_FS_PUBLISH_OPTION_NONE); 679 GNUNET_FS_PUBLISH_OPTION_NONE);
721 daemon->publish_timeout_task = GNUNET_SCHEDULER_add_delayed (timeout, 680 daemon->publish_timeout_task = GNUNET_SCHEDULER_add_delayed (timeout,
722 &publish_timeout, 681 &publish_timeout,
723 daemon); 682 daemon);
724} 683}
725 684
726 685
727static void 686static void
728download_timeout (void *cls, 687download_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
729 const struct GNUNET_SCHEDULER_TaskContext *tc)
730{ 688{
731 struct GNUNET_FS_TestDaemon *daemon = cls; 689 struct GNUNET_FS_TestDaemon *daemon = cls;
732 690
733 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 691 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
734 "Timeout while trying to download file\n"); 692 "Timeout while trying to download file\n");
735 daemon->download_timeout_task = GNUNET_SCHEDULER_NO_TASK; 693 daemon->download_timeout_task = GNUNET_SCHEDULER_NO_TASK;
736 GNUNET_FS_download_stop (daemon->download_context, GNUNET_YES); 694 GNUNET_FS_download_stop (daemon->download_context, GNUNET_YES);
737 daemon->download_context = NULL; 695 daemon->download_context = NULL;
738 GNUNET_SCHEDULER_add_continuation (daemon->download_cont, 696 GNUNET_SCHEDULER_add_continuation (daemon->download_cont,
739 daemon->download_cont_cls, 697 daemon->download_cont_cls,
740 GNUNET_SCHEDULER_REASON_TIMEOUT); 698 GNUNET_SCHEDULER_REASON_TIMEOUT);
741 daemon->download_cont = NULL; 699 daemon->download_cont = NULL;
742} 700}
743 701
@@ -757,35 +715,33 @@ download_timeout (void *cls,
757 */ 715 */
758void 716void
759GNUNET_FS_TEST_download (struct GNUNET_FS_TestDaemon *daemon, 717GNUNET_FS_TEST_download (struct GNUNET_FS_TestDaemon *daemon,
760 struct GNUNET_TIME_Relative timeout, 718 struct GNUNET_TIME_Relative timeout,
761 uint32_t anonymity, 719 uint32_t anonymity,
762 uint32_t seed, 720 uint32_t seed,
763 const struct GNUNET_FS_Uri *uri, 721 const struct GNUNET_FS_Uri *uri,
764 unsigned int verbose, 722 unsigned int verbose,
765 GNUNET_SCHEDULER_Task cont, 723 GNUNET_SCHEDULER_Task cont, void *cont_cls)
766 void *cont_cls)
767{ 724{
768 uint64_t size; 725 uint64_t size;
769 726
770 GNUNET_assert (daemon->download_cont == NULL); 727 GNUNET_assert (daemon->download_cont == NULL);
771 size = GNUNET_FS_uri_chk_get_file_size (uri); 728 size = GNUNET_FS_uri_chk_get_file_size (uri);
772 daemon->verbose = verbose; 729 daemon->verbose = verbose;
773 daemon->download_cont = cont; 730 daemon->download_cont = cont;
774 daemon->download_cont_cls = cont_cls; 731 daemon->download_cont_cls = cont_cls;
775 daemon->download_seed = seed; 732 daemon->download_seed = seed;
776 daemon->download_context = GNUNET_FS_download_start (daemon->fs, 733 daemon->download_context = GNUNET_FS_download_start (daemon->fs,
777 uri, 734 uri,
778 NULL, NULL, 735 NULL, NULL,
779 NULL, 736 NULL,
780 0, 737 0,
781 size, 738 size,
782 anonymity, 739 anonymity,
783 GNUNET_FS_DOWNLOAD_OPTION_NONE, 740 GNUNET_FS_DOWNLOAD_OPTION_NONE,
784 NULL, 741 NULL, NULL);
785 NULL);
786 daemon->download_timeout_task = GNUNET_SCHEDULER_add_delayed (timeout, 742 daemon->download_timeout_task = GNUNET_SCHEDULER_add_delayed (timeout,
787 &download_timeout, 743 &download_timeout,
788 daemon); 744 daemon);
789} 745}
790 746
791/* end of test_fs_lib.c */ 747/* end of test_fs_lib.c */
diff --git a/src/fs/fs_test_lib.h b/src/fs/fs_test_lib.h
index b348dfe78..2017b21ea 100644
--- a/src/fs/fs_test_lib.h
+++ b/src/fs/fs_test_lib.h
@@ -55,11 +55,10 @@ struct GNUNET_FS_TestDaemon;
55 */ 55 */
56void 56void
57GNUNET_FS_TEST_daemons_start (const char *template_cfg_file, 57GNUNET_FS_TEST_daemons_start (const char *template_cfg_file,
58 struct GNUNET_TIME_Relative timeout, 58 struct GNUNET_TIME_Relative timeout,
59 unsigned int total, 59 unsigned int total,
60 struct GNUNET_FS_TestDaemon **daemons, 60 struct GNUNET_FS_TestDaemon **daemons,
61 GNUNET_SCHEDULER_Task cont, 61 GNUNET_SCHEDULER_Task cont, void *cont_cls);
62 void *cont_cls);
63 62
64 63
65/** 64/**
@@ -74,10 +73,9 @@ GNUNET_FS_TEST_daemons_start (const char *template_cfg_file,
74 */ 73 */
75void 74void
76GNUNET_FS_TEST_daemons_connect (struct GNUNET_FS_TestDaemon *daemon1, 75GNUNET_FS_TEST_daemons_connect (struct GNUNET_FS_TestDaemon *daemon1,
77 struct GNUNET_FS_TestDaemon *daemon2, 76 struct GNUNET_FS_TestDaemon *daemon2,
78 struct GNUNET_TIME_Relative timeout, 77 struct GNUNET_TIME_Relative timeout,
79 GNUNET_SCHEDULER_Task cont, 78 GNUNET_SCHEDULER_Task cont, void *cont_cls);
80 void *cont_cls);
81 79
82 80
83/** 81/**
@@ -86,8 +84,9 @@ GNUNET_FS_TEST_daemons_connect (struct GNUNET_FS_TestDaemon *daemon1,
86 * @param daemons array with the daemons (must contain at least one) 84 * @param daemons array with the daemons (must contain at least one)
87 * @return peer group 85 * @return peer group
88 */ 86 */
89struct GNUNET_TESTING_PeerGroup * 87struct GNUNET_TESTING_PeerGroup *GNUNET_FS_TEST_get_group (struct
90GNUNET_FS_TEST_get_group (struct GNUNET_FS_TestDaemon **daemons); 88 GNUNET_FS_TestDaemon
89 **daemons);
91 90
92 91
93 92
@@ -98,9 +97,9 @@ GNUNET_FS_TEST_get_group (struct GNUNET_FS_TestDaemon **daemons);
98 * @param off which configuration to get 97 * @param off which configuration to get
99 * @return peer configuration 98 * @return peer configuration
100 */ 99 */
101const struct GNUNET_CONFIGURATION_Handle * 100const struct GNUNET_CONFIGURATION_Handle
102GNUNET_FS_TEST_get_configuration (struct GNUNET_FS_TestDaemon **daemons, 101 *GNUNET_FS_TEST_get_configuration (struct GNUNET_FS_TestDaemon **daemons,
103 unsigned int off); 102 unsigned int off);
104 103
105/** 104/**
106 * Stop daemons used for testing. 105 * Stop daemons used for testing.
@@ -110,7 +109,7 @@ GNUNET_FS_TEST_get_configuration (struct GNUNET_FS_TestDaemon **daemons,
110 */ 109 */
111void 110void
112GNUNET_FS_TEST_daemons_stop (unsigned int total, 111GNUNET_FS_TEST_daemons_stop (unsigned int total,
113 struct GNUNET_FS_TestDaemon **daemons); 112 struct GNUNET_FS_TestDaemon **daemons);
114 113
115 114
116/** 115/**
@@ -119,9 +118,9 @@ GNUNET_FS_TEST_daemons_stop (unsigned int total,
119 * @param cls closure (user defined) 118 * @param cls closure (user defined)
120 * @param uri a URI, NULL for errors 119 * @param uri a URI, NULL for errors
121 */ 120 */
122typedef void 121typedef void
123(*GNUNET_FS_TEST_UriContinuation)(void *cls, 122 (*GNUNET_FS_TEST_UriContinuation) (void *cls,
124 const struct GNUNET_FS_Uri *uri); 123 const struct GNUNET_FS_Uri * uri);
125 124
126 125
127/** 126/**
@@ -141,14 +140,13 @@ typedef void
141 */ 140 */
142void 141void
143GNUNET_FS_TEST_publish (struct GNUNET_FS_TestDaemon *daemon, 142GNUNET_FS_TEST_publish (struct GNUNET_FS_TestDaemon *daemon,
144 struct GNUNET_TIME_Relative timeout, 143 struct GNUNET_TIME_Relative timeout,
145 uint32_t anonymity, 144 uint32_t anonymity,
146 int do_index, 145 int do_index,
147 uint64_t size, 146 uint64_t size,
148 uint32_t seed, 147 uint32_t seed,
149 unsigned int verbose, 148 unsigned int verbose,
150 GNUNET_FS_TEST_UriContinuation cont, 149 GNUNET_FS_TEST_UriContinuation cont, void *cont_cls);
151 void *cont_cls);
152 150
153 151
154/** 152/**
@@ -166,13 +164,12 @@ GNUNET_FS_TEST_publish (struct GNUNET_FS_TestDaemon *daemon,
166 */ 164 */
167void 165void
168GNUNET_FS_TEST_download (struct GNUNET_FS_TestDaemon *daemon, 166GNUNET_FS_TEST_download (struct GNUNET_FS_TestDaemon *daemon,
169 struct GNUNET_TIME_Relative timeout, 167 struct GNUNET_TIME_Relative timeout,
170 uint32_t anonymity, 168 uint32_t anonymity,
171 uint32_t seed, 169 uint32_t seed,
172 const struct GNUNET_FS_Uri *uri, 170 const struct GNUNET_FS_Uri *uri,
173 unsigned int verbose, 171 unsigned int verbose,
174 GNUNET_SCHEDULER_Task cont, 172 GNUNET_SCHEDULER_Task cont, void *cont_cls);
175 void *cont_cls);
176 173
177 174
178 175
diff --git a/src/fs/fs_tree.c b/src/fs/fs_tree.c
index e22ce8221..5584ad868 100644
--- a/src/fs/fs_tree.c
+++ b/src/fs/fs_tree.c
@@ -40,7 +40,7 @@ struct GNUNET_FS_TreeEncoder
40 * Global FS context. 40 * Global FS context.
41 */ 41 */
42 struct GNUNET_FS_Handle *h; 42 struct GNUNET_FS_Handle *h;
43 43
44 /** 44 /**
45 * Closure for all callbacks. 45 * Closure for all callbacks.
46 */ 46 */
@@ -65,7 +65,7 @@ struct GNUNET_FS_TreeEncoder
65 * Function to call once we're done with processing. 65 * Function to call once we're done with processing.
66 */ 66 */
67 GNUNET_SCHEDULER_Task cont; 67 GNUNET_SCHEDULER_Task cont;
68 68
69 /** 69 /**
70 * Set to an error message (if we had an error). 70 * Set to an error message (if we had an error).
71 */ 71 */
@@ -132,15 +132,15 @@ GNUNET_FS_compute_depth (uint64_t flen)
132 treeDepth = 1; 132 treeDepth = 1;
133 fl = DBLOCK_SIZE; 133 fl = DBLOCK_SIZE;
134 while (fl < flen) 134 while (fl < flen)
135 {
136 treeDepth++;
137 if (fl * CHK_PER_INODE < fl)
135 { 138 {
136 treeDepth++; 139 /* integer overflow, this is a HUGE file... */
137 if (fl * CHK_PER_INODE < fl) 140 return treeDepth;
138 {
139 /* integer overflow, this is a HUGE file... */
140 return treeDepth;
141 }
142 fl = fl * CHK_PER_INODE;
143 } 141 }
142 fl = fl * CHK_PER_INODE;
143 }
144 return treeDepth; 144 return treeDepth;
145} 145}
146 146
@@ -161,7 +161,7 @@ GNUNET_FS_tree_compute_tree_size (unsigned int depth)
161 unsigned int i; 161 unsigned int i;
162 162
163 rsize = DBLOCK_SIZE; 163 rsize = DBLOCK_SIZE;
164 for (i = 0; i<depth; i++) 164 for (i = 0; i < depth; i++)
165 rsize *= CHK_PER_INODE; 165 rsize *= CHK_PER_INODE;
166 return rsize; 166 return rsize;
167} 167}
@@ -181,9 +181,8 @@ GNUNET_FS_tree_compute_tree_size (unsigned int depth)
181 * end of a block). 181 * end of a block).
182 * @return size of the corresponding IBlock 182 * @return size of the corresponding IBlock
183 */ 183 */
184static uint16_t 184static uint16_t
185GNUNET_FS_tree_compute_iblock_size (unsigned int depth, 185GNUNET_FS_tree_compute_iblock_size (unsigned int depth, uint64_t end_offset)
186 uint64_t end_offset)
187{ 186{
188 unsigned int ret; 187 unsigned int ret;
189 uint64_t mod; 188 uint64_t mod;
@@ -194,19 +193,19 @@ GNUNET_FS_tree_compute_iblock_size (unsigned int depth,
194 bds = GNUNET_FS_tree_compute_tree_size (depth); 193 bds = GNUNET_FS_tree_compute_tree_size (depth);
195 mod = end_offset % bds; 194 mod = end_offset % bds;
196 if (0 == mod) 195 if (0 == mod)
197 { 196 {
198 /* we were triggered at the end of a full block */ 197 /* we were triggered at the end of a full block */
199 ret = CHK_PER_INODE; 198 ret = CHK_PER_INODE;
200 } 199 }
201 else 200 else
202 { 201 {
203 /* we were triggered at the end of the file */ 202 /* we were triggered at the end of the file */
204 bds /= CHK_PER_INODE; 203 bds /= CHK_PER_INODE;
205 ret = mod / bds; 204 ret = mod / bds;
206 if (0 != mod % bds) 205 if (0 != mod % bds)
207 ret++; 206 ret++;
208 } 207 }
209 return (uint16_t) (ret * sizeof(struct ContentHashKey)); 208 return (uint16_t) (ret * sizeof (struct ContentHashKey));
210} 209}
211 210
212 211
@@ -223,8 +222,7 @@ GNUNET_FS_tree_compute_iblock_size (unsigned int depth,
223 */ 222 */
224size_t 223size_t
225GNUNET_FS_tree_calculate_block_size (uint64_t fsize, 224GNUNET_FS_tree_calculate_block_size (uint64_t fsize,
226 uint64_t offset, 225 uint64_t offset, unsigned int depth)
227 unsigned int depth)
228{ 226{
229 size_t ret; 227 size_t ret;
230 uint64_t rsize; 228 uint64_t rsize;
@@ -234,18 +232,16 @@ GNUNET_FS_tree_calculate_block_size (uint64_t fsize,
234 GNUNET_assert (fsize > 0); 232 GNUNET_assert (fsize > 0);
235 GNUNET_assert (offset <= fsize); 233 GNUNET_assert (offset <= fsize);
236 if (depth == 0) 234 if (depth == 0)
237 { 235 {
238 ret = DBLOCK_SIZE; 236 ret = DBLOCK_SIZE;
239 if ( (offset + ret > fsize) || 237 if ((offset + ret > fsize) || (offset + ret < offset))
240 (offset + ret < offset) ) 238 ret = (size_t) (fsize - offset);
241 ret = (size_t) (fsize - offset); 239 return ret;
242 return ret; 240 }
243 }
244 241
245 rsize = GNUNET_FS_tree_compute_tree_size (depth - 1); 242 rsize = GNUNET_FS_tree_compute_tree_size (depth - 1);
246 epos = offset + rsize * CHK_PER_INODE; 243 epos = offset + rsize * CHK_PER_INODE;
247 if ( (epos < offset) || 244 if ((epos < offset) || (epos > fsize))
248 (epos > fsize) )
249 epos = fsize; 245 epos = fsize;
250 /* round up when computing #CHKs in our IBlock */ 246 /* round up when computing #CHKs in our IBlock */
251 chks = (epos - offset + rsize - 1) / rsize; 247 chks = (epos - offset + rsize - 1) / rsize;
@@ -273,16 +269,16 @@ GNUNET_FS_tree_calculate_block_size (uint64_t fsize,
273 */ 269 */
274struct GNUNET_FS_TreeEncoder * 270struct GNUNET_FS_TreeEncoder *
275GNUNET_FS_tree_encoder_create (struct GNUNET_FS_Handle *h, 271GNUNET_FS_tree_encoder_create (struct GNUNET_FS_Handle *h,
276 uint64_t size, 272 uint64_t size,
277 void *cls, 273 void *cls,
278 GNUNET_FS_DataReader reader, 274 GNUNET_FS_DataReader reader,
279 GNUNET_FS_TreeBlockProcessor proc, 275 GNUNET_FS_TreeBlockProcessor proc,
280 GNUNET_FS_TreeProgressCallback progress, 276 GNUNET_FS_TreeProgressCallback progress,
281 GNUNET_SCHEDULER_Task cont) 277 GNUNET_SCHEDULER_Task cont)
282{ 278{
283 struct GNUNET_FS_TreeEncoder *te; 279 struct GNUNET_FS_TreeEncoder *te;
284 280
285 te = GNUNET_malloc (sizeof (struct GNUNET_FS_TreeEncoder)); 281 te = GNUNET_malloc (sizeof (struct GNUNET_FS_TreeEncoder));
286 te->h = h; 282 te->h = h;
287 te->size = size; 283 te->size = size;
288 te->cls = cls; 284 te->cls = cls;
@@ -292,8 +288,7 @@ GNUNET_FS_tree_encoder_create (struct GNUNET_FS_Handle *h,
292 te->cont = cont; 288 te->cont = cont;
293 te->chk_tree_depth = GNUNET_FS_compute_depth (size); 289 te->chk_tree_depth = GNUNET_FS_compute_depth (size);
294 te->chk_tree = GNUNET_malloc (te->chk_tree_depth * 290 te->chk_tree = GNUNET_malloc (te->chk_tree_depth *
295 CHK_PER_INODE * 291 CHK_PER_INODE * sizeof (struct ContentHashKey));
296 sizeof (struct ContentHashKey));
297 return te; 292 return te;
298} 293}
299 294
@@ -310,17 +305,16 @@ GNUNET_FS_tree_encoder_create (struct GNUNET_FS_Handle *h,
310 * @return (array of CHKs') offset in the above IBlock 305 * @return (array of CHKs') offset in the above IBlock
311 */ 306 */
312static unsigned int 307static unsigned int
313compute_chk_offset (unsigned int depth, 308compute_chk_offset (unsigned int depth, uint64_t end_offset)
314 uint64_t end_offset)
315{ 309{
316 uint64_t bds; 310 uint64_t bds;
317 unsigned int ret; 311 unsigned int ret;
318 312
319 bds = GNUNET_FS_tree_compute_tree_size (depth); 313 bds = GNUNET_FS_tree_compute_tree_size (depth);
320 if (depth > 0) 314 if (depth > 0)
321 end_offset--; /* round down since for depth > 0 offset is at the END of the block */ 315 end_offset--; /* round down since for depth > 0 offset is at the END of the block */
322 ret = end_offset / bds; 316 ret = end_offset / bds;
323 return ret % CHK_PER_INODE; 317 return ret % CHK_PER_INODE;
324} 318}
325 319
326 320
@@ -331,8 +325,8 @@ compute_chk_offset (unsigned int depth,
331 * 325 *
332 * @param te tree encoder to use 326 * @param te tree encoder to use
333 */ 327 */
334void 328void
335GNUNET_FS_tree_encoder_next (struct GNUNET_FS_TreeEncoder * te) 329GNUNET_FS_tree_encoder_next (struct GNUNET_FS_TreeEncoder *te)
336{ 330{
337 struct ContentHashKey *mychk; 331 struct ContentHashKey *mychk;
338 const void *pt_block; 332 const void *pt_block;
@@ -346,105 +340,85 @@ GNUNET_FS_tree_encoder_next (struct GNUNET_FS_TreeEncoder * te)
346 GNUNET_assert (GNUNET_NO == te->in_next); 340 GNUNET_assert (GNUNET_NO == te->in_next);
347 te->in_next = GNUNET_YES; 341 te->in_next = GNUNET_YES;
348 if (te->chk_tree_depth == te->current_depth) 342 if (te->chk_tree_depth == te->current_depth)
349 { 343 {
350 off = CHK_PER_INODE * (te->chk_tree_depth - 1); 344 off = CHK_PER_INODE * (te->chk_tree_depth - 1);
351#if DEBUG_TREE 345#if DEBUG_TREE
352 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 346 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
353 "TE done, reading CHK `%s' from %u\n", 347 "TE done, reading CHK `%s' from %u\n",
354 GNUNET_h2s (&te->chk_tree[off].query), 348 GNUNET_h2s (&te->chk_tree[off].query), off);
355 off);
356#endif 349#endif
357 te->uri = GNUNET_malloc (sizeof(struct GNUNET_FS_Uri)); 350 te->uri = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri));
358 te->uri->type = chk; 351 te->uri->type = chk;
359 te->uri->data.chk.chk = te->chk_tree[off]; 352 te->uri->data.chk.chk = te->chk_tree[off];
360 te->uri->data.chk.file_length = GNUNET_htonll (te->size); 353 te->uri->data.chk.file_length = GNUNET_htonll (te->size);
361 te->in_next = GNUNET_NO; 354 te->in_next = GNUNET_NO;
362 te->cont (te->cls, NULL); 355 te->cont (te->cls, NULL);
363 return; 356 return;
364 } 357 }
365 if (0 == te->current_depth) 358 if (0 == te->current_depth)
359 {
360 /* read DBLOCK */
361 pt_size = GNUNET_MIN (DBLOCK_SIZE, te->size - te->publish_offset);
362 if (pt_size !=
363 te->reader (te->cls, te->publish_offset, pt_size, iob, &te->emsg))
366 { 364 {
367 /* read DBLOCK */ 365 GNUNET_SCHEDULER_add_continuation (te->cont,
368 pt_size = GNUNET_MIN(DBLOCK_SIZE, 366 te->cls,
369 te->size - te->publish_offset); 367 GNUNET_SCHEDULER_REASON_TIMEOUT);
370 if (pt_size != 368 te->in_next = GNUNET_NO;
371 te->reader (te->cls, 369 return;
372 te->publish_offset,
373 pt_size,
374 iob,
375 &te->emsg))
376 {
377 GNUNET_SCHEDULER_add_continuation (te->cont,
378 te->cls,
379 GNUNET_SCHEDULER_REASON_TIMEOUT);
380 te->in_next = GNUNET_NO;
381 return;
382 }
383 pt_block = iob;
384 } 370 }
371 pt_block = iob;
372 }
385 else 373 else
386 { 374 {
387 pt_size = GNUNET_FS_tree_compute_iblock_size (te->current_depth, 375 pt_size = GNUNET_FS_tree_compute_iblock_size (te->current_depth,
388 te->publish_offset); 376 te->publish_offset);
389 pt_block = &te->chk_tree[(te->current_depth - 1) * 377 pt_block = &te->chk_tree[(te->current_depth - 1) * CHK_PER_INODE];
390 CHK_PER_INODE]; 378 }
391 } 379 off = compute_chk_offset (te->current_depth, te->publish_offset);
392 off = compute_chk_offset (te->current_depth,
393 te->publish_offset);
394#if DEBUG_TREE 380#if DEBUG_TREE
395 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 381 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
396 "TE is at offset %llu and depth %u with block size %u and target-CHK-offset %u\n", 382 "TE is at offset %llu and depth %u with block size %u and target-CHK-offset %u\n",
397 (unsigned long long) te->publish_offset, 383 (unsigned long long) te->publish_offset,
398 te->current_depth, 384 te->current_depth, (unsigned int) pt_size, (unsigned int) off);
399 (unsigned int) pt_size,
400 (unsigned int) off);
401#endif 385#endif
402 mychk = &te->chk_tree[te->current_depth*CHK_PER_INODE+off]; 386 mychk = &te->chk_tree[te->current_depth * CHK_PER_INODE + off];
403 GNUNET_CRYPTO_hash (pt_block, pt_size, &mychk->key); 387 GNUNET_CRYPTO_hash (pt_block, pt_size, &mychk->key);
404 GNUNET_CRYPTO_hash_to_aes_key (&mychk->key, &sk, &iv); 388 GNUNET_CRYPTO_hash_to_aes_key (&mychk->key, &sk, &iv);
405 GNUNET_CRYPTO_aes_encrypt (pt_block, 389 GNUNET_CRYPTO_aes_encrypt (pt_block, pt_size, &sk, &iv, enc);
406 pt_size,
407 &sk,
408 &iv,
409 enc);
410 GNUNET_CRYPTO_hash (enc, pt_size, &mychk->query); 390 GNUNET_CRYPTO_hash (enc, pt_size, &mychk->query);
411#if DEBUG_TREE 391#if DEBUG_TREE
412 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 392 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
413 "TE calculates query to be `%s', stored at %u\n", 393 "TE calculates query to be `%s', stored at %u\n",
414 GNUNET_h2s (&mychk->query), 394 GNUNET_h2s (&mychk->query),
415 te->current_depth * CHK_PER_INODE + off); 395 te->current_depth * CHK_PER_INODE + off);
416#endif 396#endif
417 if (NULL != te->proc) 397 if (NULL != te->proc)
418 te->proc (te->cls, 398 te->proc (te->cls,
419 mychk, 399 mychk,
420 te->publish_offset, 400 te->publish_offset,
421 te->current_depth, 401 te->current_depth,
422 (0 == te->current_depth) 402 (0 == te->current_depth)
423 ? GNUNET_BLOCK_TYPE_FS_DBLOCK 403 ? GNUNET_BLOCK_TYPE_FS_DBLOCK
424 : GNUNET_BLOCK_TYPE_FS_IBLOCK, 404 : GNUNET_BLOCK_TYPE_FS_IBLOCK, enc, pt_size);
425 enc,
426 pt_size);
427 if (NULL != te->progress) 405 if (NULL != te->progress)
428 te->progress (te->cls, 406 te->progress (te->cls,
429 te->publish_offset, 407 te->publish_offset, pt_block, pt_size, te->current_depth);
430 pt_block, 408 if (0 == te->current_depth)
431 pt_size, 409 {
432 te->current_depth); 410 te->publish_offset += pt_size;
433 if (0 == te->current_depth) 411 if ((te->publish_offset == te->size) ||
434 { 412 (0 == te->publish_offset % (CHK_PER_INODE * DBLOCK_SIZE)))
435 te->publish_offset += pt_size; 413 te->current_depth++;
436 if ( (te->publish_offset == te->size) || 414 }
437 (0 == te->publish_offset % (CHK_PER_INODE * DBLOCK_SIZE) ) )
438 te->current_depth++;
439 }
440 else 415 else
441 { 416 {
442 if ( (off == CHK_PER_INODE) || 417 if ((off == CHK_PER_INODE) || (te->publish_offset == te->size))
443 (te->publish_offset == te->size) ) 418 te->current_depth++;
444 te->current_depth++; 419 else
445 else 420 te->current_depth = 0;
446 te->current_depth = 0; 421 }
447 }
448 te->in_next = GNUNET_NO; 422 te->in_next = GNUNET_NO;
449} 423}
450 424
@@ -460,16 +434,15 @@ GNUNET_FS_tree_encoder_next (struct GNUNET_FS_TreeEncoder * te)
460 * prior to completion and prior to an internal error, 434 * prior to completion and prior to an internal error,
461 * both "*uri" and "*emsg" will be set to NULL). 435 * both "*uri" and "*emsg" will be set to NULL).
462 */ 436 */
463void GNUNET_FS_tree_encoder_finish (struct GNUNET_FS_TreeEncoder *te, 437void
464 struct GNUNET_FS_Uri **uri, 438GNUNET_FS_tree_encoder_finish (struct GNUNET_FS_TreeEncoder *te,
465 char **emsg) 439 struct GNUNET_FS_Uri **uri, char **emsg)
466{ 440{
467 GNUNET_assert (GNUNET_NO == te->in_next); 441 GNUNET_assert (GNUNET_NO == te->in_next);
468 if (uri != NULL) 442 if (uri != NULL)
469 *uri = te->uri; 443 *uri = te->uri;
470 else 444 else if (NULL != te->uri)
471 if (NULL != te->uri) 445 GNUNET_FS_uri_destroy (te->uri);
472 GNUNET_FS_uri_destroy (te->uri);
473 if (emsg != NULL) 446 if (emsg != NULL)
474 *emsg = te->emsg; 447 *emsg = te->emsg;
475 else 448 else
diff --git a/src/fs/fs_tree.h b/src/fs/fs_tree.h
index 5cd4d0afe..c2b7de48c 100644
--- a/src/fs/fs_tree.h
+++ b/src/fs/fs_tree.h
@@ -40,8 +40,7 @@
40 * @param flen file length for which to compute the depth 40 * @param flen file length for which to compute the depth
41 * @return depth of the tree, always > 0. A depth of 1 means only a DBLOCK. 41 * @return depth of the tree, always > 0. A depth of 1 means only a DBLOCK.
42 */ 42 */
43unsigned int 43unsigned int GNUNET_FS_compute_depth (uint64_t flen);
44GNUNET_FS_compute_depth (uint64_t flen);
45 44
46 45
47/** 46/**
@@ -53,8 +52,7 @@ GNUNET_FS_compute_depth (uint64_t flen);
53 * @param depth depth of the block. depth==0 is a DBLOCK. 52 * @param depth depth of the block. depth==0 is a DBLOCK.
54 * @return number of bytes of payload a subtree of this depth may correspond to 53 * @return number of bytes of payload a subtree of this depth may correspond to
55 */ 54 */
56uint64_t 55uint64_t GNUNET_FS_tree_compute_tree_size (unsigned int depth);
57GNUNET_FS_tree_compute_tree_size (unsigned int depth);
58 56
59 57
60/** 58/**
@@ -70,8 +68,7 @@ GNUNET_FS_tree_compute_tree_size (unsigned int depth);
70 */ 68 */
71size_t 69size_t
72GNUNET_FS_tree_calculate_block_size (uint64_t fsize, 70GNUNET_FS_tree_calculate_block_size (uint64_t fsize,
73 uint64_t offset, 71 uint64_t offset, unsigned int depth);
74 unsigned int depth);
75 72
76 73
77/** 74/**
@@ -95,14 +92,14 @@ struct GNUNET_FS_TreeEncoder;
95 * @param block the (encrypted) block 92 * @param block the (encrypted) block
96 * @param block_size size of block (in bytes) 93 * @param block_size size of block (in bytes)
97 */ 94 */
98typedef void (*GNUNET_FS_TreeBlockProcessor)(void *cls, 95typedef void (*GNUNET_FS_TreeBlockProcessor) (void *cls,
99 const struct ContentHashKey *chk, 96 const struct ContentHashKey * chk,
100 uint64_t offset, 97 uint64_t offset,
101 unsigned int depth, 98 unsigned int depth,
102 enum GNUNET_BLOCK_Type type, 99 enum GNUNET_BLOCK_Type type,
103 const void *block, 100 const void *block,
104 uint16_t block_size); 101 uint16_t block_size);
105 102
106 103
107/** 104/**
108 * Function called with information about our 105 * Function called with information about our
@@ -114,12 +111,12 @@ typedef void (*GNUNET_FS_TreeBlockProcessor)(void *cls,
114 * @param pt_size size of pt_block 111 * @param pt_size size of pt_block
115 * @param depth depth of the block in the tree, 0 for DBLOCKS 112 * @param depth depth of the block in the tree, 0 for DBLOCKS
116 */ 113 */
117typedef void (*GNUNET_FS_TreeProgressCallback)(void *cls, 114typedef void (*GNUNET_FS_TreeProgressCallback) (void *cls,
118 uint64_t offset, 115 uint64_t offset,
119 const void *pt_block, 116 const void *pt_block,
120 size_t pt_size, 117 size_t pt_size,
121 unsigned int depth); 118 unsigned int depth);
122 119
123 120
124/** 121/**
125 * Initialize a tree encoder. This function will call "proc" and 122 * Initialize a tree encoder. This function will call "proc" and
@@ -139,14 +136,18 @@ typedef void (*GNUNET_FS_TreeProgressCallback)(void *cls,
139 * @param cont function to call when done 136 * @param cont function to call when done
140 * @return tree encoder context 137 * @return tree encoder context
141 */ 138 */
142struct GNUNET_FS_TreeEncoder * 139struct GNUNET_FS_TreeEncoder *GNUNET_FS_tree_encoder_create (struct
143GNUNET_FS_tree_encoder_create (struct GNUNET_FS_Handle *h, 140 GNUNET_FS_Handle
144 uint64_t size, 141 *h, uint64_t size,
145 void *cls, 142 void *cls,
146 GNUNET_FS_DataReader reader, 143 GNUNET_FS_DataReader
147 GNUNET_FS_TreeBlockProcessor proc, 144 reader,
148 GNUNET_FS_TreeProgressCallback progress, 145 GNUNET_FS_TreeBlockProcessor
149 GNUNET_SCHEDULER_Task cont); 146 proc,
147 GNUNET_FS_TreeProgressCallback
148 progress,
149 GNUNET_SCHEDULER_Task
150 cont);
150 151
151 152
152/** 153/**
@@ -157,7 +158,7 @@ GNUNET_FS_tree_encoder_create (struct GNUNET_FS_Handle *h,
157 * 158 *
158 * @param te tree encoder to use 159 * @param te tree encoder to use
159 */ 160 */
160void GNUNET_FS_tree_encoder_next (struct GNUNET_FS_TreeEncoder * te); 161void GNUNET_FS_tree_encoder_next (struct GNUNET_FS_TreeEncoder *te);
161 162
162 163
163/** 164/**
@@ -172,8 +173,7 @@ void GNUNET_FS_tree_encoder_next (struct GNUNET_FS_TreeEncoder * te);
172 * both "*uri" and "*emsg" will be set to NULL). 173 * both "*uri" and "*emsg" will be set to NULL).
173 */ 174 */
174void GNUNET_FS_tree_encoder_finish (struct GNUNET_FS_TreeEncoder *te, 175void GNUNET_FS_tree_encoder_finish (struct GNUNET_FS_TreeEncoder *te,
175 struct GNUNET_FS_Uri **uri, 176 struct GNUNET_FS_Uri **uri, char **emsg);
176 char **emsg);
177 177
178 178
179#if 0 179#if 0
@@ -187,9 +187,8 @@ void GNUNET_FS_tree_encoder_finish (struct GNUNET_FS_TreeEncoder *te,
187 * @param data set to the resume data 187 * @param data set to the resume data
188 * @param size set to the size of the resume data 188 * @param size set to the size of the resume data
189 */ 189 */
190void GNUNET_FS_tree_encoder_resume_get_data (const struct GNUNET_FS_TreeEncoder *te, 190void GNUNET_FS_tree_encoder_resume_get_data (const struct GNUNET_FS_TreeEncoder
191 void **data, 191 *te, void **data, size_t * size);
192 size_t *size);
193 192
194 193
195/** 194/**
@@ -201,8 +200,7 @@ void GNUNET_FS_tree_encoder_resume_get_data (const struct GNUNET_FS_TreeEncoder
201 * @param size the size of the resume data 200 * @param size the size of the resume data
202 */ 201 */
203void GNUNET_FS_tree_encoder_resume (struct GNUNET_FS_TreeEncoder *te, 202void GNUNET_FS_tree_encoder_resume (struct GNUNET_FS_TreeEncoder *te,
204 const void *data, 203 const void *data, size_t size);
205 size_t size);
206#endif 204#endif
207 205
208#endif 206#endif
diff --git a/src/fs/fs_unindex.c b/src/fs/fs_unindex.c
index 83db96932..130b2eae2 100644
--- a/src/fs/fs_unindex.c
+++ b/src/fs/fs_unindex.c
@@ -47,31 +47,22 @@
47 * @return number of bytes copied to buf, 0 on error 47 * @return number of bytes copied to buf, 0 on error
48 */ 48 */
49static size_t 49static size_t
50unindex_reader (void *cls, 50unindex_reader (void *cls, uint64_t offset, size_t max, void *buf, char **emsg)
51 uint64_t offset,
52 size_t max,
53 void *buf,
54 char **emsg)
55{ 51{
56 struct GNUNET_FS_UnindexContext *uc = cls; 52 struct GNUNET_FS_UnindexContext *uc = cls;
57 size_t pt_size; 53 size_t pt_size;
58 54
59 pt_size = GNUNET_MIN(max, 55 pt_size = GNUNET_MIN (max, uc->file_size - offset);
60 uc->file_size - offset); 56 if (offset != GNUNET_DISK_file_seek (uc->fh, offset, GNUNET_DISK_SEEK_SET))
61 if (offset != 57 {
62 GNUNET_DISK_file_seek (uc->fh, offset, GNUNET_DISK_SEEK_SET)) 58 *emsg = GNUNET_strdup (_("Failed to find given position in file"));
63 { 59 return 0;
64 *emsg = GNUNET_strdup (_("Failed to find given position in file")); 60 }
65 return 0; 61 if (pt_size != GNUNET_DISK_file_read (uc->fh, buf, pt_size))
66 } 62 {
67 if (pt_size != 63 *emsg = GNUNET_strdup (_("Failed to read file"));
68 GNUNET_DISK_file_read (uc->fh, 64 return 0;
69 buf, 65 }
70 pt_size))
71 {
72 *emsg = GNUNET_strdup (_("Failed to read file"));
73 return 0;
74 }
75 return pt_size; 66 return pt_size;
76} 67}
77 68
@@ -86,22 +77,19 @@ unindex_reader (void *cls,
86 */ 77 */
87void 78void
88GNUNET_FS_unindex_make_status_ (struct GNUNET_FS_ProgressInfo *pi, 79GNUNET_FS_unindex_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
89 struct GNUNET_FS_UnindexContext *uc, 80 struct GNUNET_FS_UnindexContext *uc,
90 uint64_t offset) 81 uint64_t offset)
91{ 82{
92 pi->value.unindex.uc = uc; 83 pi->value.unindex.uc = uc;
93 pi->value.unindex.cctx = uc->client_info; 84 pi->value.unindex.cctx = uc->client_info;
94 pi->value.unindex.filename = uc->filename; 85 pi->value.unindex.filename = uc->filename;
95 pi->value.unindex.size = uc->file_size; 86 pi->value.unindex.size = uc->file_size;
96 pi->value.unindex.eta 87 pi->value.unindex.eta
97 = GNUNET_TIME_calculate_eta (uc->start_time, 88 = GNUNET_TIME_calculate_eta (uc->start_time, offset, uc->file_size);
98 offset, 89 pi->value.unindex.duration =
99 uc->file_size); 90 GNUNET_TIME_absolute_get_duration (uc->start_time);
100 pi->value.unindex.duration = GNUNET_TIME_absolute_get_duration (uc->start_time);
101 pi->value.unindex.completed = offset; 91 pi->value.unindex.completed = offset;
102 uc->client_info 92 uc->client_info = uc->h->upcb (uc->h->upcb_cls, pi);
103 = uc->h->upcb (uc->h->upcb_cls,
104 pi);
105 93
106} 94}
107 95
@@ -118,10 +106,8 @@ GNUNET_FS_unindex_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
118 */ 106 */
119static void 107static void
120unindex_progress (void *cls, 108unindex_progress (void *cls,
121 uint64_t offset, 109 uint64_t offset,
122 const void *pt_block, 110 const void *pt_block, size_t pt_size, unsigned int depth)
123 size_t pt_size,
124 unsigned int depth)
125{ 111{
126 struct GNUNET_FS_UnindexContext *uc = cls; 112 struct GNUNET_FS_UnindexContext *uc = cls;
127 struct GNUNET_FS_ProgressInfo pi; 113 struct GNUNET_FS_ProgressInfo pi;
@@ -133,7 +119,7 @@ unindex_progress (void *cls,
133 pi.value.unindex.specifics.progress.depth = depth; 119 pi.value.unindex.specifics.progress.depth = depth;
134 GNUNET_FS_unindex_make_status_ (&pi, uc, offset); 120 GNUNET_FS_unindex_make_status_ (&pi, uc, offset);
135} 121}
136 122
137 123
138/** 124/**
139 * We've encountered an error during 125 * We've encountered an error during
@@ -145,7 +131,7 @@ static void
145signal_unindex_error (struct GNUNET_FS_UnindexContext *uc) 131signal_unindex_error (struct GNUNET_FS_UnindexContext *uc)
146{ 132{
147 struct GNUNET_FS_ProgressInfo pi; 133 struct GNUNET_FS_ProgressInfo pi;
148 134
149 pi.status = GNUNET_FS_STATUS_UNINDEX_ERROR; 135 pi.status = GNUNET_FS_STATUS_UNINDEX_ERROR;
150 pi.value.unindex.eta = GNUNET_TIME_UNIT_FOREVER_REL; 136 pi.value.unindex.eta = GNUNET_TIME_UNIT_FOREVER_REL;
151 pi.value.unindex.specifics.error.message = uc->emsg; 137 pi.value.unindex.specifics.error.message = uc->emsg;
@@ -162,20 +148,19 @@ signal_unindex_error (struct GNUNET_FS_UnindexContext *uc)
162 * @param msg NULL on success, otherwise an error message 148 * @param msg NULL on success, otherwise an error message
163 */ 149 */
164static void 150static void
165process_cont (void *cls, 151process_cont (void *cls, int success, const char *msg)
166 int success,
167 const char *msg)
168{ 152{
169 struct GNUNET_FS_UnindexContext *uc = cls; 153 struct GNUNET_FS_UnindexContext *uc = cls;
154
170 if (success == GNUNET_SYSERR) 155 if (success == GNUNET_SYSERR)
171 { 156 {
172 uc->emsg = GNUNET_strdup (msg); 157 uc->emsg = GNUNET_strdup (msg);
173 signal_unindex_error (uc); 158 signal_unindex_error (uc);
174 return; 159 return;
175 } 160 }
176#if DEBUG_UNINDEX 161#if DEBUG_UNINDEX
177 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 162 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
178 "Datastore REMOVE operation succeeded\n"); 163 "Datastore REMOVE operation succeeded\n");
179#endif 164#endif
180 GNUNET_FS_tree_encoder_next (uc->tc); 165 GNUNET_FS_tree_encoder_next (uc->tc);
181} 166}
@@ -195,14 +180,13 @@ process_cont (void *cls,
195 * @param block the (encrypted) block 180 * @param block the (encrypted) block
196 * @param block_size size of block (in bytes) 181 * @param block_size size of block (in bytes)
197 */ 182 */
198static void 183static void
199unindex_process (void *cls, 184unindex_process (void *cls,
200 const struct ContentHashKey *chk, 185 const struct ContentHashKey *chk,
201 uint64_t offset, 186 uint64_t offset,
202 unsigned int depth, 187 unsigned int depth,
203 enum GNUNET_BLOCK_Type type, 188 enum GNUNET_BLOCK_Type type,
204 const void *block, 189 const void *block, uint16_t block_size)
205 uint16_t block_size)
206{ 190{
207 struct GNUNET_FS_UnindexContext *uc = cls; 191 struct GNUNET_FS_UnindexContext *uc = cls;
208 uint32_t size; 192 uint32_t size;
@@ -210,29 +194,27 @@ unindex_process (void *cls,
210 struct OnDemandBlock odb; 194 struct OnDemandBlock odb;
211 195
212 if (type != GNUNET_BLOCK_TYPE_FS_DBLOCK) 196 if (type != GNUNET_BLOCK_TYPE_FS_DBLOCK)
213 { 197 {
214 size = block_size; 198 size = block_size;
215 data = block; 199 data = block;
216 } 200 }
217 else /* on-demand encoded DBLOCK */ 201 else /* on-demand encoded DBLOCK */
218 { 202 {
219 size = sizeof(struct OnDemandBlock); 203 size = sizeof (struct OnDemandBlock);
220 odb.offset = GNUNET_htonll (offset); 204 odb.offset = GNUNET_htonll (offset);
221 odb.file_id = uc->file_id; 205 odb.file_id = uc->file_id;
222 data = &odb; 206 data = &odb;
223 } 207 }
224#if DEBUG_UNINDEX 208#if DEBUG_UNINDEX
225 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 209 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
226 "Sending REMOVE request to DATASTORE service\n"); 210 "Sending REMOVE request to DATASTORE service\n");
227#endif 211#endif
228 GNUNET_DATASTORE_remove (uc->dsh, 212 GNUNET_DATASTORE_remove (uc->dsh,
229 &chk->query, 213 &chk->query,
230 size, 214 size,
231 data, 215 data,
232 -2, 1, 216 -2, 1,
233 GNUNET_CONSTANTS_SERVICE_TIMEOUT, 217 GNUNET_CONSTANTS_SERVICE_TIMEOUT, &process_cont, uc);
234 &process_cont,
235 uc);
236} 218}
237 219
238 220
@@ -244,41 +226,41 @@ unindex_process (void *cls,
244 * @param msg NULL on timeout, otherwise the response 226 * @param msg NULL on timeout, otherwise the response
245 */ 227 */
246static void 228static void
247process_fs_response (void *cls, 229process_fs_response (void *cls, const struct GNUNET_MessageHeader *msg)
248 const struct GNUNET_MessageHeader *msg)
249{ 230{
250 struct GNUNET_FS_UnindexContext *uc = cls; 231 struct GNUNET_FS_UnindexContext *uc = cls;
251 struct GNUNET_FS_ProgressInfo pi; 232 struct GNUNET_FS_ProgressInfo pi;
252 233
253 if (uc->client != NULL) 234 if (uc->client != NULL)
254 { 235 {
255 GNUNET_CLIENT_disconnect (uc->client, GNUNET_NO); 236 GNUNET_CLIENT_disconnect (uc->client, GNUNET_NO);
256 uc->client = NULL; 237 uc->client = NULL;
257 } 238 }
258 if (uc->state != UNINDEX_STATE_FS_NOTIFY) 239 if (uc->state != UNINDEX_STATE_FS_NOTIFY)
259 { 240 {
260 uc->state = UNINDEX_STATE_ERROR; 241 uc->state = UNINDEX_STATE_ERROR;
261 uc->emsg = GNUNET_strdup (_("Unexpected time for a response from `fs' service.")); 242 uc->emsg =
262 GNUNET_FS_unindex_sync_ (uc); 243 GNUNET_strdup (_("Unexpected time for a response from `fs' service."));
263 signal_unindex_error (uc); 244 GNUNET_FS_unindex_sync_ (uc);
264 return; 245 signal_unindex_error (uc);
265 } 246 return;
247 }
266 if (NULL == msg) 248 if (NULL == msg)
267 { 249 {
268 uc->state = UNINDEX_STATE_ERROR; 250 uc->state = UNINDEX_STATE_ERROR;
269 uc->emsg = GNUNET_strdup (_("Timeout waiting for `fs' service.")); 251 uc->emsg = GNUNET_strdup (_("Timeout waiting for `fs' service."));
270 GNUNET_FS_unindex_sync_ (uc); 252 GNUNET_FS_unindex_sync_ (uc);
271 signal_unindex_error (uc); 253 signal_unindex_error (uc);
272 return; 254 return;
273 } 255 }
274 if (ntohs(msg->type) != GNUNET_MESSAGE_TYPE_FS_UNINDEX_OK) 256 if (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_FS_UNINDEX_OK)
275 { 257 {
276 uc->state = UNINDEX_STATE_ERROR; 258 uc->state = UNINDEX_STATE_ERROR;
277 uc->emsg = GNUNET_strdup (_("Invalid response from `fs' service.")); 259 uc->emsg = GNUNET_strdup (_("Invalid response from `fs' service."));
278 GNUNET_FS_unindex_sync_ (uc); 260 GNUNET_FS_unindex_sync_ (uc);
279 signal_unindex_error (uc); 261 signal_unindex_error (uc);
280 return; 262 return;
281 } 263 }
282 uc->state = UNINDEX_STATE_COMPLETE; 264 uc->state = UNINDEX_STATE_COMPLETE;
283 pi.status = GNUNET_FS_STATUS_UNINDEX_COMPLETED; 265 pi.status = GNUNET_FS_STATUS_UNINDEX_COMPLETED;
284 pi.value.unindex.eta = GNUNET_TIME_UNIT_ZERO; 266 pi.value.unindex.eta = GNUNET_TIME_UNIT_ZERO;
@@ -295,8 +277,7 @@ process_fs_response (void *cls,
295 * @param tc not used 277 * @param tc not used
296 */ 278 */
297static void 279static void
298unindex_finish (void *cls, 280unindex_finish (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
299 const struct GNUNET_SCHEDULER_TaskContext *tc)
300{ 281{
301 struct GNUNET_FS_UnindexContext *uc = cls; 282 struct GNUNET_FS_UnindexContext *uc = cls;
302 char *emsg; 283 char *emsg;
@@ -304,13 +285,8 @@ unindex_finish (void *cls,
304 struct UnindexMessage req; 285 struct UnindexMessage req;
305 286
306 /* generate final progress message */ 287 /* generate final progress message */
307 unindex_progress (uc, 288 unindex_progress (uc, uc->file_size, NULL, 0, 0);
308 uc->file_size, 289 GNUNET_FS_tree_encoder_finish (uc->tc, &uri, &emsg);
309 NULL,
310 0, 0);
311 GNUNET_FS_tree_encoder_finish (uc->tc,
312 &uri,
313 &emsg);
314 uc->tc = NULL; 290 uc->tc = NULL;
315 if (uri != NULL) 291 if (uri != NULL)
316 GNUNET_FS_uri_destroy (uri); 292 GNUNET_FS_uri_destroy (uri);
@@ -320,31 +296,31 @@ unindex_finish (void *cls,
320 uc->dsh = NULL; 296 uc->dsh = NULL;
321 uc->state = UNINDEX_STATE_FS_NOTIFY; 297 uc->state = UNINDEX_STATE_FS_NOTIFY;
322 GNUNET_FS_unindex_sync_ (uc); 298 GNUNET_FS_unindex_sync_ (uc);
323 uc->client = GNUNET_CLIENT_connect ("fs", 299 uc->client = GNUNET_CLIENT_connect ("fs", uc->h->cfg);
324 uc->h->cfg);
325 if (uc->client == NULL) 300 if (uc->client == NULL)
326 { 301 {
327 uc->state = UNINDEX_STATE_ERROR; 302 uc->state = UNINDEX_STATE_ERROR;
328 uc->emsg = GNUNET_strdup (_("Failed to connect to FS service for unindexing.")); 303 uc->emsg =
329 GNUNET_FS_unindex_sync_ (uc); 304 GNUNET_strdup (_("Failed to connect to FS service for unindexing."));
330 signal_unindex_error (uc); 305 GNUNET_FS_unindex_sync_ (uc);
331 return; 306 signal_unindex_error (uc);
332 } 307 return;
308 }
333#if DEBUG_UNINDEX 309#if DEBUG_UNINDEX
334 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 310 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
335 "Sending UNINDEX message to FS service\n"); 311 "Sending UNINDEX message to FS service\n");
336#endif 312#endif
337 req.header.size = htons (sizeof (struct UnindexMessage)); 313 req.header.size = htons (sizeof (struct UnindexMessage));
338 req.header.type = htons (GNUNET_MESSAGE_TYPE_FS_UNINDEX); 314 req.header.type = htons (GNUNET_MESSAGE_TYPE_FS_UNINDEX);
339 req.reserved = 0; 315 req.reserved = 0;
340 req.file_id = uc->file_id; 316 req.file_id = uc->file_id;
341 GNUNET_break (GNUNET_OK == 317 GNUNET_break (GNUNET_OK ==
342 GNUNET_CLIENT_transmit_and_get_response (uc->client, 318 GNUNET_CLIENT_transmit_and_get_response (uc->client,
343 &req.header, 319 &req.header,
344 GNUNET_CONSTANTS_SERVICE_TIMEOUT, 320 GNUNET_CONSTANTS_SERVICE_TIMEOUT,
345 GNUNET_YES, 321 GNUNET_YES,
346 &process_fs_response, 322 &process_fs_response,
347 uc)); 323 uc));
348} 324}
349 325
350 326
@@ -353,38 +329,36 @@ unindex_finish (void *cls,
353 * 329 *
354 * @param uc context for the unindex operation. 330 * @param uc context for the unindex operation.
355 */ 331 */
356void 332void
357GNUNET_FS_unindex_do_remove_ (struct GNUNET_FS_UnindexContext *uc) 333GNUNET_FS_unindex_do_remove_ (struct GNUNET_FS_UnindexContext *uc)
358{ 334{
359 uc->dsh = GNUNET_DATASTORE_connect (uc->h->cfg); 335 uc->dsh = GNUNET_DATASTORE_connect (uc->h->cfg);
360 if (NULL == uc->dsh) 336 if (NULL == uc->dsh)
361 { 337 {
362 uc->state = UNINDEX_STATE_ERROR; 338 uc->state = UNINDEX_STATE_ERROR;
363 uc->emsg = GNUNET_strdup (_("Failed to connect to `datastore' service.")); 339 uc->emsg = GNUNET_strdup (_("Failed to connect to `datastore' service."));
364 GNUNET_FS_unindex_sync_ (uc); 340 GNUNET_FS_unindex_sync_ (uc);
365 signal_unindex_error (uc); 341 signal_unindex_error (uc);
366 return; 342 return;
367 } 343 }
368 uc->fh = GNUNET_DISK_file_open (uc->filename, 344 uc->fh = GNUNET_DISK_file_open (uc->filename,
369 GNUNET_DISK_OPEN_READ, 345 GNUNET_DISK_OPEN_READ, GNUNET_DISK_PERM_NONE);
370 GNUNET_DISK_PERM_NONE);
371 if (NULL == uc->fh) 346 if (NULL == uc->fh)
372 { 347 {
373 GNUNET_DATASTORE_disconnect (uc->dsh, GNUNET_NO); 348 GNUNET_DATASTORE_disconnect (uc->dsh, GNUNET_NO);
374 uc->dsh = NULL; 349 uc->dsh = NULL;
375 uc->state = UNINDEX_STATE_ERROR; 350 uc->state = UNINDEX_STATE_ERROR;
376 uc->emsg = GNUNET_strdup (_("Failed to open file for unindexing.")); 351 uc->emsg = GNUNET_strdup (_("Failed to open file for unindexing."));
377 GNUNET_FS_unindex_sync_ (uc); 352 GNUNET_FS_unindex_sync_ (uc);
378 signal_unindex_error (uc); 353 signal_unindex_error (uc);
379 return; 354 return;
380 } 355 }
381 uc->tc = GNUNET_FS_tree_encoder_create (uc->h, 356 uc->tc = GNUNET_FS_tree_encoder_create (uc->h,
382 uc->file_size, 357 uc->file_size,
383 uc, 358 uc,
384 &unindex_reader, 359 &unindex_reader,
385 &unindex_process, 360 &unindex_process,
386 &unindex_progress, 361 &unindex_progress, &unindex_finish);
387 &unindex_finish);
388 GNUNET_FS_tree_encoder_next (uc->tc); 362 GNUNET_FS_tree_encoder_next (uc->tc);
389} 363}
390 364
@@ -396,26 +370,25 @@ GNUNET_FS_unindex_do_remove_ (struct GNUNET_FS_UnindexContext *uc)
396 * @param cls closure, unindex context 370 * @param cls closure, unindex context
397 * @param file_id computed hash, NULL on error 371 * @param file_id computed hash, NULL on error
398 */ 372 */
399void 373void
400GNUNET_FS_unindex_process_hash_ (void *cls, 374GNUNET_FS_unindex_process_hash_ (void *cls, const GNUNET_HashCode * file_id)
401 const GNUNET_HashCode *file_id)
402{ 375{
403 struct GNUNET_FS_UnindexContext *uc = cls; 376 struct GNUNET_FS_UnindexContext *uc = cls;
404 377
405 uc->fhc = NULL; 378 uc->fhc = NULL;
406 if (uc->state != UNINDEX_STATE_HASHING) 379 if (uc->state != UNINDEX_STATE_HASHING)
407 { 380 {
408 GNUNET_FS_unindex_stop (uc); 381 GNUNET_FS_unindex_stop (uc);
409 return; 382 return;
410 } 383 }
411 if (file_id == NULL) 384 if (file_id == NULL)
412 { 385 {
413 uc->state = UNINDEX_STATE_ERROR; 386 uc->state = UNINDEX_STATE_ERROR;
414 uc->emsg = GNUNET_strdup (_("Failed to compute hash of file.")); 387 uc->emsg = GNUNET_strdup (_("Failed to compute hash of file."));
415 GNUNET_FS_unindex_sync_ (uc); 388 GNUNET_FS_unindex_sync_ (uc);
416 signal_unindex_error (uc); 389 signal_unindex_error (uc);
417 return; 390 return;
418 } 391 }
419 uc->file_id = *file_id; 392 uc->file_id = *file_id;
420 uc->state = UNINDEX_STATE_DS_REMOVE; 393 uc->state = UNINDEX_STATE_DS_REMOVE;
421 GNUNET_FS_unindex_sync_ (uc); 394 GNUNET_FS_unindex_sync_ (uc);
@@ -436,37 +409,35 @@ GNUNET_FS_unindex_signal_suspend_ (void *cls)
436 struct GNUNET_FS_ProgressInfo pi; 409 struct GNUNET_FS_ProgressInfo pi;
437 410
438 if (uc->fhc != NULL) 411 if (uc->fhc != NULL)
439 { 412 {
440 GNUNET_CRYPTO_hash_file_cancel (uc->fhc); 413 GNUNET_CRYPTO_hash_file_cancel (uc->fhc);
441 uc->fhc = NULL; 414 uc->fhc = NULL;
442 } 415 }
443 if (uc->client != NULL) 416 if (uc->client != NULL)
444 { 417 {
445 GNUNET_CLIENT_disconnect (uc->client, GNUNET_NO); 418 GNUNET_CLIENT_disconnect (uc->client, GNUNET_NO);
446 uc->client = NULL; 419 uc->client = NULL;
447 } 420 }
448 if (NULL != uc->dsh) 421 if (NULL != uc->dsh)
449 { 422 {
450 GNUNET_DATASTORE_disconnect (uc->dsh, GNUNET_NO); 423 GNUNET_DATASTORE_disconnect (uc->dsh, GNUNET_NO);
451 uc->dsh = NULL; 424 uc->dsh = NULL;
452 } 425 }
453 if (NULL != uc->tc) 426 if (NULL != uc->tc)
454 { 427 {
455 GNUNET_FS_tree_encoder_finish (uc->tc, 428 GNUNET_FS_tree_encoder_finish (uc->tc, NULL, NULL);
456 NULL, 429 uc->tc = NULL;
457 NULL); 430 }
458 uc->tc = NULL;
459 }
460 if (uc->fh != NULL) 431 if (uc->fh != NULL)
461 { 432 {
462 GNUNET_DISK_file_close (uc->fh); 433 GNUNET_DISK_file_close (uc->fh);
463 uc->fh = NULL; 434 uc->fh = NULL;
464 } 435 }
465 GNUNET_FS_end_top (uc->h, uc->top); 436 GNUNET_FS_end_top (uc->h, uc->top);
466 pi.status = GNUNET_FS_STATUS_UNINDEX_SUSPEND; 437 pi.status = GNUNET_FS_STATUS_UNINDEX_SUSPEND;
467 GNUNET_FS_unindex_make_status_ (&pi, uc, 438 GNUNET_FS_unindex_make_status_ (&pi, uc,
468 (uc->state == UNINDEX_STATE_COMPLETE) 439 (uc->state == UNINDEX_STATE_COMPLETE)
469 ? uc->file_size : 0); 440 ? uc->file_size : 0);
470 GNUNET_break (NULL == uc->client_info); 441 GNUNET_break (NULL == uc->client_info);
471 GNUNET_free (uc->filename); 442 GNUNET_free (uc->filename);
472 GNUNET_free_non_null (uc->serialization); 443 GNUNET_free_non_null (uc->serialization);
@@ -485,17 +456,13 @@ GNUNET_FS_unindex_signal_suspend_ (void *cls)
485 */ 456 */
486struct GNUNET_FS_UnindexContext * 457struct GNUNET_FS_UnindexContext *
487GNUNET_FS_unindex_start (struct GNUNET_FS_Handle *h, 458GNUNET_FS_unindex_start (struct GNUNET_FS_Handle *h,
488 const char *filename, 459 const char *filename, void *cctx)
489 void *cctx)
490{ 460{
491 struct GNUNET_FS_UnindexContext *ret; 461 struct GNUNET_FS_UnindexContext *ret;
492 struct GNUNET_FS_ProgressInfo pi; 462 struct GNUNET_FS_ProgressInfo pi;
493 uint64_t size; 463 uint64_t size;
494 464
495 if (GNUNET_OK != 465 if (GNUNET_OK != GNUNET_DISK_file_size (filename, &size, GNUNET_YES))
496 GNUNET_DISK_file_size (filename,
497 &size,
498 GNUNET_YES))
499 return NULL; 466 return NULL;
500 ret = GNUNET_malloc (sizeof (struct GNUNET_FS_UnindexContext)); 467 ret = GNUNET_malloc (sizeof (struct GNUNET_FS_UnindexContext));
501 ret->h = h; 468 ret->h = h;
@@ -508,13 +475,10 @@ GNUNET_FS_unindex_start (struct GNUNET_FS_Handle *h,
508 pi.value.unindex.eta = GNUNET_TIME_UNIT_FOREVER_REL; 475 pi.value.unindex.eta = GNUNET_TIME_UNIT_FOREVER_REL;
509 GNUNET_FS_unindex_make_status_ (&pi, ret, 0); 476 GNUNET_FS_unindex_make_status_ (&pi, ret, 0);
510 ret->fhc = GNUNET_CRYPTO_hash_file (GNUNET_SCHEDULER_PRIORITY_IDLE, 477 ret->fhc = GNUNET_CRYPTO_hash_file (GNUNET_SCHEDULER_PRIORITY_IDLE,
511 filename, 478 filename,
512 HASHING_BLOCKSIZE, 479 HASHING_BLOCKSIZE,
513 &GNUNET_FS_unindex_process_hash_, 480 &GNUNET_FS_unindex_process_hash_, ret);
514 ret); 481 ret->top = GNUNET_FS_make_top (h, &GNUNET_FS_unindex_signal_suspend_, ret);
515 ret->top = GNUNET_FS_make_top (h,
516 &GNUNET_FS_unindex_signal_suspend_,
517 ret);
518 return ret; 482 return ret;
519} 483}
520 484
@@ -526,48 +490,47 @@ GNUNET_FS_unindex_start (struct GNUNET_FS_Handle *h,
526 */ 490 */
527void 491void
528GNUNET_FS_unindex_stop (struct GNUNET_FS_UnindexContext *uc) 492GNUNET_FS_unindex_stop (struct GNUNET_FS_UnindexContext *uc)
529{ 493{
530 struct GNUNET_FS_ProgressInfo pi; 494 struct GNUNET_FS_ProgressInfo pi;
531 495
532 if (uc->fhc != NULL) 496 if (uc->fhc != NULL)
533 { 497 {
534 GNUNET_CRYPTO_hash_file_cancel (uc->fhc); 498 GNUNET_CRYPTO_hash_file_cancel (uc->fhc);
535 uc->fhc = NULL; 499 uc->fhc = NULL;
536 } 500 }
537 if (uc->client != NULL) 501 if (uc->client != NULL)
538 { 502 {
539 GNUNET_CLIENT_disconnect (uc->client, GNUNET_NO); 503 GNUNET_CLIENT_disconnect (uc->client, GNUNET_NO);
540 uc->client = NULL; 504 uc->client = NULL;
541 } 505 }
542 if (NULL != uc->dsh) 506 if (NULL != uc->dsh)
543 { 507 {
544 GNUNET_DATASTORE_disconnect (uc->dsh, GNUNET_NO); 508 GNUNET_DATASTORE_disconnect (uc->dsh, GNUNET_NO);
545 uc->dsh = NULL; 509 uc->dsh = NULL;
546 } 510 }
547 if (NULL != uc->tc) 511 if (NULL != uc->tc)
548 { 512 {
549 GNUNET_FS_tree_encoder_finish (uc->tc, 513 GNUNET_FS_tree_encoder_finish (uc->tc, NULL, NULL);
550 NULL, 514 uc->tc = NULL;
551 NULL); 515 }
552 uc->tc = NULL;
553 }
554 if (uc->fh != NULL) 516 if (uc->fh != NULL)
555 { 517 {
556 GNUNET_DISK_file_close (uc->fh); 518 GNUNET_DISK_file_close (uc->fh);
557 uc->fh = NULL; 519 uc->fh = NULL;
558 } 520 }
559 GNUNET_FS_end_top (uc->h, uc->top); 521 GNUNET_FS_end_top (uc->h, uc->top);
560 if (uc->serialization != NULL) 522 if (uc->serialization != NULL)
561 { 523 {
562 GNUNET_FS_remove_sync_file_ (uc->h, GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, uc->serialization); 524 GNUNET_FS_remove_sync_file_ (uc->h, GNUNET_FS_SYNC_PATH_MASTER_UNINDEX,
563 GNUNET_free (uc->serialization); 525 uc->serialization);
564 uc->serialization = NULL; 526 GNUNET_free (uc->serialization);
565 } 527 uc->serialization = NULL;
528 }
566 pi.status = GNUNET_FS_STATUS_UNINDEX_STOPPED; 529 pi.status = GNUNET_FS_STATUS_UNINDEX_STOPPED;
567 pi.value.unindex.eta = GNUNET_TIME_UNIT_ZERO; 530 pi.value.unindex.eta = GNUNET_TIME_UNIT_ZERO;
568 GNUNET_FS_unindex_make_status_ (&pi, uc, 531 GNUNET_FS_unindex_make_status_ (&pi, uc,
569 (uc->state == UNINDEX_STATE_COMPLETE) 532 (uc->state == UNINDEX_STATE_COMPLETE)
570 ? uc->file_size : 0); 533 ? uc->file_size : 0);
571 GNUNET_break (NULL == uc->client_info); 534 GNUNET_break (NULL == uc->client_info);
572 GNUNET_free (uc->filename); 535 GNUNET_free (uc->filename);
573 GNUNET_free (uc); 536 GNUNET_free (uc);
diff --git a/src/fs/fs_uri.c b/src/fs/fs_uri.c
index 4b249d6bf..5d5d24ca8 100644
--- a/src/fs/fs_uri.c
+++ b/src/fs/fs_uri.c
@@ -91,33 +91,33 @@
91 * @param uri uri to convert to a unique key 91 * @param uri uri to convert to a unique key
92 * @param key wherer to store the unique key 92 * @param key wherer to store the unique key
93 */ 93 */
94void 94void
95GNUNET_FS_uri_to_key (const struct GNUNET_FS_Uri *uri, 95GNUNET_FS_uri_to_key (const struct GNUNET_FS_Uri *uri, GNUNET_HashCode * key)
96 GNUNET_HashCode * key)
97{ 96{
98 switch (uri->type) 97 switch (uri->type)
99 { 98 {
100 case chk: 99 case chk:
101 *key = uri->data.chk.chk.query; 100 *key = uri->data.chk.chk.query;
102 return; 101 return;
103 case sks: 102 case sks:
104 GNUNET_CRYPTO_hash (uri->data.sks.identifier, 103 GNUNET_CRYPTO_hash (uri->data.sks.identifier,
105 strlen (uri->data.sks.identifier), key); 104 strlen (uri->data.sks.identifier), key);
106 break; 105 break;
107 case ksk: 106 case ksk:
108 if (uri->data.ksk.keywordCount > 0) 107 if (uri->data.ksk.keywordCount > 0)
109 GNUNET_CRYPTO_hash (uri->data.ksk.keywords[0], 108 GNUNET_CRYPTO_hash (uri->data.ksk.keywords[0],
110 strlen (uri->data.ksk.keywords[0]), key); 109 strlen (uri->data.ksk.keywords[0]), key);
111 break; 110 break;
112 case loc: 111 case loc:
113 GNUNET_CRYPTO_hash (&uri->data.loc.fi, 112 GNUNET_CRYPTO_hash (&uri->data.loc.fi,
114 sizeof (struct FileIdentifier) + 113 sizeof (struct FileIdentifier) +
115 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), key); 114 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
116 break; 115 key);
117 default: 116 break;
118 memset (key, 0, sizeof (GNUNET_HashCode)); 117 default:
119 break; 118 memset (key, 0, sizeof (GNUNET_HashCode));
120 } 119 break;
120 }
121} 121}
122 122
123 123
@@ -139,45 +139,45 @@ GNUNET_FS_uri_ksk_to_string_fancy (const struct GNUNET_FS_Uri *uri)
139 unsigned int keywordCount; 139 unsigned int keywordCount;
140 140
141 if ((uri == NULL) || (uri->type != ksk)) 141 if ((uri == NULL) || (uri->type != ksk))
142 { 142 {
143 GNUNET_break (0); 143 GNUNET_break (0);
144 return NULL; 144 return NULL;
145 } 145 }
146 keywords = uri->data.ksk.keywords; 146 keywords = uri->data.ksk.keywords;
147 keywordCount = uri->data.ksk.keywordCount; 147 keywordCount = uri->data.ksk.keywordCount;
148 n = keywordCount + 1; 148 n = keywordCount + 1;
149 for (i = 0; i < keywordCount; i++) 149 for (i = 0; i < keywordCount; i++)
150 { 150 {
151 keyword = keywords[i]; 151 keyword = keywords[i];
152 n += strlen (keyword) - 1; 152 n += strlen (keyword) - 1;
153 if (NULL != strstr (&keyword[1], " ")) 153 if (NULL != strstr (&keyword[1], " "))
154 n += 2; 154 n += 2;
155 if (keyword[0] == '+') 155 if (keyword[0] == '+')
156 n++; 156 n++;
157 } 157 }
158 ret = GNUNET_malloc (n); 158 ret = GNUNET_malloc (n);
159 strcpy (ret, ""); 159 strcpy (ret, "");
160 for (i = 0; i < keywordCount; i++) 160 for (i = 0; i < keywordCount; i++)
161 {
162 keyword = keywords[i];
163 if (NULL != strstr (&keyword[1], " "))
161 { 164 {
162 keyword = keywords[i]; 165 strcat (ret, "\"");
163 if (NULL != strstr (&keyword[1], " ")) 166 if (keyword[0] == '+')
164 { 167 strcat (ret, keyword);
165 strcat (ret, "\"");
166 if (keyword[0] == '+')
167 strcat (ret, keyword);
168 else
169 strcat (ret, &keyword[1]);
170 strcat (ret, "\"");
171 }
172 else 168 else
173 { 169 strcat (ret, &keyword[1]);
174 if (keyword[0] == '+') 170 strcat (ret, "\"");
175 strcat (ret, keyword);
176 else
177 strcat (ret, &keyword[1]);
178 }
179 strcat (ret, " ");
180 } 171 }
172 else
173 {
174 if (keyword[0] == '+')
175 strcat (ret, keyword);
176 else
177 strcat (ret, &keyword[1]);
178 }
179 strcat (ret, " ");
180 }
181 return ret; 181 return ret;
182} 182}
183 183
@@ -205,37 +205,37 @@ percent_decode_keyword (const char *in, char **emsg)
205 rpos = 0; 205 rpos = 0;
206 wpos = 0; 206 wpos = 0;
207 while (out[rpos] != '\0') 207 while (out[rpos] != '\0')
208 {
209 if (out[rpos] == '%')
208 { 210 {
209 if (out[rpos] == '%') 211 if (1 != sscanf (&out[rpos + 1], "%2X", &hx))
210 { 212 {
211 if (1 != sscanf (&out[rpos + 1], "%2X", &hx)) 213 GNUNET_free (out);
212 { 214 *emsg = GNUNET_strdup (_("`%' must be followed by HEX number"));
213 GNUNET_free (out); 215 return NULL;
214 *emsg = GNUNET_strdup (_("`%' must be followed by HEX number")); 216 }
215 return NULL; 217 rpos += 3;
216 } 218 if (hx == '"')
217 rpos += 3; 219 continue; /* skip double quote */
218 if (hx == '"') 220 out[wpos++] = (char) hx;
219 continue; /* skip double quote */
220 out[wpos++] = (char) hx;
221 }
222 else
223 {
224 out[wpos++] = out[rpos++];
225 }
226 } 221 }
227 out[wpos] = '\0'; 222 else
228 if (out[0] == '+')
229 { 223 {
230 ret = GNUNET_strdup (out); 224 out[wpos++] = out[rpos++];
231 } 225 }
226 }
227 out[wpos] = '\0';
228 if (out[0] == '+')
229 {
230 ret = GNUNET_strdup (out);
231 }
232 else 232 else
233 { 233 {
234 /* need to prefix with space */ 234 /* need to prefix with space */
235 ret = GNUNET_malloc (strlen (out) + 2); 235 ret = GNUNET_malloc (strlen (out) + 2);
236 strcpy (ret, " "); 236 strcpy (ret, " ");
237 strcat (ret, out); 237 strcat (ret, out);
238 } 238 }
239 GNUNET_free (out); 239 GNUNET_free (out);
240 return ret; 240 return ret;
241} 241}
@@ -265,66 +265,64 @@ uri_ksk_parse (const char *s, char **emsg)
265 GNUNET_assert (s != NULL); 265 GNUNET_assert (s != NULL);
266 slen = strlen (s); 266 slen = strlen (s);
267 pos = strlen (GNUNET_FS_URI_KSK_PREFIX); 267 pos = strlen (GNUNET_FS_URI_KSK_PREFIX);
268 if ( (slen <= pos) || 268 if ((slen <= pos) || (0 != strncmp (s, GNUNET_FS_URI_KSK_PREFIX, pos)))
269 (0 != strncmp (s, GNUNET_FS_URI_KSK_PREFIX, 269 return NULL; /* not KSK URI */
270 pos) ) ) 270 if ((s[slen - 1] == '+') || (s[pos] == '+'))
271 return NULL; /* not KSK URI */ 271 {
272 if ( (s[slen - 1] == '+') || 272 *emsg =
273 (s[pos] == '+') ) 273 GNUNET_strdup (_("Malformed KSK URI (must not begin or end with `+')"));
274 { 274 return NULL;
275 *emsg = GNUNET_strdup (_("Malformed KSK URI (must not begin or end with `+')")); 275 }
276 return NULL;
277 }
278 max = 1; 276 max = 1;
279 saw_quote = 0; 277 saw_quote = 0;
280 for (i = pos; i < slen; i++) 278 for (i = pos; i < slen; i++)
279 {
280 if ((s[i] == '%') && (&s[i] == strstr (&s[i], "%22")))
281 { 281 {
282 if ((s[i] == '%') && (&s[i] == strstr (&s[i], "%22"))) 282 saw_quote = (saw_quote + 1) % 2;
283 { 283 i += 3;
284 saw_quote = (saw_quote + 1) % 2; 284 continue;
285 i += 3;
286 continue;
287 }
288 if ((s[i] == '+') && (saw_quote == 0))
289 {
290 max++;
291 if (s[i - 1] == '+')
292 {
293 *emsg = GNUNET_strdup (_("`++' not allowed in KSK URI"));
294 return NULL;
295 }
296 }
297 } 285 }
298 if (saw_quote == 1) 286 if ((s[i] == '+') && (saw_quote == 0))
299 { 287 {
300 *emsg = GNUNET_strdup (_("Quotes not balanced in KSK URI")); 288 max++;
301 return NULL; 289 if (s[i - 1] == '+')
290 {
291 *emsg = GNUNET_strdup (_("`++' not allowed in KSK URI"));
292 return NULL;
293 }
302 } 294 }
295 }
296 if (saw_quote == 1)
297 {
298 *emsg = GNUNET_strdup (_("Quotes not balanced in KSK URI"));
299 return NULL;
300 }
303 iret = max; 301 iret = max;
304 dup = GNUNET_strdup (s); 302 dup = GNUNET_strdup (s);
305 keywords = GNUNET_malloc (max * sizeof (char *)); 303 keywords = GNUNET_malloc (max * sizeof (char *));
306 for (i = slen - 1; i >= pos; i--) 304 for (i = slen - 1; i >= pos; i--)
305 {
306 if ((s[i] == '%') && (&s[i] == strstr (&s[i], "%22")))
307 { 307 {
308 if ((s[i] == '%') && (&s[i] == strstr (&s[i], "%22"))) 308 saw_quote = (saw_quote + 1) % 2;
309 { 309 i += 3;
310 saw_quote = (saw_quote + 1) % 2; 310 continue;
311 i += 3; 311 }
312 continue; 312 if ((dup[i] == '+') && (saw_quote == 0))
313 } 313 {
314 if ((dup[i] == '+') && (saw_quote == 0)) 314 keywords[--max] = percent_decode_keyword (&dup[i + 1], emsg);
315 { 315 if (NULL == keywords[max])
316 keywords[--max] = percent_decode_keyword (&dup[i + 1], emsg); 316 goto CLEANUP;
317 if (NULL == keywords[max]) 317 dup[i] = '\0';
318 goto CLEANUP;
319 dup[i] = '\0';
320 }
321 } 318 }
319 }
322 keywords[--max] = percent_decode_keyword (&dup[pos], emsg); 320 keywords[--max] = percent_decode_keyword (&dup[pos], emsg);
323 if (NULL == keywords[max]) 321 if (NULL == keywords[max])
324 goto CLEANUP; 322 goto CLEANUP;
325 GNUNET_assert (max == 0); 323 GNUNET_assert (max == 0);
326 GNUNET_free (dup); 324 GNUNET_free (dup);
327 ret = GNUNET_malloc (sizeof(struct GNUNET_FS_Uri)); 325 ret = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri));
328 ret->type = ksk; 326 ret->type = ksk;
329 ret->data.ksk.keywordCount = iret; 327 ret->data.ksk.keywordCount = iret;
330 ret->data.ksk.keywords = keywords; 328 ret->data.ksk.keywords = keywords;
@@ -355,30 +353,29 @@ uri_sks_parse (const char *s, char **emsg)
355 char *identifier; 353 char *identifier;
356 unsigned int pos; 354 unsigned int pos;
357 size_t slen; 355 size_t slen;
358 char enc[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)]; 356 char enc[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)];
359 357
360 GNUNET_assert (s != NULL); 358 GNUNET_assert (s != NULL);
361 slen = strlen (s); 359 slen = strlen (s);
362 pos = strlen ( GNUNET_FS_URI_SKS_PREFIX); 360 pos = strlen (GNUNET_FS_URI_SKS_PREFIX);
363 if ( (slen <= pos) || 361 if ((slen <= pos) || (0 != strncmp (s, GNUNET_FS_URI_SKS_PREFIX, pos)))
364 (0 != strncmp (s, GNUNET_FS_URI_SKS_PREFIX, 362 return NULL; /* not an SKS URI */
365 pos) ) ) 363 if ((slen < pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)) ||
366 return NULL; /* not an SKS URI */ 364 (s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] != '/'))
367 if ( (slen < pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)) || 365 {
368 (s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] != '/') ) 366 *emsg = GNUNET_strdup (_("Malformed SKS URI"));
369 { 367 return NULL;
370 *emsg = GNUNET_strdup (_("Malformed SKS URI")); 368 }
371 return NULL; 369 memcpy (enc, &s[pos], sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded));
372 } 370 enc[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0';
373 memcpy (enc, &s[pos], sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded));
374 enc[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)-1] = '\0';
375 if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (enc, &namespace)) 371 if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (enc, &namespace))
376 { 372 {
377 *emsg = GNUNET_strdup (_("Malformed SKS URI")); 373 *emsg = GNUNET_strdup (_("Malformed SKS URI"));
378 return NULL; 374 return NULL;
379 } 375 }
380 identifier = GNUNET_strdup (&s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)]); 376 identifier =
381 ret = GNUNET_malloc (sizeof(struct GNUNET_FS_Uri)); 377 GNUNET_strdup (&s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)]);
378 ret = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri));
382 ret->type = sks; 379 ret->type = sks;
383 ret->data.sks.namespace = namespace; 380 ret->data.sks.namespace = namespace;
384 ret->data.sks.identifier = identifier; 381 ret->data.sks.identifier = identifier;
@@ -403,46 +400,43 @@ uri_chk_parse (const char *s, char **emsg)
403 unsigned int pos; 400 unsigned int pos;
404 unsigned long long flen; 401 unsigned long long flen;
405 size_t slen; 402 size_t slen;
406 char h1[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)]; 403 char h1[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)];
407 char h2[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)]; 404 char h2[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)];
408 405
409 if (NULL == s) 406 if (NULL == s)
410 return NULL; 407 return NULL;
411 GNUNET_assert (s != NULL); 408 GNUNET_assert (s != NULL);
412 slen = strlen (s); 409 slen = strlen (s);
413 pos = strlen (GNUNET_FS_URI_CHK_PREFIX); 410 pos = strlen (GNUNET_FS_URI_CHK_PREFIX);
414 if ( (slen < pos + 2 * sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) + 1) || 411 if ((slen < pos + 2 * sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) + 1) ||
415 (0 != strncmp (s, GNUNET_FS_URI_CHK_PREFIX, 412 (0 != strncmp (s, GNUNET_FS_URI_CHK_PREFIX, pos)))
416 pos) ) ) 413 return NULL; /* not a CHK URI */
417 return NULL; /* not a CHK URI */ 414 if ((s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] != '.') ||
418 if ( (s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] != '.') || 415 (s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2 - 1] != '.'))
419 (s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2 - 1] != '.') ) 416 {
420 { 417 *emsg = GNUNET_strdup (_("Malformed CHK URI"));
421 *emsg = GNUNET_strdup (_("Malformed CHK URI")); 418 return NULL;
422 return NULL; 419 }
423 } 420 memcpy (h1, &s[pos], sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded));
424 memcpy (h1, 421 h1[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0';
425 &s[pos],
426 sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded));
427 h1[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)-1] = '\0';
428 memcpy (h2, 422 memcpy (h2,
429 &s[pos + sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)], 423 &s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)],
430 sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)); 424 sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded));
431 h2[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)-1] = '\0'; 425 h2[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0';
432 426
433 if ((GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h1, 427 if ((GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h1,
434 &fi.chk.key)) || 428 &fi.chk.key)) ||
435 (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h2, 429 (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h2,
436 &fi.chk.query)) || 430 &fi.chk.query)) ||
437 (1 != SSCANF (&s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2], 431 (1 !=
438 "%llu", 432 SSCANF (&s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2],
439 &flen)) ) 433 "%llu", &flen)))
440 { 434 {
441 *emsg = GNUNET_strdup (_("Malformed CHK URI")); 435 *emsg = GNUNET_strdup (_("Malformed CHK URI"));
442 return NULL; 436 return NULL;
443 } 437 }
444 fi.file_length = GNUNET_htonll (flen); 438 fi.file_length = GNUNET_htonll (flen);
445 ret = GNUNET_malloc (sizeof(struct GNUNET_FS_Uri)); 439 ret = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri));
446 ret->type = chk; 440 ret->type = chk;
447 ret->data.chk = fi; 441 ret->data.chk = fi;
448 return ret; 442 return ret;
@@ -499,16 +493,16 @@ enc2bin (const char *input, void *data, size_t size)
499 hbits = 0; 493 hbits = 0;
500 len = 0; 494 len = 0;
501 for (pos = 0; pos < size; pos++) 495 for (pos = 0; pos < size; pos++)
496 {
497 while (hbits < 8)
502 { 498 {
503 while (hbits < 8) 499 bits |= (c2v (input[len++]) << hbits);
504 { 500 hbits += 6;
505 bits |= (c2v (input[len++]) << hbits);
506 hbits += 6;
507 }
508 (((unsigned char *) data)[pos]) = (unsigned char) bits;
509 bits >>= 8;
510 hbits -= 8;
511 } 501 }
502 (((unsigned char *) data)[pos]) = (unsigned char) bits;
503 bits >>= 8;
504 hbits -= 8;
505 }
512 return len; 506 return len;
513} 507}
514 508
@@ -520,14 +514,14 @@ enc2bin (const char *input, void *data, size_t size)
520 * verify the signature of a location 514 * verify the signature of a location
521 * URI. 515 * URI.
522 */ 516 */
523struct LocUriAssembly 517struct LocUriAssembly
524{ 518{
525 struct GNUNET_CRYPTO_RsaSignaturePurpose purpose; 519 struct GNUNET_CRYPTO_RsaSignaturePurpose purpose;
526 520
527 struct GNUNET_TIME_AbsoluteNBO exptime; 521 struct GNUNET_TIME_AbsoluteNBO exptime;
528 522
529 struct FileIdentifier fi; 523 struct FileIdentifier fi;
530 524
531 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded peer; 525 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded peer;
532 526
533}; 527};
@@ -547,8 +541,8 @@ static struct GNUNET_FS_Uri *
547uri_loc_parse (const char *s, char **emsg) 541uri_loc_parse (const char *s, char **emsg)
548{ 542{
549 struct GNUNET_FS_Uri *uri; 543 struct GNUNET_FS_Uri *uri;
550 char h1[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)]; 544 char h1[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)];
551 char h2[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)]; 545 char h2[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)];
552 unsigned int pos; 546 unsigned int pos;
553 unsigned int npos; 547 unsigned int npos;
554 unsigned long long exptime; 548 unsigned long long exptime;
@@ -561,95 +555,92 @@ uri_loc_parse (const char *s, char **emsg)
561 555
562 GNUNET_assert (s != NULL); 556 GNUNET_assert (s != NULL);
563 slen = strlen (s); 557 slen = strlen (s);
564 pos = strlen ( GNUNET_FS_URI_LOC_PREFIX); 558 pos = strlen (GNUNET_FS_URI_LOC_PREFIX);
565 if ( (slen < pos + 2 * sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) + 1) || 559 if ((slen < pos + 2 * sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) + 1) ||
566 (0 != strncmp (s, GNUNET_FS_URI_LOC_PREFIX, 560 (0 != strncmp (s, GNUNET_FS_URI_LOC_PREFIX, pos)))
567 pos) ) ) 561 return NULL; /* not an SKS URI */
568 return NULL; /* not an SKS URI */ 562 if ((s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] != '.') ||
569 if ( (s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] != '.') || 563 (s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2 - 1] != '.'))
570 (s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2 - 1] != '.') ) 564 {
571 { 565 *emsg = GNUNET_strdup (_("SKS URI malformed"));
572 *emsg = GNUNET_strdup (_("SKS URI malformed")); 566 return NULL;
573 return NULL; 567 }
574 } 568 memcpy (h1, &s[pos], sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded));
575 memcpy (h1, 569 h1[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0';
576 &s[pos],
577 sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded));
578 h1[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)-1] = '\0';
579 memcpy (h2, 570 memcpy (h2,
580 &s[pos + sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)], 571 &s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)],
581 sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)); 572 sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded));
582 h2[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)-1] = '\0'; 573 h2[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0';
583 574
584 if ((GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h1, 575 if ((GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h1,
585 &ass.fi.chk.key)) || 576 &ass.fi.chk.key)) ||
586 (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h2, 577 (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h2,
587 &ass.fi.chk.query)) || 578 &ass.fi.chk.query)) ||
588 (1 != SSCANF (&s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2], 579 (1 !=
589 "%llu", 580 SSCANF (&s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2],
590 &flen)) ) 581 "%llu", &flen)))
591 { 582 {
592 *emsg = GNUNET_strdup (_("SKS URI malformed")); 583 *emsg = GNUNET_strdup (_("SKS URI malformed"));
593 return NULL; 584 return NULL;
594 } 585 }
595 ass.fi.file_length = GNUNET_htonll (flen); 586 ass.fi.file_length = GNUNET_htonll (flen);
596 587
597 npos = pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2; 588 npos = pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2;
598 while ((s[npos] != '\0') && (s[npos] != '.')) 589 while ((s[npos] != '\0') && (s[npos] != '.'))
599 npos++; 590 npos++;
600 if (s[npos] == '\0') 591 if (s[npos] == '\0')
601 { 592 {
602 *emsg = GNUNET_strdup (_("SKS URI malformed")); 593 *emsg = GNUNET_strdup (_("SKS URI malformed"));
603 goto ERR; 594 goto ERR;
604 } 595 }
605 npos++; 596 npos++;
606 ret = enc2bin (&s[npos], 597 ret = enc2bin (&s[npos],
607 &ass.peer, 598 &ass.peer,
608 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); 599 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
609 if (ret == -1) 600 if (ret == -1)
610 { 601 {
611 *emsg = GNUNET_strdup (_("SKS URI malformed (could not decode public key)")); 602 *emsg =
612 goto ERR; 603 GNUNET_strdup (_("SKS URI malformed (could not decode public key)"));
613 } 604 goto ERR;
605 }
614 npos += ret; 606 npos += ret;
615 if (s[npos++] != '.') 607 if (s[npos++] != '.')
616 { 608 {
617 *emsg = GNUNET_strdup (_("SKS URI malformed (could not find signature)")); 609 *emsg = GNUNET_strdup (_("SKS URI malformed (could not find signature)"));
618 goto ERR; 610 goto ERR;
619 } 611 }
620 ret = enc2bin (&s[npos], 612 ret = enc2bin (&s[npos], &sig, sizeof (struct GNUNET_CRYPTO_RsaSignature));
621 &sig,
622 sizeof (struct GNUNET_CRYPTO_RsaSignature));
623 if (ret == -1) 613 if (ret == -1)
624 { 614 {
625 *emsg = GNUNET_strdup (_("SKS URI malformed (could not decode signature)")); 615 *emsg = GNUNET_strdup (_("SKS URI malformed (could not decode signature)"));
626 goto ERR; 616 goto ERR;
627 } 617 }
628 npos += ret; 618 npos += ret;
629 if (s[npos++] != '.') 619 if (s[npos++] != '.')
630 { 620 {
631 *emsg = GNUNET_strdup (_("SKS URI malformed")); 621 *emsg = GNUNET_strdup (_("SKS URI malformed"));
632 goto ERR; 622 goto ERR;
633 } 623 }
634 if (1 != SSCANF (&s[npos], "%llu", &exptime)) 624 if (1 != SSCANF (&s[npos], "%llu", &exptime))
635 { 625 {
636 *emsg = GNUNET_strdup (_("SKS URI malformed (could not parse expiration time)")); 626 *emsg =
637 goto ERR; 627 GNUNET_strdup (_
638 } 628 ("SKS URI malformed (could not parse expiration time)"));
639 ass.purpose.size = htonl(sizeof(struct LocUriAssembly)); 629 goto ERR;
640 ass.purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT); 630 }
631 ass.purpose.size = htonl (sizeof (struct LocUriAssembly));
632 ass.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT);
641 et.abs_value = exptime; 633 et.abs_value = exptime;
642 ass.exptime = GNUNET_TIME_absolute_hton (et); 634 ass.exptime = GNUNET_TIME_absolute_hton (et);
643 if (GNUNET_OK != 635 if (GNUNET_OK !=
644 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT, 636 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT,
645 &ass.purpose, 637 &ass.purpose, &sig, &ass.peer))
646 &sig, 638 {
647 &ass.peer)) 639 *emsg =
648 { 640 GNUNET_strdup (_("SKS URI malformed (signature failed validation)"));
649 *emsg = GNUNET_strdup (_("SKS URI malformed (signature failed validation)")); 641 goto ERR;
650 goto ERR; 642 }
651 } 643 uri = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri));
652 uri = GNUNET_malloc (sizeof(struct GNUNET_FS_Uri));
653 uri->type = loc; 644 uri->type = loc;
654 uri->data.loc.fi = ass.fi; 645 uri->data.loc.fi = ass.fi;
655 uri->data.loc.peer = ass.peer; 646 uri->data.loc.peer = ass.peer;
@@ -670,8 +661,7 @@ ERR:
670 * @return NULL on error 661 * @return NULL on error
671 */ 662 */
672struct GNUNET_FS_Uri * 663struct GNUNET_FS_Uri *
673GNUNET_FS_uri_parse (const char *uri, 664GNUNET_FS_uri_parse (const char *uri, char **emsg)
674 char **emsg)
675{ 665{
676 struct GNUNET_FS_Uri *ret; 666 struct GNUNET_FS_Uri *ret;
677 char *msg; 667 char *msg;
@@ -679,10 +669,10 @@ GNUNET_FS_uri_parse (const char *uri,
679 if (NULL == emsg) 669 if (NULL == emsg)
680 emsg = &msg; 670 emsg = &msg;
681 *emsg = NULL; 671 *emsg = NULL;
682 if ( (NULL != (ret = uri_chk_parse (uri, emsg))) || 672 if ((NULL != (ret = uri_chk_parse (uri, emsg))) ||
683 (NULL != (ret = uri_ksk_parse (uri, emsg))) || 673 (NULL != (ret = uri_ksk_parse (uri, emsg))) ||
684 (NULL != (ret = uri_sks_parse (uri, emsg))) || 674 (NULL != (ret = uri_sks_parse (uri, emsg))) ||
685 (NULL != (ret = uri_loc_parse (uri, emsg))) ) 675 (NULL != (ret = uri_loc_parse (uri, emsg))))
686 return ret; 676 return ret;
687 if (NULL == *emsg) 677 if (NULL == *emsg)
688 *emsg = GNUNET_strdup (_("Unrecognized URI type")); 678 *emsg = GNUNET_strdup (_("Unrecognized URI type"));
@@ -697,29 +687,28 @@ GNUNET_FS_uri_parse (const char *uri,
697 * 687 *
698 * @param uri uri to free 688 * @param uri uri to free
699 */ 689 */
700void 690void
701GNUNET_FS_uri_destroy (struct GNUNET_FS_Uri *uri) 691GNUNET_FS_uri_destroy (struct GNUNET_FS_Uri *uri)
702{ 692{
703 unsigned int i; 693 unsigned int i;
704 694
705 GNUNET_assert (uri != NULL); 695 GNUNET_assert (uri != NULL);
706 switch (uri->type) 696 switch (uri->type)
707 { 697 {
708 case ksk: 698 case ksk:
709 for (i = 0; i < uri->data.ksk.keywordCount; i++) 699 for (i = 0; i < uri->data.ksk.keywordCount; i++)
710 GNUNET_free (uri->data.ksk.keywords[i]); 700 GNUNET_free (uri->data.ksk.keywords[i]);
711 GNUNET_array_grow (uri->data.ksk.keywords, uri->data.ksk.keywordCount, 701 GNUNET_array_grow (uri->data.ksk.keywords, uri->data.ksk.keywordCount, 0);
712 0); 702 break;
713 break; 703 case sks:
714 case sks: 704 GNUNET_free (uri->data.sks.identifier);
715 GNUNET_free (uri->data.sks.identifier); 705 break;
716 break; 706 case loc:
717 case loc: 707 break;
718 break; 708 default:
719 default: 709 /* do nothing */
720 /* do nothing */ 710 break;
721 break; 711 }
722 }
723 GNUNET_free (uri); 712 GNUNET_free (uri);
724} 713}
725 714
@@ -729,7 +718,7 @@ GNUNET_FS_uri_destroy (struct GNUNET_FS_Uri *uri)
729 * @param uri ksk uri to get the number of keywords from 718 * @param uri ksk uri to get the number of keywords from
730 * @return 0 if this is not a keyword URI 719 * @return 0 if this is not a keyword URI
731 */ 720 */
732unsigned int 721unsigned int
733GNUNET_FS_uri_ksk_get_keyword_count (const struct GNUNET_FS_Uri *uri) 722GNUNET_FS_uri_ksk_get_keyword_count (const struct GNUNET_FS_Uri *uri)
734{ 723{
735 if (uri->type != ksk) 724 if (uri->type != ksk)
@@ -747,10 +736,10 @@ GNUNET_FS_uri_ksk_get_keyword_count (const struct GNUNET_FS_Uri *uri)
747 * @return -1 if this is not a keyword URI, otherwise number of 736 * @return -1 if this is not a keyword URI, otherwise number of
748 * keywords iterated over until iterator aborted 737 * keywords iterated over until iterator aborted
749 */ 738 */
750int 739int
751GNUNET_FS_uri_ksk_get_keywords (const struct GNUNET_FS_Uri *uri, 740GNUNET_FS_uri_ksk_get_keywords (const struct GNUNET_FS_Uri *uri,
752 GNUNET_FS_KeywordIterator iterator, 741 GNUNET_FS_KeywordIterator iterator,
753 void *iterator_cls) 742 void *iterator_cls)
754{ 743{
755 unsigned int i; 744 unsigned int i;
756 char *keyword; 745 char *keyword;
@@ -760,15 +749,13 @@ GNUNET_FS_uri_ksk_get_keywords (const struct GNUNET_FS_Uri *uri,
760 if (iterator == NULL) 749 if (iterator == NULL)
761 return uri->data.ksk.keywordCount; 750 return uri->data.ksk.keywordCount;
762 for (i = 0; i < uri->data.ksk.keywordCount; i++) 751 for (i = 0; i < uri->data.ksk.keywordCount; i++)
763 { 752 {
764 keyword = uri->data.ksk.keywords[i]; 753 keyword = uri->data.ksk.keywords[i];
765 /* first character of keyword indicates 754 /* first character of keyword indicates
766 if it is mandatory or not */ 755 * if it is mandatory or not */
767 if (GNUNET_OK != iterator (iterator_cls, 756 if (GNUNET_OK != iterator (iterator_cls, &keyword[1], keyword[0] == '+'))
768 &keyword[1], 757 return i;
769 keyword[0] == '+')) 758 }
770 return i;
771 }
772 return i; 759 return i;
773} 760}
774 761
@@ -783,8 +770,7 @@ GNUNET_FS_uri_ksk_get_keywords (const struct GNUNET_FS_Uri *uri,
783 */ 770 */
784void 771void
785GNUNET_FS_uri_ksk_add_keyword (struct GNUNET_FS_Uri *uri, 772GNUNET_FS_uri_ksk_add_keyword (struct GNUNET_FS_Uri *uri,
786 const char *keyword, 773 const char *keyword, int is_mandatory)
787 int is_mandatory)
788{ 774{
789 unsigned int i; 775 unsigned int i;
790 const char *old; 776 const char *old;
@@ -792,17 +778,13 @@ GNUNET_FS_uri_ksk_add_keyword (struct GNUNET_FS_Uri *uri,
792 778
793 GNUNET_assert (uri->type == ksk); 779 GNUNET_assert (uri->type == ksk);
794 for (i = 0; i < uri->data.ksk.keywordCount; i++) 780 for (i = 0; i < uri->data.ksk.keywordCount; i++)
795 { 781 {
796 old = uri->data.ksk.keywords[i]; 782 old = uri->data.ksk.keywords[i];
797 if (0 == strcmp (&old[1], keyword)) 783 if (0 == strcmp (&old[1], keyword))
798 return; 784 return;
799 } 785 }
800 GNUNET_asprintf (&n, 786 GNUNET_asprintf (&n, is_mandatory ? "+%s" : " %s", keyword);
801 is_mandatory ? "+%s" : " %s", 787 GNUNET_array_append (uri->data.ksk.keywords, uri->data.ksk.keywordCount, n);
802 keyword);
803 GNUNET_array_append (uri->data.ksk.keywords,
804 uri->data.ksk.keywordCount,
805 n);
806} 788}
807 789
808 790
@@ -815,25 +797,25 @@ GNUNET_FS_uri_ksk_add_keyword (struct GNUNET_FS_Uri *uri,
815 */ 797 */
816void 798void
817GNUNET_FS_uri_ksk_remove_keyword (struct GNUNET_FS_Uri *uri, 799GNUNET_FS_uri_ksk_remove_keyword (struct GNUNET_FS_Uri *uri,
818 const char *keyword) 800 const char *keyword)
819{ 801{
820 unsigned int i; 802 unsigned int i;
821 char *old; 803 char *old;
822 804
823 GNUNET_assert (uri->type == ksk); 805 GNUNET_assert (uri->type == ksk);
824 for (i = 0; i < uri->data.ksk.keywordCount; i++) 806 for (i = 0; i < uri->data.ksk.keywordCount; i++)
807 {
808 old = uri->data.ksk.keywords[i];
809 if (0 == strcmp (&old[1], keyword))
825 { 810 {
826 old = uri->data.ksk.keywords[i]; 811 uri->data.ksk.keywords[i] =
827 if (0 == strcmp (&old[1], keyword)) 812 uri->data.ksk.keywords[uri->data.ksk.keywordCount - 1];
828 { 813 GNUNET_array_grow (uri->data.ksk.keywords, uri->data.ksk.keywordCount,
829 uri->data.ksk.keywords[i] = uri->data.ksk.keywords[uri->data.ksk.keywordCount-1]; 814 uri->data.ksk.keywordCount - 1);
830 GNUNET_array_grow (uri->data.ksk.keywords, 815 GNUNET_free (old);
831 uri->data.ksk.keywordCount, 816 return;
832 uri->data.ksk.keywordCount - 1);
833 GNUNET_free (old);
834 return;
835 }
836 } 817 }
818 }
837} 819}
838 820
839 821
@@ -846,13 +828,13 @@ GNUNET_FS_uri_ksk_remove_keyword (struct GNUNET_FS_Uri *uri,
846 */ 828 */
847int 829int
848GNUNET_FS_uri_loc_get_peer_identity (const struct GNUNET_FS_Uri *uri, 830GNUNET_FS_uri_loc_get_peer_identity (const struct GNUNET_FS_Uri *uri,
849 struct GNUNET_PeerIdentity * peer) 831 struct GNUNET_PeerIdentity *peer)
850{ 832{
851 if (uri->type != loc) 833 if (uri->type != loc)
852 return GNUNET_SYSERR; 834 return GNUNET_SYSERR;
853 GNUNET_CRYPTO_hash (&uri->data.loc.peer, 835 GNUNET_CRYPTO_hash (&uri->data.loc.peer,
854 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), 836 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
855 &peer->hashPubKey); 837 &peer->hashPubKey);
856 return GNUNET_OK; 838 return GNUNET_OK;
857} 839}
858 840
@@ -867,7 +849,7 @@ struct GNUNET_TIME_Absolute
867GNUNET_FS_uri_loc_get_expiration (const struct GNUNET_FS_Uri *uri) 849GNUNET_FS_uri_loc_get_expiration (const struct GNUNET_FS_Uri *uri)
868{ 850{
869 GNUNET_assert (uri->type == loc); 851 GNUNET_assert (uri->type == loc);
870 return uri->data.loc.expirationTime; 852 return uri->data.loc.expirationTime;
871} 853}
872 854
873 855
@@ -902,11 +884,11 @@ GNUNET_FS_uri_loc_get_uri (const struct GNUNET_FS_Uri *uri)
902 */ 884 */
903struct GNUNET_FS_Uri * 885struct GNUNET_FS_Uri *
904GNUNET_FS_uri_loc_create (const struct GNUNET_FS_Uri *baseUri, 886GNUNET_FS_uri_loc_create (const struct GNUNET_FS_Uri *baseUri,
905 const struct GNUNET_CONFIGURATION_Handle *cfg, 887 const struct GNUNET_CONFIGURATION_Handle *cfg,
906 struct GNUNET_TIME_Absolute expiration_time) 888 struct GNUNET_TIME_Absolute expiration_time)
907{ 889{
908 struct GNUNET_FS_Uri *uri; 890 struct GNUNET_FS_Uri *uri;
909 struct GNUNET_CRYPTO_RsaPrivateKey *my_private_key; 891 struct GNUNET_CRYPTO_RsaPrivateKey *my_private_key;
910 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded my_public_key; 892 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded my_public_key;
911 char *keyfile; 893 char *keyfile;
912 struct LocUriAssembly ass; 894 struct LocUriAssembly ass;
@@ -915,27 +897,24 @@ GNUNET_FS_uri_loc_create (const struct GNUNET_FS_Uri *baseUri,
915 return NULL; 897 return NULL;
916 if (GNUNET_OK != 898 if (GNUNET_OK !=
917 GNUNET_CONFIGURATION_get_value_filename (cfg, 899 GNUNET_CONFIGURATION_get_value_filename (cfg,
918 "GNUNETD", 900 "GNUNETD", "HOSTKEY", &keyfile))
919 "HOSTKEY", &keyfile)) 901 {
920 { 902 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
921 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 903 _("Lacking key configuration settings.\n"));
922 _ 904 return NULL;
923 ("Lacking key configuration settings.\n")); 905 }
924 return NULL;
925 }
926 my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile); 906 my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
927 if (my_private_key == NULL) 907 if (my_private_key == NULL)
928 { 908 {
929 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 909 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
930 _("Could not access hostkey file `%s'.\n"), 910 _("Could not access hostkey file `%s'.\n"), keyfile);
931 keyfile); 911 GNUNET_free (keyfile);
932 GNUNET_free (keyfile); 912 return NULL;
933 return NULL; 913 }
934 }
935 GNUNET_free (keyfile); 914 GNUNET_free (keyfile);
936 GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &my_public_key); 915 GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &my_public_key);
937 ass.purpose.size = htonl(sizeof(struct LocUriAssembly)); 916 ass.purpose.size = htonl (sizeof (struct LocUriAssembly));
938 ass.purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT); 917 ass.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT);
939 ass.exptime = GNUNET_TIME_absolute_hton (expiration_time); 918 ass.exptime = GNUNET_TIME_absolute_hton (expiration_time);
940 ass.fi = baseUri->data.chk; 919 ass.fi = baseUri->data.chk;
941 ass.peer = my_public_key; 920 ass.peer = my_public_key;
@@ -945,9 +924,9 @@ GNUNET_FS_uri_loc_create (const struct GNUNET_FS_Uri *baseUri,
945 uri->data.loc.expirationTime = expiration_time; 924 uri->data.loc.expirationTime = expiration_time;
946 uri->data.loc.peer = my_public_key; 925 uri->data.loc.peer = my_public_key;
947 GNUNET_assert (GNUNET_OK == 926 GNUNET_assert (GNUNET_OK ==
948 GNUNET_CRYPTO_rsa_sign (my_private_key, 927 GNUNET_CRYPTO_rsa_sign (my_private_key,
949 &ass.purpose, 928 &ass.purpose,
950 &uri->data.loc.contentSignature)); 929 &uri->data.loc.contentSignature));
951 GNUNET_CRYPTO_rsa_key_free (my_private_key); 930 GNUNET_CRYPTO_rsa_key_free (my_private_key);
952 return uri; 931 return uri;
953} 932}
@@ -963,19 +942,15 @@ GNUNET_FS_uri_loc_create (const struct GNUNET_FS_Uri *baseUri,
963 */ 942 */
964struct GNUNET_FS_Uri * 943struct GNUNET_FS_Uri *
965GNUNET_FS_uri_sks_create (struct GNUNET_FS_Namespace *ns, 944GNUNET_FS_uri_sks_create (struct GNUNET_FS_Namespace *ns,
966 const char *id, 945 const char *id, char **emsg)
967 char **emsg)
968{ 946{
969 struct GNUNET_FS_Uri *ns_uri; 947 struct GNUNET_FS_Uri *ns_uri;
970 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pk; 948 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pk;
971 949
972 ns_uri = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri)); 950 ns_uri = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri));
973 ns_uri->type = sks; 951 ns_uri->type = sks;
974 GNUNET_CRYPTO_rsa_key_get_public (ns->key, 952 GNUNET_CRYPTO_rsa_key_get_public (ns->key, &pk);
975 &pk); 953 GNUNET_CRYPTO_hash (&pk, sizeof (pk), &ns_uri->data.sks.namespace);
976 GNUNET_CRYPTO_hash (&pk,
977 sizeof (pk),
978 &ns_uri->data.sks.namespace);
979 ns_uri->data.sks.identifier = GNUNET_strdup (id); 954 ns_uri->data.sks.identifier = GNUNET_strdup (id);
980 return ns_uri; 955 return ns_uri;
981} 956}
@@ -989,11 +964,10 @@ GNUNET_FS_uri_sks_create (struct GNUNET_FS_Namespace *ns,
989 * @return an FS URI for the given namespace and identifier 964 * @return an FS URI for the given namespace and identifier
990 */ 965 */
991struct GNUNET_FS_Uri * 966struct GNUNET_FS_Uri *
992GNUNET_FS_uri_sks_create_from_nsid (GNUNET_HashCode *nsid, 967GNUNET_FS_uri_sks_create_from_nsid (GNUNET_HashCode * nsid, const char *id)
993 const char *id)
994{ 968{
995 struct GNUNET_FS_Uri *ns_uri; 969 struct GNUNET_FS_Uri *ns_uri;
996 970
997 ns_uri = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri)); 971 ns_uri = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri));
998 ns_uri->type = sks; 972 ns_uri->type = sks;
999 ns_uri->data.sks.namespace = *nsid; 973 ns_uri->data.sks.namespace = *nsid;
@@ -1019,60 +993,60 @@ canonicalize_keyword (const char *in)
1019 wpos = ret; 993 wpos = ret;
1020 rpos = in; 994 rpos = in;
1021 while ('\0' != *rpos) 995 while ('\0' != *rpos)
996 {
997 switch (tolower ((unsigned char) *rpos))
1022 { 998 {
1023 switch (tolower( (unsigned char) *rpos)) 999 case 'a':
1024 { 1000 case 'e':
1025 case 'a': 1001 case 'i':
1026 case 'e': 1002 case 'o':
1027 case 'i': 1003 case 'u':
1028 case 'o': 1004 case ' ':
1029 case 'u': 1005 case '\t':
1030 case ' ': 1006 case '\n':
1031 case '\t': 1007 case '\r':
1032 case '\n': 1008 /* skip characters listed above */
1033 case '\r': 1009 break;
1034 /* skip characters listed above */ 1010 case 'b':
1035 break; 1011 case 'c':
1036 case 'b': 1012 case 'd':
1037 case 'c': 1013 case 'f':
1038 case 'd': 1014 case 'g':
1039 case 'f': 1015 case 'h':
1040 case 'g': 1016 case 'j':
1041 case 'h': 1017 case 'k':
1042 case 'j': 1018 case 'l':
1043 case 'k': 1019 case 'm':
1044 case 'l': 1020 case 'n':
1045 case 'm': 1021 case 'p':
1046 case 'n': 1022 case 'r':
1047 case 'p': 1023 case 's':
1048 case 'r': 1024 case 't':
1049 case 's': 1025 case 'v':
1050 case 't': 1026 case 'w':
1051 case 'v': 1027 case 'x':
1052 case 'w': 1028 case 'y':
1053 case 'x': 1029 case 'z':
1054 case 'y': 1030 /* convert characters listed above to lower case */
1055 case 'z': 1031 *wpos = tolower ((unsigned char) *rpos);
1056 /* convert characters listed above to lower case */ 1032 wpos++;
1057 *wpos = tolower( (unsigned char)*rpos); 1033 break;
1058 wpos++; 1034 case '!':
1059 break; 1035 case '.':
1060 case '!': 1036 case '?':
1061 case '.': 1037 case '-':
1062 case '?': 1038 /* keep characters listed above without changes */
1063 case '-': 1039 *wpos = *rpos;
1064 /* keep characters listed above without changes */ 1040 wpos++;
1065 *wpos = *rpos; 1041 break;
1066 wpos++; 1042 default:
1067 break; 1043 /* replace characters listed above with '_' */
1068 default: 1044 *wpos = '_';
1069 /* replace characters listed above with '_' */ 1045 wpos++;
1070 *wpos = '_'; 1046 break;
1071 wpos++;
1072 break;
1073 }
1074 rpos++;
1075 } 1047 }
1048 rpos++;
1049 }
1076 return ret; 1050 return ret;
1077} 1051}
1078 1052
@@ -1094,10 +1068,10 @@ GNUNET_FS_uri_ksk_canonicalize (const struct GNUNET_FS_Uri *uri)
1094 char **kl; 1068 char **kl;
1095 1069
1096 kc = uri->data.ksk.keywordCount; 1070 kc = uri->data.ksk.keywordCount;
1097 kl = GNUNET_malloc (kc*sizeof(char*)); 1071 kl = GNUNET_malloc (kc * sizeof (char *));
1098 for (i=0;i<kc;i++) 1072 for (i = 0; i < kc; i++)
1099 kl[i] = canonicalize_keyword (uri->data.ksk.keywords[i]); 1073 kl[i] = canonicalize_keyword (uri->data.ksk.keywords[i]);
1100 ret = GNUNET_malloc (sizeof(struct GNUNET_FS_Uri)); 1074 ret = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri));
1101 ret->type = ksk; 1075 ret->type = ksk;
1102 ret->data.ksk.keywordCount = kc; 1076 ret->data.ksk.keywordCount = kc;
1103 ret->data.ksk.keywords = kl; 1077 ret->data.ksk.keywords = kl;
@@ -1116,7 +1090,7 @@ GNUNET_FS_uri_ksk_canonicalize (const struct GNUNET_FS_Uri *uri)
1116 */ 1090 */
1117struct GNUNET_FS_Uri * 1091struct GNUNET_FS_Uri *
1118GNUNET_FS_uri_ksk_merge (const struct GNUNET_FS_Uri *u1, 1092GNUNET_FS_uri_ksk_merge (const struct GNUNET_FS_Uri *u1,
1119 const struct GNUNET_FS_Uri *u2) 1093 const struct GNUNET_FS_Uri *u2)
1120{ 1094{
1121 struct GNUNET_FS_Uri *ret; 1095 struct GNUNET_FS_Uri *ret;
1122 unsigned int kc; 1096 unsigned int kc;
@@ -1126,39 +1100,37 @@ GNUNET_FS_uri_ksk_merge (const struct GNUNET_FS_Uri *u1,
1126 const char *kp; 1100 const char *kp;
1127 char **kl; 1101 char **kl;
1128 1102
1129 if ( (u1 == NULL) && (u2 == NULL) ) 1103 if ((u1 == NULL) && (u2 == NULL))
1130 return NULL; 1104 return NULL;
1131 if (u1 == NULL) 1105 if (u1 == NULL)
1132 return GNUNET_FS_uri_dup (u2); 1106 return GNUNET_FS_uri_dup (u2);
1133 if (u2 == NULL) 1107 if (u2 == NULL)
1134 return GNUNET_FS_uri_dup (u1); 1108 return GNUNET_FS_uri_dup (u1);
1135 if ( (u1->type != ksk) || 1109 if ((u1->type != ksk) || (u2->type != ksk))
1136 (u2->type != ksk) ) 1110 {
1137 { 1111 GNUNET_break (0);
1138 GNUNET_break (0); 1112 return NULL;
1139 return NULL; 1113 }
1140 }
1141 kc = u1->data.ksk.keywordCount; 1114 kc = u1->data.ksk.keywordCount;
1142 kl = GNUNET_malloc ((kc+u2->data.ksk.keywordCount)*sizeof(char*)); 1115 kl = GNUNET_malloc ((kc + u2->data.ksk.keywordCount) * sizeof (char *));
1143 for (i=0;i<u1->data.ksk.keywordCount;i++) 1116 for (i = 0; i < u1->data.ksk.keywordCount; i++)
1144 kl[i] = GNUNET_strdup (u1->data.ksk.keywords[i]); 1117 kl[i] = GNUNET_strdup (u1->data.ksk.keywords[i]);
1145 for (i=0;i<u2->data.ksk.keywordCount;i++) 1118 for (i = 0; i < u2->data.ksk.keywordCount; i++)
1146 { 1119 {
1147 kp = u2->data.ksk.keywords[i]; 1120 kp = u2->data.ksk.keywords[i];
1148 found = 0; 1121 found = 0;
1149 for (j=0;j<u1->data.ksk.keywordCount;j++) 1122 for (j = 0; j < u1->data.ksk.keywordCount; j++)
1150 if (0 == strcmp(kp + 1, 1123 if (0 == strcmp (kp + 1, kl[j] + 1))
1151 kl[j]+1)) 1124 {
1152 { 1125 found = 1;
1153 found = 1; 1126 if (kp[0] == '+')
1154 if (kp[0] == '+') 1127 kl[j][0] = '+';
1155 kl[j][0] = '+'; 1128 break;
1156 break; 1129 }
1157 } 1130 if (0 == found)
1158 if (0 == found) 1131 kl[kc++] = GNUNET_strdup (kp);
1159 kl[kc++] = GNUNET_strdup (kp); 1132 }
1160 } 1133 ret = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri));
1161 ret = GNUNET_malloc (sizeof(struct GNUNET_FS_Uri));
1162 ret->type = ksk; 1134 ret->type = ksk;
1163 ret->data.ksk.keywordCount = kc; 1135 ret->data.ksk.keywordCount = kc;
1164 ret->data.ksk.keywords = kl; 1136 ret->data.ksk.keywords = kl;
@@ -1183,33 +1155,33 @@ GNUNET_FS_uri_dup (const struct GNUNET_FS_Uri *uri)
1183 ret = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri)); 1155 ret = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri));
1184 memcpy (ret, uri, sizeof (struct GNUNET_FS_Uri)); 1156 memcpy (ret, uri, sizeof (struct GNUNET_FS_Uri));
1185 switch (ret->type) 1157 switch (ret->type)
1158 {
1159 case ksk:
1160 if (ret->data.ksk.keywordCount >=
1161 GNUNET_MAX_MALLOC_CHECKED / sizeof (char *))
1186 { 1162 {
1187 case ksk: 1163 GNUNET_break (0);
1188 if (ret->data.ksk.keywordCount >= GNUNET_MAX_MALLOC_CHECKED / sizeof (char*)) 1164 GNUNET_free (ret);
1189 { 1165 return NULL;
1190 GNUNET_break (0);
1191 GNUNET_free (ret);
1192 return NULL;
1193 }
1194 if (ret->data.ksk.keywordCount > 0)
1195 {
1196 ret->data.ksk.keywords
1197 = GNUNET_malloc (ret->data.ksk.keywordCount * sizeof (char *));
1198 for (i = 0; i < ret->data.ksk.keywordCount; i++)
1199 ret->data.ksk.keywords[i] =
1200 GNUNET_strdup (uri->data.ksk.keywords[i]);
1201 }
1202 else
1203 ret->data.ksk.keywords = NULL; /* just to be sure */
1204 break;
1205 case sks:
1206 ret->data.sks.identifier = GNUNET_strdup (uri->data.sks.identifier);
1207 break;
1208 case loc:
1209 break;
1210 default:
1211 break;
1212 } 1166 }
1167 if (ret->data.ksk.keywordCount > 0)
1168 {
1169 ret->data.ksk.keywords
1170 = GNUNET_malloc (ret->data.ksk.keywordCount * sizeof (char *));
1171 for (i = 0; i < ret->data.ksk.keywordCount; i++)
1172 ret->data.ksk.keywords[i] = GNUNET_strdup (uri->data.ksk.keywords[i]);
1173 }
1174 else
1175 ret->data.ksk.keywords = NULL; /* just to be sure */
1176 break;
1177 case sks:
1178 ret->data.sks.identifier = GNUNET_strdup (uri->data.sks.identifier);
1179 break;
1180 case loc:
1181 break;
1182 default:
1183 break;
1184 }
1213 return ret; 1185 return ret;
1214} 1186}
1215 1187
@@ -1232,8 +1204,7 @@ GNUNET_FS_uri_dup (const struct GNUNET_FS_Uri *uri)
1232 * if keywords is not legal (i.e. empty). 1204 * if keywords is not legal (i.e. empty).
1233 */ 1205 */
1234struct GNUNET_FS_Uri * 1206struct GNUNET_FS_Uri *
1235GNUNET_FS_uri_ksk_create (const char *keywords, 1207GNUNET_FS_uri_ksk_create (const char *keywords, char **emsg)
1236 char **emsg)
1237{ 1208{
1238 char **keywordarr; 1209 char **keywordarr;
1239 unsigned int num_Words; 1210 unsigned int num_Words;
@@ -1244,67 +1215,67 @@ GNUNET_FS_uri_ksk_create (const char *keywords,
1244 int saw_quote; 1215 int saw_quote;
1245 1216
1246 if (keywords == NULL) 1217 if (keywords == NULL)
1247 { 1218 {
1248 *emsg = GNUNET_strdup (_("No keywords specified!\n")); 1219 *emsg = GNUNET_strdup (_("No keywords specified!\n"));
1249 GNUNET_break (0); 1220 GNUNET_break (0);
1250 return NULL; 1221 return NULL;
1251 } 1222 }
1252 searchString = GNUNET_strdup (keywords); 1223 searchString = GNUNET_strdup (keywords);
1253 num_Words = 0; 1224 num_Words = 0;
1254 inWord = 0; 1225 inWord = 0;
1255 saw_quote = 0; 1226 saw_quote = 0;
1256 pos = searchString; 1227 pos = searchString;
1257 while ('\0' != *pos) 1228 while ('\0' != *pos)
1229 {
1230 if ((saw_quote == 0) && (isspace ((unsigned char) *pos)))
1258 { 1231 {
1259 if ((saw_quote == 0) && (isspace ((unsigned char) *pos))) 1232 inWord = 0;
1260 {
1261 inWord = 0;
1262 }
1263 else if (0 == inWord)
1264 {
1265 inWord = 1;
1266 ++num_Words;
1267 }
1268 if ('"' == *pos)
1269 saw_quote = (saw_quote + 1) % 2;
1270 pos++;
1271 } 1233 }
1272 if (num_Words == 0) 1234 else if (0 == inWord)
1273 { 1235 {
1274 GNUNET_free (searchString); 1236 inWord = 1;
1275 *emsg = GNUNET_strdup (_("No keywords specified!\n")); 1237 ++num_Words;
1276 return NULL;
1277 } 1238 }
1239 if ('"' == *pos)
1240 saw_quote = (saw_quote + 1) % 2;
1241 pos++;
1242 }
1243 if (num_Words == 0)
1244 {
1245 GNUNET_free (searchString);
1246 *emsg = GNUNET_strdup (_("No keywords specified!\n"));
1247 return NULL;
1248 }
1278 if (saw_quote != 0) 1249 if (saw_quote != 0)
1279 { 1250 {
1280 GNUNET_free (searchString); 1251 GNUNET_free (searchString);
1281 *emsg = GNUNET_strdup (_("Number of double-quotes not balanced!\n")); 1252 *emsg = GNUNET_strdup (_("Number of double-quotes not balanced!\n"));
1282 return NULL; 1253 return NULL;
1283 } 1254 }
1284 keywordarr = GNUNET_malloc (num_Words * sizeof (char *)); 1255 keywordarr = GNUNET_malloc (num_Words * sizeof (char *));
1285 num_Words = 0; 1256 num_Words = 0;
1286 inWord = 0; 1257 inWord = 0;
1287 pos = searchString; 1258 pos = searchString;
1288 while ('\0' != *pos) 1259 while ('\0' != *pos)
1260 {
1261 if ((saw_quote == 0) && (isspace ((unsigned char) *pos)))
1289 { 1262 {
1290 if ((saw_quote == 0) && (isspace ( (unsigned char) *pos))) 1263 inWord = 0;
1291 { 1264 *pos = '\0';
1292 inWord = 0;
1293 *pos = '\0';
1294 }
1295 else if (0 == inWord)
1296 {
1297 keywordarr[num_Words] = pos;
1298 inWord = 1;
1299 ++num_Words;
1300 }
1301 if ('"' == *pos)
1302 saw_quote = (saw_quote + 1) % 2;
1303 pos++;
1304 } 1265 }
1266 else if (0 == inWord)
1267 {
1268 keywordarr[num_Words] = pos;
1269 inWord = 1;
1270 ++num_Words;
1271 }
1272 if ('"' == *pos)
1273 saw_quote = (saw_quote + 1) % 2;
1274 pos++;
1275 }
1305 uri = 1276 uri =
1306 GNUNET_FS_uri_ksk_create_from_args (num_Words, 1277 GNUNET_FS_uri_ksk_create_from_args (num_Words,
1307 (const char **) keywordarr); 1278 (const char **) keywordarr);
1308 GNUNET_free (keywordarr); 1279 GNUNET_free (keywordarr);
1309 GNUNET_free (searchString); 1280 GNUNET_free (searchString);
1310 return uri; 1281 return uri;
@@ -1329,8 +1300,7 @@ GNUNET_FS_uri_ksk_create (const char *keywords,
1329 * if keywords is not legal (i.e. empty). 1300 * if keywords is not legal (i.e. empty).
1330 */ 1301 */
1331struct GNUNET_FS_Uri * 1302struct GNUNET_FS_Uri *
1332GNUNET_FS_uri_ksk_create_from_args (unsigned int argc, 1303GNUNET_FS_uri_ksk_create_from_args (unsigned int argc, const char **argv)
1333 const char **argv)
1334{ 1304{
1335 unsigned int i; 1305 unsigned int i;
1336 struct GNUNET_FS_Uri *uri; 1306 struct GNUNET_FS_Uri *uri;
@@ -1343,12 +1313,13 @@ GNUNET_FS_uri_ksk_create_from_args (unsigned int argc,
1343 if (argc == 0) 1313 if (argc == 0)
1344 return NULL; 1314 return NULL;
1345 /* allow URI to be given as one and only keyword and 1315 /* allow URI to be given as one and only keyword and
1346 handle accordingly */ 1316 * handle accordingly */
1347 emsg = NULL; 1317 emsg = NULL;
1348 if ( (argc == 1) && 1318 if ((argc == 1) &&
1349 (strlen(argv[0]) > strlen(GNUNET_FS_URI_PREFIX)) && 1319 (strlen (argv[0]) > strlen (GNUNET_FS_URI_PREFIX)) &&
1350 (0 == strncmp(argv[0], GNUNET_FS_URI_PREFIX, strlen(GNUNET_FS_URI_PREFIX)) ) && 1320 (0 ==
1351 (NULL != (uri = GNUNET_FS_uri_parse(argv[0], &emsg)) ) ) 1321 strncmp (argv[0], GNUNET_FS_URI_PREFIX, strlen (GNUNET_FS_URI_PREFIX)))
1322 && (NULL != (uri = GNUNET_FS_uri_parse (argv[0], &emsg))))
1352 return uri; 1323 return uri;
1353 GNUNET_free_non_null (emsg); 1324 GNUNET_free_non_null (emsg);
1354 uri = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri)); 1325 uri = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri));
@@ -1356,24 +1327,24 @@ GNUNET_FS_uri_ksk_create_from_args (unsigned int argc,
1356 uri->data.ksk.keywordCount = argc; 1327 uri->data.ksk.keywordCount = argc;
1357 uri->data.ksk.keywords = GNUNET_malloc (argc * sizeof (char *)); 1328 uri->data.ksk.keywords = GNUNET_malloc (argc * sizeof (char *));
1358 for (i = 0; i < argc; i++) 1329 for (i = 0; i < argc; i++)
1330 {
1331 keyword = argv[i];
1332 if (keyword[0] == '+')
1333 val = GNUNET_strdup (keyword);
1334 else
1335 GNUNET_asprintf (&val, " %s", keyword);
1336 r = val;
1337 w = val;
1338 while ('\0' != *r)
1359 { 1339 {
1360 keyword = argv[i]; 1340 if ('"' == *r)
1361 if (keyword[0] == '+') 1341 r++;
1362 val = GNUNET_strdup (keyword);
1363 else 1342 else
1364 GNUNET_asprintf (&val, " %s", keyword); 1343 *(w++) = *(r++);
1365 r = val;
1366 w = val;
1367 while ('\0' != *r)
1368 {
1369 if ('"' == *r)
1370 r++;
1371 else
1372 *(w++) = *(r++);
1373 }
1374 *w = '\0';
1375 uri->data.ksk.keywords[i] = val;
1376 } 1344 }
1345 *w = '\0';
1346 uri->data.ksk.keywords[i] = val;
1347 }
1377 return uri; 1348 return uri;
1378} 1349}
1379 1350
@@ -1385,9 +1356,9 @@ GNUNET_FS_uri_ksk_create_from_args (unsigned int argc,
1385 * @param u2 the other URI 1356 * @param u2 the other URI
1386 * @return GNUNET_YES if the URIs are equal 1357 * @return GNUNET_YES if the URIs are equal
1387 */ 1358 */
1388int 1359int
1389GNUNET_FS_uri_test_equal (const struct GNUNET_FS_Uri *u1, 1360GNUNET_FS_uri_test_equal (const struct GNUNET_FS_Uri *u1,
1390 const struct GNUNET_FS_Uri *u2) 1361 const struct GNUNET_FS_Uri *u2)
1391{ 1362{
1392 int ret; 1363 int ret;
1393 unsigned int i; 1364 unsigned int i;
@@ -1398,53 +1369,50 @@ GNUNET_FS_uri_test_equal (const struct GNUNET_FS_Uri *u1,
1398 if (u1->type != u2->type) 1369 if (u1->type != u2->type)
1399 return GNUNET_NO; 1370 return GNUNET_NO;
1400 switch (u1->type) 1371 switch (u1->type)
1401 { 1372 {
1402 case chk: 1373 case chk:
1403 if (0 == memcmp (&u1->data.chk, 1374 if (0 == memcmp (&u1->data.chk,
1404 &u2->data.chk, 1375 &u2->data.chk, sizeof (struct FileIdentifier)))
1405 sizeof (struct FileIdentifier))) 1376 return GNUNET_YES;
1406 return GNUNET_YES; 1377 return GNUNET_NO;
1407 return GNUNET_NO; 1378 case sks:
1408 case sks: 1379 if ((0 == memcmp (&u1->data.sks.namespace,
1409 if ((0 == memcmp (&u1->data.sks.namespace, 1380 &u2->data.sks.namespace,
1410 &u2->data.sks.namespace, 1381 sizeof (GNUNET_HashCode))) &&
1411 sizeof (GNUNET_HashCode))) && 1382 (0 == strcmp (u1->data.sks.identifier, u2->data.sks.identifier)))
1412 (0 == strcmp (u1->data.sks.identifier, 1383
1413 u2->data.sks.identifier))) 1384 return GNUNET_YES;
1414 1385 return GNUNET_NO;
1415 return GNUNET_YES; 1386 case ksk:
1387 if (u1->data.ksk.keywordCount != u2->data.ksk.keywordCount)
1416 return GNUNET_NO; 1388 return GNUNET_NO;
1417 case ksk: 1389 for (i = 0; i < u1->data.ksk.keywordCount; i++)
1418 if (u1->data.ksk.keywordCount != u2->data.ksk.keywordCount) 1390 {
1419 return GNUNET_NO; 1391 ret = GNUNET_NO;
1420 for (i = 0; i < u1->data.ksk.keywordCount; i++) 1392 for (j = 0; j < u2->data.ksk.keywordCount; j++)
1393 {
1394 if (0 == strcmp (u1->data.ksk.keywords[i], u2->data.ksk.keywords[j]))
1421 { 1395 {
1422 ret = GNUNET_NO; 1396 ret = GNUNET_YES;
1423 for (j = 0; j < u2->data.ksk.keywordCount; j++) 1397 break;
1424 {
1425 if (0 == strcmp (u1->data.ksk.keywords[i],
1426 u2->data.ksk.keywords[j]))
1427 {
1428 ret = GNUNET_YES;
1429 break;
1430 }
1431 }
1432 if (ret == GNUNET_NO)
1433 return GNUNET_NO;
1434 } 1398 }
1435 return GNUNET_YES; 1399 }
1436 case loc: 1400 if (ret == GNUNET_NO)
1437 if (memcmp (&u1->data.loc,
1438 &u2->data.loc,
1439 sizeof (struct FileIdentifier) +
1440 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) +
1441 sizeof (struct GNUNET_TIME_Absolute) +
1442 sizeof (unsigned short) + sizeof (unsigned short)) != 0)
1443 return GNUNET_NO; 1401 return GNUNET_NO;
1444 return GNUNET_YES;
1445 default:
1446 return GNUNET_NO;
1447 } 1402 }
1403 return GNUNET_YES;
1404 case loc:
1405 if (memcmp (&u1->data.loc,
1406 &u2->data.loc,
1407 sizeof (struct FileIdentifier) +
1408 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) +
1409 sizeof (struct GNUNET_TIME_Absolute) +
1410 sizeof (unsigned short) + sizeof (unsigned short)) != 0)
1411 return GNUNET_NO;
1412 return GNUNET_YES;
1413 default:
1414 return GNUNET_NO;
1415 }
1448} 1416}
1449 1417
1450 1418
@@ -1469,15 +1437,15 @@ GNUNET_FS_uri_test_sks (const struct GNUNET_FS_Uri *uri)
1469 * @param nsid where to store the ID of the namespace 1437 * @param nsid where to store the ID of the namespace
1470 * @return GNUNET_OK on success 1438 * @return GNUNET_OK on success
1471 */ 1439 */
1472int 1440int
1473GNUNET_FS_uri_sks_get_namespace (const struct GNUNET_FS_Uri *uri, 1441GNUNET_FS_uri_sks_get_namespace (const struct GNUNET_FS_Uri *uri,
1474 GNUNET_HashCode * nsid) 1442 GNUNET_HashCode * nsid)
1475{ 1443{
1476 if (! GNUNET_FS_uri_test_sks (uri)) 1444 if (!GNUNET_FS_uri_test_sks (uri))
1477 { 1445 {
1478 GNUNET_break (0); 1446 GNUNET_break (0);
1479 return GNUNET_SYSERR; 1447 return GNUNET_SYSERR;
1480 } 1448 }
1481 *nsid = uri->data.sks.namespace; 1449 *nsid = uri->data.sks.namespace;
1482 return GNUNET_OK; 1450 return GNUNET_OK;
1483} 1451}
@@ -1493,10 +1461,10 @@ char *
1493GNUNET_FS_uri_sks_get_content_id (const struct GNUNET_FS_Uri *uri) 1461GNUNET_FS_uri_sks_get_content_id (const struct GNUNET_FS_Uri *uri)
1494{ 1462{
1495 if (!GNUNET_FS_uri_test_sks (uri)) 1463 if (!GNUNET_FS_uri_test_sks (uri))
1496 { 1464 {
1497 GNUNET_break (0); 1465 GNUNET_break (0);
1498 return NULL; 1466 return NULL;
1499 } 1467 }
1500 return GNUNET_strdup (uri->data.sks.identifier); 1468 return GNUNET_strdup (uri->data.sks.identifier);
1501} 1469}
1502 1470
@@ -1511,7 +1479,7 @@ GNUNET_FS_uri_sks_get_content_id (const struct GNUNET_FS_Uri *uri)
1511 */ 1479 */
1512char * 1480char *
1513GNUNET_FS_uri_sks_to_string_fancy (struct GNUNET_CONFIGURATION_Handle *cfg, 1481GNUNET_FS_uri_sks_to_string_fancy (struct GNUNET_CONFIGURATION_Handle *cfg,
1514 const struct GNUNET_FS_Uri *uri) 1482 const struct GNUNET_FS_Uri *uri)
1515{ 1483{
1516 char *ret; 1484 char *ret;
1517 char *name; 1485 char *name;
@@ -1521,10 +1489,7 @@ GNUNET_FS_uri_sks_to_string_fancy (struct GNUNET_CONFIGURATION_Handle *cfg,
1521 name = GNUNET_PSEUDONYM_id_to_name (cfg, &uri->data.sks.namespace); 1489 name = GNUNET_PSEUDONYM_id_to_name (cfg, &uri->data.sks.namespace);
1522 if (name == NULL) 1490 if (name == NULL)
1523 return GNUNET_FS_uri_to_string (uri); 1491 return GNUNET_FS_uri_to_string (uri);
1524 GNUNET_asprintf (&ret, 1492 GNUNET_asprintf (&ret, "%s: %s", name, uri->data.sks.identifier);
1525 "%s: %s",
1526 name,
1527 uri->data.sks.identifier);
1528 GNUNET_free (name); 1493 GNUNET_free (name);
1529 return ret; 1494 return ret;
1530} 1495}
@@ -1536,17 +1501,17 @@ GNUNET_FS_uri_sks_to_string_fancy (struct GNUNET_CONFIGURATION_Handle *cfg,
1536 * @param uri the uri 1501 * @param uri the uri
1537 * @return GNUNET_YES if this is a KSK uri 1502 * @return GNUNET_YES if this is a KSK uri
1538 */ 1503 */
1539int 1504int
1540GNUNET_FS_uri_test_ksk (const struct GNUNET_FS_Uri *uri) 1505GNUNET_FS_uri_test_ksk (const struct GNUNET_FS_Uri *uri)
1541{ 1506{
1542#if EXTRA_CHECKS 1507#if EXTRA_CHECKS
1543 unsigned int i; 1508 unsigned int i;
1544 1509
1545 if (uri->type == ksk) 1510 if (uri->type == ksk)
1546 { 1511 {
1547 for (i = uri->data.ksk.keywordCount - 1; i >= 0; i--) 1512 for (i = uri->data.ksk.keywordCount - 1; i >= 0; i--)
1548 GNUNET_assert (uri->data.ksk.keywords[i] != NULL); 1513 GNUNET_assert (uri->data.ksk.keywords[i] != NULL);
1549 } 1514 }
1550#endif 1515#endif
1551 return uri->type == ksk; 1516 return uri->type == ksk;
1552} 1517}
@@ -1558,7 +1523,7 @@ GNUNET_FS_uri_test_ksk (const struct GNUNET_FS_Uri *uri)
1558 * @param uri the uri to check 1523 * @param uri the uri to check
1559 * @return GNUNET_YES if this is a CHK uri 1524 * @return GNUNET_YES if this is a CHK uri
1560 */ 1525 */
1561int 1526int
1562GNUNET_FS_uri_test_chk (const struct GNUNET_FS_Uri *uri) 1527GNUNET_FS_uri_test_chk (const struct GNUNET_FS_Uri *uri)
1563{ 1528{
1564 return uri->type == chk; 1529 return uri->type == chk;
@@ -1572,18 +1537,18 @@ GNUNET_FS_uri_test_chk (const struct GNUNET_FS_Uri *uri)
1572 * @param uri the CHK URI to inspect 1537 * @param uri the CHK URI to inspect
1573 * @return size of the file as specified in the CHK URI 1538 * @return size of the file as specified in the CHK URI
1574 */ 1539 */
1575uint64_t 1540uint64_t
1576GNUNET_FS_uri_chk_get_file_size (const struct GNUNET_FS_Uri *uri) 1541GNUNET_FS_uri_chk_get_file_size (const struct GNUNET_FS_Uri * uri)
1577{ 1542{
1578 switch (uri->type) 1543 switch (uri->type)
1579 { 1544 {
1580 case chk: 1545 case chk:
1581 return GNUNET_ntohll (uri->data.chk.file_length); 1546 return GNUNET_ntohll (uri->data.chk.file_length);
1582 case loc: 1547 case loc:
1583 return GNUNET_ntohll (uri->data.loc.fi.file_length); 1548 return GNUNET_ntohll (uri->data.loc.fi.file_length);
1584 default: 1549 default:
1585 GNUNET_assert (0); 1550 GNUNET_assert (0);
1586 } 1551 }
1587 return 0; /* unreachable */ 1552 return 0; /* unreachable */
1588} 1553}
1589 1554
@@ -1594,7 +1559,7 @@ GNUNET_FS_uri_chk_get_file_size (const struct GNUNET_FS_Uri *uri)
1594 * @param uri the uri to check 1559 * @param uri the uri to check
1595 * @return GNUNET_YES if this is a LOC uri 1560 * @return GNUNET_YES if this is a LOC uri
1596 */ 1561 */
1597int 1562int
1598GNUNET_FS_uri_test_loc (const struct GNUNET_FS_Uri *uri) 1563GNUNET_FS_uri_test_loc (const struct GNUNET_FS_Uri *uri)
1599{ 1564{
1600 return uri->type == loc; 1565 return uri->type == loc;
@@ -1620,26 +1585,23 @@ GNUNET_FS_uri_test_loc (const struct GNUNET_FS_Uri *uri)
1620 */ 1585 */
1621static int 1586static int
1622gather_uri_data (void *cls, 1587gather_uri_data (void *cls,
1623 const char *plugin_name, 1588 const char *plugin_name,
1624 enum EXTRACTOR_MetaType type, 1589 enum EXTRACTOR_MetaType type,
1625 enum EXTRACTOR_MetaFormat format, 1590 enum EXTRACTOR_MetaFormat format,
1626 const char *data_mime_type, 1591 const char *data_mime_type, const char *data, size_t data_len)
1627 const char *data,
1628 size_t data_len)
1629{ 1592{
1630 struct GNUNET_FS_Uri *uri = cls; 1593 struct GNUNET_FS_Uri *uri = cls;
1631 char *nkword; 1594 char *nkword;
1632 int j; 1595 int j;
1633 1596
1634 if ( (format != EXTRACTOR_METAFORMAT_UTF8) && 1597 if ((format != EXTRACTOR_METAFORMAT_UTF8) &&
1635 (format != EXTRACTOR_METAFORMAT_C_STRING) ) 1598 (format != EXTRACTOR_METAFORMAT_C_STRING))
1636 return 0; 1599 return 0;
1637 for (j = uri->data.ksk.keywordCount - 1; j >= 0; j--) 1600 for (j = uri->data.ksk.keywordCount - 1; j >= 0; j--)
1638 if (0 == strcmp (&uri->data.ksk.keywords[j][1], data)) 1601 if (0 == strcmp (&uri->data.ksk.keywords[j][1], data))
1639 return GNUNET_OK; 1602 return GNUNET_OK;
1640 GNUNET_asprintf (&nkword, 1603 GNUNET_asprintf (&nkword, " %s", /* space to mark as 'non mandatory' */
1641 " %s", /* space to mark as 'non mandatory' */ 1604 data);
1642 data);
1643 uri->data.ksk.keywords[uri->data.ksk.keywordCount++] = nkword; 1605 uri->data.ksk.keywords[uri->data.ksk.keywordCount++] = nkword;
1644 return 0; 1606 return 0;
1645} 1607}
@@ -1654,7 +1616,8 @@ gather_uri_data (void *cls,
1654 * @return NULL on error, otherwise a KSK URI 1616 * @return NULL on error, otherwise a KSK URI
1655 */ 1617 */
1656struct GNUNET_FS_Uri * 1618struct GNUNET_FS_Uri *
1657GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_CONTAINER_MetaData *md) 1619GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_CONTAINER_MetaData
1620 *md)
1658{ 1621{
1659 struct GNUNET_FS_Uri *ret; 1622 struct GNUNET_FS_Uri *ret;
1660 int ent; 1623 int ent;
@@ -1665,11 +1628,10 @@ GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_CONTAINER_MetaData
1665 ret->type = ksk; 1628 ret->type = ksk;
1666 ent = GNUNET_CONTAINER_meta_data_iterate (md, NULL, NULL); 1629 ent = GNUNET_CONTAINER_meta_data_iterate (md, NULL, NULL);
1667 if (ent > 0) 1630 if (ent > 0)
1668 { 1631 {
1669 ret->data.ksk.keywords 1632 ret->data.ksk.keywords = GNUNET_malloc (sizeof (char *) * ent);
1670 = GNUNET_malloc (sizeof (char *) * ent); 1633 GNUNET_CONTAINER_meta_data_iterate (md, &gather_uri_data, ret);
1671 GNUNET_CONTAINER_meta_data_iterate (md, &gather_uri_data, ret); 1634 }
1672 }
1673 return ret; 1635 return ret;
1674} 1636}
1675 1637
@@ -1681,7 +1643,7 @@ GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_CONTAINER_MetaData
1681static int 1643static int
1682needs_percent (char c) 1644needs_percent (char c)
1683{ 1645{
1684 return (!((isalnum ( (unsigned char) c)) || 1646 return (!((isalnum ((unsigned char) c)) ||
1685 (c == '-') || (c == '_') || (c == '.') || (c == '~'))); 1647 (c == '-') || (c == '_') || (c == '.') || (c == '~')));
1686} 1648}
1687 1649
@@ -1695,7 +1657,7 @@ needs_percent (char c)
1695static char * 1657static char *
1696uri_ksk_to_string (const struct GNUNET_FS_Uri *uri) 1658uri_ksk_to_string (const struct GNUNET_FS_Uri *uri)
1697{ 1659{
1698 char ** keywords; 1660 char **keywords;
1699 unsigned int keywordCount; 1661 unsigned int keywordCount;
1700 size_t n; 1662 size_t n;
1701 char *ret; 1663 char *ret;
@@ -1709,50 +1671,49 @@ uri_ksk_to_string (const struct GNUNET_FS_Uri *uri)
1709 return NULL; 1671 return NULL;
1710 keywords = uri->data.ksk.keywords; 1672 keywords = uri->data.ksk.keywords;
1711 keywordCount = uri->data.ksk.keywordCount; 1673 keywordCount = uri->data.ksk.keywordCount;
1712 n = 1674 n = keywordCount + strlen (GNUNET_FS_URI_PREFIX) +
1713 keywordCount + strlen (GNUNET_FS_URI_PREFIX) + 1675 strlen (GNUNET_FS_URI_KSK_INFIX) + 1;
1714 strlen (GNUNET_FS_URI_KSK_INFIX) + 1;
1715 for (i = 0; i < keywordCount; i++) 1676 for (i = 0; i < keywordCount; i++)
1677 {
1678 keyword = keywords[i];
1679 slen = strlen (keyword);
1680 n += slen;
1681 for (j = 0; j < slen; j++)
1716 { 1682 {
1717 keyword = keywords[i]; 1683 if ((j == 0) && (keyword[j] == ' '))
1718 slen = strlen (keyword); 1684 {
1719 n += slen; 1685 n--;
1720 for (j = 0; j < slen; j++) 1686 continue; /* skip leading space */
1721 { 1687 }
1722 if ((j == 0) && (keyword[j] == ' ')) 1688 if (needs_percent (keyword[j]))
1723 { 1689 n += 2; /* will use %-encoding */
1724 n--;
1725 continue; /* skip leading space */
1726 }
1727 if (needs_percent (keyword[j]))
1728 n += 2; /* will use %-encoding */
1729 }
1730 } 1690 }
1691 }
1731 ret = GNUNET_malloc (n); 1692 ret = GNUNET_malloc (n);
1732 strcpy (ret, GNUNET_FS_URI_PREFIX); 1693 strcpy (ret, GNUNET_FS_URI_PREFIX);
1733 strcat (ret, GNUNET_FS_URI_KSK_INFIX); 1694 strcat (ret, GNUNET_FS_URI_KSK_INFIX);
1734 wpos = strlen (ret); 1695 wpos = strlen (ret);
1735 for (i = 0; i < keywordCount; i++) 1696 for (i = 0; i < keywordCount; i++)
1697 {
1698 keyword = keywords[i];
1699 slen = strlen (keyword);
1700 for (j = 0; j < slen; j++)
1736 { 1701 {
1737 keyword = keywords[i]; 1702 if ((j == 0) && (keyword[j] == ' '))
1738 slen = strlen (keyword); 1703 continue; /* skip leading space */
1739 for (j = 0; j < slen; j++) 1704 if (needs_percent (keyword[j]))
1740 { 1705 {
1741 if ((j == 0) && (keyword[j] == ' ')) 1706 sprintf (&ret[wpos], "%%%02X", keyword[j]);
1742 continue; /* skip leading space */ 1707 wpos += 3;
1743 if (needs_percent (keyword[j])) 1708 }
1744 { 1709 else
1745 sprintf (&ret[wpos], "%%%02X", keyword[j]); 1710 {
1746 wpos += 3; 1711 ret[wpos++] = keyword[j];
1747 } 1712 }
1748 else
1749 {
1750 ret[wpos++] = keyword[j];
1751 }
1752 }
1753 if (i != keywordCount - 1)
1754 ret[wpos++] = '+';
1755 } 1713 }
1714 if (i != keywordCount - 1)
1715 ret[wpos++] = '+';
1716 }
1756 return ret; 1717 return ret;
1757} 1718}
1758 1719
@@ -1766,11 +1727,11 @@ uri_ksk_to_string (const struct GNUNET_FS_Uri *uri)
1766static char * 1727static char *
1767uri_sks_to_string (const struct GNUNET_FS_Uri *uri) 1728uri_sks_to_string (const struct GNUNET_FS_Uri *uri)
1768{ 1729{
1769 const GNUNET_HashCode * namespace; 1730 const GNUNET_HashCode *namespace;
1770 const char *identifier; 1731 const char *identifier;
1771 char *ret; 1732 char *ret;
1772 struct GNUNET_CRYPTO_HashAsciiEncoded ns; 1733 struct GNUNET_CRYPTO_HashAsciiEncoded ns;
1773 1734
1774 if (uri->type != sks) 1735 if (uri->type != sks)
1775 return NULL; 1736 return NULL;
1776 namespace = &uri->data.sks.namespace; 1737 namespace = &uri->data.sks.namespace;
@@ -1778,9 +1739,8 @@ uri_sks_to_string (const struct GNUNET_FS_Uri *uri)
1778 GNUNET_CRYPTO_hash_to_enc (namespace, &ns); 1739 GNUNET_CRYPTO_hash_to_enc (namespace, &ns);
1779 GNUNET_asprintf (&ret, 1740 GNUNET_asprintf (&ret,
1780 "%s%s%s/%s", 1741 "%s%s%s/%s",
1781 GNUNET_FS_URI_PREFIX, 1742 GNUNET_FS_URI_PREFIX,
1782 GNUNET_FS_URI_SKS_INFIX, 1743 GNUNET_FS_URI_SKS_INFIX, (const char *) &ns, identifier);
1783 (const char *) &ns, identifier);
1784 return ret; 1744 return ret;
1785} 1745}
1786 1746
@@ -1794,7 +1754,7 @@ uri_sks_to_string (const struct GNUNET_FS_Uri *uri)
1794static char * 1754static char *
1795uri_chk_to_string (const struct GNUNET_FS_Uri *uri) 1755uri_chk_to_string (const struct GNUNET_FS_Uri *uri)
1796{ 1756{
1797 const struct FileIdentifier * fi; 1757 const struct FileIdentifier *fi;
1798 char *ret; 1758 char *ret;
1799 struct GNUNET_CRYPTO_HashAsciiEncoded keyhash; 1759 struct GNUNET_CRYPTO_HashAsciiEncoded keyhash;
1800 struct GNUNET_CRYPTO_HashAsciiEncoded queryhash; 1760 struct GNUNET_CRYPTO_HashAsciiEncoded queryhash;
@@ -1809,9 +1769,8 @@ uri_chk_to_string (const struct GNUNET_FS_Uri *uri)
1809 "%s%s%s.%s.%llu", 1769 "%s%s%s.%s.%llu",
1810 GNUNET_FS_URI_PREFIX, 1770 GNUNET_FS_URI_PREFIX,
1811 GNUNET_FS_URI_CHK_INFIX, 1771 GNUNET_FS_URI_CHK_INFIX,
1812 (const char *) &keyhash, 1772 (const char *) &keyhash,
1813 (const char *) &queryhash, 1773 (const char *) &queryhash, GNUNET_ntohll (fi->file_length));
1814 GNUNET_ntohll (fi->file_length));
1815 return ret; 1774 return ret;
1816} 1775}
1817 1776
@@ -1829,8 +1788,8 @@ bin2enc (const void *data, size_t size)
1829 * 64 characters for encoding, 6 bits per character 1788 * 64 characters for encoding, 6 bits per character
1830 */ 1789 */
1831 static char *tbl = 1790 static char *tbl =
1832 "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_="; 1791 "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_=";
1833 1792
1834 size_t len; 1793 size_t len;
1835 size_t pos; 1794 size_t pos;
1836 unsigned int bits; 1795 unsigned int bits;
@@ -1847,16 +1806,16 @@ bin2enc (const void *data, size_t size)
1847 bits = 0; 1806 bits = 0;
1848 hbits = 0; 1807 hbits = 0;
1849 for (pos = 0; pos < size; pos++) 1808 for (pos = 0; pos < size; pos++)
1809 {
1810 bits |= ((((const unsigned char *) data)[pos]) << hbits);
1811 hbits += 8;
1812 while (hbits >= 6)
1850 { 1813 {
1851 bits |= ((((const unsigned char *) data)[pos]) << hbits); 1814 ret[len++] = tbl[bits & 63];
1852 hbits += 8; 1815 bits >>= 6;
1853 while (hbits >= 6) 1816 hbits -= 6;
1854 {
1855 ret[len++] = tbl[bits & 63];
1856 bits >>= 6;
1857 hbits -= 6;
1858 }
1859 } 1817 }
1818 }
1860 if (hbits > 0) 1819 if (hbits > 0)
1861 ret[len] = tbl[bits & 63]; 1820 ret[len] = tbl[bits & 63];
1862 return ret; 1821 return ret;
@@ -1881,19 +1840,19 @@ uri_loc_to_string (const struct GNUNET_FS_Uri *uri)
1881 GNUNET_CRYPTO_hash_to_enc (&uri->data.loc.fi.chk.key, &keyhash); 1840 GNUNET_CRYPTO_hash_to_enc (&uri->data.loc.fi.chk.key, &keyhash);
1882 GNUNET_CRYPTO_hash_to_enc (&uri->data.loc.fi.chk.query, &queryhash); 1841 GNUNET_CRYPTO_hash_to_enc (&uri->data.loc.fi.chk.query, &queryhash);
1883 peerId = bin2enc (&uri->data.loc.peer, 1842 peerId = bin2enc (&uri->data.loc.peer,
1884 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); 1843 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
1885 peerSig = bin2enc (&uri->data.loc.contentSignature, 1844 peerSig = bin2enc (&uri->data.loc.contentSignature,
1886 sizeof (struct GNUNET_CRYPTO_RsaSignature)); 1845 sizeof (struct GNUNET_CRYPTO_RsaSignature));
1887 GNUNET_asprintf (&ret, 1846 GNUNET_asprintf (&ret,
1888 "%s%s%s.%s.%llu.%s.%s.%llu", 1847 "%s%s%s.%s.%llu.%s.%s.%llu",
1889 GNUNET_FS_URI_PREFIX, 1848 GNUNET_FS_URI_PREFIX,
1890 GNUNET_FS_URI_LOC_INFIX, 1849 GNUNET_FS_URI_LOC_INFIX,
1891 (const char *) &keyhash, 1850 (const char *) &keyhash,
1892 (const char *) &queryhash, 1851 (const char *) &queryhash,
1893 (unsigned long long) GNUNET_ntohll (uri->data.loc.fi.file_length), 1852 (unsigned long long) GNUNET_ntohll (uri->data.loc.
1894 peerId, 1853 fi.file_length), peerId,
1895 peerSig, 1854 peerSig,
1896 (unsigned long long) uri->data.loc.expirationTime.abs_value); 1855 (unsigned long long) uri->data.loc.expirationTime.abs_value);
1897 GNUNET_free (peerSig); 1856 GNUNET_free (peerSig);
1898 GNUNET_free (peerId); 1857 GNUNET_free (peerId);
1899 return ret; 1858 return ret;
@@ -1910,24 +1869,24 @@ char *
1910GNUNET_FS_uri_to_string (const struct GNUNET_FS_Uri *uri) 1869GNUNET_FS_uri_to_string (const struct GNUNET_FS_Uri *uri)
1911{ 1870{
1912 if (uri == NULL) 1871 if (uri == NULL)
1913 { 1872 {
1914 GNUNET_break (0); 1873 GNUNET_break (0);
1915 return NULL; 1874 return NULL;
1916 } 1875 }
1917 switch (uri->type) 1876 switch (uri->type)
1918 { 1877 {
1919 case ksk: 1878 case ksk:
1920 return uri_ksk_to_string (uri); 1879 return uri_ksk_to_string (uri);
1921 case sks: 1880 case sks:
1922 return uri_sks_to_string (uri); 1881 return uri_sks_to_string (uri);
1923 case chk: 1882 case chk:
1924 return uri_chk_to_string (uri); 1883 return uri_chk_to_string (uri);
1925 case loc: 1884 case loc:
1926 return uri_loc_to_string (uri); 1885 return uri_loc_to_string (uri);
1927 default: 1886 default:
1928 GNUNET_break (0); 1887 GNUNET_break (0);
1929 return NULL; 1888 return NULL;
1930 } 1889 }
1931} 1890}
1932 1891
1933/* end of fs_uri.c */ 1892/* end of fs_uri.c */
diff --git a/src/fs/gnunet-directory.c b/src/fs/gnunet-directory.c
index 9bd5ed9c1..a6fa42664 100644
--- a/src/fs/gnunet-directory.c
+++ b/src/fs/gnunet-directory.c
@@ -41,21 +41,19 @@ static int ret;
41 */ 41 */
42static int 42static int
43item_printer (void *cls, 43item_printer (void *cls,
44 const char *plugin_name, 44 const char *plugin_name,
45 enum EXTRACTOR_MetaType type, 45 enum EXTRACTOR_MetaType type,
46 enum EXTRACTOR_MetaFormat format, 46 enum EXTRACTOR_MetaFormat format,
47 const char *data_mime_type, 47 const char *data_mime_type, const char *data, size_t data_size)
48 const char *data,
49 size_t data_size)
50{ 48{
51 if (type == EXTRACTOR_METATYPE_GNUNET_FULL_DATA) 49 if (type == EXTRACTOR_METATYPE_GNUNET_FULL_DATA)
52 { 50 {
53 printf(_("\t<original file embedded in %u bytes of meta data>\n"), 51 printf (_("\t<original file embedded in %u bytes of meta data>\n"),
54 (unsigned int) data_size); 52 (unsigned int) data_size);
55 return 0; 53 return 0;
56 } 54 }
57 if ( (format != EXTRACTOR_METAFORMAT_UTF8) && 55 if ((format != EXTRACTOR_METAFORMAT_UTF8) &&
58 (format != EXTRACTOR_METAFORMAT_C_STRING) ) 56 (format != EXTRACTOR_METAFORMAT_C_STRING))
59 return 0; 57 return 0;
60 if (type == EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME) 58 if (type == EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME)
61 return 0; 59 return 0;
@@ -84,36 +82,29 @@ item_printer (void *cls,
84 */ 82 */
85static void 83static void
86print_entry (void *cls, 84print_entry (void *cls,
87 const char *filename, 85 const char *filename,
88 const struct GNUNET_FS_Uri *uri, 86 const struct GNUNET_FS_Uri *uri,
89 const struct GNUNET_CONTAINER_MetaData *meta, 87 const struct GNUNET_CONTAINER_MetaData *meta,
90 size_t length, 88 size_t length, const void *data)
91 const void *data)
92{ 89{
93 char *string; 90 char *string;
94 char *name; 91 char *name;
95 92
96 name = GNUNET_CONTAINER_meta_data_get_by_type (meta, 93 name = GNUNET_CONTAINER_meta_data_get_by_type (meta,
97 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME); 94 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME);
98 if (uri == NULL) 95 if (uri == NULL)
99 { 96 {
100 printf (_("Directory `%s' meta data:\n"), 97 printf (_("Directory `%s' meta data:\n"), name);
101 name); 98 GNUNET_CONTAINER_meta_data_iterate (meta, &item_printer, NULL);
102 GNUNET_CONTAINER_meta_data_iterate (meta, 99 printf ("\n");
103 &item_printer, 100 printf (_("Directory `%s' contents:\n"), name);
104 NULL); 101 GNUNET_free (name);
105 printf ("\n"); 102 return;
106 printf (_("Directory `%s' contents:\n"), 103 }
107 name);
108 GNUNET_free (name);
109 return;
110 }
111 string = GNUNET_FS_uri_to_string (uri); 104 string = GNUNET_FS_uri_to_string (uri);
112 printf ("%s (%s):\n", name, string); 105 printf ("%s (%s):\n", name, string);
113 GNUNET_free (string); 106 GNUNET_free (string);
114 GNUNET_CONTAINER_meta_data_iterate (meta, 107 GNUNET_CONTAINER_meta_data_iterate (meta, &item_printer, NULL);
115 &item_printer,
116 NULL);
117 printf ("\n"); 108 printf ("\n");
118 GNUNET_free (name); 109 GNUNET_free (name);
119} 110}
@@ -130,8 +121,7 @@ print_entry (void *cls,
130static void 121static void
131run (void *cls, 122run (void *cls,
132 char *const *args, 123 char *const *args,
133 const char *cfgfile, 124 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
134 const struct GNUNET_CONFIGURATION_Handle *cfg)
135{ 125{
136 struct GNUNET_DISK_MapHandle *map; 126 struct GNUNET_DISK_MapHandle *map;
137 struct GNUNET_DISK_FileHandle *h; 127 struct GNUNET_DISK_FileHandle *h;
@@ -142,44 +132,35 @@ run (void *cls,
142 int i; 132 int i;
143 133
144 if (NULL == args[0]) 134 if (NULL == args[0])
145 { 135 {
146 fprintf (stderr, 136 fprintf (stderr, _("You must specify a filename to inspect."));
147 _("You must specify a filename to inspect.")); 137 ret = 1;
148 ret = 1; 138 return;
149 return; 139 }
150 }
151 i = 0; 140 i = 0;
152 while (NULL != (filename = args[i++])) 141 while (NULL != (filename = args[i++]))
142 {
143 if ((GNUNET_OK !=
144 GNUNET_DISK_file_size (filename,
145 &size,
146 GNUNET_YES)) ||
147 (NULL == (h = GNUNET_DISK_file_open (filename,
148 GNUNET_DISK_OPEN_READ,
149 GNUNET_DISK_PERM_NONE))))
153 { 150 {
154 if ( (GNUNET_OK != 151 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
155 GNUNET_DISK_file_size (filename, 152 _("Failed to read directory `%s'\n"), filename);
156 &size, 153 ret = 1;
157 GNUNET_YES)) || 154 continue;
158 (NULL == (h = GNUNET_DISK_file_open (filename,
159 GNUNET_DISK_OPEN_READ,
160 GNUNET_DISK_PERM_NONE))) )
161 {
162 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
163 _("Failed to read directory `%s'\n"),
164 filename);
165 ret = 1;
166 continue;
167 }
168 len = (size_t) size;
169 data = GNUNET_DISK_file_map (h,
170 &map,
171 GNUNET_DISK_MAP_TYPE_READ,
172 len);
173 GNUNET_assert (NULL != data);
174 GNUNET_FS_directory_list_contents (len,
175 data,
176 0,
177 &print_entry,
178 NULL);
179 printf ("\n");
180 GNUNET_DISK_file_unmap (map);
181 GNUNET_DISK_file_close (h);
182 } 155 }
156 len = (size_t) size;
157 data = GNUNET_DISK_file_map (h, &map, GNUNET_DISK_MAP_TYPE_READ, len);
158 GNUNET_assert (NULL != data);
159 GNUNET_FS_directory_list_contents (len, data, 0, &print_entry, NULL);
160 printf ("\n");
161 GNUNET_DISK_file_unmap (map);
162 GNUNET_DISK_file_close (h);
163 }
183} 164}
184 165
185/** 166/**
diff --git a/src/fs/gnunet-download.c b/src/fs/gnunet-download.c
index ccfa9c417..fc0b768d9 100644
--- a/src/fs/gnunet-download.c
+++ b/src/fs/gnunet-download.c
@@ -53,8 +53,7 @@ static char *filename;
53static int local_only; 53static int local_only;
54 54
55static void 55static void
56cleanup_task (void *cls, 56cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
57 const struct GNUNET_SCHEDULER_TaskContext *tc)
58{ 57{
59 GNUNET_FS_stop (ctx); 58 GNUNET_FS_stop (ctx);
60 ctx = NULL; 59 ctx = NULL;
@@ -62,17 +61,16 @@ cleanup_task (void *cls,
62 61
63 62
64static void 63static void
65shutdown_task (void *cls, 64shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
66 const struct GNUNET_SCHEDULER_TaskContext *tc)
67{ 65{
68 struct GNUNET_FS_DownloadContext *d; 66 struct GNUNET_FS_DownloadContext *d;
69 67
70 if (dc != NULL) 68 if (dc != NULL)
71 { 69 {
72 d = dc; 70 d = dc;
73 dc = NULL; 71 dc = NULL;
74 GNUNET_FS_download_stop (d, delete_incomplete); 72 GNUNET_FS_download_stop (d, delete_incomplete);
75 } 73 }
76} 74}
77 75
78 76
@@ -90,67 +88,64 @@ shutdown_task (void *cls,
90 * field in the GNUNET_FS_ProgressInfo struct. 88 * field in the GNUNET_FS_ProgressInfo struct.
91 */ 89 */
92static void * 90static void *
93progress_cb (void *cls, 91progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
94 const struct GNUNET_FS_ProgressInfo *info)
95{ 92{
96 char *s; 93 char *s;
97 char *t; 94 char *t;
98 95
99 switch (info->status) 96 switch (info->status)
100 { 97 {
101 case GNUNET_FS_STATUS_DOWNLOAD_START: 98 case GNUNET_FS_STATUS_DOWNLOAD_START:
102 if (verbose > 1) 99 if (verbose > 1)
103 fprintf (stderr,
104 _("Starting download `%s'.\n"),
105 info->value.download.filename);
106 break;
107 case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS:
108 if (verbose)
109 {
110 s = GNUNET_STRINGS_relative_time_to_string(info->value.download.eta);
111 t = GNUNET_STRINGS_byte_size_fancy(info->value.download.completed * 1000LL / (info->value.download.duration.rel_value + 1));
112 fprintf (stdout,
113 _("Downloading `%s' at %llu/%llu (%s remaining, %s/s)\n"),
114 info->value.download.filename,
115 (unsigned long long) info->value.download.completed,
116 (unsigned long long) info->value.download.size,
117 s,
118 t);
119 GNUNET_free (s);
120 GNUNET_free (t);
121 }
122 break;
123 case GNUNET_FS_STATUS_DOWNLOAD_ERROR:
124 fprintf (stderr, 100 fprintf (stderr,
125 _("Error downloading: %s.\n"), 101 _("Starting download `%s'.\n"), info->value.download.filename);
126 info->value.download.specifics.error.message); 102 break;
127 GNUNET_SCHEDULER_shutdown (); 103 case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS:
128 break; 104 if (verbose)
129 case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: 105 {
130 s = GNUNET_STRINGS_byte_size_fancy(info->value.download.completed * 1000 / (info->value.download.duration.rel_value + 1)); 106 s = GNUNET_STRINGS_relative_time_to_string (info->value.download.eta);
107 t = GNUNET_STRINGS_byte_size_fancy (info->value.download.completed *
108 1000LL /
109 (info->value.download.
110 duration.rel_value + 1));
131 fprintf (stdout, 111 fprintf (stdout,
132 _("Downloading `%s' done (%s/s).\n"), 112 _("Downloading `%s' at %llu/%llu (%s remaining, %s/s)\n"),
133 info->value.download.filename, 113 info->value.download.filename,
134 s); 114 (unsigned long long) info->value.download.completed,
115 (unsigned long long) info->value.download.size, s, t);
135 GNUNET_free (s); 116 GNUNET_free (s);
136 if (info->value.download.dc == dc) 117 GNUNET_free (t);
137 GNUNET_SCHEDULER_shutdown ();
138 break;
139 case GNUNET_FS_STATUS_DOWNLOAD_STOPPED:
140 if (info->value.download.dc == dc)
141 GNUNET_SCHEDULER_add_continuation (&cleanup_task,
142 NULL,
143 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
144 break;
145 case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE:
146 case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE:
147 break;
148 default:
149 fprintf (stderr,
150 _("Unexpected status: %d\n"),
151 info->status);
152 break;
153 } 118 }
119 break;
120 case GNUNET_FS_STATUS_DOWNLOAD_ERROR:
121 fprintf (stderr,
122 _("Error downloading: %s.\n"),
123 info->value.download.specifics.error.message);
124 GNUNET_SCHEDULER_shutdown ();
125 break;
126 case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED:
127 s = GNUNET_STRINGS_byte_size_fancy (info->value.download.completed * 1000 /
128 (info->value.download.
129 duration.rel_value + 1));
130 fprintf (stdout, _("Downloading `%s' done (%s/s).\n"),
131 info->value.download.filename, s);
132 GNUNET_free (s);
133 if (info->value.download.dc == dc)
134 GNUNET_SCHEDULER_shutdown ();
135 break;
136 case GNUNET_FS_STATUS_DOWNLOAD_STOPPED:
137 if (info->value.download.dc == dc)
138 GNUNET_SCHEDULER_add_continuation (&cleanup_task,
139 NULL,
140 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
141 break;
142 case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE:
143 case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE:
144 break;
145 default:
146 fprintf (stderr, _("Unexpected status: %d\n"), info->status);
147 break;
148 }
154 return NULL; 149 return NULL;
155} 150}
156 151
@@ -166,92 +161,77 @@ progress_cb (void *cls,
166static void 161static void
167run (void *cls, 162run (void *cls,
168 char *const *args, 163 char *const *args,
169 const char *cfgfile, 164 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
170 const struct GNUNET_CONFIGURATION_Handle *c)
171{ 165{
172 struct GNUNET_FS_Uri *uri; 166 struct GNUNET_FS_Uri *uri;
173 char *emsg; 167 char *emsg;
174 enum GNUNET_FS_DownloadOptions options; 168 enum GNUNET_FS_DownloadOptions options;
175 169
176 if (NULL == args[0]) 170 if (NULL == args[0])
177 { 171 {
178 fprintf (stderr, 172 fprintf (stderr, _("You need to specify a URI argument.\n"));
179 _("You need to specify a URI argument.\n")); 173 return;
180 return; 174 }
181 } 175 uri = GNUNET_FS_uri_parse (args[0], &emsg);
182 uri = GNUNET_FS_uri_parse (args[0],
183 &emsg);
184 if (NULL == uri) 176 if (NULL == uri)
185 { 177 {
186 fprintf (stderr, 178 fprintf (stderr, _("Failed to parse URI: %s\n"), emsg);
187 _("Failed to parse URI: %s\n"), 179 GNUNET_free (emsg);
188 emsg); 180 ret = 1;
189 GNUNET_free (emsg); 181 return;
190 ret = 1; 182 }
191 return; 183 if ((!GNUNET_FS_uri_test_chk (uri)) && (!GNUNET_FS_uri_test_loc (uri)))
192 } 184 {
193 if ( (! GNUNET_FS_uri_test_chk (uri)) && 185 fprintf (stderr, _("Only CHK or LOC URIs supported.\n"));
194 (! GNUNET_FS_uri_test_loc (uri)) ) 186 ret = 1;
195 { 187 GNUNET_FS_uri_destroy (uri);
196 fprintf (stderr, 188 return;
197 _("Only CHK or LOC URIs supported.\n")); 189 }
198 ret = 1;
199 GNUNET_FS_uri_destroy (uri);
200 return;
201 }
202 if (NULL == filename) 190 if (NULL == filename)
203 { 191 {
204 fprintf (stderr, 192 fprintf (stderr, _("Target filename must be specified.\n"));
205 _("Target filename must be specified.\n")); 193 ret = 1;
206 ret = 1; 194 GNUNET_FS_uri_destroy (uri);
207 GNUNET_FS_uri_destroy (uri); 195 return;
208 return; 196 }
209 }
210 cfg = c; 197 cfg = c;
211 ctx = GNUNET_FS_start (cfg, 198 ctx = GNUNET_FS_start (cfg,
212 "gnunet-download", 199 "gnunet-download",
213 &progress_cb, 200 &progress_cb,
214 NULL, 201 NULL,
215 GNUNET_FS_FLAGS_NONE, 202 GNUNET_FS_FLAGS_NONE,
216 GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM, 203 GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM,
217 parallelism, 204 parallelism,
218 GNUNET_FS_OPTIONS_REQUEST_PARALLELISM, 205 GNUNET_FS_OPTIONS_REQUEST_PARALLELISM,
219 request_parallelism, 206 request_parallelism, GNUNET_FS_OPTIONS_END);
220 GNUNET_FS_OPTIONS_END);
221 if (NULL == ctx) 207 if (NULL == ctx)
222 { 208 {
223 fprintf (stderr, 209 fprintf (stderr, _("Could not initialize `%s' subsystem.\n"), "FS");
224 _("Could not initialize `%s' subsystem.\n"), 210 GNUNET_FS_uri_destroy (uri);
225 "FS"); 211 ret = 1;
226 GNUNET_FS_uri_destroy (uri); 212 return;
227 ret = 1; 213 }
228 return;
229 }
230 options = GNUNET_FS_DOWNLOAD_OPTION_NONE; 214 options = GNUNET_FS_DOWNLOAD_OPTION_NONE;
231 if (do_recursive) 215 if (do_recursive)
232 options |= GNUNET_FS_DOWNLOAD_OPTION_RECURSIVE; 216 options |= GNUNET_FS_DOWNLOAD_OPTION_RECURSIVE;
233 if (local_only) 217 if (local_only)
234 options |= GNUNET_FS_DOWNLOAD_OPTION_LOOPBACK_ONLY; 218 options |= GNUNET_FS_DOWNLOAD_OPTION_LOOPBACK_ONLY;
235 dc = GNUNET_FS_download_start (ctx, 219 dc = GNUNET_FS_download_start (ctx,
236 uri, 220 uri,
237 NULL, 221 NULL,
238 filename, NULL, 222 filename, NULL,
239 0, 223 0,
240 GNUNET_FS_uri_chk_get_file_size (uri), 224 GNUNET_FS_uri_chk_get_file_size (uri),
241 anonymity, 225 anonymity, options, NULL, NULL);
242 options,
243 NULL,
244 NULL);
245 GNUNET_FS_uri_destroy (uri); 226 GNUNET_FS_uri_destroy (uri);
246 if (dc == NULL) 227 if (dc == NULL)
247 { 228 {
248 GNUNET_FS_stop (ctx); 229 GNUNET_FS_stop (ctx);
249 ctx = NULL; 230 ctx = NULL;
250 return; 231 return;
251 } 232 }
252 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 233 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
253 &shutdown_task, 234 &shutdown_task, NULL);
254 NULL);
255} 235}
256 236
257 237
@@ -304,4 +284,3 @@ main (int argc, char *const *argv)
304} 284}
305 285
306/* end of gnunet-download.c */ 286/* end of gnunet-download.c */
307
diff --git a/src/fs/gnunet-pseudonym.c b/src/fs/gnunet-pseudonym.c
index df67571a0..742111c4e 100644
--- a/src/fs/gnunet-pseudonym.c
+++ b/src/fs/gnunet-pseudonym.c
@@ -53,12 +53,12 @@ static struct GNUNET_CONTAINER_MetaData *adv_metadata;
53/** 53/**
54 * Our block options (-p, -r, -a). 54 * Our block options (-p, -r, -a).
55 */ 55 */
56static struct GNUNET_FS_BlockOptions bo = { { 0LL }, 1, 365, 1 }; 56static struct GNUNET_FS_BlockOptions bo = { {0LL}, 1, 365, 1 };
57 57
58/** 58/**
59 * -q option given. 59 * -q option given.
60 */ 60 */
61static int no_remote_printing; 61static int no_remote_printing;
62 62
63/** 63/**
64 * -r option. 64 * -r option.
@@ -87,53 +87,39 @@ static const struct GNUNET_CONFIGURATION_Handle *cfg;
87 87
88static int ret; 88static int ret;
89 89
90static void* 90static void *
91progress_cb (void *cls, 91progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
92 const struct GNUNET_FS_ProgressInfo *info)
93{ 92{
94 return NULL; 93 return NULL;
95} 94}
96 95
97 96
98static void 97static void
99ns_printer (void *cls, 98ns_printer (void *cls, const char *name, const GNUNET_HashCode * id)
100 const char *name,
101 const GNUNET_HashCode *id)
102{ 99{
103 struct GNUNET_CRYPTO_HashAsciiEncoded enc; 100 struct GNUNET_CRYPTO_HashAsciiEncoded enc;
104 101
105 GNUNET_CRYPTO_hash_to_enc (id, &enc); 102 GNUNET_CRYPTO_hash_to_enc (id, &enc);
106 fprintf (stdout, 103 fprintf (stdout, "%s (%s)\n", name, (const char *) &enc);
107 "%s (%s)\n",
108 name,
109 (const char*) &enc);
110} 104}
111 105
112 106
113static int 107static int
114pseudo_printer (void *cls, 108pseudo_printer (void *cls,
115 const GNUNET_HashCode * 109 const GNUNET_HashCode *
116 pseudonym, 110 pseudonym,
117 const struct 111 const struct GNUNET_CONTAINER_MetaData *md, int rating)
118 GNUNET_CONTAINER_MetaData * md,
119 int rating)
120{ 112{
121 char *id; 113 char *id;
122 114
123 id = GNUNET_PSEUDONYM_id_to_name (cfg, 115 id = GNUNET_PSEUDONYM_id_to_name (cfg, pseudonym);
124 pseudonym);
125 if (id == NULL) 116 if (id == NULL)
126 { 117 {
127 GNUNET_break (0); 118 GNUNET_break (0);
128 return GNUNET_OK; 119 return GNUNET_OK;
129 } 120 }
130 fprintf (stdout, 121 fprintf (stdout, "%s (%d):\n", id, rating);
131 "%s (%d):\n", 122 GNUNET_CONTAINER_meta_data_iterate (md, &EXTRACTOR_meta_data_print, stdout);
132 id,
133 rating);
134 GNUNET_CONTAINER_meta_data_iterate (md,
135 &EXTRACTOR_meta_data_print,
136 stdout);
137 fprintf (stdout, "\n"); 123 fprintf (stdout, "\n");
138 GNUNET_free (id); 124 GNUNET_free (id);
139 return GNUNET_OK; 125 return GNUNET_OK;
@@ -141,73 +127,58 @@ pseudo_printer (void *cls,
141 127
142 128
143static void 129static void
144post_advertising (void *cls, 130post_advertising (void *cls, const struct GNUNET_FS_Uri *uri, const char *emsg)
145 const struct GNUNET_FS_Uri *uri,
146 const char *emsg)
147{ 131{
148 GNUNET_HashCode nsid; 132 GNUNET_HashCode nsid;
149 char *set; 133 char *set;
150 int delta; 134 int delta;
151 135
152 if (emsg != NULL) 136 if (emsg != NULL)
153 { 137 {
154 fprintf (stderr, "%s", emsg); 138 fprintf (stderr, "%s", emsg);
155 ret = 1; 139 ret = 1;
156 } 140 }
157 if (ns != NULL) 141 if (ns != NULL)
142 {
143 if (GNUNET_OK != GNUNET_FS_namespace_delete (ns, GNUNET_NO))
144 ret = 1;
145 }
146 if (NULL != rating_change)
147 {
148 set = rating_change;
149 while ((*set != '\0') && (*set != ':'))
150 set++;
151 if (*set != ':')
158 { 152 {
159 if (GNUNET_OK != 153 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
160 GNUNET_FS_namespace_delete (ns, 154 _("Invalid argument `%s'\n"), rating_change);
161 GNUNET_NO))
162 ret = 1;
163 } 155 }
164 if (NULL != rating_change) 156 else
165 { 157 {
166 set = rating_change; 158 *set = '\0';
167 while ((*set != '\0') && (*set != ':')) 159 delta = strtol (&set[1], NULL, /* no error handling yet */
168 set++; 160 10);
169 if (*set != ':') 161 if (GNUNET_OK == GNUNET_PSEUDONYM_name_to_id (cfg, rating_change, &nsid))
170 { 162 {
171 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 163 (void) GNUNET_PSEUDONYM_rank (cfg, &nsid, delta);
172 _("Invalid argument `%s'\n"), 164 }
173 rating_change);
174 }
175 else 165 else
176 { 166 {
177 *set = '\0'; 167 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
178 delta = strtol (&set[1], NULL, /* no error handling yet */ 168 _("Namespace `%s' unknown.\n"), rating_change);
179 10); 169 }
180 if (GNUNET_OK ==
181 GNUNET_PSEUDONYM_name_to_id (cfg,
182 rating_change,
183 &nsid))
184 {
185 (void) GNUNET_PSEUDONYM_rank (cfg,
186 &nsid,
187 delta);
188 }
189 else
190 {
191 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
192 _("Namespace `%s' unknown.\n"),
193 rating_change);
194 }
195 }
196 GNUNET_free (rating_change);
197 rating_change = NULL;
198 } 170 }
171 GNUNET_free (rating_change);
172 rating_change = NULL;
173 }
199 if (0 != print_local_only) 174 if (0 != print_local_only)
200 { 175 {
201 GNUNET_FS_namespace_list (h, 176 GNUNET_FS_namespace_list (h, &ns_printer, NULL);
202 &ns_printer, 177 }
203 NULL);
204 }
205 else if (0 == no_remote_printing) 178 else if (0 == no_remote_printing)
206 { 179 {
207 GNUNET_PSEUDONYM_list_all (cfg, 180 GNUNET_PSEUDONYM_list_all (cfg, &pseudo_printer, NULL);
208 &pseudo_printer, 181 }
209 NULL);
210 }
211 GNUNET_FS_stop (h); 182 GNUNET_FS_stop (h);
212} 183}
213 184
@@ -223,76 +194,70 @@ post_advertising (void *cls,
223static void 194static void
224run (void *cls, 195run (void *cls,
225 char *const *args, 196 char *const *args,
226 const char *cfgfile, 197 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
227 const struct GNUNET_CONFIGURATION_Handle *c)
228{ 198{
229 char *emsg; 199 char *emsg;
230 200
231 cfg = c; 201 cfg = c;
232 h = GNUNET_FS_start (cfg, 202 h = GNUNET_FS_start (cfg,
233 "gnunet-pseudonym", 203 "gnunet-pseudonym",
234 &progress_cb, 204 &progress_cb,
235 NULL, 205 NULL, GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
236 GNUNET_FS_FLAGS_NONE,
237 GNUNET_FS_OPTIONS_END);
238 if (NULL != delete_ns) 206 if (NULL != delete_ns)
207 {
208 ns = GNUNET_FS_namespace_create (h, delete_ns);
209 if (ns == NULL)
239 { 210 {
240 ns = GNUNET_FS_namespace_create (h, delete_ns); 211 ret = 1;
241 if (ns == NULL) 212 }
242 { 213 else
243 ret = 1; 214 {
244 } 215 if (GNUNET_OK != GNUNET_FS_namespace_delete (ns, GNUNET_YES))
245 else 216 ret = 1;
246 { 217 ns = NULL;
247 if (GNUNET_OK !=
248 GNUNET_FS_namespace_delete (ns,
249 GNUNET_YES))
250 ret = 1;
251 ns = NULL;
252 }
253 } 218 }
219 }
254 if (NULL != create_ns) 220 if (NULL != create_ns)
221 {
222 ns = GNUNET_FS_namespace_create (h, create_ns);
223 if (ns == NULL)
224 {
225 ret = 1;
226 }
227 else
255 { 228 {
256 ns = GNUNET_FS_namespace_create (h, create_ns); 229 if (NULL != root_identifier)
257 if (ns == NULL) 230 {
258 { 231 if (ksk_uri == NULL)
259 ret = 1; 232 {
260 } 233 emsg = NULL;
234 ksk_uri = GNUNET_FS_uri_parse ("gnunet://fs/ksk/namespace", &emsg);
235 GNUNET_assert (NULL == emsg);
236 }
237 GNUNET_FS_namespace_advertise (h,
238 ksk_uri,
239 ns,
240 adv_metadata,
241 &bo,
242 root_identifier,
243 &post_advertising, NULL);
244 return;
245 }
261 else 246 else
262 { 247 {
263 if (NULL != root_identifier) 248 if (ksk_uri != NULL)
264 { 249 fprintf (stderr, _("Option `%s' ignored\n"), "-k");
265 if (ksk_uri == NULL) 250 }
266 {
267 emsg = NULL;
268 ksk_uri = GNUNET_FS_uri_parse ("gnunet://fs/ksk/namespace", &emsg);
269 GNUNET_assert (NULL == emsg);
270 }
271 GNUNET_FS_namespace_advertise (h,
272 ksk_uri,
273 ns,
274 adv_metadata,
275 &bo,
276 root_identifier,
277 &post_advertising,
278 NULL);
279 return;
280 }
281 else
282 {
283 if (ksk_uri != NULL)
284 fprintf (stderr, _("Option `%s' ignored\n"), "-k");
285 }
286 }
287 } 251 }
252 }
288 else 253 else
289 { 254 {
290 if (root_identifier != NULL) 255 if (root_identifier != NULL)
291 fprintf (stderr, _("Option `%s' ignored\n"), "-r"); 256 fprintf (stderr, _("Option `%s' ignored\n"), "-r");
292 if (ksk_uri != NULL) 257 if (ksk_uri != NULL)
293 fprintf (stderr, _("Option `%s' ignored\n"), "-k"); 258 fprintf (stderr, _("Option `%s' ignored\n"), "-k");
294 } 259 }
295 260
296 post_advertising (NULL, NULL, NULL); 261 post_advertising (NULL, NULL, NULL);
297} 262}
298 263
@@ -313,12 +278,10 @@ main (int argc, char *const *argv)
313 gettext_noop ("set the desired LEVEL of sender-anonymity"), 278 gettext_noop ("set the desired LEVEL of sender-anonymity"),
314 1, &GNUNET_GETOPT_set_uint, &bo.anonymity_level}, 279 1, &GNUNET_GETOPT_set_uint, &bo.anonymity_level},
315 {'C', "create", "NAME", 280 {'C', "create", "NAME",
316 gettext_noop 281 gettext_noop ("create or advertise namespace NAME"),
317 ("create or advertise namespace NAME"),
318 1, &GNUNET_GETOPT_set_string, &create_ns}, 282 1, &GNUNET_GETOPT_set_string, &create_ns},
319 {'D', "delete", "NAME", 283 {'D', "delete", "NAME",
320 gettext_noop 284 gettext_noop ("delete namespace NAME "),
321 ("delete namespace NAME "),
322 1, &GNUNET_GETOPT_set_string, &delete_ns}, 285 1, &GNUNET_GETOPT_set_string, &delete_ns},
323 {'k', "keyword", "VALUE", 286 {'k', "keyword", "VALUE",
324 gettext_noop 287 gettext_noop
@@ -341,22 +304,18 @@ main (int argc, char *const *argv)
341 gettext_noop ("set the desired replication LEVEL"), 304 gettext_noop ("set the desired replication LEVEL"),
342 1, &GNUNET_GETOPT_set_uint, &bo.replication_level}, 305 1, &GNUNET_GETOPT_set_uint, &bo.replication_level},
343 {'R', "root", "ID", 306 {'R', "root", "ID",
344 gettext_noop 307 gettext_noop ("specify ID of the root of the namespace"),
345 ("specify ID of the root of the namespace"),
346 1, &GNUNET_GETOPT_set_string, &root_identifier}, 308 1, &GNUNET_GETOPT_set_string, &root_identifier},
347 {'s', "set-rating", "ID:VALUE", 309 {'s', "set-rating", "ID:VALUE",
348 gettext_noop 310 gettext_noop ("change rating of namespace ID by VALUE"),
349 ("change rating of namespace ID by VALUE"),
350 1, &GNUNET_GETOPT_set_string, &rating_change}, 311 1, &GNUNET_GETOPT_set_string, &rating_change},
351 GNUNET_GETOPT_OPTION_END 312 GNUNET_GETOPT_OPTION_END
352 }; 313 };
353 bo.expiration_time = GNUNET_FS_year_to_time (GNUNET_FS_get_current_year () + 2); 314 bo.expiration_time =
315 GNUNET_FS_year_to_time (GNUNET_FS_get_current_year () + 2);
354 return (GNUNET_OK == 316 return (GNUNET_OK ==
355 GNUNET_PROGRAM_run (argc, 317 GNUNET_PROGRAM_run (argc, argv, "gnunet-pseudonym [OPTIONS]",
356 argv, 318 gettext_noop ("Manage GNUnet pseudonyms."),
357 "gnunet-pseudonym [OPTIONS]",
358 gettext_noop
359 ("Manage GNUnet pseudonyms."),
360 options, &run, NULL)) ? ret : 1; 319 options, &run, NULL)) ? ret : 1;
361} 320}
362 321
diff --git a/src/fs/gnunet-publish.c b/src/fs/gnunet-publish.c
index 4ff1ad000..326fed3c6 100644
--- a/src/fs/gnunet-publish.c
+++ b/src/fs/gnunet-publish.c
@@ -44,7 +44,7 @@ static struct GNUNET_FS_Uri *topKeywords;
44 44
45static struct GNUNET_FS_Uri *uri; 45static struct GNUNET_FS_Uri *uri;
46 46
47static struct GNUNET_FS_BlockOptions bo = { { 0LL }, 1, 365, 1 }; 47static struct GNUNET_FS_BlockOptions bo = { {0LL}, 1, 365, 1 };
48 48
49static char *uri_string; 49static char *uri_string;
50 50
@@ -67,23 +67,22 @@ static int do_disable_creation_time;
67static GNUNET_SCHEDULER_TaskIdentifier kill_task; 67static GNUNET_SCHEDULER_TaskIdentifier kill_task;
68 68
69 69
70static void 70static void
71do_stop_task (void *cls, 71do_stop_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
72 const struct GNUNET_SCHEDULER_TaskContext *tc)
73{ 72{
74 struct GNUNET_FS_PublishContext *p; 73 struct GNUNET_FS_PublishContext *p;
75 74
76 if (pc != NULL) 75 if (pc != NULL)
76 {
77 p = pc;
78 pc = NULL;
79 GNUNET_FS_publish_stop (p);
80 if (NULL != meta)
77 { 81 {
78 p = pc; 82 GNUNET_CONTAINER_meta_data_destroy (meta);
79 pc = NULL; 83 meta = NULL;
80 GNUNET_FS_publish_stop (p);
81 if (NULL != meta)
82 {
83 GNUNET_CONTAINER_meta_data_destroy (meta);
84 meta = NULL;
85 }
86 } 84 }
85 }
87} 86}
88 87
89 88
@@ -101,72 +100,66 @@ do_stop_task (void *cls,
101 * field in the GNUNET_FS_ProgressInfo struct. 100 * field in the GNUNET_FS_ProgressInfo struct.
102 */ 101 */
103static void * 102static void *
104progress_cb (void *cls, 103progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
105 const struct GNUNET_FS_ProgressInfo *info)
106{ 104{
107 char *s; 105 char *s;
108 106
109 switch (info->status) 107 switch (info->status)
108 {
109 case GNUNET_FS_STATUS_PUBLISH_START:
110 break;
111 case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
112 if (verbose)
110 { 113 {
111 case GNUNET_FS_STATUS_PUBLISH_START: 114 s = GNUNET_STRINGS_relative_time_to_string (info->value.publish.eta);
112 break;
113 case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
114 if (verbose)
115 {
116 s = GNUNET_STRINGS_relative_time_to_string(info->value.publish.eta);
117 fprintf (stdout,
118 _("Publishing `%s' at %llu/%llu (%s remaining)\n"),
119 info->value.publish.filename,
120 (unsigned long long) info->value.publish.completed,
121 (unsigned long long) info->value.publish.size,
122 s);
123 GNUNET_free (s);
124 }
125 break;
126 case GNUNET_FS_STATUS_PUBLISH_ERROR:
127 fprintf (stderr,
128 _("Error publishing: %s.\n"),
129 info->value.publish.specifics.error.message);
130 if (kill_task != GNUNET_SCHEDULER_NO_TASK)
131 {
132 GNUNET_SCHEDULER_cancel (kill_task);
133 kill_task = GNUNET_SCHEDULER_NO_TASK;
134 }
135 GNUNET_SCHEDULER_add_continuation (&do_stop_task,
136 NULL,
137 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
138 break;
139 case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
140 fprintf (stdout, 115 fprintf (stdout,
141 _("Publishing `%s' done.\n"), 116 _("Publishing `%s' at %llu/%llu (%s remaining)\n"),
142 info->value.publish.filename); 117 info->value.publish.filename,
143 s = GNUNET_FS_uri_to_string (info->value.publish.specifics.completed.chk_uri); 118 (unsigned long long) info->value.publish.completed,
144 fprintf (stdout, 119 (unsigned long long) info->value.publish.size, s);
145 _("URI is `%s'.\n"),
146 s);
147 GNUNET_free (s); 120 GNUNET_free (s);
148 if (info->value.publish.pctx == NULL)
149 {
150 if (kill_task != GNUNET_SCHEDULER_NO_TASK)
151 {
152 GNUNET_SCHEDULER_cancel (kill_task);
153 kill_task = GNUNET_SCHEDULER_NO_TASK;
154 }
155 GNUNET_SCHEDULER_add_continuation (&do_stop_task,
156 NULL,
157 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
158 }
159 break;
160 case GNUNET_FS_STATUS_PUBLISH_STOPPED:
161 GNUNET_break (NULL == pc);
162 return NULL;
163 default:
164 fprintf (stderr,
165 _("Unexpected status: %d\n"),
166 info->status);
167 return NULL;
168 } 121 }
169 return ""; /* non-null */ 122 break;
123 case GNUNET_FS_STATUS_PUBLISH_ERROR:
124 fprintf (stderr,
125 _("Error publishing: %s.\n"),
126 info->value.publish.specifics.error.message);
127 if (kill_task != GNUNET_SCHEDULER_NO_TASK)
128 {
129 GNUNET_SCHEDULER_cancel (kill_task);
130 kill_task = GNUNET_SCHEDULER_NO_TASK;
131 }
132 GNUNET_SCHEDULER_add_continuation (&do_stop_task,
133 NULL,
134 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
135 break;
136 case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
137 fprintf (stdout,
138 _("Publishing `%s' done.\n"), info->value.publish.filename);
139 s = GNUNET_FS_uri_to_string (info->value.publish.specifics.
140 completed.chk_uri);
141 fprintf (stdout, _("URI is `%s'.\n"), s);
142 GNUNET_free (s);
143 if (info->value.publish.pctx == NULL)
144 {
145 if (kill_task != GNUNET_SCHEDULER_NO_TASK)
146 {
147 GNUNET_SCHEDULER_cancel (kill_task);
148 kill_task = GNUNET_SCHEDULER_NO_TASK;
149 }
150 GNUNET_SCHEDULER_add_continuation (&do_stop_task,
151 NULL,
152 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
153 }
154 break;
155 case GNUNET_FS_STATUS_PUBLISH_STOPPED:
156 GNUNET_break (NULL == pc);
157 return NULL;
158 default:
159 fprintf (stderr, _("Unexpected status: %d\n"), info->status);
160 return NULL;
161 }
162 return ""; /* non-null */
170} 163}
171 164
172 165
@@ -185,22 +178,17 @@ progress_cb (void *cls,
185 */ 178 */
186static int 179static int
187meta_printer (void *cls, 180meta_printer (void *cls,
188 const char *plugin_name, 181 const char *plugin_name,
189 enum EXTRACTOR_MetaType type, 182 enum EXTRACTOR_MetaType type,
190 enum EXTRACTOR_MetaFormat format, 183 enum EXTRACTOR_MetaFormat format,
191 const char *data_mime_type, 184 const char *data_mime_type, const char *data, size_t data_size)
192 const char *data,
193 size_t data_size)
194{ 185{
195 if ( (format != EXTRACTOR_METAFORMAT_UTF8) && 186 if ((format != EXTRACTOR_METAFORMAT_UTF8) &&
196 (format != EXTRACTOR_METAFORMAT_C_STRING) ) 187 (format != EXTRACTOR_METAFORMAT_C_STRING))
197 return 0; 188 return 0;
198 if (type == EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME) 189 if (type == EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME)
199 return 0; 190 return 0;
200 fprintf (stdout, 191 fprintf (stdout, "\t%s - %s\n", EXTRACTOR_metatype_to_string (type), data);
201 "\t%s - %s\n",
202 EXTRACTOR_metatype_to_string (type),
203 data);
204 return 0; 192 return 0;
205} 193}
206 194
@@ -215,13 +203,9 @@ meta_printer (void *cls,
215 */ 203 */
216 204
217static int 205static int
218keyword_printer (void *cls, 206keyword_printer (void *cls, const char *keyword, int is_mandatory)
219 const char *keyword,
220 int is_mandatory)
221{ 207{
222 fprintf (stdout, 208 fprintf (stdout, "\t%s\n", keyword);
223 "\t%s\n",
224 keyword);
225 return GNUNET_OK; 209 return GNUNET_OK;
226} 210}
227 211
@@ -245,13 +229,12 @@ keyword_printer (void *cls,
245 */ 229 */
246static int 230static int
247publish_inspector (void *cls, 231publish_inspector (void *cls,
248 struct GNUNET_FS_FileInformation *fi, 232 struct GNUNET_FS_FileInformation *fi,
249 uint64_t length, 233 uint64_t length,
250 struct GNUNET_CONTAINER_MetaData *m, 234 struct GNUNET_CONTAINER_MetaData *m,
251 struct GNUNET_FS_Uri **uri, 235 struct GNUNET_FS_Uri **uri,
252 struct GNUNET_FS_BlockOptions *bo, 236 struct GNUNET_FS_BlockOptions *bo,
253 int *do_index, 237 int *do_index, void **client_info)
254 void **client_info)
255{ 238{
256 char *fn; 239 char *fn;
257 char *fs; 240 char *fs;
@@ -260,73 +243,57 @@ publish_inspector (void *cls,
260 if (cls == fi) 243 if (cls == fi)
261 return GNUNET_OK; 244 return GNUNET_OK;
262 if (NULL != topKeywords) 245 if (NULL != topKeywords)
246 {
247 if (*uri != NULL)
263 { 248 {
264 if (*uri != NULL) 249 new_uri = GNUNET_FS_uri_ksk_merge (topKeywords, *uri);
265 { 250 GNUNET_FS_uri_destroy (*uri);
266 new_uri = GNUNET_FS_uri_ksk_merge (topKeywords, 251 *uri = new_uri;
267 *uri); 252 GNUNET_FS_uri_destroy (topKeywords);
268 GNUNET_FS_uri_destroy (*uri);
269 *uri = new_uri;
270 GNUNET_FS_uri_destroy (topKeywords);
271 }
272 else
273 {
274 *uri = topKeywords;
275 }
276 topKeywords = NULL;
277 } 253 }
278 if (NULL != meta) 254 else
279 { 255 {
280 GNUNET_CONTAINER_meta_data_merge (m, meta); 256 *uri = topKeywords;
281 GNUNET_CONTAINER_meta_data_destroy (meta);
282 meta = NULL;
283 } 257 }
284 if (! do_disable_creation_time) 258 topKeywords = NULL;
259 }
260 if (NULL != meta)
261 {
262 GNUNET_CONTAINER_meta_data_merge (m, meta);
263 GNUNET_CONTAINER_meta_data_destroy (meta);
264 meta = NULL;
265 }
266 if (!do_disable_creation_time)
285 GNUNET_CONTAINER_meta_data_add_publication_date (m); 267 GNUNET_CONTAINER_meta_data_add_publication_date (m);
286 if (extract_only) 268 if (extract_only)
287 { 269 {
288 fn = GNUNET_CONTAINER_meta_data_get_by_type (m, 270 fn = GNUNET_CONTAINER_meta_data_get_by_type (m,
289 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME); 271 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME);
290 fs = GNUNET_STRINGS_byte_size_fancy (length); 272 fs = GNUNET_STRINGS_byte_size_fancy (length);
291 fprintf (stdout, 273 fprintf (stdout, _("Meta data for file `%s' (%s)\n"), fn, fs);
292 _("Meta data for file `%s' (%s)\n"), 274 GNUNET_CONTAINER_meta_data_iterate (m, &meta_printer, NULL);
293 fn, 275 fprintf (stdout, _("Keywords for file `%s' (%s)\n"), fn, fs);
294 fs); 276 GNUNET_free (fn);
295 GNUNET_CONTAINER_meta_data_iterate (m, 277 GNUNET_free (fs);
296 &meta_printer, 278 if (NULL != *uri)
297 NULL); 279 GNUNET_FS_uri_ksk_get_keywords (*uri, &keyword_printer, NULL);
298 fprintf (stdout, 280 fprintf (stdout, "\n");
299 _("Keywords for file `%s' (%s)\n"), 281 }
300 fn,
301 fs);
302 GNUNET_free (fn);
303 GNUNET_free (fs);
304 if (NULL != *uri)
305 GNUNET_FS_uri_ksk_get_keywords (*uri,
306 &keyword_printer,
307 NULL);
308 fprintf (stdout, "\n");
309 }
310 if (GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (m)) 282 if (GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (m))
311 GNUNET_FS_file_information_inspect (fi, 283 GNUNET_FS_file_information_inspect (fi, &publish_inspector, fi);
312 &publish_inspector,
313 fi);
314 return GNUNET_OK; 284 return GNUNET_OK;
315} 285}
316 286
317 287
318static void 288static void
319uri_sks_continuation (void *cls, 289uri_sks_continuation (void *cls,
320 const struct GNUNET_FS_Uri *ksk_uri, 290 const struct GNUNET_FS_Uri *ksk_uri, const char *emsg)
321 const char *emsg)
322{ 291{
323 if (emsg != NULL) 292 if (emsg != NULL)
324 { 293 {
325 fprintf (stderr, 294 fprintf (stderr, "%s\n", emsg);
326 "%s\n", 295 ret = 1;
327 emsg); 296 }
328 ret = 1;
329 }
330 GNUNET_FS_uri_destroy (uri); 297 GNUNET_FS_uri_destroy (uri);
331 uri = NULL; 298 uri = NULL;
332 GNUNET_FS_stop (ctx); 299 GNUNET_FS_stop (ctx);
@@ -334,48 +301,40 @@ uri_sks_continuation (void *cls,
334} 301}
335 302
336 303
337static void 304static void
338uri_ksk_continuation (void *cls, 305uri_ksk_continuation (void *cls,
339 const struct GNUNET_FS_Uri *ksk_uri, 306 const struct GNUNET_FS_Uri *ksk_uri, const char *emsg)
340 const char *emsg)
341{ 307{
342 struct GNUNET_FS_Namespace *ns; 308 struct GNUNET_FS_Namespace *ns;
343 309
344 if (emsg != NULL) 310 if (emsg != NULL)
311 {
312 fprintf (stderr, "%s\n", emsg);
313 ret = 1;
314 }
315 if (pseudonym != NULL)
316 {
317 ns = GNUNET_FS_namespace_create (ctx, pseudonym);
318 if (ns == NULL)
345 { 319 {
346 fprintf (stderr, 320 fprintf (stderr, _("Failed to create namespace `%s'\n"), pseudonym);
347 "%s\n",
348 emsg);
349 ret = 1; 321 ret = 1;
350 } 322 }
351 if (pseudonym != NULL) 323 else
352 { 324 {
353 ns = GNUNET_FS_namespace_create (ctx, 325 GNUNET_FS_publish_sks (ctx,
354 pseudonym); 326 ns,
355 if (ns == NULL) 327 this_id,
356 { 328 next_id,
357 fprintf (stderr, 329 meta,
358 _("Failed to create namespace `%s'\n"), 330 uri,
359 pseudonym); 331 &bo,
360 ret = 1; 332 GNUNET_FS_PUBLISH_OPTION_NONE,
361 } 333 uri_sks_continuation, NULL);
362 else 334 GNUNET_assert (GNUNET_OK == GNUNET_FS_namespace_delete (ns, GNUNET_NO));
363 { 335 return;
364 GNUNET_FS_publish_sks (ctx,
365 ns,
366 this_id,
367 next_id,
368 meta,
369 uri,
370 &bo,
371 GNUNET_FS_PUBLISH_OPTION_NONE,
372 uri_sks_continuation,
373 NULL);
374 GNUNET_assert (GNUNET_OK ==
375 GNUNET_FS_namespace_delete (ns, GNUNET_NO));
376 return;
377 }
378 } 336 }
337 }
379 GNUNET_FS_uri_destroy (uri); 338 GNUNET_FS_uri_destroy (uri);
380 uri = NULL; 339 uri = NULL;
381 GNUNET_FS_stop (ctx); 340 GNUNET_FS_stop (ctx);
@@ -394,8 +353,7 @@ uri_ksk_continuation (void *cls,
394static void 353static void
395run (void *cls, 354run (void *cls,
396 char *const *args, 355 char *const *args,
397 const char *cfgfile, 356 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
398 const struct GNUNET_CONFIGURATION_Handle *c)
399{ 357{
400 struct GNUNET_FS_FileInformation *fi; 358 struct GNUNET_FS_FileInformation *fi;
401 struct GNUNET_FS_Namespace *namespace; 359 struct GNUNET_FS_Namespace *namespace;
@@ -404,212 +362,187 @@ run (void *cls,
404 struct stat sbuf; 362 struct stat sbuf;
405 char *ex; 363 char *ex;
406 char *emsg; 364 char *emsg;
407 365
408 /* check arguments */ 366 /* check arguments */
409 if ((uri_string != NULL) && (extract_only)) 367 if ((uri_string != NULL) && (extract_only))
368 {
369 printf (_("Cannot extract metadata from a URI!\n"));
370 ret = -1;
371 return;
372 }
373 if (((uri_string == NULL) || (extract_only))
374 && ((args[0] == NULL) || (args[1] != NULL)))
375 {
376 printf (_("You must specify one and only one filename for insertion.\n"));
377 ret = -1;
378 return;
379 }
380 if ((uri_string != NULL) && (args[0] != NULL))
381 {
382 printf (_("You must NOT specify an URI and a filename.\n"));
383 ret = -1;
384 return;
385 }
386 if (pseudonym != NULL)
387 {
388 if (NULL == this_id)
410 { 389 {
411 printf (_("Cannot extract metadata from a URI!\n")); 390 fprintf (stderr,
391 _("Option `%s' is required when using option `%s'.\n"),
392 "-t", "-P");
412 ret = -1; 393 ret = -1;
413 return; 394 return;
414 } 395 }
415 if ( ( (uri_string == NULL) || (extract_only) ) 396 }
416 && ( (args[0] == NULL) || (args[1] != NULL) ) ) 397 else
398 { /* ordinary insertion checks */
399 if (NULL != next_id)
417 { 400 {
418 printf (_ 401 fprintf (stderr,
419 ("You must specify one and only one filename for insertion.\n")); 402 _("Option `%s' makes no sense without option `%s'.\n"),
403 "-N", "-P");
420 ret = -1; 404 ret = -1;
421 return; 405 return;
422 } 406 }
423 if ((uri_string != NULL) && (args[0] != NULL)) 407 if (NULL != this_id)
424 { 408 {
425 printf (_("You must NOT specify an URI and a filename.\n")); 409 fprintf (stderr,
410 _("Option `%s' makes no sense without option `%s'.\n"),
411 "-t", "-P");
426 ret = -1; 412 ret = -1;
427 return; 413 return;
428 } 414 }
429 if (pseudonym != NULL) 415 }
430 {
431 if (NULL == this_id)
432 {
433 fprintf (stderr,
434 _("Option `%s' is required when using option `%s'.\n"),
435 "-t", "-P");
436 ret = -1;
437 return;
438 }
439 }
440 else
441 { /* ordinary insertion checks */
442 if (NULL != next_id)
443 {
444 fprintf (stderr,
445 _("Option `%s' makes no sense without option `%s'.\n"),
446 "-N", "-P");
447 ret = -1;
448 return;
449 }
450 if (NULL != this_id)
451 {
452 fprintf (stderr,
453 _("Option `%s' makes no sense without option `%s'.\n"),
454 "-t", "-P");
455 ret = -1;
456 return;
457 }
458 }
459 cfg = c; 416 cfg = c;
460 ctx = GNUNET_FS_start (cfg, 417 ctx = GNUNET_FS_start (cfg,
461 "gnunet-publish", 418 "gnunet-publish",
462 &progress_cb, 419 &progress_cb,
463 NULL, 420 NULL, GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
464 GNUNET_FS_FLAGS_NONE,
465 GNUNET_FS_OPTIONS_END);
466 if (NULL == ctx) 421 if (NULL == ctx)
467 { 422 {
468 fprintf (stderr, 423 fprintf (stderr, _("Could not initialize `%s' subsystem.\n"), "FS");
469 _("Could not initialize `%s' subsystem.\n"), 424 ret = 1;
470 "FS"); 425 return;
471 ret = 1; 426 }
472 return;
473 }
474 namespace = NULL; 427 namespace = NULL;
475 if (NULL != pseudonym) 428 if (NULL != pseudonym)
429 {
430 namespace = GNUNET_FS_namespace_create (ctx, pseudonym);
431 if (NULL == namespace)
476 { 432 {
477 namespace = GNUNET_FS_namespace_create (ctx, 433 fprintf (stderr, _("Could not create namespace `%s'\n"), pseudonym);
478 pseudonym); 434 GNUNET_FS_stop (ctx);
479 if (NULL == namespace) 435 ret = 1;
480 { 436 return;
481 fprintf (stderr,
482 _("Could not create namespace `%s'\n"),
483 pseudonym);
484 GNUNET_FS_stop (ctx);
485 ret = 1;
486 return;
487 }
488 } 437 }
438 }
489 if (NULL != uri_string) 439 if (NULL != uri_string)
490 { 440 {
491 emsg = NULL; 441 emsg = NULL;
492 uri = GNUNET_FS_uri_parse (uri_string, 442 uri = GNUNET_FS_uri_parse (uri_string, &emsg);
493 &emsg); 443 if (uri == NULL)
494 if (uri == NULL) 444 {
495 { 445 fprintf (stderr, _("Failed to parse URI: %s\n"), emsg);
496 fprintf (stderr, 446 GNUNET_free (emsg);
497 _("Failed to parse URI: %s\n"),
498 emsg);
499 GNUNET_free (emsg);
500 if (namespace != NULL)
501 GNUNET_FS_namespace_delete (namespace, GNUNET_NO);
502 GNUNET_FS_stop (ctx);
503 ret = 1;
504 return;
505 }
506 GNUNET_FS_publish_ksk (ctx,
507 topKeywords,
508 meta,
509 uri,
510 &bo,
511 GNUNET_FS_PUBLISH_OPTION_NONE,
512 &uri_ksk_continuation,
513 NULL);
514 if (namespace != NULL) 447 if (namespace != NULL)
515 GNUNET_FS_namespace_delete (namespace, GNUNET_NO); 448 GNUNET_FS_namespace_delete (namespace, GNUNET_NO);
449 GNUNET_FS_stop (ctx);
450 ret = 1;
516 return; 451 return;
517 } 452 }
453 GNUNET_FS_publish_ksk (ctx,
454 topKeywords,
455 meta,
456 uri,
457 &bo,
458 GNUNET_FS_PUBLISH_OPTION_NONE,
459 &uri_ksk_continuation, NULL);
460 if (namespace != NULL)
461 GNUNET_FS_namespace_delete (namespace, GNUNET_NO);
462 return;
463 }
518 plugins = NULL; 464 plugins = NULL;
519 if (! disable_extractor) 465 if (!disable_extractor)
466 {
467 plugins = EXTRACTOR_plugin_add_defaults (EXTRACTOR_OPTION_DEFAULT_POLICY);
468 if (GNUNET_OK ==
469 GNUNET_CONFIGURATION_get_value_string (cfg, "FS", "EXTRACTORS", &ex))
520 { 470 {
521 plugins = EXTRACTOR_plugin_add_defaults (EXTRACTOR_OPTION_DEFAULT_POLICY); 471 if (strlen (ex) > 0)
522 if (GNUNET_OK == 472 plugins =
523 GNUNET_CONFIGURATION_get_value_string (cfg, "FS", "EXTRACTORS", 473 EXTRACTOR_plugin_add_config (plugins, ex,
524 &ex)) 474 EXTRACTOR_OPTION_DEFAULT_POLICY);
525 { 475 GNUNET_free (ex);
526 if (strlen (ex) > 0)
527 plugins = EXTRACTOR_plugin_add_config (plugins, ex, EXTRACTOR_OPTION_DEFAULT_POLICY);
528 GNUNET_free (ex);
529 }
530 } 476 }
477 }
531 emsg = NULL; 478 emsg = NULL;
532 GNUNET_assert (NULL != args[0]); 479 GNUNET_assert (NULL != args[0]);
533 if (0 != STAT (args[0], &sbuf)) 480 if (0 != STAT (args[0], &sbuf))
534 { 481 {
535 GNUNET_asprintf (&emsg, 482 GNUNET_asprintf (&emsg, _("Could not access file: %s\n"), STRERROR (errno));
536 _("Could not access file: %s\n"), 483 fi = NULL;
537 STRERROR (errno)); 484 }
538 fi = NULL;
539 }
540 else if (S_ISDIR (sbuf.st_mode)) 485 else if (S_ISDIR (sbuf.st_mode))
541 { 486 {
542 fi = GNUNET_FS_file_information_create_from_directory (ctx, 487 fi = GNUNET_FS_file_information_create_from_directory (ctx,
543 NULL, 488 NULL,
544 args[0], 489 args[0],
545 &GNUNET_FS_directory_scanner_default, 490 &GNUNET_FS_directory_scanner_default,
546 plugins, 491 plugins,
547 !do_insert, 492 !do_insert,
548 &bo, 493 &bo, &emsg);
549 &emsg); 494 }
550 }
551 else 495 else
552 { 496 {
553 if (meta == NULL) 497 if (meta == NULL)
554 meta = GNUNET_CONTAINER_meta_data_create (); 498 meta = GNUNET_CONTAINER_meta_data_create ();
555 GNUNET_FS_meta_data_extract_from_file (meta, 499 GNUNET_FS_meta_data_extract_from_file (meta, args[0], plugins);
556 args[0], 500 keywords = GNUNET_FS_uri_ksk_create_from_meta_data (meta);
557 plugins); 501 fi = GNUNET_FS_file_information_create_from_file (ctx,
558 keywords = GNUNET_FS_uri_ksk_create_from_meta_data (meta); 502 NULL,
559 fi = GNUNET_FS_file_information_create_from_file (ctx, 503 args[0],
560 NULL, 504 keywords,
561 args[0], 505 NULL, !do_insert, &bo);
562 keywords, 506 GNUNET_break (fi != NULL);
563 NULL, 507 GNUNET_FS_uri_destroy (keywords);
564 !do_insert, 508 }
565 &bo); 509 EXTRACTOR_plugin_remove_all (plugins);
566 GNUNET_break (fi != NULL);
567 GNUNET_FS_uri_destroy (keywords);
568 }
569 EXTRACTOR_plugin_remove_all (plugins);
570 if (fi == NULL) 510 if (fi == NULL)
571 { 511 {
572 fprintf (stderr, 512 fprintf (stderr, _("Could not publish `%s': %s\n"), args[0], emsg);
573 _("Could not publish `%s': %s\n"), 513 GNUNET_free (emsg);
574 args[0], 514 if (namespace != NULL)
575 emsg); 515 GNUNET_FS_namespace_delete (namespace, GNUNET_NO);
576 GNUNET_free (emsg); 516 GNUNET_FS_stop (ctx);
577 if (namespace != NULL) 517 ret = 1;
578 GNUNET_FS_namespace_delete (namespace, GNUNET_NO); 518 return;
579 GNUNET_FS_stop (ctx); 519 }
580 ret = 1; 520 GNUNET_FS_file_information_inspect (fi, &publish_inspector, NULL);
581 return;
582 }
583 GNUNET_FS_file_information_inspect (fi,
584 &publish_inspector,
585 NULL);
586 if (extract_only) 521 if (extract_only)
587 { 522 {
588 if (namespace != NULL) 523 if (namespace != NULL)
589 GNUNET_FS_namespace_delete (namespace, GNUNET_NO); 524 GNUNET_FS_namespace_delete (namespace, GNUNET_NO);
590 GNUNET_FS_file_information_destroy (fi, NULL, NULL); 525 GNUNET_FS_file_information_destroy (fi, NULL, NULL);
591 GNUNET_FS_stop (ctx); 526 GNUNET_FS_stop (ctx);
592 return; 527 return;
593 } 528 }
594 pc = GNUNET_FS_publish_start (ctx, 529 pc = GNUNET_FS_publish_start (ctx,
595 fi, 530 fi,
596 namespace, 531 namespace,
597 this_id, 532 this_id,
598 next_id, 533 next_id,
599 (do_simulate) 534 (do_simulate)
600 ? GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY 535 ? GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY
601 : GNUNET_FS_PUBLISH_OPTION_NONE); 536 : GNUNET_FS_PUBLISH_OPTION_NONE);
602 if (NULL == pc) 537 if (NULL == pc)
603 { 538 {
604 fprintf (stderr, 539 fprintf (stderr, _("Could not start publishing.\n"));
605 _("Could not start publishing.\n")); 540 GNUNET_FS_stop (ctx);
606 GNUNET_FS_stop (ctx); 541 ret = 1;
607 ret = 1; 542 return;
608 return; 543 }
609 }
610 kill_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 544 kill_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
611 &do_stop_task, 545 &do_stop_task, NULL);
612 NULL);
613} 546}
614 547
615 548
@@ -634,8 +567,7 @@ main (int argc, char *const *argv)
634 ("disable adding the creation time to the metadata of the uploaded file"), 567 ("disable adding the creation time to the metadata of the uploaded file"),
635 0, &GNUNET_GETOPT_set_one, &do_disable_creation_time}, 568 0, &GNUNET_GETOPT_set_one, &do_disable_creation_time},
636 {'D', "disable-extractor", NULL, 569 {'D', "disable-extractor", NULL,
637 gettext_noop 570 gettext_noop ("do not use libextractor to add keywords or metadata"),
638 ("do not use libextractor to add keywords or metadata"),
639 0, &GNUNET_GETOPT_set_one, &disable_extractor}, 571 0, &GNUNET_GETOPT_set_one, &disable_extractor},
640 {'e', "extract", NULL, 572 {'e', "extract", NULL,
641 gettext_noop 573 gettext_noop
@@ -651,7 +583,7 @@ main (int argc, char *const *argv)
651 1, &GNUNET_FS_getopt_set_metadata, &meta}, 583 1, &GNUNET_FS_getopt_set_metadata, &meta},
652 {'n', "noindex", NULL, 584 {'n', "noindex", NULL,
653 gettext_noop ("do not index, perform full insertion (stores entire " 585 gettext_noop ("do not index, perform full insertion (stores entire "
654 "file in encrypted form in GNUnet database)"), 586 "file in encrypted form in GNUnet database)"),
655 0, &GNUNET_GETOPT_set_one, &do_insert}, 587 0, &GNUNET_GETOPT_set_one, &do_insert},
656 {'N', "next", "ID", 588 {'N', "next", "ID",
657 gettext_noop 589 gettext_noop
@@ -670,26 +602,25 @@ main (int argc, char *const *argv)
670 1, &GNUNET_GETOPT_set_uint, &bo.replication_level}, 602 1, &GNUNET_GETOPT_set_uint, &bo.replication_level},
671 {'s', "simulate-only", NULL, 603 {'s', "simulate-only", NULL,
672 gettext_noop ("only simulate the process but do not do any " 604 gettext_noop ("only simulate the process but do not do any "
673 "actual publishing (useful to compute URIs)"), 605 "actual publishing (useful to compute URIs)"),
674 0, &GNUNET_GETOPT_set_one, &do_simulate}, 606 0, &GNUNET_GETOPT_set_one, &do_simulate},
675 {'t', "this", "ID", 607 {'t', "this", "ID",
676 gettext_noop ("set the ID of this version of the publication" 608 gettext_noop ("set the ID of this version of the publication"
677 " (for namespace insertions only)"), 609 " (for namespace insertions only)"),
678 1, &GNUNET_GETOPT_set_string, &this_id}, 610 1, &GNUNET_GETOPT_set_string, &this_id},
679 {'u', "uri", "URI", 611 {'u', "uri", "URI",
680 gettext_noop ("URI to be published (can be used instead of passing a " 612 gettext_noop ("URI to be published (can be used instead of passing a "
681 "file to add keywords to the file with the respective URI)"), 613 "file to add keywords to the file with the respective URI)"),
682 1, &GNUNET_GETOPT_set_string, &uri_string}, 614 1, &GNUNET_GETOPT_set_string, &uri_string},
683 {'V', "verbose", NULL, 615 {'V', "verbose", NULL,
684 gettext_noop ("be verbose (print progress information)"), 616 gettext_noop ("be verbose (print progress information)"),
685 0, &GNUNET_GETOPT_set_one, &verbose}, 617 0, &GNUNET_GETOPT_set_one, &verbose},
686 GNUNET_GETOPT_OPTION_END 618 GNUNET_GETOPT_OPTION_END
687 }; 619 };
688 bo.expiration_time = GNUNET_FS_year_to_time (GNUNET_FS_get_current_year () + 2); 620 bo.expiration_time =
621 GNUNET_FS_year_to_time (GNUNET_FS_get_current_year () + 2);
689 return (GNUNET_OK == 622 return (GNUNET_OK ==
690 GNUNET_PROGRAM_run (argc, 623 GNUNET_PROGRAM_run (argc, argv, "gnunet-publish [OPTIONS] FILENAME",
691 argv,
692 "gnunet-publish [OPTIONS] FILENAME",
693 gettext_noop 624 gettext_noop
694 ("Publish a file or directory on GNUnet"), 625 ("Publish a file or directory on GNUnet"),
695 options, &run, NULL)) ? ret : 1; 626 options, &run, NULL)) ? ret : 1;
diff --git a/src/fs/gnunet-search.c b/src/fs/gnunet-search.c
index c4c8b2a46..8a3e2ed6a 100644
--- a/src/fs/gnunet-search.c
+++ b/src/fs/gnunet-search.c
@@ -68,32 +68,28 @@ static int local_only;
68 * @param data actual meta-data found 68 * @param data actual meta-data found
69 * @param data_size number of bytes in data 69 * @param data_size number of bytes in data
70 * @return 0 to continue extracting, 1 to abort 70 * @return 0 to continue extracting, 1 to abort
71 */ 71 */
72static int 72static int
73item_printer (void *cls, 73item_printer (void *cls,
74 const char *plugin_name, 74 const char *plugin_name,
75 enum EXTRACTOR_MetaType type, 75 enum EXTRACTOR_MetaType type,
76 enum EXTRACTOR_MetaFormat format, 76 enum EXTRACTOR_MetaFormat format,
77 const char *data_mime_type, 77 const char *data_mime_type, const char *data, size_t data_size)
78 const char *data,
79 size_t data_size)
80{ 78{
81 if ( (format != EXTRACTOR_METAFORMAT_UTF8) && 79 if ((format != EXTRACTOR_METAFORMAT_UTF8) &&
82 (format != EXTRACTOR_METAFORMAT_C_STRING) ) 80 (format != EXTRACTOR_METAFORMAT_C_STRING))
83 return 0; 81 return 0;
84 if (type == EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME) 82 if (type == EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME)
85 return 0; 83 return 0;
86 printf ("\t%20s: %s\n", 84 printf ("\t%20s: %s\n",
87 dgettext (LIBEXTRACTOR_GETTEXT_DOMAIN, 85 dgettext (LIBEXTRACTOR_GETTEXT_DOMAIN,
88 EXTRACTOR_metatype_to_string (type)), 86 EXTRACTOR_metatype_to_string (type)), data);
89 data);
90 return 0; 87 return 0;
91} 88}
92 89
93 90
94static void 91static void
95clean_task (void *cls, 92clean_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
96 const struct GNUNET_SCHEDULER_TaskContext *tc)
97{ 93{
98 size_t dsize; 94 size_t dsize;
99 void *ddata; 95 void *ddata;
@@ -102,25 +98,23 @@ clean_task (void *cls,
102 ctx = NULL; 98 ctx = NULL;
103 if (output_filename == NULL) 99 if (output_filename == NULL)
104 return; 100 return;
105 if (GNUNET_OK != 101 if (GNUNET_OK != GNUNET_FS_directory_builder_finish (db, &dsize, &ddata))
106 GNUNET_FS_directory_builder_finish (db, 102 {
107 &dsize, 103 GNUNET_break (0);
108 &ddata)) 104 GNUNET_free (output_filename);
109 { 105 return;
110 GNUNET_break (0); 106 }
111 GNUNET_free (output_filename); 107 if (dsize !=
112 return;
113 }
114 if (dsize !=
115 GNUNET_DISK_fn_write (output_filename, 108 GNUNET_DISK_fn_write (output_filename,
116 ddata, 109 ddata,
117 dsize, 110 dsize,
118 GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE)) 111 GNUNET_DISK_PERM_USER_READ |
119 { 112 GNUNET_DISK_PERM_USER_WRITE))
120 fprintf (stderr, 113 {
121 _("Failed to write directory with search results to `%s'\n"), 114 fprintf (stderr,
122 output_filename); 115 _("Failed to write directory with search results to `%s'\n"),
123 } 116 output_filename);
117 }
124 GNUNET_free_non_null (ddata); 118 GNUNET_free_non_null (ddata);
125 GNUNET_free (output_filename); 119 GNUNET_free (output_filename);
126} 120}
@@ -140,8 +134,7 @@ clean_task (void *cls,
140 * field in the GNUNET_FS_ProgressInfo struct. 134 * field in the GNUNET_FS_ProgressInfo struct.
141 */ 135 */
142static void * 136static void *
143progress_cb (void *cls, 137progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
144 const struct GNUNET_FS_ProgressInfo *info)
145{ 138{
146 static unsigned int cnt; 139 static unsigned int cnt;
147 char *uri; 140 char *uri;
@@ -149,78 +142,72 @@ progress_cb (void *cls,
149 char *filename; 142 char *filename;
150 143
151 switch (info->status) 144 switch (info->status)
145 {
146 case GNUNET_FS_STATUS_SEARCH_START:
147 break;
148 case GNUNET_FS_STATUS_SEARCH_RESULT:
149 if (db != NULL)
150 GNUNET_FS_directory_builder_add (db,
151 info->value.search.specifics.result.uri,
152 info->value.search.specifics.result.meta,
153 NULL);
154 uri = GNUNET_FS_uri_to_string (info->value.search.specifics.result.uri);
155 printf ("#%u:\n", cnt++);
156 filename =
157 GNUNET_CONTAINER_meta_data_get_by_type (info->value.search.
158 specifics.result.meta,
159 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME);
160 if (filename != NULL)
152 { 161 {
153 case GNUNET_FS_STATUS_SEARCH_START: 162 while (NULL != (dotdot = strstr (filename, "..")))
154 break; 163 dotdot[0] = dotdot[1] = '_';
155 case GNUNET_FS_STATUS_SEARCH_RESULT: 164 printf ("gnunet-download -o \"%s\" %s\n", filename, uri);
156 if (db != NULL)
157 GNUNET_FS_directory_builder_add (db,
158 info->value.search.specifics.result.uri,
159 info->value.search.specifics.result.meta,
160 NULL);
161 uri = GNUNET_FS_uri_to_string (info->value.search.specifics.result.uri);
162 printf ("#%u:\n", cnt++);
163 filename =
164 GNUNET_CONTAINER_meta_data_get_by_type (info->value.search.specifics.result.meta,
165 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME);
166 if (filename != NULL)
167 {
168 while (NULL != (dotdot = strstr (filename, "..")))
169 dotdot[0] = dotdot[1] = '_';
170 printf ("gnunet-download -o \"%s\" %s\n",
171 filename,
172 uri);
173 }
174 else
175 printf ("gnunet-download %s\n", uri);
176 if (verbose)
177 GNUNET_CONTAINER_meta_data_iterate (info->value.search.specifics.result.meta,
178 &item_printer,
179 NULL);
180 printf ("\n");
181 fflush(stdout);
182 GNUNET_free_non_null (filename);
183 GNUNET_free (uri);
184 results++;
185 if ( (results_limit > 0) &&
186 (results >= results_limit) )
187 GNUNET_SCHEDULER_shutdown ();
188 break;
189 case GNUNET_FS_STATUS_SEARCH_UPDATE:
190 break;
191 case GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED:
192 /* ignore */
193 break;
194 case GNUNET_FS_STATUS_SEARCH_ERROR:
195 fprintf (stderr,
196 _("Error searching: %s.\n"),
197 info->value.search.specifics.error.message);
198 GNUNET_SCHEDULER_shutdown ();
199 break;
200 case GNUNET_FS_STATUS_SEARCH_STOPPED:
201 GNUNET_SCHEDULER_add_continuation (&clean_task,
202 NULL,
203 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
204 break;
205 default:
206 fprintf (stderr,
207 _("Unexpected status: %d\n"),
208 info->status);
209 break;
210 } 165 }
166 else
167 printf ("gnunet-download %s\n", uri);
168 if (verbose)
169 GNUNET_CONTAINER_meta_data_iterate (info->value.search.specifics.
170 result.meta, &item_printer, NULL);
171 printf ("\n");
172 fflush (stdout);
173 GNUNET_free_non_null (filename);
174 GNUNET_free (uri);
175 results++;
176 if ((results_limit > 0) && (results >= results_limit))
177 GNUNET_SCHEDULER_shutdown ();
178 break;
179 case GNUNET_FS_STATUS_SEARCH_UPDATE:
180 break;
181 case GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED:
182 /* ignore */
183 break;
184 case GNUNET_FS_STATUS_SEARCH_ERROR:
185 fprintf (stderr,
186 _("Error searching: %s.\n"),
187 info->value.search.specifics.error.message);
188 GNUNET_SCHEDULER_shutdown ();
189 break;
190 case GNUNET_FS_STATUS_SEARCH_STOPPED:
191 GNUNET_SCHEDULER_add_continuation (&clean_task,
192 NULL,
193 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
194 break;
195 default:
196 fprintf (stderr, _("Unexpected status: %d\n"), info->status);
197 break;
198 }
211 return NULL; 199 return NULL;
212} 200}
213 201
214 202
215static void 203static void
216shutdown_task (void *cls, 204shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
217 const struct GNUNET_SCHEDULER_TaskContext *tc)
218{ 205{
219 if (sc != NULL) 206 if (sc != NULL)
220 { 207 {
221 GNUNET_FS_search_stop (sc); 208 GNUNET_FS_search_stop (sc);
222 sc = NULL; 209 sc = NULL;
223 } 210 }
224} 211}
225 212
226 213
@@ -235,8 +222,7 @@ shutdown_task (void *cls,
235static void 222static void
236run (void *cls, 223run (void *cls,
237 char *const *args, 224 char *const *args,
238 const char *cfgfile, 225 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
239 const struct GNUNET_CONFIGURATION_Handle *c)
240{ 226{
241 struct GNUNET_FS_Uri *uri; 227 struct GNUNET_FS_Uri *uri;
242 unsigned int argc; 228 unsigned int argc;
@@ -246,63 +232,49 @@ run (void *cls,
246 argc = 0; 232 argc = 0;
247 while (NULL != args[argc]) 233 while (NULL != args[argc])
248 argc++; 234 argc++;
249 uri = GNUNET_FS_uri_ksk_create_from_args (argc, 235 uri = GNUNET_FS_uri_ksk_create_from_args (argc, (const char **) args);
250 (const char **) args);
251 if (NULL == uri) 236 if (NULL == uri)
252 { 237 {
253 fprintf (stderr, 238 fprintf (stderr, _("Could not create keyword URI from arguments.\n"));
254 _("Could not create keyword URI from arguments.\n")); 239 ret = 1;
255 ret = 1; 240 return;
256 return; 241 }
257 }
258 cfg = c; 242 cfg = c;
259 ctx = GNUNET_FS_start (cfg, 243 ctx = GNUNET_FS_start (cfg,
260 "gnunet-search", 244 "gnunet-search",
261 &progress_cb, 245 &progress_cb,
262 NULL, 246 NULL, GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
263 GNUNET_FS_FLAGS_NONE,
264 GNUNET_FS_OPTIONS_END);
265 if (NULL == ctx) 247 if (NULL == ctx)
266 { 248 {
267 fprintf (stderr, 249 fprintf (stderr, _("Could not initialize `%s' subsystem.\n"), "FS");
268 _("Could not initialize `%s' subsystem.\n"), 250 GNUNET_FS_uri_destroy (uri);
269 "FS"); 251 ret = 1;
270 GNUNET_FS_uri_destroy (uri); 252 return;
271 ret = 1; 253 }
272 return;
273 }
274 if (output_filename != NULL) 254 if (output_filename != NULL)
275 db = GNUNET_FS_directory_builder_create (NULL); 255 db = GNUNET_FS_directory_builder_create (NULL);
276 options = GNUNET_FS_SEARCH_OPTION_NONE; 256 options = GNUNET_FS_SEARCH_OPTION_NONE;
277 if (local_only) 257 if (local_only)
278 options |= GNUNET_FS_SEARCH_OPTION_LOOPBACK_ONLY; 258 options |= GNUNET_FS_SEARCH_OPTION_LOOPBACK_ONLY;
279 sc = GNUNET_FS_search_start (ctx, 259 sc = GNUNET_FS_search_start (ctx, uri, anonymity, options, NULL);
280 uri,
281 anonymity,
282 options,
283 NULL);
284 GNUNET_FS_uri_destroy (uri); 260 GNUNET_FS_uri_destroy (uri);
285 if (NULL == sc) 261 if (NULL == sc)
286 { 262 {
287 fprintf (stderr, 263 fprintf (stderr, _("Could not start searching.\n"));
288 _("Could not start searching.\n")); 264 GNUNET_FS_stop (ctx);
289 GNUNET_FS_stop (ctx); 265 ret = 1;
290 ret = 1; 266 return;
291 return; 267 }
292 }
293 if (timeout != 0) 268 if (timeout != 0)
294 { 269 {
295 delay.rel_value = timeout; 270 delay.rel_value = timeout;
296 GNUNET_SCHEDULER_add_delayed (delay, 271 GNUNET_SCHEDULER_add_delayed (delay, &shutdown_task, NULL);
297 &shutdown_task, 272 }
298 NULL);
299 }
300 else 273 else
301 { 274 {
302 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 275 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
303 &shutdown_task, 276 &shutdown_task, NULL);
304 NULL); 277 }
305 }
306} 278}
307 279
308 280
@@ -324,12 +296,10 @@ main (int argc, char *const *argv)
324 gettext_noop ("only search the local peer (no P2P network search)"), 296 gettext_noop ("only search the local peer (no P2P network search)"),
325 0, &GNUNET_GETOPT_set_one, &local_only}, 297 0, &GNUNET_GETOPT_set_one, &local_only},
326 {'o', "output", "PREFIX", 298 {'o', "output", "PREFIX",
327 gettext_noop 299 gettext_noop ("write search results to file starting with PREFIX"),
328 ("write search results to file starting with PREFIX"), 300 1, &GNUNET_GETOPT_set_string, &output_filename},
329 1, &GNUNET_GETOPT_set_string, &output_filename},
330 {'t', "timeout", "VALUE", 301 {'t', "timeout", "VALUE",
331 gettext_noop 302 gettext_noop ("automatically terminate search after VALUE ms"),
332 ("automatically terminate search after VALUE ms"),
333 1, &GNUNET_GETOPT_set_ulong, &timeout}, 303 1, &GNUNET_GETOPT_set_ulong, &timeout},
334 {'V', "verbose", NULL, 304 {'V', "verbose", NULL,
335 gettext_noop ("be verbose (print progress information)"), 305 gettext_noop ("be verbose (print progress information)"),
@@ -339,7 +309,7 @@ main (int argc, char *const *argv)
339 ("automatically terminate search after VALUE results are found"), 309 ("automatically terminate search after VALUE results are found"),
340 1, &GNUNET_GETOPT_set_ulong, &results_limit}, 310 1, &GNUNET_GETOPT_set_ulong, &results_limit},
341 GNUNET_GETOPT_OPTION_END 311 GNUNET_GETOPT_OPTION_END
342 }; 312 };
343 return (GNUNET_OK == 313 return (GNUNET_OK ==
344 GNUNET_PROGRAM_run (argc, 314 GNUNET_PROGRAM_run (argc,
345 argv, 315 argv,
@@ -350,4 +320,3 @@ main (int argc, char *const *argv)
350} 320}
351 321
352/* end of gnunet-search.c */ 322/* end of gnunet-search.c */
353
diff --git a/src/fs/gnunet-service-fs.c b/src/fs/gnunet-service-fs.c
index 5ea1bb7c1..4d12b8bfd 100644
--- a/src/fs/gnunet-service-fs.c
+++ b/src/fs/gnunet-service-fs.c
@@ -162,14 +162,12 @@ static struct GNUNET_PeerIdentity my_id;
162 * @param tc task context 162 * @param tc task context
163 */ 163 */
164static void 164static void
165age_cover_counters (void *cls, 165age_cover_counters (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
166 const struct GNUNET_SCHEDULER_TaskContext *tc)
167{ 166{
168 GSF_cover_content_count = (GSF_cover_content_count * 15) / 16; 167 GSF_cover_content_count = (GSF_cover_content_count * 15) / 16;
169 GSF_cover_query_count = (GSF_cover_query_count * 15) / 16; 168 GSF_cover_query_count = (GSF_cover_query_count * 15) / 16;
170 cover_age_task = GNUNET_SCHEDULER_add_delayed (COVER_AGE_FREQUENCY, 169 cover_age_task = GNUNET_SCHEDULER_add_delayed (COVER_AGE_FREQUENCY,
171 &age_cover_counters, 170 &age_cover_counters, NULL);
172 NULL);
173} 171}
174 172
175 173
@@ -186,8 +184,7 @@ GSF_update_datastore_delay_ (struct GNUNET_TIME_Absolute start)
186 struct GNUNET_TIME_Relative delay; 184 struct GNUNET_TIME_Relative delay;
187 185
188 delay = GNUNET_TIME_absolute_get_duration (start); 186 delay = GNUNET_TIME_absolute_get_duration (start);
189 GNUNET_LOAD_update (datastore_get_load, 187 GNUNET_LOAD_update (datastore_get_load, delay.rel_value);
190 delay.rel_value);
191} 188}
192 189
193 190
@@ -207,9 +204,9 @@ GSF_test_get_load_too_high_ (uint32_t priority)
207 204
208 ld = GNUNET_LOAD_get_load (datastore_get_load); 205 ld = GNUNET_LOAD_get_load (datastore_get_load);
209 if (ld < 1) 206 if (ld < 1)
210 return GNUNET_SYSERR; 207 return GNUNET_SYSERR;
211 if (ld <= priority) 208 if (ld <= priority)
212 return GNUNET_NO; 209 return GNUNET_NO;
213 return GNUNET_YES; 210 return GNUNET_YES;
214} 211}
215 212
@@ -227,18 +224,18 @@ GSF_test_get_load_too_high_ (uint32_t priority)
227 */ 224 */
228static int 225static int
229handle_p2p_put (void *cls, 226handle_p2p_put (void *cls,
230 const struct GNUNET_PeerIdentity *other, 227 const struct GNUNET_PeerIdentity *other,
231 const struct GNUNET_MessageHeader *message, 228 const struct GNUNET_MessageHeader *message,
232 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 229 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
233{ 230{
234 struct GSF_ConnectedPeer *cp; 231 struct GSF_ConnectedPeer *cp;
235 232
236 cp = GSF_peer_get_ (other); 233 cp = GSF_peer_get_ (other);
237 if (NULL == cp) 234 if (NULL == cp)
238 { 235 {
239 GNUNET_break (0); 236 GNUNET_break (0);
240 return GNUNET_OK; 237 return GNUNET_OK;
241 } 238 }
242 GSF_cover_content_count++; 239 GSF_cover_content_count++;
243 return GSF_handle_p2p_content_ (cp, message); 240 return GSF_handle_p2p_content_ (cp, message);
244} 241}
@@ -255,9 +252,9 @@ handle_p2p_put (void *cls,
255 */ 252 */
256static void 253static void
257consider_request_for_forwarding (void *cls, 254consider_request_for_forwarding (void *cls,
258 const struct GNUNET_PeerIdentity *peer, 255 const struct GNUNET_PeerIdentity *peer,
259 struct GSF_ConnectedPeer *cp, 256 struct GSF_ConnectedPeer *cp,
260 const struct GSF_PeerPerformanceData *ppd) 257 const struct GSF_PeerPerformanceData *ppd)
261{ 258{
262 struct GSF_PendingRequest *pr = cls; 259 struct GSF_PendingRequest *pr = cls;
263 260
@@ -277,13 +274,12 @@ consider_request_for_forwarding (void *cls,
277 */ 274 */
278static void 275static void
279consider_forwarding (void *cls, 276consider_forwarding (void *cls,
280 struct GSF_PendingRequest *pr, 277 struct GSF_PendingRequest *pr,
281 enum GNUNET_BLOCK_EvaluationResult result) 278 enum GNUNET_BLOCK_EvaluationResult result)
282{ 279{
283 if (GNUNET_BLOCK_EVALUATION_OK_LAST == result) 280 if (GNUNET_BLOCK_EVALUATION_OK_LAST == result)
284 return; /* we're done... */ 281 return; /* we're done... */
285 GSF_iterate_connected_peers_ (&consider_request_for_forwarding, 282 GSF_iterate_connected_peers_ (&consider_request_for_forwarding, pr);
286 pr);
287} 283}
288 284
289 285
@@ -300,18 +296,16 @@ consider_forwarding (void *cls,
300 */ 296 */
301static int 297static int
302handle_p2p_get (void *cls, 298handle_p2p_get (void *cls,
303 const struct GNUNET_PeerIdentity *other, 299 const struct GNUNET_PeerIdentity *other,
304 const struct GNUNET_MessageHeader *message, 300 const struct GNUNET_MessageHeader *message,
305 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 301 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
306{ 302{
307 struct GSF_PendingRequest *pr; 303 struct GSF_PendingRequest *pr;
308 304
309 pr = GSF_handle_p2p_query_ (other, message); 305 pr = GSF_handle_p2p_query_ (other, message);
310 if (NULL == pr) 306 if (NULL == pr)
311 return GNUNET_SYSERR; 307 return GNUNET_SYSERR;
312 GSF_local_lookup_ (pr, 308 GSF_local_lookup_ (pr, &consider_forwarding, NULL);
313 &consider_forwarding,
314 NULL);
315 return GNUNET_OK; 309 return GNUNET_OK;
316} 310}
317 311
@@ -328,8 +322,8 @@ handle_p2p_get (void *cls,
328 */ 322 */
329static void 323static void
330start_p2p_processing (void *cls, 324start_p2p_processing (void *cls,
331 struct GSF_PendingRequest *pr, 325 struct GSF_PendingRequest *pr,
332 enum GNUNET_BLOCK_EvaluationResult result) 326 enum GNUNET_BLOCK_EvaluationResult result)
333{ 327{
334 struct GNUNET_SERVER_Client *client = cls; 328 struct GNUNET_SERVER_Client *client = cls;
335 struct GSF_PendingRequestData *prd; 329 struct GSF_PendingRequestData *prd;
@@ -337,19 +331,17 @@ start_p2p_processing (void *cls,
337 prd = GSF_pending_request_get_data_ (pr); 331 prd = GSF_pending_request_get_data_ (pr);
338#if DEBUG_FS_CLIENT 332#if DEBUG_FS_CLIENT
339 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 333 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
340 "Finished database lookup for local request `%s' with result %d\n", 334 "Finished database lookup for local request `%s' with result %d\n",
341 GNUNET_h2s (&prd->query), 335 GNUNET_h2s (&prd->query), result);
342 result);
343#endif 336#endif
344 GNUNET_SERVER_receive_done (client, 337 GNUNET_SERVER_receive_done (client, GNUNET_OK);
345 GNUNET_OK);
346 if (GNUNET_BLOCK_EVALUATION_OK_LAST == result) 338 if (GNUNET_BLOCK_EVALUATION_OK_LAST == result)
347 return; /* we're done, 'pr' was already destroyed... */ 339 return; /* we're done, 'pr' was already destroyed... */
348 if (0 != (GSF_PRO_LOCAL_ONLY & prd->options) ) 340 if (0 != (GSF_PRO_LOCAL_ONLY & prd->options))
349 { 341 {
350 GSF_pending_request_cancel_ (pr, GNUNET_YES); 342 GSF_pending_request_cancel_ (pr, GNUNET_YES);
351 return; 343 return;
352 } 344 }
353 GSF_dht_lookup_ (pr); 345 GSF_dht_lookup_ (pr);
354 consider_forwarding (NULL, pr, result); 346 consider_forwarding (NULL, pr, result);
355} 347}
@@ -364,20 +356,18 @@ start_p2p_processing (void *cls,
364 */ 356 */
365static void 357static void
366handle_start_search (void *cls, 358handle_start_search (void *cls,
367 struct GNUNET_SERVER_Client *client, 359 struct GNUNET_SERVER_Client *client,
368 const struct GNUNET_MessageHeader *message) 360 const struct GNUNET_MessageHeader *message)
369{ 361{
370 struct GSF_PendingRequest *pr; 362 struct GSF_PendingRequest *pr;
371 363
372 pr = GSF_local_client_start_search_handler_ (client, message); 364 pr = GSF_local_client_start_search_handler_ (client, message);
373 if (NULL == pr) 365 if (NULL == pr)
374 { 366 {
375 /* GNUNET_SERVER_receive_done was already called! */ 367 /* GNUNET_SERVER_receive_done was already called! */
376 return; 368 return;
377 } 369 }
378 GSF_local_lookup_ (pr, 370 GSF_local_lookup_ (pr, &start_p2p_processing, client);
379 &start_p2p_processing,
380 client);
381} 371}
382 372
383 373
@@ -388,14 +378,13 @@ handle_start_search (void *cls,
388 * @param tc unused 378 * @param tc unused
389 */ 379 */
390static void 380static void
391shutdown_task (void *cls, 381shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
392 const struct GNUNET_SCHEDULER_TaskContext *tc)
393{ 382{
394 if (NULL != GSF_core) 383 if (NULL != GSF_core)
395 { 384 {
396 GNUNET_CORE_disconnect (GSF_core); 385 GNUNET_CORE_disconnect (GSF_core);
397 GSF_core = NULL; 386 GSF_core = NULL;
398 } 387 }
399 GSF_put_done_ (); 388 GSF_put_done_ ();
400 GSF_push_done_ (); 389 GSF_push_done_ ();
401 GSF_pending_request_done_ (); 390 GSF_pending_request_done_ ();
@@ -412,10 +401,10 @@ shutdown_task (void *cls,
412 GNUNET_STATISTICS_destroy (GSF_stats, GNUNET_NO); 401 GNUNET_STATISTICS_destroy (GSF_stats, GNUNET_NO);
413 GSF_stats = NULL; 402 GSF_stats = NULL;
414 if (GNUNET_SCHEDULER_NO_TASK != cover_age_task) 403 if (GNUNET_SCHEDULER_NO_TASK != cover_age_task)
415 { 404 {
416 GNUNET_SCHEDULER_cancel (cover_age_task); 405 GNUNET_SCHEDULER_cancel (cover_age_task);
417 cover_age_task = GNUNET_SCHEDULER_NO_TASK; 406 cover_age_task = GNUNET_SCHEDULER_NO_TASK;
418 } 407 }
419 GNUNET_FS_indexing_done (); 408 GNUNET_FS_indexing_done ();
420 GNUNET_LOAD_value_free (datastore_get_load); 409 GNUNET_LOAD_value_free (datastore_get_load);
421 datastore_get_load = NULL; 410 datastore_get_load = NULL;
@@ -436,11 +425,11 @@ shutdown_task (void *cls,
436 */ 425 */
437static int 426static int
438consider_peer_for_forwarding (void *cls, 427consider_peer_for_forwarding (void *cls,
439 const GNUNET_HashCode *key, 428 const GNUNET_HashCode * key,
440 struct GSF_PendingRequest *pr) 429 struct GSF_PendingRequest *pr)
441{ 430{
442 struct GSF_ConnectedPeer *cp = cls; 431 struct GSF_ConnectedPeer *cp = cls;
443 432
444 GSF_plan_add_ (cp, pr); 433 GSF_plan_add_ (cp, pr);
445 return GNUNET_YES; 434 return GNUNET_YES;
446} 435}
@@ -453,20 +442,19 @@ consider_peer_for_forwarding (void *cls,
453 * @param peer peer identity this notification is about 442 * @param peer peer identity this notification is about
454 * @param atsi performance information 443 * @param atsi performance information
455 */ 444 */
456static void 445static void
457peer_connect_handler (void *cls, 446peer_connect_handler (void *cls,
458 const struct GNUNET_PeerIdentity *peer, 447 const struct GNUNET_PeerIdentity *peer,
459 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 448 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
460{ 449{
461 struct GSF_ConnectedPeer *cp; 450 struct GSF_ConnectedPeer *cp;
462 451
463 if (0 == memcmp (&my_id, peer, sizeof (struct GNUNET_PeerIdentity))) 452 if (0 == memcmp (&my_id, peer, sizeof (struct GNUNET_PeerIdentity)))
464 return; 453 return;
465 cp = GSF_peer_connect_handler_ (peer, atsi); 454 cp = GSF_peer_connect_handler_ (peer, atsi);
466 if (NULL == cp) 455 if (NULL == cp)
467 return; 456 return;
468 GSF_iterate_pending_requests_ (&consider_peer_for_forwarding, 457 GSF_iterate_pending_requests_ (&consider_peer_for_forwarding, cp);
469 cp);
470} 458}
471 459
472 460
@@ -484,12 +472,10 @@ peer_connect_handler (void *cls,
484 */ 472 */
485static void 473static void
486peer_init_handler (void *cls, 474peer_init_handler (void *cls,
487 struct GNUNET_CORE_Handle * server, 475 struct GNUNET_CORE_Handle *server,
488 const struct GNUNET_PeerIdentity * 476 const struct GNUNET_PeerIdentity *my_identity,
489 my_identity, 477 const struct
490 const struct 478 GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
491 GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *
492 publicKey)
493{ 479{
494 my_id = *my_identity; 480 my_id = *my_identity;
495} 481}
@@ -503,59 +489,53 @@ peer_init_handler (void *cls,
503 */ 489 */
504static int 490static int
505main_init (struct GNUNET_SERVER_Handle *server, 491main_init (struct GNUNET_SERVER_Handle *server,
506 const struct GNUNET_CONFIGURATION_Handle *c) 492 const struct GNUNET_CONFIGURATION_Handle *c)
507{ 493{
508 static const struct GNUNET_CORE_MessageHandler p2p_handlers[] = 494 static const struct GNUNET_CORE_MessageHandler p2p_handlers[] = {
509 { 495 {&handle_p2p_get,
510 { &handle_p2p_get, 496 GNUNET_MESSAGE_TYPE_FS_GET, 0},
511 GNUNET_MESSAGE_TYPE_FS_GET, 0 }, 497 {&handle_p2p_put,
512 { &handle_p2p_put, 498 GNUNET_MESSAGE_TYPE_FS_PUT, 0},
513 GNUNET_MESSAGE_TYPE_FS_PUT, 0 }, 499 {&GSF_handle_p2p_migration_stop_,
514 { &GSF_handle_p2p_migration_stop_, 500 GNUNET_MESSAGE_TYPE_FS_MIGRATION_STOP,
515 GNUNET_MESSAGE_TYPE_FS_MIGRATION_STOP, 501 sizeof (struct MigrationStopMessage)},
516 sizeof (struct MigrationStopMessage) }, 502 {NULL, 0, 0}
517 { NULL, 0, 0 } 503 };
518 };
519 static const struct GNUNET_SERVER_MessageHandler handlers[] = { 504 static const struct GNUNET_SERVER_MessageHandler handlers[] = {
520 {&GNUNET_FS_handle_index_start, NULL, 505 {&GNUNET_FS_handle_index_start, NULL,
521 GNUNET_MESSAGE_TYPE_FS_INDEX_START, 0}, 506 GNUNET_MESSAGE_TYPE_FS_INDEX_START, 0},
522 {&GNUNET_FS_handle_index_list_get, NULL, 507 {&GNUNET_FS_handle_index_list_get, NULL,
523 GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_GET, sizeof(struct GNUNET_MessageHeader) }, 508 GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_GET,
524 {&GNUNET_FS_handle_unindex, NULL, GNUNET_MESSAGE_TYPE_FS_UNINDEX, 509 sizeof (struct GNUNET_MessageHeader)},
525 sizeof (struct UnindexMessage) }, 510 {&GNUNET_FS_handle_unindex, NULL, GNUNET_MESSAGE_TYPE_FS_UNINDEX,
526 {&handle_start_search, NULL, GNUNET_MESSAGE_TYPE_FS_START_SEARCH, 511 sizeof (struct UnindexMessage)},
527 0 }, 512 {&handle_start_search, NULL, GNUNET_MESSAGE_TYPE_FS_START_SEARCH,
513 0},
528 {NULL, NULL, 0, 0} 514 {NULL, NULL, 0, 0}
529 }; 515 };
530 516
531 GSF_core = GNUNET_CORE_connect (GSF_cfg, 517 GSF_core = GNUNET_CORE_connect (GSF_cfg, 2, /* larger? */
532 2, /* larger? */ 518 NULL,
533 NULL, 519 &peer_init_handler,
534 &peer_init_handler, 520 &peer_connect_handler,
535 &peer_connect_handler, 521 &GSF_peer_disconnect_handler_,
536 &GSF_peer_disconnect_handler_, 522 &GSF_peer_status_handler_,
537 &GSF_peer_status_handler_, 523 NULL, GNUNET_NO,
538 NULL, GNUNET_NO, 524 NULL, GNUNET_NO, p2p_handlers);
539 NULL, GNUNET_NO,
540 p2p_handlers);
541 if (NULL == GSF_core) 525 if (NULL == GSF_core)
542 { 526 {
543 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 527 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
544 _("Failed to connect to `%s' service.\n"), 528 _("Failed to connect to `%s' service.\n"), "core");
545 "core"); 529 return GNUNET_SYSERR;
546 return GNUNET_SYSERR; 530 }
547 } 531 GNUNET_SERVER_disconnect_notify (server,
548 GNUNET_SERVER_disconnect_notify (server, 532 &GSF_client_disconnect_handler_, NULL);
549 &GSF_client_disconnect_handler_,
550 NULL);
551 GNUNET_SERVER_add_handlers (server, handlers); 533 GNUNET_SERVER_add_handlers (server, handlers);
552 cover_age_task = GNUNET_SCHEDULER_add_delayed (COVER_AGE_FREQUENCY, 534 cover_age_task = GNUNET_SCHEDULER_add_delayed (COVER_AGE_FREQUENCY,
553 &age_cover_counters, 535 &age_cover_counters, NULL);
554 NULL);
555 datastore_get_load = GNUNET_LOAD_value_init (DATASTORE_LOAD_AUTODECLINE); 536 datastore_get_load = GNUNET_LOAD_value_init (DATASTORE_LOAD_AUTODECLINE);
556 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 537 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
557 &shutdown_task, 538 &shutdown_task, NULL);
558 NULL);
559 return GNUNET_OK; 539 return GNUNET_OK;
560} 540}
561 541
@@ -573,37 +553,33 @@ run (void *cls,
573 const struct GNUNET_CONFIGURATION_Handle *cfg) 553 const struct GNUNET_CONFIGURATION_Handle *cfg)
574{ 554{
575 GSF_cfg = cfg; 555 GSF_cfg = cfg;
576 GSF_enable_randomized_delays = GNUNET_CONFIGURATION_get_value_yesno (cfg, "fs", "DELAY"); 556 GSF_enable_randomized_delays =
557 GNUNET_CONFIGURATION_get_value_yesno (cfg, "fs", "DELAY");
577 GSF_dsh = GNUNET_DATASTORE_connect (cfg); 558 GSF_dsh = GNUNET_DATASTORE_connect (cfg);
578 if (NULL == GSF_dsh) 559 if (NULL == GSF_dsh)
579 { 560 {
580 GNUNET_SCHEDULER_shutdown (); 561 GNUNET_SCHEDULER_shutdown ();
581 return; 562 return;
582 } 563 }
583 GSF_rt_entry_lifetime = GNUNET_LOAD_value_init (GNUNET_TIME_UNIT_FOREVER_REL); 564 GSF_rt_entry_lifetime = GNUNET_LOAD_value_init (GNUNET_TIME_UNIT_FOREVER_REL);
584 GSF_stats = GNUNET_STATISTICS_create ("fs", cfg); 565 GSF_stats = GNUNET_STATISTICS_create ("fs", cfg);
585 block_cfg = GNUNET_CONFIGURATION_create (); 566 block_cfg = GNUNET_CONFIGURATION_create ();
586 GNUNET_CONFIGURATION_set_value_string (block_cfg, 567 GNUNET_CONFIGURATION_set_value_string (block_cfg, "block", "PLUGINS", "fs");
587 "block",
588 "PLUGINS",
589 "fs");
590 GSF_block_ctx = GNUNET_BLOCK_context_create (block_cfg); 568 GSF_block_ctx = GNUNET_BLOCK_context_create (block_cfg);
591 GNUNET_assert (NULL != GSF_block_ctx); 569 GNUNET_assert (NULL != GSF_block_ctx);
592 GSF_dht = GNUNET_DHT_connect (cfg, 570 GSF_dht = GNUNET_DHT_connect (cfg, FS_DHT_HT_SIZE);
593 FS_DHT_HT_SIZE);
594 GSF_plan_init (); 571 GSF_plan_init ();
595 GSF_pending_request_init_ (); 572 GSF_pending_request_init_ ();
596 GSF_connected_peer_init_ (); 573 GSF_connected_peer_init_ ();
597 GSF_push_init_ (); 574 GSF_push_init_ ();
598 GSF_put_init_ (); 575 GSF_put_init_ ();
599 if ( (GNUNET_OK != GNUNET_FS_indexing_init (cfg, GSF_dsh)) || 576 if ((GNUNET_OK != GNUNET_FS_indexing_init (cfg, GSF_dsh)) ||
600 577 (GNUNET_OK != main_init (server, cfg)))
601 (GNUNET_OK != main_init (server, cfg)) ) 578 {
602 { 579 GNUNET_SCHEDULER_shutdown ();
603 GNUNET_SCHEDULER_shutdown (); 580 shutdown_task (NULL, NULL);
604 shutdown_task (NULL, NULL); 581 return;
605 return; 582 }
606 }
607} 583}
608 584
609 585
@@ -621,8 +597,7 @@ main (int argc, char *const *argv)
621 GNUNET_SERVICE_run (argc, 597 GNUNET_SERVICE_run (argc,
622 argv, 598 argv,
623 "fs", 599 "fs",
624 GNUNET_SERVICE_OPTION_NONE, 600 GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1;
625 &run, NULL)) ? 0 : 1;
626} 601}
627 602
628/* end of gnunet-service-fs.c */ 603/* end of gnunet-service-fs.c */
diff --git a/src/fs/gnunet-service-fs.h b/src/fs/gnunet-service-fs.h
index bee814318..56604185f 100644
--- a/src/fs/gnunet-service-fs.h
+++ b/src/fs/gnunet-service-fs.h
@@ -167,8 +167,7 @@ extern int GSF_enable_randomized_delays;
167 * GNUNET_NO to process normally (load normal) 167 * GNUNET_NO to process normally (load normal)
168 * GNUNET_SYSERR to process for free (load low) 168 * GNUNET_SYSERR to process for free (load low)
169 */ 169 */
170int 170int GSF_test_get_load_too_high_ (uint32_t priority);
171GSF_test_get_load_too_high_ (uint32_t priority);
172 171
173 172
174/** 173/**
@@ -177,8 +176,7 @@ GSF_test_get_load_too_high_ (uint32_t priority);
177 * 176 *
178 * @param start time when the datastore request was issued 177 * @param start time when the datastore request was issued
179 */ 178 */
180void 179void GSF_update_datastore_delay_ (struct GNUNET_TIME_Absolute start);
181GSF_update_datastore_delay_ (struct GNUNET_TIME_Absolute start);
182 180
183 181
184 182
diff --git a/src/fs/gnunet-service-fs_cp.c b/src/fs/gnunet-service-fs_cp.c
index ea8a84dfe..4e57455b2 100644
--- a/src/fs/gnunet-service-fs_cp.c
+++ b/src/fs/gnunet-service-fs_cp.c
@@ -134,7 +134,7 @@ struct GSF_DelayedHandle
134 /** 134 /**
135 * Kept in a doubly-linked list. 135 * Kept in a doubly-linked list.
136 */ 136 */
137 struct GSF_DelayedHandle *next; 137 struct GSF_DelayedHandle *next;
138 138
139 /** 139 /**
140 * Kept in a doubly-linked list. 140 * Kept in a doubly-linked list.
@@ -160,7 +160,7 @@ struct GSF_DelayedHandle
160 * Size of the message. 160 * Size of the message.
161 */ 161 */
162 size_t msize; 162 size_t msize;
163 163
164}; 164};
165 165
166 166
@@ -174,7 +174,7 @@ struct PeerRequest
174 * Handle to generic request. 174 * Handle to generic request.
175 */ 175 */
176 struct GSF_PendingRequest *pr; 176 struct GSF_PendingRequest *pr;
177 177
178 /** 178 /**
179 * Handle to specific peer. 179 * Handle to specific peer.
180 */ 180 */
@@ -191,7 +191,7 @@ struct PeerRequest
191/** 191/**
192 * A connected peer. 192 * A connected peer.
193 */ 193 */
194struct GSF_ConnectedPeer 194struct GSF_ConnectedPeer
195{ 195{
196 196
197 /** 197 /**
@@ -330,17 +330,17 @@ get_latency (const struct GNUNET_TRANSPORT_ATS_Information *atsi)
330{ 330{
331 if (atsi == NULL) 331 if (atsi == NULL)
332 return GNUNET_TIME_UNIT_SECONDS; 332 return GNUNET_TIME_UNIT_SECONDS;
333 while ( (ntohl (atsi->type) != GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR) && 333 while ((ntohl (atsi->type) != GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR) &&
334 (ntohl (atsi->type) != GNUNET_TRANSPORT_ATS_QUALITY_NET_DELAY) ) 334 (ntohl (atsi->type) != GNUNET_TRANSPORT_ATS_QUALITY_NET_DELAY))
335 atsi++; 335 atsi++;
336 if (ntohl (atsi->type) == GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR) 336 if (ntohl (atsi->type) == GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR)
337 { 337 {
338 GNUNET_break (0); 338 GNUNET_break (0);
339 /* how can we not have latency data? */ 339 /* how can we not have latency data? */
340 return GNUNET_TIME_UNIT_SECONDS; 340 return GNUNET_TIME_UNIT_SECONDS;
341 } 341 }
342 return GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 342 return GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
343 ntohl (atsi->value)); 343 ntohl (atsi->value));
344} 344}
345 345
346 346
@@ -352,13 +352,12 @@ get_latency (const struct GNUNET_TRANSPORT_ATS_Information *atsi)
352 */ 352 */
353static void 353static void
354update_atsi (struct GSF_ConnectedPeer *cp, 354update_atsi (struct GSF_ConnectedPeer *cp,
355 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 355 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
356{ 356{
357 struct GNUNET_TIME_Relative latency; 357 struct GNUNET_TIME_Relative latency;
358 358
359 latency = get_latency (atsi); 359 latency = get_latency (atsi);
360 GNUNET_LOAD_value_set_decline (cp->ppd.transmission_delay, 360 GNUNET_LOAD_value_set_decline (cp->ppd.transmission_delay, latency);
361 latency);
362 /* LATER: merge atsi into cp's performance data (if we ever care...) */ 361 /* LATER: merge atsi into cp's performance data (if we ever care...) */
363} 362}
364 363
@@ -384,10 +383,7 @@ GSF_get_peer_performance_data_ (struct GSF_ConnectedPeer *cp)
384 * @param buf where to copy the message 383 * @param buf where to copy the message
385 * @return number of bytes copied to buf 384 * @return number of bytes copied to buf
386 */ 385 */
387static size_t 386static size_t peer_transmit_ready_cb (void *cls, size_t size, void *buf);
388peer_transmit_ready_cb (void *cls,
389 size_t size,
390 void *buf);
391 387
392 388
393 389
@@ -406,11 +402,11 @@ peer_transmit_ready_cb (void *cls,
406 */ 402 */
407static void 403static void
408core_reserve_callback (void *cls, 404core_reserve_callback (void *cls,
409 const struct GNUNET_PeerIdentity *peer, 405 const struct GNUNET_PeerIdentity *peer,
410 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, 406 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
411 int32_t amount, 407 int32_t amount,
412 struct GNUNET_TIME_Relative res_delay, 408 struct GNUNET_TIME_Relative res_delay,
413 uint64_t preference); 409 uint64_t preference);
414 410
415 411
416/** 412/**
@@ -426,43 +422,38 @@ schedule_transmission (struct GSF_PeerTransmitHandle *pth)
426 struct GNUNET_PeerIdentity target; 422 struct GNUNET_PeerIdentity target;
427 uint64_t ip; 423 uint64_t ip;
428 424
429 if ( (NULL != pth->cth) || 425 if ((NULL != pth->cth) || (0 != pth->cth_in_progress))
430 (0 != pth->cth_in_progress) ) 426 return; /* already done */
431 return; /* already done */
432 cp = pth->cp; 427 cp = pth->cp;
433 GNUNET_assert (0 != cp->ppd.pid); 428 GNUNET_assert (0 != cp->ppd.pid);
434 GNUNET_PEER_resolve (cp->ppd.pid, 429 GNUNET_PEER_resolve (cp->ppd.pid, &target);
435 &target); 430 if ((GNUNET_YES == pth->is_query) && (GNUNET_YES != pth->was_reserved))
436 if ( (GNUNET_YES == pth->is_query) && 431 {
437 (GNUNET_YES != pth->was_reserved) ) 432 /* query, need reservation */
438 { 433 if (GNUNET_YES != cp->did_reserve)
439 /* query, need reservation */ 434 return; /* not ready */
440 if (GNUNET_YES != cp->did_reserve) 435 cp->did_reserve = GNUNET_NO;
441 return; /* not ready */ 436 /* reservation already done! */
442 cp->did_reserve = GNUNET_NO; 437 pth->was_reserved = GNUNET_YES;
443 /* reservation already done! */ 438 ip = cp->inc_preference;
444 pth->was_reserved = GNUNET_YES; 439 cp->inc_preference = 0;
445 ip = cp->inc_preference; 440 cp->irc = GNUNET_CORE_peer_change_preference (GSF_core,
446 cp->inc_preference = 0; 441 &target,
447 cp->irc = GNUNET_CORE_peer_change_preference (GSF_core, 442 GNUNET_TIME_UNIT_FOREVER_REL,
448 &target, 443 GNUNET_BANDWIDTH_VALUE_MAX,
449 GNUNET_TIME_UNIT_FOREVER_REL, 444 DBLOCK_SIZE,
450 GNUNET_BANDWIDTH_VALUE_MAX, 445 ip,
451 DBLOCK_SIZE, 446 &core_reserve_callback, cp);
452 ip, 447 }
453 &core_reserve_callback,
454 cp);
455 }
456 GNUNET_assert (pth->cth == NULL); 448 GNUNET_assert (pth->cth == NULL);
457 pth->cth_in_progress++; 449 pth->cth_in_progress++;
458 pth->cth = GNUNET_CORE_notify_transmit_ready (GSF_core, 450 pth->cth = GNUNET_CORE_notify_transmit_ready (GSF_core,
459 GNUNET_YES, 451 GNUNET_YES,
460 pth->priority, 452 pth->priority,
461 GNUNET_TIME_absolute_get_remaining (pth->timeout), 453 GNUNET_TIME_absolute_get_remaining
462 &target, 454 (pth->timeout), &target,
463 pth->size, 455 pth->size,
464 &peer_transmit_ready_cb, 456 &peer_transmit_ready_cb, pth);
465 pth);
466 GNUNET_assert (0 < pth->cth_in_progress--); 457 GNUNET_assert (0 < pth->cth_in_progress--);
467} 458}
468 459
@@ -476,46 +467,43 @@ schedule_transmission (struct GSF_PeerTransmitHandle *pth)
476 * @return number of bytes copied to buf 467 * @return number of bytes copied to buf
477 */ 468 */
478static size_t 469static size_t
479peer_transmit_ready_cb (void *cls, 470peer_transmit_ready_cb (void *cls, size_t size, void *buf)
480 size_t size,
481 void *buf)
482{ 471{
483 struct GSF_PeerTransmitHandle *pth = cls; 472 struct GSF_PeerTransmitHandle *pth = cls;
484 struct GSF_PeerTransmitHandle *pos; 473 struct GSF_PeerTransmitHandle *pos;
485 struct GSF_ConnectedPeer *cp; 474 struct GSF_ConnectedPeer *cp;
486 size_t ret; 475 size_t ret;
487 476
488 GNUNET_assert ( (NULL == buf) || 477 GNUNET_assert ((NULL == buf) || (pth->size <= size));
489 (pth->size <= size) );
490 pth->cth = NULL; 478 pth->cth = NULL;
491 if (pth->timeout_task != GNUNET_SCHEDULER_NO_TASK) 479 if (pth->timeout_task != GNUNET_SCHEDULER_NO_TASK)
492 { 480 {
493 GNUNET_SCHEDULER_cancel (pth->timeout_task); 481 GNUNET_SCHEDULER_cancel (pth->timeout_task);
494 pth->timeout_task = GNUNET_SCHEDULER_NO_TASK; 482 pth->timeout_task = GNUNET_SCHEDULER_NO_TASK;
495 } 483 }
496 cp = pth->cp; 484 cp = pth->cp;
497 GNUNET_CONTAINER_DLL_remove (cp->pth_head, 485 GNUNET_CONTAINER_DLL_remove (cp->pth_head, cp->pth_tail, pth);
498 cp->pth_tail,
499 pth);
500 if (GNUNET_YES == pth->is_query) 486 if (GNUNET_YES == pth->is_query)
501 { 487 {
502 cp->ppd.last_request_times[(cp->last_request_times_off++) % MAX_QUEUE_PER_PEER] = GNUNET_TIME_absolute_get (); 488 cp->ppd.last_request_times[(cp->last_request_times_off++) %
503 GNUNET_assert (0 < cp->ppd.pending_queries--); 489 MAX_QUEUE_PER_PEER] =
504 } 490 GNUNET_TIME_absolute_get ();
491 GNUNET_assert (0 < cp->ppd.pending_queries--);
492 }
505 else if (GNUNET_NO == pth->is_query) 493 else if (GNUNET_NO == pth->is_query)
506 { 494 {
507 GNUNET_assert (0 < cp->ppd.pending_replies--); 495 GNUNET_assert (0 < cp->ppd.pending_replies--);
508 } 496 }
509 GNUNET_LOAD_update (cp->ppd.transmission_delay, 497 GNUNET_LOAD_update (cp->ppd.transmission_delay,
510 GNUNET_TIME_absolute_get_duration (pth->transmission_request_start_time).rel_value); 498 GNUNET_TIME_absolute_get_duration
511 ret = pth->gmc (pth->gmc_cls, 499 (pth->transmission_request_start_time).rel_value);
512 size, buf); 500 ret = pth->gmc (pth->gmc_cls, size, buf);
513 GNUNET_assert (NULL == pth->cth); 501 GNUNET_assert (NULL == pth->cth);
514 for (pos = cp->pth_head; pos != NULL; pos = pos->next) 502 for (pos = cp->pth_head; pos != NULL; pos = pos->next)
515 { 503 {
516 GNUNET_assert (pos != pth); 504 GNUNET_assert (pos != pth);
517 schedule_transmission (pos); 505 schedule_transmission (pos);
518 } 506 }
519 GNUNET_assert (pth->cth == NULL); 507 GNUNET_assert (pth->cth == NULL);
520 GNUNET_assert (pth->cth_in_progress == 0); 508 GNUNET_assert (pth->cth_in_progress == 0);
521 GNUNET_free (pth); 509 GNUNET_free (pth);
@@ -530,26 +518,22 @@ peer_transmit_ready_cb (void *cls,
530 * @param tc scheduler context 518 * @param tc scheduler context
531 */ 519 */
532static void 520static void
533retry_reservation (void *cls, 521retry_reservation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
534 const struct GNUNET_SCHEDULER_TaskContext *tc)
535{ 522{
536 struct GSF_ConnectedPeer *cp = cls; 523 struct GSF_ConnectedPeer *cp = cls;
537 uint64_t ip; 524 uint64_t ip;
538 struct GNUNET_PeerIdentity target; 525 struct GNUNET_PeerIdentity target;
539 526
540 GNUNET_PEER_resolve (cp->ppd.pid, 527 GNUNET_PEER_resolve (cp->ppd.pid, &target);
541 &target);
542 cp->irc_delay_task = GNUNET_SCHEDULER_NO_TASK; 528 cp->irc_delay_task = GNUNET_SCHEDULER_NO_TASK;
543 ip = cp->inc_preference; 529 ip = cp->inc_preference;
544 cp->inc_preference = 0; 530 cp->inc_preference = 0;
545 cp->irc = GNUNET_CORE_peer_change_preference (GSF_core, 531 cp->irc = GNUNET_CORE_peer_change_preference (GSF_core,
546 &target, 532 &target,
547 GNUNET_TIME_UNIT_FOREVER_REL, 533 GNUNET_TIME_UNIT_FOREVER_REL,
548 GNUNET_BANDWIDTH_VALUE_MAX, 534 GNUNET_BANDWIDTH_VALUE_MAX,
549 DBLOCK_SIZE, 535 DBLOCK_SIZE,
550 ip, 536 ip, &core_reserve_callback, cp);
551 &core_reserve_callback,
552 cp);
553} 537}
554 538
555 539
@@ -567,40 +551,37 @@ retry_reservation (void *cls,
567 */ 551 */
568static void 552static void
569core_reserve_callback (void *cls, 553core_reserve_callback (void *cls,
570 const struct GNUNET_PeerIdentity *peer, 554 const struct GNUNET_PeerIdentity *peer,
571 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, 555 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
572 int32_t amount, 556 int32_t amount,
573 struct GNUNET_TIME_Relative res_delay, 557 struct GNUNET_TIME_Relative res_delay,
574 uint64_t preference) 558 uint64_t preference)
575{ 559{
576 struct GSF_ConnectedPeer *cp = cls; 560 struct GSF_ConnectedPeer *cp = cls;
577 struct GSF_PeerTransmitHandle *pth; 561 struct GSF_PeerTransmitHandle *pth;
578 562
579 cp->irc = NULL; 563 cp->irc = NULL;
580 if (0 == amount) 564 if (0 == amount)
581 { 565 {
582 cp->irc_delay_task = GNUNET_SCHEDULER_add_delayed (res_delay, 566 cp->irc_delay_task = GNUNET_SCHEDULER_add_delayed (res_delay,
583 &retry_reservation, 567 &retry_reservation, cp);
584 cp); 568 return;
585 return; 569 }
586 }
587 cp->did_reserve = GNUNET_YES; 570 cp->did_reserve = GNUNET_YES;
588 pth = cp->pth_head; 571 pth = cp->pth_head;
589 if ( (NULL != pth) && 572 if ((NULL != pth) && (NULL == pth->cth))
590 (NULL == pth->cth) ) 573 {
591 { 574 /* reservation success, try transmission now! */
592 /* reservation success, try transmission now! */ 575 pth->cth_in_progress++;
593 pth->cth_in_progress++; 576 pth->cth = GNUNET_CORE_notify_transmit_ready (GSF_core,
594 pth->cth = GNUNET_CORE_notify_transmit_ready (GSF_core, 577 GNUNET_YES,
595 GNUNET_YES, 578 pth->priority,
596 pth->priority, 579 GNUNET_TIME_absolute_get_remaining
597 GNUNET_TIME_absolute_get_remaining (pth->timeout), 580 (pth->timeout), peer,
598 peer, 581 pth->size,
599 pth->size, 582 &peer_transmit_ready_cb, pth);
600 &peer_transmit_ready_cb, 583 GNUNET_assert (0 < pth->cth_in_progress--);
601 pth); 584 }
602 GNUNET_assert (0 < pth->cth_in_progress--);
603 }
604} 585}
605 586
606 587
@@ -614,7 +595,7 @@ core_reserve_callback (void *cls,
614 */ 595 */
615struct GSF_ConnectedPeer * 596struct GSF_ConnectedPeer *
616GSF_peer_connect_handler_ (const struct GNUNET_PeerIdentity *peer, 597GSF_peer_connect_handler_ (const struct GNUNET_PeerIdentity *peer,
617 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 598 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
618{ 599{
619 struct GSF_ConnectedPeer *cp; 600 struct GSF_ConnectedPeer *cp;
620 char *fn; 601 char *fn;
@@ -624,13 +605,11 @@ GSF_peer_connect_handler_ (const struct GNUNET_PeerIdentity *peer,
624 cp->ppd.pid = GNUNET_PEER_intern (peer); 605 cp->ppd.pid = GNUNET_PEER_intern (peer);
625 cp->ppd.transmission_delay = GNUNET_LOAD_value_init (GNUNET_TIME_UNIT_ZERO); 606 cp->ppd.transmission_delay = GNUNET_LOAD_value_init (GNUNET_TIME_UNIT_ZERO);
626 cp->irc = GNUNET_CORE_peer_change_preference (GSF_core, 607 cp->irc = GNUNET_CORE_peer_change_preference (GSF_core,
627 peer, 608 peer,
628 GNUNET_TIME_UNIT_FOREVER_REL, 609 GNUNET_TIME_UNIT_FOREVER_REL,
629 GNUNET_BANDWIDTH_VALUE_MAX, 610 GNUNET_BANDWIDTH_VALUE_MAX,
630 DBLOCK_SIZE, 611 DBLOCK_SIZE,
631 0, 612 0, &core_reserve_callback, cp);
632 &core_reserve_callback,
633 cp);
634 fn = get_trust_filename (peer); 613 fn = get_trust_filename (peer);
635 if ((GNUNET_DISK_file_test (fn) == GNUNET_YES) && 614 if ((GNUNET_DISK_file_test (fn) == GNUNET_YES) &&
636 (sizeof (trust) == GNUNET_DISK_fn_read (fn, &trust, sizeof (trust)))) 615 (sizeof (trust) == GNUNET_DISK_fn_read (fn, &trust, sizeof (trust))))
@@ -638,10 +617,10 @@ GSF_peer_connect_handler_ (const struct GNUNET_PeerIdentity *peer,
638 GNUNET_free (fn); 617 GNUNET_free (fn);
639 cp->request_map = GNUNET_CONTAINER_multihashmap_create (128); 618 cp->request_map = GNUNET_CONTAINER_multihashmap_create (128);
640 GNUNET_break (GNUNET_OK == 619 GNUNET_break (GNUNET_OK ==
641 GNUNET_CONTAINER_multihashmap_put (cp_map, 620 GNUNET_CONTAINER_multihashmap_put (cp_map,
642 &peer->hashPubKey, 621 &peer->hashPubKey,
643 cp, 622 cp,
644 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 623 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
645 update_atsi (cp, atsi); 624 update_atsi (cp, atsi);
646 GSF_push_start_ (cp); 625 GSF_push_start_ (cp);
647 return cp; 626 return cp;
@@ -656,23 +635,20 @@ GSF_peer_connect_handler_ (const struct GNUNET_PeerIdentity *peer,
656 * @param tc scheduler context 635 * @param tc scheduler context
657 */ 636 */
658static void 637static void
659revive_migration (void *cls, 638revive_migration (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
660 const struct GNUNET_SCHEDULER_TaskContext *tc)
661{ 639{
662 struct GSF_ConnectedPeer *cp = cls; 640 struct GSF_ConnectedPeer *cp = cls;
663 struct GNUNET_TIME_Relative bt; 641 struct GNUNET_TIME_Relative bt;
664 642
665 cp->mig_revive_task = GNUNET_SCHEDULER_NO_TASK; 643 cp->mig_revive_task = GNUNET_SCHEDULER_NO_TASK;
666 bt = GNUNET_TIME_absolute_get_remaining (cp->ppd.migration_blocked_until); 644 bt = GNUNET_TIME_absolute_get_remaining (cp->ppd.migration_blocked_until);
667 if (0 != bt.rel_value) 645 if (0 != bt.rel_value)
668 { 646 {
669 /* still time left... */ 647 /* still time left... */
670 cp->mig_revive_task 648 cp->mig_revive_task
671 = GNUNET_SCHEDULER_add_delayed (bt, 649 = GNUNET_SCHEDULER_add_delayed (bt, &revive_migration, cp);
672 &revive_migration, 650 return;
673 cp); 651 }
674 return;
675 }
676 GSF_push_start_ (cp); 652 GSF_push_start_ (cp);
677} 653}
678 654
@@ -686,9 +662,9 @@ revive_migration (void *cls,
686struct GSF_ConnectedPeer * 662struct GSF_ConnectedPeer *
687GSF_peer_get_ (const struct GNUNET_PeerIdentity *peer) 663GSF_peer_get_ (const struct GNUNET_PeerIdentity *peer)
688{ 664{
689 if (NULL == cp_map) return NULL; 665 if (NULL == cp_map)
690 return GNUNET_CONTAINER_multihashmap_get (cp_map, 666 return NULL;
691 &peer->hashPubKey); 667 return GNUNET_CONTAINER_multihashmap_get (cp_map, &peer->hashPubKey);
692} 668}
693 669
694 670
@@ -705,36 +681,33 @@ GSF_peer_get_ (const struct GNUNET_PeerIdentity *peer)
705 */ 681 */
706int 682int
707GSF_handle_p2p_migration_stop_ (void *cls, 683GSF_handle_p2p_migration_stop_ (void *cls,
708 const struct GNUNET_PeerIdentity *other, 684 const struct GNUNET_PeerIdentity *other,
709 const struct GNUNET_MessageHeader *message, 685 const struct GNUNET_MessageHeader *message,
710 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 686 const struct GNUNET_TRANSPORT_ATS_Information
687 *atsi)
711{ 688{
712 struct GSF_ConnectedPeer *cp; 689 struct GSF_ConnectedPeer *cp;
713 const struct MigrationStopMessage *msm; 690 const struct MigrationStopMessage *msm;
714 struct GNUNET_TIME_Relative bt; 691 struct GNUNET_TIME_Relative bt;
715 692
716 msm = (const struct MigrationStopMessage*) message; 693 msm = (const struct MigrationStopMessage *) message;
717 cp = GNUNET_CONTAINER_multihashmap_get (cp_map, 694 cp = GNUNET_CONTAINER_multihashmap_get (cp_map, &other->hashPubKey);
718 &other->hashPubKey);
719 if (cp == NULL) 695 if (cp == NULL)
720 { 696 {
721 GNUNET_break (0); 697 GNUNET_break (0);
722 return GNUNET_OK; 698 return GNUNET_OK;
723 } 699 }
724 bt = GNUNET_TIME_relative_ntoh (msm->duration); 700 bt = GNUNET_TIME_relative_ntoh (msm->duration);
725 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 701 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
726 _("Migration of content to peer `%s' blocked for %llu ms\n"), 702 _("Migration of content to peer `%s' blocked for %llu ms\n"),
727 GNUNET_i2s (other), 703 GNUNET_i2s (other), (unsigned long long) bt.rel_value);
728 (unsigned long long) bt.rel_value);
729 cp->ppd.migration_blocked_until = GNUNET_TIME_relative_to_absolute (bt); 704 cp->ppd.migration_blocked_until = GNUNET_TIME_relative_to_absolute (bt);
730 if (cp->mig_revive_task == GNUNET_SCHEDULER_NO_TASK) 705 if (cp->mig_revive_task == GNUNET_SCHEDULER_NO_TASK)
731 { 706 {
732 GSF_push_stop_ (cp); 707 GSF_push_stop_ (cp);
733 cp->mig_revive_task 708 cp->mig_revive_task
734 = GNUNET_SCHEDULER_add_delayed (bt, 709 = GNUNET_SCHEDULER_add_delayed (bt, &revive_migration, cp);
735 &revive_migration, 710 }
736 cp);
737 }
738 update_atsi (cp, atsi); 711 update_atsi (cp, atsi);
739 return GNUNET_OK; 712 return GNUNET_OK;
740} 713}
@@ -748,32 +721,28 @@ GSF_handle_p2p_migration_stop_ (void *cls,
748 * @param buf where to copy the message, NULL on error (peer disconnect) 721 * @param buf where to copy the message, NULL on error (peer disconnect)
749 * @return number of bytes copied to 'buf', can be 0 (without indicating an error) 722 * @return number of bytes copied to 'buf', can be 0 (without indicating an error)
750 */ 723 */
751static size_t 724static size_t
752copy_reply (void *cls, 725copy_reply (void *cls, size_t buf_size, void *buf)
753 size_t buf_size,
754 void *buf)
755{ 726{
756 struct PutMessage *pm = cls; 727 struct PutMessage *pm = cls;
757 size_t size; 728 size_t size;
758 729
759 if (buf != NULL) 730 if (buf != NULL)
760 { 731 {
761 GNUNET_assert (buf_size >= ntohs (pm->header.size)); 732 GNUNET_assert (buf_size >= ntohs (pm->header.size));
762 size = ntohs (pm->header.size); 733 size = ntohs (pm->header.size);
763 memcpy (buf, pm, size); 734 memcpy (buf, pm, size);
764 GNUNET_STATISTICS_update (GSF_stats, 735 GNUNET_STATISTICS_update (GSF_stats,
765 gettext_noop ("# replies transmitted to other peers"), 736 gettext_noop
766 1, 737 ("# replies transmitted to other peers"), 1,
767 GNUNET_NO); 738 GNUNET_NO);
768 } 739 }
769 else 740 else
770 { 741 {
771 size = 0; 742 size = 0;
772 GNUNET_STATISTICS_update (GSF_stats, 743 GNUNET_STATISTICS_update (GSF_stats,
773 gettext_noop ("# replies dropped"), 744 gettext_noop ("# replies dropped"), 1, GNUNET_NO);
774 1, 745 }
775 GNUNET_NO);
776 }
777 GNUNET_free (pm); 746 GNUNET_free (pm);
778 return size; 747 return size;
779} 748}
@@ -788,9 +757,7 @@ copy_reply (void *cls,
788 * @return GNUNET_YES (continue to iterate) 757 * @return GNUNET_YES (continue to iterate)
789 */ 758 */
790static int 759static int
791cancel_pending_request (void *cls, 760cancel_pending_request (void *cls, const GNUNET_HashCode * query, void *value)
792 const GNUNET_HashCode *query,
793 void *value)
794{ 761{
795 struct PeerRequest *peerreq = value; 762 struct PeerRequest *peerreq = value;
796 struct GSF_PendingRequest *pr = peerreq->pr; 763 struct GSF_PendingRequest *pr = peerreq->pr;
@@ -798,19 +765,17 @@ cancel_pending_request (void *cls,
798 struct GSF_PendingRequestData *prd; 765 struct GSF_PendingRequestData *prd;
799 766
800 if (peerreq->kill_task != GNUNET_SCHEDULER_NO_TASK) 767 if (peerreq->kill_task != GNUNET_SCHEDULER_NO_TASK)
801 { 768 {
802 GNUNET_SCHEDULER_cancel (peerreq->kill_task); 769 GNUNET_SCHEDULER_cancel (peerreq->kill_task);
803 peerreq->kill_task = GNUNET_SCHEDULER_NO_TASK; 770 peerreq->kill_task = GNUNET_SCHEDULER_NO_TASK;
804 } 771 }
805 GNUNET_STATISTICS_update (GSF_stats, 772 GNUNET_STATISTICS_update (GSF_stats,
806 gettext_noop ("# P2P searches active"), 773 gettext_noop ("# P2P searches active"),
807 -1, 774 -1, GNUNET_NO);
808 GNUNET_NO);
809 prd = GSF_pending_request_get_data_ (pr); 775 prd = GSF_pending_request_get_data_ (pr);
810 GNUNET_break (GNUNET_YES == 776 GNUNET_break (GNUNET_YES ==
811 GNUNET_CONTAINER_multihashmap_remove (cp->request_map, 777 GNUNET_CONTAINER_multihashmap_remove (cp->request_map,
812 &prd->query, 778 &prd->query, peerreq));
813 peerreq));
814 GSF_pending_request_cancel_ (pr, GNUNET_NO); 779 GSF_pending_request_cancel_ (pr, GNUNET_NO);
815 GNUNET_free (peerreq); 780 GNUNET_free (peerreq);
816 return GNUNET_OK; 781 return GNUNET_OK;
@@ -822,10 +787,9 @@ cancel_pending_request (void *cls,
822 * 787 *
823 * @param cls the request to free 788 * @param cls the request to free
824 * @param tc task context 789 * @param tc task context
825 */ 790 */
826static void 791static void
827peer_request_destroy (void *cls, 792peer_request_destroy (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
828 const struct GNUNET_SCHEDULER_TaskContext *tc)
829{ 793{
830 struct PeerRequest *peerreq = cls; 794 struct PeerRequest *peerreq = cls;
831 struct GSF_PendingRequest *pr = peerreq->pr; 795 struct GSF_PendingRequest *pr = peerreq->pr;
@@ -833,9 +797,7 @@ peer_request_destroy (void *cls,
833 797
834 peerreq->kill_task = GNUNET_SCHEDULER_NO_TASK; 798 peerreq->kill_task = GNUNET_SCHEDULER_NO_TASK;
835 prd = GSF_pending_request_get_data_ (pr); 799 prd = GSF_pending_request_get_data_ (pr);
836 cancel_pending_request (NULL, 800 cancel_pending_request (NULL, &prd->query, peerreq);
837 &prd->query,
838 peerreq);
839} 801}
840 802
841 803
@@ -846,27 +808,21 @@ peer_request_destroy (void *cls,
846 * @param tc scheduler context 808 * @param tc scheduler context
847 */ 809 */
848static void 810static void
849transmit_delayed_now (void *cls, 811transmit_delayed_now (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
850 const struct GNUNET_SCHEDULER_TaskContext *tc)
851{ 812{
852 struct GSF_DelayedHandle *dh = cls; 813 struct GSF_DelayedHandle *dh = cls;
853 struct GSF_ConnectedPeer *cp = dh->cp; 814 struct GSF_ConnectedPeer *cp = dh->cp;
854 815
855 GNUNET_CONTAINER_DLL_remove (cp->delayed_head, 816 GNUNET_CONTAINER_DLL_remove (cp->delayed_head, cp->delayed_tail, dh);
856 cp->delayed_tail,
857 dh);
858 if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason)) 817 if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
859 { 818 {
860 GNUNET_free (dh->pm); 819 GNUNET_free (dh->pm);
861 GNUNET_free (dh); 820 GNUNET_free (dh);
862 return; 821 return;
863 } 822 }
864 (void) GSF_peer_transmit_ (cp, GNUNET_NO, 823 (void) GSF_peer_transmit_ (cp, GNUNET_NO,
865 UINT32_MAX, 824 UINT32_MAX,
866 REPLY_TIMEOUT, 825 REPLY_TIMEOUT, dh->msize, &copy_reply, dh->pm);
867 dh->msize,
868 &copy_reply,
869 dh->pm);
870 GNUNET_free (dh); 826 GNUNET_free (dh);
871} 827}
872 828
@@ -883,12 +839,12 @@ get_randomized_delay ()
883 839
884 /* FIXME: replace 5000 with something relating to current observed P2P message latency */ 840 /* FIXME: replace 5000 with something relating to current observed P2P message latency */
885 ret = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 841 ret = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
886 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 842 GNUNET_CRYPTO_random_u32
887 5000)); 843 (GNUNET_CRYPTO_QUALITY_WEAK, 5000));
888 GNUNET_STATISTICS_update (GSF_stats, 844 GNUNET_STATISTICS_update (GSF_stats,
889 gettext_noop ("# artificial delays introduced (ms)"), 845 gettext_noop
890 ret.rel_value, 846 ("# artificial delays introduced (ms)"),
891 GNUNET_NO); 847 ret.rel_value, GNUNET_NO);
892 848
893 return ret; 849 return ret;
894} 850}
@@ -913,13 +869,12 @@ get_randomized_delay ()
913 */ 869 */
914static void 870static void
915handle_p2p_reply (void *cls, 871handle_p2p_reply (void *cls,
916 enum GNUNET_BLOCK_EvaluationResult eval, 872 enum GNUNET_BLOCK_EvaluationResult eval,
917 struct GSF_PendingRequest *pr, 873 struct GSF_PendingRequest *pr,
918 uint32_t reply_anonymity_level, 874 uint32_t reply_anonymity_level,
919 struct GNUNET_TIME_Absolute expiration, 875 struct GNUNET_TIME_Absolute expiration,
920 enum GNUNET_BLOCK_Type type, 876 enum GNUNET_BLOCK_Type type,
921 const void *data, 877 const void *data, size_t data_len)
922 size_t data_len)
923{ 878{
924 struct PeerRequest *peerreq = cls; 879 struct PeerRequest *peerreq = cls;
925 struct GSF_ConnectedPeer *cp = peerreq->cp; 880 struct GSF_ConnectedPeer *cp = peerreq->cp;
@@ -927,101 +882,91 @@ handle_p2p_reply (void *cls,
927 struct PutMessage *pm; 882 struct PutMessage *pm;
928 size_t msize; 883 size_t msize;
929 884
930 GNUNET_assert (data_len + sizeof (struct PutMessage) < GNUNET_SERVER_MAX_MESSAGE_SIZE); 885 GNUNET_assert (data_len + sizeof (struct PutMessage) <
886 GNUNET_SERVER_MAX_MESSAGE_SIZE);
931 GNUNET_assert (peerreq->pr == pr); 887 GNUNET_assert (peerreq->pr == pr);
932 prd = GSF_pending_request_get_data_ (pr); 888 prd = GSF_pending_request_get_data_ (pr);
933 if (NULL == data) 889 if (NULL == data)
934 { 890 {
935 GNUNET_STATISTICS_update (GSF_stats, 891 GNUNET_STATISTICS_update (GSF_stats,
936 gettext_noop ("# P2P searches active"), 892 gettext_noop ("# P2P searches active"),
937 -1, 893 -1, GNUNET_NO);
938 GNUNET_NO); 894 GNUNET_break (GNUNET_YES ==
939 GNUNET_break (GNUNET_YES == 895 GNUNET_CONTAINER_multihashmap_remove (cp->request_map,
940 GNUNET_CONTAINER_multihashmap_remove (cp->request_map, 896 &prd->query, peerreq));
941 &prd->query, 897 GNUNET_free (peerreq);
942 peerreq)); 898 return;
943 GNUNET_free (peerreq); 899 }
944 return;
945 }
946 GNUNET_break (type != GNUNET_BLOCK_TYPE_ANY); 900 GNUNET_break (type != GNUNET_BLOCK_TYPE_ANY);
947 if ( (prd->type != type) && 901 if ((prd->type != type) && (prd->type != GNUNET_BLOCK_TYPE_ANY))
948 (prd->type != GNUNET_BLOCK_TYPE_ANY) ) 902 {
949 { 903 GNUNET_break (0);
950 GNUNET_break (0); 904 return;
951 return; 905 }
952 }
953#if DEBUG_FS 906#if DEBUG_FS
954 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 907 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
955 "Transmitting result for query `%s' to peer\n", 908 "Transmitting result for query `%s' to peer\n",
956 GNUNET_h2s (&prd->query)); 909 GNUNET_h2s (&prd->query));
957#endif 910#endif
958 GNUNET_STATISTICS_update (GSF_stats, 911 GNUNET_STATISTICS_update (GSF_stats,
959 gettext_noop ("# replies received for other peers"), 912 gettext_noop ("# replies received for other peers"),
960 1, 913 1, GNUNET_NO);
961 GNUNET_NO);
962 msize = sizeof (struct PutMessage) + data_len; 914 msize = sizeof (struct PutMessage) + data_len;
963 if (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) 915 if (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
916 {
917 GNUNET_break (0);
918 return;
919 }
920 if ((reply_anonymity_level != UINT32_MAX) && (reply_anonymity_level > 1))
921 {
922 if (reply_anonymity_level - 1 > GSF_cover_content_count)
964 { 923 {
965 GNUNET_break (0); 924 GNUNET_STATISTICS_update (GSF_stats,
925 gettext_noop
926 ("# replies dropped due to insufficient cover traffic"),
927 1, GNUNET_NO);
966 return; 928 return;
967 } 929 }
968 if ( (reply_anonymity_level != UINT32_MAX) && 930 GSF_cover_content_count -= (reply_anonymity_level - 1);
969 (reply_anonymity_level > 1) ) 931 }
970 { 932
971 if (reply_anonymity_level - 1 > GSF_cover_content_count)
972 {
973 GNUNET_STATISTICS_update (GSF_stats,
974 gettext_noop ("# replies dropped due to insufficient cover traffic"),
975 1,
976 GNUNET_NO);
977 return;
978 }
979 GSF_cover_content_count -= (reply_anonymity_level - 1);
980 }
981
982 pm = GNUNET_malloc (msize); 933 pm = GNUNET_malloc (msize);
983 pm->header.type = htons (GNUNET_MESSAGE_TYPE_FS_PUT); 934 pm->header.type = htons (GNUNET_MESSAGE_TYPE_FS_PUT);
984 pm->header.size = htons (msize); 935 pm->header.size = htons (msize);
985 pm->type = htonl (type); 936 pm->type = htonl (type);
986 pm->expiration = GNUNET_TIME_absolute_hton (expiration); 937 pm->expiration = GNUNET_TIME_absolute_hton (expiration);
987 memcpy (&pm[1], data, data_len); 938 memcpy (&pm[1], data, data_len);
988 if ( (reply_anonymity_level != UINT32_MAX) && 939 if ((reply_anonymity_level != UINT32_MAX) &&
989 (reply_anonymity_level != 0) && 940 (reply_anonymity_level != 0) &&
990 (GSF_enable_randomized_delays == GNUNET_YES) ) 941 (GSF_enable_randomized_delays == GNUNET_YES))
991 { 942 {
992 struct GSF_DelayedHandle *dh; 943 struct GSF_DelayedHandle *dh;
993 944
994 dh = GNUNET_malloc (sizeof (struct GSF_DelayedHandle)); 945 dh = GNUNET_malloc (sizeof (struct GSF_DelayedHandle));
995 dh->cp = cp; 946 dh->cp = cp;
996 dh->pm = pm; 947 dh->pm = pm;
997 dh->msize = msize; 948 dh->msize = msize;
998 GNUNET_CONTAINER_DLL_insert (cp->delayed_head, 949 GNUNET_CONTAINER_DLL_insert (cp->delayed_head, cp->delayed_tail, dh);
999 cp->delayed_tail, 950 dh->delay_task = GNUNET_SCHEDULER_add_delayed (get_randomized_delay (),
1000 dh); 951 &transmit_delayed_now, dh);
1001 dh->delay_task = GNUNET_SCHEDULER_add_delayed (get_randomized_delay (), 952 }
1002 &transmit_delayed_now,
1003 dh);
1004 }
1005 else 953 else
1006 { 954 {
1007 (void) GSF_peer_transmit_ (cp, GNUNET_NO, 955 (void) GSF_peer_transmit_ (cp, GNUNET_NO,
1008 UINT32_MAX, 956 UINT32_MAX,
1009 REPLY_TIMEOUT, 957 REPLY_TIMEOUT, msize, &copy_reply, pm);
1010 msize, 958 }
1011 &copy_reply,
1012 pm);
1013 }
1014 if (eval != GNUNET_BLOCK_EVALUATION_OK_LAST) 959 if (eval != GNUNET_BLOCK_EVALUATION_OK_LAST)
1015 return; 960 return;
1016 if (GNUNET_SCHEDULER_NO_TASK == peerreq->kill_task) 961 if (GNUNET_SCHEDULER_NO_TASK == peerreq->kill_task)
1017 { 962 {
1018 GNUNET_STATISTICS_update (GSF_stats, 963 GNUNET_STATISTICS_update (GSF_stats,
1019 gettext_noop ("# P2P searches destroyed due to ultimate reply"), 964 gettext_noop
1020 1, 965 ("# P2P searches destroyed due to ultimate reply"),
1021 GNUNET_NO); 966 1, GNUNET_NO);
1022 peerreq->kill_task = GNUNET_SCHEDULER_add_now (&peer_request_destroy, 967 peerreq->kill_task =
1023 peerreq); 968 GNUNET_SCHEDULER_add_now (&peer_request_destroy, peerreq);
1024 } 969 }
1025} 970}
1026 971
1027 972
@@ -1040,25 +985,25 @@ change_host_trust (struct GSF_ConnectedPeer *cp, int value)
1040 return 0; 985 return 0;
1041 GNUNET_assert (cp != NULL); 986 GNUNET_assert (cp != NULL);
1042 if (value > 0) 987 if (value > 0)
988 {
989 if (cp->ppd.trust + value < cp->ppd.trust)
1043 { 990 {
1044 if (cp->ppd.trust + value < cp->ppd.trust) 991 value = UINT32_MAX - cp->ppd.trust;
1045 { 992 cp->ppd.trust = UINT32_MAX;
1046 value = UINT32_MAX - cp->ppd.trust;
1047 cp->ppd.trust = UINT32_MAX;
1048 }
1049 else
1050 cp->ppd.trust += value;
1051 } 993 }
994 else
995 cp->ppd.trust += value;
996 }
1052 else 997 else
998 {
999 if (cp->ppd.trust < -value)
1053 { 1000 {
1054 if (cp->ppd.trust < -value) 1001 value = -cp->ppd.trust;
1055 { 1002 cp->ppd.trust = 0;
1056 value = -cp->ppd.trust;
1057 cp->ppd.trust = 0;
1058 }
1059 else
1060 cp->ppd.trust += value;
1061 } 1003 }
1004 else
1005 cp->ppd.trust += value;
1006 }
1062 return value; 1007 return value;
1063} 1008}
1064 1009
@@ -1072,8 +1017,7 @@ change_host_trust (struct GSF_ConnectedPeer *cp, int value)
1072 * @return effective priority 1017 * @return effective priority
1073 */ 1018 */
1074static int32_t 1019static int32_t
1075bound_priority (uint32_t prio_in, 1020bound_priority (uint32_t prio_in, struct GSF_ConnectedPeer *cp)
1076 struct GSF_ConnectedPeer *cp)
1077{ 1021{
1078#define N ((double)128.0) 1022#define N ((double)128.0)
1079 uint32_t ret; 1023 uint32_t ret;
@@ -1082,47 +1026,46 @@ bound_priority (uint32_t prio_in,
1082 1026
1083 ld = GSF_test_get_load_too_high_ (0); 1027 ld = GSF_test_get_load_too_high_ (0);
1084 if (ld == GNUNET_SYSERR) 1028 if (ld == GNUNET_SYSERR)
1085 { 1029 {
1086 GNUNET_STATISTICS_update (GSF_stats, 1030 GNUNET_STATISTICS_update (GSF_stats,
1087 gettext_noop ("# requests done for free (low load)"), 1031 gettext_noop
1088 1, 1032 ("# requests done for free (low load)"), 1,
1089 GNUNET_NO); 1033 GNUNET_NO);
1090 return 0; /* excess resources */ 1034 return 0; /* excess resources */
1091 } 1035 }
1092 if (prio_in > INT32_MAX) 1036 if (prio_in > INT32_MAX)
1093 prio_in = INT32_MAX; 1037 prio_in = INT32_MAX;
1094 ret = - change_host_trust (cp, - (int) prio_in); 1038 ret = -change_host_trust (cp, -(int) prio_in);
1095 if (ret > 0) 1039 if (ret > 0)
1096 { 1040 {
1097 if (ret > GSF_current_priorities + N) 1041 if (ret > GSF_current_priorities + N)
1098 rret = GSF_current_priorities + N; 1042 rret = GSF_current_priorities + N;
1099 else 1043 else
1100 rret = ret; 1044 rret = ret;
1101 GSF_current_priorities 1045 GSF_current_priorities = (GSF_current_priorities * (N - 1) + rret) / N;
1102 = (GSF_current_priorities * (N-1) + rret)/N; 1046 }
1103 } 1047 if ((ld == GNUNET_YES) && (ret > 0))
1104 if ( (ld == GNUNET_YES) && (ret > 0) ) 1048 {
1105 { 1049 /* try with charging */
1106 /* try with charging */ 1050 ld = GSF_test_get_load_too_high_ (ret);
1107 ld = GSF_test_get_load_too_high_ (ret); 1051 }
1108 }
1109 if (ld == GNUNET_YES) 1052 if (ld == GNUNET_YES)
1110 { 1053 {
1111 GNUNET_STATISTICS_update (GSF_stats, 1054 GNUNET_STATISTICS_update (GSF_stats,
1112 gettext_noop ("# request dropped, priority insufficient"), 1055 gettext_noop
1113 1, 1056 ("# request dropped, priority insufficient"), 1,
1114 GNUNET_NO); 1057 GNUNET_NO);
1115 /* undo charge */ 1058 /* undo charge */
1116 change_host_trust (cp, (int) ret); 1059 change_host_trust (cp, (int) ret);
1117 return -1; /* not enough resources */ 1060 return -1; /* not enough resources */
1118 } 1061 }
1119 else 1062 else
1120 { 1063 {
1121 GNUNET_STATISTICS_update (GSF_stats, 1064 GNUNET_STATISTICS_update (GSF_stats,
1122 gettext_noop ("# requests done for a price (normal load)"), 1065 gettext_noop
1123 1, 1066 ("# requests done for a price (normal load)"), 1,
1124 GNUNET_NO); 1067 GNUNET_NO);
1125 } 1068 }
1126#undef N 1069#undef N
1127 return ret; 1070 return ret;
1128} 1071}
@@ -1144,13 +1087,13 @@ bound_ttl (int32_t ttl_in, uint32_t prio)
1144 1087
1145 if (ttl_in <= 0) 1088 if (ttl_in <= 0)
1146 return ttl_in; 1089 return ttl_in;
1147 allowed = ((unsigned long long) prio) * TTL_DECREMENT / 1000; 1090 allowed = ((unsigned long long) prio) * TTL_DECREMENT / 1000;
1148 if (ttl_in > allowed) 1091 if (ttl_in > allowed)
1149 { 1092 {
1150 if (allowed >= (1 << 30)) 1093 if (allowed >= (1 << 30))
1151 return 1 << 30; 1094 return 1 << 30;
1152 return allowed; 1095 return allowed;
1153 } 1096 }
1154 return ttl_in; 1097 return ttl_in;
1155} 1098}
1156 1099
@@ -1168,7 +1111,7 @@ bound_ttl (int32_t ttl_in, uint32_t prio)
1168 */ 1111 */
1169struct GSF_PendingRequest * 1112struct GSF_PendingRequest *
1170GSF_handle_p2p_query_ (const struct GNUNET_PeerIdentity *other, 1113GSF_handle_p2p_query_ (const struct GNUNET_PeerIdentity *other,
1171 const struct GNUNET_MessageHeader *message) 1114 const struct GNUNET_MessageHeader *message)
1172{ 1115{
1173 struct PeerRequest *peerreq; 1116 struct PeerRequest *peerreq;
1174 struct GSF_PendingRequest *pr; 1117 struct GSF_PendingRequest *pr;
@@ -1177,7 +1120,7 @@ GSF_handle_p2p_query_ (const struct GNUNET_PeerIdentity *other,
1177 struct GSF_ConnectedPeer *cps; 1120 struct GSF_ConnectedPeer *cps;
1178 const GNUNET_HashCode *namespace; 1121 const GNUNET_HashCode *namespace;
1179 const struct GNUNET_PeerIdentity *target; 1122 const struct GNUNET_PeerIdentity *target;
1180 enum GSF_PendingRequestOptions options; 1123 enum GSF_PendingRequestOptions options;
1181 uint16_t msize; 1124 uint16_t msize;
1182 const struct GetMessage *gm; 1125 const struct GetMessage *gm;
1183 unsigned int bits; 1126 unsigned int bits;
@@ -1191,229 +1134,214 @@ GSF_handle_p2p_query_ (const struct GNUNET_PeerIdentity *other,
1191 GNUNET_PEER_Id spid; 1134 GNUNET_PEER_Id spid;
1192 1135
1193 GNUNET_assert (other != NULL); 1136 GNUNET_assert (other != NULL);
1194 msize = ntohs(message->size); 1137 msize = ntohs (message->size);
1195 if (msize < sizeof (struct GetMessage)) 1138 if (msize < sizeof (struct GetMessage))
1196 { 1139 {
1197 GNUNET_break_op (0); 1140 GNUNET_break_op (0);
1198 return NULL; 1141 return NULL;
1199 } 1142 }
1200 GNUNET_STATISTICS_update (GSF_stats, 1143 GNUNET_STATISTICS_update (GSF_stats,
1201 gettext_noop ("# GET requests received (from other peers)"), 1144 gettext_noop
1202 1, 1145 ("# GET requests received (from other peers)"), 1,
1203 GNUNET_NO); 1146 GNUNET_NO);
1204 gm = (const struct GetMessage*) message; 1147 gm = (const struct GetMessage *) message;
1205 type = ntohl (gm->type); 1148 type = ntohl (gm->type);
1206 bm = ntohl (gm->hash_bitmap); 1149 bm = ntohl (gm->hash_bitmap);
1207 bits = 0; 1150 bits = 0;
1208 while (bm > 0) 1151 while (bm > 0)
1209 { 1152 {
1210 if (1 == (bm & 1)) 1153 if (1 == (bm & 1))
1211 bits++; 1154 bits++;
1212 bm >>= 1; 1155 bm >>= 1;
1213 } 1156 }
1214 if (msize < sizeof (struct GetMessage) + bits * sizeof (GNUNET_HashCode)) 1157 if (msize < sizeof (struct GetMessage) + bits * sizeof (GNUNET_HashCode))
1215 { 1158 {
1216 GNUNET_break_op (0); 1159 GNUNET_break_op (0);
1217 return NULL; 1160 return NULL;
1218 } 1161 }
1219 opt = (const GNUNET_HashCode*) &gm[1]; 1162 opt = (const GNUNET_HashCode *) &gm[1];
1220 bfsize = msize - sizeof (struct GetMessage) - bits * sizeof (GNUNET_HashCode); 1163 bfsize = msize - sizeof (struct GetMessage) - bits * sizeof (GNUNET_HashCode);
1221 /* bfsize must be power of 2, check! */ 1164 /* bfsize must be power of 2, check! */
1222 if (0 != ( (bfsize - 1) & bfsize)) 1165 if (0 != ((bfsize - 1) & bfsize))
1223 { 1166 {
1224 GNUNET_break_op (0); 1167 GNUNET_break_op (0);
1225 return NULL; 1168 return NULL;
1226 } 1169 }
1227 GSF_cover_query_count++; 1170 GSF_cover_query_count++;
1228 bm = ntohl (gm->hash_bitmap); 1171 bm = ntohl (gm->hash_bitmap);
1229 bits = 0; 1172 bits = 0;
1230 cps = GNUNET_CONTAINER_multihashmap_get (cp_map, 1173 cps = GNUNET_CONTAINER_multihashmap_get (cp_map, &other->hashPubKey);
1231 &other->hashPubKey);
1232 if (NULL == cps) 1174 if (NULL == cps)
1233 { 1175 {
1234 /* peer must have just disconnected */ 1176 /* peer must have just disconnected */
1235 GNUNET_STATISTICS_update (GSF_stats, 1177 GNUNET_STATISTICS_update (GSF_stats,
1236 gettext_noop ("# requests dropped due to initiator not being connected"), 1178 gettext_noop
1237 1, 1179 ("# requests dropped due to initiator not being connected"),
1238 GNUNET_NO); 1180 1, GNUNET_NO);
1239 return NULL; 1181 return NULL;
1240 } 1182 }
1241 if (0 != (bm & GET_MESSAGE_BIT_RETURN_TO)) 1183 if (0 != (bm & GET_MESSAGE_BIT_RETURN_TO))
1242 cp = GNUNET_CONTAINER_multihashmap_get (cp_map, 1184 cp = GNUNET_CONTAINER_multihashmap_get (cp_map, &opt[bits++]);
1243 &opt[bits++]);
1244 else 1185 else
1245 cp = cps; 1186 cp = cps;
1246 if (cp == NULL) 1187 if (cp == NULL)
1247 { 1188 {
1248#if DEBUG_FS 1189#if DEBUG_FS
1249 if (0 != (bm & GET_MESSAGE_BIT_RETURN_TO)) 1190 if (0 != (bm & GET_MESSAGE_BIT_RETURN_TO))
1250 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1191 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1251 "Failed to find RETURN-TO peer `%4s' in connection set. Dropping query.\n", 1192 "Failed to find RETURN-TO peer `%4s' in connection set. Dropping query.\n",
1252 GNUNET_i2s ((const struct GNUNET_PeerIdentity*) &opt[bits-1])); 1193 GNUNET_i2s ((const struct GNUNET_PeerIdentity *)
1253 1194 &opt[bits - 1]));
1254 else 1195
1255 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1196 else
1256 "Failed to find peer `%4s' in connection set. Dropping query.\n", 1197 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1257 GNUNET_i2s (other)); 1198 "Failed to find peer `%4s' in connection set. Dropping query.\n",
1199 GNUNET_i2s (other));
1258#endif 1200#endif
1259 GNUNET_STATISTICS_update (GSF_stats, 1201 GNUNET_STATISTICS_update (GSF_stats,
1260 gettext_noop ("# requests dropped due to missing reverse route"), 1202 gettext_noop
1261 1, 1203 ("# requests dropped due to missing reverse route"),
1262 GNUNET_NO); 1204 1, GNUNET_NO);
1263 return NULL; 1205 return NULL;
1264 } 1206 }
1265 /* note that we can really only check load here since otherwise 1207 /* note that we can really only check load here since otherwise
1266 peers could find out that we are overloaded by not being 1208 * peers could find out that we are overloaded by not being
1267 disconnected after sending us a malformed query... */ 1209 * disconnected after sending us a malformed query... */
1268 priority = bound_priority (ntohl (gm->priority), cps); 1210 priority = bound_priority (ntohl (gm->priority), cps);
1269 if (priority < 0) 1211 if (priority < 0)
1270 { 1212 {
1271#if DEBUG_FS 1213#if DEBUG_FS
1272 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1214 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1273 "Dropping query from `%s', this peer is too busy.\n", 1215 "Dropping query from `%s', this peer is too busy.\n",
1274 GNUNET_i2s (other)); 1216 GNUNET_i2s (other));
1275#endif 1217#endif
1276 return NULL; 1218 return NULL;
1277 } 1219 }
1278#if DEBUG_FS 1220#if DEBUG_FS
1279 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1221 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1280 "Received request for `%s' of type %u from peer `%4s' with flags %u\n", 1222 "Received request for `%s' of type %u from peer `%4s' with flags %u\n",
1281 GNUNET_h2s (&gm->query), 1223 GNUNET_h2s (&gm->query),
1282 (unsigned int) type, 1224 (unsigned int) type, GNUNET_i2s (other), (unsigned int) bm);
1283 GNUNET_i2s (other),
1284 (unsigned int) bm);
1285#endif 1225#endif
1286 namespace = (0 != (bm & GET_MESSAGE_BIT_SKS_NAMESPACE)) ? &opt[bits++] : NULL; 1226 namespace = (0 != (bm & GET_MESSAGE_BIT_SKS_NAMESPACE)) ? &opt[bits++] : NULL;
1287 if ( (type == GNUNET_BLOCK_TYPE_FS_SBLOCK) && 1227 if ((type == GNUNET_BLOCK_TYPE_FS_SBLOCK) && (namespace == NULL))
1288 (namespace == NULL) ) 1228 {
1289 { 1229 GNUNET_break_op (0);
1290 GNUNET_break_op (0); 1230 return NULL;
1291 return NULL; 1231 }
1292 } 1232 if ((type != GNUNET_BLOCK_TYPE_FS_SBLOCK) && (namespace != NULL))
1293 if ( (type != GNUNET_BLOCK_TYPE_FS_SBLOCK) && 1233 {
1294 (namespace != NULL) ) 1234 GNUNET_break_op (0);
1295 { 1235 return NULL;
1296 GNUNET_break_op (0); 1236 }
1297 return NULL; 1237 target =
1298 } 1238 (0 !=
1299 target = (0 != (bm & GET_MESSAGE_BIT_TRANSMIT_TO)) ? ((const struct GNUNET_PeerIdentity*) &opt[bits++]) : NULL; 1239 (bm & GET_MESSAGE_BIT_TRANSMIT_TO)) ? ((const struct GNUNET_PeerIdentity
1240 *) &opt[bits++]) : NULL;
1300 options = 0; 1241 options = 0;
1301 spid = 0; 1242 spid = 0;
1302 if ( (GNUNET_LOAD_get_load (cp->ppd.transmission_delay) > 3 * (1 + priority)) || 1243 if ((GNUNET_LOAD_get_load (cp->ppd.transmission_delay) > 3 * (1 + priority))
1303 (GNUNET_LOAD_get_average (cp->ppd.transmission_delay) > 1244 || (GNUNET_LOAD_get_average (cp->ppd.transmission_delay) >
1304 GNUNET_CONSTANTS_MAX_CORK_DELAY.rel_value * 2 + GNUNET_LOAD_get_average (GSF_rt_entry_lifetime)) ) 1245 GNUNET_CONSTANTS_MAX_CORK_DELAY.rel_value * 2 +
1305 { 1246 GNUNET_LOAD_get_average (GSF_rt_entry_lifetime)))
1306 /* don't have BW to send to peer, or would likely take longer than we have for it, 1247 {
1307 so at best indirect the query */ 1248 /* don't have BW to send to peer, or would likely take longer than we have for it,
1308 priority = 0; 1249 * so at best indirect the query */
1309 options |= GSF_PRO_FORWARD_ONLY; 1250 priority = 0;
1310 spid = GNUNET_PEER_intern (other); 1251 options |= GSF_PRO_FORWARD_ONLY;
1311 GNUNET_assert (0 != spid); 1252 spid = GNUNET_PEER_intern (other);
1312 } 1253 GNUNET_assert (0 != spid);
1254 }
1313 ttl = bound_ttl (ntohl (gm->ttl), priority); 1255 ttl = bound_ttl (ntohl (gm->ttl), priority);
1314 /* decrement ttl (always) */ 1256 /* decrement ttl (always) */
1315 ttl_decrement = 2 * TTL_DECREMENT + 1257 ttl_decrement = 2 * TTL_DECREMENT +
1316 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 1258 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, TTL_DECREMENT);
1317 TTL_DECREMENT); 1259 if ((ttl < 0) && (((int32_t) (ttl - ttl_decrement)) > 0))
1318 if ( (ttl < 0) && 1260 {
1319 (((int32_t)(ttl - ttl_decrement)) > 0) )
1320 {
1321#if DEBUG_FS 1261#if DEBUG_FS
1322 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1262 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1323 "Dropping query from `%s' due to TTL underflow (%d - %u).\n", 1263 "Dropping query from `%s' due to TTL underflow (%d - %u).\n",
1324 GNUNET_i2s (other), 1264 GNUNET_i2s (other), ttl, ttl_decrement);
1325 ttl,
1326 ttl_decrement);
1327#endif 1265#endif
1328 GNUNET_STATISTICS_update (GSF_stats, 1266 GNUNET_STATISTICS_update (GSF_stats,
1329 gettext_noop ("# requests dropped due TTL underflow"), 1267 gettext_noop
1330 1, 1268 ("# requests dropped due TTL underflow"), 1,
1331 GNUNET_NO); 1269 GNUNET_NO);
1332 /* integer underflow => drop (should be very rare)! */ 1270 /* integer underflow => drop (should be very rare)! */
1333 return NULL; 1271 return NULL;
1334 } 1272 }
1335 ttl -= ttl_decrement; 1273 ttl -= ttl_decrement;
1336 1274
1337 /* test if the request already exists */ 1275 /* test if the request already exists */
1338 peerreq = GNUNET_CONTAINER_multihashmap_get (cp->request_map, 1276 peerreq = GNUNET_CONTAINER_multihashmap_get (cp->request_map, &gm->query);
1339 &gm->query); 1277 if (peerreq != NULL)
1340 if (peerreq != NULL) 1278 {
1341 { 1279 pr = peerreq->pr;
1342 pr = peerreq->pr; 1280 prd = GSF_pending_request_get_data_ (pr);
1343 prd = GSF_pending_request_get_data_ (pr); 1281 if ((prd->type == type) &&
1344 if ( (prd->type == type) && 1282 ((type != GNUNET_BLOCK_TYPE_FS_SBLOCK) ||
1345 ( (type != GNUNET_BLOCK_TYPE_FS_SBLOCK) || 1283 (0 == memcmp (&prd->namespace, namespace, sizeof (GNUNET_HashCode)))))
1346 (0 == memcmp (&prd->namespace, 1284 {
1347 namespace, 1285 if (prd->ttl.abs_value >= GNUNET_TIME_absolute_get ().abs_value + ttl)
1348 sizeof (GNUNET_HashCode))) ) ) 1286 {
1349 { 1287 /* existing request has higher TTL, drop new one! */
1350 if (prd->ttl.abs_value >= GNUNET_TIME_absolute_get().abs_value + ttl) 1288 prd->priority += priority;
1351 {
1352 /* existing request has higher TTL, drop new one! */
1353 prd->priority += priority;
1354#if DEBUG_FS 1289#if DEBUG_FS
1355 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1290 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1356 "Have existing request with higher TTL, dropping new request.\n", 1291 "Have existing request with higher TTL, dropping new request.\n",
1357 GNUNET_i2s (other)); 1292 GNUNET_i2s (other));
1358#endif 1293#endif
1359 GNUNET_STATISTICS_update (GSF_stats, 1294 GNUNET_STATISTICS_update (GSF_stats,
1360 gettext_noop ("# requests dropped due to higher-TTL request"), 1295 gettext_noop
1361 1, 1296 ("# requests dropped due to higher-TTL request"),
1362 GNUNET_NO); 1297 1, GNUNET_NO);
1363 return NULL; 1298 return NULL;
1364 } 1299 }
1365 /* existing request has lower TTL, drop old one! */ 1300 /* existing request has lower TTL, drop old one! */
1366 GNUNET_STATISTICS_update (GSF_stats, 1301 GNUNET_STATISTICS_update (GSF_stats,
1367 gettext_noop ("# P2P searches active"), 1302 gettext_noop ("# P2P searches active"),
1368 -1, 1303 -1, GNUNET_NO);
1369 GNUNET_NO); 1304 priority += prd->priority;
1370 priority += prd->priority; 1305 GSF_pending_request_cancel_ (pr, GNUNET_YES);
1371 GSF_pending_request_cancel_ (pr, GNUNET_YES); 1306 GNUNET_assert (GNUNET_YES ==
1372 GNUNET_assert (GNUNET_YES == 1307 GNUNET_CONTAINER_multihashmap_remove (cp->request_map,
1373 GNUNET_CONTAINER_multihashmap_remove (cp->request_map, 1308 &gm->query,
1374 &gm->query, 1309 peerreq));
1375 peerreq)); 1310 if (peerreq->kill_task != GNUNET_SCHEDULER_NO_TASK)
1376 if (peerreq->kill_task != GNUNET_SCHEDULER_NO_TASK) 1311 {
1377 { 1312 GNUNET_SCHEDULER_cancel (peerreq->kill_task);
1378 GNUNET_SCHEDULER_cancel (peerreq->kill_task); 1313 peerreq->kill_task = GNUNET_SCHEDULER_NO_TASK;
1379 peerreq->kill_task = GNUNET_SCHEDULER_NO_TASK; 1314 }
1380 } 1315 GNUNET_free (peerreq);
1381 GNUNET_free (peerreq);
1382 }
1383 } 1316 }
1384 1317 }
1318
1385 peerreq = GNUNET_malloc (sizeof (struct PeerRequest)); 1319 peerreq = GNUNET_malloc (sizeof (struct PeerRequest));
1386 peerreq->cp = cp; 1320 peerreq->cp = cp;
1387 pr = GSF_pending_request_create_ (options, 1321 pr = GSF_pending_request_create_ (options,
1388 type, 1322 type,
1389 &gm->query, 1323 &gm->query,
1390 namespace, 1324 namespace,
1391 target, 1325 target,
1392 (bfsize > 0) ? (const char*)&opt[bits] : NULL, 1326 (bfsize >
1393 bfsize, 1327 0) ? (const char *) &opt[bits] : NULL,
1394 ntohl (gm->filter_mutator), 1328 bfsize, ntohl (gm->filter_mutator),
1395 1 /* anonymity */, 1329 1 /* anonymity */ ,
1396 (uint32_t) priority, 1330 (uint32_t) priority, ttl, spid, NULL, 0, /* replies_seen */
1397 ttl, 1331 &handle_p2p_reply, peerreq);
1398 spid,
1399 NULL, 0, /* replies_seen */
1400 &handle_p2p_reply,
1401 peerreq);
1402 GNUNET_assert (NULL != pr); 1332 GNUNET_assert (NULL != pr);
1403 peerreq->pr = pr; 1333 peerreq->pr = pr;
1404 GNUNET_break (GNUNET_OK == 1334 GNUNET_break (GNUNET_OK ==
1405 GNUNET_CONTAINER_multihashmap_put (cp->request_map, 1335 GNUNET_CONTAINER_multihashmap_put (cp->request_map,
1406 &gm->query, 1336 &gm->query,
1407 peerreq, 1337 peerreq,
1408 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); 1338 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
1409 GNUNET_STATISTICS_update (GSF_stats,
1410 gettext_noop ("# P2P query messages received and processed"),
1411 1,
1412 GNUNET_NO);
1413 GNUNET_STATISTICS_update (GSF_stats, 1339 GNUNET_STATISTICS_update (GSF_stats,
1414 gettext_noop ("# P2P searches active"), 1340 gettext_noop
1415 1, 1341 ("# P2P query messages received and processed"), 1,
1416 GNUNET_NO); 1342 GNUNET_NO);
1343 GNUNET_STATISTICS_update (GSF_stats, gettext_noop ("# P2P searches active"),
1344 1, GNUNET_NO);
1417 return pr; 1345 return pr;
1418} 1346}
1419 1347
@@ -1426,34 +1354,29 @@ GSF_handle_p2p_query_ (const struct GNUNET_PeerIdentity *other,
1426 * @param tc scheduler context 1354 * @param tc scheduler context
1427 */ 1355 */
1428static void 1356static void
1429peer_transmit_timeout (void *cls, 1357peer_transmit_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1430 const struct GNUNET_SCHEDULER_TaskContext *tc)
1431{ 1358{
1432 struct GSF_PeerTransmitHandle *pth = cls; 1359 struct GSF_PeerTransmitHandle *pth = cls;
1433 struct GSF_ConnectedPeer *cp; 1360 struct GSF_ConnectedPeer *cp;
1434 1361
1435#if DEBUG_FS 1362#if DEBUG_FS
1436 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1363 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1437 "Timeout trying to transmit to other peer\n"); 1364 "Timeout trying to transmit to other peer\n");
1438#endif 1365#endif
1439 pth->timeout_task = GNUNET_SCHEDULER_NO_TASK; 1366 pth->timeout_task = GNUNET_SCHEDULER_NO_TASK;
1440 cp = pth->cp; 1367 cp = pth->cp;
1441 GNUNET_CONTAINER_DLL_remove (cp->pth_head, 1368 GNUNET_CONTAINER_DLL_remove (cp->pth_head, cp->pth_tail, pth);
1442 cp->pth_tail,
1443 pth);
1444 if (GNUNET_YES == pth->is_query) 1369 if (GNUNET_YES == pth->is_query)
1445 GNUNET_assert (0 < cp->ppd.pending_queries--); 1370 GNUNET_assert (0 < cp->ppd.pending_queries--);
1446 else if (GNUNET_NO == pth->is_query) 1371 else if (GNUNET_NO == pth->is_query)
1447 GNUNET_assert (0 < cp->ppd.pending_replies--); 1372 GNUNET_assert (0 < cp->ppd.pending_replies--);
1448 GNUNET_LOAD_update (cp->ppd.transmission_delay, 1373 GNUNET_LOAD_update (cp->ppd.transmission_delay, UINT64_MAX);
1449 UINT64_MAX);
1450 if (NULL != pth->cth) 1374 if (NULL != pth->cth)
1451 { 1375 {
1452 GNUNET_CORE_notify_transmit_ready_cancel (pth->cth); 1376 GNUNET_CORE_notify_transmit_ready_cancel (pth->cth);
1453 pth->cth = NULL; 1377 pth->cth = NULL;
1454 } 1378 }
1455 pth->gmc (pth->gmc_cls, 1379 pth->gmc (pth->gmc_cls, 0, NULL);
1456 0, NULL);
1457 GNUNET_assert (0 == pth->cth_in_progress); 1380 GNUNET_assert (0 == pth->cth_in_progress);
1458 GNUNET_free (pth); 1381 GNUNET_free (pth);
1459} 1382}
@@ -1475,12 +1398,10 @@ peer_transmit_timeout (void *cls,
1475 */ 1398 */
1476struct GSF_PeerTransmitHandle * 1399struct GSF_PeerTransmitHandle *
1477GSF_peer_transmit_ (struct GSF_ConnectedPeer *cp, 1400GSF_peer_transmit_ (struct GSF_ConnectedPeer *cp,
1478 int is_query, 1401 int is_query,
1479 uint32_t priority, 1402 uint32_t priority,
1480 struct GNUNET_TIME_Relative timeout, 1403 struct GNUNET_TIME_Relative timeout,
1481 size_t size, 1404 size_t size, GSF_GetMessageCallback gmc, void *gmc_cls)
1482 GSF_GetMessageCallback gmc,
1483 void *gmc_cls)
1484{ 1405{
1485 struct GSF_PeerTransmitHandle *pth; 1406 struct GSF_PeerTransmitHandle *pth;
1486 struct GSF_PeerTransmitHandle *pos; 1407 struct GSF_PeerTransmitHandle *pos;
@@ -1498,28 +1419,22 @@ GSF_peer_transmit_ (struct GSF_ConnectedPeer *cp,
1498 /* insertion sort (by priority, descending) */ 1419 /* insertion sort (by priority, descending) */
1499 prev = NULL; 1420 prev = NULL;
1500 pos = cp->pth_head; 1421 pos = cp->pth_head;
1501 while ( (pos != NULL) && 1422 while ((pos != NULL) && (pos->priority > priority))
1502 (pos->priority > priority) ) 1423 {
1503 { 1424 prev = pos;
1504 prev = pos; 1425 pos = pos->next;
1505 pos = pos->next; 1426 }
1506 }
1507 if (prev == NULL) 1427 if (prev == NULL)
1508 GNUNET_CONTAINER_DLL_insert (cp->pth_head, 1428 GNUNET_CONTAINER_DLL_insert (cp->pth_head, cp->pth_tail, pth);
1509 cp->pth_tail,
1510 pth);
1511 else 1429 else
1512 GNUNET_CONTAINER_DLL_insert_after (cp->pth_head, 1430 GNUNET_CONTAINER_DLL_insert_after (cp->pth_head, cp->pth_tail, prev, pth);
1513 cp->pth_tail,
1514 prev,
1515 pth);
1516 if (GNUNET_YES == is_query) 1431 if (GNUNET_YES == is_query)
1517 cp->ppd.pending_queries++; 1432 cp->ppd.pending_queries++;
1518 else if (GNUNET_NO == is_query) 1433 else if (GNUNET_NO == is_query)
1519 cp->ppd.pending_replies++; 1434 cp->ppd.pending_replies++;
1520 pth->timeout_task = GNUNET_SCHEDULER_add_delayed (timeout, 1435 pth->timeout_task = GNUNET_SCHEDULER_add_delayed (timeout,
1521 &peer_transmit_timeout, 1436 &peer_transmit_timeout,
1522 pth); 1437 pth);
1523 schedule_transmission (pth); 1438 schedule_transmission (pth);
1524 return pth; 1439 return pth;
1525} 1440}
@@ -1536,21 +1451,19 @@ GSF_peer_transmit_cancel_ (struct GSF_PeerTransmitHandle *pth)
1536 struct GSF_ConnectedPeer *cp; 1451 struct GSF_ConnectedPeer *cp;
1537 1452
1538 if (pth->timeout_task != GNUNET_SCHEDULER_NO_TASK) 1453 if (pth->timeout_task != GNUNET_SCHEDULER_NO_TASK)
1539 { 1454 {
1540 GNUNET_SCHEDULER_cancel (pth->timeout_task); 1455 GNUNET_SCHEDULER_cancel (pth->timeout_task);
1541 pth->timeout_task = GNUNET_SCHEDULER_NO_TASK; 1456 pth->timeout_task = GNUNET_SCHEDULER_NO_TASK;
1542 } 1457 }
1543 if (NULL != pth->cth) 1458 if (NULL != pth->cth)
1544 { 1459 {
1545 GNUNET_CORE_notify_transmit_ready_cancel (pth->cth); 1460 GNUNET_CORE_notify_transmit_ready_cancel (pth->cth);
1546 pth->cth = NULL; 1461 pth->cth = NULL;
1547 } 1462 }
1548 cp = pth->cp; 1463 cp = pth->cp;
1549 GNUNET_CONTAINER_DLL_remove (cp->pth_head, 1464 GNUNET_CONTAINER_DLL_remove (cp->pth_head, cp->pth_tail, pth);
1550 cp->pth_tail,
1551 pth);
1552 if (GNUNET_YES == pth->is_query) 1465 if (GNUNET_YES == pth->is_query)
1553 GNUNET_assert (0 < cp->ppd.pending_queries--); 1466 GNUNET_assert (0 < cp->ppd.pending_queries--);
1554 else if (GNUNET_NO == pth->is_query) 1467 else if (GNUNET_NO == pth->is_query)
1555 GNUNET_assert (0 < cp->ppd.pending_replies--); 1468 GNUNET_assert (0 < cp->ppd.pending_replies--);
1556 GNUNET_assert (0 == pth->cth_in_progress); 1469 GNUNET_assert (0 == pth->cth_in_progress);
@@ -1567,14 +1480,18 @@ GSF_peer_transmit_cancel_ (struct GSF_PeerTransmitHandle *pth)
1567 */ 1480 */
1568void 1481void
1569GSF_peer_update_performance_ (struct GSF_ConnectedPeer *cp, 1482GSF_peer_update_performance_ (struct GSF_ConnectedPeer *cp,
1570 struct GNUNET_TIME_Absolute request_time, 1483 struct GNUNET_TIME_Absolute request_time,
1571 uint32_t request_priority) 1484 uint32_t request_priority)
1572{ 1485{
1573 struct GNUNET_TIME_Relative delay; 1486 struct GNUNET_TIME_Relative delay;
1574 1487
1575 delay = GNUNET_TIME_absolute_get_duration (request_time); 1488 delay = GNUNET_TIME_absolute_get_duration (request_time);
1576 cp->ppd.avg_reply_delay.rel_value = (cp->ppd.avg_reply_delay.rel_value * (RUNAVG_DELAY_N-1) + delay.rel_value) / RUNAVG_DELAY_N; 1489 cp->ppd.avg_reply_delay.rel_value =
1577 cp->ppd.avg_priority = (cp->ppd.avg_priority * (RUNAVG_DELAY_N-1) + request_priority) / RUNAVG_DELAY_N; 1490 (cp->ppd.avg_reply_delay.rel_value * (RUNAVG_DELAY_N - 1) +
1491 delay.rel_value) / RUNAVG_DELAY_N;
1492 cp->ppd.avg_priority =
1493 (cp->ppd.avg_priority * (RUNAVG_DELAY_N - 1) +
1494 request_priority) / RUNAVG_DELAY_N;
1578} 1495}
1579 1496
1580 1497
@@ -1587,9 +1504,10 @@ GSF_peer_update_performance_ (struct GSF_ConnectedPeer *cp,
1587 */ 1504 */
1588void 1505void
1589GSF_peer_update_responder_client_ (struct GSF_ConnectedPeer *cp, 1506GSF_peer_update_responder_client_ (struct GSF_ConnectedPeer *cp,
1590 struct GSF_LocalClient *initiator_client) 1507 struct GSF_LocalClient *initiator_client)
1591{ 1508{
1592 cp->ppd.last_client_replies[cp->last_client_replies_woff++ % CS2P_SUCCESS_LIST_SIZE] = initiator_client; 1509 cp->ppd.last_client_replies[cp->last_client_replies_woff++ %
1510 CS2P_SUCCESS_LIST_SIZE] = initiator_client;
1593} 1511}
1594 1512
1595 1513
@@ -1602,7 +1520,7 @@ GSF_peer_update_responder_client_ (struct GSF_ConnectedPeer *cp,
1602 */ 1520 */
1603void 1521void
1604GSF_peer_update_responder_peer_ (struct GSF_ConnectedPeer *cp, 1522GSF_peer_update_responder_peer_ (struct GSF_ConnectedPeer *cp,
1605 const struct GSF_ConnectedPeer *initiator_peer) 1523 const struct GSF_ConnectedPeer *initiator_peer)
1606{ 1524{
1607 unsigned int woff; 1525 unsigned int woff;
1608 1526
@@ -1627,16 +1545,15 @@ GSF_peer_update_responder_peer_ (struct GSF_ConnectedPeer *cp,
1627 */ 1545 */
1628void 1546void
1629GSF_peer_status_handler_ (void *cls, 1547GSF_peer_status_handler_ (void *cls,
1630 const struct GNUNET_PeerIdentity *peer, 1548 const struct GNUNET_PeerIdentity *peer,
1631 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, 1549 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
1632 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, 1550 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
1633 struct GNUNET_TIME_Absolute timeout, 1551 struct GNUNET_TIME_Absolute timeout,
1634 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 1552 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
1635{ 1553{
1636 struct GSF_ConnectedPeer *cp; 1554 struct GSF_ConnectedPeer *cp;
1637 1555
1638 cp = GNUNET_CONTAINER_multihashmap_get (cp_map, 1556 cp = GNUNET_CONTAINER_multihashmap_get (cp_map, &peer->hashPubKey);
1639 &peer->hashPubKey);
1640 GNUNET_assert (NULL != cp); 1557 GNUNET_assert (NULL != cp);
1641 update_atsi (cp, atsi); 1558 update_atsi (cp, atsi);
1642} 1559}
@@ -1650,40 +1567,36 @@ GSF_peer_status_handler_ (void *cls,
1650 * @param peer identity of peer that connected 1567 * @param peer identity of peer that connected
1651 */ 1568 */
1652void 1569void
1653GSF_peer_disconnect_handler_ (void *cls, 1570GSF_peer_disconnect_handler_ (void *cls, const struct GNUNET_PeerIdentity *peer)
1654 const struct GNUNET_PeerIdentity *peer)
1655{ 1571{
1656 struct GSF_ConnectedPeer *cp; 1572 struct GSF_ConnectedPeer *cp;
1657 struct GSF_PeerTransmitHandle *pth; 1573 struct GSF_PeerTransmitHandle *pth;
1658 struct GSF_DelayedHandle *dh; 1574 struct GSF_DelayedHandle *dh;
1659 1575
1660 cp = GNUNET_CONTAINER_multihashmap_get (cp_map, 1576 cp = GNUNET_CONTAINER_multihashmap_get (cp_map, &peer->hashPubKey);
1661 &peer->hashPubKey);
1662 if (NULL == cp) 1577 if (NULL == cp)
1663 return; /* must have been disconnect from core with 1578 return; /* must have been disconnect from core with
1664 'peer' == my_id, ignore */ 1579 * 'peer' == my_id, ignore */
1665 GNUNET_assert (GNUNET_YES == 1580 GNUNET_assert (GNUNET_YES ==
1666 GNUNET_CONTAINER_multihashmap_remove (cp_map, 1581 GNUNET_CONTAINER_multihashmap_remove (cp_map,
1667 &peer->hashPubKey, 1582 &peer->hashPubKey, cp));
1668 cp));
1669 if (NULL != cp->migration_pth) 1583 if (NULL != cp->migration_pth)
1670 { 1584 {
1671 GSF_peer_transmit_cancel_ (cp->migration_pth); 1585 GSF_peer_transmit_cancel_ (cp->migration_pth);
1672 cp->migration_pth = NULL; 1586 cp->migration_pth = NULL;
1673 } 1587 }
1674 if (NULL != cp->irc) 1588 if (NULL != cp->irc)
1675 { 1589 {
1676 GNUNET_CORE_peer_change_preference_cancel (cp->irc); 1590 GNUNET_CORE_peer_change_preference_cancel (cp->irc);
1677 cp->irc = NULL; 1591 cp->irc = NULL;
1678 } 1592 }
1679 if (GNUNET_SCHEDULER_NO_TASK != cp->irc_delay_task) 1593 if (GNUNET_SCHEDULER_NO_TASK != cp->irc_delay_task)
1680 { 1594 {
1681 GNUNET_SCHEDULER_cancel (cp->irc_delay_task); 1595 GNUNET_SCHEDULER_cancel (cp->irc_delay_task);
1682 cp->irc_delay_task = GNUNET_SCHEDULER_NO_TASK; 1596 cp->irc_delay_task = GNUNET_SCHEDULER_NO_TASK;
1683 } 1597 }
1684 GNUNET_CONTAINER_multihashmap_iterate (cp->request_map, 1598 GNUNET_CONTAINER_multihashmap_iterate (cp->request_map,
1685 &cancel_pending_request, 1599 &cancel_pending_request, cp);
1686 cp);
1687 GNUNET_CONTAINER_multihashmap_destroy (cp->request_map); 1600 GNUNET_CONTAINER_multihashmap_destroy (cp->request_map);
1688 cp->request_map = NULL; 1601 cp->request_map = NULL;
1689 GSF_plan_notify_peer_disconnect_ (cp); 1602 GSF_plan_notify_peer_disconnect_ (cp);
@@ -1692,40 +1605,35 @@ GSF_peer_disconnect_handler_ (void *cls,
1692 memset (cp->ppd.last_p2p_replies, 0, sizeof (cp->ppd.last_p2p_replies)); 1605 memset (cp->ppd.last_p2p_replies, 0, sizeof (cp->ppd.last_p2p_replies));
1693 GSF_push_stop_ (cp); 1606 GSF_push_stop_ (cp);
1694 while (NULL != (pth = cp->pth_head)) 1607 while (NULL != (pth = cp->pth_head))
1608 {
1609 if (NULL != pth->cth)
1695 { 1610 {
1696 if (NULL != pth->cth) 1611 GNUNET_CORE_notify_transmit_ready_cancel (pth->cth);
1697 { 1612 pth->cth = NULL;
1698 GNUNET_CORE_notify_transmit_ready_cancel (pth->cth);
1699 pth->cth = NULL;
1700 }
1701 if (pth->timeout_task != GNUNET_SCHEDULER_NO_TASK)
1702 {
1703 GNUNET_SCHEDULER_cancel (pth->timeout_task);
1704 pth->timeout_task = GNUNET_SCHEDULER_NO_TASK;
1705 }
1706 GNUNET_CONTAINER_DLL_remove (cp->pth_head,
1707 cp->pth_tail,
1708 pth);
1709 GNUNET_assert (0 == pth->cth_in_progress);
1710 pth->gmc (pth->gmc_cls,
1711 0, NULL);
1712 GNUNET_free (pth);
1713 } 1613 }
1714 while (NULL != (dh = cp->delayed_head)) 1614 if (pth->timeout_task != GNUNET_SCHEDULER_NO_TASK)
1715 { 1615 {
1716 GNUNET_CONTAINER_DLL_remove (cp->delayed_head, 1616 GNUNET_SCHEDULER_cancel (pth->timeout_task);
1717 cp->delayed_tail, 1617 pth->timeout_task = GNUNET_SCHEDULER_NO_TASK;
1718 dh);
1719 GNUNET_SCHEDULER_cancel (dh->delay_task);
1720 GNUNET_free (dh->pm);
1721 GNUNET_free (dh);
1722 } 1618 }
1619 GNUNET_CONTAINER_DLL_remove (cp->pth_head, cp->pth_tail, pth);
1620 GNUNET_assert (0 == pth->cth_in_progress);
1621 pth->gmc (pth->gmc_cls, 0, NULL);
1622 GNUNET_free (pth);
1623 }
1624 while (NULL != (dh = cp->delayed_head))
1625 {
1626 GNUNET_CONTAINER_DLL_remove (cp->delayed_head, cp->delayed_tail, dh);
1627 GNUNET_SCHEDULER_cancel (dh->delay_task);
1628 GNUNET_free (dh->pm);
1629 GNUNET_free (dh);
1630 }
1723 GNUNET_PEER_change_rc (cp->ppd.pid, -1); 1631 GNUNET_PEER_change_rc (cp->ppd.pid, -1);
1724 if (GNUNET_SCHEDULER_NO_TASK != cp->mig_revive_task) 1632 if (GNUNET_SCHEDULER_NO_TASK != cp->mig_revive_task)
1725 { 1633 {
1726 GNUNET_SCHEDULER_cancel (cp->mig_revive_task); 1634 GNUNET_SCHEDULER_cancel (cp->mig_revive_task);
1727 cp->mig_revive_task = GNUNET_SCHEDULER_NO_TASK; 1635 cp->mig_revive_task = GNUNET_SCHEDULER_NO_TASK;
1728 } 1636 }
1729 GNUNET_free (cp); 1637 GNUNET_free (cp);
1730} 1638}
1731 1639
@@ -1756,17 +1664,12 @@ struct IterationContext
1756 * @return GNUNET_YES to continue iteration 1664 * @return GNUNET_YES to continue iteration
1757 */ 1665 */
1758static int 1666static int
1759call_iterator (void *cls, 1667call_iterator (void *cls, const GNUNET_HashCode * key, void *value)
1760 const GNUNET_HashCode *key,
1761 void *value)
1762{ 1668{
1763 struct IterationContext *ic = cls; 1669 struct IterationContext *ic = cls;
1764 struct GSF_ConnectedPeer *cp = value; 1670 struct GSF_ConnectedPeer *cp = value;
1765 1671
1766 ic->it (ic->it_cls, 1672 ic->it (ic->it_cls, (const struct GNUNET_PeerIdentity *) key, cp, &cp->ppd);
1767 (const struct GNUNET_PeerIdentity*) key,
1768 cp,
1769 &cp->ppd);
1770 return GNUNET_YES; 1673 return GNUNET_YES;
1771} 1674}
1772 1675
@@ -1778,16 +1681,13 @@ call_iterator (void *cls,
1778 * @param it_cls closure for it 1681 * @param it_cls closure for it
1779 */ 1682 */
1780void 1683void
1781GSF_iterate_connected_peers_ (GSF_ConnectedPeerIterator it, 1684GSF_iterate_connected_peers_ (GSF_ConnectedPeerIterator it, void *it_cls)
1782 void *it_cls)
1783{ 1685{
1784 struct IterationContext ic; 1686 struct IterationContext ic;
1785 1687
1786 ic.it = it; 1688 ic.it = it;
1787 ic.it_cls = it_cls; 1689 ic.it_cls = it_cls;
1788 GNUNET_CONTAINER_multihashmap_iterate (cp_map, 1690 GNUNET_CONTAINER_multihashmap_iterate (cp_map, &call_iterator, &ic);
1789 &call_iterator,
1790 &ic);
1791} 1691}
1792 1692
1793 1693
@@ -1799,11 +1699,10 @@ GSF_iterate_connected_peers_ (GSF_ConnectedPeerIterator it,
1799 */ 1699 */
1800void 1700void
1801GSF_connected_peer_get_identity_ (const struct GSF_ConnectedPeer *cp, 1701GSF_connected_peer_get_identity_ (const struct GSF_ConnectedPeer *cp,
1802 struct GNUNET_PeerIdentity *id) 1702 struct GNUNET_PeerIdentity *id)
1803{ 1703{
1804 GNUNET_assert (0 != cp->ppd.pid); 1704 GNUNET_assert (0 != cp->ppd.pid);
1805 GNUNET_PEER_resolve (cp->ppd.pid, 1705 GNUNET_PEER_resolve (cp->ppd.pid, id);
1806 id);
1807} 1706}
1808 1707
1809 1708
@@ -1816,9 +1715,7 @@ GSF_connected_peer_get_identity_ (const struct GSF_ConnectedPeer *cp,
1816 * @return number of bytes copied to buf 1715 * @return number of bytes copied to buf
1817 */ 1716 */
1818static size_t 1717static size_t
1819create_migration_stop_message (void *cls, 1718create_migration_stop_message (void *cls, size_t size, void *buf)
1820 size_t size,
1821 void *buf)
1822{ 1719{
1823 struct GSF_ConnectedPeer *cp = cls; 1720 struct GSF_ConnectedPeer *cp = cls;
1824 struct MigrationStopMessage msm; 1721 struct MigrationStopMessage msm;
@@ -1830,7 +1727,9 @@ create_migration_stop_message (void *cls,
1830 msm.header.size = htons (sizeof (struct MigrationStopMessage)); 1727 msm.header.size = htons (sizeof (struct MigrationStopMessage));
1831 msm.header.type = htons (GNUNET_MESSAGE_TYPE_FS_MIGRATION_STOP); 1728 msm.header.type = htons (GNUNET_MESSAGE_TYPE_FS_MIGRATION_STOP);
1832 msm.reserved = htonl (0); 1729 msm.reserved = htonl (0);
1833 msm.duration = GNUNET_TIME_relative_hton (GNUNET_TIME_absolute_get_remaining (cp->last_migration_block)); 1730 msm.duration =
1731 GNUNET_TIME_relative_hton (GNUNET_TIME_absolute_get_remaining
1732 (cp->last_migration_block));
1834 memcpy (buf, &msm, sizeof (struct MigrationStopMessage)); 1733 memcpy (buf, &msm, sizeof (struct MigrationStopMessage));
1835 return sizeof (struct MigrationStopMessage); 1734 return sizeof (struct MigrationStopMessage);
1836} 1735}
@@ -1845,33 +1744,35 @@ create_migration_stop_message (void *cls,
1845 */ 1744 */
1846void 1745void
1847GSF_block_peer_migration_ (struct GSF_ConnectedPeer *cp, 1746GSF_block_peer_migration_ (struct GSF_ConnectedPeer *cp,
1848 struct GNUNET_TIME_Relative block_time) 1747 struct GNUNET_TIME_Relative block_time)
1849{ 1748{
1850 if (GNUNET_TIME_absolute_get_remaining (cp->last_migration_block).rel_value > block_time.rel_value) 1749 if (GNUNET_TIME_absolute_get_remaining (cp->last_migration_block).rel_value >
1851 { 1750 block_time.rel_value)
1751 {
1852#if DEBUG_FS && 0 1752#if DEBUG_FS && 0
1853 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1753 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1854 "Migration already blocked for another %llu ms\n", 1754 "Migration already blocked for another %llu ms\n",
1855 (unsigned long long) GNUNET_TIME_absolute_get_remaining (cp->last_migration_block).rel_value); 1755 (unsigned long long)
1756 GNUNET_TIME_absolute_get_remaining
1757 (cp->last_migration_block).rel_value);
1856#endif 1758#endif
1857 return; /* already blocked */ 1759 return; /* already blocked */
1858 } 1760 }
1859#if DEBUG_FS && 0 1761#if DEBUG_FS && 0
1860 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1762 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1861 "Asking to stop migration for %llu ms\n", 1763 "Asking to stop migration for %llu ms\n",
1862 (unsigned long long) block_time.rel_value); 1764 (unsigned long long) block_time.rel_value);
1863#endif 1765#endif
1864 cp->last_migration_block = GNUNET_TIME_relative_to_absolute (block_time); 1766 cp->last_migration_block = GNUNET_TIME_relative_to_absolute (block_time);
1865 if (cp->migration_pth != NULL) 1767 if (cp->migration_pth != NULL)
1866 GSF_peer_transmit_cancel_ (cp->migration_pth); 1768 GSF_peer_transmit_cancel_ (cp->migration_pth);
1867 cp->migration_pth 1769 cp->migration_pth
1868 = GSF_peer_transmit_ (cp, 1770 = GSF_peer_transmit_ (cp,
1869 GNUNET_SYSERR, 1771 GNUNET_SYSERR,
1870 UINT32_MAX, 1772 UINT32_MAX,
1871 GNUNET_TIME_UNIT_FOREVER_REL, 1773 GNUNET_TIME_UNIT_FOREVER_REL,
1872 sizeof (struct MigrationStopMessage), 1774 sizeof (struct MigrationStopMessage),
1873 &create_migration_stop_message, 1775 &create_migration_stop_message, cp);
1874 cp);
1875} 1776}
1876 1777
1877 1778
@@ -1884,9 +1785,7 @@ GSF_block_peer_migration_ (struct GSF_ConnectedPeer *cp,
1884 * @return GNUNET_OK to continue iteration 1785 * @return GNUNET_OK to continue iteration
1885 */ 1786 */
1886static int 1787static int
1887flush_trust (void *cls, 1788flush_trust (void *cls, const GNUNET_HashCode * key, void *value)
1888 const GNUNET_HashCode *key,
1889 void *value)
1890{ 1789{
1891 struct GSF_ConnectedPeer *cp = value; 1790 struct GSF_ConnectedPeer *cp = value;
1892 char *fn; 1791 char *fn;
@@ -1894,26 +1793,27 @@ flush_trust (void *cls,
1894 struct GNUNET_PeerIdentity pid; 1793 struct GNUNET_PeerIdentity pid;
1895 1794
1896 if (cp->ppd.trust == cp->disk_trust) 1795 if (cp->ppd.trust == cp->disk_trust)
1897 return GNUNET_OK; /* unchanged */ 1796 return GNUNET_OK; /* unchanged */
1898 GNUNET_assert (0 != cp->ppd.pid); 1797 GNUNET_assert (0 != cp->ppd.pid);
1899 GNUNET_PEER_resolve (cp->ppd.pid, 1798 GNUNET_PEER_resolve (cp->ppd.pid, &pid);
1900 &pid);
1901 fn = get_trust_filename (&pid); 1799 fn = get_trust_filename (&pid);
1902 if (cp->ppd.trust == 0) 1800 if (cp->ppd.trust == 0)
1903 { 1801 {
1904 if ((0 != UNLINK (fn)) && (errno != ENOENT)) 1802 if ((0 != UNLINK (fn)) && (errno != ENOENT))
1905 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING | 1803 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING |
1906 GNUNET_ERROR_TYPE_BULK, "unlink", fn); 1804 GNUNET_ERROR_TYPE_BULK, "unlink", fn);
1907 } 1805 }
1908 else 1806 else
1909 { 1807 {
1910 trust = htonl (cp->ppd.trust); 1808 trust = htonl (cp->ppd.trust);
1911 if (sizeof(uint32_t) == GNUNET_DISK_fn_write (fn, &trust, 1809 if (sizeof (uint32_t) == GNUNET_DISK_fn_write (fn, &trust,
1912 sizeof(uint32_t), 1810 sizeof (uint32_t),
1913 GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE 1811 GNUNET_DISK_PERM_USER_READ |
1914 | GNUNET_DISK_PERM_GROUP_READ | GNUNET_DISK_PERM_OTHER_READ)) 1812 GNUNET_DISK_PERM_USER_WRITE |
1915 cp->disk_trust = cp->ppd.trust; 1813 GNUNET_DISK_PERM_GROUP_READ |
1916 } 1814 GNUNET_DISK_PERM_OTHER_READ))
1815 cp->disk_trust = cp->ppd.trust;
1816 }
1917 GNUNET_free (fn); 1817 GNUNET_free (fn);
1918 return GNUNET_OK; 1818 return GNUNET_OK;
1919} 1819}
@@ -1930,7 +1830,7 @@ flush_trust (void *cls,
1930 */ 1830 */
1931void 1831void
1932GSF_connected_peer_change_preference_ (struct GSF_ConnectedPeer *cp, 1832GSF_connected_peer_change_preference_ (struct GSF_ConnectedPeer *cp,
1933 uint64_t pref) 1833 uint64_t pref)
1934{ 1834{
1935 cp->inc_preference += pref; 1835 cp->inc_preference += pref;
1936} 1836}
@@ -1943,22 +1843,17 @@ GSF_connected_peer_change_preference_ (struct GSF_ConnectedPeer *cp,
1943 * @param tc task context, not used 1843 * @param tc task context, not used
1944 */ 1844 */
1945static void 1845static void
1946cron_flush_trust (void *cls, 1846cron_flush_trust (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1947 const struct GNUNET_SCHEDULER_TaskContext *tc)
1948{ 1847{
1949 1848
1950 if (NULL == cp_map) 1849 if (NULL == cp_map)
1951 return; 1850 return;
1952 GNUNET_CONTAINER_multihashmap_iterate (cp_map, 1851 GNUNET_CONTAINER_multihashmap_iterate (cp_map, &flush_trust, NULL);
1953 &flush_trust,
1954 NULL);
1955 if (NULL == tc) 1852 if (NULL == tc)
1956 return; 1853 return;
1957 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) 1854 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
1958 return; 1855 return;
1959 GNUNET_SCHEDULER_add_delayed (TRUST_FLUSH_FREQ, 1856 GNUNET_SCHEDULER_add_delayed (TRUST_FLUSH_FREQ, &cron_flush_trust, NULL);
1960 &cron_flush_trust,
1961 NULL);
1962} 1857}
1963 1858
1964 1859
@@ -1976,7 +1871,7 @@ GSF_connected_peer_init_ ()
1976 &trustDirectory)); 1871 &trustDirectory));
1977 GNUNET_DISK_directory_create (trustDirectory); 1872 GNUNET_DISK_directory_create (trustDirectory);
1978 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_HIGH, 1873 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_HIGH,
1979 &cron_flush_trust, NULL); 1874 &cron_flush_trust, NULL);
1980} 1875}
1981 1876
1982 1877
@@ -1988,13 +1883,10 @@ GSF_connected_peer_init_ ()
1988 * @param value value in the hash map (peer entry) 1883 * @param value value in the hash map (peer entry)
1989 * @return GNUNET_YES (we should continue to iterate) 1884 * @return GNUNET_YES (we should continue to iterate)
1990 */ 1885 */
1991static int 1886static int
1992clean_peer (void *cls, 1887clean_peer (void *cls, const GNUNET_HashCode * key, void *value)
1993 const GNUNET_HashCode * key,
1994 void *value)
1995{ 1888{
1996 GSF_peer_disconnect_handler_ (NULL, 1889 GSF_peer_disconnect_handler_ (NULL, (const struct GNUNET_PeerIdentity *) key);
1997 (const struct GNUNET_PeerIdentity*) key);
1998 return GNUNET_YES; 1890 return GNUNET_YES;
1999} 1891}
2000 1892
@@ -2006,9 +1898,7 @@ void
2006GSF_connected_peer_done_ () 1898GSF_connected_peer_done_ ()
2007{ 1899{
2008 cron_flush_trust (NULL, NULL); 1900 cron_flush_trust (NULL, NULL);
2009 GNUNET_CONTAINER_multihashmap_iterate (cp_map, 1901 GNUNET_CONTAINER_multihashmap_iterate (cp_map, &clean_peer, NULL);
2010 &clean_peer,
2011 NULL);
2012 GNUNET_CONTAINER_multihashmap_destroy (cp_map); 1902 GNUNET_CONTAINER_multihashmap_destroy (cp_map);
2013 cp_map = NULL; 1903 cp_map = NULL;
2014 GNUNET_free (trustDirectory); 1904 GNUNET_free (trustDirectory);
@@ -2024,16 +1914,14 @@ GSF_connected_peer_done_ ()
2024 * @param value value in the hash map (peer entry) 1914 * @param value value in the hash map (peer entry)
2025 * @return GNUNET_YES (we should continue to iterate) 1915 * @return GNUNET_YES (we should continue to iterate)
2026 */ 1916 */
2027static int 1917static int
2028clean_local_client (void *cls, 1918clean_local_client (void *cls, const GNUNET_HashCode * key, void *value)
2029 const GNUNET_HashCode * key,
2030 void *value)
2031{ 1919{
2032 const struct GSF_LocalClient *lc = cls; 1920 const struct GSF_LocalClient *lc = cls;
2033 struct GSF_ConnectedPeer *cp = value; 1921 struct GSF_ConnectedPeer *cp = value;
2034 unsigned int i; 1922 unsigned int i;
2035 1923
2036 for (i=0;i<CS2P_SUCCESS_LIST_SIZE;i++) 1924 for (i = 0; i < CS2P_SUCCESS_LIST_SIZE; i++)
2037 if (cp->ppd.last_client_replies[i] == lc) 1925 if (cp->ppd.last_client_replies[i] == lc)
2038 cp->ppd.last_client_replies[i] = NULL; 1926 cp->ppd.last_client_replies[i] = NULL;
2039 return GNUNET_YES; 1927 return GNUNET_YES;
@@ -2050,10 +1938,9 @@ void
2050GSF_handle_local_client_disconnect_ (const struct GSF_LocalClient *lc) 1938GSF_handle_local_client_disconnect_ (const struct GSF_LocalClient *lc)
2051{ 1939{
2052 if (NULL == cp_map) 1940 if (NULL == cp_map)
2053 return; /* already cleaned up */ 1941 return; /* already cleaned up */
2054 GNUNET_CONTAINER_multihashmap_iterate (cp_map, 1942 GNUNET_CONTAINER_multihashmap_iterate (cp_map,
2055 &clean_local_client, 1943 &clean_local_client, (void *) lc);
2056 (void*) lc);
2057} 1944}
2058 1945
2059 1946
diff --git a/src/fs/gnunet-service-fs_cp.h b/src/fs/gnunet-service-fs_cp.h
index 2925dd8ae..c9485f23b 100644
--- a/src/fs/gnunet-service-fs_cp.h
+++ b/src/fs/gnunet-service-fs_cp.h
@@ -59,7 +59,7 @@ struct GSF_PeerPerformanceData
59 * getting a reply (only calculated over the requests for 59 * getting a reply (only calculated over the requests for
60 * which we actually got a reply). Calculated 60 * which we actually got a reply). Calculated
61 * as a moving average: new_delay = ((n-1)*last_delay+curr_delay) / n 61 * as a moving average: new_delay = ((n-1)*last_delay+curr_delay) / n
62 */ 62 */
63 struct GNUNET_TIME_Relative avg_reply_delay; 63 struct GNUNET_TIME_Relative avg_reply_delay;
64 64
65 /** 65 /**
@@ -125,10 +125,11 @@ struct GSF_PeerPerformanceData
125 * @param cp handle to the connected peer record 125 * @param cp handle to the connected peer record
126 * @param perf peer performance data 126 * @param perf peer performance data
127 */ 127 */
128typedef void (*GSF_ConnectedPeerIterator)(void *cls, 128typedef void (*GSF_ConnectedPeerIterator) (void *cls,
129 const struct GNUNET_PeerIdentity *peer, 129 const struct GNUNET_PeerIdentity *
130 struct GSF_ConnectedPeer *cp, 130 peer, struct GSF_ConnectedPeer * cp,
131 const struct GSF_PeerPerformanceData *ppd); 131 const struct GSF_PeerPerformanceData
132 * ppd);
132 133
133 134
134/** 135/**
@@ -139,9 +140,8 @@ typedef void (*GSF_ConnectedPeerIterator)(void *cls,
139 * @param buf where to copy the message, NULL on error (peer disconnect) 140 * @param buf where to copy the message, NULL on error (peer disconnect)
140 * @return number of bytes copied to 'buf', can be 0 (without indicating an error) 141 * @return number of bytes copied to 'buf', can be 0 (without indicating an error)
141 */ 142 */
142typedef size_t (*GSF_GetMessageCallback)(void *cls, 143typedef size_t (*GSF_GetMessageCallback) (void *cls,
143 size_t buf_size, 144 size_t buf_size, void *buf);
144 void *buf);
145 145
146 146
147/** 147/**
@@ -151,9 +151,9 @@ typedef size_t (*GSF_GetMessageCallback)(void *cls,
151 * @param cp handle to the connected peer record 151 * @param cp handle to the connected peer record
152 * @param success GNUNET_YES on success, GNUNET_NO on failure 152 * @param success GNUNET_YES on success, GNUNET_NO on failure
153 */ 153 */
154typedef void (*GSF_PeerReserveCallback)(void *cls, 154typedef void (*GSF_PeerReserveCallback) (void *cls,
155 struct GSF_ConnectedPeer *cp, 155 struct GSF_ConnectedPeer * cp,
156 int success); 156 int success);
157 157
158 158
159/** 159/**
@@ -170,9 +170,11 @@ struct GSF_PeerTransmitHandle;
170 * @param atsi performance data for the connection 170 * @param atsi performance data for the connection
171 * @return handle to connected peer entry 171 * @return handle to connected peer entry
172 */ 172 */
173struct GSF_ConnectedPeer * 173struct GSF_ConnectedPeer *GSF_peer_connect_handler_ (const struct
174GSF_peer_connect_handler_ (const struct GNUNET_PeerIdentity *peer, 174 GNUNET_PeerIdentity *peer,
175 const struct GNUNET_TRANSPORT_ATS_Information *atsi); 175 const struct
176 GNUNET_TRANSPORT_ATS_Information
177 *atsi);
176 178
177 179
178/** 180/**
@@ -181,8 +183,8 @@ GSF_peer_connect_handler_ (const struct GNUNET_PeerIdentity *peer,
181 * @param peer peer's identity 183 * @param peer peer's identity
182 * @return NULL if this peer is not currently connected 184 * @return NULL if this peer is not currently connected
183 */ 185 */
184struct GSF_ConnectedPeer * 186struct GSF_ConnectedPeer *GSF_peer_get_ (const struct GNUNET_PeerIdentity
185GSF_peer_get_ (const struct GNUNET_PeerIdentity *peer); 187 *peer);
186 188
187 189
188/** 190/**
@@ -199,14 +201,13 @@ GSF_peer_get_ (const struct GNUNET_PeerIdentity *peer);
199 * @param gmc_cls closure for gmc 201 * @param gmc_cls closure for gmc
200 * @return handle to cancel request 202 * @return handle to cancel request
201 */ 203 */
202struct GSF_PeerTransmitHandle * 204struct GSF_PeerTransmitHandle *GSF_peer_transmit_ (struct GSF_ConnectedPeer *cp,
203GSF_peer_transmit_ (struct GSF_ConnectedPeer *cp, 205 int is_query,
204 int is_query, 206 uint32_t priority,
205 uint32_t priority, 207 struct GNUNET_TIME_Relative
206 struct GNUNET_TIME_Relative timeout, 208 timeout, size_t size,
207 size_t size, 209 GSF_GetMessageCallback gmc,
208 GSF_GetMessageCallback gmc, 210 void *gmc_cls);
209 void *gmc_cls);
210 211
211 212
212/** 213/**
@@ -214,8 +215,7 @@ GSF_peer_transmit_ (struct GSF_ConnectedPeer *cp,
214 * 215 *
215 * @param pth request to cancel 216 * @param pth request to cancel
216 */ 217 */
217void 218void GSF_peer_transmit_cancel_ (struct GSF_PeerTransmitHandle *pth);
218GSF_peer_transmit_cancel_ (struct GSF_PeerTransmitHandle *pth);
219 219
220 220
221/** 221/**
@@ -227,8 +227,8 @@ GSF_peer_transmit_cancel_ (struct GSF_PeerTransmitHandle *pth);
227 */ 227 */
228void 228void
229GSF_peer_update_performance_ (struct GSF_ConnectedPeer *cp, 229GSF_peer_update_performance_ (struct GSF_ConnectedPeer *cp,
230 struct GNUNET_TIME_Absolute request_time, 230 struct GNUNET_TIME_Absolute request_time,
231 uint32_t request_priority); 231 uint32_t request_priority);
232 232
233 233
234/** 234/**
@@ -240,7 +240,7 @@ GSF_peer_update_performance_ (struct GSF_ConnectedPeer *cp,
240 */ 240 */
241void 241void
242GSF_peer_update_responder_client_ (struct GSF_ConnectedPeer *cp, 242GSF_peer_update_responder_client_ (struct GSF_ConnectedPeer *cp,
243 struct GSF_LocalClient *initiator_client); 243 struct GSF_LocalClient *initiator_client);
244 244
245 245
246/** 246/**
@@ -252,7 +252,8 @@ GSF_peer_update_responder_client_ (struct GSF_ConnectedPeer *cp,
252 */ 252 */
253void 253void
254GSF_peer_update_responder_peer_ (struct GSF_ConnectedPeer *cp, 254GSF_peer_update_responder_peer_ (struct GSF_ConnectedPeer *cp,
255 const struct GSF_ConnectedPeer *initiator_peer); 255 const struct GSF_ConnectedPeer
256 *initiator_peer);
256 257
257 258
258/** 259/**
@@ -268,11 +269,11 @@ GSF_peer_update_responder_peer_ (struct GSF_ConnectedPeer *cp,
268 */ 269 */
269void 270void
270GSF_peer_status_handler_ (void *cls, 271GSF_peer_status_handler_ (void *cls,
271 const struct GNUNET_PeerIdentity *peer, 272 const struct GNUNET_PeerIdentity *peer,
272 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, 273 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
273 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, 274 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
274 struct GNUNET_TIME_Absolute timeout, 275 struct GNUNET_TIME_Absolute timeout,
275 const struct GNUNET_TRANSPORT_ATS_Information *atsi); 276 const struct GNUNET_TRANSPORT_ATS_Information *atsi);
276 277
277 278
278/** 279/**
@@ -288,9 +289,10 @@ GSF_peer_status_handler_ (void *cls,
288 */ 289 */
289int 290int
290GSF_handle_p2p_migration_stop_ (void *cls, 291GSF_handle_p2p_migration_stop_ (void *cls,
291 const struct GNUNET_PeerIdentity *other, 292 const struct GNUNET_PeerIdentity *other,
292 const struct GNUNET_MessageHeader *message, 293 const struct GNUNET_MessageHeader *message,
293 const struct GNUNET_TRANSPORT_ATS_Information *atsi); 294 const struct GNUNET_TRANSPORT_ATS_Information
295 *atsi);
294 296
295 297
296/** 298/**
@@ -304,9 +306,11 @@ GSF_handle_p2p_migration_stop_ (void *cls,
304 * @param message the actual message 306 * @param message the actual message
305 * @return pending request handle, NULL on error 307 * @return pending request handle, NULL on error
306 */ 308 */
307struct GSF_PendingRequest * 309struct GSF_PendingRequest *GSF_handle_p2p_query_ (const struct
308GSF_handle_p2p_query_ (const struct GNUNET_PeerIdentity *other, 310 GNUNET_PeerIdentity *other,
309 const struct GNUNET_MessageHeader *message); 311 const struct
312 GNUNET_MessageHeader
313 *message);
310 314
311 315
312/** 316/**
@@ -315,8 +319,9 @@ GSF_handle_p2p_query_ (const struct GNUNET_PeerIdentity *other,
315 * @param cp peer to query 319 * @param cp peer to query
316 * @return performance data record for the peer 320 * @return performance data record for the peer
317 */ 321 */
318struct GSF_PeerPerformanceData * 322struct GSF_PeerPerformanceData *GSF_get_peer_performance_data_ (struct
319GSF_get_peer_performance_data_ (struct GSF_ConnectedPeer *cp); 323 GSF_ConnectedPeer
324 *cp);
320 325
321 326
322/** 327/**
@@ -328,7 +333,7 @@ GSF_get_peer_performance_data_ (struct GSF_ConnectedPeer *cp);
328 */ 333 */
329void 334void
330GSF_block_peer_migration_ (struct GSF_ConnectedPeer *cp, 335GSF_block_peer_migration_ (struct GSF_ConnectedPeer *cp,
331 struct GNUNET_TIME_Relative block_time); 336 struct GNUNET_TIME_Relative block_time);
332 337
333 338
334/** 339/**
@@ -340,7 +345,7 @@ GSF_block_peer_migration_ (struct GSF_ConnectedPeer *cp,
340 */ 345 */
341void 346void
342GSF_peer_disconnect_handler_ (void *cls, 347GSF_peer_disconnect_handler_ (void *cls,
343 const struct GNUNET_PeerIdentity *peer); 348 const struct GNUNET_PeerIdentity *peer);
344 349
345 350
346/** 351/**
@@ -349,8 +354,7 @@ GSF_peer_disconnect_handler_ (void *cls,
349 * 354 *
350 * @param lc handle to the local client (henceforth invalid) 355 * @param lc handle to the local client (henceforth invalid)
351 */ 356 */
352void 357void GSF_handle_local_client_disconnect_ (const struct GSF_LocalClient *lc);
353GSF_handle_local_client_disconnect_ (const struct GSF_LocalClient *lc);
354 358
355 359
356/** 360/**
@@ -364,7 +368,7 @@ GSF_handle_local_client_disconnect_ (const struct GSF_LocalClient *lc);
364 */ 368 */
365void 369void
366GSF_connected_peer_change_preference_ (struct GSF_ConnectedPeer *cp, 370GSF_connected_peer_change_preference_ (struct GSF_ConnectedPeer *cp,
367 uint64_t pref); 371 uint64_t pref);
368 372
369 373
370/** 374/**
@@ -375,7 +379,7 @@ GSF_connected_peer_change_preference_ (struct GSF_ConnectedPeer *cp,
375 */ 379 */
376void 380void
377GSF_connected_peer_get_identity_ (const struct GSF_ConnectedPeer *cp, 381GSF_connected_peer_get_identity_ (const struct GSF_ConnectedPeer *cp,
378 struct GNUNET_PeerIdentity *id); 382 struct GNUNET_PeerIdentity *id);
379 383
380 384
381/** 385/**
@@ -384,23 +388,19 @@ GSF_connected_peer_get_identity_ (const struct GSF_ConnectedPeer *cp,
384 * @param it function to call for each peer 388 * @param it function to call for each peer
385 * @param it_cls closure for it 389 * @param it_cls closure for it
386 */ 390 */
387void 391void GSF_iterate_connected_peers_ (GSF_ConnectedPeerIterator it, void *it_cls);
388GSF_iterate_connected_peers_ (GSF_ConnectedPeerIterator it,
389 void *it_cls);
390 392
391 393
392/** 394/**
393 * Initialize peer management subsystem. 395 * Initialize peer management subsystem.
394 */ 396 */
395void 397void GSF_connected_peer_init_ (void);
396GSF_connected_peer_init_ (void);
397 398
398 399
399/** 400/**
400 * Shutdown peer management subsystem. 401 * Shutdown peer management subsystem.
401 */ 402 */
402void 403void GSF_connected_peer_done_ (void);
403GSF_connected_peer_done_ (void);
404 404
405 405
406#endif 406#endif
diff --git a/src/fs/gnunet-service-fs_indexing.c b/src/fs/gnunet-service-fs_indexing.c
index f92997f49..4bf02adb0 100644
--- a/src/fs/gnunet-service-fs_indexing.c
+++ b/src/fs/gnunet-service-fs_indexing.c
@@ -41,7 +41,7 @@
41 */ 41 */
42struct IndexInfo 42struct IndexInfo
43{ 43{
44 44
45 /** 45 /**
46 * This is a linked list. 46 * This is a linked list.
47 */ 47 */
@@ -63,7 +63,7 @@ struct IndexInfo
63 * Context for hashing of the file. 63 * Context for hashing of the file.
64 */ 64 */
65 struct GNUNET_CRYPTO_FileHashContext *fhc; 65 struct GNUNET_CRYPTO_FileHashContext *fhc;
66 66
67 /** 67 /**
68 * Hash of the contents of the file. 68 * Hash of the contents of the file.
69 */ 69 */
@@ -98,57 +98,48 @@ static struct GNUNET_DATASTORE_Handle *dsh;
98 98
99/** 99/**
100 * Write the current index information list to disk. 100 * Write the current index information list to disk.
101 */ 101 */
102static void 102static void
103write_index_list () 103write_index_list ()
104{ 104{
105 struct GNUNET_BIO_WriteHandle *wh; 105 struct GNUNET_BIO_WriteHandle *wh;
106 char *fn; 106 char *fn;
107 struct IndexInfo *pos; 107 struct IndexInfo *pos;
108 108
109 if (GNUNET_OK != 109 if (GNUNET_OK !=
110 GNUNET_CONFIGURATION_get_value_filename (cfg, 110 GNUNET_CONFIGURATION_get_value_filename (cfg, "FS", "INDEXDB", &fn))
111 "FS", 111 {
112 "INDEXDB", 112 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
113 &fn)) 113 _("Configuration option `%s' in section `%s' missing.\n"),
114 { 114 "INDEXDB", "FS");
115 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 115 return;
116 _("Configuration option `%s' in section `%s' missing.\n"), 116 }
117 "INDEXDB",
118 "FS");
119 return;
120 }
121 wh = GNUNET_BIO_write_open (fn); 117 wh = GNUNET_BIO_write_open (fn);
122 if (NULL == wh) 118 if (NULL == wh)
123 { 119 {
124 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 120 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
125 _("Could not open `%s'.\n"), 121 _("Could not open `%s'.\n"), fn);
126 fn); 122 GNUNET_free (fn);
127 GNUNET_free (fn); 123 return;
128 return; 124 }
129 }
130 pos = indexed_files; 125 pos = indexed_files;
131 while (pos != NULL) 126 while (pos != NULL)
132 { 127 {
133 if ( (GNUNET_OK != 128 if ((GNUNET_OK !=
134 GNUNET_BIO_write (wh, 129 GNUNET_BIO_write (wh,
135 &pos->file_id, 130 &pos->file_id,
136 sizeof (GNUNET_HashCode))) || 131 sizeof (GNUNET_HashCode))) ||
137 (GNUNET_OK != 132 (GNUNET_OK != GNUNET_BIO_write_string (wh, pos->filename)))
138 GNUNET_BIO_write_string (wh, 133 break;
139 pos->filename)) ) 134 pos = pos->next;
140 break; 135 }
141 pos = pos->next; 136 if (GNUNET_OK != GNUNET_BIO_write_close (wh))
142 } 137 {
143 if (GNUNET_OK != 138 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
144 GNUNET_BIO_write_close (wh)) 139 _("Error writing `%s'.\n"), fn);
145 { 140 GNUNET_free (fn);
146 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 141 return;
147 _("Error writing `%s'.\n"), 142 }
148 fn);
149 GNUNET_free (fn);
150 return;
151 }
152 GNUNET_free (fn); 143 GNUNET_free (fn);
153} 144}
154 145
@@ -161,73 +152,65 @@ read_index_list ()
161{ 152{
162 struct GNUNET_BIO_ReadHandle *rh; 153 struct GNUNET_BIO_ReadHandle *rh;
163 char *fn; 154 char *fn;
164 struct IndexInfo *pos; 155 struct IndexInfo *pos;
165 char *fname; 156 char *fname;
166 GNUNET_HashCode hc; 157 GNUNET_HashCode hc;
167 size_t slen; 158 size_t slen;
168 char *emsg; 159 char *emsg;
169 160
170 if (GNUNET_OK != 161 if (GNUNET_OK !=
171 GNUNET_CONFIGURATION_get_value_filename (cfg, 162 GNUNET_CONFIGURATION_get_value_filename (cfg, "FS", "INDEXDB", &fn))
172 "FS", 163 {
173 "INDEXDB", 164 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
174 &fn)) 165 _("Configuration option `%s' in section `%s' missing.\n"),
175 { 166 "INDEXDB", "FS");
176 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 167 return;
177 _("Configuration option `%s' in section `%s' missing.\n"), 168 }
178 "INDEXDB",
179 "FS");
180 return;
181 }
182 if (GNUNET_NO == GNUNET_DISK_file_test (fn)) 169 if (GNUNET_NO == GNUNET_DISK_file_test (fn))
183 { 170 {
184 /* no index info yet */ 171 /* no index info yet */
185 GNUNET_free (fn); 172 GNUNET_free (fn);
186 return; 173 return;
187 } 174 }
188 rh = GNUNET_BIO_read_open (fn); 175 rh = GNUNET_BIO_read_open (fn);
189 if (NULL == rh) 176 if (NULL == rh)
177 {
178 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
179 _("Could not open `%s'.\n"), fn);
180 GNUNET_free (fn);
181 return;
182 }
183 while ((GNUNET_OK ==
184 GNUNET_BIO_read (rh,
185 "Hash of indexed file",
186 &hc,
187 sizeof (GNUNET_HashCode))) &&
188 (GNUNET_OK ==
189 GNUNET_BIO_read_string (rh,
190 "Name of indexed file",
191 &fname, 1024 * 16)) && (fname != NULL))
192 {
193 slen = strlen (fname) + 1;
194 pos = GNUNET_malloc (sizeof (struct IndexInfo) + slen);
195 pos->file_id = hc;
196 pos->filename = (const char *) &pos[1];
197 memcpy (&pos[1], fname, slen);
198 if (GNUNET_SYSERR ==
199 GNUNET_CONTAINER_multihashmap_put (ifm,
200 &hc,
201 (void *) pos->filename,
202 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
190 { 203 {
191 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 204 GNUNET_free (pos);
192 _("Could not open `%s'.\n"),
193 fn);
194 GNUNET_free (fn);
195 return;
196 } 205 }
197 while ( (GNUNET_OK == 206 else
198 GNUNET_BIO_read (rh,
199 "Hash of indexed file",
200 &hc,
201 sizeof (GNUNET_HashCode))) &&
202 (GNUNET_OK ==
203 GNUNET_BIO_read_string (rh,
204 "Name of indexed file",
205 &fname,
206 1024 * 16)) &&
207 (fname != NULL) )
208 { 207 {
209 slen = strlen (fname) + 1; 208 pos->next = indexed_files;
210 pos = GNUNET_malloc (sizeof (struct IndexInfo) + slen); 209 indexed_files = pos;
211 pos->file_id = hc;
212 pos->filename = (const char *) &pos[1];
213 memcpy (&pos[1], fname, slen);
214 if (GNUNET_SYSERR ==
215 GNUNET_CONTAINER_multihashmap_put (ifm,
216 &hc,
217 (void*) pos->filename,
218 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
219 {
220 GNUNET_free (pos);
221 }
222 else
223 {
224 pos->next = indexed_files;
225 indexed_files = pos;
226 }
227 GNUNET_free (fname);
228 } 210 }
229 if (GNUNET_OK != 211 GNUNET_free (fname);
230 GNUNET_BIO_read_close (rh, &emsg)) 212 }
213 if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
231 GNUNET_free (emsg); 214 GNUNET_free (emsg);
232 GNUNET_free (fn); 215 GNUNET_free (fn);
233} 216}
@@ -244,31 +227,29 @@ signal_index_ok (struct IndexInfo *ii)
244{ 227{
245 if (GNUNET_SYSERR == 228 if (GNUNET_SYSERR ==
246 GNUNET_CONTAINER_multihashmap_put (ifm, 229 GNUNET_CONTAINER_multihashmap_put (ifm,
247 &ii->file_id, 230 &ii->file_id,
248 (void*) ii->filename, 231 (void *) ii->filename,
249 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) 232 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
250 { 233 {
251 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 234 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
252 _("Index request received for file `%s' is already indexed as `%s'. Permitting anyway.\n"), 235 _
253 ii->filename, 236 ("Index request received for file `%s' is already indexed as `%s'. Permitting anyway.\n"),
254 (const char*) GNUNET_CONTAINER_multihashmap_get (ifm, 237 ii->filename,
255 &ii->file_id)); 238 (const char *) GNUNET_CONTAINER_multihashmap_get (ifm,
256 GNUNET_SERVER_transmit_context_append_data (ii->tc, 239 &ii->file_id));
257 NULL, 0, 240 GNUNET_SERVER_transmit_context_append_data (ii->tc, NULL, 0,
258 GNUNET_MESSAGE_TYPE_FS_INDEX_START_OK); 241 GNUNET_MESSAGE_TYPE_FS_INDEX_START_OK);
259 GNUNET_SERVER_transmit_context_run (ii->tc, 242 GNUNET_SERVER_transmit_context_run (ii->tc, GNUNET_TIME_UNIT_MINUTES);
260 GNUNET_TIME_UNIT_MINUTES); 243 GNUNET_free (ii);
261 GNUNET_free (ii); 244 return;
262 return; 245 }
263 }
264 ii->next = indexed_files; 246 ii->next = indexed_files;
265 indexed_files = ii; 247 indexed_files = ii;
266 write_index_list (); 248 write_index_list ();
267 GNUNET_SERVER_transmit_context_append_data (ii->tc, 249 GNUNET_SERVER_transmit_context_append_data (ii->tc,
268 NULL, 0, 250 NULL, 0,
269 GNUNET_MESSAGE_TYPE_FS_INDEX_START_OK); 251 GNUNET_MESSAGE_TYPE_FS_INDEX_START_OK);
270 GNUNET_SERVER_transmit_context_run (ii->tc, 252 GNUNET_SERVER_transmit_context_run (ii->tc, GNUNET_TIME_UNIT_MINUTES);
271 GNUNET_TIME_UNIT_MINUTES);
272 ii->tc = NULL; 253 ii->tc = NULL;
273} 254}
274 255
@@ -280,36 +261,30 @@ signal_index_ok (struct IndexInfo *ii)
280 * @param cls closure, our publishing context 261 * @param cls closure, our publishing context
281 * @param res resulting hash, NULL on error 262 * @param res resulting hash, NULL on error
282 */ 263 */
283static void 264static void
284hash_for_index_val (void *cls, 265hash_for_index_val (void *cls, const GNUNET_HashCode * res)
285 const GNUNET_HashCode *
286 res)
287{ 266{
288 struct IndexInfo *ii = cls; 267 struct IndexInfo *ii = cls;
289 268
290 ii->fhc = NULL; 269 ii->fhc = NULL;
291 if ( (res == NULL) || 270 if ((res == NULL) ||
292 (0 != memcmp (res, 271 (0 != memcmp (res, &ii->file_id, sizeof (GNUNET_HashCode))))
293 &ii->file_id, 272 {
294 sizeof(GNUNET_HashCode))) ) 273 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
295 { 274 _
296 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 275 ("Hash mismatch trying to index file `%s' which has hash `%s'\n"),
297 _("Hash mismatch trying to index file `%s' which has hash `%s'\n"), 276 ii->filename, GNUNET_h2s (res));
298 ii->filename,
299 GNUNET_h2s (res));
300#if DEBUG_FS 277#if DEBUG_FS
301 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 278 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
302 "Wanted `%s'\n", 279 "Wanted `%s'\n", GNUNET_h2s (&ii->file_id));
303 GNUNET_h2s (&ii->file_id));
304#endif 280#endif
305 GNUNET_SERVER_transmit_context_append_data (ii->tc, 281 GNUNET_SERVER_transmit_context_append_data (ii->tc,
306 NULL, 0, 282 NULL, 0,
307 GNUNET_MESSAGE_TYPE_FS_INDEX_START_FAILED); 283 GNUNET_MESSAGE_TYPE_FS_INDEX_START_FAILED);
308 GNUNET_SERVER_transmit_context_run (ii->tc, 284 GNUNET_SERVER_transmit_context_run (ii->tc, GNUNET_TIME_UNIT_MINUTES);
309 GNUNET_TIME_UNIT_MINUTES); 285 GNUNET_free (ii);
310 GNUNET_free (ii); 286 return;
311 return; 287 }
312 }
313 signal_index_ok (ii); 288 signal_index_ok (ii);
314} 289}
315 290
@@ -323,8 +298,8 @@ hash_for_index_val (void *cls,
323 */ 298 */
324void 299void
325GNUNET_FS_handle_index_start (void *cls, 300GNUNET_FS_handle_index_start (void *cls,
326 struct GNUNET_SERVER_Client *client, 301 struct GNUNET_SERVER_Client *client,
327 const struct GNUNET_MessageHeader *message) 302 const struct GNUNET_MessageHeader *message)
328{ 303{
329 const struct IndexStartMessage *ism; 304 const struct IndexStartMessage *ism;
330 char *fn; 305 char *fn;
@@ -336,77 +311,70 @@ GNUNET_FS_handle_index_start (void *cls,
336 uint64_t mydev; 311 uint64_t mydev;
337 uint64_t myino; 312 uint64_t myino;
338 313
339 msize = ntohs(message->size); 314 msize = ntohs (message->size);
340 if ( (msize <= sizeof (struct IndexStartMessage)) || 315 if ((msize <= sizeof (struct IndexStartMessage)) ||
341 ( ((const char *)message)[msize-1] != '\0') ) 316 (((const char *) message)[msize - 1] != '\0'))
342 { 317 {
343 GNUNET_break (0); 318 GNUNET_break (0);
344 GNUNET_SERVER_receive_done (client, 319 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
345 GNUNET_SYSERR); 320 return;
346 return; 321 }
347 } 322 ism = (const struct IndexStartMessage *) message;
348 ism = (const struct IndexStartMessage*) message;
349 if (0 != ism->reserved) 323 if (0 != ism->reserved)
350 { 324 {
351 GNUNET_break (0); 325 GNUNET_break (0);
352 GNUNET_SERVER_receive_done (client, 326 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
353 GNUNET_SYSERR); 327 return;
354 return; 328 }
355 } 329 fn = GNUNET_STRINGS_filename_expand ((const char *) &ism[1]);
356 fn = GNUNET_STRINGS_filename_expand ((const char*) &ism[1]);
357 if (fn == NULL) 330 if (fn == NULL)
358 { 331 {
359 GNUNET_SERVER_receive_done (client, 332 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
360 GNUNET_SYSERR); 333 return;
361 return; 334 }
362 }
363 dev = GNUNET_ntohll (ism->device); 335 dev = GNUNET_ntohll (ism->device);
364 ino = GNUNET_ntohll (ism->inode); 336 ino = GNUNET_ntohll (ism->inode);
365 ism = (const struct IndexStartMessage*) message; 337 ism = (const struct IndexStartMessage *) message;
366 slen = strlen (fn) + 1; 338 slen = strlen (fn) + 1;
367 ii = GNUNET_malloc (sizeof (struct IndexInfo) + slen); 339 ii = GNUNET_malloc (sizeof (struct IndexInfo) + slen);
368 ii->filename = (const char*) &ii[1]; 340 ii->filename = (const char *) &ii[1];
369 memcpy (&ii[1], fn, slen); 341 memcpy (&ii[1], fn, slen);
370 ii->file_id = ism->file_id; 342 ii->file_id = ism->file_id;
371#if DEBUG_FS 343#if DEBUG_FS
372 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 344 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
373 "Received `%s' message for file `%s'\n", 345 "Received `%s' message for file `%s'\n",
374 "START_INDEX", 346 "START_INDEX", ii->filename);
375 ii->filename);
376#endif 347#endif
377 348
378 ii->tc = GNUNET_SERVER_transmit_context_create (client); 349 ii->tc = GNUNET_SERVER_transmit_context_create (client);
379 mydev = 0; 350 mydev = 0;
380 myino = 0; 351 myino = 0;
381 if ( ( (dev != 0) || 352 if (((dev != 0) ||
382 (ino != 0) ) && 353 (ino != 0)) &&
383 (GNUNET_OK == GNUNET_DISK_file_get_identifiers (fn, 354 (GNUNET_OK == GNUNET_DISK_file_get_identifiers (fn,
384 &mydev, 355 &mydev,
385 &myino)) && 356 &myino)) &&
386 ( (dev == mydev) && 357 ((dev == mydev) && (ino == myino)))
387 (ino == myino) ) ) 358 {
388 { 359 /* fast validation OK! */
389 /* fast validation OK! */ 360 signal_index_ok (ii);
390 signal_index_ok (ii); 361 GNUNET_free (fn);
391 GNUNET_free (fn); 362 return;
392 return; 363 }
393 }
394#if DEBUG_FS 364#if DEBUG_FS
395 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 365 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
396 "Mismatch in file identifiers (%llu != %llu or %u != %u), need to hash.\n", 366 "Mismatch in file identifiers (%llu != %llu or %u != %u), need to hash.\n",
397 (unsigned long long) ino, 367 (unsigned long long) ino,
398 (unsigned long long) myino, 368 (unsigned long long) myino,
399 (unsigned int) dev, 369 (unsigned int) dev, (unsigned int) mydev);
400 (unsigned int) mydev);
401#endif 370#endif
402 /* slow validation, need to hash full file (again) */ 371 /* slow validation, need to hash full file (again) */
403 ii->fhc = GNUNET_CRYPTO_hash_file (GNUNET_SCHEDULER_PRIORITY_IDLE, 372 ii->fhc = GNUNET_CRYPTO_hash_file (GNUNET_SCHEDULER_PRIORITY_IDLE,
404 fn, 373 fn,
405 HASHING_BLOCKSIZE, 374 HASHING_BLOCKSIZE,
406 &hash_for_index_val, 375 &hash_for_index_val, ii);
407 ii); 376 if (ii->fhc == NULL)
408 if (ii->fhc == NULL) 377 hash_for_index_val (ii, NULL);
409 hash_for_index_val (ii, NULL);
410 GNUNET_free (fn); 378 GNUNET_free (fn);
411} 379}
412 380
@@ -420,8 +388,8 @@ GNUNET_FS_handle_index_start (void *cls,
420 */ 388 */
421void 389void
422GNUNET_FS_handle_index_list_get (void *cls, 390GNUNET_FS_handle_index_list_get (void *cls,
423 struct GNUNET_SERVER_Client *client, 391 struct GNUNET_SERVER_Client *client,
424 const struct GNUNET_MessageHeader *message) 392 const struct GNUNET_MessageHeader *message)
425{ 393{
426 struct GNUNET_SERVER_TransmitContext *tc; 394 struct GNUNET_SERVER_TransmitContext *tc;
427 struct IndexInfoMessage *iim; 395 struct IndexInfoMessage *iim;
@@ -431,31 +399,30 @@ GNUNET_FS_handle_index_list_get (void *cls,
431 struct IndexInfo *pos; 399 struct IndexInfo *pos;
432 400
433 tc = GNUNET_SERVER_transmit_context_create (client); 401 tc = GNUNET_SERVER_transmit_context_create (client);
434 iim = (struct IndexInfoMessage*) buf; 402 iim = (struct IndexInfoMessage *) buf;
435 pos = indexed_files; 403 pos = indexed_files;
436 while (NULL != pos) 404 while (NULL != pos)
405 {
406 fn = pos->filename;
407 slen = strlen (fn) + 1;
408 if (slen + sizeof (struct IndexInfoMessage) >=
409 GNUNET_SERVER_MAX_MESSAGE_SIZE)
437 { 410 {
438 fn = pos->filename; 411 GNUNET_break (0);
439 slen = strlen (fn) + 1; 412 break;
440 if (slen + sizeof (struct IndexInfoMessage) >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
441 {
442 GNUNET_break (0);
443 break;
444 }
445 iim->header.type = htons (GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY);
446 iim->header.size = htons (slen + sizeof (struct IndexInfoMessage));
447 iim->reserved = 0;
448 iim->file_id = pos->file_id;
449 memcpy (&iim[1], fn, slen);
450 GNUNET_SERVER_transmit_context_append_message (tc,
451 &iim->header);
452 pos = pos->next;
453 } 413 }
414 iim->header.type = htons (GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY);
415 iim->header.size = htons (slen + sizeof (struct IndexInfoMessage));
416 iim->reserved = 0;
417 iim->file_id = pos->file_id;
418 memcpy (&iim[1], fn, slen);
419 GNUNET_SERVER_transmit_context_append_message (tc, &iim->header);
420 pos = pos->next;
421 }
454 GNUNET_SERVER_transmit_context_append_data (tc, 422 GNUNET_SERVER_transmit_context_append_data (tc,
455 NULL, 0, 423 NULL, 0,
456 GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_END); 424 GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_END);
457 GNUNET_SERVER_transmit_context_run (tc, 425 GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_MINUTES);
458 GNUNET_TIME_UNIT_MINUTES);
459} 426}
460 427
461 428
@@ -468,8 +435,8 @@ GNUNET_FS_handle_index_list_get (void *cls,
468 */ 435 */
469void 436void
470GNUNET_FS_handle_unindex (void *cls, 437GNUNET_FS_handle_unindex (void *cls,
471 struct GNUNET_SERVER_Client *client, 438 struct GNUNET_SERVER_Client *client,
472 const struct GNUNET_MessageHeader *message) 439 const struct GNUNET_MessageHeader *message)
473{ 440{
474 const struct UnindexMessage *um; 441 const struct UnindexMessage *um;
475 struct IndexInfo *pos; 442 struct IndexInfo *pos;
@@ -478,55 +445,51 @@ GNUNET_FS_handle_unindex (void *cls,
478 struct GNUNET_SERVER_TransmitContext *tc; 445 struct GNUNET_SERVER_TransmitContext *tc;
479 int found; 446 int found;
480 447
481 um = (const struct UnindexMessage*) message; 448 um = (const struct UnindexMessage *) message;
482 if (0 != um->reserved) 449 if (0 != um->reserved)
483 { 450 {
484 GNUNET_break (0); 451 GNUNET_break (0);
485 GNUNET_SERVER_receive_done (client, 452 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
486 GNUNET_SYSERR); 453 return;
487 return; 454 }
488 }
489 found = GNUNET_NO; 455 found = GNUNET_NO;
490 prev = NULL; 456 prev = NULL;
491 pos = indexed_files; 457 pos = indexed_files;
492 while (NULL != pos) 458 while (NULL != pos)
459 {
460 next = pos->next;
461 if (0 == memcmp (&pos->file_id, &um->file_id, sizeof (GNUNET_HashCode)))
493 { 462 {
494 next = pos->next; 463 if (prev == NULL)
495 if (0 == memcmp (&pos->file_id, 464 indexed_files = next;
496 &um->file_id,
497 sizeof (GNUNET_HashCode)))
498 {
499 if (prev == NULL)
500 indexed_files = next;
501 else
502 prev->next = next;
503 GNUNET_break (GNUNET_OK ==
504 GNUNET_CONTAINER_multihashmap_remove (ifm,
505 &pos->file_id,
506 (void*) pos->filename));
507 GNUNET_free (pos);
508 found = GNUNET_YES;
509 }
510 else 465 else
511 { 466 prev->next = next;
512 prev = pos; 467 GNUNET_break (GNUNET_OK ==
513 } 468 GNUNET_CONTAINER_multihashmap_remove (ifm,
514 pos = next; 469 &pos->file_id,
470 (void *)
471 pos->filename));
472 GNUNET_free (pos);
473 found = GNUNET_YES;
515 } 474 }
475 else
476 {
477 prev = pos;
478 }
479 pos = next;
480 }
516#if DEBUG_FS 481#if DEBUG_FS
517 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 482 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
518 "Client requested unindexing of file `%s': %s\n", 483 "Client requested unindexing of file `%s': %s\n",
519 GNUNET_h2s (&um->file_id), 484 GNUNET_h2s (&um->file_id), found ? "found" : "not found");
520 found ? "found" : "not found");
521#endif 485#endif
522 if (GNUNET_YES == found) 486 if (GNUNET_YES == found)
523 write_index_list (); 487 write_index_list ();
524 tc = GNUNET_SERVER_transmit_context_create (client); 488 tc = GNUNET_SERVER_transmit_context_create (client);
525 GNUNET_SERVER_transmit_context_append_data (tc, 489 GNUNET_SERVER_transmit_context_append_data (tc,
526 NULL, 0, 490 NULL, 0,
527 GNUNET_MESSAGE_TYPE_FS_UNINDEX_OK); 491 GNUNET_MESSAGE_TYPE_FS_UNINDEX_OK);
528 GNUNET_SERVER_transmit_context_run (tc, 492 GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_MINUTES);
529 GNUNET_TIME_UNIT_MINUTES);
530} 493}
531 494
532 495
@@ -539,14 +502,11 @@ GNUNET_FS_handle_unindex (void *cls,
539 * @param msg error message 502 * @param msg error message
540 */ 503 */
541static void 504static void
542remove_cont (void *cls, 505remove_cont (void *cls, int success, const char *msg)
543 int success,
544 const char *msg)
545{ 506{
546 if (GNUNET_OK != success) 507 if (GNUNET_OK != success)
547 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 508 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
548 _("Failed to delete bogus block: %s\n"), 509 _("Failed to delete bogus block: %s\n"), msg);
549 msg);
550} 510}
551 511
552 512
@@ -571,15 +531,15 @@ remove_cont (void *cls,
571 */ 531 */
572int 532int
573GNUNET_FS_handle_on_demand_block (const GNUNET_HashCode * key, 533GNUNET_FS_handle_on_demand_block (const GNUNET_HashCode * key,
574 uint32_t size, 534 uint32_t size,
575 const void *data, 535 const void *data,
576 enum GNUNET_BLOCK_Type type, 536 enum GNUNET_BLOCK_Type type,
577 uint32_t priority, 537 uint32_t priority,
578 uint32_t anonymity, 538 uint32_t anonymity,
579 struct GNUNET_TIME_Absolute 539 struct GNUNET_TIME_Absolute
580 expiration, uint64_t uid, 540 expiration, uint64_t uid,
581 GNUNET_DATASTORE_DatumProcessor cont, 541 GNUNET_DATASTORE_DatumProcessor cont,
582 void *cont_cls) 542 void *cont_cls)
583{ 543{
584 const struct OnDemandBlock *odb; 544 const struct OnDemandBlock *odb;
585 GNUNET_HashCode nkey; 545 GNUNET_HashCode nkey;
@@ -594,99 +554,72 @@ GNUNET_FS_handle_on_demand_block (const GNUNET_HashCode * key,
594 uint64_t off; 554 uint64_t off;
595 555
596 if (size != sizeof (struct OnDemandBlock)) 556 if (size != sizeof (struct OnDemandBlock))
597 { 557 {
598 GNUNET_break (0); 558 GNUNET_break (0);
599 GNUNET_DATASTORE_remove (dsh, 559 GNUNET_DATASTORE_remove (dsh,
600 key, 560 key,
601 size, 561 size,
602 data, 562 data,
603 -1, -1, 563 -1, -1,
604 GNUNET_TIME_UNIT_FOREVER_REL, 564 GNUNET_TIME_UNIT_FOREVER_REL, &remove_cont, NULL);
605 &remove_cont, 565 return GNUNET_SYSERR;
606 NULL); 566 }
607 return GNUNET_SYSERR; 567 odb = (const struct OnDemandBlock *) data;
608 }
609 odb = (const struct OnDemandBlock*) data;
610 off = GNUNET_ntohll (odb->offset); 568 off = GNUNET_ntohll (odb->offset);
611 fn = (const char*) GNUNET_CONTAINER_multihashmap_get (ifm, 569 fn = (const char *) GNUNET_CONTAINER_multihashmap_get (ifm, &odb->file_id);
612 &odb->file_id);
613 fh = NULL; 570 fh = NULL;
614 if ( (NULL == fn) || 571 if ((NULL == fn) ||
615 (NULL == (fh = GNUNET_DISK_file_open (fn, 572 (NULL == (fh = GNUNET_DISK_file_open (fn,
616 GNUNET_DISK_OPEN_READ, 573 GNUNET_DISK_OPEN_READ,
617 GNUNET_DISK_PERM_NONE))) || 574 GNUNET_DISK_PERM_NONE))) ||
618 (off != 575 (off !=
619 GNUNET_DISK_file_seek (fh, 576 GNUNET_DISK_file_seek (fh,
620 off, 577 off,
621 GNUNET_DISK_SEEK_SET)) || 578 GNUNET_DISK_SEEK_SET)) ||
622 (-1 == 579 (-1 == (nsize = GNUNET_DISK_file_read (fh, ndata, sizeof (ndata)))))
623 (nsize = GNUNET_DISK_file_read (fh, 580 {
624 ndata, 581 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
625 sizeof (ndata)))) ) 582 _
626 { 583 ("Could not access indexed file `%s' (%s) at offset %llu: %s\n"),
627 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 584 GNUNET_h2s (&odb->file_id), fn, (unsigned long long) off,
628 _("Could not access indexed file `%s' (%s) at offset %llu: %s\n"), 585 (fn == NULL) ? _("not indexed") : STRERROR (errno));
629 GNUNET_h2s (&odb->file_id), 586 if (fh != NULL)
630 fn, 587 GNUNET_DISK_file_close (fh);
631 (unsigned long long) off, 588 GNUNET_DATASTORE_remove (dsh,
632 (fn == NULL) ? _("not indexed") : STRERROR (errno)); 589 key,
633 if (fh != NULL) 590 size,
634 GNUNET_DISK_file_close (fh); 591 data,
635 GNUNET_DATASTORE_remove (dsh, 592 -1, -1,
636 key, 593 GNUNET_TIME_UNIT_FOREVER_REL, &remove_cont, NULL);
637 size, 594 return GNUNET_SYSERR;
638 data, 595 }
639 -1, -1,
640 GNUNET_TIME_UNIT_FOREVER_REL,
641 &remove_cont,
642 NULL);
643 return GNUNET_SYSERR;
644 }
645 GNUNET_DISK_file_close (fh); 596 GNUNET_DISK_file_close (fh);
646 GNUNET_CRYPTO_hash (ndata, 597 GNUNET_CRYPTO_hash (ndata, nsize, &nkey);
647 nsize,
648 &nkey);
649 GNUNET_CRYPTO_hash_to_aes_key (&nkey, &skey, &iv); 598 GNUNET_CRYPTO_hash_to_aes_key (&nkey, &skey, &iv);
650 GNUNET_CRYPTO_aes_encrypt (ndata, 599 GNUNET_CRYPTO_aes_encrypt (ndata, nsize, &skey, &iv, edata);
651 nsize, 600 GNUNET_CRYPTO_hash (edata, nsize, &query);
652 &skey, 601 if (0 != memcmp (&query, key, sizeof (GNUNET_HashCode)))
653 &iv, 602 {
654 edata); 603 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
655 GNUNET_CRYPTO_hash (edata, 604 _("Indexed file `%s' changed at offset %llu\n"),
656 nsize, 605 fn, (unsigned long long) off);
657 &query); 606 GNUNET_DATASTORE_remove (dsh,
658 if (0 != memcmp (&query, 607 key,
659 key, 608 size,
660 sizeof (GNUNET_HashCode))) 609 data,
661 { 610 -1, -1,
662 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 611 GNUNET_TIME_UNIT_FOREVER_REL, &remove_cont, NULL);
663 _("Indexed file `%s' changed at offset %llu\n"), 612 return GNUNET_SYSERR;
664 fn, 613 }
665 (unsigned long long) off);
666 GNUNET_DATASTORE_remove (dsh,
667 key,
668 size,
669 data,
670 -1, -1,
671 GNUNET_TIME_UNIT_FOREVER_REL,
672 &remove_cont,
673 NULL);
674 return GNUNET_SYSERR;
675 }
676#if DEBUG_FS 614#if DEBUG_FS
677 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 615 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
678 "On-demand encoded block for query `%s'\n", 616 "On-demand encoded block for query `%s'\n", GNUNET_h2s (key));
679 GNUNET_h2s (key)); 617#endif
680#endif
681 cont (cont_cls, 618 cont (cont_cls,
682 key, 619 key,
683 nsize, 620 nsize,
684 edata, 621 edata,
685 GNUNET_BLOCK_TYPE_FS_DBLOCK, 622 GNUNET_BLOCK_TYPE_FS_DBLOCK, priority, anonymity, expiration, uid);
686 priority,
687 anonymity,
688 expiration,
689 uid);
690 return GNUNET_OK; 623 return GNUNET_OK;
691} 624}
692 625
@@ -697,17 +630,17 @@ GNUNET_FS_handle_on_demand_block (const GNUNET_HashCode * key,
697void 630void
698GNUNET_FS_indexing_done () 631GNUNET_FS_indexing_done ()
699{ 632{
700 struct IndexInfo *pos; 633 struct IndexInfo *pos;
701 634
702 GNUNET_CONTAINER_multihashmap_destroy (ifm); 635 GNUNET_CONTAINER_multihashmap_destroy (ifm);
703 ifm = NULL; 636 ifm = NULL;
704 while (NULL != (pos = indexed_files)) 637 while (NULL != (pos = indexed_files))
705 { 638 {
706 indexed_files = pos->next; 639 indexed_files = pos->next;
707 if (pos->fhc != NULL) 640 if (pos->fhc != NULL)
708 GNUNET_CRYPTO_hash_file_cancel (pos->fhc); 641 GNUNET_CRYPTO_hash_file_cancel (pos->fhc);
709 GNUNET_free (pos); 642 GNUNET_free (pos);
710 } 643 }
711 cfg = NULL; 644 cfg = NULL;
712} 645}
713 646
@@ -720,7 +653,7 @@ GNUNET_FS_indexing_done ()
720 */ 653 */
721int 654int
722GNUNET_FS_indexing_init (const struct GNUNET_CONFIGURATION_Handle *c, 655GNUNET_FS_indexing_init (const struct GNUNET_CONFIGURATION_Handle *c,
723 struct GNUNET_DATASTORE_Handle *d) 656 struct GNUNET_DATASTORE_Handle *d)
724{ 657{
725 cfg = c; 658 cfg = c;
726 dsh = d; 659 dsh = d;
diff --git a/src/fs/gnunet-service-fs_indexing.h b/src/fs/gnunet-service-fs_indexing.h
index e1154830b..c6ef53351 100644
--- a/src/fs/gnunet-service-fs_indexing.h
+++ b/src/fs/gnunet-service-fs_indexing.h
@@ -56,15 +56,15 @@
56 */ 56 */
57int 57int
58GNUNET_FS_handle_on_demand_block (const GNUNET_HashCode * key, 58GNUNET_FS_handle_on_demand_block (const GNUNET_HashCode * key,
59 uint32_t size, 59 uint32_t size,
60 const void *data, 60 const void *data,
61 enum GNUNET_BLOCK_Type type, 61 enum GNUNET_BLOCK_Type type,
62 uint32_t priority, 62 uint32_t priority,
63 uint32_t anonymity, 63 uint32_t anonymity,
64 struct GNUNET_TIME_Absolute 64 struct GNUNET_TIME_Absolute
65 expiration, uint64_t uid, 65 expiration, uint64_t uid,
66 GNUNET_DATASTORE_DatumProcessor cont, 66 GNUNET_DATASTORE_DatumProcessor cont,
67 void *cont_cls); 67 void *cont_cls);
68 68
69/** 69/**
70 * Handle INDEX_START-message. 70 * Handle INDEX_START-message.
@@ -75,8 +75,8 @@ GNUNET_FS_handle_on_demand_block (const GNUNET_HashCode * key,
75 */ 75 */
76void 76void
77GNUNET_FS_handle_index_start (void *cls, 77GNUNET_FS_handle_index_start (void *cls,
78 struct GNUNET_SERVER_Client *client, 78 struct GNUNET_SERVER_Client *client,
79 const struct GNUNET_MessageHeader *message); 79 const struct GNUNET_MessageHeader *message);
80 80
81 81
82/** 82/**
@@ -88,8 +88,8 @@ GNUNET_FS_handle_index_start (void *cls,
88 */ 88 */
89void 89void
90GNUNET_FS_handle_index_list_get (void *cls, 90GNUNET_FS_handle_index_list_get (void *cls,
91 struct GNUNET_SERVER_Client *client, 91 struct GNUNET_SERVER_Client *client,
92 const struct GNUNET_MessageHeader *message); 92 const struct GNUNET_MessageHeader *message);
93 93
94 94
95/** 95/**
@@ -101,8 +101,8 @@ GNUNET_FS_handle_index_list_get (void *cls,
101 */ 101 */
102void 102void
103GNUNET_FS_handle_unindex (void *cls, 103GNUNET_FS_handle_unindex (void *cls,
104 struct GNUNET_SERVER_Client *client, 104 struct GNUNET_SERVER_Client *client,
105 const struct GNUNET_MessageHeader *message); 105 const struct GNUNET_MessageHeader *message);
106 106
107 107
108/** 108/**
@@ -114,14 +114,13 @@ GNUNET_FS_handle_unindex (void *cls,
114 */ 114 */
115int 115int
116GNUNET_FS_indexing_init (const struct GNUNET_CONFIGURATION_Handle *c, 116GNUNET_FS_indexing_init (const struct GNUNET_CONFIGURATION_Handle *c,
117 struct GNUNET_DATASTORE_Handle *d); 117 struct GNUNET_DATASTORE_Handle *d);
118 118
119 119
120/** 120/**
121 * Shutdown the module. 121 * Shutdown the module.
122 */ 122 */
123void 123void GNUNET_FS_indexing_done (void);
124GNUNET_FS_indexing_done (void);
125 124
126 125
127#endif 126#endif
diff --git a/src/fs/gnunet-service-fs_lc.c b/src/fs/gnunet-service-fs_lc.c
index 18f5c10dc..aa6569387 100644
--- a/src/fs/gnunet-service-fs_lc.c
+++ b/src/fs/gnunet-service-fs_lc.c
@@ -170,16 +170,13 @@ GSF_local_client_lookup_ (struct GNUNET_SERVER_Client *client)
170 struct GSF_LocalClient *pos; 170 struct GSF_LocalClient *pos;
171 171
172 pos = client_head; 172 pos = client_head;
173 while ( (pos != NULL) && 173 while ((pos != NULL) && (pos->client != client))
174 (pos->client != client) )
175 pos = pos->next; 174 pos = pos->next;
176 if (pos != NULL) 175 if (pos != NULL)
177 return pos; 176 return pos;
178 pos = GNUNET_malloc (sizeof (struct GSF_LocalClient)); 177 pos = GNUNET_malloc (sizeof (struct GSF_LocalClient));
179 pos->client = client; 178 pos->client = client;
180 GNUNET_CONTAINER_DLL_insert (client_head, 179 GNUNET_CONTAINER_DLL_insert (client_head, client_tail, pos);
181 client_tail,
182 pos);
183 return pos; 180 return pos;
184} 181}
185 182
@@ -189,24 +186,21 @@ GSF_local_client_lookup_ (struct GNUNET_SERVER_Client *client)
189 * 186 *
190 * @param cls the client request to free 187 * @param cls the client request to free
191 * @param tc task context 188 * @param tc task context
192 */ 189 */
193static void 190static void
194client_request_destroy (void *cls, 191client_request_destroy (void *cls,
195 const struct GNUNET_SCHEDULER_TaskContext *tc) 192 const struct GNUNET_SCHEDULER_TaskContext *tc)
196{ 193{
197 struct ClientRequest *cr = cls; 194 struct ClientRequest *cr = cls;
198 struct GSF_LocalClient *lc; 195 struct GSF_LocalClient *lc;
199 196
200 cr->kill_task = GNUNET_SCHEDULER_NO_TASK; 197 cr->kill_task = GNUNET_SCHEDULER_NO_TASK;
201 lc = cr->lc; 198 lc = cr->lc;
202 GNUNET_CONTAINER_DLL_remove (lc->cr_head, 199 GNUNET_CONTAINER_DLL_remove (lc->cr_head, lc->cr_tail, cr);
203 lc->cr_tail,
204 cr);
205 GSF_pending_request_cancel_ (cr->pr, GNUNET_NO); 200 GSF_pending_request_cancel_ (cr->pr, GNUNET_NO);
206 GNUNET_STATISTICS_update (GSF_stats, 201 GNUNET_STATISTICS_update (GSF_stats,
207 gettext_noop ("# client searches active"), 202 gettext_noop ("# client searches active"),
208 - 1, 203 -1, GNUNET_NO);
209 GNUNET_NO);
210 GNUNET_free (cr); 204 GNUNET_free (cr);
211} 205}
212 206
@@ -230,13 +224,12 @@ client_request_destroy (void *cls,
230 */ 224 */
231static void 225static void
232client_response_handler (void *cls, 226client_response_handler (void *cls,
233 enum GNUNET_BLOCK_EvaluationResult eval, 227 enum GNUNET_BLOCK_EvaluationResult eval,
234 struct GSF_PendingRequest *pr, 228 struct GSF_PendingRequest *pr,
235 uint32_t reply_anonymity_level, 229 uint32_t reply_anonymity_level,
236 struct GNUNET_TIME_Absolute expiration, 230 struct GNUNET_TIME_Absolute expiration,
237 enum GNUNET_BLOCK_Type type, 231 enum GNUNET_BLOCK_Type type,
238 const void *data, 232 const void *data, size_t data_len)
239 size_t data_len)
240{ 233{
241 struct ClientRequest *cr = cls; 234 struct ClientRequest *cr = cls;
242 struct GSF_LocalClient *lc; 235 struct GSF_LocalClient *lc;
@@ -245,47 +238,44 @@ client_response_handler (void *cls,
245 size_t msize; 238 size_t msize;
246 239
247 if (NULL == data) 240 if (NULL == data)
248 { 241 {
249 /* ugh, request 'timed out' -- how can this be? */ 242 /* ugh, request 'timed out' -- how can this be? */
250 GNUNET_break (0); 243 GNUNET_break (0);
251 return; 244 return;
252 } 245 }
253 prd = GSF_pending_request_get_data_ (pr); 246 prd = GSF_pending_request_get_data_ (pr);
254 GNUNET_break (type != GNUNET_BLOCK_TYPE_ANY); 247 GNUNET_break (type != GNUNET_BLOCK_TYPE_ANY);
255 if ( (prd->type != type) && 248 if ((prd->type != type) && (prd->type != GNUNET_BLOCK_TYPE_ANY))
256 (prd->type != GNUNET_BLOCK_TYPE_ANY) ) 249 {
257 { 250 GNUNET_break (0);
258 GNUNET_break (0); 251 return;
259 return; 252 }
260 }
261 GNUNET_STATISTICS_update (GSF_stats, 253 GNUNET_STATISTICS_update (GSF_stats,
262 gettext_noop ("# replies received for local clients"), 254 gettext_noop
263 1, 255 ("# replies received for local clients"), 1,
264 GNUNET_NO); 256 GNUNET_NO);
265 GNUNET_assert (pr == cr->pr); 257 GNUNET_assert (pr == cr->pr);
266 lc = cr->lc; 258 lc = cr->lc;
267 msize = sizeof (struct PutMessage) + data_len; 259 msize = sizeof (struct PutMessage) + data_len;
268 { 260 {
269 char buf[msize]; 261 char buf[msize];
270 262
271 pm = (struct PutMessage*) buf; 263 pm = (struct PutMessage *) buf;
272 pm->header.type = htons (GNUNET_MESSAGE_TYPE_FS_PUT); 264 pm->header.type = htons (GNUNET_MESSAGE_TYPE_FS_PUT);
273 pm->header.size = htons (msize); 265 pm->header.size = htons (msize);
274 pm->type = htonl (type); 266 pm->type = htonl (type);
275 pm->expiration = GNUNET_TIME_absolute_hton (expiration); 267 pm->expiration = GNUNET_TIME_absolute_hton (expiration);
276 memcpy (&pm[1], data, data_len); 268 memcpy (&pm[1], data, data_len);
277 GSF_local_client_transmit_ (lc, &pm->header); 269 GSF_local_client_transmit_ (lc, &pm->header);
278 } 270 }
279#if DEBUG_FS_CLIENT 271#if DEBUG_FS_CLIENT
280 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 272 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
281 "Queued reply to query `%s' for local client\n", 273 "Queued reply to query `%s' for local client\n",
282 GNUNET_h2s (&prd->query), 274 GNUNET_h2s (&prd->query), (unsigned int) prd->type);
283 (unsigned int) prd->type);
284#endif 275#endif
285 if (eval != GNUNET_BLOCK_EVALUATION_OK_LAST) 276 if (eval != GNUNET_BLOCK_EVALUATION_OK_LAST)
286 return; 277 return;
287 cr->kill_task = GNUNET_SCHEDULER_add_now (&client_request_destroy, 278 cr->kill_task = GNUNET_SCHEDULER_add_now (&client_request_destroy, cr);
288 cr);
289} 279}
290 280
291 281
@@ -298,7 +288,8 @@ client_response_handler (void *cls,
298 */ 288 */
299struct GSF_PendingRequest * 289struct GSF_PendingRequest *
300GSF_local_client_start_search_handler_ (struct GNUNET_SERVER_Client *client, 290GSF_local_client_start_search_handler_ (struct GNUNET_SERVER_Client *client,
301 const struct GNUNET_MessageHeader *message) 291 const struct GNUNET_MessageHeader
292 *message)
302{ 293{
303 static GNUNET_HashCode all_zeros; 294 static GNUNET_HashCode all_zeros;
304 const struct SearchMessage *sm; 295 const struct SearchMessage *sm;
@@ -311,99 +302,84 @@ GSF_local_client_start_search_handler_ (struct GNUNET_SERVER_Client *client,
311 enum GSF_PendingRequestOptions options; 302 enum GSF_PendingRequestOptions options;
312 303
313 msize = ntohs (message->size); 304 msize = ntohs (message->size);
314 if ( (msize < sizeof (struct SearchMessage)) || 305 if ((msize < sizeof (struct SearchMessage)) ||
315 (0 != (msize - sizeof (struct SearchMessage)) % sizeof (GNUNET_HashCode)) ) 306 (0 != (msize - sizeof (struct SearchMessage)) % sizeof (GNUNET_HashCode)))
316 { 307 {
317 GNUNET_break (0); 308 GNUNET_break (0);
318 GNUNET_SERVER_receive_done (client, 309 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
319 GNUNET_SYSERR); 310 return NULL;
320 return NULL; 311 }
321 }
322 GNUNET_STATISTICS_update (GSF_stats, 312 GNUNET_STATISTICS_update (GSF_stats,
323 gettext_noop ("# client searches received"), 313 gettext_noop ("# client searches received"),
324 1, 314 1, GNUNET_NO);
325 GNUNET_NO);
326 sc = (msize - sizeof (struct SearchMessage)) / sizeof (GNUNET_HashCode); 315 sc = (msize - sizeof (struct SearchMessage)) / sizeof (GNUNET_HashCode);
327 sm = (const struct SearchMessage*) message; 316 sm = (const struct SearchMessage *) message;
328 type = ntohl (sm->type); 317 type = ntohl (sm->type);
329#if DEBUG_FS_CLIENT 318#if DEBUG_FS_CLIENT
330 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 319 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
331 "Received request for `%s' of type %u from local client\n", 320 "Received request for `%s' of type %u from local client\n",
332 GNUNET_h2s (&sm->query), 321 GNUNET_h2s (&sm->query), (unsigned int) type);
333 (unsigned int) type);
334#endif 322#endif
335 lc = GSF_local_client_lookup_ (client); 323 lc = GSF_local_client_lookup_ (client);
336 324
337 /* detect duplicate KBLOCK requests */ 325 /* detect duplicate KBLOCK requests */
338 if ( (type == GNUNET_BLOCK_TYPE_FS_KBLOCK) || 326 if ((type == GNUNET_BLOCK_TYPE_FS_KBLOCK) ||
339 (type == GNUNET_BLOCK_TYPE_FS_NBLOCK) || 327 (type == GNUNET_BLOCK_TYPE_FS_NBLOCK) || (type == GNUNET_BLOCK_TYPE_ANY))
340 (type == GNUNET_BLOCK_TYPE_ANY) ) 328 {
329 /* FIXME: this does currently not work to filter duplicate
330 * results from *local* datastore since the local store is
331 * queried before we continue to process additional
332 * messages from the client! -- fix protocol? */
333 cr = lc->cr_head;
334 while (cr != NULL)
335 {
336 prd = GSF_pending_request_get_data_ (cr->pr);
337 if ((0 != memcmp (&prd->query,
338 &sm->query,
339 sizeof (GNUNET_HashCode))) && (prd->type == type))
340 break;
341 cr = cr->next;
342 }
343 if (cr != NULL)
341 { 344 {
342 /* FIXME: this does currently not work to filter duplicate
343 results from *local* datastore since the local store is
344 queried before we continue to process additional
345 messages from the client! -- fix protocol? */
346 cr = lc->cr_head;
347 while (cr != NULL)
348 {
349 prd = GSF_pending_request_get_data_ (cr->pr);
350 if ( (0 != memcmp (&prd->query,
351 &sm->query,
352 sizeof (GNUNET_HashCode))) &&
353 (prd->type == type) )
354 break;
355 cr = cr->next;
356 }
357 if (cr != NULL)
358 {
359#if DEBUG_FS_CLIENT 345#if DEBUG_FS_CLIENT
360 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 346 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
361 "Have existing request, merging content-seen lists.\n"); 347 "Have existing request, merging content-seen lists.\n");
362#endif 348#endif
363 GSF_pending_request_update_ (cr->pr, 349 GSF_pending_request_update_ (cr->pr,
364 (const GNUNET_HashCode*) &sm[1], 350 (const GNUNET_HashCode *) &sm[1], sc);
365 sc); 351 GNUNET_STATISTICS_update (GSF_stats,
366 GNUNET_STATISTICS_update (GSF_stats, 352 gettext_noop
367 gettext_noop ("# client searches updated (merged content seen list)"), 353 ("# client searches updated (merged content seen list)"),
368 1, 354 1, GNUNET_NO);
369 GNUNET_NO); 355 GNUNET_SERVER_receive_done (client, GNUNET_OK);
370 GNUNET_SERVER_receive_done (client, 356 return NULL;
371 GNUNET_OK);
372 return NULL;
373 }
374 } 357 }
358 }
375 359
376 GNUNET_STATISTICS_update (GSF_stats, 360 GNUNET_STATISTICS_update (GSF_stats,
377 gettext_noop ("# client searches active"), 361 gettext_noop ("# client searches active"),
378 1, 362 1, GNUNET_NO);
379 GNUNET_NO);
380 cr = GNUNET_malloc (sizeof (struct ClientRequest)); 363 cr = GNUNET_malloc (sizeof (struct ClientRequest));
381 cr->lc = lc; 364 cr->lc = lc;
382 GNUNET_CONTAINER_DLL_insert (lc->cr_head, 365 GNUNET_CONTAINER_DLL_insert (lc->cr_head, lc->cr_tail, cr);
383 lc->cr_tail, 366 options = GSF_PRO_LOCAL_REQUEST;
384 cr);
385 options = GSF_PRO_LOCAL_REQUEST;
386 if (0 != (1 & ntohl (sm->options))) 367 if (0 != (1 & ntohl (sm->options)))
387 options |= GSF_PRO_LOCAL_ONLY; 368 options |= GSF_PRO_LOCAL_ONLY;
388 cr->pr = GSF_pending_request_create_ (options, 369 cr->pr = GSF_pending_request_create_ (options, type, &sm->query, (type == GNUNET_BLOCK_TYPE_FS_SBLOCK) ? &sm->target /* namespace */
389 type, 370 : NULL,
390 &sm->query, 371 (0 != memcmp (&sm->target,
391 (type == GNUNET_BLOCK_TYPE_FS_SBLOCK) 372 &all_zeros,
392 ? &sm->target /* namespace */ 373 sizeof (GNUNET_HashCode)))
393 : NULL, 374 ? (const struct GNUNET_PeerIdentity *)
394 (0 != memcmp (&sm->target, 375 &sm->target : NULL, NULL, 0,
395 &all_zeros, 376 0 /* bf */ ,
396 sizeof (GNUNET_HashCode))) 377 ntohl (sm->anonymity_level),
397 ? (const struct GNUNET_PeerIdentity*) &sm->target 378 0 /* priority */ ,
398 : NULL, 379 0 /* ttl */ ,
399 NULL, 0, 0 /* bf */, 380 0 /* sender PID */ ,
400 ntohl (sm->anonymity_level), 381 (const GNUNET_HashCode *) &sm[1], sc,
401 0 /* priority */, 382 &client_response_handler, cr);
402 0 /* ttl */,
403 0 /* sender PID */,
404 (const GNUNET_HashCode*) &sm[1], sc,
405 &client_response_handler,
406 cr);
407 return cr->pr; 383 return cr->pr;
408} 384}
409 385
@@ -422,36 +398,30 @@ GSF_local_client_start_search_handler_ (struct GNUNET_SERVER_Client *client,
422 * @return number of bytes written to buf 398 * @return number of bytes written to buf
423 */ 399 */
424static size_t 400static size_t
425transmit_to_client (void *cls, 401transmit_to_client (void *cls, size_t size, void *buf)
426 size_t size,
427 void *buf)
428{ 402{
429 struct GSF_LocalClient *lc = cls; 403 struct GSF_LocalClient *lc = cls;
430 char *cbuf = buf; 404 char *cbuf = buf;
431 struct ClientResponse *res; 405 struct ClientResponse *res;
432 size_t msize; 406 size_t msize;
433 407
434 lc->th = NULL; 408 lc->th = NULL;
435 if (NULL == buf) 409 if (NULL == buf)
436 return 0; 410 return 0;
437 msize = 0; 411 msize = 0;
438 while ( (NULL != (res = lc->res_head) ) && 412 while ((NULL != (res = lc->res_head)) && (res->msize <= size))
439 (res->msize <= size) ) 413 {
440 { 414 memcpy (&cbuf[msize], &res[1], res->msize);
441 memcpy (&cbuf[msize], &res[1], res->msize); 415 msize += res->msize;
442 msize += res->msize; 416 size -= res->msize;
443 size -= res->msize; 417 GNUNET_CONTAINER_DLL_remove (lc->res_head, lc->res_tail, res);
444 GNUNET_CONTAINER_DLL_remove (lc->res_head, 418 GNUNET_free (res);
445 lc->res_tail, 419 }
446 res);
447 GNUNET_free (res);
448 }
449 if (NULL != res) 420 if (NULL != res)
450 lc->th = GNUNET_SERVER_notify_transmit_ready (lc->client, 421 lc->th = GNUNET_SERVER_notify_transmit_ready (lc->client,
451 res->msize, 422 res->msize,
452 GNUNET_TIME_UNIT_FOREVER_REL, 423 GNUNET_TIME_UNIT_FOREVER_REL,
453 &transmit_to_client, 424 &transmit_to_client, lc);
454 lc);
455 return msize; 425 return msize;
456} 426}
457 427
@@ -466,7 +436,7 @@ transmit_to_client (void *cls,
466 */ 436 */
467void 437void
468GSF_local_client_transmit_ (struct GSF_LocalClient *lc, 438GSF_local_client_transmit_ (struct GSF_LocalClient *lc,
469 const struct GNUNET_MessageHeader *msg) 439 const struct GNUNET_MessageHeader *msg)
470{ 440{
471 struct ClientResponse *res; 441 struct ClientResponse *res;
472 size_t msize; 442 size_t msize;
@@ -476,15 +446,12 @@ GSF_local_client_transmit_ (struct GSF_LocalClient *lc,
476 res->lc = lc; 446 res->lc = lc;
477 res->msize = msize; 447 res->msize = msize;
478 memcpy (&res[1], msg, msize); 448 memcpy (&res[1], msg, msize);
479 GNUNET_CONTAINER_DLL_insert_tail (lc->res_head, 449 GNUNET_CONTAINER_DLL_insert_tail (lc->res_head, lc->res_tail, res);
480 lc->res_tail,
481 res);
482 if (NULL == lc->th) 450 if (NULL == lc->th)
483 lc->th = GNUNET_SERVER_notify_transmit_ready (lc->client, 451 lc->th = GNUNET_SERVER_notify_transmit_ready (lc->client,
484 msize, 452 msize,
485 GNUNET_TIME_UNIT_FOREVER_REL, 453 GNUNET_TIME_UNIT_FOREVER_REL,
486 &transmit_to_client, 454 &transmit_to_client, lc);
487 lc);
488} 455}
489 456
490 457
@@ -496,49 +463,40 @@ GSF_local_client_transmit_ (struct GSF_LocalClient *lc,
496 * @param client handle of the client 463 * @param client handle of the client
497 */ 464 */
498void 465void
499GSF_client_disconnect_handler_ (void *cls, 466GSF_client_disconnect_handler_ (void *cls, struct GNUNET_SERVER_Client *client)
500 struct GNUNET_SERVER_Client *client)
501{ 467{
502 struct GSF_LocalClient *pos; 468 struct GSF_LocalClient *pos;
503 struct ClientRequest *cr; 469 struct ClientRequest *cr;
504 struct ClientResponse *res; 470 struct ClientResponse *res;
505 471
506 pos = client_head; 472 pos = client_head;
507 while ( (pos != NULL) && 473 while ((pos != NULL) && (pos->client != client))
508 (pos->client != client) )
509 pos = pos->next; 474 pos = pos->next;
510 if (pos == NULL) 475 if (pos == NULL)
511 return; 476 return;
512 while (NULL != (cr = pos->cr_head)) 477 while (NULL != (cr = pos->cr_head))
513 { 478 {
514 GNUNET_CONTAINER_DLL_remove (pos->cr_head, 479 GNUNET_CONTAINER_DLL_remove (pos->cr_head, pos->cr_tail, cr);
515 pos->cr_tail, 480 GSF_pending_request_cancel_ (cr->pr, GNUNET_NO);
516 cr); 481 GNUNET_STATISTICS_update (GSF_stats,
517 GSF_pending_request_cancel_ (cr->pr, GNUNET_NO); 482 gettext_noop ("# client searches active"),
518 GNUNET_STATISTICS_update (GSF_stats, 483 -1, GNUNET_NO);
519 gettext_noop ("# client searches active"), 484 if (GNUNET_SCHEDULER_NO_TASK != cr->kill_task)
520 - 1, 485 GNUNET_SCHEDULER_cancel (cr->kill_task);
521 GNUNET_NO); 486 GNUNET_free (cr);
522 if (GNUNET_SCHEDULER_NO_TASK != cr->kill_task) 487 }
523 GNUNET_SCHEDULER_cancel (cr->kill_task);
524 GNUNET_free (cr);
525 }
526 while (NULL != (res = pos->res_head)) 488 while (NULL != (res = pos->res_head))
527 { 489 {
528 GNUNET_CONTAINER_DLL_remove (pos->res_head, 490 GNUNET_CONTAINER_DLL_remove (pos->res_head, pos->res_tail, res);
529 pos->res_tail, 491 GNUNET_free (res);
530 res); 492 }
531 GNUNET_free (res);
532 }
533 if (pos->th != NULL) 493 if (pos->th != NULL)
534 { 494 {
535 GNUNET_CONNECTION_notify_transmit_ready_cancel (pos->th); 495 GNUNET_CONNECTION_notify_transmit_ready_cancel (pos->th);
536 pos->th = NULL; 496 pos->th = NULL;
537 } 497 }
538 GSF_handle_local_client_disconnect_ (pos); 498 GSF_handle_local_client_disconnect_ (pos);
539 GNUNET_CONTAINER_DLL_remove (client_head, 499 GNUNET_CONTAINER_DLL_remove (client_head, client_tail, pos);
540 client_tail,
541 pos);
542 GNUNET_free (pos); 500 GNUNET_free (pos);
543} 501}
544 502
diff --git a/src/fs/gnunet-service-fs_lc.h b/src/fs/gnunet-service-fs_lc.h
index fb63a3571..c9d8ce191 100644
--- a/src/fs/gnunet-service-fs_lc.h
+++ b/src/fs/gnunet-service-fs_lc.h
@@ -36,8 +36,8 @@
36 * @param client handle of the client 36 * @param client handle of the client
37 * @return handle to local client entry 37 * @return handle to local client entry
38 */ 38 */
39struct GSF_LocalClient * 39struct GSF_LocalClient *GSF_local_client_lookup_ (struct GNUNET_SERVER_Client
40GSF_local_client_lookup_ (struct GNUNET_SERVER_Client *client); 40 *client);
41 41
42 42
43/** 43/**
@@ -50,9 +50,12 @@ GSF_local_client_lookup_ (struct GNUNET_SERVER_Client *client);
50 * @param message the actual message 50 * @param message the actual message
51 * @return pending request handle for the request, NULL on error 51 * @return pending request handle for the request, NULL on error
52 */ 52 */
53struct GSF_PendingRequest * 53struct GSF_PendingRequest *GSF_local_client_start_search_handler_ (struct
54GSF_local_client_start_search_handler_ (struct GNUNET_SERVER_Client *client, 54 GNUNET_SERVER_Client
55 const struct GNUNET_MessageHeader *message); 55 *client,
56 const struct
57 GNUNET_MessageHeader
58 *message);
56 59
57 60
58/** 61/**
@@ -65,7 +68,7 @@ GSF_local_client_start_search_handler_ (struct GNUNET_SERVER_Client *client,
65 */ 68 */
66void 69void
67GSF_local_client_transmit_ (struct GSF_LocalClient *lc, 70GSF_local_client_transmit_ (struct GSF_LocalClient *lc,
68 const struct GNUNET_MessageHeader *msg); 71 const struct GNUNET_MessageHeader *msg);
69 72
70 73
71/** 74/**
@@ -75,8 +78,7 @@ GSF_local_client_transmit_ (struct GSF_LocalClient *lc,
75 * @param client handle of the client 78 * @param client handle of the client
76 */ 79 */
77void 80void
78GSF_client_disconnect_handler_ (void *cls, 81GSF_client_disconnect_handler_ (void *cls, struct GNUNET_SERVER_Client *client);
79 struct GNUNET_SERVER_Client *client);
80 82
81 83
82#endif 84#endif
diff --git a/src/fs/gnunet-service-fs_pe.c b/src/fs/gnunet-service-fs_pe.c
index 789642fc6..d3ab5026b 100644
--- a/src/fs/gnunet-service-fs_pe.c
+++ b/src/fs/gnunet-service-fs_pe.c
@@ -43,7 +43,7 @@ struct PendingRequestList;
43 */ 43 */
44struct GSF_RequestPlanReference 44struct GSF_RequestPlanReference
45{ 45{
46 46
47 /** 47 /**
48 * This is a doubly-linked list. 48 * This is a doubly-linked list.
49 */ 49 */
@@ -123,12 +123,12 @@ struct GSF_RequestPlan
123 /** 123 /**
124 * Head of list of associated pending requests. 124 * Head of list of associated pending requests.
125 */ 125 */
126 struct PendingRequestList *prl_head; 126 struct PendingRequestList *prl_head;
127 127
128 /** 128 /**
129 * Tail of list of associated pending requests. 129 * Tail of list of associated pending requests.
130 */ 130 */
131 struct PendingRequestList *prl_tail; 131 struct PendingRequestList *prl_tail;
132 132
133 /** 133 /**
134 * Earliest time we'd be happy to (re)transmit this request. 134 * Earliest time we'd be happy to (re)transmit this request.
@@ -209,7 +209,7 @@ static unsigned long long plan_count;
209 */ 209 */
210static void 210static void
211schedule_peer_transmission (void *cls, 211schedule_peer_transmission (void *cls,
212 const struct GNUNET_SCHEDULER_TaskContext *tc); 212 const struct GNUNET_SCHEDULER_TaskContext *tc);
213 213
214 214
215/** 215/**
@@ -219,42 +219,36 @@ schedule_peer_transmission (void *cls,
219 * @param rp request to plan 219 * @param rp request to plan
220 */ 220 */
221static void 221static void
222plan (struct PeerPlan *pp, 222plan (struct PeerPlan *pp, struct GSF_RequestPlan *rp)
223 struct GSF_RequestPlan *rp)
224{ 223{
225 struct GSF_PendingRequestData *prd; 224 struct GSF_PendingRequestData *prd;
226 struct GNUNET_TIME_Relative delay; 225 struct GNUNET_TIME_Relative delay;
227 226
228 GNUNET_STATISTICS_set (GSF_stats, 227 GNUNET_STATISTICS_set (GSF_stats,
229 gettext_noop ("# average retransmission delay (ms)"), 228 gettext_noop ("# average retransmission delay (ms)"),
230 total_delay * 1000LL / plan_count, 229 total_delay * 1000LL / plan_count, GNUNET_NO);
231 GNUNET_NO);
232 prd = GSF_pending_request_get_data_ (rp->prl_head->pr); 230 prd = GSF_pending_request_get_data_ (rp->prl_head->pr);
233 // FIXME: calculate 'rp->priority'! 231 // FIXME: calculate 'rp->priority'!
234 if (rp->transmission_counter < 32) 232 if (rp->transmission_counter < 32)
235 delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 233 delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
236 1LL << rp->transmission_counter); 234 1LL << rp->transmission_counter);
237 else 235 else
238 delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 236 delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, UINT_MAX);
239 UINT_MAX); 237 rp->earliest_transmission = GNUNET_TIME_relative_to_absolute (delay);
240 rp->earliest_transmission
241 = GNUNET_TIME_relative_to_absolute (delay);
242#if DEBUG_FS 238#if DEBUG_FS
243 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 239 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
244 "Earliest (re)transmission for `%s' in %us\n", 240 "Earliest (re)transmission for `%s' in %us\n",
245 GNUNET_h2s (&prd->query), 241 GNUNET_h2s (&prd->query), rp->transmission_counter);
246 rp->transmission_counter); 242#endif
247#endif
248 243
249 GNUNET_assert (rp->hn == NULL); 244 GNUNET_assert (rp->hn == NULL);
250 if (GNUNET_TIME_absolute_get_remaining (rp->earliest_transmission).rel_value == 0) 245 if (GNUNET_TIME_absolute_get_remaining (rp->earliest_transmission).rel_value
251 rp->hn = GNUNET_CONTAINER_heap_insert (pp->priority_heap, 246 == 0)
252 rp, 247 rp->hn = GNUNET_CONTAINER_heap_insert (pp->priority_heap, rp, rp->priority);
253 rp->priority);
254 else 248 else
255 rp->hn = GNUNET_CONTAINER_heap_insert (pp->delay_heap, 249 rp->hn = GNUNET_CONTAINER_heap_insert (pp->delay_heap,
256 rp, 250 rp,
257 rp->earliest_transmission.abs_value); 251 rp->earliest_transmission.abs_value);
258 if (GNUNET_SCHEDULER_NO_TASK != pp->task) 252 if (GNUNET_SCHEDULER_NO_TASK != pp->task)
259 GNUNET_SCHEDULER_cancel (pp->task); 253 GNUNET_SCHEDULER_cancel (pp->task);
260 pp->task = GNUNET_SCHEDULER_add_now (&schedule_peer_transmission, pp); 254 pp->task = GNUNET_SCHEDULER_add_now (&schedule_peer_transmission, pp);
@@ -277,13 +271,13 @@ get_latest (const struct GSF_RequestPlan *rp)
277 ret = prl->pr; 271 ret = prl->pr;
278 prl = prl->next; 272 prl = prl->next;
279 while (NULL != prl) 273 while (NULL != prl)
280 { 274 {
281 if (GSF_pending_request_get_data_ (prl->pr)->ttl.abs_value > 275 if (GSF_pending_request_get_data_ (prl->pr)->ttl.abs_value >
282 GSF_pending_request_get_data_ (ret)->ttl.abs_value) 276 GSF_pending_request_get_data_ (ret)->ttl.abs_value)
283 ret = prl->pr; 277 ret = prl->pr;
284 prl = prl->next; 278 prl = prl->next;
285 } 279 }
286 return ret; 280 return ret;
287} 281}
288 282
289 283
@@ -295,10 +289,8 @@ get_latest (const struct GSF_RequestPlan *rp)
295 * @param buf where to copy the message, NULL on error (peer disconnect) 289 * @param buf where to copy the message, NULL on error (peer disconnect)
296 * @return number of bytes copied to 'buf', can be 0 (without indicating an error) 290 * @return number of bytes copied to 'buf', can be 0 (without indicating an error)
297 */ 291 */
298static size_t 292static size_t
299transmit_message_callback (void *cls, 293transmit_message_callback (void *cls, size_t buf_size, void *buf)
300 size_t buf_size,
301 void *buf)
302{ 294{
303 struct PeerPlan *pp = cls; 295 struct PeerPlan *pp = cls;
304 struct GSF_RequestPlan *rp; 296 struct GSF_RequestPlan *rp;
@@ -306,24 +298,24 @@ transmit_message_callback (void *cls,
306 298
307 pp->pth = NULL; 299 pp->pth = NULL;
308 if (NULL == buf) 300 if (NULL == buf)
309 { 301 {
310 /* failed, try again... */ 302 /* failed, try again... */
311 pp->task = GNUNET_SCHEDULER_add_now (&schedule_peer_transmission, pp); 303 pp->task = GNUNET_SCHEDULER_add_now (&schedule_peer_transmission, pp);
312 return 0; 304 return 0;
313 } 305 }
314 rp = GNUNET_CONTAINER_heap_peek (pp->priority_heap); 306 rp = GNUNET_CONTAINER_heap_peek (pp->priority_heap);
315 if (NULL == rp) 307 if (NULL == rp)
316 { 308 {
317 pp->task = GNUNET_SCHEDULER_add_now (&schedule_peer_transmission, pp); 309 pp->task = GNUNET_SCHEDULER_add_now (&schedule_peer_transmission, pp);
318 return 0; 310 return 0;
319 } 311 }
320 msize = GSF_pending_request_get_message_ (get_latest (rp), buf_size, buf); 312 msize = GSF_pending_request_get_message_ (get_latest (rp), buf_size, buf);
321 if (msize > buf_size) 313 if (msize > buf_size)
322 { 314 {
323 /* buffer to small (message changed), try again */ 315 /* buffer to small (message changed), try again */
324 pp->task = GNUNET_SCHEDULER_add_now (&schedule_peer_transmission, pp); 316 pp->task = GNUNET_SCHEDULER_add_now (&schedule_peer_transmission, pp);
325 return 0; 317 return 0;
326 } 318 }
327 /* remove from root, add again elsewhere... */ 319 /* remove from root, add again elsewhere... */
328 GNUNET_assert (rp == GNUNET_CONTAINER_heap_remove_root (pp->priority_heap)); 320 GNUNET_assert (rp == GNUNET_CONTAINER_heap_remove_root (pp->priority_heap));
329 rp->hn = NULL; 321 rp->hn = NULL;
@@ -332,15 +324,14 @@ transmit_message_callback (void *cls,
332 total_delay++; 324 total_delay++;
333#if DEBUG_FS 325#if DEBUG_FS
334 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 326 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
335 "Executing plan %p executed %u times, planning retransmission\n", 327 "Executing plan %p executed %u times, planning retransmission\n",
336 rp, 328 rp, rp->transmission_counter);
337 rp->transmission_counter); 329#endif
338#endif
339 plan (pp, rp); 330 plan (pp, rp);
340 GNUNET_STATISTICS_update (GSF_stats, 331 GNUNET_STATISTICS_update (GSF_stats,
341 gettext_noop ("# queries messages sent to other peers"), 332 gettext_noop
342 1, 333 ("# queries messages sent to other peers"), 1,
343 GNUNET_NO); 334 GNUNET_NO);
344 return msize; 335 return msize;
345} 336}
346 337
@@ -353,7 +344,7 @@ transmit_message_callback (void *cls,
353 */ 344 */
354static void 345static void
355schedule_peer_transmission (void *cls, 346schedule_peer_transmission (void *cls,
356 const struct GNUNET_SCHEDULER_TaskContext *tc) 347 const struct GNUNET_SCHEDULER_TaskContext *tc)
357{ 348{
358 struct PeerPlan *pp = cls; 349 struct PeerPlan *pp = cls;
359 struct GSF_RequestPlan *rp; 350 struct GSF_RequestPlan *rp;
@@ -361,59 +352,55 @@ schedule_peer_transmission (void *cls,
361 352
362 pp->task = GNUNET_SCHEDULER_NO_TASK; 353 pp->task = GNUNET_SCHEDULER_NO_TASK;
363 if (pp->pth != NULL) 354 if (pp->pth != NULL)
364 { 355 {
365 GSF_peer_transmit_cancel_ (pp->pth); 356 GSF_peer_transmit_cancel_ (pp->pth);
366 pp->pth = NULL; 357 pp->pth = NULL;
367 } 358 }
368 /* move ready requests to priority queue */ 359 /* move ready requests to priority queue */
369 while ( (NULL != (rp = GNUNET_CONTAINER_heap_peek (pp->delay_heap))) && 360 while ((NULL != (rp = GNUNET_CONTAINER_heap_peek (pp->delay_heap))) &&
370 (GNUNET_TIME_absolute_get_remaining (rp->earliest_transmission).rel_value == 0) ) 361 (GNUNET_TIME_absolute_get_remaining
371 { 362 (rp->earliest_transmission).rel_value == 0))
372 GNUNET_assert (rp == GNUNET_CONTAINER_heap_remove_root (pp->delay_heap)); 363 {
373 rp->hn = GNUNET_CONTAINER_heap_insert (pp->priority_heap, 364 GNUNET_assert (rp == GNUNET_CONTAINER_heap_remove_root (pp->delay_heap));
374 rp, 365 rp->hn = GNUNET_CONTAINER_heap_insert (pp->priority_heap, rp, rp->priority);
375 rp->priority); 366 }
376 }
377 if (0 == GNUNET_CONTAINER_heap_get_size (pp->priority_heap)) 367 if (0 == GNUNET_CONTAINER_heap_get_size (pp->priority_heap))
368 {
369 /* priority heap (still) empty, check for delay... */
370 rp = GNUNET_CONTAINER_heap_peek (pp->delay_heap);
371 if (NULL == rp)
378 { 372 {
379 /* priority heap (still) empty, check for delay... */
380 rp = GNUNET_CONTAINER_heap_peek (pp->delay_heap);
381 if (NULL == rp)
382 {
383#if DEBUG_FS
384 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
385 "No active requests for plan %p.\n",
386 pp);
387#endif
388 return; /* both queues empty */
389 }
390#if DEBUG_FS 373#if DEBUG_FS
391 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 374 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
392 "Sleeping for %llu ms before retrying requests on plan %p.\n", 375 "No active requests for plan %p.\n", pp);
393 (unsigned long long) GNUNET_TIME_absolute_get_remaining (rp->earliest_transmission).rel_value,
394 pp);
395#endif 376#endif
396 pp->task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining (rp->earliest_transmission), 377 return; /* both queues empty */
397 &schedule_peer_transmission,
398 pp);
399 return;
400 } 378 }
379#if DEBUG_FS
380 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
381 "Sleeping for %llu ms before retrying requests on plan %p.\n",
382 (unsigned long long)
383 GNUNET_TIME_absolute_get_remaining
384 (rp->earliest_transmission).rel_value, pp);
385#endif
386 pp->task =
387 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining
388 (rp->earliest_transmission),
389 &schedule_peer_transmission, pp);
390 return;
391 }
401 /* process from priority heap */ 392 /* process from priority heap */
402 rp = GNUNET_CONTAINER_heap_peek (pp->priority_heap); 393 rp = GNUNET_CONTAINER_heap_peek (pp->priority_heap);
403#if DEBUG_FS > 1 394#if DEBUG_FS > 1
404 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 395 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing query plan %p\n", rp);
405 "Executing query plan %p\n", 396#endif
406 rp);
407#endif
408 GNUNET_assert (NULL != rp); 397 GNUNET_assert (NULL != rp);
409 msize = GSF_pending_request_get_message_ (get_latest (rp), 0, NULL); 398 msize = GSF_pending_request_get_message_ (get_latest (rp), 0, NULL);
410 pp->pth = GSF_peer_transmit_ (pp->cp, 399 pp->pth = GSF_peer_transmit_ (pp->cp,
411 GNUNET_YES, 400 GNUNET_YES,
412 rp->priority, 401 rp->priority,
413 GNUNET_TIME_UNIT_FOREVER_REL, 402 GNUNET_TIME_UNIT_FOREVER_REL,
414 msize, 403 msize, &transmit_message_callback, pp);
415 &transmit_message_callback,
416 pp);
417 GNUNET_assert (NULL != pp->pth); 404 GNUNET_assert (NULL != pp->pth);
418} 405}
419 406
@@ -444,9 +431,8 @@ struct MergeContext
444 */ 431 */
445static int 432static int
446merge_pr (void *cls, 433merge_pr (void *cls,
447 struct GNUNET_CONTAINER_HeapNode *node, 434 struct GNUNET_CONTAINER_HeapNode *node,
448 void *element, 435 void *element, GNUNET_CONTAINER_HeapCostType cost)
449 GNUNET_CONTAINER_HeapCostType cost)
450{ 436{
451 struct MergeContext *mpr = cls; 437 struct MergeContext *mpr = cls;
452 struct GSF_RequestPlan *rp = element; 438 struct GSF_RequestPlan *rp = element;
@@ -456,37 +442,30 @@ merge_pr (void *cls,
456 struct GSF_PendingRequest *latest; 442 struct GSF_PendingRequest *latest;
457 443
458 if (GNUNET_OK != 444 if (GNUNET_OK !=
459 GSF_pending_request_is_compatible_ (mpr->pr, 445 GSF_pending_request_is_compatible_ (mpr->pr, rp->prl_head->pr))
460 rp->prl_head->pr))
461 return GNUNET_YES; 446 return GNUNET_YES;
462 /* merge new request with existing request plan */ 447 /* merge new request with existing request plan */
463 rpr = GNUNET_malloc (sizeof (struct GSF_RequestPlanReference)); 448 rpr = GNUNET_malloc (sizeof (struct GSF_RequestPlanReference));
464 prl = GNUNET_malloc (sizeof (struct PendingRequestList)); 449 prl = GNUNET_malloc (sizeof (struct PendingRequestList));
465 rpr->rp = rp; 450 rpr->rp = rp;
466 rpr->prl = prl; 451 rpr->prl = prl;
467 prl->rpr = rpr; 452 prl->rpr = rpr;
468 prl->pr = mpr->pr; 453 prl->pr = mpr->pr;
469 prd = GSF_pending_request_get_data_ (mpr->pr); 454 prd = GSF_pending_request_get_data_ (mpr->pr);
470 GNUNET_CONTAINER_DLL_insert (prd->rpr_head, 455 GNUNET_CONTAINER_DLL_insert (prd->rpr_head, prd->rpr_tail, rpr);
471 prd->rpr_tail, 456 GNUNET_CONTAINER_DLL_insert (rp->prl_head, rp->prl_tail, prl);
472 rpr);
473 GNUNET_CONTAINER_DLL_insert (rp->prl_head,
474 rp->prl_tail,
475 prl);
476 mpr->merged = GNUNET_YES; 457 mpr->merged = GNUNET_YES;
477 GNUNET_STATISTICS_update (GSF_stats, 458 GNUNET_STATISTICS_update (GSF_stats,
478 gettext_noop ("# requests merged"), 459 gettext_noop ("# requests merged"), 1, GNUNET_NO);
479 1,
480 GNUNET_NO);
481 latest = get_latest (rp); 460 latest = get_latest (rp);
482 if (GSF_pending_request_get_data_ (latest)->ttl.abs_value < prd->ttl.abs_value) 461 if (GSF_pending_request_get_data_ (latest)->ttl.abs_value <
483 { 462 prd->ttl.abs_value)
484 GNUNET_STATISTICS_update (GSF_stats, 463 {
485 gettext_noop ("# requests refreshed"), 464 GNUNET_STATISTICS_update (GSF_stats,
486 1, 465 gettext_noop ("# requests refreshed"),
487 GNUNET_NO); 466 1, GNUNET_NO);
488 rp->transmission_counter = 0; /* reset */ 467 rp->transmission_counter = 0; /* reset */
489 } 468 }
490 return GNUNET_NO; 469 return GNUNET_NO;
491} 470}
492 471
@@ -498,8 +477,7 @@ merge_pr (void *cls,
498 * @param pr request with the entry 477 * @param pr request with the entry
499 */ 478 */
500void 479void
501GSF_plan_add_ (struct GSF_ConnectedPeer *cp, 480GSF_plan_add_ (struct GSF_ConnectedPeer *cp, struct GSF_PendingRequest *pr)
502 struct GSF_PendingRequest *pr)
503{ 481{
504 struct GNUNET_PeerIdentity id; 482 struct GNUNET_PeerIdentity id;
505 struct PeerPlan *pp; 483 struct PeerPlan *pp;
@@ -511,19 +489,20 @@ GSF_plan_add_ (struct GSF_ConnectedPeer *cp,
511 489
512 GNUNET_assert (NULL != cp); 490 GNUNET_assert (NULL != cp);
513 GSF_connected_peer_get_identity_ (cp, &id); 491 GSF_connected_peer_get_identity_ (cp, &id);
514 pp = GNUNET_CONTAINER_multihashmap_get (plans, 492 pp = GNUNET_CONTAINER_multihashmap_get (plans, &id.hashPubKey);
515 &id.hashPubKey);
516 if (NULL == pp) 493 if (NULL == pp)
517 { 494 {
518 pp = GNUNET_malloc (sizeof (struct PeerPlan)); 495 pp = GNUNET_malloc (sizeof (struct PeerPlan));
519 pp->priority_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MAX); 496 pp->priority_heap =
520 pp->delay_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); 497 GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MAX);
521 pp->cp = cp; 498 pp->delay_heap =
522 GNUNET_CONTAINER_multihashmap_put (plans, 499 GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
523 &id.hashPubKey, 500 pp->cp = cp;
524 pp, 501 GNUNET_CONTAINER_multihashmap_put (plans,
525 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); 502 &id.hashPubKey,
526 } 503 pp,
504 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
505 }
527 mpc.merged = GNUNET_NO; 506 mpc.merged = GNUNET_NO;
528 mpc.pr = pr; 507 mpc.pr = pr;
529 GNUNET_CONTAINER_heap_iterate (pp->priority_heap, &merge_pr, &mpc); 508 GNUNET_CONTAINER_heap_iterate (pp->priority_heap, &merge_pr, &mpc);
@@ -534,29 +513,23 @@ GSF_plan_add_ (struct GSF_ConnectedPeer *cp,
534 return; 513 return;
535 plan_count++; 514 plan_count++;
536 GNUNET_STATISTICS_update (GSF_stats, 515 GNUNET_STATISTICS_update (GSF_stats,
537 gettext_noop ("# query plan entries"), 516 gettext_noop ("# query plan entries"),
538 1, 517 1, GNUNET_NO);
539 GNUNET_NO);
540 prd = GSF_pending_request_get_data_ (pr); 518 prd = GSF_pending_request_get_data_ (pr);
541#if DEBUG_FS 519#if DEBUG_FS
542 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 520 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
543 "Planning transmission of query `%s' to peer `%s'\n", 521 "Planning transmission of query `%s' to peer `%s'\n",
544 GNUNET_h2s (&prd->query), 522 GNUNET_h2s (&prd->query), GNUNET_i2s (&id));
545 GNUNET_i2s (&id)); 523#endif
546#endif
547 rp = GNUNET_malloc (sizeof (struct GSF_RequestPlan)); 524 rp = GNUNET_malloc (sizeof (struct GSF_RequestPlan));
548 rpr = GNUNET_malloc (sizeof (struct GSF_RequestPlanReference)); 525 rpr = GNUNET_malloc (sizeof (struct GSF_RequestPlanReference));
549 prl = GNUNET_malloc (sizeof (struct PendingRequestList)); 526 prl = GNUNET_malloc (sizeof (struct PendingRequestList));
550 rpr->rp = rp; 527 rpr->rp = rp;
551 rpr->prl = prl; 528 rpr->prl = prl;
552 prl->rpr = rpr; 529 prl->rpr = rpr;
553 prl->pr = pr; 530 prl->pr = pr;
554 GNUNET_CONTAINER_DLL_insert (prd->rpr_head, 531 GNUNET_CONTAINER_DLL_insert (prd->rpr_head, prd->rpr_tail, rpr);
555 prd->rpr_tail, 532 GNUNET_CONTAINER_DLL_insert (rp->prl_head, rp->prl_tail, prl);
556 rpr);
557 GNUNET_CONTAINER_DLL_insert (rp->prl_head,
558 rp->prl_tail,
559 prl);
560 plan (pp, rp); 533 plan (pp, rp);
561} 534}
562 535
@@ -577,58 +550,47 @@ GSF_plan_notify_peer_disconnect_ (const struct GSF_ConnectedPeer *cp)
577 struct PendingRequestList *prl; 550 struct PendingRequestList *prl;
578 551
579 GSF_connected_peer_get_identity_ (cp, &id); 552 GSF_connected_peer_get_identity_ (cp, &id);
580 pp = GNUNET_CONTAINER_multihashmap_get (plans, 553 pp = GNUNET_CONTAINER_multihashmap_get (plans, &id.hashPubKey);
581 &id.hashPubKey);
582 if (NULL == pp) 554 if (NULL == pp)
583 return; /* nothing was ever planned for this peer */ 555 return; /* nothing was ever planned for this peer */
584 GNUNET_assert (GNUNET_YES == 556 GNUNET_assert (GNUNET_YES ==
585 GNUNET_CONTAINER_multihashmap_remove (plans, 557 GNUNET_CONTAINER_multihashmap_remove (plans,
586 &id.hashPubKey, 558 &id.hashPubKey, pp));
587 pp));
588 if (NULL != pp->pth) 559 if (NULL != pp->pth)
589 GSF_peer_transmit_cancel_ (pp->pth); 560 GSF_peer_transmit_cancel_ (pp->pth);
590 if (GNUNET_SCHEDULER_NO_TASK != pp->task) 561 if (GNUNET_SCHEDULER_NO_TASK != pp->task)
591 { 562 {
592 GNUNET_SCHEDULER_cancel (pp->task); 563 GNUNET_SCHEDULER_cancel (pp->task);
593 pp->task = GNUNET_SCHEDULER_NO_TASK; 564 pp->task = GNUNET_SCHEDULER_NO_TASK;
594 } 565 }
595 while (NULL != (rp = GNUNET_CONTAINER_heap_remove_root (pp->priority_heap))) 566 while (NULL != (rp = GNUNET_CONTAINER_heap_remove_root (pp->priority_heap)))
567 {
568 while (NULL != (prl = rp->prl_head))
596 { 569 {
597 while (NULL != (prl = rp->prl_head)) 570 GNUNET_CONTAINER_DLL_remove (rp->prl_head, rp->prl_tail, prl);
598 { 571 prd = GSF_pending_request_get_data_ (prl->pr);
599 GNUNET_CONTAINER_DLL_remove (rp->prl_head, 572 GNUNET_CONTAINER_DLL_remove (prd->rpr_head, prd->rpr_tail, prl->rpr);
600 rp->prl_tail, 573 GNUNET_free (prl->rpr);
601 prl); 574 GNUNET_free (prl);
602 prd = GSF_pending_request_get_data_ (prl->pr);
603 GNUNET_CONTAINER_DLL_remove (prd->rpr_head,
604 prd->rpr_tail,
605 prl->rpr);
606 GNUNET_free (prl->rpr);
607 GNUNET_free (prl);
608 }
609 GNUNET_free (rp);
610 } 575 }
576 GNUNET_free (rp);
577 }
611 GNUNET_CONTAINER_heap_destroy (pp->priority_heap); 578 GNUNET_CONTAINER_heap_destroy (pp->priority_heap);
612 while (NULL != (rp = GNUNET_CONTAINER_heap_remove_root (pp->delay_heap))) 579 while (NULL != (rp = GNUNET_CONTAINER_heap_remove_root (pp->delay_heap)))
580 {
581 while (NULL != (prl = rp->prl_head))
613 { 582 {
614 while (NULL != (prl = rp->prl_head)) 583 GNUNET_CONTAINER_DLL_remove (rp->prl_head, rp->prl_tail, prl);
615 { 584 prd = GSF_pending_request_get_data_ (prl->pr);
616 GNUNET_CONTAINER_DLL_remove (rp->prl_head, 585 GNUNET_CONTAINER_DLL_remove (prd->rpr_head, prd->rpr_tail, prl->rpr);
617 rp->prl_tail, 586 GNUNET_free (prl->rpr);
618 prl); 587 GNUNET_free (prl);
619 prd = GSF_pending_request_get_data_ (prl->pr);
620 GNUNET_CONTAINER_DLL_remove (prd->rpr_head,
621 prd->rpr_tail,
622 prl->rpr);
623 GNUNET_free (prl->rpr);
624 GNUNET_free (prl);
625 }
626 GNUNET_free (rp);
627 } 588 }
589 GNUNET_free (rp);
590 }
628 GNUNET_STATISTICS_set (GSF_stats, 591 GNUNET_STATISTICS_set (GSF_stats,
629 gettext_noop ("# query plan entries"), 592 gettext_noop ("# query plan entries"),
630 plan_count, 593 plan_count, GNUNET_NO);
631 GNUNET_NO);
632 594
633 GNUNET_CONTAINER_heap_destroy (pp->delay_heap); 595 GNUNET_CONTAINER_heap_destroy (pp->delay_heap);
634 GNUNET_free (pp); 596 GNUNET_free (pp);
@@ -650,27 +612,22 @@ GSF_plan_notify_request_done_ (struct GSF_PendingRequest *pr)
650 612
651 prd = GSF_pending_request_get_data_ (pr); 613 prd = GSF_pending_request_get_data_ (pr);
652 while (NULL != (rpr = prd->rpr_head)) 614 while (NULL != (rpr = prd->rpr_head))
615 {
616 GNUNET_CONTAINER_DLL_remove (prd->rpr_head, prd->rpr_tail, rpr);
617 rp = rpr->rp;
618 GNUNET_CONTAINER_DLL_remove (rp->prl_head, rp->prl_tail, rpr->prl);
619 GNUNET_free (rpr->prl);
620 GNUNET_free (rpr);
621 if (rp->prl_head == 0)
653 { 622 {
654 GNUNET_CONTAINER_DLL_remove (prd->rpr_head, 623 GNUNET_CONTAINER_heap_remove_node (rp->hn);
655 prd->rpr_tail, 624 plan_count--;
656 rpr); 625 GNUNET_free (rp);
657 rp = rpr->rp;
658 GNUNET_CONTAINER_DLL_remove (rp->prl_head,
659 rp->prl_tail,
660 rpr->prl);
661 GNUNET_free (rpr->prl);
662 GNUNET_free (rpr);
663 if (rp->prl_head == 0)
664 {
665 GNUNET_CONTAINER_heap_remove_node (rp->hn);
666 plan_count--;
667 GNUNET_free (rp);
668 }
669 } 626 }
627 }
670 GNUNET_STATISTICS_set (GSF_stats, 628 GNUNET_STATISTICS_set (GSF_stats,
671 gettext_noop ("# query plan entries"), 629 gettext_noop ("# query plan entries"),
672 plan_count, 630 plan_count, GNUNET_NO);
673 GNUNET_NO);
674} 631}
675 632
676 633
@@ -690,8 +647,7 @@ GSF_plan_init ()
690void 647void
691GSF_plan_done () 648GSF_plan_done ()
692{ 649{
693 GNUNET_assert (0 == 650 GNUNET_assert (0 == GNUNET_CONTAINER_multihashmap_size (plans));
694 GNUNET_CONTAINER_multihashmap_size (plans));
695 GNUNET_CONTAINER_multihashmap_destroy (plans); 651 GNUNET_CONTAINER_multihashmap_destroy (plans);
696} 652}
697 653
diff --git a/src/fs/gnunet-service-fs_pe.h b/src/fs/gnunet-service-fs_pe.h
index 37280adc6..7fbf9fc4a 100644
--- a/src/fs/gnunet-service-fs_pe.h
+++ b/src/fs/gnunet-service-fs_pe.h
@@ -36,8 +36,7 @@
36 * @param pr request with the entry 36 * @param pr request with the entry
37 */ 37 */
38void 38void
39GSF_plan_add_ (struct GSF_ConnectedPeer *cp, 39GSF_plan_add_ (struct GSF_ConnectedPeer *cp, struct GSF_PendingRequest *pr);
40 struct GSF_PendingRequest *pr);
41 40
42 41
43/** 42/**
@@ -46,8 +45,7 @@ GSF_plan_add_ (struct GSF_ConnectedPeer *cp,
46 * 45 *
47 * @param cp connected peer 46 * @param cp connected peer
48 */ 47 */
49void 48void GSF_plan_notify_peer_disconnect_ (const struct GSF_ConnectedPeer *cp);
50GSF_plan_notify_peer_disconnect_ (const struct GSF_ConnectedPeer *cp);
51 49
52 50
53/** 51/**
@@ -56,22 +54,19 @@ GSF_plan_notify_peer_disconnect_ (const struct GSF_ConnectedPeer *cp);
56 * 54 *
57 * @param pr request that is done 55 * @param pr request that is done
58 */ 56 */
59void 57void GSF_plan_notify_request_done_ (struct GSF_PendingRequest *pr);
60GSF_plan_notify_request_done_ (struct GSF_PendingRequest *pr);
61 58
62 59
63/** 60/**
64 * Initialize plan subsystem. 61 * Initialize plan subsystem.
65 */ 62 */
66void 63void GSF_plan_init (void);
67GSF_plan_init (void);
68 64
69 65
70/** 66/**
71 * Shutdown plan subsystem. 67 * Shutdown plan subsystem.
72 */ 68 */
73void 69void GSF_plan_done (void);
74GSF_plan_done (void);
75 70
76 71
77#endif 72#endif
diff --git a/src/fs/gnunet-service-fs_pr.c b/src/fs/gnunet-service-fs_pr.c
index d3ea241a5..e637be664 100644
--- a/src/fs/gnunet-service-fs_pr.c
+++ b/src/fs/gnunet-service-fs_pr.c
@@ -43,7 +43,7 @@ struct GSF_PendingRequest
43{ 43{
44 /** 44 /**
45 * Public data for the request. 45 * Public data for the request.
46 */ 46 */
47 struct GSF_PendingRequestData public_data; 47 struct GSF_PendingRequestData public_data;
48 48
49 /** 49 /**
@@ -236,23 +236,19 @@ refresh_bloomfilter (struct GSF_PendingRequest *pr)
236 GNUNET_HashCode mhash; 236 GNUNET_HashCode mhash;
237 237
238 nsize = compute_bloomfilter_size (pr->replies_seen_count); 238 nsize = compute_bloomfilter_size (pr->replies_seen_count);
239 if ( (pr->bf != NULL) && 239 if ((pr->bf != NULL) &&
240 (nsize == GNUNET_CONTAINER_bloomfilter_get_size (pr->bf)) ) 240 (nsize == GNUNET_CONTAINER_bloomfilter_get_size (pr->bf)))
241 return GNUNET_NO; /* size not changed */ 241 return GNUNET_NO; /* size not changed */
242 if (pr->bf != NULL) 242 if (pr->bf != NULL)
243 GNUNET_CONTAINER_bloomfilter_free (pr->bf); 243 GNUNET_CONTAINER_bloomfilter_free (pr->bf);
244 pr->mingle = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 244 pr->mingle = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
245 UINT32_MAX); 245 UINT32_MAX);
246 pr->bf = GNUNET_CONTAINER_bloomfilter_init (NULL, 246 pr->bf = GNUNET_CONTAINER_bloomfilter_init (NULL, nsize, BLOOMFILTER_K);
247 nsize, 247 for (i = 0; i < pr->replies_seen_count; i++)
248 BLOOMFILTER_K); 248 {
249 for (i=0;i<pr->replies_seen_count;i++) 249 GNUNET_BLOCK_mingle_hash (&pr->replies_seen[i], pr->mingle, &mhash);
250 { 250 GNUNET_CONTAINER_bloomfilter_add (pr->bf, &mhash);
251 GNUNET_BLOCK_mingle_hash (&pr->replies_seen[i], 251 }
252 pr->mingle,
253 &mhash);
254 GNUNET_CONTAINER_bloomfilter_add (pr->bf, &mhash);
255 }
256 return GNUNET_YES; 252 return GNUNET_YES;
257} 253}
258 254
@@ -280,118 +276,115 @@ refresh_bloomfilter (struct GSF_PendingRequest *pr)
280 */ 276 */
281struct GSF_PendingRequest * 277struct GSF_PendingRequest *
282GSF_pending_request_create_ (enum GSF_PendingRequestOptions options, 278GSF_pending_request_create_ (enum GSF_PendingRequestOptions options,
283 enum GNUNET_BLOCK_Type type, 279 enum GNUNET_BLOCK_Type type,
284 const GNUNET_HashCode *query, 280 const GNUNET_HashCode * query,
285 const GNUNET_HashCode *namespace, 281 const GNUNET_HashCode * namespace,
286 const struct GNUNET_PeerIdentity *target, 282 const struct GNUNET_PeerIdentity *target,
287 const char *bf_data, 283 const char *bf_data,
288 size_t bf_size, 284 size_t bf_size,
289 uint32_t mingle, 285 uint32_t mingle,
290 uint32_t anonymity_level, 286 uint32_t anonymity_level,
291 uint32_t priority, 287 uint32_t priority,
292 int32_t ttl, 288 int32_t ttl,
293 GNUNET_PEER_Id sender_pid, 289 GNUNET_PEER_Id sender_pid,
294 const GNUNET_HashCode *replies_seen, 290 const GNUNET_HashCode * replies_seen,
295 unsigned int replies_seen_count, 291 unsigned int replies_seen_count,
296 GSF_PendingRequestReplyHandler rh, 292 GSF_PendingRequestReplyHandler rh, void *rh_cls)
297 void *rh_cls)
298{ 293{
299 struct GSF_PendingRequest *pr; 294 struct GSF_PendingRequest *pr;
300 struct GSF_PendingRequest *dpr; 295 struct GSF_PendingRequest *dpr;
301 296
302#if DEBUG_FS > 1 297#if DEBUG_FS > 1
303 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 298 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
304 "Creating request handle for `%s' of type %d\n", 299 "Creating request handle for `%s' of type %d\n",
305 GNUNET_h2s (query), 300 GNUNET_h2s (query), type);
306 type); 301#endif
307#endif
308 GNUNET_STATISTICS_update (GSF_stats, 302 GNUNET_STATISTICS_update (GSF_stats,
309 gettext_noop ("# Pending requests created"), 303 gettext_noop ("# Pending requests created"),
310 1, 304 1, GNUNET_NO);
311 GNUNET_NO);
312 pr = GNUNET_malloc (sizeof (struct GSF_PendingRequest)); 305 pr = GNUNET_malloc (sizeof (struct GSF_PendingRequest));
313 pr->local_result_offset = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, 306 pr->local_result_offset =
314 UINT64_MAX); 307 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX);
315 pr->public_data.query = *query; 308 pr->public_data.query = *query;
316 if (GNUNET_BLOCK_TYPE_FS_SBLOCK == type) 309 if (GNUNET_BLOCK_TYPE_FS_SBLOCK == type)
317 { 310 {
318 GNUNET_assert (NULL != namespace); 311 GNUNET_assert (NULL != namespace);
319 pr->public_data.namespace = *namespace; 312 pr->public_data.namespace = *namespace;
320 } 313 }
321 if (NULL != target) 314 if (NULL != target)
322 { 315 {
323 pr->public_data.target = *target; 316 pr->public_data.target = *target;
324 pr->public_data.has_target = GNUNET_YES; 317 pr->public_data.has_target = GNUNET_YES;
325 } 318 }
326 pr->public_data.anonymity_level = anonymity_level; 319 pr->public_data.anonymity_level = anonymity_level;
327 pr->public_data.priority = priority; 320 pr->public_data.priority = priority;
328 pr->public_data.original_priority = priority; 321 pr->public_data.original_priority = priority;
329 pr->public_data.options = options; 322 pr->public_data.options = options;
330 pr->public_data.type = type; 323 pr->public_data.type = type;
331 pr->public_data.start_time = GNUNET_TIME_absolute_get (); 324 pr->public_data.start_time = GNUNET_TIME_absolute_get ();
332 pr->sender_pid = sender_pid; 325 pr->sender_pid = sender_pid;
333 pr->rh = rh; 326 pr->rh = rh;
334 pr->rh_cls = rh_cls; 327 pr->rh_cls = rh_cls;
335 GNUNET_assert ( (sender_pid != 0) || 328 GNUNET_assert ((sender_pid != 0) || (0 == (options & GSF_PRO_FORWARD_ONLY)));
336 (0 == (options & GSF_PRO_FORWARD_ONLY)) );
337 if (ttl >= 0) 329 if (ttl >= 0)
338 pr->public_data.ttl = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 330 pr->public_data.ttl =
339 (uint32_t) ttl)); 331 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply
332 (GNUNET_TIME_UNIT_SECONDS,
333 (uint32_t) ttl));
340 else 334 else
341 pr->public_data.ttl = GNUNET_TIME_absolute_subtract (pr->public_data.start_time, 335 pr->public_data.ttl =
342 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 336 GNUNET_TIME_absolute_subtract (pr->public_data.start_time,
343 (uint32_t) (- ttl))); 337 GNUNET_TIME_relative_multiply
338 (GNUNET_TIME_UNIT_SECONDS,
339 (uint32_t) (-ttl)));
344 if (replies_seen_count > 0) 340 if (replies_seen_count > 0)
345 { 341 {
346 pr->replies_seen_size = replies_seen_count; 342 pr->replies_seen_size = replies_seen_count;
347 pr->replies_seen = GNUNET_malloc (sizeof (GNUNET_HashCode) * pr->replies_seen_size); 343 pr->replies_seen =
348 memcpy (pr->replies_seen, 344 GNUNET_malloc (sizeof (GNUNET_HashCode) * pr->replies_seen_size);
349 replies_seen, 345 memcpy (pr->replies_seen, replies_seen,
350 replies_seen_count * sizeof (GNUNET_HashCode)); 346 replies_seen_count * sizeof (GNUNET_HashCode));
351 pr->replies_seen_count = replies_seen_count; 347 pr->replies_seen_count = replies_seen_count;
352 } 348 }
353 if (NULL != bf_data) 349 if (NULL != bf_data)
354 { 350 {
355 pr->bf = GNUNET_CONTAINER_bloomfilter_init (bf_data, 351 pr->bf = GNUNET_CONTAINER_bloomfilter_init (bf_data,
356 bf_size, 352 bf_size, BLOOMFILTER_K);
357 BLOOMFILTER_K); 353 pr->mingle = mingle;
358 pr->mingle = mingle; 354 }
359 } 355 else if ((replies_seen_count > 0) &&
360 else if ( (replies_seen_count > 0) && 356 (0 != (options & GSF_PRO_BLOOMFILTER_FULL_REFRESH)))
361 (0 != (options & GSF_PRO_BLOOMFILTER_FULL_REFRESH)) ) 357 {
362 { 358 GNUNET_assert (GNUNET_YES == refresh_bloomfilter (pr));
363 GNUNET_assert (GNUNET_YES == refresh_bloomfilter (pr)); 359 }
364 }
365 GNUNET_CONTAINER_multihashmap_put (pr_map, 360 GNUNET_CONTAINER_multihashmap_put (pr_map,
366 query, 361 query,
367 pr, 362 pr,
368 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 363 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
369 if (0 != (options & GSF_PRO_REQUEST_EXPIRES)) 364 if (0 != (options & GSF_PRO_REQUEST_EXPIRES))
365 {
366 pr->hnode = GNUNET_CONTAINER_heap_insert (requests_by_expiration_heap,
367 pr,
368 pr->public_data.ttl.abs_value);
369 /* make sure we don't track too many requests */
370 while (GNUNET_CONTAINER_heap_get_size (requests_by_expiration_heap) >
371 max_pending_requests)
370 { 372 {
371 pr->hnode = GNUNET_CONTAINER_heap_insert (requests_by_expiration_heap, 373 dpr = GNUNET_CONTAINER_heap_peek (requests_by_expiration_heap);
372 pr, 374 GNUNET_assert (dpr != NULL);
373 pr->public_data.ttl.abs_value); 375 if (pr == dpr)
374 /* make sure we don't track too many requests */ 376 break; /* let the request live briefly... */
375 while (GNUNET_CONTAINER_heap_get_size (requests_by_expiration_heap) > max_pending_requests) 377 dpr->rh (dpr->rh_cls,
376 { 378 GNUNET_BLOCK_EVALUATION_REQUEST_VALID,
377 dpr = GNUNET_CONTAINER_heap_peek (requests_by_expiration_heap); 379 dpr,
378 GNUNET_assert (dpr != NULL); 380 UINT32_MAX,
379 if (pr == dpr) 381 GNUNET_TIME_UNIT_FOREVER_ABS, GNUNET_BLOCK_TYPE_ANY, NULL, 0);
380 break; /* let the request live briefly... */ 382 GSF_pending_request_cancel_ (dpr, GNUNET_YES);
381 dpr->rh (dpr->rh_cls,
382 GNUNET_BLOCK_EVALUATION_REQUEST_VALID,
383 dpr,
384 UINT32_MAX,
385 GNUNET_TIME_UNIT_FOREVER_ABS,
386 GNUNET_BLOCK_TYPE_ANY,
387 NULL, 0);
388 GSF_pending_request_cancel_ (dpr, GNUNET_YES);
389 }
390 } 383 }
384 }
391 GNUNET_STATISTICS_update (GSF_stats, 385 GNUNET_STATISTICS_update (GSF_stats,
392 gettext_noop ("# Pending requests active"), 386 gettext_noop ("# Pending requests active"),
393 1, 387 1, GNUNET_NO);
394 GNUNET_NO);
395 return pr; 388 return pr;
396} 389}
397 390
@@ -420,16 +413,15 @@ GSF_pending_request_get_data_ (struct GSF_PendingRequest *pr)
420 */ 413 */
421int 414int
422GSF_pending_request_is_compatible_ (struct GSF_PendingRequest *pra, 415GSF_pending_request_is_compatible_ (struct GSF_PendingRequest *pra,
423 struct GSF_PendingRequest *prb) 416 struct GSF_PendingRequest *prb)
424{ 417{
425 if ( (pra->public_data.type != prb->public_data.type) || 418 if ((pra->public_data.type != prb->public_data.type) ||
426 (0 != memcmp (&pra->public_data.query, 419 (0 != memcmp (&pra->public_data.query,
427 &prb->public_data.query, 420 &prb->public_data.query,
428 sizeof (GNUNET_HashCode))) || 421 sizeof (GNUNET_HashCode))) ||
429 ( (pra->public_data.type == GNUNET_BLOCK_TYPE_FS_SBLOCK) && 422 ((pra->public_data.type == GNUNET_BLOCK_TYPE_FS_SBLOCK) &&
430 (0 != memcmp (&pra->public_data.namespace, 423 (0 != memcmp (&pra->public_data.namespace,
431 &prb->public_data.namespace, 424 &prb->public_data.namespace, sizeof (GNUNET_HashCode)))))
432 sizeof (GNUNET_HashCode))) ) )
433 return GNUNET_NO; 425 return GNUNET_NO;
434 return GNUNET_OK; 426 return GNUNET_OK;
435} 427}
@@ -446,57 +438,53 @@ GSF_pending_request_is_compatible_ (struct GSF_PendingRequest *pra,
446 */ 438 */
447void 439void
448GSF_pending_request_update_ (struct GSF_PendingRequest *pr, 440GSF_pending_request_update_ (struct GSF_PendingRequest *pr,
449 const GNUNET_HashCode *replies_seen, 441 const GNUNET_HashCode * replies_seen,
450 unsigned int replies_seen_count) 442 unsigned int replies_seen_count)
451{ 443{
452 unsigned int i; 444 unsigned int i;
453 GNUNET_HashCode mhash; 445 GNUNET_HashCode mhash;
454 446
455 if (replies_seen_count + pr->replies_seen_count < pr->replies_seen_count) 447 if (replies_seen_count + pr->replies_seen_count < pr->replies_seen_count)
456 return; /* integer overflow */ 448 return; /* integer overflow */
457 if (0 != (pr->public_data.options & GSF_PRO_BLOOMFILTER_FULL_REFRESH)) 449 if (0 != (pr->public_data.options & GSF_PRO_BLOOMFILTER_FULL_REFRESH))
450 {
451 /* we're responsible for the BF, full refresh */
452 if (replies_seen_count + pr->replies_seen_count > pr->replies_seen_size)
453 GNUNET_array_grow (pr->replies_seen,
454 pr->replies_seen_size,
455 replies_seen_count + pr->replies_seen_count);
456 memcpy (&pr->replies_seen[pr->replies_seen_count],
457 replies_seen, sizeof (GNUNET_HashCode) * replies_seen_count);
458 pr->replies_seen_count += replies_seen_count;
459 if (GNUNET_NO == refresh_bloomfilter (pr))
458 { 460 {
459 /* we're responsible for the BF, full refresh */ 461 /* bf not recalculated, simply extend it with new bits */
460 if (replies_seen_count + pr->replies_seen_count > pr->replies_seen_size) 462 for (i = 0; i < replies_seen_count; i++)
461 GNUNET_array_grow (pr->replies_seen, 463 {
462 pr->replies_seen_size, 464 GNUNET_BLOCK_mingle_hash (&replies_seen[i], pr->mingle, &mhash);
463 replies_seen_count + pr->replies_seen_count); 465 GNUNET_CONTAINER_bloomfilter_add (pr->bf, &mhash);
464 memcpy (&pr->replies_seen[pr->replies_seen_count], 466 }
465 replies_seen,
466 sizeof (GNUNET_HashCode) * replies_seen_count);
467 pr->replies_seen_count += replies_seen_count;
468 if (GNUNET_NO == refresh_bloomfilter (pr))
469 {
470 /* bf not recalculated, simply extend it with new bits */
471 for (i=0;i<replies_seen_count;i++)
472 {
473 GNUNET_BLOCK_mingle_hash (&replies_seen[i],
474 pr->mingle,
475 &mhash);
476 GNUNET_CONTAINER_bloomfilter_add (pr->bf, &mhash);
477 }
478 }
479 } 467 }
468 }
480 else 469 else
470 {
471 if (NULL == pr->bf)
472 {
473 /* we're not the initiator, but the initiator did not give us
474 * any bloom-filter, so we need to create one on-the-fly */
475 pr->mingle = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
476 UINT32_MAX);
477 pr->bf = GNUNET_CONTAINER_bloomfilter_init (NULL,
478 compute_bloomfilter_size
479 (replies_seen_count),
480 BLOOMFILTER_K);
481 }
482 for (i = 0; i < pr->replies_seen_count; i++)
481 { 483 {
482 if (NULL == pr->bf) 484 GNUNET_BLOCK_mingle_hash (&replies_seen[i], pr->mingle, &mhash);
483 { 485 GNUNET_CONTAINER_bloomfilter_add (pr->bf, &mhash);
484 /* we're not the initiator, but the initiator did not give us
485 any bloom-filter, so we need to create one on-the-fly */
486 pr->mingle = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
487 UINT32_MAX);
488 pr->bf = GNUNET_CONTAINER_bloomfilter_init (NULL,
489 compute_bloomfilter_size (replies_seen_count),
490 BLOOMFILTER_K);
491 }
492 for (i=0;i<pr->replies_seen_count;i++)
493 {
494 GNUNET_BLOCK_mingle_hash (&replies_seen[i],
495 pr->mingle,
496 &mhash);
497 GNUNET_CONTAINER_bloomfilter_add (pr->bf, &mhash);
498 }
499 } 486 }
487 }
500} 488}
501 489
502 490
@@ -511,8 +499,7 @@ GSF_pending_request_update_ (struct GSF_PendingRequest *pr,
511 */ 499 */
512size_t 500size_t
513GSF_pending_request_get_message_ (struct GSF_PendingRequest *pr, 501GSF_pending_request_get_message_ (struct GSF_PendingRequest *pr,
514 size_t buf_size, 502 size_t buf_size, void *buf)
515 void *buf)
516{ 503{
517 char lbuf[GNUNET_SERVER_MAX_MESSAGE_SIZE]; 504 char lbuf[GNUNET_SERVER_MAX_MESSAGE_SIZE];
518 struct GetMessage *gm; 505 struct GetMessage *gm;
@@ -529,45 +516,44 @@ GSF_pending_request_get_message_ (struct GSF_PendingRequest *pr,
529#if DEBUG_FS 516#if DEBUG_FS
530 if (buf_size > 0) 517 if (buf_size > 0)
531 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 518 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
532 "Building request message for `%s' of type %d\n", 519 "Building request message for `%s' of type %d\n",
533 GNUNET_h2s (&pr->public_data.query), 520 GNUNET_h2s (&pr->public_data.query), pr->public_data.type);
534 pr->public_data.type); 521#endif
535#endif
536 k = 0; 522 k = 0;
537 bm = 0; 523 bm = 0;
538 do_route = (0 == (pr->public_data.options & GSF_PRO_FORWARD_ONLY)); 524 do_route = (0 == (pr->public_data.options & GSF_PRO_FORWARD_ONLY));
539 if ( (! do_route) && (pr->sender_pid == 0)) 525 if ((!do_route) && (pr->sender_pid == 0))
540 { 526 {
541 GNUNET_break (0); 527 GNUNET_break (0);
542 do_route = GNUNET_YES; 528 do_route = GNUNET_YES;
543 } 529 }
544 if (! do_route) 530 if (!do_route)
545 { 531 {
546 bm |= GET_MESSAGE_BIT_RETURN_TO; 532 bm |= GET_MESSAGE_BIT_RETURN_TO;
547 k++; 533 k++;
548 } 534 }
549 if (GNUNET_BLOCK_TYPE_FS_SBLOCK == pr->public_data.type) 535 if (GNUNET_BLOCK_TYPE_FS_SBLOCK == pr->public_data.type)
550 { 536 {
551 bm |= GET_MESSAGE_BIT_SKS_NAMESPACE; 537 bm |= GET_MESSAGE_BIT_SKS_NAMESPACE;
552 k++; 538 k++;
553 } 539 }
554 if (GNUNET_YES == pr->public_data.has_target) 540 if (GNUNET_YES == pr->public_data.has_target)
555 { 541 {
556 bm |= GET_MESSAGE_BIT_TRANSMIT_TO; 542 bm |= GET_MESSAGE_BIT_TRANSMIT_TO;
557 k++; 543 k++;
558 } 544 }
559 bf_size = GNUNET_CONTAINER_bloomfilter_get_size (pr->bf); 545 bf_size = GNUNET_CONTAINER_bloomfilter_get_size (pr->bf);
560 msize = sizeof (struct GetMessage) + bf_size + k * sizeof(GNUNET_HashCode); 546 msize = sizeof (struct GetMessage) + bf_size + k * sizeof (GNUNET_HashCode);
561 GNUNET_assert (msize < GNUNET_SERVER_MAX_MESSAGE_SIZE); 547 GNUNET_assert (msize < GNUNET_SERVER_MAX_MESSAGE_SIZE);
562 if (buf_size < msize) 548 if (buf_size < msize)
563 return msize; 549 return msize;
564 gm = (struct GetMessage*) lbuf; 550 gm = (struct GetMessage *) lbuf;
565 gm->header.type = htons (GNUNET_MESSAGE_TYPE_FS_GET); 551 gm->header.type = htons (GNUNET_MESSAGE_TYPE_FS_GET);
566 gm->header.size = htons (msize); 552 gm->header.size = htons (msize);
567 gm->type = htonl (pr->public_data.type); 553 gm->type = htonl (pr->public_data.type);
568 if (do_route) 554 if (do_route)
569 prio = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 555 prio = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
570 pr->public_data.priority + 1); 556 pr->public_data.priority + 1);
571 else 557 else
572 prio = 0; 558 prio = 0;
573 pr->public_data.priority -= prio; 559 pr->public_data.priority -= prio;
@@ -575,25 +561,23 @@ GSF_pending_request_get_message_ (struct GSF_PendingRequest *pr,
575 now = GNUNET_TIME_absolute_get (); 561 now = GNUNET_TIME_absolute_get ();
576 ttl = (int64_t) (pr->public_data.ttl.abs_value - now.abs_value); 562 ttl = (int64_t) (pr->public_data.ttl.abs_value - now.abs_value);
577 gm->ttl = htonl (ttl / 1000); 563 gm->ttl = htonl (ttl / 1000);
578 gm->filter_mutator = htonl(pr->mingle); 564 gm->filter_mutator = htonl (pr->mingle);
579 gm->hash_bitmap = htonl (bm); 565 gm->hash_bitmap = htonl (bm);
580 gm->query = pr->public_data.query; 566 gm->query = pr->public_data.query;
581 ext = (GNUNET_HashCode*) &gm[1]; 567 ext = (GNUNET_HashCode *) & gm[1];
582 k = 0; 568 k = 0;
583 if (! do_route) 569 if (!do_route)
584 GNUNET_PEER_resolve (pr->sender_pid, 570 GNUNET_PEER_resolve (pr->sender_pid,
585 (struct GNUNET_PeerIdentity*) &ext[k++]); 571 (struct GNUNET_PeerIdentity *) &ext[k++]);
586 if (GNUNET_BLOCK_TYPE_FS_SBLOCK == pr->public_data.type) 572 if (GNUNET_BLOCK_TYPE_FS_SBLOCK == pr->public_data.type)
587 memcpy (&ext[k++], 573 memcpy (&ext[k++], &pr->public_data.namespace, sizeof (GNUNET_HashCode));
588 &pr->public_data.namespace,
589 sizeof (GNUNET_HashCode));
590 if (GNUNET_YES == pr->public_data.has_target) 574 if (GNUNET_YES == pr->public_data.has_target)
591 ext[k++] = pr->public_data.target.hashPubKey; 575 ext[k++] = pr->public_data.target.hashPubKey;
592 if (pr->bf != NULL) 576 if (pr->bf != NULL)
593 GNUNET_assert (GNUNET_SYSERR != 577 GNUNET_assert (GNUNET_SYSERR !=
594 GNUNET_CONTAINER_bloomfilter_get_raw_data (pr->bf, 578 GNUNET_CONTAINER_bloomfilter_get_raw_data (pr->bf,
595 (char*) &ext[k], 579 (char *) &ext[k],
596 bf_size)); 580 bf_size));
597 memcpy (buf, gm, msize); 581 memcpy (buf, gm, msize);
598 return msize; 582 return msize;
599} 583}
@@ -607,63 +591,57 @@ GSF_pending_request_get_message_ (struct GSF_PendingRequest *pr,
607 * @param value value in the hash map (pending request) 591 * @param value value in the hash map (pending request)
608 * @return GNUNET_YES (we should continue to iterate) 592 * @return GNUNET_YES (we should continue to iterate)
609 */ 593 */
610static int 594static int
611clean_request (void *cls, 595clean_request (void *cls, const GNUNET_HashCode * key, void *value)
612 const GNUNET_HashCode * key,
613 void *value)
614{ 596{
615 struct GSF_PendingRequest *pr = value; 597 struct GSF_PendingRequest *pr = value;
616 GSF_LocalLookupContinuation cont; 598 GSF_LocalLookupContinuation cont;
617 599
618#if DEBUG_FS 600#if DEBUG_FS
619 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 601 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
620 "Cleaning up pending request for `%s'.\n", 602 "Cleaning up pending request for `%s'.\n", GNUNET_h2s (key));
621 GNUNET_h2s (key)); 603#endif
622#endif
623 if (NULL != (cont = pr->llc_cont)) 604 if (NULL != (cont = pr->llc_cont))
624 { 605 {
625 pr->llc_cont = NULL; 606 pr->llc_cont = NULL;
626 cont (pr->llc_cont_cls, 607 cont (pr->llc_cont_cls, pr, pr->local_result);
627 pr, 608 }
628 pr->local_result);
629 }
630 GSF_plan_notify_request_done_ (pr); 609 GSF_plan_notify_request_done_ (pr);
631 GNUNET_free_non_null (pr->replies_seen); 610 GNUNET_free_non_null (pr->replies_seen);
632 if (NULL != pr->bf) 611 if (NULL != pr->bf)
633 { 612 {
634 GNUNET_CONTAINER_bloomfilter_free (pr->bf); 613 GNUNET_CONTAINER_bloomfilter_free (pr->bf);
635 pr->bf = NULL; 614 pr->bf = NULL;
636 } 615 }
637 GNUNET_PEER_change_rc (pr->sender_pid, -1); 616 GNUNET_PEER_change_rc (pr->sender_pid, -1);
638 pr->sender_pid = 0; 617 pr->sender_pid = 0;
639 if (NULL != pr->hnode) 618 if (NULL != pr->hnode)
640 { 619 {
641 GNUNET_CONTAINER_heap_remove_node (pr->hnode); 620 GNUNET_CONTAINER_heap_remove_node (pr->hnode);
642 pr->hnode = NULL; 621 pr->hnode = NULL;
643 } 622 }
644 if (NULL != pr->qe) 623 if (NULL != pr->qe)
645 { 624 {
646 GNUNET_DATASTORE_cancel (pr->qe); 625 GNUNET_DATASTORE_cancel (pr->qe);
647 pr->qe = NULL; 626 pr->qe = NULL;
648 } 627 }
649 if (NULL != pr->gh) 628 if (NULL != pr->gh)
650 { 629 {
651 GNUNET_DHT_get_stop (pr->gh); 630 GNUNET_DHT_get_stop (pr->gh);
652 pr->gh = NULL; 631 pr->gh = NULL;
653 } 632 }
654 if (GNUNET_SCHEDULER_NO_TASK != pr->warn_task) 633 if (GNUNET_SCHEDULER_NO_TASK != pr->warn_task)
655 { 634 {
656 GNUNET_SCHEDULER_cancel (pr->warn_task); 635 GNUNET_SCHEDULER_cancel (pr->warn_task);
657 pr->warn_task = GNUNET_SCHEDULER_NO_TASK; 636 pr->warn_task = GNUNET_SCHEDULER_NO_TASK;
658 } 637 }
659 GNUNET_assert (GNUNET_OK == 638 GNUNET_assert (GNUNET_OK ==
660 GNUNET_CONTAINER_multihashmap_remove (pr_map, 639 GNUNET_CONTAINER_multihashmap_remove (pr_map,
661 &pr->public_data.query, 640 &pr->public_data.query,
662 pr)); 641 pr));
663 GNUNET_STATISTICS_update (GSF_stats, 642 GNUNET_STATISTICS_update (GSF_stats,
664 gettext_noop ("# Pending requests active"), 643 gettext_noop ("# Pending requests active"),
665 -1, 644 -1, GNUNET_NO);
666 GNUNET_NO);
667 GNUNET_free (pr); 645 GNUNET_free (pr);
668 return GNUNET_YES; 646 return GNUNET_YES;
669} 647}
@@ -676,46 +654,43 @@ clean_request (void *cls,
676 * @param full_cleanup fully purge the request 654 * @param full_cleanup fully purge the request
677 */ 655 */
678void 656void
679GSF_pending_request_cancel_ (struct GSF_PendingRequest *pr, 657GSF_pending_request_cancel_ (struct GSF_PendingRequest *pr, int full_cleanup)
680 int full_cleanup)
681{ 658{
682 GSF_LocalLookupContinuation cont; 659 GSF_LocalLookupContinuation cont;
683 660
684 if (NULL == pr_map) 661 if (NULL == pr_map)
685 return; /* already cleaned up! */ 662 return; /* already cleaned up! */
686 if (GNUNET_YES != full_cleanup) 663 if (GNUNET_YES != full_cleanup)
664 {
665 /* make request inactive (we're no longer interested in more results),
666 * but do NOT remove from our data-structures, we still need it there
667 * to prevent the request from looping */
668 pr->rh = NULL;
669 if (NULL != (cont = pr->llc_cont))
670 {
671 pr->llc_cont = NULL;
672 cont (pr->llc_cont_cls, pr, pr->local_result);
673 }
674 GSF_plan_notify_request_done_ (pr);
675 if (NULL != pr->qe)
676 {
677 GNUNET_DATASTORE_cancel (pr->qe);
678 pr->qe = NULL;
679 }
680 if (NULL != pr->gh)
687 { 681 {
688 /* make request inactive (we're no longer interested in more results), 682 GNUNET_DHT_get_stop (pr->gh);
689 but do NOT remove from our data-structures, we still need it there 683 pr->gh = NULL;
690 to prevent the request from looping */ 684 }
691 pr->rh = NULL; 685 if (GNUNET_SCHEDULER_NO_TASK != pr->warn_task)
692 if (NULL != (cont = pr->llc_cont)) 686 {
693 { 687 GNUNET_SCHEDULER_cancel (pr->warn_task);
694 pr->llc_cont = NULL; 688 pr->warn_task = GNUNET_SCHEDULER_NO_TASK;
695 cont (pr->llc_cont_cls,
696 pr,
697 pr->local_result);
698 }
699 GSF_plan_notify_request_done_ (pr);
700 if (NULL != pr->qe)
701 {
702 GNUNET_DATASTORE_cancel (pr->qe);
703 pr->qe = NULL;
704 }
705 if (NULL != pr->gh)
706 {
707 GNUNET_DHT_get_stop (pr->gh);
708 pr->gh = NULL;
709 }
710 if (GNUNET_SCHEDULER_NO_TASK != pr->warn_task)
711 {
712 GNUNET_SCHEDULER_cancel (pr->warn_task);
713 pr->warn_task = GNUNET_SCHEDULER_NO_TASK;
714 }
715 return;
716 } 689 }
690 return;
691 }
717 GNUNET_assert (GNUNET_YES == 692 GNUNET_assert (GNUNET_YES ==
718 clean_request (NULL, &pr->public_data.query, pr)); 693 clean_request (NULL, &pr->public_data.query, pr));
719} 694}
720 695
721 696
@@ -726,12 +701,11 @@ GSF_pending_request_cancel_ (struct GSF_PendingRequest *pr,
726 * @param cls closure for it 701 * @param cls closure for it
727 */ 702 */
728void 703void
729GSF_iterate_pending_requests_ (GSF_PendingRequestIterator it, 704GSF_iterate_pending_requests_ (GSF_PendingRequestIterator it, void *cls)
730 void *cls)
731{ 705{
732 GNUNET_CONTAINER_multihashmap_iterate (pr_map, 706 GNUNET_CONTAINER_multihashmap_iterate (pr_map,
733 (GNUNET_CONTAINER_HashMapIterator) it, 707 (GNUNET_CONTAINER_HashMapIterator) it,
734 cls); 708 cls);
735} 709}
736 710
737 711
@@ -798,15 +772,14 @@ struct ProcessReplyClosure
798 */ 772 */
799static void 773static void
800update_request_performance_data (struct ProcessReplyClosure *prq, 774update_request_performance_data (struct ProcessReplyClosure *prq,
801 struct GSF_PendingRequest *pr) 775 struct GSF_PendingRequest *pr)
802{ 776{
803 if (prq->sender == NULL) 777 if (prq->sender == NULL)
804 return; 778 return;
805 GSF_peer_update_performance_ (prq->sender, 779 GSF_peer_update_performance_ (prq->sender,
806 pr->public_data.start_time, 780 pr->public_data.start_time, prq->priority);
807 prq->priority);
808} 781}
809 782
810 783
811/** 784/**
812 * We have received a reply; handle it! 785 * We have received a reply; handle it!
@@ -817,9 +790,7 @@ update_request_performance_data (struct ProcessReplyClosure *prq,
817 * @return GNUNET_YES (we should continue to iterate) 790 * @return GNUNET_YES (we should continue to iterate)
818 */ 791 */
819static int 792static int
820process_reply (void *cls, 793process_reply (void *cls, const GNUNET_HashCode * key, void *value)
821 const GNUNET_HashCode *key,
822 void *value)
823{ 794{
824 struct ProcessReplyClosure *prq = cls; 795 struct ProcessReplyClosure *prq = cls;
825 struct GSF_PendingRequest *pr = value; 796 struct GSF_PendingRequest *pr = value;
@@ -829,88 +800,81 @@ process_reply (void *cls,
829 return GNUNET_YES; 800 return GNUNET_YES;
830#if DEBUG_FS 801#if DEBUG_FS
831 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 802 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
832 "Matched result (type %u) for query `%s' with pending request\n", 803 "Matched result (type %u) for query `%s' with pending request\n",
833 (unsigned int) prq->type, 804 (unsigned int) prq->type, GNUNET_h2s (key));
834 GNUNET_h2s (key)); 805#endif
835#endif
836 GNUNET_STATISTICS_update (GSF_stats, 806 GNUNET_STATISTICS_update (GSF_stats,
837 gettext_noop ("# replies received and matched"), 807 gettext_noop ("# replies received and matched"),
838 1, 808 1, GNUNET_NO);
839 GNUNET_NO);
840 prq->eval = GNUNET_BLOCK_evaluate (GSF_block_ctx, 809 prq->eval = GNUNET_BLOCK_evaluate (GSF_block_ctx,
841 prq->type, 810 prq->type,
842 key, 811 key,
843 &pr->bf, 812 &pr->bf,
844 pr->mingle, 813 pr->mingle,
845 &pr->public_data.namespace, 814 &pr->public_data.namespace,
846 (prq->type == GNUNET_BLOCK_TYPE_FS_SBLOCK) ? sizeof (GNUNET_HashCode) : 0, 815 (prq->type ==
847 prq->data, 816 GNUNET_BLOCK_TYPE_FS_SBLOCK) ?
848 prq->size); 817 sizeof (GNUNET_HashCode) : 0, prq->data,
818 prq->size);
849 switch (prq->eval) 819 switch (prq->eval)
850 { 820 {
851 case GNUNET_BLOCK_EVALUATION_OK_MORE: 821 case GNUNET_BLOCK_EVALUATION_OK_MORE:
852 update_request_performance_data (prq, pr); 822 update_request_performance_data (prq, pr);
853 break; 823 break;
854 case GNUNET_BLOCK_EVALUATION_OK_LAST: 824 case GNUNET_BLOCK_EVALUATION_OK_LAST:
855 /* short cut: stop processing early, no BF-update, etc. */ 825 /* short cut: stop processing early, no BF-update, etc. */
856 update_request_performance_data (prq, pr); 826 update_request_performance_data (prq, pr);
857 GNUNET_LOAD_update (GSF_rt_entry_lifetime, 827 GNUNET_LOAD_update (GSF_rt_entry_lifetime,
858 GNUNET_TIME_absolute_get_duration (pr->public_data.start_time).rel_value); 828 GNUNET_TIME_absolute_get_duration (pr->
859 /* pass on to other peers / local clients */ 829 public_data.start_time).rel_value);
860 pr->rh (pr->rh_cls, 830 /* pass on to other peers / local clients */
861 prq->eval, 831 pr->rh (pr->rh_cls,
862 pr, 832 prq->eval,
863 prq->anonymity_level, 833 pr,
864 prq->expiration, 834 prq->anonymity_level,
865 prq->type, 835 prq->expiration, prq->type, prq->data, prq->size);
866 prq->data, prq->size); 836 return GNUNET_YES;
867 return GNUNET_YES; 837 case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE:
868 case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE: 838 GNUNET_STATISTICS_update (GSF_stats,
869 GNUNET_STATISTICS_update (GSF_stats, 839 gettext_noop
870 gettext_noop ("# duplicate replies discarded (bloomfilter)"), 840 ("# duplicate replies discarded (bloomfilter)"),
871 1, 841 1, GNUNET_NO);
872 GNUNET_NO);
873#if DEBUG_FS && 0 842#if DEBUG_FS && 0
874 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 843 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
875 "Duplicate response `%s', discarding.\n", 844 "Duplicate response `%s', discarding.\n", GNUNET_h2s (&mhash));
876 GNUNET_h2s (&mhash));
877#endif 845#endif
878 return GNUNET_YES; /* duplicate */ 846 return GNUNET_YES; /* duplicate */
879 case GNUNET_BLOCK_EVALUATION_RESULT_INVALID: 847 case GNUNET_BLOCK_EVALUATION_RESULT_INVALID:
880 return GNUNET_YES; /* wrong namespace */ 848 return GNUNET_YES; /* wrong namespace */
881 case GNUNET_BLOCK_EVALUATION_REQUEST_VALID: 849 case GNUNET_BLOCK_EVALUATION_REQUEST_VALID:
882 GNUNET_break (0); 850 GNUNET_break (0);
883 return GNUNET_YES; 851 return GNUNET_YES;
884 case GNUNET_BLOCK_EVALUATION_REQUEST_INVALID: 852 case GNUNET_BLOCK_EVALUATION_REQUEST_INVALID:
885 GNUNET_break (0); 853 GNUNET_break (0);
886 return GNUNET_YES; 854 return GNUNET_YES;
887 case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED: 855 case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED:
888 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 856 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
889 _("Unsupported block type %u\n"), 857 _("Unsupported block type %u\n"), prq->type);
890 prq->type); 858 return GNUNET_NO;
891 return GNUNET_NO; 859 }
892 }
893 /* update bloomfilter */ 860 /* update bloomfilter */
894 GNUNET_CRYPTO_hash (prq->data, 861 GNUNET_CRYPTO_hash (prq->data, prq->size, &chash);
895 prq->size,
896 &chash);
897 GSF_pending_request_update_ (pr, &chash, 1); 862 GSF_pending_request_update_ (pr, &chash, 1);
898 if (NULL == prq->sender) 863 if (NULL == prq->sender)
899 { 864 {
900#if DEBUG_FS 865#if DEBUG_FS
901 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 866 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
902 "Found result for query `%s' in local datastore\n", 867 "Found result for query `%s' in local datastore\n",
903 GNUNET_h2s (key)); 868 GNUNET_h2s (key));
904#endif 869#endif
905 GNUNET_STATISTICS_update (GSF_stats, 870 GNUNET_STATISTICS_update (GSF_stats,
906 gettext_noop ("# results found locally"), 871 gettext_noop ("# results found locally"),
907 1, 872 1, GNUNET_NO);
908 GNUNET_NO); 873 }
909 }
910 else 874 else
911 { 875 {
912 GSF_dht_lookup_ (pr); 876 GSF_dht_lookup_ (pr);
913 } 877 }
914 prq->priority += pr->public_data.original_priority; 878 prq->priority += pr->public_data.original_priority;
915 pr->public_data.priority = 0; 879 pr->public_data.priority = 0;
916 pr->public_data.original_priority = 0; 880 pr->public_data.original_priority = 0;
@@ -918,12 +882,10 @@ process_reply (void *cls,
918 prq->request_found = GNUNET_YES; 882 prq->request_found = GNUNET_YES;
919 /* finally, pass on to other peer / local client */ 883 /* finally, pass on to other peer / local client */
920 pr->rh (pr->rh_cls, 884 pr->rh (pr->rh_cls,
921 prq->eval, 885 prq->eval,
922 pr, 886 pr,
923 prq->anonymity_level, 887 prq->anonymity_level,
924 prq->expiration, 888 prq->expiration, prq->type, prq->data, prq->size);
925 prq->type,
926 prq->data, prq->size);
927 return GNUNET_YES; 889 return GNUNET_YES;
928} 890}
929 891
@@ -960,52 +922,50 @@ struct PutMigrationContext
960 * @param success GNUNET_SYSERR on failure 922 * @param success GNUNET_SYSERR on failure
961 * @param msg NULL on success, otherwise an error message 923 * @param msg NULL on success, otherwise an error message
962 */ 924 */
963static void 925static void
964put_migration_continuation (void *cls, 926put_migration_continuation (void *cls, int success, const char *msg)
965 int success,
966 const char *msg)
967{ 927{
968 struct PutMigrationContext *pmc = cls; 928 struct PutMigrationContext *pmc = cls;
969 struct GNUNET_TIME_Relative delay; 929 struct GNUNET_TIME_Relative delay;
970 struct GNUNET_TIME_Relative block_time; 930 struct GNUNET_TIME_Relative block_time;
971 struct GSF_ConnectedPeer *cp; 931 struct GSF_ConnectedPeer *cp;
972 struct GSF_PeerPerformanceData *ppd; 932 struct GSF_PeerPerformanceData *ppd;
973 933
974 delay = GNUNET_TIME_absolute_get_duration (pmc->start); 934 delay = GNUNET_TIME_absolute_get_duration (pmc->start);
975 cp = GSF_peer_get_ (&pmc->origin); 935 cp = GSF_peer_get_ (&pmc->origin);
976 if ( (GNUNET_OK != success) && 936 if ((GNUNET_OK != success) && (GNUNET_NO == pmc->requested))
977 (GNUNET_NO == pmc->requested) ) 937 {
938 /* block migration for a bit... */
939 if (NULL != cp)
978 { 940 {
979 /* block migration for a bit... */ 941 ppd = GSF_get_peer_performance_data_ (cp);
980 if (NULL != cp) 942 ppd->migration_duplication++;
981 { 943 block_time = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
982 ppd = GSF_get_peer_performance_data_ (cp); 944 5 *
983 ppd->migration_duplication++; 945 ppd->migration_duplication +
984 block_time = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 946 GNUNET_CRYPTO_random_u32
985 5 * ppd->migration_duplication + 947 (GNUNET_CRYPTO_QUALITY_WEAK,
986 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 5)); 948 5));
987 GSF_block_peer_migration_ (cp, block_time); 949 GSF_block_peer_migration_ (cp, block_time);
988 }
989 } 950 }
951 }
990 else 952 else
953 {
954 if (NULL != cp)
991 { 955 {
992 if (NULL != cp) 956 ppd = GSF_get_peer_performance_data_ (cp);
993 { 957 ppd->migration_duplication = 0; /* reset counter */
994 ppd = GSF_get_peer_performance_data_ (cp);
995 ppd->migration_duplication = 0; /* reset counter */
996 }
997 } 958 }
959 }
998 GNUNET_free (pmc); 960 GNUNET_free (pmc);
999 /* FIXME: should we really update the load value on failure? */ 961 /* FIXME: should we really update the load value on failure? */
1000 if (NULL != datastore_put_load) 962 if (NULL != datastore_put_load)
1001 GNUNET_LOAD_update (datastore_put_load, 963 GNUNET_LOAD_update (datastore_put_load, delay.rel_value);
1002 delay.rel_value);
1003 if (GNUNET_OK == success) 964 if (GNUNET_OK == success)
1004 return; 965 return;
1005 GNUNET_STATISTICS_update (GSF_stats, 966 GNUNET_STATISTICS_update (GSF_stats,
1006 gettext_noop ("# Datastore `PUT' failures"), 967 gettext_noop ("# Datastore `PUT' failures"),
1007 1, 968 1, GNUNET_NO);
1008 GNUNET_NO);
1009} 969}
1010 970
1011 971
@@ -1025,14 +985,14 @@ test_put_load_too_high (uint32_t priority)
1025 if (NULL == datastore_put_load) 985 if (NULL == datastore_put_load)
1026 return GNUNET_NO; 986 return GNUNET_NO;
1027 if (GNUNET_LOAD_get_average (datastore_put_load) < 50) 987 if (GNUNET_LOAD_get_average (datastore_put_load) < 50)
1028 return GNUNET_NO; /* very fast */ 988 return GNUNET_NO; /* very fast */
1029 ld = GNUNET_LOAD_get_load (datastore_put_load); 989 ld = GNUNET_LOAD_get_load (datastore_put_load);
1030 if (ld < 2.0 * (1 + priority)) 990 if (ld < 2.0 * (1 + priority))
1031 return GNUNET_NO; 991 return GNUNET_NO;
1032 GNUNET_STATISTICS_update (GSF_stats, 992 GNUNET_STATISTICS_update (GSF_stats,
1033 gettext_noop ("# storage requests dropped due to high load"), 993 gettext_noop
1034 1, 994 ("# storage requests dropped due to high load"), 1,
1035 GNUNET_NO); 995 GNUNET_NO);
1036 return GNUNET_YES; 996 return GNUNET_YES;
1037} 997}
1038 998
@@ -1054,54 +1014,49 @@ test_put_load_too_high (uint32_t priority)
1054 */ 1014 */
1055static void 1015static void
1056handle_dht_reply (void *cls, 1016handle_dht_reply (void *cls,
1057 struct GNUNET_TIME_Absolute exp, 1017 struct GNUNET_TIME_Absolute exp,
1058 const GNUNET_HashCode *key, 1018 const GNUNET_HashCode * key,
1059 const struct GNUNET_PeerIdentity * const *get_path, 1019 const struct GNUNET_PeerIdentity *const *get_path,
1060 const struct GNUNET_PeerIdentity * const *put_path, 1020 const struct GNUNET_PeerIdentity *const *put_path,
1061 enum GNUNET_BLOCK_Type type, 1021 enum GNUNET_BLOCK_Type type, size_t size, const void *data)
1062 size_t size,
1063 const void *data)
1064{ 1022{
1065 struct GSF_PendingRequest *pr = cls; 1023 struct GSF_PendingRequest *pr = cls;
1066 struct ProcessReplyClosure prq; 1024 struct ProcessReplyClosure prq;
1067 struct PutMigrationContext *pmc; 1025 struct PutMigrationContext *pmc;
1068 1026
1069 GNUNET_STATISTICS_update (GSF_stats, 1027 GNUNET_STATISTICS_update (GSF_stats,
1070 gettext_noop ("# Replies received from DHT"), 1028 gettext_noop ("# Replies received from DHT"),
1071 1, 1029 1, GNUNET_NO);
1072 GNUNET_NO);
1073 memset (&prq, 0, sizeof (prq)); 1030 memset (&prq, 0, sizeof (prq));
1074 prq.data = data; 1031 prq.data = data;
1075 prq.expiration = exp; 1032 prq.expiration = exp;
1076 prq.size = size; 1033 prq.size = size;
1077 prq.type = type; 1034 prq.type = type;
1078 process_reply (&prq, key, pr); 1035 process_reply (&prq, key, pr);
1079 if ( (GNUNET_YES == active_to_migration) && 1036 if ((GNUNET_YES == active_to_migration) &&
1080 (GNUNET_NO == test_put_load_too_high (prq.priority)) ) 1037 (GNUNET_NO == test_put_load_too_high (prq.priority)))
1081 { 1038 {
1082#if DEBUG_FS 1039#if DEBUG_FS
1083 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1040 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1084 "Replicating result for query `%s' with priority %u\n", 1041 "Replicating result for query `%s' with priority %u\n",
1085 GNUNET_h2s (key), 1042 GNUNET_h2s (key), prq.priority);
1086 prq.priority);
1087#endif 1043#endif
1088 pmc = GNUNET_malloc (sizeof (struct PutMigrationContext)); 1044 pmc = GNUNET_malloc (sizeof (struct PutMigrationContext));
1089 pmc->start = GNUNET_TIME_absolute_get (); 1045 pmc->start = GNUNET_TIME_absolute_get ();
1090 pmc->requested = GNUNET_YES; 1046 pmc->requested = GNUNET_YES;
1091 if (NULL == 1047 if (NULL ==
1092 GNUNET_DATASTORE_put (GSF_dsh, 1048 GNUNET_DATASTORE_put (GSF_dsh,
1093 0, key, size, data, 1049 0, key, size, data,
1094 type, prq.priority, 1 /* anonymity */, 1050 type, prq.priority, 1 /* anonymity */ ,
1095 0 /* replication */, 1051 0 /* replication */ ,
1096 exp, 1052 exp,
1097 1 + prq.priority, MAX_DATASTORE_QUEUE, 1053 1 + prq.priority, MAX_DATASTORE_QUEUE,
1098 GNUNET_CONSTANTS_SERVICE_TIMEOUT, 1054 GNUNET_CONSTANTS_SERVICE_TIMEOUT,
1099 &put_migration_continuation, 1055 &put_migration_continuation, pmc))
1100 pmc)) 1056 {
1101 { 1057 put_migration_continuation (pmc, GNUNET_NO, NULL);
1102 put_migration_continuation (pmc, GNUNET_NO, NULL);
1103 }
1104 } 1058 }
1059 }
1105} 1060}
1106 1061
1107 1062
@@ -1121,38 +1076,34 @@ GSF_dht_lookup_ (struct GSF_PendingRequest *pr)
1121 if (0 != pr->public_data.anonymity_level) 1076 if (0 != pr->public_data.anonymity_level)
1122 return; 1077 return;
1123 if (NULL != pr->gh) 1078 if (NULL != pr->gh)
1124 { 1079 {
1125 GNUNET_DHT_get_stop (pr->gh); 1080 GNUNET_DHT_get_stop (pr->gh);
1126 pr->gh = NULL; 1081 pr->gh = NULL;
1127 } 1082 }
1128 xquery = NULL; 1083 xquery = NULL;
1129 xquery_size = 0; 1084 xquery_size = 0;
1130 if (GNUNET_BLOCK_TYPE_FS_SBLOCK == pr->public_data.type) 1085 if (GNUNET_BLOCK_TYPE_FS_SBLOCK == pr->public_data.type)
1131 { 1086 {
1132 xquery = buf; 1087 xquery = buf;
1133 memcpy (buf, &pr->public_data.namespace, sizeof (GNUNET_HashCode)); 1088 memcpy (buf, &pr->public_data.namespace, sizeof (GNUNET_HashCode));
1134 xquery_size = sizeof (GNUNET_HashCode); 1089 xquery_size = sizeof (GNUNET_HashCode);
1135 } 1090 }
1136 if (0 != (pr->public_data.options & GSF_PRO_FORWARD_ONLY)) 1091 if (0 != (pr->public_data.options & GSF_PRO_FORWARD_ONLY))
1137 { 1092 {
1138 GNUNET_assert (0 != pr->sender_pid); 1093 GNUNET_assert (0 != pr->sender_pid);
1139 GNUNET_PEER_resolve (pr->sender_pid, 1094 GNUNET_PEER_resolve (pr->sender_pid, &pi);
1140 &pi); 1095 memcpy (&buf[xquery_size], &pi, sizeof (struct GNUNET_PeerIdentity));
1141 memcpy (&buf[xquery_size], &pi, sizeof (struct GNUNET_PeerIdentity)); 1096 xquery_size += sizeof (struct GNUNET_PeerIdentity);
1142 xquery_size += sizeof (struct GNUNET_PeerIdentity); 1097 }
1143 }
1144 pr->gh = GNUNET_DHT_get_start (GSF_dht, 1098 pr->gh = GNUNET_DHT_get_start (GSF_dht,
1145 GNUNET_TIME_UNIT_FOREVER_REL, 1099 GNUNET_TIME_UNIT_FOREVER_REL,
1146 pr->public_data.type, 1100 pr->public_data.type,
1147 &pr->public_data.query, 1101 &pr->public_data.query,
1148 DEFAULT_GET_REPLICATION, 1102 DEFAULT_GET_REPLICATION,
1149 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, 1103 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
1150 pr->bf, 1104 pr->bf,
1151 pr->mingle, 1105 pr->mingle,
1152 xquery, 1106 xquery, xquery_size, &handle_dht_reply, pr);
1153 xquery_size,
1154 &handle_dht_reply,
1155 pr);
1156} 1107}
1157 1108
1158 1109
@@ -1163,17 +1114,17 @@ GSF_dht_lookup_ (struct GSF_PendingRequest *pr)
1163 * @param tc task context 1114 * @param tc task context
1164 */ 1115 */
1165static void 1116static void
1166warn_delay_task (void *cls, 1117warn_delay_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1167 const struct GNUNET_SCHEDULER_TaskContext *tc)
1168{ 1118{
1169 struct GSF_PendingRequest *pr = cls; 1119 struct GSF_PendingRequest *pr = cls;
1170 1120
1171 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1121 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1172 _("Datastore lookup already took %llu ms!\n"), 1122 _("Datastore lookup already took %llu ms!\n"),
1173 (unsigned long long) GNUNET_TIME_absolute_get_duration (pr->qe_start).rel_value); 1123 (unsigned long long)
1174 pr->warn_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, 1124 GNUNET_TIME_absolute_get_duration (pr->qe_start).rel_value);
1175 &warn_delay_task, 1125 pr->warn_task =
1176 pr); 1126 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, &warn_delay_task,
1127 pr);
1177} 1128}
1178 1129
1179 1130
@@ -1184,17 +1135,17 @@ warn_delay_task (void *cls,
1184 * @param tc task context 1135 * @param tc task context
1185 */ 1136 */
1186static void 1137static void
1187odc_warn_delay_task (void *cls, 1138odc_warn_delay_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1188 const struct GNUNET_SCHEDULER_TaskContext *tc)
1189{ 1139{
1190 struct GSF_PendingRequest *pr = cls; 1140 struct GSF_PendingRequest *pr = cls;
1191 1141
1192 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1142 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1193 _("On-demand lookup already took %llu ms!\n"), 1143 _("On-demand lookup already took %llu ms!\n"),
1194 (unsigned long long) GNUNET_TIME_absolute_get_duration (pr->qe_start).rel_value); 1144 (unsigned long long)
1195 pr->warn_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, 1145 GNUNET_TIME_absolute_get_duration (pr->qe_start).rel_value);
1196 &odc_warn_delay_task, 1146 pr->warn_task =
1197 pr); 1147 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
1148 &odc_warn_delay_task, pr);
1198} 1149}
1199 1150
1200 1151
@@ -1217,14 +1168,13 @@ odc_warn_delay_task (void *cls,
1217 */ 1168 */
1218static void 1169static void
1219process_local_reply (void *cls, 1170process_local_reply (void *cls,
1220 const GNUNET_HashCode *key, 1171 const GNUNET_HashCode * key,
1221 size_t size, 1172 size_t size,
1222 const void *data, 1173 const void *data,
1223 enum GNUNET_BLOCK_Type type, 1174 enum GNUNET_BLOCK_Type type,
1224 uint32_t priority, 1175 uint32_t priority,
1225 uint32_t anonymity, 1176 uint32_t anonymity,
1226 struct GNUNET_TIME_Absolute expiration, 1177 struct GNUNET_TIME_Absolute expiration, uint64_t uid)
1227 uint64_t uid)
1228{ 1178{
1229 struct GSF_PendingRequest *pr = cls; 1179 struct GSF_PendingRequest *pr = cls;
1230 GSF_LocalLookupContinuation cont; 1180 GSF_LocalLookupContinuation cont;
@@ -1235,236 +1185,228 @@ process_local_reply (void *cls,
1235 GNUNET_SCHEDULER_cancel (pr->warn_task); 1185 GNUNET_SCHEDULER_cancel (pr->warn_task);
1236 pr->warn_task = GNUNET_SCHEDULER_NO_TASK; 1186 pr->warn_task = GNUNET_SCHEDULER_NO_TASK;
1237 if (NULL != pr->qe) 1187 if (NULL != pr->qe)
1188 {
1189 pr->qe = NULL;
1190 if (NULL == key)
1238 { 1191 {
1239 pr->qe = NULL; 1192 GNUNET_STATISTICS_update (GSF_stats,
1240 if (NULL == key) 1193 gettext_noop
1241 { 1194 ("# Datastore lookups concluded (no results)"),
1242 GNUNET_STATISTICS_update (GSF_stats, 1195 1, GNUNET_NO);
1243 gettext_noop ("# Datastore lookups concluded (no results)"),
1244 1,
1245 GNUNET_NO);
1246 }
1247 if (GNUNET_NO == pr->have_first_uid)
1248 {
1249 pr->first_uid = uid;
1250 pr->have_first_uid = 1;
1251 }
1252 else
1253 {
1254 if ( (uid == pr->first_uid) && (key != NULL) )
1255 {
1256 GNUNET_STATISTICS_update (GSF_stats,
1257 gettext_noop ("# Datastore lookups concluded (seen all)"),
1258 1,
1259 GNUNET_NO);
1260 key = NULL; /* all replies seen! */
1261 }
1262 pr->have_first_uid++;
1263 if ( (pr->have_first_uid > MAX_RESULTS) && (key != NULL) )
1264 {
1265 GNUNET_STATISTICS_update (GSF_stats,
1266 gettext_noop ("# Datastore lookups aborted (more than MAX_RESULTS)"),
1267 1,
1268 GNUNET_NO);
1269 key = NULL; /* all replies seen! */
1270 }
1271 }
1272 } 1196 }
1273 if (NULL == key) 1197 if (GNUNET_NO == pr->have_first_uid)
1198 {
1199 pr->first_uid = uid;
1200 pr->have_first_uid = 1;
1201 }
1202 else
1274 { 1203 {
1204 if ((uid == pr->first_uid) && (key != NULL))
1205 {
1206 GNUNET_STATISTICS_update (GSF_stats,
1207 gettext_noop
1208 ("# Datastore lookups concluded (seen all)"),
1209 1, GNUNET_NO);
1210 key = NULL; /* all replies seen! */
1211 }
1212 pr->have_first_uid++;
1213 if ((pr->have_first_uid > MAX_RESULTS) && (key != NULL))
1214 {
1215 GNUNET_STATISTICS_update (GSF_stats,
1216 gettext_noop
1217 ("# Datastore lookups aborted (more than MAX_RESULTS)"),
1218 1, GNUNET_NO);
1219 key = NULL; /* all replies seen! */
1220 }
1221 }
1222 }
1223 if (NULL == key)
1224 {
1275#if DEBUG_FS > 1 1225#if DEBUG_FS > 1
1276 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1226 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1277 "No further local responses available.\n"); 1227 "No further local responses available.\n");
1278#endif 1228#endif
1279 if ( (pr->public_data.type == GNUNET_BLOCK_TYPE_FS_DBLOCK) || 1229 if ((pr->public_data.type == GNUNET_BLOCK_TYPE_FS_DBLOCK) ||
1280 (pr->public_data.type == GNUNET_BLOCK_TYPE_FS_IBLOCK) ) 1230 (pr->public_data.type == GNUNET_BLOCK_TYPE_FS_IBLOCK))
1281 GNUNET_STATISTICS_update (GSF_stats, 1231 GNUNET_STATISTICS_update (GSF_stats,
1282 gettext_noop ("# requested DBLOCK or IBLOCK not found"), 1232 gettext_noop
1283 1, 1233 ("# requested DBLOCK or IBLOCK not found"), 1,
1284 GNUNET_NO); 1234 GNUNET_NO);
1285 goto check_error_and_continue; 1235 goto check_error_and_continue;
1286 } 1236 }
1287#if DEBUG_FS 1237#if DEBUG_FS
1288 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1238 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1289 "Received reply for `%s' of type %d with UID %llu from datastore.\n", 1239 "Received reply for `%s' of type %d with UID %llu from datastore.\n",
1290 GNUNET_h2s (key), 1240 GNUNET_h2s (key), type, (unsigned long long) uid);
1291 type,
1292 (unsigned long long) uid);
1293#endif 1241#endif
1294 if (type == GNUNET_BLOCK_TYPE_FS_ONDEMAND) 1242 if (type == GNUNET_BLOCK_TYPE_FS_ONDEMAND)
1295 { 1243 {
1296#if DEBUG_FS > 1 1244#if DEBUG_FS > 1
1297 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1245 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1298 "Found ONDEMAND block, performing on-demand encoding\n"); 1246 "Found ONDEMAND block, performing on-demand encoding\n");
1299#endif 1247#endif
1248 GNUNET_STATISTICS_update (GSF_stats,
1249 gettext_noop
1250 ("# on-demand blocks matched requests"), 1,
1251 GNUNET_NO);
1252 pr->qe_start = GNUNET_TIME_absolute_get ();
1253 pr->warn_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
1254 &odc_warn_delay_task, pr);
1255 if (GNUNET_OK ==
1256 GNUNET_FS_handle_on_demand_block (key, size, data, type, priority,
1257 anonymity, expiration, uid,
1258 &process_local_reply, pr))
1259 {
1300 GNUNET_STATISTICS_update (GSF_stats, 1260 GNUNET_STATISTICS_update (GSF_stats,
1301 gettext_noop ("# on-demand blocks matched requests"), 1261 gettext_noop
1302 1, 1262 ("# on-demand lookups performed successfully"),
1303 GNUNET_NO); 1263 1, GNUNET_NO);
1304 pr->qe_start = GNUNET_TIME_absolute_get (); 1264 return; /* we're done */
1305 pr->warn_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, 1265 }
1306 &odc_warn_delay_task, 1266 GNUNET_STATISTICS_update (GSF_stats,
1307 pr); 1267 gettext_noop ("# on-demand lookups failed"),
1308 if (GNUNET_OK == 1268 1, GNUNET_NO);
1309 GNUNET_FS_handle_on_demand_block (key, size, data, type, priority, 1269 GNUNET_SCHEDULER_cancel (pr->warn_task);
1310 anonymity, expiration, uid, 1270 pr->warn_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
1311 &process_local_reply, 1271 &warn_delay_task, pr);
1312 pr)) 1272 pr->qe = GNUNET_DATASTORE_get_key (GSF_dsh,
1313 { 1273 pr->local_result_offset - 1,
1314 GNUNET_STATISTICS_update (GSF_stats, 1274 &pr->public_data.query,
1315 gettext_noop ("# on-demand lookups performed successfully"), 1275 pr->public_data.type ==
1316 1, 1276 GNUNET_BLOCK_TYPE_FS_DBLOCK ?
1317 GNUNET_NO); 1277 GNUNET_BLOCK_TYPE_ANY : pr->
1318 return; /* we're done */ 1278 public_data.type,
1319 } 1279 (0 !=
1280 (GSF_PRO_PRIORITY_UNLIMITED &
1281 pr->public_data.
1282 options)) ? UINT_MAX : 1
1283 /* queue priority */ ,
1284 (0 !=
1285 (GSF_PRO_PRIORITY_UNLIMITED &
1286 pr->public_data.options)) ? UINT_MAX :
1287 1
1288 /* max queue size */ ,
1289 GNUNET_TIME_UNIT_FOREVER_REL,
1290 &process_local_reply, pr);
1291 if (NULL != pr->qe)
1292 {
1320 GNUNET_STATISTICS_update (GSF_stats, 1293 GNUNET_STATISTICS_update (GSF_stats,
1321 gettext_noop ("# on-demand lookups failed"), 1294 gettext_noop
1322 1, 1295 ("# Datastore lookups concluded (error queueing)"),
1323 GNUNET_NO); 1296 1, GNUNET_NO);
1324 GNUNET_SCHEDULER_cancel (pr->warn_task); 1297 return; /* we're done */
1325 pr->warn_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
1326 &warn_delay_task,
1327 pr);
1328 pr->qe = GNUNET_DATASTORE_get_key (GSF_dsh,
1329 pr->local_result_offset - 1,
1330 &pr->public_data.query,
1331 pr->public_data.type == GNUNET_BLOCK_TYPE_FS_DBLOCK
1332 ? GNUNET_BLOCK_TYPE_ANY
1333 : pr->public_data.type,
1334 (0 != (GSF_PRO_PRIORITY_UNLIMITED & pr->public_data.options))
1335 ? UINT_MAX
1336 : 1 /* queue priority */,
1337 (0 != (GSF_PRO_PRIORITY_UNLIMITED & pr->public_data.options))
1338 ? UINT_MAX
1339 : 1 /* max queue size */,
1340 GNUNET_TIME_UNIT_FOREVER_REL,
1341 &process_local_reply,
1342 pr);
1343 if (NULL != pr->qe)
1344 {
1345 GNUNET_STATISTICS_update (GSF_stats,
1346 gettext_noop ("# Datastore lookups concluded (error queueing)"),
1347 1,
1348 GNUNET_NO);
1349 return; /* we're done */
1350 }
1351 goto check_error_and_continue;
1352 } 1298 }
1299 goto check_error_and_continue;
1300 }
1353 old_rf = pr->public_data.results_found; 1301 old_rf = pr->public_data.results_found;
1354 memset (&prq, 0, sizeof (prq)); 1302 memset (&prq, 0, sizeof (prq));
1355 prq.data = data; 1303 prq.data = data;
1356 prq.expiration = expiration; 1304 prq.expiration = expiration;
1357 prq.size = size; 1305 prq.size = size;
1358 if (GNUNET_OK != 1306 if (GNUNET_OK !=
1359 GNUNET_BLOCK_get_key (GSF_block_ctx, 1307 GNUNET_BLOCK_get_key (GSF_block_ctx, type, data, size, &query))
1360 type, 1308 {
1361 data, 1309 GNUNET_break (0);
1362 size, 1310 GNUNET_DATASTORE_remove (GSF_dsh,
1363 &query)) 1311 key,
1312 size, data,
1313 -1, -1, GNUNET_TIME_UNIT_FOREVER_REL, NULL, NULL);
1314 pr->qe_start = GNUNET_TIME_absolute_get ();
1315 pr->warn_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
1316 &warn_delay_task, pr);
1317 pr->qe = GNUNET_DATASTORE_get_key (GSF_dsh,
1318 pr->local_result_offset - 1,
1319 &pr->public_data.query,
1320 pr->public_data.type ==
1321 GNUNET_BLOCK_TYPE_FS_DBLOCK ?
1322 GNUNET_BLOCK_TYPE_ANY : pr->
1323 public_data.type,
1324 (0 !=
1325 (GSF_PRO_PRIORITY_UNLIMITED &
1326 pr->public_data.
1327 options)) ? UINT_MAX : 1
1328 /* queue priority */ ,
1329 (0 !=
1330 (GSF_PRO_PRIORITY_UNLIMITED &
1331 pr->public_data.options)) ? UINT_MAX :
1332 1
1333 /* max queue size */ ,
1334 GNUNET_TIME_UNIT_FOREVER_REL,
1335 &process_local_reply, pr);
1336 if (pr->qe == NULL)
1364 { 1337 {
1365 GNUNET_break (0); 1338 GNUNET_STATISTICS_update (GSF_stats,
1366 GNUNET_DATASTORE_remove (GSF_dsh, 1339 gettext_noop
1367 key, 1340 ("# Datastore lookups concluded (error queueing)"),
1368 size, data, 1341 1, GNUNET_NO);
1369 -1, -1, 1342 goto check_error_and_continue;
1370 GNUNET_TIME_UNIT_FOREVER_REL,
1371 NULL, NULL);
1372 pr->qe_start = GNUNET_TIME_absolute_get ();
1373 pr->warn_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
1374 &warn_delay_task,
1375 pr);
1376 pr->qe = GNUNET_DATASTORE_get_key (GSF_dsh,
1377 pr->local_result_offset - 1,
1378 &pr->public_data.query,
1379 pr->public_data.type == GNUNET_BLOCK_TYPE_FS_DBLOCK
1380 ? GNUNET_BLOCK_TYPE_ANY
1381 : pr->public_data.type,
1382 (0 != (GSF_PRO_PRIORITY_UNLIMITED & pr->public_data.options))
1383 ? UINT_MAX
1384 : 1 /* queue priority */,
1385 (0 != (GSF_PRO_PRIORITY_UNLIMITED & pr->public_data.options))
1386 ? UINT_MAX
1387 : 1 /* max queue size */,
1388 GNUNET_TIME_UNIT_FOREVER_REL,
1389 &process_local_reply,
1390 pr);
1391 if (pr->qe == NULL)
1392 {
1393 GNUNET_STATISTICS_update (GSF_stats,
1394 gettext_noop ("# Datastore lookups concluded (error queueing)"),
1395 1,
1396 GNUNET_NO);
1397 goto check_error_and_continue;
1398 }
1399 return;
1400 } 1343 }
1344 return;
1345 }
1401 prq.type = type; 1346 prq.type = type;
1402 prq.priority = priority; 1347 prq.priority = priority;
1403 prq.request_found = GNUNET_NO; 1348 prq.request_found = GNUNET_NO;
1404 prq.anonymity_level = anonymity; 1349 prq.anonymity_level = anonymity;
1405 if ( (old_rf == 0) && 1350 if ((old_rf == 0) && (pr->public_data.results_found == 0))
1406 (pr->public_data.results_found == 0) )
1407 GSF_update_datastore_delay_ (pr->public_data.start_time); 1351 GSF_update_datastore_delay_ (pr->public_data.start_time);
1408 process_reply (&prq, key, pr); 1352 process_reply (&prq, key, pr);
1409 pr->local_result = prq.eval; 1353 pr->local_result = prq.eval;
1410 if (prq.eval == GNUNET_BLOCK_EVALUATION_OK_LAST) 1354 if (prq.eval == GNUNET_BLOCK_EVALUATION_OK_LAST)
1411 { 1355 {
1412 GNUNET_STATISTICS_update (GSF_stats, 1356 GNUNET_STATISTICS_update (GSF_stats,
1413 gettext_noop ("# Datastore lookups concluded (found ultimate result)"), 1357 gettext_noop
1414 1, 1358 ("# Datastore lookups concluded (found ultimate result)"),
1415 GNUNET_NO); 1359 1, GNUNET_NO);
1416 goto check_error_and_continue; 1360 goto check_error_and_continue;
1417 } 1361 }
1418 if ( (0 == (GSF_PRO_PRIORITY_UNLIMITED & pr->public_data.options)) && 1362 if ((0 == (GSF_PRO_PRIORITY_UNLIMITED & pr->public_data.options)) &&
1419 ( (GNUNET_YES == GSF_test_get_load_too_high_ (0)) || 1363 ((GNUNET_YES == GSF_test_get_load_too_high_ (0)) ||
1420 (pr->public_data.results_found > 5 + 2 * pr->public_data.priority) ) ) 1364 (pr->public_data.results_found > 5 + 2 * pr->public_data.priority)))
1421 { 1365 {
1422#if DEBUG_FS > 2 1366#if DEBUG_FS > 2
1423 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1367 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Load too high, done with request\n");
1424 "Load too high, done with request\n");
1425#endif 1368#endif
1426 GNUNET_STATISTICS_update (GSF_stats, 1369 GNUNET_STATISTICS_update (GSF_stats,
1427 gettext_noop ("# Datastore lookups concluded (load too high)"), 1370 gettext_noop
1428 1, 1371 ("# Datastore lookups concluded (load too high)"),
1429 GNUNET_NO); 1372 1, GNUNET_NO);
1430 goto check_error_and_continue; 1373 goto check_error_and_continue;
1431 } 1374 }
1432 pr->qe_start = GNUNET_TIME_absolute_get (); 1375 pr->qe_start = GNUNET_TIME_absolute_get ();
1433 pr->warn_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, 1376 pr->warn_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
1434 &warn_delay_task, 1377 &warn_delay_task, pr);
1435 pr);
1436 pr->qe = GNUNET_DATASTORE_get_key (GSF_dsh, 1378 pr->qe = GNUNET_DATASTORE_get_key (GSF_dsh,
1437 pr->local_result_offset++, 1379 pr->local_result_offset++,
1438 &pr->public_data.query, 1380 &pr->public_data.query,
1439 pr->public_data.type == GNUNET_BLOCK_TYPE_FS_DBLOCK 1381 pr->public_data.type ==
1440 ? GNUNET_BLOCK_TYPE_ANY 1382 GNUNET_BLOCK_TYPE_FS_DBLOCK ?
1441 : pr->public_data.type, 1383 GNUNET_BLOCK_TYPE_ANY : pr->
1442 (0 != (GSF_PRO_PRIORITY_UNLIMITED & pr->public_data.options)) 1384 public_data.type,
1443 ? UINT_MAX 1385 (0 !=
1444 : 1 /* queue priority */, 1386 (GSF_PRO_PRIORITY_UNLIMITED &
1445 (0 != (GSF_PRO_PRIORITY_UNLIMITED & pr->public_data.options)) 1387 pr->public_data.options)) ? UINT_MAX : 1
1446 ? UINT_MAX 1388 /* queue priority */ ,
1447 : 1 /* max queue size */, 1389 (0 !=
1448 GNUNET_TIME_UNIT_FOREVER_REL, 1390 (GSF_PRO_PRIORITY_UNLIMITED &
1449 &process_local_reply, 1391 pr->public_data.options)) ? UINT_MAX : 1
1450 pr); 1392 /* max queue size */ ,
1393 GNUNET_TIME_UNIT_FOREVER_REL,
1394 &process_local_reply, pr);
1451 /* check if we successfully queued another datastore request; 1395 /* check if we successfully queued another datastore request;
1452 if so, return, otherwise call our continuation (if we have 1396 * if so, return, otherwise call our continuation (if we have
1453 any) */ 1397 * any) */
1454 check_error_and_continue: 1398check_error_and_continue:
1455 if (NULL != pr->qe) 1399 if (NULL != pr->qe)
1456 return; 1400 return;
1457 if (GNUNET_SCHEDULER_NO_TASK != pr->warn_task) 1401 if (GNUNET_SCHEDULER_NO_TASK != pr->warn_task)
1458 { 1402 {
1459 GNUNET_SCHEDULER_cancel (pr->warn_task); 1403 GNUNET_SCHEDULER_cancel (pr->warn_task);
1460 pr->warn_task = GNUNET_SCHEDULER_NO_TASK; 1404 pr->warn_task = GNUNET_SCHEDULER_NO_TASK;
1461 } 1405 }
1462 if (NULL == (cont = pr->llc_cont)) 1406 if (NULL == (cont = pr->llc_cont))
1463 return; /* no continuation */ 1407 return; /* no continuation */
1464 pr->llc_cont = NULL; 1408 pr->llc_cont = NULL;
1465 cont (pr->llc_cont_cls, 1409 cont (pr->llc_cont_cls, pr, pr->local_result);
1466 pr,
1467 pr->local_result);
1468} 1410}
1469 1411
1470 1412
@@ -1477,8 +1419,7 @@ process_local_reply (void *cls,
1477 */ 1419 */
1478void 1420void
1479GSF_local_lookup_ (struct GSF_PendingRequest *pr, 1421GSF_local_lookup_ (struct GSF_PendingRequest *pr,
1480 GSF_LocalLookupContinuation cont, 1422 GSF_LocalLookupContinuation cont, void *cont_cls)
1481 void *cont_cls)
1482{ 1423{
1483 GNUNET_assert (NULL == pr->gh); 1424 GNUNET_assert (NULL == pr->gh);
1484 GNUNET_assert (NULL == pr->llc_cont); 1425 GNUNET_assert (NULL == pr->llc_cont);
@@ -1486,41 +1427,41 @@ GSF_local_lookup_ (struct GSF_PendingRequest *pr,
1486 pr->llc_cont_cls = cont_cls; 1427 pr->llc_cont_cls = cont_cls;
1487 pr->qe_start = GNUNET_TIME_absolute_get (); 1428 pr->qe_start = GNUNET_TIME_absolute_get ();
1488 pr->warn_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, 1429 pr->warn_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
1489 &warn_delay_task, 1430 &warn_delay_task, pr);
1490 pr);
1491 GNUNET_STATISTICS_update (GSF_stats, 1431 GNUNET_STATISTICS_update (GSF_stats,
1492 gettext_noop ("# Datastore lookups initiated"), 1432 gettext_noop ("# Datastore lookups initiated"),
1493 1, 1433 1, GNUNET_NO);
1494 GNUNET_NO);
1495 pr->qe = GNUNET_DATASTORE_get_key (GSF_dsh, 1434 pr->qe = GNUNET_DATASTORE_get_key (GSF_dsh,
1496 pr->local_result_offset++, 1435 pr->local_result_offset++,
1497 &pr->public_data.query, 1436 &pr->public_data.query,
1498 pr->public_data.type == GNUNET_BLOCK_TYPE_FS_DBLOCK 1437 pr->public_data.type ==
1499 ? GNUNET_BLOCK_TYPE_ANY 1438 GNUNET_BLOCK_TYPE_FS_DBLOCK ?
1500 : pr->public_data.type, 1439 GNUNET_BLOCK_TYPE_ANY : pr->
1501 (0 != (GSF_PRO_PRIORITY_UNLIMITED & pr->public_data.options)) 1440 public_data.type,
1502 ? UINT_MAX 1441 (0 !=
1503 : 1 /* queue priority */, 1442 (GSF_PRO_PRIORITY_UNLIMITED &
1504 (0 != (GSF_PRO_PRIORITY_UNLIMITED & pr->public_data.options)) 1443 pr->public_data.options)) ? UINT_MAX : 1
1505 ? UINT_MAX 1444 /* queue priority */ ,
1506 : 1 /* max queue size */, 1445 (0 !=
1507 GNUNET_TIME_UNIT_FOREVER_REL, 1446 (GSF_PRO_PRIORITY_UNLIMITED &
1508 &process_local_reply, 1447 pr->public_data.options)) ? UINT_MAX : 1
1509 pr); 1448 /* max queue size */ ,
1449 GNUNET_TIME_UNIT_FOREVER_REL,
1450 &process_local_reply, pr);
1510 if (NULL != pr->qe) 1451 if (NULL != pr->qe)
1511 { 1452 {
1512 GNUNET_STATISTICS_update (GSF_stats, 1453 GNUNET_STATISTICS_update (GSF_stats,
1513 gettext_noop ("# Datastore lookups concluded (error queueing)"), 1454 gettext_noop
1514 1, 1455 ("# Datastore lookups concluded (error queueing)"),
1515 GNUNET_NO); 1456 1, GNUNET_NO);
1516 1457
1517 return; 1458 return;
1518 } 1459 }
1519 GNUNET_SCHEDULER_cancel (pr->warn_task); 1460 GNUNET_SCHEDULER_cancel (pr->warn_task);
1520 pr->warn_task = GNUNET_SCHEDULER_NO_TASK; 1461 pr->warn_task = GNUNET_SCHEDULER_NO_TASK;
1521 pr->llc_cont = NULL; 1462 pr->llc_cont = NULL;
1522 if (NULL != cont) 1463 if (NULL != cont)
1523 cont (cont_cls, pr, pr->local_result); 1464 cont (cont_cls, pr, pr->local_result);
1524} 1465}
1525 1466
1526 1467
@@ -1540,7 +1481,7 @@ GSF_local_lookup_ (struct GSF_PendingRequest *pr,
1540 */ 1481 */
1541int 1482int
1542GSF_handle_p2p_content_ (struct GSF_ConnectedPeer *cp, 1483GSF_handle_p2p_content_ (struct GSF_ConnectedPeer *cp,
1543 const struct GNUNET_MessageHeader *message) 1484 const struct GNUNET_MessageHeader *message)
1544{ 1485{
1545 const struct PutMessage *put; 1486 const struct PutMessage *put;
1546 uint16_t msize; 1487 uint16_t msize;
@@ -1549,38 +1490,33 @@ GSF_handle_p2p_content_ (struct GSF_ConnectedPeer *cp,
1549 struct GNUNET_TIME_Absolute expiration; 1490 struct GNUNET_TIME_Absolute expiration;
1550 GNUNET_HashCode query; 1491 GNUNET_HashCode query;
1551 struct ProcessReplyClosure prq; 1492 struct ProcessReplyClosure prq;
1552 struct GNUNET_TIME_Relative block_time; 1493 struct GNUNET_TIME_Relative block_time;
1553 double putl; 1494 double putl;
1554 struct PutMigrationContext *pmc; 1495 struct PutMigrationContext *pmc;
1555 1496
1556 msize = ntohs (message->size); 1497 msize = ntohs (message->size);
1557 if (msize < sizeof (struct PutMessage)) 1498 if (msize < sizeof (struct PutMessage))
1558 { 1499 {
1559 GNUNET_break_op(0); 1500 GNUNET_break_op (0);
1560 return GNUNET_SYSERR; 1501 return GNUNET_SYSERR;
1561 } 1502 }
1562 put = (const struct PutMessage*) message; 1503 put = (const struct PutMessage *) message;
1563 dsize = msize - sizeof (struct PutMessage); 1504 dsize = msize - sizeof (struct PutMessage);
1564 type = ntohl (put->type); 1505 type = ntohl (put->type);
1565 expiration = GNUNET_TIME_absolute_ntoh (put->expiration); 1506 expiration = GNUNET_TIME_absolute_ntoh (put->expiration);
1566 if (type == GNUNET_BLOCK_TYPE_FS_ONDEMAND) 1507 if (type == GNUNET_BLOCK_TYPE_FS_ONDEMAND)
1567 return GNUNET_SYSERR; 1508 return GNUNET_SYSERR;
1568 if (GNUNET_OK != 1509 if (GNUNET_OK !=
1569 GNUNET_BLOCK_get_key (GSF_block_ctx, 1510 GNUNET_BLOCK_get_key (GSF_block_ctx, type, &put[1], dsize, &query))
1570 type, 1511 {
1571 &put[1], 1512 GNUNET_break_op (0);
1572 dsize, 1513 return GNUNET_SYSERR;
1573 &query)) 1514 }
1574 {
1575 GNUNET_break_op (0);
1576 return GNUNET_SYSERR;
1577 }
1578 GNUNET_STATISTICS_update (GSF_stats, 1515 GNUNET_STATISTICS_update (GSF_stats,
1579 gettext_noop ("# GAP PUT messages received"), 1516 gettext_noop ("# GAP PUT messages received"),
1580 1, 1517 1, GNUNET_NO);
1581 GNUNET_NO);
1582 /* now, lookup 'query' */ 1518 /* now, lookup 'query' */
1583 prq.data = (const void*) &put[1]; 1519 prq.data = (const void *) &put[1];
1584 if (NULL != cp) 1520 if (NULL != cp)
1585 prq.sender = cp; 1521 prq.sender = cp;
1586 else 1522 else
@@ -1592,66 +1528,66 @@ GSF_handle_p2p_content_ (struct GSF_ConnectedPeer *cp,
1592 prq.anonymity_level = UINT32_MAX; 1528 prq.anonymity_level = UINT32_MAX;
1593 prq.request_found = GNUNET_NO; 1529 prq.request_found = GNUNET_NO;
1594 GNUNET_CONTAINER_multihashmap_get_multiple (pr_map, 1530 GNUNET_CONTAINER_multihashmap_get_multiple (pr_map,
1595 &query, 1531 &query, &process_reply, &prq);
1596 &process_reply,
1597 &prq);
1598 if (NULL != cp) 1532 if (NULL != cp)
1599 { 1533 {
1600 GSF_connected_peer_change_preference_ (cp, CONTENT_BANDWIDTH_VALUE + 1000 * prq.priority); 1534 GSF_connected_peer_change_preference_ (cp,
1601 GSF_get_peer_performance_data_ (cp)->trust += prq.priority; 1535 CONTENT_BANDWIDTH_VALUE +
1602 } 1536 1000 * prq.priority);
1603 if ( (GNUNET_YES == active_to_migration) && 1537 GSF_get_peer_performance_data_ (cp)->trust += prq.priority;
1604 (GNUNET_NO == test_put_load_too_high (prq.priority)) ) 1538 }
1605 { 1539 if ((GNUNET_YES == active_to_migration) &&
1540 (GNUNET_NO == test_put_load_too_high (prq.priority)))
1541 {
1606#if DEBUG_FS 1542#if DEBUG_FS
1607 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1543 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1608 "Replicating result for query `%s' with priority %u\n", 1544 "Replicating result for query `%s' with priority %u\n",
1609 GNUNET_h2s (&query), 1545 GNUNET_h2s (&query), prq.priority);
1610 prq.priority);
1611#endif 1546#endif
1612 pmc = GNUNET_malloc (sizeof (struct PutMigrationContext)); 1547 pmc = GNUNET_malloc (sizeof (struct PutMigrationContext));
1613 pmc->start = GNUNET_TIME_absolute_get (); 1548 pmc->start = GNUNET_TIME_absolute_get ();
1614 pmc->requested = prq.request_found; 1549 pmc->requested = prq.request_found;
1615 GNUNET_assert (0 != GSF_get_peer_performance_data_ (cp)->pid); 1550 GNUNET_assert (0 != GSF_get_peer_performance_data_ (cp)->pid);
1616 GNUNET_PEER_resolve (GSF_get_peer_performance_data_ (cp)->pid, 1551 GNUNET_PEER_resolve (GSF_get_peer_performance_data_ (cp)->pid,
1617 &pmc->origin); 1552 &pmc->origin);
1618 if (NULL == 1553 if (NULL ==
1619 GNUNET_DATASTORE_put (GSF_dsh, 1554 GNUNET_DATASTORE_put (GSF_dsh,
1620 0, &query, dsize, &put[1], 1555 0, &query, dsize, &put[1],
1621 type, prq.priority, 1 /* anonymity */, 1556 type, prq.priority, 1 /* anonymity */ ,
1622 0 /* replication */, 1557 0 /* replication */ ,
1623 expiration, 1558 expiration,
1624 1 + prq.priority, MAX_DATASTORE_QUEUE, 1559 1 + prq.priority, MAX_DATASTORE_QUEUE,
1625 GNUNET_CONSTANTS_SERVICE_TIMEOUT, 1560 GNUNET_CONSTANTS_SERVICE_TIMEOUT,
1626 &put_migration_continuation, 1561 &put_migration_continuation, pmc))
1627 pmc)) 1562 {
1628 { 1563 put_migration_continuation (pmc, GNUNET_NO, NULL);
1629 put_migration_continuation (pmc, GNUNET_NO, NULL);
1630 }
1631 } 1564 }
1565 }
1632 else 1566 else
1633 { 1567 {
1634#if DEBUG_FS 1568#if DEBUG_FS
1635 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1569 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1636 "Choosing not to keep content `%s' (%d/%d)\n", 1570 "Choosing not to keep content `%s' (%d/%d)\n",
1637 GNUNET_h2s (&query), 1571 GNUNET_h2s (&query),
1638 active_to_migration, 1572 active_to_migration, test_put_load_too_high (prq.priority));
1639 test_put_load_too_high (prq.priority));
1640#endif 1573#endif
1641 } 1574 }
1642 putl = GNUNET_LOAD_get_load (datastore_put_load); 1575 putl = GNUNET_LOAD_get_load (datastore_put_load);
1643 if ( (NULL != (cp = prq.sender)) && 1576 if ((NULL != (cp = prq.sender)) &&
1644 (GNUNET_NO == prq.request_found) && 1577 (GNUNET_NO == prq.request_found) &&
1645 ( (GNUNET_YES != active_to_migration) || 1578 ((GNUNET_YES != active_to_migration) ||
1646 (putl > 2.5 * (1 + prq.priority)) ) ) 1579 (putl > 2.5 * (1 + prq.priority))))
1647 { 1580 {
1648 if (GNUNET_YES != active_to_migration) 1581 if (GNUNET_YES != active_to_migration)
1649 putl = 1.0 + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 5); 1582 putl = 1.0 + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 5);
1650 block_time = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 1583 block_time = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
1651 5000 + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 1584 5000 +
1652 (unsigned int) (60000 * putl * putl))); 1585 GNUNET_CRYPTO_random_u32
1653 GSF_block_peer_migration_ (cp, block_time); 1586 (GNUNET_CRYPTO_QUALITY_WEAK,
1654 } 1587 (unsigned int) (60000 * putl *
1588 putl)));
1589 GSF_block_peer_migration_ (cp, block_time);
1590 }
1655 return GNUNET_OK; 1591 return GNUNET_OK;
1656} 1592}
1657 1593
@@ -1664,20 +1600,22 @@ GSF_pending_request_init_ ()
1664{ 1600{
1665 if (GNUNET_OK != 1601 if (GNUNET_OK !=
1666 GNUNET_CONFIGURATION_get_value_number (GSF_cfg, 1602 GNUNET_CONFIGURATION_get_value_number (GSF_cfg,
1667 "fs", 1603 "fs",
1668 "MAX_PENDING_REQUESTS", 1604 "MAX_PENDING_REQUESTS",
1669 &max_pending_requests)) 1605 &max_pending_requests))
1670 { 1606 {
1671 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1607 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1672 _("Configuration fails to specify `%s', assuming default value."), 1608 _
1673 "MAX_PENDING_REQUESTS"); 1609 ("Configuration fails to specify `%s', assuming default value."),
1674 } 1610 "MAX_PENDING_REQUESTS");
1611 }
1675 active_to_migration = GNUNET_CONFIGURATION_get_value_yesno (GSF_cfg, 1612 active_to_migration = GNUNET_CONFIGURATION_get_value_yesno (GSF_cfg,
1676 "FS", 1613 "FS",
1677 "CONTENT_CACHING"); 1614 "CONTENT_CACHING");
1678 datastore_put_load = GNUNET_LOAD_value_init (DATASTORE_LOAD_AUTODECLINE); 1615 datastore_put_load = GNUNET_LOAD_value_init (DATASTORE_LOAD_AUTODECLINE);
1679 pr_map = GNUNET_CONTAINER_multihashmap_create (32 * 1024); 1616 pr_map = GNUNET_CONTAINER_multihashmap_create (32 * 1024);
1680 requests_by_expiration_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); 1617 requests_by_expiration_heap =
1618 GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
1681} 1619}
1682 1620
1683 1621
@@ -1687,9 +1625,7 @@ GSF_pending_request_init_ ()
1687void 1625void
1688GSF_pending_request_done_ () 1626GSF_pending_request_done_ ()
1689{ 1627{
1690 GNUNET_CONTAINER_multihashmap_iterate (pr_map, 1628 GNUNET_CONTAINER_multihashmap_iterate (pr_map, &clean_request, NULL);
1691 &clean_request,
1692 NULL);
1693 GNUNET_CONTAINER_multihashmap_destroy (pr_map); 1629 GNUNET_CONTAINER_multihashmap_destroy (pr_map);
1694 pr_map = NULL; 1630 pr_map = NULL;
1695 GNUNET_CONTAINER_heap_destroy (requests_by_expiration_heap); 1631 GNUNET_CONTAINER_heap_destroy (requests_by_expiration_heap);
diff --git a/src/fs/gnunet-service-fs_pr.h b/src/fs/gnunet-service-fs_pr.h
index 1e71aa7ee..2f89f6e73 100644
--- a/src/fs/gnunet-service-fs_pr.h
+++ b/src/fs/gnunet-service-fs_pr.h
@@ -33,38 +33,38 @@
33 * Options for pending requests (bits to be ORed). 33 * Options for pending requests (bits to be ORed).
34 */ 34 */
35enum GSF_PendingRequestOptions 35enum GSF_PendingRequestOptions
36 { 36{
37 /** 37 /**
38 * Request must only be processed locally. 38 * Request must only be processed locally.
39 */ 39 */
40 GSF_PRO_LOCAL_ONLY = 1, 40 GSF_PRO_LOCAL_ONLY = 1,
41 41
42 /** 42 /**
43 * Request must only be forwarded (no routing) 43 * Request must only be forwarded (no routing)
44 */ 44 */
45 GSF_PRO_FORWARD_ONLY = 2, 45 GSF_PRO_FORWARD_ONLY = 2,
46 46
47 /** 47 /**
48 * Request persists indefinitely (no expiration). 48 * Request persists indefinitely (no expiration).
49 */ 49 */
50 GSF_PRO_REQUEST_EXPIRES = 4, 50 GSF_PRO_REQUEST_EXPIRES = 4,
51 51
52 /** 52 /**
53 * Request is allowed to refresh bloomfilter and change mingle value. 53 * Request is allowed to refresh bloomfilter and change mingle value.
54 */ 54 */
55 GSF_PRO_BLOOMFILTER_FULL_REFRESH = 8, 55 GSF_PRO_BLOOMFILTER_FULL_REFRESH = 8,
56 56
57 /** 57 /**
58 * Request priority is allowed to be exceeded. 58 * Request priority is allowed to be exceeded.
59 */ 59 */
60 GSF_PRO_PRIORITY_UNLIMITED = 16, 60 GSF_PRO_PRIORITY_UNLIMITED = 16,
61 61
62 /** 62 /**
63 * Option mask for typical local requests. 63 * Option mask for typical local requests.
64 */ 64 */
65 GSF_PRO_LOCAL_REQUEST = (GSF_PRO_BLOOMFILTER_FULL_REFRESH | GSF_PRO_PRIORITY_UNLIMITED) 65 GSF_PRO_LOCAL_REQUEST =
66 66 (GSF_PRO_BLOOMFILTER_FULL_REFRESH | GSF_PRO_PRIORITY_UNLIMITED)
67 }; 67};
68 68
69 69
70/** 70/**
@@ -84,7 +84,7 @@ struct GSF_PendingRequestData
84 * Namespace to query, only set if the type is SBLOCK. 84 * Namespace to query, only set if the type is SBLOCK.
85 */ 85 */
86 GNUNET_HashCode namespace; 86 GNUNET_HashCode namespace;
87 87
88 /** 88 /**
89 * Identity of a peer hosting the content, only set if 89 * Identity of a peer hosting the content, only set if
90 * 'has_target' is GNUNET_YES. 90 * 'has_target' is GNUNET_YES.
@@ -130,7 +130,7 @@ struct GSF_PendingRequestData
130 * Options for the request. 130 * Options for the request.
131 */ 131 */
132 enum GSF_PendingRequestOptions options; 132 enum GSF_PendingRequestOptions options;
133 133
134 /** 134 /**
135 * Type of the requested block. 135 * Type of the requested block.
136 */ 136 */
@@ -166,14 +166,17 @@ struct GSF_PendingRequestData
166 * @param data response data, NULL on request expiration 166 * @param data response data, NULL on request expiration
167 * @param data_len number of bytes in data 167 * @param data_len number of bytes in data
168 */ 168 */
169typedef void (*GSF_PendingRequestReplyHandler)(void *cls, 169typedef void (*GSF_PendingRequestReplyHandler) (void *cls,
170 enum GNUNET_BLOCK_EvaluationResult eval, 170 enum
171 struct GSF_PendingRequest *pr, 171 GNUNET_BLOCK_EvaluationResult
172 uint32_t reply_anonymity_level, 172 eval,
173 struct GNUNET_TIME_Absolute expiration, 173 struct GSF_PendingRequest * pr,
174 enum GNUNET_BLOCK_Type type, 174 uint32_t reply_anonymity_level,
175 const void *data, 175 struct GNUNET_TIME_Absolute
176 size_t data_len); 176 expiration,
177 enum GNUNET_BLOCK_Type type,
178 const void *data,
179 size_t data_len);
177 180
178 181
179/** 182/**
@@ -198,23 +201,33 @@ typedef void (*GSF_PendingRequestReplyHandler)(void *cls,
198 * @param rh_cls closure for rh 201 * @param rh_cls closure for rh
199 * @return handle for the new pending request 202 * @return handle for the new pending request
200 */ 203 */
201struct GSF_PendingRequest * 204struct GSF_PendingRequest *GSF_pending_request_create_ (enum
202GSF_pending_request_create_ (enum GSF_PendingRequestOptions options, 205 GSF_PendingRequestOptions
203 enum GNUNET_BLOCK_Type type, 206 options,
204 const GNUNET_HashCode *query, 207 enum GNUNET_BLOCK_Type
205 const GNUNET_HashCode *namespace, 208 type,
206 const struct GNUNET_PeerIdentity *target, 209 const GNUNET_HashCode *
207 const char *bf_data, 210 query,
208 size_t bf_size, 211 const GNUNET_HashCode *
209 uint32_t mingle, 212 namespace,
210 uint32_t anonymity_level, 213 const struct
211 uint32_t priority, 214 GNUNET_PeerIdentity
212 int32_t ttl, 215 *target,
213 GNUNET_PEER_Id sender_pid, 216 const char *bf_data,
214 const GNUNET_HashCode *replies_seen, 217 size_t bf_size,
215 unsigned int replies_seen_count, 218 uint32_t mingle,
216 GSF_PendingRequestReplyHandler rh, 219 uint32_t
217 void *rh_cls); 220 anonymity_level,
221 uint32_t priority,
222 int32_t ttl,
223 GNUNET_PEER_Id
224 sender_pid,
225 const GNUNET_HashCode *
226 replies_seen,
227 unsigned int
228 replies_seen_count,
229 GSF_PendingRequestReplyHandler
230 rh, void *rh_cls);
218 231
219 232
220/** 233/**
@@ -227,8 +240,8 @@ GSF_pending_request_create_ (enum GSF_PendingRequestOptions options,
227 */ 240 */
228void 241void
229GSF_pending_request_update_ (struct GSF_PendingRequest *pr, 242GSF_pending_request_update_ (struct GSF_PendingRequest *pr,
230 const GNUNET_HashCode *replies_seen, 243 const GNUNET_HashCode * replies_seen,
231 unsigned int replies_seen_count); 244 unsigned int replies_seen_count);
232 245
233 246
234/** 247/**
@@ -237,8 +250,9 @@ GSF_pending_request_update_ (struct GSF_PendingRequest *pr,
237 * @param pr pending request 250 * @param pr pending request
238 * @return associated public data 251 * @return associated public data
239 */ 252 */
240struct GSF_PendingRequestData * 253struct GSF_PendingRequestData *GSF_pending_request_get_data_ (struct
241GSF_pending_request_get_data_ (struct GSF_PendingRequest *pr); 254 GSF_PendingRequest
255 *pr);
242 256
243 257
244/** 258/**
@@ -252,7 +266,7 @@ GSF_pending_request_get_data_ (struct GSF_PendingRequest *pr);
252 */ 266 */
253int 267int
254GSF_pending_request_is_compatible_ (struct GSF_PendingRequest *pra, 268GSF_pending_request_is_compatible_ (struct GSF_PendingRequest *pra,
255 struct GSF_PendingRequest *prb); 269 struct GSF_PendingRequest *prb);
256 270
257 271
258/** 272/**
@@ -265,9 +279,14 @@ GSF_pending_request_is_compatible_ (struct GSF_PendingRequest *pra,
265 * @return number of bytes needed (if buf_size too small) or used 279 * @return number of bytes needed (if buf_size too small) or used
266 */ 280 */
267size_t 281size_t
282
283
284
285
286
287
268GSF_pending_request_get_message_ (struct GSF_PendingRequest *pr, 288GSF_pending_request_get_message_ (struct GSF_PendingRequest *pr,
269 size_t buf_size, 289 size_t buf_size, void *buf);
270 void *buf);
271 290
272 291
273/** 292/**
@@ -277,8 +296,7 @@ GSF_pending_request_get_message_ (struct GSF_PendingRequest *pr,
277 * @param full_cleanup fully purge the request 296 * @param full_cleanup fully purge the request
278 */ 297 */
279void 298void
280GSF_pending_request_cancel_ (struct GSF_PendingRequest *pr, 299GSF_pending_request_cancel_ (struct GSF_PendingRequest *pr, int full_cleanup);
281 int full_cleanup);
282 300
283 301
284/** 302/**
@@ -290,9 +308,9 @@ GSF_pending_request_cancel_ (struct GSF_PendingRequest *pr,
290 * @param pr handle to the pending request 308 * @param pr handle to the pending request
291 * @return GNUNET_YES to continue to iterate 309 * @return GNUNET_YES to continue to iterate
292 */ 310 */
293typedef int (*GSF_PendingRequestIterator)(void *cls, 311typedef int (*GSF_PendingRequestIterator) (void *cls,
294 const GNUNET_HashCode *key, 312 const GNUNET_HashCode * key,
295 struct GSF_PendingRequest *pr); 313 struct GSF_PendingRequest * pr);
296 314
297 315
298/** 316/**
@@ -301,9 +319,7 @@ typedef int (*GSF_PendingRequestIterator)(void *cls,
301 * @param it function to call for each request 319 * @param it function to call for each request
302 * @param cls closure for it 320 * @param cls closure for it
303 */ 321 */
304void 322void GSF_iterate_pending_requests_ (GSF_PendingRequestIterator it, void *cls);
305GSF_iterate_pending_requests_ (GSF_PendingRequestIterator it,
306 void *cls);
307 323
308 324
309/** 325/**
@@ -321,7 +337,7 @@ GSF_iterate_pending_requests_ (GSF_PendingRequestIterator it,
321 */ 337 */
322int 338int
323GSF_handle_p2p_content_ (struct GSF_ConnectedPeer *cp, 339GSF_handle_p2p_content_ (struct GSF_ConnectedPeer *cp,
324 const struct GNUNET_MessageHeader *message); 340 const struct GNUNET_MessageHeader *message);
325 341
326 342
327/** 343/**
@@ -329,8 +345,7 @@ GSF_handle_p2p_content_ (struct GSF_ConnectedPeer *cp,
329 * 345 *
330 * @param pr the pending request to process 346 * @param pr the pending request to process
331 */ 347 */
332void 348void GSF_dht_lookup_ (struct GSF_PendingRequest *pr);
333GSF_dht_lookup_ (struct GSF_PendingRequest *pr);
334 349
335 350
336/** 351/**
@@ -341,9 +356,10 @@ GSF_dht_lookup_ (struct GSF_PendingRequest *pr);
341 * @param pr the pending request we were processing 356 * @param pr the pending request we were processing
342 * @param result final datastore lookup result 357 * @param result final datastore lookup result
343 */ 358 */
344typedef void (*GSF_LocalLookupContinuation)(void *cls, 359typedef void (*GSF_LocalLookupContinuation) (void *cls,
345 struct GSF_PendingRequest *pr, 360 struct GSF_PendingRequest * pr,
346 enum GNUNET_BLOCK_EvaluationResult result); 361 enum GNUNET_BLOCK_EvaluationResult
362 result);
347 363
348 364
349/** 365/**
@@ -355,22 +371,19 @@ typedef void (*GSF_LocalLookupContinuation)(void *cls,
355 */ 371 */
356void 372void
357GSF_local_lookup_ (struct GSF_PendingRequest *pr, 373GSF_local_lookup_ (struct GSF_PendingRequest *pr,
358 GSF_LocalLookupContinuation cont, 374 GSF_LocalLookupContinuation cont, void *cont_cls);
359 void *cont_cls);
360 375
361 376
362/** 377/**
363 * Setup the subsystem. 378 * Setup the subsystem.
364 */ 379 */
365void 380void GSF_pending_request_init_ (void);
366GSF_pending_request_init_ (void);
367 381
368 382
369/** 383/**
370 * Shutdown the subsystem. 384 * Shutdown the subsystem.
371 */ 385 */
372void 386void GSF_pending_request_done_ (void);
373GSF_pending_request_done_ (void);
374 387
375 388
376#endif 389#endif
diff --git a/src/fs/gnunet-service-fs_push.c b/src/fs/gnunet-service-fs_push.c
index 099010758..108fce5fc 100644
--- a/src/fs/gnunet-service-fs_push.c
+++ b/src/fs/gnunet-service-fs_push.c
@@ -112,7 +112,7 @@ struct MigrationReadyPeer
112 * Handle to peer. 112 * Handle to peer.
113 */ 113 */
114 struct GSF_ConnectedPeer *peer; 114 struct GSF_ConnectedPeer *peer;
115 115
116 /** 116 /**
117 * Handle for current transmission request, 117 * Handle for current transmission request,
118 * or NULL for none. 118 * or NULL for none.
@@ -181,11 +181,8 @@ static int enabled;
181static void 181static void
182delete_migration_block (struct MigrationReadyBlock *mb) 182delete_migration_block (struct MigrationReadyBlock *mb)
183{ 183{
184 GNUNET_CONTAINER_DLL_remove (mig_head, 184 GNUNET_CONTAINER_DLL_remove (mig_head, mig_tail, mb);
185 mig_tail, 185 GNUNET_PEER_decrement_rcs (mb->target_list, MIGRATION_LIST_SIZE);
186 mb);
187 GNUNET_PEER_decrement_rcs (mb->target_list,
188 MIGRATION_LIST_SIZE);
189 mig_size--; 186 mig_size--;
190 GNUNET_free (mb); 187 GNUNET_free (mb);
191} 188}
@@ -193,9 +190,8 @@ delete_migration_block (struct MigrationReadyBlock *mb)
193 190
194/** 191/**
195 * Find content for migration to this peer. 192 * Find content for migration to this peer.
196 */ 193 */
197static void 194static void find_content (struct MigrationReadyPeer *mrp);
198find_content (struct MigrationReadyPeer *mrp);
199 195
200 196
201/** 197/**
@@ -208,9 +204,7 @@ find_content (struct MigrationReadyPeer *mrp);
208 * @return number of bytes copied to 'buf', can be 0 (without indicating an error) 204 * @return number of bytes copied to 'buf', can be 0 (without indicating an error)
209 */ 205 */
210static size_t 206static size_t
211transmit_message (void *cls, 207transmit_message (void *cls, size_t buf_size, void *buf)
212 size_t buf_size,
213 void *buf)
214{ 208{
215 struct MigrationReadyPeer *peer = cls; 209 struct MigrationReadyPeer *peer = cls;
216 struct PutMessage *msg; 210 struct PutMessage *msg;
@@ -220,22 +214,21 @@ transmit_message (void *cls,
220 msg = peer->msg; 214 msg = peer->msg;
221 peer->msg = NULL; 215 peer->msg = NULL;
222 if (buf == NULL) 216 if (buf == NULL)
223 { 217 {
224#if DEBUG_FS_MIGRATION 218#if DEBUG_FS_MIGRATION
225 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 219 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
226 "Failed to migrate content to another peer (disconnect)\n"); 220 "Failed to migrate content to another peer (disconnect)\n");
227#endif 221#endif
228 GNUNET_free (msg); 222 GNUNET_free (msg);
229 return 0; 223 return 0;
230 } 224 }
231 msize = ntohs (msg->header.size); 225 msize = ntohs (msg->header.size);
232 GNUNET_assert (msize <= buf_size); 226 GNUNET_assert (msize <= buf_size);
233 memcpy (buf, msg, msize); 227 memcpy (buf, msg, msize);
234 GNUNET_free (msg); 228 GNUNET_free (msg);
235#if DEBUG_FS_MIGRATION 229#if DEBUG_FS_MIGRATION
236 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 230 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
237 "Pushing %u bytes to another peer\n", 231 "Pushing %u bytes to another peer\n", msize);
238 msize);
239#endif 232#endif
240 find_content (peer); 233 find_content (peer);
241 return msize; 234 return msize;
@@ -251,11 +244,11 @@ transmit_message (void *cls,
251 */ 244 */
252static int 245static int
253transmit_content (struct MigrationReadyPeer *peer, 246transmit_content (struct MigrationReadyPeer *peer,
254 struct MigrationReadyBlock *block) 247 struct MigrationReadyBlock *block)
255{ 248{
256 size_t msize; 249 size_t msize;
257 struct PutMessage *msg; 250 struct PutMessage *msg;
258 unsigned int i; 251 unsigned int i;
259 struct GSF_PeerPerformanceData *ppd; 252 struct GSF_PeerPerformanceData *ppd;
260 int ret; 253 int ret;
261 254
@@ -267,40 +260,33 @@ transmit_content (struct MigrationReadyPeer *peer,
267 msg->header.size = htons (msize); 260 msg->header.size = htons (msize);
268 msg->type = htonl (block->type); 261 msg->type = htonl (block->type);
269 msg->expiration = GNUNET_TIME_absolute_hton (block->expiration); 262 msg->expiration = GNUNET_TIME_absolute_hton (block->expiration);
270 memcpy (&msg[1], 263 memcpy (&msg[1], &block[1], block->size);
271 &block[1],
272 block->size);
273 peer->msg = msg; 264 peer->msg = msg;
274 for (i=0;i<MIGRATION_LIST_SIZE;i++) 265 for (i = 0; i < MIGRATION_LIST_SIZE; i++)
266 {
267 if (block->target_list[i] == 0)
275 { 268 {
276 if (block->target_list[i] == 0) 269 block->target_list[i] = ppd->pid;
277 { 270 GNUNET_PEER_change_rc (block->target_list[i], 1);
278 block->target_list[i] = ppd->pid; 271 break;
279 GNUNET_PEER_change_rc (block->target_list[i], 1);
280 break;
281 }
282 } 272 }
273 }
283 if (MIGRATION_LIST_SIZE == i) 274 if (MIGRATION_LIST_SIZE == i)
284 { 275 {
285 delete_migration_block (block); 276 delete_migration_block (block);
286 ret = GNUNET_YES; 277 ret = GNUNET_YES;
287 } 278 }
288 else 279 else
289 { 280 {
290 ret = GNUNET_NO; 281 ret = GNUNET_NO;
291 } 282 }
292#if DEBUG_FS_MIGRATION 283#if DEBUG_FS_MIGRATION
293 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 284 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
294 "Asking for transmission of %u bytes for migration\n", 285 "Asking for transmission of %u bytes for migration\n", msize);
295 msize);
296#endif 286#endif
297 peer->th = GSF_peer_transmit_ (peer->peer, 287 peer->th = GSF_peer_transmit_ (peer->peer, GNUNET_NO, 0 /* priority */ ,
298 GNUNET_NO, 288 GNUNET_TIME_UNIT_FOREVER_REL,
299 0 /* priority */, 289 msize, &transmit_message, peer);
300 GNUNET_TIME_UNIT_FOREVER_REL,
301 msize,
302 &transmit_message,
303 peer);
304 return ret; 290 return ret;
305} 291}
306 292
@@ -317,7 +303,7 @@ count_targets (struct MigrationReadyBlock *block)
317{ 303{
318 unsigned int i; 304 unsigned int i;
319 305
320 for (i=0;i<MIGRATION_LIST_SIZE;i++) 306 for (i = 0; i < MIGRATION_LIST_SIZE; i++)
321 if (block->target_list[i] == 0) 307 if (block->target_list[i] == 0)
322 return i; 308 return i;
323 return i; 309 return i;
@@ -334,7 +320,7 @@ count_targets (struct MigrationReadyBlock *block)
334 */ 320 */
335static long 321static long
336score_content (struct MigrationReadyPeer *peer, 322score_content (struct MigrationReadyPeer *peer,
337 struct MigrationReadyBlock *block) 323 struct MigrationReadyBlock *block)
338{ 324{
339 unsigned int i; 325 unsigned int i;
340 struct GSF_PeerPerformanceData *ppd; 326 struct GSF_PeerPerformanceData *ppd;
@@ -342,14 +328,12 @@ score_content (struct MigrationReadyPeer *peer,
342 uint32_t dist; 328 uint32_t dist;
343 329
344 ppd = GSF_get_peer_performance_data_ (peer->peer); 330 ppd = GSF_get_peer_performance_data_ (peer->peer);
345 for (i=0;i<MIGRATION_LIST_SIZE;i++) 331 for (i = 0; i < MIGRATION_LIST_SIZE; i++)
346 if (block->target_list[i] == ppd->pid) 332 if (block->target_list[i] == ppd->pid)
347 return -1; 333 return -1;
348 GNUNET_assert (0 != ppd->pid); 334 GNUNET_assert (0 != ppd->pid);
349 GNUNET_PEER_resolve (ppd->pid, 335 GNUNET_PEER_resolve (ppd->pid, &id);
350 &id); 336 dist = GNUNET_CRYPTO_hash_distance_u32 (&block->query, &id.hashPubKey);
351 dist = GNUNET_CRYPTO_hash_distance_u32 (&block->query,
352 &id.hashPubKey);
353 /* closer distance, higher score: */ 337 /* closer distance, higher score: */
354 return UINT32_MAX - dist; 338 return UINT32_MAX - dist;
355} 339}
@@ -359,15 +343,14 @@ score_content (struct MigrationReadyPeer *peer,
359 * If the migration task is not currently running, consider 343 * If the migration task is not currently running, consider
360 * (re)scheduling it with the appropriate delay. 344 * (re)scheduling it with the appropriate delay.
361 */ 345 */
362static void 346static void consider_gathering (void);
363consider_gathering (void);
364 347
365 348
366/** 349/**
367 * Find content for migration to this peer. 350 * Find content for migration to this peer.
368 * 351 *
369 * @param mrp peer to find content for 352 * @param mrp peer to find content for
370 */ 353 */
371static void 354static void
372find_content (struct MigrationReadyPeer *mrp) 355find_content (struct MigrationReadyPeer *mrp)
373{ 356{
@@ -381,51 +364,51 @@ find_content (struct MigrationReadyPeer *mrp)
381 best_score = -1; 364 best_score = -1;
382 pos = mig_head; 365 pos = mig_head;
383 while (NULL != pos) 366 while (NULL != pos)
367 {
368 score = score_content (mrp, pos);
369 if (score > best_score)
384 { 370 {
385 score = score_content (mrp, pos); 371 best_score = score;
386 if (score > best_score) 372 best = pos;
387 {
388 best_score = score;
389 best = pos;
390 }
391 pos = pos->next;
392 } 373 }
393 if (NULL == best) 374 pos = pos->next;
375 }
376 if (NULL == best)
377 {
378 if (mig_size < MAX_MIGRATION_QUEUE)
394 { 379 {
395 if (mig_size < MAX_MIGRATION_QUEUE)
396 {
397#if DEBUG_FS_MIGRATION 380#if DEBUG_FS_MIGRATION
398 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 381 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
399 "No content found for pushing, waiting for queue to fill\n"); 382 "No content found for pushing, waiting for queue to fill\n");
400#endif 383#endif
401 return; /* will fill up eventually... */ 384 return; /* will fill up eventually... */
402 } 385 }
403#if DEBUG_FS_MIGRATION 386#if DEBUG_FS_MIGRATION
404 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 387 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
405 "No suitable content found, purging content from full queue\n"); 388 "No suitable content found, purging content from full queue\n");
406#endif 389#endif
407 /* failed to find migration target AND 390 /* failed to find migration target AND
408 queue is full, purge most-forwarded 391 * queue is full, purge most-forwarded
409 block from queue to make room for more */ 392 * block from queue to make room for more */
410 pos = mig_head; 393 pos = mig_head;
411 while (NULL != pos) 394 while (NULL != pos)
412 { 395 {
413 score = count_targets (pos); 396 score = count_targets (pos);
414 if (score >= best_score) 397 if (score >= best_score)
415 { 398 {
416 best_score = score; 399 best_score = score;
417 best = pos; 400 best = pos;
418 } 401 }
419 pos = pos->next; 402 pos = pos->next;
420 }
421 GNUNET_assert (NULL != best);
422 delete_migration_block (best);
423 consider_gathering ();
424 return;
425 } 403 }
404 GNUNET_assert (NULL != best);
405 delete_migration_block (best);
406 consider_gathering ();
407 return;
408 }
426#if DEBUG_FS_MIGRATION 409#if DEBUG_FS_MIGRATION
427 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 410 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
428 "Preparing to push best content to peer\n"); 411 "Preparing to push best content to peer\n");
429#endif 412#endif
430 transmit_content (mrp, best); 413 transmit_content (mrp, best);
431} 414}
@@ -440,7 +423,7 @@ find_content (struct MigrationReadyPeer *mrp)
440 */ 423 */
441static void 424static void
442gather_migration_blocks (void *cls, 425gather_migration_blocks (void *cls,
443 const struct GNUNET_SCHEDULER_TaskContext *tc); 426 const struct GNUNET_SCHEDULER_TaskContext *tc);
444 427
445 428
446/** 429/**
@@ -458,22 +441,17 @@ consider_gathering ()
458 return; 441 return;
459 if (mig_task != GNUNET_SCHEDULER_NO_TASK) 442 if (mig_task != GNUNET_SCHEDULER_NO_TASK)
460 return; 443 return;
461 if (mig_size >= MAX_MIGRATION_QUEUE) 444 if (mig_size >= MAX_MIGRATION_QUEUE)
462 return; 445 return;
463 delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 446 delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, mig_size);
464 mig_size); 447 delay = GNUNET_TIME_relative_divide (delay, MAX_MIGRATION_QUEUE);
465 delay = GNUNET_TIME_relative_divide (delay, 448 delay = GNUNET_TIME_relative_max (delay, min_migration_delay);
466 MAX_MIGRATION_QUEUE);
467 delay = GNUNET_TIME_relative_max (delay,
468 min_migration_delay);
469#if DEBUG_FS_MIGRATION 449#if DEBUG_FS_MIGRATION
470 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 450 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
471 "Scheduling gathering task (queue size: %u)\n", 451 "Scheduling gathering task (queue size: %u)\n", mig_size);
472 mig_size);
473#endif 452#endif
474 mig_task = GNUNET_SCHEDULER_add_delayed (delay, 453 mig_task = GNUNET_SCHEDULER_add_delayed (delay,
475 &gather_migration_blocks, 454 &gather_migration_blocks, NULL);
476 NULL);
477} 455}
478 456
479 457
@@ -493,53 +471,47 @@ consider_gathering ()
493 */ 471 */
494static void 472static void
495process_migration_content (void *cls, 473process_migration_content (void *cls,
496 const GNUNET_HashCode *key, 474 const GNUNET_HashCode * key,
497 size_t size, 475 size_t size,
498 const void *data, 476 const void *data,
499 enum GNUNET_BLOCK_Type type, 477 enum GNUNET_BLOCK_Type type,
500 uint32_t priority, 478 uint32_t priority,
501 uint32_t anonymity, 479 uint32_t anonymity,
502 struct GNUNET_TIME_Absolute 480 struct GNUNET_TIME_Absolute expiration, uint64_t uid)
503 expiration, uint64_t uid)
504{ 481{
505 struct MigrationReadyBlock *mb; 482 struct MigrationReadyBlock *mb;
506 struct MigrationReadyPeer *pos; 483 struct MigrationReadyPeer *pos;
507 484
508 mig_qe = NULL; 485 mig_qe = NULL;
509 if (key == NULL) 486 if (key == NULL)
510 { 487 {
511#if DEBUG_FS_MIGRATION 488#if DEBUG_FS_MIGRATION
512 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 489 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No content found for migration...\n");
513 "No content found for migration...\n");
514#endif 490#endif
515 consider_gathering (); 491 consider_gathering ();
516 return; 492 return;
517 } 493 }
518 if (GNUNET_TIME_absolute_get_remaining (expiration).rel_value < 494 if (GNUNET_TIME_absolute_get_remaining (expiration).rel_value <
519 MIN_MIGRATION_CONTENT_LIFETIME.rel_value) 495 MIN_MIGRATION_CONTENT_LIFETIME.rel_value)
520 { 496 {
521 /* content will expire soon, don't bother */ 497 /* content will expire soon, don't bother */
522 consider_gathering (); 498 consider_gathering ();
523 return; 499 return;
524 } 500 }
525 if (type == GNUNET_BLOCK_TYPE_FS_ONDEMAND) 501 if (type == GNUNET_BLOCK_TYPE_FS_ONDEMAND)
526 { 502 {
527 if (GNUNET_OK != 503 if (GNUNET_OK !=
528 GNUNET_FS_handle_on_demand_block (key, size, data, 504 GNUNET_FS_handle_on_demand_block (key, size, data,
529 type, priority, anonymity, 505 type, priority, anonymity,
530 expiration, uid, 506 expiration, uid,
531 &process_migration_content, 507 &process_migration_content, NULL))
532 NULL)) 508 consider_gathering ();
533 consider_gathering (); 509 return;
534 return; 510 }
535 }
536#if DEBUG_FS_MIGRATION 511#if DEBUG_FS_MIGRATION
537 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 512 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
538 "Retrieved block `%s' of type %u for migration (queue size: %u/%u)\n", 513 "Retrieved block `%s' of type %u for migration (queue size: %u/%u)\n",
539 GNUNET_h2s (key), 514 GNUNET_h2s (key), type, mig_size + 1, MAX_MIGRATION_QUEUE);
540 type,
541 mig_size + 1,
542 MAX_MIGRATION_QUEUE);
543#endif 515#endif
544 mb = GNUNET_malloc (sizeof (struct MigrationReadyBlock) + size); 516 mb = GNUNET_malloc (sizeof (struct MigrationReadyBlock) + size);
545 mb->query = *key; 517 mb->query = *key;
@@ -547,25 +519,22 @@ process_migration_content (void *cls,
547 mb->size = size; 519 mb->size = size;
548 mb->type = type; 520 mb->type = type;
549 memcpy (&mb[1], data, size); 521 memcpy (&mb[1], data, size);
550 GNUNET_CONTAINER_DLL_insert_after (mig_head, 522 GNUNET_CONTAINER_DLL_insert_after (mig_head, mig_tail, mig_tail, mb);
551 mig_tail,
552 mig_tail,
553 mb);
554 mig_size++; 523 mig_size++;
555 pos = peer_head; 524 pos = peer_head;
556 while (pos != NULL) 525 while (pos != NULL)
526 {
527 if (NULL == pos->th)
557 { 528 {
558 if (NULL == pos->th)
559 {
560#if DEBUG_FS_MIGRATION 529#if DEBUG_FS_MIGRATION
561 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 530 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
562 "Preparing to push best content to peer\n"); 531 "Preparing to push best content to peer\n");
563#endif 532#endif
564 if (GNUNET_YES == transmit_content (pos, mb)) 533 if (GNUNET_YES == transmit_content (pos, mb))
565 break; /* 'mb' was freed! */ 534 break; /* 'mb' was freed! */
566 }
567 pos = pos->next;
568 } 535 }
536 pos = pos->next;
537 }
569 consider_gathering (); 538 consider_gathering ();
570} 539}
571 540
@@ -579,25 +548,26 @@ process_migration_content (void *cls,
579 */ 548 */
580static void 549static void
581gather_migration_blocks (void *cls, 550gather_migration_blocks (void *cls,
582 const struct GNUNET_SCHEDULER_TaskContext *tc) 551 const struct GNUNET_SCHEDULER_TaskContext *tc)
583{ 552{
584 mig_task = GNUNET_SCHEDULER_NO_TASK; 553 mig_task = GNUNET_SCHEDULER_NO_TASK;
585 if (mig_size >= MAX_MIGRATION_QUEUE) 554 if (mig_size >= MAX_MIGRATION_QUEUE)
586 return; 555 return;
587 if (GSF_dsh != NULL) 556 if (GSF_dsh != NULL)
588 { 557 {
589#if DEBUG_FS_MIGRATION 558#if DEBUG_FS_MIGRATION
590 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 559 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
591 "Asking datastore for content for replication (queue size: %u)\n", 560 "Asking datastore for content for replication (queue size: %u)\n",
592 mig_size); 561 mig_size);
593#endif 562#endif
594 mig_qe = GNUNET_DATASTORE_get_for_replication (GSF_dsh, 563 mig_qe = GNUNET_DATASTORE_get_for_replication (GSF_dsh,
595 0, UINT_MAX, 564 0, UINT_MAX,
596 GNUNET_TIME_UNIT_FOREVER_REL, 565 GNUNET_TIME_UNIT_FOREVER_REL,
597 &process_migration_content, NULL); 566 &process_migration_content,
598 if (NULL == mig_qe) 567 NULL);
599 consider_gathering (); 568 if (NULL == mig_qe)
600 } 569 consider_gathering ();
570 }
601} 571}
602 572
603 573
@@ -617,9 +587,7 @@ GSF_push_start_ (struct GSF_ConnectedPeer *peer)
617 mrp = GNUNET_malloc (sizeof (struct MigrationReadyPeer)); 587 mrp = GNUNET_malloc (sizeof (struct MigrationReadyPeer));
618 mrp->peer = peer; 588 mrp->peer = peer;
619 find_content (mrp); 589 find_content (mrp);
620 GNUNET_CONTAINER_DLL_insert (peer_head, 590 GNUNET_CONTAINER_DLL_insert (peer_head, peer_tail, mrp);
621 peer_tail,
622 mrp);
623} 591}
624 592
625 593
@@ -636,27 +604,25 @@ GSF_push_stop_ (struct GSF_ConnectedPeer *peer)
636 604
637 pos = peer_head; 605 pos = peer_head;
638 while (pos != NULL) 606 while (pos != NULL)
607 {
608 if (pos->peer == peer)
639 { 609 {
640 if (pos->peer == peer) 610 GNUNET_CONTAINER_DLL_remove (peer_head, peer_tail, pos);
641 { 611 if (NULL != pos->th)
642 GNUNET_CONTAINER_DLL_remove (peer_head, 612 {
643 peer_tail, 613 GSF_peer_transmit_cancel_ (pos->th);
644 pos); 614 pos->th = NULL;
645 if (NULL != pos->th) 615 }
646 { 616 if (NULL != pos->msg)
647 GSF_peer_transmit_cancel_ (pos->th); 617 {
648 pos->th = NULL; 618 GNUNET_free (pos->msg);
649 } 619 pos->msg = NULL;
650 if (NULL != pos->msg) 620 }
651 { 621 GNUNET_free (pos);
652 GNUNET_free (pos->msg); 622 return;
653 pos->msg = NULL;
654 }
655 GNUNET_free (pos);
656 return;
657 }
658 pos = pos->next;
659 } 623 }
624 pos = pos->next;
625 }
660} 626}
661 627
662 628
@@ -667,23 +633,22 @@ void
667GSF_push_init_ () 633GSF_push_init_ ()
668{ 634{
669 enabled = GNUNET_CONFIGURATION_get_value_yesno (GSF_cfg, 635 enabled = GNUNET_CONFIGURATION_get_value_yesno (GSF_cfg,
670 "FS", 636 "FS", "CONTENT_PUSHING");
671 "CONTENT_PUSHING");
672 if (GNUNET_YES != enabled) 637 if (GNUNET_YES != enabled)
673 return; 638 return;
674 639
675 if (GNUNET_OK != 640 if (GNUNET_OK !=
676 GNUNET_CONFIGURATION_get_value_time (GSF_cfg, 641 GNUNET_CONFIGURATION_get_value_time (GSF_cfg,
677 "fs", 642 "fs",
678 "MIN_MIGRATION_DELAY", 643 "MIN_MIGRATION_DELAY",
679 &min_migration_delay)) 644 &min_migration_delay))
680 { 645 {
681 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 646 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
682 _("Invalid value specified for option `%s' in section `%s', content pushing disabled\n"), 647 _
683 "MIN_MIGRATION_DELAY", 648 ("Invalid value specified for option `%s' in section `%s', content pushing disabled\n"),
684 "fs"); 649 "MIN_MIGRATION_DELAY", "fs");
685 return; 650 return;
686 } 651 }
687 consider_gathering (); 652 consider_gathering ();
688} 653}
689 654
@@ -695,15 +660,15 @@ void
695GSF_push_done_ () 660GSF_push_done_ ()
696{ 661{
697 if (GNUNET_SCHEDULER_NO_TASK != mig_task) 662 if (GNUNET_SCHEDULER_NO_TASK != mig_task)
698 { 663 {
699 GNUNET_SCHEDULER_cancel (mig_task); 664 GNUNET_SCHEDULER_cancel (mig_task);
700 mig_task = GNUNET_SCHEDULER_NO_TASK; 665 mig_task = GNUNET_SCHEDULER_NO_TASK;
701 } 666 }
702 if (NULL != mig_qe) 667 if (NULL != mig_qe)
703 { 668 {
704 GNUNET_DATASTORE_cancel (mig_qe); 669 GNUNET_DATASTORE_cancel (mig_qe);
705 mig_qe = NULL; 670 mig_qe = NULL;
706 } 671 }
707 while (NULL != mig_head) 672 while (NULL != mig_head)
708 delete_migration_block (mig_head); 673 delete_migration_block (mig_head);
709 GNUNET_assert (0 == mig_size); 674 GNUNET_assert (0 == mig_size);
diff --git a/src/fs/gnunet-service-fs_push.h b/src/fs/gnunet-service-fs_push.h
index 7967b04cd..40e1252be 100644
--- a/src/fs/gnunet-service-fs_push.h
+++ b/src/fs/gnunet-service-fs_push.h
@@ -32,15 +32,13 @@
32/** 32/**
33 * Setup the module. 33 * Setup the module.
34 */ 34 */
35void 35void GSF_push_init_ (void);
36GSF_push_init_ (void);
37 36
38 37
39/** 38/**
40 * Shutdown the module. 39 * Shutdown the module.
41 */ 40 */
42void 41void GSF_push_done_ (void);
43GSF_push_done_ (void);
44 42
45 43
46/** 44/**
@@ -49,8 +47,7 @@ GSF_push_done_ (void);
49 * 47 *
50 * @param peer handle for the peer that connected 48 * @param peer handle for the peer that connected
51 */ 49 */
52void 50void GSF_push_start_ (struct GSF_ConnectedPeer *peer);
53GSF_push_start_ (struct GSF_ConnectedPeer *peer);
54 51
55 52
56/** 53/**
@@ -59,8 +56,7 @@ GSF_push_start_ (struct GSF_ConnectedPeer *peer);
59 * 56 *
60 * @param peer handle for the peer that disconnected 57 * @param peer handle for the peer that disconnected
61 */ 58 */
62void 59void GSF_push_stop_ (struct GSF_ConnectedPeer *peer);
63GSF_push_stop_ (struct GSF_ConnectedPeer *peer);
64 60
65 61
66#endif 62#endif
diff --git a/src/fs/gnunet-service-fs_put.c b/src/fs/gnunet-service-fs_put.c
index b15207ce8..e67bf0c04 100644
--- a/src/fs/gnunet-service-fs_put.c
+++ b/src/fs/gnunet-service-fs_put.c
@@ -54,7 +54,7 @@ struct PutOperator
54 * ID of task that collects blocks for DHT PUTs. 54 * ID of task that collects blocks for DHT PUTs.
55 */ 55 */
56 GNUNET_SCHEDULER_TaskIdentifier dht_task; 56 GNUNET_SCHEDULER_TaskIdentifier dht_task;
57 57
58 /** 58 /**
59 * How many entires with zero anonymity of our type do we currently 59 * How many entires with zero anonymity of our type do we currently
60 * estimate to have in the database? 60 * estimate to have in the database?
@@ -72,13 +72,12 @@ struct PutOperator
72 * ANY-terminated list of our operators (one per type 72 * ANY-terminated list of our operators (one per type
73 * of block that we're putting into the DHT). 73 * of block that we're putting into the DHT).
74 */ 74 */
75static struct PutOperator operators[] = 75static struct PutOperator operators[] = {
76 { 76 {NULL, GNUNET_BLOCK_TYPE_FS_KBLOCK, 0, 0, 0},
77 { NULL, GNUNET_BLOCK_TYPE_FS_KBLOCK, 0, 0, 0 }, 77 {NULL, GNUNET_BLOCK_TYPE_FS_SBLOCK, 0, 0, 0},
78 { NULL, GNUNET_BLOCK_TYPE_FS_SBLOCK, 0, 0, 0 }, 78 {NULL, GNUNET_BLOCK_TYPE_FS_NBLOCK, 0, 0, 0},
79 { NULL, GNUNET_BLOCK_TYPE_FS_NBLOCK, 0, 0, 0 }, 79 {NULL, GNUNET_BLOCK_TYPE_ANY, 0, 0, 0}
80 { NULL, GNUNET_BLOCK_TYPE_ANY, 0, 0, 0 } 80};
81 };
82 81
83 82
84/** 83/**
@@ -89,7 +88,7 @@ static struct PutOperator operators[] =
89 */ 88 */
90static void 89static void
91gather_dht_put_blocks (void *cls, 90gather_dht_put_blocks (void *cls,
92 const struct GNUNET_SCHEDULER_TaskContext *tc); 91 const struct GNUNET_SCHEDULER_TaskContext *tc);
93 92
94 93
95/** 94/**
@@ -99,8 +98,7 @@ gather_dht_put_blocks (void *cls,
99 * @param tc scheduler context (unused) 98 * @param tc scheduler context (unused)
100 */ 99 */
101static void 100static void
102delay_dht_put_blocks (void *cls, 101delay_dht_put_blocks (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
103 const struct GNUNET_SCHEDULER_TaskContext *tc)
104{ 102{
105 struct PutOperator *po = cls; 103 struct PutOperator *po = cls;
106 struct GNUNET_TIME_Relative delay; 104 struct GNUNET_TIME_Relative delay;
@@ -109,21 +107,19 @@ delay_dht_put_blocks (void *cls,
109 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) 107 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
110 return; 108 return;
111 if (po->zero_anonymity_count_estimate > 0) 109 if (po->zero_anonymity_count_estimate > 0)
112 { 110 {
113 delay = GNUNET_TIME_relative_divide (GNUNET_DHT_DEFAULT_REPUBLISH_FREQUENCY, 111 delay = GNUNET_TIME_relative_divide (GNUNET_DHT_DEFAULT_REPUBLISH_FREQUENCY,
114 po->zero_anonymity_count_estimate); 112 po->zero_anonymity_count_estimate);
115 delay = GNUNET_TIME_relative_min (delay, 113 delay = GNUNET_TIME_relative_min (delay, MAX_DHT_PUT_FREQ);
116 MAX_DHT_PUT_FREQ); 114 }
117 }
118 else 115 else
119 { 116 {
120 /* if we have NO zero-anonymity content yet, wait 5 minutes for some to 117 /* if we have NO zero-anonymity content yet, wait 5 minutes for some to
121 (hopefully) appear */ 118 * (hopefully) appear */
122 delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5); 119 delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5);
123 } 120 }
124 po->dht_task = GNUNET_SCHEDULER_add_delayed (delay, 121 po->dht_task = GNUNET_SCHEDULER_add_delayed (delay,
125 &gather_dht_put_blocks, 122 &gather_dht_put_blocks, po);
126 po);
127} 123}
128 124
129 125
@@ -143,45 +139,40 @@ delay_dht_put_blocks (void *cls,
143 */ 139 */
144static void 140static void
145process_dht_put_content (void *cls, 141process_dht_put_content (void *cls,
146 const GNUNET_HashCode * key, 142 const GNUNET_HashCode * key,
147 size_t size, 143 size_t size,
148 const void *data, 144 const void *data,
149 enum GNUNET_BLOCK_Type type, 145 enum GNUNET_BLOCK_Type type,
150 uint32_t priority, 146 uint32_t priority,
151 uint32_t anonymity, 147 uint32_t anonymity,
152 struct GNUNET_TIME_Absolute 148 struct GNUNET_TIME_Absolute expiration, uint64_t uid)
153 expiration, uint64_t uid) 149{
154{
155 struct PutOperator *po = cls; 150 struct PutOperator *po = cls;
156 151
157 po->dht_qe = NULL; 152 po->dht_qe = NULL;
158 if (key == NULL) 153 if (key == NULL)
159 { 154 {
160 po->zero_anonymity_count_estimate = po->current_offset - 1; 155 po->zero_anonymity_count_estimate = po->current_offset - 1;
161 po->current_offset = 0; 156 po->current_offset = 0;
162 po->dht_task = GNUNET_SCHEDULER_add_now (&delay_dht_put_blocks, 157 po->dht_task = GNUNET_SCHEDULER_add_now (&delay_dht_put_blocks, po);
163 po); 158 return;
164 return; 159 }
165 }
166 po->zero_anonymity_count_estimate = GNUNET_MAX (po->current_offset, 160 po->zero_anonymity_count_estimate = GNUNET_MAX (po->current_offset,
167 po->zero_anonymity_count_estimate); 161 po->zero_anonymity_count_estimate);
168#if DEBUG_FS 162#if DEBUG_FS
169 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 163 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
170 "Retrieved block `%s' of type %u for DHT PUT\n", 164 "Retrieved block `%s' of type %u for DHT PUT\n",
171 GNUNET_h2s (key), 165 GNUNET_h2s (key), type);
172 type);
173#endif 166#endif
174 GNUNET_DHT_put (GSF_dht, 167 GNUNET_DHT_put (GSF_dht,
175 key, 168 key,
176 DEFAULT_PUT_REPLICATION, 169 DEFAULT_PUT_REPLICATION,
177 GNUNET_DHT_RO_NONE, 170 GNUNET_DHT_RO_NONE,
178 type, 171 type,
179 size, 172 size,
180 data, 173 data,
181 expiration, 174 expiration,
182 GNUNET_TIME_UNIT_FOREVER_REL, 175 GNUNET_TIME_UNIT_FOREVER_REL, &delay_dht_put_blocks, po);
183 &delay_dht_put_blocks,
184 po);
185} 176}
186 177
187 178
@@ -192,23 +183,22 @@ process_dht_put_content (void *cls,
192 * @param tc scheduler context (unused) 183 * @param tc scheduler context (unused)
193 */ 184 */
194static void 185static void
195gather_dht_put_blocks (void *cls, 186gather_dht_put_blocks (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
196 const struct GNUNET_SCHEDULER_TaskContext *tc)
197{ 187{
198 struct PutOperator *po = cls; 188 struct PutOperator *po = cls;
199 189
200 po->dht_task = GNUNET_SCHEDULER_NO_TASK; 190 po->dht_task = GNUNET_SCHEDULER_NO_TASK;
201 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) 191 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
202 return; 192 return;
203 po->dht_qe = GNUNET_DATASTORE_get_zero_anonymity (GSF_dsh, 193 po->dht_qe = GNUNET_DATASTORE_get_zero_anonymity (GSF_dsh,
204 po->current_offset++, 194 po->current_offset++,
205 0, UINT_MAX, 195 0, UINT_MAX,
206 GNUNET_TIME_UNIT_FOREVER_REL, 196 GNUNET_TIME_UNIT_FOREVER_REL,
207 po->dht_put_type, 197 po->dht_put_type,
208 &process_dht_put_content, po); 198 &process_dht_put_content,
199 po);
209 if (NULL == po->dht_qe) 200 if (NULL == po->dht_qe)
210 po->dht_task = GNUNET_SCHEDULER_add_now (&delay_dht_put_blocks, 201 po->dht_task = GNUNET_SCHEDULER_add_now (&delay_dht_put_blocks, po);
211 po);
212} 202}
213 203
214 204
@@ -222,10 +212,11 @@ GSF_put_init_ ()
222 212
223 i = 0; 213 i = 0;
224 while (operators[i].dht_put_type != GNUNET_BLOCK_TYPE_ANY) 214 while (operators[i].dht_put_type != GNUNET_BLOCK_TYPE_ANY)
225 { 215 {
226 operators[i].dht_task = GNUNET_SCHEDULER_add_now (&gather_dht_put_blocks, &operators[i]); 216 operators[i].dht_task =
227 i++; 217 GNUNET_SCHEDULER_add_now (&gather_dht_put_blocks, &operators[i]);
228 } 218 i++;
219 }
229} 220}
230 221
231 222
@@ -240,19 +231,19 @@ GSF_put_done_ ()
240 231
241 i = 0; 232 i = 0;
242 while ((po = &operators[i])->dht_put_type != GNUNET_BLOCK_TYPE_ANY) 233 while ((po = &operators[i])->dht_put_type != GNUNET_BLOCK_TYPE_ANY)
234 {
235 if (GNUNET_SCHEDULER_NO_TASK != po->dht_task)
236 {
237 GNUNET_SCHEDULER_cancel (po->dht_task);
238 po->dht_task = GNUNET_SCHEDULER_NO_TASK;
239 }
240 if (NULL != po->dht_qe)
243 { 241 {
244 if (GNUNET_SCHEDULER_NO_TASK != po->dht_task) 242 GNUNET_DATASTORE_cancel (po->dht_qe);
245 { 243 po->dht_qe = NULL;
246 GNUNET_SCHEDULER_cancel (po->dht_task);
247 po->dht_task = GNUNET_SCHEDULER_NO_TASK;
248 }
249 if (NULL != po->dht_qe)
250 {
251 GNUNET_DATASTORE_cancel (po->dht_qe);
252 po->dht_qe = NULL;
253 }
254 i++;
255 } 244 }
245 i++;
246 }
256} 247}
257 248
258/* end of gnunet-service-fs_put.c */ 249/* end of gnunet-service-fs_put.c */
diff --git a/src/fs/gnunet-service-fs_put.h b/src/fs/gnunet-service-fs_put.h
index 59b1f83e3..21c3c3baf 100644
--- a/src/fs/gnunet-service-fs_put.h
+++ b/src/fs/gnunet-service-fs_put.h
@@ -32,15 +32,13 @@
32/** 32/**
33 * Setup the module. 33 * Setup the module.
34 */ 34 */
35void 35void GSF_put_init_ (void);
36GSF_put_init_ (void);
37 36
38 37
39/** 38/**
40 * Shutdown the module. 39 * Shutdown the module.
41 */ 40 */
42void 41void GSF_put_done_ (void);
43GSF_put_done_ (void);
44 42
45 43
46#endif 44#endif
diff --git a/src/fs/gnunet-unindex.c b/src/fs/gnunet-unindex.c
index c1d1890db..a4aad4568 100644
--- a/src/fs/gnunet-unindex.c
+++ b/src/fs/gnunet-unindex.c
@@ -40,8 +40,7 @@ static struct GNUNET_FS_UnindexContext *uc;
40 40
41 41
42static void 42static void
43cleanup_task (void *cls, 43cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
44 const struct GNUNET_SCHEDULER_TaskContext *tc)
45{ 44{
46 GNUNET_FS_stop (ctx); 45 GNUNET_FS_stop (ctx);
47 ctx = NULL; 46 ctx = NULL;
@@ -49,17 +48,16 @@ cleanup_task (void *cls,
49 48
50 49
51static void 50static void
52shutdown_task (void *cls, 51shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
53 const struct GNUNET_SCHEDULER_TaskContext *tc)
54{ 52{
55 struct GNUNET_FS_UnindexContext *u; 53 struct GNUNET_FS_UnindexContext *u;
56 54
57 if (uc != NULL) 55 if (uc != NULL)
58 { 56 {
59 u = uc; 57 u = uc;
60 uc = NULL; 58 uc = NULL;
61 GNUNET_FS_unindex_stop (u); 59 GNUNET_FS_unindex_stop (u);
62 } 60 }
63} 61}
64 62
65/** 63/**
@@ -76,49 +74,44 @@ shutdown_task (void *cls,
76 * field in the GNUNET_FS_ProgressInfo struct. 74 * field in the GNUNET_FS_ProgressInfo struct.
77 */ 75 */
78static void * 76static void *
79progress_cb (void *cls, 77progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
80 const struct GNUNET_FS_ProgressInfo *info)
81{ 78{
82 char *s; 79 char *s;
83 80
84 switch (info->status) 81 switch (info->status)
82 {
83 case GNUNET_FS_STATUS_UNINDEX_START:
84 break;
85 case GNUNET_FS_STATUS_UNINDEX_PROGRESS:
86 if (verbose)
85 { 87 {
86 case GNUNET_FS_STATUS_UNINDEX_START: 88 s = GNUNET_STRINGS_relative_time_to_string (info->value.unindex.eta);
87 break;
88 case GNUNET_FS_STATUS_UNINDEX_PROGRESS:
89 if (verbose)
90 {
91 s = GNUNET_STRINGS_relative_time_to_string(info->value.unindex.eta);
92 fprintf (stdout,
93 _("Unindexing at %llu/%llu (%s remaining)\n"),
94 (unsigned long long) info->value.unindex.completed,
95 (unsigned long long) info->value.unindex.size,
96 s);
97 GNUNET_free (s);
98 }
99 break;
100 case GNUNET_FS_STATUS_UNINDEX_ERROR:
101 fprintf (stderr,
102 _("Error unindexing: %s.\n"),
103 info->value.unindex.specifics.error.message);
104 GNUNET_SCHEDULER_shutdown ();
105 break;
106 case GNUNET_FS_STATUS_UNINDEX_COMPLETED:
107 fprintf (stdout, 89 fprintf (stdout,
108 _("Unindexing done.\n")); 90 _("Unindexing at %llu/%llu (%s remaining)\n"),
109 GNUNET_SCHEDULER_shutdown (); 91 (unsigned long long) info->value.unindex.completed,
110 break; 92 (unsigned long long) info->value.unindex.size, s);
111 case GNUNET_FS_STATUS_UNINDEX_STOPPED: 93 GNUNET_free (s);
112 GNUNET_SCHEDULER_add_continuation (&cleanup_task,
113 NULL,
114 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
115 break;
116 default:
117 fprintf (stderr,
118 _("Unexpected status: %d\n"),
119 info->status);
120 break;
121 } 94 }
95 break;
96 case GNUNET_FS_STATUS_UNINDEX_ERROR:
97 fprintf (stderr,
98 _("Error unindexing: %s.\n"),
99 info->value.unindex.specifics.error.message);
100 GNUNET_SCHEDULER_shutdown ();
101 break;
102 case GNUNET_FS_STATUS_UNINDEX_COMPLETED:
103 fprintf (stdout, _("Unindexing done.\n"));
104 GNUNET_SCHEDULER_shutdown ();
105 break;
106 case GNUNET_FS_STATUS_UNINDEX_STOPPED:
107 GNUNET_SCHEDULER_add_continuation (&cleanup_task,
108 NULL,
109 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
110 break;
111 default:
112 fprintf (stderr, _("Unexpected status: %d\n"), info->status);
113 break;
114 }
122 return NULL; 115 return NULL;
123} 116}
124 117
@@ -134,45 +127,35 @@ progress_cb (void *cls,
134static void 127static void
135run (void *cls, 128run (void *cls,
136 char *const *args, 129 char *const *args,
137 const char *cfgfile, 130 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
138 const struct GNUNET_CONFIGURATION_Handle *c)
139{ 131{
140 /* check arguments */ 132 /* check arguments */
141 if ( (args[0] == NULL) || (args[1] != NULL) ) 133 if ((args[0] == NULL) || (args[1] != NULL))
142 { 134 {
143 printf (_ 135 printf (_("You must specify one and only one filename for unindexing.\n"));
144 ("You must specify one and only one filename for unindexing.\n")); 136 ret = -1;
145 ret = -1; 137 return;
146 return; 138 }
147 }
148 cfg = c; 139 cfg = c;
149 ctx = GNUNET_FS_start (cfg, 140 ctx = GNUNET_FS_start (cfg,
150 "gnunet-unindex", 141 "gnunet-unindex",
151 &progress_cb, 142 &progress_cb,
152 NULL, 143 NULL, GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
153 GNUNET_FS_FLAGS_NONE,
154 GNUNET_FS_OPTIONS_END);
155 if (NULL == ctx) 144 if (NULL == ctx)
156 { 145 {
157 fprintf (stderr, 146 fprintf (stderr, _("Could not initialize `%s' subsystem.\n"), "FS");
158 _("Could not initialize `%s' subsystem.\n"), 147 ret = 1;
159 "FS"); 148 return;
160 ret = 1; 149 }
161 return; 150 uc = GNUNET_FS_unindex_start (ctx, args[0], NULL);
162 }
163 uc = GNUNET_FS_unindex_start (ctx,
164 args[0],
165 NULL);
166 if (NULL == uc) 151 if (NULL == uc)
167 { 152 {
168 fprintf (stderr, 153 fprintf (stderr, _("Could not start unindex operation.\n"));
169 _("Could not start unindex operation.\n")); 154 GNUNET_FS_stop (ctx);
170 GNUNET_FS_stop (ctx); 155 return;
171 return; 156 }
172 }
173 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 157 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
174 &shutdown_task, 158 &shutdown_task, NULL);
175 NULL);
176} 159}
177 160
178 161
diff --git a/src/fs/perf_gnunet_service_fs_p2p.c b/src/fs/perf_gnunet_service_fs_p2p.c
index 572585520..92441e901 100644
--- a/src/fs/perf_gnunet_service_fs_p2p.c
+++ b/src/fs/perf_gnunet_service_fs_p2p.c
@@ -52,11 +52,9 @@ static struct GNUNET_TIME_Absolute start_time;
52static const char *progname; 52static const char *progname;
53 53
54static void 54static void
55do_stop (void *cls, 55do_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
56 const struct GNUNET_SCHEDULER_TaskContext *tc)
57{ 56{
58 GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, 57 GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, daemons);
59 daemons);
60} 58}
61 59
62 60
@@ -65,7 +63,7 @@ do_stop (void *cls,
65 */ 63 */
66struct StatMaster 64struct StatMaster
67{ 65{
68 struct GNUNET_STATISTICS_Handle *stat; 66 struct GNUNET_STATISTICS_Handle *stat;
69 unsigned int daemon; 67 unsigned int daemon;
70 unsigned int value; 68 unsigned int value;
71}; 69};
@@ -79,32 +77,31 @@ struct StatValues
79/** 77/**
80 * Statistics we print out. 78 * Statistics we print out.
81 */ 79 */
82static struct StatValues stats[] = 80static struct StatValues stats[] = {
83 { 81 {"fs", "# artificial delays introduced (ms)"},
84 { "fs", "# artificial delays introduced (ms)"}, 82 {"fs", "# queries forwarded"},
85 { "fs", "# queries forwarded"}, 83 {"fs", "# replies received and matched"},
86 { "fs", "# replies received and matched"}, 84 {"fs", "# results found locally"},
87 { "fs", "# results found locally"}, 85 {"fs", "# requests forwarded due to high load"},
88 { "fs", "# requests forwarded due to high load"}, 86 {"fs", "# requests done for free (low load)"},
89 { "fs", "# requests done for free (low load)"}, 87 {"fs", "# requests dropped, priority insufficient"},
90 { "fs", "# requests dropped, priority insufficient"}, 88 {"fs", "# requests done for a price (normal load)"},
91 { "fs", "# requests done for a price (normal load)"}, 89 {"fs", "# requests dropped by datastore (queue length limit)"},
92 { "fs", "# requests dropped by datastore (queue length limit)"}, 90 {"fs", "# P2P searches received"},
93 { "fs", "# P2P searches received"}, 91 {"fs", "# P2P searches discarded (queue length bound)"},
94 { "fs", "# P2P searches discarded (queue length bound)"}, 92 {"fs", "# replies received for local clients"},
95 { "fs", "# replies received for local clients"}, 93 {"fs", "# queries retransmitted to same target"},
96 { "fs", "# queries retransmitted to same target"}, 94 {"core", "# bytes decrypted"},
97 { "core", "# bytes decrypted"}, 95 {"core", "# bytes encrypted"},
98 { "core", "# bytes encrypted"}, 96 {"core", "# discarded CORE_SEND requests"},
99 { "core", "# discarded CORE_SEND requests"}, 97 {"core", "# discarded CORE_SEND request bytes"},
100 { "core", "# discarded CORE_SEND request bytes"}, 98 {"core", "# discarded lower priority CORE_SEND requests"},
101 { "core", "# discarded lower priority CORE_SEND requests"}, 99 {"core", "# discarded lower priority CORE_SEND request bytes"},
102 { "core", "# discarded lower priority CORE_SEND request bytes"}, 100 {"transport", "# bytes received via TCP"},
103 { "transport", "# bytes received via TCP"}, 101 {"transport", "# bytes transmitted via TCP"},
104 { "transport", "# bytes transmitted via TCP"}, 102 {"datacache", "# bytes stored"},
105 { "datacache", "# bytes stored"}, 103 {NULL, NULL}
106 { NULL, NULL} 104};
107 };
108 105
109 106
110/** 107/**
@@ -119,18 +116,14 @@ static struct StatValues stats[] =
119 */ 116 */
120static int 117static int
121print_stat (void *cls, 118print_stat (void *cls,
122 const char *subsystem, 119 const char *subsystem,
123 const char *name, 120 const char *name, uint64_t value, int is_persistent)
124 uint64_t value,
125 int is_persistent)
126{ 121{
127 struct StatMaster *sm = cls; 122 struct StatMaster *sm = cls;
123
128 fprintf (stderr, 124 fprintf (stderr,
129 "Peer %2u: %12s/%50s = %12llu\n", 125 "Peer %2u: %12s/%50s = %12llu\n",
130 sm->daemon, 126 sm->daemon, subsystem, name, (unsigned long long) value);
131 subsystem,
132 name,
133 (unsigned long long) value);
134 return GNUNET_OK; 127 return GNUNET_OK;
135} 128}
136 129
@@ -138,20 +131,18 @@ print_stat (void *cls,
138/** 131/**
139 * Function that gathers stats from all daemons. 132 * Function that gathers stats from all daemons.
140 */ 133 */
141static void 134static void stat_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
142stat_run (void *cls,
143 const struct GNUNET_SCHEDULER_TaskContext *tc);
144 135
145 136
146/** 137/**
147 * Function called when GET operation on stats is done. 138 * Function called when GET operation on stats is done.
148 */ 139 */
149static void 140static void
150get_done (void *cls, 141get_done (void *cls, int success)
151 int success)
152{ 142{
153 struct StatMaster *sm = cls; 143 struct StatMaster *sm = cls;
154 GNUNET_break (GNUNET_OK == success); 144
145 GNUNET_break (GNUNET_OK == success);
155 sm->value++; 146 sm->value++;
156 GNUNET_SCHEDULER_add_now (&stat_run, sm); 147 GNUNET_SCHEDULER_add_now (&stat_run, sm);
157} 148}
@@ -161,129 +152,115 @@ get_done (void *cls,
161 * Function that gathers stats from all daemons. 152 * Function that gathers stats from all daemons.
162 */ 153 */
163static void 154static void
164stat_run (void *cls, 155stat_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
165 const struct GNUNET_SCHEDULER_TaskContext *tc)
166{ 156{
167 struct StatMaster *sm = cls; 157 struct StatMaster *sm = cls;
168 158
169 if (stats[sm->value].name != NULL) 159 if (stats[sm->value].name != NULL)
170 { 160 {
171 GNUNET_STATISTICS_get (sm->stat, 161 GNUNET_STATISTICS_get (sm->stat,
172#if 0 162#if 0
173 NULL, NULL, 163 NULL, NULL,
174#else 164#else
175 stats[sm->value].subsystem, 165 stats[sm->value].subsystem, stats[sm->value].name,
176 stats[sm->value].name,
177#endif 166#endif
178 GNUNET_TIME_UNIT_FOREVER_REL, 167 GNUNET_TIME_UNIT_FOREVER_REL,
179 &get_done, 168 &get_done, &print_stat, sm);
180 &print_stat, sm); 169 return;
181 return; 170 }
182 }
183 GNUNET_STATISTICS_destroy (sm->stat, GNUNET_NO); 171 GNUNET_STATISTICS_destroy (sm->stat, GNUNET_NO);
184 sm->value = 0; 172 sm->value = 0;
185 sm->daemon++; 173 sm->daemon++;
186 if (sm->daemon == NUM_DAEMONS) 174 if (sm->daemon == NUM_DAEMONS)
187 { 175 {
188 GNUNET_free (sm); 176 GNUNET_free (sm);
189 GNUNET_SCHEDULER_add_now (&do_stop, NULL); 177 GNUNET_SCHEDULER_add_now (&do_stop, NULL);
190 return; 178 return;
191 } 179 }
192 sm->stat = GNUNET_STATISTICS_create ("<driver>", 180 sm->stat = GNUNET_STATISTICS_create ("<driver>",
193 GNUNET_FS_TEST_get_configuration (daemons, 181 GNUNET_FS_TEST_get_configuration
194 sm->daemon)); 182 (daemons, sm->daemon));
195 GNUNET_SCHEDULER_add_now (&stat_run, sm); 183 GNUNET_SCHEDULER_add_now (&stat_run, sm);
196} 184}
197 185
198 186
199static void 187static void
200do_report (void *cls, 188do_report (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
201 const struct GNUNET_SCHEDULER_TaskContext *tc)
202{ 189{
203 struct GNUNET_TIME_Relative del; 190 struct GNUNET_TIME_Relative del;
204 char *fancy; 191 char *fancy;
205 struct StatMaster *sm; 192 struct StatMaster *sm;
206 193
207 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE)) 194 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE))
208 { 195 {
209 del = GNUNET_TIME_absolute_get_duration (start_time); 196 del = GNUNET_TIME_absolute_get_duration (start_time);
210 if (del.rel_value == 0) 197 if (del.rel_value == 0)
211 del.rel_value = 1; 198 del.rel_value = 1;
212 fancy = GNUNET_STRINGS_byte_size_fancy (((unsigned long long)FILESIZE) * 1000LL / del.rel_value); 199 fancy =
213 fprintf (stdout, 200 GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) *
214 "Download speed was %s/s\n", 201 1000LL / del.rel_value);
215 fancy); 202 fprintf (stdout, "Download speed was %s/s\n", fancy);
216 GNUNET_free (fancy); 203 GNUNET_free (fancy);
217 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 204 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
218 "Finished download, shutting down\n", 205 "Finished download, shutting down\n",
219 (unsigned long long) FILESIZE); 206 (unsigned long long) FILESIZE);
220 sm = GNUNET_malloc (sizeof (struct StatMaster)); 207 sm = GNUNET_malloc (sizeof (struct StatMaster));
221 sm->stat = GNUNET_STATISTICS_create ("<driver>", 208 sm->stat = GNUNET_STATISTICS_create ("<driver>",
222 GNUNET_FS_TEST_get_configuration (daemons, 209 GNUNET_FS_TEST_get_configuration
223 sm->daemon)); 210 (daemons, sm->daemon));
224 GNUNET_SCHEDULER_add_now (&stat_run, sm); 211 GNUNET_SCHEDULER_add_now (&stat_run, sm);
225 } 212 }
226 else 213 else
227 { 214 {
228 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 215 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
229 "Timeout during download, shutting down with error\n"); 216 "Timeout during download, shutting down with error\n");
230 ok = 1; 217 ok = 1;
231 GNUNET_SCHEDULER_add_now (&do_stop, NULL); 218 GNUNET_SCHEDULER_add_now (&do_stop, NULL);
232 } 219 }
233} 220}
234 221
235 222
236static void 223static void
237do_download (void *cls, 224do_download (void *cls, const struct GNUNET_FS_Uri *uri)
238 const struct GNUNET_FS_Uri *uri)
239{ 225{
240 int anonymity; 226 int anonymity;
241 227
242 if (NULL == uri) 228 if (NULL == uri)
243 { 229 {
244 GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, 230 GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, daemons);
245 daemons); 231 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
246 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 232 "Timeout during upload attempt, shutting down with error\n");
247 "Timeout during upload attempt, shutting down with error\n"); 233 ok = 1;
248 ok = 1; 234 return;
249 return; 235 }
250 }
251 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 236 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
252 "Downloading %llu bytes\n", 237 "Downloading %llu bytes\n", (unsigned long long) FILESIZE);
253 (unsigned long long) FILESIZE);
254 start_time = GNUNET_TIME_absolute_get (); 238 start_time = GNUNET_TIME_absolute_get ();
255 if (NULL != strstr (progname, "dht")) 239 if (NULL != strstr (progname, "dht"))
256 anonymity = 0; 240 anonymity = 0;
257 else 241 else
258 anonymity = 1; 242 anonymity = 1;
259 GNUNET_FS_TEST_download (daemons[0], 243 GNUNET_FS_TEST_download (daemons[0],
260 TIMEOUT, 244 TIMEOUT,
261 anonymity, SEED, uri, 245 anonymity, SEED, uri, VERBOSE, &do_report, NULL);
262 VERBOSE,
263 &do_report, NULL);
264} 246}
265 247
266 248
267static void 249static void
268do_publish (void *cls, 250do_publish (void *cls, const char *emsg)
269 const char *emsg)
270{ 251{
271 int do_index; 252 int do_index;
272 int anonymity; 253 int anonymity;
273 254
274 if (NULL != emsg) 255 if (NULL != emsg)
275 { 256 {
276 GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, 257 GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, daemons);
277 daemons); 258 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error trying to connect: %s\n", emsg);
278 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 259 ok = 1;
279 "Error trying to connect: %s\n", 260 return;
280 emsg); 261 }
281 ok = 1;
282 return;
283 }
284 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 262 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
285 "Publishing %llu bytes\n", 263 "Publishing %llu bytes\n", (unsigned long long) FILESIZE);
286 (unsigned long long) FILESIZE);
287 if (NULL != strstr (progname, "index")) 264 if (NULL != strstr (progname, "index"))
288 do_index = GNUNET_YES; 265 do_index = GNUNET_YES;
289 else 266 else
@@ -292,61 +269,52 @@ do_publish (void *cls,
292 anonymity = 0; 269 anonymity = 0;
293 else 270 else
294 anonymity = 1; 271 anonymity = 1;
295 272
296 GNUNET_FS_TEST_publish (daemons[NUM_DAEMONS-1], 273 GNUNET_FS_TEST_publish (daemons[NUM_DAEMONS - 1],
297 TIMEOUT, 274 TIMEOUT,
298 anonymity, 275 anonymity,
299 do_index, FILESIZE, SEED, 276 do_index, FILESIZE, SEED,
300 VERBOSE, 277 VERBOSE, &do_download, NULL);
301 &do_download, NULL);
302} 278}
303 279
304 280
305static void 281static void
306do_connect (void *cls, 282do_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
307 const struct GNUNET_SCHEDULER_TaskContext *tc)
308{ 283{
309 struct GNUNET_TESTING_PeerGroup *pg; 284 struct GNUNET_TESTING_PeerGroup *pg;
310 285
311 GNUNET_assert (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE)); 286 GNUNET_assert (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE));
312 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 287 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
313 "Daemons started, will now try to connect them\n"); 288 "Daemons started, will now try to connect them\n");
314 pg = GNUNET_FS_TEST_get_group (daemons); 289 pg = GNUNET_FS_TEST_get_group (daemons);
315 GNUNET_break ( (NUM_DAEMONS - 1) * 2 290 GNUNET_break ((NUM_DAEMONS - 1) * 2
316 == (GNUNET_TESTING_create_topology (pg, 291 == (GNUNET_TESTING_create_topology (pg,
317 GNUNET_TESTING_TOPOLOGY_LINE, 292 GNUNET_TESTING_TOPOLOGY_LINE,
318 GNUNET_TESTING_TOPOLOGY_NONE, 293 GNUNET_TESTING_TOPOLOGY_NONE,
319 NULL))); 294 NULL)));
320 GNUNET_TESTING_connect_topology (pg, 295 GNUNET_TESTING_connect_topology (pg,
321 GNUNET_TESTING_TOPOLOGY_LINE, 296 GNUNET_TESTING_TOPOLOGY_LINE,
322 GNUNET_TESTING_TOPOLOGY_OPTION_NONE, 297 GNUNET_TESTING_TOPOLOGY_OPTION_NONE,
323 0.0, 298 0.0,
324 TIMEOUT, 299 TIMEOUT, NUM_DAEMONS, &do_publish, NULL);
325 NUM_DAEMONS,
326 &do_publish,
327 NULL);
328} 300}
329 301
330 302
331static void 303static void
332run (void *cls, 304run (void *cls,
333 char *const *args, 305 char *const *args,
334 const char *cfgfile, 306 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
335 const struct GNUNET_CONFIGURATION_Handle *cfg)
336{ 307{
337 GNUNET_FS_TEST_daemons_start ("fs_test_lib_data.conf", 308 GNUNET_FS_TEST_daemons_start ("fs_test_lib_data.conf",
338 TIMEOUT, 309 TIMEOUT,
339 NUM_DAEMONS, 310 NUM_DAEMONS, daemons, &do_connect, NULL);
340 daemons,
341 &do_connect,
342 NULL);
343} 311}
344 312
345 313
346int 314int
347main (int argc, char *argv[]) 315main (int argc, char *argv[])
348{ 316{
349 char *const argvx[] = { 317 char *const argvx[] = {
350 "perf-gnunet-service-fs-p2p", 318 "perf-gnunet-service-fs-p2p",
351 "-c", 319 "-c",
352 "fs_test_lib_data.conf", 320 "fs_test_lib_data.conf",
@@ -360,16 +328,16 @@ main (int argc, char *argv[])
360 }; 328 };
361 progname = argv[0]; 329 progname = argv[0];
362 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/"); 330 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/");
363 GNUNET_log_setup ("perf_gnunet_service_fs_p2p_index", 331 GNUNET_log_setup ("perf_gnunet_service_fs_p2p_index",
364#if VERBOSE 332#if VERBOSE
365 "DEBUG", 333 "DEBUG",
366#else 334#else
367 "WARNING", 335 "WARNING",
368#endif 336#endif
369 NULL); 337 NULL);
370 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, 338 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
371 argvx, "perf-gnunet-service-fs-p2p-index", 339 argvx, "perf-gnunet-service-fs-p2p-index",
372 "nohelp", options, &run, NULL); 340 "nohelp", options, &run, NULL);
373 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/"); 341 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/");
374 return ok; 342 return ok;
375} 343}
diff --git a/src/fs/perf_gnunet_service_fs_p2p_trust.c b/src/fs/perf_gnunet_service_fs_p2p_trust.c
index 0128e281d..a78ff0571 100644
--- a/src/fs/perf_gnunet_service_fs_p2p_trust.c
+++ b/src/fs/perf_gnunet_service_fs_p2p_trust.c
@@ -87,11 +87,9 @@ static struct GNUNET_FS_Uri *uri1;
87static struct GNUNET_FS_Uri *uri2; 87static struct GNUNET_FS_Uri *uri2;
88 88
89static void 89static void
90do_stop (void *cls, 90do_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
91 const struct GNUNET_SCHEDULER_TaskContext *tc)
92{ 91{
93 GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, 92 GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, daemons);
94 daemons);
95} 93}
96 94
97 95
@@ -100,7 +98,7 @@ do_stop (void *cls,
100 */ 98 */
101struct StatMaster 99struct StatMaster
102{ 100{
103 struct GNUNET_STATISTICS_Handle *stat; 101 struct GNUNET_STATISTICS_Handle *stat;
104 unsigned int daemon; 102 unsigned int daemon;
105 unsigned int value; 103 unsigned int value;
106}; 104};
@@ -114,30 +112,29 @@ struct StatValues
114/** 112/**
115 * Statistics we print out. 113 * Statistics we print out.
116 */ 114 */
117static struct StatValues stats[] = 115static struct StatValues stats[] = {
118 { 116 {"fs", "# artificial delays introduced (ms)"},
119 { "fs", "# artificial delays introduced (ms)"}, 117 {"fs", "# queries forwarded"},
120 { "fs", "# queries forwarded"}, 118 {"fs", "# replies received and matched"},
121 { "fs", "# replies received and matched"}, 119 {"fs", "# results found locally"},
122 { "fs", "# results found locally"}, 120 {"fs", "# requests forwarded due to high load"},
123 { "fs", "# requests forwarded due to high load"}, 121 {"fs", "# requests done for free (low load)"},
124 { "fs", "# requests done for free (low load)"}, 122 {"fs", "# requests dropped, priority insufficient"},
125 { "fs", "# requests dropped, priority insufficient"}, 123 {"fs", "# requests done for a price (normal load)"},
126 { "fs", "# requests done for a price (normal load)"}, 124 {"fs", "# requests dropped by datastore (queue length limit)"},
127 { "fs", "# requests dropped by datastore (queue length limit)"}, 125 {"fs", "# P2P searches received"},
128 { "fs", "# P2P searches received"}, 126 {"fs", "# P2P searches discarded (queue length bound)"},
129 { "fs", "# P2P searches discarded (queue length bound)"}, 127 {"fs", "# replies received for local clients"},
130 { "fs", "# replies received for local clients"}, 128 {"fs", "# queries retransmitted to same target"},
131 { "fs", "# queries retransmitted to same target"}, 129 {"core", "# bytes decrypted"},
132 { "core", "# bytes decrypted"}, 130 {"core", "# bytes encrypted"},
133 { "core", "# bytes encrypted"}, 131 {"core", "# discarded CORE_SEND requests"},
134 { "core", "# discarded CORE_SEND requests"}, 132 {"core", "# discarded lower priority CORE_SEND requests"},
135 { "core", "# discarded lower priority CORE_SEND requests"}, 133 {"transport", "# bytes received via TCP"},
136 { "transport", "# bytes received via TCP"}, 134 {"transport", "# bytes transmitted via TCP"},
137 { "transport", "# bytes transmitted via TCP"}, 135 {"datacache", "# bytes stored"},
138 { "datacache", "# bytes stored"}, 136 {NULL, NULL}
139 { NULL, NULL} 137};
140 };
141 138
142 139
143/** 140/**
@@ -152,18 +149,14 @@ static struct StatValues stats[] =
152 */ 149 */
153static int 150static int
154print_stat (void *cls, 151print_stat (void *cls,
155 const char *subsystem, 152 const char *subsystem,
156 const char *name, 153 const char *name, uint64_t value, int is_persistent)
157 uint64_t value,
158 int is_persistent)
159{ 154{
160 struct StatMaster *sm = cls; 155 struct StatMaster *sm = cls;
156
161 fprintf (stderr, 157 fprintf (stderr,
162 "Peer %2u: %12s/%50s = %12llu\n", 158 "Peer %2u: %12s/%50s = %12llu\n",
163 sm->daemon, 159 sm->daemon, subsystem, name, (unsigned long long) value);
164 subsystem,
165 name,
166 (unsigned long long) value);
167 return GNUNET_OK; 160 return GNUNET_OK;
168} 161}
169 162
@@ -171,20 +164,18 @@ print_stat (void *cls,
171/** 164/**
172 * Function that gathers stats from all daemons. 165 * Function that gathers stats from all daemons.
173 */ 166 */
174static void 167static void stat_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
175stat_run (void *cls,
176 const struct GNUNET_SCHEDULER_TaskContext *tc);
177 168
178 169
179/** 170/**
180 * Function called when GET operation on stats is done. 171 * Function called when GET operation on stats is done.
181 */ 172 */
182static void 173static void
183get_done (void *cls, 174get_done (void *cls, int success)
184 int success)
185{ 175{
186 struct StatMaster *sm = cls; 176 struct StatMaster *sm = cls;
187 GNUNET_break (GNUNET_OK == success); 177
178 GNUNET_break (GNUNET_OK == success);
188 sm->value++; 179 sm->value++;
189 GNUNET_SCHEDULER_add_now (&stat_run, sm); 180 GNUNET_SCHEDULER_add_now (&stat_run, sm);
190} 181}
@@ -194,154 +185,140 @@ get_done (void *cls,
194 * Function that gathers stats from all daemons. 185 * Function that gathers stats from all daemons.
195 */ 186 */
196static void 187static void
197stat_run (void *cls, 188stat_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
198 const struct GNUNET_SCHEDULER_TaskContext *tc)
199{ 189{
200 struct StatMaster *sm = cls; 190 struct StatMaster *sm = cls;
201 191
202 if (stats[sm->value].name != NULL) 192 if (stats[sm->value].name != NULL)
203 { 193 {
204 GNUNET_STATISTICS_get (sm->stat, 194 GNUNET_STATISTICS_get (sm->stat,
205#if 0 195#if 0
206 NULL, NULL, 196 NULL, NULL,
207#else 197#else
208 stats[sm->value].subsystem, 198 stats[sm->value].subsystem, stats[sm->value].name,
209 stats[sm->value].name,
210#endif 199#endif
211 GNUNET_TIME_UNIT_FOREVER_REL, 200 GNUNET_TIME_UNIT_FOREVER_REL,
212 &get_done, 201 &get_done, &print_stat, sm);
213 &print_stat, sm); 202 return;
214 return; 203 }
215 }
216 GNUNET_STATISTICS_destroy (sm->stat, GNUNET_NO); 204 GNUNET_STATISTICS_destroy (sm->stat, GNUNET_NO);
217 sm->value = 0; 205 sm->value = 0;
218 sm->daemon++; 206 sm->daemon++;
219 if (sm->daemon == NUM_DAEMONS) 207 if (sm->daemon == NUM_DAEMONS)
220 { 208 {
221 GNUNET_free (sm); 209 GNUNET_free (sm);
222 GNUNET_SCHEDULER_add_now (&do_stop, NULL); 210 GNUNET_SCHEDULER_add_now (&do_stop, NULL);
223 return; 211 return;
224 } 212 }
225 sm->stat = GNUNET_STATISTICS_create ("<driver>", 213 sm->stat = GNUNET_STATISTICS_create ("<driver>",
226 GNUNET_FS_TEST_get_configuration (daemons, 214 GNUNET_FS_TEST_get_configuration
227 sm->daemon)); 215 (daemons, sm->daemon));
228 GNUNET_SCHEDULER_add_now (&stat_run, sm); 216 GNUNET_SCHEDULER_add_now (&stat_run, sm);
229} 217}
230 218
231 219
232static void 220static void
233do_report (void *cls, 221do_report (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
234 const struct GNUNET_SCHEDULER_TaskContext *tc)
235{ 222{
236 static int download_counter; 223 static int download_counter;
237 const char *type = cls; 224 const char *type = cls;
238 struct GNUNET_TIME_Relative del; 225 struct GNUNET_TIME_Relative del;
239 char *fancy; 226 char *fancy;
240 struct StatMaster *sm; 227 struct StatMaster *sm;
241 228
242 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE)) 229 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE))
243 { 230 {
244 del = GNUNET_TIME_absolute_get_duration (start_time); 231 del = GNUNET_TIME_absolute_get_duration (start_time);
245 if (del.rel_value == 0) 232 if (del.rel_value == 0)
246 del.rel_value = 1; 233 del.rel_value = 1;
247 fancy = GNUNET_STRINGS_byte_size_fancy (((unsigned long long)FILESIZE) * 1000LL / del.rel_value); 234 fancy =
248 fprintf (stderr, 235 GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) *
249 "Download speed of type `%s' was %s/s\n", 236 1000LL / del.rel_value);
250 type, 237 fprintf (stderr, "Download speed of type `%s' was %s/s\n", type, fancy);
251 fancy); 238 GNUNET_free (fancy);
252 GNUNET_free (fancy); 239 if (NUM_DAEMONS != ++download_counter)
253 if (NUM_DAEMONS != ++download_counter) 240 return; /* more downloads to come */
254 return; /* more downloads to come */ 241 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
255 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 242 "Finished all downloads, shutting down\n",
256 "Finished all downloads, shutting down\n", 243 (unsigned long long) FILESIZE);
257 (unsigned long long) FILESIZE); 244 sm = GNUNET_malloc (sizeof (struct StatMaster));
258 sm = GNUNET_malloc (sizeof (struct StatMaster)); 245 sm->stat = GNUNET_STATISTICS_create ("<driver>",
259 sm->stat = GNUNET_STATISTICS_create ("<driver>", 246 GNUNET_FS_TEST_get_configuration
260 GNUNET_FS_TEST_get_configuration (daemons, 247 (daemons, sm->daemon));
261 sm->daemon)); 248 GNUNET_SCHEDULER_add_now (&stat_run, sm);
262 GNUNET_SCHEDULER_add_now (&stat_run, sm); 249 }
263 }
264 else 250 else
265 { 251 {
266 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 252 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
267 "Timeout during download for type `%s', shutting down with error\n", 253 "Timeout during download for type `%s', shutting down with error\n",
268 type); 254 type);
269 ok = 1; 255 ok = 1;
270 GNUNET_SCHEDULER_add_now (&do_stop, NULL); 256 GNUNET_SCHEDULER_add_now (&do_stop, NULL);
271 } 257 }
272} 258}
273 259
274 260
275static void 261static void
276do_downloads (void *cls, 262do_downloads (void *cls, const struct GNUNET_FS_Uri *u2)
277 const struct GNUNET_FS_Uri *u2)
278{ 263{
279 int anonymity; 264 int anonymity;
280 unsigned int i; 265 unsigned int i;
281 266
282 if (NULL == u2) 267 if (NULL == u2)
283 { 268 {
284 GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, 269 GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, daemons);
285 daemons); 270 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
286 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 271 "Timeout during upload attempt, shutting down with error\n");
287 "Timeout during upload attempt, shutting down with error\n"); 272 ok = 1;
288 ok = 1; 273 return;
289 return; 274 }
290 }
291 uri2 = GNUNET_FS_uri_dup (u2); 275 uri2 = GNUNET_FS_uri_dup (u2);
292 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 276 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
293 "Downloading %llu bytes\n", 277 "Downloading %llu bytes\n", (unsigned long long) FILESIZE);
294 (unsigned long long) FILESIZE);
295 start_time = GNUNET_TIME_absolute_get (); 278 start_time = GNUNET_TIME_absolute_get ();
296 if (NULL != strstr (progname, "dht")) 279 if (NULL != strstr (progname, "dht"))
297 anonymity = 0; 280 anonymity = 0;
298 else 281 else
299 anonymity = 1; 282 anonymity = 1;
300 /* (semi) leach-download(s); not true leaches since 283 /* (semi) leach-download(s); not true leaches since
301 these peers do participate in sharing, they just 284 * these peers do participate in sharing, they just
302 don't have to offer anything *initially*. */ 285 * don't have to offer anything *initially*. */
303 for (i=0;i<NUM_DAEMONS-2;i++) 286 for (i = 0; i < NUM_DAEMONS - 2; i++)
304 GNUNET_FS_TEST_download (daemons[i], 287 GNUNET_FS_TEST_download (daemons[i],
305 TIMEOUT, 288 TIMEOUT,
306 anonymity, 289 anonymity,
307 0 == (i%2) ? SEED1 : SEED2, 290 0 == (i % 2) ? SEED1 : SEED2,
308 0 == (i%2) ? uri1 : uri2, 291 0 == (i % 2) ? uri1 : uri2,
309 VERBOSE, 292 VERBOSE, &do_report, "leach");
310 &do_report, "leach");
311 /* mutual downloads of (primary) sharing peers */ 293 /* mutual downloads of (primary) sharing peers */
312 GNUNET_FS_TEST_download (daemons[NUM_DAEMONS-2], 294 GNUNET_FS_TEST_download (daemons[NUM_DAEMONS - 2],
313 TIMEOUT, 295 TIMEOUT,
314 anonymity, SEED1, uri1, 296 anonymity, SEED1, uri1,
315 VERBOSE, 297 VERBOSE, &do_report, "seeder 2");
316 &do_report, "seeder 2"); 298 GNUNET_FS_TEST_download (daemons[NUM_DAEMONS - 1],
317 GNUNET_FS_TEST_download (daemons[NUM_DAEMONS-1], 299 TIMEOUT,
318 TIMEOUT, 300 anonymity, SEED2, uri2,
319 anonymity, SEED2, uri2, 301 VERBOSE, &do_report, "seeder 1");
320 VERBOSE,
321 &do_report, "seeder 1");
322} 302}
323 303
324 304
325static void 305static void
326do_publish2 (void *cls, 306do_publish2 (void *cls, const struct GNUNET_FS_Uri *u1)
327 const struct GNUNET_FS_Uri *u1)
328{ 307{
329 int do_index; 308 int do_index;
330 int anonymity; 309 int anonymity;
331 310
332 if (NULL == u1) 311 if (NULL == u1)
333 { 312 {
334 GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, 313 GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, daemons);
335 daemons); 314 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
336 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 315 "Timeout during upload attempt, shutting down with error\n");
337 "Timeout during upload attempt, shutting down with error\n"); 316 ok = 1;
338 ok = 1; 317 return;
339 return; 318 }
340 }
341 uri1 = GNUNET_FS_uri_dup (u1); 319 uri1 = GNUNET_FS_uri_dup (u1);
342 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 320 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
343 "Publishing %llu bytes\n", 321 "Publishing %llu bytes\n", (unsigned long long) FILESIZE);
344 (unsigned long long) FILESIZE);
345 if (NULL != strstr (progname, "index")) 322 if (NULL != strstr (progname, "index"))
346 do_index = GNUNET_YES; 323 do_index = GNUNET_YES;
347 else 324 else
@@ -350,35 +327,29 @@ do_publish2 (void *cls,
350 anonymity = 0; 327 anonymity = 0;
351 else 328 else
352 anonymity = 1; 329 anonymity = 1;
353 330
354 GNUNET_FS_TEST_publish (daemons[NUM_DAEMONS-2], 331 GNUNET_FS_TEST_publish (daemons[NUM_DAEMONS - 2],
355 TIMEOUT, 332 TIMEOUT,
356 anonymity, 333 anonymity,
357 do_index, FILESIZE, SEED2, 334 do_index, FILESIZE, SEED2,
358 VERBOSE, 335 VERBOSE, &do_downloads, NULL);
359 &do_downloads, NULL);
360} 336}
361 337
362static void 338static void
363do_publish1 (void *cls, 339do_publish1 (void *cls, const char *emsg)
364 const char *emsg)
365{ 340{
366 int do_index; 341 int do_index;
367 int anonymity; 342 int anonymity;
368 343
369 if (NULL != emsg) 344 if (NULL != emsg)
370 { 345 {
371 GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, 346 GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, daemons);
372 daemons); 347 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error trying to connect: %s\n", emsg);
373 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 348 ok = 1;
374 "Error trying to connect: %s\n", 349 return;
375 emsg); 350 }
376 ok = 1;
377 return;
378 }
379 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 351 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
380 "Publishing %llu bytes\n", 352 "Publishing %llu bytes\n", (unsigned long long) FILESIZE);
381 (unsigned long long) FILESIZE);
382 if (NULL != strstr (progname, "index")) 353 if (NULL != strstr (progname, "index"))
383 do_index = GNUNET_YES; 354 do_index = GNUNET_YES;
384 else 355 else
@@ -387,60 +358,50 @@ do_publish1 (void *cls,
387 anonymity = 0; 358 anonymity = 0;
388 else 359 else
389 anonymity = 1; 360 anonymity = 1;
390 361
391 GNUNET_FS_TEST_publish (daemons[NUM_DAEMONS-1], 362 GNUNET_FS_TEST_publish (daemons[NUM_DAEMONS - 1],
392 TIMEOUT, 363 TIMEOUT,
393 anonymity, 364 anonymity,
394 do_index, FILESIZE, SEED1, 365 do_index, FILESIZE, SEED1,
395 VERBOSE, 366 VERBOSE, &do_publish2, NULL);
396 &do_publish2, NULL);
397} 367}
398 368
399 369
400static void 370static void
401do_connect (void *cls, 371do_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
402 const struct GNUNET_SCHEDULER_TaskContext *tc)
403{ 372{
404 struct GNUNET_TESTING_PeerGroup *pg; 373 struct GNUNET_TESTING_PeerGroup *pg;
405 374
406 GNUNET_assert (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE)); 375 GNUNET_assert (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE));
407 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 376 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
408 "Daemons started, will now try to connect them\n"); 377 "Daemons started, will now try to connect them\n");
409 pg = GNUNET_FS_TEST_get_group (daemons); 378 pg = GNUNET_FS_TEST_get_group (daemons);
410 GNUNET_TESTING_create_topology (pg, 379 GNUNET_TESTING_create_topology (pg,
411 GNUNET_TESTING_TOPOLOGY_CLIQUE, 380 GNUNET_TESTING_TOPOLOGY_CLIQUE,
412 GNUNET_TESTING_TOPOLOGY_NONE, 381 GNUNET_TESTING_TOPOLOGY_NONE, NULL);
413 NULL);
414 GNUNET_TESTING_connect_topology (pg, 382 GNUNET_TESTING_connect_topology (pg,
415 GNUNET_TESTING_TOPOLOGY_CLIQUE, 383 GNUNET_TESTING_TOPOLOGY_CLIQUE,
416 GNUNET_TESTING_TOPOLOGY_OPTION_NONE, 384 GNUNET_TESTING_TOPOLOGY_OPTION_NONE,
417 0.0, 385 0.0,
418 TIMEOUT, 386 TIMEOUT, NUM_DAEMONS, &do_publish1, NULL);
419 NUM_DAEMONS,
420 &do_publish1,
421 NULL);
422} 387}
423 388
424 389
425static void 390static void
426run (void *cls, 391run (void *cls,
427 char *const *args, 392 char *const *args,
428 const char *cfgfile, 393 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
429 const struct GNUNET_CONFIGURATION_Handle *cfg)
430{ 394{
431 GNUNET_FS_TEST_daemons_start ("fs_test_lib_data.conf", 395 GNUNET_FS_TEST_daemons_start ("fs_test_lib_data.conf",
432 TIMEOUT, 396 TIMEOUT,
433 NUM_DAEMONS, 397 NUM_DAEMONS, daemons, &do_connect, NULL);
434 daemons,
435 &do_connect,
436 NULL);
437} 398}
438 399
439 400
440int 401int
441main (int argc, char *argv[]) 402main (int argc, char *argv[])
442{ 403{
443 char *const argvx[] = { 404 char *const argvx[] = {
444 "perf-gnunet-service-fs-p2p", 405 "perf-gnunet-service-fs-p2p",
445 "-c", 406 "-c",
446 "fs_test_lib_data.conf", 407 "fs_test_lib_data.conf",
@@ -454,16 +415,16 @@ main (int argc, char *argv[])
454 }; 415 };
455 progname = argv[0]; 416 progname = argv[0];
456 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/"); 417 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/");
457 GNUNET_log_setup ("perf_gnunet_service_fs_p2p_trust", 418 GNUNET_log_setup ("perf_gnunet_service_fs_p2p_trust",
458#if VERBOSE 419#if VERBOSE
459 "DEBUG", 420 "DEBUG",
460#else 421#else
461 "WARNING", 422 "WARNING",
462#endif 423#endif
463 NULL); 424 NULL);
464 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, 425 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
465 argvx, "perf-gnunet-service-fs-p2p-trust", 426 argvx, "perf-gnunet-service-fs-p2p-trust",
466 "nohelp", options, &run, NULL); 427 "nohelp", options, &run, NULL);
467 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/"); 428 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/");
468 return ok; 429 return ok;
469} 430}
diff --git a/src/fs/test_fs.c b/src/fs/test_fs.c
index 41a155407..b936c3199 100644
--- a/src/fs/test_fs.c
+++ b/src/fs/test_fs.c
@@ -37,9 +37,8 @@ makeName (unsigned int i)
37{ 37{
38 char *fn; 38 char *fn;
39 39
40 fn = 40 fn = GNUNET_malloc (strlen ("/tmp/gnunet-basic_fsui_test/BASIC_FSUI_TEST") +
41 GNUNET_malloc (strlen ("/tmp/gnunet-basic_fsui_test/BASIC_FSUI_TEST") + 41 14);
42 14);
43 GNUNET_snprintf (fn, 42 GNUNET_snprintf (fn,
44 strlen ("/tmp/gnunet-basic_fsui_test/BASIC_FSUI_TEST") + 43 strlen ("/tmp/gnunet-basic_fsui_test/BASIC_FSUI_TEST") +
45 14, "/tmp/gnunet-basic_fsui_test/BASIC_FSUI_TEST%u", i); 44 14, "/tmp/gnunet-basic_fsui_test/BASIC_FSUI_TEST%u", i);
@@ -61,39 +60,37 @@ eventCallback (void *cls, const GNUNET_FSUI_Event * event)
61 static char unused; 60 static char unused;
62 61
63 switch (event->type) 62 switch (event->type)
64 { 63 {
65 case GNUNET_FSUI_search_resumed: 64 case GNUNET_FSUI_search_resumed:
66 case GNUNET_FSUI_download_resumed: 65 case GNUNET_FSUI_download_resumed:
67 case GNUNET_FSUI_upload_resumed: 66 case GNUNET_FSUI_upload_resumed:
68 case GNUNET_FSUI_unindex_resumed: 67 case GNUNET_FSUI_unindex_resumed:
69 return &unused; 68 return &unused;
70 case GNUNET_FSUI_search_result: 69 case GNUNET_FSUI_search_result:
71#if DEBUG_VERBOSE 70#if DEBUG_VERBOSE
72 printf ("Received search result\n"); 71 printf ("Received search result\n");
73#endif 72#endif
74 search_uri = 73 search_uri = GNUNET_ECRS_uri_duplicate (event->data.SearchResult.fi.uri);
75 GNUNET_ECRS_uri_duplicate (event->data.SearchResult.fi.uri); 74 search_meta = GNUNET_meta_data_duplicate (event->data.SearchResult.fi.meta);
76 search_meta = 75 break;
77 GNUNET_meta_data_duplicate (event->data.SearchResult.fi.meta); 76 case GNUNET_FSUI_upload_completed:
78 break;
79 case GNUNET_FSUI_upload_completed:
80#if DEBUG_VERBOSE 77#if DEBUG_VERBOSE
81 printf ("Upload complete.\n"); 78 printf ("Upload complete.\n");
82#endif 79#endif
83 break; 80 break;
84 case GNUNET_FSUI_download_completed: 81 case GNUNET_FSUI_download_completed:
85#if DEBUG_VERBOSE 82#if DEBUG_VERBOSE
86 printf ("Download complete.\n"); 83 printf ("Download complete.\n");
87#endif 84#endif
88 break; 85 break;
89 case GNUNET_FSUI_unindex_completed: 86 case GNUNET_FSUI_unindex_completed:
90#if DEBUG_VERBOSE 87#if DEBUG_VERBOSE
91 printf ("Unindex complete.\n"); 88 printf ("Unindex complete.\n");
92#endif 89#endif
93 break; 90 break;
94 default: 91 default:
95 break; 92 break;
96 } 93 }
97 lastEvent = event->type; 94 lastEvent = event->type;
98 return NULL; 95 return NULL;
99} 96}
@@ -109,6 +106,7 @@ main (int argc, char *argv[])
109 int ok; 106 int ok;
110 struct GNUNET_ECRS_URI *uri; 107 struct GNUNET_ECRS_URI *uri;
111 char *filename = NULL; 108 char *filename = NULL;
109
112 char *keywords[] = { 110 char *keywords[] = {
113 "fsui_foo", 111 "fsui_foo",
114 "fsui_bar", 112 "fsui_bar",
@@ -126,16 +124,15 @@ main (int argc, char *argv[])
126 124
127 cfg = GNUNET_GC_create (); 125 cfg = GNUNET_GC_create ();
128 if (-1 == GNUNET_GC_parse_configuration (cfg, "check.conf")) 126 if (-1 == GNUNET_GC_parse_configuration (cfg, "check.conf"))
129 { 127 {
130 GNUNET_GC_free (cfg); 128 GNUNET_GC_free (cfg);
131 return -1; 129 return -1;
132 } 130 }
133#if START_DAEMON 131#if START_DAEMON
134 daemon = GNUNET_daemon_start (NULL, cfg, "peer.conf", GNUNET_NO); 132 daemon = GNUNET_daemon_start (NULL, cfg, "peer.conf", GNUNET_NO);
135 GNUNET_GE_ASSERT (NULL, daemon != NULL); 133 GNUNET_GE_ASSERT (NULL, daemon != NULL);
136 CHECK (GNUNET_OK == 134 CHECK (GNUNET_OK ==
137 GNUNET_wait_for_daemon_running (NULL, cfg, 135 GNUNET_wait_for_daemon_running (NULL, cfg, 60 * GNUNET_CRON_SECONDS));
138 60 * GNUNET_CRON_SECONDS));
139#endif 136#endif
140 GNUNET_thread_sleep (5 * GNUNET_CRON_SECONDS); /* give apps time to start */ 137 GNUNET_thread_sleep (5 * GNUNET_CRON_SECONDS); /* give apps time to start */
141 ok = GNUNET_YES; 138 ok = GNUNET_YES;
@@ -151,8 +148,8 @@ main (int argc, char *argv[])
151 "foo bar test!", strlen ("foo bar test!"), "600"); 148 "foo bar test!", strlen ("foo bar test!"), "600");
152 meta = GNUNET_meta_data_create (); 149 meta = GNUNET_meta_data_create ();
153 kuri = 150 kuri =
154 GNUNET_ECRS_keyword_command_line_to_uri (NULL, 2, 151 GNUNET_ECRS_keyword_command_line_to_uri (NULL, 2,
155 (const char **) keywords); 152 (const char **) keywords);
156 /* upload */ 153 /* upload */
157 upload = GNUNET_FSUI_upload_start (ctx, filename, (GNUNET_FSUI_DirectoryScanCallback) & GNUNET_disk_directory_scan, NULL, 0, /* anonymity */ 154 upload = GNUNET_FSUI_upload_start (ctx, filename, (GNUNET_FSUI_DirectoryScanCallback) & GNUNET_disk_directory_scan, NULL, 0, /* anonymity */
158 0, /* priority */ 155 0, /* priority */
@@ -166,13 +163,12 @@ main (int argc, char *argv[])
166 GNUNET_meta_data_destroy (meta); 163 GNUNET_meta_data_destroy (meta);
167 prog = 0; 164 prog = 0;
168 while (lastEvent != GNUNET_FSUI_upload_completed) 165 while (lastEvent != GNUNET_FSUI_upload_completed)
169 { 166 {
170 prog++; 167 prog++;
171 CHECK (prog < 168 CHECK (prog < 10000) GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
172 10000) GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS); 169 if (GNUNET_shutdown_test () == GNUNET_YES)
173 if (GNUNET_shutdown_test () == GNUNET_YES) 170 break;
174 break; 171 }
175 }
176 172
177 /* search */ 173 /* search */
178 GNUNET_snprintf (keyword, 40, "+%s +%s", keywords[0], keywords[1]); 174 GNUNET_snprintf (keyword, 40, "+%s +%s", keywords[0], keywords[1]);
@@ -182,13 +178,13 @@ main (int argc, char *argv[])
182 CHECK (search != NULL); 178 CHECK (search != NULL);
183 prog = 0; 179 prog = 0;
184 while (lastEvent != GNUNET_FSUI_search_result) 180 while (lastEvent != GNUNET_FSUI_search_result)
185 { 181 {
186 prog++; 182 prog++;
187 CHECK (prog < 10000); 183 CHECK (prog < 10000);
188 GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS); 184 GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
189 if (GNUNET_shutdown_test () == GNUNET_YES) 185 if (GNUNET_shutdown_test () == GNUNET_YES)
190 break; 186 break;
191 } 187 }
192 GNUNET_FSUI_search_abort (search); 188 GNUNET_FSUI_search_abort (search);
193 GNUNET_FSUI_search_stop (search); 189 GNUNET_FSUI_search_stop (search);
194 190
@@ -202,13 +198,13 @@ main (int argc, char *argv[])
202 GNUNET_free (fn); 198 GNUNET_free (fn);
203 prog = 0; 199 prog = 0;
204 while (lastEvent != GNUNET_FSUI_download_completed) 200 while (lastEvent != GNUNET_FSUI_download_completed)
205 { 201 {
206 prog++; 202 prog++;
207 CHECK (prog < 10000); 203 CHECK (prog < 10000);
208 GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS); 204 GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
209 if (GNUNET_shutdown_test () == GNUNET_YES) 205 if (GNUNET_shutdown_test () == GNUNET_YES)
210 break; 206 break;
211 } 207 }
212 GNUNET_FSUI_download_stop (download); 208 GNUNET_FSUI_download_stop (download);
213 download = NULL; 209 download = NULL;
214 GNUNET_ECRS_uri_destroy (search_uri); 210 GNUNET_ECRS_uri_destroy (search_uri);
@@ -217,13 +213,13 @@ main (int argc, char *argv[])
217 unindex = GNUNET_FSUI_unindex_start (ctx, filename); 213 unindex = GNUNET_FSUI_unindex_start (ctx, filename);
218 prog = 0; 214 prog = 0;
219 while (lastEvent != GNUNET_FSUI_unindex_completed) 215 while (lastEvent != GNUNET_FSUI_unindex_completed)
220 { 216 {
221 prog++; 217 prog++;
222 CHECK (prog < 10000); 218 CHECK (prog < 10000);
223 GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS); 219 GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
224 if (GNUNET_shutdown_test () == GNUNET_YES) 220 if (GNUNET_shutdown_test () == GNUNET_YES)
225 break; 221 break;
226 } 222 }
227 if (lastEvent != GNUNET_FSUI_unindex_completed) 223 if (lastEvent != GNUNET_FSUI_unindex_completed)
228 GNUNET_FSUI_unindex_abort (unindex); 224 GNUNET_FSUI_unindex_abort (unindex);
229 GNUNET_FSUI_unindex_stop (unindex); 225 GNUNET_FSUI_unindex_stop (unindex);
@@ -234,15 +230,15 @@ FAILURE:
234 if (ctx != NULL) 230 if (ctx != NULL)
235 GNUNET_FSUI_stop (ctx); 231 GNUNET_FSUI_stop (ctx);
236 if (filename != NULL) 232 if (filename != NULL)
237 { 233 {
238 UNLINK (filename); 234 UNLINK (filename);
239 GNUNET_free (filename); 235 GNUNET_free (filename);
240 } 236 }
241 if (download != NULL) 237 if (download != NULL)
242 { 238 {
243 GNUNET_FSUI_download_abort (download); 239 GNUNET_FSUI_download_abort (download);
244 GNUNET_FSUI_download_stop (download); 240 GNUNET_FSUI_download_stop (download);
245 } 241 }
246 filename = makeName (43); 242 filename = makeName (43);
247 /* TODO: verify file 'filename(42)' == file 'filename(43)' */ 243 /* TODO: verify file 'filename(42)' == file 'filename(43)' */
248 UNLINK (filename); 244 UNLINK (filename);
diff --git a/src/fs/test_fs_directory.c b/src/fs/test_fs_directory.c
index b32628b73..d8a9c63b6 100644
--- a/src/fs/test_fs_directory.c
+++ b/src/fs/test_fs_directory.c
@@ -42,27 +42,26 @@ struct PCLS
42 42
43static void 43static void
44processor (void *cls, 44processor (void *cls,
45 const char *filename, 45 const char *filename,
46 const struct GNUNET_FS_Uri *uri, 46 const struct GNUNET_FS_Uri *uri,
47 const struct GNUNET_CONTAINER_MetaData *md, 47 const struct GNUNET_CONTAINER_MetaData *md,
48 size_t length, 48 size_t length, const void *data)
49 const void *data)
50{ 49{
51 struct PCLS *p = cls; 50 struct PCLS *p = cls;
52 int i; 51 int i;
53 52
54 if (NULL == uri) 53 if (NULL == uri)
55 return; /* ignore directory's meta data */ 54 return; /* ignore directory's meta data */
56 for (i = 0; i < p->max; i++) 55 for (i = 0; i < p->max; i++)
56 {
57 if (GNUNET_CONTAINER_meta_data_test_equal (p->md[i],
58 md) &&
59 GNUNET_FS_uri_test_equal (p->uri[i], uri))
57 { 60 {
58 if (GNUNET_CONTAINER_meta_data_test_equal (p->md[i], 61 p->pos++;
59 md) && 62 return;
60 GNUNET_FS_uri_test_equal (p->uri[i], uri))
61 {
62 p->pos++;
63 return;
64 }
65 } 63 }
64 }
66 fprintf (stderr, "Error at %s:%d\n", __FILE__, __LINE__); 65 fprintf (stderr, "Error at %s:%d\n", __FILE__, __LINE__);
67} 66}
68 67
@@ -86,89 +85,81 @@ testDirectory (unsigned int i)
86 char *s; 85 char *s;
87 86
88 cls.max = i; 87 cls.max = i;
89 uris = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri*) * i); 88 uris = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri *) * i);
90 mds = GNUNET_malloc (sizeof (struct GNUNET_CONTAINER_MetaData*) * i); 89 mds = GNUNET_malloc (sizeof (struct GNUNET_CONTAINER_MetaData *) * i);
91 meta = GNUNET_CONTAINER_meta_data_create (); 90 meta = GNUNET_CONTAINER_meta_data_create ();
92 GNUNET_CONTAINER_meta_data_insert (meta, 91 GNUNET_CONTAINER_meta_data_insert (meta,
93 "<test>", 92 "<test>",
94 EXTRACTOR_METATYPE_TITLE, 93 EXTRACTOR_METATYPE_TITLE,
95 EXTRACTOR_METAFORMAT_UTF8, 94 EXTRACTOR_METAFORMAT_UTF8,
96 "text/plain", 95 "text/plain",
97 "A title", 96 "A title", strlen ("A title") + 1);
98 strlen("A title")+1); 97 GNUNET_CONTAINER_meta_data_insert (meta,
99 GNUNET_CONTAINER_meta_data_insert (meta, 98 "<test>",
100 "<test>", 99 EXTRACTOR_METATYPE_AUTHOR_NAME,
101 EXTRACTOR_METATYPE_AUTHOR_NAME, 100 EXTRACTOR_METAFORMAT_UTF8,
102 EXTRACTOR_METAFORMAT_UTF8, 101 "text/plain",
103 "text/plain", 102 "An author", strlen ("An author") + 1);
104 "An author",
105 strlen ("An author")+1);
106 for (p = 0; p < i; p++) 103 for (p = 0; p < i; p++)
104 {
105 mds[p] = GNUNET_CONTAINER_meta_data_create ();
106 for (q = 0; q <= p; q++)
107 { 107 {
108 mds[p] = GNUNET_CONTAINER_meta_data_create (); 108 GNUNET_snprintf (txt, sizeof (txt), "%u -- %u\n", p, q);
109 for (q = 0; q <= p; q++) 109 GNUNET_CONTAINER_meta_data_insert (mds[p],
110 { 110 "<test>",
111 GNUNET_snprintf (txt, sizeof(txt), "%u -- %u\n", p, q); 111 q % EXTRACTOR_metatype_get_max (),
112 GNUNET_CONTAINER_meta_data_insert (mds[p], 112 EXTRACTOR_METAFORMAT_UTF8,
113 "<test>", 113 "text/plain", txt, strlen (txt) + 1);
114 q % EXTRACTOR_metatype_get_max (),
115 EXTRACTOR_METAFORMAT_UTF8,
116 "text/plain",
117 txt,
118 strlen(txt)+1);
119 }
120 GNUNET_snprintf (uri,
121 sizeof(uri),
122 "gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.%u",
123 p);
124 emsg = NULL;
125 uris[p] = GNUNET_FS_uri_parse (uri, &emsg);
126 if (uris[p] == NULL)
127 {
128 GNUNET_CONTAINER_meta_data_destroy (mds[p]);
129 while (--p > 0)
130 {
131 GNUNET_CONTAINER_meta_data_destroy (mds[p]);
132 GNUNET_FS_uri_destroy (uris[p]);
133 }
134 GNUNET_free (mds);
135 GNUNET_free (uris);
136 GNUNET_free (emsg);
137 GNUNET_CONTAINER_meta_data_destroy (meta);
138 ABORT (); /* error in testcase */
139 }
140 GNUNET_assert (emsg == NULL);
141 } 114 }
115 GNUNET_snprintf (uri,
116 sizeof (uri),
117 "gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.%u",
118 p);
119 emsg = NULL;
120 uris[p] = GNUNET_FS_uri_parse (uri, &emsg);
121 if (uris[p] == NULL)
122 {
123 GNUNET_CONTAINER_meta_data_destroy (mds[p]);
124 while (--p > 0)
125 {
126 GNUNET_CONTAINER_meta_data_destroy (mds[p]);
127 GNUNET_FS_uri_destroy (uris[p]);
128 }
129 GNUNET_free (mds);
130 GNUNET_free (uris);
131 GNUNET_free (emsg);
132 GNUNET_CONTAINER_meta_data_destroy (meta);
133 ABORT (); /* error in testcase */
134 }
135 GNUNET_assert (emsg == NULL);
136 }
142 start = GNUNET_TIME_absolute_get (); 137 start = GNUNET_TIME_absolute_get ();
143 db = GNUNET_FS_directory_builder_create (meta); 138 db = GNUNET_FS_directory_builder_create (meta);
144 for (p = 0; p < i; p++) 139 for (p = 0; p < i; p++)
145 GNUNET_FS_directory_builder_add (db, uris[p], mds[p], NULL); 140 GNUNET_FS_directory_builder_add (db, uris[p], mds[p], NULL);
146 GNUNET_FS_directory_builder_finish (db, 141 GNUNET_FS_directory_builder_finish (db, &dlen, (void **) &data);
147 &dlen, 142 s = GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration
148 (void**) &data); 143 (start));
149 s = GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start));
150 fprintf (stdout, 144 fprintf (stdout,
151 "Creating directory with %u entires and total size %llu took %s\n", 145 "Creating directory with %u entires and total size %llu took %s\n",
152 i, 146 i, (unsigned long long) dlen, s);
153 (unsigned long long) dlen,
154 s);
155 GNUNET_free (s); 147 GNUNET_free (s);
156 if (i < 100) 148 if (i < 100)
157 { 149 {
158 cls.pos = 0; 150 cls.pos = 0;
159 cls.uri = uris; 151 cls.uri = uris;
160 cls.md = mds; 152 cls.md = mds;
161 GNUNET_FS_directory_list_contents (dlen, data, 0, 153 GNUNET_FS_directory_list_contents (dlen, data, 0, &processor, &cls);
162 &processor, &cls); 154 GNUNET_assert (cls.pos == i);
163 GNUNET_assert (cls.pos == i); 155 }
164 }
165 GNUNET_free (data); 156 GNUNET_free (data);
166 GNUNET_CONTAINER_meta_data_destroy (meta); 157 GNUNET_CONTAINER_meta_data_destroy (meta);
167 for (p = 0; p < i; p++) 158 for (p = 0; p < i; p++)
168 { 159 {
169 GNUNET_CONTAINER_meta_data_destroy (mds[p]); 160 GNUNET_CONTAINER_meta_data_destroy (mds[p]);
170 GNUNET_FS_uri_destroy (uris[p]); 161 GNUNET_FS_uri_destroy (uris[p]);
171 } 162 }
172 GNUNET_free (uris); 163 GNUNET_free (uris);
173 GNUNET_free (mds); 164 GNUNET_free (mds);
174 return ret; 165 return ret;
@@ -181,15 +172,15 @@ main (int argc, char *argv[])
181 int failureCount = 0; 172 int failureCount = 0;
182 int i; 173 int i;
183 174
184 GNUNET_log_setup ("test_fs_directory", 175 GNUNET_log_setup ("test_fs_directory",
185#if VERBOSE 176#if VERBOSE
186 "DEBUG", 177 "DEBUG",
187#else 178#else
188 "WARNING", 179 "WARNING",
189#endif 180#endif
190 NULL); 181 NULL);
191 for (i = 17; i < 1000; i *= 2) 182 for (i = 17; i < 1000; i *= 2)
192 failureCount += testDirectory (i); 183 failureCount += testDirectory (i);
193 if (failureCount != 0) 184 if (failureCount != 0)
194 return 1; 185 return 1;
195 return 0; 186 return 0;
diff --git a/src/fs/test_fs_download.c b/src/fs/test_fs_download.c
index 6bc287da3..d37b94c03 100644
--- a/src/fs/test_fs_download.c
+++ b/src/fs/test_fs_download.c
@@ -46,7 +46,7 @@
46 46
47/** 47/**
48 * How long should our test-content live? 48 * How long should our test-content live?
49 */ 49 */
50#define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) 50#define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)
51 51
52struct PeerContext 52struct PeerContext
@@ -74,57 +74,52 @@ static char *fn;
74static int err; 74static int err;
75 75
76static void 76static void
77timeout_kill_task (void *cls, 77timeout_kill_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
78 const struct GNUNET_SCHEDULER_TaskContext *tc)
79{ 78{
80 if (download != NULL) 79 if (download != NULL)
81 { 80 {
82 GNUNET_FS_download_stop (download, GNUNET_YES); 81 GNUNET_FS_download_stop (download, GNUNET_YES);
83 download = NULL; 82 download = NULL;
84 } 83 }
85 else if (publish != NULL) 84 else if (publish != NULL)
86 { 85 {
87 GNUNET_FS_publish_stop (publish); 86 GNUNET_FS_publish_stop (publish);
88 publish = NULL; 87 publish = NULL;
89 } 88 }
90 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 89 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Timeout downloading file\n");
91 "Timeout downloading file\n");
92 timeout_kill = GNUNET_SCHEDULER_NO_TASK; 90 timeout_kill = GNUNET_SCHEDULER_NO_TASK;
93 err = 1; 91 err = 1;
94} 92}
95 93
96static void 94static void
97abort_publish_task (void *cls, 95abort_publish_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
98 const struct GNUNET_SCHEDULER_TaskContext *tc)
99{ 96{
100 if (publish != NULL) 97 if (publish != NULL)
101 { 98 {
102 GNUNET_FS_publish_stop (publish); 99 GNUNET_FS_publish_stop (publish);
103 publish = NULL; 100 publish = NULL;
104 } 101 }
105} 102}
106 103
107static void 104static void
108stop_fs_task (void *cls, 105stop_fs_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
109 const struct GNUNET_SCHEDULER_TaskContext *tc)
110{ 106{
111 GNUNET_FS_stop (fs); 107 GNUNET_FS_stop (fs);
112 fs = NULL; 108 fs = NULL;
113} 109}
114 110
115static void 111static void
116abort_download_task (void *cls, 112abort_download_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
117 const struct GNUNET_SCHEDULER_TaskContext *tc)
118{ 113{
119 uint64_t size; 114 uint64_t size;
120 115
121 if (download != NULL) 116 if (download != NULL)
122 { 117 {
123 GNUNET_FS_download_stop (download, GNUNET_YES); 118 GNUNET_FS_download_stop (download, GNUNET_YES);
124 download = NULL; 119 download = NULL;
125 } 120 }
126 GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_size (fn, &size, GNUNET_YES)); 121 GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_size (fn, &size, GNUNET_YES));
127 GNUNET_assert (size == FILESIZE); 122 GNUNET_assert (size == FILESIZE);
128 GNUNET_DISK_directory_remove (fn); 123 GNUNET_DISK_directory_remove (fn);
129 GNUNET_free (fn); 124 GNUNET_free (fn);
130 fn = NULL; 125 fn = NULL;
@@ -134,115 +129,116 @@ abort_download_task (void *cls,
134 129
135 130
136static void * 131static void *
137progress_cb (void *cls, 132progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
138 const struct GNUNET_FS_ProgressInfo *event)
139{ 133{
140 134
141 switch (event->status) 135 switch (event->status)
142 { 136 {
143 case GNUNET_FS_STATUS_PUBLISH_PROGRESS: 137 case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
144#if VERBOSE 138#if VERBOSE
145 printf ("Publish is progressing (%llu/%llu at level %u off %llu)...\n", 139 printf ("Publish is progressing (%llu/%llu at level %u off %llu)...\n",
146 (unsigned long long) event->value.publish.completed, 140 (unsigned long long) event->value.publish.completed,
147 (unsigned long long) event->value.publish.size, 141 (unsigned long long) event->value.publish.size,
148 event->value.publish.specifics.progress.depth, 142 event->value.publish.specifics.progress.depth,
149 (unsigned long long) event->value.publish.specifics.progress.offset); 143 (unsigned long long) event->value.publish.specifics.
150#endif 144 progress.offset);
151 break; 145#endif
152 case GNUNET_FS_STATUS_PUBLISH_COMPLETED: 146 break;
153 printf ("Publishing complete, %llu kb/s.\n", 147 case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
154 (unsigned long long) (FILESIZE * 1000LL / (1+GNUNET_TIME_absolute_get_duration (start).rel_value) / 1024LL)); 148 printf ("Publishing complete, %llu kb/s.\n",
155 GAUGER ("FS", 149 (unsigned long long) (FILESIZE * 1000LL /
156 "Publishing speed (insertion)", 150 (1 +
157 (unsigned long long) (FILESIZE * 1000LL / (1+GNUNET_TIME_absolute_get_duration (start).rel_value) / 1024LL), 151 GNUNET_TIME_absolute_get_duration
158 "kb/s"); 152 (start).rel_value) / 1024LL));
159 fn = GNUNET_DISK_mktemp ("gnunet-download-test-dst"); 153 GAUGER ("FS", "Publishing speed (insertion)",
160 start = GNUNET_TIME_absolute_get (); 154 (unsigned long long) (FILESIZE * 1000LL /
161 download = GNUNET_FS_download_start (fs, 155 (1 +
162 event->value.publish.specifics.completed.chk_uri, 156 GNUNET_TIME_absolute_get_duration
163 NULL, 157 (start).rel_value) / 1024LL), "kb/s");
164 fn, NULL, 158 fn = GNUNET_DISK_mktemp ("gnunet-download-test-dst");
165 0, 159 start = GNUNET_TIME_absolute_get ();
166 FILESIZE, 160 download = GNUNET_FS_download_start (fs,
167 1, 161 event->value.publish.
168 GNUNET_FS_DOWNLOAD_OPTION_NONE, 162 specifics.completed.chk_uri, NULL, fn,
169 "download", 163 NULL, 0, FILESIZE, 1,
170 NULL); 164 GNUNET_FS_DOWNLOAD_OPTION_NONE,
171 GNUNET_assert (download != NULL); 165 "download", NULL);
172 break; 166 GNUNET_assert (download != NULL);
173 case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: 167 break;
174 printf ("Download complete, %llu kb/s.\n", 168 case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED:
175 (unsigned long long) (FILESIZE * 1000LL / (1+GNUNET_TIME_absolute_get_duration (start).rel_value) / 1024LL)); 169 printf ("Download complete, %llu kb/s.\n",
176 GAUGER ("FS", 170 (unsigned long long) (FILESIZE * 1000LL /
177 "Local download speed (inserted)", 171 (1 +
178 (unsigned long long) (FILESIZE * 1000LL / (1+GNUNET_TIME_absolute_get_duration (start).rel_value) / 1024LL), 172 GNUNET_TIME_absolute_get_duration
179 "kb/s"); 173 (start).rel_value) / 1024LL));
180 GNUNET_SCHEDULER_add_now (&abort_download_task, 174 GAUGER ("FS", "Local download speed (inserted)",
181 NULL); 175 (unsigned long long) (FILESIZE * 1000LL /
182 break; 176 (1 +
183 case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: 177 GNUNET_TIME_absolute_get_duration
184 GNUNET_assert (download == event->value.download.dc); 178 (start).rel_value) / 1024LL), "kb/s");
179 GNUNET_SCHEDULER_add_now (&abort_download_task, NULL);
180 break;
181 case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS:
182 GNUNET_assert (download == event->value.download.dc);
185#if VERBOSE 183#if VERBOSE
186 printf ("Download is progressing (%llu/%llu at level %u off %llu)...\n", 184 printf ("Download is progressing (%llu/%llu at level %u off %llu)...\n",
187 (unsigned long long) event->value.download.completed, 185 (unsigned long long) event->value.download.completed,
188 (unsigned long long) event->value.download.size, 186 (unsigned long long) event->value.download.size,
189 event->value.download.specifics.progress.depth, 187 event->value.download.specifics.progress.depth,
190 (unsigned long long) event->value.download.specifics.progress.offset); 188 (unsigned long long) event->value.download.specifics.
189 progress.offset);
191#endif 190#endif
192 break; 191 break;
193 case GNUNET_FS_STATUS_PUBLISH_ERROR: 192 case GNUNET_FS_STATUS_PUBLISH_ERROR:
194 fprintf (stderr, 193 fprintf (stderr,
195 "Error publishing file: %s\n", 194 "Error publishing file: %s\n",
196 event->value.publish.specifics.error.message); 195 event->value.publish.specifics.error.message);
197 GNUNET_break (0); 196 GNUNET_break (0);
198 GNUNET_SCHEDULER_add_continuation (&abort_publish_task, 197 GNUNET_SCHEDULER_add_continuation (&abort_publish_task,
199 NULL, 198 NULL,
200 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 199 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
201 break; 200 break;
202 case GNUNET_FS_STATUS_DOWNLOAD_ERROR: 201 case GNUNET_FS_STATUS_DOWNLOAD_ERROR:
203 fprintf (stderr, 202 fprintf (stderr,
204 "Error downloading file: %s\n", 203 "Error downloading file: %s\n",
205 event->value.download.specifics.error.message); 204 event->value.download.specifics.error.message);
206 GNUNET_SCHEDULER_add_now (&abort_download_task, 205 GNUNET_SCHEDULER_add_now (&abort_download_task, NULL);
207 NULL); 206 break;
208 break; 207 case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE:
209 case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE: 208 case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE:
210 case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE: 209 break;
211 break; 210 case GNUNET_FS_STATUS_PUBLISH_START:
212 case GNUNET_FS_STATUS_PUBLISH_START: 211 GNUNET_assert (0 == strcmp ("publish-context", event->value.publish.cctx));
213 GNUNET_assert (0 == strcmp ("publish-context", event->value.publish.cctx)); 212 GNUNET_assert (NULL == event->value.publish.pctx);
214 GNUNET_assert (NULL == event->value.publish.pctx); 213 GNUNET_assert (FILESIZE == event->value.publish.size);
215 GNUNET_assert (FILESIZE == event->value.publish.size); 214 GNUNET_assert (0 == event->value.publish.completed);
216 GNUNET_assert (0 == event->value.publish.completed); 215 GNUNET_assert (1 == event->value.publish.anonymity);
217 GNUNET_assert (1 == event->value.publish.anonymity); 216 break;
218 break; 217 case GNUNET_FS_STATUS_PUBLISH_STOPPED:
219 case GNUNET_FS_STATUS_PUBLISH_STOPPED: 218 GNUNET_assert (publish == event->value.publish.pc);
220 GNUNET_assert (publish == event->value.publish.pc); 219 GNUNET_assert (FILESIZE == event->value.publish.size);
221 GNUNET_assert (FILESIZE == event->value.publish.size); 220 GNUNET_assert (1 == event->value.publish.anonymity);
222 GNUNET_assert (1 == event->value.publish.anonymity); 221 GNUNET_SCHEDULER_add_now (&stop_fs_task, NULL);
223 GNUNET_SCHEDULER_add_now (&stop_fs_task, 222 break;
224 NULL); 223 case GNUNET_FS_STATUS_DOWNLOAD_START:
225 break; 224 GNUNET_assert (0 == strcmp ("download", event->value.download.cctx));
226 case GNUNET_FS_STATUS_DOWNLOAD_START: 225 GNUNET_assert (NULL == event->value.download.pctx);
227 GNUNET_assert (0 == strcmp ("download", event->value.download.cctx)); 226 GNUNET_assert (NULL != event->value.download.uri);
228 GNUNET_assert (NULL == event->value.download.pctx); 227 GNUNET_assert (0 == strcmp (fn, event->value.download.filename));
229 GNUNET_assert (NULL != event->value.download.uri); 228 GNUNET_assert (FILESIZE == event->value.download.size);
230 GNUNET_assert (0 == strcmp (fn, event->value.download.filename)); 229 GNUNET_assert (0 == event->value.download.completed);
231 GNUNET_assert (FILESIZE == event->value.download.size); 230 GNUNET_assert (1 == event->value.download.anonymity);
232 GNUNET_assert (0 == event->value.download.completed); 231 break;
233 GNUNET_assert (1 == event->value.download.anonymity); 232 case GNUNET_FS_STATUS_DOWNLOAD_STOPPED:
234 break; 233 GNUNET_assert (download == event->value.download.dc);
235 case GNUNET_FS_STATUS_DOWNLOAD_STOPPED: 234 GNUNET_SCHEDULER_add_continuation (&abort_publish_task,
236 GNUNET_assert (download == event->value.download.dc); 235 NULL,
237 GNUNET_SCHEDULER_add_continuation (&abort_publish_task, 236 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
238 NULL, 237 break;
239 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 238 default:
240 break; 239 printf ("Unexpected event: %d\n", event->status);
241 default: 240 break;
242 printf ("Unexpected event: %d\n", 241 }
243 event->status);
244 break;
245 }
246 return NULL; 242 return NULL;
247} 243}
248 244
@@ -253,11 +249,11 @@ setup_peer (struct PeerContext *p, const char *cfgname)
253 p->cfg = GNUNET_CONFIGURATION_create (); 249 p->cfg = GNUNET_CONFIGURATION_create ();
254#if START_ARM 250#if START_ARM
255 p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", 251 p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
256 "gnunet-service-arm", 252 "gnunet-service-arm",
257#if VERBOSE 253#if VERBOSE
258 "-L", "DEBUG", 254 "-L", "DEBUG",
259#endif 255#endif
260 "-c", cfgname, NULL); 256 "-c", cfgname, NULL);
261#endif 257#endif
262 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); 258 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
263} 259}
@@ -268,16 +264,17 @@ stop_arm (struct PeerContext *p)
268{ 264{
269#if START_ARM 265#if START_ARM
270 if (NULL != p->arm_proc) 266 if (NULL != p->arm_proc)
271 { 267 {
272 if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) 268 if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
273 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 269 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
274 if (GNUNET_OS_process_wait(p->arm_proc) != GNUNET_OK) 270 if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
275 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); 271 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
276 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 272 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
277 "ARM process %u stopped\n", GNUNET_OS_process_get_pid (p->arm_proc)); 273 "ARM process %u stopped\n",
278 GNUNET_OS_process_close (p->arm_proc); 274 GNUNET_OS_process_get_pid (p->arm_proc));
279 p->arm_proc = NULL; 275 GNUNET_OS_process_close (p->arm_proc);
280 } 276 p->arm_proc = NULL;
277 }
281#endif 278#endif
282 GNUNET_CONFIGURATION_destroy (p->cfg); 279 GNUNET_CONFIGURATION_destroy (p->cfg);
283} 280}
@@ -286,8 +283,7 @@ stop_arm (struct PeerContext *p)
286static void 283static void
287run (void *cls, 284run (void *cls,
288 char *const *args, 285 char *const *args,
289 const char *cfgfile, 286 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
290 const struct GNUNET_CONFIGURATION_Handle *cfg)
291{ 287{
292 const char *keywords[] = { 288 const char *keywords[] = {
293 "down_foo", 289 "down_foo",
@@ -302,12 +298,10 @@ run (void *cls,
302 298
303 setup_peer (&p1, "test_fs_download_data.conf"); 299 setup_peer (&p1, "test_fs_download_data.conf");
304 fs = GNUNET_FS_start (cfg, 300 fs = GNUNET_FS_start (cfg,
305 "test-fs-download", 301 "test-fs-download",
306 &progress_cb, 302 &progress_cb,
307 NULL, 303 NULL, GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
308 GNUNET_FS_FLAGS_NONE, 304 GNUNET_assert (NULL != fs);
309 GNUNET_FS_OPTIONS_END);
310 GNUNET_assert (NULL != fs);
311 buf = GNUNET_malloc (FILESIZE); 305 buf = GNUNET_malloc (FILESIZE);
312 for (i = 0; i < FILESIZE; i++) 306 for (i = 0; i < FILESIZE; i++)
313 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); 307 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
@@ -316,26 +310,22 @@ run (void *cls,
316 bo.content_priority = 42; 310 bo.content_priority = 42;
317 bo.anonymity_level = 1; 311 bo.anonymity_level = 1;
318 bo.replication_level = 0; 312 bo.replication_level = 0;
319 bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME); 313 bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME);
320 fi = GNUNET_FS_file_information_create_from_data (fs, 314 fi = GNUNET_FS_file_information_create_from_data (fs,
321 "publish-context", 315 "publish-context",
322 FILESIZE, 316 FILESIZE,
323 buf, 317 buf,
324 kuri, 318 kuri, meta, GNUNET_NO, &bo);
325 meta,
326 GNUNET_NO,
327 &bo);
328 GNUNET_FS_uri_destroy (kuri); 319 GNUNET_FS_uri_destroy (kuri);
329 GNUNET_CONTAINER_meta_data_destroy (meta); 320 GNUNET_CONTAINER_meta_data_destroy (meta);
330 GNUNET_assert (NULL != fi); 321 GNUNET_assert (NULL != fi);
331 timeout_kill = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 322 timeout_kill = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
332 &timeout_kill_task, 323 &timeout_kill_task, NULL);
333 NULL);
334 start = GNUNET_TIME_absolute_get (); 324 start = GNUNET_TIME_absolute_get ();
335 publish = GNUNET_FS_publish_start (fs, 325 publish = GNUNET_FS_publish_start (fs,
336 fi, 326 fi,
337 NULL, NULL, NULL, 327 NULL, NULL, NULL,
338 GNUNET_FS_PUBLISH_OPTION_NONE); 328 GNUNET_FS_PUBLISH_OPTION_NONE);
339 GNUNET_assert (publish != NULL); 329 GNUNET_assert (publish != NULL);
340} 330}
341 331
@@ -343,7 +333,7 @@ run (void *cls,
343int 333int
344main (int argc, char *argv[]) 334main (int argc, char *argv[])
345{ 335{
346 char *const argvx[] = { 336 char *const argvx[] = {
347 "test-fs-download", 337 "test-fs-download",
348 "-c", 338 "-c",
349 "test_fs_download_data.conf", 339 "test_fs_download_data.conf",
@@ -356,16 +346,15 @@ main (int argc, char *argv[])
356 GNUNET_GETOPT_OPTION_END 346 GNUNET_GETOPT_OPTION_END
357 }; 347 };
358 348
359 GNUNET_log_setup ("test_fs_download", 349 GNUNET_log_setup ("test_fs_download",
360#if VERBOSE 350#if VERBOSE
361 "DEBUG", 351 "DEBUG",
362#else 352#else
363 "WARNING", 353 "WARNING",
364#endif 354#endif
365 NULL); 355 NULL);
366 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, 356 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
367 argvx, "test-fs-download", 357 argvx, "test-fs-download", "nohelp", options, &run, NULL);
368 "nohelp", options, &run, NULL);
369 stop_arm (&p1); 358 stop_arm (&p1);
370 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-download/"); 359 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-download/");
371 return err; 360 return err;
diff --git a/src/fs/test_fs_download_indexed.c b/src/fs/test_fs_download_indexed.c
index c99dd04de..86933352a 100644
--- a/src/fs/test_fs_download_indexed.c
+++ b/src/fs/test_fs_download_indexed.c
@@ -46,7 +46,7 @@
46 46
47/** 47/**
48 * How long should our test-content live? 48 * How long should our test-content live?
49 */ 49 */
50#define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) 50#define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)
51 51
52struct PeerContext 52struct PeerContext
@@ -76,55 +76,51 @@ static char *fn1;
76static int err; 76static int err;
77 77
78static void 78static void
79timeout_kill_task (void *cls, 79timeout_kill_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
80 const struct GNUNET_SCHEDULER_TaskContext *tc)
81{ 80{
82 if (download != NULL) 81 if (download != NULL)
83 { 82 {
84 GNUNET_FS_download_stop (download, GNUNET_YES); 83 GNUNET_FS_download_stop (download, GNUNET_YES);
85 download = NULL; 84 download = NULL;
86 } 85 }
87 else if (publish != NULL) 86 else if (publish != NULL)
88 { 87 {
89 GNUNET_FS_publish_stop (publish); 88 GNUNET_FS_publish_stop (publish);
90 publish = NULL; 89 publish = NULL;
91 } 90 }
92 timeout_kill = GNUNET_SCHEDULER_NO_TASK; 91 timeout_kill = GNUNET_SCHEDULER_NO_TASK;
93 err = 1; 92 err = 1;
94} 93}
95 94
96static void 95static void
97abort_publish_task (void *cls, 96abort_publish_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
98 const struct GNUNET_SCHEDULER_TaskContext *tc)
99{ 97{
100 if (publish != NULL) 98 if (publish != NULL)
101 { 99 {
102 GNUNET_FS_publish_stop (publish); 100 GNUNET_FS_publish_stop (publish);
103 publish = NULL; 101 publish = NULL;
104 } 102 }
105} 103}
106 104
107static void 105static void
108stop_fs_task (void *cls, 106stop_fs_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
109 const struct GNUNET_SCHEDULER_TaskContext *tc)
110{ 107{
111 GNUNET_FS_stop (fs); 108 GNUNET_FS_stop (fs);
112 fs = NULL; 109 fs = NULL;
113} 110}
114 111
115static void 112static void
116abort_download_task (void *cls, 113abort_download_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
117 const struct GNUNET_SCHEDULER_TaskContext *tc)
118{ 114{
119 uint64_t size; 115 uint64_t size;
120 116
121 if (download != NULL) 117 if (download != NULL)
122 { 118 {
123 GNUNET_FS_download_stop (download, GNUNET_YES); 119 GNUNET_FS_download_stop (download, GNUNET_YES);
124 download = NULL; 120 download = NULL;
125 } 121 }
126 GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_size (fn, &size, GNUNET_YES)); 122 GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_size (fn, &size, GNUNET_YES));
127 GNUNET_assert (size == FILESIZE); 123 GNUNET_assert (size == FILESIZE);
128 GNUNET_DISK_directory_remove (fn); 124 GNUNET_DISK_directory_remove (fn);
129 GNUNET_free (fn); 125 GNUNET_free (fn);
130 fn = NULL; 126 fn = NULL;
@@ -134,115 +130,116 @@ abort_download_task (void *cls,
134 130
135 131
136static void * 132static void *
137progress_cb (void *cls, 133progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
138 const struct GNUNET_FS_ProgressInfo *event)
139{ 134{
140 135
141 switch (event->status) 136 switch (event->status)
142 { 137 {
143 case GNUNET_FS_STATUS_PUBLISH_PROGRESS: 138 case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
144#if VERBOSE 139#if VERBOSE
145 printf ("Publish is progressing (%llu/%llu at level %u off %llu)...\n", 140 printf ("Publish is progressing (%llu/%llu at level %u off %llu)...\n",
146 (unsigned long long) event->value.publish.completed, 141 (unsigned long long) event->value.publish.completed,
147 (unsigned long long) event->value.publish.size, 142 (unsigned long long) event->value.publish.size,
148 event->value.publish.specifics.progress.depth, 143 event->value.publish.specifics.progress.depth,
149 (unsigned long long) event->value.publish.specifics.progress.offset); 144 (unsigned long long) event->value.publish.specifics.
150#endif 145 progress.offset);
151 break; 146#endif
152 case GNUNET_FS_STATUS_PUBLISH_COMPLETED: 147 break;
153 printf ("Publishing complete, %llu kbps.\n", 148 case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
154 (unsigned long long) (FILESIZE * 1000LL / (1+GNUNET_TIME_absolute_get_duration (start).rel_value) / 1024LL)); 149 printf ("Publishing complete, %llu kbps.\n",
155 GAUGER ("FS", 150 (unsigned long long) (FILESIZE * 1000LL /
156 "Publishing speed (indexing)", 151 (1 +
157 (unsigned long long) (FILESIZE * 1000LL / (1+GNUNET_TIME_absolute_get_duration (start).rel_value) / 1024LL), 152 GNUNET_TIME_absolute_get_duration
158 "kb/s"); 153 (start).rel_value) / 1024LL));
159 fn = GNUNET_DISK_mktemp ("gnunet-download-test-dst"); 154 GAUGER ("FS", "Publishing speed (indexing)",
160 start = GNUNET_TIME_absolute_get (); 155 (unsigned long long) (FILESIZE * 1000LL /
161 download = GNUNET_FS_download_start (fs, 156 (1 +
162 event->value.publish.specifics.completed.chk_uri, 157 GNUNET_TIME_absolute_get_duration
163 NULL, 158 (start).rel_value) / 1024LL), "kb/s");
164 fn, NULL, 159 fn = GNUNET_DISK_mktemp ("gnunet-download-test-dst");
165 0, 160 start = GNUNET_TIME_absolute_get ();
166 FILESIZE, 161 download = GNUNET_FS_download_start (fs,
167 1, 162 event->value.publish.
168 GNUNET_FS_DOWNLOAD_OPTION_NONE, 163 specifics.completed.chk_uri, NULL, fn,
169 "download", 164 NULL, 0, FILESIZE, 1,
170 NULL); 165 GNUNET_FS_DOWNLOAD_OPTION_NONE,
171 GNUNET_assert (download != NULL); 166 "download", NULL);
172 break; 167 GNUNET_assert (download != NULL);
173 case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: 168 break;
174 printf ("Download complete, %llu kbps.\n", 169 case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED:
175 (unsigned long long) (FILESIZE * 1000LL / (1+GNUNET_TIME_absolute_get_duration (start).rel_value) / 1024LL)); 170 printf ("Download complete, %llu kbps.\n",
176 GAUGER ("FS", 171 (unsigned long long) (FILESIZE * 1000LL /
177 "Local download speed (indexed)", 172 (1 +
178 (unsigned long long) (FILESIZE * 1000LL / (1+GNUNET_TIME_absolute_get_duration (start).rel_value) / 1024LL), 173 GNUNET_TIME_absolute_get_duration
179 "kb/s"); 174 (start).rel_value) / 1024LL));
180 GNUNET_SCHEDULER_add_now (&abort_download_task, 175 GAUGER ("FS", "Local download speed (indexed)",
181 NULL); 176 (unsigned long long) (FILESIZE * 1000LL /
182 break; 177 (1 +
183 case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: 178 GNUNET_TIME_absolute_get_duration
184 GNUNET_assert (download == event->value.download.dc); 179 (start).rel_value) / 1024LL), "kb/s");
180 GNUNET_SCHEDULER_add_now (&abort_download_task, NULL);
181 break;
182 case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS:
183 GNUNET_assert (download == event->value.download.dc);
185#if VERBOSE 184#if VERBOSE
186 printf ("Download is progressing (%llu/%llu at level %u off %llu)...\n", 185 printf ("Download is progressing (%llu/%llu at level %u off %llu)...\n",
187 (unsigned long long) event->value.download.completed, 186 (unsigned long long) event->value.download.completed,
188 (unsigned long long) event->value.download.size, 187 (unsigned long long) event->value.download.size,
189 event->value.download.specifics.progress.depth, 188 event->value.download.specifics.progress.depth,
190 (unsigned long long) event->value.download.specifics.progress.offset); 189 (unsigned long long) event->value.download.specifics.
190 progress.offset);
191#endif 191#endif
192 break; 192 break;
193 case GNUNET_FS_STATUS_PUBLISH_ERROR: 193 case GNUNET_FS_STATUS_PUBLISH_ERROR:
194 fprintf (stderr, 194 fprintf (stderr,
195 "Error publishing file: %s\n", 195 "Error publishing file: %s\n",
196 event->value.publish.specifics.error.message); 196 event->value.publish.specifics.error.message);
197 GNUNET_break (0); 197 GNUNET_break (0);
198 GNUNET_SCHEDULER_add_continuation (&abort_publish_task, 198 GNUNET_SCHEDULER_add_continuation (&abort_publish_task,
199 NULL, 199 NULL,
200 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 200 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
201 break; 201 break;
202 case GNUNET_FS_STATUS_DOWNLOAD_ERROR: 202 case GNUNET_FS_STATUS_DOWNLOAD_ERROR:
203 fprintf (stderr, 203 fprintf (stderr,
204 "Error downloading file: %s\n", 204 "Error downloading file: %s\n",
205 event->value.download.specifics.error.message); 205 event->value.download.specifics.error.message);
206 GNUNET_SCHEDULER_add_now (&abort_download_task, 206 GNUNET_SCHEDULER_add_now (&abort_download_task, NULL);
207 NULL); 207 break;
208 break; 208 case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE:
209 case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE: 209 case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE:
210 case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE: 210 break;
211 break; 211 case GNUNET_FS_STATUS_PUBLISH_START:
212 case GNUNET_FS_STATUS_PUBLISH_START: 212 GNUNET_assert (0 == strcmp ("publish-context", event->value.publish.cctx));
213 GNUNET_assert (0 == strcmp ("publish-context", event->value.publish.cctx)); 213 GNUNET_assert (NULL == event->value.publish.pctx);
214 GNUNET_assert (NULL == event->value.publish.pctx); 214 GNUNET_assert (FILESIZE == event->value.publish.size);
215 GNUNET_assert (FILESIZE == event->value.publish.size); 215 GNUNET_assert (0 == event->value.publish.completed);
216 GNUNET_assert (0 == event->value.publish.completed); 216 GNUNET_assert (1 == event->value.publish.anonymity);
217 GNUNET_assert (1 == event->value.publish.anonymity); 217 break;
218 break; 218 case GNUNET_FS_STATUS_PUBLISH_STOPPED:
219 case GNUNET_FS_STATUS_PUBLISH_STOPPED: 219 GNUNET_assert (publish == event->value.publish.pc);
220 GNUNET_assert (publish == event->value.publish.pc); 220 GNUNET_assert (FILESIZE == event->value.publish.size);
221 GNUNET_assert (FILESIZE == event->value.publish.size); 221 GNUNET_assert (1 == event->value.publish.anonymity);
222 GNUNET_assert (1 == event->value.publish.anonymity); 222 GNUNET_SCHEDULER_add_now (&stop_fs_task, NULL);
223 GNUNET_SCHEDULER_add_now (&stop_fs_task, 223 break;
224 NULL); 224 case GNUNET_FS_STATUS_DOWNLOAD_START:
225 break; 225 GNUNET_assert (0 == strcmp ("download", event->value.download.cctx));
226 case GNUNET_FS_STATUS_DOWNLOAD_START: 226 GNUNET_assert (NULL == event->value.download.pctx);
227 GNUNET_assert (0 == strcmp ("download", event->value.download.cctx)); 227 GNUNET_assert (NULL != event->value.download.uri);
228 GNUNET_assert (NULL == event->value.download.pctx); 228 GNUNET_assert (0 == strcmp (fn, event->value.download.filename));
229 GNUNET_assert (NULL != event->value.download.uri); 229 GNUNET_assert (FILESIZE == event->value.download.size);
230 GNUNET_assert (0 == strcmp (fn, event->value.download.filename)); 230 GNUNET_assert (0 == event->value.download.completed);
231 GNUNET_assert (FILESIZE == event->value.download.size); 231 GNUNET_assert (1 == event->value.download.anonymity);
232 GNUNET_assert (0 == event->value.download.completed); 232 break;
233 GNUNET_assert (1 == event->value.download.anonymity); 233 case GNUNET_FS_STATUS_DOWNLOAD_STOPPED:
234 break; 234 GNUNET_assert (download == event->value.download.dc);
235 case GNUNET_FS_STATUS_DOWNLOAD_STOPPED: 235 GNUNET_SCHEDULER_add_continuation (&abort_publish_task,
236 GNUNET_assert (download == event->value.download.dc); 236 NULL,
237 GNUNET_SCHEDULER_add_continuation (&abort_publish_task, 237 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
238 NULL, 238 break;
239 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 239 default:
240 break; 240 printf ("Unexpected event: %d\n", event->status);
241 default: 241 break;
242 printf ("Unexpected event: %d\n", 242 }
243 event->status);
244 break;
245 }
246 return NULL; 243 return NULL;
247} 244}
248 245
@@ -253,11 +250,11 @@ setup_peer (struct PeerContext *p, const char *cfgname)
253 p->cfg = GNUNET_CONFIGURATION_create (); 250 p->cfg = GNUNET_CONFIGURATION_create ();
254#if START_ARM 251#if START_ARM
255 p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", 252 p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
256 "gnunet-service-arm", 253 "gnunet-service-arm",
257#if VERBOSE 254#if VERBOSE
258 "-L", "DEBUG", 255 "-L", "DEBUG",
259#endif 256#endif
260 "-c", cfgname, NULL); 257 "-c", cfgname, NULL);
261#endif 258#endif
262 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); 259 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
263} 260}
@@ -268,16 +265,17 @@ stop_arm (struct PeerContext *p)
268{ 265{
269#if START_ARM 266#if START_ARM
270 if (NULL != p->arm_proc) 267 if (NULL != p->arm_proc)
271 { 268 {
272 if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) 269 if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
273 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 270 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
274 if (GNUNET_OS_process_wait(p->arm_proc) != GNUNET_OK) 271 if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
275 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); 272 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
276 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 273 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
277 "ARM process %u stopped\n", GNUNET_OS_process_get_pid (p->arm_proc)); 274 "ARM process %u stopped\n",
278 GNUNET_OS_process_close (p->arm_proc); 275 GNUNET_OS_process_get_pid (p->arm_proc));
279 p->arm_proc = NULL; 276 GNUNET_OS_process_close (p->arm_proc);
280 } 277 p->arm_proc = NULL;
278 }
281#endif 279#endif
282 GNUNET_CONFIGURATION_destroy (p->cfg); 280 GNUNET_CONFIGURATION_destroy (p->cfg);
283} 281}
@@ -286,8 +284,7 @@ stop_arm (struct PeerContext *p)
286static void 284static void
287run (void *cls, 285run (void *cls,
288 char *const *args, 286 char *const *args,
289 const char *cfgfile, 287 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
290 const struct GNUNET_CONFIGURATION_Handle *cfg)
291{ 288{
292 const char *keywords[] = { 289 const char *keywords[] = {
293 "down_foo", 290 "down_foo",
@@ -302,47 +299,43 @@ run (void *cls,
302 299
303 setup_peer (&p1, "test_fs_download_data.conf"); 300 setup_peer (&p1, "test_fs_download_data.conf");
304 fs = GNUNET_FS_start (cfg, 301 fs = GNUNET_FS_start (cfg,
305 "test-fs-download-indexed", 302 "test-fs-download-indexed",
306 &progress_cb, 303 &progress_cb,
307 NULL, 304 NULL, GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
308 GNUNET_FS_FLAGS_NONE, 305 GNUNET_assert (NULL != fs);
309 GNUNET_FS_OPTIONS_END);
310 GNUNET_assert (NULL != fs);
311 306
312 fn1 = GNUNET_DISK_mktemp ("gnunet-download-indexed-test"); 307 fn1 = GNUNET_DISK_mktemp ("gnunet-download-indexed-test");
313 buf = GNUNET_malloc (FILESIZE); 308 buf = GNUNET_malloc (FILESIZE);
314 for (i = 0; i < FILESIZE; i++) 309 for (i = 0; i < FILESIZE; i++)
315 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); 310 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
316 GNUNET_assert (FILESIZE == 311 GNUNET_assert (FILESIZE ==
317 GNUNET_DISK_fn_write (fn1, 312 GNUNET_DISK_fn_write (fn1,
318 buf, 313 buf,
319 FILESIZE, 314 FILESIZE,
320 GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE)); 315 GNUNET_DISK_PERM_USER_READ |
316 GNUNET_DISK_PERM_USER_WRITE));
321 GNUNET_free (buf); 317 GNUNET_free (buf);
322 meta = GNUNET_CONTAINER_meta_data_create (); 318 meta = GNUNET_CONTAINER_meta_data_create ();
323 kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords); 319 kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords);
324 bo.content_priority = 42; 320 bo.content_priority = 42;
325 bo.anonymity_level = 1; 321 bo.anonymity_level = 1;
326 bo.replication_level = 0; 322 bo.replication_level = 0;
327 bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME); 323 bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME);
328 fi = GNUNET_FS_file_information_create_from_file (fs, 324 fi = GNUNET_FS_file_information_create_from_file (fs,
329 "publish-context", 325 "publish-context",
330 fn1, 326 fn1,
331 kuri, 327 kuri,
332 meta, 328 meta, GNUNET_YES, &bo);
333 GNUNET_YES,
334 &bo);
335 GNUNET_FS_uri_destroy (kuri); 329 GNUNET_FS_uri_destroy (kuri);
336 GNUNET_CONTAINER_meta_data_destroy (meta); 330 GNUNET_CONTAINER_meta_data_destroy (meta);
337 GNUNET_assert (NULL != fi); 331 GNUNET_assert (NULL != fi);
338 timeout_kill = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 332 timeout_kill = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
339 &timeout_kill_task, 333 &timeout_kill_task, NULL);
340 NULL);
341 start = GNUNET_TIME_absolute_get (); 334 start = GNUNET_TIME_absolute_get ();
342 publish = GNUNET_FS_publish_start (fs, 335 publish = GNUNET_FS_publish_start (fs,
343 fi, 336 fi,
344 NULL, NULL, NULL, 337 NULL, NULL, NULL,
345 GNUNET_FS_PUBLISH_OPTION_NONE); 338 GNUNET_FS_PUBLISH_OPTION_NONE);
346 GNUNET_assert (publish != NULL); 339 GNUNET_assert (publish != NULL);
347} 340}
348 341
@@ -350,7 +343,7 @@ run (void *cls,
350int 343int
351main (int argc, char *argv[]) 344main (int argc, char *argv[])
352{ 345{
353 char *const argvx[] = { 346 char *const argvx[] = {
354 "test-fs-download-indexed", 347 "test-fs-download-indexed",
355 "-c", 348 "-c",
356 "test_fs_download_data.conf", 349 "test_fs_download_data.conf",
@@ -363,27 +356,27 @@ main (int argc, char *argv[])
363 GNUNET_GETOPT_OPTION_END 356 GNUNET_GETOPT_OPTION_END
364 }; 357 };
365 358
366 GNUNET_log_setup ("test_fs_download_indexed", 359 GNUNET_log_setup ("test_fs_download_indexed",
367#if VERBOSE 360#if VERBOSE
368 "DEBUG", 361 "DEBUG",
369#else 362#else
370 "WARNING", 363 "WARNING",
371#endif 364#endif
372 NULL); 365 NULL);
373 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, 366 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
374 argvx, "test-fs-download-indexed", 367 argvx, "test-fs-download-indexed",
375 "nohelp", options, &run, NULL); 368 "nohelp", options, &run, NULL);
376 stop_arm (&p1); 369 stop_arm (&p1);
377 if (fn1 != NULL) 370 if (fn1 != NULL)
378 { 371 {
379 GNUNET_DISK_directory_remove (fn1); 372 GNUNET_DISK_directory_remove (fn1);
380 GNUNET_free (fn1); 373 GNUNET_free (fn1);
381 } 374 }
382 if (fn != NULL) 375 if (fn != NULL)
383 { 376 {
384 GNUNET_DISK_directory_remove (fn); 377 GNUNET_DISK_directory_remove (fn);
385 GNUNET_free (fn); 378 GNUNET_free (fn);
386 } 379 }
387 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-download/"); 380 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-download/");
388 return err; 381 return err;
389} 382}
diff --git a/src/fs/test_fs_download_persistence.c b/src/fs/test_fs_download_persistence.c
index b058367a2..d484f9587 100644
--- a/src/fs/test_fs_download_persistence.c
+++ b/src/fs/test_fs_download_persistence.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
51struct PeerContext 51struct PeerContext
@@ -75,50 +75,46 @@ static char *fn;
75static int err; 75static int err;
76 76
77static void 77static void
78timeout_kill_task (void *cls, 78timeout_kill_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
79 const struct GNUNET_SCHEDULER_TaskContext *tc)
80{ 79{
81 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 80 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Timeout downloading file\n");
82 "Timeout downloading file\n");
83 if (download != NULL) 81 if (download != NULL)
84 { 82 {
85 GNUNET_FS_download_stop (download, GNUNET_YES); 83 GNUNET_FS_download_stop (download, GNUNET_YES);
86 download = NULL; 84 download = NULL;
87 } 85 }
88 else if (publish != NULL) 86 else if (publish != NULL)
89 { 87 {
90 GNUNET_FS_publish_stop (publish); 88 GNUNET_FS_publish_stop (publish);
91 publish = NULL; 89 publish = NULL;
92 } 90 }
93 timeout_kill = GNUNET_SCHEDULER_NO_TASK; 91 timeout_kill = GNUNET_SCHEDULER_NO_TASK;
94 err = 1; 92 err = 1;
95} 93}
96 94
97static void 95static void
98abort_publish_task (void *cls, 96abort_publish_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
99 const struct GNUNET_SCHEDULER_TaskContext *tc)
100{ 97{
101 if (publish != NULL) 98 if (publish != NULL)
102 { 99 {
103 GNUNET_FS_publish_stop (publish); 100 GNUNET_FS_publish_stop (publish);
104 publish = NULL; 101 publish = NULL;
105 } 102 }
106} 103}
107 104
108 105
109static void 106static void
110abort_download_task (void *cls, 107abort_download_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
111 const struct GNUNET_SCHEDULER_TaskContext *tc)
112{ 108{
113 uint64_t size; 109 uint64_t size;
114 110
115 if (download != NULL) 111 if (download != NULL)
116 { 112 {
117 GNUNET_FS_download_stop (download, GNUNET_YES); 113 GNUNET_FS_download_stop (download, GNUNET_YES);
118 download = NULL; 114 download = NULL;
119 } 115 }
120 GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_size (fn, &size, GNUNET_YES)); 116 GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_size (fn, &size, GNUNET_YES));
121 GNUNET_assert (size == FILESIZE); 117 GNUNET_assert (size == FILESIZE);
122 GNUNET_DISK_directory_remove (fn); 118 GNUNET_DISK_directory_remove (fn);
123 GNUNET_free (fn); 119 GNUNET_free (fn);
124 fn = NULL; 120 fn = NULL;
@@ -127,24 +123,20 @@ abort_download_task (void *cls,
127} 123}
128 124
129 125
130static void * 126static void *progress_cb (void *cls,
131progress_cb (void *cls, 127 const struct GNUNET_FS_ProgressInfo *event);
132 const struct GNUNET_FS_ProgressInfo *event);
133 128
134 129
135static void 130static void
136restart_fs_task (void *cls, 131restart_fs_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
137 const struct GNUNET_SCHEDULER_TaskContext *tc)
138{ 132{
139 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 133 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Restarting FS.\n");
140 "Restarting FS.\n");
141 GNUNET_FS_stop (fs); 134 GNUNET_FS_stop (fs);
142 fs = GNUNET_FS_start (cfg, 135 fs = GNUNET_FS_start (cfg,
143 "test-fs-download-persistence", 136 "test-fs-download-persistence",
144 &progress_cb, 137 &progress_cb,
145 NULL, 138 NULL,
146 GNUNET_FS_FLAGS_PERSISTENCE, 139 GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END);
147 GNUNET_FS_OPTIONS_END);
148} 140}
149 141
150 142
@@ -161,152 +153,149 @@ consider_restart (int ev)
161 static int prev[32]; 153 static int prev[32];
162 static int off; 154 static int off;
163 int i; 155 int i;
164 for (i=0;i<off;i++) 156
157 for (i = 0; i < off; i++)
165 if (prev[i] == ev) 158 if (prev[i] == ev)
166 return; 159 return;
167 prev[off++] = ev; 160 prev[off++] = ev;
168 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_URGENT, 161 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_URGENT,
169 &restart_fs_task, 162 &restart_fs_task, NULL);
170 NULL);
171} 163}
172 164
173 165
174static void * 166static void *
175progress_cb (void *cls, 167progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
176 const struct GNUNET_FS_ProgressInfo *event)
177{ 168{
178 switch (event->status) 169 switch (event->status)
179 { 170 {
180 case GNUNET_FS_STATUS_PUBLISH_PROGRESS: 171 case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
181#if VERBOSE 172#if VERBOSE
182 printf ("Publish is progressing (%llu/%llu at level %u off %llu)...\n", 173 printf ("Publish is progressing (%llu/%llu at level %u off %llu)...\n",
183 (unsigned long long) event->value.publish.completed, 174 (unsigned long long) event->value.publish.completed,
184 (unsigned long long) event->value.publish.size, 175 (unsigned long long) event->value.publish.size,
185 event->value.publish.specifics.progress.depth, 176 event->value.publish.specifics.progress.depth,
186 (unsigned long long) event->value.publish.specifics.progress.offset); 177 (unsigned long long) event->value.publish.specifics.
187#endif 178 progress.offset);
188 break; 179#endif
189 case GNUNET_FS_STATUS_PUBLISH_COMPLETED: 180 break;
190 printf ("Publishing complete, %llu kbps.\n", 181 case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
191 (unsigned long long) (FILESIZE * 1000LL / (1+GNUNET_TIME_absolute_get_duration (start).rel_value) / 1024LL)); 182 printf ("Publishing complete, %llu kbps.\n",
192 fn = GNUNET_DISK_mktemp ("gnunet-download-test-dst"); 183 (unsigned long long) (FILESIZE * 1000LL /
193 start = GNUNET_TIME_absolute_get (); 184 (1 +
194 GNUNET_assert (download == NULL); 185 GNUNET_TIME_absolute_get_duration
195 GNUNET_FS_download_start (fs, 186 (start).rel_value) / 1024LL));
196 event->value.publish.specifics.completed.chk_uri, 187 fn = GNUNET_DISK_mktemp ("gnunet-download-test-dst");
197 NULL, 188 start = GNUNET_TIME_absolute_get ();
198 fn, NULL, 189 GNUNET_assert (download == NULL);
199 0, 190 GNUNET_FS_download_start (fs,
200 FILESIZE, 191 event->value.publish.specifics.completed.chk_uri,
201 1, 192 NULL,
202 GNUNET_FS_DOWNLOAD_OPTION_NONE, 193 fn, NULL,
203 "download", 194 0,
204 NULL); 195 FILESIZE,
205 break; 196 1,
206 case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: 197 GNUNET_FS_DOWNLOAD_OPTION_NONE, "download", NULL);
207 consider_restart (event->status); 198 break;
208 printf ("Download complete, %llu kbps.\n", 199 case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED:
209 (unsigned long long) (FILESIZE * 1000LL / (1+GNUNET_TIME_absolute_get_duration (start).rel_value) / 1024LL)); 200 consider_restart (event->status);
210 GNUNET_SCHEDULER_add_now (&abort_download_task, 201 printf ("Download complete, %llu kbps.\n",
211 NULL); 202 (unsigned long long) (FILESIZE * 1000LL /
212 break; 203 (1 +
213 case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: 204 GNUNET_TIME_absolute_get_duration
214 consider_restart (event->status); 205 (start).rel_value) / 1024LL));
215 GNUNET_assert (download == event->value.download.dc); 206 GNUNET_SCHEDULER_add_now (&abort_download_task, NULL);
207 break;
208 case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS:
209 consider_restart (event->status);
210 GNUNET_assert (download == event->value.download.dc);
216#if VERBOSE 211#if VERBOSE
217 printf ("Download is progressing (%llu/%llu at level %u off %llu)...\n", 212 printf ("Download is progressing (%llu/%llu at level %u off %llu)...\n",
218 (unsigned long long) event->value.download.completed, 213 (unsigned long long) event->value.download.completed,
219 (unsigned long long) event->value.download.size, 214 (unsigned long long) event->value.download.size,
220 event->value.download.specifics.progress.depth, 215 event->value.download.specifics.progress.depth,
221 (unsigned long long) event->value.download.specifics.progress.offset); 216 (unsigned long long) event->value.download.specifics.
217 progress.offset);
222#endif 218#endif
223 break; 219 break;
224 case GNUNET_FS_STATUS_PUBLISH_ERROR: 220 case GNUNET_FS_STATUS_PUBLISH_ERROR:
225 fprintf (stderr, 221 fprintf (stderr,
226 "Error publishing file: %s\n", 222 "Error publishing file: %s\n",
227 event->value.publish.specifics.error.message); 223 event->value.publish.specifics.error.message);
228 GNUNET_break (0); 224 GNUNET_break (0);
229 GNUNET_SCHEDULER_add_continuation (&abort_publish_task, 225 GNUNET_SCHEDULER_add_continuation (&abort_publish_task,
230 NULL, 226 NULL,
231 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 227 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
232 break; 228 break;
233 case GNUNET_FS_STATUS_DOWNLOAD_ERROR: 229 case GNUNET_FS_STATUS_DOWNLOAD_ERROR:
234 fprintf (stderr, 230 fprintf (stderr,
235 "Error downloading file: %s\n", 231 "Error downloading file: %s\n",
236 event->value.download.specifics.error.message); 232 event->value.download.specifics.error.message);
237 GNUNET_SCHEDULER_add_now (&abort_download_task, 233 GNUNET_SCHEDULER_add_now (&abort_download_task, NULL);
238 NULL); 234 break;
239 break; 235 case GNUNET_FS_STATUS_PUBLISH_SUSPEND:
240 case GNUNET_FS_STATUS_PUBLISH_SUSPEND: 236 GNUNET_assert (event->value.publish.pc == publish);
241 GNUNET_assert (event->value.publish.pc == publish); 237 publish = NULL;
242 publish = NULL; 238 break;
243 break; 239 case GNUNET_FS_STATUS_PUBLISH_RESUME:
244 case GNUNET_FS_STATUS_PUBLISH_RESUME: 240 GNUNET_assert (NULL == publish);
245 GNUNET_assert (NULL == publish); 241 publish = event->value.publish.pc;
246 publish = event->value.publish.pc; 242 break;
247 break; 243 case GNUNET_FS_STATUS_DOWNLOAD_SUSPEND:
248 case GNUNET_FS_STATUS_DOWNLOAD_SUSPEND: 244 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download suspended.\n");
249 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 245 GNUNET_assert (event->value.download.dc == download);
250 "Download suspended.\n"); 246 download = NULL;
251 GNUNET_assert (event->value.download.dc == download); 247 break;
252 download = NULL; 248 case GNUNET_FS_STATUS_DOWNLOAD_RESUME:
253 break; 249 GNUNET_assert (NULL == download);
254 case GNUNET_FS_STATUS_DOWNLOAD_RESUME: 250 download = event->value.download.dc;
255 GNUNET_assert (NULL == download); 251 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download resumed.\n");
256 download = event->value.download.dc; 252 break;
257 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 253 case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE:
258 "Download resumed.\n"); 254 consider_restart (event->status);
259 break; 255 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download active.\n");
260 case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE: 256 break;
261 consider_restart (event->status); 257 case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE:
262 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 258 consider_restart (event->status);
263 "Download active.\n"); 259 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download inactive.\n");
264 break; 260 break;
265 case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE: 261 case GNUNET_FS_STATUS_PUBLISH_START:
266 consider_restart (event->status); 262 GNUNET_assert (0 == strcmp ("publish-context", event->value.publish.cctx));
267 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 263 GNUNET_assert (NULL == event->value.publish.pctx);
268 "Download inactive.\n"); 264 GNUNET_assert (FILESIZE == event->value.publish.size);
269 break; 265 GNUNET_assert (0 == event->value.publish.completed);
270 case GNUNET_FS_STATUS_PUBLISH_START: 266 GNUNET_assert (1 == event->value.publish.anonymity);
271 GNUNET_assert (0 == strcmp ("publish-context", event->value.publish.cctx)); 267 break;
272 GNUNET_assert (NULL == event->value.publish.pctx); 268 case GNUNET_FS_STATUS_PUBLISH_STOPPED:
273 GNUNET_assert (FILESIZE == event->value.publish.size); 269 GNUNET_assert (publish == event->value.publish.pc);
274 GNUNET_assert (0 == event->value.publish.completed); 270 GNUNET_assert (FILESIZE == event->value.publish.size);
275 GNUNET_assert (1 == event->value.publish.anonymity); 271 GNUNET_assert (1 == event->value.publish.anonymity);
276 break; 272 GNUNET_FS_stop (fs);
277 case GNUNET_FS_STATUS_PUBLISH_STOPPED: 273 fs = NULL;
278 GNUNET_assert (publish == event->value.publish.pc); 274 break;
279 GNUNET_assert (FILESIZE == event->value.publish.size); 275 case GNUNET_FS_STATUS_DOWNLOAD_START:
280 GNUNET_assert (1 == event->value.publish.anonymity); 276 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download started.\n");
281 GNUNET_FS_stop (fs); 277 consider_restart (event->status);
282 fs = NULL; 278 GNUNET_assert (download == NULL);
283 break; 279 download = event->value.download.dc;
284 case GNUNET_FS_STATUS_DOWNLOAD_START: 280 GNUNET_assert (0 == strcmp ("download", event->value.download.cctx));
285 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 281 GNUNET_assert (NULL == event->value.download.pctx);
286 "Download started.\n"); 282 GNUNET_assert (NULL != event->value.download.uri);
287 consider_restart (event->status); 283 GNUNET_assert (0 == strcmp (fn, event->value.download.filename));
288 GNUNET_assert (download == NULL); 284 GNUNET_assert (FILESIZE == event->value.download.size);
289 download = event->value.download.dc; 285 GNUNET_assert (0 == event->value.download.completed);
290 GNUNET_assert (0 == strcmp ("download", event->value.download.cctx)); 286 GNUNET_assert (1 == event->value.download.anonymity);
291 GNUNET_assert (NULL == event->value.download.pctx); 287 break;
292 GNUNET_assert (NULL != event->value.download.uri); 288 case GNUNET_FS_STATUS_DOWNLOAD_STOPPED:
293 GNUNET_assert (0 == strcmp (fn, event->value.download.filename)); 289 GNUNET_assert (download == event->value.download.dc);
294 GNUNET_assert (FILESIZE == event->value.download.size); 290 GNUNET_SCHEDULER_add_continuation (&abort_publish_task,
295 GNUNET_assert (0 == event->value.download.completed); 291 NULL,
296 GNUNET_assert (1 == event->value.download.anonymity); 292 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
297 break; 293 download = NULL;
298 case GNUNET_FS_STATUS_DOWNLOAD_STOPPED: 294 break;
299 GNUNET_assert (download == event->value.download.dc); 295 default:
300 GNUNET_SCHEDULER_add_continuation (&abort_publish_task, 296 printf ("Unexpected event: %d\n", event->status);
301 NULL, 297 break;
302 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 298 }
303 download = NULL;
304 break;
305 default:
306 printf ("Unexpected event: %d\n",
307 event->status);
308 break;
309 }
310 return NULL; 299 return NULL;
311} 300}
312 301
@@ -317,11 +306,11 @@ setup_peer (struct PeerContext *p, const char *cfgname)
317 p->cfg = GNUNET_CONFIGURATION_create (); 306 p->cfg = GNUNET_CONFIGURATION_create ();
318#if START_ARM 307#if START_ARM
319 p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", 308 p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
320 "gnunet-service-arm", 309 "gnunet-service-arm",
321#if VERBOSE 310#if VERBOSE
322 "-L", "DEBUG", 311 "-L", "DEBUG",
323#endif 312#endif
324 "-c", cfgname, NULL); 313 "-c", cfgname, NULL);
325#endif 314#endif
326 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); 315 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
327} 316}
@@ -332,16 +321,17 @@ stop_arm (struct PeerContext *p)
332{ 321{
333#if START_ARM 322#if START_ARM
334 if (NULL != p->arm_proc) 323 if (NULL != p->arm_proc)
335 { 324 {
336 if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) 325 if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
337 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 326 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
338 if (GNUNET_OS_process_wait(p->arm_proc) != GNUNET_OK) 327 if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
339 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); 328 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
340 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 329 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
341 "ARM process %u stopped\n", GNUNET_OS_process_get_pid (p->arm_proc)); 330 "ARM process %u stopped\n",
342 GNUNET_OS_process_close (p->arm_proc); 331 GNUNET_OS_process_get_pid (p->arm_proc));
343 p->arm_proc = NULL; 332 GNUNET_OS_process_close (p->arm_proc);
344 } 333 p->arm_proc = NULL;
334 }
345#endif 335#endif
346 GNUNET_CONFIGURATION_destroy (p->cfg); 336 GNUNET_CONFIGURATION_destroy (p->cfg);
347} 337}
@@ -350,8 +340,7 @@ stop_arm (struct PeerContext *p)
350static void 340static void
351run (void *cls, 341run (void *cls,
352 char *const *args, 342 char *const *args,
353 const char *cfgfile, 343 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
354 const struct GNUNET_CONFIGURATION_Handle *c)
355{ 344{
356 const char *keywords[] = { 345 const char *keywords[] = {
357 "down_foo", 346 "down_foo",
@@ -367,12 +356,11 @@ run (void *cls,
367 cfg = c; 356 cfg = c;
368 setup_peer (&p1, "test_fs_download_data.conf"); 357 setup_peer (&p1, "test_fs_download_data.conf");
369 fs = GNUNET_FS_start (cfg, 358 fs = GNUNET_FS_start (cfg,
370 "test-fs-download-persistence", 359 "test-fs-download-persistence",
371 &progress_cb, 360 &progress_cb,
372 NULL, 361 NULL,
373 GNUNET_FS_FLAGS_PERSISTENCE, 362 GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END);
374 GNUNET_FS_OPTIONS_END); 363 GNUNET_assert (NULL != fs);
375 GNUNET_assert (NULL != fs);
376 buf = GNUNET_malloc (FILESIZE); 364 buf = GNUNET_malloc (FILESIZE);
377 for (i = 0; i < FILESIZE; i++) 365 for (i = 0; i < FILESIZE; i++)
378 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); 366 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
@@ -381,26 +369,22 @@ run (void *cls,
381 bo.content_priority = 42; 369 bo.content_priority = 42;
382 bo.anonymity_level = 1; 370 bo.anonymity_level = 1;
383 bo.replication_level = 0; 371 bo.replication_level = 0;
384 bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME); 372 bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME);
385 fi = GNUNET_FS_file_information_create_from_data (fs, 373 fi = GNUNET_FS_file_information_create_from_data (fs,
386 "publish-context", 374 "publish-context",
387 FILESIZE, 375 FILESIZE,
388 buf, 376 buf,
389 kuri, 377 kuri, meta, GNUNET_NO, &bo);
390 meta,
391 GNUNET_NO,
392 &bo);
393 GNUNET_FS_uri_destroy (kuri); 378 GNUNET_FS_uri_destroy (kuri);
394 GNUNET_CONTAINER_meta_data_destroy (meta); 379 GNUNET_CONTAINER_meta_data_destroy (meta);
395 GNUNET_assert (NULL != fi); 380 GNUNET_assert (NULL != fi);
396 timeout_kill = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 381 timeout_kill = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
397 &timeout_kill_task, 382 &timeout_kill_task, NULL);
398 NULL);
399 start = GNUNET_TIME_absolute_get (); 383 start = GNUNET_TIME_absolute_get ();
400 publish = GNUNET_FS_publish_start (fs, 384 publish = GNUNET_FS_publish_start (fs,
401 fi, 385 fi,
402 NULL, NULL, NULL, 386 NULL, NULL, NULL,
403 GNUNET_FS_PUBLISH_OPTION_NONE); 387 GNUNET_FS_PUBLISH_OPTION_NONE);
404 GNUNET_assert (publish != NULL); 388 GNUNET_assert (publish != NULL);
405} 389}
406 390
@@ -408,7 +392,7 @@ run (void *cls,
408int 392int
409main (int argc, char *argv[]) 393main (int argc, char *argv[])
410{ 394{
411 char *const argvx[] = { 395 char *const argvx[] = {
412 "test-fs-download-persistence", 396 "test-fs-download-persistence",
413 "-c", 397 "-c",
414 "test_fs_download_data.conf", 398 "test_fs_download_data.conf",
@@ -420,17 +404,17 @@ main (int argc, char *argv[])
420 struct GNUNET_GETOPT_CommandLineOption options[] = { 404 struct GNUNET_GETOPT_CommandLineOption options[] = {
421 GNUNET_GETOPT_OPTION_END 405 GNUNET_GETOPT_OPTION_END
422 }; 406 };
423 GNUNET_log_setup ("test_fs_download_persistence", 407 GNUNET_log_setup ("test_fs_download_persistence",
424#if VERBOSE 408#if VERBOSE
425 "DEBUG", 409 "DEBUG",
426#else 410#else
427 "WARNING", 411 "WARNING",
428#endif 412#endif
429 NULL); 413 NULL);
430 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-download/"); 414 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-download/");
431 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, 415 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
432 argvx, "test-fs-download-persistence", 416 argvx, "test-fs-download-persistence",
433 "nohelp", options, &run, NULL); 417 "nohelp", options, &run, NULL);
434 stop_arm (&p1); 418 stop_arm (&p1);
435 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-download/"); 419 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-download/");
436 return err; 420 return err;
diff --git a/src/fs/test_fs_download_recursive.c b/src/fs/test_fs_download_recursive.c
index d24a38dbc..c3e0ea440 100644
--- a/src/fs/test_fs_download_recursive.c
+++ b/src/fs/test_fs_download_recursive.c
@@ -46,10 +46,9 @@ makeName (unsigned int i)
46{ 46{
47 char *fn; 47 char *fn;
48 48
49 fn = 49 fn = GNUNET_malloc (strlen
50 GNUNET_malloc (strlen 50 ("/tmp/gnunet-fsui-recursive_download_test/FSUITEST") +
51 ("/tmp/gnunet-fsui-recursive_download_test/FSUITEST") + 51 15);
52 15);
53 GNUNET_snprintf (fn, 52 GNUNET_snprintf (fn,
54 strlen 53 strlen
55 ("/tmp/gnunet-fsui-recursive_download_test/FSUITEST") + 15, 54 ("/tmp/gnunet-fsui-recursive_download_test/FSUITEST") + 15,
@@ -68,56 +67,56 @@ makeHierarchyHelper (const char *current, const char *tree, int index,
68 fi = 0; 67 fi = 0;
69 done = 0; 68 done = 0;
70 while (!done && tree[index] != '\0') 69 while (!done && tree[index] != '\0')
70 {
71 s = GNUNET_malloc (strlen (current) + strlen (DIR_SEPARATOR_STR) + 14);
72 GNUNET_snprintf (s, strlen (current) + strlen (DIR_SEPARATOR_STR) + 14,
73 "%s%s%u", current, DIR_SEPARATOR_STR, fi);
74 switch (tree[index++])
71 { 75 {
72 s = GNUNET_malloc (strlen (current) + strlen (DIR_SEPARATOR_STR) + 14); 76 case 'd':
73 GNUNET_snprintf (s, strlen (current) + strlen (DIR_SEPARATOR_STR) + 14, 77 if (check)
74 "%s%s%u", current, DIR_SEPARATOR_STR, fi); 78 {
75 switch (tree[index++]) 79 if (GNUNET_disk_directory_test (NULL, s) == GNUNET_NO)
76 { 80 {
77 case 'd': 81 index = -1;
78 if (check)
79 {
80 if (GNUNET_disk_directory_test (NULL, s) == GNUNET_NO)
81 {
82 index = -1;
83 done = 1;
84 }
85 }
86 else
87 {
88 GNUNET_disk_directory_create (NULL, s);
89 }
90 if (!done)
91 index = makeHierarchyHelper (s, tree, index, check);
92 break;
93 case 'f':
94 if (check)
95 {
96 /* TODO: compare file contents */
97 if (GNUNET_disk_directory_test (NULL, s) != GNUNET_NO)
98 {
99 index = -1;
100 done = 1;
101 }
102 }
103 else
104 {
105 buf = GNUNET_malloc (FILESIZE);
106 for (i = 0; i < FILESIZE; i++)
107 buf[i] = GNUNET_random_u32 (GNUNET_RANDOM_QUALITY_WEAK, 256);
108 GNUNET_disk_file_write (ectx, s, buf, FILESIZE, "600");
109 GNUNET_free (buf);
110 }
111 break;
112 case '.':
113 done = 1; 82 done = 1;
114 break;
115 default:
116 break;
117 } 83 }
118 GNUNET_free (s); 84 }
119 fi++; 85 else
86 {
87 GNUNET_disk_directory_create (NULL, s);
88 }
89 if (!done)
90 index = makeHierarchyHelper (s, tree, index, check);
91 break;
92 case 'f':
93 if (check)
94 {
95 /* TODO: compare file contents */
96 if (GNUNET_disk_directory_test (NULL, s) != GNUNET_NO)
97 {
98 index = -1;
99 done = 1;
100 }
101 }
102 else
103 {
104 buf = GNUNET_malloc (FILESIZE);
105 for (i = 0; i < FILESIZE; i++)
106 buf[i] = GNUNET_random_u32 (GNUNET_RANDOM_QUALITY_WEAK, 256);
107 GNUNET_disk_file_write (ectx, s, buf, FILESIZE, "600");
108 GNUNET_free (buf);
109 }
110 break;
111 case '.':
112 done = 1;
113 break;
114 default:
115 break;
120 } 116 }
117 GNUNET_free (s);
118 fi++;
119 }
121 return index; 120 return index;
122} 121}
123 122
@@ -139,10 +138,10 @@ checkHierarchy (unsigned int i, const char *tree)
139 138
140 fn = makeName (i); 139 fn = makeName (i);
141 if (GNUNET_disk_directory_test (NULL, fn) != GNUNET_YES) 140 if (GNUNET_disk_directory_test (NULL, fn) != GNUNET_YES)
142 { 141 {
143 GNUNET_free (fn); 142 GNUNET_free (fn);
144 return GNUNET_SYSERR; 143 return GNUNET_SYSERR;
145 } 144 }
146 res = ((makeHierarchyHelper (fn, tree, 0, 1) == -1) ? 145 res = ((makeHierarchyHelper (fn, tree, 0, 1) == -1) ?
147 GNUNET_SYSERR : GNUNET_OK); 146 GNUNET_SYSERR : GNUNET_OK);
148 GNUNET_free (fn); 147 GNUNET_free (fn);
@@ -160,89 +159,87 @@ static void *
160eventCallback (void *cls, const GNUNET_FSUI_Event * event) 159eventCallback (void *cls, const GNUNET_FSUI_Event * event)
161{ 160{
162 switch (event->type) 161 switch (event->type)
163 { 162 {
164 case GNUNET_FSUI_download_suspended: 163 case GNUNET_FSUI_download_suspended:
165 download = NULL; 164 download = NULL;
166 break; 165 break;
167 case GNUNET_FSUI_download_resumed: 166 case GNUNET_FSUI_download_resumed:
168 download = event->data.DownloadResumed.dc.pos; 167 download = event->data.DownloadResumed.dc.pos;
169 break; 168 break;
170 break; 169 break;
171 case GNUNET_FSUI_upload_progress: 170 case GNUNET_FSUI_upload_progress:
172#if DEBUG_VERBOSE > 1 171#if DEBUG_VERBOSE > 1
173 printf ("Upload is progressing (%llu/%llu)...\n", 172 printf ("Upload is progressing (%llu/%llu)...\n",
174 event->data.UploadProgress.completed, 173 event->data.UploadProgress.completed,
175 event->data.UploadProgress.total); 174 event->data.UploadProgress.total);
176#endif 175#endif
177 break; 176 break;
178 case GNUNET_FSUI_upload_completed: 177 case GNUNET_FSUI_upload_completed:
179 upURI = GNUNET_ECRS_uri_duplicate (event->data.UploadCompleted.uri); 178 upURI = GNUNET_ECRS_uri_duplicate (event->data.UploadCompleted.uri);
180#if DEBUG_VERBOSE 179#if DEBUG_VERBOSE
181 printf ("Upload of `%s' complete.\n", 180 printf ("Upload of `%s' complete.\n", event->data.UploadCompleted.filename);
182 event->data.UploadCompleted.filename);
183#endif 181#endif
184 break; 182 break;
185 case GNUNET_FSUI_download_completed: 183 case GNUNET_FSUI_download_completed:
186#if DEBUG_VERBOSE 184#if DEBUG_VERBOSE
187 printf ("Download of `%s' complete.\n", 185 printf ("Download of `%s' complete.\n",
188 event->data.DownloadCompleted.filename); 186 event->data.DownloadCompleted.filename);
189#endif 187#endif
190 if (checkHierarchy (43, DIRECTORY_TREE_SPEC) == GNUNET_OK) 188 if (checkHierarchy (43, DIRECTORY_TREE_SPEC) == GNUNET_OK)
191 download_done = 1; 189 download_done = 1;
192#if DEBUG_VERBOSE 190#if DEBUG_VERBOSE
193 else 191 else
194 printf ("Hierarchy check not successful yet...\n"); 192 printf ("Hierarchy check not successful yet...\n");
195#endif 193#endif
196 break; 194 break;
197 case GNUNET_FSUI_download_progress: 195 case GNUNET_FSUI_download_progress:
198#if DEBUG_VERBOSE > 1 196#if DEBUG_VERBOSE > 1
199 printf ("Download is progressing (%llu/%llu)...\n", 197 printf ("Download is progressing (%llu/%llu)...\n",
200 event->data.DownloadProgress.completed, 198 event->data.DownloadProgress.completed,
201 event->data.DownloadProgress.total); 199 event->data.DownloadProgress.total);
202#endif 200#endif
203 break; 201 break;
204 case GNUNET_FSUI_unindex_progress: 202 case GNUNET_FSUI_unindex_progress:
205#if DEBUG_VERBOSE > 1 203#if DEBUG_VERBOSE > 1
206 printf ("Unindex is progressing (%llu/%llu)...\n", 204 printf ("Unindex is progressing (%llu/%llu)...\n",
207 event->data.UnindexProgress.completed, 205 event->data.UnindexProgress.completed,
208 event->data.UnindexProgress.total); 206 event->data.UnindexProgress.total);
209#endif 207#endif
210 break; 208 break;
211 case GNUNET_FSUI_unindex_completed: 209 case GNUNET_FSUI_unindex_completed:
212#if DEBUG_VERBOSE 210#if DEBUG_VERBOSE
213 printf ("Unindex complete.\n"); 211 printf ("Unindex complete.\n");
214#endif 212#endif
215 break; 213 break;
216 case GNUNET_FSUI_unindex_error: 214 case GNUNET_FSUI_unindex_error:
217 fprintf (stderr, "Error unindexing: %s\n", 215 fprintf (stderr, "Error unindexing: %s\n",
218 event->data.UnindexError.message); 216 event->data.UnindexError.message);
219 break; 217 break;
220 case GNUNET_FSUI_upload_error: 218 case GNUNET_FSUI_upload_error:
221 fprintf (stderr, "Error uploading: %s\n", 219 fprintf (stderr, "Error uploading: %s\n", event->data.UploadError.message);
222 event->data.UploadError.message); 220 break;
223 break; 221 case GNUNET_FSUI_download_error:
224 case GNUNET_FSUI_download_error: 222 fprintf (stderr, "Error downloading: %s\n",
225 fprintf (stderr, "Error downloading: %s\n", 223 event->data.DownloadError.message);
226 event->data.DownloadError.message); 224 break;
227 break; 225 case GNUNET_FSUI_download_aborted:
228 case GNUNET_FSUI_download_aborted:
229#if DEBUG_VERBOSE 226#if DEBUG_VERBOSE
230 printf ("Received download aborted event.\n"); 227 printf ("Received download aborted event.\n");
231#endif 228#endif
232 break; 229 break;
233 case GNUNET_FSUI_unindex_suspended: 230 case GNUNET_FSUI_unindex_suspended:
234 case GNUNET_FSUI_upload_suspended: 231 case GNUNET_FSUI_upload_suspended:
235 case GNUNET_FSUI_upload_started: 232 case GNUNET_FSUI_upload_started:
236 case GNUNET_FSUI_upload_stopped: 233 case GNUNET_FSUI_upload_stopped:
237 case GNUNET_FSUI_download_started: 234 case GNUNET_FSUI_download_started:
238 case GNUNET_FSUI_download_stopped: 235 case GNUNET_FSUI_download_stopped:
239 case GNUNET_FSUI_unindex_started: 236 case GNUNET_FSUI_unindex_started:
240 case GNUNET_FSUI_unindex_stopped: 237 case GNUNET_FSUI_unindex_stopped:
241 break; 238 break;
242 default: 239 default:
243 printf ("Unexpected event: %d\n", event->type); 240 printf ("Unexpected event: %d\n", event->type);
244 break; 241 break;
245 } 242 }
246 if (lastEvent == waitForEvent) 243 if (lastEvent == waitForEvent)
247 return NULL; /* ignore all other events */ 244 return NULL; /* ignore all other events */
248 lastEvent = event->type; 245 lastEvent = event->type;
@@ -261,6 +258,7 @@ main (int argc, char *argv[])
261 int ok; 258 int ok;
262 char *fn = NULL; 259 char *fn = NULL;
263 char *fn43 = NULL; 260 char *fn43 = NULL;
261
264 char *keywords[] = { 262 char *keywords[] = {
265 "down_foo", 263 "down_foo",
266 "down_bar", 264 "down_bar",
@@ -274,20 +272,18 @@ main (int argc, char *argv[])
274 ok = GNUNET_YES; 272 ok = GNUNET_YES;
275 cfg = GNUNET_GC_create (); 273 cfg = GNUNET_GC_create ();
276 if (-1 == GNUNET_GC_parse_configuration (cfg, "check.conf")) 274 if (-1 == GNUNET_GC_parse_configuration (cfg, "check.conf"))
277 { 275 {
278 GNUNET_GC_free (cfg); 276 GNUNET_GC_free (cfg);
279 return -1; 277 return -1;
280 } 278 }
281 fprintf(stderr, 279 fprintf (stderr, "Setup...\n");
282 "Setup...\n");
283#if START_DAEMON 280#if START_DAEMON
284 GNUNET_disk_directory_remove (NULL, 281 GNUNET_disk_directory_remove (NULL,
285 "/tmp/gnunet-fsui-recursive_download_test/"); 282 "/tmp/gnunet-fsui-recursive_download_test/");
286 daemon = GNUNET_daemon_start (NULL, cfg, "peer.conf", GNUNET_NO); 283 daemon = GNUNET_daemon_start (NULL, cfg, "peer.conf", GNUNET_NO);
287 GNUNET_GE_ASSERT (NULL, daemon != NULL); 284 GNUNET_GE_ASSERT (NULL, daemon != NULL);
288 CHECK (GNUNET_OK == 285 CHECK (GNUNET_OK ==
289 GNUNET_wait_for_daemon_running (NULL, cfg, 286 GNUNET_wait_for_daemon_running (NULL, cfg, 30 * GNUNET_CRON_SECONDS));
290 30 * GNUNET_CRON_SECONDS));
291 GNUNET_thread_sleep (5 * GNUNET_CRON_SECONDS); /* give apps time to start */ 287 GNUNET_thread_sleep (5 * GNUNET_CRON_SECONDS); /* give apps time to start */
292 /* ACTUAL TEST CODE */ 288 /* ACTUAL TEST CODE */
293#endif 289#endif
@@ -298,10 +294,9 @@ main (int argc, char *argv[])
298 fn = makeHierarchy (42, DIRECTORY_TREE_SPEC); 294 fn = makeHierarchy (42, DIRECTORY_TREE_SPEC);
299 meta = GNUNET_meta_data_create (); 295 meta = GNUNET_meta_data_create ();
300 kuri = 296 kuri =
301 GNUNET_ECRS_keyword_command_line_to_uri (ectx, 2, 297 GNUNET_ECRS_keyword_command_line_to_uri (ectx, 2,
302 (const char **) keywords); 298 (const char **) keywords);
303 fprintf(stderr, 299 fprintf (stderr, "Uploading...\n");
304 "Uploading...\n");
305 waitForEvent = GNUNET_FSUI_upload_completed; 300 waitForEvent = GNUNET_FSUI_upload_completed;
306 upload = GNUNET_FSUI_upload_start (ctx, 301 upload = GNUNET_FSUI_upload_start (ctx,
307 fn, 302 fn,
@@ -315,19 +310,18 @@ main (int argc, char *argv[])
315 kuri = NULL; 310 kuri = NULL;
316 prog = 0; 311 prog = 0;
317 while (lastEvent != GNUNET_FSUI_upload_completed) 312 while (lastEvent != GNUNET_FSUI_upload_completed)
318 { 313 {
319 prog++; 314 prog++;
320 CHECK (prog < 5000); 315 CHECK (prog < 5000);
321 GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS); 316 GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
322 if (GNUNET_shutdown_test () == GNUNET_YES) 317 if (GNUNET_shutdown_test () == GNUNET_YES)
323 break; 318 break;
324 } 319 }
325 GNUNET_FSUI_upload_stop (upload); 320 GNUNET_FSUI_upload_stop (upload);
326 upload = NULL; 321 upload = NULL;
327 CHECK (upURI != NULL); 322 CHECK (upURI != NULL);
328 323
329 fprintf(stderr, 324 fprintf (stderr, "Downloading...\n");
330 "Downloading...\n");
331 waitForEvent = GNUNET_FSUI_download_completed; 325 waitForEvent = GNUNET_FSUI_download_completed;
332 fn43 = makeName (43); 326 fn43 = makeName (43);
333 download = GNUNET_FSUI_download_start (ctx, 327 download = GNUNET_FSUI_download_start (ctx,
@@ -339,29 +333,28 @@ main (int argc, char *argv[])
339 fn43 = NULL; 333 fn43 = NULL;
340 prog = 0; 334 prog = 0;
341 while (!download_done) 335 while (!download_done)
342 { 336 {
343 prog++; 337 prog++;
344 CHECK (prog < 5000); 338 CHECK (prog < 5000);
345 GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS); 339 GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
346 if (GNUNET_shutdown_test () == GNUNET_YES) 340 if (GNUNET_shutdown_test () == GNUNET_YES)
347 break; 341 break;
348 } 342 }
349FAILURE: 343FAILURE:
350 fprintf(stderr, 344 fprintf (stderr, "Cleanup...\n");
351 "Cleanup...\n");
352 if (meta != NULL) 345 if (meta != NULL)
353 GNUNET_meta_data_destroy (meta); 346 GNUNET_meta_data_destroy (meta);
354 if (ctx != NULL) 347 if (ctx != NULL)
355 { 348 {
356 if (download != NULL) 349 if (download != NULL)
357 GNUNET_FSUI_download_stop (download); 350 GNUNET_FSUI_download_stop (download);
358 GNUNET_FSUI_stop (ctx); 351 GNUNET_FSUI_stop (ctx);
359 } 352 }
360 if (fn != NULL) 353 if (fn != NULL)
361 { 354 {
362 GNUNET_disk_directory_remove (NULL, fn); 355 GNUNET_disk_directory_remove (NULL, fn);
363 GNUNET_free (fn); 356 GNUNET_free (fn);
364 } 357 }
365 if (kuri != NULL) 358 if (kuri != NULL)
366 GNUNET_ECRS_uri_destroy (kuri); 359 GNUNET_ECRS_uri_destroy (kuri);
367 fn43 = makeName (43); 360 fn43 = makeName (43);
diff --git a/src/fs/test_fs_file_information.c b/src/fs/test_fs_file_information.c
index 00e3c2211..97a63062e 100644
--- a/src/fs/test_fs_file_information.c
+++ b/src/fs/test_fs_file_information.c
@@ -45,19 +45,17 @@
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 51
52static int 52static int
53mycleaner(void *cls, 53mycleaner (void *cls,
54 struct GNUNET_FS_FileInformation *fi, 54 struct GNUNET_FS_FileInformation *fi,
55 uint64_t length, 55 uint64_t length,
56 struct GNUNET_CONTAINER_MetaData *meta, 56 struct GNUNET_CONTAINER_MetaData *meta,
57 struct GNUNET_FS_Uri **uri, 57 struct GNUNET_FS_Uri **uri,
58 struct GNUNET_FS_BlockOptions *bo, 58 struct GNUNET_FS_BlockOptions *bo, int *do_index, void **client_info)
59 int *do_index,
60 void **client_info)
61{ 59{
62 return GNUNET_OK; 60 return GNUNET_OK;
63} 61}
@@ -66,8 +64,7 @@ mycleaner(void *cls,
66static void 64static void
67run (void *cls, 65run (void *cls,
68 char *const *args, 66 char *const *args,
69 const char *cfgfile, 67 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
70 const struct GNUNET_CONFIGURATION_Handle *cfg)
71{ 68{
72 const char *keywords[] = { 69 const char *keywords[] = {
73 "down_foo", 70 "down_foo",
@@ -86,17 +83,17 @@ run (void *cls,
86 struct GNUNET_FS_BlockOptions bo; 83 struct GNUNET_FS_BlockOptions bo;
87 84
88 fs = GNUNET_FS_start (cfg, "test-fs-file-information", NULL, NULL, 85 fs = GNUNET_FS_start (cfg, "test-fs-file-information", NULL, NULL,
89 GNUNET_FS_FLAGS_NONE, 86 GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
90 GNUNET_FS_OPTIONS_END);
91 fn1 = GNUNET_DISK_mktemp ("gnunet-file_information-test-dst"); 87 fn1 = GNUNET_DISK_mktemp ("gnunet-file_information-test-dst");
92 buf = GNUNET_malloc (FILESIZE); 88 buf = GNUNET_malloc (FILESIZE);
93 for (i = 0; i < FILESIZE; i++) 89 for (i = 0; i < FILESIZE; i++)
94 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); 90 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
95 GNUNET_assert (FILESIZE == 91 GNUNET_assert (FILESIZE ==
96 GNUNET_DISK_fn_write (fn1, 92 GNUNET_DISK_fn_write (fn1,
97 buf, 93 buf,
98 FILESIZE, 94 FILESIZE,
99 GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE)); 95 GNUNET_DISK_PERM_USER_READ |
96 GNUNET_DISK_PERM_USER_WRITE));
100 GNUNET_free (buf); 97 GNUNET_free (buf);
101 98
102 fn2 = GNUNET_DISK_mktemp ("gnunet-file_information-test-dst"); 99 fn2 = GNUNET_DISK_mktemp ("gnunet-file_information-test-dst");
@@ -104,48 +101,41 @@ run (void *cls,
104 for (i = 0; i < FILESIZE; i++) 101 for (i = 0; i < FILESIZE; i++)
105 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); 102 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
106 GNUNET_assert (FILESIZE == 103 GNUNET_assert (FILESIZE ==
107 GNUNET_DISK_fn_write (fn2, 104 GNUNET_DISK_fn_write (fn2,
108 buf, 105 buf,
109 FILESIZE, 106 FILESIZE,
110 GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE)); 107 GNUNET_DISK_PERM_USER_READ |
108 GNUNET_DISK_PERM_USER_WRITE));
111 GNUNET_free (buf); 109 GNUNET_free (buf);
112 110
113 meta = GNUNET_CONTAINER_meta_data_create (); 111 meta = GNUNET_CONTAINER_meta_data_create ();
114 kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords); 112 kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords);
115 bo.content_priority = 42; 113 bo.content_priority = 42;
116 bo.anonymity_level = 1; 114 bo.anonymity_level = 1;
117 bo.replication_level = 0; 115 bo.replication_level = 0;
118 bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME); 116 bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME);
119 fi1 = GNUNET_FS_file_information_create_from_file (fs, 117 fi1 = GNUNET_FS_file_information_create_from_file (fs,
120 "file_information-context1", 118 "file_information-context1",
121 fn1, 119 fn1,
122 kuri, 120 kuri,
123 meta, 121 meta, GNUNET_YES, &bo);
124 GNUNET_YES,
125 &bo);
126 GNUNET_assert (fi1 != NULL); 122 GNUNET_assert (fi1 != NULL);
127 fi2 = GNUNET_FS_file_information_create_from_file (fs, 123 fi2 = GNUNET_FS_file_information_create_from_file (fs,
128 "file_information-context2", 124 "file_information-context2",
129 fn2, 125 fn2,
130 kuri, 126 kuri,
131 meta, 127 meta, GNUNET_YES, &bo);
132 GNUNET_YES,
133 &bo);
134 GNUNET_assert (fi2 != NULL); 128 GNUNET_assert (fi2 != NULL);
135 fidir = GNUNET_FS_file_information_create_empty_directory (fs, 129 fidir = GNUNET_FS_file_information_create_empty_directory (fs,
136 "file_information-context-dir", 130 "file_information-context-dir",
137 kuri, 131 kuri, meta, &bo);
138 meta,
139 &bo);
140 GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi1)); 132 GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi1));
141 GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi2)); 133 GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi2));
142 GNUNET_FS_uri_destroy (kuri); 134 GNUNET_FS_uri_destroy (kuri);
143 GNUNET_CONTAINER_meta_data_destroy (meta); 135 GNUNET_CONTAINER_meta_data_destroy (meta);
144 GNUNET_assert (NULL != fidir); 136 GNUNET_assert (NULL != fidir);
145 /* FIXME: test more of API! */ 137 /* FIXME: test more of API! */
146 GNUNET_FS_file_information_destroy (fidir, 138 GNUNET_FS_file_information_destroy (fidir, &mycleaner, NULL);
147 &mycleaner,
148 NULL);
149 GNUNET_DISK_directory_remove (fn1); 139 GNUNET_DISK_directory_remove (fn1);
150 GNUNET_DISK_directory_remove (fn2); 140 GNUNET_DISK_directory_remove (fn2);
151 GNUNET_free_non_null (fn1); 141 GNUNET_free_non_null (fn1);
@@ -164,45 +154,47 @@ testThumbnail ()
164 size_t size; 154 size_t size;
165 char *date; 155 char *date;
166 156
167 ex = EXTRACTOR_plugin_add_config (NULL, "thumbnailgtk", EXTRACTOR_OPTION_DEFAULT_POLICY); 157 ex = EXTRACTOR_plugin_add_config (NULL, "thumbnailgtk",
158 EXTRACTOR_OPTION_DEFAULT_POLICY);
168 if (ex == NULL) 159 if (ex == NULL)
169 { 160 {
170 fprintf (stderr, 161 fprintf (stderr,
171 "Test incomplete, have no GTK thumbnail extractor available.\n"); 162 "Test incomplete, have no GTK thumbnail extractor available.\n");
172 return 0; /* can not test, no thumbnailer */ 163 return 0; /* can not test, no thumbnailer */
173 } 164 }
174 ex = EXTRACTOR_plugin_add_config (ex, "mime", EXTRACTOR_OPTION_DEFAULT_POLICY); 165 ex = EXTRACTOR_plugin_add_config (ex, "mime",
166 EXTRACTOR_OPTION_DEFAULT_POLICY);
175 m = GNUNET_CONTAINER_meta_data_create (); 167 m = GNUNET_CONTAINER_meta_data_create ();
176 if (3 != GNUNET_FS_meta_data_extract_from_file (m, 168 if (3 != GNUNET_FS_meta_data_extract_from_file (m,
177 "test_fs_file_information_meta_data_image.jpg", 169 "test_fs_file_information_meta_data_image.jpg",
178 ex)) 170 ex))
179 { 171 {
180 GNUNET_break (0); 172 GNUNET_break (0);
181 EXTRACTOR_plugin_remove_all (ex); 173 EXTRACTOR_plugin_remove_all (ex);
182 GNUNET_CONTAINER_meta_data_destroy (m); 174 GNUNET_CONTAINER_meta_data_destroy (m);
183 return 1; 175 return 1;
184 } 176 }
185 EXTRACTOR_plugin_remove_all (ex); 177 EXTRACTOR_plugin_remove_all (ex);
186 d = GNUNET_CONTAINER_meta_data_duplicate (m); 178 d = GNUNET_CONTAINER_meta_data_duplicate (m);
187 GNUNET_CONTAINER_meta_data_destroy (m); 179 GNUNET_CONTAINER_meta_data_destroy (m);
188 thumb = NULL; 180 thumb = NULL;
189 size = GNUNET_CONTAINER_meta_data_get_thumbnail (d, &thumb); 181 size = GNUNET_CONTAINER_meta_data_get_thumbnail (d, &thumb);
190 if (size == 0) 182 if (size == 0)
191 { 183 {
192 GNUNET_break (0); 184 GNUNET_break (0);
193 GNUNET_CONTAINER_meta_data_destroy (d); 185 GNUNET_CONTAINER_meta_data_destroy (d);
194 return 1; 186 return 1;
195 } 187 }
196 GNUNET_free (thumb); 188 GNUNET_free (thumb);
197 GNUNET_CONTAINER_meta_data_add_publication_date (d); 189 GNUNET_CONTAINER_meta_data_add_publication_date (d);
198 date = GNUNET_CONTAINER_meta_data_get_by_type (d, 190 date = GNUNET_CONTAINER_meta_data_get_by_type (d,
199 EXTRACTOR_METATYPE_PUBLICATION_DATE); 191 EXTRACTOR_METATYPE_PUBLICATION_DATE);
200 if (date == NULL) 192 if (date == NULL)
201 { 193 {
202 GNUNET_break (0); 194 GNUNET_break (0);
203 GNUNET_CONTAINER_meta_data_destroy (d); 195 GNUNET_CONTAINER_meta_data_destroy (d);
204 return 1; 196 return 1;
205 } 197 }
206 GNUNET_free (date); 198 GNUNET_free (date);
207 GNUNET_CONTAINER_meta_data_destroy (d); 199 GNUNET_CONTAINER_meta_data_destroy (d);
208 return 0; 200 return 0;
@@ -213,7 +205,7 @@ testThumbnail ()
213int 205int
214main (int argc, char *argv[]) 206main (int argc, char *argv[])
215{ 207{
216 char *const argvx[] = { 208 char *const argvx[] = {
217 "test-fs-file_information", 209 "test-fs-file_information",
218 "-c", 210 "-c",
219 "test_fs_file_information_data.conf", 211 "test_fs_file_information_data.conf",
@@ -226,18 +218,18 @@ main (int argc, char *argv[])
226 GNUNET_GETOPT_OPTION_END 218 GNUNET_GETOPT_OPTION_END
227 }; 219 };
228 220
229 GNUNET_log_setup ("test_fs_file_information", 221 GNUNET_log_setup ("test_fs_file_information",
230#if VERBOSE 222#if VERBOSE
231 "DEBUG", 223 "DEBUG",
232#else 224#else
233 "WARNING", 225 "WARNING",
234#endif 226#endif
235 NULL); 227 NULL);
236 if (0 != testThumbnail ()) 228 if (0 != testThumbnail ())
237 return 1; 229 return 1;
238 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, 230 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
239 argvx, "test-fs-file_information", 231 argvx, "test-fs-file_information",
240 "nohelp", options, &run, NULL); 232 "nohelp", options, &run, NULL);
241 return 0; 233 return 0;
242} 234}
243 235
diff --git a/src/fs/test_fs_getopt.c b/src/fs/test_fs_getopt.c
index e52984877..2b0a9fca8 100644
--- a/src/fs/test_fs_getopt.c
+++ b/src/fs/test_fs_getopt.c
@@ -28,13 +28,13 @@
28int 28int
29main (int argc, char *argv[]) 29main (int argc, char *argv[])
30{ 30{
31 GNUNET_log_setup ("test_fs_directory", 31 GNUNET_log_setup ("test_fs_directory",
32#if VERBOSE 32#if VERBOSE
33 "DEBUG", 33 "DEBUG",
34#else 34#else
35 "WARNING", 35 "WARNING",
36#endif 36#endif
37 NULL); 37 NULL);
38 fprintf (stderr, "WARNING: testcase not yet written.\n"); 38 fprintf (stderr, "WARNING: testcase not yet written.\n");
39 return 0; /* testcase passed */ 39 return 0; /* testcase passed */
40} 40}
diff --git a/src/fs/test_fs_list_indexed.c b/src/fs/test_fs_list_indexed.c
index b46ebf52d..e3330f3ba 100644
--- a/src/fs/test_fs_list_indexed.c
+++ b/src/fs/test_fs_list_indexed.c
@@ -49,7 +49,7 @@
49 49
50/** 50/**
51 * How long should our test-content live? 51 * How long should our test-content live?
52 */ 52 */
53#define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) 53#define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)
54 54
55struct PeerContext 55struct PeerContext
@@ -75,8 +75,7 @@ static char *fn2;
75static int err; 75static int err;
76 76
77static void 77static void
78abort_publish_task (void *cls, 78abort_publish_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
79 const struct GNUNET_SCHEDULER_TaskContext *tc)
80{ 79{
81 GNUNET_FS_publish_stop (publish); 80 GNUNET_FS_publish_stop (publish);
82 publish = NULL; 81 publish = NULL;
@@ -90,101 +89,96 @@ abort_publish_task (void *cls,
90 89
91 90
92static void 91static void
93list_indexed_task (void *cls, 92list_indexed_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
94 const struct GNUNET_SCHEDULER_TaskContext *tc)
95{ 93{
96 94
97 GNUNET_SCHEDULER_add_continuation (&abort_publish_task, 95 GNUNET_SCHEDULER_add_continuation (&abort_publish_task,
98 NULL, 96 NULL, GNUNET_SCHEDULER_REASON_PREREQ_DONE);
99 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
100} 97}
101 98
102 99
103static void * 100static void *
104progress_cb (void *cls, 101progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
105 const struct GNUNET_FS_ProgressInfo *event)
106{ 102{
107 void *ret; 103 void *ret;
108 104
109 ret = NULL; 105 ret = NULL;
110 switch (event->status) 106 switch (event->status)
111 { 107 {
112 case GNUNET_FS_STATUS_PUBLISH_COMPLETED: 108 case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
113 ret = event->value.publish.cctx; 109 ret = event->value.publish.cctx;
114 printf ("Publish complete, %llu kbps.\n", 110 printf ("Publish complete, %llu kbps.\n",
115 (unsigned long long) (FILESIZE * 1000 / (1+GNUNET_TIME_absolute_get_duration (start).rel_value) / 1024)); 111 (unsigned long long) (FILESIZE * 1000 /
116 if (0 == strcmp ("list_indexed-context-dir", 112 (1 +
117 event->value.publish.cctx)) 113 GNUNET_TIME_absolute_get_duration
118 GNUNET_SCHEDULER_add_continuation (&list_indexed_task, 114 (start).rel_value) / 1024));
119 NULL, 115 if (0 == strcmp ("list_indexed-context-dir", event->value.publish.cctx))
120 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 116 GNUNET_SCHEDULER_add_continuation (&list_indexed_task,
121 117 NULL,
122 break; 118 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
123 case GNUNET_FS_STATUS_PUBLISH_PROGRESS: 119
124 ret = event->value.publish.cctx; 120 break;
125 GNUNET_assert (publish == event->value.publish.pc); 121 case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
122 ret = event->value.publish.cctx;
123 GNUNET_assert (publish == event->value.publish.pc);
126#if VERBOSE 124#if VERBOSE
127 printf ("Publish is progressing (%llu/%llu at level %u off %llu)...\n", 125 printf ("Publish is progressing (%llu/%llu at level %u off %llu)...\n",
128 (unsigned long long) event->value.publish.completed, 126 (unsigned long long) event->value.publish.completed,
129 (unsigned long long) event->value.publish.size, 127 (unsigned long long) event->value.publish.size,
130 event->value.publish.specifics.progress.depth, 128 event->value.publish.specifics.progress.depth,
131 (unsigned long long) event->value.publish.specifics.progress.offset); 129 (unsigned long long) event->value.publish.specifics.
130 progress.offset);
132#endif 131#endif
133 break; 132 break;
134 case GNUNET_FS_STATUS_PUBLISH_ERROR: 133 case GNUNET_FS_STATUS_PUBLISH_ERROR:
135 ret = event->value.publish.cctx; 134 ret = event->value.publish.cctx;
136 fprintf (stderr, 135 fprintf (stderr,
137 "Error publishing file: %s\n", 136 "Error publishing file: %s\n",
138 event->value.publish.specifics.error.message); 137 event->value.publish.specifics.error.message);
139 err = 1; 138 err = 1;
140 if (0 == strcmp ("list_indexed-context-dir", 139 if (0 == strcmp ("list_indexed-context-dir", event->value.publish.cctx))
141 event->value.publish.cctx)) 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_PUBLISH_START:
146 case GNUNET_FS_STATUS_PUBLISH_START: 145 ret = event->value.publish.cctx;
147 ret = event->value.publish.cctx; 146 if (0 == strcmp ("list_indexed-context1", event->value.publish.cctx))
148 if (0 == strcmp ("list_indexed-context1", 147 {
149 event->value.publish.cctx)) 148 GNUNET_assert (0 == strcmp ("list_indexed-context-dir",
150 { 149 event->value.publish.pctx));
151 GNUNET_assert (0 == strcmp ("list_indexed-context-dir", 150 GNUNET_assert (FILESIZE == event->value.publish.size);
152 event->value.publish.pctx)); 151 GNUNET_assert (0 == event->value.publish.completed);
153 GNUNET_assert (FILESIZE == event->value.publish.size); 152 GNUNET_assert (1 == event->value.publish.anonymity);
154 GNUNET_assert (0 == event->value.publish.completed);
155 GNUNET_assert (1 == event->value.publish.anonymity);
156 }
157 else if (0 == strcmp ("list_indexed-context2",
158 event->value.publish.cctx))
159 {
160 GNUNET_assert (0 == strcmp ("list_indexed-context-dir",
161 event->value.publish.pctx));
162 GNUNET_assert (FILESIZE == event->value.publish.size);
163 GNUNET_assert (0 == event->value.publish.completed);
164 GNUNET_assert (2 == event->value.publish.anonymity);
165 }
166 else if (0 == strcmp ("list_indexed-context-dir",
167 event->value.publish.cctx))
168 {
169 GNUNET_assert (0 == event->value.publish.completed);
170 GNUNET_assert (3 == event->value.publish.anonymity);
171 }
172 else
173 GNUNET_assert (0);
174 break;
175 case GNUNET_FS_STATUS_PUBLISH_STOPPED:
176 if (0 == strcmp ("list_indexed-context-dir",
177 event->value.publish.cctx))
178 {
179 GNUNET_assert (publish == event->value.publish.pc);
180 publish = NULL;
181 }
182 break;
183 default:
184 printf ("Unexpected event: %d\n",
185 event->status);
186 break;
187 } 153 }
154 else if (0 == strcmp ("list_indexed-context2", event->value.publish.cctx))
155 {
156 GNUNET_assert (0 == strcmp ("list_indexed-context-dir",
157 event->value.publish.pctx));
158 GNUNET_assert (FILESIZE == event->value.publish.size);
159 GNUNET_assert (0 == event->value.publish.completed);
160 GNUNET_assert (2 == event->value.publish.anonymity);
161 }
162 else if (0 == strcmp ("list_indexed-context-dir",
163 event->value.publish.cctx))
164 {
165 GNUNET_assert (0 == event->value.publish.completed);
166 GNUNET_assert (3 == event->value.publish.anonymity);
167 }
168 else
169 GNUNET_assert (0);
170 break;
171 case GNUNET_FS_STATUS_PUBLISH_STOPPED:
172 if (0 == strcmp ("list_indexed-context-dir", event->value.publish.cctx))
173 {
174 GNUNET_assert (publish == event->value.publish.pc);
175 publish = NULL;
176 }
177 break;
178 default:
179 printf ("Unexpected event: %d\n", event->status);
180 break;
181 }
188 return ret; 182 return ret;
189} 183}
190 184
@@ -195,11 +189,11 @@ setup_peer (struct PeerContext *p, const char *cfgname)
195 p->cfg = GNUNET_CONFIGURATION_create (); 189 p->cfg = GNUNET_CONFIGURATION_create ();
196#if START_ARM 190#if START_ARM
197 p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", 191 p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
198 "gnunet-service-arm", 192 "gnunet-service-arm",
199#if VERBOSE 193#if VERBOSE
200 "-L", "DEBUG", 194 "-L", "DEBUG",
201#endif 195#endif
202 "-c", cfgname, NULL); 196 "-c", cfgname, NULL);
203#endif 197#endif
204 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); 198 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
205} 199}
@@ -210,16 +204,17 @@ stop_arm (struct PeerContext *p)
210{ 204{
211#if START_ARM 205#if START_ARM
212 if (NULL != p->arm_proc) 206 if (NULL != p->arm_proc)
213 { 207 {
214 if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) 208 if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
215 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 209 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
216 if (GNUNET_OS_process_wait(p->arm_proc) != GNUNET_OK) 210 if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
217 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); 211 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
218 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 212 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
219 "ARM process %u stopped\n", GNUNET_OS_process_get_pid (p->arm_proc)); 213 "ARM process %u stopped\n",
220 GNUNET_OS_process_close (p->arm_proc); 214 GNUNET_OS_process_get_pid (p->arm_proc));
221 p->arm_proc = NULL; 215 GNUNET_OS_process_close (p->arm_proc);
222 } 216 p->arm_proc = NULL;
217 }
223#endif 218#endif
224 GNUNET_CONFIGURATION_destroy (p->cfg); 219 GNUNET_CONFIGURATION_destroy (p->cfg);
225} 220}
@@ -228,8 +223,7 @@ stop_arm (struct PeerContext *p)
228static void 223static void
229run (void *cls, 224run (void *cls,
230 char *const *args, 225 char *const *args,
231 const char *cfgfile, 226 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
232 const struct GNUNET_CONFIGURATION_Handle *cfg)
233{ 227{
234 const char *keywords[] = { 228 const char *keywords[] = {
235 "down_foo", 229 "down_foo",
@@ -246,21 +240,20 @@ run (void *cls,
246 240
247 setup_peer (&p1, "test_fs_list_indexed_data.conf"); 241 setup_peer (&p1, "test_fs_list_indexed_data.conf");
248 fs = GNUNET_FS_start (cfg, 242 fs = GNUNET_FS_start (cfg,
249 "test-fs-list_indexed", 243 "test-fs-list_indexed",
250 &progress_cb, 244 &progress_cb,
251 NULL, 245 NULL, GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
252 GNUNET_FS_FLAGS_NONE, 246 GNUNET_assert (NULL != fs);
253 GNUNET_FS_OPTIONS_END);
254 GNUNET_assert (NULL != fs);
255 fn1 = GNUNET_DISK_mktemp ("gnunet-list_indexed-test-dst"); 247 fn1 = GNUNET_DISK_mktemp ("gnunet-list_indexed-test-dst");
256 buf = GNUNET_malloc (FILESIZE); 248 buf = GNUNET_malloc (FILESIZE);
257 for (i = 0; i < FILESIZE; i++) 249 for (i = 0; i < FILESIZE; i++)
258 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); 250 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
259 GNUNET_assert (FILESIZE == 251 GNUNET_assert (FILESIZE ==
260 GNUNET_DISK_fn_write (fn1, 252 GNUNET_DISK_fn_write (fn1,
261 buf, 253 buf,
262 FILESIZE, 254 FILESIZE,
263 GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE)); 255 GNUNET_DISK_PERM_USER_READ |
256 GNUNET_DISK_PERM_USER_WRITE));
264 GNUNET_free (buf); 257 GNUNET_free (buf);
265 258
266 fn2 = GNUNET_DISK_mktemp ("gnunet-list_indexed-test-dst"); 259 fn2 = GNUNET_DISK_mktemp ("gnunet-list_indexed-test-dst");
@@ -268,10 +261,11 @@ run (void *cls,
268 for (i = 0; i < FILESIZE; i++) 261 for (i = 0; i < FILESIZE; i++)
269 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); 262 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
270 GNUNET_assert (FILESIZE == 263 GNUNET_assert (FILESIZE ==
271 GNUNET_DISK_fn_write (fn2, 264 GNUNET_DISK_fn_write (fn2,
272 buf, 265 buf,
273 FILESIZE, 266 FILESIZE,
274 GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE)); 267 GNUNET_DISK_PERM_USER_READ |
268 GNUNET_DISK_PERM_USER_WRITE));
275 GNUNET_free (buf); 269 GNUNET_free (buf);
276 270
277 meta = GNUNET_CONTAINER_meta_data_create (); 271 meta = GNUNET_CONTAINER_meta_data_create ();
@@ -279,30 +273,24 @@ run (void *cls,
279 bo.content_priority = 42; 273 bo.content_priority = 42;
280 bo.anonymity_level = 1; 274 bo.anonymity_level = 1;
281 bo.replication_level = 0; 275 bo.replication_level = 0;
282 bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME); 276 bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME);
283 fi1 = GNUNET_FS_file_information_create_from_file (fs, 277 fi1 = GNUNET_FS_file_information_create_from_file (fs,
284 "list_indexed-context1", 278 "list_indexed-context1",
285 fn1, 279 fn1,
286 kuri, 280 kuri,
287 meta, 281 meta, GNUNET_YES, &bo);
288 GNUNET_YES,
289 &bo);
290 GNUNET_assert (NULL != fi1); 282 GNUNET_assert (NULL != fi1);
291 bo.anonymity_level = 2; 283 bo.anonymity_level = 2;
292 fi2 = GNUNET_FS_file_information_create_from_file (fs, 284 fi2 = GNUNET_FS_file_information_create_from_file (fs,
293 "list_indexed-context2", 285 "list_indexed-context2",
294 fn2, 286 fn2,
295 kuri, 287 kuri,
296 meta, 288 meta, GNUNET_YES, &bo);
297 GNUNET_YES,
298 &bo);
299 GNUNET_assert (NULL != fi2); 289 GNUNET_assert (NULL != fi2);
300 bo.anonymity_level = 3; 290 bo.anonymity_level = 3;
301 fidir = GNUNET_FS_file_information_create_empty_directory (fs, 291 fidir = GNUNET_FS_file_information_create_empty_directory (fs,
302 "list_indexed-context-dir", 292 "list_indexed-context-dir",
303 kuri, 293 kuri, meta, &bo);
304 meta,
305 &bo);
306 GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi1)); 294 GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi1));
307 GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi2)); 295 GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi2));
308 GNUNET_FS_uri_destroy (kuri); 296 GNUNET_FS_uri_destroy (kuri);
@@ -310,9 +298,9 @@ run (void *cls,
310 GNUNET_assert (NULL != fidir); 298 GNUNET_assert (NULL != fidir);
311 start = GNUNET_TIME_absolute_get (); 299 start = GNUNET_TIME_absolute_get ();
312 publish = GNUNET_FS_publish_start (fs, 300 publish = GNUNET_FS_publish_start (fs,
313 fidir, 301 fidir,
314 NULL, NULL, NULL, 302 NULL, NULL, NULL,
315 GNUNET_FS_PUBLISH_OPTION_NONE); 303 GNUNET_FS_PUBLISH_OPTION_NONE);
316 GNUNET_assert (publish != NULL); 304 GNUNET_assert (publish != NULL);
317} 305}
318 306
@@ -320,7 +308,7 @@ run (void *cls,
320int 308int
321main (int argc, char *argv[]) 309main (int argc, char *argv[])
322{ 310{
323 char *const argvx[] = { 311 char *const argvx[] = {
324 "test-fs-list_indexed", 312 "test-fs-list_indexed",
325 "-c", 313 "-c",
326 "test_fs_list_indexed_data.conf", 314 "test_fs_list_indexed_data.conf",
@@ -333,28 +321,28 @@ main (int argc, char *argv[])
333 GNUNET_GETOPT_OPTION_END 321 GNUNET_GETOPT_OPTION_END
334 }; 322 };
335 323
336 GNUNET_log_setup ("test_fs_list_indexed", 324 GNUNET_log_setup ("test_fs_list_indexed",
337#if VERBOSE 325#if VERBOSE
338 "DEBUG", 326 "DEBUG",
339#else 327#else
340 "WARNING", 328 "WARNING",
341#endif 329#endif
342 NULL); 330 NULL);
343 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, 331 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
344 argvx, "test-fs-list_indexed", 332 argvx, "test-fs-list_indexed",
345 "nohelp", options, &run, NULL); 333 "nohelp", options, &run, NULL);
346 stop_arm (&p1); 334 stop_arm (&p1);
347 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-list-indexed/"); 335 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-list-indexed/");
348 if (fn1 != NULL) 336 if (fn1 != NULL)
349 { 337 {
350 GNUNET_DISK_directory_remove (fn1); 338 GNUNET_DISK_directory_remove (fn1);
351 GNUNET_free (fn1); 339 GNUNET_free (fn1);
352 } 340 }
353 if (fn2 != NULL) 341 if (fn2 != NULL)
354 { 342 {
355 GNUNET_DISK_directory_remove (fn2); 343 GNUNET_DISK_directory_remove (fn2);
356 GNUNET_free (fn2); 344 GNUNET_free (fn2);
357 } 345 }
358 return err; 346 return err;
359} 347}
360 348
diff --git a/src/fs/test_fs_namespace.c b/src/fs/test_fs_namespace.c
index b4d487ddc..96caa8dfa 100644
--- a/src/fs/test_fs_namespace.c
+++ b/src/fs/test_fs_namespace.c
@@ -67,11 +67,11 @@ setup_peer (struct PeerContext *p, const char *cfgname)
67 p->cfg = GNUNET_CONFIGURATION_create (); 67 p->cfg = GNUNET_CONFIGURATION_create ();
68#if START_ARM 68#if START_ARM
69 p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", 69 p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
70 "gnunet-service-arm", 70 "gnunet-service-arm",
71#if VERBOSE 71#if VERBOSE
72 "-L", "DEBUG", 72 "-L", "DEBUG",
73#endif 73#endif
74 "-c", cfgname, NULL); 74 "-c", cfgname, NULL);
75#endif 75#endif
76 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); 76 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
77} 77}
@@ -82,68 +82,64 @@ stop_arm (struct PeerContext *p)
82{ 82{
83#if START_ARM 83#if START_ARM
84 if (NULL != p->arm_proc) 84 if (NULL != p->arm_proc)
85 { 85 {
86 if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) 86 if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
87 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 87 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
88 if (GNUNET_OS_process_wait(p->arm_proc) != GNUNET_OK) 88 if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
89 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); 89 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
90 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 90 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
91 "ARM process %u stopped\n", GNUNET_OS_process_get_pid (p->arm_proc)); 91 "ARM process %u stopped\n",
92 GNUNET_OS_process_close (p->arm_proc); 92 GNUNET_OS_process_get_pid (p->arm_proc));
93 p->arm_proc = NULL; 93 GNUNET_OS_process_close (p->arm_proc);
94 } 94 p->arm_proc = NULL;
95 }
95#endif 96#endif
96 GNUNET_CONFIGURATION_destroy (p->cfg); 97 GNUNET_CONFIGURATION_destroy (p->cfg);
97} 98}
98 99
99 100
100static void 101static void
101abort_ksk_search_task (void *cls, 102abort_ksk_search_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
102 const struct GNUNET_SCHEDULER_TaskContext *tc)
103{ 103{
104 if (ksk_search != NULL) 104 if (ksk_search != NULL)
105 {
106 GNUNET_FS_search_stop (ksk_search);
107 ksk_search = NULL;
108 if (sks_search == NULL)
105 { 109 {
106 GNUNET_FS_search_stop (ksk_search); 110 GNUNET_FS_stop (fs);
107 ksk_search = NULL; 111 if (GNUNET_SCHEDULER_NO_TASK != kill_task)
108 if (sks_search == NULL) 112 GNUNET_SCHEDULER_cancel (kill_task);
109 {
110 GNUNET_FS_stop (fs);
111 if (GNUNET_SCHEDULER_NO_TASK != kill_task)
112 GNUNET_SCHEDULER_cancel (kill_task);
113 }
114 } 113 }
114 }
115} 115}
116 116
117 117
118static void 118static void
119abort_sks_search_task (void *cls, 119abort_sks_search_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
120 const struct GNUNET_SCHEDULER_TaskContext *tc)
121{ 120{
122 struct GNUNET_FS_Namespace *ns; 121 struct GNUNET_FS_Namespace *ns;
123 122
124 if (sks_search == NULL) 123 if (sks_search == NULL)
125 return; 124 return;
126 GNUNET_FS_search_stop (sks_search); 125 GNUNET_FS_search_stop (sks_search);
127 sks_search = NULL; 126 sks_search = NULL;
128 ns = GNUNET_FS_namespace_create (fs, 127 ns = GNUNET_FS_namespace_create (fs, "testNamespace");
129 "testNamespace");
130 GNUNET_assert (NULL != ns); 128 GNUNET_assert (NULL != ns);
131 GNUNET_assert (GNUNET_OK == GNUNET_FS_namespace_delete (ns, GNUNET_YES)); 129 GNUNET_assert (GNUNET_OK == GNUNET_FS_namespace_delete (ns, GNUNET_YES));
132 if (ksk_search == NULL) 130 if (ksk_search == NULL)
133 { 131 {
134 GNUNET_FS_stop (fs); 132 GNUNET_FS_stop (fs);
135 if (GNUNET_SCHEDULER_NO_TASK != kill_task) 133 if (GNUNET_SCHEDULER_NO_TASK != kill_task)
136 GNUNET_SCHEDULER_cancel (kill_task); 134 GNUNET_SCHEDULER_cancel (kill_task);
137 } 135 }
138} 136}
139 137
140 138
141static void 139static void
142do_timeout (void *cls, 140do_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
143 const struct GNUNET_SCHEDULER_TaskContext *tc)
144{ 141{
145 fprintf (stderr, 142 fprintf (stderr, "Operation timed out\n");
146 "Operation timed out\n");
147 kill_task = GNUNET_SCHEDULER_NO_TASK; 143 kill_task = GNUNET_SCHEDULER_NO_TASK;
148 abort_sks_search_task (NULL, tc); 144 abort_sks_search_task (NULL, tc);
149 abort_ksk_search_task (NULL, tc); 145 abort_ksk_search_task (NULL, tc);
@@ -152,134 +148,121 @@ do_timeout (void *cls,
152 148
153 149
154static void * 150static void *
155progress_cb (void *cls, 151progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
156 const struct GNUNET_FS_ProgressInfo *event)
157{ 152{
158 switch (event->status) 153 switch (event->status)
154 {
155 case GNUNET_FS_STATUS_SEARCH_RESULT:
156 if (sks_search == event->value.search.sc)
157 {
158 if (!GNUNET_FS_uri_test_equal (sks_expect_uri,
159 event->value.search.specifics.result.uri))
160 {
161 fprintf (stderr, "Wrong result for sks search!\n");
162 err = 1;
163 }
164 /* give system 1ms to initiate update search! */
165 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS,
166 &abort_sks_search_task, NULL);
167 }
168 else if (ksk_search == event->value.search.sc)
159 { 169 {
160 case GNUNET_FS_STATUS_SEARCH_RESULT: 170 if (!GNUNET_FS_uri_test_equal (ksk_expect_uri,
161 if (sks_search == event->value.search.sc) 171 event->value.search.specifics.result.uri))
162 { 172 {
163 if (! GNUNET_FS_uri_test_equal (sks_expect_uri, 173 fprintf (stderr, "Wrong result for ksk search!\n");
164 event->value.search.specifics.result.uri)) 174 err = 1;
165 { 175 }
166 fprintf (stderr, 176 GNUNET_SCHEDULER_add_continuation (&abort_ksk_search_task,
167 "Wrong result for sks search!\n"); 177 NULL,
168 err = 1; 178 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
169 }
170 /* give system 1ms to initiate update search! */
171 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS,
172 &abort_sks_search_task,
173 NULL);
174 }
175 else if (ksk_search == event->value.search.sc)
176 {
177 if (! GNUNET_FS_uri_test_equal (ksk_expect_uri,
178 event->value.search.specifics.result.uri))
179 {
180 fprintf (stderr,
181 "Wrong result for ksk search!\n");
182 err = 1;
183 }
184 GNUNET_SCHEDULER_add_continuation (&abort_ksk_search_task,
185 NULL,
186 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
187 }
188 else
189 {
190 fprintf (stderr,
191 "Unexpected search result received!\n");
192 GNUNET_break (0);
193 }
194 break;
195 case GNUNET_FS_STATUS_SEARCH_ERROR:
196 fprintf (stderr,
197 "Error searching file: %s\n",
198 event->value.search.specifics.error.message);
199 if (sks_search == event->value.search.sc)
200 GNUNET_SCHEDULER_add_continuation (&abort_sks_search_task,
201 NULL,
202 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
203 else if (ksk_search == event->value.search.sc)
204 GNUNET_SCHEDULER_add_continuation (&abort_ksk_search_task,
205 NULL,
206 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
207 else
208 GNUNET_break (0);
209 break;
210 case GNUNET_FS_STATUS_SEARCH_START:
211 GNUNET_assert ( (NULL == event->value.search.cctx) ||
212 (0 == strcmp ("sks_search", event->value.search.cctx)) ||
213 (0 == strcmp ("ksk_search", event->value.search.cctx)));
214 if (NULL == event->value.search.cctx)
215 {
216 GNUNET_assert (0 == strcmp ("sks_search", event->value.search.pctx));
217 update_started = GNUNET_YES;
218 }
219 GNUNET_assert (1 == event->value.search.anonymity);
220 break;
221 case GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED:
222 return NULL;
223 case GNUNET_FS_STATUS_SEARCH_STOPPED:
224 return NULL;
225 default:
226 fprintf (stderr,
227 "Unexpected event: %d\n",
228 event->status);
229 break;
230 } 179 }
180 else
181 {
182 fprintf (stderr, "Unexpected search result received!\n");
183 GNUNET_break (0);
184 }
185 break;
186 case GNUNET_FS_STATUS_SEARCH_ERROR:
187 fprintf (stderr,
188 "Error searching file: %s\n",
189 event->value.search.specifics.error.message);
190 if (sks_search == event->value.search.sc)
191 GNUNET_SCHEDULER_add_continuation (&abort_sks_search_task,
192 NULL,
193 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
194 else if (ksk_search == event->value.search.sc)
195 GNUNET_SCHEDULER_add_continuation (&abort_ksk_search_task,
196 NULL,
197 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
198 else
199 GNUNET_break (0);
200 break;
201 case GNUNET_FS_STATUS_SEARCH_START:
202 GNUNET_assert ((NULL == event->value.search.cctx) ||
203 (0 == strcmp ("sks_search", event->value.search.cctx)) ||
204 (0 == strcmp ("ksk_search", event->value.search.cctx)));
205 if (NULL == event->value.search.cctx)
206 {
207 GNUNET_assert (0 == strcmp ("sks_search", event->value.search.pctx));
208 update_started = GNUNET_YES;
209 }
210 GNUNET_assert (1 == event->value.search.anonymity);
211 break;
212 case GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED:
213 return NULL;
214 case GNUNET_FS_STATUS_SEARCH_STOPPED:
215 return NULL;
216 default:
217 fprintf (stderr, "Unexpected event: %d\n", event->status);
218 break;
219 }
231 return event->value.search.cctx; 220 return event->value.search.cctx;
232} 221}
233 222
234 223
235static void 224static void
236publish_cont (void *cls, 225publish_cont (void *cls, const struct GNUNET_FS_Uri *ksk_uri, const char *emsg)
237 const struct GNUNET_FS_Uri *ksk_uri,
238 const char *emsg)
239{ 226{
240 char *msg; 227 char *msg;
241 struct GNUNET_FS_Uri *sks_uri; 228 struct GNUNET_FS_Uri *sks_uri;
242 char sbuf[1024]; 229 char sbuf[1024];
243 struct GNUNET_CRYPTO_HashAsciiEncoded enc; 230 struct GNUNET_CRYPTO_HashAsciiEncoded enc;
244 231
245 if (NULL != emsg) 232 if (NULL != emsg)
246 { 233 {
247 fprintf (stderr, "Error publishing: %s\n", emsg); 234 fprintf (stderr, "Error publishing: %s\n", emsg);
248 err = 1; 235 err = 1;
249 GNUNET_FS_stop (fs); 236 GNUNET_FS_stop (fs);
250 return; 237 return;
251 } 238 }
252 GNUNET_CRYPTO_hash_to_enc (&nsid, 239 GNUNET_CRYPTO_hash_to_enc (&nsid, &enc);
253 &enc); 240 GNUNET_snprintf (sbuf, sizeof (sbuf), "gnunet://fs/sks/%s/this", &enc);
254 GNUNET_snprintf (sbuf,
255 sizeof (sbuf),
256 "gnunet://fs/sks/%s/this",
257 &enc);
258 sks_uri = GNUNET_FS_uri_parse (sbuf, &msg); 241 sks_uri = GNUNET_FS_uri_parse (sbuf, &msg);
259 if (msg != NULL) 242 if (msg != NULL)
260 { 243 {
261 fprintf (stderr, "failed to parse URI `%s': %s\n", 244 fprintf (stderr, "failed to parse URI `%s': %s\n", sbuf, msg);
262 sbuf, 245 err = 1;
263 msg); 246 GNUNET_FS_stop (fs);
264 err = 1; 247 GNUNET_free (msg);
265 GNUNET_FS_stop (fs); 248 return;
266 GNUNET_free (msg); 249 }
267 return; 250 ksk_search =
268 } 251 GNUNET_FS_search_start (fs, ksk_uri, 1, GNUNET_FS_SEARCH_OPTION_NONE,
269 ksk_search = GNUNET_FS_search_start (fs, ksk_uri, 1, GNUNET_FS_SEARCH_OPTION_NONE, "ksk_search"); 252 "ksk_search");
270 sks_search = GNUNET_FS_search_start (fs, sks_uri, 1, GNUNET_FS_SEARCH_OPTION_NONE, "sks_search"); 253 sks_search =
254 GNUNET_FS_search_start (fs, sks_uri, 1, GNUNET_FS_SEARCH_OPTION_NONE,
255 "sks_search");
271 GNUNET_FS_uri_destroy (sks_uri); 256 GNUNET_FS_uri_destroy (sks_uri);
272} 257}
273 258
274 259
275static void 260static void
276sks_cont (void *cls, 261sks_cont (void *cls, const struct GNUNET_FS_Uri *uri, const char *emsg)
277 const struct GNUNET_FS_Uri *uri,
278 const char *emsg)
279{ 262{
280 struct GNUNET_CONTAINER_MetaData *meta; 263 struct GNUNET_CONTAINER_MetaData *meta;
281 struct GNUNET_FS_Uri *ksk_uri; 264 struct GNUNET_FS_Uri *ksk_uri;
282 char * msg; 265 char *msg;
283 struct GNUNET_FS_BlockOptions bo; 266 struct GNUNET_FS_BlockOptions bo;
284 267
285 meta = GNUNET_CONTAINER_meta_data_create (); 268 meta = GNUNET_CONTAINER_meta_data_create ();
@@ -290,38 +273,30 @@ sks_cont (void *cls,
290 bo.content_priority = 1; 273 bo.content_priority = 1;
291 bo.anonymity_level = 1; 274 bo.anonymity_level = 1;
292 bo.replication_level = 0; 275 bo.replication_level = 0;
293 bo.expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES); 276 bo.expiration_time =
294 GNUNET_FS_publish_ksk (fs, 277 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES);
295 ksk_uri, 278 GNUNET_FS_publish_ksk (fs, ksk_uri, meta, uri, &bo,
296 meta, 279 GNUNET_FS_PUBLISH_OPTION_NONE, &publish_cont, NULL);
297 uri,
298 &bo,
299 GNUNET_FS_PUBLISH_OPTION_NONE,
300 &publish_cont,
301 NULL);
302 GNUNET_FS_uri_destroy (ksk_uri); 280 GNUNET_FS_uri_destroy (ksk_uri);
303 GNUNET_CONTAINER_meta_data_destroy (meta); 281 GNUNET_CONTAINER_meta_data_destroy (meta);
304} 282}
305 283
306 284
307static void 285static void
308adv_cont (void *cls, 286adv_cont (void *cls, const struct GNUNET_FS_Uri *uri, const char *emsg)
309 const struct GNUNET_FS_Uri *uri,
310 const char *emsg)
311{ 287{
312 struct GNUNET_CONTAINER_MetaData *meta; 288 struct GNUNET_CONTAINER_MetaData *meta;
313 struct GNUNET_FS_Namespace *ns; 289 struct GNUNET_FS_Namespace *ns;
314 struct GNUNET_FS_BlockOptions bo; 290 struct GNUNET_FS_BlockOptions bo;
315 291
316 if (NULL != emsg) 292 if (NULL != emsg)
317 { 293 {
318 fprintf (stderr, "Error publishing: %s\n", emsg); 294 fprintf (stderr, "Error publishing: %s\n", emsg);
319 err = 1; 295 err = 1;
320 GNUNET_FS_stop (fs); 296 GNUNET_FS_stop (fs);
321 return; 297 return;
322 } 298 }
323 ns = GNUNET_FS_namespace_create (fs, 299 ns = GNUNET_FS_namespace_create (fs, "testNamespace");
324 "testNamespace");
325 GNUNET_assert (NULL != ns); 300 GNUNET_assert (NULL != ns);
326 meta = GNUNET_CONTAINER_meta_data_create (); 301 meta = GNUNET_CONTAINER_meta_data_create ();
327 GNUNET_assert (NULL == emsg); 302 GNUNET_assert (NULL == emsg);
@@ -329,31 +304,21 @@ adv_cont (void *cls,
329 bo.content_priority = 1; 304 bo.content_priority = 1;
330 bo.anonymity_level = 1; 305 bo.anonymity_level = 1;
331 bo.replication_level = 0; 306 bo.replication_level = 0;
332 bo.expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES); 307 bo.expiration_time =
333 GNUNET_FS_publish_sks (fs, 308 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES);
334 ns, 309 GNUNET_FS_publish_sks (fs, ns, "this", "next", meta, uri, /* FIXME: this is non-sense (use CHK URI!?) */
335 "this", 310 &bo, GNUNET_FS_PUBLISH_OPTION_NONE, &sks_cont, NULL);
336 "next",
337 meta,
338 uri, /* FIXME: this is non-sense (use CHK URI!?) */
339 &bo,
340 GNUNET_FS_PUBLISH_OPTION_NONE,
341 &sks_cont,
342 NULL);
343 GNUNET_CONTAINER_meta_data_destroy (meta); 311 GNUNET_CONTAINER_meta_data_destroy (meta);
344 GNUNET_FS_namespace_delete (ns, GNUNET_NO); 312 GNUNET_FS_namespace_delete (ns, GNUNET_NO);
345} 313}
346 314
347 315
348static void 316static void
349ns_iterator (void *cls, 317ns_iterator (void *cls, const char *name, const GNUNET_HashCode * id)
350 const char *name,
351 const GNUNET_HashCode *id)
352{ 318{
353 int *ok = cls; 319 int *ok = cls;
354 320
355 if (0 != strcmp (name, 321 if (0 != strcmp (name, "testNamespace"))
356 "testNamespace"))
357 return; 322 return;
358 *ok = GNUNET_YES; 323 *ok = GNUNET_YES;
359 nsid = *id; 324 nsid = *id;
@@ -369,35 +334,30 @@ testNamespace ()
369 struct GNUNET_FS_Uri *ksk_uri; 334 struct GNUNET_FS_Uri *ksk_uri;
370 int ok; 335 int ok;
371 336
372 ns = GNUNET_FS_namespace_create (fs, 337 ns = GNUNET_FS_namespace_create (fs, "testNamespace");
373 "testNamespace");
374 GNUNET_assert (NULL != ns); 338 GNUNET_assert (NULL != ns);
375 ok = GNUNET_NO; 339 ok = GNUNET_NO;
376 GNUNET_FS_namespace_list (fs, &ns_iterator, &ok); 340 GNUNET_FS_namespace_list (fs, &ns_iterator, &ok);
377 if (GNUNET_NO == ok) 341 if (GNUNET_NO == ok)
378 { 342 {
379 fprintf (stderr, "namespace_list failed to find namespace!\n"); 343 fprintf (stderr, "namespace_list failed to find namespace!\n");
380 GNUNET_FS_namespace_delete (ns, GNUNET_YES); 344 GNUNET_FS_namespace_delete (ns, GNUNET_YES);
381 GNUNET_FS_stop (fs); 345 GNUNET_FS_stop (fs);
382 err = 1; 346 err = 1;
383 return; 347 return;
384 } 348 }
385 meta = GNUNET_CONTAINER_meta_data_create (); 349 meta = GNUNET_CONTAINER_meta_data_create ();
386 ksk_uri = GNUNET_FS_uri_parse ("gnunet://fs/ksk/testnsa", NULL); 350 ksk_uri = GNUNET_FS_uri_parse ("gnunet://fs/ksk/testnsa", NULL);
387 bo.content_priority = 1; 351 bo.content_priority = 1;
388 bo.anonymity_level = 1; 352 bo.anonymity_level = 1;
389 bo.replication_level = 0; 353 bo.replication_level = 0;
390 bo.expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES); 354 bo.expiration_time =
391 GNUNET_FS_namespace_advertise (fs, 355 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES);
392 ksk_uri, 356 GNUNET_FS_namespace_advertise (fs, ksk_uri, ns, meta, &bo, "root", &adv_cont,
393 ns, 357 NULL);
394 meta, 358 kill_task =
395 &bo, 359 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, &do_timeout,
396 "root", 360 NULL);
397 &adv_cont, NULL);
398 kill_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
399 &do_timeout,
400 NULL);
401 GNUNET_FS_uri_destroy (ksk_uri); 361 GNUNET_FS_uri_destroy (ksk_uri);
402 GNUNET_FS_namespace_delete (ns, GNUNET_NO); 362 GNUNET_FS_namespace_delete (ns, GNUNET_NO);
403 GNUNET_CONTAINER_meta_data_destroy (meta); 363 GNUNET_CONTAINER_meta_data_destroy (meta);
@@ -407,16 +367,13 @@ testNamespace ()
407static void 367static void
408run (void *cls, 368run (void *cls,
409 char *const *args, 369 char *const *args,
410 const char *cfgfile, 370 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
411 const struct GNUNET_CONFIGURATION_Handle *cfg)
412{ 371{
413 setup_peer (&p1, "test_fs_namespace_data.conf"); 372 setup_peer (&p1, "test_fs_namespace_data.conf");
414 fs = GNUNET_FS_start (cfg, 373 fs = GNUNET_FS_start (cfg,
415 "test-fs-namespace", 374 "test-fs-namespace",
416 &progress_cb, 375 &progress_cb,
417 NULL, 376 NULL, GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
418 GNUNET_FS_FLAGS_NONE,
419 GNUNET_FS_OPTIONS_END);
420 testNamespace (); 377 testNamespace ();
421} 378}
422 379
@@ -424,7 +381,7 @@ run (void *cls,
424int 381int
425main (int argc, char *argv[]) 382main (int argc, char *argv[])
426{ 383{
427 char *const argvx[] = { 384 char *const argvx[] = {
428 "test-fs-namespace", 385 "test-fs-namespace",
429 "-c", 386 "-c",
430 "test_fs_namespace_data.conf", 387 "test_fs_namespace_data.conf",
@@ -437,23 +394,22 @@ main (int argc, char *argv[])
437 GNUNET_GETOPT_OPTION_END 394 GNUNET_GETOPT_OPTION_END
438 }; 395 };
439 396
440 GNUNET_log_setup ("test_fs_namespace", 397 GNUNET_log_setup ("test_fs_namespace",
441#if VERBOSE 398#if VERBOSE
442 "DEBUG", 399 "DEBUG",
443#else 400#else
444 "WARNING", 401 "WARNING",
445#endif 402#endif
446 NULL); 403 NULL);
447 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, 404 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
448 argvx, "test-fs-namespace", 405 argvx, "test-fs-namespace",
449 "nohelp", options, &run, NULL); 406 "nohelp", options, &run, NULL);
450 stop_arm (&p1); 407 stop_arm (&p1);
451 if (GNUNET_YES != update_started) 408 if (GNUNET_YES != update_started)
452 { 409 {
453 fprintf (stderr, 410 fprintf (stderr, "Update search never started!\n");
454 "Update search never started!\n"); 411 err = 1;
455 err = 1; 412 }
456 }
457 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-namespace/"); 413 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-namespace/");
458 return err; 414 return err;
459} 415}
diff --git a/src/fs/test_fs_namespace_list_updateable.c b/src/fs/test_fs_namespace_list_updateable.c
index 291ab6d9d..dc8673e21 100644
--- a/src/fs/test_fs_namespace_list_updateable.c
+++ b/src/fs/test_fs_namespace_list_updateable.c
@@ -59,8 +59,7 @@ struct PeerContext
59 59
60 60
61static void * 61static void *
62progress_cb (void *cls, 62progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
63 const struct GNUNET_FS_ProgressInfo *event)
64{ 63{
65 return NULL; 64 return NULL;
66} 65}
@@ -72,11 +71,11 @@ setup_peer (struct PeerContext *p, const char *cfgname)
72 p->cfg = GNUNET_CONFIGURATION_create (); 71 p->cfg = GNUNET_CONFIGURATION_create ();
73#if START_ARM 72#if START_ARM
74 p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", 73 p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
75 "gnunet-service-arm", 74 "gnunet-service-arm",
76#if VERBOSE 75#if VERBOSE
77 "-L", "DEBUG", 76 "-L", "DEBUG",
78#endif 77#endif
79 "-c", cfgname, NULL); 78 "-c", cfgname, NULL);
80#endif 79#endif
81 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); 80 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
82} 81}
@@ -87,16 +86,17 @@ stop_arm (struct PeerContext *p)
87{ 86{
88#if START_ARM 87#if START_ARM
89 if (NULL != p->arm_proc) 88 if (NULL != p->arm_proc)
90 { 89 {
91 if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) 90 if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
92 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 91 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
93 if (GNUNET_OS_process_wait(p->arm_proc) != GNUNET_OK) 92 if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
94 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); 93 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
95 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 94 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
96 "ARM process %u stopped\n", GNUNET_OS_process_get_pid (p->arm_proc)); 95 "ARM process %u stopped\n",
97 GNUNET_OS_process_close (p->arm_proc); 96 GNUNET_OS_process_get_pid (p->arm_proc));
98 p->arm_proc = NULL; 97 GNUNET_OS_process_close (p->arm_proc);
99 } 98 p->arm_proc = NULL;
99 }
100#endif 100#endif
101 if (uri_this != NULL) 101 if (uri_this != NULL)
102 GNUNET_FS_uri_destroy (uri_this); 102 GNUNET_FS_uri_destroy (uri_this);
@@ -113,10 +113,10 @@ stop_arm (struct PeerContext *p)
113 113
114static void 114static void
115check_next (void *cls, 115check_next (void *cls,
116 const char *last_id, 116 const char *last_id,
117 const struct GNUNET_FS_Uri *last_uri, 117 const struct GNUNET_FS_Uri *last_uri,
118 const struct GNUNET_CONTAINER_MetaData *last_meta, 118 const struct GNUNET_CONTAINER_MetaData *last_meta,
119 const char *next_id) 119 const char *next_id)
120{ 120{
121 GNUNET_break (0 == strcmp (last_id, "next")); 121 GNUNET_break (0 == strcmp (last_id, "next"));
122 GNUNET_break (0 == strcmp (next_id, "future")); 122 GNUNET_break (0 == strcmp (next_id, "future"));
@@ -126,43 +126,35 @@ check_next (void *cls,
126 126
127static void 127static void
128check_this_next (void *cls, 128check_this_next (void *cls,
129 const char *last_id, 129 const char *last_id,
130 const struct GNUNET_FS_Uri *last_uri, 130 const struct GNUNET_FS_Uri *last_uri,
131 const struct GNUNET_CONTAINER_MetaData *last_meta, 131 const struct GNUNET_CONTAINER_MetaData *last_meta,
132 const char *next_id) 132 const char *next_id)
133{ 133{
134 GNUNET_break (0 == strcmp (last_id, "this")); 134 GNUNET_break (0 == strcmp (last_id, "this"));
135 GNUNET_break (0 == strcmp (next_id, "next")); 135 GNUNET_break (0 == strcmp (next_id, "next"));
136 err -= 2; 136 err -= 2;
137 err += 4; 137 err += 4;
138 GNUNET_FS_namespace_list_updateable (ns, 138 GNUNET_FS_namespace_list_updateable (ns, next_id, &check_next, NULL);
139 next_id,
140 &check_next,
141 NULL);
142} 139}
143 140
144 141
145static void 142static void
146sks_cont_next (void *cls, 143sks_cont_next (void *cls, const struct GNUNET_FS_Uri *uri, const char *emsg)
147 const struct GNUNET_FS_Uri *uri,
148 const char *emsg)
149{ 144{
150 GNUNET_assert (NULL == emsg); 145 GNUNET_assert (NULL == emsg);
151 err += 2; 146 err += 2;
152 GNUNET_FS_namespace_list_updateable (ns, 147 GNUNET_FS_namespace_list_updateable (ns, NULL, &check_this_next, NULL);
153 NULL,
154 &check_this_next,
155 NULL);
156 148
157} 149}
158 150
159 151
160static void 152static void
161check_this (void *cls, 153check_this (void *cls,
162 const char *last_id, 154 const char *last_id,
163 const struct GNUNET_FS_Uri *last_uri, 155 const struct GNUNET_FS_Uri *last_uri,
164 const struct GNUNET_CONTAINER_MetaData *last_meta, 156 const struct GNUNET_CONTAINER_MetaData *last_meta,
165 const char *next_id) 157 const char *next_id)
166{ 158{
167 GNUNET_break (0 == strcmp (last_id, "this")); 159 GNUNET_break (0 == strcmp (last_id, "this"));
168 GNUNET_break (0 == strcmp (next_id, "next")); 160 GNUNET_break (0 == strcmp (next_id, "next"));
@@ -171,27 +163,20 @@ check_this (void *cls,
171 163
172 164
173static void 165static void
174sks_cont_this (void *cls, 166sks_cont_this (void *cls, const struct GNUNET_FS_Uri *uri, const char *emsg)
175 const struct GNUNET_FS_Uri *uri,
176 const char *emsg)
177{ 167{
178 168
179 GNUNET_assert (NULL == emsg); 169 GNUNET_assert (NULL == emsg);
180 err = 1; 170 err = 1;
181 GNUNET_FS_namespace_list_updateable (ns, 171 GNUNET_FS_namespace_list_updateable (ns, NULL, &check_this, NULL);
182 NULL,
183 &check_this,
184 NULL);
185 GNUNET_FS_publish_sks (fs, 172 GNUNET_FS_publish_sks (fs,
186 ns, 173 ns,
187 "next", 174 "next",
188 "future", 175 "future",
189 meta, 176 meta,
190 uri_next, 177 uri_next,
191 &bo, 178 &bo,
192 GNUNET_FS_PUBLISH_OPTION_NONE, 179 GNUNET_FS_PUBLISH_OPTION_NONE, &sks_cont_next, NULL);
193 &sks_cont_next,
194 NULL);
195 180
196} 181}
197 182
@@ -201,45 +186,38 @@ static void
201testNamespace () 186testNamespace ()
202{ 187{
203 188
204 ns = GNUNET_FS_namespace_create (fs, 189 ns = GNUNET_FS_namespace_create (fs, "testNamespace");
205 "testNamespace");
206 GNUNET_assert (NULL != ns); 190 GNUNET_assert (NULL != ns);
207 bo.content_priority = 1; 191 bo.content_priority = 1;
208 bo.anonymity_level = 1; 192 bo.anonymity_level = 1;
209 bo.replication_level = 0; 193 bo.replication_level = 0;
210 bo.expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES); 194 bo.expiration_time =
195 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES);
211 meta = GNUNET_CONTAINER_meta_data_create (); 196 meta = GNUNET_CONTAINER_meta_data_create ();
212 197
213 uri_this = 198 uri_this =
214 GNUNET_FS_uri_parse ("gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.42", NULL); 199 GNUNET_FS_uri_parse
200 ("gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.42",
201 NULL);
215 uri_next = 202 uri_next =
216 GNUNET_FS_uri_parse ("gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.43", NULL); 203 GNUNET_FS_uri_parse
217 GNUNET_FS_publish_sks (fs, 204 ("gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.43",
218 ns, 205 NULL);
219 "this", 206 GNUNET_FS_publish_sks (fs, ns, "this", "next", meta, uri_this, &bo,
220 "next", 207 GNUNET_FS_PUBLISH_OPTION_NONE, &sks_cont_this, NULL);
221 meta,
222 uri_this,
223 &bo,
224 GNUNET_FS_PUBLISH_OPTION_NONE,
225 &sks_cont_this,
226 NULL);
227} 208}
228 209
229 210
230static void 211static void
231run (void *cls, 212run (void *cls,
232 char *const *args, 213 char *const *args,
233 const char *cfgfile, 214 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
234 const struct GNUNET_CONFIGURATION_Handle *cfg)
235{ 215{
236 setup_peer (&p1, "test_fs_namespace_data.conf"); 216 setup_peer (&p1, "test_fs_namespace_data.conf");
237 fs = GNUNET_FS_start (cfg, 217 fs = GNUNET_FS_start (cfg,
238 "test-fs-namespace", 218 "test-fs-namespace",
239 &progress_cb, 219 &progress_cb,
240 NULL, 220 NULL, GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
241 GNUNET_FS_FLAGS_NONE,
242 GNUNET_FS_OPTIONS_END);
243 testNamespace (); 221 testNamespace ();
244} 222}
245 223
@@ -247,7 +225,7 @@ run (void *cls,
247int 225int
248main (int argc, char *argv[]) 226main (int argc, char *argv[])
249{ 227{
250 char *const argvx[] = { 228 char *const argvx[] = {
251 "test-fs-namespace", 229 "test-fs-namespace",
252 "-c", 230 "-c",
253 "test_fs_namespace_data.conf", 231 "test_fs_namespace_data.conf",
@@ -260,16 +238,16 @@ main (int argc, char *argv[])
260 GNUNET_GETOPT_OPTION_END 238 GNUNET_GETOPT_OPTION_END
261 }; 239 };
262 240
263 GNUNET_log_setup ("test_fs_namespace_list_updateable", 241 GNUNET_log_setup ("test_fs_namespace_list_updateable",
264#if VERBOSE 242#if VERBOSE
265 "DEBUG", 243 "DEBUG",
266#else 244#else
267 "WARNING", 245 "WARNING",
268#endif 246#endif
269 NULL); 247 NULL);
270 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, 248 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
271 argvx, "test-fs-namespace", 249 argvx, "test-fs-namespace",
272 "nohelp", options, &run, NULL); 250 "nohelp", options, &run, NULL);
273 stop_arm (&p1); 251 stop_arm (&p1);
274 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-namespace/"); 252 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-namespace/");
275 return err; 253 return err;
diff --git a/src/fs/test_fs_publish.c b/src/fs/test_fs_publish.c
index dcce43cdf..d53b5b0ae 100644
--- a/src/fs/test_fs_publish.c
+++ b/src/fs/test_fs_publish.c
@@ -46,7 +46,7 @@
46 46
47/** 47/**
48 * How long should our test-content live? 48 * How long should our test-content live?
49 */ 49 */
50#define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) 50#define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)
51 51
52struct PeerContext 52struct PeerContext
@@ -72,8 +72,7 @@ static char *fn2;
72static int err; 72static int err;
73 73
74static void 74static void
75abort_publish_task (void *cls, 75abort_publish_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
76 const struct GNUNET_SCHEDULER_TaskContext *tc)
77{ 76{
78 GNUNET_FS_publish_stop (publish); 77 GNUNET_FS_publish_stop (publish);
79 publish = NULL; 78 publish = NULL;
@@ -87,90 +86,86 @@ abort_publish_task (void *cls,
87 86
88 87
89static void * 88static void *
90progress_cb (void *cls, 89progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
91 const struct GNUNET_FS_ProgressInfo *event)
92{ 90{
93 void *ret; 91 void *ret;
94 92
95 ret = NULL; 93 ret = NULL;
96 switch (event->status) 94 switch (event->status)
97 { 95 {
98 case GNUNET_FS_STATUS_PUBLISH_COMPLETED: 96 case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
99 ret = event->value.publish.cctx; 97 ret = event->value.publish.cctx;
100 printf ("Publish complete, %llu kbps.\n", 98 printf ("Publish complete, %llu kbps.\n",
101 (unsigned long long) (FILESIZE * 1000 / (1+GNUNET_TIME_absolute_get_duration (start).rel_value) / 1024)); 99 (unsigned long long) (FILESIZE * 1000 /
102 if (0 == strcmp ("publish-context-dir", 100 (1 +
103 event->value.publish.cctx)) 101 GNUNET_TIME_absolute_get_duration
104 GNUNET_SCHEDULER_add_continuation (&abort_publish_task, 102 (start).rel_value) / 1024));
105 NULL, 103 if (0 == strcmp ("publish-context-dir", event->value.publish.cctx))
106 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 104 GNUNET_SCHEDULER_add_continuation (&abort_publish_task,
107 break; 105 NULL,
108 case GNUNET_FS_STATUS_PUBLISH_PROGRESS: 106 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
109 ret = event->value.publish.cctx; 107 break;
110 GNUNET_assert (publish == event->value.publish.pc); 108 case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
109 ret = event->value.publish.cctx;
110 GNUNET_assert (publish == event->value.publish.pc);
111#if VERBOSE 111#if VERBOSE
112 printf ("Publish is progressing (%llu/%llu at level %u off %llu)...\n", 112 printf ("Publish is progressing (%llu/%llu at level %u off %llu)...\n",
113 (unsigned long long) event->value.publish.completed, 113 (unsigned long long) event->value.publish.completed,
114 (unsigned long long) event->value.publish.size, 114 (unsigned long long) event->value.publish.size,
115 event->value.publish.specifics.progress.depth, 115 event->value.publish.specifics.progress.depth,
116 (unsigned long long) event->value.publish.specifics.progress.offset); 116 (unsigned long long) event->value.publish.specifics.
117 progress.offset);
117#endif 118#endif
118 break; 119 break;
119 case GNUNET_FS_STATUS_PUBLISH_ERROR: 120 case GNUNET_FS_STATUS_PUBLISH_ERROR:
120 ret = event->value.publish.cctx; 121 ret = event->value.publish.cctx;
121 fprintf (stderr, 122 fprintf (stderr,
122 "Error publishing file: %s\n", 123 "Error publishing file: %s\n",
123 event->value.publish.specifics.error.message); 124 event->value.publish.specifics.error.message);
124 err = 1; 125 err = 1;
125 if (0 == strcmp ("publish-context-dir", 126 if (0 == strcmp ("publish-context-dir", event->value.publish.cctx))
126 event->value.publish.cctx)) 127 {
127 { 128 fprintf (stderr, "Scheduling abort task for error on `%s'\n",
128 fprintf (stderr, "Scheduling abort task for error on `%s'\n", 129 (const char *) event->value.publish.cctx);
129 (const char*) event->value.publish.cctx); 130 GNUNET_SCHEDULER_add_continuation (&abort_publish_task,
130 GNUNET_SCHEDULER_add_continuation (&abort_publish_task, 131 NULL,
131 NULL, 132 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
132 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 133 }
133 } 134 break;
134 break; 135 case GNUNET_FS_STATUS_PUBLISH_START:
135 case GNUNET_FS_STATUS_PUBLISH_START: 136 ret = event->value.publish.cctx;
136 ret = event->value.publish.cctx; 137 if (0 == strcmp ("publish-context1", event->value.publish.cctx))
137 if (0 == strcmp ("publish-context1", 138 {
138 event->value.publish.cctx)) 139 GNUNET_assert (0 == strcmp ("publish-context-dir",
139 { 140 event->value.publish.pctx));
140 GNUNET_assert (0 == strcmp ("publish-context-dir", 141 GNUNET_assert (FILESIZE == event->value.publish.size);
141 event->value.publish.pctx)); 142 GNUNET_assert (0 == event->value.publish.completed);
142 GNUNET_assert (FILESIZE == event->value.publish.size); 143 GNUNET_assert (1 == event->value.publish.anonymity);
143 GNUNET_assert (0 == event->value.publish.completed); 144 }
144 GNUNET_assert (1 == event->value.publish.anonymity); 145 else if (0 == strcmp ("publish-context2", event->value.publish.cctx))
145 } 146 {
146 else if (0 == strcmp ("publish-context2", 147 GNUNET_assert (0 == strcmp ("publish-context-dir",
147 event->value.publish.cctx)) 148 event->value.publish.pctx));
148 { 149 GNUNET_assert (FILESIZE == event->value.publish.size);
149 GNUNET_assert (0 == strcmp ("publish-context-dir", 150 GNUNET_assert (0 == event->value.publish.completed);
150 event->value.publish.pctx)); 151 GNUNET_assert (2 == event->value.publish.anonymity);
151 GNUNET_assert (FILESIZE == event->value.publish.size); 152 }
152 GNUNET_assert (0 == event->value.publish.completed); 153 else if (0 == strcmp ("publish-context-dir", event->value.publish.cctx))
153 GNUNET_assert (2 == event->value.publish.anonymity); 154 {
154 } 155 GNUNET_assert (0 == event->value.publish.completed);
155 else if (0 == strcmp ("publish-context-dir", 156 GNUNET_assert (3 == event->value.publish.anonymity);
156 event->value.publish.cctx))
157 {
158 GNUNET_assert (0 == event->value.publish.completed);
159 GNUNET_assert (3 == event->value.publish.anonymity);
160 }
161 else
162 GNUNET_assert (0);
163 break;
164 case GNUNET_FS_STATUS_PUBLISH_STOPPED:
165 if (0 == strcmp ("publish-context-dir",
166 event->value.publish.cctx))
167 GNUNET_assert (publish == event->value.publish.pc);
168 break;
169 default:
170 printf ("Unexpected event: %d\n",
171 event->status);
172 break;
173 } 157 }
158 else
159 GNUNET_assert (0);
160 break;
161 case GNUNET_FS_STATUS_PUBLISH_STOPPED:
162 if (0 == strcmp ("publish-context-dir", event->value.publish.cctx))
163 GNUNET_assert (publish == event->value.publish.pc);
164 break;
165 default:
166 printf ("Unexpected event: %d\n", event->status);
167 break;
168 }
174 return ret; 169 return ret;
175} 170}
176 171
@@ -181,11 +176,11 @@ setup_peer (struct PeerContext *p, const char *cfgname)
181 p->cfg = GNUNET_CONFIGURATION_create (); 176 p->cfg = GNUNET_CONFIGURATION_create ();
182#if START_ARM 177#if START_ARM
183 p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", 178 p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
184 "gnunet-service-arm", 179 "gnunet-service-arm",
185#if VERBOSE 180#if VERBOSE
186 "-L", "DEBUG", 181 "-L", "DEBUG",
187#endif 182#endif
188 "-c", cfgname, NULL); 183 "-c", cfgname, NULL);
189#endif 184#endif
190 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); 185 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
191} 186}
@@ -196,16 +191,17 @@ stop_arm (struct PeerContext *p)
196{ 191{
197#if START_ARM 192#if START_ARM
198 if (NULL != p->arm_proc) 193 if (NULL != p->arm_proc)
199 { 194 {
200 if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) 195 if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
201 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 196 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
202 if (GNUNET_OS_process_wait(p->arm_proc) != GNUNET_OK) 197 if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
203 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); 198 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
204 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 199 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
205 "ARM process %u stopped\n", GNUNET_OS_process_get_pid (p->arm_proc)); 200 "ARM process %u stopped\n",
206 GNUNET_OS_process_close (p->arm_proc); 201 GNUNET_OS_process_get_pid (p->arm_proc));
207 p->arm_proc = NULL; 202 GNUNET_OS_process_close (p->arm_proc);
208 } 203 p->arm_proc = NULL;
204 }
209#endif 205#endif
210 GNUNET_CONFIGURATION_destroy (p->cfg); 206 GNUNET_CONFIGURATION_destroy (p->cfg);
211} 207}
@@ -214,8 +210,7 @@ stop_arm (struct PeerContext *p)
214static void 210static void
215run (void *cls, 211run (void *cls,
216 char *const *args, 212 char *const *args,
217 const char *cfgfile, 213 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
218 const struct GNUNET_CONFIGURATION_Handle *cfg)
219{ 214{
220 const char *keywords[] = { 215 const char *keywords[] = {
221 "down_foo", 216 "down_foo",
@@ -232,21 +227,20 @@ run (void *cls,
232 227
233 setup_peer (&p1, "test_fs_publish_data.conf"); 228 setup_peer (&p1, "test_fs_publish_data.conf");
234 fs = GNUNET_FS_start (cfg, 229 fs = GNUNET_FS_start (cfg,
235 "test-fs-publish", 230 "test-fs-publish",
236 &progress_cb, 231 &progress_cb,
237 NULL, 232 NULL, GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
238 GNUNET_FS_FLAGS_NONE, 233 GNUNET_assert (NULL != fs);
239 GNUNET_FS_OPTIONS_END);
240 GNUNET_assert (NULL != fs);
241 fn1 = GNUNET_DISK_mktemp ("gnunet-publish-test-dst"); 234 fn1 = GNUNET_DISK_mktemp ("gnunet-publish-test-dst");
242 buf = GNUNET_malloc (FILESIZE); 235 buf = GNUNET_malloc (FILESIZE);
243 for (i = 0; i < FILESIZE; i++) 236 for (i = 0; i < FILESIZE; i++)
244 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); 237 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
245 GNUNET_assert (FILESIZE == 238 GNUNET_assert (FILESIZE ==
246 GNUNET_DISK_fn_write (fn1, 239 GNUNET_DISK_fn_write (fn1,
247 buf, 240 buf,
248 FILESIZE, 241 FILESIZE,
249 GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE)); 242 GNUNET_DISK_PERM_USER_READ |
243 GNUNET_DISK_PERM_USER_WRITE));
250 GNUNET_free (buf); 244 GNUNET_free (buf);
251 245
252 fn2 = GNUNET_DISK_mktemp ("gnunet-publish-test-dst"); 246 fn2 = GNUNET_DISK_mktemp ("gnunet-publish-test-dst");
@@ -254,10 +248,11 @@ run (void *cls,
254 for (i = 0; i < FILESIZE; i++) 248 for (i = 0; i < FILESIZE; i++)
255 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); 249 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
256 GNUNET_assert (FILESIZE == 250 GNUNET_assert (FILESIZE ==
257 GNUNET_DISK_fn_write (fn2, 251 GNUNET_DISK_fn_write (fn2,
258 buf, 252 buf,
259 FILESIZE, 253 FILESIZE,
260 GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE)); 254 GNUNET_DISK_PERM_USER_READ |
255 GNUNET_DISK_PERM_USER_WRITE));
261 GNUNET_free (buf); 256 GNUNET_free (buf);
262 257
263 meta = GNUNET_CONTAINER_meta_data_create (); 258 meta = GNUNET_CONTAINER_meta_data_create ();
@@ -268,29 +263,23 @@ run (void *cls,
268 bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME); 263 bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME);
269 264
270 fi1 = GNUNET_FS_file_information_create_from_file (fs, 265 fi1 = GNUNET_FS_file_information_create_from_file (fs,
271 "publish-context1", 266 "publish-context1",
272 fn1, 267 fn1,
273 kuri, 268 kuri,
274 meta, 269 meta, GNUNET_YES, &bo);
275 GNUNET_YES, 270
276 &bo);
277
278 GNUNET_assert (NULL != fi1); 271 GNUNET_assert (NULL != fi1);
279 bo.anonymity_level = 2; 272 bo.anonymity_level = 2;
280 fi2 = GNUNET_FS_file_information_create_from_file (fs, 273 fi2 = GNUNET_FS_file_information_create_from_file (fs,
281 "publish-context2", 274 "publish-context2",
282 fn2, 275 fn2,
283 kuri, 276 kuri,
284 meta, 277 meta, GNUNET_YES, &bo);
285 GNUNET_YES,
286 &bo);
287 GNUNET_assert (NULL != fi2); 278 GNUNET_assert (NULL != fi2);
288 bo.anonymity_level = 3; 279 bo.anonymity_level = 3;
289 fidir = GNUNET_FS_file_information_create_empty_directory (fs, 280 fidir = GNUNET_FS_file_information_create_empty_directory (fs,
290 "publish-context-dir", 281 "publish-context-dir",
291 kuri, 282 kuri, meta, &bo);
292 meta,
293 &bo);
294 GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi1)); 283 GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi1));
295 GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi2)); 284 GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi2));
296 GNUNET_FS_uri_destroy (kuri); 285 GNUNET_FS_uri_destroy (kuri);
@@ -298,9 +287,9 @@ run (void *cls,
298 GNUNET_assert (NULL != fidir); 287 GNUNET_assert (NULL != fidir);
299 start = GNUNET_TIME_absolute_get (); 288 start = GNUNET_TIME_absolute_get ();
300 publish = GNUNET_FS_publish_start (fs, 289 publish = GNUNET_FS_publish_start (fs,
301 fidir, 290 fidir,
302 NULL, NULL, NULL, 291 NULL, NULL, NULL,
303 GNUNET_FS_PUBLISH_OPTION_NONE); 292 GNUNET_FS_PUBLISH_OPTION_NONE);
304 GNUNET_assert (publish != NULL); 293 GNUNET_assert (publish != NULL);
305} 294}
306 295
@@ -308,7 +297,7 @@ run (void *cls,
308int 297int
309main (int argc, char *argv[]) 298main (int argc, char *argv[])
310{ 299{
311 char *const argvx[] = { 300 char *const argvx[] = {
312 "test-fs-publish", 301 "test-fs-publish",
313 "-c", 302 "-c",
314 "test_fs_publish_data.conf", 303 "test_fs_publish_data.conf",
@@ -321,28 +310,27 @@ main (int argc, char *argv[])
321 GNUNET_GETOPT_OPTION_END 310 GNUNET_GETOPT_OPTION_END
322 }; 311 };
323 312
324 GNUNET_log_setup ("test_fs_publish", 313 GNUNET_log_setup ("test_fs_publish",
325#if VERBOSE 314#if VERBOSE
326 "DEBUG", 315 "DEBUG",
327#else 316#else
328 "WARNING", 317 "WARNING",
329#endif 318#endif
330 NULL); 319 NULL);
331 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, 320 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
332 argvx, "test-fs-publish", 321 argvx, "test-fs-publish", "nohelp", options, &run, NULL);
333 "nohelp", options, &run, NULL);
334 stop_arm (&p1); 322 stop_arm (&p1);
335 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-publish/"); 323 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-publish/");
336 if (fn1 != NULL) 324 if (fn1 != NULL)
337 { 325 {
338 GNUNET_DISK_directory_remove (fn1); 326 GNUNET_DISK_directory_remove (fn1);
339 GNUNET_free (fn1); 327 GNUNET_free (fn1);
340 } 328 }
341 if (fn2 != NULL) 329 if (fn2 != NULL)
342 { 330 {
343 GNUNET_DISK_directory_remove (fn2); 331 GNUNET_DISK_directory_remove (fn2);
344 GNUNET_free (fn2); 332 GNUNET_free (fn2);
345 } 333 }
346 return err; 334 return err;
347} 335}
348 336
diff --git a/src/fs/test_fs_publish_persistence.c b/src/fs/test_fs_publish_persistence.c
index 2d8332602..4dcf10965 100644
--- a/src/fs/test_fs_publish_persistence.c
+++ b/src/fs/test_fs_publish_persistence.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
51struct PeerContext 51struct PeerContext
@@ -77,8 +77,7 @@ static int err;
77static GNUNET_SCHEDULER_TaskIdentifier rtask; 77static GNUNET_SCHEDULER_TaskIdentifier rtask;
78 78
79static void 79static void
80abort_publish_task (void *cls, 80abort_publish_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
81 const struct GNUNET_SCHEDULER_TaskContext *tc)
82{ 81{
83 GNUNET_FS_publish_stop (publish); 82 GNUNET_FS_publish_stop (publish);
84 publish = NULL; 83 publish = NULL;
@@ -91,30 +90,27 @@ abort_publish_task (void *cls,
91 GNUNET_FS_stop (fs); 90 GNUNET_FS_stop (fs);
92 fs = NULL; 91 fs = NULL;
93 if (GNUNET_SCHEDULER_NO_TASK != rtask) 92 if (GNUNET_SCHEDULER_NO_TASK != rtask)
94 { 93 {
95 GNUNET_SCHEDULER_cancel (rtask); 94 GNUNET_SCHEDULER_cancel (rtask);
96 rtask = GNUNET_SCHEDULER_NO_TASK; 95 rtask = GNUNET_SCHEDULER_NO_TASK;
97 } 96 }
98} 97}
99 98
100 99
101static void * 100static void *progress_cb (void *cls,
102progress_cb (void *cls, 101 const struct GNUNET_FS_ProgressInfo *event);
103 const struct GNUNET_FS_ProgressInfo *event);
104 102
105 103
106static void 104static void
107restart_fs_task (void *cls, 105restart_fs_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
108 const struct GNUNET_SCHEDULER_TaskContext *tc)
109{ 106{
110 rtask = GNUNET_SCHEDULER_NO_TASK; 107 rtask = GNUNET_SCHEDULER_NO_TASK;
111 GNUNET_FS_stop (fs); 108 GNUNET_FS_stop (fs);
112 fs = GNUNET_FS_start (cfg, 109 fs = GNUNET_FS_start (cfg,
113 "test-fs-publish-persistence", 110 "test-fs-publish-persistence",
114 &progress_cb, 111 &progress_cb,
115 NULL, 112 NULL,
116 GNUNET_FS_FLAGS_PERSISTENCE, 113 GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END);
117 GNUNET_FS_OPTIONS_END);
118} 114}
119 115
120 116
@@ -131,111 +127,108 @@ consider_restart (int ev)
131 static int prev[32]; 127 static int prev[32];
132 static int off; 128 static int off;
133 int i; 129 int i;
134 for (i=0;i<off;i++) 130
131 for (i = 0; i < off; i++)
135 if (prev[i] == ev) 132 if (prev[i] == ev)
136 return; 133 return;
137 prev[off++] = ev; 134 prev[off++] = ev;
138 rtask = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_URGENT, 135 rtask = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_URGENT,
139 &restart_fs_task, 136 &restart_fs_task, NULL);
140 NULL);
141} 137}
142 138
143 139
144static void * 140static void *
145progress_cb (void *cls, 141progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
146 const struct GNUNET_FS_ProgressInfo *event)
147{ 142{
148 void *ret; 143 void *ret;
149 144
150 ret = NULL; 145 ret = NULL;
151 switch (event->status) 146 switch (event->status)
152 { 147 {
153 case GNUNET_FS_STATUS_PUBLISH_COMPLETED: 148 case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
154 consider_restart (event->status); 149 consider_restart (event->status);
155 ret = event->value.publish.cctx; 150 ret = event->value.publish.cctx;
156 printf ("Publish complete, %llu kbps.\n", 151 printf ("Publish complete, %llu kbps.\n",
157 (unsigned long long) (FILESIZE * 1000LL / (1+GNUNET_TIME_absolute_get_duration (start).rel_value) / 1024)); 152 (unsigned long long) (FILESIZE * 1000LL /
158 if (0 == strcmp ("publish-context-dir", 153 (1 +
159 event->value.publish.cctx)) 154 GNUNET_TIME_absolute_get_duration
160 GNUNET_SCHEDULER_add_now (&abort_publish_task, 155 (start).rel_value) / 1024));
161 NULL); 156 if (0 == strcmp ("publish-context-dir", event->value.publish.cctx))
162 break; 157 GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL);
163 case GNUNET_FS_STATUS_PUBLISH_PROGRESS: 158 break;
164 consider_restart (event->status); 159 case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
165 ret = event->value.publish.cctx; 160 consider_restart (event->status);
166 GNUNET_assert (publish == event->value.publish.pc); 161 ret = event->value.publish.cctx;
162 GNUNET_assert (publish == event->value.publish.pc);
167#if VERBOSE 163#if VERBOSE
168 printf ("Publish is progressing (%llu/%llu at level %u off %llu)...\n", 164 printf ("Publish is progressing (%llu/%llu at level %u off %llu)...\n",
169 (unsigned long long) event->value.publish.completed, 165 (unsigned long long) event->value.publish.completed,
170 (unsigned long long) event->value.publish.size, 166 (unsigned long long) event->value.publish.size,
171 event->value.publish.specifics.progress.depth, 167 event->value.publish.specifics.progress.depth,
172 (unsigned long long) event->value.publish.specifics.progress.offset); 168 (unsigned long long) event->value.publish.specifics.
169 progress.offset);
173#endif 170#endif
174 break; 171 break;
175 case GNUNET_FS_STATUS_PUBLISH_SUSPEND: 172 case GNUNET_FS_STATUS_PUBLISH_SUSPEND:
176 if (event->value.publish.pc == publish) 173 if (event->value.publish.pc == publish)
177 publish = NULL; 174 publish = NULL;
178 break; 175 break;
179 case GNUNET_FS_STATUS_PUBLISH_RESUME: 176 case GNUNET_FS_STATUS_PUBLISH_RESUME:
180 if (NULL == publish) 177 if (NULL == publish)
181 { 178 {
182 GNUNET_assert (GNUNET_YES == 179 GNUNET_assert (GNUNET_YES ==
183 GNUNET_FS_file_information_is_directory (event->value.publish.fi)); 180 GNUNET_FS_file_information_is_directory (event->
184 publish = event->value.publish.pc; 181 value.publish.
185 return "publish-context-dir"; 182 fi));
186 }
187 break;
188 case GNUNET_FS_STATUS_PUBLISH_ERROR:
189 ret = event->value.publish.cctx;
190 fprintf (stderr,
191 "Error publishing file: %s\n",
192 event->value.publish.specifics.error.message);
193 err = 1;
194 GNUNET_SCHEDULER_add_now (&abort_publish_task,
195 NULL);
196 break;
197 case GNUNET_FS_STATUS_PUBLISH_START:
198 consider_restart (event->status);
199 publish = event->value.publish.pc; 183 publish = event->value.publish.pc;
200 ret = event->value.publish.cctx; 184 return "publish-context-dir";
201 if (0 == strcmp ("publish-context1",
202 event->value.publish.cctx))
203 {
204 GNUNET_assert (0 == strcmp ("publish-context-dir",
205 event->value.publish.pctx));
206 GNUNET_assert (FILESIZE == event->value.publish.size);
207 GNUNET_assert (0 == event->value.publish.completed);
208 GNUNET_assert (1 == event->value.publish.anonymity);
209 }
210 else if (0 == strcmp ("publish-context2",
211 event->value.publish.cctx))
212 {
213 GNUNET_assert (0 == strcmp ("publish-context-dir",
214 event->value.publish.pctx));
215 GNUNET_assert (FILESIZE == event->value.publish.size);
216 GNUNET_assert (0 == event->value.publish.completed);
217 GNUNET_assert (2 == event->value.publish.anonymity);
218 }
219 else if (0 == strcmp ("publish-context-dir",
220 event->value.publish.cctx))
221 {
222 GNUNET_assert (0 == event->value.publish.completed);
223 GNUNET_assert (3 == event->value.publish.anonymity);
224 }
225 else
226 GNUNET_assert (0);
227 break;
228 case GNUNET_FS_STATUS_PUBLISH_STOPPED:
229 consider_restart (event->status);
230 if (0 == strcmp ("publish-context-dir",
231 event->value.publish.cctx))
232 GNUNET_assert (publish == event->value.publish.pc);
233 break;
234 default:
235 printf ("Unexpected event: %d\n",
236 event->status);
237 break;
238 } 185 }
186 break;
187 case GNUNET_FS_STATUS_PUBLISH_ERROR:
188 ret = event->value.publish.cctx;
189 fprintf (stderr,
190 "Error publishing file: %s\n",
191 event->value.publish.specifics.error.message);
192 err = 1;
193 GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL);
194 break;
195 case GNUNET_FS_STATUS_PUBLISH_START:
196 consider_restart (event->status);
197 publish = event->value.publish.pc;
198 ret = event->value.publish.cctx;
199 if (0 == strcmp ("publish-context1", event->value.publish.cctx))
200 {
201 GNUNET_assert (0 == strcmp ("publish-context-dir",
202 event->value.publish.pctx));
203 GNUNET_assert (FILESIZE == event->value.publish.size);
204 GNUNET_assert (0 == event->value.publish.completed);
205 GNUNET_assert (1 == event->value.publish.anonymity);
206 }
207 else if (0 == strcmp ("publish-context2", event->value.publish.cctx))
208 {
209 GNUNET_assert (0 == strcmp ("publish-context-dir",
210 event->value.publish.pctx));
211 GNUNET_assert (FILESIZE == event->value.publish.size);
212 GNUNET_assert (0 == event->value.publish.completed);
213 GNUNET_assert (2 == event->value.publish.anonymity);
214 }
215 else if (0 == strcmp ("publish-context-dir", event->value.publish.cctx))
216 {
217 GNUNET_assert (0 == event->value.publish.completed);
218 GNUNET_assert (3 == event->value.publish.anonymity);
219 }
220 else
221 GNUNET_assert (0);
222 break;
223 case GNUNET_FS_STATUS_PUBLISH_STOPPED:
224 consider_restart (event->status);
225 if (0 == strcmp ("publish-context-dir", event->value.publish.cctx))
226 GNUNET_assert (publish == event->value.publish.pc);
227 break;
228 default:
229 printf ("Unexpected event: %d\n", event->status);
230 break;
231 }
239 return ret; 232 return ret;
240} 233}
241 234
@@ -246,11 +239,11 @@ setup_peer (struct PeerContext *p, const char *cfgname)
246 p->cfg = GNUNET_CONFIGURATION_create (); 239 p->cfg = GNUNET_CONFIGURATION_create ();
247#if START_ARM 240#if START_ARM
248 p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", 241 p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
249 "gnunet-service-arm", 242 "gnunet-service-arm",
250#if VERBOSE 243#if VERBOSE
251 "-L", "DEBUG", 244 "-L", "DEBUG",
252#endif 245#endif
253 "-c", cfgname, NULL); 246 "-c", cfgname, NULL);
254#endif 247#endif
255 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); 248 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
256} 249}
@@ -261,16 +254,17 @@ stop_arm (struct PeerContext *p)
261{ 254{
262#if START_ARM 255#if START_ARM
263 if (NULL != p->arm_proc) 256 if (NULL != p->arm_proc)
264 { 257 {
265 if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) 258 if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
266 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 259 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
267 if (GNUNET_OS_process_wait(p->arm_proc) != GNUNET_OK) 260 if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
268 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); 261 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
269 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 262 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
270 "ARM process %u stopped\n", GNUNET_OS_process_get_pid (p->arm_proc)); 263 "ARM process %u stopped\n",
271 GNUNET_OS_process_close (p->arm_proc); 264 GNUNET_OS_process_get_pid (p->arm_proc));
272 p->arm_proc = NULL; 265 GNUNET_OS_process_close (p->arm_proc);
273 } 266 p->arm_proc = NULL;
267 }
274#endif 268#endif
275 GNUNET_CONFIGURATION_destroy (p->cfg); 269 GNUNET_CONFIGURATION_destroy (p->cfg);
276} 270}
@@ -279,8 +273,7 @@ stop_arm (struct PeerContext *p)
279static void 273static void
280run (void *cls, 274run (void *cls,
281 char *const *args, 275 char *const *args,
282 const char *cfgfile, 276 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
283 const struct GNUNET_CONFIGURATION_Handle *c)
284{ 277{
285 const char *keywords[] = { 278 const char *keywords[] = {
286 "down_foo", 279 "down_foo",
@@ -298,21 +291,21 @@ run (void *cls,
298 cfg = c; 291 cfg = c;
299 setup_peer (&p1, "test_fs_publish_data.conf"); 292 setup_peer (&p1, "test_fs_publish_data.conf");
300 fs = GNUNET_FS_start (cfg, 293 fs = GNUNET_FS_start (cfg,
301 "test-fs-publish-persistence", 294 "test-fs-publish-persistence",
302 &progress_cb, 295 &progress_cb,
303 NULL, 296 NULL,
304 GNUNET_FS_FLAGS_PERSISTENCE, 297 GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END);
305 GNUNET_FS_OPTIONS_END); 298 GNUNET_assert (NULL != fs);
306 GNUNET_assert (NULL != fs);
307 fn1 = GNUNET_DISK_mktemp ("gnunet-publish-test-dst"); 299 fn1 = GNUNET_DISK_mktemp ("gnunet-publish-test-dst");
308 buf = GNUNET_malloc (FILESIZE); 300 buf = GNUNET_malloc (FILESIZE);
309 for (i = 0; i < FILESIZE; i++) 301 for (i = 0; i < FILESIZE; i++)
310 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); 302 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
311 GNUNET_assert (FILESIZE == 303 GNUNET_assert (FILESIZE ==
312 GNUNET_DISK_fn_write (fn1, 304 GNUNET_DISK_fn_write (fn1,
313 buf, 305 buf,
314 FILESIZE, 306 FILESIZE,
315 GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE)); 307 GNUNET_DISK_PERM_USER_READ |
308 GNUNET_DISK_PERM_USER_WRITE));
316 GNUNET_free (buf); 309 GNUNET_free (buf);
317 310
318 fn2 = GNUNET_DISK_mktemp ("gnunet-publish-test-dst"); 311 fn2 = GNUNET_DISK_mktemp ("gnunet-publish-test-dst");
@@ -320,10 +313,11 @@ run (void *cls,
320 for (i = 0; i < FILESIZE; i++) 313 for (i = 0; i < FILESIZE; i++)
321 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); 314 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
322 GNUNET_assert (FILESIZE == 315 GNUNET_assert (FILESIZE ==
323 GNUNET_DISK_fn_write (fn2, 316 GNUNET_DISK_fn_write (fn2,
324 buf, 317 buf,
325 FILESIZE, 318 FILESIZE,
326 GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE)); 319 GNUNET_DISK_PERM_USER_READ |
320 GNUNET_DISK_PERM_USER_WRITE));
327 GNUNET_free (buf); 321 GNUNET_free (buf);
328 322
329 meta = GNUNET_CONTAINER_meta_data_create (); 323 meta = GNUNET_CONTAINER_meta_data_create ();
@@ -331,30 +325,24 @@ run (void *cls,
331 bo.content_priority = 42; 325 bo.content_priority = 42;
332 bo.anonymity_level = 1; 326 bo.anonymity_level = 1;
333 bo.replication_level = 0; 327 bo.replication_level = 0;
334 bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME); 328 bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME);
335 fi1 = GNUNET_FS_file_information_create_from_file (fs, 329 fi1 = GNUNET_FS_file_information_create_from_file (fs,
336 "publish-context1", 330 "publish-context1",
337 fn1, 331 fn1,
338 kuri, 332 kuri,
339 meta, 333 meta, GNUNET_YES, &bo);
340 GNUNET_YES,
341 &bo);
342 GNUNET_assert (NULL != fi1); 334 GNUNET_assert (NULL != fi1);
343 bo.anonymity_level = 2; 335 bo.anonymity_level = 2;
344 fi2 = GNUNET_FS_file_information_create_from_file (fs, 336 fi2 = GNUNET_FS_file_information_create_from_file (fs,
345 "publish-context2", 337 "publish-context2",
346 fn2, 338 fn2,
347 kuri, 339 kuri,
348 meta, 340 meta, GNUNET_YES, &bo);
349 GNUNET_YES,
350 &bo);
351 GNUNET_assert (NULL != fi2); 341 GNUNET_assert (NULL != fi2);
352 bo.anonymity_level = 3; 342 bo.anonymity_level = 3;
353 fidir = GNUNET_FS_file_information_create_empty_directory (fs, 343 fidir = GNUNET_FS_file_information_create_empty_directory (fs,
354 "publish-context-dir", 344 "publish-context-dir",
355 kuri, 345 kuri, meta, &bo);
356 meta,
357 &bo);
358 GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi1)); 346 GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi1));
359 GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi2)); 347 GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi2));
360 GNUNET_FS_uri_destroy (kuri); 348 GNUNET_FS_uri_destroy (kuri);
@@ -362,9 +350,8 @@ run (void *cls,
362 GNUNET_assert (NULL != fidir); 350 GNUNET_assert (NULL != fidir);
363 start = GNUNET_TIME_absolute_get (); 351 start = GNUNET_TIME_absolute_get ();
364 GNUNET_FS_publish_start (fs, 352 GNUNET_FS_publish_start (fs,
365 fidir, 353 fidir,
366 NULL, NULL, NULL, 354 NULL, NULL, NULL, GNUNET_FS_PUBLISH_OPTION_NONE);
367 GNUNET_FS_PUBLISH_OPTION_NONE);
368 GNUNET_assert (publish != NULL); 355 GNUNET_assert (publish != NULL);
369} 356}
370 357
@@ -372,7 +359,7 @@ run (void *cls,
372int 359int
373main (int argc, char *argv[]) 360main (int argc, char *argv[])
374{ 361{
375 char *const argvx[] = { 362 char *const argvx[] = {
376 "test-fs-publish-persistence", 363 "test-fs-publish-persistence",
377 "-c", 364 "-c",
378 "test_fs_publish_data.conf", 365 "test_fs_publish_data.conf",
@@ -385,28 +372,27 @@ main (int argc, char *argv[])
385 GNUNET_GETOPT_OPTION_END 372 GNUNET_GETOPT_OPTION_END
386 }; 373 };
387 374
388 GNUNET_log_setup ("test_fs_publish_persistence", 375 GNUNET_log_setup ("test_fs_publish_persistence",
389#if VERBOSE 376#if VERBOSE
390 "DEBUG", 377 "DEBUG",
391#else 378#else
392 "WARNING", 379 "WARNING",
393#endif 380#endif
394 NULL); 381 NULL);
395 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, 382 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
396 argvx, "test-fs-publish", 383 argvx, "test-fs-publish", "nohelp", options, &run, NULL);
397 "nohelp", options, &run, NULL);
398 stop_arm (&p1); 384 stop_arm (&p1);
399 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-publish/"); 385 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-publish/");
400 if (fn1 != NULL) 386 if (fn1 != NULL)
401 { 387 {
402 GNUNET_DISK_directory_remove (fn1); 388 GNUNET_DISK_directory_remove (fn1);
403 GNUNET_free (fn1); 389 GNUNET_free (fn1);
404 } 390 }
405 if (fn2 != NULL) 391 if (fn2 != NULL)
406 { 392 {
407 GNUNET_DISK_directory_remove (fn2); 393 GNUNET_DISK_directory_remove (fn2);
408 GNUNET_free (fn2); 394 GNUNET_free (fn2);
409 } 395 }
410 return err; 396 return err;
411} 397}
412 398
diff --git a/src/fs/test_fs_search.c b/src/fs/test_fs_search.c
index a1f3208ef..878624c73 100644
--- a/src/fs/test_fs_search.c
+++ b/src/fs/test_fs_search.c
@@ -45,13 +45,13 @@
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
51struct PeerContext 51struct PeerContext
52{ 52{
53 struct GNUNET_CONFIGURATION_Handle *cfg; 53 struct GNUNET_CONFIGURATION_Handle *cfg;
54 struct GNUNET_PeerIdentity id; 54 struct GNUNET_PeerIdentity id;
55#if START_ARM 55#if START_ARM
56 struct GNUNET_OS_Process *arm_proc; 56 struct GNUNET_OS_Process *arm_proc;
57#endif 57#endif
@@ -69,8 +69,7 @@ static struct GNUNET_FS_PublishContext *publish;
69 69
70 70
71static void 71static void
72abort_publish_task (void *cls, 72abort_publish_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
73 const struct GNUNET_SCHEDULER_TaskContext *tc)
74{ 73{
75 GNUNET_FS_publish_stop (publish); 74 GNUNET_FS_publish_stop (publish);
76 publish = NULL; 75 publish = NULL;
@@ -78,8 +77,7 @@ abort_publish_task (void *cls,
78 77
79 78
80static void 79static void
81abort_search_task (void *cls, 80abort_search_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
82 const struct GNUNET_SCHEDULER_TaskContext *tc)
83{ 81{
84 if (search != NULL) 82 if (search != NULL)
85 GNUNET_FS_search_stop (search); 83 GNUNET_FS_search_stop (search);
@@ -88,94 +86,90 @@ abort_search_task (void *cls,
88 86
89 87
90static void * 88static void *
91progress_cb (void *cls, 89progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
92 const struct GNUNET_FS_ProgressInfo *event) 90{
93{
94 const char *keywords[] = { 91 const char *keywords[] = {
95 "down_foo" 92 "down_foo"
96 }; 93 };
97 struct GNUNET_FS_Uri *kuri; 94 struct GNUNET_FS_Uri *kuri;
98 95
99 switch (event->status) 96 switch (event->status)
100 { 97 {
101 case GNUNET_FS_STATUS_PUBLISH_PROGRESS: 98 case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
102#if VERBOSE 99#if VERBOSE
103 printf ("Publish is progressing (%llu/%llu at level %u off %llu)...\n", 100 printf ("Publish is progressing (%llu/%llu at level %u off %llu)...\n",
104 (unsigned long long) event->value.publish.completed, 101 (unsigned long long) event->value.publish.completed,
105 (unsigned long long) event->value.publish.size, 102 (unsigned long long) event->value.publish.size,
106 event->value.publish.specifics.progress.depth, 103 event->value.publish.specifics.progress.depth,
107 (unsigned long long) event->value.publish.specifics.progress.offset); 104 (unsigned long long) event->value.publish.specifics.
108#endif 105 progress.offset);
109 break; 106#endif
110 case GNUNET_FS_STATUS_PUBLISH_COMPLETED: 107 break;
111 kuri = GNUNET_FS_uri_ksk_create_from_args (1, keywords); 108 case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
112 start = GNUNET_TIME_absolute_get (); 109 kuri = GNUNET_FS_uri_ksk_create_from_args (1, keywords);
113 search = GNUNET_FS_search_start (fs, 110 start = GNUNET_TIME_absolute_get ();
114 kuri, 111 search = GNUNET_FS_search_start (fs,
115 1, 112 kuri,
116 GNUNET_FS_SEARCH_OPTION_NONE, 113 1, GNUNET_FS_SEARCH_OPTION_NONE, "search");
117 "search"); 114 GNUNET_FS_uri_destroy (kuri);
118 GNUNET_FS_uri_destroy (kuri); 115 GNUNET_assert (search != NULL);
119 GNUNET_assert (search != NULL); 116 break;
120 break; 117 case GNUNET_FS_STATUS_SEARCH_RESULT:
121 case GNUNET_FS_STATUS_SEARCH_RESULT:
122#if VERBOSE 118#if VERBOSE
123 printf ("Search complete.\n"); 119 printf ("Search complete.\n");
124#endif 120#endif
125 GNUNET_SCHEDULER_add_continuation (&abort_search_task, 121 GNUNET_SCHEDULER_add_continuation (&abort_search_task,
126 NULL, 122 NULL,
127 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 123 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
128 break; 124 break;
129 case GNUNET_FS_STATUS_PUBLISH_ERROR: 125 case GNUNET_FS_STATUS_PUBLISH_ERROR:
130 fprintf (stderr, 126 fprintf (stderr,
131 "Error publishing file: %s\n", 127 "Error publishing file: %s\n",
132 event->value.publish.specifics.error.message); 128 event->value.publish.specifics.error.message);
133 GNUNET_break (0); 129 GNUNET_break (0);
134 GNUNET_SCHEDULER_add_continuation (&abort_publish_task, 130 GNUNET_SCHEDULER_add_continuation (&abort_publish_task,
135 NULL, 131 NULL,
136 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 132 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
137 break; 133 break;
138 case GNUNET_FS_STATUS_SEARCH_ERROR: 134 case GNUNET_FS_STATUS_SEARCH_ERROR:
139 fprintf (stderr, 135 fprintf (stderr,
140 "Error searching file: %s\n", 136 "Error searching file: %s\n",
141 event->value.search.specifics.error.message); 137 event->value.search.specifics.error.message);
142 GNUNET_SCHEDULER_add_continuation (&abort_search_task, 138 GNUNET_SCHEDULER_add_continuation (&abort_search_task,
143 NULL, 139 NULL,
144 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 140 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
145 break; 141 break;
146 case GNUNET_FS_STATUS_PUBLISH_START: 142 case GNUNET_FS_STATUS_PUBLISH_START:
147 GNUNET_assert (0 == strcmp ("publish-context", event->value.publish.cctx)); 143 GNUNET_assert (0 == strcmp ("publish-context", event->value.publish.cctx));
148 GNUNET_assert (NULL == event->value.publish.pctx); 144 GNUNET_assert (NULL == event->value.publish.pctx);
149 GNUNET_assert (FILESIZE == event->value.publish.size); 145 GNUNET_assert (FILESIZE == event->value.publish.size);
150 GNUNET_assert (0 == event->value.publish.completed); 146 GNUNET_assert (0 == event->value.publish.completed);
151 GNUNET_assert (1 == event->value.publish.anonymity); 147 GNUNET_assert (1 == event->value.publish.anonymity);
152 break; 148 break;
153 case GNUNET_FS_STATUS_PUBLISH_STOPPED: 149 case GNUNET_FS_STATUS_PUBLISH_STOPPED:
154 GNUNET_assert (publish == event->value.publish.pc); 150 GNUNET_assert (publish == event->value.publish.pc);
155 GNUNET_assert (FILESIZE == event->value.publish.size); 151 GNUNET_assert (FILESIZE == event->value.publish.size);
156 GNUNET_assert (1 == event->value.publish.anonymity); 152 GNUNET_assert (1 == event->value.publish.anonymity);
157 GNUNET_FS_stop (fs); 153 GNUNET_FS_stop (fs);
158 fs = NULL; 154 fs = NULL;
159 break; 155 break;
160 case GNUNET_FS_STATUS_SEARCH_START: 156 case GNUNET_FS_STATUS_SEARCH_START:
161 GNUNET_assert (search == NULL); 157 GNUNET_assert (search == NULL);
162 GNUNET_assert (0 == strcmp ("search", event->value.search.cctx)); 158 GNUNET_assert (0 == strcmp ("search", event->value.search.cctx));
163 GNUNET_assert (1 == event->value.search.anonymity); 159 GNUNET_assert (1 == event->value.search.anonymity);
164 break; 160 break;
165 case GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED: 161 case GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED:
166 break; 162 break;
167 case GNUNET_FS_STATUS_SEARCH_STOPPED: 163 case GNUNET_FS_STATUS_SEARCH_STOPPED:
168 GNUNET_assert (search == event->value.search.sc); 164 GNUNET_assert (search == event->value.search.sc);
169 GNUNET_SCHEDULER_add_continuation (&abort_publish_task, 165 GNUNET_SCHEDULER_add_continuation (&abort_publish_task,
170 NULL, 166 NULL,
171 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 167 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
172 break; 168 break;
173 default: 169 default:
174 fprintf (stderr, 170 fprintf (stderr, "Unexpected event: %d\n", event->status);
175 "Unexpected event: %d\n", 171 break;
176 event->status); 172 }
177 break;
178 }
179 return NULL; 173 return NULL;
180} 174}
181 175
@@ -186,11 +180,11 @@ setup_peer (struct PeerContext *p, const char *cfgname)
186 p->cfg = GNUNET_CONFIGURATION_create (); 180 p->cfg = GNUNET_CONFIGURATION_create ();
187#if START_ARM 181#if START_ARM
188 p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", 182 p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
189 "gnunet-service-arm", 183 "gnunet-service-arm",
190#if VERBOSE 184#if VERBOSE
191 "-L", "DEBUG", 185 "-L", "DEBUG",
192#endif 186#endif
193 "-c", cfgname, NULL); 187 "-c", cfgname, NULL);
194#endif 188#endif
195 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); 189 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
196} 190}
@@ -201,16 +195,17 @@ stop_arm (struct PeerContext *p)
201{ 195{
202#if START_ARM 196#if START_ARM
203 if (NULL != p->arm_proc) 197 if (NULL != p->arm_proc)
204 { 198 {
205 if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) 199 if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
206 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 200 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
207 if (GNUNET_OS_process_wait(p->arm_proc) != GNUNET_OK) 201 if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
208 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); 202 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
209 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 203 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
210 "ARM process %u stopped\n", GNUNET_OS_process_get_pid (p->arm_proc)); 204 "ARM process %u stopped\n",
211 GNUNET_OS_process_close (p->arm_proc); 205 GNUNET_OS_process_get_pid (p->arm_proc));
212 p->arm_proc = NULL; 206 GNUNET_OS_process_close (p->arm_proc);
213 } 207 p->arm_proc = NULL;
208 }
214#endif 209#endif
215 GNUNET_CONFIGURATION_destroy (p->cfg); 210 GNUNET_CONFIGURATION_destroy (p->cfg);
216} 211}
@@ -219,8 +214,7 @@ stop_arm (struct PeerContext *p)
219static void 214static void
220run (void *cls, 215run (void *cls,
221 char *const *args, 216 char *const *args,
222 const char *cfgfile, 217 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
223 const struct GNUNET_CONFIGURATION_Handle *cfg)
224{ 218{
225 const char *keywords[] = { 219 const char *keywords[] = {
226 "down_foo", 220 "down_foo",
@@ -235,12 +229,10 @@ run (void *cls,
235 229
236 setup_peer (&p1, "test_fs_search_data.conf"); 230 setup_peer (&p1, "test_fs_search_data.conf");
237 fs = GNUNET_FS_start (cfg, 231 fs = GNUNET_FS_start (cfg,
238 "test-fs-search", 232 "test-fs-search",
239 &progress_cb, 233 &progress_cb,
240 NULL, 234 NULL, GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
241 GNUNET_FS_FLAGS_NONE, 235 GNUNET_assert (NULL != fs);
242 GNUNET_FS_OPTIONS_END);
243 GNUNET_assert (NULL != fs);
244 buf = GNUNET_malloc (FILESIZE); 236 buf = GNUNET_malloc (FILESIZE);
245 for (i = 0; i < FILESIZE; i++) 237 for (i = 0; i < FILESIZE; i++)
246 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); 238 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
@@ -251,21 +243,18 @@ run (void *cls,
251 bo.replication_level = 0; 243 bo.replication_level = 0;
252 bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME); 244 bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME);
253 fi = GNUNET_FS_file_information_create_from_data (fs, 245 fi = GNUNET_FS_file_information_create_from_data (fs,
254 "publish-context", 246 "publish-context",
255 FILESIZE, 247 FILESIZE,
256 buf, 248 buf,
257 kuri, 249 kuri, meta, GNUNET_NO, &bo);
258 meta,
259 GNUNET_NO,
260 &bo);
261 GNUNET_FS_uri_destroy (kuri); 250 GNUNET_FS_uri_destroy (kuri);
262 GNUNET_CONTAINER_meta_data_destroy (meta); 251 GNUNET_CONTAINER_meta_data_destroy (meta);
263 GNUNET_assert (NULL != fi); 252 GNUNET_assert (NULL != fi);
264 start = GNUNET_TIME_absolute_get (); 253 start = GNUNET_TIME_absolute_get ();
265 publish = GNUNET_FS_publish_start (fs, 254 publish = GNUNET_FS_publish_start (fs,
266 fi, 255 fi,
267 NULL, NULL, NULL, 256 NULL, NULL, NULL,
268 GNUNET_FS_PUBLISH_OPTION_NONE); 257 GNUNET_FS_PUBLISH_OPTION_NONE);
269 GNUNET_assert (publish != NULL); 258 GNUNET_assert (publish != NULL);
270} 259}
271 260
@@ -273,7 +262,7 @@ run (void *cls,
273int 262int
274main (int argc, char *argv[]) 263main (int argc, char *argv[])
275{ 264{
276 char *const argvx[] = { 265 char *const argvx[] = {
277 "test-fs-search", 266 "test-fs-search",
278 "-c", 267 "-c",
279 "test_fs_search_data.conf", 268 "test_fs_search_data.conf",
@@ -286,16 +275,15 @@ main (int argc, char *argv[])
286 GNUNET_GETOPT_OPTION_END 275 GNUNET_GETOPT_OPTION_END
287 }; 276 };
288 277
289 GNUNET_log_setup ("test_fs_search", 278 GNUNET_log_setup ("test_fs_search",
290#if VERBOSE 279#if VERBOSE
291 "DEBUG", 280 "DEBUG",
292#else 281#else
293 "WARNING", 282 "WARNING",
294#endif 283#endif
295 NULL); 284 NULL);
296 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, 285 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
297 argvx, "test-fs-search", 286 argvx, "test-fs-search", "nohelp", options, &run, NULL);
298 "nohelp", options, &run, NULL);
299 stop_arm (&p1); 287 stop_arm (&p1);
300 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-search/"); 288 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-search/");
301 return 0; 289 return 0;
diff --git a/src/fs/test_fs_search_persistence.c b/src/fs/test_fs_search_persistence.c
index 47d177a81..eceb4d1d5 100644
--- a/src/fs/test_fs_search_persistence.c
+++ b/src/fs/test_fs_search_persistence.c
@@ -45,13 +45,13 @@
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
51struct PeerContext 51struct PeerContext
52{ 52{
53 struct GNUNET_CONFIGURATION_Handle *cfg; 53 struct GNUNET_CONFIGURATION_Handle *cfg;
54 struct GNUNET_PeerIdentity id; 54 struct GNUNET_PeerIdentity id;
55#if START_ARM 55#if START_ARM
56 struct GNUNET_OS_Process *arm_proc; 56 struct GNUNET_OS_Process *arm_proc;
57#endif 57#endif
@@ -70,8 +70,7 @@ static struct GNUNET_FS_PublishContext *publish;
70static const struct GNUNET_CONFIGURATION_Handle *cfg; 70static const struct GNUNET_CONFIGURATION_Handle *cfg;
71 71
72static void 72static void
73abort_publish_task (void *cls, 73abort_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
81static void 80static void
82abort_search_task (void *cls, 81abort_search_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
83 const struct GNUNET_SCHEDULER_TaskContext *tc)
84{ 82{
85 if (search != NULL) 83 if (search != NULL)
86 GNUNET_FS_search_stop (search); 84 GNUNET_FS_search_stop (search);
@@ -88,22 +86,19 @@ abort_search_task (void *cls,
88} 86}
89 87
90 88
91static void * 89static void *progress_cb (void *cls,
92progress_cb (void *cls, 90 const struct GNUNET_FS_ProgressInfo *event);
93 const struct GNUNET_FS_ProgressInfo *event);
94 91
95 92
96static void 93static void
97restart_fs_task (void *cls, 94restart_fs_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
98 const struct GNUNET_SCHEDULER_TaskContext *tc)
99{ 95{
100 GNUNET_FS_stop (fs); 96 GNUNET_FS_stop (fs);
101 fs = GNUNET_FS_start (cfg, 97 fs = GNUNET_FS_start (cfg,
102 "test-fs-search-persistence", 98 "test-fs-search-persistence",
103 &progress_cb, 99 &progress_cb,
104 NULL, 100 NULL,
105 GNUNET_FS_FLAGS_PERSISTENCE, 101 GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END);
106 GNUNET_FS_OPTIONS_END);
107} 102}
108 103
109 104
@@ -122,129 +117,124 @@ consider_restart (int ev)
122 static int prev[32]; 117 static int prev[32];
123 static int off; 118 static int off;
124 int i; 119 int i;
125 for (i=0;i<off;i++) 120
121 for (i = 0; i < off; i++)
126 if (prev[i] == ev) 122 if (prev[i] == ev)
127 return; 123 return;
128 prev[off++] = ev; 124 prev[off++] = ev;
129 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_URGENT, 125 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_URGENT,
130 &restart_fs_task, 126 &restart_fs_task, NULL);
131 NULL);
132} 127}
133 128
134 129
135static void * 130static void *
136progress_cb (void *cls, 131progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
137 const struct GNUNET_FS_ProgressInfo *event) 132{
138{
139 const char *keywords[] = { 133 const char *keywords[] = {
140 "down_foo" 134 "down_foo"
141 }; 135 };
142 struct GNUNET_FS_Uri *kuri; 136 struct GNUNET_FS_Uri *kuri;
143 137
144 switch (event->status) 138 switch (event->status)
145 { 139 {
146 case GNUNET_FS_STATUS_PUBLISH_PROGRESS: 140 case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
147#if VERBOSE 141#if VERBOSE
148 printf ("Publish is progressing (%llu/%llu at level %u off %llu)...\n", 142 printf ("Publish is progressing (%llu/%llu at level %u off %llu)...\n",
149 (unsigned long long) event->value.publish.completed, 143 (unsigned long long) event->value.publish.completed,
150 (unsigned long long) event->value.publish.size, 144 (unsigned long long) event->value.publish.size,
151 event->value.publish.specifics.progress.depth, 145 event->value.publish.specifics.progress.depth,
152 (unsigned long long) event->value.publish.specifics.progress.offset); 146 (unsigned long long) event->value.publish.specifics.
153#endif 147 progress.offset);
154 break; 148#endif
155 case GNUNET_FS_STATUS_PUBLISH_COMPLETED: 149 break;
156 kuri = GNUNET_FS_uri_ksk_create_from_args (1, keywords); 150 case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
157 start = GNUNET_TIME_absolute_get (); 151 kuri = GNUNET_FS_uri_ksk_create_from_args (1, keywords);
158 GNUNET_FS_search_start (fs, 152 start = GNUNET_TIME_absolute_get ();
159 kuri, 153 GNUNET_FS_search_start (fs,
160 1, 154 kuri, 1, GNUNET_FS_SEARCH_OPTION_NONE, "search");
161 GNUNET_FS_SEARCH_OPTION_NONE, 155 GNUNET_FS_uri_destroy (kuri);
162 "search"); 156 GNUNET_assert (search != NULL);
163 GNUNET_FS_uri_destroy (kuri); 157 break;
164 GNUNET_assert (search != NULL); 158 case GNUNET_FS_STATUS_PUBLISH_SUSPEND:
165 break; 159 if (event->value.publish.pc == publish)
166 case GNUNET_FS_STATUS_PUBLISH_SUSPEND: 160 publish = NULL;
167 if (event->value.publish.pc == publish) 161 break;
168 publish = NULL; 162 case GNUNET_FS_STATUS_PUBLISH_RESUME:
169 break; 163 if (NULL == publish)
170 case GNUNET_FS_STATUS_PUBLISH_RESUME: 164 publish = event->value.publish.pc;
171 if (NULL == publish) 165 break;
172 publish = event->value.publish.pc; 166 case GNUNET_FS_STATUS_SEARCH_RESULT:
173 break; 167 /* FIXME: consider_restart (event->status); cannot be tested with
174 case GNUNET_FS_STATUS_SEARCH_RESULT: 168 * search result since we exit here after the first one... */
175 /* FIXME: consider_restart (event->status); cannot be tested with
176 search result since we exit here after the first one... */
177#if VERBOSE 169#if VERBOSE
178 printf ("Search complete.\n"); 170 printf ("Search complete.\n");
179#endif 171#endif
180 GNUNET_SCHEDULER_add_continuation (&abort_search_task, 172 GNUNET_SCHEDULER_add_continuation (&abort_search_task,
181 NULL, 173 NULL,
182 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 174 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
183 break; 175 break;
184 case GNUNET_FS_STATUS_PUBLISH_ERROR: 176 case GNUNET_FS_STATUS_PUBLISH_ERROR:
185 fprintf (stderr, 177 fprintf (stderr,
186 "Error publishing file: %s\n", 178 "Error publishing file: %s\n",
187 event->value.publish.specifics.error.message); 179 event->value.publish.specifics.error.message);
188 GNUNET_break (0); 180 GNUNET_break (0);
189 GNUNET_SCHEDULER_add_continuation (&abort_publish_task, 181 GNUNET_SCHEDULER_add_continuation (&abort_publish_task,
190 NULL, 182 NULL,
191 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 183 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
192 break; 184 break;
193 case GNUNET_FS_STATUS_SEARCH_ERROR: 185 case GNUNET_FS_STATUS_SEARCH_ERROR:
194 fprintf (stderr, 186 fprintf (stderr,
195 "Error searching file: %s\n", 187 "Error searching file: %s\n",
196 event->value.search.specifics.error.message); 188 event->value.search.specifics.error.message);
197 GNUNET_SCHEDULER_add_continuation (&abort_search_task, 189 GNUNET_SCHEDULER_add_continuation (&abort_search_task,
198 NULL, 190 NULL,
199 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 191 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
200 break; 192 break;
201 case GNUNET_FS_STATUS_SEARCH_SUSPEND: 193 case GNUNET_FS_STATUS_SEARCH_SUSPEND:
202 if (event->value.search.sc == search) 194 if (event->value.search.sc == search)
203 search = NULL;
204 break;
205 case GNUNET_FS_STATUS_SEARCH_RESUME:
206 if (NULL == search)
207 {
208 search = event->value.search.sc;
209 return "search";
210 }
211 break;
212 case GNUNET_FS_STATUS_PUBLISH_START:
213 GNUNET_assert (0 == strcmp ("publish-context", event->value.publish.cctx));
214 GNUNET_assert (NULL == event->value.publish.pctx);
215 GNUNET_assert (FILESIZE == event->value.publish.size);
216 GNUNET_assert (0 == event->value.publish.completed);
217 GNUNET_assert (1 == event->value.publish.anonymity);
218 break;
219 case GNUNET_FS_STATUS_PUBLISH_STOPPED:
220 GNUNET_assert (publish == event->value.publish.pc);
221 GNUNET_assert (FILESIZE == event->value.publish.size);
222 GNUNET_assert (1 == event->value.publish.anonymity);
223 GNUNET_FS_stop (fs);
224 fs = NULL;
225 break;
226 case GNUNET_FS_STATUS_SEARCH_START:
227 consider_restart (event->status);
228 GNUNET_assert (search == NULL);
229 search = event->value.search.sc;
230 GNUNET_assert (0 == strcmp ("search", event->value.search.cctx));
231 GNUNET_assert (1 == event->value.search.anonymity);
232 break;
233 case GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED:
234 break;
235 case GNUNET_FS_STATUS_SEARCH_STOPPED:
236 GNUNET_assert (search == event->value.search.sc);
237 GNUNET_SCHEDULER_add_continuation (&abort_publish_task,
238 NULL,
239 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
240 search = NULL; 195 search = NULL;
241 break; 196 break;
242 default: 197 case GNUNET_FS_STATUS_SEARCH_RESUME:
243 fprintf (stderr, 198 if (NULL == search)
244 "Unexpected event: %d\n", 199 {
245 event->status); 200 search = event->value.search.sc;
246 break; 201 return "search";
247 } 202 }
203 break;
204 case GNUNET_FS_STATUS_PUBLISH_START:
205 GNUNET_assert (0 == strcmp ("publish-context", event->value.publish.cctx));
206 GNUNET_assert (NULL == event->value.publish.pctx);
207 GNUNET_assert (FILESIZE == event->value.publish.size);
208 GNUNET_assert (0 == event->value.publish.completed);
209 GNUNET_assert (1 == event->value.publish.anonymity);
210 break;
211 case GNUNET_FS_STATUS_PUBLISH_STOPPED:
212 GNUNET_assert (publish == event->value.publish.pc);
213 GNUNET_assert (FILESIZE == event->value.publish.size);
214 GNUNET_assert (1 == event->value.publish.anonymity);
215 GNUNET_FS_stop (fs);
216 fs = NULL;
217 break;
218 case GNUNET_FS_STATUS_SEARCH_START:
219 consider_restart (event->status);
220 GNUNET_assert (search == NULL);
221 search = event->value.search.sc;
222 GNUNET_assert (0 == strcmp ("search", event->value.search.cctx));
223 GNUNET_assert (1 == event->value.search.anonymity);
224 break;
225 case GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED:
226 break;
227 case GNUNET_FS_STATUS_SEARCH_STOPPED:
228 GNUNET_assert (search == event->value.search.sc);
229 GNUNET_SCHEDULER_add_continuation (&abort_publish_task,
230 NULL,
231 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
232 search = NULL;
233 break;
234 default:
235 fprintf (stderr, "Unexpected event: %d\n", event->status);
236 break;
237 }
248 return NULL; 238 return NULL;
249} 239}
250 240
@@ -255,11 +245,11 @@ setup_peer (struct PeerContext *p, const char *cfgname)
255 p->cfg = GNUNET_CONFIGURATION_create (); 245 p->cfg = GNUNET_CONFIGURATION_create ();
256#if START_ARM 246#if START_ARM
257 p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", 247 p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
258 "gnunet-service-arm", 248 "gnunet-service-arm",
259#if VERBOSE 249#if VERBOSE
260 "-L", "DEBUG", 250 "-L", "DEBUG",
261#endif 251#endif
262 "-c", cfgname, NULL); 252 "-c", cfgname, NULL);
263#endif 253#endif
264 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); 254 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
265} 255}
@@ -270,16 +260,17 @@ stop_arm (struct PeerContext *p)
270{ 260{
271#if START_ARM 261#if START_ARM
272 if (NULL != p->arm_proc) 262 if (NULL != p->arm_proc)
273 { 263 {
274 if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) 264 if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
275 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 265 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
276 if (GNUNET_OS_process_wait(p->arm_proc) != GNUNET_OK) 266 if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
277 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); 267 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
278 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 268 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
279 "ARM process %u stopped\n", GNUNET_OS_process_get_pid (p->arm_proc)); 269 "ARM process %u stopped\n",
280 GNUNET_OS_process_close (p->arm_proc); 270 GNUNET_OS_process_get_pid (p->arm_proc));
281 p->arm_proc = NULL; 271 GNUNET_OS_process_close (p->arm_proc);
282 } 272 p->arm_proc = NULL;
273 }
283#endif 274#endif
284 GNUNET_CONFIGURATION_destroy (p->cfg); 275 GNUNET_CONFIGURATION_destroy (p->cfg);
285} 276}
@@ -288,8 +279,7 @@ stop_arm (struct PeerContext *p)
288static void 279static void
289run (void *cls, 280run (void *cls,
290 char *const *args, 281 char *const *args,
291 const char *cfgfile, 282 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
292 const struct GNUNET_CONFIGURATION_Handle *c)
293{ 283{
294 const char *keywords[] = { 284 const char *keywords[] = {
295 "down_foo", 285 "down_foo",
@@ -305,12 +295,11 @@ run (void *cls,
305 cfg = c; 295 cfg = c;
306 setup_peer (&p1, "test_fs_search_data.conf"); 296 setup_peer (&p1, "test_fs_search_data.conf");
307 fs = GNUNET_FS_start (cfg, 297 fs = GNUNET_FS_start (cfg,
308 "test-fs-search-persistence", 298 "test-fs-search-persistence",
309 &progress_cb, 299 &progress_cb,
310 NULL, 300 NULL,
311 GNUNET_FS_FLAGS_PERSISTENCE, 301 GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END);
312 GNUNET_FS_OPTIONS_END); 302 GNUNET_assert (NULL != fs);
313 GNUNET_assert (NULL != fs);
314 buf = GNUNET_malloc (FILESIZE); 303 buf = GNUNET_malloc (FILESIZE);
315 for (i = 0; i < FILESIZE; i++) 304 for (i = 0; i < FILESIZE; i++)
316 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); 305 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
@@ -321,21 +310,18 @@ run (void *cls,
321 bo.replication_level = 0; 310 bo.replication_level = 0;
322 bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME); 311 bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME);
323 fi = GNUNET_FS_file_information_create_from_data (fs, 312 fi = GNUNET_FS_file_information_create_from_data (fs,
324 "publish-context", 313 "publish-context",
325 FILESIZE, 314 FILESIZE,
326 buf, 315 buf,
327 kuri, 316 kuri, meta, GNUNET_NO, &bo);
328 meta,
329 GNUNET_NO,
330 &bo);
331 GNUNET_FS_uri_destroy (kuri); 317 GNUNET_FS_uri_destroy (kuri);
332 GNUNET_CONTAINER_meta_data_destroy (meta); 318 GNUNET_CONTAINER_meta_data_destroy (meta);
333 GNUNET_assert (NULL != fi); 319 GNUNET_assert (NULL != fi);
334 start = GNUNET_TIME_absolute_get (); 320 start = GNUNET_TIME_absolute_get ();
335 publish = GNUNET_FS_publish_start (fs, 321 publish = GNUNET_FS_publish_start (fs,
336 fi, 322 fi,
337 NULL, NULL, NULL, 323 NULL, NULL, NULL,
338 GNUNET_FS_PUBLISH_OPTION_NONE); 324 GNUNET_FS_PUBLISH_OPTION_NONE);
339 GNUNET_assert (publish != NULL); 325 GNUNET_assert (publish != NULL);
340} 326}
341 327
@@ -343,7 +329,7 @@ run (void *cls,
343int 329int
344main (int argc, char *argv[]) 330main (int argc, char *argv[])
345{ 331{
346 char *const argvx[] = { 332 char *const argvx[] = {
347 "test-fs-search-persistence", 333 "test-fs-search-persistence",
348 "-c", 334 "-c",
349 "test_fs_search_data.conf", 335 "test_fs_search_data.conf",
@@ -357,16 +343,16 @@ main (int argc, char *argv[])
357 }; 343 };
358 344
359 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-search/"); 345 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-search/");
360 GNUNET_log_setup ("test_fs_search_persistence", 346 GNUNET_log_setup ("test_fs_search_persistence",
361#if VERBOSE 347#if VERBOSE
362 "DEBUG", 348 "DEBUG",
363#else 349#else
364 "WARNING", 350 "WARNING",
365#endif 351#endif
366 NULL); 352 NULL);
367 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, 353 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
368 argvx, "test-fs-search-persistence", 354 argvx, "test-fs-search-persistence",
369 "nohelp", options, &run, NULL); 355 "nohelp", options, &run, NULL);
370 stop_arm (&p1); 356 stop_arm (&p1);
371 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-search/"); 357 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-search/");
372 return 0; 358 return 0;
diff --git a/src/fs/test_fs_search_ranking.c b/src/fs/test_fs_search_ranking.c
index 06c37dfc2..b19ff97bf 100644
--- a/src/fs/test_fs_search_ranking.c
+++ b/src/fs/test_fs_search_ranking.c
@@ -37,8 +37,7 @@ makeName (unsigned int i)
37{ 37{
38 char *fn; 38 char *fn;
39 39
40 fn = 40 fn = GNUNET_malloc (strlen ("/tmp/gnunet-fsui-searchranktest/FSUITEST") + 14);
41 GNUNET_malloc (strlen ("/tmp/gnunet-fsui-searchranktest/FSUITEST") + 14);
42 GNUNET_snprintf (fn, 41 GNUNET_snprintf (fn,
43 strlen ("/tmp/gnunet-fsui-searchranktest/FSUITEST") + 14, 42 strlen ("/tmp/gnunet-fsui-searchranktest/FSUITEST") + 14,
44 "/tmp/gnunet-fsui-searchranktest/FSUITEST%u", i); 43 "/tmp/gnunet-fsui-searchranktest/FSUITEST%u", i);
@@ -64,57 +63,57 @@ eventCallback (void *cls, const GNUNET_FSUI_Event * event)
64 static char unused; 63 static char unused;
65 64
66 switch (event->type) 65 switch (event->type)
67 { 66 {
68 case GNUNET_FSUI_search_resumed: 67 case GNUNET_FSUI_search_resumed:
69 search = event->data.SearchResumed.sc.pos; 68 search = event->data.SearchResumed.sc.pos;
70 break; 69 break;
71 case GNUNET_FSUI_search_suspended: 70 case GNUNET_FSUI_search_suspended:
72 search = NULL; 71 search = NULL;
73 break; 72 break;
74 case GNUNET_FSUI_search_update: 73 case GNUNET_FSUI_search_update:
75 availability = event->data.SearchUpdate.availability_rank; 74 availability = event->data.SearchUpdate.availability_rank;
76 rank = event->data.SearchUpdate.applicability_rank; 75 rank = event->data.SearchUpdate.applicability_rank;
77 break; 76 break;
78 case GNUNET_FSUI_search_paused: 77 case GNUNET_FSUI_search_paused:
79 case GNUNET_FSUI_search_restarted: 78 case GNUNET_FSUI_search_restarted:
80 break; 79 break;
81 case GNUNET_FSUI_download_resumed: 80 case GNUNET_FSUI_download_resumed:
82 case GNUNET_FSUI_upload_resumed: 81 case GNUNET_FSUI_upload_resumed:
83 case GNUNET_FSUI_unindex_resumed: 82 case GNUNET_FSUI_unindex_resumed:
84 return &unused; 83 return &unused;
85 case GNUNET_FSUI_search_result: 84 case GNUNET_FSUI_search_result:
86#if CHECK_VERBOSE 85#if CHECK_VERBOSE
87 printf ("Received search result\n"); 86 printf ("Received search result\n");
88#endif 87#endif
89 uri = GNUNET_ECRS_uri_duplicate (event->data.SearchResult.fi.uri); 88 uri = GNUNET_ECRS_uri_duplicate (event->data.SearchResult.fi.uri);
90 break; 89 break;
91 case GNUNET_FSUI_upload_completed: 90 case GNUNET_FSUI_upload_completed:
92#if CHECK_VERBOSE 91#if CHECK_VERBOSE
93 printf ("Upload complete.\n"); 92 printf ("Upload complete.\n");
94#endif 93#endif
95 break; 94 break;
96 case GNUNET_FSUI_download_completed: 95 case GNUNET_FSUI_download_completed:
97#if CHECK_VERBOSE 96#if CHECK_VERBOSE
98 printf ("Download complete.\n"); 97 printf ("Download complete.\n");
99#endif 98#endif
100 break; 99 break;
101 case GNUNET_FSUI_unindex_completed: 100 case GNUNET_FSUI_unindex_completed:
102#if CHECK_VERBOSE 101#if CHECK_VERBOSE
103 printf ("Unindex complete.\n"); 102 printf ("Unindex complete.\n");
104#endif 103#endif
105 break; 104 break;
106 case GNUNET_FSUI_upload_error: 105 case GNUNET_FSUI_upload_error:
107 printf ("Upload error.\n"); 106 printf ("Upload error.\n");
108 break; 107 break;
109 case GNUNET_FSUI_download_error: 108 case GNUNET_FSUI_download_error:
110 printf ("Download error.\n"); 109 printf ("Download error.\n");
111 break; 110 break;
112 case GNUNET_FSUI_unindex_error: 111 case GNUNET_FSUI_unindex_error:
113 printf ("Unindex error.\n"); 112 printf ("Unindex error.\n");
114 break; 113 break;
115 default: 114 default:
116 break; 115 break;
117 } 116 }
118 if (lastEvent != waitForEvent) 117 if (lastEvent != waitForEvent)
119 lastEvent = event->type; 118 lastEvent = event->type;
120 return NULL; 119 return NULL;
@@ -130,6 +129,7 @@ main (int argc, char *argv[])
130#endif 129#endif
131 int ok; 130 int ok;
132 char *fn = NULL; 131 char *fn = NULL;
132
133 char *keywords[] = { 133 char *keywords[] = {
134 "search_foo", 134 "search_foo",
135 "search_bar", 135 "search_bar",
@@ -146,17 +146,16 @@ main (int argc, char *argv[])
146 ok = GNUNET_YES; 146 ok = GNUNET_YES;
147 cfg = GNUNET_GC_create (); 147 cfg = GNUNET_GC_create ();
148 if (-1 == GNUNET_GC_parse_configuration (cfg, "check.conf")) 148 if (-1 == GNUNET_GC_parse_configuration (cfg, "check.conf"))
149 { 149 {
150 GNUNET_GC_free (cfg); 150 GNUNET_GC_free (cfg);
151 return -1; 151 return -1;
152 } 152 }
153#if START_DAEMON 153#if START_DAEMON
154 GNUNET_disk_directory_remove (NULL, "/tmp/gnunet-fsui-searchranktest/"); 154 GNUNET_disk_directory_remove (NULL, "/tmp/gnunet-fsui-searchranktest/");
155 daemon = GNUNET_daemon_start (NULL, cfg, "peer.conf", GNUNET_NO); 155 daemon = GNUNET_daemon_start (NULL, cfg, "peer.conf", GNUNET_NO);
156 GNUNET_GE_ASSERT (NULL, daemon != NULL); 156 GNUNET_GE_ASSERT (NULL, daemon != NULL);
157 CHECK (GNUNET_OK == 157 CHECK (GNUNET_OK ==
158 GNUNET_wait_for_daemon_running (NULL, cfg, 158 GNUNET_wait_for_daemon_running (NULL, cfg, 30 * GNUNET_CRON_SECONDS));
159 30 * GNUNET_CRON_SECONDS));
160 GNUNET_thread_sleep (5 * GNUNET_CRON_SECONDS); /* give apps time to start */ 159 GNUNET_thread_sleep (5 * GNUNET_CRON_SECONDS); /* give apps time to start */
161 /* ACTUAL TEST CODE */ 160 /* ACTUAL TEST CODE */
162#endif 161#endif
@@ -167,21 +166,20 @@ main (int argc, char *argv[])
167 /* upload */ 166 /* upload */
168 fn = makeName (42); 167 fn = makeName (42);
169 GNUNET_disk_file_write (NULL, 168 GNUNET_disk_file_write (NULL,
170 fn, "foo bar test!", strlen ("foo bar test!"), 169 fn, "foo bar test!", strlen ("foo bar test!"), "600");
171 "600");
172 meta = GNUNET_meta_data_create (); 170 meta = GNUNET_meta_data_create ();
173 kuri = 171 kuri =
174 GNUNET_ECRS_keyword_command_line_to_uri (NULL, 2, 172 GNUNET_ECRS_keyword_command_line_to_uri (NULL, 2,
175 (const char **) keywords); 173 (const char **) keywords);
176 waitForEvent = GNUNET_FSUI_upload_completed; 174 waitForEvent = GNUNET_FSUI_upload_completed;
177 upload = 175 upload =
178 GNUNET_FSUI_upload_start (ctx, 176 GNUNET_FSUI_upload_start (ctx,
179 fn, 177 fn,
180 (GNUNET_FSUI_DirectoryScanCallback) & 178 (GNUNET_FSUI_DirectoryScanCallback) &
181 GNUNET_disk_directory_scan, NULL, 0, 0, 179 GNUNET_disk_directory_scan, NULL, 0, 0,
182 GNUNET_YES, GNUNET_NO, GNUNET_NO, 180 GNUNET_YES, GNUNET_NO, GNUNET_NO,
183 GNUNET_get_time () + 5 * GNUNET_CRON_HOURS, 181 GNUNET_get_time () + 5 * GNUNET_CRON_HOURS,
184 meta, kuri, kuri); 182 meta, kuri, kuri);
185 CHECK (NULL != upload); 183 CHECK (NULL != upload);
186 GNUNET_free (fn); 184 GNUNET_free (fn);
187 fn = NULL; 185 fn = NULL;
@@ -189,19 +187,18 @@ main (int argc, char *argv[])
189 GNUNET_meta_data_destroy (meta); 187 GNUNET_meta_data_destroy (meta);
190 prog = 0; 188 prog = 0;
191 while (lastEvent != GNUNET_FSUI_upload_completed) 189 while (lastEvent != GNUNET_FSUI_upload_completed)
190 {
191 prog++;
192 if (prog == 10000)
192 { 193 {
193 prog++; 194 fprintf (stderr,
194 if (prog == 10000) 195 "Upload failed to complete -- last event: %u\n", lastEvent);
195 {
196 fprintf (stderr,
197 "Upload failed to complete -- last event: %u\n",
198 lastEvent);
199 }
200 CHECK (prog < 10000);
201 GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
202 if (GNUNET_shutdown_test () == GNUNET_YES)
203 break;
204 } 196 }
197 CHECK (prog < 10000);
198 GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
199 if (GNUNET_shutdown_test () == GNUNET_YES)
200 break;
201 }
205 GNUNET_FSUI_upload_stop (upload); 202 GNUNET_FSUI_upload_stop (upload);
206 203
207 /* search */ 204 /* search */
@@ -217,11 +214,11 @@ main (int argc, char *argv[])
217 while ((uri == NULL) && 214 while ((uri == NULL) &&
218 (availability < 3) && 215 (availability < 3) &&
219 (rank != 2) && (GNUNET_shutdown_test () != GNUNET_YES)) 216 (rank != 2) && (GNUNET_shutdown_test () != GNUNET_YES))
220 { 217 {
221 prog++; 218 prog++;
222 CHECK (prog < 10000); 219 CHECK (prog < 10000);
223 GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS); 220 GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
224 } 221 }
225 GNUNET_FSUI_search_abort (search); 222 GNUNET_FSUI_search_abort (search);
226 GNUNET_FSUI_search_stop (search); 223 GNUNET_FSUI_search_stop (search);
227 CHECK (uri != NULL); 224 CHECK (uri != NULL);
diff --git a/src/fs/test_fs_start_stop.c b/src/fs/test_fs_start_stop.c
index 5080ecc18..e38a4b965 100644
--- a/src/fs/test_fs_start_stop.c
+++ b/src/fs/test_fs_start_stop.c
@@ -45,8 +45,7 @@ struct PeerContext
45 45
46 46
47static void * 47static void *
48progress_cb (void *cls, 48progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
49 const struct GNUNET_FS_ProgressInfo *event)
50{ 49{
51 return NULL; 50 return NULL;
52} 51}
@@ -58,11 +57,11 @@ setup_peer (struct PeerContext *p, const char *cfgname)
58 p->cfg = GNUNET_CONFIGURATION_create (); 57 p->cfg = GNUNET_CONFIGURATION_create ();
59#if START_ARM 58#if START_ARM
60 p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", 59 p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
61 "gnunet-service-arm", 60 "gnunet-service-arm",
62#if VERBOSE 61#if VERBOSE
63 "-L", "DEBUG", 62 "-L", "DEBUG",
64#endif 63#endif
65 "-c", cfgname, NULL); 64 "-c", cfgname, NULL);
66#endif 65#endif
67 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); 66 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
68} 67}
@@ -73,16 +72,17 @@ stop_arm (struct PeerContext *p)
73{ 72{
74#if START_ARM 73#if START_ARM
75 if (NULL != p->arm_proc) 74 if (NULL != p->arm_proc)
76 { 75 {
77 if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) 76 if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
78 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 77 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
79 if (GNUNET_OS_process_wait(p->arm_proc) != GNUNET_OK) 78 if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
80 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); 79 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
81 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 80 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
82 "ARM process %u stopped\n", GNUNET_OS_process_get_pid (p->arm_proc)); 81 "ARM process %u stopped\n",
83 GNUNET_OS_process_close (p->arm_proc); 82 GNUNET_OS_process_get_pid (p->arm_proc));
84 p->arm_proc = NULL; 83 GNUNET_OS_process_close (p->arm_proc);
85 } 84 p->arm_proc = NULL;
85 }
86#endif 86#endif
87 GNUNET_CONFIGURATION_destroy (p->cfg); 87 GNUNET_CONFIGURATION_destroy (p->cfg);
88} 88}
@@ -91,19 +91,16 @@ stop_arm (struct PeerContext *p)
91static void 91static void
92run (void *cls, 92run (void *cls,
93 char *const *args, 93 char *const *args,
94 const char *cfgfile, 94 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
95 const struct GNUNET_CONFIGURATION_Handle *cfg)
96{ 95{
97 struct GNUNET_FS_Handle *fs; 96 struct GNUNET_FS_Handle *fs;
98 97
99 setup_peer (&p1, "test_fs_data.conf"); 98 setup_peer (&p1, "test_fs_data.conf");
100 fs = GNUNET_FS_start (cfg, 99 fs = GNUNET_FS_start (cfg,
101 "test-fs-start-stop", 100 "test-fs-start-stop",
102 &progress_cb, 101 &progress_cb,
103 NULL, 102 NULL, GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
104 GNUNET_FS_FLAGS_NONE, 103 GNUNET_assert (NULL != fs);
105 GNUNET_FS_OPTIONS_END);
106 GNUNET_assert (NULL != fs);
107 GNUNET_FS_stop (fs); 104 GNUNET_FS_stop (fs);
108} 105}
109 106
@@ -111,7 +108,7 @@ run (void *cls,
111int 108int
112main (int argc, char *argv[]) 109main (int argc, char *argv[])
113{ 110{
114 char *const argvx[] = { 111 char *const argvx[] = {
115 "test-fs-start-stop", 112 "test-fs-start-stop",
116 "-c", 113 "-c",
117 "test_fs_data.conf", 114 "test_fs_data.conf",
@@ -124,16 +121,16 @@ main (int argc, char *argv[])
124 GNUNET_GETOPT_OPTION_END 121 GNUNET_GETOPT_OPTION_END
125 }; 122 };
126 123
127 GNUNET_log_setup ("test_fs_start_stop", 124 GNUNET_log_setup ("test_fs_start_stop",
128#if VERBOSE 125#if VERBOSE
129 "DEBUG", 126 "DEBUG",
130#else 127#else
131 "WARNING", 128 "WARNING",
132#endif 129#endif
133 NULL); 130 NULL);
134 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, 131 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
135 argvx, "test-fs-start-stop", 132 argvx, "test-fs-start-stop",
136 "nohelp", options, &run, NULL); 133 "nohelp", options, &run, NULL);
137 stop_arm (&p1); 134 stop_arm (&p1);
138 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs/"); 135 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs/");
139 return 0; 136 return 0;
diff --git a/src/fs/test_fs_test_lib.c b/src/fs/test_fs_test_lib.c
index 3c6826181..9aa7b2ee3 100644
--- a/src/fs/test_fs_test_lib.c
+++ b/src/fs/test_fs_test_lib.c
@@ -47,112 +47,91 @@ static struct GNUNET_FS_TestDaemon *daemons[NUM_DAEMONS];
47static int ret; 47static int ret;
48 48
49static void 49static void
50do_stop (void *cls, 50do_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
51 const struct GNUNET_SCHEDULER_TaskContext *tc)
52{ 51{
53 if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE)) 52 if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE))
54 { 53 {
55 GNUNET_break (0); 54 GNUNET_break (0);
56 ret = 1; 55 ret = 1;
57 } 56 }
58 else 57 else
59 { 58 {
60 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 59 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
61 "Finished download, shutting down\n", 60 "Finished download, shutting down\n",
62 (unsigned long long) FILESIZE); 61 (unsigned long long) FILESIZE);
63 } 62 }
64 GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, 63 GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, daemons);
65 daemons);
66} 64}
67 65
68 66
69static void 67static void
70do_download (void *cls, 68do_download (void *cls, const struct GNUNET_FS_Uri *uri)
71 const struct GNUNET_FS_Uri *uri)
72{ 69{
73 if (NULL == uri) 70 if (NULL == uri)
74 { 71 {
75 GNUNET_break (0); 72 GNUNET_break (0);
76 GNUNET_SCHEDULER_add_now (&do_stop, 73 GNUNET_SCHEDULER_add_now (&do_stop, NULL);
77 NULL); 74 ret = 1;
78 ret = 1; 75 return;
79 return; 76 }
80 }
81 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 77 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
82 "Downloading %llu bytes\n", 78 "Downloading %llu bytes\n", (unsigned long long) FILESIZE);
83 (unsigned long long) FILESIZE);
84 GNUNET_FS_TEST_download (daemons[0], 79 GNUNET_FS_TEST_download (daemons[0],
85 TIMEOUT, 80 TIMEOUT, 1, SEED, uri, VERBOSE, &do_stop, NULL);
86 1, SEED, uri,
87 VERBOSE,
88 &do_stop, NULL);
89} 81}
90 82
91 83
92static void 84static void
93do_publish (void *cls, 85do_publish (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
94 const struct GNUNET_SCHEDULER_TaskContext *tc)
95{ 86{
96 if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE)) 87 if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE))
97 { 88 {
98 GNUNET_break (0); 89 GNUNET_break (0);
99 ret = 1; 90 ret = 1;
100 GNUNET_SCHEDULER_add_now (&do_stop, 91 GNUNET_SCHEDULER_add_now (&do_stop, NULL);
101 NULL); 92 return;
102 return; 93 }
103 }
104 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 94 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
105 "Publishing %llu bytes\n", 95 "Publishing %llu bytes\n", (unsigned long long) FILESIZE);
106 (unsigned long long) FILESIZE);
107 GNUNET_FS_TEST_publish (daemons[0], 96 GNUNET_FS_TEST_publish (daemons[0],
108 TIMEOUT, 97 TIMEOUT,
109 1, GNUNET_NO, FILESIZE, SEED, 98 1, GNUNET_NO, FILESIZE, SEED,
110 VERBOSE, 99 VERBOSE, &do_download, NULL);
111 &do_download, NULL);
112} 100}
113 101
114 102
115static void 103static void
116do_connect (void *cls, 104do_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
117 const struct GNUNET_SCHEDULER_TaskContext *tc)
118{ 105{
119 if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE)) 106 if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE))
120 { 107 {
121 GNUNET_break (0); 108 GNUNET_break (0);
122 ret = 1; 109 ret = 1;
123 GNUNET_SCHEDULER_add_now (&do_stop, 110 GNUNET_SCHEDULER_add_now (&do_stop, NULL);
124 NULL); 111 return;
125 return; 112 }
126 }
127 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 113 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
128 "Daemons started, will now try to connect them\n"); 114 "Daemons started, will now try to connect them\n");
129 GNUNET_FS_TEST_daemons_connect (daemons[0], 115 GNUNET_FS_TEST_daemons_connect (daemons[0],
130 daemons[1], 116 daemons[1], TIMEOUT, &do_publish, NULL);
131 TIMEOUT,
132 &do_publish,
133 NULL);
134} 117}
135 118
136 119
137static void 120static void
138run (void *cls, 121run (void *cls,
139 char *const *args, 122 char *const *args,
140 const char *cfgfile, 123 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
141 const struct GNUNET_CONFIGURATION_Handle *cfg)
142{ 124{
143 GNUNET_FS_TEST_daemons_start ("fs_test_lib_data.conf", 125 GNUNET_FS_TEST_daemons_start ("fs_test_lib_data.conf",
144 TIMEOUT, 126 TIMEOUT,
145 NUM_DAEMONS, 127 NUM_DAEMONS, daemons, &do_connect, NULL);
146 daemons,
147 &do_connect,
148 NULL);
149} 128}
150 129
151 130
152int 131int
153main (int argc, char *argv[]) 132main (int argc, char *argv[])
154{ 133{
155 char *const argvx[] = { 134 char *const argvx[] = {
156 "test-fs-test-lib", 135 "test-fs-test-lib",
157 "-c", 136 "-c",
158 "fs_test_lib_data.conf", 137 "fs_test_lib_data.conf",
@@ -166,16 +145,15 @@ main (int argc, char *argv[])
166 }; 145 };
167 146
168 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/"); 147 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/");
169 GNUNET_log_setup ("test_fs_test_lib", 148 GNUNET_log_setup ("test_fs_test_lib",
170#if VERBOSE 149#if VERBOSE
171 "DEBUG", 150 "DEBUG",
172#else 151#else
173 "WARNING", 152 "WARNING",
174#endif 153#endif
175 NULL); 154 NULL);
176 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, 155 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
177 argvx, "test-fs-test-lib", 156 argvx, "test-fs-test-lib", "nohelp", options, &run, NULL);
178 "nohelp", options, &run, NULL);
179 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/"); 157 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/");
180 return ret; 158 return ret;
181} 159}
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
51struct PeerContext 51struct PeerContext
@@ -70,8 +70,7 @@ static char *fn;
70 70
71 71
72static void 72static void
73abort_publish_task (void *cls, 73abort_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
81static void 80static void
82abort_unindex_task (void *cls, 81abort_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
93static void * 91static void *
94progress_cb (void *cls, 92progress_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)
224static void 226static void
225run (void *cls, 227run (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,
284int 282int
285main (int argc, char *argv[]) 283main (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
diff --git a/src/fs/test_fs_unindex_persistence.c b/src/fs/test_fs_unindex_persistence.c
index 095c6961f..191dec57d 100644
--- a/src/fs/test_fs_unindex_persistence.c
+++ b/src/fs/test_fs_unindex_persistence.c
@@ -44,7 +44,7 @@
44 44
45/** 45/**
46 * How long should our test-content live? 46 * How long should our test-content live?
47 */ 47 */
48#define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) 48#define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)
49 49
50struct PeerContext 50struct PeerContext
@@ -70,8 +70,7 @@ static char *fn;
70static const struct GNUNET_CONFIGURATION_Handle *cfg; 70static const struct GNUNET_CONFIGURATION_Handle *cfg;
71 71
72static void 72static void
73abort_publish_task (void *cls, 73abort_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,39 +78,35 @@ abort_publish_task (void *cls,
79 78
80 79
81static void 80static void
82abort_unindex_task (void *cls, 81abort_unindex_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
83 const struct GNUNET_SCHEDULER_TaskContext *tc)
84{ 82{
85 if (unindex != NULL) 83 if (unindex != NULL)
86 { 84 {
87 GNUNET_FS_unindex_stop (unindex); 85 GNUNET_FS_unindex_stop (unindex);
88 unindex = NULL; 86 unindex = NULL;
89 } 87 }
90 if (fn != NULL) 88 if (fn != NULL)
91 { 89 {
92 GNUNET_DISK_directory_remove (fn); 90 GNUNET_DISK_directory_remove (fn);
93 GNUNET_free (fn); 91 GNUNET_free (fn);
94 fn = NULL; 92 fn = NULL;
95 } 93 }
96} 94}
97 95
98 96
99static void * 97static void *progress_cb (void *cls,
100progress_cb (void *cls, 98 const struct GNUNET_FS_ProgressInfo *event);
101 const struct GNUNET_FS_ProgressInfo *event);
102 99
103 100
104static void 101static void
105restart_fs_task (void *cls, 102restart_fs_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
106 const struct GNUNET_SCHEDULER_TaskContext *tc)
107{ 103{
108 GNUNET_FS_stop (fs); 104 GNUNET_FS_stop (fs);
109 fs = GNUNET_FS_start (cfg, 105 fs = GNUNET_FS_start (cfg,
110 "test-fs-unindex-persistence", 106 "test-fs-unindex-persistence",
111 &progress_cb, 107 &progress_cb,
112 NULL, 108 NULL,
113 GNUNET_FS_FLAGS_PERSISTENCE, 109 GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END);
114 GNUNET_FS_OPTIONS_END);
115} 110}
116 111
117 112
@@ -128,127 +123,130 @@ consider_restart (int ev)
128 static int prev[32]; 123 static int prev[32];
129 static int off; 124 static int off;
130 int i; 125 int i;
131 for (i=0;i<off;i++) 126
127 for (i = 0; i < off; i++)
132 if (prev[i] == ev) 128 if (prev[i] == ev)
133 return; 129 return;
134 prev[off++] = ev; 130 prev[off++] = ev;
135 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_URGENT, 131 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_URGENT,
136 &restart_fs_task, 132 &restart_fs_task, NULL);
137 NULL);
138} 133}
139 134
140 135
141static void * 136static void *
142progress_cb (void *cls, 137progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
143 const struct GNUNET_FS_ProgressInfo *event)
144{ 138{
145 switch (event->status) 139 switch (event->status)
146 { 140 {
147 case GNUNET_FS_STATUS_PUBLISH_PROGRESS: 141 case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
148#if VERBOSE 142#if VERBOSE
149 printf ("Publish is progressing (%llu/%llu at level %u off %llu)...\n", 143 printf ("Publish is progressing (%llu/%llu at level %u off %llu)...\n",
150 (unsigned long long) event->value.publish.completed, 144 (unsigned long long) event->value.publish.completed,
151 (unsigned long long) event->value.publish.size, 145 (unsigned long long) event->value.publish.size,
152 event->value.publish.specifics.progress.depth, 146 event->value.publish.specifics.progress.depth,
153 (unsigned long long) event->value.publish.specifics.progress.offset); 147 (unsigned long long) event->value.publish.specifics.
154#endif 148 progress.offset);
155 break; 149#endif
156 case GNUNET_FS_STATUS_PUBLISH_COMPLETED: 150 break;
157 printf ("Publishing complete, %llu kbps.\n", 151 case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
158 (unsigned long long) (FILESIZE * 1000 / (1+GNUNET_TIME_absolute_get_duration (start).rel_value) / 1024)); 152 printf ("Publishing complete, %llu kbps.\n",
159 start = GNUNET_TIME_absolute_get (); 153 (unsigned long long) (FILESIZE * 1000 /
160 unindex = GNUNET_FS_unindex_start (fs, 154 (1 +
161 fn, 155 GNUNET_TIME_absolute_get_duration
162 "unindex"); 156 (start).rel_value) / 1024));
163 GNUNET_assert (unindex != NULL); 157 start = GNUNET_TIME_absolute_get ();
164 break; 158 unindex = GNUNET_FS_unindex_start (fs, fn, "unindex");
165 case GNUNET_FS_STATUS_UNINDEX_COMPLETED: 159 GNUNET_assert (unindex != NULL);
166 printf ("Unindex complete, %llu kbps.\n", 160 break;
167 (unsigned long long) (FILESIZE * 1000 / (1+GNUNET_TIME_absolute_get_duration (start).rel_value) / 1024)); 161 case GNUNET_FS_STATUS_UNINDEX_COMPLETED:
168 GNUNET_SCHEDULER_add_continuation (&abort_unindex_task, 162 printf ("Unindex complete, %llu kbps.\n",
169 NULL, 163 (unsigned long long) (FILESIZE * 1000 /
170 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 164 (1 +
171 break; 165 GNUNET_TIME_absolute_get_duration
172 case GNUNET_FS_STATUS_UNINDEX_PROGRESS: 166 (start).rel_value) / 1024));
173 consider_restart (event->status); 167 GNUNET_SCHEDULER_add_continuation (&abort_unindex_task, NULL,
174 GNUNET_assert (unindex == event->value.unindex.uc); 168 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
169 break;
170 case GNUNET_FS_STATUS_UNINDEX_PROGRESS:
171 consider_restart (event->status);
172 GNUNET_assert (unindex == event->value.unindex.uc);
175#if VERBOSE 173#if VERBOSE
176 printf ("Unindex is progressing (%llu/%llu at level %u off %llu)...\n", 174 printf ("Unindex is progressing (%llu/%llu at level %u off %llu)...\n",
177 (unsigned long long) event->value.unindex.completed, 175 (unsigned long long) event->value.unindex.completed,
178 (unsigned long long) event->value.unindex.size, 176 (unsigned long long) event->value.unindex.size,
179 event->value.unindex.specifics.progress.depth, 177 event->value.unindex.specifics.progress.depth,
180 (unsigned long long) event->value.unindex.specifics.progress.offset); 178 (unsigned long long) event->value.unindex.specifics.
179 progress.offset);
181#endif 180#endif
182 break; 181 break;
183 case GNUNET_FS_STATUS_PUBLISH_SUSPEND: 182 case GNUNET_FS_STATUS_PUBLISH_SUSPEND:
184 if (event->value.publish.pc == publish) 183 if (event->value.publish.pc == publish)
185 publish = NULL; 184 publish = NULL;
186 break; 185 break;
187 case GNUNET_FS_STATUS_PUBLISH_RESUME: 186 case GNUNET_FS_STATUS_PUBLISH_RESUME:
188 if (NULL == publish) 187 if (NULL == publish)
189 { 188 {
190 publish = event->value.publish.pc; 189 publish = event->value.publish.pc;
191 return "publish-context"; 190 return "publish-context";
192 }
193 break;
194 case GNUNET_FS_STATUS_UNINDEX_SUSPEND:
195 GNUNET_assert (event->value.unindex.uc == unindex);
196 unindex = NULL;
197 break;
198 case GNUNET_FS_STATUS_UNINDEX_RESUME:
199 GNUNET_assert (NULL == unindex);
200 unindex = event->value.unindex.uc;
201 return "unindex";
202 case GNUNET_FS_STATUS_PUBLISH_ERROR:
203 fprintf (stderr,
204 "Error publishing file: %s\n",
205 event->value.publish.specifics.error.message);
206 GNUNET_break (0);
207 GNUNET_SCHEDULER_add_continuation (&abort_publish_task,
208 NULL,
209 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
210 break;
211 case GNUNET_FS_STATUS_UNINDEX_ERROR:
212 fprintf (stderr,
213 "Error unindexing file: %s\n",
214 event->value.unindex.specifics.error.message);
215 GNUNET_SCHEDULER_add_continuation (&abort_unindex_task,
216 NULL,
217 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
218 break;
219 case GNUNET_FS_STATUS_PUBLISH_START:
220 GNUNET_assert (0 == strcmp ("publish-context", event->value.publish.cctx));
221 GNUNET_assert (NULL == event->value.publish.pctx);
222 GNUNET_assert (FILESIZE == event->value.publish.size);
223 GNUNET_assert (0 == event->value.publish.completed);
224 GNUNET_assert (1 == event->value.publish.anonymity);
225 break;
226 case GNUNET_FS_STATUS_PUBLISH_STOPPED:
227 GNUNET_assert (publish == event->value.publish.pc);
228 GNUNET_assert (FILESIZE == event->value.publish.size);
229 GNUNET_assert (1 == event->value.publish.anonymity);
230 GNUNET_FS_stop (fs);
231 fs = NULL;
232 break;
233 case GNUNET_FS_STATUS_UNINDEX_START:
234 consider_restart (event->status);
235 GNUNET_assert (unindex == NULL);
236 GNUNET_assert (0 == strcmp ("unindex", event->value.unindex.cctx));
237 GNUNET_assert (0 == strcmp (fn, event->value.unindex.filename));
238 GNUNET_assert (FILESIZE == event->value.unindex.size);
239 GNUNET_assert (0 == event->value.unindex.completed);
240 break;
241 case GNUNET_FS_STATUS_UNINDEX_STOPPED:
242 GNUNET_assert (unindex == event->value.unindex.uc);
243 GNUNET_SCHEDULER_add_continuation (&abort_publish_task,
244 NULL,
245 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
246 break;
247 default:
248 printf ("Unexpected event: %d\n",
249 event->status);
250 break;
251 } 191 }
192 break;
193 case GNUNET_FS_STATUS_UNINDEX_SUSPEND:
194 GNUNET_assert (event->value.unindex.uc == unindex);
195 unindex = NULL;
196 break;
197 case GNUNET_FS_STATUS_UNINDEX_RESUME:
198 GNUNET_assert (NULL == unindex);
199 unindex = event->value.unindex.uc;
200 return "unindex";
201 case GNUNET_FS_STATUS_PUBLISH_ERROR:
202 fprintf (stderr,
203 "Error publishing file: %s\n",
204 event->value.publish.specifics.error.message);
205 GNUNET_break (0);
206 GNUNET_SCHEDULER_add_continuation (&abort_publish_task,
207 NULL,
208 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
209 break;
210 case GNUNET_FS_STATUS_UNINDEX_ERROR:
211 fprintf (stderr,
212 "Error unindexing file: %s\n",
213 event->value.unindex.specifics.error.message);
214 GNUNET_SCHEDULER_add_continuation (&abort_unindex_task,
215 NULL,
216 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
217 break;
218 case GNUNET_FS_STATUS_PUBLISH_START:
219 GNUNET_assert (0 == strcmp ("publish-context", event->value.publish.cctx));
220 GNUNET_assert (NULL == event->value.publish.pctx);
221 GNUNET_assert (FILESIZE == event->value.publish.size);
222 GNUNET_assert (0 == event->value.publish.completed);
223 GNUNET_assert (1 == event->value.publish.anonymity);
224 break;
225 case GNUNET_FS_STATUS_PUBLISH_STOPPED:
226 GNUNET_assert (publish == event->value.publish.pc);
227 GNUNET_assert (FILESIZE == event->value.publish.size);
228 GNUNET_assert (1 == event->value.publish.anonymity);
229 GNUNET_FS_stop (fs);
230 fs = NULL;
231 break;
232 case GNUNET_FS_STATUS_UNINDEX_START:
233 consider_restart (event->status);
234 GNUNET_assert (unindex == NULL);
235 GNUNET_assert (0 == strcmp ("unindex", event->value.unindex.cctx));
236 GNUNET_assert (0 == strcmp (fn, event->value.unindex.filename));
237 GNUNET_assert (FILESIZE == event->value.unindex.size);
238 GNUNET_assert (0 == event->value.unindex.completed);
239 break;
240 case GNUNET_FS_STATUS_UNINDEX_STOPPED:
241 GNUNET_assert (unindex == event->value.unindex.uc);
242 GNUNET_SCHEDULER_add_continuation (&abort_publish_task,
243 NULL,
244 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
245 break;
246 default:
247 printf ("Unexpected event: %d\n", event->status);
248 break;
249 }
252 return NULL; 250 return NULL;
253} 251}
254 252
@@ -259,11 +257,11 @@ setup_peer (struct PeerContext *p, const char *cfgname)
259 p->cfg = GNUNET_CONFIGURATION_create (); 257 p->cfg = GNUNET_CONFIGURATION_create ();
260#if START_ARM 258#if START_ARM
261 p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", 259 p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
262 "gnunet-service-arm", 260 "gnunet-service-arm",
263#if VERBOSE 261#if VERBOSE
264 "-L", "DEBUG", 262 "-L", "DEBUG",
265#endif 263#endif
266 "-c", cfgname, NULL); 264 "-c", cfgname, NULL);
267#endif 265#endif
268 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); 266 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
269} 267}
@@ -274,16 +272,17 @@ stop_arm (struct PeerContext *p)
274{ 272{
275#if START_ARM 273#if START_ARM
276 if (NULL != p->arm_proc) 274 if (NULL != p->arm_proc)
277 { 275 {
278 if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) 276 if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
279 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 277 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
280 if (GNUNET_OS_process_wait(p->arm_proc) != GNUNET_OK) 278 if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
281 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); 279 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
282 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 280 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
283 "ARM process %u stopped\n", GNUNET_OS_process_get_pid (p->arm_proc)); 281 "ARM process %u stopped\n",
284 GNUNET_OS_process_close (p->arm_proc); 282 GNUNET_OS_process_get_pid (p->arm_proc));
285 p->arm_proc = NULL; 283 GNUNET_OS_process_close (p->arm_proc);
286 } 284 p->arm_proc = NULL;
285 }
287#endif 286#endif
288 GNUNET_CONFIGURATION_destroy (p->cfg); 287 GNUNET_CONFIGURATION_destroy (p->cfg);
289} 288}
@@ -292,8 +291,7 @@ stop_arm (struct PeerContext *p)
292static void 291static void
293run (void *cls, 292run (void *cls,
294 char *const *args, 293 char *const *args,
295 const char *cfgfile, 294 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
296 const struct GNUNET_CONFIGURATION_Handle *c)
297{ 295{
298 const char *keywords[] = { 296 const char *keywords[] = {
299 "down_foo", 297 "down_foo",
@@ -310,20 +308,20 @@ run (void *cls,
310 setup_peer (&p1, "test_fs_unindex_data.conf"); 308 setup_peer (&p1, "test_fs_unindex_data.conf");
311 fn = GNUNET_DISK_mktemp ("gnunet-unindex-test-dst"); 309 fn = GNUNET_DISK_mktemp ("gnunet-unindex-test-dst");
312 fs = GNUNET_FS_start (cfg, 310 fs = GNUNET_FS_start (cfg,
313 "test-fs-unindex-persistence", 311 "test-fs-unindex-persistence",
314 &progress_cb, 312 &progress_cb,
315 NULL, 313 NULL,
316 GNUNET_FS_FLAGS_PERSISTENCE, 314 GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END);
317 GNUNET_FS_OPTIONS_END); 315 GNUNET_assert (NULL != fs);
318 GNUNET_assert (NULL != fs);
319 buf = GNUNET_malloc (FILESIZE); 316 buf = GNUNET_malloc (FILESIZE);
320 for (i = 0; i < FILESIZE; i++) 317 for (i = 0; i < FILESIZE; i++)
321 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); 318 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
322 GNUNET_assert (FILESIZE == 319 GNUNET_assert (FILESIZE ==
323 GNUNET_DISK_fn_write (fn, 320 GNUNET_DISK_fn_write (fn,
324 buf, 321 buf,
325 FILESIZE, 322 FILESIZE,
326 GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE)); 323 GNUNET_DISK_PERM_USER_READ |
324 GNUNET_DISK_PERM_USER_WRITE));
327 GNUNET_free (buf); 325 GNUNET_free (buf);
328 meta = GNUNET_CONTAINER_meta_data_create (); 326 meta = GNUNET_CONTAINER_meta_data_create ();
329 kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords); 327 kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords);
@@ -332,20 +330,18 @@ run (void *cls,
332 bo.replication_level = 0; 330 bo.replication_level = 0;
333 bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME); 331 bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME);
334 fi = GNUNET_FS_file_information_create_from_file (fs, 332 fi = GNUNET_FS_file_information_create_from_file (fs,
335 "publish-context", 333 "publish-context",
336 fn, 334 fn,
337 kuri, 335 kuri,
338 meta, 336 meta, GNUNET_YES, &bo);
339 GNUNET_YES,
340 &bo);
341 GNUNET_FS_uri_destroy (kuri); 337 GNUNET_FS_uri_destroy (kuri);
342 GNUNET_CONTAINER_meta_data_destroy (meta); 338 GNUNET_CONTAINER_meta_data_destroy (meta);
343 GNUNET_assert (NULL != fi); 339 GNUNET_assert (NULL != fi);
344 start = GNUNET_TIME_absolute_get (); 340 start = GNUNET_TIME_absolute_get ();
345 publish = GNUNET_FS_publish_start (fs, 341 publish = GNUNET_FS_publish_start (fs,
346 fi, 342 fi,
347 NULL, NULL, NULL, 343 NULL, NULL, NULL,
348 GNUNET_FS_PUBLISH_OPTION_NONE); 344 GNUNET_FS_PUBLISH_OPTION_NONE);
349 GNUNET_assert (publish != NULL); 345 GNUNET_assert (publish != NULL);
350} 346}
351 347
@@ -353,7 +349,7 @@ run (void *cls,
353int 349int
354main (int argc, char *argv[]) 350main (int argc, char *argv[])
355{ 351{
356 char *const argvx[] = { 352 char *const argvx[] = {
357 "test-fs-unindex", 353 "test-fs-unindex",
358 "-c", 354 "-c",
359 "test_fs_unindex_data.conf", 355 "test_fs_unindex_data.conf",
@@ -366,23 +362,22 @@ main (int argc, char *argv[])
366 GNUNET_GETOPT_OPTION_END 362 GNUNET_GETOPT_OPTION_END
367 }; 363 };
368 364
369 GNUNET_log_setup ("test_fs_unindex_persistence", 365 GNUNET_log_setup ("test_fs_unindex_persistence",
370#if VERBOSE 366#if VERBOSE
371 "DEBUG", 367 "DEBUG",
372#else 368#else
373 "WARNING", 369 "WARNING",
374#endif 370#endif
375 NULL); 371 NULL);
376 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, 372 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
377 argvx, "test-fs-unindex", 373 argvx, "test-fs-unindex", "nohelp", options, &run, NULL);
378 "nohelp", options, &run, NULL);
379 stop_arm (&p1); 374 stop_arm (&p1);
380 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-unindex/"); 375 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-unindex/");
381 if (NULL != fn) 376 if (NULL != fn)
382 { 377 {
383 GNUNET_DISK_directory_remove (fn); 378 GNUNET_DISK_directory_remove (fn);
384 GNUNET_free (fn); 379 GNUNET_free (fn);
385 } 380 }
386 return 0; 381 return 0;
387} 382}
388 383
diff --git a/src/fs/test_fs_uri.c b/src/fs/test_fs_uri.c
index 0894b8b93..e8f6ed70f 100644
--- a/src/fs/test_fs_uri.c
+++ b/src/fs/test_fs_uri.c
@@ -39,37 +39,37 @@ testKeyword ()
39 char *emsg; 39 char *emsg;
40 40
41 if (NULL != (ret = GNUNET_FS_uri_parse ("gnunet://fs/ksk/++", &emsg))) 41 if (NULL != (ret = GNUNET_FS_uri_parse ("gnunet://fs/ksk/++", &emsg)))
42 { 42 {
43 GNUNET_FS_uri_destroy (ret); 43 GNUNET_FS_uri_destroy (ret);
44 ABORT (); 44 ABORT ();
45 } 45 }
46 GNUNET_free (emsg); 46 GNUNET_free (emsg);
47 ret = GNUNET_FS_uri_parse ("gnunet://fs/ksk/foo+bar", &emsg); 47 ret = GNUNET_FS_uri_parse ("gnunet://fs/ksk/foo+bar", &emsg);
48 if (ret == NULL) 48 if (ret == NULL)
49 { 49 {
50 GNUNET_free (emsg); 50 GNUNET_free (emsg);
51 ABORT (); 51 ABORT ();
52 } 52 }
53 if (!GNUNET_FS_uri_test_ksk (ret)) 53 if (!GNUNET_FS_uri_test_ksk (ret))
54 { 54 {
55 GNUNET_FS_uri_destroy (ret); 55 GNUNET_FS_uri_destroy (ret);
56 ABORT (); 56 ABORT ();
57 } 57 }
58 if ((2 != ret->data.ksk.keywordCount) || 58 if ((2 != ret->data.ksk.keywordCount) ||
59 (0 != strcmp (" foo", ret->data.ksk.keywords[0])) || 59 (0 != strcmp (" foo", ret->data.ksk.keywords[0])) ||
60 (0 != strcmp (" bar", ret->data.ksk.keywords[1]))) 60 (0 != strcmp (" bar", ret->data.ksk.keywords[1])))
61 { 61 {
62 GNUNET_FS_uri_destroy (ret); 62 GNUNET_FS_uri_destroy (ret);
63 ABORT (); 63 ABORT ();
64 } 64 }
65 65
66 uri = GNUNET_FS_uri_to_string (ret); 66 uri = GNUNET_FS_uri_to_string (ret);
67 if (0 != strcmp (uri, "gnunet://fs/ksk/foo+bar")) 67 if (0 != strcmp (uri, "gnunet://fs/ksk/foo+bar"))
68 { 68 {
69 GNUNET_free (uri); 69 GNUNET_free (uri);
70 GNUNET_FS_uri_destroy (ret); 70 GNUNET_FS_uri_destroy (ret);
71 ABORT (); 71 ABORT ();
72 } 72 }
73 GNUNET_free (uri); 73 GNUNET_free (uri);
74 GNUNET_FS_uri_destroy (ret); 74 GNUNET_FS_uri_destroy (ret);
75 return 0; 75 return 0;
@@ -86,46 +86,45 @@ testLocation ()
86 struct GNUNET_CONFIGURATION_Handle *cfg; 86 struct GNUNET_CONFIGURATION_Handle *cfg;
87 87
88 baseURI = 88 baseURI =
89 GNUNET_FS_uri_parse ("gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.42", &emsg); 89 GNUNET_FS_uri_parse
90 ("gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.42",
91 &emsg);
90 GNUNET_assert (baseURI != NULL); 92 GNUNET_assert (baseURI != NULL);
91 GNUNET_assert (emsg == NULL); 93 GNUNET_assert (emsg == NULL);
92 cfg = GNUNET_CONFIGURATION_create (); 94 cfg = GNUNET_CONFIGURATION_create ();
93 if (GNUNET_OK != 95 if (GNUNET_OK != GNUNET_CONFIGURATION_parse (cfg, "test_fs_uri_data.conf"))
94 GNUNET_CONFIGURATION_parse (cfg, "test_fs_uri_data.conf")) 96 {
95 { 97 fprintf (stderr, "Failed to parse configuration file\n");
96 fprintf (stderr, "Failed to parse configuration file\n"); 98 GNUNET_FS_uri_destroy (baseURI);
97 GNUNET_FS_uri_destroy (baseURI); 99 GNUNET_CONFIGURATION_destroy (cfg);
98 GNUNET_CONFIGURATION_destroy (cfg); 100 return 1;
99 return 1; 101 }
100 } 102 uri = GNUNET_FS_uri_loc_create (baseURI, cfg, GNUNET_TIME_absolute_get ());
101 uri = GNUNET_FS_uri_loc_create (baseURI,
102 cfg,
103 GNUNET_TIME_absolute_get ());
104 if (uri == NULL) 103 if (uri == NULL)
105 { 104 {
106 GNUNET_break (0); 105 GNUNET_break (0);
107 GNUNET_FS_uri_destroy (baseURI); 106 GNUNET_FS_uri_destroy (baseURI);
108 GNUNET_CONFIGURATION_destroy (cfg); 107 GNUNET_CONFIGURATION_destroy (cfg);
109 return 1; 108 return 1;
110 } 109 }
111 if (!GNUNET_FS_uri_test_loc (uri)) 110 if (!GNUNET_FS_uri_test_loc (uri))
112 { 111 {
113 GNUNET_break (0); 112 GNUNET_break (0);
114 GNUNET_FS_uri_destroy (uri); 113 GNUNET_FS_uri_destroy (uri);
115 GNUNET_FS_uri_destroy (baseURI); 114 GNUNET_FS_uri_destroy (baseURI);
116 GNUNET_CONFIGURATION_destroy (cfg); 115 GNUNET_CONFIGURATION_destroy (cfg);
117 return 1; 116 return 1;
118 } 117 }
119 uri2 = GNUNET_FS_uri_loc_get_uri (uri); 118 uri2 = GNUNET_FS_uri_loc_get_uri (uri);
120 if (!GNUNET_FS_uri_test_equal (baseURI, uri2)) 119 if (!GNUNET_FS_uri_test_equal (baseURI, uri2))
121 { 120 {
122 GNUNET_break (0); 121 GNUNET_break (0);
123 GNUNET_FS_uri_destroy (uri); 122 GNUNET_FS_uri_destroy (uri);
124 GNUNET_FS_uri_destroy (uri2); 123 GNUNET_FS_uri_destroy (uri2);
125 GNUNET_FS_uri_destroy (baseURI); 124 GNUNET_FS_uri_destroy (baseURI);
126 GNUNET_CONFIGURATION_destroy (cfg); 125 GNUNET_CONFIGURATION_destroy (cfg);
127 return 1; 126 return 1;
128 } 127 }
129 GNUNET_FS_uri_destroy (uri2); 128 GNUNET_FS_uri_destroy (uri2);
130 GNUNET_FS_uri_destroy (baseURI); 129 GNUNET_FS_uri_destroy (baseURI);
131 uric = GNUNET_FS_uri_to_string (uri); 130 uric = GNUNET_FS_uri_to_string (uri);
@@ -136,22 +135,22 @@ testLocation ()
136 uri2 = GNUNET_FS_uri_parse (uric, &emsg); 135 uri2 = GNUNET_FS_uri_parse (uric, &emsg);
137 GNUNET_free (uric); 136 GNUNET_free (uric);
138 if (uri2 == NULL) 137 if (uri2 == NULL)
139 { 138 {
140 GNUNET_break (0); 139 GNUNET_break (0);
141 GNUNET_FS_uri_destroy (uri); 140 GNUNET_FS_uri_destroy (uri);
142 GNUNET_CONFIGURATION_destroy (cfg); 141 GNUNET_CONFIGURATION_destroy (cfg);
143 GNUNET_free (emsg); 142 GNUNET_free (emsg);
144 return 1; 143 return 1;
145 } 144 }
146 GNUNET_assert (NULL == emsg); 145 GNUNET_assert (NULL == emsg);
147 if (GNUNET_YES != GNUNET_FS_uri_test_equal (uri, uri2)) 146 if (GNUNET_YES != GNUNET_FS_uri_test_equal (uri, uri2))
148 { 147 {
149 GNUNET_break (0); 148 GNUNET_break (0);
150 GNUNET_FS_uri_destroy (uri); 149 GNUNET_FS_uri_destroy (uri);
151 GNUNET_FS_uri_destroy (uri2); 150 GNUNET_FS_uri_destroy (uri2);
152 GNUNET_CONFIGURATION_destroy (cfg); 151 GNUNET_CONFIGURATION_destroy (cfg);
153 return 1; 152 return 1;
154 } 153 }
155 GNUNET_FS_uri_destroy (uri2); 154 GNUNET_FS_uri_destroy (uri2);
156 GNUNET_FS_uri_destroy (uri); 155 GNUNET_FS_uri_destroy (uri);
157 GNUNET_CONFIGURATION_destroy (cfg); 156 GNUNET_CONFIGURATION_destroy (cfg);
@@ -166,51 +165,57 @@ testNamespace (int i)
166 char *emsg; 165 char *emsg;
167 166
168 if (NULL != 167 if (NULL !=
169 (ret = GNUNET_FS_uri_parse ("gnunet://fs/sks/D1KJS9H2A82Q65VKQ0ML3RFU6U1D3VUK", &emsg))) 168 (ret =
170 { 169 GNUNET_FS_uri_parse ("gnunet://fs/sks/D1KJS9H2A82Q65VKQ0ML3RFU6U1D3VUK",
171 GNUNET_FS_uri_destroy (ret); 170 &emsg)))
172 ABORT (); 171 {
173 } 172 GNUNET_FS_uri_destroy (ret);
173 ABORT ();
174 }
174 GNUNET_free (emsg); 175 GNUNET_free (emsg);
175 if (NULL != 176 if (NULL !=
176 (ret = GNUNET_FS_uri_parse ("gnunet://fs/sks/D1KJS9H2A82Q65VKQ0ML3RFU6U1D3V/test", &emsg))) 177 (ret =
177 { 178 GNUNET_FS_uri_parse
178 GNUNET_FS_uri_destroy (ret); 179 ("gnunet://fs/sks/D1KJS9H2A82Q65VKQ0ML3RFU6U1D3V/test", &emsg)))
179 ABORT (); 180 {
180 } 181 GNUNET_FS_uri_destroy (ret);
182 ABORT ();
183 }
181 GNUNET_free (emsg); 184 GNUNET_free (emsg);
182 if (NULL != (ret = GNUNET_FS_uri_parse ("gnunet://fs/sks/test", &emsg))) 185 if (NULL != (ret = GNUNET_FS_uri_parse ("gnunet://fs/sks/test", &emsg)))
183 { 186 {
184 GNUNET_FS_uri_destroy (ret); 187 GNUNET_FS_uri_destroy (ret);
185 ABORT (); 188 ABORT ();
186 } 189 }
187 GNUNET_free (emsg); 190 GNUNET_free (emsg);
188 ret = 191 ret =
189 GNUNET_FS_uri_parse ("gnunet://fs/sks/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820/test", &emsg); 192 GNUNET_FS_uri_parse
193 ("gnunet://fs/sks/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820/test",
194 &emsg);
190 if (ret == NULL) 195 if (ret == NULL)
191 { 196 {
192 GNUNET_free (emsg); 197 GNUNET_free (emsg);
193 ABORT (); 198 ABORT ();
194 } 199 }
195 if (GNUNET_FS_uri_test_ksk (ret)) 200 if (GNUNET_FS_uri_test_ksk (ret))
196 { 201 {
197 GNUNET_FS_uri_destroy (ret); 202 GNUNET_FS_uri_destroy (ret);
198 ABORT (); 203 ABORT ();
199 } 204 }
200 if (!GNUNET_FS_uri_test_sks (ret)) 205 if (!GNUNET_FS_uri_test_sks (ret))
201 { 206 {
202 GNUNET_FS_uri_destroy (ret); 207 GNUNET_FS_uri_destroy (ret);
203 ABORT (); 208 ABORT ();
204 } 209 }
205 210
206 uri = GNUNET_FS_uri_to_string (ret); 211 uri = GNUNET_FS_uri_to_string (ret);
207 if (0 != strcmp (uri, 212 if (0 != strcmp (uri,
208 "gnunet://fs/sks/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820/test")) 213 "gnunet://fs/sks/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820/test"))
209 { 214 {
210 GNUNET_FS_uri_destroy (ret); 215 GNUNET_FS_uri_destroy (ret);
211 GNUNET_free (uri); 216 GNUNET_free (uri);
212 ABORT (); 217 ABORT ();
213 } 218 }
214 GNUNET_free (uri); 219 GNUNET_free (uri);
215 GNUNET_FS_uri_destroy (ret); 220 GNUNET_FS_uri_destroy (ret);
216 return 0; 221 return 0;
@@ -224,57 +229,68 @@ testFile (int i)
224 char *emsg; 229 char *emsg;
225 230
226 if (NULL != 231 if (NULL !=
227 (ret = GNUNET_FS_uri_parse ("gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H00000440000.42", &emsg))) 232 (ret =
228 { 233 GNUNET_FS_uri_parse
229 GNUNET_FS_uri_destroy (ret); 234 ("gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H00000440000.42",
230 ABORT (); 235 &emsg)))
231 } 236 {
237 GNUNET_FS_uri_destroy (ret);
238 ABORT ();
239 }
232 GNUNET_free (emsg); 240 GNUNET_free (emsg);
233 if (NULL != 241 if (NULL !=
234 (ret = GNUNET_FS_uri_parse ("gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000", &emsg))) 242 (ret =
235 { 243 GNUNET_FS_uri_parse
236 GNUNET_FS_uri_destroy (ret); 244 ("gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000",
237 ABORT (); 245 &emsg)))
238 } 246 {
247 GNUNET_FS_uri_destroy (ret);
248 ABORT ();
249 }
239 GNUNET_free (emsg); 250 GNUNET_free (emsg);
240 if (NULL != 251 if (NULL !=
241 (ret = GNUNET_FS_uri_parse ("gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.FGH", &emsg))) 252 (ret =
242 { 253 GNUNET_FS_uri_parse
243 GNUNET_FS_uri_destroy (ret); 254 ("gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.FGH",
244 ABORT (); 255 &emsg)))
245 } 256 {
257 GNUNET_FS_uri_destroy (ret);
258 ABORT ();
259 }
246 GNUNET_free (emsg); 260 GNUNET_free (emsg);
247 ret = 261 ret =
248 GNUNET_FS_uri_parse ("gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.42", &emsg); 262 GNUNET_FS_uri_parse
263 ("gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.42",
264 &emsg);
249 if (ret == NULL) 265 if (ret == NULL)
250 { 266 {
251 GNUNET_free (emsg); 267 GNUNET_free (emsg);
252 ABORT (); 268 ABORT ();
253 } 269 }
254 if (GNUNET_FS_uri_test_ksk (ret)) 270 if (GNUNET_FS_uri_test_ksk (ret))
255 { 271 {
256 GNUNET_FS_uri_destroy (ret); 272 GNUNET_FS_uri_destroy (ret);
257 ABORT (); 273 ABORT ();
258 } 274 }
259 if (GNUNET_FS_uri_test_sks (ret)) 275 if (GNUNET_FS_uri_test_sks (ret))
260 { 276 {
261 GNUNET_FS_uri_destroy (ret); 277 GNUNET_FS_uri_destroy (ret);
262 ABORT (); 278 ABORT ();
263 } 279 }
264 if (GNUNET_ntohll (ret->data.chk.file_length) != 42) 280 if (GNUNET_ntohll (ret->data.chk.file_length) != 42)
265 { 281 {
266 GNUNET_FS_uri_destroy (ret); 282 GNUNET_FS_uri_destroy (ret);
267 ABORT (); 283 ABORT ();
268 } 284 }
269 285
270 uri = GNUNET_FS_uri_to_string (ret); 286 uri = GNUNET_FS_uri_to_string (ret);
271 if (0 != strcmp (uri, 287 if (0 != strcmp (uri,
272 "gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.42")) 288 "gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.42"))
273 { 289 {
274 GNUNET_free (uri); 290 GNUNET_free (uri);
275 GNUNET_FS_uri_destroy (ret); 291 GNUNET_FS_uri_destroy (ret);
276 ABORT (); 292 ABORT ();
277 } 293 }
278 GNUNET_free (uri); 294 GNUNET_free (uri);
279 GNUNET_FS_uri_destroy (ret); 295 GNUNET_FS_uri_destroy (ret);
280 return 0; 296 return 0;
@@ -286,22 +302,22 @@ main (int argc, char *argv[])
286 int failureCount = 0; 302 int failureCount = 0;
287 int i; 303 int i;
288 304
289 GNUNET_log_setup ("test_fs_uri", 305 GNUNET_log_setup ("test_fs_uri",
290#if VERBOSE 306#if VERBOSE
291 "DEBUG", 307 "DEBUG",
292#else 308#else
293 "WARNING", 309 "WARNING",
294#endif 310#endif
295 NULL); 311 NULL);
296 GNUNET_CRYPTO_random_disable_entropy_gathering (); 312 GNUNET_CRYPTO_random_disable_entropy_gathering ();
297 failureCount += testKeyword (); 313 failureCount += testKeyword ();
298 failureCount += testLocation (); 314 failureCount += testLocation ();
299 for (i = 0; i < 255; i++) 315 for (i = 0; i < 255; i++)
300 { 316 {
301 /* fprintf (stderr, "."); */ 317 /* fprintf (stderr, "."); */
302 failureCount += testNamespace (i); 318 failureCount += testNamespace (i);
303 failureCount += testFile (i); 319 failureCount += testFile (i);
304 } 320 }
305 /* fprintf (stderr, "\n"); */ 321 /* fprintf (stderr, "\n"); */
306 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-uri"); 322 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-uri");
307 if (failureCount != 0) 323 if (failureCount != 0)
diff --git a/src/fs/test_gnunet_service_fs_migration.c b/src/fs/test_gnunet_service_fs_migration.c
index 092cedfc2..9a209521f 100644
--- a/src/fs/test_gnunet_service_fs_migration.c
+++ b/src/fs/test_gnunet_service_fs_migration.c
@@ -53,172 +53,140 @@ static int ok;
53static struct GNUNET_TIME_Absolute start_time; 53static struct GNUNET_TIME_Absolute start_time;
54 54
55static void 55static void
56do_stop (void *cls, 56do_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
57 const struct GNUNET_SCHEDULER_TaskContext *tc)
58{ 57{
59 struct GNUNET_TIME_Relative del; 58 struct GNUNET_TIME_Relative del;
60 char *fancy; 59 char *fancy;
61 60
62 GNUNET_FS_TEST_daemons_stop (2, 61 GNUNET_FS_TEST_daemons_stop (2, daemons);
63 daemons);
64 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE)) 62 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE))
65 { 63 {
66 del = GNUNET_TIME_absolute_get_duration (start_time); 64 del = GNUNET_TIME_absolute_get_duration (start_time);
67 if (del.rel_value == 0) 65 if (del.rel_value == 0)
68 del.rel_value = 1; 66 del.rel_value = 1;
69 fancy = GNUNET_STRINGS_byte_size_fancy (((unsigned long long)FILESIZE) * 1000LL / del.rel_value); 67 fancy =
70 fprintf (stdout, 68 GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) *
71 "Download speed was %s/s\n", 69 1000LL / del.rel_value);
72 fancy); 70 fprintf (stdout, "Download speed was %s/s\n", fancy);
73 GNUNET_free (fancy); 71 GNUNET_free (fancy);
74 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 72 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
75 "Finished download, shutting down\n", 73 "Finished download, shutting down\n",
76 (unsigned long long) FILESIZE); 74 (unsigned long long) FILESIZE);
77 } 75 }
78 else 76 else
79 { 77 {
80 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 78 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
81 "Timeout during download, shutting down with error\n"); 79 "Timeout during download, shutting down with error\n");
82 ok = 1; 80 ok = 1;
83 } 81 }
84} 82}
85 83
86 84
87static void 85static void
88do_download (void *cls, 86do_download (void *cls, const char *emsg)
89 const char *emsg)
90{ 87{
91 struct GNUNET_FS_Uri *uri = cls; 88 struct GNUNET_FS_Uri *uri = cls;
92 89
93 if (emsg != NULL) 90 if (emsg != NULL)
94 { 91 {
95 GNUNET_FS_TEST_daemons_stop (2, 92 GNUNET_FS_TEST_daemons_stop (2, daemons);
96 daemons); 93 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
97 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 94 "Failed to stop source daemon: %s\n", emsg);
98 "Failed to stop source daemon: %s\n", 95 GNUNET_FS_uri_destroy (uri);
99 emsg); 96 ok = 1;
100 GNUNET_FS_uri_destroy (uri); 97 return;
101 ok = 1; 98 }
102 return;
103 }
104 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 99 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
105 "Downloading %llu bytes\n", 100 "Downloading %llu bytes\n", (unsigned long long) FILESIZE);
106 (unsigned long long) FILESIZE);
107 start_time = GNUNET_TIME_absolute_get (); 101 start_time = GNUNET_TIME_absolute_get ();
108 GNUNET_FS_TEST_download (daemons[0], 102 GNUNET_FS_TEST_download (daemons[0],
109 TIMEOUT, 103 TIMEOUT, 1, SEED, uri, VERBOSE, &do_stop, NULL);
110 1, SEED, uri,
111 VERBOSE,
112 &do_stop, NULL);
113 GNUNET_FS_uri_destroy (uri); 104 GNUNET_FS_uri_destroy (uri);
114} 105}
115 106
116 107
117static void 108static void
118stop_source_peer (void *cls, 109stop_source_peer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
119 const struct GNUNET_SCHEDULER_TaskContext *tc)
120{ 110{
121 struct GNUNET_FS_Uri *uri = cls; 111 struct GNUNET_FS_Uri *uri = cls;
122 struct GNUNET_TESTING_PeerGroup *pg; 112 struct GNUNET_TESTING_PeerGroup *pg;
123 113
124 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 114 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping source peer\n");
125 "Stopping source peer\n");
126 pg = GNUNET_FS_TEST_get_group (daemons); 115 pg = GNUNET_FS_TEST_get_group (daemons);
127 GNUNET_TESTING_daemons_vary (pg, 1, GNUNET_NO, TIMEOUT, 116 GNUNET_TESTING_daemons_vary (pg, 1, GNUNET_NO, TIMEOUT, &do_download, uri);
128 &do_download,
129 uri);
130} 117}
131 118
132 119
133static void 120static void
134do_wait (void *cls, 121do_wait (void *cls, const struct GNUNET_FS_Uri *uri)
135 const struct GNUNET_FS_Uri *uri)
136{ 122{
137 struct GNUNET_FS_Uri *d; 123 struct GNUNET_FS_Uri *d;
138 124
139 if (NULL == uri) 125 if (NULL == uri)
140 { 126 {
141 GNUNET_FS_TEST_daemons_stop (2, 127 GNUNET_FS_TEST_daemons_stop (2, daemons);
142 daemons); 128 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
143 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 129 "Timeout during upload attempt, shutting down with error\n");
144 "Timeout during upload attempt, shutting down with error\n"); 130 ok = 1;
145 ok = 1; 131 return;
146 return; 132 }
147 } 133 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Waiting to allow content to migrate\n");
148 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
149 "Waiting to allow content to migrate\n");
150 d = GNUNET_FS_uri_dup (uri); 134 d = GNUNET_FS_uri_dup (uri);
151 (void) GNUNET_SCHEDULER_add_delayed (MIGRATION_DELAY, 135 (void) GNUNET_SCHEDULER_add_delayed (MIGRATION_DELAY, &stop_source_peer, d);
152 &stop_source_peer,
153 d);
154} 136}
155 137
156 138
157static void 139static void
158do_publish (void *cls, 140do_publish (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
159 const struct GNUNET_SCHEDULER_TaskContext *tc)
160{ 141{
161 if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE)) 142 if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE))
162 { 143 {
163 GNUNET_FS_TEST_daemons_stop (2, 144 GNUNET_FS_TEST_daemons_stop (2, daemons);
164 daemons); 145 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
165 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 146 "Timeout during connect attempt, shutting down with error\n");
166 "Timeout during connect attempt, shutting down with error\n"); 147 ok = 1;
167 ok = 1; 148 return;
168 return; 149 }
169 }
170 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 150 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
171 "Publishing %llu bytes\n", 151 "Publishing %llu bytes\n", (unsigned long long) FILESIZE);
172 (unsigned long long) FILESIZE);
173 GNUNET_FS_TEST_publish (daemons[1], 152 GNUNET_FS_TEST_publish (daemons[1],
174 TIMEOUT, 153 TIMEOUT,
175 1, GNUNET_NO, FILESIZE, SEED, 154 1, GNUNET_NO, FILESIZE, SEED,
176 VERBOSE, 155 VERBOSE, &do_wait, NULL);
177 &do_wait, NULL);
178} 156}
179 157
180 158
181static void 159static void
182do_connect (void *cls, 160do_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
183 const struct GNUNET_SCHEDULER_TaskContext *tc)
184{ 161{
185 if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE)) 162 if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE))
186 { 163 {
187 fprintf (stderr, 164 fprintf (stderr, "Daemons failed to start!\n");
188 "Daemons failed to start!\n"); 165 GNUNET_break (0);
189 GNUNET_break (0); 166 ok = 1;
190 ok = 1; 167 return;
191 return; 168 }
192 }
193 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 169 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
194 "Daemons started, will now try to connect them\n"); 170 "Daemons started, will now try to connect them\n");
195 GNUNET_FS_TEST_daemons_connect (daemons[0], 171 GNUNET_FS_TEST_daemons_connect (daemons[0],
196 daemons[1], 172 daemons[1], TIMEOUT, &do_publish, NULL);
197 TIMEOUT,
198 &do_publish,
199 NULL);
200} 173}
201 174
202 175
203static void 176static void
204run (void *cls, 177run (void *cls,
205 char *const *args, 178 char *const *args,
206 const char *cfgfile, 179 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
207 const struct GNUNET_CONFIGURATION_Handle *cfg)
208{ 180{
209 GNUNET_FS_TEST_daemons_start ("test_gnunet_service_fs_migration_data.conf", 181 GNUNET_FS_TEST_daemons_start ("test_gnunet_service_fs_migration_data.conf",
210 TIMEOUT, 182 TIMEOUT, 2, daemons, &do_connect, NULL);
211 2,
212 daemons,
213 &do_connect,
214 NULL);
215} 183}
216 184
217 185
218int 186int
219main (int argc, char *argv[]) 187main (int argc, char *argv[])
220{ 188{
221 char *const argvx[] = { 189 char *const argvx[] = {
222 "test-gnunet-service-fs-migration", 190 "test-gnunet-service-fs-migration",
223 "-c", 191 "-c",
224 "fs_test_lib_data.conf", 192 "fs_test_lib_data.conf",
@@ -232,16 +200,16 @@ main (int argc, char *argv[])
232 }; 200 };
233 201
234 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-service-fs-migration/"); 202 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-service-fs-migration/");
235 GNUNET_log_setup ("test_gnunet_service_fs_migration", 203 GNUNET_log_setup ("test_gnunet_service_fs_migration",
236#if VERBOSE 204#if VERBOSE
237 "DEBUG", 205 "DEBUG",
238#else 206#else
239 "WARNING", 207 "WARNING",
240#endif 208#endif
241 NULL); 209 NULL);
242 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, 210 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
243 argvx, "test-gnunet-service-fs-migration", 211 argvx, "test-gnunet-service-fs-migration",
244 "nohelp", options, &run, NULL); 212 "nohelp", options, &run, NULL);
245 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-service-fs-migration/"); 213 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-service-fs-migration/");
246 return ok; 214 return ok;
247} 215}
diff --git a/src/fs/test_gnunet_service_fs_p2p.c b/src/fs/test_gnunet_service_fs_p2p.c
index d21e700e5..c48f98666 100644
--- a/src/fs/test_gnunet_service_fs_p2p.c
+++ b/src/fs/test_gnunet_service_fs_p2p.c
@@ -49,120 +49,100 @@ static int ok;
49static struct GNUNET_TIME_Absolute start_time; 49static struct GNUNET_TIME_Absolute start_time;
50 50
51static void 51static void
52do_stop (void *cls, 52do_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
53 const struct GNUNET_SCHEDULER_TaskContext *tc)
54{ 53{
55 struct GNUNET_TIME_Relative del; 54 struct GNUNET_TIME_Relative del;
56 char *fancy; 55 char *fancy;
57 56
58 GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, 57 GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, daemons);
59 daemons);
60 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE)) 58 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE))
61 { 59 {
62 del = GNUNET_TIME_absolute_get_duration (start_time); 60 del = GNUNET_TIME_absolute_get_duration (start_time);
63 if (del.rel_value == 0) 61 if (del.rel_value == 0)
64 del.rel_value = 1; 62 del.rel_value = 1;
65 fancy = GNUNET_STRINGS_byte_size_fancy (((unsigned long long)FILESIZE) * 1000LL / del.rel_value); 63 fancy =
66 fprintf (stdout, 64 GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) *
67 "Download speed was %s/s\n", 65 1000LL / del.rel_value);
68 fancy); 66 fprintf (stdout, "Download speed was %s/s\n", fancy);
69 GNUNET_free (fancy); 67 GNUNET_free (fancy);
70 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 68 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
71 "Finished download, shutting down\n", 69 "Finished download, shutting down\n",
72 (unsigned long long) FILESIZE); 70 (unsigned long long) FILESIZE);
73 } 71 }
74 else 72 else
75 { 73 {
76 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 74 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
77 "Timeout during download, shutting down with error\n"); 75 "Timeout during download, shutting down with error\n");
78 ok = 1; 76 ok = 1;
79 } 77 }
80} 78}
81 79
82 80
83static void 81static void
84do_download (void *cls, 82do_download (void *cls, const struct GNUNET_FS_Uri *uri)
85 const struct GNUNET_FS_Uri *uri)
86{ 83{
87 if (NULL == uri) 84 if (NULL == uri)
88 { 85 {
89 GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, 86 GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, daemons);
90 daemons); 87 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
91 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 88 "Timeout during upload attempt, shutting down with error\n");
92 "Timeout during upload attempt, shutting down with error\n"); 89 ok = 1;
93 ok = 1; 90 return;
94 return; 91 }
95 }
96 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 92 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
97 "Downloading %llu bytes\n", 93 "Downloading %llu bytes\n", (unsigned long long) FILESIZE);
98 (unsigned long long) FILESIZE);
99 start_time = GNUNET_TIME_absolute_get (); 94 start_time = GNUNET_TIME_absolute_get ();
100 GNUNET_FS_TEST_download (daemons[0], 95 GNUNET_FS_TEST_download (daemons[0],
101 TIMEOUT, 96 TIMEOUT, 1, SEED, uri, VERBOSE, &do_stop, NULL);
102 1, SEED, uri,
103 VERBOSE,
104 &do_stop, NULL);
105} 97}
106 98
107 99
108static void 100static void
109do_publish (void *cls, 101do_publish (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
110 const struct GNUNET_SCHEDULER_TaskContext *tc)
111{ 102{
112 if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE)) 103 if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE))
113 { 104 {
114 GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, 105 GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, daemons);
115 daemons); 106 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
116 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 107 "Timeout during connect attempt, shutting down with error\n");
117 "Timeout during connect attempt, shutting down with error\n"); 108 ok = 1;
118 ok = 1; 109 return;
119 return; 110 }
120 }
121 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 111 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
122 "Publishing %llu bytes\n", 112 "Publishing %llu bytes\n", (unsigned long long) FILESIZE);
123 (unsigned long long) FILESIZE);
124 GNUNET_FS_TEST_publish (daemons[1], 113 GNUNET_FS_TEST_publish (daemons[1],
125 TIMEOUT, 114 TIMEOUT,
126 1, GNUNET_NO, FILESIZE, SEED, 115 1, GNUNET_NO, FILESIZE, SEED,
127 VERBOSE, 116 VERBOSE, &do_download, NULL);
128 &do_download, NULL);
129} 117}
130 118
131 119
132static void 120static void
133do_connect (void *cls, 121do_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
134 const struct GNUNET_SCHEDULER_TaskContext *tc)
135{ 122{
136 GNUNET_assert (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE)); 123 GNUNET_assert (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE));
137 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 124 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
138 "Daemons started, will now try to connect them\n"); 125 "Daemons started, will now try to connect them\n");
139 GNUNET_FS_TEST_daemons_connect (daemons[0], 126 GNUNET_FS_TEST_daemons_connect (daemons[0],
140 daemons[1], 127 daemons[1], TIMEOUT, &do_publish, NULL);
141 TIMEOUT,
142 &do_publish,
143 NULL);
144} 128}
145 129
146 130
147static void 131static void
148run (void *cls, 132run (void *cls,
149 char *const *args, 133 char *const *args,
150 const char *cfgfile, 134 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
151 const struct GNUNET_CONFIGURATION_Handle *cfg)
152{ 135{
153 GNUNET_FS_TEST_daemons_start ("fs_test_lib_data.conf", 136 GNUNET_FS_TEST_daemons_start ("fs_test_lib_data.conf",
154 TIMEOUT, 137 TIMEOUT,
155 NUM_DAEMONS, 138 NUM_DAEMONS, daemons, &do_connect, NULL);
156 daemons,
157 &do_connect,
158 NULL);
159} 139}
160 140
161 141
162int 142int
163main (int argc, char *argv[]) 143main (int argc, char *argv[])
164{ 144{
165 char *const argvx[] = { 145 char *const argvx[] = {
166 "test-gnunet-service-fs-p2p", 146 "test-gnunet-service-fs-p2p",
167 "-c", 147 "-c",
168 "fs_test_lib_data.conf", 148 "fs_test_lib_data.conf",
@@ -176,16 +156,16 @@ main (int argc, char *argv[])
176 }; 156 };
177 157
178 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/"); 158 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/");
179 GNUNET_log_setup ("test_gnunet_service_fs_p2p", 159 GNUNET_log_setup ("test_gnunet_service_fs_p2p",
180#if VERBOSE 160#if VERBOSE
181 "DEBUG", 161 "DEBUG",
182#else 162#else
183 "WARNING", 163 "WARNING",
184#endif 164#endif
185 NULL); 165 NULL);
186 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, 166 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
187 argvx, "test-gnunet-service-fs-p2p", 167 argvx, "test-gnunet-service-fs-p2p",
188 "nohelp", options, &run, NULL); 168 "nohelp", options, &run, NULL);
189 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/"); 169 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/");
190 return ok; 170 return ok;
191} 171}