gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r34146 - in gnunet/src: include sensordashboard


From: gnunet
Subject: [GNUnet-SVN] r34146 - in gnunet/src: include sensordashboard
Date: Tue, 12 Aug 2014 13:38:23 +0200

Author: otarabai
Date: 2014-08-12 13:38:22 +0200 (Tue, 12 Aug 2014)
New Revision: 34146

Modified:
   gnunet/src/include/gnunet_sensor_util_lib.h
   gnunet/src/sensordashboard/gnunet-service-sensordashboard.c
Log:
sensordashboard: storing received anomaly reports


Modified: gnunet/src/include/gnunet_sensor_util_lib.h
===================================================================
--- gnunet/src/include/gnunet_sensor_util_lib.h 2014-08-12 10:57:54 UTC (rev 
34145)
+++ gnunet/src/include/gnunet_sensor_util_lib.h 2014-08-12 11:38:22 UTC (rev 
34146)
@@ -325,7 +325,7 @@
   /**
    * New anomaly status
    */
-  uint8_t anomalous;
+  uint16_t anomalous;
 
   /**
    * Percentage of neighbors reported the same anomaly

Modified: gnunet/src/sensordashboard/gnunet-service-sensordashboard.c
===================================================================
--- gnunet/src/sensordashboard/gnunet-service-sensordashboard.c 2014-08-12 
10:57:54 UTC (rev 34145)
+++ gnunet/src/sensordashboard/gnunet-service-sensordashboard.c 2014-08-12 
11:38:22 UTC (rev 34146)
@@ -154,11 +154,18 @@
 static struct GNUNET_PEERSTORE_Handle *peerstore;
 
 /**
- * Name of this subsystem to be used for peerstore operations
+ * Name of the subsystem used to store sensor values received from remote peers
+ * in PEERSTORE
  */
-static char *subsystem = "sensordashboard";
+static char *values_subsystem = "sensordashboard-values";
 
 /**
+ * Name of the subsystem used to store anomaly reports received from remote
+ * peers in PEERSTORE
+ */
+static char *anomalies_subsystem = "sensordashboard-anomalies";
+
+/**
  * Head of a DLL of all connected client peers
  */
 static struct ClientPeerContext *cp_head;
@@ -393,6 +400,51 @@
 
 
 /**
+ * Called with any anomaly report received from a peer.
+ *
+ * Each time the function must call #GNUNET_CADET_receive_done on the channel
+ * in order to receive the next message. This doesn't need to be immediate:
+ * can be delayed if some processing is done on the message.
+ *
+ * @param cls Closure (set from #GNUNET_CADET_connect).
+ * @param channel Connection to the other end.
+ * @param channel_ctx Place to store local state associated with the channel.
+ * @param message The actual message.
+ * @return #GNUNET_OK to keep the channel open,
+ *         #GNUNET_SYSERR to close it (signal serious error).
+ */
+static int
+handle_anomaly_report (void *cls, struct GNUNET_CADET_Channel *channel,
+                       void **channel_ctx,
+                       const struct GNUNET_MessageHeader *message)
+{
+  struct ClientPeerContext *cp = *channel_ctx;
+  struct GNUNET_SENSOR_AnomalyReportMessage *anomaly_msg;
+  struct GNUNET_SENSOR_SensorInfo *sensor;
+  uint16_t anomalous;
+  struct GNUNET_TIME_Absolute expiry;
+
+  anomaly_msg = (struct GNUNET_SENSOR_AnomalyReportMessage *) message;
+  sensor =
+      GNUNET_CONTAINER_multihashmap_get (sensors,
+                                         &anomaly_msg->sensorname_hash);
+  if (NULL == sensor)
+  {
+    GNUNET_break_op (0);
+    return GNUNET_SYSERR;
+  }
+  anomalous = ntohs (anomaly_msg->anomalous);
+  expiry =
+      (GNUNET_YES ==
+       anomalous) ? GNUNET_TIME_UNIT_FOREVER_ABS : GNUNET_TIME_absolute_get ();
+  GNUNET_PEERSTORE_store (peerstore, anomalies_subsystem, &cp->peerid,
+                          sensor->name, &anomalous, sizeof (anomalous), expiry,
+                          GNUNET_PEERSTORE_STOREOPTION_REPLACE, NULL, NULL);
+  return GNUNET_OK;
+}
+
+
+/**
  * Iterate over defined sensors, creates and sends brief sensor information to
  * given client peer over CADET.
  *
@@ -501,7 +553,7 @@
     return NULL;
   }
   if ((sensor->version_minor != ntohs (vm->sensorversion_minor)) ||
-        (sensor->version_major != ntohs (vm->sensorversion_major)))
+      (sensor->version_major != ntohs (vm->sensorversion_major)))
   {
     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
                 "Sensor version mismatch in reading message.\n");
@@ -558,7 +610,7 @@
               "# Sensor name: `%s'\n" "# Timestamp: %" PRIu64 "\n"
               "# Value size: %" PRIu64 ".\n", GNUNET_i2s (&cp->peerid),
               reading->sensor->name, reading->timestamp, reading->value_size);
-  GNUNET_PEERSTORE_store (peerstore, subsystem, &cp->peerid,
+  GNUNET_PEERSTORE_store (peerstore, values_subsystem, &cp->peerid,
                           reading->sensor->name, reading->value,
                           reading->value_size, GNUNET_TIME_UNIT_FOREVER_ABS,
                           GNUNET_PEERSTORE_STOREOPTION_MULTIPLE, NULL, NULL);
@@ -726,6 +778,9 @@
     {&handle_sensor_full_req,
      GNUNET_MESSAGE_TYPE_SENSOR_FULL_REQ,
      sizeof (struct GNUNET_MessageHeader)},
+    {&handle_anomaly_report,
+     GNUNET_MESSAGE_TYPE_SENSOR_ANOMALY_REPORT,
+     sizeof (struct GNUNET_SENSOR_AnomalyReportMessage)},
     {NULL, 0, 0}
   };
   static uint32_t cadet_ports[] = {




reply via email to

[Prev in Thread] Current Thread [Next in Thread]