gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r3268 - in GNUnet: . src/applications src/applications/adve


From: grothoff
Subject: [GNUnet-SVN] r3268 - in GNUnet: . src/applications src/applications/advertising src/applications/fs/ecrs src/applications/fs/fsui src/applications/gap src/applications/kvstore_sqlite src/applications/stats src/applications/testbed
Date: Sun, 20 Aug 2006 13:18:09 -0700 (PDT)

Author: grothoff
Date: 2006-08-20 13:18:02 -0700 (Sun, 20 Aug 2006)
New Revision: 3268

Modified:
   GNUnet/src/applications/Makefile.am
   GNUnet/src/applications/advertising/bootstrap.c
   GNUnet/src/applications/fs/ecrs/ecrstest.c
   GNUnet/src/applications/fs/fsui/downloadtest.c
   GNUnet/src/applications/fs/fsui/fsui-loader.c
   GNUnet/src/applications/fs/fsui/fsuitest.c
   GNUnet/src/applications/fs/fsui/searchtest.c
   GNUnet/src/applications/gap/gaptest.c
   GNUnet/src/applications/kvstore_sqlite/kv_sqlite.c
   GNUnet/src/applications/stats/gnunet-stats.c
   GNUnet/src/applications/testbed/testbed.c
   GNUnet/todo
Log:
fixing kvstore

Modified: GNUnet/src/applications/Makefile.am
===================================================================
--- GNUnet/src/applications/Makefile.am 2006-08-20 19:56:42 UTC (rev 3267)
+++ GNUnet/src/applications/Makefile.am 2006-08-20 20:18:02 UTC (rev 3268)
@@ -1,3 +1,5 @@
+# commented out for now: vpn
+
 if HAVE_MYSQL
  MYSQL_DIR = sqstore_mysql
 endif
@@ -7,17 +9,15 @@
 endif
 
 if !MINGW
- TESTBED_DIR = testbed
- VPN_DIR = vpn
+# TESTBED_DIR = testbed
+# VPN_DIR = vpn
 endif
 
 SUBDIRS        = \
  advertising \
  bootstrap_http \
- chat \
  datastore \
  rpc \
- dht \
  fragmentation \
  getoption \
  fs \
@@ -38,3 +38,6 @@
  traffic \
  transport \
  $(VPN_DIR)
+# dht 
+# chat
+# kvstore_sqlite

Modified: GNUnet/src/applications/advertising/bootstrap.c
===================================================================
--- GNUnet/src/applications/advertising/bootstrap.c     2006-08-20 19:56:42 UTC 
(rev 3267)
+++ GNUnet/src/applications/advertising/bootstrap.c     2006-08-20 20:18:02 UTC 
(rev 3268)
@@ -66,15 +66,16 @@
     GE_BREAK(coreAPI->ectx, 0);
     return;
   }
