From: Nathan S. Evans Date: Fri, 26 Nov 2010 14:46:44 +0000 (+0000) Subject: restrict replies to one per request (use block library) X-Git-Tag: initial-import-from-subversion-38251~19612 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=873243c9b318c74471dae58184afd8d66df17d44;p=oweals%2Fgnunet.git restrict replies to one per request (use block library) --- 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) return GNUNET_NO; } + +/** + * Task used to remove forwarding entries, either + * after timeout, when full, or on shutdown. + * + * @param cls the entry to remove + * @param tc context, reason, etc. + */ +static void +remove_forward_entry (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) +{ + struct DHTRouteSource *source_info = cls; + struct DHTQueryRecord *record; + source_info = GNUNET_CONTAINER_heap_remove_node(forward_list.minHeap, source_info->hnode); + record = source_info->record; + GNUNET_CONTAINER_DLL_remove(record->head, record->tail, source_info); + + if (record->head == NULL) /* No more entries in DLL */ + { + GNUNET_assert(GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove (forward_list.hashmap, &record->key, record)); + GNUNET_free(record); + } + if (source_info->find_peers_responded != NULL) + GNUNET_CONTAINER_bloomfilter_free(source_info->find_peers_responded); + GNUNET_free(source_info); +} + /** * Main function that handles whether or not to route a result * message to other peers, or to send to our local client. @@ -2117,7 +2144,13 @@ static int route_result_message(struct GNUNET_MessageHeader *msg, msg_ctx->peer, &pos->source); } #endif - forward_result_message(msg, peer_info, msg_ctx); + forward_result_message (msg, peer_info, msg_ctx); + /* Try removing forward entries after sending once, only allows ONE response per request */ + if (pos->delete_task != GNUNET_SCHEDULER_NO_TASK) + { + GNUNET_SCHEDULER_cancel(pos->delete_task); + pos->delete_task = GNUNET_SCHEDULER_add_now (&remove_forward_entry, pos); + } } else { @@ -3353,33 +3386,6 @@ remove_recent (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) */ } - -/** - * Task used to remove forwarding entries, either - * after timeout, when full, or on shutdown. - * - * @param cls the entry to remove - * @param tc context, reason, etc. - */ -static void -remove_forward_entry (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) -{ - struct DHTRouteSource *source_info = cls; - struct DHTQueryRecord *record; - source_info = GNUNET_CONTAINER_heap_remove_node(forward_list.minHeap, source_info->hnode); - record = source_info->record; - GNUNET_CONTAINER_DLL_remove(record->head, record->tail, source_info); - - if (record->head == NULL) /* No more entries in DLL */ - { - GNUNET_assert(GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove (forward_list.hashmap, &record->key, record)); - GNUNET_free(record); - } - if (source_info->find_peers_responded != NULL) - GNUNET_CONTAINER_bloomfilter_free(source_info->find_peers_responded); - GNUNET_free(source_info); -} - /** * Remember this routing request so that if a reply is * received we can either forward it to the correct peer