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