diff options
Diffstat (limited to 'src/fs/fs_search.c')
-rw-r--r-- | src/fs/fs_search.c | 67 |
1 files changed, 37 insertions, 30 deletions
diff --git a/src/fs/fs_search.c b/src/fs/fs_search.c index 3cbf2afef..8c6f5edcf 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) | |||
1088 | unsigned int left; | 1088 | unsigned int left; |
1089 | unsigned int todo; | 1089 | unsigned int todo; |
1090 | unsigned int fit; | 1090 | unsigned int fit; |
1091 | int first_call; | ||
1092 | unsigned int search_request_map_offset; | 1091 | unsigned int search_request_map_offset; |
1093 | unsigned int keyword_offset; | 1092 | unsigned int keyword_offset; |
1093 | int first_call; | ||
1094 | 1094 | ||
1095 | memset (&mbc, 0, sizeof (mbc)); | 1095 | memset (&mbc, 0, sizeof (mbc)); |
1096 | mbc.sc = sc; | 1096 | mbc.sc = sc; |
1097 | if (GNUNET_FS_uri_test_ksk (sc->uri)) | 1097 | if (GNUNET_FS_uri_test_ksk (sc->uri)) |
1098 | { | 1098 | { |
1099 | mbc.put_cnt = 0; | 1099 | /* This will calculate the result set size ONLY for |
1100 | "keyword_offset == 0", so we will have to recalculate | ||
1101 | it for the other keywords later! */ | ||
1100 | GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, | 1102 | GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, |
1101 | &find_result_set, | 1103 | &find_result_set, |
1102 | &mbc); | 1104 | &mbc); |
@@ -1109,7 +1111,6 @@ schedule_transmit_search_request (struct GNUNET_FS_SearchContext *sc) | |||
1109 | } | 1111 | } |
1110 | search_request_map_offset = 0; | 1112 | search_request_map_offset = 0; |
1111 | keyword_offset = 0; | 1113 | keyword_offset = 0; |
1112 | |||
1113 | first_call = GNUNET_YES; | 1114 | first_call = GNUNET_YES; |
1114 | while ( (0 != (left = | 1115 | while ( (0 != (left = |
1115 | (total_seen_results - search_request_map_offset))) || | 1116 | (total_seen_results - search_request_map_offset))) || |
@@ -1120,7 +1121,7 @@ schedule_transmit_search_request (struct GNUNET_FS_SearchContext *sc) | |||
1120 | if (0 != (sc->options & GNUNET_FS_SEARCH_OPTION_LOOPBACK_ONLY)) | 1121 | if (0 != (sc->options & GNUNET_FS_SEARCH_OPTION_LOOPBACK_ONLY)) |
1121 | options |= SEARCH_MESSAGE_OPTION_LOOPBACK_ONLY; | 1122 | options |= SEARCH_MESSAGE_OPTION_LOOPBACK_ONLY; |
1122 | 1123 | ||
1123 | fit = (GNUNET_SERVER_MAX_MESSAGE_SIZE - 1 - sizeof (*sm)) / sizeof (struct GNUNET_HashCode); | 1124 | fit = (GNUNET_MAX_MESSAGE_SIZE - 1 - sizeof (*sm)) / sizeof (struct GNUNET_HashCode); |
1124 | todo = GNUNET_MIN (fit, | 1125 | todo = GNUNET_MIN (fit, |
1125 | left); | 1126 | left); |
1126 | env = GNUNET_MQ_msg_extra (sm, | 1127 | env = GNUNET_MQ_msg_extra (sm, |
@@ -1128,6 +1129,11 @@ schedule_transmit_search_request (struct GNUNET_FS_SearchContext *sc) | |||
1128 | GNUNET_MESSAGE_TYPE_FS_START_SEARCH); | 1129 | GNUNET_MESSAGE_TYPE_FS_START_SEARCH); |
1129 | mbc.skip_cnt = search_request_map_offset; | 1130 | mbc.skip_cnt = search_request_map_offset; |
1130 | mbc.xoff = (struct GNUNET_HashCode *) &sm[1]; | 1131 | mbc.xoff = (struct GNUNET_HashCode *) &sm[1]; |
1132 | sm->type = htonl (GNUNET_BLOCK_TYPE_FS_UBLOCK); | ||
1133 | sm->anonymity_level = htonl (sc->anonymity); | ||
1134 | memset (&sm->target, | ||
1135 | 0, | ||
1136 | sizeof (struct GNUNET_PeerIdentity)); | ||
1131 | 1137 | ||
1132 | if (GNUNET_FS_uri_test_ksk (sc->uri)) | 1138 | if (GNUNET_FS_uri_test_ksk (sc->uri)) |
1133 | { | 1139 | { |
@@ -1135,17 +1141,12 @@ schedule_transmit_search_request (struct GNUNET_FS_SearchContext *sc) | |||
1135 | /* calculate how many results we can send in this message */ | 1141 | /* calculate how many results we can send in this message */ |
1136 | mbc.put_cnt = todo; | 1142 | mbc.put_cnt = todo; |
1137 | /* now build message */ | 1143 | /* now build message */ |
1138 | sm->type = htonl (GNUNET_BLOCK_TYPE_FS_UBLOCK); | ||
1139 | sm->anonymity_level = htonl (sc->anonymity); | ||
1140 | memset (&sm->target, | ||
1141 | 0, | ||
1142 | sizeof (struct GNUNET_PeerIdentity)); | ||
1143 | sm->query = sc->requests[keyword_offset].uquery; | 1144 | sm->query = sc->requests[keyword_offset].uquery; |
1144 | GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, | 1145 | GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, |
1145 | &build_result_set, | 1146 | &build_result_set, |
1146 | &mbc); | 1147 | &mbc); |
1147 | search_request_map_offset += todo; | 1148 | search_request_map_offset += todo; |
1148 | GNUNET_assert (0 == mbc.put_cnt); /* #4608 reports this fails? */ | 1149 | GNUNET_assert (0 == mbc.put_cnt); |
1149 | GNUNET_assert (total_seen_results >= search_request_map_offset); | 1150 | GNUNET_assert (total_seen_results >= search_request_map_offset); |
1150 | if (total_seen_results != search_request_map_offset) | 1151 | if (total_seen_results != search_request_map_offset) |
1151 | { | 1152 | { |
@@ -1156,11 +1157,17 @@ schedule_transmit_search_request (struct GNUNET_FS_SearchContext *sc) | |||
1156 | { | 1157 | { |
1157 | sm->options = htonl (options); | 1158 | sm->options = htonl (options); |
1158 | keyword_offset++; | 1159 | keyword_offset++; |
1159 | search_request_map_offset = 0; | ||
1160 | if (sc->uri->data.ksk.keywordCount != keyword_offset) | 1160 | if (sc->uri->data.ksk.keywordCount != keyword_offset) |
1161 | { | 1161 | { |
1162 | /* more keywords => more requesting to be done... */ | 1162 | /* more keywords => more requesting to be done... */ |
1163 | first_call = GNUNET_YES; | 1163 | first_call = GNUNET_YES; |
1164 | search_request_map_offset = 0; | ||
1165 | mbc.put_cnt = 0; | ||
1166 | mbc.keyword_offset = keyword_offset; | ||
1167 | GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, | ||
1168 | &find_result_set, | ||
1169 | &mbc); | ||
1170 | total_seen_results = mbc.put_cnt; | ||
1164 | } | 1171 | } |
1165 | } | 1172 | } |
1166 | } | 1173 | } |
@@ -1168,11 +1175,6 @@ schedule_transmit_search_request (struct GNUNET_FS_SearchContext *sc) | |||
1168 | { | 1175 | { |
1169 | GNUNET_assert (GNUNET_FS_uri_test_sks (sc->uri)); | 1176 | GNUNET_assert (GNUNET_FS_uri_test_sks (sc->uri)); |
1170 | 1177 | ||
1171 | sm->type = htonl (GNUNET_BLOCK_TYPE_FS_UBLOCK); | ||
1172 | sm->anonymity_level = htonl (sc->anonymity); | ||
1173 | memset (&sm->target, | ||
1174 | 0, | ||
1175 | sizeof (struct GNUNET_PeerIdentity)); | ||
1176 | GNUNET_CRYPTO_ecdsa_public_key_derive (&sc->uri->data.sks.ns, | 1178 | GNUNET_CRYPTO_ecdsa_public_key_derive (&sc->uri->data.sks.ns, |
1177 | sc->uri->data.sks.identifier, | 1179 | sc->uri->data.sks.identifier, |
1178 | "fs-ublock", | 1180 | "fs-ublock", |
@@ -1383,9 +1385,10 @@ GNUNET_FS_search_start_searching_ (struct GNUNET_FS_SearchContext *sc) | |||
1383 | GNUNET_assert (0 != sc->uri->data.ksk.keywordCount); | 1385 | GNUNET_assert (0 != sc->uri->data.ksk.keywordCount); |
1384 | anon = GNUNET_CRYPTO_ecdsa_key_get_anonymous (); | 1386 | anon = GNUNET_CRYPTO_ecdsa_key_get_anonymous (); |
1385 | GNUNET_CRYPTO_ecdsa_key_get_public (anon, &anon_pub); | 1387 | GNUNET_CRYPTO_ecdsa_key_get_public (anon, &anon_pub); |
1386 | sc->requests = | 1388 | sc->requests |
1387 | GNUNET_malloc (sizeof (struct SearchRequestEntry) * | 1389 | = GNUNET_new_array (sc->uri->data.ksk.keywordCount, |
1388 | sc->uri->data.ksk.keywordCount); | 1390 | struct SearchRequestEntry); |
1391 | |||
1389 | for (i = 0; i < sc->uri->data.ksk.keywordCount; i++) | 1392 | for (i = 0; i < sc->uri->data.ksk.keywordCount; i++) |
1390 | { | 1393 | { |
1391 | keyword = &sc->uri->data.ksk.keywords[i][1]; | 1394 | keyword = &sc->uri->data.ksk.keywords[i][1]; |
@@ -1666,8 +1669,8 @@ search_result_stop (void *cls, | |||
1666 | if (NULL != sr->download) | 1669 | if (NULL != sr->download) |
1667 | { | 1670 | { |
1668 | sr->download->search = NULL; | 1671 | sr->download->search = NULL; |
1669 | sr->download->top = | 1672 | sr->download->top |
1670 | GNUNET_FS_make_top (sr->download->h, | 1673 | = GNUNET_FS_make_top (sr->download->h, |
1671 | &GNUNET_FS_download_signal_suspend_, | 1674 | &GNUNET_FS_download_signal_suspend_, |
1672 | sr->download); | 1675 | sr->download); |
1673 | if (NULL != sr->download->serialization) | 1676 | if (NULL != sr->download->serialization) |
@@ -1679,7 +1682,8 @@ search_result_stop (void *cls, | |||
1679 | sr->download->serialization = NULL; | 1682 | sr->download->serialization = NULL; |
1680 | } | 1683 | } |
1681 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_LOST_PARENT; | 1684 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_LOST_PARENT; |
1682 | GNUNET_FS_download_make_status_ (&pi, sr->download); | 1685 | GNUNET_FS_download_make_status_ (&pi, |
1686 | sr->download); | ||
1683 | GNUNET_FS_download_sync_ (sr->download); | 1687 | GNUNET_FS_download_sync_ (sr->download); |
1684 | sr->download = NULL; | 1688 | sr->download = NULL; |
1685 | } | 1689 | } |
@@ -1745,25 +1749,28 @@ GNUNET_FS_search_stop (struct GNUNET_FS_SearchContext *sc) | |||
1745 | if (NULL != sc->top) | 1749 | if (NULL != sc->top) |
1746 | GNUNET_FS_end_top (sc->h, sc->top); | 1750 | GNUNET_FS_end_top (sc->h, sc->top); |
1747 | GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, | 1751 | GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, |
1748 | &search_result_stop, sc); | 1752 | &search_result_stop, |
1753 | sc); | ||
1749 | if (NULL != sc->psearch_result) | 1754 | if (NULL != sc->psearch_result) |
1750 | sc->psearch_result->update_search = NULL; | 1755 | sc->psearch_result->update_search = NULL; |
1751 | if (NULL != sc->serialization) | 1756 | if (NULL != sc->serialization) |
1752 | { | 1757 | { |
1753 | GNUNET_FS_remove_sync_file_ (sc->h, | 1758 | GNUNET_FS_remove_sync_file_ (sc->h, |
1754 | (sc->psearch_result != | 1759 | (NULL != sc->psearch_result) |
1755 | NULL) ? GNUNET_FS_SYNC_PATH_CHILD_SEARCH : | 1760 | ? GNUNET_FS_SYNC_PATH_CHILD_SEARCH |
1756 | GNUNET_FS_SYNC_PATH_MASTER_SEARCH, | 1761 | : GNUNET_FS_SYNC_PATH_MASTER_SEARCH, |
1757 | sc->serialization); | 1762 | sc->serialization); |
1758 | GNUNET_FS_remove_sync_dir_ (sc->h, | 1763 | GNUNET_FS_remove_sync_dir_ (sc->h, |
1759 | (sc->psearch_result != | 1764 | (NULL != sc->psearch_result) |
1760 | NULL) ? GNUNET_FS_SYNC_PATH_CHILD_SEARCH : | 1765 | ? GNUNET_FS_SYNC_PATH_CHILD_SEARCH |
1761 | GNUNET_FS_SYNC_PATH_MASTER_SEARCH, | 1766 | : GNUNET_FS_SYNC_PATH_MASTER_SEARCH, |
1762 | sc->serialization); | 1767 | sc->serialization); |
1763 | GNUNET_free (sc->serialization); | 1768 | GNUNET_free (sc->serialization); |
1764 | } | 1769 | } |
1765 | pi.status = GNUNET_FS_STATUS_SEARCH_STOPPED; | 1770 | pi.status = GNUNET_FS_STATUS_SEARCH_STOPPED; |
1766 | sc->client_info = GNUNET_FS_search_make_status_ (&pi, sc->h, sc); | 1771 | sc->client_info = GNUNET_FS_search_make_status_ (&pi, |
1772 | sc->h, | ||
1773 | sc); | ||
1767 | GNUNET_break (NULL == sc->client_info); | 1774 | GNUNET_break (NULL == sc->client_info); |
1768 | if (NULL != sc->task) | 1775 | if (NULL != sc->task) |
1769 | { | 1776 | { |