diff options
author | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
---|---|---|
committer | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
commit | d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb (patch) | |
tree | 9efd18ea7d425652085ed0bd5e8e45604bc5f6b9 /src/fs/plugin_block_fs.c | |
parent | a0fce305c565c0937d917a92712f15e9c5736260 (diff) | |
download | gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.tar.gz gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.zip |
uncrustify as demanded.
Diffstat (limited to 'src/fs/plugin_block_fs.c')
-rw-r--r-- | src/fs/plugin_block_fs.c | 287 |
1 files changed, 147 insertions, 140 deletions
diff --git a/src/fs/plugin_block_fs.c b/src/fs/plugin_block_fs.c index f0df52c99..8003e3837 100644 --- a/src/fs/plugin_block_fs.c +++ b/src/fs/plugin_block_fs.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 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/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file fs/plugin_block_fs.c | 22 | * @file fs/plugin_block_fs.c |
@@ -51,58 +51,61 @@ | |||
51 | * by this @a type of block (this is not an error) | 51 | * by this @a type of block (this is not an error) |
52 | */ | 52 | */ |
53 | static struct GNUNET_BLOCK_Group * | 53 | static struct GNUNET_BLOCK_Group * |
54 | block_plugin_fs_create_group (void *cls, | 54 | block_plugin_fs_create_group(void *cls, |
55 | enum GNUNET_BLOCK_Type type, | 55 | enum GNUNET_BLOCK_Type type, |
56 | uint32_t nonce, | 56 | uint32_t nonce, |
57 | const void *raw_data, | 57 | const void *raw_data, |
58 | size_t raw_data_size, | 58 | size_t raw_data_size, |
59 | va_list va) | 59 | va_list va) |
60 | { | 60 | { |
61 | unsigned int size; | 61 | unsigned int size; |
62 | const char *guard; | 62 | const char *guard; |
63 | 63 | ||
64 | switch (type) | 64 | switch (type) |
65 | { | ||
66 | case GNUNET_BLOCK_TYPE_FS_DBLOCK: | ||
67 | GNUNET_break (NULL == va_arg (va, const char *)); | ||
68 | return NULL; | ||
69 | case GNUNET_BLOCK_TYPE_FS_IBLOCK: | ||
70 | GNUNET_break (NULL == va_arg (va, const char *)); | ||
71 | return NULL; | ||
72 | case GNUNET_BLOCK_TYPE_FS_UBLOCK: | ||
73 | guard = va_arg (va, const char *); | ||
74 | if (0 == strcmp (guard, | ||
75 | "seen-set-size")) | ||
76 | { | ||
77 | size = GNUNET_BLOCK_GROUP_compute_bloomfilter_size (va_arg (va, unsigned int), | ||
78 | BLOOMFILTER_K); | ||
79 | } | ||
80 | else if (0 == strcmp (guard, | ||
81 | "filter-size")) | ||
82 | { | ||
83 | size = va_arg (va, unsigned int); | ||
84 | } | ||
85 | else | ||
86 | { | 65 | { |
87 | /* va-args invalid! bad bug, complain! */ | 66 | case GNUNET_BLOCK_TYPE_FS_DBLOCK: |
88 | GNUNET_break (0); | 67 | GNUNET_break(NULL == va_arg(va, const char *)); |
89 | size = 8; | 68 | return NULL; |
69 | |||
70 | case GNUNET_BLOCK_TYPE_FS_IBLOCK: | ||
71 | GNUNET_break(NULL == va_arg(va, const char *)); | ||
72 | return NULL; | ||
73 | |||
74 | case GNUNET_BLOCK_TYPE_FS_UBLOCK: | ||
75 | guard = va_arg(va, const char *); | ||
76 | if (0 == strcmp(guard, | ||
77 | "seen-set-size")) | ||
78 | { | ||
79 | size = GNUNET_BLOCK_GROUP_compute_bloomfilter_size(va_arg(va, unsigned int), | ||
80 | BLOOMFILTER_K); | ||
81 | } | ||
82 | else if (0 == strcmp(guard, | ||
83 | "filter-size")) | ||
84 | { | ||
85 | size = va_arg(va, unsigned int); | ||
86 | } | ||
87 | else | ||
88 | { | ||
89 | /* va-args invalid! bad bug, complain! */ | ||
90 | GNUNET_break(0); | ||
91 | size = 8; | ||
92 | } | ||
93 | if (0 == size) | ||
94 | size = raw_data_size; /* not for us to determine, use what we got! */ | ||
95 | GNUNET_break(NULL == va_arg(va, const char *)); | ||
96 | return GNUNET_BLOCK_GROUP_bf_create(cls, | ||
97 | size, | ||
98 | BLOOMFILTER_K, | ||
99 | type, | ||
100 | nonce, | ||
101 | raw_data, | ||
102 | raw_data_size); | ||
103 | |||
104 | default: | ||
105 | GNUNET_break(NULL == va_arg(va, const char *)); | ||
106 | GNUNET_break(0); | ||
107 | return NULL; | ||
90 | } | 108 | } |
91 | if (0 == size) | ||
92 | size = raw_data_size; /* not for us to determine, use what we got! */ | ||
93 | GNUNET_break (NULL == va_arg (va, const char *)); | ||
94 | return GNUNET_BLOCK_GROUP_bf_create (cls, | ||
95 | size, | ||
96 | BLOOMFILTER_K, | ||
97 | type, | ||
98 | nonce, | ||
99 | raw_data, | ||
100 | raw_data_size); | ||
101 | default: | ||
102 | GNUNET_break (NULL == va_arg (va, const char *)); | ||
103 | GNUNET_break (0); | ||
104 | return NULL; | ||
105 | } | ||
106 | } | 109 | } |
107 | 110 | ||
108 | 111 | ||
@@ -126,84 +129,86 @@ block_plugin_fs_create_group (void *cls, | |||
126 | * @return characterization of result | 129 | * @return characterization of result |
127 | */ | 130 | */ |
128 | static enum GNUNET_BLOCK_EvaluationResult | 131 | static enum GNUNET_BLOCK_EvaluationResult |
129 | block_plugin_fs_evaluate (void *cls, | 132 | block_plugin_fs_evaluate(void *cls, |
130 | struct GNUNET_BLOCK_Context *ctx, | 133 | struct GNUNET_BLOCK_Context *ctx, |
131 | enum GNUNET_BLOCK_Type type, | 134 | enum GNUNET_BLOCK_Type type, |
132 | struct GNUNET_BLOCK_Group *bg, | 135 | struct GNUNET_BLOCK_Group *bg, |
133 | enum GNUNET_BLOCK_EvaluationOptions eo, | 136 | enum GNUNET_BLOCK_EvaluationOptions eo, |
134 | const struct GNUNET_HashCode *query, | 137 | const struct GNUNET_HashCode *query, |
135 | const void *xquery, | 138 | const void *xquery, |
136 | size_t xquery_size, | 139 | size_t xquery_size, |
137 | const void *reply_block, | 140 | const void *reply_block, |
138 | size_t reply_block_size) | 141 | size_t reply_block_size) |
139 | { | 142 | { |
140 | const struct UBlock *ub; | 143 | const struct UBlock *ub; |
141 | struct GNUNET_HashCode hc; | 144 | struct GNUNET_HashCode hc; |
142 | struct GNUNET_HashCode chash; | 145 | struct GNUNET_HashCode chash; |
143 | 146 | ||
144 | switch (type) | 147 | switch (type) |
145 | { | ||
146 | case GNUNET_BLOCK_TYPE_FS_DBLOCK: | ||
147 | case GNUNET_BLOCK_TYPE_FS_IBLOCK: | ||
148 | if (0 != xquery_size) | ||
149 | { | ||
150 | GNUNET_break_op (0); | ||
151 | return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID; | ||
152 | } | ||
153 | if (NULL == reply_block) | ||
154 | return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; | ||
155 | return GNUNET_BLOCK_EVALUATION_OK_LAST; | ||
156 | case GNUNET_BLOCK_TYPE_FS_UBLOCK: | ||
157 | if (0 != xquery_size) | ||
158 | { | 148 | { |
159 | GNUNET_break_op (0); | 149 | case GNUNET_BLOCK_TYPE_FS_DBLOCK: |
160 | return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID; | 150 | case GNUNET_BLOCK_TYPE_FS_IBLOCK: |
161 | } | 151 | if (0 != xquery_size) |
162 | if (NULL == reply_block) | 152 | { |
163 | return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; | 153 | GNUNET_break_op(0); |
154 | return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID; | ||
155 | } | ||
156 | if (NULL == reply_block) | ||
157 | return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; | ||
158 | return GNUNET_BLOCK_EVALUATION_OK_LAST; | ||
164 | 159 | ||
165 | if (reply_block_size < sizeof (struct UBlock)) | 160 | case GNUNET_BLOCK_TYPE_FS_UBLOCK: |
166 | { | 161 | if (0 != xquery_size) |
167 | GNUNET_break_op (0); | 162 | { |
168 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | 163 | GNUNET_break_op(0); |
169 | } | 164 | return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID; |
170 | ub = reply_block; | 165 | } |
171 | GNUNET_CRYPTO_hash (&ub->verification_key, | 166 | if (NULL == reply_block) |
172 | sizeof (ub->verification_key), | 167 | return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; |
173 | &hc); | 168 | |
174 | if (0 != memcmp (&hc, | 169 | if (reply_block_size < sizeof(struct UBlock)) |
175 | query, | 170 | { |
176 | sizeof (struct GNUNET_HashCode))) | 171 | GNUNET_break_op(0); |
177 | { | 172 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; |
178 | GNUNET_break_op (0); | 173 | } |
179 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | 174 | ub = reply_block; |
180 | } | 175 | GNUNET_CRYPTO_hash(&ub->verification_key, |
181 | if (reply_block_size != ntohl (ub->purpose.size) + sizeof (struct GNUNET_CRYPTO_EcdsaSignature)) | 176 | sizeof(ub->verification_key), |
182 | { | 177 | &hc); |
183 | GNUNET_break_op (0); | 178 | if (0 != memcmp(&hc, |
184 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | 179 | query, |
185 | } | 180 | sizeof(struct GNUNET_HashCode))) |
186 | if ( (0 == (eo & GNUNET_BLOCK_EO_LOCAL_SKIP_CRYPTO)) && | 181 | { |
187 | (GNUNET_OK != | 182 | GNUNET_break_op(0); |
188 | GNUNET_CRYPTO_ecdsa_verify (GNUNET_SIGNATURE_PURPOSE_FS_UBLOCK, | 183 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; |
184 | } | ||
185 | if (reply_block_size != ntohl(ub->purpose.size) + sizeof(struct GNUNET_CRYPTO_EcdsaSignature)) | ||
186 | { | ||
187 | GNUNET_break_op(0); | ||
188 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | ||
189 | } | ||
190 | if ((0 == (eo & GNUNET_BLOCK_EO_LOCAL_SKIP_CRYPTO)) && | ||
191 | (GNUNET_OK != | ||
192 | GNUNET_CRYPTO_ecdsa_verify(GNUNET_SIGNATURE_PURPOSE_FS_UBLOCK, | ||
189 | &ub->purpose, | 193 | &ub->purpose, |
190 | &ub->signature, | 194 | &ub->signature, |
191 | &ub->verification_key)) ) | 195 | &ub->verification_key))) |
192 | { | 196 | { |
193 | GNUNET_break_op (0); | 197 | GNUNET_break_op(0); |
194 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | 198 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; |
199 | } | ||
200 | GNUNET_CRYPTO_hash(reply_block, | ||
201 | reply_block_size, | ||
202 | &chash); | ||
203 | if (GNUNET_YES == | ||
204 | GNUNET_BLOCK_GROUP_bf_test_and_set(bg, | ||
205 | &chash)) | ||
206 | return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE; | ||
207 | return GNUNET_BLOCK_EVALUATION_OK_MORE; | ||
208 | |||
209 | default: | ||
210 | return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; | ||
195 | } | 211 | } |
196 | GNUNET_CRYPTO_hash (reply_block, | ||
197 | reply_block_size, | ||
198 | &chash); | ||
199 | if (GNUNET_YES == | ||
200 | GNUNET_BLOCK_GROUP_bf_test_and_set (bg, | ||
201 | &chash)) | ||
202 | return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE; | ||
203 | return GNUNET_BLOCK_EVALUATION_OK_MORE; | ||
204 | default: | ||
205 | return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; | ||
206 | } | ||
207 | } | 212 | } |
208 | 213 | ||
209 | 214 | ||
@@ -219,35 +224,37 @@ block_plugin_fs_evaluate (void *cls, | |||
219 | * (or if extracting a key from a block of this type does not work) | 224 | * (or if extracting a key from a block of this type does not work) |
220 | */ | 225 | */ |
221 | static int | 226 | static int |
222 | block_plugin_fs_get_key (void *cls, | 227 | block_plugin_fs_get_key(void *cls, |
223 | enum GNUNET_BLOCK_Type type, | 228 | enum GNUNET_BLOCK_Type type, |
224 | const void *block, | 229 | const void *block, |
225 | size_t block_size, | 230 | size_t block_size, |
226 | struct GNUNET_HashCode *key) | 231 | struct GNUNET_HashCode *key) |
227 | { | 232 | { |
228 | const struct UBlock *ub; | 233 | const struct UBlock *ub; |
229 | 234 | ||
230 | switch (type) | 235 | switch (type) |
231 | { | ||
232 | case GNUNET_BLOCK_TYPE_FS_DBLOCK: | ||
233 | case GNUNET_BLOCK_TYPE_FS_IBLOCK: | ||
234 | GNUNET_CRYPTO_hash (block, block_size, key); | ||
235 | return GNUNET_OK; | ||
236 | case GNUNET_BLOCK_TYPE_FS_UBLOCK: | ||
237 | if (block_size < sizeof (struct UBlock)) | ||
238 | { | 236 | { |
239 | GNUNET_break (0); | 237 | case GNUNET_BLOCK_TYPE_FS_DBLOCK: |
238 | case GNUNET_BLOCK_TYPE_FS_IBLOCK: | ||
239 | GNUNET_CRYPTO_hash(block, block_size, key); | ||
240 | return GNUNET_OK; | ||
241 | |||
242 | case GNUNET_BLOCK_TYPE_FS_UBLOCK: | ||
243 | if (block_size < sizeof(struct UBlock)) | ||
244 | { | ||
245 | GNUNET_break(0); | ||
246 | return GNUNET_SYSERR; | ||
247 | } | ||
248 | ub = block; | ||
249 | GNUNET_CRYPTO_hash(&ub->verification_key, | ||
250 | sizeof(ub->verification_key), | ||
251 | key); | ||
252 | return GNUNET_OK; | ||
253 | |||
254 | default: | ||
255 | GNUNET_break(0); | ||
240 | return GNUNET_SYSERR; | 256 | return GNUNET_SYSERR; |
241 | } | 257 | } |
242 | ub = block; | ||
243 | GNUNET_CRYPTO_hash (&ub->verification_key, | ||
244 | sizeof (ub->verification_key), | ||
245 | key); | ||
246 | return GNUNET_OK; | ||
247 | default: | ||
248 | GNUNET_break (0); | ||
249 | return GNUNET_SYSERR; | ||
250 | } | ||
251 | } | 258 | } |
252 | 259 | ||
253 | 260 | ||
@@ -255,7 +262,7 @@ block_plugin_fs_get_key (void *cls, | |||
255 | * Entry point for the plugin. | 262 | * Entry point for the plugin. |
256 | */ | 263 | */ |
257 | void * | 264 | void * |
258 | libgnunet_plugin_block_fs_init (void *cls) | 265 | libgnunet_plugin_block_fs_init(void *cls) |
259 | { | 266 | { |
260 | static enum GNUNET_BLOCK_Type types[] = | 267 | static enum GNUNET_BLOCK_Type types[] = |
261 | { | 268 | { |
@@ -266,7 +273,7 @@ libgnunet_plugin_block_fs_init (void *cls) | |||
266 | }; | 273 | }; |
267 | struct GNUNET_BLOCK_PluginFunctions *api; | 274 | struct GNUNET_BLOCK_PluginFunctions *api; |
268 | 275 | ||
269 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); | 276 | api = GNUNET_new(struct GNUNET_BLOCK_PluginFunctions); |
270 | api->evaluate = &block_plugin_fs_evaluate; | 277 | api->evaluate = &block_plugin_fs_evaluate; |
271 | api->get_key = &block_plugin_fs_get_key; | 278 | api->get_key = &block_plugin_fs_get_key; |
272 | api->create_group = &block_plugin_fs_create_group; | 279 | api->create_group = &block_plugin_fs_create_group; |
@@ -279,11 +286,11 @@ libgnunet_plugin_block_fs_init (void *cls) | |||
279 | * Exit point from the plugin. | 286 | * Exit point from the plugin. |
280 | */ | 287 | */ |
281 | void * | 288 | void * |
282 | libgnunet_plugin_block_fs_done (void *cls) | 289 | libgnunet_plugin_block_fs_done(void *cls) |
283 | { | 290 | { |
284 | struct GNUNET_BLOCK_PluginFunctions *api = cls; | 291 | struct GNUNET_BLOCK_PluginFunctions *api = cls; |
285 | 292 | ||
286 | GNUNET_free (api); | 293 | GNUNET_free(api); |
287 | return NULL; | 294 | return NULL; |
288 | } | 295 | } |
289 | 296 | ||