+/**
+ * Request that the mesh should try to connect to a peer supporting the given
+ * message type.
+ *
+ * @param tunnel handle to existing tunnel
+ * @param app_type application type that must be supported by the peer (MESH
+ * should discover peer in proximity handling this type)
+ */
+void
+GNUNET_MESH_peer_request_connect_by_type (struct GNUNET_MESH_Tunnel *tunnel,
+ GNUNET_MESH_ApplicationType app_type)
+{
+ struct GNUNET_MESH_ConnectPeerByType msg;
+
+ GNUNET_array_append (tunnel->apps, tunnel->napps, app_type);
+
+ msg.header.size = htons (sizeof (struct GNUNET_MESH_ConnectPeerByType));
+ msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD_BY_TYPE);
+ msg.tunnel_id = htonl (tunnel->tid);
+ msg.type = htonl (app_type);
+ send_packet (tunnel->mesh, &msg.header);
+}
+
+
+/**
+ * Ask the mesh to call "notify" once it is ready to transmit the
+ * given number of bytes to the specified "target". If we are not yet
+ * connected to the specified peer, a call to this function will cause
+ * us to try to establish a connection.
+ *
+ * @param tunnel tunnel to use for transmission
+ * @param cork is corking allowed for this transmission?
+ * @param priority how important is the message?
+ * @param maxdelay how long can the message wait?
+ * @param target destination for the message,
+ * NULL for multicast to all tunnel targets
+ * @param notify_size how many bytes of buffer space does notify want?
+ * @param notify function to call when buffer space is available;
+ * will be called with NULL on timeout or if the overall queue
+ * for this peer is larger than queue_size and this is currently
+ * the message with the lowest priority
+ * @param notify_cls closure for notify
+ * @return non-NULL if the notify callback was queued,
+ * NULL if we can not even queue the request (insufficient
+ * memory); if NULL is returned, "notify" will NOT be called.
+ */
+struct GNUNET_MESH_TransmitHandle *
+GNUNET_MESH_notify_transmit_ready (struct GNUNET_MESH_Tunnel *tunnel, int cork,
+ uint32_t priority,
+ struct GNUNET_TIME_Relative maxdelay,
+ const struct GNUNET_PeerIdentity *target,
+ size_t notify_size,
+ GNUNET_CONNECTION_TransmitReadyNotify notify,
+ void *notify_cls)
+{
+ struct GNUNET_MESH_TransmitHandle *th;
+ struct GNUNET_MESH_TransmitHandle *least_priority_th;
+ uint32_t least_priority;
+ size_t overhead;
+
+ GNUNET_assert (NULL != tunnel);
+#if MESH_API_DEBUG
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "mesh: mesh notify transmit ready called\n");
+ if (NULL != target)
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: target %s\n",
+ GNUNET_i2s (target));
+ else
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: target multicast\n");
+#endif
+ GNUNET_assert (NULL != notify);
+ if (tunnel->mesh->npackets >= tunnel->mesh->max_queue_size &&
+ tunnel->npackets > 0)
+ {
+ /* queue full */
+ if (0 == priority)
+ return NULL;
+ th = tunnel->mesh->th_tail;
+ least_priority = priority;
+ least_priority_th = NULL;
+ while (NULL != th)