From f1ee15341aa2da62691269130c915f86c7644df8 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 6 Oct 2013 11:46:33 +0000 Subject: -store revocations to disk --- src/include/gnunet_disk_lib.h | 2 +- src/include/gnunet_set_service.h | 4 +- src/revocation/gnunet-service-revocation.c | 133 +++++++++++++++++++++++------ 3 files changed, 109 insertions(+), 30 deletions(-) (limited to 'src') diff --git a/src/include/gnunet_disk_lib.h b/src/include/gnunet_disk_lib.h index b5f0ccdda..0a3abce49 100644 --- a/src/include/gnunet_disk_lib.h +++ b/src/include/gnunet_disk_lib.h @@ -852,7 +852,7 @@ GNUNET_DISK_file_unmap (struct GNUNET_DISK_MapHandle *h); /** * Write file changes to disk * @param h handle to an open file - * @return GNUNET_OK on success, GNUNET_SYSERR otherwise + * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise */ int GNUNET_DISK_file_sync (const struct GNUNET_DISK_FileHandle *h); diff --git a/src/include/gnunet_set_service.h b/src/include/gnunet_set_service.h index b78e1850a..dbec108c2 100644 --- a/src/include/gnunet_set_service.h +++ b/src/include/gnunet_set_service.h @@ -242,8 +242,8 @@ GNUNET_SET_create (const struct GNUNET_CONFIGURATION_Handle *cfg, /** * Add an element to the given set. * After the element has been added (in the sense of being - * transmitted to the set service), cont will be called. - * Calls to add_element can be queued + * transmitted to the set service), @a cont will be called. + * Calls to #GNUNET_SET_add_element can be queued * * @param set set to add element to * @param element element to add to the set 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 @@ * peers that connect. * * TODO: - * - store revocations to disk * - handle p2p revocations * - handle p2p connect (trigger SET union) - * - handle client revoke message */ #include "platform.h" #include @@ -192,7 +190,7 @@ handle_query_message (void *cls, ? "Received revocation check for valid key `%s' from client\n" : "Received revocation check for revoked key `%s' from client\n", GNUNET_h2s (&hc)); - qrm.header.size = htons (sizeof (struct RevocationResponseMessage)); + qrm.header.size = htons (sizeof (struct QueryResponseMessage)); qrm.header.type = htons (GNUNET_MESSAGE_TYPE_REVOCATION_QUERY_RESPONSE); qrm.is_valid = htons ((GNUNET_YES == res) ? GNUNET_NO : GNUNET_YES); GNUNET_SERVER_notification_context_add (nc, @@ -201,7 +199,102 @@ handle_query_message (void *cls, client, &qrm.header, GNUNET_NO); - GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); + GNUNET_SERVER_receive_done (client, GNUNET_OK); +} + + +/** + * Flood the given revocation message to all neighbours. + * + * @param cls the `struct RevokeMessage` to flood + * @param target a neighbour + * @param value our `struct PeerEntry` for the neighbour + * @return #GNUNET_OK (continue to iterate) + */ +static int +do_flood (void *cls, + const struct GNUNET_PeerIdentity *target, + void *value) +{ + GNUNET_break (0); // FIXME: not implemented + return GNUNET_OK; +} + + +/** + * Publicize revocation message. Stores the message locally in the + * database and passes it to all connected neighbours (and adds it to + * the set for future connections). + * + * @param rm message to publicize + * @return #GNUNET_OK on success, #GNUNET_NO if we encountered an error, + * #GNUNET_SYSERR if the message was malformed + */ +static int +publicize_rm (const struct RevokeMessage *rm) +{ + struct RevokeMessage *cp; + struct GNUNET_HashCode hc; + struct GNUNET_SET_Element e; + + GNUNET_CRYPTO_hash (&rm->public_key, + sizeof (struct GNUNET_CRYPTO_EccPublicSignKey), + &hc); + if (GNUNET_YES == + GNUNET_CONTAINER_multihashmap_contains (revocation_map, + &hc)) + { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + _("Duplicate revocation received from peer. Ignored.\n")); + return GNUNET_OK; + } + if (GNUNET_OK != + verify_revoke_message (rm)) + { + GNUNET_break_op (0); + return GNUNET_SYSERR; + } + /* write to disk */ + if (sizeof (struct RevokeMessage) != + GNUNET_DISK_file_write (revocation_db, + rm, + sizeof (struct RevokeMessage))) + { + GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, + "write"); + return GNUNET_NO; + } + if (GNUNET_OK != + GNUNET_DISK_file_sync (revocation_db)) + { + GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, + "sync"); + return GNUNET_NO; + } + /* keep copy in memory */ + cp = (struct RevokeMessage *) GNUNET_copy_message (&rm->header); + GNUNET_break (GNUNET_OK == + GNUNET_CONTAINER_multihashmap_put (revocation_map, + &hc, + cp, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); + /* add to set for future connections */ + e.size = htons (rm->header.size); + e.type = 0; + e.data = rm; + if (GNUNET_OK != + GNUNET_SET_add_element (revocation_set, + &e, + NULL, NULL)) + { + GNUNET_break (0); + return GNUNET_OK; + } + /* flood to neighbours */ + GNUNET_CONTAINER_multipeermap_iterate (peers, + &do_flood, + cp); + return GNUNET_OK; } @@ -214,26 +307,25 @@ handle_query_message (void *cls, */ static void handle_revoke_message (void *cls, - struct GNUNET_SERVER_Client *client, - const struct GNUNET_MessageHeader *message) + struct GNUNET_SERVER_Client *client, + const struct GNUNET_MessageHeader *message) { const struct RevokeMessage *rm; struct RevocationResponseMessage rrm; + int ret; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received REVOKE message from client\n"); rm = (const struct RevokeMessage *) message; - if (GNUNET_OK != - verify_revoke_message (rm)) + if (GNUNET_SYSERR == (ret = publicize_rm (rm))) { - GNUNET_break (0); + GNUNET_break_op (0); GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); + return; } - GNUNET_break (0); // FIXME: TBD - rrm.header.size = htons (sizeof (struct RevocationResponseMessage)); rrm.header.type = htons (GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE_RESPONSE); - rrm.is_valid = htons (GNUNET_NO); + rrm.is_valid = htons ((GNUNET_OK == ret) ? GNUNET_NO : GNUNET_YES); GNUNET_SERVER_notification_context_add (nc, client); GNUNET_SERVER_notification_context_unicast (nc, @@ -258,24 +350,10 @@ handle_p2p_revoke_message (void *cls, { const struct RevokeMessage *rm; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received REVOKE message from peer\n"); rm = (const struct RevokeMessage *) message; - if (GNUNET_OK != - verify_revoke_message (rm)) - { - GNUNET_break_op (0); - return GNUNET_SYSERR; - } - GNUNET_break (0); // FIXME: TBD - -#if 0 - /* flood to rest */ - GNUNET_CONTAINER_multipeermap_iterate (peers, - &do_flood, - &ctx); -#endif + GNUNET_break_op (GNUNET_SYSERR != publicize_rm (rm)); return GNUNET_OK; } @@ -301,6 +379,7 @@ handle_core_connect (void *cls, GNUNET_CONTAINER_multipeermap_put (peers, peer, peer_entry, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); + GNUNET_break (0); // FIXME: implement revocation set union on connect! #if 0 peer_entry->transmit_task = GNUNET_SCHEDULER_add_delayed (get_transmit_delay (-1), &transmit_task_cb, -- cgit v1.2.3