diff options
author | Omar Tarabai <tarabai@devegypt.com> | 2014-09-17 19:28:17 +0000 |
---|---|---|
committer | Omar Tarabai <tarabai@devegypt.com> | 2014-09-17 19:28:17 +0000 |
commit | 25ecacf03e0da98ee59486c1dc0128e3355ff9b1 (patch) | |
tree | 6f14b2e961639d57844510e0b1db9e5bc279017f /src/sensor | |
parent | 9a7a6aa0d71f7650e0543602db678eb8bb1c2c4b (diff) | |
download | gnunet-25ecacf03e0da98ee59486c1dc0128e3355ff9b1.tar.gz gnunet-25ecacf03e0da98ee59486c1dc0128e3355ff9b1.zip |
sensor: minor fixes
Diffstat (limited to 'src/sensor')
-rw-r--r-- | src/sensor/gnunet-sensor-profiler.c | 2 | ||||
-rw-r--r-- | src/sensor/gnunet-service-sensor_reporting.c | 20 | ||||
-rw-r--r-- | src/sensor/perf_pow_sign.c | 4 | ||||
-rw-r--r-- | src/sensor/plugin_sensor_model_gaussian.c | 1 | ||||
-rw-r--r-- | src/sensor/profiler.py | 20 | ||||
-rw-r--r-- | src/sensor/sensor_util_lib_crypto.c | 3 | ||||
-rw-r--r-- | src/sensor/test_gnunet-service-sensor_reporting.conf | 4 | ||||
-rw-r--r-- | src/sensor/test_pow_sign.c | 6 |
8 files changed, 44 insertions, 16 deletions
diff --git a/src/sensor/gnunet-sensor-profiler.c b/src/sensor/gnunet-sensor-profiler.c index 467c80dee..783c6fd1e 100644 --- a/src/sensor/gnunet-sensor-profiler.c +++ b/src/sensor/gnunet-sensor-profiler.c | |||
@@ -894,7 +894,7 @@ main (int argc, char *const *argv) | |||
894 | {'t', "topology-file", "FILEPATH", gettext_noop ("Path to topology file"), | 894 | {'t', "topology-file", "FILEPATH", gettext_noop ("Path to topology file"), |
895 | GNUNET_YES, &GNUNET_GETOPT_set_filename, &topology_file}, | 895 | GNUNET_YES, &GNUNET_GETOPT_set_filename, &topology_file}, |
896 | {'i', "sensors-interval", "INTERVAL", | 896 | {'i', "sensors-interval", "INTERVAL", |
897 | gettext_noop ("Change the interval or running sensors to given value"), | 897 | gettext_noop ("Change the interval of running sensors to given value"), |
898 | GNUNET_YES, &GNUNET_GETOPT_set_uint, &sensors_interval}, | 898 | GNUNET_YES, &GNUNET_GETOPT_set_uint, &sensors_interval}, |
899 | GNUNET_GETOPT_OPTION_END | 899 | GNUNET_GETOPT_OPTION_END |
900 | }; | 900 | }; |
diff --git a/src/sensor/gnunet-service-sensor_reporting.c b/src/sensor/gnunet-service-sensor_reporting.c index 5e0972c5e..104c66945 100644 --- a/src/sensor/gnunet-service-sensor_reporting.c +++ b/src/sensor/gnunet-service-sensor_reporting.c | |||
@@ -658,7 +658,10 @@ report_creation_cb (void *cls, struct GNUNET_SENSOR_crypto_pow_block *block) | |||
658 | return; | 658 | return; |
659 | } | 659 | } |
660 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Anomaly report POW block ready.\n"); | 660 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Anomaly report POW block ready.\n"); |
661 | ai->report_block = block; | 661 | ai->report_block = |
662 | GNUNET_memdup (block, | ||
663 | sizeof (struct GNUNET_SENSOR_crypto_pow_block) + | ||
664 | block->msg_size); | ||
662 | ar_item = ai->reporting_queue_head; | 665 | ar_item = ai->reporting_queue_head; |
663 | while (NULL != ar_item) | 666 | while (NULL != ar_item) |
664 | { | 667 | { |
@@ -706,9 +709,9 @@ update_anomaly_report_pow_block (struct AnomalyInfo *ai) | |||
706 | arm->anomalous = htons (ai->anomalous); | 709 | arm->anomalous = htons (ai->anomalous); |
707 | arm->anomalous_neighbors = | 710 | arm->anomalous_neighbors = |
708 | (0 == | 711 | (0 == |
709 | neighborhood) ? 0 : ((float) | 712 | neighborhood) ? 0 : ((float) GNUNET_CONTAINER_multipeermap_size (ai-> |
710 | GNUNET_CONTAINER_multipeermap_size | 713 | anomalous_neighbors)) |
711 | (ai->anomalous_neighbors)) / neighborhood; | 714 | / neighborhood; |
712 | timestamp = GNUNET_TIME_absolute_get (); | 715 | timestamp = GNUNET_TIME_absolute_get (); |
713 | ai->report_creation_cx = | 716 | ai->report_creation_cx = |
714 | GNUNET_SENSOR_crypto_pow_sign (arm, | 717 | GNUNET_SENSOR_crypto_pow_sign (arm, |
@@ -717,6 +720,7 @@ update_anomaly_report_pow_block (struct AnomalyInfo *ai) | |||
717 | ×tamp, &mypeerid.public_key, | 720 | ×tamp, &mypeerid.public_key, |
718 | private_key, pow_matching_bits, | 721 | private_key, pow_matching_bits, |
719 | &report_creation_cb, ai); | 722 | &report_creation_cb, ai); |
723 | GNUNET_free (arm); | ||
720 | } | 724 | } |
721 | 725 | ||
722 | 726 | ||
@@ -800,8 +804,8 @@ handle_anomaly_report (void *cls, const struct GNUNET_PeerIdentity *other, | |||
800 | my_anomaly_info = get_anomaly_info_by_sensor (sensor); | 804 | my_anomaly_info = get_anomaly_info_by_sensor (sensor); |
801 | GNUNET_assert (NULL != my_anomaly_info); | 805 | GNUNET_assert (NULL != my_anomaly_info); |
802 | peer_in_anomalous_list = | 806 | peer_in_anomalous_list = |
803 | GNUNET_CONTAINER_multipeermap_contains | 807 | GNUNET_CONTAINER_multipeermap_contains (my_anomaly_info-> |
804 | (my_anomaly_info->anomalous_neighbors, other); | 808 | anomalous_neighbors, other); |
805 | peer_anomalous = ntohs (arm->anomalous); | 809 | peer_anomalous = ntohs (arm->anomalous); |
806 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 810 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
807 | "Received an anomaly update from neighbour `%s' (%d).\n", | 811 | "Received an anomaly update from neighbour `%s' (%d).\n", |
@@ -820,8 +824,8 @@ handle_anomaly_report (void *cls, const struct GNUNET_PeerIdentity *other, | |||
820 | if (GNUNET_NO == peer_in_anomalous_list) /* repeated negative report */ | 824 | if (GNUNET_NO == peer_in_anomalous_list) /* repeated negative report */ |
821 | GNUNET_break_op (0); | 825 | GNUNET_break_op (0); |
822 | else | 826 | else |
823 | GNUNET_CONTAINER_multipeermap_remove_all | 827 | GNUNET_CONTAINER_multipeermap_remove_all (my_anomaly_info-> |
824 | (my_anomaly_info->anomalous_neighbors, other); | 828 | anomalous_neighbors, other); |
825 | } | 829 | } |
826 | /* This is important to create an updated block since the data changed */ | 830 | /* This is important to create an updated block since the data changed */ |
827 | update_anomaly_report_pow_block (my_anomaly_info); | 831 | update_anomaly_report_pow_block (my_anomaly_info); |
diff --git a/src/sensor/perf_pow_sign.c b/src/sensor/perf_pow_sign.c index a99105a82..b55354490 100644 --- a/src/sensor/perf_pow_sign.c +++ b/src/sensor/perf_pow_sign.c | |||
@@ -46,7 +46,7 @@ | |||
46 | /** | 46 | /** |
47 | * How many matching bits to end with | 47 | * How many matching bits to end with |
48 | */ | 48 | */ |
49 | #define MATCHING_BITS_END 50 | 49 | #define MATCHING_BITS_END 20 |
50 | 50 | ||
51 | /** | 51 | /** |
52 | * How many readings per matching bits value | 52 | * How many readings per matching bits value |
@@ -106,7 +106,7 @@ static struct GNUNET_TIME_Relative total_duration; | |||
106 | /** | 106 | /** |
107 | * Task creating pow block | 107 | * Task creating pow block |
108 | */ | 108 | */ |
109 | struct GNUNET_SENSOR_crypto_pow_context *pow_task; | 109 | static struct GNUNET_SENSOR_crypto_pow_context *pow_task; |
110 | 110 | ||
111 | 111 | ||
112 | /** | 112 | /** |
diff --git a/src/sensor/plugin_sensor_model_gaussian.c b/src/sensor/plugin_sensor_model_gaussian.c index af879ef93..fd35ff077 100644 --- a/src/sensor/plugin_sensor_model_gaussian.c +++ b/src/sensor/plugin_sensor_model_gaussian.c | |||
@@ -135,7 +135,6 @@ sensor_gaussian_model_feed (void *cls, double val) | |||
135 | if (stddev < 0) /* Value can be slightly less than 0 due to rounding errors */ | 135 | if (stddev < 0) /* Value can be slightly less than 0 due to rounding errors */ |
136 | stddev = 0; | 136 | stddev = 0; |
137 | stddev = sqrt (stddev); | 137 | stddev = sqrt (stddev); |
138 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Mean: %Lf, Stddev: %Lf\n", mean, stddev); | ||
139 | allowed_variance = (plugin->confidence_interval * stddev); | 138 | allowed_variance = (plugin->confidence_interval * stddev); |
140 | if ((val < (mean - allowed_variance)) || (val > (mean + allowed_variance))) | 139 | if ((val < (mean - allowed_variance)) || (val > (mean + allowed_variance))) |
141 | return GNUNET_YES; | 140 | return GNUNET_YES; |
diff --git a/src/sensor/profiler.py b/src/sensor/profiler.py index 16af18643..7b77b48bb 100644 --- a/src/sensor/profiler.py +++ b/src/sensor/profiler.py | |||
@@ -16,6 +16,9 @@ def get_args(): | |||
16 | parser = argparse.ArgumentParser(description="Sensor profiler") | 16 | parser = argparse.ArgumentParser(description="Sensor profiler") |
17 | parser.add_argument('-p', '--peers', action='store', type=int, required=True, | 17 | parser.add_argument('-p', '--peers', action='store', type=int, required=True, |
18 | help='Number of peers to run') | 18 | help='Number of peers to run') |
19 | parser.add_argument('-i', '--sensors-interval', action='store', type=int, | ||
20 | required=False, | ||
21 | help='Change the interval of running sensors to given value') | ||
19 | return parser.parse_args() | 22 | return parser.parse_args() |
20 | 23 | ||
21 | def generate_topology(peers, links): | 24 | def generate_topology(peers, links): |
@@ -97,8 +100,13 @@ def handle_profiler_line(line): | |||
97 | anomaly_report(eval(parts[1])) | 100 | anomaly_report(eval(parts[1])) |
98 | return | 101 | return |
99 | 102 | ||
100 | def run_profiler(peers, topology_file): | 103 | def run_profiler(peers, topology_file, sensors_interval): |
101 | cmd = "GNUNET_FORCE_LOG='gnunet-sensor-profiler;;;;DEBUG' gnunet-sensor-profiler -p %d -t %s > log 2>&1" % (peers, topology_file) | 104 | cmd1 = "GNUNET_FORCE_LOG='gnunet-sensor-profiler;;;;DEBUG' gnunet-sensor-profiler -p %d -t %s" % (peers, topology_file) |
105 | if sensors_interval: | ||
106 | cmd1 += " -i %d" % sensors_interval | ||
107 | cmd2 = "> log 2>&1" | ||
108 | cmd = "%s %s" % (cmd1, cmd2) | ||
109 | print cmd | ||
102 | process = Popen([cmd], shell=True) | 110 | process = Popen([cmd], shell=True) |
103 | time.sleep(0.5) | 111 | time.sleep(0.5) |
104 | line = '' | 112 | line = '' |
@@ -118,7 +126,11 @@ def main(): | |||
118 | if num_peers < 3: | 126 | if num_peers < 3: |
119 | print 'Min number of peers is 3' | 127 | print 'Min number of peers is 3' |
120 | return | 128 | return |
121 | num_links = int(math.log(num_peers) * math.log(num_peers) * num_peers / 2) | 129 | sensors_interval = None |
130 | if 'sensors_interval' in args: | ||
131 | sensors_interval = args['sensors_interval'] | ||
132 | #num_links = int(math.log(num_peers) * math.log(num_peers) * num_peers / 2) | ||
133 | num_links = int(math.log(num_peers) * num_peers) | ||
122 | # Generate random topology | 134 | # Generate random topology |
123 | generate_topology(num_peers, num_links) | 135 | generate_topology(num_peers, num_links) |
124 | print 'Generated random topology with %d peers and %d links' % (num_peers, num_links) | 136 | print 'Generated random topology with %d peers and %d links' % (num_peers, num_links) |
@@ -127,7 +139,7 @@ def main(): | |||
127 | print 'Created TESTBED topology file %s' % top_file | 139 | print 'Created TESTBED topology file %s' % top_file |
128 | draw_graph() | 140 | draw_graph() |
129 | # Run c profiler | 141 | # Run c profiler |
130 | run_profiler(num_peers, top_file) | 142 | run_profiler(num_peers, top_file, sensors_interval) |
131 | 143 | ||
132 | if __name__ == "__main__": | 144 | if __name__ == "__main__": |
133 | main() | 145 | main() |
diff --git a/src/sensor/sensor_util_lib_crypto.c b/src/sensor/sensor_util_lib_crypto.c index 6767e118b..41cba1991 100644 --- a/src/sensor/sensor_util_lib_crypto.c +++ b/src/sensor/sensor_util_lib_crypto.c | |||
@@ -148,12 +148,15 @@ calculate_pow (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
148 | void *callback_cls; | 148 | void *callback_cls; |
149 | int sign_result; | 149 | int sign_result; |
150 | 150 | ||
151 | if (0 == cx->pow % 1000) | ||
152 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Checking pow %" PRIu64 ".\n", cx->pow); | ||
151 | if (GNUNET_YES == | 153 | if (GNUNET_YES == |
152 | check_pow (&cx->timestamp, | 154 | check_pow (&cx->timestamp, |
153 | sizeof (struct GNUNET_CRYPTO_EddsaPublicKey) + | 155 | sizeof (struct GNUNET_CRYPTO_EddsaPublicKey) + |
154 | sizeof (struct GNUNET_TIME_Absolute) + cx->msg_size, cx->pow, | 156 | sizeof (struct GNUNET_TIME_Absolute) + cx->msg_size, cx->pow, |
155 | cx->matching_bits)) | 157 | cx->matching_bits)) |
156 | { | 158 | { |
159 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Found pow %" PRIu64 ".\n", cx->pow); | ||
157 | cx->calculate_pow_task = GNUNET_SCHEDULER_NO_TASK; | 160 | cx->calculate_pow_task = GNUNET_SCHEDULER_NO_TASK; |
158 | result_block = | 161 | result_block = |
159 | GNUNET_malloc (sizeof (struct GNUNET_SENSOR_crypto_pow_block) + | 162 | GNUNET_malloc (sizeof (struct GNUNET_SENSOR_crypto_pow_block) + |
diff --git a/src/sensor/test_gnunet-service-sensor_reporting.conf b/src/sensor/test_gnunet-service-sensor_reporting.conf index 0d1907c9e..6c1ad845b 100644 --- a/src/sensor/test_gnunet-service-sensor_reporting.conf +++ b/src/sensor/test_gnunet-service-sensor_reporting.conf | |||
@@ -5,6 +5,7 @@ OVERLAY_TOPOLOGY = CLIQUE | |||
5 | DEFAULTSERVICES = topology dht cadet | 5 | DEFAULTSERVICES = topology dht cadet |
6 | 6 | ||
7 | [sensor] | 7 | [sensor] |
8 | #PREFIX = valgrind --leak-check=full | ||
8 | SENSOR_DIR = /tmp/test-gnunet-service-sensor-reporting/ | 9 | SENSOR_DIR = /tmp/test-gnunet-service-sensor-reporting/ |
9 | 10 | ||
10 | START_MONITORING = NO | 11 | START_MONITORING = NO |
@@ -12,6 +13,9 @@ START_REPORTING = YES | |||
12 | START_ANALYSIS = NO | 13 | START_ANALYSIS = NO |
13 | START_UPDATE = NO | 14 | START_UPDATE = NO |
14 | 15 | ||
16 | [sensor-reporting] | ||
17 | POW_MATCHING_BITS = 2 | ||
18 | |||
15 | [transport] | 19 | [transport] |
16 | PLUGINS = unix | 20 | PLUGINS = unix |
17 | 21 | ||
diff --git a/src/sensor/test_pow_sign.c b/src/sensor/test_pow_sign.c index 85a3de445..71ab6af81 100644 --- a/src/sensor/test_pow_sign.c +++ b/src/sensor/test_pow_sign.c | |||
@@ -111,9 +111,15 @@ static void | |||
111 | pow_cb (void *cls, struct GNUNET_SENSOR_crypto_pow_block *block) | 111 | pow_cb (void *cls, struct GNUNET_SENSOR_crypto_pow_block *block) |
112 | { | 112 | { |
113 | void *response; | 113 | void *response; |
114 | struct GNUNET_TIME_Absolute end_time; | ||
115 | struct GNUNET_TIME_Relative duration; | ||
114 | 116 | ||
117 | end_time = GNUNET_TIME_absolute_get(); | ||
118 | duration = GNUNET_TIME_absolute_get_difference (block->timestamp, end_time); | ||
115 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 119 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
116 | "Received block:\n" "pow: %" PRIu64 ".\n", block->pow); | 120 | "Received block:\n" "pow: %" PRIu64 ".\n", block->pow); |
121 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Block generation toke %s.\n", | ||
122 | GNUNET_STRINGS_relative_time_to_string (duration, GNUNET_NO)); | ||
117 | /* Test that the block is valid */ | 123 | /* Test that the block is valid */ |
118 | GNUNET_assert (MSG_SIZE == | 124 | GNUNET_assert (MSG_SIZE == |
119 | GNUNET_SENSOR_crypto_verify_pow_sign (block, MATCHING_BITS, | 125 | GNUNET_SENSOR_crypto_verify_pow_sign (block, MATCHING_BITS, |