gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r6776 - in GNUnet/src: applications/fs/ecrs applications/fs


From: gnunet
Subject: [GNUnet-SVN] r6776 - in GNUnet/src: applications/fs/ecrs applications/fs/fsui include
Date: Sun, 4 May 2008 17:57:07 -0600 (MDT)

Author: grothoff
Date: 2008-05-04 17:57:07 -0600 (Sun, 04 May 2008)
New Revision: 6776

Modified:
   GNUnet/src/applications/fs/ecrs/tree.h
   GNUnet/src/applications/fs/fsui/fsui.c
   GNUnet/src/applications/fs/fsui/fsui.h
   GNUnet/src/include/gnunet_ecrs_lib.h
Log:
first -- untested -- version of FSUI search probes

Modified: GNUnet/src/applications/fs/ecrs/tree.h
===================================================================
--- GNUnet/src/applications/fs/ecrs/tree.h      2008-05-04 00:27:42 UTC (rev 
6775)
+++ GNUnet/src/applications/fs/ecrs/tree.h      2008-05-04 23:57:07 UTC (rev 
6776)
@@ -27,7 +27,7 @@
  * Size of a GNUNET_EC_DBlock.  Should be a multiple of 8 and larger than
  * sizeof(GNUNET_EC_ContentHashKey).
  */
-#define DBLOCK_SIZE 32768
+#define DBLOCK_SIZE (GNUNET_ECRS_DBLOCK_SIZE)
 
 /**
  * Pick a multiple of 2 here to achive 8-byte alignment!

Modified: GNUnet/src/applications/fs/fsui/fsui.c
===================================================================
--- GNUnet/src/applications/fs/fsui/fsui.c      2008-05-04 00:27:42 UTC (rev 
6775)
+++ GNUnet/src/applications/fs/fsui/fsui.c      2008-05-04 23:57:07 UTC (rev 
6776)
@@ -33,16 +33,47 @@
 
 /* ***************** CRON code ***************** */
 
+/**
+ * How often should cron run?
+ */
 #define GNUNET_FSUI_UDT_FREQUENCY (2 * GNUNET_CRON_SECONDS)
 
+#define SQUARE(x) ((x)*(x))
+
 /**
+ * We made progress on a test download.  Since
+ * a test download only contains a single block,
+ * any progress means that the test succeeded.
+ * We just set the flag to notify the cron in
+ * the next iteration.
+ */
+static void 
+test_download_progress(unsigned long long totalBytes,
+                      unsigned long long completedBytes,
+                      GNUNET_CronTime eta,
+                      unsigned long long lastBlockOffset,
+                      const char *lastBlock, unsigned int lastBlockSize, 
+                      void *closure) {
+  struct SearchResultList * srl = closure;
+  if (lastBlockSize > 0) /* check against IBlock events */
+    srl->test_download_start_time = 0;
+}
+
+
+/**
  * Cron job for download load management.
  */
 static void
 updateDownloadThreads (void *c)
 {
   GNUNET_FSUI_Context *ctx = c;
-  GNUNET_FSUI_DownloadList *dpos;
+  GNUNET_FSUI_DownloadList *dpos;             
+  struct SearchResultList * srl;
+  struct GNUNET_FSUI_SearchList * sl;
+  unsigned long long off;
+  unsigned long long len;
+  GNUNET_CronTime now;
+  GNUNET_FSUI_Event event;
 
   GNUNET_mutex_lock (ctx->lock);
   dpos = ctx->activeDownloads.child;
@@ -57,6 +88,98 @@
       GNUNET_FSUI_updateDownloadThread (dpos);
       dpos = dpos->next;
     }
