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