diff options
author | Christian Grothoff <christian@grothoff.org> | 2018-05-09 17:33:04 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2018-05-09 17:33:04 +0200 |
commit | 8bb475af99260f1d107dbc8908268ae93960aa83 (patch) | |
tree | 1a7a1fc03424df841a6f977b137482439b09bc9f /src/namestore/test_namestore_api_store_update.c | |
parent | 1f80a11e90ee982bffaae4685e281f75ee1c225d (diff) | |
download | gnunet-8bb475af99260f1d107dbc8908268ae93960aa83.tar.gz gnunet-8bb475af99260f1d107dbc8908268ae93960aa83.zip |
implement new functions in libgnunetsq, clean up sqlite namestore plugin, implement flow control in namestore API and tests
Diffstat (limited to 'src/namestore/test_namestore_api_store_update.c')
-rw-r--r-- | src/namestore/test_namestore_api_store_update.c | 175 |
1 files changed, 94 insertions, 81 deletions
diff --git a/src/namestore/test_namestore_api_store_update.c b/src/namestore/test_namestore_api_store_update.c index 0a4551f21..7b13cd9c5 100644 --- a/src/namestore/test_namestore_api_store_update.c +++ b/src/namestore/test_namestore_api_store_update.c | |||
@@ -1,6 +1,6 @@ | |||
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 |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -21,6 +21,7 @@ | |||
21 | * @file namestore/test_namestore_api_store_update.c | 21 | * @file namestore/test_namestore_api_store_update.c |
22 | * @brief testcase for namestore_api.c: store a record, update it and perform a lookup | 22 | * @brief testcase for namestore_api.c: store a record, update it and perform a lookup |
23 | * @author Matthias Wachs | 23 | * @author Matthias Wachs |
24 | * @author Christian Grothoff | ||
24 | */ | 25 | */ |
25 | #include "platform.h" | 26 | #include "platform.h" |
26 | #include "gnunet_namecache_service.h" | 27 | #include "gnunet_namecache_service.h" |
@@ -33,7 +34,6 @@ | |||
33 | 34 | ||
34 | #define TEST_RECORD_DATA 'a' | 35 | #define TEST_RECORD_DATA 'a' |
35 | 36 | ||
36 | |||
37 | #define TEST_RECORD_TYPE2 4321 | 37 | #define TEST_RECORD_TYPE2 4321 |
38 | 38 | ||
39 | #define TEST_RECORD_DATALEN2 234 | 39 | #define TEST_RECORD_DATALEN2 234 |
@@ -63,38 +63,30 @@ static struct GNUNET_NAMECACHE_QueueEntry *ncqe; | |||
63 | 63 | ||
64 | static const char *name = "dummy"; | 64 | static const char *name = "dummy"; |
65 | 65 | ||
66 | static char *directory; | ||
67 | 66 | ||
67 | /** | ||
68 | * Terminate test with error. | ||
69 | * | ||
70 | * @param cls handle to use to re-connect. | ||
71 | */ | ||
68 | static void | 72 | static void |
69 | cleanup () | 73 | endbadly (void *cls) |
70 | { | 74 | { |
71 | if (NULL != nsh) | 75 | GNUNET_break (0); |
72 | { | 76 | 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 (); | 77 | GNUNET_SCHEDULER_shutdown (); |
78 | res = 1; | ||
87 | } | 79 | } |
88 | 80 | ||
89 | 81 | ||
90 | /** | ||
91 | * Re-establish the connection to the service. | ||
92 | * | ||
93 | * @param cls handle to use to re-connect. | ||
94 | */ | ||
95 | static void | 82 | static void |
96 | endbadly (void *cls) | 83 | end (void *cls) |
97 | { | 84 | { |
85 | if (NULL != endbadly_task) | ||
86 | { | ||
87 | GNUNET_SCHEDULER_cancel (endbadly_task); | ||
88 | endbadly_task = NULL; | ||
89 | } | ||
98 | if (NULL != nsqe) | 90 | if (NULL != nsqe) |
99 | { | 91 | { |
100 | GNUNET_NAMESTORE_cancel (nsqe); | 92 | GNUNET_NAMESTORE_cancel (nsqe); |
@@ -105,21 +97,28 @@ endbadly (void *cls) | |||
105 | GNUNET_NAMECACHE_cancel (ncqe); | 97 | GNUNET_NAMECACHE_cancel (ncqe); |
106 | ncqe = NULL; | 98 | ncqe = NULL; |
107 | } | 99 | } |
108 | cleanup (); | 100 | if (NULL != nsh) |
109 | res = 1; | 101 | { |
110 | } | 102 | GNUNET_NAMESTORE_disconnect (nsh); |
111 | 103 | nsh = NULL; | |
112 | 104 | } | |
113 | static void | 105 | if (NULL != nch) |
114 | end (void *cls) | 106 | { |
115 | { | 107 | GNUNET_NAMECACHE_disconnect (nch); |
116 | cleanup (); | 108 | nch = NULL; |
117 | res = 0; | 109 | } |
110 | if (NULL != privkey) | ||
111 | { | ||
112 | GNUNET_free (privkey); | ||
113 | privkey = NULL; | ||
114 | } | ||
118 | } | 115 | } |
119 | 116 | ||
120 | 117 | ||
121 | static void | 118 | static void |
122 | put_cont (void *cls, int32_t success, const char *emsg); | 119 | put_cont (void *cls, |
120 | int32_t success, | ||
121 | const char *emsg); | ||
123 | 122 | ||
124 | 123 | ||
125 | static void | 124 | static void |
@@ -135,11 +134,15 @@ rd_decrypt_cb (void *cls, | |||
135 | if (GNUNET_NO == update_performed) | 134 | if (GNUNET_NO == update_performed) |
136 | { | 135 | { |
137 | char rd_cmp_data[TEST_RECORD_DATALEN]; | 136 | char rd_cmp_data[TEST_RECORD_DATALEN]; |
138 | memset (rd_cmp_data, TEST_RECORD_DATA, TEST_RECORD_DATALEN); | ||
139 | 137 | ||
138 | memset (rd_cmp_data, | ||
139 | TEST_RECORD_DATA, | ||
140 | TEST_RECORD_DATALEN); | ||
140 | GNUNET_assert (TEST_RECORD_TYPE == rd[0].record_type); | 141 | GNUNET_assert (TEST_RECORD_TYPE == rd[0].record_type); |
141 | GNUNET_assert (TEST_RECORD_DATALEN == rd[0].data_size); | 142 | GNUNET_assert (TEST_RECORD_DATALEN == rd[0].data_size); |
142 | GNUNET_assert (0 == memcmp (&rd_cmp_data, rd[0].data, TEST_RECORD_DATALEN)); | 143 | GNUNET_assert (0 == memcmp (&rd_cmp_data, |
144 | rd[0].data, | ||
145 | TEST_RECORD_DATALEN)); | ||
143 | 146 | ||
144 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 147 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
145 | "Block was decrypted successfully, updating record \n"); | 148 | "Block was decrypted successfully, updating record \n"); |
@@ -149,24 +152,33 @@ rd_decrypt_cb (void *cls, | |||
149 | rd_new.record_type = TEST_RECORD_TYPE2; | 152 | rd_new.record_type = TEST_RECORD_TYPE2; |
150 | rd_new.data_size = TEST_RECORD_DATALEN2; | 153 | rd_new.data_size = TEST_RECORD_DATALEN2; |
151 | rd_new.data = GNUNET_malloc (TEST_RECORD_DATALEN2); | 154 | rd_new.data = GNUNET_malloc (TEST_RECORD_DATALEN2); |
152 | memset ((char *) rd_new.data, TEST_RECORD_DATA2, TEST_RECORD_DATALEN2); | 155 | memset ((char *) rd_new.data, |
156 | TEST_RECORD_DATA2, | ||
157 | TEST_RECORD_DATALEN2); | ||
153 | 158 | ||
154 | nsqe = GNUNET_NAMESTORE_records_store (nsh, privkey, name, | 159 | nsqe = GNUNET_NAMESTORE_records_store (nsh, |
155 | 1, &rd_new, &put_cont, (void *) name); | 160 | privkey, |
161 | name, | ||
162 | 1, | ||
163 | &rd_new, | ||
164 | &put_cont, | ||
165 | (void *) name); | ||
156 | update_performed = GNUNET_YES; | 166 | update_performed = GNUNET_YES; |
157 | } | 167 | } |
158 | else | 168 | else |
159 | { | 169 | { |
160 | char rd_cmp_data[TEST_RECORD_DATALEN2]; | 170 | char rd_cmp_data[TEST_RECORD_DATALEN2]; |
161 | memset (rd_cmp_data, TEST_RECORD_DATA2, TEST_RECORD_DATALEN2); | ||
162 | 171 | ||
172 | memset (rd_cmp_data, | ||
173 | TEST_RECORD_DATA2, | ||
174 | TEST_RECORD_DATALEN2); | ||
163 | GNUNET_assert (TEST_RECORD_TYPE2 == rd[0].record_type); | 175 | GNUNET_assert (TEST_RECORD_TYPE2 == rd[0].record_type); |
164 | GNUNET_assert (TEST_RECORD_DATALEN2 == rd[0].data_size); | 176 | GNUNET_assert (TEST_RECORD_DATALEN2 == rd[0].data_size); |
165 | GNUNET_assert (0 == memcmp (&rd_cmp_data, rd[0].data, TEST_RECORD_DATALEN2)); | 177 | GNUNET_assert (0 == memcmp (&rd_cmp_data, |
166 | 178 | rd[0].data, | |
167 | GNUNET_SCHEDULER_cancel (endbadly_task); | 179 | TEST_RECORD_DATALEN2)); |
168 | endbadly_task = NULL; | 180 | GNUNET_SCHEDULER_shutdown (); |
169 | GNUNET_SCHEDULER_add_now (&end, NULL); | 181 | res = 0; |
170 | } | 182 | } |
171 | } | 183 | } |
172 | 184 | ||
@@ -184,21 +196,25 @@ name_lookup_proc (void *cls, | |||
184 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 196 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
185 | _("Namecache returned no block for `%s'\n"), | 197 | _("Namecache returned no block for `%s'\n"), |
186 | name); | 198 | name); |
187 | if (endbadly_task != NULL) | 199 | GNUNET_SCHEDULER_shutdown (); |
188 | GNUNET_SCHEDULER_cancel (endbadly_task); | ||
189 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); | ||
190 | return; | 200 | return; |
191 | } | 201 | } |
192 | 202 | ||
193 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 203 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
194 | "Namecache returned block, decrypting \n"); | 204 | "Namecache returned block, decrypting \n"); |
195 | GNUNET_assert (GNUNET_OK == GNUNET_GNSRECORD_block_decrypt(block, | 205 | GNUNET_assert (GNUNET_OK == |
196 | &pubkey, name, &rd_decrypt_cb, (void *) name)); | 206 | GNUNET_GNSRECORD_block_decrypt (block, |
207 | &pubkey, | ||
208 | name, | ||
209 | &rd_decrypt_cb, | ||
210 | (void *) name)); | ||
197 | } | 211 | } |
198 | 212 | ||
199 | 213 | ||
200 | static void | 214 | static void |
201 | put_cont (void *cls, int32_t success, const char *emsg) | 215 | put_cont (void *cls, |
216 | int32_t success, | ||
217 | const char *emsg) | ||
202 | { | 218 | { |
203 | const char *name = cls; | 219 | const char *name = cls; |
204 | struct GNUNET_HashCode derived_hash; | 220 | struct GNUNET_HashCode derived_hash; |
@@ -216,7 +232,8 @@ put_cont (void *cls, int32_t success, const char *emsg) | |||
216 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 232 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
217 | "Looking in namecache for `%s'\n", | 233 | "Looking in namecache for `%s'\n", |
218 | GNUNET_h2s (&derived_hash)); | 234 | GNUNET_h2s (&derived_hash)); |
219 | ncqe = GNUNET_NAMECACHE_lookup_block (nch, &derived_hash, | 235 | ncqe = GNUNET_NAMECACHE_lookup_block (nch, |
236 | &derived_hash, | ||
220 | &name_lookup_proc, (void *) name); | 237 | &name_lookup_proc, (void *) name); |
221 | } | 238 | } |
222 | 239 | ||
@@ -227,41 +244,37 @@ run (void *cls, | |||
227 | struct GNUNET_TESTING_Peer *peer) | 244 | struct GNUNET_TESTING_Peer *peer) |
228 | { | 245 | { |
229 | struct GNUNET_GNSRECORD_Data rd; | 246 | 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 | 247 | ||
237 | update_performed = GNUNET_NO; | 248 | update_performed = GNUNET_NO; |
249 | GNUNET_SCHEDULER_add_shutdown (&end, | ||
250 | NULL); | ||
238 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 251 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
239 | &endbadly, NULL); | 252 | &endbadly, |
240 | GNUNET_asprintf (&hostkey_file, | 253 | NULL); |
241 | "zonefiles%s%s", | 254 | 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); | 255 | GNUNET_assert (privkey != NULL); |
248 | GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey); | 256 | GNUNET_CRYPTO_ecdsa_key_get_public (privkey, |
249 | 257 | &pubkey); | |
250 | rd.flags = GNUNET_GNSRECORD_RF_NONE; | 258 | rd.flags = GNUNET_GNSRECORD_RF_NONE; |
251 | rd.expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000; | 259 | rd.expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000; |
252 | rd.record_type = TEST_RECORD_TYPE; | 260 | rd.record_type = TEST_RECORD_TYPE; |
253 | rd.data_size = TEST_RECORD_DATALEN; | 261 | rd.data_size = TEST_RECORD_DATALEN; |
254 | rd.data = GNUNET_malloc (TEST_RECORD_DATALEN); | 262 | rd.data = GNUNET_malloc (TEST_RECORD_DATALEN); |
255 | memset ((char *) rd.data, TEST_RECORD_DATA, TEST_RECORD_DATALEN); | 263 | memset ((char *) rd.data, |
264 | TEST_RECORD_DATA, | ||
265 | TEST_RECORD_DATALEN); | ||
256 | 266 | ||
257 | nsh = GNUNET_NAMESTORE_connect (cfg); | 267 | nsh = GNUNET_NAMESTORE_connect (cfg); |
258 | GNUNET_break (NULL != nsh); | 268 | GNUNET_break (NULL != nsh); |
259 | nch = GNUNET_NAMECACHE_connect (cfg); | 269 | nch = GNUNET_NAMECACHE_connect (cfg); |
260 | GNUNET_break (NULL != nch); | 270 | GNUNET_break (NULL != nch); |
261 | nsqe = GNUNET_NAMESTORE_records_store (nsh, | 271 | nsqe = GNUNET_NAMESTORE_records_store (nsh, |
262 | privkey, name, | 272 | privkey, |
263 | 1, &rd, | 273 | name, |
264 | &put_cont, (void *) name); | 274 | 1, |
275 | &rd, | ||
276 | &put_cont, | ||
277 | (void *) name); | ||
265 | if (NULL == nsqe) | 278 | if (NULL == nsqe) |
266 | { | 279 | { |
267 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 280 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
@@ -272,7 +285,8 @@ run (void *cls, | |||
272 | 285 | ||
273 | 286 | ||
274 | int | 287 | int |
275 | main (int argc, char *argv[]) | 288 | main (int argc, |
289 | char *argv[]) | ||
276 | { | 290 | { |
277 | const char *plugin_name; | 291 | const char *plugin_name; |
278 | char *cfg_name; | 292 | char *cfg_name; |
@@ -282,6 +296,8 @@ main (int argc, char *argv[]) | |||
282 | "test_namestore_api_%s.conf", | 296 | "test_namestore_api_%s.conf", |
283 | plugin_name); | 297 | plugin_name); |
284 | res = 1; | 298 | res = 1; |
299 | GNUNET_DISK_purge_cfg_dir (cfg_name, | ||
300 | "GNUNET_TEST_HOME"); | ||
285 | if (0 != | 301 | if (0 != |
286 | GNUNET_TESTING_peer_run ("test-namestore-api-store-update", | 302 | GNUNET_TESTING_peer_run ("test-namestore-api-store-update", |
287 | cfg_name, | 303 | cfg_name, |
@@ -290,14 +306,11 @@ main (int argc, char *argv[]) | |||
290 | { | 306 | { |
291 | res = 1; | 307 | res = 1; |
292 | } | 308 | } |
309 | GNUNET_DISK_purge_cfg_dir (cfg_name, | ||
310 | "GNUNET_TEST_HOME"); | ||
293 | GNUNET_free (cfg_name); | 311 | GNUNET_free (cfg_name); |
294 | if (NULL != directory) | ||
295 | { | ||
296 | GNUNET_DISK_directory_remove (directory); | ||
297 | GNUNET_free (directory); | ||
298 | } | ||
299 | return res; | 312 | return res; |
300 | } | 313 | } |
301 | 314 | ||
302 | 315 | ||
303 | /* end of test_namestore_api_store_update.c*/ | 316 | /* end of test_namestore_api_store_update.c */ |