From 1940b899b3620786b0265144ab756a3f05bcc8b0 Mon Sep 17 00:00:00 2001 From: "Schanzenbach, Martin" Date: Thu, 16 Aug 2018 18:48:04 +0200 Subject: start zklaim service --- configure.ac | 1 + po/POTFILES.in | 125 ++++---- src/Makefile.am | 1 + src/include/gnunet_protocols.h | 5 + src/include/gnunet_reclaim_attribute_lib.h | 6 + src/zklaim/Makefile.am | 47 ++- src/zklaim/plugin_reclaim_attribute_zklaim.c | 181 +++++++++++ src/zklaim/zklaim_api.c | 433 +++++++++++++++++++++++++++ src/zklaim/zklaim_api.h | 90 ++++++ 9 files changed, 823 insertions(+), 66 deletions(-) create mode 100644 src/zklaim/plugin_reclaim_attribute_zklaim.c create mode 100644 src/zklaim/zklaim_api.c create mode 100644 src/zklaim/zklaim_api.h diff --git a/configure.ac b/configure.ac index 91a2f5227..53539cbb0 100644 --- a/configure.ac +++ b/configure.ac @@ -1772,6 +1772,7 @@ src/rest-plugins/Makefile src/abe/Makefile src/reclaim-attribute/Makefile src/reclaim/Makefile +src/zklaim/Makefile pkgconfig/Makefile pkgconfig/gnunetarm.pc pkgconfig/gnunetats.pc diff --git a/po/POTFILES.in b/po/POTFILES.in index a0fbfc6a1..a18d114ed 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -4,13 +4,21 @@ src/arm/arm_monitor_api.c src/arm/gnunet-arm.c src/arm/gnunet-service-arm.c src/arm/mockup-service.c +src/ats-tests/ats-testing-experiment.c +src/ats-tests/ats-testing-log.c +src/ats-tests/ats-testing-preferences.c +src/ats-tests/ats-testing-traffic.c +src/ats-tests/ats-testing.c +src/ats-tests/gnunet-ats-sim.c +src/ats-tests/gnunet-solver-eval.c +src/ats-tool/gnunet-ats.c src/ats/ats_api_connectivity.c src/ats/ats_api_performance.c src/ats/ats_api_scanner.c src/ats/ats_api_scheduling.c src/ats/gnunet-ats-solver-eval.c -src/ats/gnunet-service-ats_addresses.c src/ats/gnunet-service-ats.c +src/ats/gnunet-service-ats_addresses.c src/ats/gnunet-service-ats_connectivity.c src/ats/gnunet-service-ats_normalization.c src/ats/gnunet-service-ats_performance.c @@ -21,14 +29,6 @@ src/ats/gnunet-service-ats_scheduling.c src/ats/plugin_ats_mlp.c src/ats/plugin_ats_proportional.c src/ats/plugin_ats_ril.c -src/ats-tests/ats-testing.c -src/ats-tests/ats-testing-experiment.c -src/ats-tests/ats-testing-log.c -src/ats-tests/ats-testing-preferences.c -src/ats-tests/ats-testing-traffic.c -src/ats-tests/gnunet-ats-sim.c -src/ats-tests/gnunet-solver-eval.c -src/ats-tool/gnunet-ats.c src/auction/gnunet-auction-create.c src/auction/gnunet-auction-info.c src/auction/gnunet-auction-join.c @@ -40,8 +40,8 @@ src/block/plugin_block_test.c src/cadet/cadet_api.c src/cadet/cadet_test_lib.c src/cadet/desirability_table.c -src/cadet/gnunet-cadet.c src/cadet/gnunet-cadet-profiler.c +src/cadet/gnunet-cadet.c src/cadet/gnunet-service-cadet.c src/cadet/gnunet-service-cadet_channel.c src/cadet/gnunet-service-cadet_connection.c @@ -57,15 +57,15 @@ src/consensus/gnunet-service-consensus.c src/consensus/plugin_block_consensus.c src/conversation/conversation_api.c src/conversation/conversation_api_call.c -src/conversation/gnunet-conversation.c src/conversation/gnunet-conversation-test.c -src/conversation/gnunet_gst.c -src/conversation/gnunet_gst_test.c -src/conversation/gnunet-helper-audio-playback.c +src/conversation/gnunet-conversation.c src/conversation/gnunet-helper-audio-playback-gst.c -src/conversation/gnunet-helper-audio-record.c +src/conversation/gnunet-helper-audio-playback.c src/conversation/gnunet-helper-audio-record-gst.c +src/conversation/gnunet-helper-audio-record.c src/conversation/gnunet-service-conversation.c +src/conversation/gnunet_gst.c +src/conversation/gnunet_gst_test.c src/conversation/microphone.c src/conversation/plugin_gnsrecord_conversation.c src/conversation/speaker.c @@ -102,7 +102,6 @@ src/dht/dht_api.c src/dht/dht_test_lib.c src/dht/gnunet-dht-get.c src/dht/gnunet-dht-monitor.c -src/dht/gnunet_dht_profiler.c src/dht/gnunet-dht-put.c src/dht/gnunet-service-dht.c src/dht/gnunet-service-dht_clients.c @@ -111,6 +110,7 @@ src/dht/gnunet-service-dht_hello.c src/dht/gnunet-service-dht_neighbours.c src/dht/gnunet-service-dht_nse.c src/dht/gnunet-service-dht_routing.c +src/dht/gnunet_dht_profiler.c src/dht/plugin_block_dht.c src/dns/dns_api.c src/dns/gnunet-dns-monitor.c @@ -124,8 +124,8 @@ src/dv/gnunet-dv.c src/dv/gnunet-service-dv.c src/dv/plugin_transport_dv.c src/exit/gnunet-daemon-exit.c -src/exit/gnunet-helper-exit.c src/exit/gnunet-helper-exit-windows.c +src/exit/gnunet-helper-exit.c src/fragmentation/defragmentation.c src/fragmentation/fragmentation.c src/fs/fs_api.c @@ -150,8 +150,8 @@ src/fs/gnunet-auto-share.c src/fs/gnunet-daemon-fsprofiler.c src/fs/gnunet-directory.c src/fs/gnunet-download.c -src/fs/gnunet-fs.c src/fs/gnunet-fs-profiler.c +src/fs/gnunet-fs.c src/fs/gnunet-helper-fs-publish.c src/fs/gnunet-publish.c src/fs/gnunet-search.c @@ -171,10 +171,10 @@ src/gns/gns_tld_api.c src/gns/gnunet-bcd.c src/gns/gnunet-dns2gns.c src/gns/gnunet-gns-benchmark.c -src/gns/gnunet-gns.c src/gns/gnunet-gns-helper-service-w32.c src/gns/gnunet-gns-import.c src/gns/gnunet-gns-proxy.c +src/gns/gnunet-gns.c src/gns/gnunet-service-gns.c src/gns/gnunet-service-gns_interceptor.c src/gns/gnunet-service-gns_resolver.c @@ -182,16 +182,15 @@ src/gns/nss/nss_gns.c src/gns/nss/nss_gns_query.c src/gns/plugin_block_gns.c src/gns/plugin_gnsrecord_gns.c -src/gns/plugin_rest_gns.c +src/gns/w32nsp-install.c +src/gns/w32nsp-resolve.c +src/gns/w32nsp-uninstall.c +src/gns/w32nsp.c src/gnsrecord/gnsrecord.c src/gnsrecord/gnsrecord_crypto.c src/gnsrecord/gnsrecord_misc.c src/gnsrecord/gnsrecord_serialization.c src/gnsrecord/plugin_gnsrecord_dns.c -src/gns/w32nsp.c -src/gns/w32nsp-install.c -src/gns/w32nsp-resolve.c -src/gns/w32nsp-uninstall.c src/hello/address.c src/hello/gnunet-hello.c src/hello/hello.c @@ -202,17 +201,17 @@ src/identity/gnunet-identity.c src/identity/gnunet-service-identity.c src/identity/identity_api.c src/identity/identity_api_lookup.c -src/identity/plugin_rest_identity.c -src/jsonapi/jsonapi.c -src/jsonapi/jsonapi_document.c -src/jsonapi/jsonapi_error.c -src/jsonapi/jsonapi_relationship.c -src/jsonapi/jsonapi_resource.c src/json/json.c src/json/json_generator.c src/json/json_gnsrecord.c src/json/json_helper.c src/json/json_mhd.c +src/jsonapi/jsonapi.c +src/jsonapi/jsonapi_document.c +src/jsonapi/jsonapi_error.c +src/jsonapi/jsonapi_relationship.c +src/jsonapi/jsonapi_resource.c +src/jsonapi/plugin_rest_reclaim.c src/multicast/gnunet-multicast.c src/multicast/gnunet-service-multicast.c src/multicast/multicast_api.c @@ -226,8 +225,8 @@ src/namecache/namecache_api.c src/namecache/plugin_namecache_flat.c src/namecache/plugin_namecache_postgres.c src/namecache/plugin_namecache_sqlite.c -src/namestore/gnunet-namestore.c src/namestore/gnunet-namestore-fcfsd.c +src/namestore/gnunet-namestore.c src/namestore/gnunet-service-namestore.c src/namestore/gnunet-zoneimport.c src/namestore/namestore_api.c @@ -242,10 +241,10 @@ src/nat-auto/gnunet-service-nat-auto.c src/nat-auto/gnunet-service-nat-auto_legacy.c src/nat-auto/nat_auto_api.c src/nat-auto/nat_auto_api_test.c -src/nat/gnunet-helper-nat-client.c src/nat/gnunet-helper-nat-client-windows.c -src/nat/gnunet-helper-nat-server.c +src/nat/gnunet-helper-nat-client.c src/nat/gnunet-helper-nat-server-windows.c +src/nat/gnunet-helper-nat-server.c src/nat/gnunet-nat.c src/nat/gnunet-service-nat.c src/nat/gnunet-service-nat_externalip.c @@ -254,15 +253,15 @@ src/nat/gnunet-service-nat_mini.c src/nat/gnunet-service-nat_stun.c src/nat/nat_api.c src/nat/nat_api_stun.c -src/nse/gnunet-nse.c src/nse/gnunet-nse-profiler.c +src/nse/gnunet-nse.c src/nse/gnunet-service-nse.c src/nse/nse_api.c +src/peerinfo-tool/gnunet-peerinfo.c +src/peerinfo-tool/gnunet-peerinfo_plugins.c src/peerinfo/gnunet-service-peerinfo.c src/peerinfo/peerinfo_api.c src/peerinfo/peerinfo_api_notify.c -src/peerinfo-tool/gnunet-peerinfo.c -src/peerinfo-tool/gnunet-peerinfo_plugins.c src/peerstore/gnunet-peerstore.c src/peerstore/gnunet-service-peerstore.c src/peerstore/peerstore_api.c @@ -292,7 +291,6 @@ src/reclaim-attribute/reclaim_attribute.c src/reclaim/gnunet-reclaim.c src/reclaim/gnunet-service-reclaim.c src/reclaim/jwt.c -src/reclaim/oidc_helper.c src/reclaim/plugin_gnsrecord_reclaim.c src/reclaim/plugin_reclaim_sqlite.c src/reclaim/reclaim_api.c @@ -318,27 +316,25 @@ src/rest-plugins/plugin_rest_namestore.c src/rest-plugins/plugin_rest_openid_connect.c src/rest-plugins/plugin_rest_peerinfo.c src/rest/gnunet-rest-server.c -src/rest/plugin_rest_copying.c src/rest/rest.c src/revocation/gnunet-revocation.c src/revocation/gnunet-service-revocation.c src/revocation/plugin_block_revocation.c src/revocation/revocation_api.c -src/rps/gnunet-rps.c src/rps/gnunet-rps-profiler.c +src/rps/gnunet-rps.c src/rps/gnunet-service-rps.c src/rps/gnunet-service-rps_custommap.c src/rps/gnunet-service-rps_sampler.c src/rps/gnunet-service-rps_sampler_elem.c src/rps/gnunet-service-rps_view.c -src/rps/rps_api.c -src/rps/rps_test_lib.c src/rps/rps-test_util.c +src/rps/rps_api.c src/scalarproduct/gnunet-scalarproduct.c -src/scalarproduct/gnunet-service-scalarproduct_alice.c -src/scalarproduct/gnunet-service-scalarproduct_bob.c src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c src/scalarproduct/gnunet-service-scalarproduct-ecc_bob.c +src/scalarproduct/gnunet-service-scalarproduct_alice.c +src/scalarproduct/gnunet-service-scalarproduct_bob.c src/scalarproduct/scalarproduct_api.c src/secretsharing/gnunet-secretsharing-profiler.c src/secretsharing/gnunet-service-secretsharing.c @@ -367,15 +363,16 @@ src/statistics/gnunet-statistics.c src/statistics/statistics_api.c src/template/gnunet-service-template.c src/template/gnunet-template.c +src/testbed-logger/gnunet-service-testbed-logger.c +src/testbed-logger/testbed_logger_api.c src/testbed/generate-underlay-topology.c src/testbed/gnunet-daemon-latency-logger.c src/testbed/gnunet-daemon-testbed-blacklist.c src/testbed/gnunet-daemon-testbed-underlay.c src/testbed/gnunet-helper-testbed.c -src/testbed/gnunet_mpi_test.c src/testbed/gnunet-service-test-barriers.c -src/testbed/gnunet-service-testbed_barriers.c src/testbed/gnunet-service-testbed.c +src/testbed/gnunet-service-testbed_barriers.c src/testbed/gnunet-service-testbed_cache.c src/testbed/gnunet-service-testbed_connectionpool.c src/testbed/gnunet-service-testbed_cpustatus.c @@ -383,20 +380,19 @@ src/testbed/gnunet-service-testbed_links.c src/testbed/gnunet-service-testbed_meminfo.c src/testbed/gnunet-service-testbed_oc.c src/testbed/gnunet-service-testbed_peers.c -src/testbed/gnunet_testbed_mpi_spawn.c src/testbed/gnunet-testbed-profiler.c -src/testbed-logger/gnunet-service-testbed-logger.c -src/testbed-logger/testbed_logger_api.c -src/testbed/testbed_api_barriers.c +src/testbed/gnunet_mpi_test.c +src/testbed/gnunet_testbed_mpi_spawn.c src/testbed/testbed_api.c +src/testbed/testbed_api_barriers.c src/testbed/testbed_api_hosts.c src/testbed/testbed_api_operations.c src/testbed/testbed_api_peers.c src/testbed/testbed_api_sd.c src/testbed/testbed_api_services.c src/testbed/testbed_api_statistics.c -src/testbed/testbed_api_testbed.c src/testbed/testbed_api_test.c +src/testbed/testbed_api_testbed.c src/testbed/testbed_api_topology.c src/testbed/testbed_api_underlay.c src/testing/gnunet-testing.c @@ -405,28 +401,28 @@ src/testing/testing.c src/topology/friends.c src/topology/gnunet-daemon-topology.c src/transport/gnunet-helper-transport-bluetooth.c -src/transport/gnunet-helper-transport-wlan.c src/transport/gnunet-helper-transport-wlan-dummy.c -src/transport/gnunet-service-transport_ats.c +src/transport/gnunet-helper-transport-wlan.c src/transport/gnunet-service-transport.c +src/transport/gnunet-service-transport_ats.c src/transport/gnunet-service-transport_hello.c src/transport/gnunet-service-transport_manipulation.c src/transport/gnunet-service-transport_neighbours.c src/transport/gnunet-service-transport_plugins.c src/transport/gnunet-service-transport_validation.c -src/transport/gnunet-transport.c src/transport/gnunet-transport-certificate-creation.c src/transport/gnunet-transport-profiler.c src/transport/gnunet-transport-wlan-receiver.c src/transport/gnunet-transport-wlan-sender.c +src/transport/gnunet-transport.c src/transport/plugin_transport_http_client.c src/transport/plugin_transport_http_common.c src/transport/plugin_transport_http_server.c src/transport/plugin_transport_smtp.c src/transport/plugin_transport_tcp.c src/transport/plugin_transport_template.c -src/transport/plugin_transport_udp_broadcasting.c src/transport/plugin_transport_udp.c +src/transport/plugin_transport_udp_broadcasting.c src/transport/plugin_transport_unix.c src/transport/plugin_transport_wlan.c src/transport/plugin_transport_xt.c @@ -435,6 +431,11 @@ src/transport/tcp_connection_legacy.c src/transport/tcp_server_legacy.c src/transport/tcp_server_mst_legacy.c src/transport/tcp_service_legacy.c +src/transport/transport-testing-filenames.c +src/transport/transport-testing-loggers.c +src/transport/transport-testing-main.c +src/transport/transport-testing-send.c +src/transport/transport-testing.c src/transport/transport_api_address_to_string.c src/transport/transport_api_blacklist.c src/transport/transport_api_core.c @@ -443,11 +444,6 @@ src/transport/transport_api_manipulation.c src/transport/transport_api_monitor_peers.c src/transport/transport_api_monitor_plugins.c src/transport/transport_api_offer_hello.c -src/transport/transport-testing.c -src/transport/transport-testing-filenames.c -src/transport/transport-testing-loggers.c -src/transport/transport-testing-main.c -src/transport/transport-testing-send.c src/util/bandwidth.c src/util/bio.c src/util/client.c @@ -459,8 +455,8 @@ src/util/configuration_loader.c src/util/container_bloomfilter.c src/util/container_heap.c src/util/container_meta_data.c -src/util/container_multihashmap32.c src/util/container_multihashmap.c +src/util/container_multihashmap32.c src/util/container_multipeermap.c src/util/container_multishortmap.c src/util/crypto_abe.c @@ -482,15 +478,15 @@ src/util/dnsparser.c src/util/dnsstub.c src/util/getopt.c src/util/getopt_helpers.c -src/util/gnunet-config.c src/util/gnunet-config-diff.c +src/util/gnunet-config.c src/util/gnunet-ecc.c src/util/gnunet-helper-w32-console.c src/util/gnunet-resolver.c src/util/gnunet-scrypt.c src/util/gnunet-service-resolver.c -src/util/gnunet-timeout.c src/util/gnunet-timeout-w32.c +src/util/gnunet-timeout.c src/util/gnunet-uri.c src/util/helper.c src/util/load.c @@ -518,14 +514,15 @@ src/util/tun.c src/util/w32cat.c src/util/win.c src/util/winproc.c -src/vpn/gnunet-helper-vpn.c src/vpn/gnunet-helper-vpn-windows.c +src/vpn/gnunet-helper-vpn.c src/vpn/gnunet-service-vpn.c src/vpn/gnunet-vpn.c src/vpn/vpn_api.c +src/zklaim/plugin_reclaim_attribute_zklaim.c src/zklaim/zklaim.c -src/zonemaster/gnunet-service-zonemaster.c src/zonemaster/gnunet-service-zonemaster-monitor.c +src/zonemaster/gnunet-service-zonemaster.c src/fs/fs_api.h src/include/gnunet_common.h src/include/gnunet_mq_lib.h diff --git a/src/Makefile.am b/src/Makefile.am index 1c129b041..54f6dfab2 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -29,6 +29,7 @@ if HAVE_ZKLAIM EXP_DIR += zklaim endif endif +endif if HAVE_JSON EXP_DIR += \ auction diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h index 4400db7e1..0081138e0 100644 --- a/src/include/gnunet_protocols.h +++ b/src/include/gnunet_protocols.h @@ -2700,6 +2700,11 @@ extern "C" /******************************************************************************/ +/******************************************************************************/ +/*********************************** ZKLAIM ***********************************/ +#define GNUNET_MESSAGE_TYPE_ZKLAIM_CREATE 990 + +#define GNUNET_MESSAGE_TYPE_ZKLAIM_RESULT_CODE 991 /******************************************************************************/ /*********************************** CADET **********************************/ diff --git a/src/include/gnunet_reclaim_attribute_lib.h b/src/include/gnunet_reclaim_attribute_lib.h index df5356d76..9b928328e 100644 --- a/src/include/gnunet_reclaim_attribute_lib.h +++ b/src/include/gnunet_reclaim_attribute_lib.h @@ -50,6 +50,12 @@ extern "C" #define GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING 1 +/** + * ZKlaim attribute. + */ +#define GNUNET_RECLAIM_ATTRIBUTE_TYPE_ZKLAIM 2 + + /** * An attribute. diff --git a/src/zklaim/Makefile.am b/src/zklaim/Makefile.am index a3432794a..1b25ac1a3 100644 --- a/src/zklaim/Makefile.am +++ b/src/zklaim/Makefile.am @@ -12,9 +12,51 @@ if USE_COVERAGE XLIB = -lgcov endif +plugin_LTLIBRARIES = \ + libgnunet_plugin_reclaim_attribute_zklaim.la -gnunet_zklaim_SOURCES = zklaim.c +lib_LTLIBRARIES = \ + libgnunetzklaim.la + +libgnunetzklaim_la_SOURCES = \ + zklaim_api.c \ + zklaim_api.h +libgnunetzklaim_la_LIBADD = \ + $(top_builddir)/src/util/libgnunetutil.la \ + $(GN_LIBINTL) $(XLIB) +libgnunetzklaim_la_LDFLAGS = \ + $(GN_LIB_LDFLAGS) $(WINFLAGS) \ + -version-info 0:0:0 + + +libgnunet_plugin_reclaim_attribute_zklaim_la_SOURCES = \ + plugin_reclaim_attribute_zklaim.c +libgnunet_plugin_reclaim_attribute_zklaim_la_LIBADD = \ + $(top_builddir)/src/util/libgnunetutil.la \ + $(LTLIBINTL) +libgnunet_plugin_reclaim_attribute_zklaim_la_LDFLAGS = \ + $(GN_PLUGIN_LDFLAGS) + +test_zklaim_SOURCES = zklaim.c +test_zklaim_LDADD = \ + $(GCLIBADD)\ + $(LIBGCRYPT_LIBS) \ + -lzklaim \ + -lgcrypt \ + -lgmp \ + -lgmpxx \ + -lcrypto \ + -lprocps \ + -lstdc++ \ + -lm +test_zklaim_LDFLAGS = \ + $(GN_LIB_LDFLAGS) + +gnunet_zklaim_SOURCES = gnunet-zklaim.c gnunet_zklaim_LDADD = \ + $(top_builddir)/src/util/libgnunetutil.la \ + $(top_builddir)/src/identity/libgnunetidentity.la \ + libgnunetzklaim.la \ $(GCLIBADD)\ $(LIBGCRYPT_LIBS) \ -lzklaim \ @@ -28,8 +70,9 @@ gnunet_zklaim_LDADD = \ gnunet_zklaim_LDFLAGS = \ $(GN_LIB_LDFLAGS) -#lib_LTLIBRARIES = libgnunetzklaim.la bin_PROGRAMS = gnunet-zklaim +#lib_LTLIBRARIES = libgnunetzklaim.la +check_PROGRAMS = test_zklaim 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; diff --git a/src/zklaim/plugin_reclaim_attribute_zklaim.c b/src/zklaim/plugin_reclaim_attribute_zklaim.c new file mode 100644 index 000000000..a79576cb1 --- /dev/null +++ b/src/zklaim/plugin_reclaim_attribute_zklaim.c @@ -0,0 +1,181 @@ +/* + This file is part of GNUnet + Copyright (C) 2013, 2014, 2016 GNUnet e.V. + + GNUnet is free software: you can redistribute it and/or modify it + under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, + or (at your option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + +/** + * @file zklaim/plugin_reclaim_attribute_zklaim.c + * @brief identity attribute plugin to provide the API for ZKlaims + * + * @author Martin Schanzenbach + */ +#include "platform.h" +#include "gnunet_util_lib.h" +#include "gnunet_reclaim_attribute_plugin.h" +#include + + +/** + * Convert the 'value' of an attribute to a string. + * + * @param cls closure, unused + * @param type type of the attribute + * @param data value in binary encoding + * @param data_size number of bytes in @a data + * @return NULL on error, otherwise human-readable representation of the value + */ +static char * +zklaim_value_to_string (void *cls, + uint32_t type, + const void *data, + size_t data_size) +{ + + switch (type) + { + case GNUNET_RECLAIM_ATTRIBUTE_TYPE_ZKLAIM: + return GNUNET_strndup (data, data_size); + default: + return NULL; + } +} + + +/** + * Convert human-readable version of a 'value' of an attribute to the binary + * representation. + * + * @param cls closure, unused + * @param type type of the attribute + * @param s human-readable string + * @param data set to value in binary encoding (will be allocated) + * @param data_size set to number of bytes in @a data + * @return #GNUNET_OK on success + */ +static int +zklaim_string_to_value (void *cls, + uint32_t type, + const char *s, + void **data, + size_t *data_size) +{ + if (NULL == s) + return GNUNET_SYSERR; + switch (type) + { + + case GNUNET_RECLAIM_ATTRIBUTE_TYPE_ZKLAIM: + *data = GNUNET_strdup (s); + *data_size = strlen (s); + return GNUNET_OK; + default: + return GNUNET_SYSERR; + } +} + + +/** + * Mapping of attribute type numbers to human-readable + * attribute type names. + */ +static struct { + const char *name; + uint32_t number; +} zklaim_name_map[] = { + { "ZKLAIM", GNUNET_RECLAIM_ATTRIBUTE_TYPE_ZKLAIM }, + { NULL, UINT32_MAX } +}; + + +/** + * Convert a type name to the corresponding number. + * + * @param cls closure, unused + * @param zklaim_typename name to convert + * @return corresponding number, UINT32_MAX on error + */ +static uint32_t +zklaim_typename_to_number (void *cls, + const char *zklaim_typename) +{ + unsigned int i; + + i=0; + while ( (NULL != zklaim_name_map[i].name) && + (0 != strcasecmp (zklaim_typename, + zklaim_name_map[i].name)) ) + i++; + return zklaim_name_map[i].number; +} + + +/** + * Convert a type number (i.e. 1) to the corresponding type string + * + * @param cls closure, unused + * @param type number of a type to convert + * @return corresponding typestring, NULL on error + */ +static const char * +zklaim_number_to_typename (void *cls, + uint32_t type) +{ + unsigned int i; + + i=0; + while ( (NULL != zklaim_name_map[i].name) && + (type != zklaim_name_map[i].number) ) + i++; + return zklaim_name_map[i].name; +} + + +/** + * Entry point for the plugin. + * + * @param cls NULL + * @return the exported block API + */ +void * +libgnunet_plugin_reclaim_attribute_zklaim_init (void *cls) +{ + struct GNUNET_RECLAIM_ATTRIBUTE_PluginFunctions *api; + + api = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_PluginFunctions); + api->value_to_string = &zklaim_value_to_string; + api->string_to_value = &zklaim_string_to_value; + api->typename_to_number = &zklaim_typename_to_number; + api->number_to_typename = &zklaim_number_to_typename; + return api; +} + + +/** + * Exit point from the plugin. + * + * @param cls the return value from #libgnunet_plugin_block_test_init() + * @return NULL + */ +void * +libgnunet_plugin_reclaim_attribute_zklaim_done (void *cls) +{ + struct GNUNET_RECLAIM_ATTRIBUTE_PluginFunctions *api = cls; + + GNUNET_free (api); + return NULL; +} + +/* end of plugin_reclaim_attribute_type_zklaim.c */ diff --git a/src/zklaim/zklaim_api.c b/src/zklaim/zklaim_api.c new file mode 100644 index 000000000..f54ede342 --- /dev/null +++ b/src/zklaim/zklaim_api.c @@ -0,0 +1,433 @@ +/* + This file is part of GNUnet. + Copyright (C) 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 . +*/ + +/** + * @file zklaim/zklaim_api.c + * @brief api to interact with the zklaim service + * @author Martin Schanzenbach + */ +#include "platform.h" +#include "gnunet_util_lib.h" +#include "gnunet_constants.h" +#include "gnunet_protocols.h" +#include "gnunet_zklaim_service.h" +#include "zklaim/zklaim.h" +#include "zklaim_api.h" + +#define LOG(kind,...) GNUNET_log_from (kind, "zklaim-api",__VA_ARGS__) + +/** + * Handle for an ego. + */ +struct GNUNET_ZKLAIM_Context +{ + /** + * ZKlaim context. + */ + struct zklaim_ctx *zk_ctx; + + /** + * Current name associated with this context. + */ + char *name; + + /** + * Attributes associated with context + */ + char *attrs; + + /** + * Client context associated with this ego. + */ + void *ctx; + +}; + + +/** + * Handle for an operation with the service. + */ +struct GNUNET_ZKLAIM_Operation +{ + + /** + * Main handle. + */ + struct GNUNET_ZKLAIM_Handle *h; + + /** + * We keep operations in a DLL. + */ + struct GNUNET_ZKLAIM_Operation *next; + + /** + * We keep operations in a DLL. + */ + struct GNUNET_ZKLAIM_Operation *prev; + + /** + * Message to send to the zklaim service. + * Allocated at the end of this struct. + */ + const struct GNUNET_MessageHeader *msg; + + /** + * Continuation to invoke with the result of the transmission; @e cb + * will be NULL in this case. + */ + GNUNET_ZKLAIM_ContinuationWithStatus cont; + + /** + * Closure for @e cont or @e cb. + */ + void *cls; + +}; + + +/** + * Handle for the service. + */ +struct GNUNET_ZKLAIM_Handle +{ + /** + * Configuration to use. + */ + const struct GNUNET_CONFIGURATION_Handle *cfg; + + /** + * Connection to service. + */ + struct GNUNET_MQ_Handle *mq; + + /** + * Hash map from the hash of the public key to the + * respective `GNUNET_ZKLAIM_Ego` handle. + */ + struct GNUNET_CONTAINER_MultiHashMap *egos; + + /** + * Closure for @e cb. + */ + void *cb_cls; + + /** + * Head of active operations. + */ + struct GNUNET_ZKLAIM_Operation *op_head; + + /** + * Tail of active operations. + */ + struct GNUNET_ZKLAIM_Operation *op_tail; + + /** + * Task doing exponential back-off trying to reconnect. + */ + struct GNUNET_SCHEDULER_Task *reconnect_task; + + /** + * Time for next connect retry. + */ + struct GNUNET_TIME_Relative reconnect_delay; + +}; + + +/** + * Try again to connect to the zklaim service. + * + * @param cls handle to the zklaim service. + */ +static void +reconnect (void *cls); + +/** + * Reschedule a connect attempt to the service. + * + * @param h transport service to reconnect + */ +static void +reschedule_connect (struct GNUNET_ZKLAIM_Handle *h) +{ + struct GNUNET_ZKLAIM_Operation *op; + + GNUNET_assert (NULL == h->reconnect_task); + + if (NULL != h->mq) + { + GNUNET_MQ_destroy (h->mq); + h->mq = NULL; + } + while (NULL != (op = h->op_head)) + { + GNUNET_CONTAINER_DLL_remove (h->op_head, + h->op_tail, + op); + if (NULL != op->cont) + op->cont (op->cls, + GNUNET_SYSERR, + "Error in communication with the zklaim service"); + GNUNET_free (op); + } + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Scheduling task to reconnect to zklaim service in %s.\n", + GNUNET_STRINGS_relative_time_to_string (h->reconnect_delay, + GNUNET_YES)); + h->reconnect_task = + GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, + &reconnect, + h); + h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay); +} + + +/** + * Generic error handler, called with the appropriate error code and + * the same closure specified at the creation of the message queue. + * Not every message queue implementation supports an error handler. + * + * @param cls closure with the `struct GNUNET_ZKLAIM_Handle *` + * @param error error code + */ +static void +mq_error_handler (void *cls, + enum GNUNET_MQ_Error error) +{ + struct GNUNET_ZKLAIM_Handle *h = cls; + + reschedule_connect (h); +} + + +/** + * We received a result code from the service. Check the message + * is well-formed. + * + * @param cls closure + * @param rcm result message received + * @return #GNUNET_OK if the message is well-formed + */ +static int +check_zklaim_result_code (void *cls, + const struct ResultCodeMessage *rcm) +{ + uint16_t size = ntohs (rcm->header.size) - sizeof (*rcm); + const char *str = (const char *) &rcm[1]; + + if (0 == size) + return GNUNET_OK; + if ('\0' != str[size - 1]) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } + return GNUNET_OK; +} + + +/** + * We received a result code from the service. + * + * @param cls closure + * @param rcm result message received + */ +static void +handle_zklaim_result_code (void *cls, + const struct ResultCodeMessage *rcm) +{ + struct GNUNET_ZKLAIM_Handle *h = cls; + struct GNUNET_ZKLAIM_Operation *op; + uint16_t size = ntohs (rcm->header.size) - sizeof (*rcm); + const char *str = (0 == size) ? NULL : (const char *) &rcm[1]; + + op = h->op_head; + if (NULL == op) + { + GNUNET_break (0); + reschedule_connect (h); + return; + } + GNUNET_CONTAINER_DLL_remove (h->op_head, + h->op_tail, + op); + if (NULL != op->cont) + op->cont (op->cls, + GNUNET_OK, + str); + GNUNET_free (op); +} + + +/** + * Try again to connect to the zklaim service. + * + * @param cls handle to the zklaim service. + */ +static void +reconnect (void *cls) +{ + struct GNUNET_ZKLAIM_Handle *h = cls; + struct GNUNET_MQ_MessageHandler handlers[] = { + GNUNET_MQ_hd_var_size (zklaim_result_code, + GNUNET_MESSAGE_TYPE_ZKLAIM_RESULT_CODE, + struct ResultCodeMessage, + h), + GNUNET_MQ_handler_end () + }; + + h->reconnect_task = NULL; + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Connecting to zklaim service.\n"); + GNUNET_assert (NULL == h->mq); + h->mq = GNUNET_CLIENT_connect (h->cfg, + "zklaim", + handlers, + &mq_error_handler, + h); + if (NULL == h->mq) + return; +} + + +/** + * Connect to the zklaim service. + * + * @param cfg the configuration to use + * @param cb function to call on all zklaim events, can be NULL + * @param cb_cls closure for @a cb + * @return handle to use + */ +struct GNUNET_ZKLAIM_Handle * +GNUNET_ZKLAIM_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) +{ + struct GNUNET_ZKLAIM_Handle *h; + + h = GNUNET_new (struct GNUNET_ZKLAIM_Handle); + h->cfg = cfg; + reconnect (h); + if (NULL == h->mq) + { + GNUNET_free (h); + return NULL; + } + return h; +} + + +/** + * Create a new zklaim with the given name. + * + * @param h zklaim service to use + * @param name desired name + * @param cont function to call with the result (will only be called once) + * @param cont_cls closure for @a cont + * @return handle to abort the operation + */ +struct GNUNET_ZKLAIM_Operation * +GNUNET_ZKLAIM_context_create (struct GNUNET_ZKLAIM_Handle *h, + const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, + const char *name, + const char *attr_list, + GNUNET_ZKLAIM_ContinuationWithStatus cont, + void *cont_cls) +{ + struct GNUNET_ZKLAIM_Operation *op; + struct GNUNET_MQ_Envelope *env; + struct CreateRequestMessage *crm; + size_t slen; + + if (NULL == h->mq) + return NULL; + slen = strlen (name) + 1; + if (slen >= GNUNET_MAX_MESSAGE_SIZE - sizeof (struct CreateRequestMessage)) + { + GNUNET_break (0); + return NULL; + } + op = GNUNET_new (struct GNUNET_ZKLAIM_Operation); + op->h = h; + op->cont = cont; + op->cls = cont_cls; + GNUNET_CONTAINER_DLL_insert_tail (h->op_head, + h->op_tail, + op); + env = GNUNET_MQ_msg_extra (crm, + slen, + GNUNET_MESSAGE_TYPE_ZKLAIM_CREATE); + crm->name_len = htons (slen); + crm->reserved = htons (0); + crm->private_key = *pk; + GNUNET_memcpy (&crm[1], + name, + slen); + GNUNET_MQ_send (h->mq, + env); + //TODO add attrs + return op; +} + + +/** + * Cancel an zklaim operation. Note that the operation MAY still + * be executed; this merely cancels the continuation; if the request + * was already transmitted, the service may still choose to complete + * the operation. + * + * @param op operation to cancel + */ +void +GNUNET_ZKLAIM_cancel (struct GNUNET_ZKLAIM_Operation *op) +{ + op->cont = NULL; +} + + +/** + * Disconnect from zklaim service + * + * @param h handle to destroy + */ +void +GNUNET_ZKLAIM_disconnect (struct GNUNET_ZKLAIM_Handle *h) +{ + struct GNUNET_ZKLAIM_Operation *op; + + GNUNET_assert (NULL != h); + if (h->reconnect_task != NULL) + { + GNUNET_SCHEDULER_cancel (h->reconnect_task); + h->reconnect_task = NULL; + } + while (NULL != (op = h->op_head)) + { + GNUNET_break (NULL == op->cont); + GNUNET_CONTAINER_DLL_remove (h->op_head, + h->op_tail, + op); + GNUNET_free (op); + } + if (NULL != h->mq) + { + GNUNET_MQ_destroy (h->mq); + h->mq = NULL; + } + GNUNET_free (h); +} + +/* end of zklaim_api.c */ diff --git a/src/zklaim/zklaim_api.h b/src/zklaim/zklaim_api.h new file mode 100644 index 000000000..77053c667 --- /dev/null +++ b/src/zklaim/zklaim_api.h @@ -0,0 +1,90 @@ +/* + This file is part of GNUnet. + Copyright (C) 2013 GNUnet e.V. + + GNUnet is free software: you can redistribute it and/or modify it + under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, + or (at your option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + +/** + * @author Martin Schanzenbach + * @file zklaim/zklaim.h + * + * @brief Common type definitions for the zklaim + * service and API. + */ +#ifndef ZKLAIM_API_H +#define ZKLAIM_API_H + +#include "gnunet_common.h" + + +GNUNET_NETWORK_STRUCT_BEGIN + + +/** + * Answer from service to client about last operation; + * GET_DEFAULT maybe answered with this message on failure; + * CREATE and RENAME will always be answered with this message. + */ +struct ResultCodeMessage +{ + /** + * Type: #GNUNET_MESSAGE_TYPE_ZKLAIM_RESULT_CODE + */ + struct GNUNET_MessageHeader header; + + /** + * Status code for the last operation, in NBO. + * (currently not used). + */ + uint32_t result_code GNUNET_PACKED; + + /* followed by 0-terminated error message (on error) */ + +}; + + +/** + * Client requests creation of an identity. Service + * will respond with a result code. + */ +struct CreateRequestMessage +{ + /** + * Type: #GNUNET_MESSAGE_TYPE_ZKLAIM_CREATE + */ + struct GNUNET_MessageHeader header; + + /** + * Number of bytes in identity name string including 0-termination, in NBO. + */ + uint16_t name_len GNUNET_PACKED; + + /** + * Always zero. + */ + uint16_t reserved GNUNET_PACKED; + + /** + * The private key + */ + struct GNUNET_CRYPTO_EcdsaPrivateKey private_key; + + /* followed by 0-terminated identity name */ + +}; + +GNUNET_NETWORK_STRUCT_END + +#endif -- cgit v1.2.3