renaming, fixes
authorChristian Grothoff <christian@grothoff.org>
Mon, 4 Apr 2011 17:57:21 +0000 (17:57 +0000)
committerChristian Grothoff <christian@grothoff.org>
Mon, 4 Apr 2011 17:57:21 +0000 (17:57 +0000)
src/datastore/datastore_api.c
src/datastore/gnunet-service-datastore.c
src/datastore/plugin_datastore_sqlite.c
src/include/gnunet_datastore_plugin.h
src/include/gnunet_datastore_service.h
src/include/gnunet_protocols.h

index dde45f24ffeb4caee9918ce3aef8ba6bcc739b36..f6b5cd609c560e37eb384f45b26fb0cb78438202 100644 (file)
@@ -166,7 +166,13 @@ struct GNUNET_DATASTORE_QueueEntry
    * Note that the overall struct should end at a 
    * multiple of 64 bits.
    */
-  int32_t was_transmitted;
+  int was_transmitted;
+  
+  /**
+   * Are we expecting a single message in response to this
+   * request (and, if it is data, no 'END' message)?
+   */
+  int one_shot; 
   
 };
 
@@ -1251,7 +1257,10 @@ process_result_message (void *cls,
          do_disconnect (h);      
          return;
        }
-      GNUNET_DATASTORE_iterate_get_next (h);
+      if (GNUNET_YES == qe->one_shot)
+       free_queue_entry (qe);
+      else
+       GNUNET_DATASTORE_iterate_get_next (h);
       return;
     }
   dm = (const struct DataMessage*) msg;
@@ -1273,6 +1282,8 @@ process_result_message (void *cls,
           ntohl(dm->anonymity),
           GNUNET_TIME_absolute_ntoh(dm->expiration),   
           GNUNET_ntohll(dm->uid));
+  if (GNUNET_YES == qe->one_shot)
+    free_queue_entry (qe);
 }
 
 
@@ -1310,7 +1321,7 @@ GNUNET_DATASTORE_get_for_replication (struct GNUNET_DATASTORE_Handle *h,
 
 #if DEBUG_DATASTORE
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-             "Asked to get random entry in %llu ms\n",
+             "Asked to get replication entry in %llu ms\n",
              (unsigned long long) timeout.rel_value);
 #endif
   qc.rc.iter = iter;
@@ -1322,16 +1333,17 @@ GNUNET_DATASTORE_get_for_replication (struct GNUNET_DATASTORE_Handle *h,
     {
 #if DEBUG_DATASTORE
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                 "Could not create queue entry for GET RANDOM\n");
+                 "Could not create queue entry for GET REPLICATION\n");
 #endif
       return NULL;    
     }
+  qe->one_shot = GNUNET_YES;
   GNUNET_STATISTICS_update (h->stats,
-                           gettext_noop ("# GET RANDOM requests executed"),
+                           gettext_noop ("# GET REPLICATION requests executed"),
                            1,
                            GNUNET_NO);
   m = (struct GNUNET_MessageHeader*) &qe[1];
-  m->type = htons(GNUNET_MESSAGE_TYPE_DATASTORE_GET_RANDOM);
+  m->type = htons(GNUNET_MESSAGE_TYPE_DATASTORE_GET_REPLICATION);
   m->size = htons(sizeof (struct GNUNET_MessageHeader));
   process_queue (h);
   return qe;
