diff options
author | Christian Grothoff <grothoff@gnunet.org> | 2022-03-12 04:01:02 +0100 |
---|---|---|
committer | Christian Grothoff <grothoff@gnunet.org> | 2022-03-12 04:01:02 +0100 |
commit | ff992f47e6528b00937c3951b812f6938e1ee21a (patch) | |
tree | 96917d63e24d2cc02b0e09a4e1dc29987541ffe8 /src/fs | |
parent | 06f6791f2d55ab3a1b4ca4c3ba9ed5c315f8d79b (diff) | |
download | gnunet-ff992f47e6528b00937c3951b812f6938e1ee21a.tar.gz gnunet-ff992f47e6528b00937c3951b812f6938e1ee21a.zip |
revise block API to match latest DHT specs
Diffstat (limited to 'src/fs')
-rw-r--r-- | src/fs/gnunet-service-fs_pr.c | 74 | ||||
-rw-r--r-- | src/fs/plugin_block_fs.c | 117 |
2 files changed, 59 insertions, 132 deletions
diff --git a/src/fs/gnunet-service-fs_pr.c b/src/fs/gnunet-service-fs_pr.c index beb29a506..154c454ca 100644 --- a/src/fs/gnunet-service-fs_pr.c +++ b/src/fs/gnunet-service-fs_pr.c | |||
@@ -247,7 +247,8 @@ static unsigned long long max_pending_requests = (32 * 1024); | |||
247 | * @param pr request for which the BF is to be recomputed | 247 | * @param pr request for which the BF is to be recomputed |
248 | */ | 248 | */ |
249 | static void | 249 | static void |
250 | refresh_bloomfilter (enum GNUNET_BLOCK_Type type, struct GSF_PendingRequest *pr) | 250 | refresh_bloomfilter (enum GNUNET_BLOCK_Type type, |
251 | struct GSF_PendingRequest *pr) | ||
251 | { | 252 | { |
252 | if (NULL != pr->bg) | 253 | if (NULL != pr->bg) |
253 | { | 254 | { |
@@ -406,7 +407,7 @@ GSF_pending_request_create_ (enum GSF_PendingRequestOptions options, | |||
406 | break; /* let the request live briefly... */ | 407 | break; /* let the request live briefly... */ |
407 | if (NULL != dpr->rh) | 408 | if (NULL != dpr->rh) |
408 | dpr->rh (dpr->rh_cls, | 409 | dpr->rh (dpr->rh_cls, |
409 | GNUNET_BLOCK_EVALUATION_REQUEST_VALID, | 410 | GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED, |
410 | dpr, | 411 | dpr, |
411 | UINT32_MAX, | 412 | UINT32_MAX, |
412 | GNUNET_TIME_UNIT_FOREVER_ABS, | 413 | GNUNET_TIME_UNIT_FOREVER_ABS, |
@@ -557,7 +558,10 @@ GSF_pending_request_get_message_ (struct GSF_PendingRequest *pr) | |||
557 | k++; | 558 | k++; |
558 | } | 559 | } |
559 | if (GNUNET_OK != | 560 | if (GNUNET_OK != |
560 | GNUNET_BLOCK_group_serialize (pr->bg, &bf_nonce, &bf_data, &bf_size)) | 561 | GNUNET_BLOCK_group_serialize (pr->bg, |
562 | &bf_nonce, | ||
563 | &bf_data, | ||
564 | &bf_size)) | ||
561 | { | 565 | { |
562 | bf_size = 0; | 566 | bf_size = 0; |
563 | bf_data = NULL; | 567 | bf_data = NULL; |
@@ -765,11 +769,6 @@ struct ProcessReplyClosure | |||
765 | enum GNUNET_BLOCK_Type type; | 769 | enum GNUNET_BLOCK_Type type; |
766 | 770 | ||
767 | /** | 771 | /** |
768 | * Control flags for evaluation. | ||
769 | */ | ||
770 | enum GNUNET_BLOCK_EvaluationOptions eo; | ||
771 | |||
772 | /** | ||
773 | * How much was this reply worth to us? | 772 | * How much was this reply worth to us? |
774 | */ | 773 | */ |
775 | uint32_t priority; | 774 | uint32_t priority; |
@@ -850,7 +849,6 @@ process_reply (void *cls, | |||
850 | case GNUNET_BLOCK_REPLY_OK_MORE: | 849 | case GNUNET_BLOCK_REPLY_OK_MORE: |
851 | update_request_performance_data (prq, pr); | 850 | update_request_performance_data (prq, pr); |
852 | break; | 851 | break; |
853 | |||
854 | case GNUNET_BLOCK_REPLY_OK_LAST: | 852 | case GNUNET_BLOCK_REPLY_OK_LAST: |
855 | /* short cut: stop processing early, no BF-update, etc. */ | 853 | /* short cut: stop processing early, no BF-update, etc. */ |
856 | update_request_performance_data (prq, pr); | 854 | update_request_performance_data (prq, pr); |
@@ -885,7 +883,6 @@ process_reply (void *cls, | |||
885 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 883 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
886 | "Duplicate response, discarding.\n"); | 884 | "Duplicate response, discarding.\n"); |
887 | return GNUNET_YES; /* duplicate */ | 885 | return GNUNET_YES; /* duplicate */ |
888 | |||
889 | case GNUNET_BLOCK_REPLY_IRRELEVANT: | 886 | case GNUNET_BLOCK_REPLY_IRRELEVANT: |
890 | GNUNET_STATISTICS_update (GSF_stats, | 887 | GNUNET_STATISTICS_update (GSF_stats, |
891 | "# irrelevant replies discarded", | 888 | "# irrelevant replies discarded", |
@@ -894,8 +891,6 @@ process_reply (void *cls, | |||
894 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 891 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
895 | "Irrelevant response, ignoring.\n"); | 892 | "Irrelevant response, ignoring.\n"); |
896 | return GNUNET_YES; | 893 | return GNUNET_YES; |
897 | case GNUNET_BLOCK_REPLY_INVALID: | ||
898 | return GNUNET_YES; | ||
899 | case GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED: | 894 | case GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED: |
900 | GNUNET_break (0); /* bad installation? */ | 895 | GNUNET_break (0); /* bad installation? */ |
901 | return GNUNET_NO; | 896 | return GNUNET_NO; |
@@ -1127,8 +1122,9 @@ handle_dht_reply (void *cls, | |||
1127 | prq.expiration); | 1122 | prq.expiration); |
1128 | prq.size = size; | 1123 | prq.size = size; |
1129 | prq.type = type; | 1124 | prq.type = type; |
1130 | prq.eo = GNUNET_BLOCK_EO_NONE; | 1125 | process_reply (&prq, |
1131 | process_reply (&prq, key, pr); | 1126 | key, |
1127 | pr); | ||
1132 | if ((GNUNET_YES == active_to_migration) && | 1128 | if ((GNUNET_YES == active_to_migration) && |
1133 | (GNUNET_NO == test_put_load_too_high (prq.priority))) | 1129 | (GNUNET_NO == test_put_load_too_high (prq.priority))) |
1134 | { | 1130 | { |
@@ -1229,6 +1225,15 @@ cadet_reply_proc (void *cls, | |||
1229 | struct GNUNET_HashCode query; | 1225 | struct GNUNET_HashCode query; |
1230 | 1226 | ||
1231 | pr->cadet_request = NULL; | 1227 | pr->cadet_request = NULL; |
1228 | if (GNUNET_OK != | ||
1229 | GNUNET_BLOCK_check_block (GSF_block_ctx, | ||
1230 | type, | ||
1231 | data, | ||
1232 | data_size)) | ||
1233 | { | ||
1234 | GNUNET_break_op (0); | ||
1235 | return; | ||
1236 | } | ||
1232 | if (GNUNET_BLOCK_TYPE_ANY == type) | 1237 | if (GNUNET_BLOCK_TYPE_ANY == type) |
1233 | { | 1238 | { |
1234 | GNUNET_break (NULL == data); | 1239 | GNUNET_break (NULL == data); |
@@ -1247,7 +1252,11 @@ cadet_reply_proc (void *cls, | |||
1247 | return; | 1252 | return; |
1248 | } | 1253 | } |
1249 | if (GNUNET_YES != | 1254 | if (GNUNET_YES != |
1250 | GNUNET_BLOCK_get_key (GSF_block_ctx, type, data, data_size, &query)) | 1255 | GNUNET_BLOCK_get_key (GSF_block_ctx, |
1256 | type, | ||
1257 | data, | ||
1258 | data_size, | ||
1259 | &query)) | ||
1251 | { | 1260 | { |
1252 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1261 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1253 | "Failed to derive key for block of type %d\n", | 1262 | "Failed to derive key for block of type %d\n", |
@@ -1268,8 +1277,9 @@ cadet_reply_proc (void *cls, | |||
1268 | prq.expiration); | 1277 | prq.expiration); |
1269 | prq.size = data_size; | 1278 | prq.size = data_size; |
1270 | prq.type = type; | 1279 | prq.type = type; |
1271 | prq.eo = GNUNET_BLOCK_EO_NONE; | 1280 | process_reply (&prq, |
1272 | process_reply (&prq, &query, pr); | 1281 | &query, |
1282 | pr); | ||
1273 | } | 1283 | } |
1274 | 1284 | ||
1275 | 1285 | ||
@@ -1611,7 +1621,11 @@ called_from_on_demand: | |||
1611 | prq.expiration = expiration; | 1621 | prq.expiration = expiration; |
1612 | prq.size = size; | 1622 | prq.size = size; |
1613 | if (GNUNET_OK != | 1623 | if (GNUNET_OK != |
1614 | GNUNET_BLOCK_get_key (GSF_block_ctx, type, data, size, &query)) | 1624 | GNUNET_BLOCK_get_key (GSF_block_ctx, |
1625 | type, | ||
1626 | data, | ||
1627 | size, | ||
1628 | &query)) | ||
1615 | { | 1629 | { |
1616 | GNUNET_break (0); | 1630 | GNUNET_break (0); |
1617 | GNUNET_DATASTORE_remove (GSF_dsh, | 1631 | GNUNET_DATASTORE_remove (GSF_dsh, |
@@ -1631,8 +1645,9 @@ called_from_on_demand: | |||
1631 | prq.anonymity_level = anonymity; | 1645 | prq.anonymity_level = anonymity; |
1632 | if ((0 == old_rf) && (0 == pr->public_data.results_found)) | 1646 | if ((0 == old_rf) && (0 == pr->public_data.results_found)) |
1633 | GSF_update_datastore_delay_ (pr->public_data.start_time); | 1647 | GSF_update_datastore_delay_ (pr->public_data.start_time); |
1634 | prq.eo = GNUNET_BLOCK_EO_LOCAL_SKIP_CRYPTO; | 1648 | process_reply (&prq, |
1635 | process_reply (&prq, key, pr); | 1649 | key, |
1650 | pr); | ||
1636 | pr->local_result = prq.eval; | 1651 | pr->local_result = prq.eval; |
1637 | if (GNUNET_BLOCK_REPLY_OK_LAST == prq.eval) | 1652 | if (GNUNET_BLOCK_REPLY_OK_LAST == prq.eval) |
1638 | { | 1653 | { |
@@ -1720,7 +1735,8 @@ GSF_local_lookup_ (struct GSF_PendingRequest *pr, | |||
1720 | * @param put the actual message | 1735 | * @param put the actual message |
1721 | */ | 1736 | */ |
1722 | void | 1737 | void |
1723 | handle_p2p_put (void *cls, const struct PutMessage *put) | 1738 | handle_p2p_put (void *cls, |
1739 | const struct PutMessage *put) | ||
1724 | { | 1740 | { |
1725 | struct GSF_ConnectedPeer *cp = cls; | 1741 | struct GSF_ConnectedPeer *cp = cls; |
1726 | uint16_t msize; | 1742 | uint16_t msize; |
@@ -1746,7 +1762,20 @@ handle_p2p_put (void *cls, const struct PutMessage *put) | |||
1746 | GNUNET_TIME_UNIT_YEARS), | 1762 | GNUNET_TIME_UNIT_YEARS), |
1747 | expiration); | 1763 | expiration); |
1748 | if (GNUNET_OK != | 1764 | if (GNUNET_OK != |
1749 | GNUNET_BLOCK_get_key (GSF_block_ctx, type, &put[1], dsize, &query)) | 1765 | GNUNET_BLOCK_check_block (GSF_block_ctx, |
1766 | type, | ||
1767 | &put[1], | ||
1768 | dsize)) | ||
1769 | { | ||
1770 | GNUNET_break_op (0); | ||
1771 | return; | ||
1772 | } | ||
1773 | if (GNUNET_OK != | ||
1774 | GNUNET_BLOCK_get_key (GSF_block_ctx, | ||
1775 | type, | ||
1776 | &put[1], | ||
1777 | dsize, | ||
1778 | &query)) | ||
1750 | { | 1779 | { |
1751 | GNUNET_break_op (0); | 1780 | GNUNET_break_op (0); |
1752 | return; | 1781 | return; |
@@ -1764,7 +1793,6 @@ handle_p2p_put (void *cls, const struct PutMessage *put) | |||
1764 | prq.priority = 0; | 1793 | prq.priority = 0; |
1765 | prq.anonymity_level = UINT32_MAX; | 1794 | prq.anonymity_level = UINT32_MAX; |
1766 | prq.request_found = GNUNET_NO; | 1795 | prq.request_found = GNUNET_NO; |
1767 | prq.eo = GNUNET_BLOCK_EO_NONE; | ||
1768 | GNUNET_CONTAINER_multihashmap_get_multiple (pr_map, | 1796 | GNUNET_CONTAINER_multihashmap_get_multiple (pr_map, |
1769 | &query, | 1797 | &query, |
1770 | &process_reply, | 1798 | &process_reply, |
diff --git a/src/fs/plugin_block_fs.c b/src/fs/plugin_block_fs.c index 43380b3b6..029f95bc5 100644 --- a/src/fs/plugin_block_fs.c +++ b/src/fs/plugin_block_fs.c | |||
@@ -111,110 +111,6 @@ block_plugin_fs_create_group (void *cls, | |||
111 | 111 | ||
112 | 112 | ||
113 | /** | 113 | /** |
114 | * Function called to validate a reply or a request. For | ||
115 | * request evaluation, simply pass "NULL" for the reply_block. | ||
116 | * Note that it is assumed that the reply has already been | ||
117 | * matched to the key (and signatures checked) as it would | ||
118 | * be done with the #GNUNET_BLOCK_get_key() function. | ||
119 | * | ||
120 | * @param cls closure | ||
121 | * @param ctx block context | ||
122 | * @param type block type | ||
123 | * @param bg group to use for evaluation | ||
124 | * @param eo control flags | ||
125 | * @param query original query (hash) | ||
126 | * @param xquery extrended query data (can be NULL, depending on type) | ||
127 | * @param xquery_size number of bytes in @a xquery | ||
128 | * @param reply_block response to validate | ||
129 | * @param reply_block_size number of bytes in @a reply_block | ||
130 | * @return characterization of result | ||
131 | */ | ||
132 | static enum GNUNET_BLOCK_EvaluationResult | ||
133 | block_plugin_fs_evaluate (void *cls, | ||
134 | struct GNUNET_BLOCK_Context *ctx, | ||
135 | enum GNUNET_BLOCK_Type type, | ||
136 | struct GNUNET_BLOCK_Group *bg, | ||
137 | enum GNUNET_BLOCK_EvaluationOptions eo, | ||
138 | const struct GNUNET_HashCode *query, | ||
139 | const void *xquery, | ||
140 | size_t xquery_size, | ||
141 | const void *reply_block, | ||
142 | size_t reply_block_size) | ||
143 | { | ||
144 | const struct UBlock *ub; | ||
145 | struct GNUNET_HashCode hc; | ||
146 | struct GNUNET_HashCode chash; | ||
147 | |||
148 | switch (type) | ||
149 | { | ||
150 | case GNUNET_BLOCK_TYPE_FS_DBLOCK: | ||
151 | case GNUNET_BLOCK_TYPE_FS_IBLOCK: | ||
152 | if (0 != xquery_size) | ||
153 | { | ||
154 | GNUNET_break_op (0); | ||
155 | return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID; | ||
156 | } | ||
157 | if (NULL == reply_block) | ||
158 | return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; | ||
159 | return GNUNET_BLOCK_EVALUATION_OK_LAST; | ||
160 | |||
161 | case GNUNET_BLOCK_TYPE_FS_UBLOCK: | ||
162 | if (0 != xquery_size) | ||
163 | { | ||
164 | GNUNET_break_op (0); | ||
165 | return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID; | ||
166 | } | ||
167 | if (NULL == reply_block) | ||
168 | return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; | ||
169 | |||
170 | if (reply_block_size < sizeof(struct UBlock)) | ||
171 | { | ||
172 | GNUNET_break_op (0); | ||
173 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | ||
174 | } | ||
175 | ub = reply_block; | ||
176 | GNUNET_CRYPTO_hash (&ub->verification_key, | ||
177 | sizeof(ub->verification_key), | ||
178 | &hc); | ||
179 | if (0 != memcmp (&hc, | ||
180 | query, | ||
181 | sizeof(struct GNUNET_HashCode))) | ||
182 | { | ||
183 | GNUNET_break_op (0); | ||
184 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | ||
185 | } | ||
186 | if (reply_block_size != ntohl (ub->purpose.size) + sizeof(struct | ||
187 | GNUNET_CRYPTO_EcdsaSignature)) | ||
188 | { | ||
189 | GNUNET_break_op (0); | ||
190 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | ||
191 | } | ||
192 | if ((0 == (eo & GNUNET_BLOCK_EO_LOCAL_SKIP_CRYPTO)) && | ||
193 | (GNUNET_OK != | ||
194 | GNUNET_CRYPTO_ecdsa_verify_ (GNUNET_SIGNATURE_PURPOSE_FS_UBLOCK, | ||
195 | &ub->purpose, | ||
196 | &ub->signature, | ||
197 | &ub->verification_key))) | ||
198 | { | ||
199 | GNUNET_break_op (0); | ||
200 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | ||
201 | } | ||
202 | GNUNET_CRYPTO_hash (reply_block, | ||
203 | reply_block_size, | ||
204 | &chash); | ||
205 | if (GNUNET_YES == | ||
206 | GNUNET_BLOCK_GROUP_bf_test_and_set (bg, | ||
207 | &chash)) | ||
208 | return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE; | ||
209 | return GNUNET_BLOCK_EVALUATION_OK_MORE; | ||
210 | |||
211 | default: | ||
212 | return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; | ||
213 | } | ||
214 | } | ||
215 | |||
216 | |||
217 | /** | ||
218 | * Function called to obtain the key for a block. | 114 | * Function called to obtain the key for a block. |
219 | * | 115 | * |
220 | * @param cls closure | 116 | * @param cls closure |
@@ -245,8 +141,11 @@ block_plugin_fs_get_key (void *cls, | |||
245 | case GNUNET_BLOCK_TYPE_FS_UBLOCK: | 141 | case GNUNET_BLOCK_TYPE_FS_UBLOCK: |
246 | if (block_size < sizeof(struct UBlock)) | 142 | if (block_size < sizeof(struct UBlock)) |
247 | { | 143 | { |
248 | GNUNET_break (0); | 144 | GNUNET_break_op (0); |
249 | return GNUNET_SYSERR; | 145 | memset (key, |
146 | 0, | ||
147 | sizeof (*key)); | ||
148 | return GNUNET_OK; | ||
250 | } | 149 | } |
251 | ub = block; | 150 | ub = block; |
252 | GNUNET_CRYPTO_hash (&ub->verification_key, | 151 | GNUNET_CRYPTO_hash (&ub->verification_key, |
@@ -290,6 +189,7 @@ block_plugin_fs_check_query (void *cls, | |||
290 | } | 189 | } |
291 | return GNUNET_OK; | 190 | return GNUNET_OK; |
292 | default: | 191 | default: |
192 | GNUNET_break (0); | ||
293 | return GNUNET_SYSERR; | 193 | return GNUNET_SYSERR; |
294 | } | 194 | } |
295 | } | 195 | } |
@@ -300,7 +200,6 @@ block_plugin_fs_check_query (void *cls, | |||
300 | * | 200 | * |
301 | * @param cls closure | 201 | * @param cls closure |
302 | * @param type block type | 202 | * @param type block type |
303 | * @param query key for the block (hash), must match exactly | ||
304 | * @param block block data to validate | 203 | * @param block block data to validate |
305 | * @param block_size number of bytes in @a block | 204 | * @param block_size number of bytes in @a block |
306 | * @return #GNUNET_OK if the block is fine, #GNUNET_NO if not | 205 | * @return #GNUNET_OK if the block is fine, #GNUNET_NO if not |
@@ -308,7 +207,6 @@ block_plugin_fs_check_query (void *cls, | |||
308 | static enum GNUNET_GenericReturnValue | 207 | static enum GNUNET_GenericReturnValue |
309 | block_plugin_fs_check_block (void *cls, | 208 | block_plugin_fs_check_block (void *cls, |
310 | enum GNUNET_BLOCK_Type type, | 209 | enum GNUNET_BLOCK_Type type, |
311 | const struct GNUNET_HashCode *query, | ||
312 | const void *block, | 210 | const void *block, |
313 | size_t block_size) | 211 | size_t block_size) |
314 | { | 212 | { |
@@ -346,6 +244,7 @@ block_plugin_fs_check_block (void *cls, | |||
346 | return GNUNET_OK; | 244 | return GNUNET_OK; |
347 | } | 245 | } |
348 | default: | 246 | default: |
247 | GNUNET_break (0); | ||
349 | return GNUNET_SYSERR; | 248 | return GNUNET_SYSERR; |
350 | } | 249 | } |
351 | } | 250 | } |
@@ -396,6 +295,7 @@ block_plugin_fs_check_reply (void *cls, | |||
396 | return GNUNET_BLOCK_REPLY_OK_MORE; | 295 | return GNUNET_BLOCK_REPLY_OK_MORE; |
397 | } | 296 | } |
398 | default: | 297 | default: |
298 | GNUNET_break (0); | ||
399 | return GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED; | 299 | return GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED; |
400 | } | 300 | } |
401 | } | 301 | } |
@@ -416,7 +316,6 @@ libgnunet_plugin_block_fs_init (void *cls) | |||
416 | struct GNUNET_BLOCK_PluginFunctions *api; | 316 | struct GNUNET_BLOCK_PluginFunctions *api; |
417 | 317 | ||
418 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); | 318 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); |
419 | api->evaluate = &block_plugin_fs_evaluate; | ||
420 | api->get_key = &block_plugin_fs_get_key; | 319 | api->get_key = &block_plugin_fs_get_key; |
421 | api->create_group = &block_plugin_fs_create_group; | 320 | api->create_group = &block_plugin_fs_create_group; |
422 | api->check_query = &block_plugin_fs_check_query; | 321 | api->check_query = &block_plugin_fs_check_query; |