aboutsummaryrefslogtreecommitdiff
path: root/src/namestore/test_namestore_api_monitoring.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2013-09-11 09:51:14 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2013-09-11 09:51:14 +0000
commite76ee72ca139e341a5126b08de0c80f4ad514bfc (patch)
tree7855f43bec2a7452c0d986baa162743c6f34b93d /src/namestore/test_namestore_api_monitoring.c
parentbe8c744b473a17f245aa377161860e236b581c83 (diff)
downloadgnunet-e76ee72ca139e341a5126b08de0c80f4ad514bfc.tar.gz
gnunet-e76ee72ca139e341a5126b08de0c80f4ad514bfc.zip
updated tests
Diffstat (limited to 'src/namestore/test_namestore_api_monitoring.c')
-rw-r--r--src/namestore/test_namestore_api_monitoring.c178
1 files changed, 99 insertions, 79 deletions
diff --git a/src/namestore/test_namestore_api_monitoring.c b/src/namestore/test_namestore_api_monitoring.c
index 3f1224151..79474e67e 100644
--- a/src/namestore/test_namestore_api_monitoring.c
+++ b/src/namestore/test_namestore_api_monitoring.c
@@ -19,7 +19,7 @@
19*/ 19*/
20/** 20/**
21 * @file namestore/test_namestore_api_monitoring.c 21 * @file namestore/test_namestore_api_monitoring.c
22 * @brief testcase for zone iteration functionality: iterate of a specific zone 22 * @brief testcase for zone monitoring functionality: monitor first, then add records
23 */ 23 */
24#include "platform.h" 24#include "platform.h"
25#include "gnunet_common.h" 25#include "gnunet_common.h"
@@ -35,66 +35,60 @@ static struct GNUNET_NAMESTORE_Handle * nsh;
35 35
36static GNUNET_SCHEDULER_TaskIdentifier endbadly_task; 36static GNUNET_SCHEDULER_TaskIdentifier endbadly_task;
37 37
38static GNUNET_SCHEDULER_TaskIdentifier stopiteration_task;
39
40static struct GNUNET_CRYPTO_EccPrivateKey * privkey; 38static struct GNUNET_CRYPTO_EccPrivateKey * privkey;
41 39
42static struct GNUNET_CRYPTO_EccPublicKey pubkey;
43
44static struct GNUNET_HashCode zone;
45
46static struct GNUNET_CRYPTO_EccPrivateKey * privkey2; 40static struct GNUNET_CRYPTO_EccPrivateKey * privkey2;
47 41
48static struct GNUNET_CRYPTO_EccPublicKey pubkey2;
49
50static struct GNUNET_HashCode zone2;
51
52static struct GNUNET_NAMESTORE_ZoneMonitor *zm; 42static struct GNUNET_NAMESTORE_ZoneMonitor *zm;
53 43
54static int res; 44static int res;
55 45
56static int returned_records;
57
58static struct GNUNET_CRYPTO_EccSignature *sig_1;
59
60static char * s_name_1; 46static char * s_name_1;
61 47
62static struct GNUNET_NAMESTORE_RecordData *s_rd_1; 48static struct GNUNET_NAMESTORE_RecordData *s_rd_1;
63 49
64static struct GNUNET_CRYPTO_EccSignature *sig_2;
65
66static char * s_name_2; 50static char * s_name_2;
67 51
68static struct GNUNET_NAMESTORE_RecordData *s_rd_2; 52static struct GNUNET_NAMESTORE_RecordData *s_rd_2;
69 53
70static struct GNUNET_CRYPTO_EccSignature *sig_3;
71
72static char * s_name_3; 54static char * s_name_3;
73 55
74static struct GNUNET_NAMESTORE_RecordData *s_rd_3; 56static struct GNUNET_NAMESTORE_RecordData *s_rd_3;
75 57
58struct GNUNET_NAMESTORE_QueueEntry * ns_ops[3];
59
76 60
77static void 61static void
78do_shutdown () 62do_shutdown ()
79{ 63{
80 if (stopiteration_task != GNUNET_SCHEDULER_NO_TASK)
81 {
82 GNUNET_SCHEDULER_cancel (stopiteration_task);
83 stopiteration_task = GNUNET_SCHEDULER_NO_TASK;
84 }
85 if (NULL != zm) 64 if (NULL != zm)
86 { 65 {
87 GNUNET_NAMESTORE_zone_monitor_stop (zm); 66 GNUNET_NAMESTORE_zone_monitor_stop (zm);
88 zm = NULL; 67 zm = NULL;
89 } 68 }
69
70 if (NULL != ns_ops[0])
71 {
72 GNUNET_NAMESTORE_cancel(ns_ops[0]);
73 ns_ops[0] = NULL;
74 }
75 if (NULL != ns_ops[1])
76 {
77 GNUNET_NAMESTORE_cancel(ns_ops[1]);
78 ns_ops[1] = NULL;
79 }
80 if (NULL != ns_ops[2])
81 {
82 GNUNET_NAMESTORE_cancel(ns_ops[2]);
83 ns_ops[2] = NULL;
84 }
85
90 if (NULL != nsh) 86 if (NULL != nsh)
91 { 87 {
92 GNUNET_NAMESTORE_disconnect (nsh); 88 GNUNET_NAMESTORE_disconnect (nsh);
93 nsh = NULL; 89 nsh = NULL;
94 } 90 }
95 GNUNET_free_non_null(sig_1); 91
96 GNUNET_free_non_null(sig_2);
97 GNUNET_free_non_null(sig_3);
98 GNUNET_free_non_null(s_name_1); 92 GNUNET_free_non_null(s_name_1);
99 GNUNET_free_non_null(s_name_2); 93 GNUNET_free_non_null(s_name_2);
100 GNUNET_free_non_null(s_name_3); 94 GNUNET_free_non_null(s_name_3);
@@ -152,41 +146,64 @@ end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
152 146
153static void 147static void
154zone_proc (void *cls, 148zone_proc (void *cls,
155 const struct GNUNET_CRYPTO_EccPublicKey *zone_key, 149 const struct GNUNET_CRYPTO_EccPrivateKey *zone_key,
156 struct GNUNET_TIME_Absolute expire,
157 const char *name, 150 const char *name,
158 unsigned int rd_count, 151 unsigned int rd_count,
159 const struct GNUNET_NAMESTORE_RecordData *rd, 152 const struct GNUNET_NAMESTORE_RecordData *rd)
160 const struct GNUNET_CRYPTO_EccSignature *signature)
161{ 153{
162 GNUNET_break (NULL == signature); 154 static int returned_records;
155 static int fail = GNUNET_NO;
163 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 156 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
164 "Comparing results name %s\n", 157 "Comparing results name %s\n",
165 name); 158 name);
159
160 if (0 != memcmp (zone_key, privkey, sizeof (struct GNUNET_CRYPTO_EccPrivateKey)))
161 {
162 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
163 "Monitoring returned wrong zone key\n");
164 GNUNET_break (0);
165 GNUNET_SCHEDULER_cancel (endbadly_task);
166 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
167 return;
168 }
169
166 if (0 == strcmp (name, s_name_1)) 170 if (0 == strcmp (name, s_name_1))
167 { 171 {
168 if (GNUNET_YES != GNUNET_NAMESTORE_records_cmp(rd, s_rd_1)) 172 if (GNUNET_YES != GNUNET_NAMESTORE_records_cmp(rd, s_rd_1))
173 {
169 GNUNET_break (0); 174 GNUNET_break (0);
175 fail = GNUNET_YES;
176 }
170 } 177 }
171 if (0 == strcmp (name, s_name_2)) 178 else if (0 == strcmp (name, s_name_2))
172 { 179 {
173 if (GNUNET_YES != GNUNET_NAMESTORE_records_cmp(rd, s_rd_2)) 180 if (GNUNET_YES != GNUNET_NAMESTORE_records_cmp(rd, s_rd_2))
181 {
174 GNUNET_break (0); 182 GNUNET_break (0);
183 fail = GNUNET_YES;
184 }
175 } 185 }
176 if (0 == strcmp (name, s_name_3)) 186 else
177 { 187 {
178 if (GNUNET_YES != GNUNET_NAMESTORE_records_cmp(rd, s_rd_3)) 188 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
179 GNUNET_break (0); 189 "Invalid name %s\n", name);
190 GNUNET_break (0);
191 fail = GNUNET_YES;
180 } 192 }
181 if (3 == ++returned_records) 193
194 if (2 == ++returned_records)
182 { 195 {
183 if (endbadly_task != GNUNET_SCHEDULER_NO_TASK) 196 if (endbadly_task != GNUNET_SCHEDULER_NO_TASK)
184 { 197 {
185 GNUNET_SCHEDULER_cancel (endbadly_task); 198 GNUNET_SCHEDULER_cancel (endbadly_task);
186 endbadly_task = GNUNET_SCHEDULER_NO_TASK; 199 endbadly_task = GNUNET_SCHEDULER_NO_TASK;
187 } 200 }
188 GNUNET_SCHEDULER_add_now (&end, NULL); 201 if (GNUNET_YES == fail)
202 GNUNET_SCHEDULER_add_now (&endbadly, NULL);
203 else
204 GNUNET_SCHEDULER_add_now (&end, NULL);
189 } 205 }
206
190} 207}
191 208
192 209
@@ -194,11 +211,19 @@ static void
194put_cont (void *cls, int32_t success, const char *emsg) 211put_cont (void *cls, int32_t success, const char *emsg)
195{ 212{
196 static int c = 0; 213 static int c = 0;
214 char *label = cls;
215
216 if (0 == strcmp (label, s_name_1))
217 ns_ops[0] = NULL;
218 else if (0 == strcmp (label, s_name_2))
219 ns_ops[1] = NULL;
220 else if (0 == strcmp (label, s_name_3))
221 ns_ops[2] = NULL;
197 222
198 if (success == GNUNET_OK) 223 if (success == GNUNET_OK)
199 { 224 {
200 c++; 225 c++;
201 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record %u\n", c); 226 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record %u: `%s'\n", c, label);
202 } 227 }
203 else 228 else
204 { 229 {
@@ -235,12 +260,22 @@ run (void *cls,
235 struct GNUNET_TESTING_Peer *peer) 260 struct GNUNET_TESTING_Peer *peer)
236{ 261{
237 char *hostkey_file; 262 char *hostkey_file;
238 struct GNUNET_TIME_Absolute et;
239 263
240 res = 1; 264 res = 1;
241 returned_records = 0; 265
266 GNUNET_asprintf(&hostkey_file,
267 "zonefiles%s%s",
268 DIR_SEPARATOR_STR,
269 "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
270 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
271 "Using zonekey file `%s' \n", hostkey_file);
272 privkey = GNUNET_CRYPTO_ecc_key_create_from_file(hostkey_file);
273 GNUNET_free (hostkey_file);
274 GNUNET_assert (privkey != NULL);
275
276 /* Start monitoring */
242 zm = GNUNET_NAMESTORE_zone_monitor_start (cfg, 277 zm = GNUNET_NAMESTORE_zone_monitor_start (cfg,
243 NULL, 278 privkey,
244 &zone_proc, 279 &zone_proc,
245 NULL, 280 NULL,
246 NULL); 281 NULL);
@@ -251,21 +286,17 @@ run (void *cls,
251 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); 286 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
252 return; 287 return;
253 } 288 }
289
254 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &endbadly, NULL); 290 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &endbadly, NULL);
291 /* Connect to namestore */
255 nsh = GNUNET_NAMESTORE_connect (cfg); 292 nsh = GNUNET_NAMESTORE_connect (cfg);
256 GNUNET_break (NULL != nsh); 293 if (NULL == nsh)
257 294 {
258 GNUNET_asprintf(&hostkey_file, 295 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Connect to namestore\n");
259 "zonefiles%s%s", 296 GNUNET_break (0);
260 DIR_SEPARATOR_STR, 297 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
261 "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey"); 298 return;
262 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 299 }
263 "Using zonekey file `%s' \n", hostkey_file);
264 privkey = GNUNET_CRYPTO_ecc_key_create_from_file(hostkey_file);
265 GNUNET_free (hostkey_file);
266 GNUNET_assert (privkey != NULL);
267 GNUNET_CRYPTO_ecc_key_get_public(privkey, &pubkey);
268 GNUNET_CRYPTO_hash(&pubkey, sizeof (pubkey), &zone);
269 300
270 GNUNET_asprintf(&hostkey_file,"zonefiles%s%s", 301 GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",
271 DIR_SEPARATOR_STR, 302 DIR_SEPARATOR_STR,
@@ -273,41 +304,30 @@ run (void *cls,
273 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file); 304 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
274 privkey2 = GNUNET_CRYPTO_ecc_key_create_from_file(hostkey_file); 305 privkey2 = GNUNET_CRYPTO_ecc_key_create_from_file(hostkey_file);
275 GNUNET_free (hostkey_file); 306 GNUNET_free (hostkey_file);
276
277 GNUNET_assert (privkey2 != NULL); 307 GNUNET_assert (privkey2 != NULL);
278 GNUNET_CRYPTO_ecc_key_get_public(privkey2, &pubkey2);
279 GNUNET_CRYPTO_hash(&pubkey2, sizeof (pubkey), &zone2);
280 308
281 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 1\n");
282 309
310 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 3\n");
311 /* name in different zone */
312 GNUNET_asprintf(&s_name_3, "dummy3");
313 s_rd_3 = create_record(1);
314 GNUNET_assert (NULL != (ns_ops[2] = GNUNET_NAMESTORE_records_store (nsh, privkey2, s_name_3,
315 1, s_rd_3, &put_cont, s_name_3)));
316
317 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 1\n");
283 GNUNET_asprintf(&s_name_1, "dummy1"); 318 GNUNET_asprintf(&s_name_1, "dummy1");
284 s_rd_1 = create_record(1); 319 s_rd_1 = create_record(1);
285 et.abs_value_us = s_rd_1->expiration_time; 320 GNUNET_assert (NULL != (ns_ops[0] = GNUNET_NAMESTORE_records_store(nsh, privkey, s_name_1,
286 sig_1 = GNUNET_NAMESTORE_create_signature(privkey, et, s_name_1, s_rd_1, 1); 321 1, s_rd_1, &put_cont, s_name_1)));
287 GNUNET_NAMESTORE_record_put_by_authority (nsh, privkey, s_name_1,
288 1, s_rd_1,
289 &put_cont, NULL);
290 322
291 323
292 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 2 \n"); 324 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 2 \n");
293 GNUNET_asprintf(&s_name_2, "dummy2"); 325 GNUNET_asprintf(&s_name_2, "dummy2");
294 s_rd_2 = create_record(1); 326 s_rd_2 = create_record(1);
327 GNUNET_assert (NULL != (ns_ops[1] = GNUNET_NAMESTORE_records_store(nsh, privkey, s_name_2,
328 1, s_rd_2, &put_cont, s_name_2)));
295 329
296 et.abs_value_us = s_rd_2->expiration_time;
297 sig_2 = GNUNET_NAMESTORE_create_signature(privkey, et, s_name_2, s_rd_2, 1);
298 GNUNET_NAMESTORE_record_put_by_authority (nsh, privkey, s_name_2,
299 1, s_rd_2,
300 &put_cont, NULL);
301 330
302 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 3\n");
303 /* name in different zone */
304 GNUNET_asprintf(&s_name_3, "dummy3");
305 s_rd_3 = create_record(1);
306 et.abs_value_us = s_rd_3->expiration_time;
307 sig_3 = GNUNET_NAMESTORE_create_signature(privkey2, et, s_name_3, s_rd_3, 1);
308 GNUNET_NAMESTORE_record_put (nsh, &pubkey2, s_name_3,
309 GNUNET_TIME_UNIT_FOREVER_ABS, 1, s_rd_3, sig_3,
310 &put_cont, NULL);
311} 331}
312 332
313 333