/**
* Destroy flag: if true, destroy on last message.
*/
- int destroy;
+ GNUNET_SCHEDULER_TaskIdentifier destroy_task;
/**
* Queued messages, to transmit once tunnel gets connected.
c = tunnel_get_connection (t);
if (NULL == c)
{
- if (GNUNET_YES == t->destroy || MESH_TUNNEL3_SEARCHING != t->cstate)
+ if (GNUNET_SCHEDULER_NO_TASK != t->destroy_task
+ || MESH_TUNNEL3_SEARCHING != t->cstate)
{
GNUNET_break (0);
GMT_debug (t);
return;
}
- if (GNUNET_NO != t->destroy)
+ if (GNUNET_SCHEDULER_NO_TASK != t->destroy_task)
{
LOG (GNUNET_ERROR_TYPE_DEBUG, " being destroyed, why bother\n");
return;
c = tunnel_get_connection (t);
if (NULL == c)
{
- GNUNET_break (GNUNET_YES == t->destroy || MESH_TUNNEL3_READY != t->cstate);
+ GNUNET_break (GNUNET_SCHEDULER_NO_TASK != t->destroy_task
+ || MESH_TUNNEL3_READY != t->cstate);
GMT_debug (t);
return;
}
/* Start new connections if needed */
if (NULL == t->connection_head
- && GNUNET_NO == t->destroy
+ && GNUNET_SCHEDULER_NO_TASK == t->destroy_task
&& GNUNET_NO == shutting_down)
{
LOG (GNUNET_ERROR_TYPE_DEBUG, " no more connections, getting new ones\n");
LOG (GNUNET_ERROR_TYPE_DEBUG, " adding %p to %p\n", aux, t->channel_head);
GNUNET_CONTAINER_DLL_insert_tail (t->channel_head, t->channel_tail, aux);
- if (GNUNET_YES == t->destroy)
+ if (GNUNET_SCHEDULER_NO_TASK != t->destroy_task)
{
- t->destroy = GNUNET_NO;
+ GNUNET_SCHEDULER_cancel (t->destroy_task);
+ t->destroy_task = GNUNET_SCHEDULER_NO_TASK;
LOG (GNUNET_ERROR_TYPE_DEBUG, " undo destroy!\n");
}
}
}
+/**
+ * @brief Destroy a tunnel and free all resources.
+ *
+ * Should only be called a while after the tunnel has been marked as destroyed,
+ * in case there is a new channel added to the same peer shortly after marking
+ * the tunnel. This way we avoid a new public key handshake.
+ *
+ * @param cls Closure (tunnel to destroy).
+ * @param tc Task context.
+ */
+static void
+tunnel_destroy (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ struct MeshTunnel3 *t = cls;
+
+ GMT_destroy (t);
+}
+
+
/**
* Tunnel is empty: destroy it.
*
t->kx_ctx = NULL;
}
t->cstate = MESH_TUNNEL3_NEW;
- t->destroy = GNUNET_YES;
+ t->destroy_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
+ &tunnel_destroy, t);
}
if (NULL == t)
return;
- t->destroy = 2;
+ if (GNUNET_SCHEDULER_NO_TASK != t->destroy_task)
+ {
+ GNUNET_SCHEDULER_cancel (t->destroy_task);
+ t->destroy_task = GNUNET_SCHEDULER_NO_TASK;
+ }
LOG (GNUNET_ERROR_TYPE_DEBUG, "destroying tunnel %s\n", GMP_2s (t->peer));
t->kx_ctx, t->rekey_task);
LOG (GNUNET_ERROR_TYPE_DEBUG, " tq_head %p, tq_tail %p\n",
t->tq_head, t->tq_tail);
- LOG (GNUNET_ERROR_TYPE_DEBUG, " destroy %u\n", t->destroy);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, " destroy %u\n", t->destroy_task);
LOG (GNUNET_ERROR_TYPE_DEBUG, " channels:\n");
for (iterch = t->channel_head; NULL != iterch; iterch = iterch->next)