diff options
-rw-r--r-- | src/gns/Makefile.am | 1 | ||||
-rw-r--r-- | src/gns/test_gns_cname_lookup.c | 449 | ||||
-rwxr-xr-x | src/gns/test_gns_ns_lookup.sh | 47 | ||||
-rw-r--r-- | src/gns/test_gns_simple_lookup.c | 286 | ||||
-rw-r--r-- | src/gns/test_gns_simple_mx_lookup.c | 301 |
5 files changed, 48 insertions, 1036 deletions
diff --git a/src/gns/Makefile.am b/src/gns/Makefile.am index 069f24188..7a3bb5616 100644 --- a/src/gns/Makefile.am +++ b/src/gns/Makefile.am | |||
@@ -201,6 +201,7 @@ check_SCRIPTS = \ | |||
201 | test_gns_ipv6_lookup.sh\ | 201 | test_gns_ipv6_lookup.sh\ |
202 | test_gns_txt_lookup.sh\ | 202 | test_gns_txt_lookup.sh\ |
203 | test_gns_mx_lookup.sh \ | 203 | test_gns_mx_lookup.sh \ |
204 | test_gns_ns_lookup.sh \ | ||
204 | test_gns_cname_lookup.sh | 205 | test_gns_cname_lookup.sh |
205 | 206 | ||
206 | if ENABLE_TEST_RUN | 207 | if ENABLE_TEST_RUN |
diff --git a/src/gns/test_gns_cname_lookup.c b/src/gns/test_gns_cname_lookup.c deleted file mode 100644 index ee51d4aa5..000000000 --- a/src/gns/test_gns_cname_lookup.c +++ /dev/null | |||
@@ -1,449 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2012 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_cname_lookup.c | ||
22 | * @brief base testcase for testing a local GNS record lookup | ||
23 | * @author Martin Schanzenbach | ||
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 "gnunet_dnsparser_lib.h" | ||
32 | #include "gnunet_gns_service.h" | ||
33 | |||
34 | |||
35 | /** | ||
36 | * Timeout for entire testcase | ||
37 | */ | ||
38 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 20) | ||
39 | |||
40 | /* test records to resolve */ | ||
41 | #define TEST_DOMAIN_PLUS "www.gnu" | ||
42 | #define TEST_DOMAIN_ZKEY "www2.gnu" | ||
43 | #define TEST_DOMAIN_DNS "www3.gnu" | ||
44 | #define TEST_IP_PLUS "127.0.0.1" | ||
45 | #define TEST_IP_ZKEY "127.0.0.2" | ||
46 | #define TEST_IP_DNS "131.159.74.67" | ||
47 | #define TEST_RECORD_CNAME_SERVER "server.gnu" | ||
48 | #define TEST_RECORD_CNAME_PLUS "server.+" | ||
49 | #define TEST_RECORD_CNAME_ZKEY "www.J7POEUT41A8PBFS7KVVDRF88GBOU4HK8PSU5QKVLVE3R9T91E99G.zkey" | ||
50 | #define TEST_RECORD_CNAME_DNS "gnunet.org" | ||
51 | #define TEST_RECORD_NAME_SERVER "server" | ||
52 | #define TEST_RECORD_NAME_PLUS "www" | ||
53 | #define TEST_RECORD_NAME_ZKEY "www2" | ||
54 | #define TEST_RECORD_NAME_DNS "www3" | ||
55 | |||
56 | #define KEYFILE_BOB "zonefiles/J7POEUT41A8PBFS7KVVDRF88GBOU4HK8PSU5QKVLVE3R9T91E99G.zkey" | ||
57 | |||
58 | |||
59 | /* Task handle to use to schedule test failure */ | ||
60 | static GNUNET_SCHEDULER_TaskIdentifier die_task; | ||
61 | |||
62 | /* Global return value (0 for success, anything else for failure) */ | ||
63 | static int ok; | ||
64 | |||
65 | static struct GNUNET_NAMESTORE_Handle *namestore_handle; | ||
66 | |||
67 | static struct GNUNET_GNS_Handle *gns_handle; | ||
68 | |||
69 | static const struct GNUNET_CONFIGURATION_Handle *cfg; | ||
70 | |||
71 | |||
72 | /** | ||
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. | ||
76 | */ | ||
77 | static void | ||
78 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
79 | { | ||
80 | die_task = GNUNET_SCHEDULER_NO_TASK; | ||
81 | if (NULL != gns_handle) | ||
82 | { | ||
83 | GNUNET_GNS_disconnect (gns_handle); | ||
84 | gns_handle = NULL; | ||
85 | } | ||
86 | if (NULL != namestore_handle) | ||
87 | { | ||
88 | GNUNET_NAMESTORE_disconnect (namestore_handle); | ||
89 | namestore_handle = NULL; | ||
90 | } | ||
91 | GNUNET_break (0); | ||
92 | GNUNET_SCHEDULER_shutdown (); | ||
93 | ok = 1; | ||
94 | } | ||
95 | |||
96 | |||
97 | static void | ||
98 | shutdown_task (void *cls, | ||
99 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
100 | { | ||
101 | GNUNET_GNS_disconnect (gns_handle); | ||
102 | gns_handle = NULL; | ||
103 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Shutting down peer!\n"); | ||
104 | GNUNET_SCHEDULER_shutdown (); | ||
105 | } | ||
106 | |||
107 | |||
108 | static void | ||
109 | on_lookup_result_cname (void *cls, | ||
110 | uint32_t rd_count, | ||
111 | const struct GNUNET_NAMESTORE_RecordData *rd) | ||
112 | { | ||
113 | uint32_t i; | ||
114 | |||
115 | if (GNUNET_SCHEDULER_NO_TASK != die_task) | ||
116 | { | ||
117 | GNUNET_SCHEDULER_cancel (die_task); | ||
118 | die_task = GNUNET_SCHEDULER_NO_TASK; | ||
119 | } | ||
120 | GNUNET_NAMESTORE_disconnect (namestore_handle); | ||
121 | namestore_handle = NULL; | ||
122 | if (rd_count == 0) | ||
123 | { | ||
124 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
125 | "Lookup failed, rp_filtering?\n"); | ||
126 | ok = 2; | ||
127 | } | ||
128 | else | ||
129 | { | ||
130 | ok = 1; | ||
131 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "name: %s\n", (char*)cls); | ||
132 | for (i=0; i<rd_count; i++) | ||
133 | { | ||
134 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "type: %d\n", rd[i].record_type); | ||
135 | if (rd[i].record_type == GNUNET_DNSPARSER_TYPE_CNAME) | ||
136 | { | ||
137 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "CNAME: %s\n", rd[i].data); | ||
138 | if (0 == strcmp(rd[i].data, TEST_RECORD_CNAME_SERVER)) | ||
139 | { | ||
140 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
141 | "%s correctly resolved to %s!\n", TEST_DOMAIN_PLUS, rd[i].data); | ||
142 | ok = 0; | ||
143 | } | ||
144 | } | ||
145 | else | ||
146 | { | ||
147 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No resolution!\n"); | ||
148 | } | ||
149 | } | ||
150 | } | ||
151 | GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); | ||
152 | } | ||
153 | |||
154 | |||
155 | static void | ||
156 | on_lookup_result_dns (void *cls, | ||
157 | uint32_t rd_count, | ||
158 | const struct GNUNET_NAMESTORE_RecordData *rd) | ||
159 | { | ||
160 | struct in_addr a; | ||
161 | uint32_t i; | ||
162 | char* addr; | ||
163 | |||
164 | if (rd_count == 0) | ||
165 | { | ||
166 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
167 | "CNAME to DNS delegation failed. System offline?\n"); | ||
168 | } | ||
169 | else | ||
170 | { | ||
171 | ok = 1; | ||
172 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "name: %s\n", (char*)cls); | ||
173 | for (i=0; i<rd_count; i++) | ||
174 | { | ||
175 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "type: %d\n", rd[i].record_type); | ||
176 | if (rd[i].record_type == GNUNET_DNSPARSER_TYPE_A) | ||
177 | { | ||
178 | memcpy(&a, rd[i].data, sizeof(a)); | ||
179 | addr = inet_ntoa(a); | ||
180 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "address: %s\n", addr); | ||
181 | if (0 == strcmp(addr, TEST_IP_DNS)) | ||
182 | { | ||
183 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
184 | "%s correctly resolved to %s!\n", TEST_DOMAIN_DNS, addr); | ||
185 | ok = 0; | ||
186 | } | ||
187 | } | ||
188 | else | ||
189 | { | ||
190 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No resolution!\n"); | ||
191 | } | ||
192 | } | ||
193 | } | ||
194 | GNUNET_GNS_lookup (gns_handle, TEST_DOMAIN_PLUS, GNUNET_DNSPARSER_TYPE_CNAME, | ||
195 | GNUNET_YES, | ||
196 | NULL, | ||
197 | &on_lookup_result_cname, TEST_DOMAIN_PLUS); | ||
198 | } | ||
199 | |||
200 | |||
201 | static void | ||
202 | on_lookup_result_zkey (void *cls, uint32_t rd_count, | ||
203 | const struct GNUNET_NAMESTORE_RecordData *rd) | ||
204 | { | ||
205 | struct in_addr a; | ||
206 | uint32_t i; | ||
207 | char* addr; | ||
208 | |||
209 | if (rd_count == 0) | ||
210 | { | ||
211 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
212 | "Lookup failed, rp_filtering?\n"); | ||
213 | ok = 2; | ||
214 | GNUNET_SCHEDULER_shutdown (); | ||
215 | return; | ||
216 | } | ||
217 | ok = 1; | ||
218 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
219 | "name: %s\n", (char*)cls); | ||
220 | for (i=0; i<rd_count; i++) | ||
221 | { | ||
222 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
223 | "type: %d\n", rd[i].record_type); | ||
224 | if (rd[i].record_type == GNUNET_DNSPARSER_TYPE_A) | ||
225 | { | ||
226 | memcpy (&a, rd[i].data, sizeof(a)); | ||
227 | addr = inet_ntoa(a); | ||
228 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
229 | "address: %s\n", addr); | ||
230 | if (0 == strcmp (addr, TEST_IP_ZKEY)) | ||
231 | { | ||
232 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
233 | "%s correctly resolved to %s!\n", | ||
234 | TEST_DOMAIN_ZKEY, addr); | ||
235 | ok = 0; | ||
236 | } | ||
237 | } | ||
238 | else | ||
239 | { | ||
240 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
241 | "No resolution!\n"); | ||
242 | } | ||
243 | } | ||
244 | GNUNET_GNS_lookup (gns_handle, TEST_DOMAIN_DNS, GNUNET_DNSPARSER_TYPE_A, | ||
245 | GNUNET_YES, | ||
246 | NULL, | ||
247 | &on_lookup_result_dns, TEST_DOMAIN_DNS); | ||
248 | } | ||
249 | |||
250 | |||
251 | static void | ||
252 | on_lookup_result_plus (void *cls, uint32_t rd_count, | ||
253 | const struct GNUNET_NAMESTORE_RecordData *rd) | ||
254 | { | ||
255 | struct in_addr a; | ||
256 | uint32_t i; | ||
257 | char* addr; | ||
258 | |||
259 | if (rd_count == 0) | ||
260 | { | ||
261 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
262 | "Lookup failed, rp_filtering?\n"); | ||
263 | ok = 2; | ||
264 | GNUNET_SCHEDULER_shutdown (); | ||
265 | return; | ||
266 | } | ||
267 | ok = 1; | ||
268 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "name: %s\n", (char*)cls); | ||
269 | for (i=0; i<rd_count; i++) | ||
270 | { | ||
271 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "type: %d\n", rd[i].record_type); | ||
272 | if (rd[i].record_type == GNUNET_DNSPARSER_TYPE_A) | ||
273 | { | ||
274 | memcpy(&a, rd[i].data, sizeof(a)); | ||
275 | addr = inet_ntoa(a); | ||
276 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "address: %s\n", addr); | ||
277 | if (0 == strcmp(addr, TEST_IP_PLUS)) | ||
278 | { | ||
279 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
280 | "%s correctly resolved to %s!\n", TEST_DOMAIN_PLUS, addr); | ||
281 | ok = 0; | ||
282 | } | ||
283 | } | ||
284 | else | ||
285 | { | ||
286 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No resolution!\n"); | ||
287 | } | ||
288 | } | ||
289 | GNUNET_GNS_lookup (gns_handle, TEST_DOMAIN_ZKEY, GNUNET_DNSPARSER_TYPE_A, | ||
290 | GNUNET_YES, | ||
291 | NULL, | ||
292 | &on_lookup_result_zkey, TEST_DOMAIN_ZKEY); | ||
293 | } | ||
294 | |||
295 | |||
296 | /** | ||
297 | * Function scheduled to be run on the successful start of services | ||
298 | * tries to look up the dns record for TEST_DOMAIN | ||
299 | * | ||
300 | * @param cls closure | ||
301 | * @param success GNUNET_SYSERR on failure (including timeout/queue drop/failure to validate) | ||
302 | * GNUNET_NO if content was already there or not found | ||
303 | * GNUNET_YES (or other positive value) on success | ||
304 | * @param emsg NULL on success, otherwise an error message | ||
305 | */ | ||
306 | static void | ||
307 | commence_testing (void *cls, int32_t success, const char *emsg) | ||
308 | { | ||
309 | if (NULL != emsg) | ||
310 | { | ||
311 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
312 | "Failed to store record in namestore: %s\n", | ||
313 | emsg); | ||
314 | GNUNET_SCHEDULER_shutdown (); | ||
315 | return; | ||
316 | } | ||
317 | gns_handle = GNUNET_GNS_connect(cfg); | ||
318 | if (NULL == gns_handle) | ||
319 | { | ||
320 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
321 | "Failed to connect to GNS!\n"); | ||
322 | GNUNET_SCHEDULER_shutdown (); | ||
323 | return; | ||
324 | } | ||
325 | GNUNET_GNS_lookup (gns_handle, TEST_DOMAIN_PLUS, GNUNET_DNSPARSER_TYPE_A, | ||
326 | GNUNET_YES, | ||
327 | NULL, | ||
328 | &on_lookup_result_plus, TEST_DOMAIN_PLUS); | ||
329 | } | ||
330 | |||
331 | |||
332 | static void | ||
333 | do_check (void *cls, | ||
334 | const struct GNUNET_CONFIGURATION_Handle *ccfg, | ||
335 | struct GNUNET_TESTING_Peer *peer) | ||
336 | { | ||
337 | struct GNUNET_CRYPTO_EccPublicSignKey alice_pkey; | ||
338 | struct GNUNET_CRYPTO_EccPrivateKey *alice_key; | ||
339 | struct GNUNET_CRYPTO_EccPrivateKey *bob_key; | ||
340 | char* alice_keyfile; | ||
341 | struct GNUNET_NAMESTORE_RecordData rd; | ||
342 | const char* ip = TEST_IP_PLUS; | ||
343 | struct in_addr web; | ||
344 | |||
345 | cfg = ccfg; | ||
346 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); | ||
347 | |||
348 | /* put records into namestore */ | ||
349 | namestore_handle = GNUNET_NAMESTORE_connect(cfg); | ||
350 | if (NULL == namestore_handle) | ||
351 | { | ||
352 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
353 | "Failed to connect to namestore\n"); | ||
354 | GNUNET_SCHEDULER_shutdown (); | ||
355 | return; | ||
356 | } | ||
357 | |||
358 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns", | ||
359 | "ZONEKEY", | ||
360 | &alice_keyfile)) | ||
361 | { | ||
362 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
363 | "Failed to get key from cfg\n"); | ||
364 | GNUNET_SCHEDULER_shutdown (); | ||
365 | return; | ||
366 | } | ||
367 | |||
368 | alice_key = GNUNET_CRYPTO_ecc_key_create_from_file (alice_keyfile); | ||
369 | GNUNET_CRYPTO_ecc_key_get_public_for_signature (alice_key, &alice_pkey); | ||
370 | GNUNET_free(alice_keyfile); | ||
371 | |||
372 | bob_key = GNUNET_CRYPTO_ecc_key_create_from_file (KEYFILE_BOB); | ||
373 | |||
374 | rd.expiration_time = UINT64_MAX; | ||
375 | GNUNET_assert(1 == inet_pton (AF_INET, ip, &web)); | ||
376 | rd.data_size = sizeof(struct in_addr); | ||
377 | rd.data = &web; | ||
378 | rd.record_type = GNUNET_DNSPARSER_TYPE_A; | ||
379 | rd.flags = GNUNET_NAMESTORE_RF_NONE; | ||
380 | |||
381 | GNUNET_NAMESTORE_record_put_by_authority (namestore_handle, | ||
382 | alice_key, | ||
383 | TEST_RECORD_NAME_SERVER, | ||
384 | 1, &rd, | ||
385 | NULL, | ||
386 | NULL); | ||
387 | |||
388 | rd.data_size = strlen (TEST_RECORD_CNAME_PLUS); | ||
389 | rd.data = TEST_RECORD_CNAME_PLUS; | ||
390 | rd.record_type = GNUNET_DNSPARSER_TYPE_CNAME; | ||
391 | |||
392 | GNUNET_NAMESTORE_record_put_by_authority (namestore_handle, | ||
393 | alice_key, | ||
394 | TEST_RECORD_NAME_PLUS, | ||
395 | 1, &rd, | ||
396 | NULL, | ||
397 | NULL); | ||
398 | |||
399 | rd.data_size = strlen (TEST_RECORD_CNAME_ZKEY); | ||
400 | rd.data = TEST_RECORD_CNAME_ZKEY; | ||
401 | rd.record_type = GNUNET_DNSPARSER_TYPE_CNAME; | ||
402 | |||
403 | GNUNET_NAMESTORE_record_put_by_authority (namestore_handle, | ||
404 | alice_key, | ||
405 | TEST_RECORD_NAME_ZKEY, | ||
406 | 1, &rd, | ||
407 | NULL, | ||
408 | NULL); | ||
409 | |||
410 | rd.data_size = strlen (TEST_RECORD_CNAME_DNS); | ||
411 | rd.data = TEST_RECORD_CNAME_DNS; | ||
412 | rd.record_type = GNUNET_DNSPARSER_TYPE_CNAME; | ||
413 | |||
414 | GNUNET_NAMESTORE_record_put_by_authority (namestore_handle, | ||
415 | alice_key, | ||
416 | TEST_RECORD_NAME_DNS, | ||
417 | 1, &rd, | ||
418 | NULL, | ||
419 | NULL); | ||
420 | |||
421 | GNUNET_assert(1 == inet_pton (AF_INET, TEST_IP_ZKEY, &web)); | ||
422 | rd.data_size = sizeof(struct in_addr); | ||
423 | rd.data = &web; | ||
424 | rd.record_type = GNUNET_DNSPARSER_TYPE_A; | ||
425 | |||
426 | GNUNET_NAMESTORE_record_put_by_authority (namestore_handle, | ||
427 | bob_key, | ||
428 | TEST_RECORD_NAME_PLUS, | ||
429 | 1, &rd, | ||
430 | &commence_testing, | ||
431 | NULL); | ||
432 | GNUNET_free(alice_key); | ||
433 | GNUNET_free(bob_key); | ||
434 | } | ||
435 | |||
436 | |||
437 | int | ||
438 | main (int argc, char *argv[]) | ||
439 | { | ||
440 | ok = 1; | ||
441 | |||
442 | GNUNET_log_setup ("test-gns-simple-cname-lookup", | ||
443 | "WARNING", | ||
444 | NULL); | ||
445 | GNUNET_TESTING_peer_run ("test-gns-simple-cname-lookup", "test_gns_simple_lookup.conf", &do_check, NULL); | ||
446 | return ok; | ||
447 | } | ||
448 | |||
449 | /* end of test_gns_cname_lookup.c */ | ||
diff --git a/src/gns/test_gns_ns_lookup.sh b/src/gns/test_gns_ns_lookup.sh new file mode 100755 index 000000000..7e9b66bfd --- /dev/null +++ b/src/gns/test_gns_ns_lookup.sh | |||
@@ -0,0 +1,47 @@ | |||
1 | #!/bin/bash | ||
2 | trap "gnunet-arm -e -c test_gns_lookup.conf" SIGINT | ||
3 | rm -r `gnunet-config -c test_gns_lookup.conf -s PATHS -o SERVICEHOME` | ||
4 | TEST_DOMAIN="www.homepage.gnu" | ||
5 | TEST_DOMAIN_ALT="homepage.gnu" | ||
6 | TEST_DOMAIN_ALT2="uk.homepage.gnu" | ||
7 | TEST_IP_ALT2="81.187.252.184" | ||
8 | TEST_IP="131.159.74.67" | ||
9 | TEST_IP_NS="184.172.157.218" | ||
10 | TEST_RECORD_NAME="homepage" | ||
11 | TEST_RECORD_NS="gnunet.org" | ||
12 | gnunet-arm -s -c test_gns_lookup.conf | ||
13 | gnunet-identity -C testego -c test_gns_lookup.conf | ||
14 | gnunet-namestore -p -z testego -a -n $TEST_RECORD_NAME -t A -V $TEST_IP_NS -e never -c test_gns_lookup.conf | ||
15 | gnunet-namestore -p -z testego -a -n $TEST_RECORD_NAME -t NS -V $TEST_RECORD_NS -e never -c test_gns_lookup.conf | ||
16 | RES_IP=$(timeout 5 gnunet-gns --raw -z testego -u $TEST_DOMAIN -t A -c test_gns_lookup.conf) | ||
17 | RES_IP_ALT=$(timeout 5 gnunet-gns --raw -z testego -u $TEST_DOMAIN_ALT -t A -c test_gns_lookup.conf) | ||
18 | RES_IP_ALT2=$(timeout 5 gnunet-gns --raw -z testego -u $TEST_DOMAIN_ALT2 -t A -c test_gns_lookup.conf) | ||
19 | gnunet-namestore -z testego -d -n www -t A -V $TEST_IP -e never -c test_gns_lookup.conf | ||
20 | gnunet-namestore -z testego -d -n $TEST_RECORD_NAME -t NS -V $TEST_RECORD_NS -e never -c test_gns_lookup.conf | ||
21 | gnunet-identity -D testego -c test_gns_lookup.conf | ||
22 | gnunet-arm -e -c test_gns_lookup.conf | ||
23 | |||
24 | if [ "$RES_IP" == "$TEST_IP" ] | ||
25 | then | ||
26 | echo "PASS: Resolved $TEST_DOMAIN to $RES_IP." | ||
27 | else | ||
28 | echo "Failed to resolve to proper IP for $TEST_DOMAIN, got $RES_IP." | ||
29 | exit 1 | ||
30 | fi | ||
31 | |||
32 | if [ "$RES_IP_ALT" == "$TEST_IP" ] | ||
33 | then | ||
34 | echo "PASS: Resolved $TEST_DOMAIN_ALT to $RES_IP_ALT." | ||
35 | else | ||
36 | echo "Failed to resolve to proper IP for $TEST_DOMAIN_ALT, got $RES_IP_ALT." | ||
37 | exit 1 | ||
38 | fi | ||
39 | |||
40 | if [ "$RES_IP_ALT2" == "$TEST_IP_ALT2" ] | ||
41 | then | ||
42 | echo "PASS: Resolved $TEST_DOMAIN_ALT2 to $RES_IP_ALT2." | ||
43 | exit 0 | ||
44 | else | ||
45 | echo "Failed to resolve to proper IP for $TEST_DOMAIN_ALT2, got $RES_IP_ALT2." | ||
46 | exit 1 | ||
47 | fi | ||
diff --git a/src/gns/test_gns_simple_lookup.c b/src/gns/test_gns_simple_lookup.c deleted file mode 100644 index cc2abeff7..000000000 --- a/src/gns/test_gns_simple_lookup.c +++ /dev/null | |||
@@ -1,286 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2012 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_lookup.c | ||
22 | * @brief base testcase for testing a local GNS record lookup | ||
23 | * @author Martin Schanzenbach | ||
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 "gnunet_dnsparser_lib.h" | ||
32 | #include "gnunet_gns_service.h" | ||
33 | |||
34 | |||
35 | /** | ||
36 | * Timeout for entire testcase | ||
37 | */ | ||
38 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 120) | ||
39 | |||
40 | /* test records to resolve */ | ||
41 | #define TEST_DOMAIN "www.gnu" | ||
42 | #define TEST_IP "127.0.0.1" | ||
43 | #define TEST_RECORD_NAME "www" | ||
44 | |||
45 | /** | ||
46 | * Task handle to use to schedule test failure | ||
47 | */ | ||
48 | static GNUNET_SCHEDULER_TaskIdentifier die_task; | ||
49 | |||
50 | /** | ||
51 | * Global return value (0 for success, anything else for failure) | ||
52 | */ | ||
53 | static int ok; | ||
54 | |||
55 | static struct GNUNET_NAMESTORE_Handle *namestore_handle; | ||
56 | |||
57 | static struct GNUNET_GNS_Handle *gns_handle; | ||
58 | |||
59 | static const struct GNUNET_CONFIGURATION_Handle *cfg; | ||
60 | |||
61 | static struct GNUNET_GNS_LookupRequest *lr; | ||
62 | |||
63 | static struct GNUNET_NAMESTORE_QueueEntry *nsqe; | ||
64 | |||
65 | |||
66 | /** | ||
67 | * Check if the get_handle is being used, if so stop the request. Either | ||
68 | * way, schedule the end_badly_cont function which actually shuts down the | ||
69 | * test. | ||
70 | */ | ||
71 | static void | ||
72 | end_badly (void *cls, | ||
73 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
74 | { | ||
75 | if (NULL != nsqe) | ||
76 | { | ||
77 | GNUNET_NAMESTORE_cancel (nsqe); | ||
78 | nsqe = NULL; | ||
79 | } | ||
80 | if (NULL != lr) | ||
81 | { | ||
82 | GNUNET_GNS_cancel_lookup_request (lr); | ||
83 | lr = NULL; | ||
84 | } | ||
85 | if (NULL != gns_handle) | ||
86 | { | ||
87 | GNUNET_GNS_disconnect (gns_handle); | ||
88 | gns_handle = NULL; | ||
89 | } | ||
90 | |||
91 | if (NULL != namestore_handle) | ||
92 | { | ||
93 | GNUNET_NAMESTORE_disconnect (namestore_handle); | ||
94 | namestore_handle = NULL; | ||
95 | } | ||
96 | GNUNET_break (0); | ||
97 | GNUNET_SCHEDULER_shutdown (); | ||
98 | ok = 1; | ||
99 | } | ||
100 | |||
101 | |||
102 | static void | ||
103 | end_badly_now () | ||
104 | { | ||
105 | GNUNET_SCHEDULER_cancel (die_task); | ||
106 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
107 | } | ||
108 | |||
109 | |||
110 | static void | ||
111 | shutdown_task (void *cls, | ||
112 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
113 | { | ||
114 | GNUNET_GNS_disconnect (gns_handle); | ||
115 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Shutting down peer!\n"); | ||
116 | GNUNET_SCHEDULER_shutdown (); | ||
117 | } | ||
118 | |||
119 | |||
120 | /** | ||
121 | * Function called on result for a GNS lookup | ||
122 | * | ||
123 | * @param cls closure, unused | ||
124 | * @param rd_count number of records | ||
125 | * @param rd the records in reply | ||
126 | */ | ||
127 | static void | ||
128 | on_lookup_result(void *cls, uint32_t rd_count, | ||
129 | const struct GNUNET_NAMESTORE_RecordData *rd) | ||
130 | { | ||
131 | struct in_addr a; | ||
132 | uint32_t i; | ||
133 | char* addr; | ||
134 | |||
135 | lr = NULL; | ||
136 | if (GNUNET_SCHEDULER_NO_TASK != die_task) | ||
137 | { | ||
138 | GNUNET_SCHEDULER_cancel (die_task); | ||
139 | die_task = GNUNET_SCHEDULER_NO_TASK; | ||
140 | } | ||
141 | GNUNET_NAMESTORE_disconnect (namestore_handle); | ||
142 | namestore_handle = NULL; | ||
143 | if (rd_count == 0) | ||
144 | { | ||
145 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
146 | "Lookup failed, rp_filtering?\n"); | ||
147 | ok = 2; | ||
148 | } | ||
149 | else | ||
150 | { | ||
151 | ok = 1; | ||
152 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "name: %s\n", (char*)cls); | ||
153 | for (i=0; i<rd_count; i++) | ||
154 | { | ||
155 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "type: %d\n", rd[i].record_type); | ||
156 | if (rd[i].record_type == GNUNET_DNSPARSER_TYPE_A) | ||
157 | { | ||
158 | memcpy (&a, rd[i].data, sizeof(a)); | ||
159 | addr = inet_ntoa(a); | ||
160 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "address: %s\n", addr); | ||
161 | if (0 == strcmp (addr, TEST_IP)) | ||
162 | { | ||
163 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
164 | "%s correctly resolved to %s!\n", | ||
165 | TEST_DOMAIN, addr); | ||
166 | ok = 0; | ||
167 | } | ||
168 | } | ||
169 | else | ||
170 | { | ||
171 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
172 | "No resolution!\n"); | ||
173 | } | ||
174 | } | ||
175 | } | ||
176 | GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); | ||
177 | } | ||
178 | |||
179 | |||
180 | /** | ||
181 | * Function scheduled to be run on the successful start of services | ||
182 | * tries to look up the dns record for TEST_DOMAIN | ||
183 | * | ||
184 | * @param cls closure | ||
185 | * @param success GNUNET_SYSERR on failure (including timeout/queue drop/failure to validate) | ||
186 | * GNUNET_NO if content was already there or not found | ||
187 | * GNUNET_YES (or other positive value) on success | ||
188 | * @param emsg NULL on success, otherwise an error message | ||
189 | */ | ||
190 | static void | ||
191 | commence_testing (void *cls, | ||
192 | int32_t success, | ||
193 | const char *emsg) | ||
194 | { | ||
195 | nsqe = NULL; | ||
196 | if (NULL != emsg) | ||
197 | { | ||
198 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
199 | "Failed to store record in namestore: %s\n", | ||
200 | emsg); | ||
201 | end_badly_now (); | ||
202 | return; | ||
203 | } | ||
204 | gns_handle = GNUNET_GNS_connect (cfg); | ||
205 | if (NULL == gns_handle) | ||
206 | { | ||
207 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
208 | "Failed to connect to GNS!\n"); | ||
209 | end_badly_now (); | ||
210 | return; | ||
211 | } | ||
212 | lr = GNUNET_GNS_lookup (gns_handle, TEST_DOMAIN, GNUNET_DNSPARSER_TYPE_A, | ||
213 | GNUNET_YES, | ||
214 | NULL, | ||
215 | &on_lookup_result, TEST_DOMAIN); | ||
216 | } | ||
217 | |||
218 | |||
219 | static void | ||
220 | do_check (void *cls, | ||
221 | const struct GNUNET_CONFIGURATION_Handle *ccfg, | ||
222 | struct GNUNET_TESTING_Peer *peer) | ||
223 | { | ||
224 | struct GNUNET_CRYPTO_EccPublicSignKey alice_pkey; | ||
225 | struct GNUNET_CRYPTO_EccPrivateKey *alice_key; | ||
226 | struct GNUNET_NAMESTORE_RecordData rd; | ||
227 | char* alice_keyfile; | ||
228 | char* ip = TEST_IP; | ||
229 | struct in_addr web; | ||
230 | |||
231 | cfg = ccfg; | ||
232 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); | ||
233 | |||
234 | /* put records into namestore */ | ||
235 | namestore_handle = GNUNET_NAMESTORE_connect(cfg); | ||
236 | if (NULL == namestore_handle) | ||
237 | { | ||
238 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
239 | "Failed to connect to namestore\n"); | ||
240 | end_badly_now (); | ||
241 | return; | ||
242 | } | ||
243 | if (GNUNET_OK != | ||
244 | GNUNET_CONFIGURATION_get_value_filename (cfg, "gns", | ||
245 | "ZONEKEY", | ||
246 | &alice_keyfile)) | ||
247 | { | ||
248 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
249 | "Failed to get key from cfg\n"); | ||
250 | end_badly_now (); | ||
251 | return; | ||
252 | } | ||
253 | |||
254 | alice_key = GNUNET_CRYPTO_ecc_key_create_from_file (alice_keyfile); | ||
255 | GNUNET_CRYPTO_ecc_key_get_public_for_signature (alice_key, &alice_pkey); | ||
256 | GNUNET_free (alice_keyfile); | ||
257 | rd.expiration_time = UINT64_MAX; | ||
258 | GNUNET_assert (1 == inet_pton (AF_INET, ip, &web)); | ||
259 | rd.data_size = sizeof(struct in_addr); | ||
260 | rd.data = &web; | ||
261 | rd.record_type = GNUNET_DNSPARSER_TYPE_A; | ||
262 | rd.flags = GNUNET_NAMESTORE_RF_NONE; | ||
263 | nsqe = GNUNET_NAMESTORE_record_put_by_authority (namestore_handle, | ||
264 | alice_key, | ||
265 | TEST_RECORD_NAME, | ||
266 | 1, &rd, | ||
267 | &commence_testing, | ||
268 | NULL); | ||
269 | GNUNET_free (alice_key); | ||
270 | } | ||
271 | |||
272 | |||
273 | int | ||
274 | main (int argc, char *argv[]) | ||
275 | { | ||
276 | ok = 1; | ||
277 | GNUNET_log_setup ("test-gns-simple-lookup", | ||
278 | "WARNING", | ||
279 | NULL); | ||
280 | GNUNET_TESTING_peer_run ("test-gns-simple-lookup", | ||
281 | "test_gns_simple_lookup.conf", | ||
282 | &do_check, NULL); | ||
283 | return ok; | ||
284 | } | ||
285 | |||
286 | /* end of test_gns_simple_lookup.c */ | ||
diff --git a/src/gns/test_gns_simple_mx_lookup.c b/src/gns/test_gns_simple_mx_lookup.c deleted file mode 100644 index a7eec0a64..000000000 --- a/src/gns/test_gns_simple_mx_lookup.c +++ /dev/null | |||
@@ -1,301 +0,0 @@ | |||
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_mx_lookup.c | ||
22 | * @brief base testcase for testing GNS MX lookups | ||
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 | /* Timeout for entire testcase */ | ||
36 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 20) | ||
37 | |||
38 | /* test records to resolve */ | ||
39 | #define TEST_DOMAIN "bob.gnu" | ||
40 | #define TEST_IP "127.0.0.1" | ||
41 | #define TEST_RECORD_NAME "mail" | ||
42 | #define TEST_MX_NAME "mail.+" | ||
43 | #define TEST_EXPECTED_MX "mail.bob.gnu" | ||
44 | |||
45 | #define TEST_AUTHORITY_NAME "bob" | ||
46 | |||
47 | #define KEYFILE_BOB "../namestore/zonefiles/HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey" | ||
48 | |||
49 | /* Task handle to use to schedule test failure */ | ||
50 | static GNUNET_SCHEDULER_TaskIdentifier die_task; | ||
51 | |||
52 | /* Global return value (0 for success, anything else for failure) */ | ||
53 | static int ok; | ||
54 | |||
55 | static struct GNUNET_NAMESTORE_Handle *namestore_handle; | ||
56 | |||
57 | static struct GNUNET_GNS_Handle *gns_handle; | ||
58 | |||
59 | static const struct GNUNET_CONFIGURATION_Handle *cfg; | ||
60 | |||
61 | |||
62 | /** | ||
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. | ||
66 | */ | ||
67 | static void | ||
68 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
69 | { | ||
70 | die_task = GNUNET_SCHEDULER_NO_TASK; | ||
71 | if (NULL != gns_handle) | ||
72 | { | ||
73 | GNUNET_GNS_disconnect(gns_handle); | ||
74 | gns_handle = NULL; | ||
75 | } | ||
76 | |||
77 | if (NULL != namestore_handle) | ||
78 | { | ||
79 | GNUNET_NAMESTORE_disconnect (namestore_handle); | ||
80 | namestore_handle = NULL; | ||
81 | } | ||
82 | GNUNET_break (0); | ||
83 | GNUNET_SCHEDULER_shutdown (); | ||
84 | ok = 1; | ||
85 | } | ||
86 | |||
87 | |||
88 | static void | ||
89 | end_badly_now () | ||
90 | { | ||
91 | GNUNET_SCHEDULER_cancel (die_task); | ||
92 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
93 | } | ||
94 | |||
95 | |||
96 | static void | ||
97 | shutdown_task (void *cls, | ||
98 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
99 | { | ||
100 | GNUNET_GNS_disconnect(gns_handle); | ||
101 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Shutting down peer!\n"); | ||
102 | GNUNET_SCHEDULER_shutdown (); | ||
103 | } | ||
104 | |||
105 | |||
106 | static void | ||
107 | on_lookup_result(void *cls, uint32_t rd_count, | ||
108 | const struct GNUNET_NAMESTORE_RecordData *rd) | ||
109 | { | ||
110 | int i; | ||
111 | uint16_t mx_preference; | ||
112 | char* mx; | ||
113 | |||
114 | if (GNUNET_SCHEDULER_NO_TASK != die_task) | ||
115 | { | ||
116 | GNUNET_SCHEDULER_cancel (die_task); | ||
117 | die_task = GNUNET_SCHEDULER_NO_TASK; | ||
118 | } | ||
119 | |||
120 | GNUNET_NAMESTORE_disconnect (namestore_handle); | ||
121 | if (rd_count == 0) | ||
122 | { | ||
123 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
124 | "Lookup failed, rp_filtering?\n"); | ||
125 | ok = 2; | ||
126 | } | ||
127 | else | ||
128 | { | ||
129 | ok = 1; | ||
130 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "name: %s\n", (char*)cls); | ||
131 | for (i=0; i<rd_count; i++) | ||
132 | { | ||
133 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "type: %d\n", rd[i].record_type); | ||
134 | if (rd[i].record_type == GNUNET_DNSPARSER_TYPE_MX) | ||
135 | { | ||
136 | mx = (char*)rd[i].data+sizeof(uint16_t); | ||
137 | mx_preference = *(uint16_t*)rd[i].data; | ||
138 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
139 | "Got MX %s with preference %d\n", mx, mx_preference); | ||
140 | if (0 == strcmp(mx, TEST_EXPECTED_MX)) | ||
141 | { | ||
142 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
143 | "%s correctly resolved to %s!\n", TEST_DOMAIN, | ||
144 | TEST_EXPECTED_MX); | ||
145 | ok = 0; | ||
146 | } | ||
147 | } | ||
148 | } | ||
149 | } | ||
150 | |||
151 | GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); | ||
152 | |||
153 | } | ||
154 | |||
155 | |||
156 | /** | ||
157 | * Function scheduled to be run on the successful start of services | ||
158 | * tries to look up the dns record for TEST_DOMAIN | ||
159 | */ | ||
160 | static void | ||
161 | commence_testing (void *cls, int32_t success, const char *emsg) | ||
162 | { | ||
163 | gns_handle = GNUNET_GNS_connect(cfg); | ||
164 | if (NULL == gns_handle) | ||
165 | { | ||
166 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
167 | "Failed to connect to GNS!\n"); | ||
168 | end_badly_now(); | ||
169 | return; | ||
170 | } | ||
171 | GNUNET_GNS_lookup(gns_handle, TEST_DOMAIN, GNUNET_DNSPARSER_TYPE_MX, | ||
172 | GNUNET_NO, | ||
173 | NULL, | ||
174 | &on_lookup_result, TEST_DOMAIN); | ||
175 | } | ||
176 | |||
177 | |||
178 | static void | ||
179 | do_check (void *cls, | ||
180 | const struct GNUNET_CONFIGURATION_Handle *ccfg, | ||
181 | struct GNUNET_TESTING_Peer *peer) | ||
182 | { | ||
183 | struct GNUNET_CRYPTO_EccPublicSignKey alice_pkey; | ||
184 | struct GNUNET_CRYPTO_EccPublicSignKey bob_pkey; | ||
185 | struct GNUNET_CRYPTO_EccPrivateKey *alice_key; | ||
186 | struct GNUNET_CRYPTO_EccPrivateKey *bob_key; | ||
187 | struct GNUNET_CRYPTO_ShortHashCode bob_hash; | ||
188 | struct GNUNET_CRYPTO_EccSignature *sig; | ||
189 | char* alice_keyfile; | ||
190 | struct GNUNET_TIME_Absolute et; | ||
191 | |||
192 | cfg = ccfg; | ||
193 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); | ||
194 | |||
195 | /* put records into namestore */ | ||
196 | namestore_handle = GNUNET_NAMESTORE_connect(cfg); | ||
197 | if (NULL == namestore_handle) | ||
198 | { | ||
199 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to connect to namestore\n"); | ||
200 | end_badly_now(); | ||
201 | return; | ||
202 | } | ||
203 | |||
204 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns", | ||
205 | "ZONEKEY", | ||
206 | &alice_keyfile)) | ||
207 | { | ||
208 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to get key from cfg\n"); | ||
209 | end_badly_now(); | ||
210 | return; | ||
211 | } | ||
212 | |||
213 | alice_key = GNUNET_CRYPTO_ecc_key_create_from_file (alice_keyfile); | ||
214 | bob_key = GNUNET_CRYPTO_ecc_key_create_from_file (KEYFILE_BOB); | ||
215 | |||
216 | GNUNET_CRYPTO_ecc_key_get_public_for_signature (alice_key, &alice_pkey); | ||
217 | GNUNET_CRYPTO_ecc_key_get_public_for_signature (bob_key, &bob_pkey); | ||
218 | |||
219 | struct GNUNET_NAMESTORE_RecordData rd; | ||
220 | char* ip = TEST_IP; | ||
221 | struct in_addr *mail = GNUNET_malloc(sizeof(struct in_addr)); | ||
222 | char *mx_record; | ||
223 | uint16_t mx_preference = 1; | ||
224 | rd.expiration_time = UINT64_MAX; | ||
225 | GNUNET_assert(1 == inet_pton (AF_INET, ip, mail)); | ||
226 | |||
227 | GNUNET_CRYPTO_short_hash(&bob_pkey, sizeof(bob_pkey), &bob_hash); | ||
228 | |||
229 | rd.data_size = sizeof(struct GNUNET_CRYPTO_ShortHashCode); | ||
230 | rd.data = &bob_hash; | ||
231 | rd.record_type = GNUNET_NAMESTORE_TYPE_PKEY; | ||
232 | rd.flags = GNUNET_NAMESTORE_RF_NONE; | ||
233 | |||
234 | GNUNET_NAMESTORE_record_put_by_authority (namestore_handle, | ||
235 | alice_key, | ||
236 | TEST_AUTHORITY_NAME, | ||
237 | 1, &rd, | ||
238 | NULL, | ||
239 | NULL); | ||
240 | |||
241 | rd.data_size = sizeof(struct in_addr); | ||
242 | rd.data = mail; | ||
243 | rd.record_type = GNUNET_DNSPARSER_TYPE_A; | ||
244 | sig = GNUNET_NAMESTORE_create_signature(bob_key, | ||
245 | GNUNET_TIME_UNIT_FOREVER_ABS, | ||
246 | TEST_RECORD_NAME, | ||
247 | &rd, 1); | ||
248 | et.abs_value_us = rd.expiration_time; | ||
249 | GNUNET_NAMESTORE_record_put (namestore_handle, | ||
250 | &bob_pkey, | ||
251 | TEST_RECORD_NAME, | ||
252 | et, | ||
253 | 1, | ||
254 | &rd, | ||
255 | sig, | ||
256 | NULL, | ||
257 | NULL); | ||
258 | GNUNET_free (sig); | ||
259 | |||
260 | rd.data_size = sizeof(struct GNUNET_DNSPARSER_MxRecord)+strlen(TEST_MX_NAME)+1; | ||
261 | mx_record = GNUNET_malloc(sizeof(struct GNUNET_DNSPARSER_MxRecord)+strlen(TEST_MX_NAME)+1); | ||
262 | memcpy(mx_record, &mx_preference, sizeof(uint16_t)); | ||
263 | strcpy(mx_record+sizeof(uint16_t), TEST_MX_NAME); | ||
264 | rd.data = mx_record; | ||
265 | rd.record_type = GNUNET_DNSPARSER_TYPE_MX; | ||
266 | sig = GNUNET_NAMESTORE_create_signature(bob_key, | ||
267 | GNUNET_TIME_UNIT_FOREVER_ABS, | ||
268 | GNUNET_GNS_MASTERZONE_STR, | ||
269 | &rd, 1); | ||
270 | et.abs_value_us = rd.expiration_time; | ||
271 | GNUNET_NAMESTORE_record_put (namestore_handle, | ||
272 | &bob_pkey, | ||
273 | GNUNET_GNS_MASTERZONE_STR, | ||
274 | et, | ||
275 | 1, | ||
276 | &rd, | ||
277 | sig, | ||
278 | &commence_testing, | ||
279 | NULL); | ||
280 | |||
281 | GNUNET_free (alice_keyfile); | ||
282 | GNUNET_free (mx_record); | ||
283 | GNUNET_free (mail); | ||
284 | GNUNET_free (sig); | ||
285 | GNUNET_free (bob_key); | ||
286 | GNUNET_free (alice_key); | ||
287 | } | ||
288 | |||
289 | |||
290 | int | ||
291 | main (int argc, char *argv[]) | ||
292 | { | ||
293 | ok = 1; | ||
294 | GNUNET_log_setup ("test-gns-simple-mx-lookup", | ||
295 | "WARNING", | ||
296 | NULL); | ||
297 | GNUNET_TESTING_peer_run ("test-gns-simple-mx-lookup", "test_gns_simple_lookup.conf", &do_check, NULL); | ||
298 | return ok; | ||
299 | } | ||
300 | |||
301 | /* end of test_gns_simple_mx_lookup.c */ | ||