diff options
author | Christian Grothoff <christian@grothoff.org> | 2018-04-25 18:48:32 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2018-04-25 18:48:32 +0200 |
commit | c15e7951180d954ca584a95206543e8997b3a7d4 (patch) | |
tree | ae4b35aba9f80f1456946aa82b2863a326e65554 /src/namestore/gnunet-service-namestore.c | |
parent | 5c1d0aa2db08d35e46dbc61ad75b0f6e941248c0 (diff) | |
download | gnunet-c15e7951180d954ca584a95206543e8997b3a7d4.tar.gz gnunet-c15e7951180d954ca584a95206543e8997b3a7d4.zip |
clean up zone iteration logic
Diffstat (limited to 'src/namestore/gnunet-service-namestore.c')
-rw-r--r-- | src/namestore/gnunet-service-namestore.c | 83 |
1 files changed, 20 insertions, 63 deletions
diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c index c5a37dcac..994eae2c8 100644 --- a/src/namestore/gnunet-service-namestore.c +++ b/src/namestore/gnunet-service-namestore.c | |||
@@ -1301,29 +1301,6 @@ handle_zone_to_name (void *cls, | |||
1301 | 1301 | ||
1302 | 1302 | ||
1303 | /** | 1303 | /** |
1304 | * Zone iteration processor result | ||
1305 | */ | ||
1306 | enum ZoneIterationResult | ||
1307 | { | ||
1308 | /** | ||
1309 | * Iteration start. | ||
1310 | */ | ||
1311 | IT_START = 0, | ||
1312 | |||
1313 | /** | ||
1314 | * Found records, | ||
1315 | * Continue to iterate with next iteration_next call | ||
1316 | */ | ||
1317 | IT_SUCCESS_MORE_AVAILABLE = 1, | ||
1318 | |||
1319 | /** | ||
1320 | * Iteration complete | ||
1321 | */ | ||
1322 | IT_SUCCESS_NOT_MORE_RESULTS_AVAILABLE = 2 | ||
1323 | }; | ||
1324 | |||
1325 | |||
1326 | /** | ||
1327 | * Context for record remove operations passed from | 1304 | * Context for record remove operations passed from |
1328 | * #run_zone_iteration_round to #zone_iterate_proc as closure | 1305 | * #run_zone_iteration_round to #zone_iterate_proc as closure |
1329 | */ | 1306 | */ |
@@ -1339,15 +1316,6 @@ struct ZoneIterationProcResult | |||
1339 | */ | 1316 | */ |
1340 | uint64_t limit; | 1317 | uint64_t limit; |
1341 | 1318 | ||
1342 | /** | ||
1343 | * Iteration result: iteration done? | ||
1344 | * #IT_SUCCESS_MORE_AVAILABLE: if there may be more results overall but | ||
1345 | * we got one for now and have sent it to the client | ||
1346 | * #IT_SUCCESS_NOT_MORE_RESULTS_AVAILABLE: if there are no further results, | ||
1347 | * #IT_START: if we are still trying to find a result. | ||
1348 | */ | ||
1349 | int res_iteration_finished; | ||
1350 | |||
1351 | }; | 1319 | }; |
1352 | 1320 | ||
1353 | 1321 | ||
@@ -1375,21 +1343,22 @@ zone_iterate_proc (void *cls, | |||
1375 | { | 1343 | { |
1376 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1344 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1377 | "Iteration done\n"); | 1345 | "Iteration done\n"); |
1378 | proc->res_iteration_finished = IT_SUCCESS_NOT_MORE_RESULTS_AVAILABLE; | ||
1379 | return; | 1346 | return; |
1380 | } | 1347 | } |
1381 | if ( (NULL == zone_key) || | 1348 | if ( (NULL == zone_key) || |
1382 | (NULL == name) ) | 1349 | (NULL == name) ) |
1383 | { | 1350 | { |
1384 | /* what is this!? should never happen */ | 1351 | /* what is this!? should never happen */ |
1385 | proc->res_iteration_finished = IT_START; | ||
1386 | GNUNET_break (0); | 1352 | GNUNET_break (0); |
1387 | return; | 1353 | return; |
1388 | } | 1354 | } |
1389 | GNUNET_assert (proc->limit > 0); | ||
1390 | proc->limit--; | ||
1391 | if (0 == proc->limit) | 1355 | if (0 == proc->limit) |
1392 | proc->res_iteration_finished = IT_SUCCESS_MORE_AVAILABLE; | 1356 | { |
1357 | /* what is this!? should never happen */ | ||
1358 | GNUNET_break (0); | ||
1359 | return; | ||
1360 | } | ||
1361 | proc->limit--; | ||
1393 | send_lookup_response (proc->zi->nc, | 1362 | send_lookup_response (proc->zi->nc, |
1394 | proc->zi->request_id, | 1363 | proc->zi->request_id, |
1395 | zone_key, | 1364 | zone_key, |
@@ -1426,36 +1395,25 @@ run_zone_iteration_round (struct ZoneIteration *zi, | |||
1426 | struct ZoneIterationProcResult proc; | 1395 | struct ZoneIterationProcResult proc; |
1427 | struct GNUNET_MQ_Envelope *env; | 1396 | struct GNUNET_MQ_Envelope *env; |
1428 | struct RecordResultMessage *rrm; | 1397 | struct RecordResultMessage *rrm; |
1429 | int ret; | ||
1430 | 1398 | ||
1431 | memset (&proc, | 1399 | memset (&proc, |
1432 | 0, | 1400 | 0, |
1433 | sizeof (proc)); | 1401 | sizeof (proc)); |
1434 | proc.zi = zi; | 1402 | proc.zi = zi; |
1435 | proc.res_iteration_finished = IT_START; | ||
1436 | proc.limit = limit; | 1403 | proc.limit = limit; |
1437 | while (IT_START == proc.res_iteration_finished) | 1404 | GNUNET_break (GNUNET_SYSERR != |
1438 | { | 1405 | GSN_database->iterate_records (GSN_database->cls, |
1439 | if (GNUNET_SYSERR == | 1406 | (0 == memcmp (&zi->zone, |
1440 | (ret = GSN_database->iterate_records (GSN_database->cls, | 1407 | &zero, |
1441 | (0 == memcmp (&zi->zone, | 1408 | sizeof (zero))) |
1442 | &zero, | 1409 | ? NULL |
1443 | sizeof (zero))) | 1410 | : &zi->zone, |
1444 | ? NULL | 1411 | zi->offset, |
1445 | : &zi->zone, | 1412 | limit, |
1446 | zi->offset, | 1413 | &zone_iterate_proc, |
1447 | limit, | 1414 | &proc)); |
1448 | &zone_iterate_proc, | 1415 | zi->offset += (limit - proc.limit); |
1449 | &proc))) | 1416 | if (0 == proc.limit) |
1450 | { | ||
1451 | GNUNET_break (0); | ||
1452 | break; | ||
1453 | } | ||
1454 | if (GNUNET_NO == ret) | ||
1455 | proc.res_iteration_finished = IT_SUCCESS_NOT_MORE_RESULTS_AVAILABLE; | ||
1456 | zi->offset++; | ||
1457 | } | ||
1458 | if (IT_SUCCESS_MORE_AVAILABLE == proc.res_iteration_finished) | ||
1459 | { | 1417 | { |
1460 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1418 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1461 | "More results available\n"); | 1419 | "More results available\n"); |
@@ -1520,8 +1478,7 @@ handle_iteration_stop (void *cls, | |||
1520 | uint32_t rid; | 1478 | uint32_t rid; |
1521 | 1479 | ||
1522 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1480 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1523 | "Received `%s' message\n", | 1481 | "Received ZONE_ITERATION_STOP message\n"); |
1524 | "ZONE_ITERATION_STOP"); | ||
1525 | rid = ntohl (zis_msg->gns_header.r_id); | 1482 | rid = ntohl (zis_msg->gns_header.r_id); |
1526 | for (zi = nc->op_head; NULL != zi; zi = zi->next) | 1483 | for (zi = nc->op_head; NULL != zi; zi = zi->next) |
1527 | if (zi->request_id == rid) | 1484 | if (zi->request_id == rid) |