+/**
+ * Core handler for p2p hostlist advertisements
+ *
+ * @param cls closure
+ * @param peer identity of the sender
+ * @param message advertisement message we got
+ * @return #GNUNET_OK on success
+ */
+static int
+advertisement_handler (void *cls,
+ const struct GNUNET_PeerIdentity *peer,
+ const struct GNUNET_MessageHeader *message)
+{
+ GNUNET_assert (NULL != client_adv_handler);
+ return (*client_adv_handler) (cls, peer, message);
+}
+
+
+/**
+ * Method called whenever a given peer connects. Wrapper to call both
+ * client's and server's functions
+ *
+ * @param cls closure
+ * @param peer peer identity this notification is about
+ */
+static void
+connect_handler (void *cls, const struct GNUNET_PeerIdentity *peer)
+{
+ if (0 == memcmp (&me, peer, sizeof (struct GNUNET_PeerIdentity)))
+ return;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "A new peer connected, notifying client and server\n");
+ if (NULL != client_ch)
+ (*client_ch) (cls, peer);
+#if HAVE_MHD
+ if (NULL != server_ch)
+ (*server_ch) (cls, peer);
+#endif
+}
+
+
+/**
+ * Method called whenever a given peer disconnects. Wrapper to call
+ * both client's and server's functions
+ *
+ * @param cls closure
+ * @param peer peer identity this notification is about
+ */
+static void
+disconnect_handler (void *cls,
+ const struct GNUNET_PeerIdentity *peer)
+{
+ if (0 == memcmp (&me, peer, sizeof (struct GNUNET_PeerIdentity)))
+ return;
+ /* call hostlist client disconnect handler */
+ if (NULL != client_dh)
+ (*client_dh) (cls, peer);
+#if HAVE_MHD
+ /* call hostlist server disconnect handler */
+ if (NULL != server_dh)
+ (*server_dh) (cls, peer);
+#endif
+}
+
+
+/**
+ * Last task run during shutdown. Disconnects us from
+ * the other services.
+ *
+ * @param cls NULL
+ * @param tc scheduler context
+ */
+static void
+cleaning_task (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Hostlist daemon is shutting down\n");
+ if (NULL != core)
+ {
+ GNUNET_CORE_disconnect (core);
+ core = NULL;
+ }
+ if (bootstrapping)
+ {
+ GNUNET_HOSTLIST_client_stop ();
+ }
+#if HAVE_MHD
+ if (provide_hostlist)
+ {
+ GNUNET_HOSTLIST_server_stop ();
+ }
+#endif
+ if (NULL != stats)
+ {
+ GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
+ stats = NULL;
+ }
+}