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