aboutsummaryrefslogtreecommitdiff
path: root/src/fs/gnunet-publish.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-08-06 20:46:22 +0000
committerChristian Grothoff <christian@grothoff.org>2013-08-06 20:46:22 +0000
commit303ab4dafbc680b1b362f95df5b12dae831b1593 (patch)
tree8b2f411b0b31e500ce2988404b2501db03bed945 /src/fs/gnunet-publish.c
parent1360f8a1e5877a8796dc8e7d0c55d78481382e80 (diff)
downloadgnunet-303ab4dafbc680b1b362f95df5b12dae831b1593.tar.gz
gnunet-303ab4dafbc680b1b362f95df5b12dae831b1593.zip
-fixing main FS build, updating man page of gnunet-pseudonym
Diffstat (limited to 'src/fs/gnunet-publish.c')
-rw-r--r--src/fs/gnunet-publish.c211
1 files changed, 121 insertions, 90 deletions
diff --git a/src/fs/gnunet-publish.c b/src/fs/gnunet-publish.c
index 59b40a5e4..39235683c 100644
--- a/src/fs/gnunet-publish.c
+++ b/src/fs/gnunet-publish.c
@@ -27,6 +27,7 @@
27 */ 27 */
28#include "platform.h" 28#include "platform.h"
29#include "gnunet_fs_service.h" 29#include "gnunet_fs_service.h"
30#include "gnunet_identity_service.h"
30 31
31/** 32/**
32 * Global return value from 'main'. 33 * Global return value from 'main'.
@@ -137,7 +138,12 @@ static struct GNUNET_FS_DirScanner *ds;
137 * Which namespace do we publish to? NULL if we do not publish to 138 * Which namespace do we publish to? NULL if we do not publish to
138 * a namespace. 139 * a namespace.
139 */ 140 */
140static struct GNUNET_FS_Namespace *namespace; 141static struct GNUNET_IDENTITY_Ego *namespace;
142
143/**
144 * Handle to identity service.
145 */
146static struct GNUNET_IDENTITY_Handle *identity;
141 147
142 148
143/** 149/**
@@ -153,7 +159,7 @@ do_stop_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
153 struct GNUNET_FS_PublishContext *p; 159 struct GNUNET_FS_PublishContext *p;
154 160
155 kill_task = GNUNET_SCHEDULER_NO_TASK; 161 kill_task = GNUNET_SCHEDULER_NO_TASK;
156 if (pc != NULL) 162 if (NULL != pc)
157 { 163 {
158 p = pc; 164 p = pc;
159 pc = NULL; 165 pc = NULL;
@@ -182,10 +188,10 @@ stop_scanner_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
182 GNUNET_FS_directory_scan_abort (ds); 188 GNUNET_FS_directory_scan_abort (ds);
183 ds = NULL; 189 ds = NULL;
184 } 190 }
185 if (NULL != namespace) 191 if (NULL != identity)
186 { 192 {
187 GNUNET_FS_namespace_delete (namespace, GNUNET_NO); 193 GNUNET_IDENTITY_disconnect (identity);
188 namespace = NULL; 194 identity = NULL;
189 } 195 }
190 GNUNET_FS_stop (ctx); 196 GNUNET_FS_stop (ctx);
191 ctx = NULL; 197 ctx = NULL;
@@ -432,29 +438,20 @@ static void
432uri_ksk_continuation (void *cls, const struct GNUNET_FS_Uri *ksk_uri, 438uri_ksk_continuation (void *cls, const struct GNUNET_FS_Uri *ksk_uri,
433 const char *emsg) 439 const char *emsg)
434{ 440{
435 struct GNUNET_FS_Namespace *ns; 441 const struct GNUNET_CRYPTO_EccPrivateKey *priv;
436 442
437 if (NULL != emsg) 443 if (NULL != emsg)
438 { 444 {
439 FPRINTF (stderr, "%s\n", emsg); 445 FPRINTF (stderr, "%s\n", emsg);
440 ret = 1; 446 ret = 1;
441 } 447 }
442 if (NULL != pseudonym) 448 if (NULL != namespace)
443 { 449 {
444 ns = GNUNET_FS_namespace_create (ctx, pseudonym); 450 priv = GNUNET_IDENTITY_ego_get_private_key (namespace);
445 if (NULL == ns) 451 GNUNET_FS_publish_sks (ctx, priv, this_id, next_id, meta, uri, &bo,
446 { 452 GNUNET_FS_PUBLISH_OPTION_NONE,
447 FPRINTF (stderr, _("Failed to create namespace `%s' (illegal filename?)\n"), pseudonym); 453 &uri_sks_continuation, NULL);
448 ret = 1; 454 return;
449 }
450 else
451 {
452 GNUNET_FS_publish_sks (ctx, ns, this_id, next_id, meta, uri, &bo,
453 GNUNET_FS_PUBLISH_OPTION_NONE,
454 &uri_sks_continuation, NULL);
455 GNUNET_assert (GNUNET_OK == GNUNET_FS_namespace_delete (ns, GNUNET_NO));
456 return;
457 }
458 } 455 }
459 GNUNET_FS_uri_destroy (uri); 456 GNUNET_FS_uri_destroy (uri);
460 uri = NULL; 457 uri = NULL;
@@ -523,40 +520,37 @@ static void
523directory_trim_complete (struct GNUNET_FS_ShareTreeItem *directory_scan_result) 520directory_trim_complete (struct GNUNET_FS_ShareTreeItem *directory_scan_result)
524{ 521{
525 struct GNUNET_FS_FileInformation *fi; 522 struct GNUNET_FS_FileInformation *fi;
523 const struct GNUNET_CRYPTO_EccPrivateKey *priv;
526 524
527 fi = get_file_information (directory_scan_result); 525 fi = get_file_information (directory_scan_result);
528 GNUNET_FS_share_tree_free (directory_scan_result); 526 GNUNET_FS_share_tree_free (directory_scan_result);
529 if (NULL == fi) 527 if (NULL == fi)
530 { 528 {
531 FPRINTF (stderr, "%s", _("Could not publish\n")); 529 FPRINTF (stderr, "%s", _("Could not publish\n"));
532 if (NULL != namespace) 530 GNUNET_SCHEDULER_shutdown ();
533 GNUNET_FS_namespace_delete (namespace, GNUNET_NO);
534 GNUNET_FS_stop (ctx);
535 ret = 1; 531 ret = 1;
536 return; 532 return;
537 } 533 }
538 GNUNET_FS_file_information_inspect (fi, &publish_inspector, NULL); 534 GNUNET_FS_file_information_inspect (fi, &publish_inspector, NULL);
539 if (extract_only) 535 if (extract_only)
540 { 536 {
541 if (NULL != namespace)
542 GNUNET_FS_namespace_delete (namespace, GNUNET_NO);
543 GNUNET_FS_file_information_destroy (fi, NULL, NULL); 537 GNUNET_FS_file_information_destroy (fi, NULL, NULL);
544 GNUNET_FS_stop (ctx); 538 GNUNET_SCHEDULER_shutdown ();
545 if (GNUNET_SCHEDULER_NO_TASK != kill_task)
546 {
547 GNUNET_SCHEDULER_cancel (kill_task);
548 kill_task = GNUNET_SCHEDULER_NO_TASK;
549 }
550 return; 539 return;
551 } 540 }
552 pc = GNUNET_FS_publish_start (ctx, fi, namespace, this_id, next_id, 541 if (NULL == namespace)
542 priv = NULL;
543 else
544 priv = GNUNET_IDENTITY_ego_get_private_key (namespace);
545 pc = GNUNET_FS_publish_start (ctx, fi,
546 priv, this_id, next_id,
553 (do_simulate) ? 547 (do_simulate) ?
554 GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY : 548 GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY :
555 GNUNET_FS_PUBLISH_OPTION_NONE); 549 GNUNET_FS_PUBLISH_OPTION_NONE);
556 if (NULL == pc) 550 if (NULL == pc)
557 { 551 {
558 FPRINTF (stderr, "%s", _("Could not start publishing.\n")); 552 FPRINTF (stderr, "%s", _("Could not start publishing.\n"));
559 GNUNET_FS_stop (ctx); 553 GNUNET_SCHEDULER_shutdown ();
560 ret = 1; 554 ret = 1;
561 return; 555 return;
562 } 556 }
@@ -632,6 +626,94 @@ directory_scan_cb (void *cls,
632 626
633 627
634/** 628/**
629 * Continuation proceeding with initialization after identity subsystem
630 * has been initialized.
631 *
632 * @param args0 filename to publish
633 */
634static void
635identity_continuation (const char *args0)
636{
637 char *ex;
638 char *emsg;
639
640 if ( (NULL != pseudonym) &&
641 (NULL == namespace) )
642 {
643 FPRINTF (stderr, _("Selected pseudonym `%s' unknown\n"), pseudonym);
644 GNUNET_SCHEDULER_shutdown ();
645 return;
646 }
647 if (NULL != uri_string)
648 {
649 emsg = NULL;
650 if (NULL == (uri = GNUNET_FS_uri_parse (uri_string, &emsg)))
651 {
652 FPRINTF (stderr, _("Failed to parse URI: %s\n"), emsg);
653 GNUNET_free (emsg);
654 GNUNET_SCHEDULER_shutdown ();
655 ret = 1;
656 return;
657 }
658 GNUNET_FS_publish_ksk (ctx, topKeywords, meta, uri, &bo,
659 GNUNET_FS_PUBLISH_OPTION_NONE, &uri_ksk_continuation,
660 NULL);
661 return;
662 }
663 if (GNUNET_OK !=
664 GNUNET_CONFIGURATION_get_value_string (cfg, "FS", "EXTRACTORS", &ex))
665 ex = NULL;
666 if (0 != ACCESS (args0, R_OK))
667 {
668 FPRINTF (stderr,
669 _("Failed to access `%s': %s\n"),
670 args0,
671 STRERROR (errno));
672 return;
673 }
674 ds = GNUNET_FS_directory_scan_start (args0,
675 disable_extractor,
676 ex,
677 &directory_scan_cb, NULL);
678 if (NULL == ds)
679 {
680 FPRINTF (stderr,
681 "%s", _("Failed to start meta directory scanner. Is gnunet-helper-publish-fs installed?\n"));
682 return;
683 }
684}
685
686
687/**
688 * Function called by identity service with known pseudonyms.
689 *
690 * @param cls closure with 'const char *' of filename to publish
691 * @param ego ego handle
692 * @param ego_ctx context for application to store data for this ego
693 * (during the lifetime of this process, initially NULL)
694 * @param name name assigned by the user for this ego,
695 * NULL if the user just deleted the ego and it
696 * must thus no longer be used
697 */
698static void
699identity_cb (void *cls,
700 struct GNUNET_IDENTITY_Ego *ego,
701 void **ctx,
702 const char *name)
703{
704 const char *args0 = cls;
705
706 if (NULL == ego)
707 {
708 identity_continuation (args0);
709 return;
710 }
711 if (0 == strcmp (name, pseudonym))
712 namespace = ego;
713}
714
715
716/**
635 * Main function that will be run by the scheduler. 717 * Main function that will be run by the scheduler.
636 * 718 *
637 * @param cls closure 719 * @param cls closure
@@ -643,9 +725,6 @@ static void
643run (void *cls, char *const *args, const char *cfgfile, 725run (void *cls, char *const *args, const char *cfgfile,
644 const struct GNUNET_CONFIGURATION_Handle *c) 726 const struct GNUNET_CONFIGURATION_Handle *c)
645{ 727{
646 char *ex;
647 char *emsg;
648
649 /* check arguments */ 728 /* check arguments */
650 if ((NULL != uri_string) && (extract_only)) 729 if ((NULL != uri_string) && (extract_only))
651 { 730 {
@@ -703,62 +782,14 @@ run (void *cls, char *const *args, const char *cfgfile,
703 ret = 1; 782 ret = 1;
704 return; 783 return;
705 } 784 }
706 namespace = NULL;
707 if (NULL != pseudonym)
708 {
709 namespace = GNUNET_FS_namespace_create (ctx, pseudonym);
710 if (NULL == namespace)
711 {
712 FPRINTF (stderr, _("Failed to create namespace `%s' (illegal filename?)\n"), pseudonym);
713 GNUNET_FS_stop (ctx);
714 ret = 1;
715 return;
716 }
717 }
718 if (NULL != uri_string)
719 {
720 emsg = NULL;
721 if (NULL == (uri = GNUNET_FS_uri_parse (uri_string, &emsg)))
722 {
723 FPRINTF (stderr, _("Failed to parse URI: %s\n"), emsg);
724 GNUNET_free (emsg);
725 if (namespace != NULL)
726 GNUNET_FS_namespace_delete (namespace, GNUNET_NO);
727 GNUNET_FS_stop (ctx);
728 ret = 1;
729 return;
730 }
731 GNUNET_FS_publish_ksk (ctx, topKeywords, meta, uri, &bo,
732 GNUNET_FS_PUBLISH_OPTION_NONE, &uri_ksk_continuation,
733 NULL);
734 if (NULL != namespace)
735 GNUNET_FS_namespace_delete (namespace, GNUNET_NO);
736 return;
737 }
738 if (GNUNET_OK !=
739 GNUNET_CONFIGURATION_get_value_string (cfg, "FS", "EXTRACTORS", &ex))
740 ex = NULL;
741 if (0 != ACCESS (args[0], R_OK))
742 {
743 FPRINTF (stderr,
744 _("Failed to access `%s': %s\n"),
745 args[0],
746 STRERROR (errno));
747 return;
748 }
749 ds = GNUNET_FS_directory_scan_start (args[0],
750 disable_extractor,
751 ex,
752 &directory_scan_cb, NULL);
753 if (NULL == ds)
754 {
755 FPRINTF (stderr,
756 "%s", _("Failed to start meta directory scanner. Is gnunet-helper-publish-fs installed?\n"));
757 return;
758 }
759 kill_task = 785 kill_task =
760 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &do_stop_task, 786 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &do_stop_task,
761 NULL); 787 NULL);
788 if (NULL != pseudonym)
789 identity = GNUNET_IDENTITY_connect (cfg,
790 &identity_cb, args[0]);
791 else
792 identity_continuation (args[0]);
762} 793}
763 794
764 795