gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r34042 - in gnunet/src: include sensor sensor/sensors senso


From: gnunet
Subject: [GNUnet-SVN] r34042 - in gnunet/src: include sensor sensor/sensors sensordashboard
Date: Thu, 24 Jul 2014 16:27:25 +0200

Author: otarabai
Date: 2014-07-24 16:27:25 +0200 (Thu, 24 Jul 2014)
New Revision: 34042

Modified:
   gnunet/src/include/gnunet_sensor_util_lib.h
   gnunet/src/sensor/gnunet-service-sensor-analysis.c
   gnunet/src/sensor/gnunet-service-sensor-reporting.c
   gnunet/src/sensor/gnunet-service-sensor.c
   gnunet/src/sensor/sensor_util_lib.c
   gnunet/src/sensor/sensors/peerstore-memory
   gnunet/src/sensordashboard/gnunet-service-sensordashboard.c
Log:
sensor: minor fixes


Modified: gnunet/src/include/gnunet_sensor_util_lib.h
===================================================================
--- gnunet/src/include/gnunet_sensor_util_lib.h 2014-07-24 13:39:33 UTC (rev 
34041)
+++ gnunet/src/include/gnunet_sensor_util_lib.h 2014-07-24 14:27:25 UTC (rev 
34042)
@@ -38,7 +38,7 @@
 /**
  * Structure containing sensor definition
  */
-struct SensorInfo
+struct GNUNET_SENSOR_SensorInfo
 {
 
   /**
@@ -196,7 +196,7 @@
   /**
    * Sensor this reading is related to
    */
-  struct SensorInfo *sensor;
+  struct GNUNET_SENSOR_SensorInfo *sensor;
 
   /**
    * Timestamp of taking the reading
@@ -257,8 +257,10 @@
   uint16_t value_size;
 
 };
+
 GNUNET_NETWORK_STRUCT_END
 
+
 /**
  * Reads sensor definitions from local data files
  *
@@ -267,6 +269,7 @@
 struct GNUNET_CONTAINER_MultiHashMap *
 GNUNET_SENSOR_load_all_sensors ();
 
+
 /*
  * Get path to the directory containing the sensor definition files
  *
@@ -275,16 +278,6 @@
 char *
 GNUNET_SENSOR_get_sensor_dir ();
 
-/**
- * Parses a sensor reading message struct
- *
- * @param msg message header received
- * @param sensors multihashmap of loaded sensors
- * @return sensor reading struct or NULL if error
- */
-struct GNUNET_SENSOR_Reading *
-GNUNET_SENSOR_parse_reading_message (const struct GNUNET_MessageHeader *msg,
-    struct GNUNET_CONTAINER_MultiHashMap *sensors);
 
 /**
  * Destroys a group of sensors in a hashmap and the hashmap itself

Modified: gnunet/src/sensor/gnunet-service-sensor-analysis.c
===================================================================
--- gnunet/src/sensor/gnunet-service-sensor-analysis.c  2014-07-24 13:39:33 UTC 
(rev 34041)
+++ gnunet/src/sensor/gnunet-service-sensor-analysis.c  2014-07-24 14:27:25 UTC 
(rev 34042)
@@ -51,7 +51,7 @@
   /*
    * Pointer to sensor info structure
    */
-  struct SensorInfo *sensor;
+  struct GNUNET_SENSOR_SensorInfo *sensor;
 
   /*
    * Watcher of sensor values
@@ -190,7 +190,7 @@
  *
  * @param cls unused
  * @param key unused
- * @param value a 'struct SensorInfo *' with sensor information
+ * @param value a 'struct GNUNET_SENSOR_SensorInfo *' with sensor information
  * @return #GNUNET_YES to continue iterations
  */
 static int
@@ -198,7 +198,7 @@
     const struct GNUNET_HashCode *key,
     void *value)
 {
-  struct SensorInfo *sensor = value;
+  struct GNUNET_SENSOR_SensorInfo *sensor = value;
   struct SensorModel *sensor_model;
 
   if (0 != strcmp("numeric", sensor->expected_datatype))

Modified: gnunet/src/sensor/gnunet-service-sensor-reporting.c
===================================================================
--- gnunet/src/sensor/gnunet-service-sensor-reporting.c 2014-07-24 13:39:33 UTC 
(rev 34041)
+++ gnunet/src/sensor/gnunet-service-sensor-reporting.c 2014-07-24 14:27:25 UTC 
(rev 34042)
@@ -57,7 +57,7 @@
   /**
    * Sensor information
    */
-  struct SensorInfo *sensor;
+  struct GNUNET_SENSOR_SensorInfo *sensor;
 
   /**
    * Collection point reporting task
@@ -393,7 +393,7 @@
                          const struct GNUNET_SCHEDULER_TaskContext* tc)
 {
   struct ReportingContext *rc = cls;
-  struct SensorInfo *sensor = rc->sensor;
+  struct GNUNET_SENSOR_SensorInfo *sensor = rc->sensor;
   struct CadetChannelContext *cc;
   struct GNUNET_SENSOR_ReadingMessage *msg;
   size_t msg_size;
@@ -446,8 +446,8 @@
  */
 static int
 sensor_watch_cb (void *cls,
-    struct GNUNET_PEERSTORE_Record *record,
-    char *emsg)
+                 struct GNUNET_PEERSTORE_Record *record,
+                 char *emsg)
 {
   struct ReportingContext *rc = cls;
 
@@ -477,15 +477,15 @@
  *
  * @param cls unused
  * @param key unused
- * @param value a 'struct SensorInfo *' with sensor information
+ * @param value a `struct GNUNET_SENSOR_SensorInfo *` with sensor information
  * @return #GNUNET_YES to continue iterations
  */
 static int
 init_sensor_reporting (void *cls,
-    const struct GNUNET_HashCode *key,
-    void *value)
+                       const struct GNUNET_HashCode *key,
+                       void *value)
 {
-  struct SensorInfo *sensor = value;
+  struct GNUNET_SENSOR_SensorInfo *sensor = value;
   struct ReportingContext *rc;
 
   if (NULL == sensor->collection_point &&
@@ -548,8 +548,8 @@
   if (GNUNET_YES == cc->destroying)
     return;
   LOG (GNUNET_ERROR_TYPE_DEBUG,
-      "Received a `channel destroyed' notification from CADET, "
-      "cleaning up.\n");
+       "Received a `channel destroyed' notification from CADET, "
+       "cleaning up.\n");
   GNUNET_CONTAINER_DLL_remove (cc_head, cc_tail, cc);
   cc->c = NULL;
   destroy_cadet_channel_context (cc);

Modified: gnunet/src/sensor/gnunet-service-sensor.c
===================================================================
--- gnunet/src/sensor/gnunet-service-sensor.c   2014-07-24 13:39:33 UTC (rev 
34041)
+++ gnunet/src/sensor/gnunet-service-sensor.c   2014-07-24 14:27:25 UTC (rev 
34042)
@@ -61,22 +61,25 @@
 struct GNUNET_PeerIdentity peerid;
 
 /**
- * Disable a sensor
- * Sensor will not run again unless
- * explicitly enabled or reloaded
+ * Change the state of the sensor.
+ * Write the change to file to make it persistent.
  *
- * @param sensor sensor information
+ * @param sensor sensor info struct
+ * @param state new enabled state: #GNUNET_YES / #GNUNET_NO
  */
-static void set_sensor_enabled(struct SensorInfo *sensor, int state)
+static void
+set_sensor_enabled (struct GNUNET_SENSOR_SensorInfo *sensor, int state)
 {
   GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
-      "Sensor `%s': Setting enabled to %d.\n",
-      sensor->name, state);
+             "Sensor `%s': Setting enabled to %d.\n",
+             sensor->name, state);
   sensor->enabled = GNUNET_NO;
