aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2010-09-18 04:49:08 +0000
committerChristian Grothoff <christian@grothoff.org>2010-09-18 04:49:08 +0000
commit80e2d4cacefb32af3466f6aae0d14e20b2135401 (patch)
treebfacd8952d4cab2d117fb0b1e825a84f0a669f4c /src
parent68ca8e952d332b505db3c1dbd84078305fa15410 (diff)
downloadgnunet-80e2d4cacefb32af3466f6aae0d14e20b2135401.tar.gz
gnunet-80e2d4cacefb32af3466f6aae0d14e20b2135401.zip
use block lib some more
Diffstat (limited to 'src')
-rw-r--r--src/fs/fs_publish.c1
-rw-r--r--src/fs/gnunet-service-fs.c146
2 files changed, 92 insertions, 55 deletions
diff --git a/src/fs/fs_publish.c b/src/fs/fs_publish.c
index 2c9d41b05..0b0617340 100644
--- a/src/fs/fs_publish.c
+++ b/src/fs/fs_publish.c
@@ -1639,6 +1639,7 @@ GNUNET_FS_publish_ksk (struct GNUNET_FS_Handle *h,
1639 char *kbe; 1639 char *kbe;
1640 char *sptr; 1640 char *sptr;
1641 1641
1642 GNUNET_assert (NULL != uri);
1642 pkc = GNUNET_malloc (sizeof (struct PublishKskContext)); 1643 pkc = GNUNET_malloc (sizeof (struct PublishKskContext));
1643 pkc->h = h; 1644 pkc->h = h;
1644 pkc->expirationTime = expirationTime; 1645 pkc->expirationTime = expirationTime;
diff --git a/src/fs/gnunet-service-fs.c b/src/fs/gnunet-service-fs.c
index a0e275f2d..72d89c726 100644
--- a/src/fs/gnunet-service-fs.c
+++ b/src/fs/gnunet-service-fs.c
@@ -1787,23 +1787,6 @@ add_to_pending_messages_for_peer (struct ConnectedPeer *cp,
1787 1787
1788 1788
1789/** 1789/**
1790 * Mingle hash with the mingle_number to produce different bits.
1791 */
1792static void
1793mingle_hash (const GNUNET_HashCode * in,
1794 int32_t mingle_number,
1795 GNUNET_HashCode * hc)
1796{
1797 GNUNET_HashCode m;
1798
1799 GNUNET_CRYPTO_hash (&mingle_number,
1800 sizeof (int32_t),
1801 &m);
1802 GNUNET_CRYPTO_hash_xor (&m, in, hc);
1803}
1804
1805
1806/**
1807 * Test if the load on this peer is too high 1790 * Test if the load on this peer is too high
1808 * to even consider processing the query at 1791 * to even consider processing the query at
1809 * all. 1792 * all.
@@ -1965,7 +1948,9 @@ refresh_bloomfilter (struct PendingRequest *pr)
1965 BLOOMFILTER_K); 1948 BLOOMFILTER_K);
1966 for (i=0;i<pr->replies_seen_off;i++) 1949 for (i=0;i<pr->replies_seen_off;i++)
1967 { 1950 {
1968 mingle_hash (&pr->replies_seen[i], pr->mingle, &mhash); 1951 GNUNET_BLOCK_mingle_hash (&pr->replies_seen[i],
1952 pr->mingle,
1953 &mhash);
1969 GNUNET_CONTAINER_bloomfilter_add (pr->bf, &mhash); 1954 GNUNET_CONTAINER_bloomfilter_add (pr->bf, &mhash);
1970 } 1955 }
1971} 1956}
@@ -2534,8 +2519,7 @@ process_reply (void *cls,
2534 struct PutMessage *pm; 2519 struct PutMessage *pm;
2535 struct ConnectedPeer *cp; 2520 struct ConnectedPeer *cp;
2536 struct GNUNET_TIME_Relative cur_delay; 2521 struct GNUNET_TIME_Relative cur_delay;
2537 GNUNET_HashCode chash; 2522 enum GNUNET_BLOCK_EvaluationResult eval;
2538 GNUNET_HashCode mhash;
2539 size_t msize; 2523 size_t msize;
2540 2524
2541#if DEBUG_FS 2525#if DEBUG_FS
@@ -2581,9 +2565,6 @@ process_reply (void *cls,
2581 GNUNET_SERVER_client_keep (pr->client_request_list->client_list->client); 2565 GNUNET_SERVER_client_keep (pr->client_request_list->client_list->client);
2582 } 2566 }
2583 } 2567 }
2584 GNUNET_CRYPTO_hash (prq->data,
2585 prq->size,
2586 &chash);
2587 switch (prq->type) 2568 switch (prq->type)
2588 { 2569 {
2589 case GNUNET_BLOCK_TYPE_DBLOCK: 2570 case GNUNET_BLOCK_TYPE_DBLOCK:
@@ -2617,39 +2598,96 @@ process_reply (void *cls,
2617 GNUNET_break (0); 2598 GNUNET_break (0);
2618 return GNUNET_YES; 2599 return GNUNET_YES;
2619 } 2600 }
2620 if (0 != memcmp (pr->namespace, 2601 eval = GNUNET_BLOCK_evaluate (block_ctx,
2621 &prq->namespace, 2602 prq->type,
2622 sizeof (GNUNET_HashCode))) 2603 key,
2604 &pr->bf,
2605 pr->mingle,
2606 pr->namespace, sizeof (GNUNET_HashCode),
2607 prq->data,
2608 prq->size);
2609 switch (eval)
2623 { 2610 {
2624 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2611 case GNUNET_BLOCK_EVALUATION_OK_MORE:
2625 _("Reply mismatched in terms of namespace. Discarded.\n")); 2612 break;
2613 case GNUNET_BLOCK_EVALUATION_OK_LAST:
2614 break;
2615 case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE:
2616 GNUNET_STATISTICS_update (stats,
2617 gettext_noop ("# duplicate replies discarded (bloomfilter)"),
2618 1,
2619 GNUNET_NO);
2620#if DEBUG_FS
2621 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2622 "Duplicate response `%s', discarding.\n",
2623 GNUNET_h2s (&mhash));
2624#endif
2625 return GNUNET_YES; /* duplicate */
2626 case GNUNET_BLOCK_EVALUATION_RESULT_INVALID:
2626 return GNUNET_YES; /* wrong namespace */ 2627 return GNUNET_YES; /* wrong namespace */
2628 case GNUNET_BLOCK_EVALUATION_REQUEST_VALID:
2629 GNUNET_break (0);
2630 return GNUNET_YES;
2631 case GNUNET_BLOCK_EVALUATION_REQUEST_INVALID:
2632 GNUNET_break (0);
2633 return GNUNET_YES;
2634 case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED:
2635 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2636 _("Block library does not support FS blocks\n"));
2637 return GNUNET_NO;
2627 } 2638 }
2628 /* then: fall-through! */ 2639 if (pr->client_request_list != NULL)
2640 {
2641 if (pr->replies_seen_size == pr->replies_seen_off)
2642 GNUNET_array_grow (pr->replies_seen,
2643 pr->replies_seen_size,
2644 pr->replies_seen_size * 2 + 4);
2645 GNUNET_CRYPTO_hash (prq->data,
2646 prq->size,
2647 &pr->replies_seen[pr->replies_seen_off++]);
2648 refresh_bloomfilter (pr);
2649 }
2650 break;
2629 case GNUNET_BLOCK_TYPE_KBLOCK: 2651 case GNUNET_BLOCK_TYPE_KBLOCK:
2630 case GNUNET_BLOCK_TYPE_NBLOCK: 2652 case GNUNET_BLOCK_TYPE_NBLOCK:
2631 if (pr->bf != NULL) 2653 eval = GNUNET_BLOCK_evaluate (block_ctx,
2654 prq->type,
2655 key,
2656 &pr->bf,
2657 pr->mingle,
2658 NULL, 0,
2659 prq->data,
2660 prq->size);
2661 switch (eval)
2632 { 2662 {
2633 mingle_hash (&chash, pr->mingle, &mhash); 2663 case GNUNET_BLOCK_EVALUATION_OK_MORE:
2634 if (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (pr->bf, 2664 break;
2635 &mhash)) 2665 case GNUNET_BLOCK_EVALUATION_OK_LAST:
2636 { 2666 break;
2637 GNUNET_STATISTICS_update (stats, 2667 case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE:
2638 gettext_noop ("# duplicate replies discarded (bloomfilter)"), 2668 GNUNET_STATISTICS_update (stats,
2639 1, 2669 gettext_noop ("# duplicate replies discarded (bloomfilter)"),
2640 GNUNET_NO); 2670 1,
2641#if DEBUG_FS 2671 GNUNET_NO);
2642 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2643 "Duplicate response `%s', discarding.\n",
2644 GNUNET_h2s (&mhash));
2645#endif
2646 return GNUNET_YES; /* duplicate */
2647 }
2648#if DEBUG_FS 2672#if DEBUG_FS
2649 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2673 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2650 "New response `%s', adding to filter.\n", 2674 "Duplicate response `%s', discarding.\n",
2651 GNUNET_h2s (&mhash)); 2675 GNUNET_h2s (&mhash));
2652#endif 2676#endif
2677 return GNUNET_YES; /* duplicate */
2678 case GNUNET_BLOCK_EVALUATION_RESULT_INVALID:
2679 GNUNET_break_op (0);
2680 return GNUNET_YES;
2681 case GNUNET_BLOCK_EVALUATION_REQUEST_VALID:
2682 GNUNET_break (0);
2683 return GNUNET_YES;
2684 case GNUNET_BLOCK_EVALUATION_REQUEST_INVALID:
2685 GNUNET_break (0);
2686 return GNUNET_YES;
2687 case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED:
2688 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2689 _("Block library does not support FS blocks\n"));
2690 return GNUNET_NO;
2653 } 2691 }
2654 if (pr->client_request_list != NULL) 2692 if (pr->client_request_list != NULL)
2655 { 2693 {
@@ -2657,13 +2695,11 @@ process_reply (void *cls,
2657 GNUNET_array_grow (pr->replies_seen, 2695 GNUNET_array_grow (pr->replies_seen,
2658 pr->replies_seen_size, 2696 pr->replies_seen_size,
2659 pr->replies_seen_size * 2 + 4); 2697 pr->replies_seen_size * 2 + 4);
2660 pr->replies_seen[pr->replies_seen_off++] = chash; 2698 GNUNET_CRYPTO_hash (prq->data,
2699 prq->size,
2700 &pr->replies_seen[pr->replies_seen_off++]);
2701 refresh_bloomfilter (pr);
2661 } 2702 }
2662 if ( (pr->bf == NULL) ||
2663 (pr->client_request_list != NULL) )
2664 refresh_bloomfilter (pr);
2665 GNUNET_CONTAINER_bloomfilter_add (pr->bf,
2666 &mhash);
2667 break; 2703 break;
2668 default: 2704 default:
2669 GNUNET_break (0); 2705 GNUNET_break (0);
@@ -3027,9 +3063,9 @@ process_local_reply (void *cls,
3027 } 3063 }
3028 /* check for duplicates */ 3064 /* check for duplicates */
3029 GNUNET_CRYPTO_hash (data, size, &dhash); 3065 GNUNET_CRYPTO_hash (data, size, &dhash);
3030 mingle_hash (&dhash, 3066 GNUNET_BLOCK_mingle_hash (&dhash,
3031 pr->mingle, 3067 pr->mingle,
3032 &mhash); 3068 &mhash);
3033 if ( (pr->bf != NULL) && 3069 if ( (pr->bf != NULL) &&
3034 (GNUNET_YES == 3070 (GNUNET_YES ==
3035 GNUNET_CONTAINER_bloomfilter_test (pr->bf, 3071 GNUNET_CONTAINER_bloomfilter_test (pr->bf,