31#define LOG(kind, ...) GNUNET_log_from (kind, "setu", __VA_ARGS__)
38#define IBF_KEY_HASH_VAL(k) (GNUNET_CRYPTO_crc32_n (&(k), sizeof(struct \
50 return *(
struct IBF_Key *) hash;
71 for (i = 0; i < keys_per_hashcode; i++)
92 if (NULL == ibf->
count)
132 for (i = 0, filled = 0; filled < ibf->
hash_num; i++)
136 for (
unsigned int j = 0; j < filled; j++)
137 if (dst[j] == bucket % ibf->
size)
139 dst[filled++] = bucket % ibf->
size;
141 x = ((uint64_t) bucket << 32) | i;
153 for (
unsigned int i = 0; i < ibf->
hash_num; i++)
155 const int bucket = buckets[i];
207 for (uint32_t i = 0; i < ibf->
size; i++)
228 for (uint32_t i = 0; i < ibf->
size; i++)
247 for (
int j = 0; j < ibf->
hash_num; j++)
264 if (NULL != ret_side)
289 long long max_counter = 0;
290 for (uint64_t i = 0; i < ibf->
size; i++)
297 return 64 - __builtin_clzll (max_counter);
316 uint8_t counter_max_length)
324 key_dst = (
struct IBF_Key *) buf;
327 count *
sizeof(*key_dst));
333 count *
sizeof(*key_hash_dst));
334 key_hash_dst += count;
340 (uint8_t *) key_hash_dst,
352 uint8_t counter_max_length)
354 uint8_t store_size = 0;
356 uint16_t byte_ctr = 0;
364 uint8_t count_len_to_write = counter_max_length;
369 while ((count_len_to_write + store_size) >= 8)
371 uint8_t bit_shift = 0;
377 if ((store_size > 0) || (count_len_to_write > 8))
379 uint8_t bit_unused = 8 - store_size;
380 bit_shift = count_len_to_write - bit_unused;
381 store = store << bit_unused;
384 buf[byte_ctr] = ((count_val_to_write >> bit_shift) | store) & 0xFF;
386 count_len_to_write -= (8 - store_size);
387 count_val_to_write = count_val_to_write & ((1ULL <<
388 count_len_to_write) - 1);
392 store = (store << count_len_to_write) | count_val_to_write;
393 store_size = store_size + count_len_to_write;
394 count_len_to_write = 0;
403 buf[byte_ctr] = store << (8 - store_size);
415 uint8_t counter_max_length)
417 uint64_t ibf_counter_ctr = 0;
419 uint64_t store_bit_ctr = 0;
420 uint64_t byte_ctr = 0;
427 uint8_t byte_read = buf[byte_ctr];
428 uint8_t bit_to_read_left = 8;
439 if (ibf_counter_ctr > (count - 1))
445 if ((store_bit_ctr + bit_to_read_left) >= counter_max_length)
447 uint8_t bytes_used = counter_max_length - store_bit_ctr;
448 if (store_bit_ctr > 0)
450 store = store << bytes_used;
453 uint8_t bytes_to_shift = bit_to_read_left - bytes_used;
454 uint64_t counter_part = byte_read >> bytes_to_shift;
455 store = store | counter_part;
457 byte_read = byte_read & ((1 << bytes_to_shift) - 1);
458 bit_to_read_left -= bytes_used;
466 store_bit_ctr += bit_to_read_left;
473 store = store << bit_to_read_left;
474 store = store | byte_read;
497 uint8_t counter_max_length)
507 key_src = (
struct IBF_Key *) buf;
510 count *
sizeof *key_src);
516 count *
sizeof *key_hash_src);
517 key_hash_src += count;
520 count_src = (
struct IBF_Count *) key_hash_src;
539 for (uint32_t i = 0; i < ibf1->
size; i++)
void ibf_subtract(struct InvertibleBloomFilter *ibf1, const struct InvertibleBloomFilter *ibf2)
Subtract ibf2 from ibf1, storing the result in ibf1.
int ibf_decode(struct InvertibleBloomFilter *ibf, int *ret_side, struct IBF_Key *ret_id)
Decode and remove an element from the IBF, if possible.
void ibf_read_slice(const void *buf, uint32_t start, uint32_t count, struct InvertibleBloomFilter *ibf)
Read buckets from a buffer into an ibf.
struct IBF_Key ibf_key_from_hashcode(const struct GNUNET_HashCode *hash)
Create a key from a hashcode.
void ibf_write_slice(const struct InvertibleBloomFilter *ibf, uint32_t start, uint32_t count, void *buf)
Write buckets from an ibf to a buffer.
void ibf_hashcode_from_key(struct IBF_Key key, struct GNUNET_HashCode *dst)
Create a hashcode from a key, by replicating the key until the hascode is filled.
void ibf_insert(struct InvertibleBloomFilter *ibf, struct IBF_Key key)
Insert a key into an IBF.
struct InvertibleBloomFilter * ibf_dup(const struct InvertibleBloomFilter *ibf)
Create a copy of an IBF, the copy has to be destroyed properly.
struct InvertibleBloomFilter * ibf_create(uint32_t size, uint8_t hash_num)
Create an invertible bloom filter.
void ibf_remove(struct InvertibleBloomFilter *ibf, struct IBF_Key key)
Remove a key from an IBF.
void ibf_destroy(struct InvertibleBloomFilter *ibf)
Destroy all resources associated with the invertible bloom filter.
static int start
Set if we are to start default services (including ARM).
struct GNUNET_HashCode key
The key used in the DHT.
static unsigned int hash_num
static struct GNUNET_OS_Process * p
Helper process we started.
int32_t GNUNET_CRYPTO_crc32_n(const void *buf, size_t len)
Compute the CRC32 checksum for the first len bytes of the buffer.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_malloc_large(size)
Wrapper around malloc.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
#define GNUNET_memdup(buf, size)
Allocate and initialize a block of memory.
static unsigned int size
Size of the "table".
uint8_t ibf_get_max_counter(struct InvertibleBloomFilter *ibf)
Returns the minimal bytes needed to store the counter of the IBF.
void unpack_counter(const struct InvertibleBloomFilter *ibf, uint32_t start, uint64_t count, uint8_t *buf, uint8_t counter_max_length)
Unpacks the counter to transmit only the smallest possible amount of bytes and preventing overflow of...
#define IBF_KEY_HASH_VAL(k)
Compute the key's hash from the key.
static void ibf_get_indices(const struct InvertibleBloomFilter *ibf, struct IBF_Key key, int *dst)
Store unique bucket indices for the specified key in dst.
void pack_counter(const struct InvertibleBloomFilter *ibf, uint32_t start, uint64_t count, uint8_t *buf, uint8_t counter_max_length)
Packs the counter to transmit only the smallest possible amount of bytes and preventing overflow of t...
static void ibf_insert_into(struct InvertibleBloomFilter *ibf, struct IBF_Key key, const int *buckets, int side)
static int ibf_is_empty(struct InvertibleBloomFilter *ibf)
Test is the IBF is empty, i.e.
Type of the count field of IBF buckets.
Keys that can be inserted into and removed from an IBF.
Invertible bloom filter (IBF).
int remote_decoded_count
If an IBF is decoded this count stores how many elements are on the remote site.
int local_decoded_count
If an IBF is decoded this count stores how many elements are on the local site.
struct IBF_KeyHash * key_hash_sum
Xor sums of the hashes of the keys of inserted elements.
uint32_t size
How many cells does this IBF have?
struct IBF_Count * count
How many times has a bucket been hit? Can be negative, as a result of IBF subtraction.
struct IBF_Key * key_sum
Xor sums of the elements' keys, used to identify the elements.
uint8_t hash_num
In how many cells do we hash one element? Usually 4 or 3.