aboutsummaryrefslogtreecommitdiff
path: root/src/gns/gnunet-service-gns_resolver.c
diff options
context:
space:
mode:
authorMartin Schanzenbach <mschanzenbach@posteo.de>2012-06-19 14:32:19 +0000
committerMartin Schanzenbach <mschanzenbach@posteo.de>2012-06-19 14:32:19 +0000
commitee6bf88ca9daa63306559c12c2bdc9dedb78a91b (patch)
tree5722149e60ce688a5fd7402241720aca6f7a382c /src/gns/gnunet-service-gns_resolver.c
parent809906cfb208342b0894dbbfa3cb43a102caa42f (diff)
downloadgnunet-ee6bf88ca9daa63306559c12c2bdc9dedb78a91b.tar.gz
gnunet-ee6bf88ca9daa63306559c12c2bdc9dedb78a91b.zip
-ns tests, fixes
Diffstat (limited to 'src/gns/gnunet-service-gns_resolver.c')
-rw-r--r--src/gns/gnunet-service-gns_resolver.c97
1 files changed, 68 insertions, 29 deletions
diff --git a/src/gns/gnunet-service-gns_resolver.c b/src/gns/gnunet-service-gns_resolver.c
index 1c1edaea5..0236c7207 100644
--- a/src/gns/gnunet-service-gns_resolver.c
+++ b/src/gns/gnunet-service-gns_resolver.c
@@ -1325,6 +1325,8 @@ handle_dns_resolver (void *cls,
1325 struct ResolverHandle *rh = cls; 1325 struct ResolverHandle *rh = cls;
1326 struct RecordLookupHandle *rlh = rh->proc_cls; 1326 struct RecordLookupHandle *rlh = rh->proc_cls;
1327 struct GNUNET_NAMESTORE_RecordData rd; 1327 struct GNUNET_NAMESTORE_RecordData rd;
1328 struct sockaddr_in *sai;
1329 struct sockaddr_in6 *sai6;
1328 1330
1329 if (NULL == addr) 1331 if (NULL == addr)
1330 { 1332 {
@@ -1336,16 +1338,25 @@ handle_dns_resolver (void *cls,
1336 } 1338 }
1337 1339
1338 if (addrlen == sizeof (struct sockaddr_in)) 1340 if (addrlen == sizeof (struct sockaddr_in))
1341 {
1342 sai = (struct sockaddr_in*) addr;
1339 rd.record_type = GNUNET_GNS_RECORD_TYPE_A; 1343 rd.record_type = GNUNET_GNS_RECORD_TYPE_A;
1344 rd.data_size = sizeof (struct in_addr);
1345 rd.data = &sai->sin_addr;
1346 }
1340 else 1347 else
1348 {
1349 sai6 = (struct sockaddr_in6*) addr;
1341 rd.record_type = GNUNET_GNS_RECORD_AAAA; 1350 rd.record_type = GNUNET_GNS_RECORD_AAAA;
1351 rd.data_size = sizeof (struct in6_addr);
1352 rd.data = &sai6->sin6_addr;
1353 }
1342 1354
1343 rd.expiration = GNUNET_TIME_UNIT_FOREVER_ABS; 1355 rd.expiration = GNUNET_TIME_UNIT_FOREVER_ABS;
1344 rd.data_size = addrlen;
1345 rd.data = addr;
1346 1356
1347 finish_lookup (rh, rlh, 1, &rd); 1357 finish_lookup (rh, rlh, 1, &rd);
1348 free_resolver_handle (rh); 1358 free_resolver_handle (rh);
1359 GNUNET_RESOLVER_request_cancel (rh->dns_resolver_handle);
1349} 1360}
1350 1361
1351/** 1362/**
@@ -1412,7 +1423,9 @@ read_dns_response (void *cls,
1412 if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY)) 1423 if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY))
1413 { 1424 {
1414 /* timeout or shutdown */ 1425 /* timeout or shutdown */
1415 rh->proc (rh->proc_cls, rh, 0, NULL); 1426 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1427 "Terminating DNS query\n");
1428 finish_lookup (rh, rlh, 0, NULL);
1416 GNUNET_NETWORK_socket_close (rh->dns_sock); 1429 GNUNET_NETWORK_socket_close (rh->dns_sock);
1417 free_resolver_handle (rh); 1430 free_resolver_handle (rh);
1418 return; 1431 return;
@@ -1427,7 +1440,7 @@ read_dns_response (void *cls,
1427 if (-1 == r) 1440 if (-1 == r)
1428 { 1441 {
1429 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "recvfrom"); 1442 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "recvfrom");
1430 rh->proc (rh->proc_cls, rh, 0, NULL); 1443 finish_lookup (rh, rlh, 0, NULL);
1431 GNUNET_NETWORK_socket_close (rh->dns_sock); 1444 GNUNET_NETWORK_socket_close (rh->dns_sock);
1432 free_resolver_handle (rh); 1445 free_resolver_handle (rh);
1433 return; 1446 return;
@@ -1439,7 +1452,7 @@ read_dns_response (void *cls,
1439 { 1452 {
1440 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1453 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1441 "Failed to parse DNS reply!\n"); 1454 "Failed to parse DNS reply!\n");
1442 rh->proc (rh->proc_cls, rh, 0, NULL); 1455 finish_lookup (rh, rlh, 0, NULL);
1443 GNUNET_NETWORK_socket_close (rh->dns_sock); 1456 GNUNET_NETWORK_socket_close (rh->dns_sock);
1444 free_resolver_handle (rh); 1457 free_resolver_handle (rh);
1445 return; 1458 return;
@@ -1447,8 +1460,12 @@ read_dns_response (void *cls,
1447 1460
1448 for (i = 0; i < packet->num_answers; i++) 1461 for (i = 0; i < packet->num_answers; i++)
1449 { 1462 {
1463 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1464 "Got record type %d (want %d)\n",
1465 packet->answers[i].type,
1466 rlh->record_type);
1450 /* http://tools.ietf.org/html/rfc1034#section-3.6.2 */ 1467 /* http://tools.ietf.org/html/rfc1034#section-3.6.2 */
1451 if (packet->authority_records[i].type == GNUNET_GNS_RECORD_TYPE_CNAME) 1468 if (packet->answers[i].type == GNUNET_GNS_RECORD_TYPE_CNAME)
1452 { 1469 {
1453 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1470 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1454 "CNAME... restarting query with %s\n", 1471 "CNAME... restarting query with %s\n",
@@ -1471,7 +1488,7 @@ read_dns_response (void *cls,
1471 rd.record_type = packet->answers[i].type; 1488 rd.record_type = packet->answers[i].type;
1472 rd.flags = 0; 1489 rd.flags = 0;
1473 rd.expiration = packet->answers[i].expiration_time; 1490 rd.expiration = packet->answers[i].expiration_time;
1474 rh->proc (rh->proc_cls, rh, 1, &rd); 1491 finish_lookup (rh, rlh, 1, &rd);
1475 GNUNET_NETWORK_socket_close (rh->dns_sock); 1492 GNUNET_NETWORK_socket_close (rh->dns_sock);
1476 GNUNET_DNSPARSER_free_packet (packet); 1493 GNUNET_DNSPARSER_free_packet (packet);
1477 free_resolver_handle (rh); 1494 free_resolver_handle (rh);
@@ -1488,9 +1505,17 @@ read_dns_response (void *cls,
1488 1505
1489 /* restart query with CNAME */ 1506 /* restart query with CNAME */
1490 if (0 == strcmp (rh->dns_name+zone_offset, rh->dns_zone)) 1507 if (0 == strcmp (rh->dns_name+zone_offset, rh->dns_zone))
1508 {
1509 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1510 "Asking same server for %s\n", rh->dns_name);
1491 send_dns_packet (rh); 1511 send_dns_packet (rh);
1512 }
1492 else 1513 else
1514 {
1515 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1516 "Trying system resolver for %s\n", rh->dns_name);
1493 resolve_dns_name (rh); 1517 resolve_dns_name (rh);
1518 }
1494 1519
1495 GNUNET_DNSPARSER_free_packet (packet); 1520 GNUNET_DNSPARSER_free_packet (packet);
1496 return; 1521 return;
@@ -1529,8 +1554,8 @@ read_dns_response (void *cls,
1529 } 1554 }
1530 1555
1531 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1556 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1532 "Failed to parse DNS reply!\n"); 1557 "Nothing useful in DNS reply!\n");
1533 rh->proc (rh->proc_cls, rh, 0, NULL); 1558 finish_lookup (rh, rlh, 0, NULL);
1534 GNUNET_NETWORK_socket_close (rh->dns_sock); 1559 GNUNET_NETWORK_socket_close (rh->dns_sock);
1535 free_resolver_handle (rh); 1560 free_resolver_handle (rh);
1536 GNUNET_DNSPARSER_free_packet (packet); 1561 GNUNET_DNSPARSER_free_packet (packet);
@@ -1581,7 +1606,6 @@ resolve_record_dns (struct ResolverHandle *rh,
1581 struct GNUNET_DNSPARSER_Query query; 1606 struct GNUNET_DNSPARSER_Query query;
1582 struct GNUNET_DNSPARSER_Packet packet; 1607 struct GNUNET_DNSPARSER_Packet packet;
1583 struct GNUNET_DNSPARSER_Flags flags; 1608 struct GNUNET_DNSPARSER_Flags flags;
1584 char dns_name[MAX_DNS_NAME_LENGTH];
1585 struct in_addr dnsip; 1609 struct in_addr dnsip;
1586 struct sockaddr_in addr; 1610 struct sockaddr_in addr;
1587 struct sockaddr *sa; 1611 struct sockaddr *sa;
@@ -1622,7 +1646,8 @@ resolve_record_dns (struct ResolverHandle *rh,
1622 1646
1623 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1647 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1624 "GNS_PHASE_REC_DNS-%llu: Looking up %s from %s\n", 1648 "GNS_PHASE_REC_DNS-%llu: Looking up %s from %s\n",
1625 dns_name, 1649 rh->id,
1650 rh->dns_name,
1626 inet_ntoa (dnsip)); 1651 inet_ntoa (dnsip));
1627 rh->dns_sock = GNUNET_NETWORK_socket_create (AF_INET, SOCK_DGRAM, 0); 1652 rh->dns_sock = GNUNET_NETWORK_socket_create (AF_INET, SOCK_DGRAM, 0);
1628 if (rh->dns_sock == NULL) 1653 if (rh->dns_sock == NULL)
@@ -1630,7 +1655,8 @@ resolve_record_dns (struct ResolverHandle *rh,
1630 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1655 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1631 "GNS_PHASE_REC_DNS-%llu: Error creating udp socket for dns!\n", 1656 "GNS_PHASE_REC_DNS-%llu: Error creating udp socket for dns!\n",
1632 rh->id); 1657 rh->id);
1633 rh->proc(rh->proc_cls, rh, 0, NULL); 1658 finish_lookup (rh, rlh, 0, NULL);
1659 free_resolver_handle (rh);
1634 return; 1660 return;
1635 } 1661 }
1636 1662
@@ -1645,16 +1671,13 @@ resolve_record_dns (struct ResolverHandle *rh,
1645 "GNS_PHASE_REC_DNS-%llu: Error binding udp socket for dns!\n", 1671 "GNS_PHASE_REC_DNS-%llu: Error binding udp socket for dns!\n",
1646 rh->id); 1672 rh->id);
1647 GNUNET_NETWORK_socket_close (rh->dns_sock); 1673 GNUNET_NETWORK_socket_close (rh->dns_sock);
1648 rh->proc(rh->proc_cls, rh, 0, NULL); 1674 finish_lookup (rh, rlh, 0, NULL);
1675 free_resolver_handle (rh);
1649 return; 1676 return;
1650 } 1677 }
1651 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1678
1652 "GNS_PHASE_REC_DNS-%llu: NOT IMPLEMENTED!\n",
1653 rh->id);
1654 GNUNET_NETWORK_socket_close (rh->dns_sock);
1655 rh->proc(rh->proc_cls, rh, 0, NULL);
1656 /*TODO create dnsparser query, serialize, sendto, handle reply*/ 1679 /*TODO create dnsparser query, serialize, sendto, handle reply*/
1657 query.name = dns_name; 1680 query.name = rh->dns_name;
1658 query.type = rlh->record_type; 1681 query.type = rlh->record_type;
1659 query.class = GNUNET_DNSPARSER_CLASS_INTERNET; 1682 query.class = GNUNET_DNSPARSER_CLASS_INTERNET;
1660 memset (&flags, 0, sizeof (flags)); 1683 memset (&flags, 0, sizeof (flags));
@@ -1678,7 +1701,8 @@ resolve_record_dns (struct ResolverHandle *rh,
1678 "GNS_PHASE_REC_DNS-%llu: Creating raw dns packet!\n", 1701 "GNS_PHASE_REC_DNS-%llu: Creating raw dns packet!\n",
1679 rh->id); 1702 rh->id);
1680 GNUNET_NETWORK_socket_close (rh->dns_sock); 1703 GNUNET_NETWORK_socket_close (rh->dns_sock);
1681 rh->proc(rh->proc_cls, rh, 0, NULL); 1704 finish_lookup (rh, rlh, 0, NULL);
1705 free_resolver_handle (rh);
1682 return; 1706 return;
1683 } 1707 }
1684 1708
@@ -1690,13 +1714,6 @@ resolve_record_dns (struct ResolverHandle *rh,
1690#endif 1714#endif
1691 1715
1692 send_dns_packet (rh); 1716 send_dns_packet (rh);
1693
1694 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1695 "GNS_PHASE_REC_DNS-%llu: NOT IMPLEMENTED!\n",
1696 rh->id);
1697 GNUNET_free (rh->dns_raw_packet);
1698 GNUNET_NETWORK_socket_close (rh->dns_sock);
1699 rh->proc(rh->proc_cls, rh, 0, NULL);
1700} 1717}
1701 1718
1702 1719
@@ -2643,7 +2660,7 @@ handle_delegation_ns (void* cls, struct ResolverHandle *rh,
2643 } 2660 }
2644 2661
2645 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2662 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2646 "GNS_PHASE_DELEGATE_NS-%llu: VPN delegation starting.\n", 2663 "GNS_PHASE_DELEGATE_NS-%llu: NS delegation starting.\n",
2647 rh->id); 2664 rh->id);
2648 GNUNET_assert (NULL != rd); 2665 GNUNET_assert (NULL != rd);
2649 rh->proc = &handle_record_ns; 2666 rh->proc = &handle_record_ns;
@@ -2673,7 +2690,28 @@ handle_delegation_ns (void* cls, struct ResolverHandle *rh,
2673 } 2690 }
2674 return; 2691 return;
2675 } 2692 }
2676 2693
2694 if (rh->status & RSL_DELEGATE_NS)
2695 {
2696 if (rlh->record_type == GNUNET_GNS_RECORD_TYPE_NS)
2697 {
2698 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2699 "GNS_PHASE_DELEGATE_NS-%llu: Resolved queried NSRR in NS.\n",
2700 rh->id);
2701 finish_lookup(rh, rlh, rd_count, rd);
2702 free_resolver_handle(rh);
2703 return;
2704 }
2705
2706 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2707 "GNS_PHASE_DELEGATE_NS-%llu: NS delegation starting.\n",
2708 rh->id);
2709 GNUNET_assert (NULL != rd);
2710 rh->proc = &handle_record_ns;
2711 resolve_record_dns (rh, rd_count, rd);
2712 return;
2713 }
2714
2677 /** 2715 /**
2678 * we still have some left 2716 * we still have some left
2679 * check if authority in ns is fresh 2717 * check if authority in ns is fresh
@@ -2873,6 +2911,7 @@ process_delegation_result_ns(void* cls,
2873 rh->id); 2911 rh->id);
2874 rh->status |= RSL_DELEGATE_NS; 2912 rh->status |= RSL_DELEGATE_NS;
2875 rh->proc (rh->proc_cls, rh, rd_count, rd); 2913 rh->proc (rh->proc_cls, rh, rd_count, rd);
2914 return;
2876 } 2915 }
2877 2916
2878 if (rd[i].record_type != GNUNET_GNS_RECORD_PKEY) 2917 if (rd[i].record_type != GNUNET_GNS_RECORD_PKEY)