2 This file is part of GNUnet.
3 Copyright (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 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);
241 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
242 _("Error in communication with PEERINFO service: %s\n"),
248 builder->pitr = NULL;
254 has_addr = GNUNET_NO;
255 GNUNET_HELLO_iterate_addresses (hello,
259 if (GNUNET_NO == has_addr)
261 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
262 "HELLO for peer `%4s' has no address, not suitable for hostlist!\n",
264 GNUNET_STATISTICS_update (stats,
266 ("HELLOs without addresses encountered (ignored)"),
271 s = GNUNET_HELLO_size (hello);
272 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
273 "Received %u bytes of `%s' from peer `%s' for hostlist.\n",
277 if ( (old + s >= GNUNET_MAX_MALLOC_CHECKED) ||
278 (old + s >= MAX_BYTES_PER_HOSTLISTS) )
280 /* too large, skip! */
281 GNUNET_STATISTICS_update (stats,
283 ("bytes not included in hostlist (size limit)"),
287 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
288 "Adding peer `%s' to hostlist (%u bytes)\n",
291 GNUNET_array_grow (builder->data,
294 memcpy (&builder->data[old],
301 * Hostlist access policy (very permissive, allows everything).
302 * Returns #MHD_NO only if we are not yet ready to serve.
305 * @param addr address information from the client
306 * @param addrlen length of @a addr
307 * @return #MHD_YES if connection is allowed, #MHD_NO if not (we are not ready)
310 accept_policy_callback (void *cls,
311 const struct sockaddr *addr,
314 if (NULL == response)
316 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
317 "Received request for hostlist, but I am not yet ready; rejecting!\n");
320 return MHD_YES; /* accept all */
325 * Main request handler.
327 * @param cls argument given together with the function
328 * pointer when the handler was registered with MHD
330 * @param url the requested url
331 * @param method the HTTP method used (#MHD_HTTP_METHOD_GET,
332 * #MHD_HTTP_METHOD_PUT, etc.)
333 * @param version the HTTP version string (i.e.
334 * #MHD_HTTP_VERSION_1_1)
335 * @param upload_data the data being uploaded (excluding HEADERS,
336 * for a POST that fits into memory and that is encoded
337 * with a supported encoding, the POST data will NOT be
338 * given in upload_data and is instead available as
339 * part of #MHD_get_connection_values; very large POST
340 * data *will* be made available incrementally in
342 * @param upload_data_size set initially to the size of the
343 * @a upload_data provided; the method must update this
344 * value to the number of bytes NOT processed;
345 * @param con_cls pointer that the callback can set to some
346 * address and that will be preserved by MHD for future
347 * calls for this request; since the access handler may
348 * be called many times (i.e., for a PUT/POST operation
349 * with plenty of upload data) this allows the application
350 * to easily associate some request-specific state.
351 * If necessary, this state can be cleaned up in the
352 * global #MHD_RequestCompletedCallback (which
353 * can be set with the #MHD_OPTION_NOTIFY_COMPLETED).
354 * Initially, `*con_cls` will be NULL.
355 * @return #MHD_YES if the connection was handled successfully,
356 * #MHD_NO if the socket must be closed due to a serios
357 * error while handling the request
360 access_handler_callback (void *cls,
361 struct MHD_Connection *connection,
365 const char *upload_data,
366 size_t *upload_data_size,
371 /* CORS pre-flight request */
372 if (0 == strcmp (MHD_HTTP_METHOD_OPTIONS, method))
374 struct MHD_Response *options_response;
377 options_response = MHD_create_response_from_buffer (0, NULL,
378 MHD_RESPMEM_PERSISTENT);
379 add_cors_headers(options_response);
380 rc = MHD_queue_response (connection, MHD_HTTP_OK, options_response);
381 MHD_destroy_response (options_response);
384 if (0 != strcmp (method, MHD_HTTP_METHOD_GET))
386 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
387 _("Refusing `%s' request to hostlist server\n"), method);
388 GNUNET_STATISTICS_update (stats,
390 ("hostlist requests refused (not HTTP GET)"), 1,
394 if (NULL == *con_cls)
397 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
398 "Sending 100 CONTINUE reply\n");
399 return MHD_YES; /* send 100 continue */
401 if (0 != *upload_data_size)
403 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
404 _("Refusing `%s' request with %llu bytes of upload data\n"),
405 method, (unsigned long long) *upload_data_size);
406 GNUNET_STATISTICS_update (stats,
408 ("hostlist requests refused (upload data)"), 1,
410 return MHD_NO; /* do not support upload data */
412 if (NULL == response)
414 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
415 _("Could not handle hostlist request since I do not have a response yet\n"));
416 GNUNET_STATISTICS_update (stats,
418 ("hostlist requests refused (not ready)"), 1,
420 return MHD_NO; /* internal error, no response yet */
422 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
423 _("Received request for our hostlist\n"));
424 GNUNET_STATISTICS_update (stats,
425 gettext_noop ("hostlist requests processed"),
427 return MHD_queue_response (connection, MHD_HTTP_OK, response);
432 * Handler called by CORE when CORE is ready to transmit message
434 * @param cls closure with the `const struct GNUNET_PeerIdentity *` of
435 * the peer we are sending to
436 * @param size size of buffer to copy message to
437 * @param buf buffer to copy message to
438 * @return number of bytes copied to @a buf
441 adv_transmit_ready (void *cls,
445 const struct GNUNET_PeerIdentity *peer = cls;
446 static uint64_t hostlist_adv_count;
447 size_t transmission_size;
448 size_t uri_size; /* Including \0 termination! */
449 struct GNUNET_MessageHeader header;
451 struct GNUNET_CORE_TransmitHandle *th;
453 th = GNUNET_CONTAINER_multipeermap_get (advertisements,
455 GNUNET_assert (NULL != th);
456 GNUNET_assert (GNUNET_YES ==
457 GNUNET_CONTAINER_multipeermap_remove (advertisements,
462 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
463 "Transmission failed, buffer invalid!\n");
466 uri_size = strlen (hostlist_uri) + 1;
467 transmission_size = sizeof (struct GNUNET_MessageHeader) + uri_size;
468 header.type = htons (GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT);
469 header.size = htons (transmission_size);
470 GNUNET_assert (size >= transmission_size);
473 sizeof (struct GNUNET_MessageHeader));
475 memcpy (&cbuf[sizeof (struct GNUNET_MessageHeader)],
478 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
479 "Sent advertisement message: Copied %u bytes into buffer!\n",
480 (unsigned int) transmission_size);
481 hostlist_adv_count++;
482 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
483 " # Sent advertisement message: %u\n",
485 GNUNET_STATISTICS_update (stats,
486 gettext_noop ("# hostlist advertisements send"), 1,
488 return transmission_size;
493 * Method called whenever a given peer connects.
496 * @param peer peer identity this notification is about
499 connect_handler (void *cls,
500 const struct GNUNET_PeerIdentity *peer)
503 struct GNUNET_CORE_TransmitHandle *th;
507 if (NULL == hostlist_uri)
509 size = strlen (hostlist_uri) + 1;
510 if (size + sizeof (struct GNUNET_MessageHeader) >=
511 GNUNET_SERVER_MAX_MESSAGE_SIZE)
516 size += sizeof (struct GNUNET_MessageHeader);
522 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
523 "Asked CORE to transmit advertisement message with a size of %u bytes to peer `%s'\n",
527 (th = GNUNET_CORE_notify_transmit_ready (core, GNUNET_YES,
528 GNUNET_CORE_PRIO_BEST_EFFORT,
535 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
536 _("Advertisement message could not be queued by core\n"));
538 GNUNET_assert (GNUNET_YES ==
539 GNUNET_CONTAINER_multipeermap_put (advertisements,
542 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
547 * Method called whenever a given peer disconnects.
550 * @param peer peer identity this notification is about
553 disconnect_handler (void *cls,
554 const struct GNUNET_PeerIdentity *peer)
556 struct GNUNET_CORE_TransmitHandle *th;
560 th = GNUNET_CONTAINER_multipeermap_get (advertisements,
564 GNUNET_assert (GNUNET_YES ==
565 GNUNET_CONTAINER_multipeermap_remove (advertisements,
568 GNUNET_CORE_notify_transmit_ready_cancel (th);
573 * PEERINFO calls this function to let us know about a possible peer
574 * that we might want to connect to.
576 * @param cls closure (not used)
577 * @param peer potential peer to connect to
578 * @param hello HELLO for this peer (or NULL)
579 * @param err_msg NULL if successful, otherwise contains error message
582 process_notify (void *cls,
583 const struct GNUNET_PeerIdentity *peer,
584 const struct GNUNET_HELLO_Message *hello,
587 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
588 "Peerinfo is notifying us to rebuild our hostlist\n");
590 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
591 _("Error in communication with PEERINFO service: %s\n"),
595 /* restart re-build already in progress ... */
596 if (NULL != builder->pitr)
598 GNUNET_PEERINFO_iterate_cancel (builder->pitr);
599 builder->pitr = NULL;
601 GNUNET_free_non_null (builder->data);
603 builder->data = NULL;
607 builder = GNUNET_new (struct HostSet);
609 GNUNET_assert (NULL != peerinfo);
611 = GNUNET_PEERINFO_iterate (peerinfo,
613 GNUNET_TIME_UNIT_MINUTES,
614 &host_processor, NULL);
619 * Function that queries MHD's select sets and
620 * starts the task waiting for them.
622 static struct GNUNET_SCHEDULER_Task *
623 prepare_daemon (struct MHD_Daemon *daemon_handle);
627 * Call MHD to process pending requests and then go back
628 * and schedule the next run.
630 * @param cls the `struct MHD_Daemon` of the HTTP server to run
631 * @param tc scheduler context
634 run_daemon (void *cls,
635 const struct GNUNET_SCHEDULER_TaskContext *tc)
637 struct MHD_Daemon *daemon_handle = cls;
639 if (daemon_handle == daemon_handle_v4)
640 hostlist_task_v4 = NULL;
642 hostlist_task_v6 = NULL;
644 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
646 GNUNET_assert (MHD_YES == MHD_run (daemon_handle));
647 if (daemon_handle == daemon_handle_v4)
648 hostlist_task_v4 = prepare_daemon (daemon_handle);
650 hostlist_task_v6 = prepare_daemon (daemon_handle);
655 * Function that queries MHD's select sets and
656 * starts the task waiting for them.
658 * @param daemon_handle HTTP server to prepare to run
660 static struct GNUNET_SCHEDULER_Task *
661 prepare_daemon (struct MHD_Daemon *daemon_handle)
663 struct GNUNET_SCHEDULER_Task * ret;
667 struct GNUNET_NETWORK_FDSet *wrs;
668 struct GNUNET_NETWORK_FDSet *wws;
670 MHD_UNSIGNED_LONG_LONG timeout;
672 struct GNUNET_TIME_Relative tv;
677 wrs = GNUNET_NETWORK_fdset_create ();
678 wws = GNUNET_NETWORK_fdset_create ();
680 GNUNET_assert (MHD_YES == MHD_get_fdset (daemon_handle, &rs, &ws, &es, &max));
681 haveto = MHD_get_timeout (daemon_handle, &timeout);
682 if (haveto == MHD_YES)
683 tv.rel_value_us = (uint64_t) timeout * 1000LL;
685 tv = GNUNET_TIME_UNIT_FOREVER_REL;
686 GNUNET_NETWORK_fdset_copy_native (wrs, &rs, max + 1);
687 GNUNET_NETWORK_fdset_copy_native (wws, &ws, max + 1);
689 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH,
691 &run_daemon, daemon_handle);
692 GNUNET_NETWORK_fdset_destroy (wrs);
693 GNUNET_NETWORK_fdset_destroy (wws);
699 * Start server offering our hostlist.
701 * @param c configuration to use
702 * @param st statistics handle to use
703 * @param co core handle to use
704 * @param[out] server_ch set to handler for CORE connect events
705 * @param[out] server_dh set to handler for CORE disconnect events
706 * @param advertise #GNUNET_YES if we should advertise our hostlist
707 * @return #GNUNET_OK on success
710 GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c,
711 struct GNUNET_STATISTICS_Handle *st,
712 struct GNUNET_CORE_Handle *co,
713 GNUNET_CORE_ConnectEventHandler *server_ch,
714 GNUNET_CORE_DisconnectEventHandler *server_dh,
717 unsigned long long port;
724 struct sockaddr_in v4;
725 struct sockaddr_in6 v6;
726 const struct sockaddr *sa4;
727 const struct sockaddr *sa6;
729 advertising = advertise;
732 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
733 "Advertising not enabled on this hostlist server\n");
737 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
738 "Advertising enabled on this hostlist server\n");
739 advertisements = GNUNET_CONTAINER_multipeermap_create (8,
744 peerinfo = GNUNET_PEERINFO_connect (cfg);
745 if (NULL == peerinfo)
747 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
748 _("Could not access PEERINFO service. Exiting.\n"));
749 return GNUNET_SYSERR;
752 GNUNET_CONFIGURATION_get_value_number (cfg,
756 return GNUNET_SYSERR;
757 if ((0 == port) || (port > UINT16_MAX))
759 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
760 _("Invalid port number %llu. Exiting.\n"),
762 return GNUNET_SYSERR;
766 GNUNET_CONFIGURATION_get_value_string (cfg,
770 hostname = GNUNET_RESOLVER_local_fqdn_get ();
771 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
772 _("Hostlist service starts on %s:%llu\n"),
774 if (NULL != hostname)
776 size = strlen (hostname);
777 if (size + 15 > MAX_URL_LEN)
783 GNUNET_asprintf (&hostlist_uri,
784 "http://%s:%u/", hostname,
785 (unsigned int) port);
786 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
787 _("Address to obtain hostlist: `%s'\n"),
790 GNUNET_free (hostname);
793 if (GNUNET_CONFIGURATION_have_value (cfg, "HOSTLIST", "BINDTOIPV4"))
796 GNUNET_CONFIGURATION_get_value_string (cfg, "HOSTLIST",
799 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
800 _("BINDTOIP does not a valid IPv4 address! Ignoring BINDTOIPV4.\n"));
806 if (GNUNET_CONFIGURATION_have_value (cfg, "HOSTLIST", "BINDTOIPV6"))
809 GNUNET_CONFIGURATION_get_value_string (cfg, "HOSTLIST",
812 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
813 _("BINDTOIP does not a valid IPv4 address! Ignoring BINDTOIPV6.\n"));
821 if (1 == inet_pton (AF_INET, ipv4, &i4))
823 memset (&v4, 0, sizeof (v4));
824 v4.sin_family = AF_INET;
826 v4.sin_port = htons (port);
827 #if HAVE_SOCKADDR_IN_SIN_LEN
828 v4.sin_len = sizeof (v4);
830 sa4 = (const struct sockaddr *) &v4;
833 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
834 _("`%s' is not a valid IPv4 address! Ignoring BINDTOIPV4.\n"),
841 if (1 == inet_pton (AF_INET6, ipv6, &i6))
843 memset (&v6, 0, sizeof (v6));
844 v6.sin6_family = AF_INET6;
846 v6.sin6_port = htons (port);
847 #if HAVE_SOCKADDR_IN_SIN_LEN
848 v6.sin6_len = sizeof (v6);
850 sa6 = (const struct sockaddr *) &v6;
853 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
854 _("`%s' is not a valid IPv6 address! Ignoring BINDTOIPV6.\n"),
859 daemon_handle_v6 = MHD_start_daemon (MHD_USE_IPv6 | MHD_USE_DEBUG,
861 &accept_policy_callback, NULL,
862 &access_handler_callback, NULL,
863 MHD_OPTION_CONNECTION_LIMIT,
865 MHD_OPTION_PER_IP_CONNECTION_LIMIT,
867 MHD_OPTION_CONNECTION_TIMEOUT,
869 MHD_OPTION_CONNECTION_MEMORY_LIMIT,
870 (size_t) (16 * 1024),
871 MHD_OPTION_SOCK_ADDR,
874 daemon_handle_v4 = MHD_start_daemon (MHD_NO_FLAG | MHD_USE_DEBUG,
876 &accept_policy_callback, NULL,
877 &access_handler_callback, NULL,
878 MHD_OPTION_CONNECTION_LIMIT,
880 MHD_OPTION_PER_IP_CONNECTION_LIMIT,
882 MHD_OPTION_CONNECTION_TIMEOUT,
884 MHD_OPTION_CONNECTION_MEMORY_LIMIT,
885 (size_t) (16 * 1024),
886 MHD_OPTION_SOCK_ADDR,
890 if ( (NULL == daemon_handle_v6) &&
891 (NULL == daemon_handle_v4) )
893 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
894 _("Could not start hostlist HTTP server on port %u\n"),
895 (unsigned short) port);
896 return GNUNET_SYSERR;
900 *server_ch = &connect_handler;
901 *server_dh = &disconnect_handler;
902 if (NULL != daemon_handle_v4)
903 hostlist_task_v4 = prepare_daemon (daemon_handle_v4);
904 if (NULL != daemon_handle_v6)
905 hostlist_task_v6 = prepare_daemon (daemon_handle_v6);
906 notify = GNUNET_PEERINFO_notify (cfg,
908 &process_notify, NULL);
914 * Stop server offering our hostlist.
917 GNUNET_HOSTLIST_server_stop ()
919 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
920 "Hostlist server shutdown\n");
921 if (NULL != hostlist_task_v6)
923 GNUNET_SCHEDULER_cancel (hostlist_task_v6);
924 hostlist_task_v6 = NULL;
926 if (NULL != hostlist_task_v4)
928 GNUNET_SCHEDULER_cancel (hostlist_task_v4);
929 hostlist_task_v4 = NULL;
931 if (NULL != daemon_handle_v4)
933 MHD_stop_daemon (daemon_handle_v4);
934 daemon_handle_v4 = NULL;
936 if (NULL != daemon_handle_v6)
938 MHD_stop_daemon (daemon_handle_v6);
939 daemon_handle_v6 = NULL;
941 if (NULL != response)
943 MHD_destroy_response (response);
948 GNUNET_PEERINFO_notify_cancel (notify);
953 if (NULL != builder->pitr)
955 GNUNET_PEERINFO_iterate_cancel (builder->pitr);
956 builder->pitr = NULL;
958 GNUNET_free_non_null (builder->data);
959 GNUNET_free (builder);
961 if (NULL != peerinfo)
963 GNUNET_PEERINFO_disconnect (peerinfo);
966 if (NULL != advertisements)
969 GNUNET_CONTAINER_multipeermap_size (advertisements));
970 GNUNET_CONTAINER_multipeermap_destroy (advertisements);
971 advertisements = NULL;
978 /* end of gnunet-daemon-hostlist_server.c */