move to config instead of hard-coding for testing
authorChristian Grothoff <christian@grothoff.org>
Sun, 24 Jul 2011 11:43:32 +0000 (11:43 +0000)
committerChristian Grothoff <christian@grothoff.org>
Sun, 24 Jul 2011 11:43:32 +0000 (11:43 +0000)
contrib/defaults.conf
src/nse/gnunet-service-nse.c
src/nse/test_nse.conf
src/transport/test_quota_compliance_tcp_peer1.conf
src/util/crypto_aes.c

index 639c30f6a41b22f14df481373973a3552c0b8c6f..2461fb54ee55f7fa716102b4d73c1ce01cd0d4a7 100644 (file)
@@ -433,6 +433,15 @@ UNIX_MATCH_UID = YES
 UNIX_MATCH_GID = YES
 PROOFFILE = $SERVICEHOME/.nse-proof
 
+# How 'slowly' should the proof-of-work be constructed (delay
+# between rounds in ms); sane values between 0 and ~1000.
+WORKDELAY = 5
+
+# Note: changing any of the values below will make this peer
+# completely incompatible with other peers! 
+INTERVAL = 3600000
+WORKBITS = 20
+
 
 [vpn]
 CONFIG = $DEFAULTCONFIG
index ad7a0bef1c84777266e7a4ff3bfa9a18694627f7..4c0dae0e13cd923211c28cbe8dc4da8d2ba008a7 100644 (file)
 /**
  * Amount of work required (W-bit collisions) for NSE proofs, in collision-bits.
  */
-#define NSE_WORK_REQUIRED 8
+static unsigned long long nse_work_required;
 
 /**
  * Interval for sending network size estimation flood requests.
  */
-#define GNUNET_NSE_INTERVAL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
+static struct GNUNET_TIME_Relative gnunet_nse_interval;
 
 /**
  * Interval between proof find runs.
  */
-#define PROOF_FIND_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 5)
+static struct GNUNET_TIME_Relative proof_find_delay;
 
 
 /**
@@ -360,11 +360,11 @@ get_matching_bits_delay (uint32_t matching_bits)
 {
   /* Calculated as: S + f/2 - (f / pi) * (atan(x - p'))*/  
   // S is next_timestamp (ignored in return value)
-  // f is frequency (GNUNET_NSE_INTERVAL)
+  // f is frequency (gnunet_nse_interval)
   // x is matching_bits
   // p' is current_size_estimate
-  return ((double) GNUNET_NSE_INTERVAL.rel_value / (double) 2.0)
-    - ((GNUNET_NSE_INTERVAL.rel_value / M_PI) * atan (matching_bits - current_size_estimate));
+  return ((double) gnunet_nse_interval.rel_value / (double) 2.0)
+    - ((gnunet_nse_interval.rel_value / M_PI) * atan (matching_bits - current_size_estimate));
 }
 
 
@@ -673,7 +673,7 @@ update_flood_message(void *cls,
     }
   current_timestamp = next_timestamp;
   next_timestamp = GNUNET_TIME_absolute_add (current_timestamp,
-                                            GNUNET_NSE_INTERVAL);
+                                            gnunet_nse_interval);
   estimate_index = (estimate_index + 1) % HISTORY_SIZE;
   if (estimate_count < HISTORY_SIZE)
     estimate_count++;
@@ -741,7 +741,7 @@ check_proof_of_work(const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *pkey,
          pkey, 
          sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
   GNUNET_CRYPTO_hash (buf, sizeof (buf), &result);
-  return (count_leading_zeroes (&result) >= NSE_WORK_REQUIRED) ? GNUNET_YES : GNUNET_NO;
+  return (count_leading_zeroes (&result) >= nse_work_required) ? GNUNET_YES : GNUNET_NO;
 }
 
 
@@ -799,7 +799,7 @@ find_proof (void *cls,
              &counter, 
              sizeof(uint64_t));
       GNUNET_CRYPTO_hash (buf, sizeof (buf), &result);
