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