aboutsummaryrefslogtreecommitdiff
path: root/src/dht
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-04-30 12:23:37 +0000
committerChristian Grothoff <christian@grothoff.org>2015-04-30 12:23:37 +0000
commit8476cb4f1ba88a67ea5cdc5abd02ac3982caf311 (patch)
treee51733f74a7de09a8aac9c73138e7f0f3b45988c /src/dht
parent6aa05b3843eceb17422cf924acc35b32fd1a8659 (diff)
downloadgnunet-8476cb4f1ba88a67ea5cdc5abd02ac3982caf311.tar.gz
gnunet-8476cb4f1ba88a67ea5cdc5abd02ac3982caf311.zip
-implementing trail timeout handling
Diffstat (limited to 'src/dht')
-rw-r--r--src/dht/gnunet-service-wdht_neighbours.c54
1 files changed, 53 insertions, 1 deletions
diff --git a/src/dht/gnunet-service-wdht_neighbours.c b/src/dht/gnunet-service-wdht_neighbours.c
index b74f7be39..66e0e8fc3 100644
--- a/src/dht/gnunet-service-wdht_neighbours.c
+++ b/src/dht/gnunet-service-wdht_neighbours.c
@@ -807,6 +807,37 @@ pick_random_friend ()
807 807
808 808
809/** 809/**
810 * One of our trails might have timed out, check and
811 * possibly initiate cleanup.
812 *
813 * @param cls NULL
814 * @param tc unused
815 */
816static void
817trail_timeout_callback (void *cls,
818 const struct GNUNET_SCHEDULER_TaskContext *tc)
819{
820 struct Trail *trail;
821 struct GNUNET_TIME_Relative left;
822
823 trail_timeout_task = NULL;
824 while (NULL != (trail = GNUNET_CONTAINER_heap_peek (trail_heap)))
825 {
826 left = GNUNET_TIME_absolute_get_remaining (trail->expiration_time);
827 if (0 != left.rel_value_us)
828 break;
829 delete_trail (trail,
830 GNUNET_YES,
831 GNUNET_YES);
832 }
833 if (NULL != trail)
834 trail_timeout_task = GNUNET_SCHEDULER_add_delayed (left,
835 &trail_timeout_callback,
836 NULL);
837}
838
839
840/**
810 * Initiate a random walk. 841 * Initiate a random walk.
811 * 842 *
812 * @param cls NULL 843 * @param cls NULL
@@ -846,6 +877,14 @@ do_random_walk (void *cls,
846 friend->succ_head, 877 friend->succ_head,
847 friend->succ_tail, 878 friend->succ_tail,
848 trail); 879 trail);
880 trail->expiration_time = GNUNET_TIME_relative_to_absolute (TRAIL_TIMEOUT);
881 trail->hn = GNUNET_CONTAINER_heap_insert (trail_heap,
882 trail,
883 trail->expiration_time.abs_value_us);
884 if (NULL == trail_timeout_task)
885 trail_timeout_task = GNUNET_SCHEDULER_add_delayed (TRAIL_TIMEOUT,
886 &trail_timeout_callback,
887 NULL);
849 env = GNUNET_MQ_msg (rwm, 888 env = GNUNET_MQ_msg (rwm,
850 GNUNET_MESSAGE_TYPE_WDHT_RANDOM_WALK); 889 GNUNET_MESSAGE_TYPE_WDHT_RANDOM_WALK);
851 rwm->hops_taken = htonl (0); 890 rwm->hops_taken = htonl (0);
@@ -967,7 +1006,6 @@ handle_dht_p2p_random_walk (void *cls,
967 t = GNUNET_new (struct Trail); 1006 t = GNUNET_new (struct Trail);
968 t->pred_id = m->trail_id; 1007 t->pred_id = m->trail_id;
969 t->pred = pred; 1008 t->pred = pred;
970 t->expiration_time = GNUNET_TIME_relative_to_absolute (TRAIL_TIMEOUT);
971 if (GNUNET_OK != 1009 if (GNUNET_OK !=
972 GNUNET_CONTAINER_multihashmap_put (trail_map, 1010 GNUNET_CONTAINER_multihashmap_put (trail_map,
973 &t->pred_id, 1011 &t->pred_id,
@@ -982,6 +1020,15 @@ handle_dht_p2p_random_walk (void *cls,
982 pred->pred_head, 1020 pred->pred_head,
983 pred->pred_tail, 1021 pred->pred_tail,
984 t); 1022 t);
1023 t->expiration_time = GNUNET_TIME_relative_to_absolute (TRAIL_TIMEOUT);
1024 t->hn = GNUNET_CONTAINER_heap_insert (trail_heap,
1025 t,
1026 t->expiration_time.abs_value_us);
1027 if (NULL == trail_timeout_task)
1028 trail_timeout_task = GNUNET_SCHEDULER_add_delayed (TRAIL_TIMEOUT,
1029 &trail_timeout_callback,
1030 NULL);
1031
985 if (ntohl (m->hops_taken) > GDS_NSE_get ()) 1032 if (ntohl (m->hops_taken) > GDS_NSE_get ())
986 { 1033 {
987 /* We are the last hop, generate response */ 1034 /* We are the last hop, generate response */
@@ -1390,6 +1437,11 @@ GDS_NEIGHBOURS_done (void)
1390 trail_map = NULL; 1437 trail_map = NULL;
1391 GNUNET_CONTAINER_heap_destroy (trail_heap); 1438 GNUNET_CONTAINER_heap_destroy (trail_heap);
1392 trail_heap = NULL; 1439 trail_heap = NULL;
1440 if (NULL != trail_timeout_task)
1441 {
1442 GNUNET_SCHEDULER_cancel (trail_timeout_task);
1443 trail_timeout_task = NULL;
1444 }
1393} 1445}
1394 1446
1395 1447