gnunet

Main GNUnet Logic
Log | Files | Refs | Submodules | README | LICENSE

commit 1f5714ff6c83585cb7cd701ca3b7176ef42d3e60
parent 0773a954d6ed9a5c155b9cbceca7a6a316400ba6
Author: Christian Grothoff <christian@grothoff.org>
Date:   Fri, 27 Sep 2013 16:37:56 +0000

using DNS2GNS record type instead of recycling NS record type in GNS; fixing testcase by properly converting DNS records back to GNS blocks

Diffstat:
Msrc/gns/gnunet-gns.c | 15+++++++++++++--
Msrc/gns/gnunet-service-gns_interceptor.c | 9++++++++-
Msrc/gns/gnunet-service-gns_resolver.c | 24++++++++++++++++++++++--
Msrc/gns/test_gns_ns_lookup.sh | 16++++++++--------
Msrc/include/gnunet_namestore_service.h | 5+++++
Msrc/namestore/namestore_api_common.c | 42+++++++++++++++++++++++++++++++++++++++++-
6 files changed, 97 insertions(+), 14 deletions(-)

diff --git a/src/gns/gnunet-gns.c b/src/gns/gnunet-gns.c @@ -133,7 +133,7 @@ do_shutdown (void *cls, * * @param cls the 'const char *' name that was resolved * @param rd_count number of records returned - * @param rd array of 'rd_count' records with the results + * @param rd array of @a rd_count records with the results */ static void process_lookup_result (void *cls, uint32_t rd_count, @@ -155,10 +155,21 @@ process_lookup_result (void *cls, uint32_t rd_count, } for (i=0; i<rd_count; i++) { + if ( (rd[i].record_type != rtype) && + (GNUNET_NAMESTORE_TYPE_ANY != rtype) ) + continue; typename = GNUNET_NAMESTORE_number_to_typename (rd[i].record_type); string_val = GNUNET_NAMESTORE_value_to_string (rd[i].record_type, rd[i].data, rd[i].data_size); + if (NULL == string_val) + { + fprintf (stderr, + "Record %u of type %d malformed, skipping\n", + (unsigned int) i, + (int) rd[i].record_type); + continue; + } if (raw) printf ("%s\n", string_val); @@ -166,7 +177,7 @@ process_lookup_result (void *cls, uint32_t rd_count, printf ("Got `%s' record: %s\n", typename, string_val); - GNUNET_free_non_null (string_val); + GNUNET_free (string_val); } GNUNET_SCHEDULER_shutdown (); } diff --git a/src/gns/gnunet-service-gns_interceptor.c b/src/gns/gnunet-service-gns_interceptor.c @@ -135,13 +135,16 @@ reply_to_dns (void *cls, uint32_t rd_count, case GNUNET_DNSPARSER_TYPE_NS: case GNUNET_DNSPARSER_TYPE_CNAME: case GNUNET_DNSPARSER_TYPE_PTR: + // FIXME: NO! need to use DNSPARSER! answer_records[i].data.hostname = (char*)rd[i].data; break; case GNUNET_DNSPARSER_TYPE_SOA: + // FIXME: NO! need to use DNSPARSER! answer_records[i].data.soa = (struct GNUNET_DNSPARSER_SoaRecord *)rd[i].data; break; case GNUNET_DNSPARSER_TYPE_MX: + // FIXME: NO! need to use DNSPARSER! answer_records[i].data.mx = (struct GNUNET_DNSPARSER_MxRecord *)rd[i].data; break; @@ -163,17 +166,21 @@ reply_to_dns (void *cls, uint32_t rd_count, case GNUNET_DNSPARSER_TYPE_NS: case GNUNET_DNSPARSER_TYPE_CNAME: case GNUNET_DNSPARSER_TYPE_PTR: + // FIXME: NO! need to use DNSPARSER! additional_records[i].data.hostname = (char*)rd[i].data; break; case GNUNET_DNSPARSER_TYPE_SOA: + // FIXME: NO! need to use DNSPARSER! additional_records[i].data.soa = (struct GNUNET_DNSPARSER_SoaRecord *)rd[i].data; break; case GNUNET_DNSPARSER_TYPE_MX: + // FIXME: NO! need to use DNSPARSER! additional_records[i].data.mx = (struct GNUNET_DNSPARSER_MxRecord *)rd[i].data; break; default: + // FIXME: NO! need to use DNSPARSER! additional_records[i].data.raw.data_len = rd[i].data_size; additional_records[i].data.raw.data = (char*)rd[i].data; break; @@ -288,7 +295,7 @@ handle_dns_request (void *cls, * * @param gnu_zone the zone to work in * @param c the configuration - * @return GNUNET_OK on success + * @return #GNUNET_OK on success */ int GNS_interceptor_init (const struct GNUNET_CRYPTO_EccPublicSignKey *gnu_zone, diff --git a/src/gns/gnunet-service-gns_resolver.c b/src/gns/gnunet-service-gns_resolver.c @@ -752,6 +752,7 @@ dns_result_parser (void *cls, unsigned int skip; char buf[UINT16_MAX]; size_t buf_off; + size_t buf_start; buf_off = 0; skip = 0; @@ -804,6 +805,7 @@ dns_result_parser (void *cls, case GNUNET_DNSPARSER_TYPE_CNAME: case GNUNET_DNSPARSER_TYPE_PTR: case GNUNET_DNSPARSER_TYPE_NS: + buf_start = buf_off; if (GNUNET_OK != GNUNET_DNSPARSER_builder_add_name (buf, sizeof (buf), @@ -814,8 +816,11 @@ dns_result_parser (void *cls, skip++; continue; } + rd[i - skip].data_size = buf_off - buf_start; + rd[i - skip].data = &buf[buf_start]; break; case GNUNET_DNSPARSER_TYPE_SOA: + buf_start = buf_off; if (GNUNET_OK != GNUNET_DNSPARSER_builder_add_soa (buf, sizeof (buf), @@ -826,8 +831,11 @@ dns_result_parser (void *cls, skip++; continue; } + rd[i - skip].data_size = buf_off - buf_start; + rd[i - skip].data = &buf[buf_start]; break; case GNUNET_DNSPARSER_TYPE_MX: + buf_start = buf_off; if (GNUNET_OK != GNUNET_DNSPARSER_builder_add_mx (buf, sizeof (buf), @@ -838,8 +846,11 @@ dns_result_parser (void *cls, skip++; continue; } + rd[i - skip].data_size = buf_off - buf_start; + rd[i - skip].data = &buf[buf_start]; break; case GNUNET_DNSPARSER_TYPE_SRV: + buf_start = buf_off; if (GNUNET_OK != GNUNET_DNSPARSER_builder_add_srv (buf, sizeof (buf), @@ -850,6 +861,8 @@ dns_result_parser (void *cls, skip++; continue; } + rd[i - skip].data_size = buf_off - buf_start; + rd[i - skip].data = &buf[buf_start]; break; default: GNUNET_log (GNUNET_ERROR_TYPE_INFO, @@ -1197,6 +1210,11 @@ handle_gns_resolution_result (void *cls, rh); return; } + case GNUNET_NAMESTORE_TYPE_GNS2DNS: + { + /* delegation to DNS */ + goto do_recurse; + } default: break; } @@ -1392,6 +1410,7 @@ handle_gns_resolution_result (void *cls, GNS_resolver_lookup_cancel (rh); return; } + do_recurse: /* need to recurse, check if we can */ for (i=0;i<rd_count;i++) { @@ -1428,7 +1447,7 @@ handle_gns_resolution_result (void *cls, rh->task_id = GNUNET_SCHEDULER_add_now (&recursive_resolution, rh); return; - case GNUNET_DNSPARSER_TYPE_NS: + case GNUNET_NAMESTORE_TYPE_GNS2DNS: { char *ns; /* resolution continues within DNS */ @@ -1527,9 +1546,10 @@ handle_gns_resolution_result (void *cls, created from the remainder of the GNS name and the name in the NS record */ GNUNET_asprintf (&ac->label, - "%.*s.%s", + "%.*s%s%s", (int) rh->name_resolution_pos, rh->name, + (0 != rh->name_resolution_pos) ? "." : "", ns); GNUNET_free (ns); GNUNET_CONTAINER_DLL_insert_tail (rh->ac_head, diff --git a/src/gns/test_gns_ns_lookup.sh b/src/gns/test_gns_ns_lookup.sh @@ -6,18 +6,18 @@ TEST_DOMAIN_ALT="homepage.gnu" TEST_DOMAIN_ALT2="uk.homepage.gnu" TEST_IP_ALT2="81.187.252.184" TEST_IP="131.159.74.67" -TEST_IP_NS="184.172.157.218" +TEST_IP_GNS2DNS="184.172.157.218" TEST_RECORD_NAME="homepage" -TEST_RECORD_NS="gnunet.org" +TEST_RECORD_GNS2DNS="gnunet.org" gnunet-arm -s -c test_gns_lookup.conf gnunet-identity -C testego -c test_gns_lookup.conf -gnunet-namestore -p -z testego -a -n $TEST_RECORD_NAME -t A -V $TEST_IP_NS -e never -c test_gns_lookup.conf -gnunet-namestore -p -z testego -a -n $TEST_RECORD_NAME -t NS -V $TEST_RECORD_NS -e never -c test_gns_lookup.conf +gnunet-namestore -p -z testego -a -n $TEST_RECORD_NAME -t A -V $TEST_IP_GNS2DNS -e never -c test_gns_lookup.conf +gnunet-namestore -p -z testego -a -n $TEST_RECORD_NAME -t GNS2DNS -V $TEST_RECORD_GNS2DNS -e never -c test_gns_lookup.conf RES_IP=$(timeout 5 gnunet-gns --raw -z testego -u $TEST_DOMAIN -t A -c test_gns_lookup.conf) RES_IP_ALT=$(timeout 5 gnunet-gns --raw -z testego -u $TEST_DOMAIN_ALT -t A -c test_gns_lookup.conf) RES_IP_ALT2=$(timeout 5 gnunet-gns --raw -z testego -u $TEST_DOMAIN_ALT2 -t A -c test_gns_lookup.conf) gnunet-namestore -z testego -d -n www -t A -V $TEST_IP -e never -c test_gns_lookup.conf -gnunet-namestore -z testego -d -n $TEST_RECORD_NAME -t NS -V $TEST_RECORD_NS -e never -c test_gns_lookup.conf +gnunet-namestore -z testego -d -n $TEST_RECORD_NAME -t GNS2DNS -V $TEST_RECORD_GNS2DNS -e never -c test_gns_lookup.conf gnunet-identity -D testego -c test_gns_lookup.conf gnunet-arm -e -c test_gns_lookup.conf @@ -25,7 +25,7 @@ if [ "$RES_IP" == "$TEST_IP" ] then echo "PASS: Resolved $TEST_DOMAIN to $RES_IP." else - echo "Failed to resolve to proper IP for $TEST_DOMAIN, got $RES_IP." + echo "Failed to resolve to proper IP for $TEST_DOMAIN, got $RES_IP, wanted $TEST_IP." exit 1 fi @@ -33,7 +33,7 @@ if [ "$RES_IP_ALT" == "$TEST_IP" ] then echo "PASS: Resolved $TEST_DOMAIN_ALT to $RES_IP_ALT." else - echo "Failed to resolve to proper IP for $TEST_DOMAIN_ALT, got $RES_IP_ALT." + echo "Failed to resolve to proper IP for $TEST_DOMAIN_ALT, got $RES_IP_ALT, wanted $TEST_IP." exit 1 fi @@ -42,6 +42,6 @@ then echo "PASS: Resolved $TEST_DOMAIN_ALT2 to $RES_IP_ALT2." exit 0 else - echo "Failed to resolve to proper IP for $TEST_DOMAIN_ALT2, got $RES_IP_ALT2." + echo "Failed to resolve to proper IP for $TEST_DOMAIN_ALT2, got $RES_IP_ALT2, wanted $TEST_IP_ALT2." exit 1 fi diff --git a/src/include/gnunet_namestore_service.h b/src/include/gnunet_namestore_service.h @@ -67,6 +67,11 @@ extern "C" #define GNUNET_NAMESTORE_TYPE_VPN 65539 /** + * Record type for delegation to DNS. + */ +#define GNUNET_NAMESTORE_TYPE_GNS2DNS 65540 + +/** * Record type for a social place. */ #define GNUNET_NAMESTORE_TYPE_PLACE 65541 diff --git a/src/namestore/namestore_api_common.c b/src/namestore/namestore_api_common.c @@ -501,7 +501,7 @@ GNUNET_NAMESTORE_block_decrypt (const struct GNUNET_NAMESTORE_Block *block, * * @param type type of the record * @param data value in binary encoding - * @param data_size number of bytes in data + * @param data_size number of bytes in @a data * @return NULL on error, otherwise human-readable representation of the value */ char * @@ -661,6 +661,23 @@ GNUNET_NAMESTORE_value_to_string (uint32_t type, } return vpn_str; } + case GNUNET_NAMESTORE_TYPE_GNS2DNS: + { + char *ns; + size_t off; + + off = 0; + ns = GNUNET_DNSPARSER_parse_name (data, + data_size, + &off); + if ( (NULL == ns) || + (off != data_size) ) + { + GNUNET_break_op (0); + return NULL; + } + return ns; + } case GNUNET_DNSPARSER_TYPE_SRV: { struct GNUNET_DNSPARSER_SrvRecord *srv; @@ -971,6 +988,28 @@ GNUNET_NAMESTORE_string_to_value (uint32_t type, vpn->proto = htons ((uint16_t) proto); strcpy ((char*)&vpn[1], s_serv); return GNUNET_OK; + case GNUNET_NAMESTORE_TYPE_GNS2DNS: + { + char nsbuf[256]; + size_t off; + + off = 0; + if (GNUNET_OK != + GNUNET_DNSPARSER_builder_add_name (nsbuf, + sizeof (nsbuf), + &off, + s)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _("Failed to serialize GNS2DNS record with value `%s'\n"), + s); + return GNUNET_SYSERR; + } + *data_size = off; + *data = GNUNET_malloc (off); + memcpy (*data, nsbuf, off); + return GNUNET_OK; + } case GNUNET_DNSPARSER_TYPE_TLSA: *data_size = sizeof (struct GNUNET_TUN_DnsTlsaRecord) + strlen (s) - 6; *data = tlsa = GNUNET_malloc (*data_size); @@ -1017,6 +1056,7 @@ static struct { { "PSEU", GNUNET_NAMESTORE_TYPE_PSEU }, { "LEHO", GNUNET_NAMESTORE_TYPE_LEHO }, { "VPN", GNUNET_NAMESTORE_TYPE_VPN }, + { "GNS2DNS", GNUNET_NAMESTORE_TYPE_GNS2DNS }, { "TLSA", GNUNET_DNSPARSER_TYPE_TLSA }, { NULL, UINT32_MAX } };