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