gnunet_block_group_lib.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. This file is part of GNUnet.
  3. Copyright (C) 2010 GNUnet e.V.
  4. GNUnet is free software: you can redistribute it and/or modify it
  5. under the terms of the GNU Affero General Public License as published
  6. by the Free Software Foundation, either version 3 of the License,
  7. or (at your option) any later version.
  8. GNUnet is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Affero General Public License for more details.
  12. You should have received a copy of the GNU Affero General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. SPDX-License-Identifier: AGPL3.0-or-later
  15. */
  16. /**
  17. * @author Christian Grothoff
  18. *
  19. * @file
  20. * Library for creating block groups (to be used by block plugins)
  21. *
  22. * @defgroup block Block group library
  23. * Library for data group management
  24. * @{
  25. */
  26. #ifndef GNUNET_BLOCK_GROUP_LIB_H
  27. #define GNUNET_BLOCK_GROUP_LIB_H
  28. #include "gnunet_util_lib.h"
  29. #include "gnunet_block_lib.h"
  30. #ifdef __cplusplus
  31. extern "C"
  32. {
  33. #if 0 /* keep Emacsens' auto-indent happy */
  34. }
  35. #endif
  36. #endif
  37. /**
  38. * How many bytes should a bloomfilter be if we have already seen
  39. * entry_count responses? Sized so that do not have to
  40. * re-size the filter too often (to keep it cheap).
  41. *
  42. * Since other peers will also add entries but not resize the filter,
  43. * we should generally pick a slightly larger size than what the
  44. * strict math would suggest.
  45. *
  46. * @param entry_count expected number of entries in the Bloom filter
  47. * @param k number of bits set per entry
  48. * @return must be a power of two and smaller or equal to 2^15.
  49. */
  50. size_t
  51. GNUNET_BLOCK_GROUP_compute_bloomfilter_size (unsigned int entry_count,
  52. unsigned int k);
  53. /**
  54. * Create a new block group that filters duplicates using a Bloom filter.
  55. *
  56. * @param ctx block context in which the block group is created
  57. * @param bf_size size of the Bloom filter
  58. * @param bf_k K-value for the Bloom filter
  59. * @param type block type
  60. * @param nonce random value used to seed the group creation
  61. * @param raw_data optional serialized prior state of the group, NULL if unavailable/fresh
  62. * @param raw_data_size number of bytes in @a raw_data, 0 if unavailable/fresh
  63. * @return block group handle, NULL if block groups are not supported
  64. * by this @a type of block (this is not an error)
  65. */
  66. struct GNUNET_BLOCK_Group *
  67. GNUNET_BLOCK_GROUP_bf_create (void *cls,
  68. size_t bf_size,
  69. unsigned int bf_k,
  70. enum GNUNET_BLOCK_Type type,
  71. uint32_t nonce,
  72. const void *raw_data,
  73. size_t raw_data_size);
  74. /**
  75. * Test if @a hc is contained in the Bloom filter of @a bg. If so,
  76. * return #GNUNET_YES. If not, add @a hc to the Bloom filter and
  77. * return #GNUNET_NO.
  78. *
  79. * @param bg block group to use for testing
  80. * @param hc hash of element to evaluate
  81. * @return #GNUNET_YES if @a hc is (likely) a duplicate
  82. * #GNUNET_NO if @a hc was definitively not in @bg (but now is)
  83. */
  84. int
  85. GNUNET_BLOCK_GROUP_bf_test_and_set (struct GNUNET_BLOCK_Group *bg,
  86. const struct GNUNET_HashCode *hc);
  87. #if 0 /* keep Emacsens' auto-indent happy */
  88. {
  89. #endif
  90. #ifdef __cplusplus
  91. }
  92. #endif
  93. /* ifndef GNUNET_BLOCK_GROUP_LIB_H */
  94. #endif
  95. /** @} */ /* end of group */
  96. /* end of gnunet_block_group_lib.h */