diff options
Diffstat (limited to 'src/fs')
-rw-r--r-- | src/fs/gnunet-publish.c | 139 |
1 files changed, 66 insertions, 73 deletions
diff --git a/src/fs/gnunet-publish.c b/src/fs/gnunet-publish.c index 0dbedcec6..a0863dcbb 100644 --- a/src/fs/gnunet-publish.c +++ b/src/fs/gnunet-publish.c | |||
@@ -30,9 +30,9 @@ | |||
30 | #include "gnunet_identity_service.h" | 30 | #include "gnunet_identity_service.h" |
31 | 31 | ||
32 | /** | 32 | /** |
33 | * Global return value from 'main'. | 33 | * Global return value from #main(). |
34 | */ | 34 | */ |
35 | static int ret = 1; | 35 | static int ret; |
36 | 36 | ||
37 | /** | 37 | /** |
38 | * Command line option 'verbose' set | 38 | * Command line option 'verbose' set |
@@ -125,11 +125,6 @@ static int extract_only; | |||
125 | static int do_disable_creation_time; | 125 | static int do_disable_creation_time; |
126 | 126 | ||
127 | /** | 127 | /** |
128 | * Task run on CTRL-C to kill everything nicely. | ||
129 | */ | ||
130 | static struct GNUNET_SCHEDULER_Task * kill_task; | ||
131 | |||
132 | /** | ||
133 | * Handle to the directory scanner (for recursive insertions). | 128 | * Handle to the directory scanner (for recursive insertions). |
134 | */ | 129 | */ |
135 | static struct GNUNET_FS_DirScanner *ds; | 130 | static struct GNUNET_FS_DirScanner *ds; |
@@ -159,7 +154,11 @@ do_stop_task (void *cls, | |||
159 | { | 154 | { |
160 | struct GNUNET_FS_PublishContext *p; | 155 | struct GNUNET_FS_PublishContext *p; |
161 | 156 | ||
162 | kill_task = NULL; | 157 | if (NULL != ds) |
158 | { | ||
159 | GNUNET_FS_directory_scan_abort (ds); | ||
160 | ds = NULL; | ||
161 | } | ||
163 | if (NULL != identity) | 162 | if (NULL != identity) |
164 | { | 163 | { |
165 | GNUNET_IDENTITY_disconnect (identity); | 164 | GNUNET_IDENTITY_disconnect (identity); |
@@ -171,37 +170,21 @@ do_stop_task (void *cls, | |||
171 | pc = NULL; | 170 | pc = NULL; |
172 | GNUNET_FS_publish_stop (p); | 171 | GNUNET_FS_publish_stop (p); |
173 | } | 172 | } |
173 | if (NULL != ctx) | ||
174 | { | ||
175 | GNUNET_FS_stop (ctx); | ||
176 | ctx = NULL; | ||
177 | } | ||
174 | if (NULL != meta) | 178 | if (NULL != meta) |
175 | { | 179 | { |
176 | GNUNET_CONTAINER_meta_data_destroy (meta); | 180 | GNUNET_CONTAINER_meta_data_destroy (meta); |
177 | meta = NULL; | 181 | meta = NULL; |
178 | } | 182 | } |
179 | } | 183 | if (NULL != uri) |
180 | |||
181 | |||
182 | /** | ||
183 | * Stop the directory scanner (we had an error). | ||
184 | * | ||
185 | * @param cls closure | ||
186 | * @param tc scheduler context | ||
187 | */ | ||
188 | static void | ||
189 | stop_scanner_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
190 | { | ||
191 | kill_task = NULL; | ||
192 | if (NULL != ds) | ||
193 | { | ||
194 | GNUNET_FS_directory_scan_abort (ds); | ||
195 | ds = NULL; | ||
196 | } | ||
197 | if (NULL != identity) | ||
198 | { | 184 | { |
199 | GNUNET_IDENTITY_disconnect (identity); | 185 | GNUNET_FS_uri_destroy (uri); |
200 | identity = NULL; | 186 | uri = NULL; |
201 | } | 187 | } |
202 | GNUNET_FS_stop (ctx); | ||
203 | ctx = NULL; | ||
204 | ret = 1; | ||
205 | } | 188 | } |
206 | 189 | ||
207 | 190 | ||
@@ -254,14 +237,11 @@ progress_cb (void *cls, | |||
254 | } | 237 | } |
255 | break; | 238 | break; |
256 | case GNUNET_FS_STATUS_PUBLISH_ERROR: | 239 | case GNUNET_FS_STATUS_PUBLISH_ERROR: |
257 | FPRINTF (stderr, _("Error publishing: %s.\n"), | 240 | FPRINTF (stderr, |
241 | _("Error publishing: %s.\n"), | ||
258 | info->value.publish.specifics.error.message); | 242 | info->value.publish.specifics.error.message); |
259 | if (kill_task != NULL) | 243 | ret = 1; |
260 | { | 244 | GNUNET_SCHEDULER_shutdown (); |
261 | GNUNET_SCHEDULER_cancel (kill_task); | ||
262 | kill_task = NULL; | ||
263 | } | ||
264 | kill_task = GNUNET_SCHEDULER_add_now (&do_stop_task, NULL); | ||
265 | break; | 245 | break; |
266 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: | 246 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: |
267 | FPRINTF (stdout, | 247 | FPRINTF (stdout, |
@@ -284,11 +264,9 @@ progress_cb (void *cls, | |||
284 | } | 264 | } |
285 | if (NULL == info->value.publish.pctx) | 265 | if (NULL == info->value.publish.pctx) |
286 | { | 266 | { |
287 | if (NULL != kill_task) | 267 | ret = 0; |
288 | GNUNET_SCHEDULER_cancel (kill_task); | 268 | GNUNET_SCHEDULER_shutdown (); |
289 | kill_task = GNUNET_SCHEDULER_add_now (&do_stop_task, NULL); | ||
290 | } | 269 | } |
291 | ret = 0; | ||
292 | break; | 270 | break; |
293 | case GNUNET_FS_STATUS_PUBLISH_STOPPED: | 271 | case GNUNET_FS_STATUS_PUBLISH_STOPPED: |
294 | GNUNET_break (NULL == pc); | 272 | GNUNET_break (NULL == pc); |
@@ -351,9 +329,15 @@ meta_printer (void *cls, | |||
351 | if (EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME == type) | 329 | if (EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME == type) |
352 | return 0; | 330 | return 0; |
353 | #if HAVE_LIBEXTRACTOR | 331 | #if HAVE_LIBEXTRACTOR |
354 | FPRINTF (stdout, "\t%s - %s\n", EXTRACTOR_metatype_to_string (type), data); | 332 | FPRINTF (stdout, |
333 | "\t%s - %s\n", | ||
334 | EXTRACTOR_metatype_to_string (type), | ||
335 | data); | ||
355 | #else | 336 | #else |
356 | FPRINTF (stdout, "\t%d - %s\n", type, data); | 337 | FPRINTF (stdout, |
338 | "\t%d - %s\n", | ||
339 | type, | ||
340 | data); | ||
357 | #endif | 341 | #endif |
358 | return 0; | 342 | return 0; |
359 | } | 343 | } |
@@ -444,17 +428,26 @@ publish_inspector (void *cls, | |||
444 | fn = GNUNET_CONTAINER_meta_data_get_by_type (m, | 428 | fn = GNUNET_CONTAINER_meta_data_get_by_type (m, |
445 | EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME); | 429 | EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME); |
446 | fs = GNUNET_STRINGS_byte_size_fancy (length); | 430 | fs = GNUNET_STRINGS_byte_size_fancy (length); |
447 | FPRINTF (stdout, _("Meta data for file `%s' (%s)\n"), fn, fs); | 431 | FPRINTF (stdout, |
432 | _("Meta data for file `%s' (%s)\n"), | ||
433 | fn, | ||
434 | fs); | ||
448 | GNUNET_CONTAINER_meta_data_iterate (m, &meta_printer, NULL); | 435 | GNUNET_CONTAINER_meta_data_iterate (m, &meta_printer, NULL); |
449 | FPRINTF (stdout, _("Keywords for file `%s' (%s)\n"), fn, fs); | 436 | FPRINTF (stdout, |
437 | _("Keywords for file `%s' (%s)\n"), | ||
438 | fn, | ||
439 | fs); | ||
450 | GNUNET_free (fn); | 440 | GNUNET_free (fn); |
451 | GNUNET_free (fs); | 441 | GNUNET_free (fs); |
452 | if (NULL != *uri) | 442 | if (NULL != *uri) |
453 | GNUNET_FS_uri_ksk_get_keywords (*uri, &keyword_printer, NULL); | 443 | GNUNET_FS_uri_ksk_get_keywords (*uri, &keyword_printer, NULL); |
454 | FPRINTF (stdout, "%s", "\n"); | 444 | FPRINTF (stdout, |
445 | "%s", | ||
446 | "\n"); | ||
455 | } | 447 | } |
456 | if (GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (m)) | 448 | if (GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (m)) |
457 | GNUNET_FS_file_information_inspect (fi, &publish_inspector, fi); | 449 | GNUNET_FS_file_information_inspect (fi, |
450 | &publish_inspector, fi); | ||
458 | return GNUNET_OK; | 451 | return GNUNET_OK; |
459 | } | 452 | } |
460 | 453 | ||
@@ -475,13 +468,12 @@ uri_sks_continuation (void *cls, | |||
475 | { | 468 | { |
476 | if (NULL != emsg) | 469 | if (NULL != emsg) |
477 | { | 470 | { |
478 | FPRINTF (stderr, "%s\n", emsg); | 471 | FPRINTF (stderr, |
472 | "%s\n", | ||
473 | emsg); | ||
479 | ret = 1; | 474 | ret = 1; |
480 | } | 475 | } |
481 | GNUNET_FS_uri_destroy (uri); | 476 | GNUNET_SCHEDULER_shutdown (); |
482 | uri = NULL; | ||
483 | GNUNET_FS_stop (ctx); | ||
484 | ctx = NULL; | ||
485 | } | 477 | } |
486 | 478 | ||
487 | 479 | ||
@@ -503,21 +495,26 @@ uri_ksk_continuation (void *cls, | |||
503 | 495 | ||
504 | if (NULL != emsg) | 496 | if (NULL != emsg) |
505 | { | 497 | { |
506 | FPRINTF (stderr, "%s\n", emsg); | 498 | FPRINTF (stderr, |
499 | "%s\n", | ||
500 | emsg); | ||
507 | ret = 1; | 501 | ret = 1; |
508 | } | 502 | } |
509 | if (NULL != namespace) | 503 | if (NULL != namespace) |
510 | { | 504 | { |
511 | priv = GNUNET_IDENTITY_ego_get_private_key (namespace); | 505 | priv = GNUNET_IDENTITY_ego_get_private_key (namespace); |
512 | GNUNET_FS_publish_sks (ctx, priv, this_id, next_id, meta, uri, &bo, | 506 | GNUNET_FS_publish_sks (ctx, |
507 | priv, | ||
508 | this_id, | ||
509 | next_id, | ||
510 | meta, | ||
511 | uri, | ||
512 | &bo, | ||
513 | GNUNET_FS_PUBLISH_OPTION_NONE, | 513 | GNUNET_FS_PUBLISH_OPTION_NONE, |
514 | &uri_sks_continuation, NULL); | 514 | &uri_sks_continuation, NULL); |
515 | return; | 515 | return; |
516 | } | 516 | } |
517 | GNUNET_FS_uri_destroy (uri); | 517 | GNUNET_SCHEDULER_shutdown (); |
518 | uri = NULL; | ||
519 | GNUNET_FS_stop (ctx); | ||
520 | ctx = NULL; | ||
521 | } | 518 | } |
522 | 519 | ||
523 | 520 | ||
@@ -592,8 +589,8 @@ directory_trim_complete (struct GNUNET_FS_ShareTreeItem *directory_scan_result) | |||
592 | FPRINTF (stderr, | 589 | FPRINTF (stderr, |
593 | "%s", | 590 | "%s", |
594 | _("Could not publish\n")); | 591 | _("Could not publish\n")); |
595 | GNUNET_SCHEDULER_shutdown (); | ||
596 | ret = 1; | 592 | ret = 1; |
593 | GNUNET_SCHEDULER_shutdown (); | ||
597 | return; | 594 | return; |
598 | } | 595 | } |
599 | GNUNET_FS_file_information_inspect (fi, &publish_inspector, NULL); | 596 | GNUNET_FS_file_information_inspect (fi, &publish_inspector, NULL); |
@@ -617,8 +614,8 @@ directory_trim_complete (struct GNUNET_FS_ShareTreeItem *directory_scan_result) | |||
617 | FPRINTF (stderr, | 614 | FPRINTF (stderr, |
618 | "%s", | 615 | "%s", |
619 | _("Could not start publishing.\n")); | 616 | _("Could not start publishing.\n")); |
620 | GNUNET_SCHEDULER_shutdown (); | ||
621 | ret = 1; | 617 | ret = 1; |
618 | GNUNET_SCHEDULER_shutdown (); | ||
622 | return; | 619 | return; |
623 | } | 620 | } |
624 | } | 621 | } |
@@ -689,12 +686,8 @@ directory_scan_cb (void *cls, | |||
689 | FPRINTF (stdout, | 686 | FPRINTF (stdout, |
690 | "%s", | 687 | "%s", |
691 | _("Internal error scanning directory.\n")); | 688 | _("Internal error scanning directory.\n")); |
692 | if (kill_task != NULL) | 689 | ret = 1; |
693 | { | 690 | GNUNET_SCHEDULER_shutdown (); |
694 | GNUNET_SCHEDULER_cancel (kill_task); | ||
695 | kill_task = NULL; | ||
696 | } | ||
697 | kill_task = GNUNET_SCHEDULER_add_now (&stop_scanner_task, NULL); | ||
698 | break; | 691 | break; |
699 | default: | 692 | default: |
700 | GNUNET_assert (0); | 693 | GNUNET_assert (0); |
@@ -722,6 +715,7 @@ identity_continuation (const char *args0) | |||
722 | FPRINTF (stderr, | 715 | FPRINTF (stderr, |
723 | _("Selected pseudonym `%s' unknown\n"), | 716 | _("Selected pseudonym `%s' unknown\n"), |
724 | pseudonym); | 717 | pseudonym); |
718 | ret = 1; | ||
725 | GNUNET_SCHEDULER_shutdown (); | 719 | GNUNET_SCHEDULER_shutdown (); |
726 | return; | 720 | return; |
727 | } | 721 | } |
@@ -734,8 +728,8 @@ identity_continuation (const char *args0) | |||
734 | _("Failed to parse URI: %s\n"), | 728 | _("Failed to parse URI: %s\n"), |
735 | emsg); | 729 | emsg); |
736 | GNUNET_free (emsg); | 730 | GNUNET_free (emsg); |
737 | GNUNET_SCHEDULER_shutdown (); | ||
738 | ret = 1; | 731 | ret = 1; |
732 | GNUNET_SCHEDULER_shutdown (); | ||
739 | return; | 733 | return; |
740 | } | 734 | } |
741 | GNUNET_FS_publish_ksk (ctx, topKeywords, | 735 | GNUNET_FS_publish_ksk (ctx, topKeywords, |
@@ -880,10 +874,9 @@ run (void *cls, | |||
880 | ret = 1; | 874 | ret = 1; |
881 | return; | 875 | return; |
882 | } | 876 | } |
883 | kill_task = | 877 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, |
884 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, | 878 | &do_stop_task, |
885 | &do_stop_task, | 879 | NULL); |
886 | NULL); | ||
887 | if (NULL != pseudonym) | 880 | if (NULL != pseudonym) |
888 | identity = GNUNET_IDENTITY_connect (cfg, | 881 | identity = GNUNET_IDENTITY_connect (cfg, |
889 | &identity_cb, | 882 | &identity_cb, |