pass repl
authorChristian Grothoff <christian@grothoff.org>
Wed, 27 Apr 2011 19:04:31 +0000 (19:04 +0000)
committerChristian Grothoff <christian@grothoff.org>
Wed, 27 Apr 2011 19:04:31 +0000 (19:04 +0000)
src/datastore/datastore.h
src/datastore/datastore_api.c
src/datastore/gnunet-service-datastore.c
src/datastore/plugin_datastore_sqlite.c

index d66ec0e957e18ac889b2797349eef417f3aebd1a..70acffc9956eaed77f200da6b4502d202e8f312a 100644 (file)
@@ -219,6 +219,16 @@ struct DataMessage
    */
   uint32_t anonymity GNUNET_PACKED;
 
+  /**
+   * Desired replication level. 0 from service to API.
+   */
+  uint32_t replication GNUNET_PACKED;
+
+  /**
+   * For alignment.
+   */
+  uint32_t reserved GNUNET_PACKED;
+
   /**
    * Unique ID for the content (can be used for UPDATE);
    * can be zero for remove (which indicates that
index 99060bd6057d418759e5c7aca8b91ac16a646562..7818ed05cea86f06a1ca199c0260710558403d70 100644 (file)
@@ -854,9 +854,10 @@ GNUNET_DATASTORE_put (struct GNUNET_DATASTORE_Handle *h,
 
 #if DEBUG_DATASTORE
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-             "Asked to put %u bytes of data under key `%s'\n",
+             "Asked to put %u bytes of data under key `%s' for %llu ms\n",
              size,
-             GNUNET_h2s (key));
+             GNUNET_h2s (key),
+             GNUNET_TIME_absolute_get_remaining (expiration).rel_value);
 #endif
   msize = sizeof(struct DataMessage) + size;
   GNUNET_assert (msize < GNUNET_SERVER_MAX_MESSAGE_SIZE);
@@ -885,6 +886,8 @@ GNUNET_DATASTORE_put (struct GNUNET_DATASTORE_Handle *h,
   dm->type = htonl(type);
   dm->priority = htonl(priority);
   dm->anonymity = htonl(anonymity);
+  dm->replication = htonl (replication);
+  dm->reserved = htonl (0);
   dm->uid = GNUNET_htonll(0);
   dm->expiration = GNUNET_TIME_absolute_hton(expiration);
   dm->key = *key;
index deab62dd01221ea333fd7957be270e406e1bdbde..a0d5f7babe649745b73338ab74eea9a57dbd7f49 100644 (file)
@@ -646,16 +646,20 @@ transmit_item (void *cls,
   dm->type = htonl(type);
   dm->priority = htonl(priority);
   dm->anonymity = htonl(anonymity);
+  dm->replication = htonl (0);
+  dm->reserved = htonl (0);
   dm->expiration = GNUNET_TIME_absolute_hton(expiration);
   dm->uid = GNUNET_htonll(uid);
   dm->key = *key;
   memcpy (&dm[1], data, size);
 #if DEBUG_DATASTORE
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-             "Transmitting `%s' message for `%s' of type %u\n",
+             "Transmitting `%s' message for `%s' of type %u with expiration %llu (now: %llu)\n",
              "DATA",
              GNUNET_h2s (key),
-             type);
+             type,
+             (unsigned long long) expiration.abs_value,
+             (unsigned long long) GNUNET_TIME_absolute_get ().abs_value);
 #endif
   GNUNET_STATISTICS_update (stats,
                            gettext_noop ("# results found"),
@@ -870,7 +874,7 @@ execute_put (struct GNUNET_SERVER_Client *client,
                          ntohl(dm->type),
                          ntohl(dm->priority),
                          ntohl(dm->anonymity),
-                         0 /* FIXME: replication */,
+                         ntohl(dm->replication),
                          GNUNET_TIME_absolute_ntoh(dm->expiration),
                          &msg);
   if (GNUNET_OK == ret)
@@ -956,6 +960,15 @@ check_present (void *cls,
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                  "Result already present in datastore\n");
 #endif
+      /* FIXME: change API to allow increasing 'replication' counter */
+      if ( (ntohl (dm->priority) > 0) ||
+          (GNUNET_TIME_absolute_ntoh(dm->expiration).abs_value >
+           expiration.abs_value) )
+       plugin->api->update (plugin->api->cls,
+                            uid,
+                            (int32_t) ntohl(dm->priority),
+                            GNUNET_TIME_absolute_ntoh(dm->expiration),
+                            NULL);
       transmit_status (pc->client, GNUNET_NO, NULL);
       GNUNET_SERVER_client_drop (pc->client);
       GNUNET_free (pc);
index 3710b7eb7d0cc55d391486fb8728eace1a3fd617..f58c5bd281e7ebc283248bc0640d675fd3fa31a0 100644 (file)
@@ -31,7 +31,7 @@
 /**
  * Enable or disable logging debug messages.
  */
-#define DEBUG_SQLITE GNUNET_NO
+#define DEBUG_SQLITE GNUNET_YES
 
 /**
  * We allocate items on the stack at times.  To prevent a stack
@@ -475,7 +475,7 @@ sqlite_plugin_put (void *cls,
 #if DEBUG_SQLITE
   GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
                   "sqlite",
-                  "Storing in database block with type %u/key `%s'/priority %u/expiration %llu (%lld).\n",
+                  "Storing in database block with type %u/key `%s'/priority %u/expiration in %llu ms (%lld).\n",
                   type, 
                   GNUNET_h2s(key),
                   priority,
@@ -650,6 +650,12 @@ execute_get (struct Plugin *plugin,
          break;
        }
       expiration.abs_value = sqlite3_column_int64 (stmt, 3);
+#if DEBUG_SQLITE
+      GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 
+                      "sqlite",
+                      "Found reply in database with expiration %llu\n",
+                      (unsigned long long) expiration.abs_value);
+#endif
       ret = proc (proc_cls,
                  sqlite3_column_blob (stmt, 4) /* key */,
                  size,
@@ -1175,7 +1181,7 @@ libgnunet_plugin_datastore_sqlite_done (void *cls)
 #if DEBUG_SQLITE
   GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
                   "sqlite",
-                  "sqlite plugin is finished doneing\n");
+                  "sqlite plugin is finished\n");
 #endif
   return NULL;
 }