gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r2354 - in GNUnet/src: applications/advertising application


From: grothoff
Subject: [GNUnet-SVN] r2354 - in GNUnet/src: applications/advertising applications/bootstrap_http applications/dht/module applications/fragmentation applications/fs/fsui applications/fs/module applications/gap applications/identity applications/tbench applications/topology_default applications/topology_f2f include util
Date: Mon, 19 Dec 2005 12:09:07 -0800 (PST)

Author: grothoff
Date: 2005-12-19 12:09:01 -0800 (Mon, 19 Dec 2005)
New Revision: 2354

Modified:
   GNUnet/src/applications/advertising/advertising.c
   GNUnet/src/applications/advertising/bootstrap.c
   GNUnet/src/applications/bootstrap_http/http.c
   GNUnet/src/applications/dht/module/dht.c
   GNUnet/src/applications/fragmentation/fragmentation.c
   GNUnet/src/applications/fs/fsui/downloadtest.c
   GNUnet/src/applications/fs/module/fs.c
   GNUnet/src/applications/gap/gap.c
   GNUnet/src/applications/identity/identity.c
   GNUnet/src/applications/tbench/tbench.c
   GNUnet/src/applications/topology_default/topology.c
   GNUnet/src/applications/topology_f2f/topology.c
   GNUnet/src/include/gnunet_util.h
   GNUnet/src/util/random.c
Log:
more weak

Modified: GNUnet/src/applications/advertising/advertising.c
===================================================================
--- GNUnet/src/applications/advertising/advertising.c   2005-12-19 19:59:52 UTC 
(rev 2353)
+++ GNUnet/src/applications/advertising/advertising.c   2005-12-19 20:09:01 UTC 
(rev 2354)
@@ -348,7 +348,7 @@
     return;
   if (proto == NAT_PROTOCOL_NUMBER)
     return; /* don't advertise NAT addresses via broadcast */
-  if (randomi(sd->n) != 0)
+  if (weak_randomi(sd->n) != 0)
     return;
   hash2enc(&hi->hashPubKey,
           &other);
@@ -379,7 +379,7 @@
      we get a probability of 1/n for this, which
      is what we want: fewer attempts to contact fresh
      peers as the network grows): */
-  if (randomi(sd->n) != 0)
+  if (weak_randomi(sd->n) != 0)
     return;
 
   /* establish short-lived connection, send, tear down */
@@ -432,7 +432,7 @@
 
   if (getNetworkLoadUp() > 100)
     return; /* network load too high... */
-  if (0 != randomi(*prob))
+  if (0 != weak_randomi(*prob))
     return; /* ignore */
 #if DEBUG_ADVERTISING
   LOG(LOG_CRON,
@@ -498,7 +498,7 @@
                            FCC * fcc) {
   if (getNetworkLoadUp() > 100)
     return; /* network load too high... */
-  if (randomi(fcc->prob) != 0)
+  if (weak_randomi(fcc->prob) != 0)
     return; /* only forward with a certain chance */
   if (equalsHashCode512(&peer->hashPubKey,
                        &fcc->msg->senderIdentity.hashPubKey))
@@ -532,7 +532,7 @@
     return;
   if (protocol == NAT_PROTOCOL_NUMBER)
     return; /* don't forward NAT addresses */
-  if (randomi((*probability)+1) != 0)
+  if (weak_randomi((*probability)+1) != 0)
     return; /* only forward with a certain chance,
               (on average: 1 peer per run!) */
 #if DEBUG_ADVERTISING

Modified: GNUnet/src/applications/advertising/bootstrap.c
===================================================================
--- GNUnet/src/applications/advertising/bootstrap.c     2005-12-19 19:59:52 UTC 
(rev 2353)
+++ GNUnet/src/applications/advertising/bootstrap.c     2005-12-19 20:09:01 UTC 
(rev 2354)
@@ -62,7 +62,7 @@
   while ( (abort_bootstrap == NO) &&
          (hcq->helosCount > 0) ) {
     /* select hello by random */
-    rndidx = randomi(hcq->helosCount);
+    rndidx = weak_randomi(hcq->helosCount);
 #if DEBUG_BOOTSTRAP
     LOG(LOG_DEBUG,
        "%s chose hello %d of %d\n",
@@ -97,7 +97,7 @@
       if (load > 100)
        load = 100;
 
-      gnunet_util_sleep(50 + randomi((load+1)*(load+1)));
+      gnunet_util_sleep(50 + weak_randomi((load+1)*(load+1)));
     }
   }
   for (i=0;i<hcq->helosCount;i++)

Modified: GNUnet/src/applications/bootstrap_http/http.c
===================================================================
--- GNUnet/src/applications/bootstrap_http/http.c       2005-12-19 19:59:52 UTC 
(rev 2353)
+++ GNUnet/src/applications/bootstrap_http/http.c       2005-12-19 20:09:01 UTC 
(rev 2354)
@@ -291,7 +291,7 @@
     if (url[i] == ' ')
       cnt++;
   }
