2 This file is part of GNUnet.
3 (C) 2008, 2009, 2010, 2014 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 3, 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_server.c
23 * @author Christian Grothoff
24 * @author Matthias Wachs
25 * @author David Barksdale
26 * @brief application to provide an integrated hostlist HTTP server
29 #include <microhttpd.h>
30 #include "gnunet-daemon-hostlist_server.h"
31 #include "gnunet_hello_lib.h"
32 #include "gnunet_peerinfo_service.h"
33 #include "gnunet-daemon-hostlist.h"
34 #include "gnunet_resolver_service.h"
38 * How long until our hostlist advertisment transmission via CORE should
41 #define GNUNET_ADV_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5)
45 * Handle to the HTTP server as provided by libmicrohttpd for IPv6.
47 static struct MHD_Daemon *daemon_handle_v6;
50 * Handle to the HTTP server as provided by libmicrohttpd for IPv4.
52 static struct MHD_Daemon *daemon_handle_v4;
57 static const struct GNUNET_CONFIGURATION_Handle *cfg;
60 * For keeping statistics.
62 static struct GNUNET_STATISTICS_Handle *stats;
65 * Handle to the core service (NULL until we've connected to it).
67 static struct GNUNET_CORE_Handle *core;
70 * Handle to the peerinfo notify service (NULL until we've connected to it).
72 static struct GNUNET_PEERINFO_NotifyContext *notify;
75 * Our primary task for IPv4.
77 static GNUNET_SCHEDULER_TaskIdentifier hostlist_task_v4;
80 * Our primary task for IPv6.
82 static GNUNET_SCHEDULER_TaskIdentifier hostlist_task_v6;
85 * Our canonical response.
87 static struct MHD_Response *response;
90 * Handle for accessing peerinfo service.
92 static struct GNUNET_PEERINFO_Handle *peerinfo;
95 * Set if we are allowed to advertise our hostlist to others.
97 static int advertising;
100 * Buffer for the hostlist address
102 static char *hostlist_uri;
105 * Map of peer identities to `struct GNUNET_CORE_TransmitHandle *` for
106 * pending hostlist server advertisements.
108 static struct GNUNET_CONTAINER_MultiPeerMap *advertisements;
112 * Context for #host_processor().
117 * Iterator used to build @e data (NULL when done).
119 struct GNUNET_PEERINFO_IteratorContext *pitr;
122 * Place where we accumulate all of the HELLO messages.
127 * Number of bytes in @e data.
135 * NULL if we are not currenlty iterating over peer information.
137 static struct HostSet *builder;
141 * Add headers to a request indicating that we allow Cross-Origin Resource
144 * @param response response to add headers to
147 add_cors_headers (struct MHD_Response *response)
149 MHD_add_response_header (response,
150 "Access-Control-Allow-Origin",
152 MHD_add_response_header (response,
153 "Access-Control-Allow-Methods",
155 MHD_add_response_header (response,
156 "Access-Control-Max-Age",
162 * Function that assembles our response.
167 if (NULL != response)
168 MHD_destroy_response (response);
169 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
170 "Creating hostlist response with %u bytes\n",
171 (unsigned int) builder->size);
173 MHD_create_response_from_data (builder->size, builder->data, MHD_YES,
175 add_cors_headers (response);
176 if ((NULL == daemon_handle_v4) && (NULL == daemon_handle_v6))
178 MHD_destroy_response (response);
181 GNUNET_STATISTICS_set (stats, gettext_noop ("bytes in hostlist"),
182 builder->size, GNUNET_YES);
183 GNUNET_free (builder);
189 * Set @a cls to #GNUNET_YES (we have an address!).
191 * @param cls closure, an `int *`
192 * @param address the address (ignored)
193 * @param expiration expiration time (call is ignored if this is in the past)
194 * @return #GNUNET_SYSERR to stop iterating (unless expiration has occured)
197 check_has_addr (void *cls,
198 const struct GNUNET_HELLO_Address *address,
199 struct GNUNET_TIME_Absolute expiration)
203 if (0 == GNUNET_TIME_absolute_get_remaining (expiration).rel_value_us)
205 GNUNET_STATISTICS_update (stats,
206 gettext_noop ("expired addresses encountered"), 1,
208 return GNUNET_YES; /* ignore this address */
211 return GNUNET_SYSERR;
216 * Callback that processes each of the known HELLOs for the
217 * hostlist response construction.
219 * @param cls closure, NULL
220 * @param peer id of the peer, NULL for last call
221 * @param hello hello message for the peer (can be NULL)
222 * @param err_msg message
225 host_processor (void *cls,
226 const struct GNUNET_PeerIdentity *peer,
227 const struct GNUNET_HELLO_Message *hello,
236 GNUNET_assert (NULL == peer);
237 builder->pitr = NULL;
238 GNUNET_free_non_null (builder->data);
239 GNUNET_free (builder);
240 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
241 _("Error in communication with PEERINFO service: %s\n"),
247 builder->pitr = NULL;
253 has_addr = GNUNET_NO;
254 GNUNET_HELLO_iterate_addresses (hello,
258 if (GNUNET_NO == has_addr)
260 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
261 "HELLO for peer `%4s' has no address, not suitable for hostlist!\n",
263 GNUNET_STATISTICS_update (stats,
265 ("HELLOs without addresses encountered (ignored)"),
270 s = GNUNET_HELLO_size (hello);
271 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
272 "Received %u bytes of `%s' from peer `%s' for hostlist.\n",
276 if ( (old + s >= GNUNET_MAX_MALLOC_CHECKED) ||
277 (old + s >= MAX_BYTES_PER_HOSTLISTS) )
279 /* too large, skip! */
280 GNUNET_STATISTICS_update (stats,
282 ("bytes not included in hostlist (size limit)"),
286 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
287 "Adding peer `%s' to hostlist (%u bytes)\n",
290 GNUNET_array_grow (builder->data,
293 memcpy (&builder->data[old],
300 * Hostlist access policy (very permissive, allows everything).
301 * Returns #MHD_NO only if we are not yet ready to serve.
304 * @param addr address information from the client
305 * @param addrlen length of @a addr
306 * @return #MHD_YES if connection is allowed, #MHD_NO if not (we are not ready)
309 accept_policy_callback (void *cls,
310 const struct sockaddr *addr,
313 if (NULL == response)
315 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
316 "Received request for hostlist, but I am not yet ready; rejecting!\n");
319 return MHD_YES; /* accept all */
324 * Main request handler.
326 * @param cls argument given together with the function
327 * pointer when the handler was registered with MHD
329 * @param url the requested url
330 * @param method the HTTP method used (#MHD_HTTP_METHOD_GET,
331 * #MHD_HTTP_METHOD_PUT, etc.)
332 * @param version the HTTP version string (i.e.
333 * #MHD_HTTP_VERSION_1_1)
334 * @param upload_data the data being uploaded (excluding HEADERS,
335 * for a POST that fits into memory and that is encoded
336 * with a supported encoding, the POST data will NOT be
337 * given in upload_data and is instead available as
338 * part of #MHD_get_connection_values; very large POST
339 * data *will* be made available incrementally in
341 * @param upload_data_size set initially to the size of the
342 * @a upload_data provided; the method must update this
343 * value to the number of bytes NOT processed;
344 * @param con_cls pointer that the callback can set to some
345 * address and that will be preserved by MHD for future
346 * calls for this request; since the access handler may
347 * be called many times (i.e., for a PUT/POST operation
348 * with plenty of upload data) this allows the application
349 * to easily associate some request-specific state.
350 * If necessary, this state can be cleaned up in the
351 * global #MHD_RequestCompletedCallback (which
352 * can be set with the #MHD_OPTION_NOTIFY_COMPLETED).
353 * Initially, `*con_cls` will be NULL.
354 * @return #MHD_YES if the connection was handled successfully,
355 * #MHD_NO if the socket must be closed due to a serios
356 * error while handling the request
359 access_handler_callback (void *cls,
360 struct MHD_Connection *connection,
364 const char *upload_data,
365 size_t *upload_data_size,
370 /* CORS pre-flight request */
371 if (0 == strcmp (MHD_HTTP_METHOD_OPTIONS, method))
373 struct MHD_Response *options_response;
376 options_response = MHD_create_response_from_buffer (0, NULL,
377 MHD_RESPMEM_PERSISTENT);
378 add_cors_headers(options_response);
379 rc = MHD_queue_response (connection, MHD_HTTP_OK, options_response);
380 MHD_destroy_response (options_response);
383 if (0 != strcmp (method, MHD_HTTP_METHOD_GET))
385 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
386 _("Refusing `%s' request to hostlist server\n"), method);
387 GNUNET_STATISTICS_update (stats,
389 ("hostlist requests refused (not HTTP GET)"), 1,
393 if (NULL == *con_cls)
396 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
397 "Sending 100 CONTINUE reply\n");
398 return MHD_YES; /* send 100 continue */
400 if (0 != *upload_data_size)
402 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
403 _("Refusing `%s' request with %llu bytes of upload data\n"),
404 method, (unsigned long long) *upload_data_size);
405 GNUNET_STATISTICS_update (stats,
407 ("hostlist requests refused (upload data)"), 1,
409 return MHD_NO; /* do not support upload data */
411 if (NULL == response)
413 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
414 _("Could not handle hostlist request since I do not have a response yet\n"));
415 GNUNET_STATISTICS_update (stats,
417 ("hostlist requests refused (not ready)"), 1,
419 return MHD_NO; /* internal error, no response yet */
421 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
422 _("Received request for our hostlist\n"));
423 GNUNET_STATISTICS_update (stats,
424 gettext_noop ("hostlist requests processed"),
426 return MHD_queue_response (connection, MHD_HTTP_OK, response);
431 * Handler called by CORE when CORE is ready to transmit message
434 * @param size size of buffer to copy message to
435 * @param buf buffer to copy message to
436 * @return number of bytes copied to @a buf
439 adv_transmit_ready (void *cls,
443 static uint64_t hostlist_adv_count;
444 size_t transmission_size;
445 size_t uri_size; /* Including \0 termination! */
446 struct GNUNET_MessageHeader header;
451 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
452 "Transmission failed, buffer invalid!\n");
455 uri_size = strlen (hostlist_uri) + 1;
456 transmission_size = sizeof (struct GNUNET_MessageHeader) + uri_size;
457 header.type = htons (GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT);
458 header.size = htons (transmission_size);
459 GNUNET_assert (size >= transmission_size);
462 sizeof (struct GNUNET_MessageHeader));
464 memcpy (&cbuf[sizeof (struct GNUNET_MessageHeader)],
467 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
468 "Sent advertisement message: Copied %u bytes into buffer!\n",
469 (unsigned int) transmission_size);
470 hostlist_adv_count++;
471 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
472 " # Sent advertisement message: %u\n",
474 GNUNET_STATISTICS_update (stats,
475 gettext_noop ("# hostlist advertisements send"), 1,
477 return transmission_size;
482 * Method called whenever a given peer connects.
485 * @param peer peer identity this notification is about
488 connect_handler (void *cls,
489 const struct GNUNET_PeerIdentity *peer)
492 struct GNUNET_CORE_TransmitHandle *th;
496 if (NULL == hostlist_uri)
498 size = strlen (hostlist_uri) + 1;
499 if (size + sizeof (struct GNUNET_MessageHeader) >=
500 GNUNET_SERVER_MAX_MESSAGE_SIZE)
505 size += sizeof (struct GNUNET_MessageHeader);
511 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
512 "Asked CORE to transmit advertisement message with a size of %u bytes to peer `%s'\n",
516 (th = GNUNET_CORE_notify_transmit_ready (core, GNUNET_YES,
517 GNUNET_CORE_PRIO_BEST_EFFORT,
521 &adv_transmit_ready, NULL)) )
523 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
524 _("Advertisement message could not be queued by core\n"));
526 GNUNET_assert (GNUNET_YES ==
527 GNUNET_CONTAINER_multipeermap_put (advertisements,
530 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
535 * Method called whenever a given peer disconnects.
538 * @param peer peer identity this notification is about
541 disconnect_handler (void *cls,
542 const struct GNUNET_PeerIdentity *peer)
544 struct GNUNET_CORE_TransmitHandle *th;
548 th = GNUNET_CONTAINER_multipeermap_get (advertisements,
552 GNUNET_assert (GNUNET_YES ==
553 GNUNET_CONTAINER_multipeermap_remove (advertisements,
556 GNUNET_CORE_notify_transmit_ready_cancel (th);
561 * PEERINFO calls this function to let us know about a possible peer
562 * that we might want to connect to.
564 * @param cls closure (not used)
565 * @param peer potential peer to connect to
566 * @param hello HELLO for this peer (or NULL)
567 * @param err_msg NULL if successful, otherwise contains error message
570 process_notify (void *cls,
571 const struct GNUNET_PeerIdentity *peer,
572 const struct GNUNET_HELLO_Message *hello,
575 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
576 "Peerinfo is notifying us to rebuild our hostlist\n");
578 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
579 _("Error in communication with PEERINFO service: %s\n"),
583 /* restart re-build already in progress ... */
584 if (NULL != builder->pitr)
586 GNUNET_PEERINFO_iterate_cancel (builder->pitr);
587 builder->pitr = NULL;
589 GNUNET_free_non_null (builder->data);
591 builder->data = NULL;
595 builder = GNUNET_new (struct HostSet);
597 GNUNET_assert (NULL != peerinfo);
599 = GNUNET_PEERINFO_iterate (peerinfo,
601 GNUNET_TIME_UNIT_MINUTES,
602 &host_processor, NULL);
607 * Function that queries MHD's select sets and
608 * starts the task waiting for them.
610 static GNUNET_SCHEDULER_TaskIdentifier
611 prepare_daemon (struct MHD_Daemon *daemon_handle);
615 * Call MHD to process pending requests and then go back
616 * and schedule the next run.
618 * @param cls the `struct MHD_Daemon` of the HTTP server to run
619 * @param tc scheduler context
622 run_daemon (void *cls,
623 const struct GNUNET_SCHEDULER_TaskContext *tc)
625 struct MHD_Daemon *daemon_handle = cls;
627 if (daemon_handle == daemon_handle_v4)
628 hostlist_task_v4 = GNUNET_SCHEDULER_NO_TASK;
630 hostlist_task_v6 = GNUNET_SCHEDULER_NO_TASK;
632 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
634 GNUNET_assert (MHD_YES == MHD_run (daemon_handle));
635 if (daemon_handle == daemon_handle_v4)
636 hostlist_task_v4 = prepare_daemon (daemon_handle);
638 hostlist_task_v6 = prepare_daemon (daemon_handle);
643 * Function that queries MHD's select sets and
644 * starts the task waiting for them.
646 * @param daemon_handle HTTP server to prepare to run
648 static GNUNET_SCHEDULER_TaskIdentifier
649 prepare_daemon (struct MHD_Daemon *daemon_handle)
651 GNUNET_SCHEDULER_TaskIdentifier ret;
655 struct GNUNET_NETWORK_FDSet *wrs;
656 struct GNUNET_NETWORK_FDSet *wws;
658 MHD_UNSIGNED_LONG_LONG timeout;
660 struct GNUNET_TIME_Relative tv;
665 wrs = GNUNET_NETWORK_fdset_create ();
666 wws = GNUNET_NETWORK_fdset_create ();
668 GNUNET_assert (MHD_YES == MHD_get_fdset (daemon_handle, &rs, &ws, &es, &max));
669 haveto = MHD_get_timeout (daemon_handle, &timeout);
670 if (haveto == MHD_YES)
671 tv.rel_value_us = (uint64_t) timeout * 1000LL;
673 tv = GNUNET_TIME_UNIT_FOREVER_REL;
674 GNUNET_NETWORK_fdset_copy_native (wrs, &rs, max + 1);
675 GNUNET_NETWORK_fdset_copy_native (wws, &ws, max + 1);
677 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH,
679 &run_daemon, daemon_handle);
680 GNUNET_NETWORK_fdset_destroy (wrs);
681 GNUNET_NETWORK_fdset_destroy (wws);
687 * Start server offering our hostlist.
689 * @param c configuration to use
690 * @param st statistics handle to use
691 * @param co core handle to use
692 * @param[out] server_ch set to handler for CORE connect events
693 * @param[out] server_dh set to handler for CORE disconnect events
694 * @param advertise #GNUNET_YES if we should advertise our hostlist
695 * @return #GNUNET_OK on success
698 GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c,
699 struct GNUNET_STATISTICS_Handle *st,
700 struct GNUNET_CORE_Handle *co,
701 GNUNET_CORE_ConnectEventHandler *server_ch,
702 GNUNET_CORE_DisconnectEventHandler *server_dh,
705 unsigned long long port;
712 struct sockaddr_in v4;
713 struct sockaddr_in6 v6;
714 const struct sockaddr *sa4;
715 const struct sockaddr *sa6;
717 advertising = advertise;
720 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
721 "Advertising not enabled on this hostlist server\n");
725 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
726 "Advertising enabled on this hostlist server\n");
727 advertisements = GNUNET_CONTAINER_multipeermap_create (8,
732 peerinfo = GNUNET_PEERINFO_connect (cfg);
733 if (NULL == peerinfo)
735 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
736 _("Could not access PEERINFO service. Exiting.\n"));
737 return GNUNET_SYSERR;
740 GNUNET_CONFIGURATION_get_value_number (cfg,
744 return GNUNET_SYSERR;
745 if ((0 == port) || (port > UINT16_MAX))
747 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
748 _("Invalid port number %llu. Exiting.\n"),
750 return GNUNET_SYSERR;
754 GNUNET_CONFIGURATION_get_value_string (cfg,
758 hostname = GNUNET_RESOLVER_local_fqdn_get ();
759 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
760 _("Hostlist service starts on %s:%llu\n"),
762 if (NULL != hostname)
764 size = strlen (hostname);
765 if (size + 15 > MAX_URL_LEN)
771 GNUNET_asprintf (&hostlist_uri,
772 "http://%s:%u/", hostname,
773 (unsigned int) port);
774 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
775 _("Address to obtain hostlist: `%s'\n"),
778 GNUNET_free (hostname);
781 if (GNUNET_CONFIGURATION_have_value (cfg, "HOSTLIST", "BINDTOIPV4"))
784 GNUNET_CONFIGURATION_get_value_string (cfg, "HOSTLIST",
787 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
788 _("BINDTOIP does not a valid IPv4 address! Ignoring BINDTOIPV4.\n"));
794 if (GNUNET_CONFIGURATION_have_value (cfg, "HOSTLIST", "BINDTOIPV6"))
797 GNUNET_CONFIGURATION_get_value_string (cfg, "HOSTLIST",
800 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
801 _("BINDTOIP does not a valid IPv4 address! Ignoring BINDTOIPV6.\n"));
809 if (1 == inet_pton (AF_INET, ipv4, &i4))
811 memset (&v4, 0, sizeof (v4));
812 v4.sin_family = AF_INET;
814 v4.sin_port = htons (port);
815 #if HAVE_SOCKADDR_IN_SIN_LEN
816 v4.sin_len = sizeof (v4);
818 sa4 = (const struct sockaddr *) &v4;
821 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
822 _("`%s' is not a valid IPv4 address! Ignoring BINDTOIPV4.\n"),
829 if (1 == inet_pton (AF_INET6, ipv6, &i6))
831 memset (&v6, 0, sizeof (v6));
832 v6.sin6_family = AF_INET6;
834 v6.sin6_port = htons (port);
835 #if HAVE_SOCKADDR_IN_SIN_LEN
836 v6.sin6_len = sizeof (v6);
838 sa6 = (const struct sockaddr *) &v6;
841 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
842 _("`%s' is not a valid IPv6 address! Ignoring BINDTOIPV6.\n"),
847 daemon_handle_v6 = MHD_start_daemon (MHD_USE_IPv6 | MHD_USE_DEBUG,
849 &accept_policy_callback, NULL,
850 &access_handler_callback, NULL,
851 MHD_OPTION_CONNECTION_LIMIT,
853 MHD_OPTION_PER_IP_CONNECTION_LIMIT,
855 MHD_OPTION_CONNECTION_TIMEOUT,
857 MHD_OPTION_CONNECTION_MEMORY_LIMIT,
858 (size_t) (16 * 1024),
859 MHD_OPTION_SOCK_ADDR,
862 daemon_handle_v4 = MHD_start_daemon (MHD_NO_FLAG | MHD_USE_DEBUG,
864 &accept_policy_callback, NULL,
865 &access_handler_callback, NULL,
866 MHD_OPTION_CONNECTION_LIMIT,
868 MHD_OPTION_PER_IP_CONNECTION_LIMIT,
870 MHD_OPTION_CONNECTION_TIMEOUT,
872 MHD_OPTION_CONNECTION_MEMORY_LIMIT,
873 (size_t) (16 * 1024),
874 MHD_OPTION_SOCK_ADDR,
878 if ( (NULL == daemon_handle_v6) &&
879 (NULL == daemon_handle_v4) )
881 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
882 _("Could not start hostlist HTTP server on port %u\n"),
883 (unsigned short) port);
884 return GNUNET_SYSERR;
888 *server_ch = &connect_handler;
889 *server_dh = &disconnect_handler;
890 if (NULL != daemon_handle_v4)
891 hostlist_task_v4 = prepare_daemon (daemon_handle_v4);
892 if (NULL != daemon_handle_v6)
893 hostlist_task_v6 = prepare_daemon (daemon_handle_v6);
894 notify = GNUNET_PEERINFO_notify (cfg,
896 &process_notify, NULL);
902 * Stop server offering our hostlist.
905 GNUNET_HOSTLIST_server_stop ()
907 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
908 "Hostlist server shutdown\n");
909 if (GNUNET_SCHEDULER_NO_TASK != hostlist_task_v6)
911 GNUNET_SCHEDULER_cancel (hostlist_task_v6);
912 hostlist_task_v6 = GNUNET_SCHEDULER_NO_TASK;
914 if (GNUNET_SCHEDULER_NO_TASK != hostlist_task_v4)
916 GNUNET_SCHEDULER_cancel (hostlist_task_v4);
917 hostlist_task_v4 = GNUNET_SCHEDULER_NO_TASK;
919 if (NULL != daemon_handle_v4)
921 MHD_stop_daemon (daemon_handle_v4);
922 daemon_handle_v4 = NULL;
924 if (NULL != daemon_handle_v6)
926 MHD_stop_daemon (daemon_handle_v6);
927 daemon_handle_v6 = NULL;
929 if (NULL != response)
931 MHD_destroy_response (response);
936 GNUNET_PEERINFO_notify_cancel (notify);
941 if (NULL != builder->pitr)
943 GNUNET_PEERINFO_iterate_cancel (builder->pitr);
944 builder->pitr = NULL;
946 GNUNET_free_non_null (builder->data);
947 GNUNET_free (builder);
949 if (NULL != peerinfo)
951 GNUNET_PEERINFO_disconnect (peerinfo);
954 if (NULL != advertisements)
957 GNUNET_CONTAINER_multipeermap_size (advertisements));
958 GNUNET_CONTAINER_multipeermap_destroy (advertisements);
959 advertisements = NULL;
966 /* end of gnunet-daemon-hostlist_server.c */