sensor: minor fixes
authorOmar Tarabai <tarabai@devegypt.com>
Wed, 17 Sep 2014 19:28:17 +0000 (19:28 +0000)
committerOmar Tarabai <tarabai@devegypt.com>
Wed, 17 Sep 2014 19:28:17 +0000 (19:28 +0000)
src/sensor/gnunet-sensor-profiler.c
src/sensor/gnunet-service-sensor_reporting.c
src/sensor/perf_pow_sign.c
src/sensor/plugin_sensor_model_gaussian.c
src/sensor/profiler.py
src/sensor/sensor_util_lib_crypto.c
src/sensor/test_gnunet-service-sensor_reporting.conf
src/sensor/test_pow_sign.c

index 467c80dee92daaad6154002831b9cf7414e745b8..783c6fd1e881e0d39e094597bdb8e6e353e437d1 100644 (file)
@@ -894,7 +894,7 @@ main (int argc, char *const *argv)
     {'t', "topology-file", "FILEPATH", gettext_noop ("Path to topology file"),
      GNUNET_YES, &GNUNET_GETOPT_set_filename, &topology_file},
     {'i', "sensors-interval", "INTERVAL",
-     gettext_noop ("Change the interval or running sensors to given value"),
+     gettext_noop ("Change the interval of running sensors to given value"),
      GNUNET_YES, &GNUNET_GETOPT_set_uint, &sensors_interval},
     GNUNET_GETOPT_OPTION_END
   };
index 5e0972c5e964b601f644a747b24e1eb61e812b6a..104c669459c39fdae35f7e315743728a54079333 100644 (file)
@@ -658,7 +658,10 @@ report_creation_cb (void *cls, struct GNUNET_SENSOR_crypto_pow_block *block)
     return;
   }
   LOG (GNUNET_ERROR_TYPE_DEBUG, "Anomaly report POW block ready.\n");
-  ai->report_block = block;
+  ai->report_block =
+      GNUNET_memdup (block,
+                     sizeof (struct GNUNET_SENSOR_crypto_pow_block) +
+                     block->msg_size);
   ar_item = ai->reporting_queue_head;
   while (NULL != ar_item)
   {
@@ -706,9 +709,9 @@ update_anomaly_report_pow_block (struct AnomalyInfo *ai)
   arm->anomalous = htons (ai->anomalous);
   arm->anomalous_neighbors =
       (0 ==
-       neighborhood) ? 0 : ((float)
-                            GNUNET_CONTAINER_multipeermap_size
-                            (ai->anomalous_neighbors)) / neighborhood;
+       neighborhood) ? 0 : ((float) GNUNET_CONTAINER_multipeermap_size (ai->
+                                                                        anomalous_neighbors))
+      / neighborhood;
   timestamp = GNUNET_TIME_absolute_get ();
   ai->report_creation_cx =
       GNUNET_SENSOR_crypto_pow_sign (arm,
@@ -717,6 +720,7 @@ update_anomaly_report_pow_block (struct AnomalyInfo *ai)
                                      &timestamp, &mypeerid.public_key,
                                      private_key, pow_matching_bits,
                                      &report_creation_cb, ai);
+  GNUNET_free (arm);
 }
 
 
