summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxrs <xrs@mail36.net>2020-06-17 22:07:39 +0200
committerxrs <xrs@mail36.net>2020-06-17 22:07:39 +0200
commit49cf7a8e893eaf7682ac12c7d0ea5ca4a6d1a73d (patch)
tree71830c1751e291e45795958cad15e9dfa8239e1a
parentb9333fef25b57bdd7f556f5fb73f9abaef9bc5ef (diff)
parente500e9ec3678dfbb666d173854c134ac3858f8b1 (diff)
Merge branch 'master' into rewrite_of_cadet_test
-rwxr-xr-x.buildbot/build.sh5
-rwxr-xr-x.buildbot/firefly-x86_64-amdepyc_deploy.sh6
-rwxr-xr-x.buildbot/firefly-x86_64-amdepyc_test.sh3
-rwxr-xr-x.buildbot/install.sh3
-rw-r--r--.buildbot/test.sh3
-rw-r--r--ChangeLog358
-rw-r--r--README9
-rw-r--r--configure.ac67
-rw-r--r--contrib/scripts/changelog_delta.sh3
-rw-r--r--doc/handbook/chapters/developer.texi32
-rw-r--r--doc/handbook/chapters/preface.texi7
-rw-r--r--po/POTFILES.in98
-rw-r--r--src/Makefile.am22
-rw-r--r--src/cadet/Makefile.am5
-rw-r--r--src/cadet/cadet.h87
-rw-r--r--src/cadet/cadet_api.c97
-rw-r--r--src/cadet/cadet_api_drop_message.c59
-rw-r--r--src/cadet/cadet_protocol.h18
-rw-r--r--src/cadet/gnunet-service-cadet.c112
-rw-r--r--src/cadet/gnunet-service-cadet.h1
-rw-r--r--src/cadet/gnunet-service-cadet_channel.c46
-rw-r--r--src/cadet/gnunet-service-cadet_channel.h17
-rw-r--r--src/cadet/gnunet-service-cadet_connection.c52
-rw-r--r--src/cadet/gnunet-service-cadet_connection.h26
-rw-r--r--src/cadet/gnunet-service-cadet_core.c15
-rw-r--r--src/cadet/gnunet-service-cadet_peer.c59
-rw-r--r--src/cadet/gnunet-service-cadet_peer.h21
-rw-r--r--src/cadet/gnunet-service-cadet_tunnels.c43
-rw-r--r--src/cadet/gnunet-service-cadet_tunnels.h21
-rw-r--r--src/cadet/test_cadet.c365
-rw-r--r--src/cadet/test_cadet.conf7
-rw-r--r--src/conversation/test_conversation_api.c4
-rw-r--r--src/conversation/test_conversation_api_reject.c4
-rw-r--r--src/conversation/test_conversation_api_twocalls.c4
-rw-r--r--src/dht/gnunet-service-dht_neighbours.c4
-rw-r--r--src/fs/fs_api.c448
-rw-r--r--src/fs/fs_namespace.c39
-rw-r--r--src/fs/gnunet-auto-share.c32
-rw-r--r--src/fs/gnunet-service-fs_indexing.c11
-rw-r--r--src/gns/Makefile.am12
-rw-r--r--src/gnsrecord/gnunet-gnsrecord-tvg.c116
-rw-r--r--src/hostlist/Makefile.am4
-rw-r--r--src/hostlist/gnunet-daemon-hostlist.c16
-rw-r--r--src/hostlist/gnunet-daemon-hostlist_client.c43
-rw-r--r--src/identity/Makefile.am2
-rw-r--r--src/identity/gnunet-identity.c42
-rw-r--r--src/identity/identity_api.c12
-rw-r--r--src/identity/identity_api_lookup.c1
-rw-r--r--src/identity/plugin_rest_identity.c53
-rw-r--r--src/identity/test_identity.c2
-rw-r--r--src/identity/test_identity_defaults.c2
-rw-r--r--src/include/gnunet_bio_lib.h559
-rw-r--r--src/include/gnunet_buffer_lib.h13
-rw-r--r--src/include/gnunet_crypto_lib.h33
-rw-r--r--src/include/gnunet_identity_service.h2
-rw-r--r--src/include/gnunet_os_lib.h8
-rw-r--r--src/include/gnunet_protocols.h67
-rw-r--r--src/include/gnunet_signatures.h4
-rw-r--r--src/include/gnunet_transport_communication_service.h29
-rw-r--r--src/integration-tests/Makefile.am2
-rw-r--r--src/namestore/Makefile.am8
-rw-r--r--src/nse/gnunet-service-nse.c12
-rw-r--r--src/nse/nse.conf.in2
-rw-r--r--src/nse/perf_kdf.c2
-rw-r--r--src/peerinfo-tool/Makefile.am2
-rw-r--r--src/pt/Makefile.am2
-rw-r--r--src/reclaim/Makefile.am4
-rw-r--r--src/reclaim/json_reclaim.c2
-rw-r--r--src/reclaim/plugin_rest_reclaim.c3
-rw-r--r--src/revocation/gnunet-revocation-tvg.c50
-rw-r--r--src/revocation/revocation.conf.in2
-rw-r--r--src/revocation/revocation_api.c57
-rw-r--r--src/revocation/test_revocation.c2
-rw-r--r--src/statistics/gnunet-service-statistics.c10
-rw-r--r--src/testbed-logger/gnunet-service-testbed-logger.c5
-rw-r--r--src/testbed/gnunet-service-testbed_cpustatus.c6
-rw-r--r--src/transport/Makefile.am26
-rw-r--r--src/transport/gnunet-communicator-tcp.c900
-rw-r--r--src/transport/gnunet-communicator-udp.c391
-rw-r--r--src/transport/gnunet-communicator-unix.c8
-rw-r--r--src/transport/test_communicator_basic.c113
-rw-r--r--src/transport/test_communicator_tcp_basic_peer1.conf7
-rw-r--r--src/transport/test_communicator_tcp_basic_peer2.conf6
-rw-r--r--src/transport/transport-testing2.c188
-rw-r--r--src/transport/transport-testing2.h8
-rw-r--r--src/transport/transport.h60
-rw-r--r--src/transport/transport_api2_communication.c77
-rw-r--r--src/util/Makefile.am1
-rw-r--r--src/util/bio.c1219
-rw-r--r--src/util/buffer.c23
-rw-r--r--src/util/crypto_ecc.c10
-rw-r--r--src/util/crypto_hash.c27
-rw-r--r--src/util/crypto_pow.c26
-rw-r--r--src/util/crypto_rsa.c12
-rw-r--r--src/util/gnunet-scrypt.c4
-rw-r--r--src/util/os_installation.c1
-rw-r--r--src/util/perf_crypto_asymmetric.c18
-rw-r--r--src/util/resolver_api.c2
-rw-r--r--src/util/service.c7
-rw-r--r--src/util/test_bio.c601
-rw-r--r--src/util/test_crypto_ecdsa.c9
-rw-r--r--src/util/test_crypto_hash.c11
102 files changed, 5423 insertions, 1736 deletions
diff --git a/.buildbot/build.sh b/.buildbot/build.sh
new file mode 100755
index 000000000..394558ff0
--- /dev/null
+++ b/.buildbot/build.sh
@@ -0,0 +1,5 @@
+#!/bin/bash
+
+./bootstrap
+./configure --prefix=/tmp/gnunet --enable-experimental
+make
diff --git a/.buildbot/firefly-x86_64-amdepyc_deploy.sh b/.buildbot/firefly-x86_64-amdepyc_deploy.sh
new file mode 100755
index 000000000..b956a3d92
--- /dev/null
+++ b/.buildbot/firefly-x86_64-amdepyc_deploy.sh
@@ -0,0 +1,6 @@
+#!/bin/bash
+
+# Deploy docs from buildbot
+
+chmod -R ag+rX doc/
+rsync -a --delete doc/ handbook@firefly.gnunet.org:~/doc_deployment/
diff --git a/.buildbot/firefly-x86_64-amdepyc_test.sh b/.buildbot/firefly-x86_64-amdepyc_test.sh
new file mode 100755
index 000000000..db202a112
--- /dev/null
+++ b/.buildbot/firefly-x86_64-amdepyc_test.sh
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+echo "Skipped"
diff --git a/.buildbot/install.sh b/.buildbot/install.sh
new file mode 100755
index 000000000..b22f3aae0
--- /dev/null
+++ b/.buildbot/install.sh
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+make install
diff --git a/.buildbot/test.sh b/.buildbot/test.sh
new file mode 100644
index 000000000..a057cba05
--- /dev/null
+++ b/.buildbot/test.sh
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+make check
diff --git a/ChangeLog b/ChangeLog
index 29d5a737b..c6d4153c0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,361 @@
+Tue, 26 May 2020 11:49:50 +0200 (755cb5c76)
+remove argon2 dependency. Use limited libsodium argon2id function for GNS and NSE - Martin Schanzenbach
+
+Tue, 26 May 2020 00:42:24 +0200 (24be68238)
+use argon2id - Martin Schanzenbach
+
+Tue, 26 May 2020 03:05:33 +0530 (2a82be115)
+add additional test condition for GNS crypto - Florian Dold
+
+Mon, 25 May 2020 21:38:58 +0200 (a32de45ce)
+add option to create identity from private key - jospaeth
+
+Fri, 22 May 2020 09:44:22 +0200 (2fbc0f044)
+add option to show private key - Martin Schanzenbach
+
+Fri, 22 May 2020 01:16:35 +0200 (9a92bbb51)
+fix #6242 - Christian Grothoff
+
+Thu, 14 May 2020 16:03:10 +0200 (f4771fcc1)
+Improved BIO API - Christian Grothoff
+
+Sun, 17 May 2020 19:56:12 +0200 (3362a671f)
+make mhd and jansson mandatory dependencies - Martin Schanzenbach
+
+Sun, 17 May 2020 19:37:00 +0200 (ac7ba6704)
+allow compile against curl-openssl - Martin Schanzenbach
+
+Sun, 10 May 2020 11:28:00 +0200 (63c371cfb)
+separate id_token and userinfo claims requests - Martin Schanzenbach
+
+Sun, 10 May 2020 00:23:54 +0200 (44bdb66b4)
+fix #5782 - Martin Schanzenbach
+
+Sat, 9 May 2020 22:10:08 +0200 (ada94c274)
+fail of LSD0001 is violated for GNS2DNS - Martin Schanzenbach
+
+Sat, 9 May 2020 22:00:01 +0200 (3da4b0d20)
+fix #6103; make LEHOs supplemental from CNAMEs and GNS2DNS names - Martin Schanzenbach
+
+Sat, 9 May 2020 20:55:08 +0200 (63c92bbef)
+add json response headers to rest plugins - Martin Schanzenbach
+
+Sat, 9 May 2020 19:12:51 +0200 (fbdc2fbb4)
+change label processing in namestore REST api for gns records - Martin Schanzenbach
+
+Wed, 6 May 2020 18:42:45 +0200 (1847e1652)
+deprecate ill-defined set_nick API - Martin Schanzenbach
+
+Wed, 6 May 2020 21:11:08 +0530 (616af9e62)
+add libsodium dep to README - Florian Dold
+
+Wed, 6 May 2020 20:12:05 +0530 (e273b24b9)
+Fix #6070 - Florian Dold
+
+Wed, 6 May 2020 18:39:16 +0530 (d7028a584)
+move from tweetnacl (+custom hacks) -> only sodium - Florian Dold
+
+Wed, 6 May 2020 10:49:10 +0200 (e7c277845)
+remove obsolete framework option - Martin Schanzenbach
+
+Wed, 6 May 2020 10:46:20 +0200 (4d75bfd7e)
+add some more useful configuration output wrt transports - Martin Schanzenbach
+
+Wed, 6 May 2020 10:25:00 +0200 (a4fddaa4d)
+stop excessive warnings and notifications of information that is displayed later on anyway - Martin Schanzenbach
+
+Wed, 6 May 2020 09:31:11 +0200 (ca168098b)
+improve configure messages for rest and reclaim - Martin Schanzenbach
+
+Sat, 2 May 2020 00:08:38 +0200 (f38bc1041)
+fix gnunet-identity performance - Christian Grothoff
+
+Fri, 1 May 2020 10:55:51 +0200 (91e407579)
+vpn, exit: Add patch from termux for Android in a slightly different way. - nikita
+
+Fri, 24 Apr 2020 13:50:05 +0530 (892bd3c60)
+check for integer overflow in buffer lib (fixes #6217) - Florian Dold
+
+Fri, 24 Apr 2020 10:18:16 +0200 (69f8fad56)
+fix #6220 - Martin Schanzenbach
+
+Tue, 21 Apr 2020 20:43:18 +0200 (bf99d2243)
+fix #6191 - Christian Grothoff
+
+Tue, 21 Apr 2020 18:37:28 +0200 (091f411cc)
+purge scrypt; add argon2 - Martin Schanzenbach
+
+Tue, 21 Apr 2020 18:13:05 +0200 (6bda628f7)
+update revocation config - Martin Schanzenbach
+
+Tue, 21 Apr 2020 13:47:04 +0200 (13ceb583b)
+defining GNUNET_array_concatenate() for #6190 - Christian Grothoff
+
+Tue, 21 Apr 2020 13:33:25 +0200 (3776e3a77)
+fix #6189 - Christian Grothoff
+
+Tue, 21 Apr 2020 13:27:04 +0200 (e938b8617)
+fix #6186 related bugs - Christian Grothoff
+
+Tue, 21 Apr 2020 13:23:28 +0200 (68615f85c)
+use nz - Christian Grothoff
+
+Tue, 21 Apr 2020 12:15:16 +0200 (5f5a1c7b4)
+add JSON spec'er for booleans - Christian Grothoff
+
+Tue, 21 Apr 2020 00:54:49 +0200 (30361fe0e)
+make GNUNET_freez default, have GNUNET_free_nz for cases where that does not work - Christian Grothoff
+
+Sun, 19 Apr 2020 21:37:35 +0200 (254a9f066)
+add i64 deserializer - Christian Grothoff
+
+Sun, 19 Apr 2020 14:07:21 +0200 (87481d240)
+mailmap, authors: final sync of my address and name with changes in NetBSD and GNUnet members. - nikita
+
+Fri, 17 Apr 2020 19:58:40 +0200 (2be21d379)
+add argon2 for LSD0001 - Martin Schanzenbach
+
+Fri, 17 Apr 2020 19:59:31 +0200 (0c053ecbf)
+fix build with clang - Martin Schanzenbach
+
+Fri, 17 Apr 2020 19:13:42 +0200 (3695a510a)
+add relative_time specs - Christian Grothoff
+
+Fri, 17 Apr 2020 18:21:17 +0200 (6b89b84d2)
+add GNUNET_freez for #6186 - Christian Grothoff
+
+Wed, 15 Apr 2020 20:35:45 +0200 (c894cf82d)
+add integer overflow guards and avoid (unlimited) stack allocation - Christian Grothoff
+
+Wed, 15 Apr 2020 20:29:15 +0200 (839badf7c)
+take care of odd memset() calls - Christian Grothoff
+
+Wed, 15 Apr 2020 20:26:00 +0200 (b7be5b9f5)
+fix #6184 - Christian Grothoff
+
+Sat, 11 Apr 2020 23:11:43 +0200 (7bcd5338f)
+fix gnunet-statistics CLI - Christian Grothoff
+
+Sat, 11 Apr 2020 21:55:51 +0200 (f490c0f3f)
+do create directory if it doesn't exist - Christian Grothoff
+
+Sat, 11 Apr 2020 21:43:28 +0200 (90ff9edfa)
+fixing #6149 - Christian Grothoff
+
+Sat, 11 Apr 2020 20:33:08 +0200 (3bcfe59f1)
+fix static assert FTBFS with older gcc - Christian Grothoff
+
+Thu, 9 Apr 2020 01:46:44 +0200 (f3d66d0dc)
+mailmap adjust - nikita
+
+Thu, 9 Apr 2020 01:40:49 +0200 (22119c687)
+fix interpreter line of gnunet-bugreport - nikita
+
+Thu, 9 Apr 2020 00:29:16 +0200 (8547143da)
+adapt code to work with latest MHD API - Christian Grothoff
+
+Thu, 9 Apr 2020 00:21:45 +0200 (6fc0526b4)
+fix warnings - Christian Grothoff
+
+Wed, 8 Apr 2020 20:30:05 +0200 (ccfb2c2e6)
+introduce enum for generic return values - Christian Grothoff
+
+Wed, 8 Apr 2020 17:34:27 +0200 (ba4da8c3f)
+hack around crash on disconnect - Christian Grothoff
+
+Wed, 8 Apr 2020 16:56:33 +0200 (11ae9f030)
+fix sign api for to address #6164 - Christian Grothoff
+
+Wed, 8 Apr 2020 14:47:01 +0200 (17113fc2f)
+add GNUNET_static_assert() - Christian Grothoff
+
+Wed, 8 Apr 2020 14:44:39 +0200 (8c9600879)
+add check to see if CC supports '_Static_assert' - Christian Grothoff
+
+Tue, 7 Apr 2020 17:51:59 +0200 (29bd17729)
+improve comments (#6164) - Christian Grothoff
+
+Fri, 3 Apr 2020 18:50:09 +0200 (6d7fd3328)
+fix #6157 - Christian Grothoff
+
+Fri, 3 Apr 2020 18:45:46 +0200 (6fd24eef2)
+fix #6155 - Christian Grothoff
+
+Fri, 3 Apr 2020 18:43:03 +0200 (bc01117ce)
+fix #6158 - Christian Grothoff
+
+Fri, 3 Apr 2020 17:03:35 +0200 (55bff52a2)
+fix #6159 and related issues - Christian Grothoff
+
+Fri, 3 Apr 2020 15:18:58 +0200 (0541fd194)
+adding a GNUNET_memcmp_priv for constant-time comparing of data; fixes #6152 (modulo actually finding specific places where this SHOULD be used instead of GNUNET_memcmp) - Christian Grothoff
+
+Fri, 3 Apr 2020 15:05:14 +0200 (4e259dbbb)
+fix #6153 - Christian Grothoff
+
+Fri, 3 Apr 2020 14:18:58 +0200 (175303b44)
+fix #6154 - Christian Grothoff
+
+Fri, 3 Apr 2020 13:46:05 +0200 (a3d4063b7)
+added communicator tests to experimental - t3sserakt
+
+Thu, 2 Apr 2020 11:33:53 +0200 (225ddf0a2)
+fix #6146 - Christian Grothoff
+
+Sun, 29 Mar 2020 12:51:26 +0200 (73514dd0e)
+allow passing of fancy time to timetravel option - Christian Grothoff
+
+Sat, 28 Mar 2020 07:57:04 +0100 (15d926361)
+Point to explanatory documentation. - Marcello Stanisci
+
+Fri, 20 Mar 2020 15:35:54 +0100 (19d73a8fa)
+Make gnunet-namestore honour expiration dates when importing an URI - Christian Grothoff
+
+Thu, 19 Mar 2020 19:40:34 +0100 (efa84b551)
+use strtok_r in code that could plausibly be used from multi-threaded applications - Christian Grothoff
+
+Tue, 17 Mar 2020 01:05:17 +0100 (2fb32626a)
+use void * instead of char * for RSA key material to make it more clear that these are not 0-terminated strings - Christian Grothoff
+
+Mon, 16 Mar 2020 19:38:42 +0100 (39c6d488d)
+better error handling - Christian Grothoff
+
+Sun, 15 Mar 2020 22:06:28 +0100 (7de26292b)
+add function that logically belongs to libgnunetcurl instead of in multiple Taler binaries - Christian Grothoff
+
+Sun, 15 Mar 2020 15:18:53 +0100 (b37cfa2fd)
+implement new simplified POW for LSD001 - Martin Schanzenbach
+
+Thu, 12 Mar 2020 12:09:11 +0100 (0c8362ad8)
+move literature information to end of paragraph - xrs
+
+Tue, 10 Mar 2020 17:42:04 +0100 (9d5af0464)
+import CA into Icecat - Christian Grothoff
+
+Tue, 3 Mar 2020 12:31:23 +0100 (d1bdcb261)
+make static analysis happier - Christian Grothoff
+
+Tue, 3 Mar 2020 12:31:12 +0100 (9a6588810)
+remove 'illegal' (non-reentrant) log logic from signal handler - Christian Grothoff
+
+Mon, 24 Feb 2020 23:48:47 +0100 (01439e25d)
+do not segv if there is no postgres - Christian Grothoff
+
+Mon, 24 Feb 2020 18:19:09 +0100 (dae7d843f)
+support versioning schema drop - Christian Grothoff
+
+Wed, 19 Feb 2020 21:52:43 +0100 (ca8202057)
+fixing the GNS multirecord multipeer test - Christian Grothoff
+
+Tue, 18 Feb 2020 16:08:43 +0100 (3b2afcd3b)
+fix TNG test with NAT - Martin Schanzenbach
+
+Sat, 15 Feb 2020 12:55:24 +0100 (b03978816)
+proposed fix for excessive queueing (somehow does not quite work, not sure why) - Christian Grothoff
+
+Sat, 15 Feb 2020 12:25:06 +0100 (e57177325)
+better task ordering - Christian Grothoff
+
+Thu, 13 Feb 2020 19:36:37 +0100 (79243b3d2)
+add concept of supplemental records - Martin Schanzenbach
+
+Thu, 13 Feb 2020 15:15:18 +0100 (4dc95a504)
+always return nick records - Martin Schanzenbach
+
+Wed, 12 Feb 2020 23:09:03 +0100 (206866779)
+resolve nick if specifically requested - Martin Schanzenbach
+
+Wed, 12 Feb 2020 22:06:19 +0100 (e021a0f7b)
+fix duplicate NICK in record - Martin Schanzenbach
+
+Fri, 7 Feb 2020 15:51:56 +0100 (5f9f9cae1)
+consolidate reclaim attribute lib - Martin Schanzenbach
+
+Thu, 6 Feb 2020 22:34:11 +0100 (d06446f14)
+add base64url encoding to util (RFC7515) - Martin Schanzenbach
+
+Thu, 6 Feb 2020 20:08:58 +0100 (a80090ffc)
+more bugfixes and REST API change - Martin Schanzenbach
+
+Tue, 4 Feb 2020 18:42:04 +0100 (55f6d26b7)
+Refactoring reclaim attestations - Martin Schanzenbach
+
+Mon, 3 Feb 2020 21:51:57 +0100 (5b6bb2ce4)
+move to 256-bit identifier; some cleanups - Martin Schanzenbach
+
+Sun, 9 Feb 2020 17:31:41 +0100 (99d70615e)
+use versioning schema to only load database schema patches if not yet covered according to versioning table - Christian Grothoff
+
+Sun, 9 Feb 2020 15:57:39 +0100 (8f375b3ea)
+use NULL value in load_path_suffix to NOT load any files - Christian Grothoff
+
+Tue, 4 Feb 2020 19:18:25 +0100 (1ca805654)
+speed up message goodput in perf_mq(client) by 1/3rd - Christian Grothoff
+
+Tue, 4 Feb 2020 19:11:40 +0100 (c656a8218)
+adding MQ benchmark - Christian Grothoff
+
+Tue, 4 Feb 2020 18:56:17 +0100 (f40520b09)
+speed up running of tasks via GNUNTE_SCHEDULER_add_now() by a factor of at least 5 - Christian Grothoff
+
+Tue, 4 Feb 2020 18:45:19 +0100 (4caa0d290)
+add minimal scheduler benchmark - Christian Grothoff
+
+Tue, 4 Feb 2020 15:47:01 +0100 (e14544109)
+add timetravel getopt helper - Christian Grothoff
+
+Mon, 3 Feb 2020 23:51:09 +0100 (e3dcec36a)
+fix bug *AGAIN*, could swear I fixed this one before... strange - Christian Grothoff
+
+Mon, 3 Feb 2020 18:26:49 +0100 (1bba6bc12)
+added a test for DHT lookup between peers - rexxnor
+
+Thu, 30 Jan 2020 10:48:04 +0100 (015cd279b)
+added testing scripts for dns2gns - rexxnor
+
+Fri, 24 Jan 2020 16:51:29 +0100 (f4a172abf)
+export GNUNET_PQ_run_sql() functonality - Christian Grothoff
+
+Fri, 24 Jan 2020 16:30:45 +0100 (2fd320bc7)
+modify GNUNET_PQ_connect_with_cfg to enable flexible loading of .sql files - Christian Grothoff
+
+Sat, 18 Jan 2020 18:47:30 +0100 (bbfde2060)
+include mandatory includes - Christian Grothoff
+
+Fri, 17 Jan 2020 12:12:56 +0100 (5422848b4)
+do not add '/' to load path - Christian Grothoff
+
+Fri, 17 Jan 2020 03:22:31 +0100 (00bd3376b)
+quiet on psql - Christian Grothoff
+
+Fri, 17 Jan 2020 02:51:10 +0100 (8fa757a94)
+auto-provide OS_IPK paths in [paths] of config - Christian Grothoff
+
+Fri, 17 Jan 2020 02:35:29 +0100 (3c1f2bdd8)
+be more quiet - Christian Grothoff
+
+Fri, 17 Jan 2020 02:26:21 +0100 (4353432b9)
+DB load API change - Christian Grothoff
+
+Fri, 17 Jan 2020 00:25:55 +0100 (1126181ab)
+include buffer in main util header - Christian Grothoff
+
+Thu, 16 Jan 2020 17:11:58 +0100 (ec7870968)
+add new versions of alpine packages (not yet in alpine repo) - xrs
+
+Wed, 15 Jan 2020 19:41:05 +0100 (5177efb74)
+remove Taler-specific leftovers, we don't need them anymore - Florian Dold
+
+Wed, 15 Jan 2020 13:29:47 +0100 (9f36b6e9e)
+add test vector generation for crypto ops - Florian Dold
+
+Wed, 15 Jan 2020 11:45:20 +0100 (9f3f1753e)
+move buffer library from GNU Taler to GNUnet - Florian Dold
+
+Mon, 13 Jan 2020 18:58:13 -0600 (55d610bb3)
+Fix copy/paste error checking for explicit_bzero - David Barksdale
+
+
Fri Dec 20 09:22:03 2019 +0900
Released gnunet 0.12.0 -schanzen
diff --git a/README b/README
index 87d4d635e..d95022de2 100644
--- a/README
+++ b/README
@@ -63,7 +63,7 @@ These are the direct dependencies for running GNUnet:
- gettext
- gnutls >= 3.2.12 (highly recommended a gnutls
linked against libunbound)
-- A curl build against gnutls, or gnurl:
+- curl (ideally built against gnutls) or gnurl:
* libgnurl >= 7.35.0 (recommended, available from
https://gnunet.org/en/gnurl.html)
or
@@ -74,8 +74,8 @@ These are the direct dependencies for running GNUnet:
* libidn2 (prefered)
or
* libidn >= 1.0
-- libmicrohttpd >= 0.9.63 (strongly recommended for
- a wide range of features)
+- libmicrohttpd >= 0.9.63
+- libjansson
- makeinfo >= 4.8
- make[*3]
- nss (certutil binary, for
@@ -96,8 +96,6 @@ These are the direct dependencies for running GNUnet:
- which (contrib/apparmor(?), gnunet-bugreport,
and possibly more)
- zlib
-- argon2 >= 20190702 (for proof-of-work calculations in
- revocation)
- libsodium >= 1.0.11 (for elliptic curve cryptography)
These are the dependencies for GNUnet's testsuite:
@@ -124,7 +122,6 @@ These are the optional dependencies:
- bluez (for bluetooth support)
- grof (for linting of man pages)
- libextractor >= 0.6.1 (highly recommended[*5])
-- libjansson
- libopus >= 1.0.1 (for conversation tool)
- libpulse >= 2.0 (for conversation tool)
- libogg >= 1.3.0 (for conversation tool)
diff --git a/configure.ac b/configure.ac
index 94c0a7689..6dc914c12 100644
--- a/configure.ac
+++ b/configure.ac
@@ -786,12 +786,9 @@ AC_ARG_WITH(jansson,
],
[AC_MSG_RESULT([--with-jansson not specified])
CHECK_LIBHEADER(JANSSON, jansson, json_loads, jansson.h,jansson=1,)])
-AM_CONDITIONAL(HAVE_JANSSON, [test "$jansson" = 1])
-AM_CONDITIONAL(HAVE_JSON, [test x$jansson = x1])
-AS_IF([test "x$jansson" = x1],
- [AC_DEFINE([HAVE_JANSSON],[1],[Have jansson library])],
- [AC_DEFINE([HAVE_JANSSON],[0],[Lacking jansson library])])
+AS_IF([test "x$jansson" != x1],
+ [AC_MSG_ERROR([GNUnet requires libjansson])])
# check for libpulse(audio) library
pulse=0
@@ -984,8 +981,8 @@ AS_IF([test "x$curl" = xtrue],[
AC_CHECK_HEADER([curl/curl.h],
AC_CHECK_DECLS(CURLINFO_TLS_SESSION,[curl=true],[curl=false],[[#include <curl/curl.h>]]),
[curl=false])
- # need libcurl-gnutls.so, everything else is not acceptable
- AC_CHECK_LIB([curl-gnutls],[curl_easy_getinfo],,[curl=false])
+ # need libcurl-gnutls.so for proxy, warn later if not found.
+ AC_CHECK_LIB([curl-gnutls],[curl_easy_getinfo],[curl_gnutls=true],[curl_gnutls=false])
# cURL must support CURLINFO_TLS_SESSION, version >= 7.34
])
@@ -1000,7 +997,7 @@ AS_IF([test "$gnurl" = 1],
AC_DEFINE([HAVE_LIBGNURL],[0],[Lacking libgnurl])
AM_CONDITIONAL(HAVE_LIBCURL, true)
AC_DEFINE([HAVE_LIBCURL],[1],[Have libcurl])],
- [AC_MSG_WARN([ERROR: GNUnet requires libcurl-gnutls or gnurl >= 7.34])
+ [AC_MSG_ERROR([GNUnet requires libcurl or gnurl >= 7.34])
AM_CONDITIONAL(HAVE_LIBGNURL, false)
AC_DEFINE([HAVE_LIBGNURL],[0],[Lacking libgnurl])
AM_CONDITIONAL(HAVE_LIBCURL, false)
@@ -1036,20 +1033,10 @@ AS_IF([test x$nss = xfalse],
AC_CHECK_LIB([kvm],[kvm_open])
AC_CHECK_LIB([kstat],[kstat_open])
-argon=0
-# test for argon2 (for POW)
-AC_CHECK_LIB([argon2],[argon2d_hash_raw], argon=1, argon=0)
-AS_IF([test x$argon = x1],
-[
- AC_MSG_RESULT([argon2 found])
-],[
- AC_MSG_ERROR([GNUnet requires argon2.])
-])
-
libsodium=0
# test for libsodium
AC_CHECK_HEADER([sodium.h],
- [AC_CHECK_LIB([sodium], [sodium_init],
+ [AC_CHECK_LIB([sodium], [crypto_pwhash_argon2id],
[libsodium=1])])
AS_IF([test x$libsodium = x0],
@@ -1472,6 +1459,9 @@ AC_DEFINE_UNQUOTED([HAVE_MHD], $lmhd, [We have libmicrohttpd])
AM_CONDITIONAL(HAVE_JSON, [test x$jansson = x1])
AM_CONDITIONAL(HAVE_REST, [test x$jansson = x1 -a x$lmhd = x1])
+AS_IF([test "x$lmhd" != "x1"],
+ [AC_MSG_ERROR([GNUnet requires libmicrohttpd >= 0.9.63.])])
+
# restore LIBS
LIBS=$SAVE_LIBS
@@ -2001,7 +1991,7 @@ AS_IF([test "x$enable_java_ports" = "xyes"],
#### This could be moved to the checks above,
#### but for now let's keep it here.
####
-transport_msg="tcp udp unix"
+transport_msg="tcp udp unix http"
AS_IF([test "x$build_target" = "xlinux" -a "x$enable_experimental" = "xyes"],
[transport_msg="$transport_msg wlan"])
# -- print message regarding enabled experimental features
@@ -2047,26 +2037,10 @@ AS_IF([test "x$conversation_backend" = "xnone"],
[AS_IF([test "x$opus" = x1],
[conversation_msg="yes (x$conversation_backend)"],
[AC_MSG_WARN([libopus not found (required to build conversation)])])])
-# -- rest / oidc
-rest_msg="no"
-AS_IF([test "x$lmhd" = "x1" -a "x$jansson" = "x1"],
- [rest_msg="yes"
- reclaim_msg="yes (with OpenID Connect)"],
- [rest_msg="no"
- reclaim_msg="yes (without OpenID Connect)"])
-
# -- interface
interface_msg=`echo $DEFAULT_INTERFACE | tr -d \"`
-# -- libmicrohttpd
-AS_IF([test "x$lmhd" = "x0"],
- [libmicrohttpd_msg="no (REST service and HTTP transport will not be built)"],
- [libmicrohttpd_msg="yes"
- transport_msg="$transport_msg http_server"])
# -- jansson
-AS_IF([test "x$jansson" = "x0"],
- [jansson_msg="no (REST service will not be built)"],
- [jansson_msg="yes"])
# -- libextractor
AS_IF([test "$extractor" != 1],
[AC_MSG_WARN([libextractor not found, but various file-sharing functions require it])],
@@ -2080,11 +2054,15 @@ AS_IF([test "$gnurl" = "0"],
[AS_IF([test "x$curl" = "xfalse"],
[AC_MSG_WARN([libgnurl not found. http client support will not be compiled.])
AC_MSG_WARN([IMPORTANT: No HTTP client library found. HTTP transports and hostlist daemon will not be compiled, and you probably WANT the hostlist daemon])
- curl_msg="no"],
- [AC_MSG_NOTICE([libgnurl not found, trying to use libcurl-gnutls instead.])
- curl_msg="yes"])],
- [gnurl_msg="yes"
- transport_msg="$transport_msg http_client"])
+ http_client="none"],
+ [AC_MSG_NOTICE([Using libcurl as HTTP client library.])
+ http_client="curl"])],
+ [AC_MSG_NOTICE([Using libgnurl as HTTP client library.])
+ http_client="gnurl"])
+AS_IF([test "x$curl" = "xtrue" -a "x$curl_gnutls" != "xtrue"],
+ [AC_MSG_WARN([libcurl TLS backend is not gnutls. The GNS Proxy will likely not function properly.])
+ http_client="curl-openssl"],
+ [http_client="curl-gnutls"])
# -- ifconfig
AS_IF([test "$VAR_IFCONFIG_BINARY" = "false"],
[ifconfig_msg="no (optional, some features will not work)"],
@@ -2160,17 +2138,14 @@ Default Interface: ${interface_msg}
MySQL: ${mysql_msg}
PostgreSQL: ${postgres_msg}
sqlite3: ${sqlite_msg}
-gnurl: ${gnurl_msg}
-curl: ${curl_msg}
+http client: ${http_client}
bluetooth: ${bluetooth_msg}
-jansson: ${jansson_msg}
iptables: ${iptables_msg}
ifconfig: ${ifconfig_msg}
upnpc: ${upnpc_msg}
gnutls: ${gnutls_msg}
libzbar: ${libzbar_msg}
java: ${java_msg}
-libmicrohttpd: ${libmicrohttpd_msg}
libidn: ${libidn1_msg}${libidn2_msg}
libopus: ${libopus_msg}
gstreamer: ${gstreamer_msg}
@@ -2182,9 +2157,7 @@ mandoc: ${mandoc_msg}
GNUnet configuration:
=====================
transports: ${transport_msg}
-reclaimID: ${reclaim_msg}
conversation: ${conversation_msg}
-rest: ${rest_msg}
database backends: ${features_msg}
experimental: ${experimental_msg}
diff --git a/contrib/scripts/changelog_delta.sh b/contrib/scripts/changelog_delta.sh
new file mode 100644
index 000000000..1c14d69e2
--- /dev/null
+++ b/contrib/scripts/changelog_delta.sh
@@ -0,0 +1,3 @@
+#!/bin/bash
+LASTHASH=$(head -n1 ChangeLog | cut -d " " -f 7 | tr -d \( | tr -d \))
+git log --invert-grep --grep="^- " --no-merges --no-color --format="%aD (%h)%n%s - %cN%n" $LASTHASH..HEAD
diff --git a/doc/handbook/chapters/developer.texi b/doc/handbook/chapters/developer.texi
index de5166226..ca76a5f2b 100644
--- a/doc/handbook/chapters/developer.texi
+++ b/doc/handbook/chapters/developer.texi
@@ -848,8 +848,9 @@ libgnunet_plugin_transport_tcp)
@c XXX: Adjust examples to GNU Standards!
@itemize @bullet
@item We follow the GNU Coding Standards (@pxref{Top, The GNU Coding Standards,, standards, The GNU Coding Standards});
-@item Indentation is done with spaces, two per level, no tabs;
-@item C99 struct initialization is fine;
+@item Indentation is done with spaces, two per level, no tabs; specific (incomplete!) indentation rules are provided in an @code{uncrustify} configuration file (in ``contrib/``) and enforced by Git hooks;
+@item C99 struct initialization is fine and generally encouraged (but not required);
+@item As in all good C code, we care about symbol space pollution and thus use @code{static} to limit the scope where possible, even in the compilation unit that contains @code{main};
@item declare only one variable per line, for example:
@noindent
@@ -1063,6 +1064,32 @@ separated by an empty line (possibly followed by a comment describing the
following step). The code should not contain empty lines in arbitrary
places; if in doubt, it is likely better to NOT have an empty line (this
way, more code will fit on the screen).
+
+
+@item When command-line arguments become too long (and would result in
+some particularly ugly @code{uncrustify} wrapping), we start all arguments
+on a new line. As a result, there must never be a new line within an
+argument declaration (i.e. between @code{struct} and the struct's name) or
+between the type and the variable). Example:
+
+@example
+struct GNUNET_TRANSPORT_CommunicatorHandle *
+GNUNET_TRANSPORT_communicator_connect (
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ const char *config_section_name,
+ const char *addr_prefix,
+ ...);
+@end example
+
+Note that for short function names and arguments, the first argument
+does remain on the same line. Example:
+
+@example
+void
+fun (short i,
+ short j);
+@end example
+
@end itemize
@c ***********************************************************************
@@ -8941,4 +8968,3 @@ view are sampled through the sampler from the random stream of peer IDs.
According to the theoretical analysis of Bortnikov et al. this suffices
to keep the network connected and having random peers in the view.
-
diff --git a/doc/handbook/chapters/preface.texi b/doc/handbook/chapters/preface.texi
index 800b7c7cd..443fb2600 100644
--- a/doc/handbook/chapters/preface.texi
+++ b/doc/handbook/chapters/preface.texi
@@ -181,14 +181,11 @@ GNUnet maintainer can overrule any decisions made by individual
developers. Still, in practice neither has happened in the last 20
years for GNUnet, and we hope to keep it that way.
-@c TODO: Actually we are a Swiss association, or just a German association
-@c TODO: with Swiss bylaws/Satzung?
-@c TODO: Rewrite one of the 'GNUnet eV may also' sentences?
The GNUnet project is supported by GNUnet e.V., a German association
where any developer can become a member. GNUnet e.V. serves as a
legal entity to hold the copyrights to GNUnet. GNUnet e.V. may also
-choose to pay for project resources, and can collect donations.
-GNUnet e.V. may also choose to adjust the license of the
+choose to pay for project resources, and can collect donations as
+well as choose to adjust the license of the
software (with the constraint that it has to remain free software).
In 2018 we switched from GPL3 to AGPL3, in practice these changes do
not happen very often.
diff --git a/po/POTFILES.in b/po/POTFILES.in
index f38c81f49..533b2dda9 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -10,13 +10,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
@@ -25,14 +33,6 @@ src/ats/gnunet-service-ats_preferences.c
src/ats/gnunet-service-ats_reservations.c
src/ats/gnunet-service-ats_scheduling.c
src/ats/plugin_ats_proportional.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
@@ -49,8 +49,8 @@ src/cadet/cadet_api_list_peers.c
src/cadet/cadet_api_list_tunnels.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
@@ -66,15 +66,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
@@ -104,7 +104,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
@@ -113,6 +112,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
@@ -147,8 +147,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
@@ -168,9 +168,9 @@ 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-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
@@ -183,11 +183,12 @@ src/gnsrecord/gnsrecord.c
src/gnsrecord/gnsrecord_crypto.c
src/gnsrecord/gnsrecord_misc.c
src/gnsrecord/gnsrecord_serialization.c
+src/gnsrecord/gnunet-gnsrecord-tvg.c
src/gnsrecord/plugin_gnsrecord_dns.c
src/hello/address.c
src/hello/gnunet-hello.c
-src/hello/hello.c
src/hello/hello-ng.c
+src/hello/hello.c
src/hostlist/gnunet-daemon-hostlist.c
src/hostlist/gnunet-daemon-hostlist_client.c
src/hostlist/gnunet-daemon-hostlist_server.c
@@ -212,8 +213,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
@@ -239,17 +240,17 @@ 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/nt/nt.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/peerinfo-tool/plugin_rest_peerinfo.c
+src/peerinfo/gnunet-service-peerinfo.c
+src/peerinfo/peerinfo_api.c
+src/peerinfo/peerinfo_api_notify.c
src/peerstore/gnunet-peerstore.c
src/peerstore/gnunet-service-peerstore.c
src/peerstore/peerstore_api.c
@@ -295,26 +296,27 @@ src/rest/gnunet-rest-server.c
src/rest/plugin_rest_config.c
src/rest/plugin_rest_copying.c
src/rest/rest.c
+src/revocation/gnunet-revocation-tvg.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-sampler_client.c
src/rps/rps-sampler_common.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
@@ -340,15 +342,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
@@ -356,20 +359,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
@@ -381,34 +383,40 @@ src/transport/gnunet-communicator-tcp.c
src/transport/gnunet-communicator-udp.c
src/transport/gnunet-communicator-unix.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-helper-transport-wlan.c
src/transport/gnunet-service-tng.c
-src/transport/gnunet-service-transport_ats.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-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/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-testing2.c
src/transport/transport_api2_application.c
src/transport/transport_api2_communication.c
src/transport/transport_api2_core.c
@@ -421,12 +429,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-testing2.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/benchmark.c
src/util/bio.c
@@ -441,8 +443,8 @@ src/util/consttime_memcmp.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/container_multiuuidmap.c
@@ -466,8 +468,8 @@ 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-crypto-tvg.c
src/util/gnunet-ecc.c
src/util/gnunet-qr.c
@@ -504,8 +506,8 @@ src/vpn/gnunet-helper-vpn.c
src/vpn/gnunet-service-vpn.c
src/vpn/gnunet-vpn.c
src/vpn/vpn_api.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/testbed/testbed_api.h
src/testbed/testbed_api_operations.h
diff --git a/src/Makefile.am b/src/Makefile.am
index 4642b6215..446b1aa2a 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -17,26 +17,12 @@ if HAVE_ABE
EXP_DIR += \
abe
endif
-if HAVE_JSON
EXP_DIR += \
auction
endif
-endif
-if HAVE_JSON
-if HAVE_MHD
- JSON_DIR = json
-endif
-endif
-if HAVE_MHD
-if HAVE_LIBGNURL
- CURL_DIR = curl
-else
-if HAVE_LIBCURL
- CURL_DIR = curl
-endif
-endif
-endif
+JSON_DIR = json
+CURL_DIR = curl
if BUILD_PULSE_HELPERS
CONVERSATION_DIR = conversation
@@ -58,9 +44,7 @@ if HAVE_POSTGRESQL
POSTGRES_DIR = pq
endif
-if HAVE_REST
- REST_DIR = rest
-endif
+REST_DIR = rest
SUBDIRS = \
diff --git a/src/cadet/Makefile.am b/src/cadet/Makefile.am
index 80294a785..80a2d113d 100644
--- a/src/cadet/Makefile.am
+++ b/src/cadet/Makefile.am
@@ -30,6 +30,7 @@ lib_LTLIBRARIES = \
libgnunetcadet_la_SOURCES = \
cadet_api.c \
+ cadet_api_drop_message.c \
cadet_api_get_channel.c \
cadet_api_get_path.c \
cadet_api_list_peers.c \
@@ -96,6 +97,7 @@ check_PROGRAMS = \
test_cadet_2_speed_reliable \
test_cadet_2_speed_reliable_backwards \
test_cadet_2_reopen \
+ test_cadet_2_destroy \
test_cadet_5_forward \
test_cadet_5_signal \
test_cadet_5_keepalive \
@@ -217,6 +219,9 @@ test_cadet_5_reopen_SOURCES = \
test_cadet.c
test_cadet_5_reopen_LDADD = $(ld_cadet_test_lib)
+test_cadet_2_destroy_SOURCES = \
+ test_cadet.c
+test_cadet_2_destroy_LDADD = $(ld_cadet_test_lib)
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/cadet/cadet.h b/src/cadet/cadet.h
index 29400e39f..d17eab1d6 100644
--- a/src/cadet/cadet.h
+++ b/src/cadet/cadet.h
@@ -95,7 +95,6 @@ extern "C" {
GNUNET_NETWORK_STRUCT_BEGIN
-
/**
* Number uniquely identifying a channel of a client.
*/
@@ -111,6 +110,70 @@ struct GNUNET_CADET_ClientChannelNumber
uint32_t channel_of_client GNUNET_PACKED;
};
+/**
+ * Opaque handle to a channel.
+ */
+struct GNUNET_CADET_Channel
+{
+
+ /**
+ * Other end of the channel.
+ */
+ struct GNUNET_PeerIdentity peer;
+
+ /**
+ * Handle to the cadet this channel belongs to
+ */
+ struct GNUNET_CADET_Handle *cadet;
+
+ /**
+ * Channel's port, if incoming.
+ */
+ struct GNUNET_CADET_Port *incoming_port;
+
+ /**
+ * Any data the caller wants to put in here, used for the
+ * various callbacks (@e disconnects, @e window_changes, handlers).
+ */
+ void *ctx;
+
+ /**
+ * Message Queue for the channel (which we are implementing).
+ */
+ struct GNUNET_MQ_Handle *mq;
+
+ /**
+ * Task to allow mq to send more traffic.
+ */
+ struct GNUNET_SCHEDULER_Task *mq_cont;
+
+ /**
+ * Pending envelope with a message to be transmitted to the
+ * service as soon as we are allowed to. Should only be
+ * non-NULL if @e allow_send is 0.
+ */
+ struct GNUNET_MQ_Envelope *pending_env;
+
+ /**
+ * Window change handler.
+ */
+ GNUNET_CADET_WindowSizeEventHandler window_changes;
+
+ /**
+ * Disconnect handler.
+ */
+ GNUNET_CADET_DisconnectEventHandler disconnects;
+
+ /**
+ * Local ID of the channel, #GNUNET_CADET_LOCAL_CHANNEL_ID_CLI bit is set if outbound.
+ */
+ struct GNUNET_CADET_ClientChannelNumber ccn;
+
+ /**
+ * How many messages are we allowed to send to the service right now?
+ */
+ unsigned int allow_send;
+};
/**
* Message for a client to create and destroy channels.
@@ -252,7 +315,29 @@ struct GNUNET_CADET_LocalInfo
struct GNUNET_PeerIdentity peer;
};
+/**
+ * Message to drop another message of specific type. Used in test context
+ */
+struct GNUNET_CADET_RequestDropCadetMessage
+{
+ /**
+ * Type: #GNUNET_MESSAGE_TYPE_CADET_DROP_CADET_MESSAGE
+ */
+ struct GNUNET_MessageHeader header;
+
+ /**
+ * Type of the message this handler covers, in host byte order.
+ */
+ uint16_t type;
+
+ /**
+ * ID of the channel we want to drop a message for.
+ */
+ struct GNUNET_CADET_ClientChannelNumber ccn;
+
+};
+
/**
* Message to inform the client about channels in the service.
*/
diff --git a/src/cadet/cadet_api.c b/src/cadet/cadet_api.c
index 68bd4c290..45cb66c1d 100644
--- a/src/cadet/cadet_api.c
+++ b/src/cadet/cadet_api.c
@@ -73,72 +73,6 @@ struct GNUNET_CADET_Handle
struct GNUNET_TIME_Relative reconnect_time;
};
-
-/**
- * Opaque handle to a channel.
- */
-struct GNUNET_CADET_Channel
-{
- /**
- * Other end of the channel.
- */
- struct GNUNET_PeerIdentity peer;
-
- /**
- * Handle to the cadet this channel belongs to
- */
- struct GNUNET_CADET_Handle *cadet;
-
- /**
- * Channel's port, if incoming.
- */
- struct GNUNET_CADET_Port *incoming_port;
-
- /**
- * Any data the caller wants to put in here, used for the
- * various callbacks (@e disconnects, @e window_changes, handlers).
- */
- void *ctx;
-
- /**
- * Message Queue for the channel (which we are implementing).
- */
- struct GNUNET_MQ_Handle *mq;
-
- /**
- * Task to allow mq to send more traffic.
- */
- struct GNUNET_SCHEDULER_Task *mq_cont;
-
- /**
- * Pending envelope with a message to be transmitted to the
- * service as soon as we are allowed to. Should only be
- * non-NULL if @e allow_send is 0.
- */
- struct GNUNET_MQ_Envelope *pending_env;
-
- /**
- * Window change handler.
- */
- GNUNET_CADET_WindowSizeEventHandler window_changes;
-
- /**
- * Disconnect handler.
- */
- GNUNET_CADET_DisconnectEventHandler disconnects;
-
- /**
- * Local ID of the channel, #GNUNET_CADET_LOCAL_CHANNEL_ID_CLI bit is set if outbound.
- */
- struct GNUNET_CADET_ClientChannelNumber ccn;
-
- /**
- * How many messages are we allowed to send to the service right now?
- */
- unsigned int allow_send;
-};
-
-
/**
* Opaque handle to a port.
*/
@@ -995,6 +929,32 @@ GNUNET_CADET_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
/**
+ * Function to return link to AGPL source upon request.
+ *
+ * @param cls closure with the identification of the client
+ * @param msg AGPL request
+ */
+static void
+return_agpl (void *cls, const struct GNUNET_MessageHeader *msg)
+{
+ struct GNUNET_SERVICE_Client *client = cls;
+ struct GNUNET_MQ_Handle *mq;
+ struct GNUNET_MQ_Envelope *env;
+ struct GNUNET_MessageHeader *res;
+ size_t slen;
+ const struct GNUNET_OS_ProjectData *pd = GNUNET_OS_project_data_get ();
+
+ (void) msg;
+ slen = strlen (pd->agpl_url) + 1;
+ env = GNUNET_MQ_msg_extra (res, GNUNET_MESSAGE_TYPE_RESPONSE_AGPL, slen);
+ memcpy (&res[1], GNUNET_AGPL_URL, slen);
+ mq = GNUNET_SERVICE_client_get_mq (client);
+ GNUNET_MQ_send (mq, env);
+ GNUNET_SERVICE_client_continue (client);
+}
+
+
+/**
* Open a port to receive incomming MQ-based channels.
*
* @param h CADET handle.
@@ -1016,6 +976,7 @@ GNUNET_CADET_open_port (struct GNUNET_CADET_Handle *h,
const struct GNUNET_MQ_MessageHandler *handlers)
{
struct GNUNET_CADET_Port *p;
+ const struct GNUNET_OS_ProjectData *pd = GNUNET_OS_project_data_get ();
GNUNET_assert (NULL != connects);
GNUNET_assert (NULL != disconnects);
@@ -1039,7 +1000,9 @@ GNUNET_CADET_open_port (struct GNUNET_CADET_Handle *h,
p->cls = connects_cls;
p->window_changes = window_changes;
p->disconnects = disconnects;
- p->handlers = GNUNET_MQ_copy_handlers (handlers);
+ p->handlers = (NULL == pd->agpl_url)
+ ? GNUNET_MQ_copy_handlers (handlers)
+ : GNUNET_MQ_copy_handlers2 (handlers, &return_agpl, NULL);
GNUNET_assert (GNUNET_OK == open_port_cb (h, &p->id, p));
return p;
diff --git a/src/cadet/cadet_api_drop_message.c b/src/cadet/cadet_api_drop_message.c
new file mode 100644
index 000000000..d9f7e003e
--- /dev/null
+++ b/src/cadet/cadet_api_drop_message.c
@@ -0,0 +1,59 @@
+/*
+ This file is part of GNUnet.
+ Copyright (C) 2011, 2017, 2019 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 cadet/cadet_api_drop_message.c
+ * @brief cadet api: client implementation of cadet service
+ * @author t3sserakt
+ */
+#include "platform.h"
+#include "cadet.h"
+
+
+/**
+ * Drop the next cadet message of a given type..
+ *
+ * @param mq message queue
+ * @param ccn client channel number.
+ * @param type of cadet message to be dropped.
+ */
+void
+GNUNET_CADET_drop_message (struct GNUNET_MQ_Handle *mq,
+ struct GNUNET_CADET_ClientChannelNumber ccn,
+ uint16_t type)
+{
+ struct GNUNET_CADET_RequestDropCadetMessage *message;
+ struct GNUNET_MQ_Envelope *env;
+
+ env = GNUNET_MQ_msg (message, GNUNET_MESSAGE_TYPE_CADET_DROP_CADET_MESSAGE);
+
+ message->ccn = ccn;
+ message->type = type;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Dropping message for channel of type %s (%d)\n", type == GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY ? "GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY" : "UNKNOWN", type);
+
+ GNUNET_MQ_send (mq, env);
+
+}
+
+
+
+
+/* end of cadet_api_drop_message.c */
diff --git a/src/cadet/cadet_protocol.h b/src/cadet/cadet_protocol.h
index e3417f8c4..08298e224 100644
--- a/src/cadet/cadet_protocol.h
+++ b/src/cadet/cadet_protocol.h
@@ -85,6 +85,24 @@ struct GNUNET_CADET_ConnectionCreateMessage
uint32_t options GNUNET_PACKED;
/**
+ * This flag indicates the peer sending the connection create
+ * meassage likes to trigger a KX handshake.
+ */
+ int has_monotime;
+
+ /**
+ * This monotonic time is set, if a peer likes to trigger a KX, but is not
+ * the peer that should start the KX. (xrs,t3ss)
+ */
+ struct GNUNET_TIME_AbsoluteNBO monotime;
+
+ /**
+ * We sign the monotime. The receiving peer can check the signature, to verify
+ * the sending peer.
+ */
+ struct GNUNET_CRYPTO_EddsaSignature monotime_sig;
+
+ /**
* ID of the connection
*/
struct GNUNET_CADET_ConnectionTunnelIdentifier cid;
diff --git a/src/cadet/gnunet-service-cadet.c b/src/cadet/gnunet-service-cadet.c
index ba83fe0fc..03af3d5c0 100644
--- a/src/cadet/gnunet-service-cadet.c
+++ b/src/cadet/gnunet-service-cadet.c
@@ -580,6 +580,7 @@ handle_channel_create (void *cls,
if (ntohl (tcm->ccn.channel_of_client) < GNUNET_CADET_LOCAL_CHANNEL_ID_CLI)
{
/* Channel ID not in allowed range. */
+ LOG (GNUNET_ERROR_TYPE_DEBUG,"Channel ID not in allowed range.");
GNUNET_break (0);
GNUNET_SERVICE_client_drop (c->client);
return;
@@ -589,6 +590,7 @@ handle_channel_create (void *cls,
if (NULL != ch)
{
/* Channel ID already in use. Not allowed. */
+ LOG (GNUNET_ERROR_TYPE_DEBUG,"Channel ID already in use. Not allowed.");
GNUNET_break (0);
GNUNET_SERVICE_client_drop (c->client);
return;
@@ -1008,6 +1010,26 @@ handle_info_tunnels (void *cls,
GNUNET_SERVICE_client_continue (c->client);
}
+/**
+ * Handler for client's #GNUNET_MESSAGE_TYPE_CADET_DROP_CADET_MESSAGE request.
+ *
+ * @param cls client Identification of the client.
+ * @param message The actual message.
+ */
+static void
+handle_drop_message (void *cls,
+ const struct GNUNET_CADET_RequestDropCadetMessage *message)
+{
+ struct CadetClient *c = cls;
+ struct CadetChannel *ch;
+
+ ch = lookup_channel (c,
+ message->ccn);
+
+ GCCH_assign_type_to_drop(ch, message);
+
+ GNUNET_SERVICE_client_continue (c->client);
+}
/**
* Callback called when a client connects to the service.
@@ -1305,48 +1327,52 @@ run (void *cls,
* Define "main" method using service macro.
*/
GNUNET_SERVICE_MAIN
- ("cadet",
- GNUNET_SERVICE_OPTION_NONE,
- &run,
- &client_connect_cb,
- &client_disconnect_cb,
- NULL,
- GNUNET_MQ_hd_fixed_size (port_open,
- GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_OPEN,
- struct GNUNET_CADET_PortMessage,
- NULL),
- GNUNET_MQ_hd_fixed_size (port_close,
- GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_CLOSE,
- struct GNUNET_CADET_PortMessage,
- NULL),
- GNUNET_MQ_hd_fixed_size (channel_create,
- GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_CREATE,
- struct GNUNET_CADET_LocalChannelCreateMessage,
- NULL),
- GNUNET_MQ_hd_fixed_size (channel_destroy,
- GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_DESTROY,
- struct GNUNET_CADET_LocalChannelDestroyMessage,
- NULL),
- GNUNET_MQ_hd_var_size (local_data,
- GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA,
- struct GNUNET_CADET_LocalData,
- NULL),
- GNUNET_MQ_hd_fixed_size (local_ack,
- GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK,
- struct GNUNET_CADET_LocalAck,
- NULL),
- GNUNET_MQ_hd_fixed_size (get_peers,
- GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_PEERS,
- struct GNUNET_MessageHeader,
- NULL),
- GNUNET_MQ_hd_fixed_size (show_path,
- GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_PATH,
- struct GNUNET_CADET_RequestPathInfoMessage,
- NULL),
- GNUNET_MQ_hd_fixed_size (info_tunnels,
- GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_TUNNELS,
- struct GNUNET_MessageHeader,
- NULL),
- GNUNET_MQ_handler_end ());
+("cadet",
+ GNUNET_SERVICE_OPTION_NONE,
+ &run,
+ &client_connect_cb,
+ &client_disconnect_cb,
+ NULL,
+ GNUNET_MQ_hd_fixed_size (port_open,
+ GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_OPEN,
+ struct GNUNET_CADET_PortMessage,
+ NULL),
+ GNUNET_MQ_hd_fixed_size (port_close,
+ GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_CLOSE,
+ struct GNUNET_CADET_PortMessage,
+ NULL),
+ GNUNET_MQ_hd_fixed_size (channel_create,
+ GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_CREATE,
+ struct GNUNET_CADET_LocalChannelCreateMessage,
+ NULL),
+ GNUNET_MQ_hd_fixed_size (channel_destroy,
+ GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_DESTROY,
+ struct GNUNET_CADET_LocalChannelDestroyMessage,
+ NULL),
+ GNUNET_MQ_hd_var_size (local_data,
+ GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA,
+ struct GNUNET_CADET_LocalData,
+ NULL),
+ GNUNET_MQ_hd_fixed_size (local_ack,
+ GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK,
+ struct GNUNET_CADET_LocalAck,
+ NULL),
+ GNUNET_MQ_hd_fixed_size (get_peers,
+ GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_PEERS,
+ struct GNUNET_MessageHeader,
+ NULL),
+ GNUNET_MQ_hd_fixed_size (show_path,
+ GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_PATH,
+ struct GNUNET_CADET_RequestPathInfoMessage,
+ NULL),
+ GNUNET_MQ_hd_fixed_size (info_tunnels,
+ GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_TUNNELS,
+ struct GNUNET_MessageHeader,
+ NULL),
+ GNUNET_MQ_hd_fixed_size (drop_message,
+ GNUNET_MESSAGE_TYPE_CADET_DROP_CADET_MESSAGE,
+ struct GNUNET_CADET_RequestDropCadetMessage,
+ NULL),
+ GNUNET_MQ_handler_end ());
/* end of gnunet-service-cadet-new.c */
diff --git a/src/cadet/gnunet-service-cadet.h b/src/cadet/gnunet-service-cadet.h
index 6da0950f1..ff216f8c3 100644
--- a/src/cadet/gnunet-service-cadet.h
+++ b/src/cadet/gnunet-service-cadet.h
@@ -325,4 +325,5 @@ const char *
GSC_2s (struct CadetClient *c);
+
#endif
diff --git a/src/cadet/gnunet-service-cadet_channel.c b/src/cadet/gnunet-service-cadet_channel.c
index 5c8103c5e..e6fce562f 100644
--- a/src/cadet/gnunet-service-cadet_channel.c
+++ b/src/cadet/gnunet-service-cadet_channel.c
@@ -380,8 +380,44 @@ struct CadetChannel
* empty.
*/
int destroy;
+
+ /**
+ * Type of message to be droped. See GCT_send.
+ */
+ uint16_t type GNUNET_PACKED;
+
};
+/**
+ * Assign type of message to drop.
+ * @param ch CadetChannel to assign type to drop.
+ * @param message GNUNET_CADET_RequestDropCadetMessage to get the type from.
+ */
+void
+GCCH_assign_type_to_drop(struct CadetChannel *ch, const struct GNUNET_CADET_RequestDropCadetMessage *message)
+{
+
+ ch->type = message->type;
+
+}
+
+/**
+ * Check if type of message is the one to drop.
+ * @param ch CadetChannel to check for message type to drop.
+ * @param message GNUNET_MessageHeader to compare the type with.
+ */
+int
+GCCH_is_type_to_drop(struct CadetChannel *ch, const struct GNUNET_MessageHeader *message)
+{
+
+ if (ch->type == message->type)
+ {
+ ch->type = 0;
+ return GNUNET_YES;
+ }
+ else
+ return GNUNET_NO;
+}
/**
* Get the static string for identification of the channel.
@@ -594,7 +630,7 @@ send_channel_open (void *cls)
if (NULL != ch->last_control_qe)
GCT_send_cancel (ch->last_control_qe);
ch->last_control_qe =
- GCT_send (ch->t, &msgcc.header, &channel_open_sent_cb, ch);
+ GCT_send (ch->t, &msgcc.header, &channel_open_sent_cb, ch, &msgcc.ctn);
GNUNET_assert (NULL == ch->retry_control_task);
}
@@ -818,7 +854,7 @@ send_channel_data_ack (struct CadetChannel *ch)
GCCH_2s (ch));
if (NULL != ch->last_control_qe)
GCT_send_cancel (ch->last_control_qe);
- ch->last_control_qe = GCT_send (ch->t, &msg.header, &send_ack_cb, ch);
+ ch->last_control_qe = GCT_send (ch->t, &msg.header, &send_ack_cb, ch, &msg.ctn);
}
@@ -845,7 +881,7 @@ send_open_ack (void *cls)
msg.port = ch->port;
if (NULL != ch->last_control_qe)
GCT_send_cancel (ch->last_control_qe);
- ch->last_control_qe = GCT_send (ch->t, &msg.header, &send_ack_cb, ch);
+ ch->last_control_qe = GCT_send (ch->t, &msg.header, &send_ack_cb, ch, &msg.ctn);
}
@@ -1477,7 +1513,7 @@ retry_transmission (void *cls)
"Retrying transmission on %s of message %u\n",
GCCH_2s (ch),
(unsigned int) ntohl (crm->data_message->mid.mid));
- crm->qe = GCT_send (ch->t, &crm->data_message->header, &data_sent_cb, crm);
+ crm->qe = GCT_send (ch->t, &crm->data_message->header, &data_sent_cb, crm, &crm->data_message->ctn);
GNUNET_assert (NULL == ch->retry_data_task);
}
@@ -1865,7 +1901,7 @@ GCCH_handle_local_data (struct CadetChannel *ch,
GNUNET_SCHEDULER_cancel (ch->retry_data_task);
ch->retry_data_task = NULL;
}
- crm->qe = GCT_send (ch->t, &crm->data_message->header, &data_sent_cb, crm);
+ crm->qe = GCT_send (ch->t, &crm->data_message->header, &data_sent_cb, crm, &crm->data_message->ctn);
GNUNET_assert (NULL == ch->retry_data_task);
return GNUNET_OK;
}
diff --git a/src/cadet/gnunet-service-cadet_channel.h b/src/cadet/gnunet-service-cadet_channel.h
index 0a6c97329..7a072f128 100644
--- a/src/cadet/gnunet-service-cadet_channel.h
+++ b/src/cadet/gnunet-service-cadet_channel.h
@@ -57,6 +57,23 @@ GCCH_hash_port (struct GNUNET_HashCode *h_port,
const struct GNUNET_HashCode *port,
const struct GNUNET_PeerIdentity *listener);
+/**
+ * Check if type of message is the one to drop.
+ * @param ch CadetChannel to check for message type to drop.
+ * @param message GNUNET_MessageHeader to compare the type with.
+ */
+int
+GCCH_is_type_to_drop (struct CadetChannel *ch, const struct
+ GNUNET_MessageHeader *message);
+
+/**
+ * Check if type of message is the one to drop.
+ * @param ch CadetChannel to assign type to drop.
+ * @param message GNUNET_CADET_RequestDropCadetMessage to get the type from.
+ */
+void
+GCCH_assign_type_to_drop (struct CadetChannel *ch, const struct
+ GNUNET_CADET_RequestDropCadetMessage *message);
/**
* Get the static string for identification of the channel.
diff --git a/src/cadet/gnunet-service-cadet_connection.c b/src/cadet/gnunet-service-cadet_connection.c
index c07339ebc..a7c1d9fb0 100644
--- a/src/cadet/gnunet-service-cadet_connection.c
+++ b/src/cadet/gnunet-service-cadet_connection.c
@@ -26,6 +26,7 @@
* @author Christian Grothoff
*/
#include "platform.h"
+#include "gnunet_signatures.h"
#include "gnunet-service-cadet_connection.h"
#include "gnunet-service-cadet_channel.h"
#include "gnunet-service-cadet_paths.h"
@@ -78,7 +79,6 @@ enum CadetConnectionState
CADET_CONNECTION_READY
};
-
/**
* Low-level connection to a destination.
*/
@@ -206,6 +206,14 @@ update_state (struct CadetConnection *cc,
int old_ready;
int new_ready;
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Trying to update connection state for %s having old state %d to new %d and mqm_ready old %d to mqm_ready new %d\n",
+ GCT_2s (cc->ct->t),
+ cc->state,
+ new_state,
+ cc->mqm_ready,
+ new_mqm_ready);
+
if ((new_state == cc->state) && (new_mqm_ready == cc->mqm_ready))
return; /* no change, nothing to do */
old_ready =
@@ -214,6 +222,13 @@ update_state (struct CadetConnection *cc,
((CADET_CONNECTION_READY == new_state) && (GNUNET_YES == new_mqm_ready));
cc->state = new_state;
cc->mqm_ready = new_mqm_ready;
+
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Updating connection state for %s having old_ready %d and new_rady %d\n",
+ GCT_2s (cc->ct->t),
+ old_ready,
+ new_ready);
+
if (old_ready != new_ready)
cc->ready_cb (cc->ready_cb_cls, new_ready);
}
@@ -392,7 +407,7 @@ send_keepalive (void *cls)
msg.size = htons (sizeof(msg));
msg.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_KEEPALIVE);
- cc->keepalive_qe = GCT_send (cc->ct->t, &msg, &keepalive_done, cc);
+ cc->keepalive_qe = GCT_send (cc->ct->t, &msg, &keepalive_done, cc, NULL);
}
@@ -581,6 +596,25 @@ GCC_handle_encrypted (struct CadetConnection *cc,
/**
+ * Set the signature for a monotime value on a GNUNET_CADET_ConnectionCreateMessage.
+ *
+ * @param msg The GNUNET_CADET_ConnectionCreateMessage.
+ */
+void
+set_monotime_sig (struct GNUNET_CADET_ConnectionCreateMessage *msg)
+{
+
+ struct CadetConnectionCreatePS cp = { .purpose.purpose = htonl (
+ GNUNET_SIGNATURE_PURPOSE_CADET_CONNECTION_INITIATOR),
+ .purpose.size = htonl (sizeof(cp)),
+ .monotonic_time = msg->monotime};
+
+ GNUNET_CRYPTO_eddsa_sign (my_private_key, &cp,
+ &msg->monotime_sig);
+
+}
+
+/**
* Send a #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE message to the
* first hop.
*
@@ -593,6 +627,7 @@ send_create (void *cls)
struct GNUNET_CADET_ConnectionCreateMessage *create_msg;
struct GNUNET_PeerIdentity *pids;
struct GNUNET_MQ_Envelope *env;
+ struct CadetTunnel *t;
cc->task = NULL;
GNUNET_assert (GNUNET_YES == cc->mqm_ready);
@@ -603,6 +638,18 @@ send_create (void *cls)
// TODO This will be removed in a major release, because this will be a protocol breaking change. We set the deprecated 'reliable' bit here that was removed.
create_msg->options = 2;
create_msg->cid = cc->cid;
+
+ // check for tunnel state and set signed monotime (xrs,t3ss)
+ t = GCP_get_tunnel (cc->destination, GNUNET_YES);
+ if ((NULL != t)&& (GCT_get_estate (t) == CADET_TUNNEL_KEY_UNINITIALIZED) &&
+ (GCT_alice_or_betty (GCP_get_id (cc->destination)) == GNUNET_NO))
+ {
+ create_msg->has_monotime = GNUNET_YES;
+ create_msg->monotime = GNUNET_TIME_absolute_hton (
+ GNUNET_TIME_absolute_get_monotonic (cfg));
+ set_monotime_sig (create_msg);
+ }
+
pids = (struct GNUNET_PeerIdentity *) &create_msg[1];
pids[0] = my_full_id;
for (unsigned int i = 0; i <= cc->off; i++)
@@ -792,6 +839,7 @@ connection_create (struct CadetPeer *destination,
cc = GNUNET_new (struct CadetConnection);
cc->state = init_state;
cc->ct = ct;
+ cc->destination = destination; /* xrs,t3ss,lurchi*/
cc->cid = *cid;
cc->retry_delay =
GNUNET_TIME_relative_multiply (INITIAL_CONNECTION_CREATE_RETRY_DELAY, off);
diff --git a/src/cadet/gnunet-service-cadet_connection.h b/src/cadet/gnunet-service-cadet_connection.h
index b05c3b72c..ed0e909fb 100644
--- a/src/cadet/gnunet-service-cadet_connection.h
+++ b/src/cadet/gnunet-service-cadet_connection.h
@@ -183,6 +183,32 @@ GCC_handle_kx_auth (struct CadetConnection *cc,
const struct
GNUNET_CADET_TunnelKeyExchangeAuthMessage *msg);
+/**
+ * Purpose for the signature of a monotime.
+ */
+struct CadetConnectionCreatePS
+{
+
+ /**
+ * Purpose is #GNUNET_SIGNATURE_PURPOSE_CADET_CONNECTION_INITIATOR
+ */
+ struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
+
+ /**
+ * Time at the initiator when generating the signature.
+ *
+ * Note that the receiver MUST IGNORE the absolute time, and only interpret
+ * the value as a mononic time and reject "older" values than the last one
+ * observed. This is necessary as we do not want to require synchronized
+ * clocks and may not have a bidirectional communication channel.
+ *
+ * Even with this, there is no real guarantee against replay achieved here,
+ * unless the latest timestamp is persisted. Persistence should be
+ * provided via PEERSTORE if possible.
+ */
+ struct GNUNET_TIME_AbsoluteNBO monotonic_time;
+
+};
/**
* Performance metrics for a connection.
diff --git a/src/cadet/gnunet-service-cadet_core.c b/src/cadet/gnunet-service-cadet_core.c
index d54022896..04847f906 100644
--- a/src/cadet/gnunet-service-cadet_core.c
+++ b/src/cadet/gnunet-service-cadet_core.c
@@ -227,7 +227,6 @@ static unsigned long long cur_buffers;
*/
static struct GNUNET_SCHEDULER_Task *timeout_task;
-
/**
* Get the route corresponding to a hash.
*
@@ -724,6 +723,7 @@ handle_connection_create (
uint16_t size = ntohs (msg->header.size) - sizeof(*msg);
unsigned int path_length;
unsigned int off;
+ struct CadetTunnel *t;
path_length = size / sizeof(struct GNUNET_PeerIdentity);
if (0 == path_length)
@@ -822,8 +822,19 @@ handle_connection_create (
GCP_2s (origin),
GNUNET_sh2s (&msg->cid.connection_of_tunnel));
path = GCPP_get_path_from_route (path_length - 1, pids);
+ t = GCP_get_tunnel (sender, GNUNET_YES);
+
+ // Check for CADET state in case the other side has lost the tunnel (xrs,t3ss)
+ if ((GNUNET_YES == msg->has_monotime) &&
+ (GNUNET_YES == GCP_check_and_update_monotime(origin, msg->monotime)) &&
+ ( GNUNET_OK == GCP_check_monotime_sig(origin, msg)) &&
+ (CADET_TUNNEL_KEY_OK == GCT_get_estate(t)))
+ {
+ GCT_change_estate (t, CADET_TUNNEL_KEY_UNINITIALIZED);
+ }
+
if (GNUNET_OK !=
- GCT_add_inbound_connection (GCP_get_tunnel (origin, GNUNET_YES),
+ GCT_add_inbound_connection (t,
&msg->cid,
path))
{
diff --git a/src/cadet/gnunet-service-cadet_peer.c b/src/cadet/gnunet-service-cadet_peer.c
index 8258881d0..55800b88c 100644
--- a/src/cadet/gnunet-service-cadet_peer.c
+++ b/src/cadet/gnunet-service-cadet_peer.c
@@ -31,6 +31,7 @@
* to take a break if we have some connections and have searched a lot (?))
*/
#include "platform.h"
+#include "gnunet_time_lib.h"
#include "gnunet_util_lib.h"
#include "gnunet_hello_lib.h"
#include "gnunet_signatures.h"
@@ -38,10 +39,10 @@
#include "gnunet_ats_service.h"
#include "gnunet_core_service.h"
#include "gnunet_statistics_service.h"
-#include "cadet_protocol.h"
+#include "gnunet-service-cadet_peer.h"
+#include "gnunet-service-cadet.h"
#include "gnunet-service-cadet_connection.h"
#include "gnunet-service-cadet_dht.h"
-#include "gnunet-service-cadet_peer.h"
#include "gnunet-service-cadet_paths.h"
#include "gnunet-service-cadet_tunnels.h"
@@ -66,7 +67,6 @@
*/
#define MAX_OOO_QUEUE_SIZE 100
-
/**
* Data structure used to track whom we have to notify about changes
* to our message queue.
@@ -118,7 +118,7 @@ struct CadetPeer
/**
* Last time we heard from this peer (currently not used!)
*/
- struct GNUNET_TIME_Absolute last_contactXXX;
+ struct GNUNET_TIME_Absolute last_connection_create;
/**
* Array of DLLs of paths traversing the peer, organized by the
@@ -1552,5 +1552,56 @@ GCP_send_ooo (struct CadetPeer *cp,
env);
}
+/**
+ * Checking if a monotime value is newer than the last monotime value received from a peer. If the time value is newer it will be stored at the peer.
+ *
+ * @param peer The peer we received a new time value from.
+ * @param monotime Time value we check against the last time value we received from a peer.
+ * @return GNUNET_YES if monotime is newer than the last received time value, GNUNET_NO if monotime is not newer.
+ */
+int
+GCP_check_and_update_monotime (struct CadetPeer *peer,
+ struct GNUNET_TIME_AbsoluteNBO monotime)
+{
+
+ struct GNUNET_TIME_Absolute mt = GNUNET_TIME_absolute_ntoh (monotime);
+
+ if (mt.abs_value_us > *(&peer->last_connection_create.abs_value_us))
+ {
+ peer->last_connection_create = mt;
+ return GNUNET_YES;
+ }
+ return GNUNET_NO;
+}
+
+/**
+ * Checking the signature for a monotime of a GNUNET_CADET_ConnectionCreateMessage.
+ *
+ * @param peer The peer that signed the monotime value.
+ * @param msg The GNUNET_CADET_ConnectionCreateMessage with the monotime value.
+ * @return GNUNET_OK if the signature is good, GNUNET_SYSERR if not.
+ */
+int
+GCP_check_monotime_sig (struct CadetPeer *peer,
+ const struct GNUNET_CADET_ConnectionCreateMessage *msg)
+{
+ struct CadetConnectionCreatePS cp = { .purpose.purpose = htonl (
+ GNUNET_SIGNATURE_PURPOSE_CADET_CONNECTION_INITIATOR),
+ .purpose.size = htonl (sizeof(cp)),
+ .monotonic_time = msg->monotime};
+
+ if (GNUNET_OK !=
+ GNUNET_CRYPTO_eddsa_verify (
+ GNUNET_SIGNATURE_PURPOSE_CADET_CONNECTION_INITIATOR,
+ &cp,
+ &msg->monotime_sig,
+ &peer->pid.public_key))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ return GNUNET_OK;
+}
+
/* end of gnunet-service-cadet-new_peer.c */
diff --git a/src/cadet/gnunet-service-cadet_peer.h b/src/cadet/gnunet-service-cadet_peer.h
index bec0606a0..5782b8bff 100644
--- a/src/cadet/gnunet-service-cadet_peer.h
+++ b/src/cadet/gnunet-service-cadet_peer.h
@@ -402,5 +402,26 @@ void
GCP_set_mq (struct CadetPeer *cp,
struct GNUNET_MQ_Handle *mq);
+/**
+ * Checking the signature for a monotime of a GNUNET_CADET_ConnectionCreateMessage.
+ *
+ * @param peer The peer that signed the monotime value.
+ * @param msg The GNUNET_CADET_ConnectionCreateMessage with the monotime value.
+ * @return GNUNET_OK if the signature is good, GNUNET_SYSERR if not.
+ */
+int
+GCP_check_monotime_sig (struct CadetPeer *peer, const struct
+ GNUNET_CADET_ConnectionCreateMessage *msg);
+
+/**
+ * Checking if a monotime value is newer than the last monotime value received from a peer. If the time value is newer it will be stored at the peer.
+ *
+ * @param peer The peer we received a new time value from.
+ * @param monotime Time value we check against the last time value we received from a peer.
+ * @return GNUNET_YES if monotime is newer than the last received time value, GNUNET_NO if monotime is not newer.
+ */
+int
+GCP_check_and_update_monotime (struct CadetPeer *peer,
+ struct GNUNET_TIME_AbsoluteNBO monotime);
#endif
diff --git a/src/cadet/gnunet-service-cadet_tunnels.c b/src/cadet/gnunet-service-cadet_tunnels.c
index f1f2ec81f..66e7d5b1e 100644
--- a/src/cadet/gnunet-service-cadet_tunnels.c
+++ b/src/cadet/gnunet-service-cadet_tunnels.c
@@ -464,8 +464,8 @@ struct CadetTunnel
* @param other the other peer
* @return #GNUNET_YES for Alice, #GNUNET_NO for Betty, #GNUNET_SYSERR if talking to myself
*/
-static int
-alice_or_betty (const struct GNUNET_PeerIdentity *other)
+int
+GCT_alice_or_betty (const struct GNUNET_PeerIdentity *other)
{
if (0 > GNUNET_memcmp (&my_full_id,
other))
@@ -1345,7 +1345,7 @@ send_kx (struct CadetTunnel *t,
struct GNUNET_CADET_TunnelKeyExchangeMessage *msg;
enum GNUNET_CADET_KX_Flags flags;
- if (GNUNET_YES != alice_or_betty (GCP_get_id (t->destination)))
+ if (GNUNET_YES != GCT_alice_or_betty (GCP_get_id (t->destination)))
return; /* only Alice may send KX */
if ((NULL == ct) ||
(GNUNET_NO == ct->is_ready))
@@ -1521,7 +1521,7 @@ update_ax_by_kx (struct CadetTunnelAxolotl *ax,
const char salt[] = "CADET Axolotl salt";
int am_I_alice;
- if (GNUNET_SYSERR == (am_I_alice = alice_or_betty (pid)))
+ if (GNUNET_SYSERR == (am_I_alice = GCT_alice_or_betty (pid)))
{
GNUNET_break_op (0);
return GNUNET_SYSERR;
@@ -1726,7 +1726,7 @@ GCT_handle_kx (struct CadetTConnection *ct,
1,
GNUNET_NO);
if (GNUNET_YES ==
- alice_or_betty (GCP_get_id (t->destination)))
+ GCT_alice_or_betty (GCP_get_id (t->destination)))
{
/* Betty/Bob is not allowed to send KX! */
GNUNET_break_op (0);
@@ -2123,9 +2123,10 @@ GCT_add_channel (struct CadetTunnel *t,
ch,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Adding %s to %s\n",
+ "Adding %s to %s with state %d\n",
GCCH_2s (ch),
- GCT_2s (t));
+ GCT_2s (t),
+ t->estate);
switch (t->estate)
{
case CADET_TUNNEL_KEY_UNINITIALIZED:
@@ -2429,12 +2430,21 @@ connection_ready_cb (void *cls,
switch (t->estate)
{
case CADET_TUNNEL_KEY_UNINITIALIZED:
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Do not begin KX for %s if WE have no channels waiting. Retrying after %d\n",
+ GCT_2s (t),
+ GNUNET_TIME_absolute_get_remaining (t->next_kx_attempt).rel_value_us);
/* Do not begin KX if WE have no channels waiting! */
if (0 != GNUNET_TIME_absolute_get_remaining (
t->next_kx_attempt).rel_value_us)
return; /* wait for timeout before retrying */
/* We are uninitialized, just transmit immediately,
without undue delay. */
+
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Why for %s \n",
+ GCT_2s (t));
+
if (NULL != t->kx_task)
{
GNUNET_SCHEDULER_cancel (t->kx_task);
@@ -3028,7 +3038,8 @@ GCT_send_channel_destroy (struct CadetTunnel *t,
GCT_send (t,
&msg.header,
NULL,
- NULL);
+ NULL,
+ &ctn);
}
@@ -3445,18 +3456,32 @@ GCT_handle_encrypted (struct CadetTConnection *ct,
* @param t Tunnel on which this message is transmitted.
* @param cont Continuation to call once message is really sent.
* @param cont_cls Closure for @c cont.
+ * @param The ID of the channel we are using for sending.
* @return Handle to cancel message
*/
struct CadetTunnelQueueEntry *
GCT_send (struct CadetTunnel *t,
const struct GNUNET_MessageHeader *message,
GCT_SendContinuation cont,
- void *cont_cls)
+ void *cont_cls,
+ struct GNUNET_CADET_ChannelTunnelNumber *ctn)
{
struct CadetTunnelQueueEntry *tq;
uint16_t payload_size;
struct GNUNET_MQ_Envelope *env;
struct GNUNET_CADET_TunnelEncryptedMessage *ax_msg;
+ struct CadetChannel *ch;
+
+ if (NULL != ctn)
+ {
+ ch = lookup_channel (t,
+ *ctn);
+ if ((NULL != ch)&& GCCH_is_type_to_drop (ch, message))
+ {
+ GNUNET_break (0);
+ return NULL;
+ }
+ }
if (CADET_TUNNEL_KEY_OK != t->estate)
{
diff --git a/src/cadet/gnunet-service-cadet_tunnels.h b/src/cadet/gnunet-service-cadet_tunnels.h
index ef07badea..147f2e56f 100644
--- a/src/cadet/gnunet-service-cadet_tunnels.h
+++ b/src/cadet/gnunet-service-cadet_tunnels.h
@@ -80,6 +80,14 @@ enum CadetTunnelEState
CADET_TUNNEL_KEY_OK
};
+/**
+ * Am I Alice or Betty (some call her Bob), or talking to myself?
+ *
+ * @param other the other peer
+ * @return #GNUNET_YES for Alice, #GNUNET_NO for Betty, #GNUNET_SYSERR if talking to myself
+ */
+int
+GCT_alice_or_betty (const struct GNUNET_PeerIdentity *other);
/**
* Get the static string for the peer this tunnel is directed.
@@ -226,7 +234,8 @@ struct CadetTunnelQueueEntry *
GCT_send (struct CadetTunnel *t,
const struct GNUNET_MessageHeader *message,
GCT_SendContinuation cont,
- void *cont_cls);
+ void *cont_cls,
+ struct GNUNET_CADET_ChannelTunnelNumber *ctn);
/**
@@ -320,6 +329,16 @@ GCT_iterate_channels (struct CadetTunnel *t,
enum CadetTunnelEState
GCT_get_estate (struct CadetTunnel *t);
+/**
+ * Change the tunnel encryption state.
+ * If the encryption state changes to OK, stop the rekey task.
+ *
+ * @param t Tunnel whose encryption state to change, or NULL.
+ * @param state New encryption state.
+ */
+void
+GCT_change_estate (struct CadetTunnel *t,
+ enum CadetTunnelEState state);
/**
* Handle KX message.
diff --git a/src/cadet/test_cadet.c b/src/cadet/test_cadet.c
index 25713709c..779d3bc9f 100644
--- a/src/cadet/test_cadet.c
+++ b/src/cadet/test_cadet.c
@@ -25,6 +25,7 @@
*/
#include <stdio.h>
#include "platform.h"
+#include "cadet.h"
#include "cadet_test_lib.h"
#include "gnunet_cadet_service.h"
#include "gnunet_statistics_service.h"
@@ -74,6 +75,17 @@ struct CadetTestChannelWrapper
#define SPEED_REL 8
#define P2P_SIGNAL 10
#define REOPEN 11
+#define DESTROY 12
+
+/**
+ * Active peer listing operation.
+ */
+static struct GNUNET_CADET_PeersLister *plo;
+
+/*
+ * Task called to check for existing tunnel and depending on that reopen channel
+ */
+static struct GNUNET_SCHEDULER_Task *get_peers_task;
/**
* Which test are we running?
@@ -123,7 +135,12 @@ static struct GNUNET_TESTBED_Operation *t_op[2];
/**
* Peer ids.
*/
-static struct GNUNET_PeerIdentity *p_id[2];
+static struct GNUNET_PeerIdentity *testpeer_id[2];
+
+/**
+ * Peer ids.
+ */
+static struct GNUNET_CONFIGURATION_Handle *p_cfg[2];
/**
* Port ID
@@ -133,7 +150,7 @@ static struct GNUNET_HashCode port;
/**
* Peer ids counter.
*/
-static unsigned int p_ids;
+static unsigned int peerinfo_task_cnt;
/**
* Is the setup initialized?
@@ -196,16 +213,6 @@ static struct GNUNET_SCHEDULER_Task *test_task;
static struct GNUNET_SCHEDULER_Task *send_next_msg_task;
/**
- * Cadet handle for the root peer
- */
-static struct GNUNET_CADET_Handle *h1;
-
-/**
- * Cadet handle for the first leaf peer
- */
-static struct GNUNET_CADET_Handle *h2;
-
-/**
* Channel handle for the root peer
*/
static struct GNUNET_CADET_Channel *outgoing_ch;
@@ -226,6 +233,9 @@ static struct GNUNET_TIME_Absolute start_time;
*/
static struct GNUNET_TESTBED_Peer **testbed_peers;
+
+struct GNUNET_CADET_Handle **cadets_running;
+
/**
* Statistics operation handle.
*/
@@ -246,6 +256,17 @@ static unsigned int ka_received;
*/
static unsigned int msg_dropped;
+/**
+ * Drop the next cadet message of a given type..
+ *
+ * @param mq message queue
+ * @param ccn client channel number.
+ * @param type of cadet message to be dropped.
+ */
+void
+GNUNET_CADET_drop_message (struct GNUNET_MQ_Handle *mq,
+ struct GNUNET_CADET_ClientChannelNumber ccn,
+ uint16_t type);
/******************************************************************************/
@@ -516,6 +537,49 @@ static void
disconnect_handler (void *cls,
const struct GNUNET_CADET_Channel *channel);
+static struct GNUNET_PeerIdentity *
+get_from_p_ids ()
+{
+ if (0 < GNUNET_memcmp (testpeer_id[0], testpeer_id[1]))
+ {
+ return testpeer_id[1];
+ }
+ else
+ {
+ return testpeer_id[0];
+ }
+}
+
+static struct GNUNET_CADET_Handle *
+get_from_cadets ()
+{
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "1\n");
+ if (0 < GNUNET_memcmp (testpeer_id[0], testpeer_id[1]))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "standard peer\n");
+ return cadets_running[0];
+ }
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "the other peer\n");
+ return cadets_running[peers_running - 1];
+ }
+
+}
+
+static unsigned int
+get_peer_nr (int outgoing)
+{
+ if (0 < GNUNET_memcmp (testpeer_id[0], testpeer_id[1]))
+ {
+ return GNUNET_YES == outgoing ? 0 : peers_running - 1;
+ }
+ else
+ {
+ return GNUNET_YES == outgoing ? peers_running - 1 : 0;
+ }
+}
/**
* Task to reconnect to other peer.
@@ -534,6 +598,8 @@ reconnect_op (void *cls)
};
long l = (long) cls;
struct CadetTestChannelWrapper *ch;
+ static struct GNUNET_PeerIdentity *p_id;
+ static struct GNUNET_CADET_Handle *h1;
reconnect_task = NULL;
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
@@ -545,17 +611,127 @@ reconnect_op (void *cls)
outgoing_ch = NULL;
}
ch = GNUNET_new (struct CadetTestChannelWrapper);
+
+ p_id = get_from_p_ids ();
+ h1 = get_from_cadets ();
+
+ outgoing_ch = GNUNET_CADET_channel_create (h1,
+ ch,
+ p_id,
+ &port,
+ NULL,
+ &disconnect_handler,
+ handlers);
+ ch->ch = outgoing_ch;
+ send_test_message (outgoing_ch);
+}
+
+void
+reopen_channel ()
+{
+ struct CadetTestChannelWrapper *ch;
+ static struct GNUNET_CADET_Handle *h1;
+ static struct GNUNET_PeerIdentity *p_id;
+ struct GNUNET_MQ_MessageHandler handlers[] = {
+ GNUNET_MQ_hd_var_size (data,
+ GNUNET_MESSAGE_TYPE_DUMMY,
+ struct GNUNET_MessageHeader,
+ NULL),
+ GNUNET_MQ_handler_end ()
+ };
+
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "creating channel again\n");
+ p_id = get_from_p_ids ();
+ h1 = get_from_cadets ();
+
+ ch = GNUNET_new (struct CadetTestChannelWrapper);
outgoing_ch = GNUNET_CADET_channel_create (h1,
ch,
- p_id[1],
+ p_id,
&port,
NULL,
&disconnect_handler,
handlers);
ch->ch = outgoing_ch;
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Sending second test data (after destroying the channel) on channel %p...\n",
+ outgoing_ch);
send_test_message (outgoing_ch);
}
+static void
+peers_callback (void *cls, const struct GNUNET_CADET_PeerListEntry *ple);
+
+/**
+ * We ask the monitoring api for all the peers.
+ */
+static void
+get_peers (void *cls)
+{
+
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "requesting peers info!\n");
+ plo = GNUNET_CADET_list_peers (p_cfg[get_peer_nr (GNUNET_YES)],
+ &peers_callback, NULL);
+
+}
+
+/**
+ * Method called to retrieve information about all peers in CADET, called
+ * once per peer.
+ *
+ * After last peer has been reported, an additional call with NULL is done.
+ *
+ * We check the peer we are interested in, if we have a tunnel. If not, we
+ * reopen the channel
+ *
+ * @param cls Closure.
+ * @param ple information about peer, or NULL on "EOF".
+ */
+static void
+peers_callback (void *cls, const struct GNUNET_CADET_PeerListEntry *ple)
+{
+
+ const struct GNUNET_PeerIdentity *p_id;
+ const struct GNUNET_PeerIdentity *peer;
+
+
+ peer = &ple->peer;
+
+ if (NULL == ple)
+ {
+ plo = NULL;
+ return;
+ }
+ p_id = get_from_p_ids ();
+
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "ple->peer %s\n",
+ GNUNET_i2s_full (&ple->peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "p_id %s\n",
+ GNUNET_i2s_full (p_id));
+
+ if ((0 == GNUNET_memcmp (&ple->peer, p_id))&& ple->have_tunnel)
+ {
+
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "schedule get_peers again?\n");
+ get_peers_task = GNUNET_SCHEDULER_add_delayed (SHORT_TIME,
+ &get_peers,
+ NULL);
+
+ }
+ else if (0 == GNUNET_memcmp (&ple->peer, p_id) )
+ {
+
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "reopen channel\n");
+
+ reopen_channel ();
+
+ }
+}
/**
* Function called whenever an MQ-channel is destroyed, unless the destruction
@@ -575,9 +751,22 @@ disconnect_handler (void *cls,
struct CadetTestChannelWrapper *ch_w = cls;
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Channel disconnected at %d\n",
+ "Channel disconnected at ok=%d\n",
ok);
GNUNET_assert (ch_w->ch == channel);
+
+ if ((DESTROY == test) && (3 == ok))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Reopen channel task!\n");
+ if (NULL == get_peers_task)
+ {
+ get_peers_task = GNUNET_SCHEDULER_add_now (&get_peers,
+ NULL);
+ }
+ return;
+ }
+
if (channel == incoming_ch)
{
ok++;
@@ -651,8 +840,8 @@ send_test_message (struct GNUNET_CADET_Channel *channel)
int size;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sending test message on channel %p\n",
- channel);
+ "Sending test message on channel %u\n",
+ channel->ccn.channel_of_client);
size = size_payload;
if (GNUNET_NO == initialized)
{
@@ -699,6 +888,10 @@ send_test_message (struct GNUNET_CADET_Channel *channel)
"Sending DATA %u [%d bytes]\n",
data_sent, size);
}
+ else if (DESTROY == test)
+ {
+ payload = data_sent;
+ }
else
{
GNUNET_assert (0);
@@ -826,7 +1019,7 @@ handle_data (void *cls,
}
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- " ok: (%d/%d)\n",
+ "handle_data ok: (%d/%d)\n",
ok,
ok_goal);
data = (uint32_t *) &message[1];
@@ -844,6 +1037,49 @@ handle_data (void *cls,
payload, *counter);
}
+ if (DESTROY == test)
+ {
+ if (2 == ok)
+ {
+ ok++;
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "dropping message ok: (%d/%d)\n",
+ ok,
+ ok_goal);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "TEST ID 0: %s\n",
+ GNUNET_i2s (testpeer_id[0]));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "TEST ID 1: %s\n",
+ GNUNET_i2s (testpeer_id[1]));
+
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "dropping message\n");
+ GNUNET_CADET_drop_message (GNUNET_CADET_get_mq (outgoing_ch),
+ outgoing_ch->ccn,
+ GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY);
+ if (NULL != outgoing_ch)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Destroying channel %p...\n",
+ outgoing_ch);
+ GNUNET_CADET_channel_destroy (outgoing_ch);
+ outgoing_ch = NULL;
+ }
+ }
+ else if (5 == ok)
+ {
+ ok++;
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "destroy test finished ok: (%d/%d)\n",
+ ok,
+ ok_goal);
+ disconnect_task =
+ GNUNET_SCHEDULER_add_now (&gather_stats_and_exit,
+ (void *) __LINE__);
+ // End of DESTROY test.
+ }
+ }
+
if (GNUNET_NO == initialized)
{
initialized = GNUNET_YES;
@@ -861,7 +1097,7 @@ handle_data (void *cls,
if (get_target_channel () == channel) /* Got "data" */
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO, " received data %u\n", data_received);
- if ((SPEED != test) || ( (ok_goal - 2) == ok) )
+ if ((DESTROY != test) && ((SPEED != test) || ( (ok_goal - 2) == ok)) )
{
/* Send ACK */
send_test_message (channel);
@@ -927,11 +1163,13 @@ connect_handler (void *cls,
channel);
ok++;
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- " ok: %d\n",
- ok);
- if (peer == peers_requested - 1)
+ "connect_handler ok: (%d/%d)\n",
+ ok,
+ ok_goal);
+
+ if (peer == get_peer_nr (GNUNET_NO))
{
- if (NULL != incoming_ch)
+ if ((DESTROY != test)&&(NULL != incoming_ch))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Duplicate incoming channel for client %lu\n",
@@ -947,7 +1185,7 @@ connect_handler (void *cls,
(long) cls);
GNUNET_assert (0);
}
- if ((NULL != disconnect_task) && (REOPEN != test))
+ if ((NULL != disconnect_task) && (REOPEN != test) && (DESTROY != test))
{
GNUNET_SCHEDULER_cancel (disconnect_task);
disconnect_task = GNUNET_SCHEDULER_add_delayed (short_time,
@@ -971,6 +1209,7 @@ connect_handler (void *cls,
(void *) __LINE__);
}
+
/* TODO: cannot return channel as-is, in order to unify the data handlers */
ch = GNUNET_new (struct CadetTestChannelWrapper);
ch->ch = channel;
@@ -998,6 +1237,8 @@ start_test (void *cls)
GNUNET_MQ_handler_end ()
};
struct CadetTestChannelWrapper *ch;
+ static struct GNUNET_CADET_Handle *h1;
+ static struct GNUNET_PeerIdentity *p_id;
test_task = NULL;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "start_test: %s\n", test_name);
@@ -1012,20 +1253,25 @@ start_test (void *cls)
test = SPEED;
}
+ p_id = get_from_p_ids ();
+ h1 = get_from_cadets ();
+
ch = GNUNET_new (struct CadetTestChannelWrapper);
outgoing_ch = GNUNET_CADET_channel_create (h1,
ch,
- p_id[1],
+ p_id,
&port,
NULL,
&disconnect_handler,
handlers);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "channel created\n");
ch->ch = outgoing_ch;
- disconnect_task = GNUNET_SCHEDULER_add_delayed (short_time,
- &gather_stats_and_exit,
- (void *) __LINE__);
+ if (DESTROY != test)
+ disconnect_task = GNUNET_SCHEDULER_add_delayed (short_time,
+ &gather_stats_and_exit,
+ (void *) __LINE__);
if (KEEPALIVE == test)
return; /* Don't send any data. */
@@ -1054,7 +1300,7 @@ start_test (void *cls)
/**
* Callback to be called when the requested peer information is available
*
- * @param cls the closure from GNUNET_TESTBED_peer_get_information()
+ * @param cls the closure from GNUNET_TESTBED_peer_getinformation()
* @param op the operation this callback corresponds to
* @param pinfo the result; will be NULL if the operation has failed
* @param emsg error message if the operation has failed;
@@ -1068,9 +1314,6 @@ pi_cb (void *cls,
{
long i = (long) cls;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "ID callback for %ld\n",
- i);
if ((NULL == pinfo) ||
(NULL != emsg))
{
@@ -1080,15 +1323,40 @@ pi_cb (void *cls,
abort_test (__LINE__);
return;
}
- p_id[i] = pinfo->result.id;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "id: %s\n",
- GNUNET_i2s (p_id[i]));
- p_ids++;
- if (p_ids < 2)
+
+ if (GNUNET_TESTBED_PIT_IDENTITY == pinfo->pit)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "ID callback for %ld\n",
+ i);
+ testpeer_id[i] = pinfo->result.id;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "id: %s\n",
+ GNUNET_i2s (testpeer_id[i]));
+ }
+ else if (GNUNET_TESTBED_PIT_CONFIGURATION == pinfo->pit)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "CFG callback for %ld\n",
+ i);
+ p_cfg[i] = pinfo->result.cfg;
+ }
+ else
+ {
+ GNUNET_break (0);
+ }
+
+ peerinfo_task_cnt++;
+ if (peerinfo_task_cnt < 4)
return;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Got all IDs, starting test\n");
+ "Got all peer information, starting test\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "TEST ID 0: %s\n",
+ GNUNET_i2s (testpeer_id[0]));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "TEST ID 1: %s\n",
+ GNUNET_i2s (testpeer_id[1]));
test_task = GNUNET_SCHEDULER_add_now (&start_test, NULL);
}
@@ -1115,8 +1383,8 @@ tmain (void *cls,
peers_running = num_peers;
GNUNET_assert (peers_running == peers_requested);
testbed_peers = peers;
- h1 = cadets[0];
- h2 = cadets[num_peers - 1];
+ cadets_running = cadets;
+
disconnect_task = GNUNET_SCHEDULER_add_delayed (short_time,
&disconnect_cadet_peers,
(void *) __LINE__);
@@ -1130,6 +1398,14 @@ tmain (void *cls,
GNUNET_TESTBED_PIT_IDENTITY,
&pi_cb,
(void *) 1L);
+ t_op[0] = GNUNET_TESTBED_peer_get_information (peers[0],
+ GNUNET_TESTBED_PIT_CONFIGURATION,
+ &pi_cb,
+ (void *) 0L);
+ t_op[1] = GNUNET_TESTBED_peer_get_information (peers[num_peers - 1],
+ GNUNET_TESTBED_PIT_CONFIGURATION,
+ &pi_cb,
+ (void *) 1L);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "requested peer ids\n");
}
@@ -1272,6 +1548,13 @@ main (int argc, char *argv[])
// */
ok_goal = 6;
}
+ else if (strstr (argv[0], "_destroy") != NULL)
+ {
+ test = DESTROY;
+ test_name = "destroy";
+ ok_goal = 6;
+ short_time = GNUNET_TIME_relative_multiply (short_time, 5);
+ }
else
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "UNKNOWN\n");
@@ -1286,7 +1569,7 @@ main (int argc, char *argv[])
GNUNET_asprintf (&test_name, "backwards %s", test_name);
}
- p_ids = 0;
+ peerinfo_task_cnt = 0;
ports[0] = &port;
ports[1] = NULL;
GNUNET_CADET_TEST_ruN ("test_cadet_small",
diff --git a/src/cadet/test_cadet.conf b/src/cadet/test_cadet.conf
index 30e496aff..067dd5fb4 100644
--- a/src/cadet/test_cadet.conf
+++ b/src/cadet/test_cadet.conf
@@ -27,7 +27,8 @@ QUOTA = 1 MB
DATABASE = heap
[transport]
-PLUGINS = udp
+#PLUGINS = udp
+PLUGINS = tcp
NEIGHBOUR_LIMIT = 50
#MANIPULATE_DELAY_IN = 10 ms
#MANIPULATE_DELAY_OUT = 10 ms
@@ -102,3 +103,7 @@ START_ON_DEMAND = NO
[rps]
IMMEDIATE_START = NO
START_ON_DEMAND = NO
+
+[rest]
+IMMEDIATE_START = NO
+START_ON_DEMAND = NO
diff --git a/src/conversation/test_conversation_api.c b/src/conversation/test_conversation_api.c
index 2b717367a..dbb742d91 100644
--- a/src/conversation/test_conversation_api.c
+++ b/src/conversation/test_conversation_api.c
@@ -402,7 +402,7 @@ namestore_put_cont (void *cls, int32_t success, const char *emsg)
GNUNET_assert (GNUNET_YES == success);
GNUNET_assert (NULL == emsg);
GNUNET_assert (NULL == op);
- op = GNUNET_IDENTITY_create (id, "caller-ego", &caller_ego_create_cont, NULL);
+ op = GNUNET_IDENTITY_create (id, "caller-ego", NULL, &caller_ego_create_cont, NULL);
}
@@ -483,7 +483,7 @@ run (void *cls,
cfg = c;
GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_test, NULL);
id = GNUNET_IDENTITY_connect (cfg, &identity_cb, NULL);
- op = GNUNET_IDENTITY_create (id, "phone-ego", &phone_ego_create_cont, NULL);
+ op = GNUNET_IDENTITY_create (id, "phone-ego", NULL, &phone_ego_create_cont, NULL);
ns = GNUNET_NAMESTORE_connect (cfg);
}
diff --git a/src/conversation/test_conversation_api_reject.c b/src/conversation/test_conversation_api_reject.c
index 62e4109b0..855b21fd7 100644
--- a/src/conversation/test_conversation_api_reject.c
+++ b/src/conversation/test_conversation_api_reject.c
@@ -255,7 +255,7 @@ namestore_put_cont (void *cls, int32_t success, const char *emsg)
GNUNET_assert (GNUNET_YES == success);
GNUNET_assert (NULL == emsg);
GNUNET_assert (NULL == op);
- op = GNUNET_IDENTITY_create (id, "caller-ego", &caller_ego_create_cont, NULL);
+ op = GNUNET_IDENTITY_create (id, "caller-ego", NULL, &caller_ego_create_cont, NULL);
}
@@ -336,7 +336,7 @@ run (void *cls,
cfg = c;
GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_test, NULL);
id = GNUNET_IDENTITY_connect (cfg, &identity_cb, NULL);
- op = GNUNET_IDENTITY_create (id, "phone-ego", &phone_ego_create_cont, NULL);
+ op = GNUNET_IDENTITY_create (id, "phone-ego", NULL, &phone_ego_create_cont, NULL);
ns = GNUNET_NAMESTORE_connect (cfg);
}
diff --git a/src/conversation/test_conversation_api_twocalls.c b/src/conversation/test_conversation_api_twocalls.c
index fab49f7d7..6d434a3e1 100644
--- a/src/conversation/test_conversation_api_twocalls.c
+++ b/src/conversation/test_conversation_api_twocalls.c
@@ -524,7 +524,7 @@ namestore_put_cont (void *cls, int32_t success, const char *emsg)
GNUNET_assert (GNUNET_YES == success);
GNUNET_assert (NULL == emsg);
GNUNET_assert (NULL == op);
- op = GNUNET_IDENTITY_create (id, "caller-ego", &caller_ego_create_cont, NULL);
+ op = GNUNET_IDENTITY_create (id, "caller-ego", NULL, &caller_ego_create_cont, NULL);
}
@@ -613,7 +613,7 @@ run (void *cls,
timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_test, NULL);
GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
id = GNUNET_IDENTITY_connect (cfg, &identity_cb, NULL);
- op = GNUNET_IDENTITY_create (id, "phone-ego", &phone_ego_create_cont, NULL);
+ op = GNUNET_IDENTITY_create (id, "phone-ego", NULL, &phone_ego_create_cont, NULL);
ns = GNUNET_NAMESTORE_connect (cfg);
}
diff --git a/src/dht/gnunet-service-dht_neighbours.c b/src/dht/gnunet-service-dht_neighbours.c
index c251dfa12..fce69d3f6 100644
--- a/src/dht/gnunet-service-dht_neighbours.c
+++ b/src/dht/gnunet-service-dht_neighbours.c
@@ -927,8 +927,8 @@ get_distance (const struct GNUNET_HashCode *target,
(i < sizeof(struct GNUNET_HashCode) * 8) && (i < bucket + 1 + 32 - 9);
i++)
{
- if (GNUNET_CRYPTO_hash_get_bit (target, i) !=
- GNUNET_CRYPTO_hash_get_bit (have, i))
+ if (GNUNET_CRYPTO_hash_get_bit_rtl (target, i) !=
+ GNUNET_CRYPTO_hash_get_bit_rtl (have, i))
lsb |= (1 << (bucket + 32 - 9 - i)); /* first bit set will be 10,
* last bit set will be 31 -- if
* i does not reach 512 first... */
diff --git a/src/fs/fs_api.c b/src/fs/fs_api.c
index e04a93f9c..3d2ba3e99 100644
--- a/src/fs/fs_api.c
+++ b/src/fs/fs_api.c
@@ -676,7 +676,7 @@ get_read_handle (struct GNUNET_FS_Handle *h, const char *ext, const char *ent)
fn = get_serialization_file_name (h, ext, ent);
if (NULL == fn)
return NULL;
- ret = GNUNET_BIO_read_open (fn);
+ ret = GNUNET_BIO_read_open_file (fn);
GNUNET_free (fn);
return ret;
}
@@ -699,7 +699,7 @@ get_write_handle (struct GNUNET_FS_Handle *h, const char *ext, const char *ent)
fn = get_serialization_file_name (h, ext, ent);
if (NULL == fn)
return NULL;
- ret = GNUNET_BIO_write_open (fn);
+ ret = GNUNET_BIO_write_open_file (fn);
GNUNET_break (NULL != ret);
GNUNET_free (fn);
return ret;
@@ -727,7 +727,7 @@ get_write_handle_in_dir (struct GNUNET_FS_Handle *h,
fn = get_serialization_file_name_in_dir (h, ext, uni, ent);
if (NULL == fn)
return NULL;
- ret = GNUNET_BIO_write_open (fn);
+ ret = GNUNET_BIO_write_open_file (fn);
GNUNET_free (fn);
return ret;
}
@@ -839,7 +839,7 @@ write_start_time (struct GNUNET_BIO_WriteHandle *wh,
struct GNUNET_TIME_Relative dur;
dur = GNUNET_TIME_absolute_get_duration (timestamp);
- return GNUNET_BIO_write_int64 (wh, dur.rel_value_us);
+ return GNUNET_BIO_write_int64 (wh, "start time", dur.rel_value_us);
}
@@ -863,7 +863,8 @@ read_start_time (struct GNUNET_BIO_ReadHandle *rh,
{
struct GNUNET_TIME_Relative dur;
- if (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dur.rel_value_us))
+ if (GNUNET_OK != GNUNET_BIO_read_int64 (rh, "start time",
+ (int64_t *) &dur.rel_value_us))
return GNUNET_SYSERR;
*timestamp = GNUNET_TIME_absolute_subtract (GNUNET_TIME_absolute_get (), dur);
return GNUNET_OK;
@@ -937,10 +938,22 @@ deserialize_fi_node (struct GNUNET_FS_Handle *h,
(GNUNET_OK !=
GNUNET_BIO_read_string (rh, "fn", &ret->filename, 16 * 1024)) ||
(GNUNET_OK !=
- GNUNET_BIO_read_int64 (rh, &ret->bo.expiration_time.abs_value_us)) ||
- (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &ret->bo.anonymity_level)) ||
- (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &ret->bo.content_priority)) ||
- (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &ret->bo.replication_level)))
+ GNUNET_BIO_read_int64 (
+ rh,
+ "expiration time",
+ (int64_t *) &ret->bo.expiration_time.abs_value_us)) ||
+ (GNUNET_OK != GNUNET_BIO_read_int32 (
+ rh,
+ "anonymity level",
+ (int32_t *) &ret->bo.anonymity_level)) ||
+ (GNUNET_OK != GNUNET_BIO_read_int32 (
+ rh,
+ "content priority",
+ (int32_t *) &ret->bo.content_priority)) ||
+ (GNUNET_OK != GNUNET_BIO_read_int32 (
+ rh,
+ "replication level",
+ (int32_t *) &ret->bo.replication_level)))
{
GNUNET_break (0);
goto cleanup;
@@ -948,7 +961,10 @@ deserialize_fi_node (struct GNUNET_FS_Handle *h,
switch (b)
{
case 0: /* file-insert */
- if (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size))
+ if (GNUNET_OK != GNUNET_BIO_read_int64 (
+ rh,
+ "file size",
+ (int64_t *) &ret->data.file.file_size))
{
GNUNET_break (0);
goto cleanup;
@@ -990,7 +1006,10 @@ deserialize_fi_node (struct GNUNET_FS_Handle *h,
GNUNET_break (0);
goto cleanup;
}
- if (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size))
+ if (GNUNET_OK != GNUNET_BIO_read_int64 (
+ rh,
+ "file size",
+ (int64_t *) &ret->data.file.file_size))
{
GNUNET_break (0);
goto cleanup;
@@ -1010,7 +1029,10 @@ deserialize_fi_node (struct GNUNET_FS_Handle *h,
GNUNET_break (0);
goto cleanup;
}
- if ((GNUNET_OK != GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size)) ||
+ if ((GNUNET_OK != GNUNET_BIO_read_int64 (
+ rh,
+ "file size",
+ (int64_t *) &ret->data.file.file_size)) ||
(GNUNET_OK != GNUNET_BIO_read (rh,
"fileid",
&ret->data.file.file_id,
@@ -1034,7 +1056,10 @@ deserialize_fi_node (struct GNUNET_FS_Handle *h,
GNUNET_break (0);
goto cleanup;
}
- if ((GNUNET_OK != GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size)) ||
+ if ((GNUNET_OK != GNUNET_BIO_read_int64 (
+ rh,
+ "file size",
+ (int64_t *) &ret->data.file.file_size)) ||
(GNUNET_OK != GNUNET_BIO_read (rh,
"fileid",
&ret->data.file.file_id,
@@ -1054,11 +1079,18 @@ deserialize_fi_node (struct GNUNET_FS_Handle *h,
case 4: /* directory */
ret->is_directory = GNUNET_YES;
- if ((GNUNET_OK != GNUNET_BIO_read_int32 (rh, &dsize)) ||
+ if ((GNUNET_OK != GNUNET_BIO_read_int32 (rh, "dsize",
+ (int32_t *) &dsize)) ||
(GNUNET_OK !=
- GNUNET_BIO_read_int64 (rh, &ret->data.dir.contents_completed)) ||
+ GNUNET_BIO_read_int64 (
+ rh,
+ "contents completed",
+ (int64_t *) &ret->data.dir.contents_completed)) ||
(GNUNET_OK !=
- GNUNET_BIO_read_int64 (rh, &ret->data.dir.contents_size)) ||
+ GNUNET_BIO_read_int64 (
+ rh,
+ "contents size",
+ (int64_t *) &ret->data.dir.contents_size)) ||
(NULL == (ret->data.dir.dir_data = GNUNET_malloc_large (dsize))) ||
(GNUNET_OK !=
GNUNET_BIO_read (rh, "dir-data", ret->data.dir.dir_data, dsize)) ||
@@ -1294,7 +1326,7 @@ copy_from_reader (struct GNUNET_BIO_WriteHandle *wh,
GNUNET_free (emsg);
return GNUNET_SYSERR;
}
- if (GNUNET_OK != GNUNET_BIO_write (wh, buf, ret))
+ if (GNUNET_OK != GNUNET_BIO_write (wh, "copied from reader", buf, ret))
return GNUNET_SYSERR;
off += ret;
}
@@ -1353,19 +1385,34 @@ GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *fi)
skss = GNUNET_FS_uri_to_string (fi->sks_uri);
else
skss = NULL;
- if ((GNUNET_OK != GNUNET_BIO_write (wh, &b, sizeof(b))) ||
- (GNUNET_OK != GNUNET_BIO_write_meta_data (wh, fi->meta)) ||
- (GNUNET_OK != GNUNET_BIO_write_string (wh, ksks)) ||
- (GNUNET_OK != GNUNET_BIO_write_string (wh, chks)) ||
- (GNUNET_OK != GNUNET_BIO_write_string (wh, skss)) ||
+ struct GNUNET_BIO_WriteSpec ws1[] = {
+ GNUNET_BIO_write_spec_object ("b", &b, sizeof (b)),
+ GNUNET_BIO_write_spec_meta_data ("meta", fi->meta),
+ GNUNET_BIO_write_spec_string ("ksks", ksks),
+ GNUNET_BIO_write_spec_string ("chks", chks),
+ GNUNET_BIO_write_spec_string ("skss", skss),
+ GNUNET_BIO_write_spec_end (),
+ };
+ struct GNUNET_BIO_WriteSpec ws2[] = {
+ GNUNET_BIO_write_spec_string ("emsg", fi->emsg),
+ GNUNET_BIO_write_spec_string ("filename", fi->filename),
+ GNUNET_BIO_write_spec_int64 (
+ "expiration time",
+ (int64_t *) &fi->bo.expiration_time.abs_value_us),
+ GNUNET_BIO_write_spec_int32 (
+ "anonymity level",
+ (int32_t *) &fi->bo.anonymity_level),
+ GNUNET_BIO_write_spec_int32 (
+ "content priority",
+ (int32_t *) &fi->bo.content_priority),
+ GNUNET_BIO_write_spec_int32 (
+ "replication level",
+ (int32_t *) &fi->bo.replication_level),
+ GNUNET_BIO_write_spec_end (),
+ };
+ if ((GNUNET_OK != GNUNET_BIO_write_spec_commit (wh, ws1)) ||
(GNUNET_OK != write_start_time (wh, fi->start_time)) ||
- (GNUNET_OK != GNUNET_BIO_write_string (wh, fi->emsg)) ||
- (GNUNET_OK != GNUNET_BIO_write_string (wh, fi->filename)) ||
- (GNUNET_OK !=
- GNUNET_BIO_write_int64 (wh, fi->bo.expiration_time.abs_value_us)) ||
- (GNUNET_OK != GNUNET_BIO_write_int32 (wh, fi->bo.anonymity_level)) ||
- (GNUNET_OK != GNUNET_BIO_write_int32 (wh, fi->bo.content_priority)) ||
- (GNUNET_OK != GNUNET_BIO_write_int32 (wh, fi->bo.replication_level)))
+ (GNUNET_OK != GNUNET_BIO_write_spec_commit (wh, ws2)))
{
GNUNET_break (0);
goto cleanup;
@@ -1380,7 +1427,8 @@ GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *fi)
switch (b)
{
case 0: /* file-insert */
- if (GNUNET_OK != GNUNET_BIO_write_int64 (wh, fi->data.file.file_size))
+ if (GNUNET_OK != GNUNET_BIO_write_int64 (wh, "file size",
+ fi->data.file.file_size))
{
GNUNET_break (0);
goto cleanup;
@@ -1399,7 +1447,8 @@ GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *fi)
GNUNET_break (0);
goto cleanup;
}
- if (GNUNET_OK != GNUNET_BIO_write_int64 (wh, fi->data.file.file_size))
+ if (GNUNET_OK != GNUNET_BIO_write_int64 (wh, "file size",
+ fi->data.file.file_size))
{
GNUNET_break (0);
goto cleanup;
@@ -1413,8 +1462,10 @@ GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *fi)
GNUNET_break (0);
goto cleanup;
}
- if ((GNUNET_OK != GNUNET_BIO_write_int64 (wh, fi->data.file.file_size)) ||
+ if ((GNUNET_OK != GNUNET_BIO_write_int64 (wh, "file size",
+ fi->data.file.file_size)) ||
(GNUNET_OK != GNUNET_BIO_write (wh,
+ "file id",
&fi->data.file.file_id,
sizeof(struct GNUNET_HashCode))))
{
@@ -1427,19 +1478,24 @@ GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *fi)
if ((NULL != fi->data.dir.entries) &&
(NULL == fi->data.dir.entries->serialization))
GNUNET_FS_file_information_sync_ (fi->data.dir.entries);
- if ((GNUNET_OK != GNUNET_BIO_write_int32 (wh, fi->data.dir.dir_size)) ||
- (GNUNET_OK !=
- GNUNET_BIO_write_int64 (wh, fi->data.dir.contents_completed)) ||
- (GNUNET_OK !=
- GNUNET_BIO_write_int64 (wh, fi->data.dir.contents_size)) ||
- (GNUNET_OK != GNUNET_BIO_write (wh,
- fi->data.dir.dir_data,
- (uint32_t) fi->data.dir.dir_size)) ||
- (GNUNET_OK !=
- GNUNET_BIO_write_string (wh,
- (fi->data.dir.entries == NULL)
- ? NULL
- : fi->data.dir.entries->serialization)))
+ struct GNUNET_BIO_WriteSpec ws[] = {
+ GNUNET_BIO_write_spec_int32 ("dir size",
+ (int32_t *) &fi->data.dir.dir_size),
+ GNUNET_BIO_write_spec_int64 (
+ "contents completed",
+ (int64_t *) &fi->data.dir.contents_completed),
+ GNUNET_BIO_write_spec_int64 ("contents size",
+ (int64_t *) &fi->data.dir.contents_size),
+ GNUNET_BIO_write_spec_object ("dir data",
+ fi->data.dir.dir_data,
+ (uint32_t) fi->data.dir.dir_size),
+ GNUNET_BIO_write_spec_string ("dir entries",
+ (fi->data.dir.entries == NULL)
+ ? NULL
+ : fi->data.dir.entries->serialization),
+ GNUNET_BIO_write_spec_end (),
+ };
+ if ((GNUNET_OK != GNUNET_BIO_write_spec_commit (wh, ws)))
{
GNUNET_break (0);
goto cleanup;
@@ -1453,6 +1509,7 @@ GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *fi)
if ((NULL != fi->next) && (NULL == fi->next->serialization))
GNUNET_FS_file_information_sync_ (fi->next);
if (GNUNET_OK != GNUNET_BIO_write_string (wh,
+ "serialization",
(fi->next != NULL)
? fi->next->serialization
: NULL))
@@ -1460,7 +1517,7 @@ GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *fi)
GNUNET_break (0);
goto cleanup;
}
- if (GNUNET_OK != GNUNET_BIO_write_close (wh))
+ if (GNUNET_OK != GNUNET_BIO_write_close (wh, NULL))
{
wh = NULL;
GNUNET_break (0);
@@ -1469,7 +1526,7 @@ GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *fi)
return; /* done! */
cleanup:
if (NULL != wh)
- (void) GNUNET_BIO_write_close (wh);
+ (void) GNUNET_BIO_write_close (wh, NULL);
GNUNET_free_non_null (chks);
GNUNET_free_non_null (ksks);
GNUNET_free_non_null (skss);
@@ -1586,23 +1643,23 @@ deserialize_publish_file (void *cls, const char *filename)
pc->serialization = get_serialization_short_name (filename);
fi_root = NULL;
fi_pos = NULL;
- rh = GNUNET_BIO_read_open (filename);
+ rh = GNUNET_BIO_read_open_file (filename);
if (NULL == rh)
{
GNUNET_break (0);
goto cleanup;
}
- if ((GNUNET_OK !=
- GNUNET_BIO_read_string (rh, "publish-nid", &pc->nid, 1024)) ||
- (GNUNET_OK !=
- GNUNET_BIO_read_string (rh, "publish-nuid", &pc->nuid, 1024)) ||
- (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &options)) ||
- (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &all_done)) ||
- (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &have_ns)) ||
- (GNUNET_OK !=
- GNUNET_BIO_read_string (rh, "publish-firoot", &fi_root, 128)) ||
- (GNUNET_OK !=
- GNUNET_BIO_read_string (rh, "publish-fipos", &fi_pos, 128)) ||
+ struct GNUNET_BIO_ReadSpec rs[] = {
+ GNUNET_BIO_read_spec_string ("publish-nid", &pc->nid, 1024),
+ GNUNET_BIO_read_spec_string ("publish-nuid", &pc->nuid, 1024),
+ GNUNET_BIO_read_spec_int32 ("options", &options),
+ GNUNET_BIO_read_spec_int32 ("all done", &all_done),
+ GNUNET_BIO_read_spec_int32 ("have ns", &have_ns),
+ GNUNET_BIO_read_spec_string ("publish-firoot", &fi_root, 128),
+ GNUNET_BIO_read_spec_string ("publish-fipos", &fi_pos, 128),
+ GNUNET_BIO_read_spec_end (),
+ };
+ if ((GNUNET_OK != GNUNET_BIO_read_spec_commit (rh, rs)) ||
((GNUNET_YES == have_ns) &&
(GNUNET_OK != GNUNET_BIO_read (rh, "publish-ns", &ns, sizeof(ns)))))
{
@@ -1729,26 +1786,30 @@ GNUNET_FS_publish_sync_ (struct GNUNET_FS_PublishContext *pc)
goto cleanup;
}
have_ns = (NULL != pc->ns) ? GNUNET_YES : GNUNET_NO;
- if ((GNUNET_OK != GNUNET_BIO_write_string (wh, pc->nid)) ||
- (GNUNET_OK != GNUNET_BIO_write_string (wh, pc->nuid)) ||
- (GNUNET_OK != GNUNET_BIO_write_int32 (wh, pc->options)) ||
- (GNUNET_OK != GNUNET_BIO_write_int32 (wh, pc->all_done)) ||
- (GNUNET_OK != GNUNET_BIO_write_int32 (wh, have_ns)) ||
- (GNUNET_OK != GNUNET_BIO_write_string (wh, pc->fi->serialization)) ||
- (GNUNET_OK != GNUNET_BIO_write_string (wh,
- (NULL == pc->fi_pos)
- ? NULL
- : pc->fi_pos->serialization)) ||
+ struct GNUNET_BIO_WriteSpec ws[] = {
+ GNUNET_BIO_write_spec_string ("nid", pc->nid),
+ GNUNET_BIO_write_spec_string ("nuid", pc->nuid),
+ GNUNET_BIO_write_spec_int32 ("options", (int32_t *) &pc->options),
+ GNUNET_BIO_write_spec_int32 ("all done", &pc->all_done),
+ GNUNET_BIO_write_spec_int32 ("have ns", &have_ns),
+ GNUNET_BIO_write_spec_string ("serialization", pc->fi->serialization),
+ GNUNET_BIO_write_spec_string ("pos serialization", (NULL == pc->fi_pos)
+ ? NULL
+ : pc->fi_pos->serialization),
+ GNUNET_BIO_read_spec_end ()
+ };
+ if ((GNUNET_OK != GNUNET_BIO_write_spec_commit (wh, ws)) ||
((NULL != pc->ns) &&
(GNUNET_OK !=
GNUNET_BIO_write (wh,
+ "ns",
pc->ns,
sizeof(struct GNUNET_CRYPTO_EcdsaPrivateKey)))))
{
GNUNET_break (0);
goto cleanup;
}
- if (GNUNET_OK != GNUNET_BIO_write_close (wh))
+ if (GNUNET_OK != GNUNET_BIO_write_close (wh, NULL))
{
wh = NULL;
GNUNET_break (0);
@@ -1757,7 +1818,7 @@ GNUNET_FS_publish_sync_ (struct GNUNET_FS_PublishContext *pc)
return;
cleanup:
if (NULL != wh)
- (void) GNUNET_BIO_write_close (wh);
+ (void) GNUNET_BIO_write_close (wh, NULL);
GNUNET_FS_remove_sync_file_ (pc->h,
GNUNET_FS_SYNC_PATH_MASTER_PUBLISH,
pc->serialization);
@@ -1797,25 +1858,34 @@ GNUNET_FS_unindex_sync_ (struct GNUNET_FS_UnindexContext *uc)
uris = GNUNET_FS_uri_to_string (uc->ksk_uri);
else
uris = NULL;
- if ((GNUNET_OK != GNUNET_BIO_write_string (wh, uc->filename)) ||
- (GNUNET_OK != GNUNET_BIO_write_int64 (wh, uc->file_size)) ||
+ struct GNUNET_BIO_WriteSpec ws1[] = {
+ GNUNET_BIO_write_spec_string ("filename", uc->filename),
+ GNUNET_BIO_write_spec_int64 ("file size", (int64_t *) &uc->file_size),
+ GNUNET_BIO_write_spec_end (),
+ };
+ struct GNUNET_BIO_WriteSpec ws2[] = {
+ GNUNET_BIO_write_spec_int32 ("state", (int32_t *) &uc->state),
+ GNUNET_BIO_write_spec_object ("hashkey", &uc->chk,
+ sizeof (struct ContentHashKey)),
+ GNUNET_BIO_write_spec_string ("uris", uris),
+ GNUNET_BIO_write_spec_int32 ("ksk offset", (int32_t *) &uc->ksk_offset),
+ GNUNET_BIO_write_spec_end (),
+ };
+ if ((GNUNET_OK != GNUNET_BIO_write_spec_commit (wh, ws1)) ||
(GNUNET_OK != write_start_time (wh, uc->start_time)) ||
- (GNUNET_OK != GNUNET_BIO_write_int32 (wh, (uint32_t) uc->state)) ||
- (GNUNET_OK !=
- GNUNET_BIO_write (wh, &uc->chk, sizeof(struct ContentHashKey))) ||
- (GNUNET_OK != GNUNET_BIO_write_string (wh, uris)) ||
- (GNUNET_OK != GNUNET_BIO_write_int32 (wh, (uint32_t) uc->ksk_offset)) ||
+ (GNUNET_OK != GNUNET_BIO_write_spec_commit (wh, ws2)) ||
((uc->state == UNINDEX_STATE_FS_NOTIFY) &&
(GNUNET_OK != GNUNET_BIO_write (wh,
+ "file id",
&uc->file_id,
sizeof(struct GNUNET_HashCode)))) ||
((uc->state == UNINDEX_STATE_ERROR) &&
- (GNUNET_OK != GNUNET_BIO_write_string (wh, uc->emsg))))
+ (GNUNET_OK != GNUNET_BIO_write_string (wh, "emsg", uc->emsg))))
{
GNUNET_break (0);
goto cleanup;
}
- if (GNUNET_OK != GNUNET_BIO_write_close (wh))
+ if (GNUNET_OK != GNUNET_BIO_write_close (wh, NULL))
{
wh = NULL;
GNUNET_break (0);
@@ -1824,7 +1894,7 @@ GNUNET_FS_unindex_sync_ (struct GNUNET_FS_UnindexContext *uc)
return;
cleanup:
if (NULL != wh)
- (void) GNUNET_BIO_write_close (wh);
+ (void) GNUNET_BIO_write_close (wh, NULL);
GNUNET_FS_remove_sync_file_ (uc->h,
GNUNET_FS_SYNC_PATH_MASTER_UNINDEX,
uc->serialization);
@@ -1845,15 +1915,20 @@ write_download_request (struct GNUNET_BIO_WriteHandle *wh,
struct DownloadRequest *dr)
{
unsigned int i;
-
- if ((GNUNET_OK != GNUNET_BIO_write_int32 (wh, dr->state)) ||
- (GNUNET_OK != GNUNET_BIO_write_int64 (wh, dr->offset)) ||
- (GNUNET_OK != GNUNET_BIO_write_int32 (wh, dr->num_children)) ||
- (GNUNET_OK != GNUNET_BIO_write_int32 (wh, dr->depth)))
+ struct GNUNET_BIO_WriteSpec ws[] = {
+ GNUNET_BIO_write_spec_int32 ("state", (int32_t *) &dr->state),
+ GNUNET_BIO_write_spec_int64 ("offset", (int64_t *) &dr->offset),
+ GNUNET_BIO_write_spec_int32 ("num children", (int32_t *) &dr->num_children),
+ GNUNET_BIO_write_spec_int32 ("depth", (int32_t *) &dr->depth),
+ GNUNET_BIO_write_spec_end (),
+ };
+
+ if ((GNUNET_OK != GNUNET_BIO_write_spec_commit (wh, ws)))
return GNUNET_NO;
if ((BRS_CHK_SET == dr->state) &&
(GNUNET_OK !=
- GNUNET_BIO_write (wh, &dr->chk, sizeof(struct ContentHashKey))))
+ GNUNET_BIO_write (wh, "hashkey",
+ &dr->chk, sizeof(struct ContentHashKey))))
return GNUNET_NO;
for (i = 0; i < dr->num_children; i++)
if (GNUNET_NO == write_download_request (wh, dr->children[i]))
@@ -1875,11 +1950,16 @@ read_download_request (struct GNUNET_BIO_ReadHandle *rh)
unsigned int i;
dr = GNUNET_new (struct DownloadRequest);
- if ((GNUNET_OK != GNUNET_BIO_read_int32 (rh, &dr->state)) ||
- (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dr->offset)) ||
- (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &dr->num_children)) ||
+ struct GNUNET_BIO_ReadSpec rs[] = {
+ GNUNET_BIO_read_spec_int32 ("state", (int32_t *) &dr->state),
+ GNUNET_BIO_read_spec_int64 ("offset", (int64_t *) &dr->offset),
+ GNUNET_BIO_read_spec_int32 ("num children", (int32_t *) &dr->num_children),
+ GNUNET_BIO_read_spec_end (),
+ };
+ if ((GNUNET_OK != GNUNET_BIO_read_spec_commit (rh, rs)) ||
(dr->num_children > CHK_PER_INODE) ||
- (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &dr->depth)) ||
+ (GNUNET_OK != GNUNET_BIO_read_int32 (rh, "depth",
+ (int32_t *) &dr->depth)) ||
((0 == dr->depth) && (dr->num_children > 0)) ||
((dr->depth > 0) && (0 == dr->num_children)))
{
@@ -2005,7 +2085,7 @@ GNUNET_FS_download_sync_ (struct GNUNET_FS_DownloadContext *dc)
return;
}
}
- wh = GNUNET_BIO_write_open (fn);
+ wh = GNUNET_BIO_write_open_file (fn);
if (NULL == wh)
{
GNUNET_free (dc->serialization);
@@ -2016,19 +2096,28 @@ GNUNET_FS_download_sync_ (struct GNUNET_FS_DownloadContext *dc)
GNUNET_assert ((GNUNET_YES == GNUNET_FS_uri_test_chk (dc->uri)) ||
(GNUNET_YES == GNUNET_FS_uri_test_loc (dc->uri)));
uris = GNUNET_FS_uri_to_string (dc->uri);
- if ((GNUNET_OK != GNUNET_BIO_write_string (wh, uris)) ||
- (GNUNET_OK != GNUNET_BIO_write_meta_data (wh, dc->meta)) ||
- (GNUNET_OK != GNUNET_BIO_write_string (wh, dc->emsg)) ||
- (GNUNET_OK != GNUNET_BIO_write_string (wh, dc->filename)) ||
- (GNUNET_OK != GNUNET_BIO_write_string (wh, dc->temp_filename)) ||
- (GNUNET_OK != GNUNET_BIO_write_int64 (wh, dc->old_file_size)) ||
- (GNUNET_OK != GNUNET_BIO_write_int64 (wh, dc->offset)) ||
- (GNUNET_OK != GNUNET_BIO_write_int64 (wh, dc->length)) ||
- (GNUNET_OK != GNUNET_BIO_write_int64 (wh, dc->completed)) ||
+ struct GNUNET_BIO_WriteSpec ws1[] = {
+ GNUNET_BIO_write_spec_string ("uris", uris),
+ GNUNET_BIO_write_spec_meta_data ("metadata", dc->meta),
+ GNUNET_BIO_write_spec_string ("emsg", dc->emsg),
+ GNUNET_BIO_write_spec_string ("filename", dc->filename),
+ GNUNET_BIO_write_spec_string ("temp filename", dc->temp_filename),
+ GNUNET_BIO_write_spec_int64 ("old file size",
+ (int64_t *) &dc->old_file_size),
+ GNUNET_BIO_write_spec_int64 ("offset", (int64_t *) &dc->offset),
+ GNUNET_BIO_write_spec_int64 ("length", (int64_t *) &dc->length),
+ GNUNET_BIO_write_spec_int64 ("completed", (int64_t *) &dc->completed),
+ GNUNET_BIO_write_spec_end (),
+ };
+ struct GNUNET_BIO_WriteSpec ws2[] = {
+ GNUNET_BIO_write_spec_int32 ("anonymity", (int32_t *) &dc->anonymity),
+ GNUNET_BIO_write_spec_int32 ("options", (int32_t *) &dc->options),
+ GNUNET_BIO_write_spec_int32 ("has finished", (int32_t *) &dc->has_finished),
+ GNUNET_BIO_write_spec_end (),
+ };
+ if ((GNUNET_OK != GNUNET_BIO_write_spec_commit (wh, ws1)) ||
(GNUNET_OK != write_start_time (wh, dc->start_time)) ||
- (GNUNET_OK != GNUNET_BIO_write_int32 (wh, dc->anonymity)) ||
- (GNUNET_OK != GNUNET_BIO_write_int32 (wh, (uint32_t) dc->options)) ||
- (GNUNET_OK != GNUNET_BIO_write_int32 (wh, (uint32_t) dc->has_finished)))
+ (GNUNET_OK != GNUNET_BIO_write_spec_commit (wh, ws2)))
{
GNUNET_break (0);
goto cleanup;
@@ -2044,7 +2133,7 @@ GNUNET_FS_download_sync_ (struct GNUNET_FS_DownloadContext *dc)
}
GNUNET_free_non_null (uris);
uris = NULL;
- if (GNUNET_OK != GNUNET_BIO_write_close (wh))
+ if (GNUNET_OK != GNUNET_BIO_write_close (wh, NULL))
{
wh = NULL;
GNUNET_break (0);
@@ -2054,7 +2143,7 @@ GNUNET_FS_download_sync_ (struct GNUNET_FS_DownloadContext *dc)
return;
cleanup:
if (NULL != wh)
- (void) GNUNET_BIO_write_close (wh);
+ (void) GNUNET_BIO_write_close (wh, NULL);
GNUNET_free_non_null (uris);
if (0 != unlink (fn))
GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn);
@@ -2102,23 +2191,30 @@ GNUNET_FS_search_result_sync_ (struct GNUNET_FS_SearchResult *sr)
goto cleanup;
}
uris = GNUNET_FS_uri_to_string (sr->uri);
- if ((GNUNET_OK != GNUNET_BIO_write_string (wh, uris)) ||
- (GNUNET_OK != GNUNET_BIO_write_string (wh,
- (sr->download != NULL)
- ? sr->download->serialization
- : NULL)) ||
- (GNUNET_OK !=
- GNUNET_BIO_write_string (wh,
- (sr->update_search != NULL)
- ? sr->update_search->serialization
- : NULL)) ||
- (GNUNET_OK != GNUNET_BIO_write_meta_data (wh, sr->meta)) ||
- (GNUNET_OK !=
- GNUNET_BIO_write (wh, &sr->key, sizeof(struct GNUNET_HashCode))) ||
- (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sr->mandatory_missing)) ||
- (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sr->optional_support)) ||
- (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sr->availability_success)) ||
- (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sr->availability_trials)))
+ struct GNUNET_BIO_WriteSpec ws[] = {
+ GNUNET_BIO_write_spec_string ("uris", uris),
+ GNUNET_BIO_write_spec_string ("download serialization",
+ (sr->download != NULL)
+ ? sr->download->serialization
+ : NULL),
+ GNUNET_BIO_write_spec_string ("update search serialization",
+ (sr->update_search != NULL)
+ ? sr->update_search->serialization
+ : NULL),
+ GNUNET_BIO_write_spec_meta_data ("metadata", sr->meta),
+ GNUNET_BIO_write_spec_object ("key", &sr->key,
+ sizeof(struct GNUNET_HashCode)),
+ GNUNET_BIO_write_spec_int32 ("mandatory missing",
+ (int32_t *) &sr->mandatory_missing),
+ GNUNET_BIO_write_spec_int32 ("optional support",
+ (int32_t *) &sr->optional_support),
+ GNUNET_BIO_write_spec_int32 ("availability success",
+ (int32_t *) &sr->availability_success),
+ GNUNET_BIO_write_spec_int32 ("availability trials",
+ (int32_t *) &sr->availability_trials),
+ GNUNET_BIO_write_spec_end (),
+ };
+ if ((GNUNET_OK != GNUNET_BIO_write_spec_commit (wh, ws)))
{
GNUNET_break (0);
goto cleanup;
@@ -2126,13 +2222,14 @@ GNUNET_FS_search_result_sync_ (struct GNUNET_FS_SearchResult *sr)
if ((NULL != sr->uri) && (GNUNET_FS_URI_KSK == sr->sc->uri->type) &&
(GNUNET_OK !=
GNUNET_BIO_write (wh,
+ "keyword bitmap",
sr->keyword_bitmap,
(sr->sc->uri->data.ksk.keywordCount + 7) / 8)))
{
GNUNET_break (0);
goto cleanup;
}
- if (GNUNET_OK != GNUNET_BIO_write_close (wh))
+ if (GNUNET_OK != GNUNET_BIO_write_close (wh, NULL))
{
wh = NULL;
GNUNET_break (0);
@@ -2143,7 +2240,7 @@ GNUNET_FS_search_result_sync_ (struct GNUNET_FS_SearchResult *sr)
cleanup:
GNUNET_free_non_null (uris);
if (NULL != wh)
- (void) GNUNET_BIO_write_close (wh);
+ (void) GNUNET_BIO_write_close (wh, NULL);
remove_sync_file_in_dir (sr->h,
(NULL == sr->sc->psearch_result)
? GNUNET_FS_SYNC_PATH_MASTER_SEARCH
@@ -2188,19 +2285,21 @@ GNUNET_FS_search_sync_ (struct GNUNET_FS_SearchContext *sc)
(GNUNET_YES == GNUNET_FS_uri_test_sks (sc->uri)));
uris = GNUNET_FS_uri_to_string (sc->uri);
in_pause = (sc->task != NULL) ? 'r' : '\0';
- if ((GNUNET_OK != GNUNET_BIO_write_string (wh, uris)) ||
+ if ((GNUNET_OK != GNUNET_BIO_write_string (wh, "uris", uris)) ||
(GNUNET_OK != write_start_time (wh, sc->start_time)) ||
- (GNUNET_OK != GNUNET_BIO_write_string (wh, sc->emsg)) ||
- (GNUNET_OK != GNUNET_BIO_write_int32 (wh, (uint32_t) sc->options)) ||
- (GNUNET_OK != GNUNET_BIO_write (wh, &in_pause, sizeof(in_pause))) ||
- (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sc->anonymity)))
+ (GNUNET_OK != GNUNET_BIO_write_string (wh, "emsg", sc->emsg)) ||
+ (GNUNET_OK != GNUNET_BIO_write_int32 (wh, "options",
+ (uint32_t) sc->options)) ||
+ (GNUNET_OK != GNUNET_BIO_write (wh, "in pause",
+ &in_pause, sizeof(in_pause))) ||
+ (GNUNET_OK != GNUNET_BIO_write_int32 (wh, "anonymity", sc->anonymity)))
{
GNUNET_break (0);
goto cleanup;
}
GNUNET_free (uris);
uris = NULL;
- if (GNUNET_OK != GNUNET_BIO_write_close (wh))
+ if (GNUNET_OK != GNUNET_BIO_write_close (wh, NULL))
{
wh = NULL;
GNUNET_break (0);
@@ -2209,7 +2308,7 @@ GNUNET_FS_search_sync_ (struct GNUNET_FS_SearchContext *sc)
return;
cleanup:
if (NULL != wh)
- (void) GNUNET_BIO_write_close (wh);
+ (void) GNUNET_BIO_write_close (wh, NULL);
GNUNET_free_non_null (uris);
GNUNET_FS_remove_sync_file_ (sc->h, category, sc->serialization);
GNUNET_free (sc->serialization);
@@ -2239,7 +2338,7 @@ deserialize_unindex_file (void *cls, const char *filename)
uc = GNUNET_new (struct GNUNET_FS_UnindexContext);
uc->h = h;
uc->serialization = get_serialization_short_name (filename);
- rh = GNUNET_BIO_read_open (filename);
+ rh = GNUNET_BIO_read_open_file (filename);
if (NULL == rh)
{
GNUNET_break (0);
@@ -2248,14 +2347,17 @@ deserialize_unindex_file (void *cls, const char *filename)
uris = NULL;
if ((GNUNET_OK !=
GNUNET_BIO_read_string (rh, "unindex-fn", &uc->filename, 10 * 1024)) ||
- (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &uc->file_size)) ||
+ (GNUNET_OK != GNUNET_BIO_read_int64 (rh, "file size",
+ (int64_t *) &uc->file_size)) ||
(GNUNET_OK != read_start_time (rh, &uc->start_time)) ||
- (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &state)) ||
+ (GNUNET_OK != GNUNET_BIO_read_int32 (rh, "state",
+ (int32_t *) &state)) ||
(GNUNET_OK !=
GNUNET_BIO_read (rh, "uri", &uc->chk, sizeof(struct ContentHashKey))) ||
(GNUNET_OK !=
GNUNET_BIO_read_string (rh, "unindex-kskuri", &uris, 10 * 1024)) ||
- (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &uc->ksk_offset)))
+ (GNUNET_OK != GNUNET_BIO_read_int32 (rh, "ksk offset",
+ (int32_t *) &uc->ksk_offset)))
{
GNUNET_free_non_null (uris);
GNUNET_break (0);
@@ -2443,7 +2545,7 @@ deserialize_search_result (void *cls, const char *filename)
struct GNUNET_FS_SearchResult *sr;
ser = get_serialization_short_name (filename);
- rh = GNUNET_BIO_read_open (filename);
+ rh = GNUNET_BIO_read_open_file (filename);
if (NULL == rh)
{
if (NULL != ser)
@@ -2478,10 +2580,22 @@ deserialize_search_result (void *cls, const char *filename)
"result-key",
&sr->key,
sizeof(struct GNUNET_HashCode))) ||
- (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sr->mandatory_missing)) ||
- (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sr->optional_support)) ||
- (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sr->availability_success)) ||
- (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sr->availability_trials)))
+ (GNUNET_OK != GNUNET_BIO_read_int32 (
+ rh,
+ "mandatory missing",
+ (int32_t *) &sr->mandatory_missing)) ||
+ (GNUNET_OK != GNUNET_BIO_read_int32 (
+ rh,
+ "optional support",
+ (int32_t *) &sr->optional_support)) ||
+ (GNUNET_OK != GNUNET_BIO_read_int32 (
+ rh,
+ "availability success",
+ (int32_t *) &sr->availability_success)) ||
+ (GNUNET_OK != GNUNET_BIO_read_int32 (
+ rh,
+ "availability trials",
+ (int32_t *) &sr->availability_trials)))
{
GNUNET_break (0);
goto cleanup;
@@ -2741,7 +2855,7 @@ deserialize_subdownload (void *cls, const char *filename)
struct GNUNET_BIO_ReadHandle *rh;
ser = get_serialization_short_name (filename);
- rh = GNUNET_BIO_read_open (filename);
+ rh = GNUNET_BIO_read_open_file (filename);
if (NULL == rh)
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -2827,29 +2941,35 @@ deserialize_download (struct GNUNET_FS_Handle *h,
dc->parent = parent;
dc->h = h;
dc->serialization = GNUNET_strdup (serialization);
+ struct GNUNET_BIO_ReadSpec rs[] = {
+ GNUNET_BIO_read_spec_meta_data ("download-meta", &dc->meta),
+ GNUNET_BIO_read_spec_string ("download-emsg", &dc->emsg, 10 * 1024),
+ GNUNET_BIO_read_spec_string ("download-fn", &dc->filename, 10 * 1024),
+ GNUNET_BIO_read_spec_string ("download-tfn",
+ &dc->temp_filename, 10 * 1024),
+ GNUNET_BIO_read_spec_int64 ("old file size",
+ (int64_t *) &dc->old_file_size),
+ GNUNET_BIO_read_spec_int64 ("offset",
+ (int64_t *) &dc->offset),
+ GNUNET_BIO_read_spec_int64 ("length",
+ (int64_t *) &dc->length),
+ GNUNET_BIO_read_spec_int64 ("completed",
+ (int64_t *) &dc->completed),
+ GNUNET_BIO_read_spec_end (),
+ };
if ((GNUNET_OK !=
GNUNET_BIO_read_string (rh, "download-uri", &uris, 10 * 1024)) ||
(NULL == (dc->uri = GNUNET_FS_uri_parse (uris, &emsg))) ||
((GNUNET_YES != GNUNET_FS_uri_test_chk (dc->uri)) &&
(GNUNET_YES != GNUNET_FS_uri_test_loc (dc->uri))) ||
- (GNUNET_OK !=
- GNUNET_BIO_read_meta_data (rh, "download-meta", &dc->meta)) ||
- (GNUNET_OK !=
- GNUNET_BIO_read_string (rh, "download-emsg", &dc->emsg, 10 * 1024)) ||
- (GNUNET_OK !=
- GNUNET_BIO_read_string (rh, "download-fn", &dc->filename, 10 * 1024)) ||
- (GNUNET_OK != GNUNET_BIO_read_string (rh,
- "download-tfn",
- &dc->temp_filename,
- 10 * 1024)) ||
- (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dc->old_file_size)) ||
- (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dc->offset)) ||
- (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dc->length)) ||
- (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dc->completed)) ||
+ (GNUNET_OK != GNUNET_BIO_read_spec_commit (rh, rs)) ||
(GNUNET_OK != read_start_time (rh, &dc->start_time)) ||
- (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &dc->anonymity)) ||
- (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &options)) ||
- (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &status)))
+ (GNUNET_OK != GNUNET_BIO_read_int32 (rh, "anonymity",
+ (int32_t *) &dc->anonymity)) ||
+ (GNUNET_OK != GNUNET_BIO_read_int32 (rh, "options",
+ (int32_t *) &options)) ||
+ (GNUNET_OK != GNUNET_BIO_read_int32 (rh, "status",
+ (int32_t *) &status)))
{
GNUNET_break (0);
goto cleanup;
@@ -2972,10 +3092,12 @@ deserialize_search (struct GNUNET_FS_Handle *h,
(GNUNET_OK != read_start_time (rh, &sc->start_time)) ||
(GNUNET_OK !=
GNUNET_BIO_read_string (rh, "search-emsg", &sc->emsg, 10 * 1024)) ||
- (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &options)) ||
+ (GNUNET_OK != GNUNET_BIO_read_int32 (rh, "options",
+ (int32_t *) &options)) ||
(GNUNET_OK !=
GNUNET_BIO_read (rh, "search-pause", &in_pause, sizeof(in_pause))) ||
- (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sc->anonymity)))
+ (GNUNET_OK != GNUNET_BIO_read_int32 (rh, "anonymity",
+ (int32_t *) &sc->anonymity)))
{
GNUNET_break (0);
goto cleanup;
@@ -3038,7 +3160,7 @@ deserialize_search_file (void *cls, const char *filename)
if (S_ISDIR (buf.st_mode))
return GNUNET_OK; /* skip directories */
ser = get_serialization_short_name (filename);
- rh = GNUNET_BIO_read_open (filename);
+ rh = GNUNET_BIO_read_open_file (filename);
if (NULL == rh)
{
if (NULL != ser)
@@ -3081,7 +3203,7 @@ deserialize_download_file (void *cls, const char *filename)
struct GNUNET_BIO_ReadHandle *rh;
ser = get_serialization_short_name (filename);
- rh = GNUNET_BIO_read_open (filename);
+ rh = GNUNET_BIO_read_open_file (filename);
if (NULL == rh)
{
if (0 != unlink (filename))
diff --git a/src/fs/fs_namespace.c b/src/fs/fs_namespace.c
index 6ede02afd..f098032d7 100644
--- a/src/fs/fs_namespace.c
+++ b/src/fs/fs_namespace.c
@@ -195,7 +195,7 @@ write_update_information_graph (struct GNUNET_FS_UpdateInformationGraph *uig)
char *uris;
fn = get_update_information_directory (uig->h, &uig->ns);
- wh = GNUNET_BIO_write_open (fn);
+ wh = GNUNET_BIO_write_open_file (fn);
if (NULL == wh)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -205,16 +205,22 @@ write_update_information_graph (struct GNUNET_FS_UpdateInformationGraph *uig)
GNUNET_free (fn);
return;
}
- if (GNUNET_OK != GNUNET_BIO_write_int32 (wh, uig->update_node_count))
+ if (GNUNET_OK != GNUNET_BIO_write_int32 (wh,
+ "fs-namespace-node-count",
+ uig->update_node_count))
goto END;
for (i = 0; i < uig->update_node_count; i++)
{
n = uig->update_nodes[i];
uris = GNUNET_FS_uri_to_string (n->uri);
- if ((GNUNET_OK != GNUNET_BIO_write_string (wh, n->id)) ||
- (GNUNET_OK != GNUNET_BIO_write_meta_data (wh, n->md)) ||
- (GNUNET_OK != GNUNET_BIO_write_string (wh, n->update)) ||
- (GNUNET_OK != GNUNET_BIO_write_string (wh, uris)))
+ struct GNUNET_BIO_WriteSpec ws[] = {
+ GNUNET_BIO_write_spec_string("fs-namespace-node-id", n->id),
+ GNUNET_BIO_write_spec_meta_data("fs-namespace-node-meta", n->md),
+ GNUNET_BIO_write_spec_string("fs-namespace-node-update", n->update),
+ GNUNET_BIO_write_spec_string("fs-namespace-uris", uris),
+ GNUNET_BIO_write_spec_end(),
+ };
+ if (GNUNET_OK != GNUNET_BIO_write_spec_commit(wh, ws))
{
GNUNET_free (uris);
break;
@@ -222,7 +228,7 @@ write_update_information_graph (struct GNUNET_FS_UpdateInformationGraph *uig)
GNUNET_free (uris);
}
END:
- if (GNUNET_OK != GNUNET_BIO_write_close (wh))
+ if (GNUNET_OK != GNUNET_BIO_write_close (wh, NULL))
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_ ("Failed to write `%s': %s\n"),
fn,
@@ -260,13 +266,14 @@ read_update_information_graph (struct GNUNET_FS_Handle *h,
GNUNET_free (fn);
return uig;
}
- rh = GNUNET_BIO_read_open (fn);
+ rh = GNUNET_BIO_read_open_file (fn);
if (NULL == rh)
{
GNUNET_free (fn);
return uig;
}
- if (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &count))
+ if (GNUNET_OK != GNUNET_BIO_read_int32 (rh, "fs-namespace-count",
+ (int32_t *) &count))
{
GNUNET_break (0);
goto END;
@@ -284,12 +291,14 @@ read_update_information_graph (struct GNUNET_FS_Handle *h,
for (i = 0; i < count; i++)
{
n = GNUNET_new (struct NamespaceUpdateNode);
- if ((GNUNET_OK !=
- GNUNET_BIO_read_string (rh, "identifier", &n->id, 1024)) ||
- (GNUNET_OK != GNUNET_BIO_read_meta_data (rh, "meta", &n->md)) ||
- (GNUNET_OK !=
- GNUNET_BIO_read_string (rh, "update-id", &n->update, 1024)) ||
- (GNUNET_OK != GNUNET_BIO_read_string (rh, "uri", &uris, 1024 * 2)))
+ struct GNUNET_BIO_ReadSpec rs[] = {
+ GNUNET_BIO_read_spec_string("identifier", &n->id, 1024),
+ GNUNET_BIO_read_spec_meta_data("meta", &n->md),
+ GNUNET_BIO_read_spec_string("update-id", &n->update, 1024),
+ GNUNET_BIO_read_spec_string("uri", &uris, 1024 * 2),
+ GNUNET_BIO_read_spec_end(),
+ };
+ if (GNUNET_OK != GNUNET_BIO_read_spec_commit (rh, rs))
{
GNUNET_break (0);
GNUNET_free_non_null (n->id);
diff --git a/src/fs/gnunet-auto-share.c b/src/fs/gnunet-auto-share.c
index 13bc908e8..3aed0268b 100644
--- a/src/fs/gnunet-auto-share.c
+++ b/src/fs/gnunet-auto-share.c
@@ -190,18 +190,22 @@ load_state ()
emsg = NULL;
fn = get_state_file ();
- rh = GNUNET_BIO_read_open (fn);
+ rh = GNUNET_BIO_read_open_file (fn);
GNUNET_free (fn);
if (NULL == rh)
return;
fn = NULL;
- if (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &n))
+ if (GNUNET_OK != GNUNET_BIO_read_int32 (rh, "number of files",
+ (int32_t *) &n))
goto error;
while (n-- > 0)
{
- if ((GNUNET_OK != GNUNET_BIO_read_string (rh, "filename", &fn, 1024)) ||
- (GNUNET_OK !=
- GNUNET_BIO_read (rh, "id", &id, sizeof(struct GNUNET_HashCode))))
+ struct GNUNET_BIO_ReadSpec rs[] = {
+ GNUNET_BIO_read_spec_string("filename", &fn, 1024),
+ GNUNET_BIO_read_spec_object("id", &id, sizeof(struct GNUNET_HashCode)),
+ GNUNET_BIO_read_spec_end(),
+ };
+ if (GNUNET_OK != GNUNET_BIO_read_spec_commit (rh, rs))
goto error;
wi = GNUNET_new (struct WorkItem);
wi->id = id;
@@ -251,9 +255,13 @@ write_item (void *cls, const struct GNUNET_HashCode *key, void *value)
"Saving serialization ID of file `%s' with value `%s'\n",
wi->filename,
GNUNET_h2s (&wi->id));
- if ((GNUNET_OK != GNUNET_BIO_write_string (wh, wi->filename)) ||
- (GNUNET_OK !=
- GNUNET_BIO_write (wh, &wi->id, sizeof(struct GNUNET_HashCode))))
+ struct GNUNET_BIO_WriteSpec ws[] = {
+ GNUNET_BIO_write_spec_string ("auto-share-write-item-filename",
+ wi->filename),
+ GNUNET_BIO_write_spec_object ("id", &wi->id, sizeof(struct GNUNET_HashCode)),
+ GNUNET_BIO_write_spec_end (),
+ };
+ if (GNUNET_OK != GNUNET_BIO_write_spec_commit (wh, ws))
return GNUNET_SYSERR; /* write error, abort iteration */
return GNUNET_OK;
}
@@ -271,7 +279,7 @@ save_state ()
n = GNUNET_CONTAINER_multihashmap_size (work_finished);
fn = get_state_file ();
- wh = GNUNET_BIO_write_open (fn);
+ wh = GNUNET_BIO_write_open_file (fn);
if (NULL == wh)
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -280,9 +288,9 @@ save_state ()
GNUNET_free (fn);
return;
}
- if (GNUNET_OK != GNUNET_BIO_write_int32 (wh, n))
+ if (GNUNET_OK != GNUNET_BIO_write_int32 (wh, "size of state", n))
{
- (void) GNUNET_BIO_write_close (wh);
+ (void) GNUNET_BIO_write_close (wh, NULL);
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
_ ("Failed to save state to file %s\n"),
fn);
@@ -290,7 +298,7 @@ save_state ()
return;
}
(void) GNUNET_CONTAINER_multihashmap_iterate (work_finished, &write_item, wh);
- if (GNUNET_OK != GNUNET_BIO_write_close (wh))
+ if (GNUNET_OK != GNUNET_BIO_write_close (wh, NULL))
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
_ ("Failed to save state to file %s\n"),
fn);
diff --git a/src/fs/gnunet-service-fs_indexing.c b/src/fs/gnunet-service-fs_indexing.c
index 98fca3ec5..f4d560176 100644
--- a/src/fs/gnunet-service-fs_indexing.c
+++ b/src/fs/gnunet-service-fs_indexing.c
@@ -123,7 +123,7 @@ write_index_list ()
"INDEXDB");
return;
}
- wh = GNUNET_BIO_write_open (fn);
+ wh = GNUNET_BIO_write_open_file (fn);
if (NULL == wh)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
@@ -134,11 +134,14 @@ write_index_list ()
}
for (pos = indexed_files_head; NULL != pos; pos = pos->next)
if ((GNUNET_OK != GNUNET_BIO_write (wh,
+ "fs-indexing-file-id",
&pos->file_id,
sizeof(struct GNUNET_HashCode))) ||
- (GNUNET_OK != GNUNET_BIO_write_string (wh, pos->filename)))
+ (GNUNET_OK != GNUNET_BIO_write_string (wh,
+ "fs-indexing-filename",
+ pos->filename)))
break;
- if (GNUNET_OK != GNUNET_BIO_write_close (wh))
+ if (GNUNET_OK != GNUNET_BIO_write_close (wh, NULL))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
_ ("Error writing `%s'.\n"),
@@ -178,7 +181,7 @@ read_index_list ()
GNUNET_free (fn);
return;
}
- rh = GNUNET_BIO_read_open (fn);
+ rh = GNUNET_BIO_read_open_file (fn);
if (NULL == rh)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
diff --git a/src/gns/Makefile.am b/src/gns/Makefile.am
index 7a5f7cfd8..5a9c70997 100644
--- a/src/gns/Makefile.am
+++ b/src/gns/Makefile.am
@@ -55,7 +55,6 @@ lib_LTLIBRARIES = \
libgnunetgns.la
-if HAVE_MHD
if HAVE_GNUTLS
if HAVE_LIBGNURL
DO_PROXY=gnunet-gns-proxy
@@ -69,7 +68,6 @@ CPP_GNURL=@LIBCURL_CPPFLAGS@
endif
endif
endif
-endif
libexec_PROGRAMS = \
gnunet-service-gns \
@@ -82,15 +80,11 @@ bin_PROGRAMS = \
noinst_PROGRAMS = \
gnunet-gns-benchmark
-if HAVE_MHD
if LINUX
bin_PROGRAMS += gnunet-bcd
endif
-endif
-if HAVE_REST
REST_PLUGIN = libgnunet_plugin_rest_gns.la
-endif
plugin_LTLIBRARIES = \
libgnunet_plugin_block_gns.la \
@@ -258,14 +252,12 @@ libgnunet_plugin_block_gns_la_LDFLAGS = \
$(GN_LIBINTL) \
$(GN_PLUGIN_LDFLAGS)
-if HAVE_MHD
if HAVE_GNUTLS
if HAVE_LIBGNURL
check_PROGRAMS = \
test_gns_proxy
endif
endif
-endif
check_SCRIPTS = \
test_gns_lookup.sh \
@@ -286,18 +278,14 @@ check_SCRIPTS = \
test_gns_revocation.sh\
test_gns_cname_lookup.sh
-if HAVE_MHD
if HAVE_GNUTLS
if HAVE_LIBGNURL
check_SCRIPTS += \
test_proxy.sh
endif
endif
-if HAVE_JSON
check_SCRIPTS += \
test_plugin_rest_gns.sh
-endif
-endif
if ENABLE_TEST_RUN
diff --git a/src/gnsrecord/gnunet-gnsrecord-tvg.c b/src/gnsrecord/gnunet-gnsrecord-tvg.c
index cf815d629..789ff8aa3 100644
--- a/src/gnsrecord/gnunet-gnsrecord-tvg.c
+++ b/src/gnsrecord/gnunet-gnsrecord-tvg.c
@@ -37,34 +37,41 @@
#define TEST_RRCOUNT 2
static void
-print_record(const struct GNUNET_GNSRECORD_Data *rd)
+print_bytes (void *buf,
+ size_t buf_len,
+ int fold)
{
- char *data_enc;
- char *string_v;
- string_v = GNUNET_GNSRECORD_value_to_string (rd->record_type,
- rd->data,
- rd->data_size);
- fprintf (stdout,
- "EXPIRATION: %"PRIu64"\n", rd->expiration_time);
+ int i;
+
+ for (i = 0; i < buf_len; i++)
+ {
+ if ((0 != i) && (0 != fold) && (i % fold == 0))
+ printf ("\n");
+ printf ("%02x", ((unsigned char*) buf)[i]);
+ }
+ printf ("\n");
+}
+
+
+static void
+print_record (const struct GNUNET_GNSRECORD_Data *rd)
+{
+
fprintf (stdout,
- "DATA_SIZE: %"PRIu64"\n", rd->data_size);
+ "EXPIRATION: %" PRIu64 "\n", rd->expiration_time);
+ fprintf (stdout,
+ "DATA_SIZE: %zu\n", rd->data_size);
fprintf (stdout,
"TYPE: %d\n", rd->record_type);
fprintf (stdout,
"FLAGS: %d\n", rd->flags);
- GNUNET_STRINGS_base64_encode (rd->data,
- rd->data_size,
- &data_enc);
- fprintf (stdout,
- "DATA (base64):\n%s\n",
- data_enc);
fprintf (stdout,
- "DATA (Human readable):\n%s\n\n", string_v);
- GNUNET_free (string_v);
-
- GNUNET_free (data_enc);
+ "DATA:\n");
+ print_bytes ((char*) rd->data, rd->data_size, 8);
+ fprintf (stdout, "\n");
}
+
/**
* Main function that will be run.
*
@@ -80,7 +87,7 @@ run (void *cls,
const struct GNUNET_CONFIGURATION_Handle *cfg)
{
struct GNUNET_GNSRECORD_Data rd[2];
- struct GNUNET_TIME_Absolute exp_abs = GNUNET_TIME_absolute_get();
+ struct GNUNET_TIME_Absolute exp_abs = GNUNET_TIME_absolute_get ();
struct GNUNET_GNSRECORD_Block *rrblock;
char *bdata;
struct GNUNET_CRYPTO_EcdsaPrivateKey id_priv;
@@ -91,22 +98,16 @@ run (void *cls,
size_t data_size;
char *rdata;
size_t rdata_size;
- char* data_enc;
GNUNET_CRYPTO_ecdsa_key_create (&id_priv);
GNUNET_CRYPTO_ecdsa_key_get_public (&id_priv,
&id_pub);
- GNUNET_STRINGS_base64_encode (&id_priv,
- sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey),
- &data_enc);
- fprintf(stdout, "Zone private key (d):\n%s\n", data_enc);
- GNUNET_free (data_enc);
- GNUNET_STRINGS_base64_encode (&id_pub,
- sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey),
- &data_enc);
- fprintf(stdout, "Zone public key (zk):\n%s\n", data_enc);
- GNUNET_free (data_enc);
-
+ fprintf (stdout, "Zone private key (d, little-endian scalar):\n");
+ print_bytes (&id_priv, sizeof(id_priv), 0);
+ fprintf (stdout, "\n");
+ fprintf (stdout, "Zone public key (zk):\n");
+ print_bytes (&id_pub, sizeof(id_pub), 0);
+ fprintf (stdout, "\n");
GNUNET_CRYPTO_ecdsa_key_create (&pkey_data_p);
GNUNET_CRYPTO_ecdsa_key_get_public (&pkey_data_p,
@@ -114,7 +115,8 @@ run (void *cls,
fprintf (stdout,
"Label: %s\nRRCOUNT: %d\n\n", TEST_RECORD_LABEL, TEST_RRCOUNT);
memset (rd, 0, sizeof (struct GNUNET_GNSRECORD_Data) * 2);
- GNUNET_assert (GNUNET_OK == GNUNET_GNSRECORD_string_to_value (GNUNET_DNSPARSER_TYPE_A, TEST_RECORD_A, &data, &data_size));
+ GNUNET_assert (GNUNET_OK == GNUNET_GNSRECORD_string_to_value (
+ GNUNET_DNSPARSER_TYPE_A, TEST_RECORD_A, &data, &data_size));
rd[0].data = data;
rd[0].data_size = data_size;
rd[0].expiration_time = exp_abs.abs_value_us;
@@ -137,34 +139,28 @@ run (void *cls,
rd,
rdata_size,
rdata);
- GNUNET_STRINGS_base64_encode (rdata,
- rdata_size,
- &data_enc);
- fprintf(stdout, "RDATA:\n%s\n\n", data_enc);
- GNUNET_free (data_enc);
+ fprintf (stdout, "RDATA:\n");
+ print_bytes (rdata, rdata_size, 8);
+ fprintf (stdout, "\n");
rrblock = GNUNET_GNSRECORD_block_create (&id_priv,
- exp_abs,
- TEST_RECORD_LABEL,
- rd,
- TEST_RRCOUNT);
- size_t bdata_size = ntohl (rrblock->purpose.size) -
- sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) -
- sizeof(struct GNUNET_TIME_AbsoluteNBO);
- size_t rrblock_size = ntohl (rrblock->purpose.size) +
- sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey) +
- sizeof(struct GNUNET_CRYPTO_EcdsaSignature);
-
- bdata = (char*)&rrblock[1];
- GNUNET_STRINGS_base64_encode (bdata,
- bdata_size,
- &data_enc);
- fprintf(stdout, "BDATA:\n%s\n\n", data_enc);
- GNUNET_free (data_enc);
- GNUNET_STRINGS_base64_encode (rrblock,
- rrblock_size,
- &data_enc);
- fprintf(stdout, "RRBLOCK:\n%s\n", data_enc);
- GNUNET_free (data_enc);
+ exp_abs,
+ TEST_RECORD_LABEL,
+ rd,
+ TEST_RRCOUNT);
+ size_t bdata_size = ntohl (rrblock->purpose.size)
+ - sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose)
+ - sizeof(struct GNUNET_TIME_AbsoluteNBO);
+ size_t rrblock_size = ntohl (rrblock->purpose.size)
+ + sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)
+ + sizeof(struct GNUNET_CRYPTO_EcdsaSignature);
+
+ bdata = (char*) &rrblock[1];
+ fprintf (stdout, "BDATA:\n");
+ print_bytes (bdata, bdata_size, 8);
+ fprintf (stdout, "\n");
+ fprintf (stdout, "RRBLOCK:\n");
+ print_bytes (rrblock, rrblock_size, 8);
+ fprintf (stdout, "\n");
}
diff --git a/src/hostlist/Makefile.am b/src/hostlist/Makefile.am
index a8621a2b0..3b534de70 100644
--- a/src/hostlist/Makefile.am
+++ b/src/hostlist/Makefile.am
@@ -10,12 +10,10 @@ if USE_COVERAGE
AM_CFLAGS = --coverage -O0
endif
-if HAVE_MHD
HOSTLIST_SERVER_SOURCES = \
gnunet-daemon-hostlist_server.c gnunet-daemon-hostlist_server.h
GN_LIBMHD = $(MHD_LIBS)
GN_CPPMHD = $(MHD_CFLAGS)
-endif
if HAVE_LIBGNURL
libexec_PROGRAMS = \
@@ -70,13 +68,11 @@ check_PROGRAMS = \
endif
endif
-if HAVE_MHD
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
-endif
test_gnunet_daemon_hostlist_SOURCES = \
test_gnunet_daemon_hostlist.c
diff --git a/src/hostlist/gnunet-daemon-hostlist.c b/src/hostlist/gnunet-daemon-hostlist.c
index 704c796b4..54e070f89 100644
--- a/src/hostlist/gnunet-daemon-hostlist.c
+++ b/src/hostlist/gnunet-daemon-hostlist.c
@@ -30,8 +30,6 @@
#include "gnunet_protocols.h"
#include "gnunet_statistics_service.h"
-#if HAVE_MHD
-
#include "gnunet-daemon-hostlist_server.h"
/**
@@ -49,8 +47,6 @@ static int provide_hostlist;
*/
static GNUNET_CORE_ConnectEventHandler server_ch;
-#endif
-
/**
* Set if we are allowed to learn about peers by accessing
* hostlist servers.
@@ -211,13 +207,11 @@ connect_handler (void *cls,
(*client_ch)(cls,
peer,
mq));
-#if HAVE_MHD
if (NULL != server_ch)
GNUNET_assert (NULL ==
(*server_ch)(cls,
peer,
mq));
-#endif
return (void *) peer;
}
@@ -265,12 +259,10 @@ cleaning_task (void *cls)
{
GNUNET_HOSTLIST_client_stop ();
}
-#if HAVE_MHD
if (provide_hostlist)
{
GNUNET_HOSTLIST_server_stop ();
}
-#endif
if (NULL != stats)
{
GNUNET_STATISTICS_destroy (stats,
@@ -306,9 +298,7 @@ run (void *cls,
};
if ((! bootstrapping) && (! learning)
-#if HAVE_MHD
&& (! provide_hostlist)
-#endif
)
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -338,14 +328,12 @@ run (void *cls,
learning ? learn_handlers : no_learn_handlers);
-#if HAVE_MHD
if (provide_hostlist)
GNUNET_HOSTLIST_server_start (cfg,
stats,
core,
&server_ch,
advertising);
-#endif
GNUNET_SCHEDULER_add_shutdown (&cleaning_task,
NULL);
@@ -370,13 +358,11 @@ int
main (int argc, char *const *argv)
{
struct GNUNET_GETOPT_CommandLineOption options[] = {
-#if HAVE_MHD
GNUNET_GETOPT_option_flag ('a',
"advertise",
gettext_noop (
"advertise our hostlist to other peers"),
&advertising),
-#endif
GNUNET_GETOPT_option_flag ('b',
"bootstrap",
gettext_noop (
@@ -387,12 +373,10 @@ main (int argc, char *const *argv)
gettext_noop (
"enable learning about hostlist servers from other peers"),
&learning),
-#if HAVE_MHD
GNUNET_GETOPT_option_flag ('p',
"provide-hostlist",
gettext_noop ("provide a hostlist server"),
&provide_hostlist),
-#endif
GNUNET_GETOPT_OPTION_END
};
diff --git a/src/hostlist/gnunet-daemon-hostlist_client.c b/src/hostlist/gnunet-daemon-hostlist_client.c
index a5ff9f9fa..c2e8f5d88 100644
--- a/src/hostlist/gnunet-daemon-hostlist_client.c
+++ b/src/hostlist/gnunet-daemon-hostlist_client.c
@@ -1404,7 +1404,7 @@ load_hostlist_file ()
return;
}
- rh = GNUNET_BIO_read_open (filename);
+ rh = GNUNET_BIO_read_open_file (filename);
if (NULL == rh)
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
@@ -1417,13 +1417,17 @@ load_hostlist_file ()
}
counter = 0;
+ struct GNUNET_BIO_ReadSpec rs[] = {
+ GNUNET_BIO_read_spec_int32 ("times used", (int32_t *)&times_used),
+ GNUNET_BIO_read_spec_int64 ("quality", (int64_t *) &quality),
+ GNUNET_BIO_read_spec_int64 ("last used", (int64_t *) &last_used),
+ GNUNET_BIO_read_spec_int64 ("created", (int64_t *) &created),
+ GNUNET_BIO_read_spec_int32 ("hellos returned", (int32_t *) &hellos_returned),
+ GNUNET_BIO_read_spec_end (),
+ };
while ((GNUNET_OK == GNUNET_BIO_read_string (rh, "url", &uri, MAX_URL_LEN)) &&
(NULL != uri) &&
- (GNUNET_OK == GNUNET_BIO_read_int32 (rh, &times_used)) &&
- (GNUNET_OK == GNUNET_BIO_read_int64 (rh, &quality)) &&
- (GNUNET_OK == GNUNET_BIO_read_int64 (rh, &last_used)) &&
- (GNUNET_OK == GNUNET_BIO_read_int64 (rh, &created)) &&
- (GNUNET_OK == GNUNET_BIO_read_int32 (rh, &hellos_returned)))
+ (GNUNET_OK == GNUNET_BIO_read_spec_commit (rh, rs)))
{
hostlist = GNUNET_malloc (sizeof(struct Hostlist) + strlen (uri) + 1);
hostlist->hello_count = hellos_returned;
@@ -1494,7 +1498,7 @@ save_hostlist_file (int shutdown)
GNUNET_free (filename);
return;
}
- wh = GNUNET_BIO_write_open (filename);
+ wh = GNUNET_BIO_write_open_file (filename);
if (NULL == wh)
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -1521,14 +1525,21 @@ save_hostlist_file (int shutdown)
}
if (GNUNET_YES == ok)
{
- if ((GNUNET_OK != GNUNET_BIO_write_string (wh, pos->hostlist_uri)) ||
- (GNUNET_OK != GNUNET_BIO_write_int32 (wh, pos->times_used)) ||
- (GNUNET_OK != GNUNET_BIO_write_int64 (wh, pos->quality)) ||
- (GNUNET_OK !=
- GNUNET_BIO_write_int64 (wh, pos->time_last_usage.abs_value_us)) ||
- (GNUNET_OK !=
- GNUNET_BIO_write_int64 (wh, pos->time_creation.abs_value_us)) ||
- (GNUNET_OK != GNUNET_BIO_write_int32 (wh, pos->hello_count)))
+ struct GNUNET_BIO_WriteSpec ws[] = {
+ GNUNET_BIO_write_spec_string ("hostlist uri", pos->hostlist_uri),
+ GNUNET_BIO_write_spec_int32 ("times used", (int32_t *) &pos->times_used),
+ GNUNET_BIO_write_spec_int64 ("quality", (int64_t *) &pos->quality),
+ GNUNET_BIO_write_spec_int64 (
+ "last usage",
+ (int64_t *) &pos->time_last_usage.abs_value_us),
+ GNUNET_BIO_write_spec_int64 (
+ "creation time",
+ (int64_t *) &pos->time_creation.abs_value_us),
+ GNUNET_BIO_write_spec_int32 ("hellos count",
+ (int32_t *) &pos->hello_count),
+ GNUNET_BIO_write_spec_end (),
+ };
+ if ((GNUNET_OK != GNUNET_BIO_write_spec_commit (wh, ws)))
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
_ ("Error writing hostlist URIs to file `%s'\n"),
@@ -1548,7 +1559,7 @@ save_hostlist_file (int shutdown)
counter,
GNUNET_YES);
- if (GNUNET_OK != GNUNET_BIO_write_close (wh))
+ if (GNUNET_OK != GNUNET_BIO_write_close (wh, NULL))
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
_ ("Error writing hostlist URIs to file `%s'\n"),
filename);
diff --git a/src/identity/Makefile.am b/src/identity/Makefile.am
index 17e72c784..e806f0059 100644
--- a/src/identity/Makefile.am
+++ b/src/identity/Makefile.am
@@ -8,9 +8,7 @@ if USE_COVERAGE
XLIB = -lgcov
endif
-if HAVE_REST
plugin_LTLIBRARIES = libgnunet_plugin_rest_identity.la
-endif
pkgcfgdir= $(pkgdatadir)/config.d/
diff --git a/src/identity/gnunet-identity.c b/src/identity/gnunet-identity.c
index fd73048c4..cf44afd1f 100644
--- a/src/identity/gnunet-identity.c
+++ b/src/identity/gnunet-identity.c
@@ -76,6 +76,11 @@ static char *create_ego;
static char *delete_ego;
/**
+ * -P option
+ */
+static char *privkey_ego;
+
+/**
* -s option.
*/
static char *set_ego;
@@ -101,6 +106,11 @@ static struct GNUNET_IDENTITY_Operation *create_op;
static struct GNUNET_IDENTITY_Operation *delete_op;
/**
+ * Private key from command line option, or NULL.
+ */
+struct GNUNET_CRYPTO_EcdsaPrivateKey pk;
+
+/**
* Value to return from #main().
*/
static int global_ret;
@@ -390,11 +400,28 @@ run (void *cls,
&delete_finished,
&delete_op);
if (NULL != create_ego)
- create_op =
- GNUNET_IDENTITY_create (sh,
- create_ego,
- &create_finished,
- &create_op);
+ {
+ if (NULL != privkey_ego)
+ {
+ GNUNET_STRINGS_string_to_data (privkey_ego,
+ strlen (privkey_ego),
+ &pk,
+ sizeof(struct GNUNET_CRYPTO_EcdsaPrivateKey));
+ create_op =
+ GNUNET_IDENTITY_create (sh,
+ create_ego,
+ &pk,
+ &create_finished,
+ &create_op);
+ }
+ else
+ create_op =
+ GNUNET_IDENTITY_create (sh,
+ create_ego,
+ NULL,
+ &create_finished,
+ &create_op);
+ }
GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
NULL);
test_finished ();
@@ -422,6 +449,11 @@ main (int argc, char *const *argv)
"NAME",
gettext_noop ("delete ego NAME "),
&delete_ego),
+ GNUNET_GETOPT_option_string ('P',
+ "privkey",
+ "PRIVATE_KEY",
+ gettext_noop ("set the private key for the identity to PRIVATE_KEY (use together with -C)"),
+ &privkey_ego),
GNUNET_GETOPT_option_flag ('d',
"display",
gettext_noop ("display all egos"),
diff --git a/src/identity/identity_api.c b/src/identity/identity_api.c
index 693d4392e..5d17ac5d5 100644
--- a/src/identity/identity_api.c
+++ b/src/identity/identity_api.c
@@ -392,6 +392,7 @@ handle_identity_update (void *cls,
return;
}
ego = GNUNET_new (struct GNUNET_IDENTITY_Ego);
+ ego->pub_initialized = GNUNET_NO;
ego->pk = um->private_key;
ego->name = GNUNET_strdup (str);
ego->id = id;
@@ -607,11 +608,11 @@ void
GNUNET_IDENTITY_ego_get_public_key (struct GNUNET_IDENTITY_Ego *ego,
struct GNUNET_CRYPTO_EcdsaPublicKey *pk)
{
- if (! ego->pub_initialized)
+ if (GNUNET_NO == ego->pub_initialized)
{
GNUNET_CRYPTO_ecdsa_key_get_public (&ego->pk,
&ego->pub);
- ego->pub_initialized = true;
+ ego->pub_initialized = GNUNET_YES;
}
*pk = ego->pub;
}
@@ -714,6 +715,7 @@ GNUNET_IDENTITY_set (struct GNUNET_IDENTITY_Handle *h,
*
* @param h identity service to use
* @param name desired name
+ * @param privkey desired private key or NULL to create one
* @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
@@ -721,6 +723,7 @@ GNUNET_IDENTITY_set (struct GNUNET_IDENTITY_Handle *h,
struct GNUNET_IDENTITY_Operation *
GNUNET_IDENTITY_create (struct GNUNET_IDENTITY_Handle *h,
const char *name,
+ const struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey,
GNUNET_IDENTITY_CreateContinuation cont,
void *cont_cls)
{
@@ -745,7 +748,10 @@ GNUNET_IDENTITY_create (struct GNUNET_IDENTITY_Handle *h,
env = GNUNET_MQ_msg_extra (crm, slen, GNUNET_MESSAGE_TYPE_IDENTITY_CREATE);
crm->name_len = htons (slen);
crm->reserved = htons (0);
- GNUNET_CRYPTO_ecdsa_key_create (&crm->private_key);
+ if (NULL == privkey)
+ GNUNET_CRYPTO_ecdsa_key_create (&crm->private_key);
+ else
+ crm->private_key = *privkey;
op->pk = crm->private_key;
GNUNET_memcpy (&crm[1], name, slen);
GNUNET_MQ_send (h->mq, env);
diff --git a/src/identity/identity_api_lookup.c b/src/identity/identity_api_lookup.c
index 6c61d3977..26b1eacd7 100644
--- a/src/identity/identity_api_lookup.c
+++ b/src/identity/identity_api_lookup.c
@@ -130,6 +130,7 @@ handle_identity_update (void *cls, const struct UpdateMessage *um)
struct GNUNET_CRYPTO_EcdsaPublicKey pub;
struct GNUNET_HashCode id;
struct GNUNET_IDENTITY_Ego ego;
+ memset (&ego, 0, sizeof (ego));
GNUNET_break (GNUNET_YES != ntohs (um->end_of_list));
GNUNET_CRYPTO_ecdsa_key_get_public (&um->private_key, &pub);
diff --git a/src/identity/plugin_rest_identity.c b/src/identity/plugin_rest_identity.c
index 97a7bf513..009a01f16 100644
--- a/src/identity/plugin_rest_identity.c
+++ b/src/identity/plugin_rest_identity.c
@@ -57,6 +57,11 @@
#define GNUNET_REST_IDENTITY_PARAM_PUBKEY "pubkey"
/**
+ * Parameter private key
+ */
+#define GNUNET_REST_IDENTITY_PARAM_PRIVKEY "privkey"
+
+/**
* Parameter subsystem
*/
#define GNUNET_REST_IDENTITY_PARAM_SUBSYSTEM "subsystem"
@@ -463,9 +468,11 @@ ego_get_all (struct GNUNET_REST_RequestHandle *con_handle,
struct RequestHandle *handle = cls;
struct EgoEntry *ego_entry;
struct MHD_Response *resp;
+ struct GNUNET_HashCode key;
json_t *json_root;
json_t *json_ego;
char *result_str;
+ char *privkey_str;
json_root = json_array ();
// Return ego/egos
@@ -476,6 +483,19 @@ ego_get_all (struct GNUNET_REST_RequestHandle *con_handle,
json_object_set_new (json_ego,
GNUNET_REST_IDENTITY_PARAM_PUBKEY,
json_string (ego_entry->keystring));
+ GNUNET_CRYPTO_hash ("private", strlen ("private"), &key);
+ if (GNUNET_YES ==
+ GNUNET_CONTAINER_multihashmap_contains (
+ handle->rest_handle->url_param_map, &key))
+ {
+ privkey_str = GNUNET_CRYPTO_ecdsa_private_key_to_string (
+ GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego));
+ json_object_set_new (json_ego,
+ GNUNET_REST_IDENTITY_PARAM_PRIVKEY,
+ json_string (privkey_str));
+ GNUNET_free (privkey_str);
+ }
+
json_object_set_new (json_ego,
GNUNET_REST_IDENTITY_PARAM_NAME,
json_string (ego_entry->identifier));
@@ -504,8 +524,10 @@ void
ego_get_response (struct RequestHandle *handle, struct EgoEntry *ego_entry)
{
struct MHD_Response *resp;
+ struct GNUNET_HashCode key;
json_t *json_ego;
char *result_str;
+ char *privkey_str;
json_ego = json_object ();
json_object_set_new (json_ego,
@@ -514,6 +536,18 @@ ego_get_response (struct RequestHandle *handle, struct EgoEntry *ego_entry)
json_object_set_new (json_ego,
GNUNET_REST_IDENTITY_PARAM_NAME,
json_string (ego_entry->identifier));
+ GNUNET_CRYPTO_hash ("private", strlen ("private"), &key);
+ if (GNUNET_YES ==
+ GNUNET_CONTAINER_multihashmap_contains (
+ handle->rest_handle->url_param_map, &key))
+ {
+ privkey_str = GNUNET_CRYPTO_ecdsa_private_key_to_string (
+ GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego));
+ json_object_set_new (json_ego,
+ GNUNET_REST_IDENTITY_PARAM_PRIVKEY,
+ json_string (privkey_str));
+ GNUNET_free (privkey_str);
+ }
result_str = json_dumps (json_ego, 0);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str);
@@ -956,6 +990,9 @@ ego_create (struct GNUNET_REST_RequestHandle *con_handle,
json_t *data_js;
json_error_t err;
char *egoname;
+ char *privkey;
+ struct GNUNET_CRYPTO_EcdsaPrivateKey pk;
+ struct GNUNET_CRYPTO_EcdsaPrivateKey *pk_ptr;
int json_unpack_state;
char term_data[handle->data_size + 1];
@@ -982,8 +1019,11 @@ ego_create (struct GNUNET_REST_RequestHandle *con_handle,
return;
}
json_unpack_state = 0;
+ privkey = NULL;
json_unpack_state =
- json_unpack (data_js, "{s:s!}", GNUNET_REST_IDENTITY_PARAM_NAME, &egoname);
+ json_unpack (data_js, "{s:s, s?:s!}",
+ GNUNET_REST_IDENTITY_PARAM_NAME, &egoname,
+ GNUNET_REST_IDENTITY_PARAM_PRIVKEY, &privkey);
if (0 != json_unpack_state)
{
handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_DATA_INVALID);
@@ -1020,10 +1060,21 @@ ego_create (struct GNUNET_REST_RequestHandle *con_handle,
}
}
handle->name = GNUNET_strdup (egoname);
+ if (NULL != privkey)
+ {
+ GNUNET_STRINGS_string_to_data (privkey,
+ strlen (privkey),
+ &pk,
+ sizeof(struct GNUNET_CRYPTO_EcdsaPrivateKey));
+ pk_ptr = &pk;
+ }
+ else
+ pk_ptr = NULL;
json_decref (data_js);
handle->response_code = MHD_HTTP_CREATED;
handle->op = GNUNET_IDENTITY_create (handle->identity_handle,
handle->name,
+ pk_ptr,
&do_finished_create,
handle);
}
diff --git a/src/identity/test_identity.c b/src/identity/test_identity.c
index aaa435d4f..37eeab238 100644
--- a/src/identity/test_identity.c
+++ b/src/identity/test_identity.c
@@ -279,7 +279,7 @@ run (void *cls,
GNUNET_SCHEDULER_add_shutdown (&cleanup, NULL);
h = GNUNET_IDENTITY_connect (cfg, &notification_cb, NULL);
CHECK (NULL != h);
- op = GNUNET_IDENTITY_create (h, "test-id", &create_cb, NULL);
+ op = GNUNET_IDENTITY_create (h, "test-id", NULL, &create_cb, NULL);
}
diff --git a/src/identity/test_identity_defaults.c b/src/identity/test_identity_defaults.c
index 1dd05f1b9..53eec1252 100644
--- a/src/identity/test_identity_defaults.c
+++ b/src/identity/test_identity_defaults.c
@@ -266,7 +266,7 @@ run_set (void *cls,
GNUNET_SCHEDULER_add_shutdown (&cleanup, NULL);
h = GNUNET_IDENTITY_connect (cfg, &notification_cb, NULL);
CHECK (NULL != h);
- op = GNUNET_IDENTITY_create (h, "test-id", &create_cb, NULL);
+ op = GNUNET_IDENTITY_create (h, "test-id", NULL, &create_cb, NULL);
}
diff --git a/src/include/gnunet_bio_lib.h b/src/include/gnunet_bio_lib.h
index 2f715ec97..687334c1c 100644
--- a/src/include/gnunet_bio_lib.h
+++ b/src/include/gnunet_bio_lib.h
@@ -42,6 +42,8 @@ extern "C"
#endif
#endif
+/****************************** READING API *******************************/
+
/**
* Handle for buffered reading.
*/
@@ -55,11 +57,22 @@ struct GNUNET_BIO_ReadHandle;
* @return IO handle on success, NULL on error
*/
struct GNUNET_BIO_ReadHandle *
-GNUNET_BIO_read_open (const char *fn);
+GNUNET_BIO_read_open_file (const char *fn);
+
+
+/**
+ * Create a handle from an existing allocated buffer.
+ *
+ * @param buffer the buffer to use as source
+ * @param size the total size in bytes of the buffer
+ * @return IO handle on sucess, NULL on error
+ */
+struct GNUNET_BIO_ReadHandle *
+GNUNET_BIO_read_open_buffer (void *buffer, size_t size);
/**
- * Close an open file. Reports if any errors reading
+ * Close an open handle. Reports if any errors reading
* from the file were encountered.
*
* @param h file handle
@@ -71,51 +84,40 @@ GNUNET_BIO_read_close (struct GNUNET_BIO_ReadHandle *h, char **emsg);
/**
- * Read the contents of a binary file into a buffer.
+ * Read some contents into a buffer.
*
- * @param h handle to an open file
+ * @param h the IO handle to read from
* @param what describes what is being read (for error message creation)
* @param result the buffer to write the result to
* @param len the number of bytes to read
* @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
*/
int
-GNUNET_BIO_read (struct GNUNET_BIO_ReadHandle *h, const char *what,
- void *result, size_t len);
+GNUNET_BIO_read (struct GNUNET_BIO_ReadHandle *h,
+ const char *what,
+ void *result,
+ size_t len);
/**
- * Read the contents of a binary file into a buffer.
+ * Read 0-terminated string.
*
- * @param h handle to an open file
- * @param file name of the source file
- * @param line line number in the source file
- * @param result the buffer to write the result to
- * @param len the number of bytes to read
- * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
- */
-int
-GNUNET_BIO_read_fn (struct GNUNET_BIO_ReadHandle *h,
- const char *file, int line,
- void *result, size_t len);
-
-/**
- * Read 0-terminated string from a file.
- *
- * @param h handle to an open file
+ * @param h the IO handle to read from
* @param what describes what is being read (for error message creation)
- * @param result the buffer to store a pointer to the (allocated) string to
+ * @param result where to store the pointer to the (allocated) string
* (note that *result could be set to NULL as well)
* @param max_length maximum allowed length for the string
* @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
*/
int
-GNUNET_BIO_read_string (struct GNUNET_BIO_ReadHandle *h, const char *what,
- char **result, size_t max_length);
+GNUNET_BIO_read_string (struct GNUNET_BIO_ReadHandle *h,
+ const char *what,
+ char **result,
+ size_t max_length);
/**
- * Read metadata container from a file.
+ * Read a metadata container.
*
* @param h handle to an open file
* @param what describes what is being read (for error message creation)
@@ -123,79 +125,69 @@ GNUNET_BIO_read_string (struct GNUNET_BIO_ReadHandle *h, const char *what,
* @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
*/
int
-GNUNET_BIO_read_meta_data (struct GNUNET_BIO_ReadHandle *h, const char *what,
+GNUNET_BIO_read_meta_data (struct GNUNET_BIO_ReadHandle *h,
+ const char *what,
struct GNUNET_CONTAINER_MetaData **result);
/**
* Read a float.
*
- * @param h hande to open file
+ * @param h the IO handle to read from
+ * @param what describes what is being read (for error message creation)
* @param f address of float to read
*/
-#define GNUNET_BIO_read_float(h, f) (GNUNET_BIO_read_fn (h, __FILE__, __LINE__, \
- f, sizeof(float)))
+int
+GNUNET_BIO_read_float(struct GNUNET_BIO_ReadHandle *h,
+ const char *what,
+ float *f);
/**
* Read a double.
*
- * @param h hande to open file
+ * @param h the IO handle to read from
+ * @param what describes what is being read (for error message creation)
* @param f address of double to read
*/
-#define GNUNET_BIO_read_double(h, f) (GNUNET_BIO_read_fn (h, __FILE__, __LINE__, \
- f, sizeof(double)))
+int
+GNUNET_BIO_read_double(struct GNUNET_BIO_ReadHandle *h,
+ const char *what,
+ double *f);
+
/**
* Read an (u)int32_t.
*
- * @param h hande to open file
- * @param file name of the source file
- * @param line line number in the code
- * @param i address of 32-bit integer to read
+ * @param h the IO handle to read from
+ * @param what describes what is being read (for error message creation)
+ * @param i where to store the data
* @return #GNUNET_OK on success, #GNUNET_SYSERR on error
*/
int
-GNUNET_BIO_read_int32__ (struct GNUNET_BIO_ReadHandle *h, const char *file,
- int line, int32_t *i);
-
+GNUNET_BIO_read_int32 (struct GNUNET_BIO_ReadHandle *h,
+ const char *what,
+ int32_t *i);
-/**
- * Read an (u)int32_t.
- *
- * @param h hande to open file
- * @param i address of 32-bit integer to read
- */
-#define GNUNET_BIO_read_int32(h, i) GNUNET_BIO_read_int32__ (h, __FILE__, \
- __LINE__, \
- (int32_t *) i)
/**
* Read an (u)int64_t.
*
- * @param h hande to open file
- * @param file name of the source file
- * @param line line number in the code
- * @param i address of 64-bit integer to read
+ * @param h the IO handle to read from
+ * @param what describes what is being read (for error message creation)
+ * @param i where to store the data
* @return #GNUNET_OK on success, #GNUNET_SYSERR on error
*/
int
-GNUNET_BIO_read_int64__ (struct GNUNET_BIO_ReadHandle *h, const char *file,
- int line, int64_t *i);
+GNUNET_BIO_read_int64 (struct GNUNET_BIO_ReadHandle *h,
+ const char *what,
+ int64_t *i);
-/**
- * Read an (u)int64_t.
- *
- * @param h hande to open file
- * @param i address of 64-bit integer to read
- */
-#define GNUNET_BIO_read_int64(h, i) GNUNET_BIO_read_int64__ (h, __FILE__, \
- __LINE__, \
- (int64_t *) i)
+/****************************** WRITING API *******************************/
/**
* Handle for buffered writing.
@@ -205,108 +197,481 @@ struct GNUNET_BIO_WriteHandle;
/**
* Open a file for writing.
*
- * @param fn file name to be opened
+ * @param fn name of the file to be opened
* @return IO handle on success, NULL on error
*/
struct GNUNET_BIO_WriteHandle *
-GNUNET_BIO_write_open (const char *fn);
+GNUNET_BIO_write_open_file (const char *fn);
/**
- * Close an open file for writing.
+ * Create a handle backed by an in-memory buffer.
*
- * @param h file handle
- * @return GNUNET_OK on success, GNUNET_SYSERR otherwise
+ * @return IO handle on success, NULL on error
+ */
+struct GNUNET_BIO_WriteHandle *
+GNUNET_BIO_write_open_buffer (void);
+
+
+/**
+ * Force a file-based buffered writer to flush its buffer.
+ * If the handle does not use a file, this function returs #GNUNET_OK
+ * without doing anything.
+ *
+ * @param h the IO handle
+ * @return #GNUNET_OK upon success. Upon failure #GNUNET_SYSERR is returned
+ * and the file is closed
*/
int
-GNUNET_BIO_write_close (struct GNUNET_BIO_WriteHandle *h);
+GNUNET_BIO_flush (struct GNUNET_BIO_WriteHandle *h);
/**
- * Write a buffer to a file.
+ * Get the IO handle's contents.
+ * If the handle doesn't use an in-memory buffer, this function returns
+ * #GNUNET_SYSERR.
*
- * @param h handle to open file
- * @param buffer the data to write
- * @param n number of bytes to write
- * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
+ * @param h the IO handle
+ * @param emsg set to the (allocated) error message
+ * if the handle has an error message the return value is #GNUNET_SYSERR
+ * @param contents where to store the pointer to the handle's contents
+ * @param size where to store the size of @e contents
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
*/
int
-GNUNET_BIO_write (struct GNUNET_BIO_WriteHandle *h, const void *buffer,
- size_t n);
+GNUNET_BIO_get_buffer_contents (struct GNUNET_BIO_WriteHandle *h,
+ char **emsg,
+ void **contents,
+ size_t *size);
+
+
+/**
+ * Close an IO handle.
+ * If the handle was using a file, the file will be closed.
+ *
+ * @param h file handle
+ * @param emsg set to the (allocated) error message
+ * if the handle has an error message, the return value is #GNUNET_SYSERR
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
+ */
+int
+GNUNET_BIO_write_close (struct GNUNET_BIO_WriteHandle *h, char **emsg);
/**
- * Force a buffered writer to flush its buffer
+ * Write a buffer to a handle.
*
- * @param h the writer handle
- * @return #GNUNET_OK upon success. Upon failure #GNUNET_SYSERR is returned and
- * the file is closed
+ * @param h the IO handle to write to
+ * @param what what is being written (for error message creation)
+ * @param buffer the data to write
+ * @param n number of bytes to write
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
*/
int
-GNUNET_BIO_flush (struct GNUNET_BIO_WriteHandle *h);
+GNUNET_BIO_write (struct GNUNET_BIO_WriteHandle *h,
+ const char *what,
+ const void *buffer,
+ size_t n);
/**
- * Write a string to a file.
+ * Write a 0-terminated string.
*
- * @param h handle to open file
+ * @param h the IO handle to write to
+ * @param what what is being written (for error message creation)
* @param s string to write (can be NULL)
* @return #GNUNET_OK on success, #GNUNET_SYSERR on error
*/
int
-GNUNET_BIO_write_string (struct GNUNET_BIO_WriteHandle *h, const char *s);
+GNUNET_BIO_write_string (struct GNUNET_BIO_WriteHandle *h,
+ const char *what,
+ const char *s);
/**
- * Write metadata container to a file.
+ * Write a metadata container.
*
- * @param h handle to open file
+ * @param h the IO handle to write to
+ * @param what what is being written (for error message creation)
* @param m metadata to write
* @return #GNUNET_OK on success, #GNUNET_SYSERR on error
*/
int
GNUNET_BIO_write_meta_data (struct GNUNET_BIO_WriteHandle *h,
+ const char *what,
const struct GNUNET_CONTAINER_MetaData *m);
/**
* Write a float.
*
- * @param h hande to open file
+ * @param h the IO handle to write to
+ * @param what what is being written (for error message creation)
* @param f float to write (must be a variable)
*/
-#define GNUNET_BIO_write_float(h, f) GNUNET_BIO_write (h, &f, sizeof(float))
-
+int
+GNUNET_BIO_write_float(struct GNUNET_BIO_WriteHandle *h,
+ const char *what,
+ float f);
/**
* Write a double.
*
- * @param h hande to open file
+ * @param h the IO handle to write to
+ * @param what what is being written (for error message creation)
* @param f double to write (must be a variable)
*/
-#define GNUNET_BIO_write_double(h, f) GNUNET_BIO_write (h, &f, sizeof(double))
+int
+GNUNET_BIO_write_double(struct GNUNET_BIO_WriteHandle *h,
+ const char *what,
+ double f);
/**
* Write an (u)int32_t.
*
- * @param h hande to open file
+ * @param h the IO handle to write to
+ * @param what what is being written (for error message creation)
* @param i 32-bit integer to write
* @return #GNUNET_OK on success, #GNUNET_SYSERR on error
*/
int
-GNUNET_BIO_write_int32 (struct GNUNET_BIO_WriteHandle *h, int32_t i);
+GNUNET_BIO_write_int32 (struct GNUNET_BIO_WriteHandle *h,
+ const char *what,
+ int32_t i);
/**
* Write an (u)int64_t.
*
- * @param h hande to open file
+ * @param h the IO handle to write to
+ * @param what what is being written (for error message creation)
* @param i 64-bit integer to write
* @return #GNUNET_OK on success, #GNUNET_SYSERR on error
*/
int
-GNUNET_BIO_write_int64 (struct GNUNET_BIO_WriteHandle *h, int64_t i);
+GNUNET_BIO_write_int64 (struct GNUNET_BIO_WriteHandle *h,
+ const char *what,
+ int64_t i);
+
+
+/****************************** READ SPEC API ***************************/
+
+
+/**
+ * Function used to deserialize data read from @a h and store it into @a
+ * target.
+ *
+ * @param cls closure (can be NULL)
+ * @param h the IO handle to read from
+ * @param what what is being read (for error message creation)
+ * @param target where to store the data
+ * @param target_size how many bytes can be written in @a target
+ * can be 0 if the size is unknown or is not fixed
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
+ */
+typedef int
+(*GNUNET_BIO_ReadHandler)(void *cls,
+ struct GNUNET_BIO_ReadHandle *h,
+ const char *what,
+ void *target,
+ size_t target_size);
+
+
+/**
+ * Structure specifying a reading operation on an IO handle.
+ */
+struct GNUNET_BIO_ReadSpec
+{
+ /**
+ * Function performing data deserialization.
+ */
+ GNUNET_BIO_ReadHandler rh;
+
+ /**
+ * Closure for @e rh. Can be NULL.
+ */
+ void *cls;
+
+ /**
+ * What is being read (for error message creation)
+ */
+ const char *what;
+
+ /**
+ * Destination buffer. Can also be a pointer to a pointer, especially for
+ * dynamically allocated structures.
+ */
+ void *target;
+
+ /**
+ * Size of @e target. Can be 0 if unknown or not fixed.
+ */
+ size_t size;
+};
+
+
+/**
+ * End of specifications marker.
+ */
+#define GNUNET_BIO_read_spec_end() \
+ { NULL, NULL, NULL, NULL, 0 }
+
+
+/**
+ * Create the specification to read a certain amount of bytes.
+ *
+ * @param what describes what is being read (for error message creation)
+ * @param result the buffer to write the result to
+ * @param len the number of bytes to read
+ * @return the read spec
+ */
+struct GNUNET_BIO_ReadSpec
+GNUNET_BIO_read_spec_object (const char *what,
+ void *result,
+ size_t size);
+
+
+/**
+ * Create the specification to read a 0-terminated string.
+ *
+ * @param what describes what is being read (for error message creation)
+ * @param result where to store the pointer to the (allocated) string
+ * (note that *result could be set to NULL as well)
+ * @param max_length maximum allowed length for the string
+ * @return the read spec
+ */
+struct GNUNET_BIO_ReadSpec
+GNUNET_BIO_read_spec_string (const char *what,
+ char **result,
+ size_t max_length);
+
+
+/**
+ * Create the specification to read a metadata container.
+ *
+ * @param what describes what is being read (for error message creation)
+ * @param result the buffer to store a pointer to the (allocated) metadata
+ * @return the read spec
+ */
+struct GNUNET_BIO_ReadSpec
+GNUNET_BIO_read_spec_meta_data (const char *what,
+ struct GNUNET_CONTAINER_MetaData **result);
+
+
+/**
+ * Create the specification to read an (u)int32_t.
+ *
+ * @param what describes what is being read (for error message creation)
+ * @param i where to store the data
+ * @return the read spec
+ */
+struct GNUNET_BIO_ReadSpec
+GNUNET_BIO_read_spec_int32 (const char *what,
+ int32_t *i);
+
+
+/**
+ * Create the specification to read an (u)int64_t.
+ *
+ * @param what describes what is being read (for error message creation)
+ * @param i where to store the data
+ * @return the read spec
+ */
+struct GNUNET_BIO_ReadSpec
+GNUNET_BIO_read_spec_int64 (const char *what,
+ int64_t *i);
+
+
+/**
+ * Create the specification to read a float.
+ *
+ * @param what describes what is being read (for error message creation)
+ * @param f address of float to read
+ */
+struct GNUNET_BIO_ReadSpec
+GNUNET_BIO_read_spec_float(const char *what, float *f);
+
+
+/**
+ * Create the specification to read a double.
+ *
+ * @param what describes what is being read (for error message creation)
+ * @param f address of double to read
+ */
+struct GNUNET_BIO_ReadSpec
+GNUNET_BIO_read_spec_double(const char *what, double *f);
+
+
+/**
+ * Execute the read specifications in order.
+ *
+ * @param h the IO handle to read from
+ * @param rs array of read specs
+ * the last element must be #GNUNET_BIO_read_spec_end
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
+ */
+int
+GNUNET_BIO_read_spec_commit (struct GNUNET_BIO_ReadHandle *h,
+ struct GNUNET_BIO_ReadSpec *rs);
+
+
+/******************************* WRITE SPEC API *****************************/
+
+
+/**
+ * Function used to serialize data from a buffer and write it to @a h.
+ *
+ * @param cls closure (can be NULL)
+ * @param h the IO handle to write to
+ * @param what what is being written (for error message creation)
+ * @param source the data to write
+ * @param source_size how many bytes should be written
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
+ */
+typedef int
+(*GNUNET_BIO_WriteHandler) (void *cls,
+ struct GNUNET_BIO_WriteHandle *h,
+ const char *what,
+ void *source,
+ size_t source_size);
+
+
+/**
+ * Structure specifying a writing operation on an IO handle.
+ */
+struct GNUNET_BIO_WriteSpec
+{
+ /**
+ * Function performing data serialization.
+ */
+ GNUNET_BIO_WriteHandler wh;
+
+ /**
+ * Closure for @e rh. Can be NULL.
+ */
+ void *cls;
+
+ /**
+ * What is being read (for error message creation)
+ */
+ const char *what;
+
+ /**
+ * Source buffer. The data in this buffer will be written to the handle.
+ */
+ void *source;
+
+ /**
+ * Size of @e source. If it's smaller than the real size of @e source, only
+ * this many bytes will be written.
+ */
+ size_t source_size;
+};
+
+
+/**
+ * End of specifications marker.
+ */
+#define GNUNET_BIO_write_spec_end() \
+ { NULL, NULL, NULL, NULL, 0 }
+
+
+/**
+ * Create the specification to read some bytes.
+ *
+ * @param what describes what is being written (for error message creation)
+ * @param source the data to write
+ * @param size how many bytes should be written
+ * @return the write spec
+ */
+struct GNUNET_BIO_WriteSpec
+GNUNET_BIO_write_spec_object (const char *what,
+ void *source,
+ size_t size);
+
+
+/**
+ * Create the specification to write a 0-terminated string.
+ *
+ * @param what describes what is being read (for error message creation)
+ * @param s string to write (can be NULL)
+ * @return the read spec
+ */
+struct GNUNET_BIO_WriteSpec
+GNUNET_BIO_write_spec_string (const char *what,
+ const char *s);
+
+
+/**
+ * Create the specification to write a metadata container.
+ *
+ * @param what what is being written (for error message creation)
+ * @param m metadata to write
+ * @return the write spec
+ */
+struct GNUNET_BIO_WriteSpec
+GNUNET_BIO_write_spec_meta_data (const char *what,
+ const struct GNUNET_CONTAINER_MetaData *m);
+
+
+/**
+ * Create the specification to write an (u)int32_t.
+ *
+ * @param what describes what is being written (for error message creation)
+ * @param i pointer to a 32-bit integer
+ * @return the write spec
+ */
+struct GNUNET_BIO_WriteSpec
+GNUNET_BIO_write_spec_int32 (const char *what,
+ int32_t *i);
+
+
+/**
+ * Create the specification to write an (u)int64_t.
+ *
+ * @param what describes what is being written (for error message creation)
+ * @param i pointer to a 64-bit integer
+ * @return the write spec
+ */
+struct GNUNET_BIO_WriteSpec
+GNUNET_BIO_write_spec_int64 (const char *what,
+ int64_t *i);
+
+
+/**
+ * Create the specification to write a float.
+ *
+ * @param what describes what is being written (for error message creation)
+ * @param f pointer to a float
+ * @return the write spec
+ */
+struct GNUNET_BIO_WriteSpec
+GNUNET_BIO_write_spec_float(const char *what, float *f);
+
+
+/**
+ * Create the specification to write an double.
+ *
+ * @param what describes what is being written (for error message creation)
+ * @param f pointer to a double
+ * @return the write spec
+ */
+struct GNUNET_BIO_WriteSpec
+GNUNET_BIO_write_spec_double(const char *what, double *f);
+
+
+/**
+ * Execute the write specifications in order.
+ *
+ * @param h the IO handle to write to
+ * @param ws array of write specs
+ * the last element must be #GNUNET_BIO_write_spec_end
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
+ */
+int
+GNUNET_BIO_write_spec_commit (struct GNUNET_BIO_WriteHandle *h,
+ struct GNUNET_BIO_WriteSpec *ws);
#if 0 /* keep Emacsens' auto-indent happy */
diff --git a/src/include/gnunet_buffer_lib.h b/src/include/gnunet_buffer_lib.h
index c0ae06d77..e23536ab2 100644
--- a/src/include/gnunet_buffer_lib.h
+++ b/src/include/gnunet_buffer_lib.h
@@ -165,6 +165,19 @@ GNUNET_buffer_reap_str (struct GNUNET_Buffer *buf);
/**
+ * Clear the buffer and return its contents.
+ * The caller is responsible to eventually #GNUNET_free
+ * the returned data.
+ *
+ * @param buf the buffer to reap the contents from
+ * @param size where to store the size of the returned data
+ * @returns the data contained in the string
+ */
+void *
+GNUNET_buffer_reap (struct GNUNET_Buffer *buf, size_t *size);
+
+
+/**
* Free the backing memory of the given buffer.
* Does not free the memory of the buffer control structure,
* which is typically stack-allocated.
diff --git a/src/include/gnunet_crypto_lib.h b/src/include/gnunet_crypto_lib.h
index a5a50e749..d11c6b58c 100644
--- a/src/include/gnunet_crypto_lib.h
+++ b/src/include/gnunet_crypto_lib.h
@@ -659,7 +659,7 @@ GNUNET_CRYPTO_hash (const void *block,
/**
* Calculate the 'proof-of-work' hash (an expensive hash).
*
- * @param salt salt to use in pow calculation
+ * @param salt salt for the hash. Must be crypto_pwhash_argon2id_SALTBYTES long.
* @param buf data to hash
* @param buf_len number of bytes in @a buf
* @param result where to write the resulting hash
@@ -874,12 +874,25 @@ GNUNET_CRYPTO_hash_to_aes_key (
* Obtain a bit from a hashcode.
*
* @param code the `struct GNUNET_HashCode` to index bit-wise
- * @param bit index into the hashcode, [0...159]
+ * @param bit index into the hashcode, [0...159] where 0 is the leftmost bit
+ * (bytes in code interpreted big endian)
* @return Bit \a bit from hashcode \a code, -1 for invalid index
*/
int
-GNUNET_CRYPTO_hash_get_bit (const struct GNUNET_HashCode *code,
- unsigned int bit);
+GNUNET_CRYPTO_hash_get_bit_ltr (const struct GNUNET_HashCode *code,
+ unsigned int bit);
+
+
+/**
+ * Obtain a bit from a hashcode.
+ * @param code the GNUNET_CRYPTO_hash to index bit-wise
+ * @param bit index into the hashcode, [0...511] where 0 is the rightmost bit
+ * (bytes in code interpreted little endian)
+ * @return Bit \a bit from hashcode \a code, -1 for invalid index
+ */
+int
+GNUNET_CRYPTO_hash_get_bit_rtl (const struct GNUNET_HashCode *code,
+ unsigned int bit);
/**
@@ -2147,8 +2160,8 @@ GNUNET_CRYPTO_rsa_public_key_dup (const struct GNUNET_CRYPTO_RsaPublicKey *key);
* @return 0 if the two are equal
*/
int
-GNUNET_CRYPTO_rsa_signature_cmp (struct GNUNET_CRYPTO_RsaSignature *s1,
- struct GNUNET_CRYPTO_RsaSignature *s2);
+GNUNET_CRYPTO_rsa_signature_cmp (const struct GNUNET_CRYPTO_RsaSignature *s1,
+ const struct GNUNET_CRYPTO_RsaSignature *s2);
/**
* Compare the values of two private keys.
@@ -2158,8 +2171,8 @@ GNUNET_CRYPTO_rsa_signature_cmp (struct GNUNET_CRYPTO_RsaSignature *s1,
* @return 0 if the two are equal
*/
int
-GNUNET_CRYPTO_rsa_private_key_cmp (struct GNUNET_CRYPTO_RsaPrivateKey *p1,
- struct GNUNET_CRYPTO_RsaPrivateKey *p2);
+GNUNET_CRYPTO_rsa_private_key_cmp (const struct GNUNET_CRYPTO_RsaPrivateKey *p1,
+ const struct GNUNET_CRYPTO_RsaPrivateKey *p2);
/**
@@ -2170,8 +2183,8 @@ GNUNET_CRYPTO_rsa_private_key_cmp (struct GNUNET_CRYPTO_RsaPrivateKey *p1,
* @return 0 if the two are equal
*/
int
-GNUNET_CRYPTO_rsa_public_key_cmp (struct GNUNET_CRYPTO_RsaPublicKey *p1,
- struct GNUNET_CRYPTO_RsaPublicKey *p2);
+GNUNET_CRYPTO_rsa_public_key_cmp (const struct GNUNET_CRYPTO_RsaPublicKey *p1,
+ const struct GNUNET_CRYPTO_RsaPublicKey *p2);
/**
diff --git a/src/include/gnunet_identity_service.h b/src/include/gnunet_identity_service.h
index 81af671e2..f4e653598 100644
--- a/src/include/gnunet_identity_service.h
+++ b/src/include/gnunet_identity_service.h
@@ -233,6 +233,7 @@ typedef void
*
* @param id identity service to use
* @param name desired name
+ * @param privkey desired private key or NULL to create one
* @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
@@ -240,6 +241,7 @@ typedef void
struct GNUNET_IDENTITY_Operation *
GNUNET_IDENTITY_create (struct GNUNET_IDENTITY_Handle *id,
const char *name,
+ const struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey,
GNUNET_IDENTITY_CreateContinuation cont,
void *cont_cls);
diff --git a/src/include/gnunet_os_lib.h b/src/include/gnunet_os_lib.h
index a6188c1ca..b583cc493 100644
--- a/src/include/gnunet_os_lib.h
+++ b/src/include/gnunet_os_lib.h
@@ -287,6 +287,14 @@ struct GNUNET_OS_ProjectData
* If this field is NULL, the path is automatically inferred.
*/
char *gettext_path;
+
+ /**
+ * URL pointing to the source code of the application. Required for AGPL.
+ * Setting this to NULL disables the built-in mechanism, but you must
+ * provide it in some other way. If non-NULL, message type 1 and 2 are
+ * reserved.
+ */
+ char *agpl_url;
};
diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h
index e67e35f38..0db6150aa 100644
--- a/src/include/gnunet_protocols.h
+++ b/src/include/gnunet_protocols.h
@@ -50,25 +50,29 @@ extern "C" {
#endif
/*******************************************************************************
- * UTIL message types
- ******************************************************************************/
+* Deprecated
+* *****************************************************************************/
/**
* Test if service is online.
*
* @deprecated!
*/
-#define GNUNET_MESSAGE_TYPE_TEST 1
+#define GNUNET_MESSAGE_TYPE_TEST 0
+
+/*******************************************************************************
+* AGPL source code download
+* *****************************************************************************/
/**
- * Dummy messages for testing / benchmarking.
+ * Message to request source code link.
*/
-#define GNUNET_MESSAGE_TYPE_DUMMY 2
+#define GNUNET_MESSAGE_TYPE_REQUEST_AGPL 1
/**
- * Another dummy messages for testing / benchmarking.
+ * Source code link.
*/
-#define GNUNET_MESSAGE_TYPE_DUMMY2 3
+#define GNUNET_MESSAGE_TYPE_RESPONSE_AGPL 2
/*******************************************************************************
* RESOLVER message types
@@ -85,18 +89,18 @@ extern "C" {
#define GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE 5
/*******************************************************************************
-* AGPL source code download
-* *****************************************************************************/
+ * UTIL message types
+ ******************************************************************************/
/**
- * Message to request source code link.
+ * Dummy messages for testing / benchmarking.
*/
-#define GNUNET_MESSAGE_TYPE_REQUEST_AGPL 6
+#define GNUNET_MESSAGE_TYPE_DUMMY 6
/**
- * Source code link.
+ * Another dummy messages for testing / benchmarking.
*/
-#define GNUNET_MESSAGE_TYPE_RESPONSE_AGPL 7
+#define GNUNET_MESSAGE_TYPE_DUMMY2 7
/*******************************************************************************
@@ -1648,29 +1652,8 @@ extern "C" {
*/
#define GNUNET_MESSAGE_TYPE_CONSENSUS_P2P_ELEMENTS_REPORT 545
-/*
- * Initialization message for consensus p2p communication.
- */
-#define GNUNET_MESSAGE_TYPE_CONSENSUS_P2P_HELLO 546
-
-/**
- * Report that the peer is synced with the partner after successfuly decoding
- * the invertible bloom filter.
- */
-#define GNUNET_MESSAGE_TYPE_CONSENSUS_P2P_SYNCED 547
-
-/**
- * Interaction os over, got synched and reported all elements
- */
-#define GNUNET_MESSAGE_TYPE_CONSENSUS_P2P_FIN 548
-
/**
- * Abort a round, don't send requested elements anymore
- */
-#define GNUNET_MESSAGE_TYPE_CONSENSUS_P2P_ABORT 548
-
-/**
- * Abort a round, don't send requested elements anymore
+ * Provide context for a consensus round.
*/
#define GNUNET_MESSAGE_TYPE_CONSENSUS_P2P_ROUND_CONTEXT 547
@@ -2751,9 +2734,8 @@ extern "C" {
* 1000-1009 Connection-level Messages
* 1010-1019 Channel-level Messages
* 1020-1029 Local Client-Service
- * 1030-1039 Local Service Monitoring
- * 1040-1049 Application Data
- * 1050-1059 Reserved
+ * 1030-1049 Local Service Monitoring
+ * 1050-1059 Application Data
*/
/******************************** Connection ********************************/
@@ -2949,6 +2931,11 @@ extern "C" {
*/
#define GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS_END 1041
+/**
+ * Request to drop a message of type X to peer y.
+ */
+#define GNUNET_MESSAGE_TYPE_CADET_DROP_CADET_MESSAGE 1042
+
/******************************** Application *******************************/
@@ -3178,6 +3165,10 @@ extern "C" {
*/
#define GNUNET_MESSAGE_TYPE_TRANSPORT_FLOW_CONTROL 1221
+/**
+ * @brief inform transport that a queue was updated
+ */
+#define GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_UPDATE 1222
/**
* Message sent to indicate to the transport that a monitor
diff --git a/src/include/gnunet_signatures.h b/src/include/gnunet_signatures.h
index a00e0372d..503113770 100644
--- a/src/include/gnunet_signatures.h
+++ b/src/include/gnunet_signatures.h
@@ -241,6 +241,10 @@ extern "C"
*/
#define GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_INITIATOR 37
+/**
+ * Signature by a peer that like to create a connection.
+ */
+#define GNUNET_SIGNATURE_PURPOSE_CADET_CONNECTION_INITIATOR 38
#if 0 /* keep Emacsens' auto-indent happy */
{
diff --git a/src/include/gnunet_transport_communication_service.h b/src/include/gnunet_transport_communication_service.h
index f4dfc8745..ea6b95e2d 100644
--- a/src/include/gnunet_transport_communication_service.h
+++ b/src/include/gnunet_transport_communication_service.h
@@ -50,6 +50,10 @@ extern "C" {
*/
#define GNUNET_TRANSPORT_COMMUNICATION_VERSION 0x00000000
+/**
+ * Queue length
+ */
+#define GNUNET_TRANSPORT_QUEUE_LENGTH_UNLIMITED UINT64_MAX
/**
* Function called by the transport service to initialize a
@@ -176,8 +180,9 @@ GNUNET_TRANSPORT_communicator_disconnect (
* @param success #GNUNET_SYSERR on failure (try to disconnect/reset connection)
* #GNUNET_OK on success
*/
-typedef void (*GNUNET_TRANSPORT_MessageCompletedCallback) (void *cls,
- int success);
+typedef void
+(*GNUNET_TRANSPORT_MessageCompletedCallback) (void *cls,
+ int success);
/**
@@ -251,6 +256,9 @@ enum GNUNET_TRANSPORT_ConnectionStatus
* @param address address in human-readable format, 0-terminated, UTF-8
* @param mtu maximum message size supported by queue, 0 if
* sending is not supported, SIZE_MAX for no MTU
+ * @param q_len number of messages that can be send through this queue
+ * @param priority queue priority. Queues with highest priority should be
+ * used
* @param nt which network type does the @a address belong to?
* @param cs what is the connection status of the queue?
* @param mq message queue of the @a peer
@@ -262,10 +270,27 @@ GNUNET_TRANSPORT_communicator_mq_add (
const struct GNUNET_PeerIdentity *peer,
const char *address,
uint32_t mtu,
+ uint64_t q_len,
+ uint32_t priority,
enum GNUNET_NetworkType nt,
enum GNUNET_TRANSPORT_ConnectionStatus cs,
struct GNUNET_MQ_Handle *mq);
+/**
+ * Notify transport service that an MQ was updated
+ *
+ * @param ch connection to transport service
+ * @param qh the queue to update
+ * @param q_len number of messages that can be send through this queue
+ * @param priority queue priority. Queues with highest priority should be
+ * used
+ */
+void
+GNUNET_TRANSPORT_communicator_mq_update (
+ struct GNUNET_TRANSPORT_CommunicatorHandle *ch,
+ const struct GNUNET_TRANSPORT_QueueHandle *u_qh,
+ uint64_t q_len,
+ uint32_t priority);
/**
* Notify transport service that an MQ became unavailable due to a
diff --git a/src/integration-tests/Makefile.am b/src/integration-tests/Makefile.am
index f456544db..b3adc3a0f 100644
--- a/src/integration-tests/Makefile.am
+++ b/src/integration-tests/Makefile.am
@@ -21,7 +21,6 @@ check_SCRIPTS = \
endif
-if HAVE_MHD
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;
if HAVE_LIBGNURL
@@ -34,7 +33,6 @@ TESTS = \
endif
endif
endif
-endif
SUFFIXES = .py.in .py
.py.in.py:
diff --git a/src/namestore/Makefile.am b/src/namestore/Makefile.am
index 94861b478..f4b846065 100644
--- a/src/namestore/Makefile.am
+++ b/src/namestore/Makefile.am
@@ -99,9 +99,7 @@ TESTS = \
$(check_SCRIPTS)
endif
-if HAVE_REST
REST_PLUGIN = libgnunet_plugin_rest_namestore.la
-endif
lib_LTLIBRARIES = \
libgnunetnamestore.la
@@ -114,10 +112,8 @@ bin_PROGRAMS = \
gnunet-namestore \
gnunet-zoneimport
-if HAVE_MHD
libexec_PROGRAMS += \
gnunet-namestore-fcfsd
-endif
plugin_LTLIBRARIES = \
@@ -679,12 +675,8 @@ check_SCRIPTS = \
test_namestore_lookup.sh \
test_namestore_delete.sh
-if HAVE_MHD
-if HAVE_JSON
check_SCRIPTS += \
test_plugin_rest_namestore.sh
-endif
-endif
EXTRA_DIST = \
test_common.c \
diff --git a/src/nse/gnunet-service-nse.c b/src/nse/gnunet-service-nse.c
index 793f60694..ebf39585e 100644
--- a/src/nse/gnunet-service-nse.c
+++ b/src/nse/gnunet-service-nse.c
@@ -780,7 +780,7 @@ count_leading_zeroes (const struct GNUNET_HashCode *hash)
unsigned int hash_count;
hash_count = 0;
- while (0 == GNUNET_CRYPTO_hash_get_bit (hash, hash_count))
+ while (0 == GNUNET_CRYPTO_hash_get_bit_ltr (hash, hash_count))
hash_count++;
return hash_count;
}
@@ -806,7 +806,7 @@ check_proof_of_work (const struct GNUNET_CRYPTO_EddsaPublicKey *pkey,
GNUNET_memcpy (&buf[sizeof(val)],
pkey,
sizeof(struct GNUNET_CRYPTO_EddsaPublicKey));
- GNUNET_CRYPTO_pow_hash ("gnunet-nse-proof-of-work",
+ GNUNET_CRYPTO_pow_hash ("gnunet-nse-proof",
buf,
sizeof(buf),
&result);
@@ -861,7 +861,7 @@ find_proof (void *cls)
while ((counter != UINT64_MAX) && (i < ROUND_SIZE))
{
GNUNET_memcpy (buf, &counter, sizeof(uint64_t));
- GNUNET_CRYPTO_pow_hash ("gnunet-nse-proof-of-work",
+ GNUNET_CRYPTO_pow_hash ("gnunet-nse-proof",
buf,
sizeof(buf),
&result);
@@ -1001,7 +1001,7 @@ handle_p2p_estimate (void *cls,
if (NULL != lh)
GNUNET_TESTBED_LOGGER_write (lh, &t, sizeof(uint64_t));
if (NULL != histogram)
- GNUNET_BIO_write_int64 (histogram, t);
+ GNUNET_BIO_write_int64 (histogram, "histogram-time", t);
}
#endif
GNUNET_STATISTICS_update (stats, "# flood messages received", 1, GNUNET_NO);
@@ -1299,7 +1299,7 @@ shutdown_task (void *cls)
}
if (NULL != histogram)
{
- GNUNET_BIO_write_close (histogram);
+ GNUNET_BIO_write_close (histogram, NULL);
histogram = NULL;
}
#endif
@@ -1453,7 +1453,7 @@ run (void *cls,
GNUNET_assert (
0 < GNUNET_asprintf (&histogram_fn, "%s/timestamps", histogram_dir));
GNUNET_free (histogram_dir);
- histogram = GNUNET_BIO_write_open (histogram_fn);
+ histogram = GNUNET_BIO_write_open_file (histogram_fn);
if (NULL == histogram)
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"Unable to open histogram file `%s'\n",
diff --git a/src/nse/nse.conf.in b/src/nse/nse.conf.in
index d3c9a64b1..6330254e9 100644
--- a/src/nse/nse.conf.in
+++ b/src/nse/nse.conf.in
@@ -35,4 +35,4 @@ INTERVAL = 1 h
# for SCRYPT; with 2ms/op and 5ms workdelay, we can expect
# the POW calculation to be done by a high-end peer in about 6h
# DO NOT CHANGE THIS VALUE, doing so will break the protocol!
-WORKBITS = 22
+WORKBITS = 15
diff --git a/src/nse/perf_kdf.c b/src/nse/perf_kdf.c
index c5975aaf2..89b70903a 100644
--- a/src/nse/perf_kdf.c
+++ b/src/nse/perf_kdf.c
@@ -37,7 +37,7 @@ perfHash ()
memset (buf, 1, sizeof(buf));
for (unsigned int i = 0; i < 1024; i++)
- GNUNET_CRYPTO_pow_hash ("gnunet-proof-of-work",
+ GNUNET_CRYPTO_pow_hash ("gnunet-nse-proof",
buf,
sizeof(buf),
&hc);
diff --git a/src/peerinfo-tool/Makefile.am b/src/peerinfo-tool/Makefile.am
index 93252570c..dfcdcd3da 100644
--- a/src/peerinfo-tool/Makefile.am
+++ b/src/peerinfo-tool/Makefile.am
@@ -6,9 +6,7 @@ if USE_COVERAGE
XLIB = -lgcov
endif
-if HAVE_REST
REST_PLUGIN = libgnunet_plugin_rest_peerinfo.la
-endif
plugindir = $(libdir)/gnunet
diff --git a/src/pt/Makefile.am b/src/pt/Makefile.am
index 09a68b779..10ae04931 100644
--- a/src/pt/Makefile.am
+++ b/src/pt/Makefile.am
@@ -29,7 +29,6 @@ gnunet_daemon_pt_LDADD = \
$(GN_LIBINTL)
if HAVE_TESTING
-if HAVE_MHD
if HAVE_LIBGNURL
LIB_GNURL=@LIBGNURL@
@@ -58,7 +57,6 @@ endif
endif
endif
-endif
check_PROGRAMS = $(VPN_TEST)
diff --git a/src/reclaim/Makefile.am b/src/reclaim/Makefile.am
index 6d448cc3c..b6d73bdf7 100644
--- a/src/reclaim/Makefile.am
+++ b/src/reclaim/Makefile.am
@@ -9,16 +9,12 @@ if USE_COVERAGE
endif
-if HAVE_REST
REST_PLUGIN = \
libgnunet_plugin_rest_openid_connect.la \
libgnunet_plugin_rest_reclaim.la
-endif
-if HAVE_JSON
ATTESTATION_PLUGIN = \
libgnunet_plugin_reclaim_attestation_jwt.la
-endif
EXTRA_DIST = \
reclaim.conf \
diff --git a/src/reclaim/json_reclaim.c b/src/reclaim/json_reclaim.c
index d52d15ed4..c470ea567 100644
--- a/src/reclaim/json_reclaim.c
+++ b/src/reclaim/json_reclaim.c
@@ -332,7 +332,7 @@ parse_attest (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
(void **) &data,
&data_size)))
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Attestation value invalid!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Attestation value invalid!\n");
return GNUNET_SYSERR;
}
attr = GNUNET_RECLAIM_attestation_new (name_str, type, data, data_size);
diff --git a/src/reclaim/plugin_rest_reclaim.c b/src/reclaim/plugin_rest_reclaim.c
index 0800e5b20..863dd0450 100644
--- a/src/reclaim/plugin_rest_reclaim.c
+++ b/src/reclaim/plugin_rest_reclaim.c
@@ -508,8 +508,7 @@ add_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle,
handle->rest_handle->data,
handle->rest_handle->data_size);
data_json = json_loads (term_data, JSON_DECODE_ANY, &err);
- GNUNET_assert (GNUNET_OK ==
- GNUNET_JSON_parse (data_json, attrspec, NULL, NULL));
+ GNUNET_JSON_parse (data_json, attrspec, NULL, NULL);
json_decref (data_json);
if (NULL == attribute)
{
diff --git a/src/revocation/gnunet-revocation-tvg.c b/src/revocation/gnunet-revocation-tvg.c
index 23a4bf020..b8f462b28 100644
--- a/src/revocation/gnunet-revocation-tvg.c
+++ b/src/revocation/gnunet-revocation-tvg.c
@@ -34,6 +34,22 @@
#define TEST_EPOCHS 2
#define TEST_DIFFICULTY 5
+static void
+print_bytes (void *buf,
+ size_t buf_len,
+ int fold)
+{
+ int i;
+
+ for (i = 0; i < buf_len; i++)
+ {
+ if ((0 != i) && (0 != fold) && (i%fold == 0))
+ printf("\n");
+ printf("%02x", ((unsigned char*)buf)[i]);
+ }
+ printf("\n");
+}
+
/**
* Main function that will be run.
*
@@ -52,22 +68,18 @@ run (void *cls,
struct GNUNET_CRYPTO_EcdsaPublicKey id_pub;
struct GNUNET_REVOCATION_PowP pow;
struct GNUNET_REVOCATION_PowCalculationHandle *ph;
- char* data_enc;
+ struct GNUNET_TIME_Relative exp;
GNUNET_CRYPTO_ecdsa_key_create (&id_priv);
GNUNET_CRYPTO_ecdsa_key_get_public (&id_priv,
&id_pub);
- GNUNET_STRINGS_base64_encode (&id_priv,
- sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey),
- &data_enc);
- fprintf(stdout, "Zone private key (d):\n%s\n\n", data_enc);
- GNUNET_free (data_enc);
- GNUNET_STRINGS_base64_encode (&id_pub,
- sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey),
- &data_enc);
- fprintf(stdout, "Zone public key (zk):\n%s\n\n", data_enc);
- GNUNET_free (data_enc);
-
+ fprintf(stdout, "Zone private key (d, little-endian scalar):\n");
+ print_bytes (&id_priv, sizeof(id_priv), 0);
+ fprintf(stdout, "\n");
+ fprintf(stdout, "Zone public key (zk):\n");
+ print_bytes (&id_pub, sizeof(id_pub), 0);
+ fprintf(stdout, "\n");
+ memset (&pow, 0, sizeof (pow));
GNUNET_REVOCATION_pow_init (&id_priv,
&pow);
ph = GNUNET_REVOCATION_pow_start (&pow,
@@ -82,11 +94,15 @@ run (void *cls,
{
pow_passes++;
}
- GNUNET_STRINGS_base64_encode (&pow,
- sizeof (struct GNUNET_REVOCATION_PowP),
- &data_enc);
- fprintf(stdout, "Proof:\n%s\n", data_enc);
- GNUNET_free (data_enc);
+ exp = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_YEARS,
+ TEST_EPOCHS);
+ GNUNET_assert (GNUNET_OK == GNUNET_REVOCATION_check_pow (&pow,
+ TEST_DIFFICULTY,
+ exp));
+ fprintf(stdout, "Proof:\n");
+ print_bytes (&pow,
+ sizeof (pow),
+ 8);
}
diff --git a/src/revocation/revocation.conf.in b/src/revocation/revocation.conf.in
index 346168785..04393ea9f 100644
--- a/src/revocation/revocation.conf.in
+++ b/src/revocation/revocation.conf.in
@@ -13,7 +13,7 @@ UNIX_MATCH_GID = YES
# 2^25 hash operations take about 16-24h on a first-generation i7
# (using only a single-core) with SCRYPT.
# DO NOT CHANGE THIS VALUE, doing so will break the protocol!
-WORKBITS = 25
+WORKBITS = 22
EPOCH_DURATION = 356 d
DATABASE = $GNUNET_DATA_HOME/revocation.dat
diff --git a/src/revocation/revocation_api.c b/src/revocation/revocation_api.c
index 12cb63c57..3815e47b0 100644
--- a/src/revocation/revocation_api.c
+++ b/src/revocation/revocation_api.c
@@ -394,9 +394,8 @@ static unsigned int
count_leading_zeroes (const struct GNUNET_HashCode *hash)
{
unsigned int hash_count;
-
hash_count = 0;
- while ((0 == GNUNET_CRYPTO_hash_get_bit (hash, hash_count)))
+ while ((0 == GNUNET_CRYPTO_hash_get_bit_ltr (hash, hash_count)))
hash_count++;
return hash_count;
}
@@ -467,15 +466,12 @@ GNUNET_REVOCATION_check_pow (const struct GNUNET_REVOCATION_PowP *pow,
}
/**
- * First, check if any duplicates are in the PoW set
+ * First, check if PoW set is strictly monotically increasing
*/
- for (unsigned int i = 0; i < POW_COUNT; i++)
+ for (unsigned int i = 0; i < POW_COUNT-1; i++)
{
- for (unsigned int j = i + 1; j < POW_COUNT; j++)
- {
- if (pow->pow[i] == pow->pow[j])
- return GNUNET_NO;
- }
+ if (GNUNET_ntohll (pow->pow[i]) >= GNUNET_ntohll (pow->pow[i+1]))
+ return GNUNET_NO;
}
GNUNET_memcpy (&buf[sizeof(uint64_t)],
&pow->timestamp,
@@ -486,8 +482,8 @@ GNUNET_REVOCATION_check_pow (const struct GNUNET_REVOCATION_PowP *pow,
for (unsigned int i = 0; i < POW_COUNT; i++)
{
pow_val = GNUNET_ntohll (pow->pow[i]);
- GNUNET_memcpy (buf, &pow_val, sizeof(uint64_t));
- GNUNET_CRYPTO_pow_hash ("gnunet-revocation-proof-of-work",
+ GNUNET_memcpy (buf, &pow->pow[i], sizeof(uint64_t));
+ GNUNET_CRYPTO_pow_hash ("GnsRevocationPow",
buf,
sizeof(buf),
&result);
@@ -495,6 +491,7 @@ GNUNET_REVOCATION_check_pow (const struct GNUNET_REVOCATION_PowP *pow,
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Score %u with %" PRIu64 " (#%u)\n",
tmp_score, pow_val, i);
+
score += tmp_score;
}
@@ -580,9 +577,14 @@ GNUNET_REVOCATION_pow_start (struct GNUNET_REVOCATION_PowP *pow,
unsigned int difficulty)
{
struct GNUNET_REVOCATION_PowCalculationHandle *pc;
+ struct GNUNET_TIME_Relative ttl;
+
pc = GNUNET_new (struct GNUNET_REVOCATION_PowCalculationHandle);
pc->pow = pow;
+ ttl = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_YEARS,
+ epochs);
+ pc->pow->ttl = GNUNET_TIME_relative_hton (ttl);
pc->current_pow = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
UINT64_MAX);
pc->difficulty = difficulty;
@@ -590,6 +592,18 @@ GNUNET_REVOCATION_pow_start (struct GNUNET_REVOCATION_PowP *pow,
return pc;
}
+/**
+ * Comparison function for quicksort
+ *
+ * @param a left element
+ * @param b right element
+ * @return a-b
+ */
+static int
+cmp_pow_value (const void *a, const void *b)
+{
+ return ( GNUNET_ntohll(*(uint64_t*)a) - GNUNET_ntohll(*(uint64_t*)b));
+}
/**
* Calculate a key revocation valid for broadcasting for a number
@@ -609,6 +623,8 @@ GNUNET_REVOCATION_pow_round (struct GNUNET_REVOCATION_PowCalculationHandle *pc)
+ sizeof (uint64_t)] GNUNET_ALIGN;
struct GNUNET_HashCode result;
unsigned int zeros;
+ int ret;
+ uint64_t pow_nbo;
pc->current_pow++;
@@ -618,15 +634,15 @@ GNUNET_REVOCATION_pow_round (struct GNUNET_REVOCATION_PowCalculationHandle *pc)
for (unsigned int i = 0; i < POW_COUNT; i++)
if (pc->current_pow == pc->best[i].pow)
return GNUNET_NO;
-
- GNUNET_memcpy (buf, &pc->current_pow, sizeof(uint64_t));
+ pow_nbo = GNUNET_htonll (pc->current_pow);
+ GNUNET_memcpy (buf, &pow_nbo, sizeof(uint64_t));
GNUNET_memcpy (&buf[sizeof(uint64_t)],
&pc->pow->timestamp,
sizeof (uint64_t));
GNUNET_memcpy (&buf[sizeof(uint64_t) * 2],
&pc->pow->key,
sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey));
- GNUNET_CRYPTO_pow_hash ("gnunet-revocation-proof-of-work",
+ GNUNET_CRYPTO_pow_hash ("GnsRevocationPow",
buf,
sizeof(buf),
&result);
@@ -637,15 +653,22 @@ GNUNET_REVOCATION_pow_round (struct GNUNET_REVOCATION_PowCalculationHandle *pc)
{
pc->best[i].bits = zeros;
pc->best[i].pow = pc->current_pow;
- pc->pow->pow[i] = GNUNET_htonll (pc->current_pow);
+ pc->pow->pow[i] = pow_nbo;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"New best score %u with %" PRIu64 " (#%u)\n",
zeros, pc->current_pow, i);
+
break;
}
}
- return calculate_score (pc) >= pc->difficulty + pc->epochs ? GNUNET_YES :
- GNUNET_NO;
+ ret = calculate_score (pc) >= pc->difficulty + pc->epochs ? GNUNET_YES :
+ GNUNET_NO;
+ if (GNUNET_YES == ret)
+ {
+ /* Sort POWs) */
+ qsort (pc->pow->pow, POW_COUNT, sizeof (uint64_t), &cmp_pow_value);
+ }
+ return ret;
}
diff --git a/src/revocation/test_revocation.c b/src/revocation/test_revocation.c
index f193d5f6c..1c2efa60f 100644
--- a/src/revocation/test_revocation.c
+++ b/src/revocation/test_revocation.c
@@ -237,10 +237,12 @@ identity_completion_cb (void *cls,
fprintf (stderr, "All peers connected @ IDENTITY ...\n");
testpeers[0].create_id_op = GNUNET_IDENTITY_create (testpeers[0].idh,
"client",
+ NULL,
&identity_create_cb,
&testpeers[0]);
testpeers[1].create_id_op = GNUNET_IDENTITY_create (testpeers[1].idh,
"toberevoked",
+ NULL,
&identity_create_cb,
&testpeers[1]);
}
diff --git a/src/statistics/gnunet-service-statistics.c b/src/statistics/gnunet-service-statistics.c
index 5d58c3743..d40f74aaf 100644
--- a/src/statistics/gnunet-service-statistics.c
+++ b/src/statistics/gnunet-service-statistics.c
@@ -263,7 +263,7 @@ save ()
return;
}
(void) GNUNET_DISK_directory_create_for_file (fn);
- wh = GNUNET_BIO_write_open (fn);
+ wh = GNUNET_BIO_write_open_file (fn);
total = 0;
while (NULL != (se = sub_head))
{
@@ -290,10 +290,10 @@ save ()
msg->flags =
htonl (pos->persistent ? GNUNET_STATISTICS_SETFLAG_PERSISTENT : 0);
msg->value = GNUNET_htonll (pos->value);
- if (GNUNET_OK != GNUNET_BIO_write (wh, msg, size))
+ if (GNUNET_OK != GNUNET_BIO_write (wh, "statistics-save-msg", msg, size))
{
GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "write", fn);
- if (GNUNET_OK != GNUNET_BIO_write_close (wh))
+ if (GNUNET_OK != GNUNET_BIO_write_close (wh, NULL))
GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "close", fn);
wh = NULL;
}
@@ -309,7 +309,7 @@ save ()
}
if (NULL != wh)
{
- if (GNUNET_OK != GNUNET_BIO_write_close (wh))
+ if (GNUNET_OK != GNUNET_BIO_write_close (wh, NULL))
GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "close", fn);
if (0 == total)
GNUNET_break (0 == unlink (fn));
@@ -964,7 +964,7 @@ load ()
return;
}
buf = GNUNET_malloc (fsize);
- rh = GNUNET_BIO_read_open (fn);
+ rh = GNUNET_BIO_read_open_file (fn);
if (! rh)
{
GNUNET_free (buf);
diff --git a/src/testbed-logger/gnunet-service-testbed-logger.c b/src/testbed-logger/gnunet-service-testbed-logger.c
index 4e0a3cd34..81652fa4f 100644
--- a/src/testbed-logger/gnunet-service-testbed-logger.c
+++ b/src/testbed-logger/gnunet-service-testbed-logger.c
@@ -85,6 +85,7 @@ handle_log_msg (void *cls,
ms = ntohs (msg->size) - sizeof(struct GNUNET_MessageHeader);
GNUNET_BIO_write (bio,
+ "testbed-logger-handle-log-msg",
&msg[1],
ms);
GNUNET_SERVICE_client_continue (client);
@@ -108,7 +109,7 @@ shutdown_task (void *cls)
return;
}
GNUNET_break (GNUNET_OK ==
- GNUNET_BIO_write_close (bio));
+ GNUNET_BIO_write_close (bio, NULL));
}
@@ -202,7 +203,7 @@ logger_run (void *cls,
(intmax_t) pid);
GNUNET_free (hname);
GNUNET_free (dir);
- if (NULL == (bio = GNUNET_BIO_write_open (fn)))
+ if (NULL == (bio = GNUNET_BIO_write_open_file (fn)))
{
GNUNET_free (fn);
GNUNET_SCHEDULER_shutdown ();
diff --git a/src/testbed/gnunet-service-testbed_cpustatus.c b/src/testbed/gnunet-service-testbed_cpustatus.c
index e96449def..2d490ba8c 100644
--- a/src/testbed/gnunet-service-testbed_cpustatus.c
+++ b/src/testbed/gnunet-service-testbed_cpustatus.c
@@ -568,7 +568,7 @@ sample_load_task (void *cls)
ld_cpu, ld_disk, mem_usage, nproc);
if (0 < nbs)
{
- GNUNET_BIO_write (bw, str, nbs);
+ GNUNET_BIO_write (bw, "sample load task", str, nbs);
}
else
GNUNET_break (0);
@@ -612,7 +612,7 @@ GST_stats_init (const struct GNUNET_CONFIGURATION_Handle *cfg)
hostname, (intmax_t) getpid ());
GNUNET_free (stats_dir);
GNUNET_free (hostname);
- if (NULL == (bw = GNUNET_BIO_write_open (fn)))
+ if (NULL == (bw = GNUNET_BIO_write_open_file (fn)))
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
_ ("Cannot open %s for writing load statistics. "
@@ -656,7 +656,7 @@ GST_stats_destroy ()
GNUNET_SCHEDULER_cancel (sample_load_task_id);
sample_load_task_id = NULL;
}
- GNUNET_break (GNUNET_OK == GNUNET_BIO_write_close (bw));
+ GNUNET_break (GNUNET_OK == GNUNET_BIO_write_close (bw, NULL));
bw = NULL;
}
diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am
index 3028b29b4..eadb601ef 100644
--- a/src/transport/Makefile.am
+++ b/src/transport/Makefile.am
@@ -11,12 +11,10 @@ pkgcfg_DATA = \
transport.conf \
communicator-unix.conf
-if HAVE_MHD
- HTTP_SERVER_PLUGIN_LA = libgnunet_plugin_transport_http_server.la
- HTTPS_SERVER_PLUGIN_LA = libgnunet_plugin_transport_https_server.la
- HTTP_SERVER_PLUGIN_TEST = test_plugin_http_server
- HTTPS_SERVER_PLUGIN_TEST = test_plugin_https_server
-endif
+HTTP_SERVER_PLUGIN_LA = libgnunet_plugin_transport_http_server.la
+HTTPS_SERVER_PLUGIN_LA = libgnunet_plugin_transport_https_server.la
+HTTP_SERVER_PLUGIN_TEST = test_plugin_http_server
+HTTPS_SERVER_PLUGIN_TEST = test_plugin_https_server
if HAVE_LIBGNURL
HTTP_CLIENT_PLUGIN_TEST = test_plugin_http_client
@@ -36,7 +34,6 @@ CPP_GNURL=@LIBCURL_CPPFLAGS@
endif
endif
-if HAVE_MHD
if HAVE_LIBGNURL
HTTP_API_TEST = test_transport_api_http
HTTP_REVERSE_API_TEST = test_transport_api_http_reverse
@@ -76,7 +73,6 @@ endif
HTTPS_SWITCH = test_transport_address_switch_https
endif
endif
-endif
if USE_COVERAGE
AM_CFLAGS = --coverage -O0
@@ -673,13 +669,13 @@ TESTS += \
test_transport_api_timeout_udp \
test_transport_api_udp_nat \
test_transport_api_reliability_udp \
-test_quota_compliance_udp \
-test_communicator_basic-unix \
-test_communicator_basic-tcp \
-test_communicator_basic-udp \
-test_communicator_rekey-tcp \
-test_communicator_rekey-udp \
-test_communicator_backchannel-udp
+ test_quota_compliance_udp \
+ test_communicator_basic-unix \
+ test_communicator_basic-tcp \
+ test_communicator_basic-udp \
+ test_communicator_rekey-tcp \
+ test_communicator_rekey-udp \
+ test_communicator_backchannel-udp
endif
endif
diff --git a/src/transport/gnunet-communicator-tcp.c b/src/transport/gnunet-communicator-tcp.c
index bbfacbffd..e25cdf139 100644
--- a/src/transport/gnunet-communicator-tcp.c
+++ b/src/transport/gnunet-communicator-tcp.c
@@ -40,8 +40,10 @@
#include "gnunet_nt_lib.h"
#include "gnunet_nat_service.h"
#include "gnunet_statistics_service.h"
+#include "gnunet_ats_transport_service.h"
+#include "transport.h"
#include "gnunet_transport_communication_service.h"
-
+#include "gnunet_resolver_service.h"
/**
* How long do we believe our addresses to remain up (before
* the other peer should revalidate).
@@ -253,6 +255,21 @@ struct TCPFinish
GNUNET_NETWORK_STRUCT_END
+/**
+ * Struct to use as closure.
+ */
+struct ListenTask
+{
+ /**
+ * ID of listen task
+ */
+ struct GNUNET_SCHEDULER_Task *listen_task;
+
+ /**
+ * Listen socket.
+ */
+ struct GNUNET_NETWORK_Handle *listen_sock;
+};
/**
* Handle for a queue.
@@ -265,6 +282,16 @@ struct Queue
struct GNUNET_PeerIdentity target;
/**
+ * ID of listen task
+ */
+ struct GNUNET_SCHEDULER_Task *listen_task;
+
+ /**
+ * Listen socket.
+ */
+ struct GNUNET_NETWORK_Handle *listen_sock;
+
+ /**
* socket that we transmit all data with on this queue
*/
struct GNUNET_NETWORK_Handle *sock;
@@ -449,6 +476,16 @@ struct ProtoQueue
struct ProtoQueue *prev;
/**
+ * ID of listen task
+ */
+ struct GNUNET_SCHEDULER_Task *listen_task;
+
+ /**
+ * Listen socket.
+ */
+ struct GNUNET_NETWORK_Handle *listen_sock;
+
+ /**
* socket that we transmit all data with on this queue
*/
struct GNUNET_NETWORK_Handle *sock;
@@ -485,11 +522,61 @@ struct ProtoQueue
size_t ibuf_off;
};
+/**
+ * In case of port only configuration we like to bind to ipv4 and ipv6 addresses.
+ */
+struct PortOnlyIpv4Ipv6
+{
+ /**
+ * Ipv4 address we like to bind to.
+ */
+ struct sockaddr *addr_ipv4;
+
+ /**
+ * Length of ipv4 address.
+ */
+ socklen_t *addr_len_ipv4;
+
+ /**
+ * Ipv6 address we like to bind to.
+ */
+ struct sockaddr *addr_ipv6;
+
+ /**
+ * Length of ipv6 address.
+ */
+ socklen_t *addr_len_ipv6;
+
+};
/**
- * ID of listen task
+ * DLL to store the addresses we like to register at NAT service.
*/
-static struct GNUNET_SCHEDULER_Task *listen_task;
+struct Addresses
+{
+ /**
+ * Kept in a DLL.
+ */
+ struct Addresses *next;
+
+ /**
+ * Kept in a DLL.
+ */
+ struct Addresses *prev;
+
+ /**
+ * Address we like to register at NAT service.
+ */
+ struct sockaddr *addr;
+
+ /**
+ * Length of address we like to register at NAT service.
+ */
+ socklen_t addr_len;
+
+};
+
+
/**
* Maximum queue length before we stop reading towards the transport service.
@@ -512,11 +599,6 @@ static struct GNUNET_TRANSPORT_CommunicatorHandle *ch;
static struct GNUNET_CONTAINER_MultiPeerMap *queue_map;
/**
- * Listen socket.
- */
-static struct GNUNET_NETWORK_Handle *listen_sock;
-
-/**
* Our public key.
*/
static struct GNUNET_PeerIdentity my_identity;
@@ -556,6 +638,25 @@ static struct ProtoQueue *proto_head;
*/
static struct ProtoQueue *proto_tail;
+/**
+ * Handle for DNS lookup of bindto address
+ */
+struct GNUNET_RESOLVER_RequestHandle *resolve_request_handle;
+
+/**
+ * Head of DLL with addresses we like to register at NAT servcie.
+ */
+struct Addresses *addrs_head;
+
+/**
+ * Head of DLL with addresses we like to register at NAT servcie.
+ */
+struct Addresses *addrs_tail;
+
+/**
+ * Number of addresses in the DLL for register at NAT service.
+ */
+int addrs_lens;
/**
* We have been notified that our listen socket has something to
@@ -579,6 +680,10 @@ static void
queue_destroy (struct Queue *queue)
{
struct GNUNET_MQ_Handle *mq;
+ struct ListenTask *lt;
+ lt = GNUNET_new (struct ListenTask);
+ lt->listen_sock = queue->listen_sock;
+ lt->listen_task = queue->listen_task;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Disconnecting queue for peer `%s'\n",
@@ -618,11 +723,13 @@ queue_destroy (struct Queue *queue)
queue->destroyed = GNUNET_YES;
else
GNUNET_free (queue);
- if (NULL == listen_task)
- listen_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
- listen_sock,
- &listen_cb,
- NULL);
+
+ if (NULL == lt->listen_task)
+ lt->listen_task = GNUNET_SCHEDULER_add_read_net (
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ lt->listen_sock,
+ &listen_cb,
+ lt);
}
@@ -1063,7 +1170,8 @@ queue_read (void *cls)
However, we have to take into account that the plaintext buffer may have
already contained data and not jumpt too far ahead in the ciphertext.
If there is no rekey and the last message is incomplete (max > total),
- it is safe to keep the decryption so we shift by 'max' */if (GNUNET_YES == queue->rekeyed)
+ it is safe to keep the decryption so we shift by 'max' */
+ if (GNUNET_YES == queue->rekeyed)
{
max = total - old_pread_off;
queue->rekeyed = GNUNET_NO;
@@ -1095,143 +1203,276 @@ queue_read (void *cls)
queue_finish (queue);
}
+/**
+ * Convert a `struct sockaddr_in6 to a `struct sockaddr *`
+ *
+ * @param[out] sock_len set to the length of the address.
+ * @param v6 The sockaddr_in6 to be converted.
+ * @return The struct sockaddr *.
+ */
+static struct sockaddr *
+tcp_address_to_sockaddr_numeric_v6 (socklen_t *sock_len, struct sockaddr_in6 v6,
+ unsigned int port)
+{
+ struct sockaddr *in;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "1 address %s\n",
+ GNUNET_a2s (in, *sock_len));
+
+ v6.sin6_family = AF_INET6;
+ v6.sin6_port = htons ((uint16_t) port);
+#if HAVE_SOCKADDR_IN_SIN_LEN
+ v6.sin6_len = sizeof(sizeof(struct sockaddr_in6));
+#endif
+ in = GNUNET_memdup (&v6, sizeof(v6));
+ *sock_len = sizeof(struct sockaddr_in6);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "address %s\n",
+ GNUNET_a2s (in, *sock_len));
+
+ return in;
+}
/**
- * Convert TCP bind specification to a `struct sockaddr *`
+ * Convert a `struct sockaddr_in4 to a `struct sockaddr *`
*
- * @param bindto bind specification to convert
- * @param[out] sock_len set to the length of the address
- * @return converted bindto specification
+ * @param[out] sock_len set to the length of the address.
+ * @param v4 The sockaddr_in4 to be converted.
+ * @return The struct sockaddr *.
*/
static struct sockaddr *
-tcp_address_to_sockaddr (const char *bindto, socklen_t *sock_len)
+tcp_address_to_sockaddr_numeric_v4 (socklen_t *sock_len, struct sockaddr_in v4,
+ unsigned int port)
{
struct sockaddr *in;
- unsigned int port;
- char dummy[2];
- char *colon;
+
+ v4.sin_family = AF_INET;
+ v4.sin_port = htons ((uint16_t) port);
+#if HAVE_SOCKADDR_IN_SIN_LEN
+ v4.sin_len = sizeof(struct sockaddr_in);
+#endif
+ in = GNUNET_memdup (&v4, sizeof(v4));
+ *sock_len = sizeof(struct sockaddr_in);
+ return in;
+}
+
+/**
+ * Convert TCP bind specification to a `struct PortOnlyIpv4Ipv6 *`
+ *
+ * @param bindto bind specification to convert.
+ * @return The converted bindto specification.
+ */
+static struct PortOnlyIpv4Ipv6 *
+tcp_address_to_sockaddr_port_only (const char *bindto, unsigned int *port)
+{
+ struct PortOnlyIpv4Ipv6 *po;
+ struct sockaddr_in *i4;
+ struct sockaddr_in6 *i6;
+ socklen_t sock_len_ipv4;
+ socklen_t sock_len_ipv6;
+
+ /* interpreting value as just a PORT number */
+ if (*port > UINT16_MAX)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "BINDTO specification `%s' invalid: value too large for port\n",
+ bindto);
+ return NULL;
+ }
+
+ po = GNUNET_new (struct PortOnlyIpv4Ipv6);
+
+ if ((GNUNET_NO == GNUNET_NETWORK_test_pf (PF_INET6)) ||
+ (GNUNET_YES ==
+ GNUNET_CONFIGURATION_get_value_yesno (cfg,
+ COMMUNICATOR_CONFIG_SECTION,
+ "DISABLE_V6")))
+ {
+ i4 = GNUNET_malloc (sizeof(struct sockaddr_in));
+ po->addr_ipv4 = tcp_address_to_sockaddr_numeric_v4 (&sock_len_ipv4, *i4,
+ *port);
+ po->addr_len_ipv4 = &sock_len_ipv4;
+ }
+ else
+ {
+
+ i4 = GNUNET_malloc (sizeof(struct sockaddr_in));
+ po->addr_ipv4 = tcp_address_to_sockaddr_numeric_v4 (&sock_len_ipv4, *i4,
+ *port);
+ po->addr_len_ipv4 = &sock_len_ipv4;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "3.5 address %s\n",
+ GNUNET_a2s (po->addr_ipv4, sock_len_ipv4));
+
+ i6 = GNUNET_malloc (sizeof(struct sockaddr_in6));
+ po->addr_ipv6 = tcp_address_to_sockaddr_numeric_v6 (&sock_len_ipv6, *i6,
+ *port);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "3 address %s\n",
+ GNUNET_a2s (po->addr_ipv6, sock_len_ipv6));
+
+ po->addr_len_ipv6 = &sock_len_ipv6;
+ }
+ return po;
+}
+
+/**
+ * This Method extracts the address part of the BINDTO string.
+ *
+ * @param bindto String we extract the address part from.
+ * @return The extracted address string.
+ */
+static char *
+extract_address (const char *bindto)
+{
+
+ char *start;
+ char *token;
char *cp;
+ char *rest = NULL;
- if (1 == sscanf (bindto, "%u%1s", &port, dummy))
+ if (NULL == bindto)
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "bindto is NULL\n");
+
+ cp = GNUNET_strdup (bindto);
+ start = cp;
+ if (('[' == *cp) && (']' == cp[strlen (cp) - 1]))
{
- /* interpreting value as just a PORT number */
- if (port > UINT16_MAX)
+ start++; /* skip over '['*/
+ cp[strlen (cp) - 1] = '\0'; /* eat ']'*/
+ }
+ else {
+ token = strtok_r (cp, "]", &rest);
+ if (strlen (bindto) == strlen (token))
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "BINDTO specification `%s' invalid: value too large for port\n",
- bindto);
- return NULL;
+ token = strtok_r (cp, ":", &rest);
}
- if ((GNUNET_NO == GNUNET_NETWORK_test_pf (PF_INET6)) ||
- (GNUNET_YES ==
- GNUNET_CONFIGURATION_get_value_yesno (cfg,
- COMMUNICATOR_CONFIG_SECTION,
- "DISABLE_V6")))
+ else
{
- struct sockaddr_in *i4;
+ token++;
+ return token;
+ }
+ }
- i4 = GNUNET_malloc (sizeof(struct sockaddr_in));
- i4->sin_family = AF_INET;
- i4->sin_port = htons ((uint16_t) port);
-#if HAVE_SOCKADDR_IN_SIN_LEN
- i4->sin_len = sizeof(sizeof(struct sockaddr_in));
-#endif
- *sock_len = sizeof(struct sockaddr_in);
- in = (struct sockaddr *) i4;
+ // GNUNET_free(cp);
+
+ return start;
+}
+
+/**
+ * This Method extracts the port part of the BINDTO string.
+ *
+ * @param addr_and_port String we extract the port from.
+ * @return The extracted port as unsigned int.
+ */
+static unsigned int
+extract_port (const char *addr_and_port)
+{
+ unsigned int port;
+ char dummy[2];
+ char *token;
+ char *addr;
+ char *colon;
+ char *cp;
+ char *rest = NULL;
+
+ if (NULL != addr_and_port)
+ {
+ cp = GNUNET_strdup (addr_and_port);
+ token = strtok_r (cp, "]", &rest);
+ if (strlen (addr_and_port) == strlen (token))
+ {
+ colon = strrchr (cp, ':');
+ if (NULL == colon)
+ {
+ return 0;
+ }
+ addr = colon;
+ addr++;
}
else
{
- struct sockaddr_in6 *i6;
-
- i6 = GNUNET_malloc (sizeof(struct sockaddr_in6));
- i6->sin6_family = AF_INET6;
- i6->sin6_port = htons ((uint16_t) port);
-#if HAVE_SOCKADDR_IN_SIN_LEN
- i6->sin6_len = sizeof(sizeof(struct sockaddr_in6));
-#endif
- *sock_len = sizeof(struct sockaddr_in6);
- in = (struct sockaddr *) i6;
+ token = strtok_r (NULL, "]", &rest);
+ if (NULL == token)
+ {
+ return 0;
+ }
+ else
+ {
+ addr = token;
+ addr++;
+ }
}
- return in;
- }
- cp = GNUNET_strdup (bindto);
- colon = strrchr (cp, ':');
- if (NULL != colon)
- {
- /* interpet value after colon as port */
- *colon = '\0';
- colon++;
- if (1 == sscanf (colon, "%u%1s", &port, dummy))
+
+
+ if (1 == sscanf (addr, "%u%1s", &port, dummy))
{
/* interpreting value as just a PORT number */
if (port > UINT16_MAX)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "BINDTO specification `%s' invalid: value too large for port\n",
- bindto);
- GNUNET_free (cp);
- return NULL;
+ "Port `%u' invalid: value too large for port\n",
+ port);
+ // GNUNET_free (cp);
+ return 0;
}
}
else
{
- GNUNET_log (
- GNUNET_ERROR_TYPE_ERROR,
- "BINDTO specification `%s' invalid: last ':' not followed by number\n",
- bindto);
- GNUNET_free (cp);
- return NULL;
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "BINDTO specification invalid: last ':' not followed by number\n");
+ // GNUNET_free (cp);
+ return 0;
}
}
else
{
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "return 0\n");
/* interpret missing port as 0, aka pick any free one */
port = 0;
}
- {
- /* try IPv4 */
- struct sockaddr_in v4;
- if (1 == inet_pton (AF_INET, cp, &v4.sin_addr))
- {
- v4.sin_family = AF_INET;
- v4.sin_port = htons ((uint16_t) port);
-#if HAVE_SOCKADDR_IN_SIN_LEN
- v4.sin_len = sizeof(struct sockaddr_in);
-#endif
- in = GNUNET_memdup (&v4, sizeof(v4));
- *sock_len = sizeof(v4);
- GNUNET_free (cp);
- return in;
- }
+
+ return port;
+}
+
+/**
+ * Convert TCP bind specification to a `struct sockaddr *`
+ *
+ * @param bindto bind specification to convert
+ * @param[out] sock_len set to the length of the address
+ * @return converted bindto specification
+ */
+static struct sockaddr *
+tcp_address_to_sockaddr (const char *bindto, socklen_t *sock_len)
+{
+ struct sockaddr *in;
+ unsigned int port;
+ struct sockaddr_in v4;
+ struct sockaddr_in6 v6;
+ const char *start;
+
+ // cp = GNUNET_strdup (bindto);
+ start = extract_address (bindto);
+
+ if (1 == inet_pton (AF_INET, start, &v4.sin_addr))
+ {
+ // colon = strrchr (cp, ':');
+ port = extract_port (bindto);
+ in = tcp_address_to_sockaddr_numeric_v4 (sock_len, v4, port);
}
+ else if (1 == inet_pton (AF_INET6, start, &v6.sin6_addr))
{
- /* try IPv6 */
- struct sockaddr_in6 v6;
- const char *start;
-
- start = cp;
- if (('[' == *cp) && (']' == cp[strlen (cp) - 1]))
- {
- start++; /* skip over '[' */
- cp[strlen (cp) - 1] = '\0'; /* eat ']' */
- }
- if (1 == inet_pton (AF_INET6, start, &v6.sin6_addr))
- {
- v6.sin6_family = AF_INET6;
- v6.sin6_port = htons ((uint16_t) port);
-#if HAVE_SOCKADDR_IN_SIN_LEN
- v6.sin6_len = sizeof(sizeof(struct sockaddr_in6));
-#endif
- in = GNUNET_memdup (&v6, sizeof(v6));
- *sock_len = sizeof(v6);
- GNUNET_free (cp);
- return in;
- }
+ // colon = strrchr (cp, ':');
+ port = extract_port (bindto);
+ in = tcp_address_to_sockaddr_numeric_v6 (sock_len, v6, port);
}
- /* #5528 FIXME (feature!): maybe also try getnameinfo()? */
- GNUNET_free (cp);
- return NULL;
+
+ return in;
}
@@ -1547,6 +1788,8 @@ boot_queue (struct Queue *queue, enum GNUNET_TRANSPORT_ConnectionStatus cs)
&queue->target,
foreign_addr,
0 /* no MTU */,
+ GNUNET_TRANSPORT_QUEUE_LENGTH_UNLIMITED,
+ 0, /* Priority */
queue->nt,
cs,
queue->mq);
@@ -1665,6 +1908,16 @@ decrypt_and_check_tc (struct Queue *queue,
static void
free_proto_queue (struct ProtoQueue *pq)
{
+ if (NULL != pq->listen_task)
+ {
+ GNUNET_SCHEDULER_cancel (pq->listen_task);
+ pq->listen_task = NULL;
+ }
+ if (NULL != pq->listen_sock)
+ {
+ GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (pq->listen_sock));
+ pq->listen_sock = NULL;
+ }
GNUNET_NETWORK_socket_close (pq->sock);
GNUNET_free (pq->address);
GNUNET_CONTAINER_DLL_remove (proto_head, proto_tail, pq);
@@ -1737,6 +1990,8 @@ proto_read_kx (void *cls)
queue->address = pq->address; /* steals reference */
queue->address_len = pq->address_len;
queue->target = tc.sender;
+ queue->listen_task = pq->listen_task;
+ queue->listen_sock = pq->listen_sock;
queue->sock = pq->sock;
start_initial_kx_out (queue);
boot_queue (queue, GNUNET_TRANSPORT_CS_INBOUND);
@@ -1760,7 +2015,7 @@ proto_read_kx (void *cls)
* read. Do the read and reschedule this function to be called again
* once more is available.
*
- * @param cls NULL
+ * @param cls ListenTask with listening socket and task
*/
static void
listen_cb (void *cls)
@@ -1769,20 +2024,23 @@ listen_cb (void *cls)
socklen_t addrlen;
struct GNUNET_NETWORK_Handle *sock;
struct ProtoQueue *pq;
+ struct ListenTask *lt;
- listen_task = NULL;
- GNUNET_assert (NULL != listen_sock);
+ lt = cls;
+
+ lt->listen_task = NULL;
+ GNUNET_assert (NULL != lt->listen_sock);
addrlen = sizeof(in);
memset (&in, 0, sizeof(in));
- sock = GNUNET_NETWORK_socket_accept (listen_sock,
+ sock = GNUNET_NETWORK_socket_accept (lt->listen_sock,
(struct sockaddr*) &in,
&addrlen);
if ((NULL == sock) && ((EMFILE == errno) || (ENFILE == errno)))
return; /* system limit reached, wait until connection goes down */
- listen_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
- listen_sock,
- &listen_cb,
- NULL);
+ lt->listen_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ lt->listen_sock,
+ &listen_cb,
+ lt);
if ((NULL == sock) && ((EAGAIN == errno) || (ENOBUFS == errno)))
return;
if (NULL == sock)
@@ -1882,7 +2140,6 @@ queue_read_kx (void *cls)
queue->read_task = GNUNET_SCHEDULER_add_now (&queue_read, queue);
}
-
/**
* Function called by the transport service to initialize a
* message queue given address information about another peer.
@@ -1922,6 +2179,13 @@ mq_init (void *cls, const struct GNUNET_PeerIdentity *peer, const char *address)
path = &address[strlen (COMMUNICATOR_ADDRESS_PREFIX "-")];
in = tcp_address_to_sockaddr (path, &in_len);
+ if (NULL == in)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to setup TCP socket address\n");
+ return GNUNET_SYSERR;
+ }
+
sock = GNUNET_NETWORK_socket_create (in->sa_family, SOCK_STREAM, IPPROTO_TCP);
if (NULL == sock)
{
@@ -1965,7 +2229,6 @@ mq_init (void *cls, const struct GNUNET_PeerIdentity *peer, const char *address)
return GNUNET_OK;
}
-
/**
* Iterator over all message queues to clean up.
*
@@ -2003,16 +2266,6 @@ do_shutdown (void *cls)
GNUNET_NAT_unregister (nat);
nat = NULL;
}
- if (NULL != listen_task)
- {
- GNUNET_SCHEDULER_cancel (listen_task);
- listen_task = NULL;
- }
- if (NULL != listen_sock)
- {
- GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (listen_sock));
- listen_sock = NULL;
- }
GNUNET_CONTAINER_multipeermap_iterate (queue_map, &get_queue_delete_it, NULL);
GNUNET_CONTAINER_multipeermap_destroy (queue_map);
if (NULL != ch)
@@ -2085,6 +2338,10 @@ nat_address_cb (void *cls,
char *my_addr;
struct GNUNET_TRANSPORT_AddressIdentifier *ai;
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "1 nat_address %s\n",
+ GNUNET_a2s (addr, addrlen));
+
if (GNUNET_YES == add_remove)
{
enum GNUNET_NetworkType nt;
@@ -2110,80 +2367,53 @@ nat_address_cb (void *cls,
}
}
-
/**
- * Setup communicator and launch network interactions.
+ * This method launch network interactions for each address we like to bind to.
*
- * @param cls NULL (always)
- * @param args remaining command-line arguments
- * @param cfgfile name of the configuration file used (for saving, can be NULL!)
- * @param c configuration
+ * @param addr The address we will listen to.
+ * @param in_len The length of the address we will listen to.
+ * @return GNUNET_SYSERR in case of error. GNUNET_OK in case we are successfully listen to the address.
*/
-static void
-run (void *cls,
- char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *c)
+static int
+init_socket (const struct sockaddr *addr,
+ socklen_t in_len)
{
- char *bindto;
- struct sockaddr *in;
- socklen_t in_len;
struct sockaddr_storage in_sto;
socklen_t sto_len;
+ struct GNUNET_NETWORK_Handle *listen_sock;
+ struct ListenTask *lt;
- (void) cls;
- cfg = c;
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (cfg,
- COMMUNICATOR_CONFIG_SECTION,
- "BINDTO",
- &bindto))
- {
- GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- COMMUNICATOR_CONFIG_SECTION,
- "BINDTO");
- return;
- }
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_number (cfg,
- COMMUNICATOR_CONFIG_SECTION,
- "MAX_QUEUE_LENGTH",
- &max_queue_length))
- max_queue_length = DEFAULT_MAX_QUEUE_LENGTH;
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_time (cfg,
- COMMUNICATOR_CONFIG_SECTION,
- "REKEY_INTERVAL",
- &rekey_interval))
- rekey_interval = DEFAULT_REKEY_INTERVAL;
-
- in = tcp_address_to_sockaddr (bindto, &in_len);
- if (NULL == in)
+ if (NULL == addr)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to setup TCP socket address with path `%s'\n",
- bindto);
- GNUNET_free (bindto);
- return;
+ "Address is NULL.\n");
+ return GNUNET_SYSERR;
}
+
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "4 address %s\n",
+ GNUNET_a2s (addr, in_len));
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "address %s\n",
+ GNUNET_a2s (addr, in_len));
+
listen_sock =
- GNUNET_NETWORK_socket_create (in->sa_family, SOCK_STREAM, IPPROTO_TCP);
+ GNUNET_NETWORK_socket_create (addr->sa_family, SOCK_STREAM, IPPROTO_TCP);
if (NULL == listen_sock)
{
GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket");
- GNUNET_free (in);
- GNUNET_free (bindto);
- return;
+ return GNUNET_SYSERR;
}
- if (GNUNET_OK != GNUNET_NETWORK_socket_bind (listen_sock, in, in_len))
+
+ if (GNUNET_OK != GNUNET_NETWORK_socket_bind (listen_sock, addr, in_len))
{
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "bind", bindto);
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind");
GNUNET_NETWORK_socket_close (listen_sock);
listen_sock = NULL;
- GNUNET_free (in);
- GNUNET_free (bindto);
- return;
+ return GNUNET_SYSERR;
}
+
if (GNUNET_OK !=
GNUNET_NETWORK_socket_listen (listen_sock,
5))
@@ -2192,69 +2422,311 @@ run (void *cls,
"listen");
GNUNET_NETWORK_socket_close (listen_sock);
listen_sock = NULL;
- GNUNET_free (in);
- GNUNET_free (bindto);
+ return GNUNET_SYSERR;
}
+
/* We might have bound to port 0, allowing the OS to figure it out;
thus, get the real IN-address from the socket */
sto_len = sizeof(in_sto);
+
if (0 != getsockname (GNUNET_NETWORK_get_fd (listen_sock),
(struct sockaddr *) &in_sto,
&sto_len))
{
- memcpy (&in_sto, in, in_len);
+ memcpy (&in_sto, addr, in_len);
sto_len = in_len;
}
- GNUNET_free (in);
- GNUNET_free (bindto);
- in = (struct sockaddr *) &in_sto;
+
+ addr = (struct sockaddr *) &in_sto;
in_len = sto_len;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Bound to `%s'\n",
GNUNET_a2s ((const struct sockaddr *) &in_sto, sto_len));
stats = GNUNET_STATISTICS_create ("C-TCP", cfg);
GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
- is = GNUNET_NT_scanner_init ();
- my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_configuration (cfg);
+
+ if (NULL == is)
+ is = GNUNET_NT_scanner_init ();
+
+ if (NULL == my_private_key)
+ my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_configuration (cfg);
if (NULL == my_private_key)
{
GNUNET_log (
GNUNET_ERROR_TYPE_ERROR,
_ (
"Transport service is lacking key configuration settings. Exiting.\n"));
+ GNUNET_RESOLVER_request_cancel (resolve_request_handle);
GNUNET_SCHEDULER_shutdown ();
- return;
+ return GNUNET_SYSERR;
}
GNUNET_CRYPTO_eddsa_key_get_public (my_private_key, &my_identity.public_key);
/* start listening */
- listen_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
- listen_sock,
- &listen_cb,
- NULL);
- queue_map = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO);
- ch = GNUNET_TRANSPORT_communicator_connect (cfg,
- COMMUNICATOR_CONFIG_SECTION,
- COMMUNICATOR_ADDRESS_PREFIX,
- GNUNET_TRANSPORT_CC_RELIABLE,
- &mq_init,
- NULL,
- &enc_notify_cb,
- NULL);
+
+ lt = GNUNET_new (struct ListenTask);
+ lt->listen_sock = listen_sock;
+
+ lt->listen_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ listen_sock,
+ &listen_cb,
+ lt);
+
+ if (NULL == queue_map)
+ queue_map = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO);
+
+ if (NULL == ch )
+ ch = GNUNET_TRANSPORT_communicator_connect (cfg,
+ COMMUNICATOR_CONFIG_SECTION,
+ COMMUNICATOR_ADDRESS_PREFIX,
+ GNUNET_TRANSPORT_CC_RELIABLE,
+ &mq_init,
+ NULL,
+ &enc_notify_cb,
+ NULL);
+
if (NULL == ch)
{
GNUNET_break (0);
+ GNUNET_RESOLVER_request_cancel (resolve_request_handle);
GNUNET_SCHEDULER_shutdown ();
- return;
+ return GNUNET_SYSERR;
+ }
+
+ return GNUNET_OK;
+
+}
+
+/**
+ * This method reads from the DLL addrs_head to register them at the NAT service.
+ */
+static void
+nat_register ()
+{
+
+ struct sockaddr **saddrs;
+ socklen_t *saddr_lens;
+ int i;
+ struct Addresses *pos;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "nat here\n");
+
+ i = 0;
+ saddrs = GNUNET_malloc ((addrs_lens + 1) * sizeof(struct sockaddr *));
+
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "2 nat here\n");
+
+ saddr_lens = GNUNET_malloc ((addrs_lens + 1) * sizeof(socklen_t));
+
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "3 nat here\n");
+
+ for (pos = addrs_head; NULL != pos; pos = pos->next)
+ {
+
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "5 nat here\n");
+
+ saddr_lens[i] = addrs_head->addr_len;
+ saddrs[i] = GNUNET_malloc (saddr_lens[i]);
+ saddrs[i] = addrs_head->addr;
+
+ i++;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "6 nat here\n");
+
}
+
nat = GNUNET_NAT_register (cfg,
COMMUNICATOR_CONFIG_SECTION,
IPPROTO_TCP,
- 1 /* one address */,
- (const struct sockaddr **) &in,
- &in_len,
+ addrs_lens,
+ (const struct sockaddr **) saddrs,
+ saddr_lens,
&nat_address_cb,
NULL /* FIXME: support reversal: #5529 */,
NULL /* closure */);
+
+ if (NULL == nat)
+ {
+ GNUNET_break (0);
+ GNUNET_RESOLVER_request_cancel (resolve_request_handle);
+ GNUNET_SCHEDULER_shutdown ();
+ }
+}
+
+/**
+ * This method adds addresses to the DLL, that are later register at the NAT service.
+ */
+static void
+add_addr (struct sockaddr *in, socklen_t in_len)
+{
+
+ struct Addresses *saddrs;
+
+ saddrs = GNUNET_new (struct Addresses);
+ saddrs->addr = in;
+ saddrs->addr_len = in_len;
+ GNUNET_CONTAINER_DLL_insert (addrs_head, addrs_tail, saddrs);
+ addrs_lens++;
+}
+
+/**
+ * This method is the callback called by the resolver API, and wraps method init_socket.
+ *
+ * @param cls The port we will bind to.
+ * @param addr The address we will bind to.
+ * @param in_len The length of the address we will bind to.
+ */
+static void
+init_socket_resolv (void *cls,
+ const struct sockaddr *addr,
+ socklen_t in_len)
+{
+ struct sockaddr_in *v4;
+ struct sockaddr_in6 *v6;
+ struct sockaddr *in;
+ unsigned int *port;
+
+ port = cls;
+ if (NULL != addr)
+ {
+ if (AF_INET == addr->sa_family)
+ {
+ v4 = (struct sockaddr_in *) addr;
+ in = tcp_address_to_sockaddr_numeric_v4 (&in_len, *v4, *port);// _global);
+ add_addr (in, in_len);
+ }
+ else if (AF_INET6 == addr->sa_family)
+ {
+ v6 = (struct sockaddr_in6 *) addr;
+ in = tcp_address_to_sockaddr_numeric_v6 (&in_len, *v6, *port);// _global);
+ add_addr (in, in_len);
+ }
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Address family %u not suitable (not AF_INET %u nor AF_INET6 %u \n",
+ addr->sa_family,
+ AF_INET,
+ AF_INET6);
+ return;
+ }
+ init_socket (in,
+ in_len);
+ }
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Address is NULL. This might be an error or the resolver finished resolving.\n");
+ nat_register ();
+ }
+}
+
+/**
+ * Setup communicator and launch network interactions.
+ *
+ * @param cls NULL (always)
+ * @param args remaining command-line arguments
+ * @param cfgfile name of the configuration file used (for saving, can be NULL!)
+ * @param c configuration
+ */
+static void
+run (void *cls,
+ char *const *args,
+ const char *cfgfile,
+ const struct GNUNET_CONFIGURATION_Handle *c)
+{
+ char *bindto;
+ struct sockaddr *in;
+ socklen_t in_len;
+ struct sockaddr_in v4;
+ struct sockaddr_in6 v6;
+ char *start;
+ unsigned int port;
+ char dummy[2];
+ char *rest = NULL;
+ struct PortOnlyIpv4Ipv6 *po;
+
+ (void) cls;
+ cfg = c;
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (cfg,
+ COMMUNICATOR_CONFIG_SECTION,
+ "BINDTO",
+ &bindto))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ COMMUNICATOR_CONFIG_SECTION,
+ "BINDTO");
+ return;
+ }
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_number (cfg,
+ COMMUNICATOR_CONFIG_SECTION,
+ "MAX_QUEUE_LENGTH",
+ &max_queue_length))
+ max_queue_length = DEFAULT_MAX_QUEUE_LENGTH;
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_time (cfg,
+ COMMUNICATOR_CONFIG_SECTION,
+ "REKEY_INTERVAL",
+ &rekey_interval))
+ rekey_interval = DEFAULT_REKEY_INTERVAL;
+
+
+ // cp = GNUNET_strdup (bindto);
+ start = extract_address (bindto);
+
+ if (1 == sscanf (bindto, "%u%1s", &port, dummy))
+ {
+ po = tcp_address_to_sockaddr_port_only (bindto, &port);
+
+ if (NULL != &po->addr_ipv4)
+ {
+ init_socket (po->addr_ipv4, *po->addr_len_ipv4);
+ add_addr (po->addr_ipv4, *po->addr_len_ipv4);
+ }
+
+ if (NULL != &po->addr_ipv6)
+ {
+ init_socket (po->addr_ipv6, *po->addr_len_ipv6);
+ add_addr (po->addr_ipv6, *po->addr_len_ipv6);
+ }
+
+ nat_register ();
+ }
+ else if (1 == inet_pton (AF_INET, start, &v4.sin_addr))
+ {
+ port = extract_port (bindto);
+
+ in = tcp_address_to_sockaddr_numeric_v4 (&in_len, v4, port);
+ init_socket (in, in_len);
+ add_addr (in, in_len);
+ nat_register ();
+ }
+ else if (1 == inet_pton (AF_INET6, start, &v6.sin6_addr))
+ {
+ port = extract_port (bindto);
+ in = tcp_address_to_sockaddr_numeric_v6 (&in_len, v6, port);
+ init_socket (in, in_len);
+ add_addr (in, in_len);
+ nat_register ();
+ }
+ else
+ {
+ port = extract_port (bindto);
+
+ resolve_request_handle = GNUNET_RESOLVER_ip_get (strtok_r (bindto, ":",
+ &rest),
+ AF_UNSPEC,
+ GNUNET_TIME_UNIT_MINUTES,
+ &init_socket_resolv,
+ &port);
+ }
+ GNUNET_free (bindto);
}
diff --git a/src/transport/gnunet-communicator-udp.c b/src/transport/gnunet-communicator-udp.c
index 72e84567a..585b29c2d 100644
--- a/src/transport/gnunet-communicator-udp.c
+++ b/src/transport/gnunet-communicator-udp.c
@@ -549,14 +549,24 @@ struct ReceiverAddress
struct GNUNET_CONTAINER_HeapNode *hn;
/**
- * Message queue we are providing for the #ch.
+ * KX message queue we are providing for the #ch.
*/
- struct GNUNET_MQ_Handle *mq;
+ struct GNUNET_MQ_Handle *kx_mq;
+
+ /**
+ * Default message queue we are providing for the #ch.
+ */
+ struct GNUNET_MQ_Handle *d_mq;
/**
- * handle for this queue with the #ch.
+ * handle for KX queue with the #ch.
*/
- struct GNUNET_TRANSPORT_QueueHandle *qh;
+ struct GNUNET_TRANSPORT_QueueHandle *kx_qh;
+
+ /**
+ * handle for default queue with the #ch.
+ */
+ struct GNUNET_TRANSPORT_QueueHandle *d_qh;
/**
* Timeout for this receiver address.
@@ -564,9 +574,14 @@ struct ReceiverAddress
struct GNUNET_TIME_Absolute timeout;
/**
- * MTU we allowed transport for this receiver right now.
+ * MTU we allowed transport for this receiver's KX queue.
*/
- size_t mtu;
+ size_t kx_mtu;
+
+ /**
+ * MTU we allowed transport for this receiver's default queue.
+ */
+ size_t d_mtu;
/**
* Length of the DLL at @a ss_head.
@@ -786,15 +801,25 @@ receiver_destroy (struct ReceiverAddress *receiver)
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Disconnecting receiver for peer `%s'\n",
GNUNET_i2s (&receiver->target));
- if (NULL != (mq = receiver->mq))
+ if (NULL != (mq = receiver->kx_mq))
+ {
+ receiver->kx_mq = NULL;
+ GNUNET_MQ_destroy (mq);
+ }
+ if (NULL != receiver->kx_qh)
+ {
+ GNUNET_TRANSPORT_communicator_mq_del (receiver->kx_qh);
+ receiver->kx_qh = NULL;
+ }
+ if (NULL != (mq = receiver->d_mq))
{
- receiver->mq = NULL;
+ receiver->d_mq = NULL;
GNUNET_MQ_destroy (mq);
}
- if (NULL != receiver->qh)
+ if (NULL != receiver->d_qh)
{
- GNUNET_TRANSPORT_communicator_mq_del (receiver->qh);
- receiver->qh = NULL;
+ GNUNET_TRANSPORT_communicator_mq_del (receiver->d_qh);
+ receiver->d_qh = NULL;
}
GNUNET_assert (GNUNET_YES ==
GNUNET_CONTAINER_multipeermap_remove (receivers,
@@ -1030,6 +1055,8 @@ check_timeouts (void *cls)
rt = GNUNET_TIME_absolute_get_remaining (receiver->timeout);
if (0 != rt.rel_value_us)
break;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Receiver timed out\n");
receiver_destroy (receiver);
}
st = GNUNET_TIME_UNIT_FOREVER_REL;
@@ -1257,6 +1284,8 @@ handle_ack (void *cls, const struct GNUNET_PeerIdentity *pid, void *value)
{
const struct UDPAck *ack = cls;
struct ReceiverAddress *receiver = value;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "in handle ack\n");
(void) pid;
for (struct SharedSecret *ss = receiver->ss_head; NULL != ss; ss = ss->next)
@@ -1264,17 +1293,24 @@ handle_ack (void *cls, const struct GNUNET_PeerIdentity *pid, void *value)
if (0 == memcmp (&ack->cmac, &ss->cmac, sizeof(struct GNUNET_HashCode)))
{
uint32_t allowed;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Found matching mac\n");
allowed = ntohl (ack->sequence_max);
if (allowed > ss->sequence_allowed)
{
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "%u > %u (%u)\n", allowed, ss->sequence_allowed,
+ receiver->acks_available);
+
receiver->acks_available += (allowed - ss->sequence_allowed);
- if ((allowed - ss->sequence_allowed) == receiver->acks_available)
- {
- /* we just incremented from zero => MTU change! */
- setup_receiver_mq (receiver);
- }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Tell transport we have more acks!\n");
+ GNUNET_TRANSPORT_communicator_mq_update (ch,
+ receiver->d_qh,
+ (allowed - ss->sequence_allowed),
+ 1);
ss->sequence_allowed = allowed;
/* move ss to head to avoid discarding it anytime soon! */
GNUNET_CONTAINER_DLL_remove (receiver->ss_head, receiver->ss_tail, ss);
@@ -1361,6 +1397,9 @@ consider_ss_ack (struct SharedSecret *ss)
ack.header.size = htons (sizeof(ack));
ack.sequence_max = htonl (ss->sequence_allowed);
ack.cmac = ss->cmac;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Notifying transport of UDPAck %s\n",
+ GNUNET_i2s_full (&ss->sender->target));
GNUNET_TRANSPORT_communicator_notify (ch,
&ss->sender->target,
COMMUNICATOR_ADDRESS_PREFIX,
@@ -1889,15 +1928,24 @@ do_pad (gcry_cipher_hd_t out_cipher, char *dgram, size_t pad_size)
* @param impl_state our `struct ReceiverAddress`
*/
static void
-mq_send (struct GNUNET_MQ_Handle *mq,
- const struct GNUNET_MessageHeader *msg,
- void *impl_state)
+mq_send_kx (struct GNUNET_MQ_Handle *mq,
+ const struct GNUNET_MessageHeader *msg,
+ void *impl_state)
{
struct ReceiverAddress *receiver = impl_state;
uint16_t msize = ntohs (msg->size);
+ struct UdpHandshakeSignature uhs;
+ struct UDPConfirmation uc;
+ struct InitialKX kx;
+ struct GNUNET_CRYPTO_EcdhePrivateKey epriv;
+ char dgram[receiver->kx_mtu + sizeof(uc) + sizeof(kx)];
+ size_t dpos;
+ gcry_cipher_hd_t out_cipher;
+ struct SharedSecret *ss;
- GNUNET_assert (mq == receiver->mq);
- if (msize > receiver->mtu)
+
+ GNUNET_assert (mq == receiver->kx_mq);
+ if (msize > receiver->kx_mtu)
{
GNUNET_break (0);
receiver_destroy (receiver);
@@ -1905,117 +1953,125 @@ mq_send (struct GNUNET_MQ_Handle *mq,
}
reschedule_receiver_timeout (receiver);
- if (0 == receiver->acks_available)
+ /* setup key material */
+ GNUNET_CRYPTO_ecdhe_key_create (&epriv);
+
+ ss = setup_shared_secret_enc (&epriv, receiver);
+ setup_cipher (&ss->master, 0, &out_cipher);
+ /* compute 'uc' */
+ uc.sender = my_identity;
+ uc.monotonic_time =
+ GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get_monotonic (cfg));
+ uhs.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_UDP_HANDSHAKE);
+ uhs.purpose.size = htonl (sizeof(uhs));
+ uhs.sender = my_identity;
+ uhs.receiver = receiver->target;
+ GNUNET_CRYPTO_ecdhe_key_get_public (&epriv, &uhs.ephemeral);
+ uhs.monotonic_time = uc.monotonic_time;
+ GNUNET_CRYPTO_eddsa_sign (my_private_key,
+ &uhs,
+ &uc.sender_sig);
+ /* Leave space for kx */
+ dpos = sizeof(kx);
+ /* Append encrypted uc to dgram */
+ GNUNET_assert (0 == gcry_cipher_encrypt (out_cipher,
+ &dgram[dpos],
+ sizeof(uc),
+ &uc,
+ sizeof(uc)));
+ dpos += sizeof(uc);
+ /* Append encrypted payload to dgram */
+ GNUNET_assert (
+ 0 == gcry_cipher_encrypt (out_cipher, &dgram[dpos], msize, msg, msize));
+ dpos += msize;
+ do_pad (out_cipher, &dgram[dpos], sizeof(dgram) - dpos);
+ /* Datagram starts with kx */
+ kx.ephemeral = uhs.ephemeral;
+ GNUNET_assert (
+ 0 == gcry_cipher_gettag (out_cipher, kx.gcm_tag, sizeof(kx.gcm_tag)));
+ gcry_cipher_close (out_cipher);
+ memcpy (dgram, &kx, sizeof(kx));
+ if (-1 == GNUNET_NETWORK_socket_sendto (udp_sock,
+ dgram,
+ sizeof(dgram),
+ receiver->address,
+ receiver->address_len))
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "send");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Sending KX to %s\n", GNUNET_a2s (receiver->address,
+ receiver->address_len));
+ GNUNET_MQ_impl_send_continue (mq);
+}
+
+
+/**
+ * Signature of functions implementing the sending functionality of a
+ * message queue.
+ *
+ * @param mq the message queue
+ * @param msg the message to send
+ * @param impl_state our `struct ReceiverAddress`
+ */
+static void
+mq_send_d (struct GNUNET_MQ_Handle *mq,
+ const struct GNUNET_MessageHeader *msg,
+ void *impl_state)
+{
+ struct ReceiverAddress *receiver = impl_state;
+ uint16_t msize = ntohs (msg->size);
+
+ GNUNET_assert (mq == receiver->d_mq);
+ if ((msize > receiver->d_mtu) ||
+ (0 == receiver->acks_available))
{
- /* use KX encryption method */
- struct UdpHandshakeSignature uhs;
- struct UDPConfirmation uc;
- struct InitialKX kx;
- struct GNUNET_CRYPTO_EcdhePrivateKey epriv;
- char dgram[receiver->mtu + sizeof(uc) + sizeof(kx)];
- size_t dpos;
- gcry_cipher_hd_t out_cipher;
- struct SharedSecret *ss;
+ GNUNET_break (0);
+ receiver_destroy (receiver);
+ return;
+ }
+ reschedule_receiver_timeout (receiver);
- /* setup key material */
- GNUNET_CRYPTO_ecdhe_key_create (&epriv);
+ /* begin "BOX" encryption method, scan for ACKs from tail! */
+ for (struct SharedSecret *ss = receiver->ss_tail; NULL != ss; ss = ss->prev)
+ {
+ if (ss->sequence_used >= ss->sequence_allowed)
+ {
+ continue;
+ }
+ char dgram[sizeof(struct UDPBox) + receiver->d_mtu];
+ struct UDPBox *box;
+ gcry_cipher_hd_t out_cipher;
+ size_t dpos;
- ss = setup_shared_secret_enc (&epriv, receiver);
- setup_cipher (&ss->master, 0, &out_cipher);
- /* compute 'uc' */
- uc.sender = my_identity;
- uc.monotonic_time =
- GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get_monotonic (cfg));
- uhs.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_UDP_HANDSHAKE);
- uhs.purpose.size = htonl (sizeof(uhs));
- uhs.sender = my_identity;
- uhs.receiver = receiver->target;
- GNUNET_CRYPTO_ecdhe_key_get_public (&epriv, &uhs.ephemeral);
- uhs.monotonic_time = uc.monotonic_time;
- GNUNET_CRYPTO_eddsa_sign (my_private_key,
- &uhs,
- &uc.sender_sig);
- /* Leave space for kx */
- dpos = sizeof(kx);
- /* Append encrypted uc to dgram */
- GNUNET_assert (0 == gcry_cipher_encrypt (out_cipher,
- &dgram[dpos],
- sizeof(uc),
- &uc,
- sizeof(uc)));
- dpos += sizeof(uc);
+ box = (struct UDPBox *) dgram;
+ ss->sequence_used++;
+ get_kid (&ss->master, ss->sequence_used, &box->kid);
+ setup_cipher (&ss->master, ss->sequence_used, &out_cipher);
/* Append encrypted payload to dgram */
+ dpos = sizeof(struct UDPBox);
GNUNET_assert (
0 == gcry_cipher_encrypt (out_cipher, &dgram[dpos], msize, msg, msize));
dpos += msize;
do_pad (out_cipher, &dgram[dpos], sizeof(dgram) - dpos);
- /* Datagram starts with kx */
- kx.ephemeral = uhs.ephemeral;
- GNUNET_assert (
- 0 == gcry_cipher_gettag (out_cipher, kx.gcm_tag, sizeof(kx.gcm_tag)));
+ GNUNET_assert (0 == gcry_cipher_gettag (out_cipher,
+ box->gcm_tag,
+ sizeof(box->gcm_tag)));
gcry_cipher_close (out_cipher);
- memcpy (dgram, &kx, sizeof(kx));
if (-1 == GNUNET_NETWORK_socket_sendto (udp_sock,
dgram,
sizeof(dgram),
receiver->address,
receiver->address_len))
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "send");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sending KX to %s\n", GNUNET_a2s (receiver->address,
- receiver->address_len));
GNUNET_MQ_impl_send_continue (mq);
- return;
- } /* End of KX encryption method */
-
- /* begin "BOX" encryption method, scan for ACKs from tail! */
- for (struct SharedSecret *ss = receiver->ss_tail; NULL != ss; ss = ss->prev)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "In non-kx mode...\n");
- if (ss->sequence_used < ss->sequence_allowed)
+ receiver->acks_available--;
+ if (0 == receiver->acks_available)
{
- char dgram[sizeof(struct UDPBox) + receiver->mtu];
- struct UDPBox *box;
- gcry_cipher_hd_t out_cipher;
- size_t dpos;
-
- box = (struct UDPBox *) dgram;
- ss->sequence_used++;
- get_kid (&ss->master, ss->sequence_used, &box->kid);
- setup_cipher (&ss->master, ss->sequence_used, &out_cipher);
- /* Append encrypted payload to dgram */
- dpos = sizeof(struct UDPBox);
- GNUNET_assert (
- 0 == gcry_cipher_encrypt (out_cipher, &dgram[dpos], msize, msg, msize));
- dpos += msize;
- do_pad (out_cipher, &dgram[dpos], sizeof(dgram) - dpos);
- GNUNET_assert (0 == gcry_cipher_gettag (out_cipher,
- box->gcm_tag,
- sizeof(box->gcm_tag)));
- gcry_cipher_close (out_cipher);
- if (-1 == GNUNET_NETWORK_socket_sendto (udp_sock,
- dgram,
- sizeof(dgram),
- receiver->address,
- receiver->address_len))
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "send");
+ /* We have no more ACKs */
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sending data\n");
-
- GNUNET_MQ_impl_send_continue (mq);
- receiver->acks_available--;
- if (0 == receiver->acks_available)
- {
- /* We have no more ACKs => MTU change! */
- setup_receiver_mq (receiver);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "No more acks, MTU changed\n");
- }
- return;
+ "No more acks\n");
}
+ return;
}
- GNUNET_assert (0);
}
@@ -2028,13 +2084,36 @@ mq_send (struct GNUNET_MQ_Handle *mq,
* @param impl_state our `struct ReceiverAddress`
*/
static void
-mq_destroy (struct GNUNET_MQ_Handle *mq, void *impl_state)
+mq_destroy_d (struct GNUNET_MQ_Handle *mq, void *impl_state)
{
struct ReceiverAddress *receiver = impl_state;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Default MQ destroyed\n");
+ if (mq == receiver->d_mq)
+ {
+ receiver->d_mq = NULL;
+ receiver_destroy (receiver);
+ }
+}
+
- if (mq == receiver->mq)
+/**
+ * Signature of functions implementing the destruction of a message
+ * queue. Implementations must not free @a mq, but should take care
+ * of @a impl_state.
+ *
+ * @param mq the message queue to destroy
+ * @param impl_state our `struct ReceiverAddress`
+ */
+static void
+mq_destroy_kx (struct GNUNET_MQ_Handle *mq, void *impl_state)
+{
+ struct ReceiverAddress *receiver = impl_state;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "KX MQ destroyed\n");
+ if (mq == receiver->kx_mq)
{
- receiver->mq = NULL;
+ receiver->kx_mq = NULL;
receiver_destroy (receiver);
}
}
@@ -2088,12 +2167,17 @@ setup_receiver_mq (struct ReceiverAddress *receiver)
{
size_t base_mtu;
- if (NULL != receiver->qh)
+ /*if (NULL != receiver->kx_qh)
{
- GNUNET_TRANSPORT_communicator_mq_del (receiver->qh);
- receiver->qh = NULL;
+ GNUNET_TRANSPORT_communicator_mq_del (receiver->kx_qh);
+ receiver->kx_qh = NULL;
}
- GNUNET_assert (NULL == receiver->mq);
+ if (NULL != receiver->d_qh)
+ {
+ GNUNET_TRANSPORT_communicator_mq_del (receiver->d_qh);
+ receiver->d_qh = NULL;
+ }*/
+ // GNUNET_assert (NULL == receiver->mq);
switch (receiver->address->sa_family)
{
case AF_INET:
@@ -2112,35 +2196,54 @@ setup_receiver_mq (struct ReceiverAddress *receiver)
GNUNET_assert (0);
break;
}
- if (0 == receiver->acks_available)
- {
- /* MTU based on full KX messages */
- receiver->mtu = base_mtu - sizeof(struct InitialKX) /* 48 */
- - sizeof(struct UDPConfirmation); /* 104 */
- }
- else
- {
- /* MTU based on BOXed messages */
- receiver->mtu = base_mtu - sizeof(struct UDPBox);
- }
+ /* MTU based on full KX messages */
+ receiver->kx_mtu = base_mtu - sizeof(struct InitialKX) /* 48 */
+ - sizeof(struct UDPConfirmation); /* 104 */
+ /* MTU based on BOXed messages */
+ receiver->d_mtu = base_mtu - sizeof(struct UDPBox);
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Setting up MQs and QHs\n");
/* => Effective MTU for CORE will range from 1080 (IPv6 + KX) to
1404 (IPv4 + Box) bytes, depending on circumstances... */
- if (NULL == receiver->mq)
- receiver->mq = GNUNET_MQ_queue_for_callbacks (&mq_send,
- &mq_destroy,
- &mq_cancel,
- receiver,
- NULL,
- &mq_error,
- receiver);
- receiver->qh =
+ if (NULL == receiver->kx_mq)
+ receiver->kx_mq = GNUNET_MQ_queue_for_callbacks (&mq_send_kx,
+ &mq_destroy_kx,
+ &mq_cancel,
+ receiver,
+ NULL,
+ &mq_error,
+ receiver);
+ if (NULL == receiver->d_mq)
+ receiver->d_mq = GNUNET_MQ_queue_for_callbacks (&mq_send_d,
+ &mq_destroy_d,
+ &mq_cancel,
+ receiver,
+ NULL,
+ &mq_error,
+ receiver);
+
+ receiver->kx_qh =
+ GNUNET_TRANSPORT_communicator_mq_add (ch,
+ &receiver->target,
+ receiver->foreign_addr,
+ receiver->kx_mtu,
+ GNUNET_TRANSPORT_QUEUE_LENGTH_UNLIMITED,
+ 0, /* Priority */
+ receiver->nt,
+ GNUNET_TRANSPORT_CS_OUTBOUND,
+ receiver->kx_mq);
+ receiver->d_qh =
GNUNET_TRANSPORT_communicator_mq_add (ch,
&receiver->target,
receiver->foreign_addr,
- receiver->mtu,
+ receiver->d_mtu,
+ 0, /* Initialize with 0 acks */
+ 1, /* Priority */
receiver->nt,
GNUNET_TRANSPORT_CS_OUTBOUND,
- receiver->mq);
+ receiver->d_mq);
+
}
@@ -2190,6 +2293,9 @@ mq_init (void *cls, const struct GNUNET_PeerIdentity *peer, const char *address)
&receiver->target,
receiver,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Added %s to receivers\n",
+ GNUNET_i2s_full (&receiver->target));
receiver->timeout =
GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
receiver->hn = GNUNET_CONTAINER_heap_insert (receivers_heap,
@@ -2336,6 +2442,9 @@ enc_notify_cb (void *cls,
const struct UDPAck *ack;
(void) cls;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Storing UDPAck received from backchannel from %s\n",
+ GNUNET_i2s_full (sender));
if ((ntohs (msg->type) != GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_ACK) ||
(ntohs (msg->size) != sizeof(struct UDPAck)))
{
diff --git a/src/transport/gnunet-communicator-unix.c b/src/transport/gnunet-communicator-unix.c
index 31d2e4ed3..6ea0ea360 100644
--- a/src/transport/gnunet-communicator-unix.c
+++ b/src/transport/gnunet-communicator-unix.c
@@ -57,7 +57,11 @@
/**
* Our MTU.
*/
+#ifndef DARWIN
#define UNIX_MTU UINT16_MAX
+#else
+#define UNIX_MTU 2048
+#endif
GNUNET_NETWORK_STRUCT_BEGIN
@@ -669,7 +673,9 @@ setup_queue (const struct GNUNET_PeerIdentity *target,
queue->qh = GNUNET_TRANSPORT_communicator_mq_add (ch,
&queue->target,
foreign_addr,
- UNIX_MTU,
+ UNIX_MTU - sizeof (struct UNIXMessage),
+ GNUNET_TRANSPORT_QUEUE_LENGTH_UNLIMITED,
+ 0,
GNUNET_NT_LOOPBACK,
cs,
queue->mq);
diff --git a/src/transport/test_communicator_basic.c b/src/transport/test_communicator_basic.c
index e99db7cfb..290167960 100644
--- a/src/transport/test_communicator_basic.c
+++ b/src/transport/test_communicator_basic.c
@@ -58,21 +58,23 @@ static char *cfg_peers_name[NUM_PEERS];
static int ret;
+static size_t long_message_size;
+
static struct GNUNET_TIME_Absolute start_short;
static struct GNUNET_TIME_Absolute start_long;
static struct GNUNET_TIME_Absolute timeout;
-static struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *my_tc;
+static struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *my_tc;
#define SHORT_MESSAGE_SIZE 128
-#define LONG_MESSAGE_SIZE 32000
+#define LONG_MESSAGE_SIZE 32000 /* FIXME */
#define BURST_PACKETS 5000
-#define TOTAL_ITERATIONS 5
+#define TOTAL_ITERATIONS 1
#define PEER_A 0
@@ -88,6 +90,7 @@ static unsigned int iterations_left = TOTAL_ITERATIONS;
enum TestPhase
{
+ TP_INIT,
TP_BURST_SHORT,
TP_BURST_LONG,
TP_SIZE_CHECK
@@ -182,7 +185,7 @@ handle_backchannel_cb (void *cls,
struct GNUNET_PeerIdentity *pid)
{
struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Handling BC message...\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Handling BC message...\n");
if (0 == memcmp (&peer_id[PEER_A], pid, sizeof (*pid)))
return tc_hs[PEER_A];
else
@@ -197,6 +200,8 @@ make_payload (size_t payload_size)
struct GNUNET_TIME_AbsoluteNBO ts_n;
char *payload = GNUNET_malloc (payload_size);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Making payload of size %lu\n", payload_size);
GNUNET_assert (payload_size >= 8); // So that out timestamp fits
ts = GNUNET_TIME_absolute_get ();
ts_n = GNUNET_TIME_absolute_hton (ts);
@@ -218,7 +223,7 @@ latency_timeout (void *cls)
return;
}
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ LOG (GNUNET_ERROR_TYPE_ERROR,
"Latency too high. Test failed. (Phase: %d. Sent: %lu, Received: %lu)\n",
phase, num_sent, num_received);
ret = 2;
@@ -230,15 +235,18 @@ static void
size_test (void *cls)
{
char *payload;
+ size_t max_size = 64000;
GNUNET_assert (TP_SIZE_CHECK == phase);
- if (ack >= 64000)
+ if (LONG_MESSAGE_SIZE != long_message_size)
+ max_size = long_message_size;
+ if (ack + 10 > max_size)
return; /* Leave some room for our protocol, so not 2^16 exactly */
+ ack += 10;
payload = make_payload (ack);
- ack += 5;
num_sent++;
GNUNET_TRANSPORT_TESTING_transport_communicator_send (my_tc,
- (ack < 64000)
+ (ack < max_size)
? &size_test
: NULL,
NULL,
@@ -254,7 +262,7 @@ long_test (void *cls)
{
char *payload;
- payload = make_payload (LONG_MESSAGE_SIZE);
+ payload = make_payload (long_message_size);
num_sent++;
GNUNET_TRANSPORT_TESTING_transport_communicator_send (my_tc,
(BURST_PACKETS ==
@@ -263,7 +271,7 @@ long_test (void *cls)
: &long_test,
NULL,
payload,
- LONG_MESSAGE_SIZE);
+ long_message_size);
GNUNET_free (payload);
timeout = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_SECONDS);
}
@@ -289,6 +297,34 @@ short_test (void *cls)
}
+static int test_prepared = GNUNET_NO;
+
+/**
+ * This helps establishing the backchannel
+ */
+static void
+prepare_test (void *cls)
+{
+ char *payload;
+
+ if (GNUNET_YES == test_prepared)
+ {
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+ &short_test,
+ NULL);
+ return;
+ }
+ test_prepared = GNUNET_YES;
+ payload = make_payload (SHORT_MESSAGE_SIZE);
+ GNUNET_TRANSPORT_TESTING_transport_communicator_send (my_tc,
+ &prepare_test,
+ NULL,
+ payload,
+ SHORT_MESSAGE_SIZE);
+ GNUNET_free (payload);
+}
+
+
/**
* @brief Handle opening of queue
*
@@ -304,21 +340,28 @@ static void
add_queue_cb (void *cls,
struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h,
struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *
- tc_queue)
+ tc_queue,
+ size_t mtu)
{
+ if (TP_INIT != phase)
+ return;
if (0 != strcmp ((char*) cls, cfg_peers_name[0]))
return; // TODO?
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Queue established, starting test...\n");
start_short = GNUNET_TIME_absolute_get ();
- my_tc = tc_queue;
+ my_tc = tc_h;
+ if (0 != mtu)
+ long_message_size = mtu - 4; /* Dummy message header overhead */
+ else
+ long_message_size = LONG_MESSAGE_SIZE;
phase = TP_BURST_SHORT;
- timeout = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_SECONDS);
+ timeout = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES);
GNUNET_assert (NULL == to_task);
- to_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+ to_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
&latency_timeout,
NULL);
- short_test (NULL);
+ prepare_test (NULL);
}
@@ -359,7 +402,7 @@ incoming_message_cb (void *cls,
{
if (0 != strcmp ((char*) cls, cfg_peers_name[NUM_PEERS - 1]))
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ LOG (GNUNET_ERROR_TYPE_WARNING,
"unexpected receiver...\n");
return;
}
@@ -367,6 +410,9 @@ incoming_message_cb (void *cls,
timeout = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_SECONDS);
switch (phase)
{
+ case TP_INIT:
+ GNUNET_break (0);
+ break;
case TP_BURST_SHORT:
{
GNUNET_assert (SHORT_MESSAGE_SIZE == payload_len);
@@ -375,13 +421,13 @@ incoming_message_cb (void *cls,
update_avg_latency (payload);
if (num_received == BURST_PACKETS)
{
- GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
+ LOG (GNUNET_ERROR_TYPE_MESSAGE,
"Short size packet test done.\n");
char *goodput = GNUNET_STRINGS_byte_size_fancy ((SHORT_MESSAGE_SIZE
* num_received * 1000
* 1000)
/ duration.rel_value_us);
- GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
+ LOG (GNUNET_ERROR_TYPE_MESSAGE,
"%lu/%lu packets in %llu us (%s/s) -- avg latency: %llu us\n",
(unsigned long) num_received,
(unsigned long) num_sent,
@@ -400,9 +446,9 @@ incoming_message_cb (void *cls,
}
case TP_BURST_LONG:
{
- if (LONG_MESSAGE_SIZE != payload_len)
+ if (long_message_size != payload_len)
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ LOG (GNUNET_ERROR_TYPE_WARNING,
"Ignoring packet with wrong length\n");
return; // Ignore
}
@@ -411,14 +457,14 @@ incoming_message_cb (void *cls,
update_avg_latency (payload);
if (num_received == BURST_PACKETS)
{
- GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
+ LOG (GNUNET_ERROR_TYPE_MESSAGE,
"Long size packet test done.\n");
- char *goodput = GNUNET_STRINGS_byte_size_fancy ((LONG_MESSAGE_SIZE
+ char *goodput = GNUNET_STRINGS_byte_size_fancy ((long_message_size
* num_received * 1000
* 1000)
/ duration.rel_value_us);
- GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
+ LOG (GNUNET_ERROR_TYPE_MESSAGE,
"%lu/%lu packets in %llu us (%s/s) -- avg latency: %llu us\n",
(unsigned long) num_received,
(unsigned long) num_sent,
@@ -426,7 +472,7 @@ incoming_message_cb (void *cls,
goodput,
(unsigned long long) avg_latency);
GNUNET_free (goodput);
- ack = 10;
+ ack = 0;
phase = TP_SIZE_CHECK;
num_received = 0;
num_sent = 0;
@@ -437,13 +483,18 @@ incoming_message_cb (void *cls,
}
case TP_SIZE_CHECK:
{
+ size_t max_size = 64000;
+
+ GNUNET_assert (TP_SIZE_CHECK == phase);
+ if (LONG_MESSAGE_SIZE != long_message_size)
+ max_size = long_message_size;
num_received++;
update_avg_latency (payload);
- if (num_received >= (64000 - 10) / 5)
+ if (num_received >= (max_size) / 10)
{
- GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
+ LOG (GNUNET_ERROR_TYPE_MESSAGE,
"Size packet test done.\n");
- GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
+ LOG (GNUNET_ERROR_TYPE_MESSAGE,
"%lu/%lu packets -- avg latency: %llu us\n",
(unsigned long) num_received,
(unsigned long) num_sent,
@@ -459,7 +510,7 @@ incoming_message_cb (void *cls,
short_test (NULL);
break;
}
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
"Finished\n");
GNUNET_SCHEDULER_shutdown ();
}
@@ -501,6 +552,7 @@ run (void *cls)
"transport",
communicator_binary,
cfg_peers_name[i],
+ &peer_id[i],
&communicator_available_cb,
&add_address_cb,
&queue_create_reply_cb,
@@ -524,6 +576,7 @@ main (int argc,
char *test_name;
char *cfg_peer;
+ phase = TP_INIT;
ret = 1;
test_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]);
communicator_name = strchr (test_name, '-');
@@ -586,12 +639,12 @@ main (int argc,
GNUNET_CRYPTO_eddsa_key_get_public (private_key,
&peer_id[i].public_key);
GNUNET_free (private_key);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ LOG (GNUNET_ERROR_TYPE_INFO,
"Identity of peer %u is %s\n",
i,
GNUNET_i2s_full (&peer_id[i]));
}
- GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, "Starting test...\n");
+ LOG (GNUNET_ERROR_TYPE_MESSAGE, "Starting test...\n");
GNUNET_SCHEDULER_run (&run,
NULL);
return ret;
diff --git a/src/transport/test_communicator_tcp_basic_peer1.conf b/src/transport/test_communicator_tcp_basic_peer1.conf
index fc08af1ee..d0293ff51 100644
--- a/src/transport/test_communicator_tcp_basic_peer1.conf
+++ b/src/transport/test_communicator_tcp_basic_peer1.conf
@@ -18,14 +18,17 @@ UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-transport_test_1.sock
[nat]
UNIXPATH = $GNUNET_TMP/test-communicator-unix-1/nat.sock
-ENABLE_IPSCAN = YES
[communicator-unix]
UNIXPATH = $GNUNET_RUNTIME_DIR/test_gnunet-communicator-unix_1.sock
[communicator-tcp]
BINDTO = 60002
-DISABLE_V6 = YES
+DISABLE_V6 = NO
[communicator-udp]
BINDTO = 60002
+
+[resolver]
+PORT = 62089
+UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-resolver_test_1.sock
diff --git a/src/transport/test_communicator_tcp_basic_peer2.conf b/src/transport/test_communicator_tcp_basic_peer2.conf
index 4197df00d..5b9050547 100644
--- a/src/transport/test_communicator_tcp_basic_peer2.conf
+++ b/src/transport/test_communicator_tcp_basic_peer2.conf
@@ -25,7 +25,11 @@ UNIXPATH = $GNUNET_RUNTIME_DIR/test_gnunet-communicator-unix_2.sock
[communicator-tcp]
BINDTO = 60003
-DISABLE_V6 = YES
+DISABLE_V6 = NO
[communicator-udp]
BINDTO = 60003
+
+[resolver]
+PORT = 62090
+UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-resolver_test_2.sock
diff --git a/src/transport/transport-testing2.c b/src/transport/transport-testing2.c
index fe2f28f54..0dc1bb331 100644
--- a/src/transport/transport-testing2.c
+++ b/src/transport/transport-testing2.c
@@ -33,7 +33,7 @@
#include "gnunet_hello_lib.h"
#include "gnunet_signatures.h"
#include "transport.h"
-
+#include <inttypes.h>
#define LOG(kind, ...) GNUNET_log_from (kind, "transport-testing2", __VA_ARGS__)
@@ -84,6 +84,8 @@ struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle
*/
char *cfg_filename;
+ struct GNUNET_PeerIdentity peer_id;
+
/**
* @brief Handle to the transport service
*/
@@ -107,6 +109,11 @@ struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle
struct GNUNET_OS_Process *nat_proc;
/**
+ * resolver service process
+ */
+ struct GNUNET_OS_Process *resolver_proc;
+
+ /**
* @brief Task that will be run on shutdown to stop and clean communicator
*/
struct GNUNET_SCHEDULER_Task *c_shutdown_task;
@@ -225,11 +232,21 @@ struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue
uint32_t nt;
/**
- * Maximum transmission unit, in NBO. UINT32_MAX for unlimited.
+ * Maximum transmission unit. UINT32_MAX for unlimited.
*/
uint32_t mtu;
/**
+ * Queue length. UINT64_MAX for unlimited.
+ */
+ uint64_t q_len;
+
+ /**
+ * Queue prio
+ */
+ uint32_t priority;
+
+ /**
* An `enum GNUNET_TRANSPORT_ConnectionStatus` in NBO.
*/
uint32_t cs;
@@ -368,7 +385,8 @@ handle_communicator_backchannel (void *cls,
struct GNUNET_TRANSPORT_CommunicatorBackchannelIncoming *cbi;
struct GNUNET_MQ_Envelope *env;
-
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Received backchannel message\n");
if (tc_h->bc_enabled != GNUNET_YES)
{
GNUNET_SERVICE_client_continue (client->client);
@@ -376,17 +394,17 @@ handle_communicator_backchannel (void *cls,
}
/* Find client providing this communicator */
/* Finally, deliver backchannel message to communicator */
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Delivering backchannel message of type %u to %s\n",
- ntohs (msg->type),
- target_communicator);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Delivering backchannel message of type %u to %s\n",
+ ntohs (msg->type),
+ target_communicator);
other_tc_h = tc_h->bc_cb (tc_h, msg, (struct
GNUNET_PeerIdentity*) &bc_msg->pid);
env = GNUNET_MQ_msg_extra (
cbi,
isize,
GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL_INCOMING);
- cbi->pid = bc_msg->pid;
+ cbi->pid = tc_h->peer_id;
memcpy (&cbi[1], msg, isize);
@@ -493,9 +511,6 @@ handle_incoming_msg (void *cls,
msg = (struct GNUNET_MessageHeader *) &inc_msg[1];
size_t payload_len = ntohs (msg->size) - sizeof (struct
GNUNET_MessageHeader);
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Incoming message from communicator!\n");
-
if (NULL != tc_h->incoming_msg_cb)
{
tc_h->incoming_msg_cb (tc_h->cb_cls,
@@ -515,6 +530,7 @@ handle_incoming_msg (void *cls,
struct GNUNET_TRANSPORT_IncomingMessageAck *ack;
env = GNUNET_MQ_msg (ack, GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG_ACK);
+ GNUNET_assert (NULL != env);
ack->reserved = htonl (0);
ack->fc_id = inc_msg->fc_id;
ack->sender = inc_msg->sender;
@@ -605,15 +621,14 @@ handle_add_queue_message (void *cls,
client->tc;
struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *tc_queue;
- tc_queue = tc_h->queue_head;
- if (NULL != tc_queue)
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Got queue with ID %u\n", msg->qid);
+ for (tc_queue = tc_h->queue_head; NULL != tc_queue; tc_queue = tc_queue->next)
{
- while (tc_queue->qid != msg->qid)
- {
- tc_queue = tc_queue->next;
- }
+ if (tc_queue->qid == msg->qid)
+ break;
}
- else
+ if (NULL == tc_queue)
{
tc_queue =
GNUNET_new (struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue);
@@ -625,12 +640,54 @@ handle_add_queue_message (void *cls,
GNUNET_assert (tc_queue->qid == msg->qid);
GNUNET_assert (0 == GNUNET_memcmp (&tc_queue->peer_id, &msg->receiver));
tc_queue->nt = msg->nt;
- tc_queue->mtu = msg->mtu;
+ tc_queue->mtu = ntohl (msg->mtu);
tc_queue->cs = msg->cs;
+ tc_queue->priority = ntohl (msg->priority);
+ tc_queue->q_len = GNUNET_ntohll (msg->q_len);
if (NULL != tc_h->add_queue_cb)
{
- tc_h->add_queue_cb (tc_h->cb_cls, tc_h, tc_queue);
+ tc_h->add_queue_cb (tc_h->cb_cls, tc_h, tc_queue, tc_queue->mtu);
+ }
+ GNUNET_SERVICE_client_continue (client->client);
+}
+
+
+/**
+ * @brief Handle new queue
+ *
+ * Store context and call client callback.
+ *
+ * @param cls Closure - communicator handle
+ * @param msg Message struct
+ */
+static void
+handle_update_queue_message (void *cls,
+ const struct
+ GNUNET_TRANSPORT_UpdateQueueMessage *msg)
+{
+ struct MyClient *client = cls;
+ struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h =
+ client->tc;
+ struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *tc_queue;
+
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Received queue update message for %u with q_len %"PRIu64"\n",
+ msg->qid, GNUNET_ntohll(msg->q_len));
+ tc_queue = tc_h->queue_head;
+ if (NULL != tc_queue)
+ {
+ while (tc_queue->qid != msg->qid)
+ {
+ tc_queue = tc_queue->next;
+ }
}
+ GNUNET_assert (tc_queue->qid == msg->qid);
+ GNUNET_assert (0 == GNUNET_memcmp (&tc_queue->peer_id, &msg->receiver));
+ tc_queue->nt = msg->nt;
+ tc_queue->mtu = ntohl (msg->mtu);
+ tc_queue->cs = msg->cs;
+ tc_queue->priority = ntohl (msg->priority);
+ tc_queue->q_len += GNUNET_ntohll (msg->q_len);
GNUNET_SERVICE_client_continue (client->client);
}
@@ -719,6 +776,8 @@ disconnect_cb (void *cls,
GNUNET_CONTAINER_DLL_remove (tc_h->client_head,
tc_h->client_tail,
cl);
+ if (cl->c_mq == tc_h->c_mq)
+ tc_h->c_mq = NULL;
GNUNET_free (cl);
break;
}
@@ -786,6 +845,10 @@ transport_communicator_start (
GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_SETUP,
struct GNUNET_TRANSPORT_AddQueueMessage,
tc_h),
+ GNUNET_MQ_hd_fixed_size (update_queue_message,
+ GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_UPDATE,
+ struct GNUNET_TRANSPORT_UpdateQueueMessage,
+ tc_h),
// GNUNET_MQ_hd_fixed_size (del_queue_message,
// GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_TEARDOWN,
// struct GNUNET_TRANSPORT_DelQueueMessage,
@@ -819,11 +882,11 @@ shutdown_process (struct GNUNET_OS_Process *proc)
if (0 != GNUNET_OS_process_kill (proc, SIGTERM))
{
LOG (GNUNET_ERROR_TYPE_WARNING,
- "Error shutting down communicator with SIGERM, trying SIGKILL\n");
+ "Error shutting down process with SIGERM, trying SIGKILL\n");
if (0 != GNUNET_OS_process_kill (proc, SIGKILL))
{
LOG (GNUNET_ERROR_TYPE_ERROR,
- "Error shutting down communicator with SIGERM and SIGKILL\n");
+ "Error shutting down process with SIGERM and SIGKILL\n");
}
}
GNUNET_OS_process_destroy (proc);
@@ -884,6 +947,45 @@ shutdown_nat (void *cls)
shutdown_process (proc);
}
+/**
+ * @brief Task run at shutdown to kill the resolver process
+ *
+ * @param cls Closure - Process of communicator
+ */
+static void
+shutdown_resolver (void *cls)
+{
+ struct GNUNET_OS_Process *proc = cls;
+ shutdown_process (proc);
+}
+
+static void
+resolver_start (struct
+ GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h)
+{
+ char *binary;
+
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "resolver_start\n");
+ binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-resolver");
+ tc_h->resolver_proc = GNUNET_OS_start_process (GNUNET_YES,
+ GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
+ NULL,
+ NULL,
+ NULL,
+ binary,
+ "gnunet-service-resolver",
+ "-c",
+ tc_h->cfg_filename,
+ NULL);
+ if (NULL == tc_h->resolver_proc)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to start resolver service!");
+ return;
+ }
+ LOG (GNUNET_ERROR_TYPE_INFO, "started resolver service\n");
+ GNUNET_free (binary);
+
+}
/**
* @brief Start NAT
@@ -934,6 +1036,7 @@ GNUNET_TRANSPORT_TESTING_transport_communicator_service_start (
const char *service_name,
const char *binary_name,
const char *cfg_filename,
+ const struct GNUNET_PeerIdentity *peer_id,
GNUNET_TRANSPORT_TESTING_CommunicatorAvailableCallback
communicator_available_cb,
GNUNET_TRANSPORT_TESTING_AddAddressCallback add_address_cb,
@@ -971,12 +1074,15 @@ GNUNET_TRANSPORT_TESTING_transport_communicator_service_start (
tc_h->add_queue_cb = add_queue_cb;
tc_h->incoming_msg_cb = incoming_message_cb;
tc_h->bc_cb = bc_cb;
+ tc_h->peer_id = *peer_id;
tc_h->cb_cls = cb_cls;
/* Start communicator part of service */
transport_communicator_start (tc_h);
/* Start NAT */
nat_start (tc_h);
+ /* Start resolver service */
+ resolver_start (tc_h);
/* Schedule start communicator */
communicator_start (tc_h,
binary_name);
@@ -991,6 +1097,7 @@ GNUNET_TRANSPORT_TESTING_transport_communicator_service_stop (
shutdown_communicator (tc_h->c_proc);
shutdown_service (tc_h->sh);
shutdown_nat (tc_h->nat_proc);
+ shutdown_resolver (tc_h->resolver_proc);
GNUNET_CONFIGURATION_destroy (tc_h->cfg);
GNUNET_free (tc_h);
}
@@ -1058,7 +1165,7 @@ GNUNET_TRANSPORT_TESTING_transport_communicator_open_queue (
*/
void
GNUNET_TRANSPORT_TESTING_transport_communicator_send
- (struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *tc_queue,
+ (struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h,
GNUNET_SCHEDULER_TaskCallback cont,
void *cont_cls,
const void *payload,
@@ -1068,11 +1175,46 @@ GNUNET_TRANSPORT_TESTING_transport_communicator_send
struct GNUNET_TRANSPORT_SendMessageTo *msg;
struct GNUNET_MQ_Envelope *env;
size_t inbox_size;
+ struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *tc_queue;
+ struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *tc_queue_tmp;
+ tc_queue = NULL;
+ for (tc_queue_tmp = tc_h->queue_head;
+ NULL != tc_queue_tmp;
+ tc_queue_tmp = tc_queue_tmp->next)
+ {
+ if (tc_queue_tmp->q_len <= 0)
+ continue;
+ if (NULL == tc_queue)
+ {
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Selecting queue with prio %u, len %" PRIu64 " and MTU %u\n",
+ tc_queue_tmp->priority,
+ tc_queue_tmp->q_len,
+ tc_queue_tmp->mtu);
+ tc_queue = tc_queue_tmp;
+ continue;
+ }
+ if (tc_queue->priority < tc_queue_tmp->priority)
+ {
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Selecting queue with prio %u, len %" PRIu64 " and MTU %u\n",
+ tc_queue_tmp->priority,
+ tc_queue_tmp->q_len,
+ tc_queue_tmp->mtu);
+ tc_queue = tc_queue_tmp;
+ }
+ }
+ GNUNET_assert (NULL != tc_queue);
+ if (tc_queue->q_len != GNUNET_TRANSPORT_QUEUE_LENGTH_UNLIMITED)
+ tc_queue->q_len--;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Sending message\n");
inbox_size = sizeof (struct GNUNET_MessageHeader) + payload_size;
env = GNUNET_MQ_msg_extra (msg,
inbox_size,
GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG);
+ GNUNET_assert (NULL != env);
msg->qid = htonl (tc_queue->qid);
msg->mid = tc_queue->mid++;
msg->receiver = tc_queue->peer_id;
diff --git a/src/transport/transport-testing2.h b/src/transport/transport-testing2.h
index 96a08a193..b77125e82 100644
--- a/src/transport/transport-testing2.h
+++ b/src/transport/transport-testing2.h
@@ -132,7 +132,8 @@ typedef void
*tc_h,
struct
GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue
- *tc_queue);
+ *tc_queue,
+ size_t mtu);
/**
@@ -171,6 +172,7 @@ GNUNET_TRANSPORT_TESTING_transport_communicator_service_start (
const char *service_name,
const char *binary_name,
const char *cfg_filename,
+ const struct GNUNET_PeerIdentity *peer_id,
GNUNET_TRANSPORT_TESTING_CommunicatorAvailableCallback
communicator_available_cb,
GNUNET_TRANSPORT_TESTING_AddAddressCallback add_address_cb,
@@ -214,8 +216,8 @@ GNUNET_TRANSPORT_TESTING_transport_communicator_open_queue (struct
*/
void
GNUNET_TRANSPORT_TESTING_transport_communicator_send (struct
- GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue
- *tc_queue,
+ GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle
+ *tc_h,
GNUNET_SCHEDULER_TaskCallback
cont,
void *cont_cls,
diff --git a/src/transport/transport.h b/src/transport/transport.h
index 36182d8d7..a64ffd5c6 100644
--- a/src/transport/transport.h
+++ b/src/transport/transport.h
@@ -836,6 +836,17 @@ struct GNUNET_TRANSPORT_AddQueueMessage
uint32_t mtu;
/**
+ * Queue length, in NBO. Defines how many messages may be
+ * send through this queue. UINT64_MAX for unlimited.
+ */
+ uint64_t q_len;
+
+ /**
+ * Priority of the queue in relation to other queues.
+ */
+ uint32_t priority;
+
+ /**
* An `enum GNUNET_TRANSPORT_ConnectionStatus` in NBO.
*/
uint32_t cs;
@@ -845,6 +856,55 @@ struct GNUNET_TRANSPORT_AddQueueMessage
/**
+ * Update queue
+ */
+struct GNUNET_TRANSPORT_UpdateQueueMessage
+{
+ /**
+ * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_SETUP.
+ */
+ struct GNUNET_MessageHeader header;
+
+ /**
+ * Queue identifier (used to identify the queue).
+ */
+ uint32_t qid GNUNET_PACKED;
+
+ /**
+ * Receiver that can be addressed via the queue.
+ */
+ struct GNUNET_PeerIdentity receiver;
+
+ /**
+ * An `enum GNUNET_NetworkType` in NBO.
+ */
+ uint32_t nt;
+
+ /**
+ * Maximum transmission unit, in NBO. UINT32_MAX for unlimited.
+ */
+ uint32_t mtu;
+
+ /**
+ * Queue length, in NBO. Defines how many messages may be
+ * send through this queue. UINT64_MAX for unlimited.
+ */
+ uint64_t q_len;
+
+ /**
+ * Priority of the queue in relation to other queues.
+ */
+ uint32_t priority;
+
+ /**
+ * An `enum GNUNET_TRANSPORT_ConnectionStatus` in NBO.
+ */
+ uint32_t cs;
+};
+
+
+
+/**
* Remove queue, it is no longer available.
*/
struct GNUNET_TRANSPORT_DelQueueMessage
diff --git a/src/transport/transport_api2_communication.c b/src/transport/transport_api2_communication.c
index e80cd5c03..cfa144415 100644
--- a/src/transport/transport_api2_communication.c
+++ b/src/transport/transport_api2_communication.c
@@ -280,6 +280,15 @@ struct GNUNET_TRANSPORT_QueueHandle
* Maximum transmission unit for the queue.
*/
uint32_t mtu;
+
+ /**
+ * Queue length.
+ */
+ uint64_t q_len;
+ /**
+ * Queue priority.
+ */
+ uint32_t priority;
};
@@ -395,6 +404,8 @@ send_add_queue (struct GNUNET_TRANSPORT_QueueHandle *qh)
if (NULL == qh->ch->mq)
return;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Sending `GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_SETUP` message\n");
env = GNUNET_MQ_msg_extra (aqm,
strlen (qh->address) + 1,
GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_SETUP);
@@ -402,11 +413,39 @@ send_add_queue (struct GNUNET_TRANSPORT_QueueHandle *qh)
aqm->receiver = qh->peer;
aqm->nt = htonl ((uint32_t) qh->nt);
aqm->mtu = htonl (qh->mtu);
+ aqm->q_len = GNUNET_htonll (qh->q_len);
+ aqm->priority = htonl (qh->priority);
aqm->cs = htonl ((uint32_t) qh->cs);
memcpy (&aqm[1], qh->address, strlen (qh->address) + 1);
GNUNET_MQ_send (qh->ch->mq, env);
}
+/**
+ * Send message to the transport service about queue @a qh
+ * updated.
+ *
+ * @param qh queue to add
+ */
+static void
+send_update_queue (struct GNUNET_TRANSPORT_QueueHandle *qh)
+{
+ struct GNUNET_MQ_Envelope *env;
+ struct GNUNET_TRANSPORT_UpdateQueueMessage *uqm;
+
+ if (NULL == qh->ch->mq)
+ return;
+ env = GNUNET_MQ_msg (uqm, GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_UPDATE);
+ uqm->qid = htonl (qh->queue_id);
+ uqm->receiver = qh->peer;
+ uqm->nt = htonl ((uint32_t) qh->nt);
+ uqm->mtu = htonl (qh->mtu);
+ uqm->q_len = GNUNET_htonll (qh->q_len);
+ uqm->priority = htonl (qh->priority);
+ uqm->cs = htonl ((uint32_t) qh->cs);
+ GNUNET_MQ_send (qh->ch->mq, env);
+}
+
+
/**
* Send message to the transport service about queue @a qh
@@ -924,6 +963,9 @@ GNUNET_TRANSPORT_communicator_receive (
* @param address address in human-readable format, 0-terminated, UTF-8
* @param mtu maximum message size supported by queue, 0 if
* sending is not supported, SIZE_MAX for no MTU
+ * @param q_len number of messages that can be send through this queue
+ * @param priority queue priority. Queues with highest priority should be
+ * used
* @param nt which network type does the @a address belong to?
* @param cc what characteristics does the communicator have?
* @param cs what is the connection status of the queue?
@@ -936,6 +978,8 @@ GNUNET_TRANSPORT_communicator_mq_add (
const struct GNUNET_PeerIdentity *peer,
const char *address,
uint32_t mtu,
+ uint64_t q_len,
+ uint32_t priority,
enum GNUNET_NetworkType nt,
enum GNUNET_TRANSPORT_ConnectionStatus cs,
struct GNUNET_MQ_Handle *mq)
@@ -948,6 +992,8 @@ GNUNET_TRANSPORT_communicator_mq_add (
qh->address = GNUNET_strdup (address);
qh->nt = nt;
qh->mtu = mtu;
+ qh->q_len = q_len;
+ qh->priority = priority;
qh->cs = cs;
qh->mq = mq;
qh->queue_id = ch->queue_gen++;
@@ -958,6 +1004,37 @@ GNUNET_TRANSPORT_communicator_mq_add (
/**
+ * Notify transport service that an MQ was updated
+ *
+ * @param ch connection to transport service
+ * @param qh the queue to update
+ * @param q_len number of messages that can be send through this queue
+ * @param priority queue priority. Queues with highest priority should be
+ * used
+ */
+void
+GNUNET_TRANSPORT_communicator_mq_update (
+ struct GNUNET_TRANSPORT_CommunicatorHandle *ch,
+ const struct GNUNET_TRANSPORT_QueueHandle *u_qh,
+ uint64_t q_len,
+ uint32_t priority)
+{
+ struct GNUNET_TRANSPORT_QueueHandle *qh;
+
+ for (qh = ch->queue_head; NULL != qh; qh = qh->next)
+ {
+ if (u_qh == qh)
+ break;
+ }
+ GNUNET_assert (NULL != qh);
+ qh->q_len = q_len;
+ qh->priority = priority;
+ send_update_queue (qh);
+}
+
+
+
+/**
* Notify transport service that an MQ became unavailable due to a
* disconnect or timeout.
*
diff --git a/src/util/Makefile.am b/src/util/Makefile.am
index f3373fc38..83b3b9c3d 100644
--- a/src/util/Makefile.am
+++ b/src/util/Makefile.am
@@ -131,7 +131,6 @@ libgnunetutil_la_LIBADD = \
$(LIBIDN) $(LIBIDN2) \
$(Z_LIBS) \
-lunistring \
- -largon2 \
-lsodium \
$(XLIB) \
$(PTHREAD)
diff --git a/src/util/bio.c b/src/util/bio.c
index e05258f73..ce15f073b 100644
--- a/src/util/bio.c
+++ b/src/util/bio.c
@@ -48,12 +48,37 @@
/**
+ * Enum used internally to know how buffering is handled.
+ *
+ * The idea is that by using an enum, BIO can be extended to support other
+ * kinds of "backend" for buffering (or just formatted I/O.)
+ */
+enum IOType
+{
+ /**
+ * The handle uses a file to read/write data.
+ */
+ IO_FILE = 0,
+
+ /**
+ * The data is stored entirely in memory.
+ */
+ IO_BUFFER,
+};
+
+
+/**
* Handle for buffered reading.
*/
struct GNUNET_BIO_ReadHandle
{
/**
- * Underlying file abstraction.
+ * The "backend" type.
+ */
+ enum IOType type;
+
+ /**
+ * Handle to a file on disk, if @e type is #IO_FILE.
*/
struct GNUNET_DISK_FileHandle *fd;
@@ -63,12 +88,12 @@ struct GNUNET_BIO_ReadHandle
char *emsg;
/**
- * I/O buffer. Allocated at the end of the struct, do not free!
+ * I/O buffer. Do @b not free!
*/
char *buffer;
/**
- * Number of bytes available in read @e buffer.
+ * Number of bytes available in @e buffer.
*/
size_t have;
@@ -91,7 +116,7 @@ struct GNUNET_BIO_ReadHandle
* @return IO handle on success, NULL on error
*/
struct GNUNET_BIO_ReadHandle *
-GNUNET_BIO_read_open (const char *fn)
+GNUNET_BIO_read_open_file (const char *fn)
{
struct GNUNET_DISK_FileHandle *fd;
struct GNUNET_BIO_ReadHandle *h;
@@ -100,6 +125,7 @@ GNUNET_BIO_read_open (const char *fn)
if (NULL == fd)
return NULL;
h = GNUNET_malloc (sizeof(struct GNUNET_BIO_ReadHandle) + BIO_BUFFER_SIZE);
+ h->type = IO_FILE;
h->buffer = (char *) &h[1];
h->size = BIO_BUFFER_SIZE;
h->fd = fd;
@@ -108,11 +134,32 @@ GNUNET_BIO_read_open (const char *fn)
/**
- * Close an open file. Reports if any errors reading
+ * Create a handle from an existing allocated buffer.
+ *
+ * @param buffer the buffer to use as source
+ * @param size the total size in bytes of the buffer
+ * @return IO handle on sucess, NULL on error
+ */
+struct GNUNET_BIO_ReadHandle *
+GNUNET_BIO_read_open_buffer (void *buffer, size_t size)
+{
+ struct GNUNET_BIO_ReadHandle *h;
+
+ h = GNUNET_new (struct GNUNET_BIO_ReadHandle);
+ h->type = IO_BUFFER;
+ h->buffer = buffer;
+ h->size = size;
+ return h;
+}
+
+
+/**
+ * Close an open handle. Reports if any errors reading
* from the file were encountered.
*
* @param h file handle
- * @param emsg set to the error message
+ * @param emsg set to the (allocated) error message
+ * if the handle has an error message, the return value is #GNUNET_SYSERR
* @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
*/
int
@@ -121,60 +168,63 @@ GNUNET_BIO_read_close (struct GNUNET_BIO_ReadHandle *h, char **emsg)
int err;
err = (NULL == h->emsg) ? GNUNET_OK : GNUNET_SYSERR;
- if (emsg != NULL)
+ if (NULL != emsg)
*emsg = h->emsg;
else
GNUNET_free_non_null (h->emsg);
- GNUNET_DISK_file_close (h->fd);
+ switch (h->type)
+ {
+ case IO_FILE:
+ GNUNET_DISK_file_close (h->fd);
+ break;
+ case IO_BUFFER:
+ break;
+ default:
+ break;
+ }
GNUNET_free (h);
return err;
}
/**
- * Read the contents of a binary file into a buffer.
+ * Function used internally to read the contents of a file into a buffer.
*
- * @param h handle to an open file
+ * @param h the IO handle to read from
* @param what describes what is being read (for error message creation)
- * @param result the buffer to write the result to
+ * @param result the buffer to write the data to
* @param len the number of bytes to read
- * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
*/
-int
-GNUNET_BIO_read (struct GNUNET_BIO_ReadHandle *h,
- const char *what,
- void *result,
- size_t len)
+static int
+read_from_file (struct GNUNET_BIO_ReadHandle *h,
+ const char *what,
+ char *result,
+ size_t len)
{
- char *dst = result;
+ size_t pos = 0;
size_t min;
- size_t pos;
ssize_t ret;
- if (NULL != h->emsg)
- return GNUNET_SYSERR;
- pos = 0;
do
{
- /* first, use buffer */
min = h->have - h->pos;
- if (min > 0)
+ if (0 < min)
{
- if (min > len - pos)
+ if (len - pos < min)
min = len - pos;
- GNUNET_memcpy (&dst[pos], &h->buffer[h->pos], min);
+ GNUNET_memcpy (&result[pos], &h->buffer[h->pos], min);
h->pos += min;
pos += min;
}
- if (pos == len)
- return GNUNET_OK; /* done! */
+ if (len == pos)
+ return GNUNET_OK;
GNUNET_assert (((off_t) h->have) == h->pos);
- /* fill buffer */
ret = GNUNET_DISK_file_read (h->fd, h->buffer, h->size);
if (-1 == ret)
{
GNUNET_asprintf (&h->emsg,
- _ ("Error reading `%s': %s"),
+ _ ("Error reading `%s' from file: %s"),
what,
strerror (errno));
return GNUNET_SYSERR;
@@ -182,7 +232,7 @@ GNUNET_BIO_read (struct GNUNET_BIO_ReadHandle *h,
if (0 == ret)
{
GNUNET_asprintf (&h->emsg,
- _ ("Error reading `%s': %s"),
+ _ ("Error reading `%s' from file: %s"),
what,
_ ("End of file"));
return GNUNET_SYSERR;
@@ -190,41 +240,84 @@ GNUNET_BIO_read (struct GNUNET_BIO_ReadHandle *h,
h->pos = 0;
h->have = ret;
}
- while (pos < len); /* should always be true */
+ while (pos < len);
return GNUNET_OK;
}
/**
- * Read the contents of a binary file into a buffer.
+ * Function used internally to read the content of a buffer into a buffer.
*
- * @param h handle to an open file
- * @param file name of the source file
- * @param line line number in the source file
+ * @param h the IO handle to read from
+ * @param what describes what is being read (for error message creation)
+ * @param result the buffer to write the result to
+ * @param len the number of bytes to read
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
+ */
+static int
+read_from_buffer (struct GNUNET_BIO_ReadHandle *h,
+ const char *what,
+ char *result,
+ size_t len)
+{
+ if (h->size < len || h->size - h->pos < len)
+ {
+ GNUNET_asprintf (&h->emsg,
+ _ ("Error while reading `%s' from buffer: %s"),
+ what,
+ _ ("Not enough data left"));
+ return GNUNET_SYSERR;
+ }
+ GNUNET_memcpy (result, h->buffer + h->pos, len);
+ h->pos += len;
+ return GNUNET_OK;
+}
+
+
+/**
+ * Read some contents into a buffer.
+ *
+ * @param h the IO handle to read from
+ * @param what describes what is being read (for error message creation)
* @param result the buffer to write the result to
* @param len the number of bytes to read
* @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
*/
int
-GNUNET_BIO_read_fn (struct GNUNET_BIO_ReadHandle *h,
- const char *file,
- int line,
- void *result,
- size_t len)
+GNUNET_BIO_read (struct GNUNET_BIO_ReadHandle *h,
+ const char *what,
+ void *result,
+ size_t len)
{
- char what[PATH_MAX + 1024];
+ char *dst = result;
- GNUNET_snprintf (what, sizeof(what), "%s:%d", file, line);
- return GNUNET_BIO_read (h, what, result, len);
+ if (NULL != h->emsg)
+ return GNUNET_SYSERR;
+
+ if (0 == len)
+ return GNUNET_OK;
+
+ switch (h->type)
+ {
+ case IO_FILE:
+ return read_from_file (h, what, dst, len);
+ case IO_BUFFER:
+ return read_from_buffer (h, what, dst, len);
+ default:
+ GNUNET_asprintf (&h->emsg,
+ _ ("Invalid handle type while reading `%s'"),
+ what);
+ return GNUNET_SYSERR;
+ }
}
/**
- * Read 0-terminated string from a file.
+ * Read 0-terminated string.
*
- * @param h handle to an open file
+ * @param h the IO handle to read from
* @param what describes what is being read (for error message creation)
- * @param result the buffer to store a pointer to the (allocated) string to
+ * @param result where to store the pointer to the (allocated) string
* (note that *result could be set to NULL as well)
* @param max_length maximum allowed length for the string
* @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
@@ -238,10 +331,21 @@ GNUNET_BIO_read_string (struct GNUNET_BIO_ReadHandle *h,
char *buf;
uint32_t big;
- if (GNUNET_OK != GNUNET_BIO_read_int32 (h, &big))
+ if (GNUNET_OK != GNUNET_BIO_read_int32 (h,
+ _ ("string length"),
+ (int32_t *) &big))
{
- GNUNET_free_non_null (h->emsg);
- GNUNET_asprintf (&h->emsg, _ ("Error reading length of string `%s'"), what);
+ char *tmp = h->emsg;
+ if (NULL != tmp)
+ GNUNET_asprintf (&h->emsg,
+ _ ("%s (while reading `%s')"),
+ tmp,
+ what);
+ else
+ GNUNET_asprintf (&h->emsg,
+ _ ("Error reading length of string `%s'"),
+ what);
+ GNUNET_free_non_null (tmp);
return GNUNET_SYSERR;
}
if (0 == big)
@@ -274,7 +378,7 @@ GNUNET_BIO_read_string (struct GNUNET_BIO_ReadHandle *h,
/**
- * Read metadata container from a file.
+ * Read a metadata container.
*
* @param h handle to an open file
* @param what describes what is being read (for error message creation)
@@ -290,20 +394,23 @@ GNUNET_BIO_read_meta_data (struct GNUNET_BIO_ReadHandle *h,
char *buf;
struct GNUNET_CONTAINER_MetaData *meta;
- if (GNUNET_OK != GNUNET_BIO_read_int32 (h, (int32_t *) &size))
+ if (GNUNET_OK != GNUNET_BIO_read_int32 (h,
+ _ ("metadata length"),
+ (int32_t *) &size))
return GNUNET_SYSERR;
- if (size == 0)
+ if (0 == size)
{
*result = NULL;
return GNUNET_OK;
}
- if (size > MAX_META_DATA)
+ if (MAX_META_DATA < size)
{
- GNUNET_asprintf (&h->emsg,
- _ ("Serialized metadata `%s' larger than allowed (%u>%u)"),
- what,
- size,
- MAX_META_DATA);
+ GNUNET_asprintf (
+ &h->emsg,
+ _ ("Serialized metadata `%s' larger than allowed (%u > %u)"),
+ what,
+ size,
+ MAX_META_DATA);
return GNUNET_SYSERR;
}
buf = GNUNET_malloc (size);
@@ -316,7 +423,7 @@ GNUNET_BIO_read_meta_data (struct GNUNET_BIO_ReadHandle *h,
if (NULL == meta)
{
GNUNET_free (buf);
- GNUNET_asprintf (&h->emsg, _ ("Metadata `%s' failed to deserialize"), what);
+ GNUNET_asprintf (&h->emsg, _ ("Failed to deserialize metadata `%s'"), what);
return GNUNET_SYSERR;
}
GNUNET_free (buf);
@@ -324,25 +431,56 @@ GNUNET_BIO_read_meta_data (struct GNUNET_BIO_ReadHandle *h,
return GNUNET_OK;
}
+/**
+ * Read a float.
+ *
+ * @param h the IO handle to read from
+ * @param what describes what is being read (for error message creation)
+ * @param f address of float to read
+ */
+int
+GNUNET_BIO_read_float(struct GNUNET_BIO_ReadHandle *h,
+ const char *what,
+ float *f)
+{
+ int32_t *i = (int32_t *) f;
+ return GNUNET_BIO_read_int32 (h, what, i);
+}
+
+
+/**
+ * Read a double.
+ *
+ * @param h the IO handle to read from
+ * @param what describes what is being read (for error message creation)
+ * @param f address of double to read
+ */
+int
+GNUNET_BIO_read_double(struct GNUNET_BIO_ReadHandle *h,
+ const char *what,
+ double *f)
+{
+ int64_t *i = (int64_t *) f;
+ return GNUNET_BIO_read_int64 (h, what, i);
+}
+
/**
* Read an (u)int32_t.
*
- * @param h hande to open file
- * @param file name of the source file
- * @param line line number in the source file
- * @param i address of 32-bit integer to read
+ * @param h the IO handle to read from
+ * @param what describes what is being read (for error message creation)
+ * @param i where to store the data
* @return #GNUNET_OK on success, #GNUNET_SYSERR on error
*/
int
-GNUNET_BIO_read_int32__ (struct GNUNET_BIO_ReadHandle *h,
- const char *file,
- int line,
- int32_t *i)
+GNUNET_BIO_read_int32 (struct GNUNET_BIO_ReadHandle *h,
+ const char *what,
+ int32_t *i)
{
int32_t big;
- if (GNUNET_OK != GNUNET_BIO_read_fn (h, file, line, &big, sizeof(int32_t)))
+ if (GNUNET_OK != GNUNET_BIO_read (h, what, &big, sizeof(int32_t)))
return GNUNET_SYSERR;
*i = ntohl (big);
return GNUNET_OK;
@@ -352,21 +490,19 @@ GNUNET_BIO_read_int32__ (struct GNUNET_BIO_ReadHandle *h,
/**
* Read an (u)int64_t.
*
- * @param h hande to open file
- * @param file name of the source file
- * @param line line number in the source file
- * @param i address of 64-bit integer to read
+ * @param h the IO handle to read from
+ * @param what describes what is being read (for error message creation)
+ * @param i where to store the data
* @return #GNUNET_OK on success, #GNUNET_SYSERR on error
*/
int
-GNUNET_BIO_read_int64__ (struct GNUNET_BIO_ReadHandle *h,
- const char *file,
- int line,
- int64_t *i)
+GNUNET_BIO_read_int64 (struct GNUNET_BIO_ReadHandle *h,
+ const char *what,
+ int64_t *i)
{
int64_t big;
- if (GNUNET_OK != GNUNET_BIO_read_fn (h, file, line, &big, sizeof(int64_t)))
+ if (GNUNET_OK != GNUNET_BIO_read (h, what, &big, sizeof(int64_t)))
return GNUNET_SYSERR;
*i = GNUNET_ntohll (big);
return GNUNET_OK;
@@ -379,17 +515,29 @@ GNUNET_BIO_read_int64__ (struct GNUNET_BIO_ReadHandle *h,
struct GNUNET_BIO_WriteHandle
{
/**
- * Underlying file handle.
+ * The "backend" type.
+ */
+ enum IOType type;
+
+ /**
+ * Handle to a file on disk, if @e type is #IO_FILE.
*/
struct GNUNET_DISK_FileHandle *fd;
/**
- * I/O buffer. Do not free, allocated at the end of the struct.
+ * Error message, NULL if there were no errors.
*/
- char *buffer;
+ char *emsg;
+
+ /**
+ * I/O buffer.
+ * This field is a void * because it is used to hold pointers to allocated
+ * structures or arrays and will be casted to the appropriate type.
+ */
+ void *buffer;
/**
- * Number of bytes already in @e buffer.
+ * Number of bytes available in @e buffer.
*/
size_t have;
@@ -403,25 +551,26 @@ struct GNUNET_BIO_WriteHandle
/**
* Open a file for writing.
*
- * @param fn file name to be opened
+ * @param fn name of the file to be opened
* @return IO handle on success, NULL on error
*/
struct GNUNET_BIO_WriteHandle *
-GNUNET_BIO_write_open (const char *fn)
+GNUNET_BIO_write_open_file (const char *fn)
{
struct GNUNET_DISK_FileHandle *fd;
struct GNUNET_BIO_WriteHandle *h;
fd =
GNUNET_DISK_file_open (fn,
- GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_TRUNCATE
+ GNUNET_DISK_OPEN_WRITE
+ | GNUNET_DISK_OPEN_TRUNCATE
| GNUNET_DISK_OPEN_CREATE,
GNUNET_DISK_PERM_USER_READ
| GNUNET_DISK_PERM_USER_WRITE);
if (NULL == fd)
return NULL;
h = GNUNET_malloc (sizeof(struct GNUNET_BIO_WriteHandle) + BIO_BUFFER_SIZE);
- h->buffer = (char *) &h[1];
+ h->buffer = &h[1];
h->size = BIO_BUFFER_SIZE;
h->fd = fd;
return h;
@@ -429,42 +578,94 @@ GNUNET_BIO_write_open (const char *fn)
/**
- * Close an open file for writing.
+ * Create a handle backed by an in-memory buffer.
+ *
+ * @return IO handle on success, NULL on error
+ */
+struct GNUNET_BIO_WriteHandle *
+GNUNET_BIO_write_open_buffer (void)
+{
+ struct GNUNET_BIO_WriteHandle *h;
+
+ h = GNUNET_new (struct GNUNET_BIO_WriteHandle);
+ h->type = IO_BUFFER;
+ h->buffer = (void *) GNUNET_malloc (sizeof (struct GNUNET_Buffer));
+ return h;
+}
+
+
+/**
+ * Close an IO handle.
+ * If the handle was using a file, the file will be closed.
*
* @param h file handle
+ * @param emsg set to the (allocated) error message
+ * if the handle has an error message, the return value is #GNUNET_SYSERR
* @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
*/
int
-GNUNET_BIO_write_close (struct GNUNET_BIO_WriteHandle *h)
+GNUNET_BIO_write_close (struct GNUNET_BIO_WriteHandle *h, char **emsg)
{
- int ret;
+ int err;
- ret = GNUNET_SYSERR;
- if ((NULL != h->fd) && (GNUNET_OK == (ret = GNUNET_BIO_flush (h))))
- GNUNET_DISK_file_close (h->fd);
+ err = (NULL == h->emsg) ? GNUNET_OK : GNUNET_SYSERR;
+ if (NULL != emsg)
+ *emsg = h->emsg;
+ else
+ GNUNET_free_non_null (h->emsg);
+ switch (h->type)
+ {
+ case IO_FILE:
+ if (NULL == h->fd)
+ return GNUNET_SYSERR;
+ if (GNUNET_OK != GNUNET_BIO_flush (h))
+ {
+ if (NULL != emsg)
+ *emsg = h->emsg;
+ else
+ GNUNET_free_non_null (h->emsg);
+ err = GNUNET_SYSERR;
+ }
+ else
+ {
+ GNUNET_DISK_file_close (h->fd);
+ }
+ break;
+ case IO_BUFFER:
+ GNUNET_buffer_clear ((struct GNUNET_Buffer *) h->buffer);
+ GNUNET_free (h->buffer);
+ break;
+ }
GNUNET_free (h);
- return ret;
+ return err;
}
/**
- * Force a buffered writer to flush its buffer
+ * Force a file-based buffered writer to flush its buffer.
+ * If the handle does not use a file, this function returs #GNUNET_OK
+ * without doing anything.
*
- * @param h the writer handle
- * @return #GNUNET_OK upon success. Upon failure #GNUNET_SYSERR is returned and
- * the file is closed
+ * @param h the IO handle
+ * @return #GNUNET_OK upon success. Upon failure #GNUNET_SYSERR is returned
+ * and the file is closed
*/
int
GNUNET_BIO_flush (struct GNUNET_BIO_WriteHandle *h)
{
ssize_t ret;
+ if (IO_FILE != h->type)
+ return GNUNET_OK;
+
ret = GNUNET_DISK_file_write (h->fd, h->buffer, h->have);
if (ret != (ssize_t) h->have)
{
GNUNET_DISK_file_close (h->fd);
h->fd = NULL;
- return GNUNET_SYSERR; /* error */
+ GNUNET_free_non_null (h->emsg);
+ GNUNET_asprintf (&h->emsg, _ ("Unable to flush buffer to file"));
+ return GNUNET_SYSERR;
}
h->have = 0;
return GNUNET_OK;
@@ -472,96 +673,213 @@ GNUNET_BIO_flush (struct GNUNET_BIO_WriteHandle *h)
/**
- * Write a buffer to a file.
+ * Get the IO handle's contents.
+ * If the handle doesn't use an in-memory buffer, this function returns
+ * #GNUNET_SYSERR.
*
- * @param h handle to open file
- * @param buffer the data to write
- * @param n number of bytes to write
- * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
+ * @param h the IO handle
+ * @param emsg set to the (allocated) error message
+ * if the handle has an error message the return value is #GNUNET_SYSERR
+ * @param contents where to store the pointer to the handle's contents
+ * @param size where to store the size of @e contents
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
*/
int
-GNUNET_BIO_write (struct GNUNET_BIO_WriteHandle *h,
- const void *buffer,
- size_t n)
+GNUNET_BIO_get_buffer_contents (struct GNUNET_BIO_WriteHandle *h,
+ char **emsg,
+ void **contents,
+ size_t *size)
+{
+ if (IO_BUFFER != h->type)
+ return GNUNET_SYSERR;
+ if (NULL == contents || NULL == size)
+ return GNUNET_SYSERR;
+ int ret = (NULL != h->emsg) ? GNUNET_SYSERR : GNUNET_OK;
+ if (NULL != emsg)
+ *emsg = h->emsg;
+ else
+ GNUNET_free_non_null (h->emsg);
+ *contents = GNUNET_buffer_reap ((struct GNUNET_Buffer *) h->buffer, size);
+ return ret;
+}
+
+
+/**
+ * Function used internally to write the contents of a buffer into a file.
+ *
+ * @param h the IO handle to write to
+ * @param what describes what is being written (for error message creation)
+ * @param source the buffer to write
+ * @param len the number of bytes to write
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
+ */
+static int
+write_to_file (struct GNUNET_BIO_WriteHandle *h,
+ const char *what,
+ const char *source,
+ size_t len)
{
- const char *src = buffer;
size_t min;
- size_t pos;
+ size_t pos = 0;
+ char *buffer = (char *) h->buffer;
if (NULL == h->fd)
+ {
+ GNUNET_asprintf (&h->emsg,
+ _ ("Error while writing `%s' to file: %s"),
+ what,
+ _ ("No associated file"));
return GNUNET_SYSERR;
- pos = 0;
+ }
+
do
{
- /* first, just use buffer */
min = h->size - h->have;
- if (min > n - pos)
- min = n - pos;
- GNUNET_memcpy (&h->buffer[h->have], &src[pos], min);
+ if (len - pos < min)
+ min = len - pos;
+ GNUNET_memcpy (&buffer[h->have], &source[pos], min);
pos += min;
h->have += min;
- if (pos == n)
- return GNUNET_OK; /* done */
+ if (len == pos)
+ return GNUNET_OK;
GNUNET_assert (h->have == h->size);
if (GNUNET_OK != GNUNET_BIO_flush (h))
- return GNUNET_SYSERR; /* error */
+ {
+ char *tmp = h->emsg;
+ GNUNET_asprintf (&h->emsg,
+ _ ("Error while writing `%s' to file: %s"),
+ what,
+ tmp);
+ GNUNET_free_non_null (tmp);
+ return GNUNET_SYSERR;
+ }
}
- while (pos < n); /* should always be true */
+ while (pos < len);
GNUNET_break (0);
return GNUNET_OK;
}
/**
- * Write a string to a file.
+ * Function used internally to write the contents of a buffer to another buffer.
+ *
+ * @param h the IO handle to write to
+ * @param what describes what is being written (for error message creation)
+ * @param source the buffer to write
+ * @param len the number of bytes to write
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
+ */
+static int
+write_to_buffer (struct GNUNET_BIO_WriteHandle *h,
+ const char *what,
+ const char *source,
+ size_t len)
+{
+ GNUNET_buffer_write ((struct GNUNET_Buffer *) h->buffer, source, len);
+ h->have += len;
+ return GNUNET_OK;
+}
+
+
+/**
+ * Write a buffer to a handle.
+ *
+ * @param h the IO handle to write to
+ * @param what what is being written (for error message creation)
+ * @param buffer the data to write
+ * @param n number of bytes to write
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
+ */
+int
+GNUNET_BIO_write (struct GNUNET_BIO_WriteHandle *h,
+ const char *what,
+ const void *buffer,
+ size_t n)
+{
+ const char *src = buffer;
+
+ if (NULL != h->emsg)
+ return GNUNET_SYSERR;
+
+ if (0 == n)
+ return GNUNET_OK;
+
+ switch (h->type)
+ {
+ case IO_FILE:
+ return write_to_file (h, what, src, n);
+ case IO_BUFFER:
+ return write_to_buffer (h, what, src, n);
+ default:
+ GNUNET_asprintf (&h->emsg,
+ _ ("Invalid handle type while writing `%s'"),
+ what);
+ return GNUNET_SYSERR;
+ }
+}
+
+
+/**
+ * Write a 0-terminated string.
*
- * @param h handle to open file
+ * @param h the IO handle to write to
+ * @param what what is being written (for error message creation)
* @param s string to write (can be NULL)
* @return #GNUNET_OK on success, #GNUNET_SYSERR on error
*/
int
-GNUNET_BIO_write_string (struct GNUNET_BIO_WriteHandle *h, const char *s)
+GNUNET_BIO_write_string (struct GNUNET_BIO_WriteHandle *h,
+ const char *what,
+ const char *s)
{
uint32_t slen;
slen = (uint32_t) ((s == NULL) ? 0 : strlen (s) + 1);
- if (GNUNET_OK != GNUNET_BIO_write_int32 (h, slen))
+ if (GNUNET_OK != GNUNET_BIO_write_int32 (h, _ ("string length"), slen))
return GNUNET_SYSERR;
if (0 != slen)
- return GNUNET_BIO_write (h, s, slen - 1);
+ return GNUNET_BIO_write (h, what, s, slen - 1);
return GNUNET_OK;
}
/**
- * Write metadata container to a file.
+ * Write a metadata container.
*
- * @param h handle to open file
+ * @param h the IO handle to write to
+ * @param what what is being written (for error message creation)
* @param m metadata to write
* @return #GNUNET_OK on success, #GNUNET_SYSERR on error
*/
int
GNUNET_BIO_write_meta_data (struct GNUNET_BIO_WriteHandle *h,
+ const char *what,
const struct GNUNET_CONTAINER_MetaData *m)
{
ssize_t size;
char *buf;
if (m == NULL)
- return GNUNET_BIO_write_int32 (h, 0);
+ return GNUNET_BIO_write_int32 (h, _ ("metadata length"), 0);
buf = NULL;
size = GNUNET_CONTAINER_meta_data_serialize (
m,
&buf,
MAX_META_DATA,
GNUNET_CONTAINER_META_DATA_SERIALIZE_PART);
- if (size == -1)
+ if (-1 == size)
{
GNUNET_free (buf);
+ GNUNET_free_non_null (h->emsg);
+ GNUNET_asprintf (&h->emsg,
+ _ ("Failed to serialize metadata `%s'"),
+ what);
return GNUNET_SYSERR;
}
- if ((GNUNET_OK != GNUNET_BIO_write_int32 (h, (uint32_t) size)) ||
- (GNUNET_OK != GNUNET_BIO_write (h, buf, size)))
+ if ((GNUNET_OK != GNUNET_BIO_write_int32 (h,
+ _ ("metadata length"),
+ (uint32_t) size))
+ || (GNUNET_OK != GNUNET_BIO_write (h, what, buf, size)))
{
GNUNET_free (buf);
return GNUNET_SYSERR;
@@ -572,36 +890,669 @@ GNUNET_BIO_write_meta_data (struct GNUNET_BIO_WriteHandle *h,
/**
+ * Write a float.
+ *
+ * @param h the IO handle to write to
+ * @param what what is being written (for error message creation)
+ * @param f float to write
+ */
+int
+GNUNET_BIO_write_float(struct GNUNET_BIO_WriteHandle *h,
+ const char *what,
+ float f)
+{
+ int32_t i = f;
+ return GNUNET_BIO_write_int32 (h, what, i);
+}
+
+
+/**
+ * Write a double.
+ *
+ * @param h the IO handle to write to
+ * @param what what is being written (for error message creation)
+ * @param f double to write
+ */
+int
+GNUNET_BIO_write_double(struct GNUNET_BIO_WriteHandle *h,
+ const char *what,
+ double f)
+{
+ int64_t i = f;
+ return GNUNET_BIO_write_int64 (h, what, i);
+}
+
+
+/**
* Write an (u)int32_t.
*
- * @param h hande to open file
+ * @param h the IO handle to write to
+ * @param what what is being written (for error message creation)
* @param i 32-bit integer to write
* @return #GNUNET_OK on success, #GNUNET_SYSERR on error
*/
int
-GNUNET_BIO_write_int32 (struct GNUNET_BIO_WriteHandle *h, int32_t i)
+GNUNET_BIO_write_int32 (struct GNUNET_BIO_WriteHandle *h,
+ const char *what,
+ int32_t i)
{
int32_t big;
big = htonl (i);
- return GNUNET_BIO_write (h, &big, sizeof(int32_t));
+ return GNUNET_BIO_write (h, what, &big, sizeof(int32_t));
}
/**
* Write an (u)int64_t.
*
- * @param h hande to open file
+ * @param h the IO handle to write to
+ * @param what what is being written (for error message creation)
* @param i 64-bit integer to write
* @return #GNUNET_OK on success, #GNUNET_SYSERR on error
*/
int
-GNUNET_BIO_write_int64 (struct GNUNET_BIO_WriteHandle *h, int64_t i)
+GNUNET_BIO_write_int64 (struct GNUNET_BIO_WriteHandle *h,
+ const char *what,
+ int64_t i)
{
int64_t big;
big = GNUNET_htonll (i);
- return GNUNET_BIO_write (h, &big, sizeof(int64_t));
+ return GNUNET_BIO_write (h, what, &big, sizeof(int64_t));
+}
+
+
+/**
+ * Function used internally to read some bytes from within a read spec.
+ *
+ * @param cls ignored, always NULL
+ * @param h the IO handle to read from
+ * @param what what is being read (for error message creation)
+ * @param target where to store the data
+ * @param target_size how many bytes to read
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
+ */
+static int
+read_spec_handler_object (void *cls,
+ struct GNUNET_BIO_ReadHandle *h,
+ const char *what,
+ void *target,
+ size_t target_size)
+{
+ return GNUNET_BIO_read (h, what, target, target_size);
+}
+
+
+/**
+ * Create the specification to read a certain amount of bytes.
+ *
+ * @param what describes what is being read (for error message creation)
+ * @param result the buffer to write the result to
+ * @param len the number of bytes to read
+ * @return the read spec
+ */
+struct GNUNET_BIO_ReadSpec
+GNUNET_BIO_read_spec_object (const char *what,
+ void *result,
+ size_t len)
+{
+ struct GNUNET_BIO_ReadSpec rs = {
+ .rh = &read_spec_handler_object,
+ .cls = NULL,
+ .what = what,
+ .target = result,
+ .size = len,
+ };
+
+ return rs;
+}
+
+
+/**
+ * Function used interally to read a string from within a read spec.
+ *
+ * @param cls ignored, always NULL
+ * @param h the IO handle to read from
+ * @param what what is being read (for error message creation)
+ * @param target where to store the data
+ * @param target_size how many bytes to read
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
+ */
+static int
+read_spec_handler_string (void *cls,
+ struct GNUNET_BIO_ReadHandle *h,
+ const char *what,
+ void *target,
+ size_t target_size)
+{
+ char **result = target;
+ return GNUNET_BIO_read_string (h, what, result, target_size);
+}
+
+
+/**
+ * Create the specification to read a 0-terminated string.
+ *
+ * @param what describes what is being read (for error message creation)
+ * @param result where to store the pointer to the (allocated) string
+ * (note that *result could be set to NULL as well)
+ * @param max_length maximum allowed length for the string
+ * @return the read spec
+ */
+struct GNUNET_BIO_ReadSpec
+GNUNET_BIO_read_spec_string (const char *what,
+ char **result,
+ size_t max_length)
+{
+ struct GNUNET_BIO_ReadSpec rs = {
+ .rh = &read_spec_handler_string,
+ .cls = NULL,
+ .target = result,
+ .size = max_length,
+ };
+
+ return rs;
+}
+
+
+/**
+ * Function used internally to read a metadata container from within a read
+ * spec.
+ *
+ * @param cls ignored, always NULL
+ * @param h the IO handle to read from
+ * @param what what is being read (for error message creation)
+ * @param target where to store the data
+ * @param target_size ignored
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
+ */
+static int
+read_spec_handler_meta_data (void *cls,
+ struct GNUNET_BIO_ReadHandle *h,
+ const char *what,
+ void *target,
+ size_t target_size)
+{
+ struct GNUNET_CONTAINER_MetaData **result = target;
+ return GNUNET_BIO_read_meta_data (h, what, result);
+}
+
+
+/**
+ * Create the specification to read a metadata container.
+ *
+ * @param what describes what is being read (for error message creation)
+ * @param result the buffer to store a pointer to the (allocated) metadata
+ * @return the read spec
+ */
+struct GNUNET_BIO_ReadSpec
+GNUNET_BIO_read_spec_meta_data (const char *what,
+ struct GNUNET_CONTAINER_MetaData **result)
+{
+ struct GNUNET_BIO_ReadSpec rs = {
+ .rh = &read_spec_handler_meta_data,
+ .cls = NULL,
+ .target = result,
+ .size = 0,
+ };
+
+ return rs;
+}
+
+
+/**
+ * Function used internally to read an (u)int32_t from within a read spec.
+ *
+ * @param cls ignored, always NULL
+ * @param h the IO handle to read from
+ * @param what what is being read (for error message creation)
+ * @param target where to store the data
+ * @param target_size ignored
+ * @retun #GNUNET_OK on success, #GNUNET_SYSERR otherwise
+ */
+static int
+read_spec_handler_int32 (void *cls,
+ struct GNUNET_BIO_ReadHandle *h,
+ const char *what,
+ void *target,
+ size_t target_size)
+{
+ int32_t *result = target;
+ return GNUNET_BIO_read_int32 (h, what, result);
+}
+
+
+/**
+ * Create the specification to read an (u)int32_t.
+ *
+ * @param what describes what is being read (for error message creation)
+ * @param i where to store the data
+ * @return the read spec
+ */
+struct GNUNET_BIO_ReadSpec
+GNUNET_BIO_read_spec_int32 (const char *what,
+ int32_t *i)
+{
+ struct GNUNET_BIO_ReadSpec rs = {
+ .rh = &read_spec_handler_int32,
+ .cls = NULL,
+ .target = i,
+ .size = 0,
+ };
+
+ return rs;
+}
+
+
+/**
+ * Function used internally to read an (u)int64_t from within a read spec.
+ *
+ * @param cls ignored, always NULL
+ * @param h the IO handle to read from
+ * @param what what is being read (for error message creation)
+ * @param target where to store the data
+ * @param target_size ignored
+ * @retun #GNUNET_OK on success, #GNUNET_SYSERR otherwise
+ */
+static int
+read_spec_handler_int64 (void *cls,
+ struct GNUNET_BIO_ReadHandle *h,
+ const char *what,
+ void *target,
+ size_t target_size)
+{
+ int64_t *result = target;
+ return GNUNET_BIO_read_int64 (h, what, result);
+}
+
+
+/**
+ * Create the specification to read an (u)int64_t.
+ *
+ * @param what describes what is being read (for error message creation)
+ * @param i where to store the data
+ * @return the read spec
+ */
+struct GNUNET_BIO_ReadSpec
+GNUNET_BIO_read_spec_int64 (const char *what,
+ int64_t *i)
+{
+ struct GNUNET_BIO_ReadSpec rs = {
+ .rh = &read_spec_handler_int64,
+ .cls = NULL,
+ .target = i,
+ .size = 0,
+ };
+
+ return rs;
+}
+
+
+/**
+ * Create the specification to read a float.
+ *
+ * @param what describes what is being read (for error message creation)
+ * @param f address of float to read
+ */
+struct GNUNET_BIO_ReadSpec
+GNUNET_BIO_read_spec_float(const char *what, float *f)
+{
+ struct GNUNET_BIO_ReadSpec rs = {
+ .rh = &read_spec_handler_int32,
+ .cls = NULL,
+ .target = (int32_t *) f,
+ .size = 0,
+ };
+
+ return rs;
+}
+
+
+/**
+ * Create the specification to read a double.
+ *
+ * @param what describes what is being read (for error message creation)
+ * @param f address of double to read
+ */
+struct GNUNET_BIO_ReadSpec
+GNUNET_BIO_read_spec_double(const char *what, double *f)
+{
+ struct GNUNET_BIO_ReadSpec rs = {
+ .rh = &read_spec_handler_int64,
+ .cls = NULL,
+ .target = (int64_t *) f,
+ .size = 0,
+ };
+
+ return rs;
+}
+
+
+/**
+ * Execute the read specifications in order.
+ *
+ * @param h the IO handle to read from
+ * @param rs array of read specs
+ * the last element must be #GNUNET_BIO_read_spec_end
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
+ */
+int
+GNUNET_BIO_read_spec_commit (struct GNUNET_BIO_ReadHandle *h,
+ struct GNUNET_BIO_ReadSpec *rs)
+{
+ int ret = GNUNET_OK;
+
+ for (size_t i=0; NULL!=rs[i].rh; ++i)
+ {
+ ret = rs[i].rh (rs[i].cls, h, rs[i].what, rs[i].target, rs[i].size);
+ if (GNUNET_OK != ret)
+ return ret;
+ }
+
+ return ret;
+}
+
+
+/**
+ * Function used internally to write some bytes from within a write spec.
+ *
+ * @param cls ignored, always NULL
+ * @param h the IO handle to write to
+ * @param what what is being written (for error message creation)
+ * @param source the data to write
+ * @param source_size how many bytes to write
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
+ */
+static int
+write_spec_handler_object (void *cls,
+ struct GNUNET_BIO_WriteHandle *h,
+ const char *what,
+ void *source,
+ size_t source_size)
+{
+ return GNUNET_BIO_write (h, what, source, source_size);
+}
+
+
+/**
+ * Create the specification to read some bytes.
+ *
+ * @param what describes what is being written (for error message creation)
+ * @param source the data to write
+ * @param size how many bytes should be written
+ * @return the write spec
+ */
+struct GNUNET_BIO_WriteSpec
+GNUNET_BIO_write_spec_object (const char *what,
+ void *source,
+ size_t size)
+{
+ struct GNUNET_BIO_WriteSpec ws = {
+ .wh = &write_spec_handler_object,
+ .cls = NULL,
+ .what = what,
+ .source = source,
+ .source_size = size,
+ };
+
+ return ws;
+}
+
+
+/**
+ * Function used internally to write a 0-terminated string from within a write
+ * spec.
+ *
+ * @param cls ignored, always NULL
+ * @param h the IO handle to write to
+ * @param what what is being written (for error message creation)
+ * @param source the data to write
+ * @param source_size ignored
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
+ */
+static int
+write_spec_handler_string (void *cls,
+ struct GNUNET_BIO_WriteHandle *h,
+ const char *what,
+ void *source,
+ size_t source_size)
+{
+ const char *s = source;
+ return GNUNET_BIO_write_string (h, what, s);
+}
+
+
+/**
+ * Create the specification to write a 0-terminated string.
+ *
+ * @param what describes what is being read (for error message creation)
+ * @param s string to write (can be NULL)
+ * @return the read spec
+ */
+struct GNUNET_BIO_WriteSpec
+GNUNET_BIO_write_spec_string (const char *what,
+ const char *s)
+{
+ struct GNUNET_BIO_WriteSpec ws = {
+ .wh = &write_spec_handler_string,
+ .cls = NULL,
+ .what = what,
+ .source = (void *) s,
+ .source_size = 0,
+ };
+
+ return ws;
+}
+
+
+/**
+ * Function used internally to write a metadata container from within a write
+ * spec.
+ *
+ * @param cls ignored, always NULL
+ * @param h the IO handle to write to
+ * @param what what is being written (for error message creation)
+ * @param source the data to write
+ * @param source_size ignored
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
+ */
+static int
+write_spec_handler_meta_data (void *cls,
+ struct GNUNET_BIO_WriteHandle *h,
+ const char *what,
+ void *source,
+ size_t source_size)
+{
+ const struct GNUNET_CONTAINER_MetaData *m = source;
+ return GNUNET_BIO_write_meta_data (h, what, m);
+}
+
+
+/**
+ * Create the specification to write a metadata container.
+ *
+ * @param what what is being written (for error message creation)
+ * @param m metadata to write
+ * @return the write spec
+ */
+struct GNUNET_BIO_WriteSpec
+GNUNET_BIO_write_spec_meta_data (const char *what,
+ const struct GNUNET_CONTAINER_MetaData *m)
+{
+ struct GNUNET_BIO_WriteSpec ws = {
+ .wh = &write_spec_handler_meta_data,
+ .cls = NULL,
+ .what = what,
+ .source = (void *) m,
+ .source_size = 0,
+ };
+
+ return ws;
+}
+
+
+/**
+ * Function used internally to write an (u)int32_t from within a write spec.
+ *
+ * @param cls ignored, always NULL
+ * @param h the IO handle to write to
+ * @param what what is being written (for error message creation)
+ * @param source the data to write
+ * @param source_size ignored
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
+ */
+static int
+write_spec_handler_int32 (void *cls,
+ struct GNUNET_BIO_WriteHandle *h,
+ const char *what,
+ void *source,
+ size_t source_size)
+{
+ int32_t i = *(int32_t *) source;
+ return GNUNET_BIO_write_int32 (h, what, i);
+}
+
+
+/**
+ * Create the specification to write an (u)int32_t.
+ *
+ * @param what describes what is being written (for error message creation)
+ * @param i pointer to a 32-bit integer
+ * @return the write spec
+ */
+struct GNUNET_BIO_WriteSpec
+GNUNET_BIO_write_spec_int32 (const char *what,
+ int32_t *i)
+{
+ struct GNUNET_BIO_WriteSpec ws = {
+ .wh = &write_spec_handler_int32,
+ .cls = NULL,
+ .what = what,
+ .source = i,
+ .source_size = 0,
+ };
+
+ return ws;
+}
+
+
+/**
+ * Function used internally to write an (u)int64_t from within a write spec.
+ *
+ * @param cls ignored, always NULL
+ * @param h the IO handle to write to
+ * @param what what is being written (for error message creation)
+ * @param source the data to write
+ * @param source_size ignored
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
+ */
+static int
+write_spec_handler_int64 (void *cls,
+ struct GNUNET_BIO_WriteHandle *h,
+ const char *what,
+ void *source,
+ size_t source_size)
+{
+ int64_t i = *(int64_t *) source;
+ return GNUNET_BIO_write_int64 (h, what, i);
+}
+
+
+/**
+ * Create the specification to write an (u)int64_t.
+ *
+ * @param what describes what is being written (for error message creation)
+ * @param i pointer to a 64-bit integer
+ * @return the write spec
+ */
+struct GNUNET_BIO_WriteSpec
+GNUNET_BIO_write_spec_int64 (const char *what,
+ int64_t *i)
+{
+ struct GNUNET_BIO_WriteSpec ws = {
+ .wh = &write_spec_handler_int64,
+ .cls = NULL,
+ .what = what,
+ .source = i,
+ .source_size = 0,
+ };
+
+ return ws;
+}
+
+
+/**
+ * Create the specification to write a float.
+ *
+ * @param what describes what is being written (for error message creation)
+ * @param f pointer to a float
+ * @return the write spec
+ */
+struct GNUNET_BIO_WriteSpec
+GNUNET_BIO_write_spec_float(const char *what, float *f)
+{
+ struct GNUNET_BIO_WriteSpec ws = {
+ .wh = &write_spec_handler_int32,
+ .cls = NULL,
+ .what = what,
+ .source = (int32_t *) f,
+ .source_size = 0,
+ };
+
+ return ws;
+}
+
+
+/**
+ * Create the specification to write an double.
+ *
+ * @param what describes what is being written (for error message creation)
+ * @param f pointer to a double
+ * @return the write spec
+ */
+struct GNUNET_BIO_WriteSpec
+GNUNET_BIO_write_spec_double(const char *what, double *f)
+{
+ struct GNUNET_BIO_WriteSpec ws = {
+ .wh = &write_spec_handler_int64,
+ .cls = NULL,
+ .what = what,
+ .source = (int64_t *) f,
+ .source_size = 0,
+ };
+
+ return ws;
+}
+
+
+/**
+ * Execute the write specifications in order.
+ *
+ * @param h the IO handle to write to
+ * @param ws array of write specs
+ * the last element must be #GNUNET_BIO_write_spec_end
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
+ */
+int
+GNUNET_BIO_write_spec_commit (struct GNUNET_BIO_WriteHandle *h,
+ struct GNUNET_BIO_WriteSpec *ws)
+{
+ int ret = GNUNET_OK;
+
+ for (size_t i=0; NULL!=ws[i].wh; ++i)
+ {
+ ret = ws[i].wh (ws[i].cls, h, ws[i].what, ws[i].source, ws[i].source_size);
+ if (GNUNET_OK != ret)
+ return ret;
+ }
+
+ /* If it's a file-based handle, the flush makes sure that the data in the
+ buffer is actualy written to the disk. */
+ if (IO_FILE == h->type)
+ ret = GNUNET_BIO_flush (h);
+
+ return ret;
}
diff --git a/src/util/buffer.c b/src/util/buffer.c
index dabf630c7..c865f6307 100644
--- a/src/util/buffer.c
+++ b/src/util/buffer.c
@@ -130,7 +130,26 @@ GNUNET_buffer_reap_str (struct GNUNET_Buffer *buf)
buf->mem[buf->position++] = '\0';
}
res = buf->mem;
- *buf = (struct GNUNET_Buffer) { 0 };
+ memset (buf, 0, sizeof (struct GNUNET_Buffer));
+ return res;
+}
+
+
+/**
+ * Clear the buffer and return its contents.
+ * The caller is responsible to eventually #GNUNET_free
+ * the returned data.
+ *
+ * @param buf the buffer to reap the contents from
+ * @param size where to store the size of the returned data
+ * @returns the data contained in the string
+ */
+void *
+GNUNET_buffer_reap (struct GNUNET_Buffer *buf, size_t *size)
+{
+ *size = buf->position;
+ void *res = buf->mem;
+ memset (buf, 0, sizeof (struct GNUNET_Buffer));
return res;
}
@@ -144,7 +163,7 @@ void
GNUNET_buffer_clear (struct GNUNET_Buffer *buf)
{
GNUNET_free_non_null (buf->mem);
- *buf = (struct GNUNET_Buffer) { 0 };
+ memset (buf, 0, sizeof (struct GNUNET_Buffer));
}
diff --git a/src/util/crypto_ecc.c b/src/util/crypto_ecc.c
index 96d546185..e1608ae55 100644
--- a/src/util/crypto_ecc.c
+++ b/src/util/crypto_ecc.c
@@ -544,10 +544,18 @@ void
GNUNET_CRYPTO_eddsa_key_create (struct GNUNET_CRYPTO_EddsaPrivateKey *pk)
{
BENCHMARK_START (eddsa_key_create);
+ /*
+ * We do not clamp for EdDSA, since all functions that use the private key do
+ * their own clamping (just like in libsodium). What we call "private key"
+ * here, actually corresponds to the seed in libsodium.
+ *
+ * (Contrast this to ECDSA, where functions using the private key can't clamp
+ * due to properties needed for GNS. That is a worse/unsafer API, but
+ * required for the GNS constructions to work.)
+ */
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE,
pk,
sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey));
- // FIXME: should we not do the clamping here? Or is this done elsewhere?
BENCHMARK_END (eddsa_key_create);
}
diff --git a/src/util/crypto_hash.c b/src/util/crypto_hash.c
index c41c419ff..622953476 100644
--- a/src/util/crypto_hash.c
+++ b/src/util/crypto_hash.c
@@ -244,18 +244,35 @@ GNUNET_CRYPTO_hash_to_aes_key (const struct GNUNET_HashCode *hc,
/**
* Obtain a bit from a hashcode.
* @param code the GNUNET_CRYPTO_hash to index bit-wise
- * @param bit index into the hashcode, [0...511]
+ * @param bit index into the hashcode, [0...511] where 0 is the leftmost bit
+ * (bytes in code interpreted big endian)
* @return Bit \a bit from hashcode \a code, -1 for invalid index
*/
int
-GNUNET_CRYPTO_hash_get_bit (const struct GNUNET_HashCode *code, unsigned int
- bit)
+GNUNET_CRYPTO_hash_get_bit_ltr (const struct GNUNET_HashCode *code,
+ unsigned int bit)
+{
+ GNUNET_assert (bit < 8 * sizeof(struct GNUNET_HashCode));
+ return (((unsigned char *) code)[bit >> 3] & (128 >> (bit & 7))) > 0;
+}
+
+/**
+ * Obtain a bit from a hashcode.
+ * @param code the GNUNET_CRYPTO_hash to index bit-wise
+ * @param bit index into the hashcode, [0...511] where 0 is the rightmost bit
+ * (bytes in code interpreted little endian)
+ * @return Bit \a bit from hashcode \a code, -1 for invalid index
+ */
+int
+GNUNET_CRYPTO_hash_get_bit_rtl (const struct GNUNET_HashCode *code,
+ unsigned int bit)
{
GNUNET_assert (bit < 8 * sizeof(struct GNUNET_HashCode));
return (((unsigned char *) code)[bit >> 3] & (1 << (bit & 7))) > 0;
}
+
/**
* Determine how many low order bits match in two
* `struct GNUNET_HashCode`s. i.e. - 010011 and 011111 share
@@ -275,8 +292,8 @@ GNUNET_CRYPTO_hash_matching_bits (const struct GNUNET_HashCode *first,
unsigned int i;
for (i = 0; i < sizeof(struct GNUNET_HashCode) * 8; i++)
- if (GNUNET_CRYPTO_hash_get_bit (first, i) !=
- GNUNET_CRYPTO_hash_get_bit (second, i))
+ if (GNUNET_CRYPTO_hash_get_bit_rtl (first, i) !=
+ GNUNET_CRYPTO_hash_get_bit_rtl (second, i))
return i;
return sizeof(struct GNUNET_HashCode) * 8;
}
diff --git a/src/util/crypto_pow.c b/src/util/crypto_pow.c
index 35511a130..cfa0676d0 100644
--- a/src/util/crypto_pow.c
+++ b/src/util/crypto_pow.c
@@ -25,14 +25,14 @@
*/
#include "platform.h"
#include "gnunet_crypto_lib.h"
-#include <argon2.h>
+#include <sodium.h>
/**
* Calculate the 'proof-of-work' hash (an expensive hash).
* We're using a non-standard formula to avoid issues with
* ASICs appearing (see #3795).
*
- * @param salt salt for the hash
+ * @param salt salt for the hash. Must be crypto_pwhash_argon2id_SALTBYTES long.
* @param buf data to hash
* @param buf_len number of bytes in @a buf
* @param result where to write the resulting hash
@@ -43,17 +43,17 @@ GNUNET_CRYPTO_pow_hash (const char *salt,
size_t buf_len,
struct GNUNET_HashCode *result)
{
- GNUNET_break (ARGON2_OK == argon2d_hash_raw (3, /* iterations */
- 1024, /* memory (1 MiB) */
- 1, /* threads */
- buf,
- buf_len,
- salt,
- strlen (salt),
- result,
- sizeof (struct
- GNUNET_HashCode)));
-
+ GNUNET_assert (strlen (salt) == crypto_pwhash_argon2id_SALTBYTES);
+ /* Threads hardcoded at 1 in libsodium */
+ GNUNET_break (0 ==
+ crypto_pwhash_argon2id ((unsigned char *) result,
+ sizeof (struct GNUNET_HashCode),
+ buf,
+ buf_len,
+ (unsigned char*) salt,
+ 3, /* iterations */
+ 1024 * 1024, /* memory (1 MiB) */
+ crypto_pwhash_argon2id_ALG_ARGON2ID13));
}
diff --git a/src/util/crypto_rsa.c b/src/util/crypto_rsa.c
index 2957546a7..cb4640d48 100644
--- a/src/util/crypto_rsa.c
+++ b/src/util/crypto_rsa.c
@@ -620,8 +620,8 @@ rsa_blinding_key_derive (const struct GNUNET_CRYPTO_RsaPublicKey *pkey,
* @return 0 if the two are equal
*/
int
-GNUNET_CRYPTO_rsa_signature_cmp (struct GNUNET_CRYPTO_RsaSignature *s1,
- struct GNUNET_CRYPTO_RsaSignature *s2)
+GNUNET_CRYPTO_rsa_signature_cmp (const struct GNUNET_CRYPTO_RsaSignature *s1,
+ const struct GNUNET_CRYPTO_RsaSignature *s2)
{
void *b1;
void *b2;
@@ -653,8 +653,8 @@ GNUNET_CRYPTO_rsa_signature_cmp (struct GNUNET_CRYPTO_RsaSignature *s1,
* @return 0 if the two are equal
*/
int
-GNUNET_CRYPTO_rsa_public_key_cmp (struct GNUNET_CRYPTO_RsaPublicKey *p1,
- struct GNUNET_CRYPTO_RsaPublicKey *p2)
+GNUNET_CRYPTO_rsa_public_key_cmp (const struct GNUNET_CRYPTO_RsaPublicKey *p1,
+ const struct GNUNET_CRYPTO_RsaPublicKey *p2)
{
void *b1;
void *b2;
@@ -686,8 +686,8 @@ GNUNET_CRYPTO_rsa_public_key_cmp (struct GNUNET_CRYPTO_RsaPublicKey *p1,
* @return 0 if the two are equal
*/
int
-GNUNET_CRYPTO_rsa_private_key_cmp (struct GNUNET_CRYPTO_RsaPrivateKey *p1,
- struct GNUNET_CRYPTO_RsaPrivateKey *p2)
+GNUNET_CRYPTO_rsa_private_key_cmp (const struct GNUNET_CRYPTO_RsaPrivateKey *p1,
+ const struct GNUNET_CRYPTO_RsaPrivateKey *p2)
{
void *b1;
void *b2;
diff --git a/src/util/gnunet-scrypt.c b/src/util/gnunet-scrypt.c
index 70ba48d82..7d13ce469 100644
--- a/src/util/gnunet-scrypt.c
+++ b/src/util/gnunet-scrypt.c
@@ -79,7 +79,7 @@ count_leading_zeroes (const struct GNUNET_HashCode *hash)
unsigned int hash_count;
hash_count = 0;
- while (0 == GNUNET_CRYPTO_hash_get_bit (hash, hash_count))
+ while (0 == GNUNET_CRYPTO_hash_get_bit_ltr (hash, hash_count))
hash_count++;
return hash_count;
}
@@ -117,7 +117,7 @@ find_proof (void *cls)
while ((counter != UINT64_MAX) && (i < ROUND_SIZE))
{
GNUNET_memcpy (buf, &counter, sizeof(uint64_t));
- GNUNET_CRYPTO_pow_hash ("gnunet-nse-proof-of-work",
+ GNUNET_CRYPTO_pow_hash ("gnunet-nse-proof",
buf,
sizeof(buf),
&result);
diff --git a/src/util/os_installation.c b/src/util/os_installation.c
index dcd31dc2c..714df6957 100644
--- a/src/util/os_installation.c
+++ b/src/util/os_installation.c
@@ -70,6 +70,7 @@ static const struct GNUNET_OS_ProjectData default_pd = {
.is_gnu = 1,
.gettext_domain = PACKAGE,
.gettext_path = NULL,
+ .agpl_url = GNUNET_AGPL_URL,
};
/**
diff --git a/src/util/perf_crypto_asymmetric.c b/src/util/perf_crypto_asymmetric.c
index 49d9ec644..8533351e1 100644
--- a/src/util/perf_crypto_asymmetric.c
+++ b/src/util/perf_crypto_asymmetric.c
@@ -62,9 +62,9 @@ int
main (int argc, char *argv[])
{
int i;
- struct GNUNET_CRYPTO_EcdhePrivateKey *ecdhe[l];
+ struct GNUNET_CRYPTO_EcdhePrivateKey ecdhe[l];
struct GNUNET_CRYPTO_EcdhePublicKey dhpub[l];
- struct GNUNET_CRYPTO_EddsaPrivateKey *eddsa[l];
+ struct GNUNET_CRYPTO_EddsaPrivateKey eddsa[l];
struct GNUNET_CRYPTO_EddsaPublicKey dspub[l];
struct TestSig sig[l];
@@ -82,18 +82,18 @@ main (int argc, char *argv[])
start = GNUNET_TIME_absolute_get ();
for (i = 0; i < l; i++)
- eddsa[i] = GNUNET_CRYPTO_eddsa_key_create ();
+ GNUNET_CRYPTO_eddsa_key_create (&eddsa[i]);
log_duration ("EdDSA", "create key");
start = GNUNET_TIME_absolute_get ();
for (i = 0; i < l; i++)
- GNUNET_CRYPTO_eddsa_key_get_public (eddsa[i], &dspub[i]);
+ GNUNET_CRYPTO_eddsa_key_get_public (&eddsa[i], &dspub[i]);
log_duration ("EdDSA", "get public");
start = GNUNET_TIME_absolute_get ();
for (i = 0; i < l; i++)
GNUNET_assert (GNUNET_OK ==
- GNUNET_CRYPTO_eddsa_sign_ (eddsa[i],
+ GNUNET_CRYPTO_eddsa_sign_ (&eddsa[i],
&sig[i].purp,
&sig[i].sig));
log_duration ("EdDSA", "sign HashCode");
@@ -109,19 +109,19 @@ main (int argc, char *argv[])
start = GNUNET_TIME_absolute_get ();
for (i = 0; i < l; i++)
- ecdhe[i] = GNUNET_CRYPTO_ecdhe_key_create ();
+ GNUNET_CRYPTO_ecdhe_key_create (&ecdhe[i]);
log_duration ("ECDH", "create key");
start = GNUNET_TIME_absolute_get ();
for (i = 0; i < l; i++)
- GNUNET_CRYPTO_ecdhe_key_get_public (ecdhe[i], &dhpub[i]);
+ GNUNET_CRYPTO_ecdhe_key_get_public (&ecdhe[i], &dhpub[i]);
log_duration ("ECDH", "get public");
start = GNUNET_TIME_absolute_get ();
for (i = 0; i < l - 1; i += 2)
{
- GNUNET_CRYPTO_ecc_ecdh (ecdhe[i], &dhpub[i + 1], &sig[i].h);
- GNUNET_CRYPTO_ecc_ecdh (ecdhe[i + 1], &dhpub[i], &sig[i + 1].h);
+ GNUNET_CRYPTO_ecc_ecdh (&ecdhe[i], &dhpub[i + 1], &sig[i].h);
+ GNUNET_CRYPTO_ecc_ecdh (&ecdhe[i + 1], &dhpub[i], &sig[i + 1].h);
}
log_duration ("ECDH", "do DH");
diff --git a/src/util/resolver_api.c b/src/util/resolver_api.c
index a1e30bbd4..d38c700e4 100644
--- a/src/util/resolver_api.c
+++ b/src/util/resolver_api.c
@@ -152,7 +152,7 @@ struct GNUNET_RESOLVER_RequestHandle
/**
* Has this request been transmitted to the service?
* #GNUNET_YES if transmitted
- * #GNUNET_YES if not transmitted
+ * #GNUNET_NO if not transmitted
* #GNUNET_SYSERR when request was canceled
*/
int was_transmitted;
diff --git a/src/util/service.c b/src/util/service.c
index 9dc14eba9..ea078b19b 100644
--- a/src/util/service.c
+++ b/src/util/service.c
@@ -1823,9 +1823,10 @@ return_agpl (void *cls, const struct GNUNET_MessageHeader *msg)
struct GNUNET_MQ_Envelope *env;
struct GNUNET_MessageHeader *res;
size_t slen;
+ const struct GNUNET_OS_ProjectData *pd = GNUNET_OS_project_data_get ();
(void) msg;
- slen = strlen (GNUNET_AGPL_URL) + 1;
+ slen = strlen (pd->agpl_url) + 1;
env = GNUNET_MQ_msg_extra (res, GNUNET_MESSAGE_TYPE_RESPONSE_AGPL, slen);
memcpy (&res[1], GNUNET_AGPL_URL, slen);
mq = GNUNET_SERVICE_client_get_mq (client);
@@ -2019,7 +2020,9 @@ GNUNET_SERVICE_run_ (int argc,
sh.connect_cb = connect_cb;
sh.disconnect_cb = disconnect_cb;
sh.cb_cls = cls;
- sh.handlers = GNUNET_MQ_copy_handlers (handlers);
+ sh.handlers = (NULL == pd->agpl_url)
+ ? GNUNET_MQ_copy_handlers (handlers)
+ : GNUNET_MQ_copy_handlers2 (handlers, &return_agpl, NULL);
sh.service_name = service_name;
sh.ret = 0;
/* setup subsystems */
diff --git a/src/util/test_bio.c b/src/util/test_bio.c
index 53b45c23a..0c8453121 100644
--- a/src/util/test_bio.c
+++ b/src/util/test_bio.c
@@ -30,363 +30,406 @@
#define TESTSTRING "testString"
#define TESTNUMBER64 ((int64_t) 100000L)
+
static int
-test_normal_rw ()
+test_normal_rw (void)
{
- char *msg;
- int64_t testNum;
- char *readResultString;
- char *fileName = GNUNET_DISK_mktemp ("gnunet_bio");
- struct GNUNET_BIO_WriteHandle *fileW;
- struct GNUNET_BIO_ReadHandle *fileR;
- struct GNUNET_CONTAINER_MetaData *metaDataW;
- struct GNUNET_CONTAINER_MetaData *metaDataR;
-
- metaDataW = GNUNET_CONTAINER_meta_data_create ();
- metaDataR = NULL;
- GNUNET_CONTAINER_meta_data_add_publication_date (metaDataW);
-
- fileW = GNUNET_BIO_write_open (fileName);
- GNUNET_assert (NULL != fileW);
- GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_string (fileW, TESTSTRING));
- GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_meta_data (fileW, metaDataW));
- GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_int64 (fileW, TESTNUMBER64));
- GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (fileW));
-
- fileR = GNUNET_BIO_read_open (fileName);
- GNUNET_assert (NULL != fileR);
- readResultString = NULL;
- GNUNET_assert (GNUNET_OK ==
- GNUNET_BIO_read_string (fileR, "Read string error",
- &readResultString, 200));
- GNUNET_assert (NULL != readResultString);
- GNUNET_assert (0 == strcmp (TESTSTRING, readResultString));
- GNUNET_free (readResultString);
+ struct GNUNET_BIO_WriteHandle *wh;
+ struct GNUNET_BIO_ReadHandle *rh;
+ void *buffer;
+ size_t buffer_size = 0;
+ char *filename = GNUNET_DISK_mktemp ("gnunet-bio");
+ struct GNUNET_CONTAINER_MetaData *mdW;
+ struct GNUNET_CONTAINER_MetaData *mdR = NULL;
+ char *rString = NULL;
+ int64_t wNum = TESTNUMBER64;
+ int64_t rNum = 0;
+
+ mdW = GNUNET_CONTAINER_meta_data_create ();
+ GNUNET_CONTAINER_meta_data_add_publication_date (mdW);
+
+ struct GNUNET_BIO_WriteSpec ws[] = {
+ GNUNET_BIO_write_spec_string ("test-normal-rw-string", TESTSTRING),
+ GNUNET_BIO_write_spec_meta_data ("test-normal-rw-metadata", mdW),
+ GNUNET_BIO_write_spec_int64 ("test-normal-rw-int64", &wNum),
+ GNUNET_BIO_write_spec_end(),
+ };
+
+ struct GNUNET_BIO_ReadSpec rs[] = {
+ GNUNET_BIO_read_spec_string ("test-normal-rw-string", &rString, 200),
+ GNUNET_BIO_read_spec_meta_data ("test-normal-rw-metadata", &mdR),
+ GNUNET_BIO_read_spec_int64 ("test-normal-rw-int64", &rNum),
+ GNUNET_BIO_read_spec_end(),
+ };
+
+ /* I/O on file */
+ wh = GNUNET_BIO_write_open_file (filename);
+ GNUNET_assert (NULL != wh);
+ GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_spec_commit (wh, ws));
+ GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (wh, NULL));
+
+ rh = GNUNET_BIO_read_open_file (filename);
+ GNUNET_assert (NULL != rh);
+ GNUNET_assert (GNUNET_OK == GNUNET_BIO_read_spec_commit (rh, rs));
+ GNUNET_assert (GNUNET_OK == GNUNET_BIO_read_close (rh, NULL));
+ GNUNET_assert (0 == strcmp (TESTSTRING, rString));
+ GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_meta_data_test_equal (mdR, mdW));
+ GNUNET_assert (wNum == rNum);
+
+ GNUNET_CONTAINER_meta_data_destroy (mdR);
+ GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (filename));
+ GNUNET_free(filename);
+
+ /* I/O on buffer */
+ wh = GNUNET_BIO_write_open_buffer ();
+ GNUNET_assert (NULL != wh);
+ GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_spec_commit (wh, ws));
GNUNET_assert (GNUNET_OK ==
- GNUNET_BIO_read_meta_data (fileR, "Read meta error",
- &metaDataR));
- GNUNET_assert (GNUNET_YES ==
- GNUNET_CONTAINER_meta_data_test_equal (metaDataR, metaDataW));
- GNUNET_assert (GNUNET_OK == GNUNET_BIO_read_int64 (fileR, &testNum));
- GNUNET_BIO_read_close (fileR, &msg);
- GNUNET_CONTAINER_meta_data_destroy (metaDataW);
- GNUNET_CONTAINER_meta_data_destroy (metaDataR);
- GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (fileName));
- GNUNET_free (fileName);
+ GNUNET_BIO_get_buffer_contents (wh,
+ NULL,
+ &buffer,
+ &buffer_size));
+ GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (wh, NULL));
+
+ rh = GNUNET_BIO_read_open_buffer (buffer, buffer_size);
+ GNUNET_assert (NULL != rh);
+ GNUNET_assert (GNUNET_OK == GNUNET_BIO_read_spec_commit (rh, rs));
+ GNUNET_assert (GNUNET_OK == GNUNET_BIO_read_close (rh, NULL));
+ GNUNET_assert (0 == strcmp (TESTSTRING, rString));
+ GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_meta_data_test_equal (mdR, mdW));
+ GNUNET_assert (wNum == rNum);
+
+ GNUNET_free (buffer);
+
+ GNUNET_CONTAINER_meta_data_destroy (mdW);
+ GNUNET_CONTAINER_meta_data_destroy (mdR);
return 0;
}
static int
-test_nullstring_rw ()
+test_nullstring_rw (void)
{
- char *msg;
- char *readResultString = (char *) "not null";
- struct GNUNET_BIO_WriteHandle *fileW;
- struct GNUNET_BIO_ReadHandle *fileR;
- char *fileName = GNUNET_DISK_mktemp ("gnunet_bio");
-
- fileW = GNUNET_BIO_write_open (fileName);
- GNUNET_assert (NULL != fileW);
- GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_string (fileW, NULL));
- GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (fileW));
-
- fileR = GNUNET_BIO_read_open (fileName);
- GNUNET_assert (NULL != fileR);
- GNUNET_assert (GNUNET_OK ==
- GNUNET_BIO_read_string (fileR, "Read string error",
- &readResultString, 200));
- GNUNET_assert (NULL == readResultString);
- GNUNET_BIO_read_close (fileR, &msg);
- GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (fileName));
- GNUNET_free (fileName);
-
+ struct GNUNET_BIO_WriteHandle *wh;
+ struct GNUNET_BIO_ReadHandle *rh;
+ char *filename = GNUNET_DISK_mktemp ("gnunet_bio");
+ char *rString = "not null";
+
+ wh = GNUNET_BIO_write_open_file (filename);
+ GNUNET_assert (NULL != wh);
+ GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_string (wh,
+ "test-nullstring-rw",
+ NULL));
+ GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (wh, NULL));
+
+ rh = GNUNET_BIO_read_open_file (filename);
+ GNUNET_assert (NULL != rh);
+ GNUNET_assert (GNUNET_OK == GNUNET_BIO_read_string (rh,
+ "test-nullstring-rw",
+ &rString, 200));
+ GNUNET_assert (GNUNET_OK == GNUNET_BIO_read_close (rh, NULL));
+
+ GNUNET_assert (NULL == rString);
+
+ GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (filename));
+ GNUNET_free (filename);
return 0;
}
static int
-test_emptystring_rw ()
+test_emptystring_rw (void)
{
- char *msg;
- char *readResultString;
- struct GNUNET_BIO_WriteHandle *fileW;
- struct GNUNET_BIO_ReadHandle *fileR;
- char *fileName = GNUNET_DISK_mktemp ("gnunet_bio");
-
- fileW = GNUNET_BIO_write_open (fileName);
- GNUNET_assert (NULL != fileW);
- GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_string (fileW, ""));
- GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (fileW));
-
- fileR = GNUNET_BIO_read_open (fileName);
- GNUNET_assert (NULL != fileR);
- readResultString = NULL;
- GNUNET_assert (GNUNET_OK ==
- GNUNET_BIO_read_string (fileR, "Read string error",
- &readResultString, 200));
- GNUNET_free (readResultString);
- GNUNET_BIO_read_close (fileR, &msg);
- GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (fileName));
- GNUNET_free (fileName);
+ struct GNUNET_BIO_WriteHandle *wh;
+ struct GNUNET_BIO_ReadHandle *rh;
+ char *filename = GNUNET_DISK_mktemp ("gnunet_bio");
+ char *rString = NULL;
+
+ wh = GNUNET_BIO_write_open_file (filename);
+ GNUNET_assert (NULL != wh);
+ GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_string (wh,
+ "test-emptystring-rw",
+ ""));
+ GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (wh, NULL));
+
+ rh = GNUNET_BIO_read_open_file (filename);
+ GNUNET_assert (NULL != rh);
+ GNUNET_assert (GNUNET_OK == GNUNET_BIO_read_string (rh,
+ "test-emptystring-rw",
+ &rString, 200));
+ GNUNET_assert (GNUNET_OK == GNUNET_BIO_read_close (rh, NULL));
+
+ GNUNET_free (rString);
+
+ GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (filename));
+ GNUNET_free (filename);
return 0;
}
static int
-test_bigstring_rw ()
+test_bigstring_rw (void)
{
- char *msg;
- char *readResultString;
- struct GNUNET_BIO_WriteHandle *fileW;
- struct GNUNET_BIO_ReadHandle *fileR;
- char *fileName = GNUNET_DISK_mktemp ("gnunet_bio");
-
- fileW = GNUNET_BIO_write_open (fileName);
- GNUNET_assert (NULL != fileW);
- GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_string (fileW, TESTSTRING));
- GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (fileW));
-
- fileR = GNUNET_BIO_read_open (fileName);
- GNUNET_assert (NULL != fileR);
- readResultString = NULL;
- GNUNET_assert (GNUNET_SYSERR ==
- GNUNET_BIO_read_string (fileR, "Read string error",
- &readResultString, 1));
- GNUNET_assert (NULL == readResultString);
- msg = NULL;
- GNUNET_BIO_read_close (fileR, &msg);
- GNUNET_free (msg);
- GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (fileName));
- GNUNET_free (fileName);
+ struct GNUNET_BIO_WriteHandle *wh;
+ struct GNUNET_BIO_ReadHandle *rh;
+ char *filename = GNUNET_DISK_mktemp ("gnunet_bio");
+ char *rString = NULL;
+
+ wh = GNUNET_BIO_write_open_file (filename);
+ GNUNET_assert (NULL != wh);
+ GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_string (wh,
+ "test-bigstring-rw",
+ TESTSTRING));
+ GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (wh, NULL));
+
+ rh = GNUNET_BIO_read_open_file (filename);
+ GNUNET_assert (NULL != rh);
+ GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_read_string (rh,
+ "test-bigstring-rw",
+ &rString, 1));
+ GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_read_close (rh, NULL));
+
+ GNUNET_assert (NULL == rString);
+
+ GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (filename));
+ GNUNET_free (filename);
return 0;
}
static int
-test_bigmeta_rw ()
+test_bigmeta_rw (void)
{
- char *msg;
static char meta[1024 * 1024 * 10];
- struct GNUNET_BIO_WriteHandle *fileW;
- struct GNUNET_BIO_ReadHandle *fileR;
- char *fileName = GNUNET_DISK_mktemp ("gnunet_bio");
- struct GNUNET_CONTAINER_MetaData *metaDataR;
-
- memset (meta, 'b', sizeof(meta));
- meta[sizeof(meta) - 1] = '\0';
- fileW = GNUNET_BIO_write_open (fileName);
- GNUNET_assert (NULL != fileW);
- GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_int32 (fileW, sizeof(meta)));
- GNUNET_assert (GNUNET_OK == GNUNET_BIO_write (fileW, meta, sizeof(meta)));
- GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (fileW));
-
- fileR = GNUNET_BIO_read_open (fileName);
- GNUNET_assert (NULL != fileR);
- metaDataR = NULL;
+ struct GNUNET_BIO_WriteHandle *wh;
+ struct GNUNET_BIO_ReadHandle *rh;
+ char *filename = GNUNET_DISK_mktemp ("gnunet_bio");
+ struct GNUNET_CONTAINER_MetaData *mdR = NULL;
+
+ memset (meta, 'b', sizeof (meta));
+ meta[sizeof (meta) - 1] = '\0';
+
+ wh = GNUNET_BIO_write_open_file (filename);
+ GNUNET_assert (NULL != wh);
+ GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_int32 (wh,
+ "test-bigmeta-rw-int32",
+ sizeof (meta)));
+ GNUNET_assert (GNUNET_OK == GNUNET_BIO_write (wh,
+ "test-bigmeta-rw-bytes",
+ meta,
+ sizeof (meta)));
+ GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (wh, NULL));
+
+ rh = GNUNET_BIO_read_open_file (filename);
+ GNUNET_assert (NULL != rh);
GNUNET_assert (GNUNET_SYSERR ==
- GNUNET_BIO_read_meta_data (fileR, "Read meta error",
- &metaDataR));
- msg = NULL;
- GNUNET_BIO_read_close (fileR, &msg);
- GNUNET_free (msg);
- GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (fileName));
- GNUNET_assert (NULL == metaDataR);
- GNUNET_free (fileName);
+ GNUNET_BIO_read_meta_data (rh,
+ "test-bigmeta-rw-metadata",
+ &mdR));
+ GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_read_close (rh, NULL));
+
+ GNUNET_assert (NULL == mdR);
+
+ GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (filename));
+ GNUNET_free (filename);
return 0;
}
static int
-test_directory_r ()
+test_directory_r (void)
{
-#ifdef __linux__
- char *msg;
- char readResult[200];
- struct GNUNET_BIO_ReadHandle *fileR;
-
- fileR = GNUNET_BIO_read_open ("/dev");
- GNUNET_assert (NULL != fileR);
- GNUNET_assert (GNUNET_SYSERR ==
- GNUNET_BIO_read (fileR, "Read error", readResult,
- sizeof(readResult)));
- msg = NULL;
- GNUNET_BIO_read_close (fileR, &msg);
- GNUNET_free (msg);
+#ifdef LINUX
+ struct GNUNET_BIO_ReadHandle *rh;
+ char rString[200];
+
+ rh = GNUNET_BIO_read_open_file ("/dev");
+ GNUNET_assert (NULL != rh);
+ GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_read (rh,
+ "test-directory-r",
+ rString,
+ sizeof (rString)));
+ GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_read_close (rh, NULL));
#endif
return 0;
}
static int
-test_nullfile_rw ()
+test_nullfile_rw (void)
{
- static char fileNameNO[102401];
- struct GNUNET_BIO_WriteHandle *fileWNO;
- struct GNUNET_BIO_ReadHandle *fileRNO;
+ static char filename[102401];
+ struct GNUNET_BIO_WriteHandle *wh;
+ struct GNUNET_BIO_ReadHandle *rh;
- memset (fileNameNO, 'a', sizeof(fileNameNO));
- fileNameNO[sizeof(fileNameNO) - 1] = '\0';
+ memset (filename, 'a', sizeof (filename));
+ filename[sizeof (filename) - 1] = '\0';
- GNUNET_log_skip (1, GNUNET_NO);
- fileWNO = GNUNET_BIO_write_open (fileNameNO);
+ GNUNET_log_skip (2, GNUNET_NO);
+ wh = GNUNET_BIO_write_open_file (filename);
GNUNET_log_skip (0, GNUNET_YES);
- GNUNET_assert (NULL == fileWNO);
+ GNUNET_assert (NULL == wh);
- GNUNET_log_skip (1, GNUNET_NO);
- fileRNO = GNUNET_BIO_read_open (fileNameNO);
+ GNUNET_log_skip (2, GNUNET_NO);
+ rh = GNUNET_BIO_read_open_file (filename);
GNUNET_log_skip (0, GNUNET_YES);
- GNUNET_assert (NULL == fileRNO);
+ GNUNET_assert (NULL == rh);
+
return 0;
}
static int
-test_fullfile_rw ()
+test_fullfile_rw (void)
{
-#ifdef __linux__
- /* /dev/full only seems to exist on Linux */
- char *msg;
- int64_t testNum;
- char *readResultString;
- char readResult[200];
- struct GNUNET_BIO_WriteHandle *fileW;
- struct GNUNET_BIO_ReadHandle *fileR;
- struct GNUNET_CONTAINER_MetaData *metaDataW;
- struct GNUNET_CONTAINER_MetaData *metaDataR;
-
- metaDataW = GNUNET_CONTAINER_meta_data_create ();
- GNUNET_CONTAINER_meta_data_add_publication_date (metaDataW);
-
- fileW = GNUNET_BIO_write_open ("/dev/full");
- GNUNET_assert (NULL != fileW);
- (void) GNUNET_BIO_write (fileW, TESTSTRING, strlen (TESTSTRING));
- (void) GNUNET_BIO_write_string (fileW, TESTSTRING);
- (void) GNUNET_BIO_write_meta_data (fileW, metaDataW);
- GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_write_close (fileW));
- GNUNET_CONTAINER_meta_data_destroy (metaDataW);
-
- fileW = GNUNET_BIO_write_open ("/dev/full");
- GNUNET_assert (NULL != fileW);
- GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_write_close (fileW));
-
- fileR = GNUNET_BIO_read_open ("/dev/null");
- GNUNET_assert (NULL != fileR);
- GNUNET_assert (GNUNET_SYSERR ==
- GNUNET_BIO_read (fileR, "Read error", readResult,
- sizeof(readResult)));
- readResultString = NULL;
- GNUNET_assert (GNUNET_SYSERR ==
- GNUNET_BIO_read_string (fileR, "Read string error",
- &readResultString, 200));
- GNUNET_assert (NULL == readResultString);
- GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_read_int64 (fileR, &testNum));
- metaDataR = NULL;
- GNUNET_assert (GNUNET_SYSERR ==
- GNUNET_BIO_read_meta_data (fileR, "Read meta error",
- &metaDataR));
- msg = NULL;
- GNUNET_BIO_read_close (fileR, &msg);
- GNUNET_free (msg);
- GNUNET_assert (NULL == metaDataR);
+#ifdef LINUX
+ /* /dev/full doesn't exist on every platform */
+ struct GNUNET_BIO_WriteHandle *wh;
+ struct GNUNET_BIO_ReadHandle *rh;
+ char *rString = NULL;
+ char rResult[200];
+ struct GNUNET_CONTAINER_MetaData *mdW;
+ struct GNUNET_CONTAINER_MetaData *mdR = NULL;
+
+ mdW = GNUNET_CONTAINER_meta_data_create ();
+ GNUNET_CONTAINER_meta_data_add_publication_date (mdW);
+
+ struct GNUNET_BIO_WriteSpec ws[] = {
+ GNUNET_BIO_write_spec_object ("test-fullfile-rw-bytes",
+ TESTSTRING,
+ strlen (TESTSTRING)),
+ GNUNET_BIO_write_spec_string ("test-fullfile-rw-string",
+ TESTSTRING),
+ GNUNET_BIO_write_spec_meta_data ("test-fullfile-rw-metadata",
+ mdW),
+ GNUNET_BIO_write_spec_end (),
+ };
+
+ struct GNUNET_BIO_ReadSpec rs[] = {
+ GNUNET_BIO_read_spec_object ("test-fullfile-rw-bytes",
+ rResult,
+ sizeof (rResult)),
+ GNUNET_BIO_read_spec_string ("test-fullfile-rw-string",
+ &rString,
+ 200),
+ GNUNET_BIO_read_spec_meta_data ("test-fullfile-rw-metadata",
+ &mdR),
+ GNUNET_BIO_read_spec_end(),
+ };
+
+ wh = GNUNET_BIO_write_open_file ("/dev/full");
+ GNUNET_assert (NULL != wh);
+ GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_write_spec_commit (wh, ws));
+ GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_write_close (wh, NULL));
+
+ rh = GNUNET_BIO_read_open_file ("/dev/null");
+ GNUNET_assert (NULL != rh);
+ GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_read_spec_commit (rh, rs));
+ GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_read_close (rh, NULL));
+
+ GNUNET_assert (NULL == rString);
+ GNUNET_assert (NULL == mdR);
#endif
return 0;
}
static int
-test_fakestring_rw ()
+test_fakestring_rw (void)
{
- char *msg;
- int32_t tmpInt = 2;
- char *readResult;
- struct GNUNET_BIO_WriteHandle *fileW;
- struct GNUNET_BIO_ReadHandle *fileR;
- char *fileName = GNUNET_DISK_mktemp ("gnunet_bio");
-
- fileW = GNUNET_BIO_write_open (fileName);
- GNUNET_assert (NULL != fileW);
- GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_int32 (fileW, tmpInt));
- GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (fileW));
-
- fileR = GNUNET_BIO_read_open (fileName);
- GNUNET_assert (NULL != fileR);
+ struct GNUNET_BIO_WriteHandle *wh;
+ struct GNUNET_BIO_ReadHandle *rh;
+ char *filename = GNUNET_DISK_mktemp ("gnunet_bio");
+ char *rString = NULL;
+
+ wh = GNUNET_BIO_write_open_file (filename);
+ GNUNET_assert (NULL != wh);
+ GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_int32 (wh,
+ "test-fakestring-rw-int32",
+ 2));
+ GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (wh, NULL));
+
+ rh = GNUNET_BIO_read_open_file (filename);
+ GNUNET_assert (NULL != rh);
GNUNET_assert (GNUNET_SYSERR ==
- GNUNET_BIO_read_string (fileR, "Read string error",
- &readResult, 200));
- msg = NULL;
- GNUNET_BIO_read_close (fileR, &msg);
- GNUNET_free (msg);
- GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (fileName));
- GNUNET_free (fileName);
+ GNUNET_BIO_read_string (rh,
+ "test-fakestring-rw-string",
+ &rString, 200));
+ GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_read_close (rh, NULL));
+
+ GNUNET_assert (NULL == rString);
+
+ GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (filename));
+ GNUNET_free (filename);
return 0;
}
static int
-test_fakemeta_rw ()
+test_fakemeta_rw (void)
{
- char *msg;
- int32_t tmpInt = 2;
- struct GNUNET_BIO_WriteHandle *fileW;
- struct GNUNET_BIO_ReadHandle *fileR;
- char *fileName = GNUNET_DISK_mktemp ("gnunet_bio");
- struct GNUNET_CONTAINER_MetaData *metaDataR;
-
- fileW = GNUNET_BIO_write_open (fileName);
- GNUNET_assert (NULL != fileW);
- GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_int32 (fileW, tmpInt));
- GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (fileW));
-
- fileR = GNUNET_BIO_read_open (fileName);
- GNUNET_assert (NULL != fileR);
- metaDataR = NULL;
+ struct GNUNET_BIO_WriteHandle *wh;
+ struct GNUNET_BIO_ReadHandle *rh;
+ char *filename = GNUNET_DISK_mktemp ("gnunet_bio");
+ struct GNUNET_CONTAINER_MetaData *mdR = NULL;
+
+ wh = GNUNET_BIO_write_open_file (filename);
+ GNUNET_assert (NULL != wh);
+ GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_int32 (wh,
+ "test-fakestring-rw-int32",
+ 2));
+ GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (wh, NULL));
+
+ rh = GNUNET_BIO_read_open_file (filename);
+ GNUNET_assert (NULL != rh);
GNUNET_assert (GNUNET_SYSERR ==
- GNUNET_BIO_read_meta_data (fileR, "Read meta error",
- &metaDataR));
- GNUNET_assert (NULL == metaDataR);
- msg = NULL;
- GNUNET_BIO_read_close (fileR, &msg);
- GNUNET_free (msg);
- GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (fileName));
- GNUNET_free (fileName);
+ GNUNET_BIO_read_meta_data (rh,
+ "test-fakestring-rw-metadata",
+ &mdR));
+ GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_read_close (rh, NULL));
+
+ GNUNET_assert (NULL == mdR);
+
+ GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (filename));
+ GNUNET_free (filename);
return 0;
}
static int
-test_fakebigmeta_rw ()
+test_fakebigmeta_rw (void)
{
- char *msg;
- int32_t tmpInt = 1024 * 1024 * 10;
- struct GNUNET_BIO_WriteHandle *fileW;
- struct GNUNET_BIO_ReadHandle *fileR;
- char *fileName = GNUNET_DISK_mktemp ("gnunet_bio");
- struct GNUNET_CONTAINER_MetaData *metaDataR;
-
- fileW = GNUNET_BIO_write_open (fileName);
- GNUNET_assert (NULL != fileW);
- GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_int32 (fileW, tmpInt));
- GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (fileW));
-
- fileR = GNUNET_BIO_read_open (fileName);
- GNUNET_assert (NULL != fileR);
- metaDataR = NULL;
+ struct GNUNET_BIO_WriteHandle *wh;
+ struct GNUNET_BIO_ReadHandle *rh;
+ char *filename = GNUNET_DISK_mktemp ("gnunet_bio");
+ struct GNUNET_CONTAINER_MetaData *mdR = NULL;
+ int32_t wNum = 1024 * 1024 * 10;
+
+ wh = GNUNET_BIO_write_open_file (filename);
+ GNUNET_assert (NULL != wh);
+ GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_int32 (wh,
+ "test-fakebigmeta-rw-int32",
+ wNum));
+ GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (wh, NULL));
+
+ rh = GNUNET_BIO_read_open_file (filename);
+ GNUNET_assert (NULL != rh);
GNUNET_assert (GNUNET_SYSERR ==
- GNUNET_BIO_read_meta_data (fileR, "Read meta error",
- &metaDataR));
- msg = NULL;
- GNUNET_BIO_read_close (fileR, &msg);
- GNUNET_free (msg);
- GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (fileName));
- GNUNET_assert (NULL == metaDataR);
- GNUNET_free (fileName);
+ GNUNET_BIO_read_meta_data (rh,
+ "test-fakebigmeta-rw-metadata",
+ &mdR));
+ GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_read_close (rh, NULL));
+
+ GNUNET_assert (NULL == mdR);
+
+ GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (filename));
+ GNUNET_free (filename);
return 0;
}
static int
-check_string_rw ()
+check_string_rw (void)
{
GNUNET_assert (0 == test_nullstring_rw ());
GNUNET_assert (0 == test_emptystring_rw ());
@@ -397,7 +440,7 @@ check_string_rw ()
static int
-check_metadata_rw ()
+check_metadata_rw (void)
{
GNUNET_assert (0 == test_fakebigmeta_rw ());
GNUNET_assert (0 == test_fakemeta_rw ());
@@ -407,7 +450,7 @@ check_metadata_rw ()
static int
-check_file_rw ()
+check_file_rw (void)
{
GNUNET_assert (0 == test_normal_rw ());
GNUNET_assert (0 == test_nullfile_rw ());
diff --git a/src/util/test_crypto_ecdsa.c b/src/util/test_crypto_ecdsa.c
index cfa236d6d..7908590a8 100644
--- a/src/util/test_crypto_ecdsa.c
+++ b/src/util/test_crypto_ecdsa.c
@@ -107,6 +107,7 @@ testDeriveSignVerify (void)
struct GNUNET_CRYPTO_EcdsaPrivateKey *dpriv;
struct GNUNET_CRYPTO_EcdsaPublicKey pkey;
struct GNUNET_CRYPTO_EcdsaPublicKey dpub;
+ struct GNUNET_CRYPTO_EcdsaPublicKey dpub2;
dpriv = GNUNET_CRYPTO_ecdsa_private_key_derive (&key,
"test-derive",
@@ -117,9 +118,17 @@ testDeriveSignVerify (void)
"test-derive",
"test-CTX",
&dpub);
+ GNUNET_CRYPTO_ecdsa_key_get_public (dpriv, &dpub2);
purp.size = htonl (sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose));
purp.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TEST);
+ if (0 != GNUNET_memcmp (&dpub.q_y, &dpub2.q_y))
+ {
+ fprintf (stderr, "%s", "key derivation failed\n");
+ GNUNET_free (dpriv);
+ return GNUNET_SYSERR;
+ }
+
if (GNUNET_SYSERR ==
GNUNET_CRYPTO_ecdsa_sign_ (dpriv,
&purp,
diff --git a/src/util/test_crypto_hash.c b/src/util/test_crypto_hash.c
index 12e1324dd..d22e1f5d3 100644
--- a/src/util/test_crypto_hash.c
+++ b/src/util/test_crypto_hash.c
@@ -91,10 +91,15 @@ testArithmetic ()
return 1;
if (1 != GNUNET_CRYPTO_hash_xorcmp (&h1, &h2, &h2))
return 1;
- memset (&d, 0xF0, sizeof(d));
- if (0 != GNUNET_CRYPTO_hash_get_bit (&d, 3))
+ memset (&d, 0x40, sizeof(d));
+ if (0 != GNUNET_CRYPTO_hash_get_bit_rtl (&d, 3))
return 1;
- if (1 != GNUNET_CRYPTO_hash_get_bit (&d, 6))
+ if (1 != GNUNET_CRYPTO_hash_get_bit_rtl (&d, 6))
+ return 1;
+ memset (&d, 0x02, sizeof(d));
+ if (0 != GNUNET_CRYPTO_hash_get_bit_ltr (&d, 3))
+ return 1;
+ if (1 != GNUNET_CRYPTO_hash_get_bit_ltr (&d, 6))
return 1;
memset (&d, 0, sizeof(d));
GNUNET_CRYPTO_hash_to_aes_key (&d, &skey, &iv);