+
+ /* Delete from child_fc in the appropiate tunnel */
+ max = queue->tunnel->fwd_queue_max;
+ GNUNET_PEER_resolve (queue->peer->id, &id);
+ cinfo = tunnel_get_neighbor_fc (queue->tunnel, &id);
+ for (i = 0; i < cinfo->send_buffer_n; i++)
+ {
+ unsigned int i2;
+ i2 = (cinfo->send_buffer_start + i) % max;
+ if (cinfo->send_buffer[i2] == queue)
+ {
+ /* Found corresponding entry in the send_buffer. Move all others back. */
+ unsigned int j;
+ unsigned int j2;
+ unsigned int j3;
+
+ for (j = i, j2 = 0, j3 = 0; j < cinfo->send_buffer_n - 1; j++)
+ {
+ j2 = (cinfo->send_buffer_start + j) % max;
+ j3 = (cinfo->send_buffer_start + j + 1) % max;
+ cinfo->send_buffer[j2] = cinfo->send_buffer[j3];
+ }
+
+ cinfo->send_buffer[j3] = NULL;
+
+ cinfo->send_buffer_n--;
+ }
+ }
+ //queue->
+
+ GNUNET_free (queue);
+}
+
+
+/**
+ * @brief Get the next transmittable message from the queue.
+ *
+ * This will be the head, except in the case of being a data packet
+ * not allowed by the destination peer.
+ *
+ * @param peer Destination peer.
+ *
+ * @return The next viable MeshPeerQueue element to send to that peer.
+ * NULL when there are no transmittable messages.
+ */
+struct MeshPeerQueue *
+queue_get_next (const struct MeshPeerInfo *peer)
+{
+ struct MeshPeerQueue *q;
+ struct MeshTunnel *t;
+ struct MeshTransmissionDescriptor *info;
+ struct MeshTunnelChildInfo *cinfo;
+ struct GNUNET_MESH_Unicast *ucast;
+ struct GNUNET_MESH_ToOrigin *to_orig;
+ struct GNUNET_MESH_Multicast *mcast;
+ struct GNUNET_PeerIdentity id;
+ uint32_t pid;
+ uint32_t ack;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "********* selecting message\n");
+ for (q = peer->queue_head; NULL != q; q = q->next)
+ {
+ t = q->tunnel;
+ info = q->cls;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "********* %s\n",
+ GNUNET_MESH_DEBUG_M2S(q->type));
+ switch (q->type)
+ {
+ case GNUNET_MESSAGE_TYPE_MESH_UNICAST:
+ ucast = (struct GNUNET_MESH_Unicast *) info->mesh_data->data;
+ pid = ntohl (ucast->pid);
+ GNUNET_PEER_resolve (info->peer->id, &id);
+ cinfo = tunnel_get_neighbor_fc(t, &id);
+ ack = cinfo->fwd_ack;
+ break;
+ case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN:
+ to_orig = (struct GNUNET_MESH_ToOrigin *) info->mesh_data->data;
+ pid = ntohl (to_orig->pid);
+ ack = t->bck_ack;
+ break;
+ case GNUNET_MESSAGE_TYPE_MESH_MULTICAST:
+ mcast = (struct GNUNET_MESH_Multicast *) info->mesh_data->data;
+ if (GNUNET_MESSAGE_TYPE_MESH_MULTICAST != ntohs(mcast->header.type))
+ {
+ // Not a multicast payload: multicast control traffic (destroy, etc)
+ return q;
+ }
+ pid = ntohl (mcast->pid);
+ GNUNET_PEER_resolve (info->peer->id, &id);
+ cinfo = tunnel_get_neighbor_fc(t, &id);
+ ack = cinfo->fwd_ack;
+ break;
+ default:
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "********* OK!\n");
+ return q;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "********* ACK: %u, PID: %u\n",
+ ack, pid);
+ if (GNUNET_NO == GMC_is_pid_bigger(pid, ack))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "********* OK!\n");
+ return q;
+ }
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "********* NEXT!\n");
+ }
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "********* nothing found\n");
+ return NULL;
+}
+