aboutsummaryrefslogtreecommitdiff
path: root/src/sensor/gnunet-service-sensor_reporting.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/sensor/gnunet-service-sensor_reporting.c')
-rw-r--r--src/sensor/gnunet-service-sensor_reporting.c60
1 files changed, 43 insertions, 17 deletions
diff --git a/src/sensor/gnunet-service-sensor_reporting.c b/src/sensor/gnunet-service-sensor_reporting.c
index a9d5d2e30..a2015f48e 100644
--- a/src/sensor/gnunet-service-sensor_reporting.c
+++ b/src/sensor/gnunet-service-sensor_reporting.c
@@ -472,6 +472,8 @@ get_cadet_peer (struct GNUNET_PeerIdentity pid)
472 return cadetp; 472 return cadetp;
473 cadetp = cadetp->next; 473 cadetp = cadetp->next;
474 } 474 }
475 LOG (GNUNET_ERROR_TYPE_DEBUG, "Creating a CADET connection to peer `%s'.\n",
476 GNUNET_i2s (&pid));
475 /* Not found, create struct and channel */ 477 /* Not found, create struct and channel */
476 cadetp = GNUNET_new (struct CadetPeer); 478 cadetp = GNUNET_new (struct CadetPeer);
477 cadetp->peer_id = pid; 479 cadetp->peer_id = pid;
@@ -490,23 +492,26 @@ get_cadet_peer (struct GNUNET_PeerIdentity pid)
490 * MQ envelope. 492 * MQ envelope.
491 * 493 *
492 * @param ai Anomaly info struct to use 494 * @param ai Anomaly info struct to use
495 * @param type Message type
493 * @return Envelope with message 496 * @return Envelope with message
494 */ 497 */
495static struct GNUNET_MQ_Envelope * 498static struct GNUNET_MQ_Envelope *
496create_anomaly_report_message (struct AnomalyInfo *ai) 499create_anomaly_report_message (struct AnomalyInfo *ai, int type)
497{ 500{
498 struct GNUNET_SENSOR_AnomalyReportMessage *arm; 501 struct GNUNET_SENSOR_AnomalyReportMessage *arm;
499 struct GNUNET_MQ_Envelope *ev; 502 struct GNUNET_MQ_Envelope *ev;
500 503
501 ev = GNUNET_MQ_msg (arm, GNUNET_MESSAGE_TYPE_SENSOR_ANOMALY_REPORT); 504 ev = GNUNET_MQ_msg (arm, type);
502 GNUNET_CRYPTO_hash (ai->sensor->name, strlen (ai->sensor->name) + 1, 505 GNUNET_CRYPTO_hash (ai->sensor->name, strlen (ai->sensor->name) + 1,
503 &arm->sensorname_hash); 506 &arm->sensorname_hash);
504 arm->sensorversion_major = htons (ai->sensor->version_major); 507 arm->sensorversion_major = htons (ai->sensor->version_major);
505 arm->sensorversion_minor = htons (ai->sensor->version_minor); 508 arm->sensorversion_minor = htons (ai->sensor->version_minor);
506 arm->anomalous = htons (ai->anomalous); 509 arm->anomalous = htons (ai->anomalous);
507 arm->anomalous_neighbors = 510 arm->anomalous_neighbors =
508 ((float) GNUNET_CONTAINER_multipeermap_size (ai->anomalous_neighbors)) / 511 (0 ==
509 neighborhood; 512 neighborhood) ? 0 : ((float)
513 GNUNET_CONTAINER_multipeermap_size
514 (ai->anomalous_neighbors)) / neighborhood;
510 return ev; 515 return ev;
511} 516}
512 517
@@ -542,13 +547,20 @@ create_value_message (struct ValueInfo *vi)
542 * 547 *
543 * @param mq Message queue to put the message in 548 * @param mq Message queue to put the message in
544 * @param ai Anomaly info to report 549 * @param ai Anomaly info to report
550 * @param p2p Is the report sent to a neighboring peer
545 */ 551 */
546static void 552static void
547send_anomaly_report (struct GNUNET_MQ_Handle *mq, struct AnomalyInfo *ai) 553send_anomaly_report (struct GNUNET_MQ_Handle *mq, struct AnomalyInfo *ai,
554 int p2p)
548{ 555{
549 struct GNUNET_MQ_Envelope *ev; 556 struct GNUNET_MQ_Envelope *ev;
557 int type;
550 558
551 ev = create_anomaly_report_message (ai); 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);
552 GNUNET_MQ_send (mq, ev); 564 GNUNET_MQ_send (mq, ev);
553} 565}
554 566
@@ -579,8 +591,9 @@ handle_anomaly_report (void *cls, const struct GNUNET_PeerIdentity *other,
579 591
580 arm = (struct GNUNET_SENSOR_AnomalyReportMessage *) message; 592 arm = (struct GNUNET_SENSOR_AnomalyReportMessage *) message;
581 sensor = GNUNET_CONTAINER_multihashmap_get (sensors, &arm->sensorname_hash); 593 sensor = GNUNET_CONTAINER_multihashmap_get (sensors, &arm->sensorname_hash);
582 if (NULL == sensor || sensor->version_major != arm->sensorversion_major || 594 if (NULL == sensor ||
583 sensor->version_minor != arm->sensorversion_minor) 595 sensor->version_major != ntohs (arm->sensorversion_major) ||
596 sensor->version_minor != ntohs (arm->sensorversion_minor))
584 { 597 {
585 LOG (GNUNET_ERROR_TYPE_WARNING, 598 LOG (GNUNET_ERROR_TYPE_WARNING,
586 "I don't have the sensor reported by the peer `%s'.\n", 599 "I don't have the sensor reported by the peer `%s'.\n",
@@ -610,8 +623,11 @@ handle_anomaly_report (void *cls, const struct GNUNET_PeerIdentity *other,
610 if (NULL != ai->sensor->collection_point && 623 if (NULL != ai->sensor->collection_point &&
611 GNUNET_YES == ai->sensor->report_anomalies) 624 GNUNET_YES == ai->sensor->report_anomalies)
612 { 625 {
626 LOG (GNUNET_ERROR_TYPE_DEBUG,
627 "Sending anomaly report to collection point `%s'.\n",
628 GNUNET_i2s (ai->sensor->collection_point));
613 cadetp = get_cadet_peer (*ai->sensor->collection_point); 629 cadetp = get_cadet_peer (*ai->sensor->collection_point);
614 send_anomaly_report (cadetp->mq, ai); 630 send_anomaly_report (cadetp->mq, ai, GNUNET_NO);
615 } 631 }
616 return GNUNET_OK; 632 return GNUNET_OK;
617} 633}
@@ -675,7 +691,7 @@ core_disconnect_cb (void *cls, const struct GNUNET_PeerIdentity *peer)
675 corep = corep_head; 691 corep = corep_head;
676 while (NULL != corep) 692 while (NULL != corep)
677 { 693 {
678 if (peer == corep->peer_id) 694 if (0 == GNUNET_CRYPTO_cmp_peer_identity (peer, corep->peer_id))
679 { 695 {
680 GNUNET_CONTAINER_DLL_remove (corep_head, corep_tail, corep); 696 GNUNET_CONTAINER_DLL_remove (corep_head, corep_tail, corep);
681 destroy_core_peer (corep); 697 destroy_core_peer (corep);
@@ -683,9 +699,6 @@ core_disconnect_cb (void *cls, const struct GNUNET_PeerIdentity *peer)
683 } 699 }
684 corep = corep->next; 700 corep = corep->next;
685 } 701 }
686 LOG (GNUNET_ERROR_TYPE_ERROR,
687 _("Received disconnect notification from CORE"
688 " for a peer we didn't know about.\n"));
689} 702}
690 703
691 704
@@ -712,8 +725,11 @@ core_connect_cb (void *cls, const struct GNUNET_PeerIdentity *peer)
712 ai = ai_head; 725 ai = ai_head;
713 while (NULL != ai) 726 while (NULL != ai)
714 { 727 {
728 LOG (GNUNET_ERROR_TYPE_DEBUG,
729 "Updating newly connected neighbor `%s' with anomalous sensor.\n",
730 GNUNET_i2s (peer));
715 if (GNUNET_YES == ai->anomalous) 731 if (GNUNET_YES == ai->anomalous)
716 send_anomaly_report (corep->mq, ai); 732 send_anomaly_report (corep->mq, ai, GNUNET_YES);
717 ai = ai->next; 733 ai = ai->next;
718 } 734 }
719} 735}
@@ -773,6 +789,9 @@ cadet_channel_destroyed (void *cls, const struct GNUNET_CADET_Channel *channel,
773 789
774 if (GNUNET_YES == cadetp->destroying) 790 if (GNUNET_YES == cadetp->destroying)
775 return; 791 return;
792 LOG (GNUNET_ERROR_TYPE_DEBUG,
793 "CADET channel was destroyed by remote peer `%s' or failed to start.\n",
794 GNUNET_i2s (&cadetp->peer_id));
776 GNUNET_CONTAINER_DLL_remove (cadetp_head, cadetp_tail, cadetp); 795 GNUNET_CONTAINER_DLL_remove (cadetp_head, cadetp_tail, cadetp);
777 cadetp->channel = NULL; 796 cadetp->channel = NULL;
778 destroy_cadet_peer (cadetp); 797 destroy_cadet_peer (cadetp);
@@ -801,6 +820,7 @@ SENSOR_reporting_anomaly_update (struct GNUNET_SENSOR_SensorInfo *sensor,
801 820
802 if (GNUNET_NO == module_running) 821 if (GNUNET_NO == module_running)
803 return; 822 return;
823 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received an external anomaly update.\n");
804 ai = get_anomaly_info_by_sensor (sensor); 824 ai = get_anomaly_info_by_sensor (sensor);
805 GNUNET_assert (NULL != ai); 825 GNUNET_assert (NULL != ai);
806 ai->anomalous = anomalous; 826 ai->anomalous = anomalous;
@@ -808,15 +828,21 @@ SENSOR_reporting_anomaly_update (struct GNUNET_SENSOR_SensorInfo *sensor,
808 corep = corep_head; 828 corep = corep_head;
809 while (NULL != corep) 829 while (NULL != corep)
810 { 830 {
811 send_anomaly_report (corep->mq, ai); 831 LOG (GNUNET_ERROR_TYPE_DEBUG,
832 "Sending an anomaly report to neighbor `%s'.\n",
833 GNUNET_i2s (corep->peer_id));
834 send_anomaly_report (corep->mq, ai, GNUNET_YES);
812 corep = corep->next; 835 corep = corep->next;
813 } 836 }
814 /* Report change to collection point if need */ 837 /* Report change to collection point if need */
815 if (NULL != ai->sensor->collection_point && 838 if (NULL != ai->sensor->collection_point &&
816 GNUNET_YES == ai->sensor->report_anomalies) 839 GNUNET_YES == ai->sensor->report_anomalies)
817 { 840 {
841 LOG (GNUNET_ERROR_TYPE_DEBUG,
842 "Sending anomaly report to collection point `%s'.\n",
843 GNUNET_i2s (ai->sensor->collection_point));
818 cadetp = get_cadet_peer (*ai->sensor->collection_point); 844 cadetp = get_cadet_peer (*ai->sensor->collection_point);
819 send_anomaly_report (cadetp->mq, ai); 845 send_anomaly_report (cadetp->mq, ai, GNUNET_NO);
820 } 846 }
821} 847}
822 848
@@ -924,7 +950,7 @@ SENSOR_reporting_start (const struct GNUNET_CONFIGURATION_Handle *c,
924 struct GNUNET_CONTAINER_MultiHashMap *s) 950 struct GNUNET_CONTAINER_MultiHashMap *s)
925{ 951{
926 static struct GNUNET_CORE_MessageHandler core_handlers[] = { 952 static struct GNUNET_CORE_MessageHandler core_handlers[] = {
927 {&handle_anomaly_report, GNUNET_MESSAGE_TYPE_SENSOR_ANOMALY_REPORT, 953 {&handle_anomaly_report, GNUNET_MESSAGE_TYPE_SENSOR_ANOMALY_REPORT_P2P,
928 sizeof (struct GNUNET_SENSOR_AnomalyReportMessage)}, 954 sizeof (struct GNUNET_SENSOR_AnomalyReportMessage)},
929 {NULL, 0, 0} 955 {NULL, 0, 0}
930 }; 956 };