aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSchanzenbach, Martin <mschanzenbach@posteo.de>2019-07-21 21:44:06 +0200
committerSchanzenbach, Martin <mschanzenbach@posteo.de>2019-07-21 21:44:06 +0200
commit1a90ef262d8e60630d5b79135c2eefe78b1341d4 (patch)
treeee6bfd1aaae4554cae04730d389f0ef15c2648c8 /src
parentc21abffdd159b116bd957753ccbd0c8bc0cdebfe (diff)
downloadgnunet-1a90ef262d8e60630d5b79135c2eefe78b1341d4.tar.gz
gnunet-1a90ef262d8e60630d5b79135c2eefe78b1341d4.zip
formatting
Diffstat (limited to 'src')
-rw-r--r--src/fs/gnunet-auto-share.c395
1 files changed, 169 insertions, 226 deletions
diff --git a/src/fs/gnunet-auto-share.c b/src/fs/gnunet-auto-share.c
index bb14ac7e8..ba28c5c23 100644
--- a/src/fs/gnunet-auto-share.c
+++ b/src/fs/gnunet-auto-share.c
@@ -11,7 +11,7 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
@@ -167,9 +167,11 @@ get_state_file ()
167 char *ret; 167 char *ret;
168 168
169 GNUNET_asprintf (&ret, 169 GNUNET_asprintf (&ret,
170 "%s%s.auto-share", 170 "%s%s.auto-share",
171 dir_name, 171 dir_name,
172 (DIR_SEPARATOR == dir_name[strlen(dir_name)-1]) ? "" : DIR_SEPARATOR_STR); 172 (DIR_SEPARATOR == dir_name[strlen (dir_name) - 1])
173 ? ""
174 : DIR_SEPARATOR_STR);
173 return ret; 175 return ret;
174} 176}
175 177
@@ -198,39 +200,36 @@ load_state ()
198 goto error; 200 goto error;
199 while (n-- > 0) 201 while (n-- > 0)
200 { 202 {
201 if ( (GNUNET_OK != 203 if ((GNUNET_OK != GNUNET_BIO_read_string (rh, "filename", &fn, 1024)) ||
202 GNUNET_BIO_read_string (rh, "filename", &fn, 1024)) || 204 (GNUNET_OK !=
203 (GNUNET_OK != 205 GNUNET_BIO_read (rh, "id", &id, sizeof (struct GNUNET_HashCode))))
204 GNUNET_BIO_read (rh, "id", &id, sizeof (struct GNUNET_HashCode))) )
205 goto error; 206 goto error;
206 wi = GNUNET_new (struct WorkItem); 207 wi = GNUNET_new (struct WorkItem);
207 wi->id = id; 208 wi->id = id;
208 wi->filename = fn; 209 wi->filename = fn;
209 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 210 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
210 "Loaded serialization ID for `%s' is `%s'\n", 211 "Loaded serialization ID for `%s' is `%s'\n",
211 wi->filename, 212 wi->filename,
212 GNUNET_h2s (&id)); 213 GNUNET_h2s (&id));
213 fn = NULL; 214 fn = NULL;
214 GNUNET_CRYPTO_hash (wi->filename, 215 GNUNET_CRYPTO_hash (wi->filename, strlen (wi->filename), &id);
215 strlen (wi->filename),
216 &id);
217 GNUNET_break (GNUNET_OK == 216 GNUNET_break (GNUNET_OK ==
218 GNUNET_CONTAINER_multihashmap_put (work_finished, 217 GNUNET_CONTAINER_multihashmap_put (
219 &id, 218 work_finished,
220 wi, 219 &id,
221 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 220 wi,
221 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
222 } 222 }
223 if (GNUNET_OK == 223 if (GNUNET_OK == GNUNET_BIO_read_close (rh, &emsg))
224 GNUNET_BIO_read_close (rh, &emsg))
225 return; 224 return;
226 rh = NULL; 225 rh = NULL;
227 error: 226error:
228 GNUNET_free_non_null (fn); 227 GNUNET_free_non_null (fn);
229 if (NULL != rh) 228 if (NULL != rh)
230 (void) GNUNET_BIO_read_close (rh, &emsg); 229 (void) GNUNET_BIO_read_close (rh, &emsg);
231 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 230 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
232 _("Failed to load state: %s\n"), 231 _ ("Failed to load state: %s\n"),
233 emsg); 232 emsg);
234 GNUNET_free_non_null (emsg); 233 GNUNET_free_non_null (emsg);
235} 234}
236 235
@@ -244,23 +243,18 @@ load_state ()
244 * @return #GNUNET_OK to continue to iterate (if write worked) 243 * @return #GNUNET_OK to continue to iterate (if write worked)
245 */ 244 */
246static int 245static int
247write_item (void *cls, 246write_item (void *cls, const struct GNUNET_HashCode *key, void *value)
248 const struct GNUNET_HashCode *key,
249 void *value)
250{ 247{
251 struct GNUNET_BIO_WriteHandle *wh = cls; 248 struct GNUNET_BIO_WriteHandle *wh = cls;
252 struct WorkItem *wi = value; 249 struct WorkItem *wi = value;
253 250
254 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 251 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
255 "Saving serialization ID of file `%s' with value `%s'\n", 252 "Saving serialization ID of file `%s' with value `%s'\n",
256 wi->filename, 253 wi->filename,
257 GNUNET_h2s (&wi->id)); 254 GNUNET_h2s (&wi->id));
258 if ( (GNUNET_OK != 255 if ((GNUNET_OK != GNUNET_BIO_write_string (wh, wi->filename)) ||
259 GNUNET_BIO_write_string (wh, wi->filename)) || 256 (GNUNET_OK !=
260 (GNUNET_OK != 257 GNUNET_BIO_write (wh, &wi->id, sizeof (struct GNUNET_HashCode))))
261 GNUNET_BIO_write (wh,
262 &wi->id,
263 sizeof (struct GNUNET_HashCode))) )
264 return GNUNET_SYSERR; /* write error, abort iteration */ 258 return GNUNET_SYSERR; /* write error, abort iteration */
265 return GNUNET_OK; 259 return GNUNET_OK;
266} 260}
@@ -282,28 +276,25 @@ save_state ()
282 if (NULL == wh) 276 if (NULL == wh)
283 { 277 {
284 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 278 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
285 _("Failed to save state to file %s\n"), 279 _ ("Failed to save state to file %s\n"),
286 fn); 280 fn);
287 GNUNET_free (fn); 281 GNUNET_free (fn);
288 return; 282 return;
289 } 283 }
290 if (GNUNET_OK != 284 if (GNUNET_OK != GNUNET_BIO_write_int32 (wh, n))
291 GNUNET_BIO_write_int32 (wh, n))
292 { 285 {
293 (void) GNUNET_BIO_write_close (wh); 286 (void) GNUNET_BIO_write_close (wh);
294 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 287 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
295 _("Failed to save state to file %s\n"), 288 _ ("Failed to save state to file %s\n"),
296 fn); 289 fn);
297 GNUNET_free (fn); 290 GNUNET_free (fn);
298 return; 291 return;
299 } 292 }
300 (void) GNUNET_CONTAINER_multihashmap_iterate (work_finished, 293 (void) GNUNET_CONTAINER_multihashmap_iterate (work_finished, &write_item, wh);
301 &write_item,
302 wh);
303 if (GNUNET_OK != GNUNET_BIO_write_close (wh)) 294 if (GNUNET_OK != GNUNET_BIO_write_close (wh))
304 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 295 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
305 _("Failed to save state to file %s\n"), 296 _ ("Failed to save state to file %s\n"),
306 fn); 297 fn);
307 GNUNET_free (fn); 298 GNUNET_free (fn);
308} 299}
309 300
@@ -319,8 +310,7 @@ do_stop_task (void *cls)
319 do_shutdown = GNUNET_YES; 310 do_shutdown = GNUNET_YES;
320 if (NULL != publish_proc) 311 if (NULL != publish_proc)
321 { 312 {
322 GNUNET_OS_process_kill (publish_proc, 313 GNUNET_OS_process_kill (publish_proc, SIGKILL);
323 SIGKILL);
324 return; 314 return;
325 } 315 }
326 if (NULL != run_task) 316 if (NULL != run_task)
@@ -357,25 +347,22 @@ maint_child_death (void *cls)
357 const struct GNUNET_SCHEDULER_TaskContext *tc; 347 const struct GNUNET_SCHEDULER_TaskContext *tc;
358 348
359 run_task = NULL; 349 run_task = NULL;
360 pr = GNUNET_DISK_pipe_handle (sigpipe, 350 pr = GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ);
361 GNUNET_DISK_PIPE_END_READ);
362 tc = GNUNET_SCHEDULER_get_task_context (); 351 tc = GNUNET_SCHEDULER_get_task_context ();
363 if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY)) 352 if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY))
364 { 353 {
365 /* shutdown scheduled us, someone else will kill child, 354 /* shutdown scheduled us, someone else will kill child,
366 we should just try again */ 355 we should just try again */
367 run_task = 356 run_task = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
368 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, 357 pr,
369 pr, 358 &maint_child_death,
370 &maint_child_death, wi); 359 wi);
371 return; 360 return;
372 } 361 }
373 /* consume the signal */ 362 /* consume the signal */
374 GNUNET_break (0 < GNUNET_DISK_file_read (pr, &c, sizeof (c))); 363 GNUNET_break (0 < GNUNET_DISK_file_read (pr, &c, sizeof (c)));
375 364
376 ret = GNUNET_OS_process_status (publish_proc, 365 ret = GNUNET_OS_process_status (publish_proc, &type, &code);
377 &type,
378 &code);
379 GNUNET_assert (GNUNET_SYSERR != ret); 366 GNUNET_assert (GNUNET_SYSERR != ret);
380 if (GNUNET_NO == ret) 367 if (GNUNET_NO == ret)
381 { 368 {
@@ -383,10 +370,10 @@ maint_child_death (void *cls)
383 Well, let's declare it spurious (kernel bug?) and keep rolling. 370 Well, let's declare it spurious (kernel bug?) and keep rolling.
384 */ 371 */
385 GNUNET_break (0); 372 GNUNET_break (0);
386 run_task = 373 run_task = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
387 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, 374 pr,
388 pr, 375 &maint_child_death,
389 &maint_child_death, wi); 376 wi);
390 return; 377 return;
391 } 378 }
392 GNUNET_assert (GNUNET_OK == ret); 379 GNUNET_assert (GNUNET_OK == ret);
@@ -400,26 +387,22 @@ maint_child_death (void *cls)
400 GNUNET_free (wi); 387 GNUNET_free (wi);
401 return; 388 return;
402 } 389 }
403 if ( (GNUNET_OS_PROCESS_EXITED == type) && 390 if ((GNUNET_OS_PROCESS_EXITED == type) && (0 == code))
404 (0 == code) )
405 { 391 {
406 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 392 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
407 _("Publication of `%s' done\n"), 393 _ ("Publication of `%s' done\n"),
408 wi->filename); 394 wi->filename);
409 GNUNET_CRYPTO_hash (wi->filename, 395 GNUNET_CRYPTO_hash (wi->filename, strlen (wi->filename), &key);
410 strlen (wi->filename),
411 &key);
412 GNUNET_break (GNUNET_OK == 396 GNUNET_break (GNUNET_OK ==
413 GNUNET_CONTAINER_multihashmap_put (work_finished, 397 GNUNET_CONTAINER_multihashmap_put (
414 &key, 398 work_finished,
415 wi, 399 &key,
416 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 400 wi,
401 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
417 } 402 }
418 else 403 else
419 { 404 {
420 GNUNET_CONTAINER_DLL_insert_tail (work_head, 405 GNUNET_CONTAINER_DLL_insert_tail (work_head, work_tail, wi);
421 work_tail,
422 wi);
423 } 406 }
424 save_state (); 407 save_state ();
425 schedule_next_task (); 408 schedule_next_task ();
@@ -434,14 +417,15 @@ static void
434sighandler_child_death () 417sighandler_child_death ()
435{ 418{
436 static char c; 419 static char c;
437 int old_errno = errno; /* back-up errno */ 420 int old_errno = errno; /* back-up errno */
438 421
439 GNUNET_break (1 == 422 GNUNET_break (
440 GNUNET_DISK_file_write (GNUNET_DISK_pipe_handle 423 1 ==
441 (sigpipe, 424 GNUNET_DISK_file_write (GNUNET_DISK_pipe_handle (sigpipe,
442 GNUNET_DISK_PIPE_END_WRITE), 425 GNUNET_DISK_PIPE_END_WRITE),
443 &c, sizeof (c))); 426 &c,
444 errno = old_errno; /* restore errno */ 427 sizeof (c)));
428 errno = old_errno; /* restore errno */
445} 429}
446 430
447 431
@@ -463,9 +447,7 @@ work (void *cls)
463 447
464 run_task = NULL; 448 run_task = NULL;
465 wi = work_head; 449 wi = work_head;
466 GNUNET_CONTAINER_DLL_remove (work_head, 450 GNUNET_CONTAINER_DLL_remove (work_head, work_tail, wi);
467 work_tail,
468 wi);
469 argc = 0; 451 argc = 0;
470 argv[argc++] = "gnunet-publish"; 452 argv[argc++] = "gnunet-publish";
471 if (verbose) 453 if (verbose)
@@ -476,47 +458,41 @@ work (void *cls)
476 argv[argc++] = "-d"; 458 argv[argc++] = "-d";
477 argv[argc++] = "-c"; 459 argv[argc++] = "-c";
478 argv[argc++] = cfg_filename; 460 argv[argc++] = cfg_filename;
479 GNUNET_snprintf (anon_level, sizeof (anon_level), 461 GNUNET_snprintf (anon_level, sizeof (anon_level), "%u", anonymity_level);
480 "%u", anonymity_level);
481 argv[argc++] = "-a"; 462 argv[argc++] = "-a";
482 argv[argc++] = anon_level; 463 argv[argc++] = anon_level;
483 GNUNET_snprintf (content_prio, sizeof (content_prio), 464 GNUNET_snprintf (content_prio, sizeof (content_prio), "%u", content_priority);
484 "%u", content_priority);
485 argv[argc++] = "-p"; 465 argv[argc++] = "-p";
486 argv[argc++] = content_prio; 466 argv[argc++] = content_prio;
487 GNUNET_snprintf (repl_level, sizeof (repl_level), 467 GNUNET_snprintf (repl_level, sizeof (repl_level), "%u", replication_level);
488 "%u", replication_level);
489 argv[argc++] = "-r"; 468 argv[argc++] = "-r";
490 argv[argc++] = repl_level; 469 argv[argc++] = repl_level;
491 argv[argc++] = wi->filename; 470 argv[argc++] = wi->filename;
492 argv[argc] = NULL; 471 argv[argc] = NULL;
493 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 472 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ ("Publishing `%s'\n"), wi->filename);
494 _("Publishing `%s'\n"),
495 wi->filename);
496 GNUNET_assert (NULL == publish_proc); 473 GNUNET_assert (NULL == publish_proc);
497 publish_proc = GNUNET_OS_start_process_vap (GNUNET_YES, 474 publish_proc = GNUNET_OS_start_process_vap (GNUNET_YES,
498 0, NULL, NULL, NULL, 475 0,
499 "gnunet-publish", 476 NULL,
500 argv); 477 NULL,
478 NULL,
479 "gnunet-publish",
480 argv);
501 if (NULL == publish_proc) 481 if (NULL == publish_proc)
502 { 482 {
503 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 483 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
504 _("Failed to run `%s'\n"), 484 _ ("Failed to run `%s'\n"),
505 "gnunet-publish"); 485 "gnunet-publish");
506 GNUNET_CONTAINER_DLL_insert (work_head, 486 GNUNET_CONTAINER_DLL_insert (work_head, work_tail, wi);
507 work_tail, 487 run_task =
508 wi); 488 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, &work, NULL);
509 run_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
510 &work,
511 NULL);
512 return; 489 return;
513 } 490 }
514 pr = GNUNET_DISK_pipe_handle (sigpipe, 491 pr = GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ);
515 GNUNET_DISK_PIPE_END_READ); 492 run_task = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
516 run_task = 493 pr,
517 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, 494 &maint_child_death,
518 pr, 495 wi);
519 &maint_child_death, wi);
520} 496}
521 497
522 498
@@ -529,8 +505,7 @@ work (void *cls)
529 * @return #GNUNET_OK (always) 505 * @return #GNUNET_OK (always)
530 */ 506 */
531static int 507static int
532determine_id (void *cls, 508determine_id (void *cls, const char *filename)
533 const char *filename)
534{ 509{
535 struct GNUNET_HashCode *id = cls; 510 struct GNUNET_HashCode *id = cls;
536 struct stat sbuf; 511 struct stat sbuf;
@@ -539,44 +514,30 @@ determine_id (void *cls,
539 514
540 if (0 != STAT (filename, &sbuf)) 515 if (0 != STAT (filename, &sbuf))
541 { 516 {
542 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, 517 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "stat", filename);
543 "stat",
544 filename);
545 return GNUNET_OK; 518 return GNUNET_OK;
546 } 519 }
547 GNUNET_CRYPTO_hash (filename, 520 GNUNET_CRYPTO_hash (filename, strlen (filename), &fx[0]);
548 strlen (filename), 521 if (! S_ISDIR (sbuf.st_mode))
549 &fx[0]);
550 if (!S_ISDIR (sbuf.st_mode))
551 { 522 {
552 uint64_t fattr[2]; 523 uint64_t fattr[2];
553 524
554 fattr[0] = GNUNET_htonll (sbuf.st_size); 525 fattr[0] = GNUNET_htonll (sbuf.st_size);
555 fattr[0] = GNUNET_htonll (sbuf.st_mtime); 526 fattr[0] = GNUNET_htonll (sbuf.st_mtime);
556 527
557 GNUNET_CRYPTO_hash (fattr, 528 GNUNET_CRYPTO_hash (fattr, sizeof (fattr), &fx[1]);
558 sizeof (fattr),
559 &fx[1]);
560 } 529 }
561 else 530 else
562 { 531 {
563 memset (&fx[1], 532 memset (&fx[1], 1, sizeof (struct GNUNET_HashCode));
564 1, 533 GNUNET_DISK_directory_scan (filename, &determine_id, &fx[1]);
565 sizeof (struct GNUNET_HashCode));
566 GNUNET_DISK_directory_scan (filename,
567 &determine_id,
568 &fx[1]);
569 } 534 }
570 /* use hash here to make hierarchical structure distinct from 535 /* use hash here to make hierarchical structure distinct from
571 all files on the same level */ 536 all files on the same level */
572 GNUNET_CRYPTO_hash (fx, 537 GNUNET_CRYPTO_hash (fx, sizeof (fx), &ft);
573 sizeof (fx),
574 &ft);
575 /* use XOR here so that order of the files in the directory 538 /* use XOR here so that order of the files in the directory
576 does not matter! */ 539 does not matter! */
577 GNUNET_CRYPTO_hash_xor (&ft, 540 GNUNET_CRYPTO_hash_xor (&ft, id, id);
578 id,
579 id);
580 return GNUNET_OK; 541 return GNUNET_OK;
581} 542}
582 543
@@ -591,8 +552,7 @@ determine_id (void *cls,
591 * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR during shutdown 552 * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR during shutdown
592 */ 553 */
593static int 554static int
594add_file (void *cls, 555add_file (void *cls, const char *filename)
595 const char *filename)
596{ 556{
597 struct WorkItem *wi; 557 struct WorkItem *wi;
598 struct GNUNET_HashCode key; 558 struct GNUNET_HashCode key;
@@ -600,29 +560,21 @@ add_file (void *cls,
600 560
601 if (GNUNET_YES == do_shutdown) 561 if (GNUNET_YES == do_shutdown)
602 return GNUNET_SYSERR; 562 return GNUNET_SYSERR;
603 if ( (NULL != strstr (filename, 563 if ((NULL != strstr (filename, "/.auto-share")) ||
604 "/.auto-share")) || 564 (NULL != strstr (filename, "\\.auto-share")))
605 (NULL != strstr (filename,
606 "\\.auto-share")) )
607 return GNUNET_OK; /* skip internal file */ 565 return GNUNET_OK; /* skip internal file */
608 GNUNET_CRYPTO_hash (filename, 566 GNUNET_CRYPTO_hash (filename, strlen (filename), &key);
609 strlen (filename), 567 wi = GNUNET_CONTAINER_multihashmap_get (work_finished, &key);
610 &key);
611 wi = GNUNET_CONTAINER_multihashmap_get (work_finished,
612 &key);
613 memset (&id, 0, sizeof (struct GNUNET_HashCode)); 568 memset (&id, 0, sizeof (struct GNUNET_HashCode));
614 determine_id (&id, filename); 569 determine_id (&id, filename);
615 if (NULL != wi) 570 if (NULL != wi)
616 { 571 {
617 if (0 == memcmp (&id, 572 if (0 == memcmp (&id, &wi->id, sizeof (struct GNUNET_HashCode)))
618 &wi->id,
619 sizeof (struct GNUNET_HashCode)))
620 return GNUNET_OK; /* skip: we did this one already */ 573 return GNUNET_OK; /* skip: we did this one already */
621 /* contents changed, need to re-do the directory... */ 574 /* contents changed, need to re-do the directory... */
622 GNUNET_assert (GNUNET_YES == 575 GNUNET_assert (
623 GNUNET_CONTAINER_multihashmap_remove (work_finished, 576 GNUNET_YES ==
624 &key, 577 GNUNET_CONTAINER_multihashmap_remove (work_finished, &key, wi));
625 wi));
626 } 578 }
627 else 579 else
628 { 580 {
@@ -630,9 +582,7 @@ add_file (void *cls,
630 wi->filename = GNUNET_strdup (filename); 582 wi->filename = GNUNET_strdup (filename);
631 } 583 }
632 wi->id = id; 584 wi->id = id;
633 GNUNET_CONTAINER_DLL_insert (work_head, 585 GNUNET_CONTAINER_DLL_insert (work_head, work_tail, wi);
634 work_tail,
635 wi);
636 if (GNUNET_YES == do_shutdown) 586 if (GNUNET_YES == do_shutdown)
637 return GNUNET_SYSERR; 587 return GNUNET_SYSERR;
638 return GNUNET_OK; 588 return GNUNET_OK;
@@ -649,9 +599,7 @@ scan (void *cls)
649{ 599{
650 run_task = NULL; 600 run_task = NULL;
651 start_time = GNUNET_TIME_absolute_get (); 601 start_time = GNUNET_TIME_absolute_get ();
652 (void) GNUNET_DISK_directory_scan (dir_name, 602 (void) GNUNET_DISK_directory_scan (dir_name, &add_file, NULL);
653 &add_file,
654 NULL);
655 schedule_next_task (); 603 schedule_next_task ();
656} 604}
657 605
@@ -673,18 +621,13 @@ schedule_next_task ()
673 on how long it took to scan */ 621 on how long it took to scan */
674 delay = GNUNET_TIME_absolute_get_duration (start_time); 622 delay = GNUNET_TIME_absolute_get_duration (start_time);
675 delay = GNUNET_TIME_relative_saturating_multiply (delay, 100); 623 delay = GNUNET_TIME_relative_saturating_multiply (delay, 100);
676 delay = GNUNET_TIME_relative_min (delay, 624 delay = GNUNET_TIME_relative_min (delay, MAX_DELAY);
677 MAX_DELAY); 625 delay = GNUNET_TIME_relative_max (delay, MIN_DELAY);
678 delay = GNUNET_TIME_relative_max (delay, 626 run_task = GNUNET_SCHEDULER_add_delayed (delay, &scan, NULL);
679 MIN_DELAY);
680 run_task = GNUNET_SCHEDULER_add_delayed (delay,
681 &scan,
682 NULL);
683 } 627 }
684 else 628 else
685 { 629 {
686 run_task = GNUNET_SCHEDULER_add_now (&work, 630 run_task = GNUNET_SCHEDULER_add_now (&work, NULL);
687 NULL);
688 } 631 }
689} 632}
690 633
@@ -704,27 +647,23 @@ run (void *cls,
704 const struct GNUNET_CONFIGURATION_Handle *c) 647 const struct GNUNET_CONFIGURATION_Handle *c)
705{ 648{
706 /* check arguments */ 649 /* check arguments */
707 if ( (NULL == args[0]) || 650 if ((NULL == args[0]) || (NULL != args[1]) ||
708 (NULL != args[1]) || 651 (GNUNET_YES != GNUNET_DISK_directory_test (args[0], GNUNET_YES)))
709 (GNUNET_YES !=
710 GNUNET_DISK_directory_test (args[0],
711 GNUNET_YES)) )
712 { 652 {
713 printf (_("You must specify one and only one directory name for automatic publication.\n")); 653 printf (_ (
654 "You must specify one and only one directory name for automatic publication.\n"));
714 ret = -1; 655 ret = -1;
715 return; 656 return;
716 } 657 }
717 cfg_filename = GNUNET_strdup (cfgfile); 658 cfg_filename = GNUNET_strdup (cfgfile);
718 cfg = c; 659 cfg = c;
719 dir_name = args[0]; 660 dir_name = args[0];
720 work_finished = GNUNET_CONTAINER_multihashmap_create (1024, 661 work_finished = GNUNET_CONTAINER_multihashmap_create (1024, GNUNET_NO);
721 GNUNET_NO);
722 load_state (); 662 load_state ();
723 run_task = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, 663 run_task = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
724 &scan, 664 &scan,
725 NULL); 665 NULL);
726 GNUNET_SCHEDULER_add_shutdown (&do_stop_task, 666 GNUNET_SCHEDULER_add_shutdown (&do_stop_task, NULL);
727 NULL);
728} 667}
729 668
730 669
@@ -737,9 +676,7 @@ run (void *cls,
737 * @return #GNUNET_OK to continue to iterate 676 * @return #GNUNET_OK to continue to iterate
738 */ 677 */
739static int 678static int
740free_item (void *cls, 679free_item (void *cls, const struct GNUNET_HashCode *key, void *value)
741 const struct GNUNET_HashCode *key,
742 void *value)
743{ 680{
744 struct WorkItem *wi = value; 681 struct WorkItem *wi = value;
745 682
@@ -762,68 +699,74 @@ main (int argc, char *const *argv)
762 struct GNUNET_GETOPT_CommandLineOption options[] = { 699 struct GNUNET_GETOPT_CommandLineOption options[] = {
763 700
764 GNUNET_GETOPT_option_uint ('a', 701 GNUNET_GETOPT_option_uint ('a',
765 "anonymity", 702 "anonymity",
766 "LEVEL", 703 "LEVEL",
767 gettext_noop ("set the desired LEVEL of sender-anonymity"), 704 gettext_noop (
768 &anonymity_level), 705 "set the desired LEVEL of sender-anonymity"),
769 706 &anonymity_level),
770 GNUNET_GETOPT_option_flag ('d', 707
771 "disable-creation-time", 708 GNUNET_GETOPT_option_flag (
772 gettext_noop ("disable adding the creation time to the metadata of the uploaded file"), 709 'd',
773 &do_disable_creation_time), 710 "disable-creation-time",
774 711 gettext_noop (
775 GNUNET_GETOPT_option_flag ('D', 712 "disable adding the creation time to the metadata of the uploaded file"),
776 "disable-extractor", 713 &do_disable_creation_time),
777 gettext_noop ("do not use libextractor to add keywords or metadata"), 714
778 &disable_extractor), 715 GNUNET_GETOPT_option_flag (
716 'D',
717 "disable-extractor",
718 gettext_noop ("do not use libextractor to add keywords or metadata"),
719 &disable_extractor),
779 720
780 GNUNET_GETOPT_option_uint ('p', 721 GNUNET_GETOPT_option_uint ('p',
781 "priority", 722 "priority",
782 "PRIORITY", 723 "PRIORITY",
783 gettext_noop ("specify the priority of the content"), 724 gettext_noop (
784 &content_priority), 725 "specify the priority of the content"),
726 &content_priority),
785 727
786 GNUNET_GETOPT_option_uint ('r', 728 GNUNET_GETOPT_option_uint ('r',
787 "replication", 729 "replication",
788 "LEVEL", 730 "LEVEL",
789 gettext_noop ("set the desired replication LEVEL"), 731 gettext_noop (
790 &replication_level), 732 "set the desired replication LEVEL"),
733 &replication_level),
791 734
792 GNUNET_GETOPT_option_verbose (&verbose), 735 GNUNET_GETOPT_option_verbose (&verbose),
793 736
794 GNUNET_GETOPT_OPTION_END 737 GNUNET_GETOPT_OPTION_END};
795 };
796 struct WorkItem *wi; 738 struct WorkItem *wi;
797 int ok; 739 int ok;
798 struct GNUNET_SIGNAL_Context *shc_chld; 740 struct GNUNET_SIGNAL_Context *shc_chld;
799 741
800 if (GNUNET_OK != 742 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
801 GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
802 return 2; 743 return 2;
803 sigpipe = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, 744 sigpipe = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_NO, GNUNET_NO);
804 GNUNET_NO, GNUNET_NO);
805 GNUNET_assert (NULL != sigpipe); 745 GNUNET_assert (NULL != sigpipe);
806 shc_chld = 746 shc_chld =
807 GNUNET_SIGNAL_handler_install (GNUNET_SIGCHLD, 747 GNUNET_SIGNAL_handler_install (GNUNET_SIGCHLD, &sighandler_child_death);
808 &sighandler_child_death); 748 ok =
809 ok = (GNUNET_OK == 749 (GNUNET_OK ==
810 GNUNET_PROGRAM_run (argc, argv, 750 GNUNET_PROGRAM_run (
811 "gnunet-auto-share [OPTIONS] FILENAME", 751 argc,
812 gettext_noop 752 argv,
813 ("Automatically publish files from a directory on GNUnet"), 753 "gnunet-auto-share [OPTIONS] FILENAME",
814 options, &run, NULL)) ? ret : 1; 754 gettext_noop ("Automatically publish files from a directory on GNUnet"),
755 options,
756 &run,
757 NULL))
758 ? ret
759 : 1;
815 if (NULL != work_finished) 760 if (NULL != work_finished)
816 { 761 {
817 (void) GNUNET_CONTAINER_multihashmap_iterate (work_finished, 762 (void) GNUNET_CONTAINER_multihashmap_iterate (work_finished,
818 &free_item, 763 &free_item,
819 NULL); 764 NULL);
820 GNUNET_CONTAINER_multihashmap_destroy (work_finished); 765 GNUNET_CONTAINER_multihashmap_destroy (work_finished);
821 } 766 }
822 while (NULL != (wi = work_head)) 767 while (NULL != (wi = work_head))
823 { 768 {
824 GNUNET_CONTAINER_DLL_remove (work_head, 769 GNUNET_CONTAINER_DLL_remove (work_head, work_tail, wi);
825 work_tail,
826 wi);
827 GNUNET_free (wi->filename); 770 GNUNET_free (wi->filename);
828 GNUNET_free (wi); 771 GNUNET_free (wi);
829 } 772 }
@@ -833,7 +776,7 @@ main (int argc, char *const *argv)
833 sigpipe = NULL; 776 sigpipe = NULL;
834 GNUNET_free_non_null (cfg_filename); 777 GNUNET_free_non_null (cfg_filename);
835 cfg_filename = NULL; 778 cfg_filename = NULL;
836 GNUNET_free ((void*) argv); 779 GNUNET_free ((void *) argv);
837 return ok; 780 return ok;
838} 781}
839 782