diff options
author | Christian Grothoff <christian@grothoff.org> | 2017-02-20 17:19:47 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2017-02-20 17:19:47 +0100 |
commit | f6f7fbbe98c110867febbcca647da8308be123c7 (patch) | |
tree | af69447cf4f08c417197685855c097c132aea8a1 /src/fs/gnunet-service-fs_pr.c | |
parent | a3882b58f1c5976677aa65b0af8a48e8e946b06e (diff) | |
download | gnunet-f6f7fbbe98c110867febbcca647da8308be123c7.tar.gz gnunet-f6f7fbbe98c110867febbcca647da8308be123c7.zip |
completed big block refactoring in preparation for SET-BLOCK integration
Diffstat (limited to 'src/fs/gnunet-service-fs_pr.c')
-rw-r--r-- | src/fs/gnunet-service-fs_pr.c | 139 |
1 files changed, 76 insertions, 63 deletions
diff --git a/src/fs/gnunet-service-fs_pr.c b/src/fs/gnunet-service-fs_pr.c index 63462f7dc..87e2d2ee1 100644 --- a/src/fs/gnunet-service-fs_pr.c +++ b/src/fs/gnunet-service-fs_pr.c | |||
@@ -97,9 +97,9 @@ struct GSF_PendingRequest | |||
97 | struct GNUNET_HashCode *replies_seen; | 97 | struct GNUNET_HashCode *replies_seen; |
98 | 98 | ||
99 | /** | 99 | /** |
100 | * Bloomfilter masking replies we've already seen. | 100 | * Block group for filtering replies we've already seen. |
101 | */ | 101 | */ |
102 | struct GNUNET_CONTAINER_BloomFilter *bf; | 102 | struct GNUNET_BLOCK_Group *bg; |
103 | 103 | ||
104 | /** | 104 | /** |
105 | * Entry for this pending request in the expiration heap, or NULL. | 105 | * Entry for this pending request in the expiration heap, or NULL. |
@@ -190,11 +190,6 @@ struct GSF_PendingRequest | |||
190 | unsigned int replies_seen_size; | 190 | unsigned int replies_seen_size; |
191 | 191 | ||
192 | /** | 192 | /** |
193 | * Mingle value we currently use for the bf. | ||
194 | */ | ||
195 | uint32_t mingle; | ||
196 | |||
197 | /** | ||
198 | * Do we have a first UID yet? | 193 | * Do we have a first UID yet? |
199 | */ | 194 | */ |
200 | unsigned int have_first_uid; | 195 | unsigned int have_first_uid; |
@@ -248,18 +243,35 @@ static unsigned long long max_pending_requests = (32 * 1024); | |||
248 | * fresh one of minimal size without problems) OR if our peer is the | 243 | * fresh one of minimal size without problems) OR if our peer is the |
249 | * initiator (in which case we may resize to larger than mimimum size). | 244 | * initiator (in which case we may resize to larger than mimimum size). |
250 | * | 245 | * |
246 | * @param type type of the request | ||
251 | * @param pr request for which the BF is to be recomputed | 247 | * @param pr request for which the BF is to be recomputed |
252 | */ | 248 | */ |
253 | static void | 249 | static void |
254 | refresh_bloomfilter (struct GSF_PendingRequest *pr) | 250 | refresh_bloomfilter (enum GNUNET_BLOCK_Type type, |
251 | struct GSF_PendingRequest *pr) | ||
255 | { | 252 | { |
256 | if (pr->bf != NULL) | 253 | if (NULL != pr->bg) |
257 | GNUNET_CONTAINER_bloomfilter_free (pr->bf); | 254 | { |
258 | pr->mingle = | 255 | GNUNET_BLOCK_group_destroy (pr->bg); |
259 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX); | 256 | pr->bg = NULL; |
260 | pr->bf = | 257 | } |
261 | GNUNET_BLOCK_construct_bloomfilter (pr->mingle, pr->replies_seen, | 258 | if (GNUNET_BLOCK_TYPE_FS_UBLOCK != type) |
262 | pr->replies_seen_count); | 259 | return; /* no need */ |
260 | pr->bg | ||
261 | = GNUNET_BLOCK_group_create (GSF_block_ctx, | ||
262 | type, | ||
263 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | ||
264 | UINT32_MAX), | ||
265 | NULL, | ||
266 | 0, | ||
267 | "fs-seen-set-size", | ||
268 | pr->replies_seen_count); | ||
269 | if (NULL == pr->bg) | ||
270 | return; | ||
271 | GNUNET_break (GNUNET_OK == | ||
272 | GNUNET_BLOCK_group_set_seen (pr->bg, | ||
273 | pr->replies_seen, | ||
274 | pr->replies_seen_count)); | ||
263 | } | 275 | } |
264 | 276 | ||
265 | 277 | ||
@@ -355,25 +367,30 @@ GSF_pending_request_create_ (enum GSF_PendingRequestOptions options, | |||
355 | if (replies_seen_count > 0) | 367 | if (replies_seen_count > 0) |
356 | { | 368 | { |
357 | pr->replies_seen_size = replies_seen_count; | 369 | pr->replies_seen_size = replies_seen_count; |
358 | pr->replies_seen = | 370 | pr->replies_seen = GNUNET_new_array (pr->replies_seen_size, |
359 | GNUNET_malloc (sizeof (struct GNUNET_HashCode) * pr->replies_seen_size); | 371 | struct GNUNET_HashCode); |
360 | GNUNET_memcpy (pr->replies_seen, | 372 | GNUNET_memcpy (pr->replies_seen, |
361 | replies_seen, | 373 | replies_seen, |
362 | replies_seen_count * sizeof (struct GNUNET_HashCode)); | 374 | replies_seen_count * sizeof (struct GNUNET_HashCode)); |
363 | pr->replies_seen_count = replies_seen_count; | 375 | pr->replies_seen_count = replies_seen_count; |
364 | } | 376 | } |
365 | if (NULL != bf_data) | 377 | if ( (NULL != bf_data) && |
378 | (GNUNET_BLOCK_TYPE_FS_UBLOCK == pr->public_data.type) ) | ||
366 | { | 379 | { |
367 | pr->bf = | 380 | pr->bg |
368 | GNUNET_CONTAINER_bloomfilter_init (bf_data, | 381 | = GNUNET_BLOCK_group_create (GSF_block_ctx, |
369 | bf_size, | 382 | pr->public_data.type, |
370 | GNUNET_CONSTANTS_BLOOMFILTER_K); | 383 | mingle, |
371 | pr->mingle = mingle; | 384 | bf_data, |
385 | bf_size, | ||
386 | "fs-seen-set-size", | ||
387 | 0); | ||
372 | } | 388 | } |
373 | else if ((replies_seen_count > 0) && | 389 | else if ((replies_seen_count > 0) && |
374 | (0 != (options & GSF_PRO_BLOOMFILTER_FULL_REFRESH))) | 390 | (0 != (options & GSF_PRO_BLOOMFILTER_FULL_REFRESH))) |
375 | { | 391 | { |
376 | refresh_bloomfilter (pr); | 392 | refresh_bloomfilter (pr->public_data.type, |
393 | pr); | ||
377 | } | 394 | } |
378 | GNUNET_CONTAINER_multihashmap_put (pr_map, | 395 | GNUNET_CONTAINER_multihashmap_put (pr_map, |
379 | &pr->public_data.query, | 396 | &pr->public_data.query, |
@@ -461,46 +478,37 @@ GSF_pending_request_update_ (struct GSF_PendingRequest *pr, | |||
461 | const struct GNUNET_HashCode * replies_seen, | 478 | const struct GNUNET_HashCode * replies_seen, |
462 | unsigned int replies_seen_count) | 479 | unsigned int replies_seen_count) |
463 | { | 480 | { |
464 | unsigned int i; | ||
465 | struct GNUNET_HashCode mhash; | ||
466 | |||
467 | if (replies_seen_count + pr->replies_seen_count < pr->replies_seen_count) | 481 | if (replies_seen_count + pr->replies_seen_count < pr->replies_seen_count) |
468 | return; /* integer overflow */ | 482 | return; /* integer overflow */ |
469 | if (0 != (pr->public_data.options & GSF_PRO_BLOOMFILTER_FULL_REFRESH)) | 483 | if (0 != (pr->public_data.options & GSF_PRO_BLOOMFILTER_FULL_REFRESH)) |
470 | { | 484 | { |
471 | /* we're responsible for the BF, full refresh */ | 485 | /* we're responsible for the BF, full refresh */ |
472 | if (replies_seen_count + pr->replies_seen_count > pr->replies_seen_size) | 486 | if (replies_seen_count + pr->replies_seen_count > pr->replies_seen_size) |
473 | GNUNET_array_grow (pr->replies_seen, pr->replies_seen_size, | 487 | GNUNET_array_grow (pr->replies_seen, |
488 | pr->replies_seen_size, | ||
474 | replies_seen_count + pr->replies_seen_count); | 489 | replies_seen_count + pr->replies_seen_count); |
475 | GNUNET_memcpy (&pr->replies_seen[pr->replies_seen_count], replies_seen, | 490 | GNUNET_memcpy (&pr->replies_seen[pr->replies_seen_count], |
476 | sizeof (struct GNUNET_HashCode) * replies_seen_count); | 491 | replies_seen, |
492 | sizeof (struct GNUNET_HashCode) * replies_seen_count); | ||
477 | pr->replies_seen_count += replies_seen_count; | 493 | pr->replies_seen_count += replies_seen_count; |
478 | refresh_bloomfilter (pr); | 494 | refresh_bloomfilter (pr->public_data.type, |
495 | pr); | ||
479 | } | 496 | } |
480 | else | 497 | else |
481 | { | 498 | { |
482 | if (NULL == pr->bf) | 499 | if (NULL == pr->bg) |
483 | { | 500 | { |
484 | /* we're not the initiator, but the initiator did not give us | 501 | /* we're not the initiator, but the initiator did not give us |
485 | * any bloom-filter, so we need to create one on-the-fly */ | 502 | * any bloom-filter, so we need to create one on-the-fly */ |
486 | pr->mingle = | 503 | refresh_bloomfilter (pr->public_data.type, |
487 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | 504 | pr); |
488 | UINT32_MAX); | ||
489 | pr->bf = | ||
490 | GNUNET_BLOCK_construct_bloomfilter (pr->mingle, | ||
491 | replies_seen, | ||
492 | replies_seen_count); | ||
493 | } | 505 | } |
494 | else | 506 | else |
495 | { | 507 | { |
496 | for (i = 0; i < pr->replies_seen_count; i++) | 508 | GNUNET_break (GNUNET_OK == |
497 | { | 509 | GNUNET_BLOCK_group_set_seen (pr->bg, |
498 | GNUNET_BLOCK_mingle_hash (&replies_seen[i], | 510 | replies_seen, |
499 | pr->mingle, | 511 | pr->replies_seen_count)); |
500 | &mhash); | ||
501 | GNUNET_CONTAINER_bloomfilter_add (pr->bf, | ||
502 | &mhash); | ||
503 | } | ||
504 | } | 512 | } |
505 | } | 513 | } |
506 | if (NULL != pr->gh) | 514 | if (NULL != pr->gh) |
@@ -530,6 +538,8 @@ GSF_pending_request_get_message_ (struct GSF_PendingRequest *pr) | |||
530 | struct GNUNET_TIME_Absolute now; | 538 | struct GNUNET_TIME_Absolute now; |
531 | int64_t ttl; | 539 | int64_t ttl; |
532 | int do_route; | 540 | int do_route; |
541 | void *bf_data; | ||
542 | uint32_t bf_nonce; | ||
533 | 543 | ||
534 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 544 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
535 | "Building request message for `%s' of type %d\n", | 545 | "Building request message for `%s' of type %d\n", |
@@ -553,7 +563,15 @@ GSF_pending_request_get_message_ (struct GSF_PendingRequest *pr) | |||
553 | bm |= GET_MESSAGE_BIT_TRANSMIT_TO; | 563 | bm |= GET_MESSAGE_BIT_TRANSMIT_TO; |
554 | k++; | 564 | k++; |
555 | } | 565 | } |
556 | bf_size = GNUNET_CONTAINER_bloomfilter_get_size (pr->bf); | 566 | if (GNUNET_OK != |
567 | GNUNET_BLOCK_group_serialize (pr->bg, | ||
568 | &bf_nonce, | ||
569 | &bf_data, | ||
570 | &bf_size)) | ||
571 | { | ||
572 | bf_size = 0; | ||
573 | bf_data = NULL; | ||
574 | } | ||
557 | env = GNUNET_MQ_msg_extra (gm, | 575 | env = GNUNET_MQ_msg_extra (gm, |
558 | bf_size + k * sizeof (struct GNUNET_PeerIdentity), | 576 | bf_size + k * sizeof (struct GNUNET_PeerIdentity), |
559 | GNUNET_MESSAGE_TYPE_FS_GET); | 577 | GNUNET_MESSAGE_TYPE_FS_GET); |
@@ -571,7 +589,7 @@ GSF_pending_request_get_message_ (struct GSF_PendingRequest *pr) | |||
571 | now = GNUNET_TIME_absolute_get (); | 589 | now = GNUNET_TIME_absolute_get (); |
572 | ttl = (int64_t) (pr->public_data.ttl.abs_value_us - now.abs_value_us); | 590 | ttl = (int64_t) (pr->public_data.ttl.abs_value_us - now.abs_value_us); |
573 | gm->ttl = htonl (ttl / 1000LL / 1000LL); | 591 | gm->ttl = htonl (ttl / 1000LL / 1000LL); |
574 | gm->filter_mutator = htonl (pr->mingle); | 592 | gm->filter_mutator = htonl (bf_nonce); |
575 | gm->hash_bitmap = htonl (bm); | 593 | gm->hash_bitmap = htonl (bm); |
576 | gm->query = pr->public_data.query; | 594 | gm->query = pr->public_data.query; |
577 | ext = (struct GNUNET_PeerIdentity *) &gm[1]; | 595 | ext = (struct GNUNET_PeerIdentity *) &gm[1]; |
@@ -581,11 +599,10 @@ GSF_pending_request_get_message_ (struct GSF_PendingRequest *pr) | |||
581 | &ext[k++]); | 599 | &ext[k++]); |
582 | if (NULL != pr->public_data.target) | 600 | if (NULL != pr->public_data.target) |
583 | ext[k++] = *pr->public_data.target; | 601 | ext[k++] = *pr->public_data.target; |
584 | if (NULL != pr->bf) | 602 | GNUNET_memcpy (&ext[k], |
585 | GNUNET_assert (GNUNET_SYSERR != | 603 | bf_data, |
586 | GNUNET_CONTAINER_bloomfilter_get_raw_data (pr->bf, | 604 | bf_size); |
587 | (char *) &ext[k], | 605 | GNUNET_free_non_null (bf_data); |
588 | bf_size)); | ||
589 | return env; | 606 | return env; |
590 | } | 607 | } |
591 | 608 | ||
@@ -624,11 +641,8 @@ clean_request (void *cls, | |||
624 | } | 641 | } |
625 | GSF_plan_notify_request_done_ (pr); | 642 | GSF_plan_notify_request_done_ (pr); |
626 | GNUNET_free_non_null (pr->replies_seen); | 643 | GNUNET_free_non_null (pr->replies_seen); |
627 | if (NULL != pr->bf) | 644 | GNUNET_BLOCK_group_destroy (pr->bg); |
628 | { | 645 | pr->bg = NULL; |
629 | GNUNET_CONTAINER_bloomfilter_free (pr->bf); | ||
630 | pr->bf = NULL; | ||
631 | } | ||
632 | GNUNET_PEER_change_rc (pr->sender_pid, -1); | 646 | GNUNET_PEER_change_rc (pr->sender_pid, -1); |
633 | pr->sender_pid = 0; | 647 | pr->sender_pid = 0; |
634 | GNUNET_PEER_change_rc (pr->origin_pid, -1); | 648 | GNUNET_PEER_change_rc (pr->origin_pid, -1); |
@@ -844,10 +858,9 @@ process_reply (void *cls, | |||
844 | prq->eval = | 858 | prq->eval = |
845 | GNUNET_BLOCK_evaluate (GSF_block_ctx, | 859 | GNUNET_BLOCK_evaluate (GSF_block_ctx, |
846 | prq->type, | 860 | prq->type, |
861 | pr->bg, | ||
847 | prq->eo, | 862 | prq->eo, |
848 | key, | 863 | key, |
849 | &pr->bf, | ||
850 | pr->mingle, | ||
851 | NULL, | 864 | NULL, |
852 | 0, | 865 | 0, |
853 | prq->data, | 866 | prq->data, |