-      if (NSE_WORK_REQUIRED <= count_leading_zeroes(&result))
+      if (nse_work_required <= count_leading_zeroes(&result))
        {
          my_proof = counter;
          GNUNET_log (GNUNET_ERROR_TYPE_INFO,
@@ -834,7 +834,7 @@ find_proof (void *cls,
     {
       my_proof = counter;
     }
-  proof_task = GNUNET_SCHEDULER_add_delayed (PROOF_FIND_DELAY,
+  proof_task = GNUNET_SCHEDULER_add_delayed (proof_find_delay,
                                             &find_proof,
                                             NULL);
 }
@@ -979,9 +979,9 @@ handle_p2p_size_estimate(void *cls,
   ts = GNUNET_TIME_absolute_ntoh (incoming_flood->timestamp);
   if (ts.abs_value == current_timestamp.abs_value)
     idx = estimate_index;
-  else if (ts.abs_value == current_timestamp.abs_value - GNUNET_NSE_INTERVAL.rel_value)
+  else if (ts.abs_value == current_timestamp.abs_value - gnunet_nse_interval.rel_value)
     idx = (estimate_index + HISTORY_SIZE - 1) % HISTORY_SIZE;
-  else if (ts.abs_value == next_timestamp.abs_value - GNUNET_NSE_INTERVAL.rel_value)
+  else if (ts.abs_value == next_timestamp.abs_value - gnunet_nse_interval.rel_value)
     {
       if (matching_bits <= ntohl (next_message.matching_bits))
        return GNUNET_OK; /* ignore, simply too early */      
@@ -1212,12 +1212,12 @@ core_init (void *cls, struct GNUNET_CORE_Handle *server,
     }
   GNUNET_assert (0 == memcmp (&my_identity, identity, sizeof (struct GNUNET_PeerIdentity)));
   now = GNUNET_TIME_absolute_get ();
-  current_timestamp.abs_value = (now.abs_value / GNUNET_NSE_INTERVAL.rel_value) * GNUNET_NSE_INTERVAL.rel_value;
-  next_timestamp.abs_value = current_timestamp.abs_value + GNUNET_NSE_INTERVAL.rel_value;
+  current_timestamp.abs_value = (now.abs_value / gnunet_nse_interval.rel_value) * gnunet_nse_interval.rel_value;
+  next_timestamp.abs_value = current_timestamp.abs_value + gnunet_nse_interval.rel_value;
   
   for (i=0;i<HISTORY_SIZE;i++)
     {
-      prev_time.abs_value = current_timestamp.abs_value - (HISTORY_SIZE - i - 1) * GNUNET_NSE_INTERVAL.rel_value;
+      prev_time.abs_value = current_timestamp.abs_value - (HISTORY_SIZE - i - 1) * gnunet_nse_interval.rel_value;
       setup_flood_message (i, prev_time);
     }
   estimate_index = HISTORY_SIZE - 1;
@@ -1253,6 +1253,34 @@ run(void *cls, struct GNUNET_SERVER_Handle *server,
       { NULL, 0, 0 } 
     };
   cfg = c;
+
+  if ( (GNUNET_OK != 
+       GNUNET_CONFIGURATION_get_value_time (cfg,
+                                            "NSE", "INTERVAL",
+                                            &gnunet_nse_interval)) ||
+       (GNUNET_OK != 
+       GNUNET_CONFIGURATION_get_value_time (cfg,
+                                            "NSE", "WORKDELAY",
+                                            &proof_find_delay)) ||
+       (GNUNET_OK != 
+       GNUNET_CONFIGURATION_get_value_number (cfg,
+                                              "NSE", "WORKBITS",
+                                              &nse_work_required)) )       
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 
+                 _ ("NSE service is lacking key configuration settings.  Exiting.\n"));
+      GNUNET_SCHEDULER_shutdown ();
+      return;
+    }
+  if (nse_work_required >= sizeof (GNUNET_HashCode) * 8)
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 
+                 _ ("Invalid work requirement for NSE service. Exiting.\n"));
+      GNUNET_SCHEDULER_shutdown ();
+      return;
+    }
+
+
   if (GNUNET_OK != 
       GNUNET_CONFIGURATION_get_value_filename (cfg,
                                               "GNUNETD", "HOSTKEY",
index ee3c208a25754e945df90899ae945c8cdaf21616..35adc0cad3b9e9ef56f1bbe994fc1dab5a1fb932 100644 (file)
@@ -12,6 +12,14 @@ AUTOSTART = YES
 DEBUG = YES
 CONFIG = $DEFAULTCONFIG
 
+# Overriding network settings for faster testing (do NOT use
+# these values in production just because they are here)
+WORKDELAY = 1
+INTERVAL = 15000
+WORKBITS = 8
+
+
+
 [arm]
 PORT = 22354
 DEFAULTSERVICES = nse core
@@ -49,7 +57,7 @@ EXTERNAL_ADDRESS = 127.0.0.1
 AUTOSTART = NO
 
 [testing]
-NUM_PEERS = 100
+NUM_PEERS = 10
 WEAKRANDOM = YES
 TOPOLOGY = NONE
 CONNECT_TOPOLOGY = SMALL_WORLD_RING
index c09d11211880eb6e88fbe5e43894ac1685d69bfa..a8ea8a11c687afd8b777202c6142846d53d9d204 100644 (file)
@@ -36,7 +36,6 @@ PORT = 4094
 [transport-tcp]
 TIMEOUT = 300000
 PORT = 4094
-USE_LOCALADDR = YES
 
 [nat]
 DISABLEV6 = YES
index 1ab4a7301a87526a655476e22cdb0f50c06af5e9..e26b59abe4355271d956705ddc51710f2a68e837 100644 (file)
@@ -56,7 +56,7 @@ GNUNET_CRYPTO_aes_check_session_key (const struct GNUNET_CRYPTO_AesSessionKey
   crc = GNUNET_CRYPTO_crc32_n (key, GNUNET_CRYPTO_AES_KEY_LENGTH);
   if (ntohl (key->crc32) == crc)
     return GNUNET_OK;
-  GNUNET_break (0);
+  GNUNET_break_op (0);
   return GNUNET_SYSERR;
 }