diff options
author | Omar Tarabai <tarabai@devegypt.com> | 2014-08-20 14:05:05 +0000 |
---|---|---|
committer | Omar Tarabai <tarabai@devegypt.com> | 2014-08-20 14:05:05 +0000 |
commit | 5447f35b5322f59f0828699c4eef156496dbd6e6 (patch) | |
tree | 8355a10f3730a1338f3a8061674832ea96d8131e /src/sensordashboard | |
parent | 3cf872e01763549f20773077baa0a5c7b794d2ea (diff) | |
download | gnunet-5447f35b5322f59f0828699c4eef156496dbd6e6.tar.gz gnunet-5447f35b5322f59f0828699c4eef156496dbd6e6.zip |
sensor: proof-of-work ingerated with anomaly reports
Diffstat (limited to 'src/sensordashboard')
-rw-r--r-- | src/sensordashboard/gnunet-service-sensordashboard.c | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/src/sensordashboard/gnunet-service-sensordashboard.c b/src/sensordashboard/gnunet-service-sensordashboard.c index 1af3be332..cfccc9368 100644 --- a/src/sensordashboard/gnunet-service-sensordashboard.c +++ b/src/sensordashboard/gnunet-service-sensordashboard.c | |||
@@ -175,6 +175,11 @@ static struct ClientPeerContext *cp_head; | |||
175 | */ | 175 | */ |
176 | static struct ClientPeerContext *cp_tail; | 176 | static struct ClientPeerContext *cp_tail; |
177 | 177 | ||
178 | /** | ||
179 | * Parameter that defines the complexity of the proof-of-work | ||
180 | */ | ||
181 | static long long unsigned int pow_matching_bits; | ||
182 | |||
178 | 183 | ||
179 | /** | 184 | /** |
180 | * Trigger sending next pending message to the given client peer if any. | 185 | * Trigger sending next pending message to the given client peer if any. |
@@ -419,6 +424,7 @@ handle_anomaly_report (void *cls, struct GNUNET_CADET_Channel *channel, | |||
419 | const struct GNUNET_MessageHeader *message) | 424 | const struct GNUNET_MessageHeader *message) |
420 | { | 425 | { |
421 | struct ClientPeerContext *cp = *channel_ctx; | 426 | struct ClientPeerContext *cp = *channel_ctx; |
427 | struct GNUNET_SENSOR_crypto_pow_block *report_block; | ||
422 | struct GNUNET_SENSOR_AnomalyReportMessage *anomaly_msg; | 428 | struct GNUNET_SENSOR_AnomalyReportMessage *anomaly_msg; |
423 | struct GNUNET_SENSOR_SensorInfo *sensor; | 429 | struct GNUNET_SENSOR_SensorInfo *sensor; |
424 | struct GNUNET_SENSOR_DashboardAnomalyEntry *anomaly_entry; | 430 | struct GNUNET_SENSOR_DashboardAnomalyEntry *anomaly_entry; |
@@ -427,7 +433,18 @@ handle_anomaly_report (void *cls, struct GNUNET_CADET_Channel *channel, | |||
427 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 433 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
428 | "Received an anomaly report message from peer `%s'.\n", | 434 | "Received an anomaly report message from peer `%s'.\n", |
429 | GNUNET_i2s (&cp->peerid)); | 435 | GNUNET_i2s (&cp->peerid)); |
430 | anomaly_msg = (struct GNUNET_SENSOR_AnomalyReportMessage *) message; | 436 | report_block = (struct GNUNET_SENSOR_crypto_pow_block *) &message[1]; |
437 | if (sizeof (struct GNUNET_SENSOR_AnomalyReportMessage) != | ||
438 | GNUNET_SENSOR_crypto_verify_pow_sign (report_block, pow_matching_bits, | ||
439 | &cp->peerid.public_key, | ||
440 | (void **) &anomaly_msg)) | ||
441 | { | ||
442 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
443 | "Received invalid anomaly report from peer `%s'.\n", | ||
444 | GNUNET_i2s (&cp->peerid)); | ||
445 | GNUNET_break_op (0); | ||
446 | return GNUNET_SYSERR; | ||
447 | } | ||
431 | sensor = | 448 | sensor = |
432 | GNUNET_CONTAINER_multihashmap_get (sensors, | 449 | GNUNET_CONTAINER_multihashmap_get (sensors, |
433 | &anomaly_msg->sensorname_hash); | 450 | &anomaly_msg->sensorname_hash); |
@@ -790,6 +807,8 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
790 | sizeof (struct GNUNET_MessageHeader)}, | 807 | sizeof (struct GNUNET_MessageHeader)}, |
791 | {&handle_anomaly_report, | 808 | {&handle_anomaly_report, |
792 | GNUNET_MESSAGE_TYPE_SENSOR_ANOMALY_REPORT, | 809 | GNUNET_MESSAGE_TYPE_SENSOR_ANOMALY_REPORT, |
810 | sizeof (struct GNUNET_MessageHeader) + | ||
811 | sizeof (struct GNUNET_SENSOR_crypto_pow_block) + | ||
793 | sizeof (struct GNUNET_SENSOR_AnomalyReportMessage)}, | 812 | sizeof (struct GNUNET_SENSOR_AnomalyReportMessage)}, |
794 | {NULL, 0, 0} | 813 | {NULL, 0, 0} |
795 | }; | 814 | }; |
@@ -805,6 +824,26 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
805 | sensor_dir = GNUNET_SENSOR_get_default_sensor_dir (); | 824 | sensor_dir = GNUNET_SENSOR_get_default_sensor_dir (); |
806 | sensors = GNUNET_SENSOR_load_all_sensors (sensor_dir); | 825 | sensors = GNUNET_SENSOR_load_all_sensors (sensor_dir); |
807 | GNUNET_assert (NULL != sensors); | 826 | GNUNET_assert (NULL != sensors); |
827 | |||
828 | if (GNUNET_OK != | ||
829 | GNUNET_CONFIGURATION_get_value_number (cfg, "sensor-reporting", | ||
830 | "POW_MATCHING_BITS", | ||
831 | &pow_matching_bits)) | ||
832 | { | ||
833 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "sensor-reporting", | ||
834 | "POW_MATCHING_BITS"); | ||
835 | GNUNET_SCHEDULER_add_now (&cleanup_task, NULL); | ||
836 | return; | ||
837 | } | ||
838 | if (pow_matching_bits > sizeof (struct GNUNET_HashCode)) | ||
839 | { | ||
840 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
841 | "Matching bits value too large (%d > %d).\n", pow_matching_bits, | ||
842 | sizeof (struct GNUNET_HashCode)); | ||
843 | GNUNET_SCHEDULER_add_now (&cleanup_task, NULL); | ||
844 | return; | ||
845 | } | ||
846 | |||
808 | cadet = | 847 | cadet = |
809 | GNUNET_CADET_connect (cfg, NULL, &cadet_channel_created, | 848 | GNUNET_CADET_connect (cfg, NULL, &cadet_channel_created, |
810 | &cadet_channel_destroyed, cadet_handlers, | 849 | &cadet_channel_destroyed, cadet_handlers, |