aboutsummaryrefslogtreecommitdiff
path: root/src/block/plugin_block_test.c
diff options
context:
space:
mode:
authorChristian Grothoff <grothoff@gnunet.org>2022-03-12 04:01:02 +0100
committerChristian Grothoff <grothoff@gnunet.org>2022-03-12 04:01:02 +0100
commitff992f47e6528b00937c3951b812f6938e1ee21a (patch)
tree96917d63e24d2cc02b0e09a4e1dc29987541ffe8 /src/block/plugin_block_test.c
parent06f6791f2d55ab3a1b4ca4c3ba9ed5c315f8d79b (diff)
downloadgnunet-ff992f47e6528b00937c3951b812f6938e1ee21a.tar.gz
gnunet-ff992f47e6528b00937c3951b812f6938e1ee21a.zip
revise block API to match latest DHT specs
Diffstat (limited to 'src/block/plugin_block_test.c')
-rw-r--r--src/block/plugin_block_test.c120
1 files changed, 40 insertions, 80 deletions
diff --git a/src/block/plugin_block_test.c b/src/block/plugin_block_test.c
index fd643c4dc..05d379387 100644
--- a/src/block/plugin_block_test.c
+++ b/src/block/plugin_block_test.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet 2 This file is part of GNUnet
3 Copyright (C) 2010 GNUnet e.V. 3 Copyright (C) 2010, 2021, 2022 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 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 6 under the terms of the GNU Affero General Public License as published
@@ -90,59 +90,6 @@ block_plugin_test_create_group (void *cls,
90 90
91 91
92/** 92/**
93 * Function called to validate a reply or a request. For
94 * request evaluation, simply pass "NULL" for the reply_block.
95 *
96 * @param cls closure
97 * @param ctx block context
98 * @param type block type
99 * @param group group to check against
100 * @param eo control flags
101 * @param query original query (hash)
102 * @param xquery extrended query data (can be NULL, depending on type)
103 * @param xquery_size number of bytes in @a xquery
104 * @param reply_block response to validate
105 * @param reply_block_size number of bytes in @a reply_block
106 * @return characterization of result
107 */
108static enum GNUNET_BLOCK_EvaluationResult
109block_plugin_test_evaluate (void *cls,
110 struct GNUNET_BLOCK_Context *ctx,
111 enum GNUNET_BLOCK_Type type,
112 struct GNUNET_BLOCK_Group *group,
113 enum GNUNET_BLOCK_EvaluationOptions eo,
114 const struct GNUNET_HashCode *query,
115 const void *xquery,
116 size_t xquery_size,
117 const void *reply_block,
118 size_t reply_block_size)
119{
120 struct GNUNET_HashCode chash;
121
122 if (GNUNET_BLOCK_TYPE_TEST != type)
123 {
124 GNUNET_break (0);
125 return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED;
126 }
127 if (0 != xquery_size)
128 {
129 GNUNET_break_op (0);
130 return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
131 }
132 if (NULL == reply_block)
133 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
134 GNUNET_CRYPTO_hash (reply_block,
135 reply_block_size,
136 &chash);
137 if (GNUNET_YES ==
138 GNUNET_BLOCK_GROUP_bf_test_and_set (group,
139 &chash))
140 return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE;
141 return GNUNET_BLOCK_EVALUATION_OK_MORE;
142}
143
144
145/**
146 * Function called to validate a query. 93 * Function called to validate a query.
147 * 94 *
148 * @param cls closure 95 * @param cls closure
@@ -151,15 +98,18 @@ block_plugin_test_evaluate (void *cls,
151 * @param query original query (hash) 98 * @param query original query (hash)
152 * @param xquery extrended query data (can be NULL, depending on type) 99 * @param xquery extrended query data (can be NULL, depending on type)
153 * @param xquery_size number of bytes in @a xquery 100 * @param xquery_size number of bytes in @a xquery
154 * @return #GNUNET_OK if the query is fine, #GNUNET_NO if not 101 * @return #GNUNET_OK if the query is fine, #GNUNET_NO if not, #GNUNET_SYSERR if @a type is not supported
155 */ 102 */
156static enum GNUNET_GenericReturnValue 103static enum GNUNET_GenericReturnValue
157block_plugin_test_check_query (void *cls, 104block_plugin_test_check_query (void *cls,
158 enum GNUNET_BLOCK_Type type, 105 enum GNUNET_BLOCK_Type type,
159 const struct GNUNET_HashCode *query, 106 const struct GNUNET_HashCode *query,
160 const void *xquery, 107 const void *xquery,
161 size_t xquery_size) 108 size_t xquery_size)
162{ 109{
110 (void) cls;
111 (void) query;
112 (void) xquery;
163 if (GNUNET_BLOCK_TYPE_TEST != type) 113 if (GNUNET_BLOCK_TYPE_TEST != type)
164 { 114 {
165 GNUNET_break (0); 115 GNUNET_break (0);
@@ -168,9 +118,9 @@ block_plugin_test_check_query (void *cls,
168 if (0 != xquery_size) 118 if (0 != xquery_size)
169 { 119 {
170 GNUNET_break_op (0); 120 GNUNET_break_op (0);
171 return GNUNET_SYSERR; 121 return GNUNET_NO;
172 } 122 }
173 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; 123 return GNUNET_OK;
174} 124}
175 125
176 126
@@ -179,18 +129,19 @@ block_plugin_test_check_query (void *cls,
179 * 129 *
180 * @param cls closure 130 * @param cls closure
181 * @param type block type 131 * @param type block type
182 * @param query key for the block (hash), must match exactly
183 * @param block block data to validate 132 * @param block block data to validate
184 * @param block_size number of bytes in @a block 133 * @param block_size number of bytes in @a block
185 * @return #GNUNET_OK if the block is fine, #GNUNET_NO if not 134 * @return #GNUNET_OK if the block is fine, #GNUNET_NO if not, #GNUNET_SYSERR if @a type is not supported
186 */ 135 */
187static enum GNUNET_GenericReturnValue 136static enum GNUNET_GenericReturnValue
188block_plugin_test_check_block (void *cls, 137block_plugin_test_check_block (void *cls,
189 enum GNUNET_BLOCK_Type type, 138 enum GNUNET_BLOCK_Type type,
190 const struct GNUNET_HashCode *query, 139 const void *block,
191 const void *block, 140 size_t block_size)
192 size_t block_size)
193{ 141{
142 (void) cls;
143 (void) block;
144 (void) block_size;
194 if (GNUNET_BLOCK_TYPE_TEST != type) 145 if (GNUNET_BLOCK_TYPE_TEST != type)
195 { 146 {
196 GNUNET_break (0); 147 GNUNET_break (0);
@@ -218,16 +169,20 @@ block_plugin_test_check_block (void *cls,
218 */ 169 */
219static enum GNUNET_BLOCK_ReplyEvaluationResult 170static enum GNUNET_BLOCK_ReplyEvaluationResult
220block_plugin_test_check_reply (void *cls, 171block_plugin_test_check_reply (void *cls,
221 enum GNUNET_BLOCK_Type type, 172 enum GNUNET_BLOCK_Type type,
222 struct GNUNET_BLOCK_Group *group, 173 struct GNUNET_BLOCK_Group *group,
223 const struct GNUNET_HashCode *query, 174 const struct GNUNET_HashCode *query,
224 const void *xquery, 175 const void *xquery,
225 size_t xquery_size, 176 size_t xquery_size,
226 const void *reply_block, 177 const void *reply_block,
227 size_t reply_block_size) 178 size_t reply_block_size)
228{ 179{
229 struct GNUNET_HashCode chash; 180 struct GNUNET_HashCode chash;
230 181
182 (void) cls;
183 (void) query;
184 (void) xquery;
185 (void) xquery_size;
231 if (GNUNET_BLOCK_TYPE_TEST != type) 186 if (GNUNET_BLOCK_TYPE_TEST != type)
232 { 187 {
233 GNUNET_break (0); 188 GNUNET_break (0);
@@ -252,8 +207,7 @@ block_plugin_test_check_reply (void *cls,
252 * @param block block to get the key for 207 * @param block block to get the key for
253 * @param block_size number of bytes in @a block 208 * @param block_size number of bytes in @a block
254 * @param key set to the key (query) for the given block 209 * @param key set to the key (query) for the given block
255 * @return #GNUNET_OK on success, #GNUNET_SYSERR if type not supported 210 * @return #GNUNET_OK on success, #GNUNET_SYSERR if type not supported, #GNUNET_NO if extracting a key from a block of this type does not work
256 * (or if extracting a key from a block of this type does not work)
257 */ 211 */
258static enum GNUNET_GenericReturnValue 212static enum GNUNET_GenericReturnValue
259block_plugin_test_get_key (void *cls, 213block_plugin_test_get_key (void *cls,
@@ -262,9 +216,16 @@ block_plugin_test_get_key (void *cls,
262 size_t block_size, 216 size_t block_size,
263 struct GNUNET_HashCode *key) 217 struct GNUNET_HashCode *key)
264{ 218{
265 /* always fails since there is no fixed relationship between 219 (void) cls;
266 * keys and values for test values */ 220 (void) block;
267 return GNUNET_SYSERR; 221 (void) block_size;
222 (void) key;
223 if (GNUNET_BLOCK_TYPE_TEST != type)
224 {
225 GNUNET_break (0);
226 return GNUNET_SYSERR;
227 }
228 return GNUNET_NO;
268} 229}
269 230
270 231
@@ -284,7 +245,6 @@ libgnunet_plugin_block_test_init (void *cls)
284 struct GNUNET_BLOCK_PluginFunctions *api; 245 struct GNUNET_BLOCK_PluginFunctions *api;
285 246
286 api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); 247 api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions);
287 api->evaluate = &block_plugin_test_evaluate;
288 api->get_key = &block_plugin_test_get_key; 248 api->get_key = &block_plugin_test_get_key;
289 api->check_query = &block_plugin_test_check_query; 249 api->check_query = &block_plugin_test_check_query;
290 api->check_block = &block_plugin_test_check_block; 250 api->check_block = &block_plugin_test_check_block;