gnunet

Main GNUnet Logic
Log | Files | Refs | Submodules | README | LICENSE

commit 03e7efb9f11a123906b4e2138dbb4f435373136d
parent c00dfd8e42af7df167c71f75866d4485c767a7da
Author: t3sserakt <t3ss@posteo.de>
Date:   Thu,  9 Nov 2023 18:03:44 +0100

Merge branch 'master' of ssh://git.gnunet.org/gnunet

Diffstat:
Mdata/hellos/EFBZMC2ME19SE00QCSF6X4405EQ2NPBG2XKRA1FEM6S3WRQ6N4H0 | 0
Mmeson.build | 1+
Msrc/plugin/namestore/Makefile.am | 360++++---------------------------------------------------------------------------
Msrc/plugin/namestore/meson.build | 27+++++++++++++++++++++++++++
Dsrc/plugin/namestore/perf_namestore_api_import.c | 406-------------------------------------------------------------------------------
Dsrc/plugin/namestore/perf_namestore_api_zone_iteration.c | 378-------------------------------------------------------------------------------
Dsrc/plugin/namestore/test_namestore_api.conf | 43-------------------------------------------
Dsrc/plugin/namestore/test_namestore_api_edit_records.c | 399-------------------------------------------------------------------------------
Dsrc/plugin/namestore/test_namestore_api_lookup_nick.c | 347-------------------------------------------------------------------------------
Dsrc/plugin/namestore/test_namestore_api_monitoring.c | 378-------------------------------------------------------------------------------
Dsrc/plugin/namestore/test_namestore_api_monitoring_existing.c | 393-------------------------------------------------------------------------------
Dsrc/plugin/namestore/test_namestore_api_remove.c | 219-------------------------------------------------------------------------------
Dsrc/plugin/namestore/test_namestore_api_remove_not_existing_record.c | 179-------------------------------------------------------------------------------
Dsrc/plugin/namestore/test_namestore_api_store.c | 172-------------------------------------------------------------------------------
Dsrc/plugin/namestore/test_namestore_api_store_update.c | 269-------------------------------------------------------------------------------
Dsrc/plugin/namestore/test_namestore_api_tx_rollback.c | 264-------------------------------------------------------------------------------
Dsrc/plugin/namestore/test_namestore_api_zone_iteration.c | 464-------------------------------------------------------------------------------
Dsrc/plugin/namestore/test_namestore_api_zone_iteration_nick.c | 460-------------------------------------------------------------------------------
Dsrc/plugin/namestore/test_namestore_api_zone_iteration_specific_zone.c | 447-------------------------------------------------------------------------------
Dsrc/plugin/namestore/test_namestore_api_zone_iteration_stop.c | 449-------------------------------------------------------------------------------
Dsrc/plugin/namestore/test_namestore_api_zone_to_name.c | 266-------------------------------------------------------------------------------
Msrc/plugin/namestore/test_plugin_namestore.c | 5++---
Msrc/service/arm/gnunet-service-arm.c | 2+-
Msrc/service/dht/gnunet-service-dht.c | 15+++++++++++++--
Msrc/service/namestore/Makefile.am | 347+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/service/namestore/meson.build | 59+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/service/namestore/perf_namestore_api_import.c | 406+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Rsrc/plugin/namestore/perf_namestore_api_postgres.conf -> src/service/namestore/perf_namestore_api_postgres.conf | 0
Rsrc/plugin/namestore/perf_namestore_api_sqlite.conf -> src/service/namestore/perf_namestore_api_sqlite.conf | 0
Asrc/service/namestore/perf_namestore_api_zone_iteration.c | 378+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Rsrc/plugin/namestore/test_common.c -> src/service/namestore/test_common.c | 0
Asrc/service/namestore/test_namestore_api.conf | 43+++++++++++++++++++++++++++++++++++++++++++
Asrc/service/namestore/test_namestore_api_edit_records.c | 399+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/service/namestore/test_namestore_api_lookup_nick.c | 347+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/service/namestore/test_namestore_api_monitoring.c | 378+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/service/namestore/test_namestore_api_monitoring_existing.c | 393+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Rsrc/plugin/namestore/test_namestore_api_postgres.conf -> src/service/namestore/test_namestore_api_postgres.conf | 0
Asrc/service/namestore/test_namestore_api_remove.c | 219+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/service/namestore/test_namestore_api_remove_not_existing_record.c | 179+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Rsrc/plugin/namestore/test_namestore_api_sqlite.conf -> src/service/namestore/test_namestore_api_sqlite.conf | 0
Asrc/service/namestore/test_namestore_api_store.c | 172+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/service/namestore/test_namestore_api_store_update.c | 260+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/service/namestore/test_namestore_api_tx_rollback.c | 264+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/service/namestore/test_namestore_api_zone_iteration.c | 464+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/service/namestore/test_namestore_api_zone_iteration_nick.c | 460+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/service/namestore/test_namestore_api_zone_iteration_specific_zone.c | 447+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/service/namestore/test_namestore_api_zone_iteration_stop.c | 449+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/service/namestore/test_namestore_api_zone_to_name.c | 266+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/service/peerstore/gnunet-service-peerstore.c | 12+++++++++---
Msrc/service/testing/testing_api_loop.c | 57+++++++++++++++++++++++----------------------------------
Msrc/service/transport/gnunet-service-transport.c | 22++++++++++++++++------
Msrc/service/util/meson.build | 13+++++++++++++
Msrc/service/util/test_resolver_api.c | 2+-
53 files changed, 6050 insertions(+), 5929 deletions(-)

diff --git a/data/hellos/EFBZMC2ME19SE00QCSF6X4405EQ2NPBG2XKRA1FEM6S3WRQ6N4H0 b/data/hellos/EFBZMC2ME19SE00QCSF6X4405EQ2NPBG2XKRA1FEM6S3WRQ6N4H0 Binary files differ. diff --git a/meson.build b/meson.build @@ -420,6 +420,7 @@ pkg = import('pkgconfig') subdir('src') subdir('doc') subdir('contrib') +subdir('data') meson.add_dist_script('meson-dist-script') diff --git a/src/plugin/namestore/Makefile.am b/src/plugin/namestore/Makefile.am @@ -19,62 +19,7 @@ if USE_COVERAGE endif -if HAVE_SQLITE -SQLITE_PLUGIN = libgnunet_plugin_namestore_sqlite.la -SQLITE_TESTS = test_plugin_namestore_sqlite \ - test_namestore_api_store_sqlite \ - test_namestore_api_store_update_sqlite \ - test_namestore_api_zone_iteration_sqlite \ - test_namestore_api_remove_sqlite \ - test_namestore_api_lookup_nick_sqlite \ - test_namestore_api_monitoring_sqlite \ - test_namestore_api_remove_not_existing_record_sqlite \ - test_namestore_api_zone_iteration_nick_sqlite \ - test_namestore_api_zone_iteration_specific_zone_sqlite \ - test_namestore_api_zone_iteration_stop_sqlite \ - test_namestore_api_monitoring_existing_sqlite \ - test_namestore_api_zone_to_name_sqlite \ - perf_namestore_api_zone_iteration_sqlite \ - perf_namestore_api_import_sqlite \ - perf_namestore_api_import_postgres \ - test_namestore_api_tx_rollback_sqlite -endif - - -if HAVE_POSTGRESQL -POSTGRES_PLUGIN = libgnunet_plugin_namestore_postgres.la -POSTGRES_TESTS = test_plugin_namestore_postgres \ - test_namestore_api_store_postgres \ - test_namestore_api_store_update_postgres \ - test_namestore_api_remove_postgres \ - test_namestore_api_zone_iteration_postgres \ - test_namestore_api_lookup_nick_postgres \ - test_namestore_api_monitoring_postgres \ - test_namestore_api_remove_not_existing_record_postgres \ - test_namestore_api_zone_iteration_nick_postgres \ - test_namestore_api_zone_iteration_specific_zone_postgres \ - test_namestore_api_zone_iteration_stop_postgres \ - test_namestore_api_monitoring_existing_postgres \ - test_namestore_api_zone_to_name_postgres \ - perf_namestore_api_zone_iteration_postgres \ - test_namestore_api_tx_rollback_postgres -if HAVE_EXPERIMENTAL -POSTGRES_TESTS += test_namestore_api_edit_records_postgres -endif -endif - -if HAVE_SQLITE -check_PROGRAMS = \ - $(SQLITE_TESTS) \ - $(POSTGRES_TESTS) -endif -if ENABLE_TEST_RUN -AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset XDG_CONFIG_HOME; -TESTS = \ - $(check_PROGRAMS) \ - $(check_SCRIPTS) -endif plugin_LTLIBRARIES = \ $(SQLITE_PLUGIN) \ @@ -101,311 +46,34 @@ libgnunet_plugin_namestore_postgres_la_LIBADD = \ libgnunet_plugin_namestore_postgres_la_LDFLAGS = \ $(GN_PLUGIN_LDFLAGS) $(POSTGRESQL_LDFLAGS) -test_namestore_api_store_sqlite_SOURCES = \ - test_namestore_api_store.c -test_namestore_api_store_sqlite_LDADD = \ - $(top_builddir)/src/service/testing/libgnunettesting.la \ - $(top_builddir)/src/lib/util/libgnunetutil.la \ - $(top_builddir)/src/lib/gnsrecord/libgnunetgnsrecord.la \ - $(top_builddir)/src/service/identity/libgnunetidentity.la \ - $(top_builddir)/src/service/namestore/libgnunetnamestore.la - -test_namestore_api_store_postgres_SOURCES = \ - test_namestore_api_store.c -test_namestore_api_store_postgres_LDADD = \ - $(top_builddir)/src/service/testing/libgnunettesting.la \ - $(top_builddir)/src/lib/util/libgnunetutil.la \ - $(top_builddir)/src/lib/gnsrecord/libgnunetgnsrecord.la \ - $(top_builddir)/src/service/identity/libgnunetidentity.la \ - $(top_builddir)/src/service/namestore/libgnunetnamestore.la - -test_namestore_api_store_update_sqlite_SOURCES = \ - test_namestore_api_store_update.c -test_namestore_api_store_update_sqlite_LDADD = \ - $(top_builddir)/src/service/testing/libgnunettesting.la \ - $(top_builddir)/src/lib/util/libgnunetutil.la \ - $(top_builddir)/src/service/identity/libgnunetidentity.la \ - $(top_builddir)/src/lib/gnsrecord/libgnunetgnsrecord.la \ - $(top_builddir)/src/service/namecache/libgnunetnamecache.la \ - $(top_builddir)/src/service/namestore/libgnunetnamestore.la - -test_namestore_api_store_update_postgres_SOURCES = \ - test_namestore_api_store_update.c -test_namestore_api_store_update_postgres_LDADD = \ - $(top_builddir)/src/service/testing/libgnunettesting.la \ - $(top_builddir)/src/lib/util/libgnunetutil.la \ - $(top_builddir)/src/service/identity/libgnunetidentity.la \ - $(top_builddir)/src/lib/gnsrecord/libgnunetgnsrecord.la \ - $(top_builddir)/src/service/namecache/libgnunetnamecache.la \ - $(top_builddir)/src/service/namestore/libgnunetnamestore.la - -test_namestore_api_lookup_nick_sqlite_SOURCES = \ - test_namestore_api_lookup_nick.c -test_namestore_api_lookup_nick_sqlite_LDADD = \ - $(top_builddir)/src/service/testing/libgnunettesting.la \ - $(top_builddir)/src/lib/util/libgnunetutil.la \ - $(top_builddir)/src/service/identity/libgnunetidentity.la \ - $(top_builddir)/src/lib/gnsrecord/libgnunetgnsrecord.la \ - $(top_builddir)/src/service/namecache/libgnunetnamecache.la \ - $(top_builddir)/src/service/namestore/libgnunetnamestore.la - -test_namestore_api_lookup_nick_postgres_SOURCES = \ - test_namestore_api_lookup_nick.c -test_namestore_api_lookup_nick_postgres_LDADD = \ - $(top_builddir)/src/service/testing/libgnunettesting.la \ - $(top_builddir)/src/lib/util/libgnunetutil.la \ - $(top_builddir)/src/service/identity/libgnunetidentity.la \ - $(top_builddir)/src/lib/gnsrecord/libgnunetgnsrecord.la \ - $(top_builddir)/src/service/namecache/libgnunetnamecache.la \ - $(top_builddir)/src/service/namestore/libgnunetnamestore.la - -test_namestore_api_remove_sqlite_SOURCES = \ - test_namestore_api_remove.c -test_namestore_api_remove_sqlite_LDADD = \ - $(top_builddir)/src/service/identity/libgnunetidentity.la \ - $(top_builddir)/src/service/testing/libgnunettesting.la \ - $(top_builddir)/src/lib/util/libgnunetutil.la \ - $(top_builddir)/src/lib/gnsrecord/libgnunetgnsrecord.la \ - $(top_builddir)/src/service/namestore/libgnunetnamestore.la - -test_namestore_api_remove_postgres_SOURCES = \ - test_namestore_api_remove.c -test_namestore_api_remove_postgres_LDADD = \ - $(top_builddir)/src/service/identity/libgnunetidentity.la \ - $(top_builddir)/src/service/testing/libgnunettesting.la \ - $(top_builddir)/src/lib/util/libgnunetutil.la \ - $(top_builddir)/src/lib/gnsrecord/libgnunetgnsrecord.la \ - $(top_builddir)/src/service/namestore/libgnunetnamestore.la - -test_namestore_api_remove_not_existing_record_sqlite_SOURCES = \ - test_namestore_api_remove_not_existing_record.c -test_namestore_api_remove_not_existing_record_sqlite_LDADD = \ - $(top_builddir)/src/service/testing/libgnunettesting.la \ - $(top_builddir)/src/lib/util/libgnunetutil.la \ - $(top_builddir)/src/service/identity/libgnunetidentity.la \ - $(top_builddir)/src/lib/gnsrecord/libgnunetgnsrecord.la \ - $(top_builddir)/src/service/namestore/libgnunetnamestore.la - -test_namestore_api_remove_not_existing_record_postgres_SOURCES = \ - test_namestore_api_remove_not_existing_record.c -test_namestore_api_remove_not_existing_record_postgres_LDADD = \ - $(top_builddir)/src/service/testing/libgnunettesting.la \ - $(top_builddir)/src/service/identity/libgnunetidentity.la \ - $(top_builddir)/src/lib/util/libgnunetutil.la \ - $(top_builddir)/src/lib/gnsrecord/libgnunetgnsrecord.la \ - $(top_builddir)/src/service/namestore/libgnunetnamestore.la - -test_namestore_api_zone_to_name_sqlite_SOURCES = \ - test_namestore_api_zone_to_name.c -test_namestore_api_zone_to_name_sqlite_LDADD = \ - $(top_builddir)/src/service/identity/libgnunetidentity.la \ - $(top_builddir)/src/service/testing/libgnunettesting.la \ - $(top_builddir)/src/lib/util/libgnunetutil.la \ - $(top_builddir)/src/service/namestore/libgnunetnamestore.la - -test_namestore_api_zone_to_name_postgres_SOURCES = \ - test_namestore_api_zone_to_name.c -test_namestore_api_zone_to_name_postgres_LDADD = \ - $(top_builddir)/src/service/identity/libgnunetidentity.la \ - $(top_builddir)/src/service/testing/libgnunettesting.la \ - $(top_builddir)/src/lib/util/libgnunetutil.la \ - $(top_builddir)/src/service/namestore/libgnunetnamestore.la - -test_namestore_api_monitoring_sqlite_SOURCES = \ - test_namestore_api_monitoring.c -test_namestore_api_monitoring_sqlite_LDADD = \ - $(top_builddir)/src/service/identity/libgnunetidentity.la \ - $(top_builddir)/src/service/testing/libgnunettesting.la \ - $(top_builddir)/src/service/namestore/libgnunetnamestore.la \ - $(top_builddir)/src/lib/gnsrecord/libgnunetgnsrecord.la \ - $(top_builddir)/src/lib/util/libgnunetutil.la - -test_namestore_api_monitoring_postgres_SOURCES = \ - test_namestore_api_monitoring.c -test_namestore_api_monitoring_postgres_LDADD = \ - $(top_builddir)/src/service/testing/libgnunettesting.la \ - $(top_builddir)/src/service/identity/libgnunetidentity.la \ - $(top_builddir)/src/service/namestore/libgnunetnamestore.la \ - $(top_builddir)/src/lib/gnsrecord/libgnunetgnsrecord.la \ - $(top_builddir)/src/lib/util/libgnunetutil.la - -test_namestore_api_monitoring_existing_sqlite_SOURCES = \ - test_namestore_api_monitoring_existing.c -test_namestore_api_monitoring_existing_sqlite_LDADD = \ - $(top_builddir)/src/service/testing/libgnunettesting.la \ - $(top_builddir)/src/service/identity/libgnunetidentity.la \ - $(top_builddir)/src/service/namestore/libgnunetnamestore.la \ - $(top_builddir)/src/lib/gnsrecord/libgnunetgnsrecord.la \ - $(top_builddir)/src/lib/util/libgnunetutil.la - -test_namestore_api_monitoring_existing_postgres_SOURCES = \ - test_namestore_api_monitoring_existing.c -test_namestore_api_monitoring_existing_postgres_LDADD = \ - $(top_builddir)/src/service/testing/libgnunettesting.la \ - $(top_builddir)/src/service/namestore/libgnunetnamestore.la \ - $(top_builddir)/src/lib/gnsrecord/libgnunetgnsrecord.la \ - $(top_builddir)/src/service/identity/libgnunetidentity.la \ - $(top_builddir)/src/lib/util/libgnunetutil.la - -test_namestore_api_tx_rollback_sqlite_SOURCES = \ - test_namestore_api_tx_rollback.c -test_namestore_api_tx_rollback_sqlite_LDADD = \ - $(top_builddir)/src/service/testing/libgnunettesting.la \ - $(top_builddir)/src/service/identity/libgnunetidentity.la \ - $(top_builddir)/src/service/namestore/libgnunetnamestore.la \ - $(top_builddir)/src/lib/gnsrecord/libgnunetgnsrecord.la \ - $(top_builddir)/src/lib/util/libgnunetutil.la - -test_namestore_api_tx_rollback_postgres_SOURCES = \ - test_namestore_api_tx_rollback.c -test_namestore_api_tx_rollback_postgres_LDADD = \ - $(top_builddir)/src/service/testing/libgnunettesting.la \ - $(top_builddir)/src/service/identity/libgnunetidentity.la \ - $(top_builddir)/src/service/namestore/libgnunetnamestore.la \ - $(top_builddir)/src/lib/gnsrecord/libgnunetgnsrecord.la \ - $(top_builddir)/src/lib/util/libgnunetutil.la - -if HAVE_EXPERIMENTAL -test_namestore_api_edit_records_postgres_SOURCES = \ - test_namestore_api_edit_records.c -test_namestore_api_edit_records_postgres_LDADD = \ - $(top_builddir)/src/service/testing/libgnunettesting.la \ - $(top_builddir)/src/service/identity/libgnunetidentity.la \ - $(top_builddir)/src/service/namestore/libgnunetnamestore.la \ - $(top_builddir)/src/lib/gnsrecord/libgnunetgnsrecord.la \ - $(top_builddir)/src/lib/util/libgnunetutil.la +if HAVE_SQLITE +SQLITE_PLUGIN = libgnunet_plugin_namestore_sqlite.la +SQLITE_TESTS = test_plugin_namestore_sqlite endif -test_namestore_api_zone_iteration_sqlite_SOURCES = \ - test_namestore_api_zone_iteration.c -test_namestore_api_zone_iteration_sqlite_LDADD = \ - $(top_builddir)/src/service/testing/libgnunettesting.la \ - $(top_builddir)/src/service/identity/libgnunetidentity.la \ - $(top_builddir)/src/lib/util/libgnunetutil.la \ - $(top_builddir)/src/lib/gnsrecord/libgnunetgnsrecord.la \ - $(top_builddir)/src/service/namestore/libgnunetnamestore.la - -test_namestore_api_zone_iteration_postgres_SOURCES = \ - test_namestore_api_zone_iteration.c -test_namestore_api_zone_iteration_postgres_LDADD = \ - $(top_builddir)/src/service/testing/libgnunettesting.la \ - $(top_builddir)/src/service/identity/libgnunetidentity.la \ - $(top_builddir)/src/lib/util/libgnunetutil.la \ - $(top_builddir)/src/lib/gnsrecord/libgnunetgnsrecord.la \ - $(top_builddir)/src/service/namestore/libgnunetnamestore.la - -perf_namestore_api_zone_iteration_postgres_SOURCES = \ - perf_namestore_api_zone_iteration.c -perf_namestore_api_zone_iteration_postgres_LDADD = \ - $(top_builddir)/src/service/testing/libgnunettesting.la \ - $(top_builddir)/src/lib/util/libgnunetutil.la \ - $(top_builddir)/src/service/identity/libgnunetidentity.la \ - $(top_builddir)/src/lib/gnsrecord/libgnunetgnsrecord.la \ - $(top_builddir)/src/service/namestore/libgnunetnamestore.la - -perf_namestore_api_import_sqlite_SOURCES = \ - perf_namestore_api_import.c -perf_namestore_api_import_sqlite_LDADD = \ - $(top_builddir)/src/service/testing/libgnunettesting.la \ - $(top_builddir)/src/lib/util/libgnunetutil.la \ - $(top_builddir)/src/service/identity/libgnunetidentity.la \ - $(top_builddir)/src/lib/gnsrecord/libgnunetgnsrecord.la \ - $(top_builddir)/src/service/namestore/libgnunetnamestore.la - -perf_namestore_api_import_postgres_SOURCES = \ - perf_namestore_api_import.c -perf_namestore_api_import_postgres_LDADD = \ - $(top_builddir)/src/service/testing/libgnunettesting.la \ - $(top_builddir)/src/lib/util/libgnunetutil.la \ - $(top_builddir)/src/service/identity/libgnunetidentity.la \ - $(top_builddir)/src/lib/gnsrecord/libgnunetgnsrecord.la \ - $(top_builddir)/src/service/namestore/libgnunetnamestore.la - -perf_namestore_api_zone_iteration_sqlite_SOURCES = \ - perf_namestore_api_zone_iteration.c -perf_namestore_api_zone_iteration_sqlite_LDADD = \ - $(top_builddir)/src/service/testing/libgnunettesting.la \ - $(top_builddir)/src/service/identity/libgnunetidentity.la \ - $(top_builddir)/src/lib/util/libgnunetutil.la \ - $(top_builddir)/src/lib/gnsrecord/libgnunetgnsrecord.la \ - $(top_builddir)/src/service/namestore/libgnunetnamestore.la - -test_namestore_api_zone_iteration_nick_sqlite_SOURCES = \ - test_namestore_api_zone_iteration_nick.c -test_namestore_api_zone_iteration_nick_sqlite_LDADD = \ - $(top_builddir)/src/service/testing/libgnunettesting.la \ - $(top_builddir)/src/service/identity/libgnunetidentity.la \ - $(top_builddir)/src/lib/util/libgnunetutil.la \ - $(top_builddir)/src/lib/gnsrecord/libgnunetgnsrecord.la \ - $(top_builddir)/src/service/namestore/libgnunetnamestore.la - -test_namestore_api_zone_iteration_nick_postgres_SOURCES = \ - test_namestore_api_zone_iteration_nick.c -test_namestore_api_zone_iteration_nick_postgres_LDADD = \ - $(top_builddir)/src/service/testing/libgnunettesting.la \ - $(top_builddir)/src/service/identity/libgnunetidentity.la \ - $(top_builddir)/src/lib/util/libgnunetutil.la \ - $(top_builddir)/src/lib/gnsrecord/libgnunetgnsrecord.la \ - $(top_builddir)/src/service/namestore/libgnunetnamestore.la - -test_namestore_api_zone_iteration_specific_zone_sqlite_SOURCES = \ - test_namestore_api_zone_iteration_specific_zone.c -test_namestore_api_zone_iteration_specific_zone_sqlite_LDADD = \ - $(top_builddir)/src/service/testing/libgnunettesting.la \ - $(top_builddir)/src/service/identity/libgnunetidentity.la \ - $(top_builddir)/src/lib/util/libgnunetutil.la \ - $(top_builddir)/src/lib/gnsrecord/libgnunetgnsrecord.la \ - $(top_builddir)/src/service/namestore/libgnunetnamestore.la - -test_namestore_api_zone_iteration_specific_zone_postgres_SOURCES = \ - test_namestore_api_zone_iteration_specific_zone.c -test_namestore_api_zone_iteration_specific_zone_postgres_LDADD = \ - $(top_builddir)/src/service/testing/libgnunettesting.la \ - $(top_builddir)/src/service/identity/libgnunetidentity.la \ - $(top_builddir)/src/lib/util/libgnunetutil.la \ - $(top_builddir)/src/lib/gnsrecord/libgnunetgnsrecord.la \ - $(top_builddir)/src/service/namestore/libgnunetnamestore.la - -test_namestore_api_zone_iteration_stop_sqlite_SOURCES = \ - test_namestore_api_zone_iteration_stop.c -test_namestore_api_zone_iteration_stop_sqlite_LDADD = \ - $(top_builddir)/src/service/testing/libgnunettesting.la \ - $(top_builddir)/src/service/identity/libgnunetidentity.la \ - $(top_builddir)/src/lib/util/libgnunetutil.la \ - $(top_builddir)/src/lib/gnsrecord/libgnunetgnsrecord.la \ - $(top_builddir)/src/service/namestore/libgnunetnamestore.la - -test_namestore_api_zone_iteration_stop_postgres_SOURCES = \ - test_namestore_api_zone_iteration_stop.c -test_namestore_api_zone_iteration_stop_postgres_LDADD = \ - $(top_builddir)/src/service/testing/libgnunettesting.la \ - $(top_builddir)/src/service/identity/libgnunetidentity.la \ - $(top_builddir)/src/lib/util/libgnunetutil.la \ - $(top_builddir)/src/lib/gnsrecord/libgnunetgnsrecord.la \ - $(top_builddir)/src/service/namestore/libgnunetnamestore.la +if HAVE_POSTGRESQL +POSTGRES_PLUGIN = libgnunet_plugin_namestore_postgres.la +POSTGRES_TESTS = test_plugin_namestore_postgres +endif +if HAVE_SQLITE +check_PROGRAMS = \ + $(SQLITE_TESTS) \ + $(POSTGRES_TESTS) +endif test_plugin_namestore_sqlite_SOURCES = \ test_plugin_namestore.c test_plugin_namestore_sqlite_LDADD = \ - $(top_builddir)/src/service/testing/libgnunettesting.la \ - $(top_builddir)/src/service/identity/libgnunetidentity.la \ $(top_builddir)/src/lib/util/libgnunetutil.la test_plugin_namestore_postgres_SOURCES = \ test_plugin_namestore.c test_plugin_namestore_postgres_LDADD = \ - $(top_builddir)/src/service/identity/libgnunetidentity.la \ - $(top_builddir)/src/service/testing/libgnunettesting.la \ $(top_builddir)/src/lib/util/libgnunetutil.la EXTRA_DIST = \ - test_common.c \ - test_namestore_api.conf \ - test_namestore_api_postgres.conf \ - test_namestore_api_sqlite.conf \ - perf_namestore_api_postgres.conf \ - perf_namestore_api_sqlite.conf \ test_plugin_namestore_sqlite.conf \ test_plugin_namestore_postgres.conf \ - $(sql_DATA) + $(sql_DATA) + diff --git a/src/plugin/namestore/meson.build b/src/plugin/namestore/meson.build @@ -10,6 +10,10 @@ shared_module('gnunet_plugin_namestore_sqlite', install: true, install_dir: get_option('libdir')/'gnunet') +configure_file(copy: true, + input: 'test_plugin_namestore_sqlite.conf', + output: 'test_plugin_namestore_sqlite.conf') + if pq_dep.found() shared_module('gnunet_plugin_namestore_postgres', ['plugin_namestore_postgres.c'], @@ -20,5 +24,28 @@ if pq_dep.found() include_directories: [incdir, configuration_inc], install: true, install_dir: get_option('libdir')/'gnunet') +configure_file(copy: true, + input: 'test_plugin_namestore_postgres.conf', + output: 'test_plugin_namestore_postgres.conf') + + testpluginnamestore_pq = executable ('test_plugin_namestore_postgres', + ['test_plugin_namestore.c'], + dependencies: [ + libgnunetutil_dep + ], + include_directories: [incdir, configuration_inc], + install: false) + test('test_plugin_namestore_postgres', testpluginnamestore_pq, workdir: meson.current_build_dir(), + suite: 'namestore') endif +testpluginnamestore_sq = executable ('test_plugin_namestore_sqlite', + ['test_plugin_namestore.c'], + dependencies: [ + libgnunetutil_dep + ], + include_directories: [incdir, configuration_inc], + install: false) +test('test_plugin_namestore_sqlite', testpluginnamestore_sq, workdir: meson.current_build_dir(), + suite: 'namestore') + diff --git a/src/plugin/namestore/perf_namestore_api_import.c b/src/plugin/namestore/perf_namestore_api_import.c @@ -1,406 +0,0 @@ -/* - This file is part of GNUnet. - Copyright (C) 2022 GNUnet e.V. - - GNUnet is free software: you can redistribute it and/or modify it - under the terms of the GNU Affero General Public License as published - by the Free Software Foundation, either version 3 of the License, - or (at your option) any later version. - - GNUnet is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - - SPDX-License-Identifier: AGPL3.0-or-later - */ -/** - * @file namestore/perf_namestore_api_import.c - * @brief testcase for namestore: Import a lot of records - * @author Martin Schanzenbach - */ -#include "platform.h" -#include "gnunet_namestore_service.h" -#include "gnunet_testing_lib.h" -#include "namestore.h" - -#define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT - -#define TEST_RECORD_COUNT 10000 - -/** - * A #BENCHMARK_SIZE of 1000 takes less than a minute on a reasonably - * modern system, so 30 minutes should be OK even for very, very - * slow systems. - */ -#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 30) - -/** - * The runtime of the benchmark is expected to be linear - * for the iteration phase with a *good* database. The FLAT - * database uses a quadratic retrieval algorithm, - * hence it should be quadratic in the size. - */ -#define BENCHMARK_SIZE 1000 - -/** - * Maximum record size - */ -#define MAX_REC_SIZE 500 - -/** - * How big are the blocks we fetch? Note that the first block is - * always just 1 record set per current API. Smaller block - * sizes will make quadratic iteration-by-offset penalties - * more pronounced. - */ -#define BLOCK_SIZE 100 - -static struct GNUNET_NAMESTORE_Handle *nsh; - -static struct GNUNET_SCHEDULER_Task *timeout_task; - -static struct GNUNET_SCHEDULER_Task *t; - -static struct GNUNET_CRYPTO_PrivateKey privkey; - -static struct GNUNET_NAMESTORE_QueueEntry *qe; - -static int res; - -static struct GNUNET_TIME_Absolute start; - -struct GNUNET_NAMESTORE_RecordInfo ri[TEST_RECORD_COUNT]; - -int single_put_pos; - -static int bulk_count = 0; - - -/** - * Terminate everything - * - * @param cls NULL - */ -static void -end (void *cls) -{ - (void) cls; - if (NULL != qe) - { - GNUNET_NAMESTORE_cancel (qe); - qe = NULL; - } - if (NULL != nsh) - { - GNUNET_NAMESTORE_disconnect (nsh); - nsh = NULL; - } - if (NULL != t) - { - GNUNET_SCHEDULER_cancel (t); - t = NULL; - } - if (NULL != timeout_task) - { - GNUNET_SCHEDULER_cancel (timeout_task); - timeout_task = NULL; - } -} - - -/** - * End with timeout. As this is a benchmark, we do not - * fail hard but return "skipped". - */ -static void -timeout (void *cls) -{ - (void) cls; - timeout_task = NULL; - GNUNET_SCHEDULER_shutdown (); - res = 77; -} - - -static struct GNUNET_GNSRECORD_Data * -create_record (unsigned int count) -{ - struct GNUNET_GNSRECORD_Data *rd; - - rd = GNUNET_malloc (count + sizeof(struct GNUNET_GNSRECORD_Data)); - rd->expiration_time = GNUNET_TIME_relative_to_absolute ( - GNUNET_TIME_UNIT_HOURS).abs_value_us; - rd->record_type = TEST_RECORD_TYPE; - rd->data_size = count; - rd->data = (void *) &rd[1]; - rd->flags = 0; - memset (&rd[1], - 'a', - count); - return rd; -} - - -static void -publish_records_single (void *cls); - -static void -commit_cont (void *cls, - enum GNUNET_ErrorCode ec) -{ - struct GNUNET_TIME_Relative delay; - - (void) cls; - qe = NULL; - if (GNUNET_EC_NONE != ec) - { - GNUNET_break (0); - GNUNET_SCHEDULER_shutdown (); - return; - } - single_put_pos++; - delay = GNUNET_TIME_absolute_get_duration (start); - fprintf (stdout, - "BULK-TX: Publishing %u records took %s\n", - TEST_RECORD_COUNT, - GNUNET_STRINGS_relative_time_to_string (delay, - GNUNET_YES)); - res = 0; - GNUNET_SCHEDULER_shutdown (); -} - -static void -publish_records_bulk_tx (void *cls); - - -static void -put_cont_bulk_tx (void *cls, - enum GNUNET_ErrorCode ec) -{ - qe = NULL; - if (GNUNET_EC_NONE != ec) - { - GNUNET_break (0); - GNUNET_SCHEDULER_shutdown (); - return; - } - if (bulk_count == TEST_RECORD_COUNT) - { - qe = GNUNET_NAMESTORE_transaction_commit (nsh, commit_cont, NULL); - return; - } - t = GNUNET_SCHEDULER_add_now (&publish_records_bulk_tx, NULL); -} - - -static void -publish_records_bulk_tx (void *cls) -{ - unsigned int sent_rds; - t = NULL; - qe = GNUNET_NAMESTORE_records_store2 (nsh, - &privkey, - TEST_RECORD_COUNT - bulk_count, - &ri[bulk_count], - &sent_rds, - &put_cont_bulk_tx, - NULL); - bulk_count += sent_rds; - GNUNET_assert (sent_rds != 0); -} - - -static void -begin_cont (void *cls, - enum GNUNET_ErrorCode ec) -{ - unsigned int sent_rds; - qe = GNUNET_NAMESTORE_records_store2 (nsh, - &privkey, - TEST_RECORD_COUNT - bulk_count, - &ri[bulk_count], - &sent_rds, - &put_cont_bulk_tx, - NULL); - bulk_count += sent_rds; - GNUNET_assert (sent_rds != 0); -} - -static void -publish_records_bulk (void *cls); - -static void -put_cont_bulk (void *cls, - enum GNUNET_ErrorCode ec) -{ - struct GNUNET_TIME_Relative delay; - - (void) cls; - qe = NULL; - if (GNUNET_EC_NONE != ec) - { - GNUNET_break (0); - GNUNET_SCHEDULER_shutdown (); - return; - } - - if (bulk_count == TEST_RECORD_COUNT) - { - delay = GNUNET_TIME_absolute_get_duration (start); - fprintf (stdout, - "BULK: Publishing %u records took %s\n", - TEST_RECORD_COUNT, - GNUNET_STRINGS_relative_time_to_string (delay, - GNUNET_YES)); - start = GNUNET_TIME_absolute_get (); - bulk_count = 0; - qe = GNUNET_NAMESTORE_transaction_begin (nsh, begin_cont, NULL); - return; - } - (void) cls; - qe = NULL; - if (GNUNET_EC_NONE != ec) - { - GNUNET_break (0); - GNUNET_SCHEDULER_shutdown (); - return; - } - t = GNUNET_SCHEDULER_add_now (&publish_records_bulk, NULL); -} - -static void -publish_records_bulk (void *cls) -{ - static unsigned int sent_rds = 0; - (void) cls; - t = NULL; - qe = GNUNET_NAMESTORE_records_store2 (nsh, - &privkey, - TEST_RECORD_COUNT - bulk_count, - &ri[bulk_count], - &sent_rds, - &put_cont_bulk, - NULL); - bulk_count += sent_rds; - GNUNET_assert (sent_rds != 0); -} - - -static void -put_cont_single (void *cls, - enum GNUNET_ErrorCode ec) -{ - struct GNUNET_TIME_Relative delay; - (void) cls; - qe = NULL; - if (GNUNET_EC_NONE != ec) - { - GNUNET_break (0); - GNUNET_SCHEDULER_shutdown (); - return; - } - single_put_pos++; - if (single_put_pos == TEST_RECORD_COUNT) - { - delay = GNUNET_TIME_absolute_get_duration (start); - fprintf (stdout, - "SINGLE: Publishing %u records took %s\n", - TEST_RECORD_COUNT, - GNUNET_STRINGS_relative_time_to_string (delay, - GNUNET_YES)); - start = GNUNET_TIME_absolute_get (); - t = GNUNET_SCHEDULER_add_now (&publish_records_bulk, NULL); - return; - } - t = GNUNET_SCHEDULER_add_now (&publish_records_single, - NULL); -} - - -static void -publish_records_single (void *cls) -{ - struct GNUNET_TIME_Relative delay; - - (void) cls; - t = NULL; - if (single_put_pos == TEST_RECORD_COUNT) - { - delay = GNUNET_TIME_absolute_get_duration (start); - fprintf (stdout, - "Publishing %u records took %s\n", - TEST_RECORD_COUNT, - GNUNET_STRINGS_relative_time_to_string (delay, - GNUNET_YES)); - GNUNET_SCHEDULER_add_now (&publish_records_bulk, NULL); - } - qe = GNUNET_NAMESTORE_records_store (nsh, - &privkey, - ri[single_put_pos].a_label, - ri[single_put_pos].a_rd_count, - ri[single_put_pos].a_rd, - &put_cont_single, - NULL); -} - - -static void -run (void *cls, - const struct GNUNET_CONFIGURATION_Handle *cfg, - struct GNUNET_TESTING_Peer *peer) -{ - - for (int i = 0; i < TEST_RECORD_COUNT; i++) - { - ri[i].a_rd = create_record (1); - ri[i].a_rd_count = 1; - GNUNET_asprintf ((char**) &ri[i].a_label, "label_%d", i); - } - GNUNET_SCHEDULER_add_shutdown (&end, - NULL); - timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, - &timeout, - NULL); - nsh = GNUNET_NAMESTORE_connect (cfg); - GNUNET_assert (NULL != nsh); - privkey.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); - GNUNET_CRYPTO_ecdsa_key_create (&privkey.ecdsa_key); - start = GNUNET_TIME_absolute_get (); - t = GNUNET_SCHEDULER_add_now (&publish_records_single, - NULL); -} - - -#include "test_common.c" - - -int -main (int argc, - char *argv[]) -{ - const char *plugin_name; - char *cfg_name; - - SETUP_CFG2 ("perf_namestore_api_%s.conf", plugin_name, cfg_name); - res = 1; - if (0 != - GNUNET_TESTING_peer_run ("perf-namestore-api-import", - cfg_name, - &run, - NULL)) - { - res = 1; - } - GNUNET_DISK_purge_cfg_dir (cfg_name, - "GNUNET_TEST_HOME"); - GNUNET_free (plugin_name); - GNUNET_free (cfg_name); - return res; -} - - -/* end of perf_namestore_api_zone_iteration.c */ diff --git a/src/plugin/namestore/perf_namestore_api_zone_iteration.c b/src/plugin/namestore/perf_namestore_api_zone_iteration.c @@ -1,378 +0,0 @@ -/* - This file is part of GNUnet. - Copyright (C) 2013, 2018 GNUnet e.V. - - GNUnet is free software: you can redistribute it and/or modify it - under the terms of the GNU Affero General Public License as published - by the Free Software Foundation, either version 3 of the License, - or (at your option) any later version. - - GNUnet is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - - SPDX-License-Identifier: AGPL3.0-or-later - */ -/** - * @file namestore/perf_namestore_api_zone_iteration.c - * @brief testcase for zone iteration functionality: iterate all zones - * @author Christian Grothoff - */ -#include "platform.h" -#include "gnunet_namestore_service.h" -#include "gnunet_testing_lib.h" -#include "namestore.h" - -#define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT - -/** - * A #BENCHMARK_SIZE of 1000 takes less than a minute on a reasonably - * modern system, so 30 minutes should be OK even for very, very - * slow systems. - */ -#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 30) - -/** - * The runtime of the benchmark is expected to be linear - * for the iteration phase with a *good* database. The FLAT - * database uses a quadratic retrieval algorithm, - * hence it should be quadratic in the size. - */ -#define BENCHMARK_SIZE 1000 - -/** - * Maximum record size - */ -#define MAX_REC_SIZE 500 - -/** - * How big are the blocks we fetch? Note that the first block is - * always just 1 record set per current API. Smaller block - * sizes will make quadratic iteration-by-offset penalties - * more pronounced. - */ -#define BLOCK_SIZE 100 - -static struct GNUNET_NAMESTORE_Handle *nsh; - -static struct GNUNET_SCHEDULER_Task *timeout_task; - -static struct GNUNET_SCHEDULER_Task *t; - -static struct GNUNET_CRYPTO_PrivateKey privkey; - -static struct GNUNET_NAMESTORE_ZoneIterator *zi; - -static struct GNUNET_NAMESTORE_QueueEntry *qe; - -static int res; - -static unsigned int off; - -static unsigned int left_until_next; - -static uint8_t seen[1 + BENCHMARK_SIZE / 8]; - -static struct GNUNET_TIME_Absolute start; - - -/** - * Terminate everything - * - * @param cls NULL - */ -static void -end (void *cls) -{ - (void) cls; - if (NULL != qe) - { - GNUNET_NAMESTORE_cancel (qe); - qe = NULL; - } - if (NULL != zi) - { - GNUNET_NAMESTORE_zone_iteration_stop (zi); - zi = NULL; - } - if (NULL != nsh) - { - GNUNET_NAMESTORE_disconnect (nsh); - nsh = NULL; - } - if (NULL != t) - { - GNUNET_SCHEDULER_cancel (t); - t = NULL; - } - if (NULL != timeout_task) - { - GNUNET_SCHEDULER_cancel (timeout_task); - timeout_task = NULL; - } -} - - -/** - * End with timeout. As this is a benchmark, we do not - * fail hard but return "skipped". - */ -static void -timeout (void *cls) -{ - (void) cls; - timeout_task = NULL; - GNUNET_SCHEDULER_shutdown (); - res = 77; -} - - -static struct GNUNET_GNSRECORD_Data * -create_record (unsigned int count) -{ - struct GNUNET_GNSRECORD_Data *rd; - - rd = GNUNET_malloc (count + sizeof(struct GNUNET_GNSRECORD_Data)); - rd->expiration_time = GNUNET_TIME_relative_to_absolute ( - GNUNET_TIME_UNIT_HOURS).abs_value_us; - rd->record_type = TEST_RECORD_TYPE; - rd->data_size = count; - rd->data = (void *) &rd[1]; - rd->flags = 0; - memset (&rd[1], - 'a', - count); - return rd; -} - - -static void -zone_end (void *cls) -{ - struct GNUNET_TIME_Relative delay; - - zi = NULL; - delay = GNUNET_TIME_absolute_get_duration (start); - fprintf (stdout, - "Iterating over %u records took %s\n", - off, - GNUNET_STRINGS_relative_time_to_string (delay, - GNUNET_YES)); - if (BENCHMARK_SIZE == off) - { - res = 0; - } - else - { - GNUNET_break (0); - res = 1; - } - GNUNET_SCHEDULER_shutdown (); -} - - -static void -fail_cb (void *cls) -{ - zi = NULL; - res = 2; - GNUNET_break (0); - GNUNET_SCHEDULER_shutdown (); -} - - -static void -zone_proc (void *cls, - const struct GNUNET_CRYPTO_PrivateKey *zone, - const char *label, - unsigned int rd_count, - const struct GNUNET_GNSRECORD_Data *rd) -{ - struct GNUNET_GNSRECORD_Data *wrd; - unsigned int xoff; - - GNUNET_assert (NULL != zone); - if (1 != sscanf (label, - "l%u", - &xoff)) - { - res = 3; - GNUNET_break (0); - GNUNET_SCHEDULER_shutdown (); - return; - } - if ((xoff > BENCHMARK_SIZE) || - (0 != (seen[xoff / 8] & (1U << (xoff % 8))))) - { - res = 3; - GNUNET_break (0); - GNUNET_SCHEDULER_shutdown (); - return; - } - seen[xoff / 8] |= (1U << (xoff % 8)); - wrd = create_record (xoff % MAX_REC_SIZE); - if ((rd->record_type != wrd->record_type) || - (rd->data_size != wrd->data_size) || - (rd->flags != wrd->flags)) - { - res = 4; - GNUNET_break (0); - GNUNET_SCHEDULER_shutdown (); - GNUNET_free (wrd); - return; - } - if (0 != memcmp (rd->data, - wrd->data, - wrd->data_size)) - { - res = 4; - GNUNET_break (0); - GNUNET_SCHEDULER_shutdown (); - GNUNET_free (wrd); - return; - } - GNUNET_free (wrd); - if (0 != GNUNET_memcmp (zone, - &privkey)) - { - res = 5; - GNUNET_break (0); - GNUNET_SCHEDULER_shutdown (); - return; - } - off++; - left_until_next--; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Obtained record %u, expecting %u more until asking for more explicitly\n", - off, - left_until_next); - if (0 == left_until_next) - { - left_until_next = BLOCK_SIZE; - GNUNET_NAMESTORE_zone_iterator_next (zi, - left_until_next); - } -} - - -static void -publish_record (void *cls); - - -static void -put_cont (void *cls, - enum GNUNET_ErrorCode ec) -{ - (void) cls; - qe = NULL; - if (GNUNET_EC_NONE != ec) - { - GNUNET_break (0); - GNUNET_SCHEDULER_shutdown (); - return; - } - t = GNUNET_SCHEDULER_add_now (&publish_record, - NULL); -} - - -static void -publish_record (void *cls) -{ - struct GNUNET_GNSRECORD_Data *rd; - char *label; - - (void) cls; - t = NULL; - if (BENCHMARK_SIZE == off) - { - struct GNUNET_TIME_Relative delay; - - delay = GNUNET_TIME_absolute_get_duration (start); - fprintf (stdout, - "Inserting %u records took %s\n", - off, - GNUNET_STRINGS_relative_time_to_string (delay, - GNUNET_YES)); - start = GNUNET_TIME_absolute_get (); - off = 0; - left_until_next = 1; - zi = GNUNET_NAMESTORE_zone_iteration_start (nsh, - NULL, - &fail_cb, - NULL, - &zone_proc, - NULL, - &zone_end, - NULL); - GNUNET_assert (NULL != zi); - return; - } - rd = create_record ((++off) % MAX_REC_SIZE); - GNUNET_asprintf (&label, - "l%u", - off); - qe = GNUNET_NAMESTORE_records_store (nsh, - &privkey, - label, - 1, rd, - &put_cont, - NULL); - GNUNET_free (label); - GNUNET_free (rd); -} - - -static void -run (void *cls, - const struct GNUNET_CONFIGURATION_Handle *cfg, - struct GNUNET_TESTING_Peer *peer) -{ - GNUNET_SCHEDULER_add_shutdown (&end, - NULL); - timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, - &timeout, - NULL); - nsh = GNUNET_NAMESTORE_connect (cfg); - GNUNET_assert (NULL != nsh); - privkey.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); - GNUNET_CRYPTO_ecdsa_key_create (&privkey.ecdsa_key); - start = GNUNET_TIME_absolute_get (); - t = GNUNET_SCHEDULER_add_now (&publish_record, - NULL); -} - - -#include "test_common.c" - - -int -main (int argc, - char *argv[]) -{ - const char *plugin_name; - char *cfg_name; - - SETUP_CFG (plugin_name, cfg_name); - res = 1; - if (0 != - GNUNET_TESTING_peer_run ("perf-namestore-api-zone-iteration", - cfg_name, - &run, - NULL)) - { - res = 1; - } - GNUNET_DISK_purge_cfg_dir (cfg_name, - "GNUNET_TEST_HOME"); - GNUNET_free (plugin_name); - GNUNET_free (cfg_name); - return res; -} - - -/* end of perf_namestore_api_zone_iteration.c */ diff --git a/src/plugin/namestore/test_namestore_api.conf b/src/plugin/namestore/test_namestore_api.conf @@ -1,43 +0,0 @@ -@INLINE@ ../../contrib/conf/gnunet/no_forcestart.conf -@INLINE@ ../../contrib/conf/gnunet/no_autostart_above_core.conf - -[PATHS] -GNUNET_TEST_HOME = $GNUNET_TMP/test-gnunet-namestore/ - -[namestore] -DATABASE = sqlite -START_ON_DEMAND = YES -#PREFIX = valgrind --track-origins=yes --log-file=/tmp/ns_tx.log -RETURN_ORPHANED = YES - -[namecache] -DATABASE = sqlite -START_ON_DEMAND = YES - -[zonemaster] -START_ON_DEMAND = YES -IMMEDIATE_START = NO - -[dht] -START_ON_DEMAND = YES -IMMEDIATE_START = NO - - -[zonemaster-monitor] -START_ON_DEMAND = YES -IMMEDIATE_START = YES - -[identity] -START_ON_DEMAND = YES - -[nse] -WORKBITS = 0 - -[rest] -BASIC_AUTH_ENABLED=NO -# PREFIX = valgrind --leak-check=full --track-origins=yes --log-file=/tmp/v_log - - - -[transport] -PLUGINS = diff --git a/src/plugin/namestore/test_namestore_api_edit_records.c b/src/plugin/namestore/test_namestore_api_edit_records.c @@ -1,399 +0,0 @@ -/* - This file is part of GNUnet. - Copyright (C) 2022 GNUnet e.V. - - GNUnet is free software: you can redistribute it and/or modify it - under the terms of the GNU Affero General Public License as published - by the Free Software Foundation, either version 3 of the License, - or (at your option) any later version. - - GNUnet is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - - SPDX-License-Identifier: AGPL3.0-or-later - */ -/** - * @file namestore/test_namestore_api_edit_records.c - * @brief testcase for namestore_api.c: Multiple clients work with record set. - */ -#include "platform.h" -#include "gnunet_namestore_service.h" -#include "gnunet_testing_lib.h" - -#define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT - -#define TEST_RECORD_DATALEN 123 - -#define TEST_RECORD_DATA 'a' - -#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100) - - -static struct GNUNET_NAMESTORE_Handle *nsh; - -static struct GNUNET_NAMESTORE_Handle *nsh2; - -static struct GNUNET_SCHEDULER_Task *endbadly_task; - -static struct GNUNET_CRYPTO_PrivateKey privkey; - -static struct GNUNET_CRYPTO_PublicKey pubkey; - -static int res; - -static int removed; - -static struct GNUNET_NAMESTORE_QueueEntry *nsqe; - -static int nonce = 0; - -static void -cleanup () -{ - if (NULL != nsh) - { - GNUNET_NAMESTORE_disconnect (nsh); - nsh = NULL; - } - GNUNET_SCHEDULER_shutdown (); -} - - -/** - * Re-establish the connection to the service. - * - * @param cls handle to use to re-connect. - */ -static void -endbadly (void *cls) -{ - if (NULL != nsqe) - { - GNUNET_NAMESTORE_cancel (nsqe); - nsqe = NULL; - } - cleanup (); - res = 1; -} - - -static void -end (void *cls) -{ - cleanup (); - res = 0; -} - -static void -lookup_it (void *cls, - const struct GNUNET_CRYPTO_PrivateKey *zone, - const char *label, - unsigned int rd_count, - const struct GNUNET_GNSRECORD_Data *rd) -{ - GNUNET_assert (0 == rd_count); - GNUNET_SCHEDULER_add_now (&end, NULL); -} - -static void -fail_cb (void *cls) -{ - if (endbadly_task != NULL) - GNUNET_SCHEDULER_cancel (endbadly_task); - endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); - return; -} - -static void -remove_cont (void *cls, - enum GNUNET_ErrorCode ec) -{ - nsqe = NULL; - if (GNUNET_EC_NONE != ec) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _ ("Unable to roll back: `%s'\n"), - GNUNET_ErrorCode_get_hint (ec)); - if (NULL != endbadly_task) - GNUNET_SCHEDULER_cancel (endbadly_task); - endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, - NULL); - return; - } - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Rolled back, perform lookup\n"); - removed = GNUNET_YES; - if (NULL != endbadly_task) - GNUNET_SCHEDULER_cancel (endbadly_task); - GNUNET_SCHEDULER_add_now (&end, NULL); -} - -static void -fail_cb_lock (void *cls); - -static void -edit_cont_b (void *cls, - const struct GNUNET_CRYPTO_PrivateKey *zone, - const char *label, - unsigned int rd_count, - const struct GNUNET_GNSRECORD_Data *rd) -{ - const char *name = cls; - /** - * We should probably never get here right at first. - * We may want to change the blocking of nsh2 so that we do get this - * eventually instead of the error callback above when locked. - */ - if (0 == nonce) - { - if (endbadly_task != NULL) - GNUNET_SCHEDULER_cancel (endbadly_task); - endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); - return; - - } - /* Abort transaction for B */ - nsqe = GNUNET_NAMESTORE_transaction_rollback (nsh2, remove_cont, - (void *) name); -} - - -static void -commit_cont_a (void *cls, - enum GNUNET_ErrorCode ec) -{ - const char *name = cls; - - GNUNET_assert (NULL != cls); - nsqe = NULL; - if (GNUNET_EC_NONE != ec) - { - GNUNET_break (0); - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Namestore could not store record: `%s'\n", - GNUNET_ErrorCode_get_hint (ec)); - if (endbadly_task != NULL) - GNUNET_SCHEDULER_cancel (endbadly_task); - endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); - return; - } - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Name store added record for `%s': %s\n", - name, - (GNUNET_EC_NONE == ec) ? "SUCCESS" : "FAIL"); - /** - * Try again for B - */ - nsqe = GNUNET_NAMESTORE_records_edit (nsh2, - &privkey, - name, - &fail_cb_lock, - (void *) name, - &edit_cont_b, - (void *) name); - - GNUNET_assert (NULL != nsqe); -} - -static void -fail_cb_lock (void *cls) -{ - const char *name = cls; - if (1 == nonce) - { - if (endbadly_task != NULL) - GNUNET_SCHEDULER_cancel (endbadly_task); - endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); - return; - } - nonce = 1; - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Failed to aquire additional lock\n"); - /* Now, we stop the transaction for B */ - nsqe = GNUNET_NAMESTORE_transaction_commit (nsh, commit_cont_a, - (void *) name); -} - - -static void -begin_cont_b (void *cls, - enum GNUNET_ErrorCode ec) -{ - const char *name = cls; - - GNUNET_assert (GNUNET_EC_NONE == ec); - /** Now, we expect this to "hang" let's see how this behaves in practice. */ - nsqe = GNUNET_NAMESTORE_records_edit (nsh2, - &privkey, - name, - &fail_cb_lock, - (void *) name, - &edit_cont_b, - (void *) name); - - GNUNET_assert (NULL != nsqe); -} - - -static void -edit_cont (void *cls, - const struct GNUNET_CRYPTO_PrivateKey *zone, - const char *label, - unsigned int rd_count, - const struct GNUNET_GNSRECORD_Data *rd) -{ - const char *name = cls; - - GNUNET_assert (1 == rd_count); - /* Now, we start a transaction for B */ - nsqe = GNUNET_NAMESTORE_transaction_begin (nsh2, begin_cont_b, (void *) name); -} - - -static void -begin_cont (void *cls, - enum GNUNET_ErrorCode ec) -{ - const char *name = cls; - - GNUNET_assert (GNUNET_EC_NONE == ec); - nsqe = GNUNET_NAMESTORE_records_edit (nsh, - &privkey, - name, - &fail_cb, - (void *) name, - &edit_cont, - (void *) name); - - GNUNET_assert (NULL != nsqe); -} - -static void -preload_cont (void *cls, - enum GNUNET_ErrorCode ec) -{ - const char *name = cls; - - GNUNET_assert (NULL != cls); - nsqe = NULL; - if (GNUNET_EC_NONE != ec) - { - GNUNET_break (0); - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Namestore could not store record: `%s'\n", - GNUNET_ErrorCode_get_hint (ec)); - if (endbadly_task != NULL) - GNUNET_SCHEDULER_cancel (endbadly_task); - endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); - return; - } - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Name store added record for `%s': %s\n", - name, - (GNUNET_EC_NONE == ec) ? "SUCCESS" : "FAIL"); - /* We start transaction for A */ - nsqe = GNUNET_NAMESTORE_transaction_begin (nsh, begin_cont, (void *) name); - -} - - -static void -run (void *cls, - const struct GNUNET_CONFIGURATION_Handle *cfg, - struct GNUNET_TESTING_Peer *peer) -{ - struct GNUNET_GNSRECORD_Data rd; - const char *name = "dummy"; - - endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, - &endbadly, - NULL); - nsh = GNUNET_NAMESTORE_connect (cfg); - nsh2 = GNUNET_NAMESTORE_connect (cfg); - GNUNET_break (NULL != nsh); - GNUNET_break (NULL != nsh2); - - privkey.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); - GNUNET_CRYPTO_ecdsa_key_create (&privkey.ecdsa_key); - GNUNET_CRYPTO_key_get_public (&privkey, - &pubkey); - - removed = GNUNET_NO; - - rd.expiration_time = GNUNET_TIME_absolute_get ().abs_value_us; - rd.record_type = TEST_RECORD_TYPE; - rd.data_size = TEST_RECORD_DATALEN; - rd.data = GNUNET_malloc (TEST_RECORD_DATALEN); - rd.flags = 0; - memset ((char *) rd.data, - 'a', - TEST_RECORD_DATALEN); - nsqe = GNUNET_NAMESTORE_records_store (nsh, - &privkey, - name, - 1, - &rd, - &preload_cont, - (void *) name); - GNUNET_assert (NULL != nsqe); - GNUNET_free_nz ((void *) rd.data); - - /*nsqe = GNUNET_NAMESTORE_transaction_commit (nsh, commit_cont); - nsqe = GNUNET_NAMESTORE_transaction_rollback (nsh, rollback_cont); Must also happen on disconnect - nsqe = GNUNET_NAMESTORE_records_edit (nsh, - &privkey, - name, - 1, - &rd, - &edit_cont, - (void *) name); - nsqe = GNUNET_NAMESTORE_records_insert_bulk (nsh, - count, - &rd, - & - nsqe = GNUNET_NAMESTORE_records_store (nsh, - &privkey, - name, - 1, - &rd, - &put_cont, - (void *) name);*/ - GNUNET_assert (NULL != nsqe); -} - - -#include "test_common.c" - - -int -main (int argc, char *argv[]) -{ - const char *plugin_name; - char *cfg_name; - - SETUP_CFG (plugin_name, cfg_name); - res = 1; - if (0 != - GNUNET_TESTING_peer_run ("test-namestore-api-remove", - cfg_name, - &run, - NULL)) - { - res = 1; - } - GNUNET_DISK_purge_cfg_dir (cfg_name, - "GNUNET_TEST_HOME"); - GNUNET_free (plugin_name); - GNUNET_free (cfg_name); - return res; -} - - -/* end of test_namestore_api_remove.c */ diff --git a/src/plugin/namestore/test_namestore_api_lookup_nick.c b/src/plugin/namestore/test_namestore_api_lookup_nick.c @@ -1,347 +0,0 @@ -/* - This file is part of GNUnet. - Copyright (C) 2012 GNUnet e.V. - - GNUnet is free software: you can redistribute it and/or modify it - under the terms of the GNU Affero General Public License as published - by the Free Software Foundation, either version 3 of the License, - or (at your option) any later version. - - GNUnet is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - - SPDX-License-Identifier: AGPL3.0-or-later - */ -/** - * @file namestore/test_namestore_api_lookup_nick.c - * @brief testcase for namestore_api.c: NICK records - */ -#include "platform.h" -#include "gnunet_namestore_service.h" -#include "gnunet_gns_service.h" -#include "gnunet_testing_lib.h" - -#define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT - -#define TEST_RECORD_DATALEN 123 - -#define TEST_NICK "gnunettestnick" - -#define TEST_RECORD_DATA 'a' - -#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) - -static struct GNUNET_NAMESTORE_Handle *nsh; - -static struct GNUNET_SCHEDULER_Task *endbadly_task; - -static struct GNUNET_CRYPTO_PrivateKey privkey; - -static struct GNUNET_CRYPTO_PublicKey pubkey; - -static int res; - -static struct GNUNET_GNSRECORD_Data rd_orig; - -static struct GNUNET_NAMESTORE_QueueEntry *nsqe; - -// static const char * name = "dummy.dummy.gnunet"; -static const char *name = "d"; - -static char *record_data; - -static void -cleanup () -{ - GNUNET_free (record_data); - if (NULL != nsh) - { - GNUNET_NAMESTORE_disconnect (nsh); - nsh = NULL; - } - GNUNET_SCHEDULER_shutdown (); -} - - -/** - * Re-establish the connection to the service. - * - * @param cls handle to use to re-connect. - * @param tc scheduler context - */ -static void -endbadly (void *cls) -{ - if (NULL != nsqe) - { - GNUNET_NAMESTORE_cancel (nsqe); - nsqe = NULL; - } - cleanup (); - res = 1; -} - - -static void -end (void *cls) -{ - cleanup (); - res = 0; -} - - -static void -lookup_it (void *cls, - const struct GNUNET_CRYPTO_PrivateKey *zone, - const char *label, - unsigned int rd_count, - const struct GNUNET_GNSRECORD_Data *rd) -{ - nsqe = NULL; - int c; - int found_record = GNUNET_NO; - int found_nick = GNUNET_NO; - - if (0 != GNUNET_memcmp (&privkey, zone)) - { - GNUNET_break (0); - GNUNET_SCHEDULER_cancel (endbadly_task); - endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); - return; - } - - if (NULL == label) - { - GNUNET_break (0); - GNUNET_SCHEDULER_cancel (endbadly_task); - endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); - return; - } - - if (0 != strcmp (label, name)) - { - GNUNET_break (0); - GNUNET_SCHEDULER_cancel (endbadly_task); - endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); - return; - } - - if (2 != rd_count) - { - GNUNET_break (0); - GNUNET_SCHEDULER_cancel (endbadly_task); - endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); - return; - } - - for (c = 0; c < rd_count; c++) - { - if (GNUNET_GNSRECORD_TYPE_NICK == rd[c].record_type) - { - if (rd[c].data_size != strlen (TEST_NICK) + 1) - { - GNUNET_break (0); - GNUNET_SCHEDULER_cancel (endbadly_task); - endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); - return; - } - if (0 != (rd[c].flags & GNUNET_GNSRECORD_RF_PRIVATE)) - { - GNUNET_break (0); - GNUNET_SCHEDULER_cancel (endbadly_task); - endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); - return; - } - if (0 != strcmp (rd[c].data, TEST_NICK)) - { - GNUNET_SCHEDULER_cancel (endbadly_task); - endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); - return; - } - found_nick = GNUNET_YES; - } - else - { - if (rd[c].record_type != TEST_RECORD_TYPE) - { - GNUNET_break (0); - GNUNET_SCHEDULER_cancel (endbadly_task); - endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); - return; - } - if (rd[c].data_size != TEST_RECORD_DATALEN) - { - GNUNET_break (0); - GNUNET_SCHEDULER_cancel (endbadly_task); - endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); - return; - } - if (0 != memcmp (rd[c].data, rd_orig.data, TEST_RECORD_DATALEN)) - { - GNUNET_break (0); - GNUNET_SCHEDULER_cancel (endbadly_task); - endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); - return; - } - if (rd[c].flags != rd->flags) - { - GNUNET_break (0); - GNUNET_SCHEDULER_cancel (endbadly_task); - endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); - return; - } - found_record = GNUNET_YES; - } - } - - /* Done */ - if ((GNUNET_YES == found_nick) && (GNUNET_YES == found_record)) - { - GNUNET_SCHEDULER_cancel (endbadly_task); - endbadly_task = NULL; - GNUNET_SCHEDULER_add_now (&end, NULL); - } - else - { - GNUNET_break (0); - GNUNET_SCHEDULER_cancel (endbadly_task); - endbadly_task = NULL; - GNUNET_SCHEDULER_add_now (&endbadly, NULL); - } -} - - -static void -fail_cb (void *cls) -{ - GNUNET_assert (0); -} - - -static void -put_cont (void *cls, enum GNUNET_ErrorCode ec) -{ - const char *name = cls; - - nsqe = NULL; - GNUNET_assert (NULL != cls); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Name store added record for `%s': %s\n", - name, - (ec == GNUNET_EC_NONE) ? "SUCCESS" : "FAIL"); - - if (GNUNET_EC_NONE != ec) - { - GNUNET_SCHEDULER_cancel (endbadly_task); - endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); - return; - } - /* Lookup */ - nsqe = GNUNET_NAMESTORE_records_lookup (nsh, - &privkey, - name, - &fail_cb, - NULL, - &lookup_it, - NULL); -} - - -static void -nick_cont (void *cls, enum GNUNET_ErrorCode ec) -{ - const char *name = cls; - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Nick added : %s\n", - (ec == GNUNET_EC_NONE) ? "SUCCESS" : "FAIL"); - - rd_orig.expiration_time = GNUNET_TIME_UNIT_HOURS.rel_value_us; - rd_orig.record_type = TEST_RECORD_TYPE; - rd_orig.data_size = TEST_RECORD_DATALEN; - record_data = GNUNET_malloc (TEST_RECORD_DATALEN); - rd_orig.data = record_data; - rd_orig.flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; - memset ((char *) rd_orig.data, 'a', TEST_RECORD_DATALEN); - - nsqe = GNUNET_NAMESTORE_records_store (nsh, &privkey, - name, - 1, - &rd_orig, - &put_cont, (void *) name); -} - - -static void -run (void *cls, - const struct GNUNET_CONFIGURATION_Handle *cfg, - struct GNUNET_TESTING_Peer *peer) -{ - struct GNUNET_GNSRECORD_Data rd; - - endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, - &endbadly, - NULL); - privkey.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); - GNUNET_CRYPTO_ecdsa_key_create (&privkey.ecdsa_key); - GNUNET_CRYPTO_key_get_public (&privkey, - &pubkey); - - nsh = GNUNET_NAMESTORE_connect (cfg); - GNUNET_break (NULL != nsh); - - memset (&rd, 0, sizeof(rd)); - rd.data = TEST_NICK; - rd.data_size = strlen (TEST_NICK) + 1; - rd.record_type = GNUNET_GNSRECORD_TYPE_NICK; - rd.expiration_time = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us; - rd.flags |= GNUNET_GNSRECORD_RF_PRIVATE; - nsqe = GNUNET_NAMESTORE_records_store (nsh, - &privkey, - GNUNET_GNS_EMPTY_LABEL_AT, - 1, - &rd, - &nick_cont, - (void *) name); - - if (NULL == nsqe) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _ ("Namestore cannot store no block\n")); - } -} - - -#include "test_common.c" - - -int -main (int argc, char *argv[]) -{ - const char *plugin_name; - char *cfg_name; - - SETUP_CFG (plugin_name, cfg_name); - res = 1; - if (0 != - GNUNET_TESTING_peer_run ("test-namestore-api-lookup-nick", - cfg_name, - &run, - NULL)) - { - res = 1; - } - GNUNET_DISK_purge_cfg_dir (cfg_name, - "GNUNET_TEST_HOME"); - GNUNET_free (plugin_name); - GNUNET_free (cfg_name); - return res; -} - - -/* end of test_namestore_api_store.c */ diff --git a/src/plugin/namestore/test_namestore_api_monitoring.c b/src/plugin/namestore/test_namestore_api_monitoring.c @@ -1,378 +0,0 @@ -/* - This file is part of GNUnet. - Copyright (C) 2013, 2018 GNUnet e.V. - - GNUnet is free software: you can redistribute it and/or modify it - under the terms of the GNU Affero General Public License as published - by the Free Software Foundation, either version 3 of the License, - or (at your option) any later version. - - GNUnet is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - - SPDX-License-Identifier: AGPL3.0-or-later - */ -/** - * @file namestore/test_namestore_api_monitoring.c - * @brief testcase for zone monitoring functionality: monitor first, then add records - */ -#include "platform.h" -#include "gnunet_namestore_service.h" -#include "gnunet_testing_lib.h" -#include "namestore.h" - -#define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT - - -#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100) - - -static struct GNUNET_NAMESTORE_Handle *nsh; - -static struct GNUNET_SCHEDULER_Task *endbadly_task; - -static struct GNUNET_CRYPTO_PrivateKey privkey; - -static struct GNUNET_CRYPTO_PrivateKey privkey2; - -static struct GNUNET_NAMESTORE_ZoneMonitor *zm; - -static int res; - -static char *s_name_1; - -static struct GNUNET_GNSRECORD_Data *s_rd_1; - -static char *s_name_2; - -static struct GNUNET_GNSRECORD_Data *s_rd_2; - -static char *s_name_3; - -static struct GNUNET_GNSRECORD_Data *s_rd_3; - -struct GNUNET_NAMESTORE_QueueEntry *ns_ops[3]; - - -static void -do_shutdown () -{ - if (NULL != zm) - { - GNUNET_NAMESTORE_zone_monitor_stop (zm); - zm = NULL; - } - if (NULL != ns_ops[0]) - { - GNUNET_NAMESTORE_cancel (ns_ops[0]); - ns_ops[0] = NULL; - } - if (NULL != ns_ops[1]) - { - GNUNET_NAMESTORE_cancel (ns_ops[1]); - ns_ops[1] = NULL; - } - if (NULL != ns_ops[2]) - { - GNUNET_NAMESTORE_cancel (ns_ops[2]); - ns_ops[2] = NULL; - } - if (NULL != nsh) - { - GNUNET_NAMESTORE_disconnect (nsh); - nsh = NULL; - } - GNUNET_free (s_name_1); - GNUNET_free (s_name_2); - GNUNET_free (s_name_3); - - if (s_rd_1 != NULL) - { - GNUNET_free_nz ((void *) s_rd_1->data); - GNUNET_free (s_rd_1); - } - if (s_rd_2 != NULL) - { - GNUNET_free_nz ((void *) s_rd_2->data); - GNUNET_free (s_rd_2); - } - if (s_rd_3 != NULL) - { - GNUNET_free_nz ((void *) s_rd_3->data); - GNUNET_free (s_rd_3); - } -} - - -/** - * Re-establish the connection to the service. - * - * @param cls handle to use to re-connect. - */ -static void -endbadly (void *cls) -{ - do_shutdown (); - res = 1; -} - - -static void -end (void *cls) -{ - do_shutdown (); - res = 0; -} - - -static void -zone_proc (void *cls, - const struct GNUNET_CRYPTO_PrivateKey *zone_key, - const char *name, - unsigned int rd_count, - const struct GNUNET_GNSRECORD_Data *rd) -{ - static int returned_records; - static int fail = GNUNET_NO; - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Comparing results name %s\n", - name); - if (0 != GNUNET_memcmp (zone_key, - &privkey)) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Monitoring returned wrong zone key\n"); - GNUNET_break (0); - GNUNET_SCHEDULER_cancel (endbadly_task); - endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); - return; - } - - if (0 == strcmp (name, s_name_1)) - { - if (GNUNET_YES != GNUNET_GNSRECORD_records_cmp (rd, s_rd_1)) - { - GNUNET_break (0); - fail = GNUNET_YES; - } - } - else if (0 == strcmp (name, s_name_2)) - { - if (GNUNET_YES != GNUNET_GNSRECORD_records_cmp (rd, s_rd_2)) - { - GNUNET_break (0); - fail = GNUNET_YES; - } - } - else - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Invalid name %s\n", - name); - GNUNET_break (0); - fail = GNUNET_YES; - } - GNUNET_NAMESTORE_zone_monitor_next (zm, - 1); - if (2 == ++returned_records) - { - if (endbadly_task != NULL) - { - GNUNET_SCHEDULER_cancel (endbadly_task); - endbadly_task = NULL; - } - if (GNUNET_YES == fail) - GNUNET_SCHEDULER_add_now (&endbadly, NULL); - else - GNUNET_SCHEDULER_add_now (&end, NULL); - } -} - - -static void -put_cont (void *cls, - enum GNUNET_ErrorCode ec) -{ - static int c = 0; - char *label = cls; - - if (0 == strcmp (label, s_name_1)) - ns_ops[0] = NULL; - else if (0 == strcmp (label, s_name_2)) - ns_ops[1] = NULL; - else if (0 == strcmp (label, s_name_3)) - ns_ops[2] = NULL; - - if (GNUNET_EC_NONE == ec) - { - c++; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Created record %u: `%s'\n", - c, - label); - } - else - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Failed to create record `%s'\n", - label); - GNUNET_break (0); - GNUNET_SCHEDULER_cancel (endbadly_task); - endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, - NULL); - } -} - - -static struct GNUNET_GNSRECORD_Data * -create_record (unsigned int count) -{ - struct GNUNET_GNSRECORD_Data *rd; - - rd = GNUNET_new_array (count, - struct GNUNET_GNSRECORD_Data); - for (unsigned int c = 0; c < count; c++) - { - rd[c].expiration_time = GNUNET_TIME_relative_to_absolute ( - GNUNET_TIME_UNIT_HOURS).abs_value_us; - rd[c].record_type = TEST_RECORD_TYPE; - rd[c].data_size = 50; - rd[c].data = GNUNET_malloc (50); - rd[c].flags = 0; - memset ((char *) rd[c].data, 'a', 50); - } - return rd; -} - - -static void -fail_cb (void *cls) -{ - GNUNET_assert (0); -} - - -static void -sync_cb (void *cls) -{ - /* do nothing */ -} - - -static void -run (void *cls, - const struct GNUNET_CONFIGURATION_Handle *cfg, - struct GNUNET_TESTING_Peer *peer) -{ - res = 1; - privkey.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); - GNUNET_CRYPTO_ecdsa_key_create (&privkey.ecdsa_key); - /* Start monitoring */ - zm = GNUNET_NAMESTORE_zone_monitor_start (cfg, - &privkey, - GNUNET_YES, - &fail_cb, - NULL, - &zone_proc, - NULL, - &sync_cb, - NULL); - if (NULL == zm) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Failed to create zone monitor\n"); - GNUNET_break (0); - endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); - return; - } - - endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &endbadly, NULL); - /* Connect to namestore */ - nsh = GNUNET_NAMESTORE_connect (cfg); - if (NULL == nsh) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Connect to namestore\n"); - GNUNET_break (0); - endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); - return; - } - - privkey2.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); - GNUNET_CRYPTO_ecdsa_key_create (&privkey2.ecdsa_key); - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Created record 3\n"); - /* name in different zone */ - GNUNET_asprintf (&s_name_3, "dummy3"); - s_rd_3 = create_record (1); - GNUNET_assert (NULL != (ns_ops[2] = - GNUNET_NAMESTORE_records_store (nsh, - &privkey2, - s_name_3, - 1, - s_rd_3, - &put_cont, - s_name_3))); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Created record 1\n"); - GNUNET_asprintf (&s_name_1, "dummy1"); - s_rd_1 = create_record (1); - GNUNET_assert (NULL != (ns_ops[0] = - GNUNET_NAMESTORE_records_store (nsh, - &privkey, - s_name_1, - 1, - s_rd_1, - &put_cont, - s_name_1))); - - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 2 \n"); - GNUNET_asprintf (&s_name_2, "dummy2"); - s_rd_2 = create_record (1); - GNUNET_assert (NULL != (ns_ops[1] = - GNUNET_NAMESTORE_records_store (nsh, - &privkey, - s_name_2, - 1, - s_rd_2, - &put_cont, - s_name_2))); -} - - -#include "test_common.c" - - -int -main (int argc, - char *argv[]) -{ - const char *plugin_name; - char *cfg_name; - - SETUP_CFG (plugin_name, cfg_name); - res = 1; - if (0 != - GNUNET_TESTING_peer_run ("test-namestore-api-monitoring", - cfg_name, - &run, - NULL)) - { - res = 1; - } - GNUNET_DISK_purge_cfg_dir (cfg_name, - "GNUNET_TEST_HOME"); - GNUNET_free (plugin_name); - GNUNET_free (cfg_name); - return res; -} - - -/* end of test_namestore_api_monitoring.c */ diff --git a/src/plugin/namestore/test_namestore_api_monitoring_existing.c b/src/plugin/namestore/test_namestore_api_monitoring_existing.c @@ -1,393 +0,0 @@ -/* - This file is part of GNUnet. - Copyright (C) 2013, 2018 GNUnet e.V. - - GNUnet is free software: you can redistribute it and/or modify it - under the terms of the GNU Affero General Public License as published - by the Free Software Foundation, either version 3 of the License, - or (at your option) any later version. - - GNUnet is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - - SPDX-License-Identifier: AGPL3.0-or-later - */ -/** - * @file namestore/test_namestore_api_monitoring_existing.c - * @brief testcase for zone monitoring functionality: add records first, then monitor - */ -#include "platform.h" -#include "gnunet_namestore_service.h" -#include "gnunet_testing_lib.h" -#include "namestore.h" - -#define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT - - -#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) - -static const struct GNUNET_CONFIGURATION_Handle *cfg; - -static struct GNUNET_NAMESTORE_Handle *nsh; - -static struct GNUNET_SCHEDULER_Task *endbadly_task; - -static struct GNUNET_CRYPTO_PrivateKey privkey; - -static struct GNUNET_CRYPTO_PrivateKey privkey2; - -static struct GNUNET_NAMESTORE_ZoneMonitor *zm; - -static int res; - -static const char *s_name_1; - -static struct GNUNET_GNSRECORD_Data *s_rd_1; - -static const char *s_name_2; - -static struct GNUNET_GNSRECORD_Data *s_rd_2; - -static const char *s_name_3; - -static struct GNUNET_GNSRECORD_Data *s_rd_3; - -struct GNUNET_NAMESTORE_QueueEntry *ns_ops[3]; - - -/** - * Re-establish the connection to the service. - * - * @param cls handle to use to re-connect. - */ -static void -endbadly (void *cls) -{ - endbadly_task = NULL; - GNUNET_break (0); - GNUNET_SCHEDULER_shutdown (); - res = 1; -} - - -static void -end (void *cls) -{ - if (NULL != zm) - { - GNUNET_NAMESTORE_zone_monitor_stop (zm); - zm = NULL; - } - if (NULL != ns_ops[0]) - { - GNUNET_NAMESTORE_cancel (ns_ops[0]); - ns_ops[0] = NULL; - } - if (NULL != ns_ops[1]) - { - GNUNET_NAMESTORE_cancel (ns_ops[1]); - ns_ops[1] = NULL; - } - if (NULL != ns_ops[2]) - { - GNUNET_NAMESTORE_cancel (ns_ops[2]); - ns_ops[2] = NULL; - } - if (NULL != endbadly_task) - { - GNUNET_SCHEDULER_cancel (endbadly_task); - endbadly_task = NULL; - } - if (NULL != nsh) - { - GNUNET_NAMESTORE_disconnect (nsh); - nsh = NULL; - } - if (NULL != s_rd_1) - { - GNUNET_free_nz ((void *) s_rd_1->data); - GNUNET_free (s_rd_1); - } - if (NULL != s_rd_2) - { - GNUNET_free_nz ((void *) s_rd_2->data); - GNUNET_free (s_rd_2); - } - if (NULL != s_rd_3) - { - GNUNET_free_nz ((void *) s_rd_3->data); - GNUNET_free (s_rd_3); - } -} - - -static void -zone_proc (void *cls, - const struct GNUNET_CRYPTO_PrivateKey *zone_key, - const char *name, - unsigned int rd_count, - const struct GNUNET_GNSRECORD_Data *rd) -{ - static int returned_records; - static int fail = GNUNET_NO; - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Comparing results name %s\n", - name); - if (0 != GNUNET_memcmp (zone_key, - &privkey)) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Monitoring returned wrong zone key\n"); - GNUNET_break (0); - GNUNET_SCHEDULER_shutdown (); - return; - } - - if (0 == strcmp (name, - s_name_1)) - { - if (GNUNET_YES != - GNUNET_GNSRECORD_records_cmp (rd, - s_rd_1)) - { - GNUNET_break (0); - fail = GNUNET_YES; - } - } - else if (0 == strcmp (name, - s_name_2)) - { - if (GNUNET_YES != - GNUNET_GNSRECORD_records_cmp (rd, - s_rd_2)) - { - GNUNET_break (0); - fail = GNUNET_YES; - } - } - else - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Invalid name %s\n", - name); - GNUNET_break (0); - fail = GNUNET_YES; - } - GNUNET_NAMESTORE_zone_monitor_next (zm, - 1); - if (2 == ++returned_records) - { - GNUNET_SCHEDULER_shutdown (); - if (GNUNET_YES == fail) - { - GNUNET_break (0); - res = 1; - } - else - { - res = 0; - } - } -} - - -static void -fail_cb (void *cls) -{ - GNUNET_assert (0); -} - - -static void -sync_cb (void *cls) -{ - /* do nothing */ -} - - -static void -put_cont (void *cls, - enum GNUNET_ErrorCode ec) -{ - static int c = 0; - const char *label = cls; - - if (0 == strcmp (label, - s_name_1)) - ns_ops[0] = NULL; - else if (0 == strcmp (label, - s_name_2)) - ns_ops[1] = NULL; - else if (0 == strcmp (label, - s_name_3)) - ns_ops[2] = NULL; - - if (GNUNET_EC_NONE == ec) - { - c++; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Created record %u: `%s'\n", - c, - label); - } - else - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Failed to created records\n"); - GNUNET_break (0); - res = 1; - GNUNET_SCHEDULER_shutdown (); - return; - } - -} - - -static struct GNUNET_GNSRECORD_Data * -create_record (unsigned int count) -{ - struct GNUNET_GNSRECORD_Data *rd; - - rd = GNUNET_new_array (count, - struct GNUNET_GNSRECORD_Data); - for (unsigned int c = 0; c < count; c++) - { - rd[c].expiration_time = GNUNET_TIME_relative_to_absolute ( - GNUNET_TIME_UNIT_HOURS).abs_value_us; - rd[c].record_type = TEST_RECORD_TYPE; - rd[c].data_size = 50; - rd[c].data = GNUNET_malloc (50); - rd[c].flags = 0; - memset ((char *) rd[c].data, - 'a', - 50); - } - return rd; -} - - -static void -run (void *cls, - const struct GNUNET_CONFIGURATION_Handle *mycfg, - struct GNUNET_TESTING_Peer *peer) -{ - res = 1; - privkey.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); - privkey2.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); - GNUNET_CRYPTO_ecdsa_key_create (&privkey.ecdsa_key); - GNUNET_CRYPTO_ecdsa_key_create (&privkey2.ecdsa_key); - - cfg = mycfg; - GNUNET_SCHEDULER_add_shutdown (&end, - NULL); - endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, - &endbadly, - NULL); - /* Connect to namestore */ - nsh = GNUNET_NAMESTORE_connect (cfg); - if (NULL == nsh) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Connect to namestore failed\n"); - GNUNET_break (0); - endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, - NULL); - return; - } - /* Start monitoring */ - zm = GNUNET_NAMESTORE_zone_monitor_start (cfg, - &privkey, - GNUNET_YES, - &fail_cb, - NULL, - &zone_proc, - NULL, - &sync_cb, - NULL); - if (NULL == zm) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Failed to create zone monitor\n"); - GNUNET_break (0); - res = 1; - GNUNET_SCHEDULER_shutdown (); - return; - } - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Created record 3\n"); - /* name in different zone */ - s_name_3 = "dummy3"; - s_rd_3 = create_record (1); - GNUNET_assert (NULL != (ns_ops[2] = - GNUNET_NAMESTORE_records_store (nsh, - &privkey2, - s_name_3, - 1, - s_rd_3, - &put_cont, - (void *) s_name_3))); - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Created record 1\n"); - s_name_1 = "dummy1"; - s_rd_1 = create_record (1); - GNUNET_assert (NULL != (ns_ops[0] = - GNUNET_NAMESTORE_records_store (nsh, - &privkey, - s_name_1, - 1, - s_rd_1, - &put_cont, - (void *) s_name_1))); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Created record 2 \n"); - s_name_2 = "dummy2"; - s_rd_2 = create_record (1); - GNUNET_assert (NULL != (ns_ops[1] = - GNUNET_NAMESTORE_records_store (nsh, - &privkey, - s_name_2, - 1, - s_rd_2, - &put_cont, - (void *) s_name_2))); -} - - -#include "test_common.c" - - -int -main (int argc, - char *argv[]) -{ - const char *plugin_name; - char *cfg_name; - - SETUP_CFG (plugin_name, cfg_name); - res = 1; - if (0 != - GNUNET_TESTING_peer_run ("test-namestore-api-monitoring-existing", - cfg_name, - &run, - NULL)) - { - GNUNET_break (0); - res = 1; - } - GNUNET_DISK_purge_cfg_dir (cfg_name, - "GNUNET_TEST_HOME"); - GNUNET_free (plugin_name); - GNUNET_free (cfg_name); - return res; -} - - -/* end of test_namestore_api_monitoring_existing.c */ diff --git a/src/plugin/namestore/test_namestore_api_remove.c b/src/plugin/namestore/test_namestore_api_remove.c @@ -1,219 +0,0 @@ -/* - This file is part of GNUnet. - Copyright (C) 2013 GNUnet e.V. - - GNUnet is free software: you can redistribute it and/or modify it - under the terms of the GNU Affero General Public License as published - by the Free Software Foundation, either version 3 of the License, - or (at your option) any later version. - - GNUnet is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - - SPDX-License-Identifier: AGPL3.0-or-later - */ -/** - * @file namestore/test_namestore_api.c - * @brief testcase for namestore_api.c to: remove record - */ -#include "platform.h" -#include "gnunet_namestore_service.h" -#include "gnunet_testing_lib.h" - -#define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT - -#define TEST_RECORD_DATALEN 123 - -#define TEST_RECORD_DATA 'a' - -#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100) - - -static struct GNUNET_NAMESTORE_Handle *nsh; - -static struct GNUNET_SCHEDULER_Task *endbadly_task; - -static struct GNUNET_CRYPTO_PrivateKey privkey; - -static struct GNUNET_CRYPTO_PublicKey pubkey; - -static int res; - -static int removed; - -static struct GNUNET_NAMESTORE_QueueEntry *nsqe; - - -static void -cleanup () -{ - if (NULL != nsh) - { - GNUNET_NAMESTORE_disconnect (nsh); - nsh = NULL; - } - GNUNET_SCHEDULER_shutdown (); -} - - -/** - * Re-establish the connection to the service. - * - * @param cls handle to use to re-connect. - */ -static void -endbadly (void *cls) -{ - if (NULL != nsqe) - { - GNUNET_NAMESTORE_cancel (nsqe); - nsqe = NULL; - } - cleanup (); - res = 1; -} - - -static void -end (void *cls) -{ - cleanup (); - res = 0; -} - - -static void -remove_cont (void *cls, - enum GNUNET_ErrorCode ec) -{ - nsqe = NULL; - if (GNUNET_EC_NONE != ec) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _ ("Records could not be removed: `%s'\n"), - GNUNET_ErrorCode_get_hint (ec)); - if (NULL != endbadly_task) - GNUNET_SCHEDULER_cancel (endbadly_task); - endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, - NULL); - return; - } - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Records were removed, perform lookup\n"); - removed = GNUNET_YES; - if (NULL != endbadly_task) - GNUNET_SCHEDULER_cancel (endbadly_task); - GNUNET_SCHEDULER_add_now (&end, NULL); -} - - -static void -put_cont (void *cls, - enum GNUNET_ErrorCode ec) -{ - const char *name = cls; - - GNUNET_assert (NULL != cls); - nsqe = NULL; - if (GNUNET_EC_NONE != ec) - { - GNUNET_break (0); - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Namestore could not store record: `%s'\n", - GNUNET_ErrorCode_get_hint (ec)); - if (endbadly_task != NULL) - GNUNET_SCHEDULER_cancel (endbadly_task); - endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); - return; - } - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Name store added record for `%s': %s\n", - name, - (GNUNET_EC_NONE == ec) ? "SUCCESS" : "FAIL"); - nsqe = GNUNET_NAMESTORE_records_store (nsh, - &privkey, - name, - 0, NULL, - &remove_cont, (void *) name); -} - - -static void -run (void *cls, - const struct GNUNET_CONFIGURATION_Handle *cfg, - struct GNUNET_TESTING_Peer *peer) -{ - struct GNUNET_GNSRECORD_Data rd; - const char *name = "dummy"; - - endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, - &endbadly, - NULL); - privkey.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); - GNUNET_CRYPTO_ecdsa_key_create (&privkey.ecdsa_key); - GNUNET_CRYPTO_key_get_public (&privkey, - &pubkey); - - removed = GNUNET_NO; - - rd.expiration_time = GNUNET_TIME_UNIT_MINUTES.rel_value_us; - rd.record_type = TEST_RECORD_TYPE; - rd.data_size = TEST_RECORD_DATALEN; - rd.data = GNUNET_malloc (TEST_RECORD_DATALEN); - rd.flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; - memset ((char *) rd.data, - 'a', - TEST_RECORD_DATALEN); - - nsh = GNUNET_NAMESTORE_connect (cfg); - GNUNET_break (NULL != nsh); - nsqe = GNUNET_NAMESTORE_records_store (nsh, - &privkey, - name, - 1, - &rd, - &put_cont, - (void *) name); - if (NULL == nsqe) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _ ("Namestore cannot store no block\n")); - } - GNUNET_free_nz ((void *) rd.data); -} - - -#include "test_common.c" - - -int -main (int argc, char *argv[]) -{ - const char *plugin_name; - char *cfg_name; - - SETUP_CFG (plugin_name, cfg_name); - res = 1; - if (0 != - GNUNET_TESTING_peer_run ("test-namestore-api-remove", - cfg_name, - &run, - NULL)) - { - res = 1; - } - GNUNET_DISK_purge_cfg_dir (cfg_name, - "GNUNET_TEST_HOME"); - GNUNET_free (plugin_name); - GNUNET_free (cfg_name); - return res; -} - - -/* end of test_namestore_api_remove.c */ diff --git a/src/plugin/namestore/test_namestore_api_remove_not_existing_record.c b/src/plugin/namestore/test_namestore_api_remove_not_existing_record.c @@ -1,179 +0,0 @@ -/* - This file is part of GNUnet. - Copyright (C) 2013 GNUnet e.V. - - GNUnet is free software: you can redistribute it and/or modify it - under the terms of the GNU Affero General Public License as published - by the Free Software Foundation, either version 3 of the License, - or (at your option) any later version. - - GNUnet is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - - SPDX-License-Identifier: AGPL3.0-or-later - */ -/** - * @file namestore/test_namestore_api_remove_not_existing_record.c - * @brief testcase for namestore_api.c - */ -#include "platform.h" -#include "gnunet_namestore_service.h" -#include "gnunet_testing_lib.h" - -#define TEST_RECORD_TYPE 1234 - -#define TEST_RECORD_DATALEN 123 - -#define TEST_RECORD_DATA 'a' - -#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100) - - -static struct GNUNET_NAMESTORE_Handle *nsh; - -static struct GNUNET_SCHEDULER_Task *endbadly_task; - -static struct GNUNET_CRYPTO_PrivateKey privkey; - -static struct GNUNET_CRYPTO_PublicKey pubkey; - -static int res; - -static struct GNUNET_NAMESTORE_QueueEntry *nsqe; - - -static void -cleanup (void) -{ - if (NULL != nsh) - { - GNUNET_NAMESTORE_disconnect (nsh); - nsh = NULL; - } - GNUNET_SCHEDULER_shutdown (); -} - - -/** - * Re-establish the connection to the service. - * - * @param cls handle to use to re-connect. - */ -static void -endbadly (void *cls) -{ - if (NULL != nsqe) - { - GNUNET_NAMESTORE_cancel (nsqe); - nsqe = NULL; - } - cleanup (); - res = 1; -} - - -static void -end (void *cls) -{ - cleanup (); - res = 0; -} - - -static void -put_cont (void *cls, - enum GNUNET_ErrorCode ec) -{ - GNUNET_assert (NULL != cls); - nsqe = NULL; - if (endbadly_task != NULL) - { - GNUNET_SCHEDULER_cancel (endbadly_task); - endbadly_task = NULL; - } - switch (ec) - { - case GNUNET_EC_NAMESTORE_RECORD_NOT_FOUND: - /* We expect that the record is not found */ - GNUNET_SCHEDULER_add_now (&end, NULL); - break; - - case GNUNET_EC_NONE: - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Namestore could remove non-existing record: `%s'\n", - GNUNET_ErrorCode_get_hint (ec)); - GNUNET_SCHEDULER_add_now (&endbadly, NULL); - break; - - default: - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Namestore failed: `%s'\n", - GNUNET_ErrorCode_get_hint (ec)); - GNUNET_SCHEDULER_add_now (&endbadly, NULL); - break; - } -} - - -static void -run (void *cls, - const struct GNUNET_CONFIGURATION_Handle *cfg, - struct GNUNET_TESTING_Peer *peer) -{ - const char *name = "dummy"; - - endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, - &endbadly, - NULL); - privkey.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); - GNUNET_CRYPTO_ecdsa_key_create (&privkey.ecdsa_key); - GNUNET_CRYPTO_key_get_public (&privkey, &pubkey); - - nsh = GNUNET_NAMESTORE_connect (cfg); - GNUNET_break (NULL != nsh); - nsqe = GNUNET_NAMESTORE_records_store (nsh, - &privkey, - name, - 0, NULL, - &put_cont, (void *) name); - if (NULL == nsqe) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _ ("Namestore cannot store no block\n")); - } -} - - -#include "test_common.c" - - -int -main (int argc, char *argv[]) -{ - const char *plugin_name; - char *cfg_name; - - SETUP_CFG (plugin_name, cfg_name); - res = 1; - if (0 != - GNUNET_TESTING_peer_run ("test-namestore-api-remove-non-existing-record", - cfg_name, - &run, - NULL)) - { - res = 1; - } - GNUNET_DISK_purge_cfg_dir (cfg_name, - "GNUNET_TEST_HOME"); - GNUNET_free (plugin_name); - GNUNET_free (cfg_name); - return res; -} - - -/* end of test_namestore_api_remove_not_existing_record.c */ diff --git a/src/plugin/namestore/test_namestore_api_store.c b/src/plugin/namestore/test_namestore_api_store.c @@ -1,172 +0,0 @@ -/* - This file is part of GNUnet. - Copyright (C) 2012 GNUnet e.V. - - GNUnet is free software: you can redistribute it and/or modify it - under the terms of the GNU Affero General Public License as published - by the Free Software Foundation, either version 3 of the License, - or (at your option) any later version. - - GNUnet is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - - SPDX-License-Identifier: AGPL3.0-or-later - */ -/** - * @file namestore/test_namestore_api_store.c - * @brief testcase for namestore_api.c: store a record - */ -#include "platform.h" -#include "gnunet_namestore_service.h" -#include "gnunet_testing_lib.h" - -#define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT - -#define TEST_RECORD_DATALEN 123 - -#define TEST_RECORD_DATA 'a' - -#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100) - - -static struct GNUNET_NAMESTORE_Handle *nsh; - -static struct GNUNET_SCHEDULER_Task *endbadly_task; - -static struct GNUNET_CRYPTO_PrivateKey privkey; - -static struct GNUNET_CRYPTO_PublicKey pubkey; - -static int res; - -static struct GNUNET_NAMESTORE_QueueEntry *nsqe; - - -static void -cleanup () -{ - if (NULL != nsh) - { - GNUNET_NAMESTORE_disconnect (nsh); - nsh = NULL; - } - GNUNET_SCHEDULER_shutdown (); -} - - -/** - * Re-establish the connection to the service. - * - * @param cls handle to use to re-connect. - */ -static void -endbadly (void *cls) -{ - if (NULL != nsqe) - { - GNUNET_NAMESTORE_cancel (nsqe); - nsqe = NULL; - } - cleanup (); - res = 1; -} - - -static void -end (void *cls) -{ - cleanup (); - res = 0; -} - - -static void -put_cont (void *cls, enum GNUNET_ErrorCode ec) -{ - const char *name = cls; - - nsqe = NULL; - GNUNET_assert (NULL != cls); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Name store added record for `%s': %s\n", - name, - (GNUNET_EC_NONE == ec) ? "SUCCESS" : "FAIL"); - GNUNET_SCHEDULER_cancel (endbadly_task); - endbadly_task = NULL; - GNUNET_SCHEDULER_add_now (&end, NULL); -} - - -static void -run (void *cls, - const struct GNUNET_CONFIGURATION_Handle *cfg, - struct GNUNET_TESTING_Peer *peer) -{ - struct GNUNET_GNSRECORD_Data rd; - const char *name = "dummy.dummy.gnunet"; - - endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, - &endbadly, NULL); - privkey.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); - GNUNET_CRYPTO_ecdsa_key_create (&privkey.ecdsa_key); - GNUNET_CRYPTO_key_get_public (&privkey, &pubkey); - - - rd.expiration_time = GNUNET_TIME_absolute_get ().abs_value_us; - rd.record_type = TEST_RECORD_TYPE; - rd.data_size = TEST_RECORD_DATALEN; - rd.data = GNUNET_malloc (TEST_RECORD_DATALEN); - rd.flags = 0; - memset ((char *) rd.data, 'a', TEST_RECORD_DATALEN); - - nsh = GNUNET_NAMESTORE_connect (cfg); - GNUNET_break (NULL != nsh); - nsqe = GNUNET_NAMESTORE_records_store (nsh, - &privkey, - name, - 1, - &rd, - &put_cont, - (void *) name); - if (NULL == nsqe) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _ ("Namestore cannot store no block\n")); - } - GNUNET_free_nz ((void *) rd.data); -} - - -#include "test_common.c" - - -int -main (int argc, char *argv[]) -{ - const char *plugin_name; - char *cfg_name; - - SETUP_CFG (plugin_name, cfg_name); - res = 1; - if (0 != - GNUNET_TESTING_peer_run ("test-namestore-api", - cfg_name, - &run, - NULL)) - { - res = 1; - } - GNUNET_DISK_purge_cfg_dir (cfg_name, - "GNUNET_TEST_HOME"); - GNUNET_free (plugin_name); - GNUNET_free (cfg_name); - return res; -} - - -/* end of test_namestore_api_store.c */ diff --git a/src/plugin/namestore/test_namestore_api_store_update.c b/src/plugin/namestore/test_namestore_api_store_update.c @@ -1,269 +0,0 @@ -/* - This file is part of GNUnet. - Copyright (C) 2012, 2013, 2018 GNUnet e.V. - - GNUnet is free software: you can redistribute it and/or modify it - under the terms of the GNU Affero General Public License as published - by the Free Software Foundation, either version 3 of the License, - or (at your option) any later version. - - GNUnet is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - - SPDX-License-Identifier: AGPL3.0-or-later - */ -/** - * @file namestore/test_namestore_api_store_update.c - * @brief testcase for namestore_api.c: store a record, update it and perform a lookup - * @author Matthias Wachs - * @author Christian Grothoff - */ -#include "platform.h" -#include "gnunet_namestore_service.h" -#include "gnunet_testing_lib.h" - -#define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT - -#define TEST_RECORD_DATALEN 123 - -#define TEST_RECORD_DATA 'a' - -#define TEST_RECORD_DATALEN2 234 - -#define TEST_RECORD_DATA2 'b' - -#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100) - - -static struct GNUNET_NAMESTORE_Handle *nsh; - -static struct GNUNET_SCHEDULER_Task *endbadly_task; - -static struct GNUNET_CRYPTO_PrivateKey privkey; - -static struct GNUNET_CRYPTO_PublicKey pubkey; - -static int res; - -static int update_performed; - -static struct GNUNET_NAMESTORE_QueueEntry *nsqe; - -static const char *name = "dummy"; - - -/** - * Terminate test with error. - * - * @param cls handle to use to re-connect. - */ -static void -endbadly (void *cls) -{ - GNUNET_break (0); - endbadly_task = NULL; - GNUNET_SCHEDULER_shutdown (); - res = 1; -} - - -static void -end (void *cls) -{ - if (NULL != endbadly_task) - { - GNUNET_SCHEDULER_cancel (endbadly_task); - endbadly_task = NULL; - } - if (NULL != nsqe) - { - GNUNET_NAMESTORE_cancel (nsqe); - nsqe = NULL; - } - if (NULL != nsh) - { - GNUNET_NAMESTORE_disconnect (nsh); - nsh = NULL; - } -} - - -static void -put_cont (void *cls, - enum GNUNET_ErrorCode ec); - - -static void -lookup_success (void *cls, - const struct GNUNET_CRYPTO_PrivateKey *zone, - const char* label, - unsigned int rd_count, - const struct GNUNET_GNSRECORD_Data *rd) -{ - struct GNUNET_GNSRECORD_Data rd_new; - - GNUNET_assert (1 == rd_count); - GNUNET_assert (NULL != rd); - nsqe = NULL; - if (GNUNET_NO == update_performed) - { - char rd_cmp_data[TEST_RECORD_DATALEN]; - - memset (rd_cmp_data, - TEST_RECORD_DATA, - TEST_RECORD_DATALEN); - GNUNET_assert (TEST_RECORD_TYPE == rd[0].record_type); - GNUNET_assert (TEST_RECORD_DATALEN == rd[0].data_size); - GNUNET_assert (0 == memcmp (&rd_cmp_data, - rd[0].data, - TEST_RECORD_DATALEN)); - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Block was decrypted successfully, updating record \n"); - - rd_new.flags = GNUNET_GNSRECORD_RF_NONE; - rd_new.expiration_time = GNUNET_TIME_absolute_get ().abs_value_us - + 1000000000; - rd_new.record_type = TEST_RECORD_TYPE; - rd_new.data_size = TEST_RECORD_DATALEN2; - rd_new.data = GNUNET_malloc (TEST_RECORD_DATALEN2); - memset ((char *) rd_new.data, - TEST_RECORD_DATA2, - TEST_RECORD_DATALEN2); - - nsqe = GNUNET_NAMESTORE_records_store (nsh, - &privkey, - name, - 1, - &rd_new, - &put_cont, - (void *) name); - GNUNET_free (rd_new.data); - update_performed = GNUNET_YES; - } - else - { - char rd_cmp_data[TEST_RECORD_DATALEN2]; - - memset (rd_cmp_data, - TEST_RECORD_DATA2, - TEST_RECORD_DATALEN2); - GNUNET_assert (TEST_RECORD_TYPE == rd[0].record_type); - GNUNET_assert (TEST_RECORD_DATALEN2 == rd[0].data_size); - GNUNET_assert (0 == memcmp (&rd_cmp_data, - rd[0].data, - TEST_RECORD_DATALEN2)); - GNUNET_SCHEDULER_shutdown (); - res = 0; - } -} - - -static void -put_cont (void *cls, - enum GNUNET_ErrorCode ec) -{ - const char *name = cls; - struct GNUNET_HashCode derived_hash; - - nsqe = NULL; - GNUNET_assert (NULL != cls); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Name store added record for `%s': %s\n", - name, - (GNUNET_EC_NONE == ec) ? "SUCCESS" : "FAIL"); - /* Create derived hash */ - GNUNET_GNSRECORD_query_from_private_key (&privkey, - name, - &derived_hash); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Looking in namestore for `%s'\n", - GNUNET_h2s (&derived_hash)); - nsqe = GNUNET_NAMESTORE_records_lookup (nsh, - &privkey, - name, - &endbadly, - (void *) name, - & lookup_success, - (void *) name); -} - - -static void -run (void *cls, - const struct GNUNET_CONFIGURATION_Handle *cfg, - struct GNUNET_TESTING_Peer *peer) -{ - struct GNUNET_GNSRECORD_Data rd; - - update_performed = GNUNET_NO; - GNUNET_SCHEDULER_add_shutdown (&end, - NULL); - endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, - &endbadly, - NULL); - memset (&privkey, 0, sizeof (privkey)); - privkey.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); - GNUNET_CRYPTO_ecdsa_key_create (&privkey.ecdsa_key); - GNUNET_CRYPTO_key_get_public (&privkey, &pubkey); - rd.flags = GNUNET_GNSRECORD_RF_NONE; - rd.expiration_time = GNUNET_TIME_absolute_get ().abs_value_us + 1000000000; - rd.record_type = TEST_RECORD_TYPE; - rd.data_size = TEST_RECORD_DATALEN; - rd.data = GNUNET_malloc (TEST_RECORD_DATALEN); - memset ((char *) rd.data, - TEST_RECORD_DATA, - TEST_RECORD_DATALEN); - - nsh = GNUNET_NAMESTORE_connect (cfg); - GNUNET_break (NULL != nsh); - nsqe = GNUNET_NAMESTORE_records_store (nsh, - &privkey, - name, - 1, - &rd, - &put_cont, - (void *) name); - if (NULL == nsqe) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _ ("Namestore cannot store no block\n")); - } - GNUNET_free_nz ((void *) rd.data); -} - - -#include "test_common.c" - - -int -main (int argc, - char *argv[]) -{ - const char *plugin_name; - char *cfg_name; - - SETUP_CFG (plugin_name, cfg_name); - res = 1; - if (0 != - GNUNET_TESTING_peer_run ("test--store-update", - cfg_name, - &run, - NULL)) - { - res = 1; - } - GNUNET_DISK_purge_cfg_dir (cfg_name, - "GNUNET_TEST_HOME"); - GNUNET_free (plugin_name); - GNUNET_free (cfg_name); - return res; -} - - -/* end of test_namestore_api_store_update.c */ diff --git a/src/plugin/namestore/test_namestore_api_tx_rollback.c b/src/plugin/namestore/test_namestore_api_tx_rollback.c @@ -1,264 +0,0 @@ -/* - This file is part of GNUnet. - Copyright (C) 2022 GNUnet e.V. - - GNUnet is free software: you can redistribute it and/or modify it - under the terms of the GNU Affero General Public License as published - by the Free Software Foundation, either version 3 of the License, - or (at your option) any later version. - - GNUnet is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - - SPDX-License-Identifier: AGPL3.0-or-later - */ -/** - * @file namestore/test_namestore_api_tx_rollback.c - * @brief testcase for namestore_api_tx_rollback.c to: rollback changes in TX - */ -#include "platform.h" -#include "gnunet_namestore_service.h" -#include "gnunet_testing_lib.h" - -#define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT - -#define TEST_RECORD_DATALEN 123 - -#define TEST_RECORD_DATA 'a' - -#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100) - - -static struct GNUNET_NAMESTORE_Handle *nsh; - -static struct GNUNET_SCHEDULER_Task *endbadly_task; - -static struct GNUNET_CRYPTO_PrivateKey privkey; - -static struct GNUNET_CRYPTO_PublicKey pubkey; - -static int res; - -static int removed; - -static struct GNUNET_NAMESTORE_QueueEntry *nsqe; - - -static void -cleanup () -{ - if (NULL != nsh) - { - GNUNET_NAMESTORE_disconnect (nsh); - nsh = NULL; - } - GNUNET_SCHEDULER_shutdown (); -} - - -/** - * Re-establish the connection to the service. - * - * @param cls handle to use to re-connect. - */ -static void -endbadly (void *cls) -{ - if (NULL != nsqe) - { - GNUNET_NAMESTORE_cancel (nsqe); - nsqe = NULL; - } - cleanup (); - res = 1; -} - - -static void -end (void *cls) -{ - cleanup (); - res = 0; -} - -static void -lookup_it (void *cls, - const struct GNUNET_CRYPTO_PrivateKey *zone, - const char *label, - unsigned int rd_count, - const struct GNUNET_GNSRECORD_Data *rd) -{ - GNUNET_assert (0 == rd_count); - GNUNET_SCHEDULER_add_now (&end, NULL); -} - -static void -fail_cb (void *cls) -{ - GNUNET_assert (0); -} - -static void -remove_cont (void *cls, - enum GNUNET_ErrorCode ec) -{ - nsqe = NULL; - if (GNUNET_EC_NONE != ec) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _ ("Unable to roll back: `%s'\n"), - GNUNET_ErrorCode_get_hint (ec)); - if (NULL != endbadly_task) - GNUNET_SCHEDULER_cancel (endbadly_task); - endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, - NULL); - return; - } - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Rolled back, perform lookup\n"); - removed = GNUNET_YES; - if (NULL != endbadly_task) - GNUNET_SCHEDULER_cancel (endbadly_task); - /* FIXME not actually doing lookup here */ - nsqe = GNUNET_NAMESTORE_records_lookup (nsh, - &privkey, - (char*) cls, - &fail_cb, - NULL, - &lookup_it, - NULL); -} - - -static void -put_cont (void *cls, - enum GNUNET_ErrorCode ec) -{ - const char *name = cls; - - GNUNET_assert (NULL != cls); - nsqe = NULL; - if (GNUNET_EC_NONE != ec) - { - GNUNET_break (0); - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Namestore could not store record: `%s'\n", - GNUNET_ErrorCode_get_hint (ec)); - if (endbadly_task != NULL) - GNUNET_SCHEDULER_cancel (endbadly_task); - endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); - return; - } - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Name store added record for `%s': %s\n", - name, - (GNUNET_EC_NONE == ec) ? "SUCCESS" : "FAIL"); - nsqe = GNUNET_NAMESTORE_transaction_rollback (nsh, remove_cont, - (void *) name); -} - -static void -begin_cont (void *cls, - enum GNUNET_ErrorCode ec) -{ - struct GNUNET_GNSRECORD_Data rd; - const char *name = cls; - - GNUNET_assert (GNUNET_EC_NONE == ec); - privkey.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); - GNUNET_CRYPTO_ecdsa_key_create (&privkey.ecdsa_key); - GNUNET_CRYPTO_key_get_public (&privkey, - &pubkey); - - removed = GNUNET_NO; - - rd.expiration_time = GNUNET_TIME_absolute_get ().abs_value_us; - rd.record_type = TEST_RECORD_TYPE; - rd.data_size = TEST_RECORD_DATALEN; - rd.data = GNUNET_malloc (TEST_RECORD_DATALEN); - rd.flags = 0; - memset ((char *) rd.data, - 'a', - TEST_RECORD_DATALEN); - nsqe = GNUNET_NAMESTORE_records_store (nsh, - &privkey, - name, - 1, - &rd, - &put_cont, - (void *) name); - GNUNET_assert (NULL != nsqe); - GNUNET_free_nz ((void *) rd.data); -} - -static void -run (void *cls, - const struct GNUNET_CONFIGURATION_Handle *cfg, - struct GNUNET_TESTING_Peer *peer) -{ - const char *name = "dummy"; - - endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, - &endbadly, - NULL); - nsh = GNUNET_NAMESTORE_connect (cfg); - GNUNET_break (NULL != nsh); - nsqe = GNUNET_NAMESTORE_transaction_begin (nsh, begin_cont, (void *) name); - /*nsqe = GNUNET_NAMESTORE_transaction_commit (nsh, commit_cont); - nsqe = GNUNET_NAMESTORE_transaction_rollback (nsh, rollback_cont); Must also happen on disconnect - nsqe = GNUNET_NAMESTORE_records_edit (nsh, - &privkey, - name, - 1, - &rd, - &edit_cont, - (void *) name); - nsqe = GNUNET_NAMESTORE_records_insert_bulk (nsh, - count, - &rd, - & - nsqe = GNUNET_NAMESTORE_records_store (nsh, - &privkey, - name, - 1, - &rd, - &put_cont, - (void *) name);*/ - GNUNET_assert (NULL != nsqe); -} - - -#include "test_common.c" - - -int -main (int argc, char *argv[]) -{ - const char *plugin_name; - char *cfg_name; - - SETUP_CFG (plugin_name, cfg_name); - res = 1; - if (0 != - GNUNET_TESTING_peer_run ("test-namestore-api-remove", - cfg_name, - &run, - NULL)) - { - res = 1; - } - GNUNET_DISK_purge_cfg_dir (cfg_name, - "GNUNET_TEST_HOME"); - GNUNET_free (plugin_name); - GNUNET_free (cfg_name); - return res; -} - - -/* end of test_namestore_api_remove.c */ diff --git a/src/plugin/namestore/test_namestore_api_zone_iteration.c b/src/plugin/namestore/test_namestore_api_zone_iteration.c @@ -1,464 +0,0 @@ -/* - This file is part of GNUnet. - Copyright (C) 2013, 2018 GNUnet e.V. - - GNUnet is free software: you can redistribute it and/or modify it - under the terms of the GNU Affero General Public License as published - by the Free Software Foundation, either version 3 of the License, - or (at your option) any later version. - - GNUnet is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - - SPDX-License-Identifier: AGPL3.0-or-later - */ -/** - * @file namestore/test_namestore_api_zone_iteration.c - * @brief testcase for zone iteration functionality: iterate all zones - */ -#include "platform.h" -#include "gnunet_namestore_service.h" -#include "gnunet_testing_lib.h" -#include "namestore.h" - -#define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT - - -#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100) - - -static struct GNUNET_NAMESTORE_Handle *nsh; - -static struct GNUNET_SCHEDULER_Task *endbadly_task; - -static struct GNUNET_CRYPTO_PrivateKey privkey; - -static struct GNUNET_CRYPTO_PrivateKey privkey2; - -static struct GNUNET_NAMESTORE_ZoneIterator *zi; - -static int res; - -static int returned_records; - -static char *s_name_1; - -static struct GNUNET_GNSRECORD_Data *s_rd_1; - -static char *s_name_2; - -static struct GNUNET_GNSRECORD_Data *s_rd_2; - -static char *s_name_3; - -static struct GNUNET_GNSRECORD_Data *s_rd_3; - - -/** - * Re-establish the connection to the service. - * - * @param cls handle to use to re-connect. - * @param tc scheduler context - */ -static void -endbadly (void *cls) -{ - endbadly_task = NULL; - GNUNET_SCHEDULER_shutdown (); - res = 1; -} - - -static void -end (void *cls) -{ - if (NULL != zi) - { - GNUNET_NAMESTORE_zone_iteration_stop (zi); - zi = NULL; - } - if (NULL != endbadly_task) - { - GNUNET_SCHEDULER_cancel (endbadly_task); - endbadly_task = NULL; - } - GNUNET_free (s_name_1); - GNUNET_free (s_name_2); - GNUNET_free (s_name_3); - if (NULL != s_rd_1) - { - GNUNET_free_nz ((void *) s_rd_1->data); - GNUNET_free (s_rd_1); - } - if (NULL != s_rd_2) - { - GNUNET_free_nz ((void *) s_rd_2->data); - GNUNET_free (s_rd_2); - } - if (NULL != s_rd_3) - { - GNUNET_free_nz ((void *) s_rd_3->data); - GNUNET_free (s_rd_3); - } - if (NULL != nsh) - { - GNUNET_NAMESTORE_disconnect (nsh); - nsh = NULL; - } -} - - -static void -zone_end (void *cls) -{ - GNUNET_break (3 == returned_records); - if (3 == returned_records) - { - res = 0; /* Last iteraterator callback, we are done */ - zi = NULL; - } - else - res = 1; - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received last result, iteration done after receing %u results\n", - returned_records); - GNUNET_SCHEDULER_shutdown (); -} - - -static void -fail_cb (void *cls) -{ - GNUNET_assert (0); -} - - -static void -zone_proc (void *cls, - const struct GNUNET_CRYPTO_PrivateKey *zone, - const char *label, - unsigned int rd_count, - const struct GNUNET_GNSRECORD_Data *rd) -{ - int failed = GNUNET_NO; - - GNUNET_assert (NULL != zone); - if (0 == GNUNET_memcmp (zone, - &privkey)) - { - if (0 == strcmp (label, s_name_1)) - { - if (rd_count == 1) - { - if (GNUNET_YES != GNUNET_GNSRECORD_records_cmp (rd, s_rd_1)) - { - failed = GNUNET_YES; - GNUNET_break (0); - } - } - else - { - failed = GNUNET_YES; - GNUNET_break (0); - } - } - else if (0 == strcmp (label, s_name_2)) - { - if (rd_count == 1) - { - if (GNUNET_YES != GNUNET_GNSRECORD_records_cmp (rd, s_rd_2)) - { - failed = GNUNET_YES; - GNUNET_break (0); - } - } - else - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Received invalid record count\n"); - failed = GNUNET_YES; - GNUNET_break (0); - } - } - else - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Comparing result failed: got name `%s' for first zone\n", - label); - failed = GNUNET_YES; - GNUNET_break (0); - } - } - else if (0 == GNUNET_memcmp (zone, - &privkey2)) - { - if (0 == strcmp (label, s_name_3)) - { - if (rd_count == 1) - { - if (GNUNET_YES != GNUNET_GNSRECORD_records_cmp (rd, s_rd_3)) - { - failed = GNUNET_YES; - GNUNET_break (0); - } - } - else - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Received invalid record count\n"); - failed = GNUNET_YES; - GNUNET_break (0); - } - } - else - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Comparing result failed: got name `%s' for first zone\n", - label); - failed = GNUNET_YES; - GNUNET_break (0); - } - } - else - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Received invalid zone\n"); - failed = GNUNET_YES; - GNUNET_break (0); - } - - if (failed == GNUNET_NO) - { - returned_records++; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Telling namestore to send the next result\n"); - GNUNET_NAMESTORE_zone_iterator_next (zi, - 1); - } - else - { - GNUNET_break (0); - GNUNET_SCHEDULER_shutdown (); - res = 1; - } -} - - -static void -put_cont (void *cls, - enum GNUNET_ErrorCode ec) -{ - static int c = 0; - - if (GNUNET_EC_NONE == ec) - { - c++; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Created record %u \n", - c); - } - else - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Failed to created records: `%s'\n", - GNUNET_ErrorCode_get_hint (ec)); - GNUNET_break (0); - GNUNET_SCHEDULER_shutdown (); - res = 1; - return; - } - - if (c == 3) - { - res = 1; - returned_records = 0; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "All records created, starting iteration over all zones \n"); - zi = GNUNET_NAMESTORE_zone_iteration_start (nsh, - NULL, - &fail_cb, - NULL, - &zone_proc, - NULL, - &zone_end, - NULL); - if (zi == NULL) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Failed to create zone iterator\n"); - GNUNET_break (0); - GNUNET_SCHEDULER_shutdown (); - res = 1; - return; - } - } -} - - -static struct GNUNET_GNSRECORD_Data * -create_record (unsigned int count) -{ - struct GNUNET_GNSRECORD_Data *rd; - - rd = GNUNET_new_array (count, - struct GNUNET_GNSRECORD_Data); - for (unsigned int c = 0; c < count; c++) - { - rd[c].expiration_time = GNUNET_TIME_relative_to_absolute ( - GNUNET_TIME_UNIT_HOURS).abs_value_us; - rd[c].record_type = TEST_RECORD_TYPE; - rd[c].data_size = 50; - rd[c].data = GNUNET_malloc (50); - rd[c].flags = 0; - memset ((char *) rd[c].data, 'a', 50); - } - return rd; -} - - -/** - * Callback called from the zone iterator when we iterate over - * the empty zone. Check that we got no records and then - * start the actual tests by filling the zone. - */ -static void -empty_zone_proc (void *cls, - const struct GNUNET_CRYPTO_PrivateKey *zone, - const char *label, - unsigned int rd_count, - const struct GNUNET_GNSRECORD_Data *rd) -{ - GNUNET_assert (nsh == cls); - if (NULL != zone) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _ ("Expected empty zone but received zone private key\n")); - GNUNET_break (0); - GNUNET_SCHEDULER_shutdown (); - res = 1; - return; - } - if ((NULL != label) || (NULL != rd) || (0 != rd_count)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _ ("Expected no zone content but received data\n")); - GNUNET_break (0); - GNUNET_SCHEDULER_shutdown (); - res = 1; - return; - } - GNUNET_assert (0); -} - - -static void -empty_zone_end (void *cls) -{ - zi = NULL; - privkey.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); - privkey2.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); - GNUNET_CRYPTO_ecdsa_key_create (&privkey.ecdsa_key); - GNUNET_CRYPTO_ecdsa_key_create (&privkey2.ecdsa_key); - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 1\n"); - - GNUNET_asprintf (&s_name_1, "dummy1"); - s_rd_1 = create_record (1); - GNUNET_NAMESTORE_records_store (nsh, - &privkey, - s_name_1, - 1, s_rd_1, - &put_cont, - NULL); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Created record 2 \n"); - GNUNET_asprintf (&s_name_2, "dummy2"); - s_rd_2 = create_record (1); - GNUNET_NAMESTORE_records_store (nsh, - &privkey, - s_name_2, - 1, s_rd_2, - &put_cont, - NULL); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Created record 3\n"); - /* name in different zone */ - GNUNET_asprintf (&s_name_3, "dummy3"); - s_rd_3 = create_record (1); - GNUNET_NAMESTORE_records_store (nsh, - &privkey2, - s_name_3, - 1, - s_rd_3, - &put_cont, - NULL); -} - - -static void -run (void *cls, - const struct GNUNET_CONFIGURATION_Handle *cfg, - struct GNUNET_TESTING_Peer *peer) -{ - endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, - &endbadly, - NULL); - GNUNET_SCHEDULER_add_shutdown (&end, - NULL); - - nsh = GNUNET_NAMESTORE_connect (cfg); - GNUNET_break (NULL != nsh); - /* first, iterate over empty namestore */ - zi = GNUNET_NAMESTORE_zone_iteration_start (nsh, - NULL, - &fail_cb, - NULL, - &empty_zone_proc, - nsh, - &empty_zone_end, - NULL); - if (NULL == zi) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Failed to create zone iterator\n"); - GNUNET_break (0); - res = 1; - GNUNET_SCHEDULER_shutdown (); - } -} - - -#include "test_common.c" - - -int -main (int argc, char *argv[]) -{ - const char *plugin_name; - char *cfg_name; - - SETUP_CFG (plugin_name, cfg_name); - res = 1; - if (0 != - GNUNET_TESTING_peer_run ("test-namestore-api-zone-iteration", - cfg_name, - &run, - NULL)) - { - res = 1; - } - GNUNET_DISK_purge_cfg_dir (cfg_name, - "GNUNET_TEST_HOME"); - GNUNET_free (plugin_name); - GNUNET_free (cfg_name); - return res; -} - - -/* end of test_namestore_api_zone_iteration.c */ diff --git a/src/plugin/namestore/test_namestore_api_zone_iteration_nick.c b/src/plugin/namestore/test_namestore_api_zone_iteration_nick.c @@ -1,460 +0,0 @@ -/* - This file is part of GNUnet. - Copyright (C) 2013 GNUnet e.V. - - GNUnet is free software: you can redistribute it and/or modify it - under the terms of the GNU Affero General Public License as published - by the Free Software Foundation, either version 3 of the License, - or (at your option) any later version. - - GNUnet is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - - SPDX-License-Identifier: AGPL3.0-or-later - */ -/** - * @file namestore/test_namestore_api_zone_iteration.c - * @brief testcase for zone iteration functionality: iterate all zones - */ -#include "platform.h" -#include "gnunet_namestore_service.h" -#include "gnunet_gns_service.h" -#include "gnunet_testing_lib.h" -#include "namestore.h" - -#define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT - -#define ZONE_NICK_1 "nick1" -#define ZONE_NICK_2 "nick2" - -#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100) - - -static struct GNUNET_NAMESTORE_Handle *nsh; - -static struct GNUNET_CRYPTO_PrivateKey privkey; - -static struct GNUNET_CRYPTO_PrivateKey privkey2; - -static struct GNUNET_NAMESTORE_ZoneIterator *zi; - -static int res; - -static int returned_records; - -static char *s_name_1; - -static struct GNUNET_GNSRECORD_Data *s_rd_1; - -static char *s_name_2; - -static struct GNUNET_GNSRECORD_Data *s_rd_2; - -static char *s_name_3; - -static struct GNUNET_GNSRECORD_Data *s_rd_3; - -static struct GNUNET_NAMESTORE_QueueEntry *nsqe; - - -/** - * Re-establish the connection to the service. - * - * @param cls handle to use to re-connect. - * @param tc scheduler context - */ -static void -end (void *cls) -{ - if (NULL != zi) - { - GNUNET_NAMESTORE_zone_iteration_stop (zi); - zi = NULL; - } - if (nsh != NULL) - { - GNUNET_NAMESTORE_disconnect (nsh); - nsh = NULL; - } - GNUNET_free (s_name_1); - GNUNET_free (s_name_2); - GNUNET_free (s_name_3); - - if (s_rd_1 != NULL) - { - GNUNET_free_nz ((void *) s_rd_1->data); - GNUNET_free (s_rd_1); - } - if (s_rd_2 != NULL) - { - GNUNET_free_nz ((void *) s_rd_2->data); - GNUNET_free (s_rd_2); - } - if (s_rd_3 != NULL) - { - GNUNET_free_nz ((void *) s_rd_3->data); - GNUNET_free (s_rd_3); - } -} - - -static int -check_zone_1 (const char *label, unsigned int rd_count, - const struct GNUNET_GNSRECORD_Data *rd) -{ - for (unsigned int c = 0; c < rd_count; c++) - { - if ((rd[c].record_type == GNUNET_GNSRECORD_TYPE_NICK) && - (0 != strcmp (rd[c].data, ZONE_NICK_1))) - { - GNUNET_break (0); - return GNUNET_YES; - } - } - return GNUNET_NO; -} - - -static int -check_zone_2 (const char *label, - unsigned int rd_count, - const struct GNUNET_GNSRECORD_Data *rd) -{ - for (unsigned int c = 0; c < rd_count; c++) - { - if ((rd[c].record_type == GNUNET_GNSRECORD_TYPE_NICK) && - (0 != strcmp (rd[c].data, ZONE_NICK_2))) - { - GNUNET_break (0); - return GNUNET_YES; - } - } - return GNUNET_NO; -} - - -static void -zone_proc_end (void *cls) -{ - zi = NULL; - res = 0; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received last result, iteration done after receing %u results\n", - returned_records); - GNUNET_SCHEDULER_shutdown (); -} - - -static void -zone_proc (void *cls, - const struct GNUNET_CRYPTO_PrivateKey *zone, - const char *label, - unsigned int rd_count, - const struct GNUNET_GNSRECORD_Data *rd) -{ - int failed = GNUNET_NO; - - GNUNET_assert (NULL != zone); - if (0 == GNUNET_memcmp (zone, &privkey)) - { - failed = check_zone_1 (label, rd_count, rd); - if (GNUNET_YES == failed) - GNUNET_break (0); - } - else if (0 == GNUNET_memcmp (zone, &privkey2)) - { - failed = check_zone_2 (label, rd_count, rd); - if (GNUNET_YES == failed) - GNUNET_break (0); - } - else - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Received invalid zone\n"); - failed = GNUNET_YES; - GNUNET_break (0); - } - - if (failed == GNUNET_NO) - { - returned_records++; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Telling namestore to send the next result\n"); - GNUNET_NAMESTORE_zone_iterator_next (zi, - 1); - } - else - { - GNUNET_break (0); - res = 1; - GNUNET_SCHEDULER_shutdown (); - } -} - - -static void -fail_cb (void *cls) -{ - GNUNET_assert (0); -} - - -static void -put_cont (void *cls, - enum GNUNET_ErrorCode ec) -{ - static int c = 0; - - if (GNUNET_EC_NONE == ec) - { - c++; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record %u \n", c); - } - else - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to created records: `%s'\n", - GNUNET_ErrorCode_get_hint (ec)); - GNUNET_break (0); - GNUNET_SCHEDULER_shutdown (); - return; - } - - if (c == 3) - { - res = 1; - returned_records = 0; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "All records created, starting iteration over all zones \n"); - zi = GNUNET_NAMESTORE_zone_iteration_start (nsh, - NULL, - &fail_cb, - NULL, - &zone_proc, - NULL, - &zone_proc_end, - NULL); - if (zi == NULL) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create zone iterator\n"); - GNUNET_break (0); - GNUNET_SCHEDULER_shutdown (); - return; - } - } -} - - -static struct GNUNET_GNSRECORD_Data * -create_record (unsigned int count) -{ - struct GNUNET_GNSRECORD_Data *rd; - - rd = GNUNET_new_array (count, - struct GNUNET_GNSRECORD_Data); - for (unsigned int c = 0; c < count; c++) - { - rd[c].expiration_time = GNUNET_TIME_relative_to_absolute ( - GNUNET_TIME_UNIT_HOURS).abs_value_us; - rd[c].record_type = TEST_RECORD_TYPE; - rd[c].data_size = 50; - rd[c].data = GNUNET_malloc (50); - rd[c].flags = 0; - memset ((char *) rd[c].data, 'a', 50); - } - return rd; -} - - -static void -nick_2_cont (void *cls, - enum GNUNET_ErrorCode ec) -{ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Nick added : %s\n", - (GNUNET_EC_NONE == ec) ? "SUCCESS" : "FAIL"); - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 1\n"); - - GNUNET_asprintf (&s_name_1, "dummy1"); - s_rd_1 = create_record (1); - GNUNET_NAMESTORE_records_store (nsh, &privkey, s_name_1, - 1, s_rd_1, - &put_cont, NULL); - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Created record 2 \n"); - GNUNET_asprintf (&s_name_2, "dummy2"); - s_rd_2 = create_record (1); - GNUNET_NAMESTORE_records_store (nsh, &privkey, s_name_2, - 1, s_rd_2, &put_cont, NULL); - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Created record 3\n"); - - /* name in different zone */ - GNUNET_asprintf (&s_name_3, "dummy3"); - s_rd_3 = create_record (1); - GNUNET_NAMESTORE_records_store (nsh, &privkey2, s_name_3, - 1, s_rd_3, - &put_cont, NULL); -} - - -static void -nick_1_cont (void *cls, enum GNUNET_ErrorCode ec) -{ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Nick 1 added : %s\n", - (GNUNET_EC_NONE == ec) ? "SUCCESS" : "FAIL"); - struct GNUNET_GNSRECORD_Data rd; - - memset (&rd, 0, sizeof(rd)); - rd.data = ZONE_NICK_2; - rd.data_size = strlen (ZONE_NICK_2) + 1; - rd.record_type = GNUNET_GNSRECORD_TYPE_NICK; - rd.expiration_time = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us; - rd.flags |= GNUNET_GNSRECORD_RF_PRIVATE; - nsqe = GNUNET_NAMESTORE_records_store (nsh, - &privkey2, - GNUNET_GNS_EMPTY_LABEL_AT, - 1, - &rd, - &nick_2_cont, - &privkey2); - - if (NULL == nsqe) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _ ("Namestore cannot store no block\n")); - } -} - - -/** - * Callback called from the zone iterator when we iterate over - * the empty zone. Check that we got no records and then - * start the actual tests by filling the zone. - */ -static void -empty_zone_proc (void *cls, - const struct GNUNET_CRYPTO_PrivateKey *zone, - const char *label, - unsigned int rd_count, - const struct GNUNET_GNSRECORD_Data *rd) -{ - GNUNET_assert (nsh == cls); - - if (NULL != zone) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _ ("Expected empty zone but received zone private key\n")); - GNUNET_break (0); - GNUNET_SCHEDULER_shutdown (); - return; - } - if ((NULL != label) || (NULL != rd) || (0 != rd_count)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _ ("Expected no zone content but received data\n")); - GNUNET_break (0); - GNUNET_SCHEDULER_shutdown (); - return; - } - GNUNET_assert (0); -} - - -static void -empty_zone_end (void *cls) -{ - GNUNET_assert (nsh == cls); - struct GNUNET_GNSRECORD_Data rd; - - zi = NULL; - privkey.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); - privkey2.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); - GNUNET_CRYPTO_ecdsa_key_create (&privkey.ecdsa_key); - GNUNET_CRYPTO_ecdsa_key_create (&privkey2.ecdsa_key); - - memset (&rd, 0, sizeof(rd)); - rd.data = ZONE_NICK_1; - rd.data_size = strlen (ZONE_NICK_1) + 1; - rd.record_type = GNUNET_GNSRECORD_TYPE_NICK; - rd.expiration_time = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us; - rd.flags |= GNUNET_GNSRECORD_RF_PRIVATE; - nsqe = GNUNET_NAMESTORE_records_store (nsh, - &privkey, - GNUNET_GNS_EMPTY_LABEL_AT, - 1, - &rd, - &nick_1_cont, - NULL); - if (NULL == nsqe) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _ ("Namestore cannot store no block\n")); - } -} - - -static void -run (void *cls, - const struct GNUNET_CONFIGURATION_Handle *cfg, - struct GNUNET_TESTING_Peer *peer) -{ - nsh = GNUNET_NAMESTORE_connect (cfg); - GNUNET_break (NULL != nsh); - GNUNET_SCHEDULER_add_shutdown (&end, - NULL); - /* first, iterate over empty namestore */ - zi = GNUNET_NAMESTORE_zone_iteration_start (nsh, - NULL, - &fail_cb, - NULL, - &empty_zone_proc, - nsh, - &empty_zone_end, - nsh); - if (NULL == zi) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Failed to create zone iterator\n"); - GNUNET_break (0); - GNUNET_SCHEDULER_shutdown (); - } -} - - -#include "test_common.c" - - -int -main (int argc, char *argv[]) -{ - const char *plugin_name; - char *cfg_name; - - SETUP_CFG (plugin_name, cfg_name); - res = 1; - if (0 != - GNUNET_TESTING_peer_run ("test-namestore-api-zone-iteration-nick", - cfg_name, - &run, - NULL)) - { - res = 1; - } - GNUNET_DISK_purge_cfg_dir (cfg_name, - "GNUNET_TEST_HOME"); - GNUNET_free (plugin_name); - GNUNET_free (cfg_name); - return res; -} - - -/* end of test_namestore_api_zone_iteration.c */ diff --git a/src/plugin/namestore/test_namestore_api_zone_iteration_specific_zone.c b/src/plugin/namestore/test_namestore_api_zone_iteration_specific_zone.c @@ -1,447 +0,0 @@ -/* - This file is part of GNUnet. - Copyright (C) 2013 GNUnet e.V. - - GNUnet is free software: you can redistribute it and/or modify it - under the terms of the GNU Affero General Public License as published - by the Free Software Foundation, either version 3 of the License, - or (at your option) any later version. - - GNUnet is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - - SPDX-License-Identifier: AGPL3.0-or-later - */ -/** - * @file namestore/test_namestore_api_zone_iteration_specific_zone.c - * @brief testcase for zone iteration functionality: iterate over a specific zone - * @author Matthias Wachs - */ -#include "platform.h" -#include "gnunet_namestore_service.h" -#include "gnunet_testing_lib.h" -#include "namestore.h" - -#define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT - - -#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100) - - -static struct GNUNET_NAMESTORE_Handle *nsh; - -static struct GNUNET_SCHEDULER_Task *endbadly_task; - -static struct GNUNET_CRYPTO_PrivateKey privkey; - -static struct GNUNET_CRYPTO_PrivateKey privkey2; - -static struct GNUNET_NAMESTORE_ZoneIterator *zi; - -static int res; - -static int returned_records; - -static char *s_name_1; - -static struct GNUNET_GNSRECORD_Data *s_rd_1; - -static char *s_name_2; - -static struct GNUNET_GNSRECORD_Data *s_rd_2; - -static char *s_name_3; - -static struct GNUNET_GNSRECORD_Data *s_rd_3; - - -/** - * Handle timeout. - * - * @param cls handle to use to re-connect. - */ -static void -endbadly (void *cls) -{ - endbadly_task = NULL; - GNUNET_SCHEDULER_shutdown (); - res = 1; -} - - -static void -end (void *cls) -{ - if (NULL != zi) - { - GNUNET_NAMESTORE_zone_iteration_stop (zi); - zi = NULL; - } - if (NULL != endbadly_task) - { - GNUNET_SCHEDULER_cancel (endbadly_task); - endbadly_task = NULL; - } - GNUNET_free (s_name_1); - GNUNET_free (s_name_2); - GNUNET_free (s_name_3); - if (s_rd_1 != NULL) - { - GNUNET_free_nz ((void *) s_rd_1->data); - GNUNET_free (s_rd_1); - } - if (s_rd_2 != NULL) - { - GNUNET_free_nz ((void *) s_rd_2->data); - GNUNET_free (s_rd_2); - } - if (s_rd_3 != NULL) - { - GNUNET_free_nz ((void *) s_rd_3->data); - GNUNET_free (s_rd_3); - } - if (nsh != NULL) - { - GNUNET_NAMESTORE_disconnect (nsh); - nsh = NULL; - } -} - - -static void -fail_cb (void *cls) -{ - GNUNET_assert (0); - zi = NULL; -} - - -static void -zone_proc (void *cls, - const struct GNUNET_CRYPTO_PrivateKey *zone, - const char *label, - unsigned int rd_count, - const struct GNUNET_GNSRECORD_Data *rd) -{ - int failed = GNUNET_NO; - - GNUNET_assert (NULL != zone); - if (0 == GNUNET_memcmp (zone, - &privkey)) - { - if (0 == strcmp (label, s_name_1)) - { - if (rd_count == 1) - { - if (GNUNET_YES != GNUNET_GNSRECORD_records_cmp (rd, s_rd_1)) - { - failed = GNUNET_YES; - GNUNET_break (0); - } - } - else - { - failed = GNUNET_YES; - GNUNET_break (0); - } - } - else if (0 == strcmp (label, s_name_2)) - { - if (rd_count == 1) - { - if (GNUNET_YES != GNUNET_GNSRECORD_records_cmp (rd, s_rd_2)) - { - failed = GNUNET_YES; - GNUNET_break (0); - } - } - else - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Received invalid record count\n"); - failed = GNUNET_YES; - GNUNET_break (0); - } - } - else - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Comparing result failed: got name `%s' for first zone\n", - label); - failed = GNUNET_YES; - GNUNET_break (0); - } - } - else if (0 == GNUNET_memcmp (zone, &privkey2)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Received data for not requested zone\n"); - failed = GNUNET_YES; - GNUNET_break (0); - } - else - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Received invalid zone\n"); - failed = GNUNET_YES; - GNUNET_break (0); - } - if (failed == GNUNET_NO) - { - returned_records++; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Telling namestore to send the next result\n"); - GNUNET_NAMESTORE_zone_iterator_next (zi, - 1); - } - else - { - GNUNET_break (0); - res = 2; - GNUNET_SCHEDULER_shutdown (); - } -} - - -static void -zone_proc_end (void *cls) -{ - zi = NULL; - GNUNET_break (2 == returned_records); - if (2 == returned_records) - { - res = 0; /* Last iteraterator callback, we are done */ - } - else - { - res = 1; - } - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received last result, iteration done after receing %u results\n", - returned_records); - GNUNET_SCHEDULER_shutdown (); -} - - -static void -put_cont (void *cls, - enum GNUNET_ErrorCode ec) -{ - static int c = 0; - - if (GNUNET_EC_NONE == ec) - { - c++; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Created record %u \n", c); - } - else - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Failed to created records: `%s'\n", - GNUNET_ErrorCode_get_hint (ec)); - GNUNET_break (0); - res = 2; - GNUNET_SCHEDULER_shutdown (); - return; - } - - if (c == 3) - { - res = 1; - returned_records = 0; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "All records created, starting iteration over all zones \n"); - zi = GNUNET_NAMESTORE_zone_iteration_start (nsh, - &privkey, - &fail_cb, - NULL, - &zone_proc, - NULL, - &zone_proc_end, - NULL); - if (zi == NULL) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Failed to create zone iterator\n"); - GNUNET_break (0); - res = 2; - GNUNET_SCHEDULER_shutdown (); - return; - } - } -} - - -static struct GNUNET_GNSRECORD_Data * -create_record (unsigned int count) -{ - struct GNUNET_GNSRECORD_Data *rd; - - rd = GNUNET_new_array (count, - struct GNUNET_GNSRECORD_Data); - for (unsigned int c = 0; c < count; c++) - { - rd[c].expiration_time = GNUNET_TIME_relative_to_absolute ( - GNUNET_TIME_UNIT_HOURS).abs_value_us; - rd[c].record_type = TEST_RECORD_TYPE; - rd[c].data_size = 50; - rd[c].data = GNUNET_malloc (50); - rd[c].flags = 0; - memset ((char *) rd[c].data, 'a', 50); - } - return rd; -} - - -/** - * Callback called from the zone iterator when we iterate over - * the empty zone. Check that we got no records and then - * start the actual tests by filling the zone. - */ -static void -empty_zone_proc (void *cls, - const struct GNUNET_CRYPTO_PrivateKey *zone, - const char *label, - unsigned int rd_count, - const struct GNUNET_GNSRECORD_Data *rd) -{ - GNUNET_assert (nsh == cls); - if (NULL != zone) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _ ("Expected empty zone but received zone private key\n")); - GNUNET_break (0); - res = 2; - GNUNET_SCHEDULER_shutdown (); - return; - } - if ((NULL != label) || (NULL != rd) || (0 != rd_count)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _ ("Expected no zone content but received data\n")); - GNUNET_break (0); - res = 2; - GNUNET_SCHEDULER_shutdown (); - return; - } - GNUNET_assert (0); -} - - -static void -empty_zone_proc_end (void *cls) -{ - zi = NULL; - privkey.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); - privkey2.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); - GNUNET_CRYPTO_ecdsa_key_create (&privkey.ecdsa_key); - GNUNET_CRYPTO_ecdsa_key_create (&privkey2.ecdsa_key); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Created record 1\n"); - GNUNET_asprintf (&s_name_1, - "dummy1"); - s_rd_1 = create_record (1); - GNUNET_NAMESTORE_records_store (nsh, - &privkey, - s_name_1, - 1, - s_rd_1, - &put_cont, - NULL); - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Created record 2 \n"); - GNUNET_asprintf (&s_name_2, - "dummy2"); - s_rd_2 = create_record (1); - GNUNET_NAMESTORE_records_store (nsh, - &privkey, - s_name_2, - 1, - s_rd_2, - &put_cont, - NULL); - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Created record 3\n"); - - /* name in different zone */ - GNUNET_asprintf (&s_name_3, - "dummy3"); - s_rd_3 = create_record (1); - GNUNET_NAMESTORE_records_store (nsh, - &privkey2, - s_name_3, - 1, s_rd_3, - &put_cont, - NULL); -} - - -static void -run (void *cls, - const struct GNUNET_CONFIGURATION_Handle *cfg, - struct GNUNET_TESTING_Peer *peer) -{ - GNUNET_SCHEDULER_add_shutdown (&end, - NULL); - endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, - &endbadly, - NULL); - nsh = GNUNET_NAMESTORE_connect (cfg); - GNUNET_break (NULL != nsh); - /* first, iterate over empty namestore */ - zi = GNUNET_NAMESTORE_zone_iteration_start (nsh, - NULL, - &fail_cb, - NULL, - &empty_zone_proc, - nsh, - &empty_zone_proc_end, - nsh); - if (NULL == zi) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Failed to create zone iterator\n"); - GNUNET_break (0); - GNUNET_SCHEDULER_shutdown (); - } -} - - -#include "test_common.c" - - -int -main (int argc, char *argv[]) -{ - const char *plugin_name; - char *cfg_name; - - SETUP_CFG (plugin_name, cfg_name); - res = 1; - if (0 != - GNUNET_TESTING_peer_run ( - "test-namestore-api-zone-iteration-specific-zone", - cfg_name, - &run, - NULL)) - { - res = 1; - } - GNUNET_DISK_purge_cfg_dir (cfg_name, - "GNUNET_TEST_HOME"); - GNUNET_free (plugin_name); - GNUNET_free (cfg_name); - return res; -} - - -/* end of test_namestore_api_zone_iteration_specific_zone.c */ diff --git a/src/plugin/namestore/test_namestore_api_zone_iteration_stop.c b/src/plugin/namestore/test_namestore_api_zone_iteration_stop.c @@ -1,449 +0,0 @@ -/* - This file is part of GNUnet. - Copyright (C) 2009 GNUnet e.V. - - GNUnet is free software: you can redistribute it and/or modify it - under the terms of the GNU Affero General Public License as published - by the Free Software Foundation, either version 3 of the License, - or (at your option) any later version. - - GNUnet is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - - SPDX-License-Identifier: AGPL3.0-or-later - */ -/** - * @file namestore/test_namestore_api_zone_iteration_stop.c - * @brief testcase for zone iteration functionality: stop iterating of zones - */ -#include "platform.h" -#include "gnunet_namestore_service.h" -#include "gnunet_testing_lib.h" -#include "namestore.h" - -#define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT - -#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100) -#define WAIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2) - -static struct GNUNET_NAMESTORE_Handle *nsh; - -static struct GNUNET_CRYPTO_PrivateKey privkey; - -static struct GNUNET_CRYPTO_PrivateKey privkey2; - -static struct GNUNET_NAMESTORE_ZoneIterator *zi; - -static int res; - -static int returned_records; - -static char *s_name_1; - -static struct GNUNET_GNSRECORD_Data *s_rd_1; - -static char *s_name_2; - -static struct GNUNET_GNSRECORD_Data *s_rd_2; - -static char *s_name_3; - -static struct GNUNET_GNSRECORD_Data *s_rd_3; - - -/** - * Re-establish the connection to the service. - * - * @param cls handle to use to re-connect. - */ -static void -end (void *cls) -{ - if (NULL != zi) - { - GNUNET_NAMESTORE_zone_iteration_stop (zi); - zi = NULL; - } - if (nsh != NULL) - { - GNUNET_NAMESTORE_disconnect (nsh); - nsh = NULL; - } - GNUNET_free (s_name_1); - GNUNET_free (s_name_2); - GNUNET_free (s_name_3); - if (s_rd_1 != NULL) - { - GNUNET_free_nz ((void *) s_rd_1->data); - GNUNET_free (s_rd_1); - } - if (s_rd_2 != NULL) - { - GNUNET_free_nz ((void *) s_rd_2->data); - GNUNET_free (s_rd_2); - } - if (s_rd_3 != NULL) - { - GNUNET_free_nz ((void *) s_rd_3->data); - GNUNET_free (s_rd_3); - } -} - - -static void -delayed_end (void *cls) -{ - GNUNET_SCHEDULER_shutdown (); -} - - -static void -fail_cb (void *cls) -{ - GNUNET_assert (0); -} - - -static void -zone_proc (void *cls, - const struct GNUNET_CRYPTO_PrivateKey *zone, - const char *label, - unsigned int rd_count, - const struct GNUNET_GNSRECORD_Data *rd) -{ - int failed = GNUNET_NO; - - GNUNET_assert (NULL != zone); - if (0 == GNUNET_memcmp (zone, &privkey)) - { - if (0 == strcmp (label, s_name_1)) - { - if (rd_count == 1) - { - if (GNUNET_YES != GNUNET_GNSRECORD_records_cmp (rd, s_rd_1)) - { - failed = GNUNET_YES; - GNUNET_break (0); - } - } - else - { - failed = GNUNET_YES; - GNUNET_break (0); - } - } - else if (0 == strcmp (label, s_name_2)) - { - if (rd_count == 1) - { - if (GNUNET_YES != GNUNET_GNSRECORD_records_cmp (rd, s_rd_2)) - { - failed = GNUNET_YES; - GNUNET_break (0); - } - } - else - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Received invalid record count\n"); - failed = GNUNET_YES; - GNUNET_break (0); - } - } - else - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Comparing result failed: got name `%s' for first zone\n", - label); - failed = GNUNET_YES; - GNUNET_break (0); - } - } - else if (0 == GNUNET_memcmp (zone, &privkey2)) - { - if (0 == strcmp (label, s_name_3)) - { - if (rd_count == 1) - { - if (GNUNET_YES != GNUNET_GNSRECORD_records_cmp (rd, s_rd_3)) - { - failed = GNUNET_YES; - GNUNET_break (0); - } - } - else - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Received invalid record count\n"); - failed = GNUNET_YES; - GNUNET_break (0); - } - } - else - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Comparing result failed: got name `%s' for first zone\n", - label); - failed = GNUNET_YES; - GNUNET_break (0); - } - } - else - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Received invalid zone\n"); - failed = GNUNET_YES; - GNUNET_break (0); - } - if (failed == GNUNET_NO) - { - if (1 == returned_records) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Telling namestore to stop zone iteration\n"); - GNUNET_NAMESTORE_zone_iteration_stop (zi); - zi = NULL; - res = 0; - GNUNET_SCHEDULER_add_delayed (WAIT, - &delayed_end, - NULL); - return; - } - returned_records++; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Telling namestore to send the next result\n"); - GNUNET_NAMESTORE_zone_iterator_next (zi, - 1); - } - else - { - GNUNET_break (0); - GNUNET_SCHEDULER_shutdown (); - } -} - - -static void -zone_proc_end (void *cls) -{ - GNUNET_break (1 <= returned_records); - if (1 >= returned_records) - res = 1; /* Last iteraterator callback, we are done */ - else - res = 0; - zi = NULL; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received last result, iteration done after receing %u results\n", - returned_records); - GNUNET_SCHEDULER_add_now (&end, NULL); -} - - -static void -put_cont (void *cls, enum GNUNET_ErrorCode ec) -{ - static int c = 0; - - if (GNUNET_EC_NONE == ec) - { - c++; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record %u \n", c); - } - else - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to created records: `%s'\n", - GNUNET_ErrorCode_get_hint (ec)); - GNUNET_break (0); - GNUNET_SCHEDULER_shutdown (); - return; - } - - if (c == 3) - { - res = 1; - returned_records = 0; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "All records created, starting iteration over all zones \n"); - zi = GNUNET_NAMESTORE_zone_iteration_start (nsh, - NULL, - &fail_cb, - NULL, - &zone_proc, - NULL, - &zone_proc_end, - NULL); - if (zi == NULL) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Failed to create zone iterator\n"); - GNUNET_break (0); - GNUNET_SCHEDULER_shutdown (); - return; - } - } -} - - -static struct GNUNET_GNSRECORD_Data * -create_record (unsigned int count) -{ - struct GNUNET_GNSRECORD_Data *rd; - - rd = GNUNET_new_array (count, - struct GNUNET_GNSRECORD_Data); - for (unsigned int c = 0; c < count; c++) - { - rd[c].expiration_time = GNUNET_TIME_relative_to_absolute ( - GNUNET_TIME_UNIT_HOURS).abs_value_us; - rd[c].record_type = TEST_RECORD_TYPE; - rd[c].data_size = 50; - rd[c].data = GNUNET_malloc (50); - rd[c].flags = 0; - memset ((char *) rd[c].data, 'a', 50); - } - return rd; -} - - -/** - * Callback called from the zone iterator when we iterate over - * the empty zone. Check that we got no records and then - * start the actual tests by filling the zone. - */ -static void -empty_zone_proc (void *cls, - const struct GNUNET_CRYPTO_PrivateKey *zone, - const char *label, - unsigned int rd_count, - const struct GNUNET_GNSRECORD_Data *rd) -{ - GNUNET_assert (nsh == cls); - if (NULL != zone) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _ ("Expected empty zone but received zone private key\n")); - GNUNET_break (0); - GNUNET_SCHEDULER_shutdown (); - return; - } - if ((NULL != label) || (NULL != rd) || (0 != rd_count)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _ ("Expected no zone content but received data\n")); - GNUNET_break (0); - GNUNET_SCHEDULER_shutdown (); - return; - } - GNUNET_assert (0); -} - - -static void -empty_zone_proc_end (void *cls) -{ - GNUNET_assert (nsh == cls); - zi = NULL; - privkey.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); - privkey2.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); - GNUNET_CRYPTO_ecdsa_key_create (&privkey.ecdsa_key); - GNUNET_CRYPTO_ecdsa_key_create (&privkey2.ecdsa_key); - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Created record 1\n"); - - GNUNET_asprintf (&s_name_1, - "dummy1"); - s_rd_1 = create_record (1); - GNUNET_NAMESTORE_records_store (nsh, - &privkey, s_name_1, - 1, s_rd_1, &put_cont, NULL); - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Created record 2 \n"); - GNUNET_asprintf (&s_name_2, - "dummy2"); - s_rd_2 = create_record (1); - GNUNET_NAMESTORE_records_store (nsh, - &privkey, - s_name_2, - 1, - s_rd_2, - &put_cont, NULL); - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Created record 3\n"); - - /* name in different zone */ - GNUNET_asprintf (&s_name_3, "dummy3"); - s_rd_3 = create_record (1); - GNUNET_NAMESTORE_records_store (nsh, - &privkey2, - s_name_3, - 1, - s_rd_3, - &put_cont, NULL); -} - - -static void -run (void *cls, - const struct GNUNET_CONFIGURATION_Handle *cfg, - struct GNUNET_TESTING_Peer *peer) -{ - nsh = GNUNET_NAMESTORE_connect (cfg); - GNUNET_break (NULL != nsh); - GNUNET_SCHEDULER_add_shutdown (&end, - NULL); - /* first, iterate over empty namestore */ - zi = GNUNET_NAMESTORE_zone_iteration_start (nsh, - NULL, - &fail_cb, - NULL, - &empty_zone_proc, - nsh, - &empty_zone_proc_end, - nsh); - if (NULL == zi) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Failed to create zone iterator\n"); - GNUNET_break (0); - GNUNET_SCHEDULER_shutdown (); - } -} - - -#include "test_common.c" - - -int -main (int argc, char *argv[]) -{ - const char *plugin_name; - char *cfg_name; - - SETUP_CFG (plugin_name, cfg_name); - res = 1; - if (0 != - GNUNET_TESTING_peer_run ("test-namestore-api-zone-iteration-stop", - cfg_name, - &run, - NULL)) - { - res = 1; - } - GNUNET_DISK_purge_cfg_dir (cfg_name, - "GNUNET_TEST_HOME"); - GNUNET_free (plugin_name); - GNUNET_free (cfg_name); - - return res; -} - - -/* end of test_namestore_api_zone_iteration_stop.c */ diff --git a/src/plugin/namestore/test_namestore_api_zone_to_name.c b/src/plugin/namestore/test_namestore_api_zone_to_name.c @@ -1,266 +0,0 @@ -/* - This file is part of GNUnet. - Copyright (C) 2009 GNUnet e.V. - - GNUnet is free software: you can redistribute it and/or modify it - under the terms of the GNU Affero General Public License as published - by the Free Software Foundation, either version 3 of the License, - or (at your option) any later version. - - GNUnet is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - - SPDX-License-Identifier: AGPL3.0-or-later - */ -/** - * @file namestore/test_namestore_api_zone_to_name.c - * @brief testcase for zone to name translation - */ -#include "platform.h" -#include "gnunet_namestore_service.h" -#include "gnunet_testing_lib.h" -#include "namestore.h" - -#define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT - -#define RECORDS 5 - -#define TEST_RECORD_DATALEN 123 - -#define TEST_RECORD_DATA 'a' - -#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100) - - -static struct GNUNET_NAMESTORE_Handle *nsh; - -static struct GNUNET_SCHEDULER_Task *endbadly_task; - -static struct GNUNET_CRYPTO_PrivateKey privkey; - -static struct GNUNET_CRYPTO_PublicKey pubkey; - -static struct GNUNET_CRYPTO_PublicKey s_zone_value; - -static char *s_name; - -static int res; - -static struct GNUNET_NAMESTORE_QueueEntry *qe; - - -/** - * Re-establish the connection to the service. - * - * @param cls handle to use to re-connect. - */ -static void -endbadly (void *cls) -{ - (void) cls; - GNUNET_SCHEDULER_shutdown (); - res = 1; -} - - -static void -end (void *cls) -{ - if (NULL != qe) - { - GNUNET_NAMESTORE_cancel (qe); - qe = NULL; - } - if (NULL != endbadly_task) - { - GNUNET_SCHEDULER_cancel (endbadly_task); - endbadly_task = NULL; - } - if (NULL != nsh) - { - GNUNET_NAMESTORE_disconnect (nsh); - nsh = NULL; - } -} - - -static void -zone_to_name_proc (void *cls, - const struct GNUNET_CRYPTO_PrivateKey *zone_key, - const char *n, - unsigned int rd_count, - const struct GNUNET_GNSRECORD_Data *rd) -{ - int fail = GNUNET_NO; - - qe = NULL; - if ((NULL == zone_key) && - (NULL == n) && - (0 == rd_count) && - (NULL == rd)) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "No result found\n"); - res = 1; - } - else - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Result found: `%s'\n", - n); - if ((NULL == n) || - (0 != strcmp (n, - s_name))) - { - fail = GNUNET_YES; - GNUNET_break (0); - } - if (1 != rd_count) - { - fail = GNUNET_YES; - GNUNET_break (0); - } - if ((NULL == zone_key) || - (0 != GNUNET_memcmp (zone_key, - &privkey))) - { - fail = GNUNET_YES; - GNUNET_break (0); - } - if (fail == GNUNET_NO) - res = 0; - else - res = 1; - } - GNUNET_SCHEDULER_add_now (&end, - NULL); -} - - -static void -error_cb (void *cls) -{ - (void) cls; - qe = NULL; - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Not found!\n"); - GNUNET_SCHEDULER_shutdown (); - res = 2; -} - - -static void -put_cont (void *cls, - enum GNUNET_ErrorCode ec) -{ - char *name = cls; - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Name store added record for `%s': %s\n", - name, - (GNUNET_EC_NONE == ec) ? - "SUCCESS" : GNUNET_ErrorCode_get_hint (ec)); - if (GNUNET_EC_NONE == ec) - { - res = 0; - - qe = GNUNET_NAMESTORE_zone_to_name (nsh, - &privkey, - &s_zone_value, - &error_cb, - NULL, - &zone_to_name_proc, - NULL); - } - else - { - res = 1; - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Failed to put records for name `%s'\n", - name); - GNUNET_SCHEDULER_add_now (&end, - NULL); - } -} - - -static void -run (void *cls, - const struct GNUNET_CONFIGURATION_Handle *cfg, - struct GNUNET_TESTING_Peer *peer) -{ - (void) cls; - (void) peer; - endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, - &endbadly, - NULL); - GNUNET_SCHEDULER_add_shutdown (&end, - NULL); - GNUNET_asprintf (&s_name, "dummy"); - privkey.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); - GNUNET_CRYPTO_ecdsa_key_create (&privkey.ecdsa_key); - /* get public key */ - GNUNET_CRYPTO_key_get_public (&privkey, - &pubkey); - - GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, - &s_zone_value, - sizeof(s_zone_value)); - s_zone_value.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); - { - struct GNUNET_GNSRECORD_Data rd; - - rd.expiration_time = GNUNET_TIME_UNIT_HOURS.rel_value_us; - rd.record_type = GNUNET_GNSRECORD_TYPE_PKEY; - rd.data_size = sizeof (s_zone_value.ecdsa_key); - rd.data = &s_zone_value.ecdsa_key; - rd.flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; - - nsh = GNUNET_NAMESTORE_connect (cfg); - GNUNET_break (NULL != nsh); - GNUNET_NAMESTORE_records_store (nsh, - &privkey, - s_name, - 1, - &rd, - &put_cont, - s_name); - } -} - - -#include "test_common.c" - - -int -main (int argc, - char *argv[]) -{ - const char *plugin_name; - char *cfg_name; - - (void) argc; - SETUP_CFG (plugin_name, cfg_name); - res = 1; - if (0 != - GNUNET_TESTING_peer_run ("test-namestore-api-zone-to-name", - cfg_name, - &run, - NULL)) - { - res = 1; - } - GNUNET_DISK_purge_cfg_dir (cfg_name, - "GNUNET_TEST_HOME"); - GNUNET_free (plugin_name); - GNUNET_free (cfg_name); - return res; -} - - -/* end of test_namestore_api_zone_to_name.c */ diff --git a/src/plugin/namestore/test_plugin_namestore.c b/src/plugin/namestore/test_plugin_namestore.c @@ -25,7 +25,6 @@ #include "platform.h" #include "gnunet_util_lib.h" #include "gnunet_namestore_plugin.h" -#include "gnunet_testing_lib.h" #define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT @@ -36,7 +35,7 @@ static int ok; */ static const char *plugin_name; - +#ifndef DARWIN // #5582 /** * Function called when the service shuts down. Unloads our namestore * plugin. @@ -52,7 +51,7 @@ unload_plugin (struct GNUNET_NAMESTORE_PluginFunctions *api) GNUNET_break (NULL == GNUNET_PLUGIN_unload (libname, api)); GNUNET_free (libname); } - +#endif /** * Load the namestore plugin. diff --git a/src/service/arm/gnunet-service-arm.c b/src/service/arm/gnunet-service-arm.c @@ -1120,7 +1120,7 @@ create_listen_socket (struct sockaddr *sa, GNUNET_free (sa); return; } - GNUNET_log (GNUNET_ERROR_TYPE_INFO, + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _ ("ARM now monitors connections to service `%s' at `%s'\n"), sl->name, GNUNET_a2s (sa, addr_len)); diff --git a/src/service/dht/gnunet-service-dht.c b/src/service/dht/gnunet-service-dht.c @@ -24,6 +24,7 @@ * @author Christian Grothoff * @author Nathan Evans */ +#include "gnunet_common.h" #include "platform.h" #include "gnunet_block_lib.h" #include "gnunet_util_lib.h" @@ -264,10 +265,21 @@ u_address_add (void *cls, { struct GDS_Underlay *u = cls; struct MyAddress *a; + enum GNUNET_GenericReturnValue add_success; GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Underlay adds address %s for this peer\n", address); + if (GNUNET_OK != (add_success = GNUNET_HELLO_builder_add_address ( + GDS_my_hello, + address))) + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Adding address `%s' from underlay %s\n", + address, + GNUNET_NO == add_success ? "not done" : "failed"); + return; + } a = GNUNET_new (struct MyAddress); a->source = source; a->url = GNUNET_strdup (address); @@ -276,8 +288,7 @@ u_address_add (void *cls, a_tail, a); *ctx = a; - GNUNET_HELLO_builder_add_address (GDS_my_hello, - address); + if (NULL != hello_task) GNUNET_SCHEDULER_cancel (hello_task); hello_task = GNUNET_SCHEDULER_add_now (&broadcast_hello, diff --git a/src/service/namestore/Makefile.am b/src/service/namestore/Makefile.am @@ -61,3 +61,350 @@ gnunet_service_namestore_LDADD = \ $(top_builddir)/src/lib/util/libgnunetutil.la \ libgnunetnamestore.la \ $(GN_LIBINTL) + +if HAVE_SQLITE +SQLITE_TESTS = \ + test_namestore_api_store_sqlite \ + test_namestore_api_store_update_sqlite \ + test_namestore_api_zone_iteration_sqlite \ + test_namestore_api_remove_sqlite \ + test_namestore_api_lookup_nick_sqlite \ + test_namestore_api_monitoring_sqlite \ + test_namestore_api_remove_not_existing_record_sqlite \ + test_namestore_api_zone_iteration_nick_sqlite \ + test_namestore_api_zone_iteration_specific_zone_sqlite \ + test_namestore_api_zone_iteration_stop_sqlite \ + test_namestore_api_monitoring_existing_sqlite \ + test_namestore_api_zone_to_name_sqlite \ + perf_namestore_api_zone_iteration_sqlite \ + perf_namestore_api_import_sqlite \ + perf_namestore_api_import_postgres \ + test_namestore_api_tx_rollback_sqlite +endif + + +if HAVE_POSTGRESQL +POSTGRES_TESTS = \ + test_namestore_api_store_postgres \ + test_namestore_api_store_update_postgres \ + test_namestore_api_remove_postgres \ + test_namestore_api_zone_iteration_postgres \ + test_namestore_api_lookup_nick_postgres \ + test_namestore_api_monitoring_postgres \ + test_namestore_api_remove_not_existing_record_postgres \ + test_namestore_api_zone_iteration_nick_postgres \ + test_namestore_api_zone_iteration_specific_zone_postgres \ + test_namestore_api_zone_iteration_stop_postgres \ + test_namestore_api_monitoring_existing_postgres \ + test_namestore_api_zone_to_name_postgres \ + perf_namestore_api_zone_iteration_postgres \ + test_namestore_api_tx_rollback_postgres +if HAVE_EXPERIMENTAL +POSTGRES_TESTS += test_namestore_api_edit_records_postgres +endif +endif + +check_PROGRAMS = \ + $(SQLITE_TESTS) \ + $(POSTGRES_TESTS) + +if ENABLE_TEST_RUN +AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset XDG_CONFIG_HOME; +TESTS = \ + $(check_PROGRAMS) \ + $(check_SCRIPTS) +endif + +test_namestore_api_store_sqlite_SOURCES = \ + test_namestore_api_store.c +test_namestore_api_store_sqlite_LDADD = \ + $(top_builddir)/src/service/testing/libgnunettesting.la \ + $(top_builddir)/src/lib/util/libgnunetutil.la \ + $(top_builddir)/src/lib/gnsrecord/libgnunetgnsrecord.la \ + $(top_builddir)/src/service/identity/libgnunetidentity.la \ + $(top_builddir)/src/service/namestore/libgnunetnamestore.la + +test_namestore_api_store_postgres_SOURCES = \ + test_namestore_api_store.c +test_namestore_api_store_postgres_LDADD = \ + $(top_builddir)/src/service/testing/libgnunettesting.la \ + $(top_builddir)/src/lib/util/libgnunetutil.la \ + $(top_builddir)/src/lib/gnsrecord/libgnunetgnsrecord.la \ + $(top_builddir)/src/service/identity/libgnunetidentity.la \ + $(top_builddir)/src/service/namestore/libgnunetnamestore.la + +test_namestore_api_store_update_sqlite_SOURCES = \ + test_namestore_api_store_update.c +test_namestore_api_store_update_sqlite_LDADD = \ + $(top_builddir)/src/service/testing/libgnunettesting.la \ + $(top_builddir)/src/lib/util/libgnunetutil.la \ + $(top_builddir)/src/service/identity/libgnunetidentity.la \ + $(top_builddir)/src/lib/gnsrecord/libgnunetgnsrecord.la \ + $(top_builddir)/src/service/namecache/libgnunetnamecache.la \ + $(top_builddir)/src/service/namestore/libgnunetnamestore.la + +test_namestore_api_store_update_postgres_SOURCES = \ + test_namestore_api_store_update.c +test_namestore_api_store_update_postgres_LDADD = \ + $(top_builddir)/src/service/testing/libgnunettesting.la \ + $(top_builddir)/src/lib/util/libgnunetutil.la \ + $(top_builddir)/src/service/identity/libgnunetidentity.la \ + $(top_builddir)/src/lib/gnsrecord/libgnunetgnsrecord.la \ + $(top_builddir)/src/service/namecache/libgnunetnamecache.la \ + $(top_builddir)/src/service/namestore/libgnunetnamestore.la + +test_namestore_api_lookup_nick_sqlite_SOURCES = \ + test_namestore_api_lookup_nick.c +test_namestore_api_lookup_nick_sqlite_LDADD = \ + $(top_builddir)/src/service/testing/libgnunettesting.la \ + $(top_builddir)/src/lib/util/libgnunetutil.la \ + $(top_builddir)/src/service/identity/libgnunetidentity.la \ + $(top_builddir)/src/lib/gnsrecord/libgnunetgnsrecord.la \ + $(top_builddir)/src/service/namecache/libgnunetnamecache.la \ + $(top_builddir)/src/service/namestore/libgnunetnamestore.la + +test_namestore_api_lookup_nick_postgres_SOURCES = \ + test_namestore_api_lookup_nick.c +test_namestore_api_lookup_nick_postgres_LDADD = \ + $(top_builddir)/src/service/testing/libgnunettesting.la \ + $(top_builddir)/src/lib/util/libgnunetutil.la \ + $(top_builddir)/src/service/identity/libgnunetidentity.la \ + $(top_builddir)/src/lib/gnsrecord/libgnunetgnsrecord.la \ + $(top_builddir)/src/service/namecache/libgnunetnamecache.la \ + $(top_builddir)/src/service/namestore/libgnunetnamestore.la + +test_namestore_api_remove_sqlite_SOURCES = \ + test_namestore_api_remove.c +test_namestore_api_remove_sqlite_LDADD = \ + $(top_builddir)/src/service/identity/libgnunetidentity.la \ + $(top_builddir)/src/service/testing/libgnunettesting.la \ + $(top_builddir)/src/lib/util/libgnunetutil.la \ + $(top_builddir)/src/lib/gnsrecord/libgnunetgnsrecord.la \ + $(top_builddir)/src/service/namestore/libgnunetnamestore.la + +test_namestore_api_remove_postgres_SOURCES = \ + test_namestore_api_remove.c +test_namestore_api_remove_postgres_LDADD = \ + $(top_builddir)/src/service/identity/libgnunetidentity.la \ + $(top_builddir)/src/service/testing/libgnunettesting.la \ + $(top_builddir)/src/lib/util/libgnunetutil.la \ + $(top_builddir)/src/lib/gnsrecord/libgnunetgnsrecord.la \ + $(top_builddir)/src/service/namestore/libgnunetnamestore.la + +test_namestore_api_remove_not_existing_record_sqlite_SOURCES = \ + test_namestore_api_remove_not_existing_record.c +test_namestore_api_remove_not_existing_record_sqlite_LDADD = \ + $(top_builddir)/src/service/testing/libgnunettesting.la \ + $(top_builddir)/src/lib/util/libgnunetutil.la \ + $(top_builddir)/src/service/identity/libgnunetidentity.la \ + $(top_builddir)/src/lib/gnsrecord/libgnunetgnsrecord.la \ + $(top_builddir)/src/service/namestore/libgnunetnamestore.la + +test_namestore_api_remove_not_existing_record_postgres_SOURCES = \ + test_namestore_api_remove_not_existing_record.c +test_namestore_api_remove_not_existing_record_postgres_LDADD = \ + $(top_builddir)/src/service/testing/libgnunettesting.la \ + $(top_builddir)/src/service/identity/libgnunetidentity.la \ + $(top_builddir)/src/lib/util/libgnunetutil.la \ + $(top_builddir)/src/lib/gnsrecord/libgnunetgnsrecord.la \ + $(top_builddir)/src/service/namestore/libgnunetnamestore.la + +test_namestore_api_zone_to_name_sqlite_SOURCES = \ + test_namestore_api_zone_to_name.c +test_namestore_api_zone_to_name_sqlite_LDADD = \ + $(top_builddir)/src/service/identity/libgnunetidentity.la \ + $(top_builddir)/src/service/testing/libgnunettesting.la \ + $(top_builddir)/src/lib/util/libgnunetutil.la \ + $(top_builddir)/src/service/namestore/libgnunetnamestore.la + +test_namestore_api_zone_to_name_postgres_SOURCES = \ + test_namestore_api_zone_to_name.c +test_namestore_api_zone_to_name_postgres_LDADD = \ + $(top_builddir)/src/service/identity/libgnunetidentity.la \ + $(top_builddir)/src/service/testing/libgnunettesting.la \ + $(top_builddir)/src/lib/util/libgnunetutil.la \ + $(top_builddir)/src/service/namestore/libgnunetnamestore.la + +test_namestore_api_monitoring_sqlite_SOURCES = \ + test_namestore_api_monitoring.c +test_namestore_api_monitoring_sqlite_LDADD = \ + $(top_builddir)/src/service/identity/libgnunetidentity.la \ + $(top_builddir)/src/service/testing/libgnunettesting.la \ + $(top_builddir)/src/service/namestore/libgnunetnamestore.la \ + $(top_builddir)/src/lib/gnsrecord/libgnunetgnsrecord.la \ + $(top_builddir)/src/lib/util/libgnunetutil.la + +test_namestore_api_monitoring_postgres_SOURCES = \ + test_namestore_api_monitoring.c +test_namestore_api_monitoring_postgres_LDADD = \ + $(top_builddir)/src/service/testing/libgnunettesting.la \ + $(top_builddir)/src/service/identity/libgnunetidentity.la \ + $(top_builddir)/src/service/namestore/libgnunetnamestore.la \ + $(top_builddir)/src/lib/gnsrecord/libgnunetgnsrecord.la \ + $(top_builddir)/src/lib/util/libgnunetutil.la + +test_namestore_api_monitoring_existing_sqlite_SOURCES = \ + test_namestore_api_monitoring_existing.c +test_namestore_api_monitoring_existing_sqlite_LDADD = \ + $(top_builddir)/src/service/testing/libgnunettesting.la \ + $(top_builddir)/src/service/identity/libgnunetidentity.la \ + $(top_builddir)/src/service/namestore/libgnunetnamestore.la \ + $(top_builddir)/src/lib/gnsrecord/libgnunetgnsrecord.la \ + $(top_builddir)/src/lib/util/libgnunetutil.la + +test_namestore_api_monitoring_existing_postgres_SOURCES = \ + test_namestore_api_monitoring_existing.c +test_namestore_api_monitoring_existing_postgres_LDADD = \ + $(top_builddir)/src/service/testing/libgnunettesting.la \ + $(top_builddir)/src/service/namestore/libgnunetnamestore.la \ + $(top_builddir)/src/lib/gnsrecord/libgnunetgnsrecord.la \ + $(top_builddir)/src/service/identity/libgnunetidentity.la \ + $(top_builddir)/src/lib/util/libgnunetutil.la + +test_namestore_api_tx_rollback_sqlite_SOURCES = \ + test_namestore_api_tx_rollback.c +test_namestore_api_tx_rollback_sqlite_LDADD = \ + $(top_builddir)/src/service/testing/libgnunettesting.la \ + $(top_builddir)/src/service/identity/libgnunetidentity.la \ + $(top_builddir)/src/service/namestore/libgnunetnamestore.la \ + $(top_builddir)/src/lib/gnsrecord/libgnunetgnsrecord.la \ + $(top_builddir)/src/lib/util/libgnunetutil.la + +test_namestore_api_tx_rollback_postgres_SOURCES = \ + test_namestore_api_tx_rollback.c +test_namestore_api_tx_rollback_postgres_LDADD = \ + $(top_builddir)/src/service/testing/libgnunettesting.la \ + $(top_builddir)/src/service/identity/libgnunetidentity.la \ + $(top_builddir)/src/service/namestore/libgnunetnamestore.la \ + $(top_builddir)/src/lib/gnsrecord/libgnunetgnsrecord.la \ + $(top_builddir)/src/lib/util/libgnunetutil.la + +if HAVE_EXPERIMENTAL +test_namestore_api_edit_records_postgres_SOURCES = \ + test_namestore_api_edit_records.c +test_namestore_api_edit_records_postgres_LDADD = \ + $(top_builddir)/src/service/testing/libgnunettesting.la \ + $(top_builddir)/src/service/identity/libgnunetidentity.la \ + $(top_builddir)/src/service/namestore/libgnunetnamestore.la \ + $(top_builddir)/src/lib/gnsrecord/libgnunetgnsrecord.la \ + $(top_builddir)/src/lib/util/libgnunetutil.la +endif + +test_namestore_api_zone_iteration_sqlite_SOURCES = \ + test_namestore_api_zone_iteration.c +test_namestore_api_zone_iteration_sqlite_LDADD = \ + $(top_builddir)/src/service/testing/libgnunettesting.la \ + $(top_builddir)/src/service/identity/libgnunetidentity.la \ + $(top_builddir)/src/lib/util/libgnunetutil.la \ + $(top_builddir)/src/lib/gnsrecord/libgnunetgnsrecord.la \ + $(top_builddir)/src/service/namestore/libgnunetnamestore.la + +test_namestore_api_zone_iteration_postgres_SOURCES = \ + test_namestore_api_zone_iteration.c +test_namestore_api_zone_iteration_postgres_LDADD = \ + $(top_builddir)/src/service/testing/libgnunettesting.la \ + $(top_builddir)/src/service/identity/libgnunetidentity.la \ + $(top_builddir)/src/lib/util/libgnunetutil.la \ + $(top_builddir)/src/lib/gnsrecord/libgnunetgnsrecord.la \ + $(top_builddir)/src/service/namestore/libgnunetnamestore.la + +perf_namestore_api_zone_iteration_postgres_SOURCES = \ + perf_namestore_api_zone_iteration.c +perf_namestore_api_zone_iteration_postgres_LDADD = \ + $(top_builddir)/src/service/testing/libgnunettesting.la \ + $(top_builddir)/src/lib/util/libgnunetutil.la \ + $(top_builddir)/src/service/identity/libgnunetidentity.la \ + $(top_builddir)/src/lib/gnsrecord/libgnunetgnsrecord.la \ + $(top_builddir)/src/service/namestore/libgnunetnamestore.la + +perf_namestore_api_import_sqlite_SOURCES = \ + perf_namestore_api_import.c +perf_namestore_api_import_sqlite_LDADD = \ + $(top_builddir)/src/service/testing/libgnunettesting.la \ + $(top_builddir)/src/lib/util/libgnunetutil.la \ + $(top_builddir)/src/service/identity/libgnunetidentity.la \ + $(top_builddir)/src/lib/gnsrecord/libgnunetgnsrecord.la \ + $(top_builddir)/src/service/namestore/libgnunetnamestore.la + +perf_namestore_api_import_postgres_SOURCES = \ + perf_namestore_api_import.c +perf_namestore_api_import_postgres_LDADD = \ + $(top_builddir)/src/service/testing/libgnunettesting.la \ + $(top_builddir)/src/lib/util/libgnunetutil.la \ + $(top_builddir)/src/service/identity/libgnunetidentity.la \ + $(top_builddir)/src/lib/gnsrecord/libgnunetgnsrecord.la \ + $(top_builddir)/src/service/namestore/libgnunetnamestore.la + + +perf_namestore_api_zone_iteration_sqlite_SOURCES = \ + perf_namestore_api_zone_iteration.c +perf_namestore_api_zone_iteration_sqlite_LDADD = \ + $(top_builddir)/src/service/testing/libgnunettesting.la \ + $(top_builddir)/src/service/identity/libgnunetidentity.la \ + $(top_builddir)/src/lib/util/libgnunetutil.la \ + $(top_builddir)/src/lib/gnsrecord/libgnunetgnsrecord.la \ + $(top_builddir)/src/service/namestore/libgnunetnamestore.la + +test_namestore_api_zone_iteration_nick_sqlite_SOURCES = \ + test_namestore_api_zone_iteration_nick.c +test_namestore_api_zone_iteration_nick_sqlite_LDADD = \ + $(top_builddir)/src/service/testing/libgnunettesting.la \ + $(top_builddir)/src/service/identity/libgnunetidentity.la \ + $(top_builddir)/src/lib/util/libgnunetutil.la \ + $(top_builddir)/src/lib/gnsrecord/libgnunetgnsrecord.la \ + $(top_builddir)/src/service/namestore/libgnunetnamestore.la + +test_namestore_api_zone_iteration_nick_postgres_SOURCES = \ + test_namestore_api_zone_iteration_nick.c +test_namestore_api_zone_iteration_nick_postgres_LDADD = \ + $(top_builddir)/src/service/testing/libgnunettesting.la \ + $(top_builddir)/src/service/identity/libgnunetidentity.la \ + $(top_builddir)/src/lib/util/libgnunetutil.la \ + $(top_builddir)/src/lib/gnsrecord/libgnunetgnsrecord.la \ + $(top_builddir)/src/service/namestore/libgnunetnamestore.la + +test_namestore_api_zone_iteration_specific_zone_sqlite_SOURCES = \ + test_namestore_api_zone_iteration_specific_zone.c +test_namestore_api_zone_iteration_specific_zone_sqlite_LDADD = \ + $(top_builddir)/src/service/testing/libgnunettesting.la \ + $(top_builddir)/src/service/identity/libgnunetidentity.la \ + $(top_builddir)/src/lib/util/libgnunetutil.la \ + $(top_builddir)/src/lib/gnsrecord/libgnunetgnsrecord.la \ + $(top_builddir)/src/service/namestore/libgnunetnamestore.la + +test_namestore_api_zone_iteration_specific_zone_postgres_SOURCES = \ + test_namestore_api_zone_iteration_specific_zone.c +test_namestore_api_zone_iteration_specific_zone_postgres_LDADD = \ + $(top_builddir)/src/service/testing/libgnunettesting.la \ + $(top_builddir)/src/service/identity/libgnunetidentity.la \ + $(top_builddir)/src/lib/util/libgnunetutil.la \ + $(top_builddir)/src/lib/gnsrecord/libgnunetgnsrecord.la \ + $(top_builddir)/src/service/namestore/libgnunetnamestore.la + +test_namestore_api_zone_iteration_stop_sqlite_SOURCES = \ + test_namestore_api_zone_iteration_stop.c +test_namestore_api_zone_iteration_stop_sqlite_LDADD = \ + $(top_builddir)/src/service/testing/libgnunettesting.la \ + $(top_builddir)/src/service/identity/libgnunetidentity.la \ + $(top_builddir)/src/lib/util/libgnunetutil.la \ + $(top_builddir)/src/lib/gnsrecord/libgnunetgnsrecord.la \ + $(top_builddir)/src/service/namestore/libgnunetnamestore.la + +test_namestore_api_zone_iteration_stop_postgres_SOURCES = \ + test_namestore_api_zone_iteration_stop.c +test_namestore_api_zone_iteration_stop_postgres_LDADD = \ + $(top_builddir)/src/service/testing/libgnunettesting.la \ + $(top_builddir)/src/service/identity/libgnunetidentity.la \ + $(top_builddir)/src/lib/util/libgnunetutil.la \ + $(top_builddir)/src/lib/gnsrecord/libgnunetgnsrecord.la \ + $(top_builddir)/src/service/namestore/libgnunetnamestore.la + + +EXTRA_DIST = \ + test_common.c \ + test_namestore_api.conf \ + test_namestore_api_postgres.conf \ + test_namestore_api_sqlite.conf \ + perf_namestore_api_postgres.conf \ + perf_namestore_api_sqlite.conf + diff --git a/src/service/namestore/meson.build b/src/service/namestore/meson.build @@ -55,3 +55,62 @@ executable ('gnunet-namestore-fcfsd', install: true, install_dir: get_option('libdir')/'gnunet'/'libexec') + +configure_file(copy: true, + input: 'test_namestore_api.conf', + output: 'test_namestore_api.conf') + +configure_file(copy: true, + input: 'test_namestore_api_sqlite.conf', + output: 'test_namestore_api_sqlite.conf') + +namestoreapitestnames = [ + 'test_namestore_api_lookup_nick', + 'test_namestore_api_monitoring', + 'test_namestore_api_monitoring_existing', + 'test_namestore_api_remove', + 'test_namestore_api_remove_not_existing_record', + 'test_namestore_api_store', + 'test_namestore_api_store_update', + 'test_namestore_api_tx_rollback', + 'test_namestore_api_zone_iteration', + 'test_namestore_api_zone_iteration_nick', + 'test_namestore_api_zone_iteration_specific_zone', + 'test_namestore_api_zone_iteration_stop', + 'test_namestore_api_zone_to_name' + ] + +if get_option('experimental') + namestoreapitestnames +='test_namestore_api_edit_records' +endif + +foreach tn : namestoreapitestnames + t = executable (tn + '_sqlite', + [tn + '.c'], + dependencies: [ + libgnunettesting_dep, + libgnunetutil_dep, + libgnunetgnsrecord_dep, + libgnunetidentity_dep, + libgnunetnamestore_dep], + include_directories: [incdir, configuration_inc], + install: false) + test(tn + '_sqlite', t, workdir: meson.current_build_dir(), + suite: 'namestore') + if pq_dep.found() + t_pq = executable (tn + '_postgres', + [tn + '.c'], + dependencies: [ + libgnunettesting_dep, + libgnunetutil_dep, + libgnunetgnsrecord_dep, + libgnunetidentity_dep, + libgnunetnamestore_dep], + include_directories: [incdir, configuration_inc], + install: false) + test(tn + '_postgres', t, workdir: meson.current_build_dir(), + suite: 'namestore') + endif +endforeach + +# FIXME perf tests missing diff --git a/src/service/namestore/perf_namestore_api_import.c b/src/service/namestore/perf_namestore_api_import.c @@ -0,0 +1,406 @@ +/* + This file is part of GNUnet. + Copyright (C) 2022 GNUnet e.V. + + GNUnet is free software: you can redistribute it and/or modify it + under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, + or (at your option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + + SPDX-License-Identifier: AGPL3.0-or-later + */ +/** + * @file namestore/perf_namestore_api_import.c + * @brief testcase for namestore: Import a lot of records + * @author Martin Schanzenbach + */ +#include "platform.h" +#include "gnunet_namestore_service.h" +#include "gnunet_testing_lib.h" +#include "../service/namestore/namestore.h" + +#define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT + +#define TEST_RECORD_COUNT 10000 + +/** + * A #BENCHMARK_SIZE of 1000 takes less than a minute on a reasonably + * modern system, so 30 minutes should be OK even for very, very + * slow systems. + */ +#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 30) + +/** + * The runtime of the benchmark is expected to be linear + * for the iteration phase with a *good* database. The FLAT + * database uses a quadratic retrieval algorithm, + * hence it should be quadratic in the size. + */ +#define BENCHMARK_SIZE 1000 + +/** + * Maximum record size + */ +#define MAX_REC_SIZE 500 + +/** + * How big are the blocks we fetch? Note that the first block is + * always just 1 record set per current API. Smaller block + * sizes will make quadratic iteration-by-offset penalties + * more pronounced. + */ +#define BLOCK_SIZE 100 + +static struct GNUNET_NAMESTORE_Handle *nsh; + +static struct GNUNET_SCHEDULER_Task *timeout_task; + +static struct GNUNET_SCHEDULER_Task *t; + +static struct GNUNET_CRYPTO_PrivateKey privkey; + +static struct GNUNET_NAMESTORE_QueueEntry *qe; + +static int res; + +static struct GNUNET_TIME_Absolute start; + +struct GNUNET_NAMESTORE_RecordInfo ri[TEST_RECORD_COUNT]; + +int single_put_pos; + +static int bulk_count = 0; + + +/** + * Terminate everything + * + * @param cls NULL + */ +static void +end (void *cls) +{ + (void) cls; + if (NULL != qe) + { + GNUNET_NAMESTORE_cancel (qe); + qe = NULL; + } + if (NULL != nsh) + { + GNUNET_NAMESTORE_disconnect (nsh); + nsh = NULL; + } + if (NULL != t) + { + GNUNET_SCHEDULER_cancel (t); + t = NULL; + } + if (NULL != timeout_task) + { + GNUNET_SCHEDULER_cancel (timeout_task); + timeout_task = NULL; + } +} + + +/** + * End with timeout. As this is a benchmark, we do not + * fail hard but return "skipped". + */ +static void +timeout (void *cls) +{ + (void) cls; + timeout_task = NULL; + GNUNET_SCHEDULER_shutdown (); + res = 77; +} + + +static struct GNUNET_GNSRECORD_Data * +create_record (unsigned int count) +{ + struct GNUNET_GNSRECORD_Data *rd; + + rd = GNUNET_malloc (count + sizeof(struct GNUNET_GNSRECORD_Data)); + rd->expiration_time = GNUNET_TIME_relative_to_absolute ( + GNUNET_TIME_UNIT_HOURS).abs_value_us; + rd->record_type = TEST_RECORD_TYPE; + rd->data_size = count; + rd->data = (void *) &rd[1]; + rd->flags = 0; + memset (&rd[1], + 'a', + count); + return rd; +} + + +static void +publish_records_single (void *cls); + +static void +commit_cont (void *cls, + enum GNUNET_ErrorCode ec) +{ + struct GNUNET_TIME_Relative delay; + + (void) cls; + qe = NULL; + if (GNUNET_EC_NONE != ec) + { + GNUNET_break (0); + GNUNET_SCHEDULER_shutdown (); + return; + } + single_put_pos++; + delay = GNUNET_TIME_absolute_get_duration (start); + fprintf (stdout, + "BULK-TX: Publishing %u records took %s\n", + TEST_RECORD_COUNT, + GNUNET_STRINGS_relative_time_to_string (delay, + GNUNET_YES)); + res = 0; + GNUNET_SCHEDULER_shutdown (); +} + +static void +publish_records_bulk_tx (void *cls); + + +static void +put_cont_bulk_tx (void *cls, + enum GNUNET_ErrorCode ec) +{ + qe = NULL; + if (GNUNET_EC_NONE != ec) + { + GNUNET_break (0); + GNUNET_SCHEDULER_shutdown (); + return; + } + if (bulk_count == TEST_RECORD_COUNT) + { + qe = GNUNET_NAMESTORE_transaction_commit (nsh, commit_cont, NULL); + return; + } + t = GNUNET_SCHEDULER_add_now (&publish_records_bulk_tx, NULL); +} + + +static void +publish_records_bulk_tx (void *cls) +{ + unsigned int sent_rds; + t = NULL; + qe = GNUNET_NAMESTORE_records_store2 (nsh, + &privkey, + TEST_RECORD_COUNT - bulk_count, + &ri[bulk_count], + &sent_rds, + &put_cont_bulk_tx, + NULL); + bulk_count += sent_rds; + GNUNET_assert (sent_rds != 0); +} + + +static void +begin_cont (void *cls, + enum GNUNET_ErrorCode ec) +{ + unsigned int sent_rds; + qe = GNUNET_NAMESTORE_records_store2 (nsh, + &privkey, + TEST_RECORD_COUNT - bulk_count, + &ri[bulk_count], + &sent_rds, + &put_cont_bulk_tx, + NULL); + bulk_count += sent_rds; + GNUNET_assert (sent_rds != 0); +} + +static void +publish_records_bulk (void *cls); + +static void +put_cont_bulk (void *cls, + enum GNUNET_ErrorCode ec) +{ + struct GNUNET_TIME_Relative delay; + + (void) cls; + qe = NULL; + if (GNUNET_EC_NONE != ec) + { + GNUNET_break (0); + GNUNET_SCHEDULER_shutdown (); + return; + } + + if (bulk_count == TEST_RECORD_COUNT) + { + delay = GNUNET_TIME_absolute_get_duration (start); + fprintf (stdout, + "BULK: Publishing %u records took %s\n", + TEST_RECORD_COUNT, + GNUNET_STRINGS_relative_time_to_string (delay, + GNUNET_YES)); + start = GNUNET_TIME_absolute_get (); + bulk_count = 0; + qe = GNUNET_NAMESTORE_transaction_begin (nsh, begin_cont, NULL); + return; + } + (void) cls; + qe = NULL; + if (GNUNET_EC_NONE != ec) + { + GNUNET_break (0); + GNUNET_SCHEDULER_shutdown (); + return; + } + t = GNUNET_SCHEDULER_add_now (&publish_records_bulk, NULL); +} + +static void +publish_records_bulk (void *cls) +{ + static unsigned int sent_rds = 0; + (void) cls; + t = NULL; + qe = GNUNET_NAMESTORE_records_store2 (nsh, + &privkey, + TEST_RECORD_COUNT - bulk_count, + &ri[bulk_count], + &sent_rds, + &put_cont_bulk, + NULL); + bulk_count += sent_rds; + GNUNET_assert (sent_rds != 0); +} + + +static void +put_cont_single (void *cls, + enum GNUNET_ErrorCode ec) +{ + struct GNUNET_TIME_Relative delay; + (void) cls; + qe = NULL; + if (GNUNET_EC_NONE != ec) + { + GNUNET_break (0); + GNUNET_SCHEDULER_shutdown (); + return; + } + single_put_pos++; + if (single_put_pos == TEST_RECORD_COUNT) + { + delay = GNUNET_TIME_absolute_get_duration (start); + fprintf (stdout, + "SINGLE: Publishing %u records took %s\n", + TEST_RECORD_COUNT, + GNUNET_STRINGS_relative_time_to_string (delay, + GNUNET_YES)); + start = GNUNET_TIME_absolute_get (); + t = GNUNET_SCHEDULER_add_now (&publish_records_bulk, NULL); + return; + } + t = GNUNET_SCHEDULER_add_now (&publish_records_single, + NULL); +} + + +static void +publish_records_single (void *cls) +{ + struct GNUNET_TIME_Relative delay; + + (void) cls; + t = NULL; + if (single_put_pos == TEST_RECORD_COUNT) + { + delay = GNUNET_TIME_absolute_get_duration (start); + fprintf (stdout, + "Publishing %u records took %s\n", + TEST_RECORD_COUNT, + GNUNET_STRINGS_relative_time_to_string (delay, + GNUNET_YES)); + GNUNET_SCHEDULER_add_now (&publish_records_bulk, NULL); + } + qe = GNUNET_NAMESTORE_records_store (nsh, + &privkey, + ri[single_put_pos].a_label, + ri[single_put_pos].a_rd_count, + ri[single_put_pos].a_rd, + &put_cont_single, + NULL); +} + + +static void +run (void *cls, + const struct GNUNET_CONFIGURATION_Handle *cfg, + struct GNUNET_TESTING_Peer *peer) +{ + + for (int i = 0; i < TEST_RECORD_COUNT; i++) + { + ri[i].a_rd = create_record (1); + ri[i].a_rd_count = 1; + GNUNET_asprintf ((char**) &ri[i].a_label, "label_%d", i); + } + GNUNET_SCHEDULER_add_shutdown (&end, + NULL); + timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, + &timeout, + NULL); + nsh = GNUNET_NAMESTORE_connect (cfg); + GNUNET_assert (NULL != nsh); + privkey.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); + GNUNET_CRYPTO_ecdsa_key_create (&privkey.ecdsa_key); + start = GNUNET_TIME_absolute_get (); + t = GNUNET_SCHEDULER_add_now (&publish_records_single, + NULL); +} + + +#include "test_common.c" + + +int +main (int argc, + char *argv[]) +{ + char *plugin_name; + char *cfg_name; + + SETUP_CFG2 ("perf_namestore_api_%s.conf", plugin_name, cfg_name); + res = 1; + if (0 != + GNUNET_TESTING_peer_run ("perf-namestore-api-import", + cfg_name, + &run, + NULL)) + { + res = 1; + } + GNUNET_DISK_purge_cfg_dir (cfg_name, + "GNUNET_TEST_HOME"); + GNUNET_free (plugin_name); + GNUNET_free (cfg_name); + return res; +} + + +/* end of perf_namestore_api_zone_iteration.c */ diff --git a/src/plugin/namestore/perf_namestore_api_postgres.conf b/src/service/namestore/perf_namestore_api_postgres.conf diff --git a/src/plugin/namestore/perf_namestore_api_sqlite.conf b/src/service/namestore/perf_namestore_api_sqlite.conf diff --git a/src/service/namestore/perf_namestore_api_zone_iteration.c b/src/service/namestore/perf_namestore_api_zone_iteration.c @@ -0,0 +1,378 @@ +/* + This file is part of GNUnet. + Copyright (C) 2013, 2018 GNUnet e.V. + + GNUnet is free software: you can redistribute it and/or modify it + under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, + or (at your option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + + SPDX-License-Identifier: AGPL3.0-or-later + */ +/** + * @file namestore/perf_namestore_api_zone_iteration.c + * @brief testcase for zone iteration functionality: iterate all zones + * @author Christian Grothoff + */ +#include "platform.h" +#include "gnunet_namestore_service.h" +#include "gnunet_testing_lib.h" +#include "../service/namestore/namestore.h" + +#define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT + +/** + * A #BENCHMARK_SIZE of 1000 takes less than a minute on a reasonably + * modern system, so 30 minutes should be OK even for very, very + * slow systems. + */ +#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 30) + +/** + * The runtime of the benchmark is expected to be linear + * for the iteration phase with a *good* database. The FLAT + * database uses a quadratic retrieval algorithm, + * hence it should be quadratic in the size. + */ +#define BENCHMARK_SIZE 1000 + +/** + * Maximum record size + */ +#define MAX_REC_SIZE 500 + +/** + * How big are the blocks we fetch? Note that the first block is + * always just 1 record set per current API. Smaller block + * sizes will make quadratic iteration-by-offset penalties + * more pronounced. + */ +#define BLOCK_SIZE 100 + +static struct GNUNET_NAMESTORE_Handle *nsh; + +static struct GNUNET_SCHEDULER_Task *timeout_task; + +static struct GNUNET_SCHEDULER_Task *t; + +static struct GNUNET_CRYPTO_PrivateKey privkey; + +static struct GNUNET_NAMESTORE_ZoneIterator *zi; + +static struct GNUNET_NAMESTORE_QueueEntry *qe; + +static int res; + +static unsigned int off; + +static unsigned int left_until_next; + +static uint8_t seen[1 + BENCHMARK_SIZE / 8]; + +static struct GNUNET_TIME_Absolute start; + + +/** + * Terminate everything + * + * @param cls NULL + */ +static void +end (void *cls) +{ + (void) cls; + if (NULL != qe) + { + GNUNET_NAMESTORE_cancel (qe); + qe = NULL; + } + if (NULL != zi) + { + GNUNET_NAMESTORE_zone_iteration_stop (zi); + zi = NULL; + } + if (NULL != nsh) + { + GNUNET_NAMESTORE_disconnect (nsh); + nsh = NULL; + } + if (NULL != t) + { + GNUNET_SCHEDULER_cancel (t); + t = NULL; + } + if (NULL != timeout_task) + { + GNUNET_SCHEDULER_cancel (timeout_task); + timeout_task = NULL; + } +} + + +/** + * End with timeout. As this is a benchmark, we do not + * fail hard but return "skipped". + */ +static void +timeout (void *cls) +{ + (void) cls; + timeout_task = NULL; + GNUNET_SCHEDULER_shutdown (); + res = 77; +} + + +static struct GNUNET_GNSRECORD_Data * +create_record (unsigned int count) +{ + struct GNUNET_GNSRECORD_Data *rd; + + rd = GNUNET_malloc (count + sizeof(struct GNUNET_GNSRECORD_Data)); + rd->expiration_time = GNUNET_TIME_relative_to_absolute ( + GNUNET_TIME_UNIT_HOURS).abs_value_us; + rd->record_type = TEST_RECORD_TYPE; + rd->data_size = count; + rd->data = (void *) &rd[1]; + rd->flags = 0; + memset (&rd[1], + 'a', + count); + return rd; +} + + +static void +zone_end (void *cls) +{ + struct GNUNET_TIME_Relative delay; + + zi = NULL; + delay = GNUNET_TIME_absolute_get_duration (start); + fprintf (stdout, + "Iterating over %u records took %s\n", + off, + GNUNET_STRINGS_relative_time_to_string (delay, + GNUNET_YES)); + if (BENCHMARK_SIZE == off) + { + res = 0; + } + else + { + GNUNET_break (0); + res = 1; + } + GNUNET_SCHEDULER_shutdown (); +} + + +static void +fail_cb (void *cls) +{ + zi = NULL; + res = 2; + GNUNET_break (0); + GNUNET_SCHEDULER_shutdown (); +} + + +static void +zone_proc (void *cls, + const struct GNUNET_CRYPTO_PrivateKey *zone, + const char *label, + unsigned int rd_count, + const struct GNUNET_GNSRECORD_Data *rd) +{ + struct GNUNET_GNSRECORD_Data *wrd; + unsigned int xoff; + + GNUNET_assert (NULL != zone); + if (1 != sscanf (label, + "l%u", + &xoff)) + { + res = 3; + GNUNET_break (0); + GNUNET_SCHEDULER_shutdown (); + return; + } + if ((xoff > BENCHMARK_SIZE) || + (0 != (seen[xoff / 8] & (1U << (xoff % 8))))) + { + res = 3; + GNUNET_break (0); + GNUNET_SCHEDULER_shutdown (); + return; + } + seen[xoff / 8] |= (1U << (xoff % 8)); + wrd = create_record (xoff % MAX_REC_SIZE); + if ((rd->record_type != wrd->record_type) || + (rd->data_size != wrd->data_size) || + (rd->flags != wrd->flags)) + { + res = 4; + GNUNET_break (0); + GNUNET_SCHEDULER_shutdown (); + GNUNET_free (wrd); + return; + } + if (0 != memcmp (rd->data, + wrd->data, + wrd->data_size)) + { + res = 4; + GNUNET_break (0); + GNUNET_SCHEDULER_shutdown (); + GNUNET_free (wrd); + return; + } + GNUNET_free (wrd); + if (0 != GNUNET_memcmp (zone, + &privkey)) + { + res = 5; + GNUNET_break (0); + GNUNET_SCHEDULER_shutdown (); + return; + } + off++; + left_until_next--; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Obtained record %u, expecting %u more until asking for more explicitly\n", + off, + left_until_next); + if (0 == left_until_next) + { + left_until_next = BLOCK_SIZE; + GNUNET_NAMESTORE_zone_iterator_next (zi, + left_until_next); + } +} + + +static void +publish_record (void *cls); + + +static void +put_cont (void *cls, + enum GNUNET_ErrorCode ec) +{ + (void) cls; + qe = NULL; + if (GNUNET_EC_NONE != ec) + { + GNUNET_break (0); + GNUNET_SCHEDULER_shutdown (); + return; + } + t = GNUNET_SCHEDULER_add_now (&publish_record, + NULL); +} + + +static void +publish_record (void *cls) +{ + struct GNUNET_GNSRECORD_Data *rd; + char *label; + + (void) cls; + t = NULL; + if (BENCHMARK_SIZE == off) + { + struct GNUNET_TIME_Relative delay; + + delay = GNUNET_TIME_absolute_get_duration (start); + fprintf (stdout, + "Inserting %u records took %s\n", + off, + GNUNET_STRINGS_relative_time_to_string (delay, + GNUNET_YES)); + start = GNUNET_TIME_absolute_get (); + off = 0; + left_until_next = 1; + zi = GNUNET_NAMESTORE_zone_iteration_start (nsh, + NULL, + &fail_cb, + NULL, + &zone_proc, + NULL, + &zone_end, + NULL); + GNUNET_assert (NULL != zi); + return; + } + rd = create_record ((++off) % MAX_REC_SIZE); + GNUNET_asprintf (&label, + "l%u", + off); + qe = GNUNET_NAMESTORE_records_store (nsh, + &privkey, + label, + 1, rd, + &put_cont, + NULL); + GNUNET_free (label); + GNUNET_free (rd); +} + + +static void +run (void *cls, + const struct GNUNET_CONFIGURATION_Handle *cfg, + struct GNUNET_TESTING_Peer *peer) +{ + GNUNET_SCHEDULER_add_shutdown (&end, + NULL); + timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, + &timeout, + NULL); + nsh = GNUNET_NAMESTORE_connect (cfg); + GNUNET_assert (NULL != nsh); + privkey.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); + GNUNET_CRYPTO_ecdsa_key_create (&privkey.ecdsa_key); + start = GNUNET_TIME_absolute_get (); + t = GNUNET_SCHEDULER_add_now (&publish_record, + NULL); +} + + +#include "test_common.c" + + +int +main (int argc, + char *argv[]) +{ + char *plugin_name; + char *cfg_name; + + SETUP_CFG (plugin_name, cfg_name); + res = 1; + if (0 != + GNUNET_TESTING_peer_run ("perf-namestore-api-zone-iteration", + cfg_name, + &run, + NULL)) + { + res = 1; + } + GNUNET_DISK_purge_cfg_dir (cfg_name, + "GNUNET_TEST_HOME"); + GNUNET_free (plugin_name); + GNUNET_free (cfg_name); + return res; +} + + +/* end of perf_namestore_api_zone_iteration.c */ diff --git a/src/plugin/namestore/test_common.c b/src/service/namestore/test_common.c diff --git a/src/service/namestore/test_namestore_api.conf b/src/service/namestore/test_namestore_api.conf @@ -0,0 +1,43 @@ +@INLINE@ ../../../contrib/conf/gnunet/no_forcestart.conf +@INLINE@ ../../../contrib/conf/gnunet/no_autostart_above_core.conf + +[PATHS] +GNUNET_TEST_HOME = $GNUNET_TMP/test-gnunet-namestore/ + +[namestore] +DATABASE = sqlite +START_ON_DEMAND = YES +#PREFIX = valgrind --track-origins=yes --log-file=/tmp/ns_tx.log +RETURN_ORPHANED = YES + +[namecache] +DATABASE = sqlite +START_ON_DEMAND = YES + +[zonemaster] +START_ON_DEMAND = YES +IMMEDIATE_START = NO + +[dht] +START_ON_DEMAND = YES +IMMEDIATE_START = NO + + +[zonemaster-monitor] +START_ON_DEMAND = YES +IMMEDIATE_START = YES + +[identity] +START_ON_DEMAND = YES + +[nse] +WORKBITS = 0 + +[rest] +BASIC_AUTH_ENABLED=NO +# PREFIX = valgrind --leak-check=full --track-origins=yes --log-file=/tmp/v_log + + + +[transport] +PLUGINS = diff --git a/src/service/namestore/test_namestore_api_edit_records.c b/src/service/namestore/test_namestore_api_edit_records.c @@ -0,0 +1,399 @@ +/* + This file is part of GNUnet. + Copyright (C) 2022 GNUnet e.V. + + GNUnet is free software: you can redistribute it and/or modify it + under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, + or (at your option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + + SPDX-License-Identifier: AGPL3.0-or-later + */ +/** + * @file namestore/test_namestore_api_edit_records.c + * @brief testcase for namestore_api.c: Multiple clients work with record set. + */ +#include "platform.h" +#include "gnunet_namestore_service.h" +#include "gnunet_testing_lib.h" + +#define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT + +#define TEST_RECORD_DATALEN 123 + +#define TEST_RECORD_DATA 'a' + +#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100) + + +static struct GNUNET_NAMESTORE_Handle *nsh; + +static struct GNUNET_NAMESTORE_Handle *nsh2; + +static struct GNUNET_SCHEDULER_Task *endbadly_task; + +static struct GNUNET_CRYPTO_PrivateKey privkey; + +static struct GNUNET_CRYPTO_PublicKey pubkey; + +static int res; + +static int removed; + +static struct GNUNET_NAMESTORE_QueueEntry *nsqe; + +static int nonce = 0; + +static void +cleanup () +{ + if (NULL != nsh) + { + GNUNET_NAMESTORE_disconnect (nsh); + nsh = NULL; + } + GNUNET_SCHEDULER_shutdown (); +} + + +/** + * Re-establish the connection to the service. + * + * @param cls handle to use to re-connect. + */ +static void +endbadly (void *cls) +{ + if (NULL != nsqe) + { + GNUNET_NAMESTORE_cancel (nsqe); + nsqe = NULL; + } + cleanup (); + res = 1; +} + + +static void +end (void *cls) +{ + cleanup (); + res = 0; +} + +static void +lookup_it (void *cls, + const struct GNUNET_CRYPTO_PrivateKey *zone, + const char *label, + unsigned int rd_count, + const struct GNUNET_GNSRECORD_Data *rd) +{ + GNUNET_assert (0 == rd_count); + GNUNET_SCHEDULER_add_now (&end, NULL); +} + +static void +fail_cb (void *cls) +{ + if (endbadly_task != NULL) + GNUNET_SCHEDULER_cancel (endbadly_task); + endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); + return; +} + +static void +remove_cont (void *cls, + enum GNUNET_ErrorCode ec) +{ + nsqe = NULL; + if (GNUNET_EC_NONE != ec) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _ ("Unable to roll back: `%s'\n"), + GNUNET_ErrorCode_get_hint (ec)); + if (NULL != endbadly_task) + GNUNET_SCHEDULER_cancel (endbadly_task); + endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, + NULL); + return; + } + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Rolled back, perform lookup\n"); + removed = GNUNET_YES; + if (NULL != endbadly_task) + GNUNET_SCHEDULER_cancel (endbadly_task); + GNUNET_SCHEDULER_add_now (&end, NULL); +} + +static void +fail_cb_lock (void *cls); + +static void +edit_cont_b (void *cls, + const struct GNUNET_CRYPTO_PrivateKey *zone, + const char *label, + unsigned int rd_count, + const struct GNUNET_GNSRECORD_Data *rd) +{ + const char *name = cls; + /** + * We should probably never get here right at first. + * We may want to change the blocking of nsh2 so that we do get this + * eventually instead of the error callback above when locked. + */ + if (0 == nonce) + { + if (endbadly_task != NULL) + GNUNET_SCHEDULER_cancel (endbadly_task); + endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); + return; + + } + /* Abort transaction for B */ + nsqe = GNUNET_NAMESTORE_transaction_rollback (nsh2, remove_cont, + (void *) name); +} + + +static void +commit_cont_a (void *cls, + enum GNUNET_ErrorCode ec) +{ + const char *name = cls; + + GNUNET_assert (NULL != cls); + nsqe = NULL; + if (GNUNET_EC_NONE != ec) + { + GNUNET_break (0); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Namestore could not store record: `%s'\n", + GNUNET_ErrorCode_get_hint (ec)); + if (endbadly_task != NULL) + GNUNET_SCHEDULER_cancel (endbadly_task); + endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); + return; + } + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Name store added record for `%s': %s\n", + name, + (GNUNET_EC_NONE == ec) ? "SUCCESS" : "FAIL"); + /** + * Try again for B + */ + nsqe = GNUNET_NAMESTORE_records_edit (nsh2, + &privkey, + name, + &fail_cb_lock, + (void *) name, + &edit_cont_b, + (void *) name); + + GNUNET_assert (NULL != nsqe); +} + +static void +fail_cb_lock (void *cls) +{ + const char *name = cls; + if (1 == nonce) + { + if (endbadly_task != NULL) + GNUNET_SCHEDULER_cancel (endbadly_task); + endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); + return; + } + nonce = 1; + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Failed to aquire additional lock\n"); + /* Now, we stop the transaction for B */ + nsqe = GNUNET_NAMESTORE_transaction_commit (nsh, commit_cont_a, + (void *) name); +} + + +static void +begin_cont_b (void *cls, + enum GNUNET_ErrorCode ec) +{ + const char *name = cls; + + GNUNET_assert (GNUNET_EC_NONE == ec); + /** Now, we expect this to "hang" let's see how this behaves in practice. */ + nsqe = GNUNET_NAMESTORE_records_edit (nsh2, + &privkey, + name, + &fail_cb_lock, + (void *) name, + &edit_cont_b, + (void *) name); + + GNUNET_assert (NULL != nsqe); +} + + +static void +edit_cont (void *cls, + const struct GNUNET_CRYPTO_PrivateKey *zone, + const char *label, + unsigned int rd_count, + const struct GNUNET_GNSRECORD_Data *rd) +{ + const char *name = cls; + + GNUNET_assert (1 == rd_count); + /* Now, we start a transaction for B */ + nsqe = GNUNET_NAMESTORE_transaction_begin (nsh2, begin_cont_b, (void *) name); +} + + +static void +begin_cont (void *cls, + enum GNUNET_ErrorCode ec) +{ + const char *name = cls; + + GNUNET_assert (GNUNET_EC_NONE == ec); + nsqe = GNUNET_NAMESTORE_records_edit (nsh, + &privkey, + name, + &fail_cb, + (void *) name, + &edit_cont, + (void *) name); + + GNUNET_assert (NULL != nsqe); +} + +static void +preload_cont (void *cls, + enum GNUNET_ErrorCode ec) +{ + const char *name = cls; + + GNUNET_assert (NULL != cls); + nsqe = NULL; + if (GNUNET_EC_NONE != ec) + { + GNUNET_break (0); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Namestore could not store record: `%s'\n", + GNUNET_ErrorCode_get_hint (ec)); + if (endbadly_task != NULL) + GNUNET_SCHEDULER_cancel (endbadly_task); + endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); + return; + } + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Name store added record for `%s': %s\n", + name, + (GNUNET_EC_NONE == ec) ? "SUCCESS" : "FAIL"); + /* We start transaction for A */ + nsqe = GNUNET_NAMESTORE_transaction_begin (nsh, begin_cont, (void *) name); + +} + + +static void +run (void *cls, + const struct GNUNET_CONFIGURATION_Handle *cfg, + struct GNUNET_TESTING_Peer *peer) +{ + struct GNUNET_GNSRECORD_Data rd; + const char *name = "dummy"; + + endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, + &endbadly, + NULL); + nsh = GNUNET_NAMESTORE_connect (cfg); + nsh2 = GNUNET_NAMESTORE_connect (cfg); + GNUNET_break (NULL != nsh); + GNUNET_break (NULL != nsh2); + + privkey.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); + GNUNET_CRYPTO_ecdsa_key_create (&privkey.ecdsa_key); + GNUNET_CRYPTO_key_get_public (&privkey, + &pubkey); + + removed = GNUNET_NO; + + rd.expiration_time = GNUNET_TIME_absolute_get ().abs_value_us; + rd.record_type = TEST_RECORD_TYPE; + rd.data_size = TEST_RECORD_DATALEN; + rd.data = GNUNET_malloc (TEST_RECORD_DATALEN); + rd.flags = 0; + memset ((char *) rd.data, + 'a', + TEST_RECORD_DATALEN); + nsqe = GNUNET_NAMESTORE_records_store (nsh, + &privkey, + name, + 1, + &rd, + &preload_cont, + (void *) name); + GNUNET_assert (NULL != nsqe); + GNUNET_free_nz ((void *) rd.data); + + /*nsqe = GNUNET_NAMESTORE_transaction_commit (nsh, commit_cont); + nsqe = GNUNET_NAMESTORE_transaction_rollback (nsh, rollback_cont); Must also happen on disconnect + nsqe = GNUNET_NAMESTORE_records_edit (nsh, + &privkey, + name, + 1, + &rd, + &edit_cont, + (void *) name); + nsqe = GNUNET_NAMESTORE_records_insert_bulk (nsh, + count, + &rd, + & + nsqe = GNUNET_NAMESTORE_records_store (nsh, + &privkey, + name, + 1, + &rd, + &put_cont, + (void *) name);*/ + GNUNET_assert (NULL != nsqe); +} + + +#include "test_common.c" + + +int +main (int argc, char *argv[]) +{ + char *plugin_name; + char *cfg_name; + + SETUP_CFG (plugin_name, cfg_name); + res = 1; + if (0 != + GNUNET_TESTING_peer_run ("test-namestore-api-remove", + cfg_name, + &run, + NULL)) + { + res = 1; + } + GNUNET_DISK_purge_cfg_dir (cfg_name, + "GNUNET_TEST_HOME"); + GNUNET_free (plugin_name); + GNUNET_free (cfg_name); + return res; +} + + +/* end of test_namestore_api_remove.c */ diff --git a/src/service/namestore/test_namestore_api_lookup_nick.c b/src/service/namestore/test_namestore_api_lookup_nick.c @@ -0,0 +1,347 @@ +/* + This file is part of GNUnet. + Copyright (C) 2012 GNUnet e.V. + + GNUnet is free software: you can redistribute it and/or modify it + under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, + or (at your option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + + SPDX-License-Identifier: AGPL3.0-or-later + */ +/** + * @file namestore/test_namestore_api_lookup_nick.c + * @brief testcase for namestore_api.c: NICK records + */ +#include "platform.h" +#include "gnunet_namestore_service.h" +#include "gnunet_gns_service.h" +#include "gnunet_testing_lib.h" + +#define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT + +#define TEST_RECORD_DATALEN 123 + +#define TEST_NICK "gnunettestnick" + +#define TEST_RECORD_DATA 'a' + +#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) + +static struct GNUNET_NAMESTORE_Handle *nsh; + +static struct GNUNET_SCHEDULER_Task *endbadly_task; + +static struct GNUNET_CRYPTO_PrivateKey privkey; + +static struct GNUNET_CRYPTO_PublicKey pubkey; + +static int res; + +static struct GNUNET_GNSRECORD_Data rd_orig; + +static struct GNUNET_NAMESTORE_QueueEntry *nsqe; + +// static const char * name = "dummy.dummy.gnunet"; +static const char *name = "d"; + +static char *record_data; + +static void +cleanup () +{ + GNUNET_free (record_data); + if (NULL != nsh) + { + GNUNET_NAMESTORE_disconnect (nsh); + nsh = NULL; + } + GNUNET_SCHEDULER_shutdown (); +} + + +/** + * Re-establish the connection to the service. + * + * @param cls handle to use to re-connect. + * @param tc scheduler context + */ +static void +endbadly (void *cls) +{ + if (NULL != nsqe) + { + GNUNET_NAMESTORE_cancel (nsqe); + nsqe = NULL; + } + cleanup (); + res = 1; +} + + +static void +end (void *cls) +{ + cleanup (); + res = 0; +} + + +static void +lookup_it (void *cls, + const struct GNUNET_CRYPTO_PrivateKey *zone, + const char *label, + unsigned int rd_count, + const struct GNUNET_GNSRECORD_Data *rd) +{ + nsqe = NULL; + int c; + int found_record = GNUNET_NO; + int found_nick = GNUNET_NO; + + if (0 != GNUNET_memcmp (&privkey, zone)) + { + GNUNET_break (0); + GNUNET_SCHEDULER_cancel (endbadly_task); + endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); + return; + } + + if (NULL == label) + { + GNUNET_break (0); + GNUNET_SCHEDULER_cancel (endbadly_task); + endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); + return; + } + + if (0 != strcmp (label, name)) + { + GNUNET_break (0); + GNUNET_SCHEDULER_cancel (endbadly_task); + endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); + return; + } + + if (2 != rd_count) + { + GNUNET_break (0); + GNUNET_SCHEDULER_cancel (endbadly_task); + endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); + return; + } + + for (c = 0; c < rd_count; c++) + { + if (GNUNET_GNSRECORD_TYPE_NICK == rd[c].record_type) + { + if (rd[c].data_size != strlen (TEST_NICK) + 1) + { + GNUNET_break (0); + GNUNET_SCHEDULER_cancel (endbadly_task); + endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); + return; + } + if (0 != (rd[c].flags & GNUNET_GNSRECORD_RF_PRIVATE)) + { + GNUNET_break (0); + GNUNET_SCHEDULER_cancel (endbadly_task); + endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); + return; + } + if (0 != strcmp (rd[c].data, TEST_NICK)) + { + GNUNET_SCHEDULER_cancel (endbadly_task); + endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); + return; + } + found_nick = GNUNET_YES; + } + else + { + if (rd[c].record_type != TEST_RECORD_TYPE) + { + GNUNET_break (0); + GNUNET_SCHEDULER_cancel (endbadly_task); + endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); + return; + } + if (rd[c].data_size != TEST_RECORD_DATALEN) + { + GNUNET_break (0); + GNUNET_SCHEDULER_cancel (endbadly_task); + endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); + return; + } + if (0 != memcmp (rd[c].data, rd_orig.data, TEST_RECORD_DATALEN)) + { + GNUNET_break (0); + GNUNET_SCHEDULER_cancel (endbadly_task); + endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); + return; + } + if (rd[c].flags != rd->flags) + { + GNUNET_break (0); + GNUNET_SCHEDULER_cancel (endbadly_task); + endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); + return; + } + found_record = GNUNET_YES; + } + } + + /* Done */ + if ((GNUNET_YES == found_nick) && (GNUNET_YES == found_record)) + { + GNUNET_SCHEDULER_cancel (endbadly_task); + endbadly_task = NULL; + GNUNET_SCHEDULER_add_now (&end, NULL); + } + else + { + GNUNET_break (0); + GNUNET_SCHEDULER_cancel (endbadly_task); + endbadly_task = NULL; + GNUNET_SCHEDULER_add_now (&endbadly, NULL); + } +} + + +static void +fail_cb (void *cls) +{ + GNUNET_assert (0); +} + + +static void +put_cont (void *cls, enum GNUNET_ErrorCode ec) +{ + const char *name = cls; + + nsqe = NULL; + GNUNET_assert (NULL != cls); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Name store added record for `%s': %s\n", + name, + (ec == GNUNET_EC_NONE) ? "SUCCESS" : "FAIL"); + + if (GNUNET_EC_NONE != ec) + { + GNUNET_SCHEDULER_cancel (endbadly_task); + endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); + return; + } + /* Lookup */ + nsqe = GNUNET_NAMESTORE_records_lookup (nsh, + &privkey, + name, + &fail_cb, + NULL, + &lookup_it, + NULL); +} + + +static void +nick_cont (void *cls, enum GNUNET_ErrorCode ec) +{ + const char *name = cls; + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Nick added : %s\n", + (ec == GNUNET_EC_NONE) ? "SUCCESS" : "FAIL"); + + rd_orig.expiration_time = GNUNET_TIME_UNIT_HOURS.rel_value_us; + rd_orig.record_type = TEST_RECORD_TYPE; + rd_orig.data_size = TEST_RECORD_DATALEN; + record_data = GNUNET_malloc (TEST_RECORD_DATALEN); + rd_orig.data = record_data; + rd_orig.flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; + memset ((char *) rd_orig.data, 'a', TEST_RECORD_DATALEN); + + nsqe = GNUNET_NAMESTORE_records_store (nsh, &privkey, + name, + 1, + &rd_orig, + &put_cont, (void *) name); +} + + +static void +run (void *cls, + const struct GNUNET_CONFIGURATION_Handle *cfg, + struct GNUNET_TESTING_Peer *peer) +{ + struct GNUNET_GNSRECORD_Data rd; + + endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, + &endbadly, + NULL); + privkey.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); + GNUNET_CRYPTO_ecdsa_key_create (&privkey.ecdsa_key); + GNUNET_CRYPTO_key_get_public (&privkey, + &pubkey); + + nsh = GNUNET_NAMESTORE_connect (cfg); + GNUNET_break (NULL != nsh); + + memset (&rd, 0, sizeof(rd)); + rd.data = TEST_NICK; + rd.data_size = strlen (TEST_NICK) + 1; + rd.record_type = GNUNET_GNSRECORD_TYPE_NICK; + rd.expiration_time = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us; + rd.flags |= GNUNET_GNSRECORD_RF_PRIVATE; + nsqe = GNUNET_NAMESTORE_records_store (nsh, + &privkey, + GNUNET_GNS_EMPTY_LABEL_AT, + 1, + &rd, + &nick_cont, + (void *) name); + + if (NULL == nsqe) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _ ("Namestore cannot store no block\n")); + } +} + + +#include "test_common.c" + + +int +main (int argc, char *argv[]) +{ + char *plugin_name; + char *cfg_name; + + SETUP_CFG (plugin_name, cfg_name); + res = 1; + if (0 != + GNUNET_TESTING_peer_run ("test-namestore-api-lookup-nick", + cfg_name, + &run, + NULL)) + { + res = 1; + } + GNUNET_DISK_purge_cfg_dir (cfg_name, + "GNUNET_TEST_HOME"); + GNUNET_free (plugin_name); + GNUNET_free (cfg_name); + return res; +} + + +/* end of test_namestore_api_store.c */ diff --git a/src/service/namestore/test_namestore_api_monitoring.c b/src/service/namestore/test_namestore_api_monitoring.c @@ -0,0 +1,378 @@ +/* + This file is part of GNUnet. + Copyright (C) 2013, 2018 GNUnet e.V. + + GNUnet is free software: you can redistribute it and/or modify it + under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, + or (at your option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + + SPDX-License-Identifier: AGPL3.0-or-later + */ +/** + * @file namestore/test_namestore_api_monitoring.c + * @brief testcase for zone monitoring functionality: monitor first, then add records + */ +#include "platform.h" +#include "gnunet_namestore_service.h" +#include "gnunet_testing_lib.h" +#include "../service/namestore/namestore.h" + +#define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT + + +#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100) + + +static struct GNUNET_NAMESTORE_Handle *nsh; + +static struct GNUNET_SCHEDULER_Task *endbadly_task; + +static struct GNUNET_CRYPTO_PrivateKey privkey; + +static struct GNUNET_CRYPTO_PrivateKey privkey2; + +static struct GNUNET_NAMESTORE_ZoneMonitor *zm; + +static int res; + +static char *s_name_1; + +static struct GNUNET_GNSRECORD_Data *s_rd_1; + +static char *s_name_2; + +static struct GNUNET_GNSRECORD_Data *s_rd_2; + +static char *s_name_3; + +static struct GNUNET_GNSRECORD_Data *s_rd_3; + +struct GNUNET_NAMESTORE_QueueEntry *ns_ops[3]; + + +static void +do_shutdown () +{ + if (NULL != zm) + { + GNUNET_NAMESTORE_zone_monitor_stop (zm); + zm = NULL; + } + if (NULL != ns_ops[0]) + { + GNUNET_NAMESTORE_cancel (ns_ops[0]); + ns_ops[0] = NULL; + } + if (NULL != ns_ops[1]) + { + GNUNET_NAMESTORE_cancel (ns_ops[1]); + ns_ops[1] = NULL; + } + if (NULL != ns_ops[2]) + { + GNUNET_NAMESTORE_cancel (ns_ops[2]); + ns_ops[2] = NULL; + } + if (NULL != nsh) + { + GNUNET_NAMESTORE_disconnect (nsh); + nsh = NULL; + } + GNUNET_free (s_name_1); + GNUNET_free (s_name_2); + GNUNET_free (s_name_3); + + if (s_rd_1 != NULL) + { + GNUNET_free_nz ((void *) s_rd_1->data); + GNUNET_free (s_rd_1); + } + if (s_rd_2 != NULL) + { + GNUNET_free_nz ((void *) s_rd_2->data); + GNUNET_free (s_rd_2); + } + if (s_rd_3 != NULL) + { + GNUNET_free_nz ((void *) s_rd_3->data); + GNUNET_free (s_rd_3); + } +} + + +/** + * Re-establish the connection to the service. + * + * @param cls handle to use to re-connect. + */ +static void +endbadly (void *cls) +{ + do_shutdown (); + res = 1; +} + + +static void +end (void *cls) +{ + do_shutdown (); + res = 0; +} + + +static void +zone_proc (void *cls, + const struct GNUNET_CRYPTO_PrivateKey *zone_key, + const char *name, + unsigned int rd_count, + const struct GNUNET_GNSRECORD_Data *rd) +{ + static int returned_records; + static int fail = GNUNET_NO; + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Comparing results name %s\n", + name); + if (0 != GNUNET_memcmp (zone_key, + &privkey)) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Monitoring returned wrong zone key\n"); + GNUNET_break (0); + GNUNET_SCHEDULER_cancel (endbadly_task); + endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); + return; + } + + if (0 == strcmp (name, s_name_1)) + { + if (GNUNET_YES != GNUNET_GNSRECORD_records_cmp (rd, s_rd_1)) + { + GNUNET_break (0); + fail = GNUNET_YES; + } + } + else if (0 == strcmp (name, s_name_2)) + { + if (GNUNET_YES != GNUNET_GNSRECORD_records_cmp (rd, s_rd_2)) + { + GNUNET_break (0); + fail = GNUNET_YES; + } + } + else + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Invalid name %s\n", + name); + GNUNET_break (0); + fail = GNUNET_YES; + } + GNUNET_NAMESTORE_zone_monitor_next (zm, + 1); + if (2 == ++returned_records) + { + if (endbadly_task != NULL) + { + GNUNET_SCHEDULER_cancel (endbadly_task); + endbadly_task = NULL; + } + if (GNUNET_YES == fail) + GNUNET_SCHEDULER_add_now (&endbadly, NULL); + else + GNUNET_SCHEDULER_add_now (&end, NULL); + } +} + + +static void +put_cont (void *cls, + enum GNUNET_ErrorCode ec) +{ + static int c = 0; + char *label = cls; + + if (0 == strcmp (label, s_name_1)) + ns_ops[0] = NULL; + else if (0 == strcmp (label, s_name_2)) + ns_ops[1] = NULL; + else if (0 == strcmp (label, s_name_3)) + ns_ops[2] = NULL; + + if (GNUNET_EC_NONE == ec) + { + c++; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Created record %u: `%s'\n", + c, + label); + } + else + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Failed to create record `%s'\n", + label); + GNUNET_break (0); + GNUNET_SCHEDULER_cancel (endbadly_task); + endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, + NULL); + } +} + + +static struct GNUNET_GNSRECORD_Data * +create_record (unsigned int count) +{ + struct GNUNET_GNSRECORD_Data *rd; + + rd = GNUNET_new_array (count, + struct GNUNET_GNSRECORD_Data); + for (unsigned int c = 0; c < count; c++) + { + rd[c].expiration_time = GNUNET_TIME_relative_to_absolute ( + GNUNET_TIME_UNIT_HOURS).abs_value_us; + rd[c].record_type = TEST_RECORD_TYPE; + rd[c].data_size = 50; + rd[c].data = GNUNET_malloc (50); + rd[c].flags = 0; + memset ((char *) rd[c].data, 'a', 50); + } + return rd; +} + + +static void +fail_cb (void *cls) +{ + GNUNET_assert (0); +} + + +static void +sync_cb (void *cls) +{ + /* do nothing */ +} + + +static void +run (void *cls, + const struct GNUNET_CONFIGURATION_Handle *cfg, + struct GNUNET_TESTING_Peer *peer) +{ + res = 1; + privkey.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); + GNUNET_CRYPTO_ecdsa_key_create (&privkey.ecdsa_key); + /* Start monitoring */ + zm = GNUNET_NAMESTORE_zone_monitor_start (cfg, + &privkey, + GNUNET_YES, + &fail_cb, + NULL, + &zone_proc, + NULL, + &sync_cb, + NULL); + if (NULL == zm) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Failed to create zone monitor\n"); + GNUNET_break (0); + endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); + return; + } + + endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &endbadly, NULL); + /* Connect to namestore */ + nsh = GNUNET_NAMESTORE_connect (cfg); + if (NULL == nsh) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Connect to namestore\n"); + GNUNET_break (0); + endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); + return; + } + + privkey2.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); + GNUNET_CRYPTO_ecdsa_key_create (&privkey2.ecdsa_key); + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Created record 3\n"); + /* name in different zone */ + GNUNET_asprintf (&s_name_3, "dummy3"); + s_rd_3 = create_record (1); + GNUNET_assert (NULL != (ns_ops[2] = + GNUNET_NAMESTORE_records_store (nsh, + &privkey2, + s_name_3, + 1, + s_rd_3, + &put_cont, + s_name_3))); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Created record 1\n"); + GNUNET_asprintf (&s_name_1, "dummy1"); + s_rd_1 = create_record (1); + GNUNET_assert (NULL != (ns_ops[0] = + GNUNET_NAMESTORE_records_store (nsh, + &privkey, + s_name_1, + 1, + s_rd_1, + &put_cont, + s_name_1))); + + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 2 \n"); + GNUNET_asprintf (&s_name_2, "dummy2"); + s_rd_2 = create_record (1); + GNUNET_assert (NULL != (ns_ops[1] = + GNUNET_NAMESTORE_records_store (nsh, + &privkey, + s_name_2, + 1, + s_rd_2, + &put_cont, + s_name_2))); +} + + +#include "test_common.c" + + +int +main (int argc, + char *argv[]) +{ + char *plugin_name; + char *cfg_name; + + SETUP_CFG (plugin_name, cfg_name); + res = 1; + if (0 != + GNUNET_TESTING_peer_run ("test-namestore-api-monitoring", + cfg_name, + &run, + NULL)) + { + res = 1; + } + GNUNET_DISK_purge_cfg_dir (cfg_name, + "GNUNET_TEST_HOME"); + GNUNET_free (plugin_name); + GNUNET_free (cfg_name); + return res; +} + + +/* end of test_namestore_api_monitoring.c */ diff --git a/src/service/namestore/test_namestore_api_monitoring_existing.c b/src/service/namestore/test_namestore_api_monitoring_existing.c @@ -0,0 +1,393 @@ +/* + This file is part of GNUnet. + Copyright (C) 2013, 2018 GNUnet e.V. + + GNUnet is free software: you can redistribute it and/or modify it + under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, + or (at your option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + + SPDX-License-Identifier: AGPL3.0-or-later + */ +/** + * @file namestore/test_namestore_api_monitoring_existing.c + * @brief testcase for zone monitoring functionality: add records first, then monitor + */ +#include "platform.h" +#include "gnunet_namestore_service.h" +#include "gnunet_testing_lib.h" +#include "../service/namestore/namestore.h" + +#define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT + + +#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) + +static const struct GNUNET_CONFIGURATION_Handle *cfg; + +static struct GNUNET_NAMESTORE_Handle *nsh; + +static struct GNUNET_SCHEDULER_Task *endbadly_task; + +static struct GNUNET_CRYPTO_PrivateKey privkey; + +static struct GNUNET_CRYPTO_PrivateKey privkey2; + +static struct GNUNET_NAMESTORE_ZoneMonitor *zm; + +static int res; + +static const char *s_name_1; + +static struct GNUNET_GNSRECORD_Data *s_rd_1; + +static const char *s_name_2; + +static struct GNUNET_GNSRECORD_Data *s_rd_2; + +static const char *s_name_3; + +static struct GNUNET_GNSRECORD_Data *s_rd_3; + +struct GNUNET_NAMESTORE_QueueEntry *ns_ops[3]; + + +/** + * Re-establish the connection to the service. + * + * @param cls handle to use to re-connect. + */ +static void +endbadly (void *cls) +{ + endbadly_task = NULL; + GNUNET_break (0); + GNUNET_SCHEDULER_shutdown (); + res = 1; +} + + +static void +end (void *cls) +{ + if (NULL != zm) + { + GNUNET_NAMESTORE_zone_monitor_stop (zm); + zm = NULL; + } + if (NULL != ns_ops[0]) + { + GNUNET_NAMESTORE_cancel (ns_ops[0]); + ns_ops[0] = NULL; + } + if (NULL != ns_ops[1]) + { + GNUNET_NAMESTORE_cancel (ns_ops[1]); + ns_ops[1] = NULL; + } + if (NULL != ns_ops[2]) + { + GNUNET_NAMESTORE_cancel (ns_ops[2]); + ns_ops[2] = NULL; + } + if (NULL != endbadly_task) + { + GNUNET_SCHEDULER_cancel (endbadly_task); + endbadly_task = NULL; + } + if (NULL != nsh) + { + GNUNET_NAMESTORE_disconnect (nsh); + nsh = NULL; + } + if (NULL != s_rd_1) + { + GNUNET_free_nz ((void *) s_rd_1->data); + GNUNET_free (s_rd_1); + } + if (NULL != s_rd_2) + { + GNUNET_free_nz ((void *) s_rd_2->data); + GNUNET_free (s_rd_2); + } + if (NULL != s_rd_3) + { + GNUNET_free_nz ((void *) s_rd_3->data); + GNUNET_free (s_rd_3); + } +} + + +static void +zone_proc (void *cls, + const struct GNUNET_CRYPTO_PrivateKey *zone_key, + const char *name, + unsigned int rd_count, + const struct GNUNET_GNSRECORD_Data *rd) +{ + static int returned_records; + static int fail = GNUNET_NO; + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Comparing results name %s\n", + name); + if (0 != GNUNET_memcmp (zone_key, + &privkey)) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Monitoring returned wrong zone key\n"); + GNUNET_break (0); + GNUNET_SCHEDULER_shutdown (); + return; + } + + if (0 == strcmp (name, + s_name_1)) + { + if (GNUNET_YES != + GNUNET_GNSRECORD_records_cmp (rd, + s_rd_1)) + { + GNUNET_break (0); + fail = GNUNET_YES; + } + } + else if (0 == strcmp (name, + s_name_2)) + { + if (GNUNET_YES != + GNUNET_GNSRECORD_records_cmp (rd, + s_rd_2)) + { + GNUNET_break (0); + fail = GNUNET_YES; + } + } + else + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Invalid name %s\n", + name); + GNUNET_break (0); + fail = GNUNET_YES; + } + GNUNET_NAMESTORE_zone_monitor_next (zm, + 1); + if (2 == ++returned_records) + { + GNUNET_SCHEDULER_shutdown (); + if (GNUNET_YES == fail) + { + GNUNET_break (0); + res = 1; + } + else + { + res = 0; + } + } +} + + +static void +fail_cb (void *cls) +{ + GNUNET_assert (0); +} + + +static void +sync_cb (void *cls) +{ + /* do nothing */ +} + + +static void +put_cont (void *cls, + enum GNUNET_ErrorCode ec) +{ + static int c = 0; + const char *label = cls; + + if (0 == strcmp (label, + s_name_1)) + ns_ops[0] = NULL; + else if (0 == strcmp (label, + s_name_2)) + ns_ops[1] = NULL; + else if (0 == strcmp (label, + s_name_3)) + ns_ops[2] = NULL; + + if (GNUNET_EC_NONE == ec) + { + c++; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Created record %u: `%s'\n", + c, + label); + } + else + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Failed to created records\n"); + GNUNET_break (0); + res = 1; + GNUNET_SCHEDULER_shutdown (); + return; + } + +} + + +static struct GNUNET_GNSRECORD_Data * +create_record (unsigned int count) +{ + struct GNUNET_GNSRECORD_Data *rd; + + rd = GNUNET_new_array (count, + struct GNUNET_GNSRECORD_Data); + for (unsigned int c = 0; c < count; c++) + { + rd[c].expiration_time = GNUNET_TIME_relative_to_absolute ( + GNUNET_TIME_UNIT_HOURS).abs_value_us; + rd[c].record_type = TEST_RECORD_TYPE; + rd[c].data_size = 50; + rd[c].data = GNUNET_malloc (50); + rd[c].flags = 0; + memset ((char *) rd[c].data, + 'a', + 50); + } + return rd; +} + + +static void +run (void *cls, + const struct GNUNET_CONFIGURATION_Handle *mycfg, + struct GNUNET_TESTING_Peer *peer) +{ + res = 1; + privkey.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); + privkey2.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); + GNUNET_CRYPTO_ecdsa_key_create (&privkey.ecdsa_key); + GNUNET_CRYPTO_ecdsa_key_create (&privkey2.ecdsa_key); + + cfg = mycfg; + GNUNET_SCHEDULER_add_shutdown (&end, + NULL); + endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, + &endbadly, + NULL); + /* Connect to namestore */ + nsh = GNUNET_NAMESTORE_connect (cfg); + if (NULL == nsh) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Connect to namestore failed\n"); + GNUNET_break (0); + endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, + NULL); + return; + } + /* Start monitoring */ + zm = GNUNET_NAMESTORE_zone_monitor_start (cfg, + &privkey, + GNUNET_YES, + &fail_cb, + NULL, + &zone_proc, + NULL, + &sync_cb, + NULL); + if (NULL == zm) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Failed to create zone monitor\n"); + GNUNET_break (0); + res = 1; + GNUNET_SCHEDULER_shutdown (); + return; + } + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Created record 3\n"); + /* name in different zone */ + s_name_3 = "dummy3"; + s_rd_3 = create_record (1); + GNUNET_assert (NULL != (ns_ops[2] = + GNUNET_NAMESTORE_records_store (nsh, + &privkey2, + s_name_3, + 1, + s_rd_3, + &put_cont, + (void *) s_name_3))); + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Created record 1\n"); + s_name_1 = "dummy1"; + s_rd_1 = create_record (1); + GNUNET_assert (NULL != (ns_ops[0] = + GNUNET_NAMESTORE_records_store (nsh, + &privkey, + s_name_1, + 1, + s_rd_1, + &put_cont, + (void *) s_name_1))); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Created record 2 \n"); + s_name_2 = "dummy2"; + s_rd_2 = create_record (1); + GNUNET_assert (NULL != (ns_ops[1] = + GNUNET_NAMESTORE_records_store (nsh, + &privkey, + s_name_2, + 1, + s_rd_2, + &put_cont, + (void *) s_name_2))); +} + + +#include "test_common.c" + + +int +main (int argc, + char *argv[]) +{ + char *plugin_name; + char *cfg_name; + + SETUP_CFG (plugin_name, cfg_name); + res = 1; + if (0 != + GNUNET_TESTING_peer_run ("test-namestore-api-monitoring-existing", + cfg_name, + &run, + NULL)) + { + GNUNET_break (0); + res = 1; + } + GNUNET_DISK_purge_cfg_dir (cfg_name, + "GNUNET_TEST_HOME"); + GNUNET_free (plugin_name); + GNUNET_free (cfg_name); + return res; +} + + +/* end of test_namestore_api_monitoring_existing.c */ diff --git a/src/plugin/namestore/test_namestore_api_postgres.conf b/src/service/namestore/test_namestore_api_postgres.conf diff --git a/src/service/namestore/test_namestore_api_remove.c b/src/service/namestore/test_namestore_api_remove.c @@ -0,0 +1,219 @@ +/* + This file is part of GNUnet. + Copyright (C) 2013 GNUnet e.V. + + GNUnet is free software: you can redistribute it and/or modify it + under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, + or (at your option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + + SPDX-License-Identifier: AGPL3.0-or-later + */ +/** + * @file namestore/test_namestore_api.c + * @brief testcase for namestore_api.c to: remove record + */ +#include "platform.h" +#include "gnunet_namestore_service.h" +#include "gnunet_testing_lib.h" + +#define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT + +#define TEST_RECORD_DATALEN 123 + +#define TEST_RECORD_DATA 'a' + +#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100) + + +static struct GNUNET_NAMESTORE_Handle *nsh; + +static struct GNUNET_SCHEDULER_Task *endbadly_task; + +static struct GNUNET_CRYPTO_PrivateKey privkey; + +static struct GNUNET_CRYPTO_PublicKey pubkey; + +static int res; + +static int removed; + +static struct GNUNET_NAMESTORE_QueueEntry *nsqe; + + +static void +cleanup () +{ + if (NULL != nsh) + { + GNUNET_NAMESTORE_disconnect (nsh); + nsh = NULL; + } + GNUNET_SCHEDULER_shutdown (); +} + + +/** + * Re-establish the connection to the service. + * + * @param cls handle to use to re-connect. + */ +static void +endbadly (void *cls) +{ + if (NULL != nsqe) + { + GNUNET_NAMESTORE_cancel (nsqe); + nsqe = NULL; + } + cleanup (); + res = 1; +} + + +static void +end (void *cls) +{ + cleanup (); + res = 0; +} + + +static void +remove_cont (void *cls, + enum GNUNET_ErrorCode ec) +{ + nsqe = NULL; + if (GNUNET_EC_NONE != ec) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _ ("Records could not be removed: `%s'\n"), + GNUNET_ErrorCode_get_hint (ec)); + if (NULL != endbadly_task) + GNUNET_SCHEDULER_cancel (endbadly_task); + endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, + NULL); + return; + } + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Records were removed, perform lookup\n"); + removed = GNUNET_YES; + if (NULL != endbadly_task) + GNUNET_SCHEDULER_cancel (endbadly_task); + GNUNET_SCHEDULER_add_now (&end, NULL); +} + + +static void +put_cont (void *cls, + enum GNUNET_ErrorCode ec) +{ + const char *name = cls; + + GNUNET_assert (NULL != cls); + nsqe = NULL; + if (GNUNET_EC_NONE != ec) + { + GNUNET_break (0); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Namestore could not store record: `%s'\n", + GNUNET_ErrorCode_get_hint (ec)); + if (endbadly_task != NULL) + GNUNET_SCHEDULER_cancel (endbadly_task); + endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); + return; + } + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Name store added record for `%s': %s\n", + name, + (GNUNET_EC_NONE == ec) ? "SUCCESS" : "FAIL"); + nsqe = GNUNET_NAMESTORE_records_store (nsh, + &privkey, + name, + 0, NULL, + &remove_cont, (void *) name); +} + + +static void +run (void *cls, + const struct GNUNET_CONFIGURATION_Handle *cfg, + struct GNUNET_TESTING_Peer *peer) +{ + struct GNUNET_GNSRECORD_Data rd; + const char *name = "dummy"; + + endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, + &endbadly, + NULL); + privkey.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); + GNUNET_CRYPTO_ecdsa_key_create (&privkey.ecdsa_key); + GNUNET_CRYPTO_key_get_public (&privkey, + &pubkey); + + removed = GNUNET_NO; + + rd.expiration_time = GNUNET_TIME_UNIT_MINUTES.rel_value_us; + rd.record_type = TEST_RECORD_TYPE; + rd.data_size = TEST_RECORD_DATALEN; + rd.data = GNUNET_malloc (TEST_RECORD_DATALEN); + rd.flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; + memset ((char *) rd.data, + 'a', + TEST_RECORD_DATALEN); + + nsh = GNUNET_NAMESTORE_connect (cfg); + GNUNET_break (NULL != nsh); + nsqe = GNUNET_NAMESTORE_records_store (nsh, + &privkey, + name, + 1, + &rd, + &put_cont, + (void *) name); + if (NULL == nsqe) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _ ("Namestore cannot store no block\n")); + } + GNUNET_free_nz ((void *) rd.data); +} + + +#include "test_common.c" + + +int +main (int argc, char *argv[]) +{ + char *plugin_name; + char *cfg_name; + + SETUP_CFG (plugin_name, cfg_name); + res = 1; + if (0 != + GNUNET_TESTING_peer_run ("test-namestore-api-remove", + cfg_name, + &run, + NULL)) + { + res = 1; + } + GNUNET_DISK_purge_cfg_dir (cfg_name, + "GNUNET_TEST_HOME"); + GNUNET_free (plugin_name); + GNUNET_free (cfg_name); + return res; +} + + +/* end of test_namestore_api_remove.c */ diff --git a/src/service/namestore/test_namestore_api_remove_not_existing_record.c b/src/service/namestore/test_namestore_api_remove_not_existing_record.c @@ -0,0 +1,179 @@ +/* + This file is part of GNUnet. + Copyright (C) 2013 GNUnet e.V. + + GNUnet is free software: you can redistribute it and/or modify it + under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, + or (at your option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + + SPDX-License-Identifier: AGPL3.0-or-later + */ +/** + * @file namestore/test_namestore_api_remove_not_existing_record.c + * @brief testcase for namestore_api.c + */ +#include "platform.h" +#include "gnunet_namestore_service.h" +#include "gnunet_testing_lib.h" + +#define TEST_RECORD_TYPE 1234 + +#define TEST_RECORD_DATALEN 123 + +#define TEST_RECORD_DATA 'a' + +#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100) + + +static struct GNUNET_NAMESTORE_Handle *nsh; + +static struct GNUNET_SCHEDULER_Task *endbadly_task; + +static struct GNUNET_CRYPTO_PrivateKey privkey; + +static struct GNUNET_CRYPTO_PublicKey pubkey; + +static int res; + +static struct GNUNET_NAMESTORE_QueueEntry *nsqe; + + +static void +cleanup (void) +{ + if (NULL != nsh) + { + GNUNET_NAMESTORE_disconnect (nsh); + nsh = NULL; + } + GNUNET_SCHEDULER_shutdown (); +} + + +/** + * Re-establish the connection to the service. + * + * @param cls handle to use to re-connect. + */ +static void +endbadly (void *cls) +{ + if (NULL != nsqe) + { + GNUNET_NAMESTORE_cancel (nsqe); + nsqe = NULL; + } + cleanup (); + res = 1; +} + + +static void +end (void *cls) +{ + cleanup (); + res = 0; +} + + +static void +put_cont (void *cls, + enum GNUNET_ErrorCode ec) +{ + GNUNET_assert (NULL != cls); + nsqe = NULL; + if (endbadly_task != NULL) + { + GNUNET_SCHEDULER_cancel (endbadly_task); + endbadly_task = NULL; + } + switch (ec) + { + case GNUNET_EC_NAMESTORE_RECORD_NOT_FOUND: + /* We expect that the record is not found */ + GNUNET_SCHEDULER_add_now (&end, NULL); + break; + + case GNUNET_EC_NONE: + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Namestore could remove non-existing record: `%s'\n", + GNUNET_ErrorCode_get_hint (ec)); + GNUNET_SCHEDULER_add_now (&endbadly, NULL); + break; + + default: + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Namestore failed: `%s'\n", + GNUNET_ErrorCode_get_hint (ec)); + GNUNET_SCHEDULER_add_now (&endbadly, NULL); + break; + } +} + + +static void +run (void *cls, + const struct GNUNET_CONFIGURATION_Handle *cfg, + struct GNUNET_TESTING_Peer *peer) +{ + const char *name = "dummy"; + + endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, + &endbadly, + NULL); + privkey.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); + GNUNET_CRYPTO_ecdsa_key_create (&privkey.ecdsa_key); + GNUNET_CRYPTO_key_get_public (&privkey, &pubkey); + + nsh = GNUNET_NAMESTORE_connect (cfg); + GNUNET_break (NULL != nsh); + nsqe = GNUNET_NAMESTORE_records_store (nsh, + &privkey, + name, + 0, NULL, + &put_cont, (void *) name); + if (NULL == nsqe) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _ ("Namestore cannot store no block\n")); + } +} + + +#include "test_common.c" + + +int +main (int argc, char *argv[]) +{ + char *plugin_name; + char *cfg_name; + + SETUP_CFG (plugin_name, cfg_name); + res = 1; + if (0 != + GNUNET_TESTING_peer_run ("test-namestore-api-remove-non-existing-record", + cfg_name, + &run, + NULL)) + { + res = 1; + } + GNUNET_DISK_purge_cfg_dir (cfg_name, + "GNUNET_TEST_HOME"); + GNUNET_free (plugin_name); + GNUNET_free (cfg_name); + return res; +} + + +/* end of test_namestore_api_remove_not_existing_record.c */ diff --git a/src/plugin/namestore/test_namestore_api_sqlite.conf b/src/service/namestore/test_namestore_api_sqlite.conf diff --git a/src/service/namestore/test_namestore_api_store.c b/src/service/namestore/test_namestore_api_store.c @@ -0,0 +1,172 @@ +/* + This file is part of GNUnet. + Copyright (C) 2012 GNUnet e.V. + + GNUnet is free software: you can redistribute it and/or modify it + under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, + or (at your option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + + SPDX-License-Identifier: AGPL3.0-or-later + */ +/** + * @file namestore/test_namestore_api_store.c + * @brief testcase for namestore_api.c: store a record + */ +#include "platform.h" +#include "gnunet_namestore_service.h" +#include "gnunet_testing_lib.h" + +#define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT + +#define TEST_RECORD_DATALEN 123 + +#define TEST_RECORD_DATA 'a' + +#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100) + + +static struct GNUNET_NAMESTORE_Handle *nsh; + +static struct GNUNET_SCHEDULER_Task *endbadly_task; + +static struct GNUNET_CRYPTO_PrivateKey privkey; + +static struct GNUNET_CRYPTO_PublicKey pubkey; + +static int res; + +static struct GNUNET_NAMESTORE_QueueEntry *nsqe; + + +static void +cleanup () +{ + if (NULL != nsh) + { + GNUNET_NAMESTORE_disconnect (nsh); + nsh = NULL; + } + GNUNET_SCHEDULER_shutdown (); +} + + +/** + * Re-establish the connection to the service. + * + * @param cls handle to use to re-connect. + */ +static void +endbadly (void *cls) +{ + if (NULL != nsqe) + { + GNUNET_NAMESTORE_cancel (nsqe); + nsqe = NULL; + } + cleanup (); + res = 1; +} + + +static void +end (void *cls) +{ + cleanup (); + res = 0; +} + + +static void +put_cont (void *cls, enum GNUNET_ErrorCode ec) +{ + const char *name = cls; + + nsqe = NULL; + GNUNET_assert (NULL != cls); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Name store added record for `%s': %s\n", + name, + (GNUNET_EC_NONE == ec) ? "SUCCESS" : "FAIL"); + GNUNET_SCHEDULER_cancel (endbadly_task); + endbadly_task = NULL; + GNUNET_SCHEDULER_add_now (&end, NULL); +} + + +static void +run (void *cls, + const struct GNUNET_CONFIGURATION_Handle *cfg, + struct GNUNET_TESTING_Peer *peer) +{ + struct GNUNET_GNSRECORD_Data rd; + const char *name = "dummy.dummy.gnunet"; + + endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, + &endbadly, NULL); + privkey.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); + GNUNET_CRYPTO_ecdsa_key_create (&privkey.ecdsa_key); + GNUNET_CRYPTO_key_get_public (&privkey, &pubkey); + + + rd.expiration_time = GNUNET_TIME_absolute_get ().abs_value_us; + rd.record_type = TEST_RECORD_TYPE; + rd.data_size = TEST_RECORD_DATALEN; + rd.data = GNUNET_malloc (TEST_RECORD_DATALEN); + rd.flags = 0; + memset ((char *) rd.data, 'a', TEST_RECORD_DATALEN); + + nsh = GNUNET_NAMESTORE_connect (cfg); + GNUNET_break (NULL != nsh); + nsqe = GNUNET_NAMESTORE_records_store (nsh, + &privkey, + name, + 1, + &rd, + &put_cont, + (void *) name); + if (NULL == nsqe) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _ ("Namestore cannot store no block\n")); + } + GNUNET_free_nz ((void *) rd.data); +} + + +#include "test_common.c" + + +int +main (int argc, char *argv[]) +{ + char *plugin_name; + char *cfg_name; + + SETUP_CFG (plugin_name, cfg_name); + res = 1; + if (0 != + GNUNET_TESTING_peer_run ("test-namestore-api", + cfg_name, + &run, + NULL)) + { + res = 1; + } + GNUNET_DISK_purge_cfg_dir (cfg_name, + "GNUNET_TEST_HOME"); + GNUNET_free (plugin_name); + GNUNET_free (cfg_name); + return res; +} + + +/* end of test_namestore_api_store.c */ diff --git a/src/service/namestore/test_namestore_api_store_update.c b/src/service/namestore/test_namestore_api_store_update.c @@ -0,0 +1,260 @@ +/* + This file is part of GNUnet. + Copyright (C) 2012, 2013, 2018 GNUnet e.V. + + GNUnet is free software: you can redistribute it and/or modify it + under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, + or (at your option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + + SPDX-License-Identifier: AGPL3.0-or-later + */ +/** + * @file namestore/test_namestore_api_store_update.c + * @brief testcase for namestore_api.c: store a record, update it and perform a lookup + * @author Matthias Wachs + * @author Christian Grothoff + */ +#include "platform.h" +#include "gnunet_namestore_service.h" +#include "gnunet_testing_lib.h" + +#define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT + +#define TEST_RECORD_DATALEN 123 + +#define TEST_RECORD_DATA 'a' + +#define TEST_RECORD_DATALEN2 234 + +#define TEST_RECORD_DATA2 'b' + +#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100) + + +static struct GNUNET_NAMESTORE_Handle *nsh; + +static struct GNUNET_SCHEDULER_Task *endbadly_task; + +static struct GNUNET_CRYPTO_PrivateKey privkey; + +static struct GNUNET_CRYPTO_PublicKey pubkey; + +static int res; + +static int update_performed; + +static struct GNUNET_NAMESTORE_QueueEntry *nsqe; + +static const char *name = "dummy"; + + +/** + * Terminate test with error. + * + * @param cls handle to use to re-connect. + */ +static void +endbadly (void *cls) +{ + GNUNET_break (0); + endbadly_task = NULL; + GNUNET_SCHEDULER_shutdown (); + res = 1; +} + + +static void +end (void *cls) +{ + if (NULL != endbadly_task) + { + GNUNET_SCHEDULER_cancel (endbadly_task); + endbadly_task = NULL; + } + if (NULL != nsqe) + { + GNUNET_NAMESTORE_cancel (nsqe); + nsqe = NULL; + } + if (NULL != nsh) + { + GNUNET_NAMESTORE_disconnect (nsh); + nsh = NULL; + } +} + + +static void +put_cont (void *cls, + enum GNUNET_ErrorCode ec); + + +static void +lookup_success (void *cls, + const struct GNUNET_CRYPTO_PrivateKey *zone, + const char* label, + unsigned int rd_count, + const struct GNUNET_GNSRECORD_Data *rd) +{ + struct GNUNET_GNSRECORD_Data rd_new; + + GNUNET_assert (1 == rd_count); + GNUNET_assert (NULL != rd); + nsqe = NULL; + if (GNUNET_NO == update_performed) + { + char rd_cmp_data[TEST_RECORD_DATALEN]; + + memset (rd_cmp_data, + TEST_RECORD_DATA, + TEST_RECORD_DATALEN); + GNUNET_assert (TEST_RECORD_TYPE == rd[0].record_type); + GNUNET_assert (TEST_RECORD_DATALEN == rd[0].data_size); + GNUNET_assert (0 == memcmp (&rd_cmp_data, + rd[0].data, + TEST_RECORD_DATALEN)); + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Block was decrypted successfully, updating record \n"); + + rd_new.flags = GNUNET_GNSRECORD_RF_NONE; + rd_new.expiration_time = GNUNET_TIME_absolute_get ().abs_value_us + + 1000000000; + rd_new.record_type = TEST_RECORD_TYPE; + rd_new.data_size = TEST_RECORD_DATALEN2; + rd_new.data = GNUNET_malloc (TEST_RECORD_DATALEN2); + memset ((char *) rd_new.data, + TEST_RECORD_DATA2, + TEST_RECORD_DATALEN2); + + nsqe = GNUNET_NAMESTORE_records_store (nsh, + &privkey, + name, + 1, + &rd_new, + &put_cont, + (void *) name); + GNUNET_free_nz ((void*) rd_new.data); + update_performed = GNUNET_YES; + } + else + { + char rd_cmp_data[TEST_RECORD_DATALEN2]; + + memset (rd_cmp_data, + TEST_RECORD_DATA2, + TEST_RECORD_DATALEN2); + GNUNET_assert (TEST_RECORD_TYPE == rd[0].record_type); + GNUNET_assert (TEST_RECORD_DATALEN2 == rd[0].data_size); + GNUNET_assert (0 == memcmp (&rd_cmp_data, + rd[0].data, + TEST_RECORD_DATALEN2)); + GNUNET_SCHEDULER_shutdown (); + res = 0; + } +} + + +static void +put_cont (void *cls, + enum GNUNET_ErrorCode ec) +{ + nsqe = NULL; + GNUNET_assert (NULL != cls); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Name store added record for `%s': %s\n", + name, + (GNUNET_EC_NONE == ec) ? "SUCCESS" : "FAIL"); + nsqe = GNUNET_NAMESTORE_records_lookup (nsh, + &privkey, + name, + &endbadly, + (void *) name, + & lookup_success, + (void *) name); +} + + +static void +run (void *cls, + const struct GNUNET_CONFIGURATION_Handle *cfg, + struct GNUNET_TESTING_Peer *peer) +{ + struct GNUNET_GNSRECORD_Data rd; + + update_performed = GNUNET_NO; + GNUNET_SCHEDULER_add_shutdown (&end, + NULL); + endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, + &endbadly, + NULL); + memset (&privkey, 0, sizeof (privkey)); + privkey.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); + GNUNET_CRYPTO_ecdsa_key_create (&privkey.ecdsa_key); + GNUNET_CRYPTO_key_get_public (&privkey, &pubkey); + rd.flags = GNUNET_GNSRECORD_RF_NONE; + rd.expiration_time = GNUNET_TIME_absolute_get ().abs_value_us + 1000000000; + rd.record_type = TEST_RECORD_TYPE; + rd.data_size = TEST_RECORD_DATALEN; + rd.data = GNUNET_malloc (TEST_RECORD_DATALEN); + memset ((char *) rd.data, + TEST_RECORD_DATA, + TEST_RECORD_DATALEN); + + nsh = GNUNET_NAMESTORE_connect (cfg); + GNUNET_break (NULL != nsh); + + nsqe = GNUNET_NAMESTORE_records_store (nsh, + &privkey, + name, + 1, + &rd, + &put_cont, + (void *) name); + if (NULL == nsqe) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _ ("Namestore cannot store no block\n")); + } + GNUNET_free_nz ((void *) rd.data); +} + + +#include "test_common.c" + + +int +main (int argc, + char *argv[]) +{ + char *plugin_name; + char *cfg_name; + + SETUP_CFG (plugin_name, cfg_name); + res = 1; + if (0 != + GNUNET_TESTING_peer_run ("test-namestore-store-update", + cfg_name, + &run, + NULL)) + { + res = 1; + } + GNUNET_DISK_purge_cfg_dir (cfg_name, + "GNUNET_TEST_HOME"); + GNUNET_free (plugin_name); + GNUNET_free (cfg_name); + return res; +} + + +/* end of test_namestore_api_store_update.c */ diff --git a/src/service/namestore/test_namestore_api_tx_rollback.c b/src/service/namestore/test_namestore_api_tx_rollback.c @@ -0,0 +1,264 @@ +/* + This file is part of GNUnet. + Copyright (C) 2022 GNUnet e.V. + + GNUnet is free software: you can redistribute it and/or modify it + under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, + or (at your option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + + SPDX-License-Identifier: AGPL3.0-or-later + */ +/** + * @file namestore/test_namestore_api_tx_rollback.c + * @brief testcase for namestore_api_tx_rollback.c to: rollback changes in TX + */ +#include "platform.h" +#include "gnunet_namestore_service.h" +#include "gnunet_testing_lib.h" + +#define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT + +#define TEST_RECORD_DATALEN 123 + +#define TEST_RECORD_DATA 'a' + +#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100) + + +static struct GNUNET_NAMESTORE_Handle *nsh; + +static struct GNUNET_SCHEDULER_Task *endbadly_task; + +static struct GNUNET_CRYPTO_PrivateKey privkey; + +static struct GNUNET_CRYPTO_PublicKey pubkey; + +static int res; + +static int removed; + +static struct GNUNET_NAMESTORE_QueueEntry *nsqe; + + +static void +cleanup () +{ + if (NULL != nsh) + { + GNUNET_NAMESTORE_disconnect (nsh); + nsh = NULL; + } + GNUNET_SCHEDULER_shutdown (); +} + + +/** + * Re-establish the connection to the service. + * + * @param cls handle to use to re-connect. + */ +static void +endbadly (void *cls) +{ + if (NULL != nsqe) + { + GNUNET_NAMESTORE_cancel (nsqe); + nsqe = NULL; + } + cleanup (); + res = 1; +} + + +static void +end (void *cls) +{ + cleanup (); + res = 0; +} + +static void +lookup_it (void *cls, + const struct GNUNET_CRYPTO_PrivateKey *zone, + const char *label, + unsigned int rd_count, + const struct GNUNET_GNSRECORD_Data *rd) +{ + GNUNET_assert (0 == rd_count); + GNUNET_SCHEDULER_add_now (&end, NULL); +} + +static void +fail_cb (void *cls) +{ + GNUNET_assert (0); +} + +static void +remove_cont (void *cls, + enum GNUNET_ErrorCode ec) +{ + nsqe = NULL; + if (GNUNET_EC_NONE != ec) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _ ("Unable to roll back: `%s'\n"), + GNUNET_ErrorCode_get_hint (ec)); + if (NULL != endbadly_task) + GNUNET_SCHEDULER_cancel (endbadly_task); + endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, + NULL); + return; + } + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Rolled back, perform lookup\n"); + removed = GNUNET_YES; + if (NULL != endbadly_task) + GNUNET_SCHEDULER_cancel (endbadly_task); + /* FIXME not actually doing lookup here */ + nsqe = GNUNET_NAMESTORE_records_lookup (nsh, + &privkey, + (char*) cls, + &fail_cb, + NULL, + &lookup_it, + NULL); +} + + +static void +put_cont (void *cls, + enum GNUNET_ErrorCode ec) +{ + const char *name = cls; + + GNUNET_assert (NULL != cls); + nsqe = NULL; + if (GNUNET_EC_NONE != ec) + { + GNUNET_break (0); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Namestore could not store record: `%s'\n", + GNUNET_ErrorCode_get_hint (ec)); + if (endbadly_task != NULL) + GNUNET_SCHEDULER_cancel (endbadly_task); + endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); + return; + } + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Name store added record for `%s': %s\n", + name, + (GNUNET_EC_NONE == ec) ? "SUCCESS" : "FAIL"); + nsqe = GNUNET_NAMESTORE_transaction_rollback (nsh, remove_cont, + (void *) name); +} + +static void +begin_cont (void *cls, + enum GNUNET_ErrorCode ec) +{ + struct GNUNET_GNSRECORD_Data rd; + const char *name = cls; + + GNUNET_assert (GNUNET_EC_NONE == ec); + privkey.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); + GNUNET_CRYPTO_ecdsa_key_create (&privkey.ecdsa_key); + GNUNET_CRYPTO_key_get_public (&privkey, + &pubkey); + + removed = GNUNET_NO; + + rd.expiration_time = GNUNET_TIME_absolute_get ().abs_value_us; + rd.record_type = TEST_RECORD_TYPE; + rd.data_size = TEST_RECORD_DATALEN; + rd.data = GNUNET_malloc (TEST_RECORD_DATALEN); + rd.flags = 0; + memset ((char *) rd.data, + 'a', + TEST_RECORD_DATALEN); + nsqe = GNUNET_NAMESTORE_records_store (nsh, + &privkey, + name, + 1, + &rd, + &put_cont, + (void *) name); + GNUNET_assert (NULL != nsqe); + GNUNET_free_nz ((void *) rd.data); +} + +static void +run (void *cls, + const struct GNUNET_CONFIGURATION_Handle *cfg, + struct GNUNET_TESTING_Peer *peer) +{ + const char *name = "dummy"; + + endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, + &endbadly, + NULL); + nsh = GNUNET_NAMESTORE_connect (cfg); + GNUNET_break (NULL != nsh); + nsqe = GNUNET_NAMESTORE_transaction_begin (nsh, begin_cont, (void *) name); + /*nsqe = GNUNET_NAMESTORE_transaction_commit (nsh, commit_cont); + nsqe = GNUNET_NAMESTORE_transaction_rollback (nsh, rollback_cont); Must also happen on disconnect + nsqe = GNUNET_NAMESTORE_records_edit (nsh, + &privkey, + name, + 1, + &rd, + &edit_cont, + (void *) name); + nsqe = GNUNET_NAMESTORE_records_insert_bulk (nsh, + count, + &rd, + & + nsqe = GNUNET_NAMESTORE_records_store (nsh, + &privkey, + name, + 1, + &rd, + &put_cont, + (void *) name);*/ + GNUNET_assert (NULL != nsqe); +} + + +#include "test_common.c" + + +int +main (int argc, char *argv[]) +{ + char *plugin_name; + char *cfg_name; + + SETUP_CFG (plugin_name, cfg_name); + res = 1; + if (0 != + GNUNET_TESTING_peer_run ("test-namestore-api-remove", + cfg_name, + &run, + NULL)) + { + res = 1; + } + GNUNET_DISK_purge_cfg_dir (cfg_name, + "GNUNET_TEST_HOME"); + GNUNET_free (plugin_name); + GNUNET_free (cfg_name); + return res; +} + + +/* end of test_namestore_api_remove.c */ diff --git a/src/service/namestore/test_namestore_api_zone_iteration.c b/src/service/namestore/test_namestore_api_zone_iteration.c @@ -0,0 +1,464 @@ +/* + This file is part of GNUnet. + Copyright (C) 2013, 2018 GNUnet e.V. + + GNUnet is free software: you can redistribute it and/or modify it + under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, + or (at your option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + + SPDX-License-Identifier: AGPL3.0-or-later + */ +/** + * @file namestore/test_namestore_api_zone_iteration.c + * @brief testcase for zone iteration functionality: iterate all zones + */ +#include "platform.h" +#include "gnunet_namestore_service.h" +#include "gnunet_testing_lib.h" +#include "../service/namestore/namestore.h" + +#define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT + + +#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100) + + +static struct GNUNET_NAMESTORE_Handle *nsh; + +static struct GNUNET_SCHEDULER_Task *endbadly_task; + +static struct GNUNET_CRYPTO_PrivateKey privkey; + +static struct GNUNET_CRYPTO_PrivateKey privkey2; + +static struct GNUNET_NAMESTORE_ZoneIterator *zi; + +static int res; + +static int returned_records; + +static char *s_name_1; + +static struct GNUNET_GNSRECORD_Data *s_rd_1; + +static char *s_name_2; + +static struct GNUNET_GNSRECORD_Data *s_rd_2; + +static char *s_name_3; + +static struct GNUNET_GNSRECORD_Data *s_rd_3; + + +/** + * Re-establish the connection to the service. + * + * @param cls handle to use to re-connect. + * @param tc scheduler context + */ +static void +endbadly (void *cls) +{ + endbadly_task = NULL; + GNUNET_SCHEDULER_shutdown (); + res = 1; +} + + +static void +end (void *cls) +{ + if (NULL != zi) + { + GNUNET_NAMESTORE_zone_iteration_stop (zi); + zi = NULL; + } + if (NULL != endbadly_task) + { + GNUNET_SCHEDULER_cancel (endbadly_task); + endbadly_task = NULL; + } + GNUNET_free (s_name_1); + GNUNET_free (s_name_2); + GNUNET_free (s_name_3); + if (NULL != s_rd_1) + { + GNUNET_free_nz ((void *) s_rd_1->data); + GNUNET_free (s_rd_1); + } + if (NULL != s_rd_2) + { + GNUNET_free_nz ((void *) s_rd_2->data); + GNUNET_free (s_rd_2); + } + if (NULL != s_rd_3) + { + GNUNET_free_nz ((void *) s_rd_3->data); + GNUNET_free (s_rd_3); + } + if (NULL != nsh) + { + GNUNET_NAMESTORE_disconnect (nsh); + nsh = NULL; + } +} + + +static void +zone_end (void *cls) +{ + GNUNET_break (3 == returned_records); + if (3 == returned_records) + { + res = 0; /* Last iteraterator callback, we are done */ + zi = NULL; + } + else + res = 1; + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Received last result, iteration done after receing %u results\n", + returned_records); + GNUNET_SCHEDULER_shutdown (); +} + + +static void +fail_cb (void *cls) +{ + GNUNET_assert (0); +} + + +static void +zone_proc (void *cls, + const struct GNUNET_CRYPTO_PrivateKey *zone, + const char *label, + unsigned int rd_count, + const struct GNUNET_GNSRECORD_Data *rd) +{ + int failed = GNUNET_NO; + + GNUNET_assert (NULL != zone); + if (0 == GNUNET_memcmp (zone, + &privkey)) + { + if (0 == strcmp (label, s_name_1)) + { + if (rd_count == 1) + { + if (GNUNET_YES != GNUNET_GNSRECORD_records_cmp (rd, s_rd_1)) + { + failed = GNUNET_YES; + GNUNET_break (0); + } + } + else + { + failed = GNUNET_YES; + GNUNET_break (0); + } + } + else if (0 == strcmp (label, s_name_2)) + { + if (rd_count == 1) + { + if (GNUNET_YES != GNUNET_GNSRECORD_records_cmp (rd, s_rd_2)) + { + failed = GNUNET_YES; + GNUNET_break (0); + } + } + else + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Received invalid record count\n"); + failed = GNUNET_YES; + GNUNET_break (0); + } + } + else + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Comparing result failed: got name `%s' for first zone\n", + label); + failed = GNUNET_YES; + GNUNET_break (0); + } + } + else if (0 == GNUNET_memcmp (zone, + &privkey2)) + { + if (0 == strcmp (label, s_name_3)) + { + if (rd_count == 1) + { + if (GNUNET_YES != GNUNET_GNSRECORD_records_cmp (rd, s_rd_3)) + { + failed = GNUNET_YES; + GNUNET_break (0); + } + } + else + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Received invalid record count\n"); + failed = GNUNET_YES; + GNUNET_break (0); + } + } + else + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Comparing result failed: got name `%s' for first zone\n", + label); + failed = GNUNET_YES; + GNUNET_break (0); + } + } + else + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Received invalid zone\n"); + failed = GNUNET_YES; + GNUNET_break (0); + } + + if (failed == GNUNET_NO) + { + returned_records++; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Telling namestore to send the next result\n"); + GNUNET_NAMESTORE_zone_iterator_next (zi, + 1); + } + else + { + GNUNET_break (0); + GNUNET_SCHEDULER_shutdown (); + res = 1; + } +} + + +static void +put_cont (void *cls, + enum GNUNET_ErrorCode ec) +{ + static int c = 0; + + if (GNUNET_EC_NONE == ec) + { + c++; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Created record %u \n", + c); + } + else + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Failed to created records: `%s'\n", + GNUNET_ErrorCode_get_hint (ec)); + GNUNET_break (0); + GNUNET_SCHEDULER_shutdown (); + res = 1; + return; + } + + if (c == 3) + { + res = 1; + returned_records = 0; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "All records created, starting iteration over all zones \n"); + zi = GNUNET_NAMESTORE_zone_iteration_start (nsh, + NULL, + &fail_cb, + NULL, + &zone_proc, + NULL, + &zone_end, + NULL); + if (zi == NULL) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Failed to create zone iterator\n"); + GNUNET_break (0); + GNUNET_SCHEDULER_shutdown (); + res = 1; + return; + } + } +} + + +static struct GNUNET_GNSRECORD_Data * +create_record (unsigned int count) +{ + struct GNUNET_GNSRECORD_Data *rd; + + rd = GNUNET_new_array (count, + struct GNUNET_GNSRECORD_Data); + for (unsigned int c = 0; c < count; c++) + { + rd[c].expiration_time = GNUNET_TIME_relative_to_absolute ( + GNUNET_TIME_UNIT_HOURS).abs_value_us; + rd[c].record_type = TEST_RECORD_TYPE; + rd[c].data_size = 50; + rd[c].data = GNUNET_malloc (50); + rd[c].flags = 0; + memset ((char *) rd[c].data, 'a', 50); + } + return rd; +} + + +/** + * Callback called from the zone iterator when we iterate over + * the empty zone. Check that we got no records and then + * start the actual tests by filling the zone. + */ +static void +empty_zone_proc (void *cls, + const struct GNUNET_CRYPTO_PrivateKey *zone, + const char *label, + unsigned int rd_count, + const struct GNUNET_GNSRECORD_Data *rd) +{ + GNUNET_assert (nsh == cls); + if (NULL != zone) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _ ("Expected empty zone but received zone private key\n")); + GNUNET_break (0); + GNUNET_SCHEDULER_shutdown (); + res = 1; + return; + } + if ((NULL != label) || (NULL != rd) || (0 != rd_count)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _ ("Expected no zone content but received data\n")); + GNUNET_break (0); + GNUNET_SCHEDULER_shutdown (); + res = 1; + return; + } + GNUNET_assert (0); +} + + +static void +empty_zone_end (void *cls) +{ + zi = NULL; + privkey.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); + privkey2.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); + GNUNET_CRYPTO_ecdsa_key_create (&privkey.ecdsa_key); + GNUNET_CRYPTO_ecdsa_key_create (&privkey2.ecdsa_key); + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 1\n"); + + GNUNET_asprintf (&s_name_1, "dummy1"); + s_rd_1 = create_record (1); + GNUNET_NAMESTORE_records_store (nsh, + &privkey, + s_name_1, + 1, s_rd_1, + &put_cont, + NULL); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Created record 2 \n"); + GNUNET_asprintf (&s_name_2, "dummy2"); + s_rd_2 = create_record (1); + GNUNET_NAMESTORE_records_store (nsh, + &privkey, + s_name_2, + 1, s_rd_2, + &put_cont, + NULL); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Created record 3\n"); + /* name in different zone */ + GNUNET_asprintf (&s_name_3, "dummy3"); + s_rd_3 = create_record (1); + GNUNET_NAMESTORE_records_store (nsh, + &privkey2, + s_name_3, + 1, + s_rd_3, + &put_cont, + NULL); +} + + +static void +run (void *cls, + const struct GNUNET_CONFIGURATION_Handle *cfg, + struct GNUNET_TESTING_Peer *peer) +{ + endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, + &endbadly, + NULL); + GNUNET_SCHEDULER_add_shutdown (&end, + NULL); + + nsh = GNUNET_NAMESTORE_connect (cfg); + GNUNET_break (NULL != nsh); + /* first, iterate over empty namestore */ + zi = GNUNET_NAMESTORE_zone_iteration_start (nsh, + NULL, + &fail_cb, + NULL, + &empty_zone_proc, + nsh, + &empty_zone_end, + NULL); + if (NULL == zi) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Failed to create zone iterator\n"); + GNUNET_break (0); + res = 1; + GNUNET_SCHEDULER_shutdown (); + } +} + + +#include "test_common.c" + + +int +main (int argc, char *argv[]) +{ + char *plugin_name; + char *cfg_name; + + SETUP_CFG (plugin_name, cfg_name); + res = 1; + if (0 != + GNUNET_TESTING_peer_run ("test-namestore-api-zone-iteration", + cfg_name, + &run, + NULL)) + { + res = 1; + } + GNUNET_DISK_purge_cfg_dir (cfg_name, + "GNUNET_TEST_HOME"); + GNUNET_free (plugin_name); + GNUNET_free (cfg_name); + return res; +} + + +/* end of test_namestore_api_zone_iteration.c */ diff --git a/src/service/namestore/test_namestore_api_zone_iteration_nick.c b/src/service/namestore/test_namestore_api_zone_iteration_nick.c @@ -0,0 +1,460 @@ +/* + This file is part of GNUnet. + Copyright (C) 2013 GNUnet e.V. + + GNUnet is free software: you can redistribute it and/or modify it + under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, + or (at your option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + + SPDX-License-Identifier: AGPL3.0-or-later + */ +/** + * @file namestore/test_namestore_api_zone_iteration.c + * @brief testcase for zone iteration functionality: iterate all zones + */ +#include "platform.h" +#include "gnunet_namestore_service.h" +#include "gnunet_gns_service.h" +#include "gnunet_testing_lib.h" +#include "../service/namestore/namestore.h" + +#define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT + +#define ZONE_NICK_1 "nick1" +#define ZONE_NICK_2 "nick2" + +#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100) + + +static struct GNUNET_NAMESTORE_Handle *nsh; + +static struct GNUNET_CRYPTO_PrivateKey privkey; + +static struct GNUNET_CRYPTO_PrivateKey privkey2; + +static struct GNUNET_NAMESTORE_ZoneIterator *zi; + +static int res; + +static int returned_records; + +static char *s_name_1; + +static struct GNUNET_GNSRECORD_Data *s_rd_1; + +static char *s_name_2; + +static struct GNUNET_GNSRECORD_Data *s_rd_2; + +static char *s_name_3; + +static struct GNUNET_GNSRECORD_Data *s_rd_3; + +static struct GNUNET_NAMESTORE_QueueEntry *nsqe; + + +/** + * Re-establish the connection to the service. + * + * @param cls handle to use to re-connect. + * @param tc scheduler context + */ +static void +end (void *cls) +{ + if (NULL != zi) + { + GNUNET_NAMESTORE_zone_iteration_stop (zi); + zi = NULL; + } + if (nsh != NULL) + { + GNUNET_NAMESTORE_disconnect (nsh); + nsh = NULL; + } + GNUNET_free (s_name_1); + GNUNET_free (s_name_2); + GNUNET_free (s_name_3); + + if (s_rd_1 != NULL) + { + GNUNET_free_nz ((void *) s_rd_1->data); + GNUNET_free (s_rd_1); + } + if (s_rd_2 != NULL) + { + GNUNET_free_nz ((void *) s_rd_2->data); + GNUNET_free (s_rd_2); + } + if (s_rd_3 != NULL) + { + GNUNET_free_nz ((void *) s_rd_3->data); + GNUNET_free (s_rd_3); + } +} + + +static int +check_zone_1 (const char *label, unsigned int rd_count, + const struct GNUNET_GNSRECORD_Data *rd) +{ + for (unsigned int c = 0; c < rd_count; c++) + { + if ((rd[c].record_type == GNUNET_GNSRECORD_TYPE_NICK) && + (0 != strcmp (rd[c].data, ZONE_NICK_1))) + { + GNUNET_break (0); + return GNUNET_YES; + } + } + return GNUNET_NO; +} + + +static int +check_zone_2 (const char *label, + unsigned int rd_count, + const struct GNUNET_GNSRECORD_Data *rd) +{ + for (unsigned int c = 0; c < rd_count; c++) + { + if ((rd[c].record_type == GNUNET_GNSRECORD_TYPE_NICK) && + (0 != strcmp (rd[c].data, ZONE_NICK_2))) + { + GNUNET_break (0); + return GNUNET_YES; + } + } + return GNUNET_NO; +} + + +static void +zone_proc_end (void *cls) +{ + zi = NULL; + res = 0; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Received last result, iteration done after receing %u results\n", + returned_records); + GNUNET_SCHEDULER_shutdown (); +} + + +static void +zone_proc (void *cls, + const struct GNUNET_CRYPTO_PrivateKey *zone, + const char *label, + unsigned int rd_count, + const struct GNUNET_GNSRECORD_Data *rd) +{ + int failed = GNUNET_NO; + + GNUNET_assert (NULL != zone); + if (0 == GNUNET_memcmp (zone, &privkey)) + { + failed = check_zone_1 (label, rd_count, rd); + if (GNUNET_YES == failed) + GNUNET_break (0); + } + else if (0 == GNUNET_memcmp (zone, &privkey2)) + { + failed = check_zone_2 (label, rd_count, rd); + if (GNUNET_YES == failed) + GNUNET_break (0); + } + else + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Received invalid zone\n"); + failed = GNUNET_YES; + GNUNET_break (0); + } + + if (failed == GNUNET_NO) + { + returned_records++; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Telling namestore to send the next result\n"); + GNUNET_NAMESTORE_zone_iterator_next (zi, + 1); + } + else + { + GNUNET_break (0); + res = 1; + GNUNET_SCHEDULER_shutdown (); + } +} + + +static void +fail_cb (void *cls) +{ + GNUNET_assert (0); +} + + +static void +put_cont (void *cls, + enum GNUNET_ErrorCode ec) +{ + static int c = 0; + + if (GNUNET_EC_NONE == ec) + { + c++; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record %u \n", c); + } + else + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to created records: `%s'\n", + GNUNET_ErrorCode_get_hint (ec)); + GNUNET_break (0); + GNUNET_SCHEDULER_shutdown (); + return; + } + + if (c == 3) + { + res = 1; + returned_records = 0; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "All records created, starting iteration over all zones \n"); + zi = GNUNET_NAMESTORE_zone_iteration_start (nsh, + NULL, + &fail_cb, + NULL, + &zone_proc, + NULL, + &zone_proc_end, + NULL); + if (zi == NULL) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create zone iterator\n"); + GNUNET_break (0); + GNUNET_SCHEDULER_shutdown (); + return; + } + } +} + + +static struct GNUNET_GNSRECORD_Data * +create_record (unsigned int count) +{ + struct GNUNET_GNSRECORD_Data *rd; + + rd = GNUNET_new_array (count, + struct GNUNET_GNSRECORD_Data); + for (unsigned int c = 0; c < count; c++) + { + rd[c].expiration_time = GNUNET_TIME_relative_to_absolute ( + GNUNET_TIME_UNIT_HOURS).abs_value_us; + rd[c].record_type = TEST_RECORD_TYPE; + rd[c].data_size = 50; + rd[c].data = GNUNET_malloc (50); + rd[c].flags = 0; + memset ((char *) rd[c].data, 'a', 50); + } + return rd; +} + + +static void +nick_2_cont (void *cls, + enum GNUNET_ErrorCode ec) +{ + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Nick added : %s\n", + (GNUNET_EC_NONE == ec) ? "SUCCESS" : "FAIL"); + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 1\n"); + + GNUNET_asprintf (&s_name_1, "dummy1"); + s_rd_1 = create_record (1); + GNUNET_NAMESTORE_records_store (nsh, &privkey, s_name_1, + 1, s_rd_1, + &put_cont, NULL); + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Created record 2 \n"); + GNUNET_asprintf (&s_name_2, "dummy2"); + s_rd_2 = create_record (1); + GNUNET_NAMESTORE_records_store (nsh, &privkey, s_name_2, + 1, s_rd_2, &put_cont, NULL); + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Created record 3\n"); + + /* name in different zone */ + GNUNET_asprintf (&s_name_3, "dummy3"); + s_rd_3 = create_record (1); + GNUNET_NAMESTORE_records_store (nsh, &privkey2, s_name_3, + 1, s_rd_3, + &put_cont, NULL); +} + + +static void +nick_1_cont (void *cls, enum GNUNET_ErrorCode ec) +{ + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Nick 1 added : %s\n", + (GNUNET_EC_NONE == ec) ? "SUCCESS" : "FAIL"); + struct GNUNET_GNSRECORD_Data rd; + + memset (&rd, 0, sizeof(rd)); + rd.data = ZONE_NICK_2; + rd.data_size = strlen (ZONE_NICK_2) + 1; + rd.record_type = GNUNET_GNSRECORD_TYPE_NICK; + rd.expiration_time = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us; + rd.flags |= GNUNET_GNSRECORD_RF_PRIVATE; + nsqe = GNUNET_NAMESTORE_records_store (nsh, + &privkey2, + GNUNET_GNS_EMPTY_LABEL_AT, + 1, + &rd, + &nick_2_cont, + &privkey2); + + if (NULL == nsqe) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _ ("Namestore cannot store no block\n")); + } +} + + +/** + * Callback called from the zone iterator when we iterate over + * the empty zone. Check that we got no records and then + * start the actual tests by filling the zone. + */ +static void +empty_zone_proc (void *cls, + const struct GNUNET_CRYPTO_PrivateKey *zone, + const char *label, + unsigned int rd_count, + const struct GNUNET_GNSRECORD_Data *rd) +{ + GNUNET_assert (nsh == cls); + + if (NULL != zone) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _ ("Expected empty zone but received zone private key\n")); + GNUNET_break (0); + GNUNET_SCHEDULER_shutdown (); + return; + } + if ((NULL != label) || (NULL != rd) || (0 != rd_count)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _ ("Expected no zone content but received data\n")); + GNUNET_break (0); + GNUNET_SCHEDULER_shutdown (); + return; + } + GNUNET_assert (0); +} + + +static void +empty_zone_end (void *cls) +{ + GNUNET_assert (nsh == cls); + struct GNUNET_GNSRECORD_Data rd; + + zi = NULL; + privkey.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); + privkey2.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); + GNUNET_CRYPTO_ecdsa_key_create (&privkey.ecdsa_key); + GNUNET_CRYPTO_ecdsa_key_create (&privkey2.ecdsa_key); + + memset (&rd, 0, sizeof(rd)); + rd.data = ZONE_NICK_1; + rd.data_size = strlen (ZONE_NICK_1) + 1; + rd.record_type = GNUNET_GNSRECORD_TYPE_NICK; + rd.expiration_time = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us; + rd.flags |= GNUNET_GNSRECORD_RF_PRIVATE; + nsqe = GNUNET_NAMESTORE_records_store (nsh, + &privkey, + GNUNET_GNS_EMPTY_LABEL_AT, + 1, + &rd, + &nick_1_cont, + NULL); + if (NULL == nsqe) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _ ("Namestore cannot store no block\n")); + } +} + + +static void +run (void *cls, + const struct GNUNET_CONFIGURATION_Handle *cfg, + struct GNUNET_TESTING_Peer *peer) +{ + nsh = GNUNET_NAMESTORE_connect (cfg); + GNUNET_break (NULL != nsh); + GNUNET_SCHEDULER_add_shutdown (&end, + NULL); + /* first, iterate over empty namestore */ + zi = GNUNET_NAMESTORE_zone_iteration_start (nsh, + NULL, + &fail_cb, + NULL, + &empty_zone_proc, + nsh, + &empty_zone_end, + nsh); + if (NULL == zi) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Failed to create zone iterator\n"); + GNUNET_break (0); + GNUNET_SCHEDULER_shutdown (); + } +} + + +#include "test_common.c" + + +int +main (int argc, char *argv[]) +{ + char *plugin_name; + char *cfg_name; + + SETUP_CFG (plugin_name, cfg_name); + res = 1; + if (0 != + GNUNET_TESTING_peer_run ("test-namestore-api-zone-iteration-nick", + cfg_name, + &run, + NULL)) + { + res = 1; + } + GNUNET_DISK_purge_cfg_dir (cfg_name, + "GNUNET_TEST_HOME"); + GNUNET_free (plugin_name); + GNUNET_free (cfg_name); + return res; +} + + +/* end of test_namestore_api_zone_iteration.c */ diff --git a/src/service/namestore/test_namestore_api_zone_iteration_specific_zone.c b/src/service/namestore/test_namestore_api_zone_iteration_specific_zone.c @@ -0,0 +1,447 @@ +/* + This file is part of GNUnet. + Copyright (C) 2013 GNUnet e.V. + + GNUnet is free software: you can redistribute it and/or modify it + under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, + or (at your option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + + SPDX-License-Identifier: AGPL3.0-or-later + */ +/** + * @file namestore/test_namestore_api_zone_iteration_specific_zone.c + * @brief testcase for zone iteration functionality: iterate over a specific zone + * @author Matthias Wachs + */ +#include "platform.h" +#include "gnunet_namestore_service.h" +#include "gnunet_testing_lib.h" +#include "../service/namestore/namestore.h" + +#define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT + + +#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100) + + +static struct GNUNET_NAMESTORE_Handle *nsh; + +static struct GNUNET_SCHEDULER_Task *endbadly_task; + +static struct GNUNET_CRYPTO_PrivateKey privkey; + +static struct GNUNET_CRYPTO_PrivateKey privkey2; + +static struct GNUNET_NAMESTORE_ZoneIterator *zi; + +static int res; + +static int returned_records; + +static char *s_name_1; + +static struct GNUNET_GNSRECORD_Data *s_rd_1; + +static char *s_name_2; + +static struct GNUNET_GNSRECORD_Data *s_rd_2; + +static char *s_name_3; + +static struct GNUNET_GNSRECORD_Data *s_rd_3; + + +/** + * Handle timeout. + * + * @param cls handle to use to re-connect. + */ +static void +endbadly (void *cls) +{ + endbadly_task = NULL; + GNUNET_SCHEDULER_shutdown (); + res = 1; +} + + +static void +end (void *cls) +{ + if (NULL != zi) + { + GNUNET_NAMESTORE_zone_iteration_stop (zi); + zi = NULL; + } + if (NULL != endbadly_task) + { + GNUNET_SCHEDULER_cancel (endbadly_task); + endbadly_task = NULL; + } + GNUNET_free (s_name_1); + GNUNET_free (s_name_2); + GNUNET_free (s_name_3); + if (s_rd_1 != NULL) + { + GNUNET_free_nz ((void *) s_rd_1->data); + GNUNET_free (s_rd_1); + } + if (s_rd_2 != NULL) + { + GNUNET_free_nz ((void *) s_rd_2->data); + GNUNET_free (s_rd_2); + } + if (s_rd_3 != NULL) + { + GNUNET_free_nz ((void *) s_rd_3->data); + GNUNET_free (s_rd_3); + } + if (nsh != NULL) + { + GNUNET_NAMESTORE_disconnect (nsh); + nsh = NULL; + } +} + + +static void +fail_cb (void *cls) +{ + GNUNET_assert (0); + zi = NULL; +} + + +static void +zone_proc (void *cls, + const struct GNUNET_CRYPTO_PrivateKey *zone, + const char *label, + unsigned int rd_count, + const struct GNUNET_GNSRECORD_Data *rd) +{ + int failed = GNUNET_NO; + + GNUNET_assert (NULL != zone); + if (0 == GNUNET_memcmp (zone, + &privkey)) + { + if (0 == strcmp (label, s_name_1)) + { + if (rd_count == 1) + { + if (GNUNET_YES != GNUNET_GNSRECORD_records_cmp (rd, s_rd_1)) + { + failed = GNUNET_YES; + GNUNET_break (0); + } + } + else + { + failed = GNUNET_YES; + GNUNET_break (0); + } + } + else if (0 == strcmp (label, s_name_2)) + { + if (rd_count == 1) + { + if (GNUNET_YES != GNUNET_GNSRECORD_records_cmp (rd, s_rd_2)) + { + failed = GNUNET_YES; + GNUNET_break (0); + } + } + else + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Received invalid record count\n"); + failed = GNUNET_YES; + GNUNET_break (0); + } + } + else + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Comparing result failed: got name `%s' for first zone\n", + label); + failed = GNUNET_YES; + GNUNET_break (0); + } + } + else if (0 == GNUNET_memcmp (zone, &privkey2)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Received data for not requested zone\n"); + failed = GNUNET_YES; + GNUNET_break (0); + } + else + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Received invalid zone\n"); + failed = GNUNET_YES; + GNUNET_break (0); + } + if (failed == GNUNET_NO) + { + returned_records++; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Telling namestore to send the next result\n"); + GNUNET_NAMESTORE_zone_iterator_next (zi, + 1); + } + else + { + GNUNET_break (0); + res = 2; + GNUNET_SCHEDULER_shutdown (); + } +} + + +static void +zone_proc_end (void *cls) +{ + zi = NULL; + GNUNET_break (2 == returned_records); + if (2 == returned_records) + { + res = 0; /* Last iteraterator callback, we are done */ + } + else + { + res = 1; + } + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Received last result, iteration done after receing %u results\n", + returned_records); + GNUNET_SCHEDULER_shutdown (); +} + + +static void +put_cont (void *cls, + enum GNUNET_ErrorCode ec) +{ + static int c = 0; + + if (GNUNET_EC_NONE == ec) + { + c++; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Created record %u \n", c); + } + else + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Failed to created records: `%s'\n", + GNUNET_ErrorCode_get_hint (ec)); + GNUNET_break (0); + res = 2; + GNUNET_SCHEDULER_shutdown (); + return; + } + + if (c == 3) + { + res = 1; + returned_records = 0; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "All records created, starting iteration over all zones \n"); + zi = GNUNET_NAMESTORE_zone_iteration_start (nsh, + &privkey, + &fail_cb, + NULL, + &zone_proc, + NULL, + &zone_proc_end, + NULL); + if (zi == NULL) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Failed to create zone iterator\n"); + GNUNET_break (0); + res = 2; + GNUNET_SCHEDULER_shutdown (); + return; + } + } +} + + +static struct GNUNET_GNSRECORD_Data * +create_record (unsigned int count) +{ + struct GNUNET_GNSRECORD_Data *rd; + + rd = GNUNET_new_array (count, + struct GNUNET_GNSRECORD_Data); + for (unsigned int c = 0; c < count; c++) + { + rd[c].expiration_time = GNUNET_TIME_relative_to_absolute ( + GNUNET_TIME_UNIT_HOURS).abs_value_us; + rd[c].record_type = TEST_RECORD_TYPE; + rd[c].data_size = 50; + rd[c].data = GNUNET_malloc (50); + rd[c].flags = 0; + memset ((char *) rd[c].data, 'a', 50); + } + return rd; +} + + +/** + * Callback called from the zone iterator when we iterate over + * the empty zone. Check that we got no records and then + * start the actual tests by filling the zone. + */ +static void +empty_zone_proc (void *cls, + const struct GNUNET_CRYPTO_PrivateKey *zone, + const char *label, + unsigned int rd_count, + const struct GNUNET_GNSRECORD_Data *rd) +{ + GNUNET_assert (nsh == cls); + if (NULL != zone) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _ ("Expected empty zone but received zone private key\n")); + GNUNET_break (0); + res = 2; + GNUNET_SCHEDULER_shutdown (); + return; + } + if ((NULL != label) || (NULL != rd) || (0 != rd_count)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _ ("Expected no zone content but received data\n")); + GNUNET_break (0); + res = 2; + GNUNET_SCHEDULER_shutdown (); + return; + } + GNUNET_assert (0); +} + + +static void +empty_zone_proc_end (void *cls) +{ + zi = NULL; + privkey.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); + privkey2.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); + GNUNET_CRYPTO_ecdsa_key_create (&privkey.ecdsa_key); + GNUNET_CRYPTO_ecdsa_key_create (&privkey2.ecdsa_key); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Created record 1\n"); + GNUNET_asprintf (&s_name_1, + "dummy1"); + s_rd_1 = create_record (1); + GNUNET_NAMESTORE_records_store (nsh, + &privkey, + s_name_1, + 1, + s_rd_1, + &put_cont, + NULL); + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Created record 2 \n"); + GNUNET_asprintf (&s_name_2, + "dummy2"); + s_rd_2 = create_record (1); + GNUNET_NAMESTORE_records_store (nsh, + &privkey, + s_name_2, + 1, + s_rd_2, + &put_cont, + NULL); + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Created record 3\n"); + + /* name in different zone */ + GNUNET_asprintf (&s_name_3, + "dummy3"); + s_rd_3 = create_record (1); + GNUNET_NAMESTORE_records_store (nsh, + &privkey2, + s_name_3, + 1, s_rd_3, + &put_cont, + NULL); +} + + +static void +run (void *cls, + const struct GNUNET_CONFIGURATION_Handle *cfg, + struct GNUNET_TESTING_Peer *peer) +{ + GNUNET_SCHEDULER_add_shutdown (&end, + NULL); + endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, + &endbadly, + NULL); + nsh = GNUNET_NAMESTORE_connect (cfg); + GNUNET_break (NULL != nsh); + /* first, iterate over empty namestore */ + zi = GNUNET_NAMESTORE_zone_iteration_start (nsh, + NULL, + &fail_cb, + NULL, + &empty_zone_proc, + nsh, + &empty_zone_proc_end, + nsh); + if (NULL == zi) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Failed to create zone iterator\n"); + GNUNET_break (0); + GNUNET_SCHEDULER_shutdown (); + } +} + + +#include "test_common.c" + + +int +main (int argc, char *argv[]) +{ + char *plugin_name; + char *cfg_name; + + SETUP_CFG (plugin_name, cfg_name); + res = 1; + if (0 != + GNUNET_TESTING_peer_run ( + "test-namestore-api-zone-iteration-specific-zone", + cfg_name, + &run, + NULL)) + { + res = 1; + } + GNUNET_DISK_purge_cfg_dir (cfg_name, + "GNUNET_TEST_HOME"); + GNUNET_free (plugin_name); + GNUNET_free (cfg_name); + return res; +} + + +/* end of test_namestore_api_zone_iteration_specific_zone.c */ diff --git a/src/service/namestore/test_namestore_api_zone_iteration_stop.c b/src/service/namestore/test_namestore_api_zone_iteration_stop.c @@ -0,0 +1,449 @@ +/* + This file is part of GNUnet. + Copyright (C) 2009 GNUnet e.V. + + GNUnet is free software: you can redistribute it and/or modify it + under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, + or (at your option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + + SPDX-License-Identifier: AGPL3.0-or-later + */ +/** + * @file namestore/test_namestore_api_zone_iteration_stop.c + * @brief testcase for zone iteration functionality: stop iterating of zones + */ +#include "platform.h" +#include "gnunet_namestore_service.h" +#include "gnunet_testing_lib.h" +#include "../service/namestore/namestore.h" + +#define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT + +#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100) +#define WAIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2) + +static struct GNUNET_NAMESTORE_Handle *nsh; + +static struct GNUNET_CRYPTO_PrivateKey privkey; + +static struct GNUNET_CRYPTO_PrivateKey privkey2; + +static struct GNUNET_NAMESTORE_ZoneIterator *zi; + +static int res; + +static int returned_records; + +static char *s_name_1; + +static struct GNUNET_GNSRECORD_Data *s_rd_1; + +static char *s_name_2; + +static struct GNUNET_GNSRECORD_Data *s_rd_2; + +static char *s_name_3; + +static struct GNUNET_GNSRECORD_Data *s_rd_3; + + +/** + * Re-establish the connection to the service. + * + * @param cls handle to use to re-connect. + */ +static void +end (void *cls) +{ + if (NULL != zi) + { + GNUNET_NAMESTORE_zone_iteration_stop (zi); + zi = NULL; + } + if (nsh != NULL) + { + GNUNET_NAMESTORE_disconnect (nsh); + nsh = NULL; + } + GNUNET_free (s_name_1); + GNUNET_free (s_name_2); + GNUNET_free (s_name_3); + if (s_rd_1 != NULL) + { + GNUNET_free_nz ((void *) s_rd_1->data); + GNUNET_free (s_rd_1); + } + if (s_rd_2 != NULL) + { + GNUNET_free_nz ((void *) s_rd_2->data); + GNUNET_free (s_rd_2); + } + if (s_rd_3 != NULL) + { + GNUNET_free_nz ((void *) s_rd_3->data); + GNUNET_free (s_rd_3); + } +} + + +static void +delayed_end (void *cls) +{ + GNUNET_SCHEDULER_shutdown (); +} + + +static void +fail_cb (void *cls) +{ + GNUNET_assert (0); +} + + +static void +zone_proc (void *cls, + const struct GNUNET_CRYPTO_PrivateKey *zone, + const char *label, + unsigned int rd_count, + const struct GNUNET_GNSRECORD_Data *rd) +{ + int failed = GNUNET_NO; + + GNUNET_assert (NULL != zone); + if (0 == GNUNET_memcmp (zone, &privkey)) + { + if (0 == strcmp (label, s_name_1)) + { + if (rd_count == 1) + { + if (GNUNET_YES != GNUNET_GNSRECORD_records_cmp (rd, s_rd_1)) + { + failed = GNUNET_YES; + GNUNET_break (0); + } + } + else + { + failed = GNUNET_YES; + GNUNET_break (0); + } + } + else if (0 == strcmp (label, s_name_2)) + { + if (rd_count == 1) + { + if (GNUNET_YES != GNUNET_GNSRECORD_records_cmp (rd, s_rd_2)) + { + failed = GNUNET_YES; + GNUNET_break (0); + } + } + else + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Received invalid record count\n"); + failed = GNUNET_YES; + GNUNET_break (0); + } + } + else + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Comparing result failed: got name `%s' for first zone\n", + label); + failed = GNUNET_YES; + GNUNET_break (0); + } + } + else if (0 == GNUNET_memcmp (zone, &privkey2)) + { + if (0 == strcmp (label, s_name_3)) + { + if (rd_count == 1) + { + if (GNUNET_YES != GNUNET_GNSRECORD_records_cmp (rd, s_rd_3)) + { + failed = GNUNET_YES; + GNUNET_break (0); + } + } + else + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Received invalid record count\n"); + failed = GNUNET_YES; + GNUNET_break (0); + } + } + else + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Comparing result failed: got name `%s' for first zone\n", + label); + failed = GNUNET_YES; + GNUNET_break (0); + } + } + else + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Received invalid zone\n"); + failed = GNUNET_YES; + GNUNET_break (0); + } + if (failed == GNUNET_NO) + { + if (1 == returned_records) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Telling namestore to stop zone iteration\n"); + GNUNET_NAMESTORE_zone_iteration_stop (zi); + zi = NULL; + res = 0; + GNUNET_SCHEDULER_add_delayed (WAIT, + &delayed_end, + NULL); + return; + } + returned_records++; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Telling namestore to send the next result\n"); + GNUNET_NAMESTORE_zone_iterator_next (zi, + 1); + } + else + { + GNUNET_break (0); + GNUNET_SCHEDULER_shutdown (); + } +} + + +static void +zone_proc_end (void *cls) +{ + GNUNET_break (1 <= returned_records); + if (1 >= returned_records) + res = 1; /* Last iteraterator callback, we are done */ + else + res = 0; + zi = NULL; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Received last result, iteration done after receing %u results\n", + returned_records); + GNUNET_SCHEDULER_add_now (&end, NULL); +} + + +static void +put_cont (void *cls, enum GNUNET_ErrorCode ec) +{ + static int c = 0; + + if (GNUNET_EC_NONE == ec) + { + c++; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record %u \n", c); + } + else + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to created records: `%s'\n", + GNUNET_ErrorCode_get_hint (ec)); + GNUNET_break (0); + GNUNET_SCHEDULER_shutdown (); + return; + } + + if (c == 3) + { + res = 1; + returned_records = 0; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "All records created, starting iteration over all zones \n"); + zi = GNUNET_NAMESTORE_zone_iteration_start (nsh, + NULL, + &fail_cb, + NULL, + &zone_proc, + NULL, + &zone_proc_end, + NULL); + if (zi == NULL) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Failed to create zone iterator\n"); + GNUNET_break (0); + GNUNET_SCHEDULER_shutdown (); + return; + } + } +} + + +static struct GNUNET_GNSRECORD_Data * +create_record (unsigned int count) +{ + struct GNUNET_GNSRECORD_Data *rd; + + rd = GNUNET_new_array (count, + struct GNUNET_GNSRECORD_Data); + for (unsigned int c = 0; c < count; c++) + { + rd[c].expiration_time = GNUNET_TIME_relative_to_absolute ( + GNUNET_TIME_UNIT_HOURS).abs_value_us; + rd[c].record_type = TEST_RECORD_TYPE; + rd[c].data_size = 50; + rd[c].data = GNUNET_malloc (50); + rd[c].flags = 0; + memset ((char *) rd[c].data, 'a', 50); + } + return rd; +} + + +/** + * Callback called from the zone iterator when we iterate over + * the empty zone. Check that we got no records and then + * start the actual tests by filling the zone. + */ +static void +empty_zone_proc (void *cls, + const struct GNUNET_CRYPTO_PrivateKey *zone, + const char *label, + unsigned int rd_count, + const struct GNUNET_GNSRECORD_Data *rd) +{ + GNUNET_assert (nsh == cls); + if (NULL != zone) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _ ("Expected empty zone but received zone private key\n")); + GNUNET_break (0); + GNUNET_SCHEDULER_shutdown (); + return; + } + if ((NULL != label) || (NULL != rd) || (0 != rd_count)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _ ("Expected no zone content but received data\n")); + GNUNET_break (0); + GNUNET_SCHEDULER_shutdown (); + return; + } + GNUNET_assert (0); +} + + +static void +empty_zone_proc_end (void *cls) +{ + GNUNET_assert (nsh == cls); + zi = NULL; + privkey.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); + privkey2.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); + GNUNET_CRYPTO_ecdsa_key_create (&privkey.ecdsa_key); + GNUNET_CRYPTO_ecdsa_key_create (&privkey2.ecdsa_key); + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Created record 1\n"); + + GNUNET_asprintf (&s_name_1, + "dummy1"); + s_rd_1 = create_record (1); + GNUNET_NAMESTORE_records_store (nsh, + &privkey, s_name_1, + 1, s_rd_1, &put_cont, NULL); + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Created record 2 \n"); + GNUNET_asprintf (&s_name_2, + "dummy2"); + s_rd_2 = create_record (1); + GNUNET_NAMESTORE_records_store (nsh, + &privkey, + s_name_2, + 1, + s_rd_2, + &put_cont, NULL); + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Created record 3\n"); + + /* name in different zone */ + GNUNET_asprintf (&s_name_3, "dummy3"); + s_rd_3 = create_record (1); + GNUNET_NAMESTORE_records_store (nsh, + &privkey2, + s_name_3, + 1, + s_rd_3, + &put_cont, NULL); +} + + +static void +run (void *cls, + const struct GNUNET_CONFIGURATION_Handle *cfg, + struct GNUNET_TESTING_Peer *peer) +{ + nsh = GNUNET_NAMESTORE_connect (cfg); + GNUNET_break (NULL != nsh); + GNUNET_SCHEDULER_add_shutdown (&end, + NULL); + /* first, iterate over empty namestore */ + zi = GNUNET_NAMESTORE_zone_iteration_start (nsh, + NULL, + &fail_cb, + NULL, + &empty_zone_proc, + nsh, + &empty_zone_proc_end, + nsh); + if (NULL == zi) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Failed to create zone iterator\n"); + GNUNET_break (0); + GNUNET_SCHEDULER_shutdown (); + } +} + + +#include "test_common.c" + + +int +main (int argc, char *argv[]) +{ + char *plugin_name; + char *cfg_name; + + SETUP_CFG (plugin_name, cfg_name); + res = 1; + if (0 != + GNUNET_TESTING_peer_run ("test-namestore-api-zone-iteration-stop", + cfg_name, + &run, + NULL)) + { + res = 1; + } + GNUNET_DISK_purge_cfg_dir (cfg_name, + "GNUNET_TEST_HOME"); + GNUNET_free (plugin_name); + GNUNET_free (cfg_name); + + return res; +} + + +/* end of test_namestore_api_zone_iteration_stop.c */ diff --git a/src/service/namestore/test_namestore_api_zone_to_name.c b/src/service/namestore/test_namestore_api_zone_to_name.c @@ -0,0 +1,266 @@ +/* + This file is part of GNUnet. + Copyright (C) 2009 GNUnet e.V. + + GNUnet is free software: you can redistribute it and/or modify it + under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, + or (at your option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + + SPDX-License-Identifier: AGPL3.0-or-later + */ +/** + * @file namestore/test_namestore_api_zone_to_name.c + * @brief testcase for zone to name translation + */ +#include "platform.h" +#include "gnunet_namestore_service.h" +#include "gnunet_testing_lib.h" +#include "../service/namestore/namestore.h" + +#define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT + +#define RECORDS 5 + +#define TEST_RECORD_DATALEN 123 + +#define TEST_RECORD_DATA 'a' + +#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100) + + +static struct GNUNET_NAMESTORE_Handle *nsh; + +static struct GNUNET_SCHEDULER_Task *endbadly_task; + +static struct GNUNET_CRYPTO_PrivateKey privkey; + +static struct GNUNET_CRYPTO_PublicKey pubkey; + +static struct GNUNET_CRYPTO_PublicKey s_zone_value; + +static char *s_name; + +static int res; + +static struct GNUNET_NAMESTORE_QueueEntry *qe; + + +/** + * Re-establish the connection to the service. + * + * @param cls handle to use to re-connect. + */ +static void +endbadly (void *cls) +{ + (void) cls; + GNUNET_SCHEDULER_shutdown (); + res = 1; +} + + +static void +end (void *cls) +{ + if (NULL != qe) + { + GNUNET_NAMESTORE_cancel (qe); + qe = NULL; + } + if (NULL != endbadly_task) + { + GNUNET_SCHEDULER_cancel (endbadly_task); + endbadly_task = NULL; + } + if (NULL != nsh) + { + GNUNET_NAMESTORE_disconnect (nsh); + nsh = NULL; + } +} + + +static void +zone_to_name_proc (void *cls, + const struct GNUNET_CRYPTO_PrivateKey *zone_key, + const char *n, + unsigned int rd_count, + const struct GNUNET_GNSRECORD_Data *rd) +{ + int fail = GNUNET_NO; + + qe = NULL; + if ((NULL == zone_key) && + (NULL == n) && + (0 == rd_count) && + (NULL == rd)) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "No result found\n"); + res = 1; + } + else + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Result found: `%s'\n", + n); + if ((NULL == n) || + (0 != strcmp (n, + s_name))) + { + fail = GNUNET_YES; + GNUNET_break (0); + } + if (1 != rd_count) + { + fail = GNUNET_YES; + GNUNET_break (0); + } + if ((NULL == zone_key) || + (0 != GNUNET_memcmp (zone_key, + &privkey))) + { + fail = GNUNET_YES; + GNUNET_break (0); + } + if (fail == GNUNET_NO) + res = 0; + else + res = 1; + } + GNUNET_SCHEDULER_add_now (&end, + NULL); +} + + +static void +error_cb (void *cls) +{ + (void) cls; + qe = NULL; + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Not found!\n"); + GNUNET_SCHEDULER_shutdown (); + res = 2; +} + + +static void +put_cont (void *cls, + enum GNUNET_ErrorCode ec) +{ + char *name = cls; + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Name store added record for `%s': %s\n", + name, + (GNUNET_EC_NONE == ec) ? + "SUCCESS" : GNUNET_ErrorCode_get_hint (ec)); + if (GNUNET_EC_NONE == ec) + { + res = 0; + + qe = GNUNET_NAMESTORE_zone_to_name (nsh, + &privkey, + &s_zone_value, + &error_cb, + NULL, + &zone_to_name_proc, + NULL); + } + else + { + res = 1; + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Failed to put records for name `%s'\n", + name); + GNUNET_SCHEDULER_add_now (&end, + NULL); + } +} + + +static void +run (void *cls, + const struct GNUNET_CONFIGURATION_Handle *cfg, + struct GNUNET_TESTING_Peer *peer) +{ + (void) cls; + (void) peer; + endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, + &endbadly, + NULL); + GNUNET_SCHEDULER_add_shutdown (&end, + NULL); + GNUNET_asprintf (&s_name, "dummy"); + privkey.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); + GNUNET_CRYPTO_ecdsa_key_create (&privkey.ecdsa_key); + /* get public key */ + GNUNET_CRYPTO_key_get_public (&privkey, + &pubkey); + + GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, + &s_zone_value, + sizeof(s_zone_value)); + s_zone_value.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); + { + struct GNUNET_GNSRECORD_Data rd; + + rd.expiration_time = GNUNET_TIME_UNIT_HOURS.rel_value_us; + rd.record_type = GNUNET_GNSRECORD_TYPE_PKEY; + rd.data_size = sizeof (s_zone_value.ecdsa_key); + rd.data = &s_zone_value.ecdsa_key; + rd.flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; + + nsh = GNUNET_NAMESTORE_connect (cfg); + GNUNET_break (NULL != nsh); + GNUNET_NAMESTORE_records_store (nsh, + &privkey, + s_name, + 1, + &rd, + &put_cont, + s_name); + } +} + + +#include "test_common.c" + + +int +main (int argc, + char *argv[]) +{ + char *plugin_name; + char *cfg_name; + + (void) argc; + SETUP_CFG (plugin_name, cfg_name); + res = 1; + if (0 != + GNUNET_TESTING_peer_run ("test-namestore-api-zone-to-name", + cfg_name, + &run, + NULL)) + { + res = 1; + } + GNUNET_DISK_purge_cfg_dir (cfg_name, + "GNUNET_TEST_HOME"); + GNUNET_free (plugin_name); + GNUNET_free (cfg_name); + return res; +} + + +/* end of test_namestore_api_zone_to_name.c */ diff --git a/src/service/peerstore/gnunet-service-peerstore.c b/src/service/peerstore/gnunet-service-peerstore.c @@ -157,7 +157,7 @@ static void expire_records_continuation (void *cls, int success) { if (success > 0) - GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%d records expired.\n", success); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%d records expired.\n", success); GNUNET_assert (NULL == expire_task); expire_task = GNUNET_SCHEDULER_add_delayed ( GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, @@ -508,7 +508,7 @@ handle_store (void *cls, const struct StoreRecordMessage *srm) record = PEERSTORE_parse_record_message (srm); GNUNET_log ( - GNUNET_ERROR_TYPE_INFO, + GNUNET_ERROR_TYPE_DEBUG, "Received a store request. Sub system `%s' Peer `%s Key `%s' Options: %u.\n", record->sub_system, GNUNET_i2s (&record->peer), @@ -596,12 +596,18 @@ hosts_directory_scan_callback (void *cls, const char *fullname) } hello = (const struct GNUNET_MessageHeader *) &buffer[0]; builder = GNUNET_HELLO_builder_from_msg (hello); + if (NULL == builder) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Unable to parse HELLO message\n"); + return GNUNET_OK; + } pid = GNUNET_HELLO_builder_get_id (builder); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "store contrib hello for peer %s\n", GNUNET_i2s (pid)); - + if (GNUNET_OK != db->store_record (db->cls, "peerstore", pid, diff --git a/src/service/testing/testing_api_loop.c b/src/service/testing/testing_api_loop.c @@ -45,6 +45,11 @@ struct GNUNET_TESTING_Interpreter const struct GNUNET_HELPER_Handle **helper; /** + * Handle to a send op + */ + struct GNUNET_HELPER_SendHandle *send_handle; + + /** * Size of the array helper. * */ @@ -357,6 +362,11 @@ finish_test (void *cls) GNUNET_SCHEDULER_cancel (is->timeout_task); is->timeout_task = NULL; } + if (NULL != is->send_handle) + { + GNUNET_HELPER_send_cancel (is->send_handle); + is->send_handle = NULL; + } GNUNET_free (is->commands); is->rc (is->rc_cls, is->result); @@ -731,37 +741,6 @@ GNUNET_TESTING_add_netjail_helper (struct GNUNET_TESTING_Interpreter *is, } -/** - * Send Message to netjail nodes. - * - * @param is The interpreter. - * @param global_node_number The netjail node to inform. - * @param header The message to send. - */ -static void -send_message_to_netjail (struct GNUNET_TESTING_Interpreter *is, - unsigned int global_node_number, - struct GNUNET_MessageHeader *header) -{ - const struct GNUNET_HELPER_Handle *helper; - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "send message of type %u to locals\n", - ntohs (header->type)); - helper = is->helper[global_node_number - 1]; - /** - FIXME: This should probably be put into a linked list - inside is and cleaned up at some point. - */ - struct GNUNET_HELPER_SendHandle *sh = GNUNET_HELPER_send ( - (struct GNUNET_HELPER_Handle *) helper, - header, - GNUNET_NO, - &clear_msg, - NULL); -} - - void TST_interpreter_send_barrier_crossable (struct GNUNET_TESTING_Interpreter *is, const char *barrier_name, @@ -780,9 +759,19 @@ TST_interpreter_send_barrier_crossable (struct GNUNET_TESTING_Interpreter *is, adm->header.type = htons (GNUNET_MESSAGE_TYPE_CMDS_HELPER_BARRIER_CROSSABLE); adm->header.size = htons ((uint16_t) msg_length); memcpy (&adm[1], barrier_name, name_len); - send_message_to_netjail (is, - global_node_number, - &adm->header); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "send message of type %u to locals\n", + ntohs (adm->header.type)); + /** + FIXME: This should probably be put into a linked list + inside is and cleaned up at some point. + */ + is->send_handle = GNUNET_HELPER_send ( + (struct GNUNET_HELPER_Handle *) is->helper[global_node_number - 1], + &adm->header, + GNUNET_NO, + &clear_msg, + NULL); GNUNET_free (adm); } diff --git a/src/service/transport/gnunet-service-transport.c b/src/service/transport/gnunet-service-transport.c @@ -5526,6 +5526,15 @@ shc_cont (void *cls, int success) GNUNET_PEERSTORE_STOREOPTION_MULTIPLE, &peerstore_store_own_cb, ale); + if (NULL == ale->sc) + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Failed to store our address `%s' with peerstore\n", + ale->address); + ale->st = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, + &store_pi, + ale); + } } @@ -5543,6 +5552,7 @@ store_pi (void *cls) const char *dash; char *address_uri; char *prefix = GNUNET_HELLO_address_to_prefix (ale->address); + unsigned int add_success; dash = strchr (ale->address, '-'); GNUNET_assert (NULL != dash); @@ -5557,15 +5567,15 @@ store_pi (void *cls) "Storing our address `%s' in peerstore until %s!\n", ale->address, GNUNET_STRINGS_absolute_time_to_string (hello_mono_time)); - if (GNUNET_OK != GNUNET_HELLO_builder_add_address (GST_my_hello, - address_uri)) + add_success = GNUNET_HELLO_builder_add_address (GST_my_hello, + address_uri); + if (GNUNET_OK != add_success) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "Address `%s' invalid\n", - address_uri); + "Storing our address `%s' %s\n", + address_uri, + GNUNET_NO == add_success ? "not done" : "failed"); GNUNET_free (address_uri); - ale->st = - GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &store_pi, ale); return; } // FIXME hello_mono_time used here?? What about expiration in ale? diff --git a/src/service/util/meson.build b/src/service/util/meson.build @@ -19,3 +19,16 @@ executable ('gnunet-service-resolver', include_directories: [incdir, configuration_inc], install: true, install_dir: get_option('libdir') / 'gnunet' / 'libexec') + +testresolverapi = executable ('test_resolver_api', + ['test_resolver_api.c'], + dependencies: [libgnunetutil_dep], + include_directories: [incdir, configuration_inc], + install: false) +configure_file(copy: true, + input: 'test_resolver_api_data.conf', + output: 'test_resolver_api_data.conf') + +test('test_resolver_api', testresolverapi, workdir: meson.current_build_dir(), + suite: 'resolver') + diff --git a/src/service/util/test_resolver_api.c b/src/service/util/test_resolver_api.c @@ -25,7 +25,7 @@ #include "platform.h" #include "gnunet_util_lib.h" #include "gnunet_resolver_service.h" -#include "resolver.h" +#include "../lib/util/resolver.h" static int disable_rootserver_check;