2 This file is part of GNUnet.
3 Copyright (C) 2008, 2009, 2010, 2014 GNUnet e.V.
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., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, 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 struct GNUNET_SCHEDULER_Task *hostlist_task_v4;
80 * Our primary task for IPv6.
82 static struct GNUNET_SCHEDULER_Task *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_buffer (builder->size,
175 MHD_RESPMEM_MUST_FREE);
176 add_cors_headers (response);
177 if ((NULL == daemon_handle_v4) && (NULL == daemon_handle_v6))
179 MHD_destroy_response (response);
182 GNUNET_STATISTICS_set (stats, gettext_noop ("bytes in hostlist"),
183 builder->size, GNUNET_YES);
184 GNUNET_free (builder);
190 * Set @a cls to #GNUNET_YES (we have an address!).
192 * @param cls closure, an `int *`
193 * @param address the address (ignored)
194 * @param expiration expiration time (call is ignored if this is in the past)
195 * @return #GNUNET_SYSERR to stop iterating (unless expiration has occured)
198 check_has_addr (void *cls,
199 const struct GNUNET_HELLO_Address *address,
200 struct GNUNET_TIME_Absolute expiration)
204 if (0 == GNUNET_TIME_absolute_get_remaining (expiration).rel_value_us)
206 GNUNET_STATISTICS_update (stats,
207 gettext_noop ("expired addresses encountered"), 1,
209 return GNUNET_YES; /* ignore this address */
212 return GNUNET_SYSERR;
217 * Callback that processes each of the known HELLOs for the
218 * hostlist response construction.
220 * @param cls closure, NULL
221 * @param peer id of the peer, NULL for last call
222 * @param hello hello message for the peer (can be NULL)
223 * @param err_msg message
226 host_processor (void *cls,
227 const struct GNUNET_PeerIdentity *peer,
228 const struct GNUNET_HELLO_Message *hello,
237 GNUNET_assert (NULL == peer);
238 builder->pitr = NULL;
239 GNUNET_free_non_null (builder->data);
240 GNUNET_free (builder);
242 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
243 _("Error in communication with PEERINFO service: %s\n"),
249 builder->pitr = NULL;
255 has_addr = GNUNET_NO;
256 GNUNET_HELLO_iterate_addresses (hello,
260 if (GNUNET_NO == has_addr)
262 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
263 "HELLO for peer `%4s' has no address, not suitable for hostlist!\n",
265 GNUNET_STATISTICS_update (stats,
267 ("HELLOs without addresses encountered (ignored)"),
272 s = GNUNET_HELLO_size (hello);
273 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
274 "Received %u bytes of `%s' from peer `%s' for hostlist.\n",
278 if ( (old + s >= GNUNET_MAX_MALLOC_CHECKED) ||
279 (old + s >= MAX_BYTES_PER_HOSTLISTS) )
281 /* too large, skip! */
282 GNUNET_STATISTICS_update (stats,
284 ("bytes not included in hostlist (size limit)"),
288 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
289 "Adding peer `%s' to hostlist (%u bytes)\n",
292 GNUNET_array_grow (builder->data,
295 GNUNET_memcpy (&builder->data[old],
302 * Hostlist access policy (very permissive, allows everything).
303 * Returns #MHD_NO only if we are not yet ready to serve.
306 * @param addr address information from the client
307 * @param addrlen length of @a addr
308 * @return #MHD_YES if connection is allowed, #MHD_NO if not (we are not ready)
311 accept_policy_callback (void *cls,
312 const struct sockaddr *addr,
315 if (NULL == response)
317 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
318 "Received request for hostlist, but I am not yet ready; rejecting!\n");
321 return MHD_YES; /* accept all */
326 * Main request handler.
328 * @param cls argument given together with the function
329 * pointer when the handler was registered with MHD
331 * @param url the requested url
332 * @param method the HTTP method used (#MHD_HTTP_METHOD_GET,
333 * #MHD_HTTP_METHOD_PUT, etc.)
334 * @param version the HTTP version string (i.e.
335 * #MHD_HTTP_VERSION_1_1)
336 * @param upload_data the data being uploaded (excluding HEADERS,
337 * for a POST that fits into memory and that is encoded
338 * with a supported encoding, the POST data will NOT be
339 * given in upload_data and is instead available as
340 * part of #MHD_get_connection_values; very large POST
341 * data *will* be made available incrementally in
343 * @param upload_data_size set initially to the size of the
344 * @a upload_data provided; the method must update this
345 * value to the number of bytes NOT processed;
346 * @param con_cls pointer that the callback can set to some
347 * address and that will be preserved by MHD for future
348 * calls for this request; since the access handler may
349 * be called many times (i.e., for a PUT/POST operation
350 * with plenty of upload data) this allows the application
351 * to easily associate some request-specific state.
352 * If necessary, this state can be cleaned up in the
353 * global #MHD_RequestCompletedCallback (which
354 * can be set with the #MHD_OPTION_NOTIFY_COMPLETED).
355 * Initially, `*con_cls` will be NULL.
356 * @return #MHD_YES if the connection was handled successfully,
357 * #MHD_NO if the socket must be closed due to a serios
358 * error while handling the request
361 access_handler_callback (void *cls,
362 struct MHD_Connection *connection,
366 const char *upload_data,
367 size_t *upload_data_size,
372 /* CORS pre-flight request */
373 if (0 == strcmp (MHD_HTTP_METHOD_OPTIONS, method))
375 struct MHD_Response *options_response;
378 options_response = MHD_create_response_from_buffer (0, NULL,
379 MHD_RESPMEM_PERSISTENT);
380 add_cors_headers(options_response);
381 rc = MHD_queue_response (connection, MHD_HTTP_OK, options_response);
382 MHD_destroy_response (options_response);
385 if (0 != strcmp (method, MHD_HTTP_METHOD_GET))
387 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
388 _("Refusing `%s' request to hostlist server\n"), method);
389 GNUNET_STATISTICS_update (stats,
391 ("hostlist requests refused (not HTTP GET)"), 1,
395 if (NULL == *con_cls)
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
433 * @param cls closure with the `const struct GNUNET_PeerIdentity *` of
434 * the peer we are sending to
435 * @param size size of buffer to copy message to
436 * @param buf buffer to copy message to
437 * @return number of bytes copied to @a buf
440 adv_transmit_ready (void *cls,
444 const struct GNUNET_PeerIdentity *peer = cls;
445 static uint64_t hostlist_adv_count;
446 size_t transmission_size;
447 size_t uri_size; /* Including \0 termination! */
448 struct GNUNET_MessageHeader header;
450 struct GNUNET_CORE_TransmitHandle *th;
452 th = GNUNET_CONTAINER_multipeermap_get (advertisements,
454 GNUNET_assert (NULL != th);
455 GNUNET_assert (GNUNET_YES ==
456 GNUNET_CONTAINER_multipeermap_remove (advertisements,
461 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
462 "Transmission failed, buffer invalid!\n");
465 uri_size = strlen (hostlist_uri) + 1;
466 transmission_size = sizeof (struct GNUNET_MessageHeader) + uri_size;
467 header.type = htons (GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT);
468 header.size = htons (transmission_size);
469 GNUNET_assert (size >= transmission_size);
472 sizeof (struct GNUNET_MessageHeader));
474 GNUNET_memcpy (&cbuf[sizeof (struct GNUNET_MessageHeader)],
477 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
478 "Sent advertisement message: Copied %u bytes into buffer!\n",
479 (unsigned int) transmission_size);
480 hostlist_adv_count++;
481 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
482 " # Sent advertisement message: %llu\n",
483 (unsigned long long) hostlist_adv_count);
484 GNUNET_STATISTICS_update (stats,
485 gettext_noop ("# hostlist advertisements send"), 1,
487 return transmission_size;
492 * Method called whenever a given peer connects.
495 * @param peer peer identity this notification is about
498 connect_handler (void *cls,
499 const struct GNUNET_PeerIdentity *peer)
502 struct GNUNET_CORE_TransmitHandle *th;
506 if (NULL == hostlist_uri)
508 size = strlen (hostlist_uri) + 1;
509 if (size + sizeof (struct GNUNET_MessageHeader) >=
510 GNUNET_SERVER_MAX_MESSAGE_SIZE)
515 size += sizeof (struct GNUNET_MessageHeader);
521 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
522 "Asked CORE to transmit advertisement message with a size of %u bytes to peer `%s'\n",
526 (th = GNUNET_CORE_notify_transmit_ready (core, GNUNET_YES,
527 GNUNET_CORE_PRIO_BEST_EFFORT,
534 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
535 _("Advertisement message could not be queued by core\n"));
537 GNUNET_assert (GNUNET_YES ==
538 GNUNET_CONTAINER_multipeermap_put (advertisements,
541 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
546 * Method called whenever a given peer disconnects.
549 * @param peer peer identity this notification is about
552 disconnect_handler (void *cls,
553 const struct GNUNET_PeerIdentity *peer)
555 struct GNUNET_CORE_TransmitHandle *th;
559 th = GNUNET_CONTAINER_multipeermap_get (advertisements,
563 GNUNET_assert (GNUNET_YES ==
564 GNUNET_CONTAINER_multipeermap_remove (advertisements,
567 GNUNET_CORE_notify_transmit_ready_cancel (th);
572 * PEERINFO calls this function to let us know about a possible peer
573 * that we might want to connect to.
575 * @param cls closure (not used)
576 * @param peer potential peer to connect to
577 * @param hello HELLO for this peer (or NULL)
578 * @param err_msg NULL if successful, otherwise contains error message
581 process_notify (void *cls,
582 const struct GNUNET_PeerIdentity *peer,
583 const struct GNUNET_HELLO_Message *hello,
586 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
587 "Peerinfo is notifying us to rebuild our hostlist\n");
589 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
590 _("Error in communication with PEERINFO service: %s\n"),
594 /* restart re-build already in progress ... */
595 if (NULL != builder->pitr)
597 GNUNET_PEERINFO_iterate_cancel (builder->pitr);
598 builder->pitr = NULL;
600 GNUNET_free_non_null (builder->data);
602 builder->data = NULL;
606 builder = GNUNET_new (struct HostSet);
608 GNUNET_assert (NULL != peerinfo);
610 = GNUNET_PEERINFO_iterate (peerinfo,
612 &host_processor, NULL);
617 * Function that queries MHD's select sets and
618 * starts the task waiting for them.
620 static struct GNUNET_SCHEDULER_Task *
621 prepare_daemon (struct MHD_Daemon *daemon_handle);
625 * Call MHD to process pending requests and then go back
626 * and schedule the next run.
628 * @param cls the `struct MHD_Daemon` of the HTTP server to run
631 run_daemon (void *cls)
633 struct MHD_Daemon *daemon_handle = cls;
635 if (daemon_handle == daemon_handle_v4)
636 hostlist_task_v4 = NULL;
638 hostlist_task_v6 = NULL;
639 GNUNET_assert (MHD_YES == MHD_run (daemon_handle));
640 if (daemon_handle == daemon_handle_v4)
641 hostlist_task_v4 = prepare_daemon (daemon_handle);
643 hostlist_task_v6 = prepare_daemon (daemon_handle);
648 * Function that queries MHD's select sets and
649 * starts the task waiting for them.
651 * @param daemon_handle HTTP server to prepare to run
653 static struct GNUNET_SCHEDULER_Task *
654 prepare_daemon (struct MHD_Daemon *daemon_handle)
656 struct GNUNET_SCHEDULER_Task * ret;
660 struct GNUNET_NETWORK_FDSet *wrs;
661 struct GNUNET_NETWORK_FDSet *wws;
663 MHD_UNSIGNED_LONG_LONG timeout;
665 struct GNUNET_TIME_Relative tv;
670 wrs = GNUNET_NETWORK_fdset_create ();
671 wws = GNUNET_NETWORK_fdset_create ();
673 GNUNET_assert (MHD_YES ==
674 MHD_get_fdset (daemon_handle,
675 &rs, &ws, &es, &max));
676 haveto = MHD_get_timeout (daemon_handle, &timeout);
677 if (haveto == MHD_YES)
678 tv.rel_value_us = (uint64_t) timeout * 1000LL;
680 tv = GNUNET_TIME_UNIT_FOREVER_REL;
681 GNUNET_NETWORK_fdset_copy_native (wrs, &rs, max + 1);
682 GNUNET_NETWORK_fdset_copy_native (wws, &ws, max + 1);
683 ret = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH,
685 &run_daemon, daemon_handle);
686 GNUNET_NETWORK_fdset_destroy (wrs);
687 GNUNET_NETWORK_fdset_destroy (wws);
693 * Start server offering our hostlist.
695 * @param c configuration to use
696 * @param st statistics handle to use
697 * @param co core handle to use
698 * @param[out] server_ch set to handler for CORE connect events
699 * @param[out] server_dh set to handler for CORE disconnect events
700 * @param advertise #GNUNET_YES if we should advertise our hostlist
701 * @return #GNUNET_OK on success
704 GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c,
705 struct GNUNET_STATISTICS_Handle *st,
706 struct GNUNET_CORE_Handle *co,
707 GNUNET_CORE_ConnectEventHandler *server_ch,
708 GNUNET_CORE_DisconnectEventHandler *server_dh,
711 unsigned long long port;
718 struct sockaddr_in v4;
719 struct sockaddr_in6 v6;
720 const struct sockaddr *sa4;
721 const struct sockaddr *sa6;
723 advertising = advertise;
726 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
727 "Advertising not enabled on this hostlist server\n");
731 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
732 "Advertising enabled on this hostlist server\n");
733 advertisements = GNUNET_CONTAINER_multipeermap_create (8,
738 peerinfo = GNUNET_PEERINFO_connect (cfg);
739 if (NULL == peerinfo)
741 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
742 _("Could not access PEERINFO service. Exiting.\n"));
743 return GNUNET_SYSERR;
746 GNUNET_CONFIGURATION_get_value_number (cfg,
750 return GNUNET_SYSERR;
751 if ((0 == port) || (port > UINT16_MAX))
753 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
754 _("Invalid port number %llu. Exiting.\n"),
756 return GNUNET_SYSERR;
760 GNUNET_CONFIGURATION_get_value_string (cfg,
764 hostname = GNUNET_RESOLVER_local_fqdn_get ();
765 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
766 _("Hostlist service starts on %s:%llu\n"),
768 if (NULL != hostname)
770 size = strlen (hostname);
771 if (size + 15 > MAX_URL_LEN)
777 GNUNET_asprintf (&hostlist_uri,
778 "http://%s:%u/", hostname,
779 (unsigned int) port);
780 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
781 _("Address to obtain hostlist: `%s'\n"),
784 GNUNET_free (hostname);
787 if (GNUNET_CONFIGURATION_have_value (cfg, "HOSTLIST", "BINDTOIPV4"))
790 GNUNET_CONFIGURATION_get_value_string (cfg, "HOSTLIST",
793 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
794 _("BINDTOIP does not a valid IPv4 address! Ignoring BINDTOIPV4.\n"));
800 if (GNUNET_CONFIGURATION_have_value (cfg, "HOSTLIST", "BINDTOIPV6"))
803 GNUNET_CONFIGURATION_get_value_string (cfg, "HOSTLIST",
806 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
807 _("BINDTOIP does not a valid IPv4 address! Ignoring BINDTOIPV6.\n"));
815 if (1 == inet_pton (AF_INET, ipv4, &i4))
817 memset (&v4, 0, sizeof (v4));
818 v4.sin_family = AF_INET;
820 v4.sin_port = htons (port);
821 #if HAVE_SOCKADDR_IN_SIN_LEN
822 v4.sin_len = sizeof (v4);
824 sa4 = (const struct sockaddr *) &v4;
827 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
828 _("`%s' is not a valid IPv4 address! Ignoring BINDTOIPV4.\n"),
835 if (1 == inet_pton (AF_INET6, ipv6, &i6))
837 memset (&v6, 0, sizeof (v6));
838 v6.sin6_family = AF_INET6;
840 v6.sin6_port = htons (port);
841 #if HAVE_SOCKADDR_IN_SIN_LEN
842 v6.sin6_len = sizeof (v6);
844 sa6 = (const struct sockaddr *) &v6;
847 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
848 _("`%s' is not a valid IPv6 address! Ignoring BINDTOIPV6.\n"),
853 daemon_handle_v6 = MHD_start_daemon (MHD_USE_IPv6 | MHD_USE_DEBUG,
855 &accept_policy_callback, NULL,
856 &access_handler_callback, NULL,
857 MHD_OPTION_CONNECTION_LIMIT,
859 MHD_OPTION_PER_IP_CONNECTION_LIMIT,
861 MHD_OPTION_CONNECTION_TIMEOUT,
863 MHD_OPTION_CONNECTION_MEMORY_LIMIT,
864 (size_t) (16 * 1024),
865 MHD_OPTION_SOCK_ADDR,
868 daemon_handle_v4 = MHD_start_daemon (MHD_NO_FLAG | MHD_USE_DEBUG,
870 &accept_policy_callback, NULL,
871 &access_handler_callback, NULL,
872 MHD_OPTION_CONNECTION_LIMIT,
874 MHD_OPTION_PER_IP_CONNECTION_LIMIT,
876 MHD_OPTION_CONNECTION_TIMEOUT,
878 MHD_OPTION_CONNECTION_MEMORY_LIMIT,
879 (size_t) (16 * 1024),
880 MHD_OPTION_SOCK_ADDR,
884 if ( (NULL == daemon_handle_v6) &&
885 (NULL == daemon_handle_v4) )
887 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
888 _("Could not start hostlist HTTP server on port %u\n"),
889 (unsigned short) port);
890 return GNUNET_SYSERR;
894 *server_ch = &connect_handler;
895 *server_dh = &disconnect_handler;
896 if (NULL != daemon_handle_v4)
897 hostlist_task_v4 = prepare_daemon (daemon_handle_v4);
898 if (NULL != daemon_handle_v6)
899 hostlist_task_v6 = prepare_daemon (daemon_handle_v6);
900 notify = GNUNET_PEERINFO_notify (cfg,
902 &process_notify, NULL);
908 * Stop server offering our hostlist.
911 GNUNET_HOSTLIST_server_stop ()
913 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
914 "Hostlist server shutdown\n");
915 if (NULL != hostlist_task_v6)
917 GNUNET_SCHEDULER_cancel (hostlist_task_v6);
918 hostlist_task_v6 = NULL;
920 if (NULL != hostlist_task_v4)
922 GNUNET_SCHEDULER_cancel (hostlist_task_v4);
923 hostlist_task_v4 = NULL;
925 if (NULL != daemon_handle_v4)
927 MHD_stop_daemon (daemon_handle_v4);
928 daemon_handle_v4 = NULL;
930 if (NULL != daemon_handle_v6)
932 MHD_stop_daemon (daemon_handle_v6);
933 daemon_handle_v6 = NULL;
935 if (NULL != response)
937 MHD_destroy_response (response);
942 GNUNET_PEERINFO_notify_cancel (notify);
947 if (NULL != builder->pitr)
949 GNUNET_PEERINFO_iterate_cancel (builder->pitr);
950 builder->pitr = NULL;
952 GNUNET_free_non_null (builder->data);
953 GNUNET_free (builder);
956 if (NULL != peerinfo)
958 GNUNET_PEERINFO_disconnect (peerinfo);
961 if (NULL != advertisements)
964 GNUNET_CONTAINER_multipeermap_size (advertisements));
965 GNUNET_CONTAINER_multipeermap_destroy (advertisements);
966 advertisements = NULL;
973 /* end of gnunet-daemon-hostlist_server.c */