diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-10-06 11:46:33 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-10-06 11:46:33 +0000 |
commit | f1ee15341aa2da62691269130c915f86c7644df8 (patch) | |
tree | 684cbf6bdfec6dafa5c9fa0b058f1e5061b6b935 /src/revocation | |
parent | 2ebfdbbe8af9eef26ad1a2776a20227715560558 (diff) | |
download | gnunet-f1ee15341aa2da62691269130c915f86c7644df8.tar.gz gnunet-f1ee15341aa2da62691269130c915f86c7644df8.zip |
-store revocations to disk
Diffstat (limited to 'src/revocation')
-rw-r--r-- | src/revocation/gnunet-service-revocation.c | 133 |
1 files changed, 106 insertions, 27 deletions
diff --git a/src/revocation/gnunet-service-revocation.c b/src/revocation/gnunet-service-revocation.c index a410f7b4e..7022098f7 100644 --- a/src/revocation/gnunet-service-revocation.c +++ b/src/revocation/gnunet-service-revocation.c | |||
@@ -31,10 +31,8 @@ | |||
31 | * peers that connect. | 31 | * peers that connect. |
32 | * | 32 | * |
33 | * TODO: | 33 | * TODO: |
34 | * - store revocations to disk | ||
35 | * - handle p2p revocations | 34 | * - handle p2p revocations |
36 | * - handle p2p connect (trigger SET union) | 35 | * - handle p2p connect (trigger SET union) |
37 | * - handle client revoke message | ||
38 | */ | 36 | */ |
39 | #include "platform.h" | 37 | #include "platform.h" |
40 | #include <math.h> | 38 | #include <math.h> |
@@ -192,7 +190,7 @@ handle_query_message (void *cls, | |||
192 | ? "Received revocation check for valid key `%s' from client\n" | 190 | ? "Received revocation check for valid key `%s' from client\n" |
193 | : "Received revocation check for revoked key `%s' from client\n", | 191 | : "Received revocation check for revoked key `%s' from client\n", |
194 | GNUNET_h2s (&hc)); | 192 | GNUNET_h2s (&hc)); |
195 | qrm.header.size = htons (sizeof (struct RevocationResponseMessage)); | 193 | qrm.header.size = htons (sizeof (struct QueryResponseMessage)); |
196 | qrm.header.type = htons (GNUNET_MESSAGE_TYPE_REVOCATION_QUERY_RESPONSE); | 194 | qrm.header.type = htons (GNUNET_MESSAGE_TYPE_REVOCATION_QUERY_RESPONSE); |
197 | qrm.is_valid = htons ((GNUNET_YES == res) ? GNUNET_NO : GNUNET_YES); | 195 | qrm.is_valid = htons ((GNUNET_YES == res) ? GNUNET_NO : GNUNET_YES); |
198 | GNUNET_SERVER_notification_context_add (nc, | 196 | GNUNET_SERVER_notification_context_add (nc, |
@@ -201,7 +199,102 @@ handle_query_message (void *cls, | |||
201 | client, | 199 | client, |
202 | &qrm.header, | 200 | &qrm.header, |
203 | GNUNET_NO); | 201 | GNUNET_NO); |
204 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 202 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
203 | } | ||
204 | |||
205 | |||
206 | /** | ||
207 | * Flood the given revocation message to all neighbours. | ||
208 | * | ||
209 | * @param cls the `struct RevokeMessage` to flood | ||
210 | * @param target a neighbour | ||
211 | * @param value our `struct PeerEntry` for the neighbour | ||
212 | * @return #GNUNET_OK (continue to iterate) | ||
213 | */ | ||
214 | static int | ||
215 | do_flood (void *cls, | ||
216 | const struct GNUNET_PeerIdentity *target, | ||
217 | void *value) | ||
218 | { | ||
219 | GNUNET_break (0); // FIXME: not implemented | ||
220 | return GNUNET_OK; | ||
221 | } | ||
222 | |||
223 | |||
224 | /** | ||
225 | * Publicize revocation message. Stores the message locally in the | ||
226 | * database and passes it to all connected neighbours (and adds it to | ||
227 | * the set for future connections). | ||
228 | * | ||
229 | * @param rm message to publicize | ||
230 | * @return #GNUNET_OK on success, #GNUNET_NO if we encountered an error, | ||
231 | * #GNUNET_SYSERR if the message was malformed | ||
232 | */ | ||
233 | static int | ||
234 | publicize_rm (const struct RevokeMessage *rm) | ||
235 | { | ||
236 | struct RevokeMessage *cp; | ||
237 | struct GNUNET_HashCode hc; | ||
238 | struct GNUNET_SET_Element e; | ||
239 | |||
240 | GNUNET_CRYPTO_hash (&rm->public_key, | ||
241 | sizeof (struct GNUNET_CRYPTO_EccPublicSignKey), | ||
242 | &hc); | ||
243 | if (GNUNET_YES == | ||
244 | GNUNET_CONTAINER_multihashmap_contains (revocation_map, | ||
245 | &hc)) | ||
246 | { | ||
247 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
248 | _("Duplicate revocation received from peer. Ignored.\n")); | ||
249 | return GNUNET_OK; | ||
250 | } | ||
251 | if (GNUNET_OK != | ||
252 | verify_revoke_message (rm)) | ||
253 | { | ||
254 | GNUNET_break_op (0); | ||
255 | return GNUNET_SYSERR; | ||
256 | } | ||
257 | /* write to disk */ | ||
258 | if (sizeof (struct RevokeMessage) != | ||
259 | GNUNET_DISK_file_write (revocation_db, | ||
260 | rm, | ||
261 | sizeof (struct RevokeMessage))) | ||
262 | { | ||
263 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, | ||
264 | "write"); | ||
265 | return GNUNET_NO; | ||
266 | } | ||
267 | if (GNUNET_OK != | ||
268 | GNUNET_DISK_file_sync (revocation_db)) | ||
269 | { | ||
270 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, | ||
271 | "sync"); | ||
272 | return GNUNET_NO; | ||
273 | } | ||
274 | /* keep copy in memory */ | ||
275 | cp = (struct RevokeMessage *) GNUNET_copy_message (&rm->header); | ||
276 | GNUNET_break (GNUNET_OK == | ||
277 | GNUNET_CONTAINER_multihashmap_put (revocation_map, | ||
278 | &hc, | ||
279 | cp, | ||
280 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
281 | /* add to set for future connections */ | ||
282 | e.size = htons (rm->header.size); | ||
283 | e.type = 0; | ||
284 | e.data = rm; | ||
285 | if (GNUNET_OK != | ||
286 | GNUNET_SET_add_element (revocation_set, | ||
287 | &e, | ||
288 | NULL, NULL)) | ||
289 | { | ||
290 | GNUNET_break (0); | ||
291 | return GNUNET_OK; | ||
292 | } | ||
293 | /* flood to neighbours */ | ||
294 | GNUNET_CONTAINER_multipeermap_iterate (peers, | ||
295 | &do_flood, | ||
296 | cp); | ||
297 | return GNUNET_OK; | ||
205 | } | 298 | } |
206 | 299 | ||
207 | 300 | ||
@@ -214,26 +307,25 @@ handle_query_message (void *cls, | |||
214 | */ | 307 | */ |
215 | static void | 308 | static void |
216 | handle_revoke_message (void *cls, | 309 | handle_revoke_message (void *cls, |
217 | struct GNUNET_SERVER_Client *client, | 310 | struct GNUNET_SERVER_Client *client, |
218 | const struct GNUNET_MessageHeader *message) | 311 | const struct GNUNET_MessageHeader *message) |
219 | { | 312 | { |
220 | const struct RevokeMessage *rm; | 313 | const struct RevokeMessage *rm; |
221 | struct RevocationResponseMessage rrm; | 314 | struct RevocationResponseMessage rrm; |
315 | int ret; | ||
222 | 316 | ||
223 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 317 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
224 | "Received REVOKE message from client\n"); | 318 | "Received REVOKE message from client\n"); |
225 | rm = (const struct RevokeMessage *) message; | 319 | rm = (const struct RevokeMessage *) message; |
226 | if (GNUNET_OK != | 320 | if (GNUNET_SYSERR == (ret = publicize_rm (rm))) |
227 | verify_revoke_message (rm)) | ||
228 | { | 321 | { |
229 | GNUNET_break (0); | 322 | GNUNET_break_op (0); |
230 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 323 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
324 | return; | ||
231 | } | 325 | } |
232 | GNUNET_break (0); // FIXME: TBD | ||
233 | |||
234 | rrm.header.size = htons (sizeof (struct RevocationResponseMessage)); | 326 | rrm.header.size = htons (sizeof (struct RevocationResponseMessage)); |
235 | rrm.header.type = htons (GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE_RESPONSE); | 327 | rrm.header.type = htons (GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE_RESPONSE); |
236 | rrm.is_valid = htons (GNUNET_NO); | 328 | rrm.is_valid = htons ((GNUNET_OK == ret) ? GNUNET_NO : GNUNET_YES); |
237 | GNUNET_SERVER_notification_context_add (nc, | 329 | GNUNET_SERVER_notification_context_add (nc, |
238 | client); | 330 | client); |
239 | GNUNET_SERVER_notification_context_unicast (nc, | 331 | GNUNET_SERVER_notification_context_unicast (nc, |
@@ -258,24 +350,10 @@ handle_p2p_revoke_message (void *cls, | |||
258 | { | 350 | { |
259 | const struct RevokeMessage *rm; | 351 | const struct RevokeMessage *rm; |
260 | 352 | ||
261 | |||
262 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 353 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
263 | "Received REVOKE message from peer\n"); | 354 | "Received REVOKE message from peer\n"); |
264 | rm = (const struct RevokeMessage *) message; | 355 | rm = (const struct RevokeMessage *) message; |
265 | if (GNUNET_OK != | 356 | GNUNET_break_op (GNUNET_SYSERR != publicize_rm (rm)); |
266 | verify_revoke_message (rm)) | ||
267 | { | ||
268 | GNUNET_break_op (0); | ||
269 | return GNUNET_SYSERR; | ||
270 | } | ||
271 | GNUNET_break (0); // FIXME: TBD | ||
272 | |||
273 | #if 0 | ||
274 | /* flood to rest */ | ||
275 | GNUNET_CONTAINER_multipeermap_iterate (peers, | ||
276 | &do_flood, | ||
277 | &ctx); | ||
278 | #endif | ||
279 | return GNUNET_OK; | 357 | return GNUNET_OK; |
280 | } | 358 | } |
281 | 359 | ||
@@ -301,6 +379,7 @@ handle_core_connect (void *cls, | |||
301 | GNUNET_CONTAINER_multipeermap_put (peers, peer, | 379 | GNUNET_CONTAINER_multipeermap_put (peers, peer, |
302 | peer_entry, | 380 | peer_entry, |
303 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 381 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
382 | GNUNET_break (0); // FIXME: implement revocation set union on connect! | ||
304 | #if 0 | 383 | #if 0 |
305 | peer_entry->transmit_task = | 384 | peer_entry->transmit_task = |
306 | GNUNET_SCHEDULER_add_delayed (get_transmit_delay (-1), &transmit_task_cb, | 385 | GNUNET_SCHEDULER_add_delayed (get_transmit_delay (-1), &transmit_task_cb, |