@@ -800,8 +804,8 @@ handle_anomaly_report (void *cls, const struct GNUNET_PeerIdentity *other,
   my_anomaly_info = get_anomaly_info_by_sensor (sensor);
   GNUNET_assert (NULL != my_anomaly_info);
   peer_in_anomalous_list =
-      GNUNET_CONTAINER_multipeermap_contains
-      (my_anomaly_info->anomalous_neighbors, other);
+      GNUNET_CONTAINER_multipeermap_contains (my_anomaly_info->
+                                              anomalous_neighbors, other);
   peer_anomalous = ntohs (arm->anomalous);
   LOG (GNUNET_ERROR_TYPE_DEBUG,
        "Received an anomaly update from neighbour `%s' (%d).\n",
@@ -820,8 +824,8 @@ handle_anomaly_report (void *cls, const struct GNUNET_PeerIdentity *other,
     if (GNUNET_NO == peer_in_anomalous_list)    /* repeated negative report */
       GNUNET_break_op (0);
     else
-      GNUNET_CONTAINER_multipeermap_remove_all
-          (my_anomaly_info->anomalous_neighbors, other);
+      GNUNET_CONTAINER_multipeermap_remove_all (my_anomaly_info->
+                                                anomalous_neighbors, other);
   }
   /* This is important to create an updated block since the data changed */
   update_anomaly_report_pow_block (my_anomaly_info);
index a99105a82b188c49116fda69b5a836d10a32089d..b553544907f6ceb6e9c784feade994160c495403 100644 (file)
@@ -46,7 +46,7 @@
 /**
  * How many matching bits to end with
  */
-#define MATCHING_BITS_END 50
+#define MATCHING_BITS_END 20
 
 /**
  * How many readings per matching bits value
@@ -106,7 +106,7 @@ static struct GNUNET_TIME_Relative total_duration;
 /**
  * Task creating pow block
  */
-struct GNUNET_SENSOR_crypto_pow_context *pow_task;
+static struct GNUNET_SENSOR_crypto_pow_context *pow_task;
 
 
 /**
index af879ef9347634983118396258a3208b9f5a9e62..fd35ff077e9b5da6f80fccd321409b830c02c3fe 100644 (file)
@@ -135,7 +135,6 @@ sensor_gaussian_model_feed (void *cls, double val)
   if (stddev < 0)               /* Value can be slightly less than 0 due to rounding errors */
     stddev = 0;
   stddev = sqrt (stddev);
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "Mean: %Lf, Stddev: %Lf\n", mean, stddev);
   allowed_variance = (plugin->confidence_interval * stddev);
   if ((val < (mean - allowed_variance)) || (val > (mean + allowed_variance)))
     return GNUNET_YES;
index 16af18643e7c82e7e6760f59e144faa676fa3011..7b77b48bb6ec719e09557dcb86bb1895ea66a9b5 100644 (file)
@@ -16,6 +16,9 @@ def get_args():
   parser = argparse.ArgumentParser(description="Sensor profiler")
   parser.add_argument('-p', '--peers', action='store', type=int, required=True,
                       help='Number of peers to run')
+  parser.add_argument('-i', '--sensors-interval', action='store', type=int,
+                      required=False,
+                      help='Change the interval of running sensors to given value')
   return parser.parse_args()
 
 def generate_topology(peers, links):
@@ -97,8 +100,13 @@ def handle_profiler_line(line):
     anomaly_report(eval(parts[1]))
     return
 
-def run_profiler(peers, topology_file):
-  cmd = "GNUNET_FORCE_LOG='gnunet-sensor-profiler;;;;DEBUG' gnunet-sensor-profiler -p %d -t %s > log 2>&1" % (peers, topology_file)
+def run_profiler(peers, topology_file, sensors_interval):
+  cmd1 = "GNUNET_FORCE_LOG='gnunet-sensor-profiler;;;;DEBUG' gnunet-sensor-profiler -p %d -t %s" % (peers, topology_file)
+  if sensors_interval:
+    cmd1 += " -i %d" % sensors_interval
+  cmd2 = "> log 2>&1"
+  cmd = "%s %s" % (cmd1, cmd2)
+  print cmd
   process = Popen([cmd], shell=True)
   time.sleep(0.5)
   line = ''
@@ -118,7 +126,11 @@ def main():
   if num_peers < 3:
     print 'Min number of peers is 3'
     return
-  num_links = int(math.log(num_peers) * math.log(num_peers) * num_peers / 2)
+  sensors_interval = None
+  if 'sensors_interval' in args:
+    sensors_interval = args['sensors_interval']
+  #num_links = int(math.log(num_peers) * math.log(num_peers) * num_peers / 2)
+  num_links = int(math.log(num_peers) * num_peers)
   # Generate random topology
   generate_topology(num_peers, num_links)
   print 'Generated random topology with %d peers and %d links' % (num_peers, num_links)
@@ -127,7 +139,7 @@ def main():
   print 'Created TESTBED topology file %s' % top_file
   draw_graph()
   # Run c profiler
-  run_profiler(num_peers, top_file)
+  run_profiler(num_peers, top_file, sensors_interval)
   
 if __name__ == "__main__":
   main()
index 6767e118b4a207b7a123a1428eb598fd3ebaf7ca..41cba199154522474825ba1be08aea14e4e6d941 100644 (file)
@@ -148,12 +148,15 @@ calculate_pow (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   void *callback_cls;
   int sign_result;
 
+  if (0 == cx->pow % 1000)
+    LOG (GNUNET_ERROR_TYPE_DEBUG, "Checking pow %" PRIu64 ".\n", cx->pow);
   if (GNUNET_YES ==
       check_pow (&cx->timestamp,
                  sizeof (struct GNUNET_CRYPTO_EddsaPublicKey) +
                  sizeof (struct GNUNET_TIME_Absolute) + cx->msg_size, cx->pow,
                  cx->matching_bits))
   {
+    LOG (GNUNET_ERROR_TYPE_DEBUG, "Found pow %" PRIu64 ".\n", cx->pow);
     cx->calculate_pow_task = GNUNET_SCHEDULER_NO_TASK;
     result_block =
         GNUNET_malloc (sizeof (struct GNUNET_SENSOR_crypto_pow_block) +
index 0d1907c9eaef00972d9302296ca06e930b92c05d..6c1ad845be6dabbf39bbc20e3e64f4ada6d1ae63 100644 (file)
@@ -5,6 +5,7 @@ OVERLAY_TOPOLOGY = CLIQUE
 DEFAULTSERVICES = topology dht cadet
 
 [sensor]
+#PREFIX = valgrind --leak-check=full
 SENSOR_DIR = /tmp/test-gnunet-service-sensor-reporting/
 
 START_MONITORING = NO
@@ -12,6 +13,9 @@ START_REPORTING = YES
 START_ANALYSIS = NO
 START_UPDATE = NO
 
+[sensor-reporting]
+POW_MATCHING_BITS = 2
+
 [transport]
 PLUGINS = unix
 
index 85a3de4453ca4464e69769f9f218fa312b16010b..71ab6af81791719eab4057b0496398ffc03cc054 100644 (file)
@@ -111,9 +111,15 @@ static void
 pow_cb (void *cls, struct GNUNET_SENSOR_crypto_pow_block *block)
 {
   void *response;
+  struct GNUNET_TIME_Absolute end_time;
+  struct GNUNET_TIME_Relative duration;
 
+  end_time = GNUNET_TIME_absolute_get();
+  duration = GNUNET_TIME_absolute_get_difference (block->timestamp, end_time);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Received block:\n" "pow: %" PRIu64 ".\n", block->pow);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Block generation toke %s.\n",
+              GNUNET_STRINGS_relative_time_to_string (duration, GNUNET_NO));
   /* Test that the block is valid */
   GNUNET_assert (MSG_SIZE ==
                  GNUNET_SENSOR_crypto_verify_pow_sign (block, MATCHING_BITS,