aboutsummaryrefslogtreecommitdiff
path: root/src/gns
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2012-09-03 12:03:59 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2012-09-03 12:03:59 +0000
commit5d685d027f45c91933c5c7df4152243255560dfd (patch)
tree0435687f9666e6899e51aa149e97ebb1f3576b3e /src/gns
parent01cabc8235c680f414c996cb68758f7fdeaec29e (diff)
downloadgnunet-5d685d027f45c91933c5c7df4152243255560dfd.tar.gz
gnunet-5d685d027f45c91933c5c7df4152243255560dfd.zip
test
Diffstat (limited to 'src/gns')
-rw-r--r--src/gns/Makefile.am4
-rw-r--r--src/gns/test_gns_simple_get_authority.c201
-rw-r--r--src/gns/test_gns_simple_shorten.c4
3 files changed, 72 insertions, 137 deletions
diff --git a/src/gns/Makefile.am b/src/gns/Makefile.am
index 7b88769fb..f5c2771b7 100644
--- a/src/gns/Makefile.am
+++ b/src/gns/Makefile.am
@@ -199,12 +199,12 @@ test_gns_simple_get_authority_LDADD = \
199 $(top_builddir)/src/util/libgnunetutil.la \ 199 $(top_builddir)/src/util/libgnunetutil.la \
200 $(top_builddir)/src/namestore/libgnunetnamestore.la \ 200 $(top_builddir)/src/namestore/libgnunetnamestore.la \
201 $(top_builddir)/src/gns/libgnunetgns.la \ 201 $(top_builddir)/src/gns/libgnunetgns.la \
202 $(top_builddir)/src/testing_old/libgnunettesting_old.la 202 $(top_builddir)/src/testing/libgnunettesting.la
203test_gns_simple_get_authority_DEPENDENCIES = \ 203test_gns_simple_get_authority_DEPENDENCIES = \
204 $(top_builddir)/src/util/libgnunetutil.la \ 204 $(top_builddir)/src/util/libgnunetutil.la \
205 $(top_builddir)/src/namestore/libgnunetnamestore.la \ 205 $(top_builddir)/src/namestore/libgnunetnamestore.la \
206 $(top_builddir)/src/gns/libgnunetgns.la \ 206 $(top_builddir)/src/gns/libgnunetgns.la \
207 $(top_builddir)/src/testing_old/libgnunettesting_old.la 207 $(top_builddir)/src/testing/libgnunettesting.la
208 208
209 209
210test_gns_pseu_shorten_SOURCES = \ 210test_gns_pseu_shorten_SOURCES = \
diff --git a/src/gns/test_gns_simple_get_authority.c b/src/gns/test_gns_simple_get_authority.c
index 6a8184efd..867cb8de6 100644
--- a/src/gns/test_gns_simple_get_authority.c
+++ b/src/gns/test_gns_simple_get_authority.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"
@@ -56,13 +56,6 @@
56 56
57/* Globals */ 57/* Globals */
58 58
59/**
60 * Directory to store temp data in, defined in config file
61 */
62static char *test_directory;
63
64static struct GNUNET_TESTING_PeerGroup *pg;
65
66/* Task handle to use to schedule test failure */ 59/* Task handle to use to schedule test failure */
67GNUNET_SCHEDULER_TaskIdentifier die_task; 60GNUNET_SCHEDULER_TaskIdentifier die_task;
68 61
@@ -75,35 +68,56 @@ static struct GNUNET_GNS_Handle *gns_handle;
75 68
76const struct GNUNET_CONFIGURATION_Handle *cfg; 69const struct GNUNET_CONFIGURATION_Handle *cfg;
77 70
71
78/** 72/**
79 * Check whether peers successfully shut down. 73 * Check if the get_handle is being used, if so stop the request. Either
74 * way, schedule the end_badly_cont function which actually shuts down the
75 * test.
80 */ 76 */
81static void 77static void
82shutdown_callback (void *cls, const char *emsg) 78end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
79{
80 GNUNET_SCHEDULER_shutdown ();
81 ok = 1;
82}
83
84void end_badly_now ()
83{ 85{
84 if (emsg != NULL) 86 if (NULL != gns_handle)
87 {
88 GNUNET_GNS_disconnect(gns_handle);
89 gns_handle = NULL;
90 }
91
92 if (NULL != namestore_handle)
85 { 93 {
86 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error on shutdown! ret=%d\n", ok); 94 GNUNET_NAMESTORE_disconnect (namestore_handle);
87 if (ok == 0) 95 namestore_handle = NULL;
88 ok = 2;
89 } 96 }
90 97
91 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "done(ret=%d)!\n", ok); 98 GNUNET_SCHEDULER_cancel (die_task);
99 die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
92} 100}
93 101
102
94/** 103/**
95 * Called when gns_get_authority finishes 104 * Called when gns_get_authority finishes
96 */ 105 */
97static void 106static void
98process_auth_result(void* cls, const char* aname) 107process_auth_result(void* cls, const char* aname)
99{ 108{
100 GNUNET_GNS_disconnect(gns_handle);
101 109
110 GNUNET_GNS_disconnect(gns_handle);
102 111
103 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 112 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
104 "disconnecting from namestore\n"); 113 "Disconnecting from namestore\n");
105 GNUNET_NAMESTORE_disconnect (namestore_handle); 114 GNUNET_NAMESTORE_disconnect (namestore_handle);
106 ok = 0; 115
116 if (GNUNET_SCHEDULER_NO_TASK != die_task)
117 {
118 GNUNET_SCHEDULER_cancel (die_task);
119 die_task = GNUNET_SCHEDULER_NO_TASK;
120 }
107 121
108 if (aname == NULL) 122 if (aname == NULL)
109 { 123 {
@@ -122,15 +136,20 @@ process_auth_result(void* cls, const char* aname)
122 TEST_EXPECTED_RESULT, aname); 136 TEST_EXPECTED_RESULT, aname);
123 ok = 1; 137 ok = 1;
124 } 138 }
139 else
140 {
141 ok = 0;
142 }
125 143
126 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "get_authority test finished!\n"); 144 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "get_authority test finished!\n");
127 145
128 } 146 }
129 147
130 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Shutting down peer1!\n"); 148 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Shutting down peer1!\n");
131 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); 149 GNUNET_SCHEDULER_shutdown ();
132} 150}
133 151
152
134/** 153/**
135 * Function scheduled to be run on the successful start of services 154 * Function scheduled to be run on the successful start of services
136 * tries to shorten the name TEST_DOMAIN using gns 155 * tries to shorten the name TEST_DOMAIN using gns
@@ -138,57 +157,27 @@ process_auth_result(void* cls, const char* aname)
138static void 157static void
139commence_testing (void *cls, int32_t success, const char *emsg) 158commence_testing (void *cls, int32_t success, const char *emsg)
140{ 159{
141 160
142
143
144 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 161 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
145 "connecting to gns\n"); 162 "Connecting to gns\n");
146 gns_handle = GNUNET_GNS_connect(cfg); 163 gns_handle = GNUNET_GNS_connect(cfg);
147
148 if (NULL == gns_handle) 164 if (NULL == gns_handle)
149 { 165 {
150 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 166 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
151 "failed to connect to gns\n"); 167 "Failed to connect to gns\n");
152 ok = 1; 168 end_badly_now();
153 return; 169 return;
154 } 170 }
155 171
156 GNUNET_GNS_get_authority(gns_handle, TEST_DOMAIN, &process_auth_result, 172 GNUNET_GNS_get_authority(gns_handle, TEST_DOMAIN, &process_auth_result,
157 TEST_DOMAIN); 173 TEST_DOMAIN);
158
159} 174}
160 175
161/**
162 * Continuation for the GNUNET_DHT_get_stop call, so that we don't shut
163 * down the peers without freeing memory associated with GET request.
164 */
165static void
166end_badly_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
167{
168 176
169 if (pg != NULL)
170 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
171 GNUNET_SCHEDULER_cancel (die_task);
172}
173 177
174/** 178void do_check (void *cls,
175 * Check if the get_handle is being used, if so stop the request. Either 179 const struct GNUNET_CONFIGURATION_Handle *ccfg,
176 * way, schedule the end_badly_cont function which actually shuts down the 180 struct GNUNET_TESTING_Peer *peer)
177 * test.
178 */
179static void
180end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
181{
182 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failing test with error: `%s'!\n",
183 (char *) cls);
184 GNUNET_SCHEDULER_add_now (&end_badly_cont, NULL);
185 ok = 1;
186}
187
188static void
189do_shorten(void *cls, const struct GNUNET_PeerIdentity *id,
190 const struct GNUNET_CONFIGURATION_Handle *_cfg,
191 struct GNUNET_TESTING_Daemon *d, const char *emsg)
192{ 181{
193 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded our_pkey; 182 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded our_pkey;
194 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded alice_pkey; 183 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded alice_pkey;
@@ -201,16 +190,16 @@ do_shorten(void *cls, const struct GNUNET_PeerIdentity *id,
201 struct GNUNET_CRYPTO_RsaSignature *sig; 190 struct GNUNET_CRYPTO_RsaSignature *sig;
202 char* our_keyfile; 191 char* our_keyfile;
203 192
204 cfg = _cfg; 193 cfg = ccfg;
205 194 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
206 GNUNET_SCHEDULER_cancel (die_task); 195 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Running test\n");
207 196
208 /* put records into namestore */ 197 /* put records into namestore */
209 namestore_handle = GNUNET_NAMESTORE_connect(cfg); 198 namestore_handle = GNUNET_NAMESTORE_connect(cfg);
210 if (NULL == namestore_handle) 199 if (NULL == namestore_handle)
211 { 200 {
212 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to connect to namestore\n"); 201 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to connect to namestore\n");
213 ok = -1; 202 end_badly_now();
214 return; 203 return;
215 } 204 }
216 205
@@ -219,7 +208,7 @@ do_shorten(void *cls, const struct GNUNET_PeerIdentity *id,
219 &our_keyfile)) 208 &our_keyfile))
220 { 209 {
221 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to get key from cfg\n"); 210 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to get key from cfg\n");
222 ok = -1; 211 end_badly_now();
223 return; 212 return;
224 } 213 }
225 214
@@ -228,24 +217,24 @@ do_shorten(void *cls, const struct GNUNET_PeerIdentity *id,
228 217
229 bob_key = GNUNET_CRYPTO_rsa_key_create_from_file (KEYFILE_BOB); 218 bob_key = GNUNET_CRYPTO_rsa_key_create_from_file (KEYFILE_BOB);
230 alice_key = GNUNET_CRYPTO_rsa_key_create_from_file (KEYFILE_ALICE); 219 alice_key = GNUNET_CRYPTO_rsa_key_create_from_file (KEYFILE_ALICE);
231 220
232 GNUNET_CRYPTO_rsa_key_get_public (our_key, &our_pkey); 221 GNUNET_CRYPTO_rsa_key_get_public (our_key, &our_pkey);
233 GNUNET_CRYPTO_rsa_key_get_public (alice_key, &alice_pkey); 222 GNUNET_CRYPTO_rsa_key_get_public (alice_key, &alice_pkey);
234 GNUNET_CRYPTO_rsa_key_get_public (bob_key, &bob_pkey); 223 GNUNET_CRYPTO_rsa_key_get_public (bob_key, &bob_pkey);
235 224
236 struct GNUNET_NAMESTORE_RecordData rd; 225 struct GNUNET_NAMESTORE_RecordData rd;
237 char* ip = TEST_IP; 226 char* ip = TEST_IP;
238 struct in_addr *web = GNUNET_malloc(sizeof(struct in_addr)); 227 struct in_addr *web = GNUNET_malloc (sizeof(struct in_addr));
239 rd.expiration_time = UINT64_MAX; 228 rd.expiration_time = UINT64_MAX;
240 GNUNET_assert(1 == inet_pton (AF_INET, ip, web)); 229 GNUNET_assert (1 == inet_pton (AF_INET, ip, web));
241 230
242 GNUNET_CRYPTO_short_hash(&bob_pkey, sizeof(bob_pkey), &bob_hash); 231 GNUNET_CRYPTO_short_hash(&bob_pkey, sizeof(bob_pkey), &bob_hash);
243 232
244 rd.data_size = sizeof(struct GNUNET_CRYPTO_ShortHashCode); 233 rd.data_size = sizeof(struct GNUNET_CRYPTO_ShortHashCode);
245 rd.data = &bob_hash; 234 rd.data = &bob_hash;
246 rd.record_type = GNUNET_GNS_RECORD_PKEY; 235 rd.record_type = GNUNET_GNS_RECORD_PKEY;
247 rd.flags = GNUNET_NAMESTORE_RF_AUTHORITY; 236 rd.flags = GNUNET_NAMESTORE_RF_AUTHORITY;
248 237
249 /* put bob into our zone */ 238 /* put bob into our zone */
250 GNUNET_NAMESTORE_record_create (namestore_handle, 239 GNUNET_NAMESTORE_record_create (namestore_handle,
251 our_key, 240 our_key,
@@ -253,7 +242,7 @@ do_shorten(void *cls, const struct GNUNET_PeerIdentity *id,
253 &rd, 242 &rd,
254 NULL, 243 NULL,
255 NULL); 244 NULL);
256 245
257 /* put alice into bobs zone */ 246 /* put alice into bobs zone */
258 GNUNET_CRYPTO_short_hash(&alice_pkey, sizeof(alice_pkey), &alice_hash); 247 GNUNET_CRYPTO_short_hash(&alice_pkey, sizeof(alice_pkey), &alice_hash);
259 rd.data = &alice_hash; 248 rd.data = &alice_hash;
@@ -270,6 +259,8 @@ do_shorten(void *cls, const struct GNUNET_PeerIdentity *id,
270 NULL, 259 NULL,
271 NULL); 260 NULL);
272 261
262 GNUNET_free (sig);
263
273 /* put www A record and PSEU into alice's zone */ 264 /* put www A record and PSEU into alice's zone */
274 265
275 rd.data_size = sizeof(struct in_addr); 266 rd.data_size = sizeof(struct in_addr);
@@ -306,86 +297,30 @@ do_shorten(void *cls, const struct GNUNET_PeerIdentity *id,
306 &commence_testing, 297 &commence_testing,
307 NULL); 298 NULL);
308 299
309 GNUNET_free(sig); 300 GNUNET_free (web);
301 GNUNET_free (sig);
310 GNUNET_CRYPTO_rsa_key_free (alice_key); 302 GNUNET_CRYPTO_rsa_key_free (alice_key);
311 GNUNET_CRYPTO_rsa_key_free (bob_key); 303 GNUNET_CRYPTO_rsa_key_free (bob_key);
312 GNUNET_CRYPTO_rsa_key_free (our_key); 304 GNUNET_CRYPTO_rsa_key_free (our_key);
313} 305}
314 306
315static void
316run (void *cls, char *const *args, const char *cfgfile,
317 const struct GNUNET_CONFIGURATION_Handle *c)
318{
319 cfg = c;
320 /* Get path from configuration file */
321 if (GNUNET_YES !=
322 GNUNET_CONFIGURATION_get_value_string (cfg, "paths", "servicehome",
323 &test_directory))
324 {
325 ok = 404;
326 return;
327 }
328
329
330 /* Set up a task to end testing if peer start fails */
331 die_task =
332 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly,
333 "didn't start all daemons in reasonable amount of time!!!");
334
335 /* Start alice */
336 pg = GNUNET_TESTING_daemons_start(cfg, 1, 1, 1, TIMEOUT,
337 NULL, NULL, &do_shorten, NULL,
338 NULL, NULL, NULL);
339}
340
341static int
342check ()
343{
344 int ret;
345
346 /* Arguments for GNUNET_PROGRAM_run */
347 char *const argv[] = { "test-gns-simple-get-authority", /* Name to give running binary */
348 "-c",
349 "test_gns_simple_lookup.conf", /* Config file to use */
350#if VERBOSE
351 "-L", "DEBUG",
352#endif
353 NULL
354 };
355 struct GNUNET_GETOPT_CommandLineOption options[] = {
356 GNUNET_GETOPT_OPTION_END
357 };
358 /* Run the run function as a new program */
359 ret =
360 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
361 "test-gns-simple-get-authority", "nohelp", options, &run,
362 &ok);
363 if (ret != GNUNET_OK)
364 {
365 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
366 "`test-gns-simple-get-authority': Failed with error code %d\n", ret);
367 }
368 return ok;
369}
370
371int 307int
372main (int argc, char *argv[]) 308main (int argc, char *argv[])
373{ 309{
374 int ret; 310 ok = 1;
375 311
376 GNUNET_log_setup ("test-gns-simple-lookup", 312 GNUNET_log_setup ("test-gns-simple-get-authority",
377#if VERBOSE 313#if VERBOSE
378 "DEBUG", 314 "DEBUG",
379#else 315#else
380 "WARNING", 316 "WARNING",
381#endif 317#endif
382 NULL); 318 NULL);
383 ret = check (); 319
384 /** 320 GNUNET_TESTING_peer_run ("test-gns-simple-get-authority", "test_gns_simple_lookup.conf", &do_check, NULL);
385 * Need to remove base directory, subdirectories taken care 321
386 * of by the testing framework. 322 return ok;
387 */
388 return ret;
389} 323}
390 324
391/* end of test_gns_twopeer.c */ 325/* end of test-gns-simple-get-authority.c */
326
diff --git a/src/gns/test_gns_simple_shorten.c b/src/gns/test_gns_simple_shorten.c
index e8433d274..e8612520d 100644
--- a/src/gns/test_gns_simple_shorten.c
+++ b/src/gns/test_gns_simple_shorten.c
@@ -153,7 +153,7 @@ commence_testing (void *cls, int32_t success, const char *emsg)
153 { 153 {
154 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 154 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
155 "Failed to connect to gns\n"); 155 "Failed to connect to gns\n");
156 ok = 1; 156 end_badly_now ();
157 return; 157 return;
158 } 158 }
159 159
@@ -344,4 +344,4 @@ main (int argc, char *argv[])
344 return ok; 344 return ok;
345} 345}
346 346
347/* end of test_gns_simple_shorten.c */ 347/* end of test_gns_twopeer.c */