gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r33427 - gnunet/src/peerstore


From: gnunet
Subject: [GNUnet-SVN] r33427 - gnunet/src/peerstore
Date: Tue, 27 May 2014 20:37:45 +0200

Author: otarabai
Date: 2014-05-27 20:37:44 +0200 (Tue, 27 May 2014)
New Revision: 33427

Modified:
   gnunet/src/peerstore/gnunet-service-peerstore.c
   gnunet/src/peerstore/peerstore_api.c
   gnunet/src/peerstore/plugin_peerstore_sqlite.c
Log:
peerstore: iterate request timeout


Modified: gnunet/src/peerstore/gnunet-service-peerstore.c
===================================================================
--- gnunet/src/peerstore/gnunet-service-peerstore.c     2014-05-27 14:43:12 UTC 
(rev 33426)
+++ gnunet/src/peerstore/gnunet-service-peerstore.c     2014-05-27 18:37:44 UTC 
(rev 33427)
@@ -67,6 +67,8 @@
     GNUNET_free (db_lib_name);
     db_lib_name = NULL;
   }
+
+  GNUNET_SCHEDULER_shutdown();
 }
 
 /**
@@ -78,6 +80,8 @@
 {
   int deleted;
 
+  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
+    return;
   GNUNET_assert(NULL != db);
   deleted = db->expire_records(db->cls, GNUNET_TIME_absolute_get());
   GNUNET_log(GNUNET_ERROR_TYPE_INFO, "%d records expired.\n", deleted);
@@ -266,7 +270,7 @@
          GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Could not load database backend 
`%s'\n", db_lib_name);
   else
   {
-    cleanup_expired_records(NULL, NULL);
+    GNUNET_SCHEDULER_add_now(&cleanup_expired_records, NULL);
     GNUNET_SERVER_add_handlers (server, handlers);
     GNUNET_SERVER_disconnect_notify (server,
              &handle_client_disconnect,

Modified: gnunet/src/peerstore/peerstore_api.c
===================================================================
--- gnunet/src/peerstore/peerstore_api.c        2014-05-27 14:43:12 UTC (rev 
33426)
+++ gnunet/src/peerstore/peerstore_api.c        2014-05-27 18:37:44 UTC (rev 
33427)
@@ -161,6 +161,12 @@
    */
   int request_sent;
 
+  /**
+   * Task identifier for the function called
+   * on iterate request timeout
+   */
+  GNUNET_SCHEDULER_TaskIdentifier timeout_task;
+
 };
 
 
/******************************************************************************/
@@ -432,7 +438,7 @@
     GNUNET_PEERSTORE_Continuation cont,
     void *cont_cls)
 {
-  struct GNUNET_MQ_Envelope *ev;
+  struct GNUNET_MQ_Envelope *ev; //FIXME: add 'replace' flag in store function 
(similar to multihashmap)
   struct GNUNET_PEERSTORE_StoreContext *sc;
 
   LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -452,7 +458,7 @@
   sc->h = h;
   sc->request_sent = GNUNET_NO;
   GNUNET_CONTAINER_DLL_insert(h->store_head, h->store_tail, sc);
-  GNUNET_MQ_notify_sent(ev, &store_request_sent, ev);
+  GNUNET_MQ_notify_sent(ev, &store_request_sent, sc);
   GNUNET_MQ_send(h->mq, ev);
   return sc;
 
@@ -499,8 +505,7 @@
   msg_type = ntohs(msg->type);
   if(GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_END == msg_type)
   {
-    GNUNET_CONTAINER_DLL_remove(ic->h->iterate_head, ic->h->iterate_tail, ic);
-    GNUNET_free(ic);
+    GNUNET_PEERSTORE_iterate_cancel(ic);
     if(NULL != callback)
       callback(callback_cls, NULL, NULL);
     return;
@@ -533,6 +538,19 @@
 }
 
 /**
+ * Called when the iterate request is timedout
+ *
+ * @param cls a 'struct GNUNET_PEERSTORE_IterateContext *'
+ */
+void iterate_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+  struct GNUNET_PEERSTORE_IterateContext *ic = cls;
+
+  ic->timeout_task = GNUNET_SCHEDULER_NO_TASK;
+  GNUNET_PEERSTORE_iterate_cancel(ic);
+}
+
+/**
  * Cancel an iterate request
  * Please do not call after the iterate request is done
  *
@@ -541,7 +559,12 @@
 void
 GNUNET_PEERSTORE_iterate_cancel (struct GNUNET_PEERSTORE_IterateContext *ic)
 {
-  LOG(GNUNET_ERROR_TYPE_DEBUG, "User request cancel of iterate request.\n");
+  LOG(GNUNET_ERROR_TYPE_DEBUG, "Canceling iterate request.\n");
+  if(GNUNET_SCHEDULER_NO_TASK != ic->timeout_task)
+  {
+    GNUNET_SCHEDULER_cancel(ic->timeout_task);
+    ic->timeout_task = GNUNET_SCHEDULER_NO_TASK;
+  }
   if(GNUNET_NO == ic->request_sent)
   {
     if(NULL != ic->ev)
@@ -566,13 +589,14 @@
  * @param timeout time after which the iterate request is canceled
  * @param callback function called with each matching record, all NULL's on end
  * @param callback_cls closure for @a callback
+ * @return Handle to iteration request
  */
 struct GNUNET_PEERSTORE_IterateContext *
 GNUNET_PEERSTORE_iterate (struct GNUNET_PEERSTORE_Handle *h,
     char *sub_system,
     const struct GNUNET_PeerIdentity *peer,
     const char *key,
-    struct GNUNET_TIME_Relative timeout, //FIXME: handle timeout
+    struct GNUNET_TIME_Relative timeout,
     GNUNET_PEERSTORE_Processor callback, void *callback_cls)
 {
   struct GNUNET_MQ_Envelope *ev;
@@ -594,8 +618,9 @@
   GNUNET_CONTAINER_DLL_insert(h->iterate_head, h->iterate_tail, ic);
   LOG(GNUNET_ERROR_TYPE_DEBUG,
         "Sending an iterate request for sub system `%s'\n", sub_system);
-  GNUNET_MQ_notify_sent(ev, &iterate_request_sent, ev);
+  GNUNET_MQ_notify_sent(ev, &iterate_request_sent, ic);
   GNUNET_MQ_send(h->mq, ev);
+  ic->timeout_task = GNUNET_SCHEDULER_add_delayed(timeout, &iterate_timeout, 
ic);
   return ic;
 }
 

