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