From b8da6057b2c0c66931ccde9b4bba418fc5222724 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Wed, 6 Oct 2010 11:44:29 +0000 Subject: use size_t --- src/datacache/datacache.c | 4 +-- src/datacache/perf_datacache.c | 2 +- src/datacache/plugin_datacache.h | 14 +++++----- src/datacache/plugin_datacache_mysql.c | 4 +-- src/datacache/plugin_datacache_postgres.c | 4 +-- src/datacache/plugin_datacache_sqlite.c | 4 +-- src/datacache/plugin_datacache_template.c | 4 +-- src/datacache/test_datacache.c | 2 +- src/datastore/datastore_api.c | 6 ++--- src/datastore/perf_datastore_api.c | 4 +-- src/datastore/test_datastore_api.c | 10 +++---- src/datastore/test_datastore_api_management.c | 4 +-- src/dht/gnunet-service-dht.c | 38 ++++++++++++++++++++++----- src/include/gnunet_datacache_lib.h | 4 +-- src/include/gnunet_datastore_service.h | 7 ++--- 15 files changed, 69 insertions(+), 42 deletions(-) diff --git a/src/datacache/datacache.c b/src/datacache/datacache.c index 9c1a90bca..d2aa2616a 100644 --- a/src/datacache/datacache.c +++ b/src/datacache/datacache.c @@ -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) diff --git a/src/datacache/perf_datacache.c b/src/datacache/perf_datacache.c index 10efa5eee..023199231 100644 --- a/src/datacache/perf_datacache.c +++ b/src/datacache/perf_datacache.c @@ -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) { diff --git a/src/datacache/plugin_datacache.h b/src/datacache/plugin_datacache.h index c7360834b..bf35b2619 100644 --- a/src/datacache/plugin_datacache.h +++ b/src/datacache/plugin_datacache.h @@ -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); /** diff --git a/src/datacache/plugin_datacache_mysql.c b/src/datacache/plugin_datacache_mysql.c index a85e9f480..8241fb5f8 100644 --- a/src/datacache/plugin_datacache_mysql.c +++ b/src/datacache/plugin_datacache_mysql.c @@ -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) diff --git a/src/datacache/plugin_datacache_postgres.c b/src/datacache/plugin_datacache_postgres.c index fcd9e5161..c9d6deaaa 100644 --- a/src/datacache/plugin_datacache_postgres.c +++ b/src/datacache/plugin_datacache_postgres.c @@ -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) diff --git a/src/datacache/plugin_datacache_sqlite.c b/src/datacache/plugin_datacache_sqlite.c index 8c144baa2..5c304bd8a 100644 --- a/src/datacache/plugin_datacache_sqlite.c +++ b/src/datacache/plugin_datacache_sqlite.c @@ -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) diff --git a/src/datacache/plugin_datacache_template.c b/src/datacache/plugin_datacache_template.c index 4ebf72661..25e4c9a42 100644 --- a/src/datacache/plugin_datacache_template.c +++ b/src/datacache/plugin_datacache_template.c @@ -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) diff --git a/src/datacache/test_datacache.c b/src/datacache/test_datacache.c index 0c9399aff..da7894d6b 100644 --- a/src/datacache/test_datacache.c +++ b/src/datacache/test_datacache.c @@ -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) { diff --git a/src/datastore/datastore_api.c b/src/datastore/datastore_api.c index 5bb4160c2..18aa0bcdc 100644 --- a/src/datastore/datastore_api.c +++ b/src/datastore/datastore_api.c @@ -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, diff --git a/src/datastore/perf_datastore_api.c b/src/datastore/perf_datastore_api.c index 741878309..3cb730bcb 100644 --- a/src/datastore/perf_datastore_api.c +++ b/src/datastore/perf_datastore_api.c @@ -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, diff --git a/src/datastore/test_datastore_api.c b/src/datastore/test_datastore_api.c index 0ea3c4c86..10a195cfb 100644 --- a/src/datastore/test_datastore_api.c +++ b/src/datastore/test_datastore_api.c @@ -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, diff --git a/src/datastore/test_datastore_api_management.c b/src/datastore/test_datastore_api_management.c index 3de1544f3..8e49409b6 100644 --- a/src/datastore/test_datastore_api_management.c +++ b/src/datastore/test_datastore_api_management.c @@ -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, diff --git a/src/dht/gnunet-service-dht.c b/src/dht/gnunet-service-dht.c index 5cc3bcfbf..5c49114ae 100644 --- a/src/dht/gnunet-service-dht.c +++ b/src/dht/gnunet-service-dht.c @@ -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; diff --git a/src/include/gnunet_datacache_lib.h b/src/include/gnunet_datacache_lib.h index efce55af4..74878f08b 100644 --- a/src/include/gnunet_datacache_lib.h +++ b/src/include/gnunet_datacache_lib.h @@ -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); diff --git a/src/include/gnunet_datastore_service.h b/src/include/gnunet_datastore_service.h index 55ee111a9..c41d21058 100644 --- a/src/include/gnunet_datastore_service.h +++ b/src/include/gnunet_datastore_service.h @@ -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. -- cgit v1.2.3