Modified: gnunet/src/peerstore/plugin_peerstore_sqlite.c
===================================================================
--- gnunet/src/peerstore/plugin_peerstore_sqlite.c      2014-05-27 14:43:12 UTC 
(rev 33426)
+++ gnunet/src/peerstore/plugin_peerstore_sqlite.c      2014-05-27 18:37:44 UTC 
(rev 33427)
@@ -51,6 +51,8 @@
 
 #define LOG(kind,...) GNUNET_log_from (kind, "peerstore-sqlite", __VA_ARGS__)
 
+//FIXME: Indexes
+
 /**
  * Context for all functions in this plugin.
  */
@@ -98,11 +100,6 @@
   sqlite3_stmt *select_peerstoredata_by_all;
 
   /**
-   * Precompiled SQL for selecting from peerstoredata
-   */
-  sqlite3_stmt *select_peerstoredata_by_all_and_value;
-
-  /**
    * Precompiled SQL for deleting expired records from peerstoredata
    */
   sqlite3_stmt *expire_peerstoredata;
@@ -237,42 +234,6 @@
 }
 
 /**
- * Checks if a record with the given information
- * already exists
- *
- * @return #GNUNET_YES / #GNUNET_NO
- *
-static int
-check_existing(void *cls,
-    const char *sub_system,
-    const struct GNUNET_PeerIdentity *peer,
-    const char *key,
-    const void *value,
-    size_t size)
-{
-  struct Plugin *plugin = cls;
-  sqlite3_stmt *stmt = plugin->select_peerstoredata_by_all_and_value;
-  int sret;
-
-  if(SQLITE_OK != sqlite3_bind_text(stmt, 1, sub_system, strlen(sub_system) + 
1, SQLITE_STATIC)
-      || SQLITE_OK != sqlite3_bind_blob(stmt, 2, peer, sizeof(struct 
GNUNET_PeerIdentity), SQLITE_STATIC)
-      || SQLITE_OK != sqlite3_bind_text(stmt, 3, key, strlen(key) + 1, 
SQLITE_STATIC)
-      || SQLITE_OK != sqlite3_bind_blob(stmt, 4, value, size, SQLITE_STATIC))
-  {
-    LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
-        "sqlite3_bind");
-    sqlite3_reset(stmt);
-    return GNUNET_NO;
-  }
-  sret = sqlite3_step (stmt);
-  sqlite3_reset(stmt);
-  if(SQLITE_ROW == sret)
-    return GNUNET_YES;
-  return GNUNET_NO;
-
-}*/
-
-/**
  * Store a record in the peerstore.
  * Key is the combination of sub system and peer identity.
  * One key can store multiple values.
@@ -296,17 +257,6 @@
   struct Plugin *plugin = cls;
   sqlite3_stmt *stmt = plugin->insert_peerstoredata;
 
-  //FIXME: check if value exists with the same key first
-  /*if(GNUNET_YES == check_existing(cls,
-      sub_system,
-      peer,
-      key,
-      value,
-      size))
-  {
-
-  }*/
-
   if(SQLITE_OK != sqlite3_bind_text(stmt, 1, sub_system, strlen(sub_system) + 
1, SQLITE_STATIC)
       || SQLITE_OK != sqlite3_bind_blob(stmt, 2, peer, sizeof(struct 
GNUNET_PeerIdentity), SQLITE_STATIC)
       || SQLITE_OK != sqlite3_bind_text(stmt, 3, key, strlen(key) + 1, 
SQLITE_STATIC)
@@ -466,13 +416,6 @@
       " AND key = ?",
       &plugin->select_peerstoredata_by_all);
   sql_prepare(plugin->dbh,
-      "SELECT * FROM peerstoredata"
-      " WHERE sub_system = ?"
-      " AND peer_id = ?"
-      " AND key = ?"
-      " AND value = ?",
-      &plugin->select_peerstoredata_by_all_and_value);
-  sql_prepare(plugin->dbh,
       "DELETE FROM peerstoredata"
       " WHERE expiry < ?",
       &plugin->expire_peerstoredata);




reply via email to

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