diff options
Diffstat (limited to 'src/service/setu/plugin_block_setu_test.c')
-rw-r--r-- | src/service/setu/plugin_block_setu_test.c | 195 |
1 files changed, 195 insertions, 0 deletions
diff --git a/src/service/setu/plugin_block_setu_test.c b/src/service/setu/plugin_block_setu_test.c new file mode 100644 index 000000000..178ad3314 --- /dev/null +++ b/src/service/setu/plugin_block_setu_test.c | |||
@@ -0,0 +1,195 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | Copyright (C) 2017 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 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file setu/plugin_block_setu_test.c | ||
23 | * @brief set test block, recognizes elements with non-zero first byte as invalid | ||
24 | * @author Christian Grothoff | ||
25 | */ | ||
26 | #include "platform.h" | ||
27 | #include "gnunet_block_plugin.h" | ||
28 | #include "gnunet_block_group_lib.h" | ||
29 | |||
30 | |||
31 | /** | ||
32 | * Function called to validate a query. | ||
33 | * | ||
34 | * @param cls closure | ||
35 | * @param ctx block context | ||
36 | * @param type block type | ||
37 | * @param query original query (hash) | ||
38 | * @param xquery extrended query data (can be NULL, depending on type) | ||
39 | * @param xquery_size number of bytes in @a xquery | ||
40 | * @return #GNUNET_OK if the query is fine, #GNUNET_NO if not | ||
41 | */ | ||
42 | static enum GNUNET_GenericReturnValue | ||
43 | block_plugin_setu_test_check_query (void *cls, | ||
44 | enum GNUNET_BLOCK_Type type, | ||
45 | const struct GNUNET_HashCode *query, | ||
46 | const void *xquery, | ||
47 | size_t xquery_size) | ||
48 | { | ||
49 | if (GNUNET_BLOCK_TYPE_SETU_TEST != type) | ||
50 | { | ||
51 | GNUNET_break (0); | ||
52 | return GNUNET_SYSERR; | ||
53 | } | ||
54 | if (0 != xquery_size) | ||
55 | { | ||
56 | GNUNET_break_op (0); | ||
57 | return GNUNET_NO; | ||
58 | } | ||
59 | return GNUNET_OK; | ||
60 | } | ||
61 | |||
62 | |||
63 | /** | ||
64 | * Function called to validate a block for storage. | ||
65 | * | ||
66 | * @param cls closure | ||
67 | * @param type block type | ||
68 | * @param block block data to validate | ||
69 | * @param block_size number of bytes in @a block | ||
70 | * @return #GNUNET_OK if the block is fine, #GNUNET_NO if not | ||
71 | */ | ||
72 | static enum GNUNET_GenericReturnValue | ||
73 | block_plugin_setu_test_check_block (void *cls, | ||
74 | enum GNUNET_BLOCK_Type type, | ||
75 | const void *block, | ||
76 | size_t block_size) | ||
77 | { | ||
78 | if (GNUNET_BLOCK_TYPE_SETU_TEST != type) | ||
79 | { | ||
80 | GNUNET_break (0); | ||
81 | return GNUNET_SYSERR; | ||
82 | } | ||
83 | if ( (NULL == block) || | ||
84 | (0 == block_size) || | ||
85 | (0 != ((char *) block)[0]) ) | ||
86 | return GNUNET_NO; | ||
87 | return GNUNET_OK; | ||
88 | } | ||
89 | |||
90 | |||
91 | /** | ||
92 | * Function called to validate a reply to a request. Note that it is assumed | ||
93 | * that the reply has already been matched to the key (and signatures checked) | ||
94 | * as it would be done with the GetKeyFunction and the | ||
95 | * BlockEvaluationFunction. | ||
96 | * | ||
97 | * @param cls closure | ||
98 | * @param type block type | ||
99 | * @param group which block group to use for evaluation | ||
100 | * @param query original query (hash) | ||
101 | * @param xquery extrended query data (can be NULL, depending on type) | ||
102 | * @param xquery_size number of bytes in @a xquery | ||
103 | * @param reply_block response to validate | ||
104 | * @param reply_block_size number of bytes in @a reply_block | ||
105 | * @return characterization of result | ||
106 | */ | ||
107 | static enum GNUNET_BLOCK_ReplyEvaluationResult | ||
108 | block_plugin_setu_test_check_reply (void *cls, | ||
109 | enum GNUNET_BLOCK_Type type, | ||
110 | struct GNUNET_BLOCK_Group *group, | ||
111 | const struct GNUNET_HashCode *query, | ||
112 | const void *xquery, | ||
113 | size_t xquery_size, | ||
114 | const void *reply_block, | ||
115 | size_t reply_block_size) | ||
116 | { | ||
117 | (void) cls; | ||
118 | (void) xquery; | ||
119 | (void) xquery_size; | ||
120 | if (GNUNET_BLOCK_TYPE_SETU_TEST != type) | ||
121 | { | ||
122 | GNUNET_break (0); | ||
123 | return GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED; | ||
124 | } | ||
125 | if ( (NULL == reply_block) || | ||
126 | (0 == reply_block_size) || | ||
127 | (0 != ((char *) reply_block)[0]) ) | ||
128 | GNUNET_assert (0); | ||
129 | return GNUNET_BLOCK_REPLY_OK_MORE; | ||
130 | } | ||
131 | |||
132 | |||
133 | /** | ||
134 | * Function called to obtain the key for a block. | ||
135 | * | ||
136 | * @param cls closure | ||
137 | * @param type block type | ||
138 | * @param block block to get the key for | ||
139 | * @param block_size number of bytes in block | ||
140 | * @param key set to the key (query) for the given block | ||
141 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if type not supported | ||
142 | * (or if extracting a key from a block of this type does not work) | ||
143 | */ | ||
144 | static enum GNUNET_GenericReturnValue | ||
145 | block_plugin_setu_test_get_key (void *cls, | ||
146 | enum GNUNET_BLOCK_Type type, | ||
147 | const void *block, | ||
148 | size_t block_size, | ||
149 | struct GNUNET_HashCode *key) | ||
150 | { | ||
151 | if (GNUNET_BLOCK_TYPE_SETU_TEST != type) | ||
152 | { | ||
153 | GNUNET_break (0); | ||
154 | return GNUNET_SYSERR; | ||
155 | } | ||
156 | return GNUNET_NO; | ||
157 | } | ||
158 | |||
159 | |||
160 | /** | ||
161 | * Entry point for the plugin. | ||
162 | */ | ||
163 | void * | ||
164 | libgnunet_plugin_block_setu_test_init (void *cls) | ||
165 | { | ||
166 | static enum GNUNET_BLOCK_Type types[] = { | ||
167 | GNUNET_BLOCK_TYPE_SETU_TEST, | ||
168 | GNUNET_BLOCK_TYPE_ANY /* end of list */ | ||
169 | }; | ||
170 | struct GNUNET_BLOCK_PluginFunctions *api; | ||
171 | |||
172 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); | ||
173 | api->get_key = &block_plugin_setu_test_get_key; | ||
174 | api->check_query = &block_plugin_setu_test_check_query; | ||
175 | api->check_block = &block_plugin_setu_test_check_block; | ||
176 | api->check_reply = &block_plugin_setu_test_check_reply; | ||
177 | api->types = types; | ||
178 | return api; | ||
179 | } | ||
180 | |||
181 | |||
182 | /** | ||
183 | * Exit point from the plugin. | ||
184 | */ | ||
185 | void * | ||
186 | libgnunet_plugin_block_setu_test_done (void *cls) | ||
187 | { | ||
188 | struct GNUNET_BLOCK_PluginFunctions *api = cls; | ||
189 | |||
190 | GNUNET_free (api); | ||
191 | return NULL; | ||
192 | } | ||
193 | |||
194 | |||
195 | /* end of plugin_block_setu_test.c */ | ||