aboutsummaryrefslogtreecommitdiff
path: root/src/mesh/gnunet-service-mesh_tunnel.c
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2014-01-07 09:38:22 +0000
committerBart Polot <bart@net.in.tum.de>2014-01-07 09:38:22 +0000
commitf2d27a480dea985dc49f1b9fe7a57eb21ee18d42 (patch)
tree54cff5f594651f24e58278635a305239878bb3f0 /src/mesh/gnunet-service-mesh_tunnel.c
parent0da95dcf912658ec3e4385c8969f43f666c0e27d (diff)
downloadgnunet-f2d27a480dea985dc49f1b9fe7a57eb21ee18d42.tar.gz
gnunet-f2d27a480dea985dc49f1b9fe7a57eb21ee18d42.zip
- delay tunnel destruction 1 min to avoid rekeying
Diffstat (limited to 'src/mesh/gnunet-service-mesh_tunnel.c')
-rw-r--r--src/mesh/gnunet-service-mesh_tunnel.c47
1 files changed, 37 insertions, 10 deletions
diff --git a/src/mesh/gnunet-service-mesh_tunnel.c b/src/mesh/gnunet-service-mesh_tunnel.c
index 07375a43c..672905b5e 100644
--- a/src/mesh/gnunet-service-mesh_tunnel.c
+++ b/src/mesh/gnunet-service-mesh_tunnel.c
@@ -136,7 +136,7 @@ struct MeshTunnel3
136 /** 136 /**
137 * Destroy flag: if true, destroy on last message. 137 * Destroy flag: if true, destroy on last message.
138 */ 138 */
139 int destroy; 139 GNUNET_SCHEDULER_TaskIdentifier destroy_task;
140 140
141 /** 141 /**
142 * Queued messages, to transmit once tunnel gets connected. 142 * Queued messages, to transmit once tunnel gets connected.
@@ -779,7 +779,8 @@ send_prebuilt_message (const struct GNUNET_MessageHeader *message,
779 c = tunnel_get_connection (t); 779 c = tunnel_get_connection (t);
780 if (NULL == c) 780 if (NULL == c)
781 { 781 {
782 if (GNUNET_YES == t->destroy || MESH_TUNNEL3_SEARCHING != t->cstate) 782 if (GNUNET_SCHEDULER_NO_TASK != t->destroy_task
783 || MESH_TUNNEL3_SEARCHING != t->cstate)
783 { 784 {
784 GNUNET_break (0); 785 GNUNET_break (0);
785 GMT_debug (t); 786 GMT_debug (t);
@@ -905,7 +906,7 @@ send_kx (struct MeshTunnel3 *t,
905 return; 906 return;
906 } 907 }
907 908
908 if (GNUNET_NO != t->destroy) 909 if (GNUNET_SCHEDULER_NO_TASK != t->destroy_task)
909 { 910 {
910 LOG (GNUNET_ERROR_TYPE_DEBUG, " being destroyed, why bother\n"); 911 LOG (GNUNET_ERROR_TYPE_DEBUG, " being destroyed, why bother\n");
911 return; 912 return;
@@ -925,7 +926,8 @@ send_kx (struct MeshTunnel3 *t,
925 c = tunnel_get_connection (t); 926 c = tunnel_get_connection (t);
926 if (NULL == c) 927 if (NULL == c)
927 { 928 {
928 GNUNET_break (GNUNET_YES == t->destroy || MESH_TUNNEL3_READY != t->cstate); 929 GNUNET_break (GNUNET_SCHEDULER_NO_TASK != t->destroy_task
930 || MESH_TUNNEL3_READY != t->cstate);
929 GMT_debug (t); 931 GMT_debug (t);
930 return; 932 return;
931 } 933 }
@@ -1869,7 +1871,7 @@ GMT_remove_connection (struct MeshTunnel3 *t,
1869 1871
1870 /* Start new connections if needed */ 1872 /* Start new connections if needed */
1871 if (NULL == t->connection_head 1873 if (NULL == t->connection_head
1872 && GNUNET_NO == t->destroy 1874 && GNUNET_SCHEDULER_NO_TASK == t->destroy_task
1873 && GNUNET_NO == shutting_down) 1875 && GNUNET_NO == shutting_down)
1874 { 1876 {
1875 LOG (GNUNET_ERROR_TYPE_DEBUG, " no more connections, getting new ones\n"); 1877 LOG (GNUNET_ERROR_TYPE_DEBUG, " no more connections, getting new ones\n");
@@ -1918,9 +1920,10 @@ GMT_add_channel (struct MeshTunnel3 *t, struct MeshChannel *ch)
1918 LOG (GNUNET_ERROR_TYPE_DEBUG, " adding %p to %p\n", aux, t->channel_head); 1920 LOG (GNUNET_ERROR_TYPE_DEBUG, " adding %p to %p\n", aux, t->channel_head);
1919 GNUNET_CONTAINER_DLL_insert_tail (t->channel_head, t->channel_tail, aux); 1921 GNUNET_CONTAINER_DLL_insert_tail (t->channel_head, t->channel_tail, aux);
1920 1922
1921 if (GNUNET_YES == t->destroy) 1923 if (GNUNET_SCHEDULER_NO_TASK != t->destroy_task)
1922 { 1924 {
1923 t->destroy = GNUNET_NO; 1925 GNUNET_SCHEDULER_cancel (t->destroy_task);
1926 t->destroy_task = GNUNET_SCHEDULER_NO_TASK;
1924 LOG (GNUNET_ERROR_TYPE_DEBUG, " undo destroy!\n"); 1927 LOG (GNUNET_ERROR_TYPE_DEBUG, " undo destroy!\n");
1925 } 1928 }
1926} 1929}
@@ -1978,6 +1981,25 @@ GMT_get_channel (struct MeshTunnel3 *t, MESH_ChannelNumber chid)
1978 1981
1979 1982
1980/** 1983/**
1984 * @brief Destroy a tunnel and free all resources.
1985 *
1986 * Should only be called a while after the tunnel has been marked as destroyed,
1987 * in case there is a new channel added to the same peer shortly after marking
1988 * the tunnel. This way we avoid a new public key handshake.
1989 *
1990 * @param cls Closure (tunnel to destroy).
1991 * @param tc Task context.
1992 */
1993static void
1994tunnel_destroy (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1995{
1996 struct MeshTunnel3 *t = cls;
1997
1998 GMT_destroy (t);
1999}
2000
2001
2002/**
1981 * Tunnel is empty: destroy it. 2003 * Tunnel is empty: destroy it.
1982 * 2004 *
1983 * Notifies all connections about the destruction. 2005 * Notifies all connections about the destruction.
@@ -2005,7 +2027,8 @@ GMT_destroy_empty (struct MeshTunnel3 *t)
2005 t->kx_ctx = NULL; 2027 t->kx_ctx = NULL;
2006 } 2028 }
2007 t->cstate = MESH_TUNNEL3_NEW; 2029 t->cstate = MESH_TUNNEL3_NEW;
2008 t->destroy = GNUNET_YES; 2030 t->destroy_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
2031 &tunnel_destroy, t);
2009} 2032}
2010 2033
2011 2034
@@ -2046,7 +2069,11 @@ GMT_destroy (struct MeshTunnel3 *t)
2046 if (NULL == t) 2069 if (NULL == t)
2047 return; 2070 return;
2048 2071
2049 t->destroy = 2; 2072 if (GNUNET_SCHEDULER_NO_TASK != t->destroy_task)
2073 {
2074 GNUNET_SCHEDULER_cancel (t->destroy_task);
2075 t->destroy_task = GNUNET_SCHEDULER_NO_TASK;
2076 }
2050 2077
2051 LOG (GNUNET_ERROR_TYPE_DEBUG, "destroying tunnel %s\n", GMP_2s (t->peer)); 2078 LOG (GNUNET_ERROR_TYPE_DEBUG, "destroying tunnel %s\n", GMP_2s (t->peer));
2052 2079
@@ -2598,7 +2625,7 @@ GMT_debug (const struct MeshTunnel3 *t)
2598 t->kx_ctx, t->rekey_task); 2625 t->kx_ctx, t->rekey_task);
2599 LOG (GNUNET_ERROR_TYPE_DEBUG, " tq_head %p, tq_tail %p\n", 2626 LOG (GNUNET_ERROR_TYPE_DEBUG, " tq_head %p, tq_tail %p\n",
2600 t->tq_head, t->tq_tail); 2627 t->tq_head, t->tq_tail);
2601 LOG (GNUNET_ERROR_TYPE_DEBUG, " destroy %u\n", t->destroy); 2628 LOG (GNUNET_ERROR_TYPE_DEBUG, " destroy %u\n", t->destroy_task);
2602 2629
2603 LOG (GNUNET_ERROR_TYPE_DEBUG, " channels:\n"); 2630 LOG (GNUNET_ERROR_TYPE_DEBUG, " channels:\n");
2604 for (iterch = t->channel_head; NULL != iterch; iterch = iterch->next) 2631 for (iterch = t->channel_head; NULL != iterch; iterch = iterch->next)