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