use size_t
authorChristian Grothoff <christian@grothoff.org>
Wed, 6 Oct 2010 11:44:29 +0000 (11:44 +0000)
committerChristian Grothoff <christian@grothoff.org>
Wed, 6 Oct 2010 11:44:29 +0000 (11:44 +0000)
15 files changed:
src/datacache/datacache.c
src/datacache/perf_datacache.c
src/datacache/plugin_datacache.h
src/datacache/plugin_datacache_mysql.c
src/datacache/plugin_datacache_postgres.c
src/datacache/plugin_datacache_sqlite.c
src/datacache/plugin_datacache_template.c
src/datacache/test_datacache.c
src/datastore/datastore_api.c
src/datastore/perf_datastore_api.c
src/datastore/test_datastore_api.c
src/datastore/test_datastore_api_management.c
src/dht/gnunet-service-dht.c
src/include/gnunet_datacache_lib.h
src/include/gnunet_datastore_service.h

index 9c1a90bca2d0d262fe7d7b4479278a2d04ae0b90..d2aa2616a826f3ad0645dd67d4248387e1d8ab99 100644 (file)
@@ -100,7 +100,7 @@ struct GNUNET_DATACACHE_Handle
 static void 
 env_delete_notify (void *cls,
                   const GNUNET_HashCode *key,
-                  uint32_t size)
+                  size_t size)
 {
   struct GNUNET_DATACACHE_Handle * h = cls;
   GNUNET_assert (h->utilization >= size);
@@ -237,7 +237,7 @@ void GNUNET_DATACACHE_destroy (struct GNUNET_DATACACHE_Handle *h)
 int 
 GNUNET_DATACACHE_put (struct GNUNET_DATACACHE_Handle *h,
                      const GNUNET_HashCode * key,
-                     uint32_t size,
+                     size_t size,
                      const char *data,
                      enum GNUNET_BLOCK_Type type,
                      struct GNUNET_TIME_Absolute discard_time)
index 10efa5eee99db89ffe4c000fb1663b7c5945e97c..0231992314ff3598733ab5086ca681dbc1a64586 100644 (file)
@@ -46,7 +46,7 @@ static int
 checkIt (void *cls,
         struct GNUNET_TIME_Absolute exp,
         const GNUNET_HashCode * key,
-         uint32_t size, 
+         size_t size, 
         const char *data, 
         enum GNUNET_BLOCK_Type type)
 {
index c7360834b8628f00642a487a4f111f09cc94a2a8..bf35b2619c5ac282b196a79591c105b8f0ad212c 100644 (file)
@@ -47,7 +47,7 @@ extern "C"
  */
 typedef void (*GNUNET_DATACACHE_DeleteNotifyCallback)(void *cls,
                                                      const GNUNET_HashCode *key,
-                                                     uint32_t size);
+                                                     size_t size);
 
 
 /**
@@ -112,12 +112,12 @@ struct GNUNET_DATACACHE_PluginFunctions {
    * @param discard_time when to discard the value in any case
    * @return 0 on error, number of bytes used otherwise
    */
-  uint32_t (*put) (void *cls,
-                  const GNUNET_HashCode * key,
-                  uint32_t size,
-                  const char *data,
-                  enum GNUNET_BLOCK_Type type,
-                  struct GNUNET_TIME_Absolute discard_time);
+  size_t (*put) (void *cls,
+                const GNUNET_HashCode * key,
+                size_t size,
+                const char *data,
+                enum GNUNET_BLOCK_Type type,
+                struct GNUNET_TIME_Absolute discard_time);
 
 
   /**
index a85e9f48023404c9107df14f1d5a92cbbddeab21..8241fb5f85af2d9ae1bccd02e0356c3b2bed71a9 100644 (file)
@@ -721,10 +721,10 @@ itable (struct Plugin *plugin)
  * @param discard_time when to discard the value in any case
  * @return 0 on error, number of bytes used otherwise
  */
-static uint32_t 
+static size_t 
 mysql_plugin_put (void *cls,
                  const GNUNET_HashCode * key,
-                 uint32_t size,
+                 size_t size,
                  const char *data,
                  enum GNUNET_BLOCK_Type type,
                  struct GNUNET_TIME_Absolute discard_time)
index fcd9e516138571c8faa6aa4e04a0ff6fc2ddc07d..c9d6deaaa565149fb0d530b352bbe5fd6aa0da33 100644 (file)
@@ -301,10 +301,10 @@ delete_by_rowid (struct Plugin *plugin,
  * @param discard_time when to discard the value in any case
  * @return 0 on error, number of bytes used otherwise
  */
-static uint32_t 
+static size_t 
 postgres_plugin_put (void *cls,
                     const GNUNET_HashCode * key,
-                    uint32_t size,
+                    size_t size,
                     const char *data,
                     enum GNUNET_BLOCK_Type type,
                     struct GNUNET_TIME_Absolute discard_time)
index 8c144baa2c6b651f5bae70d9afa5b69783db4887..5c304bd8ade6ab0a634b6845a4a1f9799f1c9d06 100644 (file)
@@ -94,10 +94,10 @@ sq_prepare (sqlite3 * dbh, const char *zSql,    /* SQL statement, UTF-8 encoded
  * @param discard_time when to discard the value in any case
  * @return 0 on error, number of bytes used otherwise
  */
-static uint32_t 
+static size_t 
 sqlite_plugin_put (void *cls,
                   const GNUNET_HashCode * key,
-                  uint32_t size,
+                  size_t size,
                   const char *data,
                   enum GNUNET_BLOCK_Type type,
                   struct GNUNET_TIME_Absolute discard_time)
index 4ebf72661c76e439eeb43c7c72475a49f6a046f9..25e4c9a4234986a3392f506dde8a8c244a92b1dc 100644 (file)
@@ -51,10 +51,10 @@ struct Plugin
  * @param discard_time when to discard the value in any case
  * @return 0 on error, number of bytes used otherwise
  */
-static uint32_t 
+static size_t 
 template_plugin_put (void *cls,
                     const GNUNET_HashCode * key,
-                    uint32_t size,
+                    size_t size,
                     const char *data,
                     enum GNUNET_BLOCK_Type type,
                     struct GNUNET_TIME_Absolute discard_time)
index 0c9399affabb1e29cd8a36c0b5509fc0d4979e08..da7894d6b601ac94216167dbc9d06e57854a7dd0 100644 (file)
@@ -42,7 +42,7 @@ static int
 checkIt (void *cls,
         struct GNUNET_TIME_Absolute exp,
         const GNUNET_HashCode * key,
-         uint32_t size, 
+         size_t size, 
         const char *data, 
         enum GNUNET_BLOCK_Type type)
 {
index 5bb4160c28003b60ef8e38b13591f38f4f4a3757..18aa0bcdc0f3360d017a60a72053a9e0eeb0ef4f 100644 (file)
@@ -765,7 +765,7 @@ struct GNUNET_DATASTORE_QueueEntry *
 GNUNET_DATASTORE_put (struct GNUNET_DATASTORE_Handle *h,
                      int rid,
                       const GNUNET_HashCode * key,
-                      uint32_t size,
+                      size_t size,
                       const void *data,
                       enum GNUNET_BLOCK_Type type,
                       uint32_t priority,
@@ -801,7 +801,7 @@ GNUNET_DATASTORE_put (struct GNUNET_DATASTORE_Handle *h,
   dm->header.type = htons(GNUNET_MESSAGE_TYPE_DATASTORE_PUT);
   dm->header.size = htons(msize);
   dm->rid = htonl(rid);
-  dm->size = htonl(size);
+  dm->size = htonl( (uint32_t) size);
   dm->type = htonl(type);
   dm->priority = htonl(priority);
   dm->anonymity = htonl(anonymity);
@@ -1012,7 +1012,7 @@ GNUNET_DATASTORE_update (struct GNUNET_DATASTORE_Handle *h,
 struct GNUNET_DATASTORE_QueueEntry *
 GNUNET_DATASTORE_remove (struct GNUNET_DATASTORE_Handle *h,
                          const GNUNET_HashCode *key,
-                         uint32_t size, 
+                         size_t size, 
                         const void *data,
                         unsigned int queue_priority,
                         unsigned int max_queue_size,
index 741878309cd7b9df2998d2f97626f42ec0e9fb71..3cb730bcba90a53d3151ae77166f436bd70a2c24 100644 (file)
@@ -101,7 +101,7 @@ struct CpsRunContext
   int i;
 
   GNUNET_HashCode key;
-  uint32_t esize;
+  size_t esize;
   char data[65536];
 };
 
@@ -197,7 +197,7 @@ do_delete (void *cls,
 static void 
 delete_value (void *cls,
              const GNUNET_HashCode * key,
-             uint32_t size,
+             size_t size,
              const void *data,
              enum GNUNET_BLOCK_Type type,
              uint32_t priority,
index 0ea3c4c86cee653ca365e26cb903ca1420fed52c..10a195cfb10eae5ef5efbeb7c3d70c7bce3a673c 100644 (file)
@@ -183,7 +183,7 @@ get_reserved (void *cls,
 static void 
 check_value (void *cls,
             const GNUNET_HashCode * key,
-            uint32_t size,
+            size_t size,
             const void *data,
             enum GNUNET_BLOCK_Type type,
             uint32_t priority,
@@ -221,7 +221,7 @@ check_value (void *cls,
 static void 
 delete_value (void *cls,
              const GNUNET_HashCode * key,
-             uint32_t size,
+             size_t size,
              const void *data,
              enum GNUNET_BLOCK_Type type,
              uint32_t priority,
@@ -261,7 +261,7 @@ delete_value (void *cls,
 static void 
 check_nothing (void *cls,
               const GNUNET_HashCode * key,
-              uint32_t size,
+              size_t size,
               const void *data,
               enum GNUNET_BLOCK_Type type,
               uint32_t priority,
@@ -285,7 +285,7 @@ check_nothing (void *cls,
 static void 
 check_multiple (void *cls,
                const GNUNET_HashCode * key,
-               uint32_t size,
+               size_t size,
                const void *data,
                enum GNUNET_BLOCK_Type type,
                uint32_t priority,
@@ -343,7 +343,7 @@ check_multiple (void *cls,
 static void 
 check_update (void *cls,
              const GNUNET_HashCode * key,
-             uint32_t size,
+             size_t size,
              const void *data,
              enum GNUNET_BLOCK_Type type,
              uint32_t priority,
index 3de1544f3277e6cb43400d2a2c02ba08e52fa60f..8e49409b6e2d8dff65fd7604fd7859fbd45c833d 100644 (file)
@@ -143,7 +143,7 @@ check_success (void *cls,
 static void 
 check_value (void *cls,
             const GNUNET_HashCode * key,
-            uint32_t size,
+            size_t size,
             const void *data,
             enum GNUNET_BLOCK_Type type,
             uint32_t priority,
@@ -191,7 +191,7 @@ check_value (void *cls,
 static void 
 check_nothing (void *cls,
               const GNUNET_HashCode * key,
-              uint32_t size,
+              size_t size,
               const void *data,
               enum GNUNET_BLOCK_Type type,
               uint32_t priority,
index 5cc3bcfbfe54af89f8da77faeccba4d6256f2b8d..5c49114ae500d8dade7e0171c5fc90b7bd2f4609 100644 (file)
@@ -2140,7 +2140,7 @@ static int
 datacache_get_iterator (void *cls,
                         struct GNUNET_TIME_Absolute exp,
                         const GNUNET_HashCode * key,
-                        uint32_t size, const char *data, 
+                        size_t size, const char *data, 
                        enum GNUNET_BLOCK_Type type)
 {
   struct DHT_MessageContext *msg_ctx = cls;
@@ -2584,24 +2584,50 @@ handle_dht_put (void *cls,
                const struct GNUNET_MessageHeader *msg,
                 struct DHT_MessageContext *message_context)
 {
-  struct GNUNET_DHT_PutMessage *put_msg;
+  const struct GNUNET_DHT_PutMessage *put_msg;
   enum GNUNET_BLOCK_Type put_type;
   size_t data_size;
   int ret;
   struct RepublishContext *put_context;
+  GNUNET_HashCode key;
 
   GNUNET_assert (ntohs (msg->size) >=
                  sizeof (struct GNUNET_DHT_PutMessage));
 
 
-  put_msg = (struct GNUNET_DHT_PutMessage *)msg;
+  put_msg = (const struct GNUNET_DHT_PutMessage *)msg;
   put_type = (enum GNUNET_BLOCK_Type) ntohl (put_msg->type);
 
   if (put_type == GNUNET_BLOCK_DHT_MALICIOUS_MESSAGE_TYPE)
     return;
-
   data_size = ntohs (put_msg->header.size) - sizeof (struct GNUNET_DHT_PutMessage);
-
+  ret = GNUNET_BLOCK_get_key (block_context,
+                             put_type,
+                             &put_msg[1],
+                             data_size,
+                             &key);
+  if (GNUNET_NO == ret)
+    {
+      /* invalid reply */
+      GNUNET_break_op (0);
+      return;
+    }
+  if ( (GNUNET_YES == ret) &&
+       (0 != memcmp (&key,
+                    &message_context->key,
+                    sizeof (GNUNET_HashCode))) )
+    {
+      /* invalid wrapper: key mismatch! */
+      GNUNET_break_op (0);
+      return;
+    }
+  /* ret == GNUNET_SYSERR means that there is no known relationship between
+     data and the key, so we cannot check it */
+#if DEBUG_DHT
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "`%s:%s': Received `%s' request (inserting data!), message type %d, key %s, uid %llu\n",
+              my_short_id, "DHT", "PUT", put_type, GNUNET_h2s (&message_context->key), message_context->unique_id);
+#endif
 #if DEBUG_DHT_ROUTING
   if (message_context->hop_count == 0) /* Locally initiated request */
     {
@@ -3655,7 +3681,7 @@ static int
 republish_content_iterator (void *cls,
                             struct GNUNET_TIME_Absolute exp,
                             const GNUNET_HashCode * key,
-                            uint32_t size, const char *data, uint32_t type)
+                            size_t size, const char *data, uint32_t type)
 {
 
   struct DHT_MessageContext *new_msg_ctx;
index efce55af4055782054f5921af76902595044ae41..74878f08b2f4a9e1abf1f48546641d68850c2178 100644 (file)
@@ -85,7 +85,7 @@ void GNUNET_DATACACHE_destroy (struct GNUNET_DATACACHE_Handle *h);
 typedef int (*GNUNET_DATACACHE_Iterator) (void *cls,
                                          struct GNUNET_TIME_Absolute exp,
                                          const GNUNET_HashCode * key,
-                                         uint32_t size, /* FIXME: use size_t? */
+                                         size_t size, 
                                          const char *data,
                                          enum GNUNET_BLOCK_Type type);
 
@@ -104,7 +104,7 @@ typedef int (*GNUNET_DATACACHE_Iterator) (void *cls,
 int 
 GNUNET_DATACACHE_put (struct GNUNET_DATACACHE_Handle *h,
                      const GNUNET_HashCode * key,
-                     uint32_t size,
+                     size_t size,
                      const char *data,
                      enum GNUNET_BLOCK_Type type,
                      struct GNUNET_TIME_Absolute discard_time);
index 55ee111a96bd383773308f8ec5b37c9264b0d2d1..c41d21058d4f8a67c5079f30c9d9eebc0ef685cd 100644 (file)
@@ -153,7 +153,7 @@ struct GNUNET_DATASTORE_QueueEntry *
 GNUNET_DATASTORE_put (struct GNUNET_DATASTORE_Handle *h,
                      int rid,
                       const GNUNET_HashCode * key,
-                      uint32_t size,
+                      size_t size,
                       const void *data,
                       enum GNUNET_BLOCK_Type type,
                       uint32_t priority,
@@ -250,7 +250,7 @@ GNUNET_DATASTORE_update (struct GNUNET_DATASTORE_Handle *h,
 struct GNUNET_DATASTORE_QueueEntry *
 GNUNET_DATASTORE_remove (struct GNUNET_DATASTORE_Handle *h,
                          const GNUNET_HashCode *key,
-                         uint32_t size, 
+                         size_t size, 
                         const void *data,
                         unsigned int queue_priority,
                         unsigned int max_queue_size,
@@ -275,7 +275,7 @@ GNUNET_DATASTORE_remove (struct GNUNET_DATASTORE_Handle *h,
  */
 typedef void (*GNUNET_DATASTORE_Iterator) (void *cls,
                                           const GNUNET_HashCode * key,
-                                          uint32_t size,
+                                          size_t size,
                                           const void *data,
                                           enum GNUNET_BLOCK_Type type,
                                           uint32_t priority,
@@ -353,6 +353,7 @@ GNUNET_DATASTORE_get_random (struct GNUNET_DATASTORE_Handle *h,
                              GNUNET_DATASTORE_Iterator iter, 
                             void *iter_cls);
 
+
 /**
  * Cancel a datastore operation.  The final callback from the
  * operation must not have been done yet.