diff options
author | Christian Grothoff <christian@grothoff.org> | 2010-04-22 08:29:36 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2010-04-22 08:29:36 +0000 |
commit | 808e125f5a5a08b41fc4b4234f29008fc5fb8c81 (patch) | |
tree | be6d36c4fe7ff50cf075a0bb5b8d76b235e4cdc8 /src/hostlist/gnunet-daemon-hostlist.c | |
parent | 17ed8fb315fc5e426ec26dbb7374485aaf5019f4 (diff) | |
download | gnunet-808e125f5a5a08b41fc4b4234f29008fc5fb8c81.tar.gz gnunet-808e125f5a5a08b41fc4b4234f29008fc5fb8c81.zip |
create hostlist client if we have no MHD
Diffstat (limited to 'src/hostlist/gnunet-daemon-hostlist.c')
-rw-r--r-- | src/hostlist/gnunet-daemon-hostlist.c | 65 |
1 files changed, 40 insertions, 25 deletions
diff --git a/src/hostlist/gnunet-daemon-hostlist.c b/src/hostlist/gnunet-daemon-hostlist.c index ec129fd8a..9ebf63719 100644 --- a/src/hostlist/gnunet-daemon-hostlist.c +++ b/src/hostlist/gnunet-daemon-hostlist.c | |||
@@ -22,17 +22,11 @@ | |||
22 | * @file hostlist/gnunet-daemon-hostlist.c | 22 | * @file hostlist/gnunet-daemon-hostlist.c |
23 | * @brief code for bootstrapping via hostlist servers | 23 | * @brief code for bootstrapping via hostlist servers |
24 | * @author Christian Grothoff | 24 | * @author Christian Grothoff |
25 | * | ||
26 | * TODO: | ||
27 | * - implement -a and -e switches (send P2P messages about our hostlist URL, | ||
28 | * receive such messages and automatically update our hostlist URL config | ||
29 | * value). | ||
30 | */ | 25 | */ |
31 | 26 | ||
32 | #include <stdlib.h> | 27 | #include <stdlib.h> |
33 | #include "platform.h" | 28 | #include "platform.h" |
34 | #include "hostlist-client.h" | 29 | #include "hostlist-client.h" |
35 | #include "hostlist-server.h" | ||
36 | #include "gnunet_core_service.h" | 30 | #include "gnunet_core_service.h" |
37 | #include "gnunet_getopt_lib.h" | 31 | #include "gnunet_getopt_lib.h" |
38 | #include "gnunet_protocols.h" | 32 | #include "gnunet_protocols.h" |
@@ -42,12 +36,33 @@ | |||
42 | #include "gnunet_time_lib.h" | 36 | #include "gnunet_time_lib.h" |
43 | #include "gnunet_util_lib.h" | 37 | #include "gnunet_util_lib.h" |
44 | 38 | ||
39 | #if HAVE_MHD | ||
40 | |||
41 | #include "hostlist-server.h" | ||
42 | |||
45 | /** | 43 | /** |
46 | * Set if we are allowed to advertise our hostlist to others. | 44 | * Set if we are allowed to advertise our hostlist to others. |
47 | */ | 45 | */ |
48 | static int advertising; | 46 | static int advertising; |
49 | 47 | ||
50 | /** | 48 | /** |
49 | * Set if the user wants us to run a hostlist server. | ||
50 | */ | ||
51 | static int provide_hostlist; | ||
52 | |||
53 | /** | ||
54 | * Handle to hostlist server's connect handler | ||
55 | */ | ||
56 | static GNUNET_CORE_ConnectEventHandler server_ch = NULL; | ||
57 | |||
58 | /** | ||
59 | * Handle to hostlist server's disconnect handler | ||
60 | */ | ||
61 | static GNUNET_CORE_DisconnectEventHandler server_dh = NULL; | ||
62 | |||
63 | #endif | ||
64 | |||
65 | /** | ||
51 | * Set if we are allowed to learn about peers by accessing | 66 | * Set if we are allowed to learn about peers by accessing |
52 | * hostlist servers. | 67 | * hostlist servers. |
53 | */ | 68 | */ |
@@ -60,11 +75,6 @@ static int bootstrapping; | |||
60 | static int learning; | 75 | static int learning; |
61 | 76 | ||
62 | /** | 77 | /** |
63 | * Set if the user wants us to run a hostlist server. | ||
64 | */ | ||
65 | static int provide_hostlist; | ||
66 | |||
67 | /** | ||
68 | * Statistics handle. | 78 | * Statistics handle. |
69 | */ | 79 | */ |
70 | static struct GNUNET_STATISTICS_Handle *stats; | 80 | static struct GNUNET_STATISTICS_Handle *stats; |
@@ -90,31 +100,25 @@ static GNUNET_CORE_ConnectEventHandler client_ch = NULL; | |||
90 | static GNUNET_CORE_DisconnectEventHandler client_dh = NULL; | 100 | static GNUNET_CORE_DisconnectEventHandler client_dh = NULL; |
91 | 101 | ||
92 | /** | 102 | /** |
93 | * Handle to hostlist server's connect handler | ||
94 | */ | ||
95 | static GNUNET_CORE_ConnectEventHandler server_ch = NULL; | ||
96 | |||
97 | /** | ||
98 | * Handle to hostlist server's disconnect handler | ||
99 | */ | ||
100 | static GNUNET_CORE_DisconnectEventHandler server_dh = NULL; | ||
101 | |||
102 | /** | ||
103 | * gnunet-daemon-hostlist command line options. | 103 | * gnunet-daemon-hostlist command line options. |
104 | */ | 104 | */ |
105 | static struct GNUNET_GETOPT_CommandLineOption options[] = { | 105 | static struct GNUNET_GETOPT_CommandLineOption options[] = { |
106 | #if HAVE_MHD | ||
106 | { 'a', "advertise", NULL, | 107 | { 'a', "advertise", NULL, |
107 | gettext_noop ("advertise our hostlist to other peers"), | 108 | gettext_noop ("advertise our hostlist to other peers"), |
108 | GNUNET_NO, &GNUNET_GETOPT_set_one, &advertising }, | 109 | GNUNET_NO, &GNUNET_GETOPT_set_one, &advertising }, |
110 | #endif | ||
109 | { 'b', "bootstrap", NULL, | 111 | { 'b', "bootstrap", NULL, |
110 | gettext_noop ("bootstrap using hostlists (it is highly recommended that you always use this option)"), | 112 | gettext_noop ("bootstrap using hostlists (it is highly recommended that you always use this option)"), |
111 | GNUNET_NO, &GNUNET_GETOPT_set_one, &bootstrapping }, | 113 | GNUNET_NO, &GNUNET_GETOPT_set_one, &bootstrapping }, |
112 | { 'e', "enable-learning", NULL, | 114 | { 'e', "enable-learning", NULL, |
113 | gettext_noop ("enable learning about hostlist servers from other peers"), | 115 | gettext_noop ("enable learning about hostlist servers from other peers"), |
114 | GNUNET_NO, &GNUNET_GETOPT_set_one, &learning}, | 116 | GNUNET_NO, &GNUNET_GETOPT_set_one, &learning}, |
117 | #if HAVE_MHD | ||
115 | { 'p', "provide-hostlist", NULL, | 118 | { 'p', "provide-hostlist", NULL, |
116 | gettext_noop ("provide a hostlist server"), | 119 | gettext_noop ("provide a hostlist server"), |
117 | GNUNET_NO, &GNUNET_GETOPT_set_one, &provide_hostlist}, | 120 | GNUNET_NO, &GNUNET_GETOPT_set_one, &provide_hostlist}, |
121 | #endif | ||
118 | GNUNET_GETOPT_OPTION_END | 122 | GNUNET_GETOPT_OPTION_END |
119 | }; | 123 | }; |
120 | 124 | ||
@@ -153,10 +157,12 @@ core_init (void *cls, | |||
153 | GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded * | 157 | GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded * |
154 | publicKey) | 158 | publicKey) |
155 | { | 159 | { |
160 | #if HAVE_MHD | ||
156 | if (advertising && (NULL != server)) | 161 | if (advertising && (NULL != server)) |
157 | { | 162 | { |
158 | /* FIXME: provide "server" to 'hostlist' module */ | 163 | /* FIXME: provide "server" to 'hostlist' module */ |
159 | } | 164 | } |
165 | #endif | ||
160 | } | 166 | } |
161 | 167 | ||
162 | /** | 168 | /** |
@@ -192,8 +198,10 @@ connect_handler (void *cls, | |||
192 | "A new peer connected, notifying client and server\n"); | 198 | "A new peer connected, notifying client and server\n"); |
193 | if ( NULL != client_ch) | 199 | if ( NULL != client_ch) |
194 | (*client_ch) (cls, peer, latency, distance); | 200 | (*client_ch) (cls, peer, latency, distance); |
201 | #if HAVE_MHD | ||
195 | if ( NULL != server_ch) | 202 | if ( NULL != server_ch) |
196 | (*server_ch) (cls, peer, latency, distance); | 203 | (*server_ch) (cls, peer, latency, distance); |
204 | #endif | ||
197 | } | 205 | } |
198 | 206 | ||
199 | /** | 207 | /** |
@@ -211,10 +219,11 @@ disconnect_handler (void *cls, | |||
211 | /* call hostlist client disconnect handler*/ | 219 | /* call hostlist client disconnect handler*/ |
212 | if ( NULL != client_dh) | 220 | if ( NULL != client_dh) |
213 | (*client_dh) (cls, peer); | 221 | (*client_dh) (cls, peer); |
214 | 222 | #if HAVE_MHD | |
215 | /* call hostlist server disconnect handler*/ | 223 | /* call hostlist server disconnect handler*/ |
216 | if ( NULL != server_dh) | 224 | if ( NULL != server_dh) |
217 | (*server_dh) (cls, peer); | 225 | (*server_dh) (cls, peer); |
226 | #endif | ||
218 | } | 227 | } |
219 | 228 | ||
220 | /** | 229 | /** |
@@ -230,10 +239,12 @@ cleaning_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
230 | { | 239 | { |
231 | GNUNET_HOSTLIST_client_stop (); | 240 | GNUNET_HOSTLIST_client_stop (); |
232 | } | 241 | } |
242 | #if HAVE_MHD | ||
233 | if (provide_hostlist) | 243 | if (provide_hostlist) |
234 | { | 244 | { |
235 | GNUNET_HOSTLIST_server_stop (); | 245 | GNUNET_HOSTLIST_server_stop (); |
236 | } | 246 | } |
247 | #endif | ||
237 | if (core != NULL) | 248 | if (core != NULL) |
238 | { | 249 | { |
239 | GNUNET_CORE_disconnect (core); | 250 | GNUNET_CORE_disconnect (core); |
@@ -281,8 +292,11 @@ run (void *cls, | |||
281 | const struct GNUNET_CONFIGURATION_Handle * cfg) | 292 | const struct GNUNET_CONFIGURATION_Handle * cfg) |
282 | { | 293 | { |
283 | if ( (! bootstrapping) && | 294 | if ( (! bootstrapping) && |
284 | (! learning) && | 295 | (! learning) |
285 | (! provide_hostlist) ) | 296 | #if HAVE_MHD |
297 | && (! provide_hostlist) | ||
298 | #endif | ||
299 | ) | ||
286 | { | 300 | { |
287 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 301 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
288 | _("None of the functions for the hostlist daemon were enabled. I have no reason to run!\n")); | 302 | _("None of the functions for the hostlist daemon were enabled. I have no reason to run!\n")); |
@@ -304,11 +318,12 @@ run (void *cls, | |||
304 | GNUNET_HOSTLIST_client_start (cfg, sched, stats, | 318 | GNUNET_HOSTLIST_client_start (cfg, sched, stats, |
305 | &client_ch, &client_dh, &client_adv_handler, learning); | 319 | &client_ch, &client_dh, &client_adv_handler, learning); |
306 | } | 320 | } |
321 | #if HAVE_MHD | ||
307 | if (provide_hostlist) | 322 | if (provide_hostlist) |
308 | { | 323 | { |
309 | GNUNET_HOSTLIST_server_start (cfg, sched, stats, core, &server_ch, &server_dh, advertising ); | 324 | GNUNET_HOSTLIST_server_start (cfg, sched, stats, core, &server_ch, &server_dh, advertising ); |
310 | } | 325 | } |
311 | 326 | #endif | |
312 | GNUNET_SCHEDULER_add_delayed (sched, | 327 | GNUNET_SCHEDULER_add_delayed (sched, |
313 | GNUNET_TIME_UNIT_FOREVER_REL, | 328 | GNUNET_TIME_UNIT_FOREVER_REL, |
314 | &cleaning_task, NULL); | 329 | &cleaning_task, NULL); |