aboutsummaryrefslogtreecommitdiff
path: root/src/mesh
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2011-10-18 11:15:58 +0000
committerBart Polot <bart@net.in.tum.de>2011-10-18 11:15:58 +0000
commitf3c69312a7fca7c5a233bd39a1c2abaec9f3b263 (patch)
tree57ffc13bfde1594fef58154dd62d4b236c303e98 /src/mesh
parentab1bea7ea82a2ca7c98093d8c09e41ba67204164 (diff)
downloadgnunet-f3c69312a7fca7c5a233bd39a1c2abaec9f3b263.tar.gz
gnunet-f3c69312a7fca7c5a233bd39a1c2abaec9f3b263.zip
Added tunnel timeout on inactivity
Diffstat (limited to 'src/mesh')
-rw-r--r--src/mesh/gnunet-service-mesh.c67
1 files changed, 57 insertions, 10 deletions
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c
index a9db45dde..8ee55c845 100644
--- a/src/mesh/gnunet-service-mesh.c
+++ b/src/mesh/gnunet-service-mesh.c
@@ -305,6 +305,14 @@ struct MeshTunnel
305 * Task to keep the used paths alive 305 * Task to keep the used paths alive
306 */ 306 */
307 GNUNET_SCHEDULER_TaskIdentifier path_refresh_task; 307 GNUNET_SCHEDULER_TaskIdentifier path_refresh_task;
308
309 /**
310 * Task to destroy the tunnel after timeout
311 *
312 * FIXME: merge the two? a tunnel will have either
313 * a path refresh OR a timeout, never both!
314 */
315 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
308}; 316};
309 317
310 318
@@ -1424,7 +1432,7 @@ path_build_from_dht (const struct GNUNET_PeerIdentity *get_path,
1424 * 1432 *
1425 * TODO: implement explicit multicast keepalive? 1433 * TODO: implement explicit multicast keepalive?
1426 */ 1434 */
1427void 1435static void
1428path_refresh (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); 1436path_refresh (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
1429 1437
1430 1438
@@ -1767,6 +1775,10 @@ tunnel_destroy (struct MeshTunnel *t)
1767 tree_destroy(t->tree); 1775 tree_destroy(t->tree);
1768 if (NULL != t->dht_get_type) 1776 if (NULL != t->dht_get_type)
1769 GNUNET_DHT_get_stop(t->dht_get_type); 1777 GNUNET_DHT_get_stop(t->dht_get_type);
1778 if (GNUNET_SCHEDULER_NO_TASK != t->timeout_task)
1779 GNUNET_SCHEDULER_cancel(t->timeout_task);
1780 if (GNUNET_SCHEDULER_NO_TASK != t->path_refresh_task)
1781 GNUNET_SCHEDULER_cancel(t->path_refresh_task);
1770 GNUNET_free (t); 1782 GNUNET_free (t);
1771 return r; 1783 return r;
1772} 1784}
@@ -1797,6 +1809,40 @@ tunnel_destroy_iterator (void *cls, const GNUNET_HashCode * key, void *value)
1797} 1809}
1798 1810
1799 1811
1812/**
1813 * Timeout function, destroys tunnel if called
1814 *
1815 * @param cls Closure (tunnel to destroy).
1816 * @param tc TaskContext
1817 */
1818static void
1819tunnel_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1820{
1821 struct MeshTunnel *t = cls;
1822
1823 if (GNUNET_SCHEDULER_REASON_SHUTDOWN == tc->reason)
1824 return;
1825 t->timeout_task = GNUNET_SCHEDULER_NO_TASK;
1826 tunnel_destroy (t);
1827}
1828
1829/**
1830 * Resets the tunnel timeout. Starts it if no timeout was running.
1831 *
1832 * @param t Tunnel whose timeout to reset.
1833 */
1834static void
1835tunnel_reset_timeout (struct MeshTunnel *t)
1836{
1837 if (GNUNET_SCHEDULER_NO_TASK != t->timeout_task)
1838 GNUNET_SCHEDULER_cancel (t->timeout_task);
1839 t->timeout_task = GNUNET_SCHEDULER_add_delayed (
1840 GNUNET_TIME_relative_multiply(REFRESH_PATH_TIME, 4),
1841 &tunnel_timeout,
1842 t);
1843}
1844
1845
1800/******************************************************************************/ 1846/******************************************************************************/
1801/**************** MESH NETWORK HANDLER HELPERS ***********************/ 1847/**************** MESH NETWORK HANDLER HELPERS ***********************/
1802/******************************************************************************/ 1848/******************************************************************************/
@@ -2214,6 +2260,7 @@ handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer,
2214 GNUNET_break (0); 2260 GNUNET_break (0);
2215 return GNUNET_OK; 2261 return GNUNET_OK;
2216 } 2262 }
2263 tunnel_reset_timeout (t);
2217 GNUNET_CRYPTO_hash (&t->local_tid, sizeof (MESH_TunnelNumber), &hash); 2264 GNUNET_CRYPTO_hash (&t->local_tid, sizeof (MESH_TunnelNumber), &hash);
2218 if (GNUNET_OK != 2265 if (GNUNET_OK !=
2219 GNUNET_CONTAINER_multihashmap_put ( 2266 GNUNET_CONTAINER_multihashmap_put (
@@ -2368,6 +2415,7 @@ handle_mesh_data_unicast (void *cls, const struct GNUNET_PeerIdentity *peer,
2368 GNUNET_break_op (0); 2415 GNUNET_break_op (0);
2369 return GNUNET_OK; 2416 return GNUNET_OK;
2370 } 2417 }
2418 tunnel_reset_timeout (t);
2371 pid = GNUNET_PEER_search(&msg->destination); 2419 pid = GNUNET_PEER_search(&msg->destination);
2372 if (pid == myid) 2420 if (pid == myid)
2373 { 2421 {
@@ -2429,6 +2477,7 @@ handle_mesh_data_multicast (void *cls, const struct GNUNET_PeerIdentity *peer,
2429 GNUNET_break_op (0); 2477 GNUNET_break_op (0);
2430 return GNUNET_OK; 2478 return GNUNET_OK;
2431 } 2479 }
2480 tunnel_reset_timeout (t);
2432 2481
2433 /* Transmit to locally interested clients */ 2482 /* Transmit to locally interested clients */
2434 if (NULL != t->peers && 2483 if (NULL != t->peers &&
@@ -2568,8 +2617,7 @@ handle_mesh_path_ack (void *cls, const struct GNUNET_PeerIdentity *peer,
2568 /* Message for us? */ 2617 /* Message for us? */
2569 if (0 == memcmp (&msg->oid, &my_full_id, sizeof (struct GNUNET_PeerIdentity))) 2618 if (0 == memcmp (&msg->oid, &my_full_id, sizeof (struct GNUNET_PeerIdentity)))
2570 { 2619 {
2571 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2620 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: It's for us!\n");
2572 "MESH: It's for us!\n");
2573 if (NULL == t->client) 2621 if (NULL == t->client)
2574 { 2622 {
2575 GNUNET_break_op (0); 2623 GNUNET_break_op (0);
@@ -2697,13 +2745,15 @@ notify_client_connection_failure (void *cls, size_t size, void *buf)
2697 * 2745 *
2698 * TODO: implement explicit multicast keepalive? 2746 * TODO: implement explicit multicast keepalive?
2699 */ 2747 */
2700void 2748static void
2701path_refresh (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 2749path_refresh (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2702{ 2750{
2703 struct MeshTunnel *t = cls; 2751 struct MeshTunnel *t = cls;
2704 struct GNUNET_MessageHeader *payload; 2752 struct GNUNET_MessageHeader *payload;
2705 struct GNUNET_MESH_Multicast *msg; 2753 struct GNUNET_MESH_Multicast *msg;
2706 size_t size; 2754 size_t size = sizeof(struct GNUNET_MESH_Multicast) +
2755 sizeof(struct GNUNET_MessageHeader);
2756 char cbuf[size];
2707 2757
2708 if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) 2758 if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
2709 { 2759 {
@@ -2715,9 +2765,7 @@ path_refresh (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2715 "MESH: sending keepalive for tunnel %d\n", 2765 "MESH: sending keepalive for tunnel %d\n",
2716 t->id.tid); 2766 t->id.tid);
2717 2767
2718 size = sizeof(struct GNUNET_MESH_Multicast) + 2768 msg = (struct GNUNET_MESH_Multicast *) cbuf;
2719 sizeof(struct GNUNET_MessageHeader);
2720 msg = GNUNET_malloc (size);
2721 msg->header.size = htons (size); 2769 msg->header.size = htons (size);
2722 msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_MULTICAST); 2770 msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_MULTICAST);
2723 msg->oid = my_full_id; 2771 msg->oid = my_full_id;
@@ -2725,9 +2773,8 @@ path_refresh (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2725 payload = (struct GNUNET_MessageHeader *) &msg[1]; 2773 payload = (struct GNUNET_MessageHeader *) &msg[1];
2726 payload->size = htons (sizeof(struct GNUNET_MessageHeader)); 2774 payload->size = htons (sizeof(struct GNUNET_MessageHeader));
2727 payload->type = htons (GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE); 2775 payload->type = htons (GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE);
2728 handle_mesh_data_multicast (NULL, &my_full_id, &msg->header, NULL); 2776 tunnel_send_multicast (t, &msg->header);
2729 2777
2730 GNUNET_free (msg);
2731 t->path_refresh_task = 2778 t->path_refresh_task =
2732 GNUNET_SCHEDULER_add_delayed (t->tree->refresh, &path_refresh, t); 2779 GNUNET_SCHEDULER_add_delayed (t->tree->refresh, &path_refresh, t);
2733 return; 2780 return;