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