gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r4056 - in GNUnet: . src/applications/dht/module src/util/c


From: grothoff
Subject: [GNUnet-SVN] r4056 - in GNUnet: . src/applications/dht/module src/util/cron
Date: Tue, 26 Dec 2006 20:34:13 -0800 (PST)

Author: grothoff
Date: 2006-12-26 20:34:10 -0800 (Tue, 26 Dec 2006)
New Revision: 4056

Modified:
   GNUnet/src/applications/dht/module/service.c
   GNUnet/src/util/cron/cron.c
   GNUnet/todo
Log:
DHT timeout

Modified: GNUnet/src/applications/dht/module/service.c
===================================================================
--- GNUnet/src/applications/dht/module/service.c        2006-12-27 04:16:57 UTC 
(rev 4055)
+++ GNUnet/src/applications/dht/module/service.c        2006-12-27 04:34:10 UTC 
(rev 4056)
@@ -22,8 +22,6 @@
  * @file module/service.c
  * @brief internal GNUnet DHT service
  * @author Christian Grothoff
- *
- * TODO: support async get timeout (gap never stops otherwise!)
  */
 
 #include "platform.h"
@@ -38,12 +36,41 @@
 static CoreAPIForApplication * coreAPI;
 
 typedef struct DHT_GET_RECORD {
+  /**
+   * Key that we are looking for.
+   */  
   HashCode512 key;
+
+  /**
+   * Semaphore used to signal completion of timeout cron job.
+   */
+  struct SEMAPHORE * sem;
+
+  /**
+   * Function to call for each result.
+   */
   DataProcessor callback;
+
+  /**
+   * Extra argument to callback.
+   */
   void * cls;
+
+  /**
+   * Function to call once we are done
+   */
   DHT_OP_Complete callbackComplete;
+
+  /**
+   * Extra argument to callbackComplete
+   */
   void * closure;
+
+  /**
+   * Type of the content that we are looking for.
+   */
   unsigned int type;
+
 } DHT_GET_RECORD;
 
 static void client_result_converter(const HashCode512 * key,
@@ -66,10 +93,23 @@
 }
 
 /**
+ * Cron job that notifies the client.
+ */
+static void timeout_callback(void * cls) {
+  struct DHT_GET_RECORD * rec = cls;
+
+  rec->callbackComplete(rec->closure);
+  SEMAPHORE_UP(rec->sem);
+}
+
+/**
  * Perform an asynchronous GET operation on the DHT identified by
  * 'table' using 'key' as the key.  The peer does not have to be part
- * of the table (if so, we will attempt to locate a peer that is!)
+ * of the table (if so, we will attempt to locate a peer that is!).
  *
+ * Even in the case of a time-out (once completion callback has been
+ * invoked), clients will still call the "stop" function explicitly.
+ *
  * @param table table to use for the lookup
  * @param key the key to look up
  * @param timeout how long to wait until this operation should
@@ -89,12 +129,18 @@
   struct DHT_GET_RECORD * ret;
 
   ret = MALLOC(sizeof(DHT_GET_RECORD));
+  ret->key = *key;
+  ret->sem = SEMAPHORE_CREATE(0);
   ret->callback = callback;
   ret->cls = cls;
   ret->callbackComplete = callbackComplete;
   ret->closure = closure;
   ret->type = type;
-  ret->key = *key;
+  cron_add_job(coreAPI->cron,
+              &timeout_callback,
+              timeout,
+              0,
+              ret);
   dht_get_start(key,
                type,
                &client_result_converter,
@@ -110,8 +156,14 @@
   dht_get_stop(&record->key,
               record->type,
               &client_result_converter,
-              record);
-  record->callbackComplete(record->closure);
+              record);  
+  cron_advance_job(coreAPI->cron,
+                  &timeout_callback,
+                  0,
+                  record);             
+  /* wait for cron-job to complete! */
+  SEMAPHORE_DOWN(record->sem, YES);
+  SEMAPHORE_DESTROY(record->sem);
   FREE(record);
   return OK;
 }
@@ -123,7 +175,8 @@
  * @param capi the core API
  * @return NULL on errors, DHT_API otherwise
  */
-DHT_ServiceAPI * provide_module_dht(CoreAPIForApplication * capi) {
+DHT_ServiceAPI * 
+provide_module_dht(CoreAPIForApplication * capi) {
   static DHT_ServiceAPI api;
 
   if (OK != init_dht_store(1024 * 1024,

Modified: GNUnet/src/util/cron/cron.c
===================================================================
--- GNUnet/src/util/cron/cron.c 2006-12-27 04:16:57 UTC (rev 4055)
+++ GNUnet/src/util/cron/cron.c 2006-12-27 04:34:10 UTC (rev 4056)
@@ -347,20 +347,7 @@
   MUTEX_LOCK(cron->deltaListLock_);
   jobId = cron->firstUsed_;
   if (jobId == -1) {
-    /* not in queue; add if not running */
-    if ( (method != cron->runningJob_) ||
-         (data != cron->runningData_) ||
-        (deltaRepeat != cron->runningRepeat_) ) {
-      GE_LOG(cron->ectx,
-            GE_ERROR | GE_USER | GE_DEVELOPER | GE_BULK,
-            _("`%s' called with cron job not in queue, adding.  This may not 
be what you want.\n"),
-            __FUNCTION__);
-      cron_add_job(cron,
-                  method,
-                  0,
-                  deltaRepeat,
-                  data);
-    }
+    /* not in queue - do nothing! */
     MUTEX_UNLOCK(cron->deltaListLock_);
     return;
   }

Modified: GNUnet/todo
===================================================================
--- GNUnet/todo 2006-12-27 04:16:57 UTC (rev 4055)
+++ GNUnet/todo 2006-12-27 04:34:10 UTC (rev 4056)
@@ -31,7 +31,6 @@
 0.7.2 [3'07]:
 - new features:
   * XFS / support for location URIs [CG] 
-    + dht/service.c: timeout [RC]
     + dht/cs: not done yet [RC]
     + dht/tools: update clients [RC]
     + dht/gap integration [RC]





reply via email to

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