aboutsummaryrefslogtreecommitdiff
path: root/src/gns
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2012-09-03 15:04:41 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2012-09-03 15:04:41 +0000
commit32566458738aa4d91d02616ef4f38c2614acf301 (patch)
tree33e57c9be6928b3435a8d63417f647656aaab75c /src/gns
parenta6c88c59dfc11abe372b928bdf938cc19e4c8891 (diff)
downloadgnunet-32566458738aa4d91d02616ef4f38c2614acf301.tar.gz
gnunet-32566458738aa4d91d02616ef4f38c2614acf301.zip
next one
Diffstat (limited to 'src/gns')
-rw-r--r--src/gns/Makefile.am4
-rw-r--r--src/gns/test_gns_max_queries.c177
2 files changed, 59 insertions, 122 deletions
diff --git a/src/gns/Makefile.am b/src/gns/Makefile.am
index 59bd1191a..9c2d5b3fe 100644
--- a/src/gns/Makefile.am
+++ b/src/gns/Makefile.am
@@ -229,12 +229,12 @@ test_gns_max_queries_LDADD = \
229 $(top_builddir)/src/util/libgnunetutil.la \ 229 $(top_builddir)/src/util/libgnunetutil.la \
230 $(top_builddir)/src/namestore/libgnunetnamestore.la \ 230 $(top_builddir)/src/namestore/libgnunetnamestore.la \
231 $(top_builddir)/src/gns/libgnunetgns.la \ 231 $(top_builddir)/src/gns/libgnunetgns.la \
232 $(top_builddir)/src/testing_old/libgnunettesting_old.la 232 $(top_builddir)/src/testing/libgnunettesting.la
233test_gns_max_queries_DEPENDENCIES = \ 233test_gns_max_queries_DEPENDENCIES = \
234 $(top_builddir)/src/util/libgnunetutil.la \ 234 $(top_builddir)/src/util/libgnunetutil.la \
235 $(top_builddir)/src/namestore/libgnunetnamestore.la \ 235 $(top_builddir)/src/namestore/libgnunetnamestore.la \
236 $(top_builddir)/src/gns/libgnunetgns.la \ 236 $(top_builddir)/src/gns/libgnunetgns.la \
237 $(top_builddir)/src/testing_old/libgnunettesting_old.la 237 $(top_builddir)/src/testing/libgnunettesting.la
238 238
239test_gns_cname_lookup_SOURCES = \ 239test_gns_cname_lookup_SOURCES = \
240 test_gns_cname_lookup.c 240 test_gns_cname_lookup.c
diff --git a/src/gns/test_gns_max_queries.c b/src/gns/test_gns_max_queries.c
index 3f3900206..1c3037b87 100644
--- a/src/gns/test_gns_max_queries.c
+++ b/src/gns/test_gns_max_queries.c
@@ -23,7 +23,7 @@
23 * in particular query replacement and clean shutdown 23 * in particular query replacement and clean shutdown
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_dns.h" 28#include "block_dns.h"
29#include "gns.h" 29#include "gns.h"
@@ -53,13 +53,6 @@
53 53
54/* Globals */ 54/* Globals */
55 55
56/**
57 * Directory to store temp data in, defined in config file
58 */
59static char *test_directory;
60
61static struct GNUNET_TESTING_PeerGroup *pg;
62
63/* Task handle to use to schedule test failure */ 56/* Task handle to use to schedule test failure */
64GNUNET_SCHEDULER_TaskIdentifier die_task; 57GNUNET_SCHEDULER_TaskIdentifier die_task;
65 58
@@ -74,26 +67,49 @@ const struct GNUNET_CONFIGURATION_Handle *cfg;
74 67
75static unsigned long long max_parallel_lookups; 68static unsigned long long max_parallel_lookups;
76 69
70
77/** 71/**
78 * Check whether peers successfully shut down. 72 * Check if the get_handle is being used, if so stop the request. Either
73 * way, schedule the end_badly_cont function which actually shuts down the
74 * test.
79 */ 75 */
80void 76static void
81shutdown_callback (void *cls, const char *emsg) 77end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
82{ 78{
83 if (emsg != NULL) 79 die_task = GNUNET_SCHEDULER_NO_TASK;
80 if (NULL != gns_handle)
84 { 81 {
85 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error on shutdown! ret=%d\n", ok); 82 GNUNET_GNS_disconnect(gns_handle);
86 if (ok == 0) 83 gns_handle = NULL;
87 ok = 2;
88 } 84 }
89 85
90 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "done(ret=%d)!\n", ok); 86 if (NULL != namestore_handle)
87 {
88 GNUNET_NAMESTORE_disconnect (namestore_handle);
89 namestore_handle = NULL;
90 }
91 GNUNET_break (0);
92 GNUNET_SCHEDULER_shutdown ();
93 ok = 1;
91} 94}
92 95
93static void 96static void
97end_badly_now ()
98{
99 GNUNET_SCHEDULER_cancel (die_task);
100 die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
101}
102
103
104static void
94on_lookup_result_dummy(void *cls, uint32_t rd_count, 105on_lookup_result_dummy(void *cls, uint32_t rd_count,
95 const struct GNUNET_NAMESTORE_RecordData *rd) 106 const struct GNUNET_NAMESTORE_RecordData *rd)
96{ 107{
108 if (GNUNET_SCHEDULER_NO_TASK != die_task)
109 {
110 GNUNET_SCHEDULER_cancel (die_task);
111 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
112 }
97 if (rd_count != 0) 113 if (rd_count != 0)
98 { 114 {
99 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 115 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
@@ -101,6 +117,7 @@ on_lookup_result_dummy(void *cls, uint32_t rd_count,
101 rd_count); 117 rd_count);
102 ok = -1; 118 ok = -1;
103 } 119 }
120 fprintf (stderr, ".");
104} 121}
105 122
106static void 123static void
@@ -111,7 +128,14 @@ on_lookup_result(void *cls, uint32_t rd_count,
111 int i; 128 int i;
112 char* addr; 129 char* addr;
113 130
131 if (GNUNET_SCHEDULER_NO_TASK != die_task)
132 {
133 GNUNET_SCHEDULER_cancel (die_task);
134 die_task = GNUNET_SCHEDULER_NO_TASK;
135 }
136
114 GNUNET_NAMESTORE_disconnect (namestore_handle); 137 GNUNET_NAMESTORE_disconnect (namestore_handle);
138 namestore_handle = NULL;
115 if (rd_count == 0) 139 if (rd_count == 0)
116 { 140 {
117 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 141 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -144,10 +168,9 @@ on_lookup_result(void *cls, uint32_t rd_count,
144 } 168 }
145 } 169 }
146 GNUNET_GNS_disconnect(gns_handle); 170 GNUNET_GNS_disconnect(gns_handle);
147 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Shutting down peer1!\n"); 171 gns_handle = NULL;
148 //GNUNET_TESTING_daemon_stop (d1, TIMEOUT, &shutdown_callback, NULL, 172 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Shutting down peer!\n");
149 // GNUNET_YES, GNUNET_NO); 173 GNUNET_SCHEDULER_shutdown ();
150 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
151} 174}
152 175
153 176
@@ -191,37 +214,11 @@ commence_testing (void *cls, int32_t success, const char *emsg)
191} 214}
192 215
193 216
194/**
195 * Continuation for the GNUNET_DHT_get_stop call, so that we don't shut
196 * down the peers without freeing memory associated with GET request.
197 */
198static void
199end_badly_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
200{
201
202 if (pg != NULL)
203 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
204 GNUNET_SCHEDULER_cancel (die_task);
205}
206
207/**
208 * Check if the get_handle is being used, if so stop the request. Either
209 * way, schedule the end_badly_cont function which actually shuts down the
210 * test.
211 */
212static void
213end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
214{
215 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failing test with error: `%s'!\n",
216 (char *) cls);
217 GNUNET_SCHEDULER_add_now (&end_badly_cont, NULL);
218 ok = 1;
219}
220 217
221static void 218static void
222do_lookup(void *cls, const struct GNUNET_PeerIdentity *id, 219do_check (void *cls,
223 const struct GNUNET_CONFIGURATION_Handle *_cfg, 220 const struct GNUNET_CONFIGURATION_Handle *ccfg,
224 struct GNUNET_TESTING_Daemon *d, const char *emsg) 221 struct GNUNET_TESTING_Peer *peer)
225{ 222{
226 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded alice_pkey; 223 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded alice_pkey;
227 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded bob_pkey; 224 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded bob_pkey;
@@ -230,16 +227,16 @@ do_lookup(void *cls, const struct GNUNET_PeerIdentity *id,
230 char* alice_keyfile; 227 char* alice_keyfile;
231 struct GNUNET_CRYPTO_ShortHashCode bob_hash; 228 struct GNUNET_CRYPTO_ShortHashCode bob_hash;
232 229
233 cfg = _cfg; 230 cfg = ccfg;
231 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
234 232
235 GNUNET_SCHEDULER_cancel (die_task);
236 233
237 /* put records into namestore */ 234 /* put records into namestore */
238 namestore_handle = GNUNET_NAMESTORE_connect(cfg); 235 namestore_handle = GNUNET_NAMESTORE_connect(cfg);
239 if (NULL == namestore_handle) 236 if (NULL == namestore_handle)
240 { 237 {
241 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to connect to namestore\n"); 238 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to connect to namestore\n");
242 ok = -1; 239 end_badly_now();
243 return; 240 return;
244 } 241 }
245 242
@@ -248,7 +245,7 @@ do_lookup(void *cls, const struct GNUNET_PeerIdentity *id,
248 &alice_keyfile)) 245 &alice_keyfile))
249 { 246 {
250 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to get key from cfg\n"); 247 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to get key from cfg\n");
251 ok = -1; 248 end_badly_now();
252 return; 249 return;
253 } 250 }
254 251
@@ -257,7 +254,7 @@ do_lookup(void *cls, const struct GNUNET_PeerIdentity *id,
257 &max_parallel_lookups)) 254 &max_parallel_lookups))
258 { 255 {
259 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to get max queries from cfg\n"); 256 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to get max queries from cfg\n");
260 ok = -1; 257 end_badly_now();
261 GNUNET_free (alice_keyfile); 258 GNUNET_free (alice_keyfile);
262 return; 259 return;
263 } 260 }
@@ -305,82 +302,22 @@ do_lookup(void *cls, const struct GNUNET_PeerIdentity *id,
305 302
306} 303}
307 304
308static void
309run (void *cls, char *const *args, const char *cfgfile,
310 const struct GNUNET_CONFIGURATION_Handle *c)
311{
312 cfg = c;
313 /* Get path from configuration file */
314 if (GNUNET_YES !=
315 GNUNET_CONFIGURATION_get_value_string (cfg, "paths", "servicehome",
316 &test_directory))
317 {
318 ok = 404;
319 return;
320 }
321
322
323 /* Set up a task to end testing if peer start fails */
324 die_task =
325 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly,
326 "didn't start all daemons in reasonable amount of time!!!");
327
328 /* Start alice */
329 //d1 = GNUNET_TESTING_daemon_start(cfg, TIMEOUT, GNUNET_NO, NULL, NULL, 0,
330 // NULL, NULL, NULL, &do_lookup, NULL);
331 pg = GNUNET_TESTING_daemons_start(cfg, 1, 1, 1, TIMEOUT,
332 NULL, NULL, &do_lookup, NULL,
333 NULL, NULL, NULL);
334}
335
336static int
337check ()
338{
339 int ret;
340
341 /* Arguments for GNUNET_PROGRAM_run */
342 char *const argv[] = { "test-gns-max-queries", /* Name to give running binary */
343 "-c",
344 "test_gns_simple_lookup.conf", /* Config file to use */
345#if VERBOSE
346 "-L", "DEBUG",
347#endif
348 NULL
349 };
350 struct GNUNET_GETOPT_CommandLineOption options[] = {
351 GNUNET_GETOPT_OPTION_END
352 };
353 /* Run the run function as a new program */
354 ret =
355 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
356 "test-gns-max-queries", "nohelp", options, &run,
357 &ok);
358 if (ret != GNUNET_OK)
359 {
360 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
361 "`test-gns-simple-lookup': Failed with error code %d\n", ret);
362 }
363 return ok;
364}
365 305
366int 306int
367main (int argc, char *argv[]) 307main (int argc, char *argv[])
368{ 308{
369 int ret; 309 ok = 1;
370 310
371 GNUNET_log_setup ("test-gns-simple-lookup", 311 GNUNET_log_setup ("test-gns-max-queries",
372#if VERBOSE 312#if VERBOSE
373 "DEBUG", 313 "DEBUG",
374#else 314#else
375 "WARNING", 315 "WARNING",
376#endif 316#endif
377 NULL); 317 NULL);
378 ret = check (); 318 GNUNET_TESTING_peer_run ("test-gns-max-queries", "test_gns_simple_lookup.conf", &do_check, NULL);
379 /** 319 return ok;
380 * Need to remove base directory, subdirectories taken care
381 * of by the testing framework.
382 */
383 return ret;
384} 320}
385 321
386/* end of test_gns_twopeer.c */ 322
323/* end of test_gns_simple_zkey_lookup.c */