+/**
+ * Handler called by core when core is ready to transmit message
+ * @param cls closure
+ * @param size size of buffer to copy message to
+ * @param buf buffer to copy message to
+ */
+static size_t
+adv_transmit_ready (void *cls, size_t size, void *buf)
+{
+ static uint64_t hostlist_adv_count;
+
+ size_t transmission_size;
+ size_t uri_size; /* Including \0 termination! */
+ struct GNUNET_MessageHeader header;
+ char *cbuf;
+
+ if (buf == NULL)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Transmission failed, buffer invalid!\n");
+ return 0;
+ }
+ uri_size = strlen (hostlist_uri) + 1;
+ transmission_size = sizeof (struct GNUNET_MessageHeader) + uri_size;
+ header.type = htons (GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT);
+ header.size = htons (transmission_size);
+ GNUNET_assert (size >= transmission_size);
+ memcpy (buf, &header, sizeof (struct GNUNET_MessageHeader));
+ cbuf = buf;
+ memcpy (&cbuf[sizeof (struct GNUNET_MessageHeader)], hostlist_uri, uri_size);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Sent advertisement message: Copied %u bytes into buffer!\n",
+ (unsigned int) transmission_size);
+ hostlist_adv_count++;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ " # Sent advertisement message: %u\n", hostlist_adv_count);
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop ("# hostlist advertisements send"),
+ 1, GNUNET_NO);
+ return transmission_size;
+}
+
+
+/**
+ * Method called whenever a given peer connects.
+ *
+ * @param cls closure
+ * @param peer peer identity this notification is about
+ * @param atsi performance data
+ */
+static void
+connect_handler (void *cls,
+ const struct
+ GNUNET_PeerIdentity *peer,
+ const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+{
+ size_t size;
+
+ if (!advertising)
+ return;
+ if (hostlist_uri == NULL)
+ return;
+ size = strlen (hostlist_uri) + 1;
+ if (size + sizeof (struct GNUNET_MessageHeader) >=
+ GNUNET_SERVER_MAX_MESSAGE_SIZE)
+ {
+ GNUNET_break (0);
+ return;
+ }
+ size += sizeof (struct GNUNET_MessageHeader);
+ if (NULL == core)
+ {
+ GNUNET_break (0);
+ return;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Asked core to transmit advertisement message with a size of %u bytes to peer `%s'\n",
+ size, GNUNET_i2s (peer));
+ if (NULL == GNUNET_CORE_notify_transmit_ready (core,
+ GNUNET_YES,
+ 0,
+ GNUNET_ADV_TIMEOUT,
+ peer,
+ size,
+ &adv_transmit_ready, NULL))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Advertisement message could not be queued by core\n"));
+ }
+}
+
+
+/**
+ * Method called whenever a given peer disconnects.
+ *
+ * @param cls closure
+ * @param peer peer identity this notification is about
+ */
+static void
+disconnect_handler (void *cls, const struct GNUNET_PeerIdentity *peer)
+{
+ /* nothing to do */
+}
+
+/**
+ * PEERINFO calls this function to let us know about a possible peer
+ * that we might want to connect to.
+ *
+ * @param cls closure (not used)
+ * @param peer potential peer to connect to
+ * @param hello HELLO for this peer (or NULL)
+ * @param err_msg NULL if successful, otherwise contains error message
+ */
+static void
+process_notify (void *cls,
+ const struct GNUNET_PeerIdentity *peer,
+ const struct GNUNET_HELLO_Message *hello, const char *err_msg)
+{
+ struct HostSet *results;
+
+#if DEBUG_HOSTLIST_SERVER
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Peerinfo is notifying us to rebuild our hostlist\n");
+#endif
+ if (err_msg != NULL)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ _("Error in communication with PEERINFO service\n"));
+ /* return; */
+ }
+ results = GNUNET_malloc (sizeof (struct HostSet));
+ GNUNET_assert (peerinfo != NULL);
+ pitr = GNUNET_PEERINFO_iterate (peerinfo,
+ NULL,
+ GNUNET_TIME_UNIT_MINUTES,
+ &host_processor, results);
+}
+