aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/gns/Makefile.am15
-rw-r--r--src/gns/gnunet-service-gns.c17
-rw-r--r--src/gns/plugin_block_gns.c4
-rw-r--r--src/gns/test_gns_dht_delegated_lookup.c392
4 files changed, 420 insertions, 8 deletions
diff --git a/src/gns/Makefile.am b/src/gns/Makefile.am
index 6ca49b2e4..cf31c4d79 100644
--- a/src/gns/Makefile.am
+++ b/src/gns/Makefile.am
@@ -29,7 +29,8 @@ check_SCRIPTS = \
29 29
30check_PROGRAMS = \ 30check_PROGRAMS = \
31 test_gns_simple_lookup \ 31 test_gns_simple_lookup \
32 test_gns_simple_delegated_lookup 32 test_gns_simple_delegated_lookup \
33 test_gns_dht_delegated_lookup
33 34
34 35
35plugin_LTLIBRARIES = \ 36plugin_LTLIBRARIES = \
@@ -68,6 +69,18 @@ test_gns_simple_delegated_lookup_DEPENDENCIES = \
68 $(top_builddir)/src/namestore/libgnunetnamestore.la \ 69 $(top_builddir)/src/namestore/libgnunetnamestore.la \
69 $(top_builddir)/src/testing/libgnunettesting.la 70 $(top_builddir)/src/testing/libgnunettesting.la
70 71
72test_gns_dht_delegated_lookup_SOURCES = \
73 test_gns_dht_delegated_lookup.c
74test_gns_dht_delegated_lookup_LDADD = \
75 $(top_builddir)/src/util/libgnunetutil.la \
76 $(top_builddir)/src/namestore/libgnunetnamestore.la \
77 $(top_builddir)/src/dht/libgnunetdht.la \
78 $(top_builddir)/src/testing/libgnunettesting.la
79test_gns_dht_delegated_lookup_DEPENDENCIES = \
80 $(top_builddir)/src/util/libgnunetutil.la \
81 $(top_builddir)/src/namestore/libgnunetnamestore.la \
82 $(top_builddir)/src/dht/libgnunetdht.la \
83 $(top_builddir)/src/testing/libgnunettesting.la
71 84
72#gnunet_gns_lookup_SOURCES = \ 85#gnunet_gns_lookup_SOURCES = \
73# gnunet-gns-lookup.c 86# gnunet-gns-lookup.c
diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c
index 9ec08b205..4b693440f 100644
--- a/src/gns/gnunet-service-gns.c
+++ b/src/gns/gnunet-service-gns.c
@@ -266,8 +266,8 @@ process_authority_dht_result(void* cls,
266 { 266 {
267 struct GNUNET_NAMESTORE_RecordData rd[num_records]; 267 struct GNUNET_NAMESTORE_RecordData rd[num_records];
268 268
269 rd_data += strlen(name) + sizeof(struct GNSNameRecordBlock); 269 rd_data += strlen(name) + 1 + sizeof(struct GNSNameRecordBlock);
270 rd_size = size - strlen(name) - sizeof(struct GNSNameRecordBlock); 270 rd_size = size - strlen(name) - 1 - sizeof(struct GNSNameRecordBlock);
271 271
272 if (GNUNET_SYSERR == GNUNET_NAMESTORE_records_deserialize (rd_size, 272 if (GNUNET_SYSERR == GNUNET_NAMESTORE_records_deserialize (rd_size,
273 rd_data, 273 rd_data,
@@ -427,8 +427,8 @@ process_name_dht_result(void* cls,
427 { 427 {
428 struct GNUNET_NAMESTORE_RecordData rd[num_records]; 428 struct GNUNET_NAMESTORE_RecordData rd[num_records];
429 429
430 rd_data += strlen(name) + sizeof(struct GNSNameRecordBlock); 430 rd_data += strlen(name) + 1 + sizeof(struct GNSNameRecordBlock);
431 rd_size = size - strlen(name) - sizeof(struct GNSNameRecordBlock); 431 rd_size = size - strlen(name) - 1 - sizeof(struct GNSNameRecordBlock);
432 432
433 if (GNUNET_SYSERR == GNUNET_NAMESTORE_records_deserialize (rd_size, 433 if (GNUNET_SYSERR == GNUNET_NAMESTORE_records_deserialize (rd_size,
434 rd_data, 434 rd_data,
@@ -504,6 +504,9 @@ resolve_name_dht(struct GNUNET_GNS_ResolverHandle *rh, const char* name)
504 GNUNET_HashCode lookup_key; 504 GNUNET_HashCode lookup_key;
505 struct GNUNET_CRYPTO_HashAsciiEncoded lookup_key_string; 505 struct GNUNET_CRYPTO_HashAsciiEncoded lookup_key_string;
506 506
507 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
508 "A\n");
509
507 GNUNET_CRYPTO_hash(name, strlen(name), &name_hash); 510 GNUNET_CRYPTO_hash(name, strlen(name), &name_hash);
508 GNUNET_CRYPTO_hash_xor(&name_hash, &rh->authority, &lookup_key); 511 GNUNET_CRYPTO_hash_xor(&name_hash, &rh->authority, &lookup_key);
509 GNUNET_CRYPTO_hash_to_enc (&lookup_key, &lookup_key_string); 512 GNUNET_CRYPTO_hash_to_enc (&lookup_key, &lookup_key_string);
@@ -793,7 +796,7 @@ process_authoritative_result(void* cls,
793 { 796 {
794 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 797 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
795 "trying dht...\n"); 798 "trying dht...\n");
796 resolve_name_dht(rh, name); 799 resolve_name_dht(rh, rh->name);
797 return; 800 return;
798 } 801 }
799 else 802 else
@@ -1181,7 +1184,9 @@ put_gns_record(void *cls,
1181 rd_payload_length, 1184 rd_payload_length,
1182 nrb_data)) 1185 nrb_data))
1183 { 1186 {
1184 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Recor serialization failed!\n"); 1187 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Record serialization failed!\n");
1188 return;
1189 //FIXME what to do
1185 } 1190 }
1186 1191
1187 1192
diff --git a/src/gns/plugin_block_gns.c b/src/gns/plugin_block_gns.c
index d1d8d4d6b..ca7cfe8f4 100644
--- a/src/gns/plugin_block_gns.c
+++ b/src/gns/plugin_block_gns.c
@@ -109,6 +109,8 @@ block_plugin_gns_evaluate (void *cls, enum GNUNET_BLOCK_Type type,
109 rd_count, 109 rd_count,
110 rd)) 110 rd))
111 { 111 {
112 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
113 "Data invalid (%d bytes, %d records)\n", rd_len, rd_count);
112 return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID; 114 return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
113 } 115 }
114 116
@@ -125,7 +127,7 @@ block_plugin_gns_evaluate (void *cls, enum GNUNET_BLOCK_Type type,
125 name, 127 name,
126 rd_count, 128 rd_count,
127 rd, 129 rd,
128 NULL)) 130 &nrb->signature))
129 { 131 {
130 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Signature invalid\n"); 132 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Signature invalid\n");
131 return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID; 133 return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
diff --git a/src/gns/test_gns_dht_delegated_lookup.c b/src/gns/test_gns_dht_delegated_lookup.c
new file mode 100644
index 000000000..8c2224623
--- /dev/null
+++ b/src/gns/test_gns_dht_delegated_lookup.c
@@ -0,0 +1,392 @@
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_twopeer.c
22 * @brief base testcase for testing DHT service with
23 * two running peers.
24 *
25 * This testcase starts peers using the GNUNET_TESTING_daemons_start
26 * function call. On peer start, connects to the peers DHT service
27 * by calling GNUNET_DHT_connected. Once notified about all peers
28 * being started (by the peers_started_callback function), calls
29 * GNUNET_TESTING_connect_topology, which connects the peers in a
30 * "straight line" topology. On notification that all peers have
31 * been properly connected, calls the do_get function which initiates
32 * a GNUNET_DHT_get from the *second* peer. Once the GNUNET_DHT_get
33 * function starts, runs the do_put function to insert data at the first peer.
34 * If the GET is successful, schedules finish_testing
35 * to stop the test and shut down peers. If GET is unsuccessful
36 * after GET_TIMEOUT seconds, prints an error message and shuts down
37 * the peers.
38 */
39#include "platform.h"
40#include "gnunet_testing_lib.h"
41#include "gnunet_core_service.h"
42#include "block_gns.h"
43#include "gnunet_signatures.h"
44#include "gnunet_namestore_service.h"
45#include "../namestore/namestore.h"
46#include "gnunet_dnsparser_lib.h"
47#include "gnunet_dht_service.h"
48#include "gnunet_gns_service.h"
49
50/* DEFINES */
51#define VERBOSE GNUNET_YES
52
53/* Timeout for entire testcase */
54#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10)
55
56/* If number of peers not in config file, use this number */
57#define DEFAULT_NUM_PEERS 2
58
59/* test records to resolve */
60#define TEST_DOMAIN "www.bob.gnunet"
61#define TEST_IP "127.0.0.1"
62#define TEST_RECORD_NAME "www"
63
64#define TEST_AUTHORITY_NAME "bob"
65
66#define DHT_OPERATION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
67
68/* Globals */
69
70/**
71 * Directory to store temp data in, defined in config file
72 */
73static char *test_directory;
74
75struct GNUNET_TESTING_Daemon *d1;
76
77
78/* Task handle to use to schedule test failure */
79GNUNET_SCHEDULER_TaskIdentifier die_task;
80
81/* Global return value (0 for success, anything else for failure) */
82static int ok;
83
84static struct GNUNET_NAMESTORE_Handle *namestore_handle;
85
86static struct GNUNET_DHT_Handle *dht_handle;
87
88const struct GNUNET_CONFIGURATION_Handle *cfg;
89
90struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded alice_pkey;
91struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded bob_pkey;
92struct GNUNET_CRYPTO_RsaPrivateKey *alice_key;
93struct GNUNET_CRYPTO_RsaPrivateKey *bob_key;
94
95/**
96 * Check whether peers successfully shut down.
97 */
98void
99shutdown_callback (void *cls, const char *emsg)
100{
101 if (emsg != NULL)
102 {
103 if (ok == 0)
104 ok = 2;
105 }
106
107 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "done(ret=%d)!\n", ok);
108}
109
110/**
111 * Function scheduled to be run on the successful start of services
112 * tries to look up the dns record for TEST_DOMAIN
113 */
114static void
115finish_testing (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
116{
117 struct hostent *he;
118 struct in_addr a;
119 char* addr;
120 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "A\n");
121 GNUNET_NAMESTORE_disconnect(namestore_handle, GNUNET_YES);
122 GNUNET_DHT_disconnect(dht_handle);
123 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "B\n");
124
125 he = gethostbyname (TEST_DOMAIN);
126
127 if (!he)
128 {
129 ok = 2;
130 }
131 else
132 {
133 ok = 1;
134 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "name: %s\n", he->h_name);
135 while (*he->h_addr_list)
136 {
137 memcpy(&a, *he->h_addr_list++, sizeof(a));
138 addr = inet_ntoa(a);
139 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "address: %s\n", addr);
140 if (0 == strcmp(addr, TEST_IP))
141 {
142 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
143 "%s correctly resolved to %s!\n", TEST_DOMAIN, addr);
144 ok = 0;
145 }
146 else
147 {
148 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "No resolution!\n");
149 }
150 }
151 }
152 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Shutting down peer1!\n");
153 GNUNET_TESTING_daemon_stop (d1, TIMEOUT, &shutdown_callback, NULL,
154 GNUNET_YES, GNUNET_NO);
155}
156
157/**
158 * Continuation for the GNUNET_DHT_get_stop call, so that we don't shut
159 * down the peers without freeing memory associated with GET request.
160 */
161static void
162end_badly_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
163{
164
165 if (d1 != NULL)
166 GNUNET_TESTING_daemon_stop (d1, TIMEOUT, &shutdown_callback, NULL,
167 GNUNET_YES, GNUNET_NO);
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_INFO, "Failing test with error: `%s'!\n",
180 (char *) cls);
181 GNUNET_SCHEDULER_add_now (&end_badly_cont, NULL);
182 ok = 1;
183}
184
185
186static void
187put_dht(void *cls, int32_t success, const char *emsg)
188{
189 struct GNSNameRecordBlock *nrb;
190 GNUNET_HashCode name_hash;
191 GNUNET_HashCode xor_hash;
192 GNUNET_HashCode zone_hash;
193 uint32_t rd_payload_length;
194 char* nrb_data = NULL;
195 struct GNUNET_CRYPTO_RsaSignature *sig;
196 struct GNUNET_NAMESTORE_RecordData rd;
197 char* ip = TEST_IP;
198 struct in_addr *web = GNUNET_malloc(sizeof(struct in_addr));
199
200 rd.expiration = GNUNET_TIME_absolute_get_forever ();
201 GNUNET_assert(1 == inet_pton (AF_INET, ip, web));
202 rd.data_size = sizeof(struct in_addr);
203 rd.data = web;
204 rd.record_type = GNUNET_DNSPARSER_TYPE_A;
205 sig = GNUNET_NAMESTORE_create_signature(bob_key, TEST_RECORD_NAME,
206 &rd, 1);
207
208 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "B\n");
209 rd_payload_length = GNUNET_NAMESTORE_records_get_size (1, &rd);
210 nrb = GNUNET_malloc(rd_payload_length + strlen(TEST_RECORD_NAME) + 1
211 + sizeof(struct GNSNameRecordBlock));
212 nrb->signature = *sig;
213 nrb->public_key = bob_pkey;
214 nrb->rd_count = htonl(1);
215 memset(&nrb[1], 0, strlen(TEST_RECORD_NAME) + 1);
216 memcpy(&nrb[1], TEST_RECORD_NAME, strlen(TEST_RECORD_NAME));
217 nrb_data = (char*)&nrb[1];
218 nrb_data += strlen(TEST_RECORD_NAME) + 1;
219 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "C\n");
220
221 if (-1 == GNUNET_NAMESTORE_records_serialize (1,
222 &rd,
223 rd_payload_length,
224 nrb_data))
225 {
226 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Record serialization failed!\n");
227 ok = 3;
228 return;
229 }
230 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "D\n");
231 GNUNET_CRYPTO_hash(TEST_RECORD_NAME, strlen(TEST_RECORD_NAME), &name_hash);
232 GNUNET_CRYPTO_hash(&bob_pkey,
233 sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
234 &zone_hash);
235 GNUNET_CRYPTO_hash_xor(&zone_hash, &name_hash, &xor_hash);
236 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "E\n");
237
238 rd_payload_length += sizeof(struct GNSNameRecordBlock) +
239 strlen(TEST_RECORD_NAME) + 1;
240 GNUNET_DHT_put (dht_handle, &xor_hash,
241 0,
242 GNUNET_DHT_RO_NONE,
243 GNUNET_BLOCK_TYPE_GNS_NAMERECORD,
244 rd_payload_length,
245 (char*)nrb,
246 rd.expiration,
247 DHT_OPERATION_TIMEOUT,
248 NULL,
249 NULL);
250 GNUNET_SCHEDULER_add_delayed(TIMEOUT, &finish_testing, NULL);
251 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "F\n");
252}
253
254static void
255do_lookup(void *cls, const struct GNUNET_PeerIdentity *id,
256 const struct GNUNET_CONFIGURATION_Handle *cfg,
257 struct GNUNET_TESTING_Daemon *d, const char *emsg)
258{
259
260
261 char* alice_keyfile;
262
263
264
265 GNUNET_SCHEDULER_cancel (die_task);
266
267 /* put records into namestore */
268 namestore_handle = GNUNET_NAMESTORE_connect(cfg);
269 if (NULL == namestore_handle)
270 {
271 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to connect to namestore\n");
272 ok = -1;
273 return;
274 }
275
276 /* dht */
277 dht_handle = GNUNET_DHT_connect(cfg, 1);
278 if (NULL == dht_handle)
279 {
280 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to connect to dht\n");
281 ok = -1;
282 return;
283 }
284
285 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, "gns",
286 "ZONEKEY",
287 &alice_keyfile))
288 {
289 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to get key from cfg\n");
290 ok = -1;
291 return;
292 }
293
294 alice_key = GNUNET_CRYPTO_rsa_key_create_from_file (alice_keyfile);
295 bob_key = GNUNET_CRYPTO_rsa_key_create ();
296
297 GNUNET_CRYPTO_rsa_key_get_public (alice_key, &alice_pkey);
298 GNUNET_CRYPTO_rsa_key_get_public (bob_key, &bob_pkey);
299
300 struct GNUNET_NAMESTORE_RecordData rd;
301 rd.expiration = GNUNET_TIME_absolute_get_forever ();
302 rd.data_size = sizeof(bob_pkey);
303 rd.data = &bob_pkey;
304 rd.record_type = GNUNET_GNS_RECORD_PKEY;
305
306 GNUNET_NAMESTORE_record_create (namestore_handle,
307 alice_key,
308 TEST_AUTHORITY_NAME,
309 &rd,
310 &put_dht,
311 NULL);
312
313
314
315}
316
317static void
318run (void *cls, char *const *args, const char *cfgfile,
319 const struct GNUNET_CONFIGURATION_Handle *c)
320{
321 cfg = c;
322 /* Get path from configuration file */
323 if (GNUNET_YES !=
324 GNUNET_CONFIGURATION_get_value_string (cfg, "paths", "servicehome",
325 &test_directory))
326 {
327 ok = 404;
328 return;
329 }
330
331
332 /* Set up a task to end testing if peer start fails */
333 die_task =
334 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly,
335 "didn't start all daemons in reasonable amount of time!!!");
336
337 /* Start alice */
338 d1 = GNUNET_TESTING_daemon_start(cfg, TIMEOUT, GNUNET_NO, NULL, NULL, 0,
339 NULL, NULL, NULL, &do_lookup, NULL);
340}
341
342static int
343check ()
344{
345 int ret;
346
347 /* Arguments for GNUNET_PROGRAM_run */
348 char *const argv[] = { "test-gns-simple-lookup", /* Name to give running binary */
349 "-c",
350 "test_gns_simple_lookup.conf", /* Config file to use */
351#if VERBOSE
352 "-L", "DEBUG",
353#endif
354 NULL
355 };
356 struct GNUNET_GETOPT_CommandLineOption options[] = {
357 GNUNET_GETOPT_OPTION_END
358 };
359 /* Run the run function as a new program */
360 ret =
361 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
362 "test-gns-simple-lookup", "nohelp", options, &run,
363 &ok);
364 if (ret != GNUNET_OK)
365 {
366 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
367 "`test-gns-simple-lookup': Failed with error code %d\n", ret);
368 }
369 return ok;
370}
371
372int
373main (int argc, char *argv[])
374{
375 int ret;
376
377 GNUNET_log_setup ("test-gns-simple-lookup",
378#if VERBOSE
379 "DEBUG",
380#else
381 "WARNING",
382#endif
383 NULL);
384 ret = check ();
385 /**
386 * Need to remove base directory, subdirectories taken care
387 * of by the testing framework.
388 */
389 return ret;
390}
391
392/* end of test_gns_twopeer.c */