Author: grothoff Date: 2008-02-22 08:24:15 -0700 (Fri, 22 Feb 2008) New Revision: 6413
Modified: GNUnet/src/applications/datastore/datastore.c GNUnet/src/applications/rpc/rpc.c GNUnet/src/applications/sqstore_mysql/mysql.c GNUnet/src/include/gnunet_datastore_service.h Log: fixes Modified: GNUnet/src/applications/datastore/datastore.c =================================================================== --- GNUnet/src/applications/datastore/datastore.c 2008-02-22 07:52:41 UTC (rev 6412) +++ GNUnet/src/applications/datastore/datastore.c 2008-02-22 15:24:15 UTC (rev 6413) @@ -67,6 +67,8 @@ static struct GNUNET_CronManager *cron; +static struct GNUNET_Mutex *lock; + static GNUNET_Stats_ServiceAPI *stats; static int stat_filtered; @@ -197,56 +199,6 @@ return ret; } -/** - * Store an item in the datastore. If the item is - * already present, a second copy is created. - * - * @return GNUNET_YES on success, GNUNET_NO if the datastore is - * full and the priority of the item is not high enough - * to justify removing something else, GNUNET_SYSERR on - * other serious error (i.e. IO permission denied) - */ -static int -put (const GNUNET_HashCode * key, const GNUNET_DatastoreValue * value) -{ - int ok; - GNUNET_DatastoreValue *nvalue; - - /* check if we have enough space / priority */ - if (GNUNET_ntohll (value->expirationTime) < GNUNET_get_time ()) - { - GNUNET_GE_LOG (coreAPI->ectx, - GNUNET_GE_INFO | GNUNET_GE_REQUEST | GNUNET_GE_USER, - "Received content for put already expired!\n"); - return GNUNET_NO; - } - if ((available < ntohl (value->size)) && - (minPriority > ntohl (value->prio) + comp_priority ())) - { - GNUNET_GE_LOG (coreAPI->ectx, - GNUNET_GE_INFO | GNUNET_GE_REQUEST | GNUNET_GE_USER, - "Datastore full (%llu/%llu) and content priority too low to kick out other content. Refusing put.\n", - sq->getSize (), quota); - return GNUNET_NO; /* new content has such a low priority that - we should not even bother! */ - } - if (ntohl (value->prio) < minPriority) - minPriority = ntohl (value->prio); - /* construct new value with comp'ed priority */ - nvalue = GNUNET_malloc (ntohl (value->size)); - memcpy (nvalue, value, ntohl (value->size)); - nvalue->prio = htonl (comp_priority () + ntohl (value->prio)); - /* add the content */ - ok = sq->put (key, nvalue); - GNUNET_free (nvalue); - if (ok == GNUNET_YES) - { - makeAvailable (key); - available -= ntohl (value->size); - } - return ok; -} - typedef struct { int exists; @@ -297,6 +249,7 @@ cls.value = value; GNUNET_hash (&value[1], ntohl (value->size) - sizeof (GNUNET_DatastoreValue), &vhc); + GNUNET_mutex_lock(lock); sq->get (key, &vhc, ntohl (value->type), &checkExists, &cls); if ((!cls.exists) && (ntohl (value->type) == GNUNET_ECRS_BLOCKTYPE_DATA)) sq->get (key, &vhc, GNUNET_ECRS_BLOCKTYPE_ONDEMAND, &checkExists, &cls); @@ -308,11 +261,13 @@ if ((ntohl (value->prio) == 0) && (GNUNET_ntohll (value->expirationTime) <= cls.expiration)) { - return GNUNET_OK; + GNUNET_mutex_unlock(lock); + return GNUNET_OK; } /* update prio */ sq->update (cls.uid, ntohl (value->prio), GNUNET_ntohll (value->expirationTime)); + GNUNET_mutex_unlock(lock); return GNUNET_OK; } comp_prio = comp_priority (); @@ -326,8 +281,11 @@ /* check if we have enough space / priority */ if ((available < ntohl (value->size)) && (minPriority > ntohl (value->prio) + comp_prio)) - return GNUNET_NO; /* new content has such a low priority that - we should not even bother! */ + { + GNUNET_mutex_unlock(lock); + return GNUNET_NO; /* new content has such a low priority that + we should not even bother! */ + } if (ntohl (value->prio) + comp_prio < minPriority) minPriority = ntohl (value->prio) + comp_prio; /* construct new value with comp'ed priority */ @@ -342,6 +300,7 @@ makeAvailable (key); available -= ntohl (value->size); } + GNUNET_mutex_unlock(lock); return ok; } @@ -477,6 +436,7 @@ } return NULL; } + lock = GNUNET_mutex_create(GNUNET_NO); fsdir = NULL; GNUNET_GC_get_configuration_value_filename (capi->cfg, "FS", @@ -496,7 +456,6 @@ 10 * GNUNET_CRON_SECONDS, NULL); GNUNET_cron_start (cron); api.getSize = &getSize; - api.put = &put; api.fast_get = &testAvailable; api.putUpdate = &putUpdate; api.get = &get; @@ -525,6 +484,7 @@ coreAPI->release_service (stats); stats = NULL; } + GNUNET_mutex_destroy(lock); sq = NULL; coreAPI = NULL; } Modified: GNUnet/src/applications/rpc/rpc.c =================================================================== --- GNUnet/src/applications/rpc/rpc.c 2008-02-22 07:52:41 UTC (rev 6412) +++ GNUnet/src/applications/rpc/rpc.c 2008-02-22 15:24:15 UTC (rev 6413) @@ -507,7 +507,7 @@ ret->functionNameLength = htonl (errorCode); else ret->functionNameLength = htonl (slen); - ret->argumentCount = htonl ((value == NULL) ? 0 : GNUNET_RPC_parameters_count (values)); + ret->argumentCount = htonl ((values == NULL) ? 0 : GNUNET_RPC_parameters_count (values)); if (name != NULL) memcpy (&ret[1], name, slen); GNUNET_RPC_parameters_serialize (values, &((char *) &ret[1])[slen]); Modified: GNUnet/src/applications/sqstore_mysql/mysql.c =================================================================== --- GNUnet/src/applications/sqstore_mysql/mysql.c 2008-02-22 07:52:41 UTC (rev 6412) +++ GNUnet/src/applications/sqstore_mysql/mysql.c 2008-02-22 15:24:15 UTC (rev 6413) @@ -1262,6 +1262,14 @@ rbind[0].buffer = &total; rbind[0].is_unsigned = GNUNET_YES; /* first, determine total number of results */ + mysql_thread_init (); + GNUNET_mutex_lock (lock); + if (GNUNET_OK != CHECK_DBH) + { + mysql_thread_end (); + GNUNET_mutex_unlock (lock); + return GNUNET_SYSERR; + } if (type != 0) stmt = (vhash != @@ -1271,14 +1279,6 @@ stmt = (vhash != NULL) ? dbh->count_entry_by_hash_and_vhash : dbh->count_entry_by_hash; - mysql_thread_init (); - GNUNET_mutex_lock (lock); - if (GNUNET_OK != CHECK_DBH) - { - mysql_thread_end (); - GNUNET_mutex_unlock (lock); - return GNUNET_SYSERR; - } GNUNET_GE_ASSERT (ectx, mysql_stmt_param_count (stmt) <= 3); GNUNET_GE_ASSERT (ectx, mysql_stmt_field_count (stmt) == 1); if (mysql_stmt_bind_param (stmt, qbind)) Modified: GNUnet/src/include/gnunet_datastore_service.h =================================================================== --- GNUnet/src/include/gnunet_datastore_service.h 2008-02-22 07:52:41 UTC (rev 6412) +++ GNUnet/src/include/gnunet_datastore_service.h 2008-02-22 15:24:15 UTC (rev 6413) @@ -127,18 +127,6 @@ unsigned long long (*getSize) (void); /** - * Store an item in the datastore. If the item is - * already present, a second copy is created. - * - * @return GNUNET_YES on success, GNUNET_NO if the datastore is - * full and the priority of the item is not high enough - * to justify removing something else, GNUNET_SYSERR on - * other serious error (i.e. IO permission denied) - */ - int (*put) (const GNUNET_HashCode * key, - const GNUNET_DatastoreValue * value); - - /** * Store an item in the datastore. If the item is already present, * the priorities are summed up and the higher expiration time and * lower anonymity level is used. _______________________________________________ GNUnet-SVN mailing list GNUnet-SVN@gnu.org http://lists.gnu.org/mailman/listinfo/gnunet-svn