diff options
Diffstat (limited to 'src/namestore/test_namestore_api_store_update.c')
-rw-r--r-- | src/namestore/test_namestore_api_store_update.c | 202 |
1 files changed, 106 insertions, 96 deletions
diff --git a/src/namestore/test_namestore_api_store_update.c b/src/namestore/test_namestore_api_store_update.c index 0a4551f21..bd62fdd4c 100644 --- a/src/namestore/test_namestore_api_store_update.c +++ b/src/namestore/test_namestore_api_store_update.c | |||
@@ -1,41 +1,38 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2012, 2013 GNUnet e.V. | 3 | Copyright (C) 2012, 2013, 2018 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | it under the terms of the GNU General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation; either version 3, or (at your | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with GNUnet; see the file COPYING. If not, write to the | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | ||
19 | */ | 17 | */ |
20 | /** | 18 | /** |
21 | * @file namestore/test_namestore_api_store_update.c | 19 | * @file namestore/test_namestore_api_store_update.c |
22 | * @brief testcase for namestore_api.c: store a record, update it and perform a lookup | 20 | * @brief testcase for namestore_api.c: store a record, update it and perform a lookup |
23 | * @author Matthias Wachs | 21 | * @author Matthias Wachs |
22 | * @author Christian Grothoff | ||
24 | */ | 23 | */ |
25 | #include "platform.h" | 24 | #include "platform.h" |
26 | #include "gnunet_namecache_service.h" | 25 | #include "gnunet_namecache_service.h" |
27 | #include "gnunet_namestore_service.h" | 26 | #include "gnunet_namestore_service.h" |
28 | #include "gnunet_testing_lib.h" | 27 | #include "gnunet_testing_lib.h" |
28 | #include "gnunet_dnsparser_lib.h" | ||
29 | 29 | ||
30 | #define TEST_RECORD_TYPE 1234 | 30 | #define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT |
31 | 31 | ||
32 | #define TEST_RECORD_DATALEN 123 | 32 | #define TEST_RECORD_DATALEN 123 |
33 | 33 | ||
34 | #define TEST_RECORD_DATA 'a' | 34 | #define TEST_RECORD_DATA 'a' |
35 | 35 | ||
36 | |||
37 | #define TEST_RECORD_TYPE2 4321 | ||
38 | |||
39 | #define TEST_RECORD_DATALEN2 234 | 36 | #define TEST_RECORD_DATALEN2 234 |
40 | 37 | ||
41 | #define TEST_RECORD_DATA2 'b' | 38 | #define TEST_RECORD_DATA2 'b' |
@@ -63,38 +60,30 @@ static struct GNUNET_NAMECACHE_QueueEntry *ncqe; | |||
63 | 60 | ||
64 | static const char *name = "dummy"; | 61 | static const char *name = "dummy"; |
65 | 62 | ||
66 | static char *directory; | ||
67 | 63 | ||
64 | /** | ||
65 | * Terminate test with error. | ||
66 | * | ||
67 | * @param cls handle to use to re-connect. | ||
68 | */ | ||
68 | static void | 69 | static void |
69 | cleanup () | 70 | endbadly (void *cls) |
70 | { | 71 | { |
71 | if (NULL != nsh) | 72 | GNUNET_break (0); |
72 | { | 73 | endbadly_task = NULL; |
73 | GNUNET_NAMESTORE_disconnect (nsh); | ||
74 | nsh = NULL; | ||
75 | } | ||
76 | if (NULL != nch) | ||
77 | { | ||
78 | GNUNET_NAMECACHE_disconnect (nch); | ||
79 | nch = NULL; | ||
80 | } | ||
81 | if (NULL != privkey) | ||
82 | { | ||
83 | GNUNET_free (privkey); | ||
84 | privkey = NULL; | ||
85 | } | ||
86 | GNUNET_SCHEDULER_shutdown (); | 74 | GNUNET_SCHEDULER_shutdown (); |
75 | res = 1; | ||
87 | } | 76 | } |
88 | 77 | ||
89 | 78 | ||
90 | /** | ||
91 | * Re-establish the connection to the service. | ||
92 | * | ||
93 | * @param cls handle to use to re-connect. | ||
94 | */ | ||
95 | static void | 79 | static void |
96 | endbadly (void *cls) | 80 | end (void *cls) |
97 | { | 81 | { |
82 | if (NULL != endbadly_task) | ||
83 | { | ||
84 | GNUNET_SCHEDULER_cancel (endbadly_task); | ||
85 | endbadly_task = NULL; | ||
86 | } | ||
98 | if (NULL != nsqe) | 87 | if (NULL != nsqe) |
99 | { | 88 | { |
100 | GNUNET_NAMESTORE_cancel (nsqe); | 89 | GNUNET_NAMESTORE_cancel (nsqe); |
@@ -105,21 +94,28 @@ endbadly (void *cls) | |||
105 | GNUNET_NAMECACHE_cancel (ncqe); | 94 | GNUNET_NAMECACHE_cancel (ncqe); |
106 | ncqe = NULL; | 95 | ncqe = NULL; |
107 | } | 96 | } |
108 | cleanup (); | 97 | if (NULL != nsh) |
109 | res = 1; | 98 | { |
110 | } | 99 | GNUNET_NAMESTORE_disconnect (nsh); |
111 | 100 | nsh = NULL; | |
112 | 101 | } | |
113 | static void | 102 | if (NULL != nch) |
114 | end (void *cls) | 103 | { |
115 | { | 104 | GNUNET_NAMECACHE_disconnect (nch); |
116 | cleanup (); | 105 | nch = NULL; |
117 | res = 0; | 106 | } |
107 | if (NULL != privkey) | ||
108 | { | ||
109 | GNUNET_free (privkey); | ||
110 | privkey = NULL; | ||
111 | } | ||
118 | } | 112 | } |
119 | 113 | ||
120 | 114 | ||
121 | static void | 115 | static void |
122 | put_cont (void *cls, int32_t success, const char *emsg); | 116 | put_cont (void *cls, |
117 | int32_t success, | ||
118 | const char *emsg); | ||
123 | 119 | ||
124 | 120 | ||
125 | static void | 121 | static void |
@@ -135,38 +131,51 @@ rd_decrypt_cb (void *cls, | |||
135 | if (GNUNET_NO == update_performed) | 131 | if (GNUNET_NO == update_performed) |
136 | { | 132 | { |
137 | char rd_cmp_data[TEST_RECORD_DATALEN]; | 133 | char rd_cmp_data[TEST_RECORD_DATALEN]; |
138 | memset (rd_cmp_data, TEST_RECORD_DATA, TEST_RECORD_DATALEN); | ||
139 | 134 | ||
135 | memset (rd_cmp_data, | ||
136 | TEST_RECORD_DATA, | ||
137 | TEST_RECORD_DATALEN); | ||
140 | GNUNET_assert (TEST_RECORD_TYPE == rd[0].record_type); | 138 | GNUNET_assert (TEST_RECORD_TYPE == rd[0].record_type); |
141 | GNUNET_assert (TEST_RECORD_DATALEN == rd[0].data_size); | 139 | GNUNET_assert (TEST_RECORD_DATALEN == rd[0].data_size); |
142 | GNUNET_assert (0 == memcmp (&rd_cmp_data, rd[0].data, TEST_RECORD_DATALEN)); | 140 | GNUNET_assert (0 == memcmp (&rd_cmp_data, |
141 | rd[0].data, | ||
142 | TEST_RECORD_DATALEN)); | ||
143 | 143 | ||
144 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 144 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
145 | "Block was decrypted successfully, updating record \n"); | 145 | "Block was decrypted successfully, updating record \n"); |
146 | 146 | ||
147 | rd_new.flags = GNUNET_GNSRECORD_RF_NONE; | 147 | rd_new.flags = GNUNET_GNSRECORD_RF_NONE; |
148 | rd_new.expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000; | 148 | rd_new.expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000; |
149 | rd_new.record_type = TEST_RECORD_TYPE2; | 149 | rd_new.record_type = TEST_RECORD_TYPE; |
150 | rd_new.data_size = TEST_RECORD_DATALEN2; | 150 | rd_new.data_size = TEST_RECORD_DATALEN2; |
151 | rd_new.data = GNUNET_malloc (TEST_RECORD_DATALEN2); | 151 | rd_new.data = GNUNET_malloc (TEST_RECORD_DATALEN2); |
152 | memset ((char *) rd_new.data, TEST_RECORD_DATA2, TEST_RECORD_DATALEN2); | 152 | memset ((char *) rd_new.data, |
153 | TEST_RECORD_DATA2, | ||
154 | TEST_RECORD_DATALEN2); | ||
153 | 155 | ||
154 | nsqe = GNUNET_NAMESTORE_records_store (nsh, privkey, name, | 156 | nsqe = GNUNET_NAMESTORE_records_store (nsh, |
155 | 1, &rd_new, &put_cont, (void *) name); | 157 | privkey, |
158 | name, | ||
159 | 1, | ||
160 | &rd_new, | ||
161 | &put_cont, | ||
162 | (void *) name); | ||
156 | update_performed = GNUNET_YES; | 163 | update_performed = GNUNET_YES; |
157 | } | 164 | } |
158 | else | 165 | else |
159 | { | 166 | { |
160 | char rd_cmp_data[TEST_RECORD_DATALEN2]; | 167 | char rd_cmp_data[TEST_RECORD_DATALEN2]; |
161 | memset (rd_cmp_data, TEST_RECORD_DATA2, TEST_RECORD_DATALEN2); | ||
162 | 168 | ||
163 | GNUNET_assert (TEST_RECORD_TYPE2 == rd[0].record_type); | 169 | memset (rd_cmp_data, |
170 | TEST_RECORD_DATA2, | ||
171 | TEST_RECORD_DATALEN2); | ||
172 | GNUNET_assert (TEST_RECORD_TYPE == rd[0].record_type); | ||
164 | GNUNET_assert (TEST_RECORD_DATALEN2 == rd[0].data_size); | 173 | GNUNET_assert (TEST_RECORD_DATALEN2 == rd[0].data_size); |
165 | GNUNET_assert (0 == memcmp (&rd_cmp_data, rd[0].data, TEST_RECORD_DATALEN2)); | 174 | GNUNET_assert (0 == memcmp (&rd_cmp_data, |
166 | 175 | rd[0].data, | |
167 | GNUNET_SCHEDULER_cancel (endbadly_task); | 176 | TEST_RECORD_DATALEN2)); |
168 | endbadly_task = NULL; | 177 | GNUNET_SCHEDULER_shutdown (); |
169 | GNUNET_SCHEDULER_add_now (&end, NULL); | 178 | res = 0; |
170 | } | 179 | } |
171 | } | 180 | } |
172 | 181 | ||
@@ -184,21 +193,25 @@ name_lookup_proc (void *cls, | |||
184 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 193 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
185 | _("Namecache returned no block for `%s'\n"), | 194 | _("Namecache returned no block for `%s'\n"), |
186 | name); | 195 | name); |
187 | if (endbadly_task != NULL) | 196 | GNUNET_SCHEDULER_shutdown (); |
188 | GNUNET_SCHEDULER_cancel (endbadly_task); | ||
189 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); | ||
190 | return; | 197 | return; |
191 | } | 198 | } |
192 | 199 | ||
193 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 200 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
194 | "Namecache returned block, decrypting \n"); | 201 | "Namecache returned block, decrypting \n"); |
195 | GNUNET_assert (GNUNET_OK == GNUNET_GNSRECORD_block_decrypt(block, | 202 | GNUNET_assert (GNUNET_OK == |
196 | &pubkey, name, &rd_decrypt_cb, (void *) name)); | 203 | GNUNET_GNSRECORD_block_decrypt (block, |
204 | &pubkey, | ||
205 | name, | ||
206 | &rd_decrypt_cb, | ||
207 | (void *) name)); | ||
197 | } | 208 | } |
198 | 209 | ||
199 | 210 | ||
200 | static void | 211 | static void |
201 | put_cont (void *cls, int32_t success, const char *emsg) | 212 | put_cont (void *cls, |
213 | int32_t success, | ||
214 | const char *emsg) | ||
202 | { | 215 | { |
203 | const char *name = cls; | 216 | const char *name = cls; |
204 | struct GNUNET_HashCode derived_hash; | 217 | struct GNUNET_HashCode derived_hash; |
@@ -216,7 +229,8 @@ put_cont (void *cls, int32_t success, const char *emsg) | |||
216 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 229 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
217 | "Looking in namecache for `%s'\n", | 230 | "Looking in namecache for `%s'\n", |
218 | GNUNET_h2s (&derived_hash)); | 231 | GNUNET_h2s (&derived_hash)); |
219 | ncqe = GNUNET_NAMECACHE_lookup_block (nch, &derived_hash, | 232 | ncqe = GNUNET_NAMECACHE_lookup_block (nch, |
233 | &derived_hash, | ||
220 | &name_lookup_proc, (void *) name); | 234 | &name_lookup_proc, (void *) name); |
221 | } | 235 | } |
222 | 236 | ||
@@ -227,41 +241,37 @@ run (void *cls, | |||
227 | struct GNUNET_TESTING_Peer *peer) | 241 | struct GNUNET_TESTING_Peer *peer) |
228 | { | 242 | { |
229 | struct GNUNET_GNSRECORD_Data rd; | 243 | struct GNUNET_GNSRECORD_Data rd; |
230 | char *hostkey_file; | ||
231 | |||
232 | directory = NULL; | ||
233 | GNUNET_assert (GNUNET_OK == | ||
234 | GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS", "GNUNET_TEST_HOME", &directory)); | ||
235 | GNUNET_DISK_directory_remove (directory); | ||
236 | 244 | ||
237 | update_performed = GNUNET_NO; | 245 | update_performed = GNUNET_NO; |
246 | GNUNET_SCHEDULER_add_shutdown (&end, | ||
247 | NULL); | ||
238 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 248 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
239 | &endbadly, NULL); | 249 | &endbadly, |
240 | GNUNET_asprintf (&hostkey_file, | 250 | NULL); |
241 | "zonefiles%s%s", | 251 | privkey = GNUNET_CRYPTO_ecdsa_key_create (); |
242 | DIR_SEPARATOR_STR, | ||
243 | "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey"); | ||
244 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file); | ||
245 | privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file); | ||
246 | GNUNET_free (hostkey_file); | ||
247 | GNUNET_assert (privkey != NULL); | 252 | GNUNET_assert (privkey != NULL); |
248 | GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey); | 253 | GNUNET_CRYPTO_ecdsa_key_get_public (privkey, |
249 | 254 | &pubkey); | |
250 | rd.flags = GNUNET_GNSRECORD_RF_NONE; | 255 | rd.flags = GNUNET_GNSRECORD_RF_NONE; |
251 | rd.expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000; | 256 | rd.expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000; |
252 | rd.record_type = TEST_RECORD_TYPE; | 257 | rd.record_type = TEST_RECORD_TYPE; |
253 | rd.data_size = TEST_RECORD_DATALEN; | 258 | rd.data_size = TEST_RECORD_DATALEN; |
254 | rd.data = GNUNET_malloc (TEST_RECORD_DATALEN); | 259 | rd.data = GNUNET_malloc (TEST_RECORD_DATALEN); |
255 | memset ((char *) rd.data, TEST_RECORD_DATA, TEST_RECORD_DATALEN); | 260 | memset ((char *) rd.data, |
261 | TEST_RECORD_DATA, | ||
262 | TEST_RECORD_DATALEN); | ||
256 | 263 | ||
257 | nsh = GNUNET_NAMESTORE_connect (cfg); | 264 | nsh = GNUNET_NAMESTORE_connect (cfg); |
258 | GNUNET_break (NULL != nsh); | 265 | GNUNET_break (NULL != nsh); |
259 | nch = GNUNET_NAMECACHE_connect (cfg); | 266 | nch = GNUNET_NAMECACHE_connect (cfg); |
260 | GNUNET_break (NULL != nch); | 267 | GNUNET_break (NULL != nch); |
261 | nsqe = GNUNET_NAMESTORE_records_store (nsh, | 268 | nsqe = GNUNET_NAMESTORE_records_store (nsh, |
262 | privkey, name, | 269 | privkey, |
263 | 1, &rd, | 270 | name, |
264 | &put_cont, (void *) name); | 271 | 1, |
272 | &rd, | ||
273 | &put_cont, | ||
274 | (void *) name); | ||
265 | if (NULL == nsqe) | 275 | if (NULL == nsqe) |
266 | { | 276 | { |
267 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 277 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
@@ -272,7 +282,8 @@ run (void *cls, | |||
272 | 282 | ||
273 | 283 | ||
274 | int | 284 | int |
275 | main (int argc, char *argv[]) | 285 | main (int argc, |
286 | char *argv[]) | ||
276 | { | 287 | { |
277 | const char *plugin_name; | 288 | const char *plugin_name; |
278 | char *cfg_name; | 289 | char *cfg_name; |
@@ -282,6 +293,8 @@ main (int argc, char *argv[]) | |||
282 | "test_namestore_api_%s.conf", | 293 | "test_namestore_api_%s.conf", |
283 | plugin_name); | 294 | plugin_name); |
284 | res = 1; | 295 | res = 1; |
296 | GNUNET_DISK_purge_cfg_dir (cfg_name, | ||
297 | "GNUNET_TEST_HOME"); | ||
285 | if (0 != | 298 | if (0 != |
286 | GNUNET_TESTING_peer_run ("test-namestore-api-store-update", | 299 | GNUNET_TESTING_peer_run ("test-namestore-api-store-update", |
287 | cfg_name, | 300 | cfg_name, |
@@ -290,14 +303,11 @@ main (int argc, char *argv[]) | |||
290 | { | 303 | { |
291 | res = 1; | 304 | res = 1; |
292 | } | 305 | } |
306 | GNUNET_DISK_purge_cfg_dir (cfg_name, | ||
307 | "GNUNET_TEST_HOME"); | ||
293 | GNUNET_free (cfg_name); | 308 | GNUNET_free (cfg_name); |
294 | if (NULL != directory) | ||
295 | { | ||
296 | GNUNET_DISK_directory_remove (directory); | ||
297 | GNUNET_free (directory); | ||
298 | } | ||
299 | return res; | 309 | return res; |
300 | } | 310 | } |
301 | 311 | ||
302 | 312 | ||
303 | /* end of test_namestore_api_store_update.c*/ | 313 | /* end of test_namestore_api_store_update.c */ |