-  cnt = randomi(cnt); /* pick random hostlist of the pack */
+  cnt = weak_randomi(cnt); /* pick random hostlist of the pack */
   i = strlen(url);
   while (i > 0) {
     i--;

Modified: GNUnet/src/applications/dht/module/dht.c
===================================================================
--- GNUnet/src/applications/dht/module/dht.c    2005-12-19 19:59:52 UTC (rev 
2353)
+++ GNUnet/src/applications/dht/module/dht.c    2005-12-19 20:09:01 UTC (rev 
2354)
@@ -1065,8 +1065,8 @@
      if greater than 1k, only add with exponentially
      decreasing probability */
   if ( (s < 1024) ||
-       ( (s*s < randomi(32768)*randomi(32768)) &&
-        (s*s < randomi(32768)*randomi(32768)) ) ) {
+       ( (s*s < weak_randomi(32768)*weak_randomi(32768)) &&
+        (s*s < weak_randomi(32768)*weak_randomi(32768)) ) ) {
     RPC_paramAdd(args,
                 "tables",
                 sizeof(DHT_TableId) * tc,

Modified: GNUnet/src/applications/fragmentation/fragmentation.c
===================================================================
--- GNUnet/src/applications/fragmentation/fragmentation.c       2005-12-19 
19:59:52 UTC (rev 2353)
+++ GNUnet/src/applications/fragmentation/fragmentation.c       2005-12-19 
20:09:01 UTC (rev 2354)
@@ -458,7 +458,7 @@
   }
   if (stats != NULL)
     stats->change(stat_fragmented, 1);
-  id = (idGen++) + randomi(512);
+  id = (idGen++) + weak_randomi(512);
   /* write first fragment to buf */
   frag = (P2P_fragmentation_MESSAGE*) buf;
   frag->header.size = htons(len);

Modified: GNUnet/src/applications/fs/fsui/downloadtest.c
===================================================================
--- GNUnet/src/applications/fs/fsui/downloadtest.c      2005-12-19 19:59:52 UTC 
(rev 2353)
+++ GNUnet/src/applications/fs/fsui/downloadtest.c      2005-12-19 20:09:01 UTC 
(rev 2354)
@@ -249,7 +249,7 @@
     CHECK(prog < 10000);
     gnunet_util_sleep(50 * cronMILLIS);
     if ( (suspendRestart > 0) &&
-        (randomi(4) == 0) ) {
+        (weak_randomi(4) == 0) ) {
       suspendCron();
 #if 1
 #if DEBUG_VERBOSE

Modified: GNUnet/src/applications/fs/module/fs.c
===================================================================
--- GNUnet/src/applications/fs/module/fs.c      2005-12-19 19:59:52 UTC (rev 
2353)
+++ GNUnet/src/applications/fs/module/fs.c      2005-12-19 20:09:01 UTC (rev 
2354)
@@ -326,7 +326,7 @@
       et -= now;
       et = et % MAX_MIGRATION_EXP;
       if (et > 0)
-       et = randomi(et);
+       et = weak_randomi(et);
       et = et + now;
     }
     gw->timeout = htonll(et);
@@ -685,7 +685,7 @@
     et -= now;
     et = et % MAX_MIGRATION_EXP;
     if (et > 0)
-      et = randomi(et);
+      et = weak_randomi(et);
     et = et + now;
   }
   gw->timeout = htonll(et);
@@ -847,7 +847,7 @@
     et -= now;
     et = et % MAX_MIGRATION_EXP;
     if (et > 0)
-      et = randomi(et);
+      et = weak_randomi(et);
     et = et + now;
   }
   gw->timeout = htonll(et);

