aboutsummaryrefslogtreecommitdiff
path: root/src/gns
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2012-09-03 12:34:11 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2012-09-03 12:34:11 +0000
commit7b8f07966a8dae71a081f434d213d1379c988d66 (patch)
tree1e684caad756785de09ee792b6060cff29b224cc /src/gns
parent5d685d027f45c91933c5c7df4152243255560dfd (diff)
downloadgnunet-7b8f07966a8dae71a081f434d213d1379c988d66.tar.gz
gnunet-7b8f07966a8dae71a081f434d213d1379c988d66.zip
- next test
Diffstat (limited to 'src/gns')
-rw-r--r--src/gns/Makefile.am12
-rw-r--r--src/gns/test_gns_simple_delegated_lookup.c168
-rw-r--r--src/gns/test_gns_simple_get_authority.c12
-rw-r--r--src/gns/test_gns_simple_lookup.c186
4 files changed, 118 insertions, 260 deletions
diff --git a/src/gns/Makefile.am b/src/gns/Makefile.am
index f5c2771b7..49ae289c4 100644
--- a/src/gns/Makefile.am
+++ b/src/gns/Makefile.am
@@ -106,12 +106,12 @@ test_gns_simple_lookup_LDADD = \
106 $(top_builddir)/src/util/libgnunetutil.la \ 106 $(top_builddir)/src/util/libgnunetutil.la \
107 $(top_builddir)/src/namestore/libgnunetnamestore.la \ 107 $(top_builddir)/src/namestore/libgnunetnamestore.la \
108 $(top_builddir)/src/gns/libgnunetgns.la \ 108 $(top_builddir)/src/gns/libgnunetgns.la \
109 $(top_builddir)/src/testing_old/libgnunettesting_old.la 109 $(top_builddir)/src/testing/libgnunettesting.la
110test_gns_simple_lookup_DEPENDENCIES = \ 110test_gns_simple_lookup_DEPENDENCIES = \
111 $(top_builddir)/src/util/libgnunetutil.la \ 111 $(top_builddir)/src/util/libgnunetutil.la \
112 $(top_builddir)/src/namestore/libgnunetnamestore.la \ 112 $(top_builddir)/src/namestore/libgnunetnamestore.la \
113 $(top_builddir)/src/gns/libgnunetgns.la \ 113 $(top_builddir)/src/gns/libgnunetgns.la \
114 $(top_builddir)/src/testing_old/libgnunettesting_old.la 114 $(top_builddir)/src/testing/libgnunettesting.la
115 115
116test_gns_simple_delegated_lookup_SOURCES = \ 116test_gns_simple_delegated_lookup_SOURCES = \
117 test_gns_simple_delegated_lookup.c 117 test_gns_simple_delegated_lookup.c
@@ -119,12 +119,12 @@ test_gns_simple_delegated_lookup_LDADD = \
119 $(top_builddir)/src/util/libgnunetutil.la \ 119 $(top_builddir)/src/util/libgnunetutil.la \
120 $(top_builddir)/src/namestore/libgnunetnamestore.la \ 120 $(top_builddir)/src/namestore/libgnunetnamestore.la \
121 $(top_builddir)/src/gns/libgnunetgns.la \ 121 $(top_builddir)/src/gns/libgnunetgns.la \
122 $(top_builddir)/src/testing_old/libgnunettesting_old.la 122 $(top_builddir)/src/testing/libgnunettesting.la
123test_gns_simple_delegated_lookup_DEPENDENCIES = \ 123test_gns_simple_delegated_lookup_DEPENDENCIES = \
124 $(top_builddir)/src/util/libgnunetutil.la \ 124 $(top_builddir)/src/util/libgnunetutil.la \
125 $(top_builddir)/src/namestore/libgnunetnamestore.la \ 125 $(top_builddir)/src/namestore/libgnunetnamestore.la \
126 $(top_builddir)/src/gns/libgnunetgns.la \ 126 $(top_builddir)/src/gns/libgnunetgns.la \
127 $(top_builddir)/src/testing_old/libgnunettesting_old.la 127 $(top_builddir)/src/testing/libgnunettesting.la
128 128
129test_gns_simple_mx_lookup_SOURCES = \ 129test_gns_simple_mx_lookup_SOURCES = \
130 test_gns_simple_mx_lookup.c 130 test_gns_simple_mx_lookup.c
@@ -172,13 +172,13 @@ test_gns_dht_delegated_lookup_LDADD = \
172 $(top_builddir)/src/namestore/libgnunetnamestore.la \ 172 $(top_builddir)/src/namestore/libgnunetnamestore.la \
173 $(top_builddir)/src/dht/libgnunetdht.la \ 173 $(top_builddir)/src/dht/libgnunetdht.la \
174 $(top_builddir)/src/gns/libgnunetgns.la \ 174 $(top_builddir)/src/gns/libgnunetgns.la \
175 $(top_builddir)/src/testing_old/libgnunettesting_old.la 175 $(top_builddir)/src/testing/libgnunettesting.la
176test_gns_dht_delegated_lookup_DEPENDENCIES = \ 176test_gns_dht_delegated_lookup_DEPENDENCIES = \
177 $(top_builddir)/src/util/libgnunetutil.la \ 177 $(top_builddir)/src/util/libgnunetutil.la \
178 $(top_builddir)/src/namestore/libgnunetnamestore.la \ 178 $(top_builddir)/src/namestore/libgnunetnamestore.la \
179 $(top_builddir)/src/dht/libgnunetdht.la \ 179 $(top_builddir)/src/dht/libgnunetdht.la \
180 $(top_builddir)/src/gns/libgnunetgns.la \ 180 $(top_builddir)/src/gns/libgnunetgns.la \
181 $(top_builddir)/src/testing_old/libgnunettesting_old.la 181 $(top_builddir)/src/testing/libgnunettesting.la
182 182
183test_gns_simple_shorten_SOURCES = \ 183test_gns_simple_shorten_SOURCES = \
184 test_gns_simple_shorten.c 184 test_gns_simple_shorten.c
diff --git a/src/gns/test_gns_simple_delegated_lookup.c b/src/gns/test_gns_simple_delegated_lookup.c
index af126a297..763704910 100644
--- a/src/gns/test_gns_simple_delegated_lookup.c
+++ b/src/gns/test_gns_simple_delegated_lookup.c
@@ -37,7 +37,7 @@
37 * the peers. 37 * the peers.
38 */ 38 */
39#include "platform.h" 39#include "platform.h"
40#include "gnunet_testing_lib.h" 40#include "gnunet_testing_lib-new.h"
41#include "gnunet_core_service.h" 41#include "gnunet_core_service.h"
42#include "block_dns.h" 42#include "block_dns.h"
43#include "gnunet_signatures.h" 43#include "gnunet_signatures.h"
@@ -66,13 +66,6 @@
66 66
67/* Globals */ 67/* Globals */
68 68
69/**
70 * Directory to store temp data in, defined in config file
71 */
72static char *test_directory;
73
74static struct GNUNET_TESTING_PeerGroup *pg;
75
76/* Task handle to use to schedule test failure */ 69/* Task handle to use to schedule test failure */
77GNUNET_SCHEDULER_TaskIdentifier die_task; 70GNUNET_SCHEDULER_TaskIdentifier die_task;
78 71
@@ -86,21 +79,36 @@ static struct GNUNET_GNS_Handle *gns_handle;
86const struct GNUNET_CONFIGURATION_Handle *cfg; 79const struct GNUNET_CONFIGURATION_Handle *cfg;
87 80
88/** 81/**
89 * Check whether peers successfully shut down. 82 * Check if the get_handle is being used, if so stop the request. Either
83 * way, schedule the end_badly_cont function which actually shuts down the
84 * test.
90 */ 85 */
91void 86static void
92shutdown_callback (void *cls, const char *emsg) 87end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
93{ 88{
94 if (emsg != NULL) 89 if (NULL != gns_handle)
90 {
91 GNUNET_GNS_disconnect(gns_handle);
92 gns_handle = NULL;
93 }
94
95 if (NULL != namestore_handle)
95 { 96 {
96 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error on shutdown! ret=%d\n", ok); 97 GNUNET_NAMESTORE_disconnect (namestore_handle);
97 if (ok == 0) 98 namestore_handle = NULL;
98 ok = 2;
99 } 99 }
100 GNUNET_break (0);
101 GNUNET_SCHEDULER_shutdown ();
102 ok = 1;
103}
100 104
101 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "done(ret=%d)!\n", ok); 105void end_badly_now ()
106{
107 GNUNET_SCHEDULER_cancel (die_task);
108 die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
102} 109}
103 110
111
104static void 112static void
105on_lookup_result(void *cls, uint32_t rd_count, 113on_lookup_result(void *cls, uint32_t rd_count,
106 const struct GNUNET_NAMESTORE_RecordData *rd) 114 const struct GNUNET_NAMESTORE_RecordData *rd)
@@ -109,6 +117,12 @@ on_lookup_result(void *cls, uint32_t rd_count,
109 int i; 117 int i;
110 char* addr; 118 char* addr;
111 119
120 if (GNUNET_SCHEDULER_NO_TASK != die_task)
121 {
122 GNUNET_SCHEDULER_cancel (die_task);
123 die_task = GNUNET_SCHEDULER_NO_TASK;
124 }
125
112 GNUNET_NAMESTORE_disconnect (namestore_handle); 126 GNUNET_NAMESTORE_disconnect (namestore_handle);
113 if (rd_count == 0) 127 if (rd_count == 0)
114 { 128 {
@@ -141,9 +155,10 @@ on_lookup_result(void *cls, uint32_t rd_count,
141 } 155 }
142 } 156 }
143 } 157 }
158
144 GNUNET_GNS_disconnect(gns_handle); 159 GNUNET_GNS_disconnect(gns_handle);
145 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Shutting down peer1!\n"); 160 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Shutting down peer!\n");
146 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); 161 GNUNET_SCHEDULER_shutdown ();
147} 162}
148 163
149 164
@@ -161,6 +176,8 @@ commence_testing (void *cls, int32_t success, const char *emsg)
161 { 176 {
162 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 177 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
163 "Failed to connect to GNS!\n"); 178 "Failed to connect to GNS!\n");
179 end_badly_now();
180 return;
164 } 181 }
165 182
166 GNUNET_GNS_lookup(gns_handle, TEST_DOMAIN, GNUNET_GNS_RECORD_A, 183 GNUNET_GNS_lookup(gns_handle, TEST_DOMAIN, GNUNET_GNS_RECORD_A,
@@ -169,37 +186,11 @@ commence_testing (void *cls, int32_t success, const char *emsg)
169 &on_lookup_result, TEST_DOMAIN); 186 &on_lookup_result, TEST_DOMAIN);
170} 187}
171 188
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 GNUNET_SCHEDULER_cancel (die_task);
183}
184 189
185/**
186 * Check if the get_handle is being used, if so stop the request. Either
187 * way, schedule the end_badly_cont function which actually shuts down the
188 * test.
189 */
190static void
191end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
192{
193 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failing test with error: `%s'!\n",
194 (char *) cls);
195 GNUNET_SCHEDULER_add_now (&end_badly_cont, NULL);
196 ok = 1;
197}
198 190
199static void 191void do_check (void *cls,
200do_lookup(void *cls, const struct GNUNET_PeerIdentity *id, 192 const struct GNUNET_CONFIGURATION_Handle *ccfg,
201 const struct GNUNET_CONFIGURATION_Handle *_cfg, 193 struct GNUNET_TESTING_Peer *peer)
202 struct GNUNET_TESTING_Daemon *d, const char *emsg)
203{ 194{
204 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded alice_pkey; 195 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded alice_pkey;
205 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded bob_pkey; 196 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded bob_pkey;
@@ -210,16 +201,15 @@ do_lookup(void *cls, const struct GNUNET_PeerIdentity *id,
210 char* alice_keyfile; 201 char* alice_keyfile;
211 struct GNUNET_TIME_Absolute et; 202 struct GNUNET_TIME_Absolute et;
212 203
213 cfg = _cfg; 204 cfg = ccfg;
214 205 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
215 GNUNET_SCHEDULER_cancel (die_task);
216 206
217 /* put records into namestore */ 207 /* put records into namestore */
218 namestore_handle = GNUNET_NAMESTORE_connect(cfg); 208 namestore_handle = GNUNET_NAMESTORE_connect(cfg);
219 if (NULL == namestore_handle) 209 if (NULL == namestore_handle)
220 { 210 {
221 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to connect to namestore\n"); 211 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to connect to namestore\n");
222 ok = -1; 212 end_badly_now () ;
223 return; 213 return;
224 } 214 }
225 215
@@ -228,7 +218,7 @@ do_lookup(void *cls, const struct GNUNET_PeerIdentity *id,
228 &alice_keyfile)) 218 &alice_keyfile))
229 { 219 {
230 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to get key from cfg\n"); 220 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to get key from cfg\n");
231 ok = -1; 221 end_badly_now () ;
232 return; 222 return;
233 } 223 }
234 224
@@ -275,85 +265,31 @@ do_lookup(void *cls, const struct GNUNET_PeerIdentity *id,
275 sig, 265 sig,
276 &commence_testing, 266 &commence_testing,
277 NULL); 267 NULL);
278 GNUNET_free(sig); 268
269 GNUNET_free (web);
270 GNUNET_free (sig);
271 GNUNET_free (alice_keyfile);
279 GNUNET_CRYPTO_rsa_key_free(bob_key); 272 GNUNET_CRYPTO_rsa_key_free(bob_key);
280 GNUNET_CRYPTO_rsa_key_free(alice_key); 273 GNUNET_CRYPTO_rsa_key_free(alice_key);
281} 274}
282 275
283static void
284run (void *cls, char *const *args, const char *cfgfile,
285 const struct GNUNET_CONFIGURATION_Handle *c)
286{
287 cfg = c;
288 /* Get path from configuration file */
289 if (GNUNET_YES !=
290 GNUNET_CONFIGURATION_get_value_string (cfg, "paths", "servicehome",
291 &test_directory))
292 {
293 ok = 404;
294 return;
295 }
296
297
298 /* Set up a task to end testing if peer start fails */
299 die_task =
300 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly,
301 "didn't start all daemons in reasonable amount of time!!!");
302
303 /* Start alice */
304 pg = GNUNET_TESTING_daemons_start(cfg, 1, 1, 1, TIMEOUT,
305 NULL, NULL, &do_lookup, NULL,
306 NULL, NULL, NULL);
307}
308
309static int
310check ()
311{
312 int ret;
313
314 /* Arguments for GNUNET_PROGRAM_run */
315 char *const argv[] = { "test-gns-simple-delegated-lookup", /* Name to give running binary */
316 "-c",
317 "test_gns_simple_lookup.conf", /* Config file to use */
318#if VERBOSE
319 "-L", "DEBUG",
320#endif
321 NULL
322 };
323 struct GNUNET_GETOPT_CommandLineOption options[] = {
324 GNUNET_GETOPT_OPTION_END
325 };
326 /* Run the run function as a new program */
327 ret =
328 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
329 "test-gns-simple-delegated-lookup", "nohelp", options, &run,
330 &ok);
331 if (ret != GNUNET_OK)
332 {
333 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
334 "`test-gns-simple-delegated-lookup': Failed with error code %d\n", ret);
335 }
336 return ok;
337}
338 276
339int 277int
340main (int argc, char *argv[]) 278main (int argc, char *argv[])
341{ 279{
342 int ret; 280 ok = 1;
343 281
344 GNUNET_log_setup ("test-gns-simple-lookup", 282 GNUNET_log_setup ("test-gns-simple-delegated-lookup",
345#if VERBOSE 283#if VERBOSE
346 "DEBUG", 284 "DEBUG",
347#else 285#else
348 "WARNING", 286 "WARNING",
349#endif 287#endif
350 NULL); 288 NULL);
351 ret = check (); 289
352 /** 290 GNUNET_TESTING_peer_run ("test-gns-simple-delegated-lookup", "test_gns_simple_lookup.conf", &do_check, NULL);
353 * Need to remove base directory, subdirectories taken care 291
354 * of by the testing framework. 292 return ok;
355 */
356 return ret;
357} 293}
358 294
359/* end of test_gns_twopeer.c */ 295/* end of test_gns_twopeer.c */
diff --git a/src/gns/test_gns_simple_get_authority.c b/src/gns/test_gns_simple_get_authority.c
index 867cb8de6..8d7df2c04 100644
--- a/src/gns/test_gns_simple_get_authority.c
+++ b/src/gns/test_gns_simple_get_authority.c
@@ -77,12 +77,6 @@ const struct GNUNET_CONFIGURATION_Handle *cfg;
77static void 77static void
78end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 78end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
79{ 79{
80 GNUNET_SCHEDULER_shutdown ();
81 ok = 1;
82}
83
84void end_badly_now ()
85{
86 if (NULL != gns_handle) 80 if (NULL != gns_handle)
87 { 81 {
88 GNUNET_GNS_disconnect(gns_handle); 82 GNUNET_GNS_disconnect(gns_handle);
@@ -94,7 +88,13 @@ void end_badly_now ()
94 GNUNET_NAMESTORE_disconnect (namestore_handle); 88 GNUNET_NAMESTORE_disconnect (namestore_handle);
95 namestore_handle = NULL; 89 namestore_handle = NULL;
96 } 90 }
91 GNUNET_break (0);
92 GNUNET_SCHEDULER_shutdown ();
93 ok = 1;
94}
97 95
96void end_badly_now ()
97{
98 GNUNET_SCHEDULER_cancel (die_task); 98 GNUNET_SCHEDULER_cancel (die_task);
99 die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); 99 die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
100} 100}
diff --git a/src/gns/test_gns_simple_lookup.c b/src/gns/test_gns_simple_lookup.c
index 2d708fde6..76df1d479 100644
--- a/src/gns/test_gns_simple_lookup.c
+++ b/src/gns/test_gns_simple_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_dns.h" 28#include "block_dns.h"
29#include "gnunet_signatures.h" 29#include "gnunet_signatures.h"
@@ -47,13 +47,6 @@
47 47
48/* Globals */ 48/* Globals */
49 49
50/**
51 * Directory to store temp data in, defined in config file
52 */
53static char *test_directory;
54
55static struct GNUNET_TESTING_PeerGroup *pg;
56
57/* Task handle to use to schedule test failure */ 50/* Task handle to use to schedule test failure */
58GNUNET_SCHEDULER_TaskIdentifier die_task; 51GNUNET_SCHEDULER_TaskIdentifier die_task;
59 52
@@ -67,30 +60,50 @@ static struct GNUNET_GNS_Handle *gns_handle;
67const struct GNUNET_CONFIGURATION_Handle *cfg; 60const struct GNUNET_CONFIGURATION_Handle *cfg;
68 61
69/** 62/**
70 * Check whether peers successfully shut down. 63 * Check if the get_handle is being used, if so stop the request. Either
64 * way, schedule the end_badly_cont function which actually shuts down the
65 * test.
71 */ 66 */
72void 67static void
73shutdown_callback (void *cls, const char *emsg) 68end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
74{ 69{
75 if (emsg != NULL) 70 if (NULL != gns_handle)
76 { 71 {
77 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error on shutdown! ret=%d\n", ok); 72 GNUNET_GNS_disconnect(gns_handle);
78 if (ok == 0) 73 gns_handle = NULL;
79 ok = 2;
80 } 74 }
81 75
82 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "done(ret=%d)!\n", ok); 76 if (NULL != namestore_handle)
77 {
78 GNUNET_NAMESTORE_disconnect (namestore_handle);
79 namestore_handle = NULL;
80 }
81 GNUNET_break (0);
82 GNUNET_SCHEDULER_shutdown ();
83 ok = 1;
83} 84}
84 85
86void end_badly_now ()
87{
88 GNUNET_SCHEDULER_cancel (die_task);
89 die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
90}
85 91
86static void 92static void
87on_lookup_result(void *cls, uint32_t rd_count, 93on_lookup_result(void *cls, uint32_t rd_count,
88 const struct GNUNET_NAMESTORE_RecordData *rd) 94 const struct GNUNET_NAMESTORE_RecordData *rd)
89{ 95{
96
90 struct in_addr a; 97 struct in_addr a;
91 int i; 98 int i;
92 char* addr; 99 char* addr;
93 100
101 if (GNUNET_SCHEDULER_NO_TASK != die_task)
102 {
103 GNUNET_SCHEDULER_cancel (die_task);
104 die_task = GNUNET_SCHEDULER_NO_TASK;
105 }
106
94 GNUNET_NAMESTORE_disconnect (namestore_handle); 107 GNUNET_NAMESTORE_disconnect (namestore_handle);
95 if (rd_count == 0) 108 if (rd_count == 0)
96 { 109 {
@@ -123,9 +136,11 @@ on_lookup_result(void *cls, uint32_t rd_count,
123 } 136 }
124 } 137 }
125 } 138 }
139
126 GNUNET_GNS_disconnect(gns_handle); 140 GNUNET_GNS_disconnect(gns_handle);
127 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Shutting down peer1!\n"); 141 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Shutting down peer!\n");
128 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); 142 GNUNET_SCHEDULER_shutdown ();
143
129} 144}
130 145
131 146
@@ -136,16 +151,12 @@ on_lookup_result(void *cls, uint32_t rd_count,
136static void 151static void
137commence_testing (void *cls, int32_t success, const char *emsg) 152commence_testing (void *cls, int32_t success, const char *emsg)
138{ 153{
139
140
141
142 gns_handle = GNUNET_GNS_connect(cfg); 154 gns_handle = GNUNET_GNS_connect(cfg);
143
144 if (NULL == gns_handle) 155 if (NULL == gns_handle)
145 { 156 {
146 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 157 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
147 "Failed to connect to GNS!\n"); 158 "Failed to connect to GNS!\n");
148 ok = 2; 159 end_badly_now();
149 } 160 }
150 161
151 GNUNET_GNS_lookup(gns_handle, TEST_DOMAIN, GNUNET_GNS_RECORD_A, 162 GNUNET_GNS_lookup(gns_handle, TEST_DOMAIN, GNUNET_GNS_RECORD_A,
@@ -154,53 +165,27 @@ commence_testing (void *cls, int32_t success, const char *emsg)
154 &on_lookup_result, TEST_DOMAIN); 165 &on_lookup_result, TEST_DOMAIN);
155} 166}
156 167
157
158/**
159 * Continuation for the GNUNET_DHT_get_stop call, so that we don't shut
160 * down the peers without freeing memory associated with GET request.
161 */
162static void
163end_badly_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
164{
165
166 if (pg != NULL)
167 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
168 GNUNET_SCHEDULER_cancel (die_task);
169}
170
171/**
172 * Check if the get_handle is being used, if so stop the request. Either
173 * way, schedule the end_badly_cont function which actually shuts down the
174 * test.
175 */
176static void
177end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
178{
179 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failing test with error: `%s'!\n",
180 (char *) cls);
181 GNUNET_SCHEDULER_add_now (&end_badly_cont, NULL);
182 ok = 1;
183}
184
185static void 168static void
186do_lookup(void *cls, const struct GNUNET_PeerIdentity *id, 169do_check (void *cls,
187 const struct GNUNET_CONFIGURATION_Handle *_cfg, 170 const struct GNUNET_CONFIGURATION_Handle *ccfg,
188 struct GNUNET_TESTING_Daemon *d, const char *emsg) 171 struct GNUNET_TESTING_Peer *peer)
189{ 172{
190 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded alice_pkey; 173 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded alice_pkey;
191 struct GNUNET_CRYPTO_RsaPrivateKey *alice_key; 174 struct GNUNET_CRYPTO_RsaPrivateKey *alice_key;
175 struct GNUNET_NAMESTORE_RecordData rd;
192 char* alice_keyfile; 176 char* alice_keyfile;
193 177 char* ip = TEST_IP;
194 cfg = _cfg; 178 struct in_addr *web = GNUNET_malloc(sizeof(struct in_addr));
195 179
196 GNUNET_SCHEDULER_cancel (die_task); 180 cfg = ccfg;
181 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
197 182
198 /* put records into namestore */ 183 /* put records into namestore */
199 namestore_handle = GNUNET_NAMESTORE_connect(cfg); 184 namestore_handle = GNUNET_NAMESTORE_connect(cfg);
200 if (NULL == namestore_handle) 185 if (NULL == namestore_handle)
201 { 186 {
202 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to connect to namestore\n"); 187 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to connect to namestore\n");
203 ok = -1; 188 end_badly_now () ;
204 return; 189 return;
205 } 190 }
206 191
@@ -209,21 +194,17 @@ do_lookup(void *cls, const struct GNUNET_PeerIdentity *id,
209 &alice_keyfile)) 194 &alice_keyfile))
210 { 195 {
211 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to get key from cfg\n"); 196 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to get key from cfg\n");
212 ok = -1; 197 end_badly_now () ;
213 return; 198 return;
214 } 199 }
215 200
216 alice_key = GNUNET_CRYPTO_rsa_key_create_from_file (alice_keyfile); 201 alice_key = GNUNET_CRYPTO_rsa_key_create_from_file (alice_keyfile);
217
218 GNUNET_CRYPTO_rsa_key_get_public (alice_key, &alice_pkey); 202 GNUNET_CRYPTO_rsa_key_get_public (alice_key, &alice_pkey);
219
220 GNUNET_free(alice_keyfile); 203 GNUNET_free(alice_keyfile);
221 204
222 struct GNUNET_NAMESTORE_RecordData rd; 205
223 char* ip = TEST_IP;
224 struct in_addr *web = GNUNET_malloc(sizeof(struct in_addr));
225 rd.expiration_time = UINT64_MAX; 206 rd.expiration_time = UINT64_MAX;
226 GNUNET_assert(1 == inet_pton (AF_INET, ip, web)); 207 GNUNET_assert (1 == inet_pton (AF_INET, ip, web));
227 rd.data_size = sizeof(struct in_addr); 208 rd.data_size = sizeof(struct in_addr);
228 rd.data = web; 209 rd.data = web;
229 rd.record_type = GNUNET_DNSPARSER_TYPE_A; 210 rd.record_type = GNUNET_DNSPARSER_TYPE_A;
@@ -235,72 +216,15 @@ do_lookup(void *cls, const struct GNUNET_PeerIdentity *id,
235 &rd, 216 &rd,
236 &commence_testing, 217 &commence_testing,
237 NULL); 218 NULL);
238 219
239 GNUNET_CRYPTO_rsa_key_free(alice_key); 220 GNUNET_CRYPTO_rsa_key_free(alice_key);
240 GNUNET_free(web); 221 GNUNET_free(web);
241
242}
243
244static void
245run (void *cls, char *const *args, const char *cfgfile,
246 const struct GNUNET_CONFIGURATION_Handle *c)
247{
248 cfg = c;
249 /* Get path from configuration file */
250 if (GNUNET_YES !=
251 GNUNET_CONFIGURATION_get_value_string (cfg, "paths", "servicehome",
252 &test_directory))
253 {
254 ok = 404;
255 return;
256 }
257
258
259 /* Set up a task to end testing if peer start fails */
260 die_task =
261 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly,
262 "didn't start all daemons in reasonable amount of time!!!");
263
264 /* Start alice */
265 pg = GNUNET_TESTING_daemons_start(cfg, 1, 1, 1, TIMEOUT,
266 NULL, NULL, &do_lookup, NULL,
267 NULL, NULL, NULL);
268}
269
270static int
271check ()
272{
273 int ret;
274
275 /* Arguments for GNUNET_PROGRAM_run */
276 char *const argv[] = { "test-gns-simple-lookup", /* Name to give running binary */
277 "-c",
278 "test_gns_simple_lookup.conf", /* Config file to use */
279#if VERBOSE
280 "-L", "DEBUG",
281#endif
282 NULL
283 };
284 struct GNUNET_GETOPT_CommandLineOption options[] = {
285 GNUNET_GETOPT_OPTION_END
286 };
287 /* Run the run function as a new program */
288 ret =
289 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
290 "test-gns-simple-lookup", "nohelp", options, &run,
291 &ok);
292 if (ret != GNUNET_OK)
293 {
294 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
295 "`test-gns-simple-lookup': Failed with error code %d\n", ret);
296 }
297 return ok;
298} 222}
299 223
300int 224int
301main (int argc, char *argv[]) 225main (int argc, char *argv[])
302{ 226{
303 int ret; 227 ok = 1;
304 228
305 GNUNET_log_setup ("test-gns-simple-lookup", 229 GNUNET_log_setup ("test-gns-simple-lookup",
306#if VERBOSE 230#if VERBOSE
@@ -309,12 +233,10 @@ main (int argc, char *argv[])
309 "WARNING", 233 "WARNING",
310#endif 234#endif
311 NULL); 235 NULL);
312 ret = check (); 236
313 /** 237 GNUNET_TESTING_peer_run ("test-gns-simple-lookup", "test_gns_simple_lookup.conf", &do_check, NULL);
314 * Need to remove base directory, subdirectories taken care 238
315 * of by the testing framework. 239 return ok;
316 */
317 return ret;
318} 240}
319 241
320/* end of test_gns_twopeer.c */ 242/* end of test_gns_simple_lookup.c */