aboutsummaryrefslogtreecommitdiff
path: root/src/hostlist/hostlist-server.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/hostlist/hostlist-server.c')
-rw-r--r--src/hostlist/hostlist-server.c125
1 files changed, 53 insertions, 72 deletions
diff --git a/src/hostlist/hostlist-server.c b/src/hostlist/hostlist-server.c
index e30b3c1e0..e48b6a4ac 100644
--- a/src/hostlist/hostlist-server.c
+++ b/src/hostlist/hostlist-server.c
@@ -123,15 +123,15 @@ finish_response (struct HostSet *results)
123 "Creating hostlist response with %u bytes\n", 123 "Creating hostlist response with %u bytes\n",
124 (unsigned int) results->size); 124 (unsigned int) results->size);
125#endif 125#endif
126 response = MHD_create_response_from_data (results->size, 126 response =
127 results->data, MHD_YES, MHD_NO); 127 MHD_create_response_from_data (results->size, results->data, MHD_YES,
128 MHD_NO);
128 if ((daemon_handle_v4 == NULL) && (daemon_handle_v6 == NULL)) 129 if ((daemon_handle_v4 == NULL) && (daemon_handle_v6 == NULL))
129 { 130 {
130 MHD_destroy_response (response); 131 MHD_destroy_response (response);
131 response = NULL; 132 response = NULL;
132 } 133 }
133 GNUNET_STATISTICS_set (stats, 134 GNUNET_STATISTICS_set (stats, gettext_noop ("bytes in hostlist"),
134 gettext_noop ("bytes in hostlist"),
135 results->size, GNUNET_YES); 135 results->size, GNUNET_YES);
136 GNUNET_free (results); 136 GNUNET_free (results);
137} 137}
@@ -148,18 +148,17 @@ finish_response (struct HostSet *results)
148 * @return GNUNET_SYSERR to stop iterating (unless expiration has occured) 148 * @return GNUNET_SYSERR to stop iterating (unless expiration has occured)
149 */ 149 */
150static int 150static int
151check_has_addr (void *cls, 151check_has_addr (void *cls, const char *tname,
152 const char *tname, 152 struct GNUNET_TIME_Absolute expiration, const void *addr,
153 struct GNUNET_TIME_Absolute expiration, 153 uint16_t addrlen)
154 const void *addr, uint16_t addrlen)
155{ 154{
156 int *arg = cls; 155 int *arg = cls;
157 156
158 if (GNUNET_TIME_absolute_get_remaining (expiration).rel_value == 0) 157 if (GNUNET_TIME_absolute_get_remaining (expiration).rel_value == 0)
159 { 158 {
160 GNUNET_STATISTICS_update (stats, 159 GNUNET_STATISTICS_update (stats,
161 gettext_noop ("expired addresses encountered"), 160 gettext_noop ("expired addresses encountered"), 1,
162 1, GNUNET_YES); 161 GNUNET_YES);
163 return GNUNET_YES; /* ignore this address */ 162 return GNUNET_YES; /* ignore this address */
164 } 163 }
165 *arg = GNUNET_YES; 164 *arg = GNUNET_YES;
@@ -172,8 +171,7 @@ check_has_addr (void *cls,
172 * hostlist response construction. 171 * hostlist response construction.
173 */ 172 */
174static void 173static void
175host_processor (void *cls, 174host_processor (void *cls, const struct GNUNET_PeerIdentity *peer,
176 const struct GNUNET_PeerIdentity *peer,
177 const struct GNUNET_HELLO_Message *hello, const char *err_msg) 175 const struct GNUNET_HELLO_Message *hello, const char *err_msg)
178{ 176{
179 struct HostSet *results = cls; 177 struct HostSet *results = cls;
@@ -229,8 +227,8 @@ host_processor (void *cls,
229 } 227 }
230#if DEBUG_HOSTLIST_SERVER 228#if DEBUG_HOSTLIST_SERVER
231 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 229 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
232 "Adding peer `%s' to hostlist (%u bytes)\n", 230 "Adding peer `%s' to hostlist (%u bytes)\n", GNUNET_i2s (peer),
233 GNUNET_i2s (peer), (unsigned int) s); 231 (unsigned int) s);
234#endif 232#endif
235 GNUNET_array_grow (results->data, results->size, old + s); 233 GNUNET_array_grow (results->data, results->size, old + s);
236 memcpy (&results->data[old], hello, s); 234 memcpy (&results->data[old], hello, s);
@@ -242,8 +240,8 @@ host_processor (void *cls,
242 * Hostlist access policy (very permissive, allows everything). 240 * Hostlist access policy (very permissive, allows everything).
243 */ 241 */
244static int 242static int
245accept_policy_callback (void *cls, 243accept_policy_callback (void *cls, const struct sockaddr *addr,
246 const struct sockaddr *addr, socklen_t addrlen) 244 socklen_t addrlen)
247{ 245{
248 if (NULL == response) 246 if (NULL == response)
249 { 247 {
@@ -261,12 +259,9 @@ accept_policy_callback (void *cls,
261 * Main request handler. 259 * Main request handler.
262 */ 260 */
263static int 261static int
264access_handler_callback (void *cls, 262access_handler_callback (void *cls, struct MHD_Connection *connection,
265 struct MHD_Connection *connection, 263 const char *url, const char *method,
266 const char *url, 264 const char *version, const char *upload_data,
267 const char *method,
268 const char *version,
269 const char *upload_data,
270 size_t * upload_data_size, void **con_cls) 265 size_t * upload_data_size, void **con_cls)
271{ 266{
272 static int dummy; 267 static int dummy;
@@ -312,8 +307,7 @@ access_handler_callback (void *cls,
312 return MHD_NO; /* internal error, no response yet */ 307 return MHD_NO; /* internal error, no response yet */
313 } 308 }
314 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Received request for our hostlist\n")); 309 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Received request for our hostlist\n"));
315 GNUNET_STATISTICS_update (stats, 310 GNUNET_STATISTICS_update (stats, gettext_noop ("hostlist requests processed"),
316 gettext_noop ("hostlist requests processed"),
317 1, GNUNET_YES); 311 1, GNUNET_YES);
318 return MHD_queue_response (connection, MHD_HTTP_OK, response); 312 return MHD_queue_response (connection, MHD_HTTP_OK, response);
319} 313}
@@ -353,11 +347,11 @@ adv_transmit_ready (void *cls, size_t size, void *buf)
353 "Sent advertisement message: Copied %u bytes into buffer!\n", 347 "Sent advertisement message: Copied %u bytes into buffer!\n",
354 (unsigned int) transmission_size); 348 (unsigned int) transmission_size);
355 hostlist_adv_count++; 349 hostlist_adv_count++;
356 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 350 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " # Sent advertisement message: %u\n",
357 " # Sent advertisement message: %u\n", hostlist_adv_count); 351 hostlist_adv_count);
358 GNUNET_STATISTICS_update (stats, 352 GNUNET_STATISTICS_update (stats,
359 gettext_noop ("# hostlist advertisements send"), 353 gettext_noop ("# hostlist advertisements send"), 1,
360 1, GNUNET_NO); 354 GNUNET_NO);
361 return transmission_size; 355 return transmission_size;
362} 356}
363 357
@@ -370,9 +364,7 @@ adv_transmit_ready (void *cls, size_t size, void *buf)
370 * @param atsi performance data 364 * @param atsi performance data
371 */ 365 */
372static void 366static void
373connect_handler (void *cls, 367connect_handler (void *cls, const struct GNUNET_PeerIdentity *peer,
374 const struct
375 GNUNET_PeerIdentity *peer,
376 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 368 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
377{ 369{
378 size_t size; 370 size_t size;
@@ -397,13 +389,10 @@ connect_handler (void *cls,
397 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 389 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
398 "Asked core to transmit advertisement message with a size of %u bytes to peer `%s'\n", 390 "Asked core to transmit advertisement message with a size of %u bytes to peer `%s'\n",
399 size, GNUNET_i2s (peer)); 391 size, GNUNET_i2s (peer));
400 if (NULL == GNUNET_CORE_notify_transmit_ready (core, 392 if (NULL ==
401 GNUNET_YES, 393 GNUNET_CORE_notify_transmit_ready (core, GNUNET_YES, 0,
402 0, 394 GNUNET_ADV_TIMEOUT, peer, size,
403 GNUNET_ADV_TIMEOUT, 395 &adv_transmit_ready, NULL))
404 peer,
405 size,
406 &adv_transmit_ready, NULL))
407 { 396 {
408 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 397 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
409 _("Advertisement message could not be queued by core\n")); 398 _("Advertisement message could not be queued by core\n"));
@@ -433,8 +422,7 @@ disconnect_handler (void *cls, const struct GNUNET_PeerIdentity *peer)
433 * @param err_msg NULL if successful, otherwise contains error message 422 * @param err_msg NULL if successful, otherwise contains error message
434 */ 423 */
435static void 424static void
436process_notify (void *cls, 425process_notify (void *cls, const struct GNUNET_PeerIdentity *peer,
437 const struct GNUNET_PeerIdentity *peer,
438 const struct GNUNET_HELLO_Message *hello, const char *err_msg) 426 const struct GNUNET_HELLO_Message *hello, const char *err_msg)
439{ 427{
440 struct HostSet *results; 428 struct HostSet *results;
@@ -451,18 +439,17 @@ process_notify (void *cls,
451 } 439 }
452 results = GNUNET_malloc (sizeof (struct HostSet)); 440 results = GNUNET_malloc (sizeof (struct HostSet));
453 GNUNET_assert (peerinfo != NULL); 441 GNUNET_assert (peerinfo != NULL);
454 pitr = GNUNET_PEERINFO_iterate (peerinfo, 442 pitr =
455 NULL, 443 GNUNET_PEERINFO_iterate (peerinfo, NULL, GNUNET_TIME_UNIT_MINUTES,
456 GNUNET_TIME_UNIT_MINUTES, 444 &host_processor, results);
457 &host_processor, results);
458} 445}
459 446
460/** 447/**
461 * Function that queries MHD's select sets and 448 * Function that queries MHD's select sets and
462 * starts the task waiting for them. 449 * starts the task waiting for them.
463 */ 450 */
464static GNUNET_SCHEDULER_TaskIdentifier 451static GNUNET_SCHEDULER_TaskIdentifier prepare_daemon (struct MHD_Daemon
465prepare_daemon (struct MHD_Daemon *daemon_handle); 452 *daemon_handle);
466 453
467 454
468/** 455/**
@@ -524,9 +511,10 @@ prepare_daemon (struct MHD_Daemon *daemon_handle)
524 GNUNET_NETWORK_fdset_copy_native (wrs, &rs, max + 1); 511 GNUNET_NETWORK_fdset_copy_native (wrs, &rs, max + 1);
525 GNUNET_NETWORK_fdset_copy_native (wws, &ws, max + 1); 512 GNUNET_NETWORK_fdset_copy_native (wws, &ws, max + 1);
526 GNUNET_NETWORK_fdset_copy_native (wes, &es, max + 1); 513 GNUNET_NETWORK_fdset_copy_native (wes, &es, max + 1);
527 ret = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH, 514 ret =
528 GNUNET_SCHEDULER_NO_TASK, 515 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH,
529 tv, wrs, wws, &run_daemon, daemon_handle); 516 GNUNET_SCHEDULER_NO_TASK, tv, wrs, wws,
517 &run_daemon, daemon_handle);
530 GNUNET_NETWORK_fdset_destroy (wrs); 518 GNUNET_NETWORK_fdset_destroy (wrs);
531 GNUNET_NETWORK_fdset_destroy (wws); 519 GNUNET_NETWORK_fdset_destroy (wws);
532 GNUNET_NETWORK_fdset_destroy (wes); 520 GNUNET_NETWORK_fdset_destroy (wes);
@@ -568,9 +556,9 @@ GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c,
568 _("Could not access PEERINFO service. Exiting.\n")); 556 _("Could not access PEERINFO service. Exiting.\n"));
569 return GNUNET_SYSERR; 557 return GNUNET_SYSERR;
570 } 558 }
571 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, 559 if (GNUNET_OK !=
572 "HOSTLIST", 560 GNUNET_CONFIGURATION_get_value_number (cfg, "HOSTLIST", "HTTPPORT",
573 "HTTPPORT", &port)) 561 &port))
574 return GNUNET_SYSERR; 562 return GNUNET_SYSERR;
575 if ((port == 0) || (port > UINT16_MAX)) 563 if ((port == 0) || (port > UINT16_MAX))
576 { 564 {
@@ -579,14 +567,13 @@ GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c,
579 return GNUNET_SYSERR; 567 return GNUNET_SYSERR;
580 } 568 }
581 569
582 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg, 570 if (GNUNET_SYSERR ==
583 "HOSTLIST", 571 GNUNET_CONFIGURATION_get_value_string (cfg, "HOSTLIST",
584 "EXTERNAL_DNS_NAME", 572 "EXTERNAL_DNS_NAME", &hostname))
585 &hostname))
586 hostname = GNUNET_RESOLVER_local_fqdn_get (); 573 hostname = GNUNET_RESOLVER_local_fqdn_get ();
587 574
588 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 575 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Hostlist service starts on %s:%llu\n"),
589 _("Hostlist service starts on %s:%llu\n"), hostname, port); 576 hostname, port);
590 if (NULL != hostname) 577 if (NULL != hostname)
591 { 578 {
592 size = strlen (hostname); 579 size = strlen (hostname);
@@ -596,8 +583,8 @@ GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c,
596 } 583 }
597 else 584 else
598 { 585 {
599 GNUNET_asprintf (&hostlist_uri, 586 GNUNET_asprintf (&hostlist_uri, "http://%s:%u/", hostname,
600 "http://%s:%u/", hostname, (unsigned int) port); 587 (unsigned int) port);
601 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 588 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
602 _("Address to obtain hostlist: `%s'\n"), hostlist_uri); 589 _("Address to obtain hostlist: `%s'\n"), hostlist_uri);
603 } 590 }
@@ -607,12 +594,9 @@ GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c,
607#if DEBUG_HOSTLIST_SERVER 594#if DEBUG_HOSTLIST_SERVER
608 | MHD_USE_DEBUG 595 | MHD_USE_DEBUG
609#endif 596#endif
610 , 597 , (unsigned short) port,
611 (unsigned short) port, 598 &accept_policy_callback, NULL,
612 &accept_policy_callback, 599 &access_handler_callback, NULL,
613 NULL,
614 &access_handler_callback,
615 NULL,
616 MHD_OPTION_CONNECTION_LIMIT, 600 MHD_OPTION_CONNECTION_LIMIT,
617 (unsigned int) 16, 601 (unsigned int) 16,
618 MHD_OPTION_PER_IP_CONNECTION_LIMIT, 602 MHD_OPTION_PER_IP_CONNECTION_LIMIT,
@@ -625,12 +609,9 @@ GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c,
625#if DEBUG_HOSTLIST_SERVER 609#if DEBUG_HOSTLIST_SERVER
626 | MHD_USE_DEBUG 610 | MHD_USE_DEBUG
627#endif 611#endif
628 , 612 , (unsigned short) port,
629 (unsigned short) port, 613 &accept_policy_callback, NULL,
630 &accept_policy_callback, 614 &access_handler_callback, NULL,
631 NULL,
632 &access_handler_callback,
633 NULL,
634 MHD_OPTION_CONNECTION_LIMIT, 615 MHD_OPTION_CONNECTION_LIMIT,
635 (unsigned int) 16, 616 (unsigned int) 16,
636 MHD_OPTION_PER_IP_CONNECTION_LIMIT, 617 MHD_OPTION_PER_IP_CONNECTION_LIMIT,