aboutsummaryrefslogtreecommitdiff
path: root/src/fs
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-09-27 11:29:11 +0000
committerChristian Grothoff <christian@grothoff.org>2011-09-27 11:29:11 +0000
commit926f5a24e5a30566a51effb0e1752c15b0fa1e88 (patch)
tree744173dbd29bf685d2424db58f620b53c24cce1d /src/fs
parentb9ae190b8cfaa9124e284cc46595fa3b52b16696 (diff)
downloadgnunet-926f5a24e5a30566a51effb0e1752c15b0fa1e88.tar.gz
gnunet-926f5a24e5a30566a51effb0e1752c15b0fa1e88.zip
move bloomfilter recalculation to block library
Diffstat (limited to 'src/fs')
-rw-r--r--src/fs/fs.h6
-rw-r--r--src/fs/gnunet-service-fs_pr.c84
2 files changed, 18 insertions, 72 deletions
diff --git a/src/fs/fs.h b/src/fs/fs.h
index ed74850b2..b5fdb1cc7 100644
--- a/src/fs/fs.h
+++ b/src/fs/fs.h
@@ -132,12 +132,6 @@
132#define HASHING_BLOCKSIZE (1024 * 128) 132#define HASHING_BLOCKSIZE (1024 * 128)
133 133
134/** 134/**
135 * Number of bits we set per entry in the bloomfilter.
136 * Do not change!
137 */
138#define BLOOMFILTER_K GNUNET_DHT_GET_BLOOMFILTER_K
139
140/**
141 * Number of availability trials we perform per search result. 135 * Number of availability trials we perform per search result.
142 */ 136 */
143#define AVAILABILITY_TRIALS_MAX 8 137#define AVAILABILITY_TRIALS_MAX 8
diff --git a/src/fs/gnunet-service-fs_pr.c b/src/fs/gnunet-service-fs_pr.c
index f63c088c0..d47d28ce6 100644
--- a/src/fs/gnunet-service-fs_pr.c
+++ b/src/fs/gnunet-service-fs_pr.c
@@ -188,35 +188,6 @@ static struct GNUNET_CONTAINER_Heap *requests_by_expiration_heap;
188static unsigned long long max_pending_requests = (32 * 1024); 188static unsigned long long max_pending_requests = (32 * 1024);
189 189
190 190
191/**
192 * How many bytes should a bloomfilter be if we have already seen
193 * entry_count responses? Note that BLOOMFILTER_K gives us the number
194 * of bits set per entry. Furthermore, we should not re-size the
195 * filter too often (to keep it cheap).
196 *
197 * Since other peers will also add entries but not resize the filter,
198 * we should generally pick a slightly larger size than what the
199 * strict math would suggest.
200 *
201 * @return must be a power of two and smaller or equal to 2^15.
202 */
203static size_t
204compute_bloomfilter_size (unsigned int entry_count)
205{
206 size_t size;
207 unsigned int ideal = (entry_count * BLOOMFILTER_K) / 4;
208 uint16_t max = 1 << 15;
209
210 if (entry_count > max)
211 return max;
212 size = 8;
213 while ((size < max) && (size < ideal))
214 size *= 2;
215 if (size > max)
216 return max;
217 return size;
218}
219
220 191
221/** 192/**
222 * Recalculate our bloom filter for filtering replies. This function 193 * Recalculate our bloom filter for filtering replies. This function
@@ -226,30 +197,17 @@ compute_bloomfilter_size (unsigned int entry_count)
226 * initiator (in which case we may resize to larger than mimimum size). 197 * initiator (in which case we may resize to larger than mimimum size).
227 * 198 *
228 * @param pr request for which the BF is to be recomputed 199 * @param pr request for which the BF is to be recomputed
229 * @return GNUNET_YES if a refresh actually happened
230 */ 200 */
231static int 201static void
232refresh_bloomfilter (struct GSF_PendingRequest *pr) 202refresh_bloomfilter (struct GSF_PendingRequest *pr)
233{ 203{
234 unsigned int i;
235 size_t nsize;
236 GNUNET_HashCode mhash;
237
238 nsize = compute_bloomfilter_size (pr->replies_seen_count);
239 if ((pr->bf != NULL) &&
240 (nsize == GNUNET_CONTAINER_bloomfilter_get_size (pr->bf)))
241 return GNUNET_NO; /* size not changed */
242 if (pr->bf != NULL) 204 if (pr->bf != NULL)
243 GNUNET_CONTAINER_bloomfilter_free (pr->bf); 205 GNUNET_CONTAINER_bloomfilter_free (pr->bf);
244 pr->mingle = 206 pr->mingle =
245 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX); 207 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX);
246 pr->bf = GNUNET_CONTAINER_bloomfilter_init (NULL, nsize, BLOOMFILTER_K); 208 pr->bf = GNUNET_BLOCK_construct_bloomfilter (pr->mingle,
247 for (i = 0; i < pr->replies_seen_count; i++) 209 pr->replies_seen,
248 { 210 pr->replies_seen_count);
249 GNUNET_BLOCK_mingle_hash (&pr->replies_seen[i], pr->mingle, &mhash);
250 GNUNET_CONTAINER_bloomfilter_add (pr->bf, &mhash);
251 }
252 return GNUNET_YES;
253} 211}
254 212
255 213
@@ -346,13 +304,13 @@ GSF_pending_request_create_ (enum GSF_PendingRequestOptions options,
346 if (NULL != bf_data) 304 if (NULL != bf_data)
347 { 305 {
348 pr->bf = 306 pr->bf =
349 GNUNET_CONTAINER_bloomfilter_init (bf_data, bf_size, BLOOMFILTER_K); 307 GNUNET_CONTAINER_bloomfilter_init (bf_data, bf_size, GNUNET_CONSTANTS_BLOOMFILTER_K);
350 pr->mingle = mingle; 308 pr->mingle = mingle;
351 } 309 }
352 else if ((replies_seen_count > 0) && 310 else if ((replies_seen_count > 0) &&
353 (0 != (options & GSF_PRO_BLOOMFILTER_FULL_REFRESH))) 311 (0 != (options & GSF_PRO_BLOOMFILTER_FULL_REFRESH)))
354 { 312 {
355 GNUNET_assert (GNUNET_YES == refresh_bloomfilter (pr)); 313 refresh_bloomfilter (pr);
356 } 314 }
357 GNUNET_CONTAINER_multihashmap_put (pr_map, query, pr, 315 GNUNET_CONTAINER_multihashmap_put (pr_map, query, pr,
358 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 316 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
@@ -449,15 +407,7 @@ GSF_pending_request_update_ (struct GSF_PendingRequest *pr,
449 memcpy (&pr->replies_seen[pr->replies_seen_count], replies_seen, 407 memcpy (&pr->replies_seen[pr->replies_seen_count], replies_seen,
450 sizeof (GNUNET_HashCode) * replies_seen_count); 408 sizeof (GNUNET_HashCode) * replies_seen_count);
451 pr->replies_seen_count += replies_seen_count; 409 pr->replies_seen_count += replies_seen_count;
452 if (GNUNET_NO == refresh_bloomfilter (pr)) 410 refresh_bloomfilter (pr);
453 {
454 /* bf not recalculated, simply extend it with new bits */
455 for (i = 0; i < replies_seen_count; i++)
456 {
457 GNUNET_BLOCK_mingle_hash (&replies_seen[i], pr->mingle, &mhash);
458 GNUNET_CONTAINER_bloomfilter_add (pr->bf, &mhash);
459 }
460 }
461 } 411 }
462 else 412 else
463 { 413 {
@@ -468,15 +418,17 @@ GSF_pending_request_update_ (struct GSF_PendingRequest *pr,
468 pr->mingle = 418 pr->mingle =
469 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX); 419 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX);
470 pr->bf = 420 pr->bf =
471 GNUNET_CONTAINER_bloomfilter_init (NULL, 421 GNUNET_BLOCK_construct_bloomfilter (pr->mingle,
472 compute_bloomfilter_size 422 replies_seen,
473 (replies_seen_count), 423 replies_seen_count);
474 BLOOMFILTER_K); 424 }
475 } 425 else
476 for (i = 0; i < pr->replies_seen_count; i++)
477 { 426 {
478 GNUNET_BLOCK_mingle_hash (&replies_seen[i], pr->mingle, &mhash); 427 for (i = 0; i < pr->replies_seen_count; i++)
479 GNUNET_CONTAINER_bloomfilter_add (pr->bf, &mhash); 428 {
429 GNUNET_BLOCK_mingle_hash (&replies_seen[i], pr->mingle, &mhash);
430 GNUNET_CONTAINER_bloomfilter_add (pr->bf, &mhash);
431 }
480 } 432 }
481 } 433 }
482} 434}