gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r1347 - in GNUnet/src: applications/dht/module applications


From: durner
Subject: [GNUnet-SVN] r1347 - in GNUnet/src: applications/dht/module applications/fs/ecrs applications/gap applications/identity applications/transport include server util
Date: Sat, 9 Jul 2005 07:05:22 -0700 (PDT)

Author: durner
Date: 2005-07-09 07:05:10 -0700 (Sat, 09 Jul 2005)
New Revision: 1347

Modified:
   GNUnet/src/applications/dht/module/datastore_dht_master.c
   GNUnet/src/applications/fs/ecrs/download.c
   GNUnet/src/applications/gap/gap.c
   GNUnet/src/applications/identity/identity.c
   GNUnet/src/applications/transport/transport.c
   GNUnet/src/include/gnunet_util.h
   GNUnet/src/server/connection.c
   GNUnet/src/util/random.c
Log:
Optimize permute()

Modified: GNUnet/src/applications/dht/module/datastore_dht_master.c
===================================================================
--- GNUnet/src/applications/dht/module/datastore_dht_master.c   2005-07-09 
13:58:47 UTC (rev 1346)
+++ GNUnet/src/applications/dht/module/datastore_dht_master.c   2005-07-09 
14:05:10 UTC (rev 1347)
@@ -100,7 +100,7 @@
       else
        count = pos->count;
       if (count < pos->count)
-       perm = permute(pos->count); /* randomize returned set! */
+       perm = permute(WEAK, pos->count); /* randomize returned set! */
       else
        perm = NULL;
 

Modified: GNUnet/src/applications/fs/ecrs/download.c
===================================================================
--- GNUnet/src/applications/fs/ecrs/download.c  2005-07-09 13:58:47 UTC (rev 
1346)
+++ GNUnet/src/applications/fs/ecrs/download.c  2005-07-09 14:05:10 UTC (rev 
1347)
@@ -1092,7 +1092,7 @@
   }
 
   minSleep = 5000 * cronMILLIS; /* max-sleep! */
