aboutsummaryrefslogtreecommitdiff
path: root/src/gns/test_gns_dht_delegated_lookup.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2012-09-03 13:56:55 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2012-09-03 13:56:55 +0000
commit2074f4de6f84fd93758d7a95f45f4565bddf9c79 (patch)
tree5fd6448781c29d2f74c8df70925fa44f52df53ee /src/gns/test_gns_dht_delegated_lookup.c
parent70c9e99f4e00544f02c08bd1c73a18342782f986 (diff)
downloadgnunet-2074f4de6f84fd93758d7a95f45f4565bddf9c79.tar.gz
gnunet-2074f4de6f84fd93758d7a95f45f4565bddf9c79.zip
- next test
Diffstat (limited to 'src/gns/test_gns_dht_delegated_lookup.c')
-rw-r--r--src/gns/test_gns_dht_delegated_lookup.c207
1 files changed, 77 insertions, 130 deletions
diff --git a/src/gns/test_gns_dht_delegated_lookup.c b/src/gns/test_gns_dht_delegated_lookup.c
index 65c9cfaeb..b7d11bc5a 100644
--- a/src/gns/test_gns_dht_delegated_lookup.c
+++ b/src/gns/test_gns_dht_delegated_lookup.c
@@ -23,7 +23,7 @@
23 * 23 *
24 */ 24 */
25#include "platform.h" 25#include "platform.h"
26#include "gnunet_testing_lib.h" 26#include "gnunet_testing_lib-new.h"
27#include "gnunet_core_service.h" 27#include "gnunet_core_service.h"
28#include "block_gns.h" 28#include "block_gns.h"
29#include "gnunet_signatures.h" 29#include "gnunet_signatures.h"
@@ -39,6 +39,9 @@
39/* Timeout for entire testcase */ 39/* Timeout for entire testcase */
40#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 20) 40#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 20)
41 41
42/* Timeout for entire testcase */
43#define DHT_DELAY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10)
44
42/* If number of peers not in config file, use this number */ 45/* If number of peers not in config file, use this number */
43#define DEFAULT_NUM_PEERS 2 46#define DEFAULT_NUM_PEERS 2
44 47
@@ -55,15 +58,9 @@
55 58
56/* Globals */ 59/* Globals */
57 60
58/**
59 * Directory to store temp data in, defined in config file
60 */
61static char *test_directory;
62
63static struct GNUNET_TESTING_PeerGroup *pg;
64
65/* Task handle to use to schedule test failure */ 61/* Task handle to use to schedule test failure */
66GNUNET_SCHEDULER_TaskIdentifier die_task; 62GNUNET_SCHEDULER_TaskIdentifier die_task;
63GNUNET_SCHEDULER_TaskIdentifier wait_task;
67 64
68/* Global return value (0 for success, anything else for failure) */ 65/* Global return value (0 for success, anything else for failure) */
69static int ok; 66static int ok;
@@ -81,20 +78,49 @@ struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded bob_pkey;
81struct GNUNET_CRYPTO_RsaPrivateKey *alice_key; 78struct GNUNET_CRYPTO_RsaPrivateKey *alice_key;
82struct GNUNET_CRYPTO_RsaPrivateKey *bob_key; 79struct GNUNET_CRYPTO_RsaPrivateKey *bob_key;
83 80
81
84/** 82/**
85 * Check whether peers successfully shut down. 83 * Check if the get_handle is being used, if so stop the request. Either
84 * way, schedule the end_badly_cont function which actually shuts down the
85 * test.
86 */ 86 */
87void 87static void
88shutdown_callback (void *cls, const char *emsg) 88end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
89{ 89{
90 if (emsg != NULL) 90 die_task = GNUNET_SCHEDULER_NO_TASK;
91 if (NULL != gns_handle)
91 { 92 {
92 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error on shutdown! ret=%d\n", ok); 93 GNUNET_GNS_disconnect (gns_handle);
93 if (ok == 0) 94 gns_handle = NULL;
94 ok = 2;
95 } 95 }
96 96
97 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "done(ret=%d)!\n", ok); 97 if (NULL != dht_handle)
98 {
99 GNUNET_DHT_disconnect (dht_handle);
100 dht_handle = NULL;
101 }
102
103 if (NULL != namestore_handle)
104 {
105 GNUNET_NAMESTORE_disconnect (namestore_handle);
106 namestore_handle = NULL;
107 }
108 GNUNET_break (0);
109 GNUNET_SCHEDULER_shutdown ();
110 ok = 1;
111}
112
113static void
114end_badly_now ()
115{
116
117 if (GNUNET_SCHEDULER_NO_TASK != wait_task)
118 {
119 GNUNET_SCHEDULER_cancel (wait_task);
120 wait_task = GNUNET_SCHEDULER_NO_TASK;
121 }
122 GNUNET_SCHEDULER_cancel (die_task);
123 die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
98} 124}
99 125
100 126
@@ -106,9 +132,14 @@ on_lookup_result(void *cls, uint32_t rd_count,
106 int i; 132 int i;
107 char* addr; 133 char* addr;
108 134
109 GNUNET_NAMESTORE_disconnect (namestore_handle); 135 if (GNUNET_SCHEDULER_NO_TASK != die_task)
110 136 {
137 GNUNET_SCHEDULER_cancel (die_task);
138 die_task = GNUNET_SCHEDULER_NO_TASK;
139 }
111 140
141 GNUNET_NAMESTORE_disconnect (namestore_handle);
142 namestore_handle = NULL;
112 if (rd_count == 0) 143 if (rd_count == 0)
113 { 144 {
114 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 145 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -141,10 +172,11 @@ on_lookup_result(void *cls, uint32_t rd_count,
141 } 172 }
142 } 173 }
143 GNUNET_GNS_disconnect(gns_handle); 174 GNUNET_GNS_disconnect(gns_handle);
144 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Shutting down peer1!\n"); 175 gns_handle = NULL;
145 //GNUNET_TESTING_daemon_stop (d1, TIMEOUT, &shutdown_callback, NULL, 176 GNUNET_DHT_disconnect (dht_handle);
146 // GNUNET_YES, GNUNET_NO); 177 dht_handle = NULL;
147 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); 178 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Shutting down peer!\n");
179 GNUNET_SCHEDULER_shutdown ();
148} 180}
149 181
150 182
@@ -161,6 +193,8 @@ commence_testing (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
161 { 193 {
162 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 194 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
163 "Failed to connect to GNS!\n"); 195 "Failed to connect to GNS!\n");
196 end_badly_now();
197 return;
164 } 198 }
165 199
166 GNUNET_GNS_lookup(gns_handle, TEST_DOMAIN, GNUNET_GNS_RECORD_A, 200 GNUNET_GNS_lookup(gns_handle, TEST_DOMAIN, GNUNET_GNS_RECORD_A,
@@ -169,34 +203,6 @@ commence_testing (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
169 &on_lookup_result, TEST_DOMAIN); 203 &on_lookup_result, TEST_DOMAIN);
170} 204}
171 205
172/**
173 * Continuation for the GNUNET_DHT_get_stop call, so that we don't shut
174 * down the peers without freeing memory associated with GET request.
175 */
176static void
177end_badly_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
178{
179
180 if (pg != NULL) {
181 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
182 }
183 GNUNET_SCHEDULER_cancel (die_task);
184}
185
186/**
187 * Check if the get_handle is being used, if so stop the request. Either
188 * way, schedule the end_badly_cont function which actually shuts down the
189 * test.
190 */
191static void
192end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
193{
194 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failing test with error: `%s'!\n",
195 (char *) cls);
196 GNUNET_SCHEDULER_add_now (&end_badly_cont, NULL);
197 ok = 1;
198}
199
200 206
201static void 207static void
202put_dht(void *cls, int32_t success, const char *emsg) 208put_dht(void *cls, int32_t success, const char *emsg)
@@ -249,6 +255,7 @@ put_dht(void *cls, int32_t success, const char *emsg)
249 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Record serialization failed!\n"); 255 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Record serialization failed!\n");
250 ok = 3; 256 ok = 3;
251 GNUNET_free (nrb); 257 GNUNET_free (nrb);
258 end_badly_now ();
252 return; 259 return;
253 } 260 }
254 GNUNET_CRYPTO_short_hash(TEST_RECORD_NAME, strlen(TEST_RECORD_NAME), &name_hash); 261 GNUNET_CRYPTO_short_hash(TEST_RECORD_NAME, strlen(TEST_RECORD_NAME), &name_hash);
@@ -272,29 +279,31 @@ put_dht(void *cls, int32_t success, const char *emsg)
272 NULL, 279 NULL,
273 NULL); 280 NULL);
274 GNUNET_free (nrb); 281 GNUNET_free (nrb);
275 GNUNET_SCHEDULER_add_delayed(TIMEOUT, &commence_testing, NULL); 282 if (GNUNET_SCHEDULER_NO_TASK != die_task)
283 {
284 GNUNET_SCHEDULER_cancel (die_task);
285 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
286 }
287 wait_task = GNUNET_SCHEDULER_add_delayed(DHT_DELAY, &commence_testing, NULL);
276} 288}
277 289
278static void 290static void
279do_lookup(void *cls, const struct GNUNET_PeerIdentity *id, 291do_check (void *cls,
280 const struct GNUNET_CONFIGURATION_Handle *_cfg, 292 const struct GNUNET_CONFIGURATION_Handle *ccfg,
281 struct GNUNET_TESTING_Daemon *d, const char *emsg) 293 struct GNUNET_TESTING_Peer *peer)
282{ 294{
283
284
285 char* alice_keyfile; 295 char* alice_keyfile;
286 struct GNUNET_CRYPTO_ShortHashCode bob_hash; 296 struct GNUNET_CRYPTO_ShortHashCode bob_hash;
287 297
288 cfg = _cfg; 298 cfg = ccfg;
289 299 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
290 GNUNET_SCHEDULER_cancel (die_task);
291 300
292 /* put records into namestore */ 301 /* put records into namestore */
293 namestore_handle = GNUNET_NAMESTORE_connect(cfg); 302 namestore_handle = GNUNET_NAMESTORE_connect(cfg);
294 if (NULL == namestore_handle) 303 if (NULL == namestore_handle)
295 { 304 {
296 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to connect to namestore\n"); 305 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to connect to namestore\n");
297 ok = -1; 306 end_badly_now ();
298 return; 307 return;
299 } 308 }
300 309
@@ -303,7 +312,7 @@ do_lookup(void *cls, const struct GNUNET_PeerIdentity *id,
303 if (NULL == dht_handle) 312 if (NULL == dht_handle)
304 { 313 {
305 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to connect to dht\n"); 314 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to connect to dht\n");
306 ok = -1; 315 end_badly_now ();
307 return; 316 return;
308 } 317 }
309 318
@@ -312,7 +321,7 @@ do_lookup(void *cls, const struct GNUNET_PeerIdentity *id,
312 &alice_keyfile)) 321 &alice_keyfile))
313 { 322 {
314 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to get key from cfg\n"); 323 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to get key from cfg\n");
315 ok = -1; 324 end_badly_now ();
316 return; 325 return;
317 } 326 }
318 327
@@ -338,86 +347,24 @@ do_lookup(void *cls, const struct GNUNET_PeerIdentity *id,
338 &rd, 347 &rd,
339 &put_dht, 348 &put_dht,
340 NULL); 349 NULL);
341
342
343
344} 350}
345 351
346static void
347run (void *cls, char *const *args, const char *cfgfile,
348 const struct GNUNET_CONFIGURATION_Handle *c)
349{
350 cfg = c;
351 /* Get path from configuration file */
352 if (GNUNET_YES !=
353 GNUNET_CONFIGURATION_get_value_string (cfg, "paths", "servicehome",
354 &test_directory))
355 {
356 ok = 404;
357 return;
358 }
359
360
361 /* Set up a task to end testing if peer start fails */
362 die_task =
363 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly,
364 "didn't start all daemons in reasonable amount of time!!!");
365
366 /* Start alice */
367 //d1 = GNUNET_TESTING_daemon_start(cfg, TIMEOUT, GNUNET_NO, NULL, NULL, 0,
368 // NULL, NULL, NULL, &do_lookup, NULL);
369 pg = GNUNET_TESTING_daemons_start(cfg, 1, 1, 1, TIMEOUT,
370 NULL, NULL, &do_lookup, NULL, NULL, NULL, NULL);
371}
372
373static int
374check ()
375{
376 int ret;
377
378 /* Arguments for GNUNET_PROGRAM_run */
379 char *const argv[] = { "test-gns-dht-delegated-lookup", /* Name to give running binary */
380 "-c",
381 "test_gns_simple_lookup.conf", /* Config file to use */
382#if VERBOSE
383 "-L", "DEBUG",
384#endif
385 NULL
386 };
387 struct GNUNET_GETOPT_CommandLineOption options[] = {
388 GNUNET_GETOPT_OPTION_END
389 };
390 /* Run the run function as a new program */
391 ret =
392 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
393 "test-gns-dht-delegated-lookup", "nohelp", options, &run,
394 &ok);
395 if (ret != GNUNET_OK)
396 {
397 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
398 "`test-gns-dht-delegated-lookup': Failed with error code %d\n", ret);
399 }
400 return ok;
401}
402 352
403int 353int
404main (int argc, char *argv[]) 354main (int argc, char *argv[])
405{ 355{
406 int ret; 356 ok = 1;
407 357
408 GNUNET_log_setup ("test-gns-simple-lookup", 358 GNUNET_log_setup ("test-gns-dht-delegated-lookup",
409#if VERBOSE 359#if VERBOSE
410 "DEBUG", 360 "DEBUG",
411#else 361#else
412 "WARNING", 362 "WARNING",
413#endif 363#endif
414 NULL); 364 NULL);
415 ret = check (); 365 GNUNET_TESTING_peer_run ("test-gns-dht-delegated-lookup", "test_gns_simple_lookup.conf", &do_check, NULL);
416 /** 366 return ok;
417 * Need to remove base directory, subdirectories taken care
418 * of by the testing framework.
419 */
420 return ret;
421} 367}
422 368
423/* end of test_gns_twopeer.c */ 369
370/* end of test_gns_dht_delegated_lookup.c */