aboutsummaryrefslogtreecommitdiff
path: root/src/gns/gnunet-dns2gns.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-09-05 11:09:18 +0000
committerChristian Grothoff <christian@grothoff.org>2013-09-05 11:09:18 +0000
commitf014057b89dfa367b67fd128c47a56621bef619e (patch)
tree27f703fc92264304a8dbc9e212c4dcf6314361c7 /src/gns/gnunet-dns2gns.c
parent0ffafff9fe803380a691e8238f93c9290a2c01ef (diff)
downloadgnunet-f014057b89dfa367b67fd128c47a56621bef619e.tar.gz
gnunet-f014057b89dfa367b67fd128c47a56621bef619e.zip
-integrate identity service with dns2gns (#3010)
Diffstat (limited to 'src/gns/gnunet-dns2gns.c')
-rw-r--r--src/gns/gnunet-dns2gns.c131
1 files changed, 104 insertions, 27 deletions
diff --git a/src/gns/gnunet-dns2gns.c b/src/gns/gnunet-dns2gns.c
index 509321eba..4b5c66e57 100644
--- a/src/gns/gnunet-dns2gns.c
+++ b/src/gns/gnunet-dns2gns.c
@@ -26,6 +26,7 @@
26#include <gnunet_util_lib.h> 26#include <gnunet_util_lib.h>
27#include <gnunet_dnsparser_lib.h> 27#include <gnunet_dnsparser_lib.h>
28#include <gnunet_gns_service.h> 28#include <gnunet_gns_service.h>
29#include <gnunet_identity_service.h>
29#include <gnunet_dnsstub_lib.h> 30#include <gnunet_dnsstub_lib.h>
30#include "gns.h" 31#include "gns.h"
31 32
@@ -149,6 +150,22 @@ static struct GNUNET_CRYPTO_EccPublicKey my_zone;
149 */ 150 */
150static char *gns_zone_str; 151static char *gns_zone_str;
151 152
153/**
154 * Configuration to use.
155 */
156static const struct GNUNET_CONFIGURATION_Handle *cfg;
157
158/**
159 * Connection to identity service.
160 */
161static struct GNUNET_IDENTITY_Handle *identity;
162
163/**
164 * Request for our ego.
165 */
166static struct GNUNET_IDENTITY_Operation *id_op;
167
168
152 169
153/** 170/**
154 * Task run on shutdown. Cleans up everything. 171 * Task run on shutdown. Cleans up everything.
@@ -557,34 +574,11 @@ read_dns6 (void *cls,
557 574
558 575
559/** 576/**
560 * Main function that will be run. 577 * Start DNS daemon.
561 *
562 * @param cls closure
563 * @param args remaining command-line arguments
564 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
565 * @param cfg configuration
566 */ 578 */
567static void 579static void
568run (void *cls, char *const *args, const char *cfgfile, 580run_dnsd ()
569 const struct GNUNET_CONFIGURATION_Handle *cfg)
570{ 581{
571 if (NULL == dns_ip)
572 {
573 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
574 _("No DNS server specified!\n"));
575 return;
576 }
577 if ( (NULL == gns_zone_str) ||
578 (GNUNET_OK !=
579 GNUNET_CRYPTO_ecc_public_key_from_string (gns_zone_str,
580 strlen (gns_zone_str),
581 &my_zone)) )
582 {
583 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
584 _("No valid GNS zone specified!\n"));
585 return;
586 }
587
588 if (NULL == dns_suffix) 582 if (NULL == dns_suffix)
589 dns_suffix = DNS_SUFFIX; 583 dns_suffix = DNS_SUFFIX;
590 if (NULL == fcfs_suffix) 584 if (NULL == fcfs_suffix)
@@ -665,13 +659,96 @@ run (void *cls, char *const *args, const char *cfgfile,
665 &read_dns6, 659 &read_dns6,
666 listen_socket6); 660 listen_socket6);
667 661
662}
663
664
665/**
666 * Method called to inform about the egos of this peer.
667 *
668 * When used with #GNUNET_IDENTITY_create or #GNUNET_IDENTITY_get,
669 * this function is only called ONCE, and 'NULL' being passed in
670 * @a ego does indicate an error (i.e. name is taken or no default
671 * value is known). If @a ego is non-NULL and if '*ctx'
672 * is set in those callbacks, the value WILL be passed to a subsequent
673 * call to the identity callback of #GNUNET_IDENTITY_connect (if
674 * that one was not NULL).
675 *
676 * @param cls closure, NULL
677 * @param ego ego handle
678 * @param ctx context for application to store data for this ego
679 * (during the lifetime of this process, initially NULL)
680 * @param name name assigned by the user for this ego,
681 * NULL if the user just deleted the ego and it
682 * must thus no longer be used
683 */
684static void
685identity_cb (void *cls,
686 struct GNUNET_IDENTITY_Ego *ego,
687 void **ctx,
688 const char *name)
689{
690 id_op = NULL;
691 if (NULL == ego)
692 {
693 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
694 _("No ego configured for `dns2gns` subsystem\n"));
695 return;
696 }
697 GNUNET_IDENTITY_ego_get_public_key (ego,
698 &my_zone);
699 run_dnsd ();
700}
701
702
703/**
704 * Main function that will be run.
705 *
706 * @param cls closure
707 * @param args remaining command-line arguments
708 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
709 * @param c configuration
710 */
711static void
712run (void *cls, char *const *args, const char *cfgfile,
713 const struct GNUNET_CONFIGURATION_Handle *c)
714{
715 cfg = c;
716
717 if (NULL == dns_ip)
718 {
719 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
720 _("No DNS server specified!\n"));
721 return;
722 }
668 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 723 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
669 &do_shutdown, NULL); 724 &do_shutdown, NULL);
725 if (NULL == gns_zone_str)
726 {
727 identity = GNUNET_IDENTITY_connect (cfg,
728 NULL, NULL);
729 id_op = GNUNET_IDENTITY_get (identity,
730 "dns2gns",
731 &identity_cb,
732 NULL);
733 return;
734 }
735 if ( (NULL == gns_zone_str) ||
736 (GNUNET_OK !=
737 GNUNET_CRYPTO_ecc_public_key_from_string (gns_zone_str,
738 strlen (gns_zone_str),
739 &my_zone)) )
740 {
741 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
742 _("No valid GNS zone specified!\n"));
743 GNUNET_SCHEDULER_shutdown ();
744 return;
745 }
746 run_dnsd ();
670} 747}
671 748
672 749
673/** 750/**
674 * The main function for the fcfs daemon. 751 * The main function for the dns2gns daemon.
675 * 752 *
676 * @param argc number of arguments from the command line 753 * @param argc number of arguments from the command line
677 * @param argv command line arguments 754 * @param argv command line arguments
@@ -695,7 +772,7 @@ main (int argc,
695 gettext_noop ("UDP port to listen on for inbound DNS requests; default: 53"), 1, 772 gettext_noop ("UDP port to listen on for inbound DNS requests; default: 53"), 1,
696 &GNUNET_GETOPT_set_uint, &listen_port}, 773 &GNUNET_GETOPT_set_uint, &listen_port},
697 {'z', "zone", "PUBLICKEY", 774 {'z', "zone", "PUBLICKEY",
698 gettext_noop ("Public key of the GNS zone to use (required)"), 1, 775 gettext_noop ("Public key of the GNS zone to use (overrides default)"), 1,
699 &GNUNET_GETOPT_set_string, &gns_zone_str}, 776 &GNUNET_GETOPT_set_string, &gns_zone_str},
700 GNUNET_GETOPT_OPTION_END 777 GNUNET_GETOPT_OPTION_END
701 }; 778 };