46#define LOG(kind, ...) \
47 GNUNET_log_from (kind, "util-container-bloomfilter", __VA_ARGS__)
49#define LOG_STRERROR(kind, syscall) \
50 GNUNET_log_from_strerror (kind, "util-container-bloomfilter", syscall)
52#define LOG_STRERROR_FILE(kind, syscall, filename) \
53 GNUNET_log_from_strerror_file (kind, \
54 "util-container-bloomfilter", \
129 unsigned int targetBit;
131 arraySlot = bitIdx / 8;
132 targetBit = (1L << (bitIdx % 8));
148 unsigned int targetBit;
151 targetBit = (1L << (bitIdx % 8));
168 unsigned int targetBit;
171 targetBit = (1L << (bitIdx % 8));
196 unsigned int targetLoc;
203 fileSlot = bitIdx / 2;
204 targetLoc = bitIdx % 2;
211 high = (
value & (~0xF)) >> 4;
223 value = ((high << 4) | low);
247 unsigned int targetLoc;
252 fileslot = bitIdx / 2;
253 targetLoc = bitIdx % 2;
263 high = (
value & 0xF0) >> 4;
268 if ((low > 0) && (low < 0xF))
277 if ((high > 0) && (high < 0xF))
284 value = ((high << 4) | low);
295#define BUFFSIZE 65536
309 size_t bytesleft =
size;
314 memset (buffer, 0,
sizeof(buffer));
316 while (bytesleft > 0)
318 if (bytesleft >
sizeof(buffer))
372 unsigned int slot = 0;
379 while ( (0 != bitCount) &&
385 ntohl ((((uint32_t *) &tmp)[slot]))
485 if ((k == 0) || (
size == 0))
490 while ((ui <
size) && (ui * 2 > ui))
527 else if (fsize != ((off_t)
size) * 4LL)
532 "Size of file on disk is incorrect for this Bloom filter (want %llu, have %llu)\n"),
533 (
unsigned long long) (
size * 4LL),
534 (
unsigned long long) fsize);
580 while (pos < ((off_t)
size) * 8LL)
596 for (i = 0; i <
res; i++)
598 if ((rbuff[i] & 0x0F) != 0)
600 if ((rbuff[i] & 0xF0) != 0)
619 if ((0 == k) || (0 ==
size))
716 unsigned long long *fc;
717 const unsigned long long *
dc;
723 fc = (
unsigned long long *) bf->
bitArray;
724 dc = (
const unsigned long long *)
data;
725 n =
size /
sizeof(
unsigned long long);
727 for (i = 0; i < n; i++)
729 for (i = n *
sizeof(
unsigned long long); i <
size; i++)
742 unsigned long long *fc;
743 const unsigned long long *
dc;
754 fc = (
unsigned long long *) bf->
bitArray;
755 dc = (
const unsigned long long *) to_or->
bitArray;
756 n =
size /
sizeof(
unsigned long long);
758 for (i = 0; i < n; i++)
760 for (i = n *
sizeof(
unsigned long long); i <
size; i++)
801 while (
GNUNET_YES == iterator (iterator_cls, &hc))
static enum GNUNET_GenericReturnValue make_empty_file(const struct GNUNET_DISK_FileHandle *fh, size_t size)
Creates a file filled with zeroes.
static enum GNUNET_GenericReturnValue testBitCallback(void *cls, const struct GNUNET_CONTAINER_BloomFilter *bf, unsigned int bit)
Callback: test if all bits are set.
static void incrementBit(char *bitArray, unsigned int bitIdx, const struct GNUNET_DISK_FileHandle *fh)
Sets a bit active in the bitArray and increments bit-specific usage counter on disk (but only if the ...
static void decrementBit(char *bitArray, unsigned int bitIdx, const struct GNUNET_DISK_FileHandle *fh)
Clears a bit from bitArray if the respective usage counter on the disk hits/is zero.
static enum GNUNET_GenericReturnValue incrementBitCallback(void *cls, const struct GNUNET_CONTAINER_BloomFilter *bf, unsigned int bit)
Callback: increment bit.
static void clearBit(char *bitArray, unsigned int bitIdx)
Clears a bit from bitArray.
#define LOG_STRERROR_FILE(kind, syscall, filename)
static void setBit(char *bitArray, unsigned int bitIdx)
Sets a bit active in the bitArray.
enum GNUNET_GenericReturnValue(* BitIterator)(void *cls, const struct GNUNET_CONTAINER_BloomFilter *bf, unsigned int bit)
Iterator (callback) method to be called by the bloomfilter iterator on each bit that is to be set or ...
static void iterateBits(const struct GNUNET_CONTAINER_BloomFilter *bf, BitIterator callback, void *arg, const struct GNUNET_HashCode *key)
Call an iterator for each bit that the bloomfilter must test or set for this element.
static bool testBit(char *bitArray, unsigned int bitIdx)
Checks if a bit is active in the bitArray.
static enum GNUNET_GenericReturnValue decrementBitCallback(void *cls, const struct GNUNET_CONTAINER_BloomFilter *bf, unsigned int bit)
Callback: decrement bit.
static char * data
The data to insert into the dht.
struct GNUNET_HashCode key
The key used in the DHT.
static struct GNUNET_FS_DownloadContext * dc
static char * res
Currently read line or NULL on EOF.
static char * value
Value of the record to add/remove.
void GNUNET_CONTAINER_bloomfilter_resize(struct GNUNET_CONTAINER_BloomFilter *bf, GNUNET_CONTAINER_HashCodeIterator iterator, void *iterator_cls, size_t size, unsigned int k)
Resize a bloom filter.
struct GNUNET_CONTAINER_BloomFilter * GNUNET_CONTAINER_bloomfilter_init(const char *data, size_t size, unsigned int k)
Create a Bloom filter from raw bits.
void GNUNET_CONTAINER_bloomfilter_add(struct GNUNET_CONTAINER_BloomFilter *bf, const struct GNUNET_HashCode *e)
Add an element to the filter.
bool GNUNET_CONTAINER_bloomfilter_test(const struct GNUNET_CONTAINER_BloomFilter *bf, const struct GNUNET_HashCode *e)
Test if an element is in the filter.
struct GNUNET_CONTAINER_BloomFilter * GNUNET_CONTAINER_bloomfilter_copy(const struct GNUNET_CONTAINER_BloomFilter *bf)
Create a copy of a bloomfilter.
void GNUNET_CONTAINER_bloomfilter_clear(struct GNUNET_CONTAINER_BloomFilter *bf)
Reset a Bloom filter to empty.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_bloomfilter_get_raw_data(const struct GNUNET_CONTAINER_BloomFilter *bf, char *data, size_t size)
Copy the raw data of this Bloom filter into the given data array.
int(* GNUNET_CONTAINER_HashCodeIterator)(void *cls, struct GNUNET_HashCode *next)
Iterator over struct GNUNET_HashCode.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_bloomfilter_or2(struct GNUNET_CONTAINER_BloomFilter *bf, const struct GNUNET_CONTAINER_BloomFilter *to_or)
"or" the entries of the given raw data array with the data of the given Bloom filter.
struct GNUNET_CONTAINER_BloomFilter * GNUNET_CONTAINER_bloomfilter_load(const char *filename, size_t size, unsigned int k)
Load a Bloom filter from a file.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_bloomfilter_or(struct GNUNET_CONTAINER_BloomFilter *bf, const char *data, size_t size)
"or" the entries of the given raw data array with the data of the given Bloom filter.
size_t GNUNET_CONTAINER_bloomfilter_get_size(const struct GNUNET_CONTAINER_BloomFilter *bf)
Get size of the bloom filter.
void GNUNET_CONTAINER_bloomfilter_remove(struct GNUNET_CONTAINER_BloomFilter *bf, const struct GNUNET_HashCode *e)
Remove an element from the filter.
void GNUNET_CONTAINER_bloomfilter_free(struct GNUNET_CONTAINER_BloomFilter *bf)
Free the space associated with a filter in memory, flush to drive if needed (do not free the space on...
struct GNUNET_DISK_FileHandle * GNUNET_DISK_file_open(const char *fn, enum GNUNET_DISK_OpenFlags flags, enum GNUNET_DISK_AccessPermissions perm)
Open a file.
enum GNUNET_GenericReturnValue GNUNET_DISK_file_test(const char *fil)
Check that fil corresponds to a filename (of a file that exists and that is not a directory).
ssize_t GNUNET_DISK_file_write(const struct GNUNET_DISK_FileHandle *h, const void *buffer, size_t n)
Write a buffer to a file.
off_t GNUNET_DISK_file_seek(const struct GNUNET_DISK_FileHandle *h, off_t offset, enum GNUNET_DISK_Seek whence)
Move the read/write pointer in a file.
enum GNUNET_GenericReturnValue GNUNET_DISK_handle_invalid(const struct GNUNET_DISK_FileHandle *h)
Checks whether a handle is invalid.
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
ssize_t GNUNET_DISK_file_read(const struct GNUNET_DISK_FileHandle *h, void *result, size_t len)
Read the contents of a binary file into a buffer.
enum GNUNET_GenericReturnValue GNUNET_DISK_file_handle_size(struct GNUNET_DISK_FileHandle *fh, off_t *size)
Get the size of an open file.
@ GNUNET_DISK_OPEN_CREATE
Create file if it doesn't exist.
@ GNUNET_DISK_OPEN_READWRITE
Open the file for both reading and writing.
@ GNUNET_DISK_PERM_USER_READ
Owner can read.
@ GNUNET_DISK_PERM_USER_WRITE
Owner can write.
@ GNUNET_DISK_SEEK_SET
Seek an absolute position (from the start of the file).
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
#define GNUNET_log(kind,...)
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
size_t GNUNET_CONTAINER_bloomfilter_get_element_addresses(const struct GNUNET_CONTAINER_BloomFilter *bf)
Get the number of the addresses set per element in the bloom filter.
GNUNET_GenericReturnValue
Named constants for return values.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
#define GNUNET_log_strerror(level, cmd)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_ERROR
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#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.
static unsigned int size
Size of the "table".
size_t bitArraySize
Size of bitArray in bytes.
unsigned int addressesPerElement
How many bits we set for each stored element.
struct GNUNET_DISK_FileHandle * fh
The bit counter file on disk.
char * bitArray
The actual bloomfilter bit array.
char * filename
Filename of the filter.
Handle used to access files (and pipes).