-  GNUNET_assert(NULL != sensor->cfg);
-  GNUNET_CONFIGURATION_set_value_string(sensor->cfg, sensor->name, "ENABLED",
-      (GNUNET_YES == state)?"YES":"NO");
-  GNUNET_CONFIGURATION_write(sensor->cfg, sensor->def_file);
+  GNUNET_assert (NULL != sensor->cfg);
+  GNUNET_CONFIGURATION_set_value_string (sensor->cfg,
+                                         sensor->name,
+                                         "ENABLED",
+                                         (GNUNET_YES == state) ? "YES" : "NO");
+  GNUNET_CONFIGURATION_write (sensor->cfg, sensor->def_file);
 }
 
 /**
@@ -87,23 +90,23 @@
  */
 static void
 shutdown_task (void *cls,
-              const struct GNUNET_SCHEDULER_TaskContext *tc)
+               const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
-  SENSOR_update_stop ();
-  SENSOR_reporting_stop();
-  SENSOR_analysis_stop();
+  //SENSOR_update_stop ();
+  SENSOR_reporting_stop ();
+  SENSOR_analysis_stop ();
   GNUNET_SENSOR_destroy_sensors (sensors);
-  if(NULL != statistics)
+  if (NULL != statistics)
   {
-    GNUNET_STATISTICS_destroy(statistics, GNUNET_YES);
+    GNUNET_STATISTICS_destroy (statistics, GNUNET_YES);
     statistics = NULL;
   }
-  if(NULL != peerstore)
+  if (NULL != peerstore)
   {
-    GNUNET_PEERSTORE_disconnect(peerstore, GNUNET_YES);
+    GNUNET_PEERSTORE_disconnect (peerstore, GNUNET_YES);
     peerstore = NULL;
   }
-  GNUNET_SCHEDULER_shutdown();
+  GNUNET_SCHEDULER_shutdown ();
 }
 
 
