+ me = *my_identity;
+}
+
+
+/**
+ * Core handler for p2p hostlist advertisements
+ *
+ * @param cls closure
+ * @param message advertisement message we got
+ * @return #GNUNET_OK if message is well-formed
+ */
+static int
+check_advertisement (void *cls,
+ const struct GNUNET_MessageHeader *message)
+{
+ size_t size;
+ size_t uri_size;
+ const char *uri;
+
+ size = ntohs (message->size);
+ if (size <= sizeof (struct GNUNET_MessageHeader))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ uri = (const char *) &message[1];
+ uri_size = size - sizeof (struct GNUNET_MessageHeader);
+ if (uri[uri_size - 1] != '\0')
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ return GNUNET_OK;
+}
+
+
+/**
+ * Core handler for p2p hostlist advertisements
+ *
+ * @param cls closure
+ * @param message advertisement message we got
+ * @return #GNUNET_OK on success
+ */
+static void
+handle_advertisement (void *cls,
+ const struct GNUNET_MessageHeader *message)
+{
+ const char *uri = (const char *) &message[1];
+
+ GNUNET_assert (NULL != client_adv_handler);
+ (void) (*client_adv_handler) (uri);
+}
+
+
+/**
+ * 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
+ * @param mq queue for sending messages to @a peer
+ * @return peer
+ */
+static void *
+connect_handler (void *cls,
+ const struct GNUNET_PeerIdentity *peer,
+ struct GNUNET_MQ_Handle *mq)
+{
+ if (0 == memcmp (&me,
+ peer,
+ sizeof (struct GNUNET_PeerIdentity)))
+ return NULL;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "A new peer connected, notifying client and server\n");
+ if (NULL != client_ch)
+ GNUNET_assert (NULL ==
+ (*client_ch) (cls,
+ peer,
+ mq));
+#if HAVE_MHD
+ if (NULL != server_ch)
+ GNUNET_assert (NULL ==
+ (*server_ch) (cls,
+ peer,
+ mq));
+#endif
+ return (void *) peer;
+}
+
+
+/**
+ * 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,
+ void *internal_cls)
+{
+ if (0 == memcmp (&me,
+ peer,
+ sizeof (struct GNUNET_PeerIdentity)))
+ return;
+ /* call hostlist client disconnect handler */
+ if (NULL != client_dh)
+ (*client_dh) (cls,
+ peer,
+ NULL);