diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-06-18 14:50:33 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-06-18 14:50:33 +0000 |
commit | 352c6c0da07467c8aef266565df01a2844016a3e (patch) | |
tree | 1326c3d43d7fd4c5c4000ed02621655ce4eb8085 /src/fs/gnunet-auto-share.c | |
parent | 45a1b1ceca389f0db1f88b7cf7dd52587647fd8d (diff) | |
download | gnunet-352c6c0da07467c8aef266565df01a2844016a3e.tar.gz gnunet-352c6c0da07467c8aef266565df01a2844016a3e.zip |
-debugging gnunet-auto-share, now largely works
Diffstat (limited to 'src/fs/gnunet-auto-share.c')
-rw-r--r-- | src/fs/gnunet-auto-share.c | 99 |
1 files changed, 81 insertions, 18 deletions
diff --git a/src/fs/gnunet-auto-share.c b/src/fs/gnunet-auto-share.c index ac38c6d94..0ea0647e9 100644 --- a/src/fs/gnunet-auto-share.c +++ b/src/fs/gnunet-auto-share.c | |||
@@ -29,6 +29,10 @@ | |||
29 | #include "platform.h" | 29 | #include "platform.h" |
30 | #include "gnunet_util_lib.h" | 30 | #include "gnunet_util_lib.h" |
31 | 31 | ||
32 | #define MIN_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 4) | ||
33 | |||
34 | #define MAX_FREQUENCY GNUNET_TIME_UNIT_MINUTES | ||
35 | |||
32 | 36 | ||
33 | /** | 37 | /** |
34 | * Item in our work queue (or in the set of files/directories | 38 | * Item in our work queue (or in the set of files/directories |
@@ -207,6 +211,10 @@ load_state () | |||
207 | wi = GNUNET_malloc (sizeof (struct WorkItem)); | 211 | wi = GNUNET_malloc (sizeof (struct WorkItem)); |
208 | wi->id = id; | 212 | wi->id = id; |
209 | wi->filename = fn; | 213 | wi->filename = fn; |
214 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
215 | "Loaded serialization ID for `%s' is `%s'\n", | ||
216 | wi->filename, | ||
217 | GNUNET_h2s (&id)); | ||
210 | fn = NULL; | 218 | fn = NULL; |
211 | GNUNET_CRYPTO_hash (wi->filename, | 219 | GNUNET_CRYPTO_hash (wi->filename, |
212 | strlen (wi->filename), | 220 | strlen (wi->filename), |
@@ -247,6 +255,10 @@ write_item (void *cls, | |||
247 | struct GNUNET_BIO_WriteHandle *wh = cls; | 255 | struct GNUNET_BIO_WriteHandle *wh = cls; |
248 | struct WorkItem *wi = value; | 256 | struct WorkItem *wi = value; |
249 | 257 | ||
258 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
259 | "Saving serialization ID of file `%s' with value `%s'\n", | ||
260 | wi->filename, | ||
261 | GNUNET_h2s (&wi->id)); | ||
250 | if ( (GNUNET_OK != | 262 | if ( (GNUNET_OK != |
251 | GNUNET_BIO_write_string (wh, wi->filename)) || | 263 | GNUNET_BIO_write_string (wh, wi->filename)) || |
252 | (GNUNET_OK != | 264 | (GNUNET_OK != |
@@ -335,19 +347,65 @@ maint_child_death (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
335 | { | 347 | { |
336 | struct WorkItem *wi = cls; | 348 | struct WorkItem *wi = cls; |
337 | struct GNUNET_HashCode key; | 349 | struct GNUNET_HashCode key; |
350 | enum GNUNET_OS_ProcessStatusType type; | ||
351 | unsigned long code; | ||
352 | int ret; | ||
353 | char c; | ||
354 | const struct GNUNET_DISK_FileHandle *pr; | ||
355 | |||
338 | 356 | ||
339 | run_task = GNUNET_SCHEDULER_NO_TASK; | 357 | run_task = GNUNET_SCHEDULER_NO_TASK; |
340 | GNUNET_break (GNUNET_OK == | 358 | pr = GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ); |
341 | GNUNET_OS_process_wait (publish_proc)); | 359 | if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY)) |
360 | { | ||
361 | /* shutdown scheduled us, ignore! */ | ||
362 | run_task = | ||
363 | GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, | ||
364 | pr, &maint_child_death, wi); | ||
365 | return; | ||
366 | } | ||
367 | |||
368 | ret = GNUNET_OS_process_status (publish_proc, | ||
369 | &type, | ||
370 | &code); | ||
371 | GNUNET_assert (GNUNET_SYSERR != ret); | ||
372 | if (GNUNET_NO == ret) | ||
373 | { | ||
374 | GNUNET_break (0); | ||
375 | GNUNET_OS_process_kill (publish_proc, SIGKILL); | ||
376 | type = GNUNET_OS_PROCESS_SIGNALED; | ||
377 | } | ||
342 | GNUNET_OS_process_destroy (publish_proc); | 378 | GNUNET_OS_process_destroy (publish_proc); |
343 | publish_proc = NULL; | 379 | publish_proc = NULL; |
344 | GNUNET_CRYPTO_hash (wi->filename, | 380 | /* consume the signal */ |
345 | strlen (wi->filename), | 381 | GNUNET_break (0 < GNUNET_DISK_file_read (pr, &c, sizeof (c))); |
346 | &key); | 382 | |
347 | GNUNET_CONTAINER_multihashmap_put (work_finished, | 383 | if (GNUNET_YES == do_shutdown) |
348 | &key, | 384 | { |
349 | wi, | 385 | GNUNET_free (wi->filename); |
350 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | 386 | GNUNET_free (wi); |
387 | return; | ||
388 | } | ||
389 | if ( (GNUNET_OS_PROCESS_EXITED == type) && | ||
390 | (0 == code) ) | ||
391 | { | ||
392 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
393 | _("Publication of `%s' done\n"), | ||
394 | wi->filename); | ||
395 | GNUNET_CRYPTO_hash (wi->filename, | ||
396 | strlen (wi->filename), | ||
397 | &key); | ||
398 | GNUNET_CONTAINER_multihashmap_put (work_finished, | ||
399 | &key, | ||
400 | wi, | ||
401 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | ||
402 | } | ||
403 | else | ||
404 | { | ||
405 | GNUNET_CONTAINER_DLL_insert_tail (work_head, | ||
406 | work_tail, | ||
407 | wi); | ||
408 | } | ||
351 | save_state (); | 409 | save_state (); |
352 | schedule_next_task (); | 410 | schedule_next_task (); |
353 | } | 411 | } |
@@ -418,6 +476,9 @@ work (void *cls, | |||
418 | argv[argc++] = repl_level; | 476 | argv[argc++] = repl_level; |
419 | argv[argc++] = wi->filename; | 477 | argv[argc++] = wi->filename; |
420 | argv[argc] = NULL; | 478 | argv[argc] = NULL; |
479 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
480 | _("Publishing `%s'\n"), | ||
481 | wi->filename); | ||
421 | publish_proc = GNUNET_OS_start_process_vap (GNUNET_YES, | 482 | publish_proc = GNUNET_OS_start_process_vap (GNUNET_YES, |
422 | NULL, NULL, | 483 | NULL, NULL, |
423 | "gnunet-publish", | 484 | "gnunet-publish", |
@@ -459,9 +520,6 @@ determine_id (void *cls, | |||
459 | struct GNUNET_HashCode fx[2]; | 520 | struct GNUNET_HashCode fx[2]; |
460 | struct GNUNET_HashCode ft; | 521 | struct GNUNET_HashCode ft; |
461 | 522 | ||
462 | if (NULL != strstr (filename, | ||
463 | DIR_SEPARATOR_STR ".auto-share")) | ||
464 | return GNUNET_OK; /* skip internal file */ | ||
465 | if (0 != STAT (filename, &sbuf)) | 523 | if (0 != STAT (filename, &sbuf)) |
466 | { | 524 | { |
467 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "stat", filename); | 525 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "stat", filename); |
@@ -470,9 +528,12 @@ determine_id (void *cls, | |||
470 | GNUNET_CRYPTO_hash (filename, strlen (filename), &fx[0]); | 528 | GNUNET_CRYPTO_hash (filename, strlen (filename), &fx[0]); |
471 | if (!S_ISDIR (sbuf.st_mode)) | 529 | if (!S_ISDIR (sbuf.st_mode)) |
472 | { | 530 | { |
473 | uint64_t fsize = GNUNET_htonll (sbuf.st_size); | 531 | uint64_t fattr[2]; |
474 | 532 | ||
475 | GNUNET_CRYPTO_hash (&fsize, sizeof (uint64_t), &fx[1]); | 533 | fattr[0] = GNUNET_htonll (sbuf.st_size); |
534 | fattr[0] = GNUNET_htonll (sbuf.st_mtime); | ||
535 | |||
536 | GNUNET_CRYPTO_hash (fattr, sizeof (fattr), &fx[1]); | ||
476 | } | 537 | } |
477 | else | 538 | else |
478 | { | 539 | { |
@@ -510,6 +571,9 @@ add_file (void *cls, | |||
510 | 571 | ||
511 | if (GNUNET_YES == do_shutdown) | 572 | if (GNUNET_YES == do_shutdown) |
512 | return GNUNET_SYSERR; | 573 | return GNUNET_SYSERR; |
574 | if (NULL != strstr (filename, | ||
575 | DIR_SEPARATOR_STR ".auto-share")) | ||
576 | return GNUNET_OK; /* skip internal file */ | ||
513 | GNUNET_CRYPTO_hash (filename, | 577 | GNUNET_CRYPTO_hash (filename, |
514 | strlen (filename), | 578 | strlen (filename), |
515 | &key); | 579 | &key); |
@@ -527,13 +591,13 @@ add_file (void *cls, | |||
527 | GNUNET_CONTAINER_multihashmap_remove (work_finished, | 591 | GNUNET_CONTAINER_multihashmap_remove (work_finished, |
528 | &key, | 592 | &key, |
529 | wi); | 593 | wi); |
530 | wi->id = id; | ||
531 | } | 594 | } |
532 | else | 595 | else |
533 | { | 596 | { |
534 | wi = GNUNET_malloc (sizeof (struct WorkItem)); | 597 | wi = GNUNET_malloc (sizeof (struct WorkItem)); |
535 | wi->filename = GNUNET_strdup (filename); | 598 | wi->filename = GNUNET_strdup (filename); |
536 | } | 599 | } |
600 | wi->id = id; | ||
537 | GNUNET_CONTAINER_DLL_insert (work_head, | 601 | GNUNET_CONTAINER_DLL_insert (work_head, |
538 | work_tail, | 602 | work_tail, |
539 | wi); | 603 | wi); |
@@ -576,12 +640,11 @@ schedule_next_task () | |||
576 | /* delay by at most 4h, at least 1s, and otherwise in between depending | 640 | /* delay by at most 4h, at least 1s, and otherwise in between depending |
577 | on how long it took to scan */ | 641 | on how long it took to scan */ |
578 | delay = GNUNET_TIME_absolute_get_duration (start_time); | 642 | delay = GNUNET_TIME_absolute_get_duration (start_time); |
579 | delay = GNUNET_TIME_relative_min (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, | 643 | delay = GNUNET_TIME_relative_min (MIN_FREQUENCY, |
580 | 4), | ||
581 | GNUNET_TIME_relative_multiply (delay, | 644 | GNUNET_TIME_relative_multiply (delay, |
582 | 100)); | 645 | 100)); |
583 | delay = GNUNET_TIME_relative_max (delay, | 646 | delay = GNUNET_TIME_relative_max (delay, |
584 | GNUNET_TIME_UNIT_MINUTES); | 647 | MAX_FREQUENCY); |
585 | run_task = GNUNET_SCHEDULER_add_delayed (delay, | 648 | run_task = GNUNET_SCHEDULER_add_delayed (delay, |
586 | &scan, | 649 | &scan, |
587 | NULL); | 650 | NULL); |