Modified: GNUnet/src/applications/gap/gap.c
===================================================================
--- GNUnet/src/applications/gap/gap.c   2005-12-19 19:59:52 UTC (rev 2353)
+++ GNUnet/src/applications/gap/gap.c   2005-12-19 20:09:01 UTC (rev 2354)
@@ -792,8 +792,8 @@
                          &id->hashPubKey);
   if (distance <= 0)
     distance = 1;
-  ranking += 0xFFFF / (1 + randomi(distance));
-  ranking += 1 + randomi(0xFF); /* small random chance for everyone */
+  ranking += 0xFFFF / (1 + weak_randomi(distance));
+  ranking += 1 + weak_randomi(0xFF); /* small random chance for everyone */
   if (equalsHashCode512(&id->hashPubKey,
                        &qr->noTarget.hashPubKey))
     ranking = 0; /* no chance for blocked peers */
@@ -876,7 +876,7 @@
         Replace existing query! */
       oldestIndex = i;
       if ( (queries[i].expires > now - 4 * TTL_DECREMENT) && /* not long 
expired */
-          (randomi(4) != 0) ) {
+          (weak_randomi(4) != 0) ) {
        /* do not clear the bitmap describing which peers we have
           forwarded the query to already; but do this only with high
           probability since we may want to try again if the query is
@@ -943,7 +943,7 @@
 
        if (rankingSum == 0)
          break;
-       sel = randomi64(rankingSum);
+       sel = weak_randomi64(rankingSum);
        pos = 0;        
        for (j=0;j<8*BITMAP_SIZE;j++) {
          pos += qr->rankings[j];
@@ -1101,7 +1101,7 @@
   /* delay reply, delay longer if we are busy (makes it harder
      to predict / analyze, too). */
   addCronJob(&useContentLater,
-            randomi(TTL_DECREMENT),
+            weak_randomi(TTL_DECREMENT),
             0,
             pmsg);
 }
@@ -1455,7 +1455,7 @@
     *doForward = YES;
     return 17;
   }