-  while ( (! hqc.do_shutdown) &&
+  while ( (! hcq->do_shutdown) &&
          (hcq->helosCount > 0) ) {
     /* select hello by random */
     rndidx = weak_randomi(hcq->helosCount);
 #if DEBUG_BOOTSTRAP
-    GE_LOG(ectx, GE_DEBUG | GE_REQUEST | GE_USER,
-       "%s chose hello %d of %d\n",
-       __FUNCTION__,
-       rndidx, hcq->helosCount);
+    GE_LOG(ectx, 
+          GE_DEBUG | GE_REQUEST | GE_USER,
+          "%s chose hello %d of %d\n",
+          __FUNCTION__,
+          rndidx, hcq->helosCount);
 #endif
     msg = (P2P_hello_MESSAGE*) hcq->helos[rndidx];
     hcq->helos[rndidx]

Modified: GNUnet/src/applications/fs/ecrs/ecrstest.c
===================================================================
--- GNUnet/src/applications/fs/ecrs/ecrstest.c  2006-08-20 19:56:42 UTC (rev 
3267)
+++ GNUnet/src/applications/fs/ecrs/ecrstest.c  2006-08-20 20:18:02 UTC (rev 
3268)
@@ -58,7 +58,7 @@
 
   fn = STRDUP("/tmp/gnunet-ecrstest");
   name = expandFileName(fn);
-  mkdirp(name);
+  disk_directory_create(ectx, name);
   FREE(fn);
   fn = MALLOC(strlen(name) + 40);
   SNPRINTF(fn,

Modified: GNUnet/src/applications/fs/fsui/downloadtest.c
===================================================================
--- GNUnet/src/applications/fs/fsui/downloadtest.c      2006-08-20 19:56:42 UTC 
(rev 3267)
+++ GNUnet/src/applications/fs/fsui/downloadtest.c      2006-08-20 20:18:02 UTC 
(rev 3268)
@@ -61,7 +61,7 @@
 
   fn = STRDUP("/tmp/gnunet-fsuidownloadtest");
   name = expandFileName(fn);
-  mkdirp(name);
+  disk_directory_create(ectx, name);
   FREE(fn);
   fn = MALLOC(strlen(name) + 40);
   SNPRINTF(fn,

Modified: GNUnet/src/applications/fs/fsui/fsui-loader.c
===================================================================
--- GNUnet/src/applications/fs/fsui/fsui-loader.c       2006-08-20 19:56:42 UTC 
(rev 3267)
+++ GNUnet/src/applications/fs/fsui/fsui-loader.c       2006-08-20 20:18:02 UTC 
(rev 3268)
@@ -29,8 +29,8 @@
 #include "gnunet_util_config_impl.h"
 #include "gnunet_util_error_loggers.h"
 
-static void eventCallback(void * cls,
-                         const FSUI_Event * event) {
+static void * eventCallback(void * cls,
+                           const FSUI_Event * event) {
 #if 0
   switch(event->type) {
   case FSUI_search_result:
@@ -50,6 +50,7 @@
     break;
   }
 #endif
+  return NULL;
 }
 
 int main(int argc,

Modified: GNUnet/src/applications/fs/fsui/fsuitest.c
===================================================================
--- GNUnet/src/applications/fs/fsui/fsuitest.c  2006-08-20 19:56:42 UTC (rev 
3267)
+++ GNUnet/src/applications/fs/fsui/fsuitest.c  2006-08-20 20:18:02 UTC (rev 
3268)
@@ -53,7 +53,7 @@
 
   fn = STRDUP("/tmp/gnunet-fsuitest");
   name = expandFileName(fn);
-  mkdirp(name);
+  disk_directory_create(ectx, name);
   FREE(fn);
   fn = MALLOC(strlen(name) + 40);
   SNPRINTF(fn,

Modified: GNUnet/src/applications/fs/fsui/searchtest.c
===================================================================
--- GNUnet/src/applications/fs/fsui/searchtest.c        2006-08-20 19:56:42 UTC 
(rev 3267)
+++ GNUnet/src/applications/fs/fsui/searchtest.c        2006-08-20 20:18:02 UTC 
(rev 3268)
@@ -53,7 +53,7 @@
 
   fn = STRDUP("/tmp/gnunet-fsuisearchtest");
   name = expandFileName(fn);
-  mkdirp(name);
+  disk_directory_create(ectx, name);
   FREE(fn);
   fn = MALLOC(strlen(name) + 40);
   SNPRINTF(fn,

Modified: GNUnet/src/applications/gap/gaptest.c
===================================================================
--- GNUnet/src/applications/gap/gaptest.c       2006-08-20 19:56:42 UTC (rev 
3267)
+++ GNUnet/src/applications/gap/gaptest.c       2006-08-20 20:18:02 UTC (rev 
3268)
@@ -66,7 +66,7 @@
 
   fn = STRDUP("/tmp/gnunet-ecrstest");
   name = expandFileName(fn);
-  mkdirp(name);
+  disk_directory_create(ectx, name);
   FREE(fn);
   fn = MALLOC(strlen(name) + 40);
   SNPRINTF(fn,

Modified: GNUnet/src/applications/kvstore_sqlite/kv_sqlite.c
===================================================================
--- GNUnet/src/applications/kvstore_sqlite/kv_sqlite.c  2006-08-20 19:56:42 UTC 
(rev 3267)
+++ GNUnet/src/applications/kvstore_sqlite/kv_sqlite.c  2006-08-20 20:18:02 UTC 
(rev 3268)
@@ -30,6 +30,7 @@
 
 #include "platform.h"
 #include "gnunet_util.h"
+#include "gnunet_directories.h"
 #include "gnunet_kvstore_service.h"
 #include <sqlite3.h>
 
@@ -40,17 +41,19 @@
  * a failure of the command 'cmd' with the message given
  * by strerror(errno).
  */
-#define DIE_SQLITE(cmd) do { errexit(_("`%s' failed at %s:%d with error: 
%s\n"), cmd, __FILE__, __LINE__, sqlite3_errmsg(dbh->dbh)); } while(0);
+#define DIE_SQLITE(cmd) do { GE_LOG(ectx, GE_FATAL | GE_ADMIN | GE_BULK, 
_("`%s' failed at %s:%d with error: %s\n"), cmd, __FILE__, __LINE__, 
sqlite3_errmsg(dbh->dbh)); abort(); } while(0);
 
 /**
  * Log an error message at log-level 'level' that indicates
  * a failure of the command 'cmd' on file 'filename'
  * with the message given by strerror(errno).
  */
-#define LOG_SQLITE(level, cmd) do { fprintf(stderr, _("`%s' failed at %s:%d 
with error: %s\n"), cmd, __FILE__, __LINE__, sqlite3_errmsg(dbh->dbh)); } 
while(0);
+#define LOG_SQLITE(level, cmd) do { GE_LOG(ectx, GE_ERROR | GE_ADMIN | 
GE_BULK, _("`%s' failed at %s:%d with error: %s\n"), cmd, __FILE__, __LINE__, 
sqlite3_errmsg(dbh->dbh)); } while(0);
 
 static CoreAPIForApplication * coreAPI;
 
+static struct GE_Context * ectx;
+
 /**
  * @brief Wrapper for SQLite
  */
@@ -58,22 +61,26 @@
   /* Native SQLite database handle - may not be shared between threads! */
   sqlite3 *dbh;
   /* Thread ID owning this handle */
-  pthread_t tid;
+  struct PTHREAD * tid;
   /* Synchronized access to sqlite */
-  Mutex *DATABASE_Lock_;
+  struct MUTEX * DATABASE_Lock_;
 } sqliteHandle;
 
 /**
  * @brief Information about the database
  */
 typedef struct {
-  Mutex DATABASE_Lock_;
+  struct MUTEX * DATABASE_Lock_;
+
   /** name of the database */
   char *name;  
+
   /** filename of this database */
   char *fn;
+
   /** bytes used */
   double payload;
+
   unsigned int lastSync;
   
   /* Open handles */
@@ -88,11 +95,12 @@
 
 
 static unsigned int databases = 0;
+
 static sqliteDatabase *dbs;
 
 static sqliteHandle *getDBHandle(const char *name);
 
-static Mutex databasesLock;
+static struct MUTEX * databasesLock;
 
 /**
  * @brief Encode a binary buffer "in" of size n bytes so that it contains
@@ -167,33 +175,29 @@
 /**
  * @brief Create new database structure
  */
-static void new_db(sqliteDatabase *db, const char *name)
-{
+static void new_db(sqliteDatabase *db, 
+                  const char *name) {
   char *dir;
-  unsigned int mem;
+  size_t mem;
   
   memset(db, sizeof(sqliteDatabase), 0);
   
-  MUTEX_CREATE(&db->DATABASE_Lock_);
+  db->DATABASE_Lock_ = MUTEX_CREATE(NO);
   
   /* Get path to database file */
-  dir = getFileName("KEYVALUE_DATABASE", "DIR",
-           _("Configuration file must specify directory for "
-           "storing data in section `%s' under `%s'.\n"));
-           
-  if (dir != NULL)
-    mem = strlen(dir);
-  else
-    mem = 0;
-    
-  mkdirp(dir);
-    
-  mem += strlen(name) + 6; /* 6 = "/" + ".dat" */
-   
+  GC_get_configuration_value_filename(coreAPI->cfg,
+                                     "KEYVALUE_DATABASE", 
+                                     "DIR",
+                                     VAR_DAEMON_DIRECTORY "/kvstore/",
+                                     &dir);
+  mem = strlen(dir) + strlen(name) + 5;
   db->fn = (char *) MALLOC(mem);
-  sprintf(db->fn, "%s/%s.dat", dir, name);
-  FREE(dir);
-  
+  SNPRINTF(db->fn, 
+          mem,
+          "%s/%s.dat",
+          dir, 
+          name);
+  FREE(dir);  
   db->name = STRDUP(name);
 }
 
@@ -221,11 +225,10 @@
  */
 static sqliteHandle *getDBHandle(const char *name) {
   unsigned int idx;
-  pthread_t this_tid;
   sqliteHandle *dbh = NULL;
   sqliteDatabase *db = NULL;
   
-  MUTEX_LOCK(&databasesLock);
+  MUTEX_LOCK(databasesLock);
   
   /* Is database already open? */
   db = getDB(name);  
@@ -237,14 +240,12 @@
     new_db(db, name);
   }
 
-  MUTEX_UNLOCK(&databasesLock);
-
-  MUTEX_LOCK(&db->DATABASE_Lock_);
+  MUTEX_UNLOCK(databasesLock);
+  MUTEX_LOCK(db->DATABASE_Lock_);
   
   /* Was it opened by this thread? */
-  this_tid = pthread_self();
   for (idx = 0; idx < db->handle_count; idx++)
-    if (pthread_equal(db->handles[idx].tid, this_tid)) {
+    if (PTHREAD_TEST_SELF(db->handles[idx].tid)) {
       dbh = db->handles + idx;
       break;
     }
@@ -255,8 +256,8 @@
         db->handle_count,
         db->handle_count + 1);
     dbh = db->handles + db->handle_count - 1;
-    dbh->tid = this_tid;
-    dbh->DATABASE_Lock_ = &db->DATABASE_Lock_;
+    dbh->tid = PTHREAD_GET_SELF();
+    dbh->DATABASE_Lock_ = db->DATABASE_Lock_;
 
     /* Open database */
     if (sqlite3_open(db->fn, &dbh->dbh) != SQLITE_OK) {
@@ -274,25 +275,25 @@
     sqlite3_exec(dbh->dbh, "PRAGMA page_size=4096", NULL, NULL, NULL);
   }
 
-  MUTEX_UNLOCK(&db->DATABASE_Lock_);
+  MUTEX_UNLOCK(db->DATABASE_Lock_);
 
   return dbh;
 }
 
-static void close_database(sqliteDatabase *db)
-{
+static void close_database(sqliteDatabase *db) {
   unsigned int idx;
 
   for (idx = 0; idx < db->handle_count; idx++) {
-    sqliteHandle *dbh = db->handles + idx;
-
+    sqliteHandle * dbh = db->handles + idx;
+    PTHREAD_REL_SELF(dbh->tid);
     if (sqlite3_close(dbh->dbh) != SQLITE_OK)
-      LOG_SQLITE(LOG_ERROR, "sqlite_close");
+      LOG_SQLITE(LOG_ERROR, 
+                "sqlite_close");
   }
   FREE(db->handles);
   db->handle_count = 0;
 
-  MUTEX_DESTROY(&db->DATABASE_Lock_);
+  MUTEX_DESTROY(db->DATABASE_Lock_);
   FREE(db->fn);
   FREE(db->name);
 
@@ -671,16 +672,16 @@
 KVstore_ServiceAPI *
 provide_module_kvstore_sqlite(CoreAPIForApplication * capi) {
   static KVstore_ServiceAPI api;
-
+  
+  ectx = capi->ectx;
 #if DEBUG_SQLITE
-  GE_LOG(ectx, GE_DEBUG | GE_REQUEST | GE_USER,
-      "SQLite: initializing database\n");
+  GE_LOG(ectx, 
+        GE_DEBUG | GE_REQUEST | GE_USER,
+        "SQLite: initializing database\n");
 #endif
 
-  MUTEX_CREATE(&databasesLock);
-
+  databasesLock = MUTEX_CREATE(NO);
   coreAPI = capi;
-
   api.closeTable = &closeTable;
   api.del = &del;
   api.get = &get;
@@ -697,12 +698,12 @@
 void release_module_kvstore_sqlite() {
   sqlite_shutdown();
 #if DEBUG_SQLITE
-  GE_LOG(ectx, GE_DEBUG | GE_REQUEST | GE_USER,
-      "SQLite KVStore: database shutdown\n");
+  GE_LOG(ectx,
+        GE_DEBUG | GE_REQUEST | GE_USER,
+        "SQLite KVStore: database shutdown\n");
 #endif
 
-  MUTEX_DESTROY(&databasesLock);
-
+  MUTEX_DESTROY(databasesLock);
   coreAPI = NULL;
 }
 

Modified: GNUnet/src/applications/stats/gnunet-stats.c
===================================================================
--- GNUnet/src/applications/stats/gnunet-stats.c        2006-08-20 19:56:42 UTC 
(rev 3267)
+++ GNUnet/src/applications/stats/gnunet-stats.c        2006-08-20 20:18:02 UTC 
(rev 3268)
@@ -117,7 +117,7 @@
   GE_setDefaultContext(ectx);
   cfg = GC_create_C_impl();
   GE_ASSERT(ectx, cfg != NULL);
-  os_init();
+  os_init(ectx);
   if (-1 == gnunet_parse_options("gnunet-stats",
                                 ectx,
                                 cfg,

Modified: GNUnet/src/applications/testbed/testbed.c
===================================================================
--- GNUnet/src/applications/testbed/testbed.c   2006-08-20 19:56:42 UTC (rev 
3267)
+++ GNUnet/src/applications/testbed/testbed.c   2006-08-20 20:18:02 UTC (rev 
3268)
@@ -513,7 +513,7 @@
   if (tmp == NULL)
     tmp = STRDUP("/");
   dir = expandFileName(tmp);
-  mkdirp(dir);
+  disk_directory_create(ectx, dir);
   FREE(tmp);
 
   MUTEX_LOCK(&lock);
@@ -844,7 +844,7 @@
   }
   gnHome = expandFileName(tmp);
   FREE(tmp);
-  mkdirp(gnHome);
+  disk_directory_create(ectx, gnHome);
 
   filename = MALLOC(strlen(filename) + strlen(gnHome) + 2); /*2: /, \0 */
   strcpy(filename, gnHome);

Modified: GNUnet/todo
===================================================================
--- GNUnet/todo 2006-08-20 19:56:42 UTC (rev 3267)
+++ GNUnet/todo 2006-08-20 20:18:02 UTC (rev 3268)
@@ -29,11 +29,11 @@
       traffic, ecrs_core, template, tbench, tracekit, fs/fslib,
       fs/module, gap, fs/ecrs, fs/uritrack, fs/namespace,
       fs/fsui, fs/collection, fs/tools, bootstrap_http,
-      sqstore_mysql, topology_f2f, rpc compile
+      sqstore_mysql, topology_f2f, rpc, kvstore_sqlite compile
     + fs/fsui, fs/collection, fs/uritrack, fs/namespace
       must still be revised to match new API!
     + rest: dht, vpn
-    + low priority: chat, kvstore_sqlite, testbed
+    + low priority: chat, testbed
   * setup:
     + main binary compiles, plugins are missing
       consider reorganization (subdirectories):





reply via email to

[Prev in Thread] Current Thread [Next in Thread]