aboutsummaryrefslogtreecommitdiff
path: root/src/hostlist/gnunet-daemon-hostlist.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-08-15 21:46:35 +0000
committerChristian Grothoff <christian@grothoff.org>2011-08-15 21:46:35 +0000
commit502af2167f7c218366666ca4944bd7cc54b5b19a (patch)
treea91fec5cc9769d260640bd91c6633cb9cf395524 /src/hostlist/gnunet-daemon-hostlist.c
parent03af5a603b7cc53432249d5854cd412aa90dde0d (diff)
downloadgnunet-502af2167f7c218366666ca4944bd7cc54b5b19a.tar.gz
gnunet-502af2167f7c218366666ca4944bd7cc54b5b19a.zip
indentation
Diffstat (limited to 'src/hostlist/gnunet-daemon-hostlist.c')
-rw-r--r--src/hostlist/gnunet-daemon-hostlist.c177
1 files changed, 86 insertions, 91 deletions
diff --git a/src/hostlist/gnunet-daemon-hostlist.c b/src/hostlist/gnunet-daemon-hostlist.c
index f409dc9a6..c49aec765 100644
--- a/src/hostlist/gnunet-daemon-hostlist.c
+++ b/src/hostlist/gnunet-daemon-hostlist.c
@@ -129,12 +129,9 @@ static struct GNUNET_PeerIdentity me;
129 129
130static void 130static void
131core_init (void *cls, 131core_init (void *cls,
132 struct GNUNET_CORE_Handle * server, 132 struct GNUNET_CORE_Handle *server,
133 const struct GNUNET_PeerIdentity * 133 const struct GNUNET_PeerIdentity *my_identity,
134 my_identity, 134 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
135 const struct
136 GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *
137 publicKey)
138{ 135{
139 me = *my_identity; 136 me = *my_identity;
140} 137}
@@ -142,10 +139,11 @@ core_init (void *cls,
142/** 139/**
143 * Core handler for p2p hostlist advertisements 140 * Core handler for p2p hostlist advertisements
144 */ 141 */
145static int advertisement_handler (void *cls, 142static int
146 const struct GNUNET_PeerIdentity * peer, 143advertisement_handler (void *cls,
147 const struct GNUNET_MessageHeader * message, 144 const struct GNUNET_PeerIdentity *peer,
148 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 145 const struct GNUNET_MessageHeader *message,
146 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
149{ 147{
150 GNUNET_assert (NULL != client_adv_handler); 148 GNUNET_assert (NULL != client_adv_handler);
151 return (*client_adv_handler) (cls, peer, message, atsi); 149 return (*client_adv_handler) (cls, peer, message, atsi);
@@ -162,17 +160,17 @@ static int advertisement_handler (void *cls,
162static void 160static void
163connect_handler (void *cls, 161connect_handler (void *cls,
164 const struct 162 const struct
165 GNUNET_PeerIdentity * peer, 163 GNUNET_PeerIdentity *peer,
166 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 164 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
167{ 165{
168 if (0 == memcmp (&me, peer, sizeof (struct GNUNET_PeerIdentity))) 166 if (0 == memcmp (&me, peer, sizeof (struct GNUNET_PeerIdentity)))
169 return; 167 return;
170 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 168 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
171 "A new peer connected, notifying client and server\n"); 169 "A new peer connected, notifying client and server\n");
172 if ( NULL != client_ch) 170 if (NULL != client_ch)
173 (*client_ch) (cls, peer, atsi); 171 (*client_ch) (cls, peer, atsi);
174#if HAVE_MHD 172#if HAVE_MHD
175 if ( NULL != server_ch) 173 if (NULL != server_ch)
176 (*server_ch) (cls, peer, atsi); 174 (*server_ch) (cls, peer, atsi);
177#endif 175#endif
178} 176}
@@ -184,18 +182,16 @@ connect_handler (void *cls,
184 * @param peer peer identity this notification is about 182 * @param peer peer identity this notification is about
185 */ 183 */
186static void 184static void
187disconnect_handler (void *cls, 185disconnect_handler (void *cls, const struct GNUNET_PeerIdentity *peer)
188 const struct
189 GNUNET_PeerIdentity * peer)
190{ 186{
191 if (0 == memcmp (&me, peer, sizeof (struct GNUNET_PeerIdentity))) 187 if (0 == memcmp (&me, peer, sizeof (struct GNUNET_PeerIdentity)))
192 return; 188 return;
193 /* call hostlist client disconnect handler*/ 189 /* call hostlist client disconnect handler */
194 if ( NULL != client_dh) 190 if (NULL != client_dh)
195 (*client_dh) (cls, peer); 191 (*client_dh) (cls, peer);
196#if HAVE_MHD 192#if HAVE_MHD
197 /* call hostlist server disconnect handler*/ 193 /* call hostlist server disconnect handler */
198 if ( NULL != server_dh) 194 if (NULL != server_dh)
199 (*server_dh) (cls, peer); 195 (*server_dh) (cls, peer);
200#endif 196#endif
201} 197}
@@ -207,29 +203,27 @@ disconnect_handler (void *cls,
207static void 203static void
208cleaning_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 204cleaning_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
209{ 205{
210 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 206 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hostlist daemon is shutting down\n");
211 "Hostlist daemon is shutting down\n");
212 if (core != NULL) 207 if (core != NULL)
213 { 208 {
214 GNUNET_CORE_disconnect (core); 209 GNUNET_CORE_disconnect (core);
215 core = NULL; 210 core = NULL;
216 } 211 }
217 if (bootstrapping) 212 if (bootstrapping)
218 { 213 {
219 GNUNET_HOSTLIST_client_stop (); 214 GNUNET_HOSTLIST_client_stop ();
220 } 215 }
221#if HAVE_MHD 216#if HAVE_MHD
222 if (provide_hostlist) 217 if (provide_hostlist)
223 { 218 {
224 GNUNET_HOSTLIST_server_stop (); 219 GNUNET_HOSTLIST_server_stop ();
225 } 220 }
226#endif 221#endif
227 if (stats != NULL) 222 if (stats != NULL)
228 { 223 {
229 GNUNET_STATISTICS_destroy (stats, 224 GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
230 GNUNET_NO); 225 stats = NULL;
231 stats = NULL; 226 }
232 }
233} 227}
234 228
235 229
@@ -241,67 +235,67 @@ cleaning_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
241 * @param cfgfile name of the configuration file used (for saving, can be NULL!) 235 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
242 * @param cfg configuration 236 * @param cfg configuration
243 */ 237 */
244static void 238static void
245run (void *cls, 239run (void *cls,
246 char *const *args, 240 char *const *args,
247 const char *cfgfile, 241 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
248 const struct GNUNET_CONFIGURATION_Handle * cfg)
249{ 242{
250 static const struct GNUNET_CORE_MessageHandler learn_handlers[] = { 243 static const struct GNUNET_CORE_MessageHandler learn_handlers[] = {
251 { &advertisement_handler, GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT, 0}, 244 {&advertisement_handler, GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT, 0},
252 { NULL, 0, 0 } 245 {NULL, 0, 0}
253 }; 246 };
254 static const struct GNUNET_CORE_MessageHandler no_learn_handlers[] = { 247 static const struct GNUNET_CORE_MessageHandler no_learn_handlers[] = {
255 { NULL, 0, 0 } 248 {NULL, 0, 0}
256 }; 249 };
257 if ( (! bootstrapping) && 250 if ((!bootstrapping) && (!learning)
258 (! learning)
259#if HAVE_MHD 251#if HAVE_MHD
260 && (! provide_hostlist) 252 && (!provide_hostlist)
261#endif 253#endif
262 ) 254 )
263 { 255 {
264 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 256 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
265 _("None of the functions for the hostlist daemon were enabled. I have no reason to run!\n")); 257 _
266 return; 258 ("None of the functions for the hostlist daemon were enabled. I have no reason to run!\n"));
267 } 259 return;
260 }
268 261
269 262
270 263
271 stats = GNUNET_STATISTICS_create ("hostlist", cfg); 264 stats = GNUNET_STATISTICS_create ("hostlist", cfg);
272 265
273 core = GNUNET_CORE_connect (cfg, 266 core = GNUNET_CORE_connect (cfg,
274 1, 267 1,
275 NULL, 268 NULL,
276 &core_init, 269 &core_init,
277 &connect_handler, &disconnect_handler, NULL, 270 &connect_handler, &disconnect_handler, NULL,
278 NULL, GNUNET_NO, 271 NULL, GNUNET_NO,
279 NULL, GNUNET_NO, 272 NULL, GNUNET_NO,
280 learning? learn_handlers : no_learn_handlers); 273 learning ? learn_handlers : no_learn_handlers);
281 274
282 if (bootstrapping) 275 if (bootstrapping)
283 { 276 {
284 GNUNET_HOSTLIST_client_start (cfg, stats, 277 GNUNET_HOSTLIST_client_start (cfg, stats,
285 &client_ch, &client_dh, &client_adv_handler, learning); 278 &client_ch, &client_dh, &client_adv_handler,
286 } 279 learning);
280 }
287 281
288 #if HAVE_MHD 282#if HAVE_MHD
289 if (provide_hostlist) 283 if (provide_hostlist)
290 { 284 {
291 GNUNET_HOSTLIST_server_start (cfg, stats, core, &server_ch, &server_dh, advertising ); 285 GNUNET_HOSTLIST_server_start (cfg, stats, core, &server_ch, &server_dh,
292 } 286 advertising);
287 }
293#endif 288#endif
294 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 289 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
295 &cleaning_task, NULL); 290 &cleaning_task, NULL);
296 291
297 if (NULL == core) 292 if (NULL == core)
298 { 293 {
299 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 294 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
300 _("Failed to connect to `%s' service.\n"), 295 _("Failed to connect to `%s' service.\n"), "core");
301 "core"); 296 GNUNET_SCHEDULER_shutdown ();
302 GNUNET_SCHEDULER_shutdown (); 297 return;
303 return; 298 }
304 }
305} 299}
306 300
307 301
@@ -317,33 +311,34 @@ main (int argc, char *const *argv)
317{ 311{
318 static const struct GNUNET_GETOPT_CommandLineOption options[] = { 312 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
319#if HAVE_MHD 313#if HAVE_MHD
320 { 'a', "advertise", NULL, 314 {'a', "advertise", NULL,
321 gettext_noop ("advertise our hostlist to other peers"), 315 gettext_noop ("advertise our hostlist to other peers"),
322 GNUNET_NO, &GNUNET_GETOPT_set_one, &advertising }, 316 GNUNET_NO, &GNUNET_GETOPT_set_one, &advertising},
323#endif 317#endif
324 { 'b', "bootstrap", NULL, 318 {'b', "bootstrap", NULL,
325 gettext_noop ("bootstrap using hostlists (it is highly recommended that you always use this option)"), 319 gettext_noop
326 GNUNET_NO, &GNUNET_GETOPT_set_one, &bootstrapping }, 320 ("bootstrap using hostlists (it is highly recommended that you always use this option)"),
327 { 'e', "enable-learning", NULL, 321 GNUNET_NO, &GNUNET_GETOPT_set_one, &bootstrapping},
328 gettext_noop ("enable learning about hostlist servers from other peers"), 322 {'e', "enable-learning", NULL,
329 GNUNET_NO, &GNUNET_GETOPT_set_one, &learning}, 323 gettext_noop ("enable learning about hostlist servers from other peers"),
324 GNUNET_NO, &GNUNET_GETOPT_set_one, &learning},
330#if HAVE_MHD 325#if HAVE_MHD
331 { 'p', "provide-hostlist", NULL, 326 {'p', "provide-hostlist", NULL,
332 gettext_noop ("provide a hostlist server"), 327 gettext_noop ("provide a hostlist server"),
333 GNUNET_NO, &GNUNET_GETOPT_set_one, &provide_hostlist}, 328 GNUNET_NO, &GNUNET_GETOPT_set_one, &provide_hostlist},
334#endif 329#endif
335 GNUNET_GETOPT_OPTION_END 330 GNUNET_GETOPT_OPTION_END
336 }; 331 };
337 332
338 int ret; 333 int ret;
334
339 GNUNET_log_setup ("hostlist", "WARNING", NULL); 335 GNUNET_log_setup ("hostlist", "WARNING", NULL);
340 ret = (GNUNET_OK == 336 ret = (GNUNET_OK ==
341 GNUNET_PROGRAM_run (argc, 337 GNUNET_PROGRAM_run (argc,
342 argv, 338 argv,
343 "hostlist", 339 "hostlist",
344 _("GNUnet hostlist server and client"), 340 _("GNUnet hostlist server and client"),
345 options, 341 options, &run, NULL)) ? 0 : 1;
346 &run, NULL)) ? 0 : 1;
347 342
348 return ret; 343 return ret;
349} 344}