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)
327 count *
sizeof(*key_dst));
333 count *
sizeof(*key_hash_dst));
334 key_hash_dst += count;
340 (uint8_t *) key_hash_dst,
353 uint8_t counter_max_length)
355 uint8_t store_size = 0;
357 uint16_t byte_ctr = 0;
365 uint8_t count_len_to_write = counter_max_length;
370 while ((count_len_to_write + store_size) >= 8)
372 uint8_t bit_shift = 0;
378 if ((store_size > 0) || (count_len_to_write > 8))
380 uint8_t bit_unused = 8 - store_size;
381 bit_shift = count_len_to_write - bit_unused;
382 store = store << bit_unused;
385 buf[byte_ctr] = ((count_val_to_write >> bit_shift) | store) & 0xFF;
387 count_len_to_write -= (8 - store_size);
388 count_val_to_write = count_val_to_write & ((1ULL <<
389 count_len_to_write) - 1);
393 store = (store << count_len_to_write) | count_val_to_write;
394 store_size = store_size + count_len_to_write;
395 count_len_to_write = 0;
404 buf[byte_ctr] = store << (8 - store_size);
417 uint8_t counter_max_length)
419 uint64_t ibf_counter_ctr = 0;
421 uint64_t store_bit_ctr = 0;
422 uint64_t byte_ctr = 0;
429 uint8_t byte_read =
buf[byte_ctr];
430 uint8_t bit_to_read_left = 8;
441 if (ibf_counter_ctr > (count - 1))
447 if ((store_bit_ctr + bit_to_read_left) >= counter_max_length)
449 uint8_t bytes_used = counter_max_length - store_bit_ctr;
450 if (store_bit_ctr > 0)
452 store = store << bytes_used;
455 uint8_t bytes_to_shift = bit_to_read_left - bytes_used;
456 uint64_t counter_part = byte_read >> bytes_to_shift;
457 store = store | counter_part;
459 byte_read = byte_read & ((1 << bytes_to_shift) - 1);
460 bit_to_read_left -= bytes_used;
467 store_bit_ctr += bit_to_read_left;
474 store = store << bit_to_read_left;
475 store = store | byte_read;
498 uint8_t counter_max_length)
511 count *
sizeof *key_src);
517 count *
sizeof *key_hash_src);
518 key_hash_src += count;
521 count_src = (
struct IBF_Count *) key_hash_src;
540 for (uint32_t i = 0; i < ibf1->
size; i++)
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".
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.
struct InvertibleBloomFilter * ibf_create(uint32_t size, uint8_t hash_num)
Create an invertible bloom filter.
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.
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.
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.