-  if (randomi(TIE_BREAKER_CHANCE) == 0) {
+  if (weak_randomi(TIE_BREAKER_CHANCE) == 0) {
     addToSlot(ITE_REPLACE, ite, query, ttl, priority, sender);
     *isRouted = YES;
     *doForward = YES;
@@ -2079,13 +2079,13 @@
   /* decrement ttl (always) */
   ttl = ntohl(qmsg->ttl);
   if (ttl < 0) {
-    ttl = ttl - 2*TTL_DECREMENT - randomi(TTL_DECREMENT);
+    ttl = ttl - 2*TTL_DECREMENT - weak_randomi(TTL_DECREMENT);
     if (ttl > 0) {
       FREE(qmsg);
       return OK; /* just abort */
     }
   } else {
-    ttl = ttl - 2*TTL_DECREMENT - randomi(TTL_DECREMENT);
+    ttl = ttl - 2*TTL_DECREMENT - weak_randomi(TTL_DECREMENT);
   }
   prio = ntohl(qmsg->priority);
   policy = evaluateQuery(sender,
@@ -2189,7 +2189,7 @@
     LOG(LOG_WARNING,
        _("Traffic service failed to load; gap cannot ensure cover-traffic 
availability.\n"));
   }
-  random_qsel = randomi(0xFFFF);
+  random_qsel = weak_randomi(0xFFFF);
   indirectionTableSize =
     getConfigurationInt("GAP",
                        "TABLESIZE");

Modified: GNUnet/src/applications/identity/identity.c
===================================================================
--- GNUnet/src/applications/identity/identity.c 2005-12-19 19:59:52 UTC (rev 
2353)
+++ GNUnet/src/applications/identity/identity.c 2005-12-19 20:09:01 UTC (rev 
2354)
@@ -749,9 +749,9 @@
     entry->delta = 1 * cronDAYS;
   } else {
     entry->delta
-      = entry->delta * 2 + randomi((desperation+1)*cronSECONDS);
+      = entry->delta * 2 + weak_randomi((desperation+1)*cronSECONDS);
     if (entry->delta > 4 * cronHOURS)
-      entry->delta = 4 *  randomi(cronHOURS * (desperation+1));
+      entry->delta = 4 *  weak_randomi(cronHOURS * (desperation+1));
   }
   cronTime(&entry->until);
   entry->until += entry->delta;

Modified: GNUnet/src/applications/tbench/tbench.c
===================================================================
--- GNUnet/src/applications/tbench/tbench.c     2005-12-19 19:59:52 UTC (rev 
2353)
+++ GNUnet/src/applications/tbench/tbench.c     2005-12-19 20:09:01 UTC (rev 
2354)
@@ -288,14 +288,14 @@
     earlyEnd = 0;
     presem = SEMAPHORE_NEW(1);
     postsem = SEMAPHORE_NEW(0);
-    currNounce = randomi(0xFFFFFF);
+    currNounce = weak_randomi(0xFFFFFF);
     p2p->nounce
       = htonl(currNounce);
     currIteration = iteration;
     p2p->iterationNum
       = htonl(currIteration);
     memset(&p2p[1],
-          randomi(256),
+          weak_randomi(256),
           size - sizeof(P2P_tbench_MESSAGE));
     p2p->crc
       = htonl(crc32N(&p2p[1],

Modified: GNUnet/src/applications/topology_default/topology.c
===================================================================
--- GNUnet/src/applications/topology_default/topology.c 2005-12-19 19:59:52 UTC 
(rev 2353)
+++ GNUnet/src/applications/topology_default/topology.c 2005-12-19 20:09:01 UTC 
(rev 2354)
@@ -181,7 +181,7 @@
   }
   if (indexMatch.costSelector > 0)
     indexMatch.costSelector
-      = randomi(indexMatch.costSelector/4)*4;
+      = weak_randomi(indexMatch.costSelector/4)*4;
   indexMatch.match = *(coreAPI->myIdentity);
   identity->forEachHost(now,
                        &scanHelperSelect,

Modified: GNUnet/src/applications/topology_f2f/topology.c
===================================================================
--- GNUnet/src/applications/topology_f2f/topology.c     2005-12-19 19:59:52 UTC 
(rev 2353)
+++ GNUnet/src/applications/topology_f2f/topology.c     2005-12-19 20:09:01 UTC 
(rev 2354)
@@ -177,7 +177,7 @@
     return; /* no matching peers found! */
   if (indexMatch.costSelector > 0)
     indexMatch.costSelector
-      = randomi(indexMatch.costSelector/4)*4;
+      = weak_randomi(indexMatch.costSelector/4)*4;
   indexMatch.match = *(coreAPI->myIdentity);
   identity->forEachHost(now,
                        (HostIterator)&scanHelperSelect,

Modified: GNUnet/src/include/gnunet_util.h
===================================================================
--- GNUnet/src/include/gnunet_util.h    2005-12-19 19:59:52 UTC (rev 2353)
+++ GNUnet/src/include/gnunet_util.h    2005-12-19 20:09:01 UTC (rev 2354)
@@ -568,6 +568,8 @@
  */
 unsigned long long randomi64(unsigned long long u);
 
+unsigned long long weak_randomi64(unsigned long long u);
+
 /**
  * Get an array with a random permutation of the
  * numbers 0...n-1.

Modified: GNUnet/src/util/random.c
===================================================================
--- GNUnet/src/util/random.c    2005-12-19 19:59:52 UTC (rev 2353)
+++ GNUnet/src/util/random.c    2005-12-19 20:09:01 UTC (rev 2354)
@@ -104,6 +104,7 @@
 unsigned long long randomi64(unsigned long long u) {
   unsigned long long ret;
 
+  GNUNET_ASSERT(u > 0);
   lockGcrypt();
   gcry_randomize((unsigned char *) &ret,
                 sizeof(unsigned long long),
@@ -127,4 +128,13 @@
        return ret;
 }
 
+unsigned long long weak_randomi64(unsigned long long u) {
+       unsigned long long ret;
+       GNUNET_ASSERT(u > 0);
+       ret = u * ((double) RANDOM() / RAND_MAX);
+       if (ret >= u)
+               ret = u-1;
+       return ret;
+}
+
 /* end of random.c */





reply via email to

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