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