aboutsummaryrefslogtreecommitdiff
path: root/src/namestore/gnunet-service-namestore.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/namestore/gnunet-service-namestore.c')
-rw-r--r--src/namestore/gnunet-service-namestore.c67
1 files changed, 49 insertions, 18 deletions
diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c
index d2a09087e..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;
@@ -615,10 +618,25 @@ get_nick_record (const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone)
615 if ( (GNUNET_OK != res) || 618 if ( (GNUNET_OK != res) ||
616 (NULL == nick) ) 619 (NULL == nick) )
617 { 620 {
618 GNUNET_CRYPTO_ecdsa_key_get_public (zone, &pub); 621 static int do_log = GNUNET_LOG_CALL_STATUS;
619 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, 622
620 "No nick name set for zone `%s'\n", 623 if (0 == do_log)
621 GNUNET_GNSRECORD_z2s (&pub)); 624 do_log
625 = GNUNET_get_log_call_status (GNUNET_ERROR_TYPE_DEBUG,
626 "namestore",
627 __FILE__,
628 __FUNCTION__,
629 __LINE__);
630 if (1 == do_log)
631 {
632 GNUNET_CRYPTO_ecdsa_key_get_public (zone, &pub);
633 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
634 "No nick name set for zone `%s'\n",
635 GNUNET_GNSRECORD_z2s (&pub));
636 }
637 /* update cache */
638 cache_nick (zone,
639 NULL);
622 return NULL; 640 return NULL;
623 } 641 }
624 642
@@ -1603,8 +1621,10 @@ handle_record_store (void *cls,
1603 #GNUNET_GNS_EMPTY_LABEL_AT label */ 1621 #GNUNET_GNS_EMPTY_LABEL_AT label */
1604 struct GNUNET_GNSRECORD_Data rd_clean[GNUNET_NZL(rd_count)]; 1622 struct GNUNET_GNSRECORD_Data rd_clean[GNUNET_NZL(rd_count)];
1605 unsigned int rd_clean_off; 1623 unsigned int rd_clean_off;
1624 int have_nick;
1606 1625
1607 rd_clean_off = 0; 1626 rd_clean_off = 0;
1627 have_nick = GNUNET_NO;
1608 for (unsigned int i=0;i<rd_count;i++) 1628 for (unsigned int i=0;i<rd_count;i++)
1609 { 1629 {
1610 rd_clean[rd_clean_off] = rd[i]; 1630 rd_clean[rd_clean_off] = rd[i];
@@ -1616,8 +1636,19 @@ handle_record_store (void *cls,
1616 if ( (0 == strcmp (GNUNET_GNS_EMPTY_LABEL_AT, 1636 if ( (0 == strcmp (GNUNET_GNS_EMPTY_LABEL_AT,
1617 conv_name)) && 1637 conv_name)) &&
1618 (GNUNET_GNSRECORD_TYPE_NICK == rd[i].record_type) ) 1638 (GNUNET_GNSRECORD_TYPE_NICK == rd[i].record_type) )
1639 {
1619 cache_nick (&rp_msg->private_key, 1640 cache_nick (&rp_msg->private_key,
1620 &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);
1621 } 1652 }
1622 res = GSN_database->store_records (GSN_database->cls, 1653 res = GSN_database->store_records (GSN_database->cls,
1623 &rp_msg->private_key, 1654 &rp_msg->private_key,