src/cadet/cadet_common.c
src/cadet/cadet_path.c
src/cadet/cadet_test_lib.c
+src/cadet/cadet_test_lib_new.c
src/cadet/desirability_table.c
src/cadet/gnunet-cadet.c
src/cadet/gnunet-cadet-profiler.c
#define TEMPLATE_BF_SIZE 8
+/**
+ * How many bytes should a bloomfilter be if we have already seen
+ * entry_count responses? Note that #GNUNET_CONSTANTS_BLOOMFILTER_K
+ * gives us the number of bits set per entry. Furthermore, we should
+ * not re-size the filter too often (to keep it cheap).
+ *
+ * Since other peers will also add entries but not resize the filter,
+ * we should generally pick a slightly larger size than what the
+ * strict math would suggest.
+ *
+ * @param entry_count expected number of entries in the Bloom filter
+ * @return must be a power of two and smaller or equal to 2^15.
+ */
+static size_t
+compute_bloomfilter_size (unsigned int entry_count)
+{
+ size_t size;
+ unsigned int ideal = (entry_count * BLOOMFILTER_K) / 4;
+ uint16_t max = 1 << 15;
+
+ if (entry_count > max)
+ return max;
+ size = 8;
+ while ((size < max) && (size < ideal))
+ size *= 2;
+ if (size > max)
+ return max;
+ return size;
+}
+
+
/**
* Create a new block group.
*
size_t raw_data_size,
va_list va)
{
+ unsigned int bf_size;
+ const char *guard;
+
+ guard = va_arg (va, const char *);
+ if (0 == memcmp (guard,
+ "seen-set-size",
+ strlen ("seen-set-size")))
+ bf_size = compute_bloomfilter_size (va_arg (va, unsigned int));
+ else if (0 == memcmp (guard,
+ "filter-size",
+ strlen ("filter-size")))
+ bf_size = va_arg (va, unsigned int);
+ else
+ {
+ GNUNET_break (0);
+ bf_size = TEMPLATE_BF_SIZE;
+ }
+ GNUNET_break (NULL == va_arg (va, const char *));
return GNUNET_BLOCK_GROUP_bf_create (cls,
TEMPLATE_BF_SIZE,
BLOOMFILTER_K,
#define TEST_BF_SIZE 8
+/**
+ * How many bytes should a bloomfilter be if we have already seen
+ * entry_count responses? Note that #GNUNET_CONSTANTS_BLOOMFILTER_K
+ * gives us the number of bits set per entry. Furthermore, we should
+ * not re-size the filter too often (to keep it cheap).
+ *
+ * Since other peers will also add entries but not resize the filter,
+ * we should generally pick a slightly larger size than what the
+ * strict math would suggest.
+ *
+ * @param entry_count expected number of entries in the Bloom filter
+ * @return must be a power of two and smaller or equal to 2^15.
+ */
+static size_t
+compute_bloomfilter_size (unsigned int entry_count)
+{
+ size_t size;
+ unsigned int ideal = (entry_count * BLOOMFILTER_K) / 4;
+ uint16_t max = 1 << 15;
+
+ if (entry_count > max)
+ return max;
+ size = 8;
+ while ((size < max) && (size < ideal))
+ size *= 2;
+ if (size > max)
+ return max;
+ return size;
+}
+
+
/**
* Create a new block group.
*
size_t raw_data_size,
va_list va)
{
+ unsigned int bf_size;
+ const char *guard;
+
+ guard = va_arg (va, const char *);
+ if (0 == memcmp (guard,
+ "seen-set-size",
+ strlen ("seen-set-size")))
+ bf_size = compute_bloomfilter_size (va_arg (va, unsigned int));
+ else if (0 == memcmp (guard,
+ "filter-size",
+ strlen ("filter-size")))
+ bf_size = va_arg (va, unsigned int);
+ else
+ {
+ GNUNET_break (0);
+ bf_size = TEST_BF_SIZE;
+ }
+ GNUNET_break (NULL == va_arg (va, const char *));
return GNUNET_BLOCK_GROUP_bf_create (cls,
- TEST_BF_SIZE,
+ bf_size,
BLOOMFILTER_K,
type,
nonce,
NULL,
0,
"seen-set-size",
- cqr->seen_replies_count);
+ cqr->seen_replies_count,
+ NULL);
GNUNET_BLOCK_group_set_seen (bg,
cqr->seen_replies,
cqr->seen_replies_count);
NULL,
0,
"filter-size",
- DHT_BLOOM_SIZE);
+ DHT_BLOOM_SIZE,
+ NULL);
GNUNET_CONTAINER_multipeermap_iterate (all_connected_peers,
&add_known_to_bloom,
bg);
&xquery[xquery_size],
reply_bf_size,
"filter-size",
- reply_bf_size);
+ reply_bf_size,
+ NULL);
/* remember request for routing replies */
GDS_ROUTING_add (peer->id,
type,
GNUNET_break (0);
bf_size = 8;
}
+ GNUNET_break (NULL == va_arg (va, const char *));
return GNUNET_BLOCK_GROUP_bf_create (cls,
bf_size,
BLOOMFILTER_K,
UINT32_MAX),
NULL,
0,
- "fs-seen-set-size",
- pr->replies_seen_count);
+ "seen-set-size",
+ pr->replies_seen_count,
+ NULL);
if (NULL == pr->bg)
return;
GNUNET_break (GNUNET_OK ==
mingle,
bf_data,
bf_size,
- "fs-seen-set-size",
- 0);
+ "seen-set-size",
+ 0,
+ NULL);
}
else if ((replies_seen_count > 0) &&
(0 != (options & GSF_PRO_BLOOMFILTER_FULL_REFRESH)))
switch (type)
{
case GNUNET_BLOCK_TYPE_FS_DBLOCK:
+ GNUNET_break (NULL == va_arg (va, const char *));
return NULL;
case GNUNET_BLOCK_TYPE_FS_IBLOCK:
+ GNUNET_break (NULL == va_arg (va, const char *));
return NULL;
case GNUNET_BLOCK_TYPE_FS_UBLOCK:
guard = va_arg (va, const char *);
if (0 != memcmp (guard,
- "fs-seen-set-size",
- strlen ("fs-seen-set-size")))
+ "seen-set-size",
+ strlen ("seen-set-size")))
{
/* va-args invalid! bad bug, complain! */
GNUNET_break (0);
}
if (0 == size)
size = raw_data_size; /* not for us to determine, use what we got! */
+ GNUNET_break (NULL == va_arg (va, const char *));
return GNUNET_BLOCK_GROUP_bf_create (cls,
size,
BLOOMFILTER_K,
raw_data,
raw_data_size);
default:
+ GNUNET_break (NULL == va_arg (va, const char *));
GNUNET_break (0);
return NULL;
}
#define GNS_BF_SIZE 8
+/**
+ * How many bytes should a bloomfilter be if we have already seen
+ * entry_count responses? Note that #GNUNET_CONSTANTS_BLOOMFILTER_K
+ * gives us the number of bits set per entry. Furthermore, we should
+ * not re-size the filter too often (to keep it cheap).
+ *
+ * Since other peers will also add entries but not resize the filter,
+ * we should generally pick a slightly larger size than what the
+ * strict math would suggest.
+ *
+ * @param entry_count expected number of entries in the Bloom filter
+ * @return must be a power of two and smaller or equal to 2^15.
+ */
+static size_t
+compute_bloomfilter_size (unsigned int entry_count)
+{
+ size_t size;
+ unsigned int ideal = (entry_count * BLOOMFILTER_K) / 4;
+ uint16_t max = 1 << 15;
+
+ if (entry_count > max)
+ return max;
+ size = 8;
+ while ((size < max) && (size < ideal))
+ size *= 2;
+ if (size > max)
+ return max;
+ return size;
+}
+
+
/**
* Create a new block group.
*
size_t raw_data_size,
va_list va)
{
+ unsigned int bf_size;
+ const char *guard;
+
+ guard = va_arg (va, const char *);
+ if (0 == memcmp (guard,
+ "seen-set-size",
+ strlen ("seen-set-size")))
+ bf_size = compute_bloomfilter_size (va_arg (va, unsigned int));
+ else if (0 == memcmp (guard,
+ "filter-size",
+ strlen ("filter-size")))
+ bf_size = va_arg (va, unsigned int);
+ else
+ {
+ GNUNET_break (0);
+ bf_size = GNS_BF_SIZE;
+ }
+ GNUNET_break (NULL == va_arg (va, const char *));
return GNUNET_BLOCK_GROUP_bf_create (cls,
- GNS_BF_SIZE,
+ bf_size,
BLOOMFILTER_K,
type,
nonce,
#include "gnunet_block_group_lib.h"
#include "block_regex.h"
#include "regex_block_lib.h"
-#include "gnunet_constants.h"
#include "gnunet_signatures.h"
+
+/**
+ * Number of bits we set per entry in the bloomfilter.
+ * Do not change!
+ */
+#define BLOOMFILTER_K 16
+
+
/**
* How big is the BF we use for REGEX blocks?
*/
#define REGEX_BF_SIZE 8
+/**
+ * How many bytes should a bloomfilter be if we have already seen
+ * entry_count responses? Note that #GNUNET_CONSTANTS_BLOOMFILTER_K
+ * gives us the number of bits set per entry. Furthermore, we should
+ * not re-size the filter too often (to keep it cheap).
+ *
+ * Since other peers will also add entries but not resize the filter,
+ * we should generally pick a slightly larger size than what the
+ * strict math would suggest.
+ *
+ * @param entry_count expected number of entries in the Bloom filter
+ * @return must be a power of two and smaller or equal to 2^15.
+ */
+static size_t
+compute_bloomfilter_size (unsigned int entry_count)
+{
+ size_t size;
+ unsigned int ideal = (entry_count * BLOOMFILTER_K) / 4;
+ uint16_t max = 1 << 15;
+
+ if (entry_count > max)
+ return max;
+ size = 8;
+ while ((size < max) && (size < ideal))
+ size *= 2;
+ if (size > max)
+ return max;
+ return size;
+}
+
+
/**
* Create a new block group.
*
size_t raw_data_size,
va_list va)
{
+ unsigned int bf_size;
+ const char *guard;
+
+ guard = va_arg (va, const char *);
+ if (0 == memcmp (guard,
+ "seen-set-size",
+ strlen ("seen-set-size")))
+ bf_size = compute_bloomfilter_size (va_arg (va, unsigned int));
+ else if (0 == memcmp (guard,
+ "filter-size",
+ strlen ("filter-size")))
+ bf_size = va_arg (va, unsigned int);
+ else
+ {
+ GNUNET_break (0);
+ bf_size = REGEX_BF_SIZE;
+ }
+ GNUNET_break (NULL == va_arg (va, const char *));
return GNUNET_BLOCK_GROUP_bf_create (cls,
- REGEX_BF_SIZE,
- GNUNET_CONSTANTS_BLOOMFILTER_K,
+ bf_size,
+ BLOOMFILTER_K,
type,
nonce,
raw_data,