aboutsummaryrefslogtreecommitdiff
path: root/src/sensor
diff options
context:
space:
mode:
authorOmar Tarabai <tarabai@devegypt.com>2014-08-20 14:05:05 +0000
committerOmar Tarabai <tarabai@devegypt.com>2014-08-20 14:05:05 +0000
commit5447f35b5322f59f0828699c4eef156496dbd6e6 (patch)
tree8355a10f3730a1338f3a8061674832ea96d8131e /src/sensor
parent3cf872e01763549f20773077baa0a5c7b794d2ea (diff)
downloadgnunet-5447f35b5322f59f0828699c4eef156496dbd6e6.tar.gz
gnunet-5447f35b5322f59f0828699c4eef156496dbd6e6.zip
sensor: proof-of-work ingerated with anomaly reports
Diffstat (limited to 'src/sensor')
-rw-r--r--src/sensor/gnunet-service-sensor_reporting.c294
-rw-r--r--src/sensor/gnunet-service-sensor_update.c4
-rw-r--r--src/sensor/sensor.conf.in10
-rw-r--r--src/sensor/sensor_util_lib_crypto.c9
-rw-r--r--src/sensor/test_pow_sign.c12
5 files changed, 278 insertions, 51 deletions
diff --git a/src/sensor/gnunet-service-sensor_reporting.c b/src/sensor/gnunet-service-sensor_reporting.c
index 562768ff1..5e0972c5e 100644
--- a/src/sensor/gnunet-service-sensor_reporting.c
+++ b/src/sensor/gnunet-service-sensor_reporting.c
@@ -34,6 +34,35 @@
34#define LOG(kind,...) GNUNET_log_from (kind, "sensor-reporting",__VA_ARGS__) 34#define LOG(kind,...) GNUNET_log_from (kind, "sensor-reporting",__VA_ARGS__)
35 35
36 36
37/**
38 * When we are still generating a proof-of-work and we need to send an anomaly
39 * report, we queue them until the generation is complete
40 */
41struct AnomalyReportingQueueItem
42{
43
44 /**
45 * DLL
46 */
47 struct AnomalyReportingQueueItem *prev;
48
49 /**
50 * DLL
51 */
52 struct AnomalyReportingQueueItem *next;
53
54 /**
55 * Message queue belonging to the peer that is the destination of the report
56 */
57 struct GNUNET_MQ_Handle *dest_mq;
58
59 /**
60 * Report type
61 */
62 int type;
63
64};
65
37struct AnomalyInfo 66struct AnomalyInfo
38{ 67{
39 68
@@ -62,6 +91,26 @@ struct AnomalyInfo
62 */ 91 */
63 struct GNUNET_CONTAINER_MultiPeerMap *anomalous_neighbors; 92 struct GNUNET_CONTAINER_MultiPeerMap *anomalous_neighbors;
64 93
94 /**
95 * Report block with proof-of-work and signature
96 */
97 struct GNUNET_SENSOR_crypto_pow_block *report_block;
98
99 /**
100 * Context of an operation creating pow and signature
101 */
102 struct GNUNET_SENSOR_crypto_pow_context *report_creation_cx;
103
104 /**
105 * Head of the queue of pending report destinations
106 */
107 struct AnomalyReportingQueueItem *reporting_queue_head;
108
109 /**
110 * Head of the queue of pending report destinations
111 */
112 struct AnomalyReportingQueueItem *reporting_queue_tail;
113
65}; 114};
66 115
67struct ValueInfo 116struct ValueInfo
@@ -214,6 +263,11 @@ static struct GNUNET_CADET_Handle *cadet;
214static struct GNUNET_PeerIdentity mypeerid; 263static struct GNUNET_PeerIdentity mypeerid;
215 264
216/** 265/**
266 * My private key
267 */
268static struct GNUNET_CRYPTO_EddsaPrivateKey *private_key;
269
270/**
217 * Head of DLL of anomaly info structs 271 * Head of DLL of anomaly info structs
218 */ 272 */
219static struct AnomalyInfo *ai_head; 273static struct AnomalyInfo *ai_head;
@@ -263,6 +317,11 @@ static int module_running = GNUNET_NO;
263 */ 317 */
264static int neighborhood; 318static int neighborhood;
265 319
320/**
321 * Parameter that defines the complexity of the proof-of-work
322 */
323static long long unsigned int pow_matching_bits;
324
266 325
267 326
268/******************************************************************************/ 327/******************************************************************************/
@@ -277,8 +336,31 @@ static int neighborhood;
277static void 336static void
278destroy_anomaly_info (struct AnomalyInfo *ai) 337destroy_anomaly_info (struct AnomalyInfo *ai)
279{ 338{
339 struct AnomalyReportingQueueItem *ar_item;
340
341 ar_item = ai->reporting_queue_head;
342 while (NULL != ar_item)
343 {
344 GNUNET_CONTAINER_DLL_remove (ai->reporting_queue_head,
345 ai->reporting_queue_tail, ar_item);
346 GNUNET_free (ar_item);
347 ar_item = ai->reporting_queue_head;
348 }
349 if (NULL != ai->report_creation_cx)
350 {
351 GNUNET_SENSOR_crypto_pow_sign_cancel (ai->report_creation_cx);
352 ai->report_creation_cx = NULL;
353 }
354 if (NULL != ai->report_block)
355 {
356 GNUNET_free (ai->report_block);
357 ai->report_block = NULL;
358 }
280 if (NULL != ai->anomalous_neighbors) 359 if (NULL != ai->anomalous_neighbors)
360 {
281 GNUNET_CONTAINER_multipeermap_destroy (ai->anomalous_neighbors); 361 GNUNET_CONTAINER_multipeermap_destroy (ai->anomalous_neighbors);
362 ai->anomalous_neighbors = NULL;
363 }
282 GNUNET_free (ai); 364 GNUNET_free (ai);
283} 365}
284 366
@@ -488,20 +570,135 @@ get_cadet_peer (struct GNUNET_PeerIdentity pid)
488 570
489 571
490/** 572/**
491 * Create an anomaly report message from a given anomaly info struct inside a 573 * This function is called only when we have a block ready and want to send it
492 * MQ envelope. 574 * to the given peer (represented by its message queue)
493 * 575 *
494 * @param ai Anomaly info struct to use 576 * @param mq Message queue to put the message in
577 * @param ai Anomaly info to report
495 * @param type Message type 578 * @param type Message type
496 * @return Envelope with message
497 */ 579 */
498static struct GNUNET_MQ_Envelope * 580static void
499create_anomaly_report_message (struct AnomalyInfo *ai, int type) 581do_send_anomaly_report (struct GNUNET_MQ_Handle *mq, struct AnomalyInfo *ai,
582 int type)
500{ 583{
501 struct GNUNET_SENSOR_AnomalyReportMessage *arm; 584 struct GNUNET_MessageHeader *msg;
502 struct GNUNET_MQ_Envelope *ev; 585 struct GNUNET_MQ_Envelope *ev;
586 size_t block_size;
587
588 GNUNET_assert (NULL != ai->report_block);
589 block_size =
590 sizeof (struct GNUNET_SENSOR_crypto_pow_block) +
591 ai->report_block->msg_size;
592 ev = GNUNET_MQ_msg_header_extra (msg, block_size, type);
593 memcpy (&msg[1], ai->report_block, block_size);
594 GNUNET_MQ_send (mq, ev);
595}
596
597
598/**
599 * Check if we have signed and proof-of-work block ready.
600 * If yes, we send the report directly, if no, we enqueue the reporting until
601 * the block is ready.
602 *
603 * @param mq Message queue to put the message in
604 * @param ai Anomaly info to report
605 * @param p2p Is the report sent to a neighboring peer
606 */
607static void
608send_anomaly_report (struct GNUNET_MQ_Handle *mq, struct AnomalyInfo *ai,
609 int p2p)
610{
611 struct AnomalyReportingQueueItem *ar_item;
612 int type;
613
614 type =
615 (GNUNET_YES ==
616 p2p) ? GNUNET_MESSAGE_TYPE_SENSOR_ANOMALY_REPORT_P2P :
617 GNUNET_MESSAGE_TYPE_SENSOR_ANOMALY_REPORT;
618 if (NULL == ai->report_block)
619 {
620 ar_item = GNUNET_new (struct AnomalyReportingQueueItem);
621
622 ar_item->dest_mq = mq;
623 ar_item->type = type;
624 GNUNET_CONTAINER_DLL_insert_tail (ai->reporting_queue_head,
625 ai->reporting_queue_tail, ar_item);
626 }
627 else
628 {
629 do_send_anomaly_report (mq, ai, type);
630 }
631}
632
633
634/**
635 * Callback when the crypto module finished created proof-of-work and signature
636 * for an anomaly report.
637 *
638 * @param cls Closure, a `struct AnomalyInfo *`
639 * @param block The resulting block, NULL on error
640 */
641static void
642report_creation_cb (void *cls, struct GNUNET_SENSOR_crypto_pow_block *block)
643{
644 struct AnomalyInfo *ai = cls;
645 struct AnomalyReportingQueueItem *ar_item;
646
647 ai->report_creation_cx = NULL;
648 if (NULL != ai->report_block)
649 {
650 LOG (GNUNET_ERROR_TYPE_ERROR,
651 _("Double creation of proof-of-work, this should not happen.\n"));
652 return;
653 }
654 if (NULL == block)
655 {
656 LOG (GNUNET_ERROR_TYPE_ERROR,
657 _("Failed to create pow and signature block.\n"));
658 return;
659 }
660 LOG (GNUNET_ERROR_TYPE_DEBUG, "Anomaly report POW block ready.\n");
661 ai->report_block = block;
662 ar_item = ai->reporting_queue_head;
663 while (NULL != ar_item)
664 {
665 GNUNET_CONTAINER_DLL_remove (ai->reporting_queue_head,
666 ai->reporting_queue_tail, ar_item);
667 do_send_anomaly_report (ar_item->dest_mq, ai, ar_item->type);
668 GNUNET_free (ar_item);
669 ar_item = ai->reporting_queue_head;
670 }
671}
672
673
674/**
675 * When a change to the anomaly info of a sensor is done, this function should
676 * be called to create the message, its proof-of-work and signuature ready to
677 * be sent to other peers or collection point.
678 *
679 * @param ai Anomaly Info struct
680 */
681static void
682update_anomaly_report_pow_block (struct AnomalyInfo *ai)
683{
684 struct GNUNET_SENSOR_AnomalyReportMessage *arm;
685 struct GNUNET_TIME_Absolute timestamp;
686
687 LOG (GNUNET_ERROR_TYPE_DEBUG,
688 "Updating anomaly report POW block due to data change.\n");
689 if (NULL != ai->report_block)
690 {
691 GNUNET_free (ai->report_block);
692 ai->report_block = NULL;
693 }
694 if (NULL != ai->report_creation_cx)
695 {
696 /* If a creation is already running, cancel it because the data changed */
697 GNUNET_SENSOR_crypto_pow_sign_cancel (ai->report_creation_cx);
698 ai->report_creation_cx = NULL;
699 }
700 arm = GNUNET_new (struct GNUNET_SENSOR_AnomalyReportMessage);
503 701
504 ev = GNUNET_MQ_msg (arm, type);
505 GNUNET_CRYPTO_hash (ai->sensor->name, strlen (ai->sensor->name) + 1, 702 GNUNET_CRYPTO_hash (ai->sensor->name, strlen (ai->sensor->name) + 1,
506 &arm->sensorname_hash); 703 &arm->sensorname_hash);
507 arm->sensorversion_major = htons (ai->sensor->version_major); 704 arm->sensorversion_major = htons (ai->sensor->version_major);
@@ -512,7 +709,14 @@ create_anomaly_report_message (struct AnomalyInfo *ai, int type)
512 neighborhood) ? 0 : ((float) 709 neighborhood) ? 0 : ((float)
513 GNUNET_CONTAINER_multipeermap_size 710 GNUNET_CONTAINER_multipeermap_size
514 (ai->anomalous_neighbors)) / neighborhood; 711 (ai->anomalous_neighbors)) / neighborhood;
515 return ev; 712 timestamp = GNUNET_TIME_absolute_get ();
713 ai->report_creation_cx =
714 GNUNET_SENSOR_crypto_pow_sign (arm,
715 sizeof (struct
716 GNUNET_SENSOR_AnomalyReportMessage),
717 &timestamp, &mypeerid.public_key,
718 private_key, pow_matching_bits,
719 &report_creation_cb, ai);
516} 720}
517 721
518 722
@@ -542,29 +746,6 @@ create_value_message (struct ValueInfo *vi)
542} 746}
543 747
544 748
545/**
546 * Send given anomaly info report by putting it in the given message queue.
547 *
548 * @param mq Message queue to put the message in
549 * @param ai Anomaly info to report
550 * @param p2p Is the report sent to a neighboring peer
551 */
552static void
553send_anomaly_report (struct GNUNET_MQ_Handle *mq, struct AnomalyInfo *ai,
554 int p2p)
555{
556 struct GNUNET_MQ_Envelope *ev;
557 int type;
558
559 type =
560 (GNUNET_YES ==
561 p2p) ? GNUNET_MESSAGE_TYPE_SENSOR_ANOMALY_REPORT_P2P :
562 GNUNET_MESSAGE_TYPE_SENSOR_ANOMALY_REPORT;
563 ev = create_anomaly_report_message (ai, type);
564 GNUNET_MQ_send (mq, ev);
565}
566
567
568/******************************************************************************/ 749/******************************************************************************/
569/*************************** CORE Handlers ***************************/ 750/*************************** CORE Handlers ***************************/
570/******************************************************************************/ 751/******************************************************************************/
@@ -583,6 +764,7 @@ static int
583handle_anomaly_report (void *cls, const struct GNUNET_PeerIdentity *other, 764handle_anomaly_report (void *cls, const struct GNUNET_PeerIdentity *other,
584 const struct GNUNET_MessageHeader *message) 765 const struct GNUNET_MessageHeader *message)
585{ 766{
767 struct GNUNET_SENSOR_crypto_pow_block *report_block;
586 struct GNUNET_SENSOR_AnomalyReportMessage *arm; 768 struct GNUNET_SENSOR_AnomalyReportMessage *arm;
587 struct GNUNET_SENSOR_SensorInfo *sensor; 769 struct GNUNET_SENSOR_SensorInfo *sensor;
588 struct AnomalyInfo *my_anomaly_info; 770 struct AnomalyInfo *my_anomaly_info;
@@ -590,7 +772,21 @@ handle_anomaly_report (void *cls, const struct GNUNET_PeerIdentity *other,
590 int peer_anomalous; 772 int peer_anomalous;
591 int peer_in_anomalous_list; 773 int peer_in_anomalous_list;
592 774
593 arm = (struct GNUNET_SENSOR_AnomalyReportMessage *) message; 775 /* Verify proof-of-work, signature and extract report message */
776 report_block = (struct GNUNET_SENSOR_crypto_pow_block *) &message[1];
777 if (sizeof (struct GNUNET_SENSOR_AnomalyReportMessage) !=
778 GNUNET_SENSOR_crypto_verify_pow_sign (report_block, pow_matching_bits,
779 (struct GNUNET_CRYPTO_EddsaPublicKey
780 *) &other->public_key,
781 (void **) &arm))
782 {
783 LOG (GNUNET_ERROR_TYPE_WARNING,
784 "Received invalid anomaly report from peer `%s'.\n",
785 GNUNET_i2s (other));
786 GNUNET_break_op (0);
787 return GNUNET_SYSERR;
788 }
789 /* Now we parse the content of the message */
594 sensor = GNUNET_CONTAINER_multihashmap_get (sensors, &arm->sensorname_hash); 790 sensor = GNUNET_CONTAINER_multihashmap_get (sensors, &arm->sensorname_hash);
595 if (NULL == sensor || 791 if (NULL == sensor ||
596 sensor->version_major != ntohs (arm->sensorversion_major) || 792 sensor->version_major != ntohs (arm->sensorversion_major) ||
@@ -627,6 +823,8 @@ handle_anomaly_report (void *cls, const struct GNUNET_PeerIdentity *other,
627 GNUNET_CONTAINER_multipeermap_remove_all 823 GNUNET_CONTAINER_multipeermap_remove_all
628 (my_anomaly_info->anomalous_neighbors, other); 824 (my_anomaly_info->anomalous_neighbors, other);
629 } 825 }
826 /* This is important to create an updated block since the data changed */
827 update_anomaly_report_pow_block (my_anomaly_info);
630 /* Send anomaly update to collection point only if I have the same anomaly */ 828 /* Send anomaly update to collection point only if I have the same anomaly */
631 if (GNUNET_YES == my_anomaly_info->anomalous && 829 if (GNUNET_YES == my_anomaly_info->anomalous &&
632 NULL != sensor->collection_point && 830 NULL != sensor->collection_point &&
@@ -839,6 +1037,8 @@ SENSOR_reporting_anomaly_update (struct GNUNET_SENSOR_SensorInfo *sensor,
839 ai = get_anomaly_info_by_sensor (sensor); 1037 ai = get_anomaly_info_by_sensor (sensor);
840 GNUNET_assert (NULL != ai); 1038 GNUNET_assert (NULL != ai);
841 ai->anomalous = anomalous; 1039 ai->anomalous = anomalous;
1040 /* This is important to create an updated block since the data changed */
1041 update_anomaly_report_pow_block (ai);
842 /* Report change to all neighbors */ 1042 /* Report change to all neighbors */
843 corep = corep_head; 1043 corep = corep_head;
844 while (NULL != corep) 1044 while (NULL != corep)
@@ -928,6 +1128,8 @@ init_sensor_reporting (void *cls, const struct GNUNET_HashCode *key,
928 ai->anomalous = GNUNET_NO; 1128 ai->anomalous = GNUNET_NO;
929 ai->anomalous_neighbors = 1129 ai->anomalous_neighbors =
930 GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO); 1130 GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO);
1131 ai->report_block = NULL;
1132 ai->report_creation_cx = NULL;
931 GNUNET_CONTAINER_DLL_insert (ai_head, ai_tail, ai); 1133 GNUNET_CONTAINER_DLL_insert (ai_head, ai_tail, ai);
932 /* Create sensor value info context (if needed to be reported) */ 1134 /* Create sensor value info context (if needed to be reported) */
933 if (NULL == sensor->collection_point || GNUNET_NO == sensor->report_values) 1135 if (NULL == sensor->collection_point || GNUNET_NO == sensor->report_values)
@@ -966,6 +1168,8 @@ SENSOR_reporting_start (const struct GNUNET_CONFIGURATION_Handle *c,
966{ 1168{
967 static struct GNUNET_CORE_MessageHandler core_handlers[] = { 1169 static struct GNUNET_CORE_MessageHandler core_handlers[] = {
968 {&handle_anomaly_report, GNUNET_MESSAGE_TYPE_SENSOR_ANOMALY_REPORT_P2P, 1170 {&handle_anomaly_report, GNUNET_MESSAGE_TYPE_SENSOR_ANOMALY_REPORT_P2P,
1171 sizeof (struct GNUNET_MessageHeader) +
1172 sizeof (struct GNUNET_SENSOR_crypto_pow_block) +
969 sizeof (struct GNUNET_SENSOR_AnomalyReportMessage)}, 1173 sizeof (struct GNUNET_SENSOR_AnomalyReportMessage)},
970 {NULL, 0, 0} 1174 {NULL, 0, 0}
971 }; 1175 };
@@ -977,6 +1181,23 @@ SENSOR_reporting_start (const struct GNUNET_CONFIGURATION_Handle *c,
977 GNUNET_assert (NULL != s); 1181 GNUNET_assert (NULL != s);
978 sensors = s; 1182 sensors = s;
979 cfg = c; 1183 cfg = c;
1184 if (GNUNET_OK !=
1185 GNUNET_CONFIGURATION_get_value_number (cfg, "sensor-reporting",
1186 "POW_MATCHING_BITS",
1187 &pow_matching_bits))
1188 {
1189 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "sensor-reporting",
1190 "POW_MATCHING_BITS");
1191 SENSOR_reporting_stop ();
1192 return GNUNET_SYSERR;
1193 }
1194 if (pow_matching_bits > sizeof (struct GNUNET_HashCode))
1195 {
1196 LOG (GNUNET_ERROR_TYPE_ERROR, "Matching bits value too large (%d > %d).\n",
1197 pow_matching_bits, sizeof (struct GNUNET_HashCode));
1198 SENSOR_reporting_stop ();
1199 return GNUNET_SYSERR;
1200 }
980 /* Connect to PEERSTORE */ 1201 /* Connect to PEERSTORE */
981 peerstore = GNUNET_PEERSTORE_connect (cfg); 1202 peerstore = GNUNET_PEERSTORE_connect (cfg);
982 if (NULL == peerstore) 1203 if (NULL == peerstore)
@@ -1007,6 +1228,13 @@ SENSOR_reporting_start (const struct GNUNET_CONFIGURATION_Handle *c,
1007 SENSOR_reporting_stop (); 1228 SENSOR_reporting_stop ();
1008 return GNUNET_SYSERR; 1229 return GNUNET_SYSERR;
1009 } 1230 }
1231 private_key = GNUNET_CRYPTO_eddsa_key_create_from_configuration (cfg);
1232 if (NULL == private_key)
1233 {
1234 LOG (GNUNET_ERROR_TYPE_ERROR, _("Failed to load my private key.\n"));
1235 SENSOR_reporting_stop ();
1236 return GNUNET_SYSERR;
1237 }
1010 GNUNET_CRYPTO_get_peer_identity (cfg, &mypeerid); 1238 GNUNET_CRYPTO_get_peer_identity (cfg, &mypeerid);
1011 GNUNET_CONTAINER_multihashmap_iterate (sensors, &init_sensor_reporting, NULL); 1239 GNUNET_CONTAINER_multihashmap_iterate (sensors, &init_sensor_reporting, NULL);
1012 neighborhood = 0; 1240 neighborhood = 0;
diff --git a/src/sensor/gnunet-service-sensor_update.c b/src/sensor/gnunet-service-sensor_update.c
index 1bcdd792a..aa7716f1c 100644
--- a/src/sensor/gnunet-service-sensor_update.c
+++ b/src/sensor/gnunet-service-sensor_update.c
@@ -452,8 +452,8 @@ load_update_points ()
452 int count = 0; 452 int count = 0;
453 453
454 if (GNUNET_OK != 454 if (GNUNET_OK !=
455 GNUNET_CONFIGURATION_get_value_string (cfg, "sensor", "UPDATE_POINTS", 455 GNUNET_CONFIGURATION_get_value_string (cfg, "sensor-update",
456 &points_list)) 456 "UPDATE_POINTS", &points_list))
457 { 457 {
458 return 0; 458 return 0;
459 } 459 }
diff --git a/src/sensor/sensor.conf.in b/src/sensor/sensor.conf.in
index a2bfe8a8e..f24503a0c 100644
--- a/src/sensor/sensor.conf.in
+++ b/src/sensor/sensor.conf.in
@@ -15,9 +15,6 @@ START_UPDATE = YES
15# If not set, will load from default location. 15# If not set, will load from default location.
16#SENSOR_DIR = 16#SENSOR_DIR =
17 17
18# Space separated list of trusted peers running update points
19UPDATE_POINTS =
20
21[sensor-analysis] 18[sensor-analysis]
22MODEL = gaussian 19MODEL = gaussian
23# How many subsequent values required to flip anomaly label. (Default: 1) 20# How many subsequent values required to flip anomaly label. (Default: 1)
@@ -27,3 +24,10 @@ CONFIRMATION_COUNT = 3
27[sensor-model-gaussian] 24[sensor-model-gaussian]
28TRAINING_WINDOW = 1000 25TRAINING_WINDOW = 1000
29CONFIDENCE_INTERVAL = 3 26CONFIDENCE_INTERVAL = 3
27
28[sensor-reporting]
29POW_MATCHING_BITS = 15
30
31[sensor-update]
32# Space separated list of trusted peers running update points
33UPDATE_POINTS =
diff --git a/src/sensor/sensor_util_lib_crypto.c b/src/sensor/sensor_util_lib_crypto.c
index e097ed3ae..bf271e792 100644
--- a/src/sensor/sensor_util_lib_crypto.c
+++ b/src/sensor/sensor_util_lib_crypto.c
@@ -257,7 +257,6 @@ GNUNET_SENSOR_crypto_pow_sign (void *msg, size_t msg_size,
257 * @param block The block received and needs to be verified 257 * @param block The block received and needs to be verified
258 * @param matching_bits Number of leading zeros in the hash used to verify pow 258 * @param matching_bits Number of leading zeros in the hash used to verify pow
259 * @param public_key Public key of the peer that sent this block 259 * @param public_key Public key of the peer that sent this block
260 * @param purpose Expected signing purpose
261 * @param payload Where to store the pointer to the payload 260 * @param payload Where to store the pointer to the payload
262 * @return Size of the payload 261 * @return Size of the payload
263 */ 262 */
@@ -265,8 +264,7 @@ size_t
265GNUNET_SENSOR_crypto_verify_pow_sign (struct GNUNET_SENSOR_crypto_pow_block * 264GNUNET_SENSOR_crypto_verify_pow_sign (struct GNUNET_SENSOR_crypto_pow_block *
266 block, int matching_bits, 265 block, int matching_bits,
267 struct GNUNET_CRYPTO_EddsaPublicKey * 266 struct GNUNET_CRYPTO_EddsaPublicKey *
268 public_key, uint32_t purpose, 267 public_key, void **payload)
269 void **payload)
270{ 268{
271 /* Check public key */ 269 /* Check public key */
272 if (0 != 270 if (0 !=
@@ -278,8 +276,9 @@ GNUNET_SENSOR_crypto_verify_pow_sign (struct GNUNET_SENSOR_crypto_pow_block *
278 } 276 }
279 /* Check signature */ 277 /* Check signature */
280 if (GNUNET_OK != 278 if (GNUNET_OK !=
281 GNUNET_CRYPTO_eddsa_verify (purpose, &block->purpose, &block->signature, 279 GNUNET_CRYPTO_eddsa_verify
282 public_key)) 280 (GNUNET_SIGNATURE_PURPOSE_SENSOR_ANOMALY_REPORT, &block->purpose,
281 &block->signature, public_key))
283 { 282 {
284 LOG (GNUNET_ERROR_TYPE_WARNING, "Invalid signature.\n"); 283 LOG (GNUNET_ERROR_TYPE_WARNING, "Invalid signature.\n");
285 return 0; 284 return 0;
diff --git a/src/sensor/test_pow_sign.c b/src/sensor/test_pow_sign.c
index e1e78a721..af9f6eb52 100644
--- a/src/sensor/test_pow_sign.c
+++ b/src/sensor/test_pow_sign.c
@@ -76,12 +76,12 @@ static char msg[MSG_SIZE];
76/** 76/**
77 * Private key of sending peer 77 * Private key of sending peer
78 */ 78 */
79struct GNUNET_CRYPTO_EddsaPrivateKey *private_key; 79static struct GNUNET_CRYPTO_EddsaPrivateKey *private_key;
80 80
81/** 81/**
82 * Public key of sending peer 82 * Public key of sending peer
83 */ 83 */
84struct GNUNET_CRYPTO_EddsaPublicKey *public_key; 84static struct GNUNET_CRYPTO_EddsaPublicKey *public_key;
85 85
86 86
87/** 87/**
@@ -117,17 +117,13 @@ pow_cb (void *cls, struct GNUNET_SENSOR_crypto_pow_block *block)
117 /* Test that the block is valid */ 117 /* Test that the block is valid */
118 GNUNET_assert (MSG_SIZE == 118 GNUNET_assert (MSG_SIZE ==
119 GNUNET_SENSOR_crypto_verify_pow_sign (block, MATCHING_BITS, 119 GNUNET_SENSOR_crypto_verify_pow_sign (block, MATCHING_BITS,
120 public_key, 120 public_key, &response));
121 GNUNET_SIGNATURE_PURPOSE_SENSOR_ANOMALY_REPORT,
122 &response));
123 GNUNET_assert (0 == memcmp (msg, response, MSG_SIZE)); 121 GNUNET_assert (0 == memcmp (msg, response, MSG_SIZE));
124 /* Modify the payload and test that verification returns invalid */ 122 /* Modify the payload and test that verification returns invalid */
125 block->pow++; 123 block->pow++;
126 GNUNET_assert (0 == 124 GNUNET_assert (0 ==
127 GNUNET_SENSOR_crypto_verify_pow_sign (block, MATCHING_BITS, 125 GNUNET_SENSOR_crypto_verify_pow_sign (block, MATCHING_BITS,
128 public_key, 126 public_key, &response));
129 GNUNET_SIGNATURE_PURPOSE_SENSOR_ANOMALY_REPORT,
130 &response));
131 ok = 0; 127 ok = 0;
132 GNUNET_SCHEDULER_cancel (shutdown_task); 128 GNUNET_SCHEDULER_cancel (shutdown_task);
133 GNUNET_SCHEDULER_add_now (do_shutdown, NULL); 129 GNUNET_SCHEDULER_add_now (do_shutdown, NULL);