clean up zone iteration logic
authorChristian Grothoff <christian@grothoff.org>
Wed, 25 Apr 2018 16:48:32 +0000 (18:48 +0200)
committerChristian Grothoff <christian@grothoff.org>
Wed, 25 Apr 2018 16:48:32 +0000 (18:48 +0200)
src/namestore/gnunet-service-namestore.c
src/namestore/gnunet-zoneimport.c

index c5a37dcac3d6b5c328aadd49bc2250954c29af57..994eae2c8d26aaef8f94e3222a0c8dd58be5a937 100644 (file)
@@ -1300,29 +1300,6 @@ handle_zone_to_name (void *cls,
 }
 
 
-/**
- * Zone iteration processor result
- */
-enum ZoneIterationResult
-{
-  /**
-   * Iteration start.
-   */
-  IT_START = 0,
-
-  /**
-   * Found records,
-   * Continue to iterate with next iteration_next call
-   */
-  IT_SUCCESS_MORE_AVAILABLE = 1,
-
-  /**
-   * Iteration complete
-   */
-  IT_SUCCESS_NOT_MORE_RESULTS_AVAILABLE = 2
-};
-
-
 /**
  * Context for record remove operations passed from
  * #run_zone_iteration_round to #zone_iterate_proc as closure
@@ -1339,15 +1316,6 @@ struct ZoneIterationProcResult
    */
   uint64_t limit;
 
-  /**
-   * Iteration result: iteration done?
-   * #IT_SUCCESS_MORE_AVAILABLE:  if there may be more results overall but
-   * we got one for now and have sent it to the client
-   * #IT_SUCCESS_NOT_MORE_RESULTS_AVAILABLE: if there are no further results,
-   * #IT_START: if we are still trying to find a result.
-   */
-  int res_iteration_finished;
-
 };
 
 
@@ -1375,21 +1343,22 @@ zone_iterate_proc (void *cls,
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                "Iteration done\n");
-    proc->res_iteration_finished = IT_SUCCESS_NOT_MORE_RESULTS_AVAILABLE;
     return;
   }
   if ( (NULL == zone_key) ||
        (NULL == name) )
   {
     /* what is this!? should never happen */
-    proc->res_iteration_finished = IT_START;
     GNUNET_break (0);
     return;
   }
-  GNUNET_assert (proc->limit > 0);
-  proc->limit--;
   if (0 == proc->limit)
-    proc->res_iteration_finished = IT_SUCCESS_MORE_AVAILABLE;
+  {
+    /* what is this!? should never happen */
+    GNUNET_break (0);
+    return;
+  }
+  proc->limit--;
   send_lookup_response (proc->zi->nc,
                        proc->zi->request_id,
                        zone_key,
@@ -1426,36 +1395,25 @@ run_zone_iteration_round (struct ZoneIteration *zi,
   struct ZoneIterationProcResult proc;
   struct GNUNET_MQ_Envelope *env;
   struct RecordResultMessage *rrm;
-  int ret;
 
   memset (&proc,
           0,
           sizeof (proc));
   proc.zi = zi;
-  proc.res_iteration_finished = IT_START;
   proc.limit = limit;
-  while (IT_START == proc.res_iteration_finished)
-  {
-    if (GNUNET_SYSERR ==
-       (ret = GSN_database->iterate_records (GSN_database->cls,
-                                             (0 == memcmp (&zi->zone,
-                                                            &zero,
-                                                            sizeof (zero)))
-                                             ? NULL
-                                             : &zi->zone,
-                                             zi->offset,
-                                              limit,
-                                             &zone_iterate_proc,
-                                              &proc)))
-    {
-      GNUNET_break (0);
-      break;
-    }
-    if (GNUNET_NO == ret)
-      proc.res_iteration_finished = IT_SUCCESS_NOT_MORE_RESULTS_AVAILABLE;
-    zi->offset++;
-  }
-  if (IT_SUCCESS_MORE_AVAILABLE == proc.res_iteration_finished)
+  GNUNET_break (GNUNET_SYSERR !=
+                GSN_database->iterate_records (GSN_database->cls,
+                                               (0 == memcmp (&zi->zone,
+                                                             &zero,
+                                                             sizeof (zero)))
+                                               ? NULL
+                                               : &zi->zone,
+                                               zi->offset,
+                                               limit,
+                                               &zone_iterate_proc,
+                                               &proc));
+  zi->offset += (limit - proc.limit);
+  if (0 == proc.limit)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "More results available\n");
@@ -1520,8 +1478,7 @@ handle_iteration_stop (void *cls,
   uint32_t rid;
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-             "Received `%s' message\n",
-             "ZONE_ITERATION_STOP");
+             "Received ZONE_ITERATION_STOP message\n");
   rid = ntohl (zis_msg->gns_header.r_id);
   for (zi = nc->op_head; NULL != zi; zi = zi->next)
     if (zi->request_id == rid)
index 356e740f14aad304e55248a6c774500e2db8e030..779df695b7dc2544fb30155e3ae85615bac65c66 100644 (file)
@@ -1515,6 +1515,7 @@ iterate_zones (void *cls)
                                            NULL);
     GNUNET_CONTAINER_multihashmap_destroy (ns_pending);
     ns_pending = NULL;
+    GNUNET_assert (NULL == t);
     t = GNUNET_SCHEDULER_add_now (&process_queue,
                                   NULL);
     return;