aboutsummaryrefslogtreecommitdiff
path: root/src/block
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2022-05-31 23:43:05 +0200
committerChristian Grothoff <christian@grothoff.org>2022-05-31 23:43:05 +0200
commitedddc9384e9bc4331d57291de7318bbe401e49b0 (patch)
treebe9387df3a4fa4e8cb71590501fb3740920c5bb6 /src/block
parent02a2c3560aa08c3c7f389706b0e24007e2010bc5 (diff)
downloadgnunet-edddc9384e9bc4331d57291de7318bbe401e49b0.tar.gz
gnunet-edddc9384e9bc4331d57291de7318bbe401e49b0.zip
protocol change: swap xquery and result filter, integrate mutator with result filter
Diffstat (limited to 'src/block')
-rw-r--r--src/block/bg_bf.c34
-rw-r--r--src/block/block.c6
-rw-r--r--src/block/plugin_block_template.c25
-rw-r--r--src/block/plugin_block_test.c3
4 files changed, 38 insertions, 30 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,
diff --git a/src/block/block.c b/src/block/block.c
index 98095b51c..4b2d8a960 100644
--- a/src/block/block.c
+++ b/src/block/block.c
@@ -91,6 +91,7 @@ struct MinglePacker
91 91
92GNUNET_NETWORK_STRUCT_END 92GNUNET_NETWORK_STRUCT_END
93 93
94
94void 95void
95GNUNET_BLOCK_mingle_hash (const struct GNUNET_HashCode *in, 96GNUNET_BLOCK_mingle_hash (const struct GNUNET_HashCode *in,
96 uint32_t mingle_number, 97 uint32_t mingle_number,
@@ -172,11 +173,9 @@ GNUNET_BLOCK_context_destroy (struct GNUNET_BLOCK_Context *ctx)
172 173
173enum GNUNET_GenericReturnValue 174enum GNUNET_GenericReturnValue
174GNUNET_BLOCK_group_serialize (struct GNUNET_BLOCK_Group *bg, 175GNUNET_BLOCK_group_serialize (struct GNUNET_BLOCK_Group *bg,
175 uint32_t *nonce,
176 void **raw_data, 176 void **raw_data,
177 size_t *raw_data_size) 177 size_t *raw_data_size)
178{ 178{
179 *nonce = 0;
180 *raw_data = NULL; 179 *raw_data = NULL;
181 *raw_data_size = 0; 180 *raw_data_size = 0;
182 if (NULL == bg) 181 if (NULL == bg)
@@ -184,7 +183,6 @@ GNUNET_BLOCK_group_serialize (struct GNUNET_BLOCK_Group *bg,
184 if (NULL == bg->serialize_cb) 183 if (NULL == bg->serialize_cb)
185 return GNUNET_NO; 184 return GNUNET_NO;
186 return bg->serialize_cb (bg, 185 return bg->serialize_cb (bg,
187 nonce,
188 raw_data, 186 raw_data,
189 raw_data_size); 187 raw_data_size);
190} 188}
@@ -248,7 +246,6 @@ find_plugin (struct GNUNET_BLOCK_Context *ctx,
248struct GNUNET_BLOCK_Group * 246struct GNUNET_BLOCK_Group *
249GNUNET_BLOCK_group_create (struct GNUNET_BLOCK_Context *ctx, 247GNUNET_BLOCK_group_create (struct GNUNET_BLOCK_Context *ctx,
250 enum GNUNET_BLOCK_Type type, 248 enum GNUNET_BLOCK_Type type,
251 uint32_t nonce,
252 const void *raw_data, 249 const void *raw_data,
253 size_t raw_data_size, 250 size_t raw_data_size,
254 ...) 251 ...)
@@ -267,7 +264,6 @@ GNUNET_BLOCK_group_create (struct GNUNET_BLOCK_Context *ctx,
267 raw_data_size); 264 raw_data_size);
268 bg = plugin->create_group (plugin->cls, 265 bg = plugin->create_group (plugin->cls,
269 type, 266 type,
270 nonce,
271 raw_data, 267 raw_data,
272 raw_data_size, 268 raw_data_size,
273 ap); 269 ap);
diff --git a/src/block/plugin_block_template.c b/src/block/plugin_block_template.c
index dcaf1afaa..46a370924 100644
--- a/src/block/plugin_block_template.c
+++ b/src/block/plugin_block_template.c
@@ -48,7 +48,6 @@
48 * 48 *
49 * @param ctx block context in which the block group is created 49 * @param ctx block context in which the block group is created
50 * @param type type of the block for which we are creating the group 50 * @param type type of the block for which we are creating the group
51 * @param nonce random value used to seed the group creation
52 * @param raw_data optional serialized prior state of the group, NULL if unavailable/fresh 51 * @param raw_data optional serialized prior state of the group, NULL if unavailable/fresh
53 * @param raw_data_size number of bytes in @a raw_data, 0 if unavailable/fresh 52 * @param raw_data_size number of bytes in @a raw_data, 0 if unavailable/fresh
54 * @param va variable arguments specific to @a type 53 * @param va variable arguments specific to @a type
@@ -58,7 +57,6 @@
58static struct GNUNET_BLOCK_Group * 57static struct GNUNET_BLOCK_Group *
59block_plugin_template_create_group (void *cls, 58block_plugin_template_create_group (void *cls,
60 enum GNUNET_BLOCK_Type type, 59 enum GNUNET_BLOCK_Type type,
61 uint32_t nonce,
62 const void *raw_data, 60 const void *raw_data,
63 size_t raw_data_size, 61 size_t raw_data_size,
64 va_list va) 62 va_list va)
@@ -85,7 +83,6 @@ block_plugin_template_create_group (void *cls,
85 bf_size, 83 bf_size,
86 BLOOMFILTER_K, 84 BLOOMFILTER_K,
87 type, 85 type,
88 nonce,
89 raw_data, 86 raw_data,
90 raw_data_size); 87 raw_data_size);
91} 88}
@@ -124,9 +121,9 @@ block_plugin_template_check_query (void *cls,
124 */ 121 */
125static enum GNUNET_GenericReturnValue 122static enum GNUNET_GenericReturnValue
126block_plugin_template_check_block (void *cls, 123block_plugin_template_check_block (void *cls,
127 enum GNUNET_BLOCK_Type type, 124 enum GNUNET_BLOCK_Type type,
128 const void *block, 125 const void *block,
129 size_t block_size) 126 size_t block_size)
130{ 127{
131 return GNUNET_SYSERR; 128 return GNUNET_SYSERR;
132} 129}
@@ -150,14 +147,14 @@ block_plugin_template_check_block (void *cls,
150 */ 147 */
151static enum GNUNET_BLOCK_ReplyEvaluationResult 148static enum GNUNET_BLOCK_ReplyEvaluationResult
152block_plugin_template_check_reply ( 149block_plugin_template_check_reply (
153 void *cls, 150 void *cls,
154 enum GNUNET_BLOCK_Type type, 151 enum GNUNET_BLOCK_Type type,
155 struct GNUNET_BLOCK_Group *group, 152 struct GNUNET_BLOCK_Group *group,
156 const struct GNUNET_HashCode *query, 153 const struct GNUNET_HashCode *query,
157 const void *xquery, 154 const void *xquery,
158 size_t xquery_size, 155 size_t xquery_size,
159 const void *reply_block, 156 const void *reply_block,
160 size_t reply_block_size) 157 size_t reply_block_size)
161{ 158{
162 return GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED; 159 return GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED;
163} 160}
diff --git a/src/block/plugin_block_test.c b/src/block/plugin_block_test.c
index 05d379387..2e404bbc2 100644
--- a/src/block/plugin_block_test.c
+++ b/src/block/plugin_block_test.c
@@ -46,7 +46,6 @@
46 * 46 *
47 * @param ctx block context in which the block group is created 47 * @param ctx block context in which the block group is created
48 * @param type type of the block for which we are creating the group 48 * @param type type of the block for which we are creating the group
49 * @param nonce random value used to seed the group creation
50 * @param raw_data optional serialized prior state of the group, NULL if unavailable/fresh 49 * @param raw_data optional serialized prior state of the group, NULL if unavailable/fresh
51 * @param raw_data_size number of bytes in @a raw_data, 0 if unavailable/fresh 50 * @param raw_data_size number of bytes in @a raw_data, 0 if unavailable/fresh
52 * @param va variable arguments specific to @a type 51 * @param va variable arguments specific to @a type
@@ -56,7 +55,6 @@
56static struct GNUNET_BLOCK_Group * 55static struct GNUNET_BLOCK_Group *
57block_plugin_test_create_group (void *cls, 56block_plugin_test_create_group (void *cls,
58 enum GNUNET_BLOCK_Type type, 57 enum GNUNET_BLOCK_Type type,
59 uint32_t nonce,
60 const void *raw_data, 58 const void *raw_data,
61 size_t raw_data_size, 59 size_t raw_data_size,
62 va_list va) 60 va_list va)
@@ -83,7 +81,6 @@ block_plugin_test_create_group (void *cls,
83 bf_size, 81 bf_size,
84 BLOOMFILTER_K, 82 BLOOMFILTER_K,
85 type, 83 type,
86 nonce,
87 raw_data, 84 raw_data,
88 raw_data_size); 85 raw_data_size);
89} 86}