@@ -115,19 +118,18 @@
  */
 static void
 handle_client_disconnect (void *cls,
-                         struct GNUNET_SERVER_Client
-                         * client)
+                          struct GNUNET_SERVER_Client *client)
 {
 }
 
 /**
- * Creates a structure with basic sensor info to be sent to a client
+ * Creates a structure with basic sensor info to be sent to a client.
  *
  * @param sensor sensor information
  * @return message ready to be sent to client
  */
 static struct SensorInfoMessage *
-create_sensor_info_msg(struct SensorInfo *sensor)
+create_sensor_info_msg (struct GNUNET_SENSOR_SensorInfo *sensor)
 {
   struct SensorInfoMessage *msg;
   uint16_t len;
@@ -171,14 +173,15 @@
  * @param message the actual message
  */
 static void
-handle_get_sensor (void *cls, struct GNUNET_SERVER_Client *client,
-            const struct GNUNET_MessageHeader *message)
+handle_get_sensor (void *cls,
+                   struct GNUNET_SERVER_Client *client,
+                   const struct GNUNET_MessageHeader *message)
 {
   struct GNUNET_SERVER_TransmitContext *tc;
   char *sensorname;
   size_t sensorname_len;
   struct GNUNET_HashCode key;
-  struct SensorInfo *sensorinfo;
+  struct GNUNET_SENSOR_SensorInfo *sensorinfo;
   struct SensorInfoMessage *msg;
 
   sensorname = (char *)&message[1];
@@ -188,7 +191,7 @@
   tc = GNUNET_SERVER_transmit_context_create (client);
   GNUNET_CRYPTO_hash(sensorname, sensorname_len, &key);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created key hash for requested 
sensor\n");
-  sensorinfo = (struct SensorInfo *)GNUNET_CONTAINER_multihashmap_get(sensors, 
&key);
+  sensorinfo = (struct GNUNET_SENSOR_SensorInfo 
*)GNUNET_CONTAINER_multihashmap_get(sensors, &key);
   if(NULL != sensorinfo)
   {
     msg = create_sensor_info_msg(sensorinfo);
@@ -205,15 +208,16 @@
 /**
  * Iterator for sensors and adds them to transmit context
  *
- * @param cls a 'struct GNUNET_SERVER_TransmitContext *'
+ * @param cls a `struct GNUNET_SERVER_TransmitContext *`
  * @param key hash of sensor name, key to hashmap
- * @param value a 'struct SensorInfo *'
+ * @param value a `struct GNUNET_SENSOR_SensorInfo *`
  */
-int add_sensor_to_tc(void *cls,
-    const struct GNUNET_HashCode *key, void *value)
+int add_sensor_to_tc (void *cls,
+                      const struct GNUNET_HashCode *key,
+                      void *value)
 {
   struct GNUNET_SERVER_TransmitContext *tc = cls;
-  struct SensorInfo *sensorinfo = value;
+  struct GNUNET_SENSOR_SensorInfo *sensorinfo = value;
   struct SensorInfoMessage *msg;
 
   msg = create_sensor_info_msg(sensorinfo);
@@ -251,7 +255,7 @@
  * @return #GNUNET_YES / #GNUNET_NO
  */
 static int
-should_run_sensor(struct SensorInfo *sensorinfo)
+should_run_sensor(struct GNUNET_SENSOR_SensorInfo *sensorinfo)
 {
   struct GNUNET_TIME_Absolute now;
 
@@ -280,7 +284,7 @@
 /**
  * Callback function to process statistic values
  *
- * @param cls 'struct SensorInfo *'
+ * @param cls `struct GNUNET_SENSOR_SensorInfo *`
  * @param subsystem name of subsystem that created the statistic
  * @param name the name of the datum
  * @param value the current value
@@ -293,7 +297,7 @@
     uint64_t value,
     int is_persistent)
 {
-  struct SensorInfo *sensorinfo = cls;
+  struct GNUNET_SENSOR_SensorInfo *sensorinfo = cls;
   double dvalue = (double)value;
   struct GNUNET_TIME_Absolute expiry;
 
@@ -315,13 +319,13 @@
 /**
  * Continuation called after sensor gets all gnunet statistics values
  *
- * @param cls 'struct SensorInfo *'
+ * @param cls `struct GNUNET_SENSOR_SensorInfo *`
  * @param success #GNUNET_OK if statistics were
  *        successfully obtained, #GNUNET_SYSERR if not.
  */
 void end_sensor_run_stat (void *cls, int success)
 {
-  struct SensorInfo *sensorinfo = cls;
+  struct GNUNET_SENSOR_SensorInfo *sensorinfo = cls;
 
   sensorinfo->gnunet_stat_get_handle = NULL;
   sensorinfo->running = GNUNET_NO;
@@ -337,7 +341,9 @@
  * @return size of new parsed value, 0 for error
  */
 static size_t
-parse_sensor_value (const char *value, struct SensorInfo* sensor, void **ret)
+parse_sensor_value (const char *value,
+                    struct GNUNET_SENSOR_SensorInfo *sensor,
+                    void **ret)
 {
   double *dval;
   char *endptr;
@@ -367,12 +373,12 @@
 /**
  * Callback for output of executed sensor process
  *
- * @param cls 'struct SensorInfo *'
+ * @param cls `struct GNUNET_SENSOR_SensorInfo *`
  * @param line line of output from a command, NULL for the end
  */
 void sensor_process_callback (void *cls, const char *line)
 {
-  struct SensorInfo *sensorinfo = cls;
+  struct GNUNET_SENSOR_SensorInfo *sensorinfo = cls;
   void *value;
   size_t valsize;
   struct GNUNET_TIME_Absolute expiry;
@@ -443,7 +449,7 @@
 sensor_run (void *cls,
     const struct GNUNET_SCHEDULER_TaskContext * tc)
 {
-  struct SensorInfo *sensorinfo = cls;
+  struct GNUNET_SENSOR_SensorInfo *sensorinfo = cls;
   int check_result;
   char *sensors_dir;
   char *process_path;
@@ -530,7 +536,7 @@
  *
  * @param cls unused
  * @param key hash of sensor name, key to hashmap (unused)
- * @param value a 'struct SensorInfo *'
+ * @param value a `struct GNUNET_SENSOR_SensorInfo *`
  * @return #GNUNET_YES if we should continue to
  *         iterate,
  *         #GNUNET_NO if not.
@@ -538,7 +544,7 @@
 int schedule_sensor(void *cls,
     const struct GNUNET_HashCode *key, void *value)
 {
-  struct SensorInfo *sensorinfo = value;
+  struct GNUNET_SENSOR_SensorInfo *sensorinfo = value;
 
   if(GNUNET_NO == should_run_sensor(sensorinfo))
     return GNUNET_YES;
@@ -589,17 +595,17 @@
   schedule_all_sensors();
   SENSOR_analysis_start(c, sensors);
   SENSOR_reporting_start(c, sensors);
-  SENSOR_update_start (c, sensors);
+  //SENSOR_update_start (c, sensors);
   statistics = GNUNET_STATISTICS_create("sensor", cfg);
   GNUNET_CRYPTO_get_peer_identity(cfg, &peerid);
   peerstore = GNUNET_PEERSTORE_connect(cfg);
   GNUNET_SERVER_add_handlers (server, handlers);
   GNUNET_SERVER_disconnect_notify (server, 
-                                  &handle_client_disconnect,
-                                  NULL);
+           &handle_client_disconnect,
+           NULL);
   GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
-                               &shutdown_task,
-                               NULL);
+        &shutdown_task,
+        NULL);
 }
 
 
@@ -617,8 +623,8 @@
           GNUNET_SERVICE_run (argc,
                               argv,
                               "sensor",
-                             GNUNET_SERVICE_OPTION_NONE,
-                             &run, NULL)) ? 0 : 1;
+            GNUNET_SERVICE_OPTION_NONE,
+            &run, NULL)) ? 0 : 1;
 }
 
 /* end of gnunet-service-sensor.c */

Modified: gnunet/src/sensor/sensor_util_lib.c
===================================================================
--- gnunet/src/sensor/sensor_util_lib.c 2014-07-24 13:39:33 UTC (rev 34041)
+++ gnunet/src/sensor/sensor_util_lib.c 2014-07-24 14:27:25 UTC (rev 34042)
@@ -87,10 +87,10 @@
  * @param cfg configuration handle
  * @param sectionname configuration section containing definition
  */
-static struct SensorInfo *
+static struct GNUNET_SENSOR_SensorInfo *
 load_sensor_from_cfg(struct GNUNET_CONFIGURATION_Handle *cfg, const char 
*sectionname)
 {
-  struct SensorInfo *sensor;
+  struct GNUNET_SENSOR_SensorInfo *sensor;
   char *version_str;
   char *starttime_str;
   char *endtime_str;
@@ -98,7 +98,7 @@
   char *dummy;
   struct GNUNET_CRYPTO_EddsaPublicKey public_key;
 
-  sensor = GNUNET_new(struct SensorInfo);
+  sensor = GNUNET_new(struct GNUNET_SENSOR_SensorInfo);
   //name
   sensor->name = GNUNET_strdup(sectionname);
   //version
@@ -260,12 +260,12 @@
  *
  * @param filename full path to file containing sensor definition
  */
-static struct SensorInfo *
+static struct GNUNET_SENSOR_SensorInfo *
 load_sensor_from_file(const char *filename)
 {
   struct GNUNET_CONFIGURATION_Handle *sensorcfg;
   const char *filebasename;
-  struct SensorInfo *sensor;
+  struct GNUNET_SENSOR_SensorInfo *sensor;
 
   //test file
   if(GNUNET_YES != GNUNET_DISK_file_test(filename))
@@ -303,9 +303,10 @@
  * @return 1: s1 > s2, 0: s1 == s2, -1: s1 < s2
  */
 static int
-sensor_version_compare(struct SensorInfo *s1, struct SensorInfo *s2)
+sensor_version_compare (struct GNUNET_SENSOR_SensorInfo *s1,
+                        struct GNUNET_SENSOR_SensorInfo *s2)
 {
-  if(s1->version_major == s2->version_major)
+  if (s1->version_major == s2->version_major)
     return (s1->version_minor < s2->version_minor) ? -1 : (s1->version_minor > 
s2->version_minor);
   else
     return (s1->version_major < s2->version_major) ? -1 : (s1->version_major > 
s2->version_major);
@@ -317,13 +318,15 @@
  *
  * @param sensor Sensor structure to add
  * @param map Hashmap to add to
- * @return #GNUNET_YES if added, #GNUNET_NO if not added which is not 
necessarily an error
+ * @return #GNUNET_YES if added
+ *         #GNUNET_NO if not added which is not necessarily an error
  */
 static int
-add_sensor_to_hashmap(struct SensorInfo *sensor, struct 
GNUNET_CONTAINER_MultiHashMap *map)
+add_sensor_to_hashmap (struct GNUNET_SENSOR_SensorInfo *sensor,
+                       struct GNUNET_CONTAINER_MultiHashMap *map)
 {
   struct GNUNET_HashCode key;
-  struct SensorInfo *existing;
+  struct GNUNET_SENSOR_SensorInfo *existing;
 
   GNUNET_CRYPTO_hash(sensor->name, strlen(sensor->name) + 1, &key);
   existing = GNUNET_CONTAINER_multihashmap_get(map, &key);
@@ -331,19 +334,25 @@
   {
     if(sensor_version_compare(existing, sensor) >= 0) //same or newer version 
already exist
     {
-      LOG (GNUNET_ERROR_TYPE_INFO, _("Sensor `%s' already exists with same or 
newer version\n"), sensor->name);
+      LOG (GNUNET_ERROR_TYPE_INFO,
+           _("Sensor `%s' already exists with same or newer version\n"),
+           sensor->name);
       return GNUNET_NO;
     }
     else
     {
       GNUNET_CONTAINER_multihashmap_remove(map, &key, existing); //remove the 
old version
       GNUNET_free(existing);
-      LOG (GNUNET_ERROR_TYPE_INFO, "Upgrading sensor `%s' to a newer 
version\n", sensor->name);
+      LOG (GNUNET_ERROR_TYPE_INFO,
+           "Upgrading sensor `%s' to a newer version\n",
+           sensor->name);
     }
   }
   if(GNUNET_SYSERR == GNUNET_CONTAINER_multihashmap_put(map, &key, sensor, 
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
   {
-    LOG (GNUNET_ERROR_TYPE_ERROR, _("Error adding new sensor `%s' to global 
hashmap, this should not happen\n"), sensor->name);
+    LOG (GNUNET_ERROR_TYPE_ERROR,
+         _("Error adding new sensor `%s' to global hashmap.\n"),
+         sensor->name);
     return GNUNET_NO;
   }
 
@@ -361,7 +370,7 @@
 reload_sensors_dir_cb(void *cls, const char *filename)
 {
   struct GNUNET_CONTAINER_MultiHashMap *sensors = cls;
-  struct SensorInfo *sensor;
+  struct GNUNET_SENSOR_SensorInfo *sensor;
 
   if(GNUNET_YES != GNUNET_DISK_file_test(filename))
     return GNUNET_OK;
@@ -423,131 +432,61 @@
   return sensors;
 }
 
-/**
- * Parses a sensor reading message struct
- *
- * @param msg message header received
- * @param sensors multihashmap of loaded sensors
- * @return sensor reading struct or NULL if error
- */
-struct GNUNET_SENSOR_Reading *
-GNUNET_SENSOR_parse_reading_message (const struct GNUNET_MessageHeader *msg,
-    struct GNUNET_CONTAINER_MultiHashMap *sensors)
-{
-  uint16_t msg_size;
-  struct GNUNET_SENSOR_ReadingMessage *rm;
-  uint16_t sensorname_size;
-  uint16_t value_size;
-  void *dummy;
-  char *sensorname;
-  struct GNUNET_HashCode key;
-  struct SensorInfo *sensor;
-  struct GNUNET_SENSOR_Reading *reading;
 
-  msg_size = ntohs (msg->size);
-  if (msg_size < sizeof (struct GNUNET_SENSOR_ReadingMessage))
-  {
-    LOG (GNUNET_ERROR_TYPE_WARNING, "Invalid reading message size.\n");
-    return NULL;
-  }
-  rm = (struct GNUNET_SENSOR_ReadingMessage *)msg;
-  sensorname_size = ntohs (rm->sensorname_size);
-  value_size = ntohs (rm->value_size);
-  if ((sizeof (struct GNUNET_SENSOR_ReadingMessage)
-      + sensorname_size + value_size) != msg_size)
-  {
-    LOG (GNUNET_ERROR_TYPE_WARNING, "Invalid reading message size.\n");
-    return NULL;
-  }
-  dummy = &rm[1];
-  sensorname = GNUNET_malloc (sensorname_size);
-  memcpy (sensorname, dummy, sensorname_size);
-  GNUNET_CRYPTO_hash(sensorname, sensorname_size, &key);
-  GNUNET_free (sensorname);
-  sensor = GNUNET_CONTAINER_multihashmap_get (sensors, &key);
-  if (NULL == sensor)
-  {
-    LOG (GNUNET_ERROR_TYPE_WARNING,
-        "Unknown sensor name in reading message.\n");
-    return NULL;
-  }
-  if ((sensor->version_minor != ntohs (rm->sensorversion_minor)) ||
-      (sensor->version_major != ntohs (rm->sensorversion_major)))
-  {
-    LOG (GNUNET_ERROR_TYPE_WARNING,
-        "Sensor version mismatch in reading message.\n");
-    return NULL;
-  }
-  if (0 == strcmp (sensor->expected_datatype, "numeric") &&
-      sizeof (double) != value_size)
-  {
-    LOG (GNUNET_ERROR_TYPE_WARNING,
-        "Invalid value size for a numerical sensor.\n");
-    return NULL;
-  }
-  reading = GNUNET_new (struct GNUNET_SENSOR_Reading);
-  reading->sensor = sensor;
-  reading->timestamp = GNUNET_be64toh (rm->timestamp);
-  reading->value_size = value_size;
-  reading->value = GNUNET_malloc (value_size);
-  dummy += sensorname_size;
-  memcpy (reading->value, dummy, value_size);
-  return reading;
-}
-
 /**
  * Remove sensor execution from scheduler
  *
  * @param cls unused
  * @param key hash of sensor name, key to hashmap
- * @param value a 'struct SensorInfo *'
+ * @param value a `struct GNUNET_SENSOR_SensorInfo *`
  * @return #GNUNET_YES if we should continue to
  *         iterate,
  *         #GNUNET_NO if not.
  */
 static int destroy_sensor(void *cls,
-    const struct GNUNET_HashCode *key, void *value)
+                          const struct GNUNET_HashCode *key,
+                          void *value)
 {
-  struct SensorInfo *sensorinfo = value;
+  struct GNUNET_SENSOR_SensorInfo *sensor = value;
 
-  if(GNUNET_SCHEDULER_NO_TASK != sensorinfo->execution_task)
+  if(GNUNET_SCHEDULER_NO_TASK != sensor->execution_task)
   {
-    GNUNET_SCHEDULER_cancel(sensorinfo->execution_task);
-    sensorinfo->execution_task = GNUNET_SCHEDULER_NO_TASK;
+    GNUNET_SCHEDULER_cancel(sensor->execution_task);
+    sensor->execution_task = GNUNET_SCHEDULER_NO_TASK;
   }
-  if(NULL != sensorinfo->gnunet_stat_get_handle)
+  if(NULL != sensor->gnunet_stat_get_handle)
   {
-    GNUNET_STATISTICS_get_cancel(sensorinfo->gnunet_stat_get_handle);
-    sensorinfo->gnunet_stat_get_handle = NULL;
+    GNUNET_STATISTICS_get_cancel(sensor->gnunet_stat_get_handle);
+    sensor->gnunet_stat_get_handle = NULL;
   }
-  if(NULL != sensorinfo->ext_cmd)
+  if(NULL != sensor->ext_cmd)
   {
-    GNUNET_OS_command_stop(sensorinfo->ext_cmd);
-    sensorinfo->ext_cmd = NULL;
+    GNUNET_OS_command_stop(sensor->ext_cmd);
+    sensor->ext_cmd = NULL;
   }
-  if(NULL != sensorinfo->cfg)
-    GNUNET_CONFIGURATION_destroy(sensorinfo->cfg);
-  if(NULL != sensorinfo->name)
-    GNUNET_free(sensorinfo->name);
-  if(NULL != sensorinfo->def_file)
-    GNUNET_free(sensorinfo->def_file);
-  if(NULL != sensorinfo->description)
-    GNUNET_free(sensorinfo->description);
-  if(NULL != sensorinfo->category)
-    GNUNET_free(sensorinfo->category);
-  if(NULL != sensorinfo->capabilities)
-    GNUNET_free(sensorinfo->capabilities);
-  if(NULL != sensorinfo->gnunet_stat_service)
-    GNUNET_free(sensorinfo->gnunet_stat_service);
-  if(NULL != sensorinfo->gnunet_stat_name)
-    GNUNET_free(sensorinfo->gnunet_stat_name);
-  if(NULL != sensorinfo->ext_process)
-    GNUNET_free(sensorinfo->ext_process);
-  if(NULL != sensorinfo->ext_args)
-    GNUNET_free(sensorinfo->ext_args);
-  if (NULL != sensorinfo->collection_point)
-    GNUNET_free (sensorinfo->collection_point);
-  GNUNET_free(sensorinfo);
+  if(NULL != sensor->cfg)
+    GNUNET_CONFIGURATION_destroy(sensor->cfg);
+  if(NULL != sensor->name)
+    GNUNET_free (sensor->name);
+  if(NULL != sensor->def_file)
+    GNUNET_free (sensor->def_file);
+  if(NULL != sensor->description)
+    GNUNET_free (sensor->description);
+  if(NULL != sensor->category)
+    GNUNET_free (sensor->category);
+  if(NULL != sensor->capabilities)
+    GNUNET_free (sensor->capabilities);
+  if(NULL != sensor->gnunet_stat_service)
+    GNUNET_free (sensor->gnunet_stat_service);
+  if(NULL != sensor->gnunet_stat_name)
+    GNUNET_free (sensor->gnunet_stat_name);
+  if(NULL != sensor->ext_process)
+    GNUNET_free (sensor->ext_process);
+  if(NULL != sensor->ext_args)
+    GNUNET_free (sensor->ext_args);
+  if (NULL != sensor->collection_point)
+    GNUNET_free (sensor->collection_point);
+  GNUNET_free (sensor);
   return GNUNET_YES;
 }
 

Modified: gnunet/src/sensor/sensors/peerstore-memory
===================================================================
--- gnunet/src/sensor/sensors/peerstore-memory  2014-07-24 13:39:33 UTC (rev 
34041)
+++ gnunet/src/sensor/sensors/peerstore-memory  2014-07-24 14:27:25 UTC (rev 
34042)
@@ -25,8 +25,8 @@
 EXPECTED_DATATYPE = numeric
 
 # Reporting mechanism
-#COLLECTION_POINT = NCEKA096482PC84GFTG61EHAVXY3BQDTPB5FANATQD5CDADJ2HP0
-#COLLECTION_INTERVAL = 7200
+COLLECTION_POINT = NCEKA096482PC84GFTG61EHAVXY3BQDTPB5FANATQD5CDADJ2HP0
+COLLECTION_INTERVAL = 61
 
 P2P_REPORT = NO
 #P2P_INTERVAL = 

Modified: gnunet/src/sensordashboard/gnunet-service-sensordashboard.c
===================================================================
--- gnunet/src/sensordashboard/gnunet-service-sensordashboard.c 2014-07-24 
13:39:33 UTC (rev 34041)
+++ gnunet/src/sensordashboard/gnunet-service-sensordashboard.c 2014-07-24 
14:27:25 UTC (rev 34042)
@@ -59,6 +59,11 @@
    */
   struct GNUNET_CADET_Channel *ch;
 
+  /**
+   * Are we in the process of destroying this context?
+   */
+  int destroying;
+
 };
 
 
@@ -101,6 +106,7 @@
 static void
 destroy_clientpeer (struct ClientPeerContext *cp)
 {
+  cp->destroying = GNUNET_YES;
   if (NULL != cp->ch)
   {
     GNUNET_CADET_channel_destroy (cp->ch);
@@ -109,6 +115,7 @@
   GNUNET_free (cp);
 }
 
+
 /**
  * Task run during shutdown.
  *
@@ -138,9 +145,10 @@
     peerstore = NULL;
   }
   GNUNET_SENSOR_destroy_sensors (sensors);
-  GNUNET_SCHEDULER_shutdown();
+  GNUNET_SCHEDULER_shutdown ();
 }
 
+
 /**
  * Function called whenever a channel is destroyed.  Should clean up
  * any associated state.
@@ -159,11 +167,14 @@
 {
   struct ClientPeerContext *cp = channel_ctx;
 
+  if (GNUNET_YES == cp->destroying)
+    return;
   cp->ch = NULL;
   GNUNET_CONTAINER_DLL_remove (cp_head, cp_tail, cp);
   destroy_clientpeer (cp);
 }
 
+
 /**
  * Method called whenever another peer has added us to a channel
  * the other peer initiated.
@@ -193,11 +204,86 @@
   cp = GNUNET_new (struct ClientPeerContext);
   cp->peerid = *initiator;
   cp->ch = channel;
+  cp->destroying = GNUNET_NO;
   GNUNET_CONTAINER_DLL_insert (cp_head, cp_tail, cp);
   return cp;
 }
 
+
 /**
+ * Parses a sensor reading message struct
+ *
+ * @param msg message header received
+ * @param sensors multihashmap of loaded sensors
+ * @return sensor reading struct or NULL if error
+ */
+static struct GNUNET_SENSOR_Reading *
+parse_reading_message (const struct GNUNET_MessageHeader *msg,
+                       struct GNUNET_CONTAINER_MultiHashMap *sensors)
+{
+  uint16_t msg_size;
+  struct GNUNET_SENSOR_ReadingMessage *rm;
+  uint16_t sensorname_size;
+  uint16_t value_size;
+  void *dummy;
+  char *sensorname;
+  struct GNUNET_HashCode key;
+  struct GNUNET_SENSOR_SensorInfo *sensor;
+  struct GNUNET_SENSOR_Reading *reading;
+
+  msg_size = ntohs (msg->size);
+  if (msg_size < sizeof (struct GNUNET_SENSOR_ReadingMessage))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Invalid reading message size.\n");
+    return NULL;
+  }
+  rm = (struct GNUNET_SENSOR_ReadingMessage *)msg;
+  sensorname_size = ntohs (rm->sensorname_size);
+  value_size = ntohs (rm->value_size);
+  if ((sizeof (struct GNUNET_SENSOR_ReadingMessage)
+      + sensorname_size + value_size) != msg_size)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Invalid reading message size.\n");
+    return NULL;
+  }
+  dummy = &rm[1];
+  sensorname = GNUNET_malloc (sensorname_size);
+  memcpy (sensorname, dummy, sensorname_size);
+  GNUNET_CRYPTO_hash(sensorname, sensorname_size, &key);
+  GNUNET_free (sensorname);
+  sensor = GNUNET_CONTAINER_multihashmap_get (sensors, &key);
+  if (NULL == sensor)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+        "Unknown sensor name in reading message.\n");
+    return NULL;
+  }
+  if ((sensor->version_minor != ntohs (rm->sensorversion_minor)) ||
+      (sensor->version_major != ntohs (rm->sensorversion_major)))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                "Sensor version mismatch in reading message.\n");
+    return NULL;
+  }
+  if (0 == strcmp (sensor->expected_datatype, "numeric") &&
+      sizeof (double) != value_size)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                "Invalid value size for a numerical sensor.\n");
+    return NULL;
+  }
+  reading = GNUNET_new (struct GNUNET_SENSOR_Reading);
+  reading->sensor = sensor;
+  reading->timestamp = GNUNET_be64toh (rm->timestamp);
+  reading->value_size = value_size;
+  reading->value = GNUNET_malloc (value_size);
+  dummy += sensorname_size;
+  memcpy (reading->value, dummy, value_size);
+  return reading;
+}
+
+
+/**
  * Called with any sensor reading messages received from CADET.
  *
  * Each time the function must call #GNUNET_CADET_receive_done on the channel
@@ -217,15 +303,15 @@
                        void **channel_ctx,
                        const struct GNUNET_MessageHeader *message)
 {
-  struct GNUNET_PeerIdentity *peer = *channel_ctx;
+  struct ClientPeerContext *cp = *channel_ctx;
   struct GNUNET_SENSOR_Reading *reading;
 
-  reading = GNUNET_SENSOR_parse_reading_message (message, sensors);
+  reading = parse_reading_message (message, sensors);
   if (NULL == reading)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
                 "Received an invalid sensor reading from peer `%s'\n",
-                GNUNET_i2s (peer));
+                GNUNET_i2s (&cp->peerid));
     return GNUNET_SYSERR;
   }
   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
@@ -233,13 +319,13 @@
               "# Sensor name: `%s'\n"
               "# Timestamp: %" PRIu64 "\n"
               "# Value size: %" PRIu64 ".\n",
-              GNUNET_i2s (peer),
+              GNUNET_i2s (&cp->peerid),
               reading->sensor->name,
               reading->timestamp,
               reading->value_size);
-  GNUNET_PEERSTORE_store (peerstore, subsystem, peer, reading->sensor->name,
-                          reading->value, reading->value_size,
-                          GNUNET_TIME_UNIT_FOREVER_ABS,
+  GNUNET_PEERSTORE_store (peerstore, subsystem, &cp->peerid,
+                          reading->sensor->name, reading->value,
+                          reading->value_size, GNUNET_TIME_UNIT_FOREVER_ABS,
                           GNUNET_PEERSTORE_STOREOPTION_MULTIPLE, NULL, NULL);
   GNUNET_free (reading->value);
   GNUNET_free (reading);
@@ -286,7 +372,7 @@
      const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
   static const struct GNUNET_SERVER_MessageHandler handlers[] = {
-    {NULL, NULL, 0, 0}
+      {NULL, NULL, 0, 0}
   };
   static struct GNUNET_CADET_MessageHandler cadet_handlers[] = {
       {&handle_sensor_reading,
@@ -309,7 +395,7 @@
                                &cadet_channel_destroyed,
                                cadet_handlers,
                                cadet_ports);
-  if(NULL == cadet)
+  if (NULL == cadet)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 _("Failed to connect to `%s' service.\n"), "CADET");




reply via email to

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