summaryrefslogtreecommitdiff
path: root/src/revocation/plugin_block_revocation.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/revocation/plugin_block_revocation.c')
-rw-r--r--src/revocation/plugin_block_revocation.c179
1 files changed, 88 insertions, 91 deletions
diff --git a/src/revocation/plugin_block_revocation.c b/src/revocation/plugin_block_revocation.c
index 2d03eb8b2..e7b4a8cde 100644
--- a/src/revocation/plugin_block_revocation.c
+++ b/src/revocation/plugin_block_revocation.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 block/plugin_block_revocation.c 22 * @file block/plugin_block_revocation.c
@@ -49,11 +49,8 @@
49/** 49/**
50 * Context used inside the plugin. 50 * Context used inside the plugin.
51 */ 51 */
52struct InternalContext 52struct InternalContext {
53{
54
55 unsigned int matching_bits; 53 unsigned int matching_bits;
56
57}; 54};
58 55
59 56
@@ -70,37 +67,37 @@ struct InternalContext
70 * by this @a type of block (this is not an error) 67 * by this @a type of block (this is not an error)
71 */ 68 */
72static struct GNUNET_BLOCK_Group * 69static struct GNUNET_BLOCK_Group *
73block_plugin_revocation_create_group (void *cls, 70block_plugin_revocation_create_group(void *cls,
74 enum GNUNET_BLOCK_Type type, 71 enum GNUNET_BLOCK_Type type,
75 uint32_t nonce, 72 uint32_t nonce,
76 const void *raw_data, 73 const void *raw_data,
77 size_t raw_data_size, 74 size_t raw_data_size,
78 va_list va) 75 va_list va)
79{ 76{
80 unsigned int bf_size; 77 unsigned int bf_size;
81 const char *guard; 78 const char *guard;
82 79
83 guard = va_arg (va, const char *); 80 guard = va_arg(va, const char *);
84 if (0 == strcmp (guard, 81 if (0 == strcmp(guard,
85 "seen-set-size")) 82 "seen-set-size"))
86 bf_size = GNUNET_BLOCK_GROUP_compute_bloomfilter_size (va_arg (va, unsigned int), 83 bf_size = GNUNET_BLOCK_GROUP_compute_bloomfilter_size(va_arg(va, unsigned int),
87 BLOOMFILTER_K); 84 BLOOMFILTER_K);
88 else if (0 == strcmp (guard, 85 else if (0 == strcmp(guard,
89 "filter-size")) 86 "filter-size"))
90 bf_size = va_arg (va, unsigned int); 87 bf_size = va_arg(va, unsigned int);
91 else 88 else
92 { 89 {
93 GNUNET_break (0); 90 GNUNET_break(0);
94 bf_size = REVOCATION_BF_SIZE; 91 bf_size = REVOCATION_BF_SIZE;
95 } 92 }
96 GNUNET_break (NULL == va_arg (va, const char *)); 93 GNUNET_break(NULL == va_arg(va, const char *));
97 return GNUNET_BLOCK_GROUP_bf_create (cls, 94 return GNUNET_BLOCK_GROUP_bf_create(cls,
98 bf_size, 95 bf_size,
99 BLOOMFILTER_K, 96 BLOOMFILTER_K,
100 type, 97 type,
101 nonce, 98 nonce,
102 raw_data, 99 raw_data,
103 raw_data_size); 100 raw_data_size);
104} 101}
105 102
106 103
@@ -121,16 +118,16 @@ block_plugin_revocation_create_group (void *cls,
121 * @return characterization of result 118 * @return characterization of result
122 */ 119 */
123static enum GNUNET_BLOCK_EvaluationResult 120static enum GNUNET_BLOCK_EvaluationResult
124block_plugin_revocation_evaluate (void *cls, 121block_plugin_revocation_evaluate(void *cls,
125 struct GNUNET_BLOCK_Context *ctx, 122 struct GNUNET_BLOCK_Context *ctx,
126 enum GNUNET_BLOCK_Type type, 123 enum GNUNET_BLOCK_Type type,
127 struct GNUNET_BLOCK_Group *group, 124 struct GNUNET_BLOCK_Group *group,
128 enum GNUNET_BLOCK_EvaluationOptions eo, 125 enum GNUNET_BLOCK_EvaluationOptions eo,
129 const struct GNUNET_HashCode *query, 126 const struct GNUNET_HashCode *query,
130 const void *xquery, 127 const void *xquery,
131 size_t xquery_size, 128 size_t xquery_size,
132 const void *reply_block, 129 const void *reply_block,
133 size_t reply_block_size) 130 size_t reply_block_size)
134{ 131{
135 struct InternalContext *ic = cls; 132 struct InternalContext *ic = cls;
136 struct GNUNET_HashCode chash; 133 struct GNUNET_HashCode chash;
@@ -138,34 +135,34 @@ block_plugin_revocation_evaluate (void *cls,
138 135
139 if (NULL == reply_block) 136 if (NULL == reply_block)
140 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; 137 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
141 if (reply_block_size != sizeof (*rm)) 138 if (reply_block_size != sizeof(*rm))
142 { 139 {
143 GNUNET_break_op (0); 140 GNUNET_break_op(0);
144 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; 141 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
145 } 142 }
146 if (GNUNET_YES != 143 if (GNUNET_YES !=
147 GNUNET_REVOCATION_check_pow (&rm->public_key, 144 GNUNET_REVOCATION_check_pow(&rm->public_key,
148 rm->proof_of_work, 145 rm->proof_of_work,
149 ic->matching_bits)) 146 ic->matching_bits))
150 { 147 {
151 GNUNET_break_op (0); 148 GNUNET_break_op(0);
152 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; 149 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
153 } 150 }
154 if (GNUNET_OK != 151 if (GNUNET_OK !=
155 GNUNET_CRYPTO_ecdsa_verify (GNUNET_SIGNATURE_PURPOSE_REVOCATION, 152 GNUNET_CRYPTO_ecdsa_verify(GNUNET_SIGNATURE_PURPOSE_REVOCATION,
156 &rm->purpose, 153 &rm->purpose,
157 &rm->signature, 154 &rm->signature,
158 &rm->public_key)) 155 &rm->public_key))
159 { 156 {
160 GNUNET_break_op (0); 157 GNUNET_break_op(0);
161 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; 158 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
162 } 159 }
163 GNUNET_CRYPTO_hash (&rm->public_key, 160 GNUNET_CRYPTO_hash(&rm->public_key,
164 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey), 161 sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey),
165 &chash); 162 &chash);
166 if (GNUNET_YES == 163 if (GNUNET_YES ==
167 GNUNET_BLOCK_GROUP_bf_test_and_set (group, 164 GNUNET_BLOCK_GROUP_bf_test_and_set(group,
168 &chash)) 165 &chash))
169 return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE; 166 return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE;
170 return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; 167 return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED;
171} 168}
@@ -183,22 +180,22 @@ block_plugin_revocation_evaluate (void *cls,
183 * (or if extracting a key from a block of this type does not work) 180 * (or if extracting a key from a block of this type does not work)
184 */ 181 */
185static int 182static int
186block_plugin_revocation_get_key (void *cls, 183block_plugin_revocation_get_key(void *cls,
187 enum GNUNET_BLOCK_Type type, 184 enum GNUNET_BLOCK_Type type,
188 const void *block, 185 const void *block,
189 size_t block_size, 186 size_t block_size,
190 struct GNUNET_HashCode *key) 187 struct GNUNET_HashCode *key)
191{ 188{
192 const struct RevokeMessage *rm = block; 189 const struct RevokeMessage *rm = block;
193 190
194 if (block_size != sizeof (*rm)) 191 if (block_size != sizeof(*rm))
195 { 192 {
196 GNUNET_break_op (0); 193 GNUNET_break_op(0);
197 return GNUNET_SYSERR; 194 return GNUNET_SYSERR;
198 } 195 }
199 GNUNET_CRYPTO_hash (&rm->public_key, 196 GNUNET_CRYPTO_hash(&rm->public_key,
200 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey), 197 sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey),
201 key); 198 key);
202 return GNUNET_OK; 199 return GNUNET_OK;
203} 200}
204 201
@@ -209,7 +206,7 @@ block_plugin_revocation_get_key (void *cls,
209 * @param cls the configuration to use 206 * @param cls the configuration to use
210 */ 207 */
211void * 208void *
212libgnunet_plugin_block_revocation_init (void *cls) 209libgnunet_plugin_block_revocation_init(void *cls)
213{ 210{
214 static enum GNUNET_BLOCK_Type types[] = 211 static enum GNUNET_BLOCK_Type types[] =
215 { 212 {
@@ -222,19 +219,19 @@ libgnunet_plugin_block_revocation_init (void *cls)
222 unsigned long long matching_bits; 219 unsigned long long matching_bits;
223 220
224 if (GNUNET_OK != 221 if (GNUNET_OK !=
225 GNUNET_CONFIGURATION_get_value_number (cfg, 222 GNUNET_CONFIGURATION_get_value_number(cfg,
226 "REVOCATION", 223 "REVOCATION",
227 "WORKBITS", 224 "WORKBITS",
228 &matching_bits)) 225 &matching_bits))
229 return NULL; 226 return NULL;
230 227
231 api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); 228 api = GNUNET_new(struct GNUNET_BLOCK_PluginFunctions);
232 api->evaluate = &block_plugin_revocation_evaluate; 229 api->evaluate = &block_plugin_revocation_evaluate;
233 api->get_key = &block_plugin_revocation_get_key; 230 api->get_key = &block_plugin_revocation_get_key;
234 api->create_group = &block_plugin_revocation_create_group; 231 api->create_group = &block_plugin_revocation_create_group;
235 api->types = types; 232 api->types = types;
236 ic = GNUNET_new (struct InternalContext); 233 ic = GNUNET_new(struct InternalContext);
237 ic->matching_bits = (unsigned int) matching_bits; 234 ic->matching_bits = (unsigned int)matching_bits;
238 api->cls = ic; 235 api->cls = ic;
239 return api; 236 return api;
240} 237}
@@ -244,13 +241,13 @@ libgnunet_plugin_block_revocation_init (void *cls)
244 * Exit point from the plugin. 241 * Exit point from the plugin.
245 */ 242 */
246void * 243void *
247libgnunet_plugin_block_revocation_done (void *cls) 244libgnunet_plugin_block_revocation_done(void *cls)
248{ 245{
249 struct GNUNET_BLOCK_PluginFunctions *api = cls; 246 struct GNUNET_BLOCK_PluginFunctions *api = cls;
250 struct InternalContext *ic = api->cls; 247 struct InternalContext *ic = api->cls;
251 248
252 GNUNET_free (ic); 249 GNUNET_free(ic);
253 GNUNET_free (api); 250 GNUNET_free(api);
254 return NULL; 251 return NULL;
255} 252}
256 253