aboutsummaryrefslogtreecommitdiff
path: root/src/namestore
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2013-12-06 14:06:17 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2013-12-06 14:06:17 +0000
commite8ce3f9912d4daed5d0d7359b38422aeebe20048 (patch)
treec874ee11286a9a34a652af4b9b861c9f4bf304c0 /src/namestore
parentf553a4098ae625812a9d082aedfc393c212c7d13 (diff)
downloadgnunet-e8ce3f9912d4daed5d0d7359b38422aeebe20048.tar.gz
gnunet-e8ce3f9912d4daed5d0d7359b38422aeebe20048.zip
- test if identity service is running
- default ego is used if none given
Diffstat (limited to 'src/namestore')
-rw-r--r--src/namestore/gnunet-namestore.c106
1 files changed, 89 insertions, 17 deletions
diff --git a/src/namestore/gnunet-namestore.c b/src/namestore/gnunet-namestore.c
index 5de86182f..6a8df6945 100644
--- a/src/namestore/gnunet-namestore.c
+++ b/src/namestore/gnunet-namestore.c
@@ -50,6 +50,10 @@ static struct GNUNET_CRYPTO_EcdsaPrivateKey zone_pkey;
50 */ 50 */
51static struct GNUNET_IDENTITY_EgoLookup *el; 51static struct GNUNET_IDENTITY_EgoLookup *el;
52 52
53static struct GNUNET_IDENTITY_Handle *idh;
54
55struct GNUNET_IDENTITY_Operation *get_default;
56
53/** 57/**
54 * Name of the ego controlling the zone. 58 * Name of the ego controlling the zone.
55 */ 59 */
@@ -196,6 +200,16 @@ static void
196do_shutdown (void *cls, 200do_shutdown (void *cls,
197 const struct GNUNET_SCHEDULER_TaskContext *tc) 201 const struct GNUNET_SCHEDULER_TaskContext *tc)
198{ 202{
203 if (NULL != get_default)
204 {
205 GNUNET_IDENTITY_cancel (get_default);
206 get_default = NULL;
207 }
208 if (NULL != idh)
209 {
210 GNUNET_IDENTITY_disconnect (idh);
211 idh = NULL;
212 }
199 if (NULL != el) 213 if (NULL != el)
200 { 214 {
201 GNUNET_IDENTITY_ego_lookup_cancel (el); 215 GNUNET_IDENTITY_ego_lookup_cancel (el);
@@ -764,14 +778,17 @@ identity_cb (void *cls,
764 el = NULL; 778 el = NULL;
765 if (NULL == ego) 779 if (NULL == ego)
766 { 780 {
767 fprintf (stderr, 781 if (NULL != ego_name)
768 _("Ego `%s' not known to identity service\n"), 782 {
769 ego_name); 783 fprintf (stderr,
784 _("Ego `%s' not known to identity service\n"),
785 ego_name);
786 }
770 GNUNET_SCHEDULER_shutdown (); 787 GNUNET_SCHEDULER_shutdown ();
771 return; 788 return;
772 } 789 }
773 zone_pkey = *GNUNET_IDENTITY_ego_get_private_key (ego); 790 zone_pkey = *GNUNET_IDENTITY_ego_get_private_key (ego);
774 GNUNET_free (ego_name); 791 GNUNET_free_non_null (ego_name);
775 ego_name = NULL; 792 ego_name = NULL;
776 GNUNET_CLIENT_service_test ("namestore", cfg, 793 GNUNET_CLIENT_service_test ("namestore", cfg,
777 GNUNET_TIME_UNIT_SECONDS, 794 GNUNET_TIME_UNIT_SECONDS,
@@ -780,6 +797,69 @@ identity_cb (void *cls,
780} 797}
781 798
782 799
800static void
801default_ego_cb (void *cls,
802 struct GNUNET_IDENTITY_Ego *ego,
803 void **ctx,
804 const char *name)
805{
806 get_default = NULL;
807 if (NULL == ego)
808 {
809 fprintf (stderr,
810 _("No default ego configured in identity service\n"));
811 GNUNET_SCHEDULER_shutdown ();
812 return;
813 }
814 else
815 {
816 identity_cb (cls, ego);
817 }
818}
819
820static void
821id_connect_cb (void *cls,
822 struct GNUNET_IDENTITY_Ego *ego,
823 void **ctx,
824 const char *name)
825{
826 const struct GNUNET_CONFIGURATION_Handle *cfg = cls;
827 if (NULL == ego)
828 {
829 get_default = GNUNET_IDENTITY_get (idh, "namestore",
830 &default_ego_cb, (void *) cfg);
831 }
832}
833
834
835static void
836testservice_id_task (void *cls, int result)
837{
838 const struct GNUNET_CONFIGURATION_Handle *cfg = cls;
839 if (result != GNUNET_YES)
840 {
841 fprintf (stderr,
842 _("Identity service is not running\n"));
843 GNUNET_SCHEDULER_shutdown ();
844 return;
845 }
846 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
847 &do_shutdown, (void *) cfg);
848
849 if (NULL == ego_name)
850 {
851 idh = GNUNET_IDENTITY_connect (cfg, &id_connect_cb, (void *) cfg);
852 if (NULL == idh)
853 fprintf (stderr, _("Cannot connect to identity service\n"));
854 return;
855 }
856 el = GNUNET_IDENTITY_ego_lookup (cfg,
857 ego_name,
858 &identity_cb,
859 (void *) cfg);
860}
861
862
783/** 863/**
784 * Main function that will be run. 864 * Main function that will be run.
785 * 865 *
@@ -792,21 +872,13 @@ static void
792run (void *cls, char *const *args, const char *cfgfile, 872run (void *cls, char *const *args, const char *cfgfile,
793 const struct GNUNET_CONFIGURATION_Handle *cfg) 873 const struct GNUNET_CONFIGURATION_Handle *cfg)
794{ 874{
795 if (NULL == ego_name)
796 {
797 fprintf (stderr,
798 _("You must specify which zone should be accessed\n"));
799 return;
800 }
801
802 if ( (NULL != args[0]) && (NULL == uri) ) 875 if ( (NULL != args[0]) && (NULL == uri) )
803 uri = GNUNET_strdup (args[0]); 876 uri = GNUNET_strdup (args[0]);
804 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 877
805 &do_shutdown, NULL); 878 GNUNET_CLIENT_service_test ("identity", cfg,
806 el = GNUNET_IDENTITY_ego_lookup (cfg, 879 GNUNET_TIME_UNIT_SECONDS,
807 ego_name, 880 &testservice_id_task,
808 &identity_cb, 881 (void *) cfg);
809 (void *) cfg);
810} 882}
811 883
812 884