if (GNUNET_MESSAGE_TYPE_MESH_UNICAST == pq->type ||
GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN == pq->type)
{
- // Should have been removed on destroy children
+ /* Should have been removed on destroy children */
GNUNET_break (0);
}
queue_destroy (pq, GNUNET_YES);
struct GNUNET_PeerIdentity dst_id;
struct MeshFlowControl *fc;
size_t data_size;
+ uint16_t type;
peer->core_transmit = NULL;
t = queue->tunnel;
GNUNET_assert (0 < t->pending_messages);
t->pending_messages--;
+ type = 0;
/* Fill buf */
switch (queue->type)
case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN:
data_size = send_core_data_raw (queue->cls, size, buf);
msg = (struct GNUNET_MessageHeader *) buf;
- switch (ntohs (msg->type)) // Type of preconstructed message
- {
- case GNUNET_MESSAGE_TYPE_MESH_UNICAST:
- 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);
- break;
- default:
- break;
- }
+ type = ntohs (msg->type);
break;
case GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE:
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "********* path create\n");
queue->type);
data_size = 0;
}
- switch (queue->type)
+
+ /* Free queue, but cls was freed by send_core_* */
+ queue_destroy (queue, GNUNET_NO);
+
+ /* Send ACK if needed, after accounting for sent ID in fc->queue_n */
+ switch (type)
{
case GNUNET_MESSAGE_TYPE_MESH_UNICAST:
+ tunnel_send_fwd_ack (t, GNUNET_MESSAGE_TYPE_MESH_UNICAST);
+ break;
case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN:
-// if (cinfo->send_buffer[cinfo->send_buffer_start] != queue)
-// { FIXME
-// 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);
-// }
-// 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);
-// }
+ tunnel_send_bck_ack (t, GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN);
break;
default:
break;
}
- /* Free queue, but cls was freed by send_core_* */
- queue_destroy (queue, GNUNET_NO);
-
if (GNUNET_YES == t->destroy && 0 == t->pending_messages)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "********* destroying tunnel!\n");
&queue_send,
peer);
}
- else
+ else if (NULL != peer->queue_head)
{
- if (NULL != peer->queue_head)
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "********* %s stalled\n",
+ GNUNET_i2s (&my_full_id));
+ if (peer->id == t->next_hop)
+ fc = &t->next_fc;
+ else if (peer->id == t->prev_hop)
+ fc = &t->prev_fc;
+ else
{
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "********* %s stalled\n",
- GNUNET_i2s(&my_full_id));
- if (peer->id == t->next_hop)
- fc = &t->next_fc;
- else
- fc = &t->prev_fc;
- if (GNUNET_SCHEDULER_NO_TASK == fc->poll_task)
- {
- fc->t = t;
- fc->poll_task = GNUNET_SCHEDULER_add_delayed (fc->poll_time,
- &tunnel_poll, fc);
- }
+ GNUNET_break (0);
+ fc = NULL;
+ }
+ if (NULL != fc && GNUNET_SCHEDULER_NO_TASK == fc->poll_task)
+ {
+ fc->t = t;
+ fc->poll_task = GNUNET_SCHEDULER_add_delayed (fc->poll_time,
+ &tunnel_poll, fc);
}
}
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "********* return %d\n", data_size);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "********* Return %d\n", data_size);
return data_size;
}
GNUNET_STATISTICS_update(stats,
"# messages dropped (buffer full)",
1, GNUNET_NO);
- return; // Drop message
+ return; /* Drop message */
}
(*n)++;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
" path is for tunnel %s [%X].\n", GNUNET_i2s (pi), tid);
t = tunnel_get (pi, tid);
- if (NULL == t) // FIXME only for INCOMING tunnels?
+ if (NULL == t)
{
uint32_t opt;
t = tunnel_new (GNUNET_PEER_intern (pi), tid, NULL, 0);
if (NULL == t)
{
- // FIXME notify failure
+ GNUNET_break (0);
return GNUNET_OK;
}
opt = ntohl (msg->opt);
t->queue_max = 1;
}
- // FIXME only assign a local tid if a local client is interested (on demand)
- while (NULL != tunnel_get_incoming (next_local_tid))
- next_local_tid = (next_local_tid + 1) | GNUNET_MESH_LOCAL_TUNNEL_ID_SERV;
- t->local_tid_dest = next_local_tid++;
- next_local_tid = next_local_tid | GNUNET_MESH_LOCAL_TUNNEL_ID_SERV;
- // FIXME end
-
tunnel_reset_timeout (t);
GMC_hash32 (t->local_tid_dest, &hash);
if (GNUNET_OK !=
if (own_pos == size - 1)
{
/* It is for us! Send ack. */
+ // TODO: check port number / client registration
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " It's for us!\n");
peer_info_add_path_to_origin (orig_peer_info, path, GNUNET_NO);
t->dest = myid;
+
+ while (NULL != tunnel_get_incoming (next_local_tid))
+ next_local_tid = (next_local_tid + 1) | GNUNET_MESH_LOCAL_TUNNEL_ID_SERV;
+ t->local_tid_dest = next_local_tid++;
+ next_local_tid = next_local_tid | GNUNET_MESH_LOCAL_TUNNEL_ID_SERV;
+
send_path_ack (t);
}
else
{
struct GNUNET_MESH_ManipulatePath *msg;
struct GNUNET_PeerIdentity *pi;
- struct MeshPeerPath *path;
struct MeshTunnel *t;
unsigned int own_pos;
unsigned int i;
GNUNET_break_op (0);
return GNUNET_OK;
}
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Creating path...\n");
- path = path_new (size);
own_pos = 0;
for (i = 0; i < size; i++)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " ... adding %s\n",
- GNUNET_i2s (&pi[i]));
- path->peers[i] = GNUNET_PEER_intern (&pi[i]);
- if (path->peers[i] == myid)
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " %u: %s\n", i, GNUNET_i2s (&pi[i]));
+ if (GNUNET_PEER_search (&pi[i]) == myid)
own_pos = i;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Own position: %u\n", own_pos);
- if (own_pos < path->length - 1)
- send_prebuilt_message (message, path->peers[own_pos + 1], t);
+ if (own_pos < size - 1)
+ send_prebuilt_message (message, t->next_hop, t);
else
send_client_tunnel_destroy (t);
-// tunnel_delete_peer (t, path->peers[path->length - 1]); FIXME
- path_destroy (path);
return GNUNET_OK;
}
{
struct GNUNET_MESH_Poll *msg;
struct MeshTunnel *t;
+ GNUNET_PEER_Id id;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got an POLL packet from %s!\n",
GNUNET_i2s (peer));
}
/* Is this a forward or backward ACK? */
- if (t->prev_hop != GNUNET_PEER_search(peer))
+ id = GNUNET_PEER_search(peer);
+ if (t->next_hop == id)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " from FWD\n");
- /* FIXME cinfo->bck_ack = cinfo->fwd_pid; // mark as ready to send */
tunnel_send_bck_ack (t, GNUNET_MESSAGE_TYPE_MESH_POLL);
}
- else
+ else if (t->prev_hop == id)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " from BCK\n");
tunnel_send_fwd_ack (t, GNUNET_MESSAGE_TYPE_MESH_POLL);
}
+ else
+ GNUNET_break (0);
return GNUNET_OK;
}