struct GNUNET_MESH_TransmitHandle *prev;
/**
- * Tunnel this message is sent over (may be NULL for control messages).
+ * Tunnel this message is sent on / for (may be NULL for control messages).
*/
struct GNUNET_MESH_Tunnel *tunnel;
* Auxiliary function to send an already constructed packet to the service.
* Takes care of creating a new queue element, copying the message and
* calling the tmt_rdy function if necessary.
+ *
* @param h mesh handle
* @param msg message to transmit
+ * @param tunnel tunnel this send is related to (NULL if N/A)
*/
static void
send_packet (struct GNUNET_MESH_Handle *h,
- const struct GNUNET_MessageHeader *msg);
+ const struct GNUNET_MessageHeader *msg,
+ struct GNUNET_MESH_Tunnel *tunnel);
/**
"mesh: Sending %lu bytes long message %d types and %d apps\n",
ntohs (msg->header.size), ntypes, napps);
#endif
- send_packet (h, &msg->header);
+ send_packet (h, &msg->header, NULL);
}
}
tmsg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE);
tmsg.header.size = htons (sizeof (struct GNUNET_MESH_TunnelMessage));
tmsg.tunnel_id = htonl (t->tid);
- send_packet (h, &tmsg.header);
+ send_packet (h, &tmsg.header, t);
pmsg.header.size = htons (sizeof (struct GNUNET_MESH_PeerControl));
pmsg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD);
t->disconnect_handler (t->cls, &pmsg.peer);
/* If the tunnel was "by type", dont connect individual peers */
if (0 == t->napps)
- send_packet (t->mesh, &pmsg.header);
+ send_packet (t->mesh, &pmsg.header, t);
}
/* Reconnect all types, if any */
for (i = 0; i < t->napps; i++)
msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD_BY_TYPE);
msg.tunnel_id = htonl (t->tid);
msg.type = htonl (t->apps[i]);
- send_packet (t->mesh, &msg.header);
+ send_packet (t->mesh, &msg.header, t);
}
}
return GNUNET_YES;
* Auxiliary function to send an already constructed packet to the service.
* Takes care of creating a new queue element, copying the message and
* calling the tmt_rdy function if necessary.
+ *
* @param h mesh handle
* @param msg message to transmit
+ * @param tunnel tunnel this send is related to (NULL if N/A)
*/
static void
send_packet (struct GNUNET_MESH_Handle *h,
- const struct GNUNET_MessageHeader *msg)
+ const struct GNUNET_MessageHeader *msg,
+ struct GNUNET_MESH_Tunnel *tunnel)
{
struct GNUNET_MESH_TransmitHandle *th;
size_t msize;
th->priority = UINT32_MAX;
th->timeout = GNUNET_TIME_UNIT_FOREVER_ABS;
th->size = msize;
+ th->tunnel = tunnel;
memcpy (&th[1], msg, msize);
add_to_queue (h, th);
if (NULL != h->th)
while (NULL != t)
{
aux = t->next;
+ if (t->tid < GNUNET_MESH_LOCAL_TUNNEL_ID_SERV)
+ {
+ GNUNET_break (0);
+#if MESH_API_DEBUG
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: tunnel %X not destroyed\n",
+ t->tid);
+#endif
+ }
destroy_tunnel (t, GNUNET_YES);
t = aux;
}
{
struct GNUNET_MessageHeader *msg;
- /* Make sure it is a connect packet (everything else should have been
+ /* Make sure it is an allowed packet (everything else should have been
* already canceled).
*/
GNUNET_break (UINT32_MAX == th->priority);
GNUNET_break (NULL == th->notify);
msg = (struct GNUNET_MessageHeader *) &th[1];
- if (GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT != ntohs(msg->type))
+ switch (ntohs(msg->type))
{
- GNUNET_break (0);
+ case GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT:
+ case GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY:
+ break;
+ default:
+ GNUNET_break (0);
#if MESH_API_DEBUG
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: expected %u, got %u\n",
- GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT, ntohs(msg->type));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: unexpected msg %u\n",
+ ntohs(msg->type));
#endif
}
msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE);
msg.header.size = htons (sizeof (struct GNUNET_MESH_TunnelMessage));
msg.tunnel_id = htonl (t->tid);
- send_packet (h, &msg.header);
+ send_packet (h, &msg.header, t);
return t;
}
{
struct GNUNET_MESH_Handle *h;
struct GNUNET_MESH_TunnelMessage msg;
+ struct GNUNET_MESH_TransmitHandle *th;
LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: Destroying tunnel\n");
h = tunnel->mesh;
msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY);
msg.header.size = htons (sizeof (struct GNUNET_MESH_TunnelMessage));
msg.tunnel_id = htonl (tunnel->tid);
+ th = h->th_head;
+ while (th != NULL)
+ {
+ struct GNUNET_MESH_TransmitHandle *aux;
+ if (th->tunnel == tunnel)
+ {
+ aux = th->next;
+ /* FIXME call the handler? */
+ if (NULL != th->notify)
+ th->notify (th->notify_cls, 0, NULL);
+ GNUNET_CONTAINER_DLL_remove (h->th_head, h->th_tail, th);
+ GNUNET_free (th);
+ th = aux;
+ }
+ else
+ th = th->next;
+ }
+
destroy_tunnel (tunnel, GNUNET_NO);
- send_packet (h, &msg.header);
+ send_packet (h, &msg.header, tunnel);
}
msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD);
msg.tunnel_id = htonl (tunnel->tid);
msg.peer = *peer;
- send_packet (tunnel->mesh, &msg.header);
+ send_packet (tunnel->mesh, &msg.header, tunnel);
return;
}
msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_DEL);
msg.tunnel_id = htonl (tunnel->tid);
memcpy (&msg.peer, peer, sizeof (struct GNUNET_PeerIdentity));
- send_packet (tunnel->mesh, &msg.header);
+ send_packet (tunnel->mesh, &msg.header, tunnel);
}
msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD_BY_TYPE);
msg.tunnel_id = htonl (tunnel->tid);
msg.type = htonl (app_type);
- send_packet (tunnel->mesh, &msg.header);
+ send_packet (tunnel->mesh, &msg.header, tunnel);
}