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