aboutsummaryrefslogtreecommitdiff
path: root/src/namestore
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2018-04-25 16:18:31 +0200
committerChristian Grothoff <christian@grothoff.org>2018-04-25 16:18:31 +0200
commit4dc79497d7f745996068e62e973e34d220580323 (patch)
treee6d429d3cf2240ec3459f1d4533201dc40b27015 /src/namestore
parentbdbb7c684f2c9711989d2543ecc08a95be23e6c4 (diff)
downloadgnunet-4dc79497d7f745996068e62e973e34d220580323.tar.gz
gnunet-4dc79497d7f745996068e62e973e34d220580323.zip
extend namestore API to enable faster iterations by returning more than one result at a time
Diffstat (limited to 'src/namestore')
-rw-r--r--src/namestore/gnunet-namestore-fcfsd.c12
-rw-r--r--src/namestore/gnunet-namestore.c6
-rw-r--r--src/namestore/gnunet-service-namestore.c41
-rw-r--r--src/namestore/namestore.h8
-rw-r--r--src/namestore/namestore_api.c6
-rw-r--r--src/namestore/plugin_namestore_flat.c100
-rw-r--r--src/namestore/plugin_namestore_postgres.c36
-rw-r--r--src/namestore/plugin_namestore_sqlite.c185
-rw-r--r--src/namestore/plugin_rest_namestore.c6
-rw-r--r--src/namestore/test_namestore_api.conf11
-rw-r--r--src/namestore/test_namestore_api_monitoring_existing.c27
-rw-r--r--src/namestore/test_namestore_api_zone_iteration.c3
-rw-r--r--src/namestore/test_namestore_api_zone_iteration_nick.c3
-rw-r--r--src/namestore/test_namestore_api_zone_iteration_specific_zone.c3
-rw-r--r--src/namestore/test_namestore_api_zone_iteration_stop.c3
-rw-r--r--src/namestore/test_plugin_namestore.c82
16 files changed, 355 insertions, 177 deletions
diff --git a/src/namestore/gnunet-namestore-fcfsd.c b/src/namestore/gnunet-namestore-fcfsd.c
index ddd609918..6e45f8227 100644
--- a/src/namestore/gnunet-namestore-fcfsd.c
+++ b/src/namestore/gnunet-namestore-fcfsd.c
@@ -326,13 +326,15 @@ iterate_cb (void *cls,
326 326
327 if (1 != rd_len) 327 if (1 != rd_len)
328 { 328 {
329 GNUNET_NAMESTORE_zone_iterator_next (zr->list_it); 329 GNUNET_NAMESTORE_zone_iterator_next (zr->list_it,
330 1);
330 return; 331 return;
331 } 332 }
332 333
333 if (GNUNET_GNSRECORD_TYPE_PKEY != rd->record_type) 334 if (GNUNET_GNSRECORD_TYPE_PKEY != rd->record_type)
334 { 335 {
335 GNUNET_NAMESTORE_zone_iterator_next (zr->list_it); 336 GNUNET_NAMESTORE_zone_iterator_next (zr->list_it,
337 1);
336 return; 338 return;
337 } 339 }
338 340
@@ -343,7 +345,8 @@ iterate_cb (void *cls,
343 if (NULL == pkey) 345 if (NULL == pkey)
344 { 346 {
345 GNUNET_break (0); 347 GNUNET_break (0);
346 GNUNET_NAMESTORE_zone_iterator_next (zr->list_it); 348 GNUNET_NAMESTORE_zone_iterator_next (zr->list_it,
349 1);
347 return; 350 return;
348 } 351 }
349 if (bytes_free < (strlen (name) + strlen (pkey) + 40)) 352 if (bytes_free < (strlen (name) + strlen (pkey) + 40))
@@ -359,7 +362,8 @@ iterate_cb (void *cls,
359 name, 362 name,
360 pkey); 363 pkey);
361 zr->write_offset = strlen (zr->zoneinfo); 364 zr->write_offset = strlen (zr->zoneinfo);
362 GNUNET_NAMESTORE_zone_iterator_next (zr->list_it); 365 GNUNET_NAMESTORE_zone_iterator_next (zr->list_it,
366 1);
363 GNUNET_free (pkey); 367 GNUNET_free (pkey);
364} 368}
365 369
diff --git a/src/namestore/gnunet-namestore.c b/src/namestore/gnunet-namestore.c
index 660737595..7b8312b46 100644
--- a/src/namestore/gnunet-namestore.c
+++ b/src/namestore/gnunet-namestore.c
@@ -398,7 +398,8 @@ display_record (void *cls,
398 if ( (NULL != name) && 398 if ( (NULL != name) &&
399 (0 != strcmp (name, rname)) ) 399 (0 != strcmp (name, rname)) )
400 { 400 {
401 GNUNET_NAMESTORE_zone_iterator_next (list_it); 401 GNUNET_NAMESTORE_zone_iterator_next (list_it,
402 1);
402 return; 403 return;
403 } 404 }
404 FPRINTF (stdout, 405 FPRINTF (stdout,
@@ -441,7 +442,8 @@ display_record (void *cls,
441 GNUNET_free (s); 442 GNUNET_free (s);
442 } 443 }
443 FPRINTF (stdout, "%s", "\n"); 444 FPRINTF (stdout, "%s", "\n");
444 GNUNET_NAMESTORE_zone_iterator_next (list_it); 445 GNUNET_NAMESTORE_zone_iterator_next (list_it,
446 1);
445} 447}
446 448
447 449
diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c
index cc41f071d..2fffbeba7 100644
--- a/src/namestore/gnunet-service-namestore.c
+++ b/src/namestore/gnunet-service-namestore.c
@@ -83,8 +83,8 @@ struct ZoneIteration
83 * Offset of the zone iteration used to address next result of the zone 83 * Offset of the zone iteration used to address next result of the zone
84 * iteration in the store 84 * iteration in the store
85 * 85 *
86 * Initialy set to 0 in handle_iteration_start 86 * Initialy set to 0 in #handle_iteration_start
87 * Incremented with by every call to handle_iteration_next 87 * Incremented with by every call to #handle_iteration_next
88 */ 88 */
89 uint32_t offset; 89 uint32_t offset;
90 90
@@ -1065,6 +1065,7 @@ handle_record_store (void *cls,
1065 GSN_database->iterate_records (GSN_database->cls, 1065 GSN_database->iterate_records (GSN_database->cls,
1066 &rp_msg->private_key, 1066 &rp_msg->private_key,
1067 0, 1067 0,
1068 1,
1068 NULL, 1069 NULL,
1069 0)) ) 1070 0)) )
1070 { 1071 {
@@ -1323,6 +1324,11 @@ struct ZoneIterationProcResult
1323 struct ZoneIteration *zi; 1324 struct ZoneIteration *zi;
1324 1325
1325 /** 1326 /**
1327 * Number of results left to be returned in this iteration.
1328 */
1329 uint64_t limit;
1330
1331 /**
1326 * Iteration result: iteration done? 1332 * Iteration result: iteration done?
1327 * #IT_SUCCESS_MORE_AVAILABLE: if there may be more results overall but 1333 * #IT_SUCCESS_MORE_AVAILABLE: if there may be more results overall but
1328 * we got one for now and have sent it to the client 1334 * we got one for now and have sent it to the client
@@ -1361,14 +1367,18 @@ zone_iterate_proc (void *cls,
1361 proc->res_iteration_finished = IT_SUCCESS_NOT_MORE_RESULTS_AVAILABLE; 1367 proc->res_iteration_finished = IT_SUCCESS_NOT_MORE_RESULTS_AVAILABLE;
1362 return; 1368 return;
1363 } 1369 }
1364 if ((NULL == zone_key) || (NULL == name)) 1370 if ( (NULL == zone_key) ||
1371 (NULL == name) )
1365 { 1372 {
1366 /* what is this!? should never happen */ 1373 /* what is this!? should never happen */
1367 proc->res_iteration_finished = IT_START; 1374 proc->res_iteration_finished = IT_START;
1368 GNUNET_break (0); 1375 GNUNET_break (0);
1369 return; 1376 return;
1370 } 1377 }
1371 proc->res_iteration_finished = IT_SUCCESS_MORE_AVAILABLE; 1378 GNUNET_assert (proc->limit > 0);
1379 proc->limit--;
1380 if (0 == proc->limit)
1381 proc->res_iteration_finished = IT_SUCCESS_MORE_AVAILABLE;
1372 send_lookup_response (proc->zi->nc, 1382 send_lookup_response (proc->zi->nc,
1373 proc->zi->request_id, 1383 proc->zi->request_id,
1374 zone_key, 1384 zone_key,
@@ -1389,7 +1399,6 @@ zone_iterate_proc (void *cls,
1389 name, 1399 name,
1390 rd_count, 1400 rd_count,
1391 rd); 1401 rd);
1392
1393} 1402}
1394 1403
1395 1404
@@ -1397,18 +1406,23 @@ zone_iterate_proc (void *cls,
1397 * Perform the next round of the zone iteration. 1406 * Perform the next round of the zone iteration.
1398 * 1407 *
1399 * @param zi zone iterator to process 1408 * @param zi zone iterator to process
1409 * @param limit number of results to return in one pass
1400 */ 1410 */
1401static void 1411static void
1402run_zone_iteration_round (struct ZoneIteration *zi) 1412run_zone_iteration_round (struct ZoneIteration *zi,
1413 uint64_t limit)
1403{ 1414{
1404 struct ZoneIterationProcResult proc; 1415 struct ZoneIterationProcResult proc;
1405 struct GNUNET_MQ_Envelope *env; 1416 struct GNUNET_MQ_Envelope *env;
1406 struct RecordResultMessage *rrm; 1417 struct RecordResultMessage *rrm;
1407 int ret; 1418 int ret;
1408 1419
1409 memset (&proc, 0, sizeof (proc)); 1420 memset (&proc,
1421 0,
1422 sizeof (proc));
1410 proc.zi = zi; 1423 proc.zi = zi;
1411 proc.res_iteration_finished = IT_START; 1424 proc.res_iteration_finished = IT_START;
1425 proc.limit = limit;
1412 while (IT_START == proc.res_iteration_finished) 1426 while (IT_START == proc.res_iteration_finished)
1413 { 1427 {
1414 if (GNUNET_SYSERR == 1428 if (GNUNET_SYSERR ==
@@ -1419,6 +1433,7 @@ run_zone_iteration_round (struct ZoneIteration *zi)
1419 ? NULL 1433 ? NULL
1420 : &zi->zone, 1434 : &zi->zone,
1421 zi->offset, 1435 zi->offset,
1436 limit,
1422 &zone_iterate_proc, 1437 &zone_iterate_proc,
1423 &proc))) 1438 &proc)))
1424 { 1439 {
@@ -1433,7 +1448,8 @@ run_zone_iteration_round (struct ZoneIteration *zi)
1433 { 1448 {
1434 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1449 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1435 "More results available\n"); 1450 "More results available\n");
1436 return; /* more results later */ 1451 return; /* more results later after we get the
1452 #GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT message */
1437 } 1453 }
1438 /* send empty response to indicate end of list */ 1454 /* send empty response to indicate end of list */
1439 env = GNUNET_MQ_msg (rrm, 1455 env = GNUNET_MQ_msg (rrm,
@@ -1472,7 +1488,8 @@ handle_iteration_start (void *cls,
1472 GNUNET_CONTAINER_DLL_insert (nc->op_head, 1488 GNUNET_CONTAINER_DLL_insert (nc->op_head,
1473 nc->op_tail, 1489 nc->op_tail,
1474 zi); 1490 zi);
1475 run_zone_iteration_round (zi); 1491 run_zone_iteration_round (zi,
1492 1);
1476 GNUNET_SERVICE_client_continue (nc->client); 1493 GNUNET_SERVICE_client_continue (nc->client);
1477} 1494}
1478 1495
@@ -1525,6 +1542,7 @@ handle_iteration_next (void *cls,
1525 struct NamestoreClient *nc = cls; 1542 struct NamestoreClient *nc = cls;
1526 struct ZoneIteration *zi; 1543 struct ZoneIteration *zi;
1527 uint32_t rid; 1544 uint32_t rid;
1545 uint64_t limit;
1528 1546
1529 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1547 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1530 "Received ZONE_ITERATION_NEXT message\n"); 1548 "Received ZONE_ITERATION_NEXT message\n");
@@ -1533,6 +1551,7 @@ handle_iteration_next (void *cls,
1533 1, 1551 1,
1534 GNUNET_NO); 1552 GNUNET_NO);
1535 rid = ntohl (zis_msg->gns_header.r_id); 1553 rid = ntohl (zis_msg->gns_header.r_id);
1554 limit = GNUNET_ntohll (zis_msg->limit);
1536 for (zi = nc->op_head; NULL != zi; zi = zi->next) 1555 for (zi = nc->op_head; NULL != zi; zi = zi->next)
1537 if (zi->request_id == rid) 1556 if (zi->request_id == rid)
1538 break; 1557 break;
@@ -1542,7 +1561,8 @@ handle_iteration_next (void *cls,
1542 GNUNET_SERVICE_client_drop (nc->client); 1561 GNUNET_SERVICE_client_drop (nc->client);
1543 return; 1562 return;
1544 } 1563 }
1545 run_zone_iteration_round (zi); 1564 run_zone_iteration_round (zi,
1565 limit);
1546 GNUNET_SERVICE_client_continue (nc->client); 1566 GNUNET_SERVICE_client_continue (nc->client);
1547} 1567}
1548 1568
@@ -1665,6 +1685,7 @@ monitor_next (void *cls)
1665 ? NULL 1685 ? NULL
1666 : &zm->zone, 1686 : &zm->zone,
1667 zm->offset++, 1687 zm->offset++,
1688 1,
1668 &monitor_iterate_cb, 1689 &monitor_iterate_cb,
1669 zm); 1690 zm);
1670 if (GNUNET_SYSERR == ret) 1691 if (GNUNET_SYSERR == ret)
diff --git a/src/namestore/namestore.h b/src/namestore/namestore.h
index ec7f28704..b398af8a9 100644
--- a/src/namestore/namestore.h
+++ b/src/namestore/namestore.h
@@ -345,6 +345,14 @@ struct ZoneIterationNextMessage
345 * Type will be #GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT 345 * Type will be #GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT
346 */ 346 */
347 struct GNUNET_NAMESTORE_Header gns_header; 347 struct GNUNET_NAMESTORE_Header gns_header;
348
349 /**
350 * Number of records to return to the iterator in one shot
351 * (before #GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT
352 * should be send again). In NBO.
353 */
354 uint64_t limit;
355
348}; 356};
349 357
350 358
diff --git a/src/namestore/namestore_api.c b/src/namestore/namestore_api.c
index 05bdf17da..65d3d75d0 100644
--- a/src/namestore/namestore_api.c
+++ b/src/namestore/namestore_api.c
@@ -1281,9 +1281,12 @@ GNUNET_NAMESTORE_zone_iteration_start (struct GNUNET_NAMESTORE_Handle *h,
1281 * for the next record. 1281 * for the next record.
1282 * 1282 *
1283 * @param it the iterator 1283 * @param it the iterator
1284 * @param limit number of records to return to the iterator in one shot
1285 * (before #GNUNET_NAMESTORE_zone_iterator_next is to be called again)
1284 */ 1286 */
1285void 1287void
1286GNUNET_NAMESTORE_zone_iterator_next (struct GNUNET_NAMESTORE_ZoneIterator *it) 1288GNUNET_NAMESTORE_zone_iterator_next (struct GNUNET_NAMESTORE_ZoneIterator *it,
1289 uint64_t limit)
1287{ 1290{
1288 struct GNUNET_NAMESTORE_Handle *h = it->h; 1291 struct GNUNET_NAMESTORE_Handle *h = it->h;
1289 struct ZoneIterationNextMessage *msg; 1292 struct ZoneIterationNextMessage *msg;
@@ -1294,6 +1297,7 @@ GNUNET_NAMESTORE_zone_iterator_next (struct GNUNET_NAMESTORE_ZoneIterator *it)
1294 env = GNUNET_MQ_msg (msg, 1297 env = GNUNET_MQ_msg (msg,
1295 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT); 1298 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT);
1296 msg->gns_header.r_id = htonl (it->op_id); 1299 msg->gns_header.r_id = htonl (it->op_id);
1300 msg->limit = GNUNET_htonll (limit);
1297 GNUNET_MQ_send (h->mq, 1301 GNUNET_MQ_send (h->mq,
1298 env); 1302 env);
1299} 1303}
diff --git a/src/namestore/plugin_namestore_flat.c b/src/namestore/plugin_namestore_flat.c
index 305fe7ba1..e9ed1cc4f 100644
--- a/src/namestore/plugin_namestore_flat.c
+++ b/src/namestore/plugin_namestore_flat.c
@@ -86,6 +86,7 @@ struct Plugin
86 86
87}; 87};
88 88
89
89struct FlatFileEntry 90struct FlatFileEntry
90{ 91{
91 /** 92 /**
@@ -501,9 +502,7 @@ namestore_flat_lookup_records (void *cls,
501 size_t key_len; 502 size_t key_len;
502 503
503 if (NULL == zone) 504 if (NULL == zone)
504 {
505 return GNUNET_SYSERR; 505 return GNUNET_SYSERR;
506 }
507 key_len = strlen (label) + sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey); 506 key_len = strlen (label) + sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey);
508 key = GNUNET_malloc (key_len); 507 key = GNUNET_malloc (key_len);
509 GNUNET_memcpy (key, 508 GNUNET_memcpy (key,
@@ -532,30 +531,77 @@ namestore_flat_lookup_records (void *cls,
532} 531}
533 532
534 533
534/**
535 * Closure for #iterate_zones.
536 */
537struct IterateContext
538{
539 /**
540 * How many more records should we skip before returning results?
541 */
542 uint64_t offset;
543
544 /**
545 * How many more records should we return?
546 */
547 uint64_t limit;
548
549 /**
550 * Target zone.
551 */
552 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone;
553
554 /**
555 * Function to call on each record.
556 */
557 GNUNET_NAMESTORE_RecordIterator iter;
558
559 /**
560 * Closure for @e iter.
561 */
562 void *iter_cls;
563
564};
565
566
567/**
568 * Helper function for #namestore_flat_iterate_records().
569 *
570 * @param cls a `struct IterateContext`
571 * @param key unused
572 * @param value a `struct FlatFileEntry`
573 * @return #GNUNET_YES to continue the iteration
574 */
535static int 575static int
536iterate_zones (void *cls, 576iterate_zones (void *cls,
537 const struct GNUNET_HashCode *key, 577 const struct GNUNET_HashCode *key,
538 void *value) 578 void *value)
539{ 579{
540 struct Plugin *plugin = cls; 580 struct IterateContext *ic = cls;
541 struct FlatFileEntry *entry = value; 581 struct FlatFileEntry *entry = value;
542 582
543 (void) key; 583 (void) key;
544 if ((plugin->target_offset > plugin->offset) || 584 if (0 == ic->limit)
545 ( (NULL != plugin->iter_zone) && 585 return GNUNET_NO;
546 (0 != memcmp (entry->private_key, 586 if ( (NULL != it->zone) &&
547 plugin->iter_zone, 587 (0 != memcmp (entry->private_key,
548 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))))) { 588 ic->zone,
549 plugin->offset++; 589 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) )
590 return GNUNET_YES;
591 if (ic->offset > 0)
592 {
593 ic->offset--;
550 return GNUNET_YES; 594 return GNUNET_YES;
551 } 595 }
552 plugin->iter (plugin->iter_cls, 596 ic->iter (ic->iter_cls,
553 entry->private_key, 597 entry->private_key,
554 entry->label, 598 entry->label,
555 entry->record_count, 599 entry->record_count,
556 entry->record_data); 600 entry->record_data);
557 plugin->iter_result_found = GNUNET_YES; 601 ic->limit--;
558 return GNUNET_NO; 602 if (0 == ic->limit)
603 return GNUNET_NO;
604 return GNUNET_YES;
559} 605}
560 606
561 607
@@ -566,31 +612,31 @@ iterate_zones (void *cls,
566 * @param cls closure (internal context for the plugin) 612 * @param cls closure (internal context for the plugin)
567 * @param zone hash of public key of the zone, NULL to iterate over all zones 613 * @param zone hash of public key of the zone, NULL to iterate over all zones
568 * @param offset offset in the list of all matching records 614 * @param offset offset in the list of all matching records
615 * @param limit maximum number of results to return to @a iter
569 * @param iter function to call with the result 616 * @param iter function to call with the result
570 * @param iter_cls closure for @a iter 617 * @param iter_cls closure for @a iter
571 * @return #GNUNET_OK on success, #GNUNET_NO if there were no results, #GNUNET_SYSERR on error 618 * @return #GNUNET_OK on success, #GNUNET_NO if there were no more results, #GNUNET_SYSERR on error
572 */ 619 */
573static int 620static int
574namestore_flat_iterate_records (void *cls, 621namestore_flat_iterate_records (void *cls,
575 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, 622 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
576 uint64_t offset, 623 uint64_t offset,
624 uint64_t limit,
577 GNUNET_NAMESTORE_RecordIterator iter, 625 GNUNET_NAMESTORE_RecordIterator iter,
578 void *iter_cls) 626 void *iter_cls)
579{ 627{
580 struct Plugin *plugin = cls; 628 struct Plugin *plugin = cls;
629 struct IterateContext ic;
581 630
582 /* FIXME: maybe use separate closure to better handle 631 ic.offset = offset;
583 recursive calls? */ 632 ic.limit = limit;
584 plugin->target_offset = offset; 633 ic.iter = iter;
585 plugin->offset = 0; 634 ic.iter_cls = iter_cls;
586 plugin->iter = iter; 635 ic.zone = zone;
587 plugin->iter_cls = iter_cls;
588 plugin->iter_zone = zone;
589 plugin->iter_result_found = GNUNET_NO;
590 GNUNET_CONTAINER_multihashmap_iterate (plugin->hm, 636 GNUNET_CONTAINER_multihashmap_iterate (plugin->hm,
591 &iterate_zones, 637 &iterate_zones,
592 plugin); 638 &ic);
593 return plugin->iter_result_found; 639 return (0 == ic.limit) ? GNUNET_OK : GNUNET_NO;
594} 640}
595 641
596 642
diff --git a/src/namestore/plugin_namestore_postgres.c b/src/namestore/plugin_namestore_postgres.c
index e38fcafb1..4a24ddf88 100644
--- a/src/namestore/plugin_namestore_postgres.c
+++ b/src/namestore/plugin_namestore_postgres.c
@@ -149,22 +149,28 @@ database_setup (struct Plugin *plugin)
149 struct GNUNET_PQ_PreparedStatement ps[] = { 149 struct GNUNET_PQ_PreparedStatement ps[] = {
150 GNUNET_PQ_make_prepare ("store_records", 150 GNUNET_PQ_make_prepare ("store_records",
151 "INSERT INTO ns097records (zone_private_key, pkey, rvalue, record_count, record_data, label) VALUES " 151 "INSERT INTO ns097records (zone_private_key, pkey, rvalue, record_count, record_data, label) VALUES "
152 "($1, $2, $3, $4, $5, $6)", 6), 152 "($1, $2, $3, $4, $5, $6)",
153 6),
153 GNUNET_PQ_make_prepare ("delete_records", 154 GNUNET_PQ_make_prepare ("delete_records",
154 "DELETE FROM ns097records " 155 "DELETE FROM ns097records "
155 "WHERE zone_private_key=$1 AND label=$2", 2), 156 "WHERE zone_private_key=$1 AND label=$2",
157 2),
156 GNUNET_PQ_make_prepare ("zone_to_name", 158 GNUNET_PQ_make_prepare ("zone_to_name",
157 "SELECT record_count,record_data,label FROM ns097records" 159 "SELECT record_count,record_data,label FROM ns097records"
158 " WHERE zone_private_key=$1 AND pkey=$2", 2), 160 " WHERE zone_private_key=$1 AND pkey=$2",
161 2),
159 GNUNET_PQ_make_prepare ("iterate_zone", 162 GNUNET_PQ_make_prepare ("iterate_zone",
160 "SELECT record_count,record_data,label FROM ns097records " 163 "SELECT record_count,record_data,label FROM ns097records "
161 "WHERE zone_private_key=$1 ORDER BY rvalue LIMIT 1 OFFSET $2", 2), 164 "WHERE zone_private_key=$1 ORDER BY rvalue OFFSET $2 LIMIT $3",
165 3),
162 GNUNET_PQ_make_prepare ("iterate_all_zones", 166 GNUNET_PQ_make_prepare ("iterate_all_zones",
163 "SELECT record_count,record_data,label,zone_private_key" 167 "SELECT record_count,record_data,label,zone_private_key"
164 " FROM ns097records ORDER BY rvalue LIMIT 1 OFFSET $1", 1), 168 " FROM ns097records ORDER BY rvalue OFFSET $1 LIMIT $2",
169 2),
165 GNUNET_PQ_make_prepare ("lookup_label", 170 GNUNET_PQ_make_prepare ("lookup_label",
166 "SELECT record_count,record_data,label " 171 "SELECT record_count,record_data,label "
167 "FROM ns097records WHERE zone_private_key=$1 AND label=$2", 2), 172 "FROM ns097records WHERE zone_private_key=$1 AND label=$2",
173 2),
168 GNUNET_PQ_PREPARED_STATEMENT_END 174 GNUNET_PQ_PREPARED_STATEMENT_END
169 }; 175 };
170 176
@@ -278,6 +284,12 @@ struct ParserContext
278 * Zone key, NULL if part of record. 284 * Zone key, NULL if part of record.
279 */ 285 */
280 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key; 286 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key;
287
288 /**
289 * Number of results still to return (counted down by
290 * number of results given to iterator).
291 */
292 uint64_t limit;
281}; 293};
282 294
283 295
@@ -360,6 +372,7 @@ parse_result_call_iterator (void *cls,
360 } 372 }
361 GNUNET_PQ_cleanup_result (rs); 373 GNUNET_PQ_cleanup_result (rs);
362 } 374 }
375 pc->limit -= num_results;
363} 376}
364 377
365 378
@@ -410,14 +423,16 @@ namestore_postgres_lookup_records (void *cls,
410 * @param cls closure (internal context for the plugin) 423 * @param cls closure (internal context for the plugin)
411 * @param zone hash of public key of the zone, NULL to iterate over all zones 424 * @param zone hash of public key of the zone, NULL to iterate over all zones
412 * @param offset offset in the list of all matching records 425 * @param offset offset in the list of all matching records
426 * @param limit maximum number of results to fetch
413 * @param iter function to call with the result 427 * @param iter function to call with the result
414 * @param iter_cls closure for @a iter 428 * @param iter_cls closure for @a iter
415 * @return #GNUNET_OK on success, #GNUNET_NO if there were no results, #GNUNET_SYSERR on error 429 * @return #GNUNET_OK on success, #GNUNET_NO if there were no more results, #GNUNET_SYSERR on error
416 */ 430 */
417static int 431static int
418namestore_postgres_iterate_records (void *cls, 432namestore_postgres_iterate_records (void *cls,
419 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, 433 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
420 uint64_t offset, 434 uint64_t offset,
435 uint64_t limit,
421 GNUNET_NAMESTORE_RecordIterator iter, 436 GNUNET_NAMESTORE_RecordIterator iter,
422 void *iter_cls) 437 void *iter_cls)
423{ 438{
@@ -428,10 +443,12 @@ namestore_postgres_iterate_records (void *cls,
428 pc.iter = iter; 443 pc.iter = iter;
429 pc.iter_cls = iter_cls; 444 pc.iter_cls = iter_cls;
430 pc.zone_key = zone; 445 pc.zone_key = zone;
446 pc.limit = limit;
431 if (NULL == zone) 447 if (NULL == zone)
432 { 448 {
433 struct GNUNET_PQ_QueryParam params_without_zone[] = { 449 struct GNUNET_PQ_QueryParam params_without_zone[] = {
434 GNUNET_PQ_query_param_uint64 (&offset), 450 GNUNET_PQ_query_param_uint64 (&offset),
451 GNUNET_PQ_query_param_uint64 (&limit),
435 GNUNET_PQ_query_param_end 452 GNUNET_PQ_query_param_end
436 }; 453 };
437 454
@@ -446,6 +463,7 @@ namestore_postgres_iterate_records (void *cls,
446 struct GNUNET_PQ_QueryParam params_with_zone[] = { 463 struct GNUNET_PQ_QueryParam params_with_zone[] = {
447 GNUNET_PQ_query_param_auto_from_type (zone), 464 GNUNET_PQ_query_param_auto_from_type (zone),
448 GNUNET_PQ_query_param_uint64 (&offset), 465 GNUNET_PQ_query_param_uint64 (&offset),
466 GNUNET_PQ_query_param_uint64 (&limit),
449 GNUNET_PQ_query_param_end 467 GNUNET_PQ_query_param_end
450 }; 468 };
451 469
@@ -458,9 +476,9 @@ namestore_postgres_iterate_records (void *cls,
458 if (res < 0) 476 if (res < 0)
459 return GNUNET_SYSERR; 477 return GNUNET_SYSERR;
460 478
461 if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == res) 479 if ( (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == res) ||
480 (pc.limit > 0) )
462 return GNUNET_NO; 481 return GNUNET_NO;
463
464 return GNUNET_OK; 482 return GNUNET_OK;
465} 483}
466 484
diff --git a/src/namestore/plugin_namestore_sqlite.c b/src/namestore/plugin_namestore_sqlite.c
index 5ad84688c..f905787b5 100644
--- a/src/namestore/plugin_namestore_sqlite.c
+++ b/src/namestore/plugin_namestore_sqlite.c
@@ -302,12 +302,12 @@ database_setup (struct Plugin *plugin)
302 sq_prepare (plugin->dbh, 302 sq_prepare (plugin->dbh,
303 "SELECT record_count,record_data,label" 303 "SELECT record_count,record_data,label"
304 " FROM ns097records WHERE zone_private_key=?" 304 " FROM ns097records WHERE zone_private_key=?"
305 " ORDER BY rvalue LIMIT 1 OFFSET ?", 305 " ORDER BY rvalue LIMIT ? OFFSET ?",
306 &plugin->iterate_zone)) || 306 &plugin->iterate_zone)) ||
307 (SQLITE_OK != 307 (SQLITE_OK !=
308 sq_prepare (plugin->dbh, 308 sq_prepare (plugin->dbh,
309 "SELECT record_count,record_data,label,zone_private_key" 309 "SELECT record_count,record_data,label,zone_private_key"
310 " FROM ns097records ORDER BY rvalue LIMIT 1 OFFSET ?", 310 " FROM ns097records ORDER BY rvalue LIMIT ? OFFSET ?",
311 &plugin->iterate_all_zones)) || 311 &plugin->iterate_all_zones)) ||
312 (SQLITE_OK != 312 (SQLITE_OK !=
313 sq_prepare (plugin->dbh, 313 sq_prepare (plugin->dbh,
@@ -526,16 +526,18 @@ namestore_sqlite_store_records (void *cls,
526 * @param plugin plugin context 526 * @param plugin plugin context
527 * @param stmt to run (and then clean up) 527 * @param stmt to run (and then clean up)
528 * @param zone_key private key of the zone 528 * @param zone_key private key of the zone
529 * @param limit maximum number of results to fetch
529 * @param iter iterator to call with the result 530 * @param iter iterator to call with the result
530 * @param iter_cls closure for @a iter 531 * @param iter_cls closure for @a iter
531 * @return #GNUNET_OK on success, #GNUNET_NO if there were no results, #GNUNET_SYSERR on error 532 * @return #GNUNET_OK on success, #GNUNET_NO if there were no results, #GNUNET_SYSERR on error
532 */ 533 */
533static int 534static int
534get_record_and_call_iterator (struct Plugin *plugin, 535get_records_and_call_iterator (struct Plugin *plugin,
535 sqlite3_stmt *stmt, 536 sqlite3_stmt *stmt,
536 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, 537 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
537 GNUNET_NAMESTORE_RecordIterator iter, 538 uint64_t limit,
538 void *iter_cls) 539 GNUNET_NAMESTORE_RecordIterator iter,
540 void *iter_cls)
539{ 541{
540 uint32_t record_count; 542 uint32_t record_count;
541 size_t data_size; 543 size_t data_size;
@@ -545,74 +547,86 @@ get_record_and_call_iterator (struct Plugin *plugin,
545 int ret; 547 int ret;
546 int sret; 548 int sret;
547 549
548 ret = GNUNET_NO; 550 ret = GNUNET_OK;
549 if (SQLITE_ROW == (sret = sqlite3_step (stmt))) 551 for (uint64_t i = 0;i<limit ; i++)
550 { 552 {
551 struct GNUNET_SQ_ResultSpec rs[] = { 553 if (SQLITE_ROW == (sret = sqlite3_step (stmt)))
552 GNUNET_SQ_result_spec_uint32 (&record_count),
553 GNUNET_SQ_result_spec_variable_size (&data, &data_size),
554 GNUNET_SQ_result_spec_string (&label),
555 GNUNET_SQ_result_spec_end
556 };
557 struct GNUNET_SQ_ResultSpec rsx[] = {
558 GNUNET_SQ_result_spec_uint32 (&record_count),
559 GNUNET_SQ_result_spec_variable_size (&data, &data_size),
560 GNUNET_SQ_result_spec_string (&label),
561 GNUNET_SQ_result_spec_auto_from_type (&zk),
562 GNUNET_SQ_result_spec_end
563 };
564
565 if (NULL == zone_key)
566 {
567 zone_key = &zk;
568 ret = GNUNET_SQ_extract_result (stmt,
569 rsx);
570 }
571 else
572 {
573 ret = GNUNET_SQ_extract_result (stmt,
574 rs);
575 }
576 if ( (GNUNET_OK != ret) ||
577 (record_count > 64 * 1024) )
578 { 554 {
579 /* sanity check, don't stack allocate far too much just 555 struct GNUNET_SQ_ResultSpec rs[] = {
580 because database might contain a large value here */ 556 GNUNET_SQ_result_spec_uint32 (&record_count),
581 GNUNET_break (0); 557 GNUNET_SQ_result_spec_variable_size (&data, &data_size),
582 ret = GNUNET_SYSERR; 558 GNUNET_SQ_result_spec_string (&label),
559 GNUNET_SQ_result_spec_end
560 };
561 struct GNUNET_SQ_ResultSpec rsx[] = {
562 GNUNET_SQ_result_spec_uint32 (&record_count),
563 GNUNET_SQ_result_spec_variable_size (&data, &data_size),
564 GNUNET_SQ_result_spec_string (&label),
565 GNUNET_SQ_result_spec_auto_from_type (&zk),
566 GNUNET_SQ_result_spec_end
567 };
568
569 if (NULL == zone_key)
570 {
571 zone_key = &zk;
572 ret = GNUNET_SQ_extract_result (stmt,
573 rsx);
574 }
575 else
576 {
577 ret = GNUNET_SQ_extract_result (stmt,
578 rs);
579 }
580 if ( (GNUNET_OK != ret) ||
581 (record_count > 64 * 1024) )
582 {
583 /* sanity check, don't stack allocate far too much just
584 because database might contain a large value here */
585 GNUNET_break (0);
586 ret = GNUNET_SYSERR;
587 break;
588 }
589 else
590 {
591 struct GNUNET_GNSRECORD_Data rd[record_count];
592
593 if (GNUNET_OK !=
594 GNUNET_GNSRECORD_records_deserialize (data_size,
595 data,
596 record_count,
597 rd))
598 {
599 GNUNET_break (0);
600 ret = GNUNET_SYSERR;
601 break;
602 }
603 else
604 {
605 if (NULL != iter)
606 iter (iter_cls,
607 zone_key,
608 label,
609 record_count,
610 rd);
611 }
612 }
613 GNUNET_SQ_cleanup_result (rs);
583 } 614 }
584 else 615 else
585 { 616 {
586 struct GNUNET_GNSRECORD_Data rd[record_count]; 617 if (SQLITE_DONE != sret)
587
588 if (GNUNET_OK !=
589 GNUNET_GNSRECORD_records_deserialize (data_size,
590 data,
591 record_count,
592 rd))
593 { 618 {
594 GNUNET_break (0); 619 LOG_SQLITE (plugin,
595 ret = GNUNET_SYSERR; 620 GNUNET_ERROR_TYPE_ERROR,
621 "sqlite_step");
622 ret = GNUNET_SYSERR;
596 } 623 }
597 else 624 else
598 { 625 {
599 if (NULL != iter) 626 ret = GNUNET_NO;
600 iter (iter_cls,
601 zone_key,
602 label,
603 record_count,
604 rd);
605 ret = GNUNET_YES;
606 } 627 }
628 break;
607 } 629 }
608 GNUNET_SQ_cleanup_result (rs);
609 }
610 else
611 {
612 if (SQLITE_DONE != sret)
613 LOG_SQLITE (plugin,
614 GNUNET_ERROR_TYPE_ERROR,
615 "sqlite_step");
616 } 630 }
617 GNUNET_SQ_reset (plugin->dbh, 631 GNUNET_SQ_reset (plugin->dbh,
618 stmt); 632 stmt);
@@ -656,11 +670,12 @@ namestore_sqlite_lookup_records (void *cls,
656 plugin->lookup_label); 670 plugin->lookup_label);
657 return GNUNET_SYSERR; 671 return GNUNET_SYSERR;
658 } 672 }
659 return get_record_and_call_iterator (plugin, 673 return get_records_and_call_iterator (plugin,
660 plugin->lookup_label, 674 plugin->lookup_label,
661 zone, 675 zone,
662 iter, 676 1,
663 iter_cls); 677 iter,
678 iter_cls);
664} 679}
665 680
666 681
@@ -671,14 +686,16 @@ namestore_sqlite_lookup_records (void *cls,
671 * @param cls closure (internal context for the plugin) 686 * @param cls closure (internal context for the plugin)
672 * @param zone hash of public key of the zone, NULL to iterate over all zones 687 * @param zone hash of public key of the zone, NULL to iterate over all zones
673 * @param offset offset in the list of all matching records 688 * @param offset offset in the list of all matching records
689 * @param limit maximum number of results to return
674 * @param iter function to call with the result 690 * @param iter function to call with the result
675 * @param iter_cls closure for @a iter 691 * @param iter_cls closure for @a iter
676 * @return #GNUNET_OK on success, #GNUNET_NO if there were no results, #GNUNET_SYSERR on error 692 * @return #GNUNET_OK on success, #GNUNET_NO if there were no more results, #GNUNET_SYSERR on error
677 */ 693 */
678static int 694static int
679namestore_sqlite_iterate_records (void *cls, 695namestore_sqlite_iterate_records (void *cls,
680 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, 696 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
681 uint64_t offset, 697 uint64_t offset,
698 uint64_t limit,
682 GNUNET_NAMESTORE_RecordIterator iter, 699 GNUNET_NAMESTORE_RecordIterator iter,
683 void *iter_cls) 700 void *iter_cls)
684{ 701{
@@ -689,6 +706,7 @@ namestore_sqlite_iterate_records (void *cls,
689 if (NULL == zone) 706 if (NULL == zone)
690 { 707 {
691 struct GNUNET_SQ_QueryParam params[] = { 708 struct GNUNET_SQ_QueryParam params[] = {
709 GNUNET_SQ_query_param_uint64 (&limit),
692 GNUNET_SQ_query_param_uint64 (&offset), 710 GNUNET_SQ_query_param_uint64 (&offset),
693 GNUNET_SQ_query_param_end 711 GNUNET_SQ_query_param_end
694 }; 712 };
@@ -701,6 +719,7 @@ namestore_sqlite_iterate_records (void *cls,
701 { 719 {
702 struct GNUNET_SQ_QueryParam params[] = { 720 struct GNUNET_SQ_QueryParam params[] = {
703 GNUNET_SQ_query_param_auto_from_type (zone), 721 GNUNET_SQ_query_param_auto_from_type (zone),
722 GNUNET_SQ_query_param_uint64 (&limit),
704 GNUNET_SQ_query_param_uint64 (&offset), 723 GNUNET_SQ_query_param_uint64 (&offset),
705 GNUNET_SQ_query_param_end 724 GNUNET_SQ_query_param_end
706 }; 725 };
@@ -718,11 +737,12 @@ namestore_sqlite_iterate_records (void *cls,
718 stmt); 737 stmt);
719 return GNUNET_SYSERR; 738 return GNUNET_SYSERR;
720 } 739 }
721 return get_record_and_call_iterator (plugin, 740 return get_records_and_call_iterator (plugin,
722 stmt, 741 stmt,
723 zone, 742 zone,
724 iter, 743 limit,
725 iter_cls); 744 iter,
745 iter_cls);
726} 746}
727 747
728 748
@@ -764,11 +784,12 @@ namestore_sqlite_zone_to_name (void *cls,
764 LOG (GNUNET_ERROR_TYPE_DEBUG, 784 LOG (GNUNET_ERROR_TYPE_DEBUG,
765 "Performing reverse lookup for `%s'\n", 785 "Performing reverse lookup for `%s'\n",
766 GNUNET_GNSRECORD_z2s (value_zone)); 786 GNUNET_GNSRECORD_z2s (value_zone));
767 return get_record_and_call_iterator (plugin, 787 return get_records_and_call_iterator (plugin,
768 plugin->zone_to_name, 788 plugin->zone_to_name,
769 zone, 789 zone,
770 iter, 790 1,
771 iter_cls); 791 iter,
792 iter_cls);
772} 793}
773 794
774 795
@@ -787,7 +808,9 @@ libgnunet_plugin_namestore_sqlite_init (void *cls)
787 808
788 if (NULL != plugin.cfg) 809 if (NULL != plugin.cfg)
789 return NULL; /* can only initialize once! */ 810 return NULL; /* can only initialize once! */
790 memset (&plugin, 0, sizeof (struct Plugin)); 811 memset (&plugin,
812 0,
813 sizeof (struct Plugin));
791 plugin.cfg = cfg; 814 plugin.cfg = cfg;
792 if (GNUNET_OK != database_setup (&plugin)) 815 if (GNUNET_OK != database_setup (&plugin))
793 { 816 {
diff --git a/src/namestore/plugin_rest_namestore.c b/src/namestore/plugin_rest_namestore.c
index aedb39159..fd1528a1d 100644
--- a/src/namestore/plugin_rest_namestore.c
+++ b/src/namestore/plugin_rest_namestore.c
@@ -452,7 +452,8 @@ namestore_list_response (void *cls,
452 "%s does not match %s\n", 452 "%s does not match %s\n",
453 rname, 453 rname,
454 handle->name); 454 handle->name);
455 GNUNET_NAMESTORE_zone_iterator_next (handle->list_it); 455 GNUNET_NAMESTORE_zone_iterator_next (handle->list_it,
456 1);
456 return; 457 return;
457 } 458 }
458 459
@@ -483,7 +484,8 @@ namestore_list_response (void *cls,
483 } 484 }
484 485
485 json_decref (result_array); 486 json_decref (result_array);
486 GNUNET_NAMESTORE_zone_iterator_next (handle->list_it); 487 GNUNET_NAMESTORE_zone_iterator_next (handle->list_it,
488 1);
487} 489}
488 490
489 491
diff --git a/src/namestore/test_namestore_api.conf b/src/namestore/test_namestore_api.conf
index a1a674d89..29ff90b5d 100644
--- a/src/namestore/test_namestore_api.conf
+++ b/src/namestore/test_namestore_api.conf
@@ -1,8 +1,19 @@
1@INLINE@ ../../contrib/no_forcestart.conf
2@INLINE@ ../../contrib/no_autostart_above_core.conf
3
1[PATHS] 4[PATHS]
2GNUNET_TEST_HOME = /tmp/test-gnunet-namestore/ 5GNUNET_TEST_HOME = /tmp/test-gnunet-namestore/
3 6
4[namestore] 7[namestore]
5DATABASE = sqlite 8DATABASE = sqlite
9AUTOSTART = YES
10
11[namecache]
12DATABASE = sqlite
13AUTOSTART = YES
14
15[identity]
16AUTOSTART = YES
6 17
7[namestore-sqlite] 18[namestore-sqlite]
8FILENAME = $GNUNET_TEST_HOME/namestore/sqlite_test.db 19FILENAME = $GNUNET_TEST_HOME/namestore/sqlite_test.db
diff --git a/src/namestore/test_namestore_api_monitoring_existing.c b/src/namestore/test_namestore_api_monitoring_existing.c
index cd1838b5c..374ad44dd 100644
--- a/src/namestore/test_namestore_api_monitoring_existing.c
+++ b/src/namestore/test_namestore_api_monitoring_existing.c
@@ -71,18 +71,18 @@ do_shutdown ()
71 71
72 if (NULL != ns_ops[0]) 72 if (NULL != ns_ops[0])
73 { 73 {
74 GNUNET_NAMESTORE_cancel(ns_ops[0]); 74 GNUNET_NAMESTORE_cancel(ns_ops[0]);
75 ns_ops[0] = NULL; 75 ns_ops[0] = NULL;
76 } 76 }
77 if (NULL != ns_ops[1]) 77 if (NULL != ns_ops[1])
78 { 78 {
79 GNUNET_NAMESTORE_cancel(ns_ops[1]); 79 GNUNET_NAMESTORE_cancel(ns_ops[1]);
80 ns_ops[1] = NULL; 80 ns_ops[1] = NULL;
81 } 81 }
82 if (NULL != ns_ops[2]) 82 if (NULL != ns_ops[2])
83 { 83 {
84 GNUNET_NAMESTORE_cancel(ns_ops[2]); 84 GNUNET_NAMESTORE_cancel(ns_ops[2]);
85 ns_ops[2] = NULL; 85 ns_ops[2] = NULL;
86 } 86 }
87 87
88 if (NULL != nsh) 88 if (NULL != nsh)
@@ -274,18 +274,20 @@ put_cont (void *cls, int32_t success, const char *emsg)
274static struct GNUNET_GNSRECORD_Data * 274static struct GNUNET_GNSRECORD_Data *
275create_record (unsigned int count) 275create_record (unsigned int count)
276{ 276{
277 unsigned int c;
278 struct GNUNET_GNSRECORD_Data * rd; 277 struct GNUNET_GNSRECORD_Data * rd;
279 278
280 rd = GNUNET_malloc (count * sizeof (struct GNUNET_GNSRECORD_Data)); 279 rd = GNUNET_new_array (count,
281 for (c = 0; c < count; c++) 280 struct GNUNET_GNSRECORD_Data);
281 for (unsigned int c = 0; c < count; c++)
282 { 282 {
283 rd[c].expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS).abs_value_us; 283 rd[c].expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS).abs_value_us;
284 rd[c].record_type = 1111; 284 rd[c].record_type = 1111;
285 rd[c].data_size = 50; 285 rd[c].data_size = 50;
286 rd[c].data = GNUNET_malloc(50); 286 rd[c].data = GNUNET_malloc(50);
287 rd[c].flags = 0; 287 rd[c].flags = 0;
288 memset ((char *) rd[c].data, 'a', 50); 288 memset ((char *) rd[c].data,
289 'a',
290 50);
289 } 291 }
290 return rd; 292 return rd;
291} 293}
@@ -300,7 +302,10 @@ run (void *cls,
300 302
301 directory = NULL; 303 directory = NULL;
302 GNUNET_assert (GNUNET_OK == 304 GNUNET_assert (GNUNET_OK ==
303 GNUNET_CONFIGURATION_get_value_string(mycfg, "PATHS", "GNUNET_TEST_HOME", &directory)); 305 GNUNET_CONFIGURATION_get_value_string (mycfg,
306 "PATHS",
307 "GNUNET_TEST_HOME",
308 &directory));
304 GNUNET_DISK_directory_remove (directory); 309 GNUNET_DISK_directory_remove (directory);
305 310
306 res = 1; 311 res = 1;
diff --git a/src/namestore/test_namestore_api_zone_iteration.c b/src/namestore/test_namestore_api_zone_iteration.c
index 8960be55d..1343d42bf 100644
--- a/src/namestore/test_namestore_api_zone_iteration.c
+++ b/src/namestore/test_namestore_api_zone_iteration.c
@@ -276,7 +276,8 @@ zone_proc (void *cls,
276 returned_records ++; 276 returned_records ++;
277 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 277 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
278 "Telling namestore to send the next result\n"); 278 "Telling namestore to send the next result\n");
279 GNUNET_NAMESTORE_zone_iterator_next (zi); 279 GNUNET_NAMESTORE_zone_iterator_next (zi,
280 1);
280 } 281 }
281 else 282 else
282 { 283 {
diff --git a/src/namestore/test_namestore_api_zone_iteration_nick.c b/src/namestore/test_namestore_api_zone_iteration_nick.c
index 791702f97..395d1854f 100644
--- a/src/namestore/test_namestore_api_zone_iteration_nick.c
+++ b/src/namestore/test_namestore_api_zone_iteration_nick.c
@@ -245,7 +245,8 @@ zone_proc (void *cls,
245 returned_records ++; 245 returned_records ++;
246 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 246 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
247 "Telling namestore to send the next result\n"); 247 "Telling namestore to send the next result\n");
248 GNUNET_NAMESTORE_zone_iterator_next (zi); 248 GNUNET_NAMESTORE_zone_iterator_next (zi,
249 1);
249 } 250 }
250 else 251 else
251 { 252 {
diff --git a/src/namestore/test_namestore_api_zone_iteration_specific_zone.c b/src/namestore/test_namestore_api_zone_iteration_specific_zone.c
index c5ae927b0..d222bf16c 100644
--- a/src/namestore/test_namestore_api_zone_iteration_specific_zone.c
+++ b/src/namestore/test_namestore_api_zone_iteration_specific_zone.c
@@ -238,7 +238,8 @@ zone_proc (void *cls,
238 returned_records ++; 238 returned_records ++;
239 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 239 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
240 "Telling namestore to send the next result\n"); 240 "Telling namestore to send the next result\n");
241 GNUNET_NAMESTORE_zone_iterator_next (zi); 241 GNUNET_NAMESTORE_zone_iterator_next (zi,
242 1);
242 } 243 }
243 else 244 else
244 { 245 {
diff --git a/src/namestore/test_namestore_api_zone_iteration_stop.c b/src/namestore/test_namestore_api_zone_iteration_stop.c
index a5f040150..d23a5f4cb 100644
--- a/src/namestore/test_namestore_api_zone_iteration_stop.c
+++ b/src/namestore/test_namestore_api_zone_iteration_stop.c
@@ -271,7 +271,8 @@ zone_proc (void *cls,
271 returned_records ++; 271 returned_records ++;
272 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 272 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
273 "Telling namestore to send the next result\n"); 273 "Telling namestore to send the next result\n");
274 GNUNET_NAMESTORE_zone_iterator_next (zi); 274 GNUNET_NAMESTORE_zone_iterator_next (zi,
275 1);
275 } 276 }
276 else 277 else
277 { 278 {
diff --git a/src/namestore/test_plugin_namestore.c b/src/namestore/test_plugin_namestore.c
index aa5d10809..d591eb325 100644
--- a/src/namestore/test_plugin_namestore.c
+++ b/src/namestore/test_plugin_namestore.c
@@ -47,8 +47,12 @@ unload_plugin (struct GNUNET_NAMESTORE_PluginFunctions *api)
47{ 47{
48 char *libname; 48 char *libname;
49 49
50 GNUNET_asprintf (&libname, "libgnunet_plugin_namestore_%s", plugin_name); 50 GNUNET_asprintf (&libname,
51 GNUNET_break (NULL == GNUNET_PLUGIN_unload (libname, api)); 51 "libgnunet_plugin_namestore_%s",
52 plugin_name);
53 GNUNET_break (NULL ==
54 GNUNET_PLUGIN_unload (libname,
55 api));
52 GNUNET_free (libname); 56 GNUNET_free (libname);
53} 57}
54 58
@@ -65,12 +69,17 @@ load_plugin (const struct GNUNET_CONFIGURATION_Handle *cfg)
65 struct GNUNET_NAMESTORE_PluginFunctions *ret; 69 struct GNUNET_NAMESTORE_PluginFunctions *ret;
66 char *libname; 70 char *libname;
67 71
68 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Loading `%s' namestore plugin\n"), 72 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
73 _("Loading `%s' namestore plugin\n"),
69 plugin_name); 74 plugin_name);
70 GNUNET_asprintf (&libname, "libgnunet_plugin_namestore_%s", plugin_name); 75 GNUNET_asprintf (&libname,
76 "libgnunet_plugin_namestore_%s",
77 plugin_name);
71 if (NULL == (ret = GNUNET_PLUGIN_load (libname, (void*) cfg))) 78 if (NULL == (ret = GNUNET_PLUGIN_load (libname, (void*) cfg)))
72 { 79 {
73 FPRINTF (stderr, "Failed to load plugin `%s'!\n", plugin_name); 80 FPRINTF (stderr,
81 "Failed to load plugin `%s'!\n",
82 plugin_name);
74 GNUNET_free (libname); 83 GNUNET_free (libname);
75 return NULL; 84 return NULL;
76 } 85 }
@@ -81,21 +90,22 @@ load_plugin (const struct GNUNET_CONFIGURATION_Handle *cfg)
81 90
82static void 91static void
83test_record (void *cls, 92test_record (void *cls,
84 const struct GNUNET_CRYPTO_EcdsaPrivateKey *private_key, 93 const struct GNUNET_CRYPTO_EcdsaPrivateKey *private_key,
85 const char *label, 94 const char *label,
86 unsigned int rd_count, 95 unsigned int rd_count,
87 const struct GNUNET_GNSRECORD_Data *rd) 96 const struct GNUNET_GNSRECORD_Data *rd)
88{ 97{
89 int *idp = cls; 98 int *idp = cls;
90 int id = *idp; 99 int id = *idp;
91 struct GNUNET_CRYPTO_EcdsaPrivateKey tzone_private_key; 100 struct GNUNET_CRYPTO_EcdsaPrivateKey tzone_private_key;
92 char tname[64]; 101 char tname[64];
93 unsigned int trd_count = 1 + (id % 1024); 102 unsigned int trd_count = 1 + (id % 1024);
94 unsigned int i;
95 103
96 GNUNET_snprintf (tname, sizeof (tname), 104 GNUNET_snprintf (tname,
97 "a%u", (unsigned int ) id); 105 sizeof (tname),
98 for (i=0;i<trd_count;i++) 106 "a%u",
107 (unsigned int ) id);
108 for (unsigned int i=0;i<trd_count;i++)
99 { 109 {
100 GNUNET_assert (rd[i].data_size == id % 10); 110 GNUNET_assert (rd[i].data_size == id % 10);
101 GNUNET_assert (0 == memcmp ("Hello World", rd[i].data, id % 10)); 111 GNUNET_assert (0 == memcmp ("Hello World", rd[i].data, id % 10));
@@ -104,31 +114,39 @@ test_record (void *cls,
104 } 114 }
105 memset (&tzone_private_key, (id % 241), sizeof (tzone_private_key)); 115 memset (&tzone_private_key, (id % 241), sizeof (tzone_private_key));
106 GNUNET_assert (0 == strcmp (label, tname)); 116 GNUNET_assert (0 == strcmp (label, tname));
107 GNUNET_assert (0 == memcmp (&tzone_private_key, private_key, sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))); 117 GNUNET_assert (0 == memcmp (&tzone_private_key,
118 private_key,
119 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)));
108} 120}
109 121
110 122
111static void 123static void
112get_record (struct GNUNET_NAMESTORE_PluginFunctions *nsp, int id) 124get_record (struct GNUNET_NAMESTORE_PluginFunctions *nsp,
125 int id)
113{ 126{
114 GNUNET_assert (GNUNET_OK == nsp->iterate_records (nsp->cls, 127 GNUNET_assert (GNUNET_OK ==
115 NULL, 0, &test_record, &id)); 128 nsp->iterate_records (nsp->cls,
129 NULL,
130 0,
131 1,
132 &test_record,
133 &id));
116} 134}
117 135
118 136
119static void 137static void
120put_record (struct GNUNET_NAMESTORE_PluginFunctions *nsp, int id) 138put_record (struct GNUNET_NAMESTORE_PluginFunctions *nsp,
139 int id)
121{ 140{
122 struct GNUNET_CRYPTO_EcdsaPrivateKey zone_private_key; 141 struct GNUNET_CRYPTO_EcdsaPrivateKey zone_private_key;
123 char label[64]; 142 char label[64];
124 unsigned int rd_count = 1 + (id % 1024); 143 unsigned int rd_count = 1 + (id % 1024);
125 struct GNUNET_GNSRECORD_Data rd[rd_count]; 144 struct GNUNET_GNSRECORD_Data rd[rd_count];
126 struct GNUNET_CRYPTO_EcdsaSignature signature; 145 struct GNUNET_CRYPTO_EcdsaSignature signature;
127 unsigned int i;
128 146
129 GNUNET_snprintf (label, sizeof (label), 147 GNUNET_snprintf (label, sizeof (label),
130 "a%u", (unsigned int ) id); 148 "a%u", (unsigned int ) id);
131 for (i=0;i<rd_count;i++) 149 for (unsigned int i=0;i<rd_count;i++)
132 { 150 {
133 rd[i].data = "Hello World"; 151 rd[i].data = "Hello World";
134 rd[i].data_size = id % 10; 152 rd[i].data_size = id % 10;
@@ -147,7 +165,9 @@ put_record (struct GNUNET_NAMESTORE_PluginFunctions *nsp, int id)
147 165
148 166
149static void 167static void
150run (void *cls, char *const *args, const char *cfgfile, 168run (void *cls,
169 char *const *args,
170 const char *cfgfile,
151 const struct GNUNET_CONFIGURATION_Handle *cfg) 171 const struct GNUNET_CONFIGURATION_Handle *cfg)
152{ 172{
153 struct GNUNET_NAMESTORE_PluginFunctions *nsp; 173 struct GNUNET_NAMESTORE_PluginFunctions *nsp;
@@ -169,7 +189,8 @@ run (void *cls, char *const *args, const char *cfgfile,
169 189
170 190
171int 191int
172main (int argc, char *argv[]) 192main (int argc,
193 char *argv[])
173{ 194{
174 char cfg_name[128]; 195 char cfg_name[128];
175 char *const xargv[] = { 196 char *const xargv[] = {
@@ -187,12 +208,21 @@ main (int argc, char *argv[])
187 "WARNING", 208 "WARNING",
188 NULL); 209 NULL);
189 plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]); 210 plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]);
190 GNUNET_snprintf (cfg_name, sizeof (cfg_name), "test_plugin_namestore_%s.conf", 211 GNUNET_snprintf (cfg_name,
212 sizeof (cfg_name),
213 "test_plugin_namestore_%s.conf",
191 plugin_name); 214 plugin_name);
192 GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, xargv, 215 GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1,
193 "test-plugin-namestore", "nohelp", options, &run, NULL); 216 xargv,
217 "test-plugin-namestore",
218 "nohelp",
219 options,
220 &run,
221 NULL);
194 if (ok != 0) 222 if (ok != 0)
195 FPRINTF (stderr, "Missed some testcases: %d\n", ok); 223 FPRINTF (stderr,
224 "Missed some testcases: %d\n",
225 ok);
196 //GNUNET_DISK_directory_remove ("/tmp/gnunet-test-plugin-namestore-sqlite"); 226 //GNUNET_DISK_directory_remove ("/tmp/gnunet-test-plugin-namestore-sqlite");
197 return ok; 227 return ok;
198} 228}