summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlessio Vanni <vannilla@firemail.cc>2021-09-07 14:50:20 +0200
committerAlessio Vanni <vannilla@firemail.cc>2021-09-07 14:50:20 +0200
commit6e1bb6601e21a3329950129b9dc39e05746e3b65 (patch)
treedfc20058c8b430ef37c059ec21c2905168a07084 /src
parent382fc8faaf4ccccd870dc7e746a9f002f3f6cfd1 (diff)
parent3da9cbd621a98c885a0c633ddaec0a84aa8a8e66 (diff)
-Merge branch 'master' into dev/vanni/build-info
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am2
-rw-r--r--src/arm/arm_api.c7
-rw-r--r--src/ats-tests/.gitignore14
-rw-r--r--src/ats-tests/Makefile.am169
-rw-r--r--src/ats-tests/ats-testing-experiment.c820
-rw-r--r--src/ats-tests/ats-testing-log.c979
-rw-r--r--src/ats-tests/ats-testing-preferences.c265
-rw-r--r--src/ats-tests/ats-testing-traffic.c393
-rw-r--r--src/ats-tests/ats-testing.c975
-rw-r--r--src/ats-tests/ats-testing.h757
-rw-r--r--src/ats-tests/experiments/evaluation1_dru_3_peers_1addr_1scope_prop.conf24
-rw-r--r--src/ats-tests/experiments/evaluation1_dru_3_peers_1addr_1scope_prop.exp46
-rw-r--r--src/ats-tests/experiments/send_linear_10_sec.exp30
-rw-r--r--src/ats-tests/experiments/test.exp55
-rw-r--r--src/ats-tests/gnunet-ats-sim.c399
-rw-r--r--src/ats-tests/gnunet-solver-eval.c1025
-rw-r--r--src/ats-tests/gnunet_ats_sim_default.conf6
-rw-r--r--src/ats-tests/perf_ats.c601
-rw-r--r--src/ats-tests/perf_ats.h256
-rw-r--r--src/ats-tests/perf_ats_logging.c780
-rw-r--r--src/ats-tests/perf_ats_proportional_bandwidth.conf4
-rw-r--r--src/ats-tests/perf_ats_proportional_latency.conf4
-rw-r--r--src/ats-tests/perf_ats_proportional_none.conf4
-rw-r--r--src/ats-tests/template_perf_ats.conf52
-rw-r--r--src/block/Makefile.am13
-rw-r--r--src/consensus/Makefile.am1
-rw-r--r--src/conversation/conversation_api.c1
-rw-r--r--src/curl/curl.c51
-rw-r--r--src/datacache/plugin_datacache_postgres.c4
-rw-r--r--src/datacache/plugin_datacache_sqlite.c2
-rw-r--r--src/datastore/datastore_api.c4
-rw-r--r--src/datastore/plugin_datastore_mysql.c2
-rw-r--r--src/datastore/plugin_datastore_postgres.c2
-rw-r--r--src/datastore/plugin_datastore_sqlite.c4
-rw-r--r--src/dht/Makefile.am1
-rw-r--r--src/dht/gnunet-service-dht_neighbours.c12
-rw-r--r--src/dhtu/plugin_dhtu_ip.c67
-rw-r--r--src/dns/Makefile.am6
-rw-r--r--src/fs/Makefile.am5
-rw-r--r--src/gns/gnunet-gns-proxy.c2
-rw-r--r--src/gnsrecord/Makefile.am2
-rw-r--r--src/hostlist/hostlist.conf2
-rw-r--r--src/identity/identity_api.c4
-rw-r--r--src/identity/plugin_rest_identity.c26
-rw-r--r--src/include/Makefile.am2
-rw-r--r--src/include/gnunet_common.h42
-rw-r--r--src/include/gnunet_configuration_lib.h193
-rw-r--r--src/include/gnunet_container_lib.h3
-rw-r--r--src/include/gnunet_curl_lib.h2
-rw-r--r--src/include/gnunet_db_lib.h44
-rw-r--r--src/include/gnunet_disk_lib.h26
-rw-r--r--src/include/gnunet_json_lib.h304
-rw-r--r--src/include/gnunet_messenger_service.h12
-rw-r--r--src/include/gnunet_pq_lib.h125
-rw-r--r--src/include/gnunet_protocols.h7
-rw-r--r--src/include/gnunet_setu_service.h26
-rw-r--r--src/include/gnunet_testbed_ng_service.h284
-rw-r--r--src/include/gnunet_testing_ng_lib.h74
-rw-r--r--src/include/gnunet_testing_plugin.h7
-rw-r--r--src/include/gnunet_util_lib.h3
-rw-r--r--src/include/platform.h34
-rw-r--r--src/json/Makefile.am12
-rw-r--r--src/json/json.c37
-rw-r--r--src/json/json_pack.c325
-rw-r--r--src/messenger/gnunet-messenger.c7
-rw-r--r--src/messenger/gnunet-service-messenger_handle.c32
-rw-r--r--src/messenger/gnunet-service-messenger_member.c1
-rw-r--r--src/messenger/gnunet-service-messenger_room.c1
-rw-r--r--src/namecache/namecache_api.c1
-rw-r--r--src/namestore/Makefile.am4
-rw-r--r--src/namestore/gnunet-namestore-fcfsd.c12
-rw-r--r--src/namestore/plugin_rest_namestore.c6
-rw-r--r--src/namestore/zonefiles/BW7PTMDSN5KS42GMK2VKVE96BAYDS3QVMAS7SC5208FD6HFTAXE0.zkey1
-rw-r--r--src/namestore/zonefiles/CNFGWF0JH0C65M6PQW6VSRR6D3NEZVHAQF6NC037J01TETS6CJ30.zkeybin32 -> 0 bytes
-rw-r--r--src/namestore/zonefiles/KHW2Y5A7X59Z8BC2GHSEQ9WGZ5HWVEF25TBFR3Q5QHCERMVM76DG.zkey1
-rw-r--r--src/namestore/zonefiles/TWY43VS959JJ41KN2FG8782EJ2N0XDF4J6BWASR1BK5BPPRWQJAG.zkey2
-rw-r--r--src/nse/Makefile.am1
-rw-r--r--src/peerinfo-tool/Makefile.am8
-rw-r--r--src/pq/Makefile.am1
-rw-r--r--src/pq/pq.h31
-rw-r--r--src/pq/pq_connect.c84
-rw-r--r--src/pq/pq_event.c320
-rw-r--r--src/pq/test_pq.c129
-rw-r--r--src/reclaim/Makefile.am13
-rw-r--r--src/regex/Makefile.am4
-rw-r--r--src/rest/plugin_rest_config.c14
-rw-r--r--src/revocation/Makefile.am5
-rw-r--r--src/revocation/gnunet-service-revocation.c1
-rw-r--r--src/secretsharing/Makefile.am1
-rw-r--r--src/set/ibf.c2
-rw-r--r--src/set/ibf.h1
-rw-r--r--src/setu/gnunet-service-setu.c2085
-rw-r--r--src/setu/gnunet-service-setu_protocol.h78
-rw-r--r--src/setu/gnunet-service-setu_strata_estimator.c362
-rw-r--r--src/setu/gnunet-service-setu_strata_estimator.h54
-rw-r--r--src/setu/ibf.c290
-rw-r--r--src/setu/ibf.h65
-rw-r--r--src/setu/perf_setu_api.c571
-rw-r--r--src/setu/setu.h49
-rw-r--r--src/setu/setu_api.c40
-rw-r--r--src/setu/test_setu_api.c60
-rw-r--r--src/testbed/Makefile.am59
-rw-r--r--src/testbed/gnunet-cmd.c123
-rw-r--r--src/testbed/testbed_api.h6
-rw-r--r--src/testbed/testbed_api_cmd_controller.c203
-rw-r--r--src/testbed/testbed_api_cmd_peer.c281
-rw-r--r--src/testbed/testbed_api_cmd_peer_store.c60
-rw-r--r--src/testbed/testbed_api_cmd_send_peer_ready.c103
-rw-r--r--src/testbed/testbed_api_cmd_tng_connect.c55
-rw-r--r--src/testbed/testbed_api_cmd_tng_service.c276
-rw-r--r--src/testbed/testbed_api_hosts.c53
-rw-r--r--src/testbed/testbed_helper.h54
-rw-r--r--src/testing/Makefile.am50
-rw-r--r--src/testing/gnunet-cmds-helper.c (renamed from src/testbed/gnunet-cmds-helper.c)205
-rwxr-xr-xsrc/testing/netjail_core.sh (renamed from src/testbed/netjail_core.sh)15
-rwxr-xr-xsrc/testing/netjail_exec.sh (renamed from src/testbed/netjail_exec.sh)4
-rwxr-xr-xsrc/testing/netjail_start.sh (renamed from src/testbed/netjail_start.sh)2
-rwxr-xr-xsrc/testing/netjail_stop.sh (renamed from src/testbed/netjail_stop.sh)2
-rw-r--r--src/testing/test_testing_api_cmd_netjail.c (renamed from src/testbed/test_testbed_api_cmd_netjail.c)21
-rw-r--r--src/testing/test_testing_plugin_testcmd.c (renamed from src/testbed/plugin_testcmd.c)9
-rw-r--r--src/testing/testing_api_cmd_block_until_all_peers_started.c (renamed from src/testbed/testbed_api_cmd_block_until_all_peers_started.c)41
-rw-r--r--src/testing/testing_api_cmd_local_test_finished.c (renamed from src/testbed/testbed_api_cmd_local_test_finished.c)50
-rw-r--r--src/testing/testing_api_cmd_netjail_start.c (renamed from src/testbed/testbed_api_cmd_netjail_start.c)66
-rw-r--r--src/testing/testing_api_cmd_netjail_start_testsystem.c (renamed from src/testbed/testbed_api_cmd_netjail_start_testbed.c)318
-rw-r--r--src/testing/testing_api_cmd_netjail_stop.c (renamed from src/testbed/testbed_api_cmd_netjail_stop.c)64
-rw-r--r--src/testing/testing_api_cmd_netjail_stop_testsystem.c (renamed from src/testbed/testbed_api_cmd_netjail_stop_testbed.c)68
-rw-r--r--src/testing/testing_api_cmd_send_peer_ready.c36
-rw-r--r--src/testing/testing_api_cmd_system_create.c25
-rw-r--r--src/testing/testing_api_cmd_system_destroy.c116
-rw-r--r--src/testing/testing_api_loop.c44
-rw-r--r--src/testing/testing_cmds.h90
-rw-r--r--src/transport/Makefile.am71
-rw-r--r--src/transport/gnunet-communicator-tcp.c32
-rw-r--r--src/transport/plugin_cmd_simple_send.c188
-rw-r--r--src/transport/test_transport_api2_tcp_node1.conf23
-rw-r--r--src/transport/test_transport_api2_tcp_node2.conf22
-rw-r--r--src/transport/test_transport_api_cmd_simple_send.c80
-rw-r--r--src/transport/test_transport_plugin_cmd_simple_send.c248
-rwxr-xr-xsrc/transport/test_transport_simple_send.sh2
-rw-r--r--src/transport/transport-testing-cmds.h81
-rw-r--r--src/transport/transport-testing-ng.h74
-rw-r--r--src/transport/transport-testing2.h37
-rw-r--r--src/transport/transport_api_cmd_connecting_peers.c118
-rw-r--r--src/transport/transport_api_cmd_send_simple.c82
-rw-r--r--src/transport/transport_api_cmd_start_peer.c274
-rw-r--r--src/transport/transport_api_cmd_stop_peer.c163
-rw-r--r--src/util/Makefile.am10
-rw-r--r--src/util/client.c1
-rw-r--r--src/util/common_logging.c4
-rw-r--r--src/util/configuration.c1096
-rw-r--r--src/util/configuration_helper.c302
-rw-r--r--src/util/configuration_loader.c91
-rw-r--r--src/util/crypto_hkdf.c6
-rw-r--r--src/util/disk.c194
-rw-r--r--src/util/gnunet-config.c318
-rw-r--r--src/util/network.c30
-rw-r--r--src/util/os_installation.c2
-rw-r--r--src/util/os_priority.c14
-rw-r--r--src/util/plugin.c6
-rw-r--r--src/util/program.c89
-rw-r--r--src/util/strings.c2
-rw-r--r--src/util/test_plugin.c52
-rw-r--r--src/util/test_plugin_plug.c5
-rw-r--r--src/vpn/Makefile.am5
-rw-r--r--src/vpn/gnunet-helper-vpn.c11
165 files changed, 7947 insertions, 12062 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 5df85f9db..ef8c5b110 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -3,7 +3,6 @@
if HAVE_TESTING
TESTING = testing
TESTBED = testbed-logger testbed
- ATS_TESTS = ats-tests
endif
if HAVE_EXPERIMENTAL
@@ -72,7 +71,6 @@ SUBDIRS = \
ats-tool \
core \
$(TESTBED) \
- $(ATS_TESTS) \
nse \
dhtu \
dht \
diff --git a/src/arm/arm_api.c b/src/arm/arm_api.c
index afc32fc3a..5fcbfb0a9 100644
--- a/src/arm/arm_api.c
+++ b/src/arm/arm_api.c
@@ -977,9 +977,12 @@ GNUNET_ARM_request_service_start (struct GNUNET_ARM_Handle *h,
{
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
"pipe");
- } else {
+ ret = GNUNET_ARM_RESULT_START_FAILED;
+ }
+ else
+ {
wsig = GNUNET_DISK_pipe_detach_end (sig,
- GNUNET_DISK_PIPE_END_WRITE);
+ GNUNET_DISK_PIPE_END_WRITE);
ret = start_arm_service (h,
std_inheritance,
wsig);
diff --git a/src/ats-tests/.gitignore b/src/ats-tests/.gitignore
deleted file mode 100644
index 5e15db496..000000000
--- a/src/ats-tests/.gitignore
+++ /dev/null
@@ -1,14 +0,0 @@
-gnunet-solver-eval
-gnunet-ats-sim
-perf_ats_proportional_core_bandwidth
-perf_ats_proportional_core_latency
-perf_ats_proportional_core_none
-perf_ats_proportional_transport_bandwidth
-perf_ats_proportional_transport_latency
-perf_ats_proportional_transport_none
-perf_ats_mlp_core_bandwidth
-perf_ats_mlp_core_latency
-perf_ats_mlp_core_none
-perf_ats_mlp_transport_bandwidth
-perf_ats_mlp_transport_latency
-perf_ats_mlp_transport_none
diff --git a/src/ats-tests/Makefile.am b/src/ats-tests/Makefile.am
deleted file mode 100644
index 543fed287..000000000
--- a/src/ats-tests/Makefile.am
+++ /dev/null
@@ -1,169 +0,0 @@
-#t This Makefile.am is in the public domain
-AM_CPPFLAGS = -I$(top_srcdir)/src/include
-
-pkgcfgdir= $(pkgdatadir)/config.d/
-
-libexecdir= $(pkglibdir)/libexec/
-
-if USE_COVERAGE
- AM_CFLAGS = -fprofile-arcs -ftest-coverage
-endif
-
-if HAVE_TESTING
-TESTING_TESTS = \
- perf_ats_proportional_transport_none \
- perf_ats_proportional_transport_bandwidth \
- perf_ats_proportional_transport_latency \
- perf_ats_proportional_core_none \
- perf_ats_proportional_core_bandwidth \
- perf_ats_proportional_core_latency \
- $(PERF_MLP)
-
-endif
-
-lib_LTLIBRARIES = \
- libgnunetatstesting.la
-
-check_PROGRAMS = \
- $(TESTING_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)
-endif
-
-noinst_PROGRAMS = \
- gnunet-ats-sim gnunet-solver-eval
-
-libgnunetatstesting_la_SOURCES = \
- ats-testing.c ats-testing.h \
- ats-testing-log.c ats-testing-traffic.c \
- ats-testing-experiment.c ats-testing-preferences.c
-libgnunetatstesting_la_LIBADD = \
- $(top_builddir)/src/testbed/libgnunettestbed.la \
- $(top_builddir)/src/testing/libgnunettesting.la \
- $(top_builddir)/src/statistics/libgnunetstatistics.la \
- $(top_builddir)/src/core/libgnunetcore.la \
- $(top_builddir)/src/transport/libgnunettransport.la \
- $(top_builddir)/src/hello/libgnunethello.la \
- $(top_builddir)/src/ats/libgnunetats.la \
- $(top_builddir)/src/arm/libgnunetarm.la \
- $(top_builddir)/src/util/libgnunetutil.la \
- $(GN_LIBINTL)
-libgnunetatstesting_la_DEPENDENCIES = \
- $(top_builddir)/src/testbed/libgnunettestbed.la \
- $(top_builddir)/src/ats/libgnunetats.la
-libgnunetatstesting_la_LDFLAGS = \
- $(GN_LIB_LDFLAGS)
-
-gnunet_ats_sim_SOURCES = \
- gnunet-ats-sim.c
-gnunet_ats_sim_LDADD = \
- $(top_builddir)/src/util/libgnunetutil.la \
- $(top_builddir)/src/ats-tests/libgnunetatstesting.la \
- $(top_builddir)/src/testbed/libgnunettestbed.la \
- $(top_builddir)/src/ats/libgnunetats.la \
- $(top_builddir)/src/core/libgnunetcore.la \
- $(top_builddir)/src/transport/libgnunettransport.la
-gnunet_ats_sim_DEPENDENCIES = \
- libgnunetatstesting.la \
- $(top_builddir)/src/util/libgnunetutil.la
-gnunet_ats_sim_LDFLAGS = \
- $(GN_LIBINTL)
-
-
-gnunet_solver_eval_SOURCES = \
- gnunet-solver-eval.c
-gnunet_solver_eval_LDADD = \
- $(top_builddir)/src/util/libgnunetutil.la \
- $(top_builddir)/src/ats/libgnunetats.la \
- $(top_builddir)/src/core/libgnunetcore.la \
- $(top_builddir)/src/transport/libgnunettransport.la
-gnunet_solver_eval_DEPENDENCIES = \
- $(top_builddir)/src/util/libgnunetutil.la
-gnunet_solver_eval_LDFLAGS = \
- $(GN_LIBINTL)
-
-perf_ats_proportional_core_none_SOURCES = \
- perf_ats.c
-perf_ats_proportional_core_none_LDADD = \
- $(top_builddir)/src/util/libgnunetutil.la \
- $(top_builddir)/src/ats-tests/libgnunetatstesting.la \
- $(top_builddir)/src/testbed/libgnunettestbed.la \
- $(top_builddir)/src/ats/libgnunetats.la \
- $(top_builddir)/src/core/libgnunetcore.la \
- $(top_builddir)/src/transport/libgnunettransport.la
-perf_ats_proportional_core_none_DEPENDENCIES = \
- libgnunetatstesting.la \
- $(top_builddir)/src/util/libgnunetutil.la
-
-perf_ats_proportional_transport_none_SOURCES = \
- perf_ats.c
-perf_ats_proportional_transport_none_LDADD = \
- $(top_builddir)/src/util/libgnunetutil.la \
- $(top_builddir)/src/ats-tests/libgnunetatstesting.la \
- $(top_builddir)/src/testbed/libgnunettestbed.la \
- $(top_builddir)/src/ats/libgnunetats.la \
- $(top_builddir)/src/core/libgnunetcore.la \
- $(top_builddir)/src/transport/libgnunettransport.la
-perf_ats_proportional_transport_none_DEPENDENCIES = \
- libgnunetatstesting.la \
- $(top_builddir)/src/util/libgnunetutil.la
-
-perf_ats_proportional_core_bandwidth_SOURCES = \
- perf_ats.c
-perf_ats_proportional_core_bandwidth_LDADD = \
- $(top_builddir)/src/util/libgnunetutil.la \
- $(top_builddir)/src/ats-tests/libgnunetatstesting.la \
- $(top_builddir)/src/testbed/libgnunettestbed.la \
- $(top_builddir)/src/ats/libgnunetats.la \
- $(top_builddir)/src/core/libgnunetcore.la \
- $(top_builddir)/src/transport/libgnunettransport.la
-perf_ats_proportional_core_bandwidth_DEPENDENCIES = \
- libgnunetatstesting.la \
- $(top_builddir)/src/util/libgnunetutil.la
-
-perf_ats_proportional_transport_bandwidth_SOURCES = \
- perf_ats.c
-perf_ats_proportional_transport_bandwidth_LDADD = \
- $(top_builddir)/src/util/libgnunetutil.la \
- $(top_builddir)/src/ats-tests/libgnunetatstesting.la \
- $(top_builddir)/src/testbed/libgnunettestbed.la \
- $(top_builddir)/src/ats/libgnunetats.la \
- $(top_builddir)/src/core/libgnunetcore.la \
- $(top_builddir)/src/transport/libgnunettransport.la
-perf_ats_proportional_transport_bandwidth_DEPENDENCIES = \
- libgnunetatstesting.la \
- $(top_builddir)/src/util/libgnunetutil.la
-
-perf_ats_proportional_core_latency_SOURCES = \
- perf_ats.c
-perf_ats_proportional_core_latency_LDADD = \
- $(top_builddir)/src/util/libgnunetutil.la \
- $(top_builddir)/src/ats-tests/libgnunetatstesting.la \
- $(top_builddir)/src/testbed/libgnunettestbed.la \
- $(top_builddir)/src/ats/libgnunetats.la \
- $(top_builddir)/src/core/libgnunetcore.la \
- $(top_builddir)/src/transport/libgnunettransport.la
-perf_ats_proportional_core_latency_DEPENDENCIES = \
- libgnunetatstesting.la \
- $(top_builddir)/src/util/libgnunetutil.la
-
-perf_ats_proportional_transport_latency_SOURCES = \
- perf_ats.c
-perf_ats_proportional_transport_latency_LDADD = \
- $(top_builddir)/src/util/libgnunetutil.la \
- $(top_builddir)/src/ats-tests/libgnunetatstesting.la \
- $(top_builddir)/src/testbed/libgnunettestbed.la \
- $(top_builddir)/src/ats/libgnunetats.la \
- $(top_builddir)/src/core/libgnunetcore.la \
- $(top_builddir)/src/transport/libgnunettransport.la
-perf_ats_proportional_transport_latency_DEPENDENCIES = \
- libgnunetatstesting.la \
- $(top_builddir)/src/util/libgnunetutil.la
-
-EXTRA_DIST = \
- gnunet_ats_sim_default.conf \
- perf_ats_proportional_none.conf \
- perf_ats_proportional_bandwidth.conf \
- perf_ats_proportional_latency.conf
diff --git a/src/ats-tests/ats-testing-experiment.c b/src/ats-tests/ats-testing-experiment.c
deleted file mode 100644
index 9f8db1be4..000000000
--- a/src/ats-tests/ats-testing-experiment.c
+++ /dev/null
@@ -1,820 +0,0 @@
-/*
- This file is part of GNUnet.
- Copyright (C) 2010-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 ats-tests/ats-testing-experiment.c
- * @brief ats benchmark: controlled experiment execution
- * @author Christian Grothoff
- * @author Matthias Wachs
- */
-#include "platform.h"
-#include "gnunet_util_lib.h"
-#include "ats-testing.h"
-
-const char *
-print_op (enum OperationType op)
-{
- switch (op)
- {
- case START_SEND:
- return "START_SEND";
-
- case STOP_SEND:
- return "STOP_SEND";
-
- case START_PREFERENCE:
- return "START_PREFERENCE";
-
- case STOP_PREFERENCE:
- return "STOP_PREFERENCE";
-
- default:
- break;
- }
- return "";
-}
-
-
-static struct Experiment *
-create_experiment ()
-{
- struct Experiment *e;
-
- e = GNUNET_new (struct Experiment);
- e->name = NULL;
- e->num_masters = 0;
- e->num_slaves = 0;
- e->start = NULL;
- e->total_duration = GNUNET_TIME_UNIT_ZERO;
- return e;
-}
-
-
-static void
-free_experiment (struct Experiment *e)
-{
- struct Episode *cur;
- struct Episode *next;
- struct GNUNET_ATS_TEST_Operation *cur_o;
- struct GNUNET_ATS_TEST_Operation *next_o;
-
- next = e->start;
- for (cur = next; NULL != cur; cur = next)
- {
- next = cur->next;
-
- next_o = cur->head;
- for (cur_o = next_o; NULL != cur_o; cur_o = next_o)
- {
- next_o = cur_o->next;
- GNUNET_free (cur_o);
- }
- GNUNET_free (cur);
- }
-
- GNUNET_free (e->name);
- GNUNET_free (e->cfg_file);
- GNUNET_free (e);
-}
-
-
-static int
-load_episode (struct Experiment *e,
- struct Episode *cur,
- struct GNUNET_CONFIGURATION_Handle *cfg)
-{
- struct GNUNET_ATS_TEST_Operation *o;
- char *sec_name;
- char *op_name;
- char *op;
- char *type;
- char *pref;
- int op_counter = 0;
-
- fprintf (stderr, "Parsing episode %u\n", cur->id);
- GNUNET_asprintf (&sec_name, "episode-%u", cur->id);
-
- while (1)
- {
- /* Load operation */
- GNUNET_asprintf (&op_name, "op-%u-operation", op_counter);
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
- sec_name,
- op_name, &op))
- {
- GNUNET_free (op_name);
- break;
- }
- o = GNUNET_new (struct GNUNET_ATS_TEST_Operation);
- /* operations = set_rate, start_send, stop_send, set_preference */
- if (0 == strcmp (op, "start_send"))
- {
- o->type = START_SEND;
- }
- else if (0 == strcmp (op, "stop_send"))
- {
- o->type = STOP_SEND;
- }
- else if (0 == strcmp (op, "start_preference"))
- {
- o->type = START_PREFERENCE;
- }
- else if (0 == strcmp (op, "stop_preference"))
- {
- o->type = STOP_PREFERENCE;
- }
- else
- {
- fprintf (stderr, "Invalid operation %u `%s' in episode %u\n",
- op_counter, op, cur->id);
- GNUNET_free (op);
- GNUNET_free (op_name);
- GNUNET_free (o);
- GNUNET_free (sec_name);
- return GNUNET_SYSERR;
- }
- GNUNET_free (op_name);
-
- /* Get source */
- GNUNET_asprintf (&op_name, "op-%u-src", op_counter);
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
- sec_name,
- op_name,
- &o->src_id))
- {
- fprintf (stderr, "Missing src in operation %u `%s' in episode %u\n",
- op_counter, op, cur->id);
- GNUNET_free (op);
- GNUNET_free (op_name);
- GNUNET_free (o);
- GNUNET_free (sec_name);
- return GNUNET_SYSERR;
- }
- if (o->src_id > (e->num_masters - 1))
- {
- fprintf (stderr, "Invalid src %llu in operation %u `%s' in episode %u\n",
- o->src_id, op_counter, op, cur->id);
- GNUNET_free (op);
- GNUNET_free (op_name);
- GNUNET_free (o);
- GNUNET_free (sec_name);
- return GNUNET_SYSERR;
- }
- GNUNET_free (op_name);
-
- /* Get destination */
- GNUNET_asprintf (&op_name, "op-%u-dest", op_counter);
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
- sec_name,
- op_name,
- &o->dest_id))
- {
- fprintf (stderr, "Missing src in operation %u `%s' in episode %u\n",
- op_counter, op, cur->id);
- GNUNET_free (op);
- GNUNET_free (op_name);
- GNUNET_free (o);
- GNUNET_free (sec_name);
- return GNUNET_SYSERR;
- }
- if (o->dest_id > (e->num_slaves - 1))
- {
- fprintf (stderr,
- "Invalid destination %llu in operation %u `%s' in episode %u\n",
- o->dest_id, op_counter, op, cur->id);
- GNUNET_free (op);
- GNUNET_free (op_name);
- GNUNET_free (o);
- GNUNET_free (sec_name);
- return GNUNET_SYSERR;
- }
- GNUNET_free (op_name);
-
- GNUNET_asprintf (&op_name, "op-%u-type", op_counter);
- if ((GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_string (cfg,
- sec_name,
- op_name,
- &type)) &&
- (STOP_SEND != o->type) &&
- (STOP_PREFERENCE != o->type))
- {
- /* Load arguments for set_rate, start_send, set_preference */
- if (0 == strcmp (type, "constant"))
- {
- o->gen_type = GNUNET_ATS_TEST_TG_CONSTANT;
- }
- else if (0 == strcmp (type, "linear"))
- {
- o->gen_type = GNUNET_ATS_TEST_TG_LINEAR;
- }
- else if (0 == strcmp (type, "sinus"))
- {
- o->gen_type = GNUNET_ATS_TEST_TG_SINUS;
- }
- else if (0 == strcmp (type, "random"))
- {
- o->gen_type = GNUNET_ATS_TEST_TG_RANDOM;
- }
- else
- {
- fprintf (stderr, "Invalid type %u `%s' in episode %u\n",
- op_counter, op, cur->id);
- GNUNET_free (type);
- GNUNET_free (op);
- GNUNET_free (op_name);
- GNUNET_free (sec_name);
- GNUNET_free (o);
- return GNUNET_SYSERR;
- }
- GNUNET_free (op_name);
-
- /* Get base rate */
- GNUNET_asprintf (&op_name, "op-%u-base-rate", op_counter);
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
- sec_name,
- op_name,
- &o->base_rate))
- {
- fprintf (stderr,
- "Missing base rate in operation %u `%s' in episode %u\n",
- op_counter, op, cur->id);
- GNUNET_free (type);
- GNUNET_free (op);
- GNUNET_free (op_name);
- GNUNET_free (sec_name);
- GNUNET_free (o);
- return GNUNET_SYSERR;
- }
- GNUNET_free (op_name);
-
- /* Get max rate */
- GNUNET_asprintf (&op_name, "op-%u-max-rate", op_counter);
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
- sec_name,
- op_name,
- &o->max_rate))
- {
- if ((GNUNET_ATS_TEST_TG_LINEAR == o->gen_type) ||
- (GNUNET_ATS_TEST_TG_RANDOM == o->gen_type) ||
- (GNUNET_ATS_TEST_TG_SINUS == o->gen_type))
- {
- fprintf (stderr,
- "Missing max rate in operation %u `%s' in episode %u\n",
- op_counter, op, cur->id);
- GNUNET_free (type);
- GNUNET_free (op_name);
- GNUNET_free (op);
- GNUNET_free (o);
- GNUNET_free (sec_name);
- return GNUNET_SYSERR;
- }
- }
- GNUNET_free (op_name);
-
- /* Get period */
- GNUNET_asprintf (&op_name, "op-%u-period", op_counter);
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
- sec_name,
- op_name,
- &o->period))
- {
- o->period = cur->duration;
- }
- GNUNET_free (op_name);
-
- if (START_PREFERENCE == o->type)
- {
- /* Get frequency */
- GNUNET_asprintf (&op_name, "op-%u-frequency", op_counter);
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
- sec_name,
- op_name,
- &o->frequency))
- {
- fprintf (stderr,
- "Missing frequency in operation %u `%s' in episode %u\n",
- op_counter, op, cur->id);
- GNUNET_free (type);
- GNUNET_free (op_name);
- GNUNET_free (op);
- GNUNET_free (o);
- GNUNET_free (sec_name);
- return GNUNET_SYSERR;
- }
- GNUNET_free (op_name);
-
- /* Get preference */
- GNUNET_asprintf (&op_name, "op-%u-pref", op_counter);
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
- sec_name,
- op_name,
- &pref))
- {
- fprintf (stderr,
- "Missing preference in operation %u `%s' in episode %u\n",
- op_counter, op, cur->id);
- GNUNET_free (type);
- GNUNET_free (op_name);
- GNUNET_free (op);
- GNUNET_free (pref);
- GNUNET_free (o);
- GNUNET_free (sec_name);
- return GNUNET_SYSERR;
- }
-
- if (0 == strcmp (pref, "bandwidth"))
- o->pref_type = GNUNET_ATS_PREFERENCE_BANDWIDTH;
- else if (0 == strcmp (pref, "latency"))
- o->pref_type = GNUNET_ATS_PREFERENCE_LATENCY;
- else
- {
- fprintf (stderr,
- "Invalid preference in operation %u `%s' in episode %u\n",
- op_counter, op, cur->id);
- GNUNET_free (type);
- GNUNET_free (op_name);
- GNUNET_free (op);
- GNUNET_free (pref);
- GNUNET_free (o);
- GNUNET_free (sec_name);
- return GNUNET_SYSERR;
- }
- GNUNET_free (pref);
- GNUNET_free (op_name);
- }
- }
-
- /* Safety checks */
- if ((GNUNET_ATS_TEST_TG_LINEAR == o->gen_type) ||
- (GNUNET_ATS_TEST_TG_SINUS == o->gen_type))
- {
- if ((o->max_rate - o->base_rate) > o->base_rate)
- {
- /* This will cause an underflow */
- GNUNET_break (0);
- }
- fprintf (stderr,
- "Selected max rate and base rate cannot be used for desired traffic form!\n");
- }
-
- if ((START_SEND == o->type) || (START_PREFERENCE == o->type))
- fprintf (stderr,
- "Found operation %u in episode %u: %s [%llu]->[%llu] == %s, %llu -> %llu in %s\n",
- op_counter, cur->id, print_op (o->type), o->src_id,
- o->dest_id, (NULL != type) ? type : "",
- o->base_rate, o->max_rate,
- GNUNET_STRINGS_relative_time_to_string (o->period, GNUNET_YES));
- else
- fprintf (stderr, "Found operation %u in episode %u: %s [%llu]->[%llu]\n",
- op_counter, cur->id, print_op (o->type), o->src_id, o->dest_id);
-
- GNUNET_free (type);
- GNUNET_free (op);
-
- GNUNET_CONTAINER_DLL_insert (cur->head, cur->tail, o);
- op_counter++;
- }
- GNUNET_free (sec_name);
-
- return GNUNET_OK;
-}
-
-
-static int
-load_episodes (struct Experiment *e, struct GNUNET_CONFIGURATION_Handle *cfg)
-{
- int e_counter = 0;
- char *sec_name;
- struct GNUNET_TIME_Relative e_duration;
- struct Episode *cur;
- struct Episode *last;
-
- e_counter = 0;
- last = NULL;
- while (1)
- {
- GNUNET_asprintf (&sec_name, "episode-%u", e_counter);
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
- sec_name,
- "duration",
- &e_duration))
- {
- GNUNET_free (sec_name);
- break;
- }
-
- cur = GNUNET_new (struct Episode);
- cur->duration = e_duration;
- cur->id = e_counter;
-
- if (GNUNET_OK != load_episode (e, cur, cfg))
- {
- GNUNET_free (sec_name);
- GNUNET_free (cur);
- return GNUNET_SYSERR;
- }
-
- fprintf (stderr, "Found episode %u with duration %s \n",
- e_counter,
- GNUNET_STRINGS_relative_time_to_string (cur->duration,
- GNUNET_YES));
-
- /* Update experiment */
- e->num_episodes++;
- e->total_duration = GNUNET_TIME_relative_add (e->total_duration,
- cur->duration);
- /* Put in linked list */
- if (NULL == last)
- e->start = cur;
- else
- last->next = cur;
-
- GNUNET_free (sec_name);
- e_counter++;
- last = cur;
- }
- return e_counter;
-}
-
-
-static void
-timeout_experiment (void *cls)
-{
- struct Experiment *e = cls;
-
- e->experiment_timeout_task = NULL;
- fprintf (stderr, "Experiment timeout!\n");
-
- if (NULL != e->episode_timeout_task)
- {
- GNUNET_SCHEDULER_cancel (e->episode_timeout_task);
- e->episode_timeout_task = NULL;
- }
-
- e->e_done_cb (e, GNUNET_TIME_absolute_get_duration (e->start_time),
- GNUNET_SYSERR);
-}
-
-
-static void
-enforce_start_send (struct GNUNET_ATS_TEST_Operation *op)
-{
- struct BenchmarkPeer *peer;
- struct BenchmarkPartner *partner;
-
- peer = GNUNET_ATS_TEST_get_peer (op->src_id);
- if (NULL == peer)
- {
- GNUNET_break (0);
- return;
- }
-
- partner = GNUNET_ATS_TEST_get_partner (op->src_id, op->dest_id);
- if (NULL == partner)
- {
- GNUNET_break (0);
- return;
- }
-
- fprintf (stderr, "Found master %llu slave %llu\n", op->src_id, op->dest_id);
-
- if (NULL != partner->tg)
- {
- fprintf (stderr, "Stopping traffic between master %llu slave %llu\n",
- op->src_id, op->dest_id);
- GNUNET_ATS_TEST_generate_traffic_stop (partner->tg);
- partner->tg = NULL;
- }
-
- partner->tg = GNUNET_ATS_TEST_generate_traffic_start (peer, partner,
- op->gen_type,
- op->base_rate,
- op->max_rate,
- op->period,
- GNUNET_TIME_UNIT_FOREVER_REL);
-}
-
-
-static void
-enforce_stop_send (struct GNUNET_ATS_TEST_Operation *op)
-{
- struct BenchmarkPartner *p;
-
- p = GNUNET_ATS_TEST_get_partner (op->src_id, op->dest_id);
- if (NULL == p)
- {
- GNUNET_break (0);
- return;
- }
-
- fprintf (stderr, "Found master %llu slave %llu\n", op->src_id, op->dest_id);
-
- if (NULL != p->tg)
- {
- fprintf (stderr, "Stopping traffic between master %llu slave %llu\n",
- op->src_id, op->dest_id);
- GNUNET_ATS_TEST_generate_traffic_stop (p->tg);
- p->tg = NULL;
- }
-}
-
-
-static void
-enforce_start_preference (struct GNUNET_ATS_TEST_Operation *op)
-{
- struct BenchmarkPeer *peer;
- struct BenchmarkPartner *partner;
-
- peer = GNUNET_ATS_TEST_get_peer (op->src_id);
- if (NULL == peer)
- {
- GNUNET_break (0);
- return;
- }
-
- partner = GNUNET_ATS_TEST_get_partner (op->src_id, op->dest_id);
- if (NULL == partner)
- {
- GNUNET_break (0);
- return;
- }
-
- fprintf (stderr, "Found master %llu slave %llu\n", op->src_id, op->dest_id);
-
- if (NULL != partner->pg)
- {
- fprintf (stderr, "Stopping traffic between master %llu slave %llu\n",
- op->src_id, op->dest_id);
- GNUNET_ATS_TEST_generate_preferences_stop (partner->pg);
- partner->pg = NULL;
- }
-
- partner->pg = GNUNET_ATS_TEST_generate_preferences_start (peer, partner,
- op->gen_type,
- op->base_rate,
- op->max_rate,
- op->period,
- op->frequency,
- op->pref_type);
-}
-
-
-static void
-enforce_stop_preference (struct GNUNET_ATS_TEST_Operation *op)
-{
- struct BenchmarkPartner *p;
-
- p = GNUNET_ATS_TEST_get_partner (op->src_id, op->dest_id);
- if (NULL == p)
- {
- GNUNET_break (0);
- return;
- }
-
- fprintf (stderr, "Found master %llu slave %llu\n", op->src_id, op->dest_id);
-
- if (NULL != p->pg)
- {
- fprintf (stderr, "Stopping preference between master %llu slave %llu\n",
- op->src_id, op->dest_id);
- GNUNET_ATS_TEST_generate_preferences_stop (p->pg);
- p->pg = NULL;
- }
-}
-
-
-static void
-enforce_episode (struct Episode *ep)
-{
- struct GNUNET_ATS_TEST_Operation *cur;
-
- for (cur = ep->head; NULL != cur; cur = cur->next)
- {
- fprintf (stderr, "Enforcing operation: %s [%llu]->[%llu] == %llu\n",
- print_op (cur->type), cur->src_id, cur->dest_id, cur->base_rate);
- switch (cur->type)
- {
- case START_SEND:
- enforce_start_send (cur);
- break;
-
- case STOP_SEND:
- enforce_stop_send (cur);
- break;
-
- case START_PREFERENCE:
- enforce_start_preference (cur);
- break;
-
- case STOP_PREFERENCE:
- enforce_stop_preference (cur);
- break;
-
- default:
- break;
- }
- }
-}
-
-
-static void
-timeout_episode (void *cls)
-{
- struct Experiment *e = cls;
-
- e->episode_timeout_task = NULL;
- if (NULL != e->ep_done_cb)
- e->ep_done_cb (e->cur);
-
- /* Scheduling next */
- e->cur = e->cur->next;
- if (NULL == e->cur)
- {
- /* done */
- fprintf (stderr, "Last episode done!\n");
- if (NULL != e->experiment_timeout_task)
- {
- GNUNET_SCHEDULER_cancel (e->experiment_timeout_task);
- e->experiment_timeout_task = NULL;
- }
- e->e_done_cb (e, GNUNET_TIME_absolute_get_duration (e->start_time),
- GNUNET_OK);
- return;
- }
-
- fprintf (stderr, "Running episode %u with timeout %s\n",
- e->cur->id,
- GNUNET_STRINGS_relative_time_to_string (e->cur->duration,
- GNUNET_YES));
- enforce_episode (e->cur);
-
- e->episode_timeout_task = GNUNET_SCHEDULER_add_delayed (e->cur->duration,
- &timeout_episode, e);
-}
-
-
-void
-GNUNET_ATS_TEST_experimentation_run (struct Experiment *e,
- GNUNET_ATS_TESTING_EpisodeDoneCallback
- ep_done_cb,
- GNUNET_ATS_TESTING_ExperimentDoneCallback
- e_done_cb)
-{
- fprintf (stderr, "Running experiment `%s' with timeout %s\n", e->name,
- GNUNET_STRINGS_relative_time_to_string (e->max_duration,
- GNUNET_YES));
- e->e_done_cb = e_done_cb;
- e->ep_done_cb = ep_done_cb;
- e->start_time = GNUNET_TIME_absolute_get ();
-
- /* Start total time out */
- e->experiment_timeout_task = GNUNET_SCHEDULER_add_delayed (e->max_duration,
- &timeout_experiment,
- e);
-
- /* Start */
- e->cur = e->start;
- fprintf (stderr, "Running episode %u with timeout %s\n",
- e->cur->id,
- GNUNET_STRINGS_relative_time_to_string (e->cur->duration,
- GNUNET_YES));
- enforce_episode (e->cur);
- e->episode_timeout_task = GNUNET_SCHEDULER_add_delayed (e->cur->duration,
- &timeout_episode, e);
-}
-
-
-struct Experiment *
-GNUNET_ATS_TEST_experimentation_load (const char *filename)
-{
- struct Experiment *e;
- struct GNUNET_CONFIGURATION_Handle *cfg;
-
- e = NULL;
-
- cfg = GNUNET_CONFIGURATION_create ();
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, filename))
- {
- fprintf (stderr, "Failed to load `%s'\n", filename);
- GNUNET_CONFIGURATION_destroy (cfg);
- return NULL;
- }
-
- e = create_experiment ();
-
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg, "experiment",
- "name", &e->name))
- {
- fprintf (stderr, "Invalid %s", "name");
- free_experiment (e);
- return NULL;
- }
- else
- fprintf (stderr, "Experiment name: `%s'\n", e->name);
-
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_filename (cfg,
- "experiment",
- "cfg_file",
- &e->cfg_file))
- {
- fprintf (stderr, "Invalid %s", "cfg_file");
- free_experiment (e);
- return NULL;
- }
- else
- fprintf (stderr, "Experiment name: `%s'\n", e->cfg_file);
-
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg, "experiment",
- "masters",
- &e->num_masters))
- {
- fprintf (stderr, "Invalid %s", "masters");
- free_experiment (e);
- return NULL;
- }
- else
- fprintf (stderr, "Experiment masters: `%llu'\n",
- e->num_masters);
-
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg, "experiment",
- "slaves",
- &e->num_slaves))
- {
- fprintf (stderr, "Invalid %s", "slaves");
- free_experiment (e);
- return NULL;
- }
- else
- fprintf (stderr, "Experiment slaves: `%llu'\n",
- e->num_slaves);
-
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg, "experiment",
- "log_freq",
- &e->log_freq))
- {
- fprintf (stderr, "Invalid %s", "log_freq");
- free_experiment (e);
- return NULL;
- }
- else
- fprintf (stderr, "Experiment logging frequency: `%s'\n",
- GNUNET_STRINGS_relative_time_to_string (e->log_freq, GNUNET_YES));
-
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg, "experiment",
- "max_duration",
- &e->max_duration))
- {
- fprintf (stderr, "Invalid %s", "max_duration");
- free_experiment (e);
- return NULL;
- }
- else
- fprintf (stderr, "Experiment duration: `%s'\n",
- GNUNET_STRINGS_relative_time_to_string (e->max_duration,
- GNUNET_YES));
-
- load_episodes (e, cfg);
- fprintf (stderr, "Loaded %u episodes with total duration %s\n",
- e->num_episodes,
- GNUNET_STRINGS_relative_time_to_string (e->total_duration,
- GNUNET_YES));
-
- GNUNET_CONFIGURATION_destroy (cfg);
- return e;
-}
-
-
-void
-GNUNET_ATS_TEST_experimentation_stop (struct Experiment *e)
-{
- if (NULL != e->experiment_timeout_task)
- {
- GNUNET_SCHEDULER_cancel (e->experiment_timeout_task);
- e->experiment_timeout_task = NULL;
- }
- if (NULL != e->episode_timeout_task)
- {
- GNUNET_SCHEDULER_cancel (e->episode_timeout_task);
- e->episode_timeout_task = NULL;
- }
- free_experiment (e);
-}
-
-
-/* end of file ats-testing-experiment.c*/
diff --git a/src/ats-tests/ats-testing-log.c b/src/ats-tests/ats-testing-log.c
deleted file mode 100644
index dfdfa8a80..000000000
--- a/src/ats-tests/ats-testing-log.c
+++ /dev/null
@@ -1,979 +0,0 @@
-/*
- This file is part of GNUnet.
- Copyright (C) 2010-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 ats-tests/ats-testing-log.c
- * @brief ats benchmark: logging for performance tests
- * @author Christian Grothoff
- * @author Matthias Wachs
- */
-#include "platform.h"
-#include "gnunet_util_lib.h"
-#include "ats-testing.h"
-
-#define THROUGHPUT_TEMPLATE "#!/usr/bin/gnuplot \n" \
- "set datafile separator ';' \n" \
- "set title \"Throughput between Master and Slaves\" \n" \
- "set xlabel \"Time in ms\" \n" \
- "set ylabel \"Bytes/s\" \n" \
- "set grid \n"
-
-#define RTT_TEMPLATE "#!/usr/bin/gnuplot \n" \
- "set datafile separator ';' \n" \
- "set title \"Application level roundtrip time between Master and Slaves\" \n" \
- "set xlabel \"Time in ms\" \n" \
- "set ylabel \"ms\" \n" \
- "set grid \n"
-
-#define BW_TEMPLATE "#!/usr/bin/gnuplot \n" \
- "set datafile separator ';' \n" \
- "set title \"Bandwidth inbound and outbound between Master and Slaves\" \n" \
- "set xlabel \"Time in ms\" \n" \
- "set ylabel \"Bytes / s \" \n" \
- "set grid \n"
-
-#define LOG_ITEMS_TIME 2
-#define LOG_ITEMS_PER_PEER 17
-
-#define LOG_ITEM_BYTES_SENT 1
-#define LOG_ITEM_MSGS_SENT 2
-#define LOG_ITEM_THROUGHPUT_SENT 3
-#define LOG_ITEM_BYTES_RECV 4
-#define LOG_ITEM_MSGS_RECV 5
-#define LOG_ITEM_THROUGHPUT_RECV 6
-#define LOG_ITEM_APP_RTT 7
-#define LOG_ITEM_ATS_BW_IN 8
-#define LOG_ITEM_ATS_BW_OUT 9
-#define LOG_ITEM_ATS_COSTS_LAN 10
-#define LOG_ITEM_ATS_WAN 11
-#define LOG_ITEM_ATS_WLAN 12
-#define LOG_ITEM_ATS_DELAY 13
-#define LOG_ITEM_ATS_DISTANCE 14
-#define LOG_ITEM_ATS_NETWORKTYPE 15
-#define LOG_ITEM_ATS_UTIL_UP 16
-#define LOG_ITEM_ATS_UTIL_DOWN 17
-
-/**
- * A single logging time step for a partner
- */
-struct PartnerLoggingTimestep
-{
- /**
- * Peer
- */
- struct BenchmarkPeer *slave;
-
- /**
- * Total number of messages this peer has sent
- */
- unsigned int total_messages_sent;
-
- /**
- * Total number of bytes this peer has sent
- */
- unsigned int total_bytes_sent;
-
- /**
- * Total number of messages this peer has received
- */
- unsigned int total_messages_received;
-
- /**
- * Total number of bytes this peer has received
- */
- unsigned int total_bytes_received;
-
- /**
- * Total outbound throughput for master in Bytes / s
- */
- unsigned int throughput_sent;
-
- /**
- * Total inbound throughput for master in Bytes / s
- */
- unsigned int throughput_recv;
-
- /**
- * Accumulated RTT for all messages
- */
- unsigned int total_app_rtt;
-
- /**
- * Current application level delay
- */
- unsigned int app_rtt;
-
- /* Current ATS properties */
-
- unsigned int ats_distance;
-
- struct GNUNET_TIME_Relative ats_delay;
-
- uint32_t bandwidth_in;
-
- uint32_t bandwidth_out;
-
- uint32_t ats_utilization_out;
-
- uint32_t ats_utilization_in;
-
- enum GNUNET_NetworkType ats_network_type;
-
- double pref_bandwidth;
- double pref_delay;
-};
-
-
-/**
- * A single logging time step for a peer
- */
-struct PeerLoggingTimestep
-{
- /**
- * Next in DLL
- */
- struct PeerLoggingTimestep *next;
-
- /**
- * Prev in DLL
- */
- struct PeerLoggingTimestep *prev;
-
- /**
- * Logging timestamp
- */
- struct GNUNET_TIME_Absolute timestamp;
-
- /**
- * Total number of messages this peer has sent
- */
- unsigned int total_messages_sent;
-
- /**
- * Total number of bytes this peer has sent
- */
- unsigned int total_bytes_sent;
-
- /**
- * Total number of messages this peer has received
- */
- unsigned int total_messages_received;
-
- /**
- * Total number of bytes this peer has received
- */
- unsigned int total_bytes_received;
-
- /**
- * Total outbound throughput for master in Bytes / s
- */
- unsigned int total_throughput_send;
-
- /**
- * Total inbound throughput for master in Bytes / s
- */
- unsigned int total_throughput_recv;
-
- /**
- * Logs for slaves
- */
- struct PartnerLoggingTimestep *slaves_log;
-};
-
-/**
- * Entry for a benchmark peer
- */
-struct LoggingPeer
-{
- /**
- * Peer
- */
- struct BenchmarkPeer *peer;
-
- /**
- * Start time
- */
- struct GNUNET_TIME_Absolute start;
-
- /**
- * DLL for logging entries: head
- */
- struct PeerLoggingTimestep *head;
-
- /**
- * DLL for logging entries: tail
- */
- struct PeerLoggingTimestep *tail;
-};
-
-struct LoggingHandle
-{
- /**
- * Logging task
- */
- struct GNUNET_SCHEDULER_Task *log_task;
-
- /**
- * Reference to perf_ats' masters
- */
- int num_masters;
- int num_slaves;
- int running;
- int verbose;
- const char *name;
- struct GNUNET_TIME_Relative frequency;
-
- /**
- * Log structure of length num_peers
- */
- struct LoggingPeer *lp;
-};
-
-
-static void
-write_throughput_gnuplot_script (char *fn, struct LoggingPeer *lp, char **fs,
- int slaves)
-{
- struct GNUNET_DISK_FileHandle *f;
- char *gfn;
- char *data;
- int c_s;
-
- GNUNET_asprintf (&gfn, "gnuplot_throughput_%s", fn);
- fprintf (stderr,
- "Writing throughput plot for master %u and %u slaves to `%s'\n",
- lp->peer->no, slaves, gfn);
-
- f = GNUNET_DISK_file_open (gfn,
- GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE,
- GNUNET_DISK_PERM_USER_EXEC
- | GNUNET_DISK_PERM_USER_READ
- | GNUNET_DISK_PERM_USER_WRITE);
- if (NULL == f)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot open gnuplot file `%s'\n",
- gfn);
- GNUNET_free (gfn);
- return;
- }
-
- /* Write header */
- if (GNUNET_SYSERR == GNUNET_DISK_file_write (f, THROUGHPUT_TEMPLATE,
- strlen (THROUGHPUT_TEMPLATE)))
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Cannot write data to plot file `%s'\n", gfn);
-
- /* Write master data */
- GNUNET_asprintf (&data,
- "plot '%s' using 2:%u with lines title 'Master %u send total', \\\n" \
- "'%s' using 2:%u with lines title 'Master %u receive total', \\\n",
- fn, LOG_ITEMS_TIME + LOG_ITEM_THROUGHPUT_SENT, lp->peer->no,
- fn, LOG_ITEMS_TIME + LOG_ITEM_THROUGHPUT_RECV, lp->peer->no);
- if (GNUNET_SYSERR == GNUNET_DISK_file_write (f, data, strlen (data)))
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Cannot write data to plot file `%s'\n", gfn);
- GNUNET_free (data);
-
- for (c_s = 0; c_s < slaves; c_s++)
- {
- GNUNET_asprintf (&data,
- "'%s' using 2:%u with lines title 'Master %u - Slave %u send', \\\n" \
- "'%s' using 2:%u with lines title 'Master %u - Slave %u receive'%s\n",
- fs[c_s],
- LOG_ITEMS_TIME + LOG_ITEM_THROUGHPUT_SENT,
- lp->peer->no,
- lp->peer->partners[c_s].dest->no,
- fs[c_s],
- LOG_ITEMS_TIME + LOG_ITEM_THROUGHPUT_RECV,
- lp->peer->no,
- lp->peer->partners[c_s].dest->no,
- (c_s < lp->peer->num_partners - 1) ? ", \\" :
- "\n pause -1");
- if (GNUNET_SYSERR == GNUNET_DISK_file_write (f, data, strlen (data)))
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Cannot write data to plot file `%s'\n", gfn);
- GNUNET_free (data);
- }
-
- if (GNUNET_SYSERR == GNUNET_DISK_file_close (f))
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Cannot close gnuplot file `%s'\n", gfn);
- else
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Data successfully written to plot file `%s'\n", gfn);
- GNUNET_free (gfn);
-}
-
-
-static void
-write_rtt_gnuplot_script (char *fn, struct LoggingPeer *lp, char **fs, int
- slaves)
-{
- struct GNUNET_DISK_FileHandle *f;
- char *gfn;
- char *data;
- int c_s;
-
- GNUNET_asprintf (&gfn, "gnuplot_rtt_%s", fn);
- fprintf (stderr, "Writing rtt plot for master %u to `%s'\n",
- lp->peer->no, gfn);
-
- f = GNUNET_DISK_file_open (gfn,
- GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE,
- GNUNET_DISK_PERM_USER_EXEC
- | GNUNET_DISK_PERM_USER_READ
- | GNUNET_DISK_PERM_USER_WRITE);
- if (NULL == f)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot open gnuplot file `%s'\n",
- gfn);
- GNUNET_free (gfn);
- return;
- }
-
- /* Write header */
- if (GNUNET_SYSERR == GNUNET_DISK_file_write (f, RTT_TEMPLATE, strlen (
- RTT_TEMPLATE)))
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Cannot write data to plot file `%s'\n", gfn);
-
- for (c_s = 0; c_s < slaves; c_s++)
- {
- GNUNET_asprintf (&data,
- "%s'%s' using 2:%u with lines title 'Master %u - Slave %u '%s\n",
- (0 == c_s) ? "plot " : "",
- fs[c_s],
- LOG_ITEMS_TIME + LOG_ITEM_APP_RTT,
- lp->peer->no,
- lp->peer->partners[c_s].dest->no,
- (c_s < lp->peer->num_partners - 1) ? ", \\" :
- "\n pause -1");
- if (GNUNET_SYSERR == GNUNET_DISK_file_write (f, data, strlen (data)))
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Cannot write data to plot file `%s'\n", gfn);
- GNUNET_free (data);
- }
-
- if (GNUNET_SYSERR == GNUNET_DISK_file_close (f))
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot close gnuplot file `%s'\n",
- gfn);
- else
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Data successfully written to plot file `%s'\n", gfn);
- GNUNET_free (gfn);
-}
-
-
-static void
-write_bw_gnuplot_script (char *fn, struct LoggingPeer *lp, char **fs, int
- slaves)
-{
- struct GNUNET_DISK_FileHandle *f;
- char *gfn;
- char *data;
- int c_s;
-
- GNUNET_asprintf (&gfn, "gnuplot_bw_%s", fn);
- fprintf (stderr, "Writing bandwidth plot for master %u to `%s'\n",
- lp->peer->no, gfn);
-
- f = GNUNET_DISK_file_open (gfn,
- GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE,
- GNUNET_DISK_PERM_USER_EXEC
- | GNUNET_DISK_PERM_USER_READ
- | GNUNET_DISK_PERM_USER_WRITE);
- if (NULL == f)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot open gnuplot file `%s'\n",
- gfn);
- GNUNET_free (gfn);
- return;
- }
-
- /* Write header */
- if (GNUNET_SYSERR == GNUNET_DISK_file_write (f, BW_TEMPLATE, strlen (
- BW_TEMPLATE)))
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Cannot write data to plot file `%s'\n", gfn);
-
- for (c_s = 0; c_s < slaves; c_s++)
- {
- GNUNET_asprintf (&data, "%s" \
- "'%s' using 2:%u with lines title 'BW out master %u - Slave %u ', \\\n" \
- "'%s' using 2:%u with lines title 'BW in master %u - Slave %u '" \
- "%s\n",
- (0 == c_s) ? "plot " : "",
- fs[c_s],
- LOG_ITEMS_TIME + LOG_ITEM_ATS_BW_OUT,
- lp->peer->no, c_s,
- fs[c_s],
- LOG_ITEMS_TIME + LOG_ITEM_ATS_BW_IN,
- lp->peer->no, c_s,
- (c_s < lp->peer->num_partners - 1) ? ", \\" :
- "\n pause -1");
- if (GNUNET_SYSERR == GNUNET_DISK_file_write (f, data, strlen (data)))
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Cannot write data to plot file `%s'\n", gfn);
- GNUNET_free (data);
- }
-
- if (GNUNET_SYSERR == GNUNET_DISK_file_close (f))
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot close gnuplot file `%s'\n",
- gfn);
- else
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Data successfully written to plot file `%s'\n", gfn);
- GNUNET_free (gfn);
-}
-
-
-void
-GNUNET_ATS_TEST_logging_write_to_file (struct LoggingHandle *l,
- const char *experiment_name,
- int plots)
-{
- struct GNUNET_DISK_FileHandle *f[l->num_slaves];
- struct GNUNET_DISK_FileHandle *f_m;
- const char *tmp_exp_name;
- char *filename_master;
- char *filename_slaves[l->num_slaves];
- char *data;
- struct PeerLoggingTimestep *cur_lt;
- struct PartnerLoggingTimestep *plt;
- struct GNUNET_TIME_Absolute timestamp;
- int c_m;
- int c_s;
-
-
- timestamp = GNUNET_TIME_absolute_get ();
-
- tmp_exp_name = experiment_name;
- for (c_m = 0; c_m < l->num_masters; c_m++)
- {
- GNUNET_asprintf (&filename_master, "%s_%llu_master%u_%s",
- experiment_name,
- (unsigned long long) timestamp.abs_value_us, c_m, l->name);
- fprintf (stderr, "Writing data for master %u to file `%s'\n",
- c_m, filename_master);
-
- f_m = GNUNET_DISK_file_open (filename_master,
- GNUNET_DISK_OPEN_WRITE
- | GNUNET_DISK_OPEN_CREATE,
- GNUNET_DISK_PERM_USER_READ
- | GNUNET_DISK_PERM_USER_WRITE);
- if (NULL == f_m)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot open log file `%s'\n",
- filename_master);
- GNUNET_free (filename_master);
- return;
- }
-
- GNUNET_asprintf (&data, "# master %u; experiment : %s\n"
- "timestamp; timestamp delta; #messages sent; #bytes sent; #throughput sent; #messages received; #bytes received; #throughput received; \n",
- c_m, experiment_name);
- if (GNUNET_SYSERR == GNUNET_DISK_file_write (f_m, data, strlen (data)))
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Cannot write data to log file `%s'\n", filename_master);
- GNUNET_free (data);
-
- for (c_s = 0; c_s < l->lp[c_m].peer->num_partners; c_s++)
- {
- GNUNET_asprintf (&filename_slaves[c_s], "%s_%llu_master%u_slave_%u_%s",
- tmp_exp_name,
- (unsigned long long) timestamp.abs_value_us,
- c_m, c_s, l->name);
-
- fprintf (stderr, "Writing data for master %u slave %u to file `%s'\n",
- c_m, c_s, filename_slaves[c_s]);
-
- f[c_s] = GNUNET_DISK_file_open (filename_slaves[c_s],
- GNUNET_DISK_OPEN_WRITE
- | GNUNET_DISK_OPEN_CREATE,
- GNUNET_DISK_PERM_USER_READ
- | GNUNET_DISK_PERM_USER_WRITE);
- if (NULL == f[c_s])
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot open log file `%s'\n",
- filename_slaves[c_s]);
- GNUNET_free (filename_slaves[c_s]);
- GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close (f_m));
- GNUNET_free (filename_master);
- return;
- }
-
- /* Header */
- GNUNET_asprintf (&data, "# master %u; slave %u ; experiment : %s\n"
- "timestamp; timestamp delta; #messages sent; #bytes sent; #throughput sent; #messages received; #bytes received; #throughput received; " \
- "rtt; bw in; bw out; ats_cost_lan; ats_cost_wlan; ats_delay; ats_distance; ats_network_type; ats_utilization_up ;ats_utilization_down;" \
- "pref bandwidth; pref delay\n",
- c_m, c_s, experiment_name);
- if (GNUNET_SYSERR == GNUNET_DISK_file_write (f[c_s], data, strlen (data)))
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Cannot write data to log file `%s'\n",
- filename_slaves[c_s]);
- GNUNET_free (data);
- }
-
- for (cur_lt = l->lp[c_m].head; NULL != cur_lt; cur_lt = cur_lt->next)
- {
- if (l->verbose)
- fprintf (stderr,
- "Master [%u]: timestamp %llu %llu ; %u %u %u ; %u %u %u\n",
- l->lp[c_m].peer->no,
- (long long unsigned int) cur_lt->timestamp.abs_value_us,
- (long long unsigned int) GNUNET_TIME_absolute_get_difference (
- l->lp[c_m].start,
- cur_lt
- ->timestamp).rel_value_us / 1000,
- cur_lt->total_messages_sent,
- cur_lt->total_bytes_sent,
- cur_lt->total_throughput_send,
- cur_lt->total_messages_received,
- cur_lt->total_bytes_received,
- cur_lt->total_throughput_recv);
-
- /* Assembling master string */
- GNUNET_asprintf (&data, "%llu;%llu;%u;%u;%u;%u;%u;%u;\n",
- (long long unsigned int) cur_lt->timestamp.abs_value_us,
- (long long unsigned
- int) GNUNET_TIME_absolute_get_difference (
- l->lp[c_m].start,
- cur_lt
- ->timestamp).
- rel_value_us / 1000,
- cur_lt->total_messages_sent,
- cur_lt->total_bytes_sent,
- cur_lt->total_throughput_send,
- cur_lt->total_messages_received,
- cur_lt->total_bytes_received,
- cur_lt->total_throughput_recv);
-
- if (GNUNET_SYSERR == GNUNET_DISK_file_write (f_m, data, strlen (data)))
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Cannot write data to master file %u\n", c_m);
- GNUNET_free (data);
-
-
- for (c_s = 0; c_s < l->lp[c_m].peer->num_partners; c_s++)
- {
- plt = &cur_lt->slaves_log[c_s];
- /* Log partners */
-
- /* Assembling slave string */
- GNUNET_asprintf (&data,
- "%llu;%llu;%u;%u;%u;%u;%u;%u;%.3f;%u;%u;%llu;%u;%u;%u;%u;%.3f;%.3f\n",
- (long long unsigned
- int) cur_lt->timestamp.abs_value_us,
- (long long unsigned
- int) GNUNET_TIME_absolute_get_difference (
- l->lp[c_m].start,
- cur_lt
- ->timestamp)
- .rel_value_us / 1000,
- plt->total_messages_sent,
- plt->total_bytes_sent,
- plt->throughput_sent,
- plt->total_messages_received,
- plt->total_bytes_received,
- plt->throughput_recv,
- (double) plt->app_rtt / 1000,
- plt->bandwidth_in,
- plt->bandwidth_out,
- (unsigned long long) plt->ats_delay.rel_value_us,
- plt->ats_distance,
- plt->ats_network_type,
- plt->ats_utilization_out,
- plt->ats_utilization_in,
- plt->pref_bandwidth,
- plt->pref_delay);
-
- if (l->verbose)
- fprintf (stderr,
- "\t Slave [%u]: %u %u %u ; %u %u %u rtt %u delay %llu bw_in %u bw_out %u \n",
- plt->slave->no,
- plt->total_messages_sent,
- plt->total_bytes_sent,
- plt->throughput_sent,
- plt->total_messages_received,
- plt->total_bytes_received,
- plt->throughput_recv,
- plt->app_rtt,
- (long long unsigned int) plt->ats_delay.rel_value_us,
- plt->bandwidth_in,
- plt->bandwidth_out);
-
- if (GNUNET_SYSERR == GNUNET_DISK_file_write (f[c_s], data, strlen (
- data)))
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Cannot write data to log file `%s'\n",
- filename_slaves[c_s]);
- GNUNET_free (data);
- }
- }
-
- for (c_s = 0; c_s < l->lp[c_m].peer->num_partners; c_s++)
- {
- if (GNUNET_SYSERR == GNUNET_DISK_file_close (f[c_s]))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Cannot close log file for master[%u] slave[%u]\n", c_m,
- c_s);
- continue;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Data file successfully written to log file for `%s'\n",
- filename_slaves[c_s]);
- }
-
- if (GNUNET_SYSERR == GNUNET_DISK_file_close (f_m))
- {
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
- "close",
- filename_master);
- GNUNET_free (filename_master);
- return;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Data file successfully written to log file for master `%s'\n",
- filename_master);
-
- if (GNUNET_YES == plots)
- {
- write_throughput_gnuplot_script (filename_master, &l->lp[c_m],
- filename_slaves, l->num_slaves);
- write_rtt_gnuplot_script (filename_master, &l->lp[c_m], filename_slaves,
- l->num_slaves);
- write_bw_gnuplot_script (filename_master, &l->lp[c_m], filename_slaves,
- l->num_slaves);
- }
- }
- GNUNET_free (filename_master);
-}
-
-
-/**
- * Log all data now
- *
- * @param l logging handle to use
- */
-void
-GNUNET_ATS_TEST_logging_now (struct LoggingHandle *l)
-{
- struct LoggingPeer *bp;
- struct PeerLoggingTimestep *mlt;
- struct PeerLoggingTimestep *prev_log_mlt;
- struct PartnerLoggingTimestep *slt;
- struct PartnerLoggingTimestep *prev_log_slt;
- struct BenchmarkPartner *p;
- struct GNUNET_TIME_Relative delta;
- int c_s;
- int c_m;
- unsigned int app_rtt;
- double mult;
-
- if (GNUNET_YES != l->running)
- return;
-
- for (c_m = 0; c_m < l->num_masters; c_m++)
- {
- bp = &l->lp[c_m];
- mlt = GNUNET_new (struct PeerLoggingTimestep);
- GNUNET_CONTAINER_DLL_insert_tail (l->lp[c_m].head, l->lp[c_m].tail, mlt);
- prev_log_mlt = mlt->prev;
-
- /* Collect data */
- /* Current master state */
- mlt->timestamp = GNUNET_TIME_absolute_get ();
- mlt->total_bytes_sent = bp->peer->total_bytes_sent;
- mlt->total_messages_sent = bp->peer->total_messages_sent;
- mlt->total_bytes_received = bp->peer->total_bytes_received;
- mlt->total_messages_received = bp->peer->total_messages_received;
-
- /* Throughput */
- if (NULL == prev_log_mlt)
- {
- /* Get difference to start */
- delta = GNUNET_TIME_absolute_get_difference (l->lp[c_m].start,
- mlt->timestamp);
- }
- else
- {
- /* Get difference to last timestep */
- delta = GNUNET_TIME_absolute_get_difference (mlt->prev->timestamp,
- mlt->timestamp);
- }
-
- /* Multiplication factor for throughput calculation */
- mult = (double) GNUNET_TIME_UNIT_SECONDS.rel_value_us
- / (delta.rel_value_us);
-
- /* Total throughput */
- if (NULL != prev_log_mlt)
- {
- if (mlt->total_bytes_sent - mlt->prev->total_bytes_sent > 0)
- {
- mlt->total_throughput_send = mult * (mlt->total_bytes_sent
- - mlt->prev->total_bytes_sent);
- }
- else
- {
- mlt->total_throughput_send = 0;
- // mlt->total_throughput_send = prev_log_mlt->total_throughput_send; /* no msgs send */
- }
-
- if (mlt->total_bytes_received - mlt->prev->total_bytes_received > 0)
- {
- mlt->total_throughput_recv = mult * (mlt->total_bytes_received
- - mlt->prev->total_bytes_received);
- }
- else
- {
- mlt->total_throughput_recv = 0;
- // mlt->total_throughput_recv = prev_log_mlt->total_throughput_recv; /* no msgs received */
- }
- }
- else
- {
- mlt->total_throughput_send = mult * mlt->total_bytes_sent;
- mlt->total_throughput_recv = mult * mlt->total_bytes_received;
- }
-
- if (GNUNET_YES == l->verbose)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Master[%u] delta: %llu us, bytes (sent/received): %u / %u; throughput send/recv: %u / %u\n",
- c_m,
- (unsigned long long) delta.rel_value_us,
- mlt->total_bytes_sent,
- mlt->total_bytes_received,
- mlt->total_throughput_send,
- mlt->total_throughput_recv);
- }
-
- mlt->slaves_log = GNUNET_malloc (bp->peer->num_partners
- * sizeof(struct PartnerLoggingTimestep));
-
- for (c_s = 0; c_s < bp->peer->num_partners; c_s++)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Collect logging data master[%u] slave [%u]\n", c_m, c_s);
-
- p = &bp->peer->partners[c_s];
- slt = &mlt->slaves_log[c_s];
-
- slt->slave = p->dest;
- /* Bytes sent from master to this slave */
- slt->total_bytes_sent = p->bytes_sent;
- /* Messages sent from master to this slave */
- slt->total_messages_sent = p->messages_sent;
- /* Bytes master received from this slave */
- slt->total_bytes_received = p->bytes_received;
- /* Messages master received from this slave */
- slt->total_messages_received = p->messages_received;
- slt->total_app_rtt = p->total_app_rtt;
- /* ats performance information */
- slt->ats_delay = p->props.delay;
- slt->ats_distance = p->props.distance;
- slt->ats_network_type = p->props.scope;
- slt->ats_utilization_in = p->props.utilization_out;
- slt->ats_utilization_out = p->props.utilization_out;
- slt->bandwidth_in = p->bandwidth_in;
- slt->bandwidth_out = p->bandwidth_out;
- slt->pref_bandwidth = p->pref_bandwidth;
- slt->pref_delay = p->pref_delay;
-
- /* Total application level rtt */
- if (NULL == prev_log_mlt)
- {
- if (0 != slt->total_messages_sent)
- app_rtt = slt->total_app_rtt / slt->total_messages_sent;
- else
- app_rtt = 0;
- }
- else
- {
- prev_log_slt = &prev_log_mlt->slaves_log[c_s];
- if ((slt->total_messages_sent - prev_log_slt->total_messages_sent) > 0)
- app_rtt = (slt->total_app_rtt - prev_log_slt->total_app_rtt)
- / (slt->total_messages_sent
- - prev_log_slt->total_messages_sent);
- else
- {
- app_rtt = prev_log_slt->app_rtt; /* No messages were */
- }
- }
- slt->app_rtt = app_rtt;
-
- /* Partner throughput */
- if (NULL != prev_log_mlt)
- {
- prev_log_slt = &prev_log_mlt->slaves_log[c_s];
- if (slt->total_bytes_sent > prev_log_slt->total_bytes_sent)
- slt->throughput_sent = mult * (slt->total_bytes_sent
- - prev_log_slt->total_bytes_sent);
- else
- slt->throughput_sent = 0;
-
- if (slt->total_bytes_received > prev_log_slt->total_bytes_received)
- slt->throughput_recv = mult
- * (slt->total_bytes_received
- - prev_log_slt->total_bytes_received);
- else
- slt->throughput_recv = 0;
- }
- else
- {
- slt->throughput_sent = mult * slt->total_bytes_sent;
- slt->throughput_recv = mult * slt->total_bytes_received;
- }
-
- if (GNUNET_YES == l->verbose)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Master [%u] -> Slave [%u]: delta: %llu us, bytes (sent/received): %u / %u; throughput send/recv: %u / %u\n",
- c_m, c_s,
- (unsigned long long) delta.rel_value_us,
- mlt->total_bytes_sent,
- mlt->total_bytes_received,
- slt->throughput_sent,
- slt->throughput_recv);
- }
- else
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Master [%u]: slave [%u]\n",
- bp->peer->no, p->dest->no);
- }
- }
-}
-
-
-static void
-collect_log_task (void *cls)
-{
- struct LoggingHandle *l = cls;
-
- l->log_task = NULL;
- GNUNET_ATS_TEST_logging_now (l);
- l->log_task = GNUNET_SCHEDULER_add_delayed (l->frequency,
- &collect_log_task,
- l);
-}
-
-
-/**
- * Stop logging
- *
- * @param l the logging handle
- */
-void
-GNUNET_ATS_TEST_logging_stop (struct LoggingHandle *l)
-{
- if (GNUNET_YES != l->running)
- return;
-
- if (NULL != l->log_task)
- {
- GNUNET_SCHEDULER_cancel (l->log_task);
- l->log_task = NULL;
- }
- l->running = GNUNET_NO;
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _ ("Stop logging\n"));
-}
-
-
-/**
- * Clean up logging data
- *
- * @param l the logging handle
- */
-void
-GNUNET_ATS_TEST_logging_clean_up (struct LoggingHandle *l)
-{
- int c_m;
- struct PeerLoggingTimestep *cur;
-
- if (GNUNET_YES == l->running)
- GNUNET_ATS_TEST_logging_stop (l);
-
- for (c_m = 0; c_m < l->num_masters; c_m++)
- {
- while (NULL != (cur = l->lp[c_m].head))
- {
- GNUNET_CONTAINER_DLL_remove (l->lp[c_m].head, l->lp[c_m].tail, cur);
- GNUNET_free (cur->slaves_log);
- GNUNET_free (cur);
- }
- }
-
- GNUNET_free (l->lp);
- GNUNET_free (l);
-}
-
-
-/**
- * Start logging
- *
- * @param log_frequency the logging frequency
- * @param testname the testname
- * @param masters the master peers used for benchmarking
- * @param num_masters the number of master peers
- * @param num_slaves the number of slave peers
- * @param verbose verbose logging
- * @return the logging handle or NULL on error
- */
-struct LoggingHandle *
-GNUNET_ATS_TEST_logging_start (struct GNUNET_TIME_Relative log_frequency,
- const char *testname,
- struct BenchmarkPeer *masters,
- int num_masters,
- int num_slaves,
- int verbose)
-{
- struct LoggingHandle *l;
- int c_m;
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _ ("Start logging `%s'\n"), testname);
-
- l = GNUNET_new (struct LoggingHandle);
- l->num_masters = num_masters;
- l->num_slaves = num_slaves;
- l->name = testname;
- l->frequency = log_frequency;
- l->verbose = verbose;
- l->lp = GNUNET_malloc (num_masters * sizeof(struct LoggingPeer));
-
- for (c_m = 0; c_m < num_masters; c_m++)
- {
- l->lp[c_m].peer = &masters[c_m];
- l->lp[c_m].start = GNUNET_TIME_absolute_get ();
- }
-
- /* Schedule logging task */
- l->log_task = GNUNET_SCHEDULER_add_now (&collect_log_task, l);
- l->running = GNUNET_YES;
-
- return l;
-}
-
-
-/* end of file ats-testing-log.c */
diff --git a/src/ats-tests/ats-testing-preferences.c b/src/ats-tests/ats-testing-preferences.c
deleted file mode 100644
index f30fde960..000000000
--- a/src/ats-tests/ats-testing-preferences.c
+++ /dev/null
@@ -1,265 +0,0 @@
-/*
- This file is part of GNUnet.
- Copyright (C) 2010-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 ats-tests/ats-testing-preferences.c
- * @brief ats benchmark: preference generator
- * @author Christian Grothoff
- * @author Matthias Wachs
- */
-#include "platform.h"
-#include "gnunet_util_lib.h"
-#include "ats-testing.h"
-
-static struct PreferenceGenerator *pg_head;
-static struct PreferenceGenerator *pg_tail;
-
-extern struct GNUNET_ATS_TEST_Topology *top;
-
-static double
-get_preference (struct PreferenceGenerator *pg)
-{
- struct GNUNET_TIME_Relative time_delta;
- double delta_value;
- double pref_value;
-
- /* Calculate the current preference value */
- switch (pg->type)
- {
- case GNUNET_ATS_TEST_TG_CONSTANT:
- pref_value = pg->base_value;
- break;
-
- case GNUNET_ATS_TEST_TG_LINEAR:
- time_delta = GNUNET_TIME_absolute_get_duration (pg->time_start);
- /* Calculate point of time in the current period */
- time_delta.rel_value_us = time_delta.rel_value_us
- % pg->duration_period.rel_value_us;
- delta_value = ((double) time_delta.rel_value_us
- / pg->duration_period.rel_value_us) * (pg->max_value
- - pg->base_value);
- if ((pg->max_value < pg->base_value) &&
- ((pg->max_value - pg->base_value) > pg->base_value))
- {
- /* This will cause an underflow */
- GNUNET_break (0);
- }
- pref_value = pg->base_value + delta_value;
- break;
-
- case GNUNET_ATS_TEST_TG_RANDOM:
- delta_value = (double) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
- 10000 * (pg->max_value
- - pg->base_value))
- / 10000;
- pref_value = pg->base_value + delta_value;
- break;
-
- case GNUNET_ATS_TEST_TG_SINUS:
- time_delta = GNUNET_TIME_absolute_get_duration (pg->time_start);
- /* Calculate point of time in the current period */
- time_delta.rel_value_us = time_delta.rel_value_us
- % pg->duration_period.rel_value_us;
- if ((pg->max_value - pg->base_value) > pg->base_value)
- {
- /* This will cause an underflow for second half of sinus period,
- * will be detected in general when experiments are loaded */
- GNUNET_break (0);
- }
- delta_value = (pg->max_value - pg->base_value)
- * sin ((2 * M_PI)
- / ((double) pg->duration_period.rel_value_us)
- * time_delta.rel_value_us);
- pref_value = pg->base_value + delta_value;
- break;
-
- default:
- pref_value = 0.0;
- break;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Current preference value is %f\n",
- pref_value);
- return pref_value;
-}
-
-
-static void
-set_pref_task (void *cls)
-{
- struct BenchmarkPartner *p = cls;
- double pref_value;
-
- p->pg->set_task = NULL;
-
- pref_value = get_preference (p->pg);
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Setting preference for master [%u] and slave [%u] for %s to %f\n",
- p->me->no, p->dest->no,
- GNUNET_ATS_print_preference_type (p->pg->kind), pref_value);
-
- GNUNET_ATS_performance_change_preference (p->me->ats_perf_handle,
- &p->dest->id,
- p->pg->kind,
- pref_value,
- GNUNET_ATS_PREFERENCE_END);
-
- switch (p->pg->kind)
- {
- case GNUNET_ATS_PREFERENCE_BANDWIDTH:
- p->pref_bandwidth = pref_value;
- break;
-
- case GNUNET_ATS_PREFERENCE_LATENCY:
- p->pref_delay = pref_value;
- break;
-
- default:
- break;
- }
-
- p->pg->set_task = GNUNET_SCHEDULER_add_delayed (p->pg->frequency,
- set_pref_task, p);
-}
-
-
-/**
- * Generate between the source master and the partner and set preferences with a
- * value depending on the generator.
- *
- * @param src source
- * @param dest partner
- * @param type type of preferences to generate
- * @param base_value traffic base rate to send data with
- * @param value_rate traffic maximum rate to send data with
- * @param period duration of a period of preferences generation (~ 1/frequency)
- * @param frequency how long to generate preferences
- * @param kind ATS preference to generate
- * @return the preference generator
- */
-struct PreferenceGenerator *
-GNUNET_ATS_TEST_generate_preferences_start (struct BenchmarkPeer *src,
- struct BenchmarkPartner *dest,
- enum GeneratorType type,
- unsigned int base_value,
- unsigned int value_rate,
- struct GNUNET_TIME_Relative period,
- struct GNUNET_TIME_Relative
- frequency,
- enum GNUNET_ATS_PreferenceKind kind)
-{
- struct PreferenceGenerator *pg;
-
- if (NULL != dest->pg)
- {
- GNUNET_break (0);
- return NULL;
- }
-
- pg = GNUNET_new (struct PreferenceGenerator);
- GNUNET_CONTAINER_DLL_insert (pg_head, pg_tail, pg);
- pg->type = type;
- pg->src = src;
- pg->dest = dest;
- pg->kind = kind;
- pg->base_value = base_value;
- pg->max_value = value_rate;
- pg->duration_period = period;
- pg->frequency = frequency;
- pg->time_start = GNUNET_TIME_absolute_get ();
-
- switch (type)
- {
- case GNUNET_ATS_TEST_TG_CONSTANT:
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Setting up constant preference generator master[%u] `%s' and slave [%u] `%s' max %u Bips\n",
- dest->me->no, GNUNET_i2s (&dest->me->id),
- dest->dest->no, GNUNET_i2s (&dest->dest->id),
- base_value);
- break;
-
- case GNUNET_ATS_TEST_TG_LINEAR:
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Setting up linear preference generator master[%u] `%s' and slave [%u] `%s' min %u Bips max %u Bips\n",
- dest->me->no, GNUNET_i2s (&dest->me->id),
- dest->dest->no, GNUNET_i2s (&dest->dest->id),
- base_value, value_rate);
- break;
-
- case GNUNET_ATS_TEST_TG_SINUS:
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Setting up sinus preference generator master[%u] `%s' and slave [%u] `%s' baserate %u Bips, amplitude %u Bps\n",
- dest->me->no, GNUNET_i2s (&dest->me->id),
- dest->dest->no, GNUNET_i2s (&dest->dest->id),
- base_value, value_rate);
- break;
-
- case GNUNET_ATS_TEST_TG_RANDOM:
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Setting up random preference generator master[%u] `%s' and slave [%u] `%s' min %u Bips max %u Bps\n",
- dest->me->no, GNUNET_i2s (&dest->me->id),
- dest->dest->no, GNUNET_i2s (&dest->dest->id),
- base_value, value_rate);
- break;
-
- default:
- break;
- }
-
- dest->pg = pg;
- pg->set_task = GNUNET_SCHEDULER_add_now (&set_pref_task, dest);
- return pg;
-}
-
-
-void
-GNUNET_ATS_TEST_generate_preferences_stop (struct PreferenceGenerator *pg)
-{
- GNUNET_CONTAINER_DLL_remove (pg_head, pg_tail, pg);
- pg->dest->pg = NULL;
-
- if (NULL != pg->set_task)
- {
- GNUNET_SCHEDULER_cancel (pg->set_task);
- pg->set_task = NULL;
- }
-
- GNUNET_free (pg);
-}
-
-
-/**
- * Stop all preferences generators
- */
-void
-GNUNET_ATS_TEST_generate_preferences_stop_all ()
-{
- struct PreferenceGenerator *cur;
- struct PreferenceGenerator *next;
-
- next = pg_head;
- for (cur = next; NULL != cur; cur = next)
- {
- next = cur->next;
- GNUNET_ATS_TEST_generate_preferences_stop (cur);
- }
-}
-
-
-/* end of file ats-testing-preferences.c */
diff --git a/src/ats-tests/ats-testing-traffic.c b/src/ats-tests/ats-testing-traffic.c
deleted file mode 100644
index f19eac871..000000000
--- a/src/ats-tests/ats-testing-traffic.c
+++ /dev/null
@@ -1,393 +0,0 @@
-/*
- This file is part of GNUnet.
- Copyright (C) 2010-2013, 2016 GNUnet e.V.
-
- GNUnet is free software: you can redistribute it and/or modify it
- under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation, either version 3 of the License,
- or (at your option) any later version.
-
- GNUnet is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-
- SPDX-License-Identifier: AGPL3.0-or-later
- */
-/**
- * @file ats-tests/ats-testing-traffic.c
- * @brief ats benchmark: traffic generator
- * @author Christian Grothoff
- * @author Matthias Wachs
- */
-#include "platform.h"
-#include "gnunet_util_lib.h"
-#include "ats-testing.h"
-
-static struct TrafficGenerator *tg_head;
-static struct TrafficGenerator *tg_tail;
-
-extern struct GNUNET_ATS_TEST_Topology *top;
-
-static struct GNUNET_TIME_Relative
-get_delay (struct TrafficGenerator *tg)
-{
- struct GNUNET_TIME_Relative delay;
- struct GNUNET_TIME_Relative time_delta;
- long long int cur_rate;
- long long int delta_rate;
-
- delay.rel_value_us = 0;
-
- /* Calculate the current transmission rate based on the type of traffic */
- switch (tg->type)
- {
- case GNUNET_ATS_TEST_TG_CONSTANT:
- if (UINT32_MAX == tg->base_rate)
- return GNUNET_TIME_UNIT_ZERO;
- cur_rate = tg->base_rate;
- break;
-
- case GNUNET_ATS_TEST_TG_LINEAR:
- time_delta = GNUNET_TIME_absolute_get_duration (tg->time_start);
- /* Calculate point of time in the current period */
- time_delta.rel_value_us = time_delta.rel_value_us
- % tg->duration_period.rel_value_us;
- delta_rate = ((double) time_delta.rel_value_us
- / tg->duration_period.rel_value_us)
- * (tg->max_rate - tg->base_rate);
- if ((tg->max_rate < tg->base_rate) && ((tg->max_rate - tg->base_rate) >
- tg->base_rate))
- {
- /* This will cause an underflow */
- GNUNET_break (0);
- }
- cur_rate = tg->base_rate + delta_rate;
- break;
-
- case GNUNET_ATS_TEST_TG_RANDOM:
- cur_rate = tg->base_rate + GNUNET_CRYPTO_random_u32 (
- GNUNET_CRYPTO_QUALITY_WEAK,
- tg->max_rate
- - tg->base_rate);
- break;
-
- case GNUNET_ATS_TEST_TG_SINUS:
- time_delta = GNUNET_TIME_absolute_get_duration (tg->time_start);
- /* Calculate point of time in the current period */
- time_delta.rel_value_us = time_delta.rel_value_us
- % tg->duration_period.rel_value_us;
- if ((tg->max_rate - tg->base_rate) > tg->base_rate)
- {
- /* This will cause an underflow for second half of sinus period,
- * will be detected in general when experiments are loaded */
- GNUNET_break (0);
- }
- delta_rate = (tg->max_rate - tg->base_rate)
- * sin ((2 * M_PI)
- / ((double) tg->duration_period.rel_value_us)
- * time_delta.rel_value_us);
- cur_rate = tg->base_rate + delta_rate;
- break;
-
- default:
- return delay;
- break;
- }
-
- if (cur_rate < 0)
- {
- cur_rate = 1;
- }
- /* Calculate the delay for the next message based on the current delay */
- delay.rel_value_us = GNUNET_TIME_UNIT_SECONDS.rel_value_us
- * TEST_MESSAGE_SIZE / cur_rate;
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Current rate is %lld, calculated delay is %llu\n",
- cur_rate,
- (unsigned long long) delay.rel_value_us);
- return delay;
-}
-
-
-static void
-update_ping_data (void *cls)
-{
- struct BenchmarkPartner *p = cls;
- struct GNUNET_TIME_Relative delay;
-
- p->messages_sent++;
- p->bytes_sent += TEST_MESSAGE_SIZE;
- p->me->total_messages_sent++;
- p->me->total_bytes_sent += TEST_MESSAGE_SIZE;
-
- if (NULL == p->tg)
- {
- GNUNET_break (0);
- return;
- }
- delay = get_delay (p->tg);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Delay for next transmission %s\n",
- GNUNET_STRINGS_relative_time_to_string (delay,
- GNUNET_YES));
- p->tg->next_ping_transmission
- = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (),
- delay);
-}
-
-
-static void
-comm_schedule_send (void *cls)
-{
- struct BenchmarkPartner *p = cls;
- struct TestMessage *msg;
- struct GNUNET_MQ_Envelope *env;
-
- p->tg->send_task = NULL;
- p->last_message_sent = GNUNET_TIME_absolute_get ();
- env = GNUNET_MQ_msg (msg,
- TEST_MESSAGE_TYPE_PING);
- memset (msg->padding,
- 'a',
- sizeof(msg->padding));
- GNUNET_MQ_notify_sent (env,
- &update_ping_data,
- p);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Master [%u]: Sending PING to [%u]\n",
- p->me->no,
- p->dest->no);
- GNUNET_MQ_send (p->mq,
- env);
-}
-
-
-static void
-update_pong_data (void *cls)
-{
- struct BenchmarkPartner *p = cls;
-
- p->messages_sent++;
- p->bytes_sent += TEST_MESSAGE_SIZE;
- p->me->total_messages_sent++;
- p->me->total_bytes_sent += TEST_MESSAGE_SIZE;
-}
-
-
-void
-GNUNET_ATS_TEST_traffic_handle_ping (struct BenchmarkPartner *p)
-{
- struct TestMessage *msg;
- struct GNUNET_MQ_Envelope *env;
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Slave [%u]: Received PING from [%u], sending PONG\n",
- p->me->no,
- p->dest->no);
- p->messages_received++;
- p->bytes_received += TEST_MESSAGE_SIZE;
- p->me->total_messages_received++;
- p->me->total_bytes_received += TEST_MESSAGE_SIZE;
-
-
- env = GNUNET_MQ_msg (msg,
- TEST_MESSAGE_TYPE_PING);
- memset (msg->padding,
- 'a',
- sizeof(msg->padding));
- GNUNET_MQ_notify_sent (env,
- &update_pong_data,
- p);
- GNUNET_MQ_send (p->mq,
- env);
-}
-
-
-void
-GNUNET_ATS_TEST_traffic_handle_pong (struct BenchmarkPartner *p)
-{
- struct GNUNET_TIME_Relative left;
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Master [%u]: Received PONG from [%u], next message\n",
- p->me->no,
- p->dest->no);
-
- p->messages_received++;
- p->bytes_received += TEST_MESSAGE_SIZE;
- p->me->total_messages_received++;
- p->me->total_bytes_received += TEST_MESSAGE_SIZE;
- p->total_app_rtt += GNUNET_TIME_absolute_get_difference (p->last_message_sent,
- GNUNET_TIME_absolute_get ())
- .rel_value_us;
-
- /* Schedule next send event */
- if (NULL == p->tg)
- return;
-
- left = GNUNET_TIME_absolute_get_remaining (p->tg->next_ping_transmission);
- if (UINT32_MAX == p->tg->base_rate)
- {
- p->tg->send_task = GNUNET_SCHEDULER_add_now (&comm_schedule_send, p);
- }
- else if (0 == left.rel_value_us)
- {
- p->tg->send_task = GNUNET_SCHEDULER_add_now (&comm_schedule_send, p);
- }
- else
- {
- /* Enforce minimum transmission rate 1 msg / sec */
- if (GNUNET_TIME_UNIT_SECONDS.rel_value_us == (left =
- GNUNET_TIME_relative_min (
- left,
- GNUNET_TIME_UNIT_SECONDS))
- .rel_value_us)
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Enforcing minimum send rate between master [%u] and slave [%u]\n",
- p->me->no, p->dest->no);
- p->tg->send_task = GNUNET_SCHEDULER_add_delayed (left,
- &comm_schedule_send, p);
- }
-}
-
-
-/**
- * Generate between the source master and the partner and send traffic with a
- * maximum rate.
- *
- * @param src traffic source
- * @param dest traffic partner
- * @param type type of traffic to generate
- * @param base_rate traffic base rate to send data with
- * @param max_rate traffic maximum rate to send data with
- * @param period duration of a period of traffic generation (~ 1/frequency)
- * @param duration how long to generate traffic
- * @return the traffic generator
- */
-struct TrafficGenerator *
-GNUNET_ATS_TEST_generate_traffic_start (struct BenchmarkPeer *src,
- struct BenchmarkPartner *dest,
- enum GeneratorType type,
- unsigned int base_rate,
- unsigned int max_rate,
- struct GNUNET_TIME_Relative period,
- struct GNUNET_TIME_Relative duration)
-{
- struct TrafficGenerator *tg;
-
- if (NULL != dest->tg)
- {
- GNUNET_break (0);
- return NULL;
- }
-
- tg = GNUNET_new (struct TrafficGenerator);
- GNUNET_CONTAINER_DLL_insert (tg_head,
- tg_tail,
- tg);
- tg->type = type;
- tg->src = src;
- tg->dest = dest;
- tg->base_rate = base_rate;
- tg->max_rate = max_rate;
- tg->duration_period = period;
- tg->time_start = GNUNET_TIME_absolute_get ();
- tg->next_ping_transmission = GNUNET_TIME_UNIT_FOREVER_ABS;
-
- switch (type)
- {
- case GNUNET_ATS_TEST_TG_CONSTANT:
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Setting up constant traffic generator master[%u] `%s' and slave [%u] `%s' max %u Bips\n",
- dest->me->no,
- GNUNET_i2s (&dest->me->id),
- dest->dest->no,
- GNUNET_i2s (&dest->dest->id),
- base_rate);
- break;
-
- case GNUNET_ATS_TEST_TG_LINEAR:
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Setting up linear traffic generator master[%u] `%s' and slave [%u] `%s' min %u Bips max %u Bips\n",
- dest->me->no,
- GNUNET_i2s (&dest->me->id),
- dest->dest->no,
- GNUNET_i2s (&dest->dest->id),
- base_rate,
- max_rate);
- break;
-
- case GNUNET_ATS_TEST_TG_SINUS:
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Setting up sinus traffic generator master[%u] `%s' and slave [%u] `%s' baserate %u Bips, amplitude %u Bps\n",
- dest->me->no,
- GNUNET_i2s (&dest->me->id),
- dest->dest->no,
- GNUNET_i2s (&dest->dest->id),
- base_rate,
- max_rate);
- break;
-
- case GNUNET_ATS_TEST_TG_RANDOM:
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Setting up random traffic generator master[%u] `%s' and slave [%u] `%s' min %u Bips max %u Bps\n",
- dest->me->no,
- GNUNET_i2s (&dest->me->id),
- dest->dest->no,
- GNUNET_i2s (&dest->dest->id),
- base_rate,
- max_rate);
- break;
-
- default:
- break;
- }
-
- dest->tg = tg;
- tg->send_task
- = GNUNET_SCHEDULER_add_now (&comm_schedule_send,
- dest);
- return tg;
-}
-
-
-void
-GNUNET_ATS_TEST_generate_traffic_stop (struct TrafficGenerator *tg)
-{
- GNUNET_CONTAINER_DLL_remove (tg_head,
- tg_tail,
- tg);
- tg->dest->tg = NULL;
- if (NULL != tg->send_task)
- {
- GNUNET_SCHEDULER_cancel (tg->send_task);
- tg->send_task = NULL;
- }
- GNUNET_free (tg);
-}
-
-
-/**
- * Stop all traffic generators
- */
-void
-GNUNET_ATS_TEST_generate_traffic_stop_all ()
-{
- struct TrafficGenerator *cur;
- struct TrafficGenerator *next;
-
- next = tg_head;
- for (cur = next; NULL != cur; cur = next)
- {
- next = cur->next;
- GNUNET_ATS_TEST_generate_traffic_stop (cur);
- }
-}
-
-
-/* end of file ats-testing-traffic.c */
diff --git a/src/ats-tests/ats-testing.c b/src/ats-tests/ats-testing.c
deleted file mode 100644
index c6ba8533d..000000000
--- a/src/ats-tests/ats-testing.c
+++ /dev/null
@@ -1,975 +0,0 @@
-/*
- This file is part of GNUnet.
- Copyright (C) 2010-2013, 2016, 2017 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 ats-tests/ats-testing.c
- * @brief ats testing library: setup topology
- * solvers
- * @author Christian Grothoff
- * @author Matthias Wachs
- */
-#include "ats-testing.h"
-
-
-/**
- * Connect peers with testbed
- */
-struct TestbedConnectOperation
-{
- /**
- * The benchmarking master initiating this connection
- */
- struct BenchmarkPeer *master;
-
- /**
- * The benchmarking slave to connect to
- */
- struct BenchmarkPeer *slave;
-
- /**
- * Testbed operation to connect peers
- */
- struct GNUNET_TESTBED_Operation *connect_op;
-};
-
-struct GNUNET_CONFIGURATION_Handle *cfg;
-
-struct GNUNET_ATS_TEST_Topology *top;
-
-
-/**
- * Shutdown nicely
- *
- * @param cls NULL
- */
-static void
-do_shutdown (void *cls)
-{
- int c_m;
- int c_s;
- int c_op;
- struct BenchmarkPeer *p;
-
- top->state.benchmarking = GNUNET_NO;
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Benchmarking done\n");
-
- GNUNET_ATS_TEST_generate_traffic_stop_all ();
-
- for (c_m = 0; c_m < top->num_masters; c_m++)
- {
- p = &top->mps[c_m];
- if (NULL != top->mps[c_m].peer_id_op)
- {
- GNUNET_TESTBED_operation_done (p->peer_id_op);
- p->peer_id_op = NULL;
- }
-
- if (NULL != p->ats_task)
- GNUNET_SCHEDULER_cancel (p->ats_task);
- p->ats_task = NULL;
-
- for (c_op = 0; c_op < p->num_partners; c_op++)
- {
- if ((NULL != p->core_connect_ops) &&
- (NULL != p->core_connect_ops[c_op].connect_op))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Failed to connect peer 0 and %u\n",
- c_op);
- GNUNET_TESTBED_operation_done (p->core_connect_ops[c_op].connect_op);
- p->core_connect_ops[c_op].connect_op = NULL;
- }
- }
-
- if (NULL != p->ats_perf_op)
- {
- GNUNET_TESTBED_operation_done (p->ats_perf_op);
- p->ats_perf_op = NULL;
- }
-
- if (NULL != p->comm_op)
- {
- GNUNET_TESTBED_operation_done (p->comm_op);
- p->comm_op = NULL;
- }
- GNUNET_free (p->core_connect_ops);
- GNUNET_free (p->partners);
- p->partners = NULL;
- }
-
- for (c_s = 0; c_s < top->num_slaves; c_s++)
- {
- p = &top->sps[c_s];
- if (NULL != p->peer_id_op)
- {
- GNUNET_TESTBED_operation_done (p->peer_id_op);
- p->peer_id_op = NULL;
- }
- if (NULL != p->ats_perf_op)
- {
- GNUNET_TESTBED_operation_done (p->ats_perf_op);
- p->ats_perf_op = NULL;
- }
- if (NULL != p->comm_op)
- {
- GNUNET_TESTBED_operation_done (p->comm_op);
- p->comm_op = NULL;
- }
- GNUNET_free (p->partners);
- p->partners = NULL;
- }
- GNUNET_SCHEDULER_shutdown ();
- GNUNET_free (top);
- top = NULL;
-}
-
-
-static struct BenchmarkPartner *
-find_partner (struct BenchmarkPeer *me,
- const struct GNUNET_PeerIdentity *peer)
-{
- int c_m;
-
- for (c_m = 0; c_m < me->num_partners; c_m++)
- {
- /* Find a partner with other as destination */
- if (0 == GNUNET_memcmp (peer,
- &me->partners[c_m].dest->id))
- {
- return &me->partners[c_m];
- }
- }
-
- return NULL;
-}
-
-
-static struct BenchmarkPeer *
-find_peer (const struct GNUNET_PeerIdentity *peer)
-{
- int c_p;
-
- for (c_p = 0; c_p < top->num_masters; c_p++)
- {
- if (0 == GNUNET_memcmp (&top->mps[c_p].id,
- peer))
- return &top->mps[c_p];
- }
-
- for (c_p = 0; c_p < top->num_slaves; c_p++)
- {
- if (0 == GNUNET_memcmp (&top->sps[c_p].id,
- peer))
- return &top->sps[c_p];
- }
- return NULL;
-}
-
-
-/**
- * Method called whenever a given peer connects.
- *
- * @param cls closure
- * @param peer peer identity this notification is about
- * @param mq queue to use to send messages to @a peer
- * @return the `struct BenchmarkPartner` of @a peer
- */
-static void *
-comm_connect_cb (void *cls,
- const struct GNUNET_PeerIdentity *peer,
- struct GNUNET_MQ_Handle *mq)
-{
- struct BenchmarkPeer *me = cls;
- struct BenchmarkPeer *remote;
- struct BenchmarkPartner *p;
- char *id;
- int c;
- int completed;
-
- remote = find_peer (peer);
- if (NULL == remote)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Unknown peer connected: `%s'\n",
- GNUNET_i2s (peer));
- GNUNET_break (0);
- return NULL;
- }
-
- id = GNUNET_strdup (GNUNET_i2s (&me->id));
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "%s [%u] `%s' connected to %s [%u] %s\n",
- (me->master == GNUNET_YES) ? "Master" : "Slave",
- me->no,
- id,
- (remote->master == GNUNET_YES) ? "Master" : "Slave",
- remote->no,
- GNUNET_i2s (peer));
-
- me->core_connections++;
- if ((GNUNET_YES == me->master) &&
- (GNUNET_NO == remote->master) &&
- (GNUNET_NO == top->state.connected_CORE))
- {
- me->core_slave_connections++;
-
- if (me->core_slave_connections == top->num_slaves)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Master [%u] connected all slaves\n",
- me->no);
- }
- completed = GNUNET_YES;
- for (c = 0; c < top->num_masters; c++)
- {
- if (top->mps[c].core_slave_connections != top->num_slaves)
- completed = GNUNET_NO;
- }
- if (GNUNET_YES == completed)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "All master peers connected all slave peers\n");
- top->state.connected_CORE = GNUNET_YES;
- /* Notify about setup done */
- if (NULL != top->done_cb)
- top->done_cb (top->done_cb_cls,
- top->mps,
- top->sps);
- }
- }
- GNUNET_free (id);
- p = find_partner (me,
- peer);
- if (NULL != p)
- p->mq = mq;
- return p;
-}
-
-
-/**
- * @param cls this peer
- * @param peer id of disconnecting peer
- * @param internal_cls the `struct BenchmarkPartner` of @a peer
- */
-static void
-comm_disconnect_cb (void *cls,
- const struct GNUNET_PeerIdentity *peer,
- void *internal_cls)
-{
- struct BenchmarkPeer *me = cls;
- struct BenchmarkPartner *p = internal_cls;
- char *id;
-
- if (NULL == p)
- return;
-
- id = GNUNET_strdup (GNUNET_i2s (&me->id));
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "%s disconnected from %s\n",
- id,
- GNUNET_i2s (peer));
- GNUNET_assert (me->core_connections > 0);
- me->core_connections--;
-
- if ((GNUNET_YES == top->state.benchmarking) &&
- ((GNUNET_YES == me->master) ||
- (GNUNET_YES == p->dest->master)))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "%s disconnected from %s while benchmarking\n",
- id,
- GNUNET_i2s (peer));
- }
- GNUNET_free (id);
-}
-
-
-static void
-handle_pong (void *cls,
- const struct TestMessage *message)
-{
- struct BenchmarkPartner *p = cls;
-
- GNUNET_ATS_TEST_traffic_handle_pong (p);
-}
-
-
-static void
-handle_ping (void *cls,
- const struct TestMessage *message)
-{
- struct BenchmarkPartner *p = cls;
-
- GNUNET_ATS_TEST_traffic_handle_ping (p);
-}
-
-
-static void *
-transport_connect_adapter (void *cls,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
-{
- struct BenchmarkPeer *me = cls;
- struct GNUNET_MQ_MessageHandler handlers[] = {
- GNUNET_MQ_hd_fixed_size (ping,
- TEST_MESSAGE_TYPE_PING,
- struct TestMessage,
- me),
- GNUNET_MQ_hd_fixed_size (pong,
- TEST_MESSAGE_TYPE_PONG,
- struct TestMessage,
- me),
- GNUNET_MQ_handler_end ()
- };
-
- me->th = GNUNET_TRANSPORT_core_connect (cfg,
- &me->id,
- handlers,
- me,
- &comm_connect_cb,
- &comm_disconnect_cb,
- NULL);
- if (NULL == me->th)
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to create transport connection \n");
- return me->th;
-}
-
-
-static void
-transport_disconnect_adapter (void *cls,
- void *op_result)
-{
- struct BenchmarkPeer *me = cls;
-
- GNUNET_TRANSPORT_core_disconnect (me->th);
- me->th = NULL;
-}
-
-
-static void *
-core_connect_adapter (void *cls,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
-{
- struct BenchmarkPeer *me = cls;
- struct GNUNET_MQ_MessageHandler handlers[] = {
- GNUNET_MQ_hd_fixed_size (ping,
- TEST_MESSAGE_TYPE_PING,
- struct TestMessage,
- me),
- GNUNET_MQ_hd_fixed_size (pong,
- TEST_MESSAGE_TYPE_PONG,
- struct TestMessage,
- me),
- GNUNET_MQ_handler_end ()
- };
-
- me->ch = GNUNET_CORE_connect (cfg,
- me,
- NULL,
- &comm_connect_cb,
- &comm_disconnect_cb,
- handlers);
- if (NULL == me->ch)
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to create core connection \n");
- return me->ch;
-}
-
-
-static void
-core_disconnect_adapter (void *cls,
- void *op_result)
-{
- struct BenchmarkPeer *me = cls;
-
- GNUNET_CORE_disconnect (me->ch);
- me->ch = NULL;
-}
-
-
-static void
-connect_completion_callback (void *cls,
- struct GNUNET_TESTBED_Operation *op,
- const char *emsg)
-{
- struct TestbedConnectOperation *cop = cls;
- static int ops = 0;
- int c;
-
- if (NULL == emsg)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _ ("Connected master [%u] with slave [%u]\n"),
- cop->master->no,
- cop->slave->no);
- }
- else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _ ("Failed to connect master peer [%u] with slave [%u]\n"),
- cop->master->no, cop->slave->no);
- GNUNET_break (0);
- GNUNET_SCHEDULER_shutdown ();
- }
- GNUNET_TESTBED_operation_done (op);
- ops++;
- for (c = 0; c < top->num_slaves; c++)
- {
- if (cop == &cop->master->core_connect_ops[c])
- cop->master->core_connect_ops[c].connect_op = NULL;
- }
- if (ops == top->num_masters * top->num_slaves)
- {
- top->state.connected_PEERS = GNUNET_YES;
- }
-}
-
-
-static void
-do_connect_peers (void *cls)
-{
- int c_m;
- int c_s;
- struct BenchmarkPeer *p;
-
- if ((top->state.connected_ATS_service == GNUNET_NO) ||
- (top->state.connected_COMM_service == GNUNET_NO))
- return;
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Connecting peers on CORE level\n");
- for (c_m = 0; c_m < top->num_masters; c_m++)
- {
- p = &top->mps[c_m];
- p->core_connect_ops = GNUNET_malloc (top->num_slaves
- * sizeof(struct
- TestbedConnectOperation));
-
- for (c_s = 0; c_s < top->num_slaves; c_s++)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Connecting master [%u] with slave [%u]\n",
- p->no,
- top->sps[c_s].no);
- p->core_connect_ops[c_s].master = p;
- p->core_connect_ops[c_s].slave = &top->sps[c_s];
- p->core_connect_ops[c_s].connect_op
- = GNUNET_TESTBED_overlay_connect (NULL,
- &connect_completion_callback,
- &p->core_connect_ops[c_s],
- top->sps[c_s].peer,
- p->peer);
- if (NULL == p->core_connect_ops[c_s].connect_op)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Could not connect master [%u] and slave [%u]\n",
- p->no,
- top->sps[c_s].no);
- GNUNET_break (0);
- GNUNET_SCHEDULER_shutdown ();
- return;
- }
- }
- }
-}
-
-
-static void
-comm_connect_completion_cb (void *cls,
- struct GNUNET_TESTBED_Operation *op,
- void *ca_result,
- const char *emsg)
-{
- static int comm_done = 0;
-
- if ((NULL != emsg) || (NULL == ca_result))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Initialization failed, shutdown\n");
- GNUNET_break (0);
- GNUNET_SCHEDULER_shutdown ();
- return;
- }
- comm_done++;
-
- if (comm_done == top->num_slaves + top->num_masters)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Connected to all %s services\n",
- (GNUNET_YES == top->test_core) ? "CORE" : "TRANSPORT");
- top->state.connected_COMM_service = GNUNET_YES;
- GNUNET_SCHEDULER_add_now (&do_connect_peers,
- NULL);
- }
-}
-
-
-static void
-do_comm_connect (void *cls)
-{
- int c_s;
- int c_m;
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Connecting to all %s services\n",
- (GNUNET_YES == top->test_core) ? "CORE" : "TRANSPORT");
- for (c_m = 0; c_m < top->num_masters; c_m++)
- {
- if (GNUNET_YES == top->test_core)
- top->mps[c_m].comm_op
- = GNUNET_TESTBED_service_connect (NULL,
- top->mps[c_m].peer,
- "core",
- &comm_connect_completion_cb,
- NULL,
- &core_connect_adapter,
- &core_disconnect_adapter,
- &top->mps[c_m]);
- else
- {
- top->mps[c_m].comm_op
- = GNUNET_TESTBED_service_connect (NULL,
- top->mps[c_m].peer,
- "transport",
- &comm_connect_completion_cb,
- NULL,
- &transport_connect_adapter,
- &transport_disconnect_adapter,
- &top->mps[c_m]);
- }
- }
-
- for (c_s = 0; c_s < top->num_slaves; c_s++)
- {
- if (GNUNET_YES == top->test_core)
- top->sps[c_s].comm_op
- = GNUNET_TESTBED_service_connect (NULL,
- top->sps[c_s].peer,
- "core",
- &comm_connect_completion_cb,
- NULL,
- &core_connect_adapter,
- &core_disconnect_adapter,
- &top->sps[c_s]);
- else
- {
- top->sps[c_s].comm_op
- = GNUNET_TESTBED_service_connect (NULL,
- top->sps[c_s].peer,
- "transport",
- &comm_connect_completion_cb,
- NULL,
- &transport_connect_adapter,
- &transport_disconnect_adapter,
- &top->sps[c_s]);
- }
- }
-}
-
-
-static void
-ats_performance_info_cb (void *cls,
- const struct GNUNET_HELLO_Address *address,
- int address_active,
- struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
- struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
- const struct GNUNET_ATS_Properties *ats_prop)
-{
- struct BenchmarkPeer *me = cls;
- struct BenchmarkPartner *p;
- int log;
- char *peer_id;
-
- if (NULL == address)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Peer %u: ATS Service disconnected!\n",
- me->no);
- return;
- }
-
- p = find_partner (me,
- &address->peer);
- if (NULL == p)
- {
- /* This is not one of my partners
- * Will happen since the peers will connect to each other due to gossiping
- */
- return;
- }
- peer_id = GNUNET_strdup (GNUNET_i2s (&me->id));
-
- log = GNUNET_NO;
- if ((p->bandwidth_in != ntohl (bandwidth_in.value__)) ||
- (p->bandwidth_out != ntohl (bandwidth_out.value__)))
- log = GNUNET_YES;
- p->bandwidth_in = ntohl (bandwidth_in.value__);
- p->bandwidth_out = ntohl (bandwidth_out.value__);
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "%s [%u] received ATS information: %s\n",
- (GNUNET_YES == p->me->master) ? "Master" : "Slave",
- p->me->no,
- GNUNET_i2s (&p->dest->id));
-
- p->props.utilization_out = ats_prop->utilization_out;
- p->props.utilization_in = ats_prop->utilization_in;
- p->props.scope = ats_prop->scope;
- p->props.delay = ats_prop->delay;
- p->props.distance = ats_prop->distance;
-
- if (GNUNET_YES == log)
- top->ats_perf_cb (cls, address,
- address_active,
- bandwidth_out,
- bandwidth_in,
- ats_prop);
- GNUNET_free (peer_id);
-}
-
-
-static void *
-ats_perf_connect_adapter (void *cls,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
-{
- struct BenchmarkPeer *me = cls;
-
- me->ats_perf_handle
- = GNUNET_ATS_performance_init (cfg,
- &ats_performance_info_cb,
- me);
- if (NULL == me->ats_perf_handle)
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to create ATS performance handle \n");
- return me->ats_perf_handle;
-}
-
-
-static void
-ats_perf_disconnect_adapter (void *cls,
- void *op_result)
-{
- struct BenchmarkPeer *me = cls;
-
- GNUNET_ATS_performance_done (me->ats_perf_handle);
- me->ats_perf_handle = NULL;
-}
-
-
-static void
-ats_connect_completion_cb (void *cls,
- struct GNUNET_TESTBED_Operation *op,
- void *ca_result,
- const char *emsg)
-{
- static int op_done = 0;
-
- if ((NULL != emsg) || (NULL == ca_result))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Initialization failed, shutdown\n");
- GNUNET_break (0);
- GNUNET_SCHEDULER_shutdown ();
- return;
- }
- op_done++;
- if (op_done == (top->num_masters + top->num_slaves))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Connected to all ATS services\n");
- top->state.connected_ATS_service = GNUNET_YES;
- GNUNET_SCHEDULER_add_now (&do_comm_connect,
- NULL);
- }
-}
-
-
-static void
-do_connect_ats (void *cls)
-{
- int c_m;
- int c_s;
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Connecting to all ATS services\n");
- for (c_m = 0; c_m < top->num_masters; c_m++)
- {
- top->mps[c_m].ats_perf_op
- = GNUNET_TESTBED_service_connect (NULL,
- top->mps[c_m].peer,
- "ats",
- &ats_connect_completion_cb,
- NULL,
- &ats_perf_connect_adapter,
- &ats_perf_disconnect_adapter,
- &top->mps[c_m]);
- }
-
- for (c_s = 0; c_s < top->num_slaves; c_s++)
- {
- top->sps[c_s].ats_perf_op
- = GNUNET_TESTBED_service_connect (NULL,
- top->sps[c_s].peer,
- "ats",
- &ats_connect_completion_cb,
- NULL,
- &ats_perf_connect_adapter,
- &ats_perf_disconnect_adapter,
- &top->sps[c_s]);
- }
-}
-
-
-static void
-peerinformation_cb (void *cb_cls,
- struct GNUNET_TESTBED_Operation *op,
- const struct GNUNET_TESTBED_PeerInformation *pinfo,
- const char *emsg)
-{
- struct BenchmarkPeer *p = cb_cls;
- static int done = 0;
-
- GNUNET_assert (pinfo->pit == GNUNET_TESTBED_PIT_IDENTITY);
-
- p->id = *pinfo->result.id;
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "%s [%u] has peer id `%s'\n",
- (p->master == GNUNET_YES) ? "Master" : "Slave",
- p->no,
- GNUNET_i2s (&p->id));
-
- GNUNET_TESTBED_operation_done (op);
- p->peer_id_op = NULL;
- done++;
-
- if (done == top->num_slaves + top->num_masters)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Retrieved all peer ID, connect to ATS\n");
- GNUNET_SCHEDULER_add_now (&do_connect_ats,
- NULL);
- }
-}
-
-
-/**
- * Signature of a main function for a testcase.
- *
- * @param cls closure
- * @param h testbed handle
- * @param num_peers number of peers in 'peers'
- * @param peers_ handle to peers run in the testbed
- * @param links_succeeded the number of overlay link connection attempts that
- * succeeded
- * @param links_failed the number of overlay link connection attempts that
- * failed
- */
-static void
-main_run (void *cls,
- struct GNUNET_TESTBED_RunHandle *h,
- unsigned int num_peers,
- struct GNUNET_TESTBED_Peer **peers_,
- unsigned int links_succeeded,
- unsigned int links_failed)
-{
- int c_m;
- int c_s;
-
- GNUNET_assert (NULL == cls);
- GNUNET_assert (top->num_masters + top->num_slaves == num_peers);
- GNUNET_assert (NULL != peers_);
-
- GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
- top);
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Setting up %u masters and %u slaves\n",
- top->num_masters,
- top->num_slaves);
-
- /* Setup master peers */
- for (c_m = 0; c_m < top->num_masters; c_m++)
- {
- GNUNET_assert (NULL != peers_[c_m]);
- top->mps[c_m].peer = peers_[c_m];
- top->mps[c_m].no = c_m;
- top->mps[c_m].master = GNUNET_YES;
- top->mps[c_m].pref_partner = &top->sps[c_m];
- top->mps[c_m].pref_value = TEST_ATS_PREFERENCE_DEFAULT;
- top->mps[c_m].partners =
- GNUNET_malloc (top->num_slaves * sizeof(struct BenchmarkPartner));
- top->mps[c_m].num_partners = top->num_slaves;
- /* Initialize partners */
- for (c_s = 0; c_s < top->num_slaves; c_s++)
- {
- top->mps[c_m].partners[c_s].me = &top->mps[c_m];
- top->mps[c_m].partners[c_s].dest = &top->sps[c_s];
- }
- /* Get configuration */
- top->mps[c_m].peer_id_op
- = GNUNET_TESTBED_peer_get_information (top->mps[c_m].peer,
- GNUNET_TESTBED_PIT_IDENTITY,
- &peerinformation_cb,
- &top->mps[c_m]);
- }
-
- /* Setup slave peers */
- for (c_s = 0; c_s < top->num_slaves; c_s++)
- {
- GNUNET_assert (NULL != peers_[c_s + top->num_masters]);
- top->sps[c_s].peer = peers_[c_s + top->num_masters];
- top->sps[c_s].no = c_s + top->num_masters;
- top->sps[c_s].master = GNUNET_NO;
- top->sps[c_s].partners =
- GNUNET_new_array (top->num_masters,
- struct BenchmarkPartner);
- top->sps[c_s].num_partners = top->num_masters;
- /* Initialize partners */
- for (c_m = 0; c_m < top->num_masters; c_m++)
- {
- top->sps[c_s].partners[c_m].me = &top->sps[c_s];
- top->sps[c_s].partners[c_m].dest = &top->mps[c_m];
-
- /* Initialize properties */
- top->sps[c_s].partners[c_m].props.delay = GNUNET_TIME_UNIT_ZERO;
- top->sps[c_s].partners[c_m].props.distance = 0;
- top->sps[c_s].partners[c_m].props.scope = GNUNET_NT_UNSPECIFIED;
- top->sps[c_s].partners[c_m].props.utilization_in = 0;
- top->sps[c_s].partners[c_m].props.utilization_out = 0;
- }
- /* Get configuration */
- top->sps[c_s].peer_id_op
- = GNUNET_TESTBED_peer_get_information (top->sps[c_s].peer,
- GNUNET_TESTBED_PIT_IDENTITY,
- &peerinformation_cb,
- &top->sps[c_s]);
- }
-}
-
-
-/**
- * Controller event callback
- *
- * @param cls NULL
- * @param event the controller event
- */
-static void
-controller_event_cb (void *cls,
- const struct GNUNET_TESTBED_EventInformation *event)
-{
- switch (event->type)
- {
- case GNUNET_TESTBED_ET_CONNECT:
- break;
-
- case GNUNET_TESTBED_ET_OPERATION_FINISHED:
- break;
-
- default:
- GNUNET_break (0);
- GNUNET_SCHEDULER_shutdown ();
- }
-}
-
-
-struct BenchmarkPeer *
-GNUNET_ATS_TEST_get_peer (int src)
-{
- if (src > top->num_masters)
- return NULL;
- return &top->mps[src];
-}
-
-
-struct BenchmarkPartner *
-GNUNET_ATS_TEST_get_partner (int src,
- int dest)
-{
- if (src > top->num_masters)
- return NULL;
- if (dest > top->num_slaves)
- return NULL;
- return &top->mps[src].partners[dest];
-}
-
-
-/**
- * Create a topology for ats testing
- *
- * @param name test name
- * @param cfg_file configuration file to use for the peers
- * @param num_slaves number of slaves
- * @param num_masters number of masters
- * @param test_core connect to CORE service (GNUNET_YES) or transport (GNUNET_NO)
- * @param done_cb function to call when topology is setup
- * @param done_cb_cls cls for callback
- * @param log_request_cb callback to call when logging is required
- */
-void
-GNUNET_ATS_TEST_create_topology (char *name, char *cfg_file,
- unsigned int num_slaves,
- unsigned int num_masters,
- int test_core,
- GNUNET_ATS_TEST_TopologySetupDoneCallback
- done_cb,
- void *done_cb_cls,
- GNUNET_ATS_AddressInformationCallback
- log_request_cb)
-{
- top = GNUNET_new (struct GNUNET_ATS_TEST_Topology);
- top->num_masters = num_masters;
- top->num_slaves = num_slaves;
- top->done_cb = done_cb;
- top->done_cb_cls = done_cb_cls;
- top->test_core = test_core;
- top->ats_perf_cb = log_request_cb;
- top->mps = GNUNET_new_array (num_masters,
- struct BenchmarkPeer);
- top->sps = GNUNET_new_array (num_slaves,
- struct BenchmarkPeer);
-
- /* Start topology */
- uint64_t event_mask;
- event_mask = 0;
- event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT);
- event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED);
- (void) GNUNET_TESTBED_test_run (name,
- cfg_file,
- num_slaves + num_masters,
- event_mask,
- &controller_event_cb, NULL,
- &main_run, NULL);
-}
-
-
-/**
- * Shutdown topology
- */
-void
-GNUNET_ATS_TEST_shutdown_topology (void)
-{
- if (NULL == top)
- return;
- GNUNET_SCHEDULER_shutdown ();
-}
-
-
-/* end of file ats-testing.c */
diff --git a/src/ats-tests/ats-testing.h b/src/ats-tests/ats-testing.h
deleted file mode 100644
index 017ffef4f..000000000
--- a/src/ats-tests/ats-testing.h
+++ /dev/null
@@ -1,757 +0,0 @@
-/*
- This file is part of GNUnet.
- Copyright (C) 2010-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 ats-tests/ats-testing.h
- * @brief ats testing library: setup topology and provide logging to test ats
- * @author Christian Grothoff
- * @author Matthias Wachs
- */
-#include "platform.h"
-#include "gnunet_util_lib.h"
-#include "gnunet_testbed_service.h"
-#include "gnunet_ats_service.h"
-#include "gnunet_core_service.h"
-#include "gnunet_transport_service.h"
-
-#define TEST_ATS_PREFERENCE_DEFAULT 1.0
-
-/**
- * Message type sent for traffic generation
- */
-#define TEST_MESSAGE_TYPE_PING 12345
-
-/**
- * Message type sent as response during traffic generation
- */
-#define TEST_MESSAGE_TYPE_PONG 12346
-
-/**
- * Size of test messages
- */
-#define TEST_MESSAGE_SIZE 100
-
-
-struct TestMessage
-{
- struct GNUNET_MessageHeader header;
-
- uint8_t padding[TEST_MESSAGE_SIZE - sizeof(struct GNUNET_MessageHeader)];
-};
-
-
-struct BenchmarkPartner;
-
-struct BenchmarkPeer;
-
-struct GNUNET_ATS_TEST_Topology;
-
-struct TrafficGenerator;
-
-struct LoggingHandle;
-
-enum GeneratorType
-{
- GNUNET_ATS_TEST_TG_LINEAR,
- GNUNET_ATS_TEST_TG_CONSTANT,
- GNUNET_ATS_TEST_TG_RANDOM,
- GNUNET_ATS_TEST_TG_SINUS
-};
-
-
-/**
- * Callback to call when topology setup is completed
- *
- * @param cls the closure
- * @param masters array of master peers
- * @param slaves array of master peers
- */
-typedef void (*GNUNET_ATS_TEST_TopologySetupDoneCallback) (
- void *cls,
- struct BenchmarkPeer *masters,
- struct BenchmarkPeer *slaves);
-
-/**
- * Callback called when logging is required for the data contained
- *
- * @param cls the closure
- * @param address an address
- * @param address_active is address active
- * @param bandwidth_out bandwidth outbound
- * @param bandwidth_in bandwidth inbound
- * @param prop performance information
- */
-typedef void (*GNUNET_ATS_TEST_LogRequest) (
- void *cls,
- const struct GNUNET_HELLO_Address *address,
- int address_active,
- struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
- struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
- const struct GNUNET_ATS_Properties *prop);
-
-/**
- * Information we track for a peer in the testbed.
- */
-struct BenchmarkPeer
-{
- /**
- * Handle with testbed.
- */
- struct GNUNET_TESTBED_Peer *peer;
-
- /**
- * Unique identifier
- */
- int no;
-
- /**
- * Is this peer a measter: GNUNET_YES/GNUNET_NO
- */
- int master;
-
- /**
- * Peer ID
- */
- struct GNUNET_PeerIdentity id;
-
- /**
- * Testbed operation to get peer information
- */
- struct GNUNET_TESTBED_Operation *peer_id_op;
-
- /**
- * Testbed operation to connect to ATS performance service
- */
- struct GNUNET_TESTBED_Operation *ats_perf_op;
-
- /**
- * Testbed operation to connect to core
- */
- struct GNUNET_TESTBED_Operation *comm_op;
-
- /**
- * ATS performance handle
- */
- struct GNUNET_ATS_PerformanceHandle *ats_perf_handle;
-
- /**
- * Masters only:
- * Testbed connect operations to connect masters to slaves
- */
- struct TestbedConnectOperation *core_connect_ops;
-
- /**
- * Core handle
- */
- struct GNUNET_CORE_Handle *ch;
-
- /**
- * Transport handle
- */
- struct GNUNET_TRANSPORT_CoreHandle *th;
-
- /**
- * Masters only:
- * Peer to set ATS preferences for
- */
- struct BenchmarkPeer *pref_partner;
-
- /**
- * Masters only
- * Progress task
- */
- struct GNUNET_SCHEDULER_Task *ats_task;
-
- /**
- * Masters only
- * Progress task
- */
- double pref_value;
-
- /**
- * Array of partners with num_slaves entries (if master) or
- * num_master entries (if slave)
- */
- struct BenchmarkPartner *partners;
-
- /**
- * Number of partners
- */
- int num_partners;
-
- /**
- * Number of core connections
- */
- int core_connections;
-
- /**
- * Masters only:
- * Number of connections to slave peers
- */
- int core_slave_connections;
-
- /**
- * Total number of messages this peer has sent
- */
- unsigned int total_messages_sent;
-
- /**
- * Total number of bytes this peer has sent
- */
- unsigned int total_bytes_sent;
-
- /**
- * Total number of messages this peer has received
- */
- unsigned int total_messages_received;
-
- /**
- * Total number of bytes this peer has received
- */
- unsigned int total_bytes_received;
-};
-
-struct TrafficGenerator
-{
- struct TrafficGenerator *prev;
- struct TrafficGenerator *next;
-
- enum GeneratorType type;
-
- struct BenchmarkPeer *src;
- struct BenchmarkPartner *dest;
-
- long int base_rate;
- long int max_rate;
- struct GNUNET_TIME_Relative duration_period;
-
- struct GNUNET_SCHEDULER_Task *send_task;
- struct GNUNET_TIME_Absolute next_ping_transmission;
- struct GNUNET_TIME_Absolute time_start;
-};
-
-
-struct PreferenceGenerator
-{
- struct PreferenceGenerator *prev;
- struct PreferenceGenerator *next;
-
- enum GeneratorType type;
-
- struct BenchmarkPeer *src;
- struct BenchmarkPartner *dest;
-
- enum GNUNET_ATS_PreferenceKind kind;
-
- long int base_value;
- long int max_value;
- struct GNUNET_TIME_Relative duration_period;
- struct GNUNET_TIME_Relative frequency;
-
- struct GNUNET_SCHEDULER_Task *set_task;
- struct GNUNET_TIME_Absolute next_ping_transmission;
- struct GNUNET_TIME_Absolute time_start;
-};
-
-/**
- * Information about a benchmarking partner
- */
-struct BenchmarkPartner
-{
- /**
- * The peer itself this partner belongs to
- */
- struct BenchmarkPeer *me;
-
- /**
- * The partner peer
- */
- struct BenchmarkPeer *dest;
-
- /**
- * Message queue handle.
- */
- struct GNUNET_MQ_Handle *mq;
-
- /**
- * Handle for traffic generator
- */
- struct TrafficGenerator *tg;
-
- /**
- * Handle for preference generator
- */
- struct PreferenceGenerator *pg;
-
- /**
- * Timestamp to calculate communication layer delay
- */
- struct GNUNET_TIME_Absolute last_message_sent;
-
- /**
- * Accumulated RTT for all messages
- */
- unsigned int total_app_rtt;
-
- /**
- * Number of messages sent to this partner
- */
- unsigned int messages_sent;
-
- /**
- * Number of bytes sent to this partner
- */
- unsigned int bytes_sent;
-
- /**
- * Number of messages received from this partner
- */
- unsigned int messages_received;
-
- /**
- * Number of bytes received from this partner
- */
- unsigned int bytes_received;
-
- /**
- * Current ATS properties
- */
- struct GNUNET_ATS_Properties props;
-
- /**
- * Bandwidth assigned inbound
- */
- uint32_t bandwidth_in;
-
- /**
- * Bandwidth assigned outbound
- */
- uint32_t bandwidth_out;
-
- /**
- * Current preference values for bandwidth
- */
- double pref_bandwidth;
-
- /**
- * Current preference values for delay
- */
- double pref_delay;
-};
-
-
-/**
- * Overall state of the performance benchmark
- */
-struct BenchmarkState
-{
- /**
- * Are we connected to ATS service of all peers: GNUNET_YES/NO
- */
- int connected_ATS_service;
-
- /**
- * Are we connected to CORE service of all peers: GNUNET_YES/NO
- */
- int connected_COMM_service;
-
- /**
- * Are we connected to all peers: GNUNET_YES/NO
- */
- int connected_PEERS;
-
- /**
- * Are we connected to all slave peers on CORE level: GNUNET_YES/NO
- */
- int connected_CORE;
-
- /**
- * Are we connected to CORE service of all peers: GNUNET_YES/NO
- */
- int benchmarking;
-};
-
-
-struct GNUNET_ATS_TEST_Topology
-{
- /**
- * Progress task
- */
- struct GNUNET_SCHEDULER_Task *progress_task;
-
- /**
- * Test result
- */
- int result;
-
- /**
- * Test core (#GNUNET_YES) or transport (#GNUNET_NO)
- */
- int test_core;
-
- /**
- * Solver string
- */
- char *solver;
-
- /**
- * Preference string
- */
- char *testname;
-
- /**
- * Preference string
- */
- char *pref_str;
-
- /**
- * ATS preference value
- */
- int pref_val;
-
- /**
- * Number master peers
- */
- unsigned int num_masters;
-
- /**
- * Array of master peers
- */
- struct BenchmarkPeer *mps;
-
- /**
- * Number slave peers
- */
- unsigned int num_slaves;
-
- /**
- * Array of slave peers
- */
- struct BenchmarkPeer *sps;
-
- /**
- * Benchmark duration
- */
- struct GNUNET_TIME_Relative perf_duration;
-
- /**
- * Logging frequency
- */
- struct GNUNET_TIME_Relative log_frequency;
-
- /**
- * Benchmark state
- */
- struct BenchmarkState state;
-
- GNUNET_ATS_TEST_TopologySetupDoneCallback done_cb;
-
- GNUNET_ATS_AddressInformationCallback ats_perf_cb;
-
- void *done_cb_cls;
-};
-
-enum OperationType
-{
- START_SEND,
- STOP_SEND,
- START_PREFERENCE,
- STOP_PREFERENCE
-};
-
-struct Episode;
-
-struct Experiment;
-
-typedef void (*GNUNET_ATS_TESTING_EpisodeDoneCallback) (struct Episode *e);
-
-typedef void (*GNUNET_ATS_TESTING_ExperimentDoneCallback) (
- struct Experiment *e,
- struct GNUNET_TIME_Relative duration,
- int success);
-
-/**
- * An operation in an experiment
- */
-struct GNUNET_ATS_TEST_Operation
-{
- struct GNUNET_ATS_TEST_Operation *next;
- struct GNUNET_ATS_TEST_Operation *prev;
-
- long long unsigned int src_id;
- long long unsigned int dest_id;
-
- long long unsigned int base_rate;
- long long unsigned int max_rate;
- struct GNUNET_TIME_Relative period;
- struct GNUNET_TIME_Relative frequency;
-
- enum OperationType type;
- enum GeneratorType gen_type;
- enum GNUNET_ATS_PreferenceKind pref_type;
-};
-
-struct Episode
-{
- int id;
- struct Episode *next;
- struct GNUNET_TIME_Relative duration;
-
- struct GNUNET_ATS_TEST_Operation *head;
- struct GNUNET_ATS_TEST_Operation *tail;
-};
-
-
-struct Experiment
-{
- char *name;
- char *cfg_file;
- unsigned long long int num_masters;
- unsigned long long int num_slaves;
- struct GNUNET_TIME_Relative log_freq;
- struct GNUNET_TIME_Relative max_duration;
- struct GNUNET_TIME_Relative total_duration;
- struct GNUNET_TIME_Absolute start_time;
- unsigned int num_episodes;
- struct Episode *start;
-
- struct GNUNET_SCHEDULER_Task *experiment_timeout_task;
- struct GNUNET_SCHEDULER_Task *episode_timeout_task;
- struct Episode *cur;
-
- GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb;
- GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb;
-};
-
-
-extern struct GNUNET_CONFIGURATION_Handle *cfg;
-
-/**
- * Execute the specified experiment
- *
- * @param e the Experiment
- * @param ep_done_cb a episode is completed
- * @param e_done_cb the experiment is completed
- */
-void
-GNUNET_ATS_TEST_experimentation_run (
- struct Experiment *e,
- GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb,
- GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb);
-
-
-/**
- * Load an experiment from a file
- *
- * @param filename the file
- * @return the Experiment or NULL on failure
- */
-struct Experiment *
-GNUNET_ATS_TEST_experimentation_load (const char *filename);
-
-
-/**
- * Stop an experiment
- *
- * @param e the experiment
- */
-void
-GNUNET_ATS_TEST_experimentation_stop (struct Experiment *e);
-
-
-void
-GNUNET_ATS_TEST_traffic_handle_ping (struct BenchmarkPartner *p);
-
-
-void
-GNUNET_ATS_TEST_traffic_handle_pong (struct BenchmarkPartner *p);
-
-
-/**
- * Generate between the source master and the partner and send traffic with a
- * maximum rate.
- *
- * @param src traffic source
- * @param dest traffic partner
- * @param type type of traffic to generate
- * @param base_rate traffic base rate to send data with
- * @param max_rate traffic maximum rate to send data with
- * @param period duration of a period of traffic generation (~ 1/frequency)
- * @param duration how long to generate traffic
- * @return the traffic generator
- */
-struct TrafficGenerator *
-GNUNET_ATS_TEST_generate_traffic_start (struct BenchmarkPeer *src,
- struct BenchmarkPartner *dest,
- enum GeneratorType type,
- unsigned int base_rate,
- unsigned int max_rate,
- struct GNUNET_TIME_Relative period,
- struct GNUNET_TIME_Relative duration);
-
-
-void
-GNUNET_ATS_TEST_generate_traffic_stop (struct TrafficGenerator *tg);
-
-
-/**
- * Stop all traffic generators
- */
-void
-GNUNET_ATS_TEST_generate_traffic_stop_all (void);
-
-
-/**
- * Generate between the source master and the partner and set preferences with a
- * value depending on the generator.
- *
- * @param src source
- * @param dest partner
- * @param type type of preferences to generate
- * @param base_value traffic base rate to send data with
- * @param value_rate traffic maximum rate to send data with
- * @param period duration of a period of preferences generation (~ 1/frequency)
- * @param frequency how long to generate preferences
- * @param kind ATS preference to generate
- * @return the traffic generator
- */
-struct PreferenceGenerator *
-GNUNET_ATS_TEST_generate_preferences_start (
- struct BenchmarkPeer *src,
- struct BenchmarkPartner *dest,
- enum GeneratorType type,
- unsigned int base_value,
- unsigned int value_rate,
- struct GNUNET_TIME_Relative period,
- struct GNUNET_TIME_Relative frequency,
- enum GNUNET_ATS_PreferenceKind kind);
-
-
-void
-GNUNET_ATS_TEST_generate_preferences_stop (struct PreferenceGenerator *pg);
-
-
-void
-GNUNET_ATS_TEST_generate_preferences_stop_all (void);
-
-
-/**
- * Start logging
- *
- * @param log_frequency the logging frequency
- * @param testname the testname
- * @param masters the master peers used for benchmarking
- * @param num_masters the number of master peers
- * @param num_slaves the number of slave peers
- * @param verbose verbose logging
- * @return the logging handle or NULL on error
- */
-struct LoggingHandle *
-GNUNET_ATS_TEST_logging_start (struct GNUNET_TIME_Relative log_frequency,
- const char *testname,
- struct BenchmarkPeer *masters,
- int num_masters,
- int num_slaves,
- int verbose);
-
-
-/**
- * Stop logging
- *
- * @param l the logging handle
- */
-void
-GNUNET_ATS_TEST_logging_clean_up (struct LoggingHandle *l);
-
-
-/**
- * Stop logging
- *
- * @param l the logging handle
- */
-void
-GNUNET_ATS_TEST_logging_stop (struct LoggingHandle *l);
-
-
-/**
- * Log all data now
- *
- * @param l logging handle to use
- */
-void
-GNUNET_ATS_TEST_logging_now (struct LoggingHandle *l);
-
-
-/**
- * Write logging data to file
- *
- * @param l logging handle to use
- * @param test_name name of the current test
- * @param plots create gnuplots: #GNUNET_YES or #GNUNET_NO
- */
-void
-GNUNET_ATS_TEST_logging_write_to_file (struct LoggingHandle *l,
- const char *test_name,
- int plots);
-
-
-/**
- * Topology related functions
- */
-struct BenchmarkPeer *
-GNUNET_ATS_TEST_get_peer (int src);
-
-
-struct BenchmarkPartner *
-GNUNET_ATS_TEST_get_partner (int src, int dest);
-
-
-/**
- * Create a topology for ats testing
- *
- * @param name test name
- * @param cfg_file configuration file to use for the peers
- * @param num_slaves number of slaves
- * @param num_masters number of masters
- * @param test_core connect to CORE service (#GNUNET_YES) or transport
- * (#GNUNET_NO)
- * @param done_cb function to call when topology is setup
- * @param done_cb_cls cls for callback
- * @param log_request_cb callback to call when logging is required
- */
-void
-GNUNET_ATS_TEST_create_topology (
- char *name,
- char *cfg_file,
- unsigned int num_slaves,
- unsigned int num_masters,
- int test_core,
- GNUNET_ATS_TEST_TopologySetupDoneCallback done_cb,
- void *done_cb_cls,
- GNUNET_ATS_TEST_LogRequest ats_perf_cb);
-
-
-/**
- * Shutdown topology
- */
-void
-GNUNET_ATS_TEST_shutdown_topology (void);
-
-
-/* end of file ats-testing.h */
diff --git a/src/ats-tests/experiments/evaluation1_dru_3_peers_1addr_1scope_prop.conf b/src/ats-tests/experiments/evaluation1_dru_3_peers_1addr_1scope_prop.conf
deleted file mode 100644
index 4b66e5aea..000000000
--- a/src/ats-tests/experiments/evaluation1_dru_3_peers_1addr_1scope_prop.conf
+++ /dev/null
@@ -1,24 +0,0 @@
-@INLINE@ template_perf_ats.conf
-
-[transport]
-plugins = unix
-
-[ats]
-MODE = MLP
-UNSPECIFIED_QUOTA_IN = 128 KiB
-UNSPECIFIED_QUOTA_OUT = 128 KiB
-# LOOPBACK
-LOOPBACK_QUOTA_IN = 128 KiB
-LOOPBACK_QUOTA_OUT = 128 KiB
-# LAN
-LAN_QUOTA_IN = 128 KiB
-LAN_QUOTA_OUT = 128 KiB
-# WAN
-WAN_QUOTA_IN = 128 KiB
-WAN_QUOTA_OUT = 128 KiB
-# WLAN
-WLAN_QUOTA_IN = 128 KiB
-WLAN_QUOTA_OUT = 128 KiB
-# BLUETOOTH
-BLUETOOTH_QUOTA_IN = 128 KiB
-BLUETOOTH_QUOTA_OUT = 128 KiB \ No newline at end of file
diff --git a/src/ats-tests/experiments/evaluation1_dru_3_peers_1addr_1scope_prop.exp b/src/ats-tests/experiments/evaluation1_dru_3_peers_1addr_1scope_prop.exp
deleted file mode 100644
index 6a04e7491..000000000
--- a/src/ats-tests/experiments/evaluation1_dru_3_peers_1addr_1scope_prop.exp
+++ /dev/null
@@ -1,46 +0,0 @@
-[experiment]
-name = sc1_eval_dru_prop
-masters = 1
-slaves = 3
-max_duration = 20 s
-log_freq = 100 ms
-cfg_file = experiments/evaluation1_dru_3_peers_1addr_1scope_prop.conf
-
-[episode-0]
-# operations = start_send, stop_send, start_preference, stop_preference
-duration = 10 s
-op-0-operation = start_send
-op-0-src = 0
-op-0-dest = 0
-op-0-type = constant
-#op-0-period = 10 s
-op-0-base-rate= 10000
-#op-0-max-rate = 10000
-
-op-1-operation = start_send
-op-1-src = 0
-op-1-dest = 1
-op-1-type = constant
-#op-1-period = 10 s
-op-1-base-rate= 10000
-#op-1-max-rate = 10000
-
-op-2-operation = start_send
-op-2-src = 0
-op-2-dest = 2
-op-2-type = constant
-#op-1-period = 10 s
-op-2-base-rate= 10000
-#op-1-max-rate = 10000
-
-[episode-1]
-duration = 10 s
-op-0-operation = start_preference
-op-0-src = 0
-op-0-dest = 2
-op-0-type = constant
-#op-0-period = 10 s
-op-0-pref = bandwidth
-op-0-frequency = 1 s
-op-0-base-rate= 50
-#op-0-max-rate = 10000 \ No newline at end of file
diff --git a/src/ats-tests/experiments/send_linear_10_sec.exp b/src/ats-tests/experiments/send_linear_10_sec.exp
deleted file mode 100644
index efd2c7b08..000000000
--- a/src/ats-tests/experiments/send_linear_10_sec.exp
+++ /dev/null
@@ -1,30 +0,0 @@
-[experiment]
- name = test
- masters = 1
- slaves = 3
- max_duration = 2 s
- cfg_file = gnunet_ats_sim_default.conf
-
-[episode-0]
-# operations = set_rate, start_send, stop_send, set_preference
-duration = 2 s
-op-0-operation = set_rate
-op-0-src = 0
-op-0-dest = 0
-op-0-type = constant
-op-0-base-rate= 10000
-op-0-max-rate = 10000
-
-op-1-operation = set_rate
-op-1-src = 0
-op-1-dest = 1
-op-1-type = constant
-op-1-base-rate= 10000
-op-1-max-rate = 10000
-
-op-2-operation = set_rate
-op-2-src = 0
-op-2-dest = 2
-op-2-type = constant
-op-2-base-rate= 10000
-op-2-max-rate = 10000 \ No newline at end of file
diff --git a/src/ats-tests/experiments/test.exp b/src/ats-tests/experiments/test.exp
deleted file mode 100644
index 636139f89..000000000
--- a/src/ats-tests/experiments/test.exp
+++ /dev/null
@@ -1,55 +0,0 @@
-[experiment]
- name = test
- masters = 1
- slaves = 2
- max_duration = 15 s
- log_freq = 100 ms
- cfg_file = gnunet_ats_sim_default.conf
-
-[episode-0]
-# operations = start_send, stop_send, start_preference, stop_preference
-duration = 10 s
-op-0-operation = start_send
-op-0-src = 0
-op-0-dest = 0
-op-0-type = constant
-op-0-base-rate= 10000
-op-0-max-rate = 10000
-
-op-1-operation = start_send
-op-1-src = 0
-op-1-dest = 1
-op-1-type = sinus
-op-1-period = 5 s
-op-1-base-rate= 10000
-op-1-max-rate = 15000
-
-op-2-operation = start_preference
-op-2-src = 0
-op-2-dest = 0
-op-2-type = constant
-op-2-period = 5 s
-op-2-base-rate= 10
-op-2-max-rate = 5
-op-2-pref = latency
-op-2-frequency = 2 s
-
-op-3-operation = start_preference
-op-3-src = 0
-op-3-dest = 1
-op-3-type = linear
-op-3-period = 5 s
-op-3-base-rate= 40
-op-3-max-rate = 50
-op-3-pref = bandwidth
-op-3-frequency = 750 ms
-
-[episode-1]
-duration = 5 s
-op-0-operation = stop_preference
-op-0-src = 0
-op-0-dest = 0
-
-op-1-operation = stop_preference
-op-1-src = 0
-op-1-dest = 1
diff --git a/src/ats-tests/gnunet-ats-sim.c b/src/ats-tests/gnunet-ats-sim.c
deleted file mode 100644
index 15cd52e2f..000000000
--- a/src/ats-tests/gnunet-ats-sim.c
+++ /dev/null
@@ -1,399 +0,0 @@
-/*
- This file is part of GNUnet.
- Copyright (C) 2010-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 ats-tests/gnunet-ats-sim.c
- * @brief ats traffic simulator: this tool uses the ats-test library to setup a
- * topology and generate traffic between these peers. The traffic description
- * is loaded from a experiment description file
- * @author Christian Grothoff
- * @author Matthias Wachs
- */
-#include "platform.h"
-#include "gnunet_util_lib.h"
-#include "gnunet_testbed_service.h"
-#include "gnunet_ats_service.h"
-#include "gnunet_core_service.h"
-#include "ats-testing.h"
-
-#define TEST_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, \
- 10)
-
-static struct BenchmarkPeer *masters_p;
-static struct BenchmarkPeer *slaves_p;
-
-/**
- * cmd option -e: experiment file
- */
-static char *opt_exp_file;
-
-/**
- * cmd option -l: enable logging
- */
-static int opt_log;
-
-/**
- * cmd option -p: enable plots
- */
-static int opt_plot;
-
-/**
- * cmd option -v: verbose logs
- */
-static int opt_verbose;
-
-static struct GNUNET_SCHEDULER_Task *timeout_task;
-
-static struct Experiment *e;
-
-static struct LoggingHandle *l;
-
-
-static void
-evaluate (struct GNUNET_TIME_Relative duration_total)
-{
- int c_m;
- int c_s;
- unsigned int duration;
- struct BenchmarkPeer *mp;
- struct BenchmarkPartner *p;
-
- unsigned int b_sent_sec;
- double kb_sent_percent;
- unsigned int b_recv_sec;
- double kb_recv_percent;
- unsigned int rtt;
-
-
- duration = (duration_total.rel_value_us / (1000 * 1000));
- if (0 == duration)
- duration = 1;
- for (c_m = 0; c_m < e->num_masters; c_m++)
- {
- mp = &masters_p[c_m];
- fprintf (stderr,
- _ (
- "Master [%u]: sent: %u KiB in %u sec. = %u KiB/s, received: %u KiB in %u sec. = %u KiB/s\n"),
- mp->no, mp->total_bytes_sent / 1024,
- duration,
- (mp->total_bytes_sent / 1024) / duration,
- mp->total_bytes_received / 1024,
- duration,
- (mp->total_bytes_received / 1024) / duration);
-
- for (c_s = 0; c_s < e->num_slaves; c_s++)
- {
- p = &mp->partners[c_s];
-
- b_sent_sec = 0;
- b_recv_sec = 0;
- kb_sent_percent = 0.0;
- kb_recv_percent = 0.0;
- rtt = 0;
-
- if (duration > 0)
- {
- b_sent_sec = p->bytes_sent / duration;
- b_recv_sec = p->bytes_received / duration;
- }
-
- if (mp->total_bytes_sent > 0)
- kb_sent_percent = ((double) p->bytes_sent * 100) / mp->total_bytes_sent;
- if (mp->total_bytes_received > 0)
- kb_recv_percent = ((double) p->bytes_received * 100)
- / mp->total_bytes_received;
- if (1000 * p->messages_sent > 0)
- rtt = p->total_app_rtt / (1000 * p->messages_sent);
- fprintf (stderr,
- "%c Master [%u] -> Slave [%u]: sent %u Bips (%.2f %%), received %u Bips (%.2f %%)\n",
- (mp->pref_partner == p->dest) ? '*' : ' ',
- mp->no, p->dest->no,
- b_sent_sec, kb_sent_percent,
- b_recv_sec, kb_recv_percent);
- fprintf (stderr,
- "%c Master [%u] -> Slave [%u]: Average application layer RTT: %u ms\n",
- (mp->pref_partner == p->dest) ? '*' : ' ',
- mp->no, p->dest->no, rtt);
- }
- }
-}
-
-
-static void
-do_shutdown (void *cls)
-{
- fprintf (stderr, "Shutdown\n");
- if (NULL != timeout_task)
- {
- GNUNET_SCHEDULER_cancel (timeout_task);
- timeout_task = NULL;
- }
- if (NULL != l)
- {
- GNUNET_ATS_TEST_logging_stop (l);
- GNUNET_ATS_TEST_logging_clean_up (l);
- l = NULL;
- }
-
- /* Stop traffic generation */
- GNUNET_ATS_TEST_generate_traffic_stop_all ();
-
- /* Stop all preference generations */
- GNUNET_ATS_TEST_generate_preferences_stop_all ();
-
- if (NULL != e)
- {
- GNUNET_ATS_TEST_experimentation_stop (e);
- e = NULL;
- }
- GNUNET_ATS_TEST_shutdown_topology ();
-}
-
-
-static void
-do_timeout (void *cls)
-{
- timeout_task = NULL;
- GNUNET_SCHEDULER_shutdown ();
-}
-
-
-static void
-log_request__cb (void *cls,
- const struct GNUNET_HELLO_Address *address,
- int address_active,
- struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
- struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
- const struct GNUNET_ATS_Properties *ats)
-{
- if (NULL != l)
- {
- // GNUNET_break (0);
- // GNUNET_ATS_TEST_logging_now (l);
- }
-}
-
-
-static void
-experiment_done_cb (struct Experiment *e,
- struct GNUNET_TIME_Relative duration,
- int success)
-{
- if (GNUNET_OK == success)
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Experiment done successful in %s\n",
- GNUNET_STRINGS_relative_time_to_string (duration,
- GNUNET_YES));
- else
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment failed \n");
-
- /* Stop logging */
- GNUNET_ATS_TEST_logging_stop (l);
-
- /* Stop traffic generation */
- GNUNET_ATS_TEST_generate_traffic_stop_all ();
-
- /* Stop all preference generations */
- GNUNET_ATS_TEST_generate_preferences_stop_all ();
-
- evaluate (duration);
- if (opt_log)
- GNUNET_ATS_TEST_logging_write_to_file (l, opt_exp_file, opt_plot);
- GNUNET_SCHEDULER_shutdown ();
-}
-
-
-static void
-episode_done_cb (struct Episode *ep)
-{
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Episode %u done\n",
- ep->id);
-}
-
-
-static void
-topology_setup_done (void *cls,
- struct BenchmarkPeer *masters,
- struct BenchmarkPeer *slaves)
-{
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Topology setup complete!\n");
-
- masters_p = masters;
- slaves_p = slaves;
-
- l = GNUNET_ATS_TEST_logging_start (e->log_freq,
- e->name,
- masters_p,
- e->num_masters, e->num_slaves,
- opt_verbose);
- GNUNET_ATS_TEST_experimentation_run (e,
- &episode_done_cb,
- &experiment_done_cb);
-/*
- GNUNET_ATS_TEST_generate_preferences_start(&masters[0],&masters[0].partners[0],
- GNUNET_ATS_TEST_TG_CONSTANT, 1, 1, GNUNET_TIME_UNIT_SECONDS,
- GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 250),
- GNUNET_ATS_PREFERENCE_BANDWIDTH);
- *//*
- GNUNET_ATS_TEST_generate_preferences_start(&masters[0],&masters[0].partners[0],
- GNUNET_ATS_TEST_TG_LINEAR, 1, 50,
- GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2),
- GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 250),
- GNUNET_ATS_PREFERENCE_BANDWIDTH);
- *//*
- GNUNET_ATS_TEST_generate_preferences_start(&masters[0],&masters[0].partners[0],
- GNUNET_ATS_TEST_TG_RANDOM, 1, 50,
- GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2),
- GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 250),
- GNUNET_ATS_PREFERENCE_BANDWIDTH);
- *//*
- GNUNET_ATS_TEST_generate_preferences_start(&masters[0],&masters[0].partners[0],
- GNUNET_ATS_TEST_TG_SINUS, 10, 5,
- GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5),
- GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 250),
- GNUNET_ATS_PREFERENCE_BANDWIDTH);
- */
-#if 0
- int c_m;
- int c_s;
- for (c_m = 0; c_m < e->num_masters; c_m++)
- {
- for (c_s = 0; c_s < e->num_slaves; c_s++)
- {
- /* Generate maximum traffic to all peers */
- /* Example: Generate traffic with constant 10,000 Bytes/s */
- GNUNET_ATS_TEST_generate_traffic_start (&masters[c_m],
- &masters[c_m].partners[c_s],
- GNUNET_ATS_TEST_TG_CONSTANT,
- 10000,
- GNUNET_TIME_UNIT_FOREVER_REL);
- /* Example: Generate traffic with an increasing rate from 1000 to 2000
- * Bytes/s with in a minute */
- GNUNET_ATS_TEST_generate_traffic_start (&masters[c_m],
- &masters[c_m].partners[c_s],
- GNUNET_ATS_TEST_TG_LINEAR,
- 1000,
- 2000,
- GNUNET_TIME_UNIT_MINUTES,
- GNUNET_TIME_UNIT_FOREVER_REL);
- /* Example: Generate traffic with a random rate between 1000 to 2000
- * Bytes/s */
- GNUNET_ATS_TEST_generate_traffic_start (&masters[c_m],
- &masters[c_m].partners[c_s],
- GNUNET_ATS_TEST_TG_RANDOM,
- 1000,
- 2000,
- GNUNET_TIME_UNIT_FOREVER_REL,
- GNUNET_TIME_UNIT_FOREVER_REL);
- /* Example: Generate traffic with a sinus form, a base rate of
- * 1000 Bytes/s, an amplitude of (max-base), and a period of 1 minute */
- GNUNET_ATS_TEST_generate_traffic_start (&masters[c_m],
- &masters[c_m].partners[c_s],
- GNUNET_ATS_TEST_TG_SINUS,
- 1000,
- 2000,
- GNUNET_TIME_UNIT_MINUTES,
- GNUNET_TIME_UNIT_FOREVER_REL);
- }
- }
-#endif
-
- timeout_task
- = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_add (
- GNUNET_TIME_UNIT_MINUTES,
- e->max_duration),
- &do_timeout,
- NULL);
- GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
-}
-
-
-static void
-parse_args (int argc, char *argv[])
-{
- int c;
-
- opt_exp_file = NULL;
- opt_log = GNUNET_NO;
- opt_plot = GNUNET_NO;
-
- for (c = 0; c < argc; c++)
- {
- if ((c < (argc - 1)) && (0 == strcmp (argv[c], "-e")))
- {
- GNUNET_free (opt_exp_file);
- opt_exp_file = GNUNET_strdup (argv[c + 1]);
- }
- if (0 == strcmp (argv[c], "-l"))
- {
- opt_log = GNUNET_YES;
- }
- if (0 == strcmp (argv[c], "-p"))
- {
- opt_plot = GNUNET_YES;
- }
- if (0 == strcmp (argv[c], "-v"))
- {
- opt_verbose = GNUNET_YES;
- }
- }
-}
-
-
-int
-main (int argc, char *argv[])
-{
- GNUNET_log_setup ("gnunet-ats-sim", "INFO", NULL);
-
- parse_args (argc, argv);
- if (NULL == opt_exp_file)
- {
- fprintf (stderr, "No experiment given...\n");
- return 1;
- }
-
- fprintf (stderr, "Loading experiment `%s' \n", opt_exp_file);
- e = GNUNET_ATS_TEST_experimentation_load (opt_exp_file);
- if (NULL == e)
- {
- fprintf (stderr, "Invalid experiment\n");
- return 1;
- }
- if (0 == e->num_episodes)
- {
- fprintf (stderr, "No episodes included\n");
- return 1;
- }
-
- /* Setup a topology with */
- GNUNET_ATS_TEST_create_topology ("gnunet-ats-sim", e->cfg_file,
- e->num_slaves,
- e->num_masters,
- GNUNET_NO,
- &topology_setup_done,
- NULL,
- &log_request__cb);
- GNUNET_free (opt_exp_file);
- return 0;
-}
-
-
-/* end of file gnunet-ats-sim.c */
diff --git a/src/ats-tests/gnunet-solver-eval.c b/src/ats-tests/gnunet-solver-eval.c
deleted file mode 100644
index 7a3461bf7..000000000
--- a/src/ats-tests/gnunet-solver-eval.c
+++ /dev/null
@@ -1,1025 +0,0 @@
-/*
- This file is part of GNUnet.
- Copyright (C) 2010-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 ats-tests/ats-testing-experiment.c
- * @brief ats benchmark: controlled experiment execution
- * @author Christian Grothoff
- * @author Matthias Wachs
- */
-#include "platform.h"
-#include "gnunet_util_lib.h"
-#include "gnunet_ats_plugin.h"
-#include "gnunet_ats_service.h"
-#include "ats-testing.h"
-
-
-/**
- * Experiments
- */
-const char *
-print_op (enum OperationType op)
-{
- switch (op)
- {
- case START_SEND:
- return "START_SEND";
-
- case STOP_SEND:
- return "STOP_SEND";
-
- case START_PREFERENCE:
- return "START_PREFERENCE";
-
- case STOP_PREFERENCE:
- return "STOP_PREFERENCE";
-
- default:
- break;
- }
- return "";
-}
-
-
-static struct Experiment *
-create_experiment ()
-{
- struct Experiment *e;
-
- e = GNUNET_new (struct Experiment);
- e->name = NULL;
- e->num_masters = 0;
- e->num_slaves = 0;
- e->start = NULL;
- e->total_duration = GNUNET_TIME_UNIT_ZERO;
- return e;
-}
-
-
-static void
-free_experiment (struct Experiment *e)
-{
- struct Episode *cur;
- struct Episode *next;
- struct GNUNET_ATS_TEST_Operation *cur_o;
- struct GNUNET_ATS_TEST_Operation *next_o;
-
- next = e->start;
- for (cur = next; NULL != cur; cur = next)
- {
- next = cur->next;
-
- next_o = cur->head;
- for (cur_o = next_o; NULL != cur_o; cur_o = next_o)
- {
- next_o = cur_o->next;
- GNUNET_free (cur_o);
- }
- GNUNET_free (cur);
- }
-
- GNUNET_free (e->name);
- GNUNET_free (e->cfg_file);
- GNUNET_free (e);
-}
-
-
-static int
-load_episode (struct Experiment *e,
- struct Episode *cur,
- struct GNUNET_CONFIGURATION_Handle *cfg)
-{
- struct GNUNET_ATS_TEST_Operation *o;
- char *sec_name;
- char *op_name;
- char *op;
- char *type;
- char *pref;
- int op_counter = 0;
-
- fprintf (stderr, "Parsing episode %u\n", cur->id);
- GNUNET_asprintf (&sec_name, "episode-%u", cur->id);
-
- while (1)
- {
- /* Load operation */
- GNUNET_asprintf (&op_name, "op-%u-operation", op_counter);
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
- sec_name,
- op_name, &op))
- {
- GNUNET_free (op_name);
- break;
- }
- o = GNUNET_new (struct GNUNET_ATS_TEST_Operation);
- /* operations = set_rate, start_send, stop_send, set_preference */
- if (0 == strcmp (op, "start_send"))
- {
- o->type = START_SEND;
- }
- else if (0 == strcmp (op, "stop_send"))
- {
- o->type = STOP_SEND;
- }
- else if (0 == strcmp (op, "start_preference"))
- {
- o->type = START_PREFERENCE;
- }
- else if (0 == strcmp (op, "stop_preference"))
- {
- o->type = STOP_PREFERENCE;
- }
- else
- {
- fprintf (stderr, "Invalid operation %u `%s' in episode %u\n",
- op_counter, op, cur->id);
- GNUNET_free (op);
- GNUNET_free (op_name);
- GNUNET_free (sec_name);
- GNUNET_free (o);
- return GNUNET_SYSERR;
- }
- GNUNET_free (op_name);
-
- /* Get source */
- GNUNET_asprintf (&op_name, "op-%u-src", op_counter);
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
- sec_name,
- op_name,
- &o->src_id))
- {
- fprintf (stderr, "Missing src in operation %u `%s' in episode %u\n",
- op_counter, op, cur->id);
- GNUNET_free (op);
- GNUNET_free (op_name);
- GNUNET_free (sec_name);
- GNUNET_free (o);
- return GNUNET_SYSERR;
- }
- if (o->src_id > (e->num_masters - 1))
- {
- fprintf (stderr, "Invalid src %llu in operation %u `%s' in episode %u\n",
- o->src_id, op_counter, op, cur->id);
- GNUNET_free (op);
- GNUNET_free (op_name);
- GNUNET_free (sec_name);
- GNUNET_free (o);
- return GNUNET_SYSERR;
- }
- GNUNET_free (op_name);
-
- /* Get destination */
- GNUNET_asprintf (&op_name, "op-%u-dest", op_counter);
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
- sec_name,
- op_name,
- &o->dest_id))
- {
- fprintf (stderr, "Missing src in operation %u `%s' in episode %u\n",
- op_counter, op, cur->id);
- GNUNET_free (op);
- GNUNET_free (op_name);
- GNUNET_free (sec_name);
- GNUNET_free (o);
- return GNUNET_SYSERR;
- }
- if (o->dest_id > (e->num_slaves - 1))
- {
- fprintf (stderr,
- "Invalid destination %llu in operation %u `%s' in episode %u\n",
- o->dest_id,
- op_counter,
- op,
- cur->id);
- GNUNET_free (op);
- GNUNET_free (op_name);
- GNUNET_free (sec_name);
- GNUNET_free (o);
- return GNUNET_SYSERR;
- }
- GNUNET_free (op_name);
-
- GNUNET_asprintf (&op_name, "op-%u-type", op_counter);
- if ((GNUNET_SYSERR !=
- GNUNET_CONFIGURATION_get_value_string (cfg,
- sec_name,
- op_name,
- &type)) &&
- (STOP_SEND != o->type) &&
- (STOP_PREFERENCE != o->type))
- {
- /* Load arguments for set_rate, start_send, set_preference */
- if (0 == strcmp (type, "constant"))
- {
- o->gen_type = GNUNET_ATS_TEST_TG_CONSTANT;
- }
- else if (0 == strcmp (type, "linear"))
- {
- o->gen_type = GNUNET_ATS_TEST_TG_LINEAR;
- }
- else if (0 == strcmp (type, "sinus"))
- {
- o->gen_type = GNUNET_ATS_TEST_TG_SINUS;
- }
- else if (0 == strcmp (type, "random"))
- {
- o->gen_type = GNUNET_ATS_TEST_TG_RANDOM;
- }
- else
- {
- fprintf (stderr, "Invalid type %u `%s' in episode %u\n",
- op_counter, op, cur->id);
- GNUNET_free (type);
- GNUNET_free (op);
- GNUNET_free (op_name);
- GNUNET_free (sec_name);
- GNUNET_free (o);
- return GNUNET_SYSERR;
- }
- GNUNET_free (op_name);
-
- /* Get base rate */
- GNUNET_asprintf (&op_name, "op-%u-base-rate", op_counter);
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
- sec_name,
- op_name,
- &o->base_rate))
- {
- fprintf (stderr,
- "Missing base rate in operation %u `%s' in episode %u\n",
- op_counter, op, cur->id);
- GNUNET_free (type);
- GNUNET_free (op);
- GNUNET_free (op_name);
- GNUNET_free (sec_name);
- GNUNET_free (o);
- return GNUNET_SYSERR;
- }
- GNUNET_free (op_name);
-
- /* Get max rate */
- GNUNET_asprintf (&op_name, "op-%u-max-rate", op_counter);
- if (GNUNET_SYSERR ==
- GNUNET_CONFIGURATION_get_value_number (cfg,
- sec_name,
- op_name,
- &o->max_rate))
- {
- if ((GNUNET_ATS_TEST_TG_LINEAR == o->gen_type) ||
- (GNUNET_ATS_TEST_TG_RANDOM == o->gen_type) ||
- (GNUNET_ATS_TEST_TG_SINUS == o->gen_type))
- {
- fprintf (stderr,
- "Missing max rate in operation %u `%s' in episode %u\n",
- op_counter, op, cur->id);
- GNUNET_free (type);
- GNUNET_free (op_name);
- GNUNET_free (op);
- GNUNET_free (sec_name);
- GNUNET_free (o);
- return GNUNET_SYSERR;
- }
- }
- GNUNET_free (op_name);
-
- /* Get period */
- GNUNET_asprintf (&op_name, "op-%u-period", op_counter);
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
- sec_name,
- op_name,
- &o->period))
- {
- o->period = cur->duration;
- }
- GNUNET_free (op_name);
-
- if (START_PREFERENCE == o->type)
- {
- /* Get frequency */
- GNUNET_asprintf (&op_name, "op-%u-frequency", op_counter);
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
- sec_name,
- op_name,
- &o->frequency))
- {
- fprintf (stderr,
- "Missing frequency in operation %u `%s' in episode %u\n",
- op_counter, op, cur->id);
- GNUNET_free (type);
- GNUNET_free (op_name);
- GNUNET_free (op);
- GNUNET_free (sec_name);
- GNUNET_free (o);
- return GNUNET_SYSERR;
- }
- GNUNET_free (op_name);
-
- /* Get preference */
- GNUNET_asprintf (&op_name, "op-%u-pref", op_counter);
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
- sec_name,
- op_name,
- &pref))
- {
- fprintf (stderr,
- "Missing preference in operation %u `%s' in episode %u\n",
- op_counter, op, cur->id);
- GNUNET_free (type);
- GNUNET_free (op_name);
- GNUNET_free (op);
- GNUNET_free (sec_name);
- GNUNET_free (pref);
- GNUNET_free (o);
- return GNUNET_SYSERR;
- }
-
- if (0 == strcmp (pref, "bandwidth"))
- o->pref_type = GNUNET_ATS_PREFERENCE_BANDWIDTH;
- else if (0 == strcmp (pref, "latency"))
- o->pref_type = GNUNET_ATS_PREFERENCE_LATENCY;
- else
- {
- fprintf (stderr,
- "Invalid preference in operation %u `%s' in episode %u\n",
- op_counter,
- op,
- cur->id);
- GNUNET_free (type);
- GNUNET_free (op_name);
- GNUNET_free (op);
- GNUNET_free (sec_name);
- GNUNET_free (pref);
- GNUNET_free (o);
- return GNUNET_SYSERR;
- }
- GNUNET_free (pref);
- GNUNET_free (op_name);
- }
- }
-
- /* Safety checks */
- if ((GNUNET_ATS_TEST_TG_LINEAR == o->gen_type) ||
- (GNUNET_ATS_TEST_TG_SINUS == o->gen_type))
- {
- if ((o->max_rate - o->base_rate) > o->base_rate)
- {
- /* This will cause an underflow */
- GNUNET_break (0);
- }
- fprintf (stderr,
- "Selected max rate and base rate cannot be used for desired traffic form!\n");
- }
-
- if ((START_SEND == o->type) || (START_PREFERENCE == o->type))
- fprintf (stderr,
- "Found operation %u in episode %u: %s [%llu]->[%llu] == %s, %llu -> %llu in %s\n",
- op_counter, cur->id, print_op (o->type), o->src_id,
- o->dest_id, (NULL != type) ? type : "",
- o->base_rate, o->max_rate,
- GNUNET_STRINGS_relative_time_to_string (o->period, GNUNET_YES));
- else
- fprintf (stderr, "Found operation %u in episode %u: %s [%llu]->[%llu]\n",
- op_counter, cur->id, print_op (o->type), o->src_id, o->dest_id);
-
- GNUNET_free (type);
- GNUNET_free (op);
-
- GNUNET_CONTAINER_DLL_insert (cur->head, cur->tail, o);
- op_counter++;
- }
- GNUNET_free (sec_name);
-
- return GNUNET_OK;
-}
-
-
-static int
-load_episodes (struct Experiment *e, struct GNUNET_CONFIGURATION_Handle *cfg)
-{
- int e_counter = 0;
- char *sec_name;
- struct GNUNET_TIME_Relative e_duration;
- struct Episode *cur;
- struct Episode *last;
-
- e_counter = 0;
- last = NULL;
- while (1)
- {
- GNUNET_asprintf (&sec_name, "episode-%u", e_counter);
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
- sec_name,
- "duration",
- &e_duration))
- {
- GNUNET_free (sec_name);
- break;
- }
-
- cur = GNUNET_new (struct Episode);
- cur->duration = e_duration;
- cur->id = e_counter;
-
- if (GNUNET_OK != load_episode (e, cur, cfg))
- {
- GNUNET_free (sec_name);
- GNUNET_free (cur);
- return GNUNET_SYSERR;
- }
-
- fprintf (stderr, "Found episode %u with duration %s \n",
- e_counter,
- GNUNET_STRINGS_relative_time_to_string (cur->duration,
- GNUNET_YES));
-
- /* Update experiment */
- e->num_episodes++;
- e->total_duration = GNUNET_TIME_relative_add (e->total_duration,
- cur->duration);
- /* Put in linked list */
- if (NULL == last)
- e->start = cur;
- else
- last->next = cur;
-
- GNUNET_free (sec_name);
- e_counter++;
- last = cur;
- }
- return e_counter;
-}
-
-
-static void
-timeout_experiment (void *cls)
-{
- struct Experiment *e = cls;
-
- e->experiment_timeout_task = NULL;
- fprintf (stderr, "Experiment timeout!\n");
-
- if (NULL != e->episode_timeout_task)
- {
- GNUNET_SCHEDULER_cancel (e->episode_timeout_task);
- e->episode_timeout_task = NULL;
- }
-
- e->e_done_cb (e, GNUNET_TIME_absolute_get_duration (e->start_time),
- GNUNET_SYSERR);
-}
-
-
-static void
-enforce_start_send (struct GNUNET_ATS_TEST_Operation *op)
-{
- /*
- struct BenchmarkPeer *peer;
- struct BenchmarkPartner *partner;
-
- peer = GNUNET_ATS_TEST_get_peer (op->src_id);
- if (NULL == peer)
- {
- GNUNET_break (0);
- return;
- }
-
- partner = GNUNET_ATS_TEST_get_partner (op->src_id, op->dest_id);
- if (NULL == partner)
- {
- GNUNET_break (0);
- return;
- }
-
- fprintf (stderr, "Found master %llu slave %llu\n",op->src_id, op->dest_id);
-
- if (NULL != partner->tg)
- {
- fprintf (stderr, "Stopping traffic between master %llu slave %llu\n",op->src_id, op->dest_id);
- GNUNET_ATS_TEST_generate_traffic_stop(partner->tg);
- partner->tg = NULL;
- }
-
- partner->tg = GNUNET_ATS_TEST_generate_traffic_start(peer, partner,
- op->tg_type, op->base_rate, op->max_rate, op->period,
- GNUNET_TIME_UNIT_FOREVER_REL);
- */}
-
-
-static void
-enforce_stop_send (struct GNUNET_ATS_TEST_Operation *op)
-{
- /*
- struct BenchmarkPartner *p;
- p = GNUNET_ATS_TEST_get_partner (op->src_id, op->dest_id);
- if (NULL == p)
- {
- GNUNET_break (0);
- return;
- }
-
- fprintf (stderr, "Found master %llu slave %llu\n",op->src_id, op->dest_id);
-
- if (NULL != p->tg)
- {
- fprintf (stderr, "Stopping traffic between master %llu slave %llu\n",
- op->src_id, op->dest_id);
- GNUNET_ATS_TEST_generate_traffic_stop(p->tg);
- p->tg = NULL;
- }
- */}
-
-
-static void
-enforce_start_preference (struct GNUNET_ATS_TEST_Operation *op)
-{
- /*
- struct BenchmarkPeer *peer;
- struct BenchmarkPartner *partner;
-
- peer = GNUNET_ATS_TEST_get_peer (op->src_id);
- if (NULL == peer)
- {
- GNUNET_break (0);
- return;
- }
-
- partner = GNUNET_ATS_TEST_get_partner (op->src_id, op->dest_id);
- if (NULL == partner)
- {
- GNUNET_break (0);
- return;
- }
-
- fprintf (stderr, "Found master %llu slave %llu\n",op->src_id, op->dest_id);
-
- if (NULL != partner->pg)
- {
- fprintf (stderr, "Stopping traffic between master %llu slave %llu\n",
- op->src_id, op->dest_id);
- GNUNET_ATS_TEST_generate_preferences_stop(partner->pg);
- partner->pg = NULL;
- }
-
- partner->pg = GNUNET_ATS_TEST_generate_preferences_start(peer, partner,
- op->tg_type, op->base_rate, op->max_rate, op->period, op->frequency,
- op->pref_type);
- */}
-
-
-static void
-enforce_stop_preference (struct GNUNET_ATS_TEST_Operation *op)
-{
- /*
- struct BenchmarkPartner *p;
- p = GNUNET_ATS_TEST_get_partner (op->src_id, op->dest_id);
- if (NULL == p)
- {
- GNUNET_break (0);
- return;
- }
-
- fprintf (stderr, "Found master %llu slave %llu\n",op->src_id, op->dest_id);
-
- if (NULL != p->pg)
- {
- fprintf (stderr, "Stopping preference between master %llu slave %llu\n",
- op->src_id, op->dest_id);
- GNUNET_ATS_TEST_generate_preferences_stop (p->pg);
- p->pg = NULL;
- }
- */}
-
-
-static void
-enforce_episode (struct Episode *ep)
-{
- struct GNUNET_ATS_TEST_Operation *cur;
-
- for (cur = ep->head; NULL != cur; cur = cur->next)
- {
- fprintf (stderr, "Enforcing operation: %s [%llu]->[%llu] == %llu\n",
- print_op (cur->type), cur->src_id, cur->dest_id, cur->base_rate);
- switch (cur->type)
- {
- case START_SEND:
- enforce_start_send (cur);
- break;
-
- case STOP_SEND:
- enforce_stop_send (cur);
- break;
-
- case START_PREFERENCE:
- enforce_start_preference (cur);
- break;
-
- case STOP_PREFERENCE:
- enforce_stop_preference (cur);
- break;
-
- default:
- break;
- }
- }
-}
-
-
-static void
-timeout_episode (void *cls)
-{
- struct Experiment *e = cls;
-
- e->episode_timeout_task = NULL;
- if (NULL != e->ep_done_cb)
- e->ep_done_cb (e->cur);
-
- /* Scheduling next */
- e->cur = e->cur->next;
- if (NULL == e->cur)
- {
- /* done */
- fprintf (stderr, "Last episode done!\n");
- if (NULL != e->experiment_timeout_task)
- {
- GNUNET_SCHEDULER_cancel (e->experiment_timeout_task);
- e->experiment_timeout_task = NULL;
- }
- e->e_done_cb (e, GNUNET_TIME_absolute_get_duration (e->start_time),
- GNUNET_OK);
- return;
- }
-
- fprintf (stderr, "Running episode %u with timeout %s\n",
- e->cur->id,
- GNUNET_STRINGS_relative_time_to_string (e->cur->duration,
- GNUNET_YES));
- enforce_episode (e->cur);
-
- e->episode_timeout_task = GNUNET_SCHEDULER_add_delayed (e->cur->duration,
- &timeout_episode, e);
-}
-
-
-void
-GNUNET_ATS_solvers_experimentation_run (struct Experiment *e,
- GNUNET_ATS_TESTING_EpisodeDoneCallback
- ep_done_cb,
- GNUNET_ATS_TESTING_ExperimentDoneCallback
- e_done_cb)
-{
- fprintf (stderr, "Running experiment `%s' with timeout %s\n", e->name,
- GNUNET_STRINGS_relative_time_to_string (e->max_duration,
- GNUNET_YES));
- e->e_done_cb = e_done_cb;
- e->ep_done_cb = ep_done_cb;
- e->start_time = GNUNET_TIME_absolute_get ();
-
- /* Start total time out */
- e->experiment_timeout_task = GNUNET_SCHEDULER_add_delayed (e->max_duration,
- &timeout_experiment,
- e);
-
- /* Start */
- e->cur = e->start;
- fprintf (stderr, "Running episode %u with timeout %s\n",
- e->cur->id,
- GNUNET_STRINGS_relative_time_to_string (e->cur->duration,
- GNUNET_YES));
- enforce_episode (e->cur);
- e->episode_timeout_task = GNUNET_SCHEDULER_add_delayed (e->cur->duration,
- &timeout_episode, e);
-}
-
-
-struct Experiment *
-GNUNET_ATS_solvers_experimentation_load (char *filename)
-{
- struct Experiment *e;
- struct GNUNET_CONFIGURATION_Handle *cfg;
-
- e = NULL;
-
- cfg = GNUNET_CONFIGURATION_create ();
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, filename))
- {
- fprintf (stderr, "Failed to load `%s'\n", filename);
- GNUNET_CONFIGURATION_destroy (cfg);
- return NULL;
- }
-
- e = create_experiment ();
-
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg, "experiment",
- "name", &e->name))
- {
- fprintf (stderr, "Invalid %s", "name");
- free_experiment (e);
- return NULL;
- }
- else
- fprintf (stderr, "Experiment name: `%s'\n", e->name);
-
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_filename (cfg,
- "experiment",
- "cfg_file",
- &e->cfg_file))
- {
- fprintf (stderr, "Invalid %s", "cfg_file");
- free_experiment (e);
- return NULL;
- }
- else
- fprintf (stderr, "Experiment name: `%s'\n", e->cfg_file);
-
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg, "experiment",
- "masters",
- &e->num_masters))
- {
- fprintf (stderr, "Invalid %s", "masters");
- free_experiment (e);
- return NULL;
- }
- else
- fprintf (stderr, "Experiment masters: `%llu'\n",
- e->num_masters);
-
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg, "experiment",
- "slaves",
- &e->num_slaves))
- {
- fprintf (stderr, "Invalid %s", "slaves");
- free_experiment (e);
- return NULL;
- }
- else
- fprintf (stderr, "Experiment slaves: `%llu'\n",
- e->num_slaves);
-
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg, "experiment",
- "log_freq",
- &e->log_freq))
- {
- fprintf (stderr, "Invalid %s", "log_freq");
- free_experiment (e);
- return NULL;
- }
- else
- fprintf (stderr, "Experiment logging frequency: `%s'\n",
- GNUNET_STRINGS_relative_time_to_string (e->log_freq, GNUNET_YES));
-
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg, "experiment",
- "max_duration",
- &e->max_duration))
- {
- fprintf (stderr, "Invalid %s", "max_duration");
- free_experiment (e);
- return NULL;
- }
- else
- fprintf (stderr, "Experiment duration: `%s'\n",
- GNUNET_STRINGS_relative_time_to_string (e->max_duration,
- GNUNET_YES));
-
- load_episodes (e, cfg);
- fprintf (stderr, "Loaded %u episodes with total duration %s\n",
- e->num_episodes,
- GNUNET_STRINGS_relative_time_to_string (e->total_duration,
- GNUNET_YES));
-
- GNUNET_CONFIGURATION_destroy (cfg);
- return e;
-}
-
-
-void
-GNUNET_ATS_solvers_experimentation_stop (struct Experiment *e)
-{
- if (NULL != e->experiment_timeout_task)
- {
- GNUNET_SCHEDULER_cancel (e->experiment_timeout_task);
- e->experiment_timeout_task = NULL;
- }
- if (NULL != e->episode_timeout_task)
- {
- GNUNET_SCHEDULER_cancel (e->episode_timeout_task);
- e->episode_timeout_task = NULL;
- }
- free_experiment (e);
-}
-
-
-/**
- * Solver
- */
-
-struct GNUNET_ATS_TESTING_SolverHandle
-{
- char *plugin;
- struct GNUNET_ATS_PluginEnvironment env;
- void *solver;
-};
-
-enum GNUNET_ATS_Solvers
-{
- GNUNET_ATS_SOLVER_PROPORTIONAL,
- GNUNET_ATS_SOLVER_MLP,
- GNUNET_ATS_SOLVER_RIL,
-};
-
-void
-GNUNET_ATS_solvers_solver_stop (struct GNUNET_ATS_TESTING_SolverHandle *sh)
-{
- GNUNET_PLUGIN_unload (sh->plugin, sh->solver);
- GNUNET_free (sh->plugin);
- GNUNET_free (sh);
-}
-
-
-struct GNUNET_ATS_TESTING_SolverHandle *
-GNUNET_ATS_solvers_solver_start (enum GNUNET_ATS_Solvers type)
-{
- struct GNUNET_ATS_TESTING_SolverHandle *sh;
- char *solver_str;
-
- switch (type)
- {
- case GNUNET_ATS_SOLVER_PROPORTIONAL:
- solver_str = "proportional";
- break;
-
- case GNUNET_ATS_SOLVER_MLP:
- solver_str = "mlp";
- break;
-
- case GNUNET_ATS_SOLVER_RIL:
- solver_str = "ril";
- break;
-
- default:
- GNUNET_break (0);
- return NULL;
- break;
- }
-
- sh = GNUNET_new (struct GNUNET_ATS_TESTING_SolverHandle);
- GNUNET_asprintf (&sh->plugin, "libgnunet_plugin_ats_%s", solver_str);
- // sh->solver = GNUNET_PLUGIN_load (sh->plugin, &sh->env);
- if (NULL == sh->solver)
- {
- fprintf (stderr, "Failed to load solver `%s'\n", sh->plugin);
- exit (1);
- }
-
- return sh;
-}
-
-
-static struct Experiment *e;
-
-static struct GNUNET_ATS_TESTING_SolverHandle *sh;
-
-/**
- * cmd option -e: experiment file
- */
-static char *opt_exp_file;
-
-static char *opt_solver;
-
-/**
- * cmd option -l: enable logging
- */
-static int opt_log;
-
-/**
- * cmd option -p: enable plots
- */
-static int opt_plot;
-
-/**
- * cmd option -v: verbose logs
- */
-static int opt_verbose;
-
-static void
-run (void *cls, char *const *args, const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
-{
- enum GNUNET_ATS_Solvers solver;
-
- if (NULL == opt_exp_file)
- {
- fprintf (stderr, "No experiment given ...\n");
- exit (1);
- }
-
- if (NULL == opt_solver)
- {
- fprintf (stderr, "No solver given ...\n");
- exit (1);
- }
-
- if (0 == strcmp (opt_solver, "mlp"))
- {
- solver = GNUNET_ATS_SOLVER_MLP;
- }
- else if (0 == strcmp (opt_solver, "proportional"))
- {
- solver = GNUNET_ATS_SOLVER_PROPORTIONAL;
- }
- else if (0 == strcmp (opt_solver, "ril"))
- {
- solver = GNUNET_ATS_SOLVER_RIL;
- }
- else
- {
- fprintf (stderr, "No solver given ...");
- return;
- }
-
- /* load experiment */
- e = GNUNET_ATS_solvers_experimentation_load (opt_exp_file);
- if (NULL == e)
- {
- fprintf (stderr, "Failed to load experiment ...\n");
- return;
- }
-
- /* load solver */
- sh = GNUNET_ATS_solvers_solver_start (solver);
- if (NULL == sh)
- {
- fprintf (stderr, "Failed to start solver ...\n");
- return;
- }
-
- /* start logging */
-
- /* run experiment */
-
- /* WAIT */
-}
-
-
-/**
- * Main function of the benchmark
- *
- * @param argc argument count
- * @param argv argument values
- */
-int
-main (int argc, char *argv[])
-{
- opt_exp_file = NULL;
- opt_solver = NULL;
- opt_log = GNUNET_NO;
- opt_plot = GNUNET_NO;
-
- struct GNUNET_GETOPT_CommandLineOption options[] = {
- GNUNET_GETOPT_option_string ('s',
- "solver",
- NULL,
- gettext_noop ("solver to use"),
- &opt_solver),
-
- GNUNET_GETOPT_option_string ('e',
- "experiment",
- NULL,
- gettext_noop ("experiment to use"),
- &opt_exp_file),
-
- GNUNET_GETOPT_option_flag ('e',
- "experiment",
- gettext_noop ("experiment to use"),
- &opt_verbose),
- GNUNET_GETOPT_OPTION_END
- };
-
- if (GNUNET_OK !=
- GNUNET_PROGRAM_run (argc,
- argv, argv[0],
- NULL,
- options,
- &run, argv[0]))
- return 1;
-
- return 0;
-}
-
-
-/* end of file gnunet-solver-eval.c*/
diff --git a/src/ats-tests/gnunet_ats_sim_default.conf b/src/ats-tests/gnunet_ats_sim_default.conf
deleted file mode 100644
index a838306c3..000000000
--- a/src/ats-tests/gnunet_ats_sim_default.conf
+++ /dev/null
@@ -1,6 +0,0 @@
-@INLINE@ template_perf_ats.conf
-[transport]
-plugins = unix
-
-[ats]
-MODE = proportional
diff --git a/src/ats-tests/perf_ats.c b/src/ats-tests/perf_ats.c
deleted file mode 100644
index 64756b8aa..000000000
--- a/src/ats-tests/perf_ats.c
+++ /dev/null
@@ -1,601 +0,0 @@
-/*
- This file is part of GNUnet.
- Copyright (C) 2010-2013, 2016 GNUnet e.V.
-
- GNUnet is free software: you can redistribute it and/or modify it
- under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation, either version 3 of the License,
- or (at your option) any later version.
-
- GNUnet is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-
- SPDX-License-Identifier: AGPL3.0-or-later
- */
-/**
- * @file ats/perf_ats.c
- * @brief ats benchmark: start peers and modify preferences, monitor change over time
- * @author Christian Grothoff
- * @author Matthias Wachs
- */
-#include "platform.h"
-#include "gnunet_util_lib.h"
-#include "gnunet_testbed_service.h"
-#include "gnunet_ats_service.h"
-#include "gnunet_core_service.h"
-#include "ats-testing.h"
-
-
-#define TEST_ATS_PREFRENCE_FREQUENCY GNUNET_TIME_relative_multiply ( \
- GNUNET_TIME_UNIT_SECONDS, 1)
-#define TEST_ATS_PREFRENCE_START 1.0
-#define TEST_ATS_PREFRENCE_DELTA 1.0
-
-#define TEST_MESSAGE_FREQUENCY GNUNET_TIME_relative_multiply ( \
- GNUNET_TIME_UNIT_SECONDS, 1)
-
-#define TEST_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, \
- 120)
-#define BENCHMARK_DURATION GNUNET_TIME_relative_multiply ( \
- GNUNET_TIME_UNIT_SECONDS, 10)
-#define LOGGING_FREQUENCY GNUNET_TIME_relative_multiply ( \
- GNUNET_TIME_UNIT_MILLISECONDS, 500)
-#define TESTNAME_PREFIX "perf_ats_"
-#define DEFAULT_SLAVES_NUM 2
-#define DEFAULT_MASTERS_NUM 1
-
-/**
- * timeout task
- */
-static struct GNUNET_SCHEDULER_Task *timeout_task;
-
-/**
- * Progress task
- */
-static struct GNUNET_SCHEDULER_Task *progress_task;
-
-/**
- * Test result
- */
-static int result;
-
-/**
- * Test result logging
- */
-static int logging;
-
-/**
- * Test core (#GNUNET_YES) or transport (#GNUNET_NO)
- */
-static int test_core;
-
-/**
- * Solver string
- */
-static char *solver;
-
-/**
- * Preference string
- */
-static char *testname;
-
-/**
- * Preference string
- */
-static char *pref_str;
-
-/**
- * ATS preference value
- */
-static int pref_val;
-
-/**
- * Benchmark duration
- */
-static struct GNUNET_TIME_Relative perf_duration;
-
-/**
- * Logging frequency
- */
-static struct GNUNET_TIME_Relative log_frequency;
-
-/**
- * Number master peers
- */
-static unsigned int num_masters;
-
-/**
- * Array of master peers
- */
-static struct BenchmarkPeer *mps;
-
-/**
- * Number slave peers
- */
-static unsigned int num_slaves;
-
-/**
- * Array of master peers
- */
-static struct BenchmarkPeer *sps;
-
-static struct LoggingHandle *l;
-
-
-static void
-evaluate ()
-{
- int c_m;
- int c_s;
- unsigned int duration;
- struct BenchmarkPeer *mp;
- struct BenchmarkPartner *p;
-
- unsigned int kb_sent_sec;
- double kb_sent_percent;
- unsigned int kb_recv_sec;
- double kb_recv_percent;
- unsigned int rtt;
-
- duration = 1 + (perf_duration.rel_value_us / (1000 * 1000));
- for (c_m = 0; c_m < num_masters; c_m++)
- {
- mp = &mps[c_m];
- fprintf (stderr,
- "Master [%u]: sent: %u KiB in %u sec. = %u KiB/s, received: %u KiB in %u sec. = %u KiB/s\n",
- mp->no, mp->total_bytes_sent / 1024, duration,
- (mp->total_bytes_sent / 1024) / duration,
- mp->total_bytes_received / 1024, duration,
- (mp->total_bytes_received / 1024) / duration);
-
- for (c_s = 0; c_s < num_slaves; c_s++)
- {
- p = &mp->partners[c_s];
- kb_sent_sec = 0;
- kb_recv_sec = 0;
- kb_sent_percent = 0.0;
- kb_recv_percent = 0.0;
- rtt = 0;
-
- if (duration > 0)
- {
- kb_sent_sec = (p->bytes_sent / 1024) / duration;
- kb_recv_sec = (p->bytes_received / 1024) / duration;
- }
-
- if (mp->total_bytes_sent > 0)
- kb_sent_percent = ((double) p->bytes_sent * 100) / mp->total_bytes_sent;
- if (mp->total_bytes_received > 0)
- kb_recv_percent = ((double) p->bytes_received * 100)
- / mp->total_bytes_received;
- if (1000 * p->messages_sent > 0)
- rtt = p->total_app_rtt / (1000 * p->messages_sent);
- fprintf (stderr,
- "%c Master [%u] -> Slave [%u]: sent %u KiB/s (%.2f %%), received %u KiB/s (%.2f %%)\n",
- (mp->pref_partner == p->dest) ? '*' : ' ',
- mp->no, p->dest->no,
- kb_sent_sec, kb_sent_percent,
- kb_recv_sec, kb_recv_percent);
- fprintf (stderr,
- "%c Master [%u] -> Slave [%u]: Average application layer RTT: %u ms\n",
- (mp->pref_partner == p->dest) ? '*' : ' ',
- mp->no, p->dest->no, rtt);
- }
- }
-}
-
-
-/**
- * Shutdown nicely
- *
- * @param cls NULL
- */
-static void
-do_shutdown (void *cls)
-{
- if (GNUNET_YES == logging)
- GNUNET_ATS_TEST_logging_clean_up (l);
- if (NULL != timeout_task)
- {
- GNUNET_SCHEDULER_cancel (timeout_task);
- timeout_task = NULL;
- }
- if (NULL != progress_task)
- {
- fprintf (stderr, "0\n");
- GNUNET_SCHEDULER_cancel (progress_task);
- progress_task = NULL;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Benchmarking done\n");
- GNUNET_ATS_TEST_shutdown_topology ();
-}
-
-
-/**
- * Shutdown nicely
- *
- * @param cls NULL
- */
-static void
-do_timeout (void *cls)
-{
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Terminating with timeout\n");
- timeout_task = NULL;
- evaluate ();
- GNUNET_SCHEDULER_shutdown ();
-}
-
-
-static void
-print_progress (void *cls)
-{
- static int calls;
-
- progress_task = NULL;
- fprintf (stderr,
- "%llu..",
- (long long unsigned) perf_duration.rel_value_us / (1000 * 1000)
- - calls);
- calls++;
-
- progress_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
- &print_progress,
- NULL);
-}
-
-
-static void
-ats_pref_task (void *cls)
-{
- struct BenchmarkPeer *me = cls;
-
- me->ats_task = NULL;
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- " Master [%u] set preference for slave [%u] to %f\n",
- me->no, me->pref_partner->no, me->pref_value);
- GNUNET_ATS_performance_change_preference (me->ats_perf_handle,
- &me->pref_partner->id,
- pref_val, me->pref_value,
- GNUNET_ATS_PREFERENCE_END);
- me->pref_value += TEST_ATS_PREFRENCE_DELTA;
- me->ats_task = GNUNET_SCHEDULER_add_delayed (TEST_ATS_PREFRENCE_FREQUENCY,
- &ats_pref_task, cls);
-}
-
-
-static void
-start_benchmark (void *cls)
-{
- int c_m;
- int c_s;
-
- progress_task = GNUNET_SCHEDULER_add_now (&print_progress,
- NULL);
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Topology connected, start benchmarking...\n");
-
- /* Start sending test messages */
- for (c_m = 0; c_m < num_masters; c_m++)
- {
- for (c_s = 0; c_s < num_slaves; c_s++)
- {
- GNUNET_ATS_TEST_generate_traffic_start (&mps[c_m],
- &mps[c_m].partners[c_s],
- GNUNET_ATS_TEST_TG_LINEAR,
- UINT32_MAX,
- UINT32_MAX,
- GNUNET_TIME_UNIT_MINUTES,
- GNUNET_TIME_UNIT_FOREVER_REL);
- }
- if (pref_val != GNUNET_ATS_PREFERENCE_END)
- mps[c_m].ats_task = GNUNET_SCHEDULER_add_now (&ats_pref_task,
- &mps[c_m]);
- }
-
- if (GNUNET_YES == logging)
- l = GNUNET_ATS_TEST_logging_start (log_frequency,
- testname, mps,
- num_masters, num_slaves,
- GNUNET_NO);
-}
-
-
-static void
-do_benchmark (void *cls,
- struct BenchmarkPeer *masters,
- struct BenchmarkPeer *slaves)
-{
- mps = masters;
- sps = slaves;
- GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
- NULL);
- timeout_task = GNUNET_SCHEDULER_add_delayed (perf_duration,
- &do_timeout,
- NULL);
- progress_task = GNUNET_SCHEDULER_add_now (&start_benchmark,
- NULL);
-}
-
-
-static struct BenchmarkPartner *
-find_partner (struct BenchmarkPeer *me,
- const struct GNUNET_PeerIdentity *peer)
-{
- int c_m;
-
- GNUNET_assert (NULL != me);
- GNUNET_assert (NULL != peer);
-
- for (c_m = 0; c_m < me->num_partners; c_m++)
- {
- /* Find a partner with other as destination */
- if (0 == GNUNET_memcmp (peer, &me->partners[c_m].dest->id))
- {
- return &me->partners[c_m];
- }
- }
- return NULL;
-}
-
-
-static void
-log_request_cb (void *cls,
- const struct GNUNET_HELLO_Address *address,
- int address_active,
- struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
- struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
- const struct GNUNET_ATS_Properties *ats)
-{
- struct BenchmarkPeer *me = cls;
- struct BenchmarkPartner *p;
- char *peer_id;
-
- p = find_partner (me, &address->peer);
- if (NULL == p)
- {
- /* This is not one of my partners
- * Will happen since the peers will connect to each other due to gossiping
- */
- return;
- }
- peer_id = GNUNET_strdup (GNUNET_i2s (&me->id));
-
- if ((p->bandwidth_in != ntohl (bandwidth_in.value__)) ||
- (p->bandwidth_out != ntohl (bandwidth_out.value__)))
- p->bandwidth_in = ntohl (bandwidth_in.value__);
- p->bandwidth_out = ntohl (bandwidth_out.value__);
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "%s [%u] received ATS information for peers `%s'\n",
- (GNUNET_YES == p->me->master) ? "Master" : "Slave",
- p->me->no,
- GNUNET_i2s (&p->dest->id));
-
- GNUNET_free (peer_id);
- if (NULL != l)
- GNUNET_ATS_TEST_logging_now (l);
-}
-
-
-/*
- * Start the performance test case
- */
-int
-main (int argc, char *argv[])
-{
- char *tmp;
- char *tmp_sep;
- char *test_name;
- char *conf_name;
- char *comm_name;
- char *dotexe;
- char *prefs[] = GNUNET_ATS_PreferenceTypeString;
- int c;
-
- result = 0;
-
- /* Determine testname
- * perf_ats_<solver>_<transport>_<preference>[.exe]*/
-
- /* Find test prefix, store in temp */
- tmp = strstr (argv[0], TESTNAME_PREFIX);
- if (NULL == tmp)
- {
- fprintf (stderr, "Unable to parse test name `%s'\n", argv[0]);
- return GNUNET_SYSERR;
- }
-
- /* Set tmp to end of test name prefix */
- tmp += strlen (TESTNAME_PREFIX);
-
- /* Determine solver name */
- solver = GNUNET_strdup (tmp);
- /* Remove .exe prefix */
- if ((NULL != (dotexe = strstr (solver, ".exe"))) && (dotexe[4] == '\0'))
- dotexe[0] = '\0';
-
- /* Determine first '_' after solver */
- tmp_sep = strchr (solver, '_');
- if (NULL == tmp_sep)
- {
- fprintf (stderr, "Unable to parse test name `%s'\n", argv[0]);
- GNUNET_free (solver);
- return GNUNET_SYSERR;
- }
- tmp_sep[0] = '\0';
- comm_name = GNUNET_strdup (&tmp_sep[1]);
- tmp_sep = strchr (comm_name, '_');
- if (NULL == tmp_sep)
- {
- fprintf (stderr, "Unable to parse test name `%s'\n", argv[0]);
- GNUNET_free (solver);
- return GNUNET_SYSERR;
- }
- tmp_sep[0] = '\0';
- for (c = 0; c <= strlen (comm_name); c++)
- comm_name[c] = toupper (comm_name[c]);
- if (0 == strcmp (comm_name, "CORE"))
- test_core = GNUNET_YES;
- else if (0 == strcmp (comm_name, "TRANSPORT"))
- test_core = GNUNET_NO;
- else
- {
- GNUNET_free (comm_name);
- GNUNET_free (solver);
- return GNUNET_SYSERR;
- }
-
- pref_str = GNUNET_strdup (tmp_sep + 1);
-
- GNUNET_asprintf (&conf_name, "%s%s_%s.conf", TESTNAME_PREFIX, solver,
- pref_str);
- GNUNET_asprintf (&test_name, "%s%s_%s", TESTNAME_PREFIX, solver, pref_str);
-
- for (c = 0; c <= strlen (pref_str); c++)
- pref_str[c] = toupper (pref_str[c]);
- pref_val = -1;
-
- if (0 != strcmp (pref_str, "NONE"))
- {
- for (c = 0; c < GNUNET_ATS_PREFERENCE_END; c++)
- {
- if (0 == strcmp (pref_str, prefs[c]))
- {
- pref_val = c;
- break;
- }
- }
- }
- else
- {
- /* abuse terminator to indicate no pref */
- pref_val = GNUNET_ATS_PREFERENCE_END;
- }
- if (-1 == pref_val)
- {
- fprintf (stderr, "Unknown preference: `%s'\n", pref_str);
- GNUNET_free (solver);
- GNUNET_free (pref_str);
- GNUNET_free (comm_name);
- return -1;
- }
-
- for (c = 0; c < (argc - 1); c++)
- {
- if (0 == strcmp (argv[c], "-d"))
- break;
- }
- if (c < argc - 1)
- {
- if (GNUNET_OK != GNUNET_STRINGS_fancy_time_to_relative (argv[c + 1],
- &perf_duration))
- fprintf (stderr, "Failed to parse duration `%s'\n", argv[c + 1]);
- }
- else
- {
- perf_duration = BENCHMARK_DURATION;
- }
- fprintf (stderr, "Running benchmark for %llu secs\n", (unsigned long
- long) (perf_duration.
- rel_value_us)
- / (1000 * 1000));
-
- for (c = 0; c < (argc - 1); c++)
- {
- if (0 == strcmp (argv[c], "-s"))
- break;
- }
- if (c < argc - 1)
- {
- if ((0L != (num_slaves = strtol (argv[c + 1], NULL, 10)))
- && (num_slaves >= 1))
- fprintf (stderr, "Starting %u slave peers\n", num_slaves);
- else
- num_slaves = DEFAULT_SLAVES_NUM;
- }
- else
- num_slaves = DEFAULT_SLAVES_NUM;
-
- for (c = 0; c < (argc - 1); c++)
- {
- if (0 == strcmp (argv[c], "-m"))
- break;
- }
- if (c < argc - 1)
- {
- if ((0L != (num_masters = strtol (argv[c + 1], NULL, 10)))
- && (num_masters >= 2))
- fprintf (stderr, "Starting %u master peers\n", num_masters);
- else
- num_masters = DEFAULT_MASTERS_NUM;
- }
- else
- num_masters = DEFAULT_MASTERS_NUM;
-
- logging = GNUNET_NO;
- for (c = 0; c < argc; c++)
- {
- if (0 == strcmp (argv[c], "-l"))
- logging = GNUNET_YES;
- }
-
- if (GNUNET_YES == logging)
- {
- for (c = 0; c < (argc - 1); c++)
- {
- if (0 == strcmp (argv[c], "-f"))
- break;
- }
- if (c < argc - 1)
- {
- if (GNUNET_OK != GNUNET_STRINGS_fancy_time_to_relative (argv[c + 1],
- &log_frequency))
- fprintf (stderr, "Failed to parse duration `%s'\n", argv[c + 1]);
- }
- else
- {
- log_frequency = LOGGING_FREQUENCY;
- }
- fprintf (stderr, "Using log frequency %llu ms\n",
- (unsigned long long) (log_frequency.rel_value_us) / (1000));
- }
-
- GNUNET_asprintf (&testname, "%s_%s_%s", solver, comm_name, pref_str);
-
- if (num_slaves < num_masters)
- {
- fprintf (stderr,
- "Number of master peers is lower than slaves! exit...\n");
- GNUNET_free (test_name);
- GNUNET_free (solver);
- GNUNET_free (pref_str);
- GNUNET_free (comm_name);
- return GNUNET_SYSERR;
- }
-
- /**
- * Setup the topology
- */
- GNUNET_ATS_TEST_create_topology ("perf-ats",
- conf_name,
- num_slaves,
- num_masters,
- test_core,
- &do_benchmark,
- NULL,
- &log_request_cb);
-
- return result;
-}
-
-
-/* end of file perf_ats.c */
diff --git a/src/ats-tests/perf_ats.h b/src/ats-tests/perf_ats.h
deleted file mode 100644
index 6460aa098..000000000
--- a/src/ats-tests/perf_ats.h
+++ /dev/null
@@ -1,256 +0,0 @@
-/*
- This file is part of GNUnet.
- Copyright (C) 2010-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 ats/perf_ats.c
- * @brief ats benchmark: start peers and modify preferences, monitor change over time
- * @author Christian Grothoff
- * @author Matthias Wachs
- */
-#include "platform.h"
-#include "gnunet_util_lib.h"
-#include "gnunet_testbed_service.h"
-#include "gnunet_ats_service.h"
-#include "gnunet_core_service.h"
-#include "ats-testing.h"
-
-#define TEST_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, \
- 120)
-#define BENCHMARK_DURATION GNUNET_TIME_relative_multiply ( \
- GNUNET_TIME_UNIT_SECONDS, 10)
-#define LOGGING_FREQUENCY GNUNET_TIME_relative_multiply ( \
- GNUNET_TIME_UNIT_MILLISECONDS, 500)
-#define TESTNAME_PREFIX "perf_ats_"
-#define DEFAULT_SLAVES_NUM 2
-#define DEFAULT_MASTERS_NUM 1
-
-#define TEST_ATS_PREFRENCE_FREQUENCY GNUNET_TIME_relative_multiply ( \
- GNUNET_TIME_UNIT_SECONDS, 1)
-#define TEST_ATS_PREFRENCE_START 1.0
-#define TEST_ATS_PREFRENCE_DELTA 1.0
-
-#define TEST_MESSAGE_TYPE_PING 12345
-#define TEST_MESSAGE_TYPE_PONG 12346
-#define TEST_MESSAGE_SIZE 1000
-#define TEST_MESSAGE_FREQUENCY GNUNET_TIME_relative_multiply ( \
- GNUNET_TIME_UNIT_SECONDS, 1)
-
-/**
- * Information about a benchmarking partner
- */
-struct BenchmarkPartner
-{
- /**
- * The peer itself this partner belongs to
- */
- struct BenchmarkPeer *me;
-
- /**
- * The partner peer
- */
- struct BenchmarkPeer *dest;
-
- /**
- * Core transmit handles
- */
- struct GNUNET_CORE_TransmitHandle *cth;
-
- /**
- * Transport transmit handles
- */
- struct GNUNET_TRANSPORT_TransmitHandle *tth;
-
- /**
- * Timestamp to calculate communication layer delay
- */
- struct GNUNET_TIME_Absolute last_message_sent;
-
- /**
- * Accumulated RTT for all messages
- */
- unsigned int total_app_rtt;
-
- /**
- * Number of messages sent to this partner
- */
- unsigned int messages_sent;
-
- /**
- * Number of bytes sent to this partner
- */
- unsigned int bytes_sent;
-
- /**
- * Number of messages received from this partner
- */
- unsigned int messages_received;
-
- /**
- * Number of bytes received from this partner
- */
- unsigned int bytes_received;
-
- /* Current ATS properties */
-
- uint32_t ats_distance;
-
- uint32_t ats_delay;
-
- uint32_t bandwidth_in;
-
- uint32_t bandwidth_out;
-
- uint32_t ats_utilization_up;
-
- uint32_t ats_utilization_down;
-
- uint32_t ats_network_type;
-
- uint32_t ats_cost_wan;
-
- uint32_t ats_cost_lan;
-
- uint32_t ats_cost_wlan;
-};
-
-
-/**
- * Information we track for a peer in the testbed.
- */
-struct BenchmarkPeer
-{
- /**
- * Handle with testbed.
- */
- struct GNUNET_TESTBED_Peer *peer;
-
- /**
- * Unique identifier
- */
- int no;
-
- /**
- * Is this peer a measter: GNUNET_YES/GNUNET_NO
- */
- int master;
-
- /**
- * Peer ID
- */
- struct GNUNET_PeerIdentity id;
-
- /**
- * Testbed operation to get peer information
- */
- struct GNUNET_TESTBED_Operation *peer_id_op;
-
- /**
- * Testbed operation to connect to ATS performance service
- */
- struct GNUNET_TESTBED_Operation *ats_perf_op;
-
- /**
- * Testbed operation to connect to core
- */
- struct GNUNET_TESTBED_Operation *comm_op;
-
- /**
- * ATS performance handle
- */
- struct GNUNET_ATS_PerformanceHandle *ats_perf_handle;
-
- /**
- * Masters only:
- * Testbed connect operations to connect masters to slaves
- */
- struct TestbedConnectOperation *core_connect_ops;
-
- /**
- * Core handle
- */
- struct GNUNET_CORE_Handle *ch;
-
- /**
- * Core handle
- */
- struct GNUNET_TRANSPORT_Handle *th;
-
- /**
- * Masters only:
- * Peer to set ATS preferences for
- */
- struct BenchmarkPeer *pref_partner;
-
- /**
- * Masters only
- * Progress task
- */
- struct GNUNET_SCHEDULER_Task *ats_task;
-
- /**
- * Masters only
- * Progress task
- */
- double pref_value;
-
- /**
- * Array of partners with num_slaves entries (if master) or
- * num_master entries (if slave)
- */
- struct BenchmarkPartner *partners;
-
- /**
- * Number of partners
- */
- int num_partners;
-
- /**
- * Number of core connections
- */
- int core_connections;
-
- /**
- * Masters only:
- * Number of connections to slave peers
- */
- int core_slave_connections;
-
- /**
- * Total number of messages this peer has sent
- */
- unsigned int total_messages_sent;
-
- /**
- * Total number of bytes this peer has sent
- */
- unsigned int total_bytes_sent;
-
- /**
- * Total number of messages this peer has received
- */
- unsigned int total_messages_received;
-
- /**
- * Total number of bytes this peer has received
- */
- unsigned int total_bytes_received;
-};
-
-
-/* end of file perf_ats.h */
diff --git a/src/ats-tests/perf_ats_logging.c b/src/ats-tests/perf_ats_logging.c
deleted file mode 100644
index ac8fa8950..000000000
--- a/src/ats-tests/perf_ats_logging.c
+++ /dev/null
@@ -1,780 +0,0 @@
-/*
- This file is part of GNUnet.
- Copyright (C) 2010-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 ats/perf_ats_logging.c
- * @brief ats benchmark: logging for performance tests
- * @author Christian Grothoff
- * @author Matthias Wachs
- */
-#include "platform.h"
-#include "gnunet_util_lib.h"
-#include "perf_ats.h"
-
-#define THROUGHPUT_TEMPLATE "#!/usr/bin/gnuplot \n" \
- "set datafile separator ';' \n" \
- "set title \"Throughput between Master and Slaves\" \n" \
- "set xlabel \"Time in ms\" \n" \
- "set ylabel \"Bytes/s\" \n" \
- "set grid \n"
-
-#define RTT_TEMPLATE "#!/usr/bin/gnuplot \n" \
- "set datafile separator ';' \n" \
- "set title \"Application level roundtrip time between Master and Slaves\" \n" \
- "set xlabel \"Time in ms\" \n" \
- "set ylabel \"ms\" \n" \
- "set grid \n"
-
-#define BW_TEMPLATE "#!/usr/bin/gnuplot \n" \
- "set datafile separator ';' \n" \
- "set title \"Bandwidth inbound and outbound between Master and Slaves\" \n" \
- "set xlabel \"Time in ms\" \n" \
- "set ylabel \"Bytes / s \" \n" \
- "set grid \n"
-
-#define LOG_ITEMS_TIME 2
-#define LOG_ITEMS_PER_PEER 17
-
-#define LOG_ITEM_BYTES_SENT 1
-#define LOG_ITEM_MSGS_SENT 2
-#define LOG_ITEM_THROUGHPUT_SENT 3
-#define LOG_ITEM_BYTES_RECV 4
-#define LOG_ITEM_MSGS_RECV 5
-#define LOG_ITEM_THROUGHPUT_RECV 6
-#define LOG_ITEM_APP_RTT 7
-#define LOG_ITEM_ATS_BW_IN 8
-#define LOG_ITEM_ATS_BW_OUT 9
-#define LOG_ITEM_ATS_COSTS_LAN 10
-#define LOG_ITEM_ATS_WAN 11
-#define LOG_ITEM_ATS_WLAN 12
-#define LOG_ITEM_ATS_DELAY 13
-#define LOG_ITEM_ATS_DISTANCE 14
-#define LOG_ITEM_ATS_NETWORKTYPE 15
-#define LOG_ITEM_ATS_UTIL_UP 16
-#define LOG_ITEM_ATS_UTIL_DOWN 17
-
-/**
- * Logging task
- */
-static struct GNUNET_SCHEDULER_Task *log_task;
-
-/**
- * Reference to perf_ats' masters
- */
-static int num_peers;
-static int running;
-static char *name;
-static struct GNUNET_TIME_Relative frequency;
-
-/**
- * A single logging time step for a partner
- */
-struct PartnerLoggingTimestep
-{
- /**
- * Peer
- */
- struct BenchmarkPeer *slave;
-
- /**
- * Total number of messages this peer has sent
- */
- unsigned int total_messages_sent;
-
- /**
- * Total number of bytes this peer has sent
- */
- unsigned int total_bytes_sent;
-
- /**
- * Total number of messages this peer has received
- */
- unsigned int total_messages_received;
-
- /**
- * Total number of bytes this peer has received
- */
- unsigned int total_bytes_received;
-
- /**
- * Total outbound throughput for master in Bytes / s
- */
- unsigned int throughput_sent;
-
- /**
- * Total inbound throughput for master in Bytes / s
- */
- unsigned int throughput_recv;
-
- /**
- * Accumulated RTT for all messages
- */
- unsigned int total_app_rtt;
-
- /**
- * Current application level delay
- */
- unsigned int app_rtt;
-
- /* Current ATS properties */
-
- uint32_t ats_distance;
-
- uint32_t ats_delay;
-
- uint32_t bandwidth_in;
-
- uint32_t bandwidth_out;
-
- uint32_t ats_utilization_up;
-
- uint32_t ats_utilization_down;
-
- uint32_t ats_network_type;
-
- uint32_t ats_cost_wan;
-
- uint32_t ats_cost_lan;
-
- uint32_t ats_cost_wlan;
-};
-
-
-/**
- * A single logging time step for a peer
- */
-struct PeerLoggingTimestep
-{
- /**
- * Next in DLL
- */
- struct PeerLoggingTimestep *next;
-
- /**
- * Prev in DLL
- */
- struct PeerLoggingTimestep *prev;
-
- /**
- * Logging timestamp
- */
- struct GNUNET_TIME_Absolute timestamp;
-
- /**
- * Total number of messages this peer has sent
- */
- unsigned int total_messages_sent;
-
- /**
- * Total number of bytes this peer has sent
- */
- unsigned int total_bytes_sent;
-
- /**
- * Total number of messages this peer has received
- */
- unsigned int total_messages_received;
-
- /**
- * Total number of bytes this peer has received
- */
- unsigned int total_bytes_received;
-
- /**
- * Total outbound throughput for master in Bytes / s
- */
- unsigned int total_throughput_send;
-
- /**
- * Total inbound throughput for master in Bytes / s
- */
- unsigned int total_throughput_recv;
-
- /**
- * Logs for slaves
- */
- struct PartnerLoggingTimestep *slaves_log;
-};
-
-/**
- * Entry for a benchmark peer
- */
-struct LoggingPeer
-{
- /**
- * Peer
- */
- struct BenchmarkPeer *peer;
-
- /**
- * Start time
- */
- struct GNUNET_TIME_Absolute start;
-
- /**
- * DLL for logging entries: head
- */
- struct PeerLoggingTimestep *head;
-
- /**
- * DLL for logging entries: tail
- */
- struct PeerLoggingTimestep *tail;
-};
-
-/**
- * Log structure of length num_peers
- */
-static struct LoggingPeer *lp;
-
-
-static void
-write_throughput_gnuplot_script (char *fn, struct LoggingPeer *lp)
-{
- struct GNUNET_DISK_FileHandle *f;
- char *gfn;
- char *data;
- int c_s;
- int peer_index;
-
- GNUNET_asprintf (&gfn, "gnuplot_throughput_%s", fn);
- f = GNUNET_DISK_file_open (gfn,
- GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE,
- GNUNET_DISK_PERM_USER_EXEC
- | GNUNET_DISK_PERM_USER_READ
- | GNUNET_DISK_PERM_USER_WRITE);
- if (NULL == f)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot open gnuplot file `%s'\n",
- gfn);
- GNUNET_free (gfn);
- return;
- }
-
- /* Write header */
-
- if (GNUNET_SYSERR == GNUNET_DISK_file_write (f, THROUGHPUT_TEMPLATE, strlen (
- THROUGHPUT_TEMPLATE)))
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Cannot write data to plot file `%s'\n", gfn);
-
- /* Write master data */
- peer_index = LOG_ITEMS_TIME;
- GNUNET_asprintf (&data,
- "plot '%s' using 2:%u with lines title 'Master %u send total', \\\n" \
- "'%s' using 2:%u with lines title 'Master %u receive total', \\\n",
- fn, peer_index + LOG_ITEM_THROUGHPUT_SENT, lp->peer->no,
- fn, peer_index + LOG_ITEM_THROUGHPUT_RECV, lp->peer->no);
- if (GNUNET_SYSERR == GNUNET_DISK_file_write (f, data, strlen (data)))
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Cannot write data to plot file `%s'\n", gfn);
- GNUNET_free (data);
-
- peer_index = LOG_ITEMS_TIME + LOG_ITEMS_PER_PEER;
- for (c_s = 0; c_s < lp->peer->num_partners; c_s++)
- {
- GNUNET_asprintf (&data,
- "'%s' using 2:%u with lines title 'Master %u - Slave %u send', \\\n" \
- "'%s' using 2:%u with lines title 'Master %u - Slave %u receive'%s\n",
- fn, peer_index + LOG_ITEM_THROUGHPUT_SENT, lp->peer->no,
- lp->peer->partners[c_s].dest->no,
- fn, peer_index + LOG_ITEM_THROUGHPUT_RECV, lp->peer->no,
- lp->peer->partners[c_s].dest->no,
- (c_s < lp->peer->num_partners - 1) ? ", \\" :
- "\n pause -1");
- if (GNUNET_SYSERR == GNUNET_DISK_file_write (f, data, strlen (data)))
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Cannot write data to plot file `%s'\n", gfn);
- GNUNET_free (data);
- peer_index += LOG_ITEMS_PER_PEER;
- }
-
- if (GNUNET_SYSERR == GNUNET_DISK_file_close (f))
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot close gnuplot file `%s'\n",
- gfn);
- else
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Data successfully written to plot file `%s'\n", gfn);
-
- GNUNET_free (gfn);
-}
-
-
-static void
-write_rtt_gnuplot_script (char *fn, struct LoggingPeer *lp)
-{
- struct GNUNET_DISK_FileHandle *f;
- char *gfn;
- char *data;
- int c_s;
- int index;
-
- GNUNET_asprintf (&gfn, "gnuplot_rtt_%s", fn);
- f = GNUNET_DISK_file_open (gfn,
- GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE,
- GNUNET_DISK_PERM_USER_EXEC
- | GNUNET_DISK_PERM_USER_READ
- | GNUNET_DISK_PERM_USER_WRITE);
- if (NULL == f)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot open gnuplot file `%s'\n",
- gfn);
- GNUNET_free (gfn);
- return;
- }
-
- /* Write header */
-
- if (GNUNET_SYSERR == GNUNET_DISK_file_write (f, RTT_TEMPLATE, strlen (
- RTT_TEMPLATE)))
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Cannot write data to plot file `%s'\n", gfn);
-
- index = LOG_ITEMS_TIME + LOG_ITEMS_PER_PEER;
- for (c_s = 0; c_s < lp->peer->num_partners; c_s++)
- {
- GNUNET_asprintf (&data,
- "%s'%s' using 2:%u with lines title 'Master %u - Slave %u '%s\n",
- (0 == c_s) ? "plot " : "",
- fn, index + LOG_ITEM_APP_RTT, lp->peer->no,
- lp->peer->partners[c_s].dest->no,
- (c_s < lp->peer->num_partners - 1) ? ", \\" :
- "\n pause -1");
- if (GNUNET_SYSERR == GNUNET_DISK_file_write (f, data, strlen (data)))
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Cannot write data to plot file `%s'\n", gfn);
- GNUNET_free (data);
- index += LOG_ITEMS_PER_PEER;
- }
-
- if (GNUNET_SYSERR == GNUNET_DISK_file_close (f))
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot close gnuplot file `%s'\n",
- gfn);
- else
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Data successfully written to plot file `%s'\n", gfn);
- GNUNET_free (gfn);
-}
-
-
-static void
-write_bw_gnuplot_script (char *fn, struct LoggingPeer *lp)
-{
- struct GNUNET_DISK_FileHandle *f;
- char *gfn;
- char *data;
- int c_s;
- int index;
-
- GNUNET_asprintf (&gfn, "gnuplot_bw_%s", fn);
- f = GNUNET_DISK_file_open (gfn,
- GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE,
- GNUNET_DISK_PERM_USER_EXEC
- | GNUNET_DISK_PERM_USER_READ
- | GNUNET_DISK_PERM_USER_WRITE);
- if (NULL == f)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot open gnuplot file `%s'\n",
- gfn);
- GNUNET_free (gfn);
- return;
- }
-
- /* Write header */
-
- if (GNUNET_SYSERR == GNUNET_DISK_file_write (f, BW_TEMPLATE, strlen (
- BW_TEMPLATE)))
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Cannot write data to plot file `%s'\n", gfn);
-
- index = LOG_ITEMS_TIME + LOG_ITEMS_PER_PEER;
- for (c_s = 0; c_s < lp->peer->num_partners; c_s++)
- {
- GNUNET_asprintf (&data, "%s" \
- "'%s' using 2:%u with lines title 'BW out master %u - Slave %u ', \\\n" \
- "'%s' using 2:%u with lines title 'BW in master %u - Slave %u '" \
- "%s\n",
- (0 == c_s) ? "plot " : "",
- fn, index + LOG_ITEM_ATS_BW_OUT, lp->peer->no,
- lp->peer->partners[c_s].dest->no,
- fn, index + LOG_ITEM_ATS_BW_IN, lp->peer->no,
- lp->peer->partners[c_s].dest->no,
- (c_s < lp->peer->num_partners - 1) ? ", \\" :
- "\n pause -1");
- if (GNUNET_SYSERR == GNUNET_DISK_file_write (f, data, strlen (data)))
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Cannot write data to plot file `%s'\n", gfn);
- GNUNET_free (data);
- index += LOG_ITEMS_PER_PEER;
- }
-
- if (GNUNET_SYSERR == GNUNET_DISK_file_close (f))
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot close gnuplot file `%s'\n",
- gfn);
- else
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Data successfully written to plot file `%s'\n", gfn);
- GNUNET_free (gfn);
-}
-
-
-static void
-write_to_file ()
-{
- struct GNUNET_DISK_FileHandle *f;
-
- char *filename;
- char *data;
- char *slave_string;
- char *slave_string_tmp;
- struct PeerLoggingTimestep *cur_lt;
- struct PartnerLoggingTimestep *plt;
- int c_m;
- int c_s;
-
- for (c_m = 0; c_m < num_peers; c_m++)
- {
- GNUNET_asprintf (&filename, "%llu_master_%u_%s_%s.data",
- GNUNET_TIME_absolute_get ().abs_value_us,
- lp[c_m].peer->no, GNUNET_i2s (&lp[c_m].peer->id), name);
-
- f = GNUNET_DISK_file_open (filename,
- GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE,
- GNUNET_DISK_PERM_USER_READ
- | GNUNET_DISK_PERM_USER_WRITE);
- if (NULL == f)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot open log file `%s'\n",
- filename);
- GNUNET_free (filename);
- return;
- }
-
- for (cur_lt = lp[c_m].head; NULL != cur_lt; cur_lt = cur_lt->next)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Master [%u]: timestamp %llu %llu ; %u %u %u ; %u %u %u\n",
- lp[c_m].peer->no,
- cur_lt->timestamp, GNUNET_TIME_absolute_get_difference (
- lp[c_m].start, cur_lt->timestamp).rel_value_us / 1000,
- cur_lt->total_messages_sent, cur_lt->total_bytes_sent,
- cur_lt->total_throughput_send,
- cur_lt->total_messages_received, cur_lt->total_bytes_received,
- cur_lt->total_throughput_recv);
-
- slave_string = GNUNET_strdup (";");
- for (c_s = 0; c_s < lp[c_m].peer->num_partners; c_s++)
- {
- plt = &cur_lt->slaves_log[c_s];
- /* Log partners */
-
- /* Assembling slave string */
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "\t Slave [%u]: %u %u %u ; %u %u %u rtt %u delay %u bw_in %u bw_out %u \n",
- plt->slave->no,
- plt->total_messages_sent, plt->total_bytes_sent,
- plt->throughput_sent,
- plt->total_messages_received, plt->total_bytes_received,
- plt->throughput_recv,
- plt->app_rtt, plt->ats_delay,
- plt->bandwidth_in, plt->bandwidth_out);
-
- GNUNET_asprintf (&slave_string_tmp,
- "%s%u;%u;%u;%u;%u;%u;%.3f;%u;%u;%u;%u;%u;%u;%u;%u;%u;%u;",
- slave_string,
- plt->total_messages_sent, plt->total_bytes_sent,
- plt->throughput_sent,
- plt->total_messages_received,
- plt->total_bytes_received, plt->throughput_sent,
- (double) plt->app_rtt / 1000,
- plt->bandwidth_in, plt->bandwidth_out,
- plt->ats_cost_lan, plt->ats_cost_wan,
- plt->ats_cost_wlan,
- plt->ats_delay, plt->ats_distance,
- plt->ats_network_type,
- plt->ats_utilization_up, plt->ats_utilization_down);
- GNUNET_free (slave_string);
- slave_string = slave_string_tmp;
- }
- /* Assembling master string */
-
-
- GNUNET_asprintf (&data, "%llu;%llu;%u;%u;%u;%u;%u;%u;;;;;;;;;;;%s\n",
- cur_lt->timestamp,
- GNUNET_TIME_absolute_get_difference (lp[c_m].start,
- cur_lt->timestamp).
- rel_value_us / 1000,
- cur_lt->total_messages_sent, cur_lt->total_bytes_sent,
- cur_lt->total_throughput_send,
- cur_lt->total_messages_received,
- cur_lt->total_bytes_received,
- cur_lt->total_throughput_recv,
- slave_string);
- GNUNET_free (slave_string);
-
- if (GNUNET_SYSERR == GNUNET_DISK_file_write (f, data, strlen (data)))
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Cannot write data to log file `%s'\n", filename);
- GNUNET_free (data);
- }
- if (GNUNET_SYSERR == GNUNET_DISK_file_close (f))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot close log file `%s'\n",
- filename);
- GNUNET_free (filename);
- return;
- }
-
- write_throughput_gnuplot_script (filename, lp);
- write_rtt_gnuplot_script (filename, lp);
- write_bw_gnuplot_script (filename, lp);
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Data file successfully written to log file `%s'\n", filename);
- GNUNET_free (filename);
- }
-}
-
-
-void
-collect_log_now (void)
-{
- struct LoggingPeer *bp;
- struct PeerLoggingTimestep *mlt;
- struct PeerLoggingTimestep *prev_log_mlt;
- struct PartnerLoggingTimestep *slt;
- struct PartnerLoggingTimestep *prev_log_slt;
- struct BenchmarkPartner *p;
- struct GNUNET_TIME_Relative delta;
- int c_s;
- int c_m;
- unsigned int app_rtt;
- double mult;
-
- if (GNUNET_YES != running)
- return;
-
- for (c_m = 0; c_m < num_peers; c_m++)
- {
- bp = &lp[c_m];
- mlt = GNUNET_new (struct PeerLoggingTimestep);
- GNUNET_CONTAINER_DLL_insert_tail (bp->head, bp->tail, mlt);
- prev_log_mlt = mlt->prev;
-
- /* Collect data */
-
- /* Current master state */
- mlt->timestamp = GNUNET_TIME_absolute_get ();
- mlt->total_bytes_sent = bp->peer->total_bytes_sent;
- mlt->total_messages_sent = bp->peer->total_messages_sent;
- mlt->total_bytes_received = bp->peer->total_bytes_received;
- mlt->total_messages_received = bp->peer->total_messages_received;
-
- /* Throughput */
- if (NULL == prev_log_mlt)
- {
- /* Get difference to start */
- delta = GNUNET_TIME_absolute_get_difference (lp[c_m].start,
- mlt->timestamp);
- }
- else
- {
- /* Get difference to last timestep */
- delta = GNUNET_TIME_absolute_get_difference (mlt->prev->timestamp,
- mlt->timestamp);
- }
-
- /* Multiplication factor for throughput calculation */
- mult = (1.0 * 1000 * 1000) / (delta.rel_value_us);
-
- /* Total throughput */
- if (NULL != prev_log_mlt)
- {
- if (mlt->total_bytes_sent - mlt->prev->total_bytes_sent > 0)
- mlt->total_throughput_send = mult * (mlt->total_bytes_sent
- - mlt->prev->total_bytes_sent);
- else
- mlt->total_throughput_send = prev_log_mlt->total_throughput_send; /* no msgs send */
-
- if (mlt->total_bytes_received - mlt->prev->total_bytes_received > 0)
- mlt->total_throughput_recv = mult * (mlt->total_bytes_received
- - mlt->prev->total_bytes_received);
- else
- mlt->total_throughput_recv = prev_log_mlt->total_throughput_recv; /* no msgs received */
- }
- else
- {
- mlt->total_throughput_send = mult * mlt->total_bytes_sent;
- mlt->total_throughput_send = mult * mlt->total_bytes_received;
- }
-
- mlt->slaves_log = GNUNET_malloc (bp->peer->num_partners
- * sizeof(struct PartnerLoggingTimestep));
-
- for (c_s = 0; c_s < bp->peer->num_partners; c_s++)
- {
- p = &bp->peer->partners[c_s];
- slt = &mlt->slaves_log[c_s];
-
- slt->slave = p->dest;
- /* Bytes sent from master to this slave */
- slt->total_bytes_sent = p->bytes_sent;
- /* Messages sent from master to this slave */
- slt->total_messages_sent = p->messages_sent;
- /* Bytes master received from this slave */
- slt->total_bytes_received = p->bytes_received;
- /* Messages master received from this slave */
- slt->total_messages_received = p->messages_received;
- slt->total_app_rtt = p->total_app_rtt;
- /* ats performance information */
- slt->ats_cost_lan = p->ats_cost_lan;
- slt->ats_cost_wan = p->ats_cost_wan;
- slt->ats_cost_wlan = p->ats_cost_wlan;
- slt->ats_delay = p->ats_delay;
- slt->ats_distance = p->ats_distance;
- slt->ats_network_type = p->ats_network_type;
- slt->ats_utilization_down = p->ats_utilization_down;
- slt->ats_utilization_up = p->ats_utilization_up;
- slt->bandwidth_in = p->bandwidth_in;
- slt->bandwidth_out = p->bandwidth_out;
-
- /* Total application level rtt */
- if (NULL == prev_log_mlt)
- {
- if (0 != slt->total_messages_sent)
- app_rtt = slt->total_app_rtt / slt->total_messages_sent;
- else
- app_rtt = 0;
- }
- else
- {
- prev_log_slt = &prev_log_mlt->slaves_log[c_s];
- if ((slt->total_messages_sent - prev_log_slt->total_messages_sent) > 0)
- app_rtt = (slt->total_app_rtt - prev_log_slt->total_app_rtt)
- / (slt->total_messages_sent
- - prev_log_slt->total_messages_sent);
- else
- app_rtt = prev_log_slt->app_rtt; /* No messages were */
- }
- slt->app_rtt = app_rtt;
-
- /* Partner throughput */
- if (NULL != prev_log_mlt)
- {
- prev_log_slt = &prev_log_mlt->slaves_log[c_s];
- if (slt->total_bytes_sent - prev_log_slt->total_bytes_sent > 0)
- slt->throughput_sent = mult * (slt->total_bytes_sent
- - prev_log_slt->total_bytes_sent);
- else
- slt->throughput_sent = prev_log_slt->throughput_sent; /* no msgs send */
-
- if (slt->total_bytes_received - prev_log_slt->total_bytes_received > 0)
- slt->throughput_recv = mult * (slt->total_bytes_received
- - prev_log_slt->total_bytes_received);
- else
- slt->throughput_recv = prev_log_slt->throughput_recv; /* no msgs received */
- }
- else
- {
- slt->throughput_sent = mult * slt->total_bytes_sent;
- slt->throughput_sent = mult * slt->total_bytes_received;
- }
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Master [%u]: slave [%u]\n",
- bp->peer->no, p->dest->no);
- }
- }
-}
-
-
-static void
-collect_log_task (void *cls)
-{
- log_task = NULL;
- collect_log_now ();
- log_task = GNUNET_SCHEDULER_add_delayed (frequency,
- &collect_log_task, NULL);
-}
-
-
-void
-perf_logging_stop ()
-{
- int c_m;
- struct PeerLoggingTimestep *cur;
-
- if (GNUNET_YES != running)
- return;
-
- if (NULL != log_task)
- {
- GNUNET_SCHEDULER_cancel (log_task);
- log_task = NULL;
- }
- collect_log_task (NULL);
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _ ("Stop logging\n"));
-
- write_to_file ();
-
- for (c_m = 0; c_m < num_peers; c_m++)
- {
- while (NULL != (cur = lp[c_m].head))
- {
- GNUNET_CONTAINER_DLL_remove (lp[c_m].head, lp[c_m].tail, cur);
- GNUNET_free (cur->slaves_log);
- GNUNET_free (cur);
- }
- }
-
- GNUNET_free (lp);
-}
-
-
-void
-perf_logging_start (struct GNUNET_TIME_Relative log_frequency,
- char *testname, struct BenchmarkPeer *masters, int
- num_masters)
-{
- int c_m;
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _ ("Start logging `%s'\n"), testname);
-
- num_peers = num_masters;
- name = testname;
- frequency = log_frequency;
-
- lp = GNUNET_malloc (num_masters * sizeof(struct LoggingPeer));
-
- for (c_m = 0; c_m < num_masters; c_m++)
- {
- lp[c_m].peer = &masters[c_m];
- lp[c_m].start = GNUNET_TIME_absolute_get ();
- }
-
- /* Schedule logging task */
- log_task = GNUNET_SCHEDULER_add_now (&collect_log_task, NULL);
- running = GNUNET_YES;
-}
-
-
-/* end of file perf_ats_logging.c */
diff --git a/src/ats-tests/perf_ats_proportional_bandwidth.conf b/src/ats-tests/perf_ats_proportional_bandwidth.conf
deleted file mode 100644
index dba96c0fe..000000000
--- a/src/ats-tests/perf_ats_proportional_bandwidth.conf
+++ /dev/null
@@ -1,4 +0,0 @@
-@INLINE@ template_perf_ats.conf
-
-[ats]
-MODE = proportional
diff --git a/src/ats-tests/perf_ats_proportional_latency.conf b/src/ats-tests/perf_ats_proportional_latency.conf
deleted file mode 100644
index dba96c0fe..000000000
--- a/src/ats-tests/perf_ats_proportional_latency.conf
+++ /dev/null
@@ -1,4 +0,0 @@
-@INLINE@ template_perf_ats.conf
-
-[ats]
-MODE = proportional
diff --git a/src/ats-tests/perf_ats_proportional_none.conf b/src/ats-tests/perf_ats_proportional_none.conf
deleted file mode 100644
index dba96c0fe..000000000
--- a/src/ats-tests/perf_ats_proportional_none.conf
+++ /dev/null
@@ -1,4 +0,0 @@
-@INLINE@ template_perf_ats.conf
-
-[ats]
-MODE = proportional
diff --git a/src/ats-tests/template_perf_ats.conf b/src/ats-tests/template_perf_ats.conf
deleted file mode 100644
index 74f608bfb..000000000
--- a/src/ats-tests/template_perf_ats.conf
+++ /dev/null
@@ -1,52 +0,0 @@
-@INLINE@ ../../contrib/conf/gnunet/no_forcestart.conf
-
-[testbed]
-# How long should operations wait?
-OPERATION_TIMEOUT = 60 s
-
-[transport-udp]
-BROADCAST = NO
-
-[peerinfo]
-USE_INCLUDED_HELLOS = NO
-
-[transport]
-#PREFIX = valgrind --leak-check=yes
-
-[ats]
-# PREFIX = valgrind
-
-# Network specific inbound/outbound quotas
-UNSPECIFIED_QUOTA_IN = 128 KiB
-UNSPECIFIED_QUOTA_OUT = 128 KiB
-# LOOPBACK
-LOOPBACK_QUOTA_IN = 128 KiB
-LOOPBACK_QUOTA_OUT = 128 KiB
-# LAN
-LAN_QUOTA_IN = 128 KiB
-LAN_QUOTA_OUT = 128 KiB
-# WAN
-WAN_QUOTA_IN = 128 KiB
-WAN_QUOTA_OUT = 128 KiB
-# WLAN
-WLAN_QUOTA_IN = 128 KiB
-WLAN_QUOTA_OUT = 128 KiB
-# BLUETOOTH
-BLUETOOTH_QUOTA_IN = 128 KiB
-BLUETOOTH_QUOTA_OUT = 128 KiB
-
-[transport-blacklist-M1RGJB4FQSM17JJ3M9BF7Q0I8MCO8C462NMOHI26RLT7C7A2KE6HCOPRA4ARM5HPL1J9IDDK5G8SFU5GUSHCTBH90ECETK1BFQD76R0]
-HIJN5O404QNUR37OSJUTNJ6H2KJS198DHI2J3I8SE3DMKVRG1RNQPODN1IJBF14KEMPPPRM0B9F9ILFKHOFCA655CH6M5OCNCMR0FE0 =
-CDTU8QQ8UPLGHR3B91V0CLTDOHONLB8QGHGUEM2JM1GANTEV0O6T20SD2N2HDN2QSHDG6IDTBR48KRDCS601FI6VHG59E7DQA98JD2O =
-
-[transport-blacklist-93ARIS6Q347RPU9EFPS9LA00VPHQLG3RBLKEKTHV4D6UVGEAC75KIIBFB5U9KK9P9P1RU1CBPV4BSSDUTB2AL2N2LG9KSO9APQNLS0O]
-HIJN5O404QNUR37OSJUTNJ6H2KJS198DHI2J3I8SE3DMKVRG1RNQPODN1IJBF14KEMPPPRM0B9F9ILFKHOFCA655CH6M5OCNCMR0FE0 =
-CDTU8QQ8UPLGHR3B91V0CLTDOHONLB8QGHGUEM2JM1GANTEV0O6T20SD2N2HDN2QSHDG6IDTBR48KRDCS601FI6VHG59E7DQA98JD2O =
-
-[transport-blacklist-OF84RAOAU2B1SOSEHJH6350MA0F7C98U55RI76LGIQOM7O33TFHPNUFB47CDBSCOLIINMVJ2U82445ABOBQRIVREG20L31KVDV5HG60]
-HIJN5O404QNUR37OSJUTNJ6H2KJS198DHI2J3I8SE3DMKVRG1RNQPODN1IJBF14KEMPPPRM0B9F9ILFKHOFCA655CH6M5OCNCMR0FE0 =
-CDTU8QQ8UPLGHR3B91V0CLTDOHONLB8QGHGUEM2JM1GANTEV0O6T20SD2N2HDN2QSHDG6IDTBR48KRDCS601FI6VHG59E7DQA98JD2O =
-
-[transport-blacklist-548J7M14O4I0F8I84U0UFARVJ97DB6QOT3MCA8O8SNAIT5JJ8TR95LUVAP3N5L7DN33IB49SNMF3Q3C0VPLTGP9ASCULA9S2OIMHHH8]
-HIJN5O404QNUR37OSJUTNJ6H2KJS198DHI2J3I8SE3DMKVRG1RNQPODN1IJBF14KEMPPPRM0B9F9ILFKHOFCA655CH6M5OCNCMR0FE0 =
-CDTU8QQ8UPLGHR3B91V0CLTDOHONLB8QGHGUEM2JM1GANTEV0O6T20SD2N2HDN2QSHDG6IDTBR48KRDCS601FI6VHG59E7DQA98JD2O =
diff --git a/src/block/Makefile.am b/src/block/Makefile.am
index ceeff4c66..ea796bf8f 100644
--- a/src/block/Makefile.am
+++ b/src/block/Makefile.am
@@ -26,10 +26,6 @@ libgnunet_plugin_block_template_la_LIBADD = \
libgnunetblock.la \
$(top_builddir)/src/util/libgnunetutil.la \
$(LTLIBINTL)
-libgnunet_plugin_block_template_la_DEPENDENCIES = \
- libgnunetblockgroup.la \
- libgnunetblock.la \
- $(top_builddir)/src/util/libgnunetutil.la
libgnunet_plugin_block_template_la_LDFLAGS = \
$(GN_PLUGIN_LDFLAGS)
@@ -40,10 +36,6 @@ libgnunet_plugin_block_test_la_LIBADD = \
libgnunetblock.la \
$(top_builddir)/src/util/libgnunetutil.la \
$(LTLIBINTL)
-libgnunet_plugin_block_test_la_DEPENDENCIES = \
- libgnunetblockgroup.la \
- libgnunetblock.la \
- $(top_builddir)/src/util/libgnunetutil.la
libgnunet_plugin_block_test_la_LDFLAGS = \
$(GN_PLUGIN_LDFLAGS)
@@ -51,8 +43,6 @@ libgnunetblock_la_SOURCES = \
block.c
libgnunetblock_la_LIBADD = \
$(top_builddir)/src/util/libgnunetutil.la
-libgnunetblock_la_DEPENDENCIES = \
- $(top_builddir)/src/util/libgnunetutil.la
libgnunetblock_la_LDFLAGS = \
$(GN_LIB_LDFLAGS) \
$(GN_LIBINTL) \
@@ -63,9 +53,6 @@ libgnunetblockgroup_la_SOURCES = \
libgnunetblockgroup_la_LIBADD = \
libgnunetblock.la \
$(top_builddir)/src/util/libgnunetutil.la
-libgnunetblockgroup_la_DEPENDENCIES = \
- libgnunetblock.la \
- $(top_builddir)/src/util/libgnunetutil.la
libgnunetblockgroup_la_LDFLAGS = \
$(GN_LIB_LDFLAGS) \
$(GN_LIBINTL) \
diff --git a/src/consensus/Makefile.am b/src/consensus/Makefile.am
index 24e685fb9..cf1d32e74 100644
--- a/src/consensus/Makefile.am
+++ b/src/consensus/Makefile.am
@@ -40,6 +40,7 @@ gnunet_consensus_profiler_SOURCES = \
gnunet_consensus_profiler_LDADD = \
$(top_builddir)/src/util/libgnunetutil.la \
libgnunetconsensus.la \
+ $(top_builddir)/src/testing/libgnunettesting.la \
$(top_builddir)/src/testbed/libgnunettestbed.la \
$(GN_LIBINTL)
diff --git a/src/conversation/conversation_api.c b/src/conversation/conversation_api.c
index 88fe8f11c..1984abdd6 100644
--- a/src/conversation/conversation_api.c
+++ b/src/conversation/conversation_api.c
@@ -645,6 +645,7 @@ GNUNET_CONVERSATION_phone_create (const struct GNUNET_CONFIGURATION_Handle *cfg,
GNUNET_CRYPTO_hash (line,
strlen (line),
&line_port);
+ GNUNET_free (line);
phone = GNUNET_new (struct GNUNET_CONVERSATION_Phone);
if (GNUNET_OK !=
GNUNET_CRYPTO_get_peer_identity (cfg,
diff --git a/src/curl/curl.c b/src/curl/curl.c
index b6aef4f61..71672c780 100644
--- a/src/curl/curl.c
+++ b/src/curl/curl.c
@@ -759,6 +759,15 @@ GNUNET_CURL_download_get_result_ (struct GNUNET_CURL_DownloadBuffer *db,
"Downloaded body: %.*s\n",
(int) db->buf_size,
(char *) db->buf);
+ if (CURLE_OK !=
+ curl_easy_getinfo (eh,
+ CURLINFO_RESPONSE_CODE,
+ response_code))
+ {
+ /* unexpected error... */
+ GNUNET_break (0);
+ *response_code = 0;
+ }
if ((CURLE_OK !=
curl_easy_getinfo (eh,
CURLINFO_CONTENT_TYPE,
@@ -768,15 +777,6 @@ GNUNET_CURL_download_get_result_ (struct GNUNET_CURL_DownloadBuffer *db,
{
/* No content type or explicitly not JSON, refuse to parse
(but keep response code) */
- if (CURLE_OK !=
- curl_easy_getinfo (eh,
- CURLINFO_RESPONSE_CODE,
- response_code))
- {
- /* unexpected error... */
- GNUNET_break (0);
- *response_code = 0;
- }
if (0 != db->buf_size)
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"Did NOT detect response `%.*s' as JSON\n",
@@ -786,6 +786,20 @@ GNUNET_CURL_download_get_result_ (struct GNUNET_CURL_DownloadBuffer *db,
}
if (MHD_HTTP_NO_CONTENT == *response_code)
return NULL;
+ if (0 == *response_code)
+ {
+ char *url;
+
+ if (CURLE_OK !=
+ curl_easy_getinfo (eh,
+ CURLINFO_EFFECTIVE_URL,
+ &url))
+ url = "<unknown URL>";
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failed to download response from `%s': \n",
+ url);
+ return NULL;
+ }
json = NULL;
if (0 == db->eno)
{
@@ -802,18 +816,6 @@ GNUNET_CURL_download_get_result_ (struct GNUNET_CURL_DownloadBuffer *db,
GNUNET_free (db->buf);
db->buf = NULL;
db->buf_size = 0;
- if (NULL != json)
- {
- if (CURLE_OK !=
- curl_easy_getinfo (eh,
- CURLINFO_RESPONSE_CODE,
- response_code))
- {
- /* unexpected error... */
- GNUNET_break (0);
- *response_code = 0;
- }
- }
return json;
}
@@ -825,8 +827,9 @@ GNUNET_CURL_download_get_result_ (struct GNUNET_CURL_DownloadBuffer *db,
* @param header header string; will be given to the context AS IS.
* @return #GNUNET_OK if no errors occurred, #GNUNET_SYSERR otherwise.
*/
-int
-GNUNET_CURL_append_header (struct GNUNET_CURL_Context *ctx, const char *header)
+enum GNUNET_GenericReturnValue
+GNUNET_CURL_append_header (struct GNUNET_CURL_Context *ctx,
+ const char *header)
{
ctx->common_headers = curl_slist_append (ctx->common_headers, header);
if (NULL == ctx->common_headers)
@@ -892,7 +895,7 @@ do_benchmark (CURLMsg *cmsg)
curl -w "foo%{size_request} -XPOST --data "ABC" $URL
the CURLINFO_REQUEST_SIZE should be the whole size of the request
including headers and body.
- *///
+ */
GNUNET_break (size_curl <= size_long);
urd = get_url_benchmark_data (url, (unsigned int) response_code);
diff --git a/src/datacache/plugin_datacache_postgres.c b/src/datacache/plugin_datacache_postgres.c
index 724324ca4..6613ae928 100644
--- a/src/datacache/plugin_datacache_postgres.c
+++ b/src/datacache/plugin_datacache_postgres.c
@@ -306,7 +306,7 @@ postgres_plugin_get (void *cls,
{
struct Plugin *plugin = cls;
uint32_t type32 = (uint32_t) type;
- struct GNUNET_TIME_Absolute now;
+ struct GNUNET_TIME_Absolute now = { 0 };
struct GNUNET_PQ_QueryParam paramk[] = {
GNUNET_PQ_query_param_auto_from_type (key),
GNUNET_PQ_query_param_absolute_time (&now),
@@ -424,7 +424,7 @@ postgres_plugin_get_random (void *cls,
{
struct Plugin *plugin = cls;
uint32_t off;
- struct GNUNET_TIME_Absolute now;
+ struct GNUNET_TIME_Absolute now = { 0 };
struct GNUNET_TIME_Absolute expiration_time;
size_t data_size;
void *data;
diff --git a/src/datacache/plugin_datacache_sqlite.c b/src/datacache/plugin_datacache_sqlite.c
index a7da6b068..66ff9e82c 100644
--- a/src/datacache/plugin_datacache_sqlite.c
+++ b/src/datacache/plugin_datacache_sqlite.c
@@ -468,7 +468,7 @@ sqlite_plugin_get_random (void *cls,
struct GNUNET_TIME_Absolute exp;
size_t size;
void *dat;
- uint32_t off;
+ uint32_t off = 0;
size_t psize;
uint32_t type;
struct GNUNET_PeerIdentity *path;
diff --git a/src/datastore/datastore_api.c b/src/datastore/datastore_api.c
index d658b9c85..a49bc8586 100644
--- a/src/datastore/datastore_api.c
+++ b/src/datastore/datastore_api.c
@@ -1400,7 +1400,7 @@ GNUNET_DATASTORE_get_key (struct GNUNET_DATASTORE_Handle *h,
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Asked to look for data of type %u under key `%s'\n",
(unsigned int) type,
- GNUNET_h2s (key));
+ (NULL != key) ? GNUNET_h2s (key) : "NULL");
if (NULL == key)
{
env = GNUNET_MQ_msg (gm,
@@ -1430,7 +1430,7 @@ GNUNET_DATASTORE_get_key (struct GNUNET_DATASTORE_Handle *h,
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Could not queue request for `%s'\n",
- GNUNET_h2s (key));
+ (NULL != key) ? GNUNET_h2s (key): "NULL");
return NULL;
}
#if INSANE_STATISTICS
diff --git a/src/datastore/plugin_datastore_mysql.c b/src/datastore/plugin_datastore_mysql.c
index 4f0e0838e..216a6faa4 100644
--- a/src/datastore/plugin_datastore_mysql.c
+++ b/src/datastore/plugin_datastore_mysql.c
@@ -994,7 +994,7 @@ mysql_plugin_get_expiration (void *cls,
void *proc_cls)
{
struct Plugin *plugin = cls;
- struct GNUNET_TIME_Absolute now;
+ struct GNUNET_TIME_Absolute now = { 0 };
struct GNUNET_MY_QueryParam params_select[] = {
GNUNET_MY_query_param_absolute_time (&now),
GNUNET_MY_query_param_end
diff --git a/src/datastore/plugin_datastore_postgres.c b/src/datastore/plugin_datastore_postgres.c
index 66929f91a..8fb0bf6ee 100644
--- a/src/datastore/plugin_datastore_postgres.c
+++ b/src/datastore/plugin_datastore_postgres.c
@@ -729,7 +729,7 @@ postgres_plugin_get_expiration (void *cls,
void *proc_cls)
{
struct Plugin *plugin = cls;
- struct GNUNET_TIME_Absolute now;
+ struct GNUNET_TIME_Absolute now = { 0 };
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_absolute_time (&now),
GNUNET_PQ_query_param_end
diff --git a/src/datastore/plugin_datastore_sqlite.c b/src/datastore/plugin_datastore_sqlite.c
index f58955b7b..3c2d7f2d4 100644
--- a/src/datastore/plugin_datastore_sqlite.c
+++ b/src/datastore/plugin_datastore_sqlite.c
@@ -1029,7 +1029,7 @@ sqlite_plugin_get_replication (void *cls,
{
struct Plugin *plugin = cls;
struct ReplCtx rc;
- uint64_t rvalue;
+ uint64_t rvalue = 0;
uint32_t repl;
struct GNUNET_SQ_QueryParam params_sel_repl[] =
{ GNUNET_SQ_query_param_uint64 (&rvalue),
@@ -1096,7 +1096,7 @@ sqlite_plugin_get_expiration (void *cls,
{
struct Plugin *plugin = cls;
sqlite3_stmt *stmt;
- struct GNUNET_TIME_Absolute now;
+ struct GNUNET_TIME_Absolute now = { 0 };
struct GNUNET_SQ_QueryParam params[] = { GNUNET_SQ_query_param_absolute_time (
&now),
GNUNET_SQ_query_param_end };
diff --git a/src/dht/Makefile.am b/src/dht/Makefile.am
index 2182d1c7f..919eca438 100644
--- a/src/dht/Makefile.am
+++ b/src/dht/Makefile.am
@@ -112,6 +112,7 @@ gnunet_dht_profiler_LDADD = \
libgnunetdht.la \
$(top_builddir)/src/core/libgnunetcore.la \
$(top_builddir)/src/util/libgnunetutil.la \
+ $(top_builddir)/src/testing/libgnunettesting.la \
$(top_builddir)/src/testbed/libgnunettestbed.la
gnunet_dht_profiler_LDFLAGS = \
$(GN_LIBINTL)
diff --git a/src/dht/gnunet-service-dht_neighbours.c b/src/dht/gnunet-service-dht_neighbours.c
index 2c30f0b68..ca255310c 100644
--- a/src/dht/gnunet-service-dht_neighbours.c
+++ b/src/dht/gnunet-service-dht_neighbours.c
@@ -894,7 +894,7 @@ get_distance (const struct GNUNET_HashCode *target,
unsigned int bucket)
{
uint64_t lsb = 0;
-
+
for (unsigned int i = bucket + 1;
(i < sizeof(struct GNUNET_HashCode) * 8) &&
(i < bucket + 1 + 64);
@@ -997,14 +997,15 @@ select_peer (const struct GNUNET_HashCode *key,
chosen = NULL;
for (bc = 0; bc <= closest_bucket; bc++)
{
- pos = k_buckets[bc].head;
count = 0;
- while ( (pos != NULL) &&
- (count < bucket_size) )
+ for (pos = k_buckets[bc].head;
+ (pos != NULL) &&
+ (count < bucket_size);
+ pos = pos->next)
{
unsigned int bucket;
uint64_t dist;
-
+
bucket = GNUNET_CRYPTO_hash_matching_bits (key,
&pos->phash);
dist = get_distance (key,
@@ -1037,7 +1038,6 @@ select_peer (const struct GNUNET_HashCode *key,
chosen = NULL;
}
count++;
- pos = pos->next;
}
}
if (NULL == chosen)
diff --git a/src/dhtu/plugin_dhtu_ip.c b/src/dhtu/plugin_dhtu_ip.c
index f80325cbc..8593a69ef 100644
--- a/src/dhtu/plugin_dhtu_ip.c
+++ b/src/dhtu/plugin_dhtu_ip.c
@@ -64,12 +64,12 @@ struct GNUNET_DHTU_Source
* Address in URL form ("ip+udp://$IP:$PORT")
*/
char *address;
-
+
/**
* Hash of the IP address.
*/
struct GNUNET_DHTU_Hash id;
-
+
/**
* My actual address.
*/
@@ -79,12 +79,12 @@ struct GNUNET_DHTU_Source
* Number of bytes in @a addr.
*/
socklen_t addrlen;
-
+
/**
* Last generation this address was observed.
*/
unsigned int scan_generation;
-
+
};
@@ -104,12 +104,12 @@ struct GNUNET_DHTU_Target
* Kept in a DLL.
*/
struct GNUNET_DHTU_Target *prev;
-
+
/**
* Application context for this target.
*/
void *app_ctx;
-
+
/**
* Hash of the IP address.
*/
@@ -124,7 +124,7 @@ struct GNUNET_DHTU_Target
* Tail of preferences expressed for this target.
*/
struct GNUNET_DHTU_PreferenceHandle *ph_tail;
-
+
/**
* Target IP address.
*/
@@ -134,7 +134,7 @@ struct GNUNET_DHTU_Target
* Number of bytes in @a addr.
*/
socklen_t addrlen;
-
+
/**
* Preference counter, length of the @a ph_head DLL.
*/
@@ -170,7 +170,7 @@ struct GNUNET_DHTU_PreferenceHandle
*/
struct Plugin
{
- /**
+ /**
* Callbacks into the DHT.
*/
struct GNUNET_DHTU_PluginEnvironment *env;
@@ -200,7 +200,7 @@ struct Plugin
* Map from hashes of sockaddrs to targets.
*/
struct GNUNET_CONTAINER_MultiHashMap *dsts;
-
+
/**
* Task that scans for IP address changes.
*/
@@ -212,7 +212,7 @@ struct Plugin
struct GNUNET_SCHEDULER_Task *read_task;
/**
- * Port we bind to.
+ * Port we bind to.
*/
char *port;
@@ -290,7 +290,7 @@ create_target (struct Plugin *plugin,
GNUNET_CONTAINER_multihashmap_size (plugin->dsts))
{
struct GNUNET_HashCode key;
-
+
dst = NULL;
for (struct GNUNET_DHTU_Target *pos = plugin->dst_head;
NULL != pos;
@@ -316,7 +316,7 @@ create_target (struct Plugin *plugin,
GNUNET_assert (NULL == dst->ph_head);
GNUNET_free (dst);
}
- pk.size = htons (sizeof (pk));
+ pk.size = htons (sizeof (pk));
dst = GNUNET_new (struct GNUNET_DHTU_Target);
dst->addrlen = addrlen;
memcpy (&dst->addr,
@@ -391,10 +391,10 @@ find_target (struct Plugin *plugin,
addrlen);
GNUNET_assert (GNUNET_YES ==
GNUNET_CONTAINER_multihashmap_put (
- plugin->dsts,
- &key,
- dst,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
+ plugin->dsts,
+ &key,
+ dst,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
}
else
{
@@ -429,7 +429,7 @@ ip_try_connect (void *cls,
.ai_flags = AI_NUMERICHOST | AI_NUMERICSERV
};
struct addrinfo *result = NULL;
-
+
if (0 !=
strncmp (address,
"ip+",
@@ -481,7 +481,7 @@ ip_try_connect (void *cls,
* Request underlay to keep the connection to @a target alive if possible.
* Hold may be called multiple times to express a strong preference to
* keep a connection, say because a @a target is in multiple tables.
- *
+ *
* @param cls closure
* @param target connection to keep alive
*/
@@ -503,7 +503,7 @@ ip_hold (void *cls,
/**
* Do no long request underlay to keep the connection alive.
- *
+ *
* @param cls closure
* @param target connection to keep alive
*/
@@ -511,7 +511,7 @@ static void
ip_drop (struct GNUNET_DHTU_PreferenceHandle *ph)
{
struct GNUNET_DHTU_Target *target = ph->target;
-
+
GNUNET_CONTAINER_DLL_remove (target->ph_head,
target->ph_tail,
ph);
@@ -532,7 +532,7 @@ ip_drop (struct GNUNET_DHTU_PreferenceHandle *ph)
* @param msg_size number of bytes in @a msg
* @param finished_cb function called once transmission is done
* (not called if @a target disconnects, then only the
- * disconnect_cb is called).
+ * disconnect_cb is called).
* @param finished_cb_cls closure for @a finished_cb
*/
static void
@@ -568,7 +568,7 @@ create_source (struct Plugin *plugin,
socklen_t addrlen)
{
struct GNUNET_DHTU_Source *src;
-
+
src = GNUNET_new (struct GNUNET_DHTU_Source);
src->addrlen = addrlen;
memcpy (&src->addr,
@@ -731,7 +731,7 @@ find_source (struct Plugin *plugin,
(0 == memcmp (addr,
&src->addr,
addrlen)) )
- return src;
+ return src;
}
return create_source (plugin,
@@ -788,7 +788,7 @@ read_cb (void *cls)
cmsg->cmsg_len)
{
struct in_pktinfo pi;
-
+
memcpy (&pi,
CMSG_DATA (cmsg),
sizeof (pi));
@@ -797,7 +797,7 @@ read_cb (void *cls)
.sin_family = AF_INET,
.sin_addr = pi.ipi_addr
};
-
+
src = find_source (plugin,
&sa,
sizeof (sa));
@@ -814,7 +814,7 @@ read_cb (void *cls)
cmsg->cmsg_len)
{
struct in6_pktinfo pi;
-
+
memcpy (&pi,
CMSG_DATA (cmsg),
sizeof (pi));
@@ -824,7 +824,7 @@ read_cb (void *cls)
.sin6_addr = pi.ipi6_addr,
.sin6_scope_id = pi.ipi6_ifindex
};
-
+
src = find_source (plugin,
&sa,
sizeof (sa));
@@ -833,7 +833,7 @@ read_cb (void *cls)
}
else
GNUNET_break (0);
- }
+ }
}
dst = find_target (plugin,
&sa,
@@ -932,7 +932,8 @@ libgnunet_plugin_dhtu_ip_init (void *cls)
GNUNET_free (plugin);
return NULL;
}
- switch (af) {
+ switch (af)
+ {
case AF_INET:
{
int on = 1;
@@ -956,7 +957,7 @@ libgnunet_plugin_dhtu_ip_init (void *cls)
if (0 !=
bind (sock,
- &sa,
+ (const struct sockaddr *) &sa,
sizeof (sa)))
{
GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
@@ -989,10 +990,10 @@ libgnunet_plugin_dhtu_ip_init (void *cls)
.sin6_family = AF_INET6,
.sin6_port = htons ((uint16_t) nport)
};
-
+
if (0 !=
bind (sock,
- &sa,
+ (const struct sockaddr *) &sa,
sizeof (sa)))
{
GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
diff --git a/src/dns/Makefile.am b/src/dns/Makefile.am
index 45107304b..f8672d55e 100644
--- a/src/dns/Makefile.am
+++ b/src/dns/Makefile.am
@@ -83,10 +83,6 @@ libgnunet_plugin_block_dns_la_LIBADD = \
$(top_builddir)/src/block/libgnunetblockgroup.la \
$(top_builddir)/src/block/libgnunetblock.la \
$(top_builddir)/src/util/libgnunetutil.la
-libgnunet_plugin_block_dns_la_DEPENDENCIES = \
- $(top_builddir)/src/block/libgnunetblockgroup.la \
- $(top_builddir)/src/block/libgnunetblock.la \
- $(top_builddir)/src/util/libgnunetutil.la
libgnunet_plugin_block_dns_la_LDFLAGS = \
$(GN_LIBINTL) \
$(top_builddir)/src/block/$(GN_PLUGIN_LDFLAGS)
@@ -99,5 +95,3 @@ endif
EXTRA_DIST = \
$(check_SCRIPTS)
-
-
diff --git a/src/fs/Makefile.am b/src/fs/Makefile.am
index 25590c6f7..5b6ba2376 100644
--- a/src/fs/Makefile.am
+++ b/src/fs/Makefile.am
@@ -49,10 +49,6 @@ libgnunetfs_la_LIBADD = \
$(top_builddir)/src/statistics/libgnunetstatistics.la \
$(top_builddir)/src/util/libgnunetutil.la \
$(GN_LIBINTL) $(XLIB) $(LIBGCRYPT_LIBS) -lunistring
-libgnunetfs_la_DEPENDENCIES = \
- $(top_builddir)/src/datastore/libgnunetdatastore.la \
- $(top_builddir)/src/statistics/libgnunetstatistics.la \
- $(top_builddir)/src/util/libgnunetutil.la
if HAVE_LIBEXTRACTOR
libgnunetfs_la_LIBADD += \
@@ -105,6 +101,7 @@ endif
gnunet_fs_profiler_SOURCES = \
gnunet-fs-profiler.c
gnunet_fs_profiler_LDADD = \
+ $(top_builddir)/src/testing/libgnunettesting.la \
$(top_builddir)/src/testbed/libgnunettestbed.la \
$(top_builddir)/src/util/libgnunetutil.la \
$(GN_LIBINTL)
diff --git a/src/gns/gnunet-gns-proxy.c b/src/gns/gnunet-gns-proxy.c
index 5e3f9d6df..ec9fb12ae 100644
--- a/src/gns/gnunet-gns-proxy.c
+++ b/src/gns/gnunet-gns-proxy.c
@@ -1264,7 +1264,7 @@ curl_check_hdr (void *buffer,
}
GNUNET_free (leho_host);
}
- if (0 == strcasecmp (MHD_HTTP_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN,
+ else if (0 == strcasecmp (MHD_HTTP_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN,
hdr_type))
{
char *leho_host;
diff --git a/src/gnsrecord/Makefile.am b/src/gnsrecord/Makefile.am
index 27f5446a1..42ac4ede4 100644
--- a/src/gnsrecord/Makefile.am
+++ b/src/gnsrecord/Makefile.am
@@ -53,8 +53,6 @@ libgnunetgnsrecord_la_LIBADD = \
$(LIBGCRYPT_LIBS) \
-lsodium \
$(GN_LIBINTL)
-libgnunetgnsrecord_la_DEPENDENCIES = \
- $(top_builddir)/src/identity/libgnunetidentity.la
libgnunetgnsrecord_la_LDFLAGS = \
$(GN_LIB_LDFLAGS) \
-version-info 0:0:0
diff --git a/src/hostlist/hostlist.conf b/src/hostlist/hostlist.conf
index 0a31a23ad..d994ce9fb 100644
--- a/src/hostlist/hostlist.conf
+++ b/src/hostlist/hostlist.conf
@@ -20,7 +20,7 @@ HOSTLISTFILE = $GNUNET_CONFIG_HOME/hostlist/learned.txt
OPTIONS = -b
# Default list of hostlist servers for bootstrapping
-SERVERS = http://v14.gnunet.org/hostlist https://gnunet.io/hostlist
+SERVERS = http://v15.gnunet.org/hostlist https://gnunet.io/hostlist
# http://silent.0xdeadc0de.eu:8080/
# bind hostlist http server to a specific IPv4
diff --git a/src/identity/identity_api.c b/src/identity/identity_api.c
index 3bbe0b957..22371f91a 100644
--- a/src/identity/identity_api.c
+++ b/src/identity/identity_api.c
@@ -1236,14 +1236,12 @@ GNUNET_IDENTITY_public_key_from_string (const char *str,
struct GNUNET_IDENTITY_PublicKey *key)
{
enum GNUNET_GenericReturnValue ret;
- enum GNUNET_IDENTITY_KeyType ktype;
ret = GNUNET_STRINGS_string_to_data (str,
strlen (str),
key,
sizeof (*key));
if (GNUNET_OK != ret)
return GNUNET_SYSERR;
- ktype = ntohl (key->type);
return GNUNET_OK;
}
@@ -1254,14 +1252,12 @@ GNUNET_IDENTITY_private_key_from_string (const char *str,
struct GNUNET_IDENTITY_PrivateKey *key)
{
enum GNUNET_GenericReturnValue ret;
- enum GNUNET_IDENTITY_KeyType ktype;
ret = GNUNET_STRINGS_string_to_data (str,
strlen (str),
key,
sizeof (*key));
if (GNUNET_OK != ret)
return GNUNET_SYSERR;
- ktype = ntohl (key->type);
return GNUNET_OK;
}
diff --git a/src/identity/plugin_rest_identity.c b/src/identity/plugin_rest_identity.c
index dba1d478d..d7cd0e826 100644
--- a/src/identity/plugin_rest_identity.c
+++ b/src/identity/plugin_rest_identity.c
@@ -322,7 +322,9 @@ do_error (void *cls)
handle->response_code = MHD_HTTP_OK;
response = json_dumps (json_error, 0);
resp = GNUNET_REST_create_response (response);
- MHD_add_response_header (resp, "Content-Type", "application/json");
+ GNUNET_assert (MHD_NO != MHD_add_response_header (resp,
+ "Content-Type",
+ "application/json"));
handle->proc (handle->proc_cls, resp, handle->response_code);
json_decref (json_error);
GNUNET_free (response);
@@ -412,7 +414,9 @@ ego_get_for_subsystem (void *cls,
result_str = json_dumps (json_root, 0);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str);
resp = GNUNET_REST_create_response (result_str);
- MHD_add_response_header (resp, "Content-Type", "application/json");
+ GNUNET_assert (MHD_NO != MHD_add_response_header (resp,
+ "Content-Type",
+ "application/json"));
json_decref (json_root);
handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
GNUNET_free (result_str);
@@ -514,7 +518,9 @@ ego_get_all (struct GNUNET_REST_RequestHandle *con_handle,
result_str = json_dumps (json_root, 0);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str);
resp = GNUNET_REST_create_response (result_str);
- MHD_add_response_header (resp, "Content-Type", "application/json");
+ GNUNET_assert (MHD_NO != MHD_add_response_header (resp,
+ "Content-Type",
+ "application/json"));
json_decref (json_root);
handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
GNUNET_free (result_str);
@@ -561,7 +567,9 @@ ego_get_response (struct RequestHandle *handle, struct EgoEntry *ego_entry)
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str);
resp = GNUNET_REST_create_response (result_str);
handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
- MHD_add_response_header (resp, "Content-Type", "application/json");
+ GNUNET_assert (MHD_NO != MHD_add_response_header (resp,
+ "Content-Type",
+ "application/json"));
json_decref (json_ego);
GNUNET_free (result_str);
GNUNET_SCHEDULER_add_now (&cleanup_handle, handle);
@@ -1195,7 +1203,9 @@ options_cont (struct GNUNET_REST_RequestHandle *con_handle,
// For now, independent of path return all options
resp = GNUNET_REST_create_response (NULL);
- MHD_add_response_header (resp, "Access-Control-Allow-Methods", allow_methods);
+ GNUNET_assert (MHD_NO != MHD_add_response_header (resp,
+ "Access-Control-Allow-Methods",
+ allow_methods));
handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
GNUNET_SCHEDULER_add_now (&cleanup_handle, handle);
return;
@@ -1216,6 +1226,12 @@ list_ego (void *cls,
state = ID_REST_STATE_POST_INIT;
return;
}
+ if (NULL == ego)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Called with NULL ego\n");
+ return;
+ }
if (ID_REST_STATE_INIT == state)
{
ego_entry = GNUNET_new (struct EgoEntry);
diff --git a/src/include/Makefile.am b/src/include/Makefile.am
index d15186342..9c22b5977 100644
--- a/src/include/Makefile.am
+++ b/src/include/Makefile.am
@@ -115,8 +115,8 @@ gnunetinclude_HEADERS = \
gnunet_strings_lib.h \
gnunet_testbed_service.h \
gnunet_testbed_logger_service.h \
- gnunet_testbed_ng_service.h \
gnunet_testing_lib.h \
+ gnunet_testing_plugin.h \
gnunet_testing_ng_lib.h \
gnunet_time_lib.h \
gnunet_transport_service.h \
diff --git a/src/include/gnunet_common.h b/src/include/gnunet_common.h
index df1ccff26..3ee2a070a 100644
--- a/src/include/gnunet_common.h
+++ b/src/include/gnunet_common.h
@@ -1,6 +1,6 @@
/*
This file is part of GNUnet.
- Copyright (C) 2006-2020 GNUnet e.V.
+ Copyright (C) 2006-2021 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
@@ -135,7 +135,7 @@ enum GNUNET_GenericReturnValue
* tree where gnunet_config.h is unavailable
*/
#ifndef GNUNET_EXTRA_LOGGING
-#define GNUNET_EXTRA_LOGGING 0
+#define GNUNET_EXTRA_LOGGING 1
#endif
/**
@@ -875,19 +875,37 @@ GNUNET_error_type_to_string (enum GNUNET_ErrorType kind);
* @ingroup logging
* Use this for fatal errors that cannot be handled
*/
+#if __GNUC__ >= 6 || __clang_major__ >= 6
#define GNUNET_assert(cond) \
do \
{ \
+ _Pragma("GCC diagnostic push") \
+ _Pragma("GCC diagnostic ignored \"-Wtautological-compare\"") \
if (! (cond)) \
{ \
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \
- _ ("Assertion failed at %s:%d. Aborting.\n"), \
+ dgettext ("gnunet", "Assertion failed at %s:%d. Aborting.\n"), \
__FILE__, \
__LINE__); \
GNUNET_abort_ (); \
} \
+ _Pragma("GCC diagnostic pop") \
} while (0)
-
+#else
+/* older GCC/clangs do not support -Wtautological-compare */
+#define GNUNET_assert(cond) \
+ do \
+ { \
+ if (! (cond)) \
+ { \
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \
+ dgettext ("gnunet", "Assertion failed at %s:%d. Aborting.\n"), \
+ __FILE__, \
+ __LINE__); \
+ GNUNET_abort_ (); \
+ } \
+ } while (0)
+#endif
/**
* @ingroup logging
@@ -899,7 +917,7 @@ GNUNET_error_type_to_string (enum GNUNET_ErrorType kind);
if (! (cond)) \
{ \
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \
- _ ("Assertion failed at %s:%d. Aborting.\n"), \
+ dgettext ("gnunet", "Assertion failed at %s:%d. Aborting.\n"), \
f, \
l); \
GNUNET_abort_ (); \
@@ -921,7 +939,7 @@ GNUNET_error_type_to_string (enum GNUNET_ErrorType kind);
{ \
GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, \
comp, \
- _ ("Assertion failed at %s:%d. Aborting.\n"), \
+ dgettext ("gnunet", "Assertion failed at %s:%d. Aborting.\n"), \
__FILE__, \
__LINE__); \
GNUNET_abort_ (); \
@@ -962,7 +980,7 @@ GNUNET_error_type_to_string (enum GNUNET_ErrorType kind);
if (! (cond)) \
{ \
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \
- _ ("Assertion failed at %s:%d.\n"), \
+ dgettext ("gnunet", "Assertion failed at %s:%d.\n"), \
__FILE__, \
__LINE__); \
} \
@@ -984,7 +1002,7 @@ GNUNET_error_type_to_string (enum GNUNET_ErrorType kind);
if (! (cond)) \
{ \
GNUNET_log (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, \
- _ ("External protocol violation detected at %s:%d.\n"), \
+ dgettext ("gnunet", "External protocol violation detected at %s:%d.\n"), \
__FILE__, \
__LINE__); \
} \
@@ -1001,7 +1019,7 @@ GNUNET_error_type_to_string (enum GNUNET_ErrorType kind);
do \
{ \
GNUNET_log (level, \
- _ ("`%s' failed at %s:%d with error: %s\n"), \
+ dgettext ("gnunet", "`%s' failed at %s:%d with error: %s\n"), \
cmd, \
__FILE__, \
__LINE__, \
@@ -1020,7 +1038,7 @@ GNUNET_error_type_to_string (enum GNUNET_ErrorType kind);
{ \
GNUNET_log_from (level, \
component, \
- _ ("`%s' failed at %s:%d with error: %s\n"), \
+ dgettext ("gnunet", "`%s' failed at %s:%d with error: %s\n"), \
cmd, \
__FILE__, \
__LINE__, \
@@ -1038,7 +1056,7 @@ GNUNET_error_type_to_string (enum GNUNET_ErrorType kind);
do \
{ \
GNUNET_log (level, \
- _ ("`%s' failed on file `%s' at %s:%d with error: %s\n"), \
+ dgettext ("gnunet", "`%s' failed on file `%s' at %s:%d with error: %s\n"), \
cmd, \
filename, \
__FILE__, \
@@ -1058,7 +1076,7 @@ GNUNET_error_type_to_string (enum GNUNET_ErrorType kind);
{ \
GNUNET_log_from (level, \
component, \
- _ ("`%s' failed on file `%s' at %s:%d with error: %s\n"), \
+ dgettext ("gnunet", "`%s' failed on file `%s' at %s:%d with error: %s\n"), \
cmd, \
filename, \
__FILE__, \
diff --git a/src/include/gnunet_configuration_lib.h b/src/include/gnunet_configuration_lib.h
index 21a5ab810..570546b68 100644
--- a/src/include/gnunet_configuration_lib.h
+++ b/src/include/gnunet_configuration_lib.h
@@ -113,6 +113,18 @@ GNUNET_CONFIGURATION_default (void);
/**
+ * Return the filename of the default configuration filename
+ * that is used when no explicit configuration entry point
+ * has been specified.
+ *
+ * @returns NULL if no default configuration file can be located,
+ * a newly allocated string otherwise
+ */
+char *
+GNUNET_CONFIGURATION_default_filename (void);
+
+
+/**
* Parse a configuration file, add all of the options in the
* file to the configuration environment.
*
@@ -139,21 +151,33 @@ GNUNET_CONFIGURATION_serialize (const struct GNUNET_CONFIGURATION_Handle *cfg,
/**
+ * Serializes the given configuration with diagnostics information.
+ * Diagnostics information will only be available if diagnostics
+ * have been enabled before parsing.
+ *
+ * @param cfg configuration to serialize
+ * @return the memory block where the serialized configuration is
+ * present. This memory should be freed by the caller
+ */
+char *
+GNUNET_CONFIGURATION_serialize_diagnostics (const struct
+ GNUNET_CONFIGURATION_Handle *cfg);
+
+/**
* De-serializes configuration
*
* @param cfg configuration to update
* @param mem the memory block of serialized configuration
* @param size the size of the memory block
- * @param allow_inline set to the base directory if we recursively load configuration
- * from inlined configurations; NULL if not and raise warnings
- * when we come across them
+ * @param source_filename source filename, will be used
+ * to resolve relative @INLINE@ statements
* @return #GNUNET_OK on success, #GNUNET_SYSERR on error
*/
enum GNUNET_GenericReturnValue
GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg,
const char *mem,
size_t size,
- const char *basedir);
+ const char *source_filename);
/**
@@ -235,6 +259,16 @@ GNUNET_CONFIGURATION_parse_and_run (const char *filename,
GNUNET_CONFIGURATION_Callback cb,
void *cb_cls);
+/**
+ * Enable extra diagnostics. Will produce more log output
+ * and allocate more memory.
+ *
+ * @param cfg configuration handle
+ */
+void
+GNUNET_CONFIGURATION_enable_diagnostics (struct
+ GNUNET_CONFIGURATION_Handle *cfg);
+
/**
* Function to iterate over options.
@@ -598,6 +632,157 @@ GNUNET_CONFIGURATION_append_value_filename (struct
const char *option,
const char *value);
+
+/**
+ * Closure for #GNUNET_CONFIGURATION_config_tool_run()
+ * with settings for what should be done with the
+ * configuration.
+ */
+struct GNUNET_CONFIGURATION_ConfigSettings
+{
+
+ /**
+ * Must be set to the API version, i.e.
+ * #GNUNET_UTIL_VERSION. Used to detect
+ * which version of the struct the client
+ * is using.
+ */
+ unsigned int api_version;
+
+ /**
+ * Name of the section
+ */
+ char *section;
+
+ /**
+ * Name of the option
+ */
+ char *option;
+
+ /**
+ * Value to set
+ */
+ char *value;
+
+ /**
+ * Treat option as a filename.
+ */
+ int is_filename;
+
+ /**
+ * Whether to show the sections.
+ */
+ int list_sections;
+
+ /**
+ * Should we write out the configuration file, even if no value was changed?
+ */
+ int rewrite;
+
+ /**
+ * Should we give extra diagnostics?
+ */
+ int diagnostics;
+
+ /**
+ * Should the generated configuration file contain the whole configuration?
+ */
+ int full;
+
+
+ /**
+ * Return value from the operation, to be returned
+ * from 'main'.
+ */
+ int global_ret;
+
+};
+
+
+/**
+ * Macro that expands to a set of GNUNET-getopt directives
+ * to initialize a `struct GNUNET_CONFIGURATION_ConfigSettings`
+ * from the command line.
+ *
+ * @param cs configuration settings to initialize
+ */
+#define GNUNET_CONFIGURATION_CONFIG_OPTIONS(cs) \
+ GNUNET_GETOPT_option_flag ( \
+ 'F', \
+ "full", \
+ gettext_noop ( \
+ "write the full configuration file, including default values"), \
+ &(cs)->full), \
+ GNUNET_GETOPT_option_flag ( \
+ 'f', \
+ "filename", \
+ gettext_noop ("interpret option value as a filename (with $-expansion)"), \
+ &(cs)->is_filename), \
+ GNUNET_GETOPT_option_string ('o', \
+ "option", \
+ "OPTION", \
+ gettext_noop ("name of the option to access"), \
+ &(cs)->option), \
+ GNUNET_GETOPT_option_flag ( \
+ 'r', \
+ "rewrite", \
+ gettext_noop ( \
+ "rewrite the configuration file, even if nothing changed"), \
+ &(cs)->rewrite), \
+ GNUNET_GETOPT_option_flag ( \
+ 'd', \
+ "diagnostics", \
+ gettext_noop ( \
+ "output extra diagnostics"), \
+ &(cs)->diagnostics), \
+ GNUNET_GETOPT_option_flag ('S', \
+ "list-sections", \
+ gettext_noop ( \
+ "print available configuration sections"), \
+ &(cs)->list_sections), \
+ GNUNET_GETOPT_option_string ('s', \
+ "section", \
+ "SECTION", \
+ gettext_noop ( \
+ "name of the section to access"), \
+ &(cs)->section), \
+ GNUNET_GETOPT_option_string ('V', \
+ "value", \
+ "VALUE", \
+ gettext_noop ("value to set"), \
+ &(cs)->value)
+
+
+/**
+ * Free resources associated with @a cs.
+ *
+ * @param[in] cs settings to free (actual memory
+ * of @a cs itself is not released)
+ */
+void
+GNUNET_CONFIGURATION_config_settings_free (
+ struct GNUNET_CONFIGURATION_ConfigSettings *cs);
+
+
+/**
+ * Main task to run to perform operations typical for
+ * gnunet-config as per the configuration settings
+ * given in @a cls.
+ *
+ * @param cls closure with the `struct GNUNET_CONFIGURATION_ConfigSettings`
+ * @param args remaining command-line arguments
+ * @param cfgfile name of the configuration file used (for saving,
+ * can be NULL!)
+ * @param cfg configuration
+ */
+void
+GNUNET_CONFIGURATION_config_tool_run (
+ void *cls,
+ char *const *args,
+ const char *cfgfile,
+ const struct GNUNET_CONFIGURATION_Handle *cfg);
+
+
#if 0 /* keep Emacsens' auto-indent happy */
{
#endif
diff --git a/src/include/gnunet_container_lib.h b/src/include/gnunet_container_lib.h
index c8930746d..3eb80595c 100644
--- a/src/include/gnunet_container_lib.h
+++ b/src/include/gnunet_container_lib.h
@@ -2608,7 +2608,8 @@ GNUNET_CONTAINER_heap_node_get_cost (
* @return #GNUNET_YES if we should continue to iterate,
* #GNUNET_NO if not.
*/
-typedef int (*GNUNET_CONTAINER_HeapIterator) (
+typedef int
+(*GNUNET_CONTAINER_HeapIterator) (
void *cls,
struct GNUNET_CONTAINER_HeapNode *node,
void *element,
diff --git a/src/include/gnunet_curl_lib.h b/src/include/gnunet_curl_lib.h
index f51e4b503..38acecc48 100644
--- a/src/include/gnunet_curl_lib.h
+++ b/src/include/gnunet_curl_lib.h
@@ -150,7 +150,7 @@ GNUNET_CURL_get_select_info (struct GNUNET_CURL_Context *ctx,
* @param header header string; will be given to the context AS IS.
* @return #GNUNET_OK if no errors occurred, #GNUNET_SYSERR otherwise.
*/
-int
+enum GNUNET_GenericReturnValue
GNUNET_CURL_append_header (struct GNUNET_CURL_Context *ctx,
const char *header);
diff --git a/src/include/gnunet_db_lib.h b/src/include/gnunet_db_lib.h
index 85ad13e31..e88e836f6 100644
--- a/src/include/gnunet_db_lib.h
+++ b/src/include/gnunet_db_lib.h
@@ -25,6 +25,7 @@
#ifndef GNUNET_DB_LIB_H
#define GNUNET_DB_LIB_H
+#include "gnunet_common.h"
/**
* Status code returned from functions running database commands.
@@ -61,4 +62,47 @@ enum GNUNET_DB_QueryStatus
that returned more than one result. */
};
+
+/**
+ * Handle for an active LISTENer to a database.
+ */
+struct GNUNET_DB_EventHandler;
+
+/**
+ * Function called on events received from Postgres.
+ *
+ * @param cls closure
+ * @param extra additional event data provided
+ * @param extra_size number of bytes in @a extra
+ */
+typedef void
+(*GNUNET_DB_EventCallback)(void *cls,
+ const void *extra,
+ size_t extra_size);
+
+GNUNET_NETWORK_STRUCT_BEGIN
+
+
+/**
+ * Header of a structure that describes an
+ * event channel we may subscribe to or notify on.
+ */
+struct GNUNET_DB_EventHeaderP
+{
+ /**
+ * The length of the struct (in bytes, including the length field itself),
+ * in big-endian format.
+ */
+ uint16_t size GNUNET_PACKED;
+
+ /**
+ * The type of the message (GNUNET_DB_EVENT_TYPE_XXXX), in big-endian format.
+ */
+ uint16_t type GNUNET_PACKED;
+
+};
+
+GNUNET_NETWORK_STRUCT_END
+
+
#endif
diff --git a/src/include/gnunet_disk_lib.h b/src/include/gnunet_disk_lib.h
index 3805039fc..7dfd9ccf1 100644
--- a/src/include/gnunet_disk_lib.h
+++ b/src/include/gnunet_disk_lib.h
@@ -266,6 +266,16 @@ GNUNET_DISK_handle_invalid (const struct GNUNET_DISK_FileHandle *h);
enum GNUNET_GenericReturnValue
GNUNET_DISK_file_test (const char *fil);
+/**
+ * Check that fil corresponds to a filename and the file has read permissions.
+ *
+ * @param fil filename to check
+ * @return #GNUNET_YES if yes, #GNUNET_NO if file doesn't exist or
+ * has no read permissions, #GNUNET_SYSERR if something else
+ * (will print an error message in that case, too).
+ */
+enum GNUNET_GenericReturnValue
+GNUNET_DISK_file_test_read (const char *fil);
/**
* Move a file out of the way (create a backup) by renaming it to "orig.NUM~"
@@ -654,6 +664,22 @@ GNUNET_DISK_directory_scan (const char *dir_name,
GNUNET_FileNameCallback callback,
void *callback_cls);
+/**
+ * Find all files matching a glob pattern.
+ *
+ * Currently, the glob_pattern only supports asterisks in the last
+ * path component.
+ *
+ * @param glob_patterb the glob pattern to search for
+ * @param callback the method to call for each file
+ * @param callback_cls closure for @a callback
+ * @return the number of files found, -1 on error
+ */
+int
+GNUNET_DISK_glob (const char *glob_pattern,
+ GNUNET_FileNameCallback callback,
+ void *callback_cls);
+
/**
* Create the directory structure for storing
diff --git a/src/include/gnunet_json_lib.h b/src/include/gnunet_json_lib.h
index 3dc79105e..92f696e08 100644
--- a/src/include/gnunet_json_lib.h
+++ b/src/include/gnunet_json_lib.h
@@ -521,6 +521,310 @@ GNUNET_JSON_getopt (char shortName,
const char *description,
json_t **json);
+
+/* ****************** JSON PACK helper ******************* */
+
+
+/**
+ * Element in the array to give to the packer.
+ */
+struct GNUNET_JSON_PackSpec;
+
+
+/**
+ * Function called to pack an element into the JSON
+ * object as part of #GNUNET_JSON_pack_().
+ *
+ * @param se pack specification to execute
+ * @return json object to pack, NULL to pack nothing
+ */
+typedef json_t *
+(*GNUNET_JSON_PackCallback)(const struct GNUNET_JSON_PackSpec *se);
+
+
+/**
+ * Element in the array to give to the packer.
+ */
+struct GNUNET_JSON_PackSpec
+{
+ /**
+ * Name of the field to pack.
+ */
+ const char *field_name;
+
+ /**
+ * Object to pack.
+ */
+ json_t *object;
+
+ /**
+ * True if a NULL (or 0) argument is allowed. In this
+ * case, if the argument is NULL the @e packer should
+ * return NULL and the field should be skipped (omitted from
+ * the generated object) and not be serialized at all.
+ */
+ bool allow_null;
+};
+
+
+/**
+ * Pack a JSON object from a @a spec. Aborts if
+ * packing fails.
+ *
+ * @param spec specification object
+ * @return JSON object
+ */
+json_t *
+GNUNET_JSON_pack_ (struct GNUNET_JSON_PackSpec spec[]);
+
+
+/**
+ * Pack a JSON object from a @a spec. Aborts if
+ * packing fails.
+ *
+ * @param ... list of specification objects
+ * @return JSON object
+ */
+#define GNUNET_JSON_PACK(...) \
+ GNUNET_JSON_pack_ ((struct GNUNET_JSON_PackSpec[]) {__VA_ARGS__, \
+ GNUNET_JSON_pack_end_ ()})
+
+
+/**
+ * Do not use directly. Use #GNUNET_JSON_PACK.
+ *
+ * @return array terminator
+ */
+struct GNUNET_JSON_PackSpec
+GNUNET_JSON_pack_end_ (void);
+
+
+/**
+ * Modify packer instruction to allow NULL as a value.
+ *
+ * @param in json pack specification to modify
+ * @return json pack specification
+ */
+struct GNUNET_JSON_PackSpec
+GNUNET_JSON_pack_allow_null (struct GNUNET_JSON_PackSpec in);
+
+
+/**
+ * Generate packer instruction for a JSON field of type
+ * bool.
+ *
+ * @param name name of the field to add to the object
+ * @param b boolean value
+ * @return json pack specification
+ */
+struct GNUNET_JSON_PackSpec
+GNUNET_JSON_pack_bool (const char *name,
+ bool b);
+
+
+/**
+ * Generate packer instruction for a JSON field of type
+ * string.
+ *
+ * @param name name of the field to add to the object
+ * @param s string value
+ * @return json pack specification
+ */
+struct GNUNET_JSON_PackSpec
+GNUNET_JSON_pack_string (const char *name,
+ const char *s);
+
+
+/**
+ * Generate packer instruction for a JSON field of type
+ * unsigned integer. Note that the maximum allowed
+ * value is still limited by JSON and not UINT64_MAX.
+ *
+ * @param name name of the field to add to the object
+ * @param num numeric value
+ * @return json pack specification
+ */
+struct GNUNET_JSON_PackSpec
+GNUNET_JSON_pack_uint64 (const char *name,
+ uint64_t num);
+
+
+/**
+ * Generate packer instruction for a JSON field of type
+ * signed integer.
+ *
+ * @param name name of the field to add to the object
+ * @param num numeric value
+ * @return json pack specification
+ */
+struct GNUNET_JSON_PackSpec
+GNUNET_JSON_pack_int64 (const char *name,
+ int64_t num);
+
+
+/**
+ * Generate packer instruction for a JSON field of type
+ * JSON object where the reference is taken over by
+ * the packer.
+ *
+ * @param name name of the field to add to the object
+ * @param o object to steal
+ * @return json pack specification
+ */
+struct GNUNET_JSON_PackSpec
+GNUNET_JSON_pack_object_steal (const char *name,
+ json_t *o);
+
+
+/**
+ * Generate packer instruction for a JSON field of type JSON object where the
+ * reference counter is incremented by the packer. Note that a deep copy is
+ * not performed.
+ *
+ * @param name name of the field to add to the object
+ * @param o object to increment reference counter of
+ * @return json pack specification
+ */
+struct GNUNET_JSON_PackSpec
+GNUNET_JSON_pack_object_incref (const char *name,
+ json_t *o);
+
+
+/**
+ * Generate packer instruction for a JSON field of type
+ * JSON array where the reference is taken over by
+ * the packer.
+ *
+ * @param name name of the field to add to the object
+ * @param a array to steal
+ * @return json pack specification
+ */
+struct GNUNET_JSON_PackSpec
+GNUNET_JSON_pack_array_steal (const char *name,
+ json_t *a);
+
+
+/**
+ * Generate packer instruction for a JSON field of type JSON array where the
+ * reference counter is incremented by the packer. Note that a deep copy is
+ * not performed.
+ *
+ * @param name name of the field to add to the object
+ * @param a array to increment reference counter of
+ * @return json pack specification
+ */
+struct GNUNET_JSON_PackSpec
+GNUNET_JSON_pack_array_incref (const char *name,
+ json_t *a);
+
+
+/**
+ * Generate packer instruction for a JSON field of type
+ * variable size binary blob.
+ *
+ * @param name name of the field to add to the object
+ * @param blob binary data to pack
+ * @param blob_size number of bytes in @a blob
+ * @return json pack specification
+ */
+struct GNUNET_JSON_PackSpec
+GNUNET_JSON_pack_data_varsize (const char *name,
+ const void *blob,
+ size_t blob_size);
+
+
+/**
+ * Generate packer instruction for a JSON field where the
+ * size is automatically determined from the argument.
+ *
+ * @param name name of the field to add to the object
+ * @param blob data to pack, must not be an array
+ * @return json pack specification
+ */
+#define GNUNET_JSON_pack_data_auto(name,blob) \
+ GNUNET_JSON_pack_data_varsize (name, blob, sizeof (*blob))
+
+
+/**
+ * Generate packer instruction for a JSON field of type
+ * absolute time.
+ *
+ * @param name name of the field to add to the object
+ * @param at absolute time to pack, a value of 0 is only
+ * allowed with #GNUNET_JSON_pack_allow_null()!
+ * @return json pack specification
+ */
+struct GNUNET_JSON_PackSpec
+GNUNET_JSON_pack_time_abs (const char *name,
+ struct GNUNET_TIME_Absolute at);
+
+
+/**
+ * Generate packer instruction for a JSON field of type
+ * absolute time in network byte order.
+ *
+ * @param name name of the field to add to the object
+ * @param at absolute time to pack, a value of 0 is only
+ * allowed with #GNUNET_JSON_pack_allow_null()!
+ * @return json pack specification
+ */
+struct GNUNET_JSON_PackSpec
+GNUNET_JSON_pack_time_abs_nbo (const char *name,
+ struct GNUNET_TIME_AbsoluteNBO at);
+
+
+/**
+ * Generate packer instruction for a JSON field of type
+ * relative time.
+ *
+ * @param name name of the field to add to the object
+ * @param rt relative time to pack
+ * @return json pack specification
+ */
+struct GNUNET_JSON_PackSpec
+GNUNET_JSON_pack_time_rel (const char *name,
+ struct GNUNET_TIME_Relative rt);
+
+
+/**
+ * Generate packer instruction for a JSON field of type
+ * relative time in network byte order.
+ *
+ * @param name name of the field to add to the object
+ * @param rt relative time to pack
+ * @return json pack specification
+ */
+struct GNUNET_JSON_PackSpec
+GNUNET_JSON_pack_time_rel_nbo (const char *name,
+ struct GNUNET_TIME_RelativeNBO rt);
+
+
+/**
+ * Generate packer instruction for a JSON field of type
+ * RSA public key.
+ *
+ * @param name name of the field to add to the object
+ * @param pk RSA public key
+ * @return json pack specification
+ */
+struct GNUNET_JSON_PackSpec
+GNUNET_JSON_pack_rsa_public_key (const char *name,
+ const struct GNUNET_CRYPTO_RsaPublicKey *pk);
+
+
+/**
+ * Generate packer instruction for a JSON field of type
+ * RSA signature.
+ *
+ * @param name name of the field to add to the object
+ * @param sig RSA signature
+ * @return json pack specification
+ */
+struct GNUNET_JSON_PackSpec
+GNUNET_JSON_pack_rsa_signature (const char *name,
+ const struct GNUNET_CRYPTO_RsaSignature *sig);
+
+
#endif
/* end of gnunet_json_lib.h */
diff --git a/src/include/gnunet_messenger_service.h b/src/include/gnunet_messenger_service.h
index ecd856eb9..5d7155a3d 100644
--- a/src/include/gnunet_messenger_service.h
+++ b/src/include/gnunet_messenger_service.h
@@ -499,6 +499,7 @@ struct GNUNET_MESSENGER_Message
/**
* Enum for the different supported flags used by message handling
+ * Compatible flags can be OR'ed together.
*/
enum GNUNET_MESSENGER_MessageFlags
{
@@ -508,9 +509,14 @@ enum GNUNET_MESSENGER_MessageFlags
GNUNET_MESSENGER_FLAG_NONE = 0,
/**
+ * The sent flag. The flag indicates that the message was sent by the client.
+ */
+ GNUNET_MESSENGER_FLAG_SENT = 1,
+
+ /**
* The private flag. The flag indicates that the message was privately encrypted.
*/
- GNUNET_MESSENGER_FLAG_PRIVATE = 1,
+ GNUNET_MESSENGER_FLAG_PRIVATE = 2,
};
/**
@@ -526,8 +532,8 @@ typedef void
/**
* Method called whenever a message is sent or received from a <i>room</i>.
*
- * The flag <i>private_message</i> will be #GNUNET_YES if a message was
- * received privately, otherwise #GNUNET_NO.
+ * The <i>flags</i> will indicate with a bitmask if a message was
+ * received privately or if the message was sent by the client.
*
* @param[in/out] cls Closure from #GNUNET_MESSENGER_connect
* @param[in] room Room handle
diff --git a/src/include/gnunet_pq_lib.h b/src/include/gnunet_pq_lib.h
index 1f2915165..fe3fabbea 100644
--- a/src/include/gnunet_pq_lib.h
+++ b/src/include/gnunet_pq_lib.h
@@ -853,113 +853,8 @@ GNUNET_PQ_reconnect (struct GNUNET_PQ_Context *db);
/**
- * Function called whenever the socket needed for
- * notifications from postgres changes.
- *
- * @param cls closure
- * @param fd socket to listen on, -1 for none
- */
-typedef void
-(*GNUNET_PQ_SocketCallback)(void *cls,
- int fd);
-
-
-/**
- * Obtain the file descriptor to poll on for notifications.
- * Useful if the GNUnet scheduler is NOT to be used for
- * such notifications.
- *
- * @param db database handle
- * @param sc function to call with the socket
- * @param sc_cls closure for @a sc
- */
-void
-GNUNET_PQ_event_set_socket_callback (struct GNUNET_PQ_Context *db,
- GNUNET_PQ_SocketCallback sc,
- void *sc_cls);
-
-
-/**
- * Poll for database events now. Used if the event FD
- * is ready and the application wants to trigger applicable
- * events.
- * Useful if the GNUnet scheduler is NOT to be used for
- * such notifications.
- *
- * @param db database handle
- */
-void
-GNUNET_PQ_event_do_poll (struct GNUNET_PQ_Context *db);
-
-
-/**
- * Run poll event loop using the GNUnet scheduler.
- *
- * @param db database handle
- */
-void
-GNUNET_PQ_event_scheduler_start (struct GNUNET_PQ_Context *db);
-
-
-/**
- * Stop running poll event loop using the GNUnet scheduler.
- *
- * @param db database handle
- */
-void
-GNUNET_PQ_event_scheduler_stop (struct GNUNET_PQ_Context *db);
-
-
-/**
- * Handle for an active LISTENer to the database.
- */
-struct GNUNET_PQ_EventHandler;
-
-/**
- * Function called on events received from Postgres.
- *
- * @param cls closure
- * @param extra additional event data provided
- * @param extra_size number of bytes in @a extra
- */
-typedef void
-(*GNUNET_PQ_EventCallback)(void *cls,
- const void *extra,
- size_t extra_size);
-
-GNUNET_NETWORK_STRUCT_BEGIN
-
-
-/**
- * Header of a structure that describes an
- * event channel we may subscribe to or notify on.
- */
-struct GNUNET_PQ_EventHeaderP
-{
- /**
- * The length of the struct (in bytes, including the length field itself),
- * in big-endian format.
- */
- uint16_t size GNUNET_PACKED;
-
- /**
- * The type of the message (GNUNET_PQ_EVENT_TYPE_XXXX), in big-endian format.
- */
- uint16_t type GNUNET_PACKED;
-
-};
-
-GNUNET_NETWORK_STRUCT_END
-
-
-/**
- * Handle for an active LISTENer to the database.
- */
-struct GNUNET_PQ_EventHandler;
-
-/**
* Register callback to be invoked on events of type @a es.
- *
+ *
* Unlike many other calls, this function is thread-safe
* and may be called from threads that are different
* from the one that setup @a db. However, the @a cb
@@ -968,21 +863,23 @@ struct GNUNET_PQ_EventHandler;
*
* @param db database context to use
* @param es specification of the event to listen for
+ * @param timeout when to trigger @a cb based on timeout
* @param cb function to call when the event happens, possibly
- * multiple times (until #GNUNET_PQ_event_listen_cancel() is invoked)
+ * multiple times (until #GNUNET_PQ_event_listen_cancel() is invoked), including on timeout
* @param cb_cls closure for @a cb
* @return handle useful to cancel the listener
*/
-struct GNUNET_PQ_EventHandler *
+struct GNUNET_DB_EventHandler *
GNUNET_PQ_event_listen (struct GNUNET_PQ_Context *db,
- const struct GNUNET_PQ_EventHeaderP *es,
- GNUNET_PQ_EventCallback cb,
+ const struct GNUNET_DB_EventHeaderP *es,
+ struct GNUNET_TIME_Relative timeout,
+ GNUNET_DB_EventCallback cb,
void *cb_cls);
/**
* Stop notifications.
- *
+ *
* Unlike many other calls, this function is thread-safe
* and may be called from threads that are different
* from the one that setup @a db. However, the @a cb
@@ -992,12 +889,12 @@ GNUNET_PQ_event_listen (struct GNUNET_PQ_Context *db,
* @param eh handle to unregister.
*/
void
-GNUNET_PQ_event_listen_cancel (struct GNUNET_PQ_EventHandler *eh);
+GNUNET_PQ_event_listen_cancel (struct GNUNET_DB_EventHandler *eh);
/**
* Notify all that listen on @a es of an event.
- *
+ *
* Unlike many other calls, this function is thread-safe
* and may be called from threads that are different
* from the one that setup @a db. However, the @a cb
@@ -1011,7 +908,7 @@ GNUNET_PQ_event_listen_cancel (struct GNUNET_PQ_EventHandler *eh);
*/
void
GNUNET_PQ_event_notify (struct GNUNET_PQ_Context *db,
- const struct GNUNET_PQ_EventHeaderP *es,
+ const struct GNUNET_DB_EventHeaderP *es,
const void *extra,
size_t extra_size);
diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h
index 715e94c6a..6b61dfc72 100644
--- a/src/include/gnunet_protocols.h
+++ b/src/include/gnunet_protocols.h
@@ -1784,6 +1784,13 @@ extern "C" {
*/
#define GNUNET_MESSAGE_TYPE_SETU_P2P_OVER 572
+/**
+ * Signals other peer that all elements are sent.
+ */
+
+#define GNUNET_MESSAGE_TYPE_SETU_P2P_SEND_FULL 710
+
+
/*******************************************************************************
* SETI message types
diff --git a/src/include/gnunet_setu_service.h b/src/include/gnunet_setu_service.h
index bacec9408..1d7e48402 100644
--- a/src/include/gnunet_setu_service.h
+++ b/src/include/gnunet_setu_service.h
@@ -163,7 +163,31 @@ enum GNUNET_SETU_OptionType
/**
* Notify client also if we are sending a value to the other peer.
*/
- GNUNET_SETU_OPTION_SYMMETRIC = 8
+ GNUNET_SETU_OPTION_SYMMETRIC = 8,
+
+ /**
+ * Byzantine upper bound. Is the maximal plausible number of elements
+ * a peer can have default max uint64
+ */
+ GNUNET_SETU_OPTION_CUSTOM_BYZANTINE_UPPER_BOUND = 16,
+
+ /**
+ * Bandwidth latency tradeoff determines how much bytes a single RTT is
+ * worth, which is a performance setting
+ */
+ GNUNET_SETU_OPTION_CUSTOM_BANDWIDTH_LATENCY_TRADEOFF= 32,
+
+ /**
+ * The factor determines the number of buckets an IBF has which is
+ * multiplied by the estimated setsize default: 2
+ */
+ GNUNET_SETU_OPTION_CUSTOM_IBF_BUCKET_NUMBER_FACTOR= 64,
+
+ /**
+ * This setting determines to how many IBF buckets an single elements
+ * is mapped to.
+ */
+ GNUNET_SETU_OPTION_CUSTOM_IBF_BUCKETS_PER_ELEMENT= 128
};
diff --git a/src/include/gnunet_testbed_ng_service.h b/src/include/gnunet_testbed_ng_service.h
deleted file mode 100644
index 49e9f56bc..000000000
--- a/src/include/gnunet_testbed_ng_service.h
+++ /dev/null
@@ -1,284 +0,0 @@
-/*
- This file is part of GNUnet
- Copyright (C) 2021 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
- */
-
-/**
- * @author t3sserakt
- *
- * @file
- * API for writing tests and creating large-scale emulation testbeds for GNUnet with command pattern.
- *
- * @defgroup testbed Testbed service
- * Writing tests and creating large-scale emulation testbeds for GNUnet with command pattern.
- *
- * @see [Documentation](https://docs.gnunet.org/handbook/gnunet.html#TESTBED-NG-Subsystem)
- *
- * @{
- */
-
-#ifndef GNUNET_TESTBED_NG_SERVICE_H
-#define GNUNET_TESTBED_NG_SERVICE_H
-
-#include "gnunet_util_lib.h"
-#include "gnunet_testing_ng_lib.h"
-
-struct TngState;
-
-struct PeerCmdState
-{
- /**
- * The label of a controller command.
- */
- const char *controller_label;
-
- /**
- * Handle to operation
- */
- struct GNUNET_TESTBED_Operation *operation;
-
- /**
- * Name of the host, use "NULL" for localhost.
- */
- const char *hostname;
-
- /**
- * Username to use for the login; may be NULL.
- */
- const char *username;
-
- /**
- * Port number to use for ssh; use 0 to let ssh decide.
- */
- uint16_t port;
-
- /**
- * The configuration to use as a template while starting a controller
- * on this host. Operation queue sizes specific to a host are also
- * read from this configuration handle.
- */
- struct GNUNET_CONFIGURATION_Handle *cfg;
-
- /**
- * The host to run peers and controllers on
- */
- struct GNUNET_TESTBED_Host *host;
-
- /**
- * Abort task identifier
- */
- struct GNUNET_SCHEDULER_Task *abort_task;
-
- /**
- * Flag indicating if peer is ready.
- */
- int peer_ready;
-
- /**
- * Flag indicating controller is going down.
- */
- int peer_going_down;
-
- /**
- * Interpreter state.
- */
- struct GNUNET_TESTING_Interpreter *is;
-
- /**
- * Peer to start
- */
- struct GNUNET_TESTBED_Peer *peer;
-};
-
-struct ControllerState
-{
- /**
- * The ip address of the controller which will be set as TRUSTED
- * HOST(all connections form this ip are permitted by the testbed) when
- * starting testbed controller at host. This can either be a single ip
- * address or a network address in CIDR notation.
- */
- const char *trusted_ip;
-
- /**
- * Name of the host, use "NULL" for localhost.
- */
- const char *hostname;
-
- /**
- * Username to use for the login; may be NULL.
- */
- const char *username;
-
- /**
- * Port number to use for ssh; use 0 to let ssh decide.
- */
- uint16_t port;
-
- /**
- * The configuration to use as a template while starting a controller
- * on this host. Operation queue sizes specific to a host are also
- * read from this configuration handle.
- */
- struct GNUNET_CONFIGURATION_Handle *cfg;
-
- /**
- * The host to run peers and controllers on
- */
- struct GNUNET_TESTBED_Host *host;
-
- /**
- * The controller process
- */
- struct GNUNET_TESTBED_ControllerProc *cp;
-
- /**
- * The controller handle
- */
- struct GNUNET_TESTBED_Controller *controller;
-
- /**
- * A bit mask with set of events to call the controller for.
- */
- uint64_t event_mask;
-
- /**
- * Abort task identifier
- */
- struct GNUNET_SCHEDULER_Task *abort_task;
-
- /**
- * Handle for host registration
- */
- struct GNUNET_TESTBED_HostRegistrationHandle *reg_handle;
-
- /**
- * Flag indicating if host create with controller is ready.
- */
- int host_ready;
-
- /**
- * Flag indicating controller is going down.
- */
- int controller_going_down;
-
- /**
- * Interpreter state.
- */
- struct GNUNET_TESTING_Interpreter *is;
-};
-
-/**
- * Offer data from trait
- *
- * @param cmd command to extract the controller from.
- * @param pt pointer to controller.
- * @return #GNUNET_OK on success.
- */
-int
-GNUNET_TESTBED_get_trait_controller (const struct GNUNET_TESTING_Command *cmd,
- struct GNUNET_TESTBED_Controller **
- controller);
-
-struct GNUNET_TESTING_Command
-GNUNET_TESTBED_cmd_controller (const char *label,
- const char *host,
- uint64_t event_mask);
-
-void
-GNUNET_TESTBED_shutdown_controller (struct ControllerState *cs);
-
-void
-GNUNET_TESTBED_shutdown_peer (struct PeerCmdState *ps);
-
-void
-GNUNET_TESTBED_shutdown_service (struct TngState *ss);
-
-/**
- * Create command.
- *
- * @param label name for command.
- * @param binaryname to start.
- * @return command.
- */
-struct GNUNET_TESTING_Command
-GNUNET_TESTBED_cmd_netjail_start (const char *label,
- char *local_m,
- char *global_n);
-
-
-/**
- * Create command.
- *
- * @param label name for command.
- * @param binaryname to exec.
- * @return command.
- */
-struct GNUNET_TESTING_Command
-GNUNET_TESTBED_cmd_netjail_start_testbed (const char *label,
- char *local_m,
- char *global_n,
- char *plugin_name);
-
-
-/**
- * Create command.
- *
- * @param label name for command.
- * @param binaryname to stop.
- * @return command.
- */
-struct GNUNET_TESTING_Command
-GNUNET_TESTBED_cmd_netjail_stop (const char *label,
- char *local_m,
- char *global_n);
-
-
-struct GNUNET_TESTING_Command
-GNUNET_TESTBED_cmd_stop_testbed (const char *label,
- const char *helper_start_label,
- char *local_m,
- char *global_n);
-
-
-int
-GNUNET_TESTBED_get_trait_helper_handles (const struct
- GNUNET_TESTING_Command *cmd,
- struct GNUNET_HELPER_Handle ***helper);
-
-
-int
-GNUNET_TESTBED_get_trait_hosts (const struct
- GNUNET_TESTING_Command *cmd,
- struct GNUNET_TESTBED_Host ***hosts);
-
-struct GNUNET_TESTING_Command
-GNUNET_TESTING_cmd_block_until_all_peers_started (const char *label,
- unsigned int *
- all_peers_started);
-
-struct GNUNET_TESTING_Command
-GNUNET_TESTING_cmd_send_peer_ready (const char *label,
- TESTBED_CMD_HELPER_write_cb write_message);
-
-struct GNUNET_TESTING_Command
-GNUNET_TESTING_cmd_local_test_finished (const char *label,
- TESTBED_CMD_HELPER_write_cb
- write_message);
-
-#endif
diff --git a/src/include/gnunet_testing_ng_lib.h b/src/include/gnunet_testing_ng_lib.h
index aad7ddec2..939863d67 100644
--- a/src/include/gnunet_testing_ng_lib.h
+++ b/src/include/gnunet_testing_ng_lib.h
@@ -838,8 +838,82 @@ GNUNET_TESTING_get_trait_test_system (const struct
GNUNET_TESTING_Command *cmd,
struct GNUNET_TESTING_System **test_system);
+
struct GNUNET_TESTING_Command
GNUNET_TESTING_cmd_system_create (const char *label,
const char *testdir);
+
+struct GNUNET_TESTING_Command
+GNUNET_TESTING_cmd_system_destroy (const char *label,
+ const char *create_label);
+
+
+/**
+ * Create command.
+ *
+ * @param label name for command.
+ * @param binaryname to start.
+ * @return command.
+ */
+struct GNUNET_TESTING_Command
+GNUNET_TESTING_cmd_netjail_start (const char *label,
+ char *local_m,
+ char *global_n);
+
+
+/**
+ * Create command.
+ *
+ * @param label name for command.
+ * @param binaryname to exec.
+ * @return command.
+ */
+struct GNUNET_TESTING_Command
+GNUNET_TESTING_cmd_netjail_start_testing_system (const char *label,
+ char *local_m,
+ char *global_n,
+ char *plugin_name,
+ unsigned int *rv);
+
+
+/**
+ * Create command.
+ *
+ * @param label name for command.
+ * @param binaryname to stop.
+ * @return command.
+ */
+struct GNUNET_TESTING_Command
+GNUNET_TESTING_cmd_netjail_stop (const char *label,
+ char *local_m,
+ char *global_n);
+
+
+struct GNUNET_TESTING_Command
+GNUNET_TESTING_cmd_stop_testing_system (const char *label,
+ const char *helper_start_label,
+ char *local_m,
+ char *global_n);
+
+
+int
+GNUNET_TESTING_get_trait_helper_handles (const struct
+ GNUNET_TESTING_Command *cmd,
+ struct GNUNET_HELPER_Handle ***helper);
+
+
+struct GNUNET_TESTING_Command
+GNUNET_TESTING_cmd_block_until_all_peers_started (const char *label,
+ unsigned int *
+ all_peers_started);
+
+struct GNUNET_TESTING_Command
+GNUNET_TESTING_cmd_send_peer_ready (const char *label,
+ TESTING_CMD_HELPER_write_cb write_message);
+
+struct GNUNET_TESTING_Command
+GNUNET_TESTING_cmd_local_test_finished (const char *label,
+ TESTING_CMD_HELPER_write_cb
+ write_message);
#endif
diff --git a/src/include/gnunet_testing_plugin.h b/src/include/gnunet_testing_plugin.h
index 8395e2a49..151827d4b 100644
--- a/src/include/gnunet_testing_plugin.h
+++ b/src/include/gnunet_testing_plugin.h
@@ -37,15 +37,16 @@ extern "C"
#endif
typedef void
-(*TESTBED_CMD_HELPER_write_cb) (struct GNUNET_MessageHeader *message, size_t
+(*TESTING_CMD_HELPER_write_cb) (struct GNUNET_MessageHeader *message, size_t
msg_length);
typedef void
-(*GNUNET_TESTING_PLUGIN_StartTestCase) (TESTBED_CMD_HELPER_write_cb
+(*GNUNET_TESTING_PLUGIN_StartTestCase) (TESTING_CMD_HELPER_write_cb
write_message, char *router_ip,
char *node_ip,
char *n,
- char *m);
+ char *m,
+ char *local_m);
typedef void
(*GNUNET_TESTING_PLUGIN_ALL_PEERS_STARTED) ();
diff --git a/src/include/gnunet_util_lib.h b/src/include/gnunet_util_lib.h
index 3acd4cb9b..cc4f3a01e 100644
--- a/src/include/gnunet_util_lib.h
+++ b/src/include/gnunet_util_lib.h
@@ -58,7 +58,8 @@ extern "C"
* THIS release. Otherwise, you are violating the Affero GPL if you make
* this service available to anyone but yourself.
*/
-#define GNUNET_AGPL_URL "https://gnunet.org/git/gnunet.git#" PACKAGE_VERSION
+#define GNUNET_AGPL_URL "https://git.gnunet.org/gnunet.git/tag/?h=v" \
+ PACKAGE_VERSION
#include "gnunet_crypto_lib.h"
diff --git a/src/include/platform.h b/src/include/platform.h
index e641b38eb..e44f9f51a 100644
--- a/src/include/platform.h
+++ b/src/include/platform.h
@@ -22,7 +22,7 @@
* @author Nils Durner
* @author Christian Grothoff
*
- * @file
+ * @file gnunet/src/include/platform.h
* Platform specific includes and defines.
*
* This file should never be included by installed
@@ -170,18 +170,12 @@
#include "compat.h"
#include <locale.h>
-#ifndef FRAMEWORK_BUILD
#include "gettext.h"
/**
* GNU gettext support macro.
*/
#define _(String) dgettext (PACKAGE, String)
#define LIBEXTRACTOR_GETTEXT_DOMAIN "libextractor"
-#else
-#include "libintlemu.h"
-#define _(String) dgettext ("org.gnunet.gnunet", String)
-#define LIBEXTRACTOR_GETTEXT_DOMAIN "org.gnunet.libextractor"
-#endif
#include <sys/mman.h>
@@ -252,6 +246,32 @@ atoll (const char *nptr);
#define GNUNET_THREAD_LOCAL
#endif
+
+/* LSB-style exit status codes */
+#ifndef EXIT_INVALIDARGUMENT
+#define EXIT_INVALIDARGUMENT 2
+#endif
+
+#ifndef EXIT_NOTIMPLEMENTED
+#define EXIT_NOTIMPLEMENTED 3
+#endif
+
+#ifndef EXIT_NOPERMISSION
+#define EXIT_NOPERMISSION 4
+#endif
+
+#ifndef EXIT_NOTINSTALLED
+#define EXIT_NOTINSTALLED 5
+#endif
+
+#ifndef EXIT_NOTCONFIGURED
+#define EXIT_NOTCONFIGURED 6
+#endif
+
+#ifndef EXIT_NOTRUNNING
+#define EXIT_NOTRUNNING 7
+#endif
+
/**
* clang et al do not have such an attribute
*/
diff --git a/src/json/Makefile.am b/src/json/Makefile.am
index d4ea38adf..2e97cecb9 100644
--- a/src/json/Makefile.am
+++ b/src/json/Makefile.am
@@ -13,21 +13,21 @@ libgnunetjson_la_LDFLAGS = \
$(GN_LIBINTL) \
-version-info 0:0:0 \
-no-undefined
-libgnunetjson_la_CFLAGS = $(MHD_CFLAGS) $(AM_CFLAGS)
+libgnunetjson_la_CFLAGS = \
+ $(MHD_CFLAGS) \
+ $(AM_CFLAGS)
libgnunetjson_la_SOURCES = \
json.c \
- json_mhd.c \
json_generator.c \
- json_helper.c
+ json_helper.c \
+ json_mhd.c \
+ json_pack.c
libgnunetjson_la_LIBADD = \
$(top_builddir)/src/util/libgnunetutil.la \
-ljansson \
$(MHD_LIBS) \
$(XLIB) \
$(Z_LIBS)
-libgnunetjson_la_DEPENDENCIES = \
- $(top_builddir)/src/util/libgnunetutil.la
-
check_PROGRAMS = \
test_json \
diff --git a/src/json/json.c b/src/json/json.c
index d55189804..51d5c0c72 100644
--- a/src/json/json.c
+++ b/src/json/json.c
@@ -28,19 +28,6 @@
#include "gnunet_json_lib.h"
-/**
- * Navigate and parse data in a JSON tree. Tries to parse the @a root
- * to find all of the values given in the @a spec. If one of the
- * entries in @a spec cannot be found or parsed, the name of the JSON
- * field is returned in @a error_json_name, and the offset of the
- * entry in @a spec is returned in @a error_line.
- *
- * @param root the JSON node to start the navigation at.
- * @param spec parse specification array
- * @param[out] error_json_name which JSON field was problematic
- * @param[out] which index into @a spec did we encounter an error
- * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
- */
enum GNUNET_GenericReturnValue
GNUNET_JSON_parse (const json_t *root,
struct GNUNET_JSON_Specification *spec,
@@ -85,12 +72,6 @@ GNUNET_JSON_parse (const json_t *root,
}
-/**
- * Set the "optional" flag for a parser specification entry.
- *
- * @param spec specification to modify
- * @return spec copy of @a spec with optional bit set
- */
struct GNUNET_JSON_Specification
GNUNET_JSON_spec_mark_optional (struct GNUNET_JSON_Specification spec)
{
@@ -101,18 +82,13 @@ GNUNET_JSON_spec_mark_optional (struct GNUNET_JSON_Specification spec)
}
-/**
- * Frees all elements allocated during a #GNUNET_JSON_parse()
- * operation.
- *
- * @param spec specification of the parse operation
- */
void
GNUNET_JSON_parse_free (struct GNUNET_JSON_Specification *spec)
{
for (unsigned int i = 0; NULL != spec[i].parser; i++)
if (NULL != spec[i].cleaner)
- spec[i].cleaner (spec[i].cls, &spec[i]);
+ spec[i].cleaner (spec[i].cls,
+ &spec[i]);
}
@@ -151,15 +127,6 @@ set_json (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
}
-/**
- * Allow user to specify a JSON input value.
- *
- * @param shortName short name of the option
- * @param name long name of the option
- * @param argumentHelp help text for the option argument
- * @param description long help text for the option
- * @param[out] val set to the JSON specified at the command line
- */
struct GNUNET_GETOPT_CommandLineOption
GNUNET_JSON_getopt (char shortName,
const char *name,
diff --git a/src/json/json_pack.c b/src/json/json_pack.c
new file mode 100644
index 000000000..92f8b4535
--- /dev/null
+++ b/src/json/json_pack.c
@@ -0,0 +1,325 @@
+/*
+ This file is part of GNUnet
+ Copyright (C) 2021 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 json/json_pack.c
+ * @brief functions to pack JSON objects
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "gnunet_json_lib.h"
+
+
+json_t *
+GNUNET_JSON_pack_ (struct GNUNET_JSON_PackSpec spec[])
+{
+ json_t *ret;
+
+ ret = json_object ();
+ GNUNET_assert (NULL != ret);
+ for (unsigned int i = 0;
+ NULL != spec[i].field_name;
+ i++)
+ {
+ if (NULL == spec[i].object)
+ {
+ GNUNET_assert (spec[i].allow_null);
+ }
+ else
+ {
+ GNUNET_assert (0 ==
+ json_object_set_new (ret,
+ spec[i].field_name,
+ spec[i].object));
+ spec[i].object = NULL;
+ }
+ }
+ return ret;
+}
+
+
+struct GNUNET_JSON_PackSpec
+GNUNET_JSON_pack_end_ (void)
+{
+ struct GNUNET_JSON_PackSpec ps = {
+ .field_name = NULL
+ };
+
+ return ps;
+}
+
+
+struct GNUNET_JSON_PackSpec
+GNUNET_JSON_pack_allow_null (struct GNUNET_JSON_PackSpec in)
+{
+ in.allow_null = true;
+ return in;
+}
+
+
+struct GNUNET_JSON_PackSpec
+GNUNET_JSON_pack_bool (const char *name,
+ bool b)
+{
+ struct GNUNET_JSON_PackSpec ps = {
+ .field_name = name,
+ .object = json_boolean (b)
+ };
+
+ return ps;
+}
+
+
+struct GNUNET_JSON_PackSpec
+GNUNET_JSON_pack_string (const char *name,
+ const char *s)
+{
+ struct GNUNET_JSON_PackSpec ps = {
+ .field_name = name,
+ .object = json_string (s)
+ };
+
+ return ps;
+}
+
+
+struct GNUNET_JSON_PackSpec
+GNUNET_JSON_pack_uint64 (const char *name,
+ uint64_t num)
+{
+ struct GNUNET_JSON_PackSpec ps = {
+ .field_name = name,
+ .object = json_integer ((json_int_t) num)
+ };
+
+#if JSON_INTEGER_IS_LONG_LONG
+ GNUNET_assert (num <= LLONG_MAX);
+#else
+ GNUNET_assert (num <= LONG_MAX);
+#endif
+ return ps;
+}
+
+
+struct GNUNET_JSON_PackSpec
+GNUNET_JSON_pack_int64 (const char *name,
+ int64_t num)
+{
+ struct GNUNET_JSON_PackSpec ps = {
+ .field_name = name,
+ .object = json_integer ((json_int_t) num)
+ };
+
+#if JSON_INTEGER_IS_LONG_LONG
+ GNUNET_assert (num <= LLONG_MAX);
+ GNUNET_assert (num >= LLONG_MIN);
+#else
+ GNUNET_assert (num <= LONG_MAX);
+ GNUNET_assert (num >= LONG_MIN);
+#endif
+ return ps;
+}
+
+
+struct GNUNET_JSON_PackSpec
+GNUNET_JSON_pack_object_steal (const char *name,
+ json_t *o)
+{
+ struct GNUNET_JSON_PackSpec ps = {
+ .field_name = name,
+ .object = o
+ };
+
+ if (NULL == o)
+ return ps;
+ if (! json_is_object (o))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Expected JSON object for field `%s'\n",
+ name);
+ GNUNET_assert (0);
+ }
+ return ps;
+}
+
+
+struct GNUNET_JSON_PackSpec
+GNUNET_JSON_pack_object_incref (const char *name,
+ json_t *o)
+{
+ struct GNUNET_JSON_PackSpec ps = {
+ .field_name = name,
+ .object = o
+ };
+
+ if (NULL == o)
+ return ps;
+ (void) json_incref (o);
+ if (! json_is_object (o))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Expected JSON object for field `%s'\n",
+ name);
+ GNUNET_assert (0);
+ }
+ return ps;
+}
+
+
+struct GNUNET_JSON_PackSpec
+GNUNET_JSON_pack_array_steal (const char *name,
+ json_t *a)
+{
+ struct GNUNET_JSON_PackSpec ps = {
+ .field_name = name,
+ .object = a
+ };
+
+ if (NULL == a)
+ return ps;
+ if (! json_is_array (a))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Expected JSON array for field `%s'\n",
+ name);
+ GNUNET_assert (0);
+ }
+ return ps;
+}
+
+
+struct GNUNET_JSON_PackSpec
+GNUNET_JSON_pack_array_incref (const char *name,
+ json_t *a)
+{
+ struct GNUNET_JSON_PackSpec ps = {
+ .field_name = name,
+ .object = a
+ };
+
+ if (NULL == a)
+ return ps;
+ (void) json_incref (a);
+ if (! json_is_array (a))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Expected JSON array for field `%s'\n",
+ name);
+ GNUNET_assert (0);
+ }
+ return ps;
+}
+
+
+struct GNUNET_JSON_PackSpec
+GNUNET_JSON_pack_data_varsize (const char *name,
+ const void *blob,
+ size_t blob_size)
+{
+ struct GNUNET_JSON_PackSpec ps = {
+ .field_name = name,
+ .object = (NULL != blob)
+ ? GNUNET_JSON_from_data (blob,
+ blob_size)
+ : NULL
+ };
+
+ return ps;
+}
+
+
+struct GNUNET_JSON_PackSpec
+GNUNET_JSON_pack_time_abs (const char *name,
+ struct GNUNET_TIME_Absolute at)
+{
+ struct GNUNET_JSON_PackSpec ps = {
+ .field_name = name
+ };
+
+ if (0 != at.abs_value_us)
+ {
+ ps.object = GNUNET_JSON_from_time_abs (at);
+ GNUNET_assert (NULL != ps.object);
+ }
+ else
+ {
+ ps.object = NULL;
+ }
+ return ps;
+}
+
+
+struct GNUNET_JSON_PackSpec
+GNUNET_JSON_pack_time_abs_nbo (const char *name,
+ struct GNUNET_TIME_AbsoluteNBO at)
+{
+ return GNUNET_JSON_pack_time_abs (name,
+ GNUNET_TIME_absolute_ntoh (at));
+}
+
+
+struct GNUNET_JSON_PackSpec
+GNUNET_JSON_pack_time_rel (const char *name,
+ struct GNUNET_TIME_Relative rt)
+{
+ json_t *json;
+
+ json = GNUNET_JSON_from_time_rel (rt);
+ GNUNET_assert (NULL != json);
+ return GNUNET_JSON_pack_object_steal (name,
+ json);
+}
+
+
+struct GNUNET_JSON_PackSpec
+GNUNET_JSON_pack_time_rel_nbo (const char *name,
+ struct GNUNET_TIME_RelativeNBO rt)
+{
+ return GNUNET_JSON_pack_time_rel (name,
+ GNUNET_TIME_relative_ntoh (rt));
+}
+
+
+struct GNUNET_JSON_PackSpec
+GNUNET_JSON_pack_rsa_public_key (const char *name,
+ const struct GNUNET_CRYPTO_RsaPublicKey *pk)
+{
+ struct GNUNET_JSON_PackSpec ps = {
+ .field_name = name,
+ .object = GNUNET_JSON_from_rsa_public_key (pk)
+ };
+
+ return ps;
+}
+
+
+struct GNUNET_JSON_PackSpec
+GNUNET_JSON_pack_rsa_signature (const char *name,
+ const struct GNUNET_CRYPTO_RsaSignature *sig)
+{
+ struct GNUNET_JSON_PackSpec ps = {
+ .field_name = name,
+ .object = GNUNET_JSON_from_rsa_signature (sig)
+ };
+
+ return ps;
+}
+
+
+/* end of json_pack.c */
diff --git a/src/messenger/gnunet-messenger.c b/src/messenger/gnunet-messenger.c
index 094ae398d..28fa4b147 100644
--- a/src/messenger/gnunet-messenger.c
+++ b/src/messenger/gnunet-messenger.c
@@ -80,7 +80,12 @@ on_message (void *cls, struct GNUNET_MESSENGER_Room *room, const struct GNUNET_M
}
case GNUNET_MESSENGER_KIND_TEXT:
{
- printf ("* '%s' says: \"%s\"\n", sender_name, message->body.text.text);
+ if (flags & GNUNET_MESSENGER_FLAG_SENT)
+ printf (">");
+ else
+ printf ("<");
+
+ printf (" '%s' says: \"%s\"\n", sender_name, message->body.text.text);
break;
}
default:
diff --git a/src/messenger/gnunet-service-messenger_handle.c b/src/messenger/gnunet-service-messenger_handle.c
index 4d2318d62..d7007dbf6 100644
--- a/src/messenger/gnunet-service-messenger_handle.c
+++ b/src/messenger/gnunet-service-messenger_handle.c
@@ -474,6 +474,28 @@ get_next_member_session_contect(const struct GNUNET_MESSENGER_MemberSession *ses
return get_member_session_context(session);
}
+static const struct GNUNET_MESSENGER_MemberSession*
+get_handle_member_session (struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key)
+{
+ GNUNET_assert((handle) && (key) && (handle->service));
+
+ const struct GNUNET_ShortHashCode *id = get_handle_member_id(handle, key);
+ struct GNUNET_MESSENGER_SrvRoom *room = get_service_room(handle->service, key);
+
+ if ((!id) || (!room))
+ return NULL;
+
+ struct GNUNET_MESSENGER_MemberStore *store = get_room_member_store(room);
+ struct GNUNET_MESSENGER_Member *member = get_store_member(store, id);
+
+ const struct GNUNET_MESSENGER_Ego *ego = get_handle_ego(handle);
+
+ if (!ego)
+ return NULL;
+
+ return get_member_session(member, &(ego->pub));
+}
+
void
notify_handle_message (struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key,
const struct GNUNET_MESSENGER_MemberSession *session,
@@ -523,9 +545,13 @@ notify_handle_message (struct GNUNET_MESSENGER_SrvHandle *handle, const struct G
GNUNET_memcpy(&(msg->context), context, sizeof(msg->context));
GNUNET_memcpy(&(msg->hash), hash, sizeof(msg->hash));
- msg->flags = (uint32_t) (
- private_message? GNUNET_MESSENGER_FLAG_PRIVATE : GNUNET_MESSENGER_FLAG_NONE
- );
+ msg->flags = (uint32_t) GNUNET_MESSENGER_FLAG_NONE;
+
+ if (get_handle_member_session(handle, key) == session)
+ msg->flags |= (uint32_t) GNUNET_MESSENGER_FLAG_SENT;
+
+ if (private_message)
+ msg->flags |= (uint32_t) GNUNET_MESSENGER_FLAG_PRIVATE;
char *buffer = ((char*) msg) + sizeof(*msg);
encode_message (message, length, buffer, GNUNET_YES);
diff --git a/src/messenger/gnunet-service-messenger_member.c b/src/messenger/gnunet-service-messenger_member.c
index 7f00e8438..b0a735dbe 100644
--- a/src/messenger/gnunet-service-messenger_member.c
+++ b/src/messenger/gnunet-service-messenger_member.c
@@ -88,6 +88,7 @@ callback_scan_for_sessions (void *cls, const char *filename)
GNUNET_asprintf (&directory, "%s%c", filename, DIR_SEPARATOR);
load_member_session(member, directory);
+ GNUNET_free (directory);
}
return GNUNET_OK;
diff --git a/src/messenger/gnunet-service-messenger_room.c b/src/messenger/gnunet-service-messenger_room.c
index c3a5e3a4b..73e94908f 100644
--- a/src/messenger/gnunet-service-messenger_room.c
+++ b/src/messenger/gnunet-service-messenger_room.c
@@ -1144,6 +1144,7 @@ load_room (struct GNUNET_MESSENGER_SrvRoom *room)
GNUNET_asprintf (&last_messages_file, "%s%s", room_dir, "last_messages.list");
load_message_state(&(room->state), room_dir);
+ GNUNET_free (last_messages_file);
}
GNUNET_free(room_dir);
diff --git a/src/namecache/namecache_api.c b/src/namecache/namecache_api.c
index fdbf142a7..70c848037 100644
--- a/src/namecache/namecache_api.c
+++ b/src/namecache/namecache_api.c
@@ -228,6 +228,7 @@ handle_lookup_block_response (void *cls,
char buf[size] GNUNET_ALIGN;
struct GNUNET_GNSRECORD_Block *block;
+ memset (buf, 0, size);
block = (struct GNUNET_GNSRECORD_Block *) buf;
GNUNET_memcpy (block,
&msg[1],
diff --git a/src/namestore/Makefile.am b/src/namestore/Makefile.am
index 61bcfbaf8..18e6a196b 100644
--- a/src/namestore/Makefile.am
+++ b/src/namestore/Makefile.am
@@ -752,8 +752,4 @@ EXTRA_DIST = \
test_plugin_namestore_postgres.conf \
test_plugin_namestore_flat.conf \
test_hostkey \
- zonefiles/BW7PTMDSN5KS42GMK2VKVE96BAYDS3QVMAS7SC5208FD6HFTAXE0.zkey \
- zonefiles/KHW2Y5A7X59Z8BC2GHSEQ9WGZ5HWVEF25TBFR3Q5QHCERMVM76DG.zkey \
- zonefiles/CNFGWF0JH0C65M6PQW6VSRR6D3NEZVHAQF6NC037J01TETS6CJ30.zkey \
- zonefiles/TWY43VS959JJ41KN2FG8782EJ2N0XDF4J6BWASR1BK5BPPRWQJAG.zkey \
$(check_SCRIPTS)
diff --git a/src/namestore/gnunet-namestore-fcfsd.c b/src/namestore/gnunet-namestore-fcfsd.c
index 847f7cb64..95d4c5878 100644
--- a/src/namestore/gnunet-namestore-fcfsd.c
+++ b/src/namestore/gnunet-namestore-fcfsd.c
@@ -185,15 +185,15 @@ do_shutdown (void *cls)
}
if (NULL != notfound_page)
{
- MHD_destroy_response (main_page->response);
- GNUNET_free (main_page->handle);
- GNUNET_free (main_page);
+ MHD_destroy_response (notfound_page->response);
+ GNUNET_free (notfound_page->handle);
+ GNUNET_free (notfound_page);
}
if (NULL != forbidden_page)
{
- MHD_destroy_response (main_page->response);
- GNUNET_free (main_page->handle);
- GNUNET_free (main_page);
+ MHD_destroy_response (forbidden_page->response);
+ GNUNET_free (forbidden_page->handle);
+ GNUNET_free (forbidden_page);
}
if (NULL != namestore)
diff --git a/src/namestore/plugin_rest_namestore.c b/src/namestore/plugin_rest_namestore.c
index ae93e5eff..ff5494dc7 100644
--- a/src/namestore/plugin_rest_namestore.c
+++ b/src/namestore/plugin_rest_namestore.c
@@ -955,6 +955,12 @@ list_ego (void *cls,
state = ID_REST_STATE_POST_INIT;
return;
}
+ if (NULL == ego)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Called with NULL ego\n");
+ return;
+ }
if (ID_REST_STATE_INIT == state)
{
ego_entry = GNUNET_new (struct EgoEntry);
diff --git a/src/namestore/zonefiles/BW7PTMDSN5KS42GMK2VKVE96BAYDS3QVMAS7SC5208FD6HFTAXE0.zkey b/src/namestore/zonefiles/BW7PTMDSN5KS42GMK2VKVE96BAYDS3QVMAS7SC5208FD6HFTAXE0.zkey
deleted file mode 100644
index 0d37aefef..000000000
--- a/src/namestore/zonefiles/BW7PTMDSN5KS42GMK2VKVE96BAYDS3QVMAS7SC5208FD6HFTAXE0.zkey
+++ /dev/null
@@ -1 +0,0 @@
- Q0҆d /#`$f \ No newline at end of file
diff --git a/src/namestore/zonefiles/CNFGWF0JH0C65M6PQW6VSRR6D3NEZVHAQF6NC037J01TETS6CJ30.zkey b/src/namestore/zonefiles/CNFGWF0JH0C65M6PQW6VSRR6D3NEZVHAQF6NC037J01TETS6CJ30.zkey
deleted file mode 100644
index b5b465ea1..000000000
--- a/src/namestore/zonefiles/CNFGWF0JH0C65M6PQW6VSRR6D3NEZVHAQF6NC037J01TETS6CJ30.zkey
+++ /dev/null
Binary files differ
diff --git a/src/namestore/zonefiles/KHW2Y5A7X59Z8BC2GHSEQ9WGZ5HWVEF25TBFR3Q5QHCERMVM76DG.zkey b/src/namestore/zonefiles/KHW2Y5A7X59Z8BC2GHSEQ9WGZ5HWVEF25TBFR3Q5QHCERMVM76DG.zkey
deleted file mode 100644
index 7535efb5e..000000000
--- a/src/namestore/zonefiles/KHW2Y5A7X59Z8BC2GHSEQ9WGZ5HWVEF25TBFR3Q5QHCERMVM76DG.zkey
+++ /dev/null
@@ -1 +0,0 @@
-p8&D6Vv+X{ A \ No newline at end of file
diff --git a/src/namestore/zonefiles/TWY43VS959JJ41KN2FG8782EJ2N0XDF4J6BWASR1BK5BPPRWQJAG.zkey b/src/namestore/zonefiles/TWY43VS959JJ41KN2FG8782EJ2N0XDF4J6BWASR1BK5BPPRWQJAG.zkey
deleted file mode 100644
index ac3ed96a3..000000000
--- a/src/namestore/zonefiles/TWY43VS959JJ41KN2FG8782EJ2N0XDF4J6BWASR1BK5BPPRWQJAG.zkey
+++ /dev/null
@@ -1,2 +0,0 @@
-XJM
-d胦ӌB=B \ No newline at end of file
diff --git a/src/nse/Makefile.am b/src/nse/Makefile.am
index 85ae4d3be..824aa10d4 100644
--- a/src/nse/Makefile.am
+++ b/src/nse/Makefile.am
@@ -47,6 +47,7 @@ gnunet_nse_profiler_LDADD = -lm \
libgnunetnse.la \
$(top_builddir)/src/util/libgnunetutil.la \
$(top_builddir)/src/statistics/libgnunetstatistics.la \
+ $(top_builddir)/src/testing/libgnunettesting.la \
$(top_builddir)/src/testbed/libgnunettestbed.la \
$(GN_LIBINTL)
diff --git a/src/peerinfo-tool/Makefile.am b/src/peerinfo-tool/Makefile.am
index 74af5890b..825ad5452 100644
--- a/src/peerinfo-tool/Makefile.am
+++ b/src/peerinfo-tool/Makefile.am
@@ -26,14 +26,6 @@ libgnunet_plugin_rest_peerinfo_la_LIBADD = \
$(top_builddir)/src/json/libgnunetjson.la \
$(top_builddir)/src/util/libgnunetutil.la $(XLIBS) \
$(LTLIBINTL) -ljansson $(MHD_LIBS)
-libgnunet_plugin_rest_peerinfo_la_DEPENDENCIES = \
- $(top_builddir)/src/hello/libgnunethello.la \
- $(top_builddir)/src/peerinfo/libgnunetpeerinfo.la \
- $(top_builddir)/src/transport/libgnunettransport.la \
- $(top_builddir)/src/ats/libgnunetats.la \
- $(top_builddir)/src/rest/libgnunetrest.la \
- $(top_builddir)/src/json/libgnunetjson.la \
- $(top_builddir)/src/util/libgnunetutil.la
libgnunet_plugin_rest_peerinfo_la_LDFLAGS = \
$(GN_PLUGIN_LDFLAGS)
libgnunet_plugin_rest_peerinfo_la_CFLAGS = $(MHD_CFLAGS) $(AM_CFLAGS)
diff --git a/src/pq/Makefile.am b/src/pq/Makefile.am
index 0febac4ac..cbb123cbb 100644
--- a/src/pq/Makefile.am
+++ b/src/pq/Makefile.am
@@ -24,7 +24,6 @@ libgnunetpq_la_LIBADD = -lpq \
libgnunetpq_la_LDFLAGS = \
$(POSTGRESQL_LDFLAGS) \
$(GN_LIB_LDFLAGS) \
- -lpthread \
-version-info 1:0:0
if ENABLE_TEST_RUN
diff --git a/src/pq/pq.h b/src/pq/pq.h
index 3c89626a9..d10931d99 100644
--- a/src/pq/pq.h
+++ b/src/pq/pq.h
@@ -28,6 +28,7 @@
#include "gnunet_util_lib.h"
#include "gnunet_pq_lib.h"
+
/**
* Handle to Postgres database.
*/
@@ -59,24 +60,32 @@ struct GNUNET_PQ_Context
char *load_path;
/**
- * Function to call on Postgres FDs.
+ * Map managing event subscriptions.
*/
- GNUNET_PQ_SocketCallback sc;
+ struct GNUNET_CONTAINER_MultiShortmap *channel_map;
/**
- * Closure for @e sc.
+ * Task responsible for processing events.
*/
- void *sc_cls;
+ struct GNUNET_SCHEDULER_Task *event_task;
/**
- * Map managing event subscriptions.
+ * File descriptor wrapper for @e event_task.
*/
- struct GNUNET_CONTAINER_MultiShortmap *channel_map;
-
- /**
- * Lock to access @e channel_map.
- */
- pthread_mutex_t notify_lock;
+ struct GNUNET_NETWORK_Handle *rfd;
};
+
+/**
+ * Internal API. Reconnect should re-register notifications
+ * after a disconnect.
+ *
+ * @param db the DB handle
+ * @param fd socket to listen on
+ */
+void
+GNUNET_PQ_event_reconnect_ (struct GNUNET_PQ_Context *db,
+ int fd);
+
+
#endif
diff --git a/src/pq/pq_connect.c b/src/pq/pq_connect.c
index 00664dcd0..a2dce3fb0 100644
--- a/src/pq/pq_connect.c
+++ b/src/pq/pq_connect.c
@@ -24,6 +24,7 @@
*/
#include "platform.h"
#include "pq.h"
+#include <pthread.h>
/**
@@ -63,28 +64,6 @@ pq_notice_processor_cb (void *arg,
}
-/**
- * Create a connection to the Postgres database using @a config_str for the
- * configuration. Initialize logging via GNUnet's log routines and disable
- * Postgres's logger. Also ensures that the statements in @a load_path and @a
- * es are executed whenever we (re)connect to the database, and that the
- * prepared statements in @a ps are "ready". If statements in @es fail that
- * were created with #GNUNET_PQ_make_execute(), then the entire operation
- * fails.
- *
- * In @a load_path, a list of "$XXXX.sql" files is expected where $XXXX
- * must be a sequence of contiguous integer values starting at 0000.
- * These files are then loaded in sequence using "psql $config_str" before
- * running statements from @e es. The directory is inspected again on
- * reconnect.
- *
- * @param config_str configuration to use
- * @param load_path path to directory with SQL transactions to run, can be NULL
- * @param es #GNUNET_PQ_PREPARED_STATEMENT_END-terminated
- * array of statements to execute upon EACH connection, can be NULL
- * @param ps array of prepared statements to prepare, can be NULL
- * @return NULL on error
- */
struct GNUNET_PQ_Context *
GNUNET_PQ_connect (const char *config_str,
const char *load_path,
@@ -122,6 +101,8 @@ GNUNET_PQ_connect (const char *config_str,
ps,
plen * sizeof (struct GNUNET_PQ_PreparedStatement));
}
+ db->channel_map = GNUNET_CONTAINER_multishortmap_create (16,
+ GNUNET_YES);
GNUNET_PQ_reconnect (db);
if (NULL == db->conn)
{
@@ -142,7 +123,7 @@ GNUNET_PQ_connect (const char *config_str,
* @param i patch number to append to the @a load_path
* @return #GNUNET_OK on success, #GNUNET_NO if patch @a i does not exist, #GNUNET_SYSERR on error
*/
-static int
+static enum GNUNET_GenericReturnValue
apply_patch (struct GNUNET_PQ_Context *db,
const char *load_path,
unsigned int i)
@@ -162,7 +143,7 @@ apply_patch (struct GNUNET_PQ_Context *db,
"Applying SQL file `%s' on database %s\n",
buf,
db->config_str);
- psql = GNUNET_OS_start_process (GNUNET_OS_INHERIT_STD_NONE,
+ psql = GNUNET_OS_start_process (GNUNET_OS_INHERIT_STD_ERR,
NULL,
NULL,
NULL,
@@ -191,7 +172,7 @@ apply_patch (struct GNUNET_PQ_Context *db,
(0 != code) )
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Could not run PSQL on file %s: %d\n",
+ "Could not run PSQL on file %s: psql exit code was %d\n",
buf,
(int) code);
return GNUNET_SYSERR;
@@ -200,15 +181,6 @@ apply_patch (struct GNUNET_PQ_Context *db,
}
-/**
- * Within the @a db context, run all the SQL files
- * from the @a load_path from 0000-9999.sql (as long
- * as the files exist contiguously).
- *
- * @param db database context to use
- * @param load_path where to find the XXXX.sql files
- * @return #GNUNET_OK on success
- */
enum GNUNET_GenericReturnValue
GNUNET_PQ_run_sql (struct GNUNET_PQ_Context *db,
const char *load_path)
@@ -304,11 +276,6 @@ GNUNET_PQ_run_sql (struct GNUNET_PQ_Context *db,
}
-/**
- * Reinitialize the database @a db if the connection is down.
- *
- * @param db database connection to reinitialize
- */
void
GNUNET_PQ_reconnect_if_down (struct GNUNET_PQ_Context *db)
{
@@ -321,14 +288,11 @@ GNUNET_PQ_reconnect_if_down (struct GNUNET_PQ_Context *db)
}
-/**
- * Reinitialize the database @a db.
- *
- * @param db database connection to reinitialize
- */
void
GNUNET_PQ_reconnect (struct GNUNET_PQ_Context *db)
{
+ GNUNET_PQ_event_reconnect_ (db,
+ -1);
if (NULL != db->conn)
PQfinish (db->conn);
db->conn = PQconnectdb (db->config_str);
@@ -380,7 +344,7 @@ GNUNET_PQ_reconnect (struct GNUNET_PQ_Context *db)
0);
if (GNUNET_NO == ret)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"Failed to find SQL file to load database versioning logic\n");
PQfinish (db->conn);
db->conn = NULL;
@@ -448,26 +412,11 @@ GNUNET_PQ_reconnect (struct GNUNET_PQ_Context *db)
db->conn = NULL;
return;
}
+ GNUNET_PQ_event_reconnect_ (db,
+ PQsocket (db->conn));
}
-/**
- * Connect to a postgres database using the configuration
- * option "CONFIG" in @a section. Also ensures that the
- * statements in @a es are executed whenever we (re)connect to the
- * database, and that the prepared statements in @a ps are "ready".
- *
- * The caller does not have to ensure that @a es and @a ps remain allocated
- * and initialized in memory until #GNUNET_PQ_disconnect() is called, as a copy will be made.
- *
- * @param cfg configuration
- * @param section configuration section to use to get Postgres configuration options
- * @param load_path_suffix suffix to append to the SQL_DIR in the configuration
- * @param es #GNUNET_PQ_PREPARED_STATEMENT_END-terminated
- * array of statements to execute upon EACH connection, can be NULL
- * @param ps array of prepared statements to prepare, can be NULL
- * @return the postgres handle, NULL on error
- */
struct GNUNET_PQ_Context *
GNUNET_PQ_connect_with_cfg (const struct GNUNET_CONFIGURATION_Handle *cfg,
const char *section,
@@ -509,15 +458,14 @@ GNUNET_PQ_connect_with_cfg (const struct GNUNET_CONFIGURATION_Handle *cfg,
}
-/**
- * Disconnect from the database, destroying the prepared statements
- * and releasing other associated resources.
- *
- * @param db database handle to disconnect (will be free'd)
- */
void
GNUNET_PQ_disconnect (struct GNUNET_PQ_Context *db)
{
+ if (NULL == db)
+ return;
+ GNUNET_assert (0 ==
+ GNUNET_CONTAINER_multishortmap_size (db->channel_map));
+ GNUNET_CONTAINER_multishortmap_destroy (db->channel_map);
GNUNET_free (db->es);
GNUNET_free (db->ps);
GNUNET_free (db->load_path);
diff --git a/src/pq/pq_event.c b/src/pq/pq_event.c
index ecb942230..79a2e80c6 100644
--- a/src/pq/pq_event.c
+++ b/src/pq/pq_event.c
@@ -29,8 +29,8 @@
/**
* Handle for an active LISTENer to the database.
- */
-struct GNUNET_PQ_EventHandler
+ */
+struct GNUNET_DB_EventHandler
{
/**
* Channel name.
@@ -40,7 +40,7 @@ struct GNUNET_PQ_EventHandler
/**
* Function to call on events.
*/
- GNUNET_PQ_EventCallback cb;
+ GNUNET_DB_EventCallback cb;
/**
* Closure for @e cb.
@@ -51,9 +51,12 @@ struct GNUNET_PQ_EventHandler
* Database context this event handler is with.
*/
struct GNUNET_PQ_Context *db;
-};
-
+ /**
+ * Task to run on timeout.
+ */
+ struct GNUNET_SCHEDULER_Task *timeout_task;
+};
/**
@@ -63,7 +66,7 @@ struct GNUNET_PQ_EventHandler
* @param[out] sh short hash to set
*/
static void
-es_to_sh (const struct GNUNET_PQ_EventHeaderP *es,
+es_to_sh (const struct GNUNET_DB_EventHeaderP *es,
struct GNUNET_ShortHashCode *sh)
{
struct GNUNET_HashCode h_channel;
@@ -103,6 +106,24 @@ sh_to_channel (struct GNUNET_ShortHashCode *sh,
/**
+ * Convert @a sh to a Postgres identifier.
+ *
+ * @param identifier to convert
+ * @param[out] sh set to short hash
+ * @return #GNUNET_OK on success
+ */
+static enum GNUNET_GenericReturnValue
+channel_to_sh (const char *identifier,
+ struct GNUNET_ShortHashCode *sh)
+{
+ return GNUNET_STRINGS_string_to_data (identifier,
+ strlen (identifier),
+ sh,
+ sizeof (*sh));
+}
+
+
+/**
* Convert @a es to a Postgres identifier.
*
* @param es spec to hash to an identifier
@@ -111,7 +132,7 @@ sh_to_channel (struct GNUNET_ShortHashCode *sh,
* @return end position of the identifier
*/
static char *
-es_to_channel (const struct GNUNET_PQ_EventHeaderP *es,
+es_to_channel (const struct GNUNET_DB_EventHeaderP *es,
char identifier[64])
{
struct GNUNET_ShortHashCode sh;
@@ -141,12 +162,12 @@ struct NotifyContext
/**
- * Function called on every event handler that
+ * Function called on every event handler that
* needs to be triggered.
*
* @param cls a `struct NotifyContext`
* @param sh channel name
- * @param value a `struct GNUNET_PQ_EventHandler`
+ * @param value a `struct GNUNET_DB_EventHandler`
* @return #GNUNET_OK continue to iterate
*/
static int
@@ -155,45 +176,27 @@ do_notify (void *cls,
void *value)
{
struct NotifyContext *ctx = cls;
- struct GNUNET_PQ_EventHandler *eh = value;
+ struct GNUNET_DB_EventHandler *eh = value;
eh->cb (eh->cb_cls,
ctx->extra,
ctx->extra_size);
return GNUNET_OK;
-}
-
-
-void
-GNUNET_PQ_event_set_socket_callback (struct GNUNET_PQ_Context *db,
- GNUNET_PQ_SocketCallback sc,
- void *sc_cls)
-{
- int fd;
-
- db->sc = sc;
- db->sc_cls = sc_cls;
- if (NULL == sc)
- return;
- GNUNET_assert (0 ==
- pthread_mutex_lock (&db->notify_lock));
- fd = PQsocket (db->conn);
- if ( (-1 != fd) &&
- (0 != GNUNET_CONTAINER_multishortmap_size (db->channel_map)) )
- sc (sc_cls,
- fd);
- GNUNET_assert (0 ==
- pthread_mutex_unlock (&db->notify_lock));
}
-void
-GNUNET_PQ_event_do_poll (struct GNUNET_PQ_Context *db)
+static void
+event_do_poll (struct GNUNET_PQ_Context *db)
{
PGnotify *n;
- GNUNET_assert (0 ==
- pthread_mutex_lock (&db->notify_lock));
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "PG poll job active\n");
+ if (1 !=
+ PQconsumeInput (db->conn))
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to read from Postgres: %s\n",
+ PQerrorMessage (db->conn));
while (NULL != (n = PQnotifies (db->conn)))
{
struct GNUNET_ShortHashCode sh;
@@ -201,15 +204,22 @@ GNUNET_PQ_event_do_poll (struct GNUNET_PQ_Context *db)
.extra = NULL
};
+ if ('X' != toupper ((int) n->relname[0]))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Ignoring notification for unsupported channel identifier `%s'\n",
+ n->relname);
+ PQfreemem (n);
+ continue;
+ }
if (GNUNET_OK !=
- GNUNET_STRINGS_string_to_data (n->relname,
- strlen (n->relname),
- &sh,
- sizeof (sh)))
+ channel_to_sh (&n->relname[1],
+ &sh))
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"Ignoring notification for unsupported channel identifier `%s'\n",
n->relname);
+ PQfreemem (n);
continue;
}
if ( (NULL != n->extra) &&
@@ -223,36 +233,97 @@ GNUNET_PQ_event_do_poll (struct GNUNET_PQ_Context *db)
"Ignoring notification for unsupported extra data `%s' on channel `%s'\n",
n->extra,
n->relname);
+ PQfreemem (n);
continue;
}
- GNUNET_CONTAINER_multishortmap_iterate (db->channel_map,
- &do_notify,
- &ctx);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Received notification %s with extra data `%.*s'\n",
+ n->relname,
+ (int) ctx.extra_size,
+ (const char *) ctx.extra);
+ GNUNET_CONTAINER_multishortmap_get_multiple (db->channel_map,
+ &sh,
+ &do_notify,
+ &ctx);
GNUNET_free (ctx.extra);
+ PQfreemem (n);
}
- GNUNET_assert (0 ==
- pthread_mutex_unlock (&db->notify_lock));
}
-void
-GNUNET_PQ_event_scheduler_start (struct GNUNET_PQ_Context *db)
+/**
+ * The GNUnet scheduler notifies us that we need to
+ * trigger the DB event poller.
+ *
+ * @param cls a `struct GNUNET_PQ_Context *`
+ */
+static void
+do_scheduler_notify (void *cls)
{
- GNUNET_break (0); // FIXME: not implemented
+ struct GNUNET_PQ_Context *db = cls;
+
+ db->event_task = NULL;
+ GNUNET_assert (NULL != db->rfd);
+ event_do_poll (db);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Resubscribing\n");
+ db->event_task
+ = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ db->rfd,
+ &do_scheduler_notify,
+ db);
}
-void
-GNUNET_PQ_event_scheduler_stop (struct GNUNET_PQ_Context *db)
+/**
+ * Function called when the Postgres FD changes and we need
+ * to update the scheduler event loop task.
+ *
+ * @param cls a `struct GNUNET_PQ_Context *`
+ * @param fd the file descriptor, possibly -1
+ */
+static void
+scheduler_fd_cb (void *cls,
+ int fd)
{
- GNUNET_break (0); // FIXME: not implemented
+ struct GNUNET_PQ_Context *db = cls;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "New poll FD is %d\n",
+ fd);
+ if (NULL != db->event_task)
+ {
+ GNUNET_SCHEDULER_cancel (db->event_task);
+ db->event_task = NULL;
+ }
+ GNUNET_free (db->rfd);
+ if (-1 == fd)
+ return;
+ if (0 == GNUNET_CONTAINER_multishortmap_size (db->channel_map))
+ return;
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Activating poll job on %d\n",
+ fd);
+ db->rfd = GNUNET_NETWORK_socket_box_native (fd);
+ db->event_task
+ = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_ZERO,
+ db->rfd,
+ &do_scheduler_notify,
+ db);
}
+/**
+ * Helper function to trigger an SQL @a cmd on @a db
+ *
+ * @param db database to send command to
+ * @param cmd prefix of the command to send
+ * @param eh details about the event
+ */
static void
manage_subscribe (struct GNUNET_PQ_Context *db,
const char *cmd,
- struct GNUNET_PQ_EventHandler *eh)
+ struct GNUNET_DB_EventHandler *eh)
{
char sql[16 + 64];
char *end;
@@ -262,6 +333,9 @@ manage_subscribe (struct GNUNET_PQ_Context *db,
cmd);
end = sh_to_channel (&eh->sh,
end);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Executing PQ command `%s'\n",
+ sql);
result = PQexec (db->conn,
sql);
if (PGRES_COMMAND_OK != PQresultStatus (result))
@@ -282,76 +356,134 @@ manage_subscribe (struct GNUNET_PQ_Context *db,
}
-struct GNUNET_PQ_EventHandler *
+/**
+ * Re-subscribe to notifications after disconnect.
+ *
+ * @param cls the DB context
+ * @param sh the short hash of the channel
+ * @param eh the event handler
+ * @return #GNUNET_OK to continue to iterate
+ */
+static int
+register_notify (void *cls,
+ const struct GNUNET_ShortHashCode *sh,
+ void *value)
+{
+ struct GNUNET_PQ_Context *db = cls;
+ struct GNUNET_DB_EventHandler *eh = value;
+
+ manage_subscribe (db,
+ "LISTEN X",
+ eh);
+ return GNUNET_OK;
+}
+
+
+void
+GNUNET_PQ_event_reconnect_ (struct GNUNET_PQ_Context *db,
+ int fd)
+{
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Change in PQ event FD to %d\n",
+ fd);
+ scheduler_fd_cb (db,
+ fd);
+ GNUNET_CONTAINER_multishortmap_iterate (db->channel_map,
+ &register_notify,
+ db);
+}
+
+
+/**
+ * Function run on timeout for an event. Triggers
+ * the notification, but does NOT clear the handler.
+ *
+ * @param cls a `struct GNUNET_DB_EventHandler *`
+ */
+static void
+event_timeout (void *cls)
+{
+ struct GNUNET_DB_EventHandler *eh = cls;
+
+ eh->timeout_task = NULL;
+ eh->cb (eh->cb_cls,
+ NULL,
+ 0);
+}
+
+
+struct GNUNET_DB_EventHandler *
GNUNET_PQ_event_listen (struct GNUNET_PQ_Context *db,
- const struct GNUNET_PQ_EventHeaderP *es,
- GNUNET_PQ_EventCallback cb,
+ const struct GNUNET_DB_EventHeaderP *es,
+ struct GNUNET_TIME_Relative timeout,
+ GNUNET_DB_EventCallback cb,
void *cb_cls)
{
- struct GNUNET_PQ_EventHandler *eh;
- bool was_zero;
+ struct GNUNET_DB_EventHandler *eh;
- eh = GNUNET_new (struct GNUNET_PQ_EventHandler);
+ eh = GNUNET_new (struct GNUNET_DB_EventHandler);
eh->db = db;
es_to_sh (es,
&eh->sh);
eh->cb = cb;
eh->cb_cls = cb_cls;
- GNUNET_assert (0 ==
- pthread_mutex_lock (&db->notify_lock));
- was_zero = (0 == GNUNET_CONTAINER_multishortmap_size (db->channel_map));
GNUNET_assert (GNUNET_OK ==
GNUNET_CONTAINER_multishortmap_put (db->channel_map,
- &eh->sh,
- eh,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
- if ( (NULL != db->sc) &&
- was_zero)
+ &eh->sh,
+ eh,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
+ if (NULL == db->event_task)
{
- int fd = PQsocket (db->conn);
-
- if (-1 != fd)
- db->sc (db->sc_cls,
- fd);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Starting event scheduler\n");
+ scheduler_fd_cb (db,
+ PQsocket (db->conn));
}
manage_subscribe (db,
- "LISTEN ",
+ "LISTEN X",
eh);
- GNUNET_assert (0 ==
- pthread_mutex_unlock (&db->notify_lock));
+ eh->timeout_task = GNUNET_SCHEDULER_add_delayed (timeout,
+ &event_timeout,
+ eh);
return eh;
}
void
-GNUNET_PQ_event_listen_cancel (struct GNUNET_PQ_EventHandler *eh)
+GNUNET_PQ_event_listen_cancel (struct GNUNET_DB_EventHandler *eh)
{
struct GNUNET_PQ_Context *db = eh->db;
- GNUNET_assert (0 ==
- pthread_mutex_lock (&db->notify_lock));
GNUNET_assert (GNUNET_OK ==
GNUNET_CONTAINER_multishortmap_remove (db->channel_map,
- &eh->sh,
- eh));
-
+ &eh->sh,
+ eh));
manage_subscribe (db,
- "UNLISTEN ",
+ "UNLISTEN X",
eh);
- if ( (NULL != db->sc) &&
- (0 == GNUNET_CONTAINER_multishortmap_size (db->channel_map)) )
+ if (0 == GNUNET_CONTAINER_multishortmap_size (db->channel_map))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Stopping PQ event scheduler job\n");
+ GNUNET_free (db->rfd);
+ if (NULL != db->event_task)
+ {
+ GNUNET_SCHEDULER_cancel (db->event_task);
+ db->event_task = NULL;
+ }
+ }
+ if (NULL != eh->timeout_task)
{
- db->sc (db->sc_cls,
- -1);
+ GNUNET_SCHEDULER_cancel (eh->timeout_task);
+ eh->timeout_task = NULL;
}
- GNUNET_assert (0 ==
- pthread_mutex_unlock (&db->notify_lock));
+ GNUNET_free (eh);
}
void
GNUNET_PQ_event_notify (struct GNUNET_PQ_Context *db,
- const struct GNUNET_PQ_EventHeaderP *es,
+ const struct GNUNET_DB_EventHeaderP *es,
const void *extra,
size_t extra_size)
{
@@ -360,11 +492,11 @@ GNUNET_PQ_event_notify (struct GNUNET_PQ_Context *db,
PGresult *result;
end = stpcpy (sql,
- "NOTIFY ");
+ "NOTIFY X");
end = es_to_channel (es,
end);
end = stpcpy (end,
- "'");
+ ", '");
end = GNUNET_STRINGS_data_to_string (extra,
extra_size,
end,
@@ -373,6 +505,9 @@ GNUNET_PQ_event_notify (struct GNUNET_PQ_Context *db,
*end = '\0';
end = stpcpy (end,
"'");
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Executing command `%s'\n",
+ sql);
result = PQexec (db->conn,
sql);
if (PGRES_COMMAND_OK != PQresultStatus (result))
@@ -390,7 +525,8 @@ GNUNET_PQ_event_notify (struct GNUNET_PQ_Context *db,
PQerrorMessage (db->conn));
}
PQclear (result);
+ event_do_poll (db);
}
-/* end of pq_event.c */
+/* end of pq_event.c */
diff --git a/src/pq/test_pq.c b/src/pq/test_pq.c
index e588da45d..90b5c6489 100644
--- a/src/pq/test_pq.c
+++ b/src/pq/test_pq.c
@@ -25,6 +25,26 @@
#include "platform.h"
#include "pq.h"
+/**
+ * Database handle.
+ */
+static struct GNUNET_PQ_Context *db;
+
+/**
+ * Global return value, 0 on success.
+ */
+static int ret;
+
+/**
+ * An event handler.
+ */
+static struct GNUNET_DB_EventHandler *eh;
+
+/**
+ * Timeout task.
+ */
+static struct GNUNET_SCHEDULER_Task *tt;
+
/**
* Setup prepared statements.
@@ -109,7 +129,7 @@ run_queries (struct GNUNET_PQ_Context *db)
uint64_t u64;
uint64_t u642;
uint64_t uzzz = 42;
-
+
priv = GNUNET_CRYPTO_rsa_private_key_create (1024);
pub = GNUNET_CRYPTO_rsa_private_key_get_public (priv);
memset (&hmsg, 42, sizeof(hmsg));
@@ -220,6 +240,91 @@ run_queries (struct GNUNET_PQ_Context *db)
}
+/**
+ * Task called on shutdown.
+ *
+ * @param cls NULL
+ */
+static void
+event_end (void *cls)
+{
+ GNUNET_PQ_event_listen_cancel (eh);
+ eh = NULL;
+ if (NULL != tt)
+ {
+ GNUNET_SCHEDULER_cancel (tt);
+ tt = NULL;
+ }
+}
+
+
+/**
+ * Task called on timeout. Should not happen, means
+ * we did not get the expected event.
+ *
+ * @param cls NULL
+ */
+static void
+timeout_cb (void *cls)
+{
+ ret = 2;
+ GNUNET_break (0);
+ tt = NULL;
+ GNUNET_SCHEDULER_shutdown ();
+}
+
+
+/**
+ * Task called on expected event
+ *
+ * @param cls NULL
+ */
+static void
+event_sched_cb (void *cls,
+ const void *extra,
+ size_t extra_size)
+{
+ GNUNET_assert (5 == extra_size);
+ GNUNET_assert (0 ==
+ memcmp ("hello",
+ extra,
+ 5));
+ GNUNET_SCHEDULER_shutdown ();
+}
+
+
+/**
+ * Run tests that need a scheduler.
+ *
+ * @param cls NULL
+ */
+static void
+sched_tests (void *cls)
+{
+ struct GNUNET_DB_EventHeaderP es = {
+ .size = htons (sizeof (es)),
+ .type = htons (42)
+ };
+
+
+ tt = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+ &timeout_cb,
+ NULL);
+ eh = GNUNET_PQ_event_listen (db,
+ &es,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ &event_sched_cb,
+ NULL);
+ GNUNET_PQ_reconnect (db);
+ GNUNET_SCHEDULER_add_shutdown (&event_end,
+ NULL);
+ GNUNET_PQ_event_notify (db,
+ &es,
+ "hello",
+ 5);
+}
+
+
int
main (int argc,
const char *const argv[])
@@ -239,11 +344,9 @@ main (int argc,
")"),
GNUNET_PQ_EXECUTE_STATEMENT_END
};
- struct GNUNET_PQ_Context *db;
- int ret;
GNUNET_log_setup ("test-pq",
- "WARNING",
+ "INFO",
NULL);
db = GNUNET_PQ_connect ("postgres:///gnunetcheck",
NULL,
@@ -272,12 +375,26 @@ main (int argc,
return 1;
}
ret = run_queries (db);
+ if (0 != ret)
+ {
+ GNUNET_break (0);
+ GNUNET_PQ_disconnect (db);
+ return ret;
+ }
+ GNUNET_SCHEDULER_run (&sched_tests,
+ NULL);
+ if (0 != ret)
+ {
+ GNUNET_break (0);
+ GNUNET_PQ_disconnect (db);
+ return ret;
+ }
#if TEST_RESTART
fprintf (stderr, "Please restart Postgres database now!\n");
sleep (60);
- ret = run_queries (db);
+ ret |= run_queries (db);
fprintf (stderr, "Result: %d (expect: 1 -- if you restarted the DB)\n", ret);
- ret = run_queries (db);
+ ret |= run_queries (db);
fprintf (stderr, "Result: %d (expect: 0)\n", ret);
#endif
{
diff --git a/src/reclaim/Makefile.am b/src/reclaim/Makefile.am
index 1a0b7fae4..350d77d4b 100644
--- a/src/reclaim/Makefile.am
+++ b/src/reclaim/Makefile.am
@@ -61,14 +61,6 @@ libgnunet_plugin_rest_reclaim_la_LIBADD = \
$(top_builddir)/src/namestore/libgnunetnamestore.la \
$(top_builddir)/src/util/libgnunetutil.la $(XLIBS) \
$(LTLIBINTL) -ljansson $(MHD_LIBS)
-libgnunet_plugin_rest_reclaim_la_DEPENDENCIES = \
- $(top_builddir)/src/identity/libgnunetidentity.la \
- libgnunetreclaim.la \
- $(top_builddir)/src/json/libgnunetjson.la \
- $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \
- $(top_builddir)/src/rest/libgnunetrest.la \
- $(top_builddir)/src/namestore/libgnunetnamestore.la \
- $(top_builddir)/src/util/libgnunetutil.la
libgnunet_plugin_rest_reclaim_la_LDFLAGS = \
$(GN_PLUGIN_LDFLAGS)
libgnunet_plugin_rest_reclaim_la_CFLAGS = $(MHD_CFLAGS) $(AM_CFLAGS)
@@ -102,11 +94,6 @@ libgnunet_plugin_rest_pabc_la_LIBADD = \
$(top_builddir)/src/rest/libgnunetrest.la \
$(top_builddir)/src/util/libgnunetutil.la $(XLIBS) \
$(LTLIBINTL) -ljansson -lpabc $(MHD_LIBS)
-libgnunet_plugin_rest_pabc_la_DEPENDENCIES = \
- libgnunetreclaim.la \
- $(top_builddir)/src/json/libgnunetjson.la \
- $(top_builddir)/src/rest/libgnunetrest.la \
- $(top_builddir)/src/util/libgnunetutil.la
libgnunet_plugin_rest_pabc_la_LDFLAGS = \
$(GN_PLUGIN_LDFLAGS)
libgnunet_plugin_rest_pabc_la_CFLAGS = $(MHD_CFLAGS) $(AM_CFLAGS)
diff --git a/src/regex/Makefile.am b/src/regex/Makefile.am
index 13413f242..9a7466cb2 100644
--- a/src/regex/Makefile.am
+++ b/src/regex/Makefile.am
@@ -53,9 +53,6 @@ libgnunetregex_internal_a_SOURCES = \
regex_internal_lib.h \
regex_internal.h regex_internal.c \
regex_internal_dht.c
-libgnunetregex_internal_a_DEPENDENCIES = \
- libgnunetregexblock.la
-
libgnunetregex_la_SOURCES = \
regex_api_announce.c \
@@ -126,6 +123,7 @@ gnunet_regex_profiler_SOURCES = \
gnunet-regex-profiler.c
gnunet_regex_profiler_LDADD = -lm \
$(top_builddir)/src/arm/libgnunetarm.la \
+ $(top_builddir)/src/testing/libgnunettesting.la \
$(top_builddir)/src/testbed/libgnunettestbed.la \
libgnunetregex_internal.a \
$(top_builddir)/src/dht/libgnunetdht.la \
diff --git a/src/rest/plugin_rest_config.c b/src/rest/plugin_rest_config.c
index af833efff..b0f18754c 100644
--- a/src/rest/plugin_rest_config.c
+++ b/src/rest/plugin_rest_config.c
@@ -91,7 +91,6 @@ static struct RequestHandle *requests_head;
static struct RequestHandle *requests_tail;
-
/**
* Cleanup request handle.
*
@@ -199,7 +198,9 @@ get_cont (struct GNUNET_REST_RequestHandle *con_handle,
}
response = json_dumps (result, 0);
resp = GNUNET_REST_create_response (response);
- MHD_add_response_header (resp, "Content-Type", "application/json");
+ GNUNET_assert (MHD_NO != MHD_add_response_header (resp,
+ "Content-Type",
+ "application/json"));
handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
cleanup_handle (handle);
GNUNET_free (response);
@@ -334,6 +335,7 @@ set_cont (struct GNUNET_REST_RequestHandle *con_handle,
handle->proc (handle->proc_cls,
GNUNET_REST_create_response (NULL),
MHD_HTTP_OK);
+ GNUNET_free (cfg_fn);
cleanup_handle (handle);
}
@@ -352,9 +354,9 @@ options_cont (struct GNUNET_REST_RequestHandle *con_handle,
struct RequestHandle *handle = cls;
resp = GNUNET_REST_create_response (NULL);
- MHD_add_response_header (resp,
- "Access-Control-Allow-Methods",
- MHD_HTTP_METHOD_GET);
+ GNUNET_assert (MHD_NO != MHD_add_response_header (resp,
+ "Access-Control-Allow-Methods",
+ MHD_HTTP_METHOD_GET));
handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
cleanup_handle (handle);
}
@@ -424,7 +426,7 @@ libgnunet_plugin_rest_config_init (void *cls)
api->cls = &plugin;
api->name = GNUNET_REST_API_NS_CONFIG;
api->process_request = &rest_config_process_request;
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("CONFIG REST API initialized\n"));
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ ("CONFIG REST API initialized\n"));
return api;
}
diff --git a/src/revocation/Makefile.am b/src/revocation/Makefile.am
index b1a079a0d..d0c58584e 100644
--- a/src/revocation/Makefile.am
+++ b/src/revocation/Makefile.am
@@ -32,11 +32,6 @@ libgnunet_plugin_block_revocation_la_LIBADD = \
$(top_builddir)/src/util/libgnunetutil.la \
$(top_builddir)/src/identity/libgnunetidentity.la \
$(LTLIBINTL)
-libgnunet_plugin_block_revocation_la_DEPENDENCIES = \
- libgnunetrevocation.la \
- $(top_builddir)/src/block/libgnunetblockgroup.la \
- $(top_builddir)/src/block/libgnunetblock.la \
- $(top_builddir)/src/util/libgnunetutil.la
libgnunet_plugin_block_revocation_la_LDFLAGS = \
$(GN_PLUGIN_LDFLAGS)
diff --git a/src/revocation/gnunet-service-revocation.c b/src/revocation/gnunet-service-revocation.c
index 2d8111adb..5fe0ade98 100644
--- a/src/revocation/gnunet-service-revocation.c
+++ b/src/revocation/gnunet-service-revocation.c
@@ -949,6 +949,7 @@ run (void *cls,
if (0 > ksize)
{
GNUNET_break_op (0);
+ GNUNET_free (rm);
GNUNET_free (fn);
return;
}
diff --git a/src/secretsharing/Makefile.am b/src/secretsharing/Makefile.am
index 787cfa0c1..9ae6e7892 100644
--- a/src/secretsharing/Makefile.am
+++ b/src/secretsharing/Makefile.am
@@ -24,6 +24,7 @@ gnunet_secretsharing_profiler_SOURCES = \
gnunet-secretsharing-profiler.c
gnunet_secretsharing_profiler_LDADD = \
libgnunetsecretsharing.la \
+ $(top_builddir)/src/testing/libgnunettesting.la \
$(top_builddir)/src/testbed/libgnunettestbed.la \
$(top_builddir)/src/util/libgnunetutil.la \
$(GN_LIBINTL)
diff --git a/src/set/ibf.c b/src/set/ibf.c
index 1532afceb..0f7eb6a9f 100644
--- a/src/set/ibf.c
+++ b/src/set/ibf.c
@@ -294,7 +294,7 @@ ibf_write_slice (const struct InvertibleBloomFilter *ibf, uint32_t start,
struct IBF_KeyHash *key_hash_dst;
struct IBF_Count *count_dst;
- GNUNET_assert (start + count <= ibf->size);
+ GNUNET_assert (start + count <= ibf->size);
/* copy keys */
key_dst = (struct IBF_Key *) buf;
diff --git a/src/set/ibf.h b/src/set/ibf.h
index 7c2ab33b1..334a797ef 100644
--- a/src/set/ibf.h
+++ b/src/set/ibf.h
@@ -245,6 +245,7 @@ void
ibf_destroy (struct InvertibleBloomFilter *ibf);
+
#if 0 /* keep Emacsens' auto-indent happy */
{
#endif
diff --git a/src/setu/gnunet-service-setu.c b/src/setu/gnunet-service-setu.c
index bd1113f15..339d347f8 100644
--- a/src/setu/gnunet-service-setu.c
+++ b/src/setu/gnunet-service-setu.c
@@ -22,6 +22,7 @@
* @brief set union operation
* @author Florian Dold
* @author Christian Grothoff
+ * @author Elias Summermatter
*/
#include "platform.h"
#include "gnunet_util_lib.h"
@@ -50,33 +51,61 @@
*/
#define SE_STRATA_COUNT 32
+
/**
- * Size of the IBFs in the strata estimator.
+ * Primes for all 4 different strata estimators 61,67,71,73,79,83,89,97 348
+ * Based on the bsc thesis of Elias Summermatter (2021)
*/
-#define SE_IBF_SIZE 80
+#define SE_IBFS_TOTAL_SIZE 632
/**
* The hash num parameter for the difference digests and strata estimators.
*/
-#define SE_IBF_HASH_NUM 4
+#define SE_IBF_HASH_NUM 3
/**
* Number of buckets that can be transmitted in one message.
*/
-#define MAX_BUCKETS_PER_MESSAGE ((1 << 15) / IBF_BUCKET_SIZE)
+#define MAX_BUCKETS_PER_MESSAGE ((1 << 16) / IBF_BUCKET_SIZE)
/**
- * The maximum size of an ibf we use is 2^(MAX_IBF_ORDER).
+ * The maximum size of an ibf we use is MAX_IBF_SIZE=2^20.
* Choose this value so that computing the IBF is still cheaper
* than transmitting all values.
*/
-#define MAX_IBF_ORDER (20)
+#define MAX_IBF_SIZE 1048576
+
+
+/**
+ * Minimal size of an ibf
+ * Based on the bsc thesis of Elias Summermatter (2021)
+ */
+#define IBF_MIN_SIZE 37
+
+/**
+ * AVG RTT for differential sync when k=2 and Factor = 2
+ * Based on the bsc thesis of Elias Summermatter (2021)
+ */
+#define DIFFERENTIAL_RTT_MEAN 3.65145
+
+/**
+ * Security level used for byzantine checks (2^80)
+ */
+
+#define SECURITY_LEVEL 80
+
+/**
+ * Is the estimated probability for a new round this values
+ * is based on the bsc thesis of Elias Summermatter (2021)
+ */
+
+#define PROBABILITY_FOR_NEW_ROUND 0.15
/**
- * Number of buckets used in the ibf per estimated
- * difference.
+ * Measure the performance in a csv
*/
-#define IBF_ALPHA 4
+
+#define MEASURE_PERFORMANCE 0
/**
@@ -146,6 +175,28 @@ enum UnionOperationPhase
PHASE_FULL_RECEIVING
};
+/**
+ * Different modes of operations
+ */
+
+enum MODE_OF_OPERATION
+{
+ /**
+ * Mode just synchronizes the difference between sets
+ */
+ DIFFERENTIAL_SYNC,
+
+ /**
+ * Mode send full set sending local set first
+ */
+ FULL_SYNC_LOCAL_SENDING_FIRST,
+
+ /**
+ * Mode request full set from remote peer
+ */
+ FULL_SYNC_REMOTE_SENDING_FIRST
+};
+
/**
* Information about an element element in the set. All elements are
@@ -277,7 +328,7 @@ struct Operation
* Copy of the set's strata estimator at the time of
* creation of this operation.
*/
- struct StrataEstimator *se;
+ struct MultiStrataEstimator *se;
/**
* The IBF we currently receive.
@@ -320,7 +371,7 @@ struct Operation
/**
* Number of ibf buckets already received into the @a remote_ibf.
*/
- unsigned int ibf_buckets_received;
+ uint64_t ibf_buckets_received;
/**
* Salt that we're using for sending IBFs
@@ -386,7 +437,7 @@ struct Operation
* Lower bound for the set size, used only when
* byzantine mode is enabled.
*/
- int byzantine_lower_bound;
+ uint64_t byzantine_lower_bound;
/**
* Unique request id for the request from a remote peer, sent to the
@@ -401,21 +452,83 @@ struct Operation
*/
unsigned int generation_created;
+
+ /**
+ * User defined Bandwidth Round Trips Tradeoff
+ */
+ uint64_t rtt_bandwidth_tradeoff;
+
+
+ /**
+ * Number of Element per bucket in IBF
+ */
+ uint8_t ibf_number_buckets_per_element;
+
+
+ /**
+ * Set difference is multiplied with this factor
+ * to gennerate large enough IBF
+ */
+ uint8_t ibf_bucket_number_factor;
+
+ /**
+ * Defines which site a client is
+ * 0 = Initiating peer
+ * 1 = Receiving peer
+ */
+ uint8_t peer_site;
+
+
/**
- * User defined Bandwidth Round Trips Tradeoff
+ * Local peer element count
*/
- double rtt_bandwidth_tradeoff;
+ uint64_t local_element_count;
/**
- * Number of Element per bucket in IBF
+ * Mode of operation that was chosen by the algorithm
*/
- unsigned int ibf_number_buckets_per_element;
+ uint8_t mode_of_operation;
/**
- * Number of buckets in IBF
+ * Hashmap to keep track of the send/received messages
*/
- unsigned ibf_bucket_number;
+ struct GNUNET_CONTAINER_MultiHashMap *message_control_flow;
+ /**
+ * Hashmap to keep track of the send/received inquiries (ibf keys)
+ */
+ struct GNUNET_CONTAINER_MultiHashMap *inquiries_sent;
+
+
+ /**
+ * Total size of local set
+ */
+ uint64_t total_elements_size_local;
+
+ /**
+ * Limit of number of elements in set
+ */
+ uint64_t byzantine_upper_bound;
+
+ /**
+ * is the count of already passed differential sync iterations
+ */
+ uint8_t differential_sync_iterations;
+
+ /**
+ * Estimated or committed set difference at the start
+ */
+ uint64_t remote_set_diff;
+
+ /**
+ * Estimated or committed set difference at the start
+ */
+ uint64_t local_set_diff;
+
+ /**
+ * Boolean to enforce an active passive switch
+ */
+ bool active_passive_switch_required;
};
@@ -431,6 +544,16 @@ struct SetContent
struct GNUNET_CONTAINER_MultiHashMap *elements;
/**
+ * Maps `struct GNUNET_HashCode *` to `struct ElementEntry *` randomized.
+ */
+ struct GNUNET_CONTAINER_MultiHashMap *elements_randomized;
+
+ /**
+ * Salt to construct the randomized element map
+ */
+ uint64_t elements_randomized_salt;
+
+ /**
* Number of references to the content.
*/
unsigned int refcount;
@@ -478,7 +601,7 @@ struct Set
* The strata estimator is only generated once for each set. The IBF keys
* are derived from the element hashes with salt=0.
*/
- struct StrataEstimator *se;
+ struct MultiStrataEstimator *se;
/**
* Evaluate operations are held in a linked list.
@@ -635,96 +758,687 @@ static int in_shutdown;
*/
static uint32_t suggest_id;
+#if MEASURE_PERFORMANCE
+/**
+ * Handles configuration file for setu performance test
+ *
+ */
+static const struct GNUNET_CONFIGURATION_Handle *setu_cfg;
+
+
+/**
+ * Stores the performance data for induvidual message
+ */
+
+
+struct perf_num_send_received_msg
+{
+ uint64_t sent;
+ uint64_t sent_var_bytes;
+ uint64_t received;
+ uint64_t received_var_bytes;
+};
+
+/**
+ * Main struct to measure performance (data/rtts)
+ */
+struct per_store_struct
+{
+ struct perf_num_send_received_msg operation_request;
+ struct perf_num_send_received_msg se;
+ struct perf_num_send_received_msg request_full;
+ struct perf_num_send_received_msg element_full;
+ struct perf_num_send_received_msg full_done;
+ struct perf_num_send_received_msg ibf;
+ struct perf_num_send_received_msg inquery;
+ struct perf_num_send_received_msg element;
+ struct perf_num_send_received_msg demand;
+ struct perf_num_send_received_msg offer;
+ struct perf_num_send_received_msg done;
+ struct perf_num_send_received_msg over;
+ uint64_t se_diff;
+ uint64_t se_diff_remote;
+ uint64_t se_diff_local;
+ uint64_t active_passive_switches;
+ uint8_t mode_of_operation;
+};
+
+struct per_store_struct perf_store;
+#endif
+
+/**
+ * Different states to control the messages flow in differential mode
+ */
+
+enum MESSAGE_CONTROL_FLOW_STATE
+{
+ /**
+ * Initial message state
+ */
+ MSG_CFS_UNINITIALIZED,
+
+ /**
+ * Track that a message has been sent
+ */
+ MSG_CFS_SENT,
+
+ /**
+ * Track that receiving this message is expected
+ */
+ MSG_CFS_EXPECTED,
+
+ /**
+ * Track that message has been received
+ */
+ MSG_CFS_RECEIVED,
+};
/**
- * Added Roundtripscounter
+ * Message types to track in message control flow
*/
+enum MESSAGE_TYPE
+{
+ /**
+ * Offer message type
+ */
+ OFFER_MESSAGE,
-struct perf_num_send_resived_msg {
- int sent;
- int sent_var_bytes;
- int received;
- int received_var_bytes;
+ /**
+ * Demand message type
+ */
+ DEMAND_MESSAGE,
+
+ /**
+ * Element message type
+ */
+ ELEMENT_MESSAGE,
};
-struct perf_rtt_struct
-{
- struct perf_num_send_resived_msg operation_request;
- struct perf_num_send_resived_msg se;
- struct perf_num_send_resived_msg request_full;
- struct perf_num_send_resived_msg element_full;
- struct perf_num_send_resived_msg full_done;
- struct perf_num_send_resived_msg ibf;
- struct perf_num_send_resived_msg inquery;
- struct perf_num_send_resived_msg element;
- struct perf_num_send_resived_msg demand;
- struct perf_num_send_resived_msg offer;
- struct perf_num_send_resived_msg done;
- struct perf_num_send_resived_msg over;
+/**
+ * Struct to tracked messages in message control flow
+ */
+struct messageControlFlowElement
+{
+ /**
+ * Track the message control state of the offer message
+ */
+ enum MESSAGE_CONTROL_FLOW_STATE offer;
+ /**
+ * Track the message control state of the demand message
+ */
+ enum MESSAGE_CONTROL_FLOW_STATE demand;
+ /**
+ * Track the message control state of the element message
+ */
+ enum MESSAGE_CONTROL_FLOW_STATE element;
};
-struct perf_rtt_struct perf_rtt;
+#if MEASURE_PERFORMANCE
+/**
+ * Loads different configuration to perform performance tests
+ *
+ * @param op operation handle
+ */
+static void
+load_config (struct Operation *op)
+{
+ long long number;
+ float fl;
+
+ setu_cfg = GNUNET_CONFIGURATION_create ();
+ GNUNET_CONFIGURATION_load (setu_cfg,
+ "perf_setu.conf");
+ GNUNET_CONFIGURATION_get_value_float (setu_cfg,
+ "IBF",
+ "BUCKET_NUMBER_FACTOR",
+ &fl);
+ op->ibf_bucket_number_factor = fl;
+ GNUNET_CONFIGURATION_get_value_number (setu_cfg,
+ "IBF",
+ "NUMBER_PER_BUCKET",
+ &number);
+ op->ibf_number_buckets_per_element = number;
+ GNUNET_CONFIGURATION_get_value_number (setu_cfg,
+ "PERFORMANCE",
+ "TRADEOFF",
+ &number);
+ op->rtt_bandwidth_tradeoff = number;
+ GNUNET_CONFIGURATION_get_value_number (setu_cfg,
+ "BOUNDARIES",
+ "UPPER_ELEMENT",
+ &number);
+ op->byzantine_upper_bound = number;
+ op->peer_site = 0;
+}
+
+
+/**
+ * Function to calculate total bytes used for performance measurement
+ * @param size
+ * @param perf_num_send_received_msg
+ * @return bytes used
+ */
static int
-sum_sent_received_bytes(int size, struct perf_num_send_resived_msg perf_rtt_struct) {
- return (size * perf_rtt_struct.sent) +
- (size * perf_rtt_struct.received) +
- perf_rtt_struct.sent_var_bytes +
- perf_rtt_struct.received_var_bytes;
+sum_sent_received_bytes (uint64_t size,
+ struct perf_num_send_received_msg
+ perf_num_send_received_msg)
+{
+ return (size * perf_num_send_received_msg.sent)
+ + (size * perf_num_send_received_msg.received)
+ + perf_num_send_received_msg.sent_var_bytes
+ + perf_num_send_received_msg.received_var_bytes;
}
-static float
-calculate_perf_rtt() {
- /**
- * Calculate RTT of init phase normally always 1
- */
- float rtt = 1;
- int bytes_transmitted = 0;
- /**
- * Calculate RGNUNET_SETU_AcceptMessageRT of Fullsync normally 1 or 1.5 depending
- */
- if (( perf_rtt.element_full.received != 0 ) ||
- ( perf_rtt.element_full.sent != 0)
- ) rtt += 1;
+/**
+ * Function that calculates the perfmance values and writes them down
+ */
+static void
+calculate_perf_store ()
+{
- if (( perf_rtt.request_full.received != 0 ) ||
- ( perf_rtt.request_full.sent != 0)
- ) rtt += 0.5;
+ /**
+ * Calculate RTT of init phase normally always 1
+ */
+ float rtt = 1;
+ int bytes_transmitted = 0;
- /**
- * In case of a differential sync 3 rtt's are needed.
- * for every active/passive switch additional 3.5 rtt's are used
- */
+ /**
+ * Calculate RGNUNET_SETU_AcceptMessageRT of Fullsync normally 1 or 1.5 depending
+ */
+ if ((perf_store.element_full.received != 0) ||
+ (perf_store.element_full.sent != 0)
+ )
+ rtt += 1;
+
+ if ((perf_store.request_full.received != 0) ||
+ (perf_store.request_full.sent != 0)
+ )
+ rtt += 0.5;
- int iterations = perf_rtt.ibf.received;
- if(iterations > 1)
- rtt += (iterations - 1 ) * 0.5;
- rtt += 3 * iterations;
+ /**
+ * In case of a differential sync 3 rtt's are needed.
+ * for every active/passive switch additional 3.5 rtt's are used
+ */
+ if ((perf_store.element.received != 0) ||
+ (perf_store.element.sent != 0))
+ {
+ int iterations = perf_store.active_passive_switches;
+
+ if (iterations > 0)
+ rtt += iterations * 0.5;
+ rtt += 2.5;
+ }
+
+
+ /**
+ * Calculate data sended size
+ */
+ bytes_transmitted += sum_sent_received_bytes (sizeof(struct
+ GNUNET_SETU_ResultMessage),
+ perf_store.request_full);
+
+ bytes_transmitted += sum_sent_received_bytes (sizeof(struct
+ GNUNET_SETU_ElementMessage),
+ perf_store.element_full);
+ bytes_transmitted += sum_sent_received_bytes (sizeof(struct
+ GNUNET_SETU_ElementMessage),
+ perf_store.element);
+ // bytes_transmitted += sum_sent_received_bytes(sizeof(GNUNET_MESSAGE_TYPE_SETU_P2P_OPERATION_REQUEST), perf_store.operation_request);
+ bytes_transmitted += sum_sent_received_bytes (sizeof(struct
+ StrataEstimatorMessage),
+ perf_store.se);
+ bytes_transmitted += sum_sent_received_bytes (4, perf_store.full_done);
+ bytes_transmitted += sum_sent_received_bytes (sizeof(struct IBFMessage),
+ perf_store.ibf);
+ bytes_transmitted += sum_sent_received_bytes (sizeof(struct InquiryMessage),
+ perf_store.inquery);
+ bytes_transmitted += sum_sent_received_bytes (sizeof(struct
+ GNUNET_MessageHeader),
+ perf_store.demand);
+ bytes_transmitted += sum_sent_received_bytes (sizeof(struct
+ GNUNET_MessageHeader),
+ perf_store.offer);
+ bytes_transmitted += sum_sent_received_bytes (4, perf_store.done);
+
+ /**
+ * Write IBF failure rate for different BUCKET_NUMBER_FACTOR
+ */
+ float factor;
+ GNUNET_CONFIGURATION_get_value_float (setu_cfg,"IBF", "BUCKET_NUMBER_FACTOR",
+ &factor);
+ long long num_per_bucket;
+ GNUNET_CONFIGURATION_get_value_number (setu_cfg,"IBF", "NUMBER_PER_BUCKET",
+ &num_per_bucket);
+
+
+ int decoded = 0;
+ if (perf_store.active_passive_switches == 0)
+ decoded = 1;
+ int ibf_bytes_transmitted = sum_sent_received_bytes (sizeof(struct
+ IBFMessage),
+ perf_store.ibf);
+
+ FILE *out1 = fopen ("perf_data.csv", "a");
+ fprintf (out1, "%d,%f,%d,%d,%f,%d,%d,%d,%d,%d\n",num_per_bucket,factor,
+ decoded,ibf_bytes_transmitted,rtt,perf_store.se_diff,
+ bytes_transmitted,
+ perf_store.se_diff_local,perf_store.se_diff_remote,
+ perf_store.mode_of_operation);
+ fclose (out1);
+
+}
+
+
+#endif
+/**
+ * Function that chooses the optimal mode of operation depending on
+ * operation parameters.
+ * @param avg_element_size
+ * @param local_set_size
+ * @param remote_set_size
+ * @param est_set_diff_remote
+ * @param est_set_diff_local
+ * @param bandwith_latency_tradeoff
+ * @param ibf_bucket_number_factor
+ * @return calcuated mode of operation
+ */
+static uint8_t
+estimate_best_mode_of_operation (uint64_t avg_element_size,
+ uint64_t local_set_size,
+ uint64_t remote_set_size,
+ uint64_t est_set_diff_remote,
+ uint64_t est_set_diff_local,
+ uint64_t bandwith_latency_tradeoff,
+ uint64_t ibf_bucket_number_factor)
+{
+
+ /*
+ * In case of initial sync fall to predefined states
+ */
+
+ if (0 == local_set_size)
+ return FULL_SYNC_REMOTE_SENDING_FIRST;
+ if (0 == remote_set_size)
+ return FULL_SYNC_LOCAL_SENDING_FIRST;
+
+ /*
+ * Calculate bytes for full Sync
+ */
+
+ uint8_t sizeof_full_done_header = 4;
+ uint8_t sizeof_done_header = 4;
+ uint8_t rtt_min_full = 2;
+ uint8_t sizeof_request_full = 4;
+ uint64_t estimated_total_diff = (est_set_diff_remote + est_set_diff_local);
+
+ /* Estimate byte required if we send first */
+ uint64_t total_elements_to_send_local_send_first = est_set_diff_remote
+ + local_set_size;
+
+ uint64_t total_bytes_full_local_send_first = (avg_element_size
+ *
+ total_elements_to_send_local_send_first) \
+ + (
+ total_elements_to_send_local_send_first * sizeof(struct
+ GNUNET_SETU_ElementMessage)) \
+ + (sizeof_full_done_header * 2) \
+ + rtt_min_full
+ * bandwith_latency_tradeoff;
+
+ /* Estimate bytes required if we request from remote peer */
+ uint64_t total_elements_to_send_remote_send_first = est_set_diff_local
+ + remote_set_size;
+
+ uint64_t total_bytes_full_remote_send_first = (avg_element_size
+ *
+ total_elements_to_send_remote_send_first) \
+ + (
+ total_elements_to_send_remote_send_first * sizeof(struct
+ GNUNET_SETU_ElementMessage)) \
+ + (sizeof_full_done_header * 2) \
+ + (rtt_min_full + 0.5)
+ * bandwith_latency_tradeoff \
+ + sizeof_request_full;
+
+ /*
+ * Calculate bytes for differential Sync
+ */
+
+ /* Estimate bytes required by IBF transmission*/
+
+ long double ibf_bucket_count = estimated_total_diff
+ * ibf_bucket_number_factor;
+
+ if (ibf_bucket_count <= IBF_MIN_SIZE)
+ {
+ ibf_bucket_count = IBF_MIN_SIZE;
+ }
+ uint64_t ibf_message_count = ceil ( ((float) ibf_bucket_count)
+ / ((float) MAX_BUCKETS_PER_MESSAGE));
+
+ uint64_t estimated_counter_size = ceil (
+ MIN (2 * log2l (((float) local_set_size)
+ / ((float) ibf_bucket_count)),
+ log2l (local_set_size)));
+
+ long double counter_bytes = (float) estimated_counter_size / 8;
+
+ uint64_t ibf_bytes = ceil ((sizeof (struct IBFMessage) * ibf_message_count)
+ * 1.2 \
+ + (ibf_bucket_count * sizeof(struct IBF_Key)) * 1.2 \
+ + (ibf_bucket_count * sizeof(struct IBF_KeyHash))
+ * 1.2 \
+ + (ibf_bucket_count * counter_bytes) * 1.2);
+
+ /* Estimate full byte count for differential sync */
+ uint64_t element_size = (avg_element_size
+ + sizeof (struct GNUNET_SETU_ElementMessage)) \
+ * estimated_total_diff;
+ uint64_t done_size = sizeof_done_header;
+ uint64_t inquery_size = (sizeof (struct IBF_Key)
+ + sizeof (struct InquiryMessage))
+ * estimated_total_diff;
+ uint64_t demand_size =
+ (sizeof(struct GNUNET_HashCode) + sizeof(struct GNUNET_MessageHeader))
+ * estimated_total_diff;
+ uint64_t offer_size = (sizeof (struct GNUNET_HashCode)
+ + sizeof (struct GNUNET_MessageHeader))
+ * estimated_total_diff;
+
+ uint64_t total_bytes_diff = (element_size + done_size + inquery_size
+ + demand_size + offer_size + ibf_bytes) \
+ + (DIFFERENTIAL_RTT_MEAN
+ * bandwith_latency_tradeoff);
+
+ uint64_t full_min = MIN (total_bytes_full_local_send_first,
+ total_bytes_full_remote_send_first);
+
+ /* Decide between full and differential sync */
+
+ if (full_min < total_bytes_diff)
+ {
+ /* Decide between sending all element first or receiving all elements */
+ if (total_bytes_full_remote_send_first > total_bytes_full_local_send_first)
+ {
+ return FULL_SYNC_LOCAL_SENDING_FIRST;
+ }
+ else
+ {
+ return FULL_SYNC_REMOTE_SENDING_FIRST;
+ }
+ }
+ else
+ {
+ return DIFFERENTIAL_SYNC;
+ }
+}
+
+
+/**
+ * Validates the if a message is received in a correct phase
+ * @param allowed_phases
+ * @param size_phases
+ * @param op
+ * @return #GNUNET_YES if message permitted in phase and #GNUNET_NO if not permitted in given
+ * phase
+ */
+static enum GNUNET_GenericReturnValue
+check_valid_phase (const uint8_t allowed_phases[],
+ size_t size_phases,
+ struct Operation *op)
+{
+ /**
+ * Iterate over allowed phases
+ */
+ for (uint32_t phase_ctr = 0; phase_ctr < size_phases; phase_ctr++)
+ {
+ uint8_t phase = allowed_phases[phase_ctr];
+ if (phase == op->phase)
+ {
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Message received in valid phase\n");
+ return GNUNET_YES;
+ }
+ }
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ "Received message in invalid phase: %u\n", op->phase);
+ return GNUNET_NO;
+}
+
+
+/**
+ * Function to update, track and validate message received in differential
+ * sync. This function tracks states of messages and check it against different
+ * constraints as described in Summermatter's BSc Thesis (2021)
+ * @param hash_map: Hashmap to store message control flow
+ * @param new_mcfs: The new message control flow state an given message type should be set to
+ * @param hash_code: Hash code of the element
+ * @param mt: The message type for which the message control flow state should be set
+ * @return GNUNET_YES message is valid in message control flow GNUNET_NO when message is not valid
+ * at this point in message flow
+ */
+static int
+update_message_control_flow (struct GNUNET_CONTAINER_MultiHashMap *hash_map,
+ enum MESSAGE_CONTROL_FLOW_STATE new_mcfs,
+ const struct GNUNET_HashCode *hash_code,
+ enum MESSAGE_TYPE mt)
+{
+ struct messageControlFlowElement *cfe = NULL;
+ enum MESSAGE_CONTROL_FLOW_STATE *mcfs;
+
+ /**
+ * Check logic for forbidden messages
+ */
+
+ cfe = GNUNET_CONTAINER_multihashmap_get (hash_map, hash_code);
+ if ((ELEMENT_MESSAGE == mt) && (cfe != NULL))
+ {
+ if ((new_mcfs != MSG_CFS_SENT) && (MSG_CFS_RECEIVED != cfe->offer))
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ "Received an element without sent offer!\n");
+ return GNUNET_NO;
+ }
+ /* Check that only requested elements are received! */
+ if ((ELEMENT_MESSAGE == mt) && (new_mcfs != MSG_CFS_SENT) && (cfe->demand !=
+ MSG_CFS_SENT))
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ "Received an element that was not demanded\n");
+ return GNUNET_NO;
+ }
+ }
+
+ /**
+ * In case the element hash is not in the hashmap create a new entry
+ */
+
+ if (NULL == cfe)
+ {
+ cfe = GNUNET_new (struct messageControlFlowElement);
+ if (GNUNET_SYSERR == GNUNET_CONTAINER_multihashmap_put (hash_map, hash_code,
+ cfe,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
+ {
+ GNUNET_free (cfe);
+ return GNUNET_SYSERR;
+ }
+ }
+
+ /**
+ * Set state of message
+ */
+
+ if (OFFER_MESSAGE == mt)
+ {
+ mcfs = &cfe->offer;
+ }
+ else if (DEMAND_MESSAGE == mt)
+ {
+ mcfs = &cfe->demand;
+ }
+ else if (ELEMENT_MESSAGE == mt)
+ {
+ mcfs = &cfe->element;
+ }
+ else
+ {
+ return GNUNET_SYSERR;
+ }
+
+ /**
+ * Check if state is allowed
+ */
+
+ if (new_mcfs <= *mcfs)
+ {
+ return GNUNET_NO;
+ }
+
+ *mcfs = new_mcfs;
+ return GNUNET_YES;
+}
+
+
+/**
+ * Validate if a message in differential sync si already received before.
+ * @param hash_map
+ * @param hash_code
+ * @param mt
+ * @return GNUNET_YES when message is already in store if message is not in store return GNUNET_NO
+ */
+static int
+is_message_in_message_control_flow (struct
+ GNUNET_CONTAINER_MultiHashMap *hash_map,
+ struct GNUNET_HashCode *hash_code,
+ enum MESSAGE_TYPE mt)
+{
+ struct messageControlFlowElement *cfe = NULL;
+ enum MESSAGE_CONTROL_FLOW_STATE *mcfs;
+
+ cfe = GNUNET_CONTAINER_multihashmap_get (hash_map, hash_code);
+
+ /**
+ * Set state of message
+ */
+
+ if (cfe != NULL)
+ {
+ if (OFFER_MESSAGE == mt)
+ {
+ mcfs = &cfe->offer;
+ }
+ else if (DEMAND_MESSAGE == mt)
+ {
+ mcfs = &cfe->demand;
+ }
+ else if (ELEMENT_MESSAGE == mt)
+ {
+ mcfs = &cfe->element;
+ }
+ else
+ {
+ return GNUNET_SYSERR;
+ }
/**
- * Calculate data sended size
+ * Evaluate if set is in message
*/
- bytes_transmitted += sum_sent_received_bytes(sizeof(GNUNET_MESSAGE_TYPE_SETU_P2P_REQUEST_FULL), perf_rtt.request_full);
- bytes_transmitted += sum_sent_received_bytes(sizeof(GNUNET_MESSAGE_TYPE_SETU_P2P_FULL_ELEMENT), perf_rtt.element_full);
- bytes_transmitted += sum_sent_received_bytes(sizeof(GNUNET_MESSAGE_TYPE_SETU_P2P_ELEMENTS), perf_rtt.element);
- bytes_transmitted += sum_sent_received_bytes(sizeof(GNUNET_MESSAGE_TYPE_SETU_P2P_OPERATION_REQUEST), perf_rtt.operation_request);
- bytes_transmitted += sum_sent_received_bytes(sizeof(GNUNET_MESSAGE_TYPE_SETU_P2P_SE), perf_rtt.se);
- bytes_transmitted += sum_sent_received_bytes(sizeof(GNUNET_MESSAGE_TYPE_SETU_P2P_FULL_DONE), perf_rtt.full_done);
- bytes_transmitted += sum_sent_received_bytes(sizeof(GNUNET_MESSAGE_TYPE_SETU_P2P_IBF), perf_rtt.ibf);
- bytes_transmitted += sum_sent_received_bytes(sizeof(GNUNET_MESSAGE_TYPE_SETU_P2P_INQUIRY), perf_rtt.inquery);
- bytes_transmitted += sum_sent_received_bytes(sizeof(GNUNET_MESSAGE_TYPE_SETU_P2P_DEMAND), perf_rtt.demand);
- bytes_transmitted += sum_sent_received_bytes(sizeof(GNUNET_MESSAGE_TYPE_SETU_P2P_OFFER), perf_rtt.offer);
- bytes_transmitted += sum_sent_received_bytes(sizeof(GNUNET_MESSAGE_TYPE_SETU_P2P_DONE), perf_rtt.done);
+ if (*mcfs != MSG_CFS_UNINITIALIZED)
+ {
+ return GNUNET_YES;
+ }
+ }
+ return GNUNET_NO;
+}
- LOG(GNUNET_ERROR_TYPE_ERROR,"Bytes Transmitted: %d\n", bytes_transmitted);
- LOG(GNUNET_ERROR_TYPE_ERROR,"Reached tradeoff bandwidth/rtt: %f\n", (bytes_transmitted / rtt ));
+/**
+ * Iterator for determining if all demands have been
+ * satisfied
+ *
+ * @param cls the union operation `struct Operation *`
+ * @param key unused
+ * @param value the `struct ElementEntry *` to insert
+ * into the key-to-element mapping
+ * @return #GNUNET_YES (to continue iterating)
+ */
+static int
+determinate_done_message_iterator (void *cls,
+ const struct GNUNET_HashCode *key,
+ void *value)
+{
+ struct messageControlFlowElement *mcfe = value;
- return rtt;
+ if (((mcfe->element == MSG_CFS_SENT) || (mcfe->element == MSG_CFS_RECEIVED) ))
+ {
+ return GNUNET_YES;
+ }
+ return GNUNET_NO;
+}
+
+
+/**
+ * Iterator for determining average size
+ *
+ * @param cls the union operation `struct Operation *`
+ * @param key unused
+ * @param value the `struct ElementEntry *` to insert
+ * into the key-to-element mapping
+ * @return #GNUNET_YES (to continue iterating)
+ */
+static int
+determinate_avg_element_size_iterator (void *cls,
+ const struct GNUNET_HashCode *key,
+ void *value)
+{
+ struct Operation *op = cls;
+ struct GNUNET_SETU_Element *element = value;
+ op->total_elements_size_local += element->size;
+ return GNUNET_YES;
+}
+
+
+/**
+ * Create randomized element hashmap for full sending
+ *
+ * @param cls the union operation `struct Operation *`
+ * @param key unused
+ * @param value the `struct ElementEntry *` to insert
+ * into the key-to-element mapping
+ * @return #GNUNET_YES (to continue iterating)
+ */
+static int
+create_randomized_element_iterator (void *cls,
+ const struct GNUNET_HashCode *key,
+ void *value)
+{
+ struct Operation *op = cls;
+
+ struct GNUNET_HashContext *hashed_key_context =
+ GNUNET_CRYPTO_hash_context_start ();
+ struct GNUNET_HashCode new_key;
+
+ /**
+ * Hash element with new salt to randomize hashmap
+ */
+ GNUNET_CRYPTO_hash_context_read (hashed_key_context,
+ &key,
+ sizeof(struct IBF_Key));
+ GNUNET_CRYPTO_hash_context_read (hashed_key_context,
+ &op->set->content->elements_randomized_salt,
+ sizeof(uint32_t));
+ GNUNET_CRYPTO_hash_context_finish (hashed_key_context,
+ &new_key);
+ GNUNET_CONTAINER_multihashmap_put (op->set->content->elements_randomized,
+ &new_key,value,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE);
+ return GNUNET_YES;
}
@@ -808,6 +1522,36 @@ send_client_done (void *cls)
}
+/**
+ * Check if all given byzantine parameters are in given boundaries
+ * @param op
+ * @return indicator if all given byzantine parameters are in given boundaries
+ */
+
+static int
+check_byzantine_bounds (struct Operation *op)
+{
+ if (op->byzantine != GNUNET_YES)
+ return GNUNET_OK;
+
+ /**
+ * Check upper byzantine bounds
+ */
+ if (op->remote_element_count + op->remote_set_diff >
+ op->byzantine_upper_bound)
+ return GNUNET_SYSERR;
+ if (op->local_element_count + op->local_set_diff > op->byzantine_upper_bound)
+ return GNUNET_SYSERR;
+
+ /**
+ * Check lower byzantine bounds
+ */
+ if (op->remote_element_count < op->byzantine_lower_bound)
+ return GNUNET_SYSERR;
+ return GNUNET_OK;
+}
+
+
/* FIXME: the destroy logic is a mess and should be cleaned up! */
/**
@@ -977,6 +1721,101 @@ fail_union_operation (struct Operation *op)
/**
+ * Function that checks if full sync is plausible
+ * @param initial_local_elements_in_set
+ * @param estimated_set_difference
+ * @param repeated_elements
+ * @param fresh_elements
+ * @param op
+ * @return GNUNET_OK if
+ */
+
+static void
+full_sync_plausibility_check (struct Operation *op)
+{
+ if (GNUNET_YES != op->byzantine)
+ return;
+
+ int security_level_lb = -1 * SECURITY_LEVEL;
+ uint64_t duplicates = op->received_fresh - op->received_total;
+
+ /*
+ * Protect full sync from receiving double element when in FULL SENDING
+ */
+ if (PHASE_FULL_SENDING == op->phase)
+ {
+ if (duplicates > 0)
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ "PROTOCOL VIOLATION: Received duplicate element in full receiving "
+ "mode of operation this is not allowed! Duplicates: %llu\n",
+ (unsigned long long) duplicates);
+ GNUNET_break_op (0);
+ fail_union_operation (op);
+ return;
+ }
+
+ }
+
+ /*
+ * Protect full sync with probabilistic algorithm
+ */
+ if (PHASE_FULL_RECEIVING == op->phase)
+ {
+ if (0 == op->remote_set_diff)
+ op->remote_set_diff = 1;
+
+ long double base = (1 - (long double) (op->remote_set_diff
+ / (long double) (op->initial_size
+ + op->
+ remote_set_diff)));
+ long double exponent = (op->received_total - (op->received_fresh * ((long
+ double)
+ op->
+ initial_size
+ / (long
+ double)
+ op->
+ remote_set_diff)));
+ long double value = exponent * (log2l (base) / log2l (2));
+ if ((value < security_level_lb) || (value > SECURITY_LEVEL) )
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ "PROTOCOL VIOLATION: Other peer violated probabilistic rule for receiving "
+ "to many duplicated full element : %LF\n",
+ value);
+ GNUNET_break_op (0);
+ fail_union_operation (op);
+ return;
+ }
+ }
+}
+
+
+/**
+ * Limit active passive switches in differential sync to configured security level
+ * @param op
+ */
+static void
+check_max_differential_rounds (struct Operation *op)
+{
+ double probability = op->differential_sync_iterations * (log2l (
+ PROBABILITY_FOR_NEW_ROUND)
+ / log2l (2));
+ if ((-1 * SECURITY_LEVEL) > probability)
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ "PROTOCOL VIOLATION: Other peer violated probabilistic rule for to many active passive "
+ "switches in differential sync: %u\n",
+ op->differential_sync_iterations);
+ GNUNET_break_op (0);
+ fail_union_operation (op);
+ return;
+ }
+}
+
+
+/**
* Derive the IBF key from a hash code and
* a salt.
*
@@ -1004,12 +1843,12 @@ get_ibf_key (const struct GNUNET_HashCode *src)
struct GetElementContext
{
/**
- * FIXME.
+ * Gnunet hash code in context
*/
struct GNUNET_HashCode hash;
/**
- * FIXME.
+ * Pointer to the key entry
*/
struct KeyEntry *k;
};
@@ -1122,7 +1961,7 @@ salt_key (const struct IBF_Key *k_in,
uint32_t salt,
struct IBF_Key *k_out)
{
- int s = salt % 64;
+ int s = (salt * 7) % 64;
uint64_t x = k_in->key_val;
/* rotate ibf key */
@@ -1132,14 +1971,14 @@ salt_key (const struct IBF_Key *k_in,
/**
- * FIXME.
+ * Reverse modification done in the salt_key function
*/
static void
unsalt_key (const struct IBF_Key *k_in,
uint32_t salt,
struct IBF_Key *k_out)
{
- int s = salt % 64;
+ int s = (salt * 7) % 64;
uint64_t x = k_in->key_val;
x = (x << s) | (x >> (64 - s));
@@ -1258,7 +2097,9 @@ prepare_ibf (struct Operation *op,
if (NULL != op->local_ibf)
ibf_destroy (op->local_ibf);
- op->local_ibf = ibf_create (size, SE_IBF_HASH_NUM);
+ // op->local_ibf = ibf_create (size, SE_IBF_HASH_NUM);
+ op->local_ibf = ibf_create (size,
+ ((uint8_t) op->ibf_number_buckets_per_element));
if (NULL == op->local_ibf)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -1283,13 +2124,23 @@ prepare_ibf (struct Operation *op,
*/
static int
send_ibf (struct Operation *op,
- uint16_t ibf_order)
+ uint32_t ibf_size)
{
- unsigned int buckets_sent = 0;
+ uint64_t buckets_sent = 0;
struct InvertibleBloomFilter *ibf;
+ op->differential_sync_iterations++;
+ /**
+ * Enforce min size of IBF
+ */
+ uint32_t ibf_min_size = IBF_MIN_SIZE;
+
+ if (ibf_size < ibf_min_size)
+ {
+ ibf_size = ibf_min_size;
+ }
if (GNUNET_OK !=
- prepare_ibf (op, 1 << ibf_order))
+ prepare_ibf (op, ibf_size))
{
/* allocation failed */
return GNUNET_SYSERR;
@@ -1297,45 +2148,52 @@ send_ibf (struct Operation *op,
LOG (GNUNET_ERROR_TYPE_DEBUG,
"sending ibf of size %u\n",
- 1 << ibf_order);
+ (unsigned int) ibf_size);
{
char name[64];
- GNUNET_snprintf (name, sizeof(name), "# sent IBF (order %u)", ibf_order);
+
+ GNUNET_snprintf (name,
+ sizeof(name),
+ "# sent IBF (order %u)",
+ ibf_size);
GNUNET_STATISTICS_update (_GSS_statistics, name, 1, GNUNET_NO);
}
ibf = op->local_ibf;
- while (buckets_sent < (1 << ibf_order))
+ while (buckets_sent < ibf_size)
{
unsigned int buckets_in_message;
struct GNUNET_MQ_Envelope *ev;
struct IBFMessage *msg;
- buckets_in_message = (1 << ibf_order) - buckets_sent;
+ buckets_in_message = ibf_size - buckets_sent;
/* limit to maximum */
if (buckets_in_message > MAX_BUCKETS_PER_MESSAGE)
buckets_in_message = MAX_BUCKETS_PER_MESSAGE;
- perf_rtt.ibf.sent += 1;
- perf_rtt.ibf.sent_var_bytes += ( buckets_in_message * IBF_BUCKET_SIZE );
+#if MEASURE_PERFORMANCE
+ perf_store.ibf.sent += 1;
+ perf_store.ibf.sent_var_bytes += (buckets_in_message * IBF_BUCKET_SIZE);
+#endif
ev = GNUNET_MQ_msg_extra (msg,
buckets_in_message * IBF_BUCKET_SIZE,
GNUNET_MESSAGE_TYPE_SETU_P2P_IBF);
- msg->reserved1 = 0;
- msg->reserved2 = 0;
- msg->order = ibf_order;
+ msg->ibf_size = ibf_size;
msg->offset = htonl (buckets_sent);
msg->salt = htonl (op->salt_send);
+ msg->ibf_counter_bit_length = ibf_get_max_counter (ibf);
+
+
ibf_write_slice (ibf, buckets_sent,
- buckets_in_message, &msg[1]);
+ buckets_in_message, &msg[1], msg->ibf_counter_bit_length);
buckets_sent += buckets_in_message;
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "ibf chunk size %u, %u/%u sent\n",
- buckets_in_message,
- buckets_sent,
- 1 << ibf_order);
+ "ibf chunk size %u, %llu/%u sent\n",
+ (unsigned int) buckets_in_message,
+ (unsigned long long) buckets_sent,
+ (unsigned int) ibf_size);
GNUNET_MQ_send (op->mq, ev);
}
@@ -1354,17 +2212,26 @@ send_ibf (struct Operation *op,
* @return the required size of the ibf
*/
static unsigned int
-get_order_from_difference (unsigned int diff)
+get_size_from_difference (unsigned int diff, int number_buckets_per_element,
+ float ibf_bucket_number_factor)
{
- unsigned int ibf_order;
+ /** Make ibf estimation size odd reasoning can be found in BSc Thesis of
+ * Elias Summermatter (2021) in section 3.11 **/
+ return (((int) (diff * ibf_bucket_number_factor)) | 1);
+
+}
- ibf_order = 2;
- while (((1 << ibf_order) < (IBF_ALPHA * diff) ||
- ((1 << ibf_order) < SE_IBF_HASH_NUM)) &&
- (ibf_order < MAX_IBF_ORDER))
- ibf_order++;
- // add one for correction
- return ibf_order + 1;
+
+static unsigned int
+get_next_ibf_size (float ibf_bucket_number_factor, unsigned int
+ decoded_elements, unsigned int last_ibf_size)
+{
+ unsigned int next_size = (unsigned int) ((last_ibf_size * 2)
+ - (ibf_bucket_number_factor
+ * decoded_elements));
+ /** Make ibf estimation size odd reasoning can be found in BSc Thesis of
+ * Elias Summermatter (2021) in section 3.11 **/
+ return next_size | 1;
}
@@ -1391,8 +2258,10 @@ send_full_element_iterator (void *cls,
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Sending element %s\n",
GNUNET_h2s (key));
- perf_rtt.element_full.received += 1;
- perf_rtt.element_full.received_var_bytes += el->size;
+#if MEASURE_PERFORMANCE
+ perf_store.element_full.received += 1;
+ perf_store.element_full.received_var_bytes += el->size;
+#endif
ev = GNUNET_MQ_msg_extra (emsg,
el->size,
GNUNET_MESSAGE_TYPE_SETU_P2P_FULL_ELEMENT);
@@ -1421,10 +2290,25 @@ send_full_set (struct Operation *op)
"Dedicing to transmit the full set\n");
/* FIXME: use a more memory-friendly way of doing this with an
iterator, just as we do in the non-full case! */
+
+ // Randomize Elements to send
+ op->set->content->elements_randomized = GNUNET_CONTAINER_multihashmap_create (
+ 32,GNUNET_NO);
+ op->set->content->elements_randomized_salt = GNUNET_CRYPTO_random_u64 (
+ GNUNET_CRYPTO_QUALITY_NONCE,
+ UINT64_MAX);
(void) GNUNET_CONTAINER_multihashmap_iterate (op->set->content->elements,
- &send_full_element_iterator,
+ &
+ create_randomized_element_iterator,
op);
- perf_rtt.full_done.sent += 1;
+
+ (void) GNUNET_CONTAINER_multihashmap_iterate (
+ op->set->content->elements_randomized,
+ &send_full_element_iterator,
+ op);
+#if MEASURE_PERFORMANCE
+ perf_store.full_done.sent += 1;
+#endif
ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_SETU_P2P_FULL_DONE);
GNUNET_MQ_send (op->mq,
ev);
@@ -1454,7 +2338,7 @@ check_union_p2p_strata_estimator (void *cls,
msg->header.type));
len = ntohs (msg->header.size) - sizeof(struct StrataEstimatorMessage);
if ((GNUNET_NO == is_compressed) &&
- (len != SE_STRATA_COUNT * SE_IBF_SIZE * IBF_BUCKET_SIZE))
+ (len != SE_STRATA_COUNT * SE_IBFS_TOTAL_SIZE * IBF_BUCKET_SIZE))
{
GNUNET_break (0);
return GNUNET_SYSERR;
@@ -1473,14 +2357,44 @@ static void
handle_union_p2p_strata_estimator (void *cls,
const struct StrataEstimatorMessage *msg)
{
- perf_rtt.se.received += 1;
- perf_rtt.se.received_var_bytes += ntohs (msg->header.size) - sizeof(struct StrataEstimatorMessage);
+#if MEASURE_PERFORMANCE
+ perf_store.se.received += 1;
+ perf_store.se.received_var_bytes += ntohs (msg->header.size) - sizeof(struct
+ StrataEstimatorMessage);
+#endif
struct Operation *op = cls;
- struct StrataEstimator *remote_se;
+ struct MultiStrataEstimator *remote_se;
unsigned int diff;
uint64_t other_size;
size_t len;
int is_compressed;
+ op->local_element_count = GNUNET_CONTAINER_multihashmap_size (
+ op->set->content->elements);
+ // Setting peer site to receiving peer
+ op->peer_site = 1;
+
+ /**
+ * Check that the message is received only in supported phase
+ */
+ uint8_t allowed_phases[] = {PHASE_EXPECT_SE};
+ if (GNUNET_OK !=
+ check_valid_phase (allowed_phases,sizeof(allowed_phases),op))
+ {
+ GNUNET_break (0);
+ fail_union_operation (op);
+ return;
+ }
+
+ /** Only allow 1,2,4,8 SEs **/
+ if ((msg->se_count > 8) || (__builtin_popcount ((int) msg->se_count) != 1))
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ "PROTOCOL VIOLATION: Invalid number of se transmitted by other peer %u\n",
+ msg->se_count);
+ GNUNET_break_op (0);
+ fail_union_operation (op);
+ return;
+ }
is_compressed = (GNUNET_MESSAGE_TYPE_SETU_P2P_SEC == htons (
msg->header.type));
@@ -1490,8 +2404,20 @@ handle_union_p2p_strata_estimator (void *cls,
GNUNET_NO);
len = ntohs (msg->header.size) - sizeof(struct StrataEstimatorMessage);
other_size = GNUNET_ntohll (msg->set_size);
+ op->remote_element_count = other_size;
+
+ if (op->byzantine_upper_bound < op->remote_element_count)
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ "Exceeded configured upper bound <%lu> of element: %u\n",
+ op->byzantine_upper_bound,
+ op->remote_element_count);
+ fail_union_operation (op);
+ return;
+ }
+
remote_se = strata_estimator_create (SE_STRATA_COUNT,
- SE_IBF_SIZE,
+ SE_IBFS_TOTAL_SIZE,
SE_IBF_HASH_NUM);
if (NULL == remote_se)
{
@@ -1503,6 +2429,8 @@ handle_union_p2p_strata_estimator (void *cls,
strata_estimator_read (&msg[1],
len,
is_compressed,
+ msg->se_count,
+ SE_IBFS_TOTAL_SIZE,
remote_se))
{
/* decompression failed */
@@ -1511,11 +2439,76 @@ handle_union_p2p_strata_estimator (void *cls,
return;
}
GNUNET_assert (NULL != op->se);
- diff = strata_estimator_difference (remote_se,
- op->se);
+ strata_estimator_difference (remote_se,
+ op->se);
+
+ /* Calculate remote local diff */
+ long diff_remote = remote_se->stratas[0]->strata[0]->remote_decoded_count;
+ long diff_local = remote_se->stratas[0]->strata[0]->local_decoded_count;
+
+ /* Prevent estimations from overshooting max element */
+ if (diff_remote + op->remote_element_count > op->byzantine_upper_bound)
+ diff_remote = op->byzantine_upper_bound - op->remote_element_count;
+ if (diff_local + op->local_element_count > op->byzantine_upper_bound)
+ diff_local = op->byzantine_upper_bound - op->local_element_count;
+ if ((diff_remote < 0) || (diff_local < 0))
+ {
+ strata_estimator_destroy (remote_se);
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ "PROTOCOL VIOLATION: More element is set as upper boundary or other peer is "
+ "malicious: remote diff %ld, local diff: %ld\n",
+ diff_remote, diff_local);
+ GNUNET_break_op (0);
+ fail_union_operation (op);
+ return;
+ }
- if (diff > 200)
- diff = diff * 3 / 2;
+ /* Make estimation more precise in initial sync cases */
+ if (0 == op->remote_element_count)
+ {
+ diff_remote = 0;
+ diff_local = op->local_element_count;
+ }
+ if (0 == op->local_element_count)
+ {
+ diff_local = 0;
+ diff_remote = op->remote_element_count;
+ }
+
+ diff = diff_remote + diff_local;
+ op->remote_set_diff = diff_remote;
+
+ /** Calculate avg element size if not initial sync **/
+ uint64_t avg_element_size = 0;
+ if (0 < op->local_element_count)
+ {
+ op->total_elements_size_local = 0;
+ GNUNET_CONTAINER_multihashmap_iterate (op->set->content->elements,
+ &
+ determinate_avg_element_size_iterator,
+ op);
+ avg_element_size = op->total_elements_size_local / op->local_element_count;
+ }
+
+ op->mode_of_operation = estimate_best_mode_of_operation (avg_element_size,
+ GNUNET_CONTAINER_multihashmap_size (
+ op->set->content->
+ elements),
+ op->
+ remote_element_count,
+ diff_remote,
+ diff_local,
+ op->
+ rtt_bandwidth_tradeoff,
+ op->
+ ibf_bucket_number_factor);
+
+#if MEASURE_PERFORMANCE
+ perf_store.se_diff_local = diff_local;
+ perf_store.se_diff_remote = diff_remote;
+ perf_store.se_diff = diff;
+ perf_store.mode_of_operation = op->mode_of_operation;
+#endif
strata_estimator_destroy (remote_se);
strata_estimator_destroy (op->se);
@@ -1523,7 +2516,8 @@ handle_union_p2p_strata_estimator (void *cls,
LOG (GNUNET_ERROR_TYPE_DEBUG,
"got se diff=%d, using ibf size %d\n",
diff,
- 1U << get_order_from_difference (diff));
+ 1U << get_size_from_difference (diff, op->ibf_number_buckets_per_element,
+ op->ibf_bucket_number_factor));
{
char *set_debug;
@@ -1546,16 +2540,8 @@ handle_union_p2p_strata_estimator (void *cls,
return;
}
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx: %f\n", op->rtt_bandwidth_tradeoff);
-
-
- /**
- * Added rtt_bandwidth_tradeoff directly need future improvements
- */
if ((GNUNET_YES == op->force_full) ||
- (diff > op->initial_size / 4) ||
- (0 == other_size))
+ (op->mode_of_operation != DIFFERENTIAL_SYNC))
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Deciding to go for full set transmission (diff=%d, own set=%llu)\n",
@@ -1565,9 +2551,17 @@ handle_union_p2p_strata_estimator (void *cls,
"# of full sends",
1,
GNUNET_NO);
- if ((op->initial_size <= other_size) ||
- (0 == other_size))
+ if (FULL_SYNC_LOCAL_SENDING_FIRST == op->mode_of_operation)
{
+ struct TransmitFullMessage *signal_msg;
+ struct GNUNET_MQ_Envelope *ev;
+ ev = GNUNET_MQ_msg_extra (signal_msg,sizeof(struct TransmitFullMessage),
+ GNUNET_MESSAGE_TYPE_SETU_P2P_SEND_FULL);
+ signal_msg->remote_set_difference = htonl (diff_local);
+ signal_msg->remote_set_size = htonl (op->local_element_count);
+ signal_msg->local_set_difference = htonl (diff_remote);
+ GNUNET_MQ_send (op->mq,
+ ev);
send_full_set (op);
}
else
@@ -1577,9 +2571,15 @@ handle_union_p2p_strata_estimator (void *cls,
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Telling other peer that we expect its full set\n");
op->phase = PHASE_FULL_RECEIVING;
- perf_rtt.request_full.sent += 1;
- ev = GNUNET_MQ_msg_header (
- GNUNET_MESSAGE_TYPE_SETU_P2P_REQUEST_FULL);
+#if MEASURE_PERFORMANCE
+ perf_store.request_full.sent += 1;
+#endif
+ struct TransmitFullMessage *signal_msg;
+ ev = GNUNET_MQ_msg_extra (signal_msg,sizeof(struct TransmitFullMessage),
+ GNUNET_MESSAGE_TYPE_SETU_P2P_REQUEST_FULL);
+ signal_msg->remote_set_difference = htonl (diff_local);
+ signal_msg->remote_set_size = htonl (op->local_element_count);
+ signal_msg->local_set_difference = htonl (diff_remote);
GNUNET_MQ_send (op->mq,
ev);
}
@@ -1592,7 +2592,9 @@ handle_union_p2p_strata_estimator (void *cls,
GNUNET_NO);
if (GNUNET_OK !=
send_ibf (op,
- get_order_from_difference (diff)))
+ get_size_from_difference (diff,
+ op->ibf_number_buckets_per_element,
+ op->ibf_bucket_number_factor)))
{
/* Internal error, best we can do is shut the connection */
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -1625,15 +2627,64 @@ send_offers_iterator (void *cls,
/* Detect 32-bit key collision for the 64-bit IBF keys. */
if (ke->ibf_key.key_val != sec->ibf_key.key_val)
+ {
+ op->active_passive_switch_required = true;
return GNUNET_YES;
+ }
- perf_rtt.offer.sent += 1;
- perf_rtt.offer.sent_var_bytes += sizeof(struct GNUNET_HashCode);
+ /* Prevent implementation from sending a offer multiple times in case of roll switch */
+ if (GNUNET_YES ==
+ is_message_in_message_control_flow (
+ op->message_control_flow,
+ &ke->element->element_hash,
+ OFFER_MESSAGE)
+ )
+ {
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Skipping already sent processed element offer!\n");
+ return GNUNET_YES;
+ }
+ /* Save send offer message for message control */
+ if (GNUNET_YES !=
+ update_message_control_flow (
+ op->message_control_flow,
+ MSG_CFS_SENT,
+ &ke->element->element_hash,
+ OFFER_MESSAGE)
+ )
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ "Double offer message sent found!\n");
+ GNUNET_break (0);
+ fail_union_operation (op);
+ return GNUNET_NO;
+ }
+ ;
+
+ /* Mark element to be expected to received */
+ if (GNUNET_YES !=
+ update_message_control_flow (
+ op->message_control_flow,
+ MSG_CFS_EXPECTED,
+ &ke->element->element_hash,
+ DEMAND_MESSAGE)
+ )
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ "Double demand received found!\n");
+ GNUNET_break (0);
+ fail_union_operation (op);
+ return GNUNET_NO;
+ }
+ ;
+#if MEASURE_PERFORMANCE
+ perf_store.offer.sent += 1;
+ perf_store.offer.sent_var_bytes += sizeof(struct GNUNET_HashCode);
+#endif
ev = GNUNET_MQ_msg_header_extra (mh,
sizeof(struct GNUNET_HashCode),
GNUNET_MESSAGE_TYPE_SETU_P2P_OFFER);
-
GNUNET_assert (NULL != ev);
*(struct GNUNET_HashCode *) &mh[1] = ke->element->element_hash;
LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -1651,7 +2702,7 @@ send_offers_iterator (void *cls,
* @param op union operation
* @param ibf_key IBF key of interest
*/
-static void
+void
send_offers_for_key (struct Operation *op,
struct IBF_Key ibf_key)
{
@@ -1694,6 +2745,7 @@ decode_and_send (struct Operation *op)
/* allocation failed */
return GNUNET_SYSERR;
}
+
diff_ibf = ibf_dup (op->local_ibf);
ibf_subtract (diff_ibf,
op->remote_ibf);
@@ -1706,7 +2758,7 @@ decode_and_send (struct Operation *op)
diff_ibf->size);
num_decoded = 0;
- key.key_val = 0; /* just to avoid compiler thinking we use undef'ed variable */
+ key.key_val = 0; /* just to avoid compiler thinking we use undef'ed variable */
while (1)
{
@@ -1738,23 +2790,36 @@ decode_and_send (struct Operation *op)
if ((GNUNET_SYSERR == res) ||
(GNUNET_YES == cycle_detected))
{
- int next_order;
- next_order = 0;
- while (1 << next_order < diff_ibf->size)
- next_order++;
- next_order++;
- if (next_order <= MAX_IBF_ORDER)
+ uint32_t next_size;
+ /** Enforce odd ibf size **/
+
+ next_size = get_next_ibf_size (op->ibf_bucket_number_factor, num_decoded,
+ diff_ibf->size);
+ /** Make ibf estimation size odd reasoning can be found in BSc Thesis of
+ * Elias Summermatter (2021) in section 3.11 **/
+ uint32_t ibf_min_size = IBF_MIN_SIZE | 1;
+
+ if (next_size<ibf_min_size)
+ next_size = ibf_min_size;
+
+
+ if (next_size <= MAX_IBF_SIZE)
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
"decoding failed, sending larger ibf (size %u)\n",
- 1 << next_order);
+ next_size);
GNUNET_STATISTICS_update (_GSS_statistics,
"# of IBF retries",
1,
GNUNET_NO);
- op->salt_send++;
+#if MEASURE_PERFORMANCE
+ perf_store.active_passive_switches += 1;
+#endif
+
+ op->salt_send = op->salt_receive++;
+
if (GNUNET_OK !=
- send_ibf (op, next_order))
+ send_ibf (op, next_size))
{
/* Internal error, best we can do is shut the connection */
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -1786,7 +2851,9 @@ decode_and_send (struct Operation *op)
LOG (GNUNET_ERROR_TYPE_DEBUG,
"transmitted all values, sending DONE\n");
- perf_rtt.done.sent += 1;
+#if MEASURE_PERFORMANCE
+ perf_store.done.sent += 1;
+#endif
ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_SETU_P2P_DONE);
GNUNET_MQ_send (op->mq, ev);
/* We now wait until we get a DONE message back
@@ -1797,7 +2864,6 @@ decode_and_send (struct Operation *op)
if (1 == side)
{
struct IBF_Key unsalted_key;
-
unsalt_key (&key,
op->salt_receive,
&unsalted_key);
@@ -1809,8 +2875,29 @@ decode_and_send (struct Operation *op)
struct GNUNET_MQ_Envelope *ev;
struct InquiryMessage *msg;
- perf_rtt.inquery.sent += 1;
- perf_rtt.inquery.sent_var_bytes += sizeof(struct IBF_Key);
+#if MEASURE_PERFORMANCE
+ perf_store.inquery.sent += 1;
+ perf_store.inquery.sent_var_bytes += sizeof(struct IBF_Key);
+#endif
+
+ /** Add sent inquiries to hashmap for flow control **/
+ struct GNUNET_HashContext *hashed_key_context =
+ GNUNET_CRYPTO_hash_context_start ();
+ struct GNUNET_HashCode *hashed_key = (struct
+ GNUNET_HashCode*) GNUNET_malloc (
+ sizeof(struct GNUNET_HashCode));
+ enum MESSAGE_CONTROL_FLOW_STATE mcfs = MSG_CFS_SENT;
+ GNUNET_CRYPTO_hash_context_read (hashed_key_context,
+ &key,
+ sizeof(struct IBF_Key));
+ GNUNET_CRYPTO_hash_context_finish (hashed_key_context,
+ hashed_key);
+ GNUNET_CONTAINER_multihashmap_put (op->inquiries_sent,
+ hashed_key,
+ &mcfs,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE
+ );
+
/* It may be nice to merge multiple requests, but with CADET's corking it is not worth
* the effort additional complexity. */
ev = GNUNET_MQ_msg_extra (msg,
@@ -1836,6 +2923,100 @@ decode_and_send (struct Operation *op)
/**
+ * Check send full message received from other peer
+ * @param cls
+ * @param msg
+ * @return
+ */
+
+static int
+check_union_p2p_send_full (void *cls,
+ const struct TransmitFullMessage *msg)
+{
+ return GNUNET_OK;
+}
+
+
+/**
+ * Handle send full message received from other peer
+ *
+ * @param cls
+ * @param msg
+ */
+static void
+handle_union_p2p_send_full (void *cls,
+ const struct TransmitFullMessage *msg)
+{
+ struct Operation *op = cls;
+
+ /**
+ * Check that the message is received only in supported phase
+ */
+ uint8_t allowed_phases[] = {PHASE_EXPECT_IBF};
+ if (GNUNET_OK !=
+ check_valid_phase (allowed_phases,sizeof(allowed_phases),op))
+ {
+ GNUNET_break (0);
+ fail_union_operation (op);
+ return;
+ }
+
+ /** write received values to operator**/
+ op->remote_element_count = ntohl (msg->remote_set_size);
+ op->remote_set_diff = ntohl (msg->remote_set_difference);
+ op->local_set_diff = ntohl (msg->local_set_difference);
+
+ /** Check byzantine limits **/
+ if (check_byzantine_bounds (op) != GNUNET_OK)
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ "PROTOCOL VIOLATION: Parameters transmitted from other peer do not satisfie byzantine "
+ "criteria\n");
+ GNUNET_break_op (0);
+ fail_union_operation (op);
+ return;
+ }
+
+ /** Calculate avg element size if not initial sync **/
+ op->local_element_count = GNUNET_CONTAINER_multihashmap_size (
+ op->set->content->elements);
+ uint64_t avg_element_size = 0;
+ if (0 < op->local_element_count)
+ {
+ op->total_elements_size_local = 0;
+ GNUNET_CONTAINER_multihashmap_iterate (op->set->content->elements,
+ &
+ determinate_avg_element_size_iterator,
+ op);
+ avg_element_size = op->total_elements_size_local / op->local_element_count;
+ }
+
+ /** Validate mode of operation **/
+ int mode_of_operation = estimate_best_mode_of_operation (avg_element_size,
+ op->
+ remote_element_count,
+ op->
+ local_element_count,
+ op->local_set_diff,
+ op->remote_set_diff,
+ op->
+ rtt_bandwidth_tradeoff,
+ op->
+ ibf_bucket_number_factor);
+ if (FULL_SYNC_LOCAL_SENDING_FIRST != mode_of_operation)
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ "PROTOCOL VIOLATION: Remote peer choose to send his full set first but correct mode would have been"
+ " : %d\n", mode_of_operation);
+ GNUNET_break_op (0);
+ fail_union_operation (op);
+ return;
+ }
+ op->phase = PHASE_FULL_RECEIVING;
+}
+
+
+/**
* Check an IBF message from a remote peer.
*
* Reassemble the IBF from multiple pieces, and
@@ -1872,7 +3053,8 @@ check_union_p2p_ibf (void *cls,
GNUNET_break_op (0);
return GNUNET_SYSERR;
}
- if (1 << msg->order != op->remote_ibf->size)
+
+ if (msg->ibf_size != op->remote_ibf->size)
{
GNUNET_break_op (0);
return GNUNET_SYSERR;
@@ -1909,9 +3091,26 @@ handle_union_p2p_ibf (void *cls,
{
struct Operation *op = cls;
unsigned int buckets_in_message;
+ /**
+ * Check that the message is received only in supported phase
+ */
+ uint8_t allowed_phases[] = {PHASE_EXPECT_IBF, PHASE_EXPECT_IBF_LAST,
+ PHASE_PASSIVE_DECODING};
+ if (GNUNET_OK !=
+ check_valid_phase (allowed_phases,sizeof(allowed_phases),op))
+ {
+ GNUNET_break (0);
+ fail_union_operation (op);
+ return;
+ }
+ op->differential_sync_iterations++;
+ check_max_differential_rounds (op);
+ op->active_passive_switch_required = false;
- perf_rtt.ibf.received += 1;
- perf_rtt.ibf.received_var_bytes += (ntohs (msg->header.size) - sizeof *msg);
+#if MEASURE_PERFORMANCE
+ perf_store.ibf.received += 1;
+ perf_store.ibf.received_var_bytes += (ntohs (msg->header.size) - sizeof *msg);
+#endif
buckets_in_message = (ntohs (msg->header.size) - sizeof *msg)
/ IBF_BUCKET_SIZE;
@@ -1922,8 +3121,10 @@ handle_union_p2p_ibf (void *cls,
GNUNET_assert (NULL == op->remote_ibf);
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Creating new ibf of size %u\n",
- 1 << msg->order);
- op->remote_ibf = ibf_create (1 << msg->order, SE_IBF_HASH_NUM);
+ ntohl (msg->ibf_size));
+ // op->remote_ibf = ibf_create (1 << msg->order, SE_IBF_HASH_NUM);
+ op->remote_ibf = ibf_create (msg->ibf_size,
+ ((uint8_t) op->ibf_number_buckets_per_element));
op->salt_receive = ntohl (msg->salt);
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Receiving new IBF with salt %u\n",
@@ -1954,7 +3155,7 @@ handle_union_p2p_ibf (void *cls,
ibf_read_slice (&msg[1],
op->ibf_buckets_received,
buckets_in_message,
- op->remote_ibf);
+ op->remote_ibf, msg->ibf_counter_bit_length);
op->ibf_buckets_received += buckets_in_message;
if (op->ibf_buckets_received == op->remote_ibf->size)
@@ -2030,18 +3231,24 @@ maybe_finish (struct Operation *op)
num_demanded = GNUNET_CONTAINER_multihashmap_size (
op->demanded_hashes);
-
+ int send_done = GNUNET_CONTAINER_multihashmap_iterate (
+ op->message_control_flow,
+ &
+ determinate_done_message_iterator,
+ op);
if (PHASE_FINISH_WAITING == op->phase)
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "In PHASE_FINISH_WAITING, pending %u demands\n",
- num_demanded);
- if (0 == num_demanded)
+ "In PHASE_FINISH_WAITING, pending %u demands -> %d\n",
+ num_demanded, op->peer_site);
+ if (-1 != send_done)
{
struct GNUNET_MQ_Envelope *ev;
op->phase = PHASE_FINISHED;
- perf_rtt.done.sent += 1;
+#if MEASURE_PERFORMANCE
+ perf_store.done.sent += 1;
+#endif
ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_SETU_P2P_DONE);
GNUNET_MQ_send (op->mq,
ev);
@@ -2052,9 +3259,9 @@ maybe_finish (struct Operation *op)
if (PHASE_FINISH_CLOSING == op->phase)
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "In PHASE_FINISH_CLOSING, pending %u demands\n",
- num_demanded);
- if (0 == num_demanded)
+ "In PHASE_FINISH_CLOSING, pending %u demands %d\n",
+ num_demanded, op->peer_site);
+ if (-1 != send_done)
{
op->phase = PHASE_FINISHED;
send_client_done (op);
@@ -2102,11 +3309,25 @@ handle_union_p2p_elements (void *cls,
struct KeyEntry *ke;
uint16_t element_size;
+ /**
+ * Check that the message is received only in supported phase
+ */
+ uint8_t allowed_phases[] = {PHASE_ACTIVE_DECODING, PHASE_PASSIVE_DECODING,
+ PHASE_FINISH_WAITING, PHASE_FINISH_CLOSING};
+ if (GNUNET_OK !=
+ check_valid_phase (allowed_phases,sizeof(allowed_phases),op))
+ {
+ GNUNET_break (0);
+ fail_union_operation (op);
+ return;
+ }
element_size = ntohs (emsg->header.size) - sizeof(struct
GNUNET_SETU_ElementMessage);
- perf_rtt.element.received += 1;
- perf_rtt.element.received_var_bytes += element_size;
+#if MEASURE_PERFORMANCE
+ perf_store.element.received += 1;
+ perf_store.element.received_var_bytes += element_size;
+#endif
ee = GNUNET_malloc (sizeof(struct ElementEntry) + element_size);
GNUNET_memcpy (&ee[1],
@@ -2129,6 +3350,21 @@ handle_union_p2p_elements (void *cls,
return;
}
+ if (GNUNET_OK !=
+ update_message_control_flow (
+ op->message_control_flow,
+ MSG_CFS_RECEIVED,
+ &ee->element_hash,
+ ELEMENT_MESSAGE)
+ )
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ "An element has been received more than once!\n");
+ GNUNET_break (0);
+ fail_union_operation (op);
+ return;
+ }
+
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Got element (size %u, hash %s) from peer\n",
(unsigned int) element_size,
@@ -2217,33 +3453,25 @@ handle_union_p2p_full_element (void *cls,
struct KeyEntry *ke;
uint16_t element_size;
-
-
- if(PHASE_EXPECT_IBF == op->phase) {
- op->phase = PHASE_FULL_RECEIVING;
- }
-
-
-
- /* Allow only receiving of full element message if in expect IBF or in PHASE_FULL_RECEIVING state */
- if ((PHASE_FULL_RECEIVING != op->phase) &&
- (PHASE_FULL_SENDING != op->phase))
+ /**
+ * Check that the message is received only in supported phase
+ */
+ uint8_t allowed_phases[] = {PHASE_FULL_RECEIVING, PHASE_FULL_SENDING};
+ if (GNUNET_OK !=
+ check_valid_phase (allowed_phases,sizeof(allowed_phases),op))
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Handle full element phase is %u\n",
- (unsigned) op->phase);
- GNUNET_break_op (0);
- fail_union_operation (op);
- return;
+ GNUNET_break (0);
+ fail_union_operation (op);
+ return;
}
-
-
element_size = ntohs (emsg->header.size)
- sizeof(struct GNUNET_SETU_ElementMessage);
- perf_rtt.element_full.received += 1;
- perf_rtt.element_full.received_var_bytes += element_size;
+#if MEASURE_PERFORMANCE
+ perf_store.element_full.received += 1;
+ perf_store.element_full.received_var_bytes += element_size;
+#endif
ee = GNUNET_malloc (sizeof(struct ElementEntry) + element_size);
GNUNET_memcpy (&ee[1], &emsg[1], element_size);
@@ -2268,17 +3496,15 @@ handle_union_p2p_full_element (void *cls,
GNUNET_NO);
op->received_total++;
-
ke = op_get_element (op,
&ee->element_hash);
if (NULL != ke)
{
- /* Got repeated element. Should not happen since
- * we track demands. */
GNUNET_STATISTICS_update (_GSS_statistics,
"# repeated elements",
1,
GNUNET_NO);
+ full_sync_plausibility_check (op);
ke->received = GNUNET_YES;
GNUNET_free (ee);
}
@@ -2294,15 +3520,15 @@ handle_union_p2p_full_element (void *cls,
GNUNET_SETU_STATUS_ADD_LOCAL);
}
+
if ((GNUNET_YES == op->byzantine) &&
- (op->received_total > 384 + op->received_fresh * 4) &&
- (op->received_fresh < op->received_total / 6))
+ (op->received_total > op->remote_element_count) )
{
/* The other peer gave us lots of old elements, there's something wrong. */
LOG (GNUNET_ERROR_TYPE_ERROR,
- "Other peer sent only %llu/%llu fresh elements, failing operation\n",
- (unsigned long long) op->received_fresh,
- (unsigned long long) op->received_total);
+ "Other peer sent %llu elements while pretending to have %llu elements, failing operation\n",
+ (unsigned long long) op->received_total,
+ (unsigned long long) op->remote_element_count);
GNUNET_break_op (0);
fail_union_operation (op);
return;
@@ -2356,18 +3582,50 @@ handle_union_p2p_inquiry (void *cls,
const struct IBF_Key *ibf_key;
unsigned int num_keys;
- perf_rtt.inquery.received += 1;
- perf_rtt.inquery.received_var_bytes += (ntohs (msg->header.size) - sizeof(struct InquiryMessage));
+ /**
+ * Check that the message is received only in supported phase
+ */
+ uint8_t allowed_phases[] = {PHASE_ACTIVE_DECODING, PHASE_PASSIVE_DECODING};
+ if (GNUNET_OK !=
+ check_valid_phase (allowed_phases,sizeof(allowed_phases),op))
+ {
+ GNUNET_break (0);
+ fail_union_operation (op);
+ return;
+ }
+
+#if MEASURE_PERFORMANCE
+ perf_store.inquery.received += 1;
+ perf_store.inquery.received_var_bytes += (ntohs (msg->header.size)
+ - sizeof(struct InquiryMessage));
+#endif
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Received union inquiry\n");
num_keys = (ntohs (msg->header.size) - sizeof(struct InquiryMessage))
/ sizeof(struct IBF_Key);
ibf_key = (const struct IBF_Key *) &msg[1];
+
+ /** Add received inquiries to hashmap for flow control **/
+ struct GNUNET_HashContext *hashed_key_context =
+ GNUNET_CRYPTO_hash_context_start ();
+ struct GNUNET_HashCode *hashed_key = (struct GNUNET_HashCode*) GNUNET_malloc (
+ sizeof(struct GNUNET_HashCode));;
+ enum MESSAGE_CONTROL_FLOW_STATE mcfs = MSG_CFS_RECEIVED;
+ GNUNET_CRYPTO_hash_context_read (hashed_key_context,
+ &ibf_key,
+ sizeof(struct IBF_Key));
+ GNUNET_CRYPTO_hash_context_finish (hashed_key_context,
+ hashed_key);
+ GNUNET_CONTAINER_multihashmap_put (op->inquiries_sent,
+ hashed_key,
+ &mcfs,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE
+ );
+
while (0 != num_keys--)
{
struct IBF_Key unsalted_key;
-
unsalt_key (ibf_key,
ntohl (msg->salt),
&unsalted_key);
@@ -2402,7 +3660,9 @@ send_missing_full_elements_iter (void *cls,
if (GNUNET_YES == ke->received)
return GNUNET_YES;
- perf_rtt.element_full.received += 1;
+#if MEASURE_PERFORMANCE
+ perf_store.element_full.received += 1;
+#endif
ev = GNUNET_MQ_msg_extra (emsg,
ee->element.size,
GNUNET_MESSAGE_TYPE_SETU_P2P_FULL_ELEMENT);
@@ -2422,18 +3682,84 @@ send_missing_full_elements_iter (void *cls,
* @param cls closure, a set union operation
* @param mh the demand message
*/
+static int
+check_union_p2p_request_full (void *cls,
+ const struct TransmitFullMessage *mh)
+{
+ return GNUNET_OK;
+}
+
+
static void
handle_union_p2p_request_full (void *cls,
- const struct GNUNET_MessageHeader *mh)
+ const struct TransmitFullMessage *msg)
{
struct Operation *op = cls;
- perf_rtt.request_full.received += 1;
+ /**
+ * Check that the message is received only in supported phase
+ */
+ uint8_t allowed_phases[] = {PHASE_EXPECT_IBF};
+ if (GNUNET_OK !=
+ check_valid_phase (allowed_phases,sizeof(allowed_phases),op))
+ {
+ GNUNET_break (0);
+ fail_union_operation (op);
+ return;
+ }
- LOG (GNUNET_ERROR_TYPE_DEBUG,
+ op->remote_element_count = ntohl (msg->remote_set_size);
+ op->remote_set_diff = ntohl (msg->remote_set_difference);
+ op->local_set_diff = ntohl (msg->local_set_difference);
+
+
+ if (check_byzantine_bounds (op) != GNUNET_OK)
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ "PROTOCOL VIOLATION: Parameters transmitted from other peer do not satisfie byzantine "
+ "criteria\n");
+ GNUNET_break_op (0);
+ fail_union_operation (op);
+ return;
+ }
+
+#if MEASURE_PERFORMANCE
+ perf_store.request_full.received += 1;
+#endif
+
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
"Received request for full set transmission\n");
- if (PHASE_EXPECT_IBF != op->phase)
+
+ /** Calculate avg element size if not initial sync **/
+ op->local_element_count = GNUNET_CONTAINER_multihashmap_size (
+ op->set->content->elements);
+ uint64_t avg_element_size = 0;
+ if (0 < op->local_element_count)
+ {
+ op->total_elements_size_local = 0;
+ GNUNET_CONTAINER_multihashmap_iterate (op->set->content->elements,
+ &
+ determinate_avg_element_size_iterator,
+ op);
+ avg_element_size = op->total_elements_size_local / op->local_element_count;
+ }
+
+ int mode_of_operation = estimate_best_mode_of_operation (avg_element_size,
+ op->
+ remote_element_count,
+ op->
+ local_element_count,
+ op->local_set_diff,
+ op->remote_set_diff,
+ op->
+ rtt_bandwidth_tradeoff,
+ op->
+ ibf_bucket_number_factor);
+ if (FULL_SYNC_REMOTE_SENDING_FIRST != mode_of_operation)
{
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ "PROTOCOL VIOLATION: Remote peer choose to request the full set first but correct mode would have been"
+ " : %d\n", mode_of_operation);
GNUNET_break_op (0);
fail_union_operation (op);
return;
@@ -2458,7 +3784,21 @@ handle_union_p2p_full_done (void *cls,
{
struct Operation *op = cls;
- perf_rtt.full_done.received += 1;
+ /**
+ * Check that the message is received only in supported phase
+ */
+ uint8_t allowed_phases[] = {PHASE_FULL_SENDING, PHASE_FULL_RECEIVING};
+ if (GNUNET_OK !=
+ check_valid_phase (allowed_phases,sizeof(allowed_phases),op))
+ {
+ GNUNET_break (0);
+ fail_union_operation (op);
+ return;
+ }
+
+#if MEASURE_PERFORMANCE
+ perf_store.full_done.received += 1;
+#endif
switch (op->phase)
{
@@ -2466,6 +3806,19 @@ handle_union_p2p_full_done (void *cls,
{
struct GNUNET_MQ_Envelope *ev;
+ if ((GNUNET_YES == op->byzantine) &&
+ (op->received_total != op->remote_element_count) )
+ {
+ /* The other peer gave not enough elements before sending full done, there's something wrong. */
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ "Other peer sent only %llu/%llu fresh elements, failing operation\n",
+ (unsigned long long) op->received_total,
+ (unsigned long long) op->remote_element_count);
+ GNUNET_break_op (0);
+ fail_union_operation (op);
+ return;
+ }
+
LOG (GNUNET_ERROR_TYPE_DEBUG,
"got FULL DONE, sending elements that other peer is missing\n");
@@ -2473,7 +3826,9 @@ handle_union_p2p_full_done (void *cls,
GNUNET_CONTAINER_multihashmap32_iterate (op->key_to_element,
&send_missing_full_elements_iter,
op);
- perf_rtt.full_done.sent += 1;
+#if MEASURE_PERFORMANCE
+ perf_store.full_done.sent += 1;
+#endif
ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_SETU_P2P_FULL_DONE);
GNUNET_MQ_send (op->mq,
ev);
@@ -2552,8 +3907,23 @@ handle_union_p2p_demand (void *cls,
unsigned int num_hashes;
struct GNUNET_MQ_Envelope *ev;
- perf_rtt.demand.received += 1;
- perf_rtt.demand.received_var_bytes += (ntohs (mh->size) - sizeof(struct GNUNET_MessageHeader));
+ /**
+ * Check that the message is received only in supported phase
+ */
+ uint8_t allowed_phases[] = {PHASE_ACTIVE_DECODING, PHASE_PASSIVE_DECODING,
+ PHASE_FINISH_WAITING};
+ if (GNUNET_OK !=
+ check_valid_phase (allowed_phases,sizeof(allowed_phases),op))
+ {
+ GNUNET_break (0);
+ fail_union_operation (op);
+ return;
+ }
+#if MEASURE_PERFORMANCE
+ perf_store.demand.received += 1;
+ perf_store.demand.received_var_bytes += (ntohs (mh->size) - sizeof(struct
+ GNUNET_MessageHeader));
+#endif
num_hashes = (ntohs (mh->size) - sizeof(struct GNUNET_MessageHeader))
/ sizeof(struct GNUNET_HashCode);
@@ -2570,6 +3940,39 @@ handle_union_p2p_demand (void *cls,
fail_union_operation (op);
return;
}
+
+ /* Save send demand message for message control */
+ if (GNUNET_YES !=
+ update_message_control_flow (
+ op->message_control_flow,
+ MSG_CFS_RECEIVED,
+ &ee->element_hash,
+ DEMAND_MESSAGE)
+ )
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ "Double demand message received found!\n");
+ GNUNET_break (0);
+ fail_union_operation (op);
+ return;
+ }
+ ;
+
+ /* Mark element to be expected to received */
+ if (GNUNET_YES !=
+ update_message_control_flow (
+ op->message_control_flow,
+ MSG_CFS_SENT,
+ &ee->element_hash,
+ ELEMENT_MESSAGE)
+ )
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ "Double element message sent found!\n");
+ GNUNET_break (0);
+ fail_union_operation (op);
+ return;
+ }
if (GNUNET_NO == _GSS_is_element_of_operation (ee, op))
{
/* Probably confused lazily copied sets. */
@@ -2577,8 +3980,10 @@ handle_union_p2p_demand (void *cls,
fail_union_operation (op);
return;
}
- perf_rtt.element.sent += 1;
- perf_rtt.element.sent_var_bytes += ee->element.size;
+#if MEASURE_PERFORMANCE
+ perf_store.element.sent += 1;
+ perf_store.element.sent_var_bytes += ee->element.size;
+#endif
ev = GNUNET_MQ_msg_extra (emsg,
ee->element.size,
GNUNET_MESSAGE_TYPE_SETU_P2P_ELEMENTS);
@@ -2600,9 +4005,10 @@ handle_union_p2p_demand (void *cls,
if (op->symmetric)
send_client_element (op,
&ee->element,
- GNUNET_SET_STATUS_ADD_REMOTE);
+ GNUNET_SETU_STATUS_ADD_REMOTE);
}
GNUNET_CADET_receive_done (op->channel);
+ maybe_finish (op);
}
@@ -2653,9 +4059,23 @@ handle_union_p2p_offer (void *cls,
struct Operation *op = cls;
const struct GNUNET_HashCode *hash;
unsigned int num_hashes;
+ /**
+ * Check that the message is received only in supported phase
+ */
+ uint8_t allowed_phases[] = {PHASE_ACTIVE_DECODING, PHASE_PASSIVE_DECODING};
+ if (GNUNET_OK !=
+ check_valid_phase (allowed_phases,sizeof(allowed_phases),op))
+ {
+ GNUNET_break (0);
+ fail_union_operation (op);
+ return;
+ }
- perf_rtt.offer.received += 1;
- perf_rtt.offer.received_var_bytes += (ntohs (mh->size) - sizeof(struct GNUNET_MessageHeader));
+#if MEASURE_PERFORMANCE
+ perf_store.offer.received += 1;
+ perf_store.offer.received_var_bytes += (ntohs (mh->size) - sizeof(struct
+ GNUNET_MessageHeader));
+#endif
num_hashes = (ntohs (mh->size) - sizeof(struct GNUNET_MessageHeader))
/ sizeof(struct GNUNET_HashCode);
@@ -2693,8 +4113,53 @@ handle_union_p2p_offer (void *cls,
"[OP %p] Requesting element (hash %s)\n",
op, GNUNET_h2s (hash));
- perf_rtt.demand.sent += 1;
- perf_rtt.demand.sent_var_bytes += sizeof(struct GNUNET_HashCode);
+#if MEASURE_PERFORMANCE
+ perf_store.demand.sent += 1;
+ perf_store.demand.sent_var_bytes += sizeof(struct GNUNET_HashCode);
+#endif
+ /* Save send demand message for message control */
+ if (GNUNET_YES !=
+ update_message_control_flow (
+ op->message_control_flow,
+ MSG_CFS_SENT,
+ hash,
+ DEMAND_MESSAGE))
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ "Double demand message sent found!\n");
+ GNUNET_break (0);
+ fail_union_operation (op);
+ return;
+ }
+
+ /* Mark offer as received received */
+ if (GNUNET_YES !=
+ update_message_control_flow (
+ op->message_control_flow,
+ MSG_CFS_RECEIVED,
+ hash,
+ OFFER_MESSAGE))
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ "Double offer message received found!\n");
+ GNUNET_break (0);
+ fail_union_operation (op);
+ return;
+ }
+ /* Mark element to be expected to received */
+ if (GNUNET_YES !=
+ update_message_control_flow (
+ op->message_control_flow,
+ MSG_CFS_EXPECTED,
+ hash,
+ ELEMENT_MESSAGE))
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ "Element already expected!\n");
+ GNUNET_break (0);
+ fail_union_operation (op);
+ return;
+ }
ev = GNUNET_MQ_msg_header_extra (demands,
sizeof(struct GNUNET_HashCode),
GNUNET_MESSAGE_TYPE_SETU_P2P_DEMAND);
@@ -2719,7 +4184,30 @@ handle_union_p2p_done (void *cls,
{
struct Operation *op = cls;
- perf_rtt.done.received += 1;
+ /**
+ * Check that the message is received only in supported phase
+ */
+ uint8_t allowed_phases[] = {PHASE_ACTIVE_DECODING, PHASE_PASSIVE_DECODING};
+ if (GNUNET_OK !=
+ check_valid_phase (allowed_phases,sizeof(allowed_phases),op))
+ {
+ GNUNET_break (0);
+ fail_union_operation (op);
+ return;
+ }
+
+ if (op->active_passive_switch_required)
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ "PROTOCOL VIOLATION: Received done but role change is necessary\n");
+ GNUNET_break (0);
+ fail_union_operation (op);
+ return;
+ }
+
+#if MEASURE_PERFORMANCE
+ perf_store.done.received += 1;
+#endif
switch (op->phase)
{
case PHASE_PASSIVE_DECODING:
@@ -2728,26 +4216,26 @@ handle_union_p2p_done (void *cls,
LOG (GNUNET_ERROR_TYPE_DEBUG,
"got DONE (as passive partner), waiting for our demands to be satisfied\n");
/* The active peer is done sending offers
- * and inquiries. This means that all
- * our responses to that (demands and offers)
- * must be in flight (queued or in mesh).
- *
- * We should notify the active peer once
- * all our demands are satisfied, so that the active
- * peer can quit if we gave it everything.
- */GNUNET_CADET_receive_done (op->channel);
+ * and inquiries. This means that all
+ * our responses to that (demands and offers)
+ * must be in flight (queued or in mesh).
+ *
+ * We should notify the active peer once
+ * all our demands are satisfied, so that the active
+ * peer can quit if we gave it everything.
+ */GNUNET_CADET_receive_done (op->channel);
maybe_finish (op);
return;
case PHASE_ACTIVE_DECODING:
LOG (GNUNET_ERROR_TYPE_DEBUG,
"got DONE (as active partner), waiting to finish\n");
/* All demands of the other peer are satisfied,
- * and we processed all offers, thus we know
- * exactly what our demands must be.
- *
- * We'll close the channel
- * to the other peer once our demands are met.
- */op->phase = PHASE_FINISH_CLOSING;
+ * and we processed all offers, thus we know
+ * exactly what our demands must be.
+ *
+ * We'll close the channel
+ * to the other peer once our demands are met.
+ */op->phase = PHASE_FINISH_CLOSING;
GNUNET_CADET_receive_done (op->channel);
maybe_finish (op);
return;
@@ -2769,7 +4257,9 @@ static void
handle_union_p2p_over (void *cls,
const struct GNUNET_MessageHeader *mh)
{
- perf_rtt.over.received += 1;
+#if MEASURE_PERFORMANCE
+ perf_store.over.received += 1;
+#endif
send_client_done (cls);
}
@@ -2943,7 +4433,7 @@ check_incoming_msg (void *cls,
struct Listener *listener = op->listener;
const struct GNUNET_MessageHeader *nested_context;
- /* double operation request */
+ /* double operation request */
if (0 != op->suggest_id)
{
GNUNET_break_op (0);
@@ -3053,10 +4543,10 @@ handle_client_create_set (void *cls,
}
set = GNUNET_new (struct Set);
{
- struct StrataEstimator *se;
+ struct MultiStrataEstimator *se;
se = strata_estimator_create (SE_STRATA_COUNT,
- SE_IBF_SIZE,
+ SE_IBFS_TOTAL_SIZE,
SE_IBF_HASH_NUM);
if (NULL == se)
{
@@ -3198,6 +4688,7 @@ channel_window_cb (void *cls,
* @param cls client that sent the message
* @param msg message sent by the client
*/
+
static void
handle_client_listen (void *cls,
const struct GNUNET_SETU_ListenMessage *msg)
@@ -3240,10 +4731,10 @@ handle_client_listen (void *cls,
GNUNET_MESSAGE_TYPE_SETU_P2P_FULL_DONE,
struct GNUNET_MessageHeader,
NULL),
- GNUNET_MQ_hd_fixed_size (union_p2p_request_full,
- GNUNET_MESSAGE_TYPE_SETU_P2P_REQUEST_FULL,
- struct GNUNET_MessageHeader,
- NULL),
+ GNUNET_MQ_hd_var_size (union_p2p_request_full,
+ GNUNET_MESSAGE_TYPE_SETU_P2P_REQUEST_FULL,
+ struct TransmitFullMessage,
+ NULL),
GNUNET_MQ_hd_var_size (union_p2p_strata_estimator,
GNUNET_MESSAGE_TYPE_SETU_P2P_SE,
struct StrataEstimatorMessage,
@@ -3256,6 +4747,10 @@ handle_client_listen (void *cls,
GNUNET_MESSAGE_TYPE_SETU_P2P_FULL_ELEMENT,
struct GNUNET_SETU_ElementMessage,
NULL),
+ GNUNET_MQ_hd_var_size (union_p2p_send_full,
+ GNUNET_MESSAGE_TYPE_SETU_P2P_SEND_FULL,
+ struct TransmitFullMessage,
+ NULL),
GNUNET_MQ_handler_end ()
};
struct Listener *listener;
@@ -3451,6 +4946,7 @@ handle_client_evaluate (void *cls,
{
struct ClientState *cs = cls;
struct Operation *op = GNUNET_new (struct Operation);
+
const struct GNUNET_MQ_MessageHandler cadet_handlers[] = {
GNUNET_MQ_hd_var_size (incoming_msg,
GNUNET_MESSAGE_TYPE_SETU_P2P_OPERATION_REQUEST,
@@ -3488,10 +4984,10 @@ handle_client_evaluate (void *cls,
GNUNET_MESSAGE_TYPE_SETU_P2P_FULL_DONE,
struct GNUNET_MessageHeader,
op),
- GNUNET_MQ_hd_fixed_size (union_p2p_request_full,
- GNUNET_MESSAGE_TYPE_SETU_P2P_REQUEST_FULL,
- struct GNUNET_MessageHeader,
- op),
+ GNUNET_MQ_hd_var_size (union_p2p_request_full,
+ GNUNET_MESSAGE_TYPE_SETU_P2P_REQUEST_FULL,
+ struct TransmitFullMessage,
+ op),
GNUNET_MQ_hd_var_size (union_p2p_strata_estimator,
GNUNET_MESSAGE_TYPE_SETU_P2P_SE,
struct StrataEstimatorMessage,
@@ -3504,6 +5000,10 @@ handle_client_evaluate (void *cls,
GNUNET_MESSAGE_TYPE_SETU_P2P_FULL_ELEMENT,
struct GNUNET_SETU_ElementMessage,
op),
+ GNUNET_MQ_hd_var_size (union_p2p_send_full,
+ GNUNET_MESSAGE_TYPE_SETU_P2P_SEND_FULL,
+ struct TransmitFullMessage,
+ NULL),
GNUNET_MQ_handler_end ()
};
struct Set *set;
@@ -3525,8 +5025,23 @@ handle_client_evaluate (void *cls,
op->force_full = msg->force_full;
op->force_delta = msg->force_delta;
op->symmetric = msg->symmetric;
+ op->rtt_bandwidth_tradeoff = msg->bandwidth_latency_tradeoff;
+ op->ibf_bucket_number_factor = msg->ibf_bucket_number_factor;
+ op->ibf_number_buckets_per_element = msg->ibf_number_of_buckets_per_element;
+ op->byzantine_upper_bound = msg->byzantine_upper_bond;
+ op->active_passive_switch_required = false;
context = GNUNET_MQ_extract_nested_mh (msg);
+ /* create hashmap for message control */
+ op->message_control_flow = GNUNET_CONTAINER_multihashmap_create (32,
+ GNUNET_NO);
+ op->inquiries_sent = GNUNET_CONTAINER_multihashmap_create (32,GNUNET_NO);
+
+#if MEASURE_PERFORMANCE
+ /* load config */
+ load_config (op);
+#endif
+
/* Advance generation values, so that
mutations won't interfer with the running operation. */
op->set = set;
@@ -3550,7 +5065,9 @@ handle_client_evaluate (void *cls,
struct GNUNET_MQ_Envelope *ev;
struct OperationRequestMessage *msg;
- perf_rtt.operation_request.sent += 1;
+#if MEASURE_PERFORMANCE
+ perf_store.operation_request.sent += 1;
+#endif
ev = GNUNET_MQ_msg_nested_mh (msg,
GNUNET_MESSAGE_TYPE_SETU_P2P_OPERATION_REQUEST,
context);
@@ -3567,7 +5084,11 @@ handle_client_evaluate (void *cls,
op->se = strata_estimator_dup (op->set->se);
/* we started the operation, thus we have to send the operation request */
op->phase = PHASE_EXPECT_SE;
- op->salt_receive = op->salt_send = 42; // FIXME?????
+
+ op->salt_receive = (op->peer_site + 1) % 2;
+ op->salt_send = op->peer_site; // FIXME?????
+
+
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Initiating union operation evaluation\n");
GNUNET_STATISTICS_update (_GSS_statistics,
@@ -3711,6 +5232,20 @@ handle_client_accept (void *cls,
op->force_full = msg->force_full;
op->force_delta = msg->force_delta;
op->symmetric = msg->symmetric;
+ op->rtt_bandwidth_tradeoff = msg->bandwidth_latency_tradeoff;
+ op->ibf_bucket_number_factor = msg->ibf_bucket_number_factor;
+ op->ibf_number_buckets_per_element = msg->ibf_number_of_buckets_per_element;
+ op->byzantine_upper_bound = msg->byzantine_upper_bond;
+ op->active_passive_switch_required = false;
+ /* create hashmap for message control */
+ op->message_control_flow = GNUNET_CONTAINER_multihashmap_create (32,
+ GNUNET_NO);
+ op->inquiries_sent = GNUNET_CONTAINER_multihashmap_create (32,GNUNET_NO);
+
+#if MEASURE_PERFORMANCE
+ /* load config */
+ load_config (op);
+#endif
/* Advance generation values, so that future mutations do not
interfer with the running operation. */
@@ -3729,7 +5264,7 @@ handle_client_accept (void *cls,
1,
GNUNET_NO);
{
- const struct StrataEstimator *se;
+ struct MultiStrataEstimator *se;
struct GNUNET_MQ_Envelope *ev;
struct StrataEstimatorMessage *strata_msg;
char *buf;
@@ -3739,20 +5274,40 @@ handle_client_accept (void *cls,
op->se = strata_estimator_dup (op->set->se);
op->demanded_hashes = GNUNET_CONTAINER_multihashmap_create (32,
GNUNET_NO);
- op->salt_receive = op->salt_send = 42; // FIXME?????
+ op->salt_receive = (op->peer_site + 1) % 2;
+ op->salt_send = op->peer_site; // FIXME?????
initialize_key_to_element (op);
op->initial_size = GNUNET_CONTAINER_multihashmap32_size (
op->key_to_element);
/* kick off the operation */
se = op->se;
- buf = GNUNET_malloc (se->strata_count * IBF_BUCKET_SIZE * se->ibf_size);
+
+ uint8_t se_count = 1;
+ if (op->initial_size > 0)
+ {
+ op->total_elements_size_local = 0;
+ GNUNET_CONTAINER_multihashmap_iterate (op->set->content->elements,
+ &
+ determinate_avg_element_size_iterator,
+ op);
+ se_count = determine_strata_count (
+ op->total_elements_size_local / op->initial_size,
+ op->initial_size);
+ }
+ buf = GNUNET_malloc (se->stratas[0]->strata_count * IBF_BUCKET_SIZE
+ * ((SE_IBFS_TOTAL_SIZE / 8) * se_count));
len = strata_estimator_write (se,
+ SE_IBFS_TOTAL_SIZE,
+ se_count,
buf);
- perf_rtt.se.sent += 1;
- perf_rtt.se.sent_var_bytes += len;
+#if MEASURE_PERFORMANCE
+ perf_store.se.sent += 1;
+ perf_store.se.sent_var_bytes += len;
+#endif
- if (len < se->strata_count * IBF_BUCKET_SIZE * se->ibf_size)
+ if (len < se->stratas[0]->strata_count * IBF_BUCKET_SIZE
+ * SE_IBFS_TOTAL_SIZE)
type = GNUNET_MESSAGE_TYPE_SETU_P2P_SEC;
else
type = GNUNET_MESSAGE_TYPE_SETU_P2P_SE;
@@ -3766,6 +5321,7 @@ handle_client_accept (void *cls,
strata_msg->set_size
= GNUNET_htonll (GNUNET_CONTAINER_multihashmap_size (
op->set->content->elements));
+ strata_msg->se_count = se_count;
GNUNET_MQ_send (op->mq,
ev);
op->phase = PHASE_EXPECT_IBF;
@@ -3800,8 +5356,9 @@ shutdown_task (void *cls)
GNUNET_YES);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"handled shutdown request\n");
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "RTT:%f\n", calculate_perf_rtt());
+#if MEASURE_PERFORMANCE
+ calculate_perf_store ();
+#endif
}
diff --git a/src/setu/gnunet-service-setu_protocol.h b/src/setu/gnunet-service-setu_protocol.h
index a2803ee47..c2a166e60 100644
--- a/src/setu/gnunet-service-setu_protocol.h
+++ b/src/setu/gnunet-service-setu_protocol.h
@@ -40,11 +40,6 @@ struct OperationRequestMessage
struct GNUNET_MessageHeader header;
/**
- * Operation to request, values from `enum GNUNET_SET_OperationType`
- */
- uint32_t operation GNUNET_PACKED;
-
- /**
* For Intersection: my element count
*/
uint32_t element_count GNUNET_PACKED;
@@ -72,20 +67,9 @@ struct IBFMessage
struct GNUNET_MessageHeader header;
/**
- * Order of the whole ibf, where
- * num_buckets = 2^order
- */
- uint8_t order;
-
- /**
- * Padding, must be 0.
+ * Size of the whole ibf (number of buckets)
*/
- uint8_t reserved1;
-
- /**
- * Padding, must be 0.
- */
- uint16_t reserved2 GNUNET_PACKED;
+ uint32_t ibf_size;
/**
* Offset of the strata in the rest of the message
@@ -95,12 +79,25 @@ struct IBFMessage
/**
* Salt used when hashing elements for this IBF.
*/
- uint32_t salt GNUNET_PACKED;
+ uint16_t salt GNUNET_PACKED;
+ /**
+ * The bit length of the counter
+ */
+ uint16_t ibf_counter_bit_length;
/* rest: buckets */
};
+/**
+estimate_best_mode_of_operation (uint64_t avg_element_size,
+uint64_t local_set_size,
+ uint64_t remote_set_size,
+uint64_t est_set_diff_remote,
+ uint64_t est_set_diff_local,)
+ **/
+
+
struct InquiryMessage
{
/**
@@ -113,11 +110,6 @@ struct InquiryMessage
*/
uint32_t salt GNUNET_PACKED;
- /**
- * Reserved, set to 0.
- */
- uint32_t reserved GNUNET_PACKED;
-
/* rest: inquiry IBF keys */
};
@@ -218,9 +210,47 @@ struct StrataEstimatorMessage
*/
struct GNUNET_MessageHeader header;
+ /**
+ * The number of ses transmitted
+ */
+ uint8_t se_count;
+
+ /**
+ * Size of the local set
+ */
uint64_t set_size;
};
+
+/**
+ * Message which signals to other peer that we are sending full set
+ *
+ */
+struct TransmitFullMessage
+{
+ /**
+ * Type: #GNUNET_MESSAGE_TYPE_SETU_P2P_SEND_FULL
+ */
+ struct GNUNET_MessageHeader header;
+
+ /**
+ * Remote set difference calculated with strata estimator
+ */
+ uint32_t remote_set_difference;
+
+ /**
+ * Total remote set size
+ */
+ uint32_t remote_set_size;
+
+ /**
+ * Local set difference calculated with strata estimator
+ */
+ uint32_t local_set_difference;
+
+};
+
+
GNUNET_NETWORK_STRUCT_END
#endif
diff --git a/src/setu/gnunet-service-setu_strata_estimator.c b/src/setu/gnunet-service-setu_strata_estimator.c
index 7c9a4deb6..7981cc847 100644
--- a/src/setu/gnunet-service-setu_strata_estimator.c
+++ b/src/setu/gnunet-service-setu_strata_estimator.c
@@ -22,6 +22,7 @@
* @brief invertible bloom filter
* @author Florian Dold
* @author Christian Grothoff
+ * @author Elias Summermatter
*/
#include "platform.h"
#include "gnunet_util_lib.h"
@@ -30,6 +31,82 @@
/**
+ * Should we try compressing the strata estimator? This will
+ * break compatibility with the 0.10.1-network.
+ */
+#define FAIL_10_1_COMPATIBILTIY 1
+
+/**
+ * Number of strata estimators in memory NOT transmitted
+ */
+
+#define MULTI_SE_BASE_COUNT 8
+
+/**
+ * The avg size of 1 se
+ * Based on the bsc thesis of Elias Summermatter (2021)
+ */
+
+#define AVG_BYTE_SIZE_SE 4221
+
+/**
+ * Calculates the optimal number of strata Estimators to send
+ * @param avg_element_size
+ * @param element_count
+ * @return
+ */
+uint8_t
+determine_strata_count (uint64_t avg_element_size, uint64_t element_count)
+{
+ uint64_t base_size = avg_element_size * element_count;
+ /* >67kb total size of elements in set */
+ if (base_size < AVG_BYTE_SIZE_SE * 16)
+ return 1;
+ /* >270kb total size of elements in set */
+ if (base_size < AVG_BYTE_SIZE_SE * 64)
+ return 2;
+ /* >1mb total size of elements in set */
+ if (base_size < AVG_BYTE_SIZE_SE * 256)
+ return 4;
+ return 8;
+}
+
+
+/**
+ * Modify an IBF key @a k_in based on the @a salt, returning a
+ * salted key in @a k_out.
+ */
+static void
+salt_key (const struct IBF_Key *k_in,
+ uint32_t salt,
+ struct IBF_Key *k_out)
+{
+ int s = (salt * 7) % 64;
+ uint64_t x = k_in->key_val;
+
+ /* rotate ibf key */
+ x = (x >> s) | (x << (64 - s));
+ k_out->key_val = x;
+}
+
+
+/**
+ * Reverse modification done in the salt_key function
+ */
+static void
+unsalt_key (const struct IBF_Key *k_in,
+ uint32_t salt,
+ struct IBF_Key *k_out)
+{
+ int s = (salt * 7) % 64;
+ uint64_t x = k_in->key_val;
+
+ x = (x << s) | (x >> (64 - s));
+ k_out->key_val = x;
+}
+
+
+/**
* Write the given strata estimator to the buffer.
*
* @param se strata estimator to serialize
@@ -37,21 +114,33 @@
* @return number of bytes written to @a buf
*/
size_t
-strata_estimator_write (const struct StrataEstimator *se,
+strata_estimator_write (struct MultiStrataEstimator *se,
+ uint16_t se_ibf_total_size,
+ uint8_t number_se_send,
void *buf)
{
char *sbuf = buf;
+ unsigned int i;
size_t osize;
+ uint64_t sbuf_offset = 0;
+ se->size = number_se_send;
GNUNET_assert (NULL != se);
- for (unsigned int i = 0; i < se->strata_count; i++)
+ for (uint8_t strata_ctr = 0; strata_ctr < number_se_send; strata_ctr++)
{
- ibf_write_slice (se->strata[i],
- 0,
- se->ibf_size,
- &sbuf[se->ibf_size * IBF_BUCKET_SIZE * i]);
+ for (i = 0; i < se->stratas[strata_ctr]->strata_count; i++)
+ {
+ ibf_write_slice (se->stratas[strata_ctr]->strata[i],
+ 0,
+ se->stratas[strata_ctr]->ibf_size,
+ &sbuf[sbuf_offset],
+ 8);
+ sbuf_offset += se->stratas[strata_ctr]->ibf_size * IBF_BUCKET_SIZE;
+ }
}
- osize = se->ibf_size * IBF_BUCKET_SIZE * se->strata_count;
+ osize = ((se_ibf_total_size / 8) * number_se_send) * IBF_BUCKET_SIZE
+ * se->stratas[0]->strata_count;
+#if FAIL_10_1_COMPATIBILTIY
{
char *cbuf;
size_t nsize;
@@ -62,13 +151,12 @@ strata_estimator_write (const struct StrataEstimator *se,
&cbuf,
&nsize))
{
- GNUNET_memcpy (buf,
- cbuf,
- nsize);
+ GNUNET_memcpy (buf, cbuf, nsize);
osize = nsize;
GNUNET_free (cbuf);
}
}
+#endif
return osize;
}
@@ -87,15 +175,19 @@ int
strata_estimator_read (const void *buf,
size_t buf_len,
int is_compressed,
- struct StrataEstimator *se)
+ uint8_t number_se_received,
+ uint16_t se_ibf_total_size,
+ struct MultiStrataEstimator *se)
{
+ unsigned int i;
size_t osize;
char *dbuf;
dbuf = NULL;
if (GNUNET_YES == is_compressed)
{
- osize = se->ibf_size * IBF_BUCKET_SIZE * se->strata_count;
+ osize = ((se_ibf_total_size / 8) * number_se_received) * IBF_BUCKET_SIZE
+ * se->stratas[0]->strata_count;
dbuf = GNUNET_decompress (buf,
buf_len,
osize);
@@ -108,18 +200,25 @@ strata_estimator_read (const void *buf,
buf_len = osize;
}
- if (buf_len != se->strata_count * se->ibf_size * IBF_BUCKET_SIZE)
+ if (buf_len != se->stratas[0]->strata_count * ((se_ibf_total_size / 8)
+ * number_se_received)
+ * IBF_BUCKET_SIZE)
{
GNUNET_break (0); /* very odd error */
GNUNET_free (dbuf);
return GNUNET_SYSERR;
}
- for (unsigned int i = 0; i < se->strata_count; i++)
+ for (uint8_t strata_ctr = 0; strata_ctr < number_se_received; strata_ctr++)
{
- ibf_read_slice (buf, 0, se->ibf_size, se->strata[i]);
- buf += se->ibf_size * IBF_BUCKET_SIZE;
+ for (i = 0; i < se->stratas[strata_ctr]->strata_count; i++)
+ {
+ ibf_read_slice (buf, 0, se->stratas[strata_ctr]->ibf_size,
+ se->stratas[strata_ctr]->strata[i], 8);
+ buf += se->stratas[strata_ctr]->ibf_size * IBF_BUCKET_SIZE;
+ }
}
+ se->size = number_se_received;
GNUNET_free (dbuf);
return GNUNET_OK;
}
@@ -132,38 +231,61 @@ strata_estimator_read (const void *buf,
* @param key key to add
*/
void
-strata_estimator_insert (struct StrataEstimator *se,
+strata_estimator_insert (struct MultiStrataEstimator *se,
struct IBF_Key key)
{
- uint64_t v;
- unsigned int i;
- v = key.key_val;
+
/* count trailing '1'-bits of v */
- for (i = 0; v & 1; v >>= 1, i++)
- /* empty */;
- ibf_insert (se->strata[i], key);
+ for (int strata_ctr = 0; strata_ctr < MULTI_SE_BASE_COUNT; strata_ctr++)
+ {
+ unsigned int i;
+ uint64_t v;
+
+ struct IBF_Key salted_key;
+ salt_key (&key,
+ strata_ctr * (64 / MULTI_SE_BASE_COUNT),
+ &salted_key);
+ v = salted_key.key_val;
+ for (i = 0; v & 1; v >>= 1, i++)
+ {
+ ibf_insert (se->stratas[strata_ctr]->strata[i], salted_key);
+ }
+ }
+ /* empty */;
+
}
/**
- * Remove a key from the strata estimator.
+ * Remove a key from the strata estimator. (NOT USED)
*
* @param se strata estimator to remove the key from
* @param key key to remove
*/
void
-strata_estimator_remove (struct StrataEstimator *se,
+strata_estimator_remove (struct MultiStrataEstimator *se,
struct IBF_Key key)
{
- uint64_t v;
- unsigned int i;
- v = key.key_val;
/* count trailing '1'-bits of v */
- for (i = 0; v & 1; v >>= 1, i++)
- /* empty */;
- ibf_remove (se->strata[i], key);
+ for (int strata_ctr = 0; strata_ctr < se->size; strata_ctr++)
+ {
+ uint64_t v;
+ unsigned int i;
+
+ struct IBF_Key unsalted_key;
+ unsalt_key (&key,
+ strata_ctr * (64 / MULTI_SE_BASE_COUNT),
+ &unsalted_key);
+
+ v = unsalted_key.key_val;
+ for (i = 0; v & 1; v >>= 1, i++)
+ {
+ /* empty */;
+ ibf_remove (se->stratas[strata_ctr]->strata[i], unsalted_key);
+ }
+ }
}
@@ -175,29 +297,42 @@ strata_estimator_remove (struct StrataEstimator *se,
* @param ibf_hashnum hashnum parameter of each ibf
* @return a freshly allocated, empty strata estimator, NULL on error
*/
-struct StrataEstimator *
+struct MultiStrataEstimator *
strata_estimator_create (unsigned int strata_count,
uint32_t ibf_size,
uint8_t ibf_hashnum)
{
- struct StrataEstimator *se;
-
- se = GNUNET_new (struct StrataEstimator);
- se->strata_count = strata_count;
- se->ibf_size = ibf_size;
- se->strata = GNUNET_new_array (strata_count,
- struct InvertibleBloomFilter *);
- for (unsigned int i = 0; i < strata_count; i++)
+ struct MultiStrataEstimator *se;
+ unsigned int i;
+ unsigned int j;
+ se = GNUNET_new (struct MultiStrataEstimator);
+
+ se->size = MULTI_SE_BASE_COUNT;
+ se->stratas = GNUNET_new_array (MULTI_SE_BASE_COUNT,struct StrataEstimator *);
+
+ uint8_t ibf_prime_sizes[] = {79,79,79,79,79,79,79,79};
+
+ for (uint8_t strata_ctr = 0; strata_ctr < MULTI_SE_BASE_COUNT; strata_ctr++)
{
- se->strata[i] = ibf_create (ibf_size, ibf_hashnum);
- if (NULL == se->strata[i])
+ se->stratas[strata_ctr] = GNUNET_new (struct StrataEstimator);
+ se->stratas[strata_ctr]->strata_count = strata_count;
+ se->stratas[strata_ctr]->ibf_size = ibf_prime_sizes[strata_ctr];
+ se->stratas[strata_ctr]->strata = GNUNET_new_array (strata_count * 4,
+ struct
+ InvertibleBloomFilter *);
+ for (i = 0; i < strata_count; i++)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to allocate memory for strata estimator\n");
- for (unsigned int j = 0; j < i; j++)
- ibf_destroy (se->strata[i]);
- GNUNET_free (se);
- return NULL;
+ se->stratas[strata_ctr]->strata[i] = ibf_create (
+ ibf_prime_sizes[strata_ctr], ibf_hashnum);
+ if (NULL == se->stratas[strata_ctr]->strata[i])
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to allocate memory for strata estimator\n");
+ for (j = 0; j < i; j++)
+ ibf_destroy (se->stratas[strata_ctr]->strata[i]);
+ GNUNET_free (se);
+ return NULL;
+ }
}
}
return se;
@@ -213,46 +348,71 @@ strata_estimator_create (unsigned int strata_count,
* @param se2 second strata estimator
* @return the estimated difference
*/
-unsigned int
-strata_estimator_difference (const struct StrataEstimator *se1,
- const struct StrataEstimator *se2)
+void
+strata_estimator_difference (const struct MultiStrataEstimator *se1,
+ const struct MultiStrataEstimator *se2)
{
- unsigned int count;
+ int avg_local_diff = 0;
+ int avg_remote_diff = 0;
+ uint8_t number_of_estimators = se1->size;
- GNUNET_assert (se1->strata_count == se2->strata_count);
- count = 0;
- for (int i = se1->strata_count - 1; i >= 0; i--)
+ for (uint8_t strata_ctr = 0; strata_ctr < number_of_estimators; strata_ctr++)
{
- struct InvertibleBloomFilter *diff;
- /* number of keys decoded from the ibf */
-
- /* FIXME: implement this without always allocating new IBFs */
- diff = ibf_dup (se1->strata[i]);
- ibf_subtract (diff,
- se2->strata[i]);
- for (int ibf_count = 0; GNUNET_YES; ibf_count++)
+ GNUNET_assert (se1->stratas[strata_ctr]->strata_count ==
+ se2->stratas[strata_ctr]->strata_count);
+
+
+ for (int i = se1->stratas[strata_ctr]->strata_count - 1; i >= 0; i--)
{
- int more;
+ struct InvertibleBloomFilter *diff;
+ /* number of keys decoded from the ibf */
- more = ibf_decode (diff,
- NULL,
- NULL);
- if (GNUNET_NO == more)
- {
- count += ibf_count;
- break;
- }
- /* Estimate if decoding fails or would not terminate */
- if ( (GNUNET_SYSERR == more) ||
- (ibf_count > diff->size) )
+ /* FIXME: implement this without always allocating new IBFs */
+ diff = ibf_dup (se1->stratas[strata_ctr]->strata[i]);
+ diff->local_decoded_count = 0;
+ diff->remote_decoded_count = 0;
+
+ ibf_subtract (diff, se2->stratas[strata_ctr]->strata[i]);
+
+ for (int ibf_count = 0; GNUNET_YES; ibf_count++)
{
- ibf_destroy (diff);
- return count * (1 << (i + 1));
+ int more;
+
+ more = ibf_decode (diff, NULL, NULL);
+ if (GNUNET_NO == more)
+ {
+ se1->stratas[strata_ctr]->strata[0]->local_decoded_count +=
+ diff->local_decoded_count;
+ se1->stratas[strata_ctr]->strata[0]->remote_decoded_count +=
+ diff->remote_decoded_count;
+ break;
+ }
+ /* Estimate if decoding fails or would not terminate */
+ if ((GNUNET_SYSERR == more) || (ibf_count > diff->size))
+ {
+ se1->stratas[strata_ctr]->strata[0]->local_decoded_count =
+ se1->stratas[strata_ctr]->strata[0]->local_decoded_count * (1 << (i
+ +
+ 1));
+ se1->stratas[strata_ctr]->strata[0]->remote_decoded_count =
+ se1->stratas[strata_ctr]->strata[0]->remote_decoded_count * (1 << (i
+ +
+ 1));
+ ibf_destroy (diff);
+ goto break_all_counting_loops;
+ }
}
+ ibf_destroy (diff);
}
- ibf_destroy (diff);
+break_all_counting_loops:;
+ avg_local_diff += se1->stratas[strata_ctr]->strata[0]->local_decoded_count;
+ avg_remote_diff +=
+ se1->stratas[strata_ctr]->strata[0]->remote_decoded_count;
}
- return count;
+ se1->stratas[0]->strata[0]->local_decoded_count = avg_local_diff
+ / number_of_estimators;
+ se1->stratas[0]->strata[0]->remote_decoded_count = avg_remote_diff
+ / number_of_estimators;
}
@@ -262,18 +422,28 @@ strata_estimator_difference (const struct StrataEstimator *se1,
* @param se the strata estimator to copy
* @return the copy
*/
-struct StrataEstimator *
-strata_estimator_dup (struct StrataEstimator *se)
+struct MultiStrataEstimator *
+strata_estimator_dup (struct MultiStrataEstimator *se)
{
- struct StrataEstimator *c;
-
- c = GNUNET_new (struct StrataEstimator);
- c->strata_count = se->strata_count;
- c->ibf_size = se->ibf_size;
- c->strata = GNUNET_new_array (se->strata_count,
- struct InvertibleBloomFilter *);
- for (unsigned int i = 0; i < se->strata_count; i++)
- c->strata[i] = ibf_dup (se->strata[i]);
+ struct MultiStrataEstimator *c;
+ unsigned int i;
+
+ c = GNUNET_new (struct MultiStrataEstimator);
+ c->stratas = GNUNET_new_array (MULTI_SE_BASE_COUNT,struct StrataEstimator *);
+ for (uint8_t strata_ctr = 0; strata_ctr < MULTI_SE_BASE_COUNT; strata_ctr++)
+ {
+ c->stratas[strata_ctr] = GNUNET_new (struct StrataEstimator);
+ c->stratas[strata_ctr]->strata_count =
+ se->stratas[strata_ctr]->strata_count;
+ c->stratas[strata_ctr]->ibf_size = se->stratas[strata_ctr]->ibf_size;
+ c->stratas[strata_ctr]->strata = GNUNET_new_array (
+ se->stratas[strata_ctr]->strata_count,
+ struct
+ InvertibleBloomFilter *);
+ for (i = 0; i < se->stratas[strata_ctr]->strata_count; i++)
+ c->stratas[strata_ctr]->strata[i] = ibf_dup (
+ se->stratas[strata_ctr]->strata[i]);
+ }
return c;
}
@@ -284,10 +454,14 @@ strata_estimator_dup (struct StrataEstimator *se)
* @param se strata estimator to destroy.
*/
void
-strata_estimator_destroy (struct StrataEstimator *se)
+strata_estimator_destroy (struct MultiStrataEstimator *se)
{
- for (unsigned int i = 0; i < se->strata_count; i++)
- ibf_destroy (se->strata[i]);
- GNUNET_free (se->strata);
+ unsigned int i;
+ for (uint8_t strata_ctr = 0; strata_ctr < MULTI_SE_BASE_COUNT; strata_ctr++)
+ {
+ for (i = 0; i < se->stratas[strata_ctr]->strata_count; i++)
+ ibf_destroy (se->stratas[strata_ctr]->strata[i]);
+ GNUNET_free (se->stratas[strata_ctr]->strata);
+ }
GNUNET_free (se);
}
diff --git a/src/setu/gnunet-service-setu_strata_estimator.h b/src/setu/gnunet-service-setu_strata_estimator.h
index afdbcdbbf..4871a7fcd 100644
--- a/src/setu/gnunet-service-setu_strata_estimator.h
+++ b/src/setu/gnunet-service-setu_strata_estimator.h
@@ -22,6 +22,7 @@
* @file set/gnunet-service-setu_strata_estimator.h
* @brief estimator of set difference
* @author Florian Dold
+ * @author Elias Summermatter
*/
#ifndef GNUNET_SERVICE_SETU_STRATA_ESTIMATOR_H
@@ -61,6 +62,31 @@ struct StrataEstimator
unsigned int ibf_size;
};
+struct MultiStrataEstimator
+{
+ /**
+ * Array of strata estimators
+ */
+ struct StrataEstimator **stratas;
+
+ /**
+ * Number of strata estimators in struct
+ */
+ uint8_t size;
+
+};
+
+/**
+ * Deteminate how many strata estimators in the message are necessary
+ * @param avg_element_size
+ * @param element_count
+ * @return number of strata's
+ */
+
+uint8_t
+determine_strata_count (uint64_t avg_element_size,
+ uint64_t element_count);
+
/**
* Write the given strata estimator to the buffer.
@@ -70,7 +96,9 @@ struct StrataEstimator
* @return number of bytes written to @a buf
*/
size_t
-strata_estimator_write (const struct StrataEstimator *se,
+strata_estimator_write (struct MultiStrataEstimator *se,
+ uint16_t se_ibf_total_size,
+ uint8_t number_se_send,
void *buf);
@@ -88,7 +116,9 @@ int
strata_estimator_read (const void *buf,
size_t buf_len,
int is_compressed,
- struct StrataEstimator *se);
+ uint8_t number_se_received,
+ uint16_t se_ibf_total_size,
+ struct MultiStrataEstimator *se);
/**
@@ -99,7 +129,7 @@ strata_estimator_read (const void *buf,
* @param ibf_hashnum hashnum parameter of each ibf
* @return a freshly allocated, empty strata estimator, NULL on error
*/
-struct StrataEstimator *
+struct MultiStrataEstimator *
strata_estimator_create (unsigned int strata_count,
uint32_t ibf_size,
uint8_t ibf_hashnum);
@@ -111,11 +141,11 @@ strata_estimator_create (unsigned int strata_count,
*
* @param se1 first strata estimator
* @param se2 second strata estimator
- * @return abs(|se1| - |se2|)
+ * @return nothing
*/
-unsigned int
-strata_estimator_difference (const struct StrataEstimator *se1,
- const struct StrataEstimator *se2);
+void
+strata_estimator_difference (const struct MultiStrataEstimator *se1,
+ const struct MultiStrataEstimator *se2);
/**
@@ -125,7 +155,7 @@ strata_estimator_difference (const struct StrataEstimator *se1,
* @param key key to add
*/
void
-strata_estimator_insert (struct StrataEstimator *se,
+strata_estimator_insert (struct MultiStrataEstimator *se,
struct IBF_Key key);
@@ -136,7 +166,7 @@ strata_estimator_insert (struct StrataEstimator *se,
* @param key key to remove
*/
void
-strata_estimator_remove (struct StrataEstimator *se,
+strata_estimator_remove (struct MultiStrataEstimator *se,
struct IBF_Key key);
@@ -146,7 +176,7 @@ strata_estimator_remove (struct StrataEstimator *se,
* @param se strata estimator to destroy.
*/
void
-strata_estimator_destroy (struct StrataEstimator *se);
+strata_estimator_destroy (struct MultiStrataEstimator *se);
/**
@@ -155,8 +185,8 @@ strata_estimator_destroy (struct StrataEstimator *se);
* @param se the strata estimator to copy
* @return the copy
*/
-struct StrataEstimator *
-strata_estimator_dup (struct StrataEstimator *se);
+struct MultiStrataEstimator *
+strata_estimator_dup (struct MultiStrataEstimator *se);
#if 0 /* keep Emacsens' auto-indent happy */
diff --git a/src/setu/ibf.c b/src/setu/ibf.c
index 1beba9065..dbd23c320 100644
--- a/src/setu/ibf.c
+++ b/src/setu/ibf.c
@@ -20,11 +20,15 @@
/**
* @file set/ibf.c
- * @brief implementation of the invertible Bloom filter
+ * @brief implementation of the invertible bloom filter
* @author Florian Dold
+ * @author Elias Summermatter
*/
#include "ibf.h"
+#include "gnunet_util_lib.h"
+#define LOG(kind, ...) GNUNET_log_from (kind, "setu", __VA_ARGS__)
+
/**
* Compute the key's hash from the key.
@@ -58,11 +62,12 @@ ibf_hashcode_from_key (struct IBF_Key key,
struct GNUNET_HashCode *dst)
{
struct IBF_Key *p;
+ unsigned int i;
const unsigned int keys_per_hashcode = sizeof(struct GNUNET_HashCode)
/ sizeof(struct IBF_Key);
p = (struct IBF_Key *) dst;
- for (unsigned int i = 0; i < keys_per_hashcode; i++)
+ for (i = 0; i < keys_per_hashcode; i++)
*p++ = key;
}
@@ -75,14 +80,14 @@ ibf_hashcode_from_key (struct IBF_Key key,
* @return the newly created invertible bloom filter, NULL on error
*/
struct InvertibleBloomFilter *
-ibf_create (uint32_t size,
- uint8_t hash_num)
+ibf_create (uint32_t size, uint8_t hash_num)
{
struct InvertibleBloomFilter *ibf;
GNUNET_assert (0 != size);
+
ibf = GNUNET_new (struct InvertibleBloomFilter);
- ibf->count = GNUNET_malloc_large (size * sizeof(uint8_t));
+ ibf->count = GNUNET_malloc_large (size * sizeof(uint64_t));
if (NULL == ibf->count)
{
GNUNET_free (ibf);
@@ -105,6 +110,7 @@ ibf_create (uint32_t size,
}
ibf->size = size;
ibf->hash_num = hash_num;
+
return ibf;
}
@@ -121,8 +127,7 @@ ibf_get_indices (const struct InvertibleBloomFilter *ibf,
uint32_t i;
uint32_t bucket;
- bucket = GNUNET_CRYPTO_crc32_n (&key,
- sizeof (key));
+ bucket = GNUNET_CRYPTO_crc32_n (&key, sizeof key);
for (i = 0, filled = 0; filled < ibf->hash_num; i++)
{
uint64_t x;
@@ -133,8 +138,7 @@ ibf_get_indices (const struct InvertibleBloomFilter *ibf,
dst[filled++] = bucket % ibf->size;
try_next:
x = ((uint64_t) bucket << 32) | i;
- bucket = GNUNET_CRYPTO_crc32_n (&x,
- sizeof (x));
+ bucket = GNUNET_CRYPTO_crc32_n (&x, sizeof x);
}
}
@@ -170,13 +174,8 @@ ibf_insert (struct InvertibleBloomFilter *ibf,
int buckets[ibf->hash_num];
GNUNET_assert (ibf->hash_num <= ibf->size);
- ibf_get_indices (ibf,
- key,
- buckets);
- ibf_insert_into (ibf,
- key,
- buckets,
- 1);
+ ibf_get_indices (ibf, key, buckets);
+ ibf_insert_into (ibf, key, buckets, 1);
}
@@ -193,13 +192,8 @@ ibf_remove (struct InvertibleBloomFilter *ibf,
int buckets[ibf->hash_num];
GNUNET_assert (ibf->hash_num <= ibf->size);
- ibf_get_indices (ibf,
- key,
- buckets);
- ibf_insert_into (ibf,
- key,
- buckets,
- -1);
+ ibf_get_indices (ibf, key, buckets);
+ ibf_insert_into (ibf, key, buckets, -1);
}
@@ -244,6 +238,8 @@ ibf_decode (struct InvertibleBloomFilter *ibf,
for (uint32_t i = 0; i < ibf->size; i++)
{
+ int hit;
+
/* we can only decode from pure buckets */
if ( (1 != ibf->count[i].count_val) &&
(-1 != ibf->count[i].count_val) )
@@ -257,30 +253,33 @@ ibf_decode (struct InvertibleBloomFilter *ibf,
/* test if key in bucket hits its own location,
* if not, the key hash was subject to collision */
- {
- bool hit = false;
+ hit = GNUNET_NO;
+ ibf_get_indices (ibf, ibf->key_sum[i], buckets);
+ for (int j = 0; j < ibf->hash_num; j++)
+ if (buckets[j] == i)
+ hit = GNUNET_YES;
- ibf_get_indices (ibf,
- ibf->key_sum[i],
- buckets);
- for (int j = 0; j < ibf->hash_num; j++)
- if (buckets[j] == i)
- {
- hit = true;
- break;
- }
- if (! hit)
- continue;
+ if (GNUNET_NO == hit)
+ continue;
+
+ if (1 == ibf->count[i].count_val)
+ {
+ ibf->remote_decoded_count++;
}
+ else
+ {
+ ibf->local_decoded_count++;
+ }
+
+
if (NULL != ret_side)
*ret_side = ibf->count[i].count_val;
if (NULL != ret_id)
*ret_id = ibf->key_sum[i];
/* insert on the opposite side, effectively removing the element */
- ibf_insert_into (ibf,
- ibf->key_sum[i], buckets,
- -ibf->count[i].count_val);
+ ibf_insert_into (ibf, ibf->key_sum[i], buckets, -ibf->count[i].count_val);
+
return GNUNET_YES;
}
@@ -291,6 +290,26 @@ ibf_decode (struct InvertibleBloomFilter *ibf,
/**
+ * Returns the minimal bytes needed to store the counter of the IBF
+ *
+ * @param ibf the IBF
+ */
+uint8_t
+ibf_get_max_counter (struct InvertibleBloomFilter *ibf)
+{
+ long long max_counter = 0;
+ for (uint64_t i = 0; i < ibf->size; i++)
+ {
+ if (ibf->count[i].count_val > max_counter)
+ {
+ max_counter = ibf->count[i].count_val;
+ }
+ }
+ return 64 - __builtin_clzll (max_counter);
+}
+
+
+/**
* Write buckets from an ibf to a buffer.
* Exactly (IBF_BUCKET_SIZE*ibf->size) bytes are written to buf.
*
@@ -298,16 +317,17 @@ ibf_decode (struct InvertibleBloomFilter *ibf,
* @param start with which bucket to start
* @param count how many buckets to write
* @param buf buffer to write the data to
+ * @param max bit length of a counter for unpacking
*/
void
ibf_write_slice (const struct InvertibleBloomFilter *ibf,
uint32_t start,
- uint32_t count,
- void *buf)
+ uint64_t count,
+ void *buf,
+ uint8_t counter_max_length)
{
struct IBF_Key *key_dst;
struct IBF_KeyHash *key_hash_dst;
- struct IBF_Count *count_dst;
GNUNET_assert (start + count <= ibf->size);
@@ -315,19 +335,178 @@ ibf_write_slice (const struct InvertibleBloomFilter *ibf,
key_dst = (struct IBF_Key *) buf;
GNUNET_memcpy (key_dst,
ibf->key_sum + start,
- count * sizeof *key_dst);
+ count * sizeof(*key_dst));
key_dst += count;
/* copy key hashes */
key_hash_dst = (struct IBF_KeyHash *) key_dst;
GNUNET_memcpy (key_hash_dst,
ibf->key_hash_sum + start,
- count * sizeof *key_hash_dst);
+ count * sizeof(*key_hash_dst));
key_hash_dst += count;
- /* copy counts */
- count_dst = (struct IBF_Count *) key_hash_dst;
- GNUNET_memcpy (count_dst,
- ibf->count + start,
- count * sizeof *count_dst);
+
+ /* pack and copy counter */
+ pack_counter (ibf,
+ start,
+ count,
+ (uint8_t *) key_hash_dst,
+ counter_max_length);
+
+
+}
+
+
+/**
+ * Packs the counter to transmit only the smallest possible amount of bytes and
+ * preventing overflow of the counter
+ * @param ibf the ibf to write
+ * @param start with which bucket to start
+ * @param count how many buckets to write
+ * @param buf buffer to write the data to
+ * @param max bit length of a counter for unpacking
+ */
+
+void
+pack_counter (const struct InvertibleBloomFilter *ibf,
+ uint32_t start,
+ uint64_t count,
+ uint8_t *buf,
+ uint8_t counter_max_length)
+{
+ uint8_t store_size = 0;
+ uint8_t store = 0;
+ uint16_t byte_ctr = 0;
+
+ /**
+ * Iterate over IBF bucket
+ */
+ for (uint64_t i = start; i< (count + start);)
+ {
+ uint64_t count_val_to_write = ibf->count[i].count_val;
+ uint8_t count_len_to_write = counter_max_length;
+
+ /**
+ * Pack and compose counters to byte values
+ */
+ while ((count_len_to_write + store_size) >= 8)
+ {
+ uint8_t bit_shift = 0;
+
+ /**
+ * Shift bits if more than a byte has to be written
+ * or the store size is not empty
+ */
+ if ((store_size > 0) || (count_len_to_write > 8))
+ {
+ uint8_t bit_unused = 8 - store_size;
+ bit_shift = count_len_to_write - bit_unused;
+ store = store << bit_unused;
+ }
+
+ buf[byte_ctr] = ((count_val_to_write >> bit_shift) | store) & 0xFF;
+ byte_ctr++;
+ count_len_to_write -= (8 - store_size);
+ count_val_to_write = count_val_to_write & ((1ULL <<
+ count_len_to_write) - 1);
+ store = 0;
+ store_size = 0;
+ }
+ store = (store << count_len_to_write) | count_val_to_write;
+ store_size = store_size + count_len_to_write;
+ count_len_to_write = 0;
+ i++;
+ }
+
+ /**
+ * Pack data left in story before finishing
+ */
+ if (store_size > 0)
+ {
+ buf[byte_ctr] = store << (8 - store_size);
+ byte_ctr++;
+ }
+
+}
+
+
+/**
+ * Unpacks the counter to transmit only the smallest possible amount of bytes and
+ * preventing overflow of the counter
+ * @param ibf the ibf to write
+ * @param start with which bucket to start
+ * @param count how many buckets to write
+ * @param buf buffer to write the data to
+ * @param max bit length of a counter for unpacking
+ */
+
+void
+unpack_counter (const struct InvertibleBloomFilter *ibf,
+ uint32_t start,
+ uint64_t count,
+ uint8_t *buf,
+ uint8_t counter_max_length)
+{
+ uint64_t ibf_counter_ctr = 0;
+ uint64_t store = 0;
+ uint64_t store_bit_ctr = 0;
+ uint64_t byte_ctr = 0;
+
+ /**
+ * Iterate over received bytes
+ */
+ while (true)
+ {
+ uint8_t byte_read = buf[byte_ctr];
+ uint8_t bit_to_read_left = 8;
+ byte_ctr++;
+
+ /**
+ * Pack data left in story before finishing
+ */
+ while (true)
+ {
+ /**
+ * Stop decoding when end is reached
+ */
+ if (ibf_counter_ctr > (count - 1))
+ return;
+
+ /*
+ * Unpack the counter
+ */
+ if ((store_bit_ctr + bit_to_read_left) >= counter_max_length)
+ {
+ uint8_t bytes_used = counter_max_length - store_bit_ctr;
+ if (store_bit_ctr > 0)
+ {
+ store = store << bytes_used;
+ }
+
+ uint8_t bytes_to_shift = bit_to_read_left - bytes_used;
+ uint64_t counter_part = byte_read >> bytes_to_shift;
+ store = store | counter_part;
+ ibf->count[ibf_counter_ctr + start].count_val = store;
+ byte_read = byte_read & ((1 << bytes_to_shift) - 1);
+ bit_to_read_left -= bytes_used;
+ ibf_counter_ctr++;
+ store = 0;
+ store_bit_ctr = 0;
+ }
+ else
+ {
+ store_bit_ctr += bit_to_read_left;
+ if (0 == store)
+ {
+ store = byte_read;
+ }
+ else
+ {
+ store = store << bit_to_read_left;
+ store = store | byte_read;
+ }
+ break;
+ }
+ }
+ }
}
@@ -338,12 +517,14 @@ ibf_write_slice (const struct InvertibleBloomFilter *ibf,
* @param start which bucket to start at
* @param count how many buckets to read
* @param ibf the ibf to read from
+ * @param max bit length of a counter for unpacking
*/
void
ibf_read_slice (const void *buf,
uint32_t start,
- uint32_t count,
- struct InvertibleBloomFilter *ibf)
+ uint64_t count,
+ struct InvertibleBloomFilter *ibf,
+ uint8_t counter_max_length)
{
struct IBF_Key *key_src;
struct IBF_KeyHash *key_hash_src;
@@ -364,11 +545,10 @@ ibf_read_slice (const void *buf,
key_hash_src,
count * sizeof *key_hash_src);
key_hash_src += count;
- /* copy counts */
+
+ /* copy and unpack counts */
count_src = (struct IBF_Count *) key_hash_src;
- GNUNET_memcpy (ibf->count + start,
- count_src,
- count * sizeof *count_src);
+ unpack_counter (ibf,start,count,(uint8_t *) count_src,counter_max_length);
}
diff --git a/src/setu/ibf.h b/src/setu/ibf.h
index 7c2ab33b1..5628405dc 100644
--- a/src/setu/ibf.h
+++ b/src/setu/ibf.h
@@ -22,6 +22,7 @@
* @file set/ibf.h
* @brief invertible bloom filter
* @author Florian Dold
+ * @author Elias Summermatter
*/
#ifndef GNUNET_CONSENSUS_IBF_H
@@ -62,7 +63,7 @@ struct IBF_KeyHash
*/
struct IBF_Count
{
- int8_t count_val;
+ int64_t count_val;
};
@@ -93,6 +94,20 @@ struct InvertibleBloomFilter
uint8_t hash_num;
/**
+ * If an IBF is decoded this count stores how many
+ * elements are on the local site. This is used
+ * to estimate the set difference on a site
+ */
+ int local_decoded_count;
+
+ /**
+ * If an IBF is decoded this count stores how many
+ * elements are on the remote site. This is used
+ * to estimate the set difference on a site
+ */
+ int remote_decoded_count;
+
+ /**
* Xor sums of the elements' keys, used to identify the elements.
* Array of 'size' elements.
*/
@@ -125,8 +140,9 @@ struct InvertibleBloomFilter
void
ibf_write_slice (const struct InvertibleBloomFilter *ibf,
uint32_t start,
- uint32_t count,
- void *buf);
+ uint64_t count,
+ void *buf,
+ uint8_t counter_max_length);
/**
@@ -140,8 +156,9 @@ ibf_write_slice (const struct InvertibleBloomFilter *ibf,
void
ibf_read_slice (const void *buf,
uint32_t start,
- uint32_t count,
- struct InvertibleBloomFilter *ibf);
+ uint64_t count,
+ struct InvertibleBloomFilter *ibf,
+ uint8_t counter_max_length);
/**
@@ -244,6 +261,44 @@ ibf_dup (const struct InvertibleBloomFilter *ibf);
void
ibf_destroy (struct InvertibleBloomFilter *ibf);
+uint8_t
+ibf_get_max_counter (struct InvertibleBloomFilter *ibf);
+
+
+/**
+ * Packs the counter to transmit only the smallest possible amount of bytes and
+ * preventing overflow of the counter
+ * @param ibf the ibf to write
+ * @param start with which bucket to start
+ * @param count how many buckets to write
+ * @param buf buffer to write the data to
+ * @param max bit length of a counter for unpacking
+ */
+
+void
+pack_counter (const struct InvertibleBloomFilter *ibf,
+ uint32_t start,
+ uint64_t count,
+ uint8_t *buf,
+ uint8_t counter_max_length);
+
+/**
+ * Unpacks the counter to transmit only the smallest possible amount of bytes and
+ * preventing overflow of the counter
+ * @param ibf the ibf to write
+ * @param start with which bucket to start
+ * @param count how many buckets to write
+ * @param buf buffer to write the data to
+ * @param max bit length of a counter for unpacking
+ */
+
+void
+unpack_counter (const struct InvertibleBloomFilter *ibf,
+ uint32_t start,
+ uint64_t count,
+ uint8_t *buf,
+ uint8_t counter_max_length);
+
#if 0 /* keep Emacsens' auto-indent happy */
{
diff --git a/src/setu/perf_setu_api.c b/src/setu/perf_setu_api.c
index b273f9c71..7f4d64f74 100644
--- a/src/setu/perf_setu_api.c
+++ b/src/setu/perf_setu_api.c
@@ -22,11 +22,14 @@
* @file set/test_setu_api.c
* @brief testcase for setu_api.c
* @author Florian Dold
+ * @author Elias Summermatter
*/
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_testing_lib.h"
#include "gnunet_setu_service.h"
+#include <sys/sysinfo.h>
+#include <pthread.h>
static struct GNUNET_PeerIdentity local_id;
@@ -50,6 +53,12 @@ static int ret;
static struct GNUNET_SCHEDULER_Task *tt;
+/**
+ * Handles configuration file for setu performance test
+ *
+ */
+static struct GNUNET_CONFIGURATION_Handle *setu_cfg;
+
static void
result_cb_set1 (void *cls,
@@ -57,44 +66,44 @@ result_cb_set1 (void *cls,
uint64_t size,
enum GNUNET_SETU_Status status)
{
- switch (status)
+ switch (status)
+ {
+ case GNUNET_SETU_STATUS_ADD_LOCAL:
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "set 1: got element\n");
+ break;
+
+ case GNUNET_SETU_STATUS_FAILURE:
+ GNUNET_break (0);
+ oh1 = NULL;
+ fprintf (stderr, "set 1: received failure status!\n");
+ ret = 1;
+ if (NULL != tt)
+ {
+ GNUNET_SCHEDULER_cancel (tt);
+ tt = NULL;
+ }
+ GNUNET_SCHEDULER_shutdown ();
+ break;
+
+ case GNUNET_SETU_STATUS_DONE:
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "set 1: done\n");
+ oh1 = NULL;
+ if (NULL != set1)
{
- case GNUNET_SETU_STATUS_ADD_LOCAL:
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "set 1: got element\n");
- break;
-
- case GNUNET_SETU_STATUS_FAILURE:
- GNUNET_break (0);
- oh1 = NULL;
- fprintf (stderr, "set 1: received failure status!\n");
- ret = 1;
- if (NULL != tt)
- {
- GNUNET_SCHEDULER_cancel (tt);
- tt = NULL;
- }
- GNUNET_SCHEDULER_shutdown ();
- break;
-
- case GNUNET_SETU_STATUS_DONE:
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "set 1: done\n");
- oh1 = NULL;
- if (NULL != set1)
- {
- GNUNET_SETU_destroy (set1);
- set1 = NULL;
- }
- if (NULL == set2)
- {
- GNUNET_SCHEDULER_cancel (tt);
- tt = NULL;
- GNUNET_SCHEDULER_shutdown ();
- }
- break;
-
- default:
- GNUNET_assert (0);
+ GNUNET_SETU_destroy (set1);
+ set1 = NULL;
}
+ if (NULL == set2)
+ {
+ GNUNET_SCHEDULER_cancel (tt);
+ tt = NULL;
+ GNUNET_SCHEDULER_shutdown ();
+ }
+ break;
+
+ default:
+ GNUNET_assert (0);
+ }
}
@@ -104,36 +113,36 @@ result_cb_set2 (void *cls,
uint64_t size,
enum GNUNET_SETU_Status status)
{
- switch (status)
+ switch (status)
+ {
+ case GNUNET_SETU_STATUS_ADD_LOCAL:
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "set 2: got element\n");
+ break;
+
+ case GNUNET_SETU_STATUS_FAILURE:
+ GNUNET_break (0);
+ oh2 = NULL;
+ fprintf (stderr, "set 2: received failure status\n");
+ GNUNET_SCHEDULER_shutdown ();
+ ret = 1;
+ break;
+
+ case GNUNET_SETU_STATUS_DONE:
+ oh2 = NULL;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "set 2: done\n");
+ GNUNET_SETU_destroy (set2);
+ set2 = NULL;
+ if (NULL == set1)
{
- case GNUNET_SETU_STATUS_ADD_LOCAL:
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "set 2: got element\n");
- break;
-
- case GNUNET_SETU_STATUS_FAILURE:
- GNUNET_break (0);
- oh2 = NULL;
- fprintf (stderr, "set 2: received failure status\n");
- GNUNET_SCHEDULER_shutdown ();
- ret = 1;
- break;
-
- case GNUNET_SETU_STATUS_DONE:
- oh2 = NULL;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "set 2: done\n");
- GNUNET_SETU_destroy (set2);
- set2 = NULL;
- if (NULL == set1)
- {
- GNUNET_SCHEDULER_cancel (tt);
- tt = NULL;
- GNUNET_SCHEDULER_shutdown ();
- }
- break;
-
- default:
- GNUNET_assert (0);
+ GNUNET_SCHEDULER_cancel (tt);
+ tt = NULL;
+ GNUNET_SCHEDULER_shutdown ();
}
+ break;
+
+ default:
+ GNUNET_assert (0);
+ }
}
@@ -143,14 +152,14 @@ listen_cb (void *cls,
const struct GNUNET_MessageHeader *context_msg,
struct GNUNET_SETU_Request *request)
{
- GNUNET_assert (NULL != context_msg);
- GNUNET_assert (ntohs (context_msg->type) == GNUNET_MESSAGE_TYPE_DUMMY);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "listen cb called\n");
- oh2 = GNUNET_SETU_accept (request,
- (struct GNUNET_SETU_Option[]){ 0 },
- &result_cb_set2,
- NULL);
- GNUNET_SETU_commit (oh2, set2);
+ GNUNET_assert (NULL != context_msg);
+ GNUNET_assert (ntohs (context_msg->type) == GNUNET_MESSAGE_TYPE_DUMMY);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "listen cb called\n");
+ oh2 = GNUNET_SETU_accept (request,
+ (struct GNUNET_SETU_Option[]){ 0 },
+ &result_cb_set2,
+ NULL);
+ GNUNET_SETU_commit (oh2, set2);
}
@@ -162,122 +171,89 @@ listen_cb (void *cls,
static void
start (void *cls)
{
- struct GNUNET_MessageHeader context_msg;
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting reconciliation\n");
- context_msg.size = htons (sizeof context_msg);
- context_msg.type = htons (GNUNET_MESSAGE_TYPE_DUMMY);
- listen_handle = GNUNET_SETU_listen (config,
- &app_id,
- &listen_cb,
- NULL);
- oh1 = GNUNET_SETU_prepare (&local_id,
- &app_id,
- &context_msg,
- (struct GNUNET_SETU_Option[]){ 0 },
- &result_cb_set1,
- NULL);
- GNUNET_SETU_commit (oh1, set1);
+ struct GNUNET_MessageHeader context_msg;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting reconciliation\n");
+ context_msg.size = htons (sizeof context_msg);
+ context_msg.type = htons (GNUNET_MESSAGE_TYPE_DUMMY);
+ listen_handle = GNUNET_SETU_listen (config,
+ &app_id,
+ &listen_cb,
+ NULL);
+ oh1 = GNUNET_SETU_prepare (&local_id,
+ &app_id,
+ &context_msg,
+ (struct GNUNET_SETU_Option[]){ 0 },
+ &result_cb_set1,
+ NULL);
+ GNUNET_SETU_commit (oh1, set1);
}
/**
- * Initialize the second set, continue
- *
- * @param cls closure, unused
- */
-static void
-init_set2 (void *cls)
-{
- struct GNUNET_SETU_Element element;
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "initializing set 2\n");
-
- element.element_type = 0;
- element.data = "hello1";
- element.size = strlen (element.data);
- GNUNET_SETU_add_element (set2, &element, NULL, NULL);
- element.data = "quux";
- element.size = strlen (element.data);
- GNUNET_SETU_add_element (set2, &element, NULL, NULL);
- element.data = "baz";
- element.size = strlen (element.data);
- GNUNET_SETU_add_element (set2, &element, &start, NULL);
-}
-
-/**
* Generate random byte stream
*/
-unsigned char *gen_rdm_bytestream (size_t num_bytes)
+unsigned char *
+gen_rdm_bytestream (size_t num_bytes)
{
- unsigned char *stream = GNUNET_malloc (num_bytes);
- GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_WEAK, stream, num_bytes);
- return stream;
+ unsigned char *stream = GNUNET_malloc (num_bytes);
+ GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, stream, num_bytes);
+ return stream;
}
+
/**
* Generate random sets
*/
static void
-initRandomSets(int overlap, int set1_size, int set2_size, int element_size_in_bytes)
+initRandomSets (int overlap, int set1_size, int set2_size, int
+ element_size_in_bytes)
{
- struct GNUNET_SETU_Element element;
- element.element_type = 0;
-
- // Add elements to both sets
- for (int i = 0; i < overlap; i++) {
- element.data = gen_rdm_bytestream(element_size_in_bytes);
- element.size = element_size_in_bytes;
- GNUNET_SETU_add_element (set1, &element, NULL, NULL);
- GNUNET_SETU_add_element (set2, &element, NULL, NULL);
- set1_size--;
- set2_size--;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "initialized elements in both sets\n");
-
- // Add other elements to set 1
- while(set1_size>0) {
- element.data = gen_rdm_bytestream(element_size_in_bytes);
- element.size = element_size_in_bytes;
- GNUNET_SETU_add_element (set1, &element, NULL, NULL);
- set1_size--;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "initialized elements in set1\n");
-
- // Add other elements to set 2
- while(set2_size > 0) {
- element.data = gen_rdm_bytestream(element_size_in_bytes);
- element.size = element_size_in_bytes;
+ struct GNUNET_SETU_Element element;
+ element.element_type = 0;
+
+ // Add elements to both sets
+ for (int i = 0; i < overlap; i++)
+ {
+ element.data = gen_rdm_bytestream (element_size_in_bytes);
+ element.size = element_size_in_bytes;
+ GNUNET_SETU_add_element (set1, &element, NULL, NULL);
+ GNUNET_SETU_add_element (set2, &element, NULL, NULL);
+ set1_size--;
+ set2_size--;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "initialized elements in both sets\n");
+
+ // Add other elements to set 1
+ while (set1_size>0)
+ {
+ element.data = gen_rdm_bytestream (element_size_in_bytes);
+ element.size = element_size_in_bytes;
+ GNUNET_SETU_add_element (set1, &element, NULL, NULL);
+ set1_size--;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "initialized elements in set1\n");
- if(set2_size != 1) {
- GNUNET_SETU_add_element (set2, &element,NULL, NULL);
- } else {
- GNUNET_SETU_add_element (set2, &element,&start, NULL);
- }
+ // Add other elements to set 2
+ while (set2_size > 0)
+ {
+ element.data = gen_rdm_bytestream (element_size_in_bytes);
+ element.size = element_size_in_bytes;
- set2_size--;
+ if (set2_size != 1)
+ {
+ GNUNET_SETU_add_element (set2, &element,NULL, NULL);
+ }
+ else
+ {
+ GNUNET_SETU_add_element (set2, &element,&start, NULL);
}
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "initialized elements in set2\n");
-}
-
-/**
- * Initialize the first set, continue.
- */
-static void
-init_set1 (void)
-{
- struct GNUNET_SETU_Element element;
- element.element_type = 0;
- element.data = "hello";
- element.size = strlen (element.data);
- GNUNET_SETU_add_element (set1, &element, NULL, NULL);
- element.data = "bar";
- element.size = strlen (element.data);
- GNUNET_SETU_add_element (set1, &element, &init_set2, NULL);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "initialized set 1\n");
+ set2_size--;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "initialized elements in set2\n");
}
@@ -289,10 +265,10 @@ init_set1 (void)
static void
timeout_fail (void *cls)
{
- tt = NULL;
- GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, "Testcase failed with timeout\n");
- GNUNET_SCHEDULER_shutdown ();
- ret = 1;
+ tt = NULL;
+ GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, "Testcase failed with timeout\n");
+ GNUNET_SCHEDULER_shutdown ();
+ ret = 1;
}
@@ -304,36 +280,36 @@ timeout_fail (void *cls)
static void
do_shutdown (void *cls)
{
- if (NULL != tt)
- {
- GNUNET_SCHEDULER_cancel (tt);
- tt = NULL;
- }
- if (NULL != oh1)
- {
- GNUNET_SETU_operation_cancel (oh1);
- oh1 = NULL;
- }
- if (NULL != oh2)
- {
- GNUNET_SETU_operation_cancel (oh2);
- oh2 = NULL;
- }
- if (NULL != set1)
- {
- GNUNET_SETU_destroy (set1);
- set1 = NULL;
- }
- if (NULL != set2)
- {
- GNUNET_SETU_destroy (set2);
- set2 = NULL;
- }
- if (NULL != listen_handle)
- {
- GNUNET_SETU_listen_cancel (listen_handle);
- listen_handle = NULL;
- }
+ if (NULL != tt)
+ {
+ GNUNET_SCHEDULER_cancel (tt);
+ tt = NULL;
+ }
+ if (NULL != oh1)
+ {
+ GNUNET_SETU_operation_cancel (oh1);
+ oh1 = NULL;
+ }
+ if (NULL != oh2)
+ {
+ GNUNET_SETU_operation_cancel (oh2);
+ oh2 = NULL;
+ }
+ if (NULL != set1)
+ {
+ GNUNET_SETU_destroy (set1);
+ set1 = NULL;
+ }
+ if (NULL != set2)
+ {
+ GNUNET_SETU_destroy (set2);
+ set2 = NULL;
+ }
+ if (NULL != listen_handle)
+ {
+ GNUNET_SETU_listen_cancel (listen_handle);
+ listen_handle = NULL;
+ }
}
@@ -350,79 +326,148 @@ run (void *cls,
const struct GNUNET_CONFIGURATION_Handle *cfg,
struct GNUNET_TESTING_Peer *peer)
{
- struct GNUNET_SETU_OperationHandle *my_oh;
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Running preparatory tests\n");
- tt = GNUNET_SCHEDULER_add_delayed (
- GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5),
- &timeout_fail,
- NULL);
- GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
-
- config = cfg;
- GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_get_peer_identity (cfg,
- &local_id));
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "my id (from CRYPTO): %s\n",
- GNUNET_i2s (&local_id));
- GNUNET_TESTING_peer_get_identity (peer,
- &local_id);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "my id (from TESTING): %s\n",
- GNUNET_i2s (&local_id));
- set1 = GNUNET_SETU_create (cfg);
- set2 = GNUNET_SETU_create (cfg);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Created sets %p and %p for union operation\n",
- set1,
- set2);
- GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &app_id);
-
- /* test if canceling an uncommitted request works! */
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Launching and instantly stopping set operation\n");
- my_oh = GNUNET_SETU_prepare (&local_id,
- &app_id,
- NULL,
- (struct GNUNET_SETU_Option[]){ 0 },
- NULL,
- NULL);
- GNUNET_SETU_operation_cancel (my_oh);
-
- /* test the real set reconciliation */
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Running real set-reconciliation\n");
- //init_set1 ();
- // limit ~23800 element total
- initRandomSets(50,100,100,128);
+ struct GNUNET_SETU_OperationHandle *my_oh;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Running preparatory tests\n");
+ tt = GNUNET_SCHEDULER_add_delayed (
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5),
+ &timeout_fail,
+ NULL);
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
+
+ config = cfg;
+ GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_get_peer_identity (cfg,
+ &local_id));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "my id (from CRYPTO): %s\n",
+ GNUNET_i2s (&local_id));
+ GNUNET_TESTING_peer_get_identity (peer,
+ &local_id);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "my id (from TESTING): %s\n",
+ GNUNET_i2s (&local_id));
+ set1 = GNUNET_SETU_create (cfg);
+ set2 = GNUNET_SETU_create (cfg);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Created sets %p and %p for union operation\n",
+ set1,
+ set2);
+ GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &app_id);
+
+ /* test if canceling an uncommitted request works! */
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Launching and instantly stopping set operation\n");
+ my_oh = GNUNET_SETU_prepare (&local_id,
+ &app_id,
+ NULL,
+ (struct GNUNET_SETU_Option[]){ 0 },
+ NULL,
+ NULL);
+ GNUNET_SETU_operation_cancel (my_oh);
+
+ /* test the real set reconciliation */
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Running real set-reconciliation\n");
+ // init_set1 ();
+ // limit ~23800 element total
+ initRandomSets (490, 500,500,32);
}
-static void execute_perf()
+
+void
+perf_thread ()
{
- for( int repeat_ctr = 0; repeat_ctr<1; repeat_ctr++ ) {
+ GNUNET_TESTING_service_run ("perf_setu_api",
+ "arm",
+ "test_setu.conf",
+ &run,
+ NULL);
+
+}
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Executing perf round %d\n", repeat_ctr);
- GNUNET_TESTING_service_run ("perf_setu_api",
- "arm",
- "test_setu.conf",
- &run,
- NULL);
+static void
+run_petf_thread (int total_runs)
+{
+ int core_count = get_nprocs_conf ();
+ pid_t child_pid, wpid;
+ int status = 0;
+
+// Father code (before child processes start)
+ for (int processed = 0; processed < total_runs;)
+ {
+ for (int id = 0; id < core_count; id++)
+ {
+ if (processed >= total_runs)
+ break;
+
+ if ((child_pid = fork ()) == 0)
+ {
+ perf_thread ();
+ exit (0);
+ }
+ processed += 1;
}
- return 0;
+ while ((wpid = wait (&status)) > 0)
+ ;
+
+ }
}
+static void
+execute_perf ()
+{
+
+ /**
+ * Erase statfile
+ */
+ remove ("perf_stats.csv");
+ remove ("perf_failure_bucket_number_factor.csv");
+ for (int out_out_ctr = 3; out_out_ctr <= 3; out_out_ctr++)
+ {
+
+ for (int out_ctr = 20; out_ctr <= 20; out_ctr++)
+ {
+ float base = 0.1;
+ float x = out_ctr * base;
+ char factor[10];
+ char *buffer = gcvt (x, 4, factor);
+ setu_cfg = GNUNET_CONFIGURATION_create ();
+ GNUNET_CONFIGURATION_set_value_string (setu_cfg, "IBF",
+ "BUCKET_NUMBER_FACTOR",
+ buffer); // Factor default=4
+ GNUNET_CONFIGURATION_set_value_number (setu_cfg, "IBF",
+ "NUMBER_PER_BUCKET", 3); // K default=4
+ GNUNET_CONFIGURATION_set_value_string (setu_cfg, "PERFORMANCE",
+ "TRADEOFF", "2"); // default=0.25
+ GNUNET_CONFIGURATION_set_value_string (setu_cfg, "PERFORMANCE",
+ "MAX_SET_DIFF_FACTOR_DIFFERENTIAL",
+ "20000"); // default=0.25
+ GNUNET_CONFIGURATION_set_value_number (setu_cfg, "BOUNDARIES",
+ "UPPER_ELEMENT", 5000);
+
+
+ if (GNUNET_OK != GNUNET_CONFIGURATION_write (setu_cfg, "perf_setu.conf"))
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_ERROR,
+ _ ("Failed to write subsystem default identifier map'.\n"));
+ run_petf_thread (100);
+ }
+
+ }
+ return;
+}
+
int
main (int argc, char **argv)
{
- GNUNET_log_setup ("perf_setu_api",
- "WARNING",
- NULL);
- execute_perf();
- return 0;
+ GNUNET_log_setup ("perf_setu_api",
+ "WARNING",
+ NULL);
+ execute_perf ();
+ return 0;
}
diff --git a/src/setu/setu.h b/src/setu/setu.h
index 7c2a98a02..7b606f12c 100644
--- a/src/setu/setu.h
+++ b/src/setu/setu.h
@@ -122,6 +122,31 @@ struct GNUNET_SETU_AcceptMessage
*/
uint32_t byzantine_lower_bound;
+
+ /**
+ * Upper bound for the set size, used only when
+ * byzantine mode is enabled.
+ */
+ uint64_t byzantine_upper_bond;
+
+ /**
+ * Bandwidth latency tradeoff determines how much bytes a single RTT is
+ * worth, which is a performance setting
+ */
+ uint64_t bandwidth_latency_tradeoff;
+
+ /**
+ * The factor determines the number of buckets an IBF has which is
+ * multiplied by the estimated setsize default: 2
+ */
+ uint64_t ibf_bucket_number_factor;
+
+ /**
+ * This setting determines to how many IBF buckets an single elements
+ * is mapped to.
+ */
+ uint64_t ibf_number_of_buckets_per_element;
+
};
@@ -226,6 +251,30 @@ struct GNUNET_SETU_EvaluateMessage
*/
uint32_t byzantine_lower_bound;
+ /**
+ * Upper bound for the set size, used only when
+ * byzantine mode is enabled.
+ */
+ uint64_t byzantine_upper_bond;
+
+ /**
+ * Bandwidth latency tradeoff determines how much bytes a single RTT is
+ * worth, which is a performance setting
+ */
+ uint64_t bandwidth_latency_tradeoff;
+
+ /**
+ * The factor determines the number of buckets an IBF has which is
+ * multiplied by the estimated setsize default: 2
+ */
+ uint64_t ibf_bucket_number_factor;
+
+ /**
+ * This setting determines to how many IBF buckets an single elements
+ * is mapped to.
+ */
+ uint64_t ibf_number_of_buckets_per_element;
+
/* rest: context message, that is, application-specific
message to convince listener to pick up */
};
diff --git a/src/setu/setu_api.c b/src/setu/setu_api.c
index 0a09b18b2..faa57aaba 100644
--- a/src/setu/setu_api.c
+++ b/src/setu/setu_api.c
@@ -22,6 +22,7 @@
* @brief api for the set union service
* @author Florian Dold
* @author Christian Grothoff
+ * @author Elias Summermatter
*/
#include "platform.h"
#include "gnunet_util_lib.h"
@@ -526,6 +527,14 @@ GNUNET_SETU_prepare (const struct GNUNET_PeerIdentity *other_peer,
context_msg);
msg->app_id = *app_id;
msg->target_peer = *other_peer;
+
+ /* Set default values */
+ msg->byzantine_upper_bond = UINT64_MAX;
+ msg->bandwidth_latency_tradeoff = 0;
+ msg->ibf_bucket_number_factor = 2;
+ msg->ibf_number_of_buckets_per_element = 3;
+
+
for (const struct GNUNET_SETU_Option *opt = options; opt->type != 0; opt++)
{
switch (opt->type)
@@ -534,6 +543,18 @@ GNUNET_SETU_prepare (const struct GNUNET_PeerIdentity *other_peer,
msg->byzantine = GNUNET_YES;
msg->byzantine_lower_bound = htonl (opt->v.num);
break;
+ case GNUNET_SETU_OPTION_CUSTOM_BYZANTINE_UPPER_BOUND:
+ msg->byzantine_upper_bond = htonl (opt->v.num);
+ break;
+ case GNUNET_SETU_OPTION_CUSTOM_BANDWIDTH_LATENCY_TRADEOFF:
+ msg->bandwidth_latency_tradeoff = htonl (opt->v.num);
+ break;
+ case GNUNET_SETU_OPTION_CUSTOM_IBF_BUCKET_NUMBER_FACTOR:
+ msg->ibf_bucket_number_factor = htonl (opt->v.num);
+ break;
+ case GNUNET_SETU_OPTION_CUSTOM_IBF_BUCKETS_PER_ELEMENT:
+ msg->ibf_number_of_buckets_per_element = htonl (opt->v.num);
+ break;
case GNUNET_SETU_OPTION_FORCE_FULL:
msg->force_full = GNUNET_YES;
break;
@@ -788,6 +809,13 @@ GNUNET_SETU_accept (struct GNUNET_SETU_Request *request,
mqm = GNUNET_MQ_msg (msg,
GNUNET_MESSAGE_TYPE_SETU_ACCEPT);
msg->accept_reject_id = htonl (request->accept_id);
+
+ /* Set default values */
+ msg->byzantine_upper_bond = UINT64_MAX;
+ msg->bandwidth_latency_tradeoff = 0;
+ msg->ibf_bucket_number_factor = 2;
+ msg->ibf_number_of_buckets_per_element = 3;
+
for (const struct GNUNET_SETU_Option *opt = options; opt->type != 0; opt++)
{
switch (opt->type)
@@ -796,6 +824,18 @@ GNUNET_SETU_accept (struct GNUNET_SETU_Request *request,
msg->byzantine = GNUNET_YES;
msg->byzantine_lower_bound = htonl (opt->v.num);
break;
+ case GNUNET_SETU_OPTION_CUSTOM_BYZANTINE_UPPER_BOUND:
+ msg->byzantine_upper_bond = htonl (opt->v.num);
+ break;
+ case GNUNET_SETU_OPTION_CUSTOM_BANDWIDTH_LATENCY_TRADEOFF:
+ msg->bandwidth_latency_tradeoff = htonl (opt->v.num);
+ break;
+ case GNUNET_SETU_OPTION_CUSTOM_IBF_BUCKET_NUMBER_FACTOR:
+ msg->ibf_bucket_number_factor = htonl (opt->v.num);
+ break;
+ case GNUNET_SETU_OPTION_CUSTOM_IBF_BUCKETS_PER_ELEMENT:
+ msg->ibf_number_of_buckets_per_element = htonl (opt->v.num);
+ break;
case GNUNET_SETU_OPTION_FORCE_FULL:
msg->force_full = GNUNET_YES;
break;
diff --git a/src/setu/test_setu_api.c b/src/setu/test_setu_api.c
index 2fb7d015e..5a0c9d70d 100644
--- a/src/setu/test_setu_api.c
+++ b/src/setu/test_setu_api.c
@@ -204,62 +204,6 @@ init_set2 (void *cls)
GNUNET_SETU_add_element (set2, &element, &start, NULL);
}
-/**
- * Generate random byte stream
- */
-
-unsigned char *gen_rdm_bytestream (size_t num_bytes)
-{
- unsigned char *stream = GNUNET_malloc (num_bytes);
- GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_WEAK, stream, num_bytes);
- return stream;
-}
-
-/**
- * Generate random sets
- */
-
-static void
-initRandomSets(int overlap, int set1_size, int set2_size, int element_size_in_bytes)
-{
- struct GNUNET_SETU_Element element;
- element.element_type = 0;
-
- // Add elements to both sets
- for (int i = 0; i < overlap; i++) {
- element.data = gen_rdm_bytestream(element_size_in_bytes);
- element.size = element_size_in_bytes;
- GNUNET_SETU_add_element (set1, &element, NULL, NULL);
- GNUNET_SETU_add_element (set2, &element, NULL, NULL);
- set1_size--;
- set2_size--;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "initialized elements in both sets\n");
-
- // Add other elements to set 1
- while(set1_size>0) {
- element.data = gen_rdm_bytestream(element_size_in_bytes);
- element.size = element_size_in_bytes;
- GNUNET_SETU_add_element (set1, &element, NULL, NULL);
- set1_size--;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "initialized elements in set1\n");
-
- // Add other elements to set 2
- while(set2_size > 0) {
- element.data = gen_rdm_bytestream(element_size_in_bytes);
- element.size = element_size_in_bytes;
-
- if(set2_size != 1) {
- GNUNET_SETU_add_element (set2, &element,NULL, NULL);
- } else {
- GNUNET_SETU_add_element (set2, &element,&start, NULL);
- }
-
- set2_size--;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "initialized elements in set2\n");
-}
/**
* Initialize the first set, continue.
@@ -392,9 +336,7 @@ run (void *cls,
/* test the real set reconciliation */
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Running real set-reconciliation\n");
- //init_set1 ();
- initRandomSets(19500,20000,20000,4096);
- //initRandomSets(19500,20000,20000,32);
+ init_set1 ();
}
diff --git a/src/testbed/Makefile.am b/src/testbed/Makefile.am
index a9837daf5..11399e77c 100644
--- a/src/testbed/Makefile.am
+++ b/src/testbed/Makefile.am
@@ -23,8 +23,6 @@ if HAVE_SQLITE
endif
libexec_PROGRAMS = \
- gnunet-cmd \
- gnunet-cmds-helper \
gnunet-service-testbed \
gnunet-helper-testbed \
gnunet-daemon-testbed-blacklist \
@@ -37,20 +35,6 @@ bin_PROGRAMS = \
noinst_PROGRAMS = \
$(generate_underlay)
-plugin_LTLIBRARIES = \
- libgnunet_plugin_testcmd.la
-
-libgnunet_plugin_testcmd_la_SOURCES = \
- plugin_testcmd.c
-libgnunet_plugin_testcmd_la_LIBADD = \
- $(top_builddir)/src/util/libgnunetutil.la \
- $(top_builddir)/src/testing/libgnunettesting.la \
- $(top_builddir)/src/statistics/libgnunetstatistics.la \
- libgnunettestbed.la \
- $(LTLIBINTL)
-libgnunet_plugin_testcmd_la_LDFLAGS = \
- $(GN_PLUGIN_LDFLAGS)
-
gnunet_service_testbed_SOURCES = \
gnunet-service-testbed.c gnunet-service-testbed.h \
gnunet-service-testbed_links.c gnunet-service-testbed_links.h \
@@ -75,6 +59,7 @@ gnunet_service_testbed_LDADD = $(XLIB) \
gnunet_testbed_profiler_SOURCES = \
gnunet-testbed-profiler.c
gnunet_testbed_profiler_LDADD = $(XLIB) \
+ $(top_builddir)/src/testing/libgnunettesting.la \
$(top_builddir)/src/util/libgnunetutil.la \
libgnunettestbed.la
gnunet_testbed_profiler_LDFLAGS = \
@@ -88,23 +73,6 @@ gnunet_helper_testbed_LDADD = $(XLIB) \
libgnunettestbed.la \
$(LTLIBINTL) $(Z_LIBS)
-gnunet_cmd_SOURCES = \
- gnunet-cmd.c
-gnunet_cmd_LDADD = $(XLIB) \
- $(top_builddir)/src/util/libgnunetutil.la \
- $(top_builddir)/src/testing/libgnunettesting.la \
- libgnunettestbed.la \
- $(LTLIBINTL) $(Z_LIBS)
-
-gnunet_cmds_helper_SOURCES = \
- gnunet-cmds-helper.c
-gnunet_cmds_helper_LDADD = $(XLIB) \
- $(top_builddir)/src/util/libgnunetutil.la \
- $(top_builddir)/src/testing/libgnunettesting.la \
- $(top_builddir)/src/transport/libgnunettransport.la \
- libgnunettestbed.la \
- $(LTLIBINTL) $(Z_LIBS)
-
gnunet_daemon_testbed_blacklist_SOURCES = gnunet-daemon-testbed-blacklist.c
gnunet_daemon_testbed_blacklist_LDADD = $(XLIB) \
$(top_builddir)/src/transport/libgnunettransport.la \
@@ -127,17 +95,8 @@ lib_LTLIBRARIES = \
libgnunettestbed.la
libgnunettestbed_la_SOURCES = \
- testbed_api_cmd_local_test_finished.c \
- testbed_api_cmd_send_peer_ready.c \
- testbed_api_cmd_block_until_all_peers_started.c \
- testbed_api_cmd_netjail_start.c \
- testbed_api_cmd_netjail_start_testbed.c \
- testbed_api_cmd_netjail_stop_testbed.c \
- testbed_api_cmd_netjail_stop.c \
testbed_api.c testbed_api.h testbed.h \
testbed_api_hosts.c testbed_api_hosts.h testbed_helper.h \
- testbed_api_cmd_controller.c \
- testbed_api_cmd_peer.c \
testbed_api_operations.c testbed_api_operations.h \
testbed_api_peers.c testbed_api_peers.h \
testbed_api_services.c \
@@ -156,24 +115,18 @@ libgnunettestbed_la_LIBADD = $(XLIB) \
$(top_builddir)/src/arm/libgnunetarm.la \
$(top_builddir)/src/util/libgnunetutil.la \
$(LTLIBINTL)
-libgnunettestbed_la_DEPENDENCIES = \
- $(top_builddir)/src/statistics/libgnunetstatistics.la \
- $(top_builddir)/src/transport/libgnunettransport.la \
- $(top_builddir)/src/hello/libgnunethello.la \
- $(top_builddir)/src/testing/libgnunettesting.la \
- $(top_builddir)/src/util/libgnunetutil.la
libgnunettestbed_la_LDFLAGS = \
$(GN_LIB_LDFLAGS) \
-version-info 0:0:0
generate_underlay_topology_SOURCES = generate-underlay-topology.c
generate_underlay_topology_LDADD = $(XLIB) \
+ $(top_builddir)/src/testing/libgnunettesting.la \
$(top_builddir)/src/util/libgnunetutil.la \
libgnunettestbed.la \
$(LTLIBINTL) -lsqlite3
check_PROGRAMS = \
- test_testbed_api_cmd_netjail \
test_testbed_api_hosts \
test_gnunet_helper_testbed \
test_testbed_api_controllerlink \
@@ -208,7 +161,6 @@ check_PROGRAMS = \
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 = \
- test_testbed_api_cmd_netjail \
test_testbed_api \
test_testbed_api_sd \
test_testbed_api_operations \
@@ -239,13 +191,6 @@ if ENABLE_TEST_RUN
$(underlay_testcases)
endif
-test_testbed_api_cmd_netjail_SOURCES = \
- test_testbed_api_cmd_netjail.c
-test_testbed_api_cmd_netjail_LDADD = \
- $(top_builddir)/src/testing/libgnunettesting.la \
- $(top_builddir)/src/util/libgnunetutil.la \
- libgnunettestbed.la
-
test_testbed_api_SOURCES = \
test_testbed_api.c
test_testbed_api_LDADD = \
diff --git a/src/testbed/gnunet-cmd.c b/src/testbed/gnunet-cmd.c
deleted file mode 100644
index f232bd805..000000000
--- a/src/testbed/gnunet-cmd.c
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- This file is part of GNUnet
- Copyright (C) 2008--2013, 2016 GNUnet e.V.
-
- GNUnet is free software: you can redistribute it and/or modify it
- under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation, either version 3 of the License,
- or (at your option) any later version.
-
- GNUnet is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-
- SPDX-License-Identifier: AGPL3.0-or-later
- */
-
-/**
- * @file testbed/gnunet-cmd.c
- *
- * @brief Binary to start testcase plugins
- *
- * @author t3sserakt
- */
-
-#include "platform.h"
-#include "gnunet_util_lib.h"
-#include "gnunet_testing_lib.h"
-#include "gnunet_testing_plugin.h"
-
-/**
- * Generic logging shortcut
- */
-#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
-
-#define NODE_BASE_IP "192.168.15."
-
-#define ROUTER_BASE_IP "92.68.150."
-
-/**
- * Handle for a plugin.
- */
-struct Plugin
-{
- /**
- * Name of the shared library.
- */
- char *library_name;
-
- /**
- * Plugin API.
- */
- struct GNUNET_TESTING_PluginFunctions *api;
-
- char *node_ip;
-
- char *plugin_name;
-
- char *global_n;
-
- char *local_m;
-
- char *n;
-
- char *m;
-};
-
-
-/**
- * Main function to run the test cases.
- *
- * @param cls plugin to use.
- *
- */
-static void
-run (void *cls)
-{
- struct Plugin *plugin = cls;
- char *router_ip;
- char *node_ip;
-
- router_ip = GNUNET_malloc (strlen (ROUTER_BASE_IP) + strlen (plugin->m) + 1);
- strcpy (router_ip, ROUTER_BASE_IP);
- strcat (router_ip, plugin->m);
-
- node_ip = GNUNET_malloc (strlen (NODE_BASE_IP) + strlen (plugin->n) + 1);
- strcat (node_ip, NODE_BASE_IP);
- strcat (node_ip, plugin->n);
-
- plugin->api->start_testcase (NULL, router_ip, node_ip, NULL, NULL);
-
-}
-
-
-int
-main (int argc, char *const *argv)
-{
- int rv = 0;
- struct Plugin *plugin;
-
- GNUNET_log_setup ("gnunet-cmd",
- "DEBUG",
- NULL);
-
- plugin = GNUNET_new (struct Plugin);
- plugin->api = GNUNET_PLUGIN_load (argv[0],
- NULL);
- plugin->library_name = GNUNET_strdup (argv[0]);
-
- plugin->global_n = argv[1];
- plugin->local_m = argv[2];
- plugin->n = argv[3];
- plugin->m = argv[4];
-
- GNUNET_SCHEDULER_run (&run,
- plugin);
-
- GNUNET_free (plugin);
- return rv;
-}
diff --git a/src/testbed/testbed_api.h b/src/testbed/testbed_api.h
index 9a54ca36c..d4ef832ad 100644
--- a/src/testbed/testbed_api.h
+++ b/src/testbed/testbed_api.h
@@ -37,11 +37,6 @@
*/
#define HELPER_TESTBED_BINARY "gnunet-helper-testbed"
-/**
- * Cmds Helper binary name
- */
-#define HELPER_CMDS_BINARY "gnunet-cmds-helper"
-
/**
* Enumeration of operations
@@ -185,6 +180,7 @@ struct OperationContext
typedef void
(*TESTBED_opcq_empty_cb) (void *cls);
+
/**
* Handle to interact with a GNUnet testbed controller. Each
* controller has at least one master handle which is created when the
diff --git a/src/testbed/testbed_api_cmd_controller.c b/src/testbed/testbed_api_cmd_controller.c
deleted file mode 100644
index 794b1ccf3..000000000
--- a/src/testbed/testbed_api_cmd_controller.c
+++ /dev/null
@@ -1,203 +0,0 @@
-/*
- This file is part of GNUnet
- Copyright (C) 2021 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 testbed/testbed_api_cmd_controller.c
- * @brief Command to create a controller.
- * @author t3sserakt
- */
-#include "platform.h"
-#include "gnunet_util_lib.h"
-#include "gnunet_testing_ng_lib.h"
-#include "gnunet-service-testbed.h"
-#include "testbed_api_hosts.h"
-#include "gnunet_testbed_ng_service.h"
-
-
-/**
- * Generic logging shortcut
- */
-#define LOG(kind, ...) \
- GNUNET_log (kind, __VA_ARGS__)
-
-
-/**
-*
-*
-* @param cls closure
-* @param cmd current CMD being cleaned up.
-*/
-static void
-controller_cleanup (void *cls,
- const struct GNUNET_TESTING_Command *cmd)
-{
- (void) cls;
-}
-
-
-/**
- * Signature of the event handler function called by the
- * respective event controller.
- *
- * @param cls closure
- * @param event information about the event
- */
-static void
-controller_cb (void *cls,
- const struct GNUNET_TESTBED_EventInformation *event)
-{
- struct ControllerState *cs = cls;
-
- if (NULL != event->details.operation_finished.emsg)
- {
- LOG (GNUNET_ERROR_TYPE_ERROR, "There was an operation error: %s\n",
- event->details.operation_finished.emsg);
- GNUNET_TESTBED_shutdown_controller (cs);
- }
- else if (NULL == event->details.operation_finished.generic)
- {
- GNUNET_TESTBED_operation_done (event->op);
- }
-}
-
-
-static void
-controller_run (void *cls,
- const struct GNUNET_TESTING_Command *cmd,
- struct GNUNET_TESTING_Interpreter *is)
-{
- struct ControllerState *cs = cls;
-
- cs->is = is;
-
- cs->controller =
- GNUNET_TESTBED_controller_connect (cs->host, cs->event_mask, &controller_cb,
- cs);
-
-
-}
-
-/**
-*
-*
-* @param cls closure.
-* @param[out] ret result
-* @param trait name of the trait.
-* @param index index number of the object to offer.
-* @return #GNUNET_OK on success.
-*/
-static int
-controller_traits (void *cls,
- const void **ret,
- const char *trait,
- unsigned int index)
-{
- (void) cls;
-
- struct ControllerState *cs = cls;
-
-
- struct GNUNET_TESTING_Trait traits[] = {
- {
- .index = 0,
- .trait_name = "controller",
- .ptr = (const void *) cs->controller,
- },
- GNUNET_TESTING_trait_end ()
- };
-
- return GNUNET_TESTING_get_trait (traits,
- ret,
- trait,
- index);
- return GNUNET_OK;
-}
-
-
-/**
- * Offer data from trait
- *
- * @param cmd command to extract the controller from.
- * @param pt pointer to controller.
- * @return #GNUNET_OK on success.
- */
-int
-GNUNET_TESTBED_get_trait_controller (const struct GNUNET_TESTING_Command *cmd,
- struct GNUNET_TESTBED_Controller **
- controller)
-{
- return cmd->traits (cmd->cls,
- (const void **) controller,
- "controller",
- (unsigned int) 0);
-}
-
-
-/**
- * Shutdown nicely
- *
- * @param cs controller state.
- */
-void
-GNUNET_TESTBED_shutdown_controller (struct ControllerState *cs)
-{
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Shutting down...\n");
-
- cs->controller_going_down = GNUNET_YES;
-
- if (NULL != cs->abort_task)
- GNUNET_SCHEDULER_cancel (cs->abort_task);
- if (NULL != cs->reg_handle)
- GNUNET_TESTBED_cancel_registration (cs->reg_handle);
- if (NULL != cs->controller)
- GNUNET_TESTBED_controller_disconnect (cs->controller);
- if (NULL != cs->cfg)
- GNUNET_CONFIGURATION_destroy (cs->cfg);
- if (NULL != cs->cp)
- GNUNET_TESTBED_controller_stop (cs->cp);
- if (NULL != cs->host)
- GNUNET_TESTBED_host_destroy (cs->host);
-}
-
-
-
-struct GNUNET_TESTING_Command
-GNUNET_TESTBED_cmd_controller (const char *label,
- const char *host,
- uint64_t event_mask)
-{
- struct ControllerState *cs;
-
- cs = GNUNET_new (struct ControllerState);
- cs->event_mask = event_mask;
- cs->hostname = host;
-
-
- struct GNUNET_TESTING_Command cmd = {
- .cls = cs,
- .label = label,
- .run = &controller_run,
- .cleanup = &controller_cleanup,
- .traits = &controller_traits
- };
-
- return cmd;
-}
diff --git a/src/testbed/testbed_api_cmd_peer.c b/src/testbed/testbed_api_cmd_peer.c
deleted file mode 100644
index 2e253e408..000000000
--- a/src/testbed/testbed_api_cmd_peer.c
+++ /dev/null
@@ -1,281 +0,0 @@
-/*
- This file is part of GNUnet
- Copyright (C) 2021 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 testbed/testbed_api_cmd_peer.c
- * @brief Command to create a peer.
- * @author t3sserakt
- */
-#include "platform.h"
-#include "gnunet_util_lib.h"
-#include "gnunet_testing_ng_lib.h"
-#include "gnunet_testbed_ng_service.h"
-#include "gnunet-service-testbed.h"
-#include "testbed_api_peers.h"
-
-
-/**
- * Generic logging shortcut
- */
-#define LOG(kind, ...) \
- GNUNET_log (kind, __VA_ARGS__)
-
-
-/**
-*
-*
-* @param cls closure.
-* @param[out] ret result
-* @param trait name of the trait.
-* @param index index number of the object to offer.
-* @return #GNUNET_OK on success.
-*/
-static int
-peer_traits (void *cls,
- const void **ret,
- const char *trait,
- unsigned int index)
-{
- struct PeerCmdState *ps = cls;
-
- struct GNUNET_TESTING_Trait traits[] = {
- {
- .index = 0,
- .trait_name = "peer",
- .ptr = (const void *) ps->peer,
- },
- GNUNET_TESTING_trait_end ()
- };
-
- return GNUNET_TESTING_get_trait (traits,
- ret,
- trait,
- index);
-
- return GNUNET_OK;
-}
-
-/**
- * Offer data from trait
- *
- * @param cmd command to extract the controller from.
- * @param peer pointer GNUNET_TESTBED_PEER
- * @return #GNUNET_OK on success.
- */
-int
-GNUNET_TESTBED_get_trait_peer (const struct GNUNET_TESTING_Command *cmd,
- struct GNUNET_TESTBED_Peer **
- peer)
-{
- return cmd->traits (cmd->cls,
- (const void **) peer,
- "peer",
- (unsigned int) 0);
-}
-
-
-/**
-*
-*
-* @param cls closure
-* @param cmd current CMD being cleaned up.
-*/
-static void
-peer_cleanup (void *cls,
- const struct GNUNET_TESTING_Command *cmd)
-{
- (void) cls;
-}
-
-
-/**
- * abort task to run on test timed out
- *
- * @param cls NULL
- * @param tc the task context
- */
-static void
-do_abort (void *cls)
-{
- struct PeerCmdState *ps = cls;
-
- if (GNUNET_NO == ps->peer_ready)
- {
- LOG (GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n");
- ps->abort_task = NULL;
- GNUNET_TESTBED_shutdown_peer (ps);
- }
-}
-
-
-/**
- * Functions of this signature are called when a peer has been successfully
- * created
- *
- * @param cls the closure from GNUNET_TESTBED_peer_create()
- * @param emsg MAY contain an error description, if starting peer failed.
- */
-static void
-peer_started_cb (void *cls,
- const char *emsg)
-{
- struct PeerCmdState *ps = cls;
-
- GNUNET_TESTBED_operation_done (ps->operation);
- if (NULL == emsg)
- {
- ps->peer_ready = GNUNET_YES;
- }
- else
- {
- LOG (GNUNET_ERROR_TYPE_ERROR, "There was an error starting a peer: %s\n",
- emsg);
- }
-
-}
-
-
-/**
- * Functions of this signature are called when a peer has been successfully
- * created
- *
- * @param cls the closure from GNUNET_TESTBED_peer_create()
- * @param peer the handle for the created peer; NULL on any error during
- * creation
- * @param emsg NULL if peer is not NULL; else MAY contain the error description
- */
-static void
-peer_create_cb (void *cls,
- struct GNUNET_TESTBED_Peer *peer,
- const char *emsg)
-{
- struct PeerCmdState *ps = cls;
-
- ps->peer = peer;
- GNUNET_TESTBED_operation_done (ps->operation);
- ps->operation = GNUNET_TESTBED_peer_start (NULL,
- peer,
- &peer_started_cb,
- ps);
-}
-
-
-static void
-peer_run (void *cls,
- const struct GNUNET_TESTING_Command *cmd,
- struct GNUNET_TESTING_Interpreter *is)
-{
- struct PeerCmdState *ps = cls;
- const struct GNUNET_TESTING_Command *controller_cmd;
- struct GNUNET_TESTBED_Controller *controller;
-
- ps->is = is;
- controller_cmd = GNUNET_TESTING_interpreter_lookup_command (
- ps->controller_label);
- GNUNET_TESTBED_get_trait_controller (controller_cmd,
- &controller);
- ps->host = GNUNET_TESTBED_host_create (ps->hostname, ps->username, ps->cfg,
- ps->port);
- ps->operation =
- GNUNET_TESTBED_peer_create (controller,
- ps->host,
- ps->cfg,
- &peer_create_cb,
- ps);
-
- ps->abort_task =
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_MINUTES, 5),
- &do_abort,
- ps);
-}
-
-
-void
-peer_stopped_cb (void *cls,
- const char *emsg)
-{
- struct PeerCmdState *ps = cls;
-
- if (NULL != emsg)
- {
- LOG (GNUNET_ERROR_TYPE_ERROR, "There was an error stopping a peer: %s\n",
- emsg);
- }
- GNUNET_TESTBED_operation_done (ps->operation);
- GNUNET_TESTBED_peer_destroy (ps->peer);
-}
-
-
-/**
- * Shutdown nicely
- *
- * @param cs controller state.
- */
-void
-GNUNET_TESTBED_shutdown_peer (struct PeerCmdState *ps)
-{
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Shutting down...\n");
-
- ps->peer_going_down = GNUNET_YES;
-
- if (NULL != ps->abort_task)
- GNUNET_SCHEDULER_cancel (ps->abort_task);
- if (NULL != ps->cfg)
- GNUNET_CONFIGURATION_destroy (ps->cfg);
- if (NULL != ps->host)
- GNUNET_TESTBED_host_destroy (ps->host);
-
- GNUNET_TESTBED_operation_done (ps->operation);
- ps->operation = GNUNET_TESTBED_peer_stop (NULL, ps->peer, peer_stopped_cb,
- ps);
-
-}
-
-
-struct GNUNET_TESTING_Command
-GNUNET_TESTBED_cmd_peer (const char *label,
- const char *controller_label,
- const char *hostname,
- const char *username,
- uint16_t port,
- struct GNUNET_CONFIGURATION_Handle *cfg)
-{
- struct PeerCmdState *ps;
-
- ps = GNUNET_new (struct PeerCmdState);
- ps->hostname = hostname;
- ps->username = username;
- ps->port = port;
- ps->cfg = cfg;
- ps->controller_label = controller_label;
-
- struct GNUNET_TESTING_Command cmd = {
- .cls = ps,
- .label = label,
- .run = &peer_run,
- .cleanup = &peer_cleanup,
- .traits = &peer_traits
- };
-
- return cmd;
-}
diff --git a/src/testbed/testbed_api_cmd_peer_store.c b/src/testbed/testbed_api_cmd_peer_store.c
deleted file mode 100644
index fc96f589c..000000000
--- a/src/testbed/testbed_api_cmd_peer_store.c
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- This file is part of GNUnet
- Copyright (C) 2021 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 testbed/testbed_api_cmd_peer_store.c
- * @brief Command to start the peer store service of a peer.
- * @author t3sserakt
- */
-
-
-static void
-service_run (void *cls,
- const struct GNUNET_TESTING_Command *cmd,
- struct GNUNET_TESTING_Interpreter *is)
-{
- struct PeerStoreState *pss = cls;
-
- pss->psh = GNUNET_PEERSTORE_connect (pss->cfg);
- GNUNET_TESTING_interpreter_next (ps->is);
-}
-
-
-struct GNUNET_TESTING_Command
-GNUNET_TESTBED_cmd_peer_store (const char *label,
- struct GNUNET_CONFIGURATION_Handle *cfg)
-{
-
- struct PeerStoreState *pss;
-
- pss = GNUNET_new (struct PeerStoreState);
- pss->cfg = cfg;
-
- struct GNUNET_TESTING_Command cmd = {
- .cls = pss,
- .label = label,
- .run = &peer_store_run,
- .cleanup = &peer_store_cleanup,
- .traits = &peer_store_traits
- };
-
- return cmd;
-
-}
diff --git a/src/testbed/testbed_api_cmd_send_peer_ready.c b/src/testbed/testbed_api_cmd_send_peer_ready.c
deleted file mode 100644
index f175a3e18..000000000
--- a/src/testbed/testbed_api_cmd_send_peer_ready.c
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- This file is part of GNUnet
- Copyright (C) 2021 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 testing_api_cmd_send_peer_ready.c
- * @brief cmd to send a helper message if peer is ready.
- * @author t3sserakt
- */
-#include "platform.h"
-#include "gnunet_util_lib.h"
-#include "gnunet_testing_ng_lib.h"
-#include "testbed_helper.h"
-
-
-struct SendPeerReadyState
-{
- TESTBED_CMD_HELPER_write_cb write_message;
-
- struct GNUNET_CMDS_PEER_STARTED *reply;
-};
-
-
-static int
-send_peer_ready_traits (void *cls,
- const void **ret,
- const char *trait,
- unsigned int index)
-{
- return GNUNET_OK;
-}
-
-
-static void
-send_peer_ready_cleanup (void *cls,
- const struct GNUNET_TESTING_Command *cmd)
-{
- struct SendPeerReadyState *sprs = cls;
-
- GNUNET_free (sprs->reply);
- GNUNET_free (sprs);
-}
-
-
-static void
-send_peer_ready_run (void *cls,
- const struct GNUNET_TESTING_Command *cmd,
- struct GNUNET_TESTING_Interpreter *is)
-{
- struct SendPeerReadyState *sprs = cls;
- struct GNUNET_CMDS_PEER_STARTED *reply;
- size_t msg_length;
-
- msg_length = sizeof(struct GNUNET_CMDS_PEER_STARTED);
- reply = GNUNET_new (struct GNUNET_CMDS_PEER_STARTED);
- reply->header.type = htons (GNUNET_MESSAGE_TYPE_CMDS_HELPER_PEER_STARTED);
- reply->header.size = htons ((uint16_t) msg_length);
- sprs->reply = reply;
- sprs->write_message ((struct GNUNET_MessageHeader *) reply, msg_length);
-}
-
-
-/**
- * Create command.
- *
- * @param label name for command.
- * @return command.
- */
-struct GNUNET_TESTING_Command
-GNUNET_TESTING_cmd_send_peer_ready (const char *label,
- TESTBED_CMD_HELPER_write_cb write_message)
-{
- struct SendPeerReadyState *sprs;
-
- sprs = GNUNET_new (struct SendPeerReadyState);
- sprs->write_message = write_message;
-
- struct GNUNET_TESTING_Command cmd = {
- .cls = sprs,
- .label = label,
- .run = &send_peer_ready_run,
- .cleanup = &send_peer_ready_cleanup,
- .traits = &send_peer_ready_traits
- };
-
- return cmd;
-}
diff --git a/src/testbed/testbed_api_cmd_tng_connect.c b/src/testbed/testbed_api_cmd_tng_connect.c
deleted file mode 100644
index e52cd3c76..000000000
--- a/src/testbed/testbed_api_cmd_tng_connect.c
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- This file is part of GNUnet
- Copyright (C) 2021 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 testbed/testbed_api_cmd_peer.c
- * @brief Command to create a peer.
- * @author t3sserakt
- */
-
-
-static void
-tng_connect_run (void *cls,
- const struct GNUNET_TESTING_Command *cmd,
- struct GNUNET_TESTING_Interpreter *is)
-{
- struct TngConnectState *tcs = cls;
-
- tcs->ah = GNUNET_TRANSPORT_application_init (tcs->cfg);
-}
-
-struct GNUNET_TESTING_Command
-GNUNET_TESTBED_cmd_tng_connect (const char *label)
-{
- struct TngConnectState *tcs;
-
- ts = GNUNET_new (struct TngConnectState);
-
- struct GNUNET_TESTING_Command cmd = {
- .cls = tcs,
- .label = label,
- .run = &tng_connect_run,
- .cleanup = &tmg_connect_cleanup,
- .traits = &tng_connect_traits
- };
-
- return cmd;
-}
diff --git a/src/testbed/testbed_api_cmd_tng_service.c b/src/testbed/testbed_api_cmd_tng_service.c
deleted file mode 100644
index cce2e14e3.