9e0307ec08146ce8a74dc242dd83e84403c6c7ff
[oweals/gnunet.git] / src / hostlist / hostlist-server.c
1 /*
2      This file is part of GNUnet.
3      (C) 2008, 2009, 2010 Christian Grothoff (and other contributing authors)
4
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 2, or (at your
8      option) any later version.
9
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.
14
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.
19 */
20
21 /**
22  * @file hostlist/hostlist-server.c
23  * @author Christian Grothoff
24  * @brief application to provide an integrated hostlist HTTP server
25  */
26
27 #include "platform.h"
28 #include <microhttpd.h>
29 #include "hostlist-server.h"
30 #include "gnunet_hello_lib.h"
31 #include "gnunet_peerinfo_service.h"
32 #include "gnunet-daemon-hostlist.h"
33 #include "gnunet_resolver_service.h"
34
35 #define DEBUG_HOSTLIST_SERVER GNUNET_NO
36
37 /**
38  * How often should we recalculate our response to hostlist requests?
39  */
40 #define RESPONSE_UPDATE_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5)
41
42 /**
43  * Handle to the HTTP server as provided by libmicrohttpd for IPv6.
44  */
45 static struct MHD_Daemon *daemon_handle_v6;
46
47 /**
48  * Handle to the HTTP server as provided by libmicrohttpd for IPv4.
49  */
50 static struct MHD_Daemon *daemon_handle_v4;
51
52 /**
53  * Our configuration.
54  */
55 static const struct GNUNET_CONFIGURATION_Handle *cfg;
56
57 /**
58  * Our scheduler.
59  */
60 static struct GNUNET_SCHEDULER_Handle *sched;
61
62 /**
63  * For keeping statistics.
64  */ 
65 static struct GNUNET_STATISTICS_Handle *stats;
66
67 /**
68  * Handle to the core service (NULL until we've connected to it).
69  */
70 struct GNUNET_CORE_Handle *core;
71
72 /**
73  * Our primary task for IPv4.
74  */
75 static GNUNET_SCHEDULER_TaskIdentifier hostlist_task_v4;
76
77 /**
78  * Our primary task for IPv6.
79  */
80 static GNUNET_SCHEDULER_TaskIdentifier hostlist_task_v6;
81
82 /**
83  * Task that updates our HTTP response.
84  */
85 static GNUNET_SCHEDULER_TaskIdentifier response_task;
86
87 /**
88  * Our canonical response.
89  */
90 static struct MHD_Response *response;
91
92 /**
93  * NULL if we are not currenlty iterating over peer information.
94  */
95 static struct GNUNET_PEERINFO_IteratorContext *pitr;
96
97 /**
98  * Context for host processor.
99  */
100 struct HostSet
101 {
102   unsigned int size;
103
104   char *data;
105 };
106
107 /**
108  * Task that will produce a new response object.
109  */
110 static void
111 update_response (void *cls,
112                  const struct GNUNET_SCHEDULER_TaskContext *tc);
113
114 /**
115  * Function that assembles our response.
116  */
117 static void
118 finish_response (struct HostSet *results)
119 {
120   struct GNUNET_TIME_Relative freq;
121
122   if (response != NULL)
123     MHD_destroy_response (response);
124 #if DEBUG_HOSTLIST_SERVER
125   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
126               "Creating hostlist response with %u bytes\n",
127               (unsigned int) results->size);
128 #endif
129   response = MHD_create_response_from_data (results->size,
130                                             results->data, MHD_YES, MHD_NO);
131   if ( (daemon_handle_v4 != NULL) ||
132        (daemon_handle_v6 != NULL) )
133     {
134       freq = RESPONSE_UPDATE_FREQUENCY;
135       if (results->size == 0)
136         freq = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 250);
137       /* schedule next update of the response */
138       response_task = GNUNET_SCHEDULER_add_delayed (sched,
139                                                     freq,
140                                                     &update_response,
141                                                     NULL);
142     }
143   else
144     {
145       /* already past shutdown */
146       MHD_destroy_response (response);
147       response = NULL;
148     }
149   GNUNET_STATISTICS_set (stats,
150                          gettext_noop("bytes in hostlist"),
151                          results->size,
152                          GNUNET_YES);
153   GNUNET_free (results);
154 }
155
156
157 /**
158  * Set 'cls' to GNUNET_YES (we have an address!).
159  *
160  * @param cls closure, an 'int*'
161  * @param tname name of the transport (ignored)
162  * @param expiration expiration time (call is ignored if this is in the past)
163  * @param addr the address (ignored)
164  * @param addrlen length of the address (ignored)
165  * @return  GNUNET_SYSERR to stop iterating (unless expiration has occured)
166  */
167 static int
168 check_has_addr (void *cls,
169                 const char *tname,
170                 struct GNUNET_TIME_Absolute expiration,
171                 const void *addr, size_t addrlen)
172 {
173   int *arg = cls;
174
175   if (GNUNET_TIME_absolute_get_remaining (expiration).value == 0)
176     {
177       GNUNET_STATISTICS_update (stats,
178                                 gettext_noop("expired addresses encountered"),
179                                 1,
180                                 GNUNET_YES);
181       return GNUNET_YES; /* ignore this address */
182     }
183   *arg = GNUNET_YES;
184   return GNUNET_SYSERR;
185 }
186
187
188 /**
189  * Callback that processes each of the known HELLOs for the
190  * hostlist response construction.
191  */
192 static void
193 host_processor (void *cls,
194                 const struct GNUNET_PeerIdentity * peer,
195                 const struct GNUNET_HELLO_Message *hello,
196                 uint32_t trust)
197 {
198   struct HostSet *results = cls;
199   size_t old;
200   size_t s;
201   int has_addr;
202   
203   if (peer == NULL)
204     {
205       pitr = NULL;
206       finish_response (results);
207       return;
208     }
209   has_addr = GNUNET_NO;
210   GNUNET_HELLO_iterate_addresses (hello,
211                                   GNUNET_NO,
212                                   &check_has_addr,
213                                   &has_addr);
214   if (GNUNET_NO == has_addr)
215     {
216       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
217                   "HELLO for peer `%4s' has no address, not suitable for hostlist!\n",
218                   GNUNET_i2s (peer));
219       GNUNET_STATISTICS_update (stats,
220                                 gettext_noop("HELLOs without addresses encountered (ignored)"),
221                                 1,
222                                 GNUNET_NO);
223       return; 
224     }
225   old = results->size;
226   s = GNUNET_HELLO_size(hello);
227 #if DEBUG_HOSTLIST_SERVER
228   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
229               "Received %u bytes of `%s' from peer `%s' for hostlist.\n",
230               (unsigned int) s,
231               "HELLO",
232               GNUNET_i2s (peer));
233 #endif
234   if (old + s >= GNUNET_MAX_MALLOC_CHECKED)
235     {
236       GNUNET_STATISTICS_update (stats,
237                                 gettext_noop("bytes not included in hostlist (size limit)"),
238                                 s,
239                                 GNUNET_NO);
240       return; /* too large, skip! */
241     }
242   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
243               "Adding peer `%s' to hostlist (%u bytes)\n",
244               GNUNET_i2s (peer),
245               (unsigned int) s);
246   GNUNET_array_grow (results->data,
247                      results->size,
248                      old + s);
249   memcpy (&results->data[old], hello, s);
250 }
251
252
253 /**
254  * Task that will produce a new response object.
255  */
256 static void
257 update_response (void *cls,
258                  const struct GNUNET_SCHEDULER_TaskContext *tc)
259 {
260   struct HostSet *results;
261
262   response_task = GNUNET_SCHEDULER_NO_TASK;
263   results = GNUNET_malloc(sizeof(struct HostSet));
264   pitr = GNUNET_PEERINFO_iterate (cfg, sched, 
265                                   NULL,
266                                   0, 
267                                   GNUNET_TIME_UNIT_MINUTES,
268                                   &host_processor,
269                                   results);
270 }
271
272
273 /**
274  * Hostlist access policy (very permissive, allows everything).
275  */
276 static int
277 accept_policy_callback (void *cls,
278                         const struct sockaddr *addr, socklen_t addrlen)
279 {
280   if (NULL == response)
281     {
282 #if DEBUG_HOSTLIST_SERVER
283       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
284                   "Received request for hostlist, but I am not yet ready; rejecting!\n");
285 #endif
286       return MHD_NO;
287     }
288   return MHD_YES;               /* accept all */
289 }
290
291
292 /**
293  * Main request handler.
294  */
295 static int
296 access_handler_callback (void *cls,
297                          struct MHD_Connection *connection,
298                          const char *url,
299                          const char *method,
300                          const char *version,
301                          const char *upload_data,
302                          size_t*upload_data_size, void **con_cls)
303 {
304   static int dummy;
305   
306   if (0 != strcmp (method, MHD_HTTP_METHOD_GET))
307     {
308       GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
309                   _("Refusing `%s' request to hostlist server\n"),
310                   method);
311       GNUNET_STATISTICS_update (stats,
312                                 gettext_noop("hostlist requests refused (not HTTP GET)"),
313                                 1,
314                                 GNUNET_YES);
315       return MHD_NO;
316     }
317   if (NULL == *con_cls)
318     {
319       (*con_cls) = &dummy;
320 #if DEBUG_HOSTLIST_SERVER
321       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
322                   _("Sending 100 CONTINUE reply\n"));
323 #endif
324       return MHD_YES;           /* send 100 continue */
325     }
326   if (*upload_data_size != 0)
327     {
328       GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
329                   _("Refusing `%s' request with %llu bytes of upload data\n"),
330                   method,
331                   (unsigned long long) *upload_data_size);
332       GNUNET_STATISTICS_update (stats,
333                                 gettext_noop("hostlist requests refused (upload data)"),
334                                 1,
335                                 GNUNET_YES);
336       return MHD_NO;              /* do not support upload data */
337     }
338   if (response == NULL)
339     {
340       GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
341                   _("Could not handle hostlist request since I do not have a response yet\n"));
342       GNUNET_STATISTICS_update (stats,
343                                 gettext_noop("hostlist requests refused (not ready)"),
344                                 1,
345                                 GNUNET_YES);
346       return MHD_NO;              /* internal error, no response yet */
347     }
348   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
349               _("Received request for our hostlist\n"));
350   GNUNET_STATISTICS_update (stats,
351                             gettext_noop("hostlist requests processed"),
352                             1,
353                             GNUNET_YES);
354   return MHD_queue_response (connection, MHD_HTTP_OK, response);
355 }
356
357 #if 0
358 static size_t
359 adv_transmit_ready ( void *cls, size_t size, void *buf)
360 {
361   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
362               _("Ready to transmit %u bytes of adv\n"), size);
363   return size;
364 }
365
366 static int
367 adv_transmit_message ( const struct GNUNET_PeerIdentity * peer, int size )
368 {
369   /* transmit message to peer */
370   if ( NULL == core)
371     {
372       GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
373                   _("Not connected to core, unable to send advertisement message\n"));
374       return GNUNET_NO;
375     }
376
377   struct GNUNET_TIME_Relative timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, GNUNET_ADV_TIMEOUT);
378   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
379               _("Asked to transmit %u bytes of adv\n"), size);
380   GNUNET_CORE_notify_transmit_ready (core,
381                                      0,
382                                      timeout,
383                                      peer,
384                                      size,
385                                      &adv_transmit_ready, NULL);
386   return GNUNET_YES;
387 }
388 #endif
389
390 /**
391  * Function that assembles our hostlist adv message.
392  */
393 static int
394 adv_create_message ( const struct GNUNET_PeerIdentity * peer,
395                      struct GNUNET_HOSTLIST_ADV_Message * adv_msg )
396
397 {
398   int length  = 0;
399   int size    = 0;
400   unsigned long long port;
401
402   char *uri;
403   char hostname[HOST_NAME_MAX];
404   char *protocol = "http://";
405   char *port_s = GNUNET_malloc(6 * sizeof(char));
406
407   if (0 != gethostname (hostname, sizeof (hostname) - 1))
408   {
409     GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
410         "Could not get system's hostname, unable to create advertisement message");
411     return GNUNET_NO;
412   }
413   if (-1 == GNUNET_CONFIGURATION_get_value_number (cfg,
414                                                    "HOSTLIST",
415                                                    "HTTPPORT",
416                                                    &port))
417     return GNUNET_SYSERR;
418
419   sprintf(port_s, "%llu", port);
420   length = strlen(hostname)+strlen(protocol)+strlen(port_s)+2;
421   size = (length+1) * sizeof (char);
422   uri = GNUNET_malloc(size);
423   uri = strcpy(uri, protocol);
424   uri = strcat(uri, hostname);
425   uri = strcat(uri, ":");
426   uri = strcat(uri, port_s);
427   uri = strcat(uri, "/");
428   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Address to obtain hostlist: %s\n", uri);
429
430
431   adv_msg = GNUNET_malloc ( sizeof(struct GNUNET_HOSTLIST_ADV_Message) + size);
432   if (adv_msg==NULL)
433   GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
434       "Creating message:address null\n",sizeof(struct GNUNET_HOSTLIST_ADV_Message));
435
436   if ( NULL == adv_msg)
437     {
438     GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
439         "Could not allocate memory for the message");
440     return GNUNET_NO;
441     }
442   GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
443       "size ADV_Message: %u\n",sizeof(struct GNUNET_HOSTLIST_ADV_Message));
444   GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
445       "size uri: %u\n", (length + 1) * sizeof (char));
446
447
448   if ( ( size + sizeof( struct GNUNET_HOSTLIST_ADV_Message )) > GNUNET_SERVER_MAX_MESSAGE_SIZE)
449     {
450       GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
451           "Advertisement message is bigger than GNUNET allows");
452       return GNUNET_NO;
453     }
454
455   adv_msg->header.type = htons (GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT);
456   adv_msg->header.size = htons (sizeof (struct GNUNET_HOSTLIST_ADV_Message) + size);
457   memcpy(&adv_msg[1],uri,size);
458
459   /* Request core to transmit message to peer
460   adv_transmit_message(peer, size); */
461
462   GNUNET_free ( port_s );
463   GNUNET_free ( uri );
464   GNUNET_free ( adv_msg );
465
466   return GNUNET_OK;
467 }
468
469 /**
470  * Method called whenever a given peer connects.
471  *
472  * @param cls closure
473  * @param peer peer identity this notification is about
474  * @param latency reported latency of the connection with 'other'
475  * @param distance reported distance (DV) to 'other'
476  */
477 static void
478 connect_handler (void *cls,
479                  const struct
480                  GNUNET_PeerIdentity * peer,
481                  struct GNUNET_TIME_Relative latency,
482                  uint32_t distance)
483 {
484
485   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
486               "A new peer connected to the server, preparing to send hostlist advertisement\n");
487   /* create a new advertisement message */
488   struct GNUNET_HOSTLIST_ADV_Message *adv_msg = NULL;
489   if ( (GNUNET_OK != adv_create_message(peer, adv_msg)))
490   {
491     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
492                 _(" GNUNET_OK Could not create a hostlist advertisement message, impossible to advertise hostlist\n"));
493     return;
494   }
495 }
496
497
498 /**
499  * Method called whenever a given peer disconnects.
500  *
501  * @param cls closure
502  * @param peer peer identity this notification is about
503  */
504 static void
505 disconnect_handler (void *cls,
506                     const struct
507                     GNUNET_PeerIdentity * peer)
508 {
509
510 }
511
512
513 /**
514  * Function that queries MHD's select sets and
515  * starts the task waiting for them.
516  */
517 static GNUNET_SCHEDULER_TaskIdentifier
518 prepare_daemon (struct MHD_Daemon *daemon_handle);
519
520 /**
521  * Call MHD to process pending requests and then go back
522  * and schedule the next run.
523  */
524 static void
525 run_daemon (void *cls,
526             const struct GNUNET_SCHEDULER_TaskContext *tc)
527 {
528   struct MHD_Daemon *daemon_handle = cls;
529
530   if (daemon_handle == daemon_handle_v4)
531     hostlist_task_v4 = GNUNET_SCHEDULER_NO_TASK;
532   else
533     hostlist_task_v6 = GNUNET_SCHEDULER_NO_TASK;
534
535   if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
536     return;    
537   GNUNET_assert (MHD_YES == MHD_run (daemon_handle));
538   if (daemon_handle == daemon_handle_v4)
539     hostlist_task_v4 = prepare_daemon (daemon_handle);
540   else
541     hostlist_task_v6 = prepare_daemon (daemon_handle);
542 }
543
544
545 /**
546  * Function that queries MHD's select sets and
547  * starts the task waiting for them.
548  */
549 static GNUNET_SCHEDULER_TaskIdentifier
550 prepare_daemon (struct MHD_Daemon *daemon_handle)
551 {
552   GNUNET_SCHEDULER_TaskIdentifier ret;
553   fd_set rs;
554   fd_set ws;
555   fd_set es;
556   struct GNUNET_NETWORK_FDSet *wrs;
557   struct GNUNET_NETWORK_FDSet *wws;
558   struct GNUNET_NETWORK_FDSet *wes;
559   int max;
560   unsigned long long timeout;
561   int haveto;
562   struct GNUNET_TIME_Relative tv;
563   
564   FD_ZERO(&rs);
565   FD_ZERO(&ws);
566   FD_ZERO(&es);
567   wrs = GNUNET_NETWORK_fdset_create ();
568   wes = GNUNET_NETWORK_fdset_create ();
569   wws = GNUNET_NETWORK_fdset_create ();
570   max = -1;
571   GNUNET_assert (MHD_YES ==
572                  MHD_get_fdset (daemon_handle,
573                                 &rs,
574                                 &ws,
575                                 &es,
576                                 &max));
577   haveto = MHD_get_timeout (daemon_handle, &timeout);
578   if (haveto == MHD_YES)
579     tv.value = (uint64_t) timeout;
580   else
581     tv = GNUNET_TIME_UNIT_FOREVER_REL;
582   GNUNET_NETWORK_fdset_copy_native (wrs, &rs, max);
583   GNUNET_NETWORK_fdset_copy_native (wws, &ws, max);
584   GNUNET_NETWORK_fdset_copy_native (wes, &es, max);
585   ret = GNUNET_SCHEDULER_add_select (sched,
586                                      GNUNET_SCHEDULER_PRIORITY_HIGH,
587                                      GNUNET_SCHEDULER_NO_TASK,
588                                      tv,
589                                      wrs,
590                                      wws,
591                                      &run_daemon,
592                                      daemon_handle);
593   GNUNET_NETWORK_fdset_destroy (wrs);
594   GNUNET_NETWORK_fdset_destroy (wws);
595   GNUNET_NETWORK_fdset_destroy (wes);
596   return ret;
597 }
598
599
600
601 /**
602  * Start server offering our hostlist.
603  *
604  * @return GNUNET_OK on success
605  */
606 int
607 GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c,
608                               struct GNUNET_SCHEDULER_Handle *s,
609                               struct GNUNET_STATISTICS_Handle *st,
610                               struct GNUNET_CORE_Handle *co,
611                               GNUNET_CORE_ConnectEventHandler *server_ch,
612                               GNUNET_CORE_DisconnectEventHandler *server_dh)
613 {
614   unsigned long long port;
615
616   sched = s;
617   cfg = c;
618   stats = st;
619   if (-1 == GNUNET_CONFIGURATION_get_value_number (cfg,
620                                                    "HOSTLIST",
621                                                    "HTTPPORT", 
622                                                    &port))
623     return GNUNET_SYSERR;
624   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
625               _("Hostlist service starts on port %llu\n"),
626               port);
627   daemon_handle_v6 = MHD_start_daemon (MHD_USE_IPv6 
628 #if DEBUG_HOSTLIST_SERVER
629                                        | MHD_USE_DEBUG
630 #endif
631                                        ,
632                                        (unsigned short) port,
633                                        &accept_policy_callback,
634                                        NULL,
635                                        &access_handler_callback,
636                                        NULL,
637                                        MHD_OPTION_CONNECTION_LIMIT, (unsigned int) 16,
638                                        MHD_OPTION_PER_IP_CONNECTION_LIMIT, (unsigned int) 1,
639                                        MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 16,
640                                        MHD_OPTION_CONNECTION_MEMORY_LIMIT, (size_t) (16 * 1024),
641                                        MHD_OPTION_END);
642   daemon_handle_v4 = MHD_start_daemon (MHD_NO_FLAG
643 #if DEBUG_HOSTLIST_SERVER
644                                        | MHD_USE_DEBUG
645 #endif
646                                        ,
647                                        (unsigned short) port,
648                                        &accept_policy_callback,
649                                        NULL,
650                                        &access_handler_callback,
651                                        NULL,
652                                        MHD_OPTION_CONNECTION_LIMIT, (unsigned int) 16,
653                                        MHD_OPTION_PER_IP_CONNECTION_LIMIT, (unsigned int) 1,
654                                        MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 16,
655                                        MHD_OPTION_CONNECTION_MEMORY_LIMIT, (size_t) (16 * 1024),
656                                        MHD_OPTION_END);
657
658   if ( (daemon_handle_v6 == NULL) &&
659        (daemon_handle_v4 == NULL) )
660     {
661       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
662                   _("Could not start hostlist HTTP server on port %u\n"),
663                   (unsigned short) port);
664       return GNUNET_SYSERR;    
665     }
666   core=co;
667   *server_ch = &connect_handler;
668   *server_dh = &disconnect_handler;
669
670   if (daemon_handle_v4 != NULL)
671     hostlist_task_v4 = prepare_daemon (daemon_handle_v4);
672   if (daemon_handle_v6 != NULL)
673     hostlist_task_v6 = prepare_daemon (daemon_handle_v6);
674   response_task = GNUNET_SCHEDULER_add_now (sched,
675                                             &update_response,
676                                             NULL);
677   return GNUNET_OK;
678 }
679
680 /**
681  * Stop server offering our hostlist.
682  */
683 void
684 GNUNET_HOSTLIST_server_stop ()
685 {
686 #if DEBUG_HOSTLIST_SERVER
687   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
688               "Hostlist server shutdown\n");
689 #endif
690   if (GNUNET_SCHEDULER_NO_TASK != hostlist_task_v6)
691     {
692       GNUNET_SCHEDULER_cancel (sched, hostlist_task_v6);
693       hostlist_task_v6 = GNUNET_SCHEDULER_NO_TASK;
694     }
695   if (GNUNET_SCHEDULER_NO_TASK != hostlist_task_v4)
696     {
697       GNUNET_SCHEDULER_cancel (sched, hostlist_task_v4);
698       hostlist_task_v4 = GNUNET_SCHEDULER_NO_TASK;
699     }
700   if (pitr != NULL)
701     {
702       GNUNET_PEERINFO_iterate_cancel (pitr);
703       pitr = NULL;
704     }
705   if (GNUNET_SCHEDULER_NO_TASK != response_task)
706     {
707       GNUNET_SCHEDULER_cancel (sched, response_task);
708       response_task = GNUNET_SCHEDULER_NO_TASK;
709     }
710   if (NULL != daemon_handle_v4)
711     {
712       MHD_stop_daemon (daemon_handle_v4);
713       daemon_handle_v4 = NULL;
714     }
715   if (NULL != daemon_handle_v6)
716     {
717       MHD_stop_daemon (daemon_handle_v6);
718       daemon_handle_v6 = NULL;
719     }
720   if (response != NULL)
721     {
722       MHD_destroy_response (response);
723       response = NULL;
724     }
725 }
726
727 /* end of hostlist-server.c */