/*
This file is part of GNUnet.
- Copyright (C) 2001, 2002, 2003, 2004, 2006, 2008, 2011, 2012 Christian Grothoff (and other contributing authors)
+ Copyright (C) 2001, 2002, 2003, 2004, 2006, 2008, 2011, 2012, 2018 GNUnet e.V.
- GNUnet is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published
- by the Free Software Foundation; either version 3, or (at your
- option) any later version.
+ GNUnet is free software: you can redistribute it and/or modify it
+ under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License,
+ or (at your option) any later version.
GNUnet is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
+ Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
- You should have received a copy of the GNU General Public License
- along with GNUnet; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
+ SPDX-License-Identifier: AGPL3.0-or-later
*/
/**
* @file util/container_bloomfilter.c
#include "platform.h"
#include "gnunet_util_lib.h"
-#define LOG(kind,...) GNUNET_log_from (kind, "util", __VA_ARGS__)
+#define LOG(kind,...) GNUNET_log_from (kind, "util-container-bloomfilter", __VA_ARGS__)
-#define LOG_STRERROR(kind,syscall) GNUNET_log_from_strerror (kind, "util", syscall)
+#define LOG_STRERROR(kind,syscall) GNUNET_log_from_strerror (kind, "util-container-bloomfilter", syscall)
-#define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file (kind, "util", syscall, filename)
+#define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file (kind, "util-container-bloomfilter", syscall, filename)
struct GNUNET_CONTAINER_BloomFilter
{
GNUNET_free (bf);
return NULL;
}
- if (fsize == 0)
+ if (0 == fsize)
{
/* found existing empty file, just overwrite */
- if (GNUNET_OK != make_empty_file (bf->fh, size * 4LL))
+ if (GNUNET_OK !=
+ make_empty_file (bf->fh, size * 4LL))
{
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
"write");
return NULL;
}
}
- else if (fsize != size * 4LL)
+ else if (fsize != ((off_t) size) * 4LL)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_("Size of file on disk is incorrect for this Bloom filter (want %llu, have %llu)\n"),
bf->filename = GNUNET_strdup (filename);
/* Alloc block */
bf->bitArray = GNUNET_malloc_large (size);
- if (bf->bitArray == NULL)
+ if (NULL == bf->bitArray)
{
- if (bf->fh != NULL)
+ if (NULL != bf->fh)
GNUNET_DISK_file_close (bf->fh);
GNUNET_free (bf->filename);
GNUNET_free (bf);
/* Read from the file what bits we can */
rbuff = GNUNET_malloc (BUFFSIZE);
pos = 0;
- while (pos < size * 8LL)
+ while (pos < ((off_t) size) * 8LL)
{
int res;
- res = GNUNET_DISK_file_read (bf->fh, rbuff, BUFFSIZE);
+ res = GNUNET_DISK_file_read (bf->fh,
+ rbuff,
+ BUFFSIZE);
if (res == -1)
{
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "read", bf->filename);
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING,
+ "read",
+ bf->filename);
GNUNET_free (rbuff);
GNUNET_free (bf->filename);
GNUNET_DISK_file_close (bf->fh);
bf->bitArraySize = size;
bf->addressesPerElement = k;
if (NULL != data)
- memcpy (bf->bitArray, data, size);
+ GNUNET_memcpy (bf->bitArray, data, size);
return bf;
}
* @param bf bloomfilter to take the raw data from
* @param data where to write the data
* @param size the size of the given data array
- * @return GNUNET_SYSERR if the data array is not big enough
+ * @return #GNUNET_SYSERR if the data array is not big enough
*/
int
GNUNET_CONTAINER_bloomfilter_get_raw_data (const struct
return GNUNET_SYSERR;
if (bf->bitArraySize != size)
return GNUNET_SYSERR;
- memcpy (data, bf->bitArray, size);
+ GNUNET_memcpy (data, bf->bitArray, size);
return GNUNET_OK;
}
*
* @param e the element
* @param bf the filter
- * @return GNUNET_YES if the element is in the filter, GNUNET_NO if not
+ * @return #GNUNET_YES if the element is in the filter, #GNUNET_NO if not
*/
int
-GNUNET_CONTAINER_bloomfilter_test (const struct GNUNET_CONTAINER_BloomFilter
- *bf, const struct GNUNET_HashCode * e)
+GNUNET_CONTAINER_bloomfilter_test (const struct GNUNET_CONTAINER_BloomFilter *bf,
+ const struct GNUNET_HashCode * e)
{
int res;
*/
int
GNUNET_CONTAINER_bloomfilter_or (struct GNUNET_CONTAINER_BloomFilter *bf,
- const char *data, size_t size)
+ const char *data,
+ size_t size)
{
unsigned int i;
unsigned int n;
*/
int
GNUNET_CONTAINER_bloomfilter_or2 (struct GNUNET_CONTAINER_BloomFilter *bf,
- const struct GNUNET_CONTAINER_BloomFilter
- *to_or)
+ const struct GNUNET_CONTAINER_BloomFilter *to_or)
{
unsigned int i;
unsigned int n;
*/
void
GNUNET_CONTAINER_bloomfilter_remove (struct GNUNET_CONTAINER_BloomFilter *bf,
- const struct GNUNET_HashCode * e)
+ const struct GNUNET_HashCode *e)
{
if (NULL == bf)
return;
- if (bf->filename == NULL)
+ if (NULL == bf->filename)
return;
- iterateBits (bf, &decrementBitCallback, bf, e);
+ iterateBits (bf,
+ &decrementBitCallback,
+ bf,
+ e);
}
/**
void
GNUNET_CONTAINER_bloomfilter_resize (struct GNUNET_CONTAINER_BloomFilter *bf,
GNUNET_CONTAINER_HashCodeIterator iterator,
- void *iterator_cls, size_t size,
+ void *iterator_cls,
+ size_t size,
unsigned int k)
{
struct GNUNET_HashCode hc;
while (i < size)
i *= 2;
size = i; /* make sure it's a power of 2 */
-
+ bf->addressesPerElement = k;
bf->bitArraySize = size;
bf->bitArray = GNUNET_malloc (size);
- if (bf->filename != NULL)
- make_empty_file (bf->fh, bf->bitArraySize * 4LL);
- while (GNUNET_YES == iterator (iterator_cls, &hc))
- GNUNET_CONTAINER_bloomfilter_add (bf, &hc);
+ if (NULL != bf->filename)
+ make_empty_file (bf->fh,
+ bf->bitArraySize * 4LL);
+ while (GNUNET_YES == iterator (iterator_cls,
+ &hc))
+ GNUNET_CONTAINER_bloomfilter_add (bf,
+ &hc);
}
/* end of container_bloomfilter.c */