aboutsummaryrefslogtreecommitdiff
path: root/src/gns
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2013-11-20 15:39:58 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2013-11-20 15:39:58 +0000
commit52a5e73ced4c456e5d6951158844f047048bd4e0 (patch)
treeadc7abaab3aeef5576e27777f305408465fa51e8 /src/gns
parentbbf436499f6c3d950fc8d0726a76ee7b4d2af266 (diff)
downloadgnunet-52a5e73ced4c456e5d6951158844f047048bd4e0.tar.gz
gnunet-52a5e73ced4c456e5d6951158844f047048bd4e0.zip
- renaming namestore references to namecache
- implementing nick record based shortening in resolver
Diffstat (limited to 'src/gns')
-rw-r--r--src/gns/gnunet-service-gns_resolver.c119
1 files changed, 65 insertions, 54 deletions
diff --git a/src/gns/gnunet-service-gns_resolver.c b/src/gns/gnunet-service-gns_resolver.c
index 1f9e1ab05..71af82d01 100644
--- a/src/gns/gnunet-service-gns_resolver.c
+++ b/src/gns/gnunet-service-gns_resolver.c
@@ -101,6 +101,16 @@ struct AuthorityChain
101 char *label; 101 char *label;
102 102
103 /** 103 /**
104 * label/name suggested for shortening to the authority
105 */
106 char *suggested_shortening_label;
107
108 /**
109 * Do we already try to shorten this authority?
110 */
111 int shortening_started;
112
113 /**
104 * #GNUNET_YES if the authority was a GNS authority, 114 * #GNUNET_YES if the authority was a GNS authority,
105 * #GNUNET_NO if the authority was a DNS authority. 115 * #GNUNET_NO if the authority was a DNS authority.
106 */ 116 */
@@ -1075,15 +1085,8 @@ handle_gns_cname_result (struct GNS_ResolverHandle *rh,
1075 ac->gns_authority = GNUNET_YES; 1085 ac->gns_authority = GNUNET_YES;
1076 ac->authority_info.gns_authority = rh->ac_tail->authority_info.gns_authority; 1086 ac->authority_info.gns_authority = rh->ac_tail->authority_info.gns_authority;
1077 ac->label = resolver_lookup_get_next_label (rh); 1087 ac->label = resolver_lookup_get_next_label (rh);
1078 /* tigger shortening */ 1088 ac->suggested_shortening_label = NULL;
1079 if (NULL != rh->shorten_key) 1089 ac->shortening_started = GNUNET_NO;
1080 {
1081 GNUNET_break (0); /* FIXME suggested label*/
1082 GNS_shorten_start (rh->ac_tail->label,
1083 NULL,
1084 &ac->authority_info.gns_authority,
1085 rh->shorten_key);
1086 }
1087 /* add AC to tail */ 1090 /* add AC to tail */
1088 GNUNET_CONTAINER_DLL_insert_tail (rh->ac_head, 1091 GNUNET_CONTAINER_DLL_insert_tail (rh->ac_head,
1089 rh->ac_tail, 1092 rh->ac_tail,
@@ -1332,27 +1335,30 @@ handle_gns_resolution_result (void *cls,
1332{ 1335{
1333 struct GNS_ResolverHandle *rh = cls; 1336 struct GNS_ResolverHandle *rh = cls;
1334 struct AuthorityChain *ac; 1337 struct AuthorityChain *ac;
1338 struct AuthorityChain *shorten_ac;
1335 unsigned int i; 1339 unsigned int i;
1336 char *cname; 1340 char *cname;
1337 struct VpnContext *vpn_ctx; 1341 struct VpnContext *vpn_ctx;
1338 const struct GNUNET_TUN_GnsVpnRecord *vpn; 1342 const struct GNUNET_TUN_GnsVpnRecord *vpn;
1339 const char *vname; 1343 const char *vname;
1340 const char *suggested_label;
1341 struct GNUNET_HashCode vhash; 1344 struct GNUNET_HashCode vhash;
1342 int af; 1345 int af;
1343 char scratch[UINT16_MAX]; 1346 char scratch[UINT16_MAX];
1344 size_t scratch_off; 1347 size_t scratch_off;
1345 size_t scratch_start; 1348 size_t scratch_start;
1346 size_t off; 1349 size_t off;
1347 int c2;
1348 struct GNUNET_GNSRECORD_Data rd_new[rd_count]; 1350 struct GNUNET_GNSRECORD_Data rd_new[rd_count];
1349 unsigned int rd_off; 1351 unsigned int rd_off;
1350 1352
1351 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1353 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1352 "Resolution succeeded for `%s' in zone %s, got %u records\n", 1354 "Resolution succeeded for `%s' in zone %s, got %u records\n",
1353 rh->ac_tail->label, 1355 rh->ac_tail->label,
1354 GNUNET_GNSRECORD_z2s (&rh->ac_tail->authority_info.gns_authority), 1356 GNUNET_GNSRECORD_z2s (&rh->ac_tail->authority_info.gns_authority),
1355 rd_count); 1357 rd_count);
1358
1359 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1360 "%u \n\n",
1361 rh->name_resolution_pos);
1356 if (0 == rh->name_resolution_pos) 1362 if (0 == rh->name_resolution_pos)
1357 { 1363 {
1358 /* top-level match, are we done yet? */ 1364 /* top-level match, are we done yet? */
@@ -1439,13 +1445,14 @@ handle_gns_resolution_result (void *cls,
1439 } 1445 }
1440 default: 1446 default:
1441 break; 1447 break;
1442 } 1448 } /* end: switch */
1443 } 1449 } /* end: for rd */
1444 } 1450 } /* end: name_resolution_pos */
1445 /* convert relative names in record values to absolute names, 1451 /* convert relative names in record values to absolute names,
1446 using 'scratch' array for memory allocations */ 1452 using 'scratch' array for memory allocations */
1447 scratch_off = 0; 1453 scratch_off = 0;
1448 rd_off = 0; 1454 rd_off = 0;
1455 shorten_ac = rh->ac_tail;
1449 for (i=0;i<rd_count;i++) 1456 for (i=0;i<rd_count;i++)
1450 { 1457 {
1451 rd_new[rd_off] = rd[i]; 1458 rd_new[rd_off] = rd[i];
@@ -1604,6 +1611,22 @@ handle_gns_resolution_result (void *cls,
1604 GNUNET_DNSPARSER_free_srv (srv); 1611 GNUNET_DNSPARSER_free_srv (srv);
1605 } 1612 }
1606 break; 1613 break;
1614
1615 case GNUNET_GNSRECORD_TYPE_NICK:
1616 {
1617 const char *nick;
1618 nick = rd[i].data;
1619 if ((GNUNET_GNSRECORD_TYPE_NICK ==rd[i].record_type) &&
1620 (rd[i].data_size > 0) &&
1621 (nick[rd[i].data_size -1] == '\0'))
1622 {
1623 GNUNET_break_op (0);
1624 break;
1625 }
1626 if (NULL == shorten_ac->suggested_shortening_label)
1627 shorten_ac->suggested_shortening_label = GNUNET_strdup (nick);
1628 break;
1629 }
1607 case GNUNET_GNSRECORD_TYPE_PKEY: 1630 case GNUNET_GNSRECORD_TYPE_PKEY:
1608 { 1631 {
1609 struct GNUNET_CRYPTO_EcdsaPublicKey pub; 1632 struct GNUNET_CRYPTO_EcdsaPublicKey pub;
@@ -1614,24 +1637,6 @@ handle_gns_resolution_result (void *cls,
1614 break; 1637 break;
1615 } 1638 }
1616 memcpy (&pub, rd[i].data, rd[i].data_size); 1639 memcpy (&pub, rd[i].data, rd[i].data_size);
1617
1618 /* tigger shortening */
1619 if (NULL != rh->shorten_key)
1620 {
1621 suggested_label = NULL;
1622 for (c2 = 0; c2< rd_count; c2++)
1623 {
1624 if ((GNUNET_GNSRECORD_TYPE_NICK ==rd[c2].record_type) &&
1625 (rd[i].data_size > 0) &&
1626 (((const char *) rd[c2].data)[rd[c2].data_size -1] == '\0'))
1627 suggested_label = (const char *) rd->data;
1628 }
1629 if (NULL != suggested_label)
1630 GNS_shorten_start (rh->ac_tail->label,
1631 suggested_label,
1632 &pub,
1633 rh->shorten_key);
1634 }
1635 rd_off++; 1640 rd_off++;
1636 if (GNUNET_GNSRECORD_TYPE_PKEY != rh->record_type) 1641 if (GNUNET_GNSRECORD_TYPE_PKEY != rh->record_type)
1637 { 1642 {
@@ -1643,6 +1648,8 @@ handle_gns_resolution_result (void *cls,
1643 ac->gns_authority = GNUNET_YES; 1648 ac->gns_authority = GNUNET_YES;
1644 ac->authority_info.gns_authority = pub; 1649 ac->authority_info.gns_authority = pub;
1645 ac->label = GNUNET_strdup (GNUNET_GNS_MASTERZONE_STR); 1650 ac->label = GNUNET_strdup (GNUNET_GNS_MASTERZONE_STR);
1651 ac->suggested_shortening_label = NULL;
1652 ac->shortening_started = GNUNET_NO;
1646 GNUNET_CONTAINER_DLL_insert_tail (rh->ac_head, 1653 GNUNET_CONTAINER_DLL_insert_tail (rh->ac_head,
1647 rh->ac_tail, 1654 rh->ac_tail,
1648 ac); 1655 ac);
@@ -1662,7 +1669,24 @@ handle_gns_resolution_result (void *cls,
1662 default: 1669 default:
1663 rd_off++; 1670 rd_off++;
1664 break; 1671 break;
1665 } 1672 } /* end: switch */
1673 } /* end: for rd_count */
1674
1675 /* trigger shortening */
1676 if ((NULL != rh->shorten_key) &&
1677 (NULL != shorten_ac) &&
1678 (GNUNET_NO == shorten_ac->shortening_started) &&
1679 (NULL != shorten_ac->suggested_shortening_label))
1680 {
1681 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1682 "Start shortening for label `%s' based on nick `%s'\n",
1683 shorten_ac->label,
1684 shorten_ac->suggested_shortening_label);
1685 shorten_ac->shortening_started = GNUNET_YES;
1686 GNS_shorten_start (shorten_ac->label,
1687 shorten_ac->suggested_shortening_label,
1688 &shorten_ac->authority_info.gns_authority,
1689 rh->shorten_key);
1666 } 1690 }
1667 1691
1668 /* yes, we are done, return result */ 1692 /* yes, we are done, return result */
@@ -1694,27 +1718,12 @@ handle_gns_resolution_result (void *cls,
1694 ac = GNUNET_new (struct AuthorityChain); 1718 ac = GNUNET_new (struct AuthorityChain);
1695 ac->rh = rh; 1719 ac->rh = rh;
1696 ac->gns_authority = GNUNET_YES; 1720 ac->gns_authority = GNUNET_YES;
1721 ac->suggested_shortening_label = NULL;
1722 ac->shortening_started = GNUNET_NO;
1697 memcpy (&ac->authority_info.gns_authority, 1723 memcpy (&ac->authority_info.gns_authority,
1698 rd[i].data, 1724 rd[i].data,
1699 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)); 1725 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey));
1700 ac->label = resolver_lookup_get_next_label (rh); 1726 ac->label = resolver_lookup_get_next_label (rh);
1701 /* tigger shortening */
1702 if (NULL != rh->shorten_key)
1703 {
1704 suggested_label = NULL;
1705 for (c2 = 0; c2< rd_count; c2++)
1706 {
1707 if ((GNUNET_GNSRECORD_TYPE_NICK ==rd[c2].record_type) &&
1708 (rd[c2].data_size > 0) &&
1709 ((const char *) rd[c2].data)[rd[c2].data_size -1] == '\0')
1710 suggested_label = (const char *) rd[c2].data;
1711 }
1712 if (NULL != suggested_label)
1713 GNS_shorten_start (rh->ac_tail->label,
1714 suggested_label,
1715 &ac->authority_info.gns_authority,
1716 rh->shorten_key);
1717 }
1718 /* add AC to tail */ 1727 /* add AC to tail */
1719 GNUNET_CONTAINER_DLL_insert_tail (rh->ac_head, 1728 GNUNET_CONTAINER_DLL_insert_tail (rh->ac_head,
1720 rh->ac_tail, 1729 rh->ac_tail,
@@ -1923,10 +1932,10 @@ handle_dht_response (void *cls,
1923 1932
1924 1933
1925/** 1934/**
1926 * Process a record that was stored in the namestore. 1935 * Process a record that was stored in the namecache.
1927 * 1936 *
1928 * @param cls closure with the `struct GNS_ResolverHandle` 1937 * @param cls closure with the `struct GNS_ResolverHandle`
1929 * @param block block that was stored in the namestore 1938 * @param block block that was stored in the namecache
1930 */ 1939 */
1931static void 1940static void
1932handle_namestore_block_response (void *cls, 1941handle_namestore_block_response (void *cls,
@@ -1948,7 +1957,7 @@ handle_namestore_block_response (void *cls,
1948 ( (NULL == block) || 1957 ( (NULL == block) ||
1949 (0 == GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_ntoh (block->expiration_time)).rel_value_us) ) ) 1958 (0 == GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_ntoh (block->expiration_time)).rel_value_us) ) )
1950 { 1959 {
1951 /* Namestore knows nothing; try DHT lookup */ 1960 /* namecache knows nothing; try DHT lookup */
1952 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1961 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1953 "Starting DHT lookup for `%s' in zone %s\n", 1962 "Starting DHT lookup for `%s' in zone %s\n",
1954 ac->label, 1963 ac->label,
@@ -2207,6 +2216,7 @@ start_resolver_lookup (struct GNS_ResolverHandle *rh)
2207 ac = GNUNET_new (struct AuthorityChain); 2216 ac = GNUNET_new (struct AuthorityChain);
2208 ac->rh = rh; 2217 ac->rh = rh;
2209 ac->label = resolver_lookup_get_next_label (rh); 2218 ac->label = resolver_lookup_get_next_label (rh);
2219 ac->suggested_shortening_label = NULL;
2210 if (NULL == ac->label) 2220 if (NULL == ac->label)
2211 /* name was just "gnu", so we default to label '+' */ 2221 /* name was just "gnu", so we default to label '+' */
2212 ac->label = GNUNET_strdup (GNUNET_GNS_MASTERZONE_STR); 2222 ac->label = GNUNET_strdup (GNUNET_GNS_MASTERZONE_STR);
@@ -2290,6 +2300,7 @@ GNS_resolver_lookup_cancel (struct GNS_ResolverHandle *rh)
2290 rh->ac_tail, 2300 rh->ac_tail,
2291 ac); 2301 ac);
2292 GNUNET_free (ac->label); 2302 GNUNET_free (ac->label);
2303 GNUNET_free_non_null (ac->suggested_shortening_label);
2293 GNUNET_free (ac); 2304 GNUNET_free (ac);
2294 } 2305 }
2295 if (NULL != rh->g2dc) 2306 if (NULL != rh->g2dc)