aboutsummaryrefslogtreecommitdiff
path: root/src/block/bg_bf.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/block/bg_bf.c')
-rw-r--r--src/block/bg_bf.c34
1 files changed, 26 insertions, 8 deletions
diff --git a/src/block/bg_bf.c b/src/block/bg_bf.c
index 601f605a2..520d750aa 100644
--- a/src/block/bg_bf.c
+++ b/src/block/bg_bf.c
@@ -55,7 +55,6 @@ struct BfGroupInternals
55 * Serialize state of a block group. 55 * Serialize state of a block group.
56 * 56 *
57 * @param bg group to serialize 57 * @param bg group to serialize
58 * @param[out] nonce set to the nonce of the @a bg
59 * @param[out] raw_data set to the serialized state 58 * @param[out] raw_data set to the serialized state
60 * @param[out] raw_data_size set to the number of bytes in @a raw_data 59 * @param[out] raw_data_size set to the number of bytes in @a raw_data
61 * @return #GNUNET_OK on success, #GNUNET_NO if serialization is not 60 * @return #GNUNET_OK on success, #GNUNET_NO if serialization is not
@@ -63,24 +62,25 @@ struct BfGroupInternals
63 */ 62 */
64static enum GNUNET_GenericReturnValue 63static enum GNUNET_GenericReturnValue
65bf_group_serialize_cb (struct GNUNET_BLOCK_Group *bg, 64bf_group_serialize_cb (struct GNUNET_BLOCK_Group *bg,
66 uint32_t *nonce,
67 void **raw_data, 65 void **raw_data,
68 size_t *raw_data_size) 66 size_t *raw_data_size)
69{ 67{
70 struct BfGroupInternals *gi = bg->internal_cls; 68 struct BfGroupInternals *gi = bg->internal_cls;
71 char *raw; 69 void *raw;
72 70
73 raw = GNUNET_malloc (gi->bf_size); 71 raw = GNUNET_malloc (gi->bf_size + sizeof (uint32_t));
74 if (GNUNET_OK != 72 if (GNUNET_OK !=
75 GNUNET_CONTAINER_bloomfilter_get_raw_data (gi->bf, 73 GNUNET_CONTAINER_bloomfilter_get_raw_data (gi->bf,
76 raw, 74 raw + sizeof (uint32_t),
77 gi->bf_size)) 75 gi->bf_size))
78 { 76 {
79 GNUNET_free (raw); 77 GNUNET_free (raw);
80 GNUNET_break (0); 78 GNUNET_break (0);
81 return GNUNET_SYSERR; 79 return GNUNET_SYSERR;
82 } 80 }
83 *nonce = gi->bf_mutator; 81 memcpy (raw,
82 &gi->bf_mutator,
83 sizeof (uint32_t));
84 *raw_data = raw; 84 *raw_data = raw;
85 *raw_data_size = gi->bf_size; 85 *raw_data_size = gi->bf_size;
86 return GNUNET_OK; 86 return GNUNET_OK;
@@ -164,7 +164,6 @@ bf_group_destroy_cb (struct GNUNET_BLOCK_Group *bg)
164 * @param bf_size size of the Bloom filter 164 * @param bf_size size of the Bloom filter
165 * @param bf_k K-value for the Bloom filter 165 * @param bf_k K-value for the Bloom filter
166 * @param type block type 166 * @param type block type
167 * @param nonce random value used to seed the group creation
168 * @param raw_data optional serialized prior state of the group, NULL if unavailable/fresh 167 * @param raw_data optional serialized prior state of the group, NULL if unavailable/fresh
169 * @param raw_data_size number of bytes in @a raw_data, 0 if unavailable/fresh 168 * @param raw_data_size number of bytes in @a raw_data, 0 if unavailable/fresh
170 * @return block group handle, NULL if block groups are not supported 169 * @return block group handle, NULL if block groups are not supported
@@ -175,13 +174,32 @@ GNUNET_BLOCK_GROUP_bf_create (void *cls,
175 size_t bf_size, 174 size_t bf_size,
176 unsigned int bf_k, 175 unsigned int bf_k,
177 enum GNUNET_BLOCK_Type type, 176 enum GNUNET_BLOCK_Type type,
178 uint32_t nonce,
179 const void *raw_data, 177 const void *raw_data,
180 size_t raw_data_size) 178 size_t raw_data_size)
181{ 179{
182 struct BfGroupInternals *gi; 180 struct BfGroupInternals *gi;
183 struct GNUNET_BLOCK_Group *bg; 181 struct GNUNET_BLOCK_Group *bg;
182 uint32_t nonce;
184 183
184 if ( (NULL != raw_data) &&
185 (raw_data_size < sizeof (nonce)) )
186 {
187 GNUNET_break_op (0);
188 return NULL;
189 }
190 if (NULL != raw_data)
191 {
192 memcpy (&nonce,
193 raw_data,
194 sizeof (nonce));
195 raw_data += sizeof (nonce);
196 raw_data_size -= sizeof (nonce);
197 }
198 else
199 {
200 nonce = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE,
201 UINT32_MAX);
202 }
185 gi = GNUNET_new (struct BfGroupInternals); 203 gi = GNUNET_new (struct BfGroupInternals);
186 gi->bf = GNUNET_CONTAINER_bloomfilter_init ((bf_size != raw_data_size) ? 204 gi->bf = GNUNET_CONTAINER_bloomfilter_init ((bf_size != raw_data_size) ?
187 NULL : raw_data, 205 NULL : raw_data,