uint32_t bck_ack;
/**
- * Circular buffer pointing to MeshPeerQueue elements.
- * Size determined by the tunnel queue size.
+ * Circular buffer pointing to MeshPeerQueue elements for all
+ * payload traffic going to this child.
+ * Size determined by the tunnel queue size (@c t->fwd_queue_max).
*/
struct MeshPeerQueue **send_buffer;
}
info->peer = neighbor;
if (GNUNET_MESSAGE_TYPE_MESH_PATH_ACK == type)
- {
- /*
- * TODO: in this case we only need the service to retransmit
- * the message down the path. If we pass the real type to queue_add,
- * queue_send will try to build the message from scratch. This can
- * probably be done by some other way instead of deleteing the type
- * info.
- */
type = 0;
- }
queue_add (info,
type,
size,
}
+/**
+ * Sends a PATH ACK message in reponse to a received PATH_CREATE directed to us.
+ *
+ * @param t Tunnel which to confirm.
+ */
+static void
+send_path_ack (struct MeshTunnel *t)
+{
+ struct MeshTransmissionDescriptor *info;
+ struct GNUNET_PeerIdentity id;
+ GNUNET_PEER_Id peer;
+
+ peer = tree_get_predecessor (t->tree);
+ GNUNET_PEER_resolve (peer, &id);
+ info = GNUNET_malloc (sizeof (struct MeshTransmissionDescriptor));
+ info->origin = &t->id;
+ info->peer = GNUNET_CONTAINER_multihashmap_get (peers, &id.hashPubKey);
+ GNUNET_assert (NULL != info->peer);
+
+ queue_add (info,
+ GNUNET_MESSAGE_TYPE_MESH_PATH_ACK,
+ sizeof (struct GNUNET_MESH_PathACK),
+ info->peer,
+ t);
+}
+
+
/**
* Try to establish a new connection to this peer.
* Use the best path for the given tunnel.
/**
- * Iterator to free MeshTunnelChildInfo of tunnel children.
+ * @brief Iterator to destroy MeshTunnelChildInfo of tunnel children.
+ *
+ * Destroys queue elements of all waiting transmissions and frees all memory
+ * used by the struct and its elements.
*
* @param cls Closure (tunnel info).
* @param key Hash of GNUNET_PEER_Id (unused).
{
i = (cinfo->send_buffer_start + c) % t->fwd_queue_max;
if (NULL != cinfo->send_buffer[i])
- queue_destroy(cinfo->send_buffer[i], GNUNET_YES);
+ queue_destroy (cinfo->send_buffer[i], GNUNET_YES);
else
GNUNET_break (0);
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%u %u\n", c, cinfo->send_buffer_n);
ctx.t = t;
ctx.max_child_ack = 0;
ctx.nchildren = 0;
+ ctx.init = GNUNET_NO;
tree_iterate_children (t->tree, tunnel_get_child_fwd_ack, &ctx);
if (0 == ctx.nchildren)
GNUNET_CRYPTO_hash (&t->id, sizeof (struct MESH_TunnelID), &hash);
if (GNUNET_YES != GNUNET_CONTAINER_multihashmap_remove (tunnels, &hash, t))
{
+ GNUNET_break (0);
r = GNUNET_SYSERR;
}
- GNUNET_CRYPTO_hash (&t->local_tid, sizeof (MESH_TunnelNumber), &hash);
- if (NULL != c &&
- GNUNET_YES !=
- GNUNET_CONTAINER_multihashmap_remove (c->own_tunnels, &hash, t))
+ if (NULL != c)
{
- r = GNUNET_SYSERR;
+ GNUNET_CRYPTO_hash (&t->local_tid, sizeof (MESH_TunnelNumber), &hash);
+ if (GNUNET_YES !=
+ GNUNET_CONTAINER_multihashmap_remove (c->own_tunnels, &hash, t))
+ {
+ GNUNET_break (0);
+ r = GNUNET_SYSERR;
+ }
}
+
GNUNET_CRYPTO_hash (&t->local_tid_dest, sizeof (MESH_TunnelNumber), &hash);
for (i = 0; i < t->nclients; i++)
{
if (GNUNET_YES !=
GNUNET_CONTAINER_multihashmap_remove (c->incoming_tunnels, &hash, t))
{
+ GNUNET_break (0);
r = GNUNET_SYSERR;
}
}
if (GNUNET_YES !=
GNUNET_CONTAINER_multihashmap_remove (c->ignore_tunnels, &hash, t))
{
+ GNUNET_break (0);
r = GNUNET_SYSERR;
}
}
+
if (t->nclients > 0)
{
if (GNUNET_YES !=
GNUNET_CONTAINER_multihashmap_remove (incoming_tunnels, &hash, t))
{
+ GNUNET_break (0);
r = GNUNET_SYSERR;
}
GNUNET_free (t->clients);
}
+
if (NULL != t->peers)
{
GNUNET_CONTAINER_multihashmap_iterate (t->peers, &peer_info_delete_tunnel,
* @param key the hash of the local tunnel id (used to access the hashmap)
* @param value the value stored at the key (tunnel to destroy)
*
- * @return GNUNET_OK on success
+ * @return GNUNET_OK, keep iterating.
*/
static int
tunnel_destroy_iterator (void *cls, const struct GNUNET_HashCode * key, void *value)
{
struct MeshTunnel *t = value;
struct MeshClient *c = cls;
- int r;
send_client_tunnel_disconnect(t, c);
if (c != t->owner)
return GNUNET_OK;
}
tunnel_send_destroy(t);
- r = tunnel_destroy (t);
- return r;
+ t->owner = NULL;
+ t->destroy = GNUNET_YES;
+
+ return GNUNET_OK;
}
if (GNUNET_YES == t->nobuffer)
opt |= MESH_TUNNEL_OPT_NOBUFFER;
msg->opt = htonl(opt);
+ msg->reserved = 0;
peer_ptr = (struct GNUNET_PeerIdentity *) &msg[1];
for (i = 0; i < p->length; i++)
{
struct MeshTransmissionDescriptor *dd;
struct MeshPathInfo *path_info;
+ struct MeshTunnelChildInfo *cinfo;
+ struct GNUNET_PeerIdentity id;
+ unsigned int i;
+ unsigned int max;
if (GNUNET_YES == clear_cls)
{
switch (queue->type)
{
- case GNUNET_MESSAGE_TYPE_MESH_UNICAST:
- case GNUNET_MESSAGE_TYPE_MESH_MULTICAST:
- case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN:
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " type payload\n");
+ case GNUNET_MESSAGE_TYPE_MESH_TUNNEL_DESTROY:
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, " cancelling TUNNEL_DESTROY\n");
+ /* fall through */
+ case GNUNET_MESSAGE_TYPE_MESH_UNICAST:
+ case GNUNET_MESSAGE_TYPE_MESH_MULTICAST:
+ case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN:
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ " type prebuilt (payload, tunnel destroy)\n");
dd = queue->cls;
data_descriptor_decrement_rc (dd->mesh_data);
break;
- case GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE:
+ case GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE:
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " type create path\n");
path_info = queue->cls;
path_destroy (path_info->path);
break;
- default:
+ default:
GNUNET_break (0);
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
" type %s unknown!\n",
GNUNET_CONTAINER_DLL_remove (queue->peer->queue_head,
queue->peer->queue_tail,
queue);
+
+ /* 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);
}
size_t data_size;
peer->core_transmit = NULL;
-
+
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "********* Queue send\n");
- queue = queue_get_next(peer);
+ queue = queue_get_next (peer);
- /* Queue has no internal mesh traffic not sendable payload */
+ /* Queue has no internal mesh traffic nor sendable payload */
if (NULL == queue)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "********* not ready, return\n");
if (NULL == peer->queue_head)
- GNUNET_break(0); // Should've been canceled
+ GNUNET_break (0); // Should've been canceled
return 0;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "********* not empty\n");
/* Check if buffer size is enough for the message */
if (queue->size > size)
{
-
-
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"********* not enough room, reissue\n");
peer->core_transmit =
- GNUNET_CORE_notify_transmit_ready(core_handle,
- 0,
- 0,
- GNUNET_TIME_UNIT_FOREVER_REL,
- &dst_id,
- queue->size,
- &queue_send,
- peer);
+ GNUNET_CORE_notify_transmit_ready (core_handle,
+ 0,
+ 0,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ &dst_id,
+ queue->size,
+ &queue_send,
+ peer);
return 0;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "********* size ok\n");
tunnel_send_fwd_ack (t, GNUNET_MESSAGE_TYPE_MESH_UNICAST);
break;
case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN:
- tunnel_send_bck_ack(t, GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN);
+ tunnel_send_bck_ack (t, GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN);
break;
default:
break;
break;
case GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE:
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "********* path create\n");
- data_size = send_core_path_create(queue->cls, size, buf);
+ data_size = send_core_path_create (queue->cls, size, buf);
break;
case GNUNET_MESSAGE_TYPE_MESH_PATH_ACK:
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "********* path ack\n");
- data_size = send_core_path_ack(queue->cls, size, buf);
+ data_size = send_core_path_ack (queue->cls, size, buf);
break;
case GNUNET_MESSAGE_TYPE_MESH_PATH_KEEPALIVE:
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "********* path keepalive\n");
- data_size = send_core_data_multicast(queue->cls, size, buf);
+ data_size = send_core_data_multicast (queue->cls, size, buf);
break;
default:
GNUNET_break (0);
case GNUNET_MESSAGE_TYPE_MESH_UNICAST:
case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN:
case GNUNET_MESSAGE_TYPE_MESH_MULTICAST:
- cinfo = tunnel_get_neighbor_fc(t, &dst_id);
+ cinfo = tunnel_get_neighbor_fc (t, &dst_id);
if (cinfo->send_buffer[cinfo->send_buffer_start] != queue)
{
- GNUNET_break(0);
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ GNUNET_break (0);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"at pos %u (%p) != %p\n",
cinfo->send_buffer_start,
cinfo->send_buffer[cinfo->send_buffer_start],
queue);
}
- GNUNET_break(cinfo->send_buffer_n > 0);
- cinfo->send_buffer[cinfo->send_buffer_start] = NULL;
- cinfo->send_buffer_n--;
- cinfo->send_buffer_start++;
- cinfo->send_buffer_start %= t->fwd_queue_max;
+ if (cinfo->send_buffer_n > 0)
+ {
+ cinfo->send_buffer[cinfo->send_buffer_start] = NULL;
+ cinfo->send_buffer_n--;
+ cinfo->send_buffer_start++;
+ cinfo->send_buffer_start %= t->fwd_queue_max;
+ }
+ else
+ {
+ GNUNET_break (0);
+ }
break;
default:
break;
if (NULL == dst->core_transmit)
{
dst->core_transmit =
- GNUNET_CORE_notify_transmit_ready(core_handle,
- 0,
- 0,
- GNUNET_TIME_UNIT_FOREVER_REL,
- &id,
- size,
- &queue_send,
- dst);
+ GNUNET_CORE_notify_transmit_ready (core_handle,
+ 0,
+ 0,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ &id,
+ size,
+ &queue_send,
+ dst);
}
if (NULL == n) // Is this internal mesh traffic?
return;
if (NULL != cinfo->send_buffer[i])
{
GNUNET_break (cinfo->send_buffer_n == t->fwd_queue_max); // aka i == start
- queue_destroy(cinfo->send_buffer[cinfo->send_buffer_start], GNUNET_YES);
+ queue_destroy (cinfo->send_buffer[cinfo->send_buffer_start], GNUNET_YES);
cinfo->send_buffer_start++;
cinfo->send_buffer_start %= t->fwd_queue_max;
- cinfo->send_buffer_n--;
+ }
+ else
+ {
+ cinfo->send_buffer_n++;
}
cinfo->send_buffer[i] = queue;
- cinfo->send_buffer_n++;
if (cinfo->send_buffer_n > t->fwd_queue_max)
{
GNUNET_break (0);
if (own_pos == size - 1)
{
/* It is for us! Send ack. */
- struct MeshTransmissionDescriptor *info;
-
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " It's for us!\n");
peer_info_add_path_to_origin (orig_peer_info, path, GNUNET_NO);
if (NULL == t->peers)
{
- /* New tunnel! Notify clients on data. */
+ /* New tunnel! Notify clients on first payload message. */
t->peers = GNUNET_CONTAINER_multihashmap_create (4);
}
GNUNET_break (GNUNET_SYSERR !=
peer_info_get
(&my_full_id),
GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE));
- info = GNUNET_malloc (sizeof (struct MeshTransmissionDescriptor));
- info->origin = &t->id;
- info->peer = GNUNET_CONTAINER_multihashmap_get (peers, &peer->hashPubKey);
- GNUNET_assert (NULL != info->peer);
- // FIXME don't use queue_add directly, abstact in a send_message_* funcion
- queue_add(info,
- GNUNET_MESSAGE_TYPE_MESH_PATH_ACK,
- sizeof (struct GNUNET_MESH_PathACK),
- info->peer,
- t);
+ send_path_ack (t);
}
else
{
while (NULL != q)
{
n = q->next;
- if (q->peer == pi)
- {
- /* try to reroute this traffic instead */
- queue_destroy(q, GNUNET_YES);
- }
+ /* TODO try to reroute this traffic instead */
+ queue_destroy(q, GNUNET_YES);
q = n;
}
+ if (NULL != pi->core_transmit)
+ {
+ GNUNET_CORE_notify_transmit_ready_cancel(pi->core_transmit);
+ pi->core_transmit = NULL;
+ }
peer_info_remove_path (pi, pi->id, myid);
if (myid == pi->id)
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Mesh for peer [%s] FWD ACKs %u, BCK ACKs %u\n",
GNUNET_i2s(&my_full_id), debug_fwd_ack, debug_bck_ack);
-
return ret;
}