From d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb Mon Sep 17 00:00:00 2001 From: ng0 Date: Sun, 8 Sep 2019 12:33:09 +0000 Subject: uncrustify as demanded. --- src/revocation/gnunet-revocation.c | 500 +++++++-------- src/revocation/gnunet-service-revocation.c | 985 +++++++++++++++-------------- src/revocation/plugin_block_revocation.c | 179 +++--- src/revocation/revocation.h | 20 +- src/revocation/revocation_api.c | 298 +++++---- src/revocation/test_revocation.c | 424 ++++++------- 6 files changed, 1198 insertions(+), 1208 deletions(-) (limited to 'src/revocation') diff --git a/src/revocation/gnunet-revocation.c b/src/revocation/gnunet-revocation.c index b5be65a5f..da93e6903 100644 --- a/src/revocation/gnunet-revocation.c +++ b/src/revocation/gnunet-revocation.c @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file revocation/gnunet-revocation.c @@ -91,23 +91,23 @@ static struct GNUNET_SCHEDULER_Task *pow_task; * @param cls closure */ static void -do_shutdown (void *cls) +do_shutdown(void *cls) { if (NULL != el) - { - GNUNET_IDENTITY_ego_lookup_cancel (el); - el = NULL; - } + { + GNUNET_IDENTITY_ego_lookup_cancel(el); + el = NULL; + } if (NULL != q) - { - GNUNET_REVOCATION_query_cancel (q); - q = NULL; - } + { + GNUNET_REVOCATION_query_cancel(q); + q = NULL; + } if (NULL != h) - { - GNUNET_REVOCATION_revoke_cancel (h); - h = NULL; - } + { + GNUNET_REVOCATION_revoke_cancel(h); + h = NULL; + } } @@ -118,25 +118,28 @@ do_shutdown (void *cls) * @param is_valid #GNUNET_YES if the key is still valid, #GNUNET_NO if not, #GNUNET_SYSERR on error */ static void -print_query_result (void *cls, int is_valid) +print_query_result(void *cls, int is_valid) { q = NULL; switch (is_valid) - { - case GNUNET_YES: - fprintf (stdout, _ ("Key `%s' is valid\n"), test_ego); - break; - case GNUNET_NO: - fprintf (stdout, _ ("Key `%s' has been revoked\n"), test_ego); - break; - case GNUNET_SYSERR: - fprintf (stdout, "%s", _ ("Internal error\n")); - break; - default: - GNUNET_break (0); - break; - } - GNUNET_SCHEDULER_shutdown (); + { + case GNUNET_YES: + fprintf(stdout, _("Key `%s' is valid\n"), test_ego); + break; + + case GNUNET_NO: + fprintf(stdout, _("Key `%s' has been revoked\n"), test_ego); + break; + + case GNUNET_SYSERR: + fprintf(stdout, "%s", _("Internal error\n")); + break; + + default: + GNUNET_break(0); + break; + } + GNUNET_SCHEDULER_shutdown(); } @@ -147,45 +150,47 @@ print_query_result (void *cls, int is_valid) * @param is_valid #GNUNET_YES if the key is still valid, #GNUNET_NO if not, #GNUNET_SYSERR on error */ static void -print_revocation_result (void *cls, int is_valid) +print_revocation_result(void *cls, int is_valid) { h = NULL; switch (is_valid) - { - case GNUNET_YES: - if (NULL != revoke_ego) - fprintf (stdout, - _ ("Key for ego `%s' is still valid, revocation failed (!)\n"), - revoke_ego); - else - fprintf (stdout, "%s", _ ("Revocation failed (!)\n")); - break; - case GNUNET_NO: - if (NULL != revoke_ego) - fprintf (stdout, - _ ("Key for ego `%s' has been successfully revoked\n"), - revoke_ego); - else - fprintf (stdout, "%s", _ ("Revocation successful.\n")); - break; - case GNUNET_SYSERR: - fprintf (stdout, - "%s", - _ ("Internal error, key revocation might have failed\n")); - break; - default: - GNUNET_break (0); - break; - } - GNUNET_SCHEDULER_shutdown (); + { + case GNUNET_YES: + if (NULL != revoke_ego) + fprintf(stdout, + _("Key for ego `%s' is still valid, revocation failed (!)\n"), + revoke_ego); + else + fprintf(stdout, "%s", _("Revocation failed (!)\n")); + break; + + case GNUNET_NO: + if (NULL != revoke_ego) + fprintf(stdout, + _("Key for ego `%s' has been successfully revoked\n"), + revoke_ego); + else + fprintf(stdout, "%s", _("Revocation successful.\n")); + break; + + case GNUNET_SYSERR: + fprintf(stdout, + "%s", + _("Internal error, key revocation might have failed\n")); + break; + + default: + GNUNET_break(0); + break; + } + GNUNET_SCHEDULER_shutdown(); } /** * Data needed to perform a revocation. */ -struct RevocationData -{ +struct RevocationData { /** * Public key. */ @@ -207,14 +212,14 @@ struct RevocationData * Perform the revocation. */ static void -perform_revocation (const struct RevocationData *rd) +perform_revocation(const struct RevocationData *rd) { - h = GNUNET_REVOCATION_revoke (cfg, - &rd->key, - &rd->sig, - rd->pow, - &print_revocation_result, - NULL); + h = GNUNET_REVOCATION_revoke(cfg, + &rd->key, + &rd->sig, + rd->pow, + &print_revocation_result, + NULL); } @@ -225,16 +230,16 @@ perform_revocation (const struct RevocationData *rd) * @param rd data to sync */ static void -sync_rd (const struct RevocationData *rd) +sync_rd(const struct RevocationData *rd) { if ((NULL != filename) && - (sizeof (struct RevocationData) == - GNUNET_DISK_fn_write (filename, - &rd, - sizeof (rd), - GNUNET_DISK_PERM_USER_READ | - GNUNET_DISK_PERM_USER_WRITE))) - GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "write", filename); + (sizeof(struct RevocationData) == + GNUNET_DISK_fn_write(filename, + &rd, + sizeof(rd), + GNUNET_DISK_PERM_USER_READ | + GNUNET_DISK_PERM_USER_WRITE))) + GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, "write", filename); } @@ -244,17 +249,17 @@ sync_rd (const struct RevocationData *rd) * @param cls the `struct RevocationData` */ static void -calculate_pow_shutdown (void *cls) +calculate_pow_shutdown(void *cls) { struct RevocationData *rd = cls; if (NULL != pow_task) - { - GNUNET_SCHEDULER_cancel (pow_task); - pow_task = NULL; - } - sync_rd (rd); - GNUNET_free (rd); + { + GNUNET_SCHEDULER_cancel(pow_task); + pow_task = NULL; + } + sync_rd(rd); + GNUNET_free(rd); } @@ -264,53 +269,53 @@ calculate_pow_shutdown (void *cls) * @param cls the `struct RevocationData` */ static void -calculate_pow (void *cls) +calculate_pow(void *cls) { struct RevocationData *rd = cls; /* store temporary results */ pow_task = NULL; if (0 == (rd->pow % 128)) - sync_rd (rd); + sync_rd(rd); /* display progress estimate */ if ((0 == ((1 << matching_bits) / 100 / 50)) || (0 == (rd->pow % ((1 << matching_bits) / 100 / 50)))) - fprintf (stderr, "%s", "."); + fprintf(stderr, "%s", "."); if ((0 != rd->pow) && ((0 == ((1 << matching_bits) / 100)) || (0 == (rd->pow % ((1 << matching_bits) / 100))))) - fprintf (stderr, - " - @ %3u%% (estimate)\n", - (unsigned int) (rd->pow * 100) / (1 << matching_bits)); + fprintf(stderr, + " - @ %3u%% (estimate)\n", + (unsigned int)(rd->pow * 100) / (1 << matching_bits)); /* actually do POW calculation */ rd->pow++; - if (GNUNET_OK == GNUNET_REVOCATION_check_pow (&rd->key, - rd->pow, - (unsigned int) matching_bits)) - { - if ((NULL != filename) && - (sizeof (struct RevocationData) != - GNUNET_DISK_fn_write (filename, - rd, - sizeof (struct RevocationData), - GNUNET_DISK_PERM_USER_READ | - GNUNET_DISK_PERM_USER_WRITE))) - GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "write", filename); - if (perform) + if (GNUNET_OK == GNUNET_REVOCATION_check_pow(&rd->key, + rd->pow, + (unsigned int)matching_bits)) { - perform_revocation (rd); - } - else - { - fprintf (stderr, "%s", "\n"); - fprintf (stderr, - _ ("Revocation certificate for `%s' stored in `%s'\n"), - revoke_ego, - filename); - GNUNET_SCHEDULER_shutdown (); + if ((NULL != filename) && + (sizeof(struct RevocationData) != + GNUNET_DISK_fn_write(filename, + rd, + sizeof(struct RevocationData), + GNUNET_DISK_PERM_USER_READ | + GNUNET_DISK_PERM_USER_WRITE))) + GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, "write", filename); + if (perform) + { + perform_revocation(rd); + } + else + { + fprintf(stderr, "%s", "\n"); + fprintf(stderr, + _("Revocation certificate for `%s' stored in `%s'\n"), + revoke_ego, + filename); + GNUNET_SCHEDULER_shutdown(); + } + return; } - return; - } - pow_task = GNUNET_SCHEDULER_add_now (&calculate_pow, rd); + pow_task = GNUNET_SCHEDULER_add_now(&calculate_pow, rd); } @@ -321,57 +326,57 @@ calculate_pow (void *cls) * @param ego the ego, NULL if not found */ static void -ego_callback (void *cls, const struct GNUNET_IDENTITY_Ego *ego) +ego_callback(void *cls, const struct GNUNET_IDENTITY_Ego *ego) { struct RevocationData *rd; struct GNUNET_CRYPTO_EcdsaPublicKey key; el = NULL; if (NULL == ego) - { - fprintf (stdout, _ ("Ego `%s' not found.\n"), revoke_ego); - GNUNET_SCHEDULER_shutdown (); - return; - } - GNUNET_IDENTITY_ego_get_public_key (ego, &key); - rd = GNUNET_new (struct RevocationData); - if ((NULL != filename) && (GNUNET_YES == GNUNET_DISK_file_test (filename)) && - (sizeof (struct RevocationData) == - GNUNET_DISK_fn_read (filename, rd, sizeof (struct RevocationData)))) - { - if (0 != GNUNET_memcmp (&rd->key, &key)) { - fprintf (stderr, - _ ("Error: revocation certificate in `%s' is not for `%s'\n"), - filename, - revoke_ego); - GNUNET_free (rd); + fprintf(stdout, _("Ego `%s' not found.\n"), revoke_ego); + GNUNET_SCHEDULER_shutdown(); return; } - } + GNUNET_IDENTITY_ego_get_public_key(ego, &key); + rd = GNUNET_new(struct RevocationData); + if ((NULL != filename) && (GNUNET_YES == GNUNET_DISK_file_test(filename)) && + (sizeof(struct RevocationData) == + GNUNET_DISK_fn_read(filename, rd, sizeof(struct RevocationData)))) + { + if (0 != GNUNET_memcmp(&rd->key, &key)) + { + fprintf(stderr, + _("Error: revocation certificate in `%s' is not for `%s'\n"), + filename, + revoke_ego); + GNUNET_free(rd); + return; + } + } else - { - GNUNET_REVOCATION_sign_revocation (GNUNET_IDENTITY_ego_get_private_key ( - ego), - &rd->sig); - rd->key = key; - } + { + GNUNET_REVOCATION_sign_revocation(GNUNET_IDENTITY_ego_get_private_key( + ego), + &rd->sig); + rd->key = key; + } if (GNUNET_YES == - GNUNET_REVOCATION_check_pow (&key, rd->pow, (unsigned int) matching_bits)) - { - fprintf (stderr, "%s", _ ("Revocation certificate ready\n")); - if (perform) - perform_revocation (rd); - else - GNUNET_SCHEDULER_shutdown (); - GNUNET_free (rd); - return; - } - fprintf (stderr, - "%s", - _ ("Revocation certificate not ready, calculating proof of work\n")); - pow_task = GNUNET_SCHEDULER_add_now (&calculate_pow, rd); - GNUNET_SCHEDULER_add_shutdown (&calculate_pow_shutdown, rd); + GNUNET_REVOCATION_check_pow(&key, rd->pow, (unsigned int)matching_bits)) + { + fprintf(stderr, "%s", _("Revocation certificate ready\n")); + if (perform) + perform_revocation(rd); + else + GNUNET_SCHEDULER_shutdown(); + GNUNET_free(rd); + return; + } + fprintf(stderr, + "%s", + _("Revocation certificate not ready, calculating proof of work\n")); + pow_task = GNUNET_SCHEDULER_add_now(&calculate_pow, rd); + GNUNET_SCHEDULER_add_shutdown(&calculate_pow_shutdown, rd); } @@ -384,85 +389,85 @@ ego_callback (void *cls, const struct GNUNET_IDENTITY_Ego *ego) * @param c configuration */ static void -run (void *cls, - char *const *args, - const char *cfgfile, - const struct GNUNET_CONFIGURATION_Handle *c) +run(void *cls, + char *const *args, + const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *c) { struct GNUNET_CRYPTO_EcdsaPublicKey pk; struct RevocationData rd; cfg = c; if (NULL != test_ego) - { - if (GNUNET_OK != - GNUNET_CRYPTO_ecdsa_public_key_from_string (test_ego, - strlen (test_ego), - &pk)) { - fprintf (stderr, _ ("Public key `%s' malformed\n"), test_ego); + if (GNUNET_OK != + GNUNET_CRYPTO_ecdsa_public_key_from_string(test_ego, + strlen(test_ego), + &pk)) + { + fprintf(stderr, _("Public key `%s' malformed\n"), test_ego); + return; + } + GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL); + q = GNUNET_REVOCATION_query(cfg, &pk, &print_query_result, NULL); + if (NULL != revoke_ego) + fprintf( + stderr, + "%s", + _( + "Testing and revoking at the same time is not allowed, only executing test.\n")); return; } - GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); - q = GNUNET_REVOCATION_query (cfg, &pk, &print_query_result, NULL); - if (NULL != revoke_ego) - fprintf ( - stderr, - "%s", - _ ( - "Testing and revoking at the same time is not allowed, only executing test.\n")); - return; - } - if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, - "REVOCATION", - "WORKBITS", - &matching_bits)) - { - GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, - "REVOCATION", - "WORKBITS"); - return; - } - if (NULL != revoke_ego) - { - if (! perform && (NULL == filename)) + if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(cfg, + "REVOCATION", + "WORKBITS", + &matching_bits)) { - fprintf (stderr, - "%s", - _ ("No filename to store revocation certificate given.\n")); + GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, + "REVOCATION", + "WORKBITS"); return; } - /* main code here */ - el = GNUNET_IDENTITY_ego_lookup (cfg, revoke_ego, &ego_callback, NULL); - GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); - return; - } - if ((NULL != filename) && (perform)) - { - if (sizeof (rd) != GNUNET_DISK_fn_read (filename, &rd, sizeof (rd))) + if (NULL != revoke_ego) { - fprintf (stderr, - _ ("Failed to read revocation certificate from `%s'\n"), - filename); + if (!perform && (NULL == filename)) + { + fprintf(stderr, + "%s", + _("No filename to store revocation certificate given.\n")); + return; + } + /* main code here */ + el = GNUNET_IDENTITY_ego_lookup(cfg, revoke_ego, &ego_callback, NULL); + GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL); return; } - GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); - if (GNUNET_YES != - GNUNET_REVOCATION_check_pow (&rd.key, - rd.pow, - (unsigned int) matching_bits)) + if ((NULL != filename) && (perform)) { - struct RevocationData *cp = GNUNET_new (struct RevocationData); - - *cp = rd; - pow_task = GNUNET_SCHEDULER_add_now (&calculate_pow, cp); - GNUNET_SCHEDULER_add_shutdown (&calculate_pow_shutdown, cp); + if (sizeof(rd) != GNUNET_DISK_fn_read(filename, &rd, sizeof(rd))) + { + fprintf(stderr, + _("Failed to read revocation certificate from `%s'\n"), + filename); + return; + } + GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL); + if (GNUNET_YES != + GNUNET_REVOCATION_check_pow(&rd.key, + rd.pow, + (unsigned int)matching_bits)) + { + struct RevocationData *cp = GNUNET_new(struct RevocationData); + + *cp = rd; + pow_task = GNUNET_SCHEDULER_add_now(&calculate_pow, cp); + GNUNET_SCHEDULER_add_shutdown(&calculate_pow_shutdown, cp); + return; + } + perform_revocation(&rd); return; } - perform_revocation (&rd); - return; - } - fprintf (stderr, "%s", _ ("No action specified. Nothing to do.\n")); + fprintf(stderr, "%s", _("No action specified. Nothing to do.\n")); } @@ -474,53 +479,54 @@ run (void *cls, * @return 0 ok, 1 on error */ int -main (int argc, char *const *argv) +main(int argc, char *const *argv) { struct GNUNET_GETOPT_CommandLineOption options[] = { - - GNUNET_GETOPT_option_string ('f', - "filename", - "NAME", - gettext_noop ( - "use NAME for the name of the revocation file"), - &filename), - - GNUNET_GETOPT_option_string ( + GNUNET_GETOPT_option_string('f', + "filename", + "NAME", + gettext_noop( + "use NAME for the name of the revocation file"), + &filename), + + GNUNET_GETOPT_option_string( 'R', "revoke", "NAME", - gettext_noop ( + gettext_noop( "revoke the private key associated for the the private key associated with the ego NAME "), &revoke_ego), - GNUNET_GETOPT_option_flag ( + GNUNET_GETOPT_option_flag( 'p', "perform", - gettext_noop ( + gettext_noop( "actually perform revocation, otherwise we just do the precomputation"), &perform), - GNUNET_GETOPT_option_string ('t', - "test", - "KEY", - gettext_noop ( - "test if the public key KEY has been revoked"), - &test_ego), + GNUNET_GETOPT_option_string('t', + "test", + "KEY", + gettext_noop( + "test if the public key KEY has been revoked"), + &test_ego), + + GNUNET_GETOPT_OPTION_END + }; - GNUNET_GETOPT_OPTION_END}; - if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) + if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) return 2; - ret = (GNUNET_OK == GNUNET_PROGRAM_run (argc, - argv, - "gnunet-revocation", - gettext_noop ("help text"), - options, - &run, - NULL)) - ? ret - : 1; - GNUNET_free ((void *) argv); + ret = (GNUNET_OK == GNUNET_PROGRAM_run(argc, + argv, + "gnunet-revocation", + gettext_noop("help text"), + options, + &run, + NULL)) + ? ret + : 1; + GNUNET_free((void *)argv); return ret; } diff --git a/src/revocation/gnunet-service-revocation.c b/src/revocation/gnunet-service-revocation.c index e4ea1f2ff..62be5a96b 100644 --- a/src/revocation/gnunet-service-revocation.c +++ b/src/revocation/gnunet-service-revocation.c @@ -1,19 +1,19 @@ /* - This file is part of GNUnet. - Copyright (C) 2013, 2014, 2016 GNUnet e.V. - - GNUnet is free software: you can redistribute it and/or modify it - under the terms of the GNU Affero General Public License as published - by the Free Software Foundation, either version 3 of the License, - or (at your option) any later version. - - GNUnet is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . + This file is part of GNUnet. + Copyright (C) 2013, 2014, 2016 GNUnet e.V. + + GNUnet is free software: you can redistribute it and/or modify it + under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, + or (at your option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later */ @@ -53,9 +53,7 @@ /** * Per-peer information. */ -struct PeerEntry -{ - +struct PeerEntry { /** * Queue for sending messages to this peer. */ @@ -75,7 +73,6 @@ struct PeerEntry * Handle to active set union operation (over revocation sets). */ struct GNUNET_SET_OperationHandle *so; - }; @@ -148,13 +145,13 @@ new_peer_entry(const struct GNUNET_PeerIdentity *peer) { struct PeerEntry *peer_entry; - peer_entry = GNUNET_new (struct PeerEntry); + peer_entry = GNUNET_new(struct PeerEntry); peer_entry->id = *peer; - GNUNET_assert (GNUNET_OK == - GNUNET_CONTAINER_multipeermap_put (peers, - &peer_entry->id, - peer_entry, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); + GNUNET_assert(GNUNET_OK == + GNUNET_CONTAINER_multipeermap_put(peers, + &peer_entry->id, + peer_entry, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); return peer_entry; } @@ -167,27 +164,27 @@ new_peer_entry(const struct GNUNET_PeerIdentity *peer) * #GNUNET_NO if the key/signature don't verify */ static int -verify_revoke_message (const struct RevokeMessage *rm) +verify_revoke_message(const struct RevokeMessage *rm) { if (GNUNET_YES != - GNUNET_REVOCATION_check_pow (&rm->public_key, - rm->proof_of_work, - (unsigned int) revocation_work_required)) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Proof of work invalid!\n"); - GNUNET_break_op (0); - return GNUNET_NO; - } + GNUNET_REVOCATION_check_pow(&rm->public_key, + rm->proof_of_work, + (unsigned int)revocation_work_required)) + { + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Proof of work invalid!\n"); + GNUNET_break_op(0); + return GNUNET_NO; + } if (GNUNET_OK != - GNUNET_CRYPTO_ecdsa_verify (GNUNET_SIGNATURE_PURPOSE_REVOCATION, - &rm->purpose, - &rm->signature, - &rm->public_key)) - { - GNUNET_break_op (0); - return GNUNET_NO; - } + GNUNET_CRYPTO_ecdsa_verify(GNUNET_SIGNATURE_PURPOSE_REVOCATION, + &rm->purpose, + &rm->signature, + &rm->public_key)) + { + GNUNET_break_op(0); + return GNUNET_NO; + } return GNUNET_YES; } @@ -201,9 +198,9 @@ verify_revoke_message (const struct RevokeMessage *rm) * @return @a client */ static void * -client_connect_cb (void *cls, - struct GNUNET_SERVICE_Client *client, - struct GNUNET_MQ_Handle *mq) +client_connect_cb(void *cls, + struct GNUNET_SERVICE_Client *client, + struct GNUNET_MQ_Handle *mq) { return client; } @@ -217,11 +214,11 @@ client_connect_cb (void *cls, * @param app_cls must alias @a client */ static void -client_disconnect_cb (void *cls, - struct GNUNET_SERVICE_Client *client, - void *app_cls) +client_disconnect_cb(void *cls, + struct GNUNET_SERVICE_Client *client, + void *app_cls) { - GNUNET_assert (client == app_cls); + GNUNET_assert(client == app_cls); } @@ -232,8 +229,8 @@ client_disconnect_cb (void *cls, * @param qm the message received */ static void -handle_query_message (void *cls, - const struct QueryMessage *qm) +handle_query_message(void *cls, + const struct QueryMessage *qm) { struct GNUNET_SERVICE_Client *client = cls; struct GNUNET_MQ_Envelope *env; @@ -241,22 +238,22 @@ handle_query_message (void *cls, struct GNUNET_HashCode hc; int res; - GNUNET_CRYPTO_hash (&qm->key, - sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey), - &hc); - res = GNUNET_CONTAINER_multihashmap_contains (revocation_map, - &hc); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - (GNUNET_NO == res) - ? "Received revocation check for valid key `%s' from client\n" - : "Received revocation check for revoked key `%s' from client\n", - GNUNET_h2s (&hc)); - env = GNUNET_MQ_msg (qrm, - GNUNET_MESSAGE_TYPE_REVOCATION_QUERY_RESPONSE); - qrm->is_valid = htonl ((GNUNET_YES == res) ? GNUNET_NO : GNUNET_YES); - GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), - env); - GNUNET_SERVICE_client_continue (client); + GNUNET_CRYPTO_hash(&qm->key, + sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey), + &hc); + res = GNUNET_CONTAINER_multihashmap_contains(revocation_map, + &hc); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + (GNUNET_NO == res) + ? "Received revocation check for valid key `%s' from client\n" + : "Received revocation check for revoked key `%s' from client\n", + GNUNET_h2s(&hc)); + env = GNUNET_MQ_msg(qrm, + GNUNET_MESSAGE_TYPE_REVOCATION_QUERY_RESPONSE); + qrm->is_valid = htonl((GNUNET_YES == res) ? GNUNET_NO : GNUNET_YES); + GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), + env); + GNUNET_SERVICE_client_continue(client); } @@ -269,9 +266,9 @@ handle_query_message (void *cls, * @return #GNUNET_OK (continue to iterate) */ static int -do_flood (void *cls, - const struct GNUNET_PeerIdentity *target, - void *value) +do_flood(void *cls, + const struct GNUNET_PeerIdentity *target, + void *value) { const struct RevokeMessage *rm = cls; struct PeerEntry *pe = value; @@ -280,16 +277,16 @@ do_flood (void *cls, if (NULL == pe->mq) return GNUNET_OK; /* peer connected to us via SET, - but we have no direct CORE - connection for flooding */ - e = GNUNET_MQ_msg (cp, - GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE); + but we have no direct CORE + connection for flooding */ + e = GNUNET_MQ_msg(cp, + GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE); *cp = *rm; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Flooding revocation to `%s'\n", - GNUNET_i2s (target)); - GNUNET_MQ_send (pe->mq, - e); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Flooding revocation to `%s'\n", + GNUNET_i2s(target)); + GNUNET_MQ_send(pe->mq, + e); return GNUNET_OK; } @@ -304,75 +301,75 @@ do_flood (void *cls, * #GNUNET_SYSERR if the message was malformed */ static int -publicize_rm (const struct RevokeMessage *rm) +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_EcdsaPublicKey), - &hc); + GNUNET_CRYPTO_hash(&rm->public_key, + sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey), + &hc); if (GNUNET_YES == - GNUNET_CONTAINER_multihashmap_contains (revocation_map, - &hc)) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Duplicate revocation received from peer. Ignored.\n"); - return GNUNET_OK; - } + GNUNET_CONTAINER_multihashmap_contains(revocation_map, + &hc)) + { + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Duplicate revocation received from peer. Ignored.\n"); + return GNUNET_OK; + } if (GNUNET_OK != - verify_revoke_message (rm)) - { - GNUNET_break_op (0); - return GNUNET_SYSERR; - } + 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 (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; - } + 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)); + 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.size = htons(rm->header.size); e.element_type = GNUNET_BLOCK_TYPE_REVOCATION; e.data = rm; if (GNUNET_OK != - GNUNET_SET_add_element (revocation_set, - &e, - NULL, - NULL)) - { - GNUNET_break (0); - return GNUNET_OK; - } + GNUNET_SET_add_element(revocation_set, + &e, + NULL, + NULL)) + { + GNUNET_break(0); + return GNUNET_OK; + } else - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Added revocation info to SET\n"); - } + { + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Added revocation info to SET\n"); + } /* flood to neighbours */ - GNUNET_CONTAINER_multipeermap_iterate (peers, - &do_flood, - cp); + GNUNET_CONTAINER_multipeermap_iterate(peers, + &do_flood, + cp); return GNUNET_OK; } @@ -384,28 +381,28 @@ publicize_rm (const struct RevokeMessage *rm) * @param rm the message received */ static void -handle_revoke_message (void *cls, - const struct RevokeMessage *rm) +handle_revoke_message(void *cls, + const struct RevokeMessage *rm) { struct GNUNET_SERVICE_Client *client = cls; struct GNUNET_MQ_Envelope *env; struct RevocationResponseMessage *rrm; int ret; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received REVOKE message from client\n"); - if (GNUNET_SYSERR == (ret = publicize_rm (rm))) - { - GNUNET_break_op (0); - GNUNET_SERVICE_client_drop (client); - return; - } - env = GNUNET_MQ_msg (rrm, - GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE_RESPONSE); - rrm->is_valid = htonl ((GNUNET_OK == ret) ? GNUNET_NO : GNUNET_YES); - GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), - env); - GNUNET_SERVICE_client_continue (client); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Received REVOKE message from client\n"); + if (GNUNET_SYSERR == (ret = publicize_rm(rm))) + { + GNUNET_break_op(0); + GNUNET_SERVICE_client_drop(client); + return; + } + env = GNUNET_MQ_msg(rrm, + GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE_RESPONSE); + rrm->is_valid = htonl((GNUNET_OK == ret) ? GNUNET_NO : GNUNET_YES); + GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), + env); + GNUNET_SERVICE_client_continue(client); } @@ -416,13 +413,13 @@ handle_revoke_message (void *cls, * @param rm revocation message */ static void -handle_p2p_revoke (void *cls, - const struct RevokeMessage *rm) +handle_p2p_revoke(void *cls, + const struct RevokeMessage *rm) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received REVOKE message\n"); - GNUNET_break_op (GNUNET_SYSERR != - publicize_rm (rm)); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Received REVOKE message\n"); + GNUNET_break_op(GNUNET_SYSERR != + publicize_rm(rm)); } @@ -437,60 +434,64 @@ handle_p2p_revoke (void *cls, * @param status see `enum GNUNET_SET_Status` */ static void -add_revocation (void *cls, - const struct GNUNET_SET_Element *element, - uint64_t current_size, - enum GNUNET_SET_Status status) +add_revocation(void *cls, + const struct GNUNET_SET_Element *element, + uint64_t current_size, + enum GNUNET_SET_Status status) { struct PeerEntry *peer_entry = cls; const struct RevokeMessage *rm; switch (status) - { - case GNUNET_SET_STATUS_OK: - if (element->size != sizeof (struct RevokeMessage)) { - GNUNET_break_op (0); - return; + case GNUNET_SET_STATUS_OK: + if (element->size != sizeof(struct RevokeMessage)) + { + GNUNET_break_op(0); + return; + } + if (GNUNET_BLOCK_TYPE_REVOCATION != element->element_type) + { + GNUNET_STATISTICS_update(stats, + gettext_noop("# unsupported revocations received via set union"), + 1, + GNUNET_NO); + return; + } + rm = element->data; + (void)handle_p2p_revoke(NULL, + rm); + GNUNET_STATISTICS_update(stats, + gettext_noop("# revocation messages received via set union"), + 1, GNUNET_NO); + break; + + case GNUNET_SET_STATUS_FAILURE: + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, + _("Error computing revocation set union with %s\n"), + GNUNET_i2s(&peer_entry->id)); + peer_entry->so = NULL; + GNUNET_STATISTICS_update(stats, + gettext_noop("# revocation set unions failed"), + 1, + GNUNET_NO); + break; + + case GNUNET_SET_STATUS_HALF_DONE: + break; + + case GNUNET_SET_STATUS_DONE: + peer_entry->so = NULL; + GNUNET_STATISTICS_update(stats, + gettext_noop("# revocation set unions completed"), + 1, + GNUNET_NO); + break; + + default: + GNUNET_break(0); + break; } - if (GNUNET_BLOCK_TYPE_REVOCATION != element->element_type) - { - GNUNET_STATISTICS_update (stats, - gettext_noop ("# unsupported revocations received via set union"), - 1, - GNUNET_NO); - return; - } - rm = element->data; - (void) handle_p2p_revoke (NULL, - rm); - GNUNET_STATISTICS_update (stats, - gettext_noop ("# revocation messages received via set union"), - 1, GNUNET_NO); - break; - case GNUNET_SET_STATUS_FAILURE: - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _("Error computing revocation set union with %s\n"), - GNUNET_i2s (&peer_entry->id)); - peer_entry->so = NULL; - GNUNET_STATISTICS_update (stats, - gettext_noop ("# revocation set unions failed"), - 1, - GNUNET_NO); - break; - case GNUNET_SET_STATUS_HALF_DONE: - break; - case GNUNET_SET_STATUS_DONE: - peer_entry->so = NULL; - GNUNET_STATISTICS_update (stats, - gettext_noop ("# revocation set unions completed"), - 1, - GNUNET_NO); - break; - default: - GNUNET_break (0); - break; - } } @@ -501,31 +502,31 @@ add_revocation (void *cls, * @param cls NULL */ static void -transmit_task_cb (void *cls) +transmit_task_cb(void *cls) { struct PeerEntry *peer_entry = cls; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Starting set exchange with peer `%s'\n", - GNUNET_i2s (&peer_entry->id)); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Starting set exchange with peer `%s'\n", + GNUNET_i2s(&peer_entry->id)); peer_entry->transmit_task = NULL; - GNUNET_assert (NULL == peer_entry->so); - peer_entry->so = GNUNET_SET_prepare (&peer_entry->id, - &revocation_set_union_app_id, - NULL, - GNUNET_SET_RESULT_ADDED, - (struct GNUNET_SET_Option[]) {{ 0 }}, - &add_revocation, - peer_entry); + GNUNET_assert(NULL == peer_entry->so); + peer_entry->so = GNUNET_SET_prepare(&peer_entry->id, + &revocation_set_union_app_id, + NULL, + GNUNET_SET_RESULT_ADDED, + (struct GNUNET_SET_Option[]) { { 0 } }, + &add_revocation, + peer_entry); if (GNUNET_OK != - GNUNET_SET_commit (peer_entry->so, - revocation_set)) - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _("SET service crashed, terminating revocation service\n")); - GNUNET_SCHEDULER_shutdown (); - return; - } + GNUNET_SET_commit(peer_entry->so, + revocation_set)) + { + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, + _("SET service crashed, terminating revocation service\n")); + GNUNET_SCHEDULER_shutdown(); + return; + } } @@ -537,57 +538,57 @@ transmit_task_cb (void *cls) * @param peer peer identity this notification is about */ static void * -handle_core_connect (void *cls, - const struct GNUNET_PeerIdentity *peer, - struct GNUNET_MQ_Handle *mq) +handle_core_connect(void *cls, + const struct GNUNET_PeerIdentity *peer, + struct GNUNET_MQ_Handle *mq) { struct PeerEntry *peer_entry; struct GNUNET_HashCode my_hash; struct GNUNET_HashCode peer_hash; - if (0 == GNUNET_memcmp (peer, - &my_identity)) - { - return NULL; - } - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Peer `%s' connected to us\n", - GNUNET_i2s (peer)); - GNUNET_STATISTICS_update (stats, - "# peers connected", - 1, - GNUNET_NO); - peer_entry = GNUNET_CONTAINER_multipeermap_get (peers, - peer); + if (0 == GNUNET_memcmp(peer, + &my_identity)) + { + return NULL; + } + + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Peer `%s' connected to us\n", + GNUNET_i2s(peer)); + GNUNET_STATISTICS_update(stats, + "# peers connected", + 1, + GNUNET_NO); + peer_entry = GNUNET_CONTAINER_multipeermap_get(peers, + peer); if (NULL != peer_entry) - { - /* This can happen if "core"'s notification is a tad late - and CADET+SET were faster and already produced a + { + /* This can happen if "core"'s notification is a tad late + and CADET+SET were faster and already produced a #handle_revocation_union_request() for us to deal - with. This should be rare, but isn't impossible. */ - peer_entry->mq = mq; - return peer_entry; - } - peer_entry = new_peer_entry (peer); + with. This should be rare, but isn't impossible. */ + peer_entry->mq = mq; + return peer_entry; + } + peer_entry = new_peer_entry(peer); peer_entry->mq = mq; - GNUNET_CRYPTO_hash (&my_identity, - sizeof (my_identity), - &my_hash); - GNUNET_CRYPTO_hash (peer, - sizeof (*peer), - &peer_hash); - if (0 < GNUNET_CRYPTO_hash_cmp (&my_hash, - &peer_hash)) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Starting SET operation with peer `%s'\n", - GNUNET_i2s (peer)); - peer_entry->transmit_task = - GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, - &transmit_task_cb, - peer_entry); - } + GNUNET_CRYPTO_hash(&my_identity, + sizeof(my_identity), + &my_hash); + GNUNET_CRYPTO_hash(peer, + sizeof(*peer), + &peer_hash); + if (0 < GNUNET_CRYPTO_hash_cmp(&my_hash, + &peer_hash)) + { + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Starting SET operation with peer `%s'\n", + GNUNET_i2s(peer)); + peer_entry->transmit_task = + GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, + &transmit_task_cb, + peer_entry); + } return peer_entry; } @@ -601,38 +602,38 @@ handle_core_connect (void *cls, * @param internal_cls our `struct PeerEntry` for this peer */ static void -handle_core_disconnect (void *cls, - const struct GNUNET_PeerIdentity *peer, - void *internal_cls) +handle_core_disconnect(void *cls, + const struct GNUNET_PeerIdentity *peer, + void *internal_cls) { struct PeerEntry *peer_entry = internal_cls; - if (0 == GNUNET_memcmp (peer, - &my_identity)) + if (0 == GNUNET_memcmp(peer, + &my_identity)) return; - GNUNET_assert (NULL != peer_entry); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Peer `%s' disconnected from us\n", - GNUNET_i2s (peer)); - GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multipeermap_remove (peers, - peer, - peer_entry)); + GNUNET_assert(NULL != peer_entry); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Peer `%s' disconnected from us\n", + GNUNET_i2s(peer)); + GNUNET_assert(GNUNET_YES == + GNUNET_CONTAINER_multipeermap_remove(peers, + peer, + peer_entry)); if (NULL != peer_entry->transmit_task) - { - GNUNET_SCHEDULER_cancel (peer_entry->transmit_task); - peer_entry->transmit_task = NULL; - } + { + GNUNET_SCHEDULER_cancel(peer_entry->transmit_task); + peer_entry->transmit_task = NULL; + } if (NULL != peer_entry->so) - { - GNUNET_SET_operation_cancel (peer_entry->so); - peer_entry->so = NULL; - } - GNUNET_free (peer_entry); - GNUNET_STATISTICS_update (stats, - "# peers connected", - -1, - GNUNET_NO); + { + GNUNET_SET_operation_cancel(peer_entry->so); + peer_entry->so = NULL; + } + GNUNET_free(peer_entry); + GNUNET_STATISTICS_update(stats, + "# peers connected", + -1, + GNUNET_NO); } @@ -645,11 +646,11 @@ handle_core_disconnect (void *cls, * @return #GNUNET_OK (continue to iterate) */ static int -free_entry (void *cls, - const struct GNUNET_HashCode *key, - void *value) +free_entry(void *cls, + const struct GNUNET_HashCode *key, + void *value) { - GNUNET_free (value); + GNUNET_free(value); return GNUNET_OK; } @@ -660,42 +661,42 @@ free_entry (void *cls, * @param cls unused */ static void -shutdown_task (void *cls) +shutdown_task(void *cls) { if (NULL != revocation_set) - { - GNUNET_SET_destroy (revocation_set); - revocation_set = NULL; - } + { + GNUNET_SET_destroy(revocation_set); + revocation_set = NULL; + } if (NULL != revocation_union_listen_handle) - { - GNUNET_SET_listen_cancel (revocation_union_listen_handle); - revocation_union_listen_handle = NULL; - } + { + GNUNET_SET_listen_cancel(revocation_union_listen_handle); + revocation_union_listen_handle = NULL; + } if (NULL != core_api) - { - GNUNET_CORE_disconnect (core_api); - core_api = NULL; - } + { + GNUNET_CORE_disconnect(core_api); + core_api = NULL; + } if (NULL != stats) - { - GNUNET_STATISTICS_destroy (stats, GNUNET_NO); - stats = NULL; - } + { + GNUNET_STATISTICS_destroy(stats, GNUNET_NO); + stats = NULL; + } if (NULL != peers) - { - GNUNET_CONTAINER_multipeermap_destroy (peers); - peers = NULL; - } + { + GNUNET_CONTAINER_multipeermap_destroy(peers); + peers = NULL; + } if (NULL != revocation_db) - { - GNUNET_DISK_file_close (revocation_db); - revocation_db = NULL; - } - GNUNET_CONTAINER_multihashmap_iterate (revocation_map, - &free_entry, - NULL); - GNUNET_CONTAINER_multihashmap_destroy (revocation_map); + { + GNUNET_DISK_file_close(revocation_db); + revocation_db = NULL; + } + GNUNET_CONTAINER_multihashmap_iterate(revocation_map, + &free_entry, + NULL); + GNUNET_CONTAINER_multihashmap_destroy(revocation_map); } @@ -706,16 +707,16 @@ shutdown_task (void *cls) * @param identity the public identity of this peer */ static void -core_init (void *cls, - const struct GNUNET_PeerIdentity *identity) +core_init(void *cls, + const struct GNUNET_PeerIdentity *identity) { if (NULL == identity) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Connection to core FAILED!\n"); - GNUNET_SCHEDULER_shutdown (); - return; - } + { + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + "Connection to core FAILED!\n"); + GNUNET_SCHEDULER_shutdown(); + return; + } my_identity = *identity; } @@ -736,45 +737,45 @@ core_init (void *cls, * message. It's necessary to specify the timeout. */ static void -handle_revocation_union_request (void *cls, - const struct GNUNET_PeerIdentity *other_peer, - const struct GNUNET_MessageHeader *context_msg, - struct GNUNET_SET_Request *request) +handle_revocation_union_request(void *cls, + const struct GNUNET_PeerIdentity *other_peer, + const struct GNUNET_MessageHeader *context_msg, + struct GNUNET_SET_Request *request) { struct PeerEntry *peer_entry; if (NULL == request) - { - GNUNET_break (0); - return; - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received set exchange request from peer `%s'\n", - GNUNET_i2s (other_peer)); - peer_entry = GNUNET_CONTAINER_multipeermap_get (peers, - other_peer); + { + GNUNET_break(0); + return; + } + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Received set exchange request from peer `%s'\n", + GNUNET_i2s(other_peer)); + peer_entry = GNUNET_CONTAINER_multipeermap_get(peers, + other_peer); if (NULL == peer_entry) - { - peer_entry = new_peer_entry (other_peer); - } + { + peer_entry = new_peer_entry(other_peer); + } if (NULL != peer_entry->so) - { - GNUNET_break_op (0); - return; - } - peer_entry->so = GNUNET_SET_accept (request, - GNUNET_SET_RESULT_ADDED, - (struct GNUNET_SET_Option[]) {{ 0 }}, - &add_revocation, - peer_entry); + { + GNUNET_break_op(0); + return; + } + peer_entry->so = GNUNET_SET_accept(request, + GNUNET_SET_RESULT_ADDED, + (struct GNUNET_SET_Option[]) { { 0 } }, + &add_revocation, + peer_entry); if (GNUNET_OK != - GNUNET_SET_commit (peer_entry->so, - revocation_set)) - { - GNUNET_break (0); - GNUNET_SCHEDULER_shutdown (); - return; - } + GNUNET_SET_commit(peer_entry->so, + revocation_set)) + { + GNUNET_break(0); + GNUNET_SCHEDULER_shutdown(); + return; + } } @@ -786,136 +787,136 @@ handle_revocation_union_request (void *cls, * @param c configuration to use */ static void -run (void *cls, - const struct GNUNET_CONFIGURATION_Handle *c, - struct GNUNET_SERVICE_Handle *service) +run(void *cls, + const struct GNUNET_CONFIGURATION_Handle *c, + struct GNUNET_SERVICE_Handle *service) { struct GNUNET_MQ_MessageHandler core_handlers[] = { - GNUNET_MQ_hd_fixed_size (p2p_revoke, - GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE, - struct RevokeMessage, - NULL), - GNUNET_MQ_handler_end () + GNUNET_MQ_hd_fixed_size(p2p_revoke, + GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE, + struct RevokeMessage, + NULL), + GNUNET_MQ_handler_end() }; char *fn; uint64_t left; struct RevokeMessage *rm; struct GNUNET_HashCode hc; - GNUNET_CRYPTO_hash ("revocation-set-union-application-id", - strlen ("revocation-set-union-application-id"), - &revocation_set_union_app_id); + GNUNET_CRYPTO_hash("revocation-set-union-application-id", + strlen("revocation-set-union-application-id"), + &revocation_set_union_app_id); if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_filename (c, - "REVOCATION", - "DATABASE", - &fn)) - { - GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, - "REVOCATION", - "DATABASE"); - GNUNET_SCHEDULER_shutdown (); - return; - } + GNUNET_CONFIGURATION_get_value_filename(c, + "REVOCATION", + "DATABASE", + &fn)) + { + GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, + "REVOCATION", + "DATABASE"); + GNUNET_SCHEDULER_shutdown(); + return; + } cfg = c; - revocation_map = GNUNET_CONTAINER_multihashmap_create (16, - GNUNET_NO); + revocation_map = GNUNET_CONTAINER_multihashmap_create(16, + GNUNET_NO); if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_number (cfg, - "REVOCATION", - "WORKBITS", - &revocation_work_required)) - { - GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, - "REVOCATION", - "WORKBITS"); - GNUNET_SCHEDULER_shutdown (); - GNUNET_free (fn); - return; - } - if (revocation_work_required >= sizeof (struct GNUNET_HashCode) * 8) - { - GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, - "REVOCATION", - "WORKBITS", - _("Value is too large.\n")); - GNUNET_SCHEDULER_shutdown (); - GNUNET_free (fn); - return; - } - revocation_set = GNUNET_SET_create (cfg, - GNUNET_SET_OPERATION_UNION); + GNUNET_CONFIGURATION_get_value_number(cfg, + "REVOCATION", + "WORKBITS", + &revocation_work_required)) + { + GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, + "REVOCATION", + "WORKBITS"); + GNUNET_SCHEDULER_shutdown(); + GNUNET_free(fn); + return; + } + if (revocation_work_required >= sizeof(struct GNUNET_HashCode) * 8) + { + GNUNET_log_config_invalid(GNUNET_ERROR_TYPE_ERROR, + "REVOCATION", + "WORKBITS", + _("Value is too large.\n")); + GNUNET_SCHEDULER_shutdown(); + GNUNET_free(fn); + return; + } + revocation_set = GNUNET_SET_create(cfg, + GNUNET_SET_OPERATION_UNION); revocation_union_listen_handle - = GNUNET_SET_listen (cfg, - GNUNET_SET_OPERATION_UNION, - &revocation_set_union_app_id, - &handle_revocation_union_request, - NULL); - revocation_db = GNUNET_DISK_file_open (fn, - GNUNET_DISK_OPEN_READWRITE | - GNUNET_DISK_OPEN_CREATE, - GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE | - GNUNET_DISK_PERM_GROUP_READ | - GNUNET_DISK_PERM_OTHER_READ); + = GNUNET_SET_listen(cfg, + GNUNET_SET_OPERATION_UNION, + &revocation_set_union_app_id, + &handle_revocation_union_request, + NULL); + revocation_db = GNUNET_DISK_file_open(fn, + GNUNET_DISK_OPEN_READWRITE | + GNUNET_DISK_OPEN_CREATE, + GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE | + GNUNET_DISK_PERM_GROUP_READ | + GNUNET_DISK_PERM_OTHER_READ); if (NULL == revocation_db) - { - GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, - "REVOCATION", - "DATABASE", - _("Could not open revocation database file!")); - GNUNET_SCHEDULER_shutdown (); - GNUNET_free (fn); - return; - } - if (GNUNET_OK != - GNUNET_DISK_file_size (fn, &left, GNUNET_YES, GNUNET_YES)) - left = 0; - while (left > sizeof (struct RevokeMessage)) - { - rm = GNUNET_new (struct RevokeMessage); - if (sizeof (struct RevokeMessage) != - GNUNET_DISK_file_read (revocation_db, - rm, - sizeof (struct RevokeMessage))) - { - GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, - "read", - fn); - GNUNET_free (rm); - GNUNET_SCHEDULER_shutdown (); - GNUNET_free (fn); + { + GNUNET_log_config_invalid(GNUNET_ERROR_TYPE_ERROR, + "REVOCATION", + "DATABASE", + _("Could not open revocation database file!")); + GNUNET_SCHEDULER_shutdown(); + GNUNET_free(fn); return; } - GNUNET_break (0 == ntohl (rm->reserved)); - GNUNET_CRYPTO_hash (&rm->public_key, - sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey), - &hc); - GNUNET_break (GNUNET_OK == - GNUNET_CONTAINER_multihashmap_put (revocation_map, + if (GNUNET_OK != + GNUNET_DISK_file_size(fn, &left, GNUNET_YES, GNUNET_YES)) + left = 0; + while (left > sizeof(struct RevokeMessage)) + { + rm = GNUNET_new(struct RevokeMessage); + if (sizeof(struct RevokeMessage) != + GNUNET_DISK_file_read(revocation_db, + rm, + sizeof(struct RevokeMessage))) + { + GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, + "read", + fn); + GNUNET_free(rm); + GNUNET_SCHEDULER_shutdown(); + GNUNET_free(fn); + return; + } + GNUNET_break(0 == ntohl(rm->reserved)); + GNUNET_CRYPTO_hash(&rm->public_key, + sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey), + &hc); + GNUNET_break(GNUNET_OK == + GNUNET_CONTAINER_multihashmap_put(revocation_map, &hc, rm, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); - } - GNUNET_free (fn); + } + GNUNET_free(fn); - GNUNET_SCHEDULER_add_shutdown (&shutdown_task, - NULL); - peers = GNUNET_CONTAINER_multipeermap_create (128, - GNUNET_YES); + GNUNET_SCHEDULER_add_shutdown(&shutdown_task, + NULL); + peers = GNUNET_CONTAINER_multipeermap_create(128, + GNUNET_YES); /* Connect to core service and register core handlers */ - core_api = GNUNET_CORE_connect (cfg, /* Main configuration */ - NULL, /* Closure passed to functions */ - &core_init, /* Call core_init once connected */ - &handle_core_connect, /* Handle connects */ - &handle_core_disconnect, /* Handle disconnects */ - core_handlers); /* Register these handlers */ + core_api = GNUNET_CORE_connect(cfg, /* Main configuration */ + NULL, /* Closure passed to functions */ + &core_init, /* Call core_init once connected */ + &handle_core_connect, /* Handle connects */ + &handle_core_disconnect, /* Handle disconnects */ + core_handlers); /* Register these handlers */ if (NULL == core_api) - { - GNUNET_SCHEDULER_shutdown (); - return; - } - stats = GNUNET_STATISTICS_create ("revocation", - cfg); + { + GNUNET_SCHEDULER_shutdown(); + return; + } + stats = GNUNET_STATISTICS_create("revocation", + cfg); } @@ -923,21 +924,21 @@ run (void *cls, * Define "main" method using service macro. */ GNUNET_SERVICE_MAIN -("revocation", - GNUNET_SERVICE_OPTION_NONE, - &run, - &client_connect_cb, - &client_disconnect_cb, - NULL, - GNUNET_MQ_hd_fixed_size (query_message, - GNUNET_MESSAGE_TYPE_REVOCATION_QUERY, - struct QueryMessage, - NULL), - GNUNET_MQ_hd_fixed_size (revoke_message, - GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE, - struct RevokeMessage, - NULL), - GNUNET_MQ_handler_end ()); + ("revocation", + GNUNET_SERVICE_OPTION_NONE, + &run, + &client_connect_cb, + &client_disconnect_cb, + NULL, + GNUNET_MQ_hd_fixed_size(query_message, + GNUNET_MESSAGE_TYPE_REVOCATION_QUERY, + struct QueryMessage, + NULL), + GNUNET_MQ_hd_fixed_size(revoke_message, + GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE, + struct RevokeMessage, + NULL), + GNUNET_MQ_handler_end()); #if defined(LINUX) && defined(__GLIBC__) @@ -947,11 +948,11 @@ GNUNET_SERVICE_MAIN * MINIMIZE heap size (way below 128k) since this process doesn't need much. */ void __attribute__ ((constructor)) -GNUNET_REVOCATION_memory_init () +GNUNET_REVOCATION_memory_init() { - mallopt (M_TRIM_THRESHOLD, 4 * 1024); - mallopt (M_TOP_PAD, 1 * 1024); - malloc_trim (0); + mallopt(M_TRIM_THRESHOLD, 4 * 1024); + mallopt(M_TOP_PAD, 1 * 1024); + malloc_trim(0); } #endif 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 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file block/plugin_block_revocation.c @@ -49,11 +49,8 @@ /** * Context used inside the plugin. */ -struct InternalContext -{ - +struct InternalContext { unsigned int matching_bits; - }; @@ -70,37 +67,37 @@ struct InternalContext * by this @a type of block (this is not an error) */ static struct GNUNET_BLOCK_Group * -block_plugin_revocation_create_group (void *cls, - enum GNUNET_BLOCK_Type type, - uint32_t nonce, - const void *raw_data, - size_t raw_data_size, - va_list va) +block_plugin_revocation_create_group(void *cls, + enum GNUNET_BLOCK_Type type, + uint32_t nonce, + const void *raw_data, + size_t raw_data_size, + va_list va) { unsigned int bf_size; const char *guard; - guard = va_arg (va, const char *); - if (0 == strcmp (guard, - "seen-set-size")) - bf_size = GNUNET_BLOCK_GROUP_compute_bloomfilter_size (va_arg (va, unsigned int), - BLOOMFILTER_K); - else if (0 == strcmp (guard, - "filter-size")) - bf_size = va_arg (va, unsigned int); + guard = va_arg(va, const char *); + if (0 == strcmp(guard, + "seen-set-size")) + bf_size = GNUNET_BLOCK_GROUP_compute_bloomfilter_size(va_arg(va, unsigned int), + BLOOMFILTER_K); + else if (0 == strcmp(guard, + "filter-size")) + bf_size = va_arg(va, unsigned int); else - { - GNUNET_break (0); - bf_size = REVOCATION_BF_SIZE; - } - GNUNET_break (NULL == va_arg (va, const char *)); - return GNUNET_BLOCK_GROUP_bf_create (cls, - bf_size, - BLOOMFILTER_K, - type, - nonce, - raw_data, - raw_data_size); + { + GNUNET_break(0); + bf_size = REVOCATION_BF_SIZE; + } + GNUNET_break(NULL == va_arg(va, const char *)); + return GNUNET_BLOCK_GROUP_bf_create(cls, + bf_size, + BLOOMFILTER_K, + type, + nonce, + raw_data, + raw_data_size); } @@ -121,16 +118,16 @@ block_plugin_revocation_create_group (void *cls, * @return characterization of result */ static enum GNUNET_BLOCK_EvaluationResult -block_plugin_revocation_evaluate (void *cls, - struct GNUNET_BLOCK_Context *ctx, - enum GNUNET_BLOCK_Type type, - struct GNUNET_BLOCK_Group *group, - enum GNUNET_BLOCK_EvaluationOptions eo, - const struct GNUNET_HashCode *query, - const void *xquery, - size_t xquery_size, - const void *reply_block, - size_t reply_block_size) +block_plugin_revocation_evaluate(void *cls, + struct GNUNET_BLOCK_Context *ctx, + enum GNUNET_BLOCK_Type type, + struct GNUNET_BLOCK_Group *group, + enum GNUNET_BLOCK_EvaluationOptions eo, + const struct GNUNET_HashCode *query, + const void *xquery, + size_t xquery_size, + const void *reply_block, + size_t reply_block_size) { struct InternalContext *ic = cls; struct GNUNET_HashCode chash; @@ -138,34 +135,34 @@ block_plugin_revocation_evaluate (void *cls, if (NULL == reply_block) return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; - if (reply_block_size != sizeof (*rm)) - { - GNUNET_break_op (0); - return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; - } + if (reply_block_size != sizeof(*rm)) + { + GNUNET_break_op(0); + return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; + } if (GNUNET_YES != - GNUNET_REVOCATION_check_pow (&rm->public_key, - rm->proof_of_work, - ic->matching_bits)) - { - GNUNET_break_op (0); - return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; - } + GNUNET_REVOCATION_check_pow(&rm->public_key, + rm->proof_of_work, + ic->matching_bits)) + { + GNUNET_break_op(0); + return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; + } if (GNUNET_OK != - GNUNET_CRYPTO_ecdsa_verify (GNUNET_SIGNATURE_PURPOSE_REVOCATION, - &rm->purpose, - &rm->signature, - &rm->public_key)) - { - GNUNET_break_op (0); - return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; - } - GNUNET_CRYPTO_hash (&rm->public_key, - sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey), - &chash); + GNUNET_CRYPTO_ecdsa_verify(GNUNET_SIGNATURE_PURPOSE_REVOCATION, + &rm->purpose, + &rm->signature, + &rm->public_key)) + { + GNUNET_break_op(0); + return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; + } + GNUNET_CRYPTO_hash(&rm->public_key, + sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey), + &chash); if (GNUNET_YES == - GNUNET_BLOCK_GROUP_bf_test_and_set (group, - &chash)) + GNUNET_BLOCK_GROUP_bf_test_and_set(group, + &chash)) return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE; return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; } @@ -183,22 +180,22 @@ block_plugin_revocation_evaluate (void *cls, * (or if extracting a key from a block of this type does not work) */ static int -block_plugin_revocation_get_key (void *cls, - enum GNUNET_BLOCK_Type type, - const void *block, - size_t block_size, - struct GNUNET_HashCode *key) +block_plugin_revocation_get_key(void *cls, + enum GNUNET_BLOCK_Type type, + const void *block, + size_t block_size, + struct GNUNET_HashCode *key) { const struct RevokeMessage *rm = block; - if (block_size != sizeof (*rm)) - { - GNUNET_break_op (0); - return GNUNET_SYSERR; - } - GNUNET_CRYPTO_hash (&rm->public_key, - sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey), - key); + if (block_size != sizeof(*rm)) + { + GNUNET_break_op(0); + return GNUNET_SYSERR; + } + GNUNET_CRYPTO_hash(&rm->public_key, + sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey), + key); return GNUNET_OK; } @@ -209,7 +206,7 @@ block_plugin_revocation_get_key (void *cls, * @param cls the configuration to use */ void * -libgnunet_plugin_block_revocation_init (void *cls) +libgnunet_plugin_block_revocation_init(void *cls) { static enum GNUNET_BLOCK_Type types[] = { @@ -222,19 +219,19 @@ libgnunet_plugin_block_revocation_init (void *cls) unsigned long long matching_bits; if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_number (cfg, - "REVOCATION", - "WORKBITS", - &matching_bits)) + GNUNET_CONFIGURATION_get_value_number(cfg, + "REVOCATION", + "WORKBITS", + &matching_bits)) return NULL; - api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); + api = GNUNET_new(struct GNUNET_BLOCK_PluginFunctions); api->evaluate = &block_plugin_revocation_evaluate; api->get_key = &block_plugin_revocation_get_key; api->create_group = &block_plugin_revocation_create_group; api->types = types; - ic = GNUNET_new (struct InternalContext); - ic->matching_bits = (unsigned int) matching_bits; + ic = GNUNET_new(struct InternalContext); + ic->matching_bits = (unsigned int)matching_bits; api->cls = ic; return api; } @@ -244,13 +241,13 @@ libgnunet_plugin_block_revocation_init (void *cls) * Exit point from the plugin. */ void * -libgnunet_plugin_block_revocation_done (void *cls) +libgnunet_plugin_block_revocation_done(void *cls) { struct GNUNET_BLOCK_PluginFunctions *api = cls; struct InternalContext *ic = api->cls; - GNUNET_free (ic); - GNUNET_free (api); + GNUNET_free(ic); + GNUNET_free(api); return NULL; } diff --git a/src/revocation/revocation.h b/src/revocation/revocation.h index 38fb476ed..43efd5ff2 100644 --- a/src/revocation/revocation.h +++ b/src/revocation/revocation.h @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @author Christian Grothoff @@ -33,8 +33,7 @@ GNUNET_NETWORK_STRUCT_BEGIN /** * Query key revocation status. */ -struct QueryMessage -{ +struct QueryMessage { /** * Type: #GNUNET_MESSAGE_TYPE_REVOCATION_QUERY */ @@ -49,15 +48,13 @@ struct QueryMessage * Key to check. */ struct GNUNET_CRYPTO_EcdsaPublicKey key; - }; /** * Key revocation response. */ -struct QueryResponseMessage -{ +struct QueryResponseMessage { /** * Type: #GNUNET_MESSAGE_TYPE_REVOCATION_QUERY_RESPONSE */ @@ -67,7 +64,6 @@ struct QueryResponseMessage * #GNUNET_NO if revoked, #GNUNET_YES if valid. */ uint32_t is_valid GNUNET_PACKED; - }; @@ -78,8 +74,7 @@ struct QueryResponseMessage * #GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE_RESPONSE (which is just * in a `struct GNUNET_MessageHeader`. */ -struct RevokeMessage -{ +struct RevokeMessage { /** * Type: #GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE */ @@ -110,15 +105,13 @@ struct RevokeMessage * Key to revoke. */ struct GNUNET_CRYPTO_EcdsaPublicKey public_key; - }; /** * Key revocation response. */ -struct RevocationResponseMessage -{ +struct RevocationResponseMessage { /** * Type: #GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE_RESPONSE */ @@ -129,7 +122,6 @@ struct RevocationResponseMessage * #GNUNET_YES on success */ uint32_t is_valid GNUNET_PACKED; - }; diff --git a/src/revocation/revocation_api.c b/src/revocation/revocation_api.c index 90f15a17a..091f6ae85 100644 --- a/src/revocation/revocation_api.c +++ b/src/revocation/revocation_api.c @@ -11,7 +11,7 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . @@ -33,9 +33,7 @@ /** * Handle for the key revocation query. */ -struct GNUNET_REVOCATION_Query -{ - +struct GNUNET_REVOCATION_Query { /** * Message queue to the service. */ @@ -50,7 +48,6 @@ struct GNUNET_REVOCATION_Query * Closure for @e func. */ void *func_cls; - }; @@ -64,16 +61,16 @@ struct GNUNET_REVOCATION_Query * @param error error code */ static void -query_mq_error_handler (void *cls, - enum GNUNET_MQ_Error error) +query_mq_error_handler(void *cls, + enum GNUNET_MQ_Error error) { struct GNUNET_REVOCATION_Query *q = cls; - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Revocation query MQ error\n"); - q->func (q->func_cls, - GNUNET_SYSERR); - GNUNET_REVOCATION_query_cancel (q); + GNUNET_log(GNUNET_ERROR_TYPE_INFO, + "Revocation query MQ error\n"); + q->func(q->func_cls, + GNUNET_SYSERR); + GNUNET_REVOCATION_query_cancel(q); } @@ -84,17 +81,17 @@ query_mq_error_handler (void *cls, * @param qrm response we got */ static void -handle_revocation_query_response (void *cls, - const struct QueryResponseMessage *qrm) +handle_revocation_query_response(void *cls, + const struct QueryResponseMessage *qrm) { struct GNUNET_REVOCATION_Query *q = cls; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Revocation query result: %d\n", - (uint32_t) ntohl (qrm->is_valid)); - q->func (q->func_cls, - ntohl (qrm->is_valid)); - GNUNET_REVOCATION_query_cancel (q); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Revocation query result: %d\n", + (uint32_t)ntohl(qrm->is_valid)); + q->func(q->func_cls, + ntohl(qrm->is_valid)); + GNUNET_REVOCATION_query_cancel(q); } @@ -108,41 +105,41 @@ handle_revocation_query_response (void *cls, * @return handle to use in #GNUNET_REVOCATION_query_cancel to stop REVOCATION from invoking the callback */ struct GNUNET_REVOCATION_Query * -GNUNET_REVOCATION_query (const struct GNUNET_CONFIGURATION_Handle *cfg, - const struct GNUNET_CRYPTO_EcdsaPublicKey *key, - GNUNET_REVOCATION_Callback func, - void *func_cls) +GNUNET_REVOCATION_query(const struct GNUNET_CONFIGURATION_Handle *cfg, + const struct GNUNET_CRYPTO_EcdsaPublicKey *key, + GNUNET_REVOCATION_Callback func, + void *func_cls) { struct GNUNET_REVOCATION_Query *q - = GNUNET_new (struct GNUNET_REVOCATION_Query); + = GNUNET_new(struct GNUNET_REVOCATION_Query); struct GNUNET_MQ_MessageHandler handlers[] = { - GNUNET_MQ_hd_fixed_size (revocation_query_response, - GNUNET_MESSAGE_TYPE_REVOCATION_QUERY_RESPONSE, - struct QueryResponseMessage, - q), - GNUNET_MQ_handler_end () + GNUNET_MQ_hd_fixed_size(revocation_query_response, + GNUNET_MESSAGE_TYPE_REVOCATION_QUERY_RESPONSE, + struct QueryResponseMessage, + q), + GNUNET_MQ_handler_end() }; struct QueryMessage *qm; struct GNUNET_MQ_Envelope *env; - q->mq = GNUNET_CLIENT_connect (cfg, - "revocation", - handlers, - &query_mq_error_handler, - q); + q->mq = GNUNET_CLIENT_connect(cfg, + "revocation", + handlers, + &query_mq_error_handler, + q); if (NULL == q->mq) - { - GNUNET_free (q); - return NULL; - } + { + GNUNET_free(q); + return NULL; + } q->func = func; q->func_cls = func_cls; - env = GNUNET_MQ_msg (qm, - GNUNET_MESSAGE_TYPE_REVOCATION_QUERY); - qm->reserved = htonl (0); + env = GNUNET_MQ_msg(qm, + GNUNET_MESSAGE_TYPE_REVOCATION_QUERY); + qm->reserved = htonl(0); qm->key = *key; - GNUNET_MQ_send (q->mq, - env); + GNUNET_MQ_send(q->mq, + env); return q; } @@ -153,23 +150,21 @@ GNUNET_REVOCATION_query (const struct GNUNET_CONFIGURATION_Handle *cfg, * @param q query to cancel */ void -GNUNET_REVOCATION_query_cancel (struct GNUNET_REVOCATION_Query *q) +GNUNET_REVOCATION_query_cancel(struct GNUNET_REVOCATION_Query *q) { if (NULL != q->mq) - { - GNUNET_MQ_destroy (q->mq); - q->mq = NULL; - } - GNUNET_free (q); + { + GNUNET_MQ_destroy(q->mq); + q->mq = NULL; + } + GNUNET_free(q); } /** * Handle for the key revocation operation. */ -struct GNUNET_REVOCATION_Handle -{ - +struct GNUNET_REVOCATION_Handle { /** * Message queue to the service. */ @@ -184,7 +179,6 @@ struct GNUNET_REVOCATION_Handle * Closure for @e func. */ void *func_cls; - }; @@ -198,16 +192,16 @@ struct GNUNET_REVOCATION_Handle * @param error error code */ static void -revocation_mq_error_handler (void *cls, - enum GNUNET_MQ_Error error) +revocation_mq_error_handler(void *cls, + enum GNUNET_MQ_Error error) { struct GNUNET_REVOCATION_Handle *h = cls; - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "Revocation MQ error\n"); - h->func (h->func_cls, - GNUNET_SYSERR); - GNUNET_REVOCATION_revoke_cancel (h); + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, + "Revocation MQ error\n"); + h->func(h->func_cls, + GNUNET_SYSERR); + GNUNET_REVOCATION_revoke_cancel(h); } @@ -218,17 +212,17 @@ revocation_mq_error_handler (void *cls, * @param rrm response we got */ static void -handle_revocation_response (void *cls, - const struct RevocationResponseMessage *rrm) +handle_revocation_response(void *cls, + const struct RevocationResponseMessage *rrm) { struct GNUNET_REVOCATION_Handle *h = cls; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Revocation transmission result: %d\n", - (uint32_t) ntohl (rrm->is_valid)); - h->func (h->func_cls, - ntohl (rrm->is_valid)); - GNUNET_REVOCATION_revoke_cancel (h); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Revocation transmission result: %d\n", + (uint32_t)ntohl(rrm->is_valid)); + h->func(h->func_cls, + ntohl(rrm->is_valid)); + GNUNET_REVOCATION_revoke_cancel(h); } @@ -248,64 +242,64 @@ handle_revocation_response (void *cls, * @return handle to use in #GNUNET_REVOCATION_revoke_cancel to stop REVOCATION from invoking the callback */ struct GNUNET_REVOCATION_Handle * -GNUNET_REVOCATION_revoke (const struct GNUNET_CONFIGURATION_Handle *cfg, - const struct GNUNET_CRYPTO_EcdsaPublicKey *key, - const struct GNUNET_CRYPTO_EcdsaSignature *sig, - uint64_t pow, - GNUNET_REVOCATION_Callback func, - void *func_cls) +GNUNET_REVOCATION_revoke(const struct GNUNET_CONFIGURATION_Handle *cfg, + const struct GNUNET_CRYPTO_EcdsaPublicKey *key, + const struct GNUNET_CRYPTO_EcdsaSignature *sig, + uint64_t pow, + GNUNET_REVOCATION_Callback func, + void *func_cls) { struct GNUNET_REVOCATION_Handle *h - = GNUNET_new (struct GNUNET_REVOCATION_Handle); + = GNUNET_new(struct GNUNET_REVOCATION_Handle); struct GNUNET_MQ_MessageHandler handlers[] = { - GNUNET_MQ_hd_fixed_size (revocation_response, - GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE_RESPONSE, - struct RevocationResponseMessage, - h), - GNUNET_MQ_handler_end () + GNUNET_MQ_hd_fixed_size(revocation_response, + GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE_RESPONSE, + struct RevocationResponseMessage, + h), + GNUNET_MQ_handler_end() }; unsigned long long matching_bits; struct RevokeMessage *rm; struct GNUNET_MQ_Envelope *env; - if ( (GNUNET_OK == - GNUNET_CONFIGURATION_get_value_number (cfg, - "REVOCATION", - "WORKBITS", - &matching_bits)) && - (GNUNET_YES != - GNUNET_REVOCATION_check_pow (key, - pow, - (unsigned int) matching_bits)) ) - { - GNUNET_break (0); - GNUNET_free (h); - return NULL; - } - - h->mq = GNUNET_CLIENT_connect (cfg, - "revocation", - handlers, - &revocation_mq_error_handler, - h); + if ((GNUNET_OK == + GNUNET_CONFIGURATION_get_value_number(cfg, + "REVOCATION", + "WORKBITS", + &matching_bits)) && + (GNUNET_YES != + GNUNET_REVOCATION_check_pow(key, + pow, + (unsigned int)matching_bits))) + { + GNUNET_break(0); + GNUNET_free(h); + return NULL; + } + + h->mq = GNUNET_CLIENT_connect(cfg, + "revocation", + handlers, + &revocation_mq_error_handler, + h); if (NULL == h->mq) - { - GNUNET_free (h); - return NULL; - } + { + GNUNET_free(h); + return NULL; + } h->func = func; h->func_cls = func_cls; - env = GNUNET_MQ_msg (rm, - GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE); - rm->reserved = htonl (0); + env = GNUNET_MQ_msg(rm, + GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE); + rm->reserved = htonl(0); rm->proof_of_work = pow; - rm->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_REVOCATION); - rm->purpose.size = htonl (sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) + - sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)); + rm->purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_REVOCATION); + rm->purpose.size = htonl(sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) + + sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)); rm->public_key = *key; rm->signature = *sig; - GNUNET_MQ_send (h->mq, - env); + GNUNET_MQ_send(h->mq, + env); return h; } @@ -316,14 +310,14 @@ GNUNET_REVOCATION_revoke (const struct GNUNET_CONFIGURATION_Handle *cfg, * @param h operation to cancel */ void -GNUNET_REVOCATION_revoke_cancel (struct GNUNET_REVOCATION_Handle *h) +GNUNET_REVOCATION_revoke_cancel(struct GNUNET_REVOCATION_Handle *h) { if (NULL != h->mq) - { - GNUNET_MQ_destroy (h->mq); - h->mq = NULL; - } - GNUNET_free (h); + { + GNUNET_MQ_destroy(h->mq); + h->mq = NULL; + } + GNUNET_free(h); } @@ -335,18 +329,18 @@ GNUNET_REVOCATION_revoke_cancel (struct GNUNET_REVOCATION_Handle *h) * @param result where to write the resulting hash */ static void -pow_hash (const void *buf, - size_t buf_len, - struct GNUNET_HashCode *result) +pow_hash(const void *buf, + size_t buf_len, + struct GNUNET_HashCode *result) { - GNUNET_break (0 == - gcry_kdf_derive (buf, buf_len, - GCRY_KDF_SCRYPT, - 1 /* subalgo */, - "gnunet-revocation-proof-of-work", - strlen ("gnunet-revocation-proof-of-work"), - 2 /* iterations; keep cost of individual op small */, - sizeof (struct GNUNET_HashCode), result)); + GNUNET_break(0 == + gcry_kdf_derive(buf, buf_len, + GCRY_KDF_SCRYPT, + 1 /* subalgo */, + "gnunet-revocation-proof-of-work", + strlen("gnunet-revocation-proof-of-work"), + 2 /* iterations; keep cost of individual op small */, + sizeof(struct GNUNET_HashCode), result)); } @@ -357,12 +351,12 @@ pow_hash (const void *buf, * @return the number of leading zero bits. */ static unsigned int -count_leading_zeroes (const struct GNUNET_HashCode *hash) +count_leading_zeroes(const struct GNUNET_HashCode *hash) { unsigned int hash_count; hash_count = 0; - while ((0 == GNUNET_CRYPTO_hash_get_bit (hash, hash_count))) + while ((0 == GNUNET_CRYPTO_hash_get_bit(hash, hash_count))) hash_count++; return hash_count; } @@ -378,19 +372,19 @@ count_leading_zeroes (const struct GNUNET_HashCode *hash) * @return #GNUNET_YES if the @a pow is acceptable, #GNUNET_NO if not */ int -GNUNET_REVOCATION_check_pow (const struct GNUNET_CRYPTO_EcdsaPublicKey *key, - uint64_t pow, - unsigned int matching_bits) +GNUNET_REVOCATION_check_pow(const struct GNUNET_CRYPTO_EcdsaPublicKey *key, + uint64_t pow, + unsigned int matching_bits) { - char buf[sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey) + - sizeof (pow)] GNUNET_ALIGN; + char buf[sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey) + + sizeof(pow)] GNUNET_ALIGN; struct GNUNET_HashCode result; - GNUNET_memcpy (buf, &pow, sizeof (pow)); - GNUNET_memcpy (&buf[sizeof (pow)], key, - sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)); - pow_hash (buf, sizeof (buf), &result); - return (count_leading_zeroes (&result) >= + GNUNET_memcpy(buf, &pow, sizeof(pow)); + GNUNET_memcpy(&buf[sizeof(pow)], key, + sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)); + pow_hash(buf, sizeof(buf), &result); + return (count_leading_zeroes(&result) >= matching_bits) ? GNUNET_YES : GNUNET_NO; } @@ -402,19 +396,19 @@ GNUNET_REVOCATION_check_pow (const struct GNUNET_CRYPTO_EcdsaPublicKey *key, * @param sig where to write the revocation signature */ void -GNUNET_REVOCATION_sign_revocation (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, - struct GNUNET_CRYPTO_EcdsaSignature *sig) +GNUNET_REVOCATION_sign_revocation(const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, + struct GNUNET_CRYPTO_EcdsaSignature *sig) { struct RevokeMessage rm; - rm.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_REVOCATION); - rm.purpose.size = htonl (sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) + - sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)); - GNUNET_CRYPTO_ecdsa_key_get_public (key, &rm.public_key); - GNUNET_assert (GNUNET_OK == - GNUNET_CRYPTO_ecdsa_sign (key, - &rm.purpose, - sig)); + rm.purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_REVOCATION); + rm.purpose.size = htonl(sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) + + sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)); + GNUNET_CRYPTO_ecdsa_key_get_public(key, &rm.public_key); + GNUNET_assert(GNUNET_OK == + GNUNET_CRYPTO_ecdsa_sign(key, + &rm.purpose, + sig)); } diff --git a/src/revocation/test_revocation.c b/src/revocation/test_revocation.c index 22df26165..22cb98887 100644 --- a/src/revocation/test_revocation.c +++ b/src/revocation/test_revocation.c @@ -16,7 +16,7 @@ along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file revocation/test_revocation.c * @brief base testcase for revocation exchange @@ -31,8 +31,7 @@ #define NUM_TEST_PEERS 2 -struct TestPeer -{ +struct TestPeer { struct GNUNET_TESTBED_Peer *p; struct GNUNET_TESTBED_Operation *identity_op; struct GNUNET_TESTBED_Operation *core_op; @@ -57,351 +56,352 @@ static int ok; static void -do_shutdown (void *cls) +do_shutdown(void *cls) { for (unsigned int c = 0; c < NUM_TEST_PEERS; c++) - { - if (NULL != testpeers[c].create_id_op) - { - GNUNET_IDENTITY_cancel (testpeers[c].create_id_op); - testpeers[c].create_id_op = NULL; - } - if (NULL != testpeers[c].ego_lookup) - { - GNUNET_IDENTITY_ego_lookup_cancel (testpeers[c].ego_lookup); - testpeers[c].ego_lookup = NULL; - } - if (NULL != testpeers[c].revok_handle) - { - GNUNET_REVOCATION_revoke_cancel (testpeers[c].revok_handle); - testpeers[c].revok_handle = NULL; - } - if (NULL != testpeers[c].identity_op) - { - GNUNET_TESTBED_operation_done (testpeers[c].identity_op); - testpeers[c].identity_op = NULL; - } - if (NULL != testpeers[c].core_op) { - GNUNET_TESTBED_operation_done (testpeers[c].core_op); - testpeers[c].core_op = NULL; + if (NULL != testpeers[c].create_id_op) + { + GNUNET_IDENTITY_cancel(testpeers[c].create_id_op); + testpeers[c].create_id_op = NULL; + } + if (NULL != testpeers[c].ego_lookup) + { + GNUNET_IDENTITY_ego_lookup_cancel(testpeers[c].ego_lookup); + testpeers[c].ego_lookup = NULL; + } + if (NULL != testpeers[c].revok_handle) + { + GNUNET_REVOCATION_revoke_cancel(testpeers[c].revok_handle); + testpeers[c].revok_handle = NULL; + } + if (NULL != testpeers[c].identity_op) + { + GNUNET_TESTBED_operation_done(testpeers[c].identity_op); + testpeers[c].identity_op = NULL; + } + if (NULL != testpeers[c].core_op) + { + GNUNET_TESTBED_operation_done(testpeers[c].core_op); + testpeers[c].core_op = NULL; + } } - } } static void -check_revocation (void *cls); +check_revocation(void *cls); static void -revocation_remote_cb (void *cls, int is_valid) +revocation_remote_cb(void *cls, int is_valid) { static int repeat = 0; if (GNUNET_NO == is_valid) - { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Local revocation successful\n"); - ok = 0; - GNUNET_SCHEDULER_shutdown (); - return; - } + { + GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Local revocation successful\n"); + ok = 0; + GNUNET_SCHEDULER_shutdown(); + return; + } if (repeat < 10) - { - repeat++; - GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, - &check_revocation, - NULL); - return; - } - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Flooding of revocation failed\n"); + { + repeat++; + GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, + &check_revocation, + NULL); + return; + } + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Flooding of revocation failed\n"); ok = 2; - GNUNET_SCHEDULER_shutdown (); + GNUNET_SCHEDULER_shutdown(); } static void -check_revocation (void *cls) +check_revocation(void *cls) { - GNUNET_REVOCATION_query (testpeers[0].cfg, - &testpeers[1].pubkey, - &revocation_remote_cb, - NULL); + GNUNET_REVOCATION_query(testpeers[0].cfg, + &testpeers[1].pubkey, + &revocation_remote_cb, + NULL); } static void -revocation_cb (void *cls, int is_valid) +revocation_cb(void *cls, int is_valid) { testpeers[1].revok_handle = NULL; if (GNUNET_NO == is_valid) - { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Revocation successful\n"); - check_revocation (NULL); - } + { + GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Revocation successful\n"); + check_revocation(NULL); + } } static void -ego_cb (void *cls, const struct GNUNET_IDENTITY_Ego *ego) +ego_cb(void *cls, const struct GNUNET_IDENTITY_Ego *ego) { static int completed = 0; if ((NULL != ego) && (cls == &testpeers[0])) - { - testpeers[0].ego_lookup = NULL; - testpeers[0].privkey = GNUNET_IDENTITY_ego_get_private_key (ego); - GNUNET_IDENTITY_ego_get_public_key (ego, &testpeers[0].pubkey); - completed++; - } + { + testpeers[0].ego_lookup = NULL; + testpeers[0].privkey = GNUNET_IDENTITY_ego_get_private_key(ego); + GNUNET_IDENTITY_ego_get_public_key(ego, &testpeers[0].pubkey); + completed++; + } if ((NULL != ego) && (cls == &testpeers[1])) - { - testpeers[1].ego_lookup = NULL; - testpeers[1].privkey = GNUNET_IDENTITY_ego_get_private_key (ego); - GNUNET_IDENTITY_ego_get_public_key (ego, &testpeers[1].pubkey); - GNUNET_REVOCATION_sign_revocation (testpeers[1].privkey, &testpeers[1].sig); - - GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Calculating proof of work...\n"); - testpeers[1].pow = 0; - int res = - GNUNET_REVOCATION_check_pow (&testpeers[1].pubkey, testpeers[1].pow, 5); - while (GNUNET_OK != res) { - testpeers[1].pow++; - res = - GNUNET_REVOCATION_check_pow (&testpeers[1].pubkey, testpeers[1].pow, 5); + testpeers[1].ego_lookup = NULL; + testpeers[1].privkey = GNUNET_IDENTITY_ego_get_private_key(ego); + GNUNET_IDENTITY_ego_get_public_key(ego, &testpeers[1].pubkey); + GNUNET_REVOCATION_sign_revocation(testpeers[1].privkey, &testpeers[1].sig); + + GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Calculating proof of work...\n"); + testpeers[1].pow = 0; + int res = + GNUNET_REVOCATION_check_pow(&testpeers[1].pubkey, testpeers[1].pow, 5); + while (GNUNET_OK != res) + { + testpeers[1].pow++; + res = + GNUNET_REVOCATION_check_pow(&testpeers[1].pubkey, testpeers[1].pow, 5); + } + fprintf(stderr, "Done calculating proof of work\n"); + completed++; } - fprintf (stderr, "Done calculating proof of work\n"); - completed++; - } if (2 == completed) - { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Egos retrieved\n"); - testpeers[1].revok_handle = GNUNET_REVOCATION_revoke (testpeers[1].cfg, - &testpeers[1].pubkey, - &testpeers[1].sig, - testpeers[1].pow, - &revocation_cb, - NULL); - } + { + GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Egos retrieved\n"); + testpeers[1].revok_handle = GNUNET_REVOCATION_revoke(testpeers[1].cfg, + &testpeers[1].pubkey, + &testpeers[1].sig, + testpeers[1].pow, + &revocation_cb, + NULL); + } } static void -identity_create_cb (void *cls, - const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, - const char *emsg) +identity_create_cb(void *cls, + const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, + const char *emsg) { static int completed = 0; if ((NULL == emsg) && (cls == &testpeers[0])) - { - testpeers[0].create_id_op = NULL; - completed++; - } + { + testpeers[0].create_id_op = NULL; + completed++; + } if ((NULL == emsg) && (cls == &testpeers[1])) - { - testpeers[1].create_id_op = NULL; - completed++; - } + { + testpeers[1].create_id_op = NULL; + completed++; + } if (2 != completed) return; - fprintf (stderr, "Identities created\n"); - testpeers[0].ego_lookup = GNUNET_IDENTITY_ego_lookup (testpeers[0].cfg, - "client", - &ego_cb, - &testpeers[0]); - testpeers[1].ego_lookup = GNUNET_IDENTITY_ego_lookup (testpeers[1].cfg, - "toberevoked", - &ego_cb, - &testpeers[1]); + fprintf(stderr, "Identities created\n"); + testpeers[0].ego_lookup = GNUNET_IDENTITY_ego_lookup(testpeers[0].cfg, + "client", + &ego_cb, + &testpeers[0]); + testpeers[1].ego_lookup = GNUNET_IDENTITY_ego_lookup(testpeers[1].cfg, + "toberevoked", + &ego_cb, + &testpeers[1]); } static void -identity_completion_cb (void *cls, - struct GNUNET_TESTBED_Operation *op, - void *ca_result, - const char *emsg) +identity_completion_cb(void *cls, + struct GNUNET_TESTBED_Operation *op, + void *ca_result, + const char *emsg) { static int completed = 0; completed++; if (NUM_TEST_PEERS != completed) return; - fprintf (stderr, "All peers connected @ IDENTITY ...\n"); - testpeers[0].create_id_op = GNUNET_IDENTITY_create (testpeers[0].idh, - "client", - &identity_create_cb, - &testpeers[0]); - testpeers[1].create_id_op = GNUNET_IDENTITY_create (testpeers[1].idh, - "toberevoked", - &identity_create_cb, - &testpeers[1]); + fprintf(stderr, "All peers connected @ IDENTITY ...\n"); + testpeers[0].create_id_op = GNUNET_IDENTITY_create(testpeers[0].idh, + "client", + &identity_create_cb, + &testpeers[0]); + testpeers[1].create_id_op = GNUNET_IDENTITY_create(testpeers[1].idh, + "toberevoked", + &identity_create_cb, + &testpeers[1]); } static void * -identity_connect_adapter (void *cls, - const struct GNUNET_CONFIGURATION_Handle *cfg) +identity_connect_adapter(void *cls, + const struct GNUNET_CONFIGURATION_Handle *cfg) { struct TestPeer *me = cls; me->cfg = cfg; - me->idh = GNUNET_IDENTITY_connect (cfg, NULL, NULL); + me->idh = GNUNET_IDENTITY_connect(cfg, NULL, NULL); if (NULL == me->idh) - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create IDENTITY handle \n"); + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to create IDENTITY handle \n"); return me->idh; } static void -identity_disconnect_adapter (void *cls, void *op_result) +identity_disconnect_adapter(void *cls, void *op_result) { struct TestPeer *me = cls; - GNUNET_IDENTITY_disconnect (me->idh); + + GNUNET_IDENTITY_disconnect(me->idh); me->idh = NULL; } static void * -connect_cb (void *cls, - const struct GNUNET_PeerIdentity *peer, - struct GNUNET_MQ_Handle *mq) +connect_cb(void *cls, + const struct GNUNET_PeerIdentity *peer, + struct GNUNET_MQ_Handle *mq) { static int connects = 0; connects++; if (NUM_TEST_PEERS * NUM_TEST_PEERS == connects) - { - fprintf (stderr, "All peers connected @ CORE ...\n"); - - /* Connect to identity service */ - testpeers[0].identity_op = - GNUNET_TESTBED_service_connect (NULL, - testpeers[0].p, - "identity", - &identity_completion_cb, - NULL, - &identity_connect_adapter, - &identity_disconnect_adapter, - &testpeers[0]); - testpeers[1].identity_op = - GNUNET_TESTBED_service_connect (NULL, - testpeers[1].p, - "identity", - *identity_completion_cb, - NULL, - &identity_connect_adapter, - &identity_disconnect_adapter, - &testpeers[1]); - } + { + fprintf(stderr, "All peers connected @ CORE ...\n"); + + /* Connect to identity service */ + testpeers[0].identity_op = + GNUNET_TESTBED_service_connect(NULL, + testpeers[0].p, + "identity", + &identity_completion_cb, + NULL, + &identity_connect_adapter, + &identity_disconnect_adapter, + &testpeers[0]); + testpeers[1].identity_op = + GNUNET_TESTBED_service_connect(NULL, + testpeers[1].p, + "identity", + *identity_completion_cb, + NULL, + &identity_connect_adapter, + &identity_disconnect_adapter, + &testpeers[1]); + } return NULL; } static void -core_completion_cb (void *cls, - struct GNUNET_TESTBED_Operation *op, - void *ca_result, - const char *emsg) +core_completion_cb(void *cls, + struct GNUNET_TESTBED_Operation *op, + void *ca_result, + const char *emsg) { static int completed = 0; completed++; if (NUM_TEST_PEERS == completed) - { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Connected to CORE\n"); - } + { + GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Connected to CORE\n"); + } } static void * -core_connect_adapter (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) +core_connect_adapter(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) { struct TestPeer *me = cls; me->cfg = cfg; - me->ch = GNUNET_CORE_connect (cfg, me, NULL, &connect_cb, NULL, NULL); + me->ch = GNUNET_CORE_connect(cfg, me, NULL, &connect_cb, NULL, NULL); if (NULL == me->ch) - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create CORE handle \n"); + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to create CORE handle \n"); return me->ch; } static void -core_disconnect_adapter (void *cls, void *op_result) +core_disconnect_adapter(void *cls, void *op_result) { struct TestPeer *me = cls; - GNUNET_CORE_disconnect (me->ch); + GNUNET_CORE_disconnect(me->ch); me->ch = NULL; } static void -test_connection (void *cls, - struct GNUNET_TESTBED_RunHandle *h, - unsigned int num_peers, - struct GNUNET_TESTBED_Peer **peers, - unsigned int links_succeeded, - unsigned int links_failed) +test_connection(void *cls, + struct GNUNET_TESTBED_RunHandle *h, + unsigned int num_peers, + struct GNUNET_TESTBED_Peer **peers, + unsigned int links_succeeded, + unsigned int links_failed) { unsigned int c; - GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); + GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL); if (NUM_TEST_PEERS != num_peers) - { - ok = 4; - fprintf (stderr, - "Only %u out of %u peers were started ...\n", - num_peers, - NUM_TEST_PEERS); - GNUNET_SCHEDULER_shutdown (); - return; - } + { + ok = 4; + fprintf(stderr, + "Only %u out of %u peers were started ...\n", + num_peers, + NUM_TEST_PEERS); + GNUNET_SCHEDULER_shutdown(); + return; + } /* We are generating a CLIQUE */ if (NUM_TEST_PEERS * (NUM_TEST_PEERS - 1) == links_succeeded) - { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Testbed connected peers, initializing test\n"); - for (c = 0; c < num_peers; c++) { - testpeers[c].p = peers[c]; - testpeers[c].core_op = - GNUNET_TESTBED_service_connect (NULL, - testpeers[c].p, - "core", - &core_completion_cb, - NULL, - &core_connect_adapter, - &core_disconnect_adapter, - &testpeers[c]); + GNUNET_log(GNUNET_ERROR_TYPE_INFO, + "Testbed connected peers, initializing test\n"); + for (c = 0; c < num_peers; c++) + { + testpeers[c].p = peers[c]; + testpeers[c].core_op = + GNUNET_TESTBED_service_connect(NULL, + testpeers[c].p, + "core", + &core_completion_cb, + NULL, + &core_connect_adapter, + &core_disconnect_adapter, + &testpeers[c]); + } } - } else - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Testbed failed to connect peers\n"); - ok = 5; - GNUNET_SCHEDULER_shutdown (); - return; - } + { + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Testbed failed to connect peers\n"); + ok = 5; + GNUNET_SCHEDULER_shutdown(); + return; + } } int -main (int argc, char *argv[]) +main(int argc, char *argv[]) { ok = 1; /* Connecting initial topology */ - (void) GNUNET_TESTBED_test_run ("test-revocation", - "test_revocation.conf", - NUM_TEST_PEERS, - 0, - NULL, - NULL, - &test_connection, - NULL); + (void)GNUNET_TESTBED_test_run("test-revocation", + "test_revocation.conf", + NUM_TEST_PEERS, + 0, + NULL, + NULL, + &test_connection, + NULL); return ok; } -- cgit v1.2.3