[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r1143 - in GNUnet/src: applications/topology_default applic
From: |
durner |
Subject: |
[GNUnet-SVN] r1143 - in GNUnet/src: applications/topology_default applications/topology_f2f include util |
Date: |
Wed, 29 Jun 2005 12:40:54 -0700 (PDT) |
Author: durner
Date: 2005-06-29 12:40:45 -0700 (Wed, 29 Jun 2005)
New Revision: 1143
Added:
GNUnet/src/util/random.c
Removed:
GNUnet/src/util/random_gcrypt.c
Modified:
GNUnet/src/applications/topology_default/topology.c
GNUnet/src/applications/topology_f2f/topology.c
GNUnet/src/include/gnunet_util.h
GNUnet/src/util/Makefile.am
Log:
weak_randomi()
Modified: GNUnet/src/applications/topology_default/topology.c
===================================================================
--- GNUnet/src/applications/topology_default/topology.c 2005-06-29 16:42:33 UTC
(rev 1142)
+++ GNUnet/src/applications/topology_default/topology.c 2005-06-29 19:40:45 UTC
(rev 1143)
@@ -52,16 +52,16 @@
#define LIVE_SCAN_FREQUENCY 500 * cronMILLIS
/**
- * Value < 1 that determines the chance (1:(1/LSE)) that the cron job
+ * Value > 1 that determines the chance (1:LSE) that the cron job
* actually tries to do something for a given slot.
*/
-#define LIVE_SCAN_EFFECTIVENESS 0.1
+#define LIVE_SCAN_EFFECTIVENESS 10
/**
- * Value < 1 that determines the chance (1:(1/LPE)) that the cron job
+ * Value < 1 that determines the chance (1:LPE) that the cron job
* actually tries to ping a peer that is about to time-out.
*/
-#define LIVE_PING_EFFECTIVENESS 0.05
+#define LIVE_PING_EFFECTIVENESS 20
static CoreAPIForApplication * coreAPI;
@@ -260,7 +260,7 @@
if (minint == 0)
minint = 1;
for (i=slotCount-1;i>=0;i--) {
- if (((double) RANDOM() / RAND_MAX) > LIVE_SCAN_EFFECTIVENESS)
+ if (weak_randomi(LIVE_SCAN_EFFECTIVENESS) != 0)
continue;
if ( (minint > coreAPI->isSlotUsed(i)) &&
(! testConfigurationString("GNUNETD",
@@ -268,7 +268,7 @@
"YES")) )
scanForHosts(i);
}
- if (((double) RANDOM() / RAND_MAX) <= LIVE_PING_EFFECTIVENESS)
+ if (weak_randomi(LIVE_PING_EFFECTIVENESS) == 0)
active = coreAPI->forAllConnectedNodes
(&checkNeedForPing,
NULL);
Modified: GNUnet/src/applications/topology_f2f/topology.c
===================================================================
--- GNUnet/src/applications/topology_f2f/topology.c 2005-06-29 16:42:33 UTC
(rev 1142)
+++ GNUnet/src/applications/topology_f2f/topology.c 2005-06-29 19:40:45 UTC
(rev 1143)
@@ -256,14 +256,14 @@
if (minint == 0)
minint = 1;
for (i=slotCount-1;i>=0;i--) {
- if (randomi(LIVE_SCAN_EFFECTIVENESS) != 0)
+ if (weak_randomi(LIVE_SCAN_EFFECTIVENESS) != 0)
continue;
if ( (minint > coreAPI->isSlotUsed(i)) &&
(0 == coreAPI->isSlotUsed(i)) )
scanForHosts(i);
}
- if (randomi(LIVE_SCAN_EFFECTIVENESS) == 0)
+ if (weak_randomi(LIVE_SCAN_EFFECTIVENESS) == 0)
active = coreAPI->forAllConnectedNodes
(&checkNeedForPing,
NULL);
Modified: GNUnet/src/include/gnunet_util.h
===================================================================
--- GNUnet/src/include/gnunet_util.h 2005-06-29 16:42:33 UTC (rev 1142)
+++ GNUnet/src/include/gnunet_util.h 2005-06-29 19:40:45 UTC (rev 1143)
@@ -557,6 +557,14 @@
int * permute(int n);
/**
+ * Produce a cryptographically weak random value.
+ *
+ * @param i the upper limit (exclusive) for the random number
+ * @return a random value in the interval [0,i[.
+ */
+unsigned int weak_randomi(unsigned int i);
+
+/**
* Convert a long-long to host-byte-order.
* @param n the value in network byte order
* @return the same value in host byte order
Modified: GNUnet/src/util/Makefile.am
===================================================================
--- GNUnet/src/util/Makefile.am 2005-06-29 16:42:33 UTC (rev 1142)
+++ GNUnet/src/util/Makefile.am 2005-06-29 19:40:45 UTC (rev 1143)
@@ -74,7 +74,7 @@
logging.c \
printhelp.c \
port.c \
- random_gcrypt.c \
+ random.c \
semaphore.c \
shutdown.c \
state.c \
Copied: GNUnet/src/util/random.c (from rev 1120,
GNUnet/src/util/random_gcrypt.c)
===================================================================
--- GNUnet/src/util/random_gcrypt.c 2005-06-28 20:33:49 UTC (rev 1120)
+++ GNUnet/src/util/random.c 2005-06-29 19:40:45 UTC (rev 1143)
@@ -0,0 +1,128 @@
+/*
+ This file is part of GNUnet.
+ (C) 2001, 2002, 2003, 2004, 2005 Christian Grothoff (and other
contributing authors)
+
+ GNUnet is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 2, or (at your
+ option) any later version.
+
+ GNUnet is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GNUnet; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+*/
+
+/**
+ * @file util/random.c
+ * @brief functions to gather random numbers
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "gnunet_util.h"
+#include "locking_gcrypt.h"
+#include <gcrypt.h>
+
+/**
+ * Initialize Random number generator.
+ */
+void initRAND() {
+ gcry_control(GCRYCTL_DISABLE_SECMEM, 0);
+ if (! gcry_check_version(GCRYPT_VERSION))
+ errexit(_("libgcrypt has not the expected version (version %s is
required).\n"),
+ GCRYPT_VERSION);
+ srand((unsigned int)time(NULL));
+ lockGcrypt();
+#ifdef gcry_fast_random_poll
+ gcry_fast_random_poll ();
+#endif
+ unlockGcrypt();
+}
+
+/**
+ * @return a random value in the interval [0,i[.
+ */
+unsigned int randomi(unsigned int i) {
+ static unsigned int invokeCount;
+ unsigned int ret;
+
+ lockGcrypt();
+ /* see http://lists.gnupg.org/pipermail/gcrypt-devel/2004-May/000613.html */
+ if ( (invokeCount++ % 256) == 0) {
+#ifdef gcry_fast_random_poll
+ gcry_fast_random_poll ();
+#endif
+ }
+ GNUNET_ASSERT(i > 0);
+ ret = rand();
+ gcry_randomize((unsigned char*)&ret,
+ sizeof(unsigned int),
+ GCRY_STRONG_RANDOM);
+ unlockGcrypt();
+ ret = ret % i;
+ GNUNET_ASSERT((ret >= 0) && (ret < i));
+ return ret;
+}
+
+/**
+ * Get an array with a random permutation of the numbers 0...n-1.
+ */
+int * permute(int n) {
+ int * ret;
+ int i;
+ int tmp;
+ unsigned int x;
+
+ GNUNET_ASSERT(n>0);
+ ret = (int*)MALLOC(n * sizeof(int));
+ for (i=0;i<n;i++)
+ ret[i] = i;
+ for (i=0;i<n;i++) {
+ x = randomi(n);
+ tmp = ret[x];
+ ret[x] = ret[i];
+ ret[i] = tmp;
+ }
+ return ret;
+}
+
+/**
+ * Random on unsigned 64-bit values.
+ */
+unsigned long long randomi64(unsigned long long u) {
+ unsigned long long ret;
+
+ lockGcrypt();
+ gcry_randomize((unsigned char *) &ret,
+ sizeof(unsigned long long),
+ GCRY_STRONG_RANDOM);
+ unlockGcrypt();
+ return ret % u;
+}
+
+/**
+ * @return a cryptographically weak random value in the interval [0,i[.
+ */
+unsigned int weak_randomi(unsigned int i) {
+ unsigned int ret;
+fprintf(stderr, "radnom\n");
+fflush(NULL);
+ GNUNET_ASSERT(i > 0);
+
+ ret = i * ((double) RANDOM() / RAND_MAX);
+
+ if (ret >= i)
+ ret = i;
+fflush(NULL);
+fprintf(stderr, "ret %i\n", ret);
+
+ return ret;
+}
+
+/* end of random.c */
Deleted: GNUnet/src/util/random_gcrypt.c
===================================================================
--- GNUnet/src/util/random_gcrypt.c 2005-06-29 16:42:33 UTC (rev 1142)
+++ GNUnet/src/util/random_gcrypt.c 2005-06-29 19:40:45 UTC (rev 1143)
@@ -1,108 +0,0 @@
-/*
- This file is part of GNUnet.
- (C) 2001, 2002, 2003, 2004 Christian Grothoff (and other contributing
authors)
-
- GNUnet is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published
- by the Free Software Foundation; either version 2, or (at your
- option) any later version.
-
- GNUnet is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with GNUnet; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
-
-*/
-
-/**
- * @file util/random_gcrypt.c
- * @brief functions to gather random numbers
- * @author Christian Grothoff
- */
-#include "platform.h"
-#include "gnunet_util.h"
-#include "locking_gcrypt.h"
-#include <gcrypt.h>
-
-/**
- * Initialize Random number generator.
- */
-void initRAND() {
- gcry_control(GCRYCTL_DISABLE_SECMEM, 0);
- if (! gcry_check_version(GCRYPT_VERSION))
- errexit(_("libgcrypt has not the expected version (version %s is
required).\n"),
- GCRYPT_VERSION);
- srand((unsigned int)time(NULL));
- lockGcrypt();
-#ifdef gcry_fast_random_poll
- gcry_fast_random_poll ();
-#endif
- unlockGcrypt();
-}
-
-/**
- * @return a random value in the interval [0,i[.
- */
-unsigned int randomi(unsigned int i) {
- static unsigned int invokeCount;
- unsigned int ret;
-
- lockGcrypt();
- /* see http://lists.gnupg.org/pipermail/gcrypt-devel/2004-May/000613.html */
- if ( (invokeCount++ % 256) == 0) {
-#ifdef gcry_fast_random_poll
- gcry_fast_random_poll ();
-#endif
- }
- GNUNET_ASSERT(i > 0);
- ret = rand();
- gcry_randomize((unsigned char*)&ret,
- sizeof(unsigned int),
- GCRY_STRONG_RANDOM);
- unlockGcrypt();
- ret = ret % i;
- GNUNET_ASSERT((ret >= 0) && (ret < i));
- return ret;
-}
-
-/**
- * Get an array with a random permutation of the numbers 0...n-1.
- */
-int * permute(int n) {
- int * ret;
- int i;
- int tmp;
- unsigned int x;
-
- GNUNET_ASSERT(n>0);
- ret = (int*)MALLOC(n * sizeof(int));
- for (i=0;i<n;i++)
- ret[i] = i;
- for (i=0;i<n;i++) {
- x = randomi(n);
- tmp = ret[x];
- ret[x] = ret[i];
- ret[i] = tmp;
- }
- return ret;
-}
-
-/**
- * Random on unsigned 64-bit values.
- */
-unsigned long long randomi64(unsigned long long u) {
- unsigned long long ret;
-
- lockGcrypt();
- gcry_randomize((unsigned char *) &ret,
- sizeof(unsigned long long),
- GCRY_STRONG_RANDOM);
- unlockGcrypt();
- return ret % u;
-}
-
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r1143 - in GNUnet/src: applications/topology_default applications/topology_f2f include util,
durner <=