diff options
author | Nathan S. Evans <evans@in.tum.de> | 2010-11-26 14:46:44 +0000 |
---|---|---|
committer | Nathan S. Evans <evans@in.tum.de> | 2010-11-26 14:46:44 +0000 |
commit | 873243c9b318c74471dae58184afd8d66df17d44 (patch) | |
tree | 6159edfbf5eea7e1128ba462819657d9c11b1a37 | |
parent | 2095d68fba01bb7e24d6eaa102ca5e628a478dce (diff) | |
download | gnunet-873243c9b318c74471dae58184afd8d66df17d44.tar.gz gnunet-873243c9b318c74471dae58184afd8d66df17d44.zip |
restrict replies to one per request (use block library)
-rw-r--r-- | src/dht/gnunet-service-dht.c | 62 |
1 files changed, 34 insertions, 28 deletions
diff --git a/src/dht/gnunet-service-dht.c b/src/dht/gnunet-service-dht.c index 2733fa844..acadd58b5 100644 --- a/src/dht/gnunet-service-dht.c +++ b/src/dht/gnunet-service-dht.c | |||
@@ -1964,6 +1964,33 @@ static int consider_peer (struct GNUNET_PeerIdentity *peer) | |||
1964 | return GNUNET_NO; | 1964 | return GNUNET_NO; |
1965 | } | 1965 | } |
1966 | 1966 | ||
1967 | |||
1968 | /** | ||
1969 | * Task used to remove forwarding entries, either | ||
1970 | * after timeout, when full, or on shutdown. | ||
1971 | * | ||
1972 | * @param cls the entry to remove | ||
1973 | * @param tc context, reason, etc. | ||
1974 | */ | ||
1975 | static void | ||
1976 | remove_forward_entry (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
1977 | { | ||
1978 | struct DHTRouteSource *source_info = cls; | ||
1979 | struct DHTQueryRecord *record; | ||
1980 | source_info = GNUNET_CONTAINER_heap_remove_node(forward_list.minHeap, source_info->hnode); | ||
1981 | record = source_info->record; | ||
1982 | GNUNET_CONTAINER_DLL_remove(record->head, record->tail, source_info); | ||
1983 | |||
1984 | if (record->head == NULL) /* No more entries in DLL */ | ||
1985 | { | ||
1986 | GNUNET_assert(GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove (forward_list.hashmap, &record->key, record)); | ||
1987 | GNUNET_free(record); | ||
1988 | } | ||
1989 | if (source_info->find_peers_responded != NULL) | ||
1990 | GNUNET_CONTAINER_bloomfilter_free(source_info->find_peers_responded); | ||
1991 | GNUNET_free(source_info); | ||
1992 | } | ||
1993 | |||
1967 | /** | 1994 | /** |
1968 | * Main function that handles whether or not to route a result | 1995 | * Main function that handles whether or not to route a result |
1969 | * message to other peers, or to send to our local client. | 1996 | * message to other peers, or to send to our local client. |
@@ -2117,7 +2144,13 @@ static int route_result_message(struct GNUNET_MessageHeader *msg, | |||
2117 | msg_ctx->peer, &pos->source); | 2144 | msg_ctx->peer, &pos->source); |
2118 | } | 2145 | } |
2119 | #endif | 2146 | #endif |
2120 | forward_result_message(msg, peer_info, msg_ctx); | 2147 | forward_result_message (msg, peer_info, msg_ctx); |
2148 | /* Try removing forward entries after sending once, only allows ONE response per request */ | ||
2149 | if (pos->delete_task != GNUNET_SCHEDULER_NO_TASK) | ||
2150 | { | ||
2151 | GNUNET_SCHEDULER_cancel(pos->delete_task); | ||
2152 | pos->delete_task = GNUNET_SCHEDULER_add_now (&remove_forward_entry, pos); | ||
2153 | } | ||
2121 | } | 2154 | } |
2122 | else | 2155 | else |
2123 | { | 2156 | { |
@@ -3353,33 +3386,6 @@ remove_recent (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
3353 | */ | 3386 | */ |
3354 | } | 3387 | } |
3355 | 3388 | ||
3356 | |||
3357 | /** | ||
3358 | * Task used to remove forwarding entries, either | ||
3359 | * after timeout, when full, or on shutdown. | ||
3360 | * | ||
3361 | * @param cls the entry to remove | ||
3362 | * @param tc context, reason, etc. | ||
3363 | */ | ||
3364 | static void | ||
3365 | remove_forward_entry (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
3366 | { | ||
3367 | struct DHTRouteSource *source_info = cls; | ||
3368 | struct DHTQueryRecord *record; | ||
3369 | source_info = GNUNET_CONTAINER_heap_remove_node(forward_list.minHeap, source_info->hnode); | ||
3370 | record = source_info->record; | ||
3371 | GNUNET_CONTAINER_DLL_remove(record->head, record->tail, source_info); | ||
3372 | |||
3373 | if (record->head == NULL) /* No more entries in DLL */ | ||
3374 | { | ||
3375 | GNUNET_assert(GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove (forward_list.hashmap, &record->key, record)); | ||
3376 | GNUNET_free(record); | ||
3377 | } | ||
3378 | if (source_info->find_peers_responded != NULL) | ||
3379 | GNUNET_CONTAINER_bloomfilter_free(source_info->find_peers_responded); | ||
3380 | GNUNET_free(source_info); | ||
3381 | } | ||
3382 | |||
3383 | /** | 3389 | /** |
3384 | * Remember this routing request so that if a reply is | 3390 | * Remember this routing request so that if a reply is |
3385 | * received we can either forward it to the correct peer | 3391 | * received we can either forward it to the correct peer |