aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-10-28 07:45:25 +0000
committerChristian Grothoff <christian@grothoff.org>2012-10-28 07:45:25 +0000
commit66bdbba886a79c557a81ee1565800eff056cdcc4 (patch)
tree756e94e29bcfd82a7f39d2c2dffa4a0225480a93 /src
parent74e3276f887c7852a1359d39c9c7c57b856ee23e (diff)
downloadgnunet-66bdbba886a79c557a81ee1565800eff056cdcc4.tar.gz
gnunet-66bdbba886a79c557a81ee1565800eff056cdcc4.zip
-code cleanup
Diffstat (limited to 'src')
-rw-r--r--src/gns/gnunet-gns-proxy.c16
-rw-r--r--src/gns/test_gns_ns_lookup.c143
2 files changed, 75 insertions, 84 deletions
diff --git a/src/gns/gnunet-gns-proxy.c b/src/gns/gnunet-gns-proxy.c
index fb7b80e16..7b783787b 100644
--- a/src/gns/gnunet-gns-proxy.c
+++ b/src/gns/gnunet-gns-proxy.c
@@ -484,22 +484,6 @@ is_tld (const char* name, const char* tld)
484} 484}
485 485
486 486
487/**
488 * convert integer to string representation
489 *
490 * @param i integer
491 * @return the character
492 */
493static char
494i_to_hexchar (unsigned char i)
495{
496 static char hexmap[] = "0123456789abcdef";
497
498 GNUNET_assert (sizeof (hexmap) > (i & 15));
499 return hexmap[i & 15];
500}
501
502
503static int 487static int
504con_post_data_iter (void *cls, 488con_post_data_iter (void *cls,
505 enum MHD_ValueKind kind, 489 enum MHD_ValueKind kind,
diff --git a/src/gns/test_gns_ns_lookup.c b/src/gns/test_gns_ns_lookup.c
index d0c00613e..9457dfae5 100644
--- a/src/gns/test_gns_ns_lookup.c
+++ b/src/gns/test_gns_ns_lookup.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 (C) 2009 Christian Grothoff (and other contributing authors) 3 (C) 2012 Christian Grothoff (and other contributing authors)
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -20,7 +20,7 @@
20/** 20/**
21 * @file gns/test_gns_ns_lookup.c 21 * @file gns/test_gns_ns_lookup.c
22 * @brief base testcase for testing a local GNS record lookup through NS 22 * @brief base testcase for testing a local GNS record lookup through NS
23 * 23 * @author Martin Schanzenbach
24 */ 24 */
25#include "platform.h" 25#include "platform.h"
26#include "gnunet_testing_lib-new.h" 26#include "gnunet_testing_lib-new.h"
@@ -35,9 +35,6 @@
35/* Timeout for entire testcase */ 35/* Timeout for entire testcase */
36#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 20) 36#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 20)
37 37
38/* If number of peers not in config file, use this number */
39#define DEFAULT_NUM_PEERS 2
40
41/* test records to resolve */ 38/* test records to resolve */
42#define TEST_DOMAIN "www.homepage.gads" 39#define TEST_DOMAIN "www.homepage.gads"
43#define TEST_DOMAIN_ALT "homepage.gads" 40#define TEST_DOMAIN_ALT "homepage.gads"
@@ -48,11 +45,8 @@
48#define TEST_RECORD_NAME "homepage" 45#define TEST_RECORD_NAME "homepage"
49#define TEST_RECORD_NS "gnunet.org" 46#define TEST_RECORD_NS "gnunet.org"
50 47
51/* Globals */
52
53
54/* Task handle to use to schedule test failure */ 48/* Task handle to use to schedule test failure */
55GNUNET_SCHEDULER_TaskIdentifier die_task; 49static GNUNET_SCHEDULER_TaskIdentifier die_task;
56 50
57/* Global return value (0 for success, anything else for failure) */ 51/* Global return value (0 for success, anything else for failure) */
58static int ok; 52static int ok;
@@ -65,7 +59,10 @@ static struct GNUNET_GNS_Handle *gns_handle;
65 59
66static struct GNUNET_RESOLVER_RequestHandle *resolver_handle; 60static struct GNUNET_RESOLVER_RequestHandle *resolver_handle;
67 61
68const struct GNUNET_CONFIGURATION_Handle *cfg; 62static const struct GNUNET_CONFIGURATION_Handle *cfg;
63
64static struct GNS_LookupRequest *lr;
65
69 66
70/** 67/**
71 * Check if the get_handle is being used, if so stop the request. Either 68 * Check if the get_handle is being used, if so stop the request. Either
@@ -76,19 +73,22 @@ static void
76end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 73end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
77{ 74{
78 die_task = GNUNET_SCHEDULER_NO_TASK; 75 die_task = GNUNET_SCHEDULER_NO_TASK;
79 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Test failed, shutting down...\n"); 76 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test failed, shutting down...\n");
77 if (NULL != lr)
78 {
79 GNUNET_GNS_cancel_lookup_request (lr);
80 lr = NULL;
81 }
80 if (NULL != resolver_handle) 82 if (NULL != resolver_handle)
81 { 83 {
82 GNUNET_RESOLVER_request_cancel (resolver_handle); 84 GNUNET_RESOLVER_request_cancel (resolver_handle);
83 resolver_handle = NULL; 85 resolver_handle = NULL;
84 } 86 }
85
86 if (NULL != gns_handle) 87 if (NULL != gns_handle)
87 { 88 {
88 GNUNET_GNS_disconnect(gns_handle); 89 GNUNET_GNS_disconnect(gns_handle);
89 gns_handle = NULL; 90 gns_handle = NULL;
90 } 91 }
91
92 if (NULL != namestore_handle) 92 if (NULL != namestore_handle)
93 { 93 {
94 GNUNET_NAMESTORE_disconnect (namestore_handle); 94 GNUNET_NAMESTORE_disconnect (namestore_handle);
@@ -99,6 +99,7 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
99 ok = 1; 99 ok = 1;
100} 100}
101 101
102
102static void 103static void
103end_badly_now () 104end_badly_now ()
104{ 105{
@@ -106,10 +107,12 @@ end_badly_now ()
106 die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); 107 die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
107} 108}
108 109
110
109static void 111static void
110end_now (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 112end_now (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
111{ 113{
112 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Test successful, shutting down...\n"); 114 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
115 "Test successful, shutting down...\n");
113 if (GNUNET_SCHEDULER_NO_TASK != die_task) 116 if (GNUNET_SCHEDULER_NO_TASK != die_task)
114 { 117 {
115 GNUNET_SCHEDULER_cancel (die_task); 118 GNUNET_SCHEDULER_cancel (die_task);
@@ -120,13 +123,11 @@ end_now (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
120 GNUNET_RESOLVER_request_cancel (resolver_handle); 123 GNUNET_RESOLVER_request_cancel (resolver_handle);
121 resolver_handle = NULL; 124 resolver_handle = NULL;
122 } 125 }
123
124 if (NULL != gns_handle) 126 if (NULL != gns_handle)
125 { 127 {
126 GNUNET_GNS_disconnect(gns_handle); 128 GNUNET_GNS_disconnect(gns_handle);
127 gns_handle = NULL; 129 gns_handle = NULL;
128 } 130 }
129
130 if (NULL != namestore_handle) 131 if (NULL != namestore_handle)
131 { 132 {
132 GNUNET_NAMESTORE_disconnect (namestore_handle); 133 GNUNET_NAMESTORE_disconnect (namestore_handle);
@@ -136,14 +137,17 @@ end_now (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
136 GNUNET_SCHEDULER_shutdown (); 137 GNUNET_SCHEDULER_shutdown ();
137} 138}
138 139
140
139static void 141static void
140on_lookup_result_alt2 (void *cls, uint32_t rd_count, 142on_lookup_result_alt2 (void *cls, uint32_t rd_count,
141 const struct GNUNET_NAMESTORE_RecordData *rd) 143 const struct GNUNET_NAMESTORE_RecordData *rd)
142{ 144{
143 struct in_addr a; 145 struct in_addr a;
144 int i; 146 uint32_t i;
145 char* addr; 147 char* addr;
146 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received alternative results 2\n"); 148
149 lr = NULL;
150 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received alternative results 2\n");
147 if (rd_count == 0) 151 if (rd_count == 0)
148 { 152 {
149 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 153 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -178,13 +182,16 @@ on_lookup_result_alt2 (void *cls, uint32_t rd_count,
178 GNUNET_SCHEDULER_add_now (&end_now, NULL); 182 GNUNET_SCHEDULER_add_now (&end_now, NULL);
179} 183}
180 184
185
181static void 186static void
182on_lookup_result_alt (void *cls, uint32_t rd_count, 187on_lookup_result_alt (void *cls, uint32_t rd_count,
183 const struct GNUNET_NAMESTORE_RecordData *rd) 188 const struct GNUNET_NAMESTORE_RecordData *rd)
184{ 189{
185 struct in_addr a; 190 struct in_addr a;
186 int i; 191 uint32_t i;
187 char* addr; 192 char* addr;
193
194 lr = NULL;
188 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received alternative results\n"); 195 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received alternative results\n");
189 if (rd_count == 0) 196 if (rd_count == 0)
190 { 197 {
@@ -218,19 +225,22 @@ on_lookup_result_alt (void *cls, uint32_t rd_count,
218 } 225 }
219 } 226 }
220 227
221 GNUNET_GNS_lookup(gns_handle, TEST_DOMAIN_ALT2, GNUNET_GNS_RECORD_A, 228 lr = GNUNET_GNS_lookup (gns_handle, TEST_DOMAIN_ALT2, GNUNET_GNS_RECORD_A,
222 GNUNET_YES, 229 GNUNET_YES,
223 NULL, 230 NULL,
224 &on_lookup_result_alt2, TEST_DOMAIN_ALT2); 231 &on_lookup_result_alt2, TEST_DOMAIN_ALT2);
225} 232}
226 233
234
227static void 235static void
228on_lookup_result(void *cls, uint32_t rd_count, 236on_lookup_result(void *cls, uint32_t rd_count,
229 const struct GNUNET_NAMESTORE_RecordData *rd) 237 const struct GNUNET_NAMESTORE_RecordData *rd)
230{ 238{
231 struct in_addr a; 239 struct in_addr a;
232 int i; 240 uint32_t i;
233 char* addr; 241 char* addr;
242
243 lr = NULL;
234 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received results\n"); 244 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received results\n");
235 if (rd_count == 0) 245 if (rd_count == 0)
236 { 246 {
@@ -264,20 +274,20 @@ on_lookup_result(void *cls, uint32_t rd_count,
264 } 274 }
265 } 275 }
266 276
267 GNUNET_GNS_lookup(gns_handle, TEST_DOMAIN_ALT, GNUNET_GNS_RECORD_A, 277 lr = GNUNET_GNS_lookup (gns_handle, TEST_DOMAIN_ALT, GNUNET_GNS_RECORD_A,
268 GNUNET_YES, 278 GNUNET_YES,
269 NULL, 279 NULL,
270 &on_lookup_result_alt, TEST_DOMAIN_ALT); 280 &on_lookup_result_alt, TEST_DOMAIN_ALT);
271} 281}
272 282
273 283
274static void 284static void
275start_lookup (void) 285start_lookup ()
276{ 286{
277 GNUNET_NAMESTORE_disconnect (namestore_handle); 287 GNUNET_NAMESTORE_disconnect (namestore_handle);
278 namestore_handle = NULL; 288 namestore_handle = NULL;
279 289
280 gns_handle = GNUNET_GNS_connect(cfg); 290 gns_handle = GNUNET_GNS_connect (cfg);
281 if (NULL == gns_handle) 291 if (NULL == gns_handle)
282 { 292 {
283 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 293 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -286,10 +296,10 @@ start_lookup (void)
286 return; 296 return;
287 } 297 }
288 298
289 GNUNET_GNS_lookup (gns_handle, TEST_DOMAIN, GNUNET_GNS_RECORD_A, 299 lr = GNUNET_GNS_lookup (gns_handle, TEST_DOMAIN, GNUNET_GNS_RECORD_A,
290 GNUNET_YES, 300 GNUNET_YES,
291 NULL, 301 NULL,
292 &on_lookup_result, TEST_DOMAIN); 302 &on_lookup_result, TEST_DOMAIN);
293} 303}
294 304
295 305
@@ -299,7 +309,7 @@ handle_dns_test (void *cls,
299 socklen_t addrlen) 309 socklen_t addrlen)
300{ 310{
301 struct sockaddr_in* sai; 311 struct sockaddr_in* sai;
302 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received DNS response\n"); 312
303 resolver_handle = NULL; 313 resolver_handle = NULL;
304 if (NULL == addr) 314 if (NULL == addr)
305 { 315 {
@@ -313,26 +323,27 @@ handle_dns_test (void *cls,
313 GNUNET_SCHEDULER_add_now (&end_now, NULL); 323 GNUNET_SCHEDULER_add_now (&end_now, NULL);
314 return; 324 return;
315 } 325 }
316 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Starting lookup \n"); 326 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
327 "Starting lookup \n");
317 start_lookup (); 328 start_lookup ();
318 return; 329 return;
319 } 330 }
320 331
332 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
333 "Received DNS response\n");
321 if (addrlen == sizeof (struct sockaddr_in)) 334 if (addrlen == sizeof (struct sockaddr_in))
322 { 335 {
323 sai = (struct sockaddr_in*) addr; 336 sai = (struct sockaddr_in*) addr;
324 if (0 == strcmp (TEST_IP, inet_ntoa (sai->sin_addr))) 337 if (0 == strcmp (TEST_IP, inet_ntoa (sai->sin_addr)))
325 { 338 {
326 resolver_working = GNUNET_YES; 339 resolver_working = GNUNET_YES;
327 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Resolver is working\n"); 340 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
341 "Resolver is working\n");
328 } 342 }
329
330 } 343 }
331} 344}
332 345
333 346
334
335
336/** 347/**
337 * Function scheduled to be run on the successful start of services 348 * Function scheduled to be run on the successful start of services
338 * tries to look up the dns record for TEST_DOMAIN 349 * tries to look up the dns record for TEST_DOMAIN
@@ -341,7 +352,8 @@ static void
341commence_testing (void *cls, int32_t success, const char *emsg) 352commence_testing (void *cls, int32_t success, const char *emsg)
342{ 353{
343 resolver_working = GNUNET_NO; 354 resolver_working = GNUNET_NO;
344 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Resolving NS record\n"); 355 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
356 "Resolving NS record\n");
345 GNUNET_RESOLVER_connect (cfg); 357 GNUNET_RESOLVER_connect (cfg);
346 resolver_handle = GNUNET_RESOLVER_ip_get (TEST_RECORD_NS, 358 resolver_handle = GNUNET_RESOLVER_ip_get (TEST_RECORD_NS,
347 AF_INET, 359 AF_INET,
@@ -350,6 +362,7 @@ commence_testing (void *cls, int32_t success, const char *emsg)
350 NULL); 362 NULL);
351} 363}
352 364
365
353static void 366static void
354do_check (void *cls, 367do_check (void *cls,
355 const struct GNUNET_CONFIGURATION_Handle *ccfg, 368 const struct GNUNET_CONFIGURATION_Handle *ccfg,
@@ -358,57 +371,56 @@ do_check (void *cls,
358 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded alice_pkey; 371 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded alice_pkey;
359 struct GNUNET_CRYPTO_RsaPrivateKey *alice_key; 372 struct GNUNET_CRYPTO_RsaPrivateKey *alice_key;
360 char* alice_keyfile; 373 char* alice_keyfile;
374 struct GNUNET_NAMESTORE_RecordData rd;
375 const char* ip = TEST_IP_NS;
376 struct in_addr ns;
361 377
362 cfg = ccfg; 378 cfg = ccfg;
363 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); 379 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
364 380
365 /* put records into namestore */ 381 /* put records into namestore */
366 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Connecting to namestore\n");
367 namestore_handle = GNUNET_NAMESTORE_connect(cfg); 382 namestore_handle = GNUNET_NAMESTORE_connect(cfg);
368 if (NULL == namestore_handle) 383 if (NULL == namestore_handle)
369 { 384 {
370 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to connect to namestore\n"); 385 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
386 "Failed to connect to namestore\n");
371 end_badly_now (); 387 end_badly_now ();
372 return; 388 return;
373 } 389 }
374 390
375 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns", 391 if (GNUNET_OK !=
376 "ZONEKEY", 392 GNUNET_CONFIGURATION_get_value_filename (cfg, "gns",
377 &alice_keyfile)) 393 "ZONEKEY",
394 &alice_keyfile))
378 { 395 {
379 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to get key from cfg\n"); 396 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
397 "Failed to get key from cfg\n");
380 end_badly_now (); 398 end_badly_now ();
381 return; 399 return;
382 } 400 }
383 401
384 alice_key = GNUNET_CRYPTO_rsa_key_create_from_file (alice_keyfile); 402 alice_key = GNUNET_CRYPTO_rsa_key_create_from_file (alice_keyfile);
385
386 GNUNET_CRYPTO_rsa_key_get_public (alice_key, &alice_pkey); 403 GNUNET_CRYPTO_rsa_key_get_public (alice_key, &alice_pkey);
387
388 GNUNET_free(alice_keyfile); 404 GNUNET_free(alice_keyfile);
389 405
390 struct GNUNET_NAMESTORE_RecordData rd;
391 char* ip = TEST_IP_NS;
392 struct in_addr *ns = GNUNET_malloc(sizeof(struct in_addr));
393 rd.expiration_time = UINT64_MAX; 406 rd.expiration_time = UINT64_MAX;
394 GNUNET_assert(1 == inet_pton (AF_INET, ip, ns)); 407 GNUNET_assert(1 == inet_pton (AF_INET, ip, &ns));
395 rd.data_size = sizeof(struct in_addr); 408 rd.data_size = sizeof(struct in_addr);
396 rd.data = ns; 409 rd.data = &ns;
397 rd.record_type = GNUNET_DNSPARSER_TYPE_A; 410 rd.record_type = GNUNET_DNSPARSER_TYPE_A;
398 rd.flags = GNUNET_NAMESTORE_RF_AUTHORITY; 411 rd.flags = GNUNET_NAMESTORE_RF_AUTHORITY;
399 412
400 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Creating records\n"); 413 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
414 "Creating records\n");
401 GNUNET_NAMESTORE_record_create (namestore_handle, 415 GNUNET_NAMESTORE_record_create (namestore_handle,
402 alice_key, 416 alice_key,
403 TEST_RECORD_NAME, 417 TEST_RECORD_NAME,
404 &rd, 418 &rd,
405 NULL, 419 NULL,
406 NULL); 420 NULL);
407
408 rd.data_size = strlen (TEST_RECORD_NS); 421 rd.data_size = strlen (TEST_RECORD_NS);
409 rd.data = TEST_RECORD_NS; 422 rd.data = TEST_RECORD_NS;
410 rd.record_type = GNUNET_GNS_RECORD_NS; 423 rd.record_type = GNUNET_GNS_RECORD_NS;
411
412 GNUNET_NAMESTORE_record_create (namestore_handle, 424 GNUNET_NAMESTORE_record_create (namestore_handle,
413 alice_key, 425 alice_key,
414 TEST_RECORD_NAME, 426 TEST_RECORD_NAME,
@@ -416,24 +428,19 @@ do_check (void *cls,
416 &commence_testing, 428 &commence_testing,
417 NULL); 429 NULL);
418 GNUNET_CRYPTO_rsa_key_free(alice_key); 430 GNUNET_CRYPTO_rsa_key_free(alice_key);
419 GNUNET_free(ns);
420
421} 431}
422 432
433
423int 434int
424main (int argc, char *argv[]) 435main (int argc, char *argv[])
425{ 436{
426 ok = 1; 437 ok = 1;
427
428 GNUNET_log_setup ("test-gns-simple-ns-lookup", 438 GNUNET_log_setup ("test-gns-simple-ns-lookup",
429#if VERBOSE
430 "DEBUG",
431#else
432 "WARNING", 439 "WARNING",
433#endif
434 NULL); 440 NULL);
435 GNUNET_TESTING_peer_run ("test-gns-simple-ns-lookup", "test_gns_simple_lookup.conf", &do_check, NULL); 441 GNUNET_TESTING_peer_run ("test-gns-simple-ns-lookup", "test_gns_simple_lookup.conf",
442 &do_check, NULL);
436 return ok; 443 return ok;
437} 444}
438 445
439/* end of test_gns_simple_ns_lookup.c */ 446/* end of test_gns_ns_lookup.c */