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.c103
1 files changed, 58 insertions, 45 deletions
diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c
index acf49de9e..51f9b9168 100644
--- a/src/namestore/gnunet-service-namestore.c
+++ b/src/namestore/gnunet-service-namestore.c
@@ -808,7 +808,8 @@ send_lookup_response (struct NamestoreClient *nc,
808 * @param rid client's request ID 808 * @param rid client's request ID
809 */ 809 */
810static void 810static void
811send_store_response (struct NamestoreClient *nc, int res, uint32_t rid) 811send_store_response (struct NamestoreClient *nc, int res, const char*emsg,
812 uint32_t rid)
812{ 813{
813 struct GNUNET_MQ_Envelope *env; 814 struct GNUNET_MQ_Envelope *env;
814 struct RecordStoreResponseMessage *rcr_msg; 815 struct RecordStoreResponseMessage *rcr_msg;
@@ -820,10 +821,17 @@ send_store_response (struct NamestoreClient *nc, int res, uint32_t rid)
820 "Store requests completed", 821 "Store requests completed",
821 1, 822 1,
822 GNUNET_NO); 823 GNUNET_NO);
823 env = GNUNET_MQ_msg (rcr_msg, 824 env = GNUNET_MQ_msg_extra (rcr_msg,
824 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE); 825 (NULL != emsg) ? strlen (emsg) + 1 : 0,
826 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE);
825 rcr_msg->gns_header.r_id = htonl (rid); 827 rcr_msg->gns_header.r_id = htonl (rid);
826 rcr_msg->op_result = htonl (res); 828 rcr_msg->op_result = htonl (res);
829 rcr_msg->reserved = htons (0);
830 if (NULL != emsg)
831 {
832 rcr_msg->emsg_len = htons (strlen (emsg) + 1);
833 memcpy (&rcr_msg[1], emsg, strlen (emsg) + 1);
834 }
827 GNUNET_MQ_send (nc->mq, env); 835 GNUNET_MQ_send (nc->mq, env);
828} 836}
829 837
@@ -874,7 +882,7 @@ finish_cache_operation (void *cls, int32_t success, const char *emsg)
874 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CACHE operation completed\n"); 882 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CACHE operation completed\n");
875 GNUNET_CONTAINER_DLL_remove (cop_head, cop_tail, cop); 883 GNUNET_CONTAINER_DLL_remove (cop_head, cop_tail, cop);
876 if (NULL != cop->nc) 884 if (NULL != cop->nc)
877 send_store_response (cop->nc, success, cop->rid); 885 send_store_response (cop->nc, success, emsg, cop->rid);
878 if (NULL != (zi = cop->zi)) 886 if (NULL != (zi = cop->zi))
879 { 887 {
880 zi->cache_ops--; 888 zi->cache_ops--;
@@ -931,7 +939,7 @@ refresh_block (struct NamestoreClient *nc,
931 if (0 == res_count) 939 if (0 == res_count)
932 { 940 {
933 if (NULL != nc) 941 if (NULL != nc)
934 send_store_response (nc, GNUNET_OK, rid); 942 send_store_response (nc, GNUNET_OK, NULL, rid);
935 if (rd != res) 943 if (rd != res)
936 GNUNET_free (res); 944 GNUNET_free (res);
937 return; /* no data, no need to update cache */ 945 return; /* no data, no need to update cache */
@@ -943,7 +951,7 @@ refresh_block (struct NamestoreClient *nc,
943 1, 951 1,
944 GNUNET_NO); 952 GNUNET_NO);
945 if (NULL != nc) 953 if (NULL != nc)
946 send_store_response (nc, GNUNET_OK, rid); 954 send_store_response (nc, GNUNET_OK, NULL, rid);
947 if (rd != res) 955 if (rd != res)
948 GNUNET_free (res); 956 GNUNET_free (res);
949 return; 957 return;
@@ -1472,11 +1480,21 @@ get_block_exp_existing (void *cls,
1472{ 1480{
1473 struct GNUNET_TIME_Absolute *exp = cls; 1481 struct GNUNET_TIME_Absolute *exp = cls;
1474 struct GNUNET_GNSRECORD_Data rd_pub[rd_count]; 1482 struct GNUNET_GNSRECORD_Data rd_pub[rd_count];
1483 unsigned int rd_pub_count;
1484 char *emsg;
1475 1485
1476 GNUNET_GNSRECORD_convert_records_for_export (rd, 1486 if (GNUNET_OK != GNUNET_GNSRECORD_convert_records_for_export (label,
1487 rd,
1477 rd_count, 1488 rd_count,
1478 rd_pub, 1489 rd_pub,
1479 exp); 1490 &rd_pub_count,
1491 exp,
1492 &emsg))
1493 {
1494 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1495 "%s\n", emsg);
1496 GNUNET_free (emsg);
1497 }
1480} 1498}
1481 1499
1482 1500
@@ -1501,12 +1519,10 @@ handle_record_store (void *cls, const struct RecordStoreMessage *rp_msg)
1501 struct StoreActivity *sa; 1519 struct StoreActivity *sa;
1502 struct GNUNET_TIME_Absolute existing_block_exp; 1520 struct GNUNET_TIME_Absolute existing_block_exp;
1503 struct GNUNET_TIME_Absolute new_block_exp; 1521 struct GNUNET_TIME_Absolute new_block_exp;
1504 struct GNUNET_GNSRECORD_Data *tombstone_record;
1505 1522
1506 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1523 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1507 "Received NAMESTORE_RECORD_STORE message\n"); 1524 "Received NAMESTORE_RECORD_STORE message\n");
1508 existing_block_exp.abs_value_us = 0; 1525 existing_block_exp.abs_value_us = 0;
1509 tombstone_record = NULL;
1510 rid = ntohl (rp_msg->gns_header.r_id); 1526 rid = ntohl (rp_msg->gns_header.r_id);
1511 name_len = ntohs (rp_msg->name_len); 1527 name_len = ntohs (rp_msg->name_len);
1512 rd_count = ntohs (rp_msg->rd_count); 1528 rd_count = ntohs (rp_msg->rd_count);
@@ -1560,21 +1576,23 @@ handle_record_store (void *cls, const struct RecordStoreMessage *rp_msg)
1560 /* remove "NICK" records, unless this is for the 1576 /* remove "NICK" records, unless this is for the
1561 #GNUNET_GNS_EMPTY_LABEL_AT label 1577 #GNUNET_GNS_EMPTY_LABEL_AT label
1562 We may need one additional record later for tombstone. 1578 We may need one additional record later for tombstone.
1579 FIXME: Since we must normalize the record set (check for
1580 consistency etc) we have to iterate the set twice.
1581 May be inefficient.
1582 We cannot really move the nick caching into GNSRECORD.
1563 */ 1583 */
1564 struct GNUNET_GNSRECORD_Data rd_clean[GNUNET_NZL (rd_count) + 1]; 1584 struct GNUNET_GNSRECORD_Data rd_clean[GNUNET_NZL (rd_count)];
1585 struct GNUNET_GNSRECORD_Data rd_nf[GNUNET_NZL (rd_count) + 1];
1565 unsigned int rd_clean_off; 1586 unsigned int rd_clean_off;
1587 unsigned int rd_nf_count;
1588 char *emsg;
1566 int have_nick; 1589 int have_nick;
1567 1590
1568 rd_clean_off = 0; 1591 rd_clean_off = 0;
1569 have_nick = GNUNET_NO; 1592 have_nick = GNUNET_NO;
1570 for (unsigned int i = 0; i < rd_count; i++) 1593 for (unsigned int i = 0; i < rd_count; i++)
1571 { 1594 {
1572 /* Do not allow to set tombstone records unless zonemaster */
1573 rd_clean[rd_clean_off] = rd[i]; 1595 rd_clean[rd_clean_off] = rd[i];
1574 if (GNUNET_GNSRECORD_TYPE_TOMBSTONE == rd[i].record_type)
1575 tombstone_record = &rd_clean[rd_clean_off];
1576 if (GNUNET_YES == GNUNET_GNSRECORD_is_critical (rd[i].record_type))
1577 rd_clean[rd_clean_off].flags |= GNUNET_GNSRECORD_RF_CRITICAL;
1578 1596
1579 if ((0 == strcmp (GNUNET_GNS_EMPTY_LABEL_AT, conv_name)) || 1597 if ((0 == strcmp (GNUNET_GNS_EMPTY_LABEL_AT, conv_name)) ||
1580 (GNUNET_GNSRECORD_TYPE_NICK != rd[i].record_type)) 1598 (GNUNET_GNSRECORD_TYPE_NICK != rd[i].record_type))
@@ -1587,10 +1605,21 @@ handle_record_store (void *cls, const struct RecordStoreMessage *rp_msg)
1587 have_nick = GNUNET_YES; 1605 have_nick = GNUNET_YES;
1588 } 1606 }
1589 } 1607 }
1590 GNUNET_GNSRECORD_convert_records_for_export (rd, 1608 if (GNUNET_OK != GNUNET_GNSRECORD_normalize_record_set (conv_name,
1591 rd_clean_off, 1609 rd_clean,
1592 rd_clean, 1610 rd_clean_off,
1593 &new_block_exp); 1611 rd_nf,
1612 &rd_nf_count,
1613 &new_block_exp,
1614 GNUNET_YES,
1615 &emsg))
1616 {
1617 send_store_response (nc, res, emsg, rid);
1618 GNUNET_free (emsg);
1619 GNUNET_SERVICE_client_continue (nc->client);
1620 GNUNET_free (conv_name);
1621 return;
1622 }
1594 /* 1623 /*
1595 * If existing_block_exp is 0, then there was not record set 1624 * If existing_block_exp is 0, then there was not record set
1596 * and no tombstone. 1625 * and no tombstone.
@@ -1598,27 +1627,15 @@ handle_record_store (void *cls, const struct RecordStoreMessage *rp_msg)
1598 * new block expiration would be, we need to add a tombstone 1627 * new block expiration would be, we need to add a tombstone
1599 * or update it. 1628 * or update it.
1600 */ 1629 */
1601 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1602 "New exp: %s\n",
1603 GNUNET_STRINGS_absolute_time_to_string (new_block_exp));
1604 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1605 "Old exp: %s\n",
1606 GNUNET_STRINGS_absolute_time_to_string (existing_block_exp));
1607 if (GNUNET_TIME_absolute_cmp (new_block_exp, <=, existing_block_exp)) 1630 if (GNUNET_TIME_absolute_cmp (new_block_exp, <=, existing_block_exp))
1608 { 1631 {
1609 /* There was already a TS record in the set given */ 1632 rd_nf[rd_nf_count].record_type = GNUNET_GNSRECORD_TYPE_TOMBSTONE;
1610 if (NULL != tombstone_record) 1633 rd_nf[rd_nf_count].expiration_time =
1611 { 1634 existing_block_exp.abs_value_us;
1612 tombstone_record->expiration_time = existing_block_exp.abs_value_us; 1635 rd_nf[rd_nf_count].data = NULL;
1613 } 1636 rd_nf[rd_nf_count].data_size = 0;
1614 else { 1637 rd_nf[rd_nf_count].flags |= GNUNET_GNSRECORD_RF_PRIVATE;
1615 rd_clean[rd_clean_off].record_type = GNUNET_GNSRECORD_TYPE_TOMBSTONE; 1638 rd_nf_count++;
1616 rd_clean[rd_clean_off].expiration_time = existing_block_exp.abs_value_us;
1617 rd_clean[rd_clean_off].data = NULL;
1618 rd_clean[rd_clean_off].data_size = 0;
1619 rd_clean[rd_clean_off].flags |= GNUNET_GNSRECORD_RF_PRIVATE;
1620 rd_clean_off++;
1621 }
1622 } 1639 }
1623 if ((0 == strcmp (GNUNET_GNS_EMPTY_LABEL_AT, conv_name)) && 1640 if ((0 == strcmp (GNUNET_GNS_EMPTY_LABEL_AT, conv_name)) &&
1624 (GNUNET_NO == have_nick)) 1641 (GNUNET_NO == have_nick))
@@ -1629,17 +1646,13 @@ handle_record_store (void *cls, const struct RecordStoreMessage *rp_msg)
1629 res = GSN_database->store_records (GSN_database->cls, 1646 res = GSN_database->store_records (GSN_database->cls,
1630 &rp_msg->private_key, 1647 &rp_msg->private_key,
1631 conv_name, 1648 conv_name,
1632 rd_clean_off, 1649 rd_nf_count,
1633 rd_clean); 1650 rd_nf);
1634 } 1651 }
1635 1652
1636 if (GNUNET_OK != res) 1653 if (GNUNET_OK != res)
1637 { 1654 {
1638 /* store not successful or zonemaster, not need to tell monitors */ 1655 /* store not successful or zonemaster, not need to tell monitors */
1639 send_store_response (nc, res, rid);
1640 GNUNET_SERVICE_client_continue (nc->client);
1641 GNUNET_free (conv_name);
1642 return;
1643 } 1656 }
1644 1657
1645 sa = GNUNET_malloc (sizeof(struct StoreActivity) 1658 sa = GNUNET_malloc (sizeof(struct StoreActivity)