diff options
Diffstat (limited to 'src/lib/gnsrecord/perf_gnsrecord_crypto.c')
-rw-r--r-- | src/lib/gnsrecord/perf_gnsrecord_crypto.c | 139 |
1 files changed, 139 insertions, 0 deletions
diff --git a/src/lib/gnsrecord/perf_gnsrecord_crypto.c b/src/lib/gnsrecord/perf_gnsrecord_crypto.c new file mode 100644 index 000000000..1f9a3d4d4 --- /dev/null +++ b/src/lib/gnsrecord/perf_gnsrecord_crypto.c | |||
@@ -0,0 +1,139 @@ | |||
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 it | ||
6 | under the terms of the GNU Affero General Public License as published | ||
7 | by the Free Software Foundation, either version 3 of the License, | ||
8 | or (at your 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 | Affero General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Affero General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
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 | |||
45 | static struct GNUNET_GNSRECORD_Data * | ||
46 | create_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 | ||
55 | + 1000000000; | ||
56 | rd[c].record_type = TEST_RECORD_TYPE; | ||
57 | rd[c].data_size = TEST_RECORD_DATALEN; | ||
58 | rd[c].data = GNUNET_malloc (TEST_RECORD_DATALEN); | ||
59 | memset ((char *) rd[c].data, TEST_RECORD_DATA, TEST_RECORD_DATALEN); | ||
60 | } | ||
61 | return rd; | ||
62 | } | ||
63 | |||
64 | |||
65 | static void | ||
66 | run (void *cls, | ||
67 | char *const *args, | ||
68 | const char *cfgfile, | ||
69 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
70 | { | ||
71 | struct GNUNET_GNSRECORD_Block *block; | ||
72 | struct GNUNET_HashCode query; | ||
73 | struct GNUNET_GNSRECORD_Data *s_rd; | ||
74 | const char *s_name; | ||
75 | struct GNUNET_TIME_Absolute start_time; | ||
76 | struct GNUNET_CRYPTO_PrivateKey privkey; | ||
77 | struct GNUNET_TIME_Absolute expire; | ||
78 | |||
79 | (void) cls; | ||
80 | (void) args; | ||
81 | (void) cfgfile; | ||
82 | (void) cfg; | ||
83 | expire = GNUNET_TIME_absolute_get (); | ||
84 | privkey.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); | ||
85 | GNUNET_CRYPTO_ecdsa_key_create (&privkey.ecdsa_key); | ||
86 | |||
87 | /* test block creation */ | ||
88 | s_name = "DUMMY.dummy.gnunet"; | ||
89 | s_rd = create_record (RECORDS); | ||
90 | start_time = GNUNET_TIME_absolute_get (); | ||
91 | for (unsigned int i = 0; i < ROUNDS; i++) | ||
92 | { | ||
93 | GNUNET_assert (GNUNET_OK == GNUNET_GNSRECORD_block_create2 (&privkey, | ||
94 | expire, | ||
95 | s_name, | ||
96 | s_rd, | ||
97 | RECORDS, | ||
98 | &block)); | ||
99 | GNUNET_GNSRECORD_query_from_private_key (&privkey, | ||
100 | s_name, | ||
101 | &query); | ||
102 | GNUNET_free (block); | ||
103 | } | ||
104 | fprintf (stderr, | ||
105 | "Took %s to produce %u GNS blocks for the DHT\n", | ||
106 | GNUNET_STRINGS_relative_time_to_string ( | ||
107 | GNUNET_TIME_absolute_get_duration (start_time), | ||
108 | GNUNET_YES), | ||
109 | ROUNDS); | ||
110 | for (unsigned int i = 0; i < RECORDS; i++) | ||
111 | GNUNET_free_nz ((void *) s_rd[i].data); | ||
112 | GNUNET_free (s_rd); | ||
113 | } | ||
114 | |||
115 | |||
116 | int | ||
117 | main (int argc, char *argv[]) | ||
118 | { | ||
119 | static char *const argvx[] = { | ||
120 | "perf-gnsrecord-crypto", | ||
121 | NULL | ||
122 | }; | ||
123 | static struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
124 | GNUNET_GETOPT_OPTION_END | ||
125 | }; | ||
126 | |||
127 | if (GNUNET_OK != | ||
128 | GNUNET_PROGRAM_run ((sizeof(argvx) / sizeof(char *)) - 1, | ||
129 | argvx, | ||
130 | "perf-gnsrecord-crypto", | ||
131 | "nohelp", options, | ||
132 | &run, | ||
133 | NULL)) | ||
134 | return 1; | ||
135 | return 0; | ||
136 | } | ||
137 | |||
138 | |||
139 | /* end of test_gnsrecord_crypto.c */ | ||