From 07d9f23fd354b893e85daa440270d191ef261086 Mon Sep 17 00:00:00 2001 From: Martin Schanzenbach Date: Fri, 16 Mar 2012 17:47:23 +0000 Subject: [PATCH] -mx,cname,ns postprocessing + test --- src/gns/Makefile.am | 14 + src/gns/gnunet-service-gns_resolver.c | 64 ++++- src/gns/test_gns_simple_mx_lookup.c | 384 ++++++++++++++++++++++++++ 3 files changed, 448 insertions(+), 14 deletions(-) create mode 100644 src/gns/test_gns_simple_mx_lookup.c diff --git a/src/gns/Makefile.am b/src/gns/Makefile.am index d31d5c4b1..a13296ea7 100644 --- a/src/gns/Makefile.am +++ b/src/gns/Makefile.am @@ -35,6 +35,7 @@ check_PROGRAMS = \ test_gns_simple_get_authority \ test_gns_simple_lookup \ test_gns_simple_delegated_lookup \ + test_gns_simple_mx_lookup \ test_gns_dht_delegated_lookup \ test_gns_pseu_shorten @@ -84,6 +85,19 @@ test_gns_simple_delegated_lookup_DEPENDENCIES = \ $(top_builddir)/src/gns/libgnunetgns.la \ $(top_builddir)/src/testing/libgnunettesting.la +test_gns_simple_mx_lookup_SOURCES = \ + test_gns_simple_mx_lookup.c +test_gns_simple_mx_lookup_LDADD = \ + $(top_builddir)/src/util/libgnunetutil.la \ + $(top_builddir)/src/namestore/libgnunetnamestore.la \ + $(top_builddir)/src/gns/libgnunetgns.la \ + $(top_builddir)/src/testing/libgnunettesting.la +test_gns_simple_mx_lookup_DEPENDENCIES = \ + $(top_builddir)/src/util/libgnunetutil.la \ + $(top_builddir)/src/namestore/libgnunetnamestore.la \ + $(top_builddir)/src/gns/libgnunetgns.la \ + $(top_builddir)/src/testing/libgnunettesting.la + test_gns_dht_delegated_lookup_SOURCES = \ test_gns_dht_delegated_lookup.c test_gns_dht_delegated_lookup_LDADD = \ diff --git a/src/gns/gnunet-service-gns_resolver.c b/src/gns/gnunet-service-gns_resolver.c index 8a3ef9a67..f30f67b57 100644 --- a/src/gns/gnunet-service-gns_resolver.c +++ b/src/gns/gnunet-service-gns_resolver.c @@ -946,7 +946,9 @@ process_delegation_result_dht(void* cls, * finish lookup */ static void -finish_lookup(struct RecordLookupHandle* rlh, unsigned int rd_count, +finish_lookup(struct ResolverHandle *rh, + struct RecordLookupHandle* rlh, + unsigned int rd_count, const struct GNUNET_NAMESTORE_RecordData *rd) { int i; @@ -954,6 +956,8 @@ finish_lookup(struct RecordLookupHandle* rlh, unsigned int rd_count, char new_s_value[256]; int s_len; struct GNUNET_NAMESTORE_RecordData p_rd[rd_count]; + char* pos; + char* trailer; if (rd_count > 0) memcpy(p_rd, rd, rd_count*sizeof(struct GNUNET_NAMESTORE_RecordData)); @@ -968,7 +972,6 @@ finish_lookup(struct RecordLookupHandle* rlh, unsigned int rd_count, p_rd[i].data = rd[i].data; continue; } - /** * for all those records we 'should' @@ -984,13 +987,26 @@ finish_lookup(struct RecordLookupHandle* rlh, unsigned int rd_count, continue; } - if (0 == strcmp(s_value+s_len-2, ".+")) + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Postprocessing %s\n", s_value); + + if (0 == strcmp(s_value+s_len-3, ".+")) { GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Expanding .+ for %s\n", s_value); - memset(new_s_value, 0, s_len+strlen(GNUNET_GNS_TLD)); + "Expanding .+ in %s\n", s_value); + if (strcmp(rh->name, "+") == 0) + { + trailer = rlh->name; + } + else + { + trailer = rlh->name+strlen(rh->name)+1; + } + memset(new_s_value, 0, s_len+strlen(trailer)+strlen(GNUNET_GNS_TLD)); strcpy(new_s_value, s_value); - memcpy(new_s_value+s_len-1, GNUNET_GNS_TLD, strlen(GNUNET_GNS_TLD)); + pos = new_s_value+s_len-2; + strcpy(pos, trailer); + pos += strlen(trailer); p_rd[i].data = new_s_value; p_rd[i].data_size = strlen(new_s_value)+1; GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, @@ -1026,7 +1042,7 @@ handle_record_dht(void* cls, struct ResolverHandle *rh, "No records for %s found in DHT. Aborting\n", rh->name); /* give up, cannot resolve */ - finish_lookup(rlh, 0, NULL); + finish_lookup(rh, rlh, 0, NULL); free_resolver_handle(rh); return; } @@ -1035,7 +1051,7 @@ handle_record_dht(void* cls, struct ResolverHandle *rh, GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Record resolved from DHT!"); - finish_lookup(rlh, rd_count, rd); + finish_lookup(rh, rlh, rd_count, rd); free_resolver_handle(rh); } @@ -1068,7 +1084,7 @@ handle_record_ns(void* cls, struct ResolverHandle *rh, return; } /* give up, cannot resolve */ - finish_lookup(rlh, 0, NULL); + finish_lookup(rh, rlh, 0, NULL); free_resolver_handle(rh); return; } @@ -1077,7 +1093,7 @@ handle_record_ns(void* cls, struct ResolverHandle *rh, GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Record resolved from namestore!"); - finish_lookup(rlh, rd_count, rd); + finish_lookup(rh, rlh, rd_count, rd); free_resolver_handle(rh); } @@ -1158,9 +1174,20 @@ handle_delegation_dht(void* cls, struct ResolverHandle *rh, if (strcmp(rh->name, "") == 0) { + if ((rlh->record_type == GNUNET_GNS_RECORD_PKEY)) + { + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Resolved queried PKEY via DHT.\n"); + finish_lookup(rh, rlh, rd_count, rd); + free_resolver_handle(rh); + return; + } /* We resolved full name for delegation. resolving record */ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Resolved full name for delegation via DHT. resolving record '' in ns\n"); + GNUNET_free(rh->name); + rh->name = GNUNET_malloc(strlen("+")+1); + strcpy(rh->name, "+\0"); rh->proc = &handle_record_ns; resolve_record_ns(rh); return; @@ -1181,9 +1208,7 @@ handle_delegation_dht(void* cls, struct ResolverHandle *rh, GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Cannot fully resolve delegation for %s via DHT!\n", rh->name); - rlh->proc(rlh->proc_cls, 0, NULL); - GNUNET_free(rlh->name); - GNUNET_free(rlh); + finish_lookup(rh, rlh, 0, NULL); free_resolver_handle(rh); } @@ -1244,9 +1269,20 @@ handle_delegation_ns(void* cls, struct ResolverHandle *rh, if (strcmp(rh->name, "") == 0) { + if ((rlh->record_type == GNUNET_GNS_RECORD_PKEY)) + { + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Resolved queried PKEY in NS.\n"); + finish_lookup(rh, rlh, rd_count, rd); + free_resolver_handle(rh); + return; + } /* We resolved full name for delegation. resolving record */ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Resolved full name for delegation. resolving record ''\n"); + "Resolved full name for delegation. resolving record '+'\n"); + GNUNET_free(rh->name); + rh->name = GNUNET_malloc(strlen("+")+1); + strcpy(rh->name, "+\0"); rh->proc = &handle_record_ns; resolve_record_ns(rh); return; diff --git a/src/gns/test_gns_simple_mx_lookup.c b/src/gns/test_gns_simple_mx_lookup.c new file mode 100644 index 000000000..1f39b175f --- /dev/null +++ b/src/gns/test_gns_simple_mx_lookup.c @@ -0,0 +1,384 @@ +/* + This file is part of GNUnet. + (C) 2009 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3, or (at your + option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNUnet; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ +/** + * @file gns/test_gns_simple_mx_lookup.c + * @brief base testcase for testing GNS MX lookups + * + */ +#include "platform.h" +#include "gnunet_testing_lib.h" +#include "gnunet_core_service.h" +#include "block_dns.h" +#include "gnunet_signatures.h" +#include "gnunet_namestore_service.h" +#include "../namestore/namestore.h" +#include "gnunet_dnsparser_lib.h" +#include "gnunet_gns_service.h" + +/* DEFINES */ +#define VERBOSE GNUNET_YES + +/* Timeout for entire testcase */ +#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5) + +/* If number of peers not in config file, use this number */ +#define DEFAULT_NUM_PEERS 2 + +/* test records to resolve */ +#define TEST_DOMAIN "bob.gnunet" +#define TEST_IP "127.0.0.1" +#define TEST_RECORD_NAME "mail" +#define TEST_MX_NAME "mail.+" +#define TEST_EXPECTED_MX "mail.bob.gnunet" + +#define TEST_AUTHORITY_NAME "bob" + +/* Globals */ + +/** + * Directory to store temp data in, defined in config file + */ +static char *test_directory; + +struct GNUNET_TESTING_Daemon *d1; + + +/* Task handle to use to schedule test failure */ +GNUNET_SCHEDULER_TaskIdentifier die_task; + +/* Global return value (0 for success, anything else for failure) */ +static int ok; + +static struct GNUNET_NAMESTORE_Handle *namestore_handle; + +static struct GNUNET_GNS_Handle *gns_handle; + +const struct GNUNET_CONFIGURATION_Handle *cfg; + +/** + * Check whether peers successfully shut down. + */ +void +shutdown_callback (void *cls, const char *emsg) +{ + if (emsg != NULL) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error on shutdown! ret=%d\n", ok); + if (ok == 0) + ok = 2; + } + + GNUNET_log (GNUNET_ERROR_TYPE_INFO, "done(ret=%d)!\n", ok); +} + +static void +on_lookup_result(void *cls, uint32_t rd_count, + const struct GNUNET_NAMESTORE_RecordData *rd) +{ + struct in_addr a; + int i; + char* addr; + int mx_found = 0; + int ip_found = 0; + char* mx; + + if (rd_count == 0) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Lookup failed, rp_filtering?\n"); + ok = 2; + } + else + { + ok = 1; + GNUNET_log (GNUNET_ERROR_TYPE_INFO, "name: %s\n", (char*)cls); + for (i=0; i