From 6037291cd4f4ead8719325632b7e00e163a59cb9 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Thu, 9 Mar 2017 21:38:59 +0100 Subject: fix #4608 --- src/fs/fs_search.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) (limited to 'src/fs') diff --git a/src/fs/fs_search.c b/src/fs/fs_search.c index e31115f39..af0b551ef 100644 --- a/src/fs/fs_search.c +++ b/src/fs/fs_search.c @@ -1088,15 +1088,17 @@ schedule_transmit_search_request (struct GNUNET_FS_SearchContext *sc) unsigned int left; unsigned int todo; unsigned int fit; - int first_call; unsigned int search_request_map_offset; unsigned int keyword_offset; + int first_call; memset (&mbc, 0, sizeof (mbc)); mbc.sc = sc; if (GNUNET_FS_uri_test_ksk (sc->uri)) { - mbc.put_cnt = 0; + /* This will calculate the result set size ONLY for + "keyword_offset == 0", so we will have to recalculate + it for the other keywords later! */ GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, &find_result_set, &mbc); @@ -1109,7 +1111,6 @@ schedule_transmit_search_request (struct GNUNET_FS_SearchContext *sc) } search_request_map_offset = 0; keyword_offset = 0; - first_call = GNUNET_YES; while ( (0 != (left = (total_seen_results - search_request_map_offset))) || @@ -1128,6 +1129,11 @@ schedule_transmit_search_request (struct GNUNET_FS_SearchContext *sc) GNUNET_MESSAGE_TYPE_FS_START_SEARCH); mbc.skip_cnt = search_request_map_offset; mbc.xoff = (struct GNUNET_HashCode *) &sm[1]; + sm->type = htonl (GNUNET_BLOCK_TYPE_FS_UBLOCK); + sm->anonymity_level = htonl (sc->anonymity); + memset (&sm->target, + 0, + sizeof (struct GNUNET_PeerIdentity)); if (GNUNET_FS_uri_test_ksk (sc->uri)) { @@ -1135,17 +1141,12 @@ schedule_transmit_search_request (struct GNUNET_FS_SearchContext *sc) /* calculate how many results we can send in this message */ mbc.put_cnt = todo; /* now build message */ - sm->type = htonl (GNUNET_BLOCK_TYPE_FS_UBLOCK); - sm->anonymity_level = htonl (sc->anonymity); - memset (&sm->target, - 0, - sizeof (struct GNUNET_PeerIdentity)); sm->query = sc->requests[keyword_offset].uquery; GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, &build_result_set, &mbc); search_request_map_offset += todo; - GNUNET_assert (0 == mbc.put_cnt); /* #4608 reports this fails? */ + GNUNET_assert (0 == mbc.put_cnt); GNUNET_assert (total_seen_results >= search_request_map_offset); if (total_seen_results != search_request_map_offset) { @@ -1156,11 +1157,17 @@ schedule_transmit_search_request (struct GNUNET_FS_SearchContext *sc) { sm->options = htonl (options); keyword_offset++; - search_request_map_offset = 0; if (sc->uri->data.ksk.keywordCount != keyword_offset) { /* more keywords => more requesting to be done... */ first_call = GNUNET_YES; + search_request_map_offset = 0; + mbc.put_cnt = 0; + mbc.keyword_offset = keyword_offset; + GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, + &find_result_set, + &mbc); + total_seen_results = mbc.put_cnt; } } } @@ -1168,11 +1175,6 @@ schedule_transmit_search_request (struct GNUNET_FS_SearchContext *sc) { GNUNET_assert (GNUNET_FS_uri_test_sks (sc->uri)); - sm->type = htonl (GNUNET_BLOCK_TYPE_FS_UBLOCK); - sm->anonymity_level = htonl (sc->anonymity); - memset (&sm->target, - 0, - sizeof (struct GNUNET_PeerIdentity)); GNUNET_CRYPTO_ecdsa_public_key_derive (&sc->uri->data.sks.ns, sc->uri->data.sks.identifier, "fs-ublock", -- cgit v1.2.3