From c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sat, 5 Oct 2019 15:09:28 +0200 Subject: global reindent, now with uncrustify hook enabled --- src/peerstore/gnunet-peerstore.c | 34 +- src/peerstore/gnunet-service-peerstore.c | 444 +++++++++--------- src/peerstore/peerstore.h | 6 +- src/peerstore/peerstore_api.c | 540 +++++++++++----------- src/peerstore/peerstore_common.c | 150 +++--- src/peerstore/peerstore_common.h | 28 +- src/peerstore/perf_peerstore_store.c | 64 +-- src/peerstore/plugin_peerstore_flat.c | 509 ++++++++++----------- src/peerstore/plugin_peerstore_sqlite.c | 704 +++++++++++++++-------------- src/peerstore/test_peerstore_api_iterate.c | 190 ++++---- src/peerstore/test_peerstore_api_store.c | 204 ++++----- src/peerstore/test_peerstore_api_sync.c | 92 ++-- src/peerstore/test_peerstore_api_watch.c | 80 ++-- src/peerstore/test_plugin_peerstore.c | 204 ++++----- 14 files changed, 1632 insertions(+), 1617 deletions(-) (limited to 'src/peerstore') diff --git a/src/peerstore/gnunet-peerstore.c b/src/peerstore/gnunet-peerstore.c index 891676ebd..392318f84 100644 --- a/src/peerstore/gnunet-peerstore.c +++ b/src/peerstore/gnunet-peerstore.c @@ -41,13 +41,13 @@ static struct GNUNET_PEERSTORE_Handle *peerstore_handle; * @param cls unused */ static void -shutdown_task(void *cls) +shutdown_task (void *cls) { if (NULL != peerstore_handle) - { - GNUNET_PEERSTORE_disconnect(peerstore_handle, GNUNET_YES); - peerstore_handle = NULL; - } + { + GNUNET_PEERSTORE_disconnect (peerstore_handle, GNUNET_YES); + peerstore_handle = NULL; + } } @@ -60,15 +60,15 @@ shutdown_task(void *cls) * @param cfg configuration */ static void -run(void *cls, - char *const *args, - const char *cfgfile, - const struct GNUNET_CONFIGURATION_Handle *cfg) +run (void *cls, + char *const *args, + const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *cfg) { - GNUNET_SCHEDULER_add_shutdown(&shutdown_task, - NULL); - peerstore_handle = GNUNET_PEERSTORE_connect(cfg); - GNUNET_assert(NULL != peerstore_handle); + GNUNET_SCHEDULER_add_shutdown (&shutdown_task, + NULL); + peerstore_handle = GNUNET_PEERSTORE_connect (cfg); + GNUNET_assert (NULL != peerstore_handle); ret = 0; } @@ -81,16 +81,16 @@ run(void *cls, * @return 0 ok, 1 on error */ int -main(int argc, char *const *argv) +main (int argc, char *const *argv) { static const struct GNUNET_GETOPT_CommandLineOption options[] = { GNUNET_GETOPT_OPTION_END }; return (GNUNET_OK == - GNUNET_PROGRAM_run(argc, argv, "gnunet-peerstore [options [value]]", - gettext_noop("peerstore"), options, &run, - NULL)) ? ret : 1; + GNUNET_PROGRAM_run (argc, argv, "gnunet-peerstore [options [value]]", + gettext_noop ("peerstore"), options, &run, + NULL)) ? ret : 1; } /* end of gnunet-peerstore.c */ diff --git a/src/peerstore/gnunet-service-peerstore.c b/src/peerstore/gnunet-service-peerstore.c index 02ac03e01..c92e4d3f0 100644 --- a/src/peerstore/gnunet-service-peerstore.c +++ b/src/peerstore/gnunet-service-peerstore.c @@ -75,25 +75,25 @@ static unsigned int num_clients; * Perform the actual shutdown operations */ static void -do_shutdown() +do_shutdown () { if (NULL != db_lib_name) - { - GNUNET_break(NULL == GNUNET_PLUGIN_unload(db_lib_name, db)); - GNUNET_free(db_lib_name); - db_lib_name = NULL; - } + { + GNUNET_break (NULL == GNUNET_PLUGIN_unload (db_lib_name, db)); + GNUNET_free (db_lib_name); + db_lib_name = NULL; + } if (NULL != watchers) - { - GNUNET_CONTAINER_multihashmap_destroy(watchers); - watchers = NULL; - } + { + GNUNET_CONTAINER_multihashmap_destroy (watchers); + watchers = NULL; + } if (NULL != expire_task) - { - GNUNET_SCHEDULER_cancel(expire_task); - expire_task = NULL; - } - GNUNET_SCHEDULER_shutdown(); + { + GNUNET_SCHEDULER_cancel (expire_task); + expire_task = NULL; + } + GNUNET_SCHEDULER_shutdown (); } @@ -103,42 +103,42 @@ do_shutdown() * @param cls unused */ static void -shutdown_task(void *cls) +shutdown_task (void *cls) { in_shutdown = GNUNET_YES; if (0 == num_clients) /* Only when no connected clients. */ - do_shutdown(); + do_shutdown (); } /* Forward declaration */ static void -expire_records_continuation(void *cls, int success); +expire_records_continuation (void *cls, int success); /** * Deletes any expired records from storage */ static void -cleanup_expired_records(void *cls) +cleanup_expired_records (void *cls) { int ret; expire_task = NULL; - GNUNET_assert(NULL != db); - ret = db->expire_records(db->cls, - GNUNET_TIME_absolute_get(), - &expire_records_continuation, - NULL); + GNUNET_assert (NULL != db); + ret = db->expire_records (db->cls, + GNUNET_TIME_absolute_get (), + &expire_records_continuation, + NULL); if (GNUNET_OK != ret) - { - GNUNET_assert(NULL == expire_task); - expire_task = GNUNET_SCHEDULER_add_delayed( - GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, - EXPIRED_RECORDS_CLEANUP_INTERVAL), - &cleanup_expired_records, - NULL); - } + { + GNUNET_assert (NULL == expire_task); + expire_task = GNUNET_SCHEDULER_add_delayed ( + GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, + EXPIRED_RECORDS_CLEANUP_INTERVAL), + &cleanup_expired_records, + NULL); + } } @@ -149,14 +149,14 @@ cleanup_expired_records(void *cls) * @param success count of records deleted or #GNUNET_SYSERR */ static void -expire_records_continuation(void *cls, int success) +expire_records_continuation (void *cls, int success) { if (success > 0) - GNUNET_log(GNUNET_ERROR_TYPE_INFO, "%d records expired.\n", success); - GNUNET_assert(NULL == expire_task); - expire_task = GNUNET_SCHEDULER_add_delayed( - GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, - EXPIRED_RECORDS_CLEANUP_INTERVAL), + GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%d records expired.\n", success); + GNUNET_assert (NULL == expire_task); + expire_task = GNUNET_SCHEDULER_add_delayed ( + GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, + EXPIRED_RECORDS_CLEANUP_INTERVAL), &cleanup_expired_records, NULL); } @@ -171,9 +171,9 @@ expire_records_continuation(void *cls, int success) * @return */ 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) { num_clients++; return client; @@ -189,14 +189,14 @@ client_connect_cb(void *cls, * @return #GNUNET_OK to continue iterating */ static int -client_disconnect_it(void *cls, const struct GNUNET_HashCode *key, void *value) +client_disconnect_it (void *cls, const struct GNUNET_HashCode *key, void *value) { if (value == cls) - { - GNUNET_assert(GNUNET_YES == - GNUNET_CONTAINER_multihashmap_remove(watchers, key, value)); - num_clients++; - } + { + GNUNET_assert (GNUNET_YES == + GNUNET_CONTAINER_multihashmap_remove (watchers, key, value)); + num_clients++; + } return GNUNET_OK; } @@ -208,18 +208,18 @@ client_disconnect_it(void *cls, const struct GNUNET_HashCode *key, void *value) * @param client identification of the 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_log(GNUNET_ERROR_TYPE_DEBUG, "A client disconnected, cleaning up.\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "A client disconnected, cleaning up.\n"); if (NULL != watchers) - GNUNET_CONTAINER_multihashmap_iterate(watchers, - &client_disconnect_it, - client); + GNUNET_CONTAINER_multihashmap_iterate (watchers, + &client_disconnect_it, + client); num_clients--; if ((0 == num_clients) && in_shutdown) - do_shutdown(); + do_shutdown (); } @@ -232,35 +232,35 @@ client_disconnect_cb(void *cls, * @return #GNUNET_YES to continue iteration */ static void -record_iterator(void *cls, - const struct GNUNET_PEERSTORE_Record *record, - const char *emsg) +record_iterator (void *cls, + const struct GNUNET_PEERSTORE_Record *record, + const char *emsg) { struct GNUNET_PEERSTORE_Record *cls_record = cls; struct GNUNET_MQ_Envelope *env; if (NULL == record) + { + /* No more records */ + struct GNUNET_MessageHeader *endmsg; + + env = GNUNET_MQ_msg (endmsg, GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_END); + GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (cls_record->client), env); + if (NULL == emsg) { - /* No more records */ - struct GNUNET_MessageHeader *endmsg; - - env = GNUNET_MQ_msg(endmsg, GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_END); - GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(cls_record->client), env); - if (NULL == emsg) - { - GNUNET_SERVICE_client_continue(cls_record->client); - } - else - { - GNUNET_break(0); - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to iterate: %s\n", emsg); - GNUNET_SERVICE_client_drop(cls_record->client); - } - PEERSTORE_destroy_record(cls_record); - return; + GNUNET_SERVICE_client_continue (cls_record->client); } + else + { + GNUNET_break (0); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to iterate: %s\n", emsg); + GNUNET_SERVICE_client_drop (cls_record->client); + } + PEERSTORE_destroy_record (cls_record); + return; + } - env = PEERSTORE_create_record_mq_envelope( + env = PEERSTORE_create_record_mq_envelope ( record->sub_system, &record->peer, record->key, @@ -269,7 +269,7 @@ record_iterator(void *cls, record->expiry, 0, GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_RECORD); - GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(cls_record->client), env); + GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (cls_record->client), env); } @@ -283,14 +283,14 @@ record_iterator(void *cls, * @return #GNUNET_YES to continue iterating */ static int -watch_notifier_it(void *cls, const struct GNUNET_HashCode *key, void *value) +watch_notifier_it (void *cls, const struct GNUNET_HashCode *key, void *value) { struct GNUNET_PEERSTORE_Record *record = cls; struct GNUNET_SERVICE_Client *client = value; struct GNUNET_MQ_Envelope *env; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Found a watcher to update.\n"); - env = PEERSTORE_create_record_mq_envelope( + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found a watcher to update.\n"); + env = PEERSTORE_create_record_mq_envelope ( record->sub_system, &record->peer, record->key, @@ -299,7 +299,7 @@ watch_notifier_it(void *cls, const struct GNUNET_HashCode *key, void *value) record->expiry, 0, GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_RECORD); - GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), env); + GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env); return GNUNET_YES; } @@ -310,15 +310,15 @@ watch_notifier_it(void *cls, const struct GNUNET_HashCode *key, void *value) * @param record changed record to update watchers with */ static void -watch_notifier(struct GNUNET_PEERSTORE_Record *record) +watch_notifier (struct GNUNET_PEERSTORE_Record *record) { struct GNUNET_HashCode keyhash; - PEERSTORE_hash_key(record->sub_system, &record->peer, record->key, &keyhash); - GNUNET_CONTAINER_multihashmap_get_multiple(watchers, - &keyhash, - &watch_notifier_it, - record); + PEERSTORE_hash_key (record->sub_system, &record->peer, record->key, &keyhash); + GNUNET_CONTAINER_multihashmap_get_multiple (watchers, + &keyhash, + &watch_notifier_it, + record); } @@ -329,20 +329,20 @@ watch_notifier(struct GNUNET_PEERSTORE_Record *record) * @param hm the actual message */ static void -handle_watch_cancel(void *cls, const struct StoreKeyHashMessage *hm) +handle_watch_cancel (void *cls, const struct StoreKeyHashMessage *hm) { struct GNUNET_SERVICE_Client *client = cls; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received a watch cancel request.\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received a watch cancel request.\n"); if (GNUNET_OK != - GNUNET_CONTAINER_multihashmap_remove(watchers, &hm->keyhash, client)) - { - GNUNET_break(0); - GNUNET_SERVICE_client_drop(client); - return; - } + GNUNET_CONTAINER_multihashmap_remove (watchers, &hm->keyhash, client)) + { + GNUNET_break (0); + GNUNET_SERVICE_client_drop (client); + return; + } num_clients++; - GNUNET_SERVICE_client_continue(client); + GNUNET_SERVICE_client_continue (client); } @@ -353,18 +353,18 @@ handle_watch_cancel(void *cls, const struct StoreKeyHashMessage *hm) * @param hm the actual message */ static void -handle_watch(void *cls, const struct StoreKeyHashMessage *hm) +handle_watch (void *cls, const struct StoreKeyHashMessage *hm) { struct GNUNET_SERVICE_Client *client = cls; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received a watch request.\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received a watch request.\n"); num_clients--; /* do not count watchers */ - GNUNET_SERVICE_client_mark_monitor(client); - GNUNET_CONTAINER_multihashmap_put(watchers, - &hm->keyhash, - client, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); - GNUNET_SERVICE_client_continue(client); + GNUNET_SERVICE_client_mark_monitor (client); + GNUNET_CONTAINER_multihashmap_put (watchers, + &hm->keyhash, + client, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); + GNUNET_SERVICE_client_continue (client); } @@ -376,23 +376,23 @@ handle_watch(void *cls, const struct StoreKeyHashMessage *hm) * @return #GNUNET_OK if @a srm is well-formed */ static int -check_iterate(void *cls, const struct StoreRecordMessage *srm) +check_iterate (void *cls, const struct StoreRecordMessage *srm) { struct GNUNET_PEERSTORE_Record *record; - record = PEERSTORE_parse_record_message(srm); + record = PEERSTORE_parse_record_message (srm); if (NULL == record) - { - GNUNET_break(0); - return GNUNET_SYSERR; - } + { + GNUNET_break (0); + return GNUNET_SYSERR; + } if (NULL == record->sub_system) - { - GNUNET_break(0); - PEERSTORE_destroy_record(record); - return GNUNET_SYSERR; - } - PEERSTORE_destroy_record(record); + { + GNUNET_break (0); + PEERSTORE_destroy_record (record); + return GNUNET_SYSERR; + } + PEERSTORE_destroy_record (record); return GNUNET_OK; } @@ -404,30 +404,30 @@ check_iterate(void *cls, const struct StoreRecordMessage *srm) * @param srm the actual message */ static void -handle_iterate(void *cls, const struct StoreRecordMessage *srm) +handle_iterate (void *cls, const struct StoreRecordMessage *srm) { struct GNUNET_SERVICE_Client *client = cls; struct GNUNET_PEERSTORE_Record *record; - record = PEERSTORE_parse_record_message(srm); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Iterate request: ss `%s', peer `%s', key `%s'\n", - record->sub_system, - GNUNET_i2s(&record->peer), - (NULL == record->key) ? "NULL" : record->key); + record = PEERSTORE_parse_record_message (srm); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Iterate request: ss `%s', peer `%s', key `%s'\n", + record->sub_system, + GNUNET_i2s (&record->peer), + (NULL == record->key) ? "NULL" : record->key); record->client = client; if (GNUNET_OK != - db->iterate_records(db->cls, - record->sub_system, - (ntohs(srm->peer_set)) ? &record->peer : NULL, - record->key, - &record_iterator, - record)) - { - GNUNET_break(0); - GNUNET_SERVICE_client_drop(client); - PEERSTORE_destroy_record(record); - } + db->iterate_records (db->cls, + record->sub_system, + (ntohs (srm->peer_set)) ? &record->peer : NULL, + record->key, + &record_iterator, + record)) + { + GNUNET_break (0); + GNUNET_SERVICE_client_drop (client); + PEERSTORE_destroy_record (record); + } } @@ -438,21 +438,21 @@ handle_iterate(void *cls, const struct StoreRecordMessage *srm) * @param success result */ static void -store_record_continuation(void *cls, int success) +store_record_continuation (void *cls, int success) { struct GNUNET_PEERSTORE_Record *record = cls; if (GNUNET_OK == success) - { - watch_notifier(record); - GNUNET_SERVICE_client_continue(record->client); - } + { + watch_notifier (record); + GNUNET_SERVICE_client_continue (record->client); + } else - { - GNUNET_break(0); - GNUNET_SERVICE_client_drop(record->client); - } - PEERSTORE_destroy_record(record); + { + GNUNET_break (0); + GNUNET_SERVICE_client_drop (record->client); + } + PEERSTORE_destroy_record (record); } @@ -464,23 +464,23 @@ store_record_continuation(void *cls, int success) * @return #GNUNET_OK if @a srm is well-formed */ static int -check_store(void *cls, const struct StoreRecordMessage *srm) +check_store (void *cls, const struct StoreRecordMessage *srm) { struct GNUNET_PEERSTORE_Record *record; - record = PEERSTORE_parse_record_message(srm); + record = PEERSTORE_parse_record_message (srm); if (NULL == record) - { - GNUNET_break(0); - return GNUNET_SYSERR; - } + { + GNUNET_break (0); + return GNUNET_SYSERR; + } if ((NULL == record->sub_system) || (NULL == record->key)) - { - GNUNET_break(0); - PEERSTORE_destroy_record(record); - return GNUNET_SYSERR; - } - PEERSTORE_destroy_record(record); + { + GNUNET_break (0); + PEERSTORE_destroy_record (record); + return GNUNET_SYSERR; + } + PEERSTORE_destroy_record (record); return GNUNET_OK; } @@ -492,36 +492,36 @@ check_store(void *cls, const struct StoreRecordMessage *srm) * @param srm the actual message */ static void -handle_store(void *cls, const struct StoreRecordMessage *srm) +handle_store (void *cls, const struct StoreRecordMessage *srm) { struct GNUNET_SERVICE_Client *client = cls; struct GNUNET_PEERSTORE_Record *record; - record = PEERSTORE_parse_record_message(srm); - GNUNET_log( + record = PEERSTORE_parse_record_message (srm); + GNUNET_log ( GNUNET_ERROR_TYPE_INFO, "Received a store request. Sub system `%s' Peer `%s Key `%s' Options: %u.\n", record->sub_system, - GNUNET_i2s(&record->peer), + GNUNET_i2s (&record->peer), record->key, - (uint32_t)ntohl(srm->options)); + (uint32_t) ntohl (srm->options)); record->client = client; - if (GNUNET_OK != db->store_record(db->cls, - record->sub_system, - &record->peer, - record->key, - record->value, - record->value_size, - record->expiry, - ntohl(srm->options), - &store_record_continuation, - record)) - { - GNUNET_break(0); - PEERSTORE_destroy_record(record); - GNUNET_SERVICE_client_drop(client); - return; - } + if (GNUNET_OK != db->store_record (db->cls, + record->sub_system, + &record->peer, + record->key, + record->value, + record->value_size, + record->expiry, + ntohl (srm->options), + &store_record_continuation, + record)) + { + GNUNET_break (0); + PEERSTORE_destroy_record (record); + GNUNET_SERVICE_client_drop (client); + return; + } } @@ -533,69 +533,69 @@ handle_store(void *cls, const struct StoreRecordMessage *srm) * @param service the initialized service */ 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) { char *database; in_shutdown = GNUNET_NO; cfg = c; - if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(cfg, - "peerstore", - "DATABASE", - &database)) - { - GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, - "peerstore", - "DATABASE"); - GNUNET_SCHEDULER_shutdown(); - return; - } - GNUNET_asprintf(&db_lib_name, "libgnunet_plugin_peerstore_%s", database); - db = GNUNET_PLUGIN_load(db_lib_name, (void *)cfg); - GNUNET_free(database); + if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, + "peerstore", + "DATABASE", + &database)) + { + GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, + "peerstore", + "DATABASE"); + GNUNET_SCHEDULER_shutdown (); + return; + } + GNUNET_asprintf (&db_lib_name, "libgnunet_plugin_peerstore_%s", database); + db = GNUNET_PLUGIN_load (db_lib_name, (void *) cfg); + GNUNET_free (database); if (NULL == db) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - _("Could not load database backend `%s'\n"), - db_lib_name); - GNUNET_SCHEDULER_shutdown(); - return; - } - watchers = GNUNET_CONTAINER_multihashmap_create(10, GNUNET_NO); - expire_task = GNUNET_SCHEDULER_add_now(&cleanup_expired_records, NULL); - GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL); + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _ ("Could not load database backend `%s'\n"), + db_lib_name); + GNUNET_SCHEDULER_shutdown (); + return; + } + watchers = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO); + expire_task = GNUNET_SCHEDULER_add_now (&cleanup_expired_records, NULL); + GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); } /** * Define "main" method using service macro. */ -GNUNET_SERVICE_MAIN( +GNUNET_SERVICE_MAIN ( "peerstore", GNUNET_SERVICE_OPTION_SOFT_SHUTDOWN, &run, &client_connect_cb, &client_disconnect_cb, NULL, - GNUNET_MQ_hd_var_size(store, - GNUNET_MESSAGE_TYPE_PEERSTORE_STORE, - struct StoreRecordMessage, - NULL), - GNUNET_MQ_hd_var_size(iterate, - GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE, - struct StoreRecordMessage, - NULL), - GNUNET_MQ_hd_fixed_size(watch, - GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH, - struct StoreKeyHashMessage, - NULL), - GNUNET_MQ_hd_fixed_size(watch_cancel, - GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_CANCEL, - struct StoreKeyHashMessage, - NULL), - GNUNET_MQ_handler_end()); + GNUNET_MQ_hd_var_size (store, + GNUNET_MESSAGE_TYPE_PEERSTORE_STORE, + struct StoreRecordMessage, + NULL), + GNUNET_MQ_hd_var_size (iterate, + GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE, + struct StoreRecordMessage, + NULL), + GNUNET_MQ_hd_fixed_size (watch, + GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH, + struct StoreKeyHashMessage, + NULL), + GNUNET_MQ_hd_fixed_size (watch_cancel, + GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_CANCEL, + struct StoreKeyHashMessage, + NULL), + GNUNET_MQ_handler_end ()); /* end of gnunet-service-peerstore.c */ diff --git a/src/peerstore/peerstore.h b/src/peerstore/peerstore.h index de5e5908d..0dec03443 100644 --- a/src/peerstore/peerstore.h +++ b/src/peerstore/peerstore.h @@ -33,7 +33,8 @@ GNUNET_NETWORK_STRUCT_BEGIN /** * Message carrying a PEERSTORE record message */ -struct StoreRecordMessage { +struct StoreRecordMessage +{ /** * GNUnet message header */ @@ -85,7 +86,8 @@ struct StoreRecordMessage { /** * Message carrying record key hash */ -struct StoreKeyHashMessage { +struct StoreKeyHashMessage +{ /** * GNUnet message header */ diff --git a/src/peerstore/peerstore_api.c b/src/peerstore/peerstore_api.c index 3ce2c5533..e5881a6b4 100644 --- a/src/peerstore/peerstore_api.c +++ b/src/peerstore/peerstore_api.c @@ -28,7 +28,7 @@ #include "peerstore.h" #include "peerstore_common.h" -#define LOG(kind, ...) GNUNET_log_from(kind, "peerstore-api", __VA_ARGS__) +#define LOG(kind, ...) GNUNET_log_from (kind, "peerstore-api", __VA_ARGS__) /******************************************************************************/ /************************ DATA STRUCTURES ****************************/ @@ -37,7 +37,8 @@ /** * Handle to the PEERSTORE service. */ -struct GNUNET_PEERSTORE_Handle { +struct GNUNET_PEERSTORE_Handle +{ /** * Our configuration. */ @@ -92,7 +93,8 @@ struct GNUNET_PEERSTORE_Handle { /** * Context for a store request */ -struct GNUNET_PEERSTORE_StoreContext { +struct GNUNET_PEERSTORE_StoreContext +{ /** * Kept in a DLL. */ @@ -157,7 +159,8 @@ struct GNUNET_PEERSTORE_StoreContext { /** * Context for a iterate request */ -struct GNUNET_PEERSTORE_IterateContext { +struct GNUNET_PEERSTORE_IterateContext +{ /** * Kept in a DLL. */ @@ -207,7 +210,8 @@ struct GNUNET_PEERSTORE_IterateContext { /** * Context for a watch request */ -struct GNUNET_PEERSTORE_WatchContext { +struct GNUNET_PEERSTORE_WatchContext +{ /** * Kept in a DLL. */ @@ -249,7 +253,7 @@ struct GNUNET_PEERSTORE_WatchContext { * @param cls a `struct GNUNET_PEERSTORE_Handle *h` */ static void -reconnect(void *cls); +reconnect (void *cls); /** @@ -258,32 +262,32 @@ reconnect(void *cls); * @param h peerstore handle to disconnect */ static void -disconnect(struct GNUNET_PEERSTORE_Handle *h) +disconnect (struct GNUNET_PEERSTORE_Handle *h) { struct GNUNET_PEERSTORE_IterateContext *next; for (struct GNUNET_PEERSTORE_IterateContext *ic = h->iterate_head; NULL != ic; ic = next) + { + next = ic->next; + if (GNUNET_YES == ic->iterating) { - next = ic->next; - if (GNUNET_YES == ic->iterating) - { - GNUNET_PEERSTORE_Processor icb; - void *icb_cls; - - icb = ic->callback; - icb_cls = ic->callback_cls; - GNUNET_PEERSTORE_iterate_cancel(ic); - if (NULL != icb) - icb(icb_cls, NULL, "Iteration canceled due to reconnection"); - } + GNUNET_PEERSTORE_Processor icb; + void *icb_cls; + + icb = ic->callback; + icb_cls = ic->callback_cls; + GNUNET_PEERSTORE_iterate_cancel (ic); + if (NULL != icb) + icb (icb_cls, NULL, "Iteration canceled due to reconnection"); } + } if (NULL != h->mq) - { - GNUNET_MQ_destroy(h->mq); - h->mq = NULL; - } + { + GNUNET_MQ_destroy (h->mq); + h->mq = NULL; + } } @@ -294,16 +298,16 @@ disconnect(struct GNUNET_PEERSTORE_Handle *h) * @param h peerstore to reconnect */ static void -disconnect_and_schedule_reconnect(struct GNUNET_PEERSTORE_Handle *h) +disconnect_and_schedule_reconnect (struct GNUNET_PEERSTORE_Handle *h) { - GNUNET_assert(NULL == h->reconnect_task); - disconnect(h); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Scheduling task to reconnect to PEERSTORE service in %s.\n", - GNUNET_STRINGS_relative_time_to_string(h->reconnect_delay, GNUNET_YES)); + GNUNET_assert (NULL == h->reconnect_task); + disconnect (h); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Scheduling task to reconnect to PEERSTORE service in %s.\n", + GNUNET_STRINGS_relative_time_to_string (h->reconnect_delay, GNUNET_YES)); h->reconnect_task = - GNUNET_SCHEDULER_add_delayed(h->reconnect_delay, &reconnect, h); - h->reconnect_delay = GNUNET_TIME_STD_BACKOFF(h->reconnect_delay); + GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, &reconnect, h); + h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay); } @@ -313,7 +317,7 @@ disconnect_and_schedule_reconnect(struct GNUNET_PEERSTORE_Handle *h) * @param cls a `struct GNUNET_PEERSTORE_StoreContext *` */ static void -store_request_sent(void *cls) +store_request_sent (void *cls) { struct GNUNET_PEERSTORE_StoreContext *sc = cls; GNUNET_PEERSTORE_Continuation cont; @@ -321,9 +325,9 @@ store_request_sent(void *cls) cont = sc->cont; cont_cls = sc->cont_cls; - GNUNET_PEERSTORE_store_cancel(sc); + GNUNET_PEERSTORE_store_cancel (sc); if (NULL != cont) - cont(cont_cls, GNUNET_OK); + cont (cont_cls, GNUNET_OK); } @@ -336,14 +340,14 @@ store_request_sent(void *cls) * Function called when we had trouble talking to the service. */ static void -handle_client_error(void *cls, enum GNUNET_MQ_Error error) +handle_client_error (void *cls, enum GNUNET_MQ_Error error) { struct GNUNET_PEERSTORE_Handle *h = cls; - LOG(GNUNET_ERROR_TYPE_ERROR, - "Received an error notification from MQ of type: %d\n", - error); - disconnect_and_schedule_reconnect(h); + LOG (GNUNET_ERROR_TYPE_ERROR, + "Received an error notification from MQ of type: %d\n", + error); + disconnect_and_schedule_reconnect (h); } @@ -356,16 +360,16 @@ handle_client_error(void *cls, enum GNUNET_MQ_Error error) * @return #GNUNET_YES (continue to iterate) */ static int -rewatch_it(void *cls, const struct GNUNET_HashCode *key, void *value) +rewatch_it (void *cls, const struct GNUNET_HashCode *key, void *value) { struct GNUNET_PEERSTORE_Handle *h = cls; struct GNUNET_PEERSTORE_WatchContext *wc = value; struct StoreKeyHashMessage *hm; struct GNUNET_MQ_Envelope *ev; - ev = GNUNET_MQ_msg(hm, GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH); + ev = GNUNET_MQ_msg (hm, GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH); hm->keyhash = wc->keyhash; - GNUNET_MQ_send(h->mq, ev); + GNUNET_MQ_send (h->mq, ev); return GNUNET_YES; } @@ -379,11 +383,11 @@ rewatch_it(void *cls, const struct GNUNET_HashCode *key, void *value) * @return #GNUNET_YES to continue iteration */ static int -destroy_watch(void *cls, const struct GNUNET_HashCode *key, void *value) +destroy_watch (void *cls, const struct GNUNET_HashCode *key, void *value) { struct GNUNET_PEERSTORE_WatchContext *wc = value; - GNUNET_PEERSTORE_watch_cancel(wc); + GNUNET_PEERSTORE_watch_cancel (wc); return GNUNET_YES; } @@ -396,14 +400,14 @@ destroy_watch(void *cls, const struct GNUNET_HashCode *key, void *value) * @param h Handle to the service. */ static void -final_disconnect(struct GNUNET_PEERSTORE_Handle *h) +final_disconnect (struct GNUNET_PEERSTORE_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); } @@ -414,19 +418,19 @@ final_disconnect(struct GNUNET_PEERSTORE_Handle *h) * @return NULL on error */ struct GNUNET_PEERSTORE_Handle * -GNUNET_PEERSTORE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg) +GNUNET_PEERSTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) { struct GNUNET_PEERSTORE_Handle *h; - h = GNUNET_new(struct GNUNET_PEERSTORE_Handle); + h = GNUNET_new (struct GNUNET_PEERSTORE_Handle); h->cfg = cfg; h->disconnecting = GNUNET_NO; - reconnect(h); + reconnect (h); if (NULL == h->mq) - { - GNUNET_free(h); - return NULL; - } + { + GNUNET_free (h); + return NULL; + } return h; } @@ -440,36 +444,36 @@ GNUNET_PEERSTORE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg) * @param sync_first send any pending STORE requests before disconnecting */ void -GNUNET_PEERSTORE_disconnect(struct GNUNET_PEERSTORE_Handle *h, int sync_first) +GNUNET_PEERSTORE_disconnect (struct GNUNET_PEERSTORE_Handle *h, int sync_first) { struct GNUNET_PEERSTORE_IterateContext *ic; struct GNUNET_PEERSTORE_StoreContext *sc; - LOG(GNUNET_ERROR_TYPE_DEBUG, "Disconnecting.\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting.\n"); if (NULL != h->watches) - { - GNUNET_CONTAINER_multihashmap_iterate(h->watches, &destroy_watch, NULL); - GNUNET_CONTAINER_multihashmap_destroy(h->watches); - h->watches = NULL; - } + { + GNUNET_CONTAINER_multihashmap_iterate (h->watches, &destroy_watch, NULL); + GNUNET_CONTAINER_multihashmap_destroy (h->watches); + h->watches = NULL; + } while (NULL != (ic = h->iterate_head)) - { - GNUNET_break(0); - GNUNET_PEERSTORE_iterate_cancel(ic); - } + { + GNUNET_break (0); + GNUNET_PEERSTORE_iterate_cancel (ic); + } if (NULL != h->store_head) + { + if (GNUNET_YES == sync_first) { - if (GNUNET_YES == sync_first) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Delaying disconnection due to pending store requests.\n"); - h->disconnecting = GNUNET_YES; - return; - } - while (NULL != (sc = h->store_head)) - GNUNET_PEERSTORE_store_cancel(sc); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Delaying disconnection due to pending store requests.\n"); + h->disconnecting = GNUNET_YES; + return; } - final_disconnect(h); + while (NULL != (sc = h->store_head)) + GNUNET_PEERSTORE_store_cancel (sc); + } + final_disconnect (h); } @@ -484,17 +488,17 @@ GNUNET_PEERSTORE_disconnect(struct GNUNET_PEERSTORE_Handle *h, int sync_first) * @param sc Store request context */ void -GNUNET_PEERSTORE_store_cancel(struct GNUNET_PEERSTORE_StoreContext *sc) +GNUNET_PEERSTORE_store_cancel (struct GNUNET_PEERSTORE_StoreContext *sc) { struct GNUNET_PEERSTORE_Handle *h = sc->h; - GNUNET_CONTAINER_DLL_remove(sc->h->store_head, sc->h->store_tail, sc); - GNUNET_free(sc->sub_system); - GNUNET_free(sc->value); - GNUNET_free(sc->key); - GNUNET_free(sc); + GNUNET_CONTAINER_DLL_remove (sc->h->store_head, sc->h->store_tail, sc); + GNUNET_free (sc->sub_system); + GNUNET_free (sc->value); + GNUNET_free (sc->key); + GNUNET_free (sc); if ((GNUNET_YES == h->disconnecting) && (NULL == h->store_head)) - final_disconnect(h); + final_disconnect (h); } @@ -515,41 +519,41 @@ GNUNET_PEERSTORE_store_cancel(struct GNUNET_PEERSTORE_StoreContext *sc) * @param cont_cls Closure for @a cont */ struct GNUNET_PEERSTORE_StoreContext * -GNUNET_PEERSTORE_store(struct GNUNET_PEERSTORE_Handle *h, - const char *sub_system, - const struct GNUNET_PeerIdentity *peer, - const char *key, - const void *value, - size_t size, - struct GNUNET_TIME_Absolute expiry, - enum GNUNET_PEERSTORE_StoreOption options, - GNUNET_PEERSTORE_Continuation cont, - void *cont_cls) +GNUNET_PEERSTORE_store (struct GNUNET_PEERSTORE_Handle *h, + const char *sub_system, + const struct GNUNET_PeerIdentity *peer, + const char *key, + const void *value, + size_t size, + struct GNUNET_TIME_Absolute expiry, + enum GNUNET_PEERSTORE_StoreOption options, + GNUNET_PEERSTORE_Continuation cont, + void *cont_cls) { struct GNUNET_MQ_Envelope *ev; struct GNUNET_PEERSTORE_StoreContext *sc; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Storing value (size: %lu) for subsytem `%s', peer `%s', key `%s'\n", - size, - sub_system, - GNUNET_i2s(peer), - key); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Storing value (size: %lu) for subsytem `%s', peer `%s', key `%s'\n", + size, + sub_system, + GNUNET_i2s (peer), + key); ev = - PEERSTORE_create_record_mq_envelope(sub_system, - peer, - key, - value, - size, - expiry, - options, - GNUNET_MESSAGE_TYPE_PEERSTORE_STORE); - sc = GNUNET_new(struct GNUNET_PEERSTORE_StoreContext); - - sc->sub_system = GNUNET_strdup(sub_system); + PEERSTORE_create_record_mq_envelope (sub_system, + peer, + key, + value, + size, + expiry, + options, + GNUNET_MESSAGE_TYPE_PEERSTORE_STORE); + sc = GNUNET_new (struct GNUNET_PEERSTORE_StoreContext); + + sc->sub_system = GNUNET_strdup (sub_system); sc->peer = *peer; - sc->key = GNUNET_strdup(key); - sc->value = GNUNET_memdup(value, size); + sc->key = GNUNET_strdup (key); + sc->value = GNUNET_memdup (value, size); sc->size = size; sc->expiry = expiry; sc->options = options; @@ -557,9 +561,9 @@ GNUNET_PEERSTORE_store(struct GNUNET_PEERSTORE_Handle *h, sc->cont_cls = cont_cls; sc->h = h; - GNUNET_CONTAINER_DLL_insert_tail(h->store_head, h->store_tail, sc); - GNUNET_MQ_notify_sent(ev, &store_request_sent, sc); - GNUNET_MQ_send(h->mq, ev); + GNUNET_CONTAINER_DLL_insert_tail (h->store_head, h->store_tail, sc); + GNUNET_MQ_notify_sent (ev, &store_request_sent, sc); + GNUNET_MQ_send (h->mq, ev); return sc; } @@ -576,7 +580,7 @@ GNUNET_PEERSTORE_store(struct GNUNET_PEERSTORE_Handle *h, * @param msg message received */ static void -handle_iterate_end(void *cls, const struct GNUNET_MessageHeader *msg) +handle_iterate_end (void *cls, const struct GNUNET_MessageHeader *msg) { struct GNUNET_PEERSTORE_Handle *h = cls; struct GNUNET_PEERSTORE_IterateContext *ic; @@ -585,18 +589,18 @@ handle_iterate_end(void *cls, const struct GNUNET_MessageHeader *msg) ic = h->iterate_head; if (NULL == ic) - { - LOG(GNUNET_ERROR_TYPE_ERROR, - _("Unexpected iteration response, this should not happen.\n")); - disconnect_and_schedule_reconnect(h); - return; - } + { + LOG (GNUNET_ERROR_TYPE_ERROR, + _ ("Unexpected iteration response, this should not happen.\n")); + disconnect_and_schedule_reconnect (h); + return; + } callback = ic->callback; callback_cls = ic->callback_cls; ic->iterating = GNUNET_NO; - GNUNET_PEERSTORE_iterate_cancel(ic); + GNUNET_PEERSTORE_iterate_cancel (ic); if (NULL != callback) - callback(callback_cls, NULL, NULL); + callback (callback_cls, NULL, NULL); h->reconnect_delay = GNUNET_TIME_UNIT_ZERO; } @@ -609,7 +613,7 @@ handle_iterate_end(void *cls, const struct GNUNET_MessageHeader *msg) * @param msg message received */ static int -check_iterate_result(void *cls, const struct StoreRecordMessage *msg) +check_iterate_result (void *cls, const struct StoreRecordMessage *msg) { /* we defer validation to #handle_iterate_result */ return GNUNET_OK; @@ -623,7 +627,7 @@ check_iterate_result(void *cls, const struct StoreRecordMessage *msg) * @param msg message received */ static void -handle_iterate_result(void *cls, const struct StoreRecordMessage *msg) +handle_iterate_result (void *cls, const struct StoreRecordMessage *msg) { struct GNUNET_PEERSTORE_Handle *h = cls; struct GNUNET_PEERSTORE_IterateContext *ic; @@ -633,29 +637,29 @@ handle_iterate_result(void *cls, const struct StoreRecordMessage *msg) ic = h->iterate_head; if (NULL == ic) - { - LOG(GNUNET_ERROR_TYPE_ERROR, - _("Unexpected iteration response, this should not happen.\n")); - disconnect_and_schedule_reconnect(h); - return; - } + { + LOG (GNUNET_ERROR_TYPE_ERROR, + _ ("Unexpected iteration response, this should not happen.\n")); + disconnect_and_schedule_reconnect (h); + return; + } ic->iterating = GNUNET_YES; callback = ic->callback; callback_cls = ic->callback_cls; if (NULL == callback) return; - record = PEERSTORE_parse_record_message(msg); + record = PEERSTORE_parse_record_message (msg); if (NULL == record) - { - callback(callback_cls, - NULL, - _("Received a malformed response from service.")); - } + { + callback (callback_cls, + NULL, + _ ("Received a malformed response from service.")); + } else - { - callback(callback_cls, record, NULL); - PEERSTORE_destroy_record(record); - } + { + callback (callback_cls, record, NULL); + PEERSTORE_destroy_record (record); + } } @@ -666,15 +670,15 @@ handle_iterate_result(void *cls, const struct StoreRecordMessage *msg) * @param ic Iterate request context as returned by GNUNET_PEERSTORE_iterate() */ void -GNUNET_PEERSTORE_iterate_cancel(struct GNUNET_PEERSTORE_IterateContext *ic) +GNUNET_PEERSTORE_iterate_cancel (struct GNUNET_PEERSTORE_IterateContext *ic) { if (GNUNET_NO == ic->iterating) - { - GNUNET_CONTAINER_DLL_remove(ic->h->iterate_head, ic->h->iterate_tail, ic); - GNUNET_free(ic->sub_system); - GNUNET_free_non_null(ic->key); - GNUNET_free(ic); - } + { + GNUNET_CONTAINER_DLL_remove (ic->h->iterate_head, ic->h->iterate_tail, ic); + GNUNET_free (ic->sub_system); + GNUNET_free_non_null (ic->key); + GNUNET_free (ic); + } else ic->callback = NULL; } @@ -692,39 +696,39 @@ GNUNET_PEERSTORE_iterate_cancel(struct GNUNET_PEERSTORE_IterateContext *ic) * @return Handle to iteration request */ struct GNUNET_PEERSTORE_IterateContext * -GNUNET_PEERSTORE_iterate(struct GNUNET_PEERSTORE_Handle *h, - const char *sub_system, - const struct GNUNET_PeerIdentity *peer, - const char *key, - GNUNET_PEERSTORE_Processor callback, - void *callback_cls) +GNUNET_PEERSTORE_iterate (struct GNUNET_PEERSTORE_Handle *h, + const char *sub_system, + const struct GNUNET_PeerIdentity *peer, + const char *key, + GNUNET_PEERSTORE_Processor callback, + void *callback_cls) { struct GNUNET_MQ_Envelope *ev; struct GNUNET_PEERSTORE_IterateContext *ic; ev = - PEERSTORE_create_record_mq_envelope(sub_system, - peer, - key, - NULL, - 0, - GNUNET_TIME_UNIT_FOREVER_ABS, - 0, - GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE); - ic = GNUNET_new(struct GNUNET_PEERSTORE_IterateContext); + PEERSTORE_create_record_mq_envelope (sub_system, + peer, + key, + NULL, + 0, + GNUNET_TIME_UNIT_FOREVER_ABS, + 0, + GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE); + ic = GNUNET_new (struct GNUNET_PEERSTORE_IterateContext); ic->callback = callback; ic->callback_cls = callback_cls; ic->h = h; - ic->sub_system = GNUNET_strdup(sub_system); + ic->sub_system = GNUNET_strdup (sub_system); if (NULL != peer) ic->peer = *peer; if (NULL != key) - ic->key = GNUNET_strdup(key); - GNUNET_CONTAINER_DLL_insert_tail(h->iterate_head, h->iterate_tail, ic); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Sending an iterate request for sub system `%s'\n", - sub_system); - GNUNET_MQ_send(h->mq, ev); + ic->key = GNUNET_strdup (key); + GNUNET_CONTAINER_DLL_insert_tail (h->iterate_head, h->iterate_tail, ic); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Sending an iterate request for sub system `%s'\n", + sub_system); + GNUNET_MQ_send (h->mq, ev); return ic; } @@ -740,7 +744,7 @@ GNUNET_PEERSTORE_iterate(struct GNUNET_PEERSTORE_Handle *h, * @param msg message received */ static int -check_watch_record(void *cls, const struct StoreRecordMessage *msg) +check_watch_record (void *cls, const struct StoreRecordMessage *msg) { /* we defer validation to #handle_watch_result */ return GNUNET_OK; @@ -754,35 +758,35 @@ check_watch_record(void *cls, const struct StoreRecordMessage *msg) * @param msg message received */ static void -handle_watch_record(void *cls, const struct StoreRecordMessage *msg) +handle_watch_record (void *cls, const struct StoreRecordMessage *msg) { struct GNUNET_PEERSTORE_Handle *h = cls; struct GNUNET_PEERSTORE_Record *record; struct GNUNET_HashCode keyhash; struct GNUNET_PEERSTORE_WatchContext *wc; - LOG(GNUNET_ERROR_TYPE_DEBUG, "Received a watch record from service.\n"); - record = PEERSTORE_parse_record_message(msg); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Received a watch record from service.\n"); + record = PEERSTORE_parse_record_message (msg); if (NULL == record) - { - disconnect_and_schedule_reconnect(h); - return; - } - PEERSTORE_hash_key(record->sub_system, &record->peer, record->key, &keyhash); + { + disconnect_and_schedule_reconnect (h); + return; + } + PEERSTORE_hash_key (record->sub_system, &record->peer, record->key, &keyhash); // FIXME: what if there are multiple watches for the same key? - wc = GNUNET_CONTAINER_multihashmap_get(h->watches, &keyhash); + wc = GNUNET_CONTAINER_multihashmap_get (h->watches, &keyhash); if (NULL == wc) - { - LOG(GNUNET_ERROR_TYPE_ERROR, - _("Received a watch result for a non existing watch.\n")); - PEERSTORE_destroy_record(record); - disconnect_and_schedule_reconnect(h); - return; - } + { + LOG (GNUNET_ERROR_TYPE_ERROR, + _ ("Received a watch result for a non existing watch.\n")); + PEERSTORE_destroy_record (record); + disconnect_and_schedule_reconnect (h); + return; + } if (NULL != wc->callback) - wc->callback(wc->callback_cls, record, NULL); + wc->callback (wc->callback_cls, record, NULL); h->reconnect_delay = GNUNET_TIME_UNIT_ZERO; - PEERSTORE_destroy_record(record); + PEERSTORE_destroy_record (record); } @@ -792,67 +796,67 @@ handle_watch_record(void *cls, const struct StoreRecordMessage *msg) * @param cls a `struct GNUNET_PEERSTORE_Handle *` */ static void -reconnect(void *cls) +reconnect (void *cls) { struct GNUNET_PEERSTORE_Handle *h = cls; struct GNUNET_MQ_MessageHandler mq_handlers[] = - { GNUNET_MQ_hd_fixed_size(iterate_end, - GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_END, - struct GNUNET_MessageHeader, - h), - GNUNET_MQ_hd_var_size(iterate_result, - GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_RECORD, - struct StoreRecordMessage, - h), - GNUNET_MQ_hd_var_size(watch_record, - GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_RECORD, - struct StoreRecordMessage, - h), - GNUNET_MQ_handler_end() }; + { GNUNET_MQ_hd_fixed_size (iterate_end, + GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_END, + struct GNUNET_MessageHeader, + h), + GNUNET_MQ_hd_var_size (iterate_result, + GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_RECORD, + struct StoreRecordMessage, + h), + GNUNET_MQ_hd_var_size (watch_record, + GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_RECORD, + struct StoreRecordMessage, + h), + GNUNET_MQ_handler_end () }; struct GNUNET_MQ_Envelope *ev; h->reconnect_task = NULL; - LOG(GNUNET_ERROR_TYPE_DEBUG, "Reconnecting...\n"); - h->mq = GNUNET_CLIENT_connect(h->cfg, - "peerstore", - mq_handlers, - &handle_client_error, - h); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Reconnecting...\n"); + h->mq = GNUNET_CLIENT_connect (h->cfg, + "peerstore", + mq_handlers, + &handle_client_error, + h); if (NULL == h->mq) return; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Resending pending requests after reconnect.\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Resending pending requests after reconnect.\n"); if (NULL != h->watches) - GNUNET_CONTAINER_multihashmap_iterate(h->watches, &rewatch_it, h); + GNUNET_CONTAINER_multihashmap_iterate (h->watches, &rewatch_it, h); for (struct GNUNET_PEERSTORE_IterateContext *ic = h->iterate_head; NULL != ic; ic = ic->next) - { - ev = - PEERSTORE_create_record_mq_envelope(ic->sub_system, - &ic->peer, - ic->key, - NULL, - 0, - GNUNET_TIME_UNIT_FOREVER_ABS, - 0, - GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE); - GNUNET_MQ_send(h->mq, ev); - } + { + ev = + PEERSTORE_create_record_mq_envelope (ic->sub_system, + &ic->peer, + ic->key, + NULL, + 0, + GNUNET_TIME_UNIT_FOREVER_ABS, + 0, + GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE); + GNUNET_MQ_send (h->mq, ev); + } for (struct GNUNET_PEERSTORE_StoreContext *sc = h->store_head; NULL != sc; sc = sc->next) - { - ev = - PEERSTORE_create_record_mq_envelope(sc->sub_system, - &sc->peer, - sc->key, - sc->value, - sc->size, - sc->expiry, - sc->options, - GNUNET_MESSAGE_TYPE_PEERSTORE_STORE); - GNUNET_MQ_notify_sent(ev, &store_request_sent, sc); - GNUNET_MQ_send(h->mq, ev); - } + { + ev = + PEERSTORE_create_record_mq_envelope (sc->sub_system, + &sc->peer, + sc->key, + sc->value, + sc->size, + sc->expiry, + sc->options, + GNUNET_MESSAGE_TYPE_PEERSTORE_STORE); + GNUNET_MQ_notify_sent (ev, &store_request_sent, sc); + GNUNET_MQ_send (h->mq, ev); + } } @@ -862,20 +866,20 @@ reconnect(void *cls) * @param wc handle to the watch request */ void -GNUNET_PEERSTORE_watch_cancel(struct GNUNET_PEERSTORE_WatchContext *wc) +GNUNET_PEERSTORE_watch_cancel (struct GNUNET_PEERSTORE_WatchContext *wc) { struct GNUNET_PEERSTORE_Handle *h = wc->h; struct GNUNET_MQ_Envelope *ev; struct StoreKeyHashMessage *hm; - LOG(GNUNET_ERROR_TYPE_DEBUG, "Canceling watch.\n"); - ev = GNUNET_MQ_msg(hm, GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_CANCEL); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Canceling watch.\n"); + ev = GNUNET_MQ_msg (hm, GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_CANCEL); hm->keyhash = wc->keyhash; - GNUNET_MQ_send(h->mq, ev); - GNUNET_assert( + GNUNET_MQ_send (h->mq, ev); + GNUNET_assert ( GNUNET_YES == - GNUNET_CONTAINER_multihashmap_remove(h->watches, &wc->keyhash, wc)); - GNUNET_free(wc); + GNUNET_CONTAINER_multihashmap_remove (h->watches, &wc->keyhash, wc)); + GNUNET_free (wc); } @@ -892,37 +896,37 @@ GNUNET_PEERSTORE_watch_cancel(struct GNUNET_PEERSTORE_WatchContext *wc) * @return Handle to watch request */ struct GNUNET_PEERSTORE_WatchContext * -GNUNET_PEERSTORE_watch(struct GNUNET_PEERSTORE_Handle *h, - const char *sub_system, - const struct GNUNET_PeerIdentity *peer, - const char *key, - GNUNET_PEERSTORE_Processor callback, - void *callback_cls) +GNUNET_PEERSTORE_watch (struct GNUNET_PEERSTORE_Handle *h, + const char *sub_system, + const struct GNUNET_PeerIdentity *peer, + const char *key, + GNUNET_PEERSTORE_Processor callback, + void *callback_cls) { struct GNUNET_MQ_Envelope *ev; struct StoreKeyHashMessage *hm; struct GNUNET_PEERSTORE_WatchContext *wc; - ev = GNUNET_MQ_msg(hm, GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH); - PEERSTORE_hash_key(sub_system, peer, key, &hm->keyhash); - wc = GNUNET_new(struct GNUNET_PEERSTORE_WatchContext); + ev = GNUNET_MQ_msg (hm, GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH); + PEERSTORE_hash_key (sub_system, peer, key, &hm->keyhash); + wc = GNUNET_new (struct GNUNET_PEERSTORE_WatchContext); wc->callback = callback; wc->callback_cls = callback_cls; wc->h = h; wc->keyhash = hm->keyhash; if (NULL == h->watches) - h->watches = GNUNET_CONTAINER_multihashmap_create(5, GNUNET_NO); - GNUNET_assert(GNUNET_OK == GNUNET_CONTAINER_multihashmap_put( - h->watches, - &wc->keyhash, - wc, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Sending a watch request for subsystem `%s', peer `%s', key `%s'.\n", - sub_system, - GNUNET_i2s(peer), - key); - GNUNET_MQ_send(h->mq, ev); + h->watches = GNUNET_CONTAINER_multihashmap_create (5, GNUNET_NO); + GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put ( + h->watches, + &wc->keyhash, + wc, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Sending a watch request for subsystem `%s', peer `%s', key `%s'.\n", + sub_system, + GNUNET_i2s (peer), + key); + GNUNET_MQ_send (h->mq, ev); return wc; } diff --git a/src/peerstore/peerstore_common.c b/src/peerstore/peerstore_common.c index 7fceb1ec0..0f6a73fa6 100644 --- a/src/peerstore/peerstore_common.c +++ b/src/peerstore/peerstore_common.c @@ -30,10 +30,10 @@ * */ void -PEERSTORE_hash_key(const char *sub_system, - const struct GNUNET_PeerIdentity *peer, - const char *key, - struct GNUNET_HashCode *ret) +PEERSTORE_hash_key (const char *sub_system, + const struct GNUNET_PeerIdentity *peer, + const char *key, + struct GNUNET_HashCode *ret) { size_t sssize; size_t psize; @@ -42,19 +42,19 @@ PEERSTORE_hash_key(const char *sub_system, void *block; void *blockptr; - sssize = strlen(sub_system) + 1; + sssize = strlen (sub_system) + 1; psize = sizeof(struct GNUNET_PeerIdentity); - ksize = strlen(key) + 1; + ksize = strlen (key) + 1; totalsize = sssize + psize + ksize; - block = GNUNET_malloc(totalsize); + block = GNUNET_malloc (totalsize); blockptr = block; - GNUNET_memcpy(blockptr, sub_system, sssize); + GNUNET_memcpy (blockptr, sub_system, sssize); blockptr += sssize; - GNUNET_memcpy(blockptr, peer, psize); + GNUNET_memcpy (blockptr, peer, psize); blockptr += psize; - GNUNET_memcpy(blockptr, key, ksize); - GNUNET_CRYPTO_hash(block, totalsize, ret); - GNUNET_free(block); + GNUNET_memcpy (blockptr, key, ksize); + GNUNET_CRYPTO_hash (block, totalsize, ret); + GNUNET_free (block); } @@ -72,14 +72,14 @@ PEERSTORE_hash_key(const char *sub_system, * @return pointer to record message struct */ struct GNUNET_MQ_Envelope * -PEERSTORE_create_record_mq_envelope(const char *sub_system, - const struct GNUNET_PeerIdentity *peer, - const char *key, - const void *value, - size_t value_size, - struct GNUNET_TIME_Absolute expiry, - enum GNUNET_PEERSTORE_StoreOption options, - uint16_t msg_type) +PEERSTORE_create_record_mq_envelope (const char *sub_system, + const struct GNUNET_PeerIdentity *peer, + const char *key, + const void *value, + size_t value_size, + struct GNUNET_TIME_Absolute expiry, + enum GNUNET_PEERSTORE_StoreOption options, + uint16_t msg_type) { struct StoreRecordMessage *srm; struct GNUNET_MQ_Envelope *ev; @@ -88,32 +88,32 @@ PEERSTORE_create_record_mq_envelope(const char *sub_system, size_t msg_size; void *dummy; - GNUNET_assert(NULL != sub_system); - ss_size = strlen(sub_system) + 1; + GNUNET_assert (NULL != sub_system); + ss_size = strlen (sub_system) + 1; if (NULL == key) key_size = 0; else - key_size = strlen(key) + 1; + key_size = strlen (key) + 1; msg_size = ss_size + key_size + value_size; - ev = GNUNET_MQ_msg_extra(srm, msg_size, msg_type); - srm->key_size = htons(key_size); - srm->expiry = GNUNET_TIME_absolute_hton(expiry); + ev = GNUNET_MQ_msg_extra (srm, msg_size, msg_type); + srm->key_size = htons (key_size); + srm->expiry = GNUNET_TIME_absolute_hton (expiry); if (NULL == peer) - srm->peer_set = htons(GNUNET_NO); + srm->peer_set = htons (GNUNET_NO); else - { - srm->peer_set = htons(GNUNET_YES); - srm->peer = *peer; - } - srm->sub_system_size = htons(ss_size); - srm->value_size = htons(value_size); - srm->options = htonl(options); + { + srm->peer_set = htons (GNUNET_YES); + srm->peer = *peer; + } + srm->sub_system_size = htons (ss_size); + srm->value_size = htons (value_size); + srm->options = htonl (options); dummy = &srm[1]; - GNUNET_memcpy(dummy, sub_system, ss_size); + GNUNET_memcpy (dummy, sub_system, ss_size); dummy += ss_size; - GNUNET_memcpy(dummy, key, key_size); + GNUNET_memcpy (dummy, key, key_size); dummy += key_size; - GNUNET_memcpy(dummy, value, value_size); + GNUNET_memcpy (dummy, value, value_size); return ev; } @@ -125,7 +125,7 @@ PEERSTORE_create_record_mq_envelope(const char *sub_system, * @return Pointer to record or NULL if error */ struct GNUNET_PEERSTORE_Record * -PEERSTORE_parse_record_message(const struct StoreRecordMessage *srm) +PEERSTORE_parse_record_message (const struct StoreRecordMessage *srm) { struct GNUNET_PEERSTORE_Record *record; uint16_t req_size; @@ -134,39 +134,39 @@ PEERSTORE_parse_record_message(const struct StoreRecordMessage *srm) uint16_t value_size; char *dummy; - req_size = ntohs(srm->header.size) - sizeof(*srm); - ss_size = ntohs(srm->sub_system_size); - key_size = ntohs(srm->key_size); - value_size = ntohs(srm->value_size); + req_size = ntohs (srm->header.size) - sizeof(*srm); + ss_size = ntohs (srm->sub_system_size); + key_size = ntohs (srm->key_size); + value_size = ntohs (srm->value_size); if (ss_size + key_size + value_size != req_size) - { - GNUNET_break(0); - return NULL; - } - record = GNUNET_new(struct GNUNET_PEERSTORE_Record); - if (GNUNET_YES == ntohs(srm->peer_set)) - { - record->peer = srm->peer; - } - record->expiry = GNUNET_TIME_absolute_ntoh(srm->expiry); - dummy = (char *)&srm[1]; + { + GNUNET_break (0); + return NULL; + } + record = GNUNET_new (struct GNUNET_PEERSTORE_Record); + if (GNUNET_YES == ntohs (srm->peer_set)) + { + record->peer = srm->peer; + } + record->expiry = GNUNET_TIME_absolute_ntoh (srm->expiry); + dummy = (char *) &srm[1]; if (ss_size > 0) - { - record->sub_system = GNUNET_strdup(dummy); - dummy += ss_size; - } + { + record->sub_system = GNUNET_strdup (dummy); + dummy += ss_size; + } if (key_size > 0) - { - record->key = GNUNET_strdup(dummy); - dummy += key_size; - } + { + record->key = GNUNET_strdup (dummy); + dummy += key_size; + } if (value_size > 0) - { - record->value = GNUNET_malloc(value_size); - GNUNET_memcpy(record->value, - dummy, - value_size); - } + { + record->value = GNUNET_malloc (value_size); + GNUNET_memcpy (record->value, + dummy, + value_size); + } record->value_size = value_size; return record; } @@ -178,16 +178,16 @@ PEERSTORE_parse_record_message(const struct StoreRecordMessage *srm) * @param record */ void -PEERSTORE_destroy_record(struct GNUNET_PEERSTORE_Record *record) +PEERSTORE_destroy_record (struct GNUNET_PEERSTORE_Record *record) { if (NULL != record->sub_system) - GNUNET_free(record->sub_system); + GNUNET_free (record->sub_system); if (NULL != record->key) - GNUNET_free(record->key); + GNUNET_free (record->key); if (NULL != record->value) - { - GNUNET_free(record->value); - record->value = 0; - } - GNUNET_free(record); + { + GNUNET_free (record->value); + record->value = 0; + } + GNUNET_free (record); } diff --git a/src/peerstore/peerstore_common.h b/src/peerstore/peerstore_common.h index 6379f61a6..f5352f5a5 100644 --- a/src/peerstore/peerstore_common.h +++ b/src/peerstore/peerstore_common.h @@ -31,10 +31,10 @@ * */ void -PEERSTORE_hash_key(const char *sub_system, - const struct GNUNET_PeerIdentity *peer, - const char *key, - struct GNUNET_HashCode *ret); +PEERSTORE_hash_key (const char *sub_system, + const struct GNUNET_PeerIdentity *peer, + const char *key, + struct GNUNET_HashCode *ret); /** @@ -51,14 +51,14 @@ PEERSTORE_hash_key(const char *sub_system, * @return pointer to record message struct */ struct GNUNET_MQ_Envelope * -PEERSTORE_create_record_mq_envelope(const char *sub_system, - const struct GNUNET_PeerIdentity *peer, - const char *key, - const void *value, - size_t value_size, - struct GNUNET_TIME_Absolute expiry, - enum GNUNET_PEERSTORE_StoreOption options, - uint16_t msg_type); +PEERSTORE_create_record_mq_envelope (const char *sub_system, + const struct GNUNET_PeerIdentity *peer, + const char *key, + const void *value, + size_t value_size, + struct GNUNET_TIME_Absolute expiry, + enum GNUNET_PEERSTORE_StoreOption options, + uint16_t msg_type); /** @@ -68,7 +68,7 @@ PEERSTORE_create_record_mq_envelope(const char *sub_system, * @return Pointer to record or NULL on error */ struct GNUNET_PEERSTORE_Record * -PEERSTORE_parse_record_message(const struct StoreRecordMessage *srm); +PEERSTORE_parse_record_message (const struct StoreRecordMessage *srm); /** @@ -77,6 +77,6 @@ PEERSTORE_parse_record_message(const struct StoreRecordMessage *srm); * @param record */ void -PEERSTORE_destroy_record(struct GNUNET_PEERSTORE_Record *record); +PEERSTORE_destroy_record (struct GNUNET_PEERSTORE_Record *record); /* end of peerstore_common.h */ diff --git a/src/peerstore/perf_peerstore_store.c b/src/peerstore/perf_peerstore_store.c index 392dbbb03..bdff19cb5 100644 --- a/src/peerstore/perf_peerstore_store.c +++ b/src/peerstore/perf_peerstore_store.c @@ -40,68 +40,68 @@ static char *v = "test_peerstore_stress_val"; static int count = 0; static void -disconnect() +disconnect () { if (NULL != h) - GNUNET_PEERSTORE_disconnect(h, GNUNET_YES); - GNUNET_SCHEDULER_shutdown(); + GNUNET_PEERSTORE_disconnect (h, GNUNET_YES); + GNUNET_SCHEDULER_shutdown (); } static void -store() +store () { - GNUNET_PEERSTORE_store(h, ss, &p, k, v, strlen(v) + 1, - GNUNET_TIME_UNIT_FOREVER_ABS, - (count == - 0) ? GNUNET_PEERSTORE_STOREOPTION_REPLACE : - GNUNET_PEERSTORE_STOREOPTION_MULTIPLE, NULL, NULL); + GNUNET_PEERSTORE_store (h, ss, &p, k, v, strlen (v) + 1, + GNUNET_TIME_UNIT_FOREVER_ABS, + (count == + 0) ? GNUNET_PEERSTORE_STOREOPTION_REPLACE : + GNUNET_PEERSTORE_STOREOPTION_MULTIPLE, NULL, NULL); count++; } static void -watch_cb(void *cls, const struct GNUNET_PEERSTORE_Record *record, - const char *emsg) +watch_cb (void *cls, const struct GNUNET_PEERSTORE_Record *record, + const char *emsg) { - GNUNET_assert(NULL == emsg); + GNUNET_assert (NULL == emsg); if (STORES == count) - { - ok = 0; - disconnect(); - } + { + ok = 0; + disconnect (); + } else - store(); + store (); } static void -run(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, - struct GNUNET_TESTING_Peer *peer) +run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, + struct GNUNET_TESTING_Peer *peer) { - memset(&p, 5, sizeof(p)); - h = GNUNET_PEERSTORE_connect(cfg); - GNUNET_assert(NULL != h); - GNUNET_PEERSTORE_watch(h, ss, &p, k, &watch_cb, NULL); - store(); + memset (&p, 5, sizeof(p)); + h = GNUNET_PEERSTORE_connect (cfg); + GNUNET_assert (NULL != h); + GNUNET_PEERSTORE_watch (h, ss, &p, k, &watch_cb, NULL); + store (); } int -main(int argc, char *argv[]) +main (int argc, char *argv[]) { struct GNUNET_TIME_Absolute start; struct GNUNET_TIME_Relative diff; - start = GNUNET_TIME_absolute_get(); + start = GNUNET_TIME_absolute_get (); if (0 != - GNUNET_TESTING_service_run("perf-peerstore-store", "peerstore", - "test_peerstore_api_data.conf", &run, NULL)) + GNUNET_TESTING_service_run ("perf-peerstore-store", "peerstore", + "test_peerstore_api_data.conf", &run, NULL)) return 1; - diff = GNUNET_TIME_absolute_get_duration(start); - fprintf(stderr, "Stored and retrieved %d records in %s (%s).\n", STORES, - GNUNET_STRINGS_relative_time_to_string(diff, GNUNET_YES), - GNUNET_STRINGS_relative_time_to_string(diff, GNUNET_NO)); + diff = GNUNET_TIME_absolute_get_duration (start); + fprintf (stderr, "Stored and retrieved %d records in %s (%s).\n", STORES, + GNUNET_STRINGS_relative_time_to_string (diff, GNUNET_YES), + GNUNET_STRINGS_relative_time_to_string (diff, GNUNET_NO)); return ok; } diff --git a/src/peerstore/plugin_peerstore_flat.c b/src/peerstore/plugin_peerstore_flat.c index 749e270e4..224664685 100644 --- a/src/peerstore/plugin_peerstore_flat.c +++ b/src/peerstore/plugin_peerstore_flat.c @@ -32,7 +32,8 @@ /** * Context for all functions in this plugin. */ -struct Plugin { +struct Plugin +{ /** * Configuration handle */ @@ -96,23 +97,23 @@ struct Plugin { static int -delete_entries(void *cls, - const struct GNUNET_HashCode *key, - void *value) +delete_entries (void *cls, + const struct GNUNET_HashCode *key, + void *value) { struct Plugin *plugin = cls; struct GNUNET_PEERSTORE_Record *entry = value; - if (0 != strcmp(plugin->iter_key, entry->key)) + if (0 != strcmp (plugin->iter_key, entry->key)) return GNUNET_YES; - if (0 != memcmp(plugin->iter_peer, - &entry->peer, - sizeof(struct GNUNET_PeerIdentity))) + if (0 != memcmp (plugin->iter_peer, + &entry->peer, + sizeof(struct GNUNET_PeerIdentity))) return GNUNET_YES; - if (0 != strcmp(plugin->iter_sub_system, entry->sub_system)) + if (0 != strcmp (plugin->iter_sub_system, entry->sub_system)) return GNUNET_YES; - GNUNET_CONTAINER_multihashmap_remove(plugin->hm, key, value); + GNUNET_CONTAINER_multihashmap_remove (plugin->hm, key, value); plugin->deleted_entries++; return GNUNET_YES; } @@ -128,9 +129,9 @@ delete_entries(void *cls, * @return number of deleted records */ static int -peerstore_flat_delete_records(void *cls, const char *sub_system, - const struct GNUNET_PeerIdentity *peer, - const char *key) +peerstore_flat_delete_records (void *cls, const char *sub_system, + const struct GNUNET_PeerIdentity *peer, + const char *key) { struct Plugin *plugin = cls; @@ -139,25 +140,25 @@ peerstore_flat_delete_records(void *cls, const char *sub_system, plugin->iter_key = key; plugin->deleted_entries = 0; - GNUNET_CONTAINER_multihashmap_iterate(plugin->hm, - &delete_entries, - plugin); + GNUNET_CONTAINER_multihashmap_iterate (plugin->hm, + &delete_entries, + plugin); return plugin->deleted_entries; } static int -expire_entries(void *cls, - const struct GNUNET_HashCode *key, - void *value) +expire_entries (void *cls, + const struct GNUNET_HashCode *key, + void *value) { struct Plugin *plugin = cls; struct GNUNET_PEERSTORE_Record *entry = value; if (entry->expiry.abs_value_us < plugin->iter_now.abs_value_us) - { - GNUNET_CONTAINER_multihashmap_remove(plugin->hm, key, value); - plugin->exp_changes++; - } + { + GNUNET_CONTAINER_multihashmap_remove (plugin->hm, key, value); + plugin->exp_changes++; + } return GNUNET_YES; } @@ -174,49 +175,49 @@ expire_entries(void *cls, * called */ static int -peerstore_flat_expire_records(void *cls, struct GNUNET_TIME_Absolute now, - GNUNET_PEERSTORE_Continuation cont, - void *cont_cls) +peerstore_flat_expire_records (void *cls, struct GNUNET_TIME_Absolute now, + GNUNET_PEERSTORE_Continuation cont, + void *cont_cls) { struct Plugin *plugin = cls; plugin->exp_changes = 0; plugin->iter_now = now; - GNUNET_CONTAINER_multihashmap_iterate(plugin->hm, - &expire_entries, - plugin); + GNUNET_CONTAINER_multihashmap_iterate (plugin->hm, + &expire_entries, + plugin); if (NULL != cont) - { - cont(cont_cls, plugin->exp_changes); - } + { + cont (cont_cls, plugin->exp_changes); + } return GNUNET_OK; } static int -iterate_entries(void *cls, - const struct GNUNET_HashCode *key, - void *value) +iterate_entries (void *cls, + const struct GNUNET_HashCode *key, + void *value) { struct Plugin *plugin = cls; struct GNUNET_PEERSTORE_Record *entry = value; if ((NULL != plugin->iter_peer) && - (0 != memcmp(plugin->iter_peer, - &entry->peer, - sizeof(struct GNUNET_PeerIdentity)))) - { - return GNUNET_YES; - } + (0 != memcmp (plugin->iter_peer, + &entry->peer, + sizeof(struct GNUNET_PeerIdentity)))) + { + return GNUNET_YES; + } if ((NULL != plugin->iter_key) && - (0 != strcmp(plugin->iter_key, - entry->key))) - { - return GNUNET_YES; - } + (0 != strcmp (plugin->iter_key, + entry->key))) + { + return GNUNET_YES; + } if (NULL != plugin->iter) - plugin->iter(plugin->iter_cls, entry, NULL); + plugin->iter (plugin->iter_cls, entry, NULL); plugin->iter_result_found = GNUNET_YES; return GNUNET_YES; } @@ -236,11 +237,11 @@ iterate_entries(void *cls, * called */ static int -peerstore_flat_iterate_records(void *cls, const char *sub_system, - const struct GNUNET_PeerIdentity *peer, - const char *key, - GNUNET_PEERSTORE_Processor iter, - void *iter_cls) +peerstore_flat_iterate_records (void *cls, const char *sub_system, + const struct GNUNET_PeerIdentity *peer, + const char *key, + GNUNET_PEERSTORE_Processor iter, + void *iter_cls) { struct Plugin *plugin = cls; @@ -250,11 +251,11 @@ peerstore_flat_iterate_records(void *cls, const char *sub_system, plugin->iter_sub_system = sub_system; plugin->iter_key = key; - GNUNET_CONTAINER_multihashmap_iterate(plugin->hm, - &iterate_entries, - plugin); + GNUNET_CONTAINER_multihashmap_iterate (plugin->hm, + &iterate_entries, + plugin); if (NULL != iter) - iter(iter_cls, NULL, NULL); + iter (iter_cls, NULL, NULL); return GNUNET_OK; } @@ -277,13 +278,13 @@ peerstore_flat_iterate_records(void *cls, const char *sub_system, * @return #GNUNET_OK on success, else #GNUNET_SYSERR and cont is not called */ static int -peerstore_flat_store_record(void *cls, const char *sub_system, - const struct GNUNET_PeerIdentity *peer, - const char *key, const void *value, size_t size, - struct GNUNET_TIME_Absolute expiry, - enum GNUNET_PEERSTORE_StoreOption options, - GNUNET_PEERSTORE_Continuation cont, - void *cont_cls) +peerstore_flat_store_record (void *cls, const char *sub_system, + const struct GNUNET_PeerIdentity *peer, + const char *key, const void *value, size_t size, + struct GNUNET_TIME_Absolute expiry, + enum GNUNET_PEERSTORE_StoreOption options, + GNUNET_PEERSTORE_Continuation cont, + void *cont_cls) { struct Plugin *plugin = cls; struct GNUNET_HashCode hkey; @@ -291,33 +292,33 @@ peerstore_flat_store_record(void *cls, const char *sub_system, const char *peer_id; - entry = GNUNET_new(struct GNUNET_PEERSTORE_Record); - entry->sub_system = GNUNET_strdup(sub_system); - entry->key = GNUNET_strdup(key); - entry->value = GNUNET_malloc(size); - GNUNET_memcpy(entry->value, value, size); + entry = GNUNET_new (struct GNUNET_PEERSTORE_Record); + entry->sub_system = GNUNET_strdup (sub_system); + entry->key = GNUNET_strdup (key); + entry->value = GNUNET_malloc (size); + GNUNET_memcpy (entry->value, value, size); entry->value_size = size; entry->peer = *peer; entry->expiry = expiry; - peer_id = GNUNET_i2s(peer); - GNUNET_CRYPTO_hash(peer_id, - strlen(peer_id), - &hkey); + peer_id = GNUNET_i2s (peer); + GNUNET_CRYPTO_hash (peer_id, + strlen (peer_id), + &hkey); if (GNUNET_PEERSTORE_STOREOPTION_REPLACE == options) - { - peerstore_flat_delete_records(cls, sub_system, peer, key); - } - - GNUNET_CONTAINER_multihashmap_put(plugin->hm, - &hkey, - entry, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); + { + peerstore_flat_delete_records (cls, sub_system, peer, key); + } + + GNUNET_CONTAINER_multihashmap_put (plugin->hm, + &hkey, + entry, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); if (NULL != cont) - { - cont(cont_cls, GNUNET_OK); - } + { + cont (cont_cls, GNUNET_OK); + } return GNUNET_OK; } @@ -331,7 +332,7 @@ peerstore_flat_store_record(void *cls, const char *sub_system, * @return GNUNET_OK on success */ static int -database_setup(struct Plugin *plugin) +database_setup (struct Plugin *plugin) { char *afsdir; char *key; @@ -348,139 +349,139 @@ database_setup(struct Plugin *plugin) char *line; if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_filename(plugin->cfg, "peerstore-flat", - "FILENAME", &afsdir)) + GNUNET_CONFIGURATION_get_value_filename (plugin->cfg, "peerstore-flat", + "FILENAME", &afsdir)) + { + GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "peerstore-flat", + "FILENAME"); + return GNUNET_SYSERR; + } + if (GNUNET_OK != GNUNET_DISK_file_test (afsdir)) + { + if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (afsdir)) { - GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, "peerstore-flat", - "FILENAME"); + GNUNET_break (0); + GNUNET_free (afsdir); return GNUNET_SYSERR; } - if (GNUNET_OK != GNUNET_DISK_file_test(afsdir)) - { - if (GNUNET_OK != GNUNET_DISK_directory_create_for_file(afsdir)) - { - GNUNET_break(0); - GNUNET_free(afsdir); - return GNUNET_SYSERR; - } - } + } /* afsdir should be UTF-8-encoded. If it isn't, it's a bug */ plugin->fn = afsdir; - fh = GNUNET_DISK_file_open(afsdir, - GNUNET_DISK_OPEN_CREATE | - GNUNET_DISK_OPEN_READWRITE, - GNUNET_DISK_PERM_USER_WRITE | - GNUNET_DISK_PERM_USER_READ); + fh = GNUNET_DISK_file_open (afsdir, + GNUNET_DISK_OPEN_CREATE + | GNUNET_DISK_OPEN_READWRITE, + GNUNET_DISK_PERM_USER_WRITE + | GNUNET_DISK_PERM_USER_READ); if (NULL == fh) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - _("Unable to initialize file: %s.\n"), - afsdir); - return GNUNET_SYSERR; - } + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _ ("Unable to initialize file: %s.\n"), + afsdir); + return GNUNET_SYSERR; + } /* Load data from file into hashmap */ - plugin->hm = GNUNET_CONTAINER_multihashmap_create(10, - GNUNET_NO); - - if (GNUNET_SYSERR == GNUNET_DISK_file_size(afsdir, - &size, - GNUNET_YES, - GNUNET_YES)) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - _("Unable to get filesize: %s.\n"), - afsdir); - return GNUNET_SYSERR; - } - - buffer = GNUNET_malloc(size + 1); - - if (GNUNET_SYSERR == GNUNET_DISK_file_read(fh, - buffer, - size)) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - _("Unable to read file: %s.\n"), - afsdir); - GNUNET_DISK_file_close(fh); - GNUNET_free(buffer); - return GNUNET_SYSERR; - } + plugin->hm = GNUNET_CONTAINER_multihashmap_create (10, + GNUNET_NO); + + if (GNUNET_SYSERR == GNUNET_DISK_file_size (afsdir, + &size, + GNUNET_YES, + GNUNET_YES)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _ ("Unable to get filesize: %s.\n"), + afsdir); + return GNUNET_SYSERR; + } + + buffer = GNUNET_malloc (size + 1); + + if (GNUNET_SYSERR == GNUNET_DISK_file_read (fh, + buffer, + size)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _ ("Unable to read file: %s.\n"), + afsdir); + GNUNET_DISK_file_close (fh); + GNUNET_free (buffer); + return GNUNET_SYSERR; + } buffer[size] = '\0'; - GNUNET_DISK_file_close(fh); + GNUNET_DISK_file_close (fh); if (0 < size) + { + line = strtok (buffer, "\n"); + while (line != NULL) { - line = strtok(buffer, "\n"); - while (line != NULL) - { - sub_system = strtok(line, ","); - if (NULL == sub_system) - break; - peer = strtok(NULL, ","); - if (NULL == peer) - break; - key = strtok(NULL, ","); - if (NULL == key) - break; - value = strtok(NULL, ","); - if (NULL == value) - break; - expiry = strtok(NULL, ","); - if (NULL == expiry) - break; - entry = GNUNET_new(struct GNUNET_PEERSTORE_Record); - entry->sub_system = GNUNET_strdup(sub_system); - entry->key = GNUNET_strdup(key); - { - size_t s; - char *o; - - o = NULL; - s = GNUNET_STRINGS_base64_decode(peer, - strlen(peer), - (void**)&o); - if (sizeof(struct GNUNET_PeerIdentity) == s) - GNUNET_memcpy(&entry->peer, - o, - s); - else - GNUNET_break(0); - GNUNET_free_non_null(o); - } - entry->value_size = GNUNET_STRINGS_base64_decode(value, - strlen(value), - (void**)&entry->value); - if (GNUNET_SYSERR == - GNUNET_STRINGS_fancy_time_to_absolute(expiry, - &entry->expiry)) - { - GNUNET_free(entry->sub_system); - GNUNET_free(entry->key); - GNUNET_free(entry); - break; - } - peer_id = GNUNET_i2s(&entry->peer); - GNUNET_CRYPTO_hash(peer_id, - strlen(peer_id), - &hkey); - - GNUNET_assert(GNUNET_OK == GNUNET_CONTAINER_multihashmap_put(plugin->hm, - &hkey, - entry, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); - } + sub_system = strtok (line, ","); + if (NULL == sub_system) + break; + peer = strtok (NULL, ","); + if (NULL == peer) + break; + key = strtok (NULL, ","); + if (NULL == key) + break; + value = strtok (NULL, ","); + if (NULL == value) + break; + expiry = strtok (NULL, ","); + if (NULL == expiry) + break; + entry = GNUNET_new (struct GNUNET_PEERSTORE_Record); + entry->sub_system = GNUNET_strdup (sub_system); + entry->key = GNUNET_strdup (key); + { + size_t s; + char *o; + + o = NULL; + s = GNUNET_STRINGS_base64_decode (peer, + strlen (peer), + (void**) &o); + if (sizeof(struct GNUNET_PeerIdentity) == s) + GNUNET_memcpy (&entry->peer, + o, + s); + else + GNUNET_break (0); + GNUNET_free_non_null (o); + } + entry->value_size = GNUNET_STRINGS_base64_decode (value, + strlen (value), + (void**) &entry->value); + if (GNUNET_SYSERR == + GNUNET_STRINGS_fancy_time_to_absolute (expiry, + &entry->expiry)) + { + GNUNET_free (entry->sub_system); + GNUNET_free (entry->key); + GNUNET_free (entry); + break; + } + peer_id = GNUNET_i2s (&entry->peer); + GNUNET_CRYPTO_hash (peer_id, + strlen (peer_id), + &hkey); + + GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put (plugin->hm, + &hkey, + entry, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); } - GNUNET_free(buffer); + } + GNUNET_free (buffer); return GNUNET_OK; } static int -store_and_free_entries(void *cls, - const struct GNUNET_HashCode *key, - void *value) +store_and_free_entries (void *cls, + const struct GNUNET_HashCode *key, + void *value) { struct GNUNET_DISK_FileHandle *fh = cls; struct GNUNET_PEERSTORE_Record *entry = value; @@ -489,30 +490,30 @@ store_and_free_entries(void *cls, const char *expiry; char *val; - GNUNET_STRINGS_base64_encode(entry->value, - entry->value_size, - &val); - expiry = GNUNET_STRINGS_absolute_time_to_string(entry->expiry); - GNUNET_STRINGS_base64_encode((char*)&entry->peer, - sizeof(struct GNUNET_PeerIdentity), - &peer); - GNUNET_asprintf(&line, - "%s,%s,%s,%s,%s", - entry->sub_system, - peer, - entry->key, - val, - expiry); - GNUNET_free(val); - GNUNET_free(peer); - GNUNET_DISK_file_write(fh, - line, - strlen(line)); - GNUNET_free(entry->sub_system); - GNUNET_free(entry->key); - GNUNET_free(entry->value); - GNUNET_free(entry); - GNUNET_free(line); + GNUNET_STRINGS_base64_encode (entry->value, + entry->value_size, + &val); + expiry = GNUNET_STRINGS_absolute_time_to_string (entry->expiry); + GNUNET_STRINGS_base64_encode ((char*) &entry->peer, + sizeof(struct GNUNET_PeerIdentity), + &peer); + GNUNET_asprintf (&line, + "%s,%s,%s,%s,%s", + entry->sub_system, + peer, + entry->key, + val, + expiry); + GNUNET_free (val); + GNUNET_free (peer); + GNUNET_DISK_file_write (fh, + line, + strlen (line)); + GNUNET_free (entry->sub_system); + GNUNET_free (entry->key); + GNUNET_free (entry->value); + GNUNET_free (entry); + GNUNET_free (line); return GNUNET_YES; } @@ -522,28 +523,28 @@ store_and_free_entries(void *cls, * @param plugin the plugin context (state for this module) */ static void -database_shutdown(struct Plugin *plugin) +database_shutdown (struct Plugin *plugin) { struct GNUNET_DISK_FileHandle *fh; - fh = GNUNET_DISK_file_open(plugin->fn, - GNUNET_DISK_OPEN_CREATE | - GNUNET_DISK_OPEN_TRUNCATE | - GNUNET_DISK_OPEN_READWRITE, - GNUNET_DISK_PERM_USER_WRITE | - GNUNET_DISK_PERM_USER_READ); + fh = GNUNET_DISK_file_open (plugin->fn, + GNUNET_DISK_OPEN_CREATE + | GNUNET_DISK_OPEN_TRUNCATE + | GNUNET_DISK_OPEN_READWRITE, + GNUNET_DISK_PERM_USER_WRITE + | GNUNET_DISK_PERM_USER_READ); if (NULL == fh) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - _("Unable to initialize file: %s.\n"), - plugin->fn); - return; - } - GNUNET_CONTAINER_multihashmap_iterate(plugin->hm, - &store_and_free_entries, - fh); - GNUNET_CONTAINER_multihashmap_destroy(plugin->hm); - GNUNET_DISK_file_close(fh); + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _ ("Unable to initialize file: %s.\n"), + plugin->fn); + return; + } + GNUNET_CONTAINER_multihashmap_iterate (plugin->hm, + &store_and_free_entries, + fh); + GNUNET_CONTAINER_multihashmap_destroy (plugin->hm); + GNUNET_DISK_file_close (fh); } @@ -554,7 +555,7 @@ database_shutdown(struct Plugin *plugin) * @return NULL on error, otherwise the plugin context */ void * -libgnunet_plugin_peerstore_flat_init(void *cls) +libgnunet_plugin_peerstore_flat_init (void *cls) { static struct Plugin plugin; const struct GNUNET_CONFIGURATION_Handle *cfg = cls; @@ -562,19 +563,19 @@ libgnunet_plugin_peerstore_flat_init(void *cls) if (NULL != plugin.cfg) return NULL; /* can only initialize once! */ - memset(&plugin, 0, sizeof(struct Plugin)); + memset (&plugin, 0, sizeof(struct Plugin)); plugin.cfg = cfg; - if (GNUNET_OK != database_setup(&plugin)) - { - database_shutdown(&plugin); - return NULL; - } - api = GNUNET_new(struct GNUNET_PEERSTORE_PluginFunctions); + if (GNUNET_OK != database_setup (&plugin)) + { + database_shutdown (&plugin); + return NULL; + } + api = GNUNET_new (struct GNUNET_PEERSTORE_PluginFunctions); api->cls = &plugin; api->store_record = &peerstore_flat_store_record; api->iterate_records = &peerstore_flat_iterate_records; api->expire_records = &peerstore_flat_expire_records; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Flat plugin is running\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Flat plugin is running\n"); return api; } @@ -586,15 +587,15 @@ libgnunet_plugin_peerstore_flat_init(void *cls) * @return Always NULL */ void * -libgnunet_plugin_peerstore_flat_done(void *cls) +libgnunet_plugin_peerstore_flat_done (void *cls) { struct GNUNET_PEERSTORE_PluginFunctions *api = cls; struct Plugin *plugin = api->cls; - database_shutdown(plugin); + database_shutdown (plugin); plugin->cfg = NULL; - GNUNET_free(api); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Flat plugin is finished\n"); + GNUNET_free (api); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Flat plugin is finished\n"); return NULL; } diff --git a/src/peerstore/plugin_peerstore_sqlite.c b/src/peerstore/plugin_peerstore_sqlite.c index 5f6617ebc..51cc651a2 100644 --- a/src/peerstore/plugin_peerstore_sqlite.c +++ b/src/peerstore/plugin_peerstore_sqlite.c @@ -49,14 +49,22 @@ * a failure of the command 'cmd' on file 'filename' * with the message given by strerror(errno). */ -#define LOG_SQLITE(db, level, cmd) do { GNUNET_log_from(level, "peerstore-sqlite", _("`%s' failed at %s:%d with error: %s\n"), cmd, __FILE__, __LINE__, sqlite3_errmsg(db->dbh)); } while (0) +#define LOG_SQLITE(db, level, cmd) do { GNUNET_log_from (level, \ + "peerstore-sqlite", _ ( \ + "`%s' failed at %s:%d with error: %s\n"), \ + cmd, \ + __FILE__, __LINE__, \ + sqlite3_errmsg ( \ + db->dbh)); \ +} while (0) -#define LOG(kind, ...) GNUNET_log_from(kind, "peerstore-sqlite", __VA_ARGS__) +#define LOG(kind, ...) GNUNET_log_from (kind, "peerstore-sqlite", __VA_ARGS__) /** * Context for all functions in this plugin. */ -struct Plugin { +struct Plugin +{ /** * Configuration handle */ @@ -121,46 +129,46 @@ struct Plugin { * @return number of deleted records, #GNUNE_SYSERR on error */ static int -peerstore_sqlite_delete_records(void *cls, - const char *sub_system, - const struct GNUNET_PeerIdentity *peer, - const char *key) +peerstore_sqlite_delete_records (void *cls, + const char *sub_system, + const struct GNUNET_PeerIdentity *peer, + const char *key) { struct Plugin *plugin = cls; sqlite3_stmt *stmt = plugin->delete_peerstoredata; struct GNUNET_SQ_QueryParam params[] = { - GNUNET_SQ_query_param_string(sub_system), - GNUNET_SQ_query_param_auto_from_type(peer), - GNUNET_SQ_query_param_string(key), + GNUNET_SQ_query_param_string (sub_system), + GNUNET_SQ_query_param_auto_from_type (peer), + GNUNET_SQ_query_param_string (key), GNUNET_SQ_query_param_end }; int ret; if (GNUNET_OK != - GNUNET_SQ_bind(stmt, - params)) - { - LOG_SQLITE(plugin, - GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, - "sqlite3_bind"); - GNUNET_SQ_reset(plugin->dbh, - stmt); - return GNUNET_SYSERR; - } + GNUNET_SQ_bind (stmt, + params)) + { + LOG_SQLITE (plugin, + GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, + "sqlite3_bind"); + GNUNET_SQ_reset (plugin->dbh, + stmt); + return GNUNET_SYSERR; + } if (SQLITE_DONE != - sqlite3_step(stmt)) - { - LOG_SQLITE(plugin, - GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, - "sqlite3_step"); - ret = GNUNET_SYSERR; - } + sqlite3_step (stmt)) + { + LOG_SQLITE (plugin, + GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, + "sqlite3_step"); + ret = GNUNET_SYSERR; + } else - { - ret = sqlite3_changes(plugin->dbh); - } - GNUNET_SQ_reset(plugin->dbh, - stmt); + { + ret = sqlite3_changes (plugin->dbh); + } + GNUNET_SQ_reset (plugin->dbh, + stmt); return ret; } @@ -176,42 +184,42 @@ peerstore_sqlite_delete_records(void *cls, * called */ static int -peerstore_sqlite_expire_records(void *cls, struct GNUNET_TIME_Absolute now, - GNUNET_PEERSTORE_Continuation cont, - void *cont_cls) +peerstore_sqlite_expire_records (void *cls, struct GNUNET_TIME_Absolute now, + GNUNET_PEERSTORE_Continuation cont, + void *cont_cls) { struct Plugin *plugin = cls; sqlite3_stmt *stmt = plugin->expire_peerstoredata; struct GNUNET_SQ_QueryParam params[] = { - GNUNET_SQ_query_param_absolute_time(&now), + GNUNET_SQ_query_param_absolute_time (&now), GNUNET_SQ_query_param_end }; if (GNUNET_OK != - GNUNET_SQ_bind(stmt, - params)) - { - LOG_SQLITE(plugin, - GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, - "sqlite3_bind"); - GNUNET_SQ_reset(plugin->dbh, - stmt); - return GNUNET_SYSERR; - } - if (SQLITE_DONE != sqlite3_step(stmt)) - { - LOG_SQLITE(plugin, - GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, - "sqlite3_step"); - GNUNET_SQ_reset(plugin->dbh, - stmt); - return GNUNET_SYSERR; - } + GNUNET_SQ_bind (stmt, + params)) + { + LOG_SQLITE (plugin, + GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, + "sqlite3_bind"); + GNUNET_SQ_reset (plugin->dbh, + stmt); + return GNUNET_SYSERR; + } + if (SQLITE_DONE != sqlite3_step (stmt)) + { + LOG_SQLITE (plugin, + GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, + "sqlite3_step"); + GNUNET_SQ_reset (plugin->dbh, + stmt); + return GNUNET_SYSERR; + } if (NULL != cont) - cont(cont_cls, - sqlite3_changes(plugin->dbh)); - GNUNET_SQ_reset(plugin->dbh, - stmt); + cont (cont_cls, + sqlite3_changes (plugin->dbh)); + GNUNET_SQ_reset (plugin->dbh, + stmt); return GNUNET_OK; } @@ -231,12 +239,12 @@ peerstore_sqlite_expire_records(void *cls, struct GNUNET_TIME_Absolute now, * called */ static int -peerstore_sqlite_iterate_records(void *cls, - const char *sub_system, - const struct GNUNET_PeerIdentity *peer, - const char *key, - GNUNET_PEERSTORE_Processor iter, - void *iter_cls) +peerstore_sqlite_iterate_records (void *cls, + const char *sub_system, + const struct GNUNET_PeerIdentity *peer, + const char *key, + GNUNET_PEERSTORE_Processor iter, + void *iter_cls) { struct Plugin *plugin = cls; sqlite3_stmt *stmt; @@ -244,113 +252,113 @@ peerstore_sqlite_iterate_records(void *cls, int sret; struct GNUNET_PEERSTORE_Record rec; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Executing iterate request on sqlite db.\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Executing iterate request on sqlite db.\n"); if (NULL == peer) + { + if (NULL == key) { - if (NULL == key) - { - struct GNUNET_SQ_QueryParam params[] = { - GNUNET_SQ_query_param_string(sub_system), - GNUNET_SQ_query_param_end - }; - - stmt = plugin->select_peerstoredata; - err = GNUNET_SQ_bind(stmt, - params); - } - else - { - struct GNUNET_SQ_QueryParam params[] = { - GNUNET_SQ_query_param_string(sub_system), - GNUNET_SQ_query_param_string(key), - GNUNET_SQ_query_param_end - }; - - stmt = plugin->select_peerstoredata_by_key; - err = GNUNET_SQ_bind(stmt, - params); - } + struct GNUNET_SQ_QueryParam params[] = { + GNUNET_SQ_query_param_string (sub_system), + GNUNET_SQ_query_param_end + }; + + stmt = plugin->select_peerstoredata; + err = GNUNET_SQ_bind (stmt, + params); } - else + else { - if (NULL == key) - { - struct GNUNET_SQ_QueryParam params[] = { - GNUNET_SQ_query_param_string(sub_system), - GNUNET_SQ_query_param_auto_from_type(peer), - GNUNET_SQ_query_param_end - }; - - stmt = plugin->select_peerstoredata_by_pid; - err = GNUNET_SQ_bind(stmt, - params); - } - else - { - struct GNUNET_SQ_QueryParam params[] = { - GNUNET_SQ_query_param_string(sub_system), - GNUNET_SQ_query_param_auto_from_type(peer), - GNUNET_SQ_query_param_string(key), - GNUNET_SQ_query_param_end - }; - - stmt = plugin->select_peerstoredata_by_all; - err = GNUNET_SQ_bind(stmt, - params); - } - } + struct GNUNET_SQ_QueryParam params[] = { + GNUNET_SQ_query_param_string (sub_system), + GNUNET_SQ_query_param_string (key), + GNUNET_SQ_query_param_end + }; - if (GNUNET_OK != err) - { - LOG_SQLITE(plugin, - GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, - "sqlite3_bind_XXXX"); - GNUNET_SQ_reset(plugin->dbh, - stmt); - return GNUNET_SYSERR; + stmt = plugin->select_peerstoredata_by_key; + err = GNUNET_SQ_bind (stmt, + params); } + } + else + { + if (NULL == key) + { + struct GNUNET_SQ_QueryParam params[] = { + GNUNET_SQ_query_param_string (sub_system), + GNUNET_SQ_query_param_auto_from_type (peer), + GNUNET_SQ_query_param_end + }; - err = 0; - while (SQLITE_ROW == (sret = sqlite3_step(stmt))) + stmt = plugin->select_peerstoredata_by_pid; + err = GNUNET_SQ_bind (stmt, + params); + } + else { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Returning a matched record.\n"); - struct GNUNET_SQ_ResultSpec rs[] = { - GNUNET_SQ_result_spec_string(&rec.sub_system), - GNUNET_SQ_result_spec_auto_from_type(&rec.peer), - GNUNET_SQ_result_spec_string(&rec.key), - GNUNET_SQ_result_spec_variable_size(&rec.value, &rec.value_size), - GNUNET_SQ_result_spec_absolute_time(&rec.expiry), - GNUNET_SQ_result_spec_end + struct GNUNET_SQ_QueryParam params[] = { + GNUNET_SQ_query_param_string (sub_system), + GNUNET_SQ_query_param_auto_from_type (peer), + GNUNET_SQ_query_param_string (key), + GNUNET_SQ_query_param_end }; - if (GNUNET_OK != - GNUNET_SQ_extract_result(stmt, - rs)) - { - GNUNET_break(0); - break; - } - if (NULL != iter) - iter(iter_cls, - &rec, - NULL); - GNUNET_SQ_cleanup_result(rs); + stmt = plugin->select_peerstoredata_by_all; + err = GNUNET_SQ_bind (stmt, + params); } - if (SQLITE_DONE != sret) + } + + if (GNUNET_OK != err) + { + LOG_SQLITE (plugin, + GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, + "sqlite3_bind_XXXX"); + GNUNET_SQ_reset (plugin->dbh, + stmt); + return GNUNET_SYSERR; + } + + err = 0; + while (SQLITE_ROW == (sret = sqlite3_step (stmt))) + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Returning a matched record.\n"); + struct GNUNET_SQ_ResultSpec rs[] = { + GNUNET_SQ_result_spec_string (&rec.sub_system), + GNUNET_SQ_result_spec_auto_from_type (&rec.peer), + GNUNET_SQ_result_spec_string (&rec.key), + GNUNET_SQ_result_spec_variable_size (&rec.value, &rec.value_size), + GNUNET_SQ_result_spec_absolute_time (&rec.expiry), + GNUNET_SQ_result_spec_end + }; + + if (GNUNET_OK != + GNUNET_SQ_extract_result (stmt, + rs)) { - LOG_SQLITE(plugin, - GNUNET_ERROR_TYPE_ERROR, - "sqlite_step"); - err = 1; + GNUNET_break (0); + break; } - GNUNET_SQ_reset(plugin->dbh, - stmt); + if (NULL != iter) + iter (iter_cls, + &rec, + NULL); + GNUNET_SQ_cleanup_result (rs); + } + if (SQLITE_DONE != sret) + { + LOG_SQLITE (plugin, + GNUNET_ERROR_TYPE_ERROR, + "sqlite_step"); + err = 1; + } + GNUNET_SQ_reset (plugin->dbh, + stmt); if (NULL != iter) - iter(iter_cls, - NULL, - err ? "sqlite error" : NULL); + iter (iter_cls, + NULL, + err ? "sqlite error" : NULL); return GNUNET_OK; } @@ -373,52 +381,52 @@ peerstore_sqlite_iterate_records(void *cls, * @return #GNUNET_OK on success, else #GNUNET_SYSERR and cont is not called */ static int -peerstore_sqlite_store_record(void *cls, - const char *sub_system, - const struct GNUNET_PeerIdentity *peer, - const char *key, - const void *value, - size_t size, - struct GNUNET_TIME_Absolute expiry, - enum GNUNET_PEERSTORE_StoreOption options, - GNUNET_PEERSTORE_Continuation cont, - void *cont_cls) +peerstore_sqlite_store_record (void *cls, + const char *sub_system, + const struct GNUNET_PeerIdentity *peer, + const char *key, + const void *value, + size_t size, + struct GNUNET_TIME_Absolute expiry, + enum GNUNET_PEERSTORE_StoreOption options, + GNUNET_PEERSTORE_Continuation cont, + void *cont_cls) { struct Plugin *plugin = cls; sqlite3_stmt *stmt = plugin->insert_peerstoredata; struct GNUNET_SQ_QueryParam params[] = { - GNUNET_SQ_query_param_string(sub_system), - GNUNET_SQ_query_param_auto_from_type(peer), - GNUNET_SQ_query_param_string(key), - GNUNET_SQ_query_param_fixed_size(value, size), - GNUNET_SQ_query_param_absolute_time(&expiry), + GNUNET_SQ_query_param_string (sub_system), + GNUNET_SQ_query_param_auto_from_type (peer), + GNUNET_SQ_query_param_string (key), + GNUNET_SQ_query_param_fixed_size (value, size), + GNUNET_SQ_query_param_absolute_time (&expiry), GNUNET_SQ_query_param_end }; if (GNUNET_PEERSTORE_STOREOPTION_REPLACE == options) - { - peerstore_sqlite_delete_records(cls, - sub_system, - peer, - key); - } + { + peerstore_sqlite_delete_records (cls, + sub_system, + peer, + key); + } if (GNUNET_OK != - GNUNET_SQ_bind(stmt, - params)) - LOG_SQLITE(plugin, - GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, - "sqlite3_bind"); - else if (SQLITE_DONE != sqlite3_step(stmt)) - { - LOG_SQLITE(plugin, - GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, - "sqlite3_step"); - } - GNUNET_SQ_reset(plugin->dbh, - stmt); + GNUNET_SQ_bind (stmt, + params)) + LOG_SQLITE (plugin, + GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, + "sqlite3_bind"); + else if (SQLITE_DONE != sqlite3_step (stmt)) + { + LOG_SQLITE (plugin, + GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, + "sqlite3_step"); + } + GNUNET_SQ_reset (plugin->dbh, + stmt); if (NULL != cont) - cont(cont_cls, - GNUNET_OK); + cont (cont_cls, + GNUNET_OK); return GNUNET_OK; } @@ -431,25 +439,25 @@ peerstore_sqlite_store_record(void *cls, * @return 0 on success */ static int -sql_exec(sqlite3 *dbh, - const char *sql) +sql_exec (sqlite3 *dbh, + const char *sql) { int result; - result = sqlite3_exec(dbh, - sql, - NULL, - NULL, - NULL); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Executed `%s' / %d\n", - sql, - result); + result = sqlite3_exec (dbh, + sql, + NULL, + NULL, + NULL); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Executed `%s' / %d\n", + sql, + result); if (SQLITE_OK != result) - LOG(GNUNET_ERROR_TYPE_ERROR, - _("Error executing SQL query: %s\n %s\n"), - sqlite3_errmsg(dbh), - sql); + LOG (GNUNET_ERROR_TYPE_ERROR, + _ ("Error executing SQL query: %s\n %s\n"), + sqlite3_errmsg (dbh), + sql); return result; } @@ -463,28 +471,28 @@ sql_exec(sqlite3 *dbh, * @return 0 on success */ static int -sql_prepare(sqlite3 *dbh, - const char *sql, - sqlite3_stmt ** stmt) +sql_prepare (sqlite3 *dbh, + const char *sql, + sqlite3_stmt **stmt) { char *tail; int result; - result = sqlite3_prepare_v2(dbh, - sql, - strlen(sql), - stmt, - (const char **)&tail); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Prepared `%s' / %p: %d\n", - sql, - *stmt, - result); + result = sqlite3_prepare_v2 (dbh, + sql, + strlen (sql), + stmt, + (const char **) &tail); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Prepared `%s' / %p: %d\n", + sql, + *stmt, + result); if (SQLITE_OK != result) - LOG(GNUNET_ERROR_TYPE_ERROR, - _("Error preparing SQL query: %s\n %s\n"), - sqlite3_errmsg(dbh), - sql); + LOG (GNUNET_ERROR_TYPE_ERROR, + _ ("Error preparing SQL query: %s\n %s\n"), + sqlite3_errmsg (dbh), + sql); return result; } @@ -498,110 +506,110 @@ sql_prepare(sqlite3 *dbh, * @return #GNUNET_OK on success */ static int -database_setup(struct Plugin *plugin) +database_setup (struct Plugin *plugin) { char *filename; if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_filename(plugin->cfg, - "peerstore-sqlite", - "FILENAME", - &filename)) + GNUNET_CONFIGURATION_get_value_filename (plugin->cfg, + "peerstore-sqlite", + "FILENAME", + &filename)) + { + GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, + "peerstore-sqlite", + "FILENAME"); + return GNUNET_SYSERR; + } + if (GNUNET_OK != GNUNET_DISK_file_test (filename)) + { + if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (filename)) { - GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, - "peerstore-sqlite", - "FILENAME"); + GNUNET_break (0); + GNUNET_free (filename); return GNUNET_SYSERR; } - if (GNUNET_OK != GNUNET_DISK_file_test(filename)) - { - if (GNUNET_OK != GNUNET_DISK_directory_create_for_file(filename)) - { - GNUNET_break(0); - GNUNET_free(filename); - return GNUNET_SYSERR; - } - } + } /* filename should be UTF-8-encoded. If it isn't, it's a bug */ plugin->fn = filename; /* Open database and precompile statements */ - if (SQLITE_OK != sqlite3_open(plugin->fn, - &plugin->dbh)) - { - LOG(GNUNET_ERROR_TYPE_ERROR, - _("Unable to initialize SQLite: %s.\n"), - sqlite3_errmsg(plugin->dbh)); - return GNUNET_SYSERR; - } - sql_exec(plugin->dbh, - "PRAGMA temp_store=MEMORY"); - sql_exec(plugin->dbh, - "PRAGMA synchronous=OFF"); - sql_exec(plugin->dbh, - "PRAGMA legacy_file_format=OFF"); - sql_exec(plugin->dbh, - "PRAGMA auto_vacuum=INCREMENTAL"); - sql_exec(plugin->dbh, - "PRAGMA encoding=\"UTF-8\""); - sql_exec(plugin->dbh, - "PRAGMA page_size=4096"); - sqlite3_busy_timeout(plugin->dbh, - BUSY_TIMEOUT_MS); + if (SQLITE_OK != sqlite3_open (plugin->fn, + &plugin->dbh)) + { + LOG (GNUNET_ERROR_TYPE_ERROR, + _ ("Unable to initialize SQLite: %s.\n"), + sqlite3_errmsg (plugin->dbh)); + return GNUNET_SYSERR; + } + sql_exec (plugin->dbh, + "PRAGMA temp_store=MEMORY"); + sql_exec (plugin->dbh, + "PRAGMA synchronous=OFF"); + sql_exec (plugin->dbh, + "PRAGMA legacy_file_format=OFF"); + sql_exec (plugin->dbh, + "PRAGMA auto_vacuum=INCREMENTAL"); + sql_exec (plugin->dbh, + "PRAGMA encoding=\"UTF-8\""); + sql_exec (plugin->dbh, + "PRAGMA page_size=4096"); + sqlite3_busy_timeout (plugin->dbh, + BUSY_TIMEOUT_MS); /* Create tables */ - sql_exec(plugin->dbh, - "CREATE TABLE IF NOT EXISTS peerstoredata (\n" - " sub_system TEXT NOT NULL,\n" - " peer_id BLOB NOT NULL,\n" - " key TEXT NOT NULL,\n" - " value BLOB NULL,\n" - " expiry INT8 NOT NULL" ");"); + sql_exec (plugin->dbh, + "CREATE TABLE IF NOT EXISTS peerstoredata (\n" + " sub_system TEXT NOT NULL,\n" + " peer_id BLOB NOT NULL,\n" + " key TEXT NOT NULL,\n" + " value BLOB NULL,\n" + " expiry INT8 NOT NULL" ");"); /* Create Indices */ if (SQLITE_OK != - sqlite3_exec(plugin->dbh, - "CREATE INDEX IF NOT EXISTS peerstoredata_key_index ON peerstoredata (sub_system, peer_id, key)", - NULL, - NULL, - NULL)) - { - LOG(GNUNET_ERROR_TYPE_ERROR, - _("Unable to create indices: %s.\n"), - sqlite3_errmsg(plugin->dbh)); - return GNUNET_SYSERR; - } + sqlite3_exec (plugin->dbh, + "CREATE INDEX IF NOT EXISTS peerstoredata_key_index ON peerstoredata (sub_system, peer_id, key)", + NULL, + NULL, + NULL)) + { + LOG (GNUNET_ERROR_TYPE_ERROR, + _ ("Unable to create indices: %s.\n"), + sqlite3_errmsg (plugin->dbh)); + return GNUNET_SYSERR; + } /* Prepare statements */ - sql_prepare(plugin->dbh, - "INSERT INTO peerstoredata (sub_system, peer_id, key, value, expiry)" - " VALUES (?,?,?,?,?);", - &plugin->insert_peerstoredata); - sql_prepare(plugin->dbh, - "SELECT sub_system,peer_id,key,value,expiry FROM peerstoredata" - " WHERE sub_system = ?", - &plugin->select_peerstoredata); - sql_prepare(plugin->dbh, - "SELECT sub_system,peer_id,key,value,expiry FROM peerstoredata" - " WHERE sub_system = ?" - " AND peer_id = ?", - &plugin->select_peerstoredata_by_pid); - sql_prepare(plugin->dbh, - "SELECT sub_system,peer_id,key,value,expiry FROM peerstoredata" - " WHERE sub_system = ?" - " AND key = ?", - &plugin->select_peerstoredata_by_key); - sql_prepare(plugin->dbh, - "SELECT sub_system,peer_id,key,value,expiry FROM peerstoredata" - " WHERE sub_system = ?" - " AND peer_id = ?" " AND key = ?", - &plugin->select_peerstoredata_by_all); - sql_prepare(plugin->dbh, - "DELETE FROM peerstoredata" - " WHERE expiry < ?", - &plugin->expire_peerstoredata); - sql_prepare(plugin->dbh, - "DELETE FROM peerstoredata" - " WHERE sub_system = ?" - " AND peer_id = ?" " AND key = ?", - &plugin->delete_peerstoredata); + sql_prepare (plugin->dbh, + "INSERT INTO peerstoredata (sub_system, peer_id, key, value, expiry)" + " VALUES (?,?,?,?,?);", + &plugin->insert_peerstoredata); + sql_prepare (plugin->dbh, + "SELECT sub_system,peer_id,key,value,expiry FROM peerstoredata" + " WHERE sub_system = ?", + &plugin->select_peerstoredata); + sql_prepare (plugin->dbh, + "SELECT sub_system,peer_id,key,value,expiry FROM peerstoredata" + " WHERE sub_system = ?" + " AND peer_id = ?", + &plugin->select_peerstoredata_by_pid); + sql_prepare (plugin->dbh, + "SELECT sub_system,peer_id,key,value,expiry FROM peerstoredata" + " WHERE sub_system = ?" + " AND key = ?", + &plugin->select_peerstoredata_by_key); + sql_prepare (plugin->dbh, + "SELECT sub_system,peer_id,key,value,expiry FROM peerstoredata" + " WHERE sub_system = ?" + " AND peer_id = ?" " AND key = ?", + &plugin->select_peerstoredata_by_all); + sql_prepare (plugin->dbh, + "DELETE FROM peerstoredata" + " WHERE expiry < ?", + &plugin->expire_peerstoredata); + sql_prepare (plugin->dbh, + "DELETE FROM peerstoredata" + " WHERE sub_system = ?" + " AND peer_id = ?" " AND key = ?", + &plugin->delete_peerstoredata); return GNUNET_OK; } @@ -612,26 +620,26 @@ database_setup(struct Plugin *plugin) * @param plugin the plugin context (state for this module) */ static void -database_shutdown(struct Plugin *plugin) +database_shutdown (struct Plugin *plugin) { int result; sqlite3_stmt *stmt; - while (NULL != (stmt = sqlite3_next_stmt(plugin->dbh, - NULL))) - { - result = sqlite3_finalize(stmt); - if (SQLITE_OK != result) - LOG(GNUNET_ERROR_TYPE_WARNING, - "Failed to close statement %p: %d\n", - stmt, - result); - } - if (SQLITE_OK != sqlite3_close(plugin->dbh)) - LOG_SQLITE(plugin, - GNUNET_ERROR_TYPE_ERROR, - "sqlite3_close"); - GNUNET_free_non_null(plugin->fn); + while (NULL != (stmt = sqlite3_next_stmt (plugin->dbh, + NULL))) + { + result = sqlite3_finalize (stmt); + if (SQLITE_OK != result) + LOG (GNUNET_ERROR_TYPE_WARNING, + "Failed to close statement %p: %d\n", + stmt, + result); + } + if (SQLITE_OK != sqlite3_close (plugin->dbh)) + LOG_SQLITE (plugin, + GNUNET_ERROR_TYPE_ERROR, + "sqlite3_close"); + GNUNET_free_non_null (plugin->fn); } @@ -642,7 +650,7 @@ database_shutdown(struct Plugin *plugin) * @return NULL on error, otherwise the plugin context */ void * -libgnunet_plugin_peerstore_sqlite_init(void *cls) +libgnunet_plugin_peerstore_sqlite_init (void *cls) { static struct Plugin plugin; const struct GNUNET_CONFIGURATION_Handle *cfg = cls; @@ -650,22 +658,22 @@ libgnunet_plugin_peerstore_sqlite_init(void *cls) if (NULL != plugin.cfg) return NULL; /* can only initialize once! */ - memset(&plugin, - 0, - sizeof(struct Plugin)); + memset (&plugin, + 0, + sizeof(struct Plugin)); plugin.cfg = cfg; - if (GNUNET_OK != database_setup(&plugin)) - { - database_shutdown(&plugin); - return NULL; - } - api = GNUNET_new(struct GNUNET_PEERSTORE_PluginFunctions); + if (GNUNET_OK != database_setup (&plugin)) + { + database_shutdown (&plugin); + return NULL; + } + api = GNUNET_new (struct GNUNET_PEERSTORE_PluginFunctions); api->cls = &plugin; api->store_record = &peerstore_sqlite_store_record; api->iterate_records = &peerstore_sqlite_iterate_records; api->expire_records = &peerstore_sqlite_expire_records; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Sqlite plugin is running\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Sqlite plugin is running\n"); return api; } @@ -677,16 +685,16 @@ libgnunet_plugin_peerstore_sqlite_init(void *cls) * @return Always NULL */ void * -libgnunet_plugin_peerstore_sqlite_done(void *cls) +libgnunet_plugin_peerstore_sqlite_done (void *cls) { struct GNUNET_PEERSTORE_PluginFunctions *api = cls; struct Plugin *plugin = api->cls; - database_shutdown(plugin); + database_shutdown (plugin); plugin->cfg = NULL; - GNUNET_free(api); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Sqlite plugin is finished\n"); + GNUNET_free (api); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Sqlite plugin is finished\n"); return NULL; } diff --git a/src/peerstore/test_peerstore_api_iterate.c b/src/peerstore/test_peerstore_api_iterate.c index 185fc8225..79d4a3b3c 100644 --- a/src/peerstore/test_peerstore_api_iterate.c +++ b/src/peerstore/test_peerstore_api_iterate.c @@ -42,132 +42,132 @@ static int count = 0; static void -iter3_cb(void *cls, - const struct GNUNET_PEERSTORE_Record *record, - const char *emsg) +iter3_cb (void *cls, + const struct GNUNET_PEERSTORE_Record *record, + const char *emsg) { if (NULL != emsg) - { - GNUNET_PEERSTORE_iterate_cancel(ic); - return; - } + { + GNUNET_PEERSTORE_iterate_cancel (ic); + return; + } if (NULL != record) - { - count++; - return; - } - GNUNET_assert(count == 3); + { + count++; + return; + } + GNUNET_assert (count == 3); ok = 0; - GNUNET_PEERSTORE_disconnect(h, GNUNET_NO); - GNUNET_SCHEDULER_shutdown(); + GNUNET_PEERSTORE_disconnect (h, GNUNET_NO); + GNUNET_SCHEDULER_shutdown (); } static void -iter2_cb(void *cls, - const struct GNUNET_PEERSTORE_Record *record, - const char *emsg) +iter2_cb (void *cls, + const struct GNUNET_PEERSTORE_Record *record, + const char *emsg) { if (NULL != emsg) - { - GNUNET_PEERSTORE_iterate_cancel(ic); - return; - } + { + GNUNET_PEERSTORE_iterate_cancel (ic); + return; + } if (NULL != record) - { - count++; - return; - } - GNUNET_assert(count == 2); + { + count++; + return; + } + GNUNET_assert (count == 2); count = 0; - ic = GNUNET_PEERSTORE_iterate(h, - ss, - NULL, - NULL, - &iter3_cb, - NULL); + ic = GNUNET_PEERSTORE_iterate (h, + ss, + NULL, + NULL, + &iter3_cb, + NULL); } static void -iter1_cb(void *cls, - const struct GNUNET_PEERSTORE_Record *record, - const char *emsg) +iter1_cb (void *cls, + const struct GNUNET_PEERSTORE_Record *record, + const char *emsg) { if (NULL != emsg) - { - GNUNET_PEERSTORE_iterate_cancel(ic); - return; - } + { + GNUNET_PEERSTORE_iterate_cancel (ic); + return; + } if (NULL != record) - { - count++; - return; - } - GNUNET_assert(count == 1); + { + count++; + return; + } + GNUNET_assert (count == 1); count = 0; - ic = GNUNET_PEERSTORE_iterate(h, - ss, - &p1, - NULL, - &iter2_cb, - NULL); + ic = GNUNET_PEERSTORE_iterate (h, + ss, + &p1, + NULL, + &iter2_cb, + NULL); } static void -run(void *cls, - const struct GNUNET_CONFIGURATION_Handle *cfg, - struct GNUNET_TESTING_Peer *peer) +run (void *cls, + const struct GNUNET_CONFIGURATION_Handle *cfg, + struct GNUNET_TESTING_Peer *peer) { - h = GNUNET_PEERSTORE_connect(cfg); - GNUNET_assert(NULL != h); - memset(&p1, 1, sizeof(p1)); - memset(&p2, 2, sizeof(p2)); - GNUNET_PEERSTORE_store(h, - ss, - &p1, - k1, - val, - strlen(val) + 1, - GNUNET_TIME_UNIT_FOREVER_ABS, - GNUNET_PEERSTORE_STOREOPTION_REPLACE, - NULL, - NULL); - GNUNET_PEERSTORE_store(h, - ss, - &p1, - k2, - val, - strlen(val) + 1, - GNUNET_TIME_UNIT_FOREVER_ABS, - GNUNET_PEERSTORE_STOREOPTION_REPLACE, - NULL, - NULL); - GNUNET_PEERSTORE_store(h, - ss, - &p2, - k3, - val, - strlen(val) + 1, - GNUNET_TIME_UNIT_FOREVER_ABS, - GNUNET_PEERSTORE_STOREOPTION_REPLACE, - NULL, - NULL); - ic = GNUNET_PEERSTORE_iterate(h, - ss, - &p1, - k1, - &iter1_cb, NULL); + h = GNUNET_PEERSTORE_connect (cfg); + GNUNET_assert (NULL != h); + memset (&p1, 1, sizeof(p1)); + memset (&p2, 2, sizeof(p2)); + GNUNET_PEERSTORE_store (h, + ss, + &p1, + k1, + val, + strlen (val) + 1, + GNUNET_TIME_UNIT_FOREVER_ABS, + GNUNET_PEERSTORE_STOREOPTION_REPLACE, + NULL, + NULL); + GNUNET_PEERSTORE_store (h, + ss, + &p1, + k2, + val, + strlen (val) + 1, + GNUNET_TIME_UNIT_FOREVER_ABS, + GNUNET_PEERSTORE_STOREOPTION_REPLACE, + NULL, + NULL); + GNUNET_PEERSTORE_store (h, + ss, + &p2, + k3, + val, + strlen (val) + 1, + GNUNET_TIME_UNIT_FOREVER_ABS, + GNUNET_PEERSTORE_STOREOPTION_REPLACE, + NULL, + NULL); + ic = GNUNET_PEERSTORE_iterate (h, + ss, + &p1, + k1, + &iter1_cb, NULL); } int -main(int argc, char *argv[]) +main (int argc, char *argv[]) { if (0 != - GNUNET_TESTING_service_run("test-gnunet-peerstore", "peerstore", - "test_peerstore_api_data.conf", &run, NULL)) + GNUNET_TESTING_service_run ("test-gnunet-peerstore", "peerstore", + "test_peerstore_api_data.conf", &run, NULL)) return 1; return ok; } diff --git a/src/peerstore/test_peerstore_api_store.c b/src/peerstore/test_peerstore_api_store.c index f557aafa5..c1ecc16bf 100644 --- a/src/peerstore/test_peerstore_api_store.c +++ b/src/peerstore/test_peerstore_api_store.c @@ -41,40 +41,40 @@ static int count = 0; static void -test3_cont2(void *cls, - const struct GNUNET_PEERSTORE_Record *record, - const char *emsg) +test3_cont2 (void *cls, + const struct GNUNET_PEERSTORE_Record *record, + const char *emsg) { if (NULL != emsg) return; if (NULL != record) - { - GNUNET_assert((strlen(val3) + 1) == record->value_size); - GNUNET_assert(0 == strcmp((char *)val3, - (char *)record->value)); - count++; - return; - } - GNUNET_assert(count == 1); + { + GNUNET_assert ((strlen (val3) + 1) == record->value_size); + GNUNET_assert (0 == strcmp ((char *) val3, + (char *) record->value)); + count++; + return; + } + GNUNET_assert (count == 1); ok = 0; - GNUNET_PEERSTORE_disconnect(h, GNUNET_YES); - GNUNET_SCHEDULER_shutdown(); + GNUNET_PEERSTORE_disconnect (h, GNUNET_YES); + GNUNET_SCHEDULER_shutdown (); } static void -test3_cont(void *cls, - int success) +test3_cont (void *cls, + int success) { if (GNUNET_YES != success) return; count = 0; - GNUNET_PEERSTORE_iterate(h, - subsystem, - &pid, - key, - &test3_cont2, - NULL); + GNUNET_PEERSTORE_iterate (h, + subsystem, + &pid, + key, + &test3_cont2, + NULL); } @@ -82,54 +82,54 @@ test3_cont(void *cls, * Replace the previous 2 records */ static void -test3() +test3 () { - GNUNET_PEERSTORE_store(h, - subsystem, - &pid, - key, - val3, - strlen(val3) + 1, - GNUNET_TIME_UNIT_FOREVER_ABS, - GNUNET_PEERSTORE_STOREOPTION_REPLACE, - &test3_cont, - NULL); + GNUNET_PEERSTORE_store (h, + subsystem, + &pid, + key, + val3, + strlen (val3) + 1, + GNUNET_TIME_UNIT_FOREVER_ABS, + GNUNET_PEERSTORE_STOREOPTION_REPLACE, + &test3_cont, + NULL); } static void -test2_cont2(void *cls, - const struct GNUNET_PEERSTORE_Record *record, - const char *emsg) +test2_cont2 (void *cls, + const struct GNUNET_PEERSTORE_Record *record, + const char *emsg) { if (NULL != emsg) return; if (NULL != record) - { - GNUNET_assert(((strlen(val1) + 1) == record->value_size) || - ((strlen(val2) + 1) == record->value_size)); - GNUNET_assert((0 == strcmp((char *)val1, (char *)record->value)) || - (0 == strcmp((char *)val2, (char *)record->value))); - count++; - return; - } - GNUNET_assert(count == 2); + { + GNUNET_assert (((strlen (val1) + 1) == record->value_size) || + ((strlen (val2) + 1) == record->value_size)); + GNUNET_assert ((0 == strcmp ((char *) val1, (char *) record->value)) || + (0 == strcmp ((char *) val2, (char *) record->value))); + count++; + return; + } + GNUNET_assert (count == 2); count = 0; - test3(); + test3 (); } static void -test2_cont(void *cls, int success) +test2_cont (void *cls, int success) { if (GNUNET_YES != success) return; count = 0; - GNUNET_PEERSTORE_iterate(h, - subsystem, - &pid, key, - &test2_cont2, - NULL); + GNUNET_PEERSTORE_iterate (h, + subsystem, + &pid, key, + &test2_cont2, + NULL); } @@ -137,53 +137,53 @@ test2_cont(void *cls, int success) * Test storing a second value with the same key */ void -test2() +test2 () { - GNUNET_PEERSTORE_store(h, - subsystem, - &pid, - key, - val2, - strlen(val2) + 1, - GNUNET_TIME_UNIT_FOREVER_ABS, - GNUNET_PEERSTORE_STOREOPTION_MULTIPLE, - &test2_cont, - NULL); + GNUNET_PEERSTORE_store (h, + subsystem, + &pid, + key, + val2, + strlen (val2) + 1, + GNUNET_TIME_UNIT_FOREVER_ABS, + GNUNET_PEERSTORE_STOREOPTION_MULTIPLE, + &test2_cont, + NULL); } static void -test1_cont2(void *cls, - const struct GNUNET_PEERSTORE_Record *record, - const char *emsg) +test1_cont2 (void *cls, + const struct GNUNET_PEERSTORE_Record *record, + const char *emsg) { if (NULL != emsg) return; if (NULL != record) - { - GNUNET_assert((strlen(val1) + 1) == record->value_size); - GNUNET_assert(0 == strcmp((char *)val1, (char *)record->value)); - count++; - return; - } - GNUNET_assert(count == 1); + { + GNUNET_assert ((strlen (val1) + 1) == record->value_size); + GNUNET_assert (0 == strcmp ((char *) val1, (char *) record->value)); + count++; + return; + } + GNUNET_assert (count == 1); count = 0; - test2(); + test2 (); } static void -test1_cont(void *cls, int success) +test1_cont (void *cls, int success) { if (GNUNET_YES != success) return; count = 0; - GNUNET_PEERSTORE_iterate(h, - subsystem, - &pid, - key, - &test1_cont2, - NULL); + GNUNET_PEERSTORE_iterate (h, + subsystem, + &pid, + key, + &test1_cont2, + NULL); } @@ -191,40 +191,40 @@ test1_cont(void *cls, int success) * Store a single record */ static void -test1() +test1 () { - GNUNET_PEERSTORE_store(h, - subsystem, - &pid, - key, - val1, - strlen(val1) + 1, - GNUNET_TIME_UNIT_FOREVER_ABS, - GNUNET_PEERSTORE_STOREOPTION_REPLACE, - &test1_cont, - NULL); + GNUNET_PEERSTORE_store (h, + subsystem, + &pid, + key, + val1, + strlen (val1) + 1, + GNUNET_TIME_UNIT_FOREVER_ABS, + GNUNET_PEERSTORE_STOREOPTION_REPLACE, + &test1_cont, + NULL); } static void -run(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, - struct GNUNET_TESTING_Peer *peer) +run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, + struct GNUNET_TESTING_Peer *peer) { - h = GNUNET_PEERSTORE_connect(cfg); - GNUNET_assert(NULL != h); - memset(&pid, 1, sizeof(pid)); - test1(); + h = GNUNET_PEERSTORE_connect (cfg); + GNUNET_assert (NULL != h); + memset (&pid, 1, sizeof(pid)); + test1 (); } int -main(int argc, char *argv[]) +main (int argc, char *argv[]) { if (0 != - GNUNET_TESTING_service_run("test-gnunet-peerstore", - "peerstore", - "test_peerstore_api_data.conf", - &run, NULL)) + GNUNET_TESTING_service_run ("test-gnunet-peerstore", + "peerstore", + "test_peerstore_api_data.conf", + &run, NULL)) return 1; return ok; } diff --git a/src/peerstore/test_peerstore_api_sync.c b/src/peerstore/test_peerstore_api_sync.c index 7df4778be..b2ac860b7 100644 --- a/src/peerstore/test_peerstore_api_sync.c +++ b/src/peerstore/test_peerstore_api_sync.c @@ -80,22 +80,22 @@ static const char *val = "test_peerstore_api_store_val"; * @return #GNUNET_YES (all good, continue) */ static void -iterate_cb(void *cls, - const struct GNUNET_PEERSTORE_Record *record, - const char *emsg) +iterate_cb (void *cls, + const struct GNUNET_PEERSTORE_Record *record, + const char *emsg) { const char *rec_val; - GNUNET_break(NULL == emsg); + GNUNET_break (NULL == emsg); if (NULL == record) - { - GNUNET_PEERSTORE_disconnect(h, - GNUNET_NO); - GNUNET_SCHEDULER_shutdown(); - return; - } + { + GNUNET_PEERSTORE_disconnect (h, + GNUNET_NO); + GNUNET_SCHEDULER_shutdown (); + return; + } rec_val = record->value; - GNUNET_break(0 == strcmp(rec_val, val)); + GNUNET_break (0 == strcmp (rec_val, val)); ok = 0; } @@ -107,14 +107,14 @@ iterate_cb(void *cls, * @param cls NULL */ static void -test_cont(void *cls) +test_cont (void *cls) { - h = GNUNET_PEERSTORE_connect(cfg); - GNUNET_PEERSTORE_iterate(h, - subsystem, - &pid, key, - &iterate_cb, - NULL); + h = GNUNET_PEERSTORE_connect (cfg); + GNUNET_PEERSTORE_iterate (h, + subsystem, + &pid, key, + &iterate_cb, + NULL); } @@ -122,28 +122,28 @@ test_cont(void *cls) * Actually run the test. */ static void -test1() +test1 () { - h = GNUNET_PEERSTORE_connect(cfg); - GNUNET_PEERSTORE_store(h, - subsystem, - &pid, - key, - val, strlen(val) + 1, - GNUNET_TIME_UNIT_FOREVER_ABS, - GNUNET_PEERSTORE_STOREOPTION_REPLACE, - NULL, NULL); - GNUNET_PEERSTORE_disconnect(h, - GNUNET_YES); + h = GNUNET_PEERSTORE_connect (cfg); + GNUNET_PEERSTORE_store (h, + subsystem, + &pid, + key, + val, strlen (val) + 1, + GNUNET_TIME_UNIT_FOREVER_ABS, + GNUNET_PEERSTORE_STOREOPTION_REPLACE, + NULL, NULL); + GNUNET_PEERSTORE_disconnect (h, + GNUNET_YES); h = NULL; /* We need to wait a little bit to give the disconnect a chance to actually finish the operation; otherwise, the test may fail non-deterministically if the new connection is faster than the cleanup routine of the old one. */ - GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, - &test_cont, - NULL); + GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, + &test_cont, + NULL); } @@ -155,29 +155,29 @@ test1() * @param peer handle to our peer (unused) */ static void -run(void *cls, - const struct GNUNET_CONFIGURATION_Handle *c, - struct GNUNET_TESTING_Peer *peer) +run (void *cls, + const struct GNUNET_CONFIGURATION_Handle *c, + struct GNUNET_TESTING_Peer *peer) { cfg = c; - memset(&pid, 1, sizeof(pid)); - test1(); + memset (&pid, 1, sizeof(pid)); + test1 (); } int -main(int argc, char *argv[]) +main (int argc, char *argv[]) { if (0 != - GNUNET_TESTING_service_run("test-gnunet-peerstore-sync", - "peerstore", - "test_peerstore_api_data.conf", - &run, NULL)) + GNUNET_TESTING_service_run ("test-gnunet-peerstore-sync", + "peerstore", + "test_peerstore_api_data.conf", + &run, NULL)) return 1; if (0 != ok) - fprintf(stderr, - "Test failed: %d\n", - ok); + fprintf (stderr, + "Test failed: %d\n", + ok); return ok; } diff --git a/src/peerstore/test_peerstore_api_watch.c b/src/peerstore/test_peerstore_api_watch.c index 1e097ad42..b833a99a5 100644 --- a/src/peerstore/test_peerstore_api_watch.c +++ b/src/peerstore/test_peerstore_api_watch.c @@ -39,61 +39,61 @@ static char *val = "test_peerstore_api_watch_val"; static void -watch_cb(void *cls, - const struct GNUNET_PEERSTORE_Record *record, - const char *emsg) +watch_cb (void *cls, + const struct GNUNET_PEERSTORE_Record *record, + const char *emsg) { - GNUNET_assert(NULL == emsg); - GNUNET_assert(0 == strcmp(val, - (char *)record->value)); + GNUNET_assert (NULL == emsg); + GNUNET_assert (0 == strcmp (val, + (char *) record->value)); ok = 0; - GNUNET_PEERSTORE_disconnect(h, - GNUNET_NO); - GNUNET_SCHEDULER_shutdown(); + GNUNET_PEERSTORE_disconnect (h, + GNUNET_NO); + GNUNET_SCHEDULER_shutdown (); } static void -run(void *cls, - const struct GNUNET_CONFIGURATION_Handle *cfg, - struct GNUNET_TESTING_Peer *peer) +run (void *cls, + const struct GNUNET_CONFIGURATION_Handle *cfg, + struct GNUNET_TESTING_Peer *peer) { struct GNUNET_PeerIdentity p; - h = GNUNET_PEERSTORE_connect(cfg); - GNUNET_assert(NULL != h); - memset(&p, - 4, - sizeof(p)); - GNUNET_PEERSTORE_watch(h, - ss, - &p, - k, - &watch_cb, - NULL); - GNUNET_PEERSTORE_store(h, - ss, - &p, - k, - val, - strlen(val) + 1, - GNUNET_TIME_UNIT_FOREVER_ABS, - GNUNET_PEERSTORE_STOREOPTION_REPLACE, - NULL, - NULL); + h = GNUNET_PEERSTORE_connect (cfg); + GNUNET_assert (NULL != h); + memset (&p, + 4, + sizeof(p)); + GNUNET_PEERSTORE_watch (h, + ss, + &p, + k, + &watch_cb, + NULL); + GNUNET_PEERSTORE_store (h, + ss, + &p, + k, + val, + strlen (val) + 1, + GNUNET_TIME_UNIT_FOREVER_ABS, + GNUNET_PEERSTORE_STOREOPTION_REPLACE, + NULL, + NULL); } int -main(int argc, - char *argv[]) +main (int argc, + char *argv[]) { if (0 != - GNUNET_TESTING_service_run("test-gnunet-peerstore", - "peerstore", - "test_peerstore_api_data.conf", - &run, - NULL)) + GNUNET_TESTING_service_run ("test-gnunet-peerstore", + "peerstore", + "test_peerstore_api_data.conf", + &run, + NULL)) return 1; return ok; } diff --git a/src/peerstore/test_plugin_peerstore.c b/src/peerstore/test_plugin_peerstore.c index 0664659a4..8fce65e23 100644 --- a/src/peerstore/test_plugin_peerstore.c +++ b/src/peerstore/test_plugin_peerstore.c @@ -48,17 +48,17 @@ static struct GNUNET_PeerIdentity p1; * @param api api to unload */ static void -unload_plugin(struct GNUNET_PEERSTORE_PluginFunctions *api) +unload_plugin (struct GNUNET_PEERSTORE_PluginFunctions *api) { char *libname; - GNUNET_asprintf(&libname, - "libgnunet_plugin_peer_%s", - plugin_name); - GNUNET_break(NULL == - GNUNET_PLUGIN_unload(libname, - api)); - GNUNET_free(libname); + GNUNET_asprintf (&libname, + "libgnunet_plugin_peer_%s", + plugin_name); + GNUNET_break (NULL == + GNUNET_PLUGIN_unload (libname, + api)); + GNUNET_free (libname); } @@ -69,123 +69,123 @@ unload_plugin(struct GNUNET_PEERSTORE_PluginFunctions *api) * @return NULL on error */ static struct GNUNET_PEERSTORE_PluginFunctions * -load_plugin(const struct GNUNET_CONFIGURATION_Handle *cfg) +load_plugin (const struct GNUNET_CONFIGURATION_Handle *cfg) { struct GNUNET_PEERSTORE_PluginFunctions *ret; char *libname; - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - _("Loading `%s' peer plugin\n"), - plugin_name); - GNUNET_asprintf(&libname, - "libgnunet_plugin_peerstore_%s", - plugin_name); - if (NULL == (ret = GNUNET_PLUGIN_load(libname, - (void*)cfg))) - { - fprintf(stderr, - "Failed to load plugin `%s'!\n", + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + _ ("Loading `%s' peer plugin\n"), plugin_name); - GNUNET_free(libname); - return NULL; - } - GNUNET_free(libname); + GNUNET_asprintf (&libname, + "libgnunet_plugin_peerstore_%s", + plugin_name); + if (NULL == (ret = GNUNET_PLUGIN_load (libname, + (void*) cfg))) + { + fprintf (stderr, + "Failed to load plugin `%s'!\n", + plugin_name); + GNUNET_free (libname); + return NULL; + } + GNUNET_free (libname); return ret; } static void -test_record(void *cls, - const struct GNUNET_PEERSTORE_Record *record, - const char *error) +test_record (void *cls, + const struct GNUNET_PEERSTORE_Record *record, + const char *error) { const struct GNUNET_PeerIdentity *id = cls; - const char* testval = "test_val"; + const char*testval = "test_val"; if (NULL == record) - { - unload_plugin(psp); - return; - } - GNUNET_assert(0 == memcmp(&record->peer, - id, - sizeof(struct GNUNET_PeerIdentity))); - GNUNET_assert(0 == strcmp("subsys", - record->sub_system)); - GNUNET_assert(0 == strcmp("key", - record->key)); - GNUNET_assert(0 == memcmp(testval, - record->value, - strlen(testval))); + { + unload_plugin (psp); + return; + } + GNUNET_assert (0 == memcmp (&record->peer, + id, + sizeof(struct GNUNET_PeerIdentity))); + GNUNET_assert (0 == strcmp ("subsys", + record->sub_system)); + GNUNET_assert (0 == strcmp ("key", + record->key)); + GNUNET_assert (0 == memcmp (testval, + record->value, + strlen (testval))); ok = 0; } static void -get_record(struct GNUNET_PEERSTORE_PluginFunctions *psp, - const struct GNUNET_PeerIdentity *identity) +get_record (struct GNUNET_PEERSTORE_PluginFunctions *psp, + const struct GNUNET_PeerIdentity *identity) { - GNUNET_assert(GNUNET_OK == - psp->iterate_records(psp->cls, - "subsys", - identity, - "key", - &test_record, - (void*)identity)); + GNUNET_assert (GNUNET_OK == + psp->iterate_records (psp->cls, + "subsys", + identity, + "key", + &test_record, + (void*) identity)); } static void -store_cont(void *cls, - int status) +store_cont (void *cls, + int status) { - GNUNET_assert(GNUNET_OK == status); - get_record(psp, - &p1); + GNUNET_assert (GNUNET_OK == status); + get_record (psp, + &p1); } static void -put_record(struct GNUNET_PEERSTORE_PluginFunctions *psp, - const struct GNUNET_PeerIdentity *identity) +put_record (struct GNUNET_PEERSTORE_PluginFunctions *psp, + const struct GNUNET_PeerIdentity *identity) { - GNUNET_assert(GNUNET_OK == - psp->store_record(psp->cls, - "subsys", - identity, - "key", - "test_value", - strlen("test_value"), - GNUNET_TIME_absolute_get(), - GNUNET_PEERSTORE_STOREOPTION_REPLACE, - &store_cont, - NULL)); + GNUNET_assert (GNUNET_OK == + psp->store_record (psp->cls, + "subsys", + identity, + "key", + "test_value", + strlen ("test_value"), + GNUNET_TIME_absolute_get (), + GNUNET_PEERSTORE_STOREOPTION_REPLACE, + &store_cont, + NULL)); } static void -run(void *cls, - char *const *args, - const char *cfgfile, - const struct GNUNET_CONFIGURATION_Handle *cfg) +run (void *cls, + char *const *args, + const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *cfg) { ok = 1; - psp = load_plugin(cfg); + psp = load_plugin (cfg); if (NULL == psp) - { - fprintf(stderr, - "%s", - "Failed to initialize peerstore. Database likely not setup, skipping test.\n"); - return; - } - memset(&p1, 1, sizeof(p1)); - put_record(psp, - &p1); + { + fprintf (stderr, + "%s", + "Failed to initialize peerstore. Database likely not setup, skipping test.\n"); + return; + } + memset (&p1, 1, sizeof(p1)); + put_record (psp, + &p1); } int -main(int argc, char *argv[]) +main (int argc, char *argv[]) { char cfg_name[PATH_MAX]; char *const xargv[] = { @@ -198,25 +198,25 @@ main(int argc, char *argv[]) GNUNET_GETOPT_OPTION_END }; - GNUNET_log_setup("test-plugin-peerstore", - "WARNING", - NULL); - plugin_name = GNUNET_TESTING_get_testname_from_underscore(argv[0]); - GNUNET_snprintf(cfg_name, - sizeof(cfg_name), - "test_plugin_peerstore_%s.conf", - plugin_name); - GNUNET_PROGRAM_run((sizeof(xargv) / sizeof(char *)) - 1, - xargv, - "test-plugin-peerstore", - "nohelp", - options, - &run, - NULL); + GNUNET_log_setup ("test-plugin-peerstore", + "WARNING", + NULL); + plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]); + GNUNET_snprintf (cfg_name, + sizeof(cfg_name), + "test_plugin_peerstore_%s.conf", + plugin_name); + GNUNET_PROGRAM_run ((sizeof(xargv) / sizeof(char *)) - 1, + xargv, + "test-plugin-peerstore", + "nohelp", + options, + &run, + NULL); if (ok != 0) - fprintf(stderr, - "Missed some testcases: %d\n", - ok); + fprintf (stderr, + "Missed some testcases: %d\n", + ok); return ok; } -- cgit v1.2.3