- not required anymore
[oweals/gnunet.git] / src / namestore / gnunet-service-namestore.c
index 59059d84ee5f27fbbf7c7897a9182a440f93441d..67c7e6e57d0847f273b5a76531214072ee87ccc6 100644 (file)
@@ -43,11 +43,15 @@ struct GNUNET_NAMESTORE_ZoneIteration
 
   struct GNUNET_NAMESTORE_Client * client;
 
+  int has_zone;
+
   GNUNET_HashCode zone;
 
   uint64_t request_id;
   uint32_t offset;
 
+
+
 };
 
 
@@ -166,6 +170,7 @@ client_disconnect_notification (void *cls, struct GNUNET_SERVER_Client *client)
     GNUNET_free (no);
   }
 
+
   GNUNET_SERVER_client_drop(nc->client);
   GNUNET_CONTAINER_DLL_remove (client_head, client_tail, nc);
   GNUNET_free (nc);
@@ -539,6 +544,7 @@ handle_create_record_it (void *cls,
   struct CreateRecordContext * crc = cls;
   struct GNUNET_CRYPTO_RsaSignature *signature_new = NULL;
   struct GNUNET_NAMESTORE_RecordData *rd_new = NULL;
+  struct GNUNET_TIME_Absolute block_expiration;
   int res;
   int exist = GNUNET_SYSERR;
   int update = GNUNET_NO;
@@ -605,11 +611,16 @@ handle_create_record_it (void *cls,
     }
   }
 
+  block_expiration = GNUNET_TIME_absolute_max(crc->expire, expire);
+  if (block_expiration.abs_value != expire.abs_value)
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Updated block expiration time\n");
+
+
   /* Database operation */
   GNUNET_assert ((rd_new != NULL) && (rd_count_new > 0));
   res = GSN_database->put_records(GSN_database->cls,
                                 (const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *) crc->pubkey,
-                                crc->expire,
+                                block_expiration,
                                 crc->name,
                                 rd_count_new, rd_new,
                                 signature_new);
@@ -725,6 +736,7 @@ static void handle_record_create (void *cls,
   }
 
   struct GNUNET_NAMESTORE_RecordData rd[rd_count];
+
   res = GNUNET_NAMESTORE_records_deserialize(rd_ser_len, rd_ser, rd_count, rd);
   if ((res != GNUNET_OK) || (rd_count != 1))
   {
@@ -738,6 +750,8 @@ static void handle_record_create (void *cls,
   GNUNET_CRYPTO_rsa_key_get_public(pkey, &pub);
   GNUNET_CRYPTO_hash (&pub, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &pubkey_hash);
 
+  crc.expire = GNUNET_TIME_absolute_ntoh(rp_msg->expire);
+  crc.res = GNUNET_SYSERR;
   crc.pkey = pkey;
   crc.pubkey = &pub;
   crc.rd = rd;
@@ -1174,7 +1188,11 @@ void zone_iteration_proc (void *cls,
   if ((zone_key == NULL) && (name == NULL))
   {
     struct ZoneIterationResponseMessage zir_msg;
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No more results for zone `%s'\n", GNUNET_h2s(&zi->zone));
+    if (zi->has_zone == GNUNET_YES)
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No more results for zone `%s'\n", GNUNET_h2s(&zi->zone));
+    else
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No more results for all zones\n");
+
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending empty `%s' message\n", "ZONE_ITERATION_RESPONSE");
     zir_msg.gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_RESPONSE);
     zir_msg.gns_header.header.size = htons (sizeof (struct ZoneIterationResponseMessage));
@@ -1196,7 +1214,13 @@ void zone_iteration_proc (void *cls,
   else
   {
     struct ZoneIterationResponseMessage *zir_msg;
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending name `%s' for iterating zone `%s'\n", name, GNUNET_h2s(&zi->zone));
+    if (zi->has_zone == GNUNET_YES)
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending name `%s' for iteration over zone `%s'\n",
+          name, GNUNET_h2s(&zi->zone));
+    if (zi->has_zone == GNUNET_NO)
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending name `%s' for iteration over all zones\n",
+          name);
+
     size_t name_len;
     size_t rd_ser_len;
     size_t msg_size;
@@ -1263,17 +1287,18 @@ static void handle_iteration_start (void *cls,
   if (0 == memcmp (&dummy, &zis_msg->zone, sizeof (dummy)))
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting to iterate over all zones\n");
+    zi->has_zone = GNUNET_NO;
     zone_tmp = NULL;
   }
   else
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting to iterate over zone  `%s'\n", GNUNET_h2s (&zis_msg->zone));
+    zi->has_zone = GNUNET_YES;
     zone_tmp = &zis_msg->zone;
   }
 
   GNUNET_CONTAINER_DLL_insert (nc->op_head, nc->op_tail, zi);
 
-
   res = GSN_database->iterate_records (GSN_database->cls, zone_tmp , NULL, zi->offset , &zone_iteration_proc, zi);
   GNUNET_SERVER_receive_done (client, GNUNET_OK);
 }
@@ -1311,7 +1336,10 @@ static void handle_iteration_stop (void *cls,
   }
 
   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));
+  if (GNUNET_YES == zi->has_zone)
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopped zone iteration for zone `%s'\n", GNUNET_h2s (&zi->zone));
+  else
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopped zone iteration all zones\n");
   GNUNET_free (zi);
 
   GNUNET_SERVER_receive_done (client, GNUNET_OK);
@@ -1325,6 +1353,7 @@ static void handle_iteration_next (void *cls,
 
   struct GNUNET_NAMESTORE_Client *nc;
   struct GNUNET_NAMESTORE_ZoneIteration *zi;
+  GNUNET_HashCode *zone_tmp;
   struct ZoneIterationStopMessage * zis_msg = (struct ZoneIterationStopMessage *) message;
   uint32_t rid;
 
@@ -1348,9 +1377,14 @@ static void handle_iteration_next (void *cls,
     GNUNET_SERVER_receive_done (client, GNUNET_OK);
     return;
   }
-  zi->offset++;
 
-  GSN_database->iterate_records (GSN_database->cls, &zi->zone, NULL, zi->offset , &zone_iteration_proc, zi);
+  if (GNUNET_YES == zi->has_zone)
+    zone_tmp = &zi->zone;
+  else
+    zone_tmp = NULL;
+
+  zi->offset++;
+  GSN_database->iterate_records (GSN_database->cls, zone_tmp, NULL, zi->offset , &zone_iteration_proc, zi);
   GNUNET_SERVER_receive_done (client, GNUNET_OK);
 }