- more zone iteration
authorMatthias Wachs <wachs@net.in.tum.de>
Tue, 28 Feb 2012 10:18:27 +0000 (10:18 +0000)
committerMatthias Wachs <wachs@net.in.tum.de>
Tue, 28 Feb 2012 10:18:27 +0000 (10:18 +0000)
src/namestore/gnunet-service-namestore.c
src/namestore/namestore_api.c
src/namestore/test_namestore_api_zone_iteration.c

index e796fe530d97a7d45cbfab7f635caa0be02461fe..f96146ec2990027822a776a06dcb378ac3ab9a35 100644 (file)
@@ -42,6 +42,8 @@ struct GNUNET_NAMESTORE_ZoneIteration
 
   struct GNUNET_NAMESTORE_Client * client;
 
+  GNUNET_HashCode zone;
+
   uint64_t op_id;
   uint32_t offset;
 
@@ -593,7 +595,6 @@ void zone_iteration_proc (void *cls,
   zir_msg.op_id = htonl(zi->op_id);
   zir_msg.header.size = htons (sizeof (struct ZoneIterationResponseMessage));
 
-
   GNUNET_SERVER_notification_context_unicast (snc, zi->client->client, (const struct GNUNET_MessageHeader *) &zir_msg, GNUNET_NO);
 }
 
@@ -606,6 +607,7 @@ static void handle_iteration_start (void *cls,
   struct ZoneIterationStartMessage * zis_msg = (struct ZoneIterationStartMessage *) message;
   struct GNUNET_NAMESTORE_Client *nc;
   struct GNUNET_NAMESTORE_ZoneIteration *zi;
+  int res;
 
   nc = client_lookup(client);
   if (nc == NULL)
@@ -619,10 +621,12 @@ static void handle_iteration_start (void *cls,
   zi->op_id = ntohl (zis_msg->op_id);
   zi->offset = 0;
   zi->client = nc;
+  zi->zone = zis_msg->zone;
 
   GNUNET_CONTAINER_DLL_insert (nc->op_head, nc->op_tail, zi);
 
-  GSN_database->iterate_records (GSN_database->cls, &zis_msg->zone, NULL, zi->offset , &zone_iteration_proc, zi);
+  res = GSN_database->iterate_records (GSN_database->cls, &zis_msg->zone, NULL, zi->offset , &zone_iteration_proc, zi);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "iterate_records: %i\n", res);
   GNUNET_SERVER_receive_done (client, GNUNET_OK);
 }
 
@@ -631,6 +635,38 @@ static void handle_iteration_stop (void *cls,
                           const struct GNUNET_MessageHeader * message)
 {
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "ZONE_ITERATION_STOP");
+
+  struct GNUNET_NAMESTORE_Client *nc;
+  struct GNUNET_NAMESTORE_ZoneIteration *zi;
+  struct ZoneIterationStopMessage * zis_msg = (struct ZoneIterationStopMessage *) message;
+  uint32_t id;
+
+  nc = client_lookup(client);
+  if (nc == NULL)
+  {
+    GNUNET_break_op (0);
+    GNUNET_SERVER_receive_done (client, GNUNET_OK);
+    return;
+  }
+
+  id = ntohl (zis_msg->op_id);
+  for (zi = nc->op_head; zi != NULL; zi = zi->next)
+  {
+    if (zi->op_id == id)
+      break;
+  }
+  if (zi == NULL)
+  {
+    GNUNET_break_op (0);
+    GNUNET_SERVER_receive_done (client, GNUNET_OK);
+    return;
+  }
+
+  GNUNET_CONTAINER_DLL_remove(nc->op_head, nc->op_tail, zi);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopped zone iteration for zone `%s'\n", GNUNET_h2s (&zi->zone));
+  GNUNET_free (zi);
+
+  GNUNET_SERVER_receive_done (client, GNUNET_OK);
 }
 
 static void handle_iteration_next (void *cls,
@@ -671,7 +707,7 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
     {&handle_iteration_start, NULL,
      GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START, sizeof (struct ZoneIterationStartMessage)},
     {&handle_iteration_stop, NULL,
-     GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP, 0},
+     GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP, sizeof (struct ZoneIterationStopMessage)},
     {&handle_iteration_next, NULL,
      GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT, 0},
     {NULL, NULL, 0, 0}
index 17c6380508dd4040afa6c5c0a530bc808d30d011..ace9945da29b30eb6670fab6b77ea3a37319d8e9 100644 (file)
@@ -380,6 +380,13 @@ handle_zone_iteration_response (struct GNUNET_NAMESTORE_ZoneIterator *ze,
 {
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' \n",
               "ZONE_ITERATION_RESPONSE");
+
+
+  if (ze->proc != NULL)
+  {
+    // FIXME
+    ze->proc(ze->proc_cls, NULL, GNUNET_TIME_absolute_get_forever(), "dummy", 0, NULL, NULL);
+  }
 }
 
 
index a53a2febc97f312bc51c1dc5f76b58826b67246b..c0ef8c809565450fee0d574db4962ffc6e6c7643 100644 (file)
@@ -32,6 +32,7 @@
 static struct GNUNET_NAMESTORE_Handle * nsh;
 
 static GNUNET_SCHEDULER_TaskIdentifier endbadly_task;
+static GNUNET_SCHEDULER_TaskIdentifier stopiteration_task;
 static struct GNUNET_OS_Process *arm;
 
 static struct GNUNET_CRYPTO_RsaPrivateKey * privkey;
@@ -76,6 +77,12 @@ stop_arm ()
 static void
 endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
+  if (stopiteration_task != GNUNET_SCHEDULER_NO_TASK)
+  {
+    GNUNET_SCHEDULER_cancel (stopiteration_task);
+    stopiteration_task = GNUNET_SCHEDULER_NO_TASK;
+  }
+
   if (nsh != NULL)
     GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES);
   nsh = NULL;
@@ -94,12 +101,19 @@ endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 static void
 end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
+  if (stopiteration_task != GNUNET_SCHEDULER_NO_TASK)
+  {
+    GNUNET_SCHEDULER_cancel (stopiteration_task);
+    stopiteration_task = GNUNET_SCHEDULER_NO_TASK;
+  }
+
   if (endbadly_task != GNUNET_SCHEDULER_NO_TASK)
   {
     GNUNET_SCHEDULER_cancel (endbadly_task);
     endbadly_task = GNUNET_SCHEDULER_NO_TASK;
   }
 
+
   if (privkey != NULL)
     GNUNET_CRYPTO_rsa_key_free (privkey);
   privkey = NULL;
@@ -115,6 +129,16 @@ end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   res = 0;
 }
 
+static void
+stop_iteration (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+  stopiteration_task = GNUNET_SCHEDULER_NO_TASK;
+
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping iteration for zone `%s'\n", GNUNET_h2s (&zone));
+  GNUNET_NAMESTORE_zone_iteration_stop (zi);
+
+  GNUNET_SCHEDULER_add_now (&end, NULL);
+}
 
 void zone_proc (void *cls,
                 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
@@ -125,7 +149,8 @@ void zone_proc (void *cls,
                 const struct GNUNET_CRYPTO_RsaSignature *signature)
 {
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Callback for zone `%s'\n", GNUNET_h2s (&zone));
-  endbadly_task = GNUNET_SCHEDULER_add_now (&end, NULL);
+
+  stopiteration_task = GNUNET_SCHEDULER_add_now (&stop_iteration, NULL);
 }
 
 static void