diff options
Diffstat (limited to 'src/sensor/gnunet-service-sensor_reporting.c')
-rw-r--r-- | src/sensor/gnunet-service-sensor_reporting.c | 58 |
1 files changed, 35 insertions, 23 deletions
diff --git a/src/sensor/gnunet-service-sensor_reporting.c b/src/sensor/gnunet-service-sensor_reporting.c index a2015f48e..6267e9f2a 100644 --- a/src/sensor/gnunet-service-sensor_reporting.c +++ b/src/sensor/gnunet-service-sensor_reporting.c | |||
@@ -480,7 +480,7 @@ get_cadet_peer (struct GNUNET_PeerIdentity pid) | |||
480 | cadetp->channel = | 480 | cadetp->channel = |
481 | GNUNET_CADET_channel_create (cadet, cadetp, &pid, | 481 | GNUNET_CADET_channel_create (cadet, cadetp, &pid, |
482 | GNUNET_APPLICATION_TYPE_SENSORDASHBOARD, | 482 | GNUNET_APPLICATION_TYPE_SENSORDASHBOARD, |
483 | GNUNET_CADET_OPTION_DEFAULT); | 483 | GNUNET_CADET_OPTION_RELIABLE); |
484 | cadetp->mq = GNUNET_CADET_mq_create (cadetp->channel); | 484 | cadetp->mq = GNUNET_CADET_mq_create (cadetp->channel); |
485 | GNUNET_CONTAINER_DLL_insert (cadetp_head, cadetp_tail, cadetp); | 485 | GNUNET_CONTAINER_DLL_insert (cadetp_head, cadetp_tail, cadetp); |
486 | return cadetp; | 486 | return cadetp; |
@@ -585,9 +585,10 @@ handle_anomaly_report (void *cls, const struct GNUNET_PeerIdentity *other, | |||
585 | { | 585 | { |
586 | struct GNUNET_SENSOR_AnomalyReportMessage *arm; | 586 | struct GNUNET_SENSOR_AnomalyReportMessage *arm; |
587 | struct GNUNET_SENSOR_SensorInfo *sensor; | 587 | struct GNUNET_SENSOR_SensorInfo *sensor; |
588 | struct AnomalyInfo *ai; | 588 | struct AnomalyInfo *my_anomaly_info; |
589 | struct CadetPeer *cadetp; | 589 | struct CadetPeer *cadetp; |
590 | int peer_in_list; | 590 | int peer_anomalous; |
591 | int peer_in_anomalous_list; | ||
591 | 592 | ||
592 | arm = (struct GNUNET_SENSOR_AnomalyReportMessage *) message; | 593 | arm = (struct GNUNET_SENSOR_AnomalyReportMessage *) message; |
593 | sensor = GNUNET_CONTAINER_multihashmap_get (sensors, &arm->sensorname_hash); | 594 | sensor = GNUNET_CONTAINER_multihashmap_get (sensors, &arm->sensorname_hash); |
@@ -600,34 +601,39 @@ handle_anomaly_report (void *cls, const struct GNUNET_PeerIdentity *other, | |||
600 | GNUNET_i2s (other)); | 601 | GNUNET_i2s (other)); |
601 | return GNUNET_OK; | 602 | return GNUNET_OK; |
602 | } | 603 | } |
603 | ai = get_anomaly_info_by_sensor (sensor); | 604 | my_anomaly_info = get_anomaly_info_by_sensor (sensor); |
604 | GNUNET_assert (NULL != ai); | 605 | GNUNET_assert (NULL != my_anomaly_info); |
605 | peer_in_list = | 606 | peer_in_anomalous_list = |
606 | GNUNET_CONTAINER_multipeermap_contains (ai->anomalous_neighbors, other); | 607 | GNUNET_CONTAINER_multipeermap_contains |
607 | if (GNUNET_YES == ai->anomalous) | 608 | (my_anomaly_info->anomalous_neighbors, other); |
609 | peer_anomalous = ntohs (arm->anomalous); | ||
610 | if (GNUNET_YES == peer_anomalous) | ||
608 | { | 611 | { |
609 | if (GNUNET_YES == peer_in_list) | 612 | if (GNUNET_YES == peer_in_anomalous_list) /* repeated positive report */ |
610 | GNUNET_break_op (0); | 613 | GNUNET_break_op (0); |
611 | else | 614 | else |
612 | GNUNET_CONTAINER_multipeermap_put (ai->anomalous_neighbors, other, NULL, | 615 | GNUNET_CONTAINER_multipeermap_put (my_anomaly_info->anomalous_neighbors, |
616 | other, NULL, | ||
613 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); | 617 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); |
614 | } | 618 | } |
615 | else | 619 | else |
616 | { | 620 | { |
617 | if (GNUNET_NO == peer_in_list) | 621 | if (GNUNET_NO == peer_in_anomalous_list) /* repeated negative report */ |
618 | GNUNET_break_op (0); | 622 | GNUNET_break_op (0); |
619 | else | 623 | else |
620 | GNUNET_CONTAINER_multipeermap_remove_all (ai->anomalous_neighbors, other); | 624 | GNUNET_CONTAINER_multipeermap_remove_all |
625 | (my_anomaly_info->anomalous_neighbors, other); | ||
621 | } | 626 | } |
622 | /* Send anomaly update to collection point */ | 627 | /* Send anomaly update to collection point only if I have the same anomaly */ |
623 | if (NULL != ai->sensor->collection_point && | 628 | if (GNUNET_YES == my_anomaly_info->anomalous && |
624 | GNUNET_YES == ai->sensor->report_anomalies) | 629 | NULL != sensor->collection_point && |
630 | GNUNET_YES == sensor->report_anomalies) | ||
625 | { | 631 | { |
626 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 632 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
627 | "Sending anomaly report to collection point `%s'.\n", | 633 | "Neighbor update triggered sending anomaly report to collection point `%s'.\n", |
628 | GNUNET_i2s (ai->sensor->collection_point)); | 634 | GNUNET_i2s (sensor->collection_point)); |
629 | cadetp = get_cadet_peer (*ai->sensor->collection_point); | 635 | cadetp = get_cadet_peer (*sensor->collection_point); |
630 | send_anomaly_report (cadetp->mq, ai, GNUNET_NO); | 636 | send_anomaly_report (cadetp->mq, my_anomaly_info, GNUNET_NO); |
631 | } | 637 | } |
632 | return GNUNET_OK; | 638 | return GNUNET_OK; |
633 | } | 639 | } |
@@ -687,6 +693,8 @@ core_disconnect_cb (void *cls, const struct GNUNET_PeerIdentity *peer) | |||
687 | 693 | ||
688 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&mypeerid, peer)) | 694 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&mypeerid, peer)) |
689 | return; | 695 | return; |
696 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Core peer `%s' disconnected.\n", | ||
697 | GNUNET_i2s (peer)); | ||
690 | neighborhood--; | 698 | neighborhood--; |
691 | corep = corep_head; | 699 | corep = corep_head; |
692 | while (NULL != corep) | 700 | while (NULL != corep) |
@@ -716,6 +724,8 @@ core_connect_cb (void *cls, const struct GNUNET_PeerIdentity *peer) | |||
716 | 724 | ||
717 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&mypeerid, peer)) | 725 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&mypeerid, peer)) |
718 | return; | 726 | return; |
727 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Connected to core peer `%s'.\n", | ||
728 | GNUNET_i2s (peer)); | ||
719 | neighborhood++; | 729 | neighborhood++; |
720 | corep = GNUNET_new (struct CorePeer); | 730 | corep = GNUNET_new (struct CorePeer); |
721 | corep->peer_id = (struct GNUNET_PeerIdentity *) peer; | 731 | corep->peer_id = (struct GNUNET_PeerIdentity *) peer; |
@@ -725,11 +735,13 @@ core_connect_cb (void *cls, const struct GNUNET_PeerIdentity *peer) | |||
725 | ai = ai_head; | 735 | ai = ai_head; |
726 | while (NULL != ai) | 736 | while (NULL != ai) |
727 | { | 737 | { |
728 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
729 | "Updating newly connected neighbor `%s' with anomalous sensor.\n", | ||
730 | GNUNET_i2s (peer)); | ||
731 | if (GNUNET_YES == ai->anomalous) | 738 | if (GNUNET_YES == ai->anomalous) |
739 | { | ||
740 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
741 | "Updating newly connected neighbor `%s' with anomalous sensor.\n", | ||
742 | GNUNET_i2s (peer)); | ||
732 | send_anomaly_report (corep->mq, ai, GNUNET_YES); | 743 | send_anomaly_report (corep->mq, ai, GNUNET_YES); |
744 | } | ||
733 | ai = ai->next; | 745 | ai = ai->next; |
734 | } | 746 | } |
735 | } | 747 | } |
@@ -839,7 +851,7 @@ SENSOR_reporting_anomaly_update (struct GNUNET_SENSOR_SensorInfo *sensor, | |||
839 | GNUNET_YES == ai->sensor->report_anomalies) | 851 | GNUNET_YES == ai->sensor->report_anomalies) |
840 | { | 852 | { |
841 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 853 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
842 | "Sending anomaly report to collection point `%s'.\n", | 854 | "Local anomaly update triggered sending anomaly report to collection point `%s'.\n", |
843 | GNUNET_i2s (ai->sensor->collection_point)); | 855 | GNUNET_i2s (ai->sensor->collection_point)); |
844 | cadetp = get_cadet_peer (*ai->sensor->collection_point); | 856 | cadetp = get_cadet_peer (*ai->sensor->collection_point); |
845 | send_anomaly_report (cadetp->mq, ai, GNUNET_NO); | 857 | send_anomaly_report (cadetp->mq, ai, GNUNET_NO); |