@@ -1368,6 +1380,7 @@ GNUNET_DATASTORE_iterate_zero_anonymity (struct GNUNET_DATASTORE_Handle *h,
   struct GetZeroAnonymityMessage *m;
   union QueueContext qc;
 
+  GNUNET_assert (type != GNUNET_BLOCK_TYPE_ANY);
 #if DEBUG_DATASTORE
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "Asked to get zero-anonymity entry in %llu ms\n",
index 1d092a619f4108584acaef97237be0ee796378a7..ba9bc5b9354435a9d2b20e3d3c80dff7536f4101 100644 (file)
@@ -1240,24 +1240,24 @@ handle_update (void *cls,
 
 
 /**
- * Handle GET_RANDOM-message.
+ * Handle GET_REPLICATION-message.
  *
  * @param cls closure
  * @param client identification of the client
  * @param message the actual message
  */
 static void
-handle_get_random (void *cls,
-                  struct GNUNET_SERVER_Client *client,
-                  const struct GNUNET_MessageHeader *message)
+handle_get_replication (void *cls,
+                       struct GNUNET_SERVER_Client *client,
+                       const struct GNUNET_MessageHeader *message)
 {
 #if DEBUG_DATASTORE
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "Processing `%s' request\n",
-             "GET_RANDOM");
+             "GET_REPLICATION");
 #endif
   GNUNET_STATISTICS_update (stats,
-                           gettext_noop ("# GET RANDOM requests received"),
+                           gettext_noop ("# GET REPLICATION requests received"),
                            1,
                            GNUNET_NO);
   GNUNET_SERVER_client_keep (client);
@@ -1282,6 +1282,12 @@ handle_get_zero_anonymity (void *cls,
   enum GNUNET_BLOCK_Type type;
 
   type = (enum GNUNET_BLOCK_Type) ntohl (msg->type);
+  if (type == GNUNET_BLOCK_TYPE_ANY)
+    {
+      GNUNET_break (0);
+      GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+      return;
+    }
 #if DEBUG_DATASTORE
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "Processing `%s' request\n",
@@ -1706,7 +1712,7 @@ run (void *cls,
     {&handle_update, NULL, GNUNET_MESSAGE_TYPE_DATASTORE_UPDATE, 
      sizeof (struct UpdateMessage) }, 
     {&handle_get, NULL, GNUNET_MESSAGE_TYPE_DATASTORE_GET, 0 }, 
-    {&handle_get_random, NULL, GNUNET_MESSAGE_TYPE_DATASTORE_GET_RANDOM
+    {&handle_get_replication, NULL, GNUNET_MESSAGE_TYPE_DATASTORE_GET_REPLICATION
      sizeof(struct GNUNET_MessageHeader) }, 
     {&handle_get_zero_anonymity, NULL, GNUNET_MESSAGE_TYPE_DATASTORE_GET_ZERO_ANONYMITY, 
      sizeof(struct GetZeroAnonymityMessage) }, 
index 501c9f2926a9304ad7af85b2668ab0dfc3e08f01..eca82a6fbe826fa65e7d2d6368467adbbff81d96 100644 (file)
@@ -1028,12 +1028,14 @@ sqlite_plugin_iter_zero_anonymity (void *cls,
   sqlite3_stmt *stmt_2;
   char *q;
 
+  GNUNET_assert (type != GNUNET_BLOCK_TYPE_ANY);
   now = GNUNET_TIME_absolute_get ();
   GNUNET_asprintf (&q, 
                   "SELECT type,prio,anonLevel,expire,hash,value,_ROWID_ FROM gn090 "
-                  "WHERE (prio = ?1 AND expire > %llu AND anonLevel = 0 AND hash < ?2) "
+                  "WHERE (prio = ?1 AND expire > %llu AND anonLevel = 0 AND type=%d AND hash < ?2) "
                   "ORDER BY hash DESC LIMIT 1",
-                  (unsigned long long) now.abs_value);
+                  (unsigned long long) now.abs_value,
+                  type);
   if (sq_prepare (plugin->dbh, q, &stmt_1) != SQLITE_OK)
     {
       LOG_SQLITE (plugin, NULL,
@@ -1046,9 +1048,10 @@ sqlite_plugin_iter_zero_anonymity (void *cls,
   GNUNET_free (q);
   GNUNET_asprintf (&q, 
                   "SELECT type,prio,anonLevel,expire,hash,value,_ROWID_ FROM gn090 "
-                  "WHERE (prio < ?1 AND expire > %llu AND anonLevel = 0) "
+                  "WHERE (prio < ?1 AND expire > %llu AND anonLevel = 0 AND type=%d) "
                   "ORDER BY prio DESC, hash DESC LIMIT 1",
-                  (unsigned long long) now.abs_value);
+                  (unsigned long long) now.abs_value,
+                  type);
   if (sq_prepare (plugin->dbh, q, &stmt_2) != SQLITE_OK)
     {
       LOG_SQLITE (plugin, NULL,
index 8df61b2f412eeb08a90f38a24bac683073d424c9..372ed633cb9433cca693ea9e561fa9085d3d6af0 100644 (file)
@@ -245,7 +245,7 @@ typedef int (*PluginUpdate) (void *cls,
  *
  * @param cls closure
  * @param type entries of which type should be considered?
- *        Use 0 for any type.
+ *        Myst not be zero (ANY).
  * @param iter function to call on each matching value; however,
  *        after the first call to "iter", the plugin must wait
  *        until "NextRequest" was called before giving the iterator
@@ -293,6 +293,16 @@ struct GNUNET_DATASTORE_PluginFunctions
    */
   PluginPut put;
 
+  /**
+   * Update the priority for a particular key in the datastore.  If
+   * the expiration time in value is different than the time found in
+   * the datastore, the higher value should be kept.  For the
+   * anonymity level, the lower value is to be used.  The specified
+   * priority should be added to the existing priority, ignoring the
+   * priority in value.
+   */
+  PluginUpdate update;
+
   /**
    * Function called by iterators whenever they want the next value;
    * note that unlike all of the other callbacks, this one does get a
@@ -307,6 +317,11 @@ struct GNUNET_DATASTORE_PluginFunctions
    */
   PluginGet get;
 
+  /**
+   * Iterate over content with anonymity level zero.
+   */
+  PluginSelector iter_zero_anonymity;
+
   /**
    * Function to get a random item with high replication score from
    * the database, lowering the item's replication score.  Returns a
@@ -322,21 +337,6 @@ struct GNUNET_DATASTORE_PluginFunctions
    */
   PluginRandomGet expiration_get;
 
-  /**
-   * Update the priority for a particular key in the datastore.  If
-   * the expiration time in value is different than the time found in
-   * the datastore, the higher value should be kept.  For the
-   * anonymity level, the lower value is to be used.  The specified
-   * priority should be added to the existing priority, ignoring the
-   * priority in value.
-   */
-  PluginUpdate update;
-
-  /**
-   * Iterate over content with anonymity level zero.
-   */
-  PluginSelector iter_zero_anonymity;
-
   /**
    * Delete the database.  The next operation is
    * guaranteed to be unloading of the module.
index 756d2f3be48f55e50164ba9f05cba11a0f75345b..e18d4ef12b5306854193de35be3552feaadd9300 100644 (file)
@@ -322,7 +322,7 @@ GNUNET_DATASTORE_iterate_key (struct GNUNET_DATASTORE_Handle *h,
  * @param max_queue_size at what queue size should this request be dropped
  *        (if other requests of higher priority are in the queue)
  * @param timeout how long to wait at most for a response
- * @param type allowed type for the operation (ANY for 'all types')
+ * @param type allowed type for the operation (never zero)
  * @param iter function to call on a random value; it
  *        will be called once with a value (if available)
  *        and always once with a value of NULL at the end.
index 327b4de51aae50cf2881319016f0440a66596df4..a485f67124fe0bf9d79c399c13a7857b1f948654 100644 (file)
@@ -452,7 +452,7 @@ extern "C"
 /**
  * Message sent by datastore client to get random data.
  */
-#define GNUNET_MESSAGE_TYPE_DATASTORE_GET_RANDOM 98
+#define GNUNET_MESSAGE_TYPE_DATASTORE_GET_REPLICATION 98
 
 /**
  * Message sent by datastore client to get random data.