aboutsummaryrefslogtreecommitdiff
path: root/src/namestore/gnunet-service-namestore.c
diff options
context:
space:
mode:
authorMartin Schanzenbach <schanzen@gnunet.org>2022-03-21 13:54:28 +0100
committerMartin Schanzenbach <schanzen@gnunet.org>2022-03-21 13:54:28 +0100
commit4e95b59a6f3cd35c9c1b5dcdc6320f0e0dfef79b (patch)
tree22f87fcea0ea417a7a3ca8b900c3e6c891c28088 /src/namestore/gnunet-service-namestore.c
parentec8a825b0e56c692c4879db10c6b25cd26bb42e4 (diff)
downloadgnunet-4e95b59a6f3cd35c9c1b5dcdc6320f0e0dfef79b.tar.gz
gnunet-4e95b59a6f3cd35c9c1b5dcdc6320f0e0dfef79b.zip
NAMESTORE: Towards new transaction-based API
Diffstat (limited to 'src/namestore/gnunet-service-namestore.c')
-rw-r--r--src/namestore/gnunet-service-namestore.c183
1 files changed, 0 insertions, 183 deletions
diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c
index d735822fb..95260ff9c 100644
--- a/src/namestore/gnunet-service-namestore.c
+++ b/src/namestore/gnunet-service-namestore.c
@@ -122,24 +122,6 @@ struct ZoneIteration
122}; 122};
123 123
124/** 124/**
125 * Lock on a record set
126 */
127struct RecordsLock
128{
129 /* DLL */
130 struct RecordsLock *prev;
131
132 /* DLL */
133 struct RecordsLock *next;
134
135 /* Hash of the locked label */
136 struct GNUNET_HashCode label_hash;
137
138 /* Client locking the zone */
139 struct NamestoreClient *client;
140};
141
142/**
143 * A namestore client 125 * A namestore client
144 */ 126 */
145struct NamestoreClient 127struct NamestoreClient
@@ -411,16 +393,6 @@ static struct StoreActivity *sa_head;
411static struct StoreActivity *sa_tail; 393static struct StoreActivity *sa_tail;
412 394
413/** 395/**
414 * Head of the DLL of record set locks
415 */
416static struct RecordsLock *locks_head;
417
418/**
419 * Tail of the DLL of record set locks
420 */
421static struct RecordsLock *locks_tail;
422
423/**
424 * Notification context shared by all monitors. 396 * Notification context shared by all monitors.
425 */ 397 */
426static struct GNUNET_NotificationContext *monitor_nc; 398static struct GNUNET_NotificationContext *monitor_nc;
@@ -447,7 +419,6 @@ static void
447cleanup_task (void *cls) 419cleanup_task (void *cls)
448{ 420{
449 struct CacheOperation *cop; 421 struct CacheOperation *cop;
450 struct RecordsLock *lock;
451 422
452 (void) cls; 423 (void) cls;
453 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping namestore service\n"); 424 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping namestore service\n");
@@ -459,13 +430,6 @@ cleanup_task (void *cls)
459 GNUNET_CONTAINER_DLL_remove (cop_head, cop_tail, cop); 430 GNUNET_CONTAINER_DLL_remove (cop_head, cop_tail, cop);
460 GNUNET_free (cop); 431 GNUNET_free (cop);
461 } 432 }
462 while (NULL != (lock = locks_head))
463 {
464 GNUNET_CONTAINER_DLL_remove (locks_head,
465 locks_tail,
466 lock);
467 GNUNET_free (lock);
468 }
469 433
470 if (NULL != namecache) 434 if (NULL != namecache)
471 { 435 {
@@ -1154,7 +1118,6 @@ client_disconnect_cb (void *cls,
1154 struct NamestoreClient *nc = app_ctx; 1118 struct NamestoreClient *nc = app_ctx;
1155 struct ZoneIteration *no; 1119 struct ZoneIteration *no;
1156 struct CacheOperation *cop; 1120 struct CacheOperation *cop;
1157 struct RecordsLock *lock;
1158 1121
1159 (void) cls; 1122 (void) cls;
1160 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p disconnected\n", client); 1123 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p disconnected\n", client);
@@ -1205,15 +1168,6 @@ client_disconnect_cb (void *cls,
1205 for (cop = cop_head; NULL != cop; cop = cop->next) 1168 for (cop = cop_head; NULL != cop; cop = cop->next)
1206 if (nc == cop->nc) 1169 if (nc == cop->nc)
1207 cop->nc = NULL; 1170 cop->nc = NULL;
1208 for (lock = locks_head; NULL != lock; lock = lock->next)
1209 {
1210 if (nc != lock->client)
1211 continue;
1212 GNUNET_CONTAINER_DLL_remove (locks_head,
1213 locks_tail,
1214 lock);
1215 GNUNET_free (lock);
1216 }
1217 GNUNET_free (nc); 1171 GNUNET_free (nc);
1218} 1172}
1219 1173
@@ -1407,105 +1361,6 @@ check_record_lookup (void *cls, const struct LabelLookupMessage *ll_msg)
1407 return GNUNET_OK; 1361 return GNUNET_OK;
1408} 1362}
1409 1363
1410static void
1411calculate_lock_hash (const char *label,
1412 const struct GNUNET_IDENTITY_PrivateKey *zone,
1413 struct GNUNET_HashCode *result)
1414{
1415 struct GNUNET_HashContext *hctx;
1416
1417 hctx = GNUNET_CRYPTO_hash_context_start ();
1418 GNUNET_CRYPTO_hash_context_read (hctx, label, strlen (label));
1419 GNUNET_CRYPTO_hash_context_read (hctx, zone,
1420 sizeof (*zone));
1421 GNUNET_CRYPTO_hash_context_finish (hctx, result);
1422}
1423
1424/**
1425 * Release a lock on a record set.
1426 * Does nothing if lock not held.
1427 *
1428 * @param label the label of the record set
1429 * @param zone the zone
1430 * @param nc the client releasing the lock
1431 */
1432static void
1433NST_label_lock_release (const char *label,
1434 const struct GNUNET_IDENTITY_PrivateKey *zone,
1435 const struct NamestoreClient *nc)
1436{
1437 struct GNUNET_HashCode label_hash;
1438 struct RecordsLock *lock;
1439
1440 calculate_lock_hash (label, zone, &label_hash);
1441 for (lock = locks_head; NULL != lock; lock = lock->next)
1442 if (0 == memcmp (&label_hash, &lock->label_hash, sizeof (label_hash)))
1443 break;
1444 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1445 "Record locked: %s\n", (NULL == lock) ? "No" : "Yes");
1446 if (NULL == lock)
1447 return;
1448 if (lock->client != nc)
1449 {
1450 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1451 "Lock is held by other client on `%s'\n", label);
1452 return;
1453 }
1454 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1455 "Unocking %s\n", GNUNET_h2s (&label_hash));
1456 GNUNET_CONTAINER_DLL_remove (locks_head,
1457 locks_tail,
1458 lock);
1459 GNUNET_free (lock);
1460}
1461
1462/**
1463 * Get/set a lock on a record set.
1464 * May be called multiple times but will
1465 * not aquire additional locks.
1466 *
1467 * @param the label of the record set
1468 * @param the zone
1469 * @param the client doing the locking
1470 * @return GNUNET_YES if lock retrieved or set already.
1471 */
1472static enum GNUNET_GenericReturnValue
1473NST_label_lock (const char *label,
1474 const struct GNUNET_IDENTITY_PrivateKey *zone,
1475 struct NamestoreClient *nc)
1476{
1477 struct GNUNET_HashCode label_hash;
1478 struct RecordsLock *lock;
1479
1480 calculate_lock_hash (label, zone, &label_hash);
1481 for (lock = locks_head; NULL != lock; lock = lock->next)
1482 if (0 == memcmp (&label_hash, &lock->label_hash, sizeof (label_hash)))
1483 break;
1484 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1485 "Record locked: %s\n", (NULL == lock) ? "No" : "Yes");
1486 if (NULL != lock)
1487 {
1488 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1489 "Client holds lock: %s\n", (lock->client != nc) ? "No" : "Yes");
1490 if (lock->client != nc)
1491 {
1492 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1493 "Lock is held by other client on `%s'\n", label);
1494 return GNUNET_NO;
1495 }
1496 return GNUNET_YES;
1497 }
1498 lock = GNUNET_new (struct RecordsLock);
1499 lock->client = nc;
1500 memcpy (&lock->label_hash, &label_hash, sizeof (label_hash));
1501 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1502 "Locking %s\n", GNUNET_h2s (&label_hash));
1503 GNUNET_CONTAINER_DLL_insert (locks_head,
1504 locks_tail,
1505 lock);
1506 return GNUNET_YES;
1507}
1508
1509 1364
1510/** 1365/**
1511 * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP message 1366 * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP message
@@ -1520,7 +1375,6 @@ handle_record_lookup (void *cls, const struct LabelLookupMessage *ll_msg)
1520 struct GNUNET_MQ_Envelope *env; 1375 struct GNUNET_MQ_Envelope *env;
1521 struct LabelLookupResponseMessage *llr_msg; 1376 struct LabelLookupResponseMessage *llr_msg;
1522 struct RecordLookupContext rlc; 1377 struct RecordLookupContext rlc;
1523 struct RecordsLock *lock;
1524 struct GNUNET_HashCode label_hash; 1378 struct GNUNET_HashCode label_hash;
1525 const char *name_tmp; 1379 const char *name_tmp;
1526 char *res_name; 1380 char *res_name;
@@ -1544,28 +1398,6 @@ handle_record_lookup (void *cls, const struct LabelLookupMessage *ll_msg)
1544 return; 1398 return;
1545 } 1399 }
1546 name_len = strlen (conv_name) + 1; 1400 name_len = strlen (conv_name) + 1;
1547 if (GNUNET_YES == ntohl (ll_msg->locking))
1548 {
1549 if (GNUNET_NO == NST_label_lock (conv_name, &ll_msg->zone, nc))
1550 {
1551 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1552 "Lock is held by other client on `%s'\n", conv_name);
1553 env =
1554 GNUNET_MQ_msg_extra (llr_msg,
1555 name_len,
1556 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP_RESPONSE);
1557 llr_msg->gns_header.r_id = ll_msg->gns_header.r_id;
1558 llr_msg->private_key = ll_msg->zone;
1559 llr_msg->name_len = htons (name_len);
1560 llr_msg->rd_count = htons (0);
1561 llr_msg->rd_len = htons (0);
1562 llr_msg->found = htons (GNUNET_SYSERR);
1563 GNUNET_memcpy (&llr_msg[1], conv_name, name_len);
1564 GNUNET_MQ_send (nc->mq, env);
1565 GNUNET_free (conv_name);
1566 return;
1567 }
1568 }
1569 rlc.label = conv_name; 1401 rlc.label = conv_name;
1570 rlc.found = GNUNET_NO; 1402 rlc.found = GNUNET_NO;
1571 rlc.res_rd_count = 0; 1403 rlc.res_rd_count = 0;
@@ -1699,7 +1531,6 @@ handle_record_store (void *cls, const struct RecordStoreMessage *rp_msg)
1699 unsigned int rd_count; 1531 unsigned int rd_count;
1700 int res; 1532 int res;
1701 struct StoreActivity *sa; 1533 struct StoreActivity *sa;
1702 struct RecordsLock *lock;
1703 struct GNUNET_HashCode label_hash; 1534 struct GNUNET_HashCode label_hash;
1704 struct GNUNET_TIME_Absolute existing_block_exp; 1535 struct GNUNET_TIME_Absolute existing_block_exp;
1705 struct GNUNET_TIME_Absolute new_block_exp; 1536 struct GNUNET_TIME_Absolute new_block_exp;
@@ -1753,20 +1584,6 @@ handle_record_store (void *cls, const struct RecordStoreMessage *rp_msg)
1753 GNUNET_SERVICE_client_continue (nc->client); 1584 GNUNET_SERVICE_client_continue (nc->client);
1754 return; 1585 return;
1755 } 1586 }
1756 if (GNUNET_YES == ntohl (rp_msg->locking))
1757 {
1758 if (GNUNET_NO == NST_label_lock (conv_name, &rp_msg->private_key, nc))
1759 {
1760 send_store_response (nc, GNUNET_SYSERR, _ ("Record set locked."), rid);
1761 GNUNET_SERVICE_client_continue (nc->client);
1762 GNUNET_free (conv_name);
1763 return;
1764 }
1765 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1766 "Client has lock on `%s', continuing.\n", conv_name);
1767 if (GNUNET_YES == ntohl (rp_msg->locking))
1768 NST_label_lock_release (conv_name, &rp_msg->private_key, nc);
1769 }
1770 1587
1771 GNUNET_STATISTICS_update (statistics, 1588 GNUNET_STATISTICS_update (statistics,
1772 "Well-formed store requests received", 1589 "Well-formed store requests received",