+ * Send ACK on one or more channels due to buffer in connections..
+ *
+ * @param t Channel which has some free buffer space.
+ * @param fwd Is this for FWD traffic? (ACK goes to root)
+ */
+void
+GMT_unchoke_channels (struct MeshTunnel3 *t, int fwd)
+{
+ struct MeshTChannel *iter;
+ unsigned int buffer;
+ unsigned int channels = GMT_count_channels (t);
+ unsigned int choked_n;
+ struct MeshChannel *choked[channels];
+
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "GMT_unchoke_channels on %s\n", GMT_2s (t));
+
+ if (NULL == t)
+ {
+ GNUNET_break (0);
+ return;
+ }
+
+ /* Get buffer space */
+ buffer = GMT_get_buffer (t, fwd);
+ if (0 == buffer)
+ {
+ return;
+ }
+
+ /* Count and remember choked channels */
+ choked_n = 0;
+ for (iter = t->channel_head; NULL != iter; iter = iter->next)
+ {
+ if (GNUNET_NO == GMCH_get_allowed (iter->ch, fwd))
+ {
+ choked[choked_n++] = iter->ch;
+ }
+ }
+
+ /* Unchoke random channels */
+ while (0 < buffer && 0 < choked_n)
+ {
+ unsigned int r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
+ choked_n);
+ GMCH_allow_client (choked[r], fwd);
+ choked_n--;
+ buffer--;
+ choked[r] = choked[choked_n];
+ }
+}
+
+
+/**
+ * Send ACK on one or more connections due to buffer space to the client.
+ *
+ * Iterates all connections of the tunnel and sends ACKs appropriately.
+ *
+ * @param t Tunnel.
+ * @param fwd Is this in for FWD traffic? (ACK goes dest->root)
+ */
+void
+GMT_send_acks (struct MeshTunnel3 *t, int fwd)
+{
+ struct MeshTConnection *iter;
+ uint32_t allowed;
+ uint32_t to_allow;
+ uint32_t allow_per_connection;
+ unsigned int cs;
+ unsigned int buffer;
+
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Tunnel send %s ACKs on %s\n",
+ fwd ? "FWD" : "BCK", GMT_2s (t));
+
+ if (NULL == t)
+ {
+ GNUNET_break (0);
+ return;
+ }
+ if (NULL == t->channel_head ||
+ GNUNET_NO == GMCH_is_origin (t->channel_head->ch, !fwd))
+ {
+ GNUNET_break (0);
+ return;
+ }
+
+ buffer = GMT_get_buffer (t, fwd);
+
+ /* Count connections, how many messages are already allowed */
+ cs = GMT_count_connections (t);
+ for (allowed = 0, iter = t->connection_head; NULL != iter; iter = iter->next)
+ {
+ allowed += GMC_get_allowed (iter->c, fwd);
+ }
+
+ /* Make sure there is no overflow */
+ if (allowed > buffer)
+ {
+ GNUNET_break (0);
+ return;
+ }
+
+ /* Authorize connections to send more data */
+ to_allow = buffer; /* - allowed; */
+
+ for (iter = t->connection_head; NULL != iter && to_allow > 0; iter = iter->next)
+ {
+ allow_per_connection = to_allow/cs;
+ to_allow -= allow_per_connection;
+ cs--;
+ if (GMC_get_allowed (iter->c, fwd) > 64 / 3)
+ {
+ continue;
+ }
+ GMC_allow (iter->c, buffer, fwd);
+ }
+
+ GNUNET_break (to_allow == 0);
+}
+
+
+/**
+ * Sends an already built message on a tunnel, GMT_encrypting it and