diff options
author | Christian Grothoff <christian@grothoff.org> | 2018-04-25 16:18:31 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2018-04-25 16:18:31 +0200 |
commit | 4dc79497d7f745996068e62e973e34d220580323 (patch) | |
tree | e6d429d3cf2240ec3459f1d4533201dc40b27015 /src/namestore/gnunet-service-namestore.c | |
parent | bdbb7c684f2c9711989d2543ecc08a95be23e6c4 (diff) | |
download | gnunet-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/gnunet-service-namestore.c')
-rw-r--r-- | src/namestore/gnunet-service-namestore.c | 41 |
1 files changed, 31 insertions, 10 deletions
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 | */ |
1401 | static void | 1411 | static void |
1402 | run_zone_iteration_round (struct ZoneIteration *zi) | 1412 | run_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) |