aboutsummaryrefslogtreecommitdiff
path: root/src/namestore
diff options
context:
space:
mode:
Diffstat (limited to 'src/namestore')
-rw-r--r--src/namestore/gnunet-service-namestore.c47
1 files changed, 33 insertions, 14 deletions
diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c
index 1de3a3edf..4d23b91c6 100644
--- a/src/namestore/gnunet-service-namestore.c
+++ b/src/namestore/gnunet-service-namestore.c
@@ -23,12 +23,6 @@
23 * @brief namestore for the GNUnet naming system 23 * @brief namestore for the GNUnet naming system
24 * @author Matthias Wachs 24 * @author Matthias Wachs
25 * @author Christian Grothoff 25 * @author Christian Grothoff
26 *
27 * TODO:
28 * - "get_nick_record" is a bottleneck, introduce a cache to
29 * avoid looking it up again and again (for the same few
30 * zones that the user will typically manage!)
31 * - run testcases, make sure everything works!
32 */ 26 */
33#include "platform.h" 27#include "platform.h"
34#include "gnunet_util_lib.h" 28#include "gnunet_util_lib.h"
@@ -562,13 +556,20 @@ cache_nick (const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
562 } 556 }
563 GNUNET_free_non_null (oldest->rd); 557 GNUNET_free_non_null (oldest->rd);
564 oldest->zone = *zone; 558 oldest->zone = *zone;
565 oldest->rd = GNUNET_malloc (sizeof (*nick) + 559 if (NULL != nick)
566 nick->data_size); 560 {
567 *oldest->rd = *nick; 561 oldest->rd = GNUNET_malloc (sizeof (*nick) +
568 oldest->rd->data = &oldest->rd[1]; 562 nick->data_size);
569 memcpy (&oldest->rd[1], 563 *oldest->rd = *nick;
570 nick->data, 564 oldest->rd->data = &oldest->rd[1];
571 nick->data_size); 565 memcpy (&oldest->rd[1],
566 nick->data,
567 nick->data_size);
568 }
569 else
570 {
571 oldest->rd = NULL;
572 }
572 oldest->last_used = GNUNET_TIME_absolute_get (); 573 oldest->last_used = GNUNET_TIME_absolute_get ();
573} 574}
574 575
@@ -592,8 +593,10 @@ get_nick_record (const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone)
592 struct NickCache *pos = &nick_cache[i]; 593 struct NickCache *pos = &nick_cache[i];
593 if ( (NULL != pos->rd) && 594 if ( (NULL != pos->rd) &&
594 (0 == GNUNET_memcmp (zone, 595 (0 == GNUNET_memcmp (zone,
595 &pos->zone)) ) 596 &pos->zone)) )
596 { 597 {
598 if (NULL == pos->rd)
599 return NULL;
597 nick = GNUNET_malloc (sizeof (*nick) + 600 nick = GNUNET_malloc (sizeof (*nick) +
598 pos->rd->data_size); 601 pos->rd->data_size);
599 *nick = *pos->rd; 602 *nick = *pos->rd;
@@ -631,6 +634,9 @@ get_nick_record (const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone)
631 "No nick name set for zone `%s'\n", 634 "No nick name set for zone `%s'\n",
632 GNUNET_GNSRECORD_z2s (&pub)); 635 GNUNET_GNSRECORD_z2s (&pub));
633 } 636 }
637 /* update cache */
638 cache_nick (zone,
639 NULL);
634 return NULL; 640 return NULL;
635 } 641 }
636 642
@@ -1615,8 +1621,10 @@ handle_record_store (void *cls,
1615 #GNUNET_GNS_EMPTY_LABEL_AT label */ 1621 #GNUNET_GNS_EMPTY_LABEL_AT label */
1616 struct GNUNET_GNSRECORD_Data rd_clean[GNUNET_NZL(rd_count)]; 1622 struct GNUNET_GNSRECORD_Data rd_clean[GNUNET_NZL(rd_count)];
1617 unsigned int rd_clean_off; 1623 unsigned int rd_clean_off;
1624 int have_nick;
1618 1625
1619 rd_clean_off = 0; 1626 rd_clean_off = 0;
1627 have_nick = GNUNET_NO;
1620 for (unsigned int i=0;i<rd_count;i++) 1628 for (unsigned int i=0;i<rd_count;i++)
1621 { 1629 {
1622 rd_clean[rd_clean_off] = rd[i]; 1630 rd_clean[rd_clean_off] = rd[i];
@@ -1628,8 +1636,19 @@ handle_record_store (void *cls,
1628 if ( (0 == strcmp (GNUNET_GNS_EMPTY_LABEL_AT, 1636 if ( (0 == strcmp (GNUNET_GNS_EMPTY_LABEL_AT,
1629 conv_name)) && 1637 conv_name)) &&
1630 (GNUNET_GNSRECORD_TYPE_NICK == rd[i].record_type) ) 1638 (GNUNET_GNSRECORD_TYPE_NICK == rd[i].record_type) )
1639 {
1631 cache_nick (&rp_msg->private_key, 1640 cache_nick (&rp_msg->private_key,
1632 &rd[i]); 1641 &rd[i]);
1642 have_nick = GNUNET_YES;
1643 }
1644 }
1645 if ( (0 == strcmp (GNUNET_GNS_EMPTY_LABEL_AT,
1646 conv_name)) &&
1647 (GNUNET_NO == have_nick) )
1648 {
1649 /* remove nick record from cache, in case we have one there */
1650 cache_nick (&rp_msg->private_key,
1651 NULL);
1633 } 1652 }
1634 res = GSN_database->store_records (GSN_database->cls, 1653 res = GSN_database->store_records (GSN_database->cls,
1635 &rp_msg->private_key, 1654 &rp_msg->private_key,