+  now = GNUNET_get_time();
+  sl = ctx->activeSearches;
+  while (sl != NULL)
+    { 
+      GNUNET_mutex_lock(sl->lock);
+      srl = sl->resultsReceived;
+      while (srl != NULL)
+       {                 
+         if (srl->test_download != NULL)
+           {
+             if (srl->test_download_start_time == 0)
+               {
+                 /* probe was successful, kill */
+                 GNUNET_ECRS_file_download_partial_stop (srl->test_download);
+                 srl->test_download = NULL; 
+                 srl->probeSuccess++;
+                 event.type = GNUNET_FSUI_search_update;
+                 event.data.SearchUpdate.sc.pos = sl;
+                 event.data.SearchUpdate.sc.cctx = sl->cctx;             
+                 event.data.SearchUpdate.fi = srl->fi;
+                 event.data.SearchUpdate.searchURI = sl->uri;
+                 event.data.SearchUpdate.availability_rank = srl->probeSuccess 
- srl->probeFailure;
+                 event.data.SearchUpdate.applicability_rank = 
srl->matchingSearchCount;
+                 ctx->ecb(ctx->ecbClosure, &event);
+                 ctx->active_probes--;
+                 srl->last_probe_time = now;
+               }
+             else
+               {
+                 /* consider stopping */
+                 if ( (now - srl->test_download_start_time)
+                      > SQUARE(srl->probeSuccess + srl->probeFailure + 1) * 
GNUNET_FSUI_PROBE_TIME_FACTOR)
+                   {
+                     /* timeout hit! */
+                     GNUNET_ECRS_file_download_partial_stop 
(srl->test_download);
+                     srl->test_download = NULL;
+                     srl->probeFailure++;
+                     event.type = GNUNET_FSUI_search_update;
+                     event.data.SearchUpdate.sc.pos = sl;
+                     event.data.SearchUpdate.sc.cctx = sl->cctx;               
  
+                     event.data.SearchUpdate.fi = srl->fi;
+                     event.data.SearchUpdate.searchURI = sl->uri;
+                     event.data.SearchUpdate.availability_rank = 
srl->probeSuccess - srl->probeFailure;
+                     event.data.SearchUpdate.applicability_rank = 
srl->matchingSearchCount;
+                     ctx->ecb(ctx->ecbClosure, &event);
+                     ctx->active_probes--;
+                     srl->last_probe_time = now;
+                   }
+               }
+           }
+         else
+           {
+             len = GNUNET_ECRS_uri_get_file_size(srl->fi.uri);
+             if (len == 0)
+               srl->probeSuccess = -1; /* MAX */
+             /* consider starting */
+             if ( ( (srl->probeSuccess + srl->probeFailure) < 
GNUNET_FSUI_MAX_PROBES) &&
+                  ( (srl->last_probe_time < 
+                     now 
+                     + GNUNET_FSUI_PROBE_DELAY * SQUARE(ctx->active_probes)
+                     + GNUNET_random_u64(GNUNET_RANDOM_QUALITY_WEAK, 
GNUNET_FSUI_PROBE_DELAY)) ) &&
+                  (ctx->active_probes < GNUNET_FSUI_HARD_PROBE_LIMIT) ) 
+               {
+                 off = len / GNUNET_ECRS_DBLOCK_SIZE;
+                 if (off > 0)
+                   off = GNUNET_random_u32(GNUNET_RANDOM_QUALITY_WEAK, off);
+                 off *= GNUNET_ECRS_DBLOCK_SIZE;
+                 if (len - off < GNUNET_ECRS_DBLOCK_SIZE)
+                   len = len - off;
+                 else
+                   len = GNUNET_ECRS_DBLOCK_SIZE;
+                 srl->test_download
+                   = GNUNET_ECRS_file_download_partial_start (ctx->ectx,
+                                                              ctx->cfg,
+                                                              srl->fi.uri,
+                                                              NULL,
+                                                              off,
+                                                              len,
+                                                              1,
+                                                              GNUNET_YES,
+                                                              
&test_download_progress,
+                                                              srl);
+                 srl->test_download_start_time = now;
+                 ctx->active_probes++;
+               }             
+           }
+
+         srl = srl->next;        
+       }
+      GNUNET_mutex_unlock(sl->lock);
+      sl = sl->next;
+    }
   GNUNET_mutex_unlock (ctx->lock);
 }
 

Modified: GNUnet/src/applications/fs/fsui/fsui.h
===================================================================
--- GNUnet/src/applications/fs/fsui/fsui.h      2008-05-04 00:27:42 UTC (rev 
6775)
+++ GNUnet/src/applications/fs/fsui/fsui.h      2008-05-04 23:57:07 UTC (rev 
6776)
@@ -31,6 +31,29 @@
 #include "gnunet_ecrs_lib.h"
 
 /**
+ * How many probes do we do at most per search?
+ */
+#define GNUNET_FSUI_MAX_PROBES 10
+
+/**
+ * How many seconds do we spend on the first test download?
+ * (each additional probe will take exponentially longer)
+ */
+#define GNUNET_FSUI_PROBE_TIME_FACTOR (2 * GNUNET_CRON_MINUTES)
+
+/**
+ * Given n running probes, how long should we wait
+ * between the end of one probe and the starting of
+ * the next probe?  The exact delay will be n*n*PROBE_DELAY+rand(PROBE_DELAY).
+ */
+#define GNUNET_FSUI_PROBE_DELAY (5 * GNUNET_CRON_MINUTES)
+
+/**
+ * Strict upper limit on the number of concurrent probes.
+ */
+#define GNUNET_FSUI_HARD_PROBE_LIMIT 128
+
+/**
  * Track record for a given result.
  */
 struct SearchResultList
@@ -79,6 +102,17 @@
    */
   unsigned int probeFailure;
 
+  /**
+   * When did we start the test?  Set to 0
+   * if the download was successful.
+   */
+  GNUNET_CronTime test_download_start_time;
+
+  /**
+   * When did the last probe complete?
+   */
+  GNUNET_CronTime last_probe_time;
+
 };
 
 /**
@@ -500,6 +534,11 @@
    */
   unsigned int activeDownloadThreads;
 
+  /**
+   * Number of currently active search probes.
+   */
+  unsigned int active_probes;
+
 } GNUNET_FSUI_Context;
 
 /* ************ cross-file prototypes ************ */

Modified: GNUnet/src/include/gnunet_ecrs_lib.h
===================================================================
--- GNUnet/src/include/gnunet_ecrs_lib.h        2008-05-04 00:27:42 UTC (rev 
6775)
+++ GNUnet/src/include/gnunet_ecrs_lib.h        2008-05-04 23:57:07 UTC (rev 
6776)
@@ -78,8 +78,8 @@
 #define GNUNET_ECRS_SBLOCK_UPDATE_SPORADIC  -1
 #define GNUNET_ECRS_SBLOCK_UPDATE_NONE       0
 
+#define GNUNET_ECRS_DBLOCK_SIZE (32 * 1024)
 
-
 /* ***************** metadata API (meta.c) ******************** */
 
 /**





reply via email to

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