types
[oweals/gnunet.git] / src / hostlist / gnunet-daemon-hostlist.c
index f11bcd87d9f798d3aeb3a7d66d431298341f0275..7d075cf808df69ffd43b961fbbb171d76b916ae0 100644 (file)
  * @file hostlist/gnunet-daemon-hostlist.c
  * @brief code for bootstrapping via hostlist servers
  * @author Christian Grothoff
+ *
+ * TODO:
+ * - implement -a and -e switches (send P2P messages about our hostlist URL,
+ *   receive such messages and automatically update our hostlist URL config
+ *   value).
  */
 
 #include <stdlib.h>
 #include "platform.h"
 #include "hostlist-client.h"
+#include "hostlist-server.h"
 #include "gnunet_core_service.h"
 #include "gnunet_getopt_lib.h"
 #include "gnunet_protocols.h"
 #include "gnunet_util_lib.h"
 
 
+/**
+ * Set if we are allowed to advertise our hostlist to others.
+ */
+static int advertising;
+
 /**
  * Set if we are allowed to learn about peers by accessing
  * hostlist servers.
@@ -63,11 +74,17 @@ static struct GNUNET_STATISTICS_Handle *stats;
  * gnunet-daemon-hostlist command line options.
  */
 static struct GNUNET_GETOPT_CommandLineOption options[] = {
-  { 'b', "bootstrap", NULL, gettext_noop ("bootstrap using hostlists (it is highly recommended that you always use this option)"),
+  { 'a', "advertise", NULL, 
+    gettext_noop ("advertise our hostlist to other peers"),
+    GNUNET_NO, &GNUNET_GETOPT_set_one, &advertising },
+  { 'b', "bootstrap", NULL, 
+    gettext_noop ("bootstrap using hostlists (it is highly recommended that you always use this option)"),
     GNUNET_NO, &GNUNET_GETOPT_set_one, &bootstrapping },
-  { 'e', "enable-learning", NULL, gettext_noop ("enable learning about hostlist servers from other peers"),
+  { 'e', "enable-learning", NULL,
+    gettext_noop ("enable learning about hostlist servers from other peers"),
     GNUNET_NO, &GNUNET_GETOPT_set_one, &learning},
-  { 'p', "provide-hostlist", NULL, gettext_noop ("provide a hostlist server"),
+  { 'p', "provide-hostlist", NULL, 
+    gettext_noop ("provide a hostlist server"),
     GNUNET_NO, &GNUNET_GETOPT_set_one, &provide_hostlist},
   GNUNET_GETOPT_OPTION_END
 };
@@ -82,7 +99,10 @@ core_init (void *cls,
           GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *
           publicKey)
 {
-  /* TODO: provide "server" to 'hostlist' module (if applicable) */
+  if (advertising && (NULL != server))
+    {    
+      /* FIXME: provide "server" to 'hostlist' module */
+    }
 }
 
 
@@ -115,7 +135,7 @@ run (void *cls,
      struct GNUNET_SCHEDULER_Handle * sched,
      char *const *args,
      const char *cfgfile,
-     struct GNUNET_CONFIGURATION_Handle * cfg)
+     const struct GNUNET_CONFIGURATION_Handle * cfg)
 {
   GNUNET_CORE_ClientEventHandler ch = NULL;
   GNUNET_CORE_ClientEventHandler dh = NULL;
@@ -135,8 +155,7 @@ run (void *cls,
   stats = GNUNET_STATISTICS_create (sched, "hostlist", cfg);
   if (learning)
     {
-      // FIXME!
-      // (register handler with core for hostlist ads)
+      /* FIXME (register handler with core for hostlist ads) */
     }
   if (bootstrapping)
     {
@@ -145,9 +164,7 @@ run (void *cls,
     }
   if (provide_hostlist)
     {      
-      // FIXME!
-      // (initialize MHD server and run using scheduler;
-      //  use peerinfo to gather HELLOs)
+      GNUNET_HOSTLIST_server_start (cfg, sched, stats);
     }
   GNUNET_CORE_connect (sched, cfg,
                       GNUNET_TIME_UNIT_FOREVER_REL,
@@ -161,7 +178,7 @@ run (void *cls,
   GNUNET_SCHEDULER_add_delayed (sched,
                                 GNUNET_YES,
                                 GNUNET_SCHEDULER_PRIORITY_IDLE,
-                                GNUNET_SCHEDULER_NO_PREREQUISITE_TASK,
+                                GNUNET_SCHEDULER_NO_TASK,
                                 GNUNET_TIME_UNIT_FOREVER_REL,
                                 &cleaning_task, NULL);
 }