aboutsummaryrefslogtreecommitdiff
path: root/src/gnsrecord
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2018-05-10 01:19:34 +0200
committerChristian Grothoff <christian@grothoff.org>2018-05-10 01:19:34 +0200
commitb3bb9dcb3225fbbd9f04cb8d97f2b876b35104fd (patch)
tree1ed00a65b47197696623f0f4fe3c892b3e47c20f /src/gnsrecord
parente1431b294bf72d436f2e36ea21adea0dc432ab75 (diff)
downloadgnunet-b3bb9dcb3225fbbd9f04cb8d97f2b876b35104fd.tar.gz
gnunet-b3bb9dcb3225fbbd9f04cb8d97f2b876b35104fd.zip
add gnscrypto benchmark
Diffstat (limited to 'src/gnsrecord')
-rw-r--r--src/gnsrecord/.gitignore1
-rw-r--r--src/gnsrecord/Makefile.am10
-rw-r--r--src/gnsrecord/perf_gnsrecord_crypto.c137
-rw-r--r--src/gnsrecord/test_gnsrecord_crypto.c6
4 files changed, 150 insertions, 4 deletions
diff --git a/src/gnsrecord/.gitignore b/src/gnsrecord/.gitignore
index 374abdb60..53d3bb22d 100644
--- a/src/gnsrecord/.gitignore
+++ b/src/gnsrecord/.gitignore
@@ -2,3 +2,4 @@ test_gnsrecord_block_expiration
2test_gnsrecord_crypto 2test_gnsrecord_crypto
3test_gnsrecord_serialization 3test_gnsrecord_serialization
4zonefiles 4zonefiles
5perf_gnsrecord_crypto
diff --git a/src/gnsrecord/Makefile.am b/src/gnsrecord/Makefile.am
index 2fb427c69..c83aa3307 100644
--- a/src/gnsrecord/Makefile.am
+++ b/src/gnsrecord/Makefile.am
@@ -19,7 +19,8 @@ endif
19check_PROGRAMS = \ 19check_PROGRAMS = \
20 test_gnsrecord_crypto \ 20 test_gnsrecord_crypto \
21 test_gnsrecord_serialization \ 21 test_gnsrecord_serialization \
22 test_gnsrecord_block_expiration 22 test_gnsrecord_block_expiration \
23 perf_gnsrecord_crypto
23 24
24if ENABLE_TEST_RUN 25if ENABLE_TEST_RUN
25AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset XDG_CONFIG_HOME; 26AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset XDG_CONFIG_HOME;
@@ -85,3 +86,10 @@ test_gnsrecord_crypto_LDADD = \
85 libgnunetgnsrecord.la \ 86 libgnunetgnsrecord.la \
86 $(top_builddir)/src/util/libgnunetutil.la 87 $(top_builddir)/src/util/libgnunetutil.la
87 88
89
90perf_gnsrecord_crypto_SOURCES = \
91 perf_gnsrecord_crypto.c
92perf_gnsrecord_crypto_LDADD = \
93 $(top_builddir)/src/testing/libgnunettesting.la \
94 libgnunetgnsrecord.la \
95 $(top_builddir)/src/util/libgnunetutil.la
diff --git a/src/gnsrecord/perf_gnsrecord_crypto.c b/src/gnsrecord/perf_gnsrecord_crypto.c
new file mode 100644
index 000000000..ff9721006
--- /dev/null
+++ b/src/gnsrecord/perf_gnsrecord_crypto.c
@@ -0,0 +1,137 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2018 GNUnet e.V.
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/
20/**
21 * @file gnsrecord/test_gnsrecord_crypto.c
22 * @brief testcase for block creation, verification and decryption
23 */
24#include "platform.h"
25#include "gnunet_util_lib.h"
26#include "gnunet_gnsrecord_lib.h"
27
28#define ROUNDS 1000
29
30#define RECORDS 5
31
32#define TEST_RECORD_TYPE 1234
33
34#define TEST_RECORD_DATALEN 123
35
36#define TEST_RECORD_DATA 'a'
37
38#define TEST_REMOVE_RECORD_TYPE 4321
39
40#define TEST_REMOVE_RECORD_DATALEN 255
41
42#define TEST_REMOVE_RECORD_DATA 'b'
43
44
45static struct GNUNET_GNSRECORD_Data *
46create_record (int count)
47{
48 struct GNUNET_GNSRECORD_Data *rd;
49
50 rd = GNUNET_new_array (count,
51 struct GNUNET_GNSRECORD_Data);
52 for (unsigned int c = 0; c < count; c++)
53 {
54 rd[c].expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000;
55 rd[c].record_type = TEST_RECORD_TYPE;
56 rd[c].data_size = TEST_RECORD_DATALEN;
57 rd[c].data = GNUNET_malloc(TEST_RECORD_DATALEN);
58 memset ((char *) rd[c].data, TEST_RECORD_DATA, TEST_RECORD_DATALEN);
59 }
60 return rd;
61}
62
63
64static void
65run (void *cls,
66 char *const *args,
67 const char *cfgfile,
68 const struct GNUNET_CONFIGURATION_Handle *cfg)
69{
70 struct GNUNET_GNSRECORD_Block *block;
71 struct GNUNET_HashCode query;
72 struct GNUNET_GNSRECORD_Data *s_rd;
73 const char *s_name;
74 struct GNUNET_TIME_Absolute start_time;
75 struct GNUNET_CRYPTO_EcdsaPrivateKey * privkey;
76 struct GNUNET_TIME_Absolute expire;
77
78 (void) cls;
79 (void) args;
80 (void) cfgfile;
81 (void) cfg;
82 expire = GNUNET_TIME_absolute_get();
83 privkey = GNUNET_CRYPTO_ecdsa_key_create ();
84 GNUNET_assert (NULL != privkey);
85
86 /* test block creation */
87 s_name = "DUMMY.dummy.gnunet";
88 s_rd = create_record (RECORDS);
89 start_time = GNUNET_TIME_absolute_get ();
90 for (unsigned int i=0;i<ROUNDS;i++)
91 {
92 GNUNET_assert (NULL != (block =
93 GNUNET_GNSRECORD_block_create2 (privkey,
94 expire,
95 s_name,
96 s_rd,
97 RECORDS)));
98 GNUNET_GNSRECORD_query_from_private_key (privkey,
99 s_name,
100 &query);
101 GNUNET_free (block);
102 }
103 fprintf (stderr,
104 "Took %s to produce %u GNS blocks for the DHT\n",
105 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start_time),
106 GNUNET_YES),
107 ROUNDS);
108 for (unsigned int i=0;i<RECORDS;i++)
109 GNUNET_free ((void *) s_rd[i].data);
110 GNUNET_free (s_rd);
111 GNUNET_free (privkey);
112}
113
114
115int
116main (int argc, char *argv[])
117{
118 static char *const argvx[] = {
119 "perf-gnsrecord-crypto",
120 NULL
121 };
122 static struct GNUNET_GETOPT_CommandLineOption options[] = {
123 GNUNET_GETOPT_OPTION_END
124 };
125
126 if (GNUNET_OK !=
127 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
128 argvx,
129 "perf-gnsrecord-crypto",
130 "nohelp", options,
131 &run,
132 NULL))
133 return 1;
134 return 0;
135}
136
137/* end of test_gnsrecord_crypto.c */
diff --git a/src/gnsrecord/test_gnsrecord_crypto.c b/src/gnsrecord/test_gnsrecord_crypto.c
index 1df3f3730..9ba303e66 100644
--- a/src/gnsrecord/test_gnsrecord_crypto.c
+++ b/src/gnsrecord/test_gnsrecord_crypto.c
@@ -54,7 +54,7 @@ create_record (int count)
54{ 54{
55 struct GNUNET_GNSRECORD_Data *rd; 55 struct GNUNET_GNSRECORD_Data *rd;
56 56
57 rd = GNUNET_malloc (count * sizeof (struct GNUNET_GNSRECORD_Data)); 57 rd = GNUNET_new_array (count, struct GNUNET_GNSRECORD_Data);
58 for (unsigned int c = 0; c < count; c++) 58 for (unsigned int c = 0; c < count; c++)
59 { 59 {
60 rd[c].expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000; 60 rd[c].expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000;
@@ -103,11 +103,10 @@ run (void *cls,
103 struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; 103 struct GNUNET_CRYPTO_EcdsaPublicKey pubkey;
104 struct GNUNET_HashCode query_pub; 104 struct GNUNET_HashCode query_pub;
105 struct GNUNET_HashCode query_priv; 105 struct GNUNET_HashCode query_priv;
106 struct GNUNET_TIME_Absolute expire = GNUNET_TIME_absolute_get();
106 107
107 privkey = GNUNET_CRYPTO_ecdsa_key_create (); 108 privkey = GNUNET_CRYPTO_ecdsa_key_create ();
108 GNUNET_assert (NULL != privkey); 109 GNUNET_assert (NULL != privkey);
109 struct GNUNET_TIME_Absolute expire = GNUNET_TIME_absolute_get();
110
111 /* get public key */ 110 /* get public key */
112 GNUNET_CRYPTO_ecdsa_key_get_public (privkey, 111 GNUNET_CRYPTO_ecdsa_key_get_public (privkey,
113 &pubkey); 112 &pubkey);
@@ -142,6 +141,7 @@ run (void *cls,
142 &rd_decrypt_cb, 141 &rd_decrypt_cb,
143 s_name)); 142 s_name));
144 GNUNET_free (block); 143 GNUNET_free (block);
144 GNUNET_free (privkey);
145} 145}
146 146
147 147