+/**
+ * Send an ACK informing the children nodes about the available buffer space.
+ * In case there is no child node, inform the destination clients.
+ * If buffering is off, send only on behalf of root (can be self).
+ * If buffering is on, send when sent to predecessor and buffer space is free.
+ * Note that although the name is bck_ack, the BCK mean backwards *traffic*,
+ * the ACK itself goes "forward" (towards children/clients).
+ *
+ * @param t Tunnel on which to send the ACK.
+ * @param type Type of message that triggered the ACK transmission.
+ */
+static void
+tunnel_send_bck_ack (struct MeshTunnel *t, uint16_t type)
+{
+ struct GNUNET_MESH_ACK msg;
+ struct GNUNET_PeerIdentity id;
+ uint32_t ack;
+
+ if (NULL != t->owner)
+ {
+ send_client_tunnel_ack (t->owner, t);
+ return;
+ }
+ /* Is it after unicast / multicast retransmission? */
+ if (GNUNET_MESSAGE_TYPE_MESH_ACK != type)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ACK via DATA retransmission\n");
+ if (GNUNET_YES == t->nobuffer)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Not sending ACK, nobuffer\n");
+ return;
+ }
+ if (t->queue_max > t->queue_n * 2)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Not sending ACK, buffer free\n");
+ return;
+ }
+ }
+
+ /* Ok, ACK might be necessary, what PID to ACK? */
+ ack = tunnel_get_bck_ack (t);
+
+ /* If speed_min and not all children have ack'd, dont send yet */
+ if (ack == t->last_ack)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Not sending ACK, not ready\n");
+ return;
+ }
+
+ t->last_ack = ack;
+ msg.pid = htonl (ack);
+
+ GNUNET_PEER_resolve (tree_get_predecessor (t->tree), &id);
+
+ msg.header.size = htons (sizeof (msg));
+ msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_ACK);
+ msg.tid = htonl (t->id.tid);
+ GNUNET_PEER_resolve(t->id.oid, &msg.oid);
+ send_message (&msg.header, &id, t);
+}
+
+