-  perm = permute(rm->requestListIndex);
+  perm = permute(STRONG, rm->requestListIndex);
   for (i=0;i<rm->requestListIndex;i++) {
     int j = perm[i];
     if (rm->requestList[j]->lastTimeout + TTL_DECREMENT < now) {

Modified: GNUnet/src/applications/gap/gap.c
===================================================================
--- GNUnet/src/applications/gap/gap.c   2005-07-09 13:58:47 UTC (rev 1346)
+++ GNUnet/src/applications/gap/gap.c   2005-07-09 14:05:10 UTC (rev 1347)
@@ -1596,7 +1596,7 @@
   }
 
   if (cls.valueCount > 0) {
-    perm = permute(cls.valueCount);
+    perm = permute(STRONG, cls.valueCount);
     max = getNetworkLoadDown();
     if (max > 100)
       max = 100;

Modified: GNUnet/src/applications/identity/identity.c
===================================================================
--- GNUnet/src/applications/identity/identity.c 2005-07-09 13:58:47 UTC (rev 
1346)
+++ GNUnet/src/applications/identity/identity.c 2005-07-09 14:05:10 UTC (rev 
1347)
@@ -549,7 +549,7 @@
   MUTEX_LOCK(&lock_);  
   if (YES == tryTemporaryList) {
     if (protocol == ANY_PROTOCOL_NUMBER)
-      perm = permute(MAX_TEMP_HOSTS);
+      perm = permute(WEAK, MAX_TEMP_HOSTS);
     else
       perm = NULL;
     /* ok, then first try temporary hosts 

Modified: GNUnet/src/applications/transport/transport.c
===================================================================
--- GNUnet/src/applications/transport/transport.c       2005-07-09 13:58:47 UTC 
(rev 1346)
+++ GNUnet/src/applications/transport/transport.c       2005-07-09 14:05:10 UTC 
(rev 1347)
@@ -217,7 +217,7 @@
 
   MUTEX_LOCK(&tapis_lock);
   ret = NULL;
-  perm = permute(tapis_count);
+  perm = permute(WEAK, tapis_count);
   for (i=0;i<tapis_count;i++) {
     if (tapis[perm[i]] == NULL)
       continue;
@@ -449,7 +449,7 @@
   if (ttype == ANY_PROTOCOL_NUMBER) {
     int * perm;
 
-    perm = permute(tapis_count);
+    perm = permute(WEAK, tapis_count);
     ttype = tapis_count-1;
     while ( (ttype < tapis_count) &&
            ( (tapis[perm[ttype]] == NULL) ||

Modified: GNUnet/src/include/gnunet_util.h
===================================================================
--- GNUnet/src/include/gnunet_util.h    2005-07-09 13:58:47 UTC (rev 1346)
+++ GNUnet/src/include/gnunet_util.h    2005-07-09 14:05:10 UTC (rev 1347)
@@ -88,6 +88,9 @@
 #define YES     1
 #define NO      0
 
+#define STRONG YES
+#define WEAK NO
+
 /**
  * @brief constants to specify time
  */
@@ -556,10 +559,11 @@
 /**
  * Get an array with a random permutation of the
  * numbers 0...n-1.
+ * @param mode STRONG if the strong (but expensive) PRNG should be used, WEAK 
otherwise
  * @param n the size of the array
  * @return the permutation array (allocated from heap)
  */
-int * permute(int n);
+int * permute(int mode, int n);
 
 /**
  * Produce a cryptographically weak random value.

Modified: GNUnet/src/server/connection.c
===================================================================
--- GNUnet/src/server/connection.c      2005-07-09 13:58:47 UTC (rev 1346)
+++ GNUnet/src/server/connection.c      2005-07-09 14:05:10 UTC (rev 1347)
@@ -1121,7 +1121,7 @@
     }
   }
 
-  perm = permute(be->sendBufferSize);
+  perm = permute(WEAK, be->sendBufferSize);
   /* change permutation such that SE_FLAGS
      are obeyed */
   headpos = 0;
@@ -1847,7 +1847,7 @@
     schedulableBandwidth -= decrementSB;
     if ( (activePeerCount > 0) &&
         (didAssign == NO) ) {
-      int * perm = permute(activePeerCount);
+      int * perm = permute(WEAK, activePeerCount);
       /* assign also to random "worthless" (zero-share) peers */
       for (u=0;u<activePeerCount;u++) {
        unsigned int v = perm[u]; /* use perm to avoid preference to 
low-numbered slots */
@@ -1866,7 +1866,7 @@
       if ( (schedulableBandwidth > 0) &&
           (activePeerCount > 0) ) {
        /* assign rest disregarding traffic limits */
-       perm = permute(activePeerCount);
+       perm = permute(WEAK, activePeerCount);
        for (u=0;u<activePeerCount;u++)
          entries[perm[u]]->idealized_limit 
            += (unsigned int) (schedulableBandwidth/activePeerCount);   

Modified: GNUnet/src/util/random.c
===================================================================
--- GNUnet/src/util/random.c    2005-07-09 13:58:47 UTC (rev 1346)
+++ GNUnet/src/util/random.c    2005-07-09 14:05:10 UTC (rev 1347)
@@ -71,20 +71,26 @@
 }
 
 /**
- * Get an array with a random permutation of the numbers 0...n-1.
+ * Get an array with a random permutation of the
+ * numbers 0...n-1.
+ * @param mode STRONG if the strong (but expensive) PRNG should be used, WEAK 
otherwise
+ * @param n the size of the array
+ * @return the permutation array (allocated from heap)
  */
-int * permute(int n) {
+int * permute(int mode, int n) {
   int * ret;
   int i;
   int tmp;
   unsigned int x;
+  unsigned int (*prng) (unsigned int u);
 
   GNUNET_ASSERT(n>0);
   ret = (int*)MALLOC(n * sizeof(int));
+  prng = (mode == STRONG) ? randomi : weak_randomi;
   for (i=0;i<n;i++)
     ret[i] = i;
   for (i=0;i<n;i++) {
-    x = randomi(n);
+    x = prng(n);
     tmp = ret[x];
     ret[x] = ret[i];
     ret[i] = tmp;





reply via email to

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