-periodic put fix, namestore stub fix
authorMartin Schanzenbach <mschanzenbach@posteo.de>
Sun, 26 Feb 2012 13:45:30 +0000 (13:45 +0000)
committerMartin Schanzenbach <mschanzenbach@posteo.de>
Sun, 26 Feb 2012 13:45:30 +0000 (13:45 +0000)
src/gns/gnunet-service-gns.c
src/gns/namestore_stub_api.c

index 99e092b2660e00a628d05092350408506819c3ea..e4e28c14b94c0a8b604844ce40321fb37c2b6482 100644 (file)
@@ -1072,6 +1072,10 @@ update_zone_dht_next(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   GNUNET_NAMESTORE_zone_iterator_next(namestore_iter);
 }
 
+/* prototype */
+static void
+update_zone_dht_start(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
+
 /**
  * Function used to put all records successively into the DHT.
  * FIXME bug here
@@ -1100,7 +1104,9 @@ put_gns_record(void *cls,
 
   if (NULL == name) //We're done
   {
+    GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Zone iteration finished\n");
     GNUNET_NAMESTORE_zone_iteration_stop (namestore_iter);
+    GNUNET_SCHEDULER_add_now (&update_zone_dht_start, NULL);
     return;
   }
   /**
@@ -1141,8 +1147,18 @@ static void
 update_zone_dht_start(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Update zone!\n");
-  dht_update_interval = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS,
+  if (0 == num_public_records)
+  {
+    dht_update_interval = GNUNET_TIME_relative_multiply(
+                                                      GNUNET_TIME_UNIT_SECONDS,
+                                                      1);
+  }
+  else
+  {
+    dht_update_interval = GNUNET_TIME_relative_multiply(
+                                                      GNUNET_TIME_UNIT_SECONDS,
                                                      (3600/num_public_records));
+  }
   num_public_records = 0; //start counting again
   namestore_iter = GNUNET_NAMESTORE_zone_iteration_start (namestore_handle,
                                                           &zone_hash,
@@ -1221,10 +1237,8 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
    * We have roughly an hour for all records;
    */
   dht_update_interval = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS,
-                                                      60); //FIXME from cfg
-  //GNUNET_SCHEDULER_add_delayed (dht_update_interval,
-  //                              &update_zone_dht_start,
-  //                              NULL);
+                                                      1); //FIXME from cfg
+  GNUNET_SCHEDULER_add_now (&update_zone_dht_start, NULL);
   GNUNET_log(GNUNET_ERROR_TYPE_INFO, "GNS Init done!\n");
 
 }
index e2c9de33e4b1316660a9a6f8d839d5029cd52f05..36db01f8eac53ec83cc09a26456109079f99f58b 100644 (file)
@@ -80,6 +80,7 @@ struct GNUNET_NAMESTORE_ZoneIterator
   uint32_t no_flags;
   uint32_t flags;
   struct GNUNET_NAMESTORE_Handle *h;
+  struct GNUNET_NAMESTORE_SimpleRecord *sr;
 };
 
 struct GNUNET_NAMESTORE_SimpleRecord
@@ -380,6 +381,7 @@ GNUNET_NAMESTORE_zone_iteration_start(struct GNUNET_NAMESTORE_Handle *h,
   h->locked = 1;
   it = GNUNET_malloc(sizeof(struct GNUNET_NAMESTORE_ZoneIterator));
   it->h = h;
+  it->sr = h->records_head;
   it->proc = proc;
   it->proc_cls = proc_cls;
   it->zone = zone;
@@ -392,30 +394,30 @@ GNUNET_NAMESTORE_zone_iteration_start(struct GNUNET_NAMESTORE_Handle *h,
 void
 GNUNET_NAMESTORE_zone_iterator_next(struct GNUNET_NAMESTORE_ZoneIterator *it)
 {
-  struct GNUNET_NAMESTORE_SimpleRecord *sr;
   
   if (it->h->locked == 0)
     return;
+  if (it->sr == NULL)
+  {
+    it->proc(it->proc_cls, NULL, GNUNET_TIME_UNIT_ZERO_ABS,
+             NULL, 0, NULL, NULL);
+    return;
+  }
 
-  sr = it->h->records_head;
-  for (; sr != NULL; sr = sr->next)
+  if (GNUNET_CRYPTO_hash_cmp(it->sr->zone, it->zone))
   {
-    if (GNUNET_CRYPTO_hash_cmp(sr->zone, it->zone))
-    {
-      //Simply always return all records
-      //check flags
-      it->proc(it->proc_cls, sr->zone_key, GNUNET_TIME_UNIT_FOREVER_ABS, //FIXME
-           sr->name, sr->rd_count, sr->rd, NULL);
-    }
+    //Simply always return all records
+    //check flags
+    it->proc(it->proc_cls, it->sr->zone_key, GNUNET_TIME_UNIT_FOREVER_ABS,
+         it->sr->name, it->sr->rd_count, it->sr->rd, NULL);
   }
-  it->proc(it->proc_cls, NULL, GNUNET_TIME_UNIT_ZERO_ABS, NULL, 0, NULL, NULL);
+  it->sr = it->sr->next;
 }
 
 void
 GNUNET_NAMESTORE_zone_iteration_stop(struct GNUNET_NAMESTORE_ZoneIterator *it)
 {
-  it->h->locked = 0;
-  GNUNET_free(it);
+  //it->h->locked = 0;
 }
 
 /**