2 This file is part of GNUnet.
3 (C) 2007, 2008, 2009 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file hostlist/gnunet-daemon-hostlist.c
23 * @brief code for bootstrapping via hostlist servers
24 * @author Christian Grothoff
27 * - implement -a and -e switches (send P2P messages about our hostlist URL,
28 * receive such messages and automatically update our hostlist URL config
34 #include "hostlist-client.h"
35 #include "hostlist-server.h"
36 #include "gnunet_core_service.h"
37 #include "gnunet_getopt_lib.h"
38 #include "gnunet_protocols.h"
39 #include "gnunet_program_lib.h"
40 #include "gnunet_statistics_service.h"
41 #include "gnunet_strings_lib.h"
42 #include "gnunet_time_lib.h"
43 #include "gnunet_util_lib.h"
47 * Set if we are allowed to advertise our hostlist to others.
49 static int advertising;
52 * Set if we are allowed to learn about peers by accessing
55 static int bootstrapping;
58 * Set if the user allows us to learn about new hostlists
64 * Set if the user wants us to run a hostlist server.
66 static int provide_hostlist;
71 static struct GNUNET_STATISTICS_Handle *stats;
74 * gnunet-daemon-hostlist command line options.
76 static struct GNUNET_GETOPT_CommandLineOption options[] = {
77 { 'a', "advertise", NULL,
78 gettext_noop ("advertise our hostlist to other peers"),
79 GNUNET_NO, &GNUNET_GETOPT_set_one, &advertising },
80 { 'b', "bootstrap", NULL,
81 gettext_noop ("bootstrap using hostlists (it is highly recommended that you always use this option)"),
82 GNUNET_NO, &GNUNET_GETOPT_set_one, &bootstrapping },
83 { 'e', "enable-learning", NULL,
84 gettext_noop ("enable learning about hostlist servers from other peers"),
85 GNUNET_NO, &GNUNET_GETOPT_set_one, &learning},
86 { 'p', "provide-hostlist", NULL,
87 gettext_noop ("provide a hostlist server"),
88 GNUNET_NO, &GNUNET_GETOPT_set_one, &provide_hostlist},
89 GNUNET_GETOPT_OPTION_END
95 struct GNUNET_CORE_Handle * server,
96 const struct GNUNET_PeerIdentity *
99 GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *
102 if (advertising && (NULL != server))
104 /* FIXME: provide "server" to 'hostlist' module */
110 * Last task run during shutdown. Disconnects us from
111 * the other services.
114 cleaning_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
118 GNUNET_STATISTICS_destroy (stats);
125 * Main function that will be run.
128 * @param sched the scheduler to use
129 * @param args remaining command-line arguments
130 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
131 * @param cfg configuration
135 struct GNUNET_SCHEDULER_Handle * sched,
138 struct GNUNET_CONFIGURATION_Handle * cfg)
140 GNUNET_CORE_ClientEventHandler ch = NULL;
141 GNUNET_CORE_ClientEventHandler dh = NULL;
142 struct GNUNET_CORE_MessageHandler handlers[] =
147 if ( (! bootstrapping) &&
149 (! provide_hostlist) )
151 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
152 _("None of the functions for the hostlist daemon were enabled. I have no reason to run!\n"));
155 stats = GNUNET_STATISTICS_create (sched, "hostlist", cfg);
158 /* FIXME (register handler with core for hostlist ads) */
162 GNUNET_HOSTLIST_client_start (cfg, sched, stats,
165 if (provide_hostlist)
167 GNUNET_HOSTLIST_server_start (cfg, sched, stats);
169 GNUNET_CORE_connect (sched, cfg,
170 GNUNET_TIME_UNIT_FOREVER_REL,
178 GNUNET_SCHEDULER_add_delayed (sched,
180 GNUNET_SCHEDULER_PRIORITY_IDLE,
181 GNUNET_SCHEDULER_NO_TASK,
182 GNUNET_TIME_UNIT_FOREVER_REL,
183 &cleaning_task, NULL);
188 * The main function for the hostlist daemon.
190 * @param argc number of arguments from the command line
191 * @param argv command line arguments
192 * @return 0 ok, 1 on error
195 main (int argc, char *const *argv)
200 GNUNET_PROGRAM_run (argc,
203 _("GNUnet hostlist server and client"),
205 &run, NULL)) ? 0 : 1;
209 /* end of gnunet-daemon-hostlist.c */