aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMartin Schanzenbach <mschanzenbach@posteo.de>2012-03-12 11:58:34 +0000
committerMartin Schanzenbach <mschanzenbach@posteo.de>2012-03-12 11:58:34 +0000
commit9e5c8d198154d018d7ad97efb579749c1625b2b4 (patch)
tree0b7cdf98292f606cc9da878a958194a79165051f /src
parentd656d0f85549e69a05490286b1ed5d7b06abede8 (diff)
downloadgnunet-9e5c8d198154d018d7ad97efb579749c1625b2b4.tar.gz
gnunet-9e5c8d198154d018d7ad97efb579749c1625b2b4.zip
-add get_athority test, fixes
Diffstat (limited to 'src')
-rw-r--r--src/gns/Makefile.am17
-rw-r--r--src/gns/gns_api.c2
-rw-r--r--src/gns/gnunet-service-gns.c9
-rw-r--r--src/gns/test_gns_simple_get_authority.c385
4 files changed, 408 insertions, 5 deletions
diff --git a/src/gns/Makefile.am b/src/gns/Makefile.am
index 8d7b9bb4a..9aafedf16 100644
--- a/src/gns/Makefile.am
+++ b/src/gns/Makefile.am
@@ -28,6 +28,7 @@ bin_PROGRAMS = \
28 28
29check_PROGRAMS = \ 29check_PROGRAMS = \
30 test_gns_simple_shorten \ 30 test_gns_simple_shorten \
31 test_gns_simple_get_authority \
31 test_gns_simple_lookup \ 32 test_gns_simple_lookup \
32 test_gns_simple_delegated_lookup 33 test_gns_simple_delegated_lookup
33 34
@@ -96,15 +97,27 @@ test_gns_simple_shorten_LDADD = \
96 $(top_builddir)/src/util/libgnunetutil.la \ 97 $(top_builddir)/src/util/libgnunetutil.la \
97 $(top_builddir)/src/namestore/libgnunetnamestore.la \ 98 $(top_builddir)/src/namestore/libgnunetnamestore.la \
98 $(top_builddir)/src/gns/libgnunetgns.la \ 99 $(top_builddir)/src/gns/libgnunetgns.la \
99 $(top_builddir)/src/dht/libgnunetdht.la \
100 $(top_builddir)/src/testing/libgnunettesting.la 100 $(top_builddir)/src/testing/libgnunettesting.la
101test_gns_simple_shorten_DEPENDENCIES = \ 101test_gns_simple_shorten_DEPENDENCIES = \
102 $(top_builddir)/src/util/libgnunetutil.la \ 102 $(top_builddir)/src/util/libgnunetutil.la \
103 $(top_builddir)/src/namestore/libgnunetnamestore.la \ 103 $(top_builddir)/src/namestore/libgnunetnamestore.la \
104 $(top_builddir)/src/gns/libgnunetgns.la \ 104 $(top_builddir)/src/gns/libgnunetgns.la \
105 $(top_builddir)/src/dht/libgnunetdht.la \
106 $(top_builddir)/src/testing/libgnunettesting.la 105 $(top_builddir)/src/testing/libgnunettesting.la
107 106
107test_gns_simple_get_authority_SOURCES = \
108 test_gns_simple_get_authority.c
109test_gns_simple_get_authority_LDADD = \
110 $(top_builddir)/src/util/libgnunetutil.la \
111 $(top_builddir)/src/namestore/libgnunetnamestore.la \
112 $(top_builddir)/src/gns/libgnunetgns.la \
113 $(top_builddir)/src/testing/libgnunettesting.la
114test_gns_simple_get_authority_DEPENDENCIES = \
115 $(top_builddir)/src/util/libgnunetutil.la \
116 $(top_builddir)/src/namestore/libgnunetnamestore.la \
117 $(top_builddir)/src/gns/libgnunetgns.la \
118 $(top_builddir)/src/testing/libgnunettesting.la
119
120
108gnunet_gns_SOURCES = \ 121gnunet_gns_SOURCES = \
109 gnunet-gns.c 122 gnunet-gns.c
110gnunet_gns_LDADD = \ 123gnunet_gns_LDADD = \
diff --git a/src/gns/gns_api.c b/src/gns/gns_api.c
index be1ba58f7..d15f1908e 100644
--- a/src/gns/gns_api.c
+++ b/src/gns/gns_api.c
@@ -755,7 +755,7 @@ GNUNET_GNS_get_authority (struct GNUNET_GNS_Handle *handle,
755 755
756 qe = GNUNET_malloc(sizeof (struct GNUNET_GNS_QueueEntry)); 756 qe = GNUNET_malloc(sizeof (struct GNUNET_GNS_QueueEntry));
757 qe->gns_handle = handle; 757 qe->gns_handle = handle;
758 qe->shorten_proc = proc; 758 qe->auth_proc = proc;
759 qe->proc_cls = proc_cls; 759 qe->proc_cls = proc_cls;
760 qe->r_id = get_request_id(handle); 760 qe->r_id = get_request_id(handle);
761 GNUNET_CONTAINER_DLL_insert_tail(handle->get_auth_head, 761 GNUNET_CONTAINER_DLL_insert_tail(handle->get_auth_head,
diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c
index 8d9932ead..09054d2b9 100644
--- a/src/gns/gnunet-service-gns.c
+++ b/src/gns/gnunet-service-gns.c
@@ -2301,10 +2301,14 @@ send_get_auth_response(const char* name, struct ClientGetAuthHandle *cah)
2301 GNUNET_NO); 2301 GNUNET_NO);
2302 GNUNET_SERVER_receive_done (cah->client, GNUNET_OK); 2302 GNUNET_SERVER_receive_done (cah->client, GNUNET_OK);
2303 2303
2304 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up handles...\n");
2305
2304 GNUNET_free(rmsg); 2306 GNUNET_free(rmsg);
2305 GNUNET_free(cah->name); 2307 GNUNET_free(cah->name);
2306 GNUNET_free(cah); 2308 GNUNET_free(cah);
2307 2309
2310 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "done.\n");
2311
2308} 2312}
2309 2313
2310/** 2314/**
@@ -2353,13 +2357,14 @@ handle_get_auth_delegation_result(void* cls,
2353 } 2357 }
2354 2358
2355 2359
2356 answer_len = strlen(cah->name) - strlen(rh->name); 2360 answer_len = strlen(cah->name) - strlen(rh->name) + strlen(gnunet_tld) + 1;
2357 result = GNUNET_malloc(answer_len); 2361 result = GNUNET_malloc(answer_len);
2358 memset(result, 0, answer_len); 2362 memset(result, 0, answer_len);
2359 strcpy(result, cah->name + strlen(rh->name) + 1); 2363 strcpy(result, cah->name + strlen(rh->name) + 1);
2364 strcpy(result+strlen(result), gnunet_tld);
2360 2365
2361 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2366 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2362 "Our zone: Sending authority result %s\n", result); 2367 "Got authority result %s\n", result);
2363 2368
2364 send_get_auth_response(result, cah); 2369 send_get_auth_response(result, cah);
2365 free_resolver_handle(rh); 2370 free_resolver_handle(rh);
diff --git a/src/gns/test_gns_simple_get_authority.c b/src/gns/test_gns_simple_get_authority.c
new file mode 100644
index 000000000..da8cdcbb6
--- /dev/null
+++ b/src/gns/test_gns_simple_get_authority.c
@@ -0,0 +1,385 @@
1/*
2 This file is part of GNUnet.
3 (C) 2009 Christian Grothoff (and other contributing authors)
4
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
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20/**
21 * @file gns/test_gns_simple_shorten.c
22 * @brief basic shorten test for gns api
23 *
24 */
25#include "platform.h"
26#include "gnunet_testing_lib.h"
27#include "gnunet_core_service.h"
28#include "block_dns.h"
29#include "gnunet_signatures.h"
30#include "gnunet_namestore_service.h"
31#include "../namestore/namestore.h"
32#include "gnunet_dnsparser_lib.h"
33#include "gnunet_gns_service.h"
34
35/* DEFINES */
36#define VERBOSE GNUNET_YES
37
38/* Timeout for entire testcase */
39#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10)
40
41/* If number of peers not in config file, use this number */
42#define DEFAULT_NUM_PEERS 2
43
44/* test records to resolve */
45#define TEST_DOMAIN "www.alice.bob.gnunet"
46#define TEST_IP "127.0.0.1"
47#define TEST_RECORD_NAME "www"
48
49#define TEST_AUTHORITY_BOB "bob"
50#define TEST_AUTHORITY_ALICE "alice"
51#define TEST_ALICE_PSEU "carol"
52#define TEST_EXPECTED_RESULT "alice.bob.gnunet"
53
54/* Globals */
55
56/**
57 * Directory to store temp data in, defined in config file
58 */
59static char *test_directory;
60
61struct GNUNET_TESTING_Daemon *d1;
62
63
64/* Task handle to use to schedule test failure */
65GNUNET_SCHEDULER_TaskIdentifier die_task;
66
67/* Global return value (0 for success, anything else for failure) */
68static int ok;
69
70static struct GNUNET_NAMESTORE_Handle *namestore_handle;
71
72static struct GNUNET_GNS_Handle *gns_handle;
73
74const struct GNUNET_CONFIGURATION_Handle *cfg;
75
76/**
77 * Check whether peers successfully shut down.
78 */
79static void
80shutdown_callback (void *cls, const char *emsg)
81{
82 if (emsg != NULL)
83 {
84 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error on shutdown! ret=%d\n", ok);
85 if (ok == 0)
86 ok = 2;
87 }
88
89 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "done(ret=%d)!\n", ok);
90}
91
92/**
93 * Called when gns_get_authority finishes
94 */
95static void
96process_auth_result(void* cls, const char* aname)
97{
98 GNUNET_GNS_disconnect(gns_handle);
99
100 ok = 0;
101
102 if (aname == NULL)
103 {
104 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
105 "get_authority test failed!\n");
106 ok = 1;
107 }
108 else
109 {
110 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
111 "%s authority is %s\n", (char*)cls, aname);
112 if (0 != strcmp(aname, TEST_EXPECTED_RESULT))
113 {
114 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
115 "get_authority test failed! (wanted: %s got: %s\n",
116 TEST_EXPECTED_RESULT, aname);
117 ok = 1;
118 }
119
120 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "get_authority test finished!\n");
121
122 }
123
124 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Shutting down peer1!\n");
125 GNUNET_TESTING_daemon_stop (d1, TIMEOUT, &shutdown_callback, NULL,
126 GNUNET_YES, GNUNET_NO);
127}
128
129/**
130 * Function scheduled to be run on the successful start of services
131 * tries to shorten the name TEST_DOMAIN using gns
132 */
133static void
134commence_testing (void *cls, int32_t success, const char *emsg)
135{
136
137
138
139 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
140 "disconnecting from namestore\n");
141 GNUNET_NAMESTORE_disconnect(namestore_handle, GNUNET_YES);
142
143 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
144 "connecting to gns\n");
145 gns_handle = GNUNET_GNS_connect(cfg);
146
147 if (NULL == gns_handle)
148 {
149 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
150 "failed to connect to gns\n");
151 ok = 1;
152 return;
153 }
154
155 GNUNET_GNS_get_authority(gns_handle, TEST_DOMAIN, &process_auth_result,
156 TEST_DOMAIN);
157
158}
159
160/**
161 * Continuation for the GNUNET_DHT_get_stop call, so that we don't shut
162 * down the peers without freeing memory associated with GET request.
163 */
164static void
165end_badly_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
166{
167
168 if (d1 != NULL)
169 GNUNET_TESTING_daemon_stop (d1, TIMEOUT, &shutdown_callback, NULL,
170 GNUNET_YES, GNUNET_NO);
171 GNUNET_SCHEDULER_cancel (die_task);
172}
173
174/**
175 * Check if the get_handle is being used, if so stop the request. Either
176 * way, schedule the end_badly_cont function which actually shuts down the
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{
193 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded our_pkey;
194 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded alice_pkey;
195 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded bob_pkey;
196 struct GNUNET_CRYPTO_RsaPrivateKey *our_key;
197 struct GNUNET_CRYPTO_RsaPrivateKey *alice_key;
198 struct GNUNET_CRYPTO_RsaPrivateKey *bob_key;
199 GNUNET_HashCode bob_hash;
200 GNUNET_HashCode alice_hash;
201 struct GNUNET_CRYPTO_RsaSignature *sig;
202 char* our_keyfile;
203
204 GNUNET_SCHEDULER_cancel (die_task);
205
206 /* put records into namestore */
207 namestore_handle = GNUNET_NAMESTORE_connect(cfg);
208 if (NULL == namestore_handle)
209 {
210 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to connect to namestore\n");
211 ok = -1;
212 return;
213 }
214
215 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, "gns",
216 "ZONEKEY",
217 &our_keyfile))
218 {
219 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to get key from cfg\n");
220 ok = -1;
221 return;
222 }
223
224 our_key = GNUNET_CRYPTO_rsa_key_create_from_file (our_keyfile);
225 GNUNET_free(our_keyfile);
226
227 bob_key = GNUNET_CRYPTO_rsa_key_create ();
228 alice_key = GNUNET_CRYPTO_rsa_key_create ();
229
230 GNUNET_CRYPTO_rsa_key_get_public (our_key, &our_pkey);
231 GNUNET_CRYPTO_rsa_key_get_public (alice_key, &alice_pkey);
232 GNUNET_CRYPTO_rsa_key_get_public (bob_key, &bob_pkey);
233
234 struct GNUNET_NAMESTORE_RecordData rd;
235 char* ip = TEST_IP;
236 struct in_addr *web = GNUNET_malloc(sizeof(struct in_addr));
237 rd.expiration = GNUNET_TIME_absolute_get_forever ();
238 GNUNET_assert(1 == inet_pton (AF_INET, ip, web));
239
240 GNUNET_CRYPTO_hash(&bob_pkey, sizeof(bob_pkey), &bob_hash);
241
242 rd.data_size = sizeof(GNUNET_HashCode);
243 rd.data = &bob_hash;
244 rd.record_type = GNUNET_GNS_RECORD_PKEY;
245
246 /* put bob into our zone */
247 GNUNET_NAMESTORE_record_create (namestore_handle,
248 our_key,
249 TEST_AUTHORITY_BOB,
250 &rd,
251 NULL,
252 NULL);
253
254 /* put alice into bobs zone */
255 GNUNET_CRYPTO_hash(&alice_pkey, sizeof(alice_pkey), &alice_hash);
256 rd.data = &alice_hash;
257 sig = GNUNET_NAMESTORE_create_signature(bob_key, GNUNET_TIME_absolute_get_forever(), TEST_AUTHORITY_ALICE,
258 &rd, 1);
259
260 GNUNET_NAMESTORE_record_put (namestore_handle,
261 &bob_pkey,
262 TEST_AUTHORITY_ALICE,
263 GNUNET_TIME_absolute_get_forever(),
264 1,
265 &rd,
266 sig,
267 NULL,
268 NULL);
269
270 /* put www A record and PSEU into alice's zone */
271
272 rd.data_size = sizeof(struct in_addr);
273 rd.data = web;
274 rd.record_type = GNUNET_DNSPARSER_TYPE_A;
275 sig = GNUNET_NAMESTORE_create_signature(alice_key,GNUNET_TIME_absolute_get_forever(), TEST_RECORD_NAME,
276 &rd, 1);
277
278 GNUNET_NAMESTORE_record_put (namestore_handle,
279 &alice_pkey,
280 TEST_RECORD_NAME,
281 GNUNET_TIME_absolute_get_forever(),
282 1,
283 &rd,
284 sig,
285 NULL,
286 NULL);
287
288 rd.data_size = strlen(TEST_ALICE_PSEU);
289 rd.data = TEST_ALICE_PSEU;
290 rd.record_type = GNUNET_GNS_RECORD_PSEU;
291 GNUNET_free(sig);
292
293 sig = GNUNET_NAMESTORE_create_signature(alice_key,GNUNET_TIME_absolute_get_forever(), "",
294 &rd, 1);
295
296 GNUNET_NAMESTORE_record_put (namestore_handle,
297 &alice_pkey,
298 "",
299 GNUNET_TIME_absolute_get_forever(),
300 1,
301 &rd,
302 sig,
303 &commence_testing,
304 NULL);
305
306 GNUNET_free(sig);
307
308}
309
310static void
311run (void *cls, char *const *args, const char *cfgfile,
312 const struct GNUNET_CONFIGURATION_Handle *c)
313{
314 cfg = c;
315 /* Get path from configuration file */
316 if (GNUNET_YES !=
317 GNUNET_CONFIGURATION_get_value_string (cfg, "paths", "servicehome",
318 &test_directory))
319 {
320 ok = 404;
321 return;
322 }
323
324
325 /* Set up a task to end testing if peer start fails */
326 die_task =
327 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly,
328 "didn't start all daemons in reasonable amount of time!!!");
329
330 /* Start alice */
331 d1 = GNUNET_TESTING_daemon_start(cfg, TIMEOUT, GNUNET_NO, NULL, NULL, 0,
332 NULL, NULL, NULL, &do_shorten, NULL);
333}
334
335static int
336check ()
337{
338 int ret;
339
340 /* Arguments for GNUNET_PROGRAM_run */
341 char *const argv[] = { "test-gns-simple-lookup", /* Name to give running binary */
342 "-c",
343 "test_gns_simple_lookup.conf", /* Config file to use */
344#if VERBOSE
345 "-L", "DEBUG",
346#endif
347 NULL
348 };
349 struct GNUNET_GETOPT_CommandLineOption options[] = {
350 GNUNET_GETOPT_OPTION_END
351 };
352 /* Run the run function as a new program */
353 ret =
354 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
355 "test-gns-simple-lookup", "nohelp", options, &run,
356 &ok);
357 if (ret != GNUNET_OK)
358 {
359 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
360 "`test-gns-simple-lookup': Failed with error code %d\n", ret);
361 }
362 return ok;
363}
364
365int
366main (int argc, char *argv[])
367{
368 int ret;
369
370 GNUNET_log_setup ("test-gns-simple-lookup",
371#if VERBOSE
372 "DEBUG",
373#else
374 "WARNING",
375#endif
376 NULL);
377 ret = check ();
378 /**
379 * Need to remove base directory, subdirectories taken care
380 * of by the testing framework.
381 */
382 return ret;
383}
384
385/* end of test